]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.15.3-201407060933.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.15.3-201407060933.patch
CommitLineData
6f9a6f88
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 2e37d8b..3904d75 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..fc71228 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 long 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 14fd6fd..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 }
18441@@ -231,6 +235,22 @@ static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
18442
18443 #define ARCH_HAS_USER_SINGLE_STEP_INFO
18444
18445+/*
18446+ * When hitting ptrace_stop(), we cannot return using SYSRET because
18447+ * that does not restore the full CPU state, only a minimal set. The
18448+ * ptracer can change arbitrary register values, which is usually okay
18449+ * because the usual ptrace stops run off the signal delivery path which
18450+ * forces IRET; however, ptrace_event() stops happen in arbitrary places
18451+ * in the kernel and don't force IRET path.
18452+ *
18453+ * So force IRET path after a ptrace stop.
18454+ */
18455+#define arch_ptrace_stop_needed(code, info) \
18456+({ \
18457+ set_thread_flag(TIF_NOTIFY_RESUME); \
18458+ false; \
18459+})
18460+
18461 struct user_desc;
18462 extern int do_get_thread_area(struct task_struct *p, int idx,
18463 struct user_desc __user *info);
18464diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18465index 9c6b890..5305f53 100644
18466--- a/arch/x86/include/asm/realmode.h
18467+++ b/arch/x86/include/asm/realmode.h
18468@@ -22,16 +22,14 @@ struct real_mode_header {
18469 #endif
18470 /* APM/BIOS reboot */
18471 u32 machine_real_restart_asm;
18472-#ifdef CONFIG_X86_64
18473 u32 machine_real_restart_seg;
18474-#endif
18475 };
18476
18477 /* This must match data at trampoline_32/64.S */
18478 struct trampoline_header {
18479 #ifdef CONFIG_X86_32
18480 u32 start;
18481- u16 gdt_pad;
18482+ u16 boot_cs;
18483 u16 gdt_limit;
18484 u32 gdt_base;
18485 #else
18486diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18487index a82c4f1..ac45053 100644
18488--- a/arch/x86/include/asm/reboot.h
18489+++ b/arch/x86/include/asm/reboot.h
18490@@ -6,13 +6,13 @@
18491 struct pt_regs;
18492
18493 struct machine_ops {
18494- void (*restart)(char *cmd);
18495- void (*halt)(void);
18496- void (*power_off)(void);
18497+ void (* __noreturn restart)(char *cmd);
18498+ void (* __noreturn halt)(void);
18499+ void (* __noreturn power_off)(void);
18500 void (*shutdown)(void);
18501 void (*crash_shutdown)(struct pt_regs *);
18502- void (*emergency_restart)(void);
18503-};
18504+ void (* __noreturn emergency_restart)(void);
18505+} __no_const;
18506
18507 extern struct machine_ops machine_ops;
18508
18509diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18510index 8f7866a..e442f20 100644
18511--- a/arch/x86/include/asm/rmwcc.h
18512+++ b/arch/x86/include/asm/rmwcc.h
18513@@ -3,7 +3,34 @@
18514
18515 #ifdef CC_HAVE_ASM_GOTO
18516
18517-#define __GEN_RMWcc(fullop, var, cc, ...) \
18518+#ifdef CONFIG_PAX_REFCOUNT
18519+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18520+do { \
18521+ asm_volatile_goto (fullop \
18522+ ";jno 0f\n" \
18523+ fullantiop \
18524+ ";int $4\n0:\n" \
18525+ _ASM_EXTABLE(0b, 0b) \
18526+ ";j" cc " %l[cc_label]" \
18527+ : : "m" (var), ## __VA_ARGS__ \
18528+ : "memory" : cc_label); \
18529+ return 0; \
18530+cc_label: \
18531+ return 1; \
18532+} while (0)
18533+#else
18534+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18535+do { \
18536+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18537+ : : "m" (var), ## __VA_ARGS__ \
18538+ : "memory" : cc_label); \
18539+ return 0; \
18540+cc_label: \
18541+ return 1; \
18542+} while (0)
18543+#endif
18544+
18545+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18546 do { \
18547 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18548 : : "m" (var), ## __VA_ARGS__ \
18549@@ -13,15 +40,46 @@ cc_label: \
18550 return 1; \
18551 } while (0)
18552
18553-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18554- __GEN_RMWcc(op " " arg0, var, cc)
18555+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18556+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18557
18558-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18559- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18560+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18561+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18562+
18563+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18564+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18565+
18566+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18567+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18568
18569 #else /* !CC_HAVE_ASM_GOTO */
18570
18571-#define __GEN_RMWcc(fullop, var, cc, ...) \
18572+#ifdef CONFIG_PAX_REFCOUNT
18573+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18574+do { \
18575+ char c; \
18576+ asm volatile (fullop \
18577+ ";jno 0f\n" \
18578+ fullantiop \
18579+ ";int $4\n0:\n" \
18580+ _ASM_EXTABLE(0b, 0b) \
18581+ "; set" cc " %1" \
18582+ : "+m" (var), "=qm" (c) \
18583+ : __VA_ARGS__ : "memory"); \
18584+ return c != 0; \
18585+} while (0)
18586+#else
18587+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18588+do { \
18589+ char c; \
18590+ asm volatile (fullop "; set" cc " %1" \
18591+ : "+m" (var), "=qm" (c) \
18592+ : __VA_ARGS__ : "memory"); \
18593+ return c != 0; \
18594+} while (0)
18595+#endif
18596+
18597+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18598 do { \
18599 char c; \
18600 asm volatile (fullop "; set" cc " %1" \
18601@@ -30,11 +88,17 @@ do { \
18602 return c != 0; \
18603 } while (0)
18604
18605-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18606- __GEN_RMWcc(op " " arg0, var, cc)
18607+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18608+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18609+
18610+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18611+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18612+
18613+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18614+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18615
18616-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18617- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18618+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18619+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18620
18621 #endif /* CC_HAVE_ASM_GOTO */
18622
18623diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18624index cad82c9..2e5c5c1 100644
18625--- a/arch/x86/include/asm/rwsem.h
18626+++ b/arch/x86/include/asm/rwsem.h
18627@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18628 {
18629 asm volatile("# beginning down_read\n\t"
18630 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18631+
18632+#ifdef CONFIG_PAX_REFCOUNT
18633+ "jno 0f\n"
18634+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18635+ "int $4\n0:\n"
18636+ _ASM_EXTABLE(0b, 0b)
18637+#endif
18638+
18639 /* adds 0x00000001 */
18640 " jns 1f\n"
18641 " call call_rwsem_down_read_failed\n"
18642@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18643 "1:\n\t"
18644 " mov %1,%2\n\t"
18645 " add %3,%2\n\t"
18646+
18647+#ifdef CONFIG_PAX_REFCOUNT
18648+ "jno 0f\n"
18649+ "sub %3,%2\n"
18650+ "int $4\n0:\n"
18651+ _ASM_EXTABLE(0b, 0b)
18652+#endif
18653+
18654 " jle 2f\n\t"
18655 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18656 " jnz 1b\n\t"
18657@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18658 long tmp;
18659 asm volatile("# beginning down_write\n\t"
18660 LOCK_PREFIX " xadd %1,(%2)\n\t"
18661+
18662+#ifdef CONFIG_PAX_REFCOUNT
18663+ "jno 0f\n"
18664+ "mov %1,(%2)\n"
18665+ "int $4\n0:\n"
18666+ _ASM_EXTABLE(0b, 0b)
18667+#endif
18668+
18669 /* adds 0xffff0001, returns the old value */
18670 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18671 /* was the active mask 0 before? */
18672@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18673 long tmp;
18674 asm volatile("# beginning __up_read\n\t"
18675 LOCK_PREFIX " xadd %1,(%2)\n\t"
18676+
18677+#ifdef CONFIG_PAX_REFCOUNT
18678+ "jno 0f\n"
18679+ "mov %1,(%2)\n"
18680+ "int $4\n0:\n"
18681+ _ASM_EXTABLE(0b, 0b)
18682+#endif
18683+
18684 /* subtracts 1, returns the old value */
18685 " jns 1f\n\t"
18686 " call call_rwsem_wake\n" /* expects old value in %edx */
18687@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18688 long tmp;
18689 asm volatile("# beginning __up_write\n\t"
18690 LOCK_PREFIX " xadd %1,(%2)\n\t"
18691+
18692+#ifdef CONFIG_PAX_REFCOUNT
18693+ "jno 0f\n"
18694+ "mov %1,(%2)\n"
18695+ "int $4\n0:\n"
18696+ _ASM_EXTABLE(0b, 0b)
18697+#endif
18698+
18699 /* subtracts 0xffff0001, returns the old value */
18700 " jns 1f\n\t"
18701 " call call_rwsem_wake\n" /* expects old value in %edx */
18702@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18703 {
18704 asm volatile("# beginning __downgrade_write\n\t"
18705 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18706+
18707+#ifdef CONFIG_PAX_REFCOUNT
18708+ "jno 0f\n"
18709+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18710+ "int $4\n0:\n"
18711+ _ASM_EXTABLE(0b, 0b)
18712+#endif
18713+
18714 /*
18715 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18716 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18717@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18718 */
18719 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18720 {
18721- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18722+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18723+
18724+#ifdef CONFIG_PAX_REFCOUNT
18725+ "jno 0f\n"
18726+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18727+ "int $4\n0:\n"
18728+ _ASM_EXTABLE(0b, 0b)
18729+#endif
18730+
18731 : "+m" (sem->count)
18732 : "er" (delta));
18733 }
18734@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18735 */
18736 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18737 {
18738- return delta + xadd(&sem->count, delta);
18739+ return delta + xadd_check_overflow(&sem->count, delta);
18740 }
18741
18742 #endif /* __KERNEL__ */
18743diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18744index 6f1c3a8..7744f19 100644
18745--- a/arch/x86/include/asm/segment.h
18746+++ b/arch/x86/include/asm/segment.h
18747@@ -64,10 +64,15 @@
18748 * 26 - ESPFIX small SS
18749 * 27 - per-cpu [ offset to per-cpu data area ]
18750 * 28 - stack_canary-20 [ for stack protector ]
18751- * 29 - unused
18752- * 30 - unused
18753+ * 29 - PCI BIOS CS
18754+ * 30 - PCI BIOS DS
18755 * 31 - TSS for double fault handler
18756 */
18757+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18758+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18759+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18760+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18761+
18762 #define GDT_ENTRY_TLS_MIN 6
18763 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18764
18765@@ -79,6 +84,8 @@
18766
18767 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18768
18769+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18770+
18771 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18772
18773 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18774@@ -104,6 +111,12 @@
18775 #define __KERNEL_STACK_CANARY 0
18776 #endif
18777
18778+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18779+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18780+
18781+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18782+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18783+
18784 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18785
18786 /*
18787@@ -141,7 +154,7 @@
18788 */
18789
18790 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18791-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18792+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18793
18794
18795 #else
18796@@ -165,6 +178,8 @@
18797 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18798 #define __USER32_DS __USER_DS
18799
18800+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18801+
18802 #define GDT_ENTRY_TSS 8 /* needs two entries */
18803 #define GDT_ENTRY_LDT 10 /* needs two entries */
18804 #define GDT_ENTRY_TLS_MIN 12
18805@@ -173,6 +188,8 @@
18806 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18807 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18808
18809+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18810+
18811 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18812 #define FS_TLS 0
18813 #define GS_TLS 1
18814@@ -180,12 +197,14 @@
18815 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18816 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18817
18818-#define GDT_ENTRIES 16
18819+#define GDT_ENTRIES 17
18820
18821 #endif
18822
18823 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18824+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18825 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18826+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18827 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18828 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18829 #ifndef CONFIG_PARAVIRT
18830@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18831 {
18832 unsigned long __limit;
18833 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18834- return __limit + 1;
18835+ return __limit;
18836 }
18837
18838 #endif /* !__ASSEMBLY__ */
18839diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18840index 8d3120f..352b440 100644
18841--- a/arch/x86/include/asm/smap.h
18842+++ b/arch/x86/include/asm/smap.h
18843@@ -25,11 +25,40 @@
18844
18845 #include <asm/alternative-asm.h>
18846
18847+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18848+#define ASM_PAX_OPEN_USERLAND \
18849+ 661: jmp 663f; \
18850+ .pushsection .altinstr_replacement, "a" ; \
18851+ 662: pushq %rax; nop; \
18852+ .popsection ; \
18853+ .pushsection .altinstructions, "a" ; \
18854+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18855+ .popsection ; \
18856+ call __pax_open_userland; \
18857+ popq %rax; \
18858+ 663:
18859+
18860+#define ASM_PAX_CLOSE_USERLAND \
18861+ 661: jmp 663f; \
18862+ .pushsection .altinstr_replacement, "a" ; \
18863+ 662: pushq %rax; nop; \
18864+ .popsection; \
18865+ .pushsection .altinstructions, "a" ; \
18866+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18867+ .popsection; \
18868+ call __pax_close_userland; \
18869+ popq %rax; \
18870+ 663:
18871+#else
18872+#define ASM_PAX_OPEN_USERLAND
18873+#define ASM_PAX_CLOSE_USERLAND
18874+#endif
18875+
18876 #ifdef CONFIG_X86_SMAP
18877
18878 #define ASM_CLAC \
18879 661: ASM_NOP3 ; \
18880- .pushsection .altinstr_replacement, "ax" ; \
18881+ .pushsection .altinstr_replacement, "a" ; \
18882 662: __ASM_CLAC ; \
18883 .popsection ; \
18884 .pushsection .altinstructions, "a" ; \
18885@@ -38,7 +67,7 @@
18886
18887 #define ASM_STAC \
18888 661: ASM_NOP3 ; \
18889- .pushsection .altinstr_replacement, "ax" ; \
18890+ .pushsection .altinstr_replacement, "a" ; \
18891 662: __ASM_STAC ; \
18892 .popsection ; \
18893 .pushsection .altinstructions, "a" ; \
18894@@ -56,6 +85,37 @@
18895
18896 #include <asm/alternative.h>
18897
18898+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18899+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18900+
18901+extern void __pax_open_userland(void);
18902+static __always_inline unsigned long pax_open_userland(void)
18903+{
18904+
18905+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18906+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18907+ :
18908+ : [open] "i" (__pax_open_userland)
18909+ : "memory", "rax");
18910+#endif
18911+
18912+ return 0;
18913+}
18914+
18915+extern void __pax_close_userland(void);
18916+static __always_inline unsigned long pax_close_userland(void)
18917+{
18918+
18919+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18920+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18921+ :
18922+ : [close] "i" (__pax_close_userland)
18923+ : "memory", "rax");
18924+#endif
18925+
18926+ return 0;
18927+}
18928+
18929 #ifdef CONFIG_X86_SMAP
18930
18931 static __always_inline void clac(void)
18932diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18933index 8cd27e0..7f05ec8 100644
18934--- a/arch/x86/include/asm/smp.h
18935+++ b/arch/x86/include/asm/smp.h
18936@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18937 /* cpus sharing the last level cache: */
18938 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18939 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18940-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18941+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18942
18943 static inline struct cpumask *cpu_sibling_mask(int cpu)
18944 {
18945@@ -78,7 +78,7 @@ struct smp_ops {
18946
18947 void (*send_call_func_ipi)(const struct cpumask *mask);
18948 void (*send_call_func_single_ipi)(int cpu);
18949-};
18950+} __no_const;
18951
18952 /* Globals due to paravirt */
18953 extern void set_cpu_sibling_map(int cpu);
18954@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18955 extern int safe_smp_processor_id(void);
18956
18957 #elif defined(CONFIG_X86_64_SMP)
18958-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18959-
18960-#define stack_smp_processor_id() \
18961-({ \
18962- struct thread_info *ti; \
18963- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18964- ti->cpu; \
18965-})
18966+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18967+#define stack_smp_processor_id() raw_smp_processor_id()
18968 #define safe_smp_processor_id() smp_processor_id()
18969
18970 #endif
18971diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18972index 0f62f54..cb5d0dd 100644
18973--- a/arch/x86/include/asm/spinlock.h
18974+++ b/arch/x86/include/asm/spinlock.h
18975@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18976 static inline void arch_read_lock(arch_rwlock_t *rw)
18977 {
18978 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18979+
18980+#ifdef CONFIG_PAX_REFCOUNT
18981+ "jno 0f\n"
18982+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18983+ "int $4\n0:\n"
18984+ _ASM_EXTABLE(0b, 0b)
18985+#endif
18986+
18987 "jns 1f\n"
18988 "call __read_lock_failed\n\t"
18989 "1:\n"
18990@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18991 static inline void arch_write_lock(arch_rwlock_t *rw)
18992 {
18993 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18994+
18995+#ifdef CONFIG_PAX_REFCOUNT
18996+ "jno 0f\n"
18997+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18998+ "int $4\n0:\n"
18999+ _ASM_EXTABLE(0b, 0b)
19000+#endif
19001+
19002 "jz 1f\n"
19003 "call __write_lock_failed\n\t"
19004 "1:\n"
19005@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19006
19007 static inline void arch_read_unlock(arch_rwlock_t *rw)
19008 {
19009- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19010+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19011+
19012+#ifdef CONFIG_PAX_REFCOUNT
19013+ "jno 0f\n"
19014+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19015+ "int $4\n0:\n"
19016+ _ASM_EXTABLE(0b, 0b)
19017+#endif
19018+
19019 :"+m" (rw->lock) : : "memory");
19020 }
19021
19022 static inline void arch_write_unlock(arch_rwlock_t *rw)
19023 {
19024- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19025+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19026+
19027+#ifdef CONFIG_PAX_REFCOUNT
19028+ "jno 0f\n"
19029+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19030+ "int $4\n0:\n"
19031+ _ASM_EXTABLE(0b, 0b)
19032+#endif
19033+
19034 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19035 }
19036
19037diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19038index 6a99859..03cb807 100644
19039--- a/arch/x86/include/asm/stackprotector.h
19040+++ b/arch/x86/include/asm/stackprotector.h
19041@@ -47,7 +47,7 @@
19042 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19043 */
19044 #define GDT_STACK_CANARY_INIT \
19045- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19046+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19047
19048 /*
19049 * Initialize the stackprotector canary value.
19050@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19051
19052 static inline void load_stack_canary_segment(void)
19053 {
19054-#ifdef CONFIG_X86_32
19055+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19056 asm volatile ("mov %0, %%gs" : : "r" (0));
19057 #endif
19058 }
19059diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19060index 70bbe39..4ae2bd4 100644
19061--- a/arch/x86/include/asm/stacktrace.h
19062+++ b/arch/x86/include/asm/stacktrace.h
19063@@ -11,28 +11,20 @@
19064
19065 extern int kstack_depth_to_print;
19066
19067-struct thread_info;
19068+struct task_struct;
19069 struct stacktrace_ops;
19070
19071-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19072- unsigned long *stack,
19073- unsigned long bp,
19074- const struct stacktrace_ops *ops,
19075- void *data,
19076- unsigned long *end,
19077- int *graph);
19078+typedef unsigned long walk_stack_t(struct task_struct *task,
19079+ void *stack_start,
19080+ unsigned long *stack,
19081+ unsigned long bp,
19082+ const struct stacktrace_ops *ops,
19083+ void *data,
19084+ unsigned long *end,
19085+ int *graph);
19086
19087-extern unsigned long
19088-print_context_stack(struct thread_info *tinfo,
19089- unsigned long *stack, unsigned long bp,
19090- const struct stacktrace_ops *ops, void *data,
19091- unsigned long *end, int *graph);
19092-
19093-extern unsigned long
19094-print_context_stack_bp(struct thread_info *tinfo,
19095- unsigned long *stack, unsigned long bp,
19096- const struct stacktrace_ops *ops, void *data,
19097- unsigned long *end, int *graph);
19098+extern walk_stack_t print_context_stack;
19099+extern walk_stack_t print_context_stack_bp;
19100
19101 /* Generic stack tracer with callbacks */
19102
19103@@ -40,7 +32,7 @@ struct stacktrace_ops {
19104 void (*address)(void *data, unsigned long address, int reliable);
19105 /* On negative return stop dumping */
19106 int (*stack)(void *data, char *name);
19107- walk_stack_t walk_stack;
19108+ walk_stack_t *walk_stack;
19109 };
19110
19111 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19112diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19113index d7f3b3b..3cc39f1 100644
19114--- a/arch/x86/include/asm/switch_to.h
19115+++ b/arch/x86/include/asm/switch_to.h
19116@@ -108,7 +108,7 @@ do { \
19117 "call __switch_to\n\t" \
19118 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19119 __switch_canary \
19120- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19121+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19122 "movq %%rax,%%rdi\n\t" \
19123 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19124 "jnz ret_from_fork\n\t" \
19125@@ -119,7 +119,7 @@ do { \
19126 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19127 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19128 [_tif_fork] "i" (_TIF_FORK), \
19129- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19130+ [thread_info] "m" (current_tinfo), \
19131 [current_task] "m" (current_task) \
19132 __switch_canary_iparam \
19133 : "memory", "cc" __EXTRA_CLOBBER)
19134diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19135index 47e5de2..d3dda54 100644
19136--- a/arch/x86/include/asm/thread_info.h
19137+++ b/arch/x86/include/asm/thread_info.h
19138@@ -24,7 +24,6 @@ struct exec_domain;
19139 #include <linux/atomic.h>
19140
19141 struct thread_info {
19142- struct task_struct *task; /* main task structure */
19143 struct exec_domain *exec_domain; /* execution domain */
19144 __u32 flags; /* low level flags */
19145 __u32 status; /* thread synchronous flags */
19146@@ -33,13 +32,13 @@ struct thread_info {
19147 mm_segment_t addr_limit;
19148 struct restart_block restart_block;
19149 void __user *sysenter_return;
19150+ unsigned long lowest_stack;
19151 unsigned int sig_on_uaccess_error:1;
19152 unsigned int uaccess_err:1; /* uaccess failed */
19153 };
19154
19155-#define INIT_THREAD_INFO(tsk) \
19156+#define INIT_THREAD_INFO \
19157 { \
19158- .task = &tsk, \
19159 .exec_domain = &default_exec_domain, \
19160 .flags = 0, \
19161 .cpu = 0, \
19162@@ -50,7 +49,7 @@ struct thread_info {
19163 }, \
19164 }
19165
19166-#define init_thread_info (init_thread_union.thread_info)
19167+#define init_thread_info (init_thread_union.stack)
19168 #define init_stack (init_thread_union.stack)
19169
19170 #else /* !__ASSEMBLY__ */
19171@@ -90,6 +89,7 @@ struct thread_info {
19172 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19173 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19174 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19175+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19176
19177 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19178 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19179@@ -113,17 +113,18 @@ struct thread_info {
19180 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19181 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19182 #define _TIF_X32 (1 << TIF_X32)
19183+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19184
19185 /* work to do in syscall_trace_enter() */
19186 #define _TIF_WORK_SYSCALL_ENTRY \
19187 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19188 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19189- _TIF_NOHZ)
19190+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19191
19192 /* work to do in syscall_trace_leave() */
19193 #define _TIF_WORK_SYSCALL_EXIT \
19194 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19195- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19196+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19197
19198 /* work to do on interrupt/exception return */
19199 #define _TIF_WORK_MASK \
19200@@ -134,7 +135,7 @@ struct thread_info {
19201 /* work to do on any return to user space */
19202 #define _TIF_ALLWORK_MASK \
19203 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19204- _TIF_NOHZ)
19205+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19206
19207 /* Only used for 64 bit */
19208 #define _TIF_DO_NOTIFY_MASK \
19209@@ -149,7 +150,6 @@ struct thread_info {
19210 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19211
19212 #define STACK_WARN (THREAD_SIZE/8)
19213-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19214
19215 /*
19216 * macros/functions for gaining access to the thread information structure
19217@@ -160,26 +160,18 @@ struct thread_info {
19218
19219 DECLARE_PER_CPU(unsigned long, kernel_stack);
19220
19221+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19222+
19223 static inline struct thread_info *current_thread_info(void)
19224 {
19225- struct thread_info *ti;
19226- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19227- KERNEL_STACK_OFFSET - THREAD_SIZE);
19228- return ti;
19229+ return this_cpu_read_stable(current_tinfo);
19230 }
19231
19232 #else /* !__ASSEMBLY__ */
19233
19234 /* how to get the thread information struct from ASM */
19235 #define GET_THREAD_INFO(reg) \
19236- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19237- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19238-
19239-/*
19240- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19241- * a certain register (to be used in assembler memory operands).
19242- */
19243-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19244+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19245
19246 #endif
19247
19248@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19249 extern void arch_task_cache_init(void);
19250 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19251 extern void arch_release_task_struct(struct task_struct *tsk);
19252+
19253+#define __HAVE_THREAD_FUNCTIONS
19254+#define task_thread_info(task) (&(task)->tinfo)
19255+#define task_stack_page(task) ((task)->stack)
19256+#define setup_thread_stack(p, org) do {} while (0)
19257+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19258+
19259 #endif
19260 #endif /* _ASM_X86_THREAD_INFO_H */
19261diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19262index 04905bf..49203ca 100644
19263--- a/arch/x86/include/asm/tlbflush.h
19264+++ b/arch/x86/include/asm/tlbflush.h
19265@@ -17,18 +17,44 @@
19266
19267 static inline void __native_flush_tlb(void)
19268 {
19269+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19270+ u64 descriptor[2];
19271+
19272+ descriptor[0] = PCID_KERNEL;
19273+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19274+ return;
19275+ }
19276+
19277+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19278+ if (static_cpu_has(X86_FEATURE_PCID)) {
19279+ unsigned int cpu = raw_get_cpu();
19280+
19281+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19282+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19283+ raw_put_cpu_no_resched();
19284+ return;
19285+ }
19286+#endif
19287+
19288 native_write_cr3(native_read_cr3());
19289 }
19290
19291 static inline void __native_flush_tlb_global_irq_disabled(void)
19292 {
19293- unsigned long cr4;
19294+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19295+ u64 descriptor[2];
19296
19297- cr4 = native_read_cr4();
19298- /* clear PGE */
19299- native_write_cr4(cr4 & ~X86_CR4_PGE);
19300- /* write old PGE again and flush TLBs */
19301- native_write_cr4(cr4);
19302+ descriptor[0] = PCID_KERNEL;
19303+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19304+ } else {
19305+ unsigned long cr4;
19306+
19307+ cr4 = native_read_cr4();
19308+ /* clear PGE */
19309+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19310+ /* write old PGE again and flush TLBs */
19311+ native_write_cr4(cr4);
19312+ }
19313 }
19314
19315 static inline void __native_flush_tlb_global(void)
19316@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19317
19318 static inline void __native_flush_tlb_single(unsigned long addr)
19319 {
19320+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19321+ u64 descriptor[2];
19322+
19323+ descriptor[0] = PCID_KERNEL;
19324+ descriptor[1] = addr;
19325+
19326+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19327+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19328+ if (addr < TASK_SIZE_MAX)
19329+ descriptor[1] += pax_user_shadow_base;
19330+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19331+ }
19332+
19333+ descriptor[0] = PCID_USER;
19334+ descriptor[1] = addr;
19335+#endif
19336+
19337+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19338+ return;
19339+ }
19340+
19341+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19342+ if (static_cpu_has(X86_FEATURE_PCID)) {
19343+ unsigned int cpu = raw_get_cpu();
19344+
19345+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19346+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19347+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19348+ raw_put_cpu_no_resched();
19349+
19350+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19351+ addr += pax_user_shadow_base;
19352+ }
19353+#endif
19354+
19355 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19356 }
19357
19358diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19359index 0d592e0..7437fcc 100644
19360--- a/arch/x86/include/asm/uaccess.h
19361+++ b/arch/x86/include/asm/uaccess.h
19362@@ -7,6 +7,7 @@
19363 #include <linux/compiler.h>
19364 #include <linux/thread_info.h>
19365 #include <linux/string.h>
19366+#include <linux/spinlock.h>
19367 #include <asm/asm.h>
19368 #include <asm/page.h>
19369 #include <asm/smap.h>
19370@@ -29,7 +30,12 @@
19371
19372 #define get_ds() (KERNEL_DS)
19373 #define get_fs() (current_thread_info()->addr_limit)
19374+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19375+void __set_fs(mm_segment_t x);
19376+void set_fs(mm_segment_t x);
19377+#else
19378 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19379+#endif
19380
19381 #define segment_eq(a, b) ((a).seg == (b).seg)
19382
19383@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19384 * checks that the pointer is in the user space range - after calling
19385 * this function, memory access functions may still return -EFAULT.
19386 */
19387-#define access_ok(type, addr, size) \
19388- likely(!__range_not_ok(addr, size, user_addr_max()))
19389+extern int _cond_resched(void);
19390+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19391+#define access_ok(type, addr, size) \
19392+({ \
19393+ unsigned long __size = size; \
19394+ unsigned long __addr = (unsigned long)addr; \
19395+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19396+ if (__ret_ao && __size) { \
19397+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19398+ unsigned long __end_ao = __addr + __size - 1; \
19399+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19400+ while (__addr_ao <= __end_ao) { \
19401+ char __c_ao; \
19402+ __addr_ao += PAGE_SIZE; \
19403+ if (__size > PAGE_SIZE) \
19404+ _cond_resched(); \
19405+ if (__get_user(__c_ao, (char __user *)__addr)) \
19406+ break; \
19407+ if (type != VERIFY_WRITE) { \
19408+ __addr = __addr_ao; \
19409+ continue; \
19410+ } \
19411+ if (__put_user(__c_ao, (char __user *)__addr)) \
19412+ break; \
19413+ __addr = __addr_ao; \
19414+ } \
19415+ } \
19416+ } \
19417+ __ret_ao; \
19418+})
19419
19420 /*
19421 * The exception table consists of pairs of addresses relative to the
19422@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19423 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19424 __chk_user_ptr(ptr); \
19425 might_fault(); \
19426+ pax_open_userland(); \
19427 asm volatile("call __get_user_%P3" \
19428 : "=a" (__ret_gu), "=r" (__val_gu) \
19429 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19430 (x) = (__typeof__(*(ptr))) __val_gu; \
19431+ pax_close_userland(); \
19432 __ret_gu; \
19433 })
19434
19435@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19436 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19437 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19438
19439-
19440+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19441+#define __copyuser_seg "gs;"
19442+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19443+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19444+#else
19445+#define __copyuser_seg
19446+#define __COPYUSER_SET_ES
19447+#define __COPYUSER_RESTORE_ES
19448+#endif
19449
19450 #ifdef CONFIG_X86_32
19451 #define __put_user_asm_u64(x, addr, err, errret) \
19452 asm volatile(ASM_STAC "\n" \
19453- "1: movl %%eax,0(%2)\n" \
19454- "2: movl %%edx,4(%2)\n" \
19455+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19456+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19457 "3: " ASM_CLAC "\n" \
19458 ".section .fixup,\"ax\"\n" \
19459 "4: movl %3,%0\n" \
19460@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19461
19462 #define __put_user_asm_ex_u64(x, addr) \
19463 asm volatile(ASM_STAC "\n" \
19464- "1: movl %%eax,0(%1)\n" \
19465- "2: movl %%edx,4(%1)\n" \
19466+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19467+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19468 "3: " ASM_CLAC "\n" \
19469 _ASM_EXTABLE_EX(1b, 2b) \
19470 _ASM_EXTABLE_EX(2b, 3b) \
19471@@ -257,7 +301,8 @@ extern void __put_user_8(void);
19472 __typeof__(*(ptr)) __pu_val; \
19473 __chk_user_ptr(ptr); \
19474 might_fault(); \
19475- __pu_val = x; \
19476+ __pu_val = (x); \
19477+ pax_open_userland(); \
19478 switch (sizeof(*(ptr))) { \
19479 case 1: \
19480 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19481@@ -275,6 +320,7 @@ extern void __put_user_8(void);
19482 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19483 break; \
19484 } \
19485+ pax_close_userland(); \
19486 __ret_pu; \
19487 })
19488
19489@@ -355,8 +401,10 @@ do { \
19490 } while (0)
19491
19492 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19493+do { \
19494+ pax_open_userland(); \
19495 asm volatile(ASM_STAC "\n" \
19496- "1: mov"itype" %2,%"rtype"1\n" \
19497+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19498 "2: " ASM_CLAC "\n" \
19499 ".section .fixup,\"ax\"\n" \
19500 "3: mov %3,%0\n" \
19501@@ -364,8 +412,10 @@ do { \
19502 " jmp 2b\n" \
19503 ".previous\n" \
19504 _ASM_EXTABLE(1b, 3b) \
19505- : "=r" (err), ltype(x) \
19506- : "m" (__m(addr)), "i" (errret), "0" (err))
19507+ : "=r" (err), ltype (x) \
19508+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19509+ pax_close_userland(); \
19510+} while (0)
19511
19512 #define __get_user_size_ex(x, ptr, size) \
19513 do { \
19514@@ -389,7 +439,7 @@ do { \
19515 } while (0)
19516
19517 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19518- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19519+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19520 "2:\n" \
19521 _ASM_EXTABLE_EX(1b, 2b) \
19522 : ltype(x) : "m" (__m(addr)))
19523@@ -406,13 +456,24 @@ do { \
19524 int __gu_err; \
19525 unsigned long __gu_val; \
19526 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19527- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19528+ (x) = (__typeof__(*(ptr)))__gu_val; \
19529 __gu_err; \
19530 })
19531
19532 /* FIXME: this hack is definitely wrong -AK */
19533 struct __large_struct { unsigned long buf[100]; };
19534-#define __m(x) (*(struct __large_struct __user *)(x))
19535+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19536+#define ____m(x) \
19537+({ \
19538+ unsigned long ____x = (unsigned long)(x); \
19539+ if (____x < pax_user_shadow_base) \
19540+ ____x += pax_user_shadow_base; \
19541+ (typeof(x))____x; \
19542+})
19543+#else
19544+#define ____m(x) (x)
19545+#endif
19546+#define __m(x) (*(struct __large_struct __user *)____m(x))
19547
19548 /*
19549 * Tell gcc we read from memory instead of writing: this is because
19550@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19551 * aliasing issues.
19552 */
19553 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19554+do { \
19555+ pax_open_userland(); \
19556 asm volatile(ASM_STAC "\n" \
19557- "1: mov"itype" %"rtype"1,%2\n" \
19558+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19559 "2: " ASM_CLAC "\n" \
19560 ".section .fixup,\"ax\"\n" \
19561 "3: mov %3,%0\n" \
19562@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19563 ".previous\n" \
19564 _ASM_EXTABLE(1b, 3b) \
19565 : "=r"(err) \
19566- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19567+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19568+ pax_close_userland(); \
19569+} while (0)
19570
19571 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19572- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19573+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19574 "2:\n" \
19575 _ASM_EXTABLE_EX(1b, 2b) \
19576 : : ltype(x), "m" (__m(addr)))
19577@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19578 */
19579 #define uaccess_try do { \
19580 current_thread_info()->uaccess_err = 0; \
19581+ pax_open_userland(); \
19582 stac(); \
19583 barrier();
19584
19585 #define uaccess_catch(err) \
19586 clac(); \
19587+ pax_close_userland(); \
19588 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19589 } while (0)
19590
19591@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19592 * On error, the variable @x is set to zero.
19593 */
19594
19595+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19596+#define __get_user(x, ptr) get_user((x), (ptr))
19597+#else
19598 #define __get_user(x, ptr) \
19599 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19600+#endif
19601
19602 /**
19603 * __put_user: - Write a simple value into user space, with less checking.
19604@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19605 * Returns zero on success, or -EFAULT on error.
19606 */
19607
19608+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19609+#define __put_user(x, ptr) put_user((x), (ptr))
19610+#else
19611 #define __put_user(x, ptr) \
19612 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19613+#endif
19614
19615 #define __get_user_unaligned __get_user
19616 #define __put_user_unaligned __put_user
19617@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19618 #define get_user_ex(x, ptr) do { \
19619 unsigned long __gue_val; \
19620 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19621- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19622+ (x) = (__typeof__(*(ptr)))__gue_val; \
19623 } while (0)
19624
19625 #define put_user_try uaccess_try
19626@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19627 __typeof__(ptr) __uval = (uval); \
19628 __typeof__(*(ptr)) __old = (old); \
19629 __typeof__(*(ptr)) __new = (new); \
19630+ pax_open_userland(); \
19631 switch (size) { \
19632 case 1: \
19633 { \
19634 asm volatile("\t" ASM_STAC "\n" \
19635- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19636+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19637 "2:\t" ASM_CLAC "\n" \
19638 "\t.section .fixup, \"ax\"\n" \
19639 "3:\tmov %3, %0\n" \
19640 "\tjmp 2b\n" \
19641 "\t.previous\n" \
19642 _ASM_EXTABLE(1b, 3b) \
19643- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19644+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19645 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19646 : "memory" \
19647 ); \
19648@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19649 case 2: \
19650 { \
19651 asm volatile("\t" ASM_STAC "\n" \
19652- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19653+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19654 "2:\t" ASM_CLAC "\n" \
19655 "\t.section .fixup, \"ax\"\n" \
19656 "3:\tmov %3, %0\n" \
19657 "\tjmp 2b\n" \
19658 "\t.previous\n" \
19659 _ASM_EXTABLE(1b, 3b) \
19660- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19661+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19662 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19663 : "memory" \
19664 ); \
19665@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19666 case 4: \
19667 { \
19668 asm volatile("\t" ASM_STAC "\n" \
19669- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19670+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19671 "2:\t" ASM_CLAC "\n" \
19672 "\t.section .fixup, \"ax\"\n" \
19673 "3:\tmov %3, %0\n" \
19674 "\tjmp 2b\n" \
19675 "\t.previous\n" \
19676 _ASM_EXTABLE(1b, 3b) \
19677- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19678+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19679 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19680 : "memory" \
19681 ); \
19682@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19683 __cmpxchg_wrong_size(); \
19684 \
19685 asm volatile("\t" ASM_STAC "\n" \
19686- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19687+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19688 "2:\t" ASM_CLAC "\n" \
19689 "\t.section .fixup, \"ax\"\n" \
19690 "3:\tmov %3, %0\n" \
19691 "\tjmp 2b\n" \
19692 "\t.previous\n" \
19693 _ASM_EXTABLE(1b, 3b) \
19694- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19695+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19696 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19697 : "memory" \
19698 ); \
19699@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19700 default: \
19701 __cmpxchg_wrong_size(); \
19702 } \
19703+ pax_close_userland(); \
19704 *__uval = __old; \
19705 __ret; \
19706 })
19707@@ -636,17 +713,6 @@ extern struct movsl_mask {
19708
19709 #define ARCH_HAS_NOCACHE_UACCESS 1
19710
19711-#ifdef CONFIG_X86_32
19712-# include <asm/uaccess_32.h>
19713-#else
19714-# include <asm/uaccess_64.h>
19715-#endif
19716-
19717-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19718- unsigned n);
19719-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19720- unsigned n);
19721-
19722 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19723 # define copy_user_diag __compiletime_error
19724 #else
19725@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19726 extern void copy_user_diag("copy_from_user() buffer size is too small")
19727 copy_from_user_overflow(void);
19728 extern void copy_user_diag("copy_to_user() buffer size is too small")
19729-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19730+copy_to_user_overflow(void);
19731
19732 #undef copy_user_diag
19733
19734@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19735
19736 extern void
19737 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19738-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19739+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19740 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19741
19742 #else
19743@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19744
19745 #endif
19746
19747+#ifdef CONFIG_X86_32
19748+# include <asm/uaccess_32.h>
19749+#else
19750+# include <asm/uaccess_64.h>
19751+#endif
19752+
19753 static inline unsigned long __must_check
19754 copy_from_user(void *to, const void __user *from, unsigned long n)
19755 {
19756- int sz = __compiletime_object_size(to);
19757+ size_t sz = __compiletime_object_size(to);
19758
19759 might_fault();
19760
19761@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19762 * case, and do only runtime checking for non-constant sizes.
19763 */
19764
19765- if (likely(sz < 0 || sz >= n))
19766- n = _copy_from_user(to, from, n);
19767- else if(__builtin_constant_p(n))
19768- copy_from_user_overflow();
19769- else
19770- __copy_from_user_overflow(sz, n);
19771+ if (likely(sz != (size_t)-1 && sz < n)) {
19772+ if(__builtin_constant_p(n))
19773+ copy_from_user_overflow();
19774+ else
19775+ __copy_from_user_overflow(sz, n);
19776+ } if (access_ok(VERIFY_READ, from, n))
19777+ n = __copy_from_user(to, from, n);
19778+ else if ((long)n > 0)
19779+ memset(to, 0, n);
19780
19781 return n;
19782 }
19783@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19784 static inline unsigned long __must_check
19785 copy_to_user(void __user *to, const void *from, unsigned long n)
19786 {
19787- int sz = __compiletime_object_size(from);
19788+ size_t sz = __compiletime_object_size(from);
19789
19790 might_fault();
19791
19792 /* See the comment in copy_from_user() above. */
19793- if (likely(sz < 0 || sz >= n))
19794- n = _copy_to_user(to, from, n);
19795- else if(__builtin_constant_p(n))
19796- copy_to_user_overflow();
19797- else
19798- __copy_to_user_overflow(sz, n);
19799+ if (likely(sz != (size_t)-1 && sz < n)) {
19800+ if(__builtin_constant_p(n))
19801+ copy_to_user_overflow();
19802+ else
19803+ __copy_to_user_overflow(sz, n);
19804+ } else if (access_ok(VERIFY_WRITE, to, n))
19805+ n = __copy_to_user(to, from, n);
19806
19807 return n;
19808 }
19809diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19810index 3c03a5d..1071638 100644
19811--- a/arch/x86/include/asm/uaccess_32.h
19812+++ b/arch/x86/include/asm/uaccess_32.h
19813@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19814 static __always_inline unsigned long __must_check
19815 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19816 {
19817+ if ((long)n < 0)
19818+ return n;
19819+
19820+ check_object_size(from, n, true);
19821+
19822 if (__builtin_constant_p(n)) {
19823 unsigned long ret;
19824
19825@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19826 __copy_to_user(void __user *to, const void *from, unsigned long n)
19827 {
19828 might_fault();
19829+
19830 return __copy_to_user_inatomic(to, from, n);
19831 }
19832
19833 static __always_inline unsigned long
19834 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19835 {
19836+ if ((long)n < 0)
19837+ return n;
19838+
19839 /* Avoid zeroing the tail if the copy fails..
19840 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19841 * but as the zeroing behaviour is only significant when n is not
19842@@ -137,6 +146,12 @@ static __always_inline unsigned long
19843 __copy_from_user(void *to, const void __user *from, unsigned long n)
19844 {
19845 might_fault();
19846+
19847+ if ((long)n < 0)
19848+ return n;
19849+
19850+ check_object_size(to, n, false);
19851+
19852 if (__builtin_constant_p(n)) {
19853 unsigned long ret;
19854
19855@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19856 const void __user *from, unsigned long n)
19857 {
19858 might_fault();
19859+
19860+ if ((long)n < 0)
19861+ return n;
19862+
19863 if (__builtin_constant_p(n)) {
19864 unsigned long ret;
19865
19866@@ -181,7 +200,10 @@ static __always_inline unsigned long
19867 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19868 unsigned long n)
19869 {
19870- return __copy_from_user_ll_nocache_nozero(to, from, n);
19871+ if ((long)n < 0)
19872+ return n;
19873+
19874+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19875 }
19876
19877 #endif /* _ASM_X86_UACCESS_32_H */
19878diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19879index 12a26b9..206c200 100644
19880--- a/arch/x86/include/asm/uaccess_64.h
19881+++ b/arch/x86/include/asm/uaccess_64.h
19882@@ -10,6 +10,9 @@
19883 #include <asm/alternative.h>
19884 #include <asm/cpufeature.h>
19885 #include <asm/page.h>
19886+#include <asm/pgtable.h>
19887+
19888+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19889
19890 /*
19891 * Copy To/From Userspace
19892@@ -17,14 +20,14 @@
19893
19894 /* Handles exceptions in both to and from, but doesn't do access_ok */
19895 __must_check unsigned long
19896-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19897+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19898 __must_check unsigned long
19899-copy_user_generic_string(void *to, const void *from, unsigned len);
19900+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19901 __must_check unsigned long
19902-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19903+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19904
19905 static __always_inline __must_check unsigned long
19906-copy_user_generic(void *to, const void *from, unsigned len)
19907+copy_user_generic(void *to, const void *from, unsigned long len)
19908 {
19909 unsigned ret;
19910
19911@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19912 }
19913
19914 __must_check unsigned long
19915-copy_in_user(void __user *to, const void __user *from, unsigned len);
19916+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19917
19918 static __always_inline __must_check
19919-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19920+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19921 {
19922- int ret = 0;
19923+ size_t sz = __compiletime_object_size(dst);
19924+ unsigned ret = 0;
19925+
19926+ if (size > INT_MAX)
19927+ return size;
19928+
19929+ check_object_size(dst, size, false);
19930+
19931+#ifdef CONFIG_PAX_MEMORY_UDEREF
19932+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19933+ return size;
19934+#endif
19935+
19936+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19937+ if(__builtin_constant_p(size))
19938+ copy_from_user_overflow();
19939+ else
19940+ __copy_from_user_overflow(sz, size);
19941+ return size;
19942+ }
19943
19944 if (!__builtin_constant_p(size))
19945- return copy_user_generic(dst, (__force void *)src, size);
19946+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19947 switch (size) {
19948- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19949+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19950 ret, "b", "b", "=q", 1);
19951 return ret;
19952- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19953+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19954 ret, "w", "w", "=r", 2);
19955 return ret;
19956- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19957+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19958 ret, "l", "k", "=r", 4);
19959 return ret;
19960- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19961+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19962 ret, "q", "", "=r", 8);
19963 return ret;
19964 case 10:
19965- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19966+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19967 ret, "q", "", "=r", 10);
19968 if (unlikely(ret))
19969 return ret;
19970 __get_user_asm(*(u16 *)(8 + (char *)dst),
19971- (u16 __user *)(8 + (char __user *)src),
19972+ (const u16 __user *)(8 + (const char __user *)src),
19973 ret, "w", "w", "=r", 2);
19974 return ret;
19975 case 16:
19976- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19977+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19978 ret, "q", "", "=r", 16);
19979 if (unlikely(ret))
19980 return ret;
19981 __get_user_asm(*(u64 *)(8 + (char *)dst),
19982- (u64 __user *)(8 + (char __user *)src),
19983+ (const u64 __user *)(8 + (const char __user *)src),
19984 ret, "q", "", "=r", 8);
19985 return ret;
19986 default:
19987- return copy_user_generic(dst, (__force void *)src, size);
19988+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19989 }
19990 }
19991
19992 static __always_inline __must_check
19993-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19994+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19995 {
19996 might_fault();
19997 return __copy_from_user_nocheck(dst, src, size);
19998 }
19999
20000 static __always_inline __must_check
20001-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20002+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20003 {
20004- int ret = 0;
20005+ size_t sz = __compiletime_object_size(src);
20006+ unsigned ret = 0;
20007+
20008+ if (size > INT_MAX)
20009+ return size;
20010+
20011+ check_object_size(src, size, true);
20012+
20013+#ifdef CONFIG_PAX_MEMORY_UDEREF
20014+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20015+ return size;
20016+#endif
20017+
20018+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20019+ if(__builtin_constant_p(size))
20020+ copy_to_user_overflow();
20021+ else
20022+ __copy_to_user_overflow(sz, size);
20023+ return size;
20024+ }
20025
20026 if (!__builtin_constant_p(size))
20027- return copy_user_generic((__force void *)dst, src, size);
20028+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20029 switch (size) {
20030- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20031+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20032 ret, "b", "b", "iq", 1);
20033 return ret;
20034- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20035+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20036 ret, "w", "w", "ir", 2);
20037 return ret;
20038- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20039+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20040 ret, "l", "k", "ir", 4);
20041 return ret;
20042- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20043+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20044 ret, "q", "", "er", 8);
20045 return ret;
20046 case 10:
20047- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20048+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20049 ret, "q", "", "er", 10);
20050 if (unlikely(ret))
20051 return ret;
20052 asm("":::"memory");
20053- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20054+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20055 ret, "w", "w", "ir", 2);
20056 return ret;
20057 case 16:
20058- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20059+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20060 ret, "q", "", "er", 16);
20061 if (unlikely(ret))
20062 return ret;
20063 asm("":::"memory");
20064- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20065+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20066 ret, "q", "", "er", 8);
20067 return ret;
20068 default:
20069- return copy_user_generic((__force void *)dst, src, size);
20070+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20071 }
20072 }
20073
20074 static __always_inline __must_check
20075-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20076+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20077 {
20078 might_fault();
20079 return __copy_to_user_nocheck(dst, src, size);
20080 }
20081
20082 static __always_inline __must_check
20083-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20084+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20085 {
20086- int ret = 0;
20087+ unsigned ret = 0;
20088
20089 might_fault();
20090+
20091+ if (size > INT_MAX)
20092+ return size;
20093+
20094+#ifdef CONFIG_PAX_MEMORY_UDEREF
20095+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20096+ return size;
20097+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20098+ return size;
20099+#endif
20100+
20101 if (!__builtin_constant_p(size))
20102- return copy_user_generic((__force void *)dst,
20103- (__force void *)src, size);
20104+ return copy_user_generic((__force_kernel void *)____m(dst),
20105+ (__force_kernel const void *)____m(src), size);
20106 switch (size) {
20107 case 1: {
20108 u8 tmp;
20109- __get_user_asm(tmp, (u8 __user *)src,
20110+ __get_user_asm(tmp, (const u8 __user *)src,
20111 ret, "b", "b", "=q", 1);
20112 if (likely(!ret))
20113 __put_user_asm(tmp, (u8 __user *)dst,
20114@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20115 }
20116 case 2: {
20117 u16 tmp;
20118- __get_user_asm(tmp, (u16 __user *)src,
20119+ __get_user_asm(tmp, (const u16 __user *)src,
20120 ret, "w", "w", "=r", 2);
20121 if (likely(!ret))
20122 __put_user_asm(tmp, (u16 __user *)dst,
20123@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20124
20125 case 4: {
20126 u32 tmp;
20127- __get_user_asm(tmp, (u32 __user *)src,
20128+ __get_user_asm(tmp, (const u32 __user *)src,
20129 ret, "l", "k", "=r", 4);
20130 if (likely(!ret))
20131 __put_user_asm(tmp, (u32 __user *)dst,
20132@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20133 }
20134 case 8: {
20135 u64 tmp;
20136- __get_user_asm(tmp, (u64 __user *)src,
20137+ __get_user_asm(tmp, (const u64 __user *)src,
20138 ret, "q", "", "=r", 8);
20139 if (likely(!ret))
20140 __put_user_asm(tmp, (u64 __user *)dst,
20141@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20142 return ret;
20143 }
20144 default:
20145- return copy_user_generic((__force void *)dst,
20146- (__force void *)src, size);
20147+ return copy_user_generic((__force_kernel void *)____m(dst),
20148+ (__force_kernel const void *)____m(src), size);
20149 }
20150 }
20151
20152-static __must_check __always_inline int
20153-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20154+static __must_check __always_inline unsigned long
20155+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20156 {
20157 return __copy_from_user_nocheck(dst, src, size);
20158 }
20159
20160-static __must_check __always_inline int
20161-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20162+static __must_check __always_inline unsigned long
20163+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20164 {
20165 return __copy_to_user_nocheck(dst, src, size);
20166 }
20167
20168-extern long __copy_user_nocache(void *dst, const void __user *src,
20169- unsigned size, int zerorest);
20170+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20171+ unsigned long size, int zerorest);
20172
20173-static inline int
20174-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20175+static inline unsigned long
20176+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20177 {
20178 might_fault();
20179+
20180+ if (size > INT_MAX)
20181+ return size;
20182+
20183+#ifdef CONFIG_PAX_MEMORY_UDEREF
20184+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20185+ return size;
20186+#endif
20187+
20188 return __copy_user_nocache(dst, src, size, 1);
20189 }
20190
20191-static inline int
20192+static inline unsigned long
20193 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20194- unsigned size)
20195+ unsigned long size)
20196 {
20197+ if (size > INT_MAX)
20198+ return size;
20199+
20200+#ifdef CONFIG_PAX_MEMORY_UDEREF
20201+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20202+ return size;
20203+#endif
20204+
20205 return __copy_user_nocache(dst, src, size, 0);
20206 }
20207
20208 unsigned long
20209-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20210+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20211
20212 #endif /* _ASM_X86_UACCESS_64_H */
20213diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20214index 5b238981..77fdd78 100644
20215--- a/arch/x86/include/asm/word-at-a-time.h
20216+++ b/arch/x86/include/asm/word-at-a-time.h
20217@@ -11,7 +11,7 @@
20218 * and shift, for example.
20219 */
20220 struct word_at_a_time {
20221- const unsigned long one_bits, high_bits;
20222+ unsigned long one_bits, high_bits;
20223 };
20224
20225 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20226diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20227index e45e4da..44e8572 100644
20228--- a/arch/x86/include/asm/x86_init.h
20229+++ b/arch/x86/include/asm/x86_init.h
20230@@ -129,7 +129,7 @@ struct x86_init_ops {
20231 struct x86_init_timers timers;
20232 struct x86_init_iommu iommu;
20233 struct x86_init_pci pci;
20234-};
20235+} __no_const;
20236
20237 /**
20238 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20239@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20240 void (*setup_percpu_clockev)(void);
20241 void (*early_percpu_clock_init)(void);
20242 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20243-};
20244+} __no_const;
20245
20246 struct timespec;
20247
20248@@ -168,7 +168,7 @@ struct x86_platform_ops {
20249 void (*save_sched_clock_state)(void);
20250 void (*restore_sched_clock_state)(void);
20251 void (*apic_post_init)(void);
20252-};
20253+} __no_const;
20254
20255 struct pci_dev;
20256 struct msi_msg;
20257@@ -185,7 +185,7 @@ struct x86_msi_ops {
20258 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20259 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20260 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20261-};
20262+} __no_const;
20263
20264 struct IO_APIC_route_entry;
20265 struct io_apic_irq_attr;
20266@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20267 unsigned int destination, int vector,
20268 struct io_apic_irq_attr *attr);
20269 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20270-};
20271+} __no_const;
20272
20273 extern struct x86_init_ops x86_init;
20274 extern struct x86_cpuinit_ops x86_cpuinit;
20275diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20276index c949923..c22bfa4 100644
20277--- a/arch/x86/include/asm/xen/page.h
20278+++ b/arch/x86/include/asm/xen/page.h
20279@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20280 extern struct page *m2p_find_override(unsigned long mfn);
20281 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20282
20283-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20284+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20285 {
20286 unsigned long mfn;
20287
20288diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20289index d949ef2..479b9d1 100644
20290--- a/arch/x86/include/asm/xsave.h
20291+++ b/arch/x86/include/asm/xsave.h
20292@@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20293 if (unlikely(err))
20294 return -EFAULT;
20295
20296+ pax_open_userland();
20297 __asm__ __volatile__(ASM_STAC "\n"
20298- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20299+ "1:"
20300+ __copyuser_seg
20301+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20302 "2: " ASM_CLAC "\n"
20303 ".section .fixup,\"ax\"\n"
20304 "3: movl $-1,%[err]\n"
20305@@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20306 : [err] "=r" (err)
20307 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20308 : "memory");
20309+ pax_close_userland();
20310 return err;
20311 }
20312
20313 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20314 {
20315 int err;
20316- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20317+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20318 u32 lmask = mask;
20319 u32 hmask = mask >> 32;
20320
20321+ pax_open_userland();
20322 __asm__ __volatile__(ASM_STAC "\n"
20323- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20324+ "1:"
20325+ __copyuser_seg
20326+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20327 "2: " ASM_CLAC "\n"
20328 ".section .fixup,\"ax\"\n"
20329 "3: movl $-1,%[err]\n"
20330@@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20331 : [err] "=r" (err)
20332 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20333 : "memory"); /* memory required? */
20334+ pax_close_userland();
20335 return err;
20336 }
20337
20338diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20339index bbae024..e1528f9 100644
20340--- a/arch/x86/include/uapi/asm/e820.h
20341+++ b/arch/x86/include/uapi/asm/e820.h
20342@@ -63,7 +63,7 @@ struct e820map {
20343 #define ISA_START_ADDRESS 0xa0000
20344 #define ISA_END_ADDRESS 0x100000
20345
20346-#define BIOS_BEGIN 0x000a0000
20347+#define BIOS_BEGIN 0x000c0000
20348 #define BIOS_END 0x00100000
20349
20350 #define BIOS_ROM_BASE 0xffe00000
20351diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20352index 7b0a55a..ad115bf 100644
20353--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20354+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20355@@ -49,7 +49,6 @@
20356 #define EFLAGS 144
20357 #define RSP 152
20358 #define SS 160
20359-#define ARGOFFSET R11
20360 #endif /* __ASSEMBLY__ */
20361
20362 /* top of stack page */
20363diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20364index f4d9600..b45af01 100644
20365--- a/arch/x86/kernel/Makefile
20366+++ b/arch/x86/kernel/Makefile
20367@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20368 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20369 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20370 obj-y += probe_roms.o
20371-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20372+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20373 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20374 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20375 obj-$(CONFIG_X86_64) += vsyscall_64.o
20376diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20377index 86281ff..e046fc2 100644
20378--- a/arch/x86/kernel/acpi/boot.c
20379+++ b/arch/x86/kernel/acpi/boot.c
20380@@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20381 * If your system is blacklisted here, but you find that acpi=force
20382 * works for you, please contact linux-acpi@vger.kernel.org
20383 */
20384-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20385+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20386 /*
20387 * Boxes that need ACPI disabled
20388 */
20389@@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20390 };
20391
20392 /* second table for DMI checks that should run after early-quirks */
20393-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20394+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20395 /*
20396 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20397 * which includes some code which overrides all temperature
20398diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20399index 3136820..e2c6577 100644
20400--- a/arch/x86/kernel/acpi/sleep.c
20401+++ b/arch/x86/kernel/acpi/sleep.c
20402@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20403 #else /* CONFIG_64BIT */
20404 #ifdef CONFIG_SMP
20405 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20406+
20407+ pax_open_kernel();
20408 early_gdt_descr.address =
20409 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20410+ pax_close_kernel();
20411+
20412 initial_gs = per_cpu_offset(smp_processor_id());
20413 #endif
20414 initial_code = (unsigned long)wakeup_long64;
20415diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20416index 665c6b7..eae4d56 100644
20417--- a/arch/x86/kernel/acpi/wakeup_32.S
20418+++ b/arch/x86/kernel/acpi/wakeup_32.S
20419@@ -29,13 +29,11 @@ wakeup_pmode_return:
20420 # and restore the stack ... but you need gdt for this to work
20421 movl saved_context_esp, %esp
20422
20423- movl %cs:saved_magic, %eax
20424- cmpl $0x12345678, %eax
20425+ cmpl $0x12345678, saved_magic
20426 jne bogus_magic
20427
20428 # jump to place where we left off
20429- movl saved_eip, %eax
20430- jmp *%eax
20431+ jmp *(saved_eip)
20432
20433 bogus_magic:
20434 jmp bogus_magic
20435diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20436index df94598..b7162f9 100644
20437--- a/arch/x86/kernel/alternative.c
20438+++ b/arch/x86/kernel/alternative.c
20439@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20440 */
20441 for (a = start; a < end; a++) {
20442 instr = (u8 *)&a->instr_offset + a->instr_offset;
20443+
20444+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20445+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20446+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20447+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20448+#endif
20449+
20450 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20451 BUG_ON(a->replacementlen > a->instrlen);
20452 BUG_ON(a->instrlen > sizeof(insnbuf));
20453@@ -285,6 +292,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20454 add_nops(insnbuf + a->replacementlen,
20455 a->instrlen - a->replacementlen);
20456
20457+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20458+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20459+ instr = ktva_ktla(instr);
20460+#endif
20461+
20462 text_poke_early(instr, insnbuf, a->instrlen);
20463 }
20464 }
20465@@ -300,10 +312,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20466 for (poff = start; poff < end; poff++) {
20467 u8 *ptr = (u8 *)poff + *poff;
20468
20469+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20470+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20471+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20472+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20473+#endif
20474+
20475 if (!*poff || ptr < text || ptr >= text_end)
20476 continue;
20477 /* turn DS segment override prefix into lock prefix */
20478- if (*ptr == 0x3e)
20479+ if (*ktla_ktva(ptr) == 0x3e)
20480 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20481 }
20482 mutex_unlock(&text_mutex);
20483@@ -318,10 +336,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20484 for (poff = start; poff < end; poff++) {
20485 u8 *ptr = (u8 *)poff + *poff;
20486
20487+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20488+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20489+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20490+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20491+#endif
20492+
20493 if (!*poff || ptr < text || ptr >= text_end)
20494 continue;
20495 /* turn lock prefix into DS segment override prefix */
20496- if (*ptr == 0xf0)
20497+ if (*ktla_ktva(ptr) == 0xf0)
20498 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20499 }
20500 mutex_unlock(&text_mutex);
20501@@ -458,7 +482,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20502
20503 BUG_ON(p->len > MAX_PATCH_LEN);
20504 /* prep the buffer with the original instructions */
20505- memcpy(insnbuf, p->instr, p->len);
20506+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20507 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20508 (unsigned long)p->instr, p->len);
20509
20510@@ -505,7 +529,7 @@ void __init alternative_instructions(void)
20511 if (!uniproc_patched || num_possible_cpus() == 1)
20512 free_init_pages("SMP alternatives",
20513 (unsigned long)__smp_locks,
20514- (unsigned long)__smp_locks_end);
20515+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20516 #endif
20517
20518 apply_paravirt(__parainstructions, __parainstructions_end);
20519@@ -525,13 +549,17 @@ void __init alternative_instructions(void)
20520 * instructions. And on the local CPU you need to be protected again NMI or MCE
20521 * handlers seeing an inconsistent instruction while you patch.
20522 */
20523-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20524+void *__kprobes text_poke_early(void *addr, const void *opcode,
20525 size_t len)
20526 {
20527 unsigned long flags;
20528 local_irq_save(flags);
20529- memcpy(addr, opcode, len);
20530+
20531+ pax_open_kernel();
20532+ memcpy(ktla_ktva(addr), opcode, len);
20533 sync_core();
20534+ pax_close_kernel();
20535+
20536 local_irq_restore(flags);
20537 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20538 that causes hangs on some VIA CPUs. */
20539@@ -553,36 +581,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20540 */
20541 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20542 {
20543- unsigned long flags;
20544- char *vaddr;
20545+ unsigned char *vaddr = ktla_ktva(addr);
20546 struct page *pages[2];
20547- int i;
20548+ size_t i;
20549
20550 if (!core_kernel_text((unsigned long)addr)) {
20551- pages[0] = vmalloc_to_page(addr);
20552- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20553+ pages[0] = vmalloc_to_page(vaddr);
20554+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20555 } else {
20556- pages[0] = virt_to_page(addr);
20557+ pages[0] = virt_to_page(vaddr);
20558 WARN_ON(!PageReserved(pages[0]));
20559- pages[1] = virt_to_page(addr + PAGE_SIZE);
20560+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20561 }
20562 BUG_ON(!pages[0]);
20563- local_irq_save(flags);
20564- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20565- if (pages[1])
20566- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20567- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20568- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20569- clear_fixmap(FIX_TEXT_POKE0);
20570- if (pages[1])
20571- clear_fixmap(FIX_TEXT_POKE1);
20572- local_flush_tlb();
20573- sync_core();
20574- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20575- that causes hangs on some VIA CPUs. */
20576+ text_poke_early(addr, opcode, len);
20577 for (i = 0; i < len; i++)
20578- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20579- local_irq_restore(flags);
20580+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20581 return addr;
20582 }
20583
20584@@ -602,7 +616,7 @@ int poke_int3_handler(struct pt_regs *regs)
20585 if (likely(!bp_patching_in_progress))
20586 return 0;
20587
20588- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20589+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20590 return 0;
20591
20592 /* set up the specified breakpoint handler */
20593@@ -636,7 +650,7 @@ int poke_int3_handler(struct pt_regs *regs)
20594 */
20595 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20596 {
20597- unsigned char int3 = 0xcc;
20598+ const unsigned char int3 = 0xcc;
20599
20600 bp_int3_handler = handler;
20601 bp_int3_addr = (u8 *)addr + sizeof(int3);
20602diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20603index ad28db7..c538b2c 100644
20604--- a/arch/x86/kernel/apic/apic.c
20605+++ b/arch/x86/kernel/apic/apic.c
20606@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20607 /*
20608 * Debug level, exported for io_apic.c
20609 */
20610-unsigned int apic_verbosity;
20611+int apic_verbosity;
20612
20613 int pic_mode;
20614
20615@@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20616 apic_write(APIC_ESR, 0);
20617 v = apic_read(APIC_ESR);
20618 ack_APIC_irq();
20619- atomic_inc(&irq_err_count);
20620+ atomic_inc_unchecked(&irq_err_count);
20621
20622 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20623 smp_processor_id(), v);
20624diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20625index 7c1b294..e71d27f 100644
20626--- a/arch/x86/kernel/apic/apic_flat_64.c
20627+++ b/arch/x86/kernel/apic/apic_flat_64.c
20628@@ -154,7 +154,7 @@ static int flat_probe(void)
20629 return 1;
20630 }
20631
20632-static struct apic apic_flat = {
20633+static struct apic apic_flat __read_only = {
20634 .name = "flat",
20635 .probe = flat_probe,
20636 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20637@@ -268,7 +268,7 @@ static int physflat_probe(void)
20638 return 0;
20639 }
20640
20641-static struct apic apic_physflat = {
20642+static struct apic apic_physflat __read_only = {
20643
20644 .name = "physical flat",
20645 .probe = physflat_probe,
20646diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20647index 8c7c982..a225910 100644
20648--- a/arch/x86/kernel/apic/apic_noop.c
20649+++ b/arch/x86/kernel/apic/apic_noop.c
20650@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20651 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20652 }
20653
20654-struct apic apic_noop = {
20655+struct apic apic_noop __read_only = {
20656 .name = "noop",
20657 .probe = noop_probe,
20658 .acpi_madt_oem_check = NULL,
20659diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20660index e4840aa..e7d9dac 100644
20661--- a/arch/x86/kernel/apic/bigsmp_32.c
20662+++ b/arch/x86/kernel/apic/bigsmp_32.c
20663@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20664 return dmi_bigsmp;
20665 }
20666
20667-static struct apic apic_bigsmp = {
20668+static struct apic apic_bigsmp __read_only = {
20669
20670 .name = "bigsmp",
20671 .probe = probe_bigsmp,
20672diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20673index 992060e..ecdc3b3 100644
20674--- a/arch/x86/kernel/apic/io_apic.c
20675+++ b/arch/x86/kernel/apic/io_apic.c
20676@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20677 }
20678 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20679
20680-void lock_vector_lock(void)
20681+void lock_vector_lock(void) __acquires(vector_lock)
20682 {
20683 /* Used to the online set of cpus does not change
20684 * during assign_irq_vector.
20685@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20686 raw_spin_lock(&vector_lock);
20687 }
20688
20689-void unlock_vector_lock(void)
20690+void unlock_vector_lock(void) __releases(vector_lock)
20691 {
20692 raw_spin_unlock(&vector_lock);
20693 }
20694@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20695 ack_APIC_irq();
20696 }
20697
20698-atomic_t irq_mis_count;
20699+atomic_unchecked_t irq_mis_count;
20700
20701 #ifdef CONFIG_GENERIC_PENDING_IRQ
20702 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20703@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20704 * at the cpu.
20705 */
20706 if (!(v & (1 << (i & 0x1f)))) {
20707- atomic_inc(&irq_mis_count);
20708+ atomic_inc_unchecked(&irq_mis_count);
20709
20710 eoi_ioapic_irq(irq, cfg);
20711 }
20712diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20713index cceb352..a635fd8 100644
20714--- a/arch/x86/kernel/apic/probe_32.c
20715+++ b/arch/x86/kernel/apic/probe_32.c
20716@@ -72,7 +72,7 @@ static int probe_default(void)
20717 return 1;
20718 }
20719
20720-static struct apic apic_default = {
20721+static struct apic apic_default __read_only = {
20722
20723 .name = "default",
20724 .probe = probe_default,
20725diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20726index e66766b..1c008ba 100644
20727--- a/arch/x86/kernel/apic/x2apic_cluster.c
20728+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20729@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20730 return notifier_from_errno(err);
20731 }
20732
20733-static struct notifier_block __refdata x2apic_cpu_notifier = {
20734+static struct notifier_block x2apic_cpu_notifier = {
20735 .notifier_call = update_clusterinfo,
20736 };
20737
20738@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20739 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20740 }
20741
20742-static struct apic apic_x2apic_cluster = {
20743+static struct apic apic_x2apic_cluster __read_only = {
20744
20745 .name = "cluster x2apic",
20746 .probe = x2apic_cluster_probe,
20747diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20748index 6d600eb..0300c00 100644
20749--- a/arch/x86/kernel/apic/x2apic_phys.c
20750+++ b/arch/x86/kernel/apic/x2apic_phys.c
20751@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20752 return apic == &apic_x2apic_phys;
20753 }
20754
20755-static struct apic apic_x2apic_phys = {
20756+static struct apic apic_x2apic_phys __read_only = {
20757
20758 .name = "physical x2apic",
20759 .probe = x2apic_phys_probe,
20760diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20761index 7834389..4ffc9c8 100644
20762--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20763+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20764@@ -350,7 +350,7 @@ static int uv_probe(void)
20765 return apic == &apic_x2apic_uv_x;
20766 }
20767
20768-static struct apic __refdata apic_x2apic_uv_x = {
20769+static struct apic apic_x2apic_uv_x __read_only = {
20770
20771 .name = "UV large system",
20772 .probe = uv_probe,
20773diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20774index 3ab0343..814c4787 100644
20775--- a/arch/x86/kernel/apm_32.c
20776+++ b/arch/x86/kernel/apm_32.c
20777@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20778 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20779 * even though they are called in protected mode.
20780 */
20781-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20782+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20783 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20784
20785 static const char driver_version[] = "1.16ac"; /* no spaces */
20786@@ -611,7 +611,10 @@ static long __apm_bios_call(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@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20798 &call->esi);
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
20808 return call->eax & 0xff;
20809@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20810 BUG_ON(cpu != 0);
20811 gdt = get_cpu_gdt_table(cpu);
20812 save_desc_40 = gdt[0x40 / 8];
20813+
20814+ pax_open_kernel();
20815 gdt[0x40 / 8] = bad_bios_desc;
20816+ pax_close_kernel();
20817
20818 apm_irq_save(flags);
20819 APM_DO_SAVE_SEGS;
20820@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20821 &call->eax);
20822 APM_DO_RESTORE_SEGS;
20823 apm_irq_restore(flags);
20824+
20825+ pax_open_kernel();
20826 gdt[0x40 / 8] = save_desc_40;
20827+ pax_close_kernel();
20828+
20829 put_cpu();
20830 return error;
20831 }
20832@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20833 * code to that CPU.
20834 */
20835 gdt = get_cpu_gdt_table(0);
20836+
20837+ pax_open_kernel();
20838 set_desc_base(&gdt[APM_CS >> 3],
20839 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20840 set_desc_base(&gdt[APM_CS_16 >> 3],
20841 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20842 set_desc_base(&gdt[APM_DS >> 3],
20843 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20844+ pax_close_kernel();
20845
20846 proc_create("apm", 0, NULL, &apm_file_ops);
20847
20848diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20849index 9f6b934..cf5ffb3 100644
20850--- a/arch/x86/kernel/asm-offsets.c
20851+++ b/arch/x86/kernel/asm-offsets.c
20852@@ -32,6 +32,8 @@ void common(void) {
20853 OFFSET(TI_flags, thread_info, flags);
20854 OFFSET(TI_status, thread_info, status);
20855 OFFSET(TI_addr_limit, thread_info, addr_limit);
20856+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20857+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20858
20859 BLANK();
20860 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20861@@ -52,8 +54,26 @@ void common(void) {
20862 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20863 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20864 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20865+
20866+#ifdef CONFIG_PAX_KERNEXEC
20867+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20868 #endif
20869
20870+#ifdef CONFIG_PAX_MEMORY_UDEREF
20871+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20872+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20873+#ifdef CONFIG_X86_64
20874+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20875+#endif
20876+#endif
20877+
20878+#endif
20879+
20880+ BLANK();
20881+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20882+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20883+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20884+
20885 #ifdef CONFIG_XEN
20886 BLANK();
20887 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20888diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20889index e7c798b..2b2019b 100644
20890--- a/arch/x86/kernel/asm-offsets_64.c
20891+++ b/arch/x86/kernel/asm-offsets_64.c
20892@@ -77,6 +77,7 @@ int main(void)
20893 BLANK();
20894 #undef ENTRY
20895
20896+ DEFINE(TSS_size, sizeof(struct tss_struct));
20897 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20898 BLANK();
20899
20900diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20901index 7fd54f0..0691410 100644
20902--- a/arch/x86/kernel/cpu/Makefile
20903+++ b/arch/x86/kernel/cpu/Makefile
20904@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20905 CFLAGS_REMOVE_perf_event.o = -pg
20906 endif
20907
20908-# Make sure load_percpu_segment has no stackprotector
20909-nostackp := $(call cc-option, -fno-stack-protector)
20910-CFLAGS_common.o := $(nostackp)
20911-
20912 obj-y := intel_cacheinfo.o scattered.o topology.o
20913 obj-y += proc.o capflags.o powerflags.o common.o
20914 obj-y += rdrand.o
20915diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20916index ce8b8ff..d7d8851 100644
20917--- a/arch/x86/kernel/cpu/amd.c
20918+++ b/arch/x86/kernel/cpu/amd.c
20919@@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20920 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20921 {
20922 /* AMD errata T13 (order #21922) */
20923- if ((c->x86 == 6)) {
20924+ if (c->x86 == 6) {
20925 /* Duron Rev A0 */
20926 if (c->x86_model == 3 && c->x86_mask == 0)
20927 size = 64;
20928diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20929index a135239..41fb30a 100644
20930--- a/arch/x86/kernel/cpu/common.c
20931+++ b/arch/x86/kernel/cpu/common.c
20932@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20933
20934 static const struct cpu_dev *this_cpu = &default_cpu;
20935
20936-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20937-#ifdef CONFIG_X86_64
20938- /*
20939- * We need valid kernel segments for data and code in long mode too
20940- * IRET will check the segment types kkeil 2000/10/28
20941- * Also sysret mandates a special GDT layout
20942- *
20943- * TLS descriptors are currently at a different place compared to i386.
20944- * Hopefully nobody expects them at a fixed place (Wine?)
20945- */
20946- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20947- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20948- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20949- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20950- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20951- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20952-#else
20953- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20954- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20955- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20956- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20957- /*
20958- * Segments used for calling PnP BIOS have byte granularity.
20959- * They code segments and data segments have fixed 64k limits,
20960- * the transfer segment sizes are set at run time.
20961- */
20962- /* 32-bit code */
20963- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20964- /* 16-bit code */
20965- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20966- /* 16-bit data */
20967- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20968- /* 16-bit data */
20969- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20970- /* 16-bit data */
20971- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20972- /*
20973- * The APM segments have byte granularity and their bases
20974- * are set at run time. All have 64k limits.
20975- */
20976- /* 32-bit code */
20977- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20978- /* 16-bit code */
20979- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20980- /* data */
20981- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20982-
20983- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20984- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20985- GDT_STACK_CANARY_INIT
20986-#endif
20987-} };
20988-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20989-
20990 static int __init x86_xsave_setup(char *s)
20991 {
20992 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20993@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20994 }
20995 }
20996
20997+#ifdef CONFIG_X86_64
20998+static __init int setup_disable_pcid(char *arg)
20999+{
21000+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21001+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21002+
21003+#ifdef CONFIG_PAX_MEMORY_UDEREF
21004+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21005+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21006+#endif
21007+
21008+ return 1;
21009+}
21010+__setup("nopcid", setup_disable_pcid);
21011+
21012+static void setup_pcid(struct cpuinfo_x86 *c)
21013+{
21014+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21015+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21016+
21017+#ifdef CONFIG_PAX_MEMORY_UDEREF
21018+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21019+ pax_open_kernel();
21020+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21021+ pax_close_kernel();
21022+ printk("PAX: slow and weak UDEREF enabled\n");
21023+ } else
21024+ printk("PAX: UDEREF disabled\n");
21025+#endif
21026+
21027+ return;
21028+ }
21029+
21030+ printk("PAX: PCID detected\n");
21031+ set_in_cr4(X86_CR4_PCIDE);
21032+
21033+#ifdef CONFIG_PAX_MEMORY_UDEREF
21034+ pax_open_kernel();
21035+ clone_pgd_mask = ~(pgdval_t)0UL;
21036+ pax_close_kernel();
21037+ if (pax_user_shadow_base)
21038+ printk("PAX: weak UDEREF enabled\n");
21039+ else {
21040+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21041+ printk("PAX: strong UDEREF enabled\n");
21042+ }
21043+#endif
21044+
21045+ if (cpu_has(c, X86_FEATURE_INVPCID))
21046+ printk("PAX: INVPCID detected\n");
21047+}
21048+#endif
21049+
21050 /*
21051 * Some CPU features depend on higher CPUID levels, which may not always
21052 * be available due to CPUID level capping or broken virtualization
21053@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21054 {
21055 struct desc_ptr gdt_descr;
21056
21057- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21058+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21059 gdt_descr.size = GDT_SIZE - 1;
21060 load_gdt(&gdt_descr);
21061 /* Reload the per-cpu base */
21062@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21063 setup_smep(c);
21064 setup_smap(c);
21065
21066+#ifdef CONFIG_X86_64
21067+ setup_pcid(c);
21068+#endif
21069+
21070 /*
21071 * The vendor-specific functions might have changed features.
21072 * Now we do "generic changes."
21073@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21074 /* Filter out anything that depends on CPUID levels we don't have */
21075 filter_cpuid_features(c, true);
21076
21077+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21078+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21079+#endif
21080+
21081 /* If the model name is still unset, do table lookup. */
21082 if (!c->x86_model_id[0]) {
21083 const char *p;
21084@@ -1079,14 +1086,16 @@ static __init int setup_disablecpuid(char *arg)
21085 }
21086 __setup("clearcpuid=", setup_disablecpuid);
21087
21088+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21089+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21090+
21091 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21092- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21093+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21094 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21095
21096 #ifdef CONFIG_X86_64
21097-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21098-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21099- (unsigned long) debug_idt_table };
21100+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21101+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21102
21103 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21104 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21105@@ -1246,7 +1255,7 @@ void cpu_init(void)
21106 load_ucode_ap();
21107
21108 cpu = stack_smp_processor_id();
21109- t = &per_cpu(init_tss, cpu);
21110+ t = init_tss + cpu;
21111 oist = &per_cpu(orig_ist, cpu);
21112
21113 #ifdef CONFIG_NUMA
21114@@ -1281,7 +1290,6 @@ void cpu_init(void)
21115 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21116 barrier();
21117
21118- x86_configure_nx();
21119 enable_x2apic();
21120
21121 /*
21122@@ -1333,7 +1341,7 @@ void cpu_init(void)
21123 {
21124 int cpu = smp_processor_id();
21125 struct task_struct *curr = current;
21126- struct tss_struct *t = &per_cpu(init_tss, cpu);
21127+ struct tss_struct *t = init_tss + cpu;
21128 struct thread_struct *thread = &curr->thread;
21129
21130 show_ucode_info_early();
21131diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21132index a952e9c..58a4cbb 100644
21133--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21134+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21135@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21136 };
21137
21138 #ifdef CONFIG_AMD_NB
21139+static struct attribute *default_attrs_amd_nb[] = {
21140+ &type.attr,
21141+ &level.attr,
21142+ &coherency_line_size.attr,
21143+ &physical_line_partition.attr,
21144+ &ways_of_associativity.attr,
21145+ &number_of_sets.attr,
21146+ &size.attr,
21147+ &shared_cpu_map.attr,
21148+ &shared_cpu_list.attr,
21149+ NULL,
21150+ NULL,
21151+ NULL,
21152+ NULL
21153+};
21154+
21155 static struct attribute **amd_l3_attrs(void)
21156 {
21157 static struct attribute **attrs;
21158@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21159
21160 n = ARRAY_SIZE(default_attrs);
21161
21162- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21163- n += 2;
21164-
21165- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21166- n += 1;
21167-
21168- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21169- if (attrs == NULL)
21170- return attrs = default_attrs;
21171-
21172- for (n = 0; default_attrs[n]; n++)
21173- attrs[n] = default_attrs[n];
21174+ attrs = default_attrs_amd_nb;
21175
21176 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21177 attrs[n++] = &cache_disable_0.attr;
21178@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21179 .default_attrs = default_attrs,
21180 };
21181
21182+#ifdef CONFIG_AMD_NB
21183+static struct kobj_type ktype_cache_amd_nb = {
21184+ .sysfs_ops = &sysfs_ops,
21185+ .default_attrs = default_attrs_amd_nb,
21186+};
21187+#endif
21188+
21189 static struct kobj_type ktype_percpu_entry = {
21190 .sysfs_ops = &sysfs_ops,
21191 };
21192@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21193 return retval;
21194 }
21195
21196+#ifdef CONFIG_AMD_NB
21197+ amd_l3_attrs();
21198+#endif
21199+
21200 for (i = 0; i < num_cache_leaves; i++) {
21201+ struct kobj_type *ktype;
21202+
21203 this_object = INDEX_KOBJECT_PTR(cpu, i);
21204 this_object->cpu = cpu;
21205 this_object->index = i;
21206
21207 this_leaf = CPUID4_INFO_IDX(cpu, i);
21208
21209- ktype_cache.default_attrs = default_attrs;
21210+ ktype = &ktype_cache;
21211 #ifdef CONFIG_AMD_NB
21212 if (this_leaf->base.nb)
21213- ktype_cache.default_attrs = amd_l3_attrs();
21214+ ktype = &ktype_cache_amd_nb;
21215 #endif
21216 retval = kobject_init_and_add(&(this_object->kobj),
21217- &ktype_cache,
21218+ ktype,
21219 per_cpu(ici_cache_kobject, cpu),
21220 "index%1lu", i);
21221 if (unlikely(retval)) {
21222diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21223index 68317c8..c860d41 100644
21224--- a/arch/x86/kernel/cpu/mcheck/mce.c
21225+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21226@@ -45,6 +45,7 @@
21227 #include <asm/processor.h>
21228 #include <asm/mce.h>
21229 #include <asm/msr.h>
21230+#include <asm/local.h>
21231
21232 #include "mce-internal.h"
21233
21234@@ -261,7 +262,7 @@ static void print_mce(struct mce *m)
21235 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21236 m->cs, m->ip);
21237
21238- if (m->cs == __KERNEL_CS)
21239+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21240 print_symbol("{%s}", m->ip);
21241 pr_cont("\n");
21242 }
21243@@ -294,10 +295,10 @@ static void print_mce(struct mce *m)
21244
21245 #define PANIC_TIMEOUT 5 /* 5 seconds */
21246
21247-static atomic_t mce_paniced;
21248+static atomic_unchecked_t mce_paniced;
21249
21250 static int fake_panic;
21251-static atomic_t mce_fake_paniced;
21252+static atomic_unchecked_t mce_fake_paniced;
21253
21254 /* Panic in progress. Enable interrupts and wait for final IPI */
21255 static void wait_for_panic(void)
21256@@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21257 /*
21258 * Make sure only one CPU runs in machine check panic
21259 */
21260- if (atomic_inc_return(&mce_paniced) > 1)
21261+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21262 wait_for_panic();
21263 barrier();
21264
21265@@ -329,7 +330,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21266 console_verbose();
21267 } else {
21268 /* Don't log too much for fake panic */
21269- if (atomic_inc_return(&mce_fake_paniced) > 1)
21270+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21271 return;
21272 }
21273 /* First print corrected ones that are still unlogged */
21274@@ -368,7 +369,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21275 if (!fake_panic) {
21276 if (panic_timeout == 0)
21277 panic_timeout = mca_cfg.panic_timeout;
21278- panic(msg);
21279+ panic("%s", msg);
21280 } else
21281 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21282 }
21283@@ -699,7 +700,7 @@ static int mce_timed_out(u64 *t)
21284 * might have been modified by someone else.
21285 */
21286 rmb();
21287- if (atomic_read(&mce_paniced))
21288+ if (atomic_read_unchecked(&mce_paniced))
21289 wait_for_panic();
21290 if (!mca_cfg.monarch_timeout)
21291 goto out;
21292@@ -1680,7 +1681,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21293 }
21294
21295 /* Call the installed machine check handler for this CPU setup. */
21296-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21297+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21298 unexpected_machine_check;
21299
21300 /*
21301@@ -1703,7 +1704,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21302 return;
21303 }
21304
21305+ pax_open_kernel();
21306 machine_check_vector = do_machine_check;
21307+ pax_close_kernel();
21308
21309 __mcheck_cpu_init_generic();
21310 __mcheck_cpu_init_vendor(c);
21311@@ -1717,7 +1720,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21312 */
21313
21314 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21315-static int mce_chrdev_open_count; /* #times opened */
21316+static local_t mce_chrdev_open_count; /* #times opened */
21317 static int mce_chrdev_open_exclu; /* already open exclusive? */
21318
21319 static int mce_chrdev_open(struct inode *inode, struct file *file)
21320@@ -1725,7 +1728,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21321 spin_lock(&mce_chrdev_state_lock);
21322
21323 if (mce_chrdev_open_exclu ||
21324- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21325+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21326 spin_unlock(&mce_chrdev_state_lock);
21327
21328 return -EBUSY;
21329@@ -1733,7 +1736,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21330
21331 if (file->f_flags & O_EXCL)
21332 mce_chrdev_open_exclu = 1;
21333- mce_chrdev_open_count++;
21334+ local_inc(&mce_chrdev_open_count);
21335
21336 spin_unlock(&mce_chrdev_state_lock);
21337
21338@@ -1744,7 +1747,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21339 {
21340 spin_lock(&mce_chrdev_state_lock);
21341
21342- mce_chrdev_open_count--;
21343+ local_dec(&mce_chrdev_open_count);
21344 mce_chrdev_open_exclu = 0;
21345
21346 spin_unlock(&mce_chrdev_state_lock);
21347@@ -2420,7 +2423,7 @@ static __init void mce_init_banks(void)
21348
21349 for (i = 0; i < mca_cfg.banks; i++) {
21350 struct mce_bank *b = &mce_banks[i];
21351- struct device_attribute *a = &b->attr;
21352+ device_attribute_no_const *a = &b->attr;
21353
21354 sysfs_attr_init(&a->attr);
21355 a->attr.name = b->attrname;
21356@@ -2492,7 +2495,7 @@ struct dentry *mce_get_debugfs_dir(void)
21357 static void mce_reset(void)
21358 {
21359 cpu_missing = 0;
21360- atomic_set(&mce_fake_paniced, 0);
21361+ atomic_set_unchecked(&mce_fake_paniced, 0);
21362 atomic_set(&mce_executing, 0);
21363 atomic_set(&mce_callin, 0);
21364 atomic_set(&global_nwo, 0);
21365diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21366index a304298..49b6d06 100644
21367--- a/arch/x86/kernel/cpu/mcheck/p5.c
21368+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21369@@ -10,6 +10,7 @@
21370 #include <asm/processor.h>
21371 #include <asm/mce.h>
21372 #include <asm/msr.h>
21373+#include <asm/pgtable.h>
21374
21375 /* By default disabled */
21376 int mce_p5_enabled __read_mostly;
21377@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21378 if (!cpu_has(c, X86_FEATURE_MCE))
21379 return;
21380
21381+ pax_open_kernel();
21382 machine_check_vector = pentium_machine_check;
21383+ pax_close_kernel();
21384 /* Make sure the vector pointer is visible before we enable MCEs: */
21385 wmb();
21386
21387diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21388index 7dc5564..1273569 100644
21389--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21390+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21391@@ -9,6 +9,7 @@
21392 #include <asm/processor.h>
21393 #include <asm/mce.h>
21394 #include <asm/msr.h>
21395+#include <asm/pgtable.h>
21396
21397 /* Machine check handler for WinChip C6: */
21398 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21399@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21400 {
21401 u32 lo, hi;
21402
21403+ pax_open_kernel();
21404 machine_check_vector = winchip_machine_check;
21405+ pax_close_kernel();
21406 /* Make sure the vector pointer is visible before we enable MCEs: */
21407 wmb();
21408
21409diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21410index 15c9876..0a43909 100644
21411--- a/arch/x86/kernel/cpu/microcode/core.c
21412+++ b/arch/x86/kernel/cpu/microcode/core.c
21413@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21414 return NOTIFY_OK;
21415 }
21416
21417-static struct notifier_block __refdata mc_cpu_notifier = {
21418+static struct notifier_block mc_cpu_notifier = {
21419 .notifier_call = mc_cpu_callback,
21420 };
21421
21422diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21423index a276fa7..e66810f 100644
21424--- a/arch/x86/kernel/cpu/microcode/intel.c
21425+++ b/arch/x86/kernel/cpu/microcode/intel.c
21426@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21427
21428 static int get_ucode_user(void *to, const void *from, size_t n)
21429 {
21430- return copy_from_user(to, from, n);
21431+ return copy_from_user(to, (const void __force_user *)from, n);
21432 }
21433
21434 static enum ucode_state
21435 request_microcode_user(int cpu, const void __user *buf, size_t size)
21436 {
21437- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21438+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21439 }
21440
21441 static void microcode_fini_cpu(int cpu)
21442diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21443index f961de9..8a9d332 100644
21444--- a/arch/x86/kernel/cpu/mtrr/main.c
21445+++ b/arch/x86/kernel/cpu/mtrr/main.c
21446@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21447 u64 size_or_mask, size_and_mask;
21448 static bool mtrr_aps_delayed_init;
21449
21450-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21451+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21452
21453 const struct mtrr_ops *mtrr_if;
21454
21455diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21456index df5e41f..816c719 100644
21457--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21458+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21459@@ -25,7 +25,7 @@ struct mtrr_ops {
21460 int (*validate_add_page)(unsigned long base, unsigned long size,
21461 unsigned int type);
21462 int (*have_wrcomb)(void);
21463-};
21464+} __do_const;
21465
21466 extern int generic_get_free_region(unsigned long base, unsigned long size,
21467 int replace_reg);
21468diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21469index ae407f7..39c5b00 100644
21470--- a/arch/x86/kernel/cpu/perf_event.c
21471+++ b/arch/x86/kernel/cpu/perf_event.c
21472@@ -1367,7 +1367,7 @@ static void __init pmu_check_apic(void)
21473 pr_info("no hardware sampling interrupt available.\n");
21474 }
21475
21476-static struct attribute_group x86_pmu_format_group = {
21477+static attribute_group_no_const x86_pmu_format_group = {
21478 .name = "format",
21479 .attrs = NULL,
21480 };
21481@@ -1466,7 +1466,7 @@ static struct attribute *events_attr[] = {
21482 NULL,
21483 };
21484
21485-static struct attribute_group x86_pmu_events_group = {
21486+static attribute_group_no_const x86_pmu_events_group = {
21487 .name = "events",
21488 .attrs = events_attr,
21489 };
21490@@ -1990,7 +1990,7 @@ static unsigned long get_segment_base(unsigned int segment)
21491 if (idx > GDT_ENTRIES)
21492 return 0;
21493
21494- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21495+ desc = get_cpu_gdt_table(smp_processor_id());
21496 }
21497
21498 return get_desc_base(desc + idx);
21499@@ -2080,7 +2080,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21500 break;
21501
21502 perf_callchain_store(entry, frame.return_address);
21503- fp = frame.next_frame;
21504+ fp = (const void __force_user *)frame.next_frame;
21505 }
21506 }
21507
21508diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21509index 639d128..e92d7e5 100644
21510--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21511+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21512@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21513 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21514 {
21515 struct attribute **attrs;
21516- struct attribute_group *attr_group;
21517+ attribute_group_no_const *attr_group;
21518 int i = 0, j;
21519
21520 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21521diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21522index adb02aa..9688c02 100644
21523--- a/arch/x86/kernel/cpu/perf_event_intel.c
21524+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21525@@ -2308,10 +2308,10 @@ __init int intel_pmu_init(void)
21526 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21527
21528 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21529- u64 capabilities;
21530+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21531
21532- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21533- x86_pmu.intel_cap.capabilities = capabilities;
21534+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21535+ x86_pmu.intel_cap.capabilities = capabilities;
21536 }
21537
21538 intel_ds_init();
21539diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21540index 619f769..d510008 100644
21541--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21542+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21543@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21544 NULL,
21545 };
21546
21547-static struct attribute_group rapl_pmu_events_group = {
21548+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21549 .name = "events",
21550 .attrs = NULL, /* patched at runtime */
21551 };
21552diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21553index 65bbbea..1438d9e 100644
21554--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21555+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21556@@ -3693,7 +3693,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21557 static int __init uncore_type_init(struct intel_uncore_type *type)
21558 {
21559 struct intel_uncore_pmu *pmus;
21560- struct attribute_group *attr_group;
21561+ attribute_group_no_const *attr_group;
21562 struct attribute **attrs;
21563 int i, j;
21564
21565diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21566index 90236f0..54cb20d 100644
21567--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21568+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21569@@ -503,7 +503,7 @@ struct intel_uncore_box {
21570 struct uncore_event_desc {
21571 struct kobj_attribute attr;
21572 const char *config;
21573-};
21574+} __do_const;
21575
21576 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21577 { \
21578diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21579index 3225ae6c..ee3c6db 100644
21580--- a/arch/x86/kernel/cpuid.c
21581+++ b/arch/x86/kernel/cpuid.c
21582@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21583 return notifier_from_errno(err);
21584 }
21585
21586-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21587+static struct notifier_block cpuid_class_cpu_notifier =
21588 {
21589 .notifier_call = cpuid_class_cpu_callback,
21590 };
21591diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21592index 507de80..ebaae2a 100644
21593--- a/arch/x86/kernel/crash.c
21594+++ b/arch/x86/kernel/crash.c
21595@@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21596 #ifdef CONFIG_X86_32
21597 struct pt_regs fixed_regs;
21598
21599- if (!user_mode_vm(regs)) {
21600+ if (!user_mode(regs)) {
21601 crash_fixup_ss_esp(&fixed_regs, regs);
21602 regs = &fixed_regs;
21603 }
21604diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21605index afa64ad..dce67dd 100644
21606--- a/arch/x86/kernel/crash_dump_64.c
21607+++ b/arch/x86/kernel/crash_dump_64.c
21608@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21609 return -ENOMEM;
21610
21611 if (userbuf) {
21612- if (copy_to_user(buf, vaddr + offset, csize)) {
21613+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21614 iounmap(vaddr);
21615 return -EFAULT;
21616 }
21617diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21618index f6dfd93..892ade4 100644
21619--- a/arch/x86/kernel/doublefault.c
21620+++ b/arch/x86/kernel/doublefault.c
21621@@ -12,7 +12,7 @@
21622
21623 #define DOUBLEFAULT_STACKSIZE (1024)
21624 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21625-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21626+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21627
21628 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21629
21630@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21631 unsigned long gdt, tss;
21632
21633 native_store_gdt(&gdt_desc);
21634- gdt = gdt_desc.address;
21635+ gdt = (unsigned long)gdt_desc.address;
21636
21637 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21638
21639@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21640 /* 0x2 bit is always set */
21641 .flags = X86_EFLAGS_SF | 0x2,
21642 .sp = STACK_START,
21643- .es = __USER_DS,
21644+ .es = __KERNEL_DS,
21645 .cs = __KERNEL_CS,
21646 .ss = __KERNEL_DS,
21647- .ds = __USER_DS,
21648+ .ds = __KERNEL_DS,
21649 .fs = __KERNEL_PERCPU,
21650
21651 .__cr3 = __pa_nodebug(swapper_pg_dir),
21652diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21653index d9c12d3..7858b62 100644
21654--- a/arch/x86/kernel/dumpstack.c
21655+++ b/arch/x86/kernel/dumpstack.c
21656@@ -2,6 +2,9 @@
21657 * Copyright (C) 1991, 1992 Linus Torvalds
21658 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21659 */
21660+#ifdef CONFIG_GRKERNSEC_HIDESYM
21661+#define __INCLUDED_BY_HIDESYM 1
21662+#endif
21663 #include <linux/kallsyms.h>
21664 #include <linux/kprobes.h>
21665 #include <linux/uaccess.h>
21666@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21667 static void
21668 print_ftrace_graph_addr(unsigned long addr, void *data,
21669 const struct stacktrace_ops *ops,
21670- struct thread_info *tinfo, int *graph)
21671+ struct task_struct *task, int *graph)
21672 {
21673- struct task_struct *task;
21674 unsigned long ret_addr;
21675 int index;
21676
21677 if (addr != (unsigned long)return_to_handler)
21678 return;
21679
21680- task = tinfo->task;
21681 index = task->curr_ret_stack;
21682
21683 if (!task->ret_stack || index < *graph)
21684@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21685 static inline void
21686 print_ftrace_graph_addr(unsigned long addr, void *data,
21687 const struct stacktrace_ops *ops,
21688- struct thread_info *tinfo, int *graph)
21689+ struct task_struct *task, int *graph)
21690 { }
21691 #endif
21692
21693@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21694 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21695 */
21696
21697-static inline int valid_stack_ptr(struct thread_info *tinfo,
21698- void *p, unsigned int size, void *end)
21699+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21700 {
21701- void *t = tinfo;
21702 if (end) {
21703 if (p < end && p >= (end-THREAD_SIZE))
21704 return 1;
21705@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21706 }
21707
21708 unsigned long
21709-print_context_stack(struct thread_info *tinfo,
21710+print_context_stack(struct task_struct *task, void *stack_start,
21711 unsigned long *stack, unsigned long bp,
21712 const struct stacktrace_ops *ops, void *data,
21713 unsigned long *end, int *graph)
21714 {
21715 struct stack_frame *frame = (struct stack_frame *)bp;
21716
21717- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21718+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21719 unsigned long addr;
21720
21721 addr = *stack;
21722@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21723 } else {
21724 ops->address(data, addr, 0);
21725 }
21726- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21727+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21728 }
21729 stack++;
21730 }
21731@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21732 EXPORT_SYMBOL_GPL(print_context_stack);
21733
21734 unsigned long
21735-print_context_stack_bp(struct thread_info *tinfo,
21736+print_context_stack_bp(struct task_struct *task, void *stack_start,
21737 unsigned long *stack, unsigned long bp,
21738 const struct stacktrace_ops *ops, void *data,
21739 unsigned long *end, int *graph)
21740@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21741 struct stack_frame *frame = (struct stack_frame *)bp;
21742 unsigned long *ret_addr = &frame->return_address;
21743
21744- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21745+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21746 unsigned long addr = *ret_addr;
21747
21748 if (!__kernel_text_address(addr))
21749@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21750 ops->address(data, addr, 1);
21751 frame = frame->next_frame;
21752 ret_addr = &frame->return_address;
21753- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21754+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21755 }
21756
21757 return (unsigned long)frame;
21758@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21759 static void print_trace_address(void *data, unsigned long addr, int reliable)
21760 {
21761 touch_nmi_watchdog();
21762- printk(data);
21763+ printk("%s", (char *)data);
21764 printk_stack_address(addr, reliable);
21765 }
21766
21767@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21768 }
21769 EXPORT_SYMBOL_GPL(oops_begin);
21770
21771+extern void gr_handle_kernel_exploit(void);
21772+
21773 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21774 {
21775 if (regs && kexec_should_crash(current))
21776@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21777 panic("Fatal exception in interrupt");
21778 if (panic_on_oops)
21779 panic("Fatal exception");
21780- do_exit(signr);
21781+
21782+ gr_handle_kernel_exploit();
21783+
21784+ do_group_exit(signr);
21785 }
21786
21787 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21788@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21789 print_modules();
21790 show_regs(regs);
21791 #ifdef CONFIG_X86_32
21792- if (user_mode_vm(regs)) {
21793+ if (user_mode(regs)) {
21794 sp = regs->sp;
21795 ss = regs->ss & 0xffff;
21796 } else {
21797@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21798 unsigned long flags = oops_begin();
21799 int sig = SIGSEGV;
21800
21801- if (!user_mode_vm(regs))
21802+ if (!user_mode(regs))
21803 report_bug(regs->ip, regs);
21804
21805 if (__die(str, regs, err))
21806diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21807index 5abd4cd..c65733b 100644
21808--- a/arch/x86/kernel/dumpstack_32.c
21809+++ b/arch/x86/kernel/dumpstack_32.c
21810@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21811 bp = stack_frame(task, regs);
21812
21813 for (;;) {
21814- struct thread_info *context;
21815+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21816 void *end_stack;
21817
21818 end_stack = is_hardirq_stack(stack, cpu);
21819 if (!end_stack)
21820 end_stack = is_softirq_stack(stack, cpu);
21821
21822- context = task_thread_info(task);
21823- bp = ops->walk_stack(context, stack, bp, ops, data,
21824+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
21825 end_stack, &graph);
21826
21827 /* Stop if not on irq stack */
21828@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
21829 int i;
21830
21831 show_regs_print_info(KERN_EMERG);
21832- __show_regs(regs, !user_mode_vm(regs));
21833+ __show_regs(regs, !user_mode(regs));
21834
21835 /*
21836 * When in-kernel, we also print out the stack and code at the
21837 * time of the fault..
21838 */
21839- if (!user_mode_vm(regs)) {
21840+ if (!user_mode(regs)) {
21841 unsigned int code_prologue = code_bytes * 43 / 64;
21842 unsigned int code_len = code_bytes;
21843 unsigned char c;
21844 u8 *ip;
21845+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21846
21847 pr_emerg("Stack:\n");
21848 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21849
21850 pr_emerg("Code:");
21851
21852- ip = (u8 *)regs->ip - code_prologue;
21853+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21854 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21855 /* try starting at IP */
21856- ip = (u8 *)regs->ip;
21857+ ip = (u8 *)regs->ip + cs_base;
21858 code_len = code_len - code_prologue + 1;
21859 }
21860 for (i = 0; i < code_len; i++, ip++) {
21861@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
21862 pr_cont(" Bad EIP value.");
21863 break;
21864 }
21865- if (ip == (u8 *)regs->ip)
21866+ if (ip == (u8 *)regs->ip + cs_base)
21867 pr_cont(" <%02x>", c);
21868 else
21869 pr_cont(" %02x", c);
21870@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
21871 {
21872 unsigned short ud2;
21873
21874+ ip = ktla_ktva(ip);
21875 if (ip < PAGE_OFFSET)
21876 return 0;
21877 if (probe_kernel_address((unsigned short *)ip, ud2))
21878@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
21879
21880 return ud2 == 0x0b0f;
21881 }
21882+
21883+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21884+void pax_check_alloca(unsigned long size)
21885+{
21886+ unsigned long sp = (unsigned long)&sp, stack_left;
21887+
21888+ /* all kernel stacks are of the same size */
21889+ stack_left = sp & (THREAD_SIZE - 1);
21890+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21891+}
21892+EXPORT_SYMBOL(pax_check_alloca);
21893+#endif
21894diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21895index 1abcb50..6c8d702 100644
21896--- a/arch/x86/kernel/dumpstack_64.c
21897+++ b/arch/x86/kernel/dumpstack_64.c
21898@@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21899 const struct stacktrace_ops *ops, void *data)
21900 {
21901 const unsigned cpu = get_cpu();
21902- struct thread_info *tinfo;
21903 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21904 unsigned long dummy;
21905 unsigned used = 0;
21906 int graph = 0;
21907 int done = 0;
21908+ void *stack_start;
21909
21910 if (!task)
21911 task = current;
21912@@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21913 * current stack address. If the stacks consist of nested
21914 * exceptions
21915 */
21916- tinfo = task_thread_info(task);
21917 while (!done) {
21918 unsigned long *stack_end;
21919 enum stack_type stype;
21920@@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21921 if (ops->stack(data, id) < 0)
21922 break;
21923
21924- bp = ops->walk_stack(tinfo, stack, bp, ops,
21925+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
21926 data, stack_end, &graph);
21927 ops->stack(data, "<EOE>");
21928 /*
21929@@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21930 * second-to-last pointer (index -2 to end) in the
21931 * exception stack:
21932 */
21933+ if ((u16)stack_end[-1] != __KERNEL_DS)
21934+ goto out;
21935 stack = (unsigned long *) stack_end[-2];
21936 done = 0;
21937 break;
21938@@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21939
21940 if (ops->stack(data, "IRQ") < 0)
21941 break;
21942- bp = ops->walk_stack(tinfo, stack, bp,
21943+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21944 ops, data, stack_end, &graph);
21945 /*
21946 * We link to the next stack (which would be
21947@@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21948 /*
21949 * This handles the process stack:
21950 */
21951- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21952+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21953+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21954+out:
21955 put_cpu();
21956 }
21957 EXPORT_SYMBOL(dump_trace);
21958@@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
21959
21960 return ud2 == 0x0b0f;
21961 }
21962+
21963+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21964+void pax_check_alloca(unsigned long size)
21965+{
21966+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21967+ unsigned cpu, used;
21968+ char *id;
21969+
21970+ /* check the process stack first */
21971+ stack_start = (unsigned long)task_stack_page(current);
21972+ stack_end = stack_start + THREAD_SIZE;
21973+ if (likely(stack_start <= sp && sp < stack_end)) {
21974+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21975+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21976+ return;
21977+ }
21978+
21979+ cpu = get_cpu();
21980+
21981+ /* check the irq stacks */
21982+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21983+ stack_start = stack_end - IRQ_STACK_SIZE;
21984+ if (stack_start <= sp && sp < stack_end) {
21985+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21986+ put_cpu();
21987+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21988+ return;
21989+ }
21990+
21991+ /* check the exception stacks */
21992+ used = 0;
21993+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21994+ stack_start = stack_end - EXCEPTION_STKSZ;
21995+ if (stack_end && stack_start <= sp && sp < stack_end) {
21996+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21997+ put_cpu();
21998+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21999+ return;
22000+ }
22001+
22002+ put_cpu();
22003+
22004+ /* unknown stack */
22005+ BUG();
22006+}
22007+EXPORT_SYMBOL(pax_check_alloca);
22008+#endif
22009diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22010index 988c00a..4f673b6 100644
22011--- a/arch/x86/kernel/e820.c
22012+++ b/arch/x86/kernel/e820.c
22013@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22014
22015 static void early_panic(char *msg)
22016 {
22017- early_printk(msg);
22018- panic(msg);
22019+ early_printk("%s", msg);
22020+ panic("%s", msg);
22021 }
22022
22023 static int userdef __initdata;
22024diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22025index 01d1c18..8073693 100644
22026--- a/arch/x86/kernel/early_printk.c
22027+++ b/arch/x86/kernel/early_printk.c
22028@@ -7,6 +7,7 @@
22029 #include <linux/pci_regs.h>
22030 #include <linux/pci_ids.h>
22031 #include <linux/errno.h>
22032+#include <linux/sched.h>
22033 #include <asm/io.h>
22034 #include <asm/processor.h>
22035 #include <asm/fcntl.h>
22036diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22037index 6491353..a918952 100644
22038--- a/arch/x86/kernel/entry_32.S
22039+++ b/arch/x86/kernel/entry_32.S
22040@@ -177,13 +177,153 @@
22041 /*CFI_REL_OFFSET gs, PT_GS*/
22042 .endm
22043 .macro SET_KERNEL_GS reg
22044+
22045+#ifdef CONFIG_CC_STACKPROTECTOR
22046 movl $(__KERNEL_STACK_CANARY), \reg
22047+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22048+ movl $(__USER_DS), \reg
22049+#else
22050+ xorl \reg, \reg
22051+#endif
22052+
22053 movl \reg, %gs
22054 .endm
22055
22056 #endif /* CONFIG_X86_32_LAZY_GS */
22057
22058-.macro SAVE_ALL
22059+.macro pax_enter_kernel
22060+#ifdef CONFIG_PAX_KERNEXEC
22061+ call pax_enter_kernel
22062+#endif
22063+.endm
22064+
22065+.macro pax_exit_kernel
22066+#ifdef CONFIG_PAX_KERNEXEC
22067+ call pax_exit_kernel
22068+#endif
22069+.endm
22070+
22071+#ifdef CONFIG_PAX_KERNEXEC
22072+ENTRY(pax_enter_kernel)
22073+#ifdef CONFIG_PARAVIRT
22074+ pushl %eax
22075+ pushl %ecx
22076+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22077+ mov %eax, %esi
22078+#else
22079+ mov %cr0, %esi
22080+#endif
22081+ bts $16, %esi
22082+ jnc 1f
22083+ mov %cs, %esi
22084+ cmp $__KERNEL_CS, %esi
22085+ jz 3f
22086+ ljmp $__KERNEL_CS, $3f
22087+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22088+2:
22089+#ifdef CONFIG_PARAVIRT
22090+ mov %esi, %eax
22091+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22092+#else
22093+ mov %esi, %cr0
22094+#endif
22095+3:
22096+#ifdef CONFIG_PARAVIRT
22097+ popl %ecx
22098+ popl %eax
22099+#endif
22100+ ret
22101+ENDPROC(pax_enter_kernel)
22102+
22103+ENTRY(pax_exit_kernel)
22104+#ifdef CONFIG_PARAVIRT
22105+ pushl %eax
22106+ pushl %ecx
22107+#endif
22108+ mov %cs, %esi
22109+ cmp $__KERNEXEC_KERNEL_CS, %esi
22110+ jnz 2f
22111+#ifdef CONFIG_PARAVIRT
22112+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22113+ mov %eax, %esi
22114+#else
22115+ mov %cr0, %esi
22116+#endif
22117+ btr $16, %esi
22118+ ljmp $__KERNEL_CS, $1f
22119+1:
22120+#ifdef CONFIG_PARAVIRT
22121+ mov %esi, %eax
22122+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22123+#else
22124+ mov %esi, %cr0
22125+#endif
22126+2:
22127+#ifdef CONFIG_PARAVIRT
22128+ popl %ecx
22129+ popl %eax
22130+#endif
22131+ ret
22132+ENDPROC(pax_exit_kernel)
22133+#endif
22134+
22135+ .macro pax_erase_kstack
22136+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22137+ call pax_erase_kstack
22138+#endif
22139+ .endm
22140+
22141+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22142+/*
22143+ * ebp: thread_info
22144+ */
22145+ENTRY(pax_erase_kstack)
22146+ pushl %edi
22147+ pushl %ecx
22148+ pushl %eax
22149+
22150+ mov TI_lowest_stack(%ebp), %edi
22151+ mov $-0xBEEF, %eax
22152+ std
22153+
22154+1: mov %edi, %ecx
22155+ and $THREAD_SIZE_asm - 1, %ecx
22156+ shr $2, %ecx
22157+ repne scasl
22158+ jecxz 2f
22159+
22160+ cmp $2*16, %ecx
22161+ jc 2f
22162+
22163+ mov $2*16, %ecx
22164+ repe scasl
22165+ jecxz 2f
22166+ jne 1b
22167+
22168+2: cld
22169+ mov %esp, %ecx
22170+ sub %edi, %ecx
22171+
22172+ cmp $THREAD_SIZE_asm, %ecx
22173+ jb 3f
22174+ ud2
22175+3:
22176+
22177+ shr $2, %ecx
22178+ rep stosl
22179+
22180+ mov TI_task_thread_sp0(%ebp), %edi
22181+ sub $128, %edi
22182+ mov %edi, TI_lowest_stack(%ebp)
22183+
22184+ popl %eax
22185+ popl %ecx
22186+ popl %edi
22187+ ret
22188+ENDPROC(pax_erase_kstack)
22189+#endif
22190+
22191+.macro __SAVE_ALL _DS
22192 cld
22193 PUSH_GS
22194 pushl_cfi %fs
22195@@ -206,7 +346,7 @@
22196 CFI_REL_OFFSET ecx, 0
22197 pushl_cfi %ebx
22198 CFI_REL_OFFSET ebx, 0
22199- movl $(__USER_DS), %edx
22200+ movl $\_DS, %edx
22201 movl %edx, %ds
22202 movl %edx, %es
22203 movl $(__KERNEL_PERCPU), %edx
22204@@ -214,6 +354,15 @@
22205 SET_KERNEL_GS %edx
22206 .endm
22207
22208+.macro SAVE_ALL
22209+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22210+ __SAVE_ALL __KERNEL_DS
22211+ pax_enter_kernel
22212+#else
22213+ __SAVE_ALL __USER_DS
22214+#endif
22215+.endm
22216+
22217 .macro RESTORE_INT_REGS
22218 popl_cfi %ebx
22219 CFI_RESTORE ebx
22220@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22221 popfl_cfi
22222 jmp syscall_exit
22223 CFI_ENDPROC
22224-END(ret_from_fork)
22225+ENDPROC(ret_from_fork)
22226
22227 ENTRY(ret_from_kernel_thread)
22228 CFI_STARTPROC
22229@@ -344,7 +493,15 @@ ret_from_intr:
22230 andl $SEGMENT_RPL_MASK, %eax
22231 #endif
22232 cmpl $USER_RPL, %eax
22233+
22234+#ifdef CONFIG_PAX_KERNEXEC
22235+ jae resume_userspace
22236+
22237+ pax_exit_kernel
22238+ jmp resume_kernel
22239+#else
22240 jb resume_kernel # not returning to v8086 or userspace
22241+#endif
22242
22243 ENTRY(resume_userspace)
22244 LOCKDEP_SYS_EXIT
22245@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22246 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22247 # int/exception return?
22248 jne work_pending
22249- jmp restore_all
22250-END(ret_from_exception)
22251+ jmp restore_all_pax
22252+ENDPROC(ret_from_exception)
22253
22254 #ifdef CONFIG_PREEMPT
22255 ENTRY(resume_kernel)
22256@@ -369,7 +526,7 @@ need_resched:
22257 jz restore_all
22258 call preempt_schedule_irq
22259 jmp need_resched
22260-END(resume_kernel)
22261+ENDPROC(resume_kernel)
22262 #endif
22263 CFI_ENDPROC
22264 /*
22265@@ -403,30 +560,45 @@ sysenter_past_esp:
22266 /*CFI_REL_OFFSET cs, 0*/
22267 /*
22268 * Push current_thread_info()->sysenter_return to the stack.
22269- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22270- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22271 */
22272- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22273+ pushl_cfi $0
22274 CFI_REL_OFFSET eip, 0
22275
22276 pushl_cfi %eax
22277 SAVE_ALL
22278+ GET_THREAD_INFO(%ebp)
22279+ movl TI_sysenter_return(%ebp),%ebp
22280+ movl %ebp,PT_EIP(%esp)
22281 ENABLE_INTERRUPTS(CLBR_NONE)
22282
22283 /*
22284 * Load the potential sixth argument from user stack.
22285 * Careful about security.
22286 */
22287+ movl PT_OLDESP(%esp),%ebp
22288+
22289+#ifdef CONFIG_PAX_MEMORY_UDEREF
22290+ mov PT_OLDSS(%esp),%ds
22291+1: movl %ds:(%ebp),%ebp
22292+ push %ss
22293+ pop %ds
22294+#else
22295 cmpl $__PAGE_OFFSET-3,%ebp
22296 jae syscall_fault
22297 ASM_STAC
22298 1: movl (%ebp),%ebp
22299 ASM_CLAC
22300+#endif
22301+
22302 movl %ebp,PT_EBP(%esp)
22303 _ASM_EXTABLE(1b,syscall_fault)
22304
22305 GET_THREAD_INFO(%ebp)
22306
22307+#ifdef CONFIG_PAX_RANDKSTACK
22308+ pax_erase_kstack
22309+#endif
22310+
22311 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22312 jnz sysenter_audit
22313 sysenter_do_call:
22314@@ -442,12 +614,24 @@ sysenter_after_call:
22315 testl $_TIF_ALLWORK_MASK, %ecx
22316 jne sysexit_audit
22317 sysenter_exit:
22318+
22319+#ifdef CONFIG_PAX_RANDKSTACK
22320+ pushl_cfi %eax
22321+ movl %esp, %eax
22322+ call pax_randomize_kstack
22323+ popl_cfi %eax
22324+#endif
22325+
22326+ pax_erase_kstack
22327+
22328 /* if something modifies registers it must also disable sysexit */
22329 movl PT_EIP(%esp), %edx
22330 movl PT_OLDESP(%esp), %ecx
22331 xorl %ebp,%ebp
22332 TRACE_IRQS_ON
22333 1: mov PT_FS(%esp), %fs
22334+2: mov PT_DS(%esp), %ds
22335+3: mov PT_ES(%esp), %es
22336 PTGS_TO_GS
22337 ENABLE_INTERRUPTS_SYSEXIT
22338
22339@@ -464,6 +648,9 @@ sysenter_audit:
22340 movl %eax,%edx /* 2nd arg: syscall number */
22341 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22342 call __audit_syscall_entry
22343+
22344+ pax_erase_kstack
22345+
22346 pushl_cfi %ebx
22347 movl PT_EAX(%esp),%eax /* reload syscall number */
22348 jmp sysenter_do_call
22349@@ -489,10 +676,16 @@ sysexit_audit:
22350
22351 CFI_ENDPROC
22352 .pushsection .fixup,"ax"
22353-2: movl $0,PT_FS(%esp)
22354+4: movl $0,PT_FS(%esp)
22355+ jmp 1b
22356+5: movl $0,PT_DS(%esp)
22357+ jmp 1b
22358+6: movl $0,PT_ES(%esp)
22359 jmp 1b
22360 .popsection
22361- _ASM_EXTABLE(1b,2b)
22362+ _ASM_EXTABLE(1b,4b)
22363+ _ASM_EXTABLE(2b,5b)
22364+ _ASM_EXTABLE(3b,6b)
22365 PTGS_TO_GS_EX
22366 ENDPROC(ia32_sysenter_target)
22367
22368@@ -507,6 +700,11 @@ ENTRY(system_call)
22369 pushl_cfi %eax # save orig_eax
22370 SAVE_ALL
22371 GET_THREAD_INFO(%ebp)
22372+
22373+#ifdef CONFIG_PAX_RANDKSTACK
22374+ pax_erase_kstack
22375+#endif
22376+
22377 # system call tracing in operation / emulation
22378 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22379 jnz syscall_trace_entry
22380@@ -525,6 +723,15 @@ syscall_exit:
22381 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22382 jne syscall_exit_work
22383
22384+restore_all_pax:
22385+
22386+#ifdef CONFIG_PAX_RANDKSTACK
22387+ movl %esp, %eax
22388+ call pax_randomize_kstack
22389+#endif
22390+
22391+ pax_erase_kstack
22392+
22393 restore_all:
22394 TRACE_IRQS_IRET
22395 restore_all_notrace:
22396@@ -576,14 +783,34 @@ ldt_ss:
22397 * compensating for the offset by changing to the ESPFIX segment with
22398 * a base address that matches for the difference.
22399 */
22400-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22401+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22402 mov %esp, %edx /* load kernel esp */
22403 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22404 mov %dx, %ax /* eax: new kernel esp */
22405 sub %eax, %edx /* offset (low word is 0) */
22406+#ifdef CONFIG_SMP
22407+ movl PER_CPU_VAR(cpu_number), %ebx
22408+ shll $PAGE_SHIFT_asm, %ebx
22409+ addl $cpu_gdt_table, %ebx
22410+#else
22411+ movl $cpu_gdt_table, %ebx
22412+#endif
22413 shr $16, %edx
22414- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22415- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22416+
22417+#ifdef CONFIG_PAX_KERNEXEC
22418+ mov %cr0, %esi
22419+ btr $16, %esi
22420+ mov %esi, %cr0
22421+#endif
22422+
22423+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22424+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22425+
22426+#ifdef CONFIG_PAX_KERNEXEC
22427+ bts $16, %esi
22428+ mov %esi, %cr0
22429+#endif
22430+
22431 pushl_cfi $__ESPFIX_SS
22432 pushl_cfi %eax /* new kernel esp */
22433 /* Disable interrupts, but do not irqtrace this section: we
22434@@ -612,20 +839,18 @@ work_resched:
22435 movl TI_flags(%ebp), %ecx
22436 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22437 # than syscall tracing?
22438- jz restore_all
22439+ jz restore_all_pax
22440 testb $_TIF_NEED_RESCHED, %cl
22441 jnz work_resched
22442
22443 work_notifysig: # deal with pending signals and
22444 # notify-resume requests
22445+ movl %esp, %eax
22446 #ifdef CONFIG_VM86
22447 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22448- movl %esp, %eax
22449 jne work_notifysig_v86 # returning to kernel-space or
22450 # vm86-space
22451 1:
22452-#else
22453- movl %esp, %eax
22454 #endif
22455 TRACE_IRQS_ON
22456 ENABLE_INTERRUPTS(CLBR_NONE)
22457@@ -646,7 +871,7 @@ work_notifysig_v86:
22458 movl %eax, %esp
22459 jmp 1b
22460 #endif
22461-END(work_pending)
22462+ENDPROC(work_pending)
22463
22464 # perform syscall exit tracing
22465 ALIGN
22466@@ -654,11 +879,14 @@ syscall_trace_entry:
22467 movl $-ENOSYS,PT_EAX(%esp)
22468 movl %esp, %eax
22469 call syscall_trace_enter
22470+
22471+ pax_erase_kstack
22472+
22473 /* What it returned is what we'll actually use. */
22474 cmpl $(NR_syscalls), %eax
22475 jnae syscall_call
22476 jmp syscall_exit
22477-END(syscall_trace_entry)
22478+ENDPROC(syscall_trace_entry)
22479
22480 # perform syscall exit tracing
22481 ALIGN
22482@@ -671,26 +899,30 @@ syscall_exit_work:
22483 movl %esp, %eax
22484 call syscall_trace_leave
22485 jmp resume_userspace
22486-END(syscall_exit_work)
22487+ENDPROC(syscall_exit_work)
22488 CFI_ENDPROC
22489
22490 RING0_INT_FRAME # can't unwind into user space anyway
22491 syscall_fault:
22492+#ifdef CONFIG_PAX_MEMORY_UDEREF
22493+ push %ss
22494+ pop %ds
22495+#endif
22496 ASM_CLAC
22497 GET_THREAD_INFO(%ebp)
22498 movl $-EFAULT,PT_EAX(%esp)
22499 jmp resume_userspace
22500-END(syscall_fault)
22501+ENDPROC(syscall_fault)
22502
22503 syscall_badsys:
22504 movl $-ENOSYS,PT_EAX(%esp)
22505 jmp syscall_exit
22506-END(syscall_badsys)
22507+ENDPROC(syscall_badsys)
22508
22509 sysenter_badsys:
22510 movl $-ENOSYS,PT_EAX(%esp)
22511 jmp sysenter_after_call
22512-END(syscall_badsys)
22513+ENDPROC(sysenter_badsys)
22514 CFI_ENDPROC
22515 /*
22516 * End of kprobes section
22517@@ -706,8 +938,15 @@ END(syscall_badsys)
22518 * normal stack and adjusts ESP with the matching offset.
22519 */
22520 /* fixup the stack */
22521- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22522- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22523+#ifdef CONFIG_SMP
22524+ movl PER_CPU_VAR(cpu_number), %ebx
22525+ shll $PAGE_SHIFT_asm, %ebx
22526+ addl $cpu_gdt_table, %ebx
22527+#else
22528+ movl $cpu_gdt_table, %ebx
22529+#endif
22530+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22531+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22532 shl $16, %eax
22533 addl %esp, %eax /* the adjusted stack pointer */
22534 pushl_cfi $__KERNEL_DS
22535@@ -760,7 +999,7 @@ vector=vector+1
22536 .endr
22537 2: jmp common_interrupt
22538 .endr
22539-END(irq_entries_start)
22540+ENDPROC(irq_entries_start)
22541
22542 .previous
22543 END(interrupt)
22544@@ -821,7 +1060,7 @@ ENTRY(coprocessor_error)
22545 pushl_cfi $do_coprocessor_error
22546 jmp error_code
22547 CFI_ENDPROC
22548-END(coprocessor_error)
22549+ENDPROC(coprocessor_error)
22550
22551 ENTRY(simd_coprocessor_error)
22552 RING0_INT_FRAME
22553@@ -834,7 +1073,7 @@ ENTRY(simd_coprocessor_error)
22554 .section .altinstructions,"a"
22555 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22556 .previous
22557-.section .altinstr_replacement,"ax"
22558+.section .altinstr_replacement,"a"
22559 663: pushl $do_simd_coprocessor_error
22560 664:
22561 .previous
22562@@ -843,7 +1082,7 @@ ENTRY(simd_coprocessor_error)
22563 #endif
22564 jmp error_code
22565 CFI_ENDPROC
22566-END(simd_coprocessor_error)
22567+ENDPROC(simd_coprocessor_error)
22568
22569 ENTRY(device_not_available)
22570 RING0_INT_FRAME
22571@@ -852,18 +1091,18 @@ ENTRY(device_not_available)
22572 pushl_cfi $do_device_not_available
22573 jmp error_code
22574 CFI_ENDPROC
22575-END(device_not_available)
22576+ENDPROC(device_not_available)
22577
22578 #ifdef CONFIG_PARAVIRT
22579 ENTRY(native_iret)
22580 iret
22581 _ASM_EXTABLE(native_iret, iret_exc)
22582-END(native_iret)
22583+ENDPROC(native_iret)
22584
22585 ENTRY(native_irq_enable_sysexit)
22586 sti
22587 sysexit
22588-END(native_irq_enable_sysexit)
22589+ENDPROC(native_irq_enable_sysexit)
22590 #endif
22591
22592 ENTRY(overflow)
22593@@ -873,7 +1112,7 @@ ENTRY(overflow)
22594 pushl_cfi $do_overflow
22595 jmp error_code
22596 CFI_ENDPROC
22597-END(overflow)
22598+ENDPROC(overflow)
22599
22600 ENTRY(bounds)
22601 RING0_INT_FRAME
22602@@ -882,7 +1121,7 @@ ENTRY(bounds)
22603 pushl_cfi $do_bounds
22604 jmp error_code
22605 CFI_ENDPROC
22606-END(bounds)
22607+ENDPROC(bounds)
22608
22609 ENTRY(invalid_op)
22610 RING0_INT_FRAME
22611@@ -891,7 +1130,7 @@ ENTRY(invalid_op)
22612 pushl_cfi $do_invalid_op
22613 jmp error_code
22614 CFI_ENDPROC
22615-END(invalid_op)
22616+ENDPROC(invalid_op)
22617
22618 ENTRY(coprocessor_segment_overrun)
22619 RING0_INT_FRAME
22620@@ -900,7 +1139,7 @@ ENTRY(coprocessor_segment_overrun)
22621 pushl_cfi $do_coprocessor_segment_overrun
22622 jmp error_code
22623 CFI_ENDPROC
22624-END(coprocessor_segment_overrun)
22625+ENDPROC(coprocessor_segment_overrun)
22626
22627 ENTRY(invalid_TSS)
22628 RING0_EC_FRAME
22629@@ -908,7 +1147,7 @@ ENTRY(invalid_TSS)
22630 pushl_cfi $do_invalid_TSS
22631 jmp error_code
22632 CFI_ENDPROC
22633-END(invalid_TSS)
22634+ENDPROC(invalid_TSS)
22635
22636 ENTRY(segment_not_present)
22637 RING0_EC_FRAME
22638@@ -916,7 +1155,7 @@ ENTRY(segment_not_present)
22639 pushl_cfi $do_segment_not_present
22640 jmp error_code
22641 CFI_ENDPROC
22642-END(segment_not_present)
22643+ENDPROC(segment_not_present)
22644
22645 ENTRY(stack_segment)
22646 RING0_EC_FRAME
22647@@ -924,7 +1163,7 @@ ENTRY(stack_segment)
22648 pushl_cfi $do_stack_segment
22649 jmp error_code
22650 CFI_ENDPROC
22651-END(stack_segment)
22652+ENDPROC(stack_segment)
22653
22654 ENTRY(alignment_check)
22655 RING0_EC_FRAME
22656@@ -932,7 +1171,7 @@ ENTRY(alignment_check)
22657 pushl_cfi $do_alignment_check
22658 jmp error_code
22659 CFI_ENDPROC
22660-END(alignment_check)
22661+ENDPROC(alignment_check)
22662
22663 ENTRY(divide_error)
22664 RING0_INT_FRAME
22665@@ -941,7 +1180,7 @@ ENTRY(divide_error)
22666 pushl_cfi $do_divide_error
22667 jmp error_code
22668 CFI_ENDPROC
22669-END(divide_error)
22670+ENDPROC(divide_error)
22671
22672 #ifdef CONFIG_X86_MCE
22673 ENTRY(machine_check)
22674@@ -951,7 +1190,7 @@ ENTRY(machine_check)
22675 pushl_cfi machine_check_vector
22676 jmp error_code
22677 CFI_ENDPROC
22678-END(machine_check)
22679+ENDPROC(machine_check)
22680 #endif
22681
22682 ENTRY(spurious_interrupt_bug)
22683@@ -961,7 +1200,7 @@ ENTRY(spurious_interrupt_bug)
22684 pushl_cfi $do_spurious_interrupt_bug
22685 jmp error_code
22686 CFI_ENDPROC
22687-END(spurious_interrupt_bug)
22688+ENDPROC(spurious_interrupt_bug)
22689 /*
22690 * End of kprobes section
22691 */
22692@@ -1071,7 +1310,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22693
22694 ENTRY(mcount)
22695 ret
22696-END(mcount)
22697+ENDPROC(mcount)
22698
22699 ENTRY(ftrace_caller)
22700 cmpl $0, function_trace_stop
22701@@ -1104,7 +1343,7 @@ ftrace_graph_call:
22702 .globl ftrace_stub
22703 ftrace_stub:
22704 ret
22705-END(ftrace_caller)
22706+ENDPROC(ftrace_caller)
22707
22708 ENTRY(ftrace_regs_caller)
22709 pushf /* push flags before compare (in cs location) */
22710@@ -1208,7 +1447,7 @@ trace:
22711 popl %ecx
22712 popl %eax
22713 jmp ftrace_stub
22714-END(mcount)
22715+ENDPROC(mcount)
22716 #endif /* CONFIG_DYNAMIC_FTRACE */
22717 #endif /* CONFIG_FUNCTION_TRACER */
22718
22719@@ -1226,7 +1465,7 @@ ENTRY(ftrace_graph_caller)
22720 popl %ecx
22721 popl %eax
22722 ret
22723-END(ftrace_graph_caller)
22724+ENDPROC(ftrace_graph_caller)
22725
22726 .globl return_to_handler
22727 return_to_handler:
22728@@ -1292,15 +1531,18 @@ error_code:
22729 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22730 REG_TO_PTGS %ecx
22731 SET_KERNEL_GS %ecx
22732- movl $(__USER_DS), %ecx
22733+ movl $(__KERNEL_DS), %ecx
22734 movl %ecx, %ds
22735 movl %ecx, %es
22736+
22737+ pax_enter_kernel
22738+
22739 TRACE_IRQS_OFF
22740 movl %esp,%eax # pt_regs pointer
22741 call *%edi
22742 jmp ret_from_exception
22743 CFI_ENDPROC
22744-END(page_fault)
22745+ENDPROC(page_fault)
22746
22747 /*
22748 * Debug traps and NMI can happen at the one SYSENTER instruction
22749@@ -1343,7 +1585,7 @@ debug_stack_correct:
22750 call do_debug
22751 jmp ret_from_exception
22752 CFI_ENDPROC
22753-END(debug)
22754+ENDPROC(debug)
22755
22756 /*
22757 * NMI is doubly nasty. It can happen _while_ we're handling
22758@@ -1381,6 +1623,9 @@ nmi_stack_correct:
22759 xorl %edx,%edx # zero error code
22760 movl %esp,%eax # pt_regs pointer
22761 call do_nmi
22762+
22763+ pax_exit_kernel
22764+
22765 jmp restore_all_notrace
22766 CFI_ENDPROC
22767
22768@@ -1417,12 +1662,15 @@ nmi_espfix_stack:
22769 FIXUP_ESPFIX_STACK # %eax == %esp
22770 xorl %edx,%edx # zero error code
22771 call do_nmi
22772+
22773+ pax_exit_kernel
22774+
22775 RESTORE_REGS
22776 lss 12+4(%esp), %esp # back to espfix stack
22777 CFI_ADJUST_CFA_OFFSET -24
22778 jmp irq_return
22779 CFI_ENDPROC
22780-END(nmi)
22781+ENDPROC(nmi)
22782
22783 ENTRY(int3)
22784 RING0_INT_FRAME
22785@@ -1435,14 +1683,14 @@ ENTRY(int3)
22786 call do_int3
22787 jmp ret_from_exception
22788 CFI_ENDPROC
22789-END(int3)
22790+ENDPROC(int3)
22791
22792 ENTRY(general_protection)
22793 RING0_EC_FRAME
22794 pushl_cfi $do_general_protection
22795 jmp error_code
22796 CFI_ENDPROC
22797-END(general_protection)
22798+ENDPROC(general_protection)
22799
22800 #ifdef CONFIG_KVM_GUEST
22801 ENTRY(async_page_fault)
22802@@ -1451,7 +1699,7 @@ ENTRY(async_page_fault)
22803 pushl_cfi $do_async_page_fault
22804 jmp error_code
22805 CFI_ENDPROC
22806-END(async_page_fault)
22807+ENDPROC(async_page_fault)
22808 #endif
22809
22810 /*
22811diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22812index 1e96c36..3ff710a 100644
22813--- a/arch/x86/kernel/entry_64.S
22814+++ b/arch/x86/kernel/entry_64.S
22815@@ -59,6 +59,8 @@
22816 #include <asm/context_tracking.h>
22817 #include <asm/smap.h>
22818 #include <linux/err.h>
22819+#include <asm/pgtable.h>
22820+#include <asm/alternative-asm.h>
22821
22822 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22823 #include <linux/elf-em.h>
22824@@ -80,8 +82,9 @@
22825 #ifdef CONFIG_DYNAMIC_FTRACE
22826
22827 ENTRY(function_hook)
22828+ pax_force_retaddr
22829 retq
22830-END(function_hook)
22831+ENDPROC(function_hook)
22832
22833 /* skip is set if stack has been adjusted */
22834 .macro ftrace_caller_setup skip=0
22835@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22836 #endif
22837
22838 GLOBAL(ftrace_stub)
22839+ pax_force_retaddr
22840 retq
22841-END(ftrace_caller)
22842+ENDPROC(ftrace_caller)
22843
22844 ENTRY(ftrace_regs_caller)
22845 /* Save the current flags before compare (in SS location)*/
22846@@ -191,7 +195,7 @@ ftrace_restore_flags:
22847 popfq
22848 jmp ftrace_stub
22849
22850-END(ftrace_regs_caller)
22851+ENDPROC(ftrace_regs_caller)
22852
22853
22854 #else /* ! CONFIG_DYNAMIC_FTRACE */
22855@@ -212,6 +216,7 @@ ENTRY(function_hook)
22856 #endif
22857
22858 GLOBAL(ftrace_stub)
22859+ pax_force_retaddr
22860 retq
22861
22862 trace:
22863@@ -225,12 +230,13 @@ trace:
22864 #endif
22865 subq $MCOUNT_INSN_SIZE, %rdi
22866
22867+ pax_force_fptr ftrace_trace_function
22868 call *ftrace_trace_function
22869
22870 MCOUNT_RESTORE_FRAME
22871
22872 jmp ftrace_stub
22873-END(function_hook)
22874+ENDPROC(function_hook)
22875 #endif /* CONFIG_DYNAMIC_FTRACE */
22876 #endif /* CONFIG_FUNCTION_TRACER */
22877
22878@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22879
22880 MCOUNT_RESTORE_FRAME
22881
22882+ pax_force_retaddr
22883 retq
22884-END(ftrace_graph_caller)
22885+ENDPROC(ftrace_graph_caller)
22886
22887 GLOBAL(return_to_handler)
22888 subq $24, %rsp
22889@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22890 movq 8(%rsp), %rdx
22891 movq (%rsp), %rax
22892 addq $24, %rsp
22893+ pax_force_fptr %rdi
22894 jmp *%rdi
22895+ENDPROC(return_to_handler)
22896 #endif
22897
22898
22899@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22900 ENDPROC(native_usergs_sysret64)
22901 #endif /* CONFIG_PARAVIRT */
22902
22903+ .macro ljmpq sel, off
22904+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22905+ .byte 0x48; ljmp *1234f(%rip)
22906+ .pushsection .rodata
22907+ .align 16
22908+ 1234: .quad \off; .word \sel
22909+ .popsection
22910+#else
22911+ pushq $\sel
22912+ pushq $\off
22913+ lretq
22914+#endif
22915+ .endm
22916+
22917+ .macro pax_enter_kernel
22918+ pax_set_fptr_mask
22919+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22920+ call pax_enter_kernel
22921+#endif
22922+ .endm
22923+
22924+ .macro pax_exit_kernel
22925+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22926+ call pax_exit_kernel
22927+#endif
22928+
22929+ .endm
22930+
22931+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22932+ENTRY(pax_enter_kernel)
22933+ pushq %rdi
22934+
22935+#ifdef CONFIG_PARAVIRT
22936+ PV_SAVE_REGS(CLBR_RDI)
22937+#endif
22938+
22939+#ifdef CONFIG_PAX_KERNEXEC
22940+ GET_CR0_INTO_RDI
22941+ bts $16,%rdi
22942+ jnc 3f
22943+ mov %cs,%edi
22944+ cmp $__KERNEL_CS,%edi
22945+ jnz 2f
22946+1:
22947+#endif
22948+
22949+#ifdef CONFIG_PAX_MEMORY_UDEREF
22950+ 661: jmp 111f
22951+ .pushsection .altinstr_replacement, "a"
22952+ 662: ASM_NOP2
22953+ .popsection
22954+ .pushsection .altinstructions, "a"
22955+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22956+ .popsection
22957+ GET_CR3_INTO_RDI
22958+ cmp $0,%dil
22959+ jnz 112f
22960+ mov $__KERNEL_DS,%edi
22961+ mov %edi,%ss
22962+ jmp 111f
22963+112: cmp $1,%dil
22964+ jz 113f
22965+ ud2
22966+113: sub $4097,%rdi
22967+ bts $63,%rdi
22968+ SET_RDI_INTO_CR3
22969+ mov $__UDEREF_KERNEL_DS,%edi
22970+ mov %edi,%ss
22971+111:
22972+#endif
22973+
22974+#ifdef CONFIG_PARAVIRT
22975+ PV_RESTORE_REGS(CLBR_RDI)
22976+#endif
22977+
22978+ popq %rdi
22979+ pax_force_retaddr
22980+ retq
22981+
22982+#ifdef CONFIG_PAX_KERNEXEC
22983+2: ljmpq __KERNEL_CS,1b
22984+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22985+4: SET_RDI_INTO_CR0
22986+ jmp 1b
22987+#endif
22988+ENDPROC(pax_enter_kernel)
22989+
22990+ENTRY(pax_exit_kernel)
22991+ pushq %rdi
22992+
22993+#ifdef CONFIG_PARAVIRT
22994+ PV_SAVE_REGS(CLBR_RDI)
22995+#endif
22996+
22997+#ifdef CONFIG_PAX_KERNEXEC
22998+ mov %cs,%rdi
22999+ cmp $__KERNEXEC_KERNEL_CS,%edi
23000+ jz 2f
23001+ GET_CR0_INTO_RDI
23002+ bts $16,%rdi
23003+ jnc 4f
23004+1:
23005+#endif
23006+
23007+#ifdef CONFIG_PAX_MEMORY_UDEREF
23008+ 661: jmp 111f
23009+ .pushsection .altinstr_replacement, "a"
23010+ 662: ASM_NOP2
23011+ .popsection
23012+ .pushsection .altinstructions, "a"
23013+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23014+ .popsection
23015+ mov %ss,%edi
23016+ cmp $__UDEREF_KERNEL_DS,%edi
23017+ jnz 111f
23018+ GET_CR3_INTO_RDI
23019+ cmp $0,%dil
23020+ jz 112f
23021+ ud2
23022+112: add $4097,%rdi
23023+ bts $63,%rdi
23024+ SET_RDI_INTO_CR3
23025+ mov $__KERNEL_DS,%edi
23026+ mov %edi,%ss
23027+111:
23028+#endif
23029+
23030+#ifdef CONFIG_PARAVIRT
23031+ PV_RESTORE_REGS(CLBR_RDI);
23032+#endif
23033+
23034+ popq %rdi
23035+ pax_force_retaddr
23036+ retq
23037+
23038+#ifdef CONFIG_PAX_KERNEXEC
23039+2: GET_CR0_INTO_RDI
23040+ btr $16,%rdi
23041+ jnc 4f
23042+ ljmpq __KERNEL_CS,3f
23043+3: SET_RDI_INTO_CR0
23044+ jmp 1b
23045+4: ud2
23046+ jmp 4b
23047+#endif
23048+ENDPROC(pax_exit_kernel)
23049+#endif
23050+
23051+ .macro pax_enter_kernel_user
23052+ pax_set_fptr_mask
23053+#ifdef CONFIG_PAX_MEMORY_UDEREF
23054+ call pax_enter_kernel_user
23055+#endif
23056+ .endm
23057+
23058+ .macro pax_exit_kernel_user
23059+#ifdef CONFIG_PAX_MEMORY_UDEREF
23060+ call pax_exit_kernel_user
23061+#endif
23062+#ifdef CONFIG_PAX_RANDKSTACK
23063+ pushq %rax
23064+ pushq %r11
23065+ call pax_randomize_kstack
23066+ popq %r11
23067+ popq %rax
23068+#endif
23069+ .endm
23070+
23071+#ifdef CONFIG_PAX_MEMORY_UDEREF
23072+ENTRY(pax_enter_kernel_user)
23073+ pushq %rdi
23074+ pushq %rbx
23075+
23076+#ifdef CONFIG_PARAVIRT
23077+ PV_SAVE_REGS(CLBR_RDI)
23078+#endif
23079+
23080+ 661: jmp 111f
23081+ .pushsection .altinstr_replacement, "a"
23082+ 662: ASM_NOP2
23083+ .popsection
23084+ .pushsection .altinstructions, "a"
23085+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23086+ .popsection
23087+ GET_CR3_INTO_RDI
23088+ cmp $1,%dil
23089+ jnz 4f
23090+ sub $4097,%rdi
23091+ bts $63,%rdi
23092+ SET_RDI_INTO_CR3
23093+ jmp 3f
23094+111:
23095+
23096+ GET_CR3_INTO_RDI
23097+ mov %rdi,%rbx
23098+ add $__START_KERNEL_map,%rbx
23099+ sub phys_base(%rip),%rbx
23100+
23101+#ifdef CONFIG_PARAVIRT
23102+ cmpl $0, pv_info+PARAVIRT_enabled
23103+ jz 1f
23104+ pushq %rdi
23105+ i = 0
23106+ .rept USER_PGD_PTRS
23107+ mov i*8(%rbx),%rsi
23108+ mov $0,%sil
23109+ lea i*8(%rbx),%rdi
23110+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23111+ i = i + 1
23112+ .endr
23113+ popq %rdi
23114+ jmp 2f
23115+1:
23116+#endif
23117+
23118+ i = 0
23119+ .rept USER_PGD_PTRS
23120+ movb $0,i*8(%rbx)
23121+ i = i + 1
23122+ .endr
23123+
23124+2: SET_RDI_INTO_CR3
23125+
23126+#ifdef CONFIG_PAX_KERNEXEC
23127+ GET_CR0_INTO_RDI
23128+ bts $16,%rdi
23129+ SET_RDI_INTO_CR0
23130+#endif
23131+
23132+3:
23133+
23134+#ifdef CONFIG_PARAVIRT
23135+ PV_RESTORE_REGS(CLBR_RDI)
23136+#endif
23137+
23138+ popq %rbx
23139+ popq %rdi
23140+ pax_force_retaddr
23141+ retq
23142+4: ud2
23143+ENDPROC(pax_enter_kernel_user)
23144+
23145+ENTRY(pax_exit_kernel_user)
23146+ pushq %rdi
23147+ pushq %rbx
23148+
23149+#ifdef CONFIG_PARAVIRT
23150+ PV_SAVE_REGS(CLBR_RDI)
23151+#endif
23152+
23153+ GET_CR3_INTO_RDI
23154+ 661: jmp 1f
23155+ .pushsection .altinstr_replacement, "a"
23156+ 662: ASM_NOP2
23157+ .popsection
23158+ .pushsection .altinstructions, "a"
23159+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23160+ .popsection
23161+ cmp $0,%dil
23162+ jnz 3f
23163+ add $4097,%rdi
23164+ bts $63,%rdi
23165+ SET_RDI_INTO_CR3
23166+ jmp 2f
23167+1:
23168+
23169+ mov %rdi,%rbx
23170+
23171+#ifdef CONFIG_PAX_KERNEXEC
23172+ GET_CR0_INTO_RDI
23173+ btr $16,%rdi
23174+ jnc 3f
23175+ SET_RDI_INTO_CR0
23176+#endif
23177+
23178+ add $__START_KERNEL_map,%rbx
23179+ sub phys_base(%rip),%rbx
23180+
23181+#ifdef CONFIG_PARAVIRT
23182+ cmpl $0, pv_info+PARAVIRT_enabled
23183+ jz 1f
23184+ i = 0
23185+ .rept USER_PGD_PTRS
23186+ mov i*8(%rbx),%rsi
23187+ mov $0x67,%sil
23188+ lea i*8(%rbx),%rdi
23189+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23190+ i = i + 1
23191+ .endr
23192+ jmp 2f
23193+1:
23194+#endif
23195+
23196+ i = 0
23197+ .rept USER_PGD_PTRS
23198+ movb $0x67,i*8(%rbx)
23199+ i = i + 1
23200+ .endr
23201+2:
23202+
23203+#ifdef CONFIG_PARAVIRT
23204+ PV_RESTORE_REGS(CLBR_RDI)
23205+#endif
23206+
23207+ popq %rbx
23208+ popq %rdi
23209+ pax_force_retaddr
23210+ retq
23211+3: ud2
23212+ENDPROC(pax_exit_kernel_user)
23213+#endif
23214+
23215+ .macro pax_enter_kernel_nmi
23216+ pax_set_fptr_mask
23217+
23218+#ifdef CONFIG_PAX_KERNEXEC
23219+ GET_CR0_INTO_RDI
23220+ bts $16,%rdi
23221+ jc 110f
23222+ SET_RDI_INTO_CR0
23223+ or $2,%ebx
23224+110:
23225+#endif
23226+
23227+#ifdef CONFIG_PAX_MEMORY_UDEREF
23228+ 661: jmp 111f
23229+ .pushsection .altinstr_replacement, "a"
23230+ 662: ASM_NOP2
23231+ .popsection
23232+ .pushsection .altinstructions, "a"
23233+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23234+ .popsection
23235+ GET_CR3_INTO_RDI
23236+ cmp $0,%dil
23237+ jz 111f
23238+ sub $4097,%rdi
23239+ or $4,%ebx
23240+ bts $63,%rdi
23241+ SET_RDI_INTO_CR3
23242+ mov $__UDEREF_KERNEL_DS,%edi
23243+ mov %edi,%ss
23244+111:
23245+#endif
23246+ .endm
23247+
23248+ .macro pax_exit_kernel_nmi
23249+#ifdef CONFIG_PAX_KERNEXEC
23250+ btr $1,%ebx
23251+ jnc 110f
23252+ GET_CR0_INTO_RDI
23253+ btr $16,%rdi
23254+ SET_RDI_INTO_CR0
23255+110:
23256+#endif
23257+
23258+#ifdef CONFIG_PAX_MEMORY_UDEREF
23259+ btr $2,%ebx
23260+ jnc 111f
23261+ GET_CR3_INTO_RDI
23262+ add $4097,%rdi
23263+ bts $63,%rdi
23264+ SET_RDI_INTO_CR3
23265+ mov $__KERNEL_DS,%edi
23266+ mov %edi,%ss
23267+111:
23268+#endif
23269+ .endm
23270+
23271+ .macro pax_erase_kstack
23272+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23273+ call pax_erase_kstack
23274+#endif
23275+ .endm
23276+
23277+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23278+ENTRY(pax_erase_kstack)
23279+ pushq %rdi
23280+ pushq %rcx
23281+ pushq %rax
23282+ pushq %r11
23283+
23284+ GET_THREAD_INFO(%r11)
23285+ mov TI_lowest_stack(%r11), %rdi
23286+ mov $-0xBEEF, %rax
23287+ std
23288+
23289+1: mov %edi, %ecx
23290+ and $THREAD_SIZE_asm - 1, %ecx
23291+ shr $3, %ecx
23292+ repne scasq
23293+ jecxz 2f
23294+
23295+ cmp $2*8, %ecx
23296+ jc 2f
23297+
23298+ mov $2*8, %ecx
23299+ repe scasq
23300+ jecxz 2f
23301+ jne 1b
23302+
23303+2: cld
23304+ mov %esp, %ecx
23305+ sub %edi, %ecx
23306+
23307+ cmp $THREAD_SIZE_asm, %rcx
23308+ jb 3f
23309+ ud2
23310+3:
23311+
23312+ shr $3, %ecx
23313+ rep stosq
23314+
23315+ mov TI_task_thread_sp0(%r11), %rdi
23316+ sub $256, %rdi
23317+ mov %rdi, TI_lowest_stack(%r11)
23318+
23319+ popq %r11
23320+ popq %rax
23321+ popq %rcx
23322+ popq %rdi
23323+ pax_force_retaddr
23324+ ret
23325+ENDPROC(pax_erase_kstack)
23326+#endif
23327
23328 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23329 #ifdef CONFIG_TRACE_IRQFLAGS
23330@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23331 .endm
23332
23333 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23334- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23335+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23336 jnc 1f
23337 TRACE_IRQS_ON_DEBUG
23338 1:
23339@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23340 movq \tmp,R11+\offset(%rsp)
23341 .endm
23342
23343- .macro FAKE_STACK_FRAME child_rip
23344- /* push in order ss, rsp, eflags, cs, rip */
23345- xorl %eax, %eax
23346- pushq_cfi $__KERNEL_DS /* ss */
23347- /*CFI_REL_OFFSET ss,0*/
23348- pushq_cfi %rax /* rsp */
23349- CFI_REL_OFFSET rsp,0
23350- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23351- /*CFI_REL_OFFSET rflags,0*/
23352- pushq_cfi $__KERNEL_CS /* cs */
23353- /*CFI_REL_OFFSET cs,0*/
23354- pushq_cfi \child_rip /* rip */
23355- CFI_REL_OFFSET rip,0
23356- pushq_cfi %rax /* orig rax */
23357- .endm
23358-
23359- .macro UNFAKE_STACK_FRAME
23360- addq $8*6, %rsp
23361- CFI_ADJUST_CFA_OFFSET -(6*8)
23362- .endm
23363-
23364 /*
23365 * initial frame state for interrupts (and exceptions without error code)
23366 */
23367@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23368 /* save partial stack frame */
23369 .macro SAVE_ARGS_IRQ
23370 cld
23371- /* start from rbp in pt_regs and jump over */
23372- movq_cfi rdi, (RDI-RBP)
23373- movq_cfi rsi, (RSI-RBP)
23374- movq_cfi rdx, (RDX-RBP)
23375- movq_cfi rcx, (RCX-RBP)
23376- movq_cfi rax, (RAX-RBP)
23377- movq_cfi r8, (R8-RBP)
23378- movq_cfi r9, (R9-RBP)
23379- movq_cfi r10, (R10-RBP)
23380- movq_cfi r11, (R11-RBP)
23381+ /* start from r15 in pt_regs and jump over */
23382+ movq_cfi rdi, RDI
23383+ movq_cfi rsi, RSI
23384+ movq_cfi rdx, RDX
23385+ movq_cfi rcx, RCX
23386+ movq_cfi rax, RAX
23387+ movq_cfi r8, R8
23388+ movq_cfi r9, R9
23389+ movq_cfi r10, R10
23390+ movq_cfi r11, R11
23391+ movq_cfi r12, R12
23392
23393 /* Save rbp so that we can unwind from get_irq_regs() */
23394- movq_cfi rbp, 0
23395+ movq_cfi rbp, RBP
23396
23397 /* Save previous stack value */
23398 movq %rsp, %rsi
23399
23400- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23401- testl $3, CS-RBP(%rsi)
23402+ movq %rsp,%rdi /* arg1 for handler */
23403+ testb $3, CS(%rsi)
23404 je 1f
23405 SWAPGS
23406 /*
23407@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23408 0x06 /* DW_OP_deref */, \
23409 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23410 0x22 /* DW_OP_plus */
23411+
23412+#ifdef CONFIG_PAX_MEMORY_UDEREF
23413+ testb $3, CS(%rdi)
23414+ jnz 1f
23415+ pax_enter_kernel
23416+ jmp 2f
23417+1: pax_enter_kernel_user
23418+2:
23419+#else
23420+ pax_enter_kernel
23421+#endif
23422+
23423 /* We entered an interrupt context - irqs are off: */
23424 TRACE_IRQS_OFF
23425 .endm
23426@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23427 js 1f /* negative -> in kernel */
23428 SWAPGS
23429 xorl %ebx,%ebx
23430-1: ret
23431+1:
23432+#ifdef CONFIG_PAX_MEMORY_UDEREF
23433+ testb $3, CS+8(%rsp)
23434+ jnz 1f
23435+ pax_enter_kernel
23436+ jmp 2f
23437+1: pax_enter_kernel_user
23438+2:
23439+#else
23440+ pax_enter_kernel
23441+#endif
23442+ pax_force_retaddr
23443+ ret
23444 CFI_ENDPROC
23445-END(save_paranoid)
23446+ENDPROC(save_paranoid)
23447+
23448+ENTRY(save_paranoid_nmi)
23449+ XCPT_FRAME 1 RDI+8
23450+ cld
23451+ movq_cfi rdi, RDI+8
23452+ movq_cfi rsi, RSI+8
23453+ movq_cfi rdx, RDX+8
23454+ movq_cfi rcx, RCX+8
23455+ movq_cfi rax, RAX+8
23456+ movq_cfi r8, R8+8
23457+ movq_cfi r9, R9+8
23458+ movq_cfi r10, R10+8
23459+ movq_cfi r11, R11+8
23460+ movq_cfi rbx, RBX+8
23461+ movq_cfi rbp, RBP+8
23462+ movq_cfi r12, R12+8
23463+ movq_cfi r13, R13+8
23464+ movq_cfi r14, R14+8
23465+ movq_cfi r15, R15+8
23466+ movl $1,%ebx
23467+ movl $MSR_GS_BASE,%ecx
23468+ rdmsr
23469+ testl %edx,%edx
23470+ js 1f /* negative -> in kernel */
23471+ SWAPGS
23472+ xorl %ebx,%ebx
23473+1: pax_enter_kernel_nmi
23474+ pax_force_retaddr
23475+ ret
23476+ CFI_ENDPROC
23477+ENDPROC(save_paranoid_nmi)
23478 .popsection
23479
23480 /*
23481@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23482
23483 RESTORE_REST
23484
23485- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23486+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23487 jz 1f
23488
23489 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23490@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23491 jmp ret_from_sys_call # go to the SYSRET fastpath
23492
23493 1:
23494- subq $REST_SKIP, %rsp # leave space for volatiles
23495- CFI_ADJUST_CFA_OFFSET REST_SKIP
23496 movq %rbp, %rdi
23497 call *%rbx
23498 movl $0, RAX(%rsp)
23499 RESTORE_REST
23500 jmp int_ret_from_sys_call
23501 CFI_ENDPROC
23502-END(ret_from_fork)
23503+ENDPROC(ret_from_fork)
23504
23505 /*
23506 * System call entry. Up to 6 arguments in registers are supported.
23507@@ -593,7 +1059,7 @@ END(ret_from_fork)
23508 ENTRY(system_call)
23509 CFI_STARTPROC simple
23510 CFI_SIGNAL_FRAME
23511- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23512+ CFI_DEF_CFA rsp,0
23513 CFI_REGISTER rip,rcx
23514 /*CFI_REGISTER rflags,r11*/
23515 SWAPGS_UNSAFE_STACK
23516@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23517
23518 movq %rsp,PER_CPU_VAR(old_rsp)
23519 movq PER_CPU_VAR(kernel_stack),%rsp
23520+ SAVE_ARGS 8*6,0
23521+ pax_enter_kernel_user
23522+
23523+#ifdef CONFIG_PAX_RANDKSTACK
23524+ pax_erase_kstack
23525+#endif
23526+
23527 /*
23528 * No need to follow this irqs off/on section - it's straight
23529 * and short:
23530 */
23531 ENABLE_INTERRUPTS(CLBR_NONE)
23532- SAVE_ARGS 8,0
23533 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23534 movq %rcx,RIP-ARGOFFSET(%rsp)
23535 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23536- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23537+ GET_THREAD_INFO(%rcx)
23538+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23539 jnz tracesys
23540 system_call_fastpath:
23541 #if __SYSCALL_MASK == ~0
23542@@ -639,10 +1112,13 @@ sysret_check:
23543 LOCKDEP_SYS_EXIT
23544 DISABLE_INTERRUPTS(CLBR_NONE)
23545 TRACE_IRQS_OFF
23546- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23547+ GET_THREAD_INFO(%rcx)
23548+ movl TI_flags(%rcx),%edx
23549 andl %edi,%edx
23550 jnz sysret_careful
23551 CFI_REMEMBER_STATE
23552+ pax_exit_kernel_user
23553+ pax_erase_kstack
23554 /*
23555 * sysretq will re-enable interrupts:
23556 */
23557@@ -701,6 +1177,9 @@ auditsys:
23558 movq %rax,%rsi /* 2nd arg: syscall number */
23559 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23560 call __audit_syscall_entry
23561+
23562+ pax_erase_kstack
23563+
23564 LOAD_ARGS 0 /* reload call-clobbered registers */
23565 jmp system_call_fastpath
23566
23567@@ -722,7 +1201,7 @@ sysret_audit:
23568 /* Do syscall tracing */
23569 tracesys:
23570 #ifdef CONFIG_AUDITSYSCALL
23571- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23572+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23573 jz auditsys
23574 #endif
23575 SAVE_REST
23576@@ -730,12 +1209,15 @@ tracesys:
23577 FIXUP_TOP_OF_STACK %rdi
23578 movq %rsp,%rdi
23579 call syscall_trace_enter
23580+
23581+ pax_erase_kstack
23582+
23583 /*
23584 * Reload arg registers from stack in case ptrace changed them.
23585 * We don't reload %rax because syscall_trace_enter() returned
23586 * the value it wants us to use in the table lookup.
23587 */
23588- LOAD_ARGS ARGOFFSET, 1
23589+ LOAD_ARGS 1
23590 RESTORE_REST
23591 #if __SYSCALL_MASK == ~0
23592 cmpq $__NR_syscall_max,%rax
23593@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23594 andl %edi,%edx
23595 jnz int_careful
23596 andl $~TS_COMPAT,TI_status(%rcx)
23597- jmp retint_swapgs
23598+ pax_exit_kernel_user
23599+ pax_erase_kstack
23600+ jmp retint_swapgs_pax
23601
23602 /* Either reschedule or signal or syscall exit tracking needed. */
23603 /* First do a reschedule test. */
23604@@ -811,7 +1295,7 @@ int_restore_rest:
23605 TRACE_IRQS_OFF
23606 jmp int_with_check
23607 CFI_ENDPROC
23608-END(system_call)
23609+ENDPROC(system_call)
23610
23611 .macro FORK_LIKE func
23612 ENTRY(stub_\func)
23613@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23614 DEFAULT_FRAME 0 8 /* offset 8: return address */
23615 call sys_\func
23616 RESTORE_TOP_OF_STACK %r11, 8
23617- ret $REST_SKIP /* pop extended registers */
23618+ pax_force_retaddr
23619+ ret
23620 CFI_ENDPROC
23621-END(stub_\func)
23622+ENDPROC(stub_\func)
23623 .endm
23624
23625 .macro FIXED_FRAME label,func
23626@@ -836,9 +1321,10 @@ ENTRY(\label)
23627 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23628 call \func
23629 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23630+ pax_force_retaddr
23631 ret
23632 CFI_ENDPROC
23633-END(\label)
23634+ENDPROC(\label)
23635 .endm
23636
23637 FORK_LIKE clone
23638@@ -846,19 +1332,6 @@ END(\label)
23639 FORK_LIKE vfork
23640 FIXED_FRAME stub_iopl, sys_iopl
23641
23642-ENTRY(ptregscall_common)
23643- DEFAULT_FRAME 1 8 /* offset 8: return address */
23644- RESTORE_TOP_OF_STACK %r11, 8
23645- movq_cfi_restore R15+8, r15
23646- movq_cfi_restore R14+8, r14
23647- movq_cfi_restore R13+8, r13
23648- movq_cfi_restore R12+8, r12
23649- movq_cfi_restore RBP+8, rbp
23650- movq_cfi_restore RBX+8, rbx
23651- ret $REST_SKIP /* pop extended registers */
23652- CFI_ENDPROC
23653-END(ptregscall_common)
23654-
23655 ENTRY(stub_execve)
23656 CFI_STARTPROC
23657 addq $8, %rsp
23658@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23659 RESTORE_REST
23660 jmp int_ret_from_sys_call
23661 CFI_ENDPROC
23662-END(stub_execve)
23663+ENDPROC(stub_execve)
23664
23665 /*
23666 * sigreturn is special because it needs to restore all registers on return.
23667@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23668 RESTORE_REST
23669 jmp int_ret_from_sys_call
23670 CFI_ENDPROC
23671-END(stub_rt_sigreturn)
23672+ENDPROC(stub_rt_sigreturn)
23673
23674 #ifdef CONFIG_X86_X32_ABI
23675 ENTRY(stub_x32_rt_sigreturn)
23676@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23677 RESTORE_REST
23678 jmp int_ret_from_sys_call
23679 CFI_ENDPROC
23680-END(stub_x32_rt_sigreturn)
23681+ENDPROC(stub_x32_rt_sigreturn)
23682
23683 ENTRY(stub_x32_execve)
23684 CFI_STARTPROC
23685@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23686 RESTORE_REST
23687 jmp int_ret_from_sys_call
23688 CFI_ENDPROC
23689-END(stub_x32_execve)
23690+ENDPROC(stub_x32_execve)
23691
23692 #endif
23693
23694@@ -952,7 +1425,7 @@ vector=vector+1
23695 2: jmp common_interrupt
23696 .endr
23697 CFI_ENDPROC
23698-END(irq_entries_start)
23699+ENDPROC(irq_entries_start)
23700
23701 .previous
23702 END(interrupt)
23703@@ -969,8 +1442,8 @@ END(interrupt)
23704 /* 0(%rsp): ~(interrupt number) */
23705 .macro interrupt func
23706 /* reserve pt_regs for scratch regs and rbp */
23707- subq $ORIG_RAX-RBP, %rsp
23708- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23709+ subq $ORIG_RAX, %rsp
23710+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23711 SAVE_ARGS_IRQ
23712 call \func
23713 .endm
23714@@ -997,14 +1470,14 @@ ret_from_intr:
23715
23716 /* Restore saved previous stack */
23717 popq %rsi
23718- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23719- leaq ARGOFFSET-RBP(%rsi), %rsp
23720+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23721+ movq %rsi, %rsp
23722 CFI_DEF_CFA_REGISTER rsp
23723- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23724+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23725
23726 exit_intr:
23727 GET_THREAD_INFO(%rcx)
23728- testl $3,CS-ARGOFFSET(%rsp)
23729+ testb $3,CS-ARGOFFSET(%rsp)
23730 je retint_kernel
23731
23732 /* Interrupt came from user space */
23733@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23734 * The iretq could re-enable interrupts:
23735 */
23736 DISABLE_INTERRUPTS(CLBR_ANY)
23737+ pax_exit_kernel_user
23738+retint_swapgs_pax:
23739 TRACE_IRQS_IRETQ
23740 SWAPGS
23741 jmp restore_args
23742
23743 retint_restore_args: /* return to kernel space */
23744 DISABLE_INTERRUPTS(CLBR_ANY)
23745+ pax_exit_kernel
23746+ pax_force_retaddr (RIP-ARGOFFSET)
23747 /*
23748 * The iretq could re-enable interrupts:
23749 */
23750@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23751 #endif
23752
23753 CFI_ENDPROC
23754-END(common_interrupt)
23755+ENDPROC(common_interrupt)
23756 /*
23757 * End of kprobes section
23758 */
23759@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23760 interrupt \do_sym
23761 jmp ret_from_intr
23762 CFI_ENDPROC
23763-END(\sym)
23764+ENDPROC(\sym)
23765 .endm
23766
23767 #ifdef CONFIG_TRACING
23768@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23769 call \do_sym
23770 jmp error_exit /* %ebx: no swapgs flag */
23771 CFI_ENDPROC
23772-END(\sym)
23773+ENDPROC(\sym)
23774 .endm
23775
23776 .macro paranoidzeroentry sym do_sym
23777@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23778 call \do_sym
23779 jmp paranoid_exit /* %ebx: no swapgs flag */
23780 CFI_ENDPROC
23781-END(\sym)
23782+ENDPROC(\sym)
23783 .endm
23784
23785-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23786+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23787 .macro paranoidzeroentry_ist sym do_sym ist
23788 ENTRY(\sym)
23789 INTR_FRAME
23790@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23791 TRACE_IRQS_OFF_DEBUG
23792 movq %rsp,%rdi /* pt_regs pointer */
23793 xorl %esi,%esi /* no error code */
23794+#ifdef CONFIG_SMP
23795+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23796+ lea init_tss(%r13), %r13
23797+#else
23798+ lea init_tss(%rip), %r13
23799+#endif
23800 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23801 call \do_sym
23802 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23803 jmp paranoid_exit /* %ebx: no swapgs flag */
23804 CFI_ENDPROC
23805-END(\sym)
23806+ENDPROC(\sym)
23807 .endm
23808
23809 .macro errorentry sym do_sym
23810@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23811 call \do_sym
23812 jmp error_exit /* %ebx: no swapgs flag */
23813 CFI_ENDPROC
23814-END(\sym)
23815+ENDPROC(\sym)
23816 .endm
23817
23818 #ifdef CONFIG_TRACING
23819@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23820 call \do_sym
23821 jmp paranoid_exit /* %ebx: no swapgs flag */
23822 CFI_ENDPROC
23823-END(\sym)
23824+ENDPROC(\sym)
23825 .endm
23826
23827 zeroentry divide_error do_divide_error
23828@@ -1336,9 +1819,10 @@ gs_change:
23829 2: mfence /* workaround */
23830 SWAPGS
23831 popfq_cfi
23832+ pax_force_retaddr
23833 ret
23834 CFI_ENDPROC
23835-END(native_load_gs_index)
23836+ENDPROC(native_load_gs_index)
23837
23838 _ASM_EXTABLE(gs_change,bad_gs)
23839 .section .fixup,"ax"
23840@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23841 CFI_DEF_CFA_REGISTER rsp
23842 CFI_ADJUST_CFA_OFFSET -8
23843 decl PER_CPU_VAR(irq_count)
23844+ pax_force_retaddr
23845 ret
23846 CFI_ENDPROC
23847-END(do_softirq_own_stack)
23848+ENDPROC(do_softirq_own_stack)
23849
23850 #ifdef CONFIG_XEN
23851 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23852@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23853 decl PER_CPU_VAR(irq_count)
23854 jmp error_exit
23855 CFI_ENDPROC
23856-END(xen_do_hypervisor_callback)
23857+ENDPROC(xen_do_hypervisor_callback)
23858
23859 /*
23860 * Hypervisor uses this for application faults while it executes.
23861@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23862 SAVE_ALL
23863 jmp error_exit
23864 CFI_ENDPROC
23865-END(xen_failsafe_callback)
23866+ENDPROC(xen_failsafe_callback)
23867
23868 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23869 xen_hvm_callback_vector xen_evtchn_do_upcall
23870@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23871 DEFAULT_FRAME
23872 DISABLE_INTERRUPTS(CLBR_NONE)
23873 TRACE_IRQS_OFF_DEBUG
23874- testl %ebx,%ebx /* swapgs needed? */
23875+ testl $1,%ebx /* swapgs needed? */
23876 jnz paranoid_restore
23877- testl $3,CS(%rsp)
23878+ testb $3,CS(%rsp)
23879 jnz paranoid_userspace
23880+#ifdef CONFIG_PAX_MEMORY_UDEREF
23881+ pax_exit_kernel
23882+ TRACE_IRQS_IRETQ 0
23883+ SWAPGS_UNSAFE_STACK
23884+ RESTORE_ALL 8
23885+ pax_force_retaddr_bts
23886+ jmp irq_return
23887+#endif
23888 paranoid_swapgs:
23889+#ifdef CONFIG_PAX_MEMORY_UDEREF
23890+ pax_exit_kernel_user
23891+#else
23892+ pax_exit_kernel
23893+#endif
23894 TRACE_IRQS_IRETQ 0
23895 SWAPGS_UNSAFE_STACK
23896 RESTORE_ALL 8
23897 jmp irq_return
23898 paranoid_restore:
23899+ pax_exit_kernel
23900 TRACE_IRQS_IRETQ_DEBUG 0
23901 RESTORE_ALL 8
23902+ pax_force_retaddr_bts
23903 jmp irq_return
23904 paranoid_userspace:
23905 GET_THREAD_INFO(%rcx)
23906@@ -1557,7 +2057,7 @@ paranoid_schedule:
23907 TRACE_IRQS_OFF
23908 jmp paranoid_userspace
23909 CFI_ENDPROC
23910-END(paranoid_exit)
23911+ENDPROC(paranoid_exit)
23912
23913 /*
23914 * Exception entry point. This expects an error code/orig_rax on the stack.
23915@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23916 movq_cfi r14, R14+8
23917 movq_cfi r15, R15+8
23918 xorl %ebx,%ebx
23919- testl $3,CS+8(%rsp)
23920+ testb $3,CS+8(%rsp)
23921 je error_kernelspace
23922 error_swapgs:
23923 SWAPGS
23924 error_sti:
23925+#ifdef CONFIG_PAX_MEMORY_UDEREF
23926+ testb $3, CS+8(%rsp)
23927+ jnz 1f
23928+ pax_enter_kernel
23929+ jmp 2f
23930+1: pax_enter_kernel_user
23931+2:
23932+#else
23933+ pax_enter_kernel
23934+#endif
23935 TRACE_IRQS_OFF
23936+ pax_force_retaddr
23937 ret
23938
23939 /*
23940@@ -1616,7 +2127,7 @@ bstep_iret:
23941 movq %rcx,RIP+8(%rsp)
23942 jmp error_swapgs
23943 CFI_ENDPROC
23944-END(error_entry)
23945+ENDPROC(error_entry)
23946
23947
23948 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23949@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23950 DISABLE_INTERRUPTS(CLBR_NONE)
23951 TRACE_IRQS_OFF
23952 GET_THREAD_INFO(%rcx)
23953- testl %eax,%eax
23954+ testl $1,%eax
23955 jne retint_kernel
23956 LOCKDEP_SYS_EXIT_IRQ
23957 movl TI_flags(%rcx),%edx
23958@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23959 jnz retint_careful
23960 jmp retint_swapgs
23961 CFI_ENDPROC
23962-END(error_exit)
23963+ENDPROC(error_exit)
23964
23965 /*
23966 * Test if a given stack is an NMI stack or not.
23967@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23968 * If %cs was not the kernel segment, then the NMI triggered in user
23969 * space, which means it is definitely not nested.
23970 */
23971+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23972+ je 1f
23973 cmpl $__KERNEL_CS, 16(%rsp)
23974 jne first_nmi
23975-
23976+1:
23977 /*
23978 * Check the special variable on the stack to see if NMIs are
23979 * executing.
23980@@ -1730,8 +2243,7 @@ nested_nmi:
23981
23982 1:
23983 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23984- leaq -1*8(%rsp), %rdx
23985- movq %rdx, %rsp
23986+ subq $8, %rsp
23987 CFI_ADJUST_CFA_OFFSET 1*8
23988 leaq -10*8(%rsp), %rdx
23989 pushq_cfi $__KERNEL_DS
23990@@ -1749,6 +2261,7 @@ nested_nmi_out:
23991 CFI_RESTORE rdx
23992
23993 /* No need to check faults here */
23994+# pax_force_retaddr_bts
23995 INTERRUPT_RETURN
23996
23997 CFI_RESTORE_STATE
23998@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23999 subq $ORIG_RAX-R15, %rsp
24000 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24001 /*
24002- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24003+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24004 * as we should not be calling schedule in NMI context.
24005 * Even with normal interrupts enabled. An NMI should not be
24006 * setting NEED_RESCHED or anything that normal interrupts and
24007 * exceptions might do.
24008 */
24009- call save_paranoid
24010+ call save_paranoid_nmi
24011 DEFAULT_FRAME 0
24012
24013 /*
24014@@ -1861,9 +2374,9 @@ end_repeat_nmi:
24015 * NMI itself takes a page fault, the page fault that was preempted
24016 * will read the information from the NMI page fault and not the
24017 * origin fault. Save it off and restore it if it changes.
24018- * Use the r12 callee-saved register.
24019+ * Use the r13 callee-saved register.
24020 */
24021- movq %cr2, %r12
24022+ movq %cr2, %r13
24023
24024 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24025 movq %rsp,%rdi
24026@@ -1872,31 +2385,36 @@ end_repeat_nmi:
24027
24028 /* Did the NMI take a page fault? Restore cr2 if it did */
24029 movq %cr2, %rcx
24030- cmpq %rcx, %r12
24031+ cmpq %rcx, %r13
24032 je 1f
24033- movq %r12, %cr2
24034+ movq %r13, %cr2
24035 1:
24036
24037- testl %ebx,%ebx /* swapgs needed? */
24038+ testl $1,%ebx /* swapgs needed? */
24039 jnz nmi_restore
24040 nmi_swapgs:
24041 SWAPGS_UNSAFE_STACK
24042 nmi_restore:
24043+ pax_exit_kernel_nmi
24044 /* Pop the extra iret frame at once */
24045 RESTORE_ALL 6*8
24046+ testb $3, 8(%rsp)
24047+ jnz 1f
24048+ pax_force_retaddr_bts
24049+1:
24050
24051 /* Clear the NMI executing stack variable */
24052 movq $0, 5*8(%rsp)
24053 jmp irq_return
24054 CFI_ENDPROC
24055-END(nmi)
24056+ENDPROC(nmi)
24057
24058 ENTRY(ignore_sysret)
24059 CFI_STARTPROC
24060 mov $-ENOSYS,%eax
24061 sysret
24062 CFI_ENDPROC
24063-END(ignore_sysret)
24064+ENDPROC(ignore_sysret)
24065
24066 /*
24067 * End of kprobes section
24068diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24069index 52819e8..b6d1dbd 100644
24070--- a/arch/x86/kernel/ftrace.c
24071+++ b/arch/x86/kernel/ftrace.c
24072@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24073 {
24074 unsigned char replaced[MCOUNT_INSN_SIZE];
24075
24076+ ip = ktla_ktva(ip);
24077+
24078 /*
24079 * Note: Due to modules and __init, code can
24080 * disappear and change, we need to protect against faulting
24081@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24082 unsigned char old[MCOUNT_INSN_SIZE];
24083 int ret;
24084
24085- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24086+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24087
24088 ftrace_update_func = ip;
24089 /* Make sure the breakpoints see the ftrace_update_func update */
24090@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24091 * kernel identity mapping to modify code.
24092 */
24093 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24094- ip = (unsigned long)__va(__pa_symbol(ip));
24095+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24096
24097 if (probe_kernel_write((void *)ip, val, size))
24098 return -EPERM;
24099@@ -319,7 +321,7 @@ static int add_break(unsigned long ip, const char *old)
24100 unsigned char replaced[MCOUNT_INSN_SIZE];
24101 unsigned char brk = BREAKPOINT_INSTRUCTION;
24102
24103- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24104+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24105 return -EFAULT;
24106
24107 /* Make sure it is what we expect it to be */
24108diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24109index 068054f..c248bcd 100644
24110--- a/arch/x86/kernel/head64.c
24111+++ b/arch/x86/kernel/head64.c
24112@@ -67,12 +67,12 @@ again:
24113 pgd = *pgd_p;
24114
24115 /*
24116- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24117- * critical -- __PAGE_OFFSET would point us back into the dynamic
24118+ * The use of __early_va rather than __va here is critical:
24119+ * __va would point us back into the dynamic
24120 * range and we might end up looping forever...
24121 */
24122 if (pgd)
24123- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24124+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24125 else {
24126 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24127 reset_early_page_tables();
24128@@ -82,13 +82,13 @@ again:
24129 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24130 for (i = 0; i < PTRS_PER_PUD; i++)
24131 pud_p[i] = 0;
24132- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24133+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24134 }
24135 pud_p += pud_index(address);
24136 pud = *pud_p;
24137
24138 if (pud)
24139- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24140+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24141 else {
24142 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24143 reset_early_page_tables();
24144@@ -98,7 +98,7 @@ again:
24145 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24146 for (i = 0; i < PTRS_PER_PMD; i++)
24147 pmd_p[i] = 0;
24148- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24149+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24150 }
24151 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24152 pmd_p[pmd_index(address)] = pmd;
24153@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24154 if (console_loglevel == 10)
24155 early_printk("Kernel alive\n");
24156
24157- clear_page(init_level4_pgt);
24158 /* set init_level4_pgt kernel high mapping*/
24159 init_level4_pgt[511] = early_level4_pgt[511];
24160
24161diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24162index f36bd42..56ee1534 100644
24163--- a/arch/x86/kernel/head_32.S
24164+++ b/arch/x86/kernel/head_32.S
24165@@ -26,6 +26,12 @@
24166 /* Physical address */
24167 #define pa(X) ((X) - __PAGE_OFFSET)
24168
24169+#ifdef CONFIG_PAX_KERNEXEC
24170+#define ta(X) (X)
24171+#else
24172+#define ta(X) ((X) - __PAGE_OFFSET)
24173+#endif
24174+
24175 /*
24176 * References to members of the new_cpu_data structure.
24177 */
24178@@ -55,11 +61,7 @@
24179 * and small than max_low_pfn, otherwise will waste some page table entries
24180 */
24181
24182-#if PTRS_PER_PMD > 1
24183-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24184-#else
24185-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24186-#endif
24187+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24188
24189 /* Number of possible pages in the lowmem region */
24190 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24191@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24192 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24193
24194 /*
24195+ * Real beginning of normal "text" segment
24196+ */
24197+ENTRY(stext)
24198+ENTRY(_stext)
24199+
24200+/*
24201 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24202 * %esi points to the real-mode code as a 32-bit pointer.
24203 * CS and DS must be 4 GB flat segments, but we don't depend on
24204@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24205 * can.
24206 */
24207 __HEAD
24208+
24209+#ifdef CONFIG_PAX_KERNEXEC
24210+ jmp startup_32
24211+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24212+.fill PAGE_SIZE-5,1,0xcc
24213+#endif
24214+
24215 ENTRY(startup_32)
24216 movl pa(stack_start),%ecx
24217
24218@@ -106,6 +121,59 @@ ENTRY(startup_32)
24219 2:
24220 leal -__PAGE_OFFSET(%ecx),%esp
24221
24222+#ifdef CONFIG_SMP
24223+ movl $pa(cpu_gdt_table),%edi
24224+ movl $__per_cpu_load,%eax
24225+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24226+ rorl $16,%eax
24227+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24228+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24229+ movl $__per_cpu_end - 1,%eax
24230+ subl $__per_cpu_start,%eax
24231+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24232+#endif
24233+
24234+#ifdef CONFIG_PAX_MEMORY_UDEREF
24235+ movl $NR_CPUS,%ecx
24236+ movl $pa(cpu_gdt_table),%edi
24237+1:
24238+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24239+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24240+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24241+ addl $PAGE_SIZE_asm,%edi
24242+ loop 1b
24243+#endif
24244+
24245+#ifdef CONFIG_PAX_KERNEXEC
24246+ movl $pa(boot_gdt),%edi
24247+ movl $__LOAD_PHYSICAL_ADDR,%eax
24248+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24249+ rorl $16,%eax
24250+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24251+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24252+ rorl $16,%eax
24253+
24254+ ljmp $(__BOOT_CS),$1f
24255+1:
24256+
24257+ movl $NR_CPUS,%ecx
24258+ movl $pa(cpu_gdt_table),%edi
24259+ addl $__PAGE_OFFSET,%eax
24260+1:
24261+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24262+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24263+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24264+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24265+ rorl $16,%eax
24266+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24267+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24268+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24269+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24270+ rorl $16,%eax
24271+ addl $PAGE_SIZE_asm,%edi
24272+ loop 1b
24273+#endif
24274+
24275 /*
24276 * Clear BSS first so that there are no surprises...
24277 */
24278@@ -201,8 +269,11 @@ ENTRY(startup_32)
24279 movl %eax, pa(max_pfn_mapped)
24280
24281 /* Do early initialization of the fixmap area */
24282- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24283- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24284+#ifdef CONFIG_COMPAT_VDSO
24285+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24286+#else
24287+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24288+#endif
24289 #else /* Not PAE */
24290
24291 page_pde_offset = (__PAGE_OFFSET >> 20);
24292@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24293 movl %eax, pa(max_pfn_mapped)
24294
24295 /* Do early initialization of the fixmap area */
24296- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24297- movl %eax,pa(initial_page_table+0xffc)
24298+#ifdef CONFIG_COMPAT_VDSO
24299+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24300+#else
24301+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24302+#endif
24303 #endif
24304
24305 #ifdef CONFIG_PARAVIRT
24306@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24307 cmpl $num_subarch_entries, %eax
24308 jae bad_subarch
24309
24310- movl pa(subarch_entries)(,%eax,4), %eax
24311- subl $__PAGE_OFFSET, %eax
24312- jmp *%eax
24313+ jmp *pa(subarch_entries)(,%eax,4)
24314
24315 bad_subarch:
24316 WEAK(lguest_entry)
24317@@ -261,10 +333,10 @@ WEAK(xen_entry)
24318 __INITDATA
24319
24320 subarch_entries:
24321- .long default_entry /* normal x86/PC */
24322- .long lguest_entry /* lguest hypervisor */
24323- .long xen_entry /* Xen hypervisor */
24324- .long default_entry /* Moorestown MID */
24325+ .long ta(default_entry) /* normal x86/PC */
24326+ .long ta(lguest_entry) /* lguest hypervisor */
24327+ .long ta(xen_entry) /* Xen hypervisor */
24328+ .long ta(default_entry) /* Moorestown MID */
24329 num_subarch_entries = (. - subarch_entries) / 4
24330 .previous
24331 #else
24332@@ -354,6 +426,7 @@ default_entry:
24333 movl pa(mmu_cr4_features),%eax
24334 movl %eax,%cr4
24335
24336+#ifdef CONFIG_X86_PAE
24337 testb $X86_CR4_PAE, %al # check if PAE is enabled
24338 jz enable_paging
24339
24340@@ -382,6 +455,9 @@ default_entry:
24341 /* Make changes effective */
24342 wrmsr
24343
24344+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24345+#endif
24346+
24347 enable_paging:
24348
24349 /*
24350@@ -449,14 +525,20 @@ is486:
24351 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24352 movl %eax,%ss # after changing gdt.
24353
24354- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24355+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24356 movl %eax,%ds
24357 movl %eax,%es
24358
24359 movl $(__KERNEL_PERCPU), %eax
24360 movl %eax,%fs # set this cpu's percpu
24361
24362+#ifdef CONFIG_CC_STACKPROTECTOR
24363 movl $(__KERNEL_STACK_CANARY),%eax
24364+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24365+ movl $(__USER_DS),%eax
24366+#else
24367+ xorl %eax,%eax
24368+#endif
24369 movl %eax,%gs
24370
24371 xorl %eax,%eax # Clear LDT
24372@@ -512,8 +594,11 @@ setup_once:
24373 * relocation. Manually set base address in stack canary
24374 * segment descriptor.
24375 */
24376- movl $gdt_page,%eax
24377+ movl $cpu_gdt_table,%eax
24378 movl $stack_canary,%ecx
24379+#ifdef CONFIG_SMP
24380+ addl $__per_cpu_load,%ecx
24381+#endif
24382 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24383 shrl $16, %ecx
24384 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24385@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24386 cmpl $2,(%esp) # X86_TRAP_NMI
24387 je is_nmi # Ignore NMI
24388
24389- cmpl $2,%ss:early_recursion_flag
24390+ cmpl $1,%ss:early_recursion_flag
24391 je hlt_loop
24392 incl %ss:early_recursion_flag
24393
24394@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24395 pushl (20+6*4)(%esp) /* trapno */
24396 pushl $fault_msg
24397 call printk
24398-#endif
24399 call dump_stack
24400+#endif
24401 hlt_loop:
24402 hlt
24403 jmp hlt_loop
24404@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24405 /* This is the default interrupt "handler" :-) */
24406 ALIGN
24407 ignore_int:
24408- cld
24409 #ifdef CONFIG_PRINTK
24410+ cmpl $2,%ss:early_recursion_flag
24411+ je hlt_loop
24412+ incl %ss:early_recursion_flag
24413+ cld
24414 pushl %eax
24415 pushl %ecx
24416 pushl %edx
24417@@ -617,9 +705,6 @@ ignore_int:
24418 movl $(__KERNEL_DS),%eax
24419 movl %eax,%ds
24420 movl %eax,%es
24421- cmpl $2,early_recursion_flag
24422- je hlt_loop
24423- incl early_recursion_flag
24424 pushl 16(%esp)
24425 pushl 24(%esp)
24426 pushl 32(%esp)
24427@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24428 /*
24429 * BSS section
24430 */
24431-__PAGE_ALIGNED_BSS
24432- .align PAGE_SIZE
24433 #ifdef CONFIG_X86_PAE
24434+.section .initial_pg_pmd,"a",@progbits
24435 initial_pg_pmd:
24436 .fill 1024*KPMDS,4,0
24437 #else
24438+.section .initial_page_table,"a",@progbits
24439 ENTRY(initial_page_table)
24440 .fill 1024,4,0
24441 #endif
24442+.section .initial_pg_fixmap,"a",@progbits
24443 initial_pg_fixmap:
24444 .fill 1024,4,0
24445+.section .empty_zero_page,"a",@progbits
24446 ENTRY(empty_zero_page)
24447 .fill 4096,1,0
24448+.section .swapper_pg_dir,"a",@progbits
24449 ENTRY(swapper_pg_dir)
24450+#ifdef CONFIG_X86_PAE
24451+ .fill 4,8,0
24452+#else
24453 .fill 1024,4,0
24454+#endif
24455
24456 /*
24457 * This starts the data section.
24458 */
24459 #ifdef CONFIG_X86_PAE
24460-__PAGE_ALIGNED_DATA
24461- /* Page-aligned for the benefit of paravirt? */
24462- .align PAGE_SIZE
24463+.section .initial_page_table,"a",@progbits
24464 ENTRY(initial_page_table)
24465 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24466 # if KPMDS == 3
24467@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24468 # error "Kernel PMDs should be 1, 2 or 3"
24469 # endif
24470 .align PAGE_SIZE /* needs to be page-sized too */
24471+
24472+#ifdef CONFIG_PAX_PER_CPU_PGD
24473+ENTRY(cpu_pgd)
24474+ .rept 2*NR_CPUS
24475+ .fill 4,8,0
24476+ .endr
24477+#endif
24478+
24479 #endif
24480
24481 .data
24482 .balign 4
24483 ENTRY(stack_start)
24484- .long init_thread_union+THREAD_SIZE
24485+ .long init_thread_union+THREAD_SIZE-8
24486
24487 __INITRODATA
24488 int_msg:
24489@@ -727,7 +825,7 @@ fault_msg:
24490 * segment size, and 32-bit linear address value:
24491 */
24492
24493- .data
24494+.section .rodata,"a",@progbits
24495 .globl boot_gdt_descr
24496 .globl idt_descr
24497
24498@@ -736,7 +834,7 @@ fault_msg:
24499 .word 0 # 32 bit align gdt_desc.address
24500 boot_gdt_descr:
24501 .word __BOOT_DS+7
24502- .long boot_gdt - __PAGE_OFFSET
24503+ .long pa(boot_gdt)
24504
24505 .word 0 # 32-bit align idt_desc.address
24506 idt_descr:
24507@@ -747,7 +845,7 @@ idt_descr:
24508 .word 0 # 32 bit align gdt_desc.address
24509 ENTRY(early_gdt_descr)
24510 .word GDT_ENTRIES*8-1
24511- .long gdt_page /* Overwritten for secondary CPUs */
24512+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24513
24514 /*
24515 * The boot_gdt must mirror the equivalent in setup.S and is
24516@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24517 .align L1_CACHE_BYTES
24518 ENTRY(boot_gdt)
24519 .fill GDT_ENTRY_BOOT_CS,8,0
24520- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24521- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24522+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24523+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24524+
24525+ .align PAGE_SIZE_asm
24526+ENTRY(cpu_gdt_table)
24527+ .rept NR_CPUS
24528+ .quad 0x0000000000000000 /* NULL descriptor */
24529+ .quad 0x0000000000000000 /* 0x0b reserved */
24530+ .quad 0x0000000000000000 /* 0x13 reserved */
24531+ .quad 0x0000000000000000 /* 0x1b reserved */
24532+
24533+#ifdef CONFIG_PAX_KERNEXEC
24534+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24535+#else
24536+ .quad 0x0000000000000000 /* 0x20 unused */
24537+#endif
24538+
24539+ .quad 0x0000000000000000 /* 0x28 unused */
24540+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24541+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24542+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24543+ .quad 0x0000000000000000 /* 0x4b reserved */
24544+ .quad 0x0000000000000000 /* 0x53 reserved */
24545+ .quad 0x0000000000000000 /* 0x5b reserved */
24546+
24547+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24548+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24549+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24550+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24551+
24552+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24553+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24554+
24555+ /*
24556+ * Segments used for calling PnP BIOS have byte granularity.
24557+ * The code segments and data segments have fixed 64k limits,
24558+ * the transfer segment sizes are set at run time.
24559+ */
24560+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24561+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24562+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24563+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24564+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24565+
24566+ /*
24567+ * The APM segments have byte granularity and their bases
24568+ * are set at run time. All have 64k limits.
24569+ */
24570+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24571+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24572+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24573+
24574+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24575+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24576+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24577+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24578+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24579+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24580+
24581+ /* Be sure this is zeroed to avoid false validations in Xen */
24582+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24583+ .endr
24584diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24585index a468c0a..c7dec74 100644
24586--- a/arch/x86/kernel/head_64.S
24587+++ b/arch/x86/kernel/head_64.S
24588@@ -20,6 +20,8 @@
24589 #include <asm/processor-flags.h>
24590 #include <asm/percpu.h>
24591 #include <asm/nops.h>
24592+#include <asm/cpufeature.h>
24593+#include <asm/alternative-asm.h>
24594
24595 #ifdef CONFIG_PARAVIRT
24596 #include <asm/asm-offsets.h>
24597@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24598 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24599 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24600 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24601+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24602+L3_VMALLOC_START = pud_index(VMALLOC_START)
24603+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24604+L3_VMALLOC_END = pud_index(VMALLOC_END)
24605+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24606+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24607
24608 .text
24609 __HEAD
24610@@ -89,11 +97,24 @@ startup_64:
24611 * Fixup the physical addresses in the page table
24612 */
24613 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24614+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24615+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24616+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24617+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24618+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24619
24620- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24621- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24622+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24623+#ifndef CONFIG_XEN
24624+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24625+#endif
24626+
24627+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24628+
24629+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24630+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24631
24632 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24633+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24634
24635 /*
24636 * Set up the identity mapping for the switchover. These
24637@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24638 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24639 1:
24640
24641- /* Enable PAE mode and PGE */
24642- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24643+ /* Enable PAE mode and PSE/PGE */
24644+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24645 movq %rcx, %cr4
24646
24647 /* Setup early boot stage 4 level pagetables. */
24648@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24649 movl $MSR_EFER, %ecx
24650 rdmsr
24651 btsl $_EFER_SCE, %eax /* Enable System Call */
24652- btl $20,%edi /* No Execute supported? */
24653+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24654 jnc 1f
24655 btsl $_EFER_NX, %eax
24656 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24657+#ifndef CONFIG_EFI
24658+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24659+#endif
24660+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24661+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24662+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24663+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24664+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24665+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24666 1: wrmsr /* Make changes effective */
24667
24668 /* Setup cr0 */
24669@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24670 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24671 * address given in m16:64.
24672 */
24673+ pax_set_fptr_mask
24674 movq initial_code(%rip),%rax
24675 pushq $0 # fake return address to stop unwinder
24676 pushq $__KERNEL_CS # set correct cs
24677@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24678 .quad INIT_PER_CPU_VAR(irq_stack_union)
24679
24680 GLOBAL(stack_start)
24681- .quad init_thread_union+THREAD_SIZE-8
24682+ .quad init_thread_union+THREAD_SIZE-16
24683 .word 0
24684 __FINITDATA
24685
24686@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24687 call dump_stack
24688 #ifdef CONFIG_KALLSYMS
24689 leaq early_idt_ripmsg(%rip),%rdi
24690- movq 40(%rsp),%rsi # %rip again
24691+ movq 88(%rsp),%rsi # %rip again
24692 call __print_symbol
24693 #endif
24694 #endif /* EARLY_PRINTK */
24695@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24696 early_recursion_flag:
24697 .long 0
24698
24699+ .section .rodata,"a",@progbits
24700 #ifdef CONFIG_EARLY_PRINTK
24701 early_idt_msg:
24702 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24703@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24704 NEXT_PAGE(early_dynamic_pgts)
24705 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24706
24707- .data
24708+ .section .rodata,"a",@progbits
24709
24710-#ifndef CONFIG_XEN
24711 NEXT_PAGE(init_level4_pgt)
24712- .fill 512,8,0
24713-#else
24714-NEXT_PAGE(init_level4_pgt)
24715- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24716 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24717 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24718+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24719+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24720+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24721+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24722+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24723+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24724 .org init_level4_pgt + L4_START_KERNEL*8, 0
24725 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24726 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24727
24728+#ifdef CONFIG_PAX_PER_CPU_PGD
24729+NEXT_PAGE(cpu_pgd)
24730+ .rept 2*NR_CPUS
24731+ .fill 512,8,0
24732+ .endr
24733+#endif
24734+
24735 NEXT_PAGE(level3_ident_pgt)
24736 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24737+#ifdef CONFIG_XEN
24738 .fill 511, 8, 0
24739+#else
24740+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24741+ .fill 510,8,0
24742+#endif
24743+
24744+NEXT_PAGE(level3_vmalloc_start_pgt)
24745+ .fill 512,8,0
24746+
24747+NEXT_PAGE(level3_vmalloc_end_pgt)
24748+ .fill 512,8,0
24749+
24750+NEXT_PAGE(level3_vmemmap_pgt)
24751+ .fill L3_VMEMMAP_START,8,0
24752+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24753+
24754 NEXT_PAGE(level2_ident_pgt)
24755- /* Since I easily can, map the first 1G.
24756+ /* Since I easily can, map the first 2G.
24757 * Don't set NX because code runs from these pages.
24758 */
24759- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24760-#endif
24761+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24762
24763 NEXT_PAGE(level3_kernel_pgt)
24764 .fill L3_START_KERNEL,8,0
24765@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24766 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24767 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24768
24769+NEXT_PAGE(level2_vmemmap_pgt)
24770+ .fill 512,8,0
24771+
24772 NEXT_PAGE(level2_kernel_pgt)
24773 /*
24774 * 512 MB kernel mapping. We spend a full page on this pagetable
24775@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24776 NEXT_PAGE(level2_fixmap_pgt)
24777 .fill 506,8,0
24778 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24779- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24780- .fill 5,8,0
24781+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24782+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24783+ .fill 4,8,0
24784
24785 NEXT_PAGE(level1_fixmap_pgt)
24786 .fill 512,8,0
24787
24788+NEXT_PAGE(level1_vsyscall_pgt)
24789+ .fill 512,8,0
24790+
24791 #undef PMDS
24792
24793- .data
24794+ .align PAGE_SIZE
24795+ENTRY(cpu_gdt_table)
24796+ .rept NR_CPUS
24797+ .quad 0x0000000000000000 /* NULL descriptor */
24798+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24799+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24800+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24801+ .quad 0x00cffb000000ffff /* __USER32_CS */
24802+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24803+ .quad 0x00affb000000ffff /* __USER_CS */
24804+
24805+#ifdef CONFIG_PAX_KERNEXEC
24806+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24807+#else
24808+ .quad 0x0 /* unused */
24809+#endif
24810+
24811+ .quad 0,0 /* TSS */
24812+ .quad 0,0 /* LDT */
24813+ .quad 0,0,0 /* three TLS descriptors */
24814+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24815+ /* asm/segment.h:GDT_ENTRIES must match this */
24816+
24817+#ifdef CONFIG_PAX_MEMORY_UDEREF
24818+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24819+#else
24820+ .quad 0x0 /* unused */
24821+#endif
24822+
24823+ /* zero the remaining page */
24824+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24825+ .endr
24826+
24827 .align 16
24828 .globl early_gdt_descr
24829 early_gdt_descr:
24830 .word GDT_ENTRIES*8-1
24831 early_gdt_descr_base:
24832- .quad INIT_PER_CPU_VAR(gdt_page)
24833+ .quad cpu_gdt_table
24834
24835 ENTRY(phys_base)
24836 /* This must match the first entry in level2_kernel_pgt */
24837 .quad 0x0000000000000000
24838
24839 #include "../../x86/xen/xen-head.S"
24840-
24841- __PAGE_ALIGNED_BSS
24842+
24843+ .section .rodata,"a",@progbits
24844 NEXT_PAGE(empty_zero_page)
24845 .skip PAGE_SIZE
24846diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24847index 05fd74f..c3548b1 100644
24848--- a/arch/x86/kernel/i386_ksyms_32.c
24849+++ b/arch/x86/kernel/i386_ksyms_32.c
24850@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24851 EXPORT_SYMBOL(cmpxchg8b_emu);
24852 #endif
24853
24854+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24855+
24856 /* Networking helper routines. */
24857 EXPORT_SYMBOL(csum_partial_copy_generic);
24858+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24859+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24860
24861 EXPORT_SYMBOL(__get_user_1);
24862 EXPORT_SYMBOL(__get_user_2);
24863@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24864 EXPORT_SYMBOL(___preempt_schedule_context);
24865 #endif
24866 #endif
24867+
24868+#ifdef CONFIG_PAX_KERNEXEC
24869+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24870+#endif
24871+
24872+#ifdef CONFIG_PAX_PER_CPU_PGD
24873+EXPORT_SYMBOL(cpu_pgd);
24874+#endif
24875diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24876index d5dd808..b6432cf 100644
24877--- a/arch/x86/kernel/i387.c
24878+++ b/arch/x86/kernel/i387.c
24879@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24880 static inline bool interrupted_user_mode(void)
24881 {
24882 struct pt_regs *regs = get_irq_regs();
24883- return regs && user_mode_vm(regs);
24884+ return regs && user_mode(regs);
24885 }
24886
24887 /*
24888diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24889index 2e977b5..5f2c273 100644
24890--- a/arch/x86/kernel/i8259.c
24891+++ b/arch/x86/kernel/i8259.c
24892@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24893 static void make_8259A_irq(unsigned int irq)
24894 {
24895 disable_irq_nosync(irq);
24896- io_apic_irqs &= ~(1<<irq);
24897+ io_apic_irqs &= ~(1UL<<irq);
24898 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24899 i8259A_chip.name);
24900 enable_irq(irq);
24901@@ -209,7 +209,7 @@ spurious_8259A_irq:
24902 "spurious 8259A interrupt: IRQ%d.\n", irq);
24903 spurious_irq_mask |= irqmask;
24904 }
24905- atomic_inc(&irq_err_count);
24906+ atomic_inc_unchecked(&irq_err_count);
24907 /*
24908 * Theoretically we do not have to handle this IRQ,
24909 * but in Linux this does not cause problems and is
24910@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24911 /* (slave's support for AEOI in flat mode is to be investigated) */
24912 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24913
24914+ pax_open_kernel();
24915 if (auto_eoi)
24916 /*
24917 * In AEOI mode we just have to mask the interrupt
24918 * when acking.
24919 */
24920- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24921+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24922 else
24923- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24924+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24925+ pax_close_kernel();
24926
24927 udelay(100); /* wait for 8259A to initialize */
24928
24929diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24930index a979b5b..1d6db75 100644
24931--- a/arch/x86/kernel/io_delay.c
24932+++ b/arch/x86/kernel/io_delay.c
24933@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24934 * Quirk table for systems that misbehave (lock up, etc.) if port
24935 * 0x80 is used:
24936 */
24937-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24938+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24939 {
24940 .callback = dmi_io_delay_0xed_port,
24941 .ident = "Compaq Presario V6000",
24942diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24943index 4ddaf66..49d5c18 100644
24944--- a/arch/x86/kernel/ioport.c
24945+++ b/arch/x86/kernel/ioport.c
24946@@ -6,6 +6,7 @@
24947 #include <linux/sched.h>
24948 #include <linux/kernel.h>
24949 #include <linux/capability.h>
24950+#include <linux/security.h>
24951 #include <linux/errno.h>
24952 #include <linux/types.h>
24953 #include <linux/ioport.h>
24954@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24955 return -EINVAL;
24956 if (turn_on && !capable(CAP_SYS_RAWIO))
24957 return -EPERM;
24958+#ifdef CONFIG_GRKERNSEC_IO
24959+ if (turn_on && grsec_disable_privio) {
24960+ gr_handle_ioperm();
24961+ return -ENODEV;
24962+ }
24963+#endif
24964
24965 /*
24966 * If it's the first ioperm() call in this thread's lifetime, set the
24967@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24968 * because the ->io_bitmap_max value must match the bitmap
24969 * contents:
24970 */
24971- tss = &per_cpu(init_tss, get_cpu());
24972+ tss = init_tss + get_cpu();
24973
24974 if (turn_on)
24975 bitmap_clear(t->io_bitmap_ptr, from, num);
24976@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24977 if (level > old) {
24978 if (!capable(CAP_SYS_RAWIO))
24979 return -EPERM;
24980+#ifdef CONFIG_GRKERNSEC_IO
24981+ if (grsec_disable_privio) {
24982+ gr_handle_iopl();
24983+ return -ENODEV;
24984+ }
24985+#endif
24986 }
24987 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24988 t->iopl = level << 12;
24989diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24990index 11ccfb0..ec1e46f 100644
24991--- a/arch/x86/kernel/irq.c
24992+++ b/arch/x86/kernel/irq.c
24993@@ -22,7 +22,7 @@
24994 #define CREATE_TRACE_POINTS
24995 #include <asm/trace/irq_vectors.h>
24996
24997-atomic_t irq_err_count;
24998+atomic_unchecked_t irq_err_count;
24999
25000 /* Function pointer for generic interrupt vector handling */
25001 void (*x86_platform_ipi_callback)(void) = NULL;
25002@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25003 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25004 seq_printf(p, " Hypervisor callback interrupts\n");
25005 #endif
25006- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25007+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25008 #if defined(CONFIG_X86_IO_APIC)
25009- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25010+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25011 #endif
25012 return 0;
25013 }
25014@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25015
25016 u64 arch_irq_stat(void)
25017 {
25018- u64 sum = atomic_read(&irq_err_count);
25019+ u64 sum = atomic_read_unchecked(&irq_err_count);
25020 return sum;
25021 }
25022
25023diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25024index 63ce838..2ea3e06 100644
25025--- a/arch/x86/kernel/irq_32.c
25026+++ b/arch/x86/kernel/irq_32.c
25027@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25028
25029 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25030
25031+extern void gr_handle_kernel_exploit(void);
25032+
25033 int sysctl_panic_on_stackoverflow __read_mostly;
25034
25035 /* Debugging check for stack overflow: is there less than 1KB free? */
25036@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25037 __asm__ __volatile__("andl %%esp,%0" :
25038 "=r" (sp) : "0" (THREAD_SIZE - 1));
25039
25040- return sp < (sizeof(struct thread_info) + STACK_WARN);
25041+ return sp < STACK_WARN;
25042 }
25043
25044 static void print_stack_overflow(void)
25045 {
25046 printk(KERN_WARNING "low stack detected by irq handler\n");
25047 dump_stack();
25048+ gr_handle_kernel_exploit();
25049 if (sysctl_panic_on_stackoverflow)
25050 panic("low stack detected by irq handler - check messages\n");
25051 }
25052@@ -84,10 +87,9 @@ static inline void *current_stack(void)
25053 static inline int
25054 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25055 {
25056- struct irq_stack *curstk, *irqstk;
25057+ struct irq_stack *irqstk;
25058 u32 *isp, *prev_esp, arg1, arg2;
25059
25060- curstk = (struct irq_stack *) current_stack();
25061 irqstk = __this_cpu_read(hardirq_stack);
25062
25063 /*
25064@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25065 * handler) we can't do that and just have to keep using the
25066 * current stack (which is the irq stack already after all)
25067 */
25068- if (unlikely(curstk == irqstk))
25069+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25070 return 0;
25071
25072- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25073+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25074
25075 /* Save the next esp at the bottom of the stack */
25076 prev_esp = (u32 *)irqstk;
25077 *prev_esp = current_stack_pointer;
25078
25079+#ifdef CONFIG_PAX_MEMORY_UDEREF
25080+ __set_fs(MAKE_MM_SEG(0));
25081+#endif
25082+
25083 if (unlikely(overflow))
25084 call_on_stack(print_stack_overflow, isp);
25085
25086@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25087 : "0" (irq), "1" (desc), "2" (isp),
25088 "D" (desc->handle_irq)
25089 : "memory", "cc", "ecx");
25090+
25091+#ifdef CONFIG_PAX_MEMORY_UDEREF
25092+ __set_fs(current_thread_info()->addr_limit);
25093+#endif
25094+
25095 return 1;
25096 }
25097
25098@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25099 */
25100 void irq_ctx_init(int cpu)
25101 {
25102- struct irq_stack *irqstk;
25103-
25104 if (per_cpu(hardirq_stack, cpu))
25105 return;
25106
25107- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25108- THREADINFO_GFP,
25109- THREAD_SIZE_ORDER));
25110- per_cpu(hardirq_stack, cpu) = irqstk;
25111-
25112- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25113- THREADINFO_GFP,
25114- THREAD_SIZE_ORDER));
25115- per_cpu(softirq_stack, cpu) = irqstk;
25116-
25117- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25118- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25119+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25120+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25121 }
25122
25123 void do_softirq_own_stack(void)
25124 {
25125- struct thread_info *curstk;
25126 struct irq_stack *irqstk;
25127 u32 *isp, *prev_esp;
25128
25129- curstk = current_stack();
25130 irqstk = __this_cpu_read(softirq_stack);
25131
25132 /* build the stack frame on the softirq stack */
25133@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25134 prev_esp = (u32 *)irqstk;
25135 *prev_esp = current_stack_pointer;
25136
25137+#ifdef CONFIG_PAX_MEMORY_UDEREF
25138+ __set_fs(MAKE_MM_SEG(0));
25139+#endif
25140+
25141 call_on_stack(__do_softirq, isp);
25142+
25143+#ifdef CONFIG_PAX_MEMORY_UDEREF
25144+ __set_fs(current_thread_info()->addr_limit);
25145+#endif
25146+
25147 }
25148
25149 bool handle_irq(unsigned irq, struct pt_regs *regs)
25150@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25151 if (unlikely(!desc))
25152 return false;
25153
25154- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25155+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25156 if (unlikely(overflow))
25157 print_stack_overflow();
25158 desc->handle_irq(irq, desc);
25159diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25160index 4d1c746..55a22d6 100644
25161--- a/arch/x86/kernel/irq_64.c
25162+++ b/arch/x86/kernel/irq_64.c
25163@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25164 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25165 EXPORT_PER_CPU_SYMBOL(irq_regs);
25166
25167+extern void gr_handle_kernel_exploit(void);
25168+
25169 int sysctl_panic_on_stackoverflow;
25170
25171 /*
25172@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25173 u64 estack_top, estack_bottom;
25174 u64 curbase = (u64)task_stack_page(current);
25175
25176- if (user_mode_vm(regs))
25177+ if (user_mode(regs))
25178 return;
25179
25180 if (regs->sp >= curbase + sizeof(struct thread_info) +
25181@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25182 irq_stack_top, irq_stack_bottom,
25183 estack_top, estack_bottom);
25184
25185+ gr_handle_kernel_exploit();
25186+
25187 if (sysctl_panic_on_stackoverflow)
25188 panic("low stack detected by irq handler - check messages\n");
25189 #endif
25190diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25191index 26d5a55..a01160a 100644
25192--- a/arch/x86/kernel/jump_label.c
25193+++ b/arch/x86/kernel/jump_label.c
25194@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25195 * Jump label is enabled for the first time.
25196 * So we expect a default_nop...
25197 */
25198- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25199+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25200 != 0))
25201 bug_at((void *)entry->code, __LINE__);
25202 } else {
25203@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25204 * ...otherwise expect an ideal_nop. Otherwise
25205 * something went horribly wrong.
25206 */
25207- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25208+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25209 != 0))
25210 bug_at((void *)entry->code, __LINE__);
25211 }
25212@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25213 * are converting the default nop to the ideal nop.
25214 */
25215 if (init) {
25216- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25217+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25218 bug_at((void *)entry->code, __LINE__);
25219 } else {
25220 code.jump = 0xe9;
25221 code.offset = entry->target -
25222 (entry->code + JUMP_LABEL_NOP_SIZE);
25223- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25224+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25225 bug_at((void *)entry->code, __LINE__);
25226 }
25227 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25228diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25229index 7ec1d5f..5a7d130 100644
25230--- a/arch/x86/kernel/kgdb.c
25231+++ b/arch/x86/kernel/kgdb.c
25232@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25233 #ifdef CONFIG_X86_32
25234 switch (regno) {
25235 case GDB_SS:
25236- if (!user_mode_vm(regs))
25237+ if (!user_mode(regs))
25238 *(unsigned long *)mem = __KERNEL_DS;
25239 break;
25240 case GDB_SP:
25241- if (!user_mode_vm(regs))
25242+ if (!user_mode(regs))
25243 *(unsigned long *)mem = kernel_stack_pointer(regs);
25244 break;
25245 case GDB_GS:
25246@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25247 bp->attr.bp_addr = breakinfo[breakno].addr;
25248 bp->attr.bp_len = breakinfo[breakno].len;
25249 bp->attr.bp_type = breakinfo[breakno].type;
25250- info->address = breakinfo[breakno].addr;
25251+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25252+ info->address = ktla_ktva(breakinfo[breakno].addr);
25253+ else
25254+ info->address = breakinfo[breakno].addr;
25255 info->len = breakinfo[breakno].len;
25256 info->type = breakinfo[breakno].type;
25257 val = arch_install_hw_breakpoint(bp);
25258@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25259 case 'k':
25260 /* clear the trace bit */
25261 linux_regs->flags &= ~X86_EFLAGS_TF;
25262- atomic_set(&kgdb_cpu_doing_single_step, -1);
25263+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25264
25265 /* set the trace bit if we're stepping */
25266 if (remcomInBuffer[0] == 's') {
25267 linux_regs->flags |= X86_EFLAGS_TF;
25268- atomic_set(&kgdb_cpu_doing_single_step,
25269+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25270 raw_smp_processor_id());
25271 }
25272
25273@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25274
25275 switch (cmd) {
25276 case DIE_DEBUG:
25277- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25278+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25279 if (user_mode(regs))
25280 return single_step_cont(regs, args);
25281 break;
25282@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25283 #endif /* CONFIG_DEBUG_RODATA */
25284
25285 bpt->type = BP_BREAKPOINT;
25286- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25287+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25288 BREAK_INSTR_SIZE);
25289 if (err)
25290 return err;
25291- err = probe_kernel_write((char *)bpt->bpt_addr,
25292+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25293 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25294 #ifdef CONFIG_DEBUG_RODATA
25295 if (!err)
25296@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25297 return -EBUSY;
25298 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25299 BREAK_INSTR_SIZE);
25300- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25301+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25302 if (err)
25303 return err;
25304 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25305@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25306 if (mutex_is_locked(&text_mutex))
25307 goto knl_write;
25308 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25309- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25310+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25311 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25312 goto knl_write;
25313 return err;
25314 knl_write:
25315 #endif /* CONFIG_DEBUG_RODATA */
25316- return probe_kernel_write((char *)bpt->bpt_addr,
25317+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25318 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25319 }
25320
25321diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25322index 61b17dc..784bfe9 100644
25323--- a/arch/x86/kernel/kprobes/core.c
25324+++ b/arch/x86/kernel/kprobes/core.c
25325@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25326 s32 raddr;
25327 } __packed *insn;
25328
25329- insn = (struct __arch_relative_insn *)from;
25330+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25331+
25332+ pax_open_kernel();
25333 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25334 insn->op = op;
25335+ pax_close_kernel();
25336 }
25337
25338 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25339@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25340 kprobe_opcode_t opcode;
25341 kprobe_opcode_t *orig_opcodes = opcodes;
25342
25343- if (search_exception_tables((unsigned long)opcodes))
25344+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25345 return 0; /* Page fault may occur on this address. */
25346
25347 retry:
25348@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25349 * for the first byte, we can recover the original instruction
25350 * from it and kp->opcode.
25351 */
25352- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25353+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25354 buf[0] = kp->opcode;
25355- return (unsigned long)buf;
25356+ return ktva_ktla((unsigned long)buf);
25357 }
25358
25359 /*
25360@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25361 /* Another subsystem puts a breakpoint, failed to recover */
25362 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25363 return 0;
25364+ pax_open_kernel();
25365 memcpy(dest, insn.kaddr, insn.length);
25366+ pax_close_kernel();
25367
25368 #ifdef CONFIG_X86_64
25369 if (insn_rip_relative(&insn)) {
25370@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25371 return 0;
25372 }
25373 disp = (u8 *) dest + insn_offset_displacement(&insn);
25374+ pax_open_kernel();
25375 *(s32 *) disp = (s32) newdisp;
25376+ pax_close_kernel();
25377 }
25378 #endif
25379 return insn.length;
25380@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25381 * nor set current_kprobe, because it doesn't use single
25382 * stepping.
25383 */
25384- regs->ip = (unsigned long)p->ainsn.insn;
25385+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25386 preempt_enable_no_resched();
25387 return;
25388 }
25389@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25390 regs->flags &= ~X86_EFLAGS_IF;
25391 /* single step inline if the instruction is an int3 */
25392 if (p->opcode == BREAKPOINT_INSTRUCTION)
25393- regs->ip = (unsigned long)p->addr;
25394+ regs->ip = ktla_ktva((unsigned long)p->addr);
25395 else
25396- regs->ip = (unsigned long)p->ainsn.insn;
25397+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25398 }
25399
25400 /*
25401@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25402 setup_singlestep(p, regs, kcb, 0);
25403 return 1;
25404 }
25405- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25406+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25407 /*
25408 * The breakpoint instruction was removed right
25409 * after we hit it. Another cpu has removed
25410@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25411 " movq %rax, 152(%rsp)\n"
25412 RESTORE_REGS_STRING
25413 " popfq\n"
25414+#ifdef KERNEXEC_PLUGIN
25415+ " btsq $63,(%rsp)\n"
25416+#endif
25417 #else
25418 " pushf\n"
25419 SAVE_REGS_STRING
25420@@ -779,7 +789,7 @@ static void __kprobes
25421 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25422 {
25423 unsigned long *tos = stack_addr(regs);
25424- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25425+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25426 unsigned long orig_ip = (unsigned long)p->addr;
25427 kprobe_opcode_t *insn = p->ainsn.insn;
25428
25429@@ -959,7 +969,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25430 struct die_args *args = data;
25431 int ret = NOTIFY_DONE;
25432
25433- if (args->regs && user_mode_vm(args->regs))
25434+ if (args->regs && user_mode(args->regs))
25435 return ret;
25436
25437 switch (val) {
25438diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25439index 898160b..758cde8 100644
25440--- a/arch/x86/kernel/kprobes/opt.c
25441+++ b/arch/x86/kernel/kprobes/opt.c
25442@@ -79,6 +79,7 @@ found:
25443 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25444 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25445 {
25446+ pax_open_kernel();
25447 #ifdef CONFIG_X86_64
25448 *addr++ = 0x48;
25449 *addr++ = 0xbf;
25450@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25451 *addr++ = 0xb8;
25452 #endif
25453 *(unsigned long *)addr = val;
25454+ pax_close_kernel();
25455 }
25456
25457 asm (
25458@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25459 * Verify if the address gap is in 2GB range, because this uses
25460 * a relative jump.
25461 */
25462- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25463+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25464 if (abs(rel) > 0x7fffffff)
25465 return -ERANGE;
25466
25467@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25468 op->optinsn.size = ret;
25469
25470 /* Copy arch-dep-instance from template */
25471- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25472+ pax_open_kernel();
25473+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25474+ pax_close_kernel();
25475
25476 /* Set probe information */
25477 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25478
25479 /* Set probe function call */
25480- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25481+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25482
25483 /* Set returning jmp instruction at the tail of out-of-line buffer */
25484- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25485+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25486 (u8 *)op->kp.addr + op->optinsn.size);
25487
25488 flush_icache_range((unsigned long) buf,
25489@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25490 WARN_ON(kprobe_disabled(&op->kp));
25491
25492 /* Backup instructions which will be replaced by jump address */
25493- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25494+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25495 RELATIVE_ADDR_SIZE);
25496
25497 insn_buf[0] = RELATIVEJUMP_OPCODE;
25498@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25499 /* This kprobe is really able to run optimized path. */
25500 op = container_of(p, struct optimized_kprobe, kp);
25501 /* Detour through copied instructions */
25502- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25503+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25504 if (!reenter)
25505 reset_current_kprobe();
25506 preempt_enable_no_resched();
25507diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25508index c2bedae..25e7ab60 100644
25509--- a/arch/x86/kernel/ksysfs.c
25510+++ b/arch/x86/kernel/ksysfs.c
25511@@ -184,7 +184,7 @@ out:
25512
25513 static struct kobj_attribute type_attr = __ATTR_RO(type);
25514
25515-static struct bin_attribute data_attr = {
25516+static bin_attribute_no_const data_attr __read_only = {
25517 .attr = {
25518 .name = "data",
25519 .mode = S_IRUGO,
25520diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25521index dcbbaa1..81ae763 100644
25522--- a/arch/x86/kernel/ldt.c
25523+++ b/arch/x86/kernel/ldt.c
25524@@ -68,13 +68,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25525 if (reload) {
25526 #ifdef CONFIG_SMP
25527 preempt_disable();
25528- load_LDT(pc);
25529+ load_LDT_nolock(pc);
25530 if (!cpumask_equal(mm_cpumask(current->mm),
25531 cpumask_of(smp_processor_id())))
25532 smp_call_function(flush_ldt, current->mm, 1);
25533 preempt_enable();
25534 #else
25535- load_LDT(pc);
25536+ load_LDT_nolock(pc);
25537 #endif
25538 }
25539 if (oldsize) {
25540@@ -96,7 +96,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25541 return err;
25542
25543 for (i = 0; i < old->size; i++)
25544- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25545+ write_ldt_entry(new->ldt, i, old->ldt + i);
25546 return 0;
25547 }
25548
25549@@ -117,6 +117,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25550 retval = copy_ldt(&mm->context, &old_mm->context);
25551 mutex_unlock(&old_mm->context.lock);
25552 }
25553+
25554+ if (tsk == current) {
25555+ mm->context.vdso = 0;
25556+
25557+#ifdef CONFIG_X86_32
25558+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25559+ mm->context.user_cs_base = 0UL;
25560+ mm->context.user_cs_limit = ~0UL;
25561+
25562+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25563+ cpus_clear(mm->context.cpu_user_cs_mask);
25564+#endif
25565+
25566+#endif
25567+#endif
25568+
25569+ }
25570+
25571 return retval;
25572 }
25573
25574@@ -231,6 +249,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25575 }
25576 }
25577
25578+#ifdef CONFIG_PAX_SEGMEXEC
25579+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25580+ error = -EINVAL;
25581+ goto out_unlock;
25582+ }
25583+#endif
25584+
25585 /*
25586 * On x86-64 we do not support 16-bit segments due to
25587 * IRET leaking the high bits of the kernel stack address.
25588diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25589index 1667b1d..16492c5 100644
25590--- a/arch/x86/kernel/machine_kexec_32.c
25591+++ b/arch/x86/kernel/machine_kexec_32.c
25592@@ -25,7 +25,7 @@
25593 #include <asm/cacheflush.h>
25594 #include <asm/debugreg.h>
25595
25596-static void set_idt(void *newidt, __u16 limit)
25597+static void set_idt(struct desc_struct *newidt, __u16 limit)
25598 {
25599 struct desc_ptr curidt;
25600
25601@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25602 }
25603
25604
25605-static void set_gdt(void *newgdt, __u16 limit)
25606+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25607 {
25608 struct desc_ptr curgdt;
25609
25610@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25611 }
25612
25613 control_page = page_address(image->control_code_page);
25614- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25615+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25616
25617 relocate_kernel_ptr = control_page;
25618 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25619diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25620index e69f988..da078ea 100644
25621--- a/arch/x86/kernel/module.c
25622+++ b/arch/x86/kernel/module.c
25623@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25624 }
25625 #endif
25626
25627-void *module_alloc(unsigned long size)
25628+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25629 {
25630- if (PAGE_ALIGN(size) > MODULES_LEN)
25631+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25632 return NULL;
25633 return __vmalloc_node_range(size, 1,
25634 MODULES_VADDR + get_module_load_offset(),
25635- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25636- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25637+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25638+ prot, NUMA_NO_NODE,
25639 __builtin_return_address(0));
25640 }
25641
25642+void *module_alloc(unsigned long size)
25643+{
25644+
25645+#ifdef CONFIG_PAX_KERNEXEC
25646+ return __module_alloc(size, PAGE_KERNEL);
25647+#else
25648+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25649+#endif
25650+
25651+}
25652+
25653+#ifdef CONFIG_PAX_KERNEXEC
25654+#ifdef CONFIG_X86_32
25655+void *module_alloc_exec(unsigned long size)
25656+{
25657+ struct vm_struct *area;
25658+
25659+ if (size == 0)
25660+ return NULL;
25661+
25662+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25663+return area ? area->addr : NULL;
25664+}
25665+EXPORT_SYMBOL(module_alloc_exec);
25666+
25667+void module_free_exec(struct module *mod, void *module_region)
25668+{
25669+ vunmap(module_region);
25670+}
25671+EXPORT_SYMBOL(module_free_exec);
25672+#else
25673+void module_free_exec(struct module *mod, void *module_region)
25674+{
25675+ module_free(mod, module_region);
25676+}
25677+EXPORT_SYMBOL(module_free_exec);
25678+
25679+void *module_alloc_exec(unsigned long size)
25680+{
25681+ return __module_alloc(size, PAGE_KERNEL_RX);
25682+}
25683+EXPORT_SYMBOL(module_alloc_exec);
25684+#endif
25685+#endif
25686+
25687 #ifdef CONFIG_X86_32
25688 int apply_relocate(Elf32_Shdr *sechdrs,
25689 const char *strtab,
25690@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25691 unsigned int i;
25692 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25693 Elf32_Sym *sym;
25694- uint32_t *location;
25695+ uint32_t *plocation, location;
25696
25697 DEBUGP("Applying relocate section %u to %u\n",
25698 relsec, sechdrs[relsec].sh_info);
25699 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25700 /* This is where to make the change */
25701- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25702- + rel[i].r_offset;
25703+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25704+ location = (uint32_t)plocation;
25705+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25706+ plocation = ktla_ktva((void *)plocation);
25707 /* This is the symbol it is referring to. Note that all
25708 undefined symbols have been resolved. */
25709 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25710@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25711 switch (ELF32_R_TYPE(rel[i].r_info)) {
25712 case R_386_32:
25713 /* We add the value into the location given */
25714- *location += sym->st_value;
25715+ pax_open_kernel();
25716+ *plocation += sym->st_value;
25717+ pax_close_kernel();
25718 break;
25719 case R_386_PC32:
25720 /* Add the value, subtract its position */
25721- *location += sym->st_value - (uint32_t)location;
25722+ pax_open_kernel();
25723+ *plocation += sym->st_value - location;
25724+ pax_close_kernel();
25725 break;
25726 default:
25727 pr_err("%s: Unknown relocation: %u\n",
25728@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25729 case R_X86_64_NONE:
25730 break;
25731 case R_X86_64_64:
25732+ pax_open_kernel();
25733 *(u64 *)loc = val;
25734+ pax_close_kernel();
25735 break;
25736 case R_X86_64_32:
25737+ pax_open_kernel();
25738 *(u32 *)loc = val;
25739+ pax_close_kernel();
25740 if (val != *(u32 *)loc)
25741 goto overflow;
25742 break;
25743 case R_X86_64_32S:
25744+ pax_open_kernel();
25745 *(s32 *)loc = val;
25746+ pax_close_kernel();
25747 if ((s64)val != *(s32 *)loc)
25748 goto overflow;
25749 break;
25750 case R_X86_64_PC32:
25751 val -= (u64)loc;
25752+ pax_open_kernel();
25753 *(u32 *)loc = val;
25754+ pax_close_kernel();
25755+
25756 #if 0
25757 if ((s64)val != *(s32 *)loc)
25758 goto overflow;
25759diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25760index c9603ac..9f88728 100644
25761--- a/arch/x86/kernel/msr.c
25762+++ b/arch/x86/kernel/msr.c
25763@@ -37,6 +37,7 @@
25764 #include <linux/notifier.h>
25765 #include <linux/uaccess.h>
25766 #include <linux/gfp.h>
25767+#include <linux/grsecurity.h>
25768
25769 #include <asm/processor.h>
25770 #include <asm/msr.h>
25771@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25772 int err = 0;
25773 ssize_t bytes = 0;
25774
25775+#ifdef CONFIG_GRKERNSEC_KMEM
25776+ gr_handle_msr_write();
25777+ return -EPERM;
25778+#endif
25779+
25780 if (count % 8)
25781 return -EINVAL; /* Invalid chunk size */
25782
25783@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25784 err = -EBADF;
25785 break;
25786 }
25787+#ifdef CONFIG_GRKERNSEC_KMEM
25788+ gr_handle_msr_write();
25789+ return -EPERM;
25790+#endif
25791 if (copy_from_user(&regs, uregs, sizeof regs)) {
25792 err = -EFAULT;
25793 break;
25794@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25795 return notifier_from_errno(err);
25796 }
25797
25798-static struct notifier_block __refdata msr_class_cpu_notifier = {
25799+static struct notifier_block msr_class_cpu_notifier = {
25800 .notifier_call = msr_class_cpu_callback,
25801 };
25802
25803diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25804index b4872b9..5bf0684 100644
25805--- a/arch/x86/kernel/nmi.c
25806+++ b/arch/x86/kernel/nmi.c
25807@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
25808
25809 static void nmi_max_handler(struct irq_work *w)
25810 {
25811- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
25812+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
25813 int remainder_ns, decimal_msecs;
25814- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
25815+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
25816
25817 remainder_ns = do_div(whole_msecs, (1000 * 1000));
25818 decimal_msecs = remainder_ns / 1000;
25819
25820 printk_ratelimited(KERN_INFO
25821 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
25822- a->handler, whole_msecs, decimal_msecs);
25823+ n->action->handler, whole_msecs, decimal_msecs);
25824 }
25825
25826 static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
25827@@ -134,11 +134,11 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25828 delta = sched_clock() - delta;
25829 trace_nmi_handler(a->handler, (int)delta, thishandled);
25830
25831- if (delta < nmi_longest_ns || delta < a->max_duration)
25832+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
25833 continue;
25834
25835- a->max_duration = delta;
25836- irq_work_queue(&a->irq_work);
25837+ a->work->max_duration = delta;
25838+ irq_work_queue(&a->work->irq_work);
25839 }
25840
25841 rcu_read_unlock();
25842@@ -147,7 +147,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25843 return handled;
25844 }
25845
25846-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25847+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25848 {
25849 struct nmi_desc *desc = nmi_to_desc(type);
25850 unsigned long flags;
25851@@ -155,7 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25852 if (!action->handler)
25853 return -EINVAL;
25854
25855- init_irq_work(&action->irq_work, nmi_max_handler);
25856+ action->work->action = action;
25857+ init_irq_work(&action->work->irq_work, nmi_max_handler);
25858
25859 spin_lock_irqsave(&desc->lock, flags);
25860
25861@@ -173,9 +174,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25862 * event confuses some handlers (kdump uses this flag)
25863 */
25864 if (action->flags & NMI_FLAG_FIRST)
25865- list_add_rcu(&action->list, &desc->head);
25866+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25867 else
25868- list_add_tail_rcu(&action->list, &desc->head);
25869+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25870
25871 spin_unlock_irqrestore(&desc->lock, flags);
25872 return 0;
25873@@ -198,7 +199,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25874 if (!strcmp(n->name, name)) {
25875 WARN(in_nmi(),
25876 "Trying to free NMI (%s) from NMI context!\n", n->name);
25877- list_del_rcu(&n->list);
25878+ pax_list_del_rcu((struct list_head *)&n->list);
25879 break;
25880 }
25881 }
25882@@ -523,6 +524,17 @@ static inline void nmi_nesting_postprocess(void)
25883 dotraplinkage notrace __kprobes void
25884 do_nmi(struct pt_regs *regs, long error_code)
25885 {
25886+
25887+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25888+ if (!user_mode(regs)) {
25889+ unsigned long cs = regs->cs & 0xFFFF;
25890+ unsigned long ip = ktva_ktla(regs->ip);
25891+
25892+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25893+ regs->ip = ip;
25894+ }
25895+#endif
25896+
25897 nmi_nesting_preprocess(regs);
25898
25899 nmi_enter();
25900diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25901index 6d9582e..f746287 100644
25902--- a/arch/x86/kernel/nmi_selftest.c
25903+++ b/arch/x86/kernel/nmi_selftest.c
25904@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25905 {
25906 /* trap all the unknown NMIs we may generate */
25907 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25908- __initdata);
25909+ __initconst);
25910 }
25911
25912 static void __init cleanup_nmi_testsuite(void)
25913@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25914 unsigned long timeout;
25915
25916 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25917- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25918+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25919 nmi_fail = FAILURE;
25920 return;
25921 }
25922diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25923index bbb6c73..24a58ef 100644
25924--- a/arch/x86/kernel/paravirt-spinlocks.c
25925+++ b/arch/x86/kernel/paravirt-spinlocks.c
25926@@ -8,7 +8,7 @@
25927
25928 #include <asm/paravirt.h>
25929
25930-struct pv_lock_ops pv_lock_ops = {
25931+struct pv_lock_ops pv_lock_ops __read_only = {
25932 #ifdef CONFIG_SMP
25933 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25934 .unlock_kick = paravirt_nop,
25935diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25936index 1b10af8..45bfbec 100644
25937--- a/arch/x86/kernel/paravirt.c
25938+++ b/arch/x86/kernel/paravirt.c
25939@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25940 {
25941 return x;
25942 }
25943+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25944+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25945+#endif
25946
25947 void __init default_banner(void)
25948 {
25949@@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25950
25951 if (opfunc == NULL)
25952 /* If there's no function, patch it with a ud2a (BUG) */
25953- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25954- else if (opfunc == _paravirt_nop)
25955+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
25956+ else if (opfunc == (void *)_paravirt_nop)
25957 /* If the operation is a nop, then nop the callsite */
25958 ret = paravirt_patch_nop();
25959
25960 /* identity functions just return their single argument */
25961- else if (opfunc == _paravirt_ident_32)
25962+ else if (opfunc == (void *)_paravirt_ident_32)
25963 ret = paravirt_patch_ident_32(insnbuf, len);
25964- else if (opfunc == _paravirt_ident_64)
25965+ else if (opfunc == (void *)_paravirt_ident_64)
25966 ret = paravirt_patch_ident_64(insnbuf, len);
25967+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25968+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25969+ ret = paravirt_patch_ident_64(insnbuf, len);
25970+#endif
25971
25972 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25973 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25974@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25975 if (insn_len > len || start == NULL)
25976 insn_len = len;
25977 else
25978- memcpy(insnbuf, start, insn_len);
25979+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25980
25981 return insn_len;
25982 }
25983@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25984 return this_cpu_read(paravirt_lazy_mode);
25985 }
25986
25987-struct pv_info pv_info = {
25988+struct pv_info pv_info __read_only = {
25989 .name = "bare hardware",
25990 .paravirt_enabled = 0,
25991 .kernel_rpl = 0,
25992@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25993 #endif
25994 };
25995
25996-struct pv_init_ops pv_init_ops = {
25997+struct pv_init_ops pv_init_ops __read_only = {
25998 .patch = native_patch,
25999 };
26000
26001-struct pv_time_ops pv_time_ops = {
26002+struct pv_time_ops pv_time_ops __read_only = {
26003 .sched_clock = native_sched_clock,
26004 .steal_clock = native_steal_clock,
26005 };
26006
26007-__visible struct pv_irq_ops pv_irq_ops = {
26008+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26009 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26010 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26011 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26012@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26013 #endif
26014 };
26015
26016-__visible struct pv_cpu_ops pv_cpu_ops = {
26017+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26018 .cpuid = native_cpuid,
26019 .get_debugreg = native_get_debugreg,
26020 .set_debugreg = native_set_debugreg,
26021@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26022 .end_context_switch = paravirt_nop,
26023 };
26024
26025-struct pv_apic_ops pv_apic_ops = {
26026+struct pv_apic_ops pv_apic_ops __read_only= {
26027 #ifdef CONFIG_X86_LOCAL_APIC
26028 .startup_ipi_hook = paravirt_nop,
26029 #endif
26030 };
26031
26032-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26033+#ifdef CONFIG_X86_32
26034+#ifdef CONFIG_X86_PAE
26035+/* 64-bit pagetable entries */
26036+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26037+#else
26038 /* 32-bit pagetable entries */
26039 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26040+#endif
26041 #else
26042 /* 64-bit pagetable entries */
26043 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26044 #endif
26045
26046-struct pv_mmu_ops pv_mmu_ops = {
26047+struct pv_mmu_ops pv_mmu_ops __read_only = {
26048
26049 .read_cr2 = native_read_cr2,
26050 .write_cr2 = native_write_cr2,
26051@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26052 .make_pud = PTE_IDENT,
26053
26054 .set_pgd = native_set_pgd,
26055+ .set_pgd_batched = native_set_pgd_batched,
26056 #endif
26057 #endif /* PAGETABLE_LEVELS >= 3 */
26058
26059@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26060 },
26061
26062 .set_fixmap = native_set_fixmap,
26063+
26064+#ifdef CONFIG_PAX_KERNEXEC
26065+ .pax_open_kernel = native_pax_open_kernel,
26066+ .pax_close_kernel = native_pax_close_kernel,
26067+#endif
26068+
26069 };
26070
26071 EXPORT_SYMBOL_GPL(pv_time_ops);
26072diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26073index 0497f71..7186c0d 100644
26074--- a/arch/x86/kernel/pci-calgary_64.c
26075+++ b/arch/x86/kernel/pci-calgary_64.c
26076@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26077 tce_space = be64_to_cpu(readq(target));
26078 tce_space = tce_space & TAR_SW_BITS;
26079
26080- tce_space = tce_space & (~specified_table_size);
26081+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26082 info->tce_space = (u64 *)__va(tce_space);
26083 }
26084 }
26085diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26086index 35ccf75..7a15747 100644
26087--- a/arch/x86/kernel/pci-iommu_table.c
26088+++ b/arch/x86/kernel/pci-iommu_table.c
26089@@ -2,7 +2,7 @@
26090 #include <asm/iommu_table.h>
26091 #include <linux/string.h>
26092 #include <linux/kallsyms.h>
26093-
26094+#include <linux/sched.h>
26095
26096 #define DEBUG 1
26097
26098diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26099index 6c483ba..d10ce2f 100644
26100--- a/arch/x86/kernel/pci-swiotlb.c
26101+++ b/arch/x86/kernel/pci-swiotlb.c
26102@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26103 void *vaddr, dma_addr_t dma_addr,
26104 struct dma_attrs *attrs)
26105 {
26106- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26107+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26108 }
26109
26110 static struct dma_map_ops swiotlb_dma_ops = {
26111diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26112index ca7f0d5..8996469 100644
26113--- a/arch/x86/kernel/preempt.S
26114+++ b/arch/x86/kernel/preempt.S
26115@@ -3,12 +3,14 @@
26116 #include <asm/dwarf2.h>
26117 #include <asm/asm.h>
26118 #include <asm/calling.h>
26119+#include <asm/alternative-asm.h>
26120
26121 ENTRY(___preempt_schedule)
26122 CFI_STARTPROC
26123 SAVE_ALL
26124 call preempt_schedule
26125 RESTORE_ALL
26126+ pax_force_retaddr
26127 ret
26128 CFI_ENDPROC
26129
26130@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26131 SAVE_ALL
26132 call preempt_schedule_context
26133 RESTORE_ALL
26134+ pax_force_retaddr
26135 ret
26136 CFI_ENDPROC
26137
26138diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26139index 4505e2a..ae28b0d 100644
26140--- a/arch/x86/kernel/process.c
26141+++ b/arch/x86/kernel/process.c
26142@@ -36,7 +36,8 @@
26143 * section. Since TSS's are completely CPU-local, we want them
26144 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26145 */
26146-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26147+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26148+EXPORT_SYMBOL(init_tss);
26149
26150 #ifdef CONFIG_X86_64
26151 static DEFINE_PER_CPU(unsigned char, is_idle);
26152@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26153 task_xstate_cachep =
26154 kmem_cache_create("task_xstate", xstate_size,
26155 __alignof__(union thread_xstate),
26156- SLAB_PANIC | SLAB_NOTRACK, NULL);
26157+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26158 }
26159
26160 /*
26161@@ -105,7 +106,7 @@ void exit_thread(void)
26162 unsigned long *bp = t->io_bitmap_ptr;
26163
26164 if (bp) {
26165- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26166+ struct tss_struct *tss = init_tss + get_cpu();
26167
26168 t->io_bitmap_ptr = NULL;
26169 clear_thread_flag(TIF_IO_BITMAP);
26170@@ -125,6 +126,9 @@ void flush_thread(void)
26171 {
26172 struct task_struct *tsk = current;
26173
26174+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26175+ loadsegment(gs, 0);
26176+#endif
26177 flush_ptrace_hw_breakpoint(tsk);
26178 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26179 drop_init_fpu(tsk);
26180@@ -271,7 +275,7 @@ static void __exit_idle(void)
26181 void exit_idle(void)
26182 {
26183 /* idle loop has pid 0 */
26184- if (current->pid)
26185+ if (task_pid_nr(current))
26186 return;
26187 __exit_idle();
26188 }
26189@@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26190 return ret;
26191 }
26192 #endif
26193-void stop_this_cpu(void *dummy)
26194+__noreturn void stop_this_cpu(void *dummy)
26195 {
26196 local_irq_disable();
26197 /*
26198@@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26199 }
26200 early_param("idle", idle_setup);
26201
26202-unsigned long arch_align_stack(unsigned long sp)
26203+#ifdef CONFIG_PAX_RANDKSTACK
26204+void pax_randomize_kstack(struct pt_regs *regs)
26205 {
26206- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26207- sp -= get_random_int() % 8192;
26208- return sp & ~0xf;
26209-}
26210+ struct thread_struct *thread = &current->thread;
26211+ unsigned long time;
26212
26213-unsigned long arch_randomize_brk(struct mm_struct *mm)
26214-{
26215- unsigned long range_end = mm->brk + 0x02000000;
26216- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26217-}
26218+ if (!randomize_va_space)
26219+ return;
26220+
26221+ if (v8086_mode(regs))
26222+ return;
26223
26224+ rdtscl(time);
26225+
26226+ /* P4 seems to return a 0 LSB, ignore it */
26227+#ifdef CONFIG_MPENTIUM4
26228+ time &= 0x3EUL;
26229+ time <<= 2;
26230+#elif defined(CONFIG_X86_64)
26231+ time &= 0xFUL;
26232+ time <<= 4;
26233+#else
26234+ time &= 0x1FUL;
26235+ time <<= 3;
26236+#endif
26237+
26238+ thread->sp0 ^= time;
26239+ load_sp0(init_tss + smp_processor_id(), thread);
26240+
26241+#ifdef CONFIG_X86_64
26242+ this_cpu_write(kernel_stack, thread->sp0);
26243+#endif
26244+}
26245+#endif
26246diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26247index 7bc86bb..0ea06e8 100644
26248--- a/arch/x86/kernel/process_32.c
26249+++ b/arch/x86/kernel/process_32.c
26250@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26251 unsigned long thread_saved_pc(struct task_struct *tsk)
26252 {
26253 return ((unsigned long *)tsk->thread.sp)[3];
26254+//XXX return tsk->thread.eip;
26255 }
26256
26257 void __show_regs(struct pt_regs *regs, int all)
26258@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26259 unsigned long sp;
26260 unsigned short ss, gs;
26261
26262- if (user_mode_vm(regs)) {
26263+ if (user_mode(regs)) {
26264 sp = regs->sp;
26265 ss = regs->ss & 0xffff;
26266- gs = get_user_gs(regs);
26267 } else {
26268 sp = kernel_stack_pointer(regs);
26269 savesegment(ss, ss);
26270- savesegment(gs, gs);
26271 }
26272+ gs = get_user_gs(regs);
26273
26274 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26275 (u16)regs->cs, regs->ip, regs->flags,
26276- smp_processor_id());
26277+ raw_smp_processor_id());
26278 print_symbol("EIP is at %s\n", regs->ip);
26279
26280 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26281@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26282 int copy_thread(unsigned long clone_flags, unsigned long sp,
26283 unsigned long arg, struct task_struct *p)
26284 {
26285- struct pt_regs *childregs = task_pt_regs(p);
26286+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26287 struct task_struct *tsk;
26288 int err;
26289
26290 p->thread.sp = (unsigned long) childregs;
26291 p->thread.sp0 = (unsigned long) (childregs+1);
26292+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26293
26294 if (unlikely(p->flags & PF_KTHREAD)) {
26295 /* kernel thread */
26296 memset(childregs, 0, sizeof(struct pt_regs));
26297 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26298- task_user_gs(p) = __KERNEL_STACK_CANARY;
26299- childregs->ds = __USER_DS;
26300- childregs->es = __USER_DS;
26301+ savesegment(gs, childregs->gs);
26302+ childregs->ds = __KERNEL_DS;
26303+ childregs->es = __KERNEL_DS;
26304 childregs->fs = __KERNEL_PERCPU;
26305 childregs->bx = sp; /* function */
26306 childregs->bp = arg;
26307@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26308 struct thread_struct *prev = &prev_p->thread,
26309 *next = &next_p->thread;
26310 int cpu = smp_processor_id();
26311- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26312+ struct tss_struct *tss = init_tss + cpu;
26313 fpu_switch_t fpu;
26314
26315 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26316@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26317 */
26318 lazy_save_gs(prev->gs);
26319
26320+#ifdef CONFIG_PAX_MEMORY_UDEREF
26321+ __set_fs(task_thread_info(next_p)->addr_limit);
26322+#endif
26323+
26324 /*
26325 * Load the per-thread Thread-Local Storage descriptor.
26326 */
26327@@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26328 */
26329 arch_end_context_switch(next_p);
26330
26331- this_cpu_write(kernel_stack,
26332- (unsigned long)task_stack_page(next_p) +
26333- THREAD_SIZE - KERNEL_STACK_OFFSET);
26334+ this_cpu_write(current_task, next_p);
26335+ this_cpu_write(current_tinfo, &next_p->tinfo);
26336+ this_cpu_write(kernel_stack, next->sp0);
26337
26338 /*
26339 * Restore %gs if needed (which is common)
26340@@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26341
26342 switch_fpu_finish(next_p, fpu);
26343
26344- this_cpu_write(current_task, next_p);
26345-
26346 return prev_p;
26347 }
26348
26349@@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26350 } while (count++ < 16);
26351 return 0;
26352 }
26353-
26354diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26355index 898d077..4c458ff 100644
26356--- a/arch/x86/kernel/process_64.c
26357+++ b/arch/x86/kernel/process_64.c
26358@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26359 struct pt_regs *childregs;
26360 struct task_struct *me = current;
26361
26362- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26363+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26364 childregs = task_pt_regs(p);
26365 p->thread.sp = (unsigned long) childregs;
26366 p->thread.usersp = me->thread.usersp;
26367+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26368 set_tsk_thread_flag(p, TIF_FORK);
26369 p->thread.fpu_counter = 0;
26370 p->thread.io_bitmap_ptr = NULL;
26371@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26372 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26373 savesegment(es, p->thread.es);
26374 savesegment(ds, p->thread.ds);
26375+ savesegment(ss, p->thread.ss);
26376+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26377 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26378
26379 if (unlikely(p->flags & PF_KTHREAD)) {
26380@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26381 struct thread_struct *prev = &prev_p->thread;
26382 struct thread_struct *next = &next_p->thread;
26383 int cpu = smp_processor_id();
26384- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26385+ struct tss_struct *tss = init_tss + cpu;
26386 unsigned fsindex, gsindex;
26387 fpu_switch_t fpu;
26388
26389@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26390 if (unlikely(next->ds | prev->ds))
26391 loadsegment(ds, next->ds);
26392
26393+ savesegment(ss, prev->ss);
26394+ if (unlikely(next->ss != prev->ss))
26395+ loadsegment(ss, next->ss);
26396
26397 /* We must save %fs and %gs before load_TLS() because
26398 * %fs and %gs may be cleared by load_TLS().
26399@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26400 prev->usersp = this_cpu_read(old_rsp);
26401 this_cpu_write(old_rsp, next->usersp);
26402 this_cpu_write(current_task, next_p);
26403+ this_cpu_write(current_tinfo, &next_p->tinfo);
26404
26405 /*
26406 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26407@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26408 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26409 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26410
26411- this_cpu_write(kernel_stack,
26412- (unsigned long)task_stack_page(next_p) +
26413- THREAD_SIZE - KERNEL_STACK_OFFSET);
26414+ this_cpu_write(kernel_stack, next->sp0);
26415
26416 /*
26417 * Now maybe reload the debug registers and handle I/O bitmaps
26418@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26419 if (!p || p == current || p->state == TASK_RUNNING)
26420 return 0;
26421 stack = (unsigned long)task_stack_page(p);
26422- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26423+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26424 return 0;
26425 fp = *(u64 *)(p->thread.sp);
26426 do {
26427- if (fp < (unsigned long)stack ||
26428- fp >= (unsigned long)stack+THREAD_SIZE)
26429+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26430 return 0;
26431 ip = *(u64 *)(fp+8);
26432 if (!in_sched_functions(ip))
26433diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26434index 678c0ad..d309ccb 100644
26435--- a/arch/x86/kernel/ptrace.c
26436+++ b/arch/x86/kernel/ptrace.c
26437@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26438 unsigned long sp = (unsigned long)&regs->sp;
26439 u32 *prev_esp;
26440
26441- if (context == (sp & ~(THREAD_SIZE - 1)))
26442+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26443 return sp;
26444
26445- prev_esp = (u32 *)(context);
26446+ prev_esp = *(u32 **)(context);
26447 if (prev_esp)
26448 return (unsigned long)prev_esp;
26449
26450@@ -588,7 +588,7 @@ static void ptrace_triggered(struct perf_event *bp,
26451 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26452 {
26453 int i;
26454- int dr7 = 0;
26455+ unsigned long dr7 = 0;
26456 struct arch_hw_breakpoint *info;
26457
26458 for (i = 0; i < HBP_NUM; i++) {
26459@@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
26460 unsigned long addr, unsigned long data)
26461 {
26462 int ret;
26463- unsigned long __user *datap = (unsigned long __user *)data;
26464+ unsigned long __user *datap = (__force unsigned long __user *)data;
26465
26466 switch (request) {
26467 /* read the word at location addr in the USER area. */
26468@@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
26469 if ((int) addr < 0)
26470 return -EIO;
26471 ret = do_get_thread_area(child, addr,
26472- (struct user_desc __user *)data);
26473+ (__force struct user_desc __user *) data);
26474 break;
26475
26476 case PTRACE_SET_THREAD_AREA:
26477 if ((int) addr < 0)
26478 return -EIO;
26479 ret = do_set_thread_area(child, addr,
26480- (struct user_desc __user *)data, 0);
26481+ (__force struct user_desc __user *) data, 0);
26482 break;
26483 #endif
26484
26485@@ -1292,7 +1292,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26486
26487 #ifdef CONFIG_X86_64
26488
26489-static struct user_regset x86_64_regsets[] __read_mostly = {
26490+static user_regset_no_const x86_64_regsets[] __read_only = {
26491 [REGSET_GENERAL] = {
26492 .core_note_type = NT_PRSTATUS,
26493 .n = sizeof(struct user_regs_struct) / sizeof(long),
26494@@ -1333,7 +1333,7 @@ static const struct user_regset_view user_x86_64_view = {
26495 #endif /* CONFIG_X86_64 */
26496
26497 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26498-static struct user_regset x86_32_regsets[] __read_mostly = {
26499+static user_regset_no_const x86_32_regsets[] __read_only = {
26500 [REGSET_GENERAL] = {
26501 .core_note_type = NT_PRSTATUS,
26502 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26503@@ -1386,7 +1386,7 @@ static const struct user_regset_view user_x86_32_view = {
26504 */
26505 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26506
26507-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26508+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26509 {
26510 #ifdef CONFIG_X86_64
26511 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26512@@ -1421,7 +1421,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26513 memset(info, 0, sizeof(*info));
26514 info->si_signo = SIGTRAP;
26515 info->si_code = si_code;
26516- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26517+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26518 }
26519
26520 void user_single_step_siginfo(struct task_struct *tsk,
26521@@ -1450,6 +1450,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26522 # define IS_IA32 0
26523 #endif
26524
26525+#ifdef CONFIG_GRKERNSEC_SETXID
26526+extern void gr_delayed_cred_worker(void);
26527+#endif
26528+
26529 /*
26530 * We must return the syscall number to actually look up in the table.
26531 * This can be -1L to skip running any syscall at all.
26532@@ -1460,6 +1464,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26533
26534 user_exit();
26535
26536+#ifdef CONFIG_GRKERNSEC_SETXID
26537+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26538+ gr_delayed_cred_worker();
26539+#endif
26540+
26541 /*
26542 * If we stepped into a sysenter/syscall insn, it trapped in
26543 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26544@@ -1515,6 +1524,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26545 */
26546 user_exit();
26547
26548+#ifdef CONFIG_GRKERNSEC_SETXID
26549+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26550+ gr_delayed_cred_worker();
26551+#endif
26552+
26553 audit_syscall_exit(regs);
26554
26555 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26556diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26557index 2f355d2..e75ed0a 100644
26558--- a/arch/x86/kernel/pvclock.c
26559+++ b/arch/x86/kernel/pvclock.c
26560@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26561 reset_hung_task_detector();
26562 }
26563
26564-static atomic64_t last_value = ATOMIC64_INIT(0);
26565+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26566
26567 void pvclock_resume(void)
26568 {
26569- atomic64_set(&last_value, 0);
26570+ atomic64_set_unchecked(&last_value, 0);
26571 }
26572
26573 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26574@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26575 * updating at the same time, and one of them could be slightly behind,
26576 * making the assumption that last_value always go forward fail to hold.
26577 */
26578- last = atomic64_read(&last_value);
26579+ last = atomic64_read_unchecked(&last_value);
26580 do {
26581 if (ret < last)
26582 return last;
26583- last = atomic64_cmpxchg(&last_value, last, ret);
26584+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26585 } while (unlikely(last != ret));
26586
26587 return ret;
26588diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26589index 52b1157..c6e67c4 100644
26590--- a/arch/x86/kernel/reboot.c
26591+++ b/arch/x86/kernel/reboot.c
26592@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26593
26594 void __noreturn machine_real_restart(unsigned int type)
26595 {
26596+
26597+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26598+ struct desc_struct *gdt;
26599+#endif
26600+
26601 local_irq_disable();
26602
26603 /*
26604@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26605
26606 /* Jump to the identity-mapped low memory code */
26607 #ifdef CONFIG_X86_32
26608- asm volatile("jmpl *%0" : :
26609+
26610+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26611+ gdt = get_cpu_gdt_table(smp_processor_id());
26612+ pax_open_kernel();
26613+#ifdef CONFIG_PAX_MEMORY_UDEREF
26614+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26615+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26616+ loadsegment(ds, __KERNEL_DS);
26617+ loadsegment(es, __KERNEL_DS);
26618+ loadsegment(ss, __KERNEL_DS);
26619+#endif
26620+#ifdef CONFIG_PAX_KERNEXEC
26621+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26622+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26623+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26624+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26625+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26626+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26627+#endif
26628+ pax_close_kernel();
26629+#endif
26630+
26631+ asm volatile("ljmpl *%0" : :
26632 "rm" (real_mode_header->machine_real_restart_asm),
26633 "a" (type));
26634 #else
26635@@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26636 * This means that this function can never return, it can misbehave
26637 * by not rebooting properly and hanging.
26638 */
26639-static void native_machine_emergency_restart(void)
26640+static void __noreturn native_machine_emergency_restart(void)
26641 {
26642 int i;
26643 int attempt = 0;
26644@@ -610,13 +637,13 @@ void native_machine_shutdown(void)
26645 #endif
26646 }
26647
26648-static void __machine_emergency_restart(int emergency)
26649+static void __noreturn __machine_emergency_restart(int emergency)
26650 {
26651 reboot_emergency = emergency;
26652 machine_ops.emergency_restart();
26653 }
26654
26655-static void native_machine_restart(char *__unused)
26656+static void __noreturn native_machine_restart(char *__unused)
26657 {
26658 pr_notice("machine restart\n");
26659
26660@@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
26661 __machine_emergency_restart(0);
26662 }
26663
26664-static void native_machine_halt(void)
26665+static void __noreturn native_machine_halt(void)
26666 {
26667 /* Stop other cpus and apics */
26668 machine_shutdown();
26669@@ -635,7 +662,7 @@ static void native_machine_halt(void)
26670 stop_this_cpu(NULL);
26671 }
26672
26673-static void native_machine_power_off(void)
26674+static void __noreturn native_machine_power_off(void)
26675 {
26676 if (pm_power_off) {
26677 if (!reboot_force)
26678@@ -644,9 +671,10 @@ static void native_machine_power_off(void)
26679 }
26680 /* A fallback in case there is no PM info available */
26681 tboot_shutdown(TB_SHUTDOWN_HALT);
26682+ unreachable();
26683 }
26684
26685-struct machine_ops machine_ops = {
26686+struct machine_ops machine_ops __read_only = {
26687 .power_off = native_machine_power_off,
26688 .shutdown = native_machine_shutdown,
26689 .emergency_restart = native_machine_emergency_restart,
26690diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26691index c8e41e9..64049ef 100644
26692--- a/arch/x86/kernel/reboot_fixups_32.c
26693+++ b/arch/x86/kernel/reboot_fixups_32.c
26694@@ -57,7 +57,7 @@ struct device_fixup {
26695 unsigned int vendor;
26696 unsigned int device;
26697 void (*reboot_fixup)(struct pci_dev *);
26698-};
26699+} __do_const;
26700
26701 /*
26702 * PCI ids solely used for fixups_table go here
26703diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26704index 3fd2c69..a444264 100644
26705--- a/arch/x86/kernel/relocate_kernel_64.S
26706+++ b/arch/x86/kernel/relocate_kernel_64.S
26707@@ -96,8 +96,7 @@ relocate_kernel:
26708
26709 /* jump to identity mapped page */
26710 addq $(identity_mapped - relocate_kernel), %r8
26711- pushq %r8
26712- ret
26713+ jmp *%r8
26714
26715 identity_mapped:
26716 /* set return address to 0 if not preserving context */
26717diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26718index 09c76d2..7f33fc2 100644
26719--- a/arch/x86/kernel/setup.c
26720+++ b/arch/x86/kernel/setup.c
26721@@ -110,6 +110,7 @@
26722 #include <asm/mce.h>
26723 #include <asm/alternative.h>
26724 #include <asm/prom.h>
26725+#include <asm/boot.h>
26726
26727 /*
26728 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26729@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26730 #endif
26731
26732
26733-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26734-__visible unsigned long mmu_cr4_features;
26735+#ifdef CONFIG_X86_64
26736+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26737+#elif defined(CONFIG_X86_PAE)
26738+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26739 #else
26740-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26741+__visible unsigned long mmu_cr4_features __read_only;
26742 #endif
26743
26744+void set_in_cr4(unsigned long mask)
26745+{
26746+ unsigned long cr4 = read_cr4();
26747+
26748+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26749+ return;
26750+
26751+ pax_open_kernel();
26752+ mmu_cr4_features |= mask;
26753+ pax_close_kernel();
26754+
26755+ if (trampoline_cr4_features)
26756+ *trampoline_cr4_features = mmu_cr4_features;
26757+ cr4 |= mask;
26758+ write_cr4(cr4);
26759+}
26760+EXPORT_SYMBOL(set_in_cr4);
26761+
26762+void clear_in_cr4(unsigned long mask)
26763+{
26764+ unsigned long cr4 = read_cr4();
26765+
26766+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26767+ return;
26768+
26769+ pax_open_kernel();
26770+ mmu_cr4_features &= ~mask;
26771+ pax_close_kernel();
26772+
26773+ if (trampoline_cr4_features)
26774+ *trampoline_cr4_features = mmu_cr4_features;
26775+ cr4 &= ~mask;
26776+ write_cr4(cr4);
26777+}
26778+EXPORT_SYMBOL(clear_in_cr4);
26779+
26780 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26781 int bootloader_type, bootloader_version;
26782
26783@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26784 * area (640->1Mb) as ram even though it is not.
26785 * take them out.
26786 */
26787- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26788+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26789
26790 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26791 }
26792@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26793 /* called before trim_bios_range() to spare extra sanitize */
26794 static void __init e820_add_kernel_range(void)
26795 {
26796- u64 start = __pa_symbol(_text);
26797+ u64 start = __pa_symbol(ktla_ktva(_text));
26798 u64 size = __pa_symbol(_end) - start;
26799
26800 /*
26801@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26802
26803 void __init setup_arch(char **cmdline_p)
26804 {
26805+#ifdef CONFIG_X86_32
26806+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26807+#else
26808 memblock_reserve(__pa_symbol(_text),
26809 (unsigned long)__bss_stop - (unsigned long)_text);
26810+#endif
26811
26812 early_reserve_initrd();
26813
26814@@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
26815
26816 if (!boot_params.hdr.root_flags)
26817 root_mountflags &= ~MS_RDONLY;
26818- init_mm.start_code = (unsigned long) _text;
26819- init_mm.end_code = (unsigned long) _etext;
26820+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26821+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26822 init_mm.end_data = (unsigned long) _edata;
26823 init_mm.brk = _brk_end;
26824
26825- code_resource.start = __pa_symbol(_text);
26826- code_resource.end = __pa_symbol(_etext)-1;
26827- data_resource.start = __pa_symbol(_etext);
26828+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26829+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26830+ data_resource.start = __pa_symbol(_sdata);
26831 data_resource.end = __pa_symbol(_edata)-1;
26832 bss_resource.start = __pa_symbol(__bss_start);
26833 bss_resource.end = __pa_symbol(__bss_stop)-1;
26834diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26835index 5cdff03..80fa283 100644
26836--- a/arch/x86/kernel/setup_percpu.c
26837+++ b/arch/x86/kernel/setup_percpu.c
26838@@ -21,19 +21,17 @@
26839 #include <asm/cpu.h>
26840 #include <asm/stackprotector.h>
26841
26842-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26843+#ifdef CONFIG_SMP
26844+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26845 EXPORT_PER_CPU_SYMBOL(cpu_number);
26846+#endif
26847
26848-#ifdef CONFIG_X86_64
26849 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26850-#else
26851-#define BOOT_PERCPU_OFFSET 0
26852-#endif
26853
26854 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26855 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26856
26857-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26858+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26859 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26860 };
26861 EXPORT_SYMBOL(__per_cpu_offset);
26862@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26863 {
26864 #ifdef CONFIG_NEED_MULTIPLE_NODES
26865 pg_data_t *last = NULL;
26866- unsigned int cpu;
26867+ int cpu;
26868
26869 for_each_possible_cpu(cpu) {
26870 int node = early_cpu_to_node(cpu);
26871@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26872 {
26873 #ifdef CONFIG_X86_32
26874 struct desc_struct gdt;
26875+ unsigned long base = per_cpu_offset(cpu);
26876
26877- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26878- 0x2 | DESCTYPE_S, 0x8);
26879- gdt.s = 1;
26880+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26881+ 0x83 | DESCTYPE_S, 0xC);
26882 write_gdt_entry(get_cpu_gdt_table(cpu),
26883 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26884 #endif
26885@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26886 /* alrighty, percpu areas up and running */
26887 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26888 for_each_possible_cpu(cpu) {
26889+#ifdef CONFIG_CC_STACKPROTECTOR
26890+#ifdef CONFIG_X86_32
26891+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26892+#endif
26893+#endif
26894 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26895 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26896 per_cpu(cpu_number, cpu) = cpu;
26897@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26898 */
26899 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26900 #endif
26901+#ifdef CONFIG_CC_STACKPROTECTOR
26902+#ifdef CONFIG_X86_32
26903+ if (!cpu)
26904+ per_cpu(stack_canary.canary, cpu) = canary;
26905+#endif
26906+#endif
26907 /*
26908 * Up to this point, the boot CPU has been using .init.data
26909 * area. Reload any changed state for the boot CPU.
26910diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26911index 9e5de68..16c53cb 100644
26912--- a/arch/x86/kernel/signal.c
26913+++ b/arch/x86/kernel/signal.c
26914@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26915 * Align the stack pointer according to the i386 ABI,
26916 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26917 */
26918- sp = ((sp + 4) & -16ul) - 4;
26919+ sp = ((sp - 12) & -16ul) - 4;
26920 #else /* !CONFIG_X86_32 */
26921 sp = round_down(sp, 16) - 8;
26922 #endif
26923@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26924 }
26925
26926 if (current->mm->context.vdso)
26927- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26928+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26929 else
26930- restorer = &frame->retcode;
26931+ restorer = (void __user *)&frame->retcode;
26932 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26933 restorer = ksig->ka.sa.sa_restorer;
26934
26935@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26936 * reasons and because gdb uses it as a signature to notice
26937 * signal handler stack frames.
26938 */
26939- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26940+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26941
26942 if (err)
26943 return -EFAULT;
26944@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26945 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26946
26947 /* Set up to return from userspace. */
26948- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26949+ if (current->mm->context.vdso)
26950+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26951+ else
26952+ restorer = (void __user *)&frame->retcode;
26953 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26954 restorer = ksig->ka.sa.sa_restorer;
26955 put_user_ex(restorer, &frame->pretcode);
26956@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26957 * reasons and because gdb uses it as a signature to notice
26958 * signal handler stack frames.
26959 */
26960- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26961+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26962 } put_user_catch(err);
26963
26964 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26965@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26966 {
26967 int usig = signr_convert(ksig->sig);
26968 sigset_t *set = sigmask_to_save();
26969- compat_sigset_t *cset = (compat_sigset_t *) set;
26970+ sigset_t sigcopy;
26971+ compat_sigset_t *cset;
26972+
26973+ sigcopy = *set;
26974+
26975+ cset = (compat_sigset_t *) &sigcopy;
26976
26977 /* Set up the stack frame */
26978 if (is_ia32_frame()) {
26979@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26980 } else if (is_x32_frame()) {
26981 return x32_setup_rt_frame(ksig, cset, regs);
26982 } else {
26983- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26984+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26985 }
26986 }
26987
26988diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26989index be8e1bd..a3d93fa 100644
26990--- a/arch/x86/kernel/smp.c
26991+++ b/arch/x86/kernel/smp.c
26992@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26993
26994 __setup("nonmi_ipi", nonmi_ipi_setup);
26995
26996-struct smp_ops smp_ops = {
26997+struct smp_ops smp_ops __read_only = {
26998 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26999 .smp_prepare_cpus = native_smp_prepare_cpus,
27000 .smp_cpus_done = native_smp_cpus_done,
27001diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27002index ae2fd975..c0c8d10 100644
27003--- a/arch/x86/kernel/smpboot.c
27004+++ b/arch/x86/kernel/smpboot.c
27005@@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27006
27007 enable_start_cpu0 = 0;
27008
27009-#ifdef CONFIG_X86_32
27010+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
27011+ barrier();
27012+
27013 /* switch away from the initial page table */
27014+#ifdef CONFIG_PAX_PER_CPU_PGD
27015+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27016+#else
27017 load_cr3(swapper_pg_dir);
27018+#endif
27019 __flush_tlb_all();
27020-#endif
27021
27022- /* otherwise gcc will move up smp_processor_id before the cpu_init */
27023- barrier();
27024 /*
27025 * Check TSC synchronization with the BP:
27026 */
27027@@ -757,8 +760,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27028 alternatives_enable_smp();
27029
27030 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27031- (THREAD_SIZE + task_stack_page(idle))) - 1);
27032+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27033 per_cpu(current_task, cpu) = idle;
27034+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27035
27036 #ifdef CONFIG_X86_32
27037 /* Stack for startup_32 can be just as for start_secondary onwards */
27038@@ -767,10 +771,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27039 clear_tsk_thread_flag(idle, TIF_FORK);
27040 initial_gs = per_cpu_offset(cpu);
27041 #endif
27042- per_cpu(kernel_stack, cpu) =
27043- (unsigned long)task_stack_page(idle) -
27044- KERNEL_STACK_OFFSET + THREAD_SIZE;
27045+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27046+ pax_open_kernel();
27047 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27048+ pax_close_kernel();
27049 initial_code = (unsigned long)start_secondary;
27050 stack_start = idle->thread.sp;
27051
27052@@ -916,6 +920,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27053 /* the FPU context is blank, nobody can own it */
27054 __cpu_disable_lazy_restore(cpu);
27055
27056+#ifdef CONFIG_PAX_PER_CPU_PGD
27057+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27058+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27059+ KERNEL_PGD_PTRS);
27060+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27061+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27062+ KERNEL_PGD_PTRS);
27063+#endif
27064+
27065 err = do_boot_cpu(apicid, cpu, tidle);
27066 if (err) {
27067 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27068diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27069index 9b4d51d..5d28b58 100644
27070--- a/arch/x86/kernel/step.c
27071+++ b/arch/x86/kernel/step.c
27072@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27073 struct desc_struct *desc;
27074 unsigned long base;
27075
27076- seg &= ~7UL;
27077+ seg >>= 3;
27078
27079 mutex_lock(&child->mm->context.lock);
27080- if (unlikely((seg >> 3) >= child->mm->context.size))
27081+ if (unlikely(seg >= child->mm->context.size))
27082 addr = -1L; /* bogus selector, access would fault */
27083 else {
27084 desc = child->mm->context.ldt + seg;
27085@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27086 addr += base;
27087 }
27088 mutex_unlock(&child->mm->context.lock);
27089- }
27090+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27091+ addr = ktla_ktva(addr);
27092
27093 return addr;
27094 }
27095@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27096 unsigned char opcode[15];
27097 unsigned long addr = convert_ip_to_linear(child, regs);
27098
27099+ if (addr == -EINVAL)
27100+ return 0;
27101+
27102 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27103 for (i = 0; i < copied; i++) {
27104 switch (opcode[i]) {
27105diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27106new file mode 100644
27107index 0000000..5877189
27108--- /dev/null
27109+++ b/arch/x86/kernel/sys_i386_32.c
27110@@ -0,0 +1,189 @@
27111+/*
27112+ * This file contains various random system calls that
27113+ * have a non-standard calling sequence on the Linux/i386
27114+ * platform.
27115+ */
27116+
27117+#include <linux/errno.h>
27118+#include <linux/sched.h>
27119+#include <linux/mm.h>
27120+#include <linux/fs.h>
27121+#include <linux/smp.h>
27122+#include <linux/sem.h>
27123+#include <linux/msg.h>
27124+#include <linux/shm.h>
27125+#include <linux/stat.h>
27126+#include <linux/syscalls.h>
27127+#include <linux/mman.h>
27128+#include <linux/file.h>
27129+#include <linux/utsname.h>
27130+#include <linux/ipc.h>
27131+#include <linux/elf.h>
27132+
27133+#include <linux/uaccess.h>
27134+#include <linux/unistd.h>
27135+
27136+#include <asm/syscalls.h>
27137+
27138+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27139+{
27140+ unsigned long pax_task_size = TASK_SIZE;
27141+
27142+#ifdef CONFIG_PAX_SEGMEXEC
27143+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27144+ pax_task_size = SEGMEXEC_TASK_SIZE;
27145+#endif
27146+
27147+ if (flags & MAP_FIXED)
27148+ if (len > pax_task_size || addr > pax_task_size - len)
27149+ return -EINVAL;
27150+
27151+ return 0;
27152+}
27153+
27154+/*
27155+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27156+ */
27157+static unsigned long get_align_mask(void)
27158+{
27159+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27160+ return 0;
27161+
27162+ if (!(current->flags & PF_RANDOMIZE))
27163+ return 0;
27164+
27165+ return va_align.mask;
27166+}
27167+
27168+unsigned long
27169+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27170+ unsigned long len, unsigned long pgoff, unsigned long flags)
27171+{
27172+ struct mm_struct *mm = current->mm;
27173+ struct vm_area_struct *vma;
27174+ unsigned long pax_task_size = TASK_SIZE;
27175+ struct vm_unmapped_area_info info;
27176+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27177+
27178+#ifdef CONFIG_PAX_SEGMEXEC
27179+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27180+ pax_task_size = SEGMEXEC_TASK_SIZE;
27181+#endif
27182+
27183+ pax_task_size -= PAGE_SIZE;
27184+
27185+ if (len > pax_task_size)
27186+ return -ENOMEM;
27187+
27188+ if (flags & MAP_FIXED)
27189+ return addr;
27190+
27191+#ifdef CONFIG_PAX_RANDMMAP
27192+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27193+#endif
27194+
27195+ if (addr) {
27196+ addr = PAGE_ALIGN(addr);
27197+ if (pax_task_size - len >= addr) {
27198+ vma = find_vma(mm, addr);
27199+ if (check_heap_stack_gap(vma, addr, len, offset))
27200+ return addr;
27201+ }
27202+ }
27203+
27204+ info.flags = 0;
27205+ info.length = len;
27206+ info.align_mask = filp ? get_align_mask() : 0;
27207+ info.align_offset = pgoff << PAGE_SHIFT;
27208+ info.threadstack_offset = offset;
27209+
27210+#ifdef CONFIG_PAX_PAGEEXEC
27211+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27212+ info.low_limit = 0x00110000UL;
27213+ info.high_limit = mm->start_code;
27214+
27215+#ifdef CONFIG_PAX_RANDMMAP
27216+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27217+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27218+#endif
27219+
27220+ if (info.low_limit < info.high_limit) {
27221+ addr = vm_unmapped_area(&info);
27222+ if (!IS_ERR_VALUE(addr))
27223+ return addr;
27224+ }
27225+ } else
27226+#endif
27227+
27228+ info.low_limit = mm->mmap_base;
27229+ info.high_limit = pax_task_size;
27230+
27231+ return vm_unmapped_area(&info);
27232+}
27233+
27234+unsigned long
27235+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27236+ const unsigned long len, const unsigned long pgoff,
27237+ const unsigned long flags)
27238+{
27239+ struct vm_area_struct *vma;
27240+ struct mm_struct *mm = current->mm;
27241+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27242+ struct vm_unmapped_area_info info;
27243+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27244+
27245+#ifdef CONFIG_PAX_SEGMEXEC
27246+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27247+ pax_task_size = SEGMEXEC_TASK_SIZE;
27248+#endif
27249+
27250+ pax_task_size -= PAGE_SIZE;
27251+
27252+ /* requested length too big for entire address space */
27253+ if (len > pax_task_size)
27254+ return -ENOMEM;
27255+
27256+ if (flags & MAP_FIXED)
27257+ return addr;
27258+
27259+#ifdef CONFIG_PAX_PAGEEXEC
27260+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27261+ goto bottomup;
27262+#endif
27263+
27264+#ifdef CONFIG_PAX_RANDMMAP
27265+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27266+#endif
27267+
27268+ /* requesting a specific address */
27269+ if (addr) {
27270+ addr = PAGE_ALIGN(addr);
27271+ if (pax_task_size - len >= addr) {
27272+ vma = find_vma(mm, addr);
27273+ if (check_heap_stack_gap(vma, addr, len, offset))
27274+ return addr;
27275+ }
27276+ }
27277+
27278+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27279+ info.length = len;
27280+ info.low_limit = PAGE_SIZE;
27281+ info.high_limit = mm->mmap_base;
27282+ info.align_mask = filp ? get_align_mask() : 0;
27283+ info.align_offset = pgoff << PAGE_SHIFT;
27284+ info.threadstack_offset = offset;
27285+
27286+ addr = vm_unmapped_area(&info);
27287+ if (!(addr & ~PAGE_MASK))
27288+ return addr;
27289+ VM_BUG_ON(addr != -ENOMEM);
27290+
27291+bottomup:
27292+ /*
27293+ * A failed mmap() very likely causes application failure,
27294+ * so fall back to the bottom-up function here. This scenario
27295+ * can happen with large stack limits and large mmap()
27296+ * allocations.
27297+ */
27298+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27299+}
27300diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27301index 30277e2..5664a29 100644
27302--- a/arch/x86/kernel/sys_x86_64.c
27303+++ b/arch/x86/kernel/sys_x86_64.c
27304@@ -81,8 +81,8 @@ out:
27305 return error;
27306 }
27307
27308-static void find_start_end(unsigned long flags, unsigned long *begin,
27309- unsigned long *end)
27310+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27311+ unsigned long *begin, unsigned long *end)
27312 {
27313 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27314 unsigned long new_begin;
27315@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27316 *begin = new_begin;
27317 }
27318 } else {
27319- *begin = current->mm->mmap_legacy_base;
27320+ *begin = mm->mmap_legacy_base;
27321 *end = TASK_SIZE;
27322 }
27323 }
27324@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27325 struct vm_area_struct *vma;
27326 struct vm_unmapped_area_info info;
27327 unsigned long begin, end;
27328+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27329
27330 if (flags & MAP_FIXED)
27331 return addr;
27332
27333- find_start_end(flags, &begin, &end);
27334+ find_start_end(mm, flags, &begin, &end);
27335
27336 if (len > end)
27337 return -ENOMEM;
27338
27339+#ifdef CONFIG_PAX_RANDMMAP
27340+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27341+#endif
27342+
27343 if (addr) {
27344 addr = PAGE_ALIGN(addr);
27345 vma = find_vma(mm, addr);
27346- if (end - len >= addr &&
27347- (!vma || addr + len <= vma->vm_start))
27348+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27349 return addr;
27350 }
27351
27352@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27353 info.high_limit = end;
27354 info.align_mask = filp ? get_align_mask() : 0;
27355 info.align_offset = pgoff << PAGE_SHIFT;
27356+ info.threadstack_offset = offset;
27357 return vm_unmapped_area(&info);
27358 }
27359
27360@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27361 struct mm_struct *mm = current->mm;
27362 unsigned long addr = addr0;
27363 struct vm_unmapped_area_info info;
27364+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27365
27366 /* requested length too big for entire address space */
27367 if (len > TASK_SIZE)
27368@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27369 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27370 goto bottomup;
27371
27372+#ifdef CONFIG_PAX_RANDMMAP
27373+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27374+#endif
27375+
27376 /* requesting a specific address */
27377 if (addr) {
27378 addr = PAGE_ALIGN(addr);
27379 vma = find_vma(mm, addr);
27380- if (TASK_SIZE - len >= addr &&
27381- (!vma || addr + len <= vma->vm_start))
27382+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27383 return addr;
27384 }
27385
27386@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27387 info.high_limit = mm->mmap_base;
27388 info.align_mask = filp ? get_align_mask() : 0;
27389 info.align_offset = pgoff << PAGE_SHIFT;
27390+ info.threadstack_offset = offset;
27391 addr = vm_unmapped_area(&info);
27392 if (!(addr & ~PAGE_MASK))
27393 return addr;
27394diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27395index 91a4496..bb87552 100644
27396--- a/arch/x86/kernel/tboot.c
27397+++ b/arch/x86/kernel/tboot.c
27398@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27399
27400 void tboot_shutdown(u32 shutdown_type)
27401 {
27402- void (*shutdown)(void);
27403+ void (* __noreturn shutdown)(void);
27404
27405 if (!tboot_enabled())
27406 return;
27407@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27408
27409 switch_to_tboot_pt();
27410
27411- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27412+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27413 shutdown();
27414
27415 /* should not reach here */
27416@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27417 return -ENODEV;
27418 }
27419
27420-static atomic_t ap_wfs_count;
27421+static atomic_unchecked_t ap_wfs_count;
27422
27423 static int tboot_wait_for_aps(int num_aps)
27424 {
27425@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27426 {
27427 switch (action) {
27428 case CPU_DYING:
27429- atomic_inc(&ap_wfs_count);
27430+ atomic_inc_unchecked(&ap_wfs_count);
27431 if (num_online_cpus() == 1)
27432- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27433+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27434 return NOTIFY_BAD;
27435 break;
27436 }
27437@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27438
27439 tboot_create_trampoline();
27440
27441- atomic_set(&ap_wfs_count, 0);
27442+ atomic_set_unchecked(&ap_wfs_count, 0);
27443 register_hotcpu_notifier(&tboot_cpu_notifier);
27444
27445 #ifdef CONFIG_DEBUG_FS
27446diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27447index bf7ef5c..59d0ac9 100644
27448--- a/arch/x86/kernel/time.c
27449+++ b/arch/x86/kernel/time.c
27450@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27451 {
27452 unsigned long pc = instruction_pointer(regs);
27453
27454- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27455+ if (!user_mode(regs) && in_lock_functions(pc)) {
27456 #ifdef CONFIG_FRAME_POINTER
27457- return *(unsigned long *)(regs->bp + sizeof(long));
27458+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27459 #else
27460 unsigned long *sp =
27461 (unsigned long *)kernel_stack_pointer(regs);
27462@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27463 * or above a saved flags. Eflags has bits 22-31 zero,
27464 * kernel addresses don't.
27465 */
27466+
27467+#ifdef CONFIG_PAX_KERNEXEC
27468+ return ktla_ktva(sp[0]);
27469+#else
27470 if (sp[0] >> 22)
27471 return sp[0];
27472 if (sp[1] >> 22)
27473 return sp[1];
27474 #endif
27475+
27476+#endif
27477 }
27478 return pc;
27479 }
27480diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27481index f7fec09..9991981 100644
27482--- a/arch/x86/kernel/tls.c
27483+++ b/arch/x86/kernel/tls.c
27484@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27485 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27486 return -EINVAL;
27487
27488+#ifdef CONFIG_PAX_SEGMEXEC
27489+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27490+ return -EINVAL;
27491+#endif
27492+
27493 set_tls_desc(p, idx, &info, 1);
27494
27495 return 0;
27496@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27497
27498 if (kbuf)
27499 info = kbuf;
27500- else if (__copy_from_user(infobuf, ubuf, count))
27501+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27502 return -EFAULT;
27503 else
27504 info = infobuf;
27505diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27506index 1c113db..287b42e 100644
27507--- a/arch/x86/kernel/tracepoint.c
27508+++ b/arch/x86/kernel/tracepoint.c
27509@@ -9,11 +9,11 @@
27510 #include <linux/atomic.h>
27511
27512 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27513-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27514+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27515 (unsigned long) trace_idt_table };
27516
27517 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27518-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27519+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27520
27521 static int trace_irq_vector_refcount;
27522 static DEFINE_MUTEX(irq_vector_mutex);
27523diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27524index f73b5d4..0adcc9a 100644
27525--- a/arch/x86/kernel/traps.c
27526+++ b/arch/x86/kernel/traps.c
27527@@ -66,7 +66,7 @@
27528 #include <asm/proto.h>
27529
27530 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27531-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27532+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27533 #else
27534 #include <asm/processor-flags.h>
27535 #include <asm/setup.h>
27536@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27537 #endif
27538
27539 /* Must be page-aligned because the real IDT is used in a fixmap. */
27540-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27541+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27542
27543 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27544 EXPORT_SYMBOL_GPL(used_vectors);
27545@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27546 }
27547
27548 static int __kprobes
27549-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27550+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27551 struct pt_regs *regs, long error_code)
27552 {
27553 #ifdef CONFIG_X86_32
27554- if (regs->flags & X86_VM_MASK) {
27555+ if (v8086_mode(regs)) {
27556 /*
27557 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27558 * On nmi (interrupt 2), do_trap should not be called.
27559@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27560 return -1;
27561 }
27562 #endif
27563- if (!user_mode(regs)) {
27564+ if (!user_mode_novm(regs)) {
27565 if (!fixup_exception(regs)) {
27566 tsk->thread.error_code = error_code;
27567 tsk->thread.trap_nr = trapnr;
27568+
27569+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27570+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27571+ str = "PAX: suspicious stack segment fault";
27572+#endif
27573+
27574 die(str, regs, error_code);
27575 }
27576+
27577+#ifdef CONFIG_PAX_REFCOUNT
27578+ if (trapnr == X86_TRAP_OF)
27579+ pax_report_refcount_overflow(regs);
27580+#endif
27581+
27582 return 0;
27583 }
27584
27585@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27586 }
27587
27588 static void __kprobes
27589-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27590+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27591 long error_code, siginfo_t *info)
27592 {
27593 struct task_struct *tsk = current;
27594@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27595 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27596 printk_ratelimit()) {
27597 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27598- tsk->comm, tsk->pid, str,
27599+ tsk->comm, task_pid_nr(tsk), str,
27600 regs->ip, regs->sp, error_code);
27601 print_vma_addr(" in ", regs->ip);
27602 pr_cont("\n");
27603@@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27604 tsk->thread.error_code = error_code;
27605 tsk->thread.trap_nr = X86_TRAP_DF;
27606
27607+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27608+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27609+ die("grsec: kernel stack overflow detected", regs, error_code);
27610+#endif
27611+
27612 #ifdef CONFIG_DOUBLEFAULT
27613 df_debug(regs, error_code);
27614 #endif
27615@@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27616 conditional_sti(regs);
27617
27618 #ifdef CONFIG_X86_32
27619- if (regs->flags & X86_VM_MASK) {
27620+ if (v8086_mode(regs)) {
27621 local_irq_enable();
27622 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27623 goto exit;
27624@@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27625 #endif
27626
27627 tsk = current;
27628- if (!user_mode(regs)) {
27629+ if (!user_mode_novm(regs)) {
27630 if (fixup_exception(regs))
27631 goto exit;
27632
27633 tsk->thread.error_code = error_code;
27634 tsk->thread.trap_nr = X86_TRAP_GP;
27635 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27636- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27637+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27638+
27639+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27640+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27641+ die("PAX: suspicious general protection fault", regs, error_code);
27642+ else
27643+#endif
27644+
27645 die("general protection fault", regs, error_code);
27646+ }
27647 goto exit;
27648 }
27649
27650+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27651+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27652+ struct mm_struct *mm = tsk->mm;
27653+ unsigned long limit;
27654+
27655+ down_write(&mm->mmap_sem);
27656+ limit = mm->context.user_cs_limit;
27657+ if (limit < TASK_SIZE) {
27658+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27659+ up_write(&mm->mmap_sem);
27660+ return;
27661+ }
27662+ up_write(&mm->mmap_sem);
27663+ }
27664+#endif
27665+
27666 tsk->thread.error_code = error_code;
27667 tsk->thread.trap_nr = X86_TRAP_GP;
27668
27669@@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27670 /* It's safe to allow irq's after DR6 has been saved */
27671 preempt_conditional_sti(regs);
27672
27673- if (regs->flags & X86_VM_MASK) {
27674+ if (v8086_mode(regs)) {
27675 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27676 X86_TRAP_DB);
27677 preempt_conditional_cli(regs);
27678@@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27679 * We already checked v86 mode above, so we can check for kernel mode
27680 * by just checking the CPL of CS.
27681 */
27682- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27683+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27684 tsk->thread.debugreg6 &= ~DR_STEP;
27685 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27686 regs->flags &= ~X86_EFLAGS_TF;
27687@@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27688 return;
27689 conditional_sti(regs);
27690
27691- if (!user_mode_vm(regs))
27692+ if (!user_mode(regs))
27693 {
27694 if (!fixup_exception(regs)) {
27695 task->thread.error_code = error_code;
27696diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27697index 57e5ce1..20b0040 100644
27698--- a/arch/x86/kernel/tsc.c
27699+++ b/arch/x86/kernel/tsc.c
27700@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27701 */
27702 smp_wmb();
27703
27704- ACCESS_ONCE(c2n->head) = data;
27705+ ACCESS_ONCE_RW(c2n->head) = data;
27706 }
27707
27708 /*
27709diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27710index 2ed8459..7cf329f 100644
27711--- a/arch/x86/kernel/uprobes.c
27712+++ b/arch/x86/kernel/uprobes.c
27713@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27714 int ret = NOTIFY_DONE;
27715
27716 /* We are only interested in userspace traps */
27717- if (regs && !user_mode_vm(regs))
27718+ if (regs && !user_mode(regs))
27719 return NOTIFY_DONE;
27720
27721 switch (val) {
27722@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27723
27724 if (ncopied != rasize) {
27725 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27726- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27727+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27728
27729 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27730 }
27731diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27732index b9242ba..50c5edd 100644
27733--- a/arch/x86/kernel/verify_cpu.S
27734+++ b/arch/x86/kernel/verify_cpu.S
27735@@ -20,6 +20,7 @@
27736 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27737 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27738 * arch/x86/kernel/head_32.S: processor startup
27739+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27740 *
27741 * verify_cpu, returns the status of longmode and SSE in register %eax.
27742 * 0: Success 1: Failure
27743diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27744index e8edcf5..27f9344 100644
27745--- a/arch/x86/kernel/vm86_32.c
27746+++ b/arch/x86/kernel/vm86_32.c
27747@@ -44,6 +44,7 @@
27748 #include <linux/ptrace.h>
27749 #include <linux/audit.h>
27750 #include <linux/stddef.h>
27751+#include <linux/grsecurity.h>
27752
27753 #include <asm/uaccess.h>
27754 #include <asm/io.h>
27755@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27756 do_exit(SIGSEGV);
27757 }
27758
27759- tss = &per_cpu(init_tss, get_cpu());
27760+ tss = init_tss + get_cpu();
27761 current->thread.sp0 = current->thread.saved_sp0;
27762 current->thread.sysenter_cs = __KERNEL_CS;
27763 load_sp0(tss, &current->thread);
27764@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27765
27766 if (tsk->thread.saved_sp0)
27767 return -EPERM;
27768+
27769+#ifdef CONFIG_GRKERNSEC_VM86
27770+ if (!capable(CAP_SYS_RAWIO)) {
27771+ gr_handle_vm86();
27772+ return -EPERM;
27773+ }
27774+#endif
27775+
27776 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27777 offsetof(struct kernel_vm86_struct, vm86plus) -
27778 sizeof(info.regs));
27779@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27780 int tmp;
27781 struct vm86plus_struct __user *v86;
27782
27783+#ifdef CONFIG_GRKERNSEC_VM86
27784+ if (!capable(CAP_SYS_RAWIO)) {
27785+ gr_handle_vm86();
27786+ return -EPERM;
27787+ }
27788+#endif
27789+
27790 tsk = current;
27791 switch (cmd) {
27792 case VM86_REQUEST_IRQ:
27793@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27794 tsk->thread.saved_fs = info->regs32->fs;
27795 tsk->thread.saved_gs = get_user_gs(info->regs32);
27796
27797- tss = &per_cpu(init_tss, get_cpu());
27798+ tss = init_tss + get_cpu();
27799 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27800 if (cpu_has_sep)
27801 tsk->thread.sysenter_cs = 0;
27802@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27803 goto cannot_handle;
27804 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27805 goto cannot_handle;
27806- intr_ptr = (unsigned long __user *) (i << 2);
27807+ intr_ptr = (__force unsigned long __user *) (i << 2);
27808 if (get_user(segoffs, intr_ptr))
27809 goto cannot_handle;
27810 if ((segoffs >> 16) == BIOSSEG)
27811diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27812index 49edf2d..c0d1362 100644
27813--- a/arch/x86/kernel/vmlinux.lds.S
27814+++ b/arch/x86/kernel/vmlinux.lds.S
27815@@ -26,6 +26,13 @@
27816 #include <asm/page_types.h>
27817 #include <asm/cache.h>
27818 #include <asm/boot.h>
27819+#include <asm/segment.h>
27820+
27821+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27822+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27823+#else
27824+#define __KERNEL_TEXT_OFFSET 0
27825+#endif
27826
27827 #undef i386 /* in case the preprocessor is a 32bit one */
27828
27829@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27830
27831 PHDRS {
27832 text PT_LOAD FLAGS(5); /* R_E */
27833+#ifdef CONFIG_X86_32
27834+ module PT_LOAD FLAGS(5); /* R_E */
27835+#endif
27836+#ifdef CONFIG_XEN
27837+ rodata PT_LOAD FLAGS(5); /* R_E */
27838+#else
27839+ rodata PT_LOAD FLAGS(4); /* R__ */
27840+#endif
27841 data PT_LOAD FLAGS(6); /* RW_ */
27842-#ifdef CONFIG_X86_64
27843+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27844 #ifdef CONFIG_SMP
27845 percpu PT_LOAD FLAGS(6); /* RW_ */
27846 #endif
27847+ text.init PT_LOAD FLAGS(5); /* R_E */
27848+ text.exit PT_LOAD FLAGS(5); /* R_E */
27849 init PT_LOAD FLAGS(7); /* RWE */
27850-#endif
27851 note PT_NOTE FLAGS(0); /* ___ */
27852 }
27853
27854 SECTIONS
27855 {
27856 #ifdef CONFIG_X86_32
27857- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27858- phys_startup_32 = startup_32 - LOAD_OFFSET;
27859+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27860 #else
27861- . = __START_KERNEL;
27862- phys_startup_64 = startup_64 - LOAD_OFFSET;
27863+ . = __START_KERNEL;
27864 #endif
27865
27866 /* Text and read-only data */
27867- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27868- _text = .;
27869+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27870 /* bootstrapping code */
27871+#ifdef CONFIG_X86_32
27872+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27873+#else
27874+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27875+#endif
27876+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27877+ _text = .;
27878 HEAD_TEXT
27879 . = ALIGN(8);
27880 _stext = .;
27881@@ -104,13 +124,47 @@ SECTIONS
27882 IRQENTRY_TEXT
27883 *(.fixup)
27884 *(.gnu.warning)
27885- /* End of text section */
27886- _etext = .;
27887 } :text = 0x9090
27888
27889- NOTES :text :note
27890+ . += __KERNEL_TEXT_OFFSET;
27891
27892- EXCEPTION_TABLE(16) :text = 0x9090
27893+#ifdef CONFIG_X86_32
27894+ . = ALIGN(PAGE_SIZE);
27895+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27896+
27897+#ifdef CONFIG_PAX_KERNEXEC
27898+ MODULES_EXEC_VADDR = .;
27899+ BYTE(0)
27900+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27901+ . = ALIGN(HPAGE_SIZE) - 1;
27902+ MODULES_EXEC_END = .;
27903+#endif
27904+
27905+ } :module
27906+#endif
27907+
27908+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27909+ /* End of text section */
27910+ BYTE(0)
27911+ _etext = . - __KERNEL_TEXT_OFFSET;
27912+ }
27913+
27914+#ifdef CONFIG_X86_32
27915+ . = ALIGN(PAGE_SIZE);
27916+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27917+ . = ALIGN(PAGE_SIZE);
27918+ *(.empty_zero_page)
27919+ *(.initial_pg_fixmap)
27920+ *(.initial_pg_pmd)
27921+ *(.initial_page_table)
27922+ *(.swapper_pg_dir)
27923+ } :rodata
27924+#endif
27925+
27926+ . = ALIGN(PAGE_SIZE);
27927+ NOTES :rodata :note
27928+
27929+ EXCEPTION_TABLE(16) :rodata
27930
27931 #if defined(CONFIG_DEBUG_RODATA)
27932 /* .text should occupy whole number of pages */
27933@@ -122,16 +176,20 @@ SECTIONS
27934
27935 /* Data */
27936 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27937+
27938+#ifdef CONFIG_PAX_KERNEXEC
27939+ . = ALIGN(HPAGE_SIZE);
27940+#else
27941+ . = ALIGN(PAGE_SIZE);
27942+#endif
27943+
27944 /* Start of data section */
27945 _sdata = .;
27946
27947 /* init_task */
27948 INIT_TASK_DATA(THREAD_SIZE)
27949
27950-#ifdef CONFIG_X86_32
27951- /* 32 bit has nosave before _edata */
27952 NOSAVE_DATA
27953-#endif
27954
27955 PAGE_ALIGNED_DATA(PAGE_SIZE)
27956
27957@@ -174,12 +232,19 @@ SECTIONS
27958 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
27959
27960 /* Init code and data - will be freed after init */
27961- . = ALIGN(PAGE_SIZE);
27962 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27963+ BYTE(0)
27964+
27965+#ifdef CONFIG_PAX_KERNEXEC
27966+ . = ALIGN(HPAGE_SIZE);
27967+#else
27968+ . = ALIGN(PAGE_SIZE);
27969+#endif
27970+
27971 __init_begin = .; /* paired with __init_end */
27972- }
27973+ } :init.begin
27974
27975-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27976+#ifdef CONFIG_SMP
27977 /*
27978 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27979 * output PHDR, so the next output section - .init.text - should
27980@@ -188,12 +253,27 @@ SECTIONS
27981 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27982 #endif
27983
27984- INIT_TEXT_SECTION(PAGE_SIZE)
27985-#ifdef CONFIG_X86_64
27986- :init
27987-#endif
27988+ . = ALIGN(PAGE_SIZE);
27989+ init_begin = .;
27990+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27991+ VMLINUX_SYMBOL(_sinittext) = .;
27992+ INIT_TEXT
27993+ VMLINUX_SYMBOL(_einittext) = .;
27994+ . = ALIGN(PAGE_SIZE);
27995+ } :text.init
27996
27997- INIT_DATA_SECTION(16)
27998+ /*
27999+ * .exit.text is discard at runtime, not link time, to deal with
28000+ * references from .altinstructions and .eh_frame
28001+ */
28002+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28003+ EXIT_TEXT
28004+ . = ALIGN(16);
28005+ } :text.exit
28006+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28007+
28008+ . = ALIGN(PAGE_SIZE);
28009+ INIT_DATA_SECTION(16) :init
28010
28011 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28012 __x86_cpu_dev_start = .;
28013@@ -264,19 +344,12 @@ SECTIONS
28014 }
28015
28016 . = ALIGN(8);
28017- /*
28018- * .exit.text is discard at runtime, not link time, to deal with
28019- * references from .altinstructions and .eh_frame
28020- */
28021- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28022- EXIT_TEXT
28023- }
28024
28025 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28026 EXIT_DATA
28027 }
28028
28029-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28030+#ifndef CONFIG_SMP
28031 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28032 #endif
28033
28034@@ -295,16 +368,10 @@ SECTIONS
28035 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28036 __smp_locks = .;
28037 *(.smp_locks)
28038- . = ALIGN(PAGE_SIZE);
28039 __smp_locks_end = .;
28040+ . = ALIGN(PAGE_SIZE);
28041 }
28042
28043-#ifdef CONFIG_X86_64
28044- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28045- NOSAVE_DATA
28046- }
28047-#endif
28048-
28049 /* BSS */
28050 . = ALIGN(PAGE_SIZE);
28051 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28052@@ -320,6 +387,7 @@ SECTIONS
28053 __brk_base = .;
28054 . += 64 * 1024; /* 64k alignment slop space */
28055 *(.brk_reservation) /* areas brk users have reserved */
28056+ . = ALIGN(HPAGE_SIZE);
28057 __brk_limit = .;
28058 }
28059
28060@@ -346,13 +414,12 @@ SECTIONS
28061 * for the boot processor.
28062 */
28063 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28064-INIT_PER_CPU(gdt_page);
28065 INIT_PER_CPU(irq_stack_union);
28066
28067 /*
28068 * Build-time check on the image size:
28069 */
28070-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28071+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28072 "kernel image bigger than KERNEL_IMAGE_SIZE");
28073
28074 #ifdef CONFIG_SMP
28075diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28076index 8b3b3eb..9395aa9 100644
28077--- a/arch/x86/kernel/vsyscall_64.c
28078+++ b/arch/x86/kernel/vsyscall_64.c
28079@@ -54,15 +54,13 @@
28080
28081 DEFINE_VVAR(int, vgetcpu_mode);
28082
28083-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28084+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28085
28086 static int __init vsyscall_setup(char *str)
28087 {
28088 if (str) {
28089 if (!strcmp("emulate", str))
28090 vsyscall_mode = EMULATE;
28091- else if (!strcmp("native", str))
28092- vsyscall_mode = NATIVE;
28093 else if (!strcmp("none", str))
28094 vsyscall_mode = NONE;
28095 else
28096@@ -279,8 +277,7 @@ do_ret:
28097 return true;
28098
28099 sigsegv:
28100- force_sig(SIGSEGV, current);
28101- return true;
28102+ do_group_exit(SIGKILL);
28103 }
28104
28105 /*
28106@@ -332,10 +329,7 @@ void __init map_vsyscall(void)
28107 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28108 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28109
28110- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28111- vsyscall_mode == NATIVE
28112- ? PAGE_KERNEL_VSYSCALL
28113- : PAGE_KERNEL_VVAR);
28114+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28115 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28116 (unsigned long)VSYSCALL_START);
28117
28118diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28119index 04068192..4d75aa6 100644
28120--- a/arch/x86/kernel/x8664_ksyms_64.c
28121+++ b/arch/x86/kernel/x8664_ksyms_64.c
28122@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28123 EXPORT_SYMBOL(copy_user_generic_unrolled);
28124 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28125 EXPORT_SYMBOL(__copy_user_nocache);
28126-EXPORT_SYMBOL(_copy_from_user);
28127-EXPORT_SYMBOL(_copy_to_user);
28128
28129 EXPORT_SYMBOL(copy_page);
28130 EXPORT_SYMBOL(clear_page);
28131@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28132 EXPORT_SYMBOL(___preempt_schedule_context);
28133 #endif
28134 #endif
28135+
28136+#ifdef CONFIG_PAX_PER_CPU_PGD
28137+EXPORT_SYMBOL(cpu_pgd);
28138+#endif
28139diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28140index e48b674..a451dd9 100644
28141--- a/arch/x86/kernel/x86_init.c
28142+++ b/arch/x86/kernel/x86_init.c
28143@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28144 static void default_nmi_init(void) { };
28145 static int default_i8042_detect(void) { return 1; };
28146
28147-struct x86_platform_ops x86_platform = {
28148+struct x86_platform_ops x86_platform __read_only = {
28149 .calibrate_tsc = native_calibrate_tsc,
28150 .get_wallclock = mach_get_cmos_time,
28151 .set_wallclock = mach_set_rtc_mmss,
28152@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28153 EXPORT_SYMBOL_GPL(x86_platform);
28154
28155 #if defined(CONFIG_PCI_MSI)
28156-struct x86_msi_ops x86_msi = {
28157+struct x86_msi_ops x86_msi __read_only = {
28158 .setup_msi_irqs = native_setup_msi_irqs,
28159 .compose_msi_msg = native_compose_msi_msg,
28160 .teardown_msi_irq = native_teardown_msi_irq,
28161@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28162 }
28163 #endif
28164
28165-struct x86_io_apic_ops x86_io_apic_ops = {
28166+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28167 .init = native_io_apic_init_mappings,
28168 .read = native_io_apic_read,
28169 .write = native_io_apic_write,
28170diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28171index a4b451c..8dfe1ad 100644
28172--- a/arch/x86/kernel/xsave.c
28173+++ b/arch/x86/kernel/xsave.c
28174@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28175
28176 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28177 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28178- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28179+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28180
28181 if (!use_xsave())
28182 return err;
28183
28184- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28185+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28186
28187 /*
28188 * Read the xstate_bv which we copied (directly from the cpu or
28189 * from the state in task struct) to the user buffers.
28190 */
28191- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28192+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28193
28194 /*
28195 * For legacy compatible, we always set FP/SSE bits in the bit
28196@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28197 */
28198 xstate_bv |= XSTATE_FPSSE;
28199
28200- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28201+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28202
28203 return err;
28204 }
28205@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28206 {
28207 int err;
28208
28209+ buf = (struct xsave_struct __user *)____m(buf);
28210 if (use_xsave())
28211 err = xsave_user(buf);
28212 else if (use_fxsr())
28213@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28214 */
28215 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28216 {
28217+ buf = (void __user *)____m(buf);
28218 if (use_xsave()) {
28219 if ((unsigned long)buf % 64 || fx_only) {
28220 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28221diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28222index f47a104..5ce59a8 100644
28223--- a/arch/x86/kvm/cpuid.c
28224+++ b/arch/x86/kvm/cpuid.c
28225@@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28226 struct kvm_cpuid2 *cpuid,
28227 struct kvm_cpuid_entry2 __user *entries)
28228 {
28229- int r;
28230+ int r, i;
28231
28232 r = -E2BIG;
28233 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28234 goto out;
28235 r = -EFAULT;
28236- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28237- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28238+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28239 goto out;
28240+ for (i = 0; i < cpuid->nent; ++i) {
28241+ struct kvm_cpuid_entry2 cpuid_entry;
28242+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28243+ goto out;
28244+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28245+ }
28246 vcpu->arch.cpuid_nent = cpuid->nent;
28247 kvm_apic_set_version(vcpu);
28248 kvm_x86_ops->cpuid_update(vcpu);
28249@@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28250 struct kvm_cpuid2 *cpuid,
28251 struct kvm_cpuid_entry2 __user *entries)
28252 {
28253- int r;
28254+ int r, i;
28255
28256 r = -E2BIG;
28257 if (cpuid->nent < vcpu->arch.cpuid_nent)
28258 goto out;
28259 r = -EFAULT;
28260- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28261- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28262+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28263 goto out;
28264+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28265+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28266+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28267+ goto out;
28268+ }
28269 return 0;
28270
28271 out:
28272diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28273index 0069118..c28ec0a 100644
28274--- a/arch/x86/kvm/lapic.c
28275+++ b/arch/x86/kvm/lapic.c
28276@@ -55,7 +55,7 @@
28277 #define APIC_BUS_CYCLE_NS 1
28278
28279 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28280-#define apic_debug(fmt, arg...)
28281+#define apic_debug(fmt, arg...) do {} while (0)
28282
28283 #define APIC_LVT_NUM 6
28284 /* 14 is the version for Xeon and Pentium 8.4.8*/
28285diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28286index 123efd3..ad7726e 100644
28287--- a/arch/x86/kvm/paging_tmpl.h
28288+++ b/arch/x86/kvm/paging_tmpl.h
28289@@ -331,7 +331,7 @@ retry_walk:
28290 if (unlikely(kvm_is_error_hva(host_addr)))
28291 goto error;
28292
28293- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28294+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28295 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28296 goto error;
28297 walker->ptep_user[walker->level - 1] = ptep_user;
28298diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28299index 7f4f9c2..67b1db0 100644
28300--- a/arch/x86/kvm/svm.c
28301+++ b/arch/x86/kvm/svm.c
28302@@ -3535,7 +3535,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28303 int cpu = raw_smp_processor_id();
28304
28305 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28306+
28307+ pax_open_kernel();
28308 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28309+ pax_close_kernel();
28310+
28311 load_TR_desc();
28312 }
28313
28314@@ -3936,6 +3940,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28315 #endif
28316 #endif
28317
28318+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28319+ __set_fs(current_thread_info()->addr_limit);
28320+#endif
28321+
28322 reload_tss(vcpu);
28323
28324 local_irq_disable();
28325diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28326index 138ceff..2e584f0 100644
28327--- a/arch/x86/kvm/vmx.c
28328+++ b/arch/x86/kvm/vmx.c
28329@@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28330 #endif
28331 }
28332
28333-static void vmcs_clear_bits(unsigned long field, u32 mask)
28334+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28335 {
28336 vmcs_writel(field, vmcs_readl(field) & ~mask);
28337 }
28338
28339-static void vmcs_set_bits(unsigned long field, u32 mask)
28340+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28341 {
28342 vmcs_writel(field, vmcs_readl(field) | mask);
28343 }
28344@@ -1604,7 +1604,11 @@ static void reload_tss(void)
28345 struct desc_struct *descs;
28346
28347 descs = (void *)gdt->address;
28348+
28349+ pax_open_kernel();
28350 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28351+ pax_close_kernel();
28352+
28353 load_TR_desc();
28354 }
28355
28356@@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28357 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28358 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28359
28360+#ifdef CONFIG_PAX_PER_CPU_PGD
28361+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28362+#endif
28363+
28364 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28365 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28366 vmx->loaded_vmcs->cpu = cpu;
28367@@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28368 * reads and returns guest's timestamp counter "register"
28369 * guest_tsc = host_tsc + tsc_offset -- 21.3
28370 */
28371-static u64 guest_read_tsc(void)
28372+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28373 {
28374 u64 host_tsc, tsc_offset;
28375
28376@@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28377 if (!cpu_has_vmx_flexpriority())
28378 flexpriority_enabled = 0;
28379
28380- if (!cpu_has_vmx_tpr_shadow())
28381- kvm_x86_ops->update_cr8_intercept = NULL;
28382+ if (!cpu_has_vmx_tpr_shadow()) {
28383+ pax_open_kernel();
28384+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28385+ pax_close_kernel();
28386+ }
28387
28388 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28389 kvm_disable_largepages();
28390@@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28391 if (!cpu_has_vmx_apicv())
28392 enable_apicv = 0;
28393
28394+ pax_open_kernel();
28395 if (enable_apicv)
28396- kvm_x86_ops->update_cr8_intercept = NULL;
28397+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28398 else {
28399- kvm_x86_ops->hwapic_irr_update = NULL;
28400- kvm_x86_ops->deliver_posted_interrupt = NULL;
28401- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28402+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28403+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28404+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28405 }
28406+ pax_close_kernel();
28407
28408 if (nested)
28409 nested_vmx_setup_ctls_msrs();
28410@@ -4235,7 +4248,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28411
28412 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28413 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28414+
28415+#ifndef CONFIG_PAX_PER_CPU_PGD
28416 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28417+#endif
28418
28419 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28420 #ifdef CONFIG_X86_64
28421@@ -4257,7 +4273,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28422 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28423 vmx->host_idt_base = dt.address;
28424
28425- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28426+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28427
28428 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28429 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28430@@ -7333,6 +7349,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28431 "jmp 2f \n\t"
28432 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28433 "2: "
28434+
28435+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28436+ "ljmp %[cs],$3f\n\t"
28437+ "3: "
28438+#endif
28439+
28440 /* Save guest registers, load host registers, keep flags */
28441 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28442 "pop %0 \n\t"
28443@@ -7385,6 +7407,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28444 #endif
28445 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28446 [wordsize]"i"(sizeof(ulong))
28447+
28448+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28449+ ,[cs]"i"(__KERNEL_CS)
28450+#endif
28451+
28452 : "cc", "memory"
28453 #ifdef CONFIG_X86_64
28454 , "rax", "rbx", "rdi", "rsi"
28455@@ -7398,7 +7425,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28456 if (debugctlmsr)
28457 update_debugctlmsr(debugctlmsr);
28458
28459-#ifndef CONFIG_X86_64
28460+#ifdef CONFIG_X86_32
28461 /*
28462 * The sysexit path does not restore ds/es, so we must set them to
28463 * a reasonable value ourselves.
28464@@ -7407,8 +7434,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28465 * may be executed in interrupt context, which saves and restore segments
28466 * around it, nullifying its effect.
28467 */
28468- loadsegment(ds, __USER_DS);
28469- loadsegment(es, __USER_DS);
28470+ loadsegment(ds, __KERNEL_DS);
28471+ loadsegment(es, __KERNEL_DS);
28472+ loadsegment(ss, __KERNEL_DS);
28473+
28474+#ifdef CONFIG_PAX_KERNEXEC
28475+ loadsegment(fs, __KERNEL_PERCPU);
28476+#endif
28477+
28478+#ifdef CONFIG_PAX_MEMORY_UDEREF
28479+ __set_fs(current_thread_info()->addr_limit);
28480+#endif
28481+
28482 #endif
28483
28484 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28485diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28486index 20316c6..9b3dddc 100644
28487--- a/arch/x86/kvm/x86.c
28488+++ b/arch/x86/kvm/x86.c
28489@@ -1822,8 +1822,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28490 {
28491 struct kvm *kvm = vcpu->kvm;
28492 int lm = is_long_mode(vcpu);
28493- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28494- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28495+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28496+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28497 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28498 : kvm->arch.xen_hvm_config.blob_size_32;
28499 u32 page_num = data & ~PAGE_MASK;
28500@@ -2738,6 +2738,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28501 if (n < msr_list.nmsrs)
28502 goto out;
28503 r = -EFAULT;
28504+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28505+ goto out;
28506 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28507 num_msrs_to_save * sizeof(u32)))
28508 goto out;
28509@@ -5574,7 +5576,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28510 };
28511 #endif
28512
28513-int kvm_arch_init(void *opaque)
28514+int kvm_arch_init(const void *opaque)
28515 {
28516 int r;
28517 struct kvm_x86_ops *ops = opaque;
28518diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28519index aae9413..d11e829 100644
28520--- a/arch/x86/lguest/boot.c
28521+++ b/arch/x86/lguest/boot.c
28522@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28523 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28524 * Launcher to reboot us.
28525 */
28526-static void lguest_restart(char *reason)
28527+static __noreturn void lguest_restart(char *reason)
28528 {
28529 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28530+ BUG();
28531 }
28532
28533 /*G:050
28534diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28535index 00933d5..3a64af9 100644
28536--- a/arch/x86/lib/atomic64_386_32.S
28537+++ b/arch/x86/lib/atomic64_386_32.S
28538@@ -48,6 +48,10 @@ BEGIN(read)
28539 movl (v), %eax
28540 movl 4(v), %edx
28541 RET_ENDP
28542+BEGIN(read_unchecked)
28543+ movl (v), %eax
28544+ movl 4(v), %edx
28545+RET_ENDP
28546 #undef v
28547
28548 #define v %esi
28549@@ -55,6 +59,10 @@ BEGIN(set)
28550 movl %ebx, (v)
28551 movl %ecx, 4(v)
28552 RET_ENDP
28553+BEGIN(set_unchecked)
28554+ movl %ebx, (v)
28555+ movl %ecx, 4(v)
28556+RET_ENDP
28557 #undef v
28558
28559 #define v %esi
28560@@ -70,6 +78,20 @@ RET_ENDP
28561 BEGIN(add)
28562 addl %eax, (v)
28563 adcl %edx, 4(v)
28564+
28565+#ifdef CONFIG_PAX_REFCOUNT
28566+ jno 0f
28567+ subl %eax, (v)
28568+ sbbl %edx, 4(v)
28569+ int $4
28570+0:
28571+ _ASM_EXTABLE(0b, 0b)
28572+#endif
28573+
28574+RET_ENDP
28575+BEGIN(add_unchecked)
28576+ addl %eax, (v)
28577+ adcl %edx, 4(v)
28578 RET_ENDP
28579 #undef v
28580
28581@@ -77,6 +99,24 @@ RET_ENDP
28582 BEGIN(add_return)
28583 addl (v), %eax
28584 adcl 4(v), %edx
28585+
28586+#ifdef CONFIG_PAX_REFCOUNT
28587+ into
28588+1234:
28589+ _ASM_EXTABLE(1234b, 2f)
28590+#endif
28591+
28592+ movl %eax, (v)
28593+ movl %edx, 4(v)
28594+
28595+#ifdef CONFIG_PAX_REFCOUNT
28596+2:
28597+#endif
28598+
28599+RET_ENDP
28600+BEGIN(add_return_unchecked)
28601+ addl (v), %eax
28602+ adcl 4(v), %edx
28603 movl %eax, (v)
28604 movl %edx, 4(v)
28605 RET_ENDP
28606@@ -86,6 +126,20 @@ RET_ENDP
28607 BEGIN(sub)
28608 subl %eax, (v)
28609 sbbl %edx, 4(v)
28610+
28611+#ifdef CONFIG_PAX_REFCOUNT
28612+ jno 0f
28613+ addl %eax, (v)
28614+ adcl %edx, 4(v)
28615+ int $4
28616+0:
28617+ _ASM_EXTABLE(0b, 0b)
28618+#endif
28619+
28620+RET_ENDP
28621+BEGIN(sub_unchecked)
28622+ subl %eax, (v)
28623+ sbbl %edx, 4(v)
28624 RET_ENDP
28625 #undef v
28626
28627@@ -96,6 +150,27 @@ BEGIN(sub_return)
28628 sbbl $0, %edx
28629 addl (v), %eax
28630 adcl 4(v), %edx
28631+
28632+#ifdef CONFIG_PAX_REFCOUNT
28633+ into
28634+1234:
28635+ _ASM_EXTABLE(1234b, 2f)
28636+#endif
28637+
28638+ movl %eax, (v)
28639+ movl %edx, 4(v)
28640+
28641+#ifdef CONFIG_PAX_REFCOUNT
28642+2:
28643+#endif
28644+
28645+RET_ENDP
28646+BEGIN(sub_return_unchecked)
28647+ negl %edx
28648+ negl %eax
28649+ sbbl $0, %edx
28650+ addl (v), %eax
28651+ adcl 4(v), %edx
28652 movl %eax, (v)
28653 movl %edx, 4(v)
28654 RET_ENDP
28655@@ -105,6 +180,20 @@ RET_ENDP
28656 BEGIN(inc)
28657 addl $1, (v)
28658 adcl $0, 4(v)
28659+
28660+#ifdef CONFIG_PAX_REFCOUNT
28661+ jno 0f
28662+ subl $1, (v)
28663+ sbbl $0, 4(v)
28664+ int $4
28665+0:
28666+ _ASM_EXTABLE(0b, 0b)
28667+#endif
28668+
28669+RET_ENDP
28670+BEGIN(inc_unchecked)
28671+ addl $1, (v)
28672+ adcl $0, 4(v)
28673 RET_ENDP
28674 #undef v
28675
28676@@ -114,6 +203,26 @@ BEGIN(inc_return)
28677 movl 4(v), %edx
28678 addl $1, %eax
28679 adcl $0, %edx
28680+
28681+#ifdef CONFIG_PAX_REFCOUNT
28682+ into
28683+1234:
28684+ _ASM_EXTABLE(1234b, 2f)
28685+#endif
28686+
28687+ movl %eax, (v)
28688+ movl %edx, 4(v)
28689+
28690+#ifdef CONFIG_PAX_REFCOUNT
28691+2:
28692+#endif
28693+
28694+RET_ENDP
28695+BEGIN(inc_return_unchecked)
28696+ movl (v), %eax
28697+ movl 4(v), %edx
28698+ addl $1, %eax
28699+ adcl $0, %edx
28700 movl %eax, (v)
28701 movl %edx, 4(v)
28702 RET_ENDP
28703@@ -123,6 +232,20 @@ RET_ENDP
28704 BEGIN(dec)
28705 subl $1, (v)
28706 sbbl $0, 4(v)
28707+
28708+#ifdef CONFIG_PAX_REFCOUNT
28709+ jno 0f
28710+ addl $1, (v)
28711+ adcl $0, 4(v)
28712+ int $4
28713+0:
28714+ _ASM_EXTABLE(0b, 0b)
28715+#endif
28716+
28717+RET_ENDP
28718+BEGIN(dec_unchecked)
28719+ subl $1, (v)
28720+ sbbl $0, 4(v)
28721 RET_ENDP
28722 #undef v
28723
28724@@ -132,6 +255,26 @@ BEGIN(dec_return)
28725 movl 4(v), %edx
28726 subl $1, %eax
28727 sbbl $0, %edx
28728+
28729+#ifdef CONFIG_PAX_REFCOUNT
28730+ into
28731+1234:
28732+ _ASM_EXTABLE(1234b, 2f)
28733+#endif
28734+
28735+ movl %eax, (v)
28736+ movl %edx, 4(v)
28737+
28738+#ifdef CONFIG_PAX_REFCOUNT
28739+2:
28740+#endif
28741+
28742+RET_ENDP
28743+BEGIN(dec_return_unchecked)
28744+ movl (v), %eax
28745+ movl 4(v), %edx
28746+ subl $1, %eax
28747+ sbbl $0, %edx
28748 movl %eax, (v)
28749 movl %edx, 4(v)
28750 RET_ENDP
28751@@ -143,6 +286,13 @@ BEGIN(add_unless)
28752 adcl %edx, %edi
28753 addl (v), %eax
28754 adcl 4(v), %edx
28755+
28756+#ifdef CONFIG_PAX_REFCOUNT
28757+ into
28758+1234:
28759+ _ASM_EXTABLE(1234b, 2f)
28760+#endif
28761+
28762 cmpl %eax, %ecx
28763 je 3f
28764 1:
28765@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28766 1:
28767 addl $1, %eax
28768 adcl $0, %edx
28769+
28770+#ifdef CONFIG_PAX_REFCOUNT
28771+ into
28772+1234:
28773+ _ASM_EXTABLE(1234b, 2f)
28774+#endif
28775+
28776 movl %eax, (v)
28777 movl %edx, 4(v)
28778 movl $1, %eax
28779@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28780 movl 4(v), %edx
28781 subl $1, %eax
28782 sbbl $0, %edx
28783+
28784+#ifdef CONFIG_PAX_REFCOUNT
28785+ into
28786+1234:
28787+ _ASM_EXTABLE(1234b, 1f)
28788+#endif
28789+
28790 js 1f
28791 movl %eax, (v)
28792 movl %edx, 4(v)
28793diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28794index f5cc9eb..51fa319 100644
28795--- a/arch/x86/lib/atomic64_cx8_32.S
28796+++ b/arch/x86/lib/atomic64_cx8_32.S
28797@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28798 CFI_STARTPROC
28799
28800 read64 %ecx
28801+ pax_force_retaddr
28802 ret
28803 CFI_ENDPROC
28804 ENDPROC(atomic64_read_cx8)
28805
28806+ENTRY(atomic64_read_unchecked_cx8)
28807+ CFI_STARTPROC
28808+
28809+ read64 %ecx
28810+ pax_force_retaddr
28811+ ret
28812+ CFI_ENDPROC
28813+ENDPROC(atomic64_read_unchecked_cx8)
28814+
28815 ENTRY(atomic64_set_cx8)
28816 CFI_STARTPROC
28817
28818@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28819 cmpxchg8b (%esi)
28820 jne 1b
28821
28822+ pax_force_retaddr
28823 ret
28824 CFI_ENDPROC
28825 ENDPROC(atomic64_set_cx8)
28826
28827+ENTRY(atomic64_set_unchecked_cx8)
28828+ CFI_STARTPROC
28829+
28830+1:
28831+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28832+ * are atomic on 586 and newer */
28833+ cmpxchg8b (%esi)
28834+ jne 1b
28835+
28836+ pax_force_retaddr
28837+ ret
28838+ CFI_ENDPROC
28839+ENDPROC(atomic64_set_unchecked_cx8)
28840+
28841 ENTRY(atomic64_xchg_cx8)
28842 CFI_STARTPROC
28843
28844@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28845 cmpxchg8b (%esi)
28846 jne 1b
28847
28848+ pax_force_retaddr
28849 ret
28850 CFI_ENDPROC
28851 ENDPROC(atomic64_xchg_cx8)
28852
28853-.macro addsub_return func ins insc
28854-ENTRY(atomic64_\func\()_return_cx8)
28855+.macro addsub_return func ins insc unchecked=""
28856+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28857 CFI_STARTPROC
28858 SAVE ebp
28859 SAVE ebx
28860@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28861 movl %edx, %ecx
28862 \ins\()l %esi, %ebx
28863 \insc\()l %edi, %ecx
28864+
28865+.ifb \unchecked
28866+#ifdef CONFIG_PAX_REFCOUNT
28867+ into
28868+2:
28869+ _ASM_EXTABLE(2b, 3f)
28870+#endif
28871+.endif
28872+
28873 LOCK_PREFIX
28874 cmpxchg8b (%ebp)
28875 jne 1b
28876-
28877-10:
28878 movl %ebx, %eax
28879 movl %ecx, %edx
28880+
28881+.ifb \unchecked
28882+#ifdef CONFIG_PAX_REFCOUNT
28883+3:
28884+#endif
28885+.endif
28886+
28887 RESTORE edi
28888 RESTORE esi
28889 RESTORE ebx
28890 RESTORE ebp
28891+ pax_force_retaddr
28892 ret
28893 CFI_ENDPROC
28894-ENDPROC(atomic64_\func\()_return_cx8)
28895+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28896 .endm
28897
28898 addsub_return add add adc
28899 addsub_return sub sub sbb
28900+addsub_return add add adc _unchecked
28901+addsub_return sub sub sbb _unchecked
28902
28903-.macro incdec_return func ins insc
28904-ENTRY(atomic64_\func\()_return_cx8)
28905+.macro incdec_return func ins insc unchecked=""
28906+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28907 CFI_STARTPROC
28908 SAVE ebx
28909
28910@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28911 movl %edx, %ecx
28912 \ins\()l $1, %ebx
28913 \insc\()l $0, %ecx
28914+
28915+.ifb \unchecked
28916+#ifdef CONFIG_PAX_REFCOUNT
28917+ into
28918+2:
28919+ _ASM_EXTABLE(2b, 3f)
28920+#endif
28921+.endif
28922+
28923 LOCK_PREFIX
28924 cmpxchg8b (%esi)
28925 jne 1b
28926
28927-10:
28928 movl %ebx, %eax
28929 movl %ecx, %edx
28930+
28931+.ifb \unchecked
28932+#ifdef CONFIG_PAX_REFCOUNT
28933+3:
28934+#endif
28935+.endif
28936+
28937 RESTORE ebx
28938+ pax_force_retaddr
28939 ret
28940 CFI_ENDPROC
28941-ENDPROC(atomic64_\func\()_return_cx8)
28942+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28943 .endm
28944
28945 incdec_return inc add adc
28946 incdec_return dec sub sbb
28947+incdec_return inc add adc _unchecked
28948+incdec_return dec sub sbb _unchecked
28949
28950 ENTRY(atomic64_dec_if_positive_cx8)
28951 CFI_STARTPROC
28952@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28953 movl %edx, %ecx
28954 subl $1, %ebx
28955 sbb $0, %ecx
28956+
28957+#ifdef CONFIG_PAX_REFCOUNT
28958+ into
28959+1234:
28960+ _ASM_EXTABLE(1234b, 2f)
28961+#endif
28962+
28963 js 2f
28964 LOCK_PREFIX
28965 cmpxchg8b (%esi)
28966@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28967 movl %ebx, %eax
28968 movl %ecx, %edx
28969 RESTORE ebx
28970+ pax_force_retaddr
28971 ret
28972 CFI_ENDPROC
28973 ENDPROC(atomic64_dec_if_positive_cx8)
28974@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28975 movl %edx, %ecx
28976 addl %ebp, %ebx
28977 adcl %edi, %ecx
28978+
28979+#ifdef CONFIG_PAX_REFCOUNT
28980+ into
28981+1234:
28982+ _ASM_EXTABLE(1234b, 3f)
28983+#endif
28984+
28985 LOCK_PREFIX
28986 cmpxchg8b (%esi)
28987 jne 1b
28988@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28989 CFI_ADJUST_CFA_OFFSET -8
28990 RESTORE ebx
28991 RESTORE ebp
28992+ pax_force_retaddr
28993 ret
28994 4:
28995 cmpl %edx, 4(%esp)
28996@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28997 xorl %ecx, %ecx
28998 addl $1, %ebx
28999 adcl %edx, %ecx
29000+
29001+#ifdef CONFIG_PAX_REFCOUNT
29002+ into
29003+1234:
29004+ _ASM_EXTABLE(1234b, 3f)
29005+#endif
29006+
29007 LOCK_PREFIX
29008 cmpxchg8b (%esi)
29009 jne 1b
29010@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29011 movl $1, %eax
29012 3:
29013 RESTORE ebx
29014+ pax_force_retaddr
29015 ret
29016 CFI_ENDPROC
29017 ENDPROC(atomic64_inc_not_zero_cx8)
29018diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29019index e78b8ee..7e173a8 100644
29020--- a/arch/x86/lib/checksum_32.S
29021+++ b/arch/x86/lib/checksum_32.S
29022@@ -29,7 +29,8 @@
29023 #include <asm/dwarf2.h>
29024 #include <asm/errno.h>
29025 #include <asm/asm.h>
29026-
29027+#include <asm/segment.h>
29028+
29029 /*
29030 * computes a partial checksum, e.g. for TCP/UDP fragments
29031 */
29032@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29033
29034 #define ARGBASE 16
29035 #define FP 12
29036-
29037-ENTRY(csum_partial_copy_generic)
29038+
29039+ENTRY(csum_partial_copy_generic_to_user)
29040 CFI_STARTPROC
29041+
29042+#ifdef CONFIG_PAX_MEMORY_UDEREF
29043+ pushl_cfi %gs
29044+ popl_cfi %es
29045+ jmp csum_partial_copy_generic
29046+#endif
29047+
29048+ENTRY(csum_partial_copy_generic_from_user)
29049+
29050+#ifdef CONFIG_PAX_MEMORY_UDEREF
29051+ pushl_cfi %gs
29052+ popl_cfi %ds
29053+#endif
29054+
29055+ENTRY(csum_partial_copy_generic)
29056 subl $4,%esp
29057 CFI_ADJUST_CFA_OFFSET 4
29058 pushl_cfi %edi
29059@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29060 jmp 4f
29061 SRC(1: movw (%esi), %bx )
29062 addl $2, %esi
29063-DST( movw %bx, (%edi) )
29064+DST( movw %bx, %es:(%edi) )
29065 addl $2, %edi
29066 addw %bx, %ax
29067 adcl $0, %eax
29068@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29069 SRC(1: movl (%esi), %ebx )
29070 SRC( movl 4(%esi), %edx )
29071 adcl %ebx, %eax
29072-DST( movl %ebx, (%edi) )
29073+DST( movl %ebx, %es:(%edi) )
29074 adcl %edx, %eax
29075-DST( movl %edx, 4(%edi) )
29076+DST( movl %edx, %es:4(%edi) )
29077
29078 SRC( movl 8(%esi), %ebx )
29079 SRC( movl 12(%esi), %edx )
29080 adcl %ebx, %eax
29081-DST( movl %ebx, 8(%edi) )
29082+DST( movl %ebx, %es:8(%edi) )
29083 adcl %edx, %eax
29084-DST( movl %edx, 12(%edi) )
29085+DST( movl %edx, %es:12(%edi) )
29086
29087 SRC( movl 16(%esi), %ebx )
29088 SRC( movl 20(%esi), %edx )
29089 adcl %ebx, %eax
29090-DST( movl %ebx, 16(%edi) )
29091+DST( movl %ebx, %es:16(%edi) )
29092 adcl %edx, %eax
29093-DST( movl %edx, 20(%edi) )
29094+DST( movl %edx, %es:20(%edi) )
29095
29096 SRC( movl 24(%esi), %ebx )
29097 SRC( movl 28(%esi), %edx )
29098 adcl %ebx, %eax
29099-DST( movl %ebx, 24(%edi) )
29100+DST( movl %ebx, %es:24(%edi) )
29101 adcl %edx, %eax
29102-DST( movl %edx, 28(%edi) )
29103+DST( movl %edx, %es:28(%edi) )
29104
29105 lea 32(%esi), %esi
29106 lea 32(%edi), %edi
29107@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29108 shrl $2, %edx # This clears CF
29109 SRC(3: movl (%esi), %ebx )
29110 adcl %ebx, %eax
29111-DST( movl %ebx, (%edi) )
29112+DST( movl %ebx, %es:(%edi) )
29113 lea 4(%esi), %esi
29114 lea 4(%edi), %edi
29115 dec %edx
29116@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29117 jb 5f
29118 SRC( movw (%esi), %cx )
29119 leal 2(%esi), %esi
29120-DST( movw %cx, (%edi) )
29121+DST( movw %cx, %es:(%edi) )
29122 leal 2(%edi), %edi
29123 je 6f
29124 shll $16,%ecx
29125 SRC(5: movb (%esi), %cl )
29126-DST( movb %cl, (%edi) )
29127+DST( movb %cl, %es:(%edi) )
29128 6: addl %ecx, %eax
29129 adcl $0, %eax
29130 7:
29131@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29132
29133 6001:
29134 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29135- movl $-EFAULT, (%ebx)
29136+ movl $-EFAULT, %ss:(%ebx)
29137
29138 # zero the complete destination - computing the rest
29139 # is too much work
29140@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29141
29142 6002:
29143 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29144- movl $-EFAULT,(%ebx)
29145+ movl $-EFAULT,%ss:(%ebx)
29146 jmp 5000b
29147
29148 .previous
29149
29150+ pushl_cfi %ss
29151+ popl_cfi %ds
29152+ pushl_cfi %ss
29153+ popl_cfi %es
29154 popl_cfi %ebx
29155 CFI_RESTORE ebx
29156 popl_cfi %esi
29157@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29158 popl_cfi %ecx # equivalent to addl $4,%esp
29159 ret
29160 CFI_ENDPROC
29161-ENDPROC(csum_partial_copy_generic)
29162+ENDPROC(csum_partial_copy_generic_to_user)
29163
29164 #else
29165
29166 /* Version for PentiumII/PPro */
29167
29168 #define ROUND1(x) \
29169+ nop; nop; nop; \
29170 SRC(movl x(%esi), %ebx ) ; \
29171 addl %ebx, %eax ; \
29172- DST(movl %ebx, x(%edi) ) ;
29173+ DST(movl %ebx, %es:x(%edi)) ;
29174
29175 #define ROUND(x) \
29176+ nop; nop; nop; \
29177 SRC(movl x(%esi), %ebx ) ; \
29178 adcl %ebx, %eax ; \
29179- DST(movl %ebx, x(%edi) ) ;
29180+ DST(movl %ebx, %es:x(%edi)) ;
29181
29182 #define ARGBASE 12
29183-
29184-ENTRY(csum_partial_copy_generic)
29185+
29186+ENTRY(csum_partial_copy_generic_to_user)
29187 CFI_STARTPROC
29188+
29189+#ifdef CONFIG_PAX_MEMORY_UDEREF
29190+ pushl_cfi %gs
29191+ popl_cfi %es
29192+ jmp csum_partial_copy_generic
29193+#endif
29194+
29195+ENTRY(csum_partial_copy_generic_from_user)
29196+
29197+#ifdef CONFIG_PAX_MEMORY_UDEREF
29198+ pushl_cfi %gs
29199+ popl_cfi %ds
29200+#endif
29201+
29202+ENTRY(csum_partial_copy_generic)
29203 pushl_cfi %ebx
29204 CFI_REL_OFFSET ebx, 0
29205 pushl_cfi %edi
29206@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29207 subl %ebx, %edi
29208 lea -1(%esi),%edx
29209 andl $-32,%edx
29210- lea 3f(%ebx,%ebx), %ebx
29211+ lea 3f(%ebx,%ebx,2), %ebx
29212 testl %esi, %esi
29213 jmp *%ebx
29214 1: addl $64,%esi
29215@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29216 jb 5f
29217 SRC( movw (%esi), %dx )
29218 leal 2(%esi), %esi
29219-DST( movw %dx, (%edi) )
29220+DST( movw %dx, %es:(%edi) )
29221 leal 2(%edi), %edi
29222 je 6f
29223 shll $16,%edx
29224 5:
29225 SRC( movb (%esi), %dl )
29226-DST( movb %dl, (%edi) )
29227+DST( movb %dl, %es:(%edi) )
29228 6: addl %edx, %eax
29229 adcl $0, %eax
29230 7:
29231 .section .fixup, "ax"
29232 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29233- movl $-EFAULT, (%ebx)
29234+ movl $-EFAULT, %ss:(%ebx)
29235 # zero the complete destination (computing the rest is too much work)
29236 movl ARGBASE+8(%esp),%edi # dst
29237 movl ARGBASE+12(%esp),%ecx # len
29238@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29239 rep; stosb
29240 jmp 7b
29241 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29242- movl $-EFAULT, (%ebx)
29243+ movl $-EFAULT, %ss:(%ebx)
29244 jmp 7b
29245 .previous
29246
29247+#ifdef CONFIG_PAX_MEMORY_UDEREF
29248+ pushl_cfi %ss
29249+ popl_cfi %ds
29250+ pushl_cfi %ss
29251+ popl_cfi %es
29252+#endif
29253+
29254 popl_cfi %esi
29255 CFI_RESTORE esi
29256 popl_cfi %edi
29257@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29258 CFI_RESTORE ebx
29259 ret
29260 CFI_ENDPROC
29261-ENDPROC(csum_partial_copy_generic)
29262+ENDPROC(csum_partial_copy_generic_to_user)
29263
29264 #undef ROUND
29265 #undef ROUND1
29266diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29267index f2145cf..cea889d 100644
29268--- a/arch/x86/lib/clear_page_64.S
29269+++ b/arch/x86/lib/clear_page_64.S
29270@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29271 movl $4096/8,%ecx
29272 xorl %eax,%eax
29273 rep stosq
29274+ pax_force_retaddr
29275 ret
29276 CFI_ENDPROC
29277 ENDPROC(clear_page_c)
29278@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29279 movl $4096,%ecx
29280 xorl %eax,%eax
29281 rep stosb
29282+ pax_force_retaddr
29283 ret
29284 CFI_ENDPROC
29285 ENDPROC(clear_page_c_e)
29286@@ -43,6 +45,7 @@ ENTRY(clear_page)
29287 leaq 64(%rdi),%rdi
29288 jnz .Lloop
29289 nop
29290+ pax_force_retaddr
29291 ret
29292 CFI_ENDPROC
29293 .Lclear_page_end:
29294@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29295
29296 #include <asm/cpufeature.h>
29297
29298- .section .altinstr_replacement,"ax"
29299+ .section .altinstr_replacement,"a"
29300 1: .byte 0xeb /* jmp <disp8> */
29301 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29302 2: .byte 0xeb /* jmp <disp8> */
29303diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29304index 1e572c5..2a162cd 100644
29305--- a/arch/x86/lib/cmpxchg16b_emu.S
29306+++ b/arch/x86/lib/cmpxchg16b_emu.S
29307@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29308
29309 popf
29310 mov $1, %al
29311+ pax_force_retaddr
29312 ret
29313
29314 not_same:
29315 popf
29316 xor %al,%al
29317+ pax_force_retaddr
29318 ret
29319
29320 CFI_ENDPROC
29321diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29322index 176cca6..e0d658e 100644
29323--- a/arch/x86/lib/copy_page_64.S
29324+++ b/arch/x86/lib/copy_page_64.S
29325@@ -9,6 +9,7 @@ copy_page_rep:
29326 CFI_STARTPROC
29327 movl $4096/8, %ecx
29328 rep movsq
29329+ pax_force_retaddr
29330 ret
29331 CFI_ENDPROC
29332 ENDPROC(copy_page_rep)
29333@@ -24,8 +25,8 @@ ENTRY(copy_page)
29334 CFI_ADJUST_CFA_OFFSET 2*8
29335 movq %rbx, (%rsp)
29336 CFI_REL_OFFSET rbx, 0
29337- movq %r12, 1*8(%rsp)
29338- CFI_REL_OFFSET r12, 1*8
29339+ movq %r13, 1*8(%rsp)
29340+ CFI_REL_OFFSET r13, 1*8
29341
29342 movl $(4096/64)-5, %ecx
29343 .p2align 4
29344@@ -38,7 +39,7 @@ ENTRY(copy_page)
29345 movq 0x8*4(%rsi), %r9
29346 movq 0x8*5(%rsi), %r10
29347 movq 0x8*6(%rsi), %r11
29348- movq 0x8*7(%rsi), %r12
29349+ movq 0x8*7(%rsi), %r13
29350
29351 prefetcht0 5*64(%rsi)
29352
29353@@ -49,7 +50,7 @@ ENTRY(copy_page)
29354 movq %r9, 0x8*4(%rdi)
29355 movq %r10, 0x8*5(%rdi)
29356 movq %r11, 0x8*6(%rdi)
29357- movq %r12, 0x8*7(%rdi)
29358+ movq %r13, 0x8*7(%rdi)
29359
29360 leaq 64 (%rsi), %rsi
29361 leaq 64 (%rdi), %rdi
29362@@ -68,7 +69,7 @@ ENTRY(copy_page)
29363 movq 0x8*4(%rsi), %r9
29364 movq 0x8*5(%rsi), %r10
29365 movq 0x8*6(%rsi), %r11
29366- movq 0x8*7(%rsi), %r12
29367+ movq 0x8*7(%rsi), %r13
29368
29369 movq %rax, 0x8*0(%rdi)
29370 movq %rbx, 0x8*1(%rdi)
29371@@ -77,7 +78,7 @@ ENTRY(copy_page)
29372 movq %r9, 0x8*4(%rdi)
29373 movq %r10, 0x8*5(%rdi)
29374 movq %r11, 0x8*6(%rdi)
29375- movq %r12, 0x8*7(%rdi)
29376+ movq %r13, 0x8*7(%rdi)
29377
29378 leaq 64(%rdi), %rdi
29379 leaq 64(%rsi), %rsi
29380@@ -85,10 +86,11 @@ ENTRY(copy_page)
29381
29382 movq (%rsp), %rbx
29383 CFI_RESTORE rbx
29384- movq 1*8(%rsp), %r12
29385- CFI_RESTORE r12
29386+ movq 1*8(%rsp), %r13
29387+ CFI_RESTORE r13
29388 addq $2*8, %rsp
29389 CFI_ADJUST_CFA_OFFSET -2*8
29390+ pax_force_retaddr
29391 ret
29392 .Lcopy_page_end:
29393 CFI_ENDPROC
29394@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29395
29396 #include <asm/cpufeature.h>
29397
29398- .section .altinstr_replacement,"ax"
29399+ .section .altinstr_replacement,"a"
29400 1: .byte 0xeb /* jmp <disp8> */
29401 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29402 2:
29403diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29404index dee945d..a84067b 100644
29405--- a/arch/x86/lib/copy_user_64.S
29406+++ b/arch/x86/lib/copy_user_64.S
29407@@ -18,31 +18,7 @@
29408 #include <asm/alternative-asm.h>
29409 #include <asm/asm.h>
29410 #include <asm/smap.h>
29411-
29412-/*
29413- * By placing feature2 after feature1 in altinstructions section, we logically
29414- * implement:
29415- * If CPU has feature2, jmp to alt2 is used
29416- * else if CPU has feature1, jmp to alt1 is used
29417- * else jmp to orig is used.
29418- */
29419- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29420-0:
29421- .byte 0xe9 /* 32bit jump */
29422- .long \orig-1f /* by default jump to orig */
29423-1:
29424- .section .altinstr_replacement,"ax"
29425-2: .byte 0xe9 /* near jump with 32bit immediate */
29426- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29427-3: .byte 0xe9 /* near jump with 32bit immediate */
29428- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29429- .previous
29430-
29431- .section .altinstructions,"a"
29432- altinstruction_entry 0b,2b,\feature1,5,5
29433- altinstruction_entry 0b,3b,\feature2,5,5
29434- .previous
29435- .endm
29436+#include <asm/pgtable.h>
29437
29438 .macro ALIGN_DESTINATION
29439 #ifdef FIX_ALIGNMENT
29440@@ -70,52 +46,6 @@
29441 #endif
29442 .endm
29443
29444-/* Standard copy_to_user with segment limit checking */
29445-ENTRY(_copy_to_user)
29446- CFI_STARTPROC
29447- GET_THREAD_INFO(%rax)
29448- movq %rdi,%rcx
29449- addq %rdx,%rcx
29450- jc bad_to_user
29451- cmpq TI_addr_limit(%rax),%rcx
29452- ja bad_to_user
29453- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29454- copy_user_generic_unrolled,copy_user_generic_string, \
29455- copy_user_enhanced_fast_string
29456- CFI_ENDPROC
29457-ENDPROC(_copy_to_user)
29458-
29459-/* Standard copy_from_user with segment limit checking */
29460-ENTRY(_copy_from_user)
29461- CFI_STARTPROC
29462- GET_THREAD_INFO(%rax)
29463- movq %rsi,%rcx
29464- addq %rdx,%rcx
29465- jc bad_from_user
29466- cmpq TI_addr_limit(%rax),%rcx
29467- ja bad_from_user
29468- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29469- copy_user_generic_unrolled,copy_user_generic_string, \
29470- copy_user_enhanced_fast_string
29471- CFI_ENDPROC
29472-ENDPROC(_copy_from_user)
29473-
29474- .section .fixup,"ax"
29475- /* must zero dest */
29476-ENTRY(bad_from_user)
29477-bad_from_user:
29478- CFI_STARTPROC
29479- movl %edx,%ecx
29480- xorl %eax,%eax
29481- rep
29482- stosb
29483-bad_to_user:
29484- movl %edx,%eax
29485- ret
29486- CFI_ENDPROC
29487-ENDPROC(bad_from_user)
29488- .previous
29489-
29490 /*
29491 * copy_user_generic_unrolled - memory copy with exception handling.
29492 * This version is for CPUs like P4 that don't have efficient micro
29493@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29494 */
29495 ENTRY(copy_user_generic_unrolled)
29496 CFI_STARTPROC
29497+ ASM_PAX_OPEN_USERLAND
29498 ASM_STAC
29499 cmpl $8,%edx
29500 jb 20f /* less then 8 bytes, go to byte copy loop */
29501@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29502 jnz 21b
29503 23: xor %eax,%eax
29504 ASM_CLAC
29505+ ASM_PAX_CLOSE_USERLAND
29506+ pax_force_retaddr
29507 ret
29508
29509 .section .fixup,"ax"
29510@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29511 */
29512 ENTRY(copy_user_generic_string)
29513 CFI_STARTPROC
29514+ ASM_PAX_OPEN_USERLAND
29515 ASM_STAC
29516 cmpl $8,%edx
29517 jb 2f /* less than 8 bytes, go to byte copy loop */
29518@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29519 movsb
29520 xorl %eax,%eax
29521 ASM_CLAC
29522+ ASM_PAX_CLOSE_USERLAND
29523+ pax_force_retaddr
29524 ret
29525
29526 .section .fixup,"ax"
29527@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29528 */
29529 ENTRY(copy_user_enhanced_fast_string)
29530 CFI_STARTPROC
29531+ ASM_PAX_OPEN_USERLAND
29532 ASM_STAC
29533 movl %edx,%ecx
29534 1: rep
29535 movsb
29536 xorl %eax,%eax
29537 ASM_CLAC
29538+ ASM_PAX_CLOSE_USERLAND
29539+ pax_force_retaddr
29540 ret
29541
29542 .section .fixup,"ax"
29543diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29544index 6a4f43c..c70fb52 100644
29545--- a/arch/x86/lib/copy_user_nocache_64.S
29546+++ b/arch/x86/lib/copy_user_nocache_64.S
29547@@ -8,6 +8,7 @@
29548
29549 #include <linux/linkage.h>
29550 #include <asm/dwarf2.h>
29551+#include <asm/alternative-asm.h>
29552
29553 #define FIX_ALIGNMENT 1
29554
29555@@ -16,6 +17,7 @@
29556 #include <asm/thread_info.h>
29557 #include <asm/asm.h>
29558 #include <asm/smap.h>
29559+#include <asm/pgtable.h>
29560
29561 .macro ALIGN_DESTINATION
29562 #ifdef FIX_ALIGNMENT
29563@@ -49,6 +51,16 @@
29564 */
29565 ENTRY(__copy_user_nocache)
29566 CFI_STARTPROC
29567+
29568+#ifdef CONFIG_PAX_MEMORY_UDEREF
29569+ mov pax_user_shadow_base,%rcx
29570+ cmp %rcx,%rsi
29571+ jae 1f
29572+ add %rcx,%rsi
29573+1:
29574+#endif
29575+
29576+ ASM_PAX_OPEN_USERLAND
29577 ASM_STAC
29578 cmpl $8,%edx
29579 jb 20f /* less then 8 bytes, go to byte copy loop */
29580@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29581 jnz 21b
29582 23: xorl %eax,%eax
29583 ASM_CLAC
29584+ ASM_PAX_CLOSE_USERLAND
29585 sfence
29586+ pax_force_retaddr
29587 ret
29588
29589 .section .fixup,"ax"
29590diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29591index 2419d5f..fe52d0e 100644
29592--- a/arch/x86/lib/csum-copy_64.S
29593+++ b/arch/x86/lib/csum-copy_64.S
29594@@ -9,6 +9,7 @@
29595 #include <asm/dwarf2.h>
29596 #include <asm/errno.h>
29597 #include <asm/asm.h>
29598+#include <asm/alternative-asm.h>
29599
29600 /*
29601 * Checksum copy with exception handling.
29602@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29603 CFI_ADJUST_CFA_OFFSET 7*8
29604 movq %rbx, 2*8(%rsp)
29605 CFI_REL_OFFSET rbx, 2*8
29606- movq %r12, 3*8(%rsp)
29607- CFI_REL_OFFSET r12, 3*8
29608+ movq %r15, 3*8(%rsp)
29609+ CFI_REL_OFFSET r15, 3*8
29610 movq %r14, 4*8(%rsp)
29611 CFI_REL_OFFSET r14, 4*8
29612 movq %r13, 5*8(%rsp)
29613@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29614 movl %edx, %ecx
29615
29616 xorl %r9d, %r9d
29617- movq %rcx, %r12
29618+ movq %rcx, %r15
29619
29620- shrq $6, %r12
29621+ shrq $6, %r15
29622 jz .Lhandle_tail /* < 64 */
29623
29624 clc
29625
29626 /* main loop. clear in 64 byte blocks */
29627 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29628- /* r11: temp3, rdx: temp4, r12 loopcnt */
29629+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29630 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29631 .p2align 4
29632 .Lloop:
29633@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29634 adcq %r14, %rax
29635 adcq %r13, %rax
29636
29637- decl %r12d
29638+ decl %r15d
29639
29640 dest
29641 movq %rbx, (%rsi)
29642@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29643 .Lende:
29644 movq 2*8(%rsp), %rbx
29645 CFI_RESTORE rbx
29646- movq 3*8(%rsp), %r12
29647- CFI_RESTORE r12
29648+ movq 3*8(%rsp), %r15
29649+ CFI_RESTORE r15
29650 movq 4*8(%rsp), %r14
29651 CFI_RESTORE r14
29652 movq 5*8(%rsp), %r13
29653@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29654 CFI_RESTORE rbp
29655 addq $7*8, %rsp
29656 CFI_ADJUST_CFA_OFFSET -7*8
29657+ pax_force_retaddr
29658 ret
29659 CFI_RESTORE_STATE
29660
29661diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29662index 7609e0e..b449b98 100644
29663--- a/arch/x86/lib/csum-wrappers_64.c
29664+++ b/arch/x86/lib/csum-wrappers_64.c
29665@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29666 len -= 2;
29667 }
29668 }
29669+ pax_open_userland();
29670 stac();
29671- isum = csum_partial_copy_generic((__force const void *)src,
29672+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29673 dst, len, isum, errp, NULL);
29674 clac();
29675+ pax_close_userland();
29676 if (unlikely(*errp))
29677 goto out_err;
29678
29679@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29680 }
29681
29682 *errp = 0;
29683+ pax_open_userland();
29684 stac();
29685- ret = csum_partial_copy_generic(src, (void __force *)dst,
29686+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29687 len, isum, NULL, errp);
29688 clac();
29689+ pax_close_userland();
29690 return ret;
29691 }
29692 EXPORT_SYMBOL(csum_partial_copy_to_user);
29693diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29694index a451235..1daa956 100644
29695--- a/arch/x86/lib/getuser.S
29696+++ b/arch/x86/lib/getuser.S
29697@@ -33,17 +33,40 @@
29698 #include <asm/thread_info.h>
29699 #include <asm/asm.h>
29700 #include <asm/smap.h>
29701+#include <asm/segment.h>
29702+#include <asm/pgtable.h>
29703+#include <asm/alternative-asm.h>
29704+
29705+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29706+#define __copyuser_seg gs;
29707+#else
29708+#define __copyuser_seg
29709+#endif
29710
29711 .text
29712 ENTRY(__get_user_1)
29713 CFI_STARTPROC
29714+
29715+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29716 GET_THREAD_INFO(%_ASM_DX)
29717 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29718 jae bad_get_user
29719 ASM_STAC
29720-1: movzbl (%_ASM_AX),%edx
29721+
29722+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29723+ mov pax_user_shadow_base,%_ASM_DX
29724+ cmp %_ASM_DX,%_ASM_AX
29725+ jae 1234f
29726+ add %_ASM_DX,%_ASM_AX
29727+1234:
29728+#endif
29729+
29730+#endif
29731+
29732+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29733 xor %eax,%eax
29734 ASM_CLAC
29735+ pax_force_retaddr
29736 ret
29737 CFI_ENDPROC
29738 ENDPROC(__get_user_1)
29739@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29740 ENTRY(__get_user_2)
29741 CFI_STARTPROC
29742 add $1,%_ASM_AX
29743+
29744+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29745 jc bad_get_user
29746 GET_THREAD_INFO(%_ASM_DX)
29747 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29748 jae bad_get_user
29749 ASM_STAC
29750-2: movzwl -1(%_ASM_AX),%edx
29751+
29752+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29753+ mov pax_user_shadow_base,%_ASM_DX
29754+ cmp %_ASM_DX,%_ASM_AX
29755+ jae 1234f
29756+ add %_ASM_DX,%_ASM_AX
29757+1234:
29758+#endif
29759+
29760+#endif
29761+
29762+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29763 xor %eax,%eax
29764 ASM_CLAC
29765+ pax_force_retaddr
29766 ret
29767 CFI_ENDPROC
29768 ENDPROC(__get_user_2)
29769@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29770 ENTRY(__get_user_4)
29771 CFI_STARTPROC
29772 add $3,%_ASM_AX
29773+
29774+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29775 jc bad_get_user
29776 GET_THREAD_INFO(%_ASM_DX)
29777 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29778 jae bad_get_user
29779 ASM_STAC
29780-3: movl -3(%_ASM_AX),%edx
29781+
29782+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29783+ mov pax_user_shadow_base,%_ASM_DX
29784+ cmp %_ASM_DX,%_ASM_AX
29785+ jae 1234f
29786+ add %_ASM_DX,%_ASM_AX
29787+1234:
29788+#endif
29789+
29790+#endif
29791+
29792+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29793 xor %eax,%eax
29794 ASM_CLAC
29795+ pax_force_retaddr
29796 ret
29797 CFI_ENDPROC
29798 ENDPROC(__get_user_4)
29799@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29800 GET_THREAD_INFO(%_ASM_DX)
29801 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29802 jae bad_get_user
29803+
29804+#ifdef CONFIG_PAX_MEMORY_UDEREF
29805+ mov pax_user_shadow_base,%_ASM_DX
29806+ cmp %_ASM_DX,%_ASM_AX
29807+ jae 1234f
29808+ add %_ASM_DX,%_ASM_AX
29809+1234:
29810+#endif
29811+
29812 ASM_STAC
29813 4: movq -7(%_ASM_AX),%rdx
29814 xor %eax,%eax
29815 ASM_CLAC
29816+ pax_force_retaddr
29817 ret
29818 #else
29819 add $7,%_ASM_AX
29820@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29821 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29822 jae bad_get_user_8
29823 ASM_STAC
29824-4: movl -7(%_ASM_AX),%edx
29825-5: movl -3(%_ASM_AX),%ecx
29826+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29827+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29828 xor %eax,%eax
29829 ASM_CLAC
29830+ pax_force_retaddr
29831 ret
29832 #endif
29833 CFI_ENDPROC
29834@@ -113,6 +175,7 @@ bad_get_user:
29835 xor %edx,%edx
29836 mov $(-EFAULT),%_ASM_AX
29837 ASM_CLAC
29838+ pax_force_retaddr
29839 ret
29840 CFI_ENDPROC
29841 END(bad_get_user)
29842@@ -124,6 +187,7 @@ bad_get_user_8:
29843 xor %ecx,%ecx
29844 mov $(-EFAULT),%_ASM_AX
29845 ASM_CLAC
29846+ pax_force_retaddr
29847 ret
29848 CFI_ENDPROC
29849 END(bad_get_user_8)
29850diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29851index 54fcffe..7be149e 100644
29852--- a/arch/x86/lib/insn.c
29853+++ b/arch/x86/lib/insn.c
29854@@ -20,8 +20,10 @@
29855
29856 #ifdef __KERNEL__
29857 #include <linux/string.h>
29858+#include <asm/pgtable_types.h>
29859 #else
29860 #include <string.h>
29861+#define ktla_ktva(addr) addr
29862 #endif
29863 #include <asm/inat.h>
29864 #include <asm/insn.h>
29865@@ -53,8 +55,8 @@
29866 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29867 {
29868 memset(insn, 0, sizeof(*insn));
29869- insn->kaddr = kaddr;
29870- insn->next_byte = kaddr;
29871+ insn->kaddr = ktla_ktva(kaddr);
29872+ insn->next_byte = ktla_ktva(kaddr);
29873 insn->x86_64 = x86_64 ? 1 : 0;
29874 insn->opnd_bytes = 4;
29875 if (x86_64)
29876diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29877index 05a95e7..326f2fa 100644
29878--- a/arch/x86/lib/iomap_copy_64.S
29879+++ b/arch/x86/lib/iomap_copy_64.S
29880@@ -17,6 +17,7 @@
29881
29882 #include <linux/linkage.h>
29883 #include <asm/dwarf2.h>
29884+#include <asm/alternative-asm.h>
29885
29886 /*
29887 * override generic version in lib/iomap_copy.c
29888@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29889 CFI_STARTPROC
29890 movl %edx,%ecx
29891 rep movsd
29892+ pax_force_retaddr
29893 ret
29894 CFI_ENDPROC
29895 ENDPROC(__iowrite32_copy)
29896diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29897index 56313a3..0db417e 100644
29898--- a/arch/x86/lib/memcpy_64.S
29899+++ b/arch/x86/lib/memcpy_64.S
29900@@ -24,7 +24,7 @@
29901 * This gets patched over the unrolled variant (below) via the
29902 * alternative instructions framework:
29903 */
29904- .section .altinstr_replacement, "ax", @progbits
29905+ .section .altinstr_replacement, "a", @progbits
29906 .Lmemcpy_c:
29907 movq %rdi, %rax
29908 movq %rdx, %rcx
29909@@ -33,6 +33,7 @@
29910 rep movsq
29911 movl %edx, %ecx
29912 rep movsb
29913+ pax_force_retaddr
29914 ret
29915 .Lmemcpy_e:
29916 .previous
29917@@ -44,11 +45,12 @@
29918 * This gets patched over the unrolled variant (below) via the
29919 * alternative instructions framework:
29920 */
29921- .section .altinstr_replacement, "ax", @progbits
29922+ .section .altinstr_replacement, "a", @progbits
29923 .Lmemcpy_c_e:
29924 movq %rdi, %rax
29925 movq %rdx, %rcx
29926 rep movsb
29927+ pax_force_retaddr
29928 ret
29929 .Lmemcpy_e_e:
29930 .previous
29931@@ -136,6 +138,7 @@ ENTRY(memcpy)
29932 movq %r9, 1*8(%rdi)
29933 movq %r10, -2*8(%rdi, %rdx)
29934 movq %r11, -1*8(%rdi, %rdx)
29935+ pax_force_retaddr
29936 retq
29937 .p2align 4
29938 .Lless_16bytes:
29939@@ -148,6 +151,7 @@ ENTRY(memcpy)
29940 movq -1*8(%rsi, %rdx), %r9
29941 movq %r8, 0*8(%rdi)
29942 movq %r9, -1*8(%rdi, %rdx)
29943+ pax_force_retaddr
29944 retq
29945 .p2align 4
29946 .Lless_8bytes:
29947@@ -161,6 +165,7 @@ ENTRY(memcpy)
29948 movl -4(%rsi, %rdx), %r8d
29949 movl %ecx, (%rdi)
29950 movl %r8d, -4(%rdi, %rdx)
29951+ pax_force_retaddr
29952 retq
29953 .p2align 4
29954 .Lless_3bytes:
29955@@ -179,6 +184,7 @@ ENTRY(memcpy)
29956 movb %cl, (%rdi)
29957
29958 .Lend:
29959+ pax_force_retaddr
29960 retq
29961 CFI_ENDPROC
29962 ENDPROC(memcpy)
29963diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29964index 65268a6..dd1de11 100644
29965--- a/arch/x86/lib/memmove_64.S
29966+++ b/arch/x86/lib/memmove_64.S
29967@@ -202,14 +202,16 @@ ENTRY(memmove)
29968 movb (%rsi), %r11b
29969 movb %r11b, (%rdi)
29970 13:
29971+ pax_force_retaddr
29972 retq
29973 CFI_ENDPROC
29974
29975- .section .altinstr_replacement,"ax"
29976+ .section .altinstr_replacement,"a"
29977 .Lmemmove_begin_forward_efs:
29978 /* Forward moving data. */
29979 movq %rdx, %rcx
29980 rep movsb
29981+ pax_force_retaddr
29982 retq
29983 .Lmemmove_end_forward_efs:
29984 .previous
29985diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29986index 2dcb380..2eb79fe 100644
29987--- a/arch/x86/lib/memset_64.S
29988+++ b/arch/x86/lib/memset_64.S
29989@@ -16,7 +16,7 @@
29990 *
29991 * rax original destination
29992 */
29993- .section .altinstr_replacement, "ax", @progbits
29994+ .section .altinstr_replacement, "a", @progbits
29995 .Lmemset_c:
29996 movq %rdi,%r9
29997 movq %rdx,%rcx
29998@@ -30,6 +30,7 @@
29999 movl %edx,%ecx
30000 rep stosb
30001 movq %r9,%rax
30002+ pax_force_retaddr
30003 ret
30004 .Lmemset_e:
30005 .previous
30006@@ -45,13 +46,14 @@
30007 *
30008 * rax original destination
30009 */
30010- .section .altinstr_replacement, "ax", @progbits
30011+ .section .altinstr_replacement, "a", @progbits
30012 .Lmemset_c_e:
30013 movq %rdi,%r9
30014 movb %sil,%al
30015 movq %rdx,%rcx
30016 rep stosb
30017 movq %r9,%rax
30018+ pax_force_retaddr
30019 ret
30020 .Lmemset_e_e:
30021 .previous
30022@@ -118,6 +120,7 @@ ENTRY(__memset)
30023
30024 .Lende:
30025 movq %r10,%rax
30026+ pax_force_retaddr
30027 ret
30028
30029 CFI_RESTORE_STATE
30030diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30031index c9f2d9b..e7fd2c0 100644
30032--- a/arch/x86/lib/mmx_32.c
30033+++ b/arch/x86/lib/mmx_32.c
30034@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30035 {
30036 void *p;
30037 int i;
30038+ unsigned long cr0;
30039
30040 if (unlikely(in_interrupt()))
30041 return __memcpy(to, from, len);
30042@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30043 kernel_fpu_begin();
30044
30045 __asm__ __volatile__ (
30046- "1: prefetch (%0)\n" /* This set is 28 bytes */
30047- " prefetch 64(%0)\n"
30048- " prefetch 128(%0)\n"
30049- " prefetch 192(%0)\n"
30050- " prefetch 256(%0)\n"
30051+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30052+ " prefetch 64(%1)\n"
30053+ " prefetch 128(%1)\n"
30054+ " prefetch 192(%1)\n"
30055+ " prefetch 256(%1)\n"
30056 "2: \n"
30057 ".section .fixup, \"ax\"\n"
30058- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30059+ "3: \n"
30060+
30061+#ifdef CONFIG_PAX_KERNEXEC
30062+ " movl %%cr0, %0\n"
30063+ " movl %0, %%eax\n"
30064+ " andl $0xFFFEFFFF, %%eax\n"
30065+ " movl %%eax, %%cr0\n"
30066+#endif
30067+
30068+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30069+
30070+#ifdef CONFIG_PAX_KERNEXEC
30071+ " movl %0, %%cr0\n"
30072+#endif
30073+
30074 " jmp 2b\n"
30075 ".previous\n"
30076 _ASM_EXTABLE(1b, 3b)
30077- : : "r" (from));
30078+ : "=&r" (cr0) : "r" (from) : "ax");
30079
30080 for ( ; i > 5; i--) {
30081 __asm__ __volatile__ (
30082- "1: prefetch 320(%0)\n"
30083- "2: movq (%0), %%mm0\n"
30084- " movq 8(%0), %%mm1\n"
30085- " movq 16(%0), %%mm2\n"
30086- " movq 24(%0), %%mm3\n"
30087- " movq %%mm0, (%1)\n"
30088- " movq %%mm1, 8(%1)\n"
30089- " movq %%mm2, 16(%1)\n"
30090- " movq %%mm3, 24(%1)\n"
30091- " movq 32(%0), %%mm0\n"
30092- " movq 40(%0), %%mm1\n"
30093- " movq 48(%0), %%mm2\n"
30094- " movq 56(%0), %%mm3\n"
30095- " movq %%mm0, 32(%1)\n"
30096- " movq %%mm1, 40(%1)\n"
30097- " movq %%mm2, 48(%1)\n"
30098- " movq %%mm3, 56(%1)\n"
30099+ "1: prefetch 320(%1)\n"
30100+ "2: movq (%1), %%mm0\n"
30101+ " movq 8(%1), %%mm1\n"
30102+ " movq 16(%1), %%mm2\n"
30103+ " movq 24(%1), %%mm3\n"
30104+ " movq %%mm0, (%2)\n"
30105+ " movq %%mm1, 8(%2)\n"
30106+ " movq %%mm2, 16(%2)\n"
30107+ " movq %%mm3, 24(%2)\n"
30108+ " movq 32(%1), %%mm0\n"
30109+ " movq 40(%1), %%mm1\n"
30110+ " movq 48(%1), %%mm2\n"
30111+ " movq 56(%1), %%mm3\n"
30112+ " movq %%mm0, 32(%2)\n"
30113+ " movq %%mm1, 40(%2)\n"
30114+ " movq %%mm2, 48(%2)\n"
30115+ " movq %%mm3, 56(%2)\n"
30116 ".section .fixup, \"ax\"\n"
30117- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30118+ "3:\n"
30119+
30120+#ifdef CONFIG_PAX_KERNEXEC
30121+ " movl %%cr0, %0\n"
30122+ " movl %0, %%eax\n"
30123+ " andl $0xFFFEFFFF, %%eax\n"
30124+ " movl %%eax, %%cr0\n"
30125+#endif
30126+
30127+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30128+
30129+#ifdef CONFIG_PAX_KERNEXEC
30130+ " movl %0, %%cr0\n"
30131+#endif
30132+
30133 " jmp 2b\n"
30134 ".previous\n"
30135 _ASM_EXTABLE(1b, 3b)
30136- : : "r" (from), "r" (to) : "memory");
30137+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30138
30139 from += 64;
30140 to += 64;
30141@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30142 static void fast_copy_page(void *to, void *from)
30143 {
30144 int i;
30145+ unsigned long cr0;
30146
30147 kernel_fpu_begin();
30148
30149@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30150 * but that is for later. -AV
30151 */
30152 __asm__ __volatile__(
30153- "1: prefetch (%0)\n"
30154- " prefetch 64(%0)\n"
30155- " prefetch 128(%0)\n"
30156- " prefetch 192(%0)\n"
30157- " prefetch 256(%0)\n"
30158+ "1: prefetch (%1)\n"
30159+ " prefetch 64(%1)\n"
30160+ " prefetch 128(%1)\n"
30161+ " prefetch 192(%1)\n"
30162+ " prefetch 256(%1)\n"
30163 "2: \n"
30164 ".section .fixup, \"ax\"\n"
30165- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30166+ "3: \n"
30167+
30168+#ifdef CONFIG_PAX_KERNEXEC
30169+ " movl %%cr0, %0\n"
30170+ " movl %0, %%eax\n"
30171+ " andl $0xFFFEFFFF, %%eax\n"
30172+ " movl %%eax, %%cr0\n"
30173+#endif
30174+
30175+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30176+
30177+#ifdef CONFIG_PAX_KERNEXEC
30178+ " movl %0, %%cr0\n"
30179+#endif
30180+
30181 " jmp 2b\n"
30182 ".previous\n"
30183- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30184+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30185
30186 for (i = 0; i < (4096-320)/64; i++) {
30187 __asm__ __volatile__ (
30188- "1: prefetch 320(%0)\n"
30189- "2: movq (%0), %%mm0\n"
30190- " movntq %%mm0, (%1)\n"
30191- " movq 8(%0), %%mm1\n"
30192- " movntq %%mm1, 8(%1)\n"
30193- " movq 16(%0), %%mm2\n"
30194- " movntq %%mm2, 16(%1)\n"
30195- " movq 24(%0), %%mm3\n"
30196- " movntq %%mm3, 24(%1)\n"
30197- " movq 32(%0), %%mm4\n"
30198- " movntq %%mm4, 32(%1)\n"
30199- " movq 40(%0), %%mm5\n"
30200- " movntq %%mm5, 40(%1)\n"
30201- " movq 48(%0), %%mm6\n"
30202- " movntq %%mm6, 48(%1)\n"
30203- " movq 56(%0), %%mm7\n"
30204- " movntq %%mm7, 56(%1)\n"
30205+ "1: prefetch 320(%1)\n"
30206+ "2: movq (%1), %%mm0\n"
30207+ " movntq %%mm0, (%2)\n"
30208+ " movq 8(%1), %%mm1\n"
30209+ " movntq %%mm1, 8(%2)\n"
30210+ " movq 16(%1), %%mm2\n"
30211+ " movntq %%mm2, 16(%2)\n"
30212+ " movq 24(%1), %%mm3\n"
30213+ " movntq %%mm3, 24(%2)\n"
30214+ " movq 32(%1), %%mm4\n"
30215+ " movntq %%mm4, 32(%2)\n"
30216+ " movq 40(%1), %%mm5\n"
30217+ " movntq %%mm5, 40(%2)\n"
30218+ " movq 48(%1), %%mm6\n"
30219+ " movntq %%mm6, 48(%2)\n"
30220+ " movq 56(%1), %%mm7\n"
30221+ " movntq %%mm7, 56(%2)\n"
30222 ".section .fixup, \"ax\"\n"
30223- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30224+ "3:\n"
30225+
30226+#ifdef CONFIG_PAX_KERNEXEC
30227+ " movl %%cr0, %0\n"
30228+ " movl %0, %%eax\n"
30229+ " andl $0xFFFEFFFF, %%eax\n"
30230+ " movl %%eax, %%cr0\n"
30231+#endif
30232+
30233+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30234+
30235+#ifdef CONFIG_PAX_KERNEXEC
30236+ " movl %0, %%cr0\n"
30237+#endif
30238+
30239 " jmp 2b\n"
30240 ".previous\n"
30241- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30242+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30243
30244 from += 64;
30245 to += 64;
30246@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30247 static void fast_copy_page(void *to, void *from)
30248 {
30249 int i;
30250+ unsigned long cr0;
30251
30252 kernel_fpu_begin();
30253
30254 __asm__ __volatile__ (
30255- "1: prefetch (%0)\n"
30256- " prefetch 64(%0)\n"
30257- " prefetch 128(%0)\n"
30258- " prefetch 192(%0)\n"
30259- " prefetch 256(%0)\n"
30260+ "1: prefetch (%1)\n"
30261+ " prefetch 64(%1)\n"
30262+ " prefetch 128(%1)\n"
30263+ " prefetch 192(%1)\n"
30264+ " prefetch 256(%1)\n"
30265 "2: \n"
30266 ".section .fixup, \"ax\"\n"
30267- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30268+ "3: \n"
30269+
30270+#ifdef CONFIG_PAX_KERNEXEC
30271+ " movl %%cr0, %0\n"
30272+ " movl %0, %%eax\n"
30273+ " andl $0xFFFEFFFF, %%eax\n"
30274+ " movl %%eax, %%cr0\n"
30275+#endif
30276+
30277+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30278+
30279+#ifdef CONFIG_PAX_KERNEXEC
30280+ " movl %0, %%cr0\n"
30281+#endif
30282+
30283 " jmp 2b\n"
30284 ".previous\n"
30285- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30286+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30287
30288 for (i = 0; i < 4096/64; i++) {
30289 __asm__ __volatile__ (
30290- "1: prefetch 320(%0)\n"
30291- "2: movq (%0), %%mm0\n"
30292- " movq 8(%0), %%mm1\n"
30293- " movq 16(%0), %%mm2\n"
30294- " movq 24(%0), %%mm3\n"
30295- " movq %%mm0, (%1)\n"
30296- " movq %%mm1, 8(%1)\n"
30297- " movq %%mm2, 16(%1)\n"
30298- " movq %%mm3, 24(%1)\n"
30299- " movq 32(%0), %%mm0\n"
30300- " movq 40(%0), %%mm1\n"
30301- " movq 48(%0), %%mm2\n"
30302- " movq 56(%0), %%mm3\n"
30303- " movq %%mm0, 32(%1)\n"
30304- " movq %%mm1, 40(%1)\n"
30305- " movq %%mm2, 48(%1)\n"
30306- " movq %%mm3, 56(%1)\n"
30307+ "1: prefetch 320(%1)\n"
30308+ "2: movq (%1), %%mm0\n"
30309+ " movq 8(%1), %%mm1\n"
30310+ " movq 16(%1), %%mm2\n"
30311+ " movq 24(%1), %%mm3\n"
30312+ " movq %%mm0, (%2)\n"
30313+ " movq %%mm1, 8(%2)\n"
30314+ " movq %%mm2, 16(%2)\n"
30315+ " movq %%mm3, 24(%2)\n"
30316+ " movq 32(%1), %%mm0\n"
30317+ " movq 40(%1), %%mm1\n"
30318+ " movq 48(%1), %%mm2\n"
30319+ " movq 56(%1), %%mm3\n"
30320+ " movq %%mm0, 32(%2)\n"
30321+ " movq %%mm1, 40(%2)\n"
30322+ " movq %%mm2, 48(%2)\n"
30323+ " movq %%mm3, 56(%2)\n"
30324 ".section .fixup, \"ax\"\n"
30325- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30326+ "3:\n"
30327+
30328+#ifdef CONFIG_PAX_KERNEXEC
30329+ " movl %%cr0, %0\n"
30330+ " movl %0, %%eax\n"
30331+ " andl $0xFFFEFFFF, %%eax\n"
30332+ " movl %%eax, %%cr0\n"
30333+#endif
30334+
30335+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30336+
30337+#ifdef CONFIG_PAX_KERNEXEC
30338+ " movl %0, %%cr0\n"
30339+#endif
30340+
30341 " jmp 2b\n"
30342 ".previous\n"
30343 _ASM_EXTABLE(1b, 3b)
30344- : : "r" (from), "r" (to) : "memory");
30345+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30346
30347 from += 64;
30348 to += 64;
30349diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30350index f6d13ee..d789440 100644
30351--- a/arch/x86/lib/msr-reg.S
30352+++ b/arch/x86/lib/msr-reg.S
30353@@ -3,6 +3,7 @@
30354 #include <asm/dwarf2.h>
30355 #include <asm/asm.h>
30356 #include <asm/msr.h>
30357+#include <asm/alternative-asm.h>
30358
30359 #ifdef CONFIG_X86_64
30360 /*
30361@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30362 movl %edi, 28(%r10)
30363 popq_cfi %rbp
30364 popq_cfi %rbx
30365+ pax_force_retaddr
30366 ret
30367 3:
30368 CFI_RESTORE_STATE
30369diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30370index fc6ba17..d4d989d 100644
30371--- a/arch/x86/lib/putuser.S
30372+++ b/arch/x86/lib/putuser.S
30373@@ -16,7 +16,9 @@
30374 #include <asm/errno.h>
30375 #include <asm/asm.h>
30376 #include <asm/smap.h>
30377-
30378+#include <asm/segment.h>
30379+#include <asm/pgtable.h>
30380+#include <asm/alternative-asm.h>
30381
30382 /*
30383 * __put_user_X
30384@@ -30,57 +32,125 @@
30385 * as they get called from within inline assembly.
30386 */
30387
30388-#define ENTER CFI_STARTPROC ; \
30389- GET_THREAD_INFO(%_ASM_BX)
30390-#define EXIT ASM_CLAC ; \
30391- ret ; \
30392+#define ENTER CFI_STARTPROC
30393+#define EXIT ASM_CLAC ; \
30394+ pax_force_retaddr ; \
30395+ ret ; \
30396 CFI_ENDPROC
30397
30398+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30399+#define _DEST %_ASM_CX,%_ASM_BX
30400+#else
30401+#define _DEST %_ASM_CX
30402+#endif
30403+
30404+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30405+#define __copyuser_seg gs;
30406+#else
30407+#define __copyuser_seg
30408+#endif
30409+
30410 .text
30411 ENTRY(__put_user_1)
30412 ENTER
30413+
30414+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30415+ GET_THREAD_INFO(%_ASM_BX)
30416 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30417 jae bad_put_user
30418 ASM_STAC
30419-1: movb %al,(%_ASM_CX)
30420+
30421+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30422+ mov pax_user_shadow_base,%_ASM_BX
30423+ cmp %_ASM_BX,%_ASM_CX
30424+ jb 1234f
30425+ xor %ebx,%ebx
30426+1234:
30427+#endif
30428+
30429+#endif
30430+
30431+1: __copyuser_seg movb %al,(_DEST)
30432 xor %eax,%eax
30433 EXIT
30434 ENDPROC(__put_user_1)
30435
30436 ENTRY(__put_user_2)
30437 ENTER
30438+
30439+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30440+ GET_THREAD_INFO(%_ASM_BX)
30441 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30442 sub $1,%_ASM_BX
30443 cmp %_ASM_BX,%_ASM_CX
30444 jae bad_put_user
30445 ASM_STAC
30446-2: movw %ax,(%_ASM_CX)
30447+
30448+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30449+ mov pax_user_shadow_base,%_ASM_BX
30450+ cmp %_ASM_BX,%_ASM_CX
30451+ jb 1234f
30452+ xor %ebx,%ebx
30453+1234:
30454+#endif
30455+
30456+#endif
30457+
30458+2: __copyuser_seg movw %ax,(_DEST)
30459 xor %eax,%eax
30460 EXIT
30461 ENDPROC(__put_user_2)
30462
30463 ENTRY(__put_user_4)
30464 ENTER
30465+
30466+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30467+ GET_THREAD_INFO(%_ASM_BX)
30468 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30469 sub $3,%_ASM_BX
30470 cmp %_ASM_BX,%_ASM_CX
30471 jae bad_put_user
30472 ASM_STAC
30473-3: movl %eax,(%_ASM_CX)
30474+
30475+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30476+ mov pax_user_shadow_base,%_ASM_BX
30477+ cmp %_ASM_BX,%_ASM_CX
30478+ jb 1234f
30479+ xor %ebx,%ebx
30480+1234:
30481+#endif
30482+
30483+#endif
30484+
30485+3: __copyuser_seg movl %eax,(_DEST)
30486 xor %eax,%eax
30487 EXIT
30488 ENDPROC(__put_user_4)
30489
30490 ENTRY(__put_user_8)
30491 ENTER
30492+
30493+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30494+ GET_THREAD_INFO(%_ASM_BX)
30495 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30496 sub $7,%_ASM_BX
30497 cmp %_ASM_BX,%_ASM_CX
30498 jae bad_put_user
30499 ASM_STAC
30500-4: mov %_ASM_AX,(%_ASM_CX)
30501+
30502+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30503+ mov pax_user_shadow_base,%_ASM_BX
30504+ cmp %_ASM_BX,%_ASM_CX
30505+ jb 1234f
30506+ xor %ebx,%ebx
30507+1234:
30508+#endif
30509+
30510+#endif
30511+
30512+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30513 #ifdef CONFIG_X86_32
30514-5: movl %edx,4(%_ASM_CX)
30515+5: __copyuser_seg movl %edx,4(_DEST)
30516 #endif
30517 xor %eax,%eax
30518 EXIT
30519diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30520index 1cad221..de671ee 100644
30521--- a/arch/x86/lib/rwlock.S
30522+++ b/arch/x86/lib/rwlock.S
30523@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30524 FRAME
30525 0: LOCK_PREFIX
30526 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30527+
30528+#ifdef CONFIG_PAX_REFCOUNT
30529+ jno 1234f
30530+ LOCK_PREFIX
30531+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30532+ int $4
30533+1234:
30534+ _ASM_EXTABLE(1234b, 1234b)
30535+#endif
30536+
30537 1: rep; nop
30538 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30539 jne 1b
30540 LOCK_PREFIX
30541 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30542+
30543+#ifdef CONFIG_PAX_REFCOUNT
30544+ jno 1234f
30545+ LOCK_PREFIX
30546+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30547+ int $4
30548+1234:
30549+ _ASM_EXTABLE(1234b, 1234b)
30550+#endif
30551+
30552 jnz 0b
30553 ENDFRAME
30554+ pax_force_retaddr
30555 ret
30556 CFI_ENDPROC
30557 END(__write_lock_failed)
30558@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30559 FRAME
30560 0: LOCK_PREFIX
30561 READ_LOCK_SIZE(inc) (%__lock_ptr)
30562+
30563+#ifdef CONFIG_PAX_REFCOUNT
30564+ jno 1234f
30565+ LOCK_PREFIX
30566+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30567+ int $4
30568+1234:
30569+ _ASM_EXTABLE(1234b, 1234b)
30570+#endif
30571+
30572 1: rep; nop
30573 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30574 js 1b
30575 LOCK_PREFIX
30576 READ_LOCK_SIZE(dec) (%__lock_ptr)
30577+
30578+#ifdef CONFIG_PAX_REFCOUNT
30579+ jno 1234f
30580+ LOCK_PREFIX
30581+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30582+ int $4
30583+1234:
30584+ _ASM_EXTABLE(1234b, 1234b)
30585+#endif
30586+
30587 js 0b
30588 ENDFRAME
30589+ pax_force_retaddr
30590 ret
30591 CFI_ENDPROC
30592 END(__read_lock_failed)
30593diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30594index 5dff5f0..cadebf4 100644
30595--- a/arch/x86/lib/rwsem.S
30596+++ b/arch/x86/lib/rwsem.S
30597@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30598 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30599 CFI_RESTORE __ASM_REG(dx)
30600 restore_common_regs
30601+ pax_force_retaddr
30602 ret
30603 CFI_ENDPROC
30604 ENDPROC(call_rwsem_down_read_failed)
30605@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30606 movq %rax,%rdi
30607 call rwsem_down_write_failed
30608 restore_common_regs
30609+ pax_force_retaddr
30610 ret
30611 CFI_ENDPROC
30612 ENDPROC(call_rwsem_down_write_failed)
30613@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30614 movq %rax,%rdi
30615 call rwsem_wake
30616 restore_common_regs
30617-1: ret
30618+1: pax_force_retaddr
30619+ ret
30620 CFI_ENDPROC
30621 ENDPROC(call_rwsem_wake)
30622
30623@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30624 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30625 CFI_RESTORE __ASM_REG(dx)
30626 restore_common_regs
30627+ pax_force_retaddr
30628 ret
30629 CFI_ENDPROC
30630 ENDPROC(call_rwsem_downgrade_wake)
30631diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30632index a63efd6..8149fbe 100644
30633--- a/arch/x86/lib/thunk_64.S
30634+++ b/arch/x86/lib/thunk_64.S
30635@@ -8,6 +8,7 @@
30636 #include <linux/linkage.h>
30637 #include <asm/dwarf2.h>
30638 #include <asm/calling.h>
30639+#include <asm/alternative-asm.h>
30640
30641 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30642 .macro THUNK name, func, put_ret_addr_in_rdi=0
30643@@ -15,11 +16,11 @@
30644 \name:
30645 CFI_STARTPROC
30646
30647- /* this one pushes 9 elems, the next one would be %rIP */
30648- SAVE_ARGS
30649+ /* this one pushes 15+1 elems, the next one would be %rIP */
30650+ SAVE_ARGS 8
30651
30652 .if \put_ret_addr_in_rdi
30653- movq_cfi_restore 9*8, rdi
30654+ movq_cfi_restore RIP, rdi
30655 .endif
30656
30657 call \func
30658@@ -38,8 +39,9 @@
30659
30660 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30661 CFI_STARTPROC
30662- SAVE_ARGS
30663+ SAVE_ARGS 8
30664 restore:
30665- RESTORE_ARGS
30666+ RESTORE_ARGS 1,8
30667+ pax_force_retaddr
30668 ret
30669 CFI_ENDPROC
30670diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30671index e2f5e21..4b22130 100644
30672--- a/arch/x86/lib/usercopy_32.c
30673+++ b/arch/x86/lib/usercopy_32.c
30674@@ -42,11 +42,13 @@ do { \
30675 int __d0; \
30676 might_fault(); \
30677 __asm__ __volatile__( \
30678+ __COPYUSER_SET_ES \
30679 ASM_STAC "\n" \
30680 "0: rep; stosl\n" \
30681 " movl %2,%0\n" \
30682 "1: rep; stosb\n" \
30683 "2: " ASM_CLAC "\n" \
30684+ __COPYUSER_RESTORE_ES \
30685 ".section .fixup,\"ax\"\n" \
30686 "3: lea 0(%2,%0,4),%0\n" \
30687 " jmp 2b\n" \
30688@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30689
30690 #ifdef CONFIG_X86_INTEL_USERCOPY
30691 static unsigned long
30692-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30693+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30694 {
30695 int d0, d1;
30696 __asm__ __volatile__(
30697@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30698 " .align 2,0x90\n"
30699 "3: movl 0(%4), %%eax\n"
30700 "4: movl 4(%4), %%edx\n"
30701- "5: movl %%eax, 0(%3)\n"
30702- "6: movl %%edx, 4(%3)\n"
30703+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30704+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30705 "7: movl 8(%4), %%eax\n"
30706 "8: movl 12(%4),%%edx\n"
30707- "9: movl %%eax, 8(%3)\n"
30708- "10: movl %%edx, 12(%3)\n"
30709+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30710+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30711 "11: movl 16(%4), %%eax\n"
30712 "12: movl 20(%4), %%edx\n"
30713- "13: movl %%eax, 16(%3)\n"
30714- "14: movl %%edx, 20(%3)\n"
30715+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30716+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30717 "15: movl 24(%4), %%eax\n"
30718 "16: movl 28(%4), %%edx\n"
30719- "17: movl %%eax, 24(%3)\n"
30720- "18: movl %%edx, 28(%3)\n"
30721+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30722+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30723 "19: movl 32(%4), %%eax\n"
30724 "20: movl 36(%4), %%edx\n"
30725- "21: movl %%eax, 32(%3)\n"
30726- "22: movl %%edx, 36(%3)\n"
30727+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30728+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30729 "23: movl 40(%4), %%eax\n"
30730 "24: movl 44(%4), %%edx\n"
30731- "25: movl %%eax, 40(%3)\n"
30732- "26: movl %%edx, 44(%3)\n"
30733+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30734+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30735 "27: movl 48(%4), %%eax\n"
30736 "28: movl 52(%4), %%edx\n"
30737- "29: movl %%eax, 48(%3)\n"
30738- "30: movl %%edx, 52(%3)\n"
30739+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30740+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30741 "31: movl 56(%4), %%eax\n"
30742 "32: movl 60(%4), %%edx\n"
30743- "33: movl %%eax, 56(%3)\n"
30744- "34: movl %%edx, 60(%3)\n"
30745+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30746+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30747 " addl $-64, %0\n"
30748 " addl $64, %4\n"
30749 " addl $64, %3\n"
30750@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30751 " shrl $2, %0\n"
30752 " andl $3, %%eax\n"
30753 " cld\n"
30754+ __COPYUSER_SET_ES
30755 "99: rep; movsl\n"
30756 "36: movl %%eax, %0\n"
30757 "37: rep; movsb\n"
30758 "100:\n"
30759+ __COPYUSER_RESTORE_ES
30760+ ".section .fixup,\"ax\"\n"
30761+ "101: lea 0(%%eax,%0,4),%0\n"
30762+ " jmp 100b\n"
30763+ ".previous\n"
30764+ _ASM_EXTABLE(1b,100b)
30765+ _ASM_EXTABLE(2b,100b)
30766+ _ASM_EXTABLE(3b,100b)
30767+ _ASM_EXTABLE(4b,100b)
30768+ _ASM_EXTABLE(5b,100b)
30769+ _ASM_EXTABLE(6b,100b)
30770+ _ASM_EXTABLE(7b,100b)
30771+ _ASM_EXTABLE(8b,100b)
30772+ _ASM_EXTABLE(9b,100b)
30773+ _ASM_EXTABLE(10b,100b)
30774+ _ASM_EXTABLE(11b,100b)
30775+ _ASM_EXTABLE(12b,100b)
30776+ _ASM_EXTABLE(13b,100b)
30777+ _ASM_EXTABLE(14b,100b)
30778+ _ASM_EXTABLE(15b,100b)
30779+ _ASM_EXTABLE(16b,100b)
30780+ _ASM_EXTABLE(17b,100b)
30781+ _ASM_EXTABLE(18b,100b)
30782+ _ASM_EXTABLE(19b,100b)
30783+ _ASM_EXTABLE(20b,100b)
30784+ _ASM_EXTABLE(21b,100b)
30785+ _ASM_EXTABLE(22b,100b)
30786+ _ASM_EXTABLE(23b,100b)
30787+ _ASM_EXTABLE(24b,100b)
30788+ _ASM_EXTABLE(25b,100b)
30789+ _ASM_EXTABLE(26b,100b)
30790+ _ASM_EXTABLE(27b,100b)
30791+ _ASM_EXTABLE(28b,100b)
30792+ _ASM_EXTABLE(29b,100b)
30793+ _ASM_EXTABLE(30b,100b)
30794+ _ASM_EXTABLE(31b,100b)
30795+ _ASM_EXTABLE(32b,100b)
30796+ _ASM_EXTABLE(33b,100b)
30797+ _ASM_EXTABLE(34b,100b)
30798+ _ASM_EXTABLE(35b,100b)
30799+ _ASM_EXTABLE(36b,100b)
30800+ _ASM_EXTABLE(37b,100b)
30801+ _ASM_EXTABLE(99b,101b)
30802+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30803+ : "1"(to), "2"(from), "0"(size)
30804+ : "eax", "edx", "memory");
30805+ return size;
30806+}
30807+
30808+static unsigned long
30809+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30810+{
30811+ int d0, d1;
30812+ __asm__ __volatile__(
30813+ " .align 2,0x90\n"
30814+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30815+ " cmpl $67, %0\n"
30816+ " jbe 3f\n"
30817+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30818+ " .align 2,0x90\n"
30819+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30820+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30821+ "5: movl %%eax, 0(%3)\n"
30822+ "6: movl %%edx, 4(%3)\n"
30823+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30824+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30825+ "9: movl %%eax, 8(%3)\n"
30826+ "10: movl %%edx, 12(%3)\n"
30827+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30828+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30829+ "13: movl %%eax, 16(%3)\n"
30830+ "14: movl %%edx, 20(%3)\n"
30831+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30832+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30833+ "17: movl %%eax, 24(%3)\n"
30834+ "18: movl %%edx, 28(%3)\n"
30835+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30836+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30837+ "21: movl %%eax, 32(%3)\n"
30838+ "22: movl %%edx, 36(%3)\n"
30839+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30840+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30841+ "25: movl %%eax, 40(%3)\n"
30842+ "26: movl %%edx, 44(%3)\n"
30843+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30844+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30845+ "29: movl %%eax, 48(%3)\n"
30846+ "30: movl %%edx, 52(%3)\n"
30847+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30848+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30849+ "33: movl %%eax, 56(%3)\n"
30850+ "34: movl %%edx, 60(%3)\n"
30851+ " addl $-64, %0\n"
30852+ " addl $64, %4\n"
30853+ " addl $64, %3\n"
30854+ " cmpl $63, %0\n"
30855+ " ja 1b\n"
30856+ "35: movl %0, %%eax\n"
30857+ " shrl $2, %0\n"
30858+ " andl $3, %%eax\n"
30859+ " cld\n"
30860+ "99: rep; "__copyuser_seg" movsl\n"
30861+ "36: movl %%eax, %0\n"
30862+ "37: rep; "__copyuser_seg" movsb\n"
30863+ "100:\n"
30864 ".section .fixup,\"ax\"\n"
30865 "101: lea 0(%%eax,%0,4),%0\n"
30866 " jmp 100b\n"
30867@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30868 int d0, d1;
30869 __asm__ __volatile__(
30870 " .align 2,0x90\n"
30871- "0: movl 32(%4), %%eax\n"
30872+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30873 " cmpl $67, %0\n"
30874 " jbe 2f\n"
30875- "1: movl 64(%4), %%eax\n"
30876+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30877 " .align 2,0x90\n"
30878- "2: movl 0(%4), %%eax\n"
30879- "21: movl 4(%4), %%edx\n"
30880+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30881+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30882 " movl %%eax, 0(%3)\n"
30883 " movl %%edx, 4(%3)\n"
30884- "3: movl 8(%4), %%eax\n"
30885- "31: movl 12(%4),%%edx\n"
30886+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30887+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30888 " movl %%eax, 8(%3)\n"
30889 " movl %%edx, 12(%3)\n"
30890- "4: movl 16(%4), %%eax\n"
30891- "41: movl 20(%4), %%edx\n"
30892+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30893+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30894 " movl %%eax, 16(%3)\n"
30895 " movl %%edx, 20(%3)\n"
30896- "10: movl 24(%4), %%eax\n"
30897- "51: movl 28(%4), %%edx\n"
30898+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30899+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30900 " movl %%eax, 24(%3)\n"
30901 " movl %%edx, 28(%3)\n"
30902- "11: movl 32(%4), %%eax\n"
30903- "61: movl 36(%4), %%edx\n"
30904+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30905+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30906 " movl %%eax, 32(%3)\n"
30907 " movl %%edx, 36(%3)\n"
30908- "12: movl 40(%4), %%eax\n"
30909- "71: movl 44(%4), %%edx\n"
30910+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30911+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30912 " movl %%eax, 40(%3)\n"
30913 " movl %%edx, 44(%3)\n"
30914- "13: movl 48(%4), %%eax\n"
30915- "81: movl 52(%4), %%edx\n"
30916+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30917+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30918 " movl %%eax, 48(%3)\n"
30919 " movl %%edx, 52(%3)\n"
30920- "14: movl 56(%4), %%eax\n"
30921- "91: movl 60(%4), %%edx\n"
30922+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30923+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30924 " movl %%eax, 56(%3)\n"
30925 " movl %%edx, 60(%3)\n"
30926 " addl $-64, %0\n"
30927@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30928 " shrl $2, %0\n"
30929 " andl $3, %%eax\n"
30930 " cld\n"
30931- "6: rep; movsl\n"
30932+ "6: rep; "__copyuser_seg" movsl\n"
30933 " movl %%eax,%0\n"
30934- "7: rep; movsb\n"
30935+ "7: rep; "__copyuser_seg" movsb\n"
30936 "8:\n"
30937 ".section .fixup,\"ax\"\n"
30938 "9: lea 0(%%eax,%0,4),%0\n"
30939@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30940
30941 __asm__ __volatile__(
30942 " .align 2,0x90\n"
30943- "0: movl 32(%4), %%eax\n"
30944+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30945 " cmpl $67, %0\n"
30946 " jbe 2f\n"
30947- "1: movl 64(%4), %%eax\n"
30948+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30949 " .align 2,0x90\n"
30950- "2: movl 0(%4), %%eax\n"
30951- "21: movl 4(%4), %%edx\n"
30952+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30953+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30954 " movnti %%eax, 0(%3)\n"
30955 " movnti %%edx, 4(%3)\n"
30956- "3: movl 8(%4), %%eax\n"
30957- "31: movl 12(%4),%%edx\n"
30958+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30959+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30960 " movnti %%eax, 8(%3)\n"
30961 " movnti %%edx, 12(%3)\n"
30962- "4: movl 16(%4), %%eax\n"
30963- "41: movl 20(%4), %%edx\n"
30964+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30965+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30966 " movnti %%eax, 16(%3)\n"
30967 " movnti %%edx, 20(%3)\n"
30968- "10: movl 24(%4), %%eax\n"
30969- "51: movl 28(%4), %%edx\n"
30970+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30971+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30972 " movnti %%eax, 24(%3)\n"
30973 " movnti %%edx, 28(%3)\n"
30974- "11: movl 32(%4), %%eax\n"
30975- "61: movl 36(%4), %%edx\n"
30976+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30977+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30978 " movnti %%eax, 32(%3)\n"
30979 " movnti %%edx, 36(%3)\n"
30980- "12: movl 40(%4), %%eax\n"
30981- "71: movl 44(%4), %%edx\n"
30982+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30983+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30984 " movnti %%eax, 40(%3)\n"
30985 " movnti %%edx, 44(%3)\n"
30986- "13: movl 48(%4), %%eax\n"
30987- "81: movl 52(%4), %%edx\n"
30988+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30989+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30990 " movnti %%eax, 48(%3)\n"
30991 " movnti %%edx, 52(%3)\n"
30992- "14: movl 56(%4), %%eax\n"
30993- "91: movl 60(%4), %%edx\n"
30994+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30995+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30996 " movnti %%eax, 56(%3)\n"
30997 " movnti %%edx, 60(%3)\n"
30998 " addl $-64, %0\n"
30999@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31000 " shrl $2, %0\n"
31001 " andl $3, %%eax\n"
31002 " cld\n"
31003- "6: rep; movsl\n"
31004+ "6: rep; "__copyuser_seg" movsl\n"
31005 " movl %%eax,%0\n"
31006- "7: rep; movsb\n"
31007+ "7: rep; "__copyuser_seg" movsb\n"
31008 "8:\n"
31009 ".section .fixup,\"ax\"\n"
31010 "9: lea 0(%%eax,%0,4),%0\n"
31011@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31012
31013 __asm__ __volatile__(
31014 " .align 2,0x90\n"
31015- "0: movl 32(%4), %%eax\n"
31016+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31017 " cmpl $67, %0\n"
31018 " jbe 2f\n"
31019- "1: movl 64(%4), %%eax\n"
31020+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31021 " .align 2,0x90\n"
31022- "2: movl 0(%4), %%eax\n"
31023- "21: movl 4(%4), %%edx\n"
31024+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31025+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31026 " movnti %%eax, 0(%3)\n"
31027 " movnti %%edx, 4(%3)\n"
31028- "3: movl 8(%4), %%eax\n"
31029- "31: movl 12(%4),%%edx\n"
31030+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31031+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31032 " movnti %%eax, 8(%3)\n"
31033 " movnti %%edx, 12(%3)\n"
31034- "4: movl 16(%4), %%eax\n"
31035- "41: movl 20(%4), %%edx\n"
31036+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31037+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31038 " movnti %%eax, 16(%3)\n"
31039 " movnti %%edx, 20(%3)\n"
31040- "10: movl 24(%4), %%eax\n"
31041- "51: movl 28(%4), %%edx\n"
31042+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31043+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31044 " movnti %%eax, 24(%3)\n"
31045 " movnti %%edx, 28(%3)\n"
31046- "11: movl 32(%4), %%eax\n"
31047- "61: movl 36(%4), %%edx\n"
31048+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31049+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31050 " movnti %%eax, 32(%3)\n"
31051 " movnti %%edx, 36(%3)\n"
31052- "12: movl 40(%4), %%eax\n"
31053- "71: movl 44(%4), %%edx\n"
31054+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31055+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31056 " movnti %%eax, 40(%3)\n"
31057 " movnti %%edx, 44(%3)\n"
31058- "13: movl 48(%4), %%eax\n"
31059- "81: movl 52(%4), %%edx\n"
31060+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31061+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31062 " movnti %%eax, 48(%3)\n"
31063 " movnti %%edx, 52(%3)\n"
31064- "14: movl 56(%4), %%eax\n"
31065- "91: movl 60(%4), %%edx\n"
31066+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31067+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31068 " movnti %%eax, 56(%3)\n"
31069 " movnti %%edx, 60(%3)\n"
31070 " addl $-64, %0\n"
31071@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31072 " shrl $2, %0\n"
31073 " andl $3, %%eax\n"
31074 " cld\n"
31075- "6: rep; movsl\n"
31076+ "6: rep; "__copyuser_seg" movsl\n"
31077 " movl %%eax,%0\n"
31078- "7: rep; movsb\n"
31079+ "7: rep; "__copyuser_seg" movsb\n"
31080 "8:\n"
31081 ".section .fixup,\"ax\"\n"
31082 "9: lea 0(%%eax,%0,4),%0\n"
31083@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31084 */
31085 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31086 unsigned long size);
31087-unsigned long __copy_user_intel(void __user *to, const void *from,
31088+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31089+ unsigned long size);
31090+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31091 unsigned long size);
31092 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31093 const void __user *from, unsigned long size);
31094 #endif /* CONFIG_X86_INTEL_USERCOPY */
31095
31096 /* Generic arbitrary sized copy. */
31097-#define __copy_user(to, from, size) \
31098+#define __copy_user(to, from, size, prefix, set, restore) \
31099 do { \
31100 int __d0, __d1, __d2; \
31101 __asm__ __volatile__( \
31102+ set \
31103 " cmp $7,%0\n" \
31104 " jbe 1f\n" \
31105 " movl %1,%0\n" \
31106 " negl %0\n" \
31107 " andl $7,%0\n" \
31108 " subl %0,%3\n" \
31109- "4: rep; movsb\n" \
31110+ "4: rep; "prefix"movsb\n" \
31111 " movl %3,%0\n" \
31112 " shrl $2,%0\n" \
31113 " andl $3,%3\n" \
31114 " .align 2,0x90\n" \
31115- "0: rep; movsl\n" \
31116+ "0: rep; "prefix"movsl\n" \
31117 " movl %3,%0\n" \
31118- "1: rep; movsb\n" \
31119+ "1: rep; "prefix"movsb\n" \
31120 "2:\n" \
31121+ restore \
31122 ".section .fixup,\"ax\"\n" \
31123 "5: addl %3,%0\n" \
31124 " jmp 2b\n" \
31125@@ -538,14 +650,14 @@ do { \
31126 " negl %0\n" \
31127 " andl $7,%0\n" \
31128 " subl %0,%3\n" \
31129- "4: rep; movsb\n" \
31130+ "4: rep; "__copyuser_seg"movsb\n" \
31131 " movl %3,%0\n" \
31132 " shrl $2,%0\n" \
31133 " andl $3,%3\n" \
31134 " .align 2,0x90\n" \
31135- "0: rep; movsl\n" \
31136+ "0: rep; "__copyuser_seg"movsl\n" \
31137 " movl %3,%0\n" \
31138- "1: rep; movsb\n" \
31139+ "1: rep; "__copyuser_seg"movsb\n" \
31140 "2:\n" \
31141 ".section .fixup,\"ax\"\n" \
31142 "5: addl %3,%0\n" \
31143@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31144 {
31145 stac();
31146 if (movsl_is_ok(to, from, n))
31147- __copy_user(to, from, n);
31148+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31149 else
31150- n = __copy_user_intel(to, from, n);
31151+ n = __generic_copy_to_user_intel(to, from, n);
31152 clac();
31153 return n;
31154 }
31155@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31156 {
31157 stac();
31158 if (movsl_is_ok(to, from, n))
31159- __copy_user(to, from, n);
31160+ __copy_user(to, from, n, __copyuser_seg, "", "");
31161 else
31162- n = __copy_user_intel((void __user *)to,
31163- (const void *)from, n);
31164+ n = __generic_copy_from_user_intel(to, from, n);
31165 clac();
31166 return n;
31167 }
31168@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31169 if (n > 64 && cpu_has_xmm2)
31170 n = __copy_user_intel_nocache(to, from, n);
31171 else
31172- __copy_user(to, from, n);
31173+ __copy_user(to, from, n, __copyuser_seg, "", "");
31174 #else
31175- __copy_user(to, from, n);
31176+ __copy_user(to, from, n, __copyuser_seg, "", "");
31177 #endif
31178 clac();
31179 return n;
31180 }
31181 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31182
31183-/**
31184- * copy_to_user: - Copy a block of data into user space.
31185- * @to: Destination address, in user space.
31186- * @from: Source address, in kernel space.
31187- * @n: Number of bytes to copy.
31188- *
31189- * Context: User context only. This function may sleep.
31190- *
31191- * Copy data from kernel space to user space.
31192- *
31193- * Returns number of bytes that could not be copied.
31194- * On success, this will be zero.
31195- */
31196-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31197+#ifdef CONFIG_PAX_MEMORY_UDEREF
31198+void __set_fs(mm_segment_t x)
31199 {
31200- if (access_ok(VERIFY_WRITE, to, n))
31201- n = __copy_to_user(to, from, n);
31202- return n;
31203+ switch (x.seg) {
31204+ case 0:
31205+ loadsegment(gs, 0);
31206+ break;
31207+ case TASK_SIZE_MAX:
31208+ loadsegment(gs, __USER_DS);
31209+ break;
31210+ case -1UL:
31211+ loadsegment(gs, __KERNEL_DS);
31212+ break;
31213+ default:
31214+ BUG();
31215+ }
31216 }
31217-EXPORT_SYMBOL(_copy_to_user);
31218+EXPORT_SYMBOL(__set_fs);
31219
31220-/**
31221- * copy_from_user: - Copy a block of data from user space.
31222- * @to: Destination address, in kernel space.
31223- * @from: Source address, in user space.
31224- * @n: Number of bytes to copy.
31225- *
31226- * Context: User context only. This function may sleep.
31227- *
31228- * Copy data from user space to kernel space.
31229- *
31230- * Returns number of bytes that could not be copied.
31231- * On success, this will be zero.
31232- *
31233- * If some data could not be copied, this function will pad the copied
31234- * data to the requested size using zero bytes.
31235- */
31236-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31237+void set_fs(mm_segment_t x)
31238 {
31239- if (access_ok(VERIFY_READ, from, n))
31240- n = __copy_from_user(to, from, n);
31241- else
31242- memset(to, 0, n);
31243- return n;
31244+ current_thread_info()->addr_limit = x;
31245+ __set_fs(x);
31246 }
31247-EXPORT_SYMBOL(_copy_from_user);
31248+EXPORT_SYMBOL(set_fs);
31249+#endif
31250diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31251index c905e89..01ab928 100644
31252--- a/arch/x86/lib/usercopy_64.c
31253+++ b/arch/x86/lib/usercopy_64.c
31254@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31255 might_fault();
31256 /* no memory constraint because it doesn't change any memory gcc knows
31257 about */
31258+ pax_open_userland();
31259 stac();
31260 asm volatile(
31261 " testq %[size8],%[size8]\n"
31262@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31263 _ASM_EXTABLE(0b,3b)
31264 _ASM_EXTABLE(1b,2b)
31265 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31266- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31267+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31268 [zero] "r" (0UL), [eight] "r" (8UL));
31269 clac();
31270+ pax_close_userland();
31271 return size;
31272 }
31273 EXPORT_SYMBOL(__clear_user);
31274@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31275 }
31276 EXPORT_SYMBOL(clear_user);
31277
31278-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31279+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31280 {
31281- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31282- return copy_user_generic((__force void *)to, (__force void *)from, len);
31283- }
31284- return len;
31285+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31286+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31287+ return len;
31288 }
31289 EXPORT_SYMBOL(copy_in_user);
31290
31291@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31292 * it is not necessary to optimize tail handling.
31293 */
31294 __visible unsigned long
31295-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31296+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31297 {
31298 char c;
31299 unsigned zero_len;
31300
31301+ clac();
31302+ pax_close_userland();
31303 for (; len; --len, to++) {
31304 if (__get_user_nocheck(c, from++, sizeof(char)))
31305 break;
31306@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31307 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31308 if (__put_user_nocheck(c, to++, sizeof(char)))
31309 break;
31310- clac();
31311 return len;
31312 }
31313diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31314index 6a19ad9..1c48f9a 100644
31315--- a/arch/x86/mm/Makefile
31316+++ b/arch/x86/mm/Makefile
31317@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31318 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31319
31320 obj-$(CONFIG_MEMTEST) += memtest.o
31321+
31322+quote:="
31323+obj-$(CONFIG_X86_64) += uderef_64.o
31324+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31325diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31326index 903ec1e..c4166b2 100644
31327--- a/arch/x86/mm/extable.c
31328+++ b/arch/x86/mm/extable.c
31329@@ -6,12 +6,24 @@
31330 static inline unsigned long
31331 ex_insn_addr(const struct exception_table_entry *x)
31332 {
31333- return (unsigned long)&x->insn + x->insn;
31334+ unsigned long reloc = 0;
31335+
31336+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31337+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31338+#endif
31339+
31340+ return (unsigned long)&x->insn + x->insn + reloc;
31341 }
31342 static inline unsigned long
31343 ex_fixup_addr(const struct exception_table_entry *x)
31344 {
31345- return (unsigned long)&x->fixup + x->fixup;
31346+ unsigned long reloc = 0;
31347+
31348+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31349+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31350+#endif
31351+
31352+ return (unsigned long)&x->fixup + x->fixup + reloc;
31353 }
31354
31355 int fixup_exception(struct pt_regs *regs)
31356@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31357 unsigned long new_ip;
31358
31359 #ifdef CONFIG_PNPBIOS
31360- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31361+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31362 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31363 extern u32 pnp_bios_is_utter_crap;
31364 pnp_bios_is_utter_crap = 1;
31365@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31366 i += 4;
31367 p->fixup -= i;
31368 i += 4;
31369+
31370+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31371+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31372+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31373+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31374+#endif
31375+
31376 }
31377 }
31378
31379diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31380index 8e57229..31cce89 100644
31381--- a/arch/x86/mm/fault.c
31382+++ b/arch/x86/mm/fault.c
31383@@ -14,11 +14,18 @@
31384 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31385 #include <linux/prefetch.h> /* prefetchw */
31386 #include <linux/context_tracking.h> /* exception_enter(), ... */
31387+#include <linux/unistd.h>
31388+#include <linux/compiler.h>
31389
31390 #include <asm/traps.h> /* dotraplinkage, ... */
31391 #include <asm/pgalloc.h> /* pgd_*(), ... */
31392 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31393 #include <asm/fixmap.h> /* VSYSCALL_START */
31394+#include <asm/tlbflush.h>
31395+
31396+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31397+#include <asm/stacktrace.h>
31398+#endif
31399
31400 #define CREATE_TRACE_POINTS
31401 #include <asm/trace/exceptions.h>
31402@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31403 int ret = 0;
31404
31405 /* kprobe_running() needs smp_processor_id() */
31406- if (kprobes_built_in() && !user_mode_vm(regs)) {
31407+ if (kprobes_built_in() && !user_mode(regs)) {
31408 preempt_disable();
31409 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31410 ret = 1;
31411@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31412 return !instr_lo || (instr_lo>>1) == 1;
31413 case 0x00:
31414 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31415- if (probe_kernel_address(instr, opcode))
31416+ if (user_mode(regs)) {
31417+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31418+ return 0;
31419+ } else if (probe_kernel_address(instr, opcode))
31420 return 0;
31421
31422 *prefetch = (instr_lo == 0xF) &&
31423@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31424 while (instr < max_instr) {
31425 unsigned char opcode;
31426
31427- if (probe_kernel_address(instr, opcode))
31428+ if (user_mode(regs)) {
31429+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31430+ break;
31431+ } else if (probe_kernel_address(instr, opcode))
31432 break;
31433
31434 instr++;
31435@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31436 force_sig_info(si_signo, &info, tsk);
31437 }
31438
31439+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31440+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31441+#endif
31442+
31443+#ifdef CONFIG_PAX_EMUTRAMP
31444+static int pax_handle_fetch_fault(struct pt_regs *regs);
31445+#endif
31446+
31447+#ifdef CONFIG_PAX_PAGEEXEC
31448+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31449+{
31450+ pgd_t *pgd;
31451+ pud_t *pud;
31452+ pmd_t *pmd;
31453+
31454+ pgd = pgd_offset(mm, address);
31455+ if (!pgd_present(*pgd))
31456+ return NULL;
31457+ pud = pud_offset(pgd, address);
31458+ if (!pud_present(*pud))
31459+ return NULL;
31460+ pmd = pmd_offset(pud, address);
31461+ if (!pmd_present(*pmd))
31462+ return NULL;
31463+ return pmd;
31464+}
31465+#endif
31466+
31467 DEFINE_SPINLOCK(pgd_lock);
31468 LIST_HEAD(pgd_list);
31469
31470@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31471 for (address = VMALLOC_START & PMD_MASK;
31472 address >= TASK_SIZE && address < FIXADDR_TOP;
31473 address += PMD_SIZE) {
31474+
31475+#ifdef CONFIG_PAX_PER_CPU_PGD
31476+ unsigned long cpu;
31477+#else
31478 struct page *page;
31479+#endif
31480
31481 spin_lock(&pgd_lock);
31482+
31483+#ifdef CONFIG_PAX_PER_CPU_PGD
31484+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31485+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31486+ pmd_t *ret;
31487+
31488+ ret = vmalloc_sync_one(pgd, address);
31489+ if (!ret)
31490+ break;
31491+ pgd = get_cpu_pgd(cpu, kernel);
31492+#else
31493 list_for_each_entry(page, &pgd_list, lru) {
31494+ pgd_t *pgd;
31495 spinlock_t *pgt_lock;
31496 pmd_t *ret;
31497
31498@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31499 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31500
31501 spin_lock(pgt_lock);
31502- ret = vmalloc_sync_one(page_address(page), address);
31503+ pgd = page_address(page);
31504+#endif
31505+
31506+ ret = vmalloc_sync_one(pgd, address);
31507+
31508+#ifndef CONFIG_PAX_PER_CPU_PGD
31509 spin_unlock(pgt_lock);
31510+#endif
31511
31512 if (!ret)
31513 break;
31514@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31515 * an interrupt in the middle of a task switch..
31516 */
31517 pgd_paddr = read_cr3();
31518+
31519+#ifdef CONFIG_PAX_PER_CPU_PGD
31520+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31521+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31522+#endif
31523+
31524 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31525 if (!pmd_k)
31526 return -1;
31527@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31528 * happen within a race in page table update. In the later
31529 * case just flush:
31530 */
31531- pgd = pgd_offset(current->active_mm, address);
31532+
31533 pgd_ref = pgd_offset_k(address);
31534 if (pgd_none(*pgd_ref))
31535 return -1;
31536
31537+#ifdef CONFIG_PAX_PER_CPU_PGD
31538+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31539+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31540+ if (pgd_none(*pgd)) {
31541+ set_pgd(pgd, *pgd_ref);
31542+ arch_flush_lazy_mmu_mode();
31543+ } else {
31544+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31545+ }
31546+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31547+#else
31548+ pgd = pgd_offset(current->active_mm, address);
31549+#endif
31550+
31551 if (pgd_none(*pgd)) {
31552 set_pgd(pgd, *pgd_ref);
31553 arch_flush_lazy_mmu_mode();
31554@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31555 static int is_errata100(struct pt_regs *regs, unsigned long address)
31556 {
31557 #ifdef CONFIG_X86_64
31558- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31559+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31560 return 1;
31561 #endif
31562 return 0;
31563@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31564 }
31565
31566 static const char nx_warning[] = KERN_CRIT
31567-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31568+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31569
31570 static void
31571 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31572@@ -582,7 +666,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31573 if (!oops_may_print())
31574 return;
31575
31576- if (error_code & PF_INSTR) {
31577+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31578 unsigned int level;
31579 pgd_t *pgd;
31580 pte_t *pte;
31581@@ -593,9 +677,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31582 pte = lookup_address_in_pgd(pgd, address, &level);
31583
31584 if (pte && pte_present(*pte) && !pte_exec(*pte))
31585- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31586+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31587 }
31588
31589+#ifdef CONFIG_PAX_KERNEXEC
31590+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31591+ if (current->signal->curr_ip)
31592+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31593+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31594+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31595+ else
31596+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31597+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31598+ }
31599+#endif
31600+
31601 printk(KERN_ALERT "BUG: unable to handle kernel ");
31602 if (address < PAGE_SIZE)
31603 printk(KERN_CONT "NULL pointer dereference");
31604@@ -776,6 +872,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31605 return;
31606 }
31607 #endif
31608+
31609+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31610+ if (pax_is_fetch_fault(regs, error_code, address)) {
31611+
31612+#ifdef CONFIG_PAX_EMUTRAMP
31613+ switch (pax_handle_fetch_fault(regs)) {
31614+ case 2:
31615+ return;
31616+ }
31617+#endif
31618+
31619+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31620+ do_group_exit(SIGKILL);
31621+ }
31622+#endif
31623+
31624 /* Kernel addresses are always protection faults: */
31625 if (address >= TASK_SIZE)
31626 error_code |= PF_PROT;
31627@@ -861,7 +973,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31628 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31629 printk(KERN_ERR
31630 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31631- tsk->comm, tsk->pid, address);
31632+ tsk->comm, task_pid_nr(tsk), address);
31633 code = BUS_MCEERR_AR;
31634 }
31635 #endif
31636@@ -915,6 +1027,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31637 return 1;
31638 }
31639
31640+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31641+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31642+{
31643+ pte_t *pte;
31644+ pmd_t *pmd;
31645+ spinlock_t *ptl;
31646+ unsigned char pte_mask;
31647+
31648+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31649+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31650+ return 0;
31651+
31652+ /* PaX: it's our fault, let's handle it if we can */
31653+
31654+ /* PaX: take a look at read faults before acquiring any locks */
31655+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31656+ /* instruction fetch attempt from a protected page in user mode */
31657+ up_read(&mm->mmap_sem);
31658+
31659+#ifdef CONFIG_PAX_EMUTRAMP
31660+ switch (pax_handle_fetch_fault(regs)) {
31661+ case 2:
31662+ return 1;
31663+ }
31664+#endif
31665+
31666+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31667+ do_group_exit(SIGKILL);
31668+ }
31669+
31670+ pmd = pax_get_pmd(mm, address);
31671+ if (unlikely(!pmd))
31672+ return 0;
31673+
31674+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31675+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31676+ pte_unmap_unlock(pte, ptl);
31677+ return 0;
31678+ }
31679+
31680+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31681+ /* write attempt to a protected page in user mode */
31682+ pte_unmap_unlock(pte, ptl);
31683+ return 0;
31684+ }
31685+
31686+#ifdef CONFIG_SMP
31687+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31688+#else
31689+ if (likely(address > get_limit(regs->cs)))
31690+#endif
31691+ {
31692+ set_pte(pte, pte_mkread(*pte));
31693+ __flush_tlb_one(address);
31694+ pte_unmap_unlock(pte, ptl);
31695+ up_read(&mm->mmap_sem);
31696+ return 1;
31697+ }
31698+
31699+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31700+
31701+ /*
31702+ * PaX: fill DTLB with user rights and retry
31703+ */
31704+ __asm__ __volatile__ (
31705+ "orb %2,(%1)\n"
31706+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31707+/*
31708+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31709+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31710+ * page fault when examined during a TLB load attempt. this is true not only
31711+ * for PTEs holding a non-present entry but also present entries that will
31712+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31713+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31714+ * for our target pages since their PTEs are simply not in the TLBs at all.
31715+
31716+ * the best thing in omitting it is that we gain around 15-20% speed in the
31717+ * fast path of the page fault handler and can get rid of tracing since we
31718+ * can no longer flush unintended entries.
31719+ */
31720+ "invlpg (%0)\n"
31721+#endif
31722+ __copyuser_seg"testb $0,(%0)\n"
31723+ "xorb %3,(%1)\n"
31724+ :
31725+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31726+ : "memory", "cc");
31727+ pte_unmap_unlock(pte, ptl);
31728+ up_read(&mm->mmap_sem);
31729+ return 1;
31730+}
31731+#endif
31732+
31733 /*
31734 * Handle a spurious fault caused by a stale TLB entry.
31735 *
31736@@ -981,6 +1186,9 @@ int show_unhandled_signals = 1;
31737 static inline int
31738 access_error(unsigned long error_code, struct vm_area_struct *vma)
31739 {
31740+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31741+ return 1;
31742+
31743 if (error_code & PF_WRITE) {
31744 /* write, present and write, not present: */
31745 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31746@@ -1015,7 +1223,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31747 if (error_code & PF_USER)
31748 return false;
31749
31750- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31751+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31752 return false;
31753
31754 return true;
31755@@ -1043,6 +1251,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31756 tsk = current;
31757 mm = tsk->mm;
31758
31759+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31760+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31761+ if (!search_exception_tables(regs->ip)) {
31762+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31763+ bad_area_nosemaphore(regs, error_code, address);
31764+ return;
31765+ }
31766+ if (address < pax_user_shadow_base) {
31767+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31768+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31769+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31770+ } else
31771+ address -= pax_user_shadow_base;
31772+ }
31773+#endif
31774+
31775 /*
31776 * Detect and handle instructions that would cause a page fault for
31777 * both a tracked kernel page and a userspace page.
31778@@ -1120,7 +1344,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31779 * User-mode registers count as a user access even for any
31780 * potential system fault or CPU buglet:
31781 */
31782- if (user_mode_vm(regs)) {
31783+ if (user_mode(regs)) {
31784 local_irq_enable();
31785 error_code |= PF_USER;
31786 flags |= FAULT_FLAG_USER;
31787@@ -1167,6 +1391,11 @@ retry:
31788 might_sleep();
31789 }
31790
31791+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31792+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31793+ return;
31794+#endif
31795+
31796 vma = find_vma(mm, address);
31797 if (unlikely(!vma)) {
31798 bad_area(regs, error_code, address);
31799@@ -1178,18 +1407,24 @@ retry:
31800 bad_area(regs, error_code, address);
31801 return;
31802 }
31803- if (error_code & PF_USER) {
31804- /*
31805- * Accessing the stack below %sp is always a bug.
31806- * The large cushion allows instructions like enter
31807- * and pusha to work. ("enter $65535, $31" pushes
31808- * 32 pointers and then decrements %sp by 65535.)
31809- */
31810- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31811- bad_area(regs, error_code, address);
31812- return;
31813- }
31814+ /*
31815+ * Accessing the stack below %sp is always a bug.
31816+ * The large cushion allows instructions like enter
31817+ * and pusha to work. ("enter $65535, $31" pushes
31818+ * 32 pointers and then decrements %sp by 65535.)
31819+ */
31820+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31821+ bad_area(regs, error_code, address);
31822+ return;
31823 }
31824+
31825+#ifdef CONFIG_PAX_SEGMEXEC
31826+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31827+ bad_area(regs, error_code, address);
31828+ return;
31829+ }
31830+#endif
31831+
31832 if (unlikely(expand_stack(vma, address))) {
31833 bad_area(regs, error_code, address);
31834 return;
31835@@ -1301,3 +1536,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31836 exception_exit(prev_state);
31837 }
31838 #endif /* CONFIG_TRACING */
31839+
31840+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31841+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31842+{
31843+ struct mm_struct *mm = current->mm;
31844+ unsigned long ip = regs->ip;
31845+
31846+ if (v8086_mode(regs))
31847+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31848+
31849+#ifdef CONFIG_PAX_PAGEEXEC
31850+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31851+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31852+ return true;
31853+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31854+ return true;
31855+ return false;
31856+ }
31857+#endif
31858+
31859+#ifdef CONFIG_PAX_SEGMEXEC
31860+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31861+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31862+ return true;
31863+ return false;
31864+ }
31865+#endif
31866+
31867+ return false;
31868+}
31869+#endif
31870+
31871+#ifdef CONFIG_PAX_EMUTRAMP
31872+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31873+{
31874+ int err;
31875+
31876+ do { /* PaX: libffi trampoline emulation */
31877+ unsigned char mov, jmp;
31878+ unsigned int addr1, addr2;
31879+
31880+#ifdef CONFIG_X86_64
31881+ if ((regs->ip + 9) >> 32)
31882+ break;
31883+#endif
31884+
31885+ err = get_user(mov, (unsigned char __user *)regs->ip);
31886+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31887+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31888+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31889+
31890+ if (err)
31891+ break;
31892+
31893+ if (mov == 0xB8 && jmp == 0xE9) {
31894+ regs->ax = addr1;
31895+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31896+ return 2;
31897+ }
31898+ } while (0);
31899+
31900+ do { /* PaX: gcc trampoline emulation #1 */
31901+ unsigned char mov1, mov2;
31902+ unsigned short jmp;
31903+ unsigned int addr1, addr2;
31904+
31905+#ifdef CONFIG_X86_64
31906+ if ((regs->ip + 11) >> 32)
31907+ break;
31908+#endif
31909+
31910+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31911+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31912+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31913+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31914+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31915+
31916+ if (err)
31917+ break;
31918+
31919+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31920+ regs->cx = addr1;
31921+ regs->ax = addr2;
31922+ regs->ip = addr2;
31923+ return 2;
31924+ }
31925+ } while (0);
31926+
31927+ do { /* PaX: gcc trampoline emulation #2 */
31928+ unsigned char mov, jmp;
31929+ unsigned int addr1, addr2;
31930+
31931+#ifdef CONFIG_X86_64
31932+ if ((regs->ip + 9) >> 32)
31933+ break;
31934+#endif
31935+
31936+ err = get_user(mov, (unsigned char __user *)regs->ip);
31937+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31938+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31939+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31940+
31941+ if (err)
31942+ break;
31943+
31944+ if (mov == 0xB9 && jmp == 0xE9) {
31945+ regs->cx = addr1;
31946+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31947+ return 2;
31948+ }
31949+ } while (0);
31950+
31951+ return 1; /* PaX in action */
31952+}
31953+
31954+#ifdef CONFIG_X86_64
31955+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31956+{
31957+ int err;
31958+
31959+ do { /* PaX: libffi trampoline emulation */
31960+ unsigned short mov1, mov2, jmp1;
31961+ unsigned char stcclc, jmp2;
31962+ unsigned long addr1, addr2;
31963+
31964+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31965+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31966+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31967+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31968+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31969+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31970+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31971+
31972+ if (err)
31973+ break;
31974+
31975+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31976+ regs->r11 = addr1;
31977+ regs->r10 = addr2;
31978+ if (stcclc == 0xF8)
31979+ regs->flags &= ~X86_EFLAGS_CF;
31980+ else
31981+ regs->flags |= X86_EFLAGS_CF;
31982+ regs->ip = addr1;
31983+ return 2;
31984+ }
31985+ } while (0);
31986+
31987+ do { /* PaX: gcc trampoline emulation #1 */
31988+ unsigned short mov1, mov2, jmp1;
31989+ unsigned char jmp2;
31990+ unsigned int addr1;
31991+ unsigned long addr2;
31992+
31993+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31994+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31995+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31996+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31997+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31998+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31999+
32000+ if (err)
32001+ break;
32002+
32003+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32004+ regs->r11 = addr1;
32005+ regs->r10 = addr2;
32006+ regs->ip = addr1;
32007+ return 2;
32008+ }
32009+ } while (0);
32010+
32011+ do { /* PaX: gcc trampoline emulation #2 */
32012+ unsigned short mov1, mov2, jmp1;
32013+ unsigned char jmp2;
32014+ unsigned long addr1, addr2;
32015+
32016+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32017+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32018+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32019+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32020+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32021+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32022+
32023+ if (err)
32024+ break;
32025+
32026+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32027+ regs->r11 = addr1;
32028+ regs->r10 = addr2;
32029+ regs->ip = addr1;
32030+ return 2;
32031+ }
32032+ } while (0);
32033+
32034+ return 1; /* PaX in action */
32035+}
32036+#endif
32037+
32038+/*
32039+ * PaX: decide what to do with offenders (regs->ip = fault address)
32040+ *
32041+ * returns 1 when task should be killed
32042+ * 2 when gcc trampoline was detected
32043+ */
32044+static int pax_handle_fetch_fault(struct pt_regs *regs)
32045+{
32046+ if (v8086_mode(regs))
32047+ return 1;
32048+
32049+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32050+ return 1;
32051+
32052+#ifdef CONFIG_X86_32
32053+ return pax_handle_fetch_fault_32(regs);
32054+#else
32055+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32056+ return pax_handle_fetch_fault_32(regs);
32057+ else
32058+ return pax_handle_fetch_fault_64(regs);
32059+#endif
32060+}
32061+#endif
32062+
32063+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32064+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32065+{
32066+ long i;
32067+
32068+ printk(KERN_ERR "PAX: bytes at PC: ");
32069+ for (i = 0; i < 20; i++) {
32070+ unsigned char c;
32071+ if (get_user(c, (unsigned char __force_user *)pc+i))
32072+ printk(KERN_CONT "?? ");
32073+ else
32074+ printk(KERN_CONT "%02x ", c);
32075+ }
32076+ printk("\n");
32077+
32078+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32079+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32080+ unsigned long c;
32081+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32082+#ifdef CONFIG_X86_32
32083+ printk(KERN_CONT "???????? ");
32084+#else
32085+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32086+ printk(KERN_CONT "???????? ???????? ");
32087+ else
32088+ printk(KERN_CONT "???????????????? ");
32089+#endif
32090+ } else {
32091+#ifdef CONFIG_X86_64
32092+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32093+ printk(KERN_CONT "%08x ", (unsigned int)c);
32094+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32095+ } else
32096+#endif
32097+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32098+ }
32099+ }
32100+ printk("\n");
32101+}
32102+#endif
32103+
32104+/**
32105+ * probe_kernel_write(): safely attempt to write to a location
32106+ * @dst: address to write to
32107+ * @src: pointer to the data that shall be written
32108+ * @size: size of the data chunk
32109+ *
32110+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32111+ * happens, handle that and return -EFAULT.
32112+ */
32113+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32114+{
32115+ long ret;
32116+ mm_segment_t old_fs = get_fs();
32117+
32118+ set_fs(KERNEL_DS);
32119+ pagefault_disable();
32120+ pax_open_kernel();
32121+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32122+ pax_close_kernel();
32123+ pagefault_enable();
32124+ set_fs(old_fs);
32125+
32126+ return ret ? -EFAULT : 0;
32127+}
32128diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32129index 207d9aef..69030980 100644
32130--- a/arch/x86/mm/gup.c
32131+++ b/arch/x86/mm/gup.c
32132@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32133 addr = start;
32134 len = (unsigned long) nr_pages << PAGE_SHIFT;
32135 end = start + len;
32136- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32137+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32138 (void __user *)start, len)))
32139 return 0;
32140
32141@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32142 goto slow_irqon;
32143 #endif
32144
32145+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32146+ (void __user *)start, len)))
32147+ return 0;
32148+
32149 /*
32150 * XXX: batch / limit 'nr', to avoid large irq off latency
32151 * needs some instrumenting to determine the common sizes used by
32152diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32153index 4500142..53a363c 100644
32154--- a/arch/x86/mm/highmem_32.c
32155+++ b/arch/x86/mm/highmem_32.c
32156@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32157 idx = type + KM_TYPE_NR*smp_processor_id();
32158 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32159 BUG_ON(!pte_none(*(kmap_pte-idx)));
32160+
32161+ pax_open_kernel();
32162 set_pte(kmap_pte-idx, mk_pte(page, prot));
32163+ pax_close_kernel();
32164+
32165 arch_flush_lazy_mmu_mode();
32166
32167 return (void *)vaddr;
32168diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32169index 8b977eb..4732c33 100644
32170--- a/arch/x86/mm/hugetlbpage.c
32171+++ b/arch/x86/mm/hugetlbpage.c
32172@@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32173 #ifdef CONFIG_HUGETLB_PAGE
32174 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32175 unsigned long addr, unsigned long len,
32176- unsigned long pgoff, unsigned long flags)
32177+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32178 {
32179 struct hstate *h = hstate_file(file);
32180 struct vm_unmapped_area_info info;
32181-
32182+
32183 info.flags = 0;
32184 info.length = len;
32185 info.low_limit = current->mm->mmap_legacy_base;
32186 info.high_limit = TASK_SIZE;
32187 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32188 info.align_offset = 0;
32189+ info.threadstack_offset = offset;
32190 return vm_unmapped_area(&info);
32191 }
32192
32193 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32194 unsigned long addr0, unsigned long len,
32195- unsigned long pgoff, unsigned long flags)
32196+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32197 {
32198 struct hstate *h = hstate_file(file);
32199 struct vm_unmapped_area_info info;
32200@@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32201 info.high_limit = current->mm->mmap_base;
32202 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32203 info.align_offset = 0;
32204+ info.threadstack_offset = offset;
32205 addr = vm_unmapped_area(&info);
32206
32207 /*
32208@@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32209 VM_BUG_ON(addr != -ENOMEM);
32210 info.flags = 0;
32211 info.low_limit = TASK_UNMAPPED_BASE;
32212+
32213+#ifdef CONFIG_PAX_RANDMMAP
32214+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32215+ info.low_limit += current->mm->delta_mmap;
32216+#endif
32217+
32218 info.high_limit = TASK_SIZE;
32219 addr = vm_unmapped_area(&info);
32220 }
32221@@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32222 struct hstate *h = hstate_file(file);
32223 struct mm_struct *mm = current->mm;
32224 struct vm_area_struct *vma;
32225+ unsigned long pax_task_size = TASK_SIZE;
32226+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32227
32228 if (len & ~huge_page_mask(h))
32229 return -EINVAL;
32230- if (len > TASK_SIZE)
32231+
32232+#ifdef CONFIG_PAX_SEGMEXEC
32233+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32234+ pax_task_size = SEGMEXEC_TASK_SIZE;
32235+#endif
32236+
32237+ pax_task_size -= PAGE_SIZE;
32238+
32239+ if (len > pax_task_size)
32240 return -ENOMEM;
32241
32242 if (flags & MAP_FIXED) {
32243@@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32244 return addr;
32245 }
32246
32247+#ifdef CONFIG_PAX_RANDMMAP
32248+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32249+#endif
32250+
32251 if (addr) {
32252 addr = ALIGN(addr, huge_page_size(h));
32253 vma = find_vma(mm, addr);
32254- if (TASK_SIZE - len >= addr &&
32255- (!vma || addr + len <= vma->vm_start))
32256+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32257 return addr;
32258 }
32259 if (mm->get_unmapped_area == arch_get_unmapped_area)
32260 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32261- pgoff, flags);
32262+ pgoff, flags, offset);
32263 else
32264 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32265- pgoff, flags);
32266+ pgoff, flags, offset);
32267 }
32268 #endif /* CONFIG_HUGETLB_PAGE */
32269
32270diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32271index f971306..e83e0f6 100644
32272--- a/arch/x86/mm/init.c
32273+++ b/arch/x86/mm/init.c
32274@@ -4,6 +4,7 @@
32275 #include <linux/swap.h>
32276 #include <linux/memblock.h>
32277 #include <linux/bootmem.h> /* for max_low_pfn */
32278+#include <linux/tboot.h>
32279
32280 #include <asm/cacheflush.h>
32281 #include <asm/e820.h>
32282@@ -17,6 +18,8 @@
32283 #include <asm/proto.h>
32284 #include <asm/dma.h> /* for MAX_DMA_PFN */
32285 #include <asm/microcode.h>
32286+#include <asm/desc.h>
32287+#include <asm/bios_ebda.h>
32288
32289 #include "mm_internal.h"
32290
32291@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32292 early_ioremap_page_table_range_init();
32293 #endif
32294
32295+#ifdef CONFIG_PAX_PER_CPU_PGD
32296+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32297+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32298+ KERNEL_PGD_PTRS);
32299+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32300+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32301+ KERNEL_PGD_PTRS);
32302+ load_cr3(get_cpu_pgd(0, kernel));
32303+#else
32304 load_cr3(swapper_pg_dir);
32305+#endif
32306+
32307 __flush_tlb_all();
32308
32309 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32310@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32311 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32312 * mmio resources as well as potential bios/acpi data regions.
32313 */
32314+
32315+#ifdef CONFIG_GRKERNSEC_KMEM
32316+static unsigned int ebda_start __read_only;
32317+static unsigned int ebda_end __read_only;
32318+#endif
32319+
32320 int devmem_is_allowed(unsigned long pagenr)
32321 {
32322- if (pagenr < 256)
32323+#ifdef CONFIG_GRKERNSEC_KMEM
32324+ /* allow BDA */
32325+ if (!pagenr)
32326 return 1;
32327+ /* allow EBDA */
32328+ if (pagenr >= ebda_start && pagenr < ebda_end)
32329+ return 1;
32330+ /* if tboot is in use, allow access to its hardcoded serial log range */
32331+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32332+ return 1;
32333+#else
32334+ if (!pagenr)
32335+ return 1;
32336+#ifdef CONFIG_VM86
32337+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32338+ return 1;
32339+#endif
32340+#endif
32341+
32342+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32343+ return 1;
32344+#ifdef CONFIG_GRKERNSEC_KMEM
32345+ /* throw out everything else below 1MB */
32346+ if (pagenr <= 256)
32347+ return 0;
32348+#endif
32349 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32350 return 0;
32351 if (!page_is_ram(pagenr))
32352@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32353 #endif
32354 }
32355
32356+#ifdef CONFIG_GRKERNSEC_KMEM
32357+static inline void gr_init_ebda(void)
32358+{
32359+ unsigned int ebda_addr;
32360+ unsigned int ebda_size = 0;
32361+
32362+ ebda_addr = get_bios_ebda();
32363+ if (ebda_addr) {
32364+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32365+ ebda_size <<= 10;
32366+ }
32367+ if (ebda_addr && ebda_size) {
32368+ ebda_start = ebda_addr >> PAGE_SHIFT;
32369+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32370+ } else {
32371+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32372+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32373+ }
32374+}
32375+#else
32376+static inline void gr_init_ebda(void) { }
32377+#endif
32378+
32379 void free_initmem(void)
32380 {
32381+#ifdef CONFIG_PAX_KERNEXEC
32382+#ifdef CONFIG_X86_32
32383+ /* PaX: limit KERNEL_CS to actual size */
32384+ unsigned long addr, limit;
32385+ struct desc_struct d;
32386+ int cpu;
32387+#else
32388+ pgd_t *pgd;
32389+ pud_t *pud;
32390+ pmd_t *pmd;
32391+ unsigned long addr, end;
32392+#endif
32393+#endif
32394+
32395+ gr_init_ebda();
32396+
32397+#ifdef CONFIG_PAX_KERNEXEC
32398+#ifdef CONFIG_X86_32
32399+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32400+ limit = (limit - 1UL) >> PAGE_SHIFT;
32401+
32402+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32403+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32404+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32405+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32406+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32407+ }
32408+
32409+ /* PaX: make KERNEL_CS read-only */
32410+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32411+ if (!paravirt_enabled())
32412+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32413+/*
32414+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32415+ pgd = pgd_offset_k(addr);
32416+ pud = pud_offset(pgd, addr);
32417+ pmd = pmd_offset(pud, addr);
32418+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32419+ }
32420+*/
32421+#ifdef CONFIG_X86_PAE
32422+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32423+/*
32424+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32425+ pgd = pgd_offset_k(addr);
32426+ pud = pud_offset(pgd, addr);
32427+ pmd = pmd_offset(pud, addr);
32428+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32429+ }
32430+*/
32431+#endif
32432+
32433+#ifdef CONFIG_MODULES
32434+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32435+#endif
32436+
32437+#else
32438+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32439+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32440+ pgd = pgd_offset_k(addr);
32441+ pud = pud_offset(pgd, addr);
32442+ pmd = pmd_offset(pud, addr);
32443+ if (!pmd_present(*pmd))
32444+ continue;
32445+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32446+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32447+ else
32448+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32449+ }
32450+
32451+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32452+ end = addr + KERNEL_IMAGE_SIZE;
32453+ for (; addr < end; addr += PMD_SIZE) {
32454+ pgd = pgd_offset_k(addr);
32455+ pud = pud_offset(pgd, addr);
32456+ pmd = pmd_offset(pud, addr);
32457+ if (!pmd_present(*pmd))
32458+ continue;
32459+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32460+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32461+ }
32462+#endif
32463+
32464+ flush_tlb_all();
32465+#endif
32466+
32467 free_init_pages("unused kernel",
32468 (unsigned long)(&__init_begin),
32469 (unsigned long)(&__init_end));
32470diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32471index e395048..cd38278 100644
32472--- a/arch/x86/mm/init_32.c
32473+++ b/arch/x86/mm/init_32.c
32474@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32475 bool __read_mostly __vmalloc_start_set = false;
32476
32477 /*
32478- * Creates a middle page table and puts a pointer to it in the
32479- * given global directory entry. This only returns the gd entry
32480- * in non-PAE compilation mode, since the middle layer is folded.
32481- */
32482-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32483-{
32484- pud_t *pud;
32485- pmd_t *pmd_table;
32486-
32487-#ifdef CONFIG_X86_PAE
32488- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32489- pmd_table = (pmd_t *)alloc_low_page();
32490- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32491- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32492- pud = pud_offset(pgd, 0);
32493- BUG_ON(pmd_table != pmd_offset(pud, 0));
32494-
32495- return pmd_table;
32496- }
32497-#endif
32498- pud = pud_offset(pgd, 0);
32499- pmd_table = pmd_offset(pud, 0);
32500-
32501- return pmd_table;
32502-}
32503-
32504-/*
32505 * Create a page table and place a pointer to it in a middle page
32506 * directory entry:
32507 */
32508@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32509 pte_t *page_table = (pte_t *)alloc_low_page();
32510
32511 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32512+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32513+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32514+#else
32515 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32516+#endif
32517 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32518 }
32519
32520 return pte_offset_kernel(pmd, 0);
32521 }
32522
32523+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32524+{
32525+ pud_t *pud;
32526+ pmd_t *pmd_table;
32527+
32528+ pud = pud_offset(pgd, 0);
32529+ pmd_table = pmd_offset(pud, 0);
32530+
32531+ return pmd_table;
32532+}
32533+
32534 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32535 {
32536 int pgd_idx = pgd_index(vaddr);
32537@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32538 int pgd_idx, pmd_idx;
32539 unsigned long vaddr;
32540 pgd_t *pgd;
32541+ pud_t *pud;
32542 pmd_t *pmd;
32543 pte_t *pte = NULL;
32544 unsigned long count = page_table_range_init_count(start, end);
32545@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32546 pgd = pgd_base + pgd_idx;
32547
32548 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32549- pmd = one_md_table_init(pgd);
32550- pmd = pmd + pmd_index(vaddr);
32551+ pud = pud_offset(pgd, vaddr);
32552+ pmd = pmd_offset(pud, vaddr);
32553+
32554+#ifdef CONFIG_X86_PAE
32555+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32556+#endif
32557+
32558 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32559 pmd++, pmd_idx++) {
32560 pte = page_table_kmap_check(one_page_table_init(pmd),
32561@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32562 }
32563 }
32564
32565-static inline int is_kernel_text(unsigned long addr)
32566+static inline int is_kernel_text(unsigned long start, unsigned long end)
32567 {
32568- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32569- return 1;
32570- return 0;
32571+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32572+ end <= ktla_ktva((unsigned long)_stext)) &&
32573+ (start >= ktla_ktva((unsigned long)_einittext) ||
32574+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32575+
32576+#ifdef CONFIG_ACPI_SLEEP
32577+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32578+#endif
32579+
32580+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32581+ return 0;
32582+ return 1;
32583 }
32584
32585 /*
32586@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32587 unsigned long last_map_addr = end;
32588 unsigned long start_pfn, end_pfn;
32589 pgd_t *pgd_base = swapper_pg_dir;
32590- int pgd_idx, pmd_idx, pte_ofs;
32591+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32592 unsigned long pfn;
32593 pgd_t *pgd;
32594+ pud_t *pud;
32595 pmd_t *pmd;
32596 pte_t *pte;
32597 unsigned pages_2m, pages_4k;
32598@@ -291,8 +295,13 @@ repeat:
32599 pfn = start_pfn;
32600 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32601 pgd = pgd_base + pgd_idx;
32602- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32603- pmd = one_md_table_init(pgd);
32604+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32605+ pud = pud_offset(pgd, 0);
32606+ pmd = pmd_offset(pud, 0);
32607+
32608+#ifdef CONFIG_X86_PAE
32609+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32610+#endif
32611
32612 if (pfn >= end_pfn)
32613 continue;
32614@@ -304,14 +313,13 @@ repeat:
32615 #endif
32616 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32617 pmd++, pmd_idx++) {
32618- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32619+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32620
32621 /*
32622 * Map with big pages if possible, otherwise
32623 * create normal page tables:
32624 */
32625 if (use_pse) {
32626- unsigned int addr2;
32627 pgprot_t prot = PAGE_KERNEL_LARGE;
32628 /*
32629 * first pass will use the same initial
32630@@ -322,11 +330,7 @@ repeat:
32631 _PAGE_PSE);
32632
32633 pfn &= PMD_MASK >> PAGE_SHIFT;
32634- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32635- PAGE_OFFSET + PAGE_SIZE-1;
32636-
32637- if (is_kernel_text(addr) ||
32638- is_kernel_text(addr2))
32639+ if (is_kernel_text(address, address + PMD_SIZE))
32640 prot = PAGE_KERNEL_LARGE_EXEC;
32641
32642 pages_2m++;
32643@@ -343,7 +347,7 @@ repeat:
32644 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32645 pte += pte_ofs;
32646 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32647- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32648+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32649 pgprot_t prot = PAGE_KERNEL;
32650 /*
32651 * first pass will use the same initial
32652@@ -351,7 +355,7 @@ repeat:
32653 */
32654 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32655
32656- if (is_kernel_text(addr))
32657+ if (is_kernel_text(address, address + PAGE_SIZE))
32658 prot = PAGE_KERNEL_EXEC;
32659
32660 pages_4k++;
32661@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32662
32663 pud = pud_offset(pgd, va);
32664 pmd = pmd_offset(pud, va);
32665- if (!pmd_present(*pmd))
32666+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32667 break;
32668
32669 /* should not be large page here */
32670@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32671
32672 static void __init pagetable_init(void)
32673 {
32674- pgd_t *pgd_base = swapper_pg_dir;
32675-
32676- permanent_kmaps_init(pgd_base);
32677+ permanent_kmaps_init(swapper_pg_dir);
32678 }
32679
32680-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32681+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32682 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32683
32684 /* user-defined highmem size */
32685@@ -787,10 +789,10 @@ void __init mem_init(void)
32686 ((unsigned long)&__init_end -
32687 (unsigned long)&__init_begin) >> 10,
32688
32689- (unsigned long)&_etext, (unsigned long)&_edata,
32690- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32691+ (unsigned long)&_sdata, (unsigned long)&_edata,
32692+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32693
32694- (unsigned long)&_text, (unsigned long)&_etext,
32695+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32696 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32697
32698 /*
32699@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32700 if (!kernel_set_to_readonly)
32701 return;
32702
32703+ start = ktla_ktva(start);
32704 pr_debug("Set kernel text: %lx - %lx for read write\n",
32705 start, start+size);
32706
32707@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32708 if (!kernel_set_to_readonly)
32709 return;
32710
32711+ start = ktla_ktva(start);
32712 pr_debug("Set kernel text: %lx - %lx for read only\n",
32713 start, start+size);
32714
32715@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32716 unsigned long start = PFN_ALIGN(_text);
32717 unsigned long size = PFN_ALIGN(_etext) - start;
32718
32719+ start = ktla_ktva(start);
32720 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32721 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32722 size >> 10);
32723diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32724index f35c66c..84b95ef 100644
32725--- a/arch/x86/mm/init_64.c
32726+++ b/arch/x86/mm/init_64.c
32727@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32728 * around without checking the pgd every time.
32729 */
32730
32731-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32732+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32733 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32734
32735 int force_personality32;
32736@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32737
32738 for (address = start; address <= end; address += PGDIR_SIZE) {
32739 const pgd_t *pgd_ref = pgd_offset_k(address);
32740+
32741+#ifdef CONFIG_PAX_PER_CPU_PGD
32742+ unsigned long cpu;
32743+#else
32744 struct page *page;
32745+#endif
32746
32747 if (pgd_none(*pgd_ref))
32748 continue;
32749
32750 spin_lock(&pgd_lock);
32751+
32752+#ifdef CONFIG_PAX_PER_CPU_PGD
32753+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32754+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32755+
32756+ if (pgd_none(*pgd))
32757+ set_pgd(pgd, *pgd_ref);
32758+ else
32759+ BUG_ON(pgd_page_vaddr(*pgd)
32760+ != pgd_page_vaddr(*pgd_ref));
32761+ pgd = pgd_offset_cpu(cpu, kernel, address);
32762+#else
32763 list_for_each_entry(page, &pgd_list, lru) {
32764 pgd_t *pgd;
32765 spinlock_t *pgt_lock;
32766@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32767 /* the pgt_lock only for Xen */
32768 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32769 spin_lock(pgt_lock);
32770+#endif
32771
32772 if (pgd_none(*pgd))
32773 set_pgd(pgd, *pgd_ref);
32774@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32775 BUG_ON(pgd_page_vaddr(*pgd)
32776 != pgd_page_vaddr(*pgd_ref));
32777
32778+#ifndef CONFIG_PAX_PER_CPU_PGD
32779 spin_unlock(pgt_lock);
32780+#endif
32781+
32782 }
32783 spin_unlock(&pgd_lock);
32784 }
32785@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32786 {
32787 if (pgd_none(*pgd)) {
32788 pud_t *pud = (pud_t *)spp_getpage();
32789- pgd_populate(&init_mm, pgd, pud);
32790+ pgd_populate_kernel(&init_mm, pgd, pud);
32791 if (pud != pud_offset(pgd, 0))
32792 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32793 pud, pud_offset(pgd, 0));
32794@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32795 {
32796 if (pud_none(*pud)) {
32797 pmd_t *pmd = (pmd_t *) spp_getpage();
32798- pud_populate(&init_mm, pud, pmd);
32799+ pud_populate_kernel(&init_mm, pud, pmd);
32800 if (pmd != pmd_offset(pud, 0))
32801 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32802 pmd, pmd_offset(pud, 0));
32803@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32804 pmd = fill_pmd(pud, vaddr);
32805 pte = fill_pte(pmd, vaddr);
32806
32807+ pax_open_kernel();
32808 set_pte(pte, new_pte);
32809+ pax_close_kernel();
32810
32811 /*
32812 * It's enough to flush this one mapping.
32813@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32814 pgd = pgd_offset_k((unsigned long)__va(phys));
32815 if (pgd_none(*pgd)) {
32816 pud = (pud_t *) spp_getpage();
32817- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32818- _PAGE_USER));
32819+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32820 }
32821 pud = pud_offset(pgd, (unsigned long)__va(phys));
32822 if (pud_none(*pud)) {
32823 pmd = (pmd_t *) spp_getpage();
32824- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32825- _PAGE_USER));
32826+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32827 }
32828 pmd = pmd_offset(pud, phys);
32829 BUG_ON(!pmd_none(*pmd));
32830@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32831 prot);
32832
32833 spin_lock(&init_mm.page_table_lock);
32834- pud_populate(&init_mm, pud, pmd);
32835+ pud_populate_kernel(&init_mm, pud, pmd);
32836 spin_unlock(&init_mm.page_table_lock);
32837 }
32838 __flush_tlb_all();
32839@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32840 page_size_mask);
32841
32842 spin_lock(&init_mm.page_table_lock);
32843- pgd_populate(&init_mm, pgd, pud);
32844+ pgd_populate_kernel(&init_mm, pgd, pud);
32845 spin_unlock(&init_mm.page_table_lock);
32846 pgd_changed = true;
32847 }
32848@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32849 static struct vm_area_struct gate_vma = {
32850 .vm_start = VSYSCALL_START,
32851 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32852- .vm_page_prot = PAGE_READONLY_EXEC,
32853- .vm_flags = VM_READ | VM_EXEC
32854+ .vm_page_prot = PAGE_READONLY,
32855+ .vm_flags = VM_READ
32856 };
32857
32858 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32859@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32860
32861 const char *arch_vma_name(struct vm_area_struct *vma)
32862 {
32863- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32864+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32865 return "[vdso]";
32866 if (vma == &gate_vma)
32867 return "[vsyscall]";
32868diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32869index 7b179b4..6bd17777 100644
32870--- a/arch/x86/mm/iomap_32.c
32871+++ b/arch/x86/mm/iomap_32.c
32872@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32873 type = kmap_atomic_idx_push();
32874 idx = type + KM_TYPE_NR * smp_processor_id();
32875 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32876+
32877+ pax_open_kernel();
32878 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32879+ pax_close_kernel();
32880+
32881 arch_flush_lazy_mmu_mode();
32882
32883 return (void *)vaddr;
32884diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32885index 597ac15..49841be 100644
32886--- a/arch/x86/mm/ioremap.c
32887+++ b/arch/x86/mm/ioremap.c
32888@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32889 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32890 int is_ram = page_is_ram(pfn);
32891
32892- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32893+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32894 return NULL;
32895 WARN_ON_ONCE(is_ram);
32896 }
32897@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32898 *
32899 * Caller must ensure there is only one unmapping for the same pointer.
32900 */
32901-void iounmap(volatile void __iomem *addr)
32902+void iounmap(const volatile void __iomem *addr)
32903 {
32904 struct vm_struct *p, *o;
32905
32906@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32907
32908 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32909 if (page_is_ram(start >> PAGE_SHIFT))
32910+#ifdef CONFIG_HIGHMEM
32911+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32912+#endif
32913 return __va(phys);
32914
32915 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32916@@ -322,13 +325,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32917 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32918 {
32919 if (page_is_ram(phys >> PAGE_SHIFT))
32920+#ifdef CONFIG_HIGHMEM
32921+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32922+#endif
32923 return;
32924
32925 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32926 return;
32927 }
32928
32929-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32930+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32931
32932 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32933 {
32934@@ -358,8 +364,7 @@ void __init early_ioremap_init(void)
32935 early_ioremap_setup();
32936
32937 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32938- memset(bm_pte, 0, sizeof(bm_pte));
32939- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32940+ pmd_populate_user(&init_mm, pmd, bm_pte);
32941
32942 /*
32943 * The boot-ioremap range spans multiple pmds, for which
32944diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32945index dd89a13..d77bdcc 100644
32946--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32947+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32948@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32949 * memory (e.g. tracked pages)? For now, we need this to avoid
32950 * invoking kmemcheck for PnP BIOS calls.
32951 */
32952- if (regs->flags & X86_VM_MASK)
32953+ if (v8086_mode(regs))
32954 return false;
32955- if (regs->cs != __KERNEL_CS)
32956+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32957 return false;
32958
32959 pte = kmemcheck_pte_lookup(address);
32960diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32961index 25e7e13..1964579 100644
32962--- a/arch/x86/mm/mmap.c
32963+++ b/arch/x86/mm/mmap.c
32964@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32965 * Leave an at least ~128 MB hole with possible stack randomization.
32966 */
32967 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32968-#define MAX_GAP (TASK_SIZE/6*5)
32969+#define MAX_GAP (pax_task_size/6*5)
32970
32971 static int mmap_is_legacy(void)
32972 {
32973@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32974 return rnd << PAGE_SHIFT;
32975 }
32976
32977-static unsigned long mmap_base(void)
32978+static unsigned long mmap_base(struct mm_struct *mm)
32979 {
32980 unsigned long gap = rlimit(RLIMIT_STACK);
32981+ unsigned long pax_task_size = TASK_SIZE;
32982+
32983+#ifdef CONFIG_PAX_SEGMEXEC
32984+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32985+ pax_task_size = SEGMEXEC_TASK_SIZE;
32986+#endif
32987
32988 if (gap < MIN_GAP)
32989 gap = MIN_GAP;
32990 else if (gap > MAX_GAP)
32991 gap = MAX_GAP;
32992
32993- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32994+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32995 }
32996
32997 /*
32998 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32999 * does, but not when emulating X86_32
33000 */
33001-static unsigned long mmap_legacy_base(void)
33002+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33003 {
33004- if (mmap_is_ia32())
33005+ if (mmap_is_ia32()) {
33006+
33007+#ifdef CONFIG_PAX_SEGMEXEC
33008+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33009+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33010+ else
33011+#endif
33012+
33013 return TASK_UNMAPPED_BASE;
33014- else
33015+ } else
33016 return TASK_UNMAPPED_BASE + mmap_rnd();
33017 }
33018
33019@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33020 */
33021 void arch_pick_mmap_layout(struct mm_struct *mm)
33022 {
33023- mm->mmap_legacy_base = mmap_legacy_base();
33024- mm->mmap_base = mmap_base();
33025+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33026+ mm->mmap_base = mmap_base(mm);
33027+
33028+#ifdef CONFIG_PAX_RANDMMAP
33029+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33030+ mm->mmap_legacy_base += mm->delta_mmap;
33031+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33032+ }
33033+#endif
33034
33035 if (mmap_is_legacy()) {
33036 mm->mmap_base = mm->mmap_legacy_base;
33037diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33038index 0057a7a..95c7edd 100644
33039--- a/arch/x86/mm/mmio-mod.c
33040+++ b/arch/x86/mm/mmio-mod.c
33041@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33042 break;
33043 default:
33044 {
33045- unsigned char *ip = (unsigned char *)instptr;
33046+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33047 my_trace->opcode = MMIO_UNKNOWN_OP;
33048 my_trace->width = 0;
33049 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33050@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33051 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33052 void __iomem *addr)
33053 {
33054- static atomic_t next_id;
33055+ static atomic_unchecked_t next_id;
33056 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33057 /* These are page-unaligned. */
33058 struct mmiotrace_map map = {
33059@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33060 .private = trace
33061 },
33062 .phys = offset,
33063- .id = atomic_inc_return(&next_id)
33064+ .id = atomic_inc_return_unchecked(&next_id)
33065 };
33066 map.map_id = trace->id;
33067
33068@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33069 ioremap_trace_core(offset, size, addr);
33070 }
33071
33072-static void iounmap_trace_core(volatile void __iomem *addr)
33073+static void iounmap_trace_core(const volatile void __iomem *addr)
33074 {
33075 struct mmiotrace_map map = {
33076 .phys = 0,
33077@@ -328,7 +328,7 @@ not_enabled:
33078 }
33079 }
33080
33081-void mmiotrace_iounmap(volatile void __iomem *addr)
33082+void mmiotrace_iounmap(const volatile void __iomem *addr)
33083 {
33084 might_sleep();
33085 if (is_enabled()) /* recheck and proper locking in *_core() */
33086diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33087index 1d045f9..3a00249 100644
33088--- a/arch/x86/mm/numa.c
33089+++ b/arch/x86/mm/numa.c
33090@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33091 return true;
33092 }
33093
33094-static int __init numa_register_memblks(struct numa_meminfo *mi)
33095+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33096 {
33097 unsigned long uninitialized_var(pfn_align);
33098 int i, nid;
33099diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33100index 461bc82..4e091a3 100644
33101--- a/arch/x86/mm/pageattr-test.c
33102+++ b/arch/x86/mm/pageattr-test.c
33103@@ -35,7 +35,7 @@ enum {
33104
33105 static int pte_testbit(pte_t pte)
33106 {
33107- return pte_flags(pte) & _PAGE_UNUSED1;
33108+ return pte_flags(pte) & _PAGE_CPA_TEST;
33109 }
33110
33111 struct split_state {
33112diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33113index ae242a7..1c7998f 100644
33114--- a/arch/x86/mm/pageattr.c
33115+++ b/arch/x86/mm/pageattr.c
33116@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33117 */
33118 #ifdef CONFIG_PCI_BIOS
33119 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33120- pgprot_val(forbidden) |= _PAGE_NX;
33121+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33122 #endif
33123
33124 /*
33125@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33126 * Does not cover __inittext since that is gone later on. On
33127 * 64bit we do not enforce !NX on the low mapping
33128 */
33129- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33130- pgprot_val(forbidden) |= _PAGE_NX;
33131+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33132+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33133
33134+#ifdef CONFIG_DEBUG_RODATA
33135 /*
33136 * The .rodata section needs to be read-only. Using the pfn
33137 * catches all aliases.
33138@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33139 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33140 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33141 pgprot_val(forbidden) |= _PAGE_RW;
33142+#endif
33143
33144 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33145 /*
33146@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33147 }
33148 #endif
33149
33150+#ifdef CONFIG_PAX_KERNEXEC
33151+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33152+ pgprot_val(forbidden) |= _PAGE_RW;
33153+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33154+ }
33155+#endif
33156+
33157 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33158
33159 return prot;
33160@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33161 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33162 {
33163 /* change init_mm */
33164+ pax_open_kernel();
33165 set_pte_atomic(kpte, pte);
33166+
33167 #ifdef CONFIG_X86_32
33168 if (!SHARED_KERNEL_PMD) {
33169+
33170+#ifdef CONFIG_PAX_PER_CPU_PGD
33171+ unsigned long cpu;
33172+#else
33173 struct page *page;
33174+#endif
33175
33176+#ifdef CONFIG_PAX_PER_CPU_PGD
33177+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33178+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33179+#else
33180 list_for_each_entry(page, &pgd_list, lru) {
33181- pgd_t *pgd;
33182+ pgd_t *pgd = (pgd_t *)page_address(page);
33183+#endif
33184+
33185 pud_t *pud;
33186 pmd_t *pmd;
33187
33188- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33189+ pgd += pgd_index(address);
33190 pud = pud_offset(pgd, address);
33191 pmd = pmd_offset(pud, address);
33192 set_pte_atomic((pte_t *)pmd, pte);
33193 }
33194 }
33195 #endif
33196+ pax_close_kernel();
33197 }
33198
33199 static int
33200diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33201index 6574388..87e9bef 100644
33202--- a/arch/x86/mm/pat.c
33203+++ b/arch/x86/mm/pat.c
33204@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33205
33206 if (!entry) {
33207 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33208- current->comm, current->pid, start, end - 1);
33209+ current->comm, task_pid_nr(current), start, end - 1);
33210 return -EINVAL;
33211 }
33212
33213@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33214
33215 while (cursor < to) {
33216 if (!devmem_is_allowed(pfn)) {
33217- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33218- current->comm, from, to - 1);
33219+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33220+ current->comm, from, to - 1, cursor);
33221 return 0;
33222 }
33223 cursor += PAGE_SIZE;
33224@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33225 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33226 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33227 "for [mem %#010Lx-%#010Lx]\n",
33228- current->comm, current->pid,
33229+ current->comm, task_pid_nr(current),
33230 cattr_name(flags),
33231 base, (unsigned long long)(base + size-1));
33232 return -EINVAL;
33233@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33234 flags = lookup_memtype(paddr);
33235 if (want_flags != flags) {
33236 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33237- current->comm, current->pid,
33238+ current->comm, task_pid_nr(current),
33239 cattr_name(want_flags),
33240 (unsigned long long)paddr,
33241 (unsigned long long)(paddr + size - 1),
33242@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33243 free_memtype(paddr, paddr + size);
33244 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33245 " for [mem %#010Lx-%#010Lx], got %s\n",
33246- current->comm, current->pid,
33247+ current->comm, task_pid_nr(current),
33248 cattr_name(want_flags),
33249 (unsigned long long)paddr,
33250 (unsigned long long)(paddr + size - 1),
33251diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33252index 415f6c4..d319983 100644
33253--- a/arch/x86/mm/pat_rbtree.c
33254+++ b/arch/x86/mm/pat_rbtree.c
33255@@ -160,7 +160,7 @@ success:
33256
33257 failure:
33258 printk(KERN_INFO "%s:%d conflicting memory types "
33259- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33260+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33261 end, cattr_name(found_type), cattr_name(match->type));
33262 return -EBUSY;
33263 }
33264diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33265index 9f0614d..92ae64a 100644
33266--- a/arch/x86/mm/pf_in.c
33267+++ b/arch/x86/mm/pf_in.c
33268@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33269 int i;
33270 enum reason_type rv = OTHERS;
33271
33272- p = (unsigned char *)ins_addr;
33273+ p = (unsigned char *)ktla_ktva(ins_addr);
33274 p += skip_prefix(p, &prf);
33275 p += get_opcode(p, &opcode);
33276
33277@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33278 struct prefix_bits prf;
33279 int i;
33280
33281- p = (unsigned char *)ins_addr;
33282+ p = (unsigned char *)ktla_ktva(ins_addr);
33283 p += skip_prefix(p, &prf);
33284 p += get_opcode(p, &opcode);
33285
33286@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33287 struct prefix_bits prf;
33288 int i;
33289
33290- p = (unsigned char *)ins_addr;
33291+ p = (unsigned char *)ktla_ktva(ins_addr);
33292 p += skip_prefix(p, &prf);
33293 p += get_opcode(p, &opcode);
33294
33295@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33296 struct prefix_bits prf;
33297 int i;
33298
33299- p = (unsigned char *)ins_addr;
33300+ p = (unsigned char *)ktla_ktva(ins_addr);
33301 p += skip_prefix(p, &prf);
33302 p += get_opcode(p, &opcode);
33303 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33304@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33305 struct prefix_bits prf;
33306 int i;
33307
33308- p = (unsigned char *)ins_addr;
33309+ p = (unsigned char *)ktla_ktva(ins_addr);
33310 p += skip_prefix(p, &prf);
33311 p += get_opcode(p, &opcode);
33312 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33313diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33314index c96314a..433b127 100644
33315--- a/arch/x86/mm/pgtable.c
33316+++ b/arch/x86/mm/pgtable.c
33317@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33318 list_del(&page->lru);
33319 }
33320
33321-#define UNSHARED_PTRS_PER_PGD \
33322- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33323+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33324+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33325
33326+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33327+{
33328+ unsigned int count = USER_PGD_PTRS;
33329
33330+ if (!pax_user_shadow_base)
33331+ return;
33332+
33333+ while (count--)
33334+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33335+}
33336+#endif
33337+
33338+#ifdef CONFIG_PAX_PER_CPU_PGD
33339+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33340+{
33341+ unsigned int count = USER_PGD_PTRS;
33342+
33343+ while (count--) {
33344+ pgd_t pgd;
33345+
33346+#ifdef CONFIG_X86_64
33347+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33348+#else
33349+ pgd = *src++;
33350+#endif
33351+
33352+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33353+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33354+#endif
33355+
33356+ *dst++ = pgd;
33357+ }
33358+
33359+}
33360+#endif
33361+
33362+#ifdef CONFIG_X86_64
33363+#define pxd_t pud_t
33364+#define pyd_t pgd_t
33365+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33366+#define pgtable_pxd_page_ctor(page) true
33367+#define pgtable_pxd_page_dtor(page)
33368+#define pxd_free(mm, pud) pud_free((mm), (pud))
33369+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33370+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33371+#define PYD_SIZE PGDIR_SIZE
33372+#else
33373+#define pxd_t pmd_t
33374+#define pyd_t pud_t
33375+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33376+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33377+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33378+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33379+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33380+#define pyd_offset(mm, address) pud_offset((mm), (address))
33381+#define PYD_SIZE PUD_SIZE
33382+#endif
33383+
33384+#ifdef CONFIG_PAX_PER_CPU_PGD
33385+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33386+static inline void pgd_dtor(pgd_t *pgd) {}
33387+#else
33388 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33389 {
33390 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33391@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33392 pgd_list_del(pgd);
33393 spin_unlock(&pgd_lock);
33394 }
33395+#endif
33396
33397 /*
33398 * List of all pgd's needed for non-PAE so it can invalidate entries
33399@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33400 * -- nyc
33401 */
33402
33403-#ifdef CONFIG_X86_PAE
33404+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33405 /*
33406 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33407 * updating the top-level pagetable entries to guarantee the
33408@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33409 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33410 * and initialize the kernel pmds here.
33411 */
33412-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33413+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33414
33415 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33416 {
33417@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33418 */
33419 flush_tlb_mm(mm);
33420 }
33421+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33422+#define PREALLOCATED_PXDS USER_PGD_PTRS
33423 #else /* !CONFIG_X86_PAE */
33424
33425 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33426-#define PREALLOCATED_PMDS 0
33427+#define PREALLOCATED_PXDS 0
33428
33429 #endif /* CONFIG_X86_PAE */
33430
33431-static void free_pmds(pmd_t *pmds[])
33432+static void free_pxds(pxd_t *pxds[])
33433 {
33434 int i;
33435
33436- for(i = 0; i < PREALLOCATED_PMDS; i++)
33437- if (pmds[i]) {
33438- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33439- free_page((unsigned long)pmds[i]);
33440+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33441+ if (pxds[i]) {
33442+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33443+ free_page((unsigned long)pxds[i]);
33444 }
33445 }
33446
33447-static int preallocate_pmds(pmd_t *pmds[])
33448+static int preallocate_pxds(pxd_t *pxds[])
33449 {
33450 int i;
33451 bool failed = false;
33452
33453- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33454- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33455- if (!pmd)
33456+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33457+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33458+ if (!pxd)
33459 failed = true;
33460- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33461- free_page((unsigned long)pmd);
33462- pmd = NULL;
33463+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33464+ free_page((unsigned long)pxd);
33465+ pxd = NULL;
33466 failed = true;
33467 }
33468- pmds[i] = pmd;
33469+ pxds[i] = pxd;
33470 }
33471
33472 if (failed) {
33473- free_pmds(pmds);
33474+ free_pxds(pxds);
33475 return -ENOMEM;
33476 }
33477
33478@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33479 * preallocate which never got a corresponding vma will need to be
33480 * freed manually.
33481 */
33482-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33483+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33484 {
33485 int i;
33486
33487- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33488+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33489 pgd_t pgd = pgdp[i];
33490
33491 if (pgd_val(pgd) != 0) {
33492- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33493+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33494
33495- pgdp[i] = native_make_pgd(0);
33496+ set_pgd(pgdp + i, native_make_pgd(0));
33497
33498- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33499- pmd_free(mm, pmd);
33500+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33501+ pxd_free(mm, pxd);
33502 }
33503 }
33504 }
33505
33506-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33507+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33508 {
33509- pud_t *pud;
33510+ pyd_t *pyd;
33511 int i;
33512
33513- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33514+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33515 return;
33516
33517- pud = pud_offset(pgd, 0);
33518-
33519- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33520- pmd_t *pmd = pmds[i];
33521+#ifdef CONFIG_X86_64
33522+ pyd = pyd_offset(mm, 0L);
33523+#else
33524+ pyd = pyd_offset(pgd, 0L);
33525+#endif
33526
33527+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33528+ pxd_t *pxd = pxds[i];
33529 if (i >= KERNEL_PGD_BOUNDARY)
33530- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33531- sizeof(pmd_t) * PTRS_PER_PMD);
33532+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33533+ sizeof(pxd_t) * PTRS_PER_PMD);
33534
33535- pud_populate(mm, pud, pmd);
33536+ pyd_populate(mm, pyd, pxd);
33537 }
33538 }
33539
33540 pgd_t *pgd_alloc(struct mm_struct *mm)
33541 {
33542 pgd_t *pgd;
33543- pmd_t *pmds[PREALLOCATED_PMDS];
33544+ pxd_t *pxds[PREALLOCATED_PXDS];
33545
33546 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33547
33548@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33549
33550 mm->pgd = pgd;
33551
33552- if (preallocate_pmds(pmds) != 0)
33553+ if (preallocate_pxds(pxds) != 0)
33554 goto out_free_pgd;
33555
33556 if (paravirt_pgd_alloc(mm) != 0)
33557- goto out_free_pmds;
33558+ goto out_free_pxds;
33559
33560 /*
33561 * Make sure that pre-populating the pmds is atomic with
33562@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33563 spin_lock(&pgd_lock);
33564
33565 pgd_ctor(mm, pgd);
33566- pgd_prepopulate_pmd(mm, pgd, pmds);
33567+ pgd_prepopulate_pxd(mm, pgd, pxds);
33568
33569 spin_unlock(&pgd_lock);
33570
33571 return pgd;
33572
33573-out_free_pmds:
33574- free_pmds(pmds);
33575+out_free_pxds:
33576+ free_pxds(pxds);
33577 out_free_pgd:
33578 free_page((unsigned long)pgd);
33579 out:
33580@@ -313,7 +380,7 @@ out:
33581
33582 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33583 {
33584- pgd_mop_up_pmds(mm, pgd);
33585+ pgd_mop_up_pxds(mm, pgd);
33586 pgd_dtor(pgd);
33587 paravirt_pgd_free(mm, pgd);
33588 free_page((unsigned long)pgd);
33589diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33590index 4dd8cf6..f9d143e 100644
33591--- a/arch/x86/mm/pgtable_32.c
33592+++ b/arch/x86/mm/pgtable_32.c
33593@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33594 return;
33595 }
33596 pte = pte_offset_kernel(pmd, vaddr);
33597+
33598+ pax_open_kernel();
33599 if (pte_val(pteval))
33600 set_pte_at(&init_mm, vaddr, pte, pteval);
33601 else
33602 pte_clear(&init_mm, vaddr, pte);
33603+ pax_close_kernel();
33604
33605 /*
33606 * It's enough to flush this one mapping.
33607diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33608index e666cbb..61788c45 100644
33609--- a/arch/x86/mm/physaddr.c
33610+++ b/arch/x86/mm/physaddr.c
33611@@ -10,7 +10,7 @@
33612 #ifdef CONFIG_X86_64
33613
33614 #ifdef CONFIG_DEBUG_VIRTUAL
33615-unsigned long __phys_addr(unsigned long x)
33616+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33617 {
33618 unsigned long y = x - __START_KERNEL_map;
33619
33620@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33621 #else
33622
33623 #ifdef CONFIG_DEBUG_VIRTUAL
33624-unsigned long __phys_addr(unsigned long x)
33625+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33626 {
33627 unsigned long phys_addr = x - PAGE_OFFSET;
33628 /* VMALLOC_* aren't constants */
33629diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33630index 90555bf..f5f1828 100644
33631--- a/arch/x86/mm/setup_nx.c
33632+++ b/arch/x86/mm/setup_nx.c
33633@@ -5,8 +5,10 @@
33634 #include <asm/pgtable.h>
33635 #include <asm/proto.h>
33636
33637+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33638 static int disable_nx;
33639
33640+#ifndef CONFIG_PAX_PAGEEXEC
33641 /*
33642 * noexec = on|off
33643 *
33644@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33645 return 0;
33646 }
33647 early_param("noexec", noexec_setup);
33648+#endif
33649+
33650+#endif
33651
33652 void x86_configure_nx(void)
33653 {
33654+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33655 if (cpu_has_nx && !disable_nx)
33656 __supported_pte_mask |= _PAGE_NX;
33657 else
33658+#endif
33659 __supported_pte_mask &= ~_PAGE_NX;
33660 }
33661
33662diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33663index dd8dda1..9e9b0f6 100644
33664--- a/arch/x86/mm/tlb.c
33665+++ b/arch/x86/mm/tlb.c
33666@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33667 BUG();
33668 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33669 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33670+
33671+#ifndef CONFIG_PAX_PER_CPU_PGD
33672 load_cr3(swapper_pg_dir);
33673+#endif
33674+
33675 }
33676 }
33677 EXPORT_SYMBOL_GPL(leave_mm);
33678diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33679new file mode 100644
33680index 0000000..dace51c
33681--- /dev/null
33682+++ b/arch/x86/mm/uderef_64.c
33683@@ -0,0 +1,37 @@
33684+#include <linux/mm.h>
33685+#include <asm/pgtable.h>
33686+#include <asm/uaccess.h>
33687+
33688+#ifdef CONFIG_PAX_MEMORY_UDEREF
33689+/* PaX: due to the special call convention these functions must
33690+ * - remain leaf functions under all configurations,
33691+ * - never be called directly, only dereferenced from the wrappers.
33692+ */
33693+void __pax_open_userland(void)
33694+{
33695+ unsigned int cpu;
33696+
33697+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33698+ return;
33699+
33700+ cpu = raw_get_cpu();
33701+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33702+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33703+ raw_put_cpu_no_resched();
33704+}
33705+EXPORT_SYMBOL(__pax_open_userland);
33706+
33707+void __pax_close_userland(void)
33708+{
33709+ unsigned int cpu;
33710+
33711+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33712+ return;
33713+
33714+ cpu = raw_get_cpu();
33715+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33716+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33717+ raw_put_cpu_no_resched();
33718+}
33719+EXPORT_SYMBOL(__pax_close_userland);
33720+#endif
33721diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33722index 0149575..f746de8 100644
33723--- a/arch/x86/net/bpf_jit.S
33724+++ b/arch/x86/net/bpf_jit.S
33725@@ -9,6 +9,7 @@
33726 */
33727 #include <linux/linkage.h>
33728 #include <asm/dwarf2.h>
33729+#include <asm/alternative-asm.h>
33730
33731 /*
33732 * Calling convention :
33733@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33734 jle bpf_slow_path_word
33735 mov (SKBDATA,%rsi),%eax
33736 bswap %eax /* ntohl() */
33737+ pax_force_retaddr
33738 ret
33739
33740 sk_load_half:
33741@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33742 jle bpf_slow_path_half
33743 movzwl (SKBDATA,%rsi),%eax
33744 rol $8,%ax # ntohs()
33745+ pax_force_retaddr
33746 ret
33747
33748 sk_load_byte:
33749@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33750 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33751 jle bpf_slow_path_byte
33752 movzbl (SKBDATA,%rsi),%eax
33753+ pax_force_retaddr
33754 ret
33755
33756 /**
33757@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33758 movzbl (SKBDATA,%rsi),%ebx
33759 and $15,%bl
33760 shl $2,%bl
33761+ pax_force_retaddr
33762 ret
33763
33764 /* rsi contains offset and can be scratched */
33765@@ -109,6 +114,7 @@ bpf_slow_path_word:
33766 js bpf_error
33767 mov -12(%rbp),%eax
33768 bswap %eax
33769+ pax_force_retaddr
33770 ret
33771
33772 bpf_slow_path_half:
33773@@ -117,12 +123,14 @@ bpf_slow_path_half:
33774 mov -12(%rbp),%ax
33775 rol $8,%ax
33776 movzwl %ax,%eax
33777+ pax_force_retaddr
33778 ret
33779
33780 bpf_slow_path_byte:
33781 bpf_slow_path_common(1)
33782 js bpf_error
33783 movzbl -12(%rbp),%eax
33784+ pax_force_retaddr
33785 ret
33786
33787 bpf_slow_path_byte_msh:
33788@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33789 and $15,%al
33790 shl $2,%al
33791 xchg %eax,%ebx
33792+ pax_force_retaddr
33793 ret
33794
33795 #define sk_negative_common(SIZE) \
33796@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33797 sk_negative_common(4)
33798 mov (%rax), %eax
33799 bswap %eax
33800+ pax_force_retaddr
33801 ret
33802
33803 bpf_slow_path_half_neg:
33804@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33805 mov (%rax),%ax
33806 rol $8,%ax
33807 movzwl %ax,%eax
33808+ pax_force_retaddr
33809 ret
33810
33811 bpf_slow_path_byte_neg:
33812@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33813 .globl sk_load_byte_negative_offset
33814 sk_negative_common(1)
33815 movzbl (%rax), %eax
33816+ pax_force_retaddr
33817 ret
33818
33819 bpf_slow_path_byte_msh_neg:
33820@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33821 and $15,%al
33822 shl $2,%al
33823 xchg %eax,%ebx
33824+ pax_force_retaddr
33825 ret
33826
33827 bpf_error:
33828@@ -197,4 +210,5 @@ bpf_error:
33829 xor %eax,%eax
33830 mov -8(%rbp),%rbx
33831 leaveq
33832+ pax_force_retaddr
33833 ret
33834diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33835index 6d5663a..f1ec380 100644
33836--- a/arch/x86/net/bpf_jit_comp.c
33837+++ b/arch/x86/net/bpf_jit_comp.c
33838@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33839 return ptr + len;
33840 }
33841
33842+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33843+#define MAX_INSTR_CODE_SIZE 96
33844+#else
33845+#define MAX_INSTR_CODE_SIZE 64
33846+#endif
33847+
33848 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33849
33850 #define EMIT1(b1) EMIT(b1, 1)
33851 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33852 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33853 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33854+
33855+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33856+/* original constant will appear in ecx */
33857+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33858+do { \
33859+ /* mov ecx, randkey */ \
33860+ EMIT1(0xb9); \
33861+ EMIT(_key, 4); \
33862+ /* xor ecx, randkey ^ off */ \
33863+ EMIT2(0x81, 0xf1); \
33864+ EMIT((_key) ^ (_off), 4); \
33865+} while (0)
33866+
33867+#define EMIT1_off32(b1, _off) \
33868+do { \
33869+ switch (b1) { \
33870+ case 0x05: /* add eax, imm32 */ \
33871+ case 0x2d: /* sub eax, imm32 */ \
33872+ case 0x25: /* and eax, imm32 */ \
33873+ case 0x0d: /* or eax, imm32 */ \
33874+ case 0xb8: /* mov eax, imm32 */ \
33875+ case 0x35: /* xor eax, imm32 */ \
33876+ case 0x3d: /* cmp eax, imm32 */ \
33877+ case 0xa9: /* test eax, imm32 */ \
33878+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33879+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33880+ break; \
33881+ case 0xbb: /* mov ebx, imm32 */ \
33882+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33883+ /* mov ebx, ecx */ \
33884+ EMIT2(0x89, 0xcb); \
33885+ break; \
33886+ case 0xbe: /* mov esi, imm32 */ \
33887+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33888+ /* mov esi, ecx */ \
33889+ EMIT2(0x89, 0xce); \
33890+ break; \
33891+ case 0xe8: /* call rel imm32, always to known funcs */ \
33892+ EMIT1(b1); \
33893+ EMIT(_off, 4); \
33894+ break; \
33895+ case 0xe9: /* jmp rel imm32 */ \
33896+ EMIT1(b1); \
33897+ EMIT(_off, 4); \
33898+ /* prevent fall-through, we're not called if off = 0 */ \
33899+ EMIT(0xcccccccc, 4); \
33900+ EMIT(0xcccccccc, 4); \
33901+ break; \
33902+ default: \
33903+ BUILD_BUG(); \
33904+ } \
33905+} while (0)
33906+
33907+#define EMIT2_off32(b1, b2, _off) \
33908+do { \
33909+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33910+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33911+ EMIT(randkey, 4); \
33912+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33913+ EMIT((_off) - randkey, 4); \
33914+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33915+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33916+ /* imul eax, ecx */ \
33917+ EMIT3(0x0f, 0xaf, 0xc1); \
33918+ } else { \
33919+ BUILD_BUG(); \
33920+ } \
33921+} while (0)
33922+#else
33923 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33924+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33925+#endif
33926
33927 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33928 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33929@@ -91,6 +168,24 @@ do { \
33930 #define X86_JBE 0x76
33931 #define X86_JA 0x77
33932
33933+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33934+#define APPEND_FLOW_VERIFY() \
33935+do { \
33936+ /* mov ecx, randkey */ \
33937+ EMIT1(0xb9); \
33938+ EMIT(randkey, 4); \
33939+ /* cmp ecx, randkey */ \
33940+ EMIT2(0x81, 0xf9); \
33941+ EMIT(randkey, 4); \
33942+ /* jz after 8 int 3s */ \
33943+ EMIT2(0x74, 0x08); \
33944+ EMIT(0xcccccccc, 4); \
33945+ EMIT(0xcccccccc, 4); \
33946+} while (0)
33947+#else
33948+#define APPEND_FLOW_VERIFY() do { } while (0)
33949+#endif
33950+
33951 #define EMIT_COND_JMP(op, offset) \
33952 do { \
33953 if (is_near(offset)) \
33954@@ -98,6 +193,7 @@ do { \
33955 else { \
33956 EMIT2(0x0f, op + 0x10); \
33957 EMIT(offset, 4); /* jxx .+off32 */ \
33958+ APPEND_FLOW_VERIFY(); \
33959 } \
33960 } while (0)
33961
33962@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33963 return -1;
33964 }
33965
33966-struct bpf_binary_header {
33967- unsigned int pages;
33968- /* Note : for security reasons, bpf code will follow a randomly
33969- * sized amount of int3 instructions
33970- */
33971- u8 image[];
33972-};
33973-
33974-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33975+/* Note : for security reasons, bpf code will follow a randomly
33976+ * sized amount of int3 instructions
33977+ */
33978+static u8 *bpf_alloc_binary(unsigned int proglen,
33979 u8 **image_ptr)
33980 {
33981 unsigned int sz, hole;
33982- struct bpf_binary_header *header;
33983+ u8 *header;
33984
33985 /* Most of BPF filters are really small,
33986 * but if some of them fill a page, allow at least
33987 * 128 extra bytes to insert a random section of int3
33988 */
33989- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33990- header = module_alloc(sz);
33991+ sz = round_up(proglen + 128, PAGE_SIZE);
33992+ header = module_alloc_exec(sz);
33993 if (!header)
33994 return NULL;
33995
33996+ pax_open_kernel();
33997 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33998+ pax_close_kernel();
33999
34000- header->pages = sz / PAGE_SIZE;
34001- hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34002+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34003
34004 /* insert a random number of int3 instructions before BPF code */
34005- *image_ptr = &header->image[prandom_u32() % hole];
34006+ *image_ptr = &header[prandom_u32() % hole];
34007 return header;
34008 }
34009
34010 void bpf_jit_compile(struct sk_filter *fp)
34011 {
34012- u8 temp[64];
34013+ u8 temp[MAX_INSTR_CODE_SIZE];
34014 u8 *prog;
34015 unsigned int proglen, oldproglen = 0;
34016 int ilen, i;
34017 int t_offset, f_offset;
34018 u8 t_op, f_op, seen = 0, pass;
34019 u8 *image = NULL;
34020- struct bpf_binary_header *header = NULL;
34021+ u8 *header = NULL;
34022 u8 *func;
34023 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34024 unsigned int cleanup_addr; /* epilogue code offset */
34025 unsigned int *addrs;
34026 const struct sock_filter *filter = fp->insns;
34027 int flen = fp->len;
34028+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34029+ unsigned int randkey;
34030+#endif
34031
34032 if (!bpf_jit_enable)
34033 return;
34034@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34035 return;
34036
34037 /* Before first pass, make a rough estimation of addrs[]
34038- * each bpf instruction is translated to less than 64 bytes
34039+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34040 */
34041 for (proglen = 0, i = 0; i < flen; i++) {
34042- proglen += 64;
34043+ proglen += MAX_INSTR_CODE_SIZE;
34044 addrs[i] = proglen;
34045 }
34046 cleanup_addr = proglen; /* epilogue address */
34047@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34048 for (i = 0; i < flen; i++) {
34049 unsigned int K = filter[i].k;
34050
34051+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34052+ randkey = prandom_u32();
34053+#endif
34054+
34055 switch (filter[i].code) {
34056 case BPF_S_ALU_ADD_X: /* A += X; */
34057 seen |= SEEN_XREG;
34058@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34059 case BPF_S_ALU_MUL_K: /* A *= K */
34060 if (is_imm8(K))
34061 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34062- else {
34063- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34064- EMIT(K, 4);
34065- }
34066+ else
34067+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34068 break;
34069 case BPF_S_ALU_DIV_X: /* A /= X; */
34070 seen |= SEEN_XREG;
34071@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34072 break;
34073 }
34074 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34075+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34076+ DILUTE_CONST_SEQUENCE(K, randkey);
34077+#else
34078 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34079+#endif
34080 EMIT2(0xf7, 0xf1); /* div %ecx */
34081 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34082 break;
34083@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34084 if (K == 1)
34085 break;
34086 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34087+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34088+ DILUTE_CONST_SEQUENCE(K, randkey);
34089+#else
34090 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34091+#endif
34092 EMIT2(0xf7, 0xf1); /* div %ecx */
34093 break;
34094 case BPF_S_ALU_AND_X:
34095@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34096 if (is_imm8(K)) {
34097 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34098 } else {
34099- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34100- EMIT(K, 4);
34101+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34102 }
34103 } else {
34104 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34105@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34106 if (unlikely(proglen + ilen > oldproglen)) {
34107 pr_err("bpb_jit_compile fatal error\n");
34108 kfree(addrs);
34109- module_free(NULL, header);
34110+ module_free_exec(NULL, image);
34111 return;
34112 }
34113+ pax_open_kernel();
34114 memcpy(image + proglen, temp, ilen);
34115+ pax_close_kernel();
34116 }
34117 proglen += ilen;
34118 addrs[i] = proglen;
34119@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34120
34121 if (image) {
34122 bpf_flush_icache(header, image + proglen);
34123- set_memory_ro((unsigned long)header, header->pages);
34124 fp->bpf_func = (void *)image;
34125 fp->jited = 1;
34126 }
34127@@ -783,10 +888,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34128 {
34129 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34130 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34131- struct bpf_binary_header *header = (void *)addr;
34132
34133- set_memory_rw(addr, header->pages);
34134- module_free(NULL, header);
34135+ set_memory_rw(addr, 1);
34136+ module_free_exec(NULL, (void *)addr);
34137 kfree(fp);
34138 }
34139
34140diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34141index 5d04be5..2beeaa2 100644
34142--- a/arch/x86/oprofile/backtrace.c
34143+++ b/arch/x86/oprofile/backtrace.c
34144@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34145 struct stack_frame_ia32 *fp;
34146 unsigned long bytes;
34147
34148- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34149+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34150 if (bytes != 0)
34151 return NULL;
34152
34153- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34154+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34155
34156 oprofile_add_trace(bufhead[0].return_address);
34157
34158@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34159 struct stack_frame bufhead[2];
34160 unsigned long bytes;
34161
34162- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34163+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34164 if (bytes != 0)
34165 return NULL;
34166
34167@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34168 {
34169 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34170
34171- if (!user_mode_vm(regs)) {
34172+ if (!user_mode(regs)) {
34173 unsigned long stack = kernel_stack_pointer(regs);
34174 if (depth)
34175 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34176diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34177index 379e8bd..6386e09 100644
34178--- a/arch/x86/oprofile/nmi_int.c
34179+++ b/arch/x86/oprofile/nmi_int.c
34180@@ -23,6 +23,7 @@
34181 #include <asm/nmi.h>
34182 #include <asm/msr.h>
34183 #include <asm/apic.h>
34184+#include <asm/pgtable.h>
34185
34186 #include "op_counter.h"
34187 #include "op_x86_model.h"
34188@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34189 if (ret)
34190 return ret;
34191
34192- if (!model->num_virt_counters)
34193- model->num_virt_counters = model->num_counters;
34194+ if (!model->num_virt_counters) {
34195+ pax_open_kernel();
34196+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34197+ pax_close_kernel();
34198+ }
34199
34200 mux_init(ops);
34201
34202diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34203index 50d86c0..7985318 100644
34204--- a/arch/x86/oprofile/op_model_amd.c
34205+++ b/arch/x86/oprofile/op_model_amd.c
34206@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34207 num_counters = AMD64_NUM_COUNTERS;
34208 }
34209
34210- op_amd_spec.num_counters = num_counters;
34211- op_amd_spec.num_controls = num_counters;
34212- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34213+ pax_open_kernel();
34214+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34215+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34216+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34217+ pax_close_kernel();
34218
34219 return 0;
34220 }
34221diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34222index d90528e..0127e2b 100644
34223--- a/arch/x86/oprofile/op_model_ppro.c
34224+++ b/arch/x86/oprofile/op_model_ppro.c
34225@@ -19,6 +19,7 @@
34226 #include <asm/msr.h>
34227 #include <asm/apic.h>
34228 #include <asm/nmi.h>
34229+#include <asm/pgtable.h>
34230
34231 #include "op_x86_model.h"
34232 #include "op_counter.h"
34233@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34234
34235 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34236
34237- op_arch_perfmon_spec.num_counters = num_counters;
34238- op_arch_perfmon_spec.num_controls = num_counters;
34239+ pax_open_kernel();
34240+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34241+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34242+ pax_close_kernel();
34243 }
34244
34245 static int arch_perfmon_init(struct oprofile_operations *ignore)
34246diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34247index 71e8a67..6a313bb 100644
34248--- a/arch/x86/oprofile/op_x86_model.h
34249+++ b/arch/x86/oprofile/op_x86_model.h
34250@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34251 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34252 struct op_msrs const * const msrs);
34253 #endif
34254-};
34255+} __do_const;
34256
34257 struct op_counter_config;
34258
34259diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34260index 84b9d67..260e5ff 100644
34261--- a/arch/x86/pci/intel_mid_pci.c
34262+++ b/arch/x86/pci/intel_mid_pci.c
34263@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34264 pr_info("Intel MID platform detected, using MID PCI ops\n");
34265 pci_mmcfg_late_init();
34266 pcibios_enable_irq = intel_mid_pci_irq_enable;
34267- pci_root_ops = intel_mid_pci_ops;
34268+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34269 pci_soc_mode = 1;
34270 /* Continue with standard init */
34271 return 1;
34272diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34273index 84112f5..6334d60 100644
34274--- a/arch/x86/pci/irq.c
34275+++ b/arch/x86/pci/irq.c
34276@@ -50,7 +50,7 @@ struct irq_router {
34277 struct irq_router_handler {
34278 u16 vendor;
34279 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34280-};
34281+} __do_const;
34282
34283 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34284 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34285@@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34286 return 0;
34287 }
34288
34289-static __initdata struct irq_router_handler pirq_routers[] = {
34290+static __initconst const struct irq_router_handler pirq_routers[] = {
34291 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34292 { PCI_VENDOR_ID_AL, ali_router_probe },
34293 { PCI_VENDOR_ID_ITE, ite_router_probe },
34294@@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
34295 static void __init pirq_find_router(struct irq_router *r)
34296 {
34297 struct irq_routing_table *rt = pirq_table;
34298- struct irq_router_handler *h;
34299+ const struct irq_router_handler *h;
34300
34301 #ifdef CONFIG_PCI_BIOS
34302 if (!rt->signature) {
34303@@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34304 return 0;
34305 }
34306
34307-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34308+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34309 {
34310 .callback = fix_broken_hp_bios_irq9,
34311 .ident = "HP Pavilion N5400 Series Laptop",
34312diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34313index c77b24a..c979855 100644
34314--- a/arch/x86/pci/pcbios.c
34315+++ b/arch/x86/pci/pcbios.c
34316@@ -79,7 +79,7 @@ union bios32 {
34317 static struct {
34318 unsigned long address;
34319 unsigned short segment;
34320-} bios32_indirect = { 0, __KERNEL_CS };
34321+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34322
34323 /*
34324 * Returns the entry point for the given service, NULL on error
34325@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34326 unsigned long length; /* %ecx */
34327 unsigned long entry; /* %edx */
34328 unsigned long flags;
34329+ struct desc_struct d, *gdt;
34330
34331 local_irq_save(flags);
34332- __asm__("lcall *(%%edi); cld"
34333+
34334+ gdt = get_cpu_gdt_table(smp_processor_id());
34335+
34336+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34337+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34338+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34339+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34340+
34341+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34342 : "=a" (return_code),
34343 "=b" (address),
34344 "=c" (length),
34345 "=d" (entry)
34346 : "0" (service),
34347 "1" (0),
34348- "D" (&bios32_indirect));
34349+ "D" (&bios32_indirect),
34350+ "r"(__PCIBIOS_DS)
34351+ : "memory");
34352+
34353+ pax_open_kernel();
34354+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34355+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34356+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34357+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34358+ pax_close_kernel();
34359+
34360 local_irq_restore(flags);
34361
34362 switch (return_code) {
34363- case 0:
34364- return address + entry;
34365- case 0x80: /* Not present */
34366- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34367- return 0;
34368- default: /* Shouldn't happen */
34369- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34370- service, return_code);
34371+ case 0: {
34372+ int cpu;
34373+ unsigned char flags;
34374+
34375+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34376+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34377+ printk(KERN_WARNING "bios32_service: not valid\n");
34378 return 0;
34379+ }
34380+ address = address + PAGE_OFFSET;
34381+ length += 16UL; /* some BIOSs underreport this... */
34382+ flags = 4;
34383+ if (length >= 64*1024*1024) {
34384+ length >>= PAGE_SHIFT;
34385+ flags |= 8;
34386+ }
34387+
34388+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34389+ gdt = get_cpu_gdt_table(cpu);
34390+ pack_descriptor(&d, address, length, 0x9b, flags);
34391+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34392+ pack_descriptor(&d, address, length, 0x93, flags);
34393+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34394+ }
34395+ return entry;
34396+ }
34397+ case 0x80: /* Not present */
34398+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34399+ return 0;
34400+ default: /* Shouldn't happen */
34401+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34402+ service, return_code);
34403+ return 0;
34404 }
34405 }
34406
34407 static struct {
34408 unsigned long address;
34409 unsigned short segment;
34410-} pci_indirect = { 0, __KERNEL_CS };
34411+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34412
34413-static int pci_bios_present;
34414+static int pci_bios_present __read_only;
34415
34416 static int check_pcibios(void)
34417 {
34418@@ -131,11 +174,13 @@ static int check_pcibios(void)
34419 unsigned long flags, pcibios_entry;
34420
34421 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34422- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34423+ pci_indirect.address = pcibios_entry;
34424
34425 local_irq_save(flags);
34426- __asm__(
34427- "lcall *(%%edi); cld\n\t"
34428+ __asm__("movw %w6, %%ds\n\t"
34429+ "lcall *%%ss:(%%edi); cld\n\t"
34430+ "push %%ss\n\t"
34431+ "pop %%ds\n\t"
34432 "jc 1f\n\t"
34433 "xor %%ah, %%ah\n"
34434 "1:"
34435@@ -144,7 +189,8 @@ static int check_pcibios(void)
34436 "=b" (ebx),
34437 "=c" (ecx)
34438 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34439- "D" (&pci_indirect)
34440+ "D" (&pci_indirect),
34441+ "r" (__PCIBIOS_DS)
34442 : "memory");
34443 local_irq_restore(flags);
34444
34445@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34446
34447 switch (len) {
34448 case 1:
34449- __asm__("lcall *(%%esi); cld\n\t"
34450+ __asm__("movw %w6, %%ds\n\t"
34451+ "lcall *%%ss:(%%esi); cld\n\t"
34452+ "push %%ss\n\t"
34453+ "pop %%ds\n\t"
34454 "jc 1f\n\t"
34455 "xor %%ah, %%ah\n"
34456 "1:"
34457@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34458 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34459 "b" (bx),
34460 "D" ((long)reg),
34461- "S" (&pci_indirect));
34462+ "S" (&pci_indirect),
34463+ "r" (__PCIBIOS_DS));
34464 /*
34465 * Zero-extend the result beyond 8 bits, do not trust the
34466 * BIOS having done it:
34467@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34468 *value &= 0xff;
34469 break;
34470 case 2:
34471- __asm__("lcall *(%%esi); cld\n\t"
34472+ __asm__("movw %w6, %%ds\n\t"
34473+ "lcall *%%ss:(%%esi); cld\n\t"
34474+ "push %%ss\n\t"
34475+ "pop %%ds\n\t"
34476 "jc 1f\n\t"
34477 "xor %%ah, %%ah\n"
34478 "1:"
34479@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34480 : "1" (PCIBIOS_READ_CONFIG_WORD),
34481 "b" (bx),
34482 "D" ((long)reg),
34483- "S" (&pci_indirect));
34484+ "S" (&pci_indirect),
34485+ "r" (__PCIBIOS_DS));
34486 /*
34487 * Zero-extend the result beyond 16 bits, do not trust the
34488 * BIOS having done it:
34489@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34490 *value &= 0xffff;
34491 break;
34492 case 4:
34493- __asm__("lcall *(%%esi); cld\n\t"
34494+ __asm__("movw %w6, %%ds\n\t"
34495+ "lcall *%%ss:(%%esi); cld\n\t"
34496+ "push %%ss\n\t"
34497+ "pop %%ds\n\t"
34498 "jc 1f\n\t"
34499 "xor %%ah, %%ah\n"
34500 "1:"
34501@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34502 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34503 "b" (bx),
34504 "D" ((long)reg),
34505- "S" (&pci_indirect));
34506+ "S" (&pci_indirect),
34507+ "r" (__PCIBIOS_DS));
34508 break;
34509 }
34510
34511@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34512
34513 switch (len) {
34514 case 1:
34515- __asm__("lcall *(%%esi); cld\n\t"
34516+ __asm__("movw %w6, %%ds\n\t"
34517+ "lcall *%%ss:(%%esi); cld\n\t"
34518+ "push %%ss\n\t"
34519+ "pop %%ds\n\t"
34520 "jc 1f\n\t"
34521 "xor %%ah, %%ah\n"
34522 "1:"
34523@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34524 "c" (value),
34525 "b" (bx),
34526 "D" ((long)reg),
34527- "S" (&pci_indirect));
34528+ "S" (&pci_indirect),
34529+ "r" (__PCIBIOS_DS));
34530 break;
34531 case 2:
34532- __asm__("lcall *(%%esi); cld\n\t"
34533+ __asm__("movw %w6, %%ds\n\t"
34534+ "lcall *%%ss:(%%esi); cld\n\t"
34535+ "push %%ss\n\t"
34536+ "pop %%ds\n\t"
34537 "jc 1f\n\t"
34538 "xor %%ah, %%ah\n"
34539 "1:"
34540@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34541 "c" (value),
34542 "b" (bx),
34543 "D" ((long)reg),
34544- "S" (&pci_indirect));
34545+ "S" (&pci_indirect),
34546+ "r" (__PCIBIOS_DS));
34547 break;
34548 case 4:
34549- __asm__("lcall *(%%esi); cld\n\t"
34550+ __asm__("movw %w6, %%ds\n\t"
34551+ "lcall *%%ss:(%%esi); cld\n\t"
34552+ "push %%ss\n\t"
34553+ "pop %%ds\n\t"
34554 "jc 1f\n\t"
34555 "xor %%ah, %%ah\n"
34556 "1:"
34557@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34558 "c" (value),
34559 "b" (bx),
34560 "D" ((long)reg),
34561- "S" (&pci_indirect));
34562+ "S" (&pci_indirect),
34563+ "r" (__PCIBIOS_DS));
34564 break;
34565 }
34566
34567@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34568
34569 DBG("PCI: Fetching IRQ routing table... ");
34570 __asm__("push %%es\n\t"
34571+ "movw %w8, %%ds\n\t"
34572 "push %%ds\n\t"
34573 "pop %%es\n\t"
34574- "lcall *(%%esi); cld\n\t"
34575+ "lcall *%%ss:(%%esi); cld\n\t"
34576 "pop %%es\n\t"
34577+ "push %%ss\n\t"
34578+ "pop %%ds\n"
34579 "jc 1f\n\t"
34580 "xor %%ah, %%ah\n"
34581 "1:"
34582@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34583 "1" (0),
34584 "D" ((long) &opt),
34585 "S" (&pci_indirect),
34586- "m" (opt)
34587+ "m" (opt),
34588+ "r" (__PCIBIOS_DS)
34589 : "memory");
34590 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34591 if (ret & 0xff00)
34592@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34593 {
34594 int ret;
34595
34596- __asm__("lcall *(%%esi); cld\n\t"
34597+ __asm__("movw %w5, %%ds\n\t"
34598+ "lcall *%%ss:(%%esi); cld\n\t"
34599+ "push %%ss\n\t"
34600+ "pop %%ds\n"
34601 "jc 1f\n\t"
34602 "xor %%ah, %%ah\n"
34603 "1:"
34604@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34605 : "0" (PCIBIOS_SET_PCI_HW_INT),
34606 "b" ((dev->bus->number << 8) | dev->devfn),
34607 "c" ((irq << 8) | (pin + 10)),
34608- "S" (&pci_indirect));
34609+ "S" (&pci_indirect),
34610+ "r" (__PCIBIOS_DS));
34611 return !(ret & 0xff00);
34612 }
34613 EXPORT_SYMBOL(pcibios_set_irq_routing);
34614diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34615index 9ee3491..872192f 100644
34616--- a/arch/x86/platform/efi/efi_32.c
34617+++ b/arch/x86/platform/efi/efi_32.c
34618@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34619 {
34620 struct desc_ptr gdt_descr;
34621
34622+#ifdef CONFIG_PAX_KERNEXEC
34623+ struct desc_struct d;
34624+#endif
34625+
34626 local_irq_save(efi_rt_eflags);
34627
34628 load_cr3(initial_page_table);
34629 __flush_tlb_all();
34630
34631+#ifdef CONFIG_PAX_KERNEXEC
34632+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34633+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34634+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34635+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34636+#endif
34637+
34638 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34639 gdt_descr.size = GDT_SIZE - 1;
34640 load_gdt(&gdt_descr);
34641@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34642 {
34643 struct desc_ptr gdt_descr;
34644
34645+#ifdef CONFIG_PAX_KERNEXEC
34646+ struct desc_struct d;
34647+
34648+ memset(&d, 0, sizeof d);
34649+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34650+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34651+#endif
34652+
34653 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34654 gdt_descr.size = GDT_SIZE - 1;
34655 load_gdt(&gdt_descr);
34656
34657+#ifdef CONFIG_PAX_PER_CPU_PGD
34658+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34659+#else
34660 load_cr3(swapper_pg_dir);
34661+#endif
34662+
34663 __flush_tlb_all();
34664
34665 local_irq_restore(efi_rt_eflags);
34666diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34667index 290d397..3906bcd 100644
34668--- a/arch/x86/platform/efi/efi_64.c
34669+++ b/arch/x86/platform/efi/efi_64.c
34670@@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
34671 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34672 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34673 }
34674+
34675+#ifdef CONFIG_PAX_PER_CPU_PGD
34676+ load_cr3(swapper_pg_dir);
34677+#endif
34678+
34679 __flush_tlb_all();
34680 }
34681
34682@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34683 for (pgd = 0; pgd < n_pgds; pgd++)
34684 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34685 kfree(save_pgd);
34686+
34687+#ifdef CONFIG_PAX_PER_CPU_PGD
34688+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34689+#endif
34690+
34691 __flush_tlb_all();
34692 local_irq_restore(efi_flags);
34693 early_code_mapping_set_exec(0);
34694diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34695index fbe66e6..eae5e38 100644
34696--- a/arch/x86/platform/efi/efi_stub_32.S
34697+++ b/arch/x86/platform/efi/efi_stub_32.S
34698@@ -6,7 +6,9 @@
34699 */
34700
34701 #include <linux/linkage.h>
34702+#include <linux/init.h>
34703 #include <asm/page_types.h>
34704+#include <asm/segment.h>
34705
34706 /*
34707 * efi_call_phys(void *, ...) is a function with variable parameters.
34708@@ -20,7 +22,7 @@
34709 * service functions will comply with gcc calling convention, too.
34710 */
34711
34712-.text
34713+__INIT
34714 ENTRY(efi_call_phys)
34715 /*
34716 * 0. The function can only be called in Linux kernel. So CS has been
34717@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34718 * The mapping of lower virtual memory has been created in prelog and
34719 * epilog.
34720 */
34721- movl $1f, %edx
34722- subl $__PAGE_OFFSET, %edx
34723- jmp *%edx
34724+#ifdef CONFIG_PAX_KERNEXEC
34725+ movl $(__KERNEXEC_EFI_DS), %edx
34726+ mov %edx, %ds
34727+ mov %edx, %es
34728+ mov %edx, %ss
34729+ addl $2f,(1f)
34730+ ljmp *(1f)
34731+
34732+__INITDATA
34733+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34734+.previous
34735+
34736+2:
34737+ subl $2b,(1b)
34738+#else
34739+ jmp 1f-__PAGE_OFFSET
34740 1:
34741+#endif
34742
34743 /*
34744 * 2. Now on the top of stack is the return
34745@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34746 * parameter 2, ..., param n. To make things easy, we save the return
34747 * address of efi_call_phys in a global variable.
34748 */
34749- popl %edx
34750- movl %edx, saved_return_addr
34751- /* get the function pointer into ECX*/
34752- popl %ecx
34753- movl %ecx, efi_rt_function_ptr
34754- movl $2f, %edx
34755- subl $__PAGE_OFFSET, %edx
34756- pushl %edx
34757+ popl (saved_return_addr)
34758+ popl (efi_rt_function_ptr)
34759
34760 /*
34761 * 3. Clear PG bit in %CR0.
34762@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34763 /*
34764 * 5. Call the physical function.
34765 */
34766- jmp *%ecx
34767+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34768
34769-2:
34770 /*
34771 * 6. After EFI runtime service returns, control will return to
34772 * following instruction. We'd better readjust stack pointer first.
34773@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34774 movl %cr0, %edx
34775 orl $0x80000000, %edx
34776 movl %edx, %cr0
34777- jmp 1f
34778-1:
34779+
34780 /*
34781 * 8. Now restore the virtual mode from flat mode by
34782 * adding EIP with PAGE_OFFSET.
34783 */
34784- movl $1f, %edx
34785- jmp *%edx
34786+#ifdef CONFIG_PAX_KERNEXEC
34787+ movl $(__KERNEL_DS), %edx
34788+ mov %edx, %ds
34789+ mov %edx, %es
34790+ mov %edx, %ss
34791+ ljmp $(__KERNEL_CS),$1f
34792+#else
34793+ jmp 1f+__PAGE_OFFSET
34794+#endif
34795 1:
34796
34797 /*
34798 * 9. Balance the stack. And because EAX contain the return value,
34799 * we'd better not clobber it.
34800 */
34801- leal efi_rt_function_ptr, %edx
34802- movl (%edx), %ecx
34803- pushl %ecx
34804+ pushl (efi_rt_function_ptr)
34805
34806 /*
34807- * 10. Push the saved return address onto the stack and return.
34808+ * 10. Return to the saved return address.
34809 */
34810- leal saved_return_addr, %edx
34811- movl (%edx), %ecx
34812- pushl %ecx
34813- ret
34814+ jmpl *(saved_return_addr)
34815 ENDPROC(efi_call_phys)
34816 .previous
34817
34818-.data
34819+__INITDATA
34820 saved_return_addr:
34821 .long 0
34822 efi_rt_function_ptr:
34823diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34824index e0984ef..a062dac 100644
34825--- a/arch/x86/platform/efi/efi_stub_64.S
34826+++ b/arch/x86/platform/efi/efi_stub_64.S
34827@@ -11,6 +11,7 @@
34828 #include <asm/msr.h>
34829 #include <asm/processor-flags.h>
34830 #include <asm/page_types.h>
34831+#include <asm/alternative-asm.h>
34832
34833 #define SAVE_XMM \
34834 mov %rsp, %rax; \
34835@@ -81,6 +82,7 @@ ENTRY(efi_call0)
34836 RESTORE_PGT
34837 addq $32, %rsp
34838 RESTORE_XMM
34839+ pax_force_retaddr 0, 1
34840 ret
34841 ENDPROC(efi_call0)
34842
34843@@ -93,6 +95,7 @@ ENTRY(efi_call1)
34844 RESTORE_PGT
34845 addq $32, %rsp
34846 RESTORE_XMM
34847+ pax_force_retaddr 0, 1
34848 ret
34849 ENDPROC(efi_call1)
34850
34851@@ -105,6 +108,7 @@ ENTRY(efi_call2)
34852 RESTORE_PGT
34853 addq $32, %rsp
34854 RESTORE_XMM
34855+ pax_force_retaddr 0, 1
34856 ret
34857 ENDPROC(efi_call2)
34858
34859@@ -118,6 +122,7 @@ ENTRY(efi_call3)
34860 RESTORE_PGT
34861 addq $32, %rsp
34862 RESTORE_XMM
34863+ pax_force_retaddr 0, 1
34864 ret
34865 ENDPROC(efi_call3)
34866
34867@@ -132,6 +137,7 @@ ENTRY(efi_call4)
34868 RESTORE_PGT
34869 addq $32, %rsp
34870 RESTORE_XMM
34871+ pax_force_retaddr 0, 1
34872 ret
34873 ENDPROC(efi_call4)
34874
34875@@ -147,6 +153,7 @@ ENTRY(efi_call5)
34876 RESTORE_PGT
34877 addq $48, %rsp
34878 RESTORE_XMM
34879+ pax_force_retaddr 0, 1
34880 ret
34881 ENDPROC(efi_call5)
34882
34883@@ -165,6 +172,7 @@ ENTRY(efi_call6)
34884 RESTORE_PGT
34885 addq $48, %rsp
34886 RESTORE_XMM
34887+ pax_force_retaddr 0, 1
34888 ret
34889 ENDPROC(efi_call6)
34890
34891diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34892index 1bbedc4..eb795b5 100644
34893--- a/arch/x86/platform/intel-mid/intel-mid.c
34894+++ b/arch/x86/platform/intel-mid/intel-mid.c
34895@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34896 {
34897 };
34898
34899-static void intel_mid_reboot(void)
34900+static void __noreturn intel_mid_reboot(void)
34901 {
34902 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34903+ BUG();
34904 }
34905
34906 static unsigned long __init intel_mid_calibrate_tsc(void)
34907diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34908index d6ee929..3637cb5 100644
34909--- a/arch/x86/platform/olpc/olpc_dt.c
34910+++ b/arch/x86/platform/olpc/olpc_dt.c
34911@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34912 return res;
34913 }
34914
34915-static struct of_pdt_ops prom_olpc_ops __initdata = {
34916+static struct of_pdt_ops prom_olpc_ops __initconst = {
34917 .nextprop = olpc_dt_nextprop,
34918 .getproplen = olpc_dt_getproplen,
34919 .getproperty = olpc_dt_getproperty,
34920diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34921index 424f4c9..f2a2988 100644
34922--- a/arch/x86/power/cpu.c
34923+++ b/arch/x86/power/cpu.c
34924@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34925 static void fix_processor_context(void)
34926 {
34927 int cpu = smp_processor_id();
34928- struct tss_struct *t = &per_cpu(init_tss, cpu);
34929-#ifdef CONFIG_X86_64
34930- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34931- tss_desc tss;
34932-#endif
34933+ struct tss_struct *t = init_tss + cpu;
34934+
34935 set_tss_desc(cpu, t); /*
34936 * This just modifies memory; should not be
34937 * necessary. But... This is necessary, because
34938@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34939 */
34940
34941 #ifdef CONFIG_X86_64
34942- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34943- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34944- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34945-
34946 syscall_init(); /* This sets MSR_*STAR and related */
34947 #endif
34948 load_TR_desc(); /* This does ltr */
34949diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34950index bad628a..a102610 100644
34951--- a/arch/x86/realmode/init.c
34952+++ b/arch/x86/realmode/init.c
34953@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34954 __va(real_mode_header->trampoline_header);
34955
34956 #ifdef CONFIG_X86_32
34957- trampoline_header->start = __pa_symbol(startup_32_smp);
34958+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34959+
34960+#ifdef CONFIG_PAX_KERNEXEC
34961+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34962+#endif
34963+
34964+ trampoline_header->boot_cs = __BOOT_CS;
34965 trampoline_header->gdt_limit = __BOOT_DS + 7;
34966 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34967 #else
34968@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34969 *trampoline_cr4_features = read_cr4();
34970
34971 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34972- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34973+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34974 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34975 #endif
34976 }
34977diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34978index 3497f14..cc73b92 100644
34979--- a/arch/x86/realmode/rm/Makefile
34980+++ b/arch/x86/realmode/rm/Makefile
34981@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34982
34983 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34984 -I$(srctree)/arch/x86/boot
34985+ifdef CONSTIFY_PLUGIN
34986+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34987+endif
34988 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34989 GCOV_PROFILE := n
34990diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34991index a28221d..93c40f1 100644
34992--- a/arch/x86/realmode/rm/header.S
34993+++ b/arch/x86/realmode/rm/header.S
34994@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34995 #endif
34996 /* APM/BIOS reboot */
34997 .long pa_machine_real_restart_asm
34998-#ifdef CONFIG_X86_64
34999+#ifdef CONFIG_X86_32
35000+ .long __KERNEL_CS
35001+#else
35002 .long __KERNEL32_CS
35003 #endif
35004 END(real_mode_header)
35005diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35006index 48ddd76..c26749f 100644
35007--- a/arch/x86/realmode/rm/trampoline_32.S
35008+++ b/arch/x86/realmode/rm/trampoline_32.S
35009@@ -24,6 +24,12 @@
35010 #include <asm/page_types.h>
35011 #include "realmode.h"
35012
35013+#ifdef CONFIG_PAX_KERNEXEC
35014+#define ta(X) (X)
35015+#else
35016+#define ta(X) (pa_ ## X)
35017+#endif
35018+
35019 .text
35020 .code16
35021
35022@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35023
35024 cli # We should be safe anyway
35025
35026- movl tr_start, %eax # where we need to go
35027-
35028 movl $0xA5A5A5A5, trampoline_status
35029 # write marker for master knows we're running
35030
35031@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35032 movw $1, %dx # protected mode (PE) bit
35033 lmsw %dx # into protected mode
35034
35035- ljmpl $__BOOT_CS, $pa_startup_32
35036+ ljmpl *(trampoline_header)
35037
35038 .section ".text32","ax"
35039 .code32
35040@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35041 .balign 8
35042 GLOBAL(trampoline_header)
35043 tr_start: .space 4
35044- tr_gdt_pad: .space 2
35045+ tr_boot_cs: .space 2
35046 tr_gdt: .space 6
35047 END(trampoline_header)
35048
35049diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35050index dac7b20..72dbaca 100644
35051--- a/arch/x86/realmode/rm/trampoline_64.S
35052+++ b/arch/x86/realmode/rm/trampoline_64.S
35053@@ -93,6 +93,7 @@ ENTRY(startup_32)
35054 movl %edx, %gs
35055
35056 movl pa_tr_cr4, %eax
35057+ andl $~X86_CR4_PCIDE, %eax
35058 movl %eax, %cr4 # Enable PAE mode
35059
35060 # Setup trampoline 4 level pagetables
35061@@ -106,7 +107,7 @@ ENTRY(startup_32)
35062 wrmsr
35063
35064 # Enable paging and in turn activate Long Mode
35065- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35066+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35067 movl %eax, %cr0
35068
35069 /*
35070diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35071index 9e7e147..25a4158 100644
35072--- a/arch/x86/realmode/rm/wakeup_asm.S
35073+++ b/arch/x86/realmode/rm/wakeup_asm.S
35074@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35075 lgdtl pmode_gdt
35076
35077 /* This really couldn't... */
35078- movl pmode_entry, %eax
35079 movl pmode_cr0, %ecx
35080 movl %ecx, %cr0
35081- ljmpl $__KERNEL_CS, $pa_startup_32
35082- /* -> jmp *%eax in trampoline_32.S */
35083+
35084+ ljmpl *pmode_entry
35085 #else
35086 jmp trampoline_start
35087 #endif
35088diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35089index 604a37e..e49702a 100644
35090--- a/arch/x86/tools/Makefile
35091+++ b/arch/x86/tools/Makefile
35092@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35093
35094 $(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
35095
35096-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35097+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35098 hostprogs-y += relocs
35099 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35100 PHONY += relocs
35101diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35102index bbb1d22..e505211 100644
35103--- a/arch/x86/tools/relocs.c
35104+++ b/arch/x86/tools/relocs.c
35105@@ -1,5 +1,7 @@
35106 /* This is included from relocs_32/64.c */
35107
35108+#include "../../../include/generated/autoconf.h"
35109+
35110 #define ElfW(type) _ElfW(ELF_BITS, type)
35111 #define _ElfW(bits, type) __ElfW(bits, type)
35112 #define __ElfW(bits, type) Elf##bits##_##type
35113@@ -11,6 +13,7 @@
35114 #define Elf_Sym ElfW(Sym)
35115
35116 static Elf_Ehdr ehdr;
35117+static Elf_Phdr *phdr;
35118
35119 struct relocs {
35120 uint32_t *offset;
35121@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35122 }
35123 }
35124
35125+static void read_phdrs(FILE *fp)
35126+{
35127+ unsigned int i;
35128+
35129+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35130+ if (!phdr) {
35131+ die("Unable to allocate %d program headers\n",
35132+ ehdr.e_phnum);
35133+ }
35134+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35135+ die("Seek to %d failed: %s\n",
35136+ ehdr.e_phoff, strerror(errno));
35137+ }
35138+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35139+ die("Cannot read ELF program headers: %s\n",
35140+ strerror(errno));
35141+ }
35142+ for(i = 0; i < ehdr.e_phnum; i++) {
35143+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35144+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35145+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35146+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35147+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35148+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35149+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35150+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35151+ }
35152+
35153+}
35154+
35155 static void read_shdrs(FILE *fp)
35156 {
35157- int i;
35158+ unsigned int i;
35159 Elf_Shdr shdr;
35160
35161 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35162@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35163
35164 static void read_strtabs(FILE *fp)
35165 {
35166- int i;
35167+ unsigned int i;
35168 for (i = 0; i < ehdr.e_shnum; i++) {
35169 struct section *sec = &secs[i];
35170 if (sec->shdr.sh_type != SHT_STRTAB) {
35171@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35172
35173 static void read_symtabs(FILE *fp)
35174 {
35175- int i,j;
35176+ unsigned int i,j;
35177 for (i = 0; i < ehdr.e_shnum; i++) {
35178 struct section *sec = &secs[i];
35179 if (sec->shdr.sh_type != SHT_SYMTAB) {
35180@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35181 }
35182
35183
35184-static void read_relocs(FILE *fp)
35185+static void read_relocs(FILE *fp, int use_real_mode)
35186 {
35187- int i,j;
35188+ unsigned int i,j;
35189+ uint32_t base;
35190+
35191 for (i = 0; i < ehdr.e_shnum; i++) {
35192 struct section *sec = &secs[i];
35193 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35194@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35195 die("Cannot read symbol table: %s\n",
35196 strerror(errno));
35197 }
35198+ base = 0;
35199+
35200+#ifdef CONFIG_X86_32
35201+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35202+ if (phdr[j].p_type != PT_LOAD )
35203+ continue;
35204+ 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)
35205+ continue;
35206+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35207+ break;
35208+ }
35209+#endif
35210+
35211 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35212 Elf_Rel *rel = &sec->reltab[j];
35213- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35214+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35215 rel->r_info = elf_xword_to_cpu(rel->r_info);
35216 #if (SHT_REL_TYPE == SHT_RELA)
35217 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35218@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35219
35220 static void print_absolute_symbols(void)
35221 {
35222- int i;
35223+ unsigned int i;
35224 const char *format;
35225
35226 if (ELF_BITS == 64)
35227@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35228 for (i = 0; i < ehdr.e_shnum; i++) {
35229 struct section *sec = &secs[i];
35230 char *sym_strtab;
35231- int j;
35232+ unsigned int j;
35233
35234 if (sec->shdr.sh_type != SHT_SYMTAB) {
35235 continue;
35236@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35237
35238 static void print_absolute_relocs(void)
35239 {
35240- int i, printed = 0;
35241+ unsigned int i, printed = 0;
35242 const char *format;
35243
35244 if (ELF_BITS == 64)
35245@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35246 struct section *sec_applies, *sec_symtab;
35247 char *sym_strtab;
35248 Elf_Sym *sh_symtab;
35249- int j;
35250+ unsigned int j;
35251 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35252 continue;
35253 }
35254@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35255 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35256 Elf_Sym *sym, const char *symname))
35257 {
35258- int i;
35259+ unsigned int i;
35260 /* Walk through the relocations */
35261 for (i = 0; i < ehdr.e_shnum; i++) {
35262 char *sym_strtab;
35263 Elf_Sym *sh_symtab;
35264 struct section *sec_applies, *sec_symtab;
35265- int j;
35266+ unsigned int j;
35267 struct section *sec = &secs[i];
35268
35269 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35270@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35271 {
35272 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35273 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35274+ char *sym_strtab = sec->link->link->strtab;
35275+
35276+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35277+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35278+ return 0;
35279+
35280+#ifdef CONFIG_PAX_KERNEXEC
35281+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35282+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35283+ return 0;
35284+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35285+ return 0;
35286+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35287+ return 0;
35288+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35289+ return 0;
35290+#endif
35291
35292 switch (r_type) {
35293 case R_386_NONE:
35294@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35295
35296 static void emit_relocs(int as_text, int use_real_mode)
35297 {
35298- int i;
35299+ unsigned int i;
35300 int (*write_reloc)(uint32_t, FILE *) = write32;
35301 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35302 const char *symname);
35303@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35304 {
35305 regex_init(use_real_mode);
35306 read_ehdr(fp);
35307+ read_phdrs(fp);
35308 read_shdrs(fp);
35309 read_strtabs(fp);
35310 read_symtabs(fp);
35311- read_relocs(fp);
35312+ read_relocs(fp, use_real_mode);
35313 if (ELF_BITS == 64)
35314 percpu_init();
35315 if (show_absolute_syms) {
35316diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35317index f40281e..92728c9 100644
35318--- a/arch/x86/um/mem_32.c
35319+++ b/arch/x86/um/mem_32.c
35320@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35321 gate_vma.vm_start = FIXADDR_USER_START;
35322 gate_vma.vm_end = FIXADDR_USER_END;
35323 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35324- gate_vma.vm_page_prot = __P101;
35325+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35326
35327 return 0;
35328 }
35329diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35330index 80ffa5b..a33bd15 100644
35331--- a/arch/x86/um/tls_32.c
35332+++ b/arch/x86/um/tls_32.c
35333@@ -260,7 +260,7 @@ out:
35334 if (unlikely(task == current &&
35335 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35336 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35337- "without flushed TLS.", current->pid);
35338+ "without flushed TLS.", task_pid_nr(current));
35339 }
35340
35341 return 0;
35342diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35343index c580d12..0a0ba35 100644
35344--- a/arch/x86/vdso/Makefile
35345+++ b/arch/x86/vdso/Makefile
35346@@ -196,7 +196,7 @@ quiet_cmd_vdso = VDSO $@
35347 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35348 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35349
35350-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35351+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35352 $(LTO_CFLAGS)
35353 GCOV_PROFILE := n
35354
35355diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35356index 310c5f0..766d0a7 100644
35357--- a/arch/x86/vdso/vdso32-setup.c
35358+++ b/arch/x86/vdso/vdso32-setup.c
35359@@ -29,6 +29,7 @@
35360 #include <asm/fixmap.h>
35361 #include <asm/hpet.h>
35362 #include <asm/vvar.h>
35363+#include <asm/mman.h>
35364
35365 #ifdef CONFIG_COMPAT_VDSO
35366 #define VDSO_DEFAULT 0
35367@@ -99,7 +100,7 @@ void syscall32_cpu_init(void)
35368 void enable_sep_cpu(void)
35369 {
35370 int cpu = get_cpu();
35371- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35372+ struct tss_struct *tss = init_tss + cpu;
35373
35374 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35375 put_cpu();
35376@@ -167,7 +168,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35377
35378 down_write(&mm->mmap_sem);
35379
35380- addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, 0);
35381+ addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, MAP_EXECUTABLE);
35382 if (IS_ERR_VALUE(addr)) {
35383 ret = addr;
35384 goto up_fail;
35385@@ -175,7 +176,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35386
35387 addr += VDSO_OFFSET(VDSO_PREV_PAGES);
35388
35389- current->mm->context.vdso = (void *)addr;
35390+ current->mm->context.vdso = addr;
35391
35392 /*
35393 * MAYWRITE to allow gdb to COW and set breakpoints
35394@@ -224,11 +225,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35395 #endif
35396
35397 current_thread_info()->sysenter_return =
35398- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35399+ (void __force_user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35400
35401 up_fail:
35402 if (ret)
35403- current->mm->context.vdso = NULL;
35404+ current->mm->context.vdso = 0;
35405
35406 up_write(&mm->mmap_sem);
35407
35408@@ -282,8 +283,14 @@ __initcall(ia32_binfmt_init);
35409
35410 const char *arch_vma_name(struct vm_area_struct *vma)
35411 {
35412- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35413+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35414 return "[vdso]";
35415+
35416+#ifdef CONFIG_PAX_SEGMEXEC
35417+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35418+ return "[vdso]";
35419+#endif
35420+
35421 return NULL;
35422 }
35423
35424diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35425index 1ad1026..1a08abe 100644
35426--- a/arch/x86/vdso/vma.c
35427+++ b/arch/x86/vdso/vma.c
35428@@ -17,8 +17,6 @@
35429 #include <asm/page.h>
35430
35431 #if defined(CONFIG_X86_64)
35432-unsigned int __read_mostly vdso_enabled = 1;
35433-
35434 DECLARE_VDSO_IMAGE(vdso);
35435 extern unsigned short vdso_sync_cpuid;
35436 static unsigned vdso_size;
35437@@ -144,7 +142,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35438 * unaligned here as a result of stack start randomization.
35439 */
35440 addr = PAGE_ALIGN(addr);
35441- addr = align_vdso_addr(addr);
35442
35443 return addr;
35444 }
35445@@ -157,30 +154,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35446 unsigned size)
35447 {
35448 struct mm_struct *mm = current->mm;
35449- unsigned long addr;
35450+ unsigned long addr = 0;
35451 int ret;
35452
35453- if (!vdso_enabled)
35454- return 0;
35455-
35456 down_write(&mm->mmap_sem);
35457+
35458+#ifdef CONFIG_PAX_RANDMMAP
35459+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35460+#endif
35461+
35462 addr = vdso_addr(mm->start_stack, size);
35463+ addr = align_vdso_addr(addr);
35464 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35465 if (IS_ERR_VALUE(addr)) {
35466 ret = addr;
35467 goto up_fail;
35468 }
35469
35470- current->mm->context.vdso = (void *)addr;
35471+ mm->context.vdso = addr;
35472
35473 ret = install_special_mapping(mm, addr, size,
35474 VM_READ|VM_EXEC|
35475 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35476 pages);
35477- if (ret) {
35478- current->mm->context.vdso = NULL;
35479- goto up_fail;
35480- }
35481+ if (ret)
35482+ mm->context.vdso = 0;
35483
35484 up_fail:
35485 up_write(&mm->mmap_sem);
35486@@ -200,11 +198,4 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35487 vdsox32_size);
35488 }
35489 #endif
35490-
35491-static __init int vdso_setup(char *s)
35492-{
35493- vdso_enabled = simple_strtoul(s, NULL, 0);
35494- return 0;
35495-}
35496-__setup("vdso=", vdso_setup);
35497 #endif
35498diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35499index e88fda8..76ce7ce 100644
35500--- a/arch/x86/xen/Kconfig
35501+++ b/arch/x86/xen/Kconfig
35502@@ -9,6 +9,7 @@ config XEN
35503 select XEN_HAVE_PVMMU
35504 depends on X86_64 || (X86_32 && X86_PAE)
35505 depends on X86_TSC
35506+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35507 help
35508 This is the Linux Xen port. Enabling this will allow the
35509 kernel to boot in a paravirtualized environment under the
35510diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35511index c34bfc4..e599673 100644
35512--- a/arch/x86/xen/enlighten.c
35513+++ b/arch/x86/xen/enlighten.c
35514@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35515
35516 struct shared_info xen_dummy_shared_info;
35517
35518-void *xen_initial_gdt;
35519-
35520 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35521 __read_mostly int xen_have_vector_callback;
35522 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35523@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35524 {
35525 unsigned long va = dtr->address;
35526 unsigned int size = dtr->size + 1;
35527- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35528- unsigned long frames[pages];
35529+ unsigned long frames[65536 / PAGE_SIZE];
35530 int f;
35531
35532 /*
35533@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35534 {
35535 unsigned long va = dtr->address;
35536 unsigned int size = dtr->size + 1;
35537- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35538- unsigned long frames[pages];
35539+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35540 int f;
35541
35542 /*
35543@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35544 * 8-byte entries, or 16 4k pages..
35545 */
35546
35547- BUG_ON(size > 65536);
35548+ BUG_ON(size > GDT_SIZE);
35549 BUG_ON(va & ~PAGE_MASK);
35550
35551 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35552@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35553 return 0;
35554 }
35555
35556-static void set_xen_basic_apic_ops(void)
35557+static void __init set_xen_basic_apic_ops(void)
35558 {
35559 apic->read = xen_apic_read;
35560 apic->write = xen_apic_write;
35561@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35562 #endif
35563 };
35564
35565-static void xen_reboot(int reason)
35566+static __noreturn void xen_reboot(int reason)
35567 {
35568 struct sched_shutdown r = { .reason = reason };
35569
35570- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35571- BUG();
35572+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35573+ BUG();
35574 }
35575
35576-static void xen_restart(char *msg)
35577+static __noreturn void xen_restart(char *msg)
35578 {
35579 xen_reboot(SHUTDOWN_reboot);
35580 }
35581
35582-static void xen_emergency_restart(void)
35583+static __noreturn void xen_emergency_restart(void)
35584 {
35585 xen_reboot(SHUTDOWN_reboot);
35586 }
35587
35588-static void xen_machine_halt(void)
35589+static __noreturn void xen_machine_halt(void)
35590 {
35591 xen_reboot(SHUTDOWN_poweroff);
35592 }
35593
35594-static void xen_machine_power_off(void)
35595+static __noreturn void xen_machine_power_off(void)
35596 {
35597 if (pm_power_off)
35598 pm_power_off();
35599@@ -1564,7 +1560,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35600 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35601
35602 /* Work out if we support NX */
35603- x86_configure_nx();
35604+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35605+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35606+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35607+ unsigned l, h;
35608+
35609+ __supported_pte_mask |= _PAGE_NX;
35610+ rdmsr(MSR_EFER, l, h);
35611+ l |= EFER_NX;
35612+ wrmsr(MSR_EFER, l, h);
35613+ }
35614+#endif
35615
35616 /* Get mfn list */
35617 xen_build_dynamic_phys_to_machine();
35618@@ -1592,13 +1598,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35619
35620 machine_ops = xen_machine_ops;
35621
35622- /*
35623- * The only reliable way to retain the initial address of the
35624- * percpu gdt_page is to remember it here, so we can go and
35625- * mark it RW later, when the initial percpu area is freed.
35626- */
35627- xen_initial_gdt = &per_cpu(gdt_page, 0);
35628-
35629 xen_smp_init();
35630
35631 #ifdef CONFIG_ACPI_NUMA
35632diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35633index 86e02ea..e3705ca 100644
35634--- a/arch/x86/xen/mmu.c
35635+++ b/arch/x86/xen/mmu.c
35636@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35637 return val;
35638 }
35639
35640-static pteval_t pte_pfn_to_mfn(pteval_t val)
35641+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35642 {
35643 if (val & _PAGE_PRESENT) {
35644 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35645@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35646 /* L3_k[510] -> level2_kernel_pgt
35647 * L3_i[511] -> level2_fixmap_pgt */
35648 convert_pfn_mfn(level3_kernel_pgt);
35649+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35650+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35651+ convert_pfn_mfn(level3_vmemmap_pgt);
35652 }
35653 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35654 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35655@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35656 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35657 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35658 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35659+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35660+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35661+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35662 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35663 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35664+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35665 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35666 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35667
35668@@ -2122,6 +2129,7 @@ static void __init xen_post_allocator_init(void)
35669 pv_mmu_ops.set_pud = xen_set_pud;
35670 #if PAGETABLE_LEVELS == 4
35671 pv_mmu_ops.set_pgd = xen_set_pgd;
35672+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35673 #endif
35674
35675 /* This will work as long as patching hasn't happened yet
35676@@ -2200,6 +2208,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35677 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35678 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35679 .set_pgd = xen_set_pgd_hyper,
35680+ .set_pgd_batched = xen_set_pgd_hyper,
35681
35682 .alloc_pud = xen_alloc_pmd_init,
35683 .release_pud = xen_release_pmd_init,
35684diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35685index 7005974..54fb05f 100644
35686--- a/arch/x86/xen/smp.c
35687+++ b/arch/x86/xen/smp.c
35688@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35689
35690 if (xen_pv_domain()) {
35691 if (!xen_feature(XENFEAT_writable_page_tables))
35692- /* We've switched to the "real" per-cpu gdt, so make
35693- * sure the old memory can be recycled. */
35694- make_lowmem_page_readwrite(xen_initial_gdt);
35695-
35696 #ifdef CONFIG_X86_32
35697 /*
35698 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35699 * expects __USER_DS
35700 */
35701- loadsegment(ds, __USER_DS);
35702- loadsegment(es, __USER_DS);
35703+ loadsegment(ds, __KERNEL_DS);
35704+ loadsegment(es, __KERNEL_DS);
35705 #endif
35706
35707 xen_filter_cpu_maps();
35708@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35709 #ifdef CONFIG_X86_32
35710 /* Note: PVH is not yet supported on x86_32. */
35711 ctxt->user_regs.fs = __KERNEL_PERCPU;
35712- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35713+ savesegment(gs, ctxt->user_regs.gs);
35714 #endif
35715 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35716
35717@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35718 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35719 ctxt->flags = VGCF_IN_KERNEL;
35720 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35721- ctxt->user_regs.ds = __USER_DS;
35722- ctxt->user_regs.es = __USER_DS;
35723+ ctxt->user_regs.ds = __KERNEL_DS;
35724+ ctxt->user_regs.es = __KERNEL_DS;
35725 ctxt->user_regs.ss = __KERNEL_DS;
35726
35727 xen_copy_trap_info(ctxt->trap_ctxt);
35728@@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35729 int rc;
35730
35731 per_cpu(current_task, cpu) = idle;
35732+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35733 #ifdef CONFIG_X86_32
35734 irq_ctx_init(cpu);
35735 #else
35736 clear_tsk_thread_flag(idle, TIF_FORK);
35737 #endif
35738- per_cpu(kernel_stack, cpu) =
35739- (unsigned long)task_stack_page(idle) -
35740- KERNEL_STACK_OFFSET + THREAD_SIZE;
35741+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35742
35743 xen_setup_runstate_info(cpu);
35744 xen_setup_timer(cpu);
35745@@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35746
35747 void __init xen_smp_init(void)
35748 {
35749- smp_ops = xen_smp_ops;
35750+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35751 xen_fill_possible_map();
35752 }
35753
35754diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35755index fd92a64..1f72641 100644
35756--- a/arch/x86/xen/xen-asm_32.S
35757+++ b/arch/x86/xen/xen-asm_32.S
35758@@ -99,7 +99,7 @@ ENTRY(xen_iret)
35759 pushw %fs
35760 movl $(__KERNEL_PERCPU), %eax
35761 movl %eax, %fs
35762- movl %fs:xen_vcpu, %eax
35763+ mov PER_CPU_VAR(xen_vcpu), %eax
35764 POP_FS
35765 #else
35766 movl %ss:xen_vcpu, %eax
35767diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35768index 485b695..fda3e7c 100644
35769--- a/arch/x86/xen/xen-head.S
35770+++ b/arch/x86/xen/xen-head.S
35771@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35772 #ifdef CONFIG_X86_32
35773 mov %esi,xen_start_info
35774 mov $init_thread_union+THREAD_SIZE,%esp
35775+#ifdef CONFIG_SMP
35776+ movl $cpu_gdt_table,%edi
35777+ movl $__per_cpu_load,%eax
35778+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35779+ rorl $16,%eax
35780+ movb %al,__KERNEL_PERCPU + 4(%edi)
35781+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35782+ movl $__per_cpu_end - 1,%eax
35783+ subl $__per_cpu_start,%eax
35784+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35785+#endif
35786 #else
35787 mov %rsi,xen_start_info
35788 mov $init_thread_union+THREAD_SIZE,%rsp
35789diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35790index 1cb6f4c..9981524 100644
35791--- a/arch/x86/xen/xen-ops.h
35792+++ b/arch/x86/xen/xen-ops.h
35793@@ -10,8 +10,6 @@
35794 extern const char xen_hypervisor_callback[];
35795 extern const char xen_failsafe_callback[];
35796
35797-extern void *xen_initial_gdt;
35798-
35799 struct trap_info;
35800 void xen_copy_trap_info(struct trap_info *traps);
35801
35802diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35803index 525bd3d..ef888b1 100644
35804--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35805+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35806@@ -119,9 +119,9 @@
35807 ----------------------------------------------------------------------*/
35808
35809 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35810-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35811 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35812 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35813+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35814
35815 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35816 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35817diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35818index 2f33760..835e50a 100644
35819--- a/arch/xtensa/variants/fsf/include/variant/core.h
35820+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35821@@ -11,6 +11,7 @@
35822 #ifndef _XTENSA_CORE_H
35823 #define _XTENSA_CORE_H
35824
35825+#include <linux/const.h>
35826
35827 /****************************************************************************
35828 Parameters Useful for Any Code, USER or PRIVILEGED
35829@@ -112,9 +113,9 @@
35830 ----------------------------------------------------------------------*/
35831
35832 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35833-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35834 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35835 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35836+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35837
35838 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35839 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35840diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35841index af00795..2bb8105 100644
35842--- a/arch/xtensa/variants/s6000/include/variant/core.h
35843+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35844@@ -11,6 +11,7 @@
35845 #ifndef _XTENSA_CORE_CONFIGURATION_H
35846 #define _XTENSA_CORE_CONFIGURATION_H
35847
35848+#include <linux/const.h>
35849
35850 /****************************************************************************
35851 Parameters Useful for Any Code, USER or PRIVILEGED
35852@@ -118,9 +119,9 @@
35853 ----------------------------------------------------------------------*/
35854
35855 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35856-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35857 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35858 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35859+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35860
35861 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35862 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35863diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35864index 1039fb9..d7c0d9a 100644
35865--- a/block/blk-cgroup.c
35866+++ b/block/blk-cgroup.c
35867@@ -825,7 +825,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35868 static struct cgroup_subsys_state *
35869 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35870 {
35871- static atomic64_t id_seq = ATOMIC64_INIT(0);
35872+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35873 struct blkcg *blkcg;
35874
35875 if (!parent_css) {
35876@@ -839,7 +839,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35877
35878 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35879 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35880- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35881+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35882 done:
35883 spin_lock_init(&blkcg->lock);
35884 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35885diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35886index c11d24e..e915d24 100644
35887--- a/block/blk-iopoll.c
35888+++ b/block/blk-iopoll.c
35889@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35890 }
35891 EXPORT_SYMBOL(blk_iopoll_complete);
35892
35893-static void blk_iopoll_softirq(struct softirq_action *h)
35894+static __latent_entropy void blk_iopoll_softirq(void)
35895 {
35896 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35897 int rearm = 0, budget = blk_iopoll_budget;
35898diff --git a/block/blk-map.c b/block/blk-map.c
35899index f7b22bc..ec2ddf4 100644
35900--- a/block/blk-map.c
35901+++ b/block/blk-map.c
35902@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35903 if (!len || !kbuf)
35904 return -EINVAL;
35905
35906- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35907+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35908 if (do_copy)
35909 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35910 else
35911diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35912index 53b1737..08177d2e 100644
35913--- a/block/blk-softirq.c
35914+++ b/block/blk-softirq.c
35915@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35916 * Softirq action handler - move entries to local list and loop over them
35917 * while passing them to the queue registered handler.
35918 */
35919-static void blk_done_softirq(struct softirq_action *h)
35920+static __latent_entropy void blk_done_softirq(void)
35921 {
35922 struct list_head *cpu_list, local_list;
35923
35924diff --git a/block/bsg.c b/block/bsg.c
35925index 420a5a9..23834aa 100644
35926--- a/block/bsg.c
35927+++ b/block/bsg.c
35928@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35929 struct sg_io_v4 *hdr, struct bsg_device *bd,
35930 fmode_t has_write_perm)
35931 {
35932+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35933+ unsigned char *cmdptr;
35934+
35935 if (hdr->request_len > BLK_MAX_CDB) {
35936 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35937 if (!rq->cmd)
35938 return -ENOMEM;
35939- }
35940+ cmdptr = rq->cmd;
35941+ } else
35942+ cmdptr = tmpcmd;
35943
35944- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35945+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35946 hdr->request_len))
35947 return -EFAULT;
35948
35949+ if (cmdptr != rq->cmd)
35950+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35951+
35952 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35953 if (blk_verify_command(rq->cmd, has_write_perm))
35954 return -EPERM;
35955diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35956index fbd5a67..f24fd95 100644
35957--- a/block/compat_ioctl.c
35958+++ b/block/compat_ioctl.c
35959@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35960 cgc = compat_alloc_user_space(sizeof(*cgc));
35961 cgc32 = compat_ptr(arg);
35962
35963- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35964+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35965 get_user(data, &cgc32->buffer) ||
35966 put_user(compat_ptr(data), &cgc->buffer) ||
35967 copy_in_user(&cgc->buflen, &cgc32->buflen,
35968@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35969 err |= __get_user(f->spec1, &uf->spec1);
35970 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35971 err |= __get_user(name, &uf->name);
35972- f->name = compat_ptr(name);
35973+ f->name = (void __force_kernel *)compat_ptr(name);
35974 if (err) {
35975 err = -EFAULT;
35976 goto out;
35977diff --git a/block/genhd.c b/block/genhd.c
35978index 791f419..89f21c4 100644
35979--- a/block/genhd.c
35980+++ b/block/genhd.c
35981@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35982
35983 /*
35984 * Register device numbers dev..(dev+range-1)
35985- * range must be nonzero
35986+ * Noop if @range is zero.
35987 * The hash chain is sorted on range, so that subranges can override.
35988 */
35989 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35990 struct kobject *(*probe)(dev_t, int *, void *),
35991 int (*lock)(dev_t, void *), void *data)
35992 {
35993- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35994+ if (range)
35995+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35996 }
35997
35998 EXPORT_SYMBOL(blk_register_region);
35999
36000+/* undo blk_register_region(), noop if @range is zero */
36001 void blk_unregister_region(dev_t devt, unsigned long range)
36002 {
36003- kobj_unmap(bdev_map, devt, range);
36004+ if (range)
36005+ kobj_unmap(bdev_map, devt, range);
36006 }
36007
36008 EXPORT_SYMBOL(blk_unregister_region);
36009diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36010index dc51f46..d5446a8 100644
36011--- a/block/partitions/efi.c
36012+++ b/block/partitions/efi.c
36013@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36014 if (!gpt)
36015 return NULL;
36016
36017+ if (!le32_to_cpu(gpt->num_partition_entries))
36018+ return NULL;
36019+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36020+ if (!pte)
36021+ return NULL;
36022+
36023 count = le32_to_cpu(gpt->num_partition_entries) *
36024 le32_to_cpu(gpt->sizeof_partition_entry);
36025- if (!count)
36026- return NULL;
36027- pte = kmalloc(count, GFP_KERNEL);
36028- if (!pte)
36029- return NULL;
36030-
36031 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36032 (u8 *) pte, count) < count) {
36033 kfree(pte);
36034diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36035index 2648797..92ed21f 100644
36036--- a/block/scsi_ioctl.c
36037+++ b/block/scsi_ioctl.c
36038@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36039 return put_user(0, p);
36040 }
36041
36042-static int sg_get_timeout(struct request_queue *q)
36043+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36044 {
36045 return jiffies_to_clock_t(q->sg_timeout);
36046 }
36047@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36048 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36049 struct sg_io_hdr *hdr, fmode_t mode)
36050 {
36051- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36052+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36053+ unsigned char *cmdptr;
36054+
36055+ if (rq->cmd != rq->__cmd)
36056+ cmdptr = rq->cmd;
36057+ else
36058+ cmdptr = tmpcmd;
36059+
36060+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36061 return -EFAULT;
36062+
36063+ if (cmdptr != rq->cmd)
36064+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36065+
36066 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36067 return -EPERM;
36068
36069@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36070 int err;
36071 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36072 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36073+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36074+ unsigned char *cmdptr;
36075
36076 if (!sic)
36077 return -EINVAL;
36078@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36079 */
36080 err = -EFAULT;
36081 rq->cmd_len = cmdlen;
36082- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36083+
36084+ if (rq->cmd != rq->__cmd)
36085+ cmdptr = rq->cmd;
36086+ else
36087+ cmdptr = tmpcmd;
36088+
36089+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36090 goto error;
36091
36092+ if (rq->cmd != cmdptr)
36093+ memcpy(rq->cmd, cmdptr, cmdlen);
36094+
36095 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36096 goto error;
36097
36098diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36099index 7bdd61b..afec999 100644
36100--- a/crypto/cryptd.c
36101+++ b/crypto/cryptd.c
36102@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36103
36104 struct cryptd_blkcipher_request_ctx {
36105 crypto_completion_t complete;
36106-};
36107+} __no_const;
36108
36109 struct cryptd_hash_ctx {
36110 struct crypto_shash *child;
36111@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36112
36113 struct cryptd_aead_request_ctx {
36114 crypto_completion_t complete;
36115-};
36116+} __no_const;
36117
36118 static void cryptd_queue_worker(struct work_struct *work);
36119
36120diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36121index 309d345..1632720 100644
36122--- a/crypto/pcrypt.c
36123+++ b/crypto/pcrypt.c
36124@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36125 int ret;
36126
36127 pinst->kobj.kset = pcrypt_kset;
36128- ret = kobject_add(&pinst->kobj, NULL, name);
36129+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36130 if (!ret)
36131 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36132
36133diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36134index 6921c7f..78e1af7 100644
36135--- a/drivers/acpi/acpica/hwxfsleep.c
36136+++ b/drivers/acpi/acpica/hwxfsleep.c
36137@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36138 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36139
36140 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36141- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36142- acpi_hw_extended_sleep},
36143- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36144- acpi_hw_extended_wake_prep},
36145- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36146+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36147+ .extended_function = acpi_hw_extended_sleep},
36148+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36149+ .extended_function = acpi_hw_extended_wake_prep},
36150+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36151+ .extended_function = acpi_hw_extended_wake}
36152 };
36153
36154 /*
36155diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36156index e5bcd91..74f050d 100644
36157--- a/drivers/acpi/apei/apei-internal.h
36158+++ b/drivers/acpi/apei/apei-internal.h
36159@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36160 struct apei_exec_ins_type {
36161 u32 flags;
36162 apei_exec_ins_func_t run;
36163-};
36164+} __do_const;
36165
36166 struct apei_exec_context {
36167 u32 ip;
36168diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36169index dab7cb7..f0d2994 100644
36170--- a/drivers/acpi/apei/ghes.c
36171+++ b/drivers/acpi/apei/ghes.c
36172@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36173 const struct acpi_hest_generic *generic,
36174 const struct acpi_generic_status *estatus)
36175 {
36176- static atomic_t seqno;
36177+ static atomic_unchecked_t seqno;
36178 unsigned int curr_seqno;
36179 char pfx_seq[64];
36180
36181@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36182 else
36183 pfx = KERN_ERR;
36184 }
36185- curr_seqno = atomic_inc_return(&seqno);
36186+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36187 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36188 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36189 pfx_seq, generic->header.source_id);
36190diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36191index a83e3c6..c3d617f 100644
36192--- a/drivers/acpi/bgrt.c
36193+++ b/drivers/acpi/bgrt.c
36194@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36195 if (!bgrt_image)
36196 return -ENODEV;
36197
36198- bin_attr_image.private = bgrt_image;
36199- bin_attr_image.size = bgrt_image_size;
36200+ pax_open_kernel();
36201+ *(void **)&bin_attr_image.private = bgrt_image;
36202+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36203+ pax_close_kernel();
36204
36205 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36206 if (!bgrt_kobj)
36207diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36208index 3d8413d..95f638c 100644
36209--- a/drivers/acpi/blacklist.c
36210+++ b/drivers/acpi/blacklist.c
36211@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36212 u32 is_critical_error;
36213 };
36214
36215-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36216+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36217
36218 /*
36219 * POLICY: If *anything* doesn't work, put it on the blacklist.
36220@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36221 return 0;
36222 }
36223
36224-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36225+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36226 {
36227 .callback = dmi_disable_osi_vista,
36228 .ident = "Fujitsu Siemens",
36229diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36230index c68e724..e863008 100644
36231--- a/drivers/acpi/custom_method.c
36232+++ b/drivers/acpi/custom_method.c
36233@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36234 struct acpi_table_header table;
36235 acpi_status status;
36236
36237+#ifdef CONFIG_GRKERNSEC_KMEM
36238+ return -EPERM;
36239+#endif
36240+
36241 if (!(*ppos)) {
36242 /* parse the table header to get the table length */
36243 if (count <= sizeof(struct acpi_table_header))
36244diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36245index 3dca36d..abaf070 100644
36246--- a/drivers/acpi/processor_idle.c
36247+++ b/drivers/acpi/processor_idle.c
36248@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36249 {
36250 int i, count = CPUIDLE_DRIVER_STATE_START;
36251 struct acpi_processor_cx *cx;
36252- struct cpuidle_state *state;
36253+ cpuidle_state_no_const *state;
36254 struct cpuidle_driver *drv = &acpi_idle_driver;
36255
36256 if (!pr->flags.power_setup_done)
36257diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36258index 38cb978..352c761 100644
36259--- a/drivers/acpi/sysfs.c
36260+++ b/drivers/acpi/sysfs.c
36261@@ -423,11 +423,11 @@ static u32 num_counters;
36262 static struct attribute **all_attrs;
36263 static u32 acpi_gpe_count;
36264
36265-static struct attribute_group interrupt_stats_attr_group = {
36266+static attribute_group_no_const interrupt_stats_attr_group = {
36267 .name = "interrupts",
36268 };
36269
36270-static struct kobj_attribute *counter_attrs;
36271+static kobj_attribute_no_const *counter_attrs;
36272
36273 static void delete_gpe_attr_array(void)
36274 {
36275diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36276index b986145..82bddb8 100644
36277--- a/drivers/ata/libahci.c
36278+++ b/drivers/ata/libahci.c
36279@@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36280 }
36281 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36282
36283-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36284+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36285 struct ata_taskfile *tf, int is_cmd, u16 flags,
36286 unsigned long timeout_msec)
36287 {
36288diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36289index 18d97d5..be690af 100644
36290--- a/drivers/ata/libata-core.c
36291+++ b/drivers/ata/libata-core.c
36292@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36293 static void ata_dev_xfermask(struct ata_device *dev);
36294 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36295
36296-atomic_t ata_print_id = ATOMIC_INIT(0);
36297+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36298
36299 struct ata_force_param {
36300 const char *name;
36301@@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36302 struct ata_port *ap;
36303 unsigned int tag;
36304
36305- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36306+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36307 ap = qc->ap;
36308
36309 qc->flags = 0;
36310@@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36311 struct ata_port *ap;
36312 struct ata_link *link;
36313
36314- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36315+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36316 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36317 ap = qc->ap;
36318 link = qc->dev->link;
36319@@ -5978,6 +5978,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36320 return;
36321
36322 spin_lock(&lock);
36323+ pax_open_kernel();
36324
36325 for (cur = ops->inherits; cur; cur = cur->inherits) {
36326 void **inherit = (void **)cur;
36327@@ -5991,8 +5992,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36328 if (IS_ERR(*pp))
36329 *pp = NULL;
36330
36331- ops->inherits = NULL;
36332+ *(struct ata_port_operations **)&ops->inherits = NULL;
36333
36334+ pax_close_kernel();
36335 spin_unlock(&lock);
36336 }
36337
36338@@ -6185,7 +6187,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36339
36340 /* give ports names and add SCSI hosts */
36341 for (i = 0; i < host->n_ports; i++) {
36342- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36343+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36344 host->ports[i]->local_port_no = i + 1;
36345 }
36346
36347diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36348index ef8567d..8bdbd03 100644
36349--- a/drivers/ata/libata-scsi.c
36350+++ b/drivers/ata/libata-scsi.c
36351@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36352
36353 if (rc)
36354 return rc;
36355- ap->print_id = atomic_inc_return(&ata_print_id);
36356+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36357 return 0;
36358 }
36359 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36360diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36361index 45b5ab3..98446b8 100644
36362--- a/drivers/ata/libata.h
36363+++ b/drivers/ata/libata.h
36364@@ -53,7 +53,7 @@ enum {
36365 ATA_DNXFER_QUIET = (1 << 31),
36366 };
36367
36368-extern atomic_t ata_print_id;
36369+extern atomic_unchecked_t ata_print_id;
36370 extern int atapi_passthru16;
36371 extern int libata_fua;
36372 extern int libata_noacpi;
36373diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36374index 4edb1a8..84e1658 100644
36375--- a/drivers/ata/pata_arasan_cf.c
36376+++ b/drivers/ata/pata_arasan_cf.c
36377@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36378 /* Handle platform specific quirks */
36379 if (quirk) {
36380 if (quirk & CF_BROKEN_PIO) {
36381- ap->ops->set_piomode = NULL;
36382+ pax_open_kernel();
36383+ *(void **)&ap->ops->set_piomode = NULL;
36384+ pax_close_kernel();
36385 ap->pio_mask = 0;
36386 }
36387 if (quirk & CF_BROKEN_MWDMA)
36388diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36389index f9b983a..887b9d8 100644
36390--- a/drivers/atm/adummy.c
36391+++ b/drivers/atm/adummy.c
36392@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36393 vcc->pop(vcc, skb);
36394 else
36395 dev_kfree_skb_any(skb);
36396- atomic_inc(&vcc->stats->tx);
36397+ atomic_inc_unchecked(&vcc->stats->tx);
36398
36399 return 0;
36400 }
36401diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36402index f1a9198..f466a4a 100644
36403--- a/drivers/atm/ambassador.c
36404+++ b/drivers/atm/ambassador.c
36405@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36406 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36407
36408 // VC layer stats
36409- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36410+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36411
36412 // free the descriptor
36413 kfree (tx_descr);
36414@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36415 dump_skb ("<<<", vc, skb);
36416
36417 // VC layer stats
36418- atomic_inc(&atm_vcc->stats->rx);
36419+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36420 __net_timestamp(skb);
36421 // end of our responsibility
36422 atm_vcc->push (atm_vcc, skb);
36423@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36424 } else {
36425 PRINTK (KERN_INFO, "dropped over-size frame");
36426 // should we count this?
36427- atomic_inc(&atm_vcc->stats->rx_drop);
36428+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36429 }
36430
36431 } else {
36432@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36433 }
36434
36435 if (check_area (skb->data, skb->len)) {
36436- atomic_inc(&atm_vcc->stats->tx_err);
36437+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36438 return -ENOMEM; // ?
36439 }
36440
36441diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36442index 0e3f8f9..765a7a5 100644
36443--- a/drivers/atm/atmtcp.c
36444+++ b/drivers/atm/atmtcp.c
36445@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36446 if (vcc->pop) vcc->pop(vcc,skb);
36447 else dev_kfree_skb(skb);
36448 if (dev_data) return 0;
36449- atomic_inc(&vcc->stats->tx_err);
36450+ atomic_inc_unchecked(&vcc->stats->tx_err);
36451 return -ENOLINK;
36452 }
36453 size = skb->len+sizeof(struct atmtcp_hdr);
36454@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36455 if (!new_skb) {
36456 if (vcc->pop) vcc->pop(vcc,skb);
36457 else dev_kfree_skb(skb);
36458- atomic_inc(&vcc->stats->tx_err);
36459+ atomic_inc_unchecked(&vcc->stats->tx_err);
36460 return -ENOBUFS;
36461 }
36462 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36463@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36464 if (vcc->pop) vcc->pop(vcc,skb);
36465 else dev_kfree_skb(skb);
36466 out_vcc->push(out_vcc,new_skb);
36467- atomic_inc(&vcc->stats->tx);
36468- atomic_inc(&out_vcc->stats->rx);
36469+ atomic_inc_unchecked(&vcc->stats->tx);
36470+ atomic_inc_unchecked(&out_vcc->stats->rx);
36471 return 0;
36472 }
36473
36474@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36475 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36476 read_unlock(&vcc_sklist_lock);
36477 if (!out_vcc) {
36478- atomic_inc(&vcc->stats->tx_err);
36479+ atomic_inc_unchecked(&vcc->stats->tx_err);
36480 goto done;
36481 }
36482 skb_pull(skb,sizeof(struct atmtcp_hdr));
36483@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36484 __net_timestamp(new_skb);
36485 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36486 out_vcc->push(out_vcc,new_skb);
36487- atomic_inc(&vcc->stats->tx);
36488- atomic_inc(&out_vcc->stats->rx);
36489+ atomic_inc_unchecked(&vcc->stats->tx);
36490+ atomic_inc_unchecked(&out_vcc->stats->rx);
36491 done:
36492 if (vcc->pop) vcc->pop(vcc,skb);
36493 else dev_kfree_skb(skb);
36494diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36495index b1955ba..b179940 100644
36496--- a/drivers/atm/eni.c
36497+++ b/drivers/atm/eni.c
36498@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36499 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36500 vcc->dev->number);
36501 length = 0;
36502- atomic_inc(&vcc->stats->rx_err);
36503+ atomic_inc_unchecked(&vcc->stats->rx_err);
36504 }
36505 else {
36506 length = ATM_CELL_SIZE-1; /* no HEC */
36507@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36508 size);
36509 }
36510 eff = length = 0;
36511- atomic_inc(&vcc->stats->rx_err);
36512+ atomic_inc_unchecked(&vcc->stats->rx_err);
36513 }
36514 else {
36515 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36516@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36517 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36518 vcc->dev->number,vcc->vci,length,size << 2,descr);
36519 length = eff = 0;
36520- atomic_inc(&vcc->stats->rx_err);
36521+ atomic_inc_unchecked(&vcc->stats->rx_err);
36522 }
36523 }
36524 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36525@@ -767,7 +767,7 @@ rx_dequeued++;
36526 vcc->push(vcc,skb);
36527 pushed++;
36528 }
36529- atomic_inc(&vcc->stats->rx);
36530+ atomic_inc_unchecked(&vcc->stats->rx);
36531 }
36532 wake_up(&eni_dev->rx_wait);
36533 }
36534@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36535 PCI_DMA_TODEVICE);
36536 if (vcc->pop) vcc->pop(vcc,skb);
36537 else dev_kfree_skb_irq(skb);
36538- atomic_inc(&vcc->stats->tx);
36539+ atomic_inc_unchecked(&vcc->stats->tx);
36540 wake_up(&eni_dev->tx_wait);
36541 dma_complete++;
36542 }
36543diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36544index 82f2ae0..f205c02 100644
36545--- a/drivers/atm/firestream.c
36546+++ b/drivers/atm/firestream.c
36547@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36548 }
36549 }
36550
36551- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36552+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36553
36554 fs_dprintk (FS_DEBUG_TXMEM, "i");
36555 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36556@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36557 #endif
36558 skb_put (skb, qe->p1 & 0xffff);
36559 ATM_SKB(skb)->vcc = atm_vcc;
36560- atomic_inc(&atm_vcc->stats->rx);
36561+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36562 __net_timestamp(skb);
36563 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36564 atm_vcc->push (atm_vcc, skb);
36565@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36566 kfree (pe);
36567 }
36568 if (atm_vcc)
36569- atomic_inc(&atm_vcc->stats->rx_drop);
36570+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36571 break;
36572 case 0x1f: /* Reassembly abort: no buffers. */
36573 /* Silently increment error counter. */
36574 if (atm_vcc)
36575- atomic_inc(&atm_vcc->stats->rx_drop);
36576+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36577 break;
36578 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36579 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36580diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36581index 204814e..cede831 100644
36582--- a/drivers/atm/fore200e.c
36583+++ b/drivers/atm/fore200e.c
36584@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36585 #endif
36586 /* check error condition */
36587 if (*entry->status & STATUS_ERROR)
36588- atomic_inc(&vcc->stats->tx_err);
36589+ atomic_inc_unchecked(&vcc->stats->tx_err);
36590 else
36591- atomic_inc(&vcc->stats->tx);
36592+ atomic_inc_unchecked(&vcc->stats->tx);
36593 }
36594 }
36595
36596@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36597 if (skb == NULL) {
36598 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36599
36600- atomic_inc(&vcc->stats->rx_drop);
36601+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36602 return -ENOMEM;
36603 }
36604
36605@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36606
36607 dev_kfree_skb_any(skb);
36608
36609- atomic_inc(&vcc->stats->rx_drop);
36610+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36611 return -ENOMEM;
36612 }
36613
36614 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36615
36616 vcc->push(vcc, skb);
36617- atomic_inc(&vcc->stats->rx);
36618+ atomic_inc_unchecked(&vcc->stats->rx);
36619
36620 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36621
36622@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36623 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36624 fore200e->atm_dev->number,
36625 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36626- atomic_inc(&vcc->stats->rx_err);
36627+ atomic_inc_unchecked(&vcc->stats->rx_err);
36628 }
36629 }
36630
36631@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36632 goto retry_here;
36633 }
36634
36635- atomic_inc(&vcc->stats->tx_err);
36636+ atomic_inc_unchecked(&vcc->stats->tx_err);
36637
36638 fore200e->tx_sat++;
36639 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36640diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36641index aa6be26..f70a785 100644
36642--- a/drivers/atm/he.c
36643+++ b/drivers/atm/he.c
36644@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36645
36646 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36647 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36648- atomic_inc(&vcc->stats->rx_drop);
36649+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36650 goto return_host_buffers;
36651 }
36652
36653@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36654 RBRQ_LEN_ERR(he_dev->rbrq_head)
36655 ? "LEN_ERR" : "",
36656 vcc->vpi, vcc->vci);
36657- atomic_inc(&vcc->stats->rx_err);
36658+ atomic_inc_unchecked(&vcc->stats->rx_err);
36659 goto return_host_buffers;
36660 }
36661
36662@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36663 vcc->push(vcc, skb);
36664 spin_lock(&he_dev->global_lock);
36665
36666- atomic_inc(&vcc->stats->rx);
36667+ atomic_inc_unchecked(&vcc->stats->rx);
36668
36669 return_host_buffers:
36670 ++pdus_assembled;
36671@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36672 tpd->vcc->pop(tpd->vcc, tpd->skb);
36673 else
36674 dev_kfree_skb_any(tpd->skb);
36675- atomic_inc(&tpd->vcc->stats->tx_err);
36676+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36677 }
36678 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36679 return;
36680@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36681 vcc->pop(vcc, skb);
36682 else
36683 dev_kfree_skb_any(skb);
36684- atomic_inc(&vcc->stats->tx_err);
36685+ atomic_inc_unchecked(&vcc->stats->tx_err);
36686 return -EINVAL;
36687 }
36688
36689@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36690 vcc->pop(vcc, skb);
36691 else
36692 dev_kfree_skb_any(skb);
36693- atomic_inc(&vcc->stats->tx_err);
36694+ atomic_inc_unchecked(&vcc->stats->tx_err);
36695 return -EINVAL;
36696 }
36697 #endif
36698@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36699 vcc->pop(vcc, skb);
36700 else
36701 dev_kfree_skb_any(skb);
36702- atomic_inc(&vcc->stats->tx_err);
36703+ atomic_inc_unchecked(&vcc->stats->tx_err);
36704 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36705 return -ENOMEM;
36706 }
36707@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36708 vcc->pop(vcc, skb);
36709 else
36710 dev_kfree_skb_any(skb);
36711- atomic_inc(&vcc->stats->tx_err);
36712+ atomic_inc_unchecked(&vcc->stats->tx_err);
36713 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36714 return -ENOMEM;
36715 }
36716@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36717 __enqueue_tpd(he_dev, tpd, cid);
36718 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36719
36720- atomic_inc(&vcc->stats->tx);
36721+ atomic_inc_unchecked(&vcc->stats->tx);
36722
36723 return 0;
36724 }
36725diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36726index 1dc0519..1aadaf7 100644
36727--- a/drivers/atm/horizon.c
36728+++ b/drivers/atm/horizon.c
36729@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36730 {
36731 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36732 // VC layer stats
36733- atomic_inc(&vcc->stats->rx);
36734+ atomic_inc_unchecked(&vcc->stats->rx);
36735 __net_timestamp(skb);
36736 // end of our responsibility
36737 vcc->push (vcc, skb);
36738@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36739 dev->tx_iovec = NULL;
36740
36741 // VC layer stats
36742- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36743+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36744
36745 // free the skb
36746 hrz_kfree_skb (skb);
36747diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36748index 1bdf104..9dc44b1 100644
36749--- a/drivers/atm/idt77252.c
36750+++ b/drivers/atm/idt77252.c
36751@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36752 else
36753 dev_kfree_skb(skb);
36754
36755- atomic_inc(&vcc->stats->tx);
36756+ atomic_inc_unchecked(&vcc->stats->tx);
36757 }
36758
36759 atomic_dec(&scq->used);
36760@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36761 if ((sb = dev_alloc_skb(64)) == NULL) {
36762 printk("%s: Can't allocate buffers for aal0.\n",
36763 card->name);
36764- atomic_add(i, &vcc->stats->rx_drop);
36765+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36766 break;
36767 }
36768 if (!atm_charge(vcc, sb->truesize)) {
36769 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36770 card->name);
36771- atomic_add(i - 1, &vcc->stats->rx_drop);
36772+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36773 dev_kfree_skb(sb);
36774 break;
36775 }
36776@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36777 ATM_SKB(sb)->vcc = vcc;
36778 __net_timestamp(sb);
36779 vcc->push(vcc, sb);
36780- atomic_inc(&vcc->stats->rx);
36781+ atomic_inc_unchecked(&vcc->stats->rx);
36782
36783 cell += ATM_CELL_PAYLOAD;
36784 }
36785@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36786 "(CDC: %08x)\n",
36787 card->name, len, rpp->len, readl(SAR_REG_CDC));
36788 recycle_rx_pool_skb(card, rpp);
36789- atomic_inc(&vcc->stats->rx_err);
36790+ atomic_inc_unchecked(&vcc->stats->rx_err);
36791 return;
36792 }
36793 if (stat & SAR_RSQE_CRC) {
36794 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36795 recycle_rx_pool_skb(card, rpp);
36796- atomic_inc(&vcc->stats->rx_err);
36797+ atomic_inc_unchecked(&vcc->stats->rx_err);
36798 return;
36799 }
36800 if (skb_queue_len(&rpp->queue) > 1) {
36801@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36802 RXPRINTK("%s: Can't alloc RX skb.\n",
36803 card->name);
36804 recycle_rx_pool_skb(card, rpp);
36805- atomic_inc(&vcc->stats->rx_err);
36806+ atomic_inc_unchecked(&vcc->stats->rx_err);
36807 return;
36808 }
36809 if (!atm_charge(vcc, skb->truesize)) {
36810@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36811 __net_timestamp(skb);
36812
36813 vcc->push(vcc, skb);
36814- atomic_inc(&vcc->stats->rx);
36815+ atomic_inc_unchecked(&vcc->stats->rx);
36816
36817 return;
36818 }
36819@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36820 __net_timestamp(skb);
36821
36822 vcc->push(vcc, skb);
36823- atomic_inc(&vcc->stats->rx);
36824+ atomic_inc_unchecked(&vcc->stats->rx);
36825
36826 if (skb->truesize > SAR_FB_SIZE_3)
36827 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36828@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36829 if (vcc->qos.aal != ATM_AAL0) {
36830 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36831 card->name, vpi, vci);
36832- atomic_inc(&vcc->stats->rx_drop);
36833+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36834 goto drop;
36835 }
36836
36837 if ((sb = dev_alloc_skb(64)) == NULL) {
36838 printk("%s: Can't allocate buffers for AAL0.\n",
36839 card->name);
36840- atomic_inc(&vcc->stats->rx_err);
36841+ atomic_inc_unchecked(&vcc->stats->rx_err);
36842 goto drop;
36843 }
36844
36845@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36846 ATM_SKB(sb)->vcc = vcc;
36847 __net_timestamp(sb);
36848 vcc->push(vcc, sb);
36849- atomic_inc(&vcc->stats->rx);
36850+ atomic_inc_unchecked(&vcc->stats->rx);
36851
36852 drop:
36853 skb_pull(queue, 64);
36854@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36855
36856 if (vc == NULL) {
36857 printk("%s: NULL connection in send().\n", card->name);
36858- atomic_inc(&vcc->stats->tx_err);
36859+ atomic_inc_unchecked(&vcc->stats->tx_err);
36860 dev_kfree_skb(skb);
36861 return -EINVAL;
36862 }
36863 if (!test_bit(VCF_TX, &vc->flags)) {
36864 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36865- atomic_inc(&vcc->stats->tx_err);
36866+ atomic_inc_unchecked(&vcc->stats->tx_err);
36867 dev_kfree_skb(skb);
36868 return -EINVAL;
36869 }
36870@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36871 break;
36872 default:
36873 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36874- atomic_inc(&vcc->stats->tx_err);
36875+ atomic_inc_unchecked(&vcc->stats->tx_err);
36876 dev_kfree_skb(skb);
36877 return -EINVAL;
36878 }
36879
36880 if (skb_shinfo(skb)->nr_frags != 0) {
36881 printk("%s: No scatter-gather yet.\n", card->name);
36882- atomic_inc(&vcc->stats->tx_err);
36883+ atomic_inc_unchecked(&vcc->stats->tx_err);
36884 dev_kfree_skb(skb);
36885 return -EINVAL;
36886 }
36887@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36888
36889 err = queue_skb(card, vc, skb, oam);
36890 if (err) {
36891- atomic_inc(&vcc->stats->tx_err);
36892+ atomic_inc_unchecked(&vcc->stats->tx_err);
36893 dev_kfree_skb(skb);
36894 return err;
36895 }
36896@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36897 skb = dev_alloc_skb(64);
36898 if (!skb) {
36899 printk("%s: Out of memory in send_oam().\n", card->name);
36900- atomic_inc(&vcc->stats->tx_err);
36901+ atomic_inc_unchecked(&vcc->stats->tx_err);
36902 return -ENOMEM;
36903 }
36904 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36905diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36906index 4217f29..88f547a 100644
36907--- a/drivers/atm/iphase.c
36908+++ b/drivers/atm/iphase.c
36909@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36910 status = (u_short) (buf_desc_ptr->desc_mode);
36911 if (status & (RX_CER | RX_PTE | RX_OFL))
36912 {
36913- atomic_inc(&vcc->stats->rx_err);
36914+ atomic_inc_unchecked(&vcc->stats->rx_err);
36915 IF_ERR(printk("IA: bad packet, dropping it");)
36916 if (status & RX_CER) {
36917 IF_ERR(printk(" cause: packet CRC error\n");)
36918@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36919 len = dma_addr - buf_addr;
36920 if (len > iadev->rx_buf_sz) {
36921 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36922- atomic_inc(&vcc->stats->rx_err);
36923+ atomic_inc_unchecked(&vcc->stats->rx_err);
36924 goto out_free_desc;
36925 }
36926
36927@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36928 ia_vcc = INPH_IA_VCC(vcc);
36929 if (ia_vcc == NULL)
36930 {
36931- atomic_inc(&vcc->stats->rx_err);
36932+ atomic_inc_unchecked(&vcc->stats->rx_err);
36933 atm_return(vcc, skb->truesize);
36934 dev_kfree_skb_any(skb);
36935 goto INCR_DLE;
36936@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36937 if ((length > iadev->rx_buf_sz) || (length >
36938 (skb->len - sizeof(struct cpcs_trailer))))
36939 {
36940- atomic_inc(&vcc->stats->rx_err);
36941+ atomic_inc_unchecked(&vcc->stats->rx_err);
36942 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36943 length, skb->len);)
36944 atm_return(vcc, skb->truesize);
36945@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36946
36947 IF_RX(printk("rx_dle_intr: skb push");)
36948 vcc->push(vcc,skb);
36949- atomic_inc(&vcc->stats->rx);
36950+ atomic_inc_unchecked(&vcc->stats->rx);
36951 iadev->rx_pkt_cnt++;
36952 }
36953 INCR_DLE:
36954@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36955 {
36956 struct k_sonet_stats *stats;
36957 stats = &PRIV(_ia_dev[board])->sonet_stats;
36958- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36959- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36960- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36961- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36962- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36963- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36964- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36965- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36966- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36967+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36968+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36969+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36970+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36971+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36972+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36973+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36974+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36975+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36976 }
36977 ia_cmds.status = 0;
36978 break;
36979@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36980 if ((desc == 0) || (desc > iadev->num_tx_desc))
36981 {
36982 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36983- atomic_inc(&vcc->stats->tx);
36984+ atomic_inc_unchecked(&vcc->stats->tx);
36985 if (vcc->pop)
36986 vcc->pop(vcc, skb);
36987 else
36988@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36989 ATM_DESC(skb) = vcc->vci;
36990 skb_queue_tail(&iadev->tx_dma_q, skb);
36991
36992- atomic_inc(&vcc->stats->tx);
36993+ atomic_inc_unchecked(&vcc->stats->tx);
36994 iadev->tx_pkt_cnt++;
36995 /* Increment transaction counter */
36996 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36997
36998 #if 0
36999 /* add flow control logic */
37000- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37001+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37002 if (iavcc->vc_desc_cnt > 10) {
37003 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37004 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37005diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37006index fa7d701..1e404c7 100644
37007--- a/drivers/atm/lanai.c
37008+++ b/drivers/atm/lanai.c
37009@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37010 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37011 lanai_endtx(lanai, lvcc);
37012 lanai_free_skb(lvcc->tx.atmvcc, skb);
37013- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37014+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37015 }
37016
37017 /* Try to fill the buffer - don't call unless there is backlog */
37018@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37019 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37020 __net_timestamp(skb);
37021 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37022- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37023+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37024 out:
37025 lvcc->rx.buf.ptr = end;
37026 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37027@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37028 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37029 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37030 lanai->stats.service_rxnotaal5++;
37031- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37032+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37033 return 0;
37034 }
37035 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37036@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37037 int bytes;
37038 read_unlock(&vcc_sklist_lock);
37039 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37040- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37041+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37042 lvcc->stats.x.aal5.service_trash++;
37043 bytes = (SERVICE_GET_END(s) * 16) -
37044 (((unsigned long) lvcc->rx.buf.ptr) -
37045@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37046 }
37047 if (s & SERVICE_STREAM) {
37048 read_unlock(&vcc_sklist_lock);
37049- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37050+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37051 lvcc->stats.x.aal5.service_stream++;
37052 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37053 "PDU on VCI %d!\n", lanai->number, vci);
37054@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37055 return 0;
37056 }
37057 DPRINTK("got rx crc error on vci %d\n", vci);
37058- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37059+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37060 lvcc->stats.x.aal5.service_rxcrc++;
37061 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37062 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37063diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37064index 9988ac9..7c52585 100644
37065--- a/drivers/atm/nicstar.c
37066+++ b/drivers/atm/nicstar.c
37067@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37068 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37069 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37070 card->index);
37071- atomic_inc(&vcc->stats->tx_err);
37072+ atomic_inc_unchecked(&vcc->stats->tx_err);
37073 dev_kfree_skb_any(skb);
37074 return -EINVAL;
37075 }
37076@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37077 if (!vc->tx) {
37078 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37079 card->index);
37080- atomic_inc(&vcc->stats->tx_err);
37081+ atomic_inc_unchecked(&vcc->stats->tx_err);
37082 dev_kfree_skb_any(skb);
37083 return -EINVAL;
37084 }
37085@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37086 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37087 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37088 card->index);
37089- atomic_inc(&vcc->stats->tx_err);
37090+ atomic_inc_unchecked(&vcc->stats->tx_err);
37091 dev_kfree_skb_any(skb);
37092 return -EINVAL;
37093 }
37094
37095 if (skb_shinfo(skb)->nr_frags != 0) {
37096 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37097- atomic_inc(&vcc->stats->tx_err);
37098+ atomic_inc_unchecked(&vcc->stats->tx_err);
37099 dev_kfree_skb_any(skb);
37100 return -EINVAL;
37101 }
37102@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37103 }
37104
37105 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37106- atomic_inc(&vcc->stats->tx_err);
37107+ atomic_inc_unchecked(&vcc->stats->tx_err);
37108 dev_kfree_skb_any(skb);
37109 return -EIO;
37110 }
37111- atomic_inc(&vcc->stats->tx);
37112+ atomic_inc_unchecked(&vcc->stats->tx);
37113
37114 return 0;
37115 }
37116@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37117 printk
37118 ("nicstar%d: Can't allocate buffers for aal0.\n",
37119 card->index);
37120- atomic_add(i, &vcc->stats->rx_drop);
37121+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37122 break;
37123 }
37124 if (!atm_charge(vcc, sb->truesize)) {
37125 RXPRINTK
37126 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37127 card->index);
37128- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37129+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37130 dev_kfree_skb_any(sb);
37131 break;
37132 }
37133@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37134 ATM_SKB(sb)->vcc = vcc;
37135 __net_timestamp(sb);
37136 vcc->push(vcc, sb);
37137- atomic_inc(&vcc->stats->rx);
37138+ atomic_inc_unchecked(&vcc->stats->rx);
37139 cell += ATM_CELL_PAYLOAD;
37140 }
37141
37142@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37143 if (iovb == NULL) {
37144 printk("nicstar%d: Out of iovec buffers.\n",
37145 card->index);
37146- atomic_inc(&vcc->stats->rx_drop);
37147+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37148 recycle_rx_buf(card, skb);
37149 return;
37150 }
37151@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37152 small or large buffer itself. */
37153 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37154 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37155- atomic_inc(&vcc->stats->rx_err);
37156+ atomic_inc_unchecked(&vcc->stats->rx_err);
37157 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37158 NS_MAX_IOVECS);
37159 NS_PRV_IOVCNT(iovb) = 0;
37160@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37161 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37162 card->index);
37163 which_list(card, skb);
37164- atomic_inc(&vcc->stats->rx_err);
37165+ atomic_inc_unchecked(&vcc->stats->rx_err);
37166 recycle_rx_buf(card, skb);
37167 vc->rx_iov = NULL;
37168 recycle_iov_buf(card, iovb);
37169@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37170 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37171 card->index);
37172 which_list(card, skb);
37173- atomic_inc(&vcc->stats->rx_err);
37174+ atomic_inc_unchecked(&vcc->stats->rx_err);
37175 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37176 NS_PRV_IOVCNT(iovb));
37177 vc->rx_iov = NULL;
37178@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37179 printk(" - PDU size mismatch.\n");
37180 else
37181 printk(".\n");
37182- atomic_inc(&vcc->stats->rx_err);
37183+ atomic_inc_unchecked(&vcc->stats->rx_err);
37184 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37185 NS_PRV_IOVCNT(iovb));
37186 vc->rx_iov = NULL;
37187@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37188 /* skb points to a small buffer */
37189 if (!atm_charge(vcc, skb->truesize)) {
37190 push_rxbufs(card, skb);
37191- atomic_inc(&vcc->stats->rx_drop);
37192+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37193 } else {
37194 skb_put(skb, len);
37195 dequeue_sm_buf(card, skb);
37196@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37197 ATM_SKB(skb)->vcc = vcc;
37198 __net_timestamp(skb);
37199 vcc->push(vcc, skb);
37200- atomic_inc(&vcc->stats->rx);
37201+ atomic_inc_unchecked(&vcc->stats->rx);
37202 }
37203 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37204 struct sk_buff *sb;
37205@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37206 if (len <= NS_SMBUFSIZE) {
37207 if (!atm_charge(vcc, sb->truesize)) {
37208 push_rxbufs(card, sb);
37209- atomic_inc(&vcc->stats->rx_drop);
37210+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37211 } else {
37212 skb_put(sb, len);
37213 dequeue_sm_buf(card, sb);
37214@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37215 ATM_SKB(sb)->vcc = vcc;
37216 __net_timestamp(sb);
37217 vcc->push(vcc, sb);
37218- atomic_inc(&vcc->stats->rx);
37219+ atomic_inc_unchecked(&vcc->stats->rx);
37220 }
37221
37222 push_rxbufs(card, skb);
37223@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37224
37225 if (!atm_charge(vcc, skb->truesize)) {
37226 push_rxbufs(card, skb);
37227- atomic_inc(&vcc->stats->rx_drop);
37228+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37229 } else {
37230 dequeue_lg_buf(card, skb);
37231 #ifdef NS_USE_DESTRUCTORS
37232@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37233 ATM_SKB(skb)->vcc = vcc;
37234 __net_timestamp(skb);
37235 vcc->push(vcc, skb);
37236- atomic_inc(&vcc->stats->rx);
37237+ atomic_inc_unchecked(&vcc->stats->rx);
37238 }
37239
37240 push_rxbufs(card, sb);
37241@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37242 printk
37243 ("nicstar%d: Out of huge buffers.\n",
37244 card->index);
37245- atomic_inc(&vcc->stats->rx_drop);
37246+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37247 recycle_iovec_rx_bufs(card,
37248 (struct iovec *)
37249 iovb->data,
37250@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37251 card->hbpool.count++;
37252 } else
37253 dev_kfree_skb_any(hb);
37254- atomic_inc(&vcc->stats->rx_drop);
37255+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37256 } else {
37257 /* Copy the small buffer to the huge buffer */
37258 sb = (struct sk_buff *)iov->iov_base;
37259@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37260 #endif /* NS_USE_DESTRUCTORS */
37261 __net_timestamp(hb);
37262 vcc->push(vcc, hb);
37263- atomic_inc(&vcc->stats->rx);
37264+ atomic_inc_unchecked(&vcc->stats->rx);
37265 }
37266 }
37267
37268diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37269index 943cf0d..37d15d5 100644
37270--- a/drivers/atm/solos-pci.c
37271+++ b/drivers/atm/solos-pci.c
37272@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37273 }
37274 atm_charge(vcc, skb->truesize);
37275 vcc->push(vcc, skb);
37276- atomic_inc(&vcc->stats->rx);
37277+ atomic_inc_unchecked(&vcc->stats->rx);
37278 break;
37279
37280 case PKT_STATUS:
37281@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37282 vcc = SKB_CB(oldskb)->vcc;
37283
37284 if (vcc) {
37285- atomic_inc(&vcc->stats->tx);
37286+ atomic_inc_unchecked(&vcc->stats->tx);
37287 solos_pop(vcc, oldskb);
37288 } else {
37289 dev_kfree_skb_irq(oldskb);
37290diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37291index 0215934..ce9f5b1 100644
37292--- a/drivers/atm/suni.c
37293+++ b/drivers/atm/suni.c
37294@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37295
37296
37297 #define ADD_LIMITED(s,v) \
37298- atomic_add((v),&stats->s); \
37299- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37300+ atomic_add_unchecked((v),&stats->s); \
37301+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37302
37303
37304 static void suni_hz(unsigned long from_timer)
37305diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37306index 5120a96..e2572bd 100644
37307--- a/drivers/atm/uPD98402.c
37308+++ b/drivers/atm/uPD98402.c
37309@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37310 struct sonet_stats tmp;
37311 int error = 0;
37312
37313- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37314+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37315 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37316 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37317 if (zero && !error) {
37318@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37319
37320
37321 #define ADD_LIMITED(s,v) \
37322- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37323- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37324- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37325+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37326+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37327+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37328
37329
37330 static void stat_event(struct atm_dev *dev)
37331@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37332 if (reason & uPD98402_INT_PFM) stat_event(dev);
37333 if (reason & uPD98402_INT_PCO) {
37334 (void) GET(PCOCR); /* clear interrupt cause */
37335- atomic_add(GET(HECCT),
37336+ atomic_add_unchecked(GET(HECCT),
37337 &PRIV(dev)->sonet_stats.uncorr_hcs);
37338 }
37339 if ((reason & uPD98402_INT_RFO) &&
37340@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37341 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37342 uPD98402_INT_LOS),PIMR); /* enable them */
37343 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37344- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37345- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37346- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37347+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37348+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37349+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37350 return 0;
37351 }
37352
37353diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37354index 969c3c2..9b72956 100644
37355--- a/drivers/atm/zatm.c
37356+++ b/drivers/atm/zatm.c
37357@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37358 }
37359 if (!size) {
37360 dev_kfree_skb_irq(skb);
37361- if (vcc) atomic_inc(&vcc->stats->rx_err);
37362+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37363 continue;
37364 }
37365 if (!atm_charge(vcc,skb->truesize)) {
37366@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37367 skb->len = size;
37368 ATM_SKB(skb)->vcc = vcc;
37369 vcc->push(vcc,skb);
37370- atomic_inc(&vcc->stats->rx);
37371+ atomic_inc_unchecked(&vcc->stats->rx);
37372 }
37373 zout(pos & 0xffff,MTA(mbx));
37374 #if 0 /* probably a stupid idea */
37375@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37376 skb_queue_head(&zatm_vcc->backlog,skb);
37377 break;
37378 }
37379- atomic_inc(&vcc->stats->tx);
37380+ atomic_inc_unchecked(&vcc->stats->tx);
37381 wake_up(&zatm_vcc->tx_wait);
37382 }
37383
37384diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37385index 83e910a..b224a73 100644
37386--- a/drivers/base/bus.c
37387+++ b/drivers/base/bus.c
37388@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37389 return -EINVAL;
37390
37391 mutex_lock(&subsys->p->mutex);
37392- list_add_tail(&sif->node, &subsys->p->interfaces);
37393+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37394 if (sif->add_dev) {
37395 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37396 while ((dev = subsys_dev_iter_next(&iter)))
37397@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37398 subsys = sif->subsys;
37399
37400 mutex_lock(&subsys->p->mutex);
37401- list_del_init(&sif->node);
37402+ pax_list_del_init((struct list_head *)&sif->node);
37403 if (sif->remove_dev) {
37404 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37405 while ((dev = subsys_dev_iter_next(&iter)))
37406diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37407index 25798db..15f130e 100644
37408--- a/drivers/base/devtmpfs.c
37409+++ b/drivers/base/devtmpfs.c
37410@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37411 if (!thread)
37412 return 0;
37413
37414- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37415+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37416 if (err)
37417 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37418 else
37419@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37420 *err = sys_unshare(CLONE_NEWNS);
37421 if (*err)
37422 goto out;
37423- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37424+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37425 if (*err)
37426 goto out;
37427- sys_chdir("/.."); /* will traverse into overmounted root */
37428- sys_chroot(".");
37429+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37430+ sys_chroot((char __force_user *)".");
37431 complete(&setup_done);
37432 while (1) {
37433 spin_lock(&req_lock);
37434diff --git a/drivers/base/node.c b/drivers/base/node.c
37435index 8f7ed99..700dd0c 100644
37436--- a/drivers/base/node.c
37437+++ b/drivers/base/node.c
37438@@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37439 struct node_attr {
37440 struct device_attribute attr;
37441 enum node_states state;
37442-};
37443+} __do_const;
37444
37445 static ssize_t show_node_state(struct device *dev,
37446 struct device_attribute *attr, char *buf)
37447diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37448index ae098a2..0999830 100644
37449--- a/drivers/base/power/domain.c
37450+++ b/drivers/base/power/domain.c
37451@@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37452
37453 if (dev->power.subsys_data->domain_data) {
37454 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37455- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37456+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37457 if (clear_td)
37458- gpd_data->td = (struct gpd_timing_data){ 0 };
37459+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37460
37461 if (--gpd_data->refcount == 0) {
37462 dev->power.subsys_data->domain_data = NULL;
37463@@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37464 {
37465 struct cpuidle_driver *cpuidle_drv;
37466 struct gpd_cpu_data *cpu_data;
37467- struct cpuidle_state *idle_state;
37468+ cpuidle_state_no_const *idle_state;
37469 int ret = 0;
37470
37471 if (IS_ERR_OR_NULL(genpd) || state < 0)
37472@@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37473 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37474 {
37475 struct gpd_cpu_data *cpu_data;
37476- struct cpuidle_state *idle_state;
37477+ cpuidle_state_no_const *idle_state;
37478 int ret = 0;
37479
37480 if (IS_ERR_OR_NULL(genpd))
37481diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37482index 95b181d1..c4f0e19 100644
37483--- a/drivers/base/power/sysfs.c
37484+++ b/drivers/base/power/sysfs.c
37485@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37486 return -EIO;
37487 }
37488 }
37489- return sprintf(buf, p);
37490+ return sprintf(buf, "%s", p);
37491 }
37492
37493 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37494diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37495index 2d56f41..8830f19 100644
37496--- a/drivers/base/power/wakeup.c
37497+++ b/drivers/base/power/wakeup.c
37498@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37499 * They need to be modified together atomically, so it's better to use one
37500 * atomic variable to hold them both.
37501 */
37502-static atomic_t combined_event_count = ATOMIC_INIT(0);
37503+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37504
37505 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37506 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37507
37508 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37509 {
37510- unsigned int comb = atomic_read(&combined_event_count);
37511+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37512
37513 *cnt = (comb >> IN_PROGRESS_BITS);
37514 *inpr = comb & MAX_IN_PROGRESS;
37515@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37516 ws->start_prevent_time = ws->last_time;
37517
37518 /* Increment the counter of events in progress. */
37519- cec = atomic_inc_return(&combined_event_count);
37520+ cec = atomic_inc_return_unchecked(&combined_event_count);
37521
37522 trace_wakeup_source_activate(ws->name, cec);
37523 }
37524@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37525 * Increment the counter of registered wakeup events and decrement the
37526 * couter of wakeup events in progress simultaneously.
37527 */
37528- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37529+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37530 trace_wakeup_source_deactivate(ws->name, cec);
37531
37532 split_counters(&cnt, &inpr);
37533diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37534index e8d11b6..7b1b36f 100644
37535--- a/drivers/base/syscore.c
37536+++ b/drivers/base/syscore.c
37537@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37538 void register_syscore_ops(struct syscore_ops *ops)
37539 {
37540 mutex_lock(&syscore_ops_lock);
37541- list_add_tail(&ops->node, &syscore_ops_list);
37542+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37543 mutex_unlock(&syscore_ops_lock);
37544 }
37545 EXPORT_SYMBOL_GPL(register_syscore_ops);
37546@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37547 void unregister_syscore_ops(struct syscore_ops *ops)
37548 {
37549 mutex_lock(&syscore_ops_lock);
37550- list_del(&ops->node);
37551+ pax_list_del((struct list_head *)&ops->node);
37552 mutex_unlock(&syscore_ops_lock);
37553 }
37554 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37555diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37556index 73894ca..69f64ef 100644
37557--- a/drivers/block/cciss.c
37558+++ b/drivers/block/cciss.c
37559@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37560 while (!list_empty(&h->reqQ)) {
37561 c = list_entry(h->reqQ.next, CommandList_struct, list);
37562 /* can't do anything if fifo is full */
37563- if ((h->access.fifo_full(h))) {
37564+ if ((h->access->fifo_full(h))) {
37565 dev_warn(&h->pdev->dev, "fifo full\n");
37566 break;
37567 }
37568@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37569 h->Qdepth--;
37570
37571 /* Tell the controller execute command */
37572- h->access.submit_command(h, c);
37573+ h->access->submit_command(h, c);
37574
37575 /* Put job onto the completed Q */
37576 addQ(&h->cmpQ, c);
37577@@ -3447,17 +3447,17 @@ startio:
37578
37579 static inline unsigned long get_next_completion(ctlr_info_t *h)
37580 {
37581- return h->access.command_completed(h);
37582+ return h->access->command_completed(h);
37583 }
37584
37585 static inline int interrupt_pending(ctlr_info_t *h)
37586 {
37587- return h->access.intr_pending(h);
37588+ return h->access->intr_pending(h);
37589 }
37590
37591 static inline long interrupt_not_for_us(ctlr_info_t *h)
37592 {
37593- return ((h->access.intr_pending(h) == 0) ||
37594+ return ((h->access->intr_pending(h) == 0) ||
37595 (h->interrupts_enabled == 0));
37596 }
37597
37598@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37599 u32 a;
37600
37601 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37602- return h->access.command_completed(h);
37603+ return h->access->command_completed(h);
37604
37605 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37606 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37607@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37608 trans_support & CFGTBL_Trans_use_short_tags);
37609
37610 /* Change the access methods to the performant access methods */
37611- h->access = SA5_performant_access;
37612+ h->access = &SA5_performant_access;
37613 h->transMethod = CFGTBL_Trans_Performant;
37614
37615 return;
37616@@ -4325,7 +4325,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37617 if (prod_index < 0)
37618 return -ENODEV;
37619 h->product_name = products[prod_index].product_name;
37620- h->access = *(products[prod_index].access);
37621+ h->access = products[prod_index].access;
37622
37623 if (cciss_board_disabled(h)) {
37624 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37625@@ -5057,7 +5057,7 @@ reinit_after_soft_reset:
37626 }
37627
37628 /* make sure the board interrupts are off */
37629- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37630+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37631 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37632 if (rc)
37633 goto clean2;
37634@@ -5107,7 +5107,7 @@ reinit_after_soft_reset:
37635 * fake ones to scoop up any residual completions.
37636 */
37637 spin_lock_irqsave(&h->lock, flags);
37638- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37639+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37640 spin_unlock_irqrestore(&h->lock, flags);
37641 free_irq(h->intr[h->intr_mode], h);
37642 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37643@@ -5127,9 +5127,9 @@ reinit_after_soft_reset:
37644 dev_info(&h->pdev->dev, "Board READY.\n");
37645 dev_info(&h->pdev->dev,
37646 "Waiting for stale completions to drain.\n");
37647- h->access.set_intr_mask(h, CCISS_INTR_ON);
37648+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37649 msleep(10000);
37650- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37651+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37652
37653 rc = controller_reset_failed(h->cfgtable);
37654 if (rc)
37655@@ -5152,7 +5152,7 @@ reinit_after_soft_reset:
37656 cciss_scsi_setup(h);
37657
37658 /* Turn the interrupts on so we can service requests */
37659- h->access.set_intr_mask(h, CCISS_INTR_ON);
37660+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37661
37662 /* Get the firmware version */
37663 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37664@@ -5224,7 +5224,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37665 kfree(flush_buf);
37666 if (return_code != IO_OK)
37667 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37668- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37669+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37670 free_irq(h->intr[h->intr_mode], h);
37671 }
37672
37673diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37674index 7fda30e..2f27946 100644
37675--- a/drivers/block/cciss.h
37676+++ b/drivers/block/cciss.h
37677@@ -101,7 +101,7 @@ struct ctlr_info
37678 /* information about each logical volume */
37679 drive_info_struct *drv[CISS_MAX_LUN];
37680
37681- struct access_method access;
37682+ struct access_method *access;
37683
37684 /* queue and queue Info */
37685 struct list_head reqQ;
37686@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37687 }
37688
37689 static struct access_method SA5_access = {
37690- SA5_submit_command,
37691- SA5_intr_mask,
37692- SA5_fifo_full,
37693- SA5_intr_pending,
37694- SA5_completed,
37695+ .submit_command = SA5_submit_command,
37696+ .set_intr_mask = SA5_intr_mask,
37697+ .fifo_full = SA5_fifo_full,
37698+ .intr_pending = SA5_intr_pending,
37699+ .command_completed = SA5_completed,
37700 };
37701
37702 static struct access_method SA5B_access = {
37703- SA5_submit_command,
37704- SA5B_intr_mask,
37705- SA5_fifo_full,
37706- SA5B_intr_pending,
37707- SA5_completed,
37708+ .submit_command = SA5_submit_command,
37709+ .set_intr_mask = SA5B_intr_mask,
37710+ .fifo_full = SA5_fifo_full,
37711+ .intr_pending = SA5B_intr_pending,
37712+ .command_completed = SA5_completed,
37713 };
37714
37715 static struct access_method SA5_performant_access = {
37716- SA5_submit_command,
37717- SA5_performant_intr_mask,
37718- SA5_fifo_full,
37719- SA5_performant_intr_pending,
37720- SA5_performant_completed,
37721+ .submit_command = SA5_submit_command,
37722+ .set_intr_mask = SA5_performant_intr_mask,
37723+ .fifo_full = SA5_fifo_full,
37724+ .intr_pending = SA5_performant_intr_pending,
37725+ .command_completed = SA5_performant_completed,
37726 };
37727
37728 struct board_type {
37729diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37730index 2b94403..fd6ad1f 100644
37731--- a/drivers/block/cpqarray.c
37732+++ b/drivers/block/cpqarray.c
37733@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37734 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37735 goto Enomem4;
37736 }
37737- hba[i]->access.set_intr_mask(hba[i], 0);
37738+ hba[i]->access->set_intr_mask(hba[i], 0);
37739 if (request_irq(hba[i]->intr, do_ida_intr,
37740 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37741 {
37742@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37743 add_timer(&hba[i]->timer);
37744
37745 /* Enable IRQ now that spinlock and rate limit timer are set up */
37746- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37747+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37748
37749 for(j=0; j<NWD; j++) {
37750 struct gendisk *disk = ida_gendisk[i][j];
37751@@ -694,7 +694,7 @@ DBGINFO(
37752 for(i=0; i<NR_PRODUCTS; i++) {
37753 if (board_id == products[i].board_id) {
37754 c->product_name = products[i].product_name;
37755- c->access = *(products[i].access);
37756+ c->access = products[i].access;
37757 break;
37758 }
37759 }
37760@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37761 hba[ctlr]->intr = intr;
37762 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37763 hba[ctlr]->product_name = products[j].product_name;
37764- hba[ctlr]->access = *(products[j].access);
37765+ hba[ctlr]->access = products[j].access;
37766 hba[ctlr]->ctlr = ctlr;
37767 hba[ctlr]->board_id = board_id;
37768 hba[ctlr]->pci_dev = NULL; /* not PCI */
37769@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37770
37771 while((c = h->reqQ) != NULL) {
37772 /* Can't do anything if we're busy */
37773- if (h->access.fifo_full(h) == 0)
37774+ if (h->access->fifo_full(h) == 0)
37775 return;
37776
37777 /* Get the first entry from the request Q */
37778@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37779 h->Qdepth--;
37780
37781 /* Tell the controller to do our bidding */
37782- h->access.submit_command(h, c);
37783+ h->access->submit_command(h, c);
37784
37785 /* Get onto the completion Q */
37786 addQ(&h->cmpQ, c);
37787@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37788 unsigned long flags;
37789 __u32 a,a1;
37790
37791- istat = h->access.intr_pending(h);
37792+ istat = h->access->intr_pending(h);
37793 /* Is this interrupt for us? */
37794 if (istat == 0)
37795 return IRQ_NONE;
37796@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37797 */
37798 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37799 if (istat & FIFO_NOT_EMPTY) {
37800- while((a = h->access.command_completed(h))) {
37801+ while((a = h->access->command_completed(h))) {
37802 a1 = a; a &= ~3;
37803 if ((c = h->cmpQ) == NULL)
37804 {
37805@@ -1448,11 +1448,11 @@ static int sendcmd(
37806 /*
37807 * Disable interrupt
37808 */
37809- info_p->access.set_intr_mask(info_p, 0);
37810+ info_p->access->set_intr_mask(info_p, 0);
37811 /* Make sure there is room in the command FIFO */
37812 /* Actually it should be completely empty at this time. */
37813 for (i = 200000; i > 0; i--) {
37814- temp = info_p->access.fifo_full(info_p);
37815+ temp = info_p->access->fifo_full(info_p);
37816 if (temp != 0) {
37817 break;
37818 }
37819@@ -1465,7 +1465,7 @@ DBG(
37820 /*
37821 * Send the cmd
37822 */
37823- info_p->access.submit_command(info_p, c);
37824+ info_p->access->submit_command(info_p, c);
37825 complete = pollcomplete(ctlr);
37826
37827 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37828@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37829 * we check the new geometry. Then turn interrupts back on when
37830 * we're done.
37831 */
37832- host->access.set_intr_mask(host, 0);
37833+ host->access->set_intr_mask(host, 0);
37834 getgeometry(ctlr);
37835- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37836+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37837
37838 for(i=0; i<NWD; i++) {
37839 struct gendisk *disk = ida_gendisk[ctlr][i];
37840@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37841 /* Wait (up to 2 seconds) for a command to complete */
37842
37843 for (i = 200000; i > 0; i--) {
37844- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37845+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37846 if (done == 0) {
37847 udelay(10); /* a short fixed delay */
37848 } else
37849diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37850index be73e9d..7fbf140 100644
37851--- a/drivers/block/cpqarray.h
37852+++ b/drivers/block/cpqarray.h
37853@@ -99,7 +99,7 @@ struct ctlr_info {
37854 drv_info_t drv[NWD];
37855 struct proc_dir_entry *proc;
37856
37857- struct access_method access;
37858+ struct access_method *access;
37859
37860 cmdlist_t *reqQ;
37861 cmdlist_t *cmpQ;
37862diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37863index e7093d4..b364085 100644
37864--- a/drivers/block/drbd/drbd_int.h
37865+++ b/drivers/block/drbd/drbd_int.h
37866@@ -331,7 +331,7 @@ struct drbd_epoch {
37867 struct drbd_connection *connection;
37868 struct list_head list;
37869 unsigned int barrier_nr;
37870- atomic_t epoch_size; /* increased on every request added. */
37871+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37872 atomic_t active; /* increased on every req. added, and dec on every finished. */
37873 unsigned long flags;
37874 };
37875@@ -787,7 +787,7 @@ struct drbd_device {
37876 unsigned int al_tr_number;
37877 int al_tr_cycle;
37878 wait_queue_head_t seq_wait;
37879- atomic_t packet_seq;
37880+ atomic_unchecked_t packet_seq;
37881 unsigned int peer_seq;
37882 spinlock_t peer_seq_lock;
37883 unsigned int minor;
37884@@ -1361,7 +1361,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37885 char __user *uoptval;
37886 int err;
37887
37888- uoptval = (char __user __force *)optval;
37889+ uoptval = (char __force_user *)optval;
37890
37891 set_fs(KERNEL_DS);
37892 if (level == SOL_SOCKET)
37893diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37894index 89c497c..9c736ae 100644
37895--- a/drivers/block/drbd/drbd_interval.c
37896+++ b/drivers/block/drbd/drbd_interval.c
37897@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37898 }
37899
37900 static const struct rb_augment_callbacks augment_callbacks = {
37901- augment_propagate,
37902- augment_copy,
37903- augment_rotate,
37904+ .propagate = augment_propagate,
37905+ .copy = augment_copy,
37906+ .rotate = augment_rotate,
37907 };
37908
37909 /**
37910diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37911index 331e5cc..6d657bce 100644
37912--- a/drivers/block/drbd/drbd_main.c
37913+++ b/drivers/block/drbd/drbd_main.c
37914@@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
37915 p->sector = sector;
37916 p->block_id = block_id;
37917 p->blksize = blksize;
37918- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
37919+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
37920 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
37921 }
37922
37923@@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
37924 return -EIO;
37925 p->sector = cpu_to_be64(req->i.sector);
37926 p->block_id = (unsigned long)req;
37927- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
37928+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
37929 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
37930 if (device->state.conn >= C_SYNC_SOURCE &&
37931 device->state.conn <= C_PAUSED_SYNC_T)
37932@@ -2658,8 +2658,8 @@ void drbd_destroy_connection(struct kref *kref)
37933 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
37934 struct drbd_resource *resource = connection->resource;
37935
37936- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
37937- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
37938+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
37939+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
37940 kfree(connection->current_epoch);
37941
37942 idr_destroy(&connection->peer_devices);
37943diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37944index 526414b..4eb8184 100644
37945--- a/drivers/block/drbd/drbd_nl.c
37946+++ b/drivers/block/drbd/drbd_nl.c
37947@@ -3505,7 +3505,7 @@ out:
37948
37949 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37950 {
37951- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37952+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37953 struct sk_buff *msg;
37954 struct drbd_genlmsghdr *d_out;
37955 unsigned seq;
37956@@ -3518,7 +3518,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37957 return;
37958 }
37959
37960- seq = atomic_inc_return(&drbd_genl_seq);
37961+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37962 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37963 if (!msg)
37964 goto failed;
37965diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37966index 68e3992..1aca24a 100644
37967--- a/drivers/block/drbd/drbd_receiver.c
37968+++ b/drivers/block/drbd/drbd_receiver.c
37969@@ -826,7 +826,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
37970 struct drbd_device *device = peer_device->device;
37971 int err;
37972
37973- atomic_set(&device->packet_seq, 0);
37974+ atomic_set_unchecked(&device->packet_seq, 0);
37975 device->peer_seq = 0;
37976
37977 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
37978@@ -1188,7 +1188,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37979 do {
37980 next_epoch = NULL;
37981
37982- epoch_size = atomic_read(&epoch->epoch_size);
37983+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37984
37985 switch (ev & ~EV_CLEANUP) {
37986 case EV_PUT:
37987@@ -1228,7 +1228,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37988 rv = FE_DESTROYED;
37989 } else {
37990 epoch->flags = 0;
37991- atomic_set(&epoch->epoch_size, 0);
37992+ atomic_set_unchecked(&epoch->epoch_size, 0);
37993 /* atomic_set(&epoch->active, 0); is already zero */
37994 if (rv == FE_STILL_LIVE)
37995 rv = FE_RECYCLED;
37996@@ -1456,7 +1456,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
37997 conn_wait_active_ee_empty(connection);
37998 drbd_flush(connection);
37999
38000- if (atomic_read(&connection->current_epoch->epoch_size)) {
38001+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38002 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38003 if (epoch)
38004 break;
38005@@ -1469,11 +1469,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38006 }
38007
38008 epoch->flags = 0;
38009- atomic_set(&epoch->epoch_size, 0);
38010+ atomic_set_unchecked(&epoch->epoch_size, 0);
38011 atomic_set(&epoch->active, 0);
38012
38013 spin_lock(&connection->epoch_lock);
38014- if (atomic_read(&connection->current_epoch->epoch_size)) {
38015+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38016 list_add(&epoch->list, &connection->current_epoch->list);
38017 connection->current_epoch = epoch;
38018 connection->epochs++;
38019@@ -2182,7 +2182,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38020
38021 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38022 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38023- atomic_inc(&connection->current_epoch->epoch_size);
38024+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38025 err2 = drbd_drain_block(peer_device, pi->size);
38026 if (!err)
38027 err = err2;
38028@@ -2216,7 +2216,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38029
38030 spin_lock(&connection->epoch_lock);
38031 peer_req->epoch = connection->current_epoch;
38032- atomic_inc(&peer_req->epoch->epoch_size);
38033+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38034 atomic_inc(&peer_req->epoch->active);
38035 spin_unlock(&connection->epoch_lock);
38036
38037@@ -4396,7 +4396,7 @@ struct data_cmd {
38038 int expect_payload;
38039 size_t pkt_size;
38040 int (*fn)(struct drbd_connection *, struct packet_info *);
38041-};
38042+} __do_const;
38043
38044 static struct data_cmd drbd_cmd_handler[] = {
38045 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38046@@ -4506,7 +4506,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38047 if (!list_empty(&connection->current_epoch->list))
38048 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38049 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38050- atomic_set(&connection->current_epoch->epoch_size, 0);
38051+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38052 connection->send.seen_any_write_yet = false;
38053
38054 drbd_info(connection, "Connection closed\n");
38055@@ -5281,7 +5281,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38056 struct asender_cmd {
38057 size_t pkt_size;
38058 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38059-};
38060+} __do_const;
38061
38062 static struct asender_cmd asender_tbl[] = {
38063 [P_PING] = { 0, got_Ping },
38064diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38065index f70a230..9dc90d5 100644
38066--- a/drivers/block/loop.c
38067+++ b/drivers/block/loop.c
38068@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38069
38070 file_start_write(file);
38071 set_fs(get_ds());
38072- bw = file->f_op->write(file, buf, len, &pos);
38073+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38074 set_fs(old_fs);
38075 file_end_write(file);
38076 if (likely(bw == len))
38077diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38078index 091b9ea..f5428f8 100644
38079--- a/drivers/block/null_blk.c
38080+++ b/drivers/block/null_blk.c
38081@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38082 return 0;
38083 }
38084
38085-static struct blk_mq_ops null_mq_ops = {
38086- .queue_rq = null_queue_rq,
38087- .map_queue = blk_mq_map_queue,
38088+static struct blk_mq_ops null_mq_single_ops = {
38089+ .queue_rq = null_queue_rq,
38090+ .map_queue = blk_mq_map_queue,
38091 .init_hctx = null_init_hctx,
38092 .complete = null_softirq_done_fn,
38093+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38094+ .free_hctx = blk_mq_free_single_hw_queue,
38095+};
38096+
38097+static struct blk_mq_ops null_mq_per_node_ops = {
38098+ .queue_rq = null_queue_rq,
38099+ .map_queue = blk_mq_map_queue,
38100+ .init_hctx = null_init_hctx,
38101+ .alloc_hctx = null_alloc_hctx,
38102+ .free_hctx = null_free_hctx,
38103 };
38104
38105 static struct blk_mq_reg null_mq_reg = {
38106- .ops = &null_mq_ops,
38107+ .ops = &null_mq_single_ops,
38108 .queue_depth = 64,
38109 .cmd_size = sizeof(struct nullb_cmd),
38110 .flags = BLK_MQ_F_SHOULD_MERGE,
38111@@ -521,13 +531,8 @@ static int null_add_dev(void)
38112 null_mq_reg.queue_depth = hw_queue_depth;
38113 null_mq_reg.nr_hw_queues = submit_queues;
38114
38115- if (use_per_node_hctx) {
38116- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38117- null_mq_reg.ops->free_hctx = null_free_hctx;
38118- } else {
38119- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38120- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38121- }
38122+ if (use_per_node_hctx)
38123+ null_mq_reg.ops = &null_mq_per_node_ops;
38124
38125 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38126 } else if (queue_mode == NULL_Q_BIO) {
38127diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38128index a2af73d..c0b8f61 100644
38129--- a/drivers/block/pktcdvd.c
38130+++ b/drivers/block/pktcdvd.c
38131@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38132
38133 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38134 {
38135- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38136+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38137 }
38138
38139 /*
38140@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38141 return -EROFS;
38142 }
38143 pd->settings.fp = ti.fp;
38144- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38145+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38146
38147 if (ti.nwa_v) {
38148 pd->nwa = be32_to_cpu(ti.next_writable);
38149diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38150index e5565fb..71be10b4 100644
38151--- a/drivers/block/smart1,2.h
38152+++ b/drivers/block/smart1,2.h
38153@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38154 }
38155
38156 static struct access_method smart4_access = {
38157- smart4_submit_command,
38158- smart4_intr_mask,
38159- smart4_fifo_full,
38160- smart4_intr_pending,
38161- smart4_completed,
38162+ .submit_command = smart4_submit_command,
38163+ .set_intr_mask = smart4_intr_mask,
38164+ .fifo_full = smart4_fifo_full,
38165+ .intr_pending = smart4_intr_pending,
38166+ .command_completed = smart4_completed,
38167 };
38168
38169 /*
38170@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38171 }
38172
38173 static struct access_method smart2_access = {
38174- smart2_submit_command,
38175- smart2_intr_mask,
38176- smart2_fifo_full,
38177- smart2_intr_pending,
38178- smart2_completed,
38179+ .submit_command = smart2_submit_command,
38180+ .set_intr_mask = smart2_intr_mask,
38181+ .fifo_full = smart2_fifo_full,
38182+ .intr_pending = smart2_intr_pending,
38183+ .command_completed = smart2_completed,
38184 };
38185
38186 /*
38187@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38188 }
38189
38190 static struct access_method smart2e_access = {
38191- smart2e_submit_command,
38192- smart2e_intr_mask,
38193- smart2e_fifo_full,
38194- smart2e_intr_pending,
38195- smart2e_completed,
38196+ .submit_command = smart2e_submit_command,
38197+ .set_intr_mask = smart2e_intr_mask,
38198+ .fifo_full = smart2e_fifo_full,
38199+ .intr_pending = smart2e_intr_pending,
38200+ .command_completed = smart2e_completed,
38201 };
38202
38203 /*
38204@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38205 }
38206
38207 static struct access_method smart1_access = {
38208- smart1_submit_command,
38209- smart1_intr_mask,
38210- smart1_fifo_full,
38211- smart1_intr_pending,
38212- smart1_completed,
38213+ .submit_command = smart1_submit_command,
38214+ .set_intr_mask = smart1_intr_mask,
38215+ .fifo_full = smart1_fifo_full,
38216+ .intr_pending = smart1_intr_pending,
38217+ .command_completed = smart1_completed,
38218 };
38219diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38220index f038dba..bb74c08 100644
38221--- a/drivers/bluetooth/btwilink.c
38222+++ b/drivers/bluetooth/btwilink.c
38223@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38224
38225 static int bt_ti_probe(struct platform_device *pdev)
38226 {
38227- static struct ti_st *hst;
38228+ struct ti_st *hst;
38229 struct hci_dev *hdev;
38230 int err;
38231
38232diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38233index 8a3aff7..d7538c2 100644
38234--- a/drivers/cdrom/cdrom.c
38235+++ b/drivers/cdrom/cdrom.c
38236@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38237 ENSURE(reset, CDC_RESET);
38238 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38239 cdi->mc_flags = 0;
38240- cdo->n_minors = 0;
38241 cdi->options = CDO_USE_FFLAGS;
38242
38243 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38244@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38245 else
38246 cdi->cdda_method = CDDA_OLD;
38247
38248- if (!cdo->generic_packet)
38249- cdo->generic_packet = cdrom_dummy_generic_packet;
38250+ if (!cdo->generic_packet) {
38251+ pax_open_kernel();
38252+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38253+ pax_close_kernel();
38254+ }
38255
38256 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38257 mutex_lock(&cdrom_mutex);
38258@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38259 if (cdi->exit)
38260 cdi->exit(cdi);
38261
38262- cdi->ops->n_minors--;
38263 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38264 }
38265
38266@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38267 */
38268 nr = nframes;
38269 do {
38270- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38271+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38272 if (cgc.buffer)
38273 break;
38274
38275@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38276 struct cdrom_device_info *cdi;
38277 int ret;
38278
38279- ret = scnprintf(info + *pos, max_size - *pos, header);
38280+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38281 if (!ret)
38282 return 1;
38283
38284diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38285index 51e75ad..39c4c76 100644
38286--- a/drivers/cdrom/gdrom.c
38287+++ b/drivers/cdrom/gdrom.c
38288@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38289 .audio_ioctl = gdrom_audio_ioctl,
38290 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38291 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38292- .n_minors = 1,
38293 };
38294
38295 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38296diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38297index 6e9f74a..50c7ceae 100644
38298--- a/drivers/char/Kconfig
38299+++ b/drivers/char/Kconfig
38300@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38301
38302 config DEVKMEM
38303 bool "/dev/kmem virtual device support"
38304- default y
38305+ default n
38306+ depends on !GRKERNSEC_KMEM
38307 help
38308 Say Y here if you want to support the /dev/kmem device. The
38309 /dev/kmem device is rarely used, but can be used for certain
38310@@ -577,6 +578,7 @@ config DEVPORT
38311 bool
38312 depends on !M68K
38313 depends on ISA || PCI
38314+ depends on !GRKERNSEC_KMEM
38315 default y
38316
38317 source "drivers/s390/char/Kconfig"
38318diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38319index a48e05b..6bac831 100644
38320--- a/drivers/char/agp/compat_ioctl.c
38321+++ b/drivers/char/agp/compat_ioctl.c
38322@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38323 return -ENOMEM;
38324 }
38325
38326- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38327+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38328 sizeof(*usegment) * ureserve.seg_count)) {
38329 kfree(usegment);
38330 kfree(ksegment);
38331diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38332index b297033..fa217ca 100644
38333--- a/drivers/char/agp/frontend.c
38334+++ b/drivers/char/agp/frontend.c
38335@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38336 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38337 return -EFAULT;
38338
38339- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38340+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38341 return -EFAULT;
38342
38343 client = agp_find_client_by_pid(reserve.pid);
38344@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38345 if (segment == NULL)
38346 return -ENOMEM;
38347
38348- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38349+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38350 sizeof(struct agp_segment) * reserve.seg_count)) {
38351 kfree(segment);
38352 return -EFAULT;
38353diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38354index 4f94375..413694e 100644
38355--- a/drivers/char/genrtc.c
38356+++ b/drivers/char/genrtc.c
38357@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38358 switch (cmd) {
38359
38360 case RTC_PLL_GET:
38361+ memset(&pll, 0, sizeof(pll));
38362 if (get_rtc_pll(&pll))
38363 return -EINVAL;
38364 else
38365diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38366index d5d4cd8..22d561d 100644
38367--- a/drivers/char/hpet.c
38368+++ b/drivers/char/hpet.c
38369@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38370 }
38371
38372 static int
38373-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38374+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38375 struct hpet_info *info)
38376 {
38377 struct hpet_timer __iomem *timer;
38378diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38379index 86fe45c..c0ea948 100644
38380--- a/drivers/char/hw_random/intel-rng.c
38381+++ b/drivers/char/hw_random/intel-rng.c
38382@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38383
38384 if (no_fwh_detect)
38385 return -ENODEV;
38386- printk(warning);
38387+ printk("%s", warning);
38388 return -EBUSY;
38389 }
38390
38391diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38392index e6db938..835e3a2 100644
38393--- a/drivers/char/ipmi/ipmi_msghandler.c
38394+++ b/drivers/char/ipmi/ipmi_msghandler.c
38395@@ -438,7 +438,7 @@ struct ipmi_smi {
38396 struct proc_dir_entry *proc_dir;
38397 char proc_dir_name[10];
38398
38399- atomic_t stats[IPMI_NUM_STATS];
38400+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38401
38402 /*
38403 * run_to_completion duplicate of smb_info, smi_info
38404@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38405 static DEFINE_MUTEX(smi_watchers_mutex);
38406
38407 #define ipmi_inc_stat(intf, stat) \
38408- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38409+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38410 #define ipmi_get_stat(intf, stat) \
38411- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38412+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38413
38414 static int is_lan_addr(struct ipmi_addr *addr)
38415 {
38416@@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38417 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38418 init_waitqueue_head(&intf->waitq);
38419 for (i = 0; i < IPMI_NUM_STATS; i++)
38420- atomic_set(&intf->stats[i], 0);
38421+ atomic_set_unchecked(&intf->stats[i], 0);
38422
38423 intf->proc_dir = NULL;
38424
38425diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38426index 1c4bb4f..719e873 100644
38427--- a/drivers/char/ipmi/ipmi_si_intf.c
38428+++ b/drivers/char/ipmi/ipmi_si_intf.c
38429@@ -285,7 +285,7 @@ struct smi_info {
38430 unsigned char slave_addr;
38431
38432 /* Counters and things for the proc filesystem. */
38433- atomic_t stats[SI_NUM_STATS];
38434+ atomic_unchecked_t stats[SI_NUM_STATS];
38435
38436 struct task_struct *thread;
38437
38438@@ -294,9 +294,9 @@ struct smi_info {
38439 };
38440
38441 #define smi_inc_stat(smi, stat) \
38442- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38443+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38444 #define smi_get_stat(smi, stat) \
38445- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38446+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38447
38448 #define SI_MAX_PARMS 4
38449
38450@@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
38451 atomic_set(&new_smi->req_events, 0);
38452 new_smi->run_to_completion = false;
38453 for (i = 0; i < SI_NUM_STATS; i++)
38454- atomic_set(&new_smi->stats[i], 0);
38455+ atomic_set_unchecked(&new_smi->stats[i], 0);
38456
38457 new_smi->interrupt_disabled = true;
38458 atomic_set(&new_smi->stop_operation, 0);
38459diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38460index 917403f..dddd899 100644
38461--- a/drivers/char/mem.c
38462+++ b/drivers/char/mem.c
38463@@ -18,6 +18,7 @@
38464 #include <linux/raw.h>
38465 #include <linux/tty.h>
38466 #include <linux/capability.h>
38467+#include <linux/security.h>
38468 #include <linux/ptrace.h>
38469 #include <linux/device.h>
38470 #include <linux/highmem.h>
38471@@ -36,6 +37,10 @@
38472
38473 #define DEVPORT_MINOR 4
38474
38475+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38476+extern const struct file_operations grsec_fops;
38477+#endif
38478+
38479 static inline unsigned long size_inside_page(unsigned long start,
38480 unsigned long size)
38481 {
38482@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38483
38484 while (cursor < to) {
38485 if (!devmem_is_allowed(pfn)) {
38486+#ifdef CONFIG_GRKERNSEC_KMEM
38487+ gr_handle_mem_readwrite(from, to);
38488+#else
38489 printk(KERN_INFO
38490 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38491 current->comm, from, to);
38492+#endif
38493 return 0;
38494 }
38495 cursor += PAGE_SIZE;
38496@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38497 }
38498 return 1;
38499 }
38500+#elif defined(CONFIG_GRKERNSEC_KMEM)
38501+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38502+{
38503+ return 0;
38504+}
38505 #else
38506 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38507 {
38508@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38509
38510 while (count > 0) {
38511 unsigned long remaining;
38512+ char *temp;
38513
38514 sz = size_inside_page(p, count);
38515
38516@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38517 if (!ptr)
38518 return -EFAULT;
38519
38520- remaining = copy_to_user(buf, ptr, sz);
38521+#ifdef CONFIG_PAX_USERCOPY
38522+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38523+ if (!temp) {
38524+ unxlate_dev_mem_ptr(p, ptr);
38525+ return -ENOMEM;
38526+ }
38527+ memcpy(temp, ptr, sz);
38528+#else
38529+ temp = ptr;
38530+#endif
38531+
38532+ remaining = copy_to_user(buf, temp, sz);
38533+
38534+#ifdef CONFIG_PAX_USERCOPY
38535+ kfree(temp);
38536+#endif
38537+
38538 unxlate_dev_mem_ptr(p, ptr);
38539 if (remaining)
38540 return -EFAULT;
38541@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38542 size_t count, loff_t *ppos)
38543 {
38544 unsigned long p = *ppos;
38545- ssize_t low_count, read, sz;
38546+ ssize_t low_count, read, sz, err = 0;
38547 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38548- int err = 0;
38549
38550 read = 0;
38551 if (p < (unsigned long) high_memory) {
38552@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38553 }
38554 #endif
38555 while (low_count > 0) {
38556+ char *temp;
38557+
38558 sz = size_inside_page(p, low_count);
38559
38560 /*
38561@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38562 */
38563 kbuf = xlate_dev_kmem_ptr((char *)p);
38564
38565- if (copy_to_user(buf, kbuf, sz))
38566+#ifdef CONFIG_PAX_USERCOPY
38567+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38568+ if (!temp)
38569+ return -ENOMEM;
38570+ memcpy(temp, kbuf, sz);
38571+#else
38572+ temp = kbuf;
38573+#endif
38574+
38575+ err = copy_to_user(buf, temp, sz);
38576+
38577+#ifdef CONFIG_PAX_USERCOPY
38578+ kfree(temp);
38579+#endif
38580+
38581+ if (err)
38582 return -EFAULT;
38583 buf += sz;
38584 p += sz;
38585@@ -827,6 +874,9 @@ static const struct memdev {
38586 #ifdef CONFIG_PRINTK
38587 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38588 #endif
38589+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38590+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38591+#endif
38592 };
38593
38594 static int memory_open(struct inode *inode, struct file *filp)
38595@@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
38596 continue;
38597
38598 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38599- NULL, devlist[minor].name);
38600+ NULL, "%s", devlist[minor].name);
38601 }
38602
38603 return tty_init();
38604diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38605index 9df78e2..01ba9ae 100644
38606--- a/drivers/char/nvram.c
38607+++ b/drivers/char/nvram.c
38608@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38609
38610 spin_unlock_irq(&rtc_lock);
38611
38612- if (copy_to_user(buf, contents, tmp - contents))
38613+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38614 return -EFAULT;
38615
38616 *ppos = i;
38617diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38618index 8320abd..ec48108 100644
38619--- a/drivers/char/pcmcia/synclink_cs.c
38620+++ b/drivers/char/pcmcia/synclink_cs.c
38621@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38622
38623 if (debug_level >= DEBUG_LEVEL_INFO)
38624 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38625- __FILE__, __LINE__, info->device_name, port->count);
38626+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38627
38628- WARN_ON(!port->count);
38629+ WARN_ON(!atomic_read(&port->count));
38630
38631 if (tty_port_close_start(port, tty, filp) == 0)
38632 goto cleanup;
38633@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38634 cleanup:
38635 if (debug_level >= DEBUG_LEVEL_INFO)
38636 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38637- tty->driver->name, port->count);
38638+ tty->driver->name, atomic_read(&port->count));
38639 }
38640
38641 /* Wait until the transmitter is empty.
38642@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38643
38644 if (debug_level >= DEBUG_LEVEL_INFO)
38645 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38646- __FILE__, __LINE__, tty->driver->name, port->count);
38647+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38648
38649 /* If port is closing, signal caller to try again */
38650 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38651@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38652 goto cleanup;
38653 }
38654 spin_lock(&port->lock);
38655- port->count++;
38656+ atomic_inc(&port->count);
38657 spin_unlock(&port->lock);
38658 spin_unlock_irqrestore(&info->netlock, flags);
38659
38660- if (port->count == 1) {
38661+ if (atomic_read(&port->count) == 1) {
38662 /* 1st open on this device, init hardware */
38663 retval = startup(info, tty);
38664 if (retval < 0)
38665@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38666 unsigned short new_crctype;
38667
38668 /* return error if TTY interface open */
38669- if (info->port.count)
38670+ if (atomic_read(&info->port.count))
38671 return -EBUSY;
38672
38673 switch (encoding)
38674@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38675
38676 /* arbitrate between network and tty opens */
38677 spin_lock_irqsave(&info->netlock, flags);
38678- if (info->port.count != 0 || info->netcount != 0) {
38679+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38680 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38681 spin_unlock_irqrestore(&info->netlock, flags);
38682 return -EBUSY;
38683@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38684 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38685
38686 /* return error if TTY interface open */
38687- if (info->port.count)
38688+ if (atomic_read(&info->port.count))
38689 return -EBUSY;
38690
38691 if (cmd != SIOCWANDEV)
38692diff --git a/drivers/char/random.c b/drivers/char/random.c
38693index 2b6e4cd..43d7ae1 100644
38694--- a/drivers/char/random.c
38695+++ b/drivers/char/random.c
38696@@ -270,10 +270,17 @@
38697 /*
38698 * Configuration information
38699 */
38700+#ifdef CONFIG_GRKERNSEC_RANDNET
38701+#define INPUT_POOL_SHIFT 14
38702+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38703+#define OUTPUT_POOL_SHIFT 12
38704+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38705+#else
38706 #define INPUT_POOL_SHIFT 12
38707 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38708 #define OUTPUT_POOL_SHIFT 10
38709 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38710+#endif
38711 #define SEC_XFER_SIZE 512
38712 #define EXTRACT_SIZE 10
38713
38714@@ -284,9 +291,6 @@
38715 /*
38716 * To allow fractional bits to be tracked, the entropy_count field is
38717 * denominated in units of 1/8th bits.
38718- *
38719- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38720- * credit_entropy_bits() needs to be 64 bits wide.
38721 */
38722 #define ENTROPY_SHIFT 3
38723 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38724@@ -361,12 +365,19 @@ static struct poolinfo {
38725 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38726 int tap1, tap2, tap3, tap4, tap5;
38727 } poolinfo_table[] = {
38728+#ifdef CONFIG_GRKERNSEC_RANDNET
38729+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38730+ { S(512), 411, 308, 208, 104, 1 },
38731+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38732+ { S(128), 104, 76, 51, 25, 1 },
38733+#else
38734 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38735 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38736 { S(128), 104, 76, 51, 25, 1 },
38737 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38738 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38739 { S(32), 26, 19, 14, 7, 1 },
38740+#endif
38741 #if 0
38742 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38743 { S(2048), 1638, 1231, 819, 411, 1 },
38744@@ -433,9 +444,9 @@ struct entropy_store {
38745 };
38746
38747 static void push_to_pool(struct work_struct *work);
38748-static __u32 input_pool_data[INPUT_POOL_WORDS];
38749-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38750-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38751+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38752+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38753+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38754
38755 static struct entropy_store input_pool = {
38756 .poolinfo = &poolinfo_table[0],
38757@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38758 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38759 }
38760
38761- ACCESS_ONCE(r->input_rotate) = input_rotate;
38762- ACCESS_ONCE(r->add_ptr) = i;
38763+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38764+ ACCESS_ONCE_RW(r->add_ptr) = i;
38765 smp_wmb();
38766
38767 if (out)
38768@@ -632,7 +643,7 @@ retry:
38769 /* The +2 corresponds to the /4 in the denominator */
38770
38771 do {
38772- unsigned int anfrac = min(pnfrac, pool_size/2);
38773+ u64 anfrac = min(pnfrac, pool_size/2);
38774 unsigned int add =
38775 ((pool_size - entropy_count)*anfrac*3) >> s;
38776
38777@@ -1166,7 +1177,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38778
38779 extract_buf(r, tmp);
38780 i = min_t(int, nbytes, EXTRACT_SIZE);
38781- if (copy_to_user(buf, tmp, i)) {
38782+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38783 ret = -EFAULT;
38784 break;
38785 }
38786@@ -1555,7 +1566,7 @@ static char sysctl_bootid[16];
38787 static int proc_do_uuid(struct ctl_table *table, int write,
38788 void __user *buffer, size_t *lenp, loff_t *ppos)
38789 {
38790- struct ctl_table fake_table;
38791+ ctl_table_no_const fake_table;
38792 unsigned char buf[64], tmp_uuid[16], *uuid;
38793
38794 uuid = table->data;
38795@@ -1585,7 +1596,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38796 static int proc_do_entropy(ctl_table *table, int write,
38797 void __user *buffer, size_t *lenp, loff_t *ppos)
38798 {
38799- ctl_table fake_table;
38800+ ctl_table_no_const fake_table;
38801 int entropy_count;
38802
38803 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38804diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38805index 7cc1fe22..b602d6b 100644
38806--- a/drivers/char/sonypi.c
38807+++ b/drivers/char/sonypi.c
38808@@ -54,6 +54,7 @@
38809
38810 #include <asm/uaccess.h>
38811 #include <asm/io.h>
38812+#include <asm/local.h>
38813
38814 #include <linux/sonypi.h>
38815
38816@@ -490,7 +491,7 @@ static struct sonypi_device {
38817 spinlock_t fifo_lock;
38818 wait_queue_head_t fifo_proc_list;
38819 struct fasync_struct *fifo_async;
38820- int open_count;
38821+ local_t open_count;
38822 int model;
38823 struct input_dev *input_jog_dev;
38824 struct input_dev *input_key_dev;
38825@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38826 static int sonypi_misc_release(struct inode *inode, struct file *file)
38827 {
38828 mutex_lock(&sonypi_device.lock);
38829- sonypi_device.open_count--;
38830+ local_dec(&sonypi_device.open_count);
38831 mutex_unlock(&sonypi_device.lock);
38832 return 0;
38833 }
38834@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38835 {
38836 mutex_lock(&sonypi_device.lock);
38837 /* Flush input queue on first open */
38838- if (!sonypi_device.open_count)
38839+ if (!local_read(&sonypi_device.open_count))
38840 kfifo_reset(&sonypi_device.fifo);
38841- sonypi_device.open_count++;
38842+ local_inc(&sonypi_device.open_count);
38843 mutex_unlock(&sonypi_device.lock);
38844
38845 return 0;
38846diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38847index b9a57fa..5bb9e38 100644
38848--- a/drivers/char/tpm/tpm_acpi.c
38849+++ b/drivers/char/tpm/tpm_acpi.c
38850@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38851 virt = acpi_os_map_memory(start, len);
38852 if (!virt) {
38853 kfree(log->bios_event_log);
38854+ log->bios_event_log = NULL;
38855 printk("%s: ERROR - Unable to map memory\n", __func__);
38856 return -EIO;
38857 }
38858
38859- memcpy_fromio(log->bios_event_log, virt, len);
38860+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38861
38862 acpi_os_unmap_memory(virt, len);
38863 return 0;
38864diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38865index 59f7cb2..bac8b6d 100644
38866--- a/drivers/char/tpm/tpm_eventlog.c
38867+++ b/drivers/char/tpm/tpm_eventlog.c
38868@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38869 event = addr;
38870
38871 if ((event->event_type == 0 && event->event_size == 0) ||
38872- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38873+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38874 return NULL;
38875
38876 return addr;
38877@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38878 return NULL;
38879
38880 if ((event->event_type == 0 && event->event_size == 0) ||
38881- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38882+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38883 return NULL;
38884
38885 (*pos)++;
38886@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38887 int i;
38888
38889 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38890- seq_putc(m, data[i]);
38891+ if (!seq_putc(m, data[i]))
38892+ return -EFAULT;
38893
38894 return 0;
38895 }
38896diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38897index 60aafb8..10c08e0 100644
38898--- a/drivers/char/virtio_console.c
38899+++ b/drivers/char/virtio_console.c
38900@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38901 if (to_user) {
38902 ssize_t ret;
38903
38904- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38905+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38906 if (ret)
38907 return -EFAULT;
38908 } else {
38909@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38910 if (!port_has_data(port) && !port->host_connected)
38911 return 0;
38912
38913- return fill_readbuf(port, ubuf, count, true);
38914+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38915 }
38916
38917 static int wait_port_writable(struct port *port, bool nonblock)
38918diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38919index 57a078e..c17cde8 100644
38920--- a/drivers/clk/clk-composite.c
38921+++ b/drivers/clk/clk-composite.c
38922@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38923 struct clk *clk;
38924 struct clk_init_data init;
38925 struct clk_composite *composite;
38926- struct clk_ops *clk_composite_ops;
38927+ clk_ops_no_const *clk_composite_ops;
38928
38929 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38930 if (!composite) {
38931diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38932index 501d513..fb0ecf9 100644
38933--- a/drivers/clk/socfpga/clk-gate.c
38934+++ b/drivers/clk/socfpga/clk-gate.c
38935@@ -22,6 +22,7 @@
38936 #include <linux/mfd/syscon.h>
38937 #include <linux/of.h>
38938 #include <linux/regmap.h>
38939+#include <asm/pgtable.h>
38940
38941 #include "clk.h"
38942
38943@@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
38944 return 0;
38945 }
38946
38947-static struct clk_ops gateclk_ops = {
38948+static clk_ops_no_const gateclk_ops __read_only = {
38949 .prepare = socfpga_clk_prepare,
38950 .recalc_rate = socfpga_clk_recalc_rate,
38951 .get_parent = socfpga_clk_get_parent,
38952@@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
38953 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
38954 socfpga_clk->hw.bit_idx = clk_gate[1];
38955
38956- gateclk_ops.enable = clk_gate_ops.enable;
38957- gateclk_ops.disable = clk_gate_ops.disable;
38958+ pax_open_kernel();
38959+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
38960+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
38961+ pax_close_kernel();
38962 }
38963
38964 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
38965diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
38966index de6da95..a2e72c0 100644
38967--- a/drivers/clk/socfpga/clk-pll.c
38968+++ b/drivers/clk/socfpga/clk-pll.c
38969@@ -21,6 +21,7 @@
38970 #include <linux/io.h>
38971 #include <linux/of.h>
38972 #include <linux/of_address.h>
38973+#include <asm/pgtable.h>
38974
38975 #include "clk.h"
38976
38977@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
38978 CLK_MGR_PLL_CLK_SRC_MASK;
38979 }
38980
38981-static struct clk_ops clk_pll_ops = {
38982+static struct clk_ops_no_const clk_pll_ops __read_only = {
38983 .recalc_rate = clk_pll_recalc_rate,
38984 .get_parent = clk_pll_get_parent,
38985 };
38986@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
38987 pll_clk->hw.hw.init = &init;
38988
38989 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38990- clk_pll_ops.enable = clk_gate_ops.enable;
38991- clk_pll_ops.disable = clk_gate_ops.disable;
38992+ pax_open_kernel();
38993+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38994+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38995+ pax_close_kernel();
38996
38997 clk = clk_register(NULL, &pll_clk->hw.hw);
38998 if (WARN_ON(IS_ERR(clk))) {
38999diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39000index 000e4e0..4770351 100644
39001--- a/drivers/cpufreq/acpi-cpufreq.c
39002+++ b/drivers/cpufreq/acpi-cpufreq.c
39003@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39004 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39005 per_cpu(acfreq_data, cpu) = data;
39006
39007- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39008- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39009+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39010+ pax_open_kernel();
39011+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39012+ pax_close_kernel();
39013+ }
39014
39015 result = acpi_processor_register_performance(data->acpi_data, cpu);
39016 if (result)
39017@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39018 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39019 break;
39020 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39021- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39022+ pax_open_kernel();
39023+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39024+ pax_close_kernel();
39025 break;
39026 default:
39027 break;
39028@@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
39029 if (!msrs)
39030 return;
39031
39032- acpi_cpufreq_driver.boost_supported = true;
39033- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39034+ pax_open_kernel();
39035+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39036+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39037+ pax_close_kernel();
39038
39039 cpu_notifier_register_begin();
39040
39041diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39042index abda660..f1d1de0 100644
39043--- a/drivers/cpufreq/cpufreq.c
39044+++ b/drivers/cpufreq/cpufreq.c
39045@@ -2022,7 +2022,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39046 }
39047
39048 mutex_lock(&cpufreq_governor_mutex);
39049- list_del(&governor->governor_list);
39050+ pax_list_del(&governor->governor_list);
39051 mutex_unlock(&cpufreq_governor_mutex);
39052 return;
39053 }
39054@@ -2240,7 +2240,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39055 return NOTIFY_OK;
39056 }
39057
39058-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39059+static struct notifier_block cpufreq_cpu_notifier = {
39060 .notifier_call = cpufreq_cpu_callback,
39061 };
39062
39063@@ -2280,13 +2280,17 @@ int cpufreq_boost_trigger_state(int state)
39064 return 0;
39065
39066 write_lock_irqsave(&cpufreq_driver_lock, flags);
39067- cpufreq_driver->boost_enabled = state;
39068+ pax_open_kernel();
39069+ *(bool *)&cpufreq_driver->boost_enabled = state;
39070+ pax_close_kernel();
39071 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39072
39073 ret = cpufreq_driver->set_boost(state);
39074 if (ret) {
39075 write_lock_irqsave(&cpufreq_driver_lock, flags);
39076- cpufreq_driver->boost_enabled = !state;
39077+ pax_open_kernel();
39078+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39079+ pax_close_kernel();
39080 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39081
39082 pr_err("%s: Cannot %s BOOST\n",
39083@@ -2342,8 +2346,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39084
39085 pr_debug("trying to register driver %s\n", driver_data->name);
39086
39087- if (driver_data->setpolicy)
39088- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39089+ if (driver_data->setpolicy) {
39090+ pax_open_kernel();
39091+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39092+ pax_close_kernel();
39093+ }
39094
39095 write_lock_irqsave(&cpufreq_driver_lock, flags);
39096 if (cpufreq_driver) {
39097@@ -2358,8 +2365,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39098 * Check if driver provides function to enable boost -
39099 * if not, use cpufreq_boost_set_sw as default
39100 */
39101- if (!cpufreq_driver->set_boost)
39102- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39103+ if (!cpufreq_driver->set_boost) {
39104+ pax_open_kernel();
39105+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39106+ pax_close_kernel();
39107+ }
39108
39109 ret = cpufreq_sysfs_create_file(&boost.attr);
39110 if (ret) {
39111diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39112index e1c6433..31203ae 100644
39113--- a/drivers/cpufreq/cpufreq_governor.c
39114+++ b/drivers/cpufreq/cpufreq_governor.c
39115@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39116 struct dbs_data *dbs_data;
39117 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39118 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39119- struct od_ops *od_ops = NULL;
39120+ const struct od_ops *od_ops = NULL;
39121 struct od_dbs_tuners *od_tuners = NULL;
39122 struct cs_dbs_tuners *cs_tuners = NULL;
39123 struct cpu_dbs_common_info *cpu_cdbs;
39124@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39125
39126 if ((cdata->governor == GOV_CONSERVATIVE) &&
39127 (!policy->governor->initialized)) {
39128- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39129+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39130
39131 cpufreq_register_notifier(cs_ops->notifier_block,
39132 CPUFREQ_TRANSITION_NOTIFIER);
39133@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39134
39135 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39136 (policy->governor->initialized == 1)) {
39137- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39138+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39139
39140 cpufreq_unregister_notifier(cs_ops->notifier_block,
39141 CPUFREQ_TRANSITION_NOTIFIER);
39142diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39143index bfb9ae1..e1d3a7e 100644
39144--- a/drivers/cpufreq/cpufreq_governor.h
39145+++ b/drivers/cpufreq/cpufreq_governor.h
39146@@ -205,7 +205,7 @@ struct common_dbs_data {
39147 void (*exit)(struct dbs_data *dbs_data);
39148
39149 /* Governor specific ops, see below */
39150- void *gov_ops;
39151+ const void *gov_ops;
39152 };
39153
39154 /* Governor Per policy data */
39155@@ -225,7 +225,7 @@ struct od_ops {
39156 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39157 unsigned int freq_next, unsigned int relation);
39158 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39159-};
39160+} __no_const;
39161
39162 struct cs_ops {
39163 struct notifier_block *notifier_block;
39164diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39165index 18d4091..434be15 100644
39166--- a/drivers/cpufreq/cpufreq_ondemand.c
39167+++ b/drivers/cpufreq/cpufreq_ondemand.c
39168@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39169
39170 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39171
39172-static struct od_ops od_ops = {
39173+static struct od_ops od_ops __read_only = {
39174 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39175 .powersave_bias_target = generic_powersave_bias_target,
39176 .freq_increase = dbs_freq_increase,
39177@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39178 (struct cpufreq_policy *, unsigned int, unsigned int),
39179 unsigned int powersave_bias)
39180 {
39181- od_ops.powersave_bias_target = f;
39182+ pax_open_kernel();
39183+ *(void **)&od_ops.powersave_bias_target = f;
39184+ pax_close_kernel();
39185 od_set_powersave_bias(powersave_bias);
39186 }
39187 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39188
39189 void od_unregister_powersave_bias_handler(void)
39190 {
39191- od_ops.powersave_bias_target = generic_powersave_bias_target;
39192+ pax_open_kernel();
39193+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39194+ pax_close_kernel();
39195 od_set_powersave_bias(0);
39196 }
39197 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39198diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39199index db2e45b..72c7d37 100644
39200--- a/drivers/cpufreq/intel_pstate.c
39201+++ b/drivers/cpufreq/intel_pstate.c
39202@@ -125,10 +125,10 @@ struct pstate_funcs {
39203 struct cpu_defaults {
39204 struct pstate_adjust_policy pid_policy;
39205 struct pstate_funcs funcs;
39206-};
39207+} __do_const;
39208
39209 static struct pstate_adjust_policy pid_params;
39210-static struct pstate_funcs pstate_funcs;
39211+static struct pstate_funcs *pstate_funcs;
39212
39213 struct perf_limits {
39214 int no_turbo;
39215@@ -529,7 +529,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39216
39217 cpu->pstate.current_pstate = pstate;
39218
39219- pstate_funcs.set(cpu, pstate);
39220+ pstate_funcs->set(cpu, pstate);
39221 }
39222
39223 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39224@@ -551,12 +551,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39225 {
39226 sprintf(cpu->name, "Intel 2nd generation core");
39227
39228- cpu->pstate.min_pstate = pstate_funcs.get_min();
39229- cpu->pstate.max_pstate = pstate_funcs.get_max();
39230- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39231+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39232+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39233+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39234
39235- if (pstate_funcs.get_vid)
39236- pstate_funcs.get_vid(cpu);
39237+ if (pstate_funcs->get_vid)
39238+ pstate_funcs->get_vid(cpu);
39239 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39240 }
39241
39242@@ -841,9 +841,9 @@ static int intel_pstate_msrs_not_valid(void)
39243 rdmsrl(MSR_IA32_APERF, aperf);
39244 rdmsrl(MSR_IA32_MPERF, mperf);
39245
39246- if (!pstate_funcs.get_max() ||
39247- !pstate_funcs.get_min() ||
39248- !pstate_funcs.get_turbo())
39249+ if (!pstate_funcs->get_max() ||
39250+ !pstate_funcs->get_min() ||
39251+ !pstate_funcs->get_turbo())
39252 return -ENODEV;
39253
39254 rdmsrl(MSR_IA32_APERF, tmp);
39255@@ -857,7 +857,7 @@ static int intel_pstate_msrs_not_valid(void)
39256 return 0;
39257 }
39258
39259-static void copy_pid_params(struct pstate_adjust_policy *policy)
39260+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39261 {
39262 pid_params.sample_rate_ms = policy->sample_rate_ms;
39263 pid_params.p_gain_pct = policy->p_gain_pct;
39264@@ -869,11 +869,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39265
39266 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39267 {
39268- pstate_funcs.get_max = funcs->get_max;
39269- pstate_funcs.get_min = funcs->get_min;
39270- pstate_funcs.get_turbo = funcs->get_turbo;
39271- pstate_funcs.set = funcs->set;
39272- pstate_funcs.get_vid = funcs->get_vid;
39273+ pstate_funcs = funcs;
39274 }
39275
39276 #if IS_ENABLED(CONFIG_ACPI)
39277diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39278index 529cfd9..0e28fff 100644
39279--- a/drivers/cpufreq/p4-clockmod.c
39280+++ b/drivers/cpufreq/p4-clockmod.c
39281@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39282 case 0x0F: /* Core Duo */
39283 case 0x16: /* Celeron Core */
39284 case 0x1C: /* Atom */
39285- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39286+ pax_open_kernel();
39287+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39288+ pax_close_kernel();
39289 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39290 case 0x0D: /* Pentium M (Dothan) */
39291- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39292+ pax_open_kernel();
39293+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39294+ pax_close_kernel();
39295 /* fall through */
39296 case 0x09: /* Pentium M (Banias) */
39297 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39298@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39299
39300 /* on P-4s, the TSC runs with constant frequency independent whether
39301 * throttling is active or not. */
39302- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39303+ pax_open_kernel();
39304+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39305+ pax_close_kernel();
39306
39307 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39308 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39309diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39310index 9bb42ba..b01b4a2 100644
39311--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39312+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39313@@ -18,14 +18,12 @@
39314 #include <asm/head.h>
39315 #include <asm/timer.h>
39316
39317-static struct cpufreq_driver *cpufreq_us3_driver;
39318-
39319 struct us3_freq_percpu_info {
39320 struct cpufreq_frequency_table table[4];
39321 };
39322
39323 /* Indexed by cpu number. */
39324-static struct us3_freq_percpu_info *us3_freq_table;
39325+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39326
39327 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39328 * in the Safari config register.
39329@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39330
39331 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39332 {
39333- if (cpufreq_us3_driver)
39334- us3_freq_target(policy, 0);
39335+ us3_freq_target(policy, 0);
39336
39337 return 0;
39338 }
39339
39340+static int __init us3_freq_init(void);
39341+static void __exit us3_freq_exit(void);
39342+
39343+static struct cpufreq_driver cpufreq_us3_driver = {
39344+ .init = us3_freq_cpu_init,
39345+ .verify = cpufreq_generic_frequency_table_verify,
39346+ .target_index = us3_freq_target,
39347+ .get = us3_freq_get,
39348+ .exit = us3_freq_cpu_exit,
39349+ .name = "UltraSPARC-III",
39350+
39351+};
39352+
39353 static int __init us3_freq_init(void)
39354 {
39355 unsigned long manuf, impl, ver;
39356- int ret;
39357
39358 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39359 return -ENODEV;
39360@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39361 (impl == CHEETAH_IMPL ||
39362 impl == CHEETAH_PLUS_IMPL ||
39363 impl == JAGUAR_IMPL ||
39364- impl == PANTHER_IMPL)) {
39365- struct cpufreq_driver *driver;
39366-
39367- ret = -ENOMEM;
39368- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39369- if (!driver)
39370- goto err_out;
39371-
39372- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39373- GFP_KERNEL);
39374- if (!us3_freq_table)
39375- goto err_out;
39376-
39377- driver->init = us3_freq_cpu_init;
39378- driver->verify = cpufreq_generic_frequency_table_verify;
39379- driver->target_index = us3_freq_target;
39380- driver->get = us3_freq_get;
39381- driver->exit = us3_freq_cpu_exit;
39382- strcpy(driver->name, "UltraSPARC-III");
39383-
39384- cpufreq_us3_driver = driver;
39385- ret = cpufreq_register_driver(driver);
39386- if (ret)
39387- goto err_out;
39388-
39389- return 0;
39390-
39391-err_out:
39392- if (driver) {
39393- kfree(driver);
39394- cpufreq_us3_driver = NULL;
39395- }
39396- kfree(us3_freq_table);
39397- us3_freq_table = NULL;
39398- return ret;
39399- }
39400+ impl == PANTHER_IMPL))
39401+ return cpufreq_register_driver(&cpufreq_us3_driver);
39402
39403 return -ENODEV;
39404 }
39405
39406 static void __exit us3_freq_exit(void)
39407 {
39408- if (cpufreq_us3_driver) {
39409- cpufreq_unregister_driver(cpufreq_us3_driver);
39410- kfree(cpufreq_us3_driver);
39411- cpufreq_us3_driver = NULL;
39412- kfree(us3_freq_table);
39413- us3_freq_table = NULL;
39414- }
39415+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39416 }
39417
39418 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39419diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39420index 6723f03..3465190 100644
39421--- a/drivers/cpufreq/speedstep-centrino.c
39422+++ b/drivers/cpufreq/speedstep-centrino.c
39423@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39424 !cpu_has(cpu, X86_FEATURE_EST))
39425 return -ENODEV;
39426
39427- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39428- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39429+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39430+ pax_open_kernel();
39431+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39432+ pax_close_kernel();
39433+ }
39434
39435 if (policy->cpu != 0)
39436 return -ENODEV;
39437diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39438index 136d6a2..06e373d 100644
39439--- a/drivers/cpuidle/driver.c
39440+++ b/drivers/cpuidle/driver.c
39441@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39442
39443 static void poll_idle_init(struct cpuidle_driver *drv)
39444 {
39445- struct cpuidle_state *state = &drv->states[0];
39446+ cpuidle_state_no_const *state = &drv->states[0];
39447
39448 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39449 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39450diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39451index ca89412..a7b9c49 100644
39452--- a/drivers/cpuidle/governor.c
39453+++ b/drivers/cpuidle/governor.c
39454@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39455 mutex_lock(&cpuidle_lock);
39456 if (__cpuidle_find_governor(gov->name) == NULL) {
39457 ret = 0;
39458- list_add_tail(&gov->governor_list, &cpuidle_governors);
39459+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39460 if (!cpuidle_curr_governor ||
39461 cpuidle_curr_governor->rating < gov->rating)
39462 cpuidle_switch_governor(gov);
39463diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39464index efe2f17..b8124f9 100644
39465--- a/drivers/cpuidle/sysfs.c
39466+++ b/drivers/cpuidle/sysfs.c
39467@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39468 NULL
39469 };
39470
39471-static struct attribute_group cpuidle_attr_group = {
39472+static attribute_group_no_const cpuidle_attr_group = {
39473 .attrs = cpuidle_default_attrs,
39474 .name = "cpuidle",
39475 };
39476diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39477index 12fea3e..1e28f47 100644
39478--- a/drivers/crypto/hifn_795x.c
39479+++ b/drivers/crypto/hifn_795x.c
39480@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39481 MODULE_PARM_DESC(hifn_pll_ref,
39482 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39483
39484-static atomic_t hifn_dev_number;
39485+static atomic_unchecked_t hifn_dev_number;
39486
39487 #define ACRYPTO_OP_DECRYPT 0
39488 #define ACRYPTO_OP_ENCRYPT 1
39489@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39490 goto err_out_disable_pci_device;
39491
39492 snprintf(name, sizeof(name), "hifn%d",
39493- atomic_inc_return(&hifn_dev_number)-1);
39494+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39495
39496 err = pci_request_regions(pdev, name);
39497 if (err)
39498diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39499index 2042ec3..a9ce67f 100644
39500--- a/drivers/devfreq/devfreq.c
39501+++ b/drivers/devfreq/devfreq.c
39502@@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39503 goto err_out;
39504 }
39505
39506- list_add(&governor->node, &devfreq_governor_list);
39507+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39508
39509 list_for_each_entry(devfreq, &devfreq_list, node) {
39510 int ret = 0;
39511@@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39512 }
39513 }
39514
39515- list_del(&governor->node);
39516+ pax_list_del((struct list_head *)&governor->node);
39517 err_out:
39518 mutex_unlock(&devfreq_list_lock);
39519
39520diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39521index 5239677..1cb71a8 100644
39522--- a/drivers/dma/sh/shdma-base.c
39523+++ b/drivers/dma/sh/shdma-base.c
39524@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39525 schan->slave_id = -EINVAL;
39526 }
39527
39528- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39529- sdev->desc_size, GFP_KERNEL);
39530+ schan->desc = kcalloc(sdev->desc_size,
39531+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39532 if (!schan->desc) {
39533 ret = -ENOMEM;
39534 goto edescalloc;
39535diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39536index dda7e75..0a4c867 100644
39537--- a/drivers/dma/sh/shdmac.c
39538+++ b/drivers/dma/sh/shdmac.c
39539@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39540 return ret;
39541 }
39542
39543-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39544+static struct notifier_block sh_dmae_nmi_notifier = {
39545 .notifier_call = sh_dmae_nmi_handler,
39546
39547 /* Run before NMI debug handler and KGDB */
39548diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39549index 592af5f..bb1d583 100644
39550--- a/drivers/edac/edac_device.c
39551+++ b/drivers/edac/edac_device.c
39552@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39553 */
39554 int edac_device_alloc_index(void)
39555 {
39556- static atomic_t device_indexes = ATOMIC_INIT(0);
39557+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39558
39559- return atomic_inc_return(&device_indexes) - 1;
39560+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39561 }
39562 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39563
39564diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39565index 01fae82..1dd8289 100644
39566--- a/drivers/edac/edac_mc_sysfs.c
39567+++ b/drivers/edac/edac_mc_sysfs.c
39568@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39569 struct dev_ch_attribute {
39570 struct device_attribute attr;
39571 int channel;
39572-};
39573+} __do_const;
39574
39575 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39576 struct dev_ch_attribute dev_attr_legacy_##_name = \
39577@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39578 }
39579
39580 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39581+ pax_open_kernel();
39582 if (mci->get_sdram_scrub_rate) {
39583- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39584- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39585+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39586+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39587 }
39588 if (mci->set_sdram_scrub_rate) {
39589- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39590- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39591+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39592+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39593 }
39594+ pax_close_kernel();
39595 err = device_create_file(&mci->dev,
39596 &dev_attr_sdram_scrub_rate);
39597 if (err) {
39598diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39599index 2cf44b4d..6dd2dc7 100644
39600--- a/drivers/edac/edac_pci.c
39601+++ b/drivers/edac/edac_pci.c
39602@@ -29,7 +29,7 @@
39603
39604 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39605 static LIST_HEAD(edac_pci_list);
39606-static atomic_t pci_indexes = ATOMIC_INIT(0);
39607+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39608
39609 /*
39610 * edac_pci_alloc_ctl_info
39611@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39612 */
39613 int edac_pci_alloc_index(void)
39614 {
39615- return atomic_inc_return(&pci_indexes) - 1;
39616+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39617 }
39618 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39619
39620diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39621index e8658e4..22746d6 100644
39622--- a/drivers/edac/edac_pci_sysfs.c
39623+++ b/drivers/edac/edac_pci_sysfs.c
39624@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39625 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39626 static int edac_pci_poll_msec = 1000; /* one second workq period */
39627
39628-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39629-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39630+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39631+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39632
39633 static struct kobject *edac_pci_top_main_kobj;
39634 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39635@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39636 void *value;
39637 ssize_t(*show) (void *, char *);
39638 ssize_t(*store) (void *, const char *, size_t);
39639-};
39640+} __do_const;
39641
39642 /* Set of show/store abstract level functions for PCI Parity object */
39643 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39644@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39645 edac_printk(KERN_CRIT, EDAC_PCI,
39646 "Signaled System Error on %s\n",
39647 pci_name(dev));
39648- atomic_inc(&pci_nonparity_count);
39649+ atomic_inc_unchecked(&pci_nonparity_count);
39650 }
39651
39652 if (status & (PCI_STATUS_PARITY)) {
39653@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39654 "Master Data Parity Error on %s\n",
39655 pci_name(dev));
39656
39657- atomic_inc(&pci_parity_count);
39658+ atomic_inc_unchecked(&pci_parity_count);
39659 }
39660
39661 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39662@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39663 "Detected Parity Error on %s\n",
39664 pci_name(dev));
39665
39666- atomic_inc(&pci_parity_count);
39667+ atomic_inc_unchecked(&pci_parity_count);
39668 }
39669 }
39670
39671@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39672 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39673 "Signaled System Error on %s\n",
39674 pci_name(dev));
39675- atomic_inc(&pci_nonparity_count);
39676+ atomic_inc_unchecked(&pci_nonparity_count);
39677 }
39678
39679 if (status & (PCI_STATUS_PARITY)) {
39680@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39681 "Master Data Parity Error on "
39682 "%s\n", pci_name(dev));
39683
39684- atomic_inc(&pci_parity_count);
39685+ atomic_inc_unchecked(&pci_parity_count);
39686 }
39687
39688 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39689@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39690 "Detected Parity Error on %s\n",
39691 pci_name(dev));
39692
39693- atomic_inc(&pci_parity_count);
39694+ atomic_inc_unchecked(&pci_parity_count);
39695 }
39696 }
39697 }
39698@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39699 if (!check_pci_errors)
39700 return;
39701
39702- before_count = atomic_read(&pci_parity_count);
39703+ before_count = atomic_read_unchecked(&pci_parity_count);
39704
39705 /* scan all PCI devices looking for a Parity Error on devices and
39706 * bridges.
39707@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39708 /* Only if operator has selected panic on PCI Error */
39709 if (edac_pci_get_panic_on_pe()) {
39710 /* If the count is different 'after' from 'before' */
39711- if (before_count != atomic_read(&pci_parity_count))
39712+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39713 panic("EDAC: PCI Parity Error");
39714 }
39715 }
39716diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39717index 51b7e3a..aa8a3e8 100644
39718--- a/drivers/edac/mce_amd.h
39719+++ b/drivers/edac/mce_amd.h
39720@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39721 bool (*mc0_mce)(u16, u8);
39722 bool (*mc1_mce)(u16, u8);
39723 bool (*mc2_mce)(u16, u8);
39724-};
39725+} __no_const;
39726
39727 void amd_report_gart_errors(bool);
39728 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39729diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39730index 57ea7f4..af06b76 100644
39731--- a/drivers/firewire/core-card.c
39732+++ b/drivers/firewire/core-card.c
39733@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39734 const struct fw_card_driver *driver,
39735 struct device *device)
39736 {
39737- static atomic_t index = ATOMIC_INIT(-1);
39738+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39739
39740- card->index = atomic_inc_return(&index);
39741+ card->index = atomic_inc_return_unchecked(&index);
39742 card->driver = driver;
39743 card->device = device;
39744 card->current_tlabel = 0;
39745@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39746
39747 void fw_core_remove_card(struct fw_card *card)
39748 {
39749- struct fw_card_driver dummy_driver = dummy_driver_template;
39750+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39751
39752 card->driver->update_phy_reg(card, 4,
39753 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39754diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39755index 2c6d5e1..a2cca6b 100644
39756--- a/drivers/firewire/core-device.c
39757+++ b/drivers/firewire/core-device.c
39758@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39759 struct config_rom_attribute {
39760 struct device_attribute attr;
39761 u32 key;
39762-};
39763+} __do_const;
39764
39765 static ssize_t show_immediate(struct device *dev,
39766 struct device_attribute *dattr, char *buf)
39767diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39768index eb6935c..3cc2bfa 100644
39769--- a/drivers/firewire/core-transaction.c
39770+++ b/drivers/firewire/core-transaction.c
39771@@ -38,6 +38,7 @@
39772 #include <linux/timer.h>
39773 #include <linux/types.h>
39774 #include <linux/workqueue.h>
39775+#include <linux/sched.h>
39776
39777 #include <asm/byteorder.h>
39778
39779diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39780index f477308..2795f24 100644
39781--- a/drivers/firewire/core.h
39782+++ b/drivers/firewire/core.h
39783@@ -111,6 +111,7 @@ struct fw_card_driver {
39784
39785 int (*stop_iso)(struct fw_iso_context *ctx);
39786 };
39787+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39788
39789 void fw_card_initialize(struct fw_card *card,
39790 const struct fw_card_driver *driver, struct device *device);
39791diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39792index 586f2f7..3545ad2 100644
39793--- a/drivers/firewire/ohci.c
39794+++ b/drivers/firewire/ohci.c
39795@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39796 be32_to_cpu(ohci->next_header));
39797 }
39798
39799+#ifndef CONFIG_GRKERNSEC
39800 if (param_remote_dma) {
39801 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39802 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39803 }
39804+#endif
39805
39806 spin_unlock_irq(&ohci->lock);
39807
39808@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39809 unsigned long flags;
39810 int n, ret = 0;
39811
39812+#ifndef CONFIG_GRKERNSEC
39813 if (param_remote_dma)
39814 return 0;
39815+#endif
39816
39817 /*
39818 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39819diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39820index 94a58a0..f5eba42 100644
39821--- a/drivers/firmware/dmi-id.c
39822+++ b/drivers/firmware/dmi-id.c
39823@@ -16,7 +16,7 @@
39824 struct dmi_device_attribute{
39825 struct device_attribute dev_attr;
39826 int field;
39827-};
39828+} __do_const;
39829 #define to_dmi_dev_attr(_dev_attr) \
39830 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39831
39832diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39833index 17afc51..0ef90cd 100644
39834--- a/drivers/firmware/dmi_scan.c
39835+++ b/drivers/firmware/dmi_scan.c
39836@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39837 if (buf == NULL)
39838 return -1;
39839
39840- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39841+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39842
39843 dmi_unmap(buf);
39844 return 0;
39845diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39846index 1491dd4..aa910db 100644
39847--- a/drivers/firmware/efi/cper.c
39848+++ b/drivers/firmware/efi/cper.c
39849@@ -41,12 +41,12 @@
39850 */
39851 u64 cper_next_record_id(void)
39852 {
39853- static atomic64_t seq;
39854+ static atomic64_unchecked_t seq;
39855
39856- if (!atomic64_read(&seq))
39857- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39858+ if (!atomic64_read_unchecked(&seq))
39859+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39860
39861- return atomic64_inc_return(&seq);
39862+ return atomic64_inc_return_unchecked(&seq);
39863 }
39864 EXPORT_SYMBOL_GPL(cper_next_record_id);
39865
39866diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39867index af20f17..4e4e545 100644
39868--- a/drivers/firmware/efi/efi.c
39869+++ b/drivers/firmware/efi/efi.c
39870@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39871 };
39872
39873 static struct efivars generic_efivars;
39874-static struct efivar_operations generic_ops;
39875+static efivar_operations_no_const generic_ops __read_only;
39876
39877 static int generic_ops_register(void)
39878 {
39879- generic_ops.get_variable = efi.get_variable;
39880- generic_ops.set_variable = efi.set_variable;
39881- generic_ops.get_next_variable = efi.get_next_variable;
39882- generic_ops.query_variable_store = efi_query_variable_store;
39883+ pax_open_kernel();
39884+ *(void **)&generic_ops.get_variable = efi.get_variable;
39885+ *(void **)&generic_ops.set_variable = efi.set_variable;
39886+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39887+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39888+ pax_close_kernel();
39889
39890 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39891 }
39892diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39893index 50ea412..caccd6e9 100644
39894--- a/drivers/firmware/efi/efivars.c
39895+++ b/drivers/firmware/efi/efivars.c
39896@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39897 static int
39898 create_efivars_bin_attributes(void)
39899 {
39900- struct bin_attribute *attr;
39901+ bin_attribute_no_const *attr;
39902 int error;
39903
39904 /* new_var */
39905diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39906index 2f569aa..c95f4fb 100644
39907--- a/drivers/firmware/google/memconsole.c
39908+++ b/drivers/firmware/google/memconsole.c
39909@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39910 if (!found_memconsole())
39911 return -ENODEV;
39912
39913- memconsole_bin_attr.size = memconsole_length;
39914+ pax_open_kernel();
39915+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39916+ pax_close_kernel();
39917+
39918 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39919 }
39920
39921diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39922index 8765bd6..2e5b147 100644
39923--- a/drivers/gpio/gpio-em.c
39924+++ b/drivers/gpio/gpio-em.c
39925@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39926 struct em_gio_priv *p;
39927 struct resource *io[2], *irq[2];
39928 struct gpio_chip *gpio_chip;
39929- struct irq_chip *irq_chip;
39930+ irq_chip_no_const *irq_chip;
39931 const char *name = dev_name(&pdev->dev);
39932 int ret;
39933
39934diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39935index 7030422..42a3fe9 100644
39936--- a/drivers/gpio/gpio-ich.c
39937+++ b/drivers/gpio/gpio-ich.c
39938@@ -94,7 +94,7 @@ struct ichx_desc {
39939 * this option allows driver caching written output values
39940 */
39941 bool use_outlvl_cache;
39942-};
39943+} __do_const;
39944
39945 static struct {
39946 spinlock_t lock;
39947diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39948index 03c9148..c66e753 100644
39949--- a/drivers/gpio/gpio-rcar.c
39950+++ b/drivers/gpio/gpio-rcar.c
39951@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39952 struct gpio_rcar_priv *p;
39953 struct resource *io, *irq;
39954 struct gpio_chip *gpio_chip;
39955- struct irq_chip *irq_chip;
39956+ irq_chip_no_const *irq_chip;
39957 struct device *dev = &pdev->dev;
39958 const char *name = dev_name(dev);
39959 int ret;
39960diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39961index 66cbcc1..0c5e622 100644
39962--- a/drivers/gpio/gpio-vr41xx.c
39963+++ b/drivers/gpio/gpio-vr41xx.c
39964@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
39965 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39966 maskl, pendl, maskh, pendh);
39967
39968- atomic_inc(&irq_err_count);
39969+ atomic_inc_unchecked(&irq_err_count);
39970
39971 return -EINVAL;
39972 }
39973diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39974index d8b7099..8a314a5 100644
39975--- a/drivers/gpu/drm/drm_crtc.c
39976+++ b/drivers/gpu/drm/drm_crtc.c
39977@@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39978 goto done;
39979 }
39980
39981- if (copy_to_user(&enum_ptr[copied].name,
39982+ if (copy_to_user(enum_ptr[copied].name,
39983 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39984 ret = -EFAULT;
39985 goto done;
39986diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39987old mode 100644
39988new mode 100755
39989index 03711d0..9960928a
39990--- a/drivers/gpu/drm/drm_drv.c
39991+++ b/drivers/gpu/drm/drm_drv.c
39992@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39993 /**
39994 * Copy and IOCTL return string to user space
39995 */
39996-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39997+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39998 {
39999 int len;
40000
40001@@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
40002 struct drm_file *file_priv = filp->private_data;
40003 struct drm_device *dev;
40004 const struct drm_ioctl_desc *ioctl = NULL;
40005- drm_ioctl_t *func;
40006+ drm_ioctl_no_const_t func;
40007 unsigned int nr = DRM_IOCTL_NR(cmd);
40008 int retcode = -EINVAL;
40009 char stack_kdata[128];
40010@@ -419,8 +419,9 @@ long drm_ioctl(struct file *filp,
40011 retcode = -EFAULT;
40012 goto err_i1;
40013 }
40014- } else
40015+ } else if (cmd & IOC_OUT) {
40016 memset(kdata, 0, usize);
40017+ }
40018
40019 if (ioctl->flags & DRM_UNLOCKED)
40020 retcode = func(dev, kdata, file_priv);
40021diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40022index e1eba0b..98f69f9 100644
40023--- a/drivers/gpu/drm/drm_fops.c
40024+++ b/drivers/gpu/drm/drm_fops.c
40025@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40026 return PTR_ERR(minor);
40027
40028 dev = minor->dev;
40029- if (!dev->open_count++)
40030+ if (local_inc_return(&dev->open_count) == 1)
40031 need_setup = 1;
40032
40033 /* share address_space across all char-devs of a single device */
40034@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40035 return 0;
40036
40037 err_undo:
40038- dev->open_count--;
40039+ local_dec(&dev->open_count);
40040 drm_minor_release(minor);
40041 return retcode;
40042 }
40043@@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
40044
40045 mutex_lock(&drm_global_mutex);
40046
40047- DRM_DEBUG("open_count = %d\n", dev->open_count);
40048+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40049
40050 if (dev->driver->preclose)
40051 dev->driver->preclose(dev, file_priv);
40052@@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
40053 * Begin inline drm_release
40054 */
40055
40056- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40057+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40058 task_pid_nr(current),
40059 (long)old_encode_dev(file_priv->minor->kdev->devt),
40060- dev->open_count);
40061+ local_read(&dev->open_count));
40062
40063 /* Release any auth tokens that might point to this file_priv,
40064 (do that under the drm_global_mutex) */
40065@@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40066 * End inline drm_release
40067 */
40068
40069- if (!--dev->open_count) {
40070+ if (local_dec_and_test(&dev->open_count)) {
40071 retcode = drm_lastclose(dev);
40072 if (drm_device_is_unplugged(dev))
40073 drm_put_dev(dev);
40074diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40075index 3d2e91c..d31c4c9 100644
40076--- a/drivers/gpu/drm/drm_global.c
40077+++ b/drivers/gpu/drm/drm_global.c
40078@@ -36,7 +36,7 @@
40079 struct drm_global_item {
40080 struct mutex mutex;
40081 void *object;
40082- int refcount;
40083+ atomic_t refcount;
40084 };
40085
40086 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40087@@ -49,7 +49,7 @@ void drm_global_init(void)
40088 struct drm_global_item *item = &glob[i];
40089 mutex_init(&item->mutex);
40090 item->object = NULL;
40091- item->refcount = 0;
40092+ atomic_set(&item->refcount, 0);
40093 }
40094 }
40095
40096@@ -59,7 +59,7 @@ void drm_global_release(void)
40097 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40098 struct drm_global_item *item = &glob[i];
40099 BUG_ON(item->object != NULL);
40100- BUG_ON(item->refcount != 0);
40101+ BUG_ON(atomic_read(&item->refcount) != 0);
40102 }
40103 }
40104
40105@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40106 struct drm_global_item *item = &glob[ref->global_type];
40107
40108 mutex_lock(&item->mutex);
40109- if (item->refcount == 0) {
40110+ if (atomic_read(&item->refcount) == 0) {
40111 item->object = kzalloc(ref->size, GFP_KERNEL);
40112 if (unlikely(item->object == NULL)) {
40113 ret = -ENOMEM;
40114@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40115 goto out_err;
40116
40117 }
40118- ++item->refcount;
40119+ atomic_inc(&item->refcount);
40120 ref->object = item->object;
40121 mutex_unlock(&item->mutex);
40122 return 0;
40123@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40124 struct drm_global_item *item = &glob[ref->global_type];
40125
40126 mutex_lock(&item->mutex);
40127- BUG_ON(item->refcount == 0);
40128+ BUG_ON(atomic_read(&item->refcount) == 0);
40129 BUG_ON(ref->object != item->object);
40130- if (--item->refcount == 0) {
40131+ if (atomic_dec_and_test(&item->refcount)) {
40132 ref->release(ref);
40133 item->object = NULL;
40134 }
40135diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40136index 7473035..a48b9c5 100644
40137--- a/drivers/gpu/drm/drm_info.c
40138+++ b/drivers/gpu/drm/drm_info.c
40139@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40140 struct drm_local_map *map;
40141 struct drm_map_list *r_list;
40142
40143- /* Hardcoded from _DRM_FRAME_BUFFER,
40144- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40145- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40146- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40147+ static const char * const types[] = {
40148+ [_DRM_FRAME_BUFFER] = "FB",
40149+ [_DRM_REGISTERS] = "REG",
40150+ [_DRM_SHM] = "SHM",
40151+ [_DRM_AGP] = "AGP",
40152+ [_DRM_SCATTER_GATHER] = "SG",
40153+ [_DRM_CONSISTENT] = "PCI"};
40154 const char *type;
40155 int i;
40156
40157@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40158 map = r_list->map;
40159 if (!map)
40160 continue;
40161- if (map->type < 0 || map->type > 5)
40162+ if (map->type >= ARRAY_SIZE(types))
40163 type = "??";
40164 else
40165 type = types[map->type];
40166@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40167 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40168 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40169 vma->vm_flags & VM_IO ? 'i' : '-',
40170+#ifdef CONFIG_GRKERNSEC_HIDESYM
40171+ 0);
40172+#else
40173 vma->vm_pgoff);
40174+#endif
40175
40176 #if defined(__i386__)
40177 pgprot = pgprot_val(vma->vm_page_prot);
40178diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40179index 2f4c4343..dd12cd2 100644
40180--- a/drivers/gpu/drm/drm_ioc32.c
40181+++ b/drivers/gpu/drm/drm_ioc32.c
40182@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40183 request = compat_alloc_user_space(nbytes);
40184 if (!access_ok(VERIFY_WRITE, request, nbytes))
40185 return -EFAULT;
40186- list = (struct drm_buf_desc *) (request + 1);
40187+ list = (struct drm_buf_desc __user *) (request + 1);
40188
40189 if (__put_user(count, &request->count)
40190 || __put_user(list, &request->list))
40191@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40192 request = compat_alloc_user_space(nbytes);
40193 if (!access_ok(VERIFY_WRITE, request, nbytes))
40194 return -EFAULT;
40195- list = (struct drm_buf_pub *) (request + 1);
40196+ list = (struct drm_buf_pub __user *) (request + 1);
40197
40198 if (__put_user(count, &request->count)
40199 || __put_user(list, &request->list))
40200@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40201 return 0;
40202 }
40203
40204-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40205+drm_ioctl_compat_t drm_compat_ioctls[] = {
40206 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40207 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40208 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40209@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40210 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40211 {
40212 unsigned int nr = DRM_IOCTL_NR(cmd);
40213- drm_ioctl_compat_t *fn;
40214 int ret;
40215
40216 /* Assume that ioctls without an explicit compat routine will just
40217@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40218 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40219 return drm_ioctl(filp, cmd, arg);
40220
40221- fn = drm_compat_ioctls[nr];
40222-
40223- if (fn != NULL)
40224- ret = (*fn) (filp, cmd, arg);
40225+ if (drm_compat_ioctls[nr] != NULL)
40226+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40227 else
40228 ret = drm_ioctl(filp, cmd, arg);
40229
40230diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40231index 4c24c3a..c903cab 100644
40232--- a/drivers/gpu/drm/drm_stub.c
40233+++ b/drivers/gpu/drm/drm_stub.c
40234@@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40235
40236 drm_device_set_unplugged(dev);
40237
40238- if (dev->open_count == 0) {
40239+ if (local_read(&dev->open_count) == 0) {
40240 drm_put_dev(dev);
40241 }
40242 mutex_unlock(&drm_global_mutex);
40243diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40244index c22c309..ae758c3 100644
40245--- a/drivers/gpu/drm/drm_sysfs.c
40246+++ b/drivers/gpu/drm/drm_sysfs.c
40247@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40248 */
40249 int drm_sysfs_device_add(struct drm_minor *minor)
40250 {
40251- char *minor_str;
40252+ const char *minor_str;
40253 int r;
40254
40255 if (minor->type == DRM_MINOR_CONTROL)
40256diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40257index d4d16ed..8fb0b51 100644
40258--- a/drivers/gpu/drm/i810/i810_drv.h
40259+++ b/drivers/gpu/drm/i810/i810_drv.h
40260@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40261 int page_flipping;
40262
40263 wait_queue_head_t irq_queue;
40264- atomic_t irq_received;
40265- atomic_t irq_emitted;
40266+ atomic_unchecked_t irq_received;
40267+ atomic_unchecked_t irq_emitted;
40268
40269 int front_offset;
40270 } drm_i810_private_t;
40271diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40272index eedb023..25076a4 100644
40273--- a/drivers/gpu/drm/i915/i915_dma.c
40274+++ b/drivers/gpu/drm/i915/i915_dma.c
40275@@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40276 bool can_switch;
40277
40278 spin_lock(&dev->count_lock);
40279- can_switch = (dev->open_count == 0);
40280+ can_switch = (local_read(&dev->open_count) == 0);
40281 spin_unlock(&dev->count_lock);
40282 return can_switch;
40283 }
40284diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40285index 20fef6c..76c78fb 100644
40286--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40287+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40288@@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40289
40290 static int
40291 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40292- int count)
40293+ unsigned int count)
40294 {
40295- int i;
40296+ unsigned int i;
40297 unsigned relocs_total = 0;
40298 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40299
40300diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40301index 3c59584..500f2e9 100644
40302--- a/drivers/gpu/drm/i915/i915_ioc32.c
40303+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40304@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40305 (unsigned long)request);
40306 }
40307
40308-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40309+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40310 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40311 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40312 [DRM_I915_GETPARAM] = compat_i915_getparam,
40313@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40314 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40315 {
40316 unsigned int nr = DRM_IOCTL_NR(cmd);
40317- drm_ioctl_compat_t *fn = NULL;
40318 int ret;
40319
40320 if (nr < DRM_COMMAND_BASE)
40321 return drm_compat_ioctl(filp, cmd, arg);
40322
40323- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40324- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40325-
40326- if (fn != NULL)
40327+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40328+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40329 ret = (*fn) (filp, cmd, arg);
40330- else
40331+ } else
40332 ret = drm_ioctl(filp, cmd, arg);
40333
40334 return ret;
40335diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40336index 5b60e25..eac1625 100644
40337--- a/drivers/gpu/drm/i915/intel_display.c
40338+++ b/drivers/gpu/drm/i915/intel_display.c
40339@@ -11171,13 +11171,13 @@ struct intel_quirk {
40340 int subsystem_vendor;
40341 int subsystem_device;
40342 void (*hook)(struct drm_device *dev);
40343-};
40344+} __do_const;
40345
40346 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40347 struct intel_dmi_quirk {
40348 void (*hook)(struct drm_device *dev);
40349 const struct dmi_system_id (*dmi_id_list)[];
40350-};
40351+} __do_const;
40352
40353 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40354 {
40355@@ -11185,18 +11185,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40356 return 1;
40357 }
40358
40359-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40360+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40361 {
40362- .dmi_id_list = &(const struct dmi_system_id[]) {
40363- {
40364- .callback = intel_dmi_reverse_brightness,
40365- .ident = "NCR Corporation",
40366- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40367- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40368- },
40369- },
40370- { } /* terminating entry */
40371+ .callback = intel_dmi_reverse_brightness,
40372+ .ident = "NCR Corporation",
40373+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40374+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40375 },
40376+ },
40377+ { } /* terminating entry */
40378+};
40379+
40380+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40381+ {
40382+ .dmi_id_list = &intel_dmi_quirks_table,
40383 .hook = quirk_invert_brightness,
40384 },
40385 };
40386diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40387index fe45321..836fdca 100644
40388--- a/drivers/gpu/drm/mga/mga_drv.h
40389+++ b/drivers/gpu/drm/mga/mga_drv.h
40390@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40391 u32 clear_cmd;
40392 u32 maccess;
40393
40394- atomic_t vbl_received; /**< Number of vblanks received. */
40395+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40396 wait_queue_head_t fence_queue;
40397- atomic_t last_fence_retired;
40398+ atomic_unchecked_t last_fence_retired;
40399 u32 next_fence_to_post;
40400
40401 unsigned int fb_cpp;
40402diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40403index 86b4bb8..ae237ad 100644
40404--- a/drivers/gpu/drm/mga/mga_ioc32.c
40405+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40406@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40407 return 0;
40408 }
40409
40410-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40411+drm_ioctl_compat_t mga_compat_ioctls[] = {
40412 [DRM_MGA_INIT] = compat_mga_init,
40413 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40414 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40415@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40416 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40417 {
40418 unsigned int nr = DRM_IOCTL_NR(cmd);
40419- drm_ioctl_compat_t *fn = NULL;
40420 int ret;
40421
40422 if (nr < DRM_COMMAND_BASE)
40423 return drm_compat_ioctl(filp, cmd, arg);
40424
40425- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40426- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40427-
40428- if (fn != NULL)
40429+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40430+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40431 ret = (*fn) (filp, cmd, arg);
40432- else
40433+ } else
40434 ret = drm_ioctl(filp, cmd, arg);
40435
40436 return ret;
40437diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40438index 1b071b8..de8601a 100644
40439--- a/drivers/gpu/drm/mga/mga_irq.c
40440+++ b/drivers/gpu/drm/mga/mga_irq.c
40441@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40442 if (crtc != 0)
40443 return 0;
40444
40445- return atomic_read(&dev_priv->vbl_received);
40446+ return atomic_read_unchecked(&dev_priv->vbl_received);
40447 }
40448
40449
40450@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40451 /* VBLANK interrupt */
40452 if (status & MGA_VLINEPEN) {
40453 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40454- atomic_inc(&dev_priv->vbl_received);
40455+ atomic_inc_unchecked(&dev_priv->vbl_received);
40456 drm_handle_vblank(dev, 0);
40457 handled = 1;
40458 }
40459@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40460 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40461 MGA_WRITE(MGA_PRIMEND, prim_end);
40462
40463- atomic_inc(&dev_priv->last_fence_retired);
40464+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40465 wake_up(&dev_priv->fence_queue);
40466 handled = 1;
40467 }
40468@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40469 * using fences.
40470 */
40471 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40472- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40473+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40474 - *sequence) <= (1 << 23)));
40475
40476 *sequence = cur_fence;
40477diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40478index 8268a4c..5105708 100644
40479--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40480+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40481@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40482 struct bit_table {
40483 const char id;
40484 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40485-};
40486+} __no_const;
40487
40488 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40489
40490diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40491index 7efbafa..19f8087 100644
40492--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40493+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40494@@ -97,7 +97,6 @@ struct nouveau_drm {
40495 struct drm_global_reference mem_global_ref;
40496 struct ttm_bo_global_ref bo_global_ref;
40497 struct ttm_bo_device bdev;
40498- atomic_t validate_sequence;
40499 int (*move)(struct nouveau_channel *,
40500 struct ttm_buffer_object *,
40501 struct ttm_mem_reg *, struct ttm_mem_reg *);
40502diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40503index c1a7e5a..38b8539 100644
40504--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40505+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40506@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40507 unsigned long arg)
40508 {
40509 unsigned int nr = DRM_IOCTL_NR(cmd);
40510- drm_ioctl_compat_t *fn = NULL;
40511+ drm_ioctl_compat_t fn = NULL;
40512 int ret;
40513
40514 if (nr < DRM_COMMAND_BASE)
40515diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40516index ab0228f..20b756b 100644
40517--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40518+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40519@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40520 }
40521
40522 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40523- nouveau_vram_manager_init,
40524- nouveau_vram_manager_fini,
40525- nouveau_vram_manager_new,
40526- nouveau_vram_manager_del,
40527- nouveau_vram_manager_debug
40528+ .init = nouveau_vram_manager_init,
40529+ .takedown = nouveau_vram_manager_fini,
40530+ .get_node = nouveau_vram_manager_new,
40531+ .put_node = nouveau_vram_manager_del,
40532+ .debug = nouveau_vram_manager_debug
40533 };
40534
40535 static int
40536@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40537 }
40538
40539 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40540- nouveau_gart_manager_init,
40541- nouveau_gart_manager_fini,
40542- nouveau_gart_manager_new,
40543- nouveau_gart_manager_del,
40544- nouveau_gart_manager_debug
40545+ .init = nouveau_gart_manager_init,
40546+ .takedown = nouveau_gart_manager_fini,
40547+ .get_node = nouveau_gart_manager_new,
40548+ .put_node = nouveau_gart_manager_del,
40549+ .debug = nouveau_gart_manager_debug
40550 };
40551
40552 #include <core/subdev/vm/nv04.h>
40553@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40554 }
40555
40556 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40557- nv04_gart_manager_init,
40558- nv04_gart_manager_fini,
40559- nv04_gart_manager_new,
40560- nv04_gart_manager_del,
40561- nv04_gart_manager_debug
40562+ .init = nv04_gart_manager_init,
40563+ .takedown = nv04_gart_manager_fini,
40564+ .get_node = nv04_gart_manager_new,
40565+ .put_node = nv04_gart_manager_del,
40566+ .debug = nv04_gart_manager_debug
40567 };
40568
40569 int
40570diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40571index fb84da3..d7ee463 100644
40572--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40573+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40574@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40575 bool can_switch;
40576
40577 spin_lock(&dev->count_lock);
40578- can_switch = (dev->open_count == 0);
40579+ can_switch = (local_read(&dev->open_count) == 0);
40580 spin_unlock(&dev->count_lock);
40581 return can_switch;
40582 }
40583diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40584index eb89653..613cf71 100644
40585--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40586+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40587@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40588 int ret;
40589
40590 mutex_lock(&qdev->async_io_mutex);
40591- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40592+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40593 if (qdev->last_sent_io_cmd > irq_num) {
40594 if (intr)
40595 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40596- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40597+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40598 else
40599 ret = wait_event_timeout(qdev->io_cmd_event,
40600- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40601+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40602 /* 0 is timeout, just bail the "hw" has gone away */
40603 if (ret <= 0)
40604 goto out;
40605- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40606+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40607 }
40608 outb(val, addr);
40609 qdev->last_sent_io_cmd = irq_num + 1;
40610 if (intr)
40611 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40612- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40613+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40614 else
40615 ret = wait_event_timeout(qdev->io_cmd_event,
40616- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40617+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40618 out:
40619 if (ret > 0)
40620 ret = 0;
40621diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40622index c3c2bbd..bc3c0fb 100644
40623--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40624+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40625@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40626 struct drm_info_node *node = (struct drm_info_node *) m->private;
40627 struct qxl_device *qdev = node->minor->dev->dev_private;
40628
40629- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40630- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40631- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40632- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40633+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40634+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40635+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40636+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40637 seq_printf(m, "%d\n", qdev->irq_received_error);
40638 return 0;
40639 }
40640diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40641index 36ed40b..0397633 100644
40642--- a/drivers/gpu/drm/qxl/qxl_drv.h
40643+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40644@@ -290,10 +290,10 @@ struct qxl_device {
40645 unsigned int last_sent_io_cmd;
40646
40647 /* interrupt handling */
40648- atomic_t irq_received;
40649- atomic_t irq_received_display;
40650- atomic_t irq_received_cursor;
40651- atomic_t irq_received_io_cmd;
40652+ atomic_unchecked_t irq_received;
40653+ atomic_unchecked_t irq_received_display;
40654+ atomic_unchecked_t irq_received_cursor;
40655+ atomic_unchecked_t irq_received_io_cmd;
40656 unsigned irq_received_error;
40657 wait_queue_head_t display_event;
40658 wait_queue_head_t cursor_event;
40659diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40660index 0bb86e6..d41416d 100644
40661--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40662+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40663@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40664
40665 /* TODO copy slow path code from i915 */
40666 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40667- 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);
40668+ 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);
40669
40670 {
40671 struct qxl_drawable *draw = fb_cmd;
40672@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40673 struct drm_qxl_reloc reloc;
40674
40675 if (copy_from_user(&reloc,
40676- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40677+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40678 sizeof(reloc))) {
40679 ret = -EFAULT;
40680 goto out_free_bos;
40681@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40682
40683 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40684
40685- struct drm_qxl_command *commands =
40686- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40687+ struct drm_qxl_command __user *commands =
40688+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40689
40690- if (copy_from_user(&user_cmd, &commands[cmd_num],
40691+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40692 sizeof(user_cmd)))
40693 return -EFAULT;
40694
40695diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40696index 28f84b4..fb3e224 100644
40697--- a/drivers/gpu/drm/qxl/qxl_irq.c
40698+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40699@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40700
40701 pending = xchg(&qdev->ram_header->int_pending, 0);
40702
40703- atomic_inc(&qdev->irq_received);
40704+ atomic_inc_unchecked(&qdev->irq_received);
40705
40706 if (pending & QXL_INTERRUPT_DISPLAY) {
40707- atomic_inc(&qdev->irq_received_display);
40708+ atomic_inc_unchecked(&qdev->irq_received_display);
40709 wake_up_all(&qdev->display_event);
40710 qxl_queue_garbage_collect(qdev, false);
40711 }
40712 if (pending & QXL_INTERRUPT_CURSOR) {
40713- atomic_inc(&qdev->irq_received_cursor);
40714+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40715 wake_up_all(&qdev->cursor_event);
40716 }
40717 if (pending & QXL_INTERRUPT_IO_CMD) {
40718- atomic_inc(&qdev->irq_received_io_cmd);
40719+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40720 wake_up_all(&qdev->io_cmd_event);
40721 }
40722 if (pending & QXL_INTERRUPT_ERROR) {
40723@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40724 init_waitqueue_head(&qdev->io_cmd_event);
40725 INIT_WORK(&qdev->client_monitors_config_work,
40726 qxl_client_monitors_config_work_func);
40727- atomic_set(&qdev->irq_received, 0);
40728- atomic_set(&qdev->irq_received_display, 0);
40729- atomic_set(&qdev->irq_received_cursor, 0);
40730- atomic_set(&qdev->irq_received_io_cmd, 0);
40731+ atomic_set_unchecked(&qdev->irq_received, 0);
40732+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40733+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40734+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40735 qdev->irq_received_error = 0;
40736 ret = drm_irq_install(qdev->ddev);
40737 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40738diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40739index d52c275..4e6b43d 100644
40740--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40741+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40742@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40743 }
40744 }
40745
40746-static struct vm_operations_struct qxl_ttm_vm_ops;
40747+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40748 static const struct vm_operations_struct *ttm_vm_ops;
40749
40750 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40751@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40752 return r;
40753 if (unlikely(ttm_vm_ops == NULL)) {
40754 ttm_vm_ops = vma->vm_ops;
40755+ pax_open_kernel();
40756 qxl_ttm_vm_ops = *ttm_vm_ops;
40757 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40758+ pax_close_kernel();
40759 }
40760 vma->vm_ops = &qxl_ttm_vm_ops;
40761 return 0;
40762@@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40763 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40764 {
40765 #if defined(CONFIG_DEBUG_FS)
40766- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40767- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40768- unsigned i;
40769+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40770+ {
40771+ .name = "qxl_mem_mm",
40772+ .show = &qxl_mm_dump_table,
40773+ },
40774+ {
40775+ .name = "qxl_surf_mm",
40776+ .show = &qxl_mm_dump_table,
40777+ }
40778+ };
40779
40780- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40781- if (i == 0)
40782- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40783- else
40784- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40785- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40786- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40787- qxl_mem_types_list[i].driver_features = 0;
40788- if (i == 0)
40789- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40790- else
40791- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40792+ pax_open_kernel();
40793+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40794+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40795+ pax_close_kernel();
40796
40797- }
40798- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40799+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40800 #else
40801 return 0;
40802 #endif
40803diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40804index 59459fe..be26b31 100644
40805--- a/drivers/gpu/drm/r128/r128_cce.c
40806+++ b/drivers/gpu/drm/r128/r128_cce.c
40807@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40808
40809 /* GH: Simple idle check.
40810 */
40811- atomic_set(&dev_priv->idle_count, 0);
40812+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40813
40814 /* We don't support anything other than bus-mastering ring mode,
40815 * but the ring can be in either AGP or PCI space for the ring
40816diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40817index 5bf3f5f..7000661 100644
40818--- a/drivers/gpu/drm/r128/r128_drv.h
40819+++ b/drivers/gpu/drm/r128/r128_drv.h
40820@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40821 int is_pci;
40822 unsigned long cce_buffers_offset;
40823
40824- atomic_t idle_count;
40825+ atomic_unchecked_t idle_count;
40826
40827 int page_flipping;
40828 int current_page;
40829 u32 crtc_offset;
40830 u32 crtc_offset_cntl;
40831
40832- atomic_t vbl_received;
40833+ atomic_unchecked_t vbl_received;
40834
40835 u32 color_fmt;
40836 unsigned int front_offset;
40837diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40838index b0d0fd3..a6fbbe4 100644
40839--- a/drivers/gpu/drm/r128/r128_ioc32.c
40840+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40841@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40842 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40843 }
40844
40845-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40846+drm_ioctl_compat_t r128_compat_ioctls[] = {
40847 [DRM_R128_INIT] = compat_r128_init,
40848 [DRM_R128_DEPTH] = compat_r128_depth,
40849 [DRM_R128_STIPPLE] = compat_r128_stipple,
40850@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40851 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40852 {
40853 unsigned int nr = DRM_IOCTL_NR(cmd);
40854- drm_ioctl_compat_t *fn = NULL;
40855 int ret;
40856
40857 if (nr < DRM_COMMAND_BASE)
40858 return drm_compat_ioctl(filp, cmd, arg);
40859
40860- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40861- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40862-
40863- if (fn != NULL)
40864+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40865+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40866 ret = (*fn) (filp, cmd, arg);
40867- else
40868+ } else
40869 ret = drm_ioctl(filp, cmd, arg);
40870
40871 return ret;
40872diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40873index c2ae496..30b5993 100644
40874--- a/drivers/gpu/drm/r128/r128_irq.c
40875+++ b/drivers/gpu/drm/r128/r128_irq.c
40876@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40877 if (crtc != 0)
40878 return 0;
40879
40880- return atomic_read(&dev_priv->vbl_received);
40881+ return atomic_read_unchecked(&dev_priv->vbl_received);
40882 }
40883
40884 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40885@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40886 /* VBLANK interrupt */
40887 if (status & R128_CRTC_VBLANK_INT) {
40888 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40889- atomic_inc(&dev_priv->vbl_received);
40890+ atomic_inc_unchecked(&dev_priv->vbl_received);
40891 drm_handle_vblank(dev, 0);
40892 return IRQ_HANDLED;
40893 }
40894diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40895index e806dac..f81d32f 100644
40896--- a/drivers/gpu/drm/r128/r128_state.c
40897+++ b/drivers/gpu/drm/r128/r128_state.c
40898@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40899
40900 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40901 {
40902- if (atomic_read(&dev_priv->idle_count) == 0)
40903+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40904 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40905 else
40906- atomic_set(&dev_priv->idle_count, 0);
40907+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40908 }
40909
40910 #endif
40911diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40912index 4a85bb6..aaea819 100644
40913--- a/drivers/gpu/drm/radeon/mkregtable.c
40914+++ b/drivers/gpu/drm/radeon/mkregtable.c
40915@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40916 regex_t mask_rex;
40917 regmatch_t match[4];
40918 char buf[1024];
40919- size_t end;
40920+ long end;
40921 int len;
40922 int done = 0;
40923 int r;
40924 unsigned o;
40925 struct offset *offset;
40926 char last_reg_s[10];
40927- int last_reg;
40928+ unsigned long last_reg;
40929
40930 if (regcomp
40931 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40932diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40933index 2cd144c..a01c95a 100644
40934--- a/drivers/gpu/drm/radeon/radeon_device.c
40935+++ b/drivers/gpu/drm/radeon/radeon_device.c
40936@@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40937 bool can_switch;
40938
40939 spin_lock(&dev->count_lock);
40940- can_switch = (dev->open_count == 0);
40941+ can_switch = (local_read(&dev->open_count) == 0);
40942 spin_unlock(&dev->count_lock);
40943 return can_switch;
40944 }
40945diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40946index dafd812..1bf20c7 100644
40947--- a/drivers/gpu/drm/radeon/radeon_drv.h
40948+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40949@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40950
40951 /* SW interrupt */
40952 wait_queue_head_t swi_queue;
40953- atomic_t swi_emitted;
40954+ atomic_unchecked_t swi_emitted;
40955 int vblank_crtc;
40956 uint32_t irq_enable_reg;
40957 uint32_t r500_disp_irq_reg;
40958diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40959index bdb0f93..5ff558f 100644
40960--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40961+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40962@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40963 request = compat_alloc_user_space(sizeof(*request));
40964 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40965 || __put_user(req32.param, &request->param)
40966- || __put_user((void __user *)(unsigned long)req32.value,
40967+ || __put_user((unsigned long)req32.value,
40968 &request->value))
40969 return -EFAULT;
40970
40971@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40972 #define compat_radeon_cp_setparam NULL
40973 #endif /* X86_64 || IA64 */
40974
40975-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40976+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40977 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40978 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40979 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40980@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40981 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40982 {
40983 unsigned int nr = DRM_IOCTL_NR(cmd);
40984- drm_ioctl_compat_t *fn = NULL;
40985 int ret;
40986
40987 if (nr < DRM_COMMAND_BASE)
40988 return drm_compat_ioctl(filp, cmd, arg);
40989
40990- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40991- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40992-
40993- if (fn != NULL)
40994+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40995+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40996 ret = (*fn) (filp, cmd, arg);
40997- else
40998+ } else
40999 ret = drm_ioctl(filp, cmd, arg);
41000
41001 return ret;
41002diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41003index 244b19b..c19226d 100644
41004--- a/drivers/gpu/drm/radeon/radeon_irq.c
41005+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41006@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41007 unsigned int ret;
41008 RING_LOCALS;
41009
41010- atomic_inc(&dev_priv->swi_emitted);
41011- ret = atomic_read(&dev_priv->swi_emitted);
41012+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41013+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41014
41015 BEGIN_RING(4);
41016 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41017@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41018 drm_radeon_private_t *dev_priv =
41019 (drm_radeon_private_t *) dev->dev_private;
41020
41021- atomic_set(&dev_priv->swi_emitted, 0);
41022+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41023 init_waitqueue_head(&dev_priv->swi_queue);
41024
41025 dev->max_vblank_count = 0x001fffff;
41026diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41027index 956ab7f..fbd36d8 100644
41028--- a/drivers/gpu/drm/radeon/radeon_state.c
41029+++ b/drivers/gpu/drm/radeon/radeon_state.c
41030@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41031 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41032 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41033
41034- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41035+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41036 sarea_priv->nbox * sizeof(depth_boxes[0])))
41037 return -EFAULT;
41038
41039@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41040 {
41041 drm_radeon_private_t *dev_priv = dev->dev_private;
41042 drm_radeon_getparam_t *param = data;
41043- int value;
41044+ int value = 0;
41045
41046 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41047
41048diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41049index c8a8a51..219dacc 100644
41050--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41051+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41052@@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41053 man->size = size >> PAGE_SHIFT;
41054 }
41055
41056-static struct vm_operations_struct radeon_ttm_vm_ops;
41057+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41058 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41059
41060 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41061@@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41062 }
41063 if (unlikely(ttm_vm_ops == NULL)) {
41064 ttm_vm_ops = vma->vm_ops;
41065+ pax_open_kernel();
41066 radeon_ttm_vm_ops = *ttm_vm_ops;
41067 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41068+ pax_close_kernel();
41069 }
41070 vma->vm_ops = &radeon_ttm_vm_ops;
41071 return 0;
41072diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
41073index c11b71d..c8c48aa 100644
41074--- a/drivers/gpu/drm/radeon/radeon_vm.c
41075+++ b/drivers/gpu/drm/radeon/radeon_vm.c
41076@@ -493,7 +493,7 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
41077 mutex_unlock(&vm->mutex);
41078
41079 r = radeon_bo_create(rdev, RADEON_VM_PTE_COUNT * 8,
41080- RADEON_GPU_PAGE_SIZE, false,
41081+ RADEON_GPU_PAGE_SIZE, true,
41082 RADEON_GEM_DOMAIN_VRAM, NULL, &pt);
41083 if (r)
41084 return r;
41085@@ -913,7 +913,7 @@ int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm)
41086 return -ENOMEM;
41087 }
41088
41089- r = radeon_bo_create(rdev, pd_size, RADEON_VM_PTB_ALIGN_SIZE, false,
41090+ r = radeon_bo_create(rdev, pd_size, RADEON_VM_PTB_ALIGN_SIZE, true,
41091 RADEON_GEM_DOMAIN_VRAM, NULL,
41092 &vm->page_directory);
41093 if (r)
41094diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41095index edb871d..a275c6ed 100644
41096--- a/drivers/gpu/drm/tegra/dc.c
41097+++ b/drivers/gpu/drm/tegra/dc.c
41098@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41099 }
41100
41101 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41102- dc->debugfs_files[i].data = dc;
41103+ *(void **)&dc->debugfs_files[i].data = dc;
41104
41105 err = drm_debugfs_create_files(dc->debugfs_files,
41106 ARRAY_SIZE(debugfs_files),
41107diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41108index 0e599f0..c9ea7c7 100644
41109--- a/drivers/gpu/drm/tegra/dsi.c
41110+++ b/drivers/gpu/drm/tegra/dsi.c
41111@@ -39,7 +39,7 @@ struct tegra_dsi {
41112 struct clk *clk_lp;
41113 struct clk *clk;
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/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41121index 6928015..c9853e7 100644
41122--- a/drivers/gpu/drm/tegra/hdmi.c
41123+++ b/drivers/gpu/drm/tegra/hdmi.c
41124@@ -59,7 +59,7 @@ struct tegra_hdmi {
41125 bool stereo;
41126 bool dvi;
41127
41128- struct drm_info_list *debugfs_files;
41129+ drm_info_list_no_const *debugfs_files;
41130 struct drm_minor *minor;
41131 struct dentry *debugfs;
41132 };
41133diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41134index bd850c9..d9f3573 100644
41135--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41136+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41137@@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41138 }
41139
41140 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41141- ttm_bo_man_init,
41142- ttm_bo_man_takedown,
41143- ttm_bo_man_get_node,
41144- ttm_bo_man_put_node,
41145- ttm_bo_man_debug
41146+ .init = ttm_bo_man_init,
41147+ .takedown = ttm_bo_man_takedown,
41148+ .get_node = ttm_bo_man_get_node,
41149+ .put_node = ttm_bo_man_put_node,
41150+ .debug = ttm_bo_man_debug
41151 };
41152 EXPORT_SYMBOL(ttm_bo_manager_func);
41153diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41154index dbc2def..0a9f710 100644
41155--- a/drivers/gpu/drm/ttm/ttm_memory.c
41156+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41157@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41158 zone->glob = glob;
41159 glob->zone_kernel = zone;
41160 ret = kobject_init_and_add(
41161- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41162+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41163 if (unlikely(ret != 0)) {
41164 kobject_put(&zone->kobj);
41165 return ret;
41166@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41167 zone->glob = glob;
41168 glob->zone_dma32 = zone;
41169 ret = kobject_init_and_add(
41170- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41171+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41172 if (unlikely(ret != 0)) {
41173 kobject_put(&zone->kobj);
41174 return ret;
41175diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41176index 863bef9..cba15cf 100644
41177--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41178+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41179@@ -391,9 +391,9 @@ out:
41180 static unsigned long
41181 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41182 {
41183- static atomic_t start_pool = ATOMIC_INIT(0);
41184+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41185 unsigned i;
41186- unsigned pool_offset = atomic_add_return(1, &start_pool);
41187+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41188 struct ttm_page_pool *pool;
41189 int shrink_pages = sc->nr_to_scan;
41190 unsigned long freed = 0;
41191diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41192index 3771763..883f206 100644
41193--- a/drivers/gpu/drm/udl/udl_fb.c
41194+++ b/drivers/gpu/drm/udl/udl_fb.c
41195@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41196 fb_deferred_io_cleanup(info);
41197 kfree(info->fbdefio);
41198 info->fbdefio = NULL;
41199- info->fbops->fb_mmap = udl_fb_mmap;
41200 }
41201
41202 pr_warn("released /dev/fb%d user=%d count=%d\n",
41203diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41204index ad02732..144f5ed 100644
41205--- a/drivers/gpu/drm/via/via_drv.h
41206+++ b/drivers/gpu/drm/via/via_drv.h
41207@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41208 typedef uint32_t maskarray_t[5];
41209
41210 typedef struct drm_via_irq {
41211- atomic_t irq_received;
41212+ atomic_unchecked_t irq_received;
41213 uint32_t pending_mask;
41214 uint32_t enable_mask;
41215 wait_queue_head_t irq_queue;
41216@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41217 struct timeval last_vblank;
41218 int last_vblank_valid;
41219 unsigned usec_per_vblank;
41220- atomic_t vbl_received;
41221+ atomic_unchecked_t vbl_received;
41222 drm_via_state_t hc_state;
41223 char pci_buf[VIA_PCI_BUF_SIZE];
41224 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41225diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41226index 1319433..a993b0c 100644
41227--- a/drivers/gpu/drm/via/via_irq.c
41228+++ b/drivers/gpu/drm/via/via_irq.c
41229@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41230 if (crtc != 0)
41231 return 0;
41232
41233- return atomic_read(&dev_priv->vbl_received);
41234+ return atomic_read_unchecked(&dev_priv->vbl_received);
41235 }
41236
41237 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41238@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41239
41240 status = VIA_READ(VIA_REG_INTERRUPT);
41241 if (status & VIA_IRQ_VBLANK_PENDING) {
41242- atomic_inc(&dev_priv->vbl_received);
41243- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41244+ atomic_inc_unchecked(&dev_priv->vbl_received);
41245+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41246 do_gettimeofday(&cur_vblank);
41247 if (dev_priv->last_vblank_valid) {
41248 dev_priv->usec_per_vblank =
41249@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41250 dev_priv->last_vblank = cur_vblank;
41251 dev_priv->last_vblank_valid = 1;
41252 }
41253- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41254+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41255 DRM_DEBUG("US per vblank is: %u\n",
41256 dev_priv->usec_per_vblank);
41257 }
41258@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41259
41260 for (i = 0; i < dev_priv->num_irqs; ++i) {
41261 if (status & cur_irq->pending_mask) {
41262- atomic_inc(&cur_irq->irq_received);
41263+ atomic_inc_unchecked(&cur_irq->irq_received);
41264 wake_up(&cur_irq->irq_queue);
41265 handled = 1;
41266 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41267@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41268 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41269 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41270 masks[irq][4]));
41271- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41272+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41273 } else {
41274 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41275 (((cur_irq_sequence =
41276- atomic_read(&cur_irq->irq_received)) -
41277+ atomic_read_unchecked(&cur_irq->irq_received)) -
41278 *sequence) <= (1 << 23)));
41279 }
41280 *sequence = cur_irq_sequence;
41281@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41282 }
41283
41284 for (i = 0; i < dev_priv->num_irqs; ++i) {
41285- atomic_set(&cur_irq->irq_received, 0);
41286+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41287 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41288 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41289 init_waitqueue_head(&cur_irq->irq_queue);
41290@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41291 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41292 case VIA_IRQ_RELATIVE:
41293 irqwait->request.sequence +=
41294- atomic_read(&cur_irq->irq_received);
41295+ atomic_read_unchecked(&cur_irq->irq_received);
41296 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41297 case VIA_IRQ_ABSOLUTE:
41298 break;
41299diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41300index 6b252a8..5975dfe 100644
41301--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41302+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41303@@ -437,7 +437,7 @@ struct vmw_private {
41304 * Fencing and IRQs.
41305 */
41306
41307- atomic_t marker_seq;
41308+ atomic_unchecked_t marker_seq;
41309 wait_queue_head_t fence_queue;
41310 wait_queue_head_t fifo_queue;
41311 int fence_queue_waiters; /* Protected by hw_mutex */
41312diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41313index 6ccd993..618d592 100644
41314--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41315+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41316@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41317 (unsigned int) min,
41318 (unsigned int) fifo->capabilities);
41319
41320- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41321+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41322 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41323 vmw_marker_queue_init(&fifo->marker_queue);
41324 return vmw_fifo_send_fence(dev_priv, &dummy);
41325@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41326 if (reserveable)
41327 iowrite32(bytes, fifo_mem +
41328 SVGA_FIFO_RESERVED);
41329- return fifo_mem + (next_cmd >> 2);
41330+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41331 } else {
41332 need_bounce = true;
41333 }
41334@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41335
41336 fm = vmw_fifo_reserve(dev_priv, bytes);
41337 if (unlikely(fm == NULL)) {
41338- *seqno = atomic_read(&dev_priv->marker_seq);
41339+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41340 ret = -ENOMEM;
41341 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41342 false, 3*HZ);
41343@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41344 }
41345
41346 do {
41347- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41348+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41349 } while (*seqno == 0);
41350
41351 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41352diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41353index b1273e8..9c274fd 100644
41354--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41355+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41356@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41357 }
41358
41359 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41360- vmw_gmrid_man_init,
41361- vmw_gmrid_man_takedown,
41362- vmw_gmrid_man_get_node,
41363- vmw_gmrid_man_put_node,
41364- vmw_gmrid_man_debug
41365+ .init = vmw_gmrid_man_init,
41366+ .takedown = vmw_gmrid_man_takedown,
41367+ .get_node = vmw_gmrid_man_get_node,
41368+ .put_node = vmw_gmrid_man_put_node,
41369+ .debug = vmw_gmrid_man_debug
41370 };
41371diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41372index 37881ec..319065d 100644
41373--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41374+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41375@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41376 int ret;
41377
41378 num_clips = arg->num_clips;
41379- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41380+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41381
41382 if (unlikely(num_clips == 0))
41383 return 0;
41384@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41385 int ret;
41386
41387 num_clips = arg->num_clips;
41388- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41389+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41390
41391 if (unlikely(num_clips == 0))
41392 return 0;
41393diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41394index 0c42376..6febe77 100644
41395--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41396+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41397@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41398 * emitted. Then the fence is stale and signaled.
41399 */
41400
41401- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41402+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41403 > VMW_FENCE_WRAP);
41404
41405 return ret;
41406@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41407
41408 if (fifo_idle)
41409 down_read(&fifo_state->rwsem);
41410- signal_seq = atomic_read(&dev_priv->marker_seq);
41411+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41412 ret = 0;
41413
41414 for (;;) {
41415diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41416index 8a8725c2..afed796 100644
41417--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41418+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41419@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41420 while (!vmw_lag_lt(queue, us)) {
41421 spin_lock(&queue->lock);
41422 if (list_empty(&queue->head))
41423- seqno = atomic_read(&dev_priv->marker_seq);
41424+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41425 else {
41426 marker = list_first_entry(&queue->head,
41427 struct vmw_marker, head);
41428diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41429index ec0ae2d..dc0780b 100644
41430--- a/drivers/gpu/vga/vga_switcheroo.c
41431+++ b/drivers/gpu/vga/vga_switcheroo.c
41432@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41433
41434 /* this version is for the case where the power switch is separate
41435 to the device being powered down. */
41436-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41437+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41438 {
41439 /* copy over all the bus versions */
41440 if (dev->bus && dev->bus->pm) {
41441@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41442 return ret;
41443 }
41444
41445-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41446+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41447 {
41448 /* copy over all the bus versions */
41449 if (dev->bus && dev->bus->pm) {
41450diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41451index a5c7927..025a2b4 100644
41452--- a/drivers/hid/hid-core.c
41453+++ b/drivers/hid/hid-core.c
41454@@ -2476,7 +2476,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41455
41456 int hid_add_device(struct hid_device *hdev)
41457 {
41458- static atomic_t id = ATOMIC_INIT(0);
41459+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41460 int ret;
41461
41462 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41463@@ -2518,7 +2518,7 @@ int hid_add_device(struct hid_device *hdev)
41464 /* XXX hack, any other cleaner solution after the driver core
41465 * is converted to allow more than 20 bytes as the device name? */
41466 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41467- hdev->vendor, hdev->product, atomic_inc_return(&id));
41468+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41469
41470 hid_debug_register(hdev, dev_name(&hdev->dev));
41471 ret = device_add(&hdev->dev);
41472diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41473index c13fb5b..55a3802 100644
41474--- a/drivers/hid/hid-wiimote-debug.c
41475+++ b/drivers/hid/hid-wiimote-debug.c
41476@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41477 else if (size == 0)
41478 return -EIO;
41479
41480- if (copy_to_user(u, buf, size))
41481+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41482 return -EFAULT;
41483
41484 *off += size;
41485diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41486index 0d078c3..cd0962c 100644
41487--- a/drivers/hid/uhid.c
41488+++ b/drivers/hid/uhid.c
41489@@ -47,7 +47,7 @@ struct uhid_device {
41490 struct mutex report_lock;
41491 wait_queue_head_t report_wait;
41492 atomic_t report_done;
41493- atomic_t report_id;
41494+ atomic_unchecked_t report_id;
41495 struct uhid_event report_buf;
41496 };
41497
41498@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41499
41500 spin_lock_irqsave(&uhid->qlock, flags);
41501 ev->type = UHID_FEATURE;
41502- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41503+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41504 ev->u.feature.rnum = rnum;
41505 ev->u.feature.rtype = report_type;
41506
41507@@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41508 spin_lock_irqsave(&uhid->qlock, flags);
41509
41510 /* id for old report; drop it silently */
41511- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41512+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41513 goto unlock;
41514 if (atomic_read(&uhid->report_done))
41515 goto unlock;
41516diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41517index 602ca86..10a6573 100644
41518--- a/drivers/hv/channel.c
41519+++ b/drivers/hv/channel.c
41520@@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41521 int ret = 0;
41522 int t;
41523
41524- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41525- atomic_inc(&vmbus_connection.next_gpadl_handle);
41526+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41527+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41528
41529 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41530 if (ret)
41531diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41532index bcb4950..61dba6c 100644
41533--- a/drivers/hv/hv.c
41534+++ b/drivers/hv/hv.c
41535@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41536 u64 output_address = (output) ? virt_to_phys(output) : 0;
41537 u32 output_address_hi = output_address >> 32;
41538 u32 output_address_lo = output_address & 0xFFFFFFFF;
41539- void *hypercall_page = hv_context.hypercall_page;
41540+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41541
41542 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41543 "=a"(hv_status_lo) : "d" (control_hi),
41544@@ -154,7 +154,7 @@ int hv_init(void)
41545 /* See if the hypercall page is already set */
41546 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41547
41548- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41549+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41550
41551 if (!virtaddr)
41552 goto cleanup;
41553diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41554index 5e90c5d..d8fcefb 100644
41555--- a/drivers/hv/hv_balloon.c
41556+++ b/drivers/hv/hv_balloon.c
41557@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41558
41559 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41560 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41561-static atomic_t trans_id = ATOMIC_INIT(0);
41562+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41563
41564 static int dm_ring_size = (5 * PAGE_SIZE);
41565
41566@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41567 pr_info("Memory hot add failed\n");
41568
41569 dm->state = DM_INITIALIZED;
41570- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41571+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41572 vmbus_sendpacket(dm->dev->channel, &resp,
41573 sizeof(struct dm_hot_add_response),
41574 (unsigned long)NULL,
41575@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41576 memset(&status, 0, sizeof(struct dm_status));
41577 status.hdr.type = DM_STATUS_REPORT;
41578 status.hdr.size = sizeof(struct dm_status);
41579- status.hdr.trans_id = atomic_inc_return(&trans_id);
41580+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41581
41582 /*
41583 * The host expects the guest to report free memory.
41584@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41585 * send the status. This can happen if we were interrupted
41586 * after we picked our transaction ID.
41587 */
41588- if (status.hdr.trans_id != atomic_read(&trans_id))
41589+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41590 return;
41591
41592 /*
41593@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41594 */
41595
41596 do {
41597- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41598+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41599 ret = vmbus_sendpacket(dm_device.dev->channel,
41600 bl_resp,
41601 bl_resp->hdr.size,
41602@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41603
41604 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41605 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41606- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41607+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41608 resp.hdr.size = sizeof(struct dm_unballoon_response);
41609
41610 vmbus_sendpacket(dm_device.dev->channel, &resp,
41611@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41612 memset(&version_req, 0, sizeof(struct dm_version_request));
41613 version_req.hdr.type = DM_VERSION_REQUEST;
41614 version_req.hdr.size = sizeof(struct dm_version_request);
41615- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41616+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41617 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41618 version_req.is_last_attempt = 1;
41619
41620@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41621 memset(&version_req, 0, sizeof(struct dm_version_request));
41622 version_req.hdr.type = DM_VERSION_REQUEST;
41623 version_req.hdr.size = sizeof(struct dm_version_request);
41624- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41625+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41626 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41627 version_req.is_last_attempt = 0;
41628
41629@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41630 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41631 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41632 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41633- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41634+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41635
41636 cap_msg.caps.cap_bits.balloon = 1;
41637 cap_msg.caps.cap_bits.hot_add = 1;
41638diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41639index 860134d..ea3a79a 100644
41640--- a/drivers/hv/hyperv_vmbus.h
41641+++ b/drivers/hv/hyperv_vmbus.h
41642@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41643 struct vmbus_connection {
41644 enum vmbus_connect_state conn_state;
41645
41646- atomic_t next_gpadl_handle;
41647+ atomic_unchecked_t next_gpadl_handle;
41648
41649 /*
41650 * Represents channel interrupts. Each bit position represents a
41651diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41652index 8e53a3c..7a64e44 100644
41653--- a/drivers/hv/vmbus_drv.c
41654+++ b/drivers/hv/vmbus_drv.c
41655@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41656 {
41657 int ret = 0;
41658
41659- static atomic_t device_num = ATOMIC_INIT(0);
41660+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41661
41662 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41663- atomic_inc_return(&device_num));
41664+ atomic_inc_return_unchecked(&device_num));
41665
41666 child_device_obj->device.bus = &hv_bus;
41667 child_device_obj->device.parent = &hv_acpi_dev->dev;
41668diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41669index 579bdf9..75118b5 100644
41670--- a/drivers/hwmon/acpi_power_meter.c
41671+++ b/drivers/hwmon/acpi_power_meter.c
41672@@ -116,7 +116,7 @@ struct sensor_template {
41673 struct device_attribute *devattr,
41674 const char *buf, size_t count);
41675 int index;
41676-};
41677+} __do_const;
41678
41679 /* Averaging interval */
41680 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41681@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41682 struct sensor_template *attrs)
41683 {
41684 struct device *dev = &resource->acpi_dev->dev;
41685- struct sensor_device_attribute *sensors =
41686+ sensor_device_attribute_no_const *sensors =
41687 &resource->sensors[resource->num_sensors];
41688 int res = 0;
41689
41690diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41691index 3288f13..71cfb4e 100644
41692--- a/drivers/hwmon/applesmc.c
41693+++ b/drivers/hwmon/applesmc.c
41694@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41695 {
41696 struct applesmc_node_group *grp;
41697 struct applesmc_dev_attr *node;
41698- struct attribute *attr;
41699+ attribute_no_const *attr;
41700 int ret, i;
41701
41702 for (grp = groups; grp->format; grp++) {
41703diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41704index ae208f6..48b6c5b 100644
41705--- a/drivers/hwmon/asus_atk0110.c
41706+++ b/drivers/hwmon/asus_atk0110.c
41707@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41708 struct atk_sensor_data {
41709 struct list_head list;
41710 struct atk_data *data;
41711- struct device_attribute label_attr;
41712- struct device_attribute input_attr;
41713- struct device_attribute limit1_attr;
41714- struct device_attribute limit2_attr;
41715+ device_attribute_no_const label_attr;
41716+ device_attribute_no_const input_attr;
41717+ device_attribute_no_const limit1_attr;
41718+ device_attribute_no_const limit2_attr;
41719 char label_attr_name[ATTR_NAME_SIZE];
41720 char input_attr_name[ATTR_NAME_SIZE];
41721 char limit1_attr_name[ATTR_NAME_SIZE];
41722@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41723 static struct device_attribute atk_name_attr =
41724 __ATTR(name, 0444, atk_name_show, NULL);
41725
41726-static void atk_init_attribute(struct device_attribute *attr, char *name,
41727+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41728 sysfs_show_func show)
41729 {
41730 sysfs_attr_init(&attr->attr);
41731diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41732index d76f0b7..55ae976 100644
41733--- a/drivers/hwmon/coretemp.c
41734+++ b/drivers/hwmon/coretemp.c
41735@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41736 return NOTIFY_OK;
41737 }
41738
41739-static struct notifier_block coretemp_cpu_notifier __refdata = {
41740+static struct notifier_block coretemp_cpu_notifier = {
41741 .notifier_call = coretemp_cpu_callback,
41742 };
41743
41744diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41745index 632f1dc..57e6a58 100644
41746--- a/drivers/hwmon/ibmaem.c
41747+++ b/drivers/hwmon/ibmaem.c
41748@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41749 struct aem_rw_sensor_template *rw)
41750 {
41751 struct device *dev = &data->pdev->dev;
41752- struct sensor_device_attribute *sensors = data->sensors;
41753+ sensor_device_attribute_no_const *sensors = data->sensors;
41754 int err;
41755
41756 /* Set up read-only sensors */
41757diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41758index 9fbb1b1..efbaa3e 100644
41759--- a/drivers/hwmon/iio_hwmon.c
41760+++ b/drivers/hwmon/iio_hwmon.c
41761@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41762 {
41763 struct device *dev = &pdev->dev;
41764 struct iio_hwmon_state *st;
41765- struct sensor_device_attribute *a;
41766+ sensor_device_attribute_no_const *a;
41767 int ret, i;
41768 int in_i = 1, temp_i = 1, curr_i = 1;
41769 enum iio_chan_type type;
41770diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41771index 38d5a63..cf2c2ea 100644
41772--- a/drivers/hwmon/nct6775.c
41773+++ b/drivers/hwmon/nct6775.c
41774@@ -944,10 +944,10 @@ static struct attribute_group *
41775 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41776 int repeat)
41777 {
41778- struct attribute_group *group;
41779+ attribute_group_no_const *group;
41780 struct sensor_device_attr_u *su;
41781- struct sensor_device_attribute *a;
41782- struct sensor_device_attribute_2 *a2;
41783+ sensor_device_attribute_no_const *a;
41784+ sensor_device_attribute_2_no_const *a2;
41785 struct attribute **attrs;
41786 struct sensor_device_template **t;
41787 int i, count;
41788diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41789index 291d11f..3f0dbbd 100644
41790--- a/drivers/hwmon/pmbus/pmbus_core.c
41791+++ b/drivers/hwmon/pmbus/pmbus_core.c
41792@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41793 return 0;
41794 }
41795
41796-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41797+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41798 const char *name,
41799 umode_t mode,
41800 ssize_t (*show)(struct device *dev,
41801@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41802 dev_attr->store = store;
41803 }
41804
41805-static void pmbus_attr_init(struct sensor_device_attribute *a,
41806+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41807 const char *name,
41808 umode_t mode,
41809 ssize_t (*show)(struct device *dev,
41810@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41811 u16 reg, u8 mask)
41812 {
41813 struct pmbus_boolean *boolean;
41814- struct sensor_device_attribute *a;
41815+ sensor_device_attribute_no_const *a;
41816
41817 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41818 if (!boolean)
41819@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41820 bool update, bool readonly)
41821 {
41822 struct pmbus_sensor *sensor;
41823- struct device_attribute *a;
41824+ device_attribute_no_const *a;
41825
41826 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41827 if (!sensor)
41828@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41829 const char *lstring, int index)
41830 {
41831 struct pmbus_label *label;
41832- struct device_attribute *a;
41833+ device_attribute_no_const *a;
41834
41835 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41836 if (!label)
41837diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41838index 97cd45a..ac54d8b 100644
41839--- a/drivers/hwmon/sht15.c
41840+++ b/drivers/hwmon/sht15.c
41841@@ -169,7 +169,7 @@ struct sht15_data {
41842 int supply_uv;
41843 bool supply_uv_valid;
41844 struct work_struct update_supply_work;
41845- atomic_t interrupt_handled;
41846+ atomic_unchecked_t interrupt_handled;
41847 };
41848
41849 /**
41850@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41851 ret = gpio_direction_input(data->pdata->gpio_data);
41852 if (ret)
41853 return ret;
41854- atomic_set(&data->interrupt_handled, 0);
41855+ atomic_set_unchecked(&data->interrupt_handled, 0);
41856
41857 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41858 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41859 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41860 /* Only relevant if the interrupt hasn't occurred. */
41861- if (!atomic_read(&data->interrupt_handled))
41862+ if (!atomic_read_unchecked(&data->interrupt_handled))
41863 schedule_work(&data->read_work);
41864 }
41865 ret = wait_event_timeout(data->wait_queue,
41866@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41867
41868 /* First disable the interrupt */
41869 disable_irq_nosync(irq);
41870- atomic_inc(&data->interrupt_handled);
41871+ atomic_inc_unchecked(&data->interrupt_handled);
41872 /* Then schedule a reading work struct */
41873 if (data->state != SHT15_READING_NOTHING)
41874 schedule_work(&data->read_work);
41875@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41876 * If not, then start the interrupt again - care here as could
41877 * have gone low in meantime so verify it hasn't!
41878 */
41879- atomic_set(&data->interrupt_handled, 0);
41880+ atomic_set_unchecked(&data->interrupt_handled, 0);
41881 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41882 /* If still not occurred or another handler was scheduled */
41883 if (gpio_get_value(data->pdata->gpio_data)
41884- || atomic_read(&data->interrupt_handled))
41885+ || atomic_read_unchecked(&data->interrupt_handled))
41886 return;
41887 }
41888
41889diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41890index 8df43c5..b07b91d 100644
41891--- a/drivers/hwmon/via-cputemp.c
41892+++ b/drivers/hwmon/via-cputemp.c
41893@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41894 return NOTIFY_OK;
41895 }
41896
41897-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41898+static struct notifier_block via_cputemp_cpu_notifier = {
41899 .notifier_call = via_cputemp_cpu_callback,
41900 };
41901
41902diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41903index 41fc683..a39cfea 100644
41904--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41905+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41906@@ -43,7 +43,7 @@
41907 extern struct i2c_adapter amd756_smbus;
41908
41909 static struct i2c_adapter *s4882_adapter;
41910-static struct i2c_algorithm *s4882_algo;
41911+static i2c_algorithm_no_const *s4882_algo;
41912
41913 /* Wrapper access functions for multiplexed SMBus */
41914 static DEFINE_MUTEX(amd756_lock);
41915diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41916index 721f7eb..0fd2a09 100644
41917--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41918+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41919@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41920 /* usb layer */
41921
41922 /* Send command to device, and get response. */
41923-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41924+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41925 {
41926 int ret = 0;
41927 int actual;
41928diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41929index b170bdf..3c76427 100644
41930--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41931+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41932@@ -41,7 +41,7 @@
41933 extern struct i2c_adapter *nforce2_smbus;
41934
41935 static struct i2c_adapter *s4985_adapter;
41936-static struct i2c_algorithm *s4985_algo;
41937+static i2c_algorithm_no_const *s4985_algo;
41938
41939 /* Wrapper access functions for multiplexed SMBus */
41940 static DEFINE_MUTEX(nforce2_lock);
41941diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41942index 80b47e8..1a6040d9 100644
41943--- a/drivers/i2c/i2c-dev.c
41944+++ b/drivers/i2c/i2c-dev.c
41945@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41946 break;
41947 }
41948
41949- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41950+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41951 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41952 if (IS_ERR(rdwr_pa[i].buf)) {
41953 res = PTR_ERR(rdwr_pa[i].buf);
41954diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41955index 0b510ba..4fbb5085 100644
41956--- a/drivers/ide/ide-cd.c
41957+++ b/drivers/ide/ide-cd.c
41958@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41959 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41960 if ((unsigned long)buf & alignment
41961 || blk_rq_bytes(rq) & q->dma_pad_mask
41962- || object_is_on_stack(buf))
41963+ || object_starts_on_stack(buf))
41964 drive->dma = 0;
41965 }
41966 }
41967diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41968index ede16aec..e423e8a 100644
41969--- a/drivers/iio/industrialio-core.c
41970+++ b/drivers/iio/industrialio-core.c
41971@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41972 }
41973
41974 static
41975-int __iio_device_attr_init(struct device_attribute *dev_attr,
41976+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41977 const char *postfix,
41978 struct iio_chan_spec const *chan,
41979 ssize_t (*readfunc)(struct device *dev,
41980diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41981index c323917..6ddea8b 100644
41982--- a/drivers/infiniband/core/cm.c
41983+++ b/drivers/infiniband/core/cm.c
41984@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41985
41986 struct cm_counter_group {
41987 struct kobject obj;
41988- atomic_long_t counter[CM_ATTR_COUNT];
41989+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41990 };
41991
41992 struct cm_counter_attribute {
41993@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41994 struct ib_mad_send_buf *msg = NULL;
41995 int ret;
41996
41997- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41998+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41999 counter[CM_REQ_COUNTER]);
42000
42001 /* Quick state check to discard duplicate REQs. */
42002@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42003 if (!cm_id_priv)
42004 return;
42005
42006- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42007+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42008 counter[CM_REP_COUNTER]);
42009 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42010 if (ret)
42011@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42012 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42013 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42014 spin_unlock_irq(&cm_id_priv->lock);
42015- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42016+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42017 counter[CM_RTU_COUNTER]);
42018 goto out;
42019 }
42020@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42021 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42022 dreq_msg->local_comm_id);
42023 if (!cm_id_priv) {
42024- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42025+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42026 counter[CM_DREQ_COUNTER]);
42027 cm_issue_drep(work->port, work->mad_recv_wc);
42028 return -EINVAL;
42029@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42030 case IB_CM_MRA_REP_RCVD:
42031 break;
42032 case IB_CM_TIMEWAIT:
42033- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42034+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42035 counter[CM_DREQ_COUNTER]);
42036 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42037 goto unlock;
42038@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42039 cm_free_msg(msg);
42040 goto deref;
42041 case IB_CM_DREQ_RCVD:
42042- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42043+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42044 counter[CM_DREQ_COUNTER]);
42045 goto unlock;
42046 default:
42047@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42048 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42049 cm_id_priv->msg, timeout)) {
42050 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42051- atomic_long_inc(&work->port->
42052+ atomic_long_inc_unchecked(&work->port->
42053 counter_group[CM_RECV_DUPLICATES].
42054 counter[CM_MRA_COUNTER]);
42055 goto out;
42056@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42057 break;
42058 case IB_CM_MRA_REQ_RCVD:
42059 case IB_CM_MRA_REP_RCVD:
42060- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42061+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42062 counter[CM_MRA_COUNTER]);
42063 /* fall through */
42064 default:
42065@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42066 case IB_CM_LAP_IDLE:
42067 break;
42068 case IB_CM_MRA_LAP_SENT:
42069- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42070+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42071 counter[CM_LAP_COUNTER]);
42072 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42073 goto unlock;
42074@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42075 cm_free_msg(msg);
42076 goto deref;
42077 case IB_CM_LAP_RCVD:
42078- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42079+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42080 counter[CM_LAP_COUNTER]);
42081 goto unlock;
42082 default:
42083@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42084 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42085 if (cur_cm_id_priv) {
42086 spin_unlock_irq(&cm.lock);
42087- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42088+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42089 counter[CM_SIDR_REQ_COUNTER]);
42090 goto out; /* Duplicate message. */
42091 }
42092@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42093 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42094 msg->retries = 1;
42095
42096- atomic_long_add(1 + msg->retries,
42097+ atomic_long_add_unchecked(1 + msg->retries,
42098 &port->counter_group[CM_XMIT].counter[attr_index]);
42099 if (msg->retries)
42100- atomic_long_add(msg->retries,
42101+ atomic_long_add_unchecked(msg->retries,
42102 &port->counter_group[CM_XMIT_RETRIES].
42103 counter[attr_index]);
42104
42105@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42106 }
42107
42108 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42109- atomic_long_inc(&port->counter_group[CM_RECV].
42110+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42111 counter[attr_id - CM_ATTR_ID_OFFSET]);
42112
42113 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42114@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42115 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42116
42117 return sprintf(buf, "%ld\n",
42118- atomic_long_read(&group->counter[cm_attr->index]));
42119+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42120 }
42121
42122 static const struct sysfs_ops cm_counter_ops = {
42123diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42124index 9f5ad7c..588cd84 100644
42125--- a/drivers/infiniband/core/fmr_pool.c
42126+++ b/drivers/infiniband/core/fmr_pool.c
42127@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42128
42129 struct task_struct *thread;
42130
42131- atomic_t req_ser;
42132- atomic_t flush_ser;
42133+ atomic_unchecked_t req_ser;
42134+ atomic_unchecked_t flush_ser;
42135
42136 wait_queue_head_t force_wait;
42137 };
42138@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42139 struct ib_fmr_pool *pool = pool_ptr;
42140
42141 do {
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 ib_fmr_batch_release(pool);
42145
42146- atomic_inc(&pool->flush_ser);
42147+ atomic_inc_unchecked(&pool->flush_ser);
42148 wake_up_interruptible(&pool->force_wait);
42149
42150 if (pool->flush_function)
42151@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42152 }
42153
42154 set_current_state(TASK_INTERRUPTIBLE);
42155- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42156+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42157 !kthread_should_stop())
42158 schedule();
42159 __set_current_state(TASK_RUNNING);
42160@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42161 pool->dirty_watermark = params->dirty_watermark;
42162 pool->dirty_len = 0;
42163 spin_lock_init(&pool->pool_lock);
42164- atomic_set(&pool->req_ser, 0);
42165- atomic_set(&pool->flush_ser, 0);
42166+ atomic_set_unchecked(&pool->req_ser, 0);
42167+ atomic_set_unchecked(&pool->flush_ser, 0);
42168 init_waitqueue_head(&pool->force_wait);
42169
42170 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42171@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42172 }
42173 spin_unlock_irq(&pool->pool_lock);
42174
42175- serial = atomic_inc_return(&pool->req_ser);
42176+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42177 wake_up_process(pool->thread);
42178
42179 if (wait_event_interruptible(pool->force_wait,
42180- atomic_read(&pool->flush_ser) - serial >= 0))
42181+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42182 return -EINTR;
42183
42184 return 0;
42185@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42186 } else {
42187 list_add_tail(&fmr->list, &pool->dirty_list);
42188 if (++pool->dirty_len >= pool->dirty_watermark) {
42189- atomic_inc(&pool->req_ser);
42190+ atomic_inc_unchecked(&pool->req_ser);
42191 wake_up_process(pool->thread);
42192 }
42193 }
42194diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42195index ec7a298..8742e59 100644
42196--- a/drivers/infiniband/hw/cxgb4/mem.c
42197+++ b/drivers/infiniband/hw/cxgb4/mem.c
42198@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42199 int err;
42200 struct fw_ri_tpte tpt;
42201 u32 stag_idx;
42202- static atomic_t key;
42203+ static atomic_unchecked_t key;
42204
42205 if (c4iw_fatal_error(rdev))
42206 return -EIO;
42207@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42208 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42209 rdev->stats.stag.max = rdev->stats.stag.cur;
42210 mutex_unlock(&rdev->stats.lock);
42211- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42212+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42213 }
42214 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42215 __func__, stag_state, type, pdid, stag_idx);
42216diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42217index 79b3dbc..96e5fcc 100644
42218--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42219+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42220@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42221 struct ib_atomic_eth *ateth;
42222 struct ipath_ack_entry *e;
42223 u64 vaddr;
42224- atomic64_t *maddr;
42225+ atomic64_unchecked_t *maddr;
42226 u64 sdata;
42227 u32 rkey;
42228 u8 next;
42229@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42230 IB_ACCESS_REMOTE_ATOMIC)))
42231 goto nack_acc_unlck;
42232 /* Perform atomic OP and save result. */
42233- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42234+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42235 sdata = be64_to_cpu(ateth->swap_data);
42236 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42237 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42238- (u64) atomic64_add_return(sdata, maddr) - sdata :
42239+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42240 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42241 be64_to_cpu(ateth->compare_data),
42242 sdata);
42243diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42244index 1f95bba..9530f87 100644
42245--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42246+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42247@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42248 unsigned long flags;
42249 struct ib_wc wc;
42250 u64 sdata;
42251- atomic64_t *maddr;
42252+ atomic64_unchecked_t *maddr;
42253 enum ib_wc_status send_status;
42254
42255 /*
42256@@ -382,11 +382,11 @@ again:
42257 IB_ACCESS_REMOTE_ATOMIC)))
42258 goto acc_err;
42259 /* Perform atomic OP and save result. */
42260- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42261+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42262 sdata = wqe->wr.wr.atomic.compare_add;
42263 *(u64 *) sqp->s_sge.sge.vaddr =
42264 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42265- (u64) atomic64_add_return(sdata, maddr) - sdata :
42266+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42267 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42268 sdata, wqe->wr.wr.atomic.swap);
42269 goto send_comp;
42270diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42271index fd36ec6..a6a082f 100644
42272--- a/drivers/infiniband/hw/mlx4/mad.c
42273+++ b/drivers/infiniband/hw/mlx4/mad.c
42274@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42275
42276 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42277 {
42278- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42279+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42280 cpu_to_be64(0xff00000000000000LL);
42281 }
42282
42283diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42284index ed327e6..ca1739e0 100644
42285--- a/drivers/infiniband/hw/mlx4/mcg.c
42286+++ b/drivers/infiniband/hw/mlx4/mcg.c
42287@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42288 {
42289 char name[20];
42290
42291- atomic_set(&ctx->tid, 0);
42292+ atomic_set_unchecked(&ctx->tid, 0);
42293 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42294 ctx->mcg_wq = create_singlethread_workqueue(name);
42295 if (!ctx->mcg_wq)
42296diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42297index 66b0b7d..f14836a 100644
42298--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42299+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42300@@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42301 struct list_head mcg_mgid0_list;
42302 struct workqueue_struct *mcg_wq;
42303 struct mlx4_ib_demux_pv_ctx **tun;
42304- atomic_t tid;
42305+ atomic_unchecked_t tid;
42306 int flushing; /* flushing the work queue */
42307 };
42308
42309diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42310index 9d3e5c1..6f166df 100644
42311--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42312+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42313@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42314 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42315 }
42316
42317-int mthca_QUERY_FW(struct mthca_dev *dev)
42318+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42319 {
42320 struct mthca_mailbox *mailbox;
42321 u32 *outbox;
42322@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42323 CMD_TIME_CLASS_B);
42324 }
42325
42326-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42327+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42328 int num_mtt)
42329 {
42330 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42331@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42332 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42333 }
42334
42335-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42336+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42337 int eq_num)
42338 {
42339 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42340@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42341 CMD_TIME_CLASS_B);
42342 }
42343
42344-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42345+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42346 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42347 void *in_mad, void *response_mad)
42348 {
42349diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42350index ded76c1..0cf0a08 100644
42351--- a/drivers/infiniband/hw/mthca/mthca_main.c
42352+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42353@@ -692,7 +692,7 @@ err_close:
42354 return err;
42355 }
42356
42357-static int mthca_setup_hca(struct mthca_dev *dev)
42358+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42359 {
42360 int err;
42361
42362diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42363index ed9a989..6aa5dc2 100644
42364--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42365+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42366@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42367 * through the bitmaps)
42368 */
42369
42370-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42371+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42372 {
42373 int o;
42374 int m;
42375@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42376 return key;
42377 }
42378
42379-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42380+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42381 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42382 {
42383 struct mthca_mailbox *mailbox;
42384@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42385 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42386 }
42387
42388-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42389+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42390 u64 *buffer_list, int buffer_size_shift,
42391 int list_len, u64 iova, u64 total_size,
42392 u32 access, struct mthca_mr *mr)
42393diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42394index 415f8e1..e34214e 100644
42395--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42396+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42397@@ -764,7 +764,7 @@ unlock:
42398 return 0;
42399 }
42400
42401-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42402+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42403 {
42404 struct mthca_dev *dev = to_mdev(ibcq->device);
42405 struct mthca_cq *cq = to_mcq(ibcq);
42406diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42407index 353c7b0..c6ce921 100644
42408--- a/drivers/infiniband/hw/nes/nes.c
42409+++ b/drivers/infiniband/hw/nes/nes.c
42410@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42411 LIST_HEAD(nes_adapter_list);
42412 static LIST_HEAD(nes_dev_list);
42413
42414-atomic_t qps_destroyed;
42415+atomic_unchecked_t qps_destroyed;
42416
42417 static unsigned int ee_flsh_adapter;
42418 static unsigned int sysfs_nonidx_addr;
42419@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42420 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42421 struct nes_adapter *nesadapter = nesdev->nesadapter;
42422
42423- atomic_inc(&qps_destroyed);
42424+ atomic_inc_unchecked(&qps_destroyed);
42425
42426 /* Free the control structures */
42427
42428diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42429index 33cc589..3bd6538 100644
42430--- a/drivers/infiniband/hw/nes/nes.h
42431+++ b/drivers/infiniband/hw/nes/nes.h
42432@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42433 extern unsigned int wqm_quanta;
42434 extern struct list_head nes_adapter_list;
42435
42436-extern atomic_t cm_connects;
42437-extern atomic_t cm_accepts;
42438-extern atomic_t cm_disconnects;
42439-extern atomic_t cm_closes;
42440-extern atomic_t cm_connecteds;
42441-extern atomic_t cm_connect_reqs;
42442-extern atomic_t cm_rejects;
42443-extern atomic_t mod_qp_timouts;
42444-extern atomic_t qps_created;
42445-extern atomic_t qps_destroyed;
42446-extern atomic_t sw_qps_destroyed;
42447+extern atomic_unchecked_t cm_connects;
42448+extern atomic_unchecked_t cm_accepts;
42449+extern atomic_unchecked_t cm_disconnects;
42450+extern atomic_unchecked_t cm_closes;
42451+extern atomic_unchecked_t cm_connecteds;
42452+extern atomic_unchecked_t cm_connect_reqs;
42453+extern atomic_unchecked_t cm_rejects;
42454+extern atomic_unchecked_t mod_qp_timouts;
42455+extern atomic_unchecked_t qps_created;
42456+extern atomic_unchecked_t qps_destroyed;
42457+extern atomic_unchecked_t sw_qps_destroyed;
42458 extern u32 mh_detected;
42459 extern u32 mh_pauses_sent;
42460 extern u32 cm_packets_sent;
42461@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42462 extern u32 cm_packets_received;
42463 extern u32 cm_packets_dropped;
42464 extern u32 cm_packets_retrans;
42465-extern atomic_t cm_listens_created;
42466-extern atomic_t cm_listens_destroyed;
42467+extern atomic_unchecked_t cm_listens_created;
42468+extern atomic_unchecked_t cm_listens_destroyed;
42469 extern u32 cm_backlog_drops;
42470-extern atomic_t cm_loopbacks;
42471-extern atomic_t cm_nodes_created;
42472-extern atomic_t cm_nodes_destroyed;
42473-extern atomic_t cm_accel_dropped_pkts;
42474-extern atomic_t cm_resets_recvd;
42475-extern atomic_t pau_qps_created;
42476-extern atomic_t pau_qps_destroyed;
42477+extern atomic_unchecked_t cm_loopbacks;
42478+extern atomic_unchecked_t cm_nodes_created;
42479+extern atomic_unchecked_t cm_nodes_destroyed;
42480+extern atomic_unchecked_t cm_accel_dropped_pkts;
42481+extern atomic_unchecked_t cm_resets_recvd;
42482+extern atomic_unchecked_t pau_qps_created;
42483+extern atomic_unchecked_t pau_qps_destroyed;
42484
42485 extern u32 int_mod_timer_init;
42486 extern u32 int_mod_cq_depth_256;
42487diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42488index dfa9df4..6bf7221 100644
42489--- a/drivers/infiniband/hw/nes/nes_cm.c
42490+++ b/drivers/infiniband/hw/nes/nes_cm.c
42491@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42492 u32 cm_packets_retrans;
42493 u32 cm_packets_created;
42494 u32 cm_packets_received;
42495-atomic_t cm_listens_created;
42496-atomic_t cm_listens_destroyed;
42497+atomic_unchecked_t cm_listens_created;
42498+atomic_unchecked_t cm_listens_destroyed;
42499 u32 cm_backlog_drops;
42500-atomic_t cm_loopbacks;
42501-atomic_t cm_nodes_created;
42502-atomic_t cm_nodes_destroyed;
42503-atomic_t cm_accel_dropped_pkts;
42504-atomic_t cm_resets_recvd;
42505+atomic_unchecked_t cm_loopbacks;
42506+atomic_unchecked_t cm_nodes_created;
42507+atomic_unchecked_t cm_nodes_destroyed;
42508+atomic_unchecked_t cm_accel_dropped_pkts;
42509+atomic_unchecked_t cm_resets_recvd;
42510
42511 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42512 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42513@@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42514 /* instance of function pointers for client API */
42515 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42516 static struct nes_cm_ops nes_cm_api = {
42517- mini_cm_accelerated,
42518- mini_cm_listen,
42519- mini_cm_del_listen,
42520- mini_cm_connect,
42521- mini_cm_close,
42522- mini_cm_accept,
42523- mini_cm_reject,
42524- mini_cm_recv_pkt,
42525- mini_cm_dealloc_core,
42526- mini_cm_get,
42527- mini_cm_set
42528+ .accelerated = mini_cm_accelerated,
42529+ .listen = mini_cm_listen,
42530+ .stop_listener = mini_cm_del_listen,
42531+ .connect = mini_cm_connect,
42532+ .close = mini_cm_close,
42533+ .accept = mini_cm_accept,
42534+ .reject = mini_cm_reject,
42535+ .recv_pkt = mini_cm_recv_pkt,
42536+ .destroy_cm_core = mini_cm_dealloc_core,
42537+ .get = mini_cm_get,
42538+ .set = mini_cm_set
42539 };
42540
42541 static struct nes_cm_core *g_cm_core;
42542
42543-atomic_t cm_connects;
42544-atomic_t cm_accepts;
42545-atomic_t cm_disconnects;
42546-atomic_t cm_closes;
42547-atomic_t cm_connecteds;
42548-atomic_t cm_connect_reqs;
42549-atomic_t cm_rejects;
42550+atomic_unchecked_t cm_connects;
42551+atomic_unchecked_t cm_accepts;
42552+atomic_unchecked_t cm_disconnects;
42553+atomic_unchecked_t cm_closes;
42554+atomic_unchecked_t cm_connecteds;
42555+atomic_unchecked_t cm_connect_reqs;
42556+atomic_unchecked_t cm_rejects;
42557
42558 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42559 {
42560@@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42561 kfree(listener);
42562 listener = NULL;
42563 ret = 0;
42564- atomic_inc(&cm_listens_destroyed);
42565+ atomic_inc_unchecked(&cm_listens_destroyed);
42566 } else {
42567 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42568 }
42569@@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42570 cm_node->rem_mac);
42571
42572 add_hte_node(cm_core, cm_node);
42573- atomic_inc(&cm_nodes_created);
42574+ atomic_inc_unchecked(&cm_nodes_created);
42575
42576 return cm_node;
42577 }
42578@@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42579 }
42580
42581 atomic_dec(&cm_core->node_cnt);
42582- atomic_inc(&cm_nodes_destroyed);
42583+ atomic_inc_unchecked(&cm_nodes_destroyed);
42584 nesqp = cm_node->nesqp;
42585 if (nesqp) {
42586 nesqp->cm_node = NULL;
42587@@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42588
42589 static void drop_packet(struct sk_buff *skb)
42590 {
42591- atomic_inc(&cm_accel_dropped_pkts);
42592+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42593 dev_kfree_skb_any(skb);
42594 }
42595
42596@@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42597 {
42598
42599 int reset = 0; /* whether to send reset in case of err.. */
42600- atomic_inc(&cm_resets_recvd);
42601+ atomic_inc_unchecked(&cm_resets_recvd);
42602 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42603 " refcnt=%d\n", cm_node, cm_node->state,
42604 atomic_read(&cm_node->ref_count));
42605@@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42606 rem_ref_cm_node(cm_node->cm_core, cm_node);
42607 return NULL;
42608 }
42609- atomic_inc(&cm_loopbacks);
42610+ atomic_inc_unchecked(&cm_loopbacks);
42611 loopbackremotenode->loopbackpartner = cm_node;
42612 loopbackremotenode->tcp_cntxt.rcv_wscale =
42613 NES_CM_DEFAULT_RCV_WND_SCALE;
42614@@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42615 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42616 else {
42617 rem_ref_cm_node(cm_core, cm_node);
42618- atomic_inc(&cm_accel_dropped_pkts);
42619+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42620 dev_kfree_skb_any(skb);
42621 }
42622 break;
42623@@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42624
42625 if ((cm_id) && (cm_id->event_handler)) {
42626 if (issue_disconn) {
42627- atomic_inc(&cm_disconnects);
42628+ atomic_inc_unchecked(&cm_disconnects);
42629 cm_event.event = IW_CM_EVENT_DISCONNECT;
42630 cm_event.status = disconn_status;
42631 cm_event.local_addr = cm_id->local_addr;
42632@@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42633 }
42634
42635 if (issue_close) {
42636- atomic_inc(&cm_closes);
42637+ atomic_inc_unchecked(&cm_closes);
42638 nes_disconnect(nesqp, 1);
42639
42640 cm_id->provider_data = nesqp;
42641@@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42642
42643 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42644 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42645- atomic_inc(&cm_accepts);
42646+ atomic_inc_unchecked(&cm_accepts);
42647
42648 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42649 netdev_refcnt_read(nesvnic->netdev));
42650@@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42651 struct nes_cm_core *cm_core;
42652 u8 *start_buff;
42653
42654- atomic_inc(&cm_rejects);
42655+ atomic_inc_unchecked(&cm_rejects);
42656 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42657 loopback = cm_node->loopbackpartner;
42658 cm_core = cm_node->cm_core;
42659@@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42660 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42661 ntohs(laddr->sin_port));
42662
42663- atomic_inc(&cm_connects);
42664+ atomic_inc_unchecked(&cm_connects);
42665 nesqp->active_conn = 1;
42666
42667 /* cache the cm_id in the qp */
42668@@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42669 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42670 return err;
42671 }
42672- atomic_inc(&cm_listens_created);
42673+ atomic_inc_unchecked(&cm_listens_created);
42674 }
42675
42676 cm_id->add_ref(cm_id);
42677@@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42678
42679 if (nesqp->destroyed)
42680 return;
42681- atomic_inc(&cm_connecteds);
42682+ atomic_inc_unchecked(&cm_connecteds);
42683 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42684 " local port 0x%04X. jiffies = %lu.\n",
42685 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42686@@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42687
42688 cm_id->add_ref(cm_id);
42689 ret = cm_id->event_handler(cm_id, &cm_event);
42690- atomic_inc(&cm_closes);
42691+ atomic_inc_unchecked(&cm_closes);
42692 cm_event.event = IW_CM_EVENT_CLOSE;
42693 cm_event.status = 0;
42694 cm_event.provider_data = cm_id->provider_data;
42695@@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42696 return;
42697 cm_id = cm_node->cm_id;
42698
42699- atomic_inc(&cm_connect_reqs);
42700+ atomic_inc_unchecked(&cm_connect_reqs);
42701 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42702 cm_node, cm_id, jiffies);
42703
42704@@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42705 return;
42706 cm_id = cm_node->cm_id;
42707
42708- atomic_inc(&cm_connect_reqs);
42709+ atomic_inc_unchecked(&cm_connect_reqs);
42710 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42711 cm_node, cm_id, jiffies);
42712
42713diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42714index 4166452..fc952c3 100644
42715--- a/drivers/infiniband/hw/nes/nes_mgt.c
42716+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42717@@ -40,8 +40,8 @@
42718 #include "nes.h"
42719 #include "nes_mgt.h"
42720
42721-atomic_t pau_qps_created;
42722-atomic_t pau_qps_destroyed;
42723+atomic_unchecked_t pau_qps_created;
42724+atomic_unchecked_t pau_qps_destroyed;
42725
42726 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42727 {
42728@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42729 {
42730 struct sk_buff *skb;
42731 unsigned long flags;
42732- atomic_inc(&pau_qps_destroyed);
42733+ atomic_inc_unchecked(&pau_qps_destroyed);
42734
42735 /* Free packets that have not yet been forwarded */
42736 /* Lock is acquired by skb_dequeue when removing the skb */
42737@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42738 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42739 skb_queue_head_init(&nesqp->pau_list);
42740 spin_lock_init(&nesqp->pau_lock);
42741- atomic_inc(&pau_qps_created);
42742+ atomic_inc_unchecked(&pau_qps_created);
42743 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42744 }
42745
42746diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42747index 49eb511..a774366 100644
42748--- a/drivers/infiniband/hw/nes/nes_nic.c
42749+++ b/drivers/infiniband/hw/nes/nes_nic.c
42750@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42751 target_stat_values[++index] = mh_detected;
42752 target_stat_values[++index] = mh_pauses_sent;
42753 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42754- target_stat_values[++index] = atomic_read(&cm_connects);
42755- target_stat_values[++index] = atomic_read(&cm_accepts);
42756- target_stat_values[++index] = atomic_read(&cm_disconnects);
42757- target_stat_values[++index] = atomic_read(&cm_connecteds);
42758- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42759- target_stat_values[++index] = atomic_read(&cm_rejects);
42760- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42761- target_stat_values[++index] = atomic_read(&qps_created);
42762- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42763- target_stat_values[++index] = atomic_read(&qps_destroyed);
42764- target_stat_values[++index] = atomic_read(&cm_closes);
42765+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42766+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42767+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42768+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42769+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42770+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42771+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42772+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42773+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42774+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42775+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42776 target_stat_values[++index] = cm_packets_sent;
42777 target_stat_values[++index] = cm_packets_bounced;
42778 target_stat_values[++index] = cm_packets_created;
42779 target_stat_values[++index] = cm_packets_received;
42780 target_stat_values[++index] = cm_packets_dropped;
42781 target_stat_values[++index] = cm_packets_retrans;
42782- target_stat_values[++index] = atomic_read(&cm_listens_created);
42783- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42784+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42785+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42786 target_stat_values[++index] = cm_backlog_drops;
42787- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42788- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42789- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42790- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42791- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42792+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42793+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42794+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42795+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42796+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42797 target_stat_values[++index] = nesadapter->free_4kpbl;
42798 target_stat_values[++index] = nesadapter->free_256pbl;
42799 target_stat_values[++index] = int_mod_timer_init;
42800 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42801 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42802 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42803- target_stat_values[++index] = atomic_read(&pau_qps_created);
42804- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42805+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42806+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42807 }
42808
42809 /**
42810diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42811index 218dd35..97ce31d 100644
42812--- a/drivers/infiniband/hw/nes/nes_verbs.c
42813+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42814@@ -46,9 +46,9 @@
42815
42816 #include <rdma/ib_umem.h>
42817
42818-atomic_t mod_qp_timouts;
42819-atomic_t qps_created;
42820-atomic_t sw_qps_destroyed;
42821+atomic_unchecked_t mod_qp_timouts;
42822+atomic_unchecked_t qps_created;
42823+atomic_unchecked_t sw_qps_destroyed;
42824
42825 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42826
42827@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42828 if (init_attr->create_flags)
42829 return ERR_PTR(-EINVAL);
42830
42831- atomic_inc(&qps_created);
42832+ atomic_inc_unchecked(&qps_created);
42833 switch (init_attr->qp_type) {
42834 case IB_QPT_RC:
42835 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42836@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42837 struct iw_cm_event cm_event;
42838 int ret = 0;
42839
42840- atomic_inc(&sw_qps_destroyed);
42841+ atomic_inc_unchecked(&sw_qps_destroyed);
42842 nesqp->destroyed = 1;
42843
42844 /* Blow away the connection if it exists. */
42845diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42846index c00ae09..04e91be 100644
42847--- a/drivers/infiniband/hw/qib/qib.h
42848+++ b/drivers/infiniband/hw/qib/qib.h
42849@@ -52,6 +52,7 @@
42850 #include <linux/kref.h>
42851 #include <linux/sched.h>
42852 #include <linux/kthread.h>
42853+#include <linux/slab.h>
42854
42855 #include "qib_common.h"
42856 #include "qib_verbs.h"
42857diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42858index 24c41ba..102d71f 100644
42859--- a/drivers/input/gameport/gameport.c
42860+++ b/drivers/input/gameport/gameport.c
42861@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42862 */
42863 static void gameport_init_port(struct gameport *gameport)
42864 {
42865- static atomic_t gameport_no = ATOMIC_INIT(0);
42866+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42867
42868 __module_get(THIS_MODULE);
42869
42870 mutex_init(&gameport->drv_mutex);
42871 device_initialize(&gameport->dev);
42872 dev_set_name(&gameport->dev, "gameport%lu",
42873- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42874+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42875 gameport->dev.bus = &gameport_bus;
42876 gameport->dev.release = gameport_release_port;
42877 if (gameport->parent)
42878diff --git a/drivers/input/input.c b/drivers/input/input.c
42879index 1c4c0db..6f7abe3 100644
42880--- a/drivers/input/input.c
42881+++ b/drivers/input/input.c
42882@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42883 */
42884 struct input_dev *input_allocate_device(void)
42885 {
42886- static atomic_t input_no = ATOMIC_INIT(0);
42887+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42888 struct input_dev *dev;
42889
42890 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42891@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42892 INIT_LIST_HEAD(&dev->node);
42893
42894 dev_set_name(&dev->dev, "input%ld",
42895- (unsigned long) atomic_inc_return(&input_no) - 1);
42896+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42897
42898 __module_get(THIS_MODULE);
42899 }
42900diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42901index 4a95b22..874c182 100644
42902--- a/drivers/input/joystick/sidewinder.c
42903+++ b/drivers/input/joystick/sidewinder.c
42904@@ -30,6 +30,7 @@
42905 #include <linux/kernel.h>
42906 #include <linux/module.h>
42907 #include <linux/slab.h>
42908+#include <linux/sched.h>
42909 #include <linux/input.h>
42910 #include <linux/gameport.h>
42911 #include <linux/jiffies.h>
42912diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42913index 603fe0d..f63decc 100644
42914--- a/drivers/input/joystick/xpad.c
42915+++ b/drivers/input/joystick/xpad.c
42916@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42917
42918 static int xpad_led_probe(struct usb_xpad *xpad)
42919 {
42920- static atomic_t led_seq = ATOMIC_INIT(0);
42921+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42922 long led_no;
42923 struct xpad_led *led;
42924 struct led_classdev *led_cdev;
42925@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42926 if (!led)
42927 return -ENOMEM;
42928
42929- led_no = (long)atomic_inc_return(&led_seq) - 1;
42930+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42931
42932 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42933 led->xpad = xpad;
42934diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42935index 5a73639..d586683 100644
42936--- a/drivers/input/misc/ims-pcu.c
42937+++ b/drivers/input/misc/ims-pcu.c
42938@@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42939
42940 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42941 {
42942- static atomic_t device_no = ATOMIC_INIT(0);
42943+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42944
42945 const struct ims_pcu_device_info *info;
42946 int error;
42947@@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42948 }
42949
42950 /* Device appears to be operable, complete initialization */
42951- pcu->device_no = atomic_inc_return(&device_no) - 1;
42952+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42953
42954 /*
42955 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
42956diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42957index 2f0b39d..7370f13 100644
42958--- a/drivers/input/mouse/psmouse.h
42959+++ b/drivers/input/mouse/psmouse.h
42960@@ -116,7 +116,7 @@ struct psmouse_attribute {
42961 ssize_t (*set)(struct psmouse *psmouse, void *data,
42962 const char *buf, size_t count);
42963 bool protect;
42964-};
42965+} __do_const;
42966 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42967
42968 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42969diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42970index b604564..3f14ae4 100644
42971--- a/drivers/input/mousedev.c
42972+++ b/drivers/input/mousedev.c
42973@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42974
42975 spin_unlock_irq(&client->packet_lock);
42976
42977- if (copy_to_user(buffer, data, count))
42978+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42979 return -EFAULT;
42980
42981 return count;
42982diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42983index b29134d..394deb0 100644
42984--- a/drivers/input/serio/serio.c
42985+++ b/drivers/input/serio/serio.c
42986@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
42987 */
42988 static void serio_init_port(struct serio *serio)
42989 {
42990- static atomic_t serio_no = ATOMIC_INIT(0);
42991+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42992
42993 __module_get(THIS_MODULE);
42994
42995@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
42996 mutex_init(&serio->drv_mutex);
42997 device_initialize(&serio->dev);
42998 dev_set_name(&serio->dev, "serio%ld",
42999- (long)atomic_inc_return(&serio_no) - 1);
43000+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
43001 serio->dev.bus = &serio_bus;
43002 serio->dev.release = serio_release_port;
43003 serio->dev.groups = serio_device_attr_groups;
43004diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43005index c9a02fe..0debc75 100644
43006--- a/drivers/input/serio/serio_raw.c
43007+++ b/drivers/input/serio/serio_raw.c
43008@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43009
43010 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43011 {
43012- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43013+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43014 struct serio_raw *serio_raw;
43015 int err;
43016
43017@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43018 }
43019
43020 snprintf(serio_raw->name, sizeof(serio_raw->name),
43021- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43022+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43023 kref_init(&serio_raw->kref);
43024 INIT_LIST_HEAD(&serio_raw->client_list);
43025 init_waitqueue_head(&serio_raw->wait);
43026diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43027index e5555fc..937986d 100644
43028--- a/drivers/iommu/iommu.c
43029+++ b/drivers/iommu/iommu.c
43030@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43031 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43032 {
43033 bus_register_notifier(bus, &iommu_bus_nb);
43034- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43035+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43036 }
43037
43038 /**
43039diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43040index 228632c9..edfe331 100644
43041--- a/drivers/iommu/irq_remapping.c
43042+++ b/drivers/iommu/irq_remapping.c
43043@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43044 void panic_if_irq_remap(const char *msg)
43045 {
43046 if (irq_remapping_enabled)
43047- panic(msg);
43048+ panic("%s", msg);
43049 }
43050
43051 static void ir_ack_apic_edge(struct irq_data *data)
43052@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43053
43054 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43055 {
43056- chip->irq_print_chip = ir_print_prefix;
43057- chip->irq_ack = ir_ack_apic_edge;
43058- chip->irq_eoi = ir_ack_apic_level;
43059- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43060+ pax_open_kernel();
43061+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43062+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43063+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43064+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43065+ pax_close_kernel();
43066 }
43067
43068 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43069diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43070index 57d165e..611997e 100644
43071--- a/drivers/irqchip/irq-gic.c
43072+++ b/drivers/irqchip/irq-gic.c
43073@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43074 * Supported arch specific GIC irq extension.
43075 * Default make them NULL.
43076 */
43077-struct irq_chip gic_arch_extn = {
43078+irq_chip_no_const gic_arch_extn = {
43079 .irq_eoi = NULL,
43080 .irq_mask = NULL,
43081 .irq_unmask = NULL,
43082@@ -336,7 +336,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43083 chained_irq_exit(chip, desc);
43084 }
43085
43086-static struct irq_chip gic_chip = {
43087+static irq_chip_no_const gic_chip __read_only = {
43088 .name = "GIC",
43089 .irq_mask = gic_mask_irq,
43090 .irq_unmask = gic_unmask_irq,
43091diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43092index 8777065..a4a9967 100644
43093--- a/drivers/irqchip/irq-renesas-irqc.c
43094+++ b/drivers/irqchip/irq-renesas-irqc.c
43095@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43096 struct irqc_priv *p;
43097 struct resource *io;
43098 struct resource *irq;
43099- struct irq_chip *irq_chip;
43100+ irq_chip_no_const *irq_chip;
43101 const char *name = dev_name(&pdev->dev);
43102 int ret;
43103 int k;
43104diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43105index ac6f72b..81150f2 100644
43106--- a/drivers/isdn/capi/capi.c
43107+++ b/drivers/isdn/capi/capi.c
43108@@ -81,8 +81,8 @@ struct capiminor {
43109
43110 struct capi20_appl *ap;
43111 u32 ncci;
43112- atomic_t datahandle;
43113- atomic_t msgid;
43114+ atomic_unchecked_t datahandle;
43115+ atomic_unchecked_t msgid;
43116
43117 struct tty_port port;
43118 int ttyinstop;
43119@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43120 capimsg_setu16(s, 2, mp->ap->applid);
43121 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43122 capimsg_setu8 (s, 5, CAPI_RESP);
43123- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43124+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43125 capimsg_setu32(s, 8, mp->ncci);
43126 capimsg_setu16(s, 12, datahandle);
43127 }
43128@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43129 mp->outbytes -= len;
43130 spin_unlock_bh(&mp->outlock);
43131
43132- datahandle = atomic_inc_return(&mp->datahandle);
43133+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43134 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43135 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43136 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43137 capimsg_setu16(skb->data, 2, mp->ap->applid);
43138 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43139 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43140- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43141+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43142 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43143 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43144 capimsg_setu16(skb->data, 16, len); /* Data length */
43145diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43146index c44950d..10ac276 100644
43147--- a/drivers/isdn/gigaset/bas-gigaset.c
43148+++ b/drivers/isdn/gigaset/bas-gigaset.c
43149@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43150
43151
43152 static const struct gigaset_ops gigops = {
43153- gigaset_write_cmd,
43154- gigaset_write_room,
43155- gigaset_chars_in_buffer,
43156- gigaset_brkchars,
43157- gigaset_init_bchannel,
43158- gigaset_close_bchannel,
43159- gigaset_initbcshw,
43160- gigaset_freebcshw,
43161- gigaset_reinitbcshw,
43162- gigaset_initcshw,
43163- gigaset_freecshw,
43164- gigaset_set_modem_ctrl,
43165- gigaset_baud_rate,
43166- gigaset_set_line_ctrl,
43167- gigaset_isoc_send_skb,
43168- gigaset_isoc_input,
43169+ .write_cmd = gigaset_write_cmd,
43170+ .write_room = gigaset_write_room,
43171+ .chars_in_buffer = gigaset_chars_in_buffer,
43172+ .brkchars = gigaset_brkchars,
43173+ .init_bchannel = gigaset_init_bchannel,
43174+ .close_bchannel = gigaset_close_bchannel,
43175+ .initbcshw = gigaset_initbcshw,
43176+ .freebcshw = gigaset_freebcshw,
43177+ .reinitbcshw = gigaset_reinitbcshw,
43178+ .initcshw = gigaset_initcshw,
43179+ .freecshw = gigaset_freecshw,
43180+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43181+ .baud_rate = gigaset_baud_rate,
43182+ .set_line_ctrl = gigaset_set_line_ctrl,
43183+ .send_skb = gigaset_isoc_send_skb,
43184+ .handle_input = gigaset_isoc_input,
43185 };
43186
43187 /* bas_gigaset_init
43188diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43189index 600c79b..3752bab 100644
43190--- a/drivers/isdn/gigaset/interface.c
43191+++ b/drivers/isdn/gigaset/interface.c
43192@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43193 }
43194 tty->driver_data = cs;
43195
43196- ++cs->port.count;
43197+ atomic_inc(&cs->port.count);
43198
43199- if (cs->port.count == 1) {
43200+ if (atomic_read(&cs->port.count) == 1) {
43201 tty_port_tty_set(&cs->port, tty);
43202 cs->port.low_latency = 1;
43203 }
43204@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43205
43206 if (!cs->connected)
43207 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43208- else if (!cs->port.count)
43209+ else if (!atomic_read(&cs->port.count))
43210 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43211- else if (!--cs->port.count)
43212+ else if (!atomic_dec_return(&cs->port.count))
43213 tty_port_tty_set(&cs->port, NULL);
43214
43215 mutex_unlock(&cs->mutex);
43216diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43217index 8c91fd5..14f13ce 100644
43218--- a/drivers/isdn/gigaset/ser-gigaset.c
43219+++ b/drivers/isdn/gigaset/ser-gigaset.c
43220@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43221 }
43222
43223 static const struct gigaset_ops ops = {
43224- gigaset_write_cmd,
43225- gigaset_write_room,
43226- gigaset_chars_in_buffer,
43227- gigaset_brkchars,
43228- gigaset_init_bchannel,
43229- gigaset_close_bchannel,
43230- gigaset_initbcshw,
43231- gigaset_freebcshw,
43232- gigaset_reinitbcshw,
43233- gigaset_initcshw,
43234- gigaset_freecshw,
43235- gigaset_set_modem_ctrl,
43236- gigaset_baud_rate,
43237- gigaset_set_line_ctrl,
43238- gigaset_m10x_send_skb, /* asyncdata.c */
43239- gigaset_m10x_input, /* asyncdata.c */
43240+ .write_cmd = gigaset_write_cmd,
43241+ .write_room = gigaset_write_room,
43242+ .chars_in_buffer = gigaset_chars_in_buffer,
43243+ .brkchars = gigaset_brkchars,
43244+ .init_bchannel = gigaset_init_bchannel,
43245+ .close_bchannel = gigaset_close_bchannel,
43246+ .initbcshw = gigaset_initbcshw,
43247+ .freebcshw = gigaset_freebcshw,
43248+ .reinitbcshw = gigaset_reinitbcshw,
43249+ .initcshw = gigaset_initcshw,
43250+ .freecshw = gigaset_freecshw,
43251+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43252+ .baud_rate = gigaset_baud_rate,
43253+ .set_line_ctrl = gigaset_set_line_ctrl,
43254+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43255+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43256 };
43257
43258
43259diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43260index d0a41cb..b953e50 100644
43261--- a/drivers/isdn/gigaset/usb-gigaset.c
43262+++ b/drivers/isdn/gigaset/usb-gigaset.c
43263@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43264 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43265 memcpy(cs->hw.usb->bchars, buf, 6);
43266 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43267- 0, 0, &buf, 6, 2000);
43268+ 0, 0, buf, 6, 2000);
43269 }
43270
43271 static void gigaset_freebcshw(struct bc_state *bcs)
43272@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43273 }
43274
43275 static const struct gigaset_ops ops = {
43276- gigaset_write_cmd,
43277- gigaset_write_room,
43278- gigaset_chars_in_buffer,
43279- gigaset_brkchars,
43280- gigaset_init_bchannel,
43281- gigaset_close_bchannel,
43282- gigaset_initbcshw,
43283- gigaset_freebcshw,
43284- gigaset_reinitbcshw,
43285- gigaset_initcshw,
43286- gigaset_freecshw,
43287- gigaset_set_modem_ctrl,
43288- gigaset_baud_rate,
43289- gigaset_set_line_ctrl,
43290- gigaset_m10x_send_skb,
43291- gigaset_m10x_input,
43292+ .write_cmd = gigaset_write_cmd,
43293+ .write_room = gigaset_write_room,
43294+ .chars_in_buffer = gigaset_chars_in_buffer,
43295+ .brkchars = gigaset_brkchars,
43296+ .init_bchannel = gigaset_init_bchannel,
43297+ .close_bchannel = gigaset_close_bchannel,
43298+ .initbcshw = gigaset_initbcshw,
43299+ .freebcshw = gigaset_freebcshw,
43300+ .reinitbcshw = gigaset_reinitbcshw,
43301+ .initcshw = gigaset_initcshw,
43302+ .freecshw = gigaset_freecshw,
43303+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43304+ .baud_rate = gigaset_baud_rate,
43305+ .set_line_ctrl = gigaset_set_line_ctrl,
43306+ .send_skb = gigaset_m10x_send_skb,
43307+ .handle_input = gigaset_m10x_input,
43308 };
43309
43310 /*
43311diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43312index 4d9b195..455075c 100644
43313--- a/drivers/isdn/hardware/avm/b1.c
43314+++ b/drivers/isdn/hardware/avm/b1.c
43315@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43316 }
43317 if (left) {
43318 if (t4file->user) {
43319- if (copy_from_user(buf, dp, left))
43320+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43321 return -EFAULT;
43322 } else {
43323 memcpy(buf, dp, left);
43324@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43325 }
43326 if (left) {
43327 if (config->user) {
43328- if (copy_from_user(buf, dp, left))
43329+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43330 return -EFAULT;
43331 } else {
43332 memcpy(buf, dp, left);
43333diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43334index 9b856e1..fa03c92 100644
43335--- a/drivers/isdn/i4l/isdn_common.c
43336+++ b/drivers/isdn/i4l/isdn_common.c
43337@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43338 } else
43339 return -EINVAL;
43340 case IIOCDBGVAR:
43341+ if (!capable(CAP_SYS_RAWIO))
43342+ return -EPERM;
43343 if (arg) {
43344 if (copy_to_user(argp, &dev, sizeof(ulong)))
43345 return -EFAULT;
43346diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43347index 91d5730..336523e 100644
43348--- a/drivers/isdn/i4l/isdn_concap.c
43349+++ b/drivers/isdn/i4l/isdn_concap.c
43350@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43351 }
43352
43353 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43354- &isdn_concap_dl_data_req,
43355- &isdn_concap_dl_connect_req,
43356- &isdn_concap_dl_disconn_req
43357+ .data_req = &isdn_concap_dl_data_req,
43358+ .connect_req = &isdn_concap_dl_connect_req,
43359+ .disconn_req = &isdn_concap_dl_disconn_req
43360 };
43361
43362 /* The following should better go into a dedicated source file such that
43363diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43364index 3c5f249..5fac4d0 100644
43365--- a/drivers/isdn/i4l/isdn_tty.c
43366+++ b/drivers/isdn/i4l/isdn_tty.c
43367@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43368
43369 #ifdef ISDN_DEBUG_MODEM_OPEN
43370 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43371- port->count);
43372+ atomic_read(&port->count));
43373 #endif
43374- port->count++;
43375+ atomic_inc(&port->count);
43376 port->tty = tty;
43377 /*
43378 * Start up serial port
43379@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43380 #endif
43381 return;
43382 }
43383- if ((tty->count == 1) && (port->count != 1)) {
43384+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43385 /*
43386 * Uh, oh. tty->count is 1, which means that the tty
43387 * structure will be freed. Info->count should always
43388@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43389 * serial port won't be shutdown.
43390 */
43391 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43392- "info->count is %d\n", port->count);
43393- port->count = 1;
43394+ "info->count is %d\n", atomic_read(&port->count));
43395+ atomic_set(&port->count, 1);
43396 }
43397- if (--port->count < 0) {
43398+ if (atomic_dec_return(&port->count) < 0) {
43399 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43400- info->line, port->count);
43401- port->count = 0;
43402+ info->line, atomic_read(&port->count));
43403+ atomic_set(&port->count, 0);
43404 }
43405- if (port->count) {
43406+ if (atomic_read(&port->count)) {
43407 #ifdef ISDN_DEBUG_MODEM_OPEN
43408 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43409 #endif
43410@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43411 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43412 return;
43413 isdn_tty_shutdown(info);
43414- port->count = 0;
43415+ atomic_set(&port->count, 0);
43416 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43417 port->tty = NULL;
43418 wake_up_interruptible(&port->open_wait);
43419@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43420 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43421 modem_info *info = &dev->mdm.info[i];
43422
43423- if (info->port.count == 0)
43424+ if (atomic_read(&info->port.count) == 0)
43425 continue;
43426 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43427 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43428diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43429index e2d4e58..40cd045 100644
43430--- a/drivers/isdn/i4l/isdn_x25iface.c
43431+++ b/drivers/isdn/i4l/isdn_x25iface.c
43432@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43433
43434
43435 static struct concap_proto_ops ix25_pops = {
43436- &isdn_x25iface_proto_new,
43437- &isdn_x25iface_proto_del,
43438- &isdn_x25iface_proto_restart,
43439- &isdn_x25iface_proto_close,
43440- &isdn_x25iface_xmit,
43441- &isdn_x25iface_receive,
43442- &isdn_x25iface_connect_ind,
43443- &isdn_x25iface_disconn_ind
43444+ .proto_new = &isdn_x25iface_proto_new,
43445+ .proto_del = &isdn_x25iface_proto_del,
43446+ .restart = &isdn_x25iface_proto_restart,
43447+ .close = &isdn_x25iface_proto_close,
43448+ .encap_and_xmit = &isdn_x25iface_xmit,
43449+ .data_ind = &isdn_x25iface_receive,
43450+ .connect_ind = &isdn_x25iface_connect_ind,
43451+ .disconn_ind = &isdn_x25iface_disconn_ind
43452 };
43453
43454 /* error message helper function */
43455diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43456index 6a7447c..cae33fe 100644
43457--- a/drivers/isdn/icn/icn.c
43458+++ b/drivers/isdn/icn/icn.c
43459@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43460 if (count > len)
43461 count = len;
43462 if (user) {
43463- if (copy_from_user(msg, buf, count))
43464+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43465 return -EFAULT;
43466 } else
43467 memcpy(msg, buf, count);
43468diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43469index a4f05c5..1433bc5 100644
43470--- a/drivers/isdn/mISDN/dsp_cmx.c
43471+++ b/drivers/isdn/mISDN/dsp_cmx.c
43472@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43473 static u16 dsp_count; /* last sample count */
43474 static int dsp_count_valid; /* if we have last sample count */
43475
43476-void
43477+void __intentional_overflow(-1)
43478 dsp_cmx_send(void *arg)
43479 {
43480 struct dsp_conf *conf;
43481diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43482index f58a354..fbae176 100644
43483--- a/drivers/leds/leds-clevo-mail.c
43484+++ b/drivers/leds/leds-clevo-mail.c
43485@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43486 * detected as working, but in reality it is not) as low as
43487 * possible.
43488 */
43489-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43490+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43491 {
43492 .callback = clevo_mail_led_dmi_callback,
43493 .ident = "Clevo D410J",
43494diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43495index 2eb3ef6..295891f 100644
43496--- a/drivers/leds/leds-ss4200.c
43497+++ b/drivers/leds/leds-ss4200.c
43498@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43499 * detected as working, but in reality it is not) as low as
43500 * possible.
43501 */
43502-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43503+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43504 {
43505 .callback = ss4200_led_dmi_callback,
43506 .ident = "Intel SS4200-E",
43507diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43508index 0bf1e4e..b4bf44e 100644
43509--- a/drivers/lguest/core.c
43510+++ b/drivers/lguest/core.c
43511@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43512 * The end address needs +1 because __get_vm_area allocates an
43513 * extra guard page, so we need space for that.
43514 */
43515+
43516+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43517+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43518+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43519+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43520+#else
43521 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43522 VM_ALLOC, switcher_addr, switcher_addr
43523 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43524+#endif
43525+
43526 if (!switcher_vma) {
43527 err = -ENOMEM;
43528 printk("lguest: could not map switcher pages high\n");
43529@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43530 * Now the Switcher is mapped at the right address, we can't fail!
43531 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43532 */
43533- memcpy(switcher_vma->addr, start_switcher_text,
43534+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43535 end_switcher_text - start_switcher_text);
43536
43537 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43538diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43539index e8b55c3..3514c37 100644
43540--- a/drivers/lguest/page_tables.c
43541+++ b/drivers/lguest/page_tables.c
43542@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43543 /*:*/
43544
43545 #ifdef CONFIG_X86_PAE
43546-static void release_pmd(pmd_t *spmd)
43547+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43548 {
43549 /* If the entry's not present, there's nothing to release. */
43550 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43551diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43552index 922a1ac..9dd0c2a 100644
43553--- a/drivers/lguest/x86/core.c
43554+++ b/drivers/lguest/x86/core.c
43555@@ -59,7 +59,7 @@ static struct {
43556 /* Offset from where switcher.S was compiled to where we've copied it */
43557 static unsigned long switcher_offset(void)
43558 {
43559- return switcher_addr - (unsigned long)start_switcher_text;
43560+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43561 }
43562
43563 /* This cpu's struct lguest_pages (after the Switcher text page) */
43564@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43565 * These copies are pretty cheap, so we do them unconditionally: */
43566 /* Save the current Host top-level page directory.
43567 */
43568+
43569+#ifdef CONFIG_PAX_PER_CPU_PGD
43570+ pages->state.host_cr3 = read_cr3();
43571+#else
43572 pages->state.host_cr3 = __pa(current->mm->pgd);
43573+#endif
43574+
43575 /*
43576 * Set up the Guest's page tables to see this CPU's pages (and no
43577 * other CPU's pages).
43578@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43579 * compiled-in switcher code and the high-mapped copy we just made.
43580 */
43581 for (i = 0; i < IDT_ENTRIES; i++)
43582- default_idt_entries[i] += switcher_offset();
43583+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43584
43585 /*
43586 * Set up the Switcher's per-cpu areas.
43587@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43588 * it will be undisturbed when we switch. To change %cs and jump we
43589 * need this structure to feed to Intel's "lcall" instruction.
43590 */
43591- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43592+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43593 lguest_entry.segment = LGUEST_CS;
43594
43595 /*
43596diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43597index 40634b0..4f5855e 100644
43598--- a/drivers/lguest/x86/switcher_32.S
43599+++ b/drivers/lguest/x86/switcher_32.S
43600@@ -87,6 +87,7 @@
43601 #include <asm/page.h>
43602 #include <asm/segment.h>
43603 #include <asm/lguest.h>
43604+#include <asm/processor-flags.h>
43605
43606 // We mark the start of the code to copy
43607 // It's placed in .text tho it's never run here
43608@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43609 // Changes type when we load it: damn Intel!
43610 // For after we switch over our page tables
43611 // That entry will be read-only: we'd crash.
43612+
43613+#ifdef CONFIG_PAX_KERNEXEC
43614+ mov %cr0, %edx
43615+ xor $X86_CR0_WP, %edx
43616+ mov %edx, %cr0
43617+#endif
43618+
43619 movl $(GDT_ENTRY_TSS*8), %edx
43620 ltr %dx
43621
43622@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43623 // Let's clear it again for our return.
43624 // The GDT descriptor of the Host
43625 // Points to the table after two "size" bytes
43626- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43627+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43628 // Clear "used" from type field (byte 5, bit 2)
43629- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43630+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43631+
43632+#ifdef CONFIG_PAX_KERNEXEC
43633+ mov %cr0, %eax
43634+ xor $X86_CR0_WP, %eax
43635+ mov %eax, %cr0
43636+#endif
43637
43638 // Once our page table's switched, the Guest is live!
43639 // The Host fades as we run this final step.
43640@@ -295,13 +309,12 @@ deliver_to_host:
43641 // I consulted gcc, and it gave
43642 // These instructions, which I gladly credit:
43643 leal (%edx,%ebx,8), %eax
43644- movzwl (%eax),%edx
43645- movl 4(%eax), %eax
43646- xorw %ax, %ax
43647- orl %eax, %edx
43648+ movl 4(%eax), %edx
43649+ movw (%eax), %dx
43650 // Now the address of the handler's in %edx
43651 // We call it now: its "iret" drops us home.
43652- jmp *%edx
43653+ ljmp $__KERNEL_CS, $1f
43654+1: jmp *%edx
43655
43656 // Every interrupt can come to us here
43657 // But we must truly tell each apart.
43658diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43659index 7ef7461..5a09dac 100644
43660--- a/drivers/md/bcache/closure.h
43661+++ b/drivers/md/bcache/closure.h
43662@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43663 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43664 struct workqueue_struct *wq)
43665 {
43666- BUG_ON(object_is_on_stack(cl));
43667+ BUG_ON(object_starts_on_stack(cl));
43668 closure_set_ip(cl);
43669 cl->fn = fn;
43670 cl->wq = wq;
43671diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43672index 9a8e66a..10cc762 100644
43673--- a/drivers/md/bitmap.c
43674+++ b/drivers/md/bitmap.c
43675@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43676 chunk_kb ? "KB" : "B");
43677 if (bitmap->storage.file) {
43678 seq_printf(seq, ", file: ");
43679- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43680+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43681 }
43682
43683 seq_printf(seq, "\n");
43684diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43685index 5152142..623d141 100644
43686--- a/drivers/md/dm-ioctl.c
43687+++ b/drivers/md/dm-ioctl.c
43688@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43689 cmd == DM_LIST_VERSIONS_CMD)
43690 return 0;
43691
43692- if ((cmd == DM_DEV_CREATE_CMD)) {
43693+ if (cmd == DM_DEV_CREATE_CMD) {
43694 if (!*param->name) {
43695 DMWARN("name not supplied when creating device");
43696 return -EINVAL;
43697diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43698index 7dfdb5c..4caada6 100644
43699--- a/drivers/md/dm-raid1.c
43700+++ b/drivers/md/dm-raid1.c
43701@@ -40,7 +40,7 @@ enum dm_raid1_error {
43702
43703 struct mirror {
43704 struct mirror_set *ms;
43705- atomic_t error_count;
43706+ atomic_unchecked_t error_count;
43707 unsigned long error_type;
43708 struct dm_dev *dev;
43709 sector_t offset;
43710@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43711 struct mirror *m;
43712
43713 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43714- if (!atomic_read(&m->error_count))
43715+ if (!atomic_read_unchecked(&m->error_count))
43716 return m;
43717
43718 return NULL;
43719@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43720 * simple way to tell if a device has encountered
43721 * errors.
43722 */
43723- atomic_inc(&m->error_count);
43724+ atomic_inc_unchecked(&m->error_count);
43725
43726 if (test_and_set_bit(error_type, &m->error_type))
43727 return;
43728@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43729 struct mirror *m = get_default_mirror(ms);
43730
43731 do {
43732- if (likely(!atomic_read(&m->error_count)))
43733+ if (likely(!atomic_read_unchecked(&m->error_count)))
43734 return m;
43735
43736 if (m-- == ms->mirror)
43737@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43738 {
43739 struct mirror *default_mirror = get_default_mirror(m->ms);
43740
43741- return !atomic_read(&default_mirror->error_count);
43742+ return !atomic_read_unchecked(&default_mirror->error_count);
43743 }
43744
43745 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43746@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43747 */
43748 if (likely(region_in_sync(ms, region, 1)))
43749 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43750- else if (m && atomic_read(&m->error_count))
43751+ else if (m && atomic_read_unchecked(&m->error_count))
43752 m = NULL;
43753
43754 if (likely(m))
43755@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43756 }
43757
43758 ms->mirror[mirror].ms = ms;
43759- atomic_set(&(ms->mirror[mirror].error_count), 0);
43760+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43761 ms->mirror[mirror].error_type = 0;
43762 ms->mirror[mirror].offset = offset;
43763
43764@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43765 */
43766 static char device_status_char(struct mirror *m)
43767 {
43768- if (!atomic_read(&(m->error_count)))
43769+ if (!atomic_read_unchecked(&(m->error_count)))
43770 return 'A';
43771
43772 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43773diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43774index 28a9012..9c0f6a5 100644
43775--- a/drivers/md/dm-stats.c
43776+++ b/drivers/md/dm-stats.c
43777@@ -382,7 +382,7 @@ do_sync_free:
43778 synchronize_rcu_expedited();
43779 dm_stat_free(&s->rcu_head);
43780 } else {
43781- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43782+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43783 call_rcu(&s->rcu_head, dm_stat_free);
43784 }
43785 return 0;
43786@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43787 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43788 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43789 ));
43790- ACCESS_ONCE(last->last_sector) = end_sector;
43791- ACCESS_ONCE(last->last_rw) = bi_rw;
43792+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43793+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43794 }
43795
43796 rcu_read_lock();
43797diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43798index d1600d2..4c3af3a 100644
43799--- a/drivers/md/dm-stripe.c
43800+++ b/drivers/md/dm-stripe.c
43801@@ -21,7 +21,7 @@ struct stripe {
43802 struct dm_dev *dev;
43803 sector_t physical_start;
43804
43805- atomic_t error_count;
43806+ atomic_unchecked_t error_count;
43807 };
43808
43809 struct stripe_c {
43810@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43811 kfree(sc);
43812 return r;
43813 }
43814- atomic_set(&(sc->stripe[i].error_count), 0);
43815+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43816 }
43817
43818 ti->private = sc;
43819@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43820 DMEMIT("%d ", sc->stripes);
43821 for (i = 0; i < sc->stripes; i++) {
43822 DMEMIT("%s ", sc->stripe[i].dev->name);
43823- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43824+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43825 'D' : 'A';
43826 }
43827 buffer[i] = '\0';
43828@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43829 */
43830 for (i = 0; i < sc->stripes; i++)
43831 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43832- atomic_inc(&(sc->stripe[i].error_count));
43833- if (atomic_read(&(sc->stripe[i].error_count)) <
43834+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43835+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43836 DM_IO_ERROR_THRESHOLD)
43837 schedule_work(&sc->trigger_event);
43838 }
43839diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43840index 50601ec..6d3b9dc 100644
43841--- a/drivers/md/dm-table.c
43842+++ b/drivers/md/dm-table.c
43843@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43844 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43845 struct mapped_device *md)
43846 {
43847- static char *_claim_ptr = "I belong to device-mapper";
43848+ static char _claim_ptr[] = "I belong to device-mapper";
43849 struct block_device *bdev;
43850
43851 int r;
43852@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43853 if (!dev_size)
43854 return 0;
43855
43856- if ((start >= dev_size) || (start + len > dev_size)) {
43857+ if ((start >= dev_size) || (len > dev_size - start)) {
43858 DMWARN("%s: %s too small for target: "
43859 "start=%llu, len=%llu, dev_size=%llu",
43860 dm_device_name(ti->table->md), bdevname(bdev, b),
43861diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43862index b086a94..74cb67e 100644
43863--- a/drivers/md/dm-thin-metadata.c
43864+++ b/drivers/md/dm-thin-metadata.c
43865@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43866 {
43867 pmd->info.tm = pmd->tm;
43868 pmd->info.levels = 2;
43869- pmd->info.value_type.context = pmd->data_sm;
43870+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43871 pmd->info.value_type.size = sizeof(__le64);
43872 pmd->info.value_type.inc = data_block_inc;
43873 pmd->info.value_type.dec = data_block_dec;
43874@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43875
43876 pmd->bl_info.tm = pmd->tm;
43877 pmd->bl_info.levels = 1;
43878- pmd->bl_info.value_type.context = pmd->data_sm;
43879+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43880 pmd->bl_info.value_type.size = sizeof(__le64);
43881 pmd->bl_info.value_type.inc = data_block_inc;
43882 pmd->bl_info.value_type.dec = data_block_dec;
43883diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43884index 455e649..1f214be 100644
43885--- a/drivers/md/dm.c
43886+++ b/drivers/md/dm.c
43887@@ -178,9 +178,9 @@ struct mapped_device {
43888 /*
43889 * Event handling.
43890 */
43891- atomic_t event_nr;
43892+ atomic_unchecked_t event_nr;
43893 wait_queue_head_t eventq;
43894- atomic_t uevent_seq;
43895+ atomic_unchecked_t uevent_seq;
43896 struct list_head uevent_list;
43897 spinlock_t uevent_lock; /* Protect access to uevent_list */
43898
43899@@ -1884,8 +1884,8 @@ static struct mapped_device *alloc_dev(int minor)
43900 spin_lock_init(&md->deferred_lock);
43901 atomic_set(&md->holders, 1);
43902 atomic_set(&md->open_count, 0);
43903- atomic_set(&md->event_nr, 0);
43904- atomic_set(&md->uevent_seq, 0);
43905+ atomic_set_unchecked(&md->event_nr, 0);
43906+ atomic_set_unchecked(&md->uevent_seq, 0);
43907 INIT_LIST_HEAD(&md->uevent_list);
43908 spin_lock_init(&md->uevent_lock);
43909
43910@@ -2039,7 +2039,7 @@ static void event_callback(void *context)
43911
43912 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43913
43914- atomic_inc(&md->event_nr);
43915+ atomic_inc_unchecked(&md->event_nr);
43916 wake_up(&md->eventq);
43917 }
43918
43919@@ -2732,18 +2732,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43920
43921 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43922 {
43923- return atomic_add_return(1, &md->uevent_seq);
43924+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43925 }
43926
43927 uint32_t dm_get_event_nr(struct mapped_device *md)
43928 {
43929- return atomic_read(&md->event_nr);
43930+ return atomic_read_unchecked(&md->event_nr);
43931 }
43932
43933 int dm_wait_event(struct mapped_device *md, int event_nr)
43934 {
43935 return wait_event_interruptible(md->eventq,
43936- (event_nr != atomic_read(&md->event_nr)));
43937+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43938 }
43939
43940 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43941diff --git a/drivers/md/md.c b/drivers/md/md.c
43942index 2382cfc..0d7e551 100644
43943--- a/drivers/md/md.c
43944+++ b/drivers/md/md.c
43945@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43946 * start build, activate spare
43947 */
43948 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43949-static atomic_t md_event_count;
43950+static atomic_unchecked_t md_event_count;
43951 void md_new_event(struct mddev *mddev)
43952 {
43953- atomic_inc(&md_event_count);
43954+ atomic_inc_unchecked(&md_event_count);
43955 wake_up(&md_event_waiters);
43956 }
43957 EXPORT_SYMBOL_GPL(md_new_event);
43958@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43959 */
43960 static void md_new_event_inintr(struct mddev *mddev)
43961 {
43962- atomic_inc(&md_event_count);
43963+ atomic_inc_unchecked(&md_event_count);
43964 wake_up(&md_event_waiters);
43965 }
43966
43967@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43968 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43969 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43970 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43971- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43972+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43973
43974 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43975 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43976@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43977 else
43978 sb->resync_offset = cpu_to_le64(0);
43979
43980- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43981+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43982
43983 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43984 sb->size = cpu_to_le64(mddev->dev_sectors);
43985@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43986 static ssize_t
43987 errors_show(struct md_rdev *rdev, char *page)
43988 {
43989- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43990+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43991 }
43992
43993 static ssize_t
43994@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43995 char *e;
43996 unsigned long n = simple_strtoul(buf, &e, 10);
43997 if (*buf && (*e == 0 || *e == '\n')) {
43998- atomic_set(&rdev->corrected_errors, n);
43999+ atomic_set_unchecked(&rdev->corrected_errors, n);
44000 return len;
44001 }
44002 return -EINVAL;
44003@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44004 rdev->sb_loaded = 0;
44005 rdev->bb_page = NULL;
44006 atomic_set(&rdev->nr_pending, 0);
44007- atomic_set(&rdev->read_errors, 0);
44008- atomic_set(&rdev->corrected_errors, 0);
44009+ atomic_set_unchecked(&rdev->read_errors, 0);
44010+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44011
44012 INIT_LIST_HEAD(&rdev->same_set);
44013 init_waitqueue_head(&rdev->blocked_wait);
44014@@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44015
44016 spin_unlock(&pers_lock);
44017 seq_printf(seq, "\n");
44018- seq->poll_event = atomic_read(&md_event_count);
44019+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44020 return 0;
44021 }
44022 if (v == (void*)2) {
44023@@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44024 return error;
44025
44026 seq = file->private_data;
44027- seq->poll_event = atomic_read(&md_event_count);
44028+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44029 return error;
44030 }
44031
44032@@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44033 /* always allow read */
44034 mask = POLLIN | POLLRDNORM;
44035
44036- if (seq->poll_event != atomic_read(&md_event_count))
44037+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44038 mask |= POLLERR | POLLPRI;
44039 return mask;
44040 }
44041@@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44042 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44043 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44044 (int)part_stat_read(&disk->part0, sectors[1]) -
44045- atomic_read(&disk->sync_io);
44046+ atomic_read_unchecked(&disk->sync_io);
44047 /* sync IO will cause sync_io to increase before the disk_stats
44048 * as sync_io is counted when a request starts, and
44049 * disk_stats is counted when it completes.
44050diff --git a/drivers/md/md.h b/drivers/md/md.h
44051index a49d991..3582bb7 100644
44052--- a/drivers/md/md.h
44053+++ b/drivers/md/md.h
44054@@ -94,13 +94,13 @@ struct md_rdev {
44055 * only maintained for arrays that
44056 * support hot removal
44057 */
44058- atomic_t read_errors; /* number of consecutive read errors that
44059+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44060 * we have tried to ignore.
44061 */
44062 struct timespec last_read_error; /* monotonic time since our
44063 * last read error
44064 */
44065- atomic_t corrected_errors; /* number of corrected read errors,
44066+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44067 * for reporting to userspace and storing
44068 * in superblock.
44069 */
44070@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44071
44072 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44073 {
44074- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44075+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44076 }
44077
44078 struct md_personality
44079diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44080index 786b689..ea8c956 100644
44081--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44082+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44083@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44084 * Flick into a mode where all blocks get allocated in the new area.
44085 */
44086 smm->begin = old_len;
44087- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44088+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44089
44090 /*
44091 * Extend.
44092@@ -710,7 +710,7 @@ out:
44093 /*
44094 * Switch back to normal behaviour.
44095 */
44096- memcpy(sm, &ops, sizeof(*sm));
44097+ memcpy((void *)sm, &ops, sizeof(*sm));
44098 return r;
44099 }
44100
44101diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44102index 3e6d115..ffecdeb 100644
44103--- a/drivers/md/persistent-data/dm-space-map.h
44104+++ b/drivers/md/persistent-data/dm-space-map.h
44105@@ -71,6 +71,7 @@ struct dm_space_map {
44106 dm_sm_threshold_fn fn,
44107 void *context);
44108 };
44109+typedef struct dm_space_map __no_const dm_space_map_no_const;
44110
44111 /*----------------------------------------------------------------*/
44112
44113diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44114index 56e24c0..e1c8e1f 100644
44115--- a/drivers/md/raid1.c
44116+++ b/drivers/md/raid1.c
44117@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44118 if (r1_sync_page_io(rdev, sect, s,
44119 bio->bi_io_vec[idx].bv_page,
44120 READ) != 0)
44121- atomic_add(s, &rdev->corrected_errors);
44122+ atomic_add_unchecked(s, &rdev->corrected_errors);
44123 }
44124 sectors -= s;
44125 sect += s;
44126@@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44127 test_bit(In_sync, &rdev->flags)) {
44128 if (r1_sync_page_io(rdev, sect, s,
44129 conf->tmppage, READ)) {
44130- atomic_add(s, &rdev->corrected_errors);
44131+ atomic_add_unchecked(s, &rdev->corrected_errors);
44132 printk(KERN_INFO
44133 "md/raid1:%s: read error corrected "
44134 "(%d sectors at %llu on %s)\n",
44135diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44136index cb882aa..9bd076e 100644
44137--- a/drivers/md/raid10.c
44138+++ b/drivers/md/raid10.c
44139@@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44140 /* The write handler will notice the lack of
44141 * R10BIO_Uptodate and record any errors etc
44142 */
44143- atomic_add(r10_bio->sectors,
44144+ atomic_add_unchecked(r10_bio->sectors,
44145 &conf->mirrors[d].rdev->corrected_errors);
44146
44147 /* for reconstruct, we always reschedule after a read.
44148@@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44149 {
44150 struct timespec cur_time_mon;
44151 unsigned long hours_since_last;
44152- unsigned int read_errors = atomic_read(&rdev->read_errors);
44153+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44154
44155 ktime_get_ts(&cur_time_mon);
44156
44157@@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44158 * overflowing the shift of read_errors by hours_since_last.
44159 */
44160 if (hours_since_last >= 8 * sizeof(read_errors))
44161- atomic_set(&rdev->read_errors, 0);
44162+ atomic_set_unchecked(&rdev->read_errors, 0);
44163 else
44164- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44165+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44166 }
44167
44168 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44169@@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44170 return;
44171
44172 check_decay_read_errors(mddev, rdev);
44173- atomic_inc(&rdev->read_errors);
44174- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44175+ atomic_inc_unchecked(&rdev->read_errors);
44176+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44177 char b[BDEVNAME_SIZE];
44178 bdevname(rdev->bdev, b);
44179
44180@@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44181 "md/raid10:%s: %s: Raid device exceeded "
44182 "read_error threshold [cur %d:max %d]\n",
44183 mdname(mddev), b,
44184- atomic_read(&rdev->read_errors), max_read_errors);
44185+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44186 printk(KERN_NOTICE
44187 "md/raid10:%s: %s: Failing raid device\n",
44188 mdname(mddev), b);
44189@@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44190 sect +
44191 choose_data_offset(r10_bio, rdev)),
44192 bdevname(rdev->bdev, b));
44193- atomic_add(s, &rdev->corrected_errors);
44194+ atomic_add_unchecked(s, &rdev->corrected_errors);
44195 }
44196
44197 rdev_dec_pending(rdev, mddev);
44198diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44199index ad1b9be..b417412 100644
44200--- a/drivers/md/raid5.c
44201+++ b/drivers/md/raid5.c
44202@@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44203 return 1;
44204 }
44205
44206+#ifdef CONFIG_GRKERNSEC_HIDESYM
44207+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44208+#endif
44209+
44210 static int grow_stripes(struct r5conf *conf, int num)
44211 {
44212 struct kmem_cache *sc;
44213@@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44214 "raid%d-%s", conf->level, mdname(conf->mddev));
44215 else
44216 sprintf(conf->cache_name[0],
44217+#ifdef CONFIG_GRKERNSEC_HIDESYM
44218+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44219+#else
44220 "raid%d-%p", conf->level, conf->mddev);
44221+#endif
44222 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44223
44224 conf->active_name = 0;
44225@@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44226 mdname(conf->mddev), STRIPE_SECTORS,
44227 (unsigned long long)s,
44228 bdevname(rdev->bdev, b));
44229- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44230+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44231 clear_bit(R5_ReadError, &sh->dev[i].flags);
44232 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44233 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44234 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44235
44236- if (atomic_read(&rdev->read_errors))
44237- atomic_set(&rdev->read_errors, 0);
44238+ if (atomic_read_unchecked(&rdev->read_errors))
44239+ atomic_set_unchecked(&rdev->read_errors, 0);
44240 } else {
44241 const char *bdn = bdevname(rdev->bdev, b);
44242 int retry = 0;
44243 int set_bad = 0;
44244
44245 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44246- atomic_inc(&rdev->read_errors);
44247+ atomic_inc_unchecked(&rdev->read_errors);
44248 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44249 printk_ratelimited(
44250 KERN_WARNING
44251@@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44252 mdname(conf->mddev),
44253 (unsigned long long)s,
44254 bdn);
44255- } else if (atomic_read(&rdev->read_errors)
44256+ } else if (atomic_read_unchecked(&rdev->read_errors)
44257 > conf->max_nr_stripes)
44258 printk(KERN_WARNING
44259 "md/raid:%s: Too many read errors, failing device %s.\n",
44260diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44261index 983db75..ef9248c 100644
44262--- a/drivers/media/dvb-core/dvbdev.c
44263+++ b/drivers/media/dvb-core/dvbdev.c
44264@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44265 const struct dvb_device *template, void *priv, int type)
44266 {
44267 struct dvb_device *dvbdev;
44268- struct file_operations *dvbdevfops;
44269+ file_operations_no_const *dvbdevfops;
44270 struct device *clsdev;
44271 int minor;
44272 int id;
44273diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44274index 539f4db..cdd403b 100644
44275--- a/drivers/media/dvb-frontends/af9033.h
44276+++ b/drivers/media/dvb-frontends/af9033.h
44277@@ -82,7 +82,7 @@ struct af9033_ops {
44278 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44279 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44280 int onoff);
44281-};
44282+} __no_const;
44283
44284
44285 #if IS_ENABLED(CONFIG_DVB_AF9033)
44286diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44287index 9b6c3bb..baeb5c7 100644
44288--- a/drivers/media/dvb-frontends/dib3000.h
44289+++ b/drivers/media/dvb-frontends/dib3000.h
44290@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44291 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44292 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44293 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44294-};
44295+} __no_const;
44296
44297 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44298 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44299diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44300index ed8cb90..5ef7f79 100644
44301--- a/drivers/media/pci/cx88/cx88-video.c
44302+++ b/drivers/media/pci/cx88/cx88-video.c
44303@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44304
44305 /* ------------------------------------------------------------------ */
44306
44307-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44308-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44309-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44310+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44311+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44312+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44313
44314 module_param_array(video_nr, int, NULL, 0444);
44315 module_param_array(vbi_nr, int, NULL, 0444);
44316diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44317index 802642d..5534900 100644
44318--- a/drivers/media/pci/ivtv/ivtv-driver.c
44319+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44320@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44321 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44322
44323 /* ivtv instance counter */
44324-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44325+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44326
44327 /* Parameter declarations */
44328 static int cardtype[IVTV_MAX_CARDS];
44329diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44330index 9a726ea..f5e9b52 100644
44331--- a/drivers/media/platform/omap/omap_vout.c
44332+++ b/drivers/media/platform/omap/omap_vout.c
44333@@ -63,7 +63,6 @@ enum omap_vout_channels {
44334 OMAP_VIDEO2,
44335 };
44336
44337-static struct videobuf_queue_ops video_vbq_ops;
44338 /* Variables configurable through module params*/
44339 static u32 video1_numbuffers = 3;
44340 static u32 video2_numbuffers = 3;
44341@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44342 {
44343 struct videobuf_queue *q;
44344 struct omap_vout_device *vout = NULL;
44345+ static struct videobuf_queue_ops video_vbq_ops = {
44346+ .buf_setup = omap_vout_buffer_setup,
44347+ .buf_prepare = omap_vout_buffer_prepare,
44348+ .buf_release = omap_vout_buffer_release,
44349+ .buf_queue = omap_vout_buffer_queue,
44350+ };
44351
44352 vout = video_drvdata(file);
44353 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44354@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44355 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44356
44357 q = &vout->vbq;
44358- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44359- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44360- video_vbq_ops.buf_release = omap_vout_buffer_release;
44361- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44362 spin_lock_init(&vout->vbq_lock);
44363
44364 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44365diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44366index fb2acc5..a2fcbdc4 100644
44367--- a/drivers/media/platform/s5p-tv/mixer.h
44368+++ b/drivers/media/platform/s5p-tv/mixer.h
44369@@ -156,7 +156,7 @@ struct mxr_layer {
44370 /** layer index (unique identifier) */
44371 int idx;
44372 /** callbacks for layer methods */
44373- struct mxr_layer_ops ops;
44374+ struct mxr_layer_ops *ops;
44375 /** format array */
44376 const struct mxr_format **fmt_array;
44377 /** size of format array */
44378diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44379index 74344c7..a39e70e 100644
44380--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44381+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44382@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44383 {
44384 struct mxr_layer *layer;
44385 int ret;
44386- struct mxr_layer_ops ops = {
44387+ static struct mxr_layer_ops ops = {
44388 .release = mxr_graph_layer_release,
44389 .buffer_set = mxr_graph_buffer_set,
44390 .stream_set = mxr_graph_stream_set,
44391diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44392index b713403..53cb5ad 100644
44393--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44394+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44395@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44396 layer->update_buf = next;
44397 }
44398
44399- layer->ops.buffer_set(layer, layer->update_buf);
44400+ layer->ops->buffer_set(layer, layer->update_buf);
44401
44402 if (done && done != layer->shadow_buf)
44403 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44404diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44405index a1ce55f..4a3c4d9 100644
44406--- a/drivers/media/platform/s5p-tv/mixer_video.c
44407+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44408@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44409 layer->geo.src.height = layer->geo.src.full_height;
44410
44411 mxr_geometry_dump(mdev, &layer->geo);
44412- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44413+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44414 mxr_geometry_dump(mdev, &layer->geo);
44415 }
44416
44417@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44418 layer->geo.dst.full_width = mbus_fmt.width;
44419 layer->geo.dst.full_height = mbus_fmt.height;
44420 layer->geo.dst.field = mbus_fmt.field;
44421- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44422+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44423
44424 mxr_geometry_dump(mdev, &layer->geo);
44425 }
44426@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44427 /* set source size to highest accepted value */
44428 geo->src.full_width = max(geo->dst.full_width, pix->width);
44429 geo->src.full_height = max(geo->dst.full_height, pix->height);
44430- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44431+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44432 mxr_geometry_dump(mdev, &layer->geo);
44433 /* set cropping to total visible screen */
44434 geo->src.width = pix->width;
44435@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44436 geo->src.x_offset = 0;
44437 geo->src.y_offset = 0;
44438 /* assure consistency of geometry */
44439- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44440+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44441 mxr_geometry_dump(mdev, &layer->geo);
44442 /* set full size to lowest possible value */
44443 geo->src.full_width = 0;
44444 geo->src.full_height = 0;
44445- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44446+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44447 mxr_geometry_dump(mdev, &layer->geo);
44448
44449 /* returning results */
44450@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44451 target->width = s->r.width;
44452 target->height = s->r.height;
44453
44454- layer->ops.fix_geometry(layer, stage, s->flags);
44455+ layer->ops->fix_geometry(layer, stage, s->flags);
44456
44457 /* retrieve update selection rectangle */
44458 res.left = target->x_offset;
44459@@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44460 mxr_output_get(mdev);
44461
44462 mxr_layer_update_output(layer);
44463- layer->ops.format_set(layer);
44464+ layer->ops->format_set(layer);
44465 /* enabling layer in hardware */
44466 spin_lock_irqsave(&layer->enq_slock, flags);
44467 layer->state = MXR_LAYER_STREAMING;
44468 spin_unlock_irqrestore(&layer->enq_slock, flags);
44469
44470- layer->ops.stream_set(layer, MXR_ENABLE);
44471+ layer->ops->stream_set(layer, MXR_ENABLE);
44472 mxr_streamer_get(mdev);
44473
44474 return 0;
44475@@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44476 spin_unlock_irqrestore(&layer->enq_slock, flags);
44477
44478 /* disabling layer in hardware */
44479- layer->ops.stream_set(layer, MXR_DISABLE);
44480+ layer->ops->stream_set(layer, MXR_DISABLE);
44481 /* remove one streamer */
44482 mxr_streamer_put(mdev);
44483 /* allow changes in output configuration */
44484@@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44485
44486 void mxr_layer_release(struct mxr_layer *layer)
44487 {
44488- if (layer->ops.release)
44489- layer->ops.release(layer);
44490+ if (layer->ops->release)
44491+ layer->ops->release(layer);
44492 }
44493
44494 void mxr_base_layer_release(struct mxr_layer *layer)
44495@@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44496
44497 layer->mdev = mdev;
44498 layer->idx = idx;
44499- layer->ops = *ops;
44500+ layer->ops = ops;
44501
44502 spin_lock_init(&layer->enq_slock);
44503 INIT_LIST_HEAD(&layer->enq_list);
44504diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44505index c9388c4..ce71ece 100644
44506--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44507+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44508@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44509 {
44510 struct mxr_layer *layer;
44511 int ret;
44512- struct mxr_layer_ops ops = {
44513+ static struct mxr_layer_ops ops = {
44514 .release = mxr_vp_layer_release,
44515 .buffer_set = mxr_vp_buffer_set,
44516 .stream_set = mxr_vp_stream_set,
44517diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44518index 3890f4f..b5c7511 100644
44519--- a/drivers/media/platform/vivi.c
44520+++ b/drivers/media/platform/vivi.c
44521@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44522 MODULE_LICENSE("Dual BSD/GPL");
44523 MODULE_VERSION(VIVI_VERSION);
44524
44525-static unsigned video_nr = -1;
44526-module_param(video_nr, uint, 0644);
44527+static int video_nr = -1;
44528+module_param(video_nr, int, 0644);
44529 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44530
44531 static unsigned n_devs = 1;
44532diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44533index d719e59..63f3470 100644
44534--- a/drivers/media/radio/radio-cadet.c
44535+++ b/drivers/media/radio/radio-cadet.c
44536@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44537 unsigned char readbuf[RDS_BUFFER];
44538 int i = 0;
44539
44540+ if (count > RDS_BUFFER)
44541+ return -EFAULT;
44542 mutex_lock(&dev->lock);
44543 if (dev->rdsstat == 0)
44544 cadet_start_rds(dev);
44545@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44546 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44547 mutex_unlock(&dev->lock);
44548
44549- if (i && copy_to_user(data, readbuf, i))
44550- return -EFAULT;
44551+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44552+ i = -EFAULT;
44553+
44554 return i;
44555 }
44556
44557diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44558index 5236035..c622c74 100644
44559--- a/drivers/media/radio/radio-maxiradio.c
44560+++ b/drivers/media/radio/radio-maxiradio.c
44561@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44562 /* TEA5757 pin mappings */
44563 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44564
44565-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44566+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44567
44568 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44569 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44570diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44571index 050b3bb..79f62b9 100644
44572--- a/drivers/media/radio/radio-shark.c
44573+++ b/drivers/media/radio/radio-shark.c
44574@@ -79,7 +79,7 @@ struct shark_device {
44575 u32 last_val;
44576 };
44577
44578-static atomic_t shark_instance = ATOMIC_INIT(0);
44579+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44580
44581 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44582 {
44583diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44584index 8654e0d..0608a64 100644
44585--- a/drivers/media/radio/radio-shark2.c
44586+++ b/drivers/media/radio/radio-shark2.c
44587@@ -74,7 +74,7 @@ struct shark_device {
44588 u8 *transfer_buffer;
44589 };
44590
44591-static atomic_t shark_instance = ATOMIC_INIT(0);
44592+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44593
44594 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44595 {
44596diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44597index 2fd9009..278cc1e 100644
44598--- a/drivers/media/radio/radio-si476x.c
44599+++ b/drivers/media/radio/radio-si476x.c
44600@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44601 struct si476x_radio *radio;
44602 struct v4l2_ctrl *ctrl;
44603
44604- static atomic_t instance = ATOMIC_INIT(0);
44605+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44606
44607 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44608 if (!radio)
44609diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44610index a1c641e..3007da9 100644
44611--- a/drivers/media/usb/dvb-usb/cxusb.c
44612+++ b/drivers/media/usb/dvb-usb/cxusb.c
44613@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44614
44615 struct dib0700_adapter_state {
44616 int (*set_param_save) (struct dvb_frontend *);
44617-};
44618+} __no_const;
44619
44620 static int dib7070_set_param_override(struct dvb_frontend *fe)
44621 {
44622diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44623index ae0f56a..ec71784 100644
44624--- a/drivers/media/usb/dvb-usb/dw2102.c
44625+++ b/drivers/media/usb/dvb-usb/dw2102.c
44626@@ -118,7 +118,7 @@ struct su3000_state {
44627
44628 struct s6x0_state {
44629 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44630-};
44631+} __no_const;
44632
44633 /* debug */
44634 static int dvb_usb_dw2102_debug;
44635diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44636index 7e2411c..cef73ca 100644
44637--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44638+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44639@@ -328,7 +328,7 @@ struct v4l2_buffer32 {
44640 __u32 reserved;
44641 };
44642
44643-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44644+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44645 enum v4l2_memory memory)
44646 {
44647 void __user *up_pln;
44648@@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44649 return 0;
44650 }
44651
44652-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44653+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44654 enum v4l2_memory memory)
44655 {
44656 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44657@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44658 * by passing a very big num_planes value */
44659 uplane = compat_alloc_user_space(num_planes *
44660 sizeof(struct v4l2_plane));
44661- kp->m.planes = uplane;
44662+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44663
44664 while (--num_planes >= 0) {
44665 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44666@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44667 if (num_planes == 0)
44668 return 0;
44669
44670- uplane = kp->m.planes;
44671+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44672 if (get_user(p, &up->m.planes))
44673 return -EFAULT;
44674 uplane32 = compat_ptr(p);
44675@@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44676 get_user(kp->capability, &up->capability) ||
44677 get_user(kp->flags, &up->flags))
44678 return -EFAULT;
44679- kp->base = compat_ptr(tmp);
44680+ kp->base = (void __force_kernel *)compat_ptr(tmp);
44681 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44682 return 0;
44683 }
44684@@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44685 n * sizeof(struct v4l2_ext_control32)))
44686 return -EFAULT;
44687 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44688- kp->controls = kcontrols;
44689+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44690 while (--n >= 0) {
44691 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44692 return -EFAULT;
44693@@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44694 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44695 {
44696 struct v4l2_ext_control32 __user *ucontrols;
44697- struct v4l2_ext_control __user *kcontrols = kp->controls;
44698+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44699 int n = kp->count;
44700 compat_caddr_t p;
44701
44702@@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
44703 put_user(kp->start_block, &up->start_block) ||
44704 put_user(kp->blocks, &up->blocks) ||
44705 put_user(tmp, &up->edid) ||
44706- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44707+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44708 return -EFAULT;
44709 return 0;
44710 }
44711diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44712index 55c6832..a91c7a6 100644
44713--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44714+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44715@@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44716 return 0;
44717
44718 case V4L2_CTRL_TYPE_STRING:
44719- len = strlen(c->string);
44720- if (len < ctrl->minimum)
44721+ len = strlen_user(c->string);
44722+ if (!len || len < ctrl->minimum)
44723 return -ERANGE;
44724 if ((len - ctrl->minimum) % ctrl->step)
44725 return -ERANGE;
44726diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44727index 02d1b63..5fd6b16 100644
44728--- a/drivers/media/v4l2-core/v4l2-device.c
44729+++ b/drivers/media/v4l2-core/v4l2-device.c
44730@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44731 EXPORT_SYMBOL_GPL(v4l2_device_put);
44732
44733 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44734- atomic_t *instance)
44735+ atomic_unchecked_t *instance)
44736 {
44737- int num = atomic_inc_return(instance) - 1;
44738+ int num = atomic_inc_return_unchecked(instance) - 1;
44739 int len = strlen(basename);
44740
44741 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44742diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44743index d9113cc..7de6ccc 100644
44744--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44745+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44746@@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
44747 struct file *file, void *fh, void *p);
44748 } u;
44749 void (*debug)(const void *arg, bool write_only);
44750-};
44751+} __do_const;
44752+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44753
44754 /* This control needs a priority check */
44755 #define INFO_FL_PRIO (1 << 0)
44756@@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
44757 struct video_device *vfd = video_devdata(file);
44758 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44759 bool write_only = false;
44760- struct v4l2_ioctl_info default_info;
44761+ v4l2_ioctl_info_no_const default_info;
44762 const struct v4l2_ioctl_info *info;
44763 void *fh = file->private_data;
44764 struct v4l2_fh *vfh = NULL;
44765@@ -2260,7 +2261,7 @@ done:
44766 }
44767
44768 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44769- void * __user *user_ptr, void ***kernel_ptr)
44770+ void __user **user_ptr, void ***kernel_ptr)
44771 {
44772 int ret = 0;
44773
44774@@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44775 ret = -EINVAL;
44776 break;
44777 }
44778- *user_ptr = (void __user *)buf->m.planes;
44779+ *user_ptr = (void __force_user *)buf->m.planes;
44780 *kernel_ptr = (void *)&buf->m.planes;
44781 *array_size = sizeof(struct v4l2_plane) * buf->length;
44782 ret = 1;
44783@@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44784 ret = -EINVAL;
44785 break;
44786 }
44787- *user_ptr = (void __user *)ctrls->controls;
44788+ *user_ptr = (void __force_user *)ctrls->controls;
44789 *kernel_ptr = (void *)&ctrls->controls;
44790 *array_size = sizeof(struct v4l2_ext_control)
44791 * ctrls->count;
44792@@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44793 }
44794
44795 if (has_array_args) {
44796- *kernel_ptr = user_ptr;
44797+ *kernel_ptr = (void __force_kernel *)user_ptr;
44798 if (copy_to_user(user_ptr, mbuf, array_size))
44799 err = -EFAULT;
44800 goto out_array_args;
44801diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44802index 570b18a..f880314 100644
44803--- a/drivers/message/fusion/mptbase.c
44804+++ b/drivers/message/fusion/mptbase.c
44805@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44806 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44807 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44808
44809+#ifdef CONFIG_GRKERNSEC_HIDESYM
44810+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44811+#else
44812 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44813 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44814+#endif
44815+
44816 /*
44817 * Rounding UP to nearest 4-kB boundary here...
44818 */
44819@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44820 ioc->facts.GlobalCredits);
44821
44822 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44823+#ifdef CONFIG_GRKERNSEC_HIDESYM
44824+ NULL, NULL);
44825+#else
44826 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44827+#endif
44828 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44829 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44830 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44831diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44832index 00d339c..2ea899d 100644
44833--- a/drivers/message/fusion/mptsas.c
44834+++ b/drivers/message/fusion/mptsas.c
44835@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44836 return 0;
44837 }
44838
44839+static inline void
44840+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44841+{
44842+ if (phy_info->port_details) {
44843+ phy_info->port_details->rphy = rphy;
44844+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44845+ ioc->name, rphy));
44846+ }
44847+
44848+ if (rphy) {
44849+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44850+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44851+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44852+ ioc->name, rphy, rphy->dev.release));
44853+ }
44854+}
44855+
44856 /* no mutex */
44857 static void
44858 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44859@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44860 return NULL;
44861 }
44862
44863-static inline void
44864-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44865-{
44866- if (phy_info->port_details) {
44867- phy_info->port_details->rphy = rphy;
44868- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44869- ioc->name, rphy));
44870- }
44871-
44872- if (rphy) {
44873- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44874- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44875- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44876- ioc->name, rphy, rphy->dev.release));
44877- }
44878-}
44879-
44880 static inline struct sas_port *
44881 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44882 {
44883diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44884index 727819c..ad74694 100644
44885--- a/drivers/message/fusion/mptscsih.c
44886+++ b/drivers/message/fusion/mptscsih.c
44887@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44888
44889 h = shost_priv(SChost);
44890
44891- if (h) {
44892- if (h->info_kbuf == NULL)
44893- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44894- return h->info_kbuf;
44895- h->info_kbuf[0] = '\0';
44896+ if (!h)
44897+ return NULL;
44898
44899- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44900- h->info_kbuf[size-1] = '\0';
44901- }
44902+ if (h->info_kbuf == NULL)
44903+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44904+ return h->info_kbuf;
44905+ h->info_kbuf[0] = '\0';
44906+
44907+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44908+ h->info_kbuf[size-1] = '\0';
44909
44910 return h->info_kbuf;
44911 }
44912diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44913index b7d87cd..3fb36da 100644
44914--- a/drivers/message/i2o/i2o_proc.c
44915+++ b/drivers/message/i2o/i2o_proc.c
44916@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44917 "Array Controller Device"
44918 };
44919
44920-static char *chtostr(char *tmp, u8 *chars, int n)
44921-{
44922- tmp[0] = 0;
44923- return strncat(tmp, (char *)chars, n);
44924-}
44925-
44926 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44927 char *group)
44928 {
44929@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44930 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44931 {
44932 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44933- static u32 work32[5];
44934- static u8 *work8 = (u8 *) work32;
44935- static u16 *work16 = (u16 *) work32;
44936+ u32 work32[5];
44937+ u8 *work8 = (u8 *) work32;
44938+ u16 *work16 = (u16 *) work32;
44939 int token;
44940 u32 hwcap;
44941
44942@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44943 } *result;
44944
44945 i2o_exec_execute_ddm_table ddm_table;
44946- char tmp[28 + 1];
44947
44948 result = kmalloc(sizeof(*result), GFP_KERNEL);
44949 if (!result)
44950@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44951
44952 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44953 seq_printf(seq, "%-#8x", ddm_table.module_id);
44954- seq_printf(seq, "%-29s",
44955- chtostr(tmp, ddm_table.module_name_version, 28));
44956+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44957 seq_printf(seq, "%9d ", ddm_table.data_size);
44958 seq_printf(seq, "%8d", ddm_table.code_size);
44959
44960@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44961
44962 i2o_driver_result_table *result;
44963 i2o_driver_store_table *dst;
44964- char tmp[28 + 1];
44965
44966 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44967 if (result == NULL)
44968@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44969
44970 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44971 seq_printf(seq, "%-#8x", dst->module_id);
44972- seq_printf(seq, "%-29s",
44973- chtostr(tmp, dst->module_name_version, 28));
44974- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44975+ seq_printf(seq, "%-.28s", dst->module_name_version);
44976+ seq_printf(seq, "%-.8s", dst->date);
44977 seq_printf(seq, "%8d ", dst->module_size);
44978 seq_printf(seq, "%8d ", dst->mpb_size);
44979 seq_printf(seq, "0x%04x", dst->module_flags);
44980@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44981 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44982 {
44983 struct i2o_device *d = (struct i2o_device *)seq->private;
44984- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44985+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44986 // == (allow) 512d bytes (max)
44987- static u16 *work16 = (u16 *) work32;
44988+ u16 *work16 = (u16 *) work32;
44989 int token;
44990- char tmp[16 + 1];
44991
44992 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44993
44994@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44995 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44996 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44997 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44998- seq_printf(seq, "Vendor info : %s\n",
44999- chtostr(tmp, (u8 *) (work32 + 2), 16));
45000- seq_printf(seq, "Product info : %s\n",
45001- chtostr(tmp, (u8 *) (work32 + 6), 16));
45002- seq_printf(seq, "Description : %s\n",
45003- chtostr(tmp, (u8 *) (work32 + 10), 16));
45004- seq_printf(seq, "Product rev. : %s\n",
45005- chtostr(tmp, (u8 *) (work32 + 14), 8));
45006+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45007+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45008+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45009+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45010
45011 seq_printf(seq, "Serial number : ");
45012 print_serial_number(seq, (u8 *) (work32 + 16),
45013@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45014 u8 pad[256]; // allow up to 256 byte (max) serial number
45015 } result;
45016
45017- char tmp[24 + 1];
45018-
45019 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45020
45021 if (token < 0) {
45022@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45023 }
45024
45025 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45026- seq_printf(seq, "Module name : %s\n",
45027- chtostr(tmp, result.module_name, 24));
45028- seq_printf(seq, "Module revision : %s\n",
45029- chtostr(tmp, result.module_rev, 8));
45030+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45031+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45032
45033 seq_printf(seq, "Serial number : ");
45034 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45035@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45036 u8 instance_number[4];
45037 } result;
45038
45039- char tmp[64 + 1];
45040-
45041 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45042
45043 if (token < 0) {
45044@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45045 return 0;
45046 }
45047
45048- seq_printf(seq, "Device name : %s\n",
45049- chtostr(tmp, result.device_name, 64));
45050- seq_printf(seq, "Service name : %s\n",
45051- chtostr(tmp, result.service_name, 64));
45052- seq_printf(seq, "Physical name : %s\n",
45053- chtostr(tmp, result.physical_location, 64));
45054- seq_printf(seq, "Instance number : %s\n",
45055- chtostr(tmp, result.instance_number, 4));
45056+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45057+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45058+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45059+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45060
45061 return 0;
45062 }
45063@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45064 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45065 {
45066 struct i2o_device *d = (struct i2o_device *)seq->private;
45067- static u32 work32[12];
45068- static u16 *work16 = (u16 *) work32;
45069- static u8 *work8 = (u8 *) work32;
45070+ u32 work32[12];
45071+ u16 *work16 = (u16 *) work32;
45072+ u8 *work8 = (u8 *) work32;
45073 int token;
45074
45075 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45076diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45077index 92752fb..a7494f6 100644
45078--- a/drivers/message/i2o/iop.c
45079+++ b/drivers/message/i2o/iop.c
45080@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45081
45082 spin_lock_irqsave(&c->context_list_lock, flags);
45083
45084- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45085- atomic_inc(&c->context_list_counter);
45086+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45087+ atomic_inc_unchecked(&c->context_list_counter);
45088
45089- entry->context = atomic_read(&c->context_list_counter);
45090+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45091
45092 list_add(&entry->list, &c->context_list);
45093
45094@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45095
45096 #if BITS_PER_LONG == 64
45097 spin_lock_init(&c->context_list_lock);
45098- atomic_set(&c->context_list_counter, 0);
45099+ atomic_set_unchecked(&c->context_list_counter, 0);
45100 INIT_LIST_HEAD(&c->context_list);
45101 #endif
45102
45103diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45104index d1a22aa..d0f7bf7 100644
45105--- a/drivers/mfd/ab8500-debugfs.c
45106+++ b/drivers/mfd/ab8500-debugfs.c
45107@@ -100,7 +100,7 @@ static int irq_last;
45108 static u32 *irq_count;
45109 static int num_irqs;
45110
45111-static struct device_attribute **dev_attr;
45112+static device_attribute_no_const **dev_attr;
45113 static char **event_name;
45114
45115 static u8 avg_sample = SAMPLE_16;
45116diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45117index a83eed5..62a58a9 100644
45118--- a/drivers/mfd/max8925-i2c.c
45119+++ b/drivers/mfd/max8925-i2c.c
45120@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45121 const struct i2c_device_id *id)
45122 {
45123 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45124- static struct max8925_chip *chip;
45125+ struct max8925_chip *chip;
45126 struct device_node *node = client->dev.of_node;
45127
45128 if (node && !pdata) {
45129diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45130index 460a014..21d3061 100644
45131--- a/drivers/mfd/tps65910.c
45132+++ b/drivers/mfd/tps65910.c
45133@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45134 struct tps65910_platform_data *pdata)
45135 {
45136 int ret = 0;
45137- static struct regmap_irq_chip *tps6591x_irqs_chip;
45138+ struct regmap_irq_chip *tps6591x_irqs_chip;
45139
45140 if (!irq) {
45141 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45142diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45143index 596b1f6..5b6ab74 100644
45144--- a/drivers/mfd/twl4030-irq.c
45145+++ b/drivers/mfd/twl4030-irq.c
45146@@ -34,6 +34,7 @@
45147 #include <linux/of.h>
45148 #include <linux/irqdomain.h>
45149 #include <linux/i2c/twl.h>
45150+#include <asm/pgtable.h>
45151
45152 #include "twl-core.h"
45153
45154@@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45155 * Install an irq handler for each of the SIH modules;
45156 * clone dummy irq_chip since PIH can't *do* anything
45157 */
45158- twl4030_irq_chip = dummy_irq_chip;
45159- twl4030_irq_chip.name = "twl4030";
45160+ pax_open_kernel();
45161+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45162+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45163
45164- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45165+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45166+ pax_close_kernel();
45167
45168 for (i = irq_base; i < irq_end; i++) {
45169 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45170diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45171index 464419b..64bae8d 100644
45172--- a/drivers/misc/c2port/core.c
45173+++ b/drivers/misc/c2port/core.c
45174@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45175 goto error_idr_alloc;
45176 c2dev->id = ret;
45177
45178- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45179+ pax_open_kernel();
45180+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45181+ pax_close_kernel();
45182
45183 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45184 "c2port%d", c2dev->id);
45185diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45186index 3f2b625..945e179 100644
45187--- a/drivers/misc/eeprom/sunxi_sid.c
45188+++ b/drivers/misc/eeprom/sunxi_sid.c
45189@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45190
45191 platform_set_drvdata(pdev, sid_data);
45192
45193- sid_bin_attr.size = sid_data->keysize;
45194+ pax_open_kernel();
45195+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45196+ pax_close_kernel();
45197 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45198 return -ENODEV;
45199
45200diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45201index 36f5d52..32311c3 100644
45202--- a/drivers/misc/kgdbts.c
45203+++ b/drivers/misc/kgdbts.c
45204@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45205 char before[BREAK_INSTR_SIZE];
45206 char after[BREAK_INSTR_SIZE];
45207
45208- probe_kernel_read(before, (char *)kgdbts_break_test,
45209+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45210 BREAK_INSTR_SIZE);
45211 init_simple_test();
45212 ts.tst = plant_and_detach_test;
45213@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45214 /* Activate test with initial breakpoint */
45215 if (!is_early)
45216 kgdb_breakpoint();
45217- probe_kernel_read(after, (char *)kgdbts_break_test,
45218+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45219 BREAK_INSTR_SIZE);
45220 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45221 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45222diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45223index 3ef4627..8d00486 100644
45224--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45225+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45226@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45227 * the lid is closed. This leads to interrupts as soon as a little move
45228 * is done.
45229 */
45230- atomic_inc(&lis3->count);
45231+ atomic_inc_unchecked(&lis3->count);
45232
45233 wake_up_interruptible(&lis3->misc_wait);
45234 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45235@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45236 if (lis3->pm_dev)
45237 pm_runtime_get_sync(lis3->pm_dev);
45238
45239- atomic_set(&lis3->count, 0);
45240+ atomic_set_unchecked(&lis3->count, 0);
45241 return 0;
45242 }
45243
45244@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45245 add_wait_queue(&lis3->misc_wait, &wait);
45246 while (true) {
45247 set_current_state(TASK_INTERRUPTIBLE);
45248- data = atomic_xchg(&lis3->count, 0);
45249+ data = atomic_xchg_unchecked(&lis3->count, 0);
45250 if (data)
45251 break;
45252
45253@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45254 struct lis3lv02d, miscdev);
45255
45256 poll_wait(file, &lis3->misc_wait, wait);
45257- if (atomic_read(&lis3->count))
45258+ if (atomic_read_unchecked(&lis3->count))
45259 return POLLIN | POLLRDNORM;
45260 return 0;
45261 }
45262diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45263index c439c82..1f20f57 100644
45264--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45265+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45266@@ -297,7 +297,7 @@ struct lis3lv02d {
45267 struct input_polled_dev *idev; /* input device */
45268 struct platform_device *pdev; /* platform device */
45269 struct regulator_bulk_data regulators[2];
45270- atomic_t count; /* interrupt count after last read */
45271+ atomic_unchecked_t count; /* interrupt count after last read */
45272 union axis_conversion ac; /* hw -> logical axis */
45273 int mapped_btns[3];
45274
45275diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45276index 2f30bad..c4c13d0 100644
45277--- a/drivers/misc/sgi-gru/gruhandles.c
45278+++ b/drivers/misc/sgi-gru/gruhandles.c
45279@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45280 unsigned long nsec;
45281
45282 nsec = CLKS2NSEC(clks);
45283- atomic_long_inc(&mcs_op_statistics[op].count);
45284- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45285+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45286+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45287 if (mcs_op_statistics[op].max < nsec)
45288 mcs_op_statistics[op].max = nsec;
45289 }
45290diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45291index 4f76359..cdfcb2e 100644
45292--- a/drivers/misc/sgi-gru/gruprocfs.c
45293+++ b/drivers/misc/sgi-gru/gruprocfs.c
45294@@ -32,9 +32,9 @@
45295
45296 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45297
45298-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45299+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45300 {
45301- unsigned long val = atomic_long_read(v);
45302+ unsigned long val = atomic_long_read_unchecked(v);
45303
45304 seq_printf(s, "%16lu %s\n", val, id);
45305 }
45306@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45307
45308 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45309 for (op = 0; op < mcsop_last; op++) {
45310- count = atomic_long_read(&mcs_op_statistics[op].count);
45311- total = atomic_long_read(&mcs_op_statistics[op].total);
45312+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45313+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45314 max = mcs_op_statistics[op].max;
45315 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45316 count ? total / count : 0, max);
45317diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45318index 5c3ce24..4915ccb 100644
45319--- a/drivers/misc/sgi-gru/grutables.h
45320+++ b/drivers/misc/sgi-gru/grutables.h
45321@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45322 * GRU statistics.
45323 */
45324 struct gru_stats_s {
45325- atomic_long_t vdata_alloc;
45326- atomic_long_t vdata_free;
45327- atomic_long_t gts_alloc;
45328- atomic_long_t gts_free;
45329- atomic_long_t gms_alloc;
45330- atomic_long_t gms_free;
45331- atomic_long_t gts_double_allocate;
45332- atomic_long_t assign_context;
45333- atomic_long_t assign_context_failed;
45334- atomic_long_t free_context;
45335- atomic_long_t load_user_context;
45336- atomic_long_t load_kernel_context;
45337- atomic_long_t lock_kernel_context;
45338- atomic_long_t unlock_kernel_context;
45339- atomic_long_t steal_user_context;
45340- atomic_long_t steal_kernel_context;
45341- atomic_long_t steal_context_failed;
45342- atomic_long_t nopfn;
45343- atomic_long_t asid_new;
45344- atomic_long_t asid_next;
45345- atomic_long_t asid_wrap;
45346- atomic_long_t asid_reuse;
45347- atomic_long_t intr;
45348- atomic_long_t intr_cbr;
45349- atomic_long_t intr_tfh;
45350- atomic_long_t intr_spurious;
45351- atomic_long_t intr_mm_lock_failed;
45352- atomic_long_t call_os;
45353- atomic_long_t call_os_wait_queue;
45354- atomic_long_t user_flush_tlb;
45355- atomic_long_t user_unload_context;
45356- atomic_long_t user_exception;
45357- atomic_long_t set_context_option;
45358- atomic_long_t check_context_retarget_intr;
45359- atomic_long_t check_context_unload;
45360- atomic_long_t tlb_dropin;
45361- atomic_long_t tlb_preload_page;
45362- atomic_long_t tlb_dropin_fail_no_asid;
45363- atomic_long_t tlb_dropin_fail_upm;
45364- atomic_long_t tlb_dropin_fail_invalid;
45365- atomic_long_t tlb_dropin_fail_range_active;
45366- atomic_long_t tlb_dropin_fail_idle;
45367- atomic_long_t tlb_dropin_fail_fmm;
45368- atomic_long_t tlb_dropin_fail_no_exception;
45369- atomic_long_t tfh_stale_on_fault;
45370- atomic_long_t mmu_invalidate_range;
45371- atomic_long_t mmu_invalidate_page;
45372- atomic_long_t flush_tlb;
45373- atomic_long_t flush_tlb_gru;
45374- atomic_long_t flush_tlb_gru_tgh;
45375- atomic_long_t flush_tlb_gru_zero_asid;
45376+ atomic_long_unchecked_t vdata_alloc;
45377+ atomic_long_unchecked_t vdata_free;
45378+ atomic_long_unchecked_t gts_alloc;
45379+ atomic_long_unchecked_t gts_free;
45380+ atomic_long_unchecked_t gms_alloc;
45381+ atomic_long_unchecked_t gms_free;
45382+ atomic_long_unchecked_t gts_double_allocate;
45383+ atomic_long_unchecked_t assign_context;
45384+ atomic_long_unchecked_t assign_context_failed;
45385+ atomic_long_unchecked_t free_context;
45386+ atomic_long_unchecked_t load_user_context;
45387+ atomic_long_unchecked_t load_kernel_context;
45388+ atomic_long_unchecked_t lock_kernel_context;
45389+ atomic_long_unchecked_t unlock_kernel_context;
45390+ atomic_long_unchecked_t steal_user_context;
45391+ atomic_long_unchecked_t steal_kernel_context;
45392+ atomic_long_unchecked_t steal_context_failed;
45393+ atomic_long_unchecked_t nopfn;
45394+ atomic_long_unchecked_t asid_new;
45395+ atomic_long_unchecked_t asid_next;
45396+ atomic_long_unchecked_t asid_wrap;
45397+ atomic_long_unchecked_t asid_reuse;
45398+ atomic_long_unchecked_t intr;
45399+ atomic_long_unchecked_t intr_cbr;
45400+ atomic_long_unchecked_t intr_tfh;
45401+ atomic_long_unchecked_t intr_spurious;
45402+ atomic_long_unchecked_t intr_mm_lock_failed;
45403+ atomic_long_unchecked_t call_os;
45404+ atomic_long_unchecked_t call_os_wait_queue;
45405+ atomic_long_unchecked_t user_flush_tlb;
45406+ atomic_long_unchecked_t user_unload_context;
45407+ atomic_long_unchecked_t user_exception;
45408+ atomic_long_unchecked_t set_context_option;
45409+ atomic_long_unchecked_t check_context_retarget_intr;
45410+ atomic_long_unchecked_t check_context_unload;
45411+ atomic_long_unchecked_t tlb_dropin;
45412+ atomic_long_unchecked_t tlb_preload_page;
45413+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45414+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45415+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45416+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45417+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45418+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45419+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45420+ atomic_long_unchecked_t tfh_stale_on_fault;
45421+ atomic_long_unchecked_t mmu_invalidate_range;
45422+ atomic_long_unchecked_t mmu_invalidate_page;
45423+ atomic_long_unchecked_t flush_tlb;
45424+ atomic_long_unchecked_t flush_tlb_gru;
45425+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45426+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45427
45428- atomic_long_t copy_gpa;
45429- atomic_long_t read_gpa;
45430+ atomic_long_unchecked_t copy_gpa;
45431+ atomic_long_unchecked_t read_gpa;
45432
45433- atomic_long_t mesq_receive;
45434- atomic_long_t mesq_receive_none;
45435- atomic_long_t mesq_send;
45436- atomic_long_t mesq_send_failed;
45437- atomic_long_t mesq_noop;
45438- atomic_long_t mesq_send_unexpected_error;
45439- atomic_long_t mesq_send_lb_overflow;
45440- atomic_long_t mesq_send_qlimit_reached;
45441- atomic_long_t mesq_send_amo_nacked;
45442- atomic_long_t mesq_send_put_nacked;
45443- atomic_long_t mesq_page_overflow;
45444- atomic_long_t mesq_qf_locked;
45445- atomic_long_t mesq_qf_noop_not_full;
45446- atomic_long_t mesq_qf_switch_head_failed;
45447- atomic_long_t mesq_qf_unexpected_error;
45448- atomic_long_t mesq_noop_unexpected_error;
45449- atomic_long_t mesq_noop_lb_overflow;
45450- atomic_long_t mesq_noop_qlimit_reached;
45451- atomic_long_t mesq_noop_amo_nacked;
45452- atomic_long_t mesq_noop_put_nacked;
45453- atomic_long_t mesq_noop_page_overflow;
45454+ atomic_long_unchecked_t mesq_receive;
45455+ atomic_long_unchecked_t mesq_receive_none;
45456+ atomic_long_unchecked_t mesq_send;
45457+ atomic_long_unchecked_t mesq_send_failed;
45458+ atomic_long_unchecked_t mesq_noop;
45459+ atomic_long_unchecked_t mesq_send_unexpected_error;
45460+ atomic_long_unchecked_t mesq_send_lb_overflow;
45461+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45462+ atomic_long_unchecked_t mesq_send_amo_nacked;
45463+ atomic_long_unchecked_t mesq_send_put_nacked;
45464+ atomic_long_unchecked_t mesq_page_overflow;
45465+ atomic_long_unchecked_t mesq_qf_locked;
45466+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45467+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45468+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45469+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45470+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45471+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45472+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45473+ atomic_long_unchecked_t mesq_noop_put_nacked;
45474+ atomic_long_unchecked_t mesq_noop_page_overflow;
45475
45476 };
45477
45478@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45479 tghop_invalidate, mcsop_last};
45480
45481 struct mcs_op_statistic {
45482- atomic_long_t count;
45483- atomic_long_t total;
45484+ atomic_long_unchecked_t count;
45485+ atomic_long_unchecked_t total;
45486 unsigned long max;
45487 };
45488
45489@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45490
45491 #define STAT(id) do { \
45492 if (gru_options & OPT_STATS) \
45493- atomic_long_inc(&gru_stats.id); \
45494+ atomic_long_inc_unchecked(&gru_stats.id); \
45495 } while (0)
45496
45497 #ifdef CONFIG_SGI_GRU_DEBUG
45498diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45499index c862cd4..0d176fe 100644
45500--- a/drivers/misc/sgi-xp/xp.h
45501+++ b/drivers/misc/sgi-xp/xp.h
45502@@ -288,7 +288,7 @@ struct xpc_interface {
45503 xpc_notify_func, void *);
45504 void (*received) (short, int, void *);
45505 enum xp_retval (*partid_to_nasids) (short, void *);
45506-};
45507+} __no_const;
45508
45509 extern struct xpc_interface xpc_interface;
45510
45511diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45512index 01be66d..e3a0c7e 100644
45513--- a/drivers/misc/sgi-xp/xp_main.c
45514+++ b/drivers/misc/sgi-xp/xp_main.c
45515@@ -78,13 +78,13 @@ xpc_notloaded(void)
45516 }
45517
45518 struct xpc_interface xpc_interface = {
45519- (void (*)(int))xpc_notloaded,
45520- (void (*)(int))xpc_notloaded,
45521- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45522- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45523+ .connect = (void (*)(int))xpc_notloaded,
45524+ .disconnect = (void (*)(int))xpc_notloaded,
45525+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45526+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45527 void *))xpc_notloaded,
45528- (void (*)(short, int, void *))xpc_notloaded,
45529- (enum xp_retval(*)(short, void *))xpc_notloaded
45530+ .received = (void (*)(short, int, void *))xpc_notloaded,
45531+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45532 };
45533 EXPORT_SYMBOL_GPL(xpc_interface);
45534
45535diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45536index b94d5f7..7f494c5 100644
45537--- a/drivers/misc/sgi-xp/xpc.h
45538+++ b/drivers/misc/sgi-xp/xpc.h
45539@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45540 void (*received_payload) (struct xpc_channel *, void *);
45541 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45542 };
45543+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45544
45545 /* struct xpc_partition act_state values (for XPC HB) */
45546
45547@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45548 /* found in xpc_main.c */
45549 extern struct device *xpc_part;
45550 extern struct device *xpc_chan;
45551-extern struct xpc_arch_operations xpc_arch_ops;
45552+extern xpc_arch_operations_no_const xpc_arch_ops;
45553 extern int xpc_disengage_timelimit;
45554 extern int xpc_disengage_timedout;
45555 extern int xpc_activate_IRQ_rcvd;
45556diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45557index 82dc574..8539ab2 100644
45558--- a/drivers/misc/sgi-xp/xpc_main.c
45559+++ b/drivers/misc/sgi-xp/xpc_main.c
45560@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45561 .notifier_call = xpc_system_die,
45562 };
45563
45564-struct xpc_arch_operations xpc_arch_ops;
45565+xpc_arch_operations_no_const xpc_arch_ops;
45566
45567 /*
45568 * Timer function to enforce the timelimit on the partition disengage.
45569@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45570
45571 if (((die_args->trapnr == X86_TRAP_MF) ||
45572 (die_args->trapnr == X86_TRAP_XF)) &&
45573- !user_mode_vm(die_args->regs))
45574+ !user_mode(die_args->regs))
45575 xpc_die_deactivate();
45576
45577 break;
45578diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45579index 452782b..0c10e40 100644
45580--- a/drivers/mmc/card/block.c
45581+++ b/drivers/mmc/card/block.c
45582@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45583 if (idata->ic.postsleep_min_us)
45584 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45585
45586- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45587+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45588 err = -EFAULT;
45589 goto cmd_rel_host;
45590 }
45591diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45592index f51b5ba..86614a7 100644
45593--- a/drivers/mmc/core/mmc_ops.c
45594+++ b/drivers/mmc/core/mmc_ops.c
45595@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45596 void *data_buf;
45597 int is_on_stack;
45598
45599- is_on_stack = object_is_on_stack(buf);
45600+ is_on_stack = object_starts_on_stack(buf);
45601 if (is_on_stack) {
45602 /*
45603 * dma onto stack is unsafe/nonportable, but callers to this
45604diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45605index 6834977..824ee1b 100644
45606--- a/drivers/mmc/host/dw_mmc.h
45607+++ b/drivers/mmc/host/dw_mmc.h
45608@@ -259,5 +259,5 @@ struct dw_mci_drv_data {
45609 int (*parse_dt)(struct dw_mci *host);
45610 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45611 struct dw_mci_tuning_data *tuning_data);
45612-};
45613+} __do_const;
45614 #endif /* _DW_MMC_H_ */
45615diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45616index 771c60a..12cb615 100644
45617--- a/drivers/mmc/host/mmci.c
45618+++ b/drivers/mmc/host/mmci.c
45619@@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
45620 mmc->caps2 = plat->capabilities2;
45621
45622 if (variant->busy_detect) {
45623- mmci_ops.card_busy = mmci_card_busy;
45624+ pax_open_kernel();
45625+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45626+ pax_close_kernel();
45627 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45628 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
45629 mmc->max_busy_timeout = 0;
45630diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45631index b841bb7..d82712f5 100644
45632--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45633+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45634@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45635 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45636 }
45637
45638- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45639- sdhci_esdhc_ops.platform_execute_tuning =
45640+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45641+ pax_open_kernel();
45642+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45643 esdhc_executing_tuning;
45644+ pax_close_kernel();
45645+ }
45646
45647 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45648 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45649diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45650index d61eb5a..88c0f5d 100644
45651--- a/drivers/mmc/host/sdhci-s3c.c
45652+++ b/drivers/mmc/host/sdhci-s3c.c
45653@@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45654 * we can use overriding functions instead of default.
45655 */
45656 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45657- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45658- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45659- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45660+ pax_open_kernel();
45661+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45662+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45663+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45664+ pax_close_kernel();
45665 }
45666
45667 /* It supports additional host capabilities if needed */
45668diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45669index 6293855..3415551 100644
45670--- a/drivers/mtd/chips/cfi_cmdset_0020.c
45671+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45672@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45673 size_t totlen = 0, thislen;
45674 int ret = 0;
45675 size_t buflen = 0;
45676- static char *buffer;
45677+ char *buffer;
45678
45679 if (!ECCBUF_SIZE) {
45680 /* We should fall back to a general writev implementation.
45681diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45682index c07cd57..61c4fbd 100644
45683--- a/drivers/mtd/nand/denali.c
45684+++ b/drivers/mtd/nand/denali.c
45685@@ -24,6 +24,7 @@
45686 #include <linux/slab.h>
45687 #include <linux/mtd/mtd.h>
45688 #include <linux/module.h>
45689+#include <linux/slab.h>
45690
45691 #include "denali.h"
45692
45693diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45694index bb77f75..47539b1 100644
45695--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45696+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45697@@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45698
45699 /* first try to map the upper buffer directly */
45700 if (virt_addr_valid(this->upper_buf) &&
45701- !object_is_on_stack(this->upper_buf)) {
45702+ !object_starts_on_stack(this->upper_buf)) {
45703 sg_init_one(sgl, this->upper_buf, this->upper_len);
45704 ret = dma_map_sg(this->dev, sgl, 1, dr);
45705 if (ret == 0)
45706diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45707index 51b9d6a..52af9a7 100644
45708--- a/drivers/mtd/nftlmount.c
45709+++ b/drivers/mtd/nftlmount.c
45710@@ -24,6 +24,7 @@
45711 #include <asm/errno.h>
45712 #include <linux/delay.h>
45713 #include <linux/slab.h>
45714+#include <linux/sched.h>
45715 #include <linux/mtd/mtd.h>
45716 #include <linux/mtd/nand.h>
45717 #include <linux/mtd/nftl.h>
45718diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45719index cf49c22..971b133 100644
45720--- a/drivers/mtd/sm_ftl.c
45721+++ b/drivers/mtd/sm_ftl.c
45722@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45723 #define SM_CIS_VENDOR_OFFSET 0x59
45724 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45725 {
45726- struct attribute_group *attr_group;
45727+ attribute_group_no_const *attr_group;
45728 struct attribute **attributes;
45729 struct sm_sysfs_attribute *vendor_attribute;
45730 char *vendor;
45731diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45732index d3a6789..198ec21 100644
45733--- a/drivers/net/bonding/bond_main.c
45734+++ b/drivers/net/bonding/bond_main.c
45735@@ -4504,6 +4504,7 @@ static void __exit bonding_exit(void)
45736
45737 bond_netlink_fini();
45738 unregister_pernet_subsys(&bond_net_ops);
45739+ rtnl_link_unregister(&bond_link_ops);
45740
45741 #ifdef CONFIG_NET_POLL_CONTROLLER
45742 /*
45743diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45744index f847e16..fc8dbe9 100644
45745--- a/drivers/net/bonding/bond_netlink.c
45746+++ b/drivers/net/bonding/bond_netlink.c
45747@@ -542,7 +542,7 @@ nla_put_failure:
45748 return -EMSGSIZE;
45749 }
45750
45751-struct rtnl_link_ops bond_link_ops __read_mostly = {
45752+struct rtnl_link_ops bond_link_ops = {
45753 .kind = "bond",
45754 .priv_size = sizeof(struct bonding),
45755 .setup = bond_setup,
45756diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45757index 9e7d95d..d447b88 100644
45758--- a/drivers/net/can/Kconfig
45759+++ b/drivers/net/can/Kconfig
45760@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45761
45762 config CAN_FLEXCAN
45763 tristate "Support for Freescale FLEXCAN based chips"
45764- depends on ARM || PPC
45765+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45766 ---help---
45767 Say Y here if you want to support for Freescale FlexCAN.
45768
45769diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45770index 455d4c3..3353ee7 100644
45771--- a/drivers/net/ethernet/8390/ax88796.c
45772+++ b/drivers/net/ethernet/8390/ax88796.c
45773@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45774 if (ax->plat->reg_offsets)
45775 ei_local->reg_offset = ax->plat->reg_offsets;
45776 else {
45777+ resource_size_t _mem_size = mem_size;
45778+ do_div(_mem_size, 0x18);
45779 ei_local->reg_offset = ax->reg_offsets;
45780 for (ret = 0; ret < 0x18; ret++)
45781- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45782+ ax->reg_offsets[ret] = _mem_size * ret;
45783 }
45784
45785 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45786diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
45787index 7330681..7e9e463 100644
45788--- a/drivers/net/ethernet/altera/altera_tse_main.c
45789+++ b/drivers/net/ethernet/altera/altera_tse_main.c
45790@@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
45791 return 0;
45792 }
45793
45794-static struct net_device_ops altera_tse_netdev_ops = {
45795+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
45796 .ndo_open = tse_open,
45797 .ndo_stop = tse_shutdown,
45798 .ndo_start_xmit = tse_start_xmit,
45799@@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
45800 ndev->netdev_ops = &altera_tse_netdev_ops;
45801 altera_tse_set_ethtool_ops(ndev);
45802
45803+ pax_open_kernel();
45804 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
45805
45806 if (priv->hash_filter)
45807 altera_tse_netdev_ops.ndo_set_rx_mode =
45808 tse_set_rx_mode_hashfilter;
45809+ pax_close_kernel();
45810
45811 /* Scatter/gather IO is not supported,
45812 * so it is turned off
45813diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45814index 3448cc0..67b2dc4 100644
45815--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45816+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45817@@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45818 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45819 {
45820 /* RX_MODE controlling object */
45821- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45822+ bnx2x_init_rx_mode_obj(bp);
45823
45824 /* multicast configuration controlling object */
45825 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45826diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45827index 31297266..944cf6e 100644
45828--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45829+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45830@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45831 return rc;
45832 }
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 if (CHIP_IS_E1x(bp)) {
45839- o->wait_comp = bnx2x_empty_rx_mode_wait;
45840- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45841+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45842+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45843 } else {
45844- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45845- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45846+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45847+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45848 }
45849 }
45850
45851diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45852index 80f6c79..fb7d12d 100644
45853--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45854+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45855@@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45856
45857 /********************* RX MODE ****************/
45858
45859-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45860- struct bnx2x_rx_mode_obj *o);
45861+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45862
45863 /**
45864 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45865diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45866index 04321e5..b51cdc4 100644
45867--- a/drivers/net/ethernet/broadcom/tg3.h
45868+++ b/drivers/net/ethernet/broadcom/tg3.h
45869@@ -150,6 +150,7 @@
45870 #define CHIPREV_ID_5750_A0 0x4000
45871 #define CHIPREV_ID_5750_A1 0x4001
45872 #define CHIPREV_ID_5750_A3 0x4003
45873+#define CHIPREV_ID_5750_C1 0x4201
45874 #define CHIPREV_ID_5750_C2 0x4202
45875 #define CHIPREV_ID_5752_A0_HW 0x5000
45876 #define CHIPREV_ID_5752_A0 0x6000
45877diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45878index 13f9636..228040f 100644
45879--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45880+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45881@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45882 }
45883
45884 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45885- bna_cb_ioceth_enable,
45886- bna_cb_ioceth_disable,
45887- bna_cb_ioceth_hbfail,
45888- bna_cb_ioceth_reset
45889+ .enable_cbfn = bna_cb_ioceth_enable,
45890+ .disable_cbfn = bna_cb_ioceth_disable,
45891+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45892+ .reset_cbfn = bna_cb_ioceth_reset
45893 };
45894
45895 static void bna_attr_init(struct bna_ioceth *ioceth)
45896diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45897index 8cffcdf..aadf043 100644
45898--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45899+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45900@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45901 */
45902 struct l2t_skb_cb {
45903 arp_failure_handler_func arp_failure_handler;
45904-};
45905+} __no_const;
45906
45907 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45908
45909diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45910index 24e16e3..bfe6ef2 100644
45911--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45912+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45913@@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45914
45915 int i;
45916 struct adapter *ap = netdev2adap(dev);
45917- static const unsigned int *reg_ranges;
45918+ const unsigned int *reg_ranges;
45919 int arr_size = 0, buf_size = 0;
45920
45921 if (is_t4(ap->params.chip)) {
45922diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45923index c05b66d..ed69872 100644
45924--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45925+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45926@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45927 for (i=0; i<ETH_ALEN; i++) {
45928 tmp.addr[i] = dev->dev_addr[i];
45929 }
45930- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45931+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45932 break;
45933
45934 case DE4X5_SET_HWADDR: /* Set the hardware address */
45935@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45936 spin_lock_irqsave(&lp->lock, flags);
45937 memcpy(&statbuf, &lp->pktStats, ioc->len);
45938 spin_unlock_irqrestore(&lp->lock, flags);
45939- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45940+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45941 return -EFAULT;
45942 break;
45943 }
45944diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45945index dc19bc5..f2d4548 100644
45946--- a/drivers/net/ethernet/emulex/benet/be_main.c
45947+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45948@@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45949
45950 if (wrapped)
45951 newacc += 65536;
45952- ACCESS_ONCE(*acc) = newacc;
45953+ ACCESS_ONCE_RW(*acc) = newacc;
45954 }
45955
45956 static void populate_erx_stats(struct be_adapter *adapter,
45957diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45958index 68069ea..c4484f6 100644
45959--- a/drivers/net/ethernet/faraday/ftgmac100.c
45960+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45961@@ -30,6 +30,8 @@
45962 #include <linux/netdevice.h>
45963 #include <linux/phy.h>
45964 #include <linux/platform_device.h>
45965+#include <linux/interrupt.h>
45966+#include <linux/irqreturn.h>
45967 #include <net/ip.h>
45968
45969 #include "ftgmac100.h"
45970diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45971index 8be5b40..081bc1b 100644
45972--- a/drivers/net/ethernet/faraday/ftmac100.c
45973+++ b/drivers/net/ethernet/faraday/ftmac100.c
45974@@ -31,6 +31,8 @@
45975 #include <linux/module.h>
45976 #include <linux/netdevice.h>
45977 #include <linux/platform_device.h>
45978+#include <linux/interrupt.h>
45979+#include <linux/irqreturn.h>
45980
45981 #include "ftmac100.h"
45982
45983diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45984index e61e637..9117795 100644
45985--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45986+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45987@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
45988 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
45989
45990 /* Update the base adjustement value. */
45991- ACCESS_ONCE(pf->ptp_base_adj) = incval;
45992+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
45993 smp_mb(); /* Force the above update. */
45994 }
45995
45996diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45997index 8902ae6..e7bcdce 100644
45998--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45999+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46000@@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46001 }
46002
46003 /* update the base incval used to calculate frequency adjustment */
46004- ACCESS_ONCE(adapter->base_incval) = incval;
46005+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
46006 smp_mb();
46007
46008 /* need lock to prevent incorrect read while modifying cyclecounter */
46009diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46010index 089b713..28d87ae 100644
46011--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46012+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46013@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46014 struct __vxge_hw_fifo *fifo;
46015 struct vxge_hw_fifo_config *config;
46016 u32 txdl_size, txdl_per_memblock;
46017- struct vxge_hw_mempool_cbs fifo_mp_callback;
46018+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46019+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46020+ };
46021+
46022 struct __vxge_hw_virtualpath *vpath;
46023
46024 if ((vp == NULL) || (attr == NULL)) {
46025@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46026 goto exit;
46027 }
46028
46029- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46030-
46031 fifo->mempool =
46032 __vxge_hw_mempool_create(vpath->hldev,
46033 fifo->config->memblock_size,
46034diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46035index ba20c72..f30c0fe 100644
46036--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46037+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46038@@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46039 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46040 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46041 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46042- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46043+ pax_open_kernel();
46044+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46045+ pax_close_kernel();
46046 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46047 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46048 max_tx_rings = QLCNIC_MAX_TX_RINGS;
46049diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46050index be7d7a6..a8983f8 100644
46051--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46052+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46053@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46054 case QLCNIC_NON_PRIV_FUNC:
46055 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46056 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46057- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46058+ pax_open_kernel();
46059+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46060+ pax_close_kernel();
46061 break;
46062 case QLCNIC_PRIV_FUNC:
46063 ahw->op_mode = QLCNIC_PRIV_FUNC;
46064 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46065- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46066+ pax_open_kernel();
46067+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46068+ pax_close_kernel();
46069 break;
46070 case QLCNIC_MGMT_FUNC:
46071 ahw->op_mode = QLCNIC_MGMT_FUNC;
46072 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46073- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46074+ pax_open_kernel();
46075+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46076+ pax_close_kernel();
46077 break;
46078 default:
46079 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46080diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46081index 37b979b..50f5b95 100644
46082--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46083+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46084@@ -1217,7 +1217,7 @@ flash_temp:
46085 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46086 {
46087 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46088- static const struct qlcnic_dump_operations *fw_dump_ops;
46089+ const struct qlcnic_dump_operations *fw_dump_ops;
46090 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46091 u32 entry_offset, dump, no_entries, buf_offset = 0;
46092 int i, k, ops_cnt, ops_index, dump_size = 0;
46093diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46094index aa1c079..2b1a3e8 100644
46095--- a/drivers/net/ethernet/realtek/r8169.c
46096+++ b/drivers/net/ethernet/realtek/r8169.c
46097@@ -758,22 +758,22 @@ struct rtl8169_private {
46098 struct mdio_ops {
46099 void (*write)(struct rtl8169_private *, int, int);
46100 int (*read)(struct rtl8169_private *, int);
46101- } mdio_ops;
46102+ } __no_const mdio_ops;
46103
46104 struct pll_power_ops {
46105 void (*down)(struct rtl8169_private *);
46106 void (*up)(struct rtl8169_private *);
46107- } pll_power_ops;
46108+ } __no_const pll_power_ops;
46109
46110 struct jumbo_ops {
46111 void (*enable)(struct rtl8169_private *);
46112 void (*disable)(struct rtl8169_private *);
46113- } jumbo_ops;
46114+ } __no_const jumbo_ops;
46115
46116 struct csi_ops {
46117 void (*write)(struct rtl8169_private *, int, int);
46118 u32 (*read)(struct rtl8169_private *, int);
46119- } csi_ops;
46120+ } __no_const csi_ops;
46121
46122 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46123 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46124diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46125index 6b861e3..204ac86 100644
46126--- a/drivers/net/ethernet/sfc/ptp.c
46127+++ b/drivers/net/ethernet/sfc/ptp.c
46128@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46129 ptp->start.dma_addr);
46130
46131 /* Clear flag that signals MC ready */
46132- ACCESS_ONCE(*start) = 0;
46133+ ACCESS_ONCE_RW(*start) = 0;
46134 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46135 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46136 EFX_BUG_ON_PARANOID(rc);
46137diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46138index 50617c5..b13724c 100644
46139--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46140+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46141@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46142
46143 writel(value, ioaddr + MMC_CNTRL);
46144
46145- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46146- MMC_CNTRL, value);
46147+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46148+// MMC_CNTRL, value);
46149 }
46150
46151 /* To mask all all interrupts.*/
46152diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46153index d18f711d..5755800 100644
46154--- a/drivers/net/hyperv/hyperv_net.h
46155+++ b/drivers/net/hyperv/hyperv_net.h
46156@@ -101,7 +101,7 @@ struct rndis_device {
46157
46158 enum rndis_device_state state;
46159 bool link_state;
46160- atomic_t new_req_id;
46161+ atomic_unchecked_t new_req_id;
46162
46163 spinlock_t request_lock;
46164 struct list_head req_list;
46165diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46166index 143a98c..d54fbaa 100644
46167--- a/drivers/net/hyperv/rndis_filter.c
46168+++ b/drivers/net/hyperv/rndis_filter.c
46169@@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46170 * template
46171 */
46172 set = &rndis_msg->msg.set_req;
46173- set->req_id = atomic_inc_return(&dev->new_req_id);
46174+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46175
46176 /* Add to the request list */
46177 spin_lock_irqsave(&dev->request_lock, flags);
46178@@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46179
46180 /* Setup the rndis set */
46181 halt = &request->request_msg.msg.halt_req;
46182- halt->req_id = atomic_inc_return(&dev->new_req_id);
46183+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46184
46185 /* Ignore return since this msg is optional. */
46186 rndis_filter_send_request(dev, request);
46187diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46188index 78f18be..1d19c62 100644
46189--- a/drivers/net/ieee802154/fakehard.c
46190+++ b/drivers/net/ieee802154/fakehard.c
46191@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46192 phy->transmit_power = 0xbf;
46193
46194 dev->netdev_ops = &fake_ops;
46195- dev->ml_priv = &fake_mlme;
46196+ dev->ml_priv = (void *)&fake_mlme;
46197
46198 priv = netdev_priv(dev);
46199 priv->phy = phy;
46200diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46201index 7eec598..90b8428 100644
46202--- a/drivers/net/macvlan.c
46203+++ b/drivers/net/macvlan.c
46204@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46205 int macvlan_link_register(struct rtnl_link_ops *ops)
46206 {
46207 /* common fields */
46208- ops->priv_size = sizeof(struct macvlan_dev);
46209- ops->validate = macvlan_validate;
46210- ops->maxtype = IFLA_MACVLAN_MAX;
46211- ops->policy = macvlan_policy;
46212- ops->changelink = macvlan_changelink;
46213- ops->get_size = macvlan_get_size;
46214- ops->fill_info = macvlan_fill_info;
46215+ pax_open_kernel();
46216+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46217+ *(void **)&ops->validate = macvlan_validate;
46218+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46219+ *(const void **)&ops->policy = macvlan_policy;
46220+ *(void **)&ops->changelink = macvlan_changelink;
46221+ *(void **)&ops->get_size = macvlan_get_size;
46222+ *(void **)&ops->fill_info = macvlan_fill_info;
46223+ pax_close_kernel();
46224
46225 return rtnl_link_register(ops);
46226 };
46227@@ -1044,7 +1046,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46228 return NOTIFY_DONE;
46229 }
46230
46231-static struct notifier_block macvlan_notifier_block __read_mostly = {
46232+static struct notifier_block macvlan_notifier_block = {
46233 .notifier_call = macvlan_device_event,
46234 };
46235
46236diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46237index 3381c4f..dea5fd5 100644
46238--- a/drivers/net/macvtap.c
46239+++ b/drivers/net/macvtap.c
46240@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46241 }
46242
46243 ret = 0;
46244- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46245+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46246 put_user(q->flags, &ifr->ifr_flags))
46247 ret = -EFAULT;
46248 macvtap_put_vlan(vlan);
46249@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46250 return NOTIFY_DONE;
46251 }
46252
46253-static struct notifier_block macvtap_notifier_block __read_mostly = {
46254+static struct notifier_block macvtap_notifier_block = {
46255 .notifier_call = macvtap_device_event,
46256 };
46257
46258diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46259index daec9b0..6428fcb 100644
46260--- a/drivers/net/phy/mdio-bitbang.c
46261+++ b/drivers/net/phy/mdio-bitbang.c
46262@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46263 struct mdiobb_ctrl *ctrl = bus->priv;
46264
46265 module_put(ctrl->ops->owner);
46266+ mdiobus_unregister(bus);
46267 mdiobus_free(bus);
46268 }
46269 EXPORT_SYMBOL(free_mdio_bitbang);
46270diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46271index e3923eb..2a0373b 100644
46272--- a/drivers/net/ppp/ppp_generic.c
46273+++ b/drivers/net/ppp/ppp_generic.c
46274@@ -1012,7 +1012,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46275 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46276 struct ppp_stats stats;
46277 struct ppp_comp_stats cstats;
46278- char *vers;
46279
46280 switch (cmd) {
46281 case SIOCGPPPSTATS:
46282@@ -1034,8 +1033,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46283 break;
46284
46285 case SIOCGPPPVER:
46286- vers = PPP_VERSION;
46287- if (copy_to_user(addr, vers, strlen(vers) + 1))
46288+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46289 break;
46290 err = 0;
46291 break;
46292diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46293index 1252d9c..80e660b 100644
46294--- a/drivers/net/slip/slhc.c
46295+++ b/drivers/net/slip/slhc.c
46296@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46297 register struct tcphdr *thp;
46298 register struct iphdr *ip;
46299 register struct cstate *cs;
46300- int len, hdrlen;
46301+ long len, hdrlen;
46302 unsigned char *cp = icp;
46303
46304 /* We've got a compressed packet; read the change byte */
46305diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46306index ce4989b..b40b328 100644
46307--- a/drivers/net/team/team.c
46308+++ b/drivers/net/team/team.c
46309@@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46310 return NOTIFY_DONE;
46311 }
46312
46313-static struct notifier_block team_notifier_block __read_mostly = {
46314+static struct notifier_block team_notifier_block = {
46315 .notifier_call = team_device_event,
46316 };
46317
46318diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46319index ee328ba..c4a0041 100644
46320--- a/drivers/net/tun.c
46321+++ b/drivers/net/tun.c
46322@@ -1876,7 +1876,7 @@ unlock:
46323 }
46324
46325 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46326- unsigned long arg, int ifreq_len)
46327+ unsigned long arg, size_t ifreq_len)
46328 {
46329 struct tun_file *tfile = file->private_data;
46330 struct tun_struct *tun;
46331@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46332 unsigned int ifindex;
46333 int ret;
46334
46335+ if (ifreq_len > sizeof ifr)
46336+ return -EFAULT;
46337+
46338 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46339 if (copy_from_user(&ifr, argp, ifreq_len))
46340 return -EFAULT;
46341diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46342index 660bd5e..ac59452 100644
46343--- a/drivers/net/usb/hso.c
46344+++ b/drivers/net/usb/hso.c
46345@@ -71,7 +71,7 @@
46346 #include <asm/byteorder.h>
46347 #include <linux/serial_core.h>
46348 #include <linux/serial.h>
46349-
46350+#include <asm/local.h>
46351
46352 #define MOD_AUTHOR "Option Wireless"
46353 #define MOD_DESCRIPTION "USB High Speed Option driver"
46354@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46355 struct urb *urb;
46356
46357 urb = serial->rx_urb[0];
46358- if (serial->port.count > 0) {
46359+ if (atomic_read(&serial->port.count) > 0) {
46360 count = put_rxbuf_data(urb, serial);
46361 if (count == -1)
46362 return;
46363@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46364 DUMP1(urb->transfer_buffer, urb->actual_length);
46365
46366 /* Anyone listening? */
46367- if (serial->port.count == 0)
46368+ if (atomic_read(&serial->port.count) == 0)
46369 return;
46370
46371 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46372@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46373 tty_port_tty_set(&serial->port, tty);
46374
46375 /* check for port already opened, if not set the termios */
46376- serial->port.count++;
46377- if (serial->port.count == 1) {
46378+ if (atomic_inc_return(&serial->port.count) == 1) {
46379 serial->rx_state = RX_IDLE;
46380 /* Force default termio settings */
46381 _hso_serial_set_termios(tty, NULL);
46382@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46383 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46384 if (result) {
46385 hso_stop_serial_device(serial->parent);
46386- serial->port.count--;
46387+ atomic_dec(&serial->port.count);
46388 kref_put(&serial->parent->ref, hso_serial_ref_free);
46389 }
46390 } else {
46391@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46392
46393 /* reset the rts and dtr */
46394 /* do the actual close */
46395- serial->port.count--;
46396+ atomic_dec(&serial->port.count);
46397
46398- if (serial->port.count <= 0) {
46399- serial->port.count = 0;
46400+ if (atomic_read(&serial->port.count) <= 0) {
46401+ atomic_set(&serial->port.count, 0);
46402 tty_port_tty_set(&serial->port, NULL);
46403 if (!usb_gone)
46404 hso_stop_serial_device(serial->parent);
46405@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46406
46407 /* the actual setup */
46408 spin_lock_irqsave(&serial->serial_lock, flags);
46409- if (serial->port.count)
46410+ if (atomic_read(&serial->port.count))
46411 _hso_serial_set_termios(tty, old);
46412 else
46413 tty->termios = *old;
46414@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46415 D1("Pending read interrupt on port %d\n", i);
46416 spin_lock(&serial->serial_lock);
46417 if (serial->rx_state == RX_IDLE &&
46418- serial->port.count > 0) {
46419+ atomic_read(&serial->port.count) > 0) {
46420 /* Setup and send a ctrl req read on
46421 * port i */
46422 if (!serial->rx_urb_filled[0]) {
46423@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46424 /* Start all serial ports */
46425 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46426 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46427- if (dev2ser(serial_table[i])->port.count) {
46428+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46429 result =
46430 hso_start_serial_device(serial_table[i], GFP_NOIO);
46431 hso_kick_transmit(dev2ser(serial_table[i]));
46432diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46433index 3fbfb08..2c16265 100644
46434--- a/drivers/net/usb/r8152.c
46435+++ b/drivers/net/usb/r8152.c
46436@@ -567,7 +567,7 @@ struct r8152 {
46437 void (*up)(struct r8152 *);
46438 void (*down)(struct r8152 *);
46439 void (*unload)(struct r8152 *);
46440- } rtl_ops;
46441+ } __no_const rtl_ops;
46442
46443 int intr_interval;
46444 u32 saved_wolopts;
46445diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46446index a2515887..6d13233 100644
46447--- a/drivers/net/usb/sierra_net.c
46448+++ b/drivers/net/usb/sierra_net.c
46449@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46450 /* atomic counter partially included in MAC address to make sure 2 devices
46451 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46452 */
46453-static atomic_t iface_counter = ATOMIC_INIT(0);
46454+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46455
46456 /*
46457 * SYNC Timer Delay definition used to set the expiry time
46458@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46459 dev->net->netdev_ops = &sierra_net_device_ops;
46460
46461 /* change MAC addr to include, ifacenum, and to be unique */
46462- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46463+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46464 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46465
46466 /* we will have to manufacture ethernet headers, prepare template */
46467diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46468index 77dcf92..549924a 100644
46469--- a/drivers/net/vxlan.c
46470+++ b/drivers/net/vxlan.c
46471@@ -2839,7 +2839,7 @@ nla_put_failure:
46472 return -EMSGSIZE;
46473 }
46474
46475-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46476+static struct rtnl_link_ops vxlan_link_ops = {
46477 .kind = "vxlan",
46478 .maxtype = IFLA_VXLAN_MAX,
46479 .policy = vxlan_policy,
46480@@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46481 return NOTIFY_DONE;
46482 }
46483
46484-static struct notifier_block vxlan_notifier_block __read_mostly = {
46485+static struct notifier_block vxlan_notifier_block = {
46486 .notifier_call = vxlan_lowerdev_event,
46487 };
46488
46489diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46490index 5920c99..ff2e4a5 100644
46491--- a/drivers/net/wan/lmc/lmc_media.c
46492+++ b/drivers/net/wan/lmc/lmc_media.c
46493@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46494 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46495
46496 lmc_media_t lmc_ds3_media = {
46497- lmc_ds3_init, /* special media init stuff */
46498- lmc_ds3_default, /* reset to default state */
46499- lmc_ds3_set_status, /* reset status to state provided */
46500- lmc_dummy_set_1, /* set clock source */
46501- lmc_dummy_set2_1, /* set line speed */
46502- lmc_ds3_set_100ft, /* set cable length */
46503- lmc_ds3_set_scram, /* set scrambler */
46504- lmc_ds3_get_link_status, /* get link status */
46505- lmc_dummy_set_1, /* set link status */
46506- lmc_ds3_set_crc_length, /* set CRC length */
46507- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46508- lmc_ds3_watchdog
46509+ .init = lmc_ds3_init, /* special media init stuff */
46510+ .defaults = lmc_ds3_default, /* reset to default state */
46511+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46512+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46513+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46514+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46515+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46516+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46517+ .set_link_status = lmc_dummy_set_1, /* set link status */
46518+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46519+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46520+ .watchdog = lmc_ds3_watchdog
46521 };
46522
46523 lmc_media_t lmc_hssi_media = {
46524- lmc_hssi_init, /* special media init stuff */
46525- lmc_hssi_default, /* reset to default state */
46526- lmc_hssi_set_status, /* reset status to state provided */
46527- lmc_hssi_set_clock, /* set clock source */
46528- lmc_dummy_set2_1, /* set line speed */
46529- lmc_dummy_set_1, /* set cable length */
46530- lmc_dummy_set_1, /* set scrambler */
46531- lmc_hssi_get_link_status, /* get link status */
46532- lmc_hssi_set_link_status, /* set link status */
46533- lmc_hssi_set_crc_length, /* set CRC length */
46534- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46535- lmc_hssi_watchdog
46536+ .init = lmc_hssi_init, /* special media init stuff */
46537+ .defaults = lmc_hssi_default, /* reset to default state */
46538+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46539+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46540+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46541+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46542+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46543+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46544+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46545+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46546+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46547+ .watchdog = lmc_hssi_watchdog
46548 };
46549
46550-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46551- lmc_ssi_default, /* reset to default state */
46552- lmc_ssi_set_status, /* reset status to state provided */
46553- lmc_ssi_set_clock, /* set clock source */
46554- lmc_ssi_set_speed, /* set line speed */
46555- lmc_dummy_set_1, /* set cable length */
46556- lmc_dummy_set_1, /* set scrambler */
46557- lmc_ssi_get_link_status, /* get link status */
46558- lmc_ssi_set_link_status, /* set link status */
46559- lmc_ssi_set_crc_length, /* set CRC length */
46560- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46561- lmc_ssi_watchdog
46562+lmc_media_t lmc_ssi_media = {
46563+ .init = lmc_ssi_init, /* special media init stuff */
46564+ .defaults = lmc_ssi_default, /* reset to default state */
46565+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46566+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46567+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46568+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46569+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46570+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46571+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46572+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46573+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46574+ .watchdog = lmc_ssi_watchdog
46575 };
46576
46577 lmc_media_t lmc_t1_media = {
46578- lmc_t1_init, /* special media init stuff */
46579- lmc_t1_default, /* reset to default state */
46580- lmc_t1_set_status, /* reset status to state provided */
46581- lmc_t1_set_clock, /* set clock source */
46582- lmc_dummy_set2_1, /* set line speed */
46583- lmc_dummy_set_1, /* set cable length */
46584- lmc_dummy_set_1, /* set scrambler */
46585- lmc_t1_get_link_status, /* get link status */
46586- lmc_dummy_set_1, /* set link status */
46587- lmc_t1_set_crc_length, /* set CRC length */
46588- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46589- lmc_t1_watchdog
46590+ .init = lmc_t1_init, /* special media init stuff */
46591+ .defaults = lmc_t1_default, /* reset to default state */
46592+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46593+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46594+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46595+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46596+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46597+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46598+ .set_link_status = lmc_dummy_set_1, /* set link status */
46599+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46600+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46601+ .watchdog = lmc_t1_watchdog
46602 };
46603
46604 static void
46605diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46606index feacc3b..5bac0de 100644
46607--- a/drivers/net/wan/z85230.c
46608+++ b/drivers/net/wan/z85230.c
46609@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46610
46611 struct z8530_irqhandler z8530_sync =
46612 {
46613- z8530_rx,
46614- z8530_tx,
46615- z8530_status
46616+ .rx = z8530_rx,
46617+ .tx = z8530_tx,
46618+ .status = z8530_status
46619 };
46620
46621 EXPORT_SYMBOL(z8530_sync);
46622@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46623 }
46624
46625 static struct z8530_irqhandler z8530_dma_sync = {
46626- z8530_dma_rx,
46627- z8530_dma_tx,
46628- z8530_dma_status
46629+ .rx = z8530_dma_rx,
46630+ .tx = z8530_dma_tx,
46631+ .status = z8530_dma_status
46632 };
46633
46634 static struct z8530_irqhandler z8530_txdma_sync = {
46635- z8530_rx,
46636- z8530_dma_tx,
46637- z8530_dma_status
46638+ .rx = z8530_rx,
46639+ .tx = z8530_dma_tx,
46640+ .status = z8530_dma_status
46641 };
46642
46643 /**
46644@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46645
46646 struct z8530_irqhandler z8530_nop=
46647 {
46648- z8530_rx_clear,
46649- z8530_tx_clear,
46650- z8530_status_clear
46651+ .rx = z8530_rx_clear,
46652+ .tx = z8530_tx_clear,
46653+ .status = z8530_status_clear
46654 };
46655
46656
46657diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46658index 0b60295..b8bfa5b 100644
46659--- a/drivers/net/wimax/i2400m/rx.c
46660+++ b/drivers/net/wimax/i2400m/rx.c
46661@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46662 if (i2400m->rx_roq == NULL)
46663 goto error_roq_alloc;
46664
46665- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46666+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46667 GFP_KERNEL);
46668 if (rd == NULL) {
46669 result = -ENOMEM;
46670diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46671index 64747d4..17c4cf3 100644
46672--- a/drivers/net/wireless/airo.c
46673+++ b/drivers/net/wireless/airo.c
46674@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46675 struct airo_info *ai = dev->ml_priv;
46676 int ridcode;
46677 int enabled;
46678- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46679+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46680 unsigned char *iobuf;
46681
46682 /* Only super-user can write RIDs */
46683diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46684index 99b3bfa..9559372 100644
46685--- a/drivers/net/wireless/at76c50x-usb.c
46686+++ b/drivers/net/wireless/at76c50x-usb.c
46687@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46688 }
46689
46690 /* Convert timeout from the DFU status to jiffies */
46691-static inline unsigned long at76_get_timeout(struct dfu_status *s)
46692+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46693 {
46694 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46695 | (s->poll_timeout[1] << 8)
46696diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46697index 7f1bccd..ca2ffca 100644
46698--- a/drivers/net/wireless/ath/ath10k/htc.c
46699+++ b/drivers/net/wireless/ath/ath10k/htc.c
46700@@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46701 /* registered target arrival callback from the HIF layer */
46702 int ath10k_htc_init(struct ath10k *ar)
46703 {
46704- struct ath10k_hif_cb htc_callbacks;
46705+ static struct ath10k_hif_cb htc_callbacks = {
46706+ .rx_completion = ath10k_htc_rx_completion_handler,
46707+ .tx_completion = ath10k_htc_tx_completion_handler,
46708+ };
46709 struct ath10k_htc_ep *ep = NULL;
46710 struct ath10k_htc *htc = &ar->htc;
46711
46712@@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
46713 ath10k_htc_reset_endpoint_states(htc);
46714
46715 /* setup HIF layer callbacks */
46716- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46717- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46718 htc->ar = ar;
46719
46720 /* Get HIF default pipe for HTC message exchange */
46721diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46722index 4716d33..a688310 100644
46723--- a/drivers/net/wireless/ath/ath10k/htc.h
46724+++ b/drivers/net/wireless/ath/ath10k/htc.h
46725@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46726
46727 struct ath10k_htc_ops {
46728 void (*target_send_suspend_complete)(struct ath10k *ar);
46729-};
46730+} __no_const;
46731
46732 struct ath10k_htc_ep_ops {
46733 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46734 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46735 void (*ep_tx_credits)(struct ath10k *);
46736-};
46737+} __no_const;
46738
46739 /* service connection information */
46740 struct ath10k_htc_svc_conn_req {
46741diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46742index 741b38d..b7ae41b 100644
46743--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46744+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46745@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46746 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46747 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46748
46749- ACCESS_ONCE(ads->ds_link) = i->link;
46750- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46751+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
46752+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46753
46754 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46755 ctl6 = SM(i->keytype, AR_EncrType);
46756@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46757
46758 if ((i->is_first || i->is_last) &&
46759 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46760- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46761+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46762 | set11nTries(i->rates, 1)
46763 | set11nTries(i->rates, 2)
46764 | set11nTries(i->rates, 3)
46765 | (i->dur_update ? AR_DurUpdateEna : 0)
46766 | SM(0, AR_BurstDur);
46767
46768- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46769+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46770 | set11nRate(i->rates, 1)
46771 | set11nRate(i->rates, 2)
46772 | set11nRate(i->rates, 3);
46773 } else {
46774- ACCESS_ONCE(ads->ds_ctl2) = 0;
46775- ACCESS_ONCE(ads->ds_ctl3) = 0;
46776+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46777+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46778 }
46779
46780 if (!i->is_first) {
46781- ACCESS_ONCE(ads->ds_ctl0) = 0;
46782- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46783- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46784+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46785+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46786+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46787 return;
46788 }
46789
46790@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46791 break;
46792 }
46793
46794- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46795+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46796 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46797 | SM(i->txpower, AR_XmitPower)
46798 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46799@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46800 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46801 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46802
46803- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46804- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46805+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46806+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46807
46808 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46809 return;
46810
46811- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46812+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46813 | set11nPktDurRTSCTS(i->rates, 1);
46814
46815- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46816+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46817 | set11nPktDurRTSCTS(i->rates, 3);
46818
46819- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46820+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46821 | set11nRateFlags(i->rates, 1)
46822 | set11nRateFlags(i->rates, 2)
46823 | set11nRateFlags(i->rates, 3)
46824diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46825index 729ffbf..49f50e3 100644
46826--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46827+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46828@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46829 (i->qcu << AR_TxQcuNum_S) | desc_len;
46830
46831 checksum += val;
46832- ACCESS_ONCE(ads->info) = val;
46833+ ACCESS_ONCE_RW(ads->info) = val;
46834
46835 checksum += i->link;
46836- ACCESS_ONCE(ads->link) = i->link;
46837+ ACCESS_ONCE_RW(ads->link) = i->link;
46838
46839 checksum += i->buf_addr[0];
46840- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46841+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46842 checksum += i->buf_addr[1];
46843- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46844+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46845 checksum += i->buf_addr[2];
46846- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46847+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46848 checksum += i->buf_addr[3];
46849- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46850+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46851
46852 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46853- ACCESS_ONCE(ads->ctl3) = val;
46854+ ACCESS_ONCE_RW(ads->ctl3) = val;
46855 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46856- ACCESS_ONCE(ads->ctl5) = val;
46857+ ACCESS_ONCE_RW(ads->ctl5) = val;
46858 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46859- ACCESS_ONCE(ads->ctl7) = val;
46860+ ACCESS_ONCE_RW(ads->ctl7) = val;
46861 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46862- ACCESS_ONCE(ads->ctl9) = val;
46863+ ACCESS_ONCE_RW(ads->ctl9) = val;
46864
46865 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46866- ACCESS_ONCE(ads->ctl10) = checksum;
46867+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46868
46869 if (i->is_first || i->is_last) {
46870- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46871+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46872 | set11nTries(i->rates, 1)
46873 | set11nTries(i->rates, 2)
46874 | set11nTries(i->rates, 3)
46875 | (i->dur_update ? AR_DurUpdateEna : 0)
46876 | SM(0, AR_BurstDur);
46877
46878- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46879+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46880 | set11nRate(i->rates, 1)
46881 | set11nRate(i->rates, 2)
46882 | set11nRate(i->rates, 3);
46883 } else {
46884- ACCESS_ONCE(ads->ctl13) = 0;
46885- ACCESS_ONCE(ads->ctl14) = 0;
46886+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46887+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46888 }
46889
46890 ads->ctl20 = 0;
46891@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46892
46893 ctl17 = SM(i->keytype, AR_EncrType);
46894 if (!i->is_first) {
46895- ACCESS_ONCE(ads->ctl11) = 0;
46896- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46897- ACCESS_ONCE(ads->ctl15) = 0;
46898- ACCESS_ONCE(ads->ctl16) = 0;
46899- ACCESS_ONCE(ads->ctl17) = ctl17;
46900- ACCESS_ONCE(ads->ctl18) = 0;
46901- ACCESS_ONCE(ads->ctl19) = 0;
46902+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46903+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46904+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46905+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46906+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46907+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46908+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46909 return;
46910 }
46911
46912- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46913+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46914 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46915 | SM(i->txpower, AR_XmitPower)
46916 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46917@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46918 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46919 ctl12 |= SM(val, AR_PAPRDChainMask);
46920
46921- ACCESS_ONCE(ads->ctl12) = ctl12;
46922- ACCESS_ONCE(ads->ctl17) = ctl17;
46923+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46924+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46925
46926- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46927+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46928 | set11nPktDurRTSCTS(i->rates, 1);
46929
46930- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46931+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46932 | set11nPktDurRTSCTS(i->rates, 3);
46933
46934- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46935+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46936 | set11nRateFlags(i->rates, 1)
46937 | set11nRateFlags(i->rates, 2)
46938 | set11nRateFlags(i->rates, 3)
46939 | SM(i->rtscts_rate, AR_RTSCTSRate);
46940
46941- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46942+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46943 }
46944
46945 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46946diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46947index 0acd4b5..0591c91 100644
46948--- a/drivers/net/wireless/ath/ath9k/hw.h
46949+++ b/drivers/net/wireless/ath/ath9k/hw.h
46950@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46951
46952 /* ANI */
46953 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46954-};
46955+} __no_const;
46956
46957 /**
46958 * struct ath_spec_scan - parameters for Atheros spectral scan
46959@@ -706,7 +706,7 @@ struct ath_hw_ops {
46960 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46961 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46962 #endif
46963-};
46964+} __no_const;
46965
46966 struct ath_nf_limits {
46967 s16 max;
46968diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46969index 92190da..f3a4c4c 100644
46970--- a/drivers/net/wireless/b43/phy_lp.c
46971+++ b/drivers/net/wireless/b43/phy_lp.c
46972@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46973 {
46974 struct ssb_bus *bus = dev->dev->sdev->bus;
46975
46976- static const struct b206x_channel *chandata = NULL;
46977+ const struct b206x_channel *chandata = NULL;
46978 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46979 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46980 u16 old_comm15, scale;
46981diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46982index dc1d20c..f7a4f06 100644
46983--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46984+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46985@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46986 */
46987 if (il3945_mod_params.disable_hw_scan) {
46988 D_INFO("Disabling hw_scan\n");
46989- il3945_mac_ops.hw_scan = NULL;
46990+ pax_open_kernel();
46991+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46992+ pax_close_kernel();
46993 }
46994
46995 D_INFO("*** LOAD DRIVER ***\n");
46996diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46997index d2fe259..0c4c682 100644
46998--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46999+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47000@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47001 {
47002 struct iwl_priv *priv = file->private_data;
47003 char buf[64];
47004- int buf_size;
47005+ size_t buf_size;
47006 u32 offset, len;
47007
47008 memset(buf, 0, sizeof(buf));
47009@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47010 struct iwl_priv *priv = file->private_data;
47011
47012 char buf[8];
47013- int buf_size;
47014+ size_t buf_size;
47015 u32 reset_flag;
47016
47017 memset(buf, 0, sizeof(buf));
47018@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47019 {
47020 struct iwl_priv *priv = file->private_data;
47021 char buf[8];
47022- int buf_size;
47023+ size_t buf_size;
47024 int ht40;
47025
47026 memset(buf, 0, sizeof(buf));
47027@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_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 value;
47034
47035 memset(buf, 0, sizeof(buf));
47036@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47037 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47038 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47039
47040-static const char *fmt_value = " %-30s %10u\n";
47041-static const char *fmt_hex = " %-30s 0x%02X\n";
47042-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47043-static const char *fmt_header =
47044+static const char fmt_value[] = " %-30s %10u\n";
47045+static const char fmt_hex[] = " %-30s 0x%02X\n";
47046+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47047+static const char fmt_header[] =
47048 "%-32s current cumulative delta max\n";
47049
47050 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47051@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47052 {
47053 struct iwl_priv *priv = file->private_data;
47054 char buf[8];
47055- int buf_size;
47056+ size_t buf_size;
47057 int clear;
47058
47059 memset(buf, 0, sizeof(buf));
47060@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47061 {
47062 struct iwl_priv *priv = file->private_data;
47063 char buf[8];
47064- int buf_size;
47065+ size_t buf_size;
47066 int trace;
47067
47068 memset(buf, 0, sizeof(buf));
47069@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47070 {
47071 struct iwl_priv *priv = file->private_data;
47072 char buf[8];
47073- int buf_size;
47074+ size_t buf_size;
47075 int missed;
47076
47077 memset(buf, 0, sizeof(buf));
47078@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47079
47080 struct iwl_priv *priv = file->private_data;
47081 char buf[8];
47082- int buf_size;
47083+ size_t buf_size;
47084 int plcp;
47085
47086 memset(buf, 0, sizeof(buf));
47087@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47088
47089 struct iwl_priv *priv = file->private_data;
47090 char buf[8];
47091- int buf_size;
47092+ size_t buf_size;
47093 int flush;
47094
47095 memset(buf, 0, sizeof(buf));
47096@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47097
47098 struct iwl_priv *priv = file->private_data;
47099 char buf[8];
47100- int buf_size;
47101+ size_t buf_size;
47102 int rts;
47103
47104 if (!priv->cfg->ht_params)
47105@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47106 {
47107 struct iwl_priv *priv = file->private_data;
47108 char buf[8];
47109- int buf_size;
47110+ size_t buf_size;
47111
47112 memset(buf, 0, sizeof(buf));
47113 buf_size = min(count, sizeof(buf) - 1);
47114@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47115 struct iwl_priv *priv = file->private_data;
47116 u32 event_log_flag;
47117 char buf[8];
47118- int buf_size;
47119+ size_t buf_size;
47120
47121 /* check that the interface is up */
47122 if (!iwl_is_ready(priv))
47123@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47124 struct iwl_priv *priv = file->private_data;
47125 char buf[8];
47126 u32 calib_disabled;
47127- int buf_size;
47128+ size_t buf_size;
47129
47130 memset(buf, 0, sizeof(buf));
47131 buf_size = min(count, sizeof(buf) - 1);
47132diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47133index 6a6df71..eb5c93a 100644
47134--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47135+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47136@@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47137 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47138 {
47139 struct iwl_nvm_data *data = priv->nvm_data;
47140- char *debug_msg;
47141+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47142
47143 if (data->sku_cap_11n_enable &&
47144 !priv->cfg->ht_params) {
47145@@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47146 return -EINVAL;
47147 }
47148
47149- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47150 IWL_DEBUG_INFO(priv, debug_msg,
47151 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47152 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47153diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47154index 2365553..97126d8 100644
47155--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47156+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47157@@ -1552,7 +1552,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47158 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47159
47160 char buf[8];
47161- int buf_size;
47162+ size_t buf_size;
47163 u32 reset_flag;
47164
47165 memset(buf, 0, sizeof(buf));
47166@@ -1573,7 +1573,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47167 {
47168 struct iwl_trans *trans = file->private_data;
47169 char buf[8];
47170- int buf_size;
47171+ size_t buf_size;
47172 int csr;
47173
47174 memset(buf, 0, sizeof(buf));
47175diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47176index 9d7a52f..2729a99 100644
47177--- a/drivers/net/wireless/mac80211_hwsim.c
47178+++ b/drivers/net/wireless/mac80211_hwsim.c
47179@@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47180 if (channels < 1)
47181 return -EINVAL;
47182
47183- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47184- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47185- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47186- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47187- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47188- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47189- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47190- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47191- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47192- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47193- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47194- mac80211_hwsim_assign_vif_chanctx;
47195- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47196- mac80211_hwsim_unassign_vif_chanctx;
47197+ pax_open_kernel();
47198+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47199+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47200+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47201+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47202+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47203+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47204+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47205+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47206+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47207+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47208+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47209+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47210+ pax_close_kernel();
47211
47212 spin_lock_init(&hwsim_radio_lock);
47213 INIT_LIST_HEAD(&hwsim_radios);
47214diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47215index 39d22a1..4ec8612 100644
47216--- a/drivers/net/wireless/rndis_wlan.c
47217+++ b/drivers/net/wireless/rndis_wlan.c
47218@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47219
47220 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47221
47222- if (rts_threshold < 0 || rts_threshold > 2347)
47223+ if (rts_threshold > 2347)
47224 rts_threshold = 2347;
47225
47226 tmp = cpu_to_le32(rts_threshold);
47227diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47228index e3b885d..7a7de2f 100644
47229--- a/drivers/net/wireless/rt2x00/rt2x00.h
47230+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47231@@ -375,7 +375,7 @@ struct rt2x00_intf {
47232 * for hardware which doesn't support hardware
47233 * sequence counting.
47234 */
47235- atomic_t seqno;
47236+ atomic_unchecked_t seqno;
47237 };
47238
47239 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47240diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47241index 5642ccc..01f03eb 100644
47242--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47243+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47244@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47245 * sequence counter given by mac80211.
47246 */
47247 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47248- seqno = atomic_add_return(0x10, &intf->seqno);
47249+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47250 else
47251- seqno = atomic_read(&intf->seqno);
47252+ seqno = atomic_read_unchecked(&intf->seqno);
47253
47254 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47255 hdr->seq_ctrl |= cpu_to_le16(seqno);
47256diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47257index b661f896..ddf7d2b 100644
47258--- a/drivers/net/wireless/ti/wl1251/sdio.c
47259+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47260@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47261
47262 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47263
47264- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47265- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47266+ pax_open_kernel();
47267+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47268+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47269+ pax_close_kernel();
47270
47271 wl1251_info("using dedicated interrupt line");
47272 } else {
47273- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47274- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47275+ pax_open_kernel();
47276+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47277+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47278+ pax_close_kernel();
47279
47280 wl1251_info("using SDIO interrupt");
47281 }
47282diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47283index d50dfac..0a6f5be3 100644
47284--- a/drivers/net/wireless/ti/wl12xx/main.c
47285+++ b/drivers/net/wireless/ti/wl12xx/main.c
47286@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47287 sizeof(wl->conf.mem));
47288
47289 /* read data preparation is only needed by wl127x */
47290- wl->ops->prepare_read = wl127x_prepare_read;
47291+ pax_open_kernel();
47292+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47293+ pax_close_kernel();
47294
47295 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47296 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47297@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47298 sizeof(wl->conf.mem));
47299
47300 /* read data preparation is only needed by wl127x */
47301- wl->ops->prepare_read = wl127x_prepare_read;
47302+ pax_open_kernel();
47303+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47304+ pax_close_kernel();
47305
47306 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47307 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47308diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47309index de5b4fa..7996ec6 100644
47310--- a/drivers/net/wireless/ti/wl18xx/main.c
47311+++ b/drivers/net/wireless/ti/wl18xx/main.c
47312@@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47313 }
47314
47315 if (!checksum_param) {
47316- wl18xx_ops.set_rx_csum = NULL;
47317- wl18xx_ops.init_vif = NULL;
47318+ pax_open_kernel();
47319+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47320+ *(void **)&wl18xx_ops.init_vif = NULL;
47321+ pax_close_kernel();
47322 }
47323
47324 /* Enable 11a Band only if we have 5G antennas */
47325diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47326index a912dc0..a8225ba 100644
47327--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47328+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47329@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47330 {
47331 struct zd_usb *usb = urb->context;
47332 struct zd_usb_interrupt *intr = &usb->intr;
47333- int len;
47334+ unsigned int len;
47335 u16 int_num;
47336
47337 ZD_ASSERT(in_interrupt());
47338diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47339index 683671a..4519fc2 100644
47340--- a/drivers/nfc/nfcwilink.c
47341+++ b/drivers/nfc/nfcwilink.c
47342@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47343
47344 static int nfcwilink_probe(struct platform_device *pdev)
47345 {
47346- static struct nfcwilink *drv;
47347+ struct nfcwilink *drv;
47348 int rc;
47349 __u32 protocols;
47350
47351diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47352index d93b2b6..ae50401 100644
47353--- a/drivers/oprofile/buffer_sync.c
47354+++ b/drivers/oprofile/buffer_sync.c
47355@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47356 if (cookie == NO_COOKIE)
47357 offset = pc;
47358 if (cookie == INVALID_COOKIE) {
47359- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47360+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47361 offset = pc;
47362 }
47363 if (cookie != last_cookie) {
47364@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47365 /* add userspace sample */
47366
47367 if (!mm) {
47368- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47369+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47370 return 0;
47371 }
47372
47373 cookie = lookup_dcookie(mm, s->eip, &offset);
47374
47375 if (cookie == INVALID_COOKIE) {
47376- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47377+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47378 return 0;
47379 }
47380
47381@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47382 /* ignore backtraces if failed to add a sample */
47383 if (state == sb_bt_start) {
47384 state = sb_bt_ignore;
47385- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47386+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47387 }
47388 }
47389 release_mm(mm);
47390diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47391index c0cc4e7..44d4e54 100644
47392--- a/drivers/oprofile/event_buffer.c
47393+++ b/drivers/oprofile/event_buffer.c
47394@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47395 }
47396
47397 if (buffer_pos == buffer_size) {
47398- atomic_inc(&oprofile_stats.event_lost_overflow);
47399+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47400 return;
47401 }
47402
47403diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47404index ed2c3ec..deda85a 100644
47405--- a/drivers/oprofile/oprof.c
47406+++ b/drivers/oprofile/oprof.c
47407@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47408 if (oprofile_ops.switch_events())
47409 return;
47410
47411- atomic_inc(&oprofile_stats.multiplex_counter);
47412+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47413 start_switch_worker();
47414 }
47415
47416diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47417index ee2cfce..7f8f699 100644
47418--- a/drivers/oprofile/oprofile_files.c
47419+++ b/drivers/oprofile/oprofile_files.c
47420@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47421
47422 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47423
47424-static ssize_t timeout_read(struct file *file, char __user *buf,
47425+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47426 size_t count, loff_t *offset)
47427 {
47428 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47429diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47430index 59659ce..6c860a0 100644
47431--- a/drivers/oprofile/oprofile_stats.c
47432+++ b/drivers/oprofile/oprofile_stats.c
47433@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47434 cpu_buf->sample_invalid_eip = 0;
47435 }
47436
47437- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47438- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47439- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47440- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47441- atomic_set(&oprofile_stats.multiplex_counter, 0);
47442+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47443+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47444+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47445+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47446+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47447 }
47448
47449
47450diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47451index 1fc622b..8c48fc3 100644
47452--- a/drivers/oprofile/oprofile_stats.h
47453+++ b/drivers/oprofile/oprofile_stats.h
47454@@ -13,11 +13,11 @@
47455 #include <linux/atomic.h>
47456
47457 struct oprofile_stat_struct {
47458- atomic_t sample_lost_no_mm;
47459- atomic_t sample_lost_no_mapping;
47460- atomic_t bt_lost_no_mapping;
47461- atomic_t event_lost_overflow;
47462- atomic_t multiplex_counter;
47463+ atomic_unchecked_t sample_lost_no_mm;
47464+ atomic_unchecked_t sample_lost_no_mapping;
47465+ atomic_unchecked_t bt_lost_no_mapping;
47466+ atomic_unchecked_t event_lost_overflow;
47467+ atomic_unchecked_t multiplex_counter;
47468 };
47469
47470 extern struct oprofile_stat_struct oprofile_stats;
47471diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47472index 3f49345..c750d0b 100644
47473--- a/drivers/oprofile/oprofilefs.c
47474+++ b/drivers/oprofile/oprofilefs.c
47475@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47476
47477 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47478 {
47479- atomic_t *val = file->private_data;
47480- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47481+ atomic_unchecked_t *val = file->private_data;
47482+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47483 }
47484
47485
47486@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47487
47488
47489 int oprofilefs_create_ro_atomic(struct dentry *root,
47490- char const *name, atomic_t *val)
47491+ char const *name, atomic_unchecked_t *val)
47492 {
47493 return __oprofilefs_create_file(root, name,
47494 &atomic_ro_fops, 0444, val);
47495diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47496index 61be1d9..dec05d7 100644
47497--- a/drivers/oprofile/timer_int.c
47498+++ b/drivers/oprofile/timer_int.c
47499@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47500 return NOTIFY_OK;
47501 }
47502
47503-static struct notifier_block __refdata oprofile_cpu_notifier = {
47504+static struct notifier_block oprofile_cpu_notifier = {
47505 .notifier_call = oprofile_cpu_notify,
47506 };
47507
47508diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47509index 92ed045..62d39bd7 100644
47510--- a/drivers/parport/procfs.c
47511+++ b/drivers/parport/procfs.c
47512@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47513
47514 *ppos += len;
47515
47516- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47517+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47518 }
47519
47520 #ifdef CONFIG_PARPORT_1284
47521@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47522
47523 *ppos += len;
47524
47525- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47526+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47527 }
47528 #endif /* IEEE1284.3 support. */
47529
47530diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47531index 8dcccff..35d701d 100644
47532--- a/drivers/pci/hotplug/acpiphp_ibm.c
47533+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47534@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47535 goto init_cleanup;
47536 }
47537
47538- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47539+ pax_open_kernel();
47540+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47541+ pax_close_kernel();
47542 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47543
47544 return retval;
47545diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47546index 7536eef..52dc8fa 100644
47547--- a/drivers/pci/hotplug/cpcihp_generic.c
47548+++ b/drivers/pci/hotplug/cpcihp_generic.c
47549@@ -73,7 +73,6 @@ static u16 port;
47550 static unsigned int enum_bit;
47551 static u8 enum_mask;
47552
47553-static struct cpci_hp_controller_ops generic_hpc_ops;
47554 static struct cpci_hp_controller generic_hpc;
47555
47556 static int __init validate_parameters(void)
47557@@ -139,6 +138,10 @@ static int query_enum(void)
47558 return ((value & enum_mask) == enum_mask);
47559 }
47560
47561+static struct cpci_hp_controller_ops generic_hpc_ops = {
47562+ .query_enum = query_enum,
47563+};
47564+
47565 static int __init cpcihp_generic_init(void)
47566 {
47567 int status;
47568@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47569 pci_dev_put(dev);
47570
47571 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47572- generic_hpc_ops.query_enum = query_enum;
47573 generic_hpc.ops = &generic_hpc_ops;
47574
47575 status = cpci_hp_register_controller(&generic_hpc);
47576diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47577index e8c4a7c..7046f5c 100644
47578--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47579+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47580@@ -59,7 +59,6 @@
47581 /* local variables */
47582 static bool debug;
47583 static bool poll;
47584-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47585 static struct cpci_hp_controller zt5550_hpc;
47586
47587 /* Primary cPCI bus bridge device */
47588@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47589 return 0;
47590 }
47591
47592+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47593+ .query_enum = zt5550_hc_query_enum,
47594+};
47595+
47596 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47597 {
47598 int status;
47599@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47600 dbg("returned from zt5550_hc_config");
47601
47602 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47603- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47604 zt5550_hpc.ops = &zt5550_hpc_ops;
47605 if(!poll) {
47606 zt5550_hpc.irq = hc_dev->irq;
47607 zt5550_hpc.irq_flags = IRQF_SHARED;
47608 zt5550_hpc.dev_id = hc_dev;
47609
47610- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47611- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47612- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47613+ pax_open_kernel();
47614+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47615+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47616+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47617+ pax_open_kernel();
47618 } else {
47619 info("using ENUM# polling mode");
47620 }
47621diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47622index 76ba8a1..20ca857 100644
47623--- a/drivers/pci/hotplug/cpqphp_nvram.c
47624+++ b/drivers/pci/hotplug/cpqphp_nvram.c
47625@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47626
47627 void compaq_nvram_init (void __iomem *rom_start)
47628 {
47629+
47630+#ifndef CONFIG_PAX_KERNEXEC
47631 if (rom_start) {
47632 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47633 }
47634+#endif
47635+
47636 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47637
47638 /* initialize our int15 lock */
47639diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47640index cfa92a9..29539c5 100644
47641--- a/drivers/pci/hotplug/pci_hotplug_core.c
47642+++ b/drivers/pci/hotplug/pci_hotplug_core.c
47643@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47644 return -EINVAL;
47645 }
47646
47647- slot->ops->owner = owner;
47648- slot->ops->mod_name = mod_name;
47649+ pax_open_kernel();
47650+ *(struct module **)&slot->ops->owner = owner;
47651+ *(const char **)&slot->ops->mod_name = mod_name;
47652+ pax_close_kernel();
47653
47654 mutex_lock(&pci_hp_mutex);
47655 /*
47656diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47657index 0e0a2ff..29dff57 100644
47658--- a/drivers/pci/hotplug/pciehp_core.c
47659+++ b/drivers/pci/hotplug/pciehp_core.c
47660@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47661 struct slot *slot = ctrl->slot;
47662 struct hotplug_slot *hotplug = NULL;
47663 struct hotplug_slot_info *info = NULL;
47664- struct hotplug_slot_ops *ops = NULL;
47665+ hotplug_slot_ops_no_const *ops = NULL;
47666 char name[SLOT_NAME_SIZE];
47667 int retval = -ENOMEM;
47668
47669diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47670index fb02fc2..83dc2c3 100644
47671--- a/drivers/pci/msi.c
47672+++ b/drivers/pci/msi.c
47673@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47674 {
47675 struct attribute **msi_attrs;
47676 struct attribute *msi_attr;
47677- struct device_attribute *msi_dev_attr;
47678- struct attribute_group *msi_irq_group;
47679+ device_attribute_no_const *msi_dev_attr;
47680+ attribute_group_no_const *msi_irq_group;
47681 const struct attribute_group **msi_irq_groups;
47682 struct msi_desc *entry;
47683 int ret = -ENOMEM;
47684@@ -589,7 +589,7 @@ error_attrs:
47685 count = 0;
47686 msi_attr = msi_attrs[count];
47687 while (msi_attr) {
47688- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47689+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47690 kfree(msi_attr->name);
47691 kfree(msi_dev_attr);
47692 ++count;
47693diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47694index 4e0acef..bd98e31 100644
47695--- a/drivers/pci/pci-sysfs.c
47696+++ b/drivers/pci/pci-sysfs.c
47697@@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47698 {
47699 /* allocate attribute structure, piggyback attribute name */
47700 int name_len = write_combine ? 13 : 10;
47701- struct bin_attribute *res_attr;
47702+ bin_attribute_no_const *res_attr;
47703 int retval;
47704
47705 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47706@@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47707 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47708 {
47709 int retval;
47710- struct bin_attribute *attr;
47711+ bin_attribute_no_const *attr;
47712
47713 /* If the device has VPD, try to expose it in sysfs. */
47714 if (dev->vpd) {
47715@@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47716 {
47717 int retval;
47718 int rom_size = 0;
47719- struct bin_attribute *attr;
47720+ bin_attribute_no_const *attr;
47721
47722 if (!sysfs_initialized)
47723 return -EACCES;
47724diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47725index 6bd0822..35bc2b3 100644
47726--- a/drivers/pci/pci.h
47727+++ b/drivers/pci/pci.h
47728@@ -91,7 +91,7 @@ struct pci_vpd_ops {
47729 struct pci_vpd {
47730 unsigned int len;
47731 const struct pci_vpd_ops *ops;
47732- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47733+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47734 };
47735
47736 int pci_vpd_pci22_init(struct pci_dev *dev);
47737diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47738index e1e7026..d28dd33 100644
47739--- a/drivers/pci/pcie/aspm.c
47740+++ b/drivers/pci/pcie/aspm.c
47741@@ -27,9 +27,9 @@
47742 #define MODULE_PARAM_PREFIX "pcie_aspm."
47743
47744 /* Note: those are not register definitions */
47745-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47746-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47747-#define ASPM_STATE_L1 (4) /* L1 state */
47748+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47749+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47750+#define ASPM_STATE_L1 (4U) /* L1 state */
47751 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47752 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47753
47754diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47755index ef09f5f..49ac62f 100644
47756--- a/drivers/pci/probe.c
47757+++ b/drivers/pci/probe.c
47758@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47759 struct pci_bus_region region, inverted_region;
47760 bool bar_too_big = false, bar_disabled = false;
47761
47762- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47763+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47764
47765 /* No printks while decoding is disabled! */
47766 if (!dev->mmio_always_on) {
47767diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47768index 46d1378..30e452b 100644
47769--- a/drivers/pci/proc.c
47770+++ b/drivers/pci/proc.c
47771@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47772 static int __init pci_proc_init(void)
47773 {
47774 struct pci_dev *dev = NULL;
47775+
47776+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47777+#ifdef CONFIG_GRKERNSEC_PROC_USER
47778+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47779+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47780+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47781+#endif
47782+#else
47783 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47784+#endif
47785 proc_create("devices", 0, proc_bus_pci_dir,
47786 &proc_bus_pci_dev_operations);
47787 proc_initialized = 1;
47788diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47789index 7f3aad0..7d604bb 100644
47790--- a/drivers/platform/chrome/chromeos_laptop.c
47791+++ b/drivers/platform/chrome/chromeos_laptop.c
47792@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47793 .callback = chromeos_laptop_dmi_matched, \
47794 .driver_data = (void *)&board_
47795
47796-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47797+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47798 {
47799 .ident = "Samsung Series 5 550",
47800 .matches = {
47801diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
47802index 541f951..4dfd598 100644
47803--- a/drivers/platform/x86/alienware-wmi.c
47804+++ b/drivers/platform/x86/alienware-wmi.c
47805@@ -132,7 +132,7 @@ struct wmax_led_args {
47806 } __packed;
47807
47808 static struct platform_device *platform_device;
47809-static struct device_attribute *zone_dev_attrs;
47810+static device_attribute_no_const *zone_dev_attrs;
47811 static struct attribute **zone_attrs;
47812 static struct platform_zone *zone_data;
47813
47814@@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
47815 }
47816 };
47817
47818-static struct attribute_group zone_attribute_group = {
47819+static attribute_group_no_const zone_attribute_group = {
47820 .name = "rgb_zones",
47821 };
47822
47823diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47824index c5e082f..d6307a0 100644
47825--- a/drivers/platform/x86/asus-wmi.c
47826+++ b/drivers/platform/x86/asus-wmi.c
47827@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47828 int err;
47829 u32 retval = -1;
47830
47831+#ifdef CONFIG_GRKERNSEC_KMEM
47832+ return -EPERM;
47833+#endif
47834+
47835 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47836
47837 if (err < 0)
47838@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47839 int err;
47840 u32 retval = -1;
47841
47842+#ifdef CONFIG_GRKERNSEC_KMEM
47843+ return -EPERM;
47844+#endif
47845+
47846 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47847 &retval);
47848
47849@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47850 union acpi_object *obj;
47851 acpi_status status;
47852
47853+#ifdef CONFIG_GRKERNSEC_KMEM
47854+ return -EPERM;
47855+#endif
47856+
47857 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47858 1, asus->debug.method_id,
47859 &input, &output);
47860diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47861index 62f8030..c7f2a45 100644
47862--- a/drivers/platform/x86/msi-laptop.c
47863+++ b/drivers/platform/x86/msi-laptop.c
47864@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47865
47866 if (!quirks->ec_read_only) {
47867 /* allow userland write sysfs file */
47868- dev_attr_bluetooth.store = store_bluetooth;
47869- dev_attr_wlan.store = store_wlan;
47870- dev_attr_threeg.store = store_threeg;
47871- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47872- dev_attr_wlan.attr.mode |= S_IWUSR;
47873- dev_attr_threeg.attr.mode |= S_IWUSR;
47874+ pax_open_kernel();
47875+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47876+ *(void **)&dev_attr_wlan.store = store_wlan;
47877+ *(void **)&dev_attr_threeg.store = store_threeg;
47878+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47879+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47880+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47881+ pax_close_kernel();
47882 }
47883
47884 /* disable hardware control by fn key */
47885diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47886index 70222f2..8c8ce66 100644
47887--- a/drivers/platform/x86/msi-wmi.c
47888+++ b/drivers/platform/x86/msi-wmi.c
47889@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47890 static void msi_wmi_notify(u32 value, void *context)
47891 {
47892 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47893- static struct key_entry *key;
47894+ struct key_entry *key;
47895 union acpi_object *obj;
47896 acpi_status status;
47897
47898diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47899index 9c5a074..06c976a 100644
47900--- a/drivers/platform/x86/sony-laptop.c
47901+++ b/drivers/platform/x86/sony-laptop.c
47902@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47903 }
47904
47905 /* High speed charging function */
47906-static struct device_attribute *hsc_handle;
47907+static device_attribute_no_const *hsc_handle;
47908
47909 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47910 struct device_attribute *attr,
47911@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
47912 }
47913
47914 /* low battery function */
47915-static struct device_attribute *lowbatt_handle;
47916+static device_attribute_no_const *lowbatt_handle;
47917
47918 static ssize_t sony_nc_lowbatt_store(struct device *dev,
47919 struct device_attribute *attr,
47920@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
47921 }
47922
47923 /* fan speed function */
47924-static struct device_attribute *fan_handle, *hsf_handle;
47925+static device_attribute_no_const *fan_handle, *hsf_handle;
47926
47927 static ssize_t sony_nc_hsfan_store(struct device *dev,
47928 struct device_attribute *attr,
47929@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
47930 }
47931
47932 /* USB charge function */
47933-static struct device_attribute *uc_handle;
47934+static device_attribute_no_const *uc_handle;
47935
47936 static ssize_t sony_nc_usb_charge_store(struct device *dev,
47937 struct device_attribute *attr,
47938@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
47939 }
47940
47941 /* Panel ID function */
47942-static struct device_attribute *panel_handle;
47943+static device_attribute_no_const *panel_handle;
47944
47945 static ssize_t sony_nc_panelid_show(struct device *dev,
47946 struct device_attribute *attr, char *buffer)
47947@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
47948 }
47949
47950 /* smart connect function */
47951-static struct device_attribute *sc_handle;
47952+static device_attribute_no_const *sc_handle;
47953
47954 static ssize_t sony_nc_smart_conn_store(struct device *dev,
47955 struct device_attribute *attr,
47956diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47957index 15e61c1..40a39c7 100644
47958--- a/drivers/platform/x86/thinkpad_acpi.c
47959+++ b/drivers/platform/x86/thinkpad_acpi.c
47960@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47961 return 0;
47962 }
47963
47964-void static hotkey_mask_warn_incomplete_mask(void)
47965+static void hotkey_mask_warn_incomplete_mask(void)
47966 {
47967 /* log only what the user can fix... */
47968 const u32 wantedmask = hotkey_driver_mask &
47969@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47970 && !tp_features.bright_unkfw)
47971 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47972 }
47973+}
47974
47975 #undef TPACPI_COMPARE_KEY
47976 #undef TPACPI_MAY_SEND_KEY
47977-}
47978
47979 /*
47980 * Polling driver
47981diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47982index 438d4c7..ca8a2fb 100644
47983--- a/drivers/pnp/pnpbios/bioscalls.c
47984+++ b/drivers/pnp/pnpbios/bioscalls.c
47985@@ -59,7 +59,7 @@ do { \
47986 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47987 } while(0)
47988
47989-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47990+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47991 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47992
47993 /*
47994@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47995
47996 cpu = get_cpu();
47997 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47998+
47999+ pax_open_kernel();
48000 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48001+ pax_close_kernel();
48002
48003 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48004 spin_lock_irqsave(&pnp_bios_lock, flags);
48005@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48006 :"memory");
48007 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48008
48009+ pax_open_kernel();
48010 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48011+ pax_close_kernel();
48012+
48013 put_cpu();
48014
48015 /* If we get here and this is set then the PnP BIOS faulted on us. */
48016@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48017 return status;
48018 }
48019
48020-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48021+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48022 {
48023 int i;
48024
48025@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48026 pnp_bios_callpoint.offset = header->fields.pm16offset;
48027 pnp_bios_callpoint.segment = PNP_CS16;
48028
48029+ pax_open_kernel();
48030+
48031 for_each_possible_cpu(i) {
48032 struct desc_struct *gdt = get_cpu_gdt_table(i);
48033 if (!gdt)
48034@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48035 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48036 (unsigned long)__va(header->fields.pm16dseg));
48037 }
48038+
48039+ pax_close_kernel();
48040 }
48041diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48042index 01712cb..782e822 100644
48043--- a/drivers/pnp/resource.c
48044+++ b/drivers/pnp/resource.c
48045@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48046 return 1;
48047
48048 /* check if the resource is valid */
48049- if (*irq < 0 || *irq > 15)
48050+ if (*irq > 15)
48051 return 0;
48052
48053 /* check if the resource is reserved */
48054@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48055 return 1;
48056
48057 /* check if the resource is valid */
48058- if (*dma < 0 || *dma == 4 || *dma > 7)
48059+ if (*dma == 4 || *dma > 7)
48060 return 0;
48061
48062 /* check if the resource is reserved */
48063diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48064index 0c52e2a..3421ab7 100644
48065--- a/drivers/power/pda_power.c
48066+++ b/drivers/power/pda_power.c
48067@@ -37,7 +37,11 @@ static int polling;
48068
48069 #if IS_ENABLED(CONFIG_USB_PHY)
48070 static struct usb_phy *transceiver;
48071-static struct notifier_block otg_nb;
48072+static int otg_handle_notification(struct notifier_block *nb,
48073+ unsigned long event, void *unused);
48074+static struct notifier_block otg_nb = {
48075+ .notifier_call = otg_handle_notification
48076+};
48077 #endif
48078
48079 static struct regulator *ac_draw;
48080@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48081
48082 #if IS_ENABLED(CONFIG_USB_PHY)
48083 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48084- otg_nb.notifier_call = otg_handle_notification;
48085 ret = usb_register_notifier(transceiver, &otg_nb);
48086 if (ret) {
48087 dev_err(dev, "failure to register otg notifier\n");
48088diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48089index cc439fd..8fa30df 100644
48090--- a/drivers/power/power_supply.h
48091+++ b/drivers/power/power_supply.h
48092@@ -16,12 +16,12 @@ struct power_supply;
48093
48094 #ifdef CONFIG_SYSFS
48095
48096-extern void power_supply_init_attrs(struct device_type *dev_type);
48097+extern void power_supply_init_attrs(void);
48098 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48099
48100 #else
48101
48102-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48103+static inline void power_supply_init_attrs(void) {}
48104 #define power_supply_uevent NULL
48105
48106 #endif /* CONFIG_SYSFS */
48107diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48108index 2660664..75fcb04 100644
48109--- a/drivers/power/power_supply_core.c
48110+++ b/drivers/power/power_supply_core.c
48111@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48112 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48113 EXPORT_SYMBOL_GPL(power_supply_notifier);
48114
48115-static struct device_type power_supply_dev_type;
48116+extern const struct attribute_group *power_supply_attr_groups[];
48117+static struct device_type power_supply_dev_type = {
48118+ .groups = power_supply_attr_groups,
48119+};
48120
48121 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48122 struct power_supply *supply)
48123@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48124 return PTR_ERR(power_supply_class);
48125
48126 power_supply_class->dev_uevent = power_supply_uevent;
48127- power_supply_init_attrs(&power_supply_dev_type);
48128+ power_supply_init_attrs();
48129
48130 return 0;
48131 }
48132diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48133index 44420d1..967126e 100644
48134--- a/drivers/power/power_supply_sysfs.c
48135+++ b/drivers/power/power_supply_sysfs.c
48136@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48137 .is_visible = power_supply_attr_is_visible,
48138 };
48139
48140-static const struct attribute_group *power_supply_attr_groups[] = {
48141+const struct attribute_group *power_supply_attr_groups[] = {
48142 &power_supply_attr_group,
48143 NULL,
48144 };
48145
48146-void power_supply_init_attrs(struct device_type *dev_type)
48147+void power_supply_init_attrs(void)
48148 {
48149 int i;
48150
48151- dev_type->groups = power_supply_attr_groups;
48152-
48153 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48154 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48155 }
48156diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48157index 84419af..268ede8 100644
48158--- a/drivers/powercap/powercap_sys.c
48159+++ b/drivers/powercap/powercap_sys.c
48160@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48161 struct device_attribute name_attr;
48162 };
48163
48164+static ssize_t show_constraint_name(struct device *dev,
48165+ struct device_attribute *dev_attr,
48166+ char *buf);
48167+
48168 static struct powercap_constraint_attr
48169- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48170+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48171+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48172+ .power_limit_attr = {
48173+ .attr = {
48174+ .name = NULL,
48175+ .mode = S_IWUSR | S_IRUGO
48176+ },
48177+ .show = show_constraint_power_limit_uw,
48178+ .store = store_constraint_power_limit_uw
48179+ },
48180+
48181+ .time_window_attr = {
48182+ .attr = {
48183+ .name = NULL,
48184+ .mode = S_IWUSR | S_IRUGO
48185+ },
48186+ .show = show_constraint_time_window_us,
48187+ .store = store_constraint_time_window_us
48188+ },
48189+
48190+ .max_power_attr = {
48191+ .attr = {
48192+ .name = NULL,
48193+ .mode = S_IRUGO
48194+ },
48195+ .show = show_constraint_max_power_uw,
48196+ .store = NULL
48197+ },
48198+
48199+ .min_power_attr = {
48200+ .attr = {
48201+ .name = NULL,
48202+ .mode = S_IRUGO
48203+ },
48204+ .show = show_constraint_min_power_uw,
48205+ .store = NULL
48206+ },
48207+
48208+ .max_time_window_attr = {
48209+ .attr = {
48210+ .name = NULL,
48211+ .mode = S_IRUGO
48212+ },
48213+ .show = show_constraint_max_time_window_us,
48214+ .store = NULL
48215+ },
48216+
48217+ .min_time_window_attr = {
48218+ .attr = {
48219+ .name = NULL,
48220+ .mode = S_IRUGO
48221+ },
48222+ .show = show_constraint_min_time_window_us,
48223+ .store = NULL
48224+ },
48225+
48226+ .name_attr = {
48227+ .attr = {
48228+ .name = NULL,
48229+ .mode = S_IRUGO
48230+ },
48231+ .show = show_constraint_name,
48232+ .store = NULL
48233+ }
48234+ }
48235+};
48236
48237 /* A list of powercap control_types */
48238 static LIST_HEAD(powercap_cntrl_list);
48239@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48240 }
48241
48242 static int create_constraint_attribute(int id, const char *name,
48243- int mode,
48244- struct device_attribute *dev_attr,
48245- ssize_t (*show)(struct device *,
48246- struct device_attribute *, char *),
48247- ssize_t (*store)(struct device *,
48248- struct device_attribute *,
48249- const char *, size_t)
48250- )
48251+ struct device_attribute *dev_attr)
48252 {
48253+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48254
48255- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48256- id, name);
48257- if (!dev_attr->attr.name)
48258+ if (!name)
48259 return -ENOMEM;
48260- dev_attr->attr.mode = mode;
48261- dev_attr->show = show;
48262- dev_attr->store = store;
48263+
48264+ pax_open_kernel();
48265+ *(const char **)&dev_attr->attr.name = name;
48266+ pax_close_kernel();
48267
48268 return 0;
48269 }
48270@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48271
48272 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48273 ret = create_constraint_attribute(i, "power_limit_uw",
48274- S_IWUSR | S_IRUGO,
48275- &constraint_attrs[i].power_limit_attr,
48276- show_constraint_power_limit_uw,
48277- store_constraint_power_limit_uw);
48278+ &constraint_attrs[i].power_limit_attr);
48279 if (ret)
48280 goto err_alloc;
48281 ret = create_constraint_attribute(i, "time_window_us",
48282- S_IWUSR | S_IRUGO,
48283- &constraint_attrs[i].time_window_attr,
48284- show_constraint_time_window_us,
48285- store_constraint_time_window_us);
48286+ &constraint_attrs[i].time_window_attr);
48287 if (ret)
48288 goto err_alloc;
48289- ret = create_constraint_attribute(i, "name", S_IRUGO,
48290- &constraint_attrs[i].name_attr,
48291- show_constraint_name,
48292- NULL);
48293+ ret = create_constraint_attribute(i, "name",
48294+ &constraint_attrs[i].name_attr);
48295 if (ret)
48296 goto err_alloc;
48297- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48298- &constraint_attrs[i].max_power_attr,
48299- show_constraint_max_power_uw,
48300- NULL);
48301+ ret = create_constraint_attribute(i, "max_power_uw",
48302+ &constraint_attrs[i].max_power_attr);
48303 if (ret)
48304 goto err_alloc;
48305- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48306- &constraint_attrs[i].min_power_attr,
48307- show_constraint_min_power_uw,
48308- NULL);
48309+ ret = create_constraint_attribute(i, "min_power_uw",
48310+ &constraint_attrs[i].min_power_attr);
48311 if (ret)
48312 goto err_alloc;
48313 ret = create_constraint_attribute(i, "max_time_window_us",
48314- S_IRUGO,
48315- &constraint_attrs[i].max_time_window_attr,
48316- show_constraint_max_time_window_us,
48317- NULL);
48318+ &constraint_attrs[i].max_time_window_attr);
48319 if (ret)
48320 goto err_alloc;
48321 ret = create_constraint_attribute(i, "min_time_window_us",
48322- S_IRUGO,
48323- &constraint_attrs[i].min_time_window_attr,
48324- show_constraint_min_time_window_us,
48325- NULL);
48326+ &constraint_attrs[i].min_time_window_attr);
48327 if (ret)
48328 goto err_alloc;
48329
48330@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48331 power_zone->zone_dev_attrs[count++] =
48332 &dev_attr_max_energy_range_uj.attr;
48333 if (power_zone->ops->get_energy_uj) {
48334+ pax_open_kernel();
48335 if (power_zone->ops->reset_energy_uj)
48336- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48337+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48338 else
48339- dev_attr_energy_uj.attr.mode = S_IRUGO;
48340+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48341+ pax_close_kernel();
48342 power_zone->zone_dev_attrs[count++] =
48343 &dev_attr_energy_uj.attr;
48344 }
48345diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48346index 9c5d414..c7900ce 100644
48347--- a/drivers/ptp/ptp_private.h
48348+++ b/drivers/ptp/ptp_private.h
48349@@ -51,7 +51,7 @@ struct ptp_clock {
48350 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48351 wait_queue_head_t tsev_wq;
48352 int defunct; /* tells readers to go away when clock is being removed */
48353- struct device_attribute *pin_dev_attr;
48354+ device_attribute_no_const *pin_dev_attr;
48355 struct attribute **pin_attr;
48356 struct attribute_group pin_attr_group;
48357 };
48358diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48359index 302e626..12579af 100644
48360--- a/drivers/ptp/ptp_sysfs.c
48361+++ b/drivers/ptp/ptp_sysfs.c
48362@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48363 goto no_pin_attr;
48364
48365 for (i = 0; i < n_pins; i++) {
48366- struct device_attribute *da = &ptp->pin_dev_attr[i];
48367+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48368 sysfs_attr_init(&da->attr);
48369 da->attr.name = info->pin_config[i].name;
48370 da->attr.mode = 0644;
48371diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48372index 9a09f3c..450b523 100644
48373--- a/drivers/regulator/core.c
48374+++ b/drivers/regulator/core.c
48375@@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48376 {
48377 const struct regulation_constraints *constraints = NULL;
48378 const struct regulator_init_data *init_data;
48379- static atomic_t regulator_no = ATOMIC_INIT(0);
48380+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48381 struct regulator_dev *rdev;
48382 struct device *dev;
48383 int ret, i;
48384@@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48385 rdev->dev.of_node = config->of_node;
48386 rdev->dev.parent = dev;
48387 dev_set_name(&rdev->dev, "regulator.%d",
48388- atomic_inc_return(&regulator_no) - 1);
48389+ atomic_inc_return_unchecked(&regulator_no) - 1);
48390 ret = device_register(&rdev->dev);
48391 if (ret != 0) {
48392 put_device(&rdev->dev);
48393diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48394index 2fc4111..6aa88ca 100644
48395--- a/drivers/regulator/max8660.c
48396+++ b/drivers/regulator/max8660.c
48397@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48398 max8660->shadow_regs[MAX8660_OVER1] = 5;
48399 } else {
48400 /* Otherwise devices can be toggled via software */
48401- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48402- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48403+ pax_open_kernel();
48404+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48405+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48406+ pax_close_kernel();
48407 }
48408
48409 /*
48410diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48411index dbedf17..18ff6b7 100644
48412--- a/drivers/regulator/max8973-regulator.c
48413+++ b/drivers/regulator/max8973-regulator.c
48414@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48415 if (!pdata || !pdata->enable_ext_control) {
48416 max->desc.enable_reg = MAX8973_VOUT;
48417 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48418- max->ops.enable = regulator_enable_regmap;
48419- max->ops.disable = regulator_disable_regmap;
48420- max->ops.is_enabled = regulator_is_enabled_regmap;
48421+ pax_open_kernel();
48422+ *(void **)&max->ops.enable = regulator_enable_regmap;
48423+ *(void **)&max->ops.disable = regulator_disable_regmap;
48424+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48425+ pax_close_kernel();
48426 }
48427
48428 if (pdata) {
48429diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48430index f374fa5..26f0683 100644
48431--- a/drivers/regulator/mc13892-regulator.c
48432+++ b/drivers/regulator/mc13892-regulator.c
48433@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48434 }
48435 mc13xxx_unlock(mc13892);
48436
48437- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48438+ pax_open_kernel();
48439+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48440 = mc13892_vcam_set_mode;
48441- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48442+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48443 = mc13892_vcam_get_mode;
48444+ pax_close_kernel();
48445
48446 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48447 ARRAY_SIZE(mc13892_regulators));
48448diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48449index 0963c93..ea29cce 100644
48450--- a/drivers/rtc/rtc-cmos.c
48451+++ b/drivers/rtc/rtc-cmos.c
48452@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48453 hpet_rtc_timer_init();
48454
48455 /* export at least the first block of NVRAM */
48456- nvram.size = address_space - NVRAM_OFFSET;
48457+ pax_open_kernel();
48458+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48459+ pax_close_kernel();
48460 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48461 if (retval < 0) {
48462 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48463diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48464index d049393..bb20be0 100644
48465--- a/drivers/rtc/rtc-dev.c
48466+++ b/drivers/rtc/rtc-dev.c
48467@@ -16,6 +16,7 @@
48468 #include <linux/module.h>
48469 #include <linux/rtc.h>
48470 #include <linux/sched.h>
48471+#include <linux/grsecurity.h>
48472 #include "rtc-core.h"
48473
48474 static dev_t rtc_devt;
48475@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48476 if (copy_from_user(&tm, uarg, sizeof(tm)))
48477 return -EFAULT;
48478
48479+ gr_log_timechange();
48480+
48481 return rtc_set_time(rtc, &tm);
48482
48483 case RTC_PIE_ON:
48484diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48485index f03d5ba..8325bf6 100644
48486--- a/drivers/rtc/rtc-ds1307.c
48487+++ b/drivers/rtc/rtc-ds1307.c
48488@@ -107,7 +107,7 @@ struct ds1307 {
48489 u8 offset; /* register's offset */
48490 u8 regs[11];
48491 u16 nvram_offset;
48492- struct bin_attribute *nvram;
48493+ bin_attribute_no_const *nvram;
48494 enum ds_type type;
48495 unsigned long flags;
48496 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48497diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48498index 11880c1..b823aa4 100644
48499--- a/drivers/rtc/rtc-m48t59.c
48500+++ b/drivers/rtc/rtc-m48t59.c
48501@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48502 if (IS_ERR(m48t59->rtc))
48503 return PTR_ERR(m48t59->rtc);
48504
48505- m48t59_nvram_attr.size = pdata->offset;
48506+ pax_open_kernel();
48507+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48508+ pax_close_kernel();
48509
48510 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48511 if (ret)
48512diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48513index 14b5f8d..cc9bd26 100644
48514--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48515+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48516@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48517 for (bit = 0; bit < 8; bit++) {
48518
48519 if ((pci_status[i] & (0x1 << bit)) != 0) {
48520- static const char *s;
48521+ const char *s;
48522
48523 s = pci_status_strings[bit];
48524 if (i == 7/*TARG*/ && bit == 3)
48525@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48526
48527 for (bit = 0; bit < 8; bit++) {
48528
48529- if ((split_status[i] & (0x1 << bit)) != 0) {
48530- static const char *s;
48531-
48532- s = split_status_strings[bit];
48533- printk(s, ahd_name(ahd),
48534+ if ((split_status[i] & (0x1 << bit)) != 0)
48535+ printk(split_status_strings[bit], ahd_name(ahd),
48536 split_status_source[i]);
48537- }
48538
48539 if (i > 1)
48540 continue;
48541
48542- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48543- static const char *s;
48544-
48545- s = split_status_strings[bit];
48546- printk(s, ahd_name(ahd), "SG");
48547- }
48548+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48549+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48550 }
48551 }
48552 /*
48553diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48554index e693af6..2e525b6 100644
48555--- a/drivers/scsi/bfa/bfa_fcpim.h
48556+++ b/drivers/scsi/bfa/bfa_fcpim.h
48557@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48558
48559 struct bfa_itn_s {
48560 bfa_isr_func_t isr;
48561-};
48562+} __no_const;
48563
48564 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48565 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48566diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48567index a3ab5cc..8143622 100644
48568--- a/drivers/scsi/bfa/bfa_fcs.c
48569+++ b/drivers/scsi/bfa/bfa_fcs.c
48570@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48571 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48572
48573 static struct bfa_fcs_mod_s fcs_modules[] = {
48574- { bfa_fcs_port_attach, NULL, NULL },
48575- { bfa_fcs_uf_attach, NULL, NULL },
48576- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48577- bfa_fcs_fabric_modexit },
48578+ {
48579+ .attach = bfa_fcs_port_attach,
48580+ .modinit = NULL,
48581+ .modexit = NULL
48582+ },
48583+ {
48584+ .attach = bfa_fcs_uf_attach,
48585+ .modinit = NULL,
48586+ .modexit = NULL
48587+ },
48588+ {
48589+ .attach = bfa_fcs_fabric_attach,
48590+ .modinit = bfa_fcs_fabric_modinit,
48591+ .modexit = bfa_fcs_fabric_modexit
48592+ },
48593 };
48594
48595 /*
48596diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48597index ff75ef8..2dfe00a 100644
48598--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48599+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48600@@ -89,15 +89,26 @@ static struct {
48601 void (*offline) (struct bfa_fcs_lport_s *port);
48602 } __port_action[] = {
48603 {
48604- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48605- bfa_fcs_lport_unknown_offline}, {
48606- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48607- bfa_fcs_lport_fab_offline}, {
48608- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48609- bfa_fcs_lport_n2n_offline}, {
48610- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48611- bfa_fcs_lport_loop_offline},
48612- };
48613+ .init = bfa_fcs_lport_unknown_init,
48614+ .online = bfa_fcs_lport_unknown_online,
48615+ .offline = bfa_fcs_lport_unknown_offline
48616+ },
48617+ {
48618+ .init = bfa_fcs_lport_fab_init,
48619+ .online = bfa_fcs_lport_fab_online,
48620+ .offline = bfa_fcs_lport_fab_offline
48621+ },
48622+ {
48623+ .init = bfa_fcs_lport_n2n_init,
48624+ .online = bfa_fcs_lport_n2n_online,
48625+ .offline = bfa_fcs_lport_n2n_offline
48626+ },
48627+ {
48628+ .init = bfa_fcs_lport_loop_init,
48629+ .online = bfa_fcs_lport_loop_online,
48630+ .offline = bfa_fcs_lport_loop_offline
48631+ },
48632+};
48633
48634 /*
48635 * fcs_port_sm FCS logical port state machine
48636diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48637index 2e28392..9d865b6 100644
48638--- a/drivers/scsi/bfa/bfa_ioc.h
48639+++ b/drivers/scsi/bfa/bfa_ioc.h
48640@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48641 bfa_ioc_disable_cbfn_t disable_cbfn;
48642 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48643 bfa_ioc_reset_cbfn_t reset_cbfn;
48644-};
48645+} __no_const;
48646
48647 /*
48648 * IOC event notification mechanism.
48649@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48650 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48651 enum bfi_ioc_state fwstate);
48652 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48653-};
48654+} __no_const;
48655
48656 /*
48657 * Queue element to wait for room in request queue. FIFO order is
48658diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48659index a14c784..6de6790 100644
48660--- a/drivers/scsi/bfa/bfa_modules.h
48661+++ b/drivers/scsi/bfa/bfa_modules.h
48662@@ -78,12 +78,12 @@ enum {
48663 \
48664 extern struct bfa_module_s hal_mod_ ## __mod; \
48665 struct bfa_module_s hal_mod_ ## __mod = { \
48666- bfa_ ## __mod ## _meminfo, \
48667- bfa_ ## __mod ## _attach, \
48668- bfa_ ## __mod ## _detach, \
48669- bfa_ ## __mod ## _start, \
48670- bfa_ ## __mod ## _stop, \
48671- bfa_ ## __mod ## _iocdisable, \
48672+ .meminfo = bfa_ ## __mod ## _meminfo, \
48673+ .attach = bfa_ ## __mod ## _attach, \
48674+ .detach = bfa_ ## __mod ## _detach, \
48675+ .start = bfa_ ## __mod ## _start, \
48676+ .stop = bfa_ ## __mod ## _stop, \
48677+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
48678 }
48679
48680 #define BFA_CACHELINE_SZ (256)
48681diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48682index 045c4e1..13de803 100644
48683--- a/drivers/scsi/fcoe/fcoe_sysfs.c
48684+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48685@@ -33,8 +33,8 @@
48686 */
48687 #include "libfcoe.h"
48688
48689-static atomic_t ctlr_num;
48690-static atomic_t fcf_num;
48691+static atomic_unchecked_t ctlr_num;
48692+static atomic_unchecked_t fcf_num;
48693
48694 /*
48695 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48696@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48697 if (!ctlr)
48698 goto out;
48699
48700- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48701+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48702 ctlr->f = f;
48703 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48704 INIT_LIST_HEAD(&ctlr->fcfs);
48705@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48706 fcf->dev.parent = &ctlr->dev;
48707 fcf->dev.bus = &fcoe_bus_type;
48708 fcf->dev.type = &fcoe_fcf_device_type;
48709- fcf->id = atomic_inc_return(&fcf_num) - 1;
48710+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48711 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48712
48713 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48714@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48715 {
48716 int error;
48717
48718- atomic_set(&ctlr_num, 0);
48719- atomic_set(&fcf_num, 0);
48720+ atomic_set_unchecked(&ctlr_num, 0);
48721+ atomic_set_unchecked(&fcf_num, 0);
48722
48723 error = bus_register(&fcoe_bus_type);
48724 if (error)
48725diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48726index 3cbb57a..95e47a3 100644
48727--- a/drivers/scsi/hosts.c
48728+++ b/drivers/scsi/hosts.c
48729@@ -42,7 +42,7 @@
48730 #include "scsi_logging.h"
48731
48732
48733-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48734+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48735
48736
48737 static void scsi_host_cls_release(struct device *dev)
48738@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48739 * subtract one because we increment first then return, but we need to
48740 * know what the next host number was before increment
48741 */
48742- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48743+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48744 shost->dma_channel = 0xff;
48745
48746 /* These three are default values which can be overridden */
48747diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48748index 9a6e4a2..27843b6 100644
48749--- a/drivers/scsi/hpsa.c
48750+++ b/drivers/scsi/hpsa.c
48751@@ -687,10 +687,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48752 unsigned long flags;
48753
48754 if (h->transMethod & CFGTBL_Trans_io_accel1)
48755- return h->access.command_completed(h, q);
48756+ return h->access->command_completed(h, q);
48757
48758 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48759- return h->access.command_completed(h, q);
48760+ return h->access->command_completed(h, q);
48761
48762 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48763 a = rq->head[rq->current_entry];
48764@@ -5448,7 +5448,7 @@ static void start_io(struct ctlr_info *h)
48765 while (!list_empty(&h->reqQ)) {
48766 c = list_entry(h->reqQ.next, struct CommandList, list);
48767 /* can't do anything if fifo is full */
48768- if ((h->access.fifo_full(h))) {
48769+ if ((h->access->fifo_full(h))) {
48770 h->fifo_recently_full = 1;
48771 dev_warn(&h->pdev->dev, "fifo full\n");
48772 break;
48773@@ -5472,7 +5472,7 @@ static void start_io(struct ctlr_info *h)
48774
48775 /* Tell the controller execute command */
48776 spin_unlock_irqrestore(&h->lock, flags);
48777- h->access.submit_command(h, c);
48778+ h->access->submit_command(h, c);
48779 spin_lock_irqsave(&h->lock, flags);
48780 }
48781 spin_unlock_irqrestore(&h->lock, flags);
48782@@ -5480,17 +5480,17 @@ static void start_io(struct ctlr_info *h)
48783
48784 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48785 {
48786- return h->access.command_completed(h, q);
48787+ return h->access->command_completed(h, q);
48788 }
48789
48790 static inline bool interrupt_pending(struct ctlr_info *h)
48791 {
48792- return h->access.intr_pending(h);
48793+ return h->access->intr_pending(h);
48794 }
48795
48796 static inline long interrupt_not_for_us(struct ctlr_info *h)
48797 {
48798- return (h->access.intr_pending(h) == 0) ||
48799+ return (h->access->intr_pending(h) == 0) ||
48800 (h->interrupts_enabled == 0);
48801 }
48802
48803@@ -6444,7 +6444,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48804 if (prod_index < 0)
48805 return -ENODEV;
48806 h->product_name = products[prod_index].product_name;
48807- h->access = *(products[prod_index].access);
48808+ h->access = products[prod_index].access;
48809
48810 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48811 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48812@@ -6723,7 +6723,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48813 {
48814 unsigned long flags;
48815
48816- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48817+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48818 spin_lock_irqsave(&h->lock, flags);
48819 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48820 spin_unlock_irqrestore(&h->lock, flags);
48821@@ -6951,7 +6951,7 @@ reinit_after_soft_reset:
48822 }
48823
48824 /* make sure the board interrupts are off */
48825- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48826+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48827
48828 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48829 goto clean2;
48830@@ -6986,7 +6986,7 @@ reinit_after_soft_reset:
48831 * fake ones to scoop up any residual completions.
48832 */
48833 spin_lock_irqsave(&h->lock, flags);
48834- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48835+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48836 spin_unlock_irqrestore(&h->lock, flags);
48837 free_irqs(h);
48838 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48839@@ -7005,9 +7005,9 @@ reinit_after_soft_reset:
48840 dev_info(&h->pdev->dev, "Board READY.\n");
48841 dev_info(&h->pdev->dev,
48842 "Waiting for stale completions to drain.\n");
48843- h->access.set_intr_mask(h, HPSA_INTR_ON);
48844+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48845 msleep(10000);
48846- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48847+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48848
48849 rc = controller_reset_failed(h->cfgtable);
48850 if (rc)
48851@@ -7033,7 +7033,7 @@ reinit_after_soft_reset:
48852 h->drv_req_rescan = 0;
48853
48854 /* Turn the interrupts on so we can service requests */
48855- h->access.set_intr_mask(h, HPSA_INTR_ON);
48856+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48857
48858 hpsa_hba_inquiry(h);
48859 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48860@@ -7102,7 +7102,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48861 * To write all data in the battery backed cache to disks
48862 */
48863 hpsa_flush_cache(h);
48864- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48865+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48866 hpsa_free_irqs_and_disable_msix(h);
48867 }
48868
48869@@ -7220,7 +7220,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
48870 CFGTBL_Trans_enable_directed_msix |
48871 (trans_support & (CFGTBL_Trans_io_accel1 |
48872 CFGTBL_Trans_io_accel2));
48873- struct access_method access = SA5_performant_access;
48874+ struct access_method *access = &SA5_performant_access;
48875
48876 /* This is a bit complicated. There are 8 registers on
48877 * the controller which we write to to tell it 8 different
48878@@ -7285,12 +7285,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
48879 * enable outbound interrupt coalescing in accelerator mode;
48880 */
48881 if (trans_support & CFGTBL_Trans_io_accel1) {
48882- access = SA5_ioaccel_mode1_access;
48883+ access = &SA5_ioaccel_mode1_access;
48884 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
48885 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
48886 } else {
48887 if (trans_support & CFGTBL_Trans_io_accel2) {
48888- access = SA5_ioaccel_mode2_access;
48889+ access = &SA5_ioaccel_mode2_access;
48890 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
48891 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
48892 }
48893diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48894index 44235a2..962e91b 100644
48895--- a/drivers/scsi/hpsa.h
48896+++ b/drivers/scsi/hpsa.h
48897@@ -128,7 +128,7 @@ struct ctlr_info {
48898 unsigned int msix_vector;
48899 unsigned int msi_vector;
48900 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48901- struct access_method access;
48902+ struct access_method *access;
48903 char hba_mode_enabled;
48904
48905 /* queue and queue Info */
48906@@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
48907 }
48908
48909 static struct access_method SA5_access = {
48910- SA5_submit_command,
48911- SA5_intr_mask,
48912- SA5_fifo_full,
48913- SA5_intr_pending,
48914- SA5_completed,
48915+ .submit_command = SA5_submit_command,
48916+ .set_intr_mask = SA5_intr_mask,
48917+ .fifo_full = SA5_fifo_full,
48918+ .intr_pending = SA5_intr_pending,
48919+ .command_completed = SA5_completed,
48920 };
48921
48922 static struct access_method SA5_ioaccel_mode1_access = {
48923- SA5_submit_command,
48924- SA5_performant_intr_mask,
48925- SA5_fifo_full,
48926- SA5_ioaccel_mode1_intr_pending,
48927- SA5_ioaccel_mode1_completed,
48928+ .submit_command = SA5_submit_command,
48929+ .set_intr_mask = SA5_performant_intr_mask,
48930+ .fifo_full = SA5_fifo_full,
48931+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
48932+ .command_completed = SA5_ioaccel_mode1_completed,
48933 };
48934
48935 static struct access_method SA5_ioaccel_mode2_access = {
48936- SA5_submit_command_ioaccel2,
48937- SA5_performant_intr_mask,
48938- SA5_fifo_full,
48939- SA5_performant_intr_pending,
48940- SA5_performant_completed,
48941+ .submit_command = SA5_submit_command_ioaccel2,
48942+ .set_intr_mask = SA5_performant_intr_mask,
48943+ .fifo_full = SA5_fifo_full,
48944+ .intr_pending = SA5_performant_intr_pending,
48945+ .command_completed = SA5_performant_completed,
48946 };
48947
48948 static struct access_method SA5_performant_access = {
48949- SA5_submit_command,
48950- SA5_performant_intr_mask,
48951- SA5_fifo_full,
48952- SA5_performant_intr_pending,
48953- SA5_performant_completed,
48954+ .submit_command = SA5_submit_command,
48955+ .set_intr_mask = SA5_performant_intr_mask,
48956+ .fifo_full = SA5_fifo_full,
48957+ .intr_pending = SA5_performant_intr_pending,
48958+ .command_completed = SA5_performant_completed,
48959 };
48960
48961 struct board_type {
48962diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48963index 1b3a094..068e683 100644
48964--- a/drivers/scsi/libfc/fc_exch.c
48965+++ b/drivers/scsi/libfc/fc_exch.c
48966@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48967 u16 pool_max_index;
48968
48969 struct {
48970- atomic_t no_free_exch;
48971- atomic_t no_free_exch_xid;
48972- atomic_t xid_not_found;
48973- atomic_t xid_busy;
48974- atomic_t seq_not_found;
48975- atomic_t non_bls_resp;
48976+ atomic_unchecked_t no_free_exch;
48977+ atomic_unchecked_t no_free_exch_xid;
48978+ atomic_unchecked_t xid_not_found;
48979+ atomic_unchecked_t xid_busy;
48980+ atomic_unchecked_t seq_not_found;
48981+ atomic_unchecked_t non_bls_resp;
48982 } stats;
48983 };
48984
48985@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48986 /* allocate memory for exchange */
48987 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48988 if (!ep) {
48989- atomic_inc(&mp->stats.no_free_exch);
48990+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48991 goto out;
48992 }
48993 memset(ep, 0, sizeof(*ep));
48994@@ -874,7 +874,7 @@ out:
48995 return ep;
48996 err:
48997 spin_unlock_bh(&pool->lock);
48998- atomic_inc(&mp->stats.no_free_exch_xid);
48999+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49000 mempool_free(ep, mp->ep_pool);
49001 return NULL;
49002 }
49003@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49004 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49005 ep = fc_exch_find(mp, xid);
49006 if (!ep) {
49007- atomic_inc(&mp->stats.xid_not_found);
49008+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49009 reject = FC_RJT_OX_ID;
49010 goto out;
49011 }
49012@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49013 ep = fc_exch_find(mp, xid);
49014 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49015 if (ep) {
49016- atomic_inc(&mp->stats.xid_busy);
49017+ atomic_inc_unchecked(&mp->stats.xid_busy);
49018 reject = FC_RJT_RX_ID;
49019 goto rel;
49020 }
49021@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49022 }
49023 xid = ep->xid; /* get our XID */
49024 } else if (!ep) {
49025- atomic_inc(&mp->stats.xid_not_found);
49026+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49027 reject = FC_RJT_RX_ID; /* XID not found */
49028 goto out;
49029 }
49030@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49031 } else {
49032 sp = &ep->seq;
49033 if (sp->id != fh->fh_seq_id) {
49034- atomic_inc(&mp->stats.seq_not_found);
49035+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49036 if (f_ctl & FC_FC_END_SEQ) {
49037 /*
49038 * Update sequence_id based on incoming last
49039@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49040
49041 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49042 if (!ep) {
49043- atomic_inc(&mp->stats.xid_not_found);
49044+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49045 goto out;
49046 }
49047 if (ep->esb_stat & ESB_ST_COMPLETE) {
49048- atomic_inc(&mp->stats.xid_not_found);
49049+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49050 goto rel;
49051 }
49052 if (ep->rxid == FC_XID_UNKNOWN)
49053 ep->rxid = ntohs(fh->fh_rx_id);
49054 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49055- atomic_inc(&mp->stats.xid_not_found);
49056+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49057 goto rel;
49058 }
49059 if (ep->did != ntoh24(fh->fh_s_id) &&
49060 ep->did != FC_FID_FLOGI) {
49061- atomic_inc(&mp->stats.xid_not_found);
49062+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49063 goto rel;
49064 }
49065 sof = fr_sof(fp);
49066@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49067 sp->ssb_stat |= SSB_ST_RESP;
49068 sp->id = fh->fh_seq_id;
49069 } else if (sp->id != fh->fh_seq_id) {
49070- atomic_inc(&mp->stats.seq_not_found);
49071+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49072 goto rel;
49073 }
49074
49075@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49076 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49077
49078 if (!sp)
49079- atomic_inc(&mp->stats.xid_not_found);
49080+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49081 else
49082- atomic_inc(&mp->stats.non_bls_resp);
49083+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49084
49085 fc_frame_free(fp);
49086 }
49087@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49088
49089 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49090 mp = ema->mp;
49091- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49092+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49093 st->fc_no_free_exch_xid +=
49094- atomic_read(&mp->stats.no_free_exch_xid);
49095- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49096- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49097- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49098- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49099+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49100+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49101+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49102+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49103+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49104 }
49105 }
49106 EXPORT_SYMBOL(fc_exch_update_stats);
49107diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49108index 766098a..1c6c971 100644
49109--- a/drivers/scsi/libsas/sas_ata.c
49110+++ b/drivers/scsi/libsas/sas_ata.c
49111@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49112 .postreset = ata_std_postreset,
49113 .error_handler = ata_std_error_handler,
49114 .post_internal_cmd = sas_ata_post_internal,
49115- .qc_defer = ata_std_qc_defer,
49116+ .qc_defer = ata_std_qc_defer,
49117 .qc_prep = ata_noop_qc_prep,
49118 .qc_issue = sas_ata_qc_issue,
49119 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49120diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49121index 94a3caf..a118dec 100644
49122--- a/drivers/scsi/lpfc/lpfc.h
49123+++ b/drivers/scsi/lpfc/lpfc.h
49124@@ -430,7 +430,7 @@ struct lpfc_vport {
49125 struct dentry *debug_nodelist;
49126 struct dentry *vport_debugfs_root;
49127 struct lpfc_debugfs_trc *disc_trc;
49128- atomic_t disc_trc_cnt;
49129+ atomic_unchecked_t disc_trc_cnt;
49130 #endif
49131 uint8_t stat_data_enabled;
49132 uint8_t stat_data_blocked;
49133@@ -879,8 +879,8 @@ struct lpfc_hba {
49134 struct timer_list fabric_block_timer;
49135 unsigned long bit_flags;
49136 #define FABRIC_COMANDS_BLOCKED 0
49137- atomic_t num_rsrc_err;
49138- atomic_t num_cmd_success;
49139+ atomic_unchecked_t num_rsrc_err;
49140+ atomic_unchecked_t num_cmd_success;
49141 unsigned long last_rsrc_error_time;
49142 unsigned long last_ramp_down_time;
49143 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49144@@ -915,7 +915,7 @@ struct lpfc_hba {
49145
49146 struct dentry *debug_slow_ring_trc;
49147 struct lpfc_debugfs_trc *slow_ring_trc;
49148- atomic_t slow_ring_trc_cnt;
49149+ atomic_unchecked_t slow_ring_trc_cnt;
49150 /* iDiag debugfs sub-directory */
49151 struct dentry *idiag_root;
49152 struct dentry *idiag_pci_cfg;
49153diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49154index 828c08e..e3378e0 100644
49155--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49156+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49157@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49158
49159 #include <linux/debugfs.h>
49160
49161-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49162+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49163 static unsigned long lpfc_debugfs_start_time = 0L;
49164
49165 /* iDiag */
49166@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49167 lpfc_debugfs_enable = 0;
49168
49169 len = 0;
49170- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49171+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49172 (lpfc_debugfs_max_disc_trc - 1);
49173 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49174 dtp = vport->disc_trc + i;
49175@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49176 lpfc_debugfs_enable = 0;
49177
49178 len = 0;
49179- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49180+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49181 (lpfc_debugfs_max_slow_ring_trc - 1);
49182 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49183 dtp = phba->slow_ring_trc + i;
49184@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49185 !vport || !vport->disc_trc)
49186 return;
49187
49188- index = atomic_inc_return(&vport->disc_trc_cnt) &
49189+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49190 (lpfc_debugfs_max_disc_trc - 1);
49191 dtp = vport->disc_trc + index;
49192 dtp->fmt = fmt;
49193 dtp->data1 = data1;
49194 dtp->data2 = data2;
49195 dtp->data3 = data3;
49196- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49197+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49198 dtp->jif = jiffies;
49199 #endif
49200 return;
49201@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49202 !phba || !phba->slow_ring_trc)
49203 return;
49204
49205- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49206+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49207 (lpfc_debugfs_max_slow_ring_trc - 1);
49208 dtp = phba->slow_ring_trc + index;
49209 dtp->fmt = fmt;
49210 dtp->data1 = data1;
49211 dtp->data2 = data2;
49212 dtp->data3 = data3;
49213- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49214+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49215 dtp->jif = jiffies;
49216 #endif
49217 return;
49218@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49219 "slow_ring buffer\n");
49220 goto debug_failed;
49221 }
49222- atomic_set(&phba->slow_ring_trc_cnt, 0);
49223+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49224 memset(phba->slow_ring_trc, 0,
49225 (sizeof(struct lpfc_debugfs_trc) *
49226 lpfc_debugfs_max_slow_ring_trc));
49227@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49228 "buffer\n");
49229 goto debug_failed;
49230 }
49231- atomic_set(&vport->disc_trc_cnt, 0);
49232+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49233
49234 snprintf(name, sizeof(name), "discovery_trace");
49235 vport->debug_disc_trc =
49236diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49237index 635eeb3..038aef6 100644
49238--- a/drivers/scsi/lpfc/lpfc_init.c
49239+++ b/drivers/scsi/lpfc/lpfc_init.c
49240@@ -11194,8 +11194,10 @@ lpfc_init(void)
49241 "misc_register returned with status %d", error);
49242
49243 if (lpfc_enable_npiv) {
49244- lpfc_transport_functions.vport_create = lpfc_vport_create;
49245- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49246+ pax_open_kernel();
49247+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49248+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49249+ pax_close_kernel();
49250 }
49251 lpfc_transport_template =
49252 fc_attach_transport(&lpfc_transport_functions);
49253diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49254index 462453e..c0023a6 100644
49255--- a/drivers/scsi/lpfc/lpfc_scsi.c
49256+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49257@@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49258 uint32_t evt_posted;
49259
49260 spin_lock_irqsave(&phba->hbalock, flags);
49261- atomic_inc(&phba->num_rsrc_err);
49262+ atomic_inc_unchecked(&phba->num_rsrc_err);
49263 phba->last_rsrc_error_time = jiffies;
49264
49265 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49266@@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49267 unsigned long num_rsrc_err, num_cmd_success;
49268 int i;
49269
49270- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49271- num_cmd_success = atomic_read(&phba->num_cmd_success);
49272+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49273+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49274
49275 /*
49276 * The error and success command counters are global per
49277@@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49278 }
49279 }
49280 lpfc_destroy_vport_work_array(phba, vports);
49281- atomic_set(&phba->num_rsrc_err, 0);
49282- atomic_set(&phba->num_cmd_success, 0);
49283+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49284+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49285 }
49286
49287 /**
49288diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49289index 6fd7d40..b444223 100644
49290--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49291+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49292@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49293 {
49294 struct scsi_device *sdev = to_scsi_device(dev);
49295 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49296- static struct _raid_device *raid_device;
49297+ struct _raid_device *raid_device;
49298 unsigned long flags;
49299 Mpi2RaidVolPage0_t vol_pg0;
49300 Mpi2ConfigReply_t mpi_reply;
49301@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49302 {
49303 struct scsi_device *sdev = to_scsi_device(dev);
49304 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49305- static struct _raid_device *raid_device;
49306+ struct _raid_device *raid_device;
49307 unsigned long flags;
49308 Mpi2RaidVolPage0_t vol_pg0;
49309 Mpi2ConfigReply_t mpi_reply;
49310@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49311 struct fw_event_work *fw_event)
49312 {
49313 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49314- static struct _raid_device *raid_device;
49315+ struct _raid_device *raid_device;
49316 unsigned long flags;
49317 u16 handle;
49318
49319@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49320 u64 sas_address;
49321 struct _sas_device *sas_device;
49322 struct _sas_node *expander_device;
49323- static struct _raid_device *raid_device;
49324+ struct _raid_device *raid_device;
49325 u8 retry_count;
49326 unsigned long flags;
49327
49328diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49329index be8ce54..94ed33a 100644
49330--- a/drivers/scsi/pmcraid.c
49331+++ b/drivers/scsi/pmcraid.c
49332@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49333 res->scsi_dev = scsi_dev;
49334 scsi_dev->hostdata = res;
49335 res->change_detected = 0;
49336- atomic_set(&res->read_failures, 0);
49337- atomic_set(&res->write_failures, 0);
49338+ atomic_set_unchecked(&res->read_failures, 0);
49339+ atomic_set_unchecked(&res->write_failures, 0);
49340 rc = 0;
49341 }
49342 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49343@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49344
49345 /* If this was a SCSI read/write command keep count of errors */
49346 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49347- atomic_inc(&res->read_failures);
49348+ atomic_inc_unchecked(&res->read_failures);
49349 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49350- atomic_inc(&res->write_failures);
49351+ atomic_inc_unchecked(&res->write_failures);
49352
49353 if (!RES_IS_GSCSI(res->cfg_entry) &&
49354 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49355@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49356 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49357 * hrrq_id assigned here in queuecommand
49358 */
49359- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49360+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49361 pinstance->num_hrrq;
49362 cmd->cmd_done = pmcraid_io_done;
49363
49364@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49365 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49366 * hrrq_id assigned here in queuecommand
49367 */
49368- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49369+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49370 pinstance->num_hrrq;
49371
49372 if (request_size) {
49373@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49374
49375 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49376 /* add resources only after host is added into system */
49377- if (!atomic_read(&pinstance->expose_resources))
49378+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49379 return;
49380
49381 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49382@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49383 init_waitqueue_head(&pinstance->reset_wait_q);
49384
49385 atomic_set(&pinstance->outstanding_cmds, 0);
49386- atomic_set(&pinstance->last_message_id, 0);
49387- atomic_set(&pinstance->expose_resources, 0);
49388+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49389+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49390
49391 INIT_LIST_HEAD(&pinstance->free_res_q);
49392 INIT_LIST_HEAD(&pinstance->used_res_q);
49393@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49394 /* Schedule worker thread to handle CCN and take care of adding and
49395 * removing devices to OS
49396 */
49397- atomic_set(&pinstance->expose_resources, 1);
49398+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49399 schedule_work(&pinstance->worker_q);
49400 return rc;
49401
49402diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49403index e1d150f..6c6df44 100644
49404--- a/drivers/scsi/pmcraid.h
49405+++ b/drivers/scsi/pmcraid.h
49406@@ -748,7 +748,7 @@ struct pmcraid_instance {
49407 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49408
49409 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49410- atomic_t last_message_id;
49411+ atomic_unchecked_t last_message_id;
49412
49413 /* configuration table */
49414 struct pmcraid_config_table *cfg_table;
49415@@ -777,7 +777,7 @@ struct pmcraid_instance {
49416 atomic_t outstanding_cmds;
49417
49418 /* should add/delete resources to mid-layer now ?*/
49419- atomic_t expose_resources;
49420+ atomic_unchecked_t expose_resources;
49421
49422
49423
49424@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49425 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49426 };
49427 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49428- atomic_t read_failures; /* count of failed READ commands */
49429- atomic_t write_failures; /* count of failed WRITE commands */
49430+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49431+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49432
49433 /* To indicate add/delete/modify during CCN */
49434 u8 change_detected;
49435diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49436index 07befcf..c0bff13 100644
49437--- a/drivers/scsi/qla2xxx/qla_attr.c
49438+++ b/drivers/scsi/qla2xxx/qla_attr.c
49439@@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49440 return 0;
49441 }
49442
49443-struct fc_function_template qla2xxx_transport_functions = {
49444+fc_function_template_no_const qla2xxx_transport_functions = {
49445
49446 .show_host_node_name = 1,
49447 .show_host_port_name = 1,
49448@@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49449 .bsg_timeout = qla24xx_bsg_timeout,
49450 };
49451
49452-struct fc_function_template qla2xxx_transport_vport_functions = {
49453+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49454
49455 .show_host_node_name = 1,
49456 .show_host_port_name = 1,
49457diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49458index e665e81..16e84e6 100644
49459--- a/drivers/scsi/qla2xxx/qla_gbl.h
49460+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49461@@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49462 struct device_attribute;
49463 extern struct device_attribute *qla2x00_host_attrs[];
49464 struct fc_function_template;
49465-extern struct fc_function_template qla2xxx_transport_functions;
49466-extern struct fc_function_template qla2xxx_transport_vport_functions;
49467+extern fc_function_template_no_const qla2xxx_transport_functions;
49468+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49469 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49470 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49471 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49472diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49473index 19e99cc..b3c0b7b 100644
49474--- a/drivers/scsi/qla2xxx/qla_os.c
49475+++ b/drivers/scsi/qla2xxx/qla_os.c
49476@@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49477 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49478 /* Ok, a 64bit DMA mask is applicable. */
49479 ha->flags.enable_64bit_addressing = 1;
49480- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49481- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49482+ pax_open_kernel();
49483+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49484+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49485+ pax_close_kernel();
49486 return;
49487 }
49488 }
49489diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49490index 73a5022..4e0797c 100644
49491--- a/drivers/scsi/qla4xxx/ql4_def.h
49492+++ b/drivers/scsi/qla4xxx/ql4_def.h
49493@@ -305,7 +305,7 @@ struct ddb_entry {
49494 * (4000 only) */
49495 atomic_t relogin_timer; /* Max Time to wait for
49496 * relogin to complete */
49497- atomic_t relogin_retry_count; /* Num of times relogin has been
49498+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49499 * retried */
49500 uint32_t default_time2wait; /* Default Min time between
49501 * relogins (+aens) */
49502diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49503index 459b9f7..2930a68 100644
49504--- a/drivers/scsi/qla4xxx/ql4_os.c
49505+++ b/drivers/scsi/qla4xxx/ql4_os.c
49506@@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49507 */
49508 if (!iscsi_is_session_online(cls_sess)) {
49509 /* Reset retry relogin timer */
49510- atomic_inc(&ddb_entry->relogin_retry_count);
49511+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49512 DEBUG2(ql4_printk(KERN_INFO, ha,
49513 "%s: index[%d] relogin timed out-retrying"
49514 " relogin (%d), retry (%d)\n", __func__,
49515 ddb_entry->fw_ddb_index,
49516- atomic_read(&ddb_entry->relogin_retry_count),
49517+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49518 ddb_entry->default_time2wait + 4));
49519 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49520 atomic_set(&ddb_entry->retry_relogin_timer,
49521@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49522
49523 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49524 atomic_set(&ddb_entry->relogin_timer, 0);
49525- atomic_set(&ddb_entry->relogin_retry_count, 0);
49526+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49527 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49528 ddb_entry->default_relogin_timeout =
49529 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49530diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49531index 88d46fe..7351be5 100644
49532--- a/drivers/scsi/scsi.c
49533+++ b/drivers/scsi/scsi.c
49534@@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49535 struct Scsi_Host *host = cmd->device->host;
49536 int rtn = 0;
49537
49538- atomic_inc(&cmd->device->iorequest_cnt);
49539+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49540
49541 /* check if the device is still usable */
49542 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49543diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49544index 9db097a..ca5c291 100644
49545--- a/drivers/scsi/scsi_lib.c
49546+++ b/drivers/scsi/scsi_lib.c
49547@@ -1464,7 +1464,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49548 shost = sdev->host;
49549 scsi_init_cmd_errh(cmd);
49550 cmd->result = DID_NO_CONNECT << 16;
49551- atomic_inc(&cmd->device->iorequest_cnt);
49552+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49553
49554 /*
49555 * SCSI request completion path will do scsi_device_unbusy(),
49556@@ -1490,9 +1490,9 @@ static void scsi_softirq_done(struct request *rq)
49557
49558 INIT_LIST_HEAD(&cmd->eh_entry);
49559
49560- atomic_inc(&cmd->device->iodone_cnt);
49561+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49562 if (cmd->result)
49563- atomic_inc(&cmd->device->ioerr_cnt);
49564+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49565
49566 disposition = scsi_decide_disposition(cmd);
49567 if (disposition != SUCCESS &&
49568diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49569index 074e8cc..f612e5c 100644
49570--- a/drivers/scsi/scsi_sysfs.c
49571+++ b/drivers/scsi/scsi_sysfs.c
49572@@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49573 char *buf) \
49574 { \
49575 struct scsi_device *sdev = to_scsi_device(dev); \
49576- unsigned long long count = atomic_read(&sdev->field); \
49577+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49578 return snprintf(buf, 20, "0x%llx\n", count); \
49579 } \
49580 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49581diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49582index e51add0..1e06a96 100644
49583--- a/drivers/scsi/scsi_tgt_lib.c
49584+++ b/drivers/scsi/scsi_tgt_lib.c
49585@@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49586 int err;
49587
49588 dprintk("%lx %u\n", uaddr, len);
49589- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49590+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49591 if (err) {
49592 /*
49593 * TODO: need to fixup sg_tablesize, max_segment_size,
49594diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49595index f80908f..22aba76 100644
49596--- a/drivers/scsi/scsi_transport_fc.c
49597+++ b/drivers/scsi/scsi_transport_fc.c
49598@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49599 * Netlink Infrastructure
49600 */
49601
49602-static atomic_t fc_event_seq;
49603+static atomic_unchecked_t fc_event_seq;
49604
49605 /**
49606 * fc_get_event_number - Obtain the next sequential FC event number
49607@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
49608 u32
49609 fc_get_event_number(void)
49610 {
49611- return atomic_add_return(1, &fc_event_seq);
49612+ return atomic_add_return_unchecked(1, &fc_event_seq);
49613 }
49614 EXPORT_SYMBOL(fc_get_event_number);
49615
49616@@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
49617 {
49618 int error;
49619
49620- atomic_set(&fc_event_seq, 0);
49621+ atomic_set_unchecked(&fc_event_seq, 0);
49622
49623 error = transport_class_register(&fc_host_class);
49624 if (error)
49625@@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49626 char *cp;
49627
49628 *val = simple_strtoul(buf, &cp, 0);
49629- if ((*cp && (*cp != '\n')) || (*val < 0))
49630+ if (*cp && (*cp != '\n'))
49631 return -EINVAL;
49632 /*
49633 * Check for overflow; dev_loss_tmo is u32
49634diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49635index 0102a2d..cc3f8e9 100644
49636--- a/drivers/scsi/scsi_transport_iscsi.c
49637+++ b/drivers/scsi/scsi_transport_iscsi.c
49638@@ -79,7 +79,7 @@ struct iscsi_internal {
49639 struct transport_container session_cont;
49640 };
49641
49642-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49643+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49644 static struct workqueue_struct *iscsi_eh_timer_workq;
49645
49646 static DEFINE_IDA(iscsi_sess_ida);
49647@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49648 int err;
49649
49650 ihost = shost->shost_data;
49651- session->sid = atomic_add_return(1, &iscsi_session_nr);
49652+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49653
49654 if (target_id == ISCSI_MAX_TARGET) {
49655 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49656@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49657 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49658 ISCSI_TRANSPORT_VERSION);
49659
49660- atomic_set(&iscsi_session_nr, 0);
49661+ atomic_set_unchecked(&iscsi_session_nr, 0);
49662
49663 err = class_register(&iscsi_transport_class);
49664 if (err)
49665diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49666index 13e8983..d306a68 100644
49667--- a/drivers/scsi/scsi_transport_srp.c
49668+++ b/drivers/scsi/scsi_transport_srp.c
49669@@ -36,7 +36,7 @@
49670 #include "scsi_transport_srp_internal.h"
49671
49672 struct srp_host_attrs {
49673- atomic_t next_port_id;
49674+ atomic_unchecked_t next_port_id;
49675 };
49676 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49677
49678@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49679 struct Scsi_Host *shost = dev_to_shost(dev);
49680 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49681
49682- atomic_set(&srp_host->next_port_id, 0);
49683+ atomic_set_unchecked(&srp_host->next_port_id, 0);
49684 return 0;
49685 }
49686
49687@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49688 rport_fast_io_fail_timedout);
49689 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49690
49691- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49692+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49693 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49694
49695 transport_setup_device(&rport->dev);
49696diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49697index efcbcd1..aeaf26e 100644
49698--- a/drivers/scsi/sd.c
49699+++ b/drivers/scsi/sd.c
49700@@ -2968,7 +2968,7 @@ static int sd_probe(struct device *dev)
49701 sdkp->disk = gd;
49702 sdkp->index = index;
49703 atomic_set(&sdkp->openers, 0);
49704- atomic_set(&sdkp->device->ioerr_cnt, 0);
49705+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49706
49707 if (!sdp->request_queue->rq_timeout) {
49708 if (sdp->type != TYPE_MOD)
49709diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49710index df5e961..df6b97f 100644
49711--- a/drivers/scsi/sg.c
49712+++ b/drivers/scsi/sg.c
49713@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49714 sdp->disk->disk_name,
49715 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49716 NULL,
49717- (char *)arg);
49718+ (char __user *)arg);
49719 case BLKTRACESTART:
49720 return blk_trace_startstop(sdp->device->request_queue, 1);
49721 case BLKTRACESTOP:
49722diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49723index 939edf4..3f50423 100644
49724--- a/drivers/spi/spi.c
49725+++ b/drivers/spi/spi.c
49726@@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
49727 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49728
49729 /* portable code must never pass more than 32 bytes */
49730-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49731+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49732
49733 static u8 *buf;
49734
49735diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49736index 2c61783..4d49e4e 100644
49737--- a/drivers/staging/android/timed_output.c
49738+++ b/drivers/staging/android/timed_output.c
49739@@ -25,7 +25,7 @@
49740 #include "timed_output.h"
49741
49742 static struct class *timed_output_class;
49743-static atomic_t device_count;
49744+static atomic_unchecked_t device_count;
49745
49746 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49747 char *buf)
49748@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49749 timed_output_class = class_create(THIS_MODULE, "timed_output");
49750 if (IS_ERR(timed_output_class))
49751 return PTR_ERR(timed_output_class);
49752- atomic_set(&device_count, 0);
49753+ atomic_set_unchecked(&device_count, 0);
49754 timed_output_class->dev_groups = timed_output_groups;
49755 }
49756
49757@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49758 if (ret < 0)
49759 return ret;
49760
49761- tdev->index = atomic_inc_return(&device_count);
49762+ tdev->index = atomic_inc_return_unchecked(&device_count);
49763 tdev->dev = device_create(timed_output_class, NULL,
49764 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49765 if (IS_ERR(tdev->dev))
49766diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49767index fe47cd3..19a1bd1 100644
49768--- a/drivers/staging/gdm724x/gdm_tty.c
49769+++ b/drivers/staging/gdm724x/gdm_tty.c
49770@@ -44,7 +44,7 @@
49771 #define gdm_tty_send_control(n, r, v, d, l) (\
49772 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49773
49774-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49775+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49776
49777 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49778 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49779diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49780index c270c9a..94ddf82 100644
49781--- a/drivers/staging/imx-drm/imx-drm-core.c
49782+++ b/drivers/staging/imx-drm/imx-drm-core.c
49783@@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
49784 if (imxdrm->pipes >= MAX_CRTC)
49785 return -EINVAL;
49786
49787- if (imxdrm->drm->open_count)
49788+ if (local_read(&imxdrm->drm->open_count))
49789 return -EBUSY;
49790
49791 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
49792diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49793index 3f8020c..649fded 100644
49794--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49795+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49796@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49797 return 0;
49798 }
49799
49800-sfw_test_client_ops_t brw_test_client;
49801-void brw_init_test_client(void)
49802-{
49803- brw_test_client.tso_init = brw_client_init;
49804- brw_test_client.tso_fini = brw_client_fini;
49805- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49806- brw_test_client.tso_done_rpc = brw_client_done_rpc;
49807+sfw_test_client_ops_t brw_test_client = {
49808+ .tso_init = brw_client_init,
49809+ .tso_fini = brw_client_fini,
49810+ .tso_prep_rpc = brw_client_prep_rpc,
49811+ .tso_done_rpc = brw_client_done_rpc,
49812 };
49813
49814 srpc_service_t brw_test_service;
49815diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49816index 050723a..fa6fdf1 100644
49817--- a/drivers/staging/lustre/lnet/selftest/framework.c
49818+++ b/drivers/staging/lustre/lnet/selftest/framework.c
49819@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49820
49821 extern sfw_test_client_ops_t ping_test_client;
49822 extern srpc_service_t ping_test_service;
49823-extern void ping_init_test_client(void);
49824 extern void ping_init_test_service(void);
49825
49826 extern sfw_test_client_ops_t brw_test_client;
49827 extern srpc_service_t brw_test_service;
49828-extern void brw_init_test_client(void);
49829 extern void brw_init_test_service(void);
49830
49831
49832@@ -1684,12 +1682,10 @@ sfw_startup (void)
49833 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49834 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49835
49836- brw_init_test_client();
49837 brw_init_test_service();
49838 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49839 LASSERT (rc == 0);
49840
49841- ping_init_test_client();
49842 ping_init_test_service();
49843 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49844 LASSERT (rc == 0);
49845diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49846index 750cac4..e4d751f 100644
49847--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49848+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49849@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49850 return 0;
49851 }
49852
49853-sfw_test_client_ops_t ping_test_client;
49854-void ping_init_test_client(void)
49855-{
49856- ping_test_client.tso_init = ping_client_init;
49857- ping_test_client.tso_fini = ping_client_fini;
49858- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49859- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49860-}
49861+sfw_test_client_ops_t ping_test_client = {
49862+ .tso_init = ping_client_init,
49863+ .tso_fini = ping_client_fini,
49864+ .tso_prep_rpc = ping_client_prep_rpc,
49865+ .tso_done_rpc = ping_client_done_rpc,
49866+};
49867
49868 srpc_service_t ping_test_service;
49869 void ping_init_test_service(void)
49870diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49871index 3e25f00..0d59cf5 100644
49872--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49873+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49874@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49875 ldlm_completion_callback lcs_completion;
49876 ldlm_blocking_callback lcs_blocking;
49877 ldlm_glimpse_callback lcs_glimpse;
49878-};
49879+} __no_const;
49880
49881 /* ldlm_lockd.c */
49882 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49883diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49884index 72cf3fe..4beac19 100644
49885--- a/drivers/staging/lustre/lustre/include/obd.h
49886+++ b/drivers/staging/lustre/lustre/include/obd.h
49887@@ -1427,7 +1427,7 @@ struct md_ops {
49888 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49889 * wrapper function in include/linux/obd_class.h.
49890 */
49891-};
49892+} __no_const;
49893
49894 struct lsm_operations {
49895 void (*lsm_free)(struct lov_stripe_md *);
49896diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49897index 986bf38..eab2558f 100644
49898--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49899+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49900@@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49901 int added = (mode == LCK_NL);
49902 int overlaps = 0;
49903 int splitted = 0;
49904- const struct ldlm_callback_suite null_cbs = { NULL };
49905+ const struct ldlm_callback_suite null_cbs = { };
49906
49907 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49908 LPU64" end "LPU64"\n", *flags,
49909diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49910index e947b91..f408990 100644
49911--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49912+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49913@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49914 int LL_PROC_PROTO(proc_console_max_delay_cs)
49915 {
49916 int rc, max_delay_cs;
49917- ctl_table_t dummy = *table;
49918+ ctl_table_no_const dummy = *table;
49919 cfs_duration_t d;
49920
49921 dummy.data = &max_delay_cs;
49922@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49923 int LL_PROC_PROTO(proc_console_min_delay_cs)
49924 {
49925 int rc, min_delay_cs;
49926- ctl_table_t dummy = *table;
49927+ ctl_table_no_const dummy = *table;
49928 cfs_duration_t d;
49929
49930 dummy.data = &min_delay_cs;
49931@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49932 int LL_PROC_PROTO(proc_console_backoff)
49933 {
49934 int rc, backoff;
49935- ctl_table_t dummy = *table;
49936+ ctl_table_no_const dummy = *table;
49937
49938 dummy.data = &backoff;
49939 dummy.proc_handler = &proc_dointvec;
49940diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49941index 24ae26d..9d09cab 100644
49942--- a/drivers/staging/lustre/lustre/libcfs/module.c
49943+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49944@@ -313,11 +313,11 @@ out:
49945
49946
49947 struct cfs_psdev_ops libcfs_psdev_ops = {
49948- libcfs_psdev_open,
49949- libcfs_psdev_release,
49950- NULL,
49951- NULL,
49952- libcfs_ioctl
49953+ .p_open = libcfs_psdev_open,
49954+ .p_close = libcfs_psdev_release,
49955+ .p_read = NULL,
49956+ .p_write = NULL,
49957+ .p_ioctl = libcfs_ioctl
49958 };
49959
49960 extern int insert_proc(void);
49961diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49962index 7fbc18e..f982071 100644
49963--- a/drivers/staging/lustre/lustre/llite/dir.c
49964+++ b/drivers/staging/lustre/lustre/llite/dir.c
49965@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49966 int mode;
49967 int err;
49968
49969- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49970+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49971 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49972 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49973 lump);
49974diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49975index f670469..03b7438 100644
49976--- a/drivers/staging/media/solo6x10/solo6x10-core.c
49977+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49978@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49979
49980 static int solo_sysfs_init(struct solo_dev *solo_dev)
49981 {
49982- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49983+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49984 struct device *dev = &solo_dev->dev;
49985 const char *driver;
49986 int i;
49987diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49988index 74f037b..5b5bb76 100644
49989--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49990+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49991@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49992
49993 int solo_g723_init(struct solo_dev *solo_dev)
49994 {
49995- static struct snd_device_ops ops = { NULL };
49996+ static struct snd_device_ops ops = { };
49997 struct snd_card *card;
49998 struct snd_kcontrol_new kctl;
49999 char name[32];
50000diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50001index 7f2f247..d999137 100644
50002--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50003+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50004@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50005
50006 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50007 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50008- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50009+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50010 if (p2m_id < 0)
50011 p2m_id = -p2m_id;
50012 }
50013diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50014index 8964f8b..36eb087 100644
50015--- a/drivers/staging/media/solo6x10/solo6x10.h
50016+++ b/drivers/staging/media/solo6x10/solo6x10.h
50017@@ -237,7 +237,7 @@ struct solo_dev {
50018
50019 /* P2M DMA Engine */
50020 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50021- atomic_t p2m_count;
50022+ atomic_unchecked_t p2m_count;
50023 int p2m_jiffies;
50024 unsigned int p2m_timeouts;
50025
50026diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50027index a0f4868..139f1fb 100644
50028--- a/drivers/staging/octeon/ethernet-rx.c
50029+++ b/drivers/staging/octeon/ethernet-rx.c
50030@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50031 /* Increment RX stats for virtual ports */
50032 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50033 #ifdef CONFIG_64BIT
50034- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50035- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50036+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50037+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50038 #else
50039- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50040- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50041+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50042+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50043 #endif
50044 }
50045 netif_receive_skb(skb);
50046@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50047 dev->name);
50048 */
50049 #ifdef CONFIG_64BIT
50050- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50051+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50052 #else
50053- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50054+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50055 #endif
50056 dev_kfree_skb_irq(skb);
50057 }
50058diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50059index ff7214a..6dd90f0 100644
50060--- a/drivers/staging/octeon/ethernet.c
50061+++ b/drivers/staging/octeon/ethernet.c
50062@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50063 * since the RX tasklet also increments it.
50064 */
50065 #ifdef CONFIG_64BIT
50066- atomic64_add(rx_status.dropped_packets,
50067- (atomic64_t *)&priv->stats.rx_dropped);
50068+ atomic64_add_unchecked(rx_status.dropped_packets,
50069+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50070 #else
50071- atomic_add(rx_status.dropped_packets,
50072- (atomic_t *)&priv->stats.rx_dropped);
50073+ atomic_add_unchecked(rx_status.dropped_packets,
50074+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50075 #endif
50076 }
50077
50078diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50079index c274b34..f84de76 100644
50080--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50081+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50082@@ -271,7 +271,7 @@ struct hal_ops {
50083 s32 (*c2h_handler)(struct adapter *padapter,
50084 struct c2h_evt_hdr *c2h_evt);
50085 c2h_id_filter c2h_id_filter_ccx;
50086-};
50087+} __no_const;
50088
50089 enum rt_eeprom_type {
50090 EEPROM_93C46,
50091diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50092index e8790f8..b4a5980 100644
50093--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50094+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50095@@ -124,7 +124,7 @@ struct _io_ops {
50096 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50097 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50098 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50099-};
50100+} __no_const;
50101
50102 struct io_req {
50103 struct list_head list;
50104diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50105index dc23395..cf7e9b1 100644
50106--- a/drivers/staging/rtl8712/rtl871x_io.h
50107+++ b/drivers/staging/rtl8712/rtl871x_io.h
50108@@ -108,7 +108,7 @@ struct _io_ops {
50109 u8 *pmem);
50110 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50111 u8 *pmem);
50112-};
50113+} __no_const;
50114
50115 struct io_req {
50116 struct list_head list;
50117diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50118index d183f4b..3f4903d 100644
50119--- a/drivers/staging/rtl8723au/include/hal_intf.h
50120+++ b/drivers/staging/rtl8723au/include/hal_intf.h
50121@@ -251,7 +251,7 @@ struct hal_ops {
50122 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50123 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50124 c2h_id_filter c2h_id_filter_ccx;
50125-};
50126+} __no_const;
50127
50128 enum rt_eeprom_type {
50129 EEPROM_93C46,
50130diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50131index 8d39d800..3f21c0c 100644
50132--- a/drivers/staging/rtl8723au/include/rtw_io.h
50133+++ b/drivers/staging/rtl8723au/include/rtw_io.h
50134@@ -130,7 +130,7 @@ struct _io_ops
50135 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50136 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50137
50138-};
50139+} __no_const;
50140
50141 struct io_req {
50142 struct list_head list;
50143diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50144index fe6c951..72935ba 100644
50145--- a/drivers/staging/sbe-2t3e3/netdev.c
50146+++ b/drivers/staging/sbe-2t3e3/netdev.c
50147@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50148 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50149
50150 if (rlen)
50151- if (copy_to_user(data, &resp, rlen))
50152+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50153 return -EFAULT;
50154
50155 return 0;
50156diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50157index a863a98..d272795 100644
50158--- a/drivers/staging/usbip/vhci.h
50159+++ b/drivers/staging/usbip/vhci.h
50160@@ -83,7 +83,7 @@ struct vhci_hcd {
50161 unsigned resuming:1;
50162 unsigned long re_timeout;
50163
50164- atomic_t seqnum;
50165+ atomic_unchecked_t seqnum;
50166
50167 /*
50168 * NOTE:
50169diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50170index 70e1755..de41855 100644
50171--- a/drivers/staging/usbip/vhci_hcd.c
50172+++ b/drivers/staging/usbip/vhci_hcd.c
50173@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50174
50175 spin_lock(&vdev->priv_lock);
50176
50177- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50178+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50179 if (priv->seqnum == 0xffff)
50180 dev_info(&urb->dev->dev, "seqnum max\n");
50181
50182@@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50183 return -ENOMEM;
50184 }
50185
50186- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50187+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50188 if (unlink->seqnum == 0xffff)
50189 pr_info("seqnum max\n");
50190
50191@@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50192 vdev->rhport = rhport;
50193 }
50194
50195- atomic_set(&vhci->seqnum, 0);
50196+ atomic_set_unchecked(&vhci->seqnum, 0);
50197 spin_lock_init(&vhci->lock);
50198
50199 hcd->power_budget = 0; /* no limit */
50200diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50201index d07fcb5..358e1e1 100644
50202--- a/drivers/staging/usbip/vhci_rx.c
50203+++ b/drivers/staging/usbip/vhci_rx.c
50204@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50205 if (!urb) {
50206 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50207 pr_info("max seqnum %d\n",
50208- atomic_read(&the_controller->seqnum));
50209+ atomic_read_unchecked(&the_controller->seqnum));
50210 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50211 return;
50212 }
50213diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50214index 6eecd53..29317c6 100644
50215--- a/drivers/staging/vt6655/hostap.c
50216+++ b/drivers/staging/vt6655/hostap.c
50217@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50218 *
50219 */
50220
50221+static net_device_ops_no_const apdev_netdev_ops;
50222+
50223 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50224 {
50225 PSDevice apdev_priv;
50226 struct net_device *dev = pDevice->dev;
50227 int ret;
50228- const struct net_device_ops apdev_netdev_ops = {
50229- .ndo_start_xmit = pDevice->tx_80211,
50230- };
50231
50232 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50233
50234@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50235 *apdev_priv = *pDevice;
50236 eth_hw_addr_inherit(pDevice->apdev, dev);
50237
50238+ /* only half broken now */
50239+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50240 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50241
50242 pDevice->apdev->type = ARPHRD_IEEE80211;
50243diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50244index 67ba48b..24e602f 100644
50245--- a/drivers/staging/vt6656/hostap.c
50246+++ b/drivers/staging/vt6656/hostap.c
50247@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50248 *
50249 */
50250
50251+static net_device_ops_no_const apdev_netdev_ops;
50252+
50253 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50254 {
50255 struct vnt_private *apdev_priv;
50256 struct net_device *dev = pDevice->dev;
50257 int ret;
50258- const struct net_device_ops apdev_netdev_ops = {
50259- .ndo_start_xmit = pDevice->tx_80211,
50260- };
50261
50262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50263
50264@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50265 *apdev_priv = *pDevice;
50266 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50267
50268+ /* only half broken now */
50269+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50270 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50271
50272 pDevice->apdev->type = ARPHRD_IEEE80211;
50273diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50274index e7e9372..161f530 100644
50275--- a/drivers/target/sbp/sbp_target.c
50276+++ b/drivers/target/sbp/sbp_target.c
50277@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50278
50279 #define SESSION_MAINTENANCE_INTERVAL HZ
50280
50281-static atomic_t login_id = ATOMIC_INIT(0);
50282+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50283
50284 static void session_maintenance_work(struct work_struct *);
50285 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50286@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50287 login->lun = se_lun;
50288 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50289 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50290- login->login_id = atomic_inc_return(&login_id);
50291+ login->login_id = atomic_inc_return_unchecked(&login_id);
50292
50293 login->tgt_agt = sbp_target_agent_register(login);
50294 if (IS_ERR(login->tgt_agt)) {
50295diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50296index 26416c1..e796a3d 100644
50297--- a/drivers/target/target_core_device.c
50298+++ b/drivers/target/target_core_device.c
50299@@ -1524,7 +1524,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50300 spin_lock_init(&dev->se_tmr_lock);
50301 spin_lock_init(&dev->qf_cmd_lock);
50302 sema_init(&dev->caw_sem, 1);
50303- atomic_set(&dev->dev_ordered_id, 0);
50304+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50305 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50306 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50307 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50308diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50309index 14772e9..42d9f63 100644
50310--- a/drivers/target/target_core_transport.c
50311+++ b/drivers/target/target_core_transport.c
50312@@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50313 * Used to determine when ORDERED commands should go from
50314 * Dormant to Active status.
50315 */
50316- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50317+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50318 smp_mb__after_atomic_inc();
50319 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50320 cmd->se_ordered_id, cmd->sam_task_attr,
50321diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50322index 04b1be7..5eff86d 100644
50323--- a/drivers/thermal/of-thermal.c
50324+++ b/drivers/thermal/of-thermal.c
50325@@ -30,6 +30,7 @@
50326 #include <linux/err.h>
50327 #include <linux/export.h>
50328 #include <linux/string.h>
50329+#include <linux/mm.h>
50330
50331 #include "thermal_core.h"
50332
50333@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50334 tz->get_trend = get_trend;
50335 tz->sensor_data = data;
50336
50337- tzd->ops->get_temp = of_thermal_get_temp;
50338- tzd->ops->get_trend = of_thermal_get_trend;
50339+ pax_open_kernel();
50340+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50341+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50342+ pax_close_kernel();
50343 mutex_unlock(&tzd->lock);
50344
50345 return tzd;
50346@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50347 return;
50348
50349 mutex_lock(&tzd->lock);
50350- tzd->ops->get_temp = NULL;
50351- tzd->ops->get_trend = NULL;
50352+ pax_open_kernel();
50353+ *(void **)&tzd->ops->get_temp = NULL;
50354+ *(void **)&tzd->ops->get_trend = NULL;
50355+ pax_close_kernel();
50356
50357 tz->get_temp = NULL;
50358 tz->get_trend = NULL;
50359diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50360index a57bb5a..1f727d33 100644
50361--- a/drivers/tty/cyclades.c
50362+++ b/drivers/tty/cyclades.c
50363@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50364 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50365 info->port.count);
50366 #endif
50367- info->port.count++;
50368+ atomic_inc(&info->port.count);
50369 #ifdef CY_DEBUG_COUNT
50370 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50371- current->pid, info->port.count);
50372+ current->pid, atomic_read(&info->port.count));
50373 #endif
50374
50375 /*
50376@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50377 for (j = 0; j < cy_card[i].nports; j++) {
50378 info = &cy_card[i].ports[j];
50379
50380- if (info->port.count) {
50381+ if (atomic_read(&info->port.count)) {
50382 /* XXX is the ldisc num worth this? */
50383 struct tty_struct *tty;
50384 struct tty_ldisc *ld;
50385diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50386index 0ff7fda..dbc7d52 100644
50387--- a/drivers/tty/hvc/hvc_console.c
50388+++ b/drivers/tty/hvc/hvc_console.c
50389@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50390
50391 spin_lock_irqsave(&hp->port.lock, flags);
50392 /* Check and then increment for fast path open. */
50393- if (hp->port.count++ > 0) {
50394+ if (atomic_inc_return(&hp->port.count) > 1) {
50395 spin_unlock_irqrestore(&hp->port.lock, flags);
50396 hvc_kick();
50397 return 0;
50398@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50399
50400 spin_lock_irqsave(&hp->port.lock, flags);
50401
50402- if (--hp->port.count == 0) {
50403+ if (atomic_dec_return(&hp->port.count) == 0) {
50404 spin_unlock_irqrestore(&hp->port.lock, flags);
50405 /* We are done with the tty pointer now. */
50406 tty_port_tty_set(&hp->port, NULL);
50407@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50408 */
50409 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50410 } else {
50411- if (hp->port.count < 0)
50412+ if (atomic_read(&hp->port.count) < 0)
50413 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50414- hp->vtermno, hp->port.count);
50415+ hp->vtermno, atomic_read(&hp->port.count));
50416 spin_unlock_irqrestore(&hp->port.lock, flags);
50417 }
50418 }
50419@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50420 * open->hangup case this can be called after the final close so prevent
50421 * that from happening for now.
50422 */
50423- if (hp->port.count <= 0) {
50424+ if (atomic_read(&hp->port.count) <= 0) {
50425 spin_unlock_irqrestore(&hp->port.lock, flags);
50426 return;
50427 }
50428
50429- hp->port.count = 0;
50430+ atomic_set(&hp->port.count, 0);
50431 spin_unlock_irqrestore(&hp->port.lock, flags);
50432 tty_port_tty_set(&hp->port, NULL);
50433
50434@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50435 return -EPIPE;
50436
50437 /* FIXME what's this (unprotected) check for? */
50438- if (hp->port.count <= 0)
50439+ if (atomic_read(&hp->port.count) <= 0)
50440 return -EIO;
50441
50442 spin_lock_irqsave(&hp->lock, flags);
50443diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50444index 81e939e..95ead10 100644
50445--- a/drivers/tty/hvc/hvcs.c
50446+++ b/drivers/tty/hvc/hvcs.c
50447@@ -83,6 +83,7 @@
50448 #include <asm/hvcserver.h>
50449 #include <asm/uaccess.h>
50450 #include <asm/vio.h>
50451+#include <asm/local.h>
50452
50453 /*
50454 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50455@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50456
50457 spin_lock_irqsave(&hvcsd->lock, flags);
50458
50459- if (hvcsd->port.count > 0) {
50460+ if (atomic_read(&hvcsd->port.count) > 0) {
50461 spin_unlock_irqrestore(&hvcsd->lock, flags);
50462 printk(KERN_INFO "HVCS: vterm state unchanged. "
50463 "The hvcs device node is still in use.\n");
50464@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50465 }
50466 }
50467
50468- hvcsd->port.count = 0;
50469+ atomic_set(&hvcsd->port.count, 0);
50470 hvcsd->port.tty = tty;
50471 tty->driver_data = hvcsd;
50472
50473@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50474 unsigned long flags;
50475
50476 spin_lock_irqsave(&hvcsd->lock, flags);
50477- hvcsd->port.count++;
50478+ atomic_inc(&hvcsd->port.count);
50479 hvcsd->todo_mask |= HVCS_SCHED_READ;
50480 spin_unlock_irqrestore(&hvcsd->lock, flags);
50481
50482@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50483 hvcsd = tty->driver_data;
50484
50485 spin_lock_irqsave(&hvcsd->lock, flags);
50486- if (--hvcsd->port.count == 0) {
50487+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50488
50489 vio_disable_interrupts(hvcsd->vdev);
50490
50491@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50492
50493 free_irq(irq, hvcsd);
50494 return;
50495- } else if (hvcsd->port.count < 0) {
50496+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50497 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50498 " is missmanaged.\n",
50499- hvcsd->vdev->unit_address, hvcsd->port.count);
50500+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50501 }
50502
50503 spin_unlock_irqrestore(&hvcsd->lock, flags);
50504@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50505
50506 spin_lock_irqsave(&hvcsd->lock, flags);
50507 /* Preserve this so that we know how many kref refs to put */
50508- temp_open_count = hvcsd->port.count;
50509+ temp_open_count = atomic_read(&hvcsd->port.count);
50510
50511 /*
50512 * Don't kref put inside the spinlock because the destruction
50513@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50514 tty->driver_data = NULL;
50515 hvcsd->port.tty = NULL;
50516
50517- hvcsd->port.count = 0;
50518+ atomic_set(&hvcsd->port.count, 0);
50519
50520 /* This will drop any buffered data on the floor which is OK in a hangup
50521 * scenario. */
50522@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50523 * the middle of a write operation? This is a crummy place to do this
50524 * but we want to keep it all in the spinlock.
50525 */
50526- if (hvcsd->port.count <= 0) {
50527+ if (atomic_read(&hvcsd->port.count) <= 0) {
50528 spin_unlock_irqrestore(&hvcsd->lock, flags);
50529 return -ENODEV;
50530 }
50531@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50532 {
50533 struct hvcs_struct *hvcsd = tty->driver_data;
50534
50535- if (!hvcsd || hvcsd->port.count <= 0)
50536+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50537 return 0;
50538
50539 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50540diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50541index 4190199..06d5bfa 100644
50542--- a/drivers/tty/hvc/hvsi.c
50543+++ b/drivers/tty/hvc/hvsi.c
50544@@ -85,7 +85,7 @@ struct hvsi_struct {
50545 int n_outbuf;
50546 uint32_t vtermno;
50547 uint32_t virq;
50548- atomic_t seqno; /* HVSI packet sequence number */
50549+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50550 uint16_t mctrl;
50551 uint8_t state; /* HVSI protocol state */
50552 uint8_t flags;
50553@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50554
50555 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50556 packet.hdr.len = sizeof(struct hvsi_query_response);
50557- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50558+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50559 packet.verb = VSV_SEND_VERSION_NUMBER;
50560 packet.u.version = HVSI_VERSION;
50561 packet.query_seqno = query_seqno+1;
50562@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50563
50564 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50565 packet.hdr.len = sizeof(struct hvsi_query);
50566- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50567+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50568 packet.verb = verb;
50569
50570 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50571@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50572 int wrote;
50573
50574 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50575- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50576+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50577 packet.hdr.len = sizeof(struct hvsi_control);
50578 packet.verb = VSV_SET_MODEM_CTL;
50579 packet.mask = HVSI_TSDTR;
50580@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50581 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50582
50583 packet.hdr.type = VS_DATA_PACKET_HEADER;
50584- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50585+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50586 packet.hdr.len = count + sizeof(struct hvsi_header);
50587 memcpy(&packet.data, buf, count);
50588
50589@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50590 struct hvsi_control packet __ALIGNED__;
50591
50592 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50593- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50594+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50595 packet.hdr.len = 6;
50596 packet.verb = VSV_CLOSE_PROTOCOL;
50597
50598@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50599
50600 tty_port_tty_set(&hp->port, tty);
50601 spin_lock_irqsave(&hp->lock, flags);
50602- hp->port.count++;
50603+ atomic_inc(&hp->port.count);
50604 atomic_set(&hp->seqno, 0);
50605 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50606 spin_unlock_irqrestore(&hp->lock, flags);
50607@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50608
50609 spin_lock_irqsave(&hp->lock, flags);
50610
50611- if (--hp->port.count == 0) {
50612+ if (atomic_dec_return(&hp->port.count) == 0) {
50613 tty_port_tty_set(&hp->port, NULL);
50614 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50615
50616@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50617
50618 spin_lock_irqsave(&hp->lock, flags);
50619 }
50620- } else if (hp->port.count < 0)
50621+ } else if (atomic_read(&hp->port.count) < 0)
50622 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50623- hp - hvsi_ports, hp->port.count);
50624+ hp - hvsi_ports, atomic_read(&hp->port.count));
50625
50626 spin_unlock_irqrestore(&hp->lock, flags);
50627 }
50628@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50629 tty_port_tty_set(&hp->port, NULL);
50630
50631 spin_lock_irqsave(&hp->lock, flags);
50632- hp->port.count = 0;
50633+ atomic_set(&hp->port.count, 0);
50634 hp->n_outbuf = 0;
50635 spin_unlock_irqrestore(&hp->lock, flags);
50636 }
50637diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50638index 7ae6c29..05c6dba 100644
50639--- a/drivers/tty/hvc/hvsi_lib.c
50640+++ b/drivers/tty/hvc/hvsi_lib.c
50641@@ -8,7 +8,7 @@
50642
50643 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50644 {
50645- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50646+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50647
50648 /* Assumes that always succeeds, works in practice */
50649 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50650@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50651
50652 /* Reset state */
50653 pv->established = 0;
50654- atomic_set(&pv->seqno, 0);
50655+ atomic_set_unchecked(&pv->seqno, 0);
50656
50657 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50658
50659diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50660index 17ee3bf..8d2520d 100644
50661--- a/drivers/tty/ipwireless/tty.c
50662+++ b/drivers/tty/ipwireless/tty.c
50663@@ -28,6 +28,7 @@
50664 #include <linux/tty_driver.h>
50665 #include <linux/tty_flip.h>
50666 #include <linux/uaccess.h>
50667+#include <asm/local.h>
50668
50669 #include "tty.h"
50670 #include "network.h"
50671@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50672 mutex_unlock(&tty->ipw_tty_mutex);
50673 return -ENODEV;
50674 }
50675- if (tty->port.count == 0)
50676+ if (atomic_read(&tty->port.count) == 0)
50677 tty->tx_bytes_queued = 0;
50678
50679- tty->port.count++;
50680+ atomic_inc(&tty->port.count);
50681
50682 tty->port.tty = linux_tty;
50683 linux_tty->driver_data = tty;
50684@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50685
50686 static void do_ipw_close(struct ipw_tty *tty)
50687 {
50688- tty->port.count--;
50689-
50690- if (tty->port.count == 0) {
50691+ if (atomic_dec_return(&tty->port.count) == 0) {
50692 struct tty_struct *linux_tty = tty->port.tty;
50693
50694 if (linux_tty != NULL) {
50695@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50696 return;
50697
50698 mutex_lock(&tty->ipw_tty_mutex);
50699- if (tty->port.count == 0) {
50700+ if (atomic_read(&tty->port.count) == 0) {
50701 mutex_unlock(&tty->ipw_tty_mutex);
50702 return;
50703 }
50704@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50705
50706 mutex_lock(&tty->ipw_tty_mutex);
50707
50708- if (!tty->port.count) {
50709+ if (!atomic_read(&tty->port.count)) {
50710 mutex_unlock(&tty->ipw_tty_mutex);
50711 return;
50712 }
50713@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50714 return -ENODEV;
50715
50716 mutex_lock(&tty->ipw_tty_mutex);
50717- if (!tty->port.count) {
50718+ if (!atomic_read(&tty->port.count)) {
50719 mutex_unlock(&tty->ipw_tty_mutex);
50720 return -EINVAL;
50721 }
50722@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50723 if (!tty)
50724 return -ENODEV;
50725
50726- if (!tty->port.count)
50727+ if (!atomic_read(&tty->port.count))
50728 return -EINVAL;
50729
50730 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50731@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50732 if (!tty)
50733 return 0;
50734
50735- if (!tty->port.count)
50736+ if (!atomic_read(&tty->port.count))
50737 return 0;
50738
50739 return tty->tx_bytes_queued;
50740@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50741 if (!tty)
50742 return -ENODEV;
50743
50744- if (!tty->port.count)
50745+ if (!atomic_read(&tty->port.count))
50746 return -EINVAL;
50747
50748 return get_control_lines(tty);
50749@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50750 if (!tty)
50751 return -ENODEV;
50752
50753- if (!tty->port.count)
50754+ if (!atomic_read(&tty->port.count))
50755 return -EINVAL;
50756
50757 return set_control_lines(tty, set, clear);
50758@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50759 if (!tty)
50760 return -ENODEV;
50761
50762- if (!tty->port.count)
50763+ if (!atomic_read(&tty->port.count))
50764 return -EINVAL;
50765
50766 /* FIXME: Exactly how is the tty object locked here .. */
50767@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50768 * are gone */
50769 mutex_lock(&ttyj->ipw_tty_mutex);
50770 }
50771- while (ttyj->port.count)
50772+ while (atomic_read(&ttyj->port.count))
50773 do_ipw_close(ttyj);
50774 ipwireless_disassociate_network_ttys(network,
50775 ttyj->channel_idx);
50776diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50777index 1deaca4..c8582d4 100644
50778--- a/drivers/tty/moxa.c
50779+++ b/drivers/tty/moxa.c
50780@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50781 }
50782
50783 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50784- ch->port.count++;
50785+ atomic_inc(&ch->port.count);
50786 tty->driver_data = ch;
50787 tty_port_tty_set(&ch->port, tty);
50788 mutex_lock(&ch->port.mutex);
50789diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50790index 2ebe47b..3205833 100644
50791--- a/drivers/tty/n_gsm.c
50792+++ b/drivers/tty/n_gsm.c
50793@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50794 spin_lock_init(&dlci->lock);
50795 mutex_init(&dlci->mutex);
50796 dlci->fifo = &dlci->_fifo;
50797- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50798+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50799 kfree(dlci);
50800 return NULL;
50801 }
50802@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50803 struct gsm_dlci *dlci = tty->driver_data;
50804 struct tty_port *port = &dlci->port;
50805
50806- port->count++;
50807+ atomic_inc(&port->count);
50808 tty_port_tty_set(port, tty);
50809
50810 dlci->modem_rx = 0;
50811diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50812index fe9d129..477300f 100644
50813--- a/drivers/tty/n_tty.c
50814+++ b/drivers/tty/n_tty.c
50815@@ -115,7 +115,7 @@ struct n_tty_data {
50816 int minimum_to_wake;
50817
50818 /* consumer-published */
50819- size_t read_tail;
50820+ size_t read_tail __intentional_overflow(-1);
50821 size_t line_start;
50822
50823 /* protected by output lock */
50824@@ -2516,6 +2516,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50825 {
50826 *ops = tty_ldisc_N_TTY;
50827 ops->owner = NULL;
50828- ops->refcount = ops->flags = 0;
50829+ atomic_set(&ops->refcount, 0);
50830+ ops->flags = 0;
50831 }
50832 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50833diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50834index 25c9bc7..24077b7 100644
50835--- a/drivers/tty/pty.c
50836+++ b/drivers/tty/pty.c
50837@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50838 panic("Couldn't register Unix98 pts driver");
50839
50840 /* Now create the /dev/ptmx special device */
50841+ pax_open_kernel();
50842 tty_default_fops(&ptmx_fops);
50843- ptmx_fops.open = ptmx_open;
50844+ *(void **)&ptmx_fops.open = ptmx_open;
50845+ pax_close_kernel();
50846
50847 cdev_init(&ptmx_cdev, &ptmx_fops);
50848 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50849diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50850index 383c4c7..d408e21 100644
50851--- a/drivers/tty/rocket.c
50852+++ b/drivers/tty/rocket.c
50853@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50854 tty->driver_data = info;
50855 tty_port_tty_set(port, tty);
50856
50857- if (port->count++ == 0) {
50858+ if (atomic_inc_return(&port->count) == 1) {
50859 atomic_inc(&rp_num_ports_open);
50860
50861 #ifdef ROCKET_DEBUG_OPEN
50862@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50863 #endif
50864 }
50865 #ifdef ROCKET_DEBUG_OPEN
50866- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50867+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50868 #endif
50869
50870 /*
50871@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50872 spin_unlock_irqrestore(&info->port.lock, flags);
50873 return;
50874 }
50875- if (info->port.count)
50876+ if (atomic_read(&info->port.count))
50877 atomic_dec(&rp_num_ports_open);
50878 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50879 spin_unlock_irqrestore(&info->port.lock, flags);
50880diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50881index 1274499..f541382 100644
50882--- a/drivers/tty/serial/ioc4_serial.c
50883+++ b/drivers/tty/serial/ioc4_serial.c
50884@@ -437,7 +437,7 @@ struct ioc4_soft {
50885 } is_intr_info[MAX_IOC4_INTR_ENTS];
50886
50887 /* Number of entries active in the above array */
50888- atomic_t is_num_intrs;
50889+ atomic_unchecked_t is_num_intrs;
50890 } is_intr_type[IOC4_NUM_INTR_TYPES];
50891
50892 /* is_ir_lock must be held while
50893@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50894 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50895 || (type == IOC4_OTHER_INTR_TYPE)));
50896
50897- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50898+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50899 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50900
50901 /* Save off the lower level interrupt handler */
50902@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50903
50904 soft = arg;
50905 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50906- num_intrs = (int)atomic_read(
50907+ num_intrs = (int)atomic_read_unchecked(
50908 &soft->is_intr_type[intr_type].is_num_intrs);
50909
50910 this_mir = this_ir = pending_intrs(soft, intr_type);
50911diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50912index a260cde..6b2b5ce 100644
50913--- a/drivers/tty/serial/kgdboc.c
50914+++ b/drivers/tty/serial/kgdboc.c
50915@@ -24,8 +24,9 @@
50916 #define MAX_CONFIG_LEN 40
50917
50918 static struct kgdb_io kgdboc_io_ops;
50919+static struct kgdb_io kgdboc_io_ops_console;
50920
50921-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50922+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50923 static int configured = -1;
50924
50925 static char config[MAX_CONFIG_LEN];
50926@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50927 kgdboc_unregister_kbd();
50928 if (configured == 1)
50929 kgdb_unregister_io_module(&kgdboc_io_ops);
50930+ else if (configured == 2)
50931+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
50932 }
50933
50934 static int configure_kgdboc(void)
50935@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50936 int err;
50937 char *cptr = config;
50938 struct console *cons;
50939+ int is_console = 0;
50940
50941 err = kgdboc_option_setup(config);
50942 if (err || !strlen(config) || isspace(config[0]))
50943 goto noconfig;
50944
50945 err = -ENODEV;
50946- kgdboc_io_ops.is_console = 0;
50947 kgdb_tty_driver = NULL;
50948
50949 kgdboc_use_kms = 0;
50950@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50951 int idx;
50952 if (cons->device && cons->device(cons, &idx) == p &&
50953 idx == tty_line) {
50954- kgdboc_io_ops.is_console = 1;
50955+ is_console = 1;
50956 break;
50957 }
50958 cons = cons->next;
50959@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50960 kgdb_tty_line = tty_line;
50961
50962 do_register:
50963- err = kgdb_register_io_module(&kgdboc_io_ops);
50964+ if (is_console) {
50965+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
50966+ configured = 2;
50967+ } else {
50968+ err = kgdb_register_io_module(&kgdboc_io_ops);
50969+ configured = 1;
50970+ }
50971 if (err)
50972 goto noconfig;
50973
50974@@ -205,8 +214,6 @@ do_register:
50975 if (err)
50976 goto nmi_con_failed;
50977
50978- configured = 1;
50979-
50980 return 0;
50981
50982 nmi_con_failed:
50983@@ -223,7 +230,7 @@ noconfig:
50984 static int __init init_kgdboc(void)
50985 {
50986 /* Already configured? */
50987- if (configured == 1)
50988+ if (configured >= 1)
50989 return 0;
50990
50991 return configure_kgdboc();
50992@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50993 if (config[len - 1] == '\n')
50994 config[len - 1] = '\0';
50995
50996- if (configured == 1)
50997+ if (configured >= 1)
50998 cleanup_kgdboc();
50999
51000 /* Go and configure with the new params. */
51001@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51002 .post_exception = kgdboc_post_exp_handler,
51003 };
51004
51005+static struct kgdb_io kgdboc_io_ops_console = {
51006+ .name = "kgdboc",
51007+ .read_char = kgdboc_get_char,
51008+ .write_char = kgdboc_put_char,
51009+ .pre_exception = kgdboc_pre_exp_handler,
51010+ .post_exception = kgdboc_post_exp_handler,
51011+ .is_console = 1
51012+};
51013+
51014 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51015 /* This is only available if kgdboc is a built in for early debugging */
51016 static int __init kgdboc_early_init(char *opt)
51017diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51018index 053b98e..86742e5 100644
51019--- a/drivers/tty/serial/msm_serial.c
51020+++ b/drivers/tty/serial/msm_serial.c
51021@@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
51022 .cons = MSM_CONSOLE,
51023 };
51024
51025-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51026+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51027
51028 static const struct of_device_id msm_uartdm_table[] = {
51029 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
51030@@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51031 int irq;
51032
51033 if (pdev->id == -1)
51034- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51035+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51036
51037 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51038 return -ENXIO;
51039diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51040index 1f5505e..a1a767d 100644
51041--- a/drivers/tty/serial/samsung.c
51042+++ b/drivers/tty/serial/samsung.c
51043@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51044 }
51045 }
51046
51047+static int s3c64xx_serial_startup(struct uart_port *port);
51048 static int s3c24xx_serial_startup(struct uart_port *port)
51049 {
51050 struct s3c24xx_uart_port *ourport = to_ourport(port);
51051 int ret;
51052
51053+ /* Startup sequence is different for s3c64xx and higher SoC's */
51054+ if (s3c24xx_serial_has_interrupt_mask(port))
51055+ return s3c64xx_serial_startup(port);
51056+
51057 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51058 port->mapbase, port->membase);
51059
51060@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51061 /* setup info for port */
51062 port->dev = &platdev->dev;
51063
51064- /* Startup sequence is different for s3c64xx and higher SoC's */
51065- if (s3c24xx_serial_has_interrupt_mask(port))
51066- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51067-
51068 port->uartclk = 1;
51069
51070 if (cfg->uart_flags & UPF_CONS_FLOW) {
51071diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51072index b68550d..a62d7f8 100644
51073--- a/drivers/tty/serial/serial_core.c
51074+++ b/drivers/tty/serial/serial_core.c
51075@@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
51076
51077 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
51078
51079- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
51080+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
51081 return;
51082
51083 /*
51084@@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51085 uart_flush_buffer(tty);
51086 uart_shutdown(tty, state);
51087 spin_lock_irqsave(&port->lock, flags);
51088- port->count = 0;
51089+ atomic_set(&port->count, 0);
51090 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51091 spin_unlock_irqrestore(&port->lock, flags);
51092 tty_port_tty_set(port, NULL);
51093@@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51094 goto end;
51095 }
51096
51097- port->count++;
51098+ atomic_inc(&port->count);
51099 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51100 retval = -ENXIO;
51101 goto err_dec_count;
51102@@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51103 end:
51104 return retval;
51105 err_dec_count:
51106- port->count--;
51107+ atomic_inc(&port->count);
51108 mutex_unlock(&port->mutex);
51109 goto end;
51110 }
51111diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51112index d48e040..0f52764 100644
51113--- a/drivers/tty/synclink.c
51114+++ b/drivers/tty/synclink.c
51115@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51116
51117 if (debug_level >= DEBUG_LEVEL_INFO)
51118 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51119- __FILE__,__LINE__, info->device_name, info->port.count);
51120+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51121
51122 if (tty_port_close_start(&info->port, tty, filp) == 0)
51123 goto cleanup;
51124@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51125 cleanup:
51126 if (debug_level >= DEBUG_LEVEL_INFO)
51127 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51128- tty->driver->name, info->port.count);
51129+ tty->driver->name, atomic_read(&info->port.count));
51130
51131 } /* end of mgsl_close() */
51132
51133@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51134
51135 mgsl_flush_buffer(tty);
51136 shutdown(info);
51137-
51138- info->port.count = 0;
51139+
51140+ atomic_set(&info->port.count, 0);
51141 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51142 info->port.tty = NULL;
51143
51144@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51145
51146 if (debug_level >= DEBUG_LEVEL_INFO)
51147 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51148- __FILE__,__LINE__, tty->driver->name, port->count );
51149+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51150
51151 spin_lock_irqsave(&info->irq_spinlock, flags);
51152 if (!tty_hung_up_p(filp)) {
51153 extra_count = true;
51154- port->count--;
51155+ atomic_dec(&port->count);
51156 }
51157 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51158 port->blocked_open++;
51159@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51160
51161 if (debug_level >= DEBUG_LEVEL_INFO)
51162 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51163- __FILE__,__LINE__, tty->driver->name, port->count );
51164+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51165
51166 tty_unlock(tty);
51167 schedule();
51168@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51169
51170 /* FIXME: Racy on hangup during close wait */
51171 if (extra_count)
51172- port->count++;
51173+ atomic_inc(&port->count);
51174 port->blocked_open--;
51175
51176 if (debug_level >= DEBUG_LEVEL_INFO)
51177 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51178- __FILE__,__LINE__, tty->driver->name, port->count );
51179+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51180
51181 if (!retval)
51182 port->flags |= ASYNC_NORMAL_ACTIVE;
51183@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51184
51185 if (debug_level >= DEBUG_LEVEL_INFO)
51186 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51187- __FILE__,__LINE__,tty->driver->name, info->port.count);
51188+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51189
51190 /* If port is closing, signal caller to try again */
51191 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51192@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51193 spin_unlock_irqrestore(&info->netlock, flags);
51194 goto cleanup;
51195 }
51196- info->port.count++;
51197+ atomic_inc(&info->port.count);
51198 spin_unlock_irqrestore(&info->netlock, flags);
51199
51200- if (info->port.count == 1) {
51201+ if (atomic_read(&info->port.count) == 1) {
51202 /* 1st open on this device, init hardware */
51203 retval = startup(info);
51204 if (retval < 0)
51205@@ -3446,8 +3446,8 @@ cleanup:
51206 if (retval) {
51207 if (tty->count == 1)
51208 info->port.tty = NULL; /* tty layer will release tty struct */
51209- if(info->port.count)
51210- info->port.count--;
51211+ if (atomic_read(&info->port.count))
51212+ atomic_dec(&info->port.count);
51213 }
51214
51215 return retval;
51216@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51217 unsigned short new_crctype;
51218
51219 /* return error if TTY interface open */
51220- if (info->port.count)
51221+ if (atomic_read(&info->port.count))
51222 return -EBUSY;
51223
51224 switch (encoding)
51225@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51226
51227 /* arbitrate between network and tty opens */
51228 spin_lock_irqsave(&info->netlock, flags);
51229- if (info->port.count != 0 || info->netcount != 0) {
51230+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51231 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51232 spin_unlock_irqrestore(&info->netlock, flags);
51233 return -EBUSY;
51234@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51235 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51236
51237 /* return error if TTY interface open */
51238- if (info->port.count)
51239+ if (atomic_read(&info->port.count))
51240 return -EBUSY;
51241
51242 if (cmd != SIOCWANDEV)
51243diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51244index c359a91..959fc26 100644
51245--- a/drivers/tty/synclink_gt.c
51246+++ b/drivers/tty/synclink_gt.c
51247@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51248 tty->driver_data = info;
51249 info->port.tty = tty;
51250
51251- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51252+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51253
51254 /* If port is closing, signal caller to try again */
51255 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51256@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51257 mutex_unlock(&info->port.mutex);
51258 goto cleanup;
51259 }
51260- info->port.count++;
51261+ atomic_inc(&info->port.count);
51262 spin_unlock_irqrestore(&info->netlock, flags);
51263
51264- if (info->port.count == 1) {
51265+ if (atomic_read(&info->port.count) == 1) {
51266 /* 1st open on this device, init hardware */
51267 retval = startup(info);
51268 if (retval < 0) {
51269@@ -715,8 +715,8 @@ cleanup:
51270 if (retval) {
51271 if (tty->count == 1)
51272 info->port.tty = NULL; /* tty layer will release tty struct */
51273- if(info->port.count)
51274- info->port.count--;
51275+ if(atomic_read(&info->port.count))
51276+ atomic_dec(&info->port.count);
51277 }
51278
51279 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51280@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51281
51282 if (sanity_check(info, tty->name, "close"))
51283 return;
51284- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51285+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51286
51287 if (tty_port_close_start(&info->port, tty, filp) == 0)
51288 goto cleanup;
51289@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51290 tty_port_close_end(&info->port, tty);
51291 info->port.tty = NULL;
51292 cleanup:
51293- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51294+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51295 }
51296
51297 static void hangup(struct tty_struct *tty)
51298@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51299 shutdown(info);
51300
51301 spin_lock_irqsave(&info->port.lock, flags);
51302- info->port.count = 0;
51303+ atomic_set(&info->port.count, 0);
51304 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51305 info->port.tty = NULL;
51306 spin_unlock_irqrestore(&info->port.lock, flags);
51307@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51308 unsigned short new_crctype;
51309
51310 /* return error if TTY interface open */
51311- if (info->port.count)
51312+ if (atomic_read(&info->port.count))
51313 return -EBUSY;
51314
51315 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51316@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51317
51318 /* arbitrate between network and tty opens */
51319 spin_lock_irqsave(&info->netlock, flags);
51320- if (info->port.count != 0 || info->netcount != 0) {
51321+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51322 DBGINFO(("%s hdlc_open busy\n", dev->name));
51323 spin_unlock_irqrestore(&info->netlock, flags);
51324 return -EBUSY;
51325@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51326 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51327
51328 /* return error if TTY interface open */
51329- if (info->port.count)
51330+ if (atomic_read(&info->port.count))
51331 return -EBUSY;
51332
51333 if (cmd != SIOCWANDEV)
51334@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51335 if (port == NULL)
51336 continue;
51337 spin_lock(&port->lock);
51338- if ((port->port.count || port->netcount) &&
51339+ if ((atomic_read(&port->port.count) || port->netcount) &&
51340 port->pending_bh && !port->bh_running &&
51341 !port->bh_requested) {
51342 DBGISR(("%s bh queued\n", port->device_name));
51343@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51344 spin_lock_irqsave(&info->lock, flags);
51345 if (!tty_hung_up_p(filp)) {
51346 extra_count = true;
51347- port->count--;
51348+ atomic_dec(&port->count);
51349 }
51350 spin_unlock_irqrestore(&info->lock, flags);
51351 port->blocked_open++;
51352@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51353 remove_wait_queue(&port->open_wait, &wait);
51354
51355 if (extra_count)
51356- port->count++;
51357+ atomic_inc(&port->count);
51358 port->blocked_open--;
51359
51360 if (!retval)
51361diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51362index 53ba853..3c30f6d 100644
51363--- a/drivers/tty/synclinkmp.c
51364+++ b/drivers/tty/synclinkmp.c
51365@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51366
51367 if (debug_level >= DEBUG_LEVEL_INFO)
51368 printk("%s(%d):%s open(), old ref count = %d\n",
51369- __FILE__,__LINE__,tty->driver->name, info->port.count);
51370+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51371
51372 /* If port is closing, signal caller to try again */
51373 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51374@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51375 spin_unlock_irqrestore(&info->netlock, flags);
51376 goto cleanup;
51377 }
51378- info->port.count++;
51379+ atomic_inc(&info->port.count);
51380 spin_unlock_irqrestore(&info->netlock, flags);
51381
51382- if (info->port.count == 1) {
51383+ if (atomic_read(&info->port.count) == 1) {
51384 /* 1st open on this device, init hardware */
51385 retval = startup(info);
51386 if (retval < 0)
51387@@ -796,8 +796,8 @@ cleanup:
51388 if (retval) {
51389 if (tty->count == 1)
51390 info->port.tty = NULL; /* tty layer will release tty struct */
51391- if(info->port.count)
51392- info->port.count--;
51393+ if(atomic_read(&info->port.count))
51394+ atomic_dec(&info->port.count);
51395 }
51396
51397 return retval;
51398@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51399
51400 if (debug_level >= DEBUG_LEVEL_INFO)
51401 printk("%s(%d):%s close() entry, count=%d\n",
51402- __FILE__,__LINE__, info->device_name, info->port.count);
51403+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51404
51405 if (tty_port_close_start(&info->port, tty, filp) == 0)
51406 goto cleanup;
51407@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51408 cleanup:
51409 if (debug_level >= DEBUG_LEVEL_INFO)
51410 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51411- tty->driver->name, info->port.count);
51412+ tty->driver->name, atomic_read(&info->port.count));
51413 }
51414
51415 /* Called by tty_hangup() when a hangup is signaled.
51416@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51417 shutdown(info);
51418
51419 spin_lock_irqsave(&info->port.lock, flags);
51420- info->port.count = 0;
51421+ atomic_set(&info->port.count, 0);
51422 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51423 info->port.tty = NULL;
51424 spin_unlock_irqrestore(&info->port.lock, flags);
51425@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51426 unsigned short new_crctype;
51427
51428 /* return error if TTY interface open */
51429- if (info->port.count)
51430+ if (atomic_read(&info->port.count))
51431 return -EBUSY;
51432
51433 switch (encoding)
51434@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51435
51436 /* arbitrate between network and tty opens */
51437 spin_lock_irqsave(&info->netlock, flags);
51438- if (info->port.count != 0 || info->netcount != 0) {
51439+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51440 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51441 spin_unlock_irqrestore(&info->netlock, flags);
51442 return -EBUSY;
51443@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51444 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51445
51446 /* return error if TTY interface open */
51447- if (info->port.count)
51448+ if (atomic_read(&info->port.count))
51449 return -EBUSY;
51450
51451 if (cmd != SIOCWANDEV)
51452@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51453 * do not request bottom half processing if the
51454 * device is not open in a normal mode.
51455 */
51456- if ( port && (port->port.count || port->netcount) &&
51457+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51458 port->pending_bh && !port->bh_running &&
51459 !port->bh_requested ) {
51460 if ( debug_level >= DEBUG_LEVEL_ISR )
51461@@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51462
51463 if (debug_level >= DEBUG_LEVEL_INFO)
51464 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51465- __FILE__,__LINE__, tty->driver->name, port->count );
51466+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51467
51468 spin_lock_irqsave(&info->lock, flags);
51469 if (!tty_hung_up_p(filp)) {
51470 extra_count = true;
51471- port->count--;
51472+ atomic_dec(&port->count);
51473 }
51474 spin_unlock_irqrestore(&info->lock, flags);
51475 port->blocked_open++;
51476@@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51477
51478 if (debug_level >= DEBUG_LEVEL_INFO)
51479 printk("%s(%d):%s block_til_ready() count=%d\n",
51480- __FILE__,__LINE__, tty->driver->name, port->count );
51481+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51482
51483 tty_unlock(tty);
51484 schedule();
51485@@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51486 remove_wait_queue(&port->open_wait, &wait);
51487
51488 if (extra_count)
51489- port->count++;
51490+ atomic_inc(&port->count);
51491 port->blocked_open--;
51492
51493 if (debug_level >= DEBUG_LEVEL_INFO)
51494 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51495- __FILE__,__LINE__, tty->driver->name, port->count );
51496+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51497
51498 if (!retval)
51499 port->flags |= ASYNC_NORMAL_ACTIVE;
51500diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51501index ce396ec..04a37be 100644
51502--- a/drivers/tty/sysrq.c
51503+++ b/drivers/tty/sysrq.c
51504@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51505 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51506 size_t count, loff_t *ppos)
51507 {
51508- if (count) {
51509+ if (count && capable(CAP_SYS_ADMIN)) {
51510 char c;
51511
51512 if (get_user(c, buf))
51513diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51514index 3411071..86f2cf2 100644
51515--- a/drivers/tty/tty_io.c
51516+++ b/drivers/tty/tty_io.c
51517@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51518
51519 void tty_default_fops(struct file_operations *fops)
51520 {
51521- *fops = tty_fops;
51522+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51523 }
51524
51525 /*
51526diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51527index 2d822aa..a566234 100644
51528--- a/drivers/tty/tty_ldisc.c
51529+++ b/drivers/tty/tty_ldisc.c
51530@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51531 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51532 tty_ldiscs[disc] = new_ldisc;
51533 new_ldisc->num = disc;
51534- new_ldisc->refcount = 0;
51535+ atomic_set(&new_ldisc->refcount, 0);
51536 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51537
51538 return ret;
51539@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51540 return -EINVAL;
51541
51542 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51543- if (tty_ldiscs[disc]->refcount)
51544+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51545 ret = -EBUSY;
51546 else
51547 tty_ldiscs[disc] = NULL;
51548@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51549 if (ldops) {
51550 ret = ERR_PTR(-EAGAIN);
51551 if (try_module_get(ldops->owner)) {
51552- ldops->refcount++;
51553+ atomic_inc(&ldops->refcount);
51554 ret = ldops;
51555 }
51556 }
51557@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51558 unsigned long flags;
51559
51560 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51561- ldops->refcount--;
51562+ atomic_dec(&ldops->refcount);
51563 module_put(ldops->owner);
51564 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51565 }
51566diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51567index 3f746c8..2f2fcaa 100644
51568--- a/drivers/tty/tty_port.c
51569+++ b/drivers/tty/tty_port.c
51570@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51571 unsigned long flags;
51572
51573 spin_lock_irqsave(&port->lock, flags);
51574- port->count = 0;
51575+ atomic_set(&port->count, 0);
51576 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51577 tty = port->tty;
51578 if (tty)
51579@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51580 /* The port lock protects the port counts */
51581 spin_lock_irqsave(&port->lock, flags);
51582 if (!tty_hung_up_p(filp))
51583- port->count--;
51584+ atomic_dec(&port->count);
51585 port->blocked_open++;
51586 spin_unlock_irqrestore(&port->lock, flags);
51587
51588@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51589 we must not mess that up further */
51590 spin_lock_irqsave(&port->lock, flags);
51591 if (!tty_hung_up_p(filp))
51592- port->count++;
51593+ atomic_inc(&port->count);
51594 port->blocked_open--;
51595 if (retval == 0)
51596 port->flags |= ASYNC_NORMAL_ACTIVE;
51597@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51598 return 0;
51599 }
51600
51601- if (tty->count == 1 && port->count != 1) {
51602+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51603 printk(KERN_WARNING
51604 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51605- port->count);
51606- port->count = 1;
51607+ atomic_read(&port->count));
51608+ atomic_set(&port->count, 1);
51609 }
51610- if (--port->count < 0) {
51611+ if (atomic_dec_return(&port->count) < 0) {
51612 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51613- port->count);
51614- port->count = 0;
51615+ atomic_read(&port->count));
51616+ atomic_set(&port->count, 0);
51617 }
51618
51619- if (port->count) {
51620+ if (atomic_read(&port->count)) {
51621 spin_unlock_irqrestore(&port->lock, flags);
51622 return 0;
51623 }
51624@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51625 {
51626 spin_lock_irq(&port->lock);
51627 if (!tty_hung_up_p(filp))
51628- ++port->count;
51629+ atomic_inc(&port->count);
51630 spin_unlock_irq(&port->lock);
51631 tty_port_tty_set(port, tty);
51632
51633diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51634index d0e3a44..5f8b754 100644
51635--- a/drivers/tty/vt/keyboard.c
51636+++ b/drivers/tty/vt/keyboard.c
51637@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51638 kbd->kbdmode == VC_OFF) &&
51639 value != KVAL(K_SAK))
51640 return; /* SAK is allowed even in raw mode */
51641+
51642+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51643+ {
51644+ void *func = fn_handler[value];
51645+ if (func == fn_show_state || func == fn_show_ptregs ||
51646+ func == fn_show_mem)
51647+ return;
51648+ }
51649+#endif
51650+
51651 fn_handler[value](vc);
51652 }
51653
51654@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51655 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51656 return -EFAULT;
51657
51658- if (!capable(CAP_SYS_TTY_CONFIG))
51659- perm = 0;
51660-
51661 switch (cmd) {
51662 case KDGKBENT:
51663 /* Ensure another thread doesn't free it under us */
51664@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51665 spin_unlock_irqrestore(&kbd_event_lock, flags);
51666 return put_user(val, &user_kbe->kb_value);
51667 case KDSKBENT:
51668+ if (!capable(CAP_SYS_TTY_CONFIG))
51669+ perm = 0;
51670+
51671 if (!perm)
51672 return -EPERM;
51673 if (!i && v == K_NOSUCHMAP) {
51674@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51675 int i, j, k;
51676 int ret;
51677
51678- if (!capable(CAP_SYS_TTY_CONFIG))
51679- perm = 0;
51680-
51681 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51682 if (!kbs) {
51683 ret = -ENOMEM;
51684@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51685 kfree(kbs);
51686 return ((p && *p) ? -EOVERFLOW : 0);
51687 case KDSKBSENT:
51688+ if (!capable(CAP_SYS_TTY_CONFIG))
51689+ perm = 0;
51690+
51691 if (!perm) {
51692 ret = -EPERM;
51693 goto reterr;
51694diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51695index a673e5b..36e5d32 100644
51696--- a/drivers/uio/uio.c
51697+++ b/drivers/uio/uio.c
51698@@ -25,6 +25,7 @@
51699 #include <linux/kobject.h>
51700 #include <linux/cdev.h>
51701 #include <linux/uio_driver.h>
51702+#include <asm/local.h>
51703
51704 #define UIO_MAX_DEVICES (1U << MINORBITS)
51705
51706@@ -32,7 +33,7 @@ struct uio_device {
51707 struct module *owner;
51708 struct device *dev;
51709 int minor;
51710- atomic_t event;
51711+ atomic_unchecked_t event;
51712 struct fasync_struct *async_queue;
51713 wait_queue_head_t wait;
51714 struct uio_info *info;
51715@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51716 struct device_attribute *attr, char *buf)
51717 {
51718 struct uio_device *idev = dev_get_drvdata(dev);
51719- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51720+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51721 }
51722 static DEVICE_ATTR_RO(event);
51723
51724@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51725 {
51726 struct uio_device *idev = info->uio_dev;
51727
51728- atomic_inc(&idev->event);
51729+ atomic_inc_unchecked(&idev->event);
51730 wake_up_interruptible(&idev->wait);
51731 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51732 }
51733@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51734 }
51735
51736 listener->dev = idev;
51737- listener->event_count = atomic_read(&idev->event);
51738+ listener->event_count = atomic_read_unchecked(&idev->event);
51739 filep->private_data = listener;
51740
51741 if (idev->info->open) {
51742@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51743 return -EIO;
51744
51745 poll_wait(filep, &idev->wait, wait);
51746- if (listener->event_count != atomic_read(&idev->event))
51747+ if (listener->event_count != atomic_read_unchecked(&idev->event))
51748 return POLLIN | POLLRDNORM;
51749 return 0;
51750 }
51751@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51752 do {
51753 set_current_state(TASK_INTERRUPTIBLE);
51754
51755- event_count = atomic_read(&idev->event);
51756+ event_count = atomic_read_unchecked(&idev->event);
51757 if (event_count != listener->event_count) {
51758 if (copy_to_user(buf, &event_count, count))
51759 retval = -EFAULT;
51760@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51761 static int uio_find_mem_index(struct vm_area_struct *vma)
51762 {
51763 struct uio_device *idev = vma->vm_private_data;
51764+ unsigned long size;
51765
51766 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51767- if (idev->info->mem[vma->vm_pgoff].size == 0)
51768+ size = idev->info->mem[vma->vm_pgoff].size;
51769+ if (size == 0)
51770+ return -1;
51771+ if (vma->vm_end - vma->vm_start > size)
51772 return -1;
51773 return (int)vma->vm_pgoff;
51774 }
51775@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51776 idev->owner = owner;
51777 idev->info = info;
51778 init_waitqueue_head(&idev->wait);
51779- atomic_set(&idev->event, 0);
51780+ atomic_set_unchecked(&idev->event, 0);
51781
51782 ret = uio_get_minor(idev);
51783 if (ret)
51784diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51785index 813d4d3..a71934f 100644
51786--- a/drivers/usb/atm/cxacru.c
51787+++ b/drivers/usb/atm/cxacru.c
51788@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51789 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51790 if (ret < 2)
51791 return -EINVAL;
51792- if (index < 0 || index > 0x7f)
51793+ if (index > 0x7f)
51794 return -EINVAL;
51795 pos += tmp;
51796
51797diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51798index dada014..1d0d517 100644
51799--- a/drivers/usb/atm/usbatm.c
51800+++ b/drivers/usb/atm/usbatm.c
51801@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51802 if (printk_ratelimit())
51803 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51804 __func__, vpi, vci);
51805- atomic_inc(&vcc->stats->rx_err);
51806+ atomic_inc_unchecked(&vcc->stats->rx_err);
51807 return;
51808 }
51809
51810@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51811 if (length > ATM_MAX_AAL5_PDU) {
51812 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51813 __func__, length, vcc);
51814- atomic_inc(&vcc->stats->rx_err);
51815+ atomic_inc_unchecked(&vcc->stats->rx_err);
51816 goto out;
51817 }
51818
51819@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51820 if (sarb->len < pdu_length) {
51821 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51822 __func__, pdu_length, sarb->len, vcc);
51823- atomic_inc(&vcc->stats->rx_err);
51824+ atomic_inc_unchecked(&vcc->stats->rx_err);
51825 goto out;
51826 }
51827
51828 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51829 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51830 __func__, vcc);
51831- atomic_inc(&vcc->stats->rx_err);
51832+ atomic_inc_unchecked(&vcc->stats->rx_err);
51833 goto out;
51834 }
51835
51836@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51837 if (printk_ratelimit())
51838 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51839 __func__, length);
51840- atomic_inc(&vcc->stats->rx_drop);
51841+ atomic_inc_unchecked(&vcc->stats->rx_drop);
51842 goto out;
51843 }
51844
51845@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51846
51847 vcc->push(vcc, skb);
51848
51849- atomic_inc(&vcc->stats->rx);
51850+ atomic_inc_unchecked(&vcc->stats->rx);
51851 out:
51852 skb_trim(sarb, 0);
51853 }
51854@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51855 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51856
51857 usbatm_pop(vcc, skb);
51858- atomic_inc(&vcc->stats->tx);
51859+ atomic_inc_unchecked(&vcc->stats->tx);
51860
51861 skb = skb_dequeue(&instance->sndqueue);
51862 }
51863@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51864 if (!left--)
51865 return sprintf(page,
51866 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51867- atomic_read(&atm_dev->stats.aal5.tx),
51868- atomic_read(&atm_dev->stats.aal5.tx_err),
51869- atomic_read(&atm_dev->stats.aal5.rx),
51870- atomic_read(&atm_dev->stats.aal5.rx_err),
51871- atomic_read(&atm_dev->stats.aal5.rx_drop));
51872+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51873+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51874+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51875+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51876+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51877
51878 if (!left--) {
51879 if (instance->disconnected)
51880diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51881index 2a3bbdf..91d72cf 100644
51882--- a/drivers/usb/core/devices.c
51883+++ b/drivers/usb/core/devices.c
51884@@ -126,7 +126,7 @@ static const char format_endpt[] =
51885 * time it gets called.
51886 */
51887 static struct device_connect_event {
51888- atomic_t count;
51889+ atomic_unchecked_t count;
51890 wait_queue_head_t wait;
51891 } device_event = {
51892 .count = ATOMIC_INIT(1),
51893@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51894
51895 void usbfs_conn_disc_event(void)
51896 {
51897- atomic_add(2, &device_event.count);
51898+ atomic_add_unchecked(2, &device_event.count);
51899 wake_up(&device_event.wait);
51900 }
51901
51902@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51903
51904 poll_wait(file, &device_event.wait, wait);
51905
51906- event_count = atomic_read(&device_event.count);
51907+ event_count = atomic_read_unchecked(&device_event.count);
51908 if (file->f_version != event_count) {
51909 file->f_version = event_count;
51910 return POLLIN | POLLRDNORM;
51911diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51912index 257876e..4304364 100644
51913--- a/drivers/usb/core/devio.c
51914+++ b/drivers/usb/core/devio.c
51915@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51916 struct usb_dev_state *ps = file->private_data;
51917 struct usb_device *dev = ps->dev;
51918 ssize_t ret = 0;
51919- unsigned len;
51920+ size_t len;
51921 loff_t pos;
51922 int i;
51923
51924@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51925 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51926 struct usb_config_descriptor *config =
51927 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51928- unsigned int length = le16_to_cpu(config->wTotalLength);
51929+ size_t length = le16_to_cpu(config->wTotalLength);
51930
51931 if (*ppos < pos + length) {
51932
51933 /* The descriptor may claim to be longer than it
51934 * really is. Here is the actual allocated length. */
51935- unsigned alloclen =
51936+ size_t alloclen =
51937 le16_to_cpu(dev->config[i].desc.wTotalLength);
51938
51939- len = length - (*ppos - pos);
51940+ len = length + pos - *ppos;
51941 if (len > nbytes)
51942 len = nbytes;
51943
51944 /* Simply don't write (skip over) unallocated parts */
51945 if (alloclen > (*ppos - pos)) {
51946- alloclen -= (*ppos - pos);
51947+ alloclen = alloclen + pos - *ppos;
51948 if (copy_to_user(buf,
51949 dev->rawdescriptors[i] + (*ppos - pos),
51950 min(len, alloclen))) {
51951diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51952index 9c4e292..b89877f 100644
51953--- a/drivers/usb/core/hcd.c
51954+++ b/drivers/usb/core/hcd.c
51955@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51956 */
51957 usb_get_urb(urb);
51958 atomic_inc(&urb->use_count);
51959- atomic_inc(&urb->dev->urbnum);
51960+ atomic_inc_unchecked(&urb->dev->urbnum);
51961 usbmon_urb_submit(&hcd->self, urb);
51962
51963 /* NOTE requirements on root-hub callers (usbfs and the hub
51964@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51965 urb->hcpriv = NULL;
51966 INIT_LIST_HEAD(&urb->urb_list);
51967 atomic_dec(&urb->use_count);
51968- atomic_dec(&urb->dev->urbnum);
51969+ atomic_dec_unchecked(&urb->dev->urbnum);
51970 if (atomic_read(&urb->reject))
51971 wake_up(&usb_kill_urb_queue);
51972 usb_put_urb(urb);
51973diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51974index 229a73f..ef86f98 100644
51975--- a/drivers/usb/core/hub.c
51976+++ b/drivers/usb/core/hub.c
51977@@ -27,6 +27,7 @@
51978 #include <linux/freezer.h>
51979 #include <linux/random.h>
51980 #include <linux/pm_qos.h>
51981+#include <linux/grsecurity.h>
51982
51983 #include <asm/uaccess.h>
51984 #include <asm/byteorder.h>
51985@@ -4512,6 +4513,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51986 goto done;
51987 return;
51988 }
51989+
51990+ if (gr_handle_new_usb())
51991+ goto done;
51992+
51993 if (hub_is_superspeed(hub->hdev))
51994 unit_load = 150;
51995 else
51996diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51997index 0c8a7fc..c45b40a 100644
51998--- a/drivers/usb/core/message.c
51999+++ b/drivers/usb/core/message.c
52000@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52001 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52002 * error number.
52003 */
52004-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52005+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52006 __u8 requesttype, __u16 value, __u16 index, void *data,
52007 __u16 size, int timeout)
52008 {
52009@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52010 * If successful, 0. Otherwise a negative error number. The number of actual
52011 * bytes transferred will be stored in the @actual_length parameter.
52012 */
52013-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52014+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52015 void *data, int len, int *actual_length, int timeout)
52016 {
52017 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52018@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52019 * bytes transferred will be stored in the @actual_length parameter.
52020 *
52021 */
52022-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52023+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52024 void *data, int len, int *actual_length, int timeout)
52025 {
52026 struct urb *urb;
52027diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52028index 1236c60..d47a51c 100644
52029--- a/drivers/usb/core/sysfs.c
52030+++ b/drivers/usb/core/sysfs.c
52031@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52032 struct usb_device *udev;
52033
52034 udev = to_usb_device(dev);
52035- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52036+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52037 }
52038 static DEVICE_ATTR_RO(urbnum);
52039
52040diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52041index 4d11449..f4ccabf 100644
52042--- a/drivers/usb/core/usb.c
52043+++ b/drivers/usb/core/usb.c
52044@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52045 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52046 dev->state = USB_STATE_ATTACHED;
52047 dev->lpm_disable_count = 1;
52048- atomic_set(&dev->urbnum, 0);
52049+ atomic_set_unchecked(&dev->urbnum, 0);
52050
52051 INIT_LIST_HEAD(&dev->ep0.urb_list);
52052 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52053diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52054index 85f398d..d375bbe 100644
52055--- a/drivers/usb/dwc3/gadget.c
52056+++ b/drivers/usb/dwc3/gadget.c
52057@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52058 if (!usb_endpoint_xfer_isoc(desc))
52059 return 0;
52060
52061- memset(&trb_link, 0, sizeof(trb_link));
52062-
52063 /* Link TRB for ISOC. The HWO bit is never reset */
52064 trb_st_hw = &dep->trb_pool[0];
52065
52066diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52067index 8cfc319..4868255 100644
52068--- a/drivers/usb/early/ehci-dbgp.c
52069+++ b/drivers/usb/early/ehci-dbgp.c
52070@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52071
52072 #ifdef CONFIG_KGDB
52073 static struct kgdb_io kgdbdbgp_io_ops;
52074-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52075+static struct kgdb_io kgdbdbgp_io_ops_console;
52076+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52077 #else
52078 #define dbgp_kgdb_mode (0)
52079 #endif
52080@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52081 .write_char = kgdbdbgp_write_char,
52082 };
52083
52084+static struct kgdb_io kgdbdbgp_io_ops_console = {
52085+ .name = "kgdbdbgp",
52086+ .read_char = kgdbdbgp_read_char,
52087+ .write_char = kgdbdbgp_write_char,
52088+ .is_console = 1
52089+};
52090+
52091 static int kgdbdbgp_wait_time;
52092
52093 static int __init kgdbdbgp_parse_config(char *str)
52094@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52095 ptr++;
52096 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52097 }
52098- kgdb_register_io_module(&kgdbdbgp_io_ops);
52099- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52100+ if (early_dbgp_console.index != -1)
52101+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52102+ else
52103+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52104
52105 return 0;
52106 }
52107diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52108index 2b4c82d..06a8ee6 100644
52109--- a/drivers/usb/gadget/f_uac1.c
52110+++ b/drivers/usb/gadget/f_uac1.c
52111@@ -13,6 +13,7 @@
52112 #include <linux/kernel.h>
52113 #include <linux/device.h>
52114 #include <linux/atomic.h>
52115+#include <linux/module.h>
52116
52117 #include "u_uac1.h"
52118
52119diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52120index ad0aca8..8ff84865 100644
52121--- a/drivers/usb/gadget/u_serial.c
52122+++ b/drivers/usb/gadget/u_serial.c
52123@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52124 spin_lock_irq(&port->port_lock);
52125
52126 /* already open? Great. */
52127- if (port->port.count) {
52128+ if (atomic_read(&port->port.count)) {
52129 status = 0;
52130- port->port.count++;
52131+ atomic_inc(&port->port.count);
52132
52133 /* currently opening/closing? wait ... */
52134 } else if (port->openclose) {
52135@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52136 tty->driver_data = port;
52137 port->port.tty = tty;
52138
52139- port->port.count = 1;
52140+ atomic_set(&port->port.count, 1);
52141 port->openclose = false;
52142
52143 /* if connected, start the I/O stream */
52144@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52145
52146 spin_lock_irq(&port->port_lock);
52147
52148- if (port->port.count != 1) {
52149- if (port->port.count == 0)
52150+ if (atomic_read(&port->port.count) != 1) {
52151+ if (atomic_read(&port->port.count) == 0)
52152 WARN_ON(1);
52153 else
52154- --port->port.count;
52155+ atomic_dec(&port->port.count);
52156 goto exit;
52157 }
52158
52159@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52160 * and sleep if necessary
52161 */
52162 port->openclose = true;
52163- port->port.count = 0;
52164+ atomic_set(&port->port.count, 0);
52165
52166 gser = port->port_usb;
52167 if (gser && gser->disconnect)
52168@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52169 int cond;
52170
52171 spin_lock_irq(&port->port_lock);
52172- cond = (port->port.count == 0) && !port->openclose;
52173+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52174 spin_unlock_irq(&port->port_lock);
52175 return cond;
52176 }
52177@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52178 /* if it's already open, start I/O ... and notify the serial
52179 * protocol about open/close status (connect/disconnect).
52180 */
52181- if (port->port.count) {
52182+ if (atomic_read(&port->port.count)) {
52183 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52184 gs_start_io(port);
52185 if (gser->connect)
52186@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52187
52188 port->port_usb = NULL;
52189 gser->ioport = NULL;
52190- if (port->port.count > 0 || port->openclose) {
52191+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52192 wake_up_interruptible(&port->drain_wait);
52193 if (port->port.tty)
52194 tty_hangup(port->port.tty);
52195@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52196
52197 /* finally, free any unused/unusable I/O buffers */
52198 spin_lock_irqsave(&port->port_lock, flags);
52199- if (port->port.count == 0 && !port->openclose)
52200+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52201 gs_buf_free(&port->port_write_buf);
52202 gs_free_requests(gser->out, &port->read_pool, NULL);
52203 gs_free_requests(gser->out, &port->read_queue, NULL);
52204diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52205index 7a55fea..cc0ed4f 100644
52206--- a/drivers/usb/gadget/u_uac1.c
52207+++ b/drivers/usb/gadget/u_uac1.c
52208@@ -16,6 +16,7 @@
52209 #include <linux/ctype.h>
52210 #include <linux/random.h>
52211 #include <linux/syscalls.h>
52212+#include <linux/module.h>
52213
52214 #include "u_uac1.h"
52215
52216diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52217index 7ae0c4d..35521b7 100644
52218--- a/drivers/usb/host/ehci-hub.c
52219+++ b/drivers/usb/host/ehci-hub.c
52220@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52221 urb->transfer_flags = URB_DIR_IN;
52222 usb_get_urb(urb);
52223 atomic_inc(&urb->use_count);
52224- atomic_inc(&urb->dev->urbnum);
52225+ atomic_inc_unchecked(&urb->dev->urbnum);
52226 urb->setup_dma = dma_map_single(
52227 hcd->self.controller,
52228 urb->setup_packet,
52229@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52230 urb->status = -EINPROGRESS;
52231 usb_get_urb(urb);
52232 atomic_inc(&urb->use_count);
52233- atomic_inc(&urb->dev->urbnum);
52234+ atomic_inc_unchecked(&urb->dev->urbnum);
52235 retval = submit_single_step_set_feature(hcd, urb, 0);
52236 if (!retval && !wait_for_completion_timeout(&done,
52237 msecs_to_jiffies(2000))) {
52238diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52239index ba6a5d6..f88f7f3 100644
52240--- a/drivers/usb/misc/appledisplay.c
52241+++ b/drivers/usb/misc/appledisplay.c
52242@@ -83,7 +83,7 @@ struct appledisplay {
52243 spinlock_t lock;
52244 };
52245
52246-static atomic_t count_displays = ATOMIC_INIT(0);
52247+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52248 static struct workqueue_struct *wq;
52249
52250 static void appledisplay_complete(struct urb *urb)
52251@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52252
52253 /* Register backlight device */
52254 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52255- atomic_inc_return(&count_displays) - 1);
52256+ atomic_inc_return_unchecked(&count_displays) - 1);
52257 memset(&props, 0, sizeof(struct backlight_properties));
52258 props.type = BACKLIGHT_RAW;
52259 props.max_brightness = 0xff;
52260diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52261index 8d7fc48..01c4986 100644
52262--- a/drivers/usb/serial/console.c
52263+++ b/drivers/usb/serial/console.c
52264@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52265
52266 info->port = port;
52267
52268- ++port->port.count;
52269+ atomic_inc(&port->port.count);
52270 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52271 if (serial->type->set_termios) {
52272 /*
52273@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52274 }
52275 /* Now that any required fake tty operations are completed restore
52276 * the tty port count */
52277- --port->port.count;
52278+ atomic_dec(&port->port.count);
52279 /* The console is special in terms of closing the device so
52280 * indicate this port is now acting as a system console. */
52281 port->port.console = 1;
52282@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52283 free_tty:
52284 kfree(tty);
52285 reset_open_count:
52286- port->port.count = 0;
52287+ atomic_set(&port->port.count, 0);
52288 usb_autopm_put_interface(serial->interface);
52289 error_get_interface:
52290 usb_serial_put(serial);
52291@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52292 static void usb_console_write(struct console *co,
52293 const char *buf, unsigned count)
52294 {
52295- static struct usbcons_info *info = &usbcons_info;
52296+ struct usbcons_info *info = &usbcons_info;
52297 struct usb_serial_port *port = info->port;
52298 struct usb_serial *serial;
52299 int retval = -ENODEV;
52300diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52301index 307e339..6aa97cb 100644
52302--- a/drivers/usb/storage/usb.h
52303+++ b/drivers/usb/storage/usb.h
52304@@ -63,7 +63,7 @@ struct us_unusual_dev {
52305 __u8 useProtocol;
52306 __u8 useTransport;
52307 int (*initFunction)(struct us_data *);
52308-};
52309+} __do_const;
52310
52311
52312 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52313diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52314index f2a8d29..7bc3fe7 100644
52315--- a/drivers/usb/wusbcore/wa-hc.h
52316+++ b/drivers/usb/wusbcore/wa-hc.h
52317@@ -240,7 +240,7 @@ struct wahc {
52318 spinlock_t xfer_list_lock;
52319 struct work_struct xfer_enqueue_work;
52320 struct work_struct xfer_error_work;
52321- atomic_t xfer_id_count;
52322+ atomic_unchecked_t xfer_id_count;
52323
52324 kernel_ulong_t quirks;
52325 };
52326@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52327 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52328 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52329 wa->dto_in_use = 0;
52330- atomic_set(&wa->xfer_id_count, 1);
52331+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52332 /* init the buf in URBs */
52333 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52334 usb_init_urb(&(wa->buf_in_urbs[index]));
52335diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52336index 3e2e4ed..060c9b8 100644
52337--- a/drivers/usb/wusbcore/wa-xfer.c
52338+++ b/drivers/usb/wusbcore/wa-xfer.c
52339@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52340 */
52341 static void wa_xfer_id_init(struct wa_xfer *xfer)
52342 {
52343- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52344+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52345 }
52346
52347 /* Return the xfer's ID. */
52348diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52349index 512f479..7e041d0 100644
52350--- a/drivers/vfio/vfio.c
52351+++ b/drivers/vfio/vfio.c
52352@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52353 return 0;
52354
52355 /* TODO Prevent device auto probing */
52356- WARN("Device %s added to live group %d!\n", dev_name(dev),
52357+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52358 iommu_group_id(group->iommu_group));
52359
52360 return 0;
52361diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52362index 5174eba..451e6bc 100644
52363--- a/drivers/vhost/vringh.c
52364+++ b/drivers/vhost/vringh.c
52365@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52366 /* Userspace access helpers: in this case, addresses are really userspace. */
52367 static inline int getu16_user(u16 *val, const u16 *p)
52368 {
52369- return get_user(*val, (__force u16 __user *)p);
52370+ return get_user(*val, (u16 __force_user *)p);
52371 }
52372
52373 static inline int putu16_user(u16 *p, u16 val)
52374 {
52375- return put_user(val, (__force u16 __user *)p);
52376+ return put_user(val, (u16 __force_user *)p);
52377 }
52378
52379 static inline int copydesc_user(void *dst, const void *src, size_t len)
52380 {
52381- return copy_from_user(dst, (__force void __user *)src, len) ?
52382+ return copy_from_user(dst, (void __force_user *)src, len) ?
52383 -EFAULT : 0;
52384 }
52385
52386@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52387 const struct vring_used_elem *src,
52388 unsigned int num)
52389 {
52390- return copy_to_user((__force void __user *)dst, src,
52391+ return copy_to_user((void __force_user *)dst, src,
52392 sizeof(*dst) * num) ? -EFAULT : 0;
52393 }
52394
52395 static inline int xfer_from_user(void *src, void *dst, size_t len)
52396 {
52397- return copy_from_user(dst, (__force void __user *)src, len) ?
52398+ return copy_from_user(dst, (void __force_user *)src, len) ?
52399 -EFAULT : 0;
52400 }
52401
52402 static inline int xfer_to_user(void *dst, void *src, size_t len)
52403 {
52404- return copy_to_user((__force void __user *)dst, src, len) ?
52405+ return copy_to_user((void __force_user *)dst, src, len) ?
52406 -EFAULT : 0;
52407 }
52408
52409@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52410 vrh->last_used_idx = 0;
52411 vrh->vring.num = num;
52412 /* vring expects kernel addresses, but only used via accessors. */
52413- vrh->vring.desc = (__force struct vring_desc *)desc;
52414- vrh->vring.avail = (__force struct vring_avail *)avail;
52415- vrh->vring.used = (__force struct vring_used *)used;
52416+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52417+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52418+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52419 return 0;
52420 }
52421 EXPORT_SYMBOL(vringh_init_user);
52422@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52423
52424 static inline int putu16_kern(u16 *p, u16 val)
52425 {
52426- ACCESS_ONCE(*p) = val;
52427+ ACCESS_ONCE_RW(*p) = val;
52428 return 0;
52429 }
52430
52431diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52432index 84a110a..96312c3 100644
52433--- a/drivers/video/backlight/kb3886_bl.c
52434+++ b/drivers/video/backlight/kb3886_bl.c
52435@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52436 static unsigned long kb3886bl_flags;
52437 #define KB3886BL_SUSPENDED 0x01
52438
52439-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52440+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52441 {
52442 .ident = "Sahara Touch-iT",
52443 .matches = {
52444diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52445index 1b0b233..6f34c2c 100644
52446--- a/drivers/video/fbdev/arcfb.c
52447+++ b/drivers/video/fbdev/arcfb.c
52448@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52449 return -ENOSPC;
52450
52451 err = 0;
52452- if ((count + p) > fbmemlength) {
52453+ if (count > (fbmemlength - p)) {
52454 count = fbmemlength - p;
52455 err = -ENOSPC;
52456 }
52457diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52458index 52108be..c7c110d 100644
52459--- a/drivers/video/fbdev/aty/aty128fb.c
52460+++ b/drivers/video/fbdev/aty/aty128fb.c
52461@@ -149,7 +149,7 @@ enum {
52462 };
52463
52464 /* Must match above enum */
52465-static char * const r128_family[] = {
52466+static const char * const r128_family[] = {
52467 "AGP",
52468 "PCI",
52469 "PRO AGP",
52470diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52471index c3d0074..0b9077e 100644
52472--- a/drivers/video/fbdev/aty/atyfb_base.c
52473+++ b/drivers/video/fbdev/aty/atyfb_base.c
52474@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52475 par->accel_flags = var->accel_flags; /* hack */
52476
52477 if (var->accel_flags) {
52478- info->fbops->fb_sync = atyfb_sync;
52479+ pax_open_kernel();
52480+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52481+ pax_close_kernel();
52482 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52483 } else {
52484- info->fbops->fb_sync = NULL;
52485+ pax_open_kernel();
52486+ *(void **)&info->fbops->fb_sync = NULL;
52487+ pax_close_kernel();
52488 info->flags |= FBINFO_HWACCEL_DISABLED;
52489 }
52490
52491diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52492index 2fa0317..4983f2a 100644
52493--- a/drivers/video/fbdev/aty/mach64_cursor.c
52494+++ b/drivers/video/fbdev/aty/mach64_cursor.c
52495@@ -8,6 +8,7 @@
52496 #include "../core/fb_draw.h"
52497
52498 #include <asm/io.h>
52499+#include <asm/pgtable.h>
52500
52501 #ifdef __sparc__
52502 #include <asm/fbio.h>
52503@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52504 info->sprite.buf_align = 16; /* and 64 lines tall. */
52505 info->sprite.flags = FB_PIXMAP_IO;
52506
52507- info->fbops->fb_cursor = atyfb_cursor;
52508+ pax_open_kernel();
52509+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52510+ pax_close_kernel();
52511
52512 return 0;
52513 }
52514diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
52515index 900aa4e..6d49418 100644
52516--- a/drivers/video/fbdev/core/fb_defio.c
52517+++ b/drivers/video/fbdev/core/fb_defio.c
52518@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52519
52520 BUG_ON(!fbdefio);
52521 mutex_init(&fbdefio->lock);
52522- info->fbops->fb_mmap = fb_deferred_io_mmap;
52523+ pax_open_kernel();
52524+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52525+ pax_close_kernel();
52526 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52527 INIT_LIST_HEAD(&fbdefio->pagelist);
52528 if (fbdefio->delay == 0) /* set a default of 1 s */
52529@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52530 page->mapping = NULL;
52531 }
52532
52533- info->fbops->fb_mmap = NULL;
52534+ *(void **)&info->fbops->fb_mmap = NULL;
52535 mutex_destroy(&fbdefio->lock);
52536 }
52537 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52538diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
52539index b6d5008..5bca7bf 100644
52540--- a/drivers/video/fbdev/core/fbmem.c
52541+++ b/drivers/video/fbdev/core/fbmem.c
52542@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52543 image->dx += image->width + 8;
52544 }
52545 } else if (rotate == FB_ROTATE_UD) {
52546- for (x = 0; x < num && image->dx >= 0; x++) {
52547+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52548 info->fbops->fb_imageblit(info, image);
52549 image->dx -= image->width + 8;
52550 }
52551@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52552 image->dy += image->height + 8;
52553 }
52554 } else if (rotate == FB_ROTATE_CCW) {
52555- for (x = 0; x < num && image->dy >= 0; x++) {
52556+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52557 info->fbops->fb_imageblit(info, image);
52558 image->dy -= image->height + 8;
52559 }
52560@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52561 return -EFAULT;
52562 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52563 return -EINVAL;
52564- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52565+ if (con2fb.framebuffer >= FB_MAX)
52566 return -EINVAL;
52567 if (!registered_fb[con2fb.framebuffer])
52568 request_module("fb%d", con2fb.framebuffer);
52569@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52570 __u32 data;
52571 int err;
52572
52573- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52574+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52575
52576 data = (__u32) (unsigned long) fix->smem_start;
52577 err |= put_user(data, &fix32->smem_start);
52578diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
52579index e23392e..8a77540 100644
52580--- a/drivers/video/fbdev/hyperv_fb.c
52581+++ b/drivers/video/fbdev/hyperv_fb.c
52582@@ -235,7 +235,7 @@ static uint screen_fb_size;
52583 static inline int synthvid_send(struct hv_device *hdev,
52584 struct synthvid_msg *msg)
52585 {
52586- static atomic64_t request_id = ATOMIC64_INIT(0);
52587+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52588 int ret;
52589
52590 msg->pipe_hdr.type = PIPE_MSG_DATA;
52591@@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52592
52593 ret = vmbus_sendpacket(hdev->channel, msg,
52594 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52595- atomic64_inc_return(&request_id),
52596+ atomic64_inc_return_unchecked(&request_id),
52597 VM_PKT_DATA_INBAND, 0);
52598
52599 if (ret)
52600diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
52601index 7672d2e..b56437f 100644
52602--- a/drivers/video/fbdev/i810/i810_accel.c
52603+++ b/drivers/video/fbdev/i810/i810_accel.c
52604@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52605 }
52606 }
52607 printk("ringbuffer lockup!!!\n");
52608+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52609 i810_report_error(mmio);
52610 par->dev_flags |= LOCKUP;
52611 info->pixmap.scan_align = 1;
52612diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52613index a01147f..5d896f8 100644
52614--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52615+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52616@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
52617
52618 #ifdef CONFIG_FB_MATROX_MYSTIQUE
52619 struct matrox_switch matrox_mystique = {
52620- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
52621+ .preinit = MGA1064_preinit,
52622+ .reset = MGA1064_reset,
52623+ .init = MGA1064_init,
52624+ .restore = MGA1064_restore,
52625 };
52626 EXPORT_SYMBOL(matrox_mystique);
52627 #endif
52628
52629 #ifdef CONFIG_FB_MATROX_G
52630 struct matrox_switch matrox_G100 = {
52631- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
52632+ .preinit = MGAG100_preinit,
52633+ .reset = MGAG100_reset,
52634+ .init = MGAG100_init,
52635+ .restore = MGAG100_restore,
52636 };
52637 EXPORT_SYMBOL(matrox_G100);
52638 #endif
52639diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52640index 195ad7c..09743fc 100644
52641--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52642+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52643@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
52644 }
52645
52646 struct matrox_switch matrox_millennium = {
52647- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
52648+ .preinit = Ti3026_preinit,
52649+ .reset = Ti3026_reset,
52650+ .init = Ti3026_init,
52651+ .restore = Ti3026_restore
52652 };
52653 EXPORT_SYMBOL(matrox_millennium);
52654 #endif
52655diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52656index fe92eed..106e085 100644
52657--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52658+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52659@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52660 struct mb862xxfb_par *par = info->par;
52661
52662 if (info->var.bits_per_pixel == 32) {
52663- info->fbops->fb_fillrect = cfb_fillrect;
52664- info->fbops->fb_copyarea = cfb_copyarea;
52665- info->fbops->fb_imageblit = cfb_imageblit;
52666+ pax_open_kernel();
52667+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52668+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52669+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52670+ pax_close_kernel();
52671 } else {
52672 outreg(disp, GC_L0EM, 3);
52673- info->fbops->fb_fillrect = mb86290fb_fillrect;
52674- info->fbops->fb_copyarea = mb86290fb_copyarea;
52675- info->fbops->fb_imageblit = mb86290fb_imageblit;
52676+ pax_open_kernel();
52677+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52678+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52679+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52680+ pax_close_kernel();
52681 }
52682 outreg(draw, GDC_REG_DRAW_BASE, 0);
52683 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52684diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
52685index def0412..fed6529 100644
52686--- a/drivers/video/fbdev/nvidia/nvidia.c
52687+++ b/drivers/video/fbdev/nvidia/nvidia.c
52688@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52689 info->fix.line_length = (info->var.xres_virtual *
52690 info->var.bits_per_pixel) >> 3;
52691 if (info->var.accel_flags) {
52692- info->fbops->fb_imageblit = nvidiafb_imageblit;
52693- info->fbops->fb_fillrect = nvidiafb_fillrect;
52694- info->fbops->fb_copyarea = nvidiafb_copyarea;
52695- info->fbops->fb_sync = nvidiafb_sync;
52696+ pax_open_kernel();
52697+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52698+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52699+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52700+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52701+ pax_close_kernel();
52702 info->pixmap.scan_align = 4;
52703 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52704 info->flags |= FBINFO_READS_FAST;
52705 NVResetGraphics(info);
52706 } else {
52707- info->fbops->fb_imageblit = cfb_imageblit;
52708- info->fbops->fb_fillrect = cfb_fillrect;
52709- info->fbops->fb_copyarea = cfb_copyarea;
52710- info->fbops->fb_sync = NULL;
52711+ pax_open_kernel();
52712+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52713+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52714+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52715+ *(void **)&info->fbops->fb_sync = NULL;
52716+ pax_close_kernel();
52717 info->pixmap.scan_align = 1;
52718 info->flags |= FBINFO_HWACCEL_DISABLED;
52719 info->flags &= ~FBINFO_READS_FAST;
52720@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52721 info->pixmap.size = 8 * 1024;
52722 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52723
52724- if (!hwcur)
52725- info->fbops->fb_cursor = NULL;
52726+ if (!hwcur) {
52727+ pax_open_kernel();
52728+ *(void **)&info->fbops->fb_cursor = NULL;
52729+ pax_close_kernel();
52730+ }
52731
52732 info->var.accel_flags = (!noaccel);
52733
52734diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
52735index 2412a0d..294215b 100644
52736--- a/drivers/video/fbdev/omap2/dss/display.c
52737+++ b/drivers/video/fbdev/omap2/dss/display.c
52738@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
52739 if (dssdev->name == NULL)
52740 dssdev->name = dssdev->alias;
52741
52742+ pax_open_kernel();
52743 if (drv && drv->get_resolution == NULL)
52744- drv->get_resolution = omapdss_default_get_resolution;
52745+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
52746 if (drv && drv->get_recommended_bpp == NULL)
52747- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52748+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52749 if (drv && drv->get_timings == NULL)
52750- drv->get_timings = omapdss_default_get_timings;
52751+ *(void **)&drv->get_timings = omapdss_default_get_timings;
52752+ pax_close_kernel();
52753
52754 mutex_lock(&panel_list_mutex);
52755 list_add_tail(&dssdev->panel_list, &panel_list);
52756diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
52757index 83433cb..71e9b98 100644
52758--- a/drivers/video/fbdev/s1d13xxxfb.c
52759+++ b/drivers/video/fbdev/s1d13xxxfb.c
52760@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52761
52762 switch(prod_id) {
52763 case S1D13506_PROD_ID: /* activate acceleration */
52764- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52765- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52766+ pax_open_kernel();
52767+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52768+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52769+ pax_close_kernel();
52770 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52771 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52772 break;
52773diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52774index 2bcc84a..29dd1ea 100644
52775--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
52776+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52777@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
52778 }
52779
52780 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
52781- lcdc_sys_write_index,
52782- lcdc_sys_write_data,
52783- lcdc_sys_read_data,
52784+ .write_index = lcdc_sys_write_index,
52785+ .write_data = lcdc_sys_write_data,
52786+ .read_data = lcdc_sys_read_data,
52787 };
52788
52789 static int sh_mobile_lcdc_sginit(struct fb_info *info,
52790diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
52791index d513ed6..90b0de9 100644
52792--- a/drivers/video/fbdev/smscufx.c
52793+++ b/drivers/video/fbdev/smscufx.c
52794@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52795 fb_deferred_io_cleanup(info);
52796 kfree(info->fbdefio);
52797 info->fbdefio = NULL;
52798- info->fbops->fb_mmap = ufx_ops_mmap;
52799+ pax_open_kernel();
52800+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52801+ pax_close_kernel();
52802 }
52803
52804 pr_debug("released /dev/fb%d user=%d count=%d",
52805diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
52806index 77b890e..458e666 100644
52807--- a/drivers/video/fbdev/udlfb.c
52808+++ b/drivers/video/fbdev/udlfb.c
52809@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52810 dlfb_urb_completion(urb);
52811
52812 error:
52813- atomic_add(bytes_sent, &dev->bytes_sent);
52814- atomic_add(bytes_identical, &dev->bytes_identical);
52815- atomic_add(width*height*2, &dev->bytes_rendered);
52816+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52817+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52818+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52819 end_cycles = get_cycles();
52820- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52821+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52822 >> 10)), /* Kcycles */
52823 &dev->cpu_kcycles_used);
52824
52825@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52826 dlfb_urb_completion(urb);
52827
52828 error:
52829- atomic_add(bytes_sent, &dev->bytes_sent);
52830- atomic_add(bytes_identical, &dev->bytes_identical);
52831- atomic_add(bytes_rendered, &dev->bytes_rendered);
52832+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52833+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52834+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
52835 end_cycles = get_cycles();
52836- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52837+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52838 >> 10)), /* Kcycles */
52839 &dev->cpu_kcycles_used);
52840 }
52841@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52842 fb_deferred_io_cleanup(info);
52843 kfree(info->fbdefio);
52844 info->fbdefio = NULL;
52845- info->fbops->fb_mmap = dlfb_ops_mmap;
52846+ pax_open_kernel();
52847+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
52848+ pax_close_kernel();
52849 }
52850
52851 pr_warn("released /dev/fb%d user=%d count=%d\n",
52852@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
52853 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52854 struct dlfb_data *dev = fb_info->par;
52855 return snprintf(buf, PAGE_SIZE, "%u\n",
52856- atomic_read(&dev->bytes_rendered));
52857+ atomic_read_unchecked(&dev->bytes_rendered));
52858 }
52859
52860 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52861@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52862 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52863 struct dlfb_data *dev = fb_info->par;
52864 return snprintf(buf, PAGE_SIZE, "%u\n",
52865- atomic_read(&dev->bytes_identical));
52866+ atomic_read_unchecked(&dev->bytes_identical));
52867 }
52868
52869 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52870@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52871 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52872 struct dlfb_data *dev = fb_info->par;
52873 return snprintf(buf, PAGE_SIZE, "%u\n",
52874- atomic_read(&dev->bytes_sent));
52875+ atomic_read_unchecked(&dev->bytes_sent));
52876 }
52877
52878 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52879@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52880 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52881 struct dlfb_data *dev = fb_info->par;
52882 return snprintf(buf, PAGE_SIZE, "%u\n",
52883- atomic_read(&dev->cpu_kcycles_used));
52884+ atomic_read_unchecked(&dev->cpu_kcycles_used));
52885 }
52886
52887 static ssize_t edid_show(
52888@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52889 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52890 struct dlfb_data *dev = fb_info->par;
52891
52892- atomic_set(&dev->bytes_rendered, 0);
52893- atomic_set(&dev->bytes_identical, 0);
52894- atomic_set(&dev->bytes_sent, 0);
52895- atomic_set(&dev->cpu_kcycles_used, 0);
52896+ atomic_set_unchecked(&dev->bytes_rendered, 0);
52897+ atomic_set_unchecked(&dev->bytes_identical, 0);
52898+ atomic_set_unchecked(&dev->bytes_sent, 0);
52899+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52900
52901 return count;
52902 }
52903diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
52904index 509d452..7c9d2de 100644
52905--- a/drivers/video/fbdev/uvesafb.c
52906+++ b/drivers/video/fbdev/uvesafb.c
52907@@ -19,6 +19,7 @@
52908 #include <linux/io.h>
52909 #include <linux/mutex.h>
52910 #include <linux/slab.h>
52911+#include <linux/moduleloader.h>
52912 #include <video/edid.h>
52913 #include <video/uvesafb.h>
52914 #ifdef CONFIG_X86
52915@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52916 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52917 par->pmi_setpal = par->ypan = 0;
52918 } else {
52919+
52920+#ifdef CONFIG_PAX_KERNEXEC
52921+#ifdef CONFIG_MODULES
52922+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52923+#endif
52924+ if (!par->pmi_code) {
52925+ par->pmi_setpal = par->ypan = 0;
52926+ return 0;
52927+ }
52928+#endif
52929+
52930 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52931 + task->t.regs.edi);
52932+
52933+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52934+ pax_open_kernel();
52935+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52936+ pax_close_kernel();
52937+
52938+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52939+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52940+#else
52941 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52942 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52943+#endif
52944+
52945 printk(KERN_INFO "uvesafb: protected mode interface info at "
52946 "%04x:%04x\n",
52947 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52948@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52949 par->ypan = ypan;
52950
52951 if (par->pmi_setpal || par->ypan) {
52952+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52953 if (__supported_pte_mask & _PAGE_NX) {
52954 par->pmi_setpal = par->ypan = 0;
52955 printk(KERN_WARNING "uvesafb: NX protection is active, "
52956 "better not use the PMI.\n");
52957- } else {
52958+ } else
52959+#endif
52960 uvesafb_vbe_getpmi(task, par);
52961- }
52962 }
52963 #else
52964 /* The protected mode interface is not available on non-x86. */
52965@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52966 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52967
52968 /* Disable blanking if the user requested so. */
52969- if (!blank)
52970- info->fbops->fb_blank = NULL;
52971+ if (!blank) {
52972+ pax_open_kernel();
52973+ *(void **)&info->fbops->fb_blank = NULL;
52974+ pax_close_kernel();
52975+ }
52976
52977 /*
52978 * Find out how much IO memory is required for the mode with
52979@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52980 info->flags = FBINFO_FLAG_DEFAULT |
52981 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52982
52983- if (!par->ypan)
52984- info->fbops->fb_pan_display = NULL;
52985+ if (!par->ypan) {
52986+ pax_open_kernel();
52987+ *(void **)&info->fbops->fb_pan_display = NULL;
52988+ pax_close_kernel();
52989+ }
52990 }
52991
52992 static void uvesafb_init_mtrr(struct fb_info *info)
52993@@ -1787,6 +1817,11 @@ out_mode:
52994 out:
52995 kfree(par->vbe_modes);
52996
52997+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52998+ if (par->pmi_code)
52999+ module_free_exec(NULL, par->pmi_code);
53000+#endif
53001+
53002 framebuffer_release(info);
53003 return err;
53004 }
53005@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
53006 kfree(par->vbe_state_orig);
53007 kfree(par->vbe_state_saved);
53008
53009+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53010+ if (par->pmi_code)
53011+ module_free_exec(NULL, par->pmi_code);
53012+#endif
53013+
53014 framebuffer_release(info);
53015 }
53016 return 0;
53017diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
53018index 6170e7f..dd63031 100644
53019--- a/drivers/video/fbdev/vesafb.c
53020+++ b/drivers/video/fbdev/vesafb.c
53021@@ -9,6 +9,7 @@
53022 */
53023
53024 #include <linux/module.h>
53025+#include <linux/moduleloader.h>
53026 #include <linux/kernel.h>
53027 #include <linux/errno.h>
53028 #include <linux/string.h>
53029@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53030 static int vram_total; /* Set total amount of memory */
53031 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53032 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53033-static void (*pmi_start)(void) __read_mostly;
53034-static void (*pmi_pal) (void) __read_mostly;
53035+static void (*pmi_start)(void) __read_only;
53036+static void (*pmi_pal) (void) __read_only;
53037 static int depth __read_mostly;
53038 static int vga_compat __read_mostly;
53039 /* --------------------------------------------------------------------- */
53040@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
53041 unsigned int size_remap;
53042 unsigned int size_total;
53043 char *option = NULL;
53044+ void *pmi_code = NULL;
53045
53046 /* ignore error return of fb_get_options */
53047 fb_get_options("vesafb", &option);
53048@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
53049 size_remap = size_total;
53050 vesafb_fix.smem_len = size_remap;
53051
53052-#ifndef __i386__
53053- screen_info.vesapm_seg = 0;
53054-#endif
53055-
53056 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53057 printk(KERN_WARNING
53058 "vesafb: cannot reserve video memory at 0x%lx\n",
53059@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53060 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53061 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53062
53063+#ifdef __i386__
53064+
53065+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53066+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
53067+ if (!pmi_code)
53068+#elif !defined(CONFIG_PAX_KERNEXEC)
53069+ if (0)
53070+#endif
53071+
53072+#endif
53073+ screen_info.vesapm_seg = 0;
53074+
53075 if (screen_info.vesapm_seg) {
53076- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53077- screen_info.vesapm_seg,screen_info.vesapm_off);
53078+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53079+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53080 }
53081
53082 if (screen_info.vesapm_seg < 0xc000)
53083@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53084
53085 if (ypan || pmi_setpal) {
53086 unsigned short *pmi_base;
53087+
53088 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53089- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53090- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53091+
53092+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53093+ pax_open_kernel();
53094+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53095+#else
53096+ pmi_code = pmi_base;
53097+#endif
53098+
53099+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53100+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53101+
53102+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53103+ pmi_start = ktva_ktla(pmi_start);
53104+ pmi_pal = ktva_ktla(pmi_pal);
53105+ pax_close_kernel();
53106+#endif
53107+
53108 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53109 if (pmi_base[3]) {
53110 printk(KERN_INFO "vesafb: pmi: ports = ");
53111@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53112 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53113 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53114
53115- if (!ypan)
53116- info->fbops->fb_pan_display = NULL;
53117+ if (!ypan) {
53118+ pax_open_kernel();
53119+ *(void **)&info->fbops->fb_pan_display = NULL;
53120+ pax_close_kernel();
53121+ }
53122
53123 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53124 err = -ENOMEM;
53125@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53126 fb_info(info, "%s frame buffer device\n", info->fix.id);
53127 return 0;
53128 err:
53129+
53130+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53131+ module_free_exec(NULL, pmi_code);
53132+#endif
53133+
53134 if (info->screen_base)
53135 iounmap(info->screen_base);
53136 framebuffer_release(info);
53137diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53138index 88714ae..16c2e11 100644
53139--- a/drivers/video/fbdev/via/via_clock.h
53140+++ b/drivers/video/fbdev/via/via_clock.h
53141@@ -56,7 +56,7 @@ struct via_clock {
53142
53143 void (*set_engine_pll_state)(u8 state);
53144 void (*set_engine_pll)(struct via_pll_config config);
53145-};
53146+} __no_const;
53147
53148
53149 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53150diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53151index 3c14e43..2630570 100644
53152--- a/drivers/video/logo/logo_linux_clut224.ppm
53153+++ b/drivers/video/logo/logo_linux_clut224.ppm
53154@@ -2,1603 +2,1123 @@ P3
53155 # Standard 224-color Linux logo
53156 80 80
53157 255
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 0 0 0 0 0 0 0 0 0
53163- 0 0 0 0 0 0 0 0 0 0 0 0
53164- 0 0 0 0 0 0 0 0 0 0 0 0
53165- 0 0 0 0 0 0 0 0 0 0 0 0
53166- 0 0 0 0 0 0 0 0 0 0 0 0
53167- 6 6 6 6 6 6 10 10 10 10 10 10
53168- 10 10 10 6 6 6 6 6 6 6 6 6
53169- 0 0 0 0 0 0 0 0 0 0 0 0
53170- 0 0 0 0 0 0 0 0 0 0 0 0
53171- 0 0 0 0 0 0 0 0 0 0 0 0
53172- 0 0 0 0 0 0 0 0 0 0 0 0
53173- 0 0 0 0 0 0 0 0 0 0 0 0
53174- 0 0 0 0 0 0 0 0 0 0 0 0
53175- 0 0 0 0 0 0 0 0 0 0 0 0
53176- 0 0 0 0 0 0 0 0 0 0 0 0
53177- 0 0 0 0 0 0 0 0 0 0 0 0
53178- 0 0 0 0 0 0 0 0 0 0 0 0
53179- 0 0 0 0 0 0 0 0 0 0 0 0
53180- 0 0 0 0 0 0 0 0 0 0 0 0
53181- 0 0 0 0 0 0 0 0 0 0 0 0
53182- 0 0 0 0 0 0 0 0 0 0 0 0
53183- 0 0 0 0 0 0 0 0 0 0 0 0
53184- 0 0 0 0 0 0 0 0 0 0 0 0
53185- 0 0 0 0 0 0 0 0 0 0 0 0
53186- 0 0 0 6 6 6 10 10 10 14 14 14
53187- 22 22 22 26 26 26 30 30 30 34 34 34
53188- 30 30 30 30 30 30 26 26 26 18 18 18
53189- 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 0 0 0
53196- 0 0 0 0 0 0 0 0 0 0 0 0
53197- 0 0 0 0 0 0 0 0 0 0 0 0
53198- 0 0 0 0 0 0 0 0 0 0 0 0
53199- 0 0 0 0 0 1 0 0 1 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 0 0 0
53202- 0 0 0 0 0 0 0 0 0 0 0 0
53203- 0 0 0 0 0 0 0 0 0 0 0 0
53204- 0 0 0 0 0 0 0 0 0 0 0 0
53205- 0 0 0 0 0 0 0 0 0 0 0 0
53206- 6 6 6 14 14 14 26 26 26 42 42 42
53207- 54 54 54 66 66 66 78 78 78 78 78 78
53208- 78 78 78 74 74 74 66 66 66 54 54 54
53209- 42 42 42 26 26 26 18 18 18 10 10 10
53210- 6 6 6 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 0 0 0 0 0 0 0 0 0 0
53216- 0 0 0 0 0 0 0 0 0 0 0 0
53217- 0 0 0 0 0 0 0 0 0 0 0 0
53218- 0 0 0 0 0 0 0 0 0 0 0 0
53219- 0 0 1 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 0 0 0 0 0 0
53222- 0 0 0 0 0 0 0 0 0 0 0 0
53223- 0 0 0 0 0 0 0 0 0 0 0 0
53224- 0 0 0 0 0 0 0 0 0 0 0 0
53225- 0 0 0 0 0 0 0 0 0 10 10 10
53226- 22 22 22 42 42 42 66 66 66 86 86 86
53227- 66 66 66 38 38 38 38 38 38 22 22 22
53228- 26 26 26 34 34 34 54 54 54 66 66 66
53229- 86 86 86 70 70 70 46 46 46 26 26 26
53230- 14 14 14 6 6 6 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 1 0 0 1 0 0 1 0 0 0
53240- 0 0 0 0 0 0 0 0 0 0 0 0
53241- 0 0 0 0 0 0 0 0 0 0 0 0
53242- 0 0 0 0 0 0 0 0 0 0 0 0
53243- 0 0 0 0 0 0 0 0 0 0 0 0
53244- 0 0 0 0 0 0 0 0 0 0 0 0
53245- 0 0 0 0 0 0 10 10 10 26 26 26
53246- 50 50 50 82 82 82 58 58 58 6 6 6
53247- 2 2 6 2 2 6 2 2 6 2 2 6
53248- 2 2 6 2 2 6 2 2 6 2 2 6
53249- 6 6 6 54 54 54 86 86 86 66 66 66
53250- 38 38 38 18 18 18 6 6 6 0 0 0
53251- 0 0 0 0 0 0 0 0 0 0 0 0
53252- 0 0 0 0 0 0 0 0 0 0 0 0
53253- 0 0 0 0 0 0 0 0 0 0 0 0
53254- 0 0 0 0 0 0 0 0 0 0 0 0
53255- 0 0 0 0 0 0 0 0 0 0 0 0
53256- 0 0 0 0 0 0 0 0 0 0 0 0
53257- 0 0 0 0 0 0 0 0 0 0 0 0
53258- 0 0 0 0 0 0 0 0 0 0 0 0
53259- 0 0 0 0 0 0 0 0 0 0 0 0
53260- 0 0 0 0 0 0 0 0 0 0 0 0
53261- 0 0 0 0 0 0 0 0 0 0 0 0
53262- 0 0 0 0 0 0 0 0 0 0 0 0
53263- 0 0 0 0 0 0 0 0 0 0 0 0
53264- 0 0 0 0 0 0 0 0 0 0 0 0
53265- 0 0 0 6 6 6 22 22 22 50 50 50
53266- 78 78 78 34 34 34 2 2 6 2 2 6
53267- 2 2 6 2 2 6 2 2 6 2 2 6
53268- 2 2 6 2 2 6 2 2 6 2 2 6
53269- 2 2 6 2 2 6 6 6 6 70 70 70
53270- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
53276- 0 0 0 0 0 0 0 0 0 0 0 0
53277- 0 0 0 0 0 0 0 0 0 0 0 0
53278- 0 0 0 0 0 0 0 0 0 0 0 0
53279- 0 0 1 0 0 1 0 0 1 0 0 0
53280- 0 0 0 0 0 0 0 0 0 0 0 0
53281- 0 0 0 0 0 0 0 0 0 0 0 0
53282- 0 0 0 0 0 0 0 0 0 0 0 0
53283- 0 0 0 0 0 0 0 0 0 0 0 0
53284- 0 0 0 0 0 0 0 0 0 0 0 0
53285- 6 6 6 18 18 18 42 42 42 82 82 82
53286- 26 26 26 2 2 6 2 2 6 2 2 6
53287- 2 2 6 2 2 6 2 2 6 2 2 6
53288- 2 2 6 2 2 6 2 2 6 14 14 14
53289- 46 46 46 34 34 34 6 6 6 2 2 6
53290- 42 42 42 78 78 78 42 42 42 18 18 18
53291- 6 6 6 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 0 0 0 0 0 0 0 0 0 0
53296- 0 0 0 0 0 0 0 0 0 0 0 0
53297- 0 0 0 0 0 0 0 0 0 0 0 0
53298- 0 0 0 0 0 0 0 0 0 0 0 0
53299- 0 0 1 0 0 0 0 0 1 0 0 0
53300- 0 0 0 0 0 0 0 0 0 0 0 0
53301- 0 0 0 0 0 0 0 0 0 0 0 0
53302- 0 0 0 0 0 0 0 0 0 0 0 0
53303- 0 0 0 0 0 0 0 0 0 0 0 0
53304- 0 0 0 0 0 0 0 0 0 0 0 0
53305- 10 10 10 30 30 30 66 66 66 58 58 58
53306- 2 2 6 2 2 6 2 2 6 2 2 6
53307- 2 2 6 2 2 6 2 2 6 2 2 6
53308- 2 2 6 2 2 6 2 2 6 26 26 26
53309- 86 86 86 101 101 101 46 46 46 10 10 10
53310- 2 2 6 58 58 58 70 70 70 34 34 34
53311- 10 10 10 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 1 0 0 1 0 0 1 0 0 0
53320- 0 0 0 0 0 0 0 0 0 0 0 0
53321- 0 0 0 0 0 0 0 0 0 0 0 0
53322- 0 0 0 0 0 0 0 0 0 0 0 0
53323- 0 0 0 0 0 0 0 0 0 0 0 0
53324- 0 0 0 0 0 0 0 0 0 0 0 0
53325- 14 14 14 42 42 42 86 86 86 10 10 10
53326- 2 2 6 2 2 6 2 2 6 2 2 6
53327- 2 2 6 2 2 6 2 2 6 2 2 6
53328- 2 2 6 2 2 6 2 2 6 30 30 30
53329- 94 94 94 94 94 94 58 58 58 26 26 26
53330- 2 2 6 6 6 6 78 78 78 54 54 54
53331- 22 22 22 6 6 6 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 0 0 0 0 0 0 0
53336- 0 0 0 0 0 0 0 0 0 0 0 0
53337- 0 0 0 0 0 0 0 0 0 0 0 0
53338- 0 0 0 0 0 0 0 0 0 0 0 0
53339- 0 0 0 0 0 0 0 0 0 0 0 0
53340- 0 0 0 0 0 0 0 0 0 0 0 0
53341- 0 0 0 0 0 0 0 0 0 0 0 0
53342- 0 0 0 0 0 0 0 0 0 0 0 0
53343- 0 0 0 0 0 0 0 0 0 0 0 0
53344- 0 0 0 0 0 0 0 0 0 6 6 6
53345- 22 22 22 62 62 62 62 62 62 2 2 6
53346- 2 2 6 2 2 6 2 2 6 2 2 6
53347- 2 2 6 2 2 6 2 2 6 2 2 6
53348- 2 2 6 2 2 6 2 2 6 26 26 26
53349- 54 54 54 38 38 38 18 18 18 10 10 10
53350- 2 2 6 2 2 6 34 34 34 82 82 82
53351- 38 38 38 14 14 14 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 0 0 0 0 0 0 0 0 0 0
53356- 0 0 0 0 0 0 0 0 0 0 0 0
53357- 0 0 0 0 0 0 0 0 0 0 0 0
53358- 0 0 0 0 0 0 0 0 0 0 0 0
53359- 0 0 0 0 0 1 0 0 1 0 0 0
53360- 0 0 0 0 0 0 0 0 0 0 0 0
53361- 0 0 0 0 0 0 0 0 0 0 0 0
53362- 0 0 0 0 0 0 0 0 0 0 0 0
53363- 0 0 0 0 0 0 0 0 0 0 0 0
53364- 0 0 0 0 0 0 0 0 0 6 6 6
53365- 30 30 30 78 78 78 30 30 30 2 2 6
53366- 2 2 6 2 2 6 2 2 6 2 2 6
53367- 2 2 6 2 2 6 2 2 6 2 2 6
53368- 2 2 6 2 2 6 2 2 6 10 10 10
53369- 10 10 10 2 2 6 2 2 6 2 2 6
53370- 2 2 6 2 2 6 2 2 6 78 78 78
53371- 50 50 50 18 18 18 6 6 6 0 0 0
53372- 0 0 0 0 0 0 0 0 0 0 0 0
53373- 0 0 0 0 0 0 0 0 0 0 0 0
53374- 0 0 0 0 0 0 0 0 0 0 0 0
53375- 0 0 0 0 0 0 0 0 0 0 0 0
53376- 0 0 0 0 0 0 0 0 0 0 0 0
53377- 0 0 0 0 0 0 0 0 0 0 0 0
53378- 0 0 0 0 0 0 0 0 0 0 0 0
53379- 0 0 1 0 0 0 0 0 0 0 0 0
53380- 0 0 0 0 0 0 0 0 0 0 0 0
53381- 0 0 0 0 0 0 0 0 0 0 0 0
53382- 0 0 0 0 0 0 0 0 0 0 0 0
53383- 0 0 0 0 0 0 0 0 0 0 0 0
53384- 0 0 0 0 0 0 0 0 0 10 10 10
53385- 38 38 38 86 86 86 14 14 14 2 2 6
53386- 2 2 6 2 2 6 2 2 6 2 2 6
53387- 2 2 6 2 2 6 2 2 6 2 2 6
53388- 2 2 6 2 2 6 2 2 6 2 2 6
53389- 2 2 6 2 2 6 2 2 6 2 2 6
53390- 2 2 6 2 2 6 2 2 6 54 54 54
53391- 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0 0 0 0 0
53396- 0 0 0 0 0 0 0 0 0 0 0 0
53397- 0 0 0 0 0 0 0 0 0 0 0 0
53398- 0 0 0 0 0 0 0 0 0 0 0 0
53399- 0 0 0 0 0 1 0 0 1 0 0 0
53400- 0 0 0 0 0 0 0 0 0 0 0 0
53401- 0 0 0 0 0 0 0 0 0 0 0 0
53402- 0 0 0 0 0 0 0 0 0 0 0 0
53403- 0 0 0 0 0 0 0 0 0 0 0 0
53404- 0 0 0 0 0 0 0 0 0 14 14 14
53405- 42 42 42 82 82 82 2 2 6 2 2 6
53406- 2 2 6 6 6 6 10 10 10 2 2 6
53407- 2 2 6 2 2 6 2 2 6 2 2 6
53408- 2 2 6 2 2 6 2 2 6 6 6 6
53409- 14 14 14 10 10 10 2 2 6 2 2 6
53410- 2 2 6 2 2 6 2 2 6 18 18 18
53411- 82 82 82 34 34 34 10 10 10 0 0 0
53412- 0 0 0 0 0 0 0 0 0 0 0 0
53413- 0 0 0 0 0 0 0 0 0 0 0 0
53414- 0 0 0 0 0 0 0 0 0 0 0 0
53415- 0 0 0 0 0 0 0 0 0 0 0 0
53416- 0 0 0 0 0 0 0 0 0 0 0 0
53417- 0 0 0 0 0 0 0 0 0 0 0 0
53418- 0 0 0 0 0 0 0 0 0 0 0 0
53419- 0 0 1 0 0 0 0 0 0 0 0 0
53420- 0 0 0 0 0 0 0 0 0 0 0 0
53421- 0 0 0 0 0 0 0 0 0 0 0 0
53422- 0 0 0 0 0 0 0 0 0 0 0 0
53423- 0 0 0 0 0 0 0 0 0 0 0 0
53424- 0 0 0 0 0 0 0 0 0 14 14 14
53425- 46 46 46 86 86 86 2 2 6 2 2 6
53426- 6 6 6 6 6 6 22 22 22 34 34 34
53427- 6 6 6 2 2 6 2 2 6 2 2 6
53428- 2 2 6 2 2 6 18 18 18 34 34 34
53429- 10 10 10 50 50 50 22 22 22 2 2 6
53430- 2 2 6 2 2 6 2 2 6 10 10 10
53431- 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
53440- 0 0 0 0 0 0 0 0 0 0 0 0
53441- 0 0 0 0 0 0 0 0 0 0 0 0
53442- 0 0 0 0 0 0 0 0 0 0 0 0
53443- 0 0 0 0 0 0 0 0 0 0 0 0
53444- 0 0 0 0 0 0 0 0 0 14 14 14
53445- 46 46 46 86 86 86 2 2 6 2 2 6
53446- 38 38 38 116 116 116 94 94 94 22 22 22
53447- 22 22 22 2 2 6 2 2 6 2 2 6
53448- 14 14 14 86 86 86 138 138 138 162 162 162
53449-154 154 154 38 38 38 26 26 26 6 6 6
53450- 2 2 6 2 2 6 2 2 6 2 2 6
53451- 86 86 86 46 46 46 14 14 14 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 0 0 0 0
53455- 0 0 0 0 0 0 0 0 0 0 0 0
53456- 0 0 0 0 0 0 0 0 0 0 0 0
53457- 0 0 0 0 0 0 0 0 0 0 0 0
53458- 0 0 0 0 0 0 0 0 0 0 0 0
53459- 0 0 0 0 0 0 0 0 0 0 0 0
53460- 0 0 0 0 0 0 0 0 0 0 0 0
53461- 0 0 0 0 0 0 0 0 0 0 0 0
53462- 0 0 0 0 0 0 0 0 0 0 0 0
53463- 0 0 0 0 0 0 0 0 0 0 0 0
53464- 0 0 0 0 0 0 0 0 0 14 14 14
53465- 46 46 46 86 86 86 2 2 6 14 14 14
53466-134 134 134 198 198 198 195 195 195 116 116 116
53467- 10 10 10 2 2 6 2 2 6 6 6 6
53468-101 98 89 187 187 187 210 210 210 218 218 218
53469-214 214 214 134 134 134 14 14 14 6 6 6
53470- 2 2 6 2 2 6 2 2 6 2 2 6
53471- 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
53479- 0 0 1 0 0 1 0 0 1 0 0 0
53480- 0 0 0 0 0 0 0 0 0 0 0 0
53481- 0 0 0 0 0 0 0 0 0 0 0 0
53482- 0 0 0 0 0 0 0 0 0 0 0 0
53483- 0 0 0 0 0 0 0 0 0 0 0 0
53484- 0 0 0 0 0 0 0 0 0 14 14 14
53485- 46 46 46 86 86 86 2 2 6 54 54 54
53486-218 218 218 195 195 195 226 226 226 246 246 246
53487- 58 58 58 2 2 6 2 2 6 30 30 30
53488-210 210 210 253 253 253 174 174 174 123 123 123
53489-221 221 221 234 234 234 74 74 74 2 2 6
53490- 2 2 6 2 2 6 2 2 6 2 2 6
53491- 70 70 70 58 58 58 22 22 22 6 6 6
53492- 0 0 0 0 0 0 0 0 0 0 0 0
53493- 0 0 0 0 0 0 0 0 0 0 0 0
53494- 0 0 0 0 0 0 0 0 0 0 0 0
53495- 0 0 0 0 0 0 0 0 0 0 0 0
53496- 0 0 0 0 0 0 0 0 0 0 0 0
53497- 0 0 0 0 0 0 0 0 0 0 0 0
53498- 0 0 0 0 0 0 0 0 0 0 0 0
53499- 0 0 0 0 0 0 0 0 0 0 0 0
53500- 0 0 0 0 0 0 0 0 0 0 0 0
53501- 0 0 0 0 0 0 0 0 0 0 0 0
53502- 0 0 0 0 0 0 0 0 0 0 0 0
53503- 0 0 0 0 0 0 0 0 0 0 0 0
53504- 0 0 0 0 0 0 0 0 0 14 14 14
53505- 46 46 46 82 82 82 2 2 6 106 106 106
53506-170 170 170 26 26 26 86 86 86 226 226 226
53507-123 123 123 10 10 10 14 14 14 46 46 46
53508-231 231 231 190 190 190 6 6 6 70 70 70
53509- 90 90 90 238 238 238 158 158 158 2 2 6
53510- 2 2 6 2 2 6 2 2 6 2 2 6
53511- 70 70 70 58 58 58 22 22 22 6 6 6
53512- 0 0 0 0 0 0 0 0 0 0 0 0
53513- 0 0 0 0 0 0 0 0 0 0 0 0
53514- 0 0 0 0 0 0 0 0 0 0 0 0
53515- 0 0 0 0 0 0 0 0 0 0 0 0
53516- 0 0 0 0 0 0 0 0 0 0 0 0
53517- 0 0 0 0 0 0 0 0 0 0 0 0
53518- 0 0 0 0 0 0 0 0 1 0 0 0
53519- 0 0 1 0 0 1 0 0 1 0 0 0
53520- 0 0 0 0 0 0 0 0 0 0 0 0
53521- 0 0 0 0 0 0 0 0 0 0 0 0
53522- 0 0 0 0 0 0 0 0 0 0 0 0
53523- 0 0 0 0 0 0 0 0 0 0 0 0
53524- 0 0 0 0 0 0 0 0 0 14 14 14
53525- 42 42 42 86 86 86 6 6 6 116 116 116
53526-106 106 106 6 6 6 70 70 70 149 149 149
53527-128 128 128 18 18 18 38 38 38 54 54 54
53528-221 221 221 106 106 106 2 2 6 14 14 14
53529- 46 46 46 190 190 190 198 198 198 2 2 6
53530- 2 2 6 2 2 6 2 2 6 2 2 6
53531- 74 74 74 62 62 62 22 22 22 6 6 6
53532- 0 0 0 0 0 0 0 0 0 0 0 0
53533- 0 0 0 0 0 0 0 0 0 0 0 0
53534- 0 0 0 0 0 0 0 0 0 0 0 0
53535- 0 0 0 0 0 0 0 0 0 0 0 0
53536- 0 0 0 0 0 0 0 0 0 0 0 0
53537- 0 0 0 0 0 0 0 0 0 0 0 0
53538- 0 0 0 0 0 0 0 0 1 0 0 0
53539- 0 0 1 0 0 0 0 0 1 0 0 0
53540- 0 0 0 0 0 0 0 0 0 0 0 0
53541- 0 0 0 0 0 0 0 0 0 0 0 0
53542- 0 0 0 0 0 0 0 0 0 0 0 0
53543- 0 0 0 0 0 0 0 0 0 0 0 0
53544- 0 0 0 0 0 0 0 0 0 14 14 14
53545- 42 42 42 94 94 94 14 14 14 101 101 101
53546-128 128 128 2 2 6 18 18 18 116 116 116
53547-118 98 46 121 92 8 121 92 8 98 78 10
53548-162 162 162 106 106 106 2 2 6 2 2 6
53549- 2 2 6 195 195 195 195 195 195 6 6 6
53550- 2 2 6 2 2 6 2 2 6 2 2 6
53551- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
53559- 0 0 1 0 0 0 0 0 1 0 0 0
53560- 0 0 0 0 0 0 0 0 0 0 0 0
53561- 0 0 0 0 0 0 0 0 0 0 0 0
53562- 0 0 0 0 0 0 0 0 0 0 0 0
53563- 0 0 0 0 0 0 0 0 0 0 0 0
53564- 0 0 0 0 0 0 0 0 0 10 10 10
53565- 38 38 38 90 90 90 14 14 14 58 58 58
53566-210 210 210 26 26 26 54 38 6 154 114 10
53567-226 170 11 236 186 11 225 175 15 184 144 12
53568-215 174 15 175 146 61 37 26 9 2 2 6
53569- 70 70 70 246 246 246 138 138 138 2 2 6
53570- 2 2 6 2 2 6 2 2 6 2 2 6
53571- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
53581- 0 0 0 0 0 0 0 0 0 0 0 0
53582- 0 0 0 0 0 0 0 0 0 0 0 0
53583- 0 0 0 0 0 0 0 0 0 0 0 0
53584- 0 0 0 0 0 0 0 0 0 10 10 10
53585- 38 38 38 86 86 86 14 14 14 10 10 10
53586-195 195 195 188 164 115 192 133 9 225 175 15
53587-239 182 13 234 190 10 232 195 16 232 200 30
53588-245 207 45 241 208 19 232 195 16 184 144 12
53589-218 194 134 211 206 186 42 42 42 2 2 6
53590- 2 2 6 2 2 6 2 2 6 2 2 6
53591- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
53601- 0 0 0 0 0 0 0 0 0 0 0 0
53602- 0 0 0 0 0 0 0 0 0 0 0 0
53603- 0 0 0 0 0 0 0 0 0 0 0 0
53604- 0 0 0 0 0 0 0 0 0 10 10 10
53605- 34 34 34 86 86 86 14 14 14 2 2 6
53606-121 87 25 192 133 9 219 162 10 239 182 13
53607-236 186 11 232 195 16 241 208 19 244 214 54
53608-246 218 60 246 218 38 246 215 20 241 208 19
53609-241 208 19 226 184 13 121 87 25 2 2 6
53610- 2 2 6 2 2 6 2 2 6 2 2 6
53611- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
53621- 0 0 0 0 0 0 0 0 0 0 0 0
53622- 0 0 0 0 0 0 0 0 0 0 0 0
53623- 0 0 0 0 0 0 0 0 0 0 0 0
53624- 0 0 0 0 0 0 0 0 0 10 10 10
53625- 34 34 34 82 82 82 30 30 30 61 42 6
53626-180 123 7 206 145 10 230 174 11 239 182 13
53627-234 190 10 238 202 15 241 208 19 246 218 74
53628-246 218 38 246 215 20 246 215 20 246 215 20
53629-226 184 13 215 174 15 184 144 12 6 6 6
53630- 2 2 6 2 2 6 2 2 6 2 2 6
53631- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
53641- 0 0 0 0 0 0 0 0 0 0 0 0
53642- 0 0 0 0 0 0 0 0 0 0 0 0
53643- 0 0 0 0 0 0 0 0 0 0 0 0
53644- 0 0 0 0 0 0 0 0 0 10 10 10
53645- 30 30 30 78 78 78 50 50 50 104 69 6
53646-192 133 9 216 158 10 236 178 12 236 186 11
53647-232 195 16 241 208 19 244 214 54 245 215 43
53648-246 215 20 246 215 20 241 208 19 198 155 10
53649-200 144 11 216 158 10 156 118 10 2 2 6
53650- 2 2 6 2 2 6 2 2 6 2 2 6
53651- 6 6 6 90 90 90 54 54 54 18 18 18
53652- 6 6 6 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 0 0 0
53661- 0 0 0 0 0 0 0 0 0 0 0 0
53662- 0 0 0 0 0 0 0 0 0 0 0 0
53663- 0 0 0 0 0 0 0 0 0 0 0 0
53664- 0 0 0 0 0 0 0 0 0 10 10 10
53665- 30 30 30 78 78 78 46 46 46 22 22 22
53666-137 92 6 210 162 10 239 182 13 238 190 10
53667-238 202 15 241 208 19 246 215 20 246 215 20
53668-241 208 19 203 166 17 185 133 11 210 150 10
53669-216 158 10 210 150 10 102 78 10 2 2 6
53670- 6 6 6 54 54 54 14 14 14 2 2 6
53671- 2 2 6 62 62 62 74 74 74 30 30 30
53672- 10 10 10 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 0 0 0
53681- 0 0 0 0 0 0 0 0 0 0 0 0
53682- 0 0 0 0 0 0 0 0 0 0 0 0
53683- 0 0 0 0 0 0 0 0 0 0 0 0
53684- 0 0 0 0 0 0 0 0 0 10 10 10
53685- 34 34 34 78 78 78 50 50 50 6 6 6
53686- 94 70 30 139 102 15 190 146 13 226 184 13
53687-232 200 30 232 195 16 215 174 15 190 146 13
53688-168 122 10 192 133 9 210 150 10 213 154 11
53689-202 150 34 182 157 106 101 98 89 2 2 6
53690- 2 2 6 78 78 78 116 116 116 58 58 58
53691- 2 2 6 22 22 22 90 90 90 46 46 46
53692- 18 18 18 6 6 6 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 0 0 0 0 0 0
53701- 0 0 0 0 0 0 0 0 0 0 0 0
53702- 0 0 0 0 0 0 0 0 0 0 0 0
53703- 0 0 0 0 0 0 0 0 0 0 0 0
53704- 0 0 0 0 0 0 0 0 0 10 10 10
53705- 38 38 38 86 86 86 50 50 50 6 6 6
53706-128 128 128 174 154 114 156 107 11 168 122 10
53707-198 155 10 184 144 12 197 138 11 200 144 11
53708-206 145 10 206 145 10 197 138 11 188 164 115
53709-195 195 195 198 198 198 174 174 174 14 14 14
53710- 2 2 6 22 22 22 116 116 116 116 116 116
53711- 22 22 22 2 2 6 74 74 74 70 70 70
53712- 30 30 30 10 10 10 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 0 0 0 0 0 0
53721- 0 0 0 0 0 0 0 0 0 0 0 0
53722- 0 0 0 0 0 0 0 0 0 0 0 0
53723- 0 0 0 0 0 0 0 0 0 0 0 0
53724- 0 0 0 0 0 0 6 6 6 18 18 18
53725- 50 50 50 101 101 101 26 26 26 10 10 10
53726-138 138 138 190 190 190 174 154 114 156 107 11
53727-197 138 11 200 144 11 197 138 11 192 133 9
53728-180 123 7 190 142 34 190 178 144 187 187 187
53729-202 202 202 221 221 221 214 214 214 66 66 66
53730- 2 2 6 2 2 6 50 50 50 62 62 62
53731- 6 6 6 2 2 6 10 10 10 90 90 90
53732- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
53741- 0 0 0 0 0 0 0 0 0 0 0 0
53742- 0 0 0 0 0 0 0 0 0 0 0 0
53743- 0 0 0 0 0 0 0 0 0 0 0 0
53744- 0 0 0 0 0 0 10 10 10 34 34 34
53745- 74 74 74 74 74 74 2 2 6 6 6 6
53746-144 144 144 198 198 198 190 190 190 178 166 146
53747-154 121 60 156 107 11 156 107 11 168 124 44
53748-174 154 114 187 187 187 190 190 190 210 210 210
53749-246 246 246 253 253 253 253 253 253 182 182 182
53750- 6 6 6 2 2 6 2 2 6 2 2 6
53751- 2 2 6 2 2 6 2 2 6 62 62 62
53752- 74 74 74 34 34 34 14 14 14 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- 0 0 0 0 0 0 0 0 0 0 0 0
53761- 0 0 0 0 0 0 0 0 0 0 0 0
53762- 0 0 0 0 0 0 0 0 0 0 0 0
53763- 0 0 0 0 0 0 0 0 0 0 0 0
53764- 0 0 0 10 10 10 22 22 22 54 54 54
53765- 94 94 94 18 18 18 2 2 6 46 46 46
53766-234 234 234 221 221 221 190 190 190 190 190 190
53767-190 190 190 187 187 187 187 187 187 190 190 190
53768-190 190 190 195 195 195 214 214 214 242 242 242
53769-253 253 253 253 253 253 253 253 253 253 253 253
53770- 82 82 82 2 2 6 2 2 6 2 2 6
53771- 2 2 6 2 2 6 2 2 6 14 14 14
53772- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
53780- 0 0 0 0 0 0 0 0 0 0 0 0
53781- 0 0 0 0 0 0 0 0 0 0 0 0
53782- 0 0 0 0 0 0 0 0 0 0 0 0
53783- 0 0 0 0 0 0 0 0 0 0 0 0
53784- 6 6 6 18 18 18 46 46 46 90 90 90
53785- 46 46 46 18 18 18 6 6 6 182 182 182
53786-253 253 253 246 246 246 206 206 206 190 190 190
53787-190 190 190 190 190 190 190 190 190 190 190 190
53788-206 206 206 231 231 231 250 250 250 253 253 253
53789-253 253 253 253 253 253 253 253 253 253 253 253
53790-202 202 202 14 14 14 2 2 6 2 2 6
53791- 2 2 6 2 2 6 2 2 6 2 2 6
53792- 42 42 42 86 86 86 42 42 42 18 18 18
53793- 6 6 6 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 0 0 0
53800- 0 0 0 0 0 0 0 0 0 0 0 0
53801- 0 0 0 0 0 0 0 0 0 0 0 0
53802- 0 0 0 0 0 0 0 0 0 0 0 0
53803- 0 0 0 0 0 0 0 0 0 6 6 6
53804- 14 14 14 38 38 38 74 74 74 66 66 66
53805- 2 2 6 6 6 6 90 90 90 250 250 250
53806-253 253 253 253 253 253 238 238 238 198 198 198
53807-190 190 190 190 190 190 195 195 195 221 221 221
53808-246 246 246 253 253 253 253 253 253 253 253 253
53809-253 253 253 253 253 253 253 253 253 253 253 253
53810-253 253 253 82 82 82 2 2 6 2 2 6
53811- 2 2 6 2 2 6 2 2 6 2 2 6
53812- 2 2 6 78 78 78 70 70 70 34 34 34
53813- 14 14 14 6 6 6 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 0 0 0 0 0 0
53820- 0 0 0 0 0 0 0 0 0 0 0 0
53821- 0 0 0 0 0 0 0 0 0 0 0 0
53822- 0 0 0 0 0 0 0 0 0 0 0 0
53823- 0 0 0 0 0 0 0 0 0 14 14 14
53824- 34 34 34 66 66 66 78 78 78 6 6 6
53825- 2 2 6 18 18 18 218 218 218 253 253 253
53826-253 253 253 253 253 253 253 253 253 246 246 246
53827-226 226 226 231 231 231 246 246 246 253 253 253
53828-253 253 253 253 253 253 253 253 253 253 253 253
53829-253 253 253 253 253 253 253 253 253 253 253 253
53830-253 253 253 178 178 178 2 2 6 2 2 6
53831- 2 2 6 2 2 6 2 2 6 2 2 6
53832- 2 2 6 18 18 18 90 90 90 62 62 62
53833- 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
53840- 0 0 0 0 0 0 0 0 0 0 0 0
53841- 0 0 0 0 0 0 0 0 0 0 0 0
53842- 0 0 0 0 0 0 0 0 0 0 0 0
53843- 0 0 0 0 0 0 10 10 10 26 26 26
53844- 58 58 58 90 90 90 18 18 18 2 2 6
53845- 2 2 6 110 110 110 253 253 253 253 253 253
53846-253 253 253 253 253 253 253 253 253 253 253 253
53847-250 250 250 253 253 253 253 253 253 253 253 253
53848-253 253 253 253 253 253 253 253 253 253 253 253
53849-253 253 253 253 253 253 253 253 253 253 253 253
53850-253 253 253 231 231 231 18 18 18 2 2 6
53851- 2 2 6 2 2 6 2 2 6 2 2 6
53852- 2 2 6 2 2 6 18 18 18 94 94 94
53853- 54 54 54 26 26 26 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
53860- 0 0 0 0 0 0 0 0 0 0 0 0
53861- 0 0 0 0 0 0 0 0 0 0 0 0
53862- 0 0 0 0 0 0 0 0 0 0 0 0
53863- 0 0 0 6 6 6 22 22 22 50 50 50
53864- 90 90 90 26 26 26 2 2 6 2 2 6
53865- 14 14 14 195 195 195 250 250 250 253 253 253
53866-253 253 253 253 253 253 253 253 253 253 253 253
53867-253 253 253 253 253 253 253 253 253 253 253 253
53868-253 253 253 253 253 253 253 253 253 253 253 253
53869-253 253 253 253 253 253 253 253 253 253 253 253
53870-250 250 250 242 242 242 54 54 54 2 2 6
53871- 2 2 6 2 2 6 2 2 6 2 2 6
53872- 2 2 6 2 2 6 2 2 6 38 38 38
53873- 86 86 86 50 50 50 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
53880- 0 0 0 0 0 0 0 0 0 0 0 0
53881- 0 0 0 0 0 0 0 0 0 0 0 0
53882- 0 0 0 0 0 0 0 0 0 0 0 0
53883- 6 6 6 14 14 14 38 38 38 82 82 82
53884- 34 34 34 2 2 6 2 2 6 2 2 6
53885- 42 42 42 195 195 195 246 246 246 253 253 253
53886-253 253 253 253 253 253 253 253 253 250 250 250
53887-242 242 242 242 242 242 250 250 250 253 253 253
53888-253 253 253 253 253 253 253 253 253 253 253 253
53889-253 253 253 250 250 250 246 246 246 238 238 238
53890-226 226 226 231 231 231 101 101 101 6 6 6
53891- 2 2 6 2 2 6 2 2 6 2 2 6
53892- 2 2 6 2 2 6 2 2 6 2 2 6
53893- 38 38 38 82 82 82 42 42 42 14 14 14
53894- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
53900- 0 0 0 0 0 0 0 0 0 0 0 0
53901- 0 0 0 0 0 0 0 0 0 0 0 0
53902- 0 0 0 0 0 0 0 0 0 0 0 0
53903- 10 10 10 26 26 26 62 62 62 66 66 66
53904- 2 2 6 2 2 6 2 2 6 6 6 6
53905- 70 70 70 170 170 170 206 206 206 234 234 234
53906-246 246 246 250 250 250 250 250 250 238 238 238
53907-226 226 226 231 231 231 238 238 238 250 250 250
53908-250 250 250 250 250 250 246 246 246 231 231 231
53909-214 214 214 206 206 206 202 202 202 202 202 202
53910-198 198 198 202 202 202 182 182 182 18 18 18
53911- 2 2 6 2 2 6 2 2 6 2 2 6
53912- 2 2 6 2 2 6 2 2 6 2 2 6
53913- 2 2 6 62 62 62 66 66 66 30 30 30
53914- 10 10 10 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 0 0 0
53919- 0 0 0 0 0 0 0 0 0 0 0 0
53920- 0 0 0 0 0 0 0 0 0 0 0 0
53921- 0 0 0 0 0 0 0 0 0 0 0 0
53922- 0 0 0 0 0 0 0 0 0 0 0 0
53923- 14 14 14 42 42 42 82 82 82 18 18 18
53924- 2 2 6 2 2 6 2 2 6 10 10 10
53925- 94 94 94 182 182 182 218 218 218 242 242 242
53926-250 250 250 253 253 253 253 253 253 250 250 250
53927-234 234 234 253 253 253 253 253 253 253 253 253
53928-253 253 253 253 253 253 253 253 253 246 246 246
53929-238 238 238 226 226 226 210 210 210 202 202 202
53930-195 195 195 195 195 195 210 210 210 158 158 158
53931- 6 6 6 14 14 14 50 50 50 14 14 14
53932- 2 2 6 2 2 6 2 2 6 2 2 6
53933- 2 2 6 6 6 6 86 86 86 46 46 46
53934- 18 18 18 6 6 6 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 0 0 0
53939- 0 0 0 0 0 0 0 0 0 0 0 0
53940- 0 0 0 0 0 0 0 0 0 0 0 0
53941- 0 0 0 0 0 0 0 0 0 0 0 0
53942- 0 0 0 0 0 0 0 0 0 6 6 6
53943- 22 22 22 54 54 54 70 70 70 2 2 6
53944- 2 2 6 10 10 10 2 2 6 22 22 22
53945-166 166 166 231 231 231 250 250 250 253 253 253
53946-253 253 253 253 253 253 253 253 253 250 250 250
53947-242 242 242 253 253 253 253 253 253 253 253 253
53948-253 253 253 253 253 253 253 253 253 253 253 253
53949-253 253 253 253 253 253 253 253 253 246 246 246
53950-231 231 231 206 206 206 198 198 198 226 226 226
53951- 94 94 94 2 2 6 6 6 6 38 38 38
53952- 30 30 30 2 2 6 2 2 6 2 2 6
53953- 2 2 6 2 2 6 62 62 62 66 66 66
53954- 26 26 26 10 10 10 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 0 0 0
53959- 0 0 0 0 0 0 0 0 0 0 0 0
53960- 0 0 0 0 0 0 0 0 0 0 0 0
53961- 0 0 0 0 0 0 0 0 0 0 0 0
53962- 0 0 0 0 0 0 0 0 0 10 10 10
53963- 30 30 30 74 74 74 50 50 50 2 2 6
53964- 26 26 26 26 26 26 2 2 6 106 106 106
53965-238 238 238 253 253 253 253 253 253 253 253 253
53966-253 253 253 253 253 253 253 253 253 253 253 253
53967-253 253 253 253 253 253 253 253 253 253 253 253
53968-253 253 253 253 253 253 253 253 253 253 253 253
53969-253 253 253 253 253 253 253 253 253 253 253 253
53970-253 253 253 246 246 246 218 218 218 202 202 202
53971-210 210 210 14 14 14 2 2 6 2 2 6
53972- 30 30 30 22 22 22 2 2 6 2 2 6
53973- 2 2 6 2 2 6 18 18 18 86 86 86
53974- 42 42 42 14 14 14 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 0 0 0 0 0 0
53979- 0 0 0 0 0 0 0 0 0 0 0 0
53980- 0 0 0 0 0 0 0 0 0 0 0 0
53981- 0 0 0 0 0 0 0 0 0 0 0 0
53982- 0 0 0 0 0 0 0 0 0 14 14 14
53983- 42 42 42 90 90 90 22 22 22 2 2 6
53984- 42 42 42 2 2 6 18 18 18 218 218 218
53985-253 253 253 253 253 253 253 253 253 253 253 253
53986-253 253 253 253 253 253 253 253 253 253 253 253
53987-253 253 253 253 253 253 253 253 253 253 253 253
53988-253 253 253 253 253 253 253 253 253 253 253 253
53989-253 253 253 253 253 253 253 253 253 253 253 253
53990-253 253 253 253 253 253 250 250 250 221 221 221
53991-218 218 218 101 101 101 2 2 6 14 14 14
53992- 18 18 18 38 38 38 10 10 10 2 2 6
53993- 2 2 6 2 2 6 2 2 6 78 78 78
53994- 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0
53999- 0 0 0 0 0 0 0 0 0 0 0 0
54000- 0 0 0 0 0 0 0 0 0 0 0 0
54001- 0 0 0 0 0 0 0 0 0 0 0 0
54002- 0 0 0 0 0 0 6 6 6 18 18 18
54003- 54 54 54 82 82 82 2 2 6 26 26 26
54004- 22 22 22 2 2 6 123 123 123 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 253 253 253 253 253 253 253 253 253
54008-253 253 253 253 253 253 253 253 253 253 253 253
54009-253 253 253 253 253 253 253 253 253 253 253 253
54010-253 253 253 253 253 253 253 253 253 250 250 250
54011-238 238 238 198 198 198 6 6 6 38 38 38
54012- 58 58 58 26 26 26 38 38 38 2 2 6
54013- 2 2 6 2 2 6 2 2 6 46 46 46
54014- 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
54019- 0 0 0 0 0 0 0 0 0 0 0 0
54020- 0 0 0 0 0 0 0 0 0 0 0 0
54021- 0 0 0 0 0 0 0 0 0 0 0 0
54022- 0 0 0 0 0 0 10 10 10 30 30 30
54023- 74 74 74 58 58 58 2 2 6 42 42 42
54024- 2 2 6 22 22 22 231 231 231 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 250 250 250
54027-253 253 253 253 253 253 253 253 253 253 253 253
54028-253 253 253 253 253 253 253 253 253 253 253 253
54029-253 253 253 253 253 253 253 253 253 253 253 253
54030-253 253 253 253 253 253 253 253 253 253 253 253
54031-253 253 253 246 246 246 46 46 46 38 38 38
54032- 42 42 42 14 14 14 38 38 38 14 14 14
54033- 2 2 6 2 2 6 2 2 6 6 6 6
54034- 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0 0 0
54039- 0 0 0 0 0 0 0 0 0 0 0 0
54040- 0 0 0 0 0 0 0 0 0 0 0 0
54041- 0 0 0 0 0 0 0 0 0 0 0 0
54042- 0 0 0 6 6 6 14 14 14 42 42 42
54043- 90 90 90 18 18 18 18 18 18 26 26 26
54044- 2 2 6 116 116 116 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 250 250 250 238 238 238
54047-253 253 253 253 253 253 253 253 253 253 253 253
54048-253 253 253 253 253 253 253 253 253 253 253 253
54049-253 253 253 253 253 253 253 253 253 253 253 253
54050-253 253 253 253 253 253 253 253 253 253 253 253
54051-253 253 253 253 253 253 94 94 94 6 6 6
54052- 2 2 6 2 2 6 10 10 10 34 34 34
54053- 2 2 6 2 2 6 2 2 6 2 2 6
54054- 74 74 74 58 58 58 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
54059- 0 0 0 0 0 0 0 0 0 0 0 0
54060- 0 0 0 0 0 0 0 0 0 0 0 0
54061- 0 0 0 0 0 0 0 0 0 0 0 0
54062- 0 0 0 10 10 10 26 26 26 66 66 66
54063- 82 82 82 2 2 6 38 38 38 6 6 6
54064- 14 14 14 210 210 210 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 246 246 246 242 242 242
54067-253 253 253 253 253 253 253 253 253 253 253 253
54068-253 253 253 253 253 253 253 253 253 253 253 253
54069-253 253 253 253 253 253 253 253 253 253 253 253
54070-253 253 253 253 253 253 253 253 253 253 253 253
54071-253 253 253 253 253 253 144 144 144 2 2 6
54072- 2 2 6 2 2 6 2 2 6 46 46 46
54073- 2 2 6 2 2 6 2 2 6 2 2 6
54074- 42 42 42 74 74 74 30 30 30 10 10 10
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- 0 0 0 0 0 0 0 0 0 0 0 0
54079- 0 0 0 0 0 0 0 0 0 0 0 0
54080- 0 0 0 0 0 0 0 0 0 0 0 0
54081- 0 0 0 0 0 0 0 0 0 0 0 0
54082- 6 6 6 14 14 14 42 42 42 90 90 90
54083- 26 26 26 6 6 6 42 42 42 2 2 6
54084- 74 74 74 250 250 250 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 242 242 242 242 242 242
54087-253 253 253 253 253 253 253 253 253 253 253 253
54088-253 253 253 253 253 253 253 253 253 253 253 253
54089-253 253 253 253 253 253 253 253 253 253 253 253
54090-253 253 253 253 253 253 253 253 253 253 253 253
54091-253 253 253 253 253 253 182 182 182 2 2 6
54092- 2 2 6 2 2 6 2 2 6 46 46 46
54093- 2 2 6 2 2 6 2 2 6 2 2 6
54094- 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0
54098- 0 0 0 0 0 0 0 0 0 0 0 0
54099- 0 0 0 0 0 0 0 0 0 0 0 0
54100- 0 0 0 0 0 0 0 0 0 0 0 0
54101- 0 0 0 0 0 0 0 0 0 0 0 0
54102- 10 10 10 26 26 26 66 66 66 82 82 82
54103- 2 2 6 22 22 22 18 18 18 2 2 6
54104-149 149 149 253 253 253 253 253 253 253 253 253
54105-253 253 253 253 253 253 253 253 253 253 253 253
54106-253 253 253 253 253 253 234 234 234 242 242 242
54107-253 253 253 253 253 253 253 253 253 253 253 253
54108-253 253 253 253 253 253 253 253 253 253 253 253
54109-253 253 253 253 253 253 253 253 253 253 253 253
54110-253 253 253 253 253 253 253 253 253 253 253 253
54111-253 253 253 253 253 253 206 206 206 2 2 6
54112- 2 2 6 2 2 6 2 2 6 38 38 38
54113- 2 2 6 2 2 6 2 2 6 2 2 6
54114- 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0
54118- 0 0 0 0 0 0 0 0 0 0 0 0
54119- 0 0 0 0 0 0 0 0 0 0 0 0
54120- 0 0 0 0 0 0 0 0 0 0 0 0
54121- 0 0 0 0 0 0 0 0 0 6 6 6
54122- 18 18 18 46 46 46 86 86 86 18 18 18
54123- 2 2 6 34 34 34 10 10 10 6 6 6
54124-210 210 210 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 234 234 234 242 242 242
54127-253 253 253 253 253 253 253 253 253 253 253 253
54128-253 253 253 253 253 253 253 253 253 253 253 253
54129-253 253 253 253 253 253 253 253 253 253 253 253
54130-253 253 253 253 253 253 253 253 253 253 253 253
54131-253 253 253 253 253 253 221 221 221 6 6 6
54132- 2 2 6 2 2 6 6 6 6 30 30 30
54133- 2 2 6 2 2 6 2 2 6 2 2 6
54134- 2 2 6 82 82 82 54 54 54 18 18 18
54135- 6 6 6 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 0 0 0
54138- 0 0 0 0 0 0 0 0 0 0 0 0
54139- 0 0 0 0 0 0 0 0 0 0 0 0
54140- 0 0 0 0 0 0 0 0 0 0 0 0
54141- 0 0 0 0 0 0 0 0 0 10 10 10
54142- 26 26 26 66 66 66 62 62 62 2 2 6
54143- 2 2 6 38 38 38 10 10 10 26 26 26
54144-238 238 238 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 231 231 231 238 238 238
54147-253 253 253 253 253 253 253 253 253 253 253 253
54148-253 253 253 253 253 253 253 253 253 253 253 253
54149-253 253 253 253 253 253 253 253 253 253 253 253
54150-253 253 253 253 253 253 253 253 253 253 253 253
54151-253 253 253 253 253 253 231 231 231 6 6 6
54152- 2 2 6 2 2 6 10 10 10 30 30 30
54153- 2 2 6 2 2 6 2 2 6 2 2 6
54154- 2 2 6 66 66 66 58 58 58 22 22 22
54155- 6 6 6 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 0 0 0 0 0 0
54158- 0 0 0 0 0 0 0 0 0 0 0 0
54159- 0 0 0 0 0 0 0 0 0 0 0 0
54160- 0 0 0 0 0 0 0 0 0 0 0 0
54161- 0 0 0 0 0 0 0 0 0 10 10 10
54162- 38 38 38 78 78 78 6 6 6 2 2 6
54163- 2 2 6 46 46 46 14 14 14 42 42 42
54164-246 246 246 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 231 231 231 242 242 242
54167-253 253 253 253 253 253 253 253 253 253 253 253
54168-253 253 253 253 253 253 253 253 253 253 253 253
54169-253 253 253 253 253 253 253 253 253 253 253 253
54170-253 253 253 253 253 253 253 253 253 253 253 253
54171-253 253 253 253 253 253 234 234 234 10 10 10
54172- 2 2 6 2 2 6 22 22 22 14 14 14
54173- 2 2 6 2 2 6 2 2 6 2 2 6
54174- 2 2 6 66 66 66 62 62 62 22 22 22
54175- 6 6 6 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 0 0 0 0 0 0
54178- 0 0 0 0 0 0 0 0 0 0 0 0
54179- 0 0 0 0 0 0 0 0 0 0 0 0
54180- 0 0 0 0 0 0 0 0 0 0 0 0
54181- 0 0 0 0 0 0 6 6 6 18 18 18
54182- 50 50 50 74 74 74 2 2 6 2 2 6
54183- 14 14 14 70 70 70 34 34 34 62 62 62
54184-250 250 250 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 231 231 231 246 246 246
54187-253 253 253 253 253 253 253 253 253 253 253 253
54188-253 253 253 253 253 253 253 253 253 253 253 253
54189-253 253 253 253 253 253 253 253 253 253 253 253
54190-253 253 253 253 253 253 253 253 253 253 253 253
54191-253 253 253 253 253 253 234 234 234 14 14 14
54192- 2 2 6 2 2 6 30 30 30 2 2 6
54193- 2 2 6 2 2 6 2 2 6 2 2 6
54194- 2 2 6 66 66 66 62 62 62 22 22 22
54195- 6 6 6 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 0 0 0 0 0 0
54198- 0 0 0 0 0 0 0 0 0 0 0 0
54199- 0 0 0 0 0 0 0 0 0 0 0 0
54200- 0 0 0 0 0 0 0 0 0 0 0 0
54201- 0 0 0 0 0 0 6 6 6 18 18 18
54202- 54 54 54 62 62 62 2 2 6 2 2 6
54203- 2 2 6 30 30 30 46 46 46 70 70 70
54204-250 250 250 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 231 231 231 246 246 246
54207-253 253 253 253 253 253 253 253 253 253 253 253
54208-253 253 253 253 253 253 253 253 253 253 253 253
54209-253 253 253 253 253 253 253 253 253 253 253 253
54210-253 253 253 253 253 253 253 253 253 253 253 253
54211-253 253 253 253 253 253 226 226 226 10 10 10
54212- 2 2 6 6 6 6 30 30 30 2 2 6
54213- 2 2 6 2 2 6 2 2 6 2 2 6
54214- 2 2 6 66 66 66 58 58 58 22 22 22
54215- 6 6 6 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 0 0 0 0 0 0
54218- 0 0 0 0 0 0 0 0 0 0 0 0
54219- 0 0 0 0 0 0 0 0 0 0 0 0
54220- 0 0 0 0 0 0 0 0 0 0 0 0
54221- 0 0 0 0 0 0 6 6 6 22 22 22
54222- 58 58 58 62 62 62 2 2 6 2 2 6
54223- 2 2 6 2 2 6 30 30 30 78 78 78
54224-250 250 250 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 231 231 231 246 246 246
54227-253 253 253 253 253 253 253 253 253 253 253 253
54228-253 253 253 253 253 253 253 253 253 253 253 253
54229-253 253 253 253 253 253 253 253 253 253 253 253
54230-253 253 253 253 253 253 253 253 253 253 253 253
54231-253 253 253 253 253 253 206 206 206 2 2 6
54232- 22 22 22 34 34 34 18 14 6 22 22 22
54233- 26 26 26 18 18 18 6 6 6 2 2 6
54234- 2 2 6 82 82 82 54 54 54 18 18 18
54235- 6 6 6 0 0 0 0 0 0 0 0 0
54236- 0 0 0 0 0 0 0 0 0 0 0 0
54237- 0 0 0 0 0 0 0 0 0 0 0 0
54238- 0 0 0 0 0 0 0 0 0 0 0 0
54239- 0 0 0 0 0 0 0 0 0 0 0 0
54240- 0 0 0 0 0 0 0 0 0 0 0 0
54241- 0 0 0 0 0 0 6 6 6 26 26 26
54242- 62 62 62 106 106 106 74 54 14 185 133 11
54243-210 162 10 121 92 8 6 6 6 62 62 62
54244-238 238 238 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 231 231 231 246 246 246
54247-253 253 253 253 253 253 253 253 253 253 253 253
54248-253 253 253 253 253 253 253 253 253 253 253 253
54249-253 253 253 253 253 253 253 253 253 253 253 253
54250-253 253 253 253 253 253 253 253 253 253 253 253
54251-253 253 253 253 253 253 158 158 158 18 18 18
54252- 14 14 14 2 2 6 2 2 6 2 2 6
54253- 6 6 6 18 18 18 66 66 66 38 38 38
54254- 6 6 6 94 94 94 50 50 50 18 18 18
54255- 6 6 6 0 0 0 0 0 0 0 0 0
54256- 0 0 0 0 0 0 0 0 0 0 0 0
54257- 0 0 0 0 0 0 0 0 0 0 0 0
54258- 0 0 0 0 0 0 0 0 0 0 0 0
54259- 0 0 0 0 0 0 0 0 0 0 0 0
54260- 0 0 0 0 0 0 0 0 0 6 6 6
54261- 10 10 10 10 10 10 18 18 18 38 38 38
54262- 78 78 78 142 134 106 216 158 10 242 186 14
54263-246 190 14 246 190 14 156 118 10 10 10 10
54264- 90 90 90 238 238 238 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 231 231 231 250 250 250
54267-253 253 253 253 253 253 253 253 253 253 253 253
54268-253 253 253 253 253 253 253 253 253 253 253 253
54269-253 253 253 253 253 253 253 253 253 253 253 253
54270-253 253 253 253 253 253 253 253 253 246 230 190
54271-238 204 91 238 204 91 181 142 44 37 26 9
54272- 2 2 6 2 2 6 2 2 6 2 2 6
54273- 2 2 6 2 2 6 38 38 38 46 46 46
54274- 26 26 26 106 106 106 54 54 54 18 18 18
54275- 6 6 6 0 0 0 0 0 0 0 0 0
54276- 0 0 0 0 0 0 0 0 0 0 0 0
54277- 0 0 0 0 0 0 0 0 0 0 0 0
54278- 0 0 0 0 0 0 0 0 0 0 0 0
54279- 0 0 0 0 0 0 0 0 0 0 0 0
54280- 0 0 0 6 6 6 14 14 14 22 22 22
54281- 30 30 30 38 38 38 50 50 50 70 70 70
54282-106 106 106 190 142 34 226 170 11 242 186 14
54283-246 190 14 246 190 14 246 190 14 154 114 10
54284- 6 6 6 74 74 74 226 226 226 253 253 253
54285-253 253 253 253 253 253 253 253 253 253 253 253
54286-253 253 253 253 253 253 231 231 231 250 250 250
54287-253 253 253 253 253 253 253 253 253 253 253 253
54288-253 253 253 253 253 253 253 253 253 253 253 253
54289-253 253 253 253 253 253 253 253 253 253 253 253
54290-253 253 253 253 253 253 253 253 253 228 184 62
54291-241 196 14 241 208 19 232 195 16 38 30 10
54292- 2 2 6 2 2 6 2 2 6 2 2 6
54293- 2 2 6 6 6 6 30 30 30 26 26 26
54294-203 166 17 154 142 90 66 66 66 26 26 26
54295- 6 6 6 0 0 0 0 0 0 0 0 0
54296- 0 0 0 0 0 0 0 0 0 0 0 0
54297- 0 0 0 0 0 0 0 0 0 0 0 0
54298- 0 0 0 0 0 0 0 0 0 0 0 0
54299- 0 0 0 0 0 0 0 0 0 0 0 0
54300- 6 6 6 18 18 18 38 38 38 58 58 58
54301- 78 78 78 86 86 86 101 101 101 123 123 123
54302-175 146 61 210 150 10 234 174 13 246 186 14
54303-246 190 14 246 190 14 246 190 14 238 190 10
54304-102 78 10 2 2 6 46 46 46 198 198 198
54305-253 253 253 253 253 253 253 253 253 253 253 253
54306-253 253 253 253 253 253 234 234 234 242 242 242
54307-253 253 253 253 253 253 253 253 253 253 253 253
54308-253 253 253 253 253 253 253 253 253 253 253 253
54309-253 253 253 253 253 253 253 253 253 253 253 253
54310-253 253 253 253 253 253 253 253 253 224 178 62
54311-242 186 14 241 196 14 210 166 10 22 18 6
54312- 2 2 6 2 2 6 2 2 6 2 2 6
54313- 2 2 6 2 2 6 6 6 6 121 92 8
54314-238 202 15 232 195 16 82 82 82 34 34 34
54315- 10 10 10 0 0 0 0 0 0 0 0 0
54316- 0 0 0 0 0 0 0 0 0 0 0 0
54317- 0 0 0 0 0 0 0 0 0 0 0 0
54318- 0 0 0 0 0 0 0 0 0 0 0 0
54319- 0 0 0 0 0 0 0 0 0 0 0 0
54320- 14 14 14 38 38 38 70 70 70 154 122 46
54321-190 142 34 200 144 11 197 138 11 197 138 11
54322-213 154 11 226 170 11 242 186 14 246 190 14
54323-246 190 14 246 190 14 246 190 14 246 190 14
54324-225 175 15 46 32 6 2 2 6 22 22 22
54325-158 158 158 250 250 250 253 253 253 253 253 253
54326-253 253 253 253 253 253 253 253 253 253 253 253
54327-253 253 253 253 253 253 253 253 253 253 253 253
54328-253 253 253 253 253 253 253 253 253 253 253 253
54329-253 253 253 253 253 253 253 253 253 253 253 253
54330-253 253 253 250 250 250 242 242 242 224 178 62
54331-239 182 13 236 186 11 213 154 11 46 32 6
54332- 2 2 6 2 2 6 2 2 6 2 2 6
54333- 2 2 6 2 2 6 61 42 6 225 175 15
54334-238 190 10 236 186 11 112 100 78 42 42 42
54335- 14 14 14 0 0 0 0 0 0 0 0 0
54336- 0 0 0 0 0 0 0 0 0 0 0 0
54337- 0 0 0 0 0 0 0 0 0 0 0 0
54338- 0 0 0 0 0 0 0 0 0 0 0 0
54339- 0 0 0 0 0 0 0 0 0 6 6 6
54340- 22 22 22 54 54 54 154 122 46 213 154 11
54341-226 170 11 230 174 11 226 170 11 226 170 11
54342-236 178 12 242 186 14 246 190 14 246 190 14
54343-246 190 14 246 190 14 246 190 14 246 190 14
54344-241 196 14 184 144 12 10 10 10 2 2 6
54345- 6 6 6 116 116 116 242 242 242 253 253 253
54346-253 253 253 253 253 253 253 253 253 253 253 253
54347-253 253 253 253 253 253 253 253 253 253 253 253
54348-253 253 253 253 253 253 253 253 253 253 253 253
54349-253 253 253 253 253 253 253 253 253 253 253 253
54350-253 253 253 231 231 231 198 198 198 214 170 54
54351-236 178 12 236 178 12 210 150 10 137 92 6
54352- 18 14 6 2 2 6 2 2 6 2 2 6
54353- 6 6 6 70 47 6 200 144 11 236 178 12
54354-239 182 13 239 182 13 124 112 88 58 58 58
54355- 22 22 22 6 6 6 0 0 0 0 0 0
54356- 0 0 0 0 0 0 0 0 0 0 0 0
54357- 0 0 0 0 0 0 0 0 0 0 0 0
54358- 0 0 0 0 0 0 0 0 0 0 0 0
54359- 0 0 0 0 0 0 0 0 0 10 10 10
54360- 30 30 30 70 70 70 180 133 36 226 170 11
54361-239 182 13 242 186 14 242 186 14 246 186 14
54362-246 190 14 246 190 14 246 190 14 246 190 14
54363-246 190 14 246 190 14 246 190 14 246 190 14
54364-246 190 14 232 195 16 98 70 6 2 2 6
54365- 2 2 6 2 2 6 66 66 66 221 221 221
54366-253 253 253 253 253 253 253 253 253 253 253 253
54367-253 253 253 253 253 253 253 253 253 253 253 253
54368-253 253 253 253 253 253 253 253 253 253 253 253
54369-253 253 253 253 253 253 253 253 253 253 253 253
54370-253 253 253 206 206 206 198 198 198 214 166 58
54371-230 174 11 230 174 11 216 158 10 192 133 9
54372-163 110 8 116 81 8 102 78 10 116 81 8
54373-167 114 7 197 138 11 226 170 11 239 182 13
54374-242 186 14 242 186 14 162 146 94 78 78 78
54375- 34 34 34 14 14 14 6 6 6 0 0 0
54376- 0 0 0 0 0 0 0 0 0 0 0 0
54377- 0 0 0 0 0 0 0 0 0 0 0 0
54378- 0 0 0 0 0 0 0 0 0 0 0 0
54379- 0 0 0 0 0 0 0 0 0 6 6 6
54380- 30 30 30 78 78 78 190 142 34 226 170 11
54381-239 182 13 246 190 14 246 190 14 246 190 14
54382-246 190 14 246 190 14 246 190 14 246 190 14
54383-246 190 14 246 190 14 246 190 14 246 190 14
54384-246 190 14 241 196 14 203 166 17 22 18 6
54385- 2 2 6 2 2 6 2 2 6 38 38 38
54386-218 218 218 253 253 253 253 253 253 253 253 253
54387-253 253 253 253 253 253 253 253 253 253 253 253
54388-253 253 253 253 253 253 253 253 253 253 253 253
54389-253 253 253 253 253 253 253 253 253 253 253 253
54390-250 250 250 206 206 206 198 198 198 202 162 69
54391-226 170 11 236 178 12 224 166 10 210 150 10
54392-200 144 11 197 138 11 192 133 9 197 138 11
54393-210 150 10 226 170 11 242 186 14 246 190 14
54394-246 190 14 246 186 14 225 175 15 124 112 88
54395- 62 62 62 30 30 30 14 14 14 6 6 6
54396- 0 0 0 0 0 0 0 0 0 0 0 0
54397- 0 0 0 0 0 0 0 0 0 0 0 0
54398- 0 0 0 0 0 0 0 0 0 0 0 0
54399- 0 0 0 0 0 0 0 0 0 10 10 10
54400- 30 30 30 78 78 78 174 135 50 224 166 10
54401-239 182 13 246 190 14 246 190 14 246 190 14
54402-246 190 14 246 190 14 246 190 14 246 190 14
54403-246 190 14 246 190 14 246 190 14 246 190 14
54404-246 190 14 246 190 14 241 196 14 139 102 15
54405- 2 2 6 2 2 6 2 2 6 2 2 6
54406- 78 78 78 250 250 250 253 253 253 253 253 253
54407-253 253 253 253 253 253 253 253 253 253 253 253
54408-253 253 253 253 253 253 253 253 253 253 253 253
54409-253 253 253 253 253 253 253 253 253 253 253 253
54410-250 250 250 214 214 214 198 198 198 190 150 46
54411-219 162 10 236 178 12 234 174 13 224 166 10
54412-216 158 10 213 154 11 213 154 11 216 158 10
54413-226 170 11 239 182 13 246 190 14 246 190 14
54414-246 190 14 246 190 14 242 186 14 206 162 42
54415-101 101 101 58 58 58 30 30 30 14 14 14
54416- 6 6 6 0 0 0 0 0 0 0 0 0
54417- 0 0 0 0 0 0 0 0 0 0 0 0
54418- 0 0 0 0 0 0 0 0 0 0 0 0
54419- 0 0 0 0 0 0 0 0 0 10 10 10
54420- 30 30 30 74 74 74 174 135 50 216 158 10
54421-236 178 12 246 190 14 246 190 14 246 190 14
54422-246 190 14 246 190 14 246 190 14 246 190 14
54423-246 190 14 246 190 14 246 190 14 246 190 14
54424-246 190 14 246 190 14 241 196 14 226 184 13
54425- 61 42 6 2 2 6 2 2 6 2 2 6
54426- 22 22 22 238 238 238 253 253 253 253 253 253
54427-253 253 253 253 253 253 253 253 253 253 253 253
54428-253 253 253 253 253 253 253 253 253 253 253 253
54429-253 253 253 253 253 253 253 253 253 253 253 253
54430-253 253 253 226 226 226 187 187 187 180 133 36
54431-216 158 10 236 178 12 239 182 13 236 178 12
54432-230 174 11 226 170 11 226 170 11 230 174 11
54433-236 178 12 242 186 14 246 190 14 246 190 14
54434-246 190 14 246 190 14 246 186 14 239 182 13
54435-206 162 42 106 106 106 66 66 66 34 34 34
54436- 14 14 14 6 6 6 0 0 0 0 0 0
54437- 0 0 0 0 0 0 0 0 0 0 0 0
54438- 0 0 0 0 0 0 0 0 0 0 0 0
54439- 0 0 0 0 0 0 0 0 0 6 6 6
54440- 26 26 26 70 70 70 163 133 67 213 154 11
54441-236 178 12 246 190 14 246 190 14 246 190 14
54442-246 190 14 246 190 14 246 190 14 246 190 14
54443-246 190 14 246 190 14 246 190 14 246 190 14
54444-246 190 14 246 190 14 246 190 14 241 196 14
54445-190 146 13 18 14 6 2 2 6 2 2 6
54446- 46 46 46 246 246 246 253 253 253 253 253 253
54447-253 253 253 253 253 253 253 253 253 253 253 253
54448-253 253 253 253 253 253 253 253 253 253 253 253
54449-253 253 253 253 253 253 253 253 253 253 253 253
54450-253 253 253 221 221 221 86 86 86 156 107 11
54451-216 158 10 236 178 12 242 186 14 246 186 14
54452-242 186 14 239 182 13 239 182 13 242 186 14
54453-242 186 14 246 186 14 246 190 14 246 190 14
54454-246 190 14 246 190 14 246 190 14 246 190 14
54455-242 186 14 225 175 15 142 122 72 66 66 66
54456- 30 30 30 10 10 10 0 0 0 0 0 0
54457- 0 0 0 0 0 0 0 0 0 0 0 0
54458- 0 0 0 0 0 0 0 0 0 0 0 0
54459- 0 0 0 0 0 0 0 0 0 6 6 6
54460- 26 26 26 70 70 70 163 133 67 210 150 10
54461-236 178 12 246 190 14 246 190 14 246 190 14
54462-246 190 14 246 190 14 246 190 14 246 190 14
54463-246 190 14 246 190 14 246 190 14 246 190 14
54464-246 190 14 246 190 14 246 190 14 246 190 14
54465-232 195 16 121 92 8 34 34 34 106 106 106
54466-221 221 221 253 253 253 253 253 253 253 253 253
54467-253 253 253 253 253 253 253 253 253 253 253 253
54468-253 253 253 253 253 253 253 253 253 253 253 253
54469-253 253 253 253 253 253 253 253 253 253 253 253
54470-242 242 242 82 82 82 18 14 6 163 110 8
54471-216 158 10 236 178 12 242 186 14 246 190 14
54472-246 190 14 246 190 14 246 190 14 246 190 14
54473-246 190 14 246 190 14 246 190 14 246 190 14
54474-246 190 14 246 190 14 246 190 14 246 190 14
54475-246 190 14 246 190 14 242 186 14 163 133 67
54476- 46 46 46 18 18 18 6 6 6 0 0 0
54477- 0 0 0 0 0 0 0 0 0 0 0 0
54478- 0 0 0 0 0 0 0 0 0 0 0 0
54479- 0 0 0 0 0 0 0 0 0 10 10 10
54480- 30 30 30 78 78 78 163 133 67 210 150 10
54481-236 178 12 246 186 14 246 190 14 246 190 14
54482-246 190 14 246 190 14 246 190 14 246 190 14
54483-246 190 14 246 190 14 246 190 14 246 190 14
54484-246 190 14 246 190 14 246 190 14 246 190 14
54485-241 196 14 215 174 15 190 178 144 253 253 253
54486-253 253 253 253 253 253 253 253 253 253 253 253
54487-253 253 253 253 253 253 253 253 253 253 253 253
54488-253 253 253 253 253 253 253 253 253 253 253 253
54489-253 253 253 253 253 253 253 253 253 218 218 218
54490- 58 58 58 2 2 6 22 18 6 167 114 7
54491-216 158 10 236 178 12 246 186 14 246 190 14
54492-246 190 14 246 190 14 246 190 14 246 190 14
54493-246 190 14 246 190 14 246 190 14 246 190 14
54494-246 190 14 246 190 14 246 190 14 246 190 14
54495-246 190 14 246 186 14 242 186 14 190 150 46
54496- 54 54 54 22 22 22 6 6 6 0 0 0
54497- 0 0 0 0 0 0 0 0 0 0 0 0
54498- 0 0 0 0 0 0 0 0 0 0 0 0
54499- 0 0 0 0 0 0 0 0 0 14 14 14
54500- 38 38 38 86 86 86 180 133 36 213 154 11
54501-236 178 12 246 186 14 246 190 14 246 190 14
54502-246 190 14 246 190 14 246 190 14 246 190 14
54503-246 190 14 246 190 14 246 190 14 246 190 14
54504-246 190 14 246 190 14 246 190 14 246 190 14
54505-246 190 14 232 195 16 190 146 13 214 214 214
54506-253 253 253 253 253 253 253 253 253 253 253 253
54507-253 253 253 253 253 253 253 253 253 253 253 253
54508-253 253 253 253 253 253 253 253 253 253 253 253
54509-253 253 253 250 250 250 170 170 170 26 26 26
54510- 2 2 6 2 2 6 37 26 9 163 110 8
54511-219 162 10 239 182 13 246 186 14 246 190 14
54512-246 190 14 246 190 14 246 190 14 246 190 14
54513-246 190 14 246 190 14 246 190 14 246 190 14
54514-246 190 14 246 190 14 246 190 14 246 190 14
54515-246 186 14 236 178 12 224 166 10 142 122 72
54516- 46 46 46 18 18 18 6 6 6 0 0 0
54517- 0 0 0 0 0 0 0 0 0 0 0 0
54518- 0 0 0 0 0 0 0 0 0 0 0 0
54519- 0 0 0 0 0 0 6 6 6 18 18 18
54520- 50 50 50 109 106 95 192 133 9 224 166 10
54521-242 186 14 246 190 14 246 190 14 246 190 14
54522-246 190 14 246 190 14 246 190 14 246 190 14
54523-246 190 14 246 190 14 246 190 14 246 190 14
54524-246 190 14 246 190 14 246 190 14 246 190 14
54525-242 186 14 226 184 13 210 162 10 142 110 46
54526-226 226 226 253 253 253 253 253 253 253 253 253
54527-253 253 253 253 253 253 253 253 253 253 253 253
54528-253 253 253 253 253 253 253 253 253 253 253 253
54529-198 198 198 66 66 66 2 2 6 2 2 6
54530- 2 2 6 2 2 6 50 34 6 156 107 11
54531-219 162 10 239 182 13 246 186 14 246 190 14
54532-246 190 14 246 190 14 246 190 14 246 190 14
54533-246 190 14 246 190 14 246 190 14 246 190 14
54534-246 190 14 246 190 14 246 190 14 242 186 14
54535-234 174 13 213 154 11 154 122 46 66 66 66
54536- 30 30 30 10 10 10 0 0 0 0 0 0
54537- 0 0 0 0 0 0 0 0 0 0 0 0
54538- 0 0 0 0 0 0 0 0 0 0 0 0
54539- 0 0 0 0 0 0 6 6 6 22 22 22
54540- 58 58 58 154 121 60 206 145 10 234 174 13
54541-242 186 14 246 186 14 246 190 14 246 190 14
54542-246 190 14 246 190 14 246 190 14 246 190 14
54543-246 190 14 246 190 14 246 190 14 246 190 14
54544-246 190 14 246 190 14 246 190 14 246 190 14
54545-246 186 14 236 178 12 210 162 10 163 110 8
54546- 61 42 6 138 138 138 218 218 218 250 250 250
54547-253 253 253 253 253 253 253 253 253 250 250 250
54548-242 242 242 210 210 210 144 144 144 66 66 66
54549- 6 6 6 2 2 6 2 2 6 2 2 6
54550- 2 2 6 2 2 6 61 42 6 163 110 8
54551-216 158 10 236 178 12 246 190 14 246 190 14
54552-246 190 14 246 190 14 246 190 14 246 190 14
54553-246 190 14 246 190 14 246 190 14 246 190 14
54554-246 190 14 239 182 13 230 174 11 216 158 10
54555-190 142 34 124 112 88 70 70 70 38 38 38
54556- 18 18 18 6 6 6 0 0 0 0 0 0
54557- 0 0 0 0 0 0 0 0 0 0 0 0
54558- 0 0 0 0 0 0 0 0 0 0 0 0
54559- 0 0 0 0 0 0 6 6 6 22 22 22
54560- 62 62 62 168 124 44 206 145 10 224 166 10
54561-236 178 12 239 182 13 242 186 14 242 186 14
54562-246 186 14 246 190 14 246 190 14 246 190 14
54563-246 190 14 246 190 14 246 190 14 246 190 14
54564-246 190 14 246 190 14 246 190 14 246 190 14
54565-246 190 14 236 178 12 216 158 10 175 118 6
54566- 80 54 7 2 2 6 6 6 6 30 30 30
54567- 54 54 54 62 62 62 50 50 50 38 38 38
54568- 14 14 14 2 2 6 2 2 6 2 2 6
54569- 2 2 6 2 2 6 2 2 6 2 2 6
54570- 2 2 6 6 6 6 80 54 7 167 114 7
54571-213 154 11 236 178 12 246 190 14 246 190 14
54572-246 190 14 246 190 14 246 190 14 246 190 14
54573-246 190 14 242 186 14 239 182 13 239 182 13
54574-230 174 11 210 150 10 174 135 50 124 112 88
54575- 82 82 82 54 54 54 34 34 34 18 18 18
54576- 6 6 6 0 0 0 0 0 0 0 0 0
54577- 0 0 0 0 0 0 0 0 0 0 0 0
54578- 0 0 0 0 0 0 0 0 0 0 0 0
54579- 0 0 0 0 0 0 6 6 6 18 18 18
54580- 50 50 50 158 118 36 192 133 9 200 144 11
54581-216 158 10 219 162 10 224 166 10 226 170 11
54582-230 174 11 236 178 12 239 182 13 239 182 13
54583-242 186 14 246 186 14 246 190 14 246 190 14
54584-246 190 14 246 190 14 246 190 14 246 190 14
54585-246 186 14 230 174 11 210 150 10 163 110 8
54586-104 69 6 10 10 10 2 2 6 2 2 6
54587- 2 2 6 2 2 6 2 2 6 2 2 6
54588- 2 2 6 2 2 6 2 2 6 2 2 6
54589- 2 2 6 2 2 6 2 2 6 2 2 6
54590- 2 2 6 6 6 6 91 60 6 167 114 7
54591-206 145 10 230 174 11 242 186 14 246 190 14
54592-246 190 14 246 190 14 246 186 14 242 186 14
54593-239 182 13 230 174 11 224 166 10 213 154 11
54594-180 133 36 124 112 88 86 86 86 58 58 58
54595- 38 38 38 22 22 22 10 10 10 6 6 6
54596- 0 0 0 0 0 0 0 0 0 0 0 0
54597- 0 0 0 0 0 0 0 0 0 0 0 0
54598- 0 0 0 0 0 0 0 0 0 0 0 0
54599- 0 0 0 0 0 0 0 0 0 14 14 14
54600- 34 34 34 70 70 70 138 110 50 158 118 36
54601-167 114 7 180 123 7 192 133 9 197 138 11
54602-200 144 11 206 145 10 213 154 11 219 162 10
54603-224 166 10 230 174 11 239 182 13 242 186 14
54604-246 186 14 246 186 14 246 186 14 246 186 14
54605-239 182 13 216 158 10 185 133 11 152 99 6
54606-104 69 6 18 14 6 2 2 6 2 2 6
54607- 2 2 6 2 2 6 2 2 6 2 2 6
54608- 2 2 6 2 2 6 2 2 6 2 2 6
54609- 2 2 6 2 2 6 2 2 6 2 2 6
54610- 2 2 6 6 6 6 80 54 7 152 99 6
54611-192 133 9 219 162 10 236 178 12 239 182 13
54612-246 186 14 242 186 14 239 182 13 236 178 12
54613-224 166 10 206 145 10 192 133 9 154 121 60
54614- 94 94 94 62 62 62 42 42 42 22 22 22
54615- 14 14 14 6 6 6 0 0 0 0 0 0
54616- 0 0 0 0 0 0 0 0 0 0 0 0
54617- 0 0 0 0 0 0 0 0 0 0 0 0
54618- 0 0 0 0 0 0 0 0 0 0 0 0
54619- 0 0 0 0 0 0 0 0 0 6 6 6
54620- 18 18 18 34 34 34 58 58 58 78 78 78
54621-101 98 89 124 112 88 142 110 46 156 107 11
54622-163 110 8 167 114 7 175 118 6 180 123 7
54623-185 133 11 197 138 11 210 150 10 219 162 10
54624-226 170 11 236 178 12 236 178 12 234 174 13
54625-219 162 10 197 138 11 163 110 8 130 83 6
54626- 91 60 6 10 10 10 2 2 6 2 2 6
54627- 18 18 18 38 38 38 38 38 38 38 38 38
54628- 38 38 38 38 38 38 38 38 38 38 38 38
54629- 38 38 38 38 38 38 26 26 26 2 2 6
54630- 2 2 6 6 6 6 70 47 6 137 92 6
54631-175 118 6 200 144 11 219 162 10 230 174 11
54632-234 174 13 230 174 11 219 162 10 210 150 10
54633-192 133 9 163 110 8 124 112 88 82 82 82
54634- 50 50 50 30 30 30 14 14 14 6 6 6
54635- 0 0 0 0 0 0 0 0 0 0 0 0
54636- 0 0 0 0 0 0 0 0 0 0 0 0
54637- 0 0 0 0 0 0 0 0 0 0 0 0
54638- 0 0 0 0 0 0 0 0 0 0 0 0
54639- 0 0 0 0 0 0 0 0 0 0 0 0
54640- 6 6 6 14 14 14 22 22 22 34 34 34
54641- 42 42 42 58 58 58 74 74 74 86 86 86
54642-101 98 89 122 102 70 130 98 46 121 87 25
54643-137 92 6 152 99 6 163 110 8 180 123 7
54644-185 133 11 197 138 11 206 145 10 200 144 11
54645-180 123 7 156 107 11 130 83 6 104 69 6
54646- 50 34 6 54 54 54 110 110 110 101 98 89
54647- 86 86 86 82 82 82 78 78 78 78 78 78
54648- 78 78 78 78 78 78 78 78 78 78 78 78
54649- 78 78 78 82 82 82 86 86 86 94 94 94
54650-106 106 106 101 101 101 86 66 34 124 80 6
54651-156 107 11 180 123 7 192 133 9 200 144 11
54652-206 145 10 200 144 11 192 133 9 175 118 6
54653-139 102 15 109 106 95 70 70 70 42 42 42
54654- 22 22 22 10 10 10 0 0 0 0 0 0
54655- 0 0 0 0 0 0 0 0 0 0 0 0
54656- 0 0 0 0 0 0 0 0 0 0 0 0
54657- 0 0 0 0 0 0 0 0 0 0 0 0
54658- 0 0 0 0 0 0 0 0 0 0 0 0
54659- 0 0 0 0 0 0 0 0 0 0 0 0
54660- 0 0 0 0 0 0 6 6 6 10 10 10
54661- 14 14 14 22 22 22 30 30 30 38 38 38
54662- 50 50 50 62 62 62 74 74 74 90 90 90
54663-101 98 89 112 100 78 121 87 25 124 80 6
54664-137 92 6 152 99 6 152 99 6 152 99 6
54665-138 86 6 124 80 6 98 70 6 86 66 30
54666-101 98 89 82 82 82 58 58 58 46 46 46
54667- 38 38 38 34 34 34 34 34 34 34 34 34
54668- 34 34 34 34 34 34 34 34 34 34 34 34
54669- 34 34 34 34 34 34 38 38 38 42 42 42
54670- 54 54 54 82 82 82 94 86 76 91 60 6
54671-134 86 6 156 107 11 167 114 7 175 118 6
54672-175 118 6 167 114 7 152 99 6 121 87 25
54673-101 98 89 62 62 62 34 34 34 18 18 18
54674- 6 6 6 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 0 0 0 0 0 0 0 0 0
54679- 0 0 0 0 0 0 0 0 0 0 0 0
54680- 0 0 0 0 0 0 0 0 0 0 0 0
54681- 0 0 0 6 6 6 6 6 6 10 10 10
54682- 18 18 18 22 22 22 30 30 30 42 42 42
54683- 50 50 50 66 66 66 86 86 86 101 98 89
54684-106 86 58 98 70 6 104 69 6 104 69 6
54685-104 69 6 91 60 6 82 62 34 90 90 90
54686- 62 62 62 38 38 38 22 22 22 14 14 14
54687- 10 10 10 10 10 10 10 10 10 10 10 10
54688- 10 10 10 10 10 10 6 6 6 10 10 10
54689- 10 10 10 10 10 10 10 10 10 14 14 14
54690- 22 22 22 42 42 42 70 70 70 89 81 66
54691- 80 54 7 104 69 6 124 80 6 137 92 6
54692-134 86 6 116 81 8 100 82 52 86 86 86
54693- 58 58 58 30 30 30 14 14 14 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
54700- 0 0 0 0 0 0 0 0 0 0 0 0
54701- 0 0 0 0 0 0 0 0 0 0 0 0
54702- 0 0 0 6 6 6 10 10 10 14 14 14
54703- 18 18 18 26 26 26 38 38 38 54 54 54
54704- 70 70 70 86 86 86 94 86 76 89 81 66
54705- 89 81 66 86 86 86 74 74 74 50 50 50
54706- 30 30 30 14 14 14 6 6 6 0 0 0
54707- 0 0 0 0 0 0 0 0 0 0 0 0
54708- 0 0 0 0 0 0 0 0 0 0 0 0
54709- 0 0 0 0 0 0 0 0 0 0 0 0
54710- 6 6 6 18 18 18 34 34 34 58 58 58
54711- 82 82 82 89 81 66 89 81 66 89 81 66
54712- 94 86 66 94 86 76 74 74 74 50 50 50
54713- 26 26 26 14 14 14 6 6 6 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 0 0 0
54720- 0 0 0 0 0 0 0 0 0 0 0 0
54721- 0 0 0 0 0 0 0 0 0 0 0 0
54722- 0 0 0 0 0 0 0 0 0 0 0 0
54723- 6 6 6 6 6 6 14 14 14 18 18 18
54724- 30 30 30 38 38 38 46 46 46 54 54 54
54725- 50 50 50 42 42 42 30 30 30 18 18 18
54726- 10 10 10 0 0 0 0 0 0 0 0 0
54727- 0 0 0 0 0 0 0 0 0 0 0 0
54728- 0 0 0 0 0 0 0 0 0 0 0 0
54729- 0 0 0 0 0 0 0 0 0 0 0 0
54730- 0 0 0 6 6 6 14 14 14 26 26 26
54731- 38 38 38 50 50 50 58 58 58 58 58 58
54732- 54 54 54 42 42 42 30 30 30 18 18 18
54733- 10 10 10 0 0 0 0 0 0 0 0 0
54734- 0 0 0 0 0 0 0 0 0 0 0 0
54735- 0 0 0 0 0 0 0 0 0 0 0 0
54736- 0 0 0 0 0 0 0 0 0 0 0 0
54737- 0 0 0 0 0 0 0 0 0 0 0 0
54738- 0 0 0 0 0 0 0 0 0 0 0 0
54739- 0 0 0 0 0 0 0 0 0 0 0 0
54740- 0 0 0 0 0 0 0 0 0 0 0 0
54741- 0 0 0 0 0 0 0 0 0 0 0 0
54742- 0 0 0 0 0 0 0 0 0 0 0 0
54743- 0 0 0 0 0 0 0 0 0 6 6 6
54744- 6 6 6 10 10 10 14 14 14 18 18 18
54745- 18 18 18 14 14 14 10 10 10 6 6 6
54746- 0 0 0 0 0 0 0 0 0 0 0 0
54747- 0 0 0 0 0 0 0 0 0 0 0 0
54748- 0 0 0 0 0 0 0 0 0 0 0 0
54749- 0 0 0 0 0 0 0 0 0 0 0 0
54750- 0 0 0 0 0 0 0 0 0 6 6 6
54751- 14 14 14 18 18 18 22 22 22 22 22 22
54752- 18 18 18 14 14 14 10 10 10 6 6 6
54753- 0 0 0 0 0 0 0 0 0 0 0 0
54754- 0 0 0 0 0 0 0 0 0 0 0 0
54755- 0 0 0 0 0 0 0 0 0 0 0 0
54756- 0 0 0 0 0 0 0 0 0 0 0 0
54757- 0 0 0 0 0 0 0 0 0 0 0 0
54758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54761+4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
54823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
54828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54838+4 4 4 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
54842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54846+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54847+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54851+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 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 2 1 0 2 1 0 3 2 2
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
54856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54860+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54861+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54862+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54865+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54866+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54867+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54868+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54869+4 4 4 4 4 4
54870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54874+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54875+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54876+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54879+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54880+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54881+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54882+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54883+4 4 4 4 4 4
54884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54887+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54888+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54889+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54890+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54892+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54893+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54894+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54895+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54896+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54897+4 4 4 4 4 4
54898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54901+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54902+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54903+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54904+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54905+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54906+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54907+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54908+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54909+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54910+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54911+4 4 4 4 4 4
54912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54915+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54916+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54917+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54918+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54919+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54920+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54921+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54922+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54923+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54924+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54925+4 4 4 4 4 4
54926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54928+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54929+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54930+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54931+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54932+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54933+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54934+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54935+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54936+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54937+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54938+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54939+4 4 4 4 4 4
54940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54942+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54943+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54944+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54945+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54946+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54947+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54948+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54949+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54950+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54951+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54952+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54953+4 4 4 4 4 4
54954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54956+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54957+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54958+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54959+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54960+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54961+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54962+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54963+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54964+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54965+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54966+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54967+4 4 4 4 4 4
54968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54970+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54971+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54972+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54973+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54974+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54975+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54976+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54977+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54978+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54979+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54980+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54981+4 4 4 4 4 4
54982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54983+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54984+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54985+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54986+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54987+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54988+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54989+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54990+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54991+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54992+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54993+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54994+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54995+4 4 4 4 4 4
54996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54997+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54998+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54999+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
55000+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55001+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
55002+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
55003+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
55004+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
55005+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
55006+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
55007+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
55008+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
55009+0 0 0 4 4 4
55010+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55011+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
55012+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
55013+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
55014+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
55015+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
55016+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
55017+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
55018+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
55019+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
55020+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
55021+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
55022+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
55023+2 0 0 0 0 0
55024+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
55025+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
55026+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
55027+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
55028+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
55029+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
55030+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
55031+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
55032+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
55033+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
55034+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
55035+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
55036+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
55037+37 38 37 0 0 0
55038+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55039+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
55040+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
55041+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
55042+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
55043+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
55044+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55045+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55046+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55047+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55048+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55049+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55050+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55051+85 115 134 4 0 0
55052+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55053+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55054+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55055+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55056+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55057+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55058+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55059+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55060+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55061+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55062+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55063+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55064+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55065+60 73 81 4 0 0
55066+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55067+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55068+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55069+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55070+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55071+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55072+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55073+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55074+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55075+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55076+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55077+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55078+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55079+16 19 21 4 0 0
55080+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55081+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55082+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55083+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55084+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55085+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55086+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55087+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55088+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55089+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55090+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55091+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55092+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55093+4 0 0 4 3 3
55094+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55095+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55096+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55098+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55099+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55100+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55101+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55102+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55103+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55104+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55105+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55106+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55107+3 2 2 4 4 4
55108+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55109+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55110+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55111+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55112+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55113+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55114+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55115+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55116+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55117+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55118+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55119+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55120+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55121+4 4 4 4 4 4
55122+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55123+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55124+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55125+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55126+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55127+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55128+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55129+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55130+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55131+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55132+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55133+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55134+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55135+4 4 4 4 4 4
55136+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55137+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55138+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55139+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55140+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55141+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55142+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55143+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55144+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55145+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55146+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55147+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55148+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55149+5 5 5 5 5 5
55150+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55151+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55152+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55153+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55154+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55155+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55156+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55157+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55158+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55159+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55160+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55161+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55162+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55163+5 5 5 4 4 4
55164+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55165+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55166+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55167+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55168+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55169+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55170+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55171+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55172+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55173+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55174+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55175+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55177+4 4 4 4 4 4
55178+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55179+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55180+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55181+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55182+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55183+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55184+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55185+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55186+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55187+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55188+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55189+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55191+4 4 4 4 4 4
55192+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55193+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55194+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55195+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55196+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55197+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55198+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55199+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55200+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55201+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55202+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55205+4 4 4 4 4 4
55206+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55207+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55208+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55209+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55210+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55211+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55212+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55213+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55214+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55215+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55216+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55219+4 4 4 4 4 4
55220+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55221+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55222+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55223+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55224+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55225+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55226+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55227+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55228+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55229+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55230+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55233+4 4 4 4 4 4
55234+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55235+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55236+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55237+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55238+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55239+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55240+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55241+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55242+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55243+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55244+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55247+4 4 4 4 4 4
55248+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55249+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55250+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55251+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55252+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55253+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55254+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55255+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55256+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55257+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55258+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55261+4 4 4 4 4 4
55262+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55263+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55264+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55265+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55266+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55267+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55268+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55269+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55270+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55271+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55272+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55275+4 4 4 4 4 4
55276+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55277+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55278+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55279+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55280+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55281+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55282+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55283+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55284+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55285+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55286+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55289+4 4 4 4 4 4
55290+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55291+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55292+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55293+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55294+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55295+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55296+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55297+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55298+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55299+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55300+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55303+4 4 4 4 4 4
55304+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55305+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55306+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55307+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55308+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55309+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55310+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55311+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55312+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55313+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55314+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55317+4 4 4 4 4 4
55318+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55319+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55320+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55321+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55322+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55323+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55324+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55325+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55326+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55327+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55328+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55331+4 4 4 4 4 4
55332+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55333+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55334+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55335+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55336+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55337+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55338+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55339+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55340+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55341+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55342+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55345+4 4 4 4 4 4
55346+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55347+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55348+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55349+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55350+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55351+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55352+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55353+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55354+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55355+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55356+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55359+4 4 4 4 4 4
55360+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55361+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55362+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55363+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55364+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55365+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55366+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55367+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55368+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55369+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55370+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55373+4 4 4 4 4 4
55374+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55375+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55376+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55377+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55378+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55379+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55380+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55381+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55382+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55383+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55384+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55387+4 4 4 4 4 4
55388+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55389+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55390+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55391+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55392+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55393+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55394+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55395+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55396+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55397+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55398+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55401+4 4 4 4 4 4
55402+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55403+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55404+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55405+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55406+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55407+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55408+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55409+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55410+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55411+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55412+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55415+4 4 4 4 4 4
55416+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55417+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55418+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55419+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55420+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55421+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55422+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55423+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55424+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55425+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55426+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55429+4 4 4 4 4 4
55430+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55431+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55432+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55433+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55434+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55435+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55436+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55437+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55438+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55439+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55440+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55443+4 4 4 4 4 4
55444+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55445+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55446+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55447+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55448+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55449+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55450+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55451+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55452+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55453+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55454+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55457+4 4 4 4 4 4
55458+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55459+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55460+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55461+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55462+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55463+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55464+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55465+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55466+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55467+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55468+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55471+4 4 4 4 4 4
55472+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55473+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55474+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55475+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55476+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55477+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55478+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55479+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55480+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55481+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55482+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55485+4 4 4 4 4 4
55486+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55487+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55488+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55489+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55490+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55491+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55492+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55493+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55494+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55495+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55496+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55499+4 4 4 4 4 4
55500+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55501+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55502+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55503+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55504+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55505+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55506+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55507+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55508+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55509+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55510+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55513+4 4 4 4 4 4
55514+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55515+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55516+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55517+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55518+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55519+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55520+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55521+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55522+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55523+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55524+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55527+4 4 4 4 4 4
55528+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55529+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55530+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55531+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55532+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55533+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55534+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55535+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55536+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55537+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55538+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55541+4 4 4 4 4 4
55542+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55543+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55544+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55545+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55546+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55547+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55548+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55549+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55550+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55551+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55552+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55555+4 4 4 4 4 4
55556+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55557+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55558+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55559+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55560+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55561+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55562+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55563+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55564+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55565+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55566+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55569+4 4 4 4 4 4
55570+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55571+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55572+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55573+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55574+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55575+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55576+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55577+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55578+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55579+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55583+4 4 4 4 4 4
55584+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55585+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55586+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55587+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55588+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55589+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55590+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55591+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55592+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55593+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55597+4 4 4 4 4 4
55598+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55599+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55600+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55601+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55602+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55603+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55604+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55605+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55606+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55607+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55611+4 4 4 4 4 4
55612+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55613+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55614+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55615+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55616+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55617+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55618+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55619+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55620+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55621+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55625+4 4 4 4 4 4
55626+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55627+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55628+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55629+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55630+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55631+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55632+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55633+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55634+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55639+4 4 4 4 4 4
55640+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55641+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55642+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55643+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55644+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55645+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55646+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55647+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55648+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55653+4 4 4 4 4 4
55654+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55655+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55656+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55657+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55658+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55659+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55660+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55661+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55662+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55667+4 4 4 4 4 4
55668+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55669+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55670+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55671+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55672+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55673+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55674+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55675+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55681+4 4 4 4 4 4
55682+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55683+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55684+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55685+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55686+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55687+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55688+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55689+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55695+4 4 4 4 4 4
55696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55697+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55698+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55699+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55700+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55701+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55702+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55703+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55709+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55712+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55713+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55714+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55715+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55716+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55717+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55723+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 5 5 5 5 5 5 5 5 5
55726+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55727+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55728+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55729+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55730+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55731+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55737+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55741+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55742+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55743+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55744+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55745+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55751+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 5 5 5
55755+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55756+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55757+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55758+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55765+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55770+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55771+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55772+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55779+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 5 5 5 4 3 3 5 5 5 6 6 6
55784+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55785+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55786+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55793+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 4 4 4 5 5 5 4 3 3 5 5 5
55798+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55799+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55800+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55804+4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 5 5 5
55812+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55813+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55814+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55818+4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
55826+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55827+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55828+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4
55831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 4 4 4 4 4 4
55840+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55841+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55842+5 5 5 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 4 4 4 4 4 4
55845+4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
55854+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55855+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55863+4 4 4 4 4 4
55864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55868+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55869+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55877+4 4 4 4 4 4
55878diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55879index fef20db..d28b1ab 100644
55880--- a/drivers/xen/xenfs/xenstored.c
55881+++ b/drivers/xen/xenfs/xenstored.c
55882@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55883 static int xsd_kva_open(struct inode *inode, struct file *file)
55884 {
55885 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55886+#ifdef CONFIG_GRKERNSEC_HIDESYM
55887+ NULL);
55888+#else
55889 xen_store_interface);
55890+#endif
55891+
55892 if (!file->private_data)
55893 return -ENOMEM;
55894 return 0;
55895diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55896index c71e886..61d3d44b 100644
55897--- a/fs/9p/vfs_addr.c
55898+++ b/fs/9p/vfs_addr.c
55899@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55900
55901 retval = v9fs_file_write_internal(inode,
55902 v9inode->writeback_fid,
55903- (__force const char __user *)buffer,
55904+ (const char __force_user *)buffer,
55905 len, &offset, 0);
55906 if (retval > 0)
55907 retval = 0;
55908diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55909index 53161ec..e261d8a 100644
55910--- a/fs/9p/vfs_inode.c
55911+++ b/fs/9p/vfs_inode.c
55912@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55913 void
55914 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55915 {
55916- char *s = nd_get_link(nd);
55917+ const char *s = nd_get_link(nd);
55918
55919 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55920 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55921diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55922index 370b24c..ff0be7b 100644
55923--- a/fs/Kconfig.binfmt
55924+++ b/fs/Kconfig.binfmt
55925@@ -103,7 +103,7 @@ config HAVE_AOUT
55926
55927 config BINFMT_AOUT
55928 tristate "Kernel support for a.out and ECOFF binaries"
55929- depends on HAVE_AOUT
55930+ depends on HAVE_AOUT && BROKEN
55931 ---help---
55932 A.out (Assembler.OUTput) is a set of formats for libraries and
55933 executables used in the earliest versions of UNIX. Linux used
55934diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55935index 2946712..f737435 100644
55936--- a/fs/afs/inode.c
55937+++ b/fs/afs/inode.c
55938@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55939 struct afs_vnode *vnode;
55940 struct super_block *sb;
55941 struct inode *inode;
55942- static atomic_t afs_autocell_ino;
55943+ static atomic_unchecked_t afs_autocell_ino;
55944
55945 _enter("{%x:%u},%*.*s,",
55946 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55947@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55948 data.fid.unique = 0;
55949 data.fid.vnode = 0;
55950
55951- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55952+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55953 afs_iget5_autocell_test, afs_iget5_set,
55954 &data);
55955 if (!inode) {
55956diff --git a/fs/aio.c b/fs/aio.c
55957index e609e15..c9fcd97 100644
55958--- a/fs/aio.c
55959+++ b/fs/aio.c
55960@@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55961 size += sizeof(struct io_event) * nr_events;
55962
55963 nr_pages = PFN_UP(size);
55964- if (nr_pages < 0)
55965+ if (nr_pages <= 0)
55966 return -EINVAL;
55967
55968 file = aio_private_file(ctx, nr_pages);
55969diff --git a/fs/attr.c b/fs/attr.c
55970index 6530ced..4a827e2 100644
55971--- a/fs/attr.c
55972+++ b/fs/attr.c
55973@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55974 unsigned long limit;
55975
55976 limit = rlimit(RLIMIT_FSIZE);
55977+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55978 if (limit != RLIM_INFINITY && offset > limit)
55979 goto out_sig;
55980 if (offset > inode->i_sb->s_maxbytes)
55981diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55982index 116fd38..c04182da 100644
55983--- a/fs/autofs4/waitq.c
55984+++ b/fs/autofs4/waitq.c
55985@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55986 {
55987 unsigned long sigpipe, flags;
55988 mm_segment_t fs;
55989- const char *data = (const char *)addr;
55990+ const char __user *data = (const char __force_user *)addr;
55991 ssize_t wr = 0;
55992
55993 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55994@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55995 return 1;
55996 }
55997
55998+#ifdef CONFIG_GRKERNSEC_HIDESYM
55999+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56000+#endif
56001+
56002 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56003 enum autofs_notify notify)
56004 {
56005@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56006
56007 /* If this is a direct mount request create a dummy name */
56008 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56009+#ifdef CONFIG_GRKERNSEC_HIDESYM
56010+ /* this name does get written to userland via autofs4_write() */
56011+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56012+#else
56013 qstr.len = sprintf(name, "%p", dentry);
56014+#endif
56015 else {
56016 qstr.len = autofs4_getpath(sbi, dentry, &name);
56017 if (!qstr.len) {
56018diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56019index 2722387..56059b5 100644
56020--- a/fs/befs/endian.h
56021+++ b/fs/befs/endian.h
56022@@ -11,7 +11,7 @@
56023
56024 #include <asm/byteorder.h>
56025
56026-static inline u64
56027+static inline u64 __intentional_overflow(-1)
56028 fs64_to_cpu(const struct super_block *sb, fs64 n)
56029 {
56030 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56031@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56032 return (__force fs64)cpu_to_be64(n);
56033 }
56034
56035-static inline u32
56036+static inline u32 __intentional_overflow(-1)
56037 fs32_to_cpu(const struct super_block *sb, fs32 n)
56038 {
56039 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56040@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56041 return (__force fs32)cpu_to_be32(n);
56042 }
56043
56044-static inline u16
56045+static inline u16 __intentional_overflow(-1)
56046 fs16_to_cpu(const struct super_block *sb, fs16 n)
56047 {
56048 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56049diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56050index ca0ba15..0fa3257 100644
56051--- a/fs/binfmt_aout.c
56052+++ b/fs/binfmt_aout.c
56053@@ -16,6 +16,7 @@
56054 #include <linux/string.h>
56055 #include <linux/fs.h>
56056 #include <linux/file.h>
56057+#include <linux/security.h>
56058 #include <linux/stat.h>
56059 #include <linux/fcntl.h>
56060 #include <linux/ptrace.h>
56061@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56062 #endif
56063 # define START_STACK(u) ((void __user *)u.start_stack)
56064
56065+ memset(&dump, 0, sizeof(dump));
56066+
56067 fs = get_fs();
56068 set_fs(KERNEL_DS);
56069 has_dumped = 1;
56070@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56071
56072 /* If the size of the dump file exceeds the rlimit, then see what would happen
56073 if we wrote the stack, but not the data area. */
56074+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56075 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56076 dump.u_dsize = 0;
56077
56078 /* Make sure we have enough room to write the stack and data areas. */
56079+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56080 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56081 dump.u_ssize = 0;
56082
56083@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56084 rlim = rlimit(RLIMIT_DATA);
56085 if (rlim >= RLIM_INFINITY)
56086 rlim = ~0;
56087+
56088+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56089 if (ex.a_data + ex.a_bss > rlim)
56090 return -ENOMEM;
56091
56092@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56093
56094 install_exec_creds(bprm);
56095
56096+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56097+ current->mm->pax_flags = 0UL;
56098+#endif
56099+
56100+#ifdef CONFIG_PAX_PAGEEXEC
56101+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56102+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56103+
56104+#ifdef CONFIG_PAX_EMUTRAMP
56105+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56106+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56107+#endif
56108+
56109+#ifdef CONFIG_PAX_MPROTECT
56110+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56111+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56112+#endif
56113+
56114+ }
56115+#endif
56116+
56117 if (N_MAGIC(ex) == OMAGIC) {
56118 unsigned long text_addr, map_size;
56119 loff_t pos;
56120@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56121 }
56122
56123 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56124- PROT_READ | PROT_WRITE | PROT_EXEC,
56125+ PROT_READ | PROT_WRITE,
56126 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56127 fd_offset + ex.a_text);
56128 if (error != N_DATADDR(ex)) {
56129diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56130index aa3cb62..bc53934 100644
56131--- a/fs/binfmt_elf.c
56132+++ b/fs/binfmt_elf.c
56133@@ -34,6 +34,7 @@
56134 #include <linux/utsname.h>
56135 #include <linux/coredump.h>
56136 #include <linux/sched.h>
56137+#include <linux/xattr.h>
56138 #include <asm/uaccess.h>
56139 #include <asm/param.h>
56140 #include <asm/page.h>
56141@@ -47,7 +48,7 @@
56142
56143 static int load_elf_binary(struct linux_binprm *bprm);
56144 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56145- int, int, unsigned long);
56146+ int, int, unsigned long) __intentional_overflow(-1);
56147
56148 #ifdef CONFIG_USELIB
56149 static int load_elf_library(struct file *);
56150@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56151 #define elf_core_dump NULL
56152 #endif
56153
56154+#ifdef CONFIG_PAX_MPROTECT
56155+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56156+#endif
56157+
56158+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56159+static void elf_handle_mmap(struct file *file);
56160+#endif
56161+
56162 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56163 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56164 #else
56165@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56166 .load_binary = load_elf_binary,
56167 .load_shlib = load_elf_library,
56168 .core_dump = elf_core_dump,
56169+
56170+#ifdef CONFIG_PAX_MPROTECT
56171+ .handle_mprotect= elf_handle_mprotect,
56172+#endif
56173+
56174+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56175+ .handle_mmap = elf_handle_mmap,
56176+#endif
56177+
56178 .min_coredump = ELF_EXEC_PAGESIZE,
56179 };
56180
56181@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56182
56183 static int set_brk(unsigned long start, unsigned long end)
56184 {
56185+ unsigned long e = end;
56186+
56187 start = ELF_PAGEALIGN(start);
56188 end = ELF_PAGEALIGN(end);
56189 if (end > start) {
56190@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56191 if (BAD_ADDR(addr))
56192 return addr;
56193 }
56194- current->mm->start_brk = current->mm->brk = end;
56195+ current->mm->start_brk = current->mm->brk = e;
56196 return 0;
56197 }
56198
56199@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56200 elf_addr_t __user *u_rand_bytes;
56201 const char *k_platform = ELF_PLATFORM;
56202 const char *k_base_platform = ELF_BASE_PLATFORM;
56203- unsigned char k_rand_bytes[16];
56204+ u32 k_rand_bytes[4];
56205 int items;
56206 elf_addr_t *elf_info;
56207 int ei_index = 0;
56208 const struct cred *cred = current_cred();
56209 struct vm_area_struct *vma;
56210+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56211
56212 /*
56213 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56214@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56215 * Generate 16 random bytes for userspace PRNG seeding.
56216 */
56217 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56218- u_rand_bytes = (elf_addr_t __user *)
56219- STACK_ALLOC(p, sizeof(k_rand_bytes));
56220+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56221+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56222+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56223+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56224+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56225+ u_rand_bytes = (elf_addr_t __user *) p;
56226 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56227 return -EFAULT;
56228
56229@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56230 return -EFAULT;
56231 current->mm->env_end = p;
56232
56233+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56234+
56235 /* Put the elf_info on the stack in the right place. */
56236 sp = (elf_addr_t __user *)envp + 1;
56237- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56238+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56239 return -EFAULT;
56240 return 0;
56241 }
56242@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56243 an ELF header */
56244
56245 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56246- struct file *interpreter, unsigned long *interp_map_addr,
56247- unsigned long no_base)
56248+ struct file *interpreter, unsigned long no_base)
56249 {
56250 struct elf_phdr *elf_phdata;
56251 struct elf_phdr *eppnt;
56252- unsigned long load_addr = 0;
56253+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56254 int load_addr_set = 0;
56255 unsigned long last_bss = 0, elf_bss = 0;
56256- unsigned long error = ~0UL;
56257+ unsigned long error = -EINVAL;
56258 unsigned long total_size;
56259 int retval, i, size;
56260
56261@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56262 goto out_close;
56263 }
56264
56265+#ifdef CONFIG_PAX_SEGMEXEC
56266+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56267+ pax_task_size = SEGMEXEC_TASK_SIZE;
56268+#endif
56269+
56270 eppnt = elf_phdata;
56271 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56272 if (eppnt->p_type == PT_LOAD) {
56273@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56274 map_addr = elf_map(interpreter, load_addr + vaddr,
56275 eppnt, elf_prot, elf_type, total_size);
56276 total_size = 0;
56277- if (!*interp_map_addr)
56278- *interp_map_addr = map_addr;
56279 error = map_addr;
56280 if (BAD_ADDR(map_addr))
56281 goto out_close;
56282@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56283 k = load_addr + eppnt->p_vaddr;
56284 if (BAD_ADDR(k) ||
56285 eppnt->p_filesz > eppnt->p_memsz ||
56286- eppnt->p_memsz > TASK_SIZE ||
56287- TASK_SIZE - eppnt->p_memsz < k) {
56288+ eppnt->p_memsz > pax_task_size ||
56289+ pax_task_size - eppnt->p_memsz < k) {
56290 error = -ENOMEM;
56291 goto out_close;
56292 }
56293@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56294 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56295
56296 /* Map the last of the bss segment */
56297- error = vm_brk(elf_bss, last_bss - elf_bss);
56298- if (BAD_ADDR(error))
56299- goto out_close;
56300+ if (last_bss > elf_bss) {
56301+ error = vm_brk(elf_bss, last_bss - elf_bss);
56302+ if (BAD_ADDR(error))
56303+ goto out_close;
56304+ }
56305 }
56306
56307 error = load_addr;
56308@@ -543,6 +574,336 @@ out:
56309 return error;
56310 }
56311
56312+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56313+#ifdef CONFIG_PAX_SOFTMODE
56314+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56315+{
56316+ unsigned long pax_flags = 0UL;
56317+
56318+#ifdef CONFIG_PAX_PAGEEXEC
56319+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56320+ pax_flags |= MF_PAX_PAGEEXEC;
56321+#endif
56322+
56323+#ifdef CONFIG_PAX_SEGMEXEC
56324+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56325+ pax_flags |= MF_PAX_SEGMEXEC;
56326+#endif
56327+
56328+#ifdef CONFIG_PAX_EMUTRAMP
56329+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56330+ pax_flags |= MF_PAX_EMUTRAMP;
56331+#endif
56332+
56333+#ifdef CONFIG_PAX_MPROTECT
56334+ if (elf_phdata->p_flags & PF_MPROTECT)
56335+ pax_flags |= MF_PAX_MPROTECT;
56336+#endif
56337+
56338+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56339+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56340+ pax_flags |= MF_PAX_RANDMMAP;
56341+#endif
56342+
56343+ return pax_flags;
56344+}
56345+#endif
56346+
56347+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56348+{
56349+ unsigned long pax_flags = 0UL;
56350+
56351+#ifdef CONFIG_PAX_PAGEEXEC
56352+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56353+ pax_flags |= MF_PAX_PAGEEXEC;
56354+#endif
56355+
56356+#ifdef CONFIG_PAX_SEGMEXEC
56357+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56358+ pax_flags |= MF_PAX_SEGMEXEC;
56359+#endif
56360+
56361+#ifdef CONFIG_PAX_EMUTRAMP
56362+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56363+ pax_flags |= MF_PAX_EMUTRAMP;
56364+#endif
56365+
56366+#ifdef CONFIG_PAX_MPROTECT
56367+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56368+ pax_flags |= MF_PAX_MPROTECT;
56369+#endif
56370+
56371+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56372+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56373+ pax_flags |= MF_PAX_RANDMMAP;
56374+#endif
56375+
56376+ return pax_flags;
56377+}
56378+#endif
56379+
56380+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56381+#ifdef CONFIG_PAX_SOFTMODE
56382+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56383+{
56384+ unsigned long pax_flags = 0UL;
56385+
56386+#ifdef CONFIG_PAX_PAGEEXEC
56387+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56388+ pax_flags |= MF_PAX_PAGEEXEC;
56389+#endif
56390+
56391+#ifdef CONFIG_PAX_SEGMEXEC
56392+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56393+ pax_flags |= MF_PAX_SEGMEXEC;
56394+#endif
56395+
56396+#ifdef CONFIG_PAX_EMUTRAMP
56397+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56398+ pax_flags |= MF_PAX_EMUTRAMP;
56399+#endif
56400+
56401+#ifdef CONFIG_PAX_MPROTECT
56402+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56403+ pax_flags |= MF_PAX_MPROTECT;
56404+#endif
56405+
56406+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56407+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56408+ pax_flags |= MF_PAX_RANDMMAP;
56409+#endif
56410+
56411+ return pax_flags;
56412+}
56413+#endif
56414+
56415+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56416+{
56417+ unsigned long pax_flags = 0UL;
56418+
56419+#ifdef CONFIG_PAX_PAGEEXEC
56420+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56421+ pax_flags |= MF_PAX_PAGEEXEC;
56422+#endif
56423+
56424+#ifdef CONFIG_PAX_SEGMEXEC
56425+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56426+ pax_flags |= MF_PAX_SEGMEXEC;
56427+#endif
56428+
56429+#ifdef CONFIG_PAX_EMUTRAMP
56430+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56431+ pax_flags |= MF_PAX_EMUTRAMP;
56432+#endif
56433+
56434+#ifdef CONFIG_PAX_MPROTECT
56435+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56436+ pax_flags |= MF_PAX_MPROTECT;
56437+#endif
56438+
56439+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56440+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56441+ pax_flags |= MF_PAX_RANDMMAP;
56442+#endif
56443+
56444+ return pax_flags;
56445+}
56446+#endif
56447+
56448+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56449+static unsigned long pax_parse_defaults(void)
56450+{
56451+ unsigned long pax_flags = 0UL;
56452+
56453+#ifdef CONFIG_PAX_SOFTMODE
56454+ if (pax_softmode)
56455+ return pax_flags;
56456+#endif
56457+
56458+#ifdef CONFIG_PAX_PAGEEXEC
56459+ pax_flags |= MF_PAX_PAGEEXEC;
56460+#endif
56461+
56462+#ifdef CONFIG_PAX_SEGMEXEC
56463+ pax_flags |= MF_PAX_SEGMEXEC;
56464+#endif
56465+
56466+#ifdef CONFIG_PAX_MPROTECT
56467+ pax_flags |= MF_PAX_MPROTECT;
56468+#endif
56469+
56470+#ifdef CONFIG_PAX_RANDMMAP
56471+ if (randomize_va_space)
56472+ pax_flags |= MF_PAX_RANDMMAP;
56473+#endif
56474+
56475+ return pax_flags;
56476+}
56477+
56478+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56479+{
56480+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56481+
56482+#ifdef CONFIG_PAX_EI_PAX
56483+
56484+#ifdef CONFIG_PAX_SOFTMODE
56485+ if (pax_softmode)
56486+ return pax_flags;
56487+#endif
56488+
56489+ pax_flags = 0UL;
56490+
56491+#ifdef CONFIG_PAX_PAGEEXEC
56492+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56493+ pax_flags |= MF_PAX_PAGEEXEC;
56494+#endif
56495+
56496+#ifdef CONFIG_PAX_SEGMEXEC
56497+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56498+ pax_flags |= MF_PAX_SEGMEXEC;
56499+#endif
56500+
56501+#ifdef CONFIG_PAX_EMUTRAMP
56502+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56503+ pax_flags |= MF_PAX_EMUTRAMP;
56504+#endif
56505+
56506+#ifdef CONFIG_PAX_MPROTECT
56507+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56508+ pax_flags |= MF_PAX_MPROTECT;
56509+#endif
56510+
56511+#ifdef CONFIG_PAX_ASLR
56512+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56513+ pax_flags |= MF_PAX_RANDMMAP;
56514+#endif
56515+
56516+#endif
56517+
56518+ return pax_flags;
56519+
56520+}
56521+
56522+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56523+{
56524+
56525+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56526+ unsigned long i;
56527+
56528+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56529+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56530+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56531+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56532+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56533+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56534+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56535+ return PAX_PARSE_FLAGS_FALLBACK;
56536+
56537+#ifdef CONFIG_PAX_SOFTMODE
56538+ if (pax_softmode)
56539+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56540+ else
56541+#endif
56542+
56543+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56544+ break;
56545+ }
56546+#endif
56547+
56548+ return PAX_PARSE_FLAGS_FALLBACK;
56549+}
56550+
56551+static unsigned long pax_parse_xattr_pax(struct file * const file)
56552+{
56553+
56554+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56555+ ssize_t xattr_size, i;
56556+ unsigned char xattr_value[sizeof("pemrs") - 1];
56557+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56558+
56559+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56560+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56561+ return PAX_PARSE_FLAGS_FALLBACK;
56562+
56563+ for (i = 0; i < xattr_size; i++)
56564+ switch (xattr_value[i]) {
56565+ default:
56566+ return PAX_PARSE_FLAGS_FALLBACK;
56567+
56568+#define parse_flag(option1, option2, flag) \
56569+ case option1: \
56570+ if (pax_flags_hardmode & MF_PAX_##flag) \
56571+ return PAX_PARSE_FLAGS_FALLBACK;\
56572+ pax_flags_hardmode |= MF_PAX_##flag; \
56573+ break; \
56574+ case option2: \
56575+ if (pax_flags_softmode & MF_PAX_##flag) \
56576+ return PAX_PARSE_FLAGS_FALLBACK;\
56577+ pax_flags_softmode |= MF_PAX_##flag; \
56578+ break;
56579+
56580+ parse_flag('p', 'P', PAGEEXEC);
56581+ parse_flag('e', 'E', EMUTRAMP);
56582+ parse_flag('m', 'M', MPROTECT);
56583+ parse_flag('r', 'R', RANDMMAP);
56584+ parse_flag('s', 'S', SEGMEXEC);
56585+
56586+#undef parse_flag
56587+ }
56588+
56589+ if (pax_flags_hardmode & pax_flags_softmode)
56590+ return PAX_PARSE_FLAGS_FALLBACK;
56591+
56592+#ifdef CONFIG_PAX_SOFTMODE
56593+ if (pax_softmode)
56594+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56595+ else
56596+#endif
56597+
56598+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56599+#else
56600+ return PAX_PARSE_FLAGS_FALLBACK;
56601+#endif
56602+
56603+}
56604+
56605+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56606+{
56607+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56608+
56609+ pax_flags = pax_parse_defaults();
56610+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
56611+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56612+ xattr_pax_flags = pax_parse_xattr_pax(file);
56613+
56614+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56615+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56616+ pt_pax_flags != xattr_pax_flags)
56617+ return -EINVAL;
56618+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56619+ pax_flags = xattr_pax_flags;
56620+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56621+ pax_flags = pt_pax_flags;
56622+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56623+ pax_flags = ei_pax_flags;
56624+
56625+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56626+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56627+ if ((__supported_pte_mask & _PAGE_NX))
56628+ pax_flags &= ~MF_PAX_SEGMEXEC;
56629+ else
56630+ pax_flags &= ~MF_PAX_PAGEEXEC;
56631+ }
56632+#endif
56633+
56634+ if (0 > pax_check_flags(&pax_flags))
56635+ return -EINVAL;
56636+
56637+ current->mm->pax_flags = pax_flags;
56638+ return 0;
56639+}
56640+#endif
56641+
56642 /*
56643 * These are the functions used to load ELF style executables and shared
56644 * libraries. There is no binary dependent code anywhere else.
56645@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56646 {
56647 unsigned int random_variable = 0;
56648
56649+#ifdef CONFIG_PAX_RANDUSTACK
56650+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56651+ return stack_top - current->mm->delta_stack;
56652+#endif
56653+
56654 if ((current->flags & PF_RANDOMIZE) &&
56655 !(current->personality & ADDR_NO_RANDOMIZE)) {
56656 random_variable = get_random_int() & STACK_RND_MASK;
56657@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56658 unsigned long load_addr = 0, load_bias = 0;
56659 int load_addr_set = 0;
56660 char * elf_interpreter = NULL;
56661- unsigned long error;
56662+ unsigned long error = 0;
56663 struct elf_phdr *elf_ppnt, *elf_phdata;
56664 unsigned long elf_bss, elf_brk;
56665 int retval, i;
56666@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56667 struct elfhdr elf_ex;
56668 struct elfhdr interp_elf_ex;
56669 } *loc;
56670+ unsigned long pax_task_size;
56671
56672 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56673 if (!loc) {
56674@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
56675 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56676 may depend on the personality. */
56677 SET_PERSONALITY(loc->elf_ex);
56678+
56679+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56680+ current->mm->pax_flags = 0UL;
56681+#endif
56682+
56683+#ifdef CONFIG_PAX_DLRESOLVE
56684+ current->mm->call_dl_resolve = 0UL;
56685+#endif
56686+
56687+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56688+ current->mm->call_syscall = 0UL;
56689+#endif
56690+
56691+#ifdef CONFIG_PAX_ASLR
56692+ current->mm->delta_mmap = 0UL;
56693+ current->mm->delta_stack = 0UL;
56694+#endif
56695+
56696+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56697+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56698+ send_sig(SIGKILL, current, 0);
56699+ goto out_free_dentry;
56700+ }
56701+#endif
56702+
56703+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56704+ pax_set_initial_flags(bprm);
56705+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56706+ if (pax_set_initial_flags_func)
56707+ (pax_set_initial_flags_func)(bprm);
56708+#endif
56709+
56710+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56711+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56712+ current->mm->context.user_cs_limit = PAGE_SIZE;
56713+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56714+ }
56715+#endif
56716+
56717+#ifdef CONFIG_PAX_SEGMEXEC
56718+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56719+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56720+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56721+ pax_task_size = SEGMEXEC_TASK_SIZE;
56722+ current->mm->def_flags |= VM_NOHUGEPAGE;
56723+ } else
56724+#endif
56725+
56726+ pax_task_size = TASK_SIZE;
56727+
56728+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56729+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56730+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56731+ put_cpu();
56732+ }
56733+#endif
56734+
56735+#ifdef CONFIG_PAX_ASLR
56736+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56737+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56738+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56739+ }
56740+#endif
56741+
56742+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56743+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56744+ executable_stack = EXSTACK_DISABLE_X;
56745+ current->personality &= ~READ_IMPLIES_EXEC;
56746+ } else
56747+#endif
56748+
56749 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56750 current->personality |= READ_IMPLIES_EXEC;
56751
56752@@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56753 #else
56754 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56755 #endif
56756+
56757+#ifdef CONFIG_PAX_RANDMMAP
56758+ /* PaX: randomize base address at the default exe base if requested */
56759+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56760+#ifdef CONFIG_SPARC64
56761+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56762+#else
56763+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56764+#endif
56765+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56766+ elf_flags |= MAP_FIXED;
56767+ }
56768+#endif
56769+
56770 }
56771
56772 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56773@@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56774 * allowed task size. Note that p_filesz must always be
56775 * <= p_memsz so it is only necessary to check p_memsz.
56776 */
56777- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56778- elf_ppnt->p_memsz > TASK_SIZE ||
56779- TASK_SIZE - elf_ppnt->p_memsz < k) {
56780+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56781+ elf_ppnt->p_memsz > pax_task_size ||
56782+ pax_task_size - elf_ppnt->p_memsz < k) {
56783 /* set_brk can never work. Avoid overflows. */
56784 send_sig(SIGKILL, current, 0);
56785 retval = -EINVAL;
56786@@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56787 goto out_free_dentry;
56788 }
56789 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56790- send_sig(SIGSEGV, current, 0);
56791- retval = -EFAULT; /* Nobody gets to see this, but.. */
56792- goto out_free_dentry;
56793+ /*
56794+ * This bss-zeroing can fail if the ELF
56795+ * file specifies odd protections. So
56796+ * we don't check the return value
56797+ */
56798 }
56799
56800+#ifdef CONFIG_PAX_RANDMMAP
56801+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56802+ unsigned long start, size, flags;
56803+ vm_flags_t vm_flags;
56804+
56805+ start = ELF_PAGEALIGN(elf_brk);
56806+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56807+ flags = MAP_FIXED | MAP_PRIVATE;
56808+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56809+
56810+ down_write(&current->mm->mmap_sem);
56811+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56812+ retval = -ENOMEM;
56813+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56814+// if (current->personality & ADDR_NO_RANDOMIZE)
56815+// vm_flags |= VM_READ | VM_MAYREAD;
56816+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56817+ retval = IS_ERR_VALUE(start) ? start : 0;
56818+ }
56819+ up_write(&current->mm->mmap_sem);
56820+ if (retval == 0)
56821+ retval = set_brk(start + size, start + size + PAGE_SIZE);
56822+ if (retval < 0) {
56823+ send_sig(SIGKILL, current, 0);
56824+ goto out_free_dentry;
56825+ }
56826+ }
56827+#endif
56828+
56829 if (elf_interpreter) {
56830- unsigned long interp_map_addr = 0;
56831-
56832 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56833 interpreter,
56834- &interp_map_addr,
56835 load_bias);
56836 if (!IS_ERR((void *)elf_entry)) {
56837 /*
56838@@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56839 * Decide what to dump of a segment, part, all or none.
56840 */
56841 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56842- unsigned long mm_flags)
56843+ unsigned long mm_flags, long signr)
56844 {
56845 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56846
56847@@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56848 if (vma->vm_file == NULL)
56849 return 0;
56850
56851- if (FILTER(MAPPED_PRIVATE))
56852+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56853 goto whole;
56854
56855 /*
56856@@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56857 {
56858 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56859 int i = 0;
56860- do
56861+ do {
56862 i += 2;
56863- while (auxv[i - 2] != AT_NULL);
56864+ } while (auxv[i - 2] != AT_NULL);
56865 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56866 }
56867
56868@@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56869 {
56870 mm_segment_t old_fs = get_fs();
56871 set_fs(KERNEL_DS);
56872- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56873+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56874 set_fs(old_fs);
56875 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56876 }
56877@@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56878 }
56879
56880 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56881- unsigned long mm_flags)
56882+ struct coredump_params *cprm)
56883 {
56884 struct vm_area_struct *vma;
56885 size_t size = 0;
56886
56887 for (vma = first_vma(current, gate_vma); vma != NULL;
56888 vma = next_vma(vma, gate_vma))
56889- size += vma_dump_size(vma, mm_flags);
56890+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56891 return size;
56892 }
56893
56894@@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56895
56896 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56897
56898- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56899+ offset += elf_core_vma_data_size(gate_vma, cprm);
56900 offset += elf_core_extra_data_size();
56901 e_shoff = offset;
56902
56903@@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56904 phdr.p_offset = offset;
56905 phdr.p_vaddr = vma->vm_start;
56906 phdr.p_paddr = 0;
56907- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56908+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56909 phdr.p_memsz = vma->vm_end - vma->vm_start;
56910 offset += phdr.p_filesz;
56911 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56912@@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56913 unsigned long addr;
56914 unsigned long end;
56915
56916- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56917+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56918
56919 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56920 struct page *page;
56921@@ -2202,6 +2682,167 @@ out:
56922
56923 #endif /* CONFIG_ELF_CORE */
56924
56925+#ifdef CONFIG_PAX_MPROTECT
56926+/* PaX: non-PIC ELF libraries need relocations on their executable segments
56927+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56928+ * we'll remove VM_MAYWRITE for good on RELRO segments.
56929+ *
56930+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56931+ * basis because we want to allow the common case and not the special ones.
56932+ */
56933+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56934+{
56935+ struct elfhdr elf_h;
56936+ struct elf_phdr elf_p;
56937+ unsigned long i;
56938+ unsigned long oldflags;
56939+ bool is_textrel_rw, is_textrel_rx, is_relro;
56940+
56941+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56942+ return;
56943+
56944+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56945+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56946+
56947+#ifdef CONFIG_PAX_ELFRELOCS
56948+ /* possible TEXTREL */
56949+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56950+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56951+#else
56952+ is_textrel_rw = false;
56953+ is_textrel_rx = false;
56954+#endif
56955+
56956+ /* possible RELRO */
56957+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56958+
56959+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56960+ return;
56961+
56962+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56963+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56964+
56965+#ifdef CONFIG_PAX_ETEXECRELOCS
56966+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56967+#else
56968+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56969+#endif
56970+
56971+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56972+ !elf_check_arch(&elf_h) ||
56973+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56974+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56975+ return;
56976+
56977+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56978+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56979+ return;
56980+ switch (elf_p.p_type) {
56981+ case PT_DYNAMIC:
56982+ if (!is_textrel_rw && !is_textrel_rx)
56983+ continue;
56984+ i = 0UL;
56985+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56986+ elf_dyn dyn;
56987+
56988+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56989+ break;
56990+ if (dyn.d_tag == DT_NULL)
56991+ break;
56992+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56993+ gr_log_textrel(vma);
56994+ if (is_textrel_rw)
56995+ vma->vm_flags |= VM_MAYWRITE;
56996+ else
56997+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56998+ vma->vm_flags &= ~VM_MAYWRITE;
56999+ break;
57000+ }
57001+ i++;
57002+ }
57003+ is_textrel_rw = false;
57004+ is_textrel_rx = false;
57005+ continue;
57006+
57007+ case PT_GNU_RELRO:
57008+ if (!is_relro)
57009+ continue;
57010+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57011+ vma->vm_flags &= ~VM_MAYWRITE;
57012+ is_relro = false;
57013+ continue;
57014+
57015+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57016+ case PT_PAX_FLAGS: {
57017+ const char *msg_mprotect = "", *msg_emutramp = "";
57018+ char *buffer_lib, *buffer_exe;
57019+
57020+ if (elf_p.p_flags & PF_NOMPROTECT)
57021+ msg_mprotect = "MPROTECT disabled";
57022+
57023+#ifdef CONFIG_PAX_EMUTRAMP
57024+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57025+ msg_emutramp = "EMUTRAMP enabled";
57026+#endif
57027+
57028+ if (!msg_mprotect[0] && !msg_emutramp[0])
57029+ continue;
57030+
57031+ if (!printk_ratelimit())
57032+ continue;
57033+
57034+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57035+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57036+ if (buffer_lib && buffer_exe) {
57037+ char *path_lib, *path_exe;
57038+
57039+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57040+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57041+
57042+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57043+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57044+
57045+ }
57046+ free_page((unsigned long)buffer_exe);
57047+ free_page((unsigned long)buffer_lib);
57048+ continue;
57049+ }
57050+#endif
57051+
57052+ }
57053+ }
57054+}
57055+#endif
57056+
57057+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57058+
57059+extern int grsec_enable_log_rwxmaps;
57060+
57061+static void elf_handle_mmap(struct file *file)
57062+{
57063+ struct elfhdr elf_h;
57064+ struct elf_phdr elf_p;
57065+ unsigned long i;
57066+
57067+ if (!grsec_enable_log_rwxmaps)
57068+ return;
57069+
57070+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57071+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57072+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57073+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57074+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57075+ return;
57076+
57077+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57078+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57079+ return;
57080+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57081+ gr_log_ptgnustack(file);
57082+ }
57083+}
57084+#endif
57085+
57086 static int __init init_elf_binfmt(void)
57087 {
57088 register_binfmt(&elf_format);
57089diff --git a/fs/bio.c b/fs/bio.c
57090index 6f0362b..26a7496 100644
57091--- a/fs/bio.c
57092+++ b/fs/bio.c
57093@@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57094 /*
57095 * Overflow, abort
57096 */
57097- if (end < start)
57098+ if (end < start || end - start > INT_MAX - nr_pages)
57099 return ERR_PTR(-EINVAL);
57100
57101 nr_pages += end - start;
57102@@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57103 /*
57104 * Overflow, abort
57105 */
57106- if (end < start)
57107+ if (end < start || end - start > INT_MAX - nr_pages)
57108 return ERR_PTR(-EINVAL);
57109
57110 nr_pages += end - start;
57111@@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57112 const int read = bio_data_dir(bio) == READ;
57113 struct bio_map_data *bmd = bio->bi_private;
57114 int i;
57115- char *p = bmd->sgvecs[0].iov_base;
57116+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57117
57118 bio_for_each_segment_all(bvec, bio, i) {
57119 char *addr = page_address(bvec->bv_page);
57120diff --git a/fs/block_dev.c b/fs/block_dev.c
57121index 552a8d1..d51ccf3 100644
57122--- a/fs/block_dev.c
57123+++ b/fs/block_dev.c
57124@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57125 else if (bdev->bd_contains == bdev)
57126 return true; /* is a whole device which isn't held */
57127
57128- else if (whole->bd_holder == bd_may_claim)
57129+ else if (whole->bd_holder == (void *)bd_may_claim)
57130 return true; /* is a partition of a device that is being partitioned */
57131 else if (whole->bd_holder != NULL)
57132 return false; /* is a partition of a held device */
57133diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57134index 1bcfcdb..e942132 100644
57135--- a/fs/btrfs/ctree.c
57136+++ b/fs/btrfs/ctree.c
57137@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57138 free_extent_buffer(buf);
57139 add_root_to_dirty_list(root);
57140 } else {
57141- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57142- parent_start = parent->start;
57143- else
57144+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57145+ if (parent)
57146+ parent_start = parent->start;
57147+ else
57148+ parent_start = 0;
57149+ } else
57150 parent_start = 0;
57151
57152 WARN_ON(trans->transid != btrfs_header_generation(parent));
57153diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57154index 33e561a..16df7ae 100644
57155--- a/fs/btrfs/delayed-inode.c
57156+++ b/fs/btrfs/delayed-inode.c
57157@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57158
57159 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57160 {
57161- int seq = atomic_inc_return(&delayed_root->items_seq);
57162+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57163 if ((atomic_dec_return(&delayed_root->items) <
57164 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57165 waitqueue_active(&delayed_root->wait))
57166@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57167
57168 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57169 {
57170- int val = atomic_read(&delayed_root->items_seq);
57171+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57172
57173 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57174 return 1;
57175@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57176 int seq;
57177 int ret;
57178
57179- seq = atomic_read(&delayed_root->items_seq);
57180+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57181
57182 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57183 if (ret)
57184diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57185index f70119f..ab5894d 100644
57186--- a/fs/btrfs/delayed-inode.h
57187+++ b/fs/btrfs/delayed-inode.h
57188@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57189 */
57190 struct list_head prepare_list;
57191 atomic_t items; /* for delayed items */
57192- atomic_t items_seq; /* for delayed items */
57193+ atomic_unchecked_t items_seq; /* for delayed items */
57194 int nodes; /* for delayed nodes */
57195 wait_queue_head_t wait;
57196 };
57197@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57198 struct btrfs_delayed_root *delayed_root)
57199 {
57200 atomic_set(&delayed_root->items, 0);
57201- atomic_set(&delayed_root->items_seq, 0);
57202+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57203 delayed_root->nodes = 0;
57204 spin_lock_init(&delayed_root->lock);
57205 init_waitqueue_head(&delayed_root->wait);
57206diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57207index 2f6d7b1..f186382 100644
57208--- a/fs/btrfs/ioctl.c
57209+++ b/fs/btrfs/ioctl.c
57210@@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57211 for (i = 0; i < num_types; i++) {
57212 struct btrfs_space_info *tmp;
57213
57214+ /* Don't copy in more than we allocated */
57215 if (!slot_count)
57216 break;
57217
57218+ slot_count--;
57219+
57220 info = NULL;
57221 rcu_read_lock();
57222 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57223@@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57224 memcpy(dest, &space, sizeof(space));
57225 dest++;
57226 space_args.total_spaces++;
57227- slot_count--;
57228 }
57229- if (!slot_count)
57230- break;
57231 }
57232 up_read(&info->groups_sem);
57233 }
57234diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57235index 9601d25..2896d6c 100644
57236--- a/fs/btrfs/super.c
57237+++ b/fs/btrfs/super.c
57238@@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57239 function, line, errstr);
57240 return;
57241 }
57242- ACCESS_ONCE(trans->transaction->aborted) = errno;
57243+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57244 /* Wake up anybody who may be waiting on this transaction */
57245 wake_up(&root->fs_info->transaction_wait);
57246 wake_up(&root->fs_info->transaction_blocked_wait);
57247diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57248index 4825cd2..b2fe768 100644
57249--- a/fs/btrfs/sysfs.c
57250+++ b/fs/btrfs/sysfs.c
57251@@ -438,7 +438,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57252 for (set = 0; set < FEAT_MAX; set++) {
57253 int i;
57254 struct attribute *attrs[2];
57255- struct attribute_group agroup = {
57256+ attribute_group_no_const agroup = {
57257 .name = "features",
57258 .attrs = attrs,
57259 };
57260diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57261index e2f45fc..b036909 100644
57262--- a/fs/btrfs/tree-log.c
57263+++ b/fs/btrfs/tree-log.c
57264@@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57265 blk_finish_plug(&plug);
57266 btrfs_abort_transaction(trans, root, ret);
57267 btrfs_free_logged_extents(log, log_transid);
57268- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57269+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57270 trans->transid;
57271 mutex_unlock(&root->log_mutex);
57272 goto out;
57273@@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57274 list_del_init(&root_log_ctx.list);
57275
57276 blk_finish_plug(&plug);
57277- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57278+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57279 trans->transid;
57280 if (ret != -ENOSPC) {
57281 btrfs_abort_transaction(trans, root, ret);
57282@@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57283 * now that we've moved on to the tree of log tree roots,
57284 * check the full commit flag again
57285 */
57286- if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57287+ if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57288 trans->transid) {
57289 blk_finish_plug(&plug);
57290 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57291@@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57292 EXTENT_DIRTY | EXTENT_NEW);
57293 blk_finish_plug(&plug);
57294 if (ret) {
57295- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57296+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57297 trans->transid;
57298 btrfs_abort_transaction(trans, root, ret);
57299 btrfs_free_logged_extents(log, log_transid);
57300@@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57301 */
57302 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57303 if (ret) {
57304- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57305+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57306 trans->transid;
57307 btrfs_abort_transaction(trans, root, ret);
57308 goto out_wake_log_root;
57309diff --git a/fs/buffer.c b/fs/buffer.c
57310index 9ddb9fc..7aa2487 100644
57311--- a/fs/buffer.c
57312+++ b/fs/buffer.c
57313@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57314 bh_cachep = kmem_cache_create("buffer_head",
57315 sizeof(struct buffer_head), 0,
57316 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57317- SLAB_MEM_SPREAD),
57318+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57319 NULL);
57320
57321 /*
57322diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57323index 5b99baf..47fffb5 100644
57324--- a/fs/cachefiles/bind.c
57325+++ b/fs/cachefiles/bind.c
57326@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57327 args);
57328
57329 /* start by checking things over */
57330- ASSERT(cache->fstop_percent >= 0 &&
57331- cache->fstop_percent < cache->fcull_percent &&
57332+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57333 cache->fcull_percent < cache->frun_percent &&
57334 cache->frun_percent < 100);
57335
57336- ASSERT(cache->bstop_percent >= 0 &&
57337- cache->bstop_percent < cache->bcull_percent &&
57338+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57339 cache->bcull_percent < cache->brun_percent &&
57340 cache->brun_percent < 100);
57341
57342diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57343index 0a1467b..6a53245 100644
57344--- a/fs/cachefiles/daemon.c
57345+++ b/fs/cachefiles/daemon.c
57346@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57347 if (n > buflen)
57348 return -EMSGSIZE;
57349
57350- if (copy_to_user(_buffer, buffer, n) != 0)
57351+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57352 return -EFAULT;
57353
57354 return n;
57355@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57356 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57357 return -EIO;
57358
57359- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57360+ if (datalen > PAGE_SIZE - 1)
57361 return -EOPNOTSUPP;
57362
57363 /* drag the command string into the kernel so we can parse it */
57364@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57365 if (args[0] != '%' || args[1] != '\0')
57366 return -EINVAL;
57367
57368- if (fstop < 0 || fstop >= cache->fcull_percent)
57369+ if (fstop >= cache->fcull_percent)
57370 return cachefiles_daemon_range_error(cache, args);
57371
57372 cache->fstop_percent = fstop;
57373@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57374 if (args[0] != '%' || args[1] != '\0')
57375 return -EINVAL;
57376
57377- if (bstop < 0 || bstop >= cache->bcull_percent)
57378+ if (bstop >= cache->bcull_percent)
57379 return cachefiles_daemon_range_error(cache, args);
57380
57381 cache->bstop_percent = bstop;
57382diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57383index 5349473..d6c0b93 100644
57384--- a/fs/cachefiles/internal.h
57385+++ b/fs/cachefiles/internal.h
57386@@ -59,7 +59,7 @@ struct cachefiles_cache {
57387 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57388 struct rb_root active_nodes; /* active nodes (can't be culled) */
57389 rwlock_t active_lock; /* lock for active_nodes */
57390- atomic_t gravecounter; /* graveyard uniquifier */
57391+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57392 unsigned frun_percent; /* when to stop culling (% files) */
57393 unsigned fcull_percent; /* when to start culling (% files) */
57394 unsigned fstop_percent; /* when to stop allocating (% files) */
57395@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57396 * proc.c
57397 */
57398 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57399-extern atomic_t cachefiles_lookup_histogram[HZ];
57400-extern atomic_t cachefiles_mkdir_histogram[HZ];
57401-extern atomic_t cachefiles_create_histogram[HZ];
57402+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57403+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57404+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57405
57406 extern int __init cachefiles_proc_init(void);
57407 extern void cachefiles_proc_cleanup(void);
57408 static inline
57409-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57410+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57411 {
57412 unsigned long jif = jiffies - start_jif;
57413 if (jif >= HZ)
57414 jif = HZ - 1;
57415- atomic_inc(&histogram[jif]);
57416+ atomic_inc_unchecked(&histogram[jif]);
57417 }
57418
57419 #else
57420diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57421index c0a6817..ea811166 100644
57422--- a/fs/cachefiles/namei.c
57423+++ b/fs/cachefiles/namei.c
57424@@ -317,7 +317,7 @@ try_again:
57425 /* first step is to make up a grave dentry in the graveyard */
57426 sprintf(nbuffer, "%08x%08x",
57427 (uint32_t) get_seconds(),
57428- (uint32_t) atomic_inc_return(&cache->gravecounter));
57429+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57430
57431 /* do the multiway lock magic */
57432 trap = lock_rename(cache->graveyard, dir);
57433diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57434index eccd339..4c1d995 100644
57435--- a/fs/cachefiles/proc.c
57436+++ b/fs/cachefiles/proc.c
57437@@ -14,9 +14,9 @@
57438 #include <linux/seq_file.h>
57439 #include "internal.h"
57440
57441-atomic_t cachefiles_lookup_histogram[HZ];
57442-atomic_t cachefiles_mkdir_histogram[HZ];
57443-atomic_t cachefiles_create_histogram[HZ];
57444+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57445+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57446+atomic_unchecked_t cachefiles_create_histogram[HZ];
57447
57448 /*
57449 * display the latency histogram
57450@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57451 return 0;
57452 default:
57453 index = (unsigned long) v - 3;
57454- x = atomic_read(&cachefiles_lookup_histogram[index]);
57455- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57456- z = atomic_read(&cachefiles_create_histogram[index]);
57457+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57458+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57459+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57460 if (x == 0 && y == 0 && z == 0)
57461 return 0;
57462
57463diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57464index 4b1fb5c..0d2a699 100644
57465--- a/fs/cachefiles/rdwr.c
57466+++ b/fs/cachefiles/rdwr.c
57467@@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57468 old_fs = get_fs();
57469 set_fs(KERNEL_DS);
57470 ret = file->f_op->write(
57471- file, (const void __user *) data, len, &pos);
57472+ file, (const void __force_user *) data, len, &pos);
57473 set_fs(old_fs);
57474 kunmap(page);
57475 file_end_write(file);
57476diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57477index c29d6ae..a56c4ae 100644
57478--- a/fs/ceph/dir.c
57479+++ b/fs/ceph/dir.c
57480@@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57481 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57482 struct ceph_mds_client *mdsc = fsc->mdsc;
57483 unsigned frag = fpos_frag(ctx->pos);
57484- int off = fpos_off(ctx->pos);
57485+ unsigned int off = fpos_off(ctx->pos);
57486 int err;
57487 u32 ftype;
57488 struct ceph_mds_reply_info_parsed *rinfo;
57489diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57490index 06150fd..192061b 100644
57491--- a/fs/ceph/super.c
57492+++ b/fs/ceph/super.c
57493@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57494 /*
57495 * construct our own bdi so we can control readahead, etc.
57496 */
57497-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57498+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57499
57500 static int ceph_register_bdi(struct super_block *sb,
57501 struct ceph_fs_client *fsc)
57502@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57503 default_backing_dev_info.ra_pages;
57504
57505 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57506- atomic_long_inc_return(&bdi_seq));
57507+ atomic_long_inc_return_unchecked(&bdi_seq));
57508 if (!err)
57509 sb->s_bdi = &fsc->backing_dev_info;
57510 return err;
57511diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57512index f3ac415..3d2420c 100644
57513--- a/fs/cifs/cifs_debug.c
57514+++ b/fs/cifs/cifs_debug.c
57515@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57516
57517 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57518 #ifdef CONFIG_CIFS_STATS2
57519- atomic_set(&totBufAllocCount, 0);
57520- atomic_set(&totSmBufAllocCount, 0);
57521+ atomic_set_unchecked(&totBufAllocCount, 0);
57522+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57523 #endif /* CONFIG_CIFS_STATS2 */
57524 spin_lock(&cifs_tcp_ses_lock);
57525 list_for_each(tmp1, &cifs_tcp_ses_list) {
57526@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57527 tcon = list_entry(tmp3,
57528 struct cifs_tcon,
57529 tcon_list);
57530- atomic_set(&tcon->num_smbs_sent, 0);
57531+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57532 if (server->ops->clear_stats)
57533 server->ops->clear_stats(tcon);
57534 }
57535@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57536 smBufAllocCount.counter, cifs_min_small);
57537 #ifdef CONFIG_CIFS_STATS2
57538 seq_printf(m, "Total Large %d Small %d Allocations\n",
57539- atomic_read(&totBufAllocCount),
57540- atomic_read(&totSmBufAllocCount));
57541+ atomic_read_unchecked(&totBufAllocCount),
57542+ atomic_read_unchecked(&totSmBufAllocCount));
57543 #endif /* CONFIG_CIFS_STATS2 */
57544
57545 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57546@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57547 if (tcon->need_reconnect)
57548 seq_puts(m, "\tDISCONNECTED ");
57549 seq_printf(m, "\nSMBs: %d",
57550- atomic_read(&tcon->num_smbs_sent));
57551+ atomic_read_unchecked(&tcon->num_smbs_sent));
57552 if (server->ops->print_stats)
57553 server->ops->print_stats(m, tcon);
57554 }
57555diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57556index 5be1f997..fa1015a1 100644
57557--- a/fs/cifs/cifsfs.c
57558+++ b/fs/cifs/cifsfs.c
57559@@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
57560 */
57561 cifs_req_cachep = kmem_cache_create("cifs_request",
57562 CIFSMaxBufSize + max_hdr_size, 0,
57563- SLAB_HWCACHE_ALIGN, NULL);
57564+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57565 if (cifs_req_cachep == NULL)
57566 return -ENOMEM;
57567
57568@@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
57569 efficient to alloc 1 per page off the slab compared to 17K (5page)
57570 alloc of large cifs buffers even when page debugging is on */
57571 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57572- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57573+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57574 NULL);
57575 if (cifs_sm_req_cachep == NULL) {
57576 mempool_destroy(cifs_req_poolp);
57577@@ -1180,8 +1180,8 @@ init_cifs(void)
57578 atomic_set(&bufAllocCount, 0);
57579 atomic_set(&smBufAllocCount, 0);
57580 #ifdef CONFIG_CIFS_STATS2
57581- atomic_set(&totBufAllocCount, 0);
57582- atomic_set(&totSmBufAllocCount, 0);
57583+ atomic_set_unchecked(&totBufAllocCount, 0);
57584+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57585 #endif /* CONFIG_CIFS_STATS2 */
57586
57587 atomic_set(&midCount, 0);
57588diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57589index 30f6e92..e915ba5 100644
57590--- a/fs/cifs/cifsglob.h
57591+++ b/fs/cifs/cifsglob.h
57592@@ -806,35 +806,35 @@ struct cifs_tcon {
57593 __u16 Flags; /* optional support bits */
57594 enum statusEnum tidStatus;
57595 #ifdef CONFIG_CIFS_STATS
57596- atomic_t num_smbs_sent;
57597+ atomic_unchecked_t num_smbs_sent;
57598 union {
57599 struct {
57600- atomic_t num_writes;
57601- atomic_t num_reads;
57602- atomic_t num_flushes;
57603- atomic_t num_oplock_brks;
57604- atomic_t num_opens;
57605- atomic_t num_closes;
57606- atomic_t num_deletes;
57607- atomic_t num_mkdirs;
57608- atomic_t num_posixopens;
57609- atomic_t num_posixmkdirs;
57610- atomic_t num_rmdirs;
57611- atomic_t num_renames;
57612- atomic_t num_t2renames;
57613- atomic_t num_ffirst;
57614- atomic_t num_fnext;
57615- atomic_t num_fclose;
57616- atomic_t num_hardlinks;
57617- atomic_t num_symlinks;
57618- atomic_t num_locks;
57619- atomic_t num_acl_get;
57620- atomic_t num_acl_set;
57621+ atomic_unchecked_t num_writes;
57622+ atomic_unchecked_t num_reads;
57623+ atomic_unchecked_t num_flushes;
57624+ atomic_unchecked_t num_oplock_brks;
57625+ atomic_unchecked_t num_opens;
57626+ atomic_unchecked_t num_closes;
57627+ atomic_unchecked_t num_deletes;
57628+ atomic_unchecked_t num_mkdirs;
57629+ atomic_unchecked_t num_posixopens;
57630+ atomic_unchecked_t num_posixmkdirs;
57631+ atomic_unchecked_t num_rmdirs;
57632+ atomic_unchecked_t num_renames;
57633+ atomic_unchecked_t num_t2renames;
57634+ atomic_unchecked_t num_ffirst;
57635+ atomic_unchecked_t num_fnext;
57636+ atomic_unchecked_t num_fclose;
57637+ atomic_unchecked_t num_hardlinks;
57638+ atomic_unchecked_t num_symlinks;
57639+ atomic_unchecked_t num_locks;
57640+ atomic_unchecked_t num_acl_get;
57641+ atomic_unchecked_t num_acl_set;
57642 } cifs_stats;
57643 #ifdef CONFIG_CIFS_SMB2
57644 struct {
57645- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57646- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57647+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57648+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57649 } smb2_stats;
57650 #endif /* CONFIG_CIFS_SMB2 */
57651 } stats;
57652@@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
57653 }
57654
57655 #ifdef CONFIG_CIFS_STATS
57656-#define cifs_stats_inc atomic_inc
57657+#define cifs_stats_inc atomic_inc_unchecked
57658
57659 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57660 unsigned int bytes)
57661@@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57662 /* Various Debug counters */
57663 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57664 #ifdef CONFIG_CIFS_STATS2
57665-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57666-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57667+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57668+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57669 #endif
57670 GLOBAL_EXTERN atomic_t smBufAllocCount;
57671 GLOBAL_EXTERN atomic_t midCount;
57672diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57673index 5ed03e0..e9a3a6c 100644
57674--- a/fs/cifs/file.c
57675+++ b/fs/cifs/file.c
57676@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57677 index = mapping->writeback_index; /* Start from prev offset */
57678 end = -1;
57679 } else {
57680- index = wbc->range_start >> PAGE_CACHE_SHIFT;
57681- end = wbc->range_end >> PAGE_CACHE_SHIFT;
57682- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57683+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57684 range_whole = true;
57685+ index = 0;
57686+ end = ULONG_MAX;
57687+ } else {
57688+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
57689+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
57690+ }
57691 scanned = true;
57692 }
57693 retry:
57694diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57695index 3b0c62e..f7d090c 100644
57696--- a/fs/cifs/misc.c
57697+++ b/fs/cifs/misc.c
57698@@ -170,7 +170,7 @@ cifs_buf_get(void)
57699 memset(ret_buf, 0, buf_size + 3);
57700 atomic_inc(&bufAllocCount);
57701 #ifdef CONFIG_CIFS_STATS2
57702- atomic_inc(&totBufAllocCount);
57703+ atomic_inc_unchecked(&totBufAllocCount);
57704 #endif /* CONFIG_CIFS_STATS2 */
57705 }
57706
57707@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57708 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57709 atomic_inc(&smBufAllocCount);
57710 #ifdef CONFIG_CIFS_STATS2
57711- atomic_inc(&totSmBufAllocCount);
57712+ atomic_inc_unchecked(&totSmBufAllocCount);
57713 #endif /* CONFIG_CIFS_STATS2 */
57714
57715 }
57716diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57717index d1fdfa8..94558f8 100644
57718--- a/fs/cifs/smb1ops.c
57719+++ b/fs/cifs/smb1ops.c
57720@@ -626,27 +626,27 @@ static void
57721 cifs_clear_stats(struct cifs_tcon *tcon)
57722 {
57723 #ifdef CONFIG_CIFS_STATS
57724- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57725- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57726- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57727- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57728- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57729- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57730- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57731- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57732- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57733- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57734- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57735- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57736- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57737- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57738- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57739- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57740- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57741- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57742- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57743- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57744- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57745+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57746+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57747+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57748+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57749+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57750+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57751+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57752+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57753+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57754+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57755+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57756+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57757+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57758+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57759+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57760+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57761+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57762+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57763+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57764+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57765+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57766 #endif
57767 }
57768
57769@@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57770 {
57771 #ifdef CONFIG_CIFS_STATS
57772 seq_printf(m, " Oplocks breaks: %d",
57773- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57774+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57775 seq_printf(m, "\nReads: %d Bytes: %llu",
57776- atomic_read(&tcon->stats.cifs_stats.num_reads),
57777+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57778 (long long)(tcon->bytes_read));
57779 seq_printf(m, "\nWrites: %d Bytes: %llu",
57780- atomic_read(&tcon->stats.cifs_stats.num_writes),
57781+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57782 (long long)(tcon->bytes_written));
57783 seq_printf(m, "\nFlushes: %d",
57784- atomic_read(&tcon->stats.cifs_stats.num_flushes));
57785+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57786 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57787- atomic_read(&tcon->stats.cifs_stats.num_locks),
57788- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57789- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57790+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57791+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57792+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57793 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57794- atomic_read(&tcon->stats.cifs_stats.num_opens),
57795- atomic_read(&tcon->stats.cifs_stats.num_closes),
57796- atomic_read(&tcon->stats.cifs_stats.num_deletes));
57797+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57798+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57799+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57800 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57801- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57802- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57803+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57804+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57805 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57806- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57807- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57808+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57809+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57810 seq_printf(m, "\nRenames: %d T2 Renames %d",
57811- atomic_read(&tcon->stats.cifs_stats.num_renames),
57812- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57813+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57814+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57815 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57816- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57817- atomic_read(&tcon->stats.cifs_stats.num_fnext),
57818- atomic_read(&tcon->stats.cifs_stats.num_fclose));
57819+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57820+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57821+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57822 #endif
57823 }
57824
57825diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57826index 35ddc3e..563e809 100644
57827--- a/fs/cifs/smb2ops.c
57828+++ b/fs/cifs/smb2ops.c
57829@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57830 #ifdef CONFIG_CIFS_STATS
57831 int i;
57832 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57833- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57834- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57835+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57836+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57837 }
57838 #endif
57839 }
57840@@ -405,65 +405,65 @@ static void
57841 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57842 {
57843 #ifdef CONFIG_CIFS_STATS
57844- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57845- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57846+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57847+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57848 seq_printf(m, "\nNegotiates: %d sent %d failed",
57849- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57850- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57851+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57852+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57853 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57854- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57855- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57856+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57857+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57858 seq_printf(m, "\nLogoffs: %d sent %d failed",
57859- atomic_read(&sent[SMB2_LOGOFF_HE]),
57860- atomic_read(&failed[SMB2_LOGOFF_HE]));
57861+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57862+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57863 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57864- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57865- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57866+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57867+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57868 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57869- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57870- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57871+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57872+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57873 seq_printf(m, "\nCreates: %d sent %d failed",
57874- atomic_read(&sent[SMB2_CREATE_HE]),
57875- atomic_read(&failed[SMB2_CREATE_HE]));
57876+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57877+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57878 seq_printf(m, "\nCloses: %d sent %d failed",
57879- atomic_read(&sent[SMB2_CLOSE_HE]),
57880- atomic_read(&failed[SMB2_CLOSE_HE]));
57881+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57882+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57883 seq_printf(m, "\nFlushes: %d sent %d failed",
57884- atomic_read(&sent[SMB2_FLUSH_HE]),
57885- atomic_read(&failed[SMB2_FLUSH_HE]));
57886+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57887+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57888 seq_printf(m, "\nReads: %d sent %d failed",
57889- atomic_read(&sent[SMB2_READ_HE]),
57890- atomic_read(&failed[SMB2_READ_HE]));
57891+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
57892+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
57893 seq_printf(m, "\nWrites: %d sent %d failed",
57894- atomic_read(&sent[SMB2_WRITE_HE]),
57895- atomic_read(&failed[SMB2_WRITE_HE]));
57896+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57897+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57898 seq_printf(m, "\nLocks: %d sent %d failed",
57899- atomic_read(&sent[SMB2_LOCK_HE]),
57900- atomic_read(&failed[SMB2_LOCK_HE]));
57901+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57902+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57903 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57904- atomic_read(&sent[SMB2_IOCTL_HE]),
57905- atomic_read(&failed[SMB2_IOCTL_HE]));
57906+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57907+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57908 seq_printf(m, "\nCancels: %d sent %d failed",
57909- atomic_read(&sent[SMB2_CANCEL_HE]),
57910- atomic_read(&failed[SMB2_CANCEL_HE]));
57911+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57912+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57913 seq_printf(m, "\nEchos: %d sent %d failed",
57914- atomic_read(&sent[SMB2_ECHO_HE]),
57915- atomic_read(&failed[SMB2_ECHO_HE]));
57916+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57917+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57918 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57919- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57920- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57921+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57922+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57923 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57924- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57925- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57926+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57927+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57928 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57929- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57930- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57931+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57932+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57933 seq_printf(m, "\nSetInfos: %d sent %d failed",
57934- atomic_read(&sent[SMB2_SET_INFO_HE]),
57935- atomic_read(&failed[SMB2_SET_INFO_HE]));
57936+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57937+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57938 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57939- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57940- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57941+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57942+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57943 #endif
57944 }
57945
57946diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57947index 1fb6ad2..758e171 100644
57948--- a/fs/cifs/smb2pdu.c
57949+++ b/fs/cifs/smb2pdu.c
57950@@ -2097,8 +2097,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57951 default:
57952 cifs_dbg(VFS, "info level %u isn't supported\n",
57953 srch_inf->info_level);
57954- rc = -EINVAL;
57955- goto qdir_exit;
57956+ return -EINVAL;
57957 }
57958
57959 req->FileIndex = cpu_to_le32(index);
57960diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57961index 1da168c..8bc7ff6 100644
57962--- a/fs/coda/cache.c
57963+++ b/fs/coda/cache.c
57964@@ -24,7 +24,7 @@
57965 #include "coda_linux.h"
57966 #include "coda_cache.h"
57967
57968-static atomic_t permission_epoch = ATOMIC_INIT(0);
57969+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57970
57971 /* replace or extend an acl cache hit */
57972 void coda_cache_enter(struct inode *inode, int mask)
57973@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57974 struct coda_inode_info *cii = ITOC(inode);
57975
57976 spin_lock(&cii->c_lock);
57977- cii->c_cached_epoch = atomic_read(&permission_epoch);
57978+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57979 if (!uid_eq(cii->c_uid, current_fsuid())) {
57980 cii->c_uid = current_fsuid();
57981 cii->c_cached_perm = mask;
57982@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57983 {
57984 struct coda_inode_info *cii = ITOC(inode);
57985 spin_lock(&cii->c_lock);
57986- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57987+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57988 spin_unlock(&cii->c_lock);
57989 }
57990
57991 /* remove all acl caches */
57992 void coda_cache_clear_all(struct super_block *sb)
57993 {
57994- atomic_inc(&permission_epoch);
57995+ atomic_inc_unchecked(&permission_epoch);
57996 }
57997
57998
57999@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58000 spin_lock(&cii->c_lock);
58001 hit = (mask & cii->c_cached_perm) == mask &&
58002 uid_eq(cii->c_uid, current_fsuid()) &&
58003- cii->c_cached_epoch == atomic_read(&permission_epoch);
58004+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58005 spin_unlock(&cii->c_lock);
58006
58007 return hit;
58008diff --git a/fs/compat.c b/fs/compat.c
58009index 66d3d3c..9c10175 100644
58010--- a/fs/compat.c
58011+++ b/fs/compat.c
58012@@ -54,7 +54,7 @@
58013 #include <asm/ioctls.h>
58014 #include "internal.h"
58015
58016-int compat_log = 1;
58017+int compat_log = 0;
58018
58019 int compat_printk(const char *fmt, ...)
58020 {
58021@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
58022
58023 set_fs(KERNEL_DS);
58024 /* The __user pointer cast is valid because of the set_fs() */
58025- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58026+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58027 set_fs(oldfs);
58028 /* truncating is ok because it's a user address */
58029 if (!ret)
58030@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58031 goto out;
58032
58033 ret = -EINVAL;
58034- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58035+ if (nr_segs > UIO_MAXIOV)
58036 goto out;
58037 if (nr_segs > fast_segs) {
58038 ret = -ENOMEM;
58039@@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
58040 struct compat_readdir_callback {
58041 struct dir_context ctx;
58042 struct compat_old_linux_dirent __user *dirent;
58043+ struct file * file;
58044 int result;
58045 };
58046
58047@@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58048 buf->result = -EOVERFLOW;
58049 return -EOVERFLOW;
58050 }
58051+
58052+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58053+ return 0;
58054+
58055 buf->result++;
58056 dirent = buf->dirent;
58057 if (!access_ok(VERIFY_WRITE, dirent,
58058@@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58059 if (!f.file)
58060 return -EBADF;
58061
58062+ buf.file = f.file;
58063 error = iterate_dir(f.file, &buf.ctx);
58064 if (buf.result)
58065 error = buf.result;
58066@@ -917,6 +923,7 @@ struct compat_getdents_callback {
58067 struct dir_context ctx;
58068 struct compat_linux_dirent __user *current_dir;
58069 struct compat_linux_dirent __user *previous;
58070+ struct file * file;
58071 int count;
58072 int error;
58073 };
58074@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58075 buf->error = -EOVERFLOW;
58076 return -EOVERFLOW;
58077 }
58078+
58079+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58080+ return 0;
58081+
58082 dirent = buf->previous;
58083 if (dirent) {
58084 if (__put_user(offset, &dirent->d_off))
58085@@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58086 if (!f.file)
58087 return -EBADF;
58088
58089+ buf.file = f.file;
58090 error = iterate_dir(f.file, &buf.ctx);
58091 if (error >= 0)
58092 error = buf.error;
58093@@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58094 struct dir_context ctx;
58095 struct linux_dirent64 __user *current_dir;
58096 struct linux_dirent64 __user *previous;
58097+ struct file * file;
58098 int count;
58099 int error;
58100 };
58101@@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58102 buf->error = -EINVAL; /* only used if we fail.. */
58103 if (reclen > buf->count)
58104 return -EINVAL;
58105+
58106+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58107+ return 0;
58108+
58109 dirent = buf->previous;
58110
58111 if (dirent) {
58112@@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58113 if (!f.file)
58114 return -EBADF;
58115
58116+ buf.file = f.file;
58117 error = iterate_dir(f.file, &buf.ctx);
58118 if (error >= 0)
58119 error = buf.error;
58120diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58121index 4d24d17..4f8c09e 100644
58122--- a/fs/compat_binfmt_elf.c
58123+++ b/fs/compat_binfmt_elf.c
58124@@ -30,11 +30,13 @@
58125 #undef elf_phdr
58126 #undef elf_shdr
58127 #undef elf_note
58128+#undef elf_dyn
58129 #undef elf_addr_t
58130 #define elfhdr elf32_hdr
58131 #define elf_phdr elf32_phdr
58132 #define elf_shdr elf32_shdr
58133 #define elf_note elf32_note
58134+#define elf_dyn Elf32_Dyn
58135 #define elf_addr_t Elf32_Addr
58136
58137 /*
58138diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58139index e822890..59374d5 100644
58140--- a/fs/compat_ioctl.c
58141+++ b/fs/compat_ioctl.c
58142@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58143 return -EFAULT;
58144 if (__get_user(udata, &ss32->iomem_base))
58145 return -EFAULT;
58146- ss.iomem_base = compat_ptr(udata);
58147+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58148 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58149 __get_user(ss.port_high, &ss32->port_high))
58150 return -EFAULT;
58151@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58152 for (i = 0; i < nmsgs; i++) {
58153 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58154 return -EFAULT;
58155- if (get_user(datap, &umsgs[i].buf) ||
58156- put_user(compat_ptr(datap), &tmsgs[i].buf))
58157+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58158+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58159 return -EFAULT;
58160 }
58161 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58162@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58163 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58164 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58165 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58166- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58167+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58168 return -EFAULT;
58169
58170 return ioctl_preallocate(file, p);
58171@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58172 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58173 {
58174 unsigned int a, b;
58175- a = *(unsigned int *)p;
58176- b = *(unsigned int *)q;
58177+ a = *(const unsigned int *)p;
58178+ b = *(const unsigned int *)q;
58179 if (a > b)
58180 return 1;
58181 if (a < b)
58182diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58183index e081acb..911df21 100644
58184--- a/fs/configfs/dir.c
58185+++ b/fs/configfs/dir.c
58186@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58187 }
58188 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58189 struct configfs_dirent *next;
58190- const char *name;
58191+ const unsigned char * name;
58192+ char d_name[sizeof(next->s_dentry->d_iname)];
58193 int len;
58194 struct inode *inode = NULL;
58195
58196@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58197 continue;
58198
58199 name = configfs_get_name(next);
58200- len = strlen(name);
58201+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58202+ len = next->s_dentry->d_name.len;
58203+ memcpy(d_name, name, len);
58204+ name = d_name;
58205+ } else
58206+ len = strlen(name);
58207
58208 /*
58209 * We'll have a dentry and an inode for
58210diff --git a/fs/coredump.c b/fs/coredump.c
58211index 0b2528f..836c55f 100644
58212--- a/fs/coredump.c
58213+++ b/fs/coredump.c
58214@@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58215 struct pipe_inode_info *pipe = file->private_data;
58216
58217 pipe_lock(pipe);
58218- pipe->readers++;
58219- pipe->writers--;
58220+ atomic_inc(&pipe->readers);
58221+ atomic_dec(&pipe->writers);
58222 wake_up_interruptible_sync(&pipe->wait);
58223 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58224 pipe_unlock(pipe);
58225@@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58226 * We actually want wait_event_freezable() but then we need
58227 * to clear TIF_SIGPENDING and improve dump_interrupted().
58228 */
58229- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58230+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58231
58232 pipe_lock(pipe);
58233- pipe->readers--;
58234- pipe->writers++;
58235+ atomic_dec(&pipe->readers);
58236+ atomic_inc(&pipe->writers);
58237 pipe_unlock(pipe);
58238 }
58239
58240@@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58241 struct files_struct *displaced;
58242 bool need_nonrelative = false;
58243 bool core_dumped = false;
58244- static atomic_t core_dump_count = ATOMIC_INIT(0);
58245+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58246+ long signr = siginfo->si_signo;
58247+ int dumpable;
58248 struct coredump_params cprm = {
58249 .siginfo = siginfo,
58250 .regs = signal_pt_regs(),
58251@@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58252 .mm_flags = mm->flags,
58253 };
58254
58255- audit_core_dumps(siginfo->si_signo);
58256+ audit_core_dumps(signr);
58257+
58258+ dumpable = __get_dumpable(cprm.mm_flags);
58259+
58260+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58261+ gr_handle_brute_attach(dumpable);
58262
58263 binfmt = mm->binfmt;
58264 if (!binfmt || !binfmt->core_dump)
58265 goto fail;
58266- if (!__get_dumpable(cprm.mm_flags))
58267+ if (!dumpable)
58268 goto fail;
58269
58270 cred = prepare_creds();
58271@@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58272 need_nonrelative = true;
58273 }
58274
58275- retval = coredump_wait(siginfo->si_signo, &core_state);
58276+ retval = coredump_wait(signr, &core_state);
58277 if (retval < 0)
58278 goto fail_creds;
58279
58280@@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58281 }
58282 cprm.limit = RLIM_INFINITY;
58283
58284- dump_count = atomic_inc_return(&core_dump_count);
58285+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58286 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58287 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58288 task_tgid_vnr(current), current->comm);
58289@@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58290 } else {
58291 struct inode *inode;
58292
58293+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58294+
58295 if (cprm.limit < binfmt->min_coredump)
58296 goto fail_unlock;
58297
58298@@ -673,7 +682,7 @@ close_fail:
58299 filp_close(cprm.file, NULL);
58300 fail_dropcount:
58301 if (ispipe)
58302- atomic_dec(&core_dump_count);
58303+ atomic_dec_unchecked(&core_dump_count);
58304 fail_unlock:
58305 kfree(cn.corename);
58306 coredump_finish(mm, core_dumped);
58307@@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58308 struct file *file = cprm->file;
58309 loff_t pos = file->f_pos;
58310 ssize_t n;
58311+
58312+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58313 if (cprm->written + nr > cprm->limit)
58314 return 0;
58315 while (nr) {
58316diff --git a/fs/dcache.c b/fs/dcache.c
58317index e99c6f5..2838bf58 100644
58318--- a/fs/dcache.c
58319+++ b/fs/dcache.c
58320@@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58321 */
58322 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58323 if (name->len > DNAME_INLINE_LEN-1) {
58324- dname = kmalloc(name->len + 1, GFP_KERNEL);
58325+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58326 if (!dname) {
58327 kmem_cache_free(dentry_cache, dentry);
58328 return NULL;
58329@@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58330 mempages -= reserve;
58331
58332 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58333- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58334+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58335+ SLAB_NO_SANITIZE, NULL);
58336
58337 dcache_init();
58338 inode_init();
58339diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58340index 8c41b52..145b1b9 100644
58341--- a/fs/debugfs/inode.c
58342+++ b/fs/debugfs/inode.c
58343@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58344 */
58345 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58346 {
58347+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58348+ return __create_file(name, S_IFDIR | S_IRWXU,
58349+#else
58350 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58351+#endif
58352 parent, NULL, NULL);
58353 }
58354 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58355diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58356index d4a9431..77f9b2e 100644
58357--- a/fs/ecryptfs/inode.c
58358+++ b/fs/ecryptfs/inode.c
58359@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58360 old_fs = get_fs();
58361 set_fs(get_ds());
58362 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58363- (char __user *)lower_buf,
58364+ (char __force_user *)lower_buf,
58365 PATH_MAX);
58366 set_fs(old_fs);
58367 if (rc < 0)
58368diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58369index e4141f2..d8263e8 100644
58370--- a/fs/ecryptfs/miscdev.c
58371+++ b/fs/ecryptfs/miscdev.c
58372@@ -304,7 +304,7 @@ check_list:
58373 goto out_unlock_msg_ctx;
58374 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58375 if (msg_ctx->msg) {
58376- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58377+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58378 goto out_unlock_msg_ctx;
58379 i += packet_length_size;
58380 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58381diff --git a/fs/exec.c b/fs/exec.c
58382index 238b7aa..a421d91 100644
58383--- a/fs/exec.c
58384+++ b/fs/exec.c
58385@@ -56,8 +56,20 @@
58386 #include <linux/pipe_fs_i.h>
58387 #include <linux/oom.h>
58388 #include <linux/compat.h>
58389+#include <linux/random.h>
58390+#include <linux/seq_file.h>
58391+#include <linux/coredump.h>
58392+#include <linux/mman.h>
58393+
58394+#ifdef CONFIG_PAX_REFCOUNT
58395+#include <linux/kallsyms.h>
58396+#include <linux/kdebug.h>
58397+#endif
58398+
58399+#include <trace/events/fs.h>
58400
58401 #include <asm/uaccess.h>
58402+#include <asm/sections.h>
58403 #include <asm/mmu_context.h>
58404 #include <asm/tlb.h>
58405
58406@@ -66,19 +78,34 @@
58407
58408 #include <trace/events/sched.h>
58409
58410+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58411+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58412+{
58413+ 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");
58414+}
58415+#endif
58416+
58417+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58418+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58419+EXPORT_SYMBOL(pax_set_initial_flags_func);
58420+#endif
58421+
58422 int suid_dumpable = 0;
58423
58424 static LIST_HEAD(formats);
58425 static DEFINE_RWLOCK(binfmt_lock);
58426
58427+extern int gr_process_kernel_exec_ban(void);
58428+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58429+
58430 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58431 {
58432 BUG_ON(!fmt);
58433 if (WARN_ON(!fmt->load_binary))
58434 return;
58435 write_lock(&binfmt_lock);
58436- insert ? list_add(&fmt->lh, &formats) :
58437- list_add_tail(&fmt->lh, &formats);
58438+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58439+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58440 write_unlock(&binfmt_lock);
58441 }
58442
58443@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58444 void unregister_binfmt(struct linux_binfmt * fmt)
58445 {
58446 write_lock(&binfmt_lock);
58447- list_del(&fmt->lh);
58448+ pax_list_del((struct list_head *)&fmt->lh);
58449 write_unlock(&binfmt_lock);
58450 }
58451
58452@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58453 int write)
58454 {
58455 struct page *page;
58456- int ret;
58457
58458-#ifdef CONFIG_STACK_GROWSUP
58459- if (write) {
58460- ret = expand_downwards(bprm->vma, pos);
58461- if (ret < 0)
58462- return NULL;
58463- }
58464-#endif
58465- ret = get_user_pages(current, bprm->mm, pos,
58466- 1, write, 1, &page, NULL);
58467- if (ret <= 0)
58468+ if (0 > expand_downwards(bprm->vma, pos))
58469+ return NULL;
58470+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58471 return NULL;
58472
58473 if (write) {
58474@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58475 if (size <= ARG_MAX)
58476 return page;
58477
58478+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58479+ // only allow 512KB for argv+env on suid/sgid binaries
58480+ // to prevent easy ASLR exhaustion
58481+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58482+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58483+ (size > (512 * 1024))) {
58484+ put_page(page);
58485+ return NULL;
58486+ }
58487+#endif
58488+
58489 /*
58490 * Limit to 1/4-th the stack size for the argv+env strings.
58491 * This ensures that:
58492@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58493 vma->vm_end = STACK_TOP_MAX;
58494 vma->vm_start = vma->vm_end - PAGE_SIZE;
58495 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58496+
58497+#ifdef CONFIG_PAX_SEGMEXEC
58498+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58499+#endif
58500+
58501 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58502 INIT_LIST_HEAD(&vma->anon_vma_chain);
58503
58504@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58505 mm->stack_vm = mm->total_vm = 1;
58506 up_write(&mm->mmap_sem);
58507 bprm->p = vma->vm_end - sizeof(void *);
58508+
58509+#ifdef CONFIG_PAX_RANDUSTACK
58510+ if (randomize_va_space)
58511+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58512+#endif
58513+
58514 return 0;
58515 err:
58516 up_write(&mm->mmap_sem);
58517@@ -399,7 +440,7 @@ struct user_arg_ptr {
58518 } ptr;
58519 };
58520
58521-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58522+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58523 {
58524 const char __user *native;
58525
58526@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58527 compat_uptr_t compat;
58528
58529 if (get_user(compat, argv.ptr.compat + nr))
58530- return ERR_PTR(-EFAULT);
58531+ return (const char __force_user *)ERR_PTR(-EFAULT);
58532
58533 return compat_ptr(compat);
58534 }
58535 #endif
58536
58537 if (get_user(native, argv.ptr.native + nr))
58538- return ERR_PTR(-EFAULT);
58539+ return (const char __force_user *)ERR_PTR(-EFAULT);
58540
58541 return native;
58542 }
58543@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
58544 if (!p)
58545 break;
58546
58547- if (IS_ERR(p))
58548+ if (IS_ERR((const char __force_kernel *)p))
58549 return -EFAULT;
58550
58551 if (i >= max)
58552@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58553
58554 ret = -EFAULT;
58555 str = get_user_arg_ptr(argv, argc);
58556- if (IS_ERR(str))
58557+ if (IS_ERR((const char __force_kernel *)str))
58558 goto out;
58559
58560 len = strnlen_user(str, MAX_ARG_STRLEN);
58561@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58562 int r;
58563 mm_segment_t oldfs = get_fs();
58564 struct user_arg_ptr argv = {
58565- .ptr.native = (const char __user *const __user *)__argv,
58566+ .ptr.native = (const char __user * const __force_user *)__argv,
58567 };
58568
58569 set_fs(KERNEL_DS);
58570@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58571 unsigned long new_end = old_end - shift;
58572 struct mmu_gather tlb;
58573
58574- BUG_ON(new_start > new_end);
58575+ if (new_start >= new_end || new_start < mmap_min_addr)
58576+ return -ENOMEM;
58577
58578 /*
58579 * ensure there are no vmas between where we want to go
58580@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58581 if (vma != find_vma(mm, new_start))
58582 return -EFAULT;
58583
58584+#ifdef CONFIG_PAX_SEGMEXEC
58585+ BUG_ON(pax_find_mirror_vma(vma));
58586+#endif
58587+
58588 /*
58589 * cover the whole range: [new_start, old_end)
58590 */
58591@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58592 stack_top = arch_align_stack(stack_top);
58593 stack_top = PAGE_ALIGN(stack_top);
58594
58595- if (unlikely(stack_top < mmap_min_addr) ||
58596- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58597- return -ENOMEM;
58598-
58599 stack_shift = vma->vm_end - stack_top;
58600
58601 bprm->p -= stack_shift;
58602@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58603 bprm->exec -= stack_shift;
58604
58605 down_write(&mm->mmap_sem);
58606+
58607+ /* Move stack pages down in memory. */
58608+ if (stack_shift) {
58609+ ret = shift_arg_pages(vma, stack_shift);
58610+ if (ret)
58611+ goto out_unlock;
58612+ }
58613+
58614 vm_flags = VM_STACK_FLAGS;
58615
58616+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58617+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58618+ vm_flags &= ~VM_EXEC;
58619+
58620+#ifdef CONFIG_PAX_MPROTECT
58621+ if (mm->pax_flags & MF_PAX_MPROTECT)
58622+ vm_flags &= ~VM_MAYEXEC;
58623+#endif
58624+
58625+ }
58626+#endif
58627+
58628 /*
58629 * Adjust stack execute permissions; explicitly enable for
58630 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58631@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58632 goto out_unlock;
58633 BUG_ON(prev != vma);
58634
58635- /* Move stack pages down in memory. */
58636- if (stack_shift) {
58637- ret = shift_arg_pages(vma, stack_shift);
58638- if (ret)
58639- goto out_unlock;
58640- }
58641-
58642 /* mprotect_fixup is overkill to remove the temporary stack flags */
58643 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58644
58645@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58646 #endif
58647 current->mm->start_stack = bprm->p;
58648 ret = expand_stack(vma, stack_base);
58649+
58650+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58651+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58652+ unsigned long size;
58653+ vm_flags_t vm_flags;
58654+
58655+ size = STACK_TOP - vma->vm_end;
58656+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58657+
58658+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58659+
58660+#ifdef CONFIG_X86
58661+ if (!ret) {
58662+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58663+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58664+ }
58665+#endif
58666+
58667+ }
58668+#endif
58669+
58670 if (ret)
58671 ret = -EFAULT;
58672
58673@@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
58674
58675 fsnotify_open(file);
58676
58677+ trace_open_exec(name->name);
58678+
58679 err = deny_write_access(file);
58680 if (err)
58681 goto exit;
58682@@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
58683 old_fs = get_fs();
58684 set_fs(get_ds());
58685 /* The cast to a user pointer is valid due to the set_fs() */
58686- result = vfs_read(file, (void __user *)addr, count, &pos);
58687+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
58688 set_fs(old_fs);
58689 return result;
58690 }
58691@@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
58692 tsk->mm = mm;
58693 tsk->active_mm = mm;
58694 activate_mm(active_mm, mm);
58695+ populate_stack();
58696 tsk->mm->vmacache_seqnum = 0;
58697 vmacache_flush(tsk);
58698 task_unlock(tsk);
58699@@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58700 }
58701 rcu_read_unlock();
58702
58703- if (p->fs->users > n_fs)
58704+ if (atomic_read(&p->fs->users) > n_fs)
58705 bprm->unsafe |= LSM_UNSAFE_SHARE;
58706 else
58707 p->fs->in_exec = 1;
58708@@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58709 return ret;
58710 }
58711
58712+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58713+static DEFINE_PER_CPU(u64, exec_counter);
58714+static int __init init_exec_counters(void)
58715+{
58716+ unsigned int cpu;
58717+
58718+ for_each_possible_cpu(cpu) {
58719+ per_cpu(exec_counter, cpu) = (u64)cpu;
58720+ }
58721+
58722+ return 0;
58723+}
58724+early_initcall(init_exec_counters);
58725+static inline void increment_exec_counter(void)
58726+{
58727+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
58728+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58729+}
58730+#else
58731+static inline void increment_exec_counter(void) {}
58732+#endif
58733+
58734+extern void gr_handle_exec_args(struct linux_binprm *bprm,
58735+ struct user_arg_ptr argv);
58736+
58737 /*
58738 * sys_execve() executes a new program.
58739 */
58740@@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
58741 struct user_arg_ptr argv,
58742 struct user_arg_ptr envp)
58743 {
58744+#ifdef CONFIG_GRKERNSEC
58745+ struct file *old_exec_file;
58746+ struct acl_subject_label *old_acl;
58747+ struct rlimit old_rlim[RLIM_NLIMITS];
58748+#endif
58749 struct linux_binprm *bprm;
58750 struct file *file;
58751 struct files_struct *displaced;
58752@@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
58753 if (IS_ERR(filename))
58754 return PTR_ERR(filename);
58755
58756+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58757+
58758 /*
58759 * We move the actual failure in case of RLIMIT_NPROC excess from
58760 * set*uid() to execve() because too many poorly written programs
58761@@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
58762 if (IS_ERR(file))
58763 goto out_unmark;
58764
58765+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
58766+ retval = -EPERM;
58767+ goto out_unmark;
58768+ }
58769+
58770 sched_exec();
58771
58772 bprm->file = file;
58773 bprm->filename = bprm->interp = filename->name;
58774
58775+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58776+ retval = -EACCES;
58777+ goto out_unmark;
58778+ }
58779+
58780 retval = bprm_mm_init(bprm);
58781 if (retval)
58782 goto out_unmark;
58783@@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
58784 if (retval < 0)
58785 goto out;
58786
58787+#ifdef CONFIG_GRKERNSEC
58788+ old_acl = current->acl;
58789+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58790+ old_exec_file = current->exec_file;
58791+ get_file(file);
58792+ current->exec_file = file;
58793+#endif
58794+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58795+ /* limit suid stack to 8MB
58796+ * we saved the old limits above and will restore them if this exec fails
58797+ */
58798+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58799+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58800+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58801+#endif
58802+
58803+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58804+ retval = -EPERM;
58805+ goto out_fail;
58806+ }
58807+
58808+ if (!gr_tpe_allow(file)) {
58809+ retval = -EACCES;
58810+ goto out_fail;
58811+ }
58812+
58813+ if (gr_check_crash_exec(file)) {
58814+ retval = -EACCES;
58815+ goto out_fail;
58816+ }
58817+
58818+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58819+ bprm->unsafe);
58820+ if (retval < 0)
58821+ goto out_fail;
58822+
58823 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58824 if (retval < 0)
58825- goto out;
58826+ goto out_fail;
58827
58828 bprm->exec = bprm->p;
58829 retval = copy_strings(bprm->envc, envp, bprm);
58830 if (retval < 0)
58831- goto out;
58832+ goto out_fail;
58833
58834 retval = copy_strings(bprm->argc, argv, bprm);
58835 if (retval < 0)
58836- goto out;
58837+ goto out_fail;
58838+
58839+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58840+
58841+ gr_handle_exec_args(bprm, argv);
58842
58843 retval = exec_binprm(bprm);
58844 if (retval < 0)
58845- goto out;
58846+ goto out_fail;
58847+#ifdef CONFIG_GRKERNSEC
58848+ if (old_exec_file)
58849+ fput(old_exec_file);
58850+#endif
58851
58852 /* execve succeeded */
58853+
58854+ increment_exec_counter();
58855 current->fs->in_exec = 0;
58856 current->in_execve = 0;
58857 acct_update_integrals(current);
58858@@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
58859 put_files_struct(displaced);
58860 return retval;
58861
58862+out_fail:
58863+#ifdef CONFIG_GRKERNSEC
58864+ current->acl = old_acl;
58865+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58866+ fput(current->exec_file);
58867+ current->exec_file = old_exec_file;
58868+#endif
58869+
58870 out:
58871 if (bprm->mm) {
58872 acct_arg_size(bprm, 0);
58873@@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
58874 return compat_do_execve(getname(filename), argv, envp);
58875 }
58876 #endif
58877+
58878+int pax_check_flags(unsigned long *flags)
58879+{
58880+ int retval = 0;
58881+
58882+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58883+ if (*flags & MF_PAX_SEGMEXEC)
58884+ {
58885+ *flags &= ~MF_PAX_SEGMEXEC;
58886+ retval = -EINVAL;
58887+ }
58888+#endif
58889+
58890+ if ((*flags & MF_PAX_PAGEEXEC)
58891+
58892+#ifdef CONFIG_PAX_PAGEEXEC
58893+ && (*flags & MF_PAX_SEGMEXEC)
58894+#endif
58895+
58896+ )
58897+ {
58898+ *flags &= ~MF_PAX_PAGEEXEC;
58899+ retval = -EINVAL;
58900+ }
58901+
58902+ if ((*flags & MF_PAX_MPROTECT)
58903+
58904+#ifdef CONFIG_PAX_MPROTECT
58905+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58906+#endif
58907+
58908+ )
58909+ {
58910+ *flags &= ~MF_PAX_MPROTECT;
58911+ retval = -EINVAL;
58912+ }
58913+
58914+ if ((*flags & MF_PAX_EMUTRAMP)
58915+
58916+#ifdef CONFIG_PAX_EMUTRAMP
58917+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58918+#endif
58919+
58920+ )
58921+ {
58922+ *flags &= ~MF_PAX_EMUTRAMP;
58923+ retval = -EINVAL;
58924+ }
58925+
58926+ return retval;
58927+}
58928+
58929+EXPORT_SYMBOL(pax_check_flags);
58930+
58931+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58932+char *pax_get_path(const struct path *path, char *buf, int buflen)
58933+{
58934+ char *pathname = d_path(path, buf, buflen);
58935+
58936+ if (IS_ERR(pathname))
58937+ goto toolong;
58938+
58939+ pathname = mangle_path(buf, pathname, "\t\n\\");
58940+ if (!pathname)
58941+ goto toolong;
58942+
58943+ *pathname = 0;
58944+ return buf;
58945+
58946+toolong:
58947+ return "<path too long>";
58948+}
58949+EXPORT_SYMBOL(pax_get_path);
58950+
58951+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58952+{
58953+ struct task_struct *tsk = current;
58954+ struct mm_struct *mm = current->mm;
58955+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58956+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58957+ char *path_exec = NULL;
58958+ char *path_fault = NULL;
58959+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
58960+ siginfo_t info = { };
58961+
58962+ if (buffer_exec && buffer_fault) {
58963+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58964+
58965+ down_read(&mm->mmap_sem);
58966+ vma = mm->mmap;
58967+ while (vma && (!vma_exec || !vma_fault)) {
58968+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58969+ vma_exec = vma;
58970+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58971+ vma_fault = vma;
58972+ vma = vma->vm_next;
58973+ }
58974+ if (vma_exec)
58975+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58976+ if (vma_fault) {
58977+ start = vma_fault->vm_start;
58978+ end = vma_fault->vm_end;
58979+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58980+ if (vma_fault->vm_file)
58981+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58982+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58983+ path_fault = "<heap>";
58984+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58985+ path_fault = "<stack>";
58986+ else
58987+ path_fault = "<anonymous mapping>";
58988+ }
58989+ up_read(&mm->mmap_sem);
58990+ }
58991+ if (tsk->signal->curr_ip)
58992+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58993+ else
58994+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58995+ 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),
58996+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58997+ free_page((unsigned long)buffer_exec);
58998+ free_page((unsigned long)buffer_fault);
58999+ pax_report_insns(regs, pc, sp);
59000+ info.si_signo = SIGKILL;
59001+ info.si_errno = 0;
59002+ info.si_code = SI_KERNEL;
59003+ info.si_pid = 0;
59004+ info.si_uid = 0;
59005+ do_coredump(&info);
59006+}
59007+#endif
59008+
59009+#ifdef CONFIG_PAX_REFCOUNT
59010+void pax_report_refcount_overflow(struct pt_regs *regs)
59011+{
59012+ if (current->signal->curr_ip)
59013+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59014+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59015+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59016+ else
59017+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59018+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59019+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59020+ preempt_disable();
59021+ show_regs(regs);
59022+ preempt_enable();
59023+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59024+}
59025+#endif
59026+
59027+#ifdef CONFIG_PAX_USERCOPY
59028+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59029+static noinline int check_stack_object(const void *obj, unsigned long len)
59030+{
59031+ const void * const stack = task_stack_page(current);
59032+ const void * const stackend = stack + THREAD_SIZE;
59033+
59034+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59035+ const void *frame = NULL;
59036+ const void *oldframe;
59037+#endif
59038+
59039+ if (obj + len < obj)
59040+ return -1;
59041+
59042+ if (obj + len <= stack || stackend <= obj)
59043+ return 0;
59044+
59045+ if (obj < stack || stackend < obj + len)
59046+ return -1;
59047+
59048+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59049+ oldframe = __builtin_frame_address(1);
59050+ if (oldframe)
59051+ frame = __builtin_frame_address(2);
59052+ /*
59053+ low ----------------------------------------------> high
59054+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59055+ ^----------------^
59056+ allow copies only within here
59057+ */
59058+ while (stack <= frame && frame < stackend) {
59059+ /* if obj + len extends past the last frame, this
59060+ check won't pass and the next frame will be 0,
59061+ causing us to bail out and correctly report
59062+ the copy as invalid
59063+ */
59064+ if (obj + len <= frame)
59065+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59066+ oldframe = frame;
59067+ frame = *(const void * const *)frame;
59068+ }
59069+ return -1;
59070+#else
59071+ return 1;
59072+#endif
59073+}
59074+
59075+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59076+{
59077+ if (current->signal->curr_ip)
59078+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59079+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59080+ else
59081+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59082+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59083+ dump_stack();
59084+ gr_handle_kernel_exploit();
59085+ do_group_exit(SIGKILL);
59086+}
59087+#endif
59088+
59089+#ifdef CONFIG_PAX_USERCOPY
59090+
59091+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59092+{
59093+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59094+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59095+#ifdef CONFIG_MODULES
59096+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59097+#else
59098+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59099+#endif
59100+
59101+#else
59102+ unsigned long textlow = (unsigned long)_stext;
59103+ unsigned long texthigh = (unsigned long)_etext;
59104+
59105+#ifdef CONFIG_X86_64
59106+ /* check against linear mapping as well */
59107+ if (high > (unsigned long)__va(__pa(textlow)) &&
59108+ low < (unsigned long)__va(__pa(texthigh)))
59109+ return true;
59110+#endif
59111+
59112+#endif
59113+
59114+ if (high <= textlow || low >= texthigh)
59115+ return false;
59116+ else
59117+ return true;
59118+}
59119+#endif
59120+
59121+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59122+{
59123+#ifdef CONFIG_PAX_USERCOPY
59124+ const char *type;
59125+#endif
59126+
59127+#ifndef CONFIG_STACK_GROWSUP
59128+ unsigned long stackstart = (unsigned long)task_stack_page(current);
59129+ unsigned long currentsp = (unsigned long)&stackstart;
59130+ if (unlikely((currentsp < stackstart + 512 ||
59131+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59132+ BUG();
59133+#endif
59134+
59135+#ifndef CONFIG_PAX_USERCOPY_DEBUG
59136+ if (const_size)
59137+ return;
59138+#endif
59139+
59140+#ifdef CONFIG_PAX_USERCOPY
59141+ if (!n)
59142+ return;
59143+
59144+ type = check_heap_object(ptr, n);
59145+ if (!type) {
59146+ int ret = check_stack_object(ptr, n);
59147+ if (ret == 1 || ret == 2)
59148+ return;
59149+ if (ret == 0) {
59150+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59151+ type = "<kernel text>";
59152+ else
59153+ return;
59154+ } else
59155+ type = "<process stack>";
59156+ }
59157+
59158+ pax_report_usercopy(ptr, n, to_user, type);
59159+#endif
59160+
59161+}
59162+EXPORT_SYMBOL(__check_object_size);
59163+
59164+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59165+void pax_track_stack(void)
59166+{
59167+ unsigned long sp = (unsigned long)&sp;
59168+ if (sp < current_thread_info()->lowest_stack &&
59169+ sp > (unsigned long)task_stack_page(current))
59170+ current_thread_info()->lowest_stack = sp;
59171+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59172+ BUG();
59173+}
59174+EXPORT_SYMBOL(pax_track_stack);
59175+#endif
59176+
59177+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59178+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59179+{
59180+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59181+ dump_stack();
59182+ do_group_exit(SIGKILL);
59183+}
59184+EXPORT_SYMBOL(report_size_overflow);
59185+#endif
59186diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59187index 9f9992b..8b59411 100644
59188--- a/fs/ext2/balloc.c
59189+++ b/fs/ext2/balloc.c
59190@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59191
59192 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59193 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59194- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59195+ if (free_blocks < root_blocks + 1 &&
59196 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59197 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59198- !in_group_p (sbi->s_resgid))) {
59199+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59200 return 0;
59201 }
59202 return 1;
59203diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59204index 9142614..97484fa 100644
59205--- a/fs/ext2/xattr.c
59206+++ b/fs/ext2/xattr.c
59207@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59208 struct buffer_head *bh = NULL;
59209 struct ext2_xattr_entry *entry;
59210 char *end;
59211- size_t rest = buffer_size;
59212+ size_t rest = buffer_size, total_size = 0;
59213 int error;
59214
59215 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59216@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59217 buffer += size;
59218 }
59219 rest -= size;
59220+ total_size += size;
59221 }
59222 }
59223- error = buffer_size - rest; /* total size */
59224+ error = total_size;
59225
59226 cleanup:
59227 brelse(bh);
59228diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59229index 158b5d4..2432610 100644
59230--- a/fs/ext3/balloc.c
59231+++ b/fs/ext3/balloc.c
59232@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59233
59234 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59235 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59236- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59237+ if (free_blocks < root_blocks + 1 &&
59238 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59239 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59240- !in_group_p (sbi->s_resgid))) {
59241+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59242 return 0;
59243 }
59244 return 1;
59245diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59246index c6874be..f8a6ae8 100644
59247--- a/fs/ext3/xattr.c
59248+++ b/fs/ext3/xattr.c
59249@@ -330,7 +330,7 @@ static int
59250 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59251 char *buffer, size_t buffer_size)
59252 {
59253- size_t rest = buffer_size;
59254+ size_t rest = buffer_size, total_size = 0;
59255
59256 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59257 const struct xattr_handler *handler =
59258@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59259 buffer += size;
59260 }
59261 rest -= size;
59262+ total_size += size;
59263 }
59264 }
59265- return buffer_size - rest;
59266+ return total_size;
59267 }
59268
59269 static int
59270diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59271index 5c56785..77698a2 100644
59272--- a/fs/ext4/balloc.c
59273+++ b/fs/ext4/balloc.c
59274@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59275 /* Hm, nope. Are (enough) root reserved clusters available? */
59276 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59277 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59278- capable(CAP_SYS_RESOURCE) ||
59279- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59280+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59281+ capable_nolog(CAP_SYS_RESOURCE)) {
59282
59283 if (free_clusters >= (nclusters + dirty_clusters +
59284 resv_clusters))
59285diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59286index f542e48..c0275f5 100644
59287--- a/fs/ext4/ext4.h
59288+++ b/fs/ext4/ext4.h
59289@@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59290 unsigned long s_mb_last_start;
59291
59292 /* stats for buddy allocator */
59293- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59294- atomic_t s_bal_success; /* we found long enough chunks */
59295- atomic_t s_bal_allocated; /* in blocks */
59296- atomic_t s_bal_ex_scanned; /* total extents scanned */
59297- atomic_t s_bal_goals; /* goal hits */
59298- atomic_t s_bal_breaks; /* too long searches */
59299- atomic_t s_bal_2orders; /* 2^order hits */
59300+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59301+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59302+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59303+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59304+ atomic_unchecked_t s_bal_goals; /* goal hits */
59305+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59306+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59307 spinlock_t s_bal_lock;
59308 unsigned long s_mb_buddies_generated;
59309 unsigned long long s_mb_generation_time;
59310- atomic_t s_mb_lost_chunks;
59311- atomic_t s_mb_preallocated;
59312- atomic_t s_mb_discarded;
59313+ atomic_unchecked_t s_mb_lost_chunks;
59314+ atomic_unchecked_t s_mb_preallocated;
59315+ atomic_unchecked_t s_mb_discarded;
59316 atomic_t s_lock_busy;
59317
59318 /* locality groups */
59319diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
59320index 594009f..c30cbe2 100644
59321--- a/fs/ext4/indirect.c
59322+++ b/fs/ext4/indirect.c
59323@@ -389,7 +389,13 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode,
59324 return 0;
59325 failed:
59326 for (; i >= 0; i--) {
59327- if (i != indirect_blks && branch[i].bh)
59328+ /*
59329+ * We want to ext4_forget() only freshly allocated indirect
59330+ * blocks. Buffer for new_blocks[i-1] is at branch[i].bh and
59331+ * buffer at branch[0].bh is indirect block / inode already
59332+ * existing before ext4_alloc_branch() was called.
59333+ */
59334+ if (i > 0 && i != indirect_blks && branch[i].bh)
59335 ext4_forget(handle, 1, inode, branch[i].bh,
59336 branch[i].bh->b_blocknr);
59337 ext4_free_blocks(handle, inode, NULL, new_blocks[i],
59338@@ -1312,16 +1318,24 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59339 blk = *i_data;
59340 if (level > 0) {
59341 ext4_lblk_t first2;
59342+ ext4_lblk_t count2;
59343+
59344 bh = sb_bread(inode->i_sb, le32_to_cpu(blk));
59345 if (!bh) {
59346 EXT4_ERROR_INODE_BLOCK(inode, le32_to_cpu(blk),
59347 "Read failure");
59348 return -EIO;
59349 }
59350- first2 = (first > offset) ? first - offset : 0;
59351+ if (first > offset) {
59352+ first2 = first - offset;
59353+ count2 = count;
59354+ } else {
59355+ first2 = 0;
59356+ count2 = count - (offset - first);
59357+ }
59358 ret = free_hole_blocks(handle, inode, bh,
59359 (__le32 *)bh->b_data, level - 1,
59360- first2, count - offset,
59361+ first2, count2,
59362 inode->i_sb->s_blocksize >> 2);
59363 if (ret) {
59364 brelse(bh);
59365@@ -1331,8 +1345,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59366 if (level == 0 ||
59367 (bh && all_zeroes((__le32 *)bh->b_data,
59368 (__le32 *)bh->b_data + addr_per_block))) {
59369- ext4_free_data(handle, inode, parent_bh, &blk, &blk+1);
59370- *i_data = 0;
59371+ ext4_free_data(handle, inode, parent_bh,
59372+ i_data, i_data + 1);
59373 }
59374 brelse(bh);
59375 bh = NULL;
59376diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59377index fe4e668..f983538 100644
59378--- a/fs/ext4/mballoc.c
59379+++ b/fs/ext4/mballoc.c
59380@@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59381 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59382
59383 if (EXT4_SB(sb)->s_mb_stats)
59384- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59385+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59386
59387 break;
59388 }
59389@@ -2199,7 +2199,7 @@ repeat:
59390 ac->ac_status = AC_STATUS_CONTINUE;
59391 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59392 cr = 3;
59393- atomic_inc(&sbi->s_mb_lost_chunks);
59394+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59395 goto repeat;
59396 }
59397 }
59398@@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59399 if (sbi->s_mb_stats) {
59400 ext4_msg(sb, KERN_INFO,
59401 "mballoc: %u blocks %u reqs (%u success)",
59402- atomic_read(&sbi->s_bal_allocated),
59403- atomic_read(&sbi->s_bal_reqs),
59404- atomic_read(&sbi->s_bal_success));
59405+ atomic_read_unchecked(&sbi->s_bal_allocated),
59406+ atomic_read_unchecked(&sbi->s_bal_reqs),
59407+ atomic_read_unchecked(&sbi->s_bal_success));
59408 ext4_msg(sb, KERN_INFO,
59409 "mballoc: %u extents scanned, %u goal hits, "
59410 "%u 2^N hits, %u breaks, %u lost",
59411- atomic_read(&sbi->s_bal_ex_scanned),
59412- atomic_read(&sbi->s_bal_goals),
59413- atomic_read(&sbi->s_bal_2orders),
59414- atomic_read(&sbi->s_bal_breaks),
59415- atomic_read(&sbi->s_mb_lost_chunks));
59416+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59417+ atomic_read_unchecked(&sbi->s_bal_goals),
59418+ atomic_read_unchecked(&sbi->s_bal_2orders),
59419+ atomic_read_unchecked(&sbi->s_bal_breaks),
59420+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59421 ext4_msg(sb, KERN_INFO,
59422 "mballoc: %lu generated and it took %Lu",
59423 sbi->s_mb_buddies_generated,
59424 sbi->s_mb_generation_time);
59425 ext4_msg(sb, KERN_INFO,
59426 "mballoc: %u preallocated, %u discarded",
59427- atomic_read(&sbi->s_mb_preallocated),
59428- atomic_read(&sbi->s_mb_discarded));
59429+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59430+ atomic_read_unchecked(&sbi->s_mb_discarded));
59431 }
59432
59433 free_percpu(sbi->s_locality_groups);
59434@@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59435 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59436
59437 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59438- atomic_inc(&sbi->s_bal_reqs);
59439- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59440+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59441+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59442 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59443- atomic_inc(&sbi->s_bal_success);
59444- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59445+ atomic_inc_unchecked(&sbi->s_bal_success);
59446+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59447 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59448 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59449- atomic_inc(&sbi->s_bal_goals);
59450+ atomic_inc_unchecked(&sbi->s_bal_goals);
59451 if (ac->ac_found > sbi->s_mb_max_to_scan)
59452- atomic_inc(&sbi->s_bal_breaks);
59453+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59454 }
59455
59456 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59457@@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59458 trace_ext4_mb_new_inode_pa(ac, pa);
59459
59460 ext4_mb_use_inode_pa(ac, pa);
59461- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59462+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59463
59464 ei = EXT4_I(ac->ac_inode);
59465 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59466@@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59467 trace_ext4_mb_new_group_pa(ac, pa);
59468
59469 ext4_mb_use_group_pa(ac, pa);
59470- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59471+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59472
59473 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59474 lg = ac->ac_lg;
59475@@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59476 * from the bitmap and continue.
59477 */
59478 }
59479- atomic_add(free, &sbi->s_mb_discarded);
59480+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59481
59482 return err;
59483 }
59484@@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59485 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59486 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59487 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59488- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59489+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59490 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59491
59492 return 0;
59493diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59494index 04434ad..6404663 100644
59495--- a/fs/ext4/mmp.c
59496+++ b/fs/ext4/mmp.c
59497@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59498 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59499 const char *function, unsigned int line, const char *msg)
59500 {
59501- __ext4_warning(sb, function, line, msg);
59502+ __ext4_warning(sb, function, line, "%s", msg);
59503 __ext4_warning(sb, function, line,
59504 "MMP failure info: last update time: %llu, last update "
59505 "node: %s, last update device: %s\n",
59506diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59507index 6f9e6fa..5431c02 100644
59508--- a/fs/ext4/super.c
59509+++ b/fs/ext4/super.c
59510@@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59511 }
59512
59513 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59514-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59515+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59516 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59517
59518 #ifdef CONFIG_QUOTA
59519@@ -2455,7 +2455,7 @@ struct ext4_attr {
59520 int offset;
59521 int deprecated_val;
59522 } u;
59523-};
59524+} __do_const;
59525
59526 static int parse_strtoull(const char *buf,
59527 unsigned long long max, unsigned long long *value)
59528diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59529index 4eec399..1d9444c 100644
59530--- a/fs/ext4/xattr.c
59531+++ b/fs/ext4/xattr.c
59532@@ -383,7 +383,7 @@ static int
59533 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59534 char *buffer, size_t buffer_size)
59535 {
59536- size_t rest = buffer_size;
59537+ size_t rest = buffer_size, total_size = 0;
59538
59539 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59540 const struct xattr_handler *handler =
59541@@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59542 buffer += size;
59543 }
59544 rest -= size;
59545+ total_size += size;
59546 }
59547 }
59548- return buffer_size - rest;
59549+ return total_size;
59550 }
59551
59552 static int
59553diff --git a/fs/fcntl.c b/fs/fcntl.c
59554index 72c82f6..a18b263 100644
59555--- a/fs/fcntl.c
59556+++ b/fs/fcntl.c
59557@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59558 if (err)
59559 return err;
59560
59561+ if (gr_handle_chroot_fowner(pid, type))
59562+ return -ENOENT;
59563+ if (gr_check_protected_task_fowner(pid, type))
59564+ return -EACCES;
59565+
59566 f_modown(filp, pid, type, force);
59567 return 0;
59568 }
59569diff --git a/fs/fhandle.c b/fs/fhandle.c
59570index 999ff5c..ac037c9 100644
59571--- a/fs/fhandle.c
59572+++ b/fs/fhandle.c
59573@@ -8,6 +8,7 @@
59574 #include <linux/fs_struct.h>
59575 #include <linux/fsnotify.h>
59576 #include <linux/personality.h>
59577+#include <linux/grsecurity.h>
59578 #include <asm/uaccess.h>
59579 #include "internal.h"
59580 #include "mount.h"
59581@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
59582 } else
59583 retval = 0;
59584 /* copy the mount id */
59585- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59586- sizeof(*mnt_id)) ||
59587+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59588 copy_to_user(ufh, handle,
59589 sizeof(struct file_handle) + handle_bytes))
59590 retval = -EFAULT;
59591@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
59592 * the directory. Ideally we would like CAP_DAC_SEARCH.
59593 * But we don't have that
59594 */
59595- if (!capable(CAP_DAC_READ_SEARCH)) {
59596+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
59597 retval = -EPERM;
59598 goto out_err;
59599 }
59600diff --git a/fs/file.c b/fs/file.c
59601index 8f294cf..d0f3872 100644
59602--- a/fs/file.c
59603+++ b/fs/file.c
59604@@ -16,6 +16,7 @@
59605 #include <linux/slab.h>
59606 #include <linux/vmalloc.h>
59607 #include <linux/file.h>
59608+#include <linux/security.h>
59609 #include <linux/fdtable.h>
59610 #include <linux/bitops.h>
59611 #include <linux/interrupt.h>
59612@@ -144,7 +145,7 @@ out:
59613 * Return <0 error code on error; 1 on successful completion.
59614 * The files->file_lock should be held on entry, and will be held on exit.
59615 */
59616-static int expand_fdtable(struct files_struct *files, int nr)
59617+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59618 __releases(files->file_lock)
59619 __acquires(files->file_lock)
59620 {
59621@@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59622 * expanded and execution may have blocked.
59623 * The files->file_lock should be held on entry, and will be held on exit.
59624 */
59625-static int expand_files(struct files_struct *files, int nr)
59626+static int expand_files(struct files_struct *files, unsigned int nr)
59627 {
59628 struct fdtable *fdt;
59629
59630@@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59631 if (!file)
59632 return __close_fd(files, fd);
59633
59634+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59635 if (fd >= rlimit(RLIMIT_NOFILE))
59636 return -EBADF;
59637
59638@@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59639 if (unlikely(oldfd == newfd))
59640 return -EINVAL;
59641
59642+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59643 if (newfd >= rlimit(RLIMIT_NOFILE))
59644 return -EBADF;
59645
59646@@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59647 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59648 {
59649 int err;
59650+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59651 if (from >= rlimit(RLIMIT_NOFILE))
59652 return -EINVAL;
59653 err = alloc_fd(from, flags);
59654diff --git a/fs/filesystems.c b/fs/filesystems.c
59655index 5797d45..7d7d79a 100644
59656--- a/fs/filesystems.c
59657+++ b/fs/filesystems.c
59658@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
59659 int len = dot ? dot - name : strlen(name);
59660
59661 fs = __get_fs_type(name, len);
59662+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59663+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59664+#else
59665 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59666+#endif
59667 fs = __get_fs_type(name, len);
59668
59669 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59670diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59671index 7dca743..543d620 100644
59672--- a/fs/fs_struct.c
59673+++ b/fs/fs_struct.c
59674@@ -4,6 +4,7 @@
59675 #include <linux/path.h>
59676 #include <linux/slab.h>
59677 #include <linux/fs_struct.h>
59678+#include <linux/grsecurity.h>
59679 #include "internal.h"
59680
59681 /*
59682@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59683 write_seqcount_begin(&fs->seq);
59684 old_root = fs->root;
59685 fs->root = *path;
59686+ gr_set_chroot_entries(current, path);
59687 write_seqcount_end(&fs->seq);
59688 spin_unlock(&fs->lock);
59689 if (old_root.dentry)
59690@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59691 int hits = 0;
59692 spin_lock(&fs->lock);
59693 write_seqcount_begin(&fs->seq);
59694+ /* this root replacement is only done by pivot_root,
59695+ leave grsec's chroot tagging alone for this task
59696+ so that a pivoted root isn't treated as a chroot
59697+ */
59698 hits += replace_path(&fs->root, old_root, new_root);
59699 hits += replace_path(&fs->pwd, old_root, new_root);
59700 write_seqcount_end(&fs->seq);
59701@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59702 task_lock(tsk);
59703 spin_lock(&fs->lock);
59704 tsk->fs = NULL;
59705- kill = !--fs->users;
59706+ gr_clear_chroot_entries(tsk);
59707+ kill = !atomic_dec_return(&fs->users);
59708 spin_unlock(&fs->lock);
59709 task_unlock(tsk);
59710 if (kill)
59711@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59712 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59713 /* We don't need to lock fs - think why ;-) */
59714 if (fs) {
59715- fs->users = 1;
59716+ atomic_set(&fs->users, 1);
59717 fs->in_exec = 0;
59718 spin_lock_init(&fs->lock);
59719 seqcount_init(&fs->seq);
59720@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59721 spin_lock(&old->lock);
59722 fs->root = old->root;
59723 path_get(&fs->root);
59724+ /* instead of calling gr_set_chroot_entries here,
59725+ we call it from every caller of this function
59726+ */
59727 fs->pwd = old->pwd;
59728 path_get(&fs->pwd);
59729 spin_unlock(&old->lock);
59730@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59731
59732 task_lock(current);
59733 spin_lock(&fs->lock);
59734- kill = !--fs->users;
59735+ kill = !atomic_dec_return(&fs->users);
59736 current->fs = new_fs;
59737+ gr_set_chroot_entries(current, &new_fs->root);
59738 spin_unlock(&fs->lock);
59739 task_unlock(current);
59740
59741@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59742
59743 int current_umask(void)
59744 {
59745- return current->fs->umask;
59746+ return current->fs->umask | gr_acl_umask();
59747 }
59748 EXPORT_SYMBOL(current_umask);
59749
59750 /* to be mentioned only in INIT_TASK */
59751 struct fs_struct init_fs = {
59752- .users = 1,
59753+ .users = ATOMIC_INIT(1),
59754 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59755 .seq = SEQCNT_ZERO(init_fs.seq),
59756 .umask = 0022,
59757diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59758index 29d7feb..303644d 100644
59759--- a/fs/fscache/cookie.c
59760+++ b/fs/fscache/cookie.c
59761@@ -19,7 +19,7 @@
59762
59763 struct kmem_cache *fscache_cookie_jar;
59764
59765-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59766+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59767
59768 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59769 static int fscache_alloc_object(struct fscache_cache *cache,
59770@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59771 parent ? (char *) parent->def->name : "<no-parent>",
59772 def->name, netfs_data, enable);
59773
59774- fscache_stat(&fscache_n_acquires);
59775+ fscache_stat_unchecked(&fscache_n_acquires);
59776
59777 /* if there's no parent cookie, then we don't create one here either */
59778 if (!parent) {
59779- fscache_stat(&fscache_n_acquires_null);
59780+ fscache_stat_unchecked(&fscache_n_acquires_null);
59781 _leave(" [no parent]");
59782 return NULL;
59783 }
59784@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59785 /* allocate and initialise a cookie */
59786 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59787 if (!cookie) {
59788- fscache_stat(&fscache_n_acquires_oom);
59789+ fscache_stat_unchecked(&fscache_n_acquires_oom);
59790 _leave(" [ENOMEM]");
59791 return NULL;
59792 }
59793@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59794
59795 switch (cookie->def->type) {
59796 case FSCACHE_COOKIE_TYPE_INDEX:
59797- fscache_stat(&fscache_n_cookie_index);
59798+ fscache_stat_unchecked(&fscache_n_cookie_index);
59799 break;
59800 case FSCACHE_COOKIE_TYPE_DATAFILE:
59801- fscache_stat(&fscache_n_cookie_data);
59802+ fscache_stat_unchecked(&fscache_n_cookie_data);
59803 break;
59804 default:
59805- fscache_stat(&fscache_n_cookie_special);
59806+ fscache_stat_unchecked(&fscache_n_cookie_special);
59807 break;
59808 }
59809
59810@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59811 } else {
59812 atomic_dec(&parent->n_children);
59813 __fscache_cookie_put(cookie);
59814- fscache_stat(&fscache_n_acquires_nobufs);
59815+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59816 _leave(" = NULL");
59817 return NULL;
59818 }
59819@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59820 }
59821 }
59822
59823- fscache_stat(&fscache_n_acquires_ok);
59824+ fscache_stat_unchecked(&fscache_n_acquires_ok);
59825 _leave(" = %p", cookie);
59826 return cookie;
59827 }
59828@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59829 cache = fscache_select_cache_for_object(cookie->parent);
59830 if (!cache) {
59831 up_read(&fscache_addremove_sem);
59832- fscache_stat(&fscache_n_acquires_no_cache);
59833+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59834 _leave(" = -ENOMEDIUM [no cache]");
59835 return -ENOMEDIUM;
59836 }
59837@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59838 object = cache->ops->alloc_object(cache, cookie);
59839 fscache_stat_d(&fscache_n_cop_alloc_object);
59840 if (IS_ERR(object)) {
59841- fscache_stat(&fscache_n_object_no_alloc);
59842+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
59843 ret = PTR_ERR(object);
59844 goto error;
59845 }
59846
59847- fscache_stat(&fscache_n_object_alloc);
59848+ fscache_stat_unchecked(&fscache_n_object_alloc);
59849
59850- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59851+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59852
59853 _debug("ALLOC OBJ%x: %s {%lx}",
59854 object->debug_id, cookie->def->name, object->events);
59855@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59856
59857 _enter("{%s}", cookie->def->name);
59858
59859- fscache_stat(&fscache_n_invalidates);
59860+ fscache_stat_unchecked(&fscache_n_invalidates);
59861
59862 /* Only permit invalidation of data files. Invalidating an index will
59863 * require the caller to release all its attachments to the tree rooted
59864@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59865 {
59866 struct fscache_object *object;
59867
59868- fscache_stat(&fscache_n_updates);
59869+ fscache_stat_unchecked(&fscache_n_updates);
59870
59871 if (!cookie) {
59872- fscache_stat(&fscache_n_updates_null);
59873+ fscache_stat_unchecked(&fscache_n_updates_null);
59874 _leave(" [no cookie]");
59875 return;
59876 }
59877@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59878 */
59879 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59880 {
59881- fscache_stat(&fscache_n_relinquishes);
59882+ fscache_stat_unchecked(&fscache_n_relinquishes);
59883 if (retire)
59884- fscache_stat(&fscache_n_relinquishes_retire);
59885+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59886
59887 if (!cookie) {
59888- fscache_stat(&fscache_n_relinquishes_null);
59889+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
59890 _leave(" [no cookie]");
59891 return;
59892 }
59893@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59894 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59895 goto inconsistent;
59896
59897- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59898+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59899
59900 __fscache_use_cookie(cookie);
59901 if (fscache_submit_op(object, op) < 0)
59902diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59903index 4226f66..0fb3f45 100644
59904--- a/fs/fscache/internal.h
59905+++ b/fs/fscache/internal.h
59906@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59907 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59908 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59909 struct fscache_operation *,
59910- atomic_t *,
59911- atomic_t *,
59912+ atomic_unchecked_t *,
59913+ atomic_unchecked_t *,
59914 void (*)(struct fscache_operation *));
59915 extern void fscache_invalidate_writes(struct fscache_cookie *);
59916
59917@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59918 * stats.c
59919 */
59920 #ifdef CONFIG_FSCACHE_STATS
59921-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59922-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59923+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59924+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59925
59926-extern atomic_t fscache_n_op_pend;
59927-extern atomic_t fscache_n_op_run;
59928-extern atomic_t fscache_n_op_enqueue;
59929-extern atomic_t fscache_n_op_deferred_release;
59930-extern atomic_t fscache_n_op_release;
59931-extern atomic_t fscache_n_op_gc;
59932-extern atomic_t fscache_n_op_cancelled;
59933-extern atomic_t fscache_n_op_rejected;
59934+extern atomic_unchecked_t fscache_n_op_pend;
59935+extern atomic_unchecked_t fscache_n_op_run;
59936+extern atomic_unchecked_t fscache_n_op_enqueue;
59937+extern atomic_unchecked_t fscache_n_op_deferred_release;
59938+extern atomic_unchecked_t fscache_n_op_release;
59939+extern atomic_unchecked_t fscache_n_op_gc;
59940+extern atomic_unchecked_t fscache_n_op_cancelled;
59941+extern atomic_unchecked_t fscache_n_op_rejected;
59942
59943-extern atomic_t fscache_n_attr_changed;
59944-extern atomic_t fscache_n_attr_changed_ok;
59945-extern atomic_t fscache_n_attr_changed_nobufs;
59946-extern atomic_t fscache_n_attr_changed_nomem;
59947-extern atomic_t fscache_n_attr_changed_calls;
59948+extern atomic_unchecked_t fscache_n_attr_changed;
59949+extern atomic_unchecked_t fscache_n_attr_changed_ok;
59950+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59951+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59952+extern atomic_unchecked_t fscache_n_attr_changed_calls;
59953
59954-extern atomic_t fscache_n_allocs;
59955-extern atomic_t fscache_n_allocs_ok;
59956-extern atomic_t fscache_n_allocs_wait;
59957-extern atomic_t fscache_n_allocs_nobufs;
59958-extern atomic_t fscache_n_allocs_intr;
59959-extern atomic_t fscache_n_allocs_object_dead;
59960-extern atomic_t fscache_n_alloc_ops;
59961-extern atomic_t fscache_n_alloc_op_waits;
59962+extern atomic_unchecked_t fscache_n_allocs;
59963+extern atomic_unchecked_t fscache_n_allocs_ok;
59964+extern atomic_unchecked_t fscache_n_allocs_wait;
59965+extern atomic_unchecked_t fscache_n_allocs_nobufs;
59966+extern atomic_unchecked_t fscache_n_allocs_intr;
59967+extern atomic_unchecked_t fscache_n_allocs_object_dead;
59968+extern atomic_unchecked_t fscache_n_alloc_ops;
59969+extern atomic_unchecked_t fscache_n_alloc_op_waits;
59970
59971-extern atomic_t fscache_n_retrievals;
59972-extern atomic_t fscache_n_retrievals_ok;
59973-extern atomic_t fscache_n_retrievals_wait;
59974-extern atomic_t fscache_n_retrievals_nodata;
59975-extern atomic_t fscache_n_retrievals_nobufs;
59976-extern atomic_t fscache_n_retrievals_intr;
59977-extern atomic_t fscache_n_retrievals_nomem;
59978-extern atomic_t fscache_n_retrievals_object_dead;
59979-extern atomic_t fscache_n_retrieval_ops;
59980-extern atomic_t fscache_n_retrieval_op_waits;
59981+extern atomic_unchecked_t fscache_n_retrievals;
59982+extern atomic_unchecked_t fscache_n_retrievals_ok;
59983+extern atomic_unchecked_t fscache_n_retrievals_wait;
59984+extern atomic_unchecked_t fscache_n_retrievals_nodata;
59985+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59986+extern atomic_unchecked_t fscache_n_retrievals_intr;
59987+extern atomic_unchecked_t fscache_n_retrievals_nomem;
59988+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59989+extern atomic_unchecked_t fscache_n_retrieval_ops;
59990+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59991
59992-extern atomic_t fscache_n_stores;
59993-extern atomic_t fscache_n_stores_ok;
59994-extern atomic_t fscache_n_stores_again;
59995-extern atomic_t fscache_n_stores_nobufs;
59996-extern atomic_t fscache_n_stores_oom;
59997-extern atomic_t fscache_n_store_ops;
59998-extern atomic_t fscache_n_store_calls;
59999-extern atomic_t fscache_n_store_pages;
60000-extern atomic_t fscache_n_store_radix_deletes;
60001-extern atomic_t fscache_n_store_pages_over_limit;
60002+extern atomic_unchecked_t fscache_n_stores;
60003+extern atomic_unchecked_t fscache_n_stores_ok;
60004+extern atomic_unchecked_t fscache_n_stores_again;
60005+extern atomic_unchecked_t fscache_n_stores_nobufs;
60006+extern atomic_unchecked_t fscache_n_stores_oom;
60007+extern atomic_unchecked_t fscache_n_store_ops;
60008+extern atomic_unchecked_t fscache_n_store_calls;
60009+extern atomic_unchecked_t fscache_n_store_pages;
60010+extern atomic_unchecked_t fscache_n_store_radix_deletes;
60011+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60012
60013-extern atomic_t fscache_n_store_vmscan_not_storing;
60014-extern atomic_t fscache_n_store_vmscan_gone;
60015-extern atomic_t fscache_n_store_vmscan_busy;
60016-extern atomic_t fscache_n_store_vmscan_cancelled;
60017-extern atomic_t fscache_n_store_vmscan_wait;
60018+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60019+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60020+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60021+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60022+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60023
60024-extern atomic_t fscache_n_marks;
60025-extern atomic_t fscache_n_uncaches;
60026+extern atomic_unchecked_t fscache_n_marks;
60027+extern atomic_unchecked_t fscache_n_uncaches;
60028
60029-extern atomic_t fscache_n_acquires;
60030-extern atomic_t fscache_n_acquires_null;
60031-extern atomic_t fscache_n_acquires_no_cache;
60032-extern atomic_t fscache_n_acquires_ok;
60033-extern atomic_t fscache_n_acquires_nobufs;
60034-extern atomic_t fscache_n_acquires_oom;
60035+extern atomic_unchecked_t fscache_n_acquires;
60036+extern atomic_unchecked_t fscache_n_acquires_null;
60037+extern atomic_unchecked_t fscache_n_acquires_no_cache;
60038+extern atomic_unchecked_t fscache_n_acquires_ok;
60039+extern atomic_unchecked_t fscache_n_acquires_nobufs;
60040+extern atomic_unchecked_t fscache_n_acquires_oom;
60041
60042-extern atomic_t fscache_n_invalidates;
60043-extern atomic_t fscache_n_invalidates_run;
60044+extern atomic_unchecked_t fscache_n_invalidates;
60045+extern atomic_unchecked_t fscache_n_invalidates_run;
60046
60047-extern atomic_t fscache_n_updates;
60048-extern atomic_t fscache_n_updates_null;
60049-extern atomic_t fscache_n_updates_run;
60050+extern atomic_unchecked_t fscache_n_updates;
60051+extern atomic_unchecked_t fscache_n_updates_null;
60052+extern atomic_unchecked_t fscache_n_updates_run;
60053
60054-extern atomic_t fscache_n_relinquishes;
60055-extern atomic_t fscache_n_relinquishes_null;
60056-extern atomic_t fscache_n_relinquishes_waitcrt;
60057-extern atomic_t fscache_n_relinquishes_retire;
60058+extern atomic_unchecked_t fscache_n_relinquishes;
60059+extern atomic_unchecked_t fscache_n_relinquishes_null;
60060+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60061+extern atomic_unchecked_t fscache_n_relinquishes_retire;
60062
60063-extern atomic_t fscache_n_cookie_index;
60064-extern atomic_t fscache_n_cookie_data;
60065-extern atomic_t fscache_n_cookie_special;
60066+extern atomic_unchecked_t fscache_n_cookie_index;
60067+extern atomic_unchecked_t fscache_n_cookie_data;
60068+extern atomic_unchecked_t fscache_n_cookie_special;
60069
60070-extern atomic_t fscache_n_object_alloc;
60071-extern atomic_t fscache_n_object_no_alloc;
60072-extern atomic_t fscache_n_object_lookups;
60073-extern atomic_t fscache_n_object_lookups_negative;
60074-extern atomic_t fscache_n_object_lookups_positive;
60075-extern atomic_t fscache_n_object_lookups_timed_out;
60076-extern atomic_t fscache_n_object_created;
60077-extern atomic_t fscache_n_object_avail;
60078-extern atomic_t fscache_n_object_dead;
60079+extern atomic_unchecked_t fscache_n_object_alloc;
60080+extern atomic_unchecked_t fscache_n_object_no_alloc;
60081+extern atomic_unchecked_t fscache_n_object_lookups;
60082+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60083+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60084+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60085+extern atomic_unchecked_t fscache_n_object_created;
60086+extern atomic_unchecked_t fscache_n_object_avail;
60087+extern atomic_unchecked_t fscache_n_object_dead;
60088
60089-extern atomic_t fscache_n_checkaux_none;
60090-extern atomic_t fscache_n_checkaux_okay;
60091-extern atomic_t fscache_n_checkaux_update;
60092-extern atomic_t fscache_n_checkaux_obsolete;
60093+extern atomic_unchecked_t fscache_n_checkaux_none;
60094+extern atomic_unchecked_t fscache_n_checkaux_okay;
60095+extern atomic_unchecked_t fscache_n_checkaux_update;
60096+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60097
60098 extern atomic_t fscache_n_cop_alloc_object;
60099 extern atomic_t fscache_n_cop_lookup_object;
60100@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60101 atomic_inc(stat);
60102 }
60103
60104+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60105+{
60106+ atomic_inc_unchecked(stat);
60107+}
60108+
60109 static inline void fscache_stat_d(atomic_t *stat)
60110 {
60111 atomic_dec(stat);
60112@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60113
60114 #define __fscache_stat(stat) (NULL)
60115 #define fscache_stat(stat) do {} while (0)
60116+#define fscache_stat_unchecked(stat) do {} while (0)
60117 #define fscache_stat_d(stat) do {} while (0)
60118 #endif
60119
60120diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60121index d3b4539..ed0c659 100644
60122--- a/fs/fscache/object.c
60123+++ b/fs/fscache/object.c
60124@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60125 _debug("LOOKUP \"%s\" in \"%s\"",
60126 cookie->def->name, object->cache->tag->name);
60127
60128- fscache_stat(&fscache_n_object_lookups);
60129+ fscache_stat_unchecked(&fscache_n_object_lookups);
60130 fscache_stat(&fscache_n_cop_lookup_object);
60131 ret = object->cache->ops->lookup_object(object);
60132 fscache_stat_d(&fscache_n_cop_lookup_object);
60133@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60134 if (ret == -ETIMEDOUT) {
60135 /* probably stuck behind another object, so move this one to
60136 * the back of the queue */
60137- fscache_stat(&fscache_n_object_lookups_timed_out);
60138+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60139 _leave(" [timeout]");
60140 return NO_TRANSIT;
60141 }
60142@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60143 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60144
60145 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60146- fscache_stat(&fscache_n_object_lookups_negative);
60147+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60148
60149 /* Allow write requests to begin stacking up and read requests to begin
60150 * returning ENODATA.
60151@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60152 /* if we were still looking up, then we must have a positive lookup
60153 * result, in which case there may be data available */
60154 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60155- fscache_stat(&fscache_n_object_lookups_positive);
60156+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60157
60158 /* We do (presumably) have data */
60159 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60160@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60161 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60162 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60163 } else {
60164- fscache_stat(&fscache_n_object_created);
60165+ fscache_stat_unchecked(&fscache_n_object_created);
60166 }
60167
60168 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60169@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60170 fscache_stat_d(&fscache_n_cop_lookup_complete);
60171
60172 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60173- fscache_stat(&fscache_n_object_avail);
60174+ fscache_stat_unchecked(&fscache_n_object_avail);
60175
60176 _leave("");
60177 return transit_to(JUMPSTART_DEPS);
60178@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60179
60180 /* this just shifts the object release to the work processor */
60181 fscache_put_object(object);
60182- fscache_stat(&fscache_n_object_dead);
60183+ fscache_stat_unchecked(&fscache_n_object_dead);
60184
60185 _leave("");
60186 return transit_to(OBJECT_DEAD);
60187@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60188 enum fscache_checkaux result;
60189
60190 if (!object->cookie->def->check_aux) {
60191- fscache_stat(&fscache_n_checkaux_none);
60192+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60193 return FSCACHE_CHECKAUX_OKAY;
60194 }
60195
60196@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60197 switch (result) {
60198 /* entry okay as is */
60199 case FSCACHE_CHECKAUX_OKAY:
60200- fscache_stat(&fscache_n_checkaux_okay);
60201+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60202 break;
60203
60204 /* entry requires update */
60205 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60206- fscache_stat(&fscache_n_checkaux_update);
60207+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60208 break;
60209
60210 /* entry requires deletion */
60211 case FSCACHE_CHECKAUX_OBSOLETE:
60212- fscache_stat(&fscache_n_checkaux_obsolete);
60213+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60214 break;
60215
60216 default:
60217@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60218 {
60219 const struct fscache_state *s;
60220
60221- fscache_stat(&fscache_n_invalidates_run);
60222+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60223 fscache_stat(&fscache_n_cop_invalidate_object);
60224 s = _fscache_invalidate_object(object, event);
60225 fscache_stat_d(&fscache_n_cop_invalidate_object);
60226@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60227 {
60228 _enter("{OBJ%x},%d", object->debug_id, event);
60229
60230- fscache_stat(&fscache_n_updates_run);
60231+ fscache_stat_unchecked(&fscache_n_updates_run);
60232 fscache_stat(&fscache_n_cop_update_object);
60233 object->cache->ops->update_object(object);
60234 fscache_stat_d(&fscache_n_cop_update_object);
60235diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60236index 318071a..379938b 100644
60237--- a/fs/fscache/operation.c
60238+++ b/fs/fscache/operation.c
60239@@ -17,7 +17,7 @@
60240 #include <linux/slab.h>
60241 #include "internal.h"
60242
60243-atomic_t fscache_op_debug_id;
60244+atomic_unchecked_t fscache_op_debug_id;
60245 EXPORT_SYMBOL(fscache_op_debug_id);
60246
60247 /**
60248@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60249 ASSERTCMP(atomic_read(&op->usage), >, 0);
60250 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60251
60252- fscache_stat(&fscache_n_op_enqueue);
60253+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60254 switch (op->flags & FSCACHE_OP_TYPE) {
60255 case FSCACHE_OP_ASYNC:
60256 _debug("queue async");
60257@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60258 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60259 if (op->processor)
60260 fscache_enqueue_operation(op);
60261- fscache_stat(&fscache_n_op_run);
60262+ fscache_stat_unchecked(&fscache_n_op_run);
60263 }
60264
60265 /*
60266@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60267 if (object->n_in_progress > 0) {
60268 atomic_inc(&op->usage);
60269 list_add_tail(&op->pend_link, &object->pending_ops);
60270- fscache_stat(&fscache_n_op_pend);
60271+ fscache_stat_unchecked(&fscache_n_op_pend);
60272 } else if (!list_empty(&object->pending_ops)) {
60273 atomic_inc(&op->usage);
60274 list_add_tail(&op->pend_link, &object->pending_ops);
60275- fscache_stat(&fscache_n_op_pend);
60276+ fscache_stat_unchecked(&fscache_n_op_pend);
60277 fscache_start_operations(object);
60278 } else {
60279 ASSERTCMP(object->n_in_progress, ==, 0);
60280@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60281 object->n_exclusive++; /* reads and writes must wait */
60282 atomic_inc(&op->usage);
60283 list_add_tail(&op->pend_link, &object->pending_ops);
60284- fscache_stat(&fscache_n_op_pend);
60285+ fscache_stat_unchecked(&fscache_n_op_pend);
60286 ret = 0;
60287 } else {
60288 /* If we're in any other state, there must have been an I/O
60289@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60290 if (object->n_exclusive > 0) {
60291 atomic_inc(&op->usage);
60292 list_add_tail(&op->pend_link, &object->pending_ops);
60293- fscache_stat(&fscache_n_op_pend);
60294+ fscache_stat_unchecked(&fscache_n_op_pend);
60295 } else if (!list_empty(&object->pending_ops)) {
60296 atomic_inc(&op->usage);
60297 list_add_tail(&op->pend_link, &object->pending_ops);
60298- fscache_stat(&fscache_n_op_pend);
60299+ fscache_stat_unchecked(&fscache_n_op_pend);
60300 fscache_start_operations(object);
60301 } else {
60302 ASSERTCMP(object->n_exclusive, ==, 0);
60303@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60304 object->n_ops++;
60305 atomic_inc(&op->usage);
60306 list_add_tail(&op->pend_link, &object->pending_ops);
60307- fscache_stat(&fscache_n_op_pend);
60308+ fscache_stat_unchecked(&fscache_n_op_pend);
60309 ret = 0;
60310 } else if (fscache_object_is_dying(object)) {
60311- fscache_stat(&fscache_n_op_rejected);
60312+ fscache_stat_unchecked(&fscache_n_op_rejected);
60313 op->state = FSCACHE_OP_ST_CANCELLED;
60314 ret = -ENOBUFS;
60315 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60316@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60317 ret = -EBUSY;
60318 if (op->state == FSCACHE_OP_ST_PENDING) {
60319 ASSERT(!list_empty(&op->pend_link));
60320- fscache_stat(&fscache_n_op_cancelled);
60321+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60322 list_del_init(&op->pend_link);
60323 if (do_cancel)
60324 do_cancel(op);
60325@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60326 while (!list_empty(&object->pending_ops)) {
60327 op = list_entry(object->pending_ops.next,
60328 struct fscache_operation, pend_link);
60329- fscache_stat(&fscache_n_op_cancelled);
60330+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60331 list_del_init(&op->pend_link);
60332
60333 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60334@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60335 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60336 op->state = FSCACHE_OP_ST_DEAD;
60337
60338- fscache_stat(&fscache_n_op_release);
60339+ fscache_stat_unchecked(&fscache_n_op_release);
60340
60341 if (op->release) {
60342 op->release(op);
60343@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60344 * lock, and defer it otherwise */
60345 if (!spin_trylock(&object->lock)) {
60346 _debug("defer put");
60347- fscache_stat(&fscache_n_op_deferred_release);
60348+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60349
60350 cache = object->cache;
60351 spin_lock(&cache->op_gc_list_lock);
60352@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60353
60354 _debug("GC DEFERRED REL OBJ%x OP%x",
60355 object->debug_id, op->debug_id);
60356- fscache_stat(&fscache_n_op_gc);
60357+ fscache_stat_unchecked(&fscache_n_op_gc);
60358
60359 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60360 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60361diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60362index 7f5c658..6c1e164 100644
60363--- a/fs/fscache/page.c
60364+++ b/fs/fscache/page.c
60365@@ -61,7 +61,7 @@ try_again:
60366 val = radix_tree_lookup(&cookie->stores, page->index);
60367 if (!val) {
60368 rcu_read_unlock();
60369- fscache_stat(&fscache_n_store_vmscan_not_storing);
60370+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60371 __fscache_uncache_page(cookie, page);
60372 return true;
60373 }
60374@@ -91,11 +91,11 @@ try_again:
60375 spin_unlock(&cookie->stores_lock);
60376
60377 if (xpage) {
60378- fscache_stat(&fscache_n_store_vmscan_cancelled);
60379- fscache_stat(&fscache_n_store_radix_deletes);
60380+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60381+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60382 ASSERTCMP(xpage, ==, page);
60383 } else {
60384- fscache_stat(&fscache_n_store_vmscan_gone);
60385+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60386 }
60387
60388 wake_up_bit(&cookie->flags, 0);
60389@@ -110,11 +110,11 @@ page_busy:
60390 * sleeping on memory allocation, so we may need to impose a timeout
60391 * too. */
60392 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60393- fscache_stat(&fscache_n_store_vmscan_busy);
60394+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60395 return false;
60396 }
60397
60398- fscache_stat(&fscache_n_store_vmscan_wait);
60399+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60400 __fscache_wait_on_page_write(cookie, page);
60401 gfp &= ~__GFP_WAIT;
60402 goto try_again;
60403@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60404 FSCACHE_COOKIE_STORING_TAG);
60405 if (!radix_tree_tag_get(&cookie->stores, page->index,
60406 FSCACHE_COOKIE_PENDING_TAG)) {
60407- fscache_stat(&fscache_n_store_radix_deletes);
60408+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60409 xpage = radix_tree_delete(&cookie->stores, page->index);
60410 }
60411 spin_unlock(&cookie->stores_lock);
60412@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60413
60414 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60415
60416- fscache_stat(&fscache_n_attr_changed_calls);
60417+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60418
60419 if (fscache_object_is_active(object)) {
60420 fscache_stat(&fscache_n_cop_attr_changed);
60421@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60422
60423 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60424
60425- fscache_stat(&fscache_n_attr_changed);
60426+ fscache_stat_unchecked(&fscache_n_attr_changed);
60427
60428 op = kzalloc(sizeof(*op), GFP_KERNEL);
60429 if (!op) {
60430- fscache_stat(&fscache_n_attr_changed_nomem);
60431+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60432 _leave(" = -ENOMEM");
60433 return -ENOMEM;
60434 }
60435@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60436 if (fscache_submit_exclusive_op(object, op) < 0)
60437 goto nobufs;
60438 spin_unlock(&cookie->lock);
60439- fscache_stat(&fscache_n_attr_changed_ok);
60440+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60441 fscache_put_operation(op);
60442 _leave(" = 0");
60443 return 0;
60444@@ -225,7 +225,7 @@ nobufs:
60445 kfree(op);
60446 if (wake_cookie)
60447 __fscache_wake_unused_cookie(cookie);
60448- fscache_stat(&fscache_n_attr_changed_nobufs);
60449+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60450 _leave(" = %d", -ENOBUFS);
60451 return -ENOBUFS;
60452 }
60453@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60454 /* allocate a retrieval operation and attempt to submit it */
60455 op = kzalloc(sizeof(*op), GFP_NOIO);
60456 if (!op) {
60457- fscache_stat(&fscache_n_retrievals_nomem);
60458+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60459 return NULL;
60460 }
60461
60462@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60463 return 0;
60464 }
60465
60466- fscache_stat(&fscache_n_retrievals_wait);
60467+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60468
60469 jif = jiffies;
60470 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60471 fscache_wait_bit_interruptible,
60472 TASK_INTERRUPTIBLE) != 0) {
60473- fscache_stat(&fscache_n_retrievals_intr);
60474+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60475 _leave(" = -ERESTARTSYS");
60476 return -ERESTARTSYS;
60477 }
60478@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60479 */
60480 int fscache_wait_for_operation_activation(struct fscache_object *object,
60481 struct fscache_operation *op,
60482- atomic_t *stat_op_waits,
60483- atomic_t *stat_object_dead,
60484+ atomic_unchecked_t *stat_op_waits,
60485+ atomic_unchecked_t *stat_object_dead,
60486 void (*do_cancel)(struct fscache_operation *))
60487 {
60488 int ret;
60489@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60490
60491 _debug(">>> WT");
60492 if (stat_op_waits)
60493- fscache_stat(stat_op_waits);
60494+ fscache_stat_unchecked(stat_op_waits);
60495 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60496 fscache_wait_bit_interruptible,
60497 TASK_INTERRUPTIBLE) != 0) {
60498@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60499 check_if_dead:
60500 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60501 if (stat_object_dead)
60502- fscache_stat(stat_object_dead);
60503+ fscache_stat_unchecked(stat_object_dead);
60504 _leave(" = -ENOBUFS [cancelled]");
60505 return -ENOBUFS;
60506 }
60507@@ -366,7 +366,7 @@ check_if_dead:
60508 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60509 fscache_cancel_op(op, do_cancel);
60510 if (stat_object_dead)
60511- fscache_stat(stat_object_dead);
60512+ fscache_stat_unchecked(stat_object_dead);
60513 return -ENOBUFS;
60514 }
60515 return 0;
60516@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60517
60518 _enter("%p,%p,,,", cookie, page);
60519
60520- fscache_stat(&fscache_n_retrievals);
60521+ fscache_stat_unchecked(&fscache_n_retrievals);
60522
60523 if (hlist_empty(&cookie->backing_objects))
60524 goto nobufs;
60525@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60526 goto nobufs_unlock_dec;
60527 spin_unlock(&cookie->lock);
60528
60529- fscache_stat(&fscache_n_retrieval_ops);
60530+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60531
60532 /* pin the netfs read context in case we need to do the actual netfs
60533 * read because we've encountered a cache read failure */
60534@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60535
60536 error:
60537 if (ret == -ENOMEM)
60538- fscache_stat(&fscache_n_retrievals_nomem);
60539+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60540 else if (ret == -ERESTARTSYS)
60541- fscache_stat(&fscache_n_retrievals_intr);
60542+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60543 else if (ret == -ENODATA)
60544- fscache_stat(&fscache_n_retrievals_nodata);
60545+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60546 else if (ret < 0)
60547- fscache_stat(&fscache_n_retrievals_nobufs);
60548+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60549 else
60550- fscache_stat(&fscache_n_retrievals_ok);
60551+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60552
60553 fscache_put_retrieval(op);
60554 _leave(" = %d", ret);
60555@@ -490,7 +490,7 @@ nobufs_unlock:
60556 __fscache_wake_unused_cookie(cookie);
60557 kfree(op);
60558 nobufs:
60559- fscache_stat(&fscache_n_retrievals_nobufs);
60560+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60561 _leave(" = -ENOBUFS");
60562 return -ENOBUFS;
60563 }
60564@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60565
60566 _enter("%p,,%d,,,", cookie, *nr_pages);
60567
60568- fscache_stat(&fscache_n_retrievals);
60569+ fscache_stat_unchecked(&fscache_n_retrievals);
60570
60571 if (hlist_empty(&cookie->backing_objects))
60572 goto nobufs;
60573@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60574 goto nobufs_unlock_dec;
60575 spin_unlock(&cookie->lock);
60576
60577- fscache_stat(&fscache_n_retrieval_ops);
60578+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60579
60580 /* pin the netfs read context in case we need to do the actual netfs
60581 * read because we've encountered a cache read failure */
60582@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60583
60584 error:
60585 if (ret == -ENOMEM)
60586- fscache_stat(&fscache_n_retrievals_nomem);
60587+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60588 else if (ret == -ERESTARTSYS)
60589- fscache_stat(&fscache_n_retrievals_intr);
60590+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60591 else if (ret == -ENODATA)
60592- fscache_stat(&fscache_n_retrievals_nodata);
60593+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60594 else if (ret < 0)
60595- fscache_stat(&fscache_n_retrievals_nobufs);
60596+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60597 else
60598- fscache_stat(&fscache_n_retrievals_ok);
60599+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60600
60601 fscache_put_retrieval(op);
60602 _leave(" = %d", ret);
60603@@ -621,7 +621,7 @@ nobufs_unlock:
60604 if (wake_cookie)
60605 __fscache_wake_unused_cookie(cookie);
60606 nobufs:
60607- fscache_stat(&fscache_n_retrievals_nobufs);
60608+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60609 _leave(" = -ENOBUFS");
60610 return -ENOBUFS;
60611 }
60612@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60613
60614 _enter("%p,%p,,,", cookie, page);
60615
60616- fscache_stat(&fscache_n_allocs);
60617+ fscache_stat_unchecked(&fscache_n_allocs);
60618
60619 if (hlist_empty(&cookie->backing_objects))
60620 goto nobufs;
60621@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60622 goto nobufs_unlock_dec;
60623 spin_unlock(&cookie->lock);
60624
60625- fscache_stat(&fscache_n_alloc_ops);
60626+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60627
60628 ret = fscache_wait_for_operation_activation(
60629 object, &op->op,
60630@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60631
60632 error:
60633 if (ret == -ERESTARTSYS)
60634- fscache_stat(&fscache_n_allocs_intr);
60635+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60636 else if (ret < 0)
60637- fscache_stat(&fscache_n_allocs_nobufs);
60638+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60639 else
60640- fscache_stat(&fscache_n_allocs_ok);
60641+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60642
60643 fscache_put_retrieval(op);
60644 _leave(" = %d", ret);
60645@@ -715,7 +715,7 @@ nobufs_unlock:
60646 if (wake_cookie)
60647 __fscache_wake_unused_cookie(cookie);
60648 nobufs:
60649- fscache_stat(&fscache_n_allocs_nobufs);
60650+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60651 _leave(" = -ENOBUFS");
60652 return -ENOBUFS;
60653 }
60654@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60655
60656 spin_lock(&cookie->stores_lock);
60657
60658- fscache_stat(&fscache_n_store_calls);
60659+ fscache_stat_unchecked(&fscache_n_store_calls);
60660
60661 /* find a page to store */
60662 page = NULL;
60663@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60664 page = results[0];
60665 _debug("gang %d [%lx]", n, page->index);
60666 if (page->index > op->store_limit) {
60667- fscache_stat(&fscache_n_store_pages_over_limit);
60668+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60669 goto superseded;
60670 }
60671
60672@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60673 spin_unlock(&cookie->stores_lock);
60674 spin_unlock(&object->lock);
60675
60676- fscache_stat(&fscache_n_store_pages);
60677+ fscache_stat_unchecked(&fscache_n_store_pages);
60678 fscache_stat(&fscache_n_cop_write_page);
60679 ret = object->cache->ops->write_page(op, page);
60680 fscache_stat_d(&fscache_n_cop_write_page);
60681@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60682 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60683 ASSERT(PageFsCache(page));
60684
60685- fscache_stat(&fscache_n_stores);
60686+ fscache_stat_unchecked(&fscache_n_stores);
60687
60688 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60689 _leave(" = -ENOBUFS [invalidating]");
60690@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60691 spin_unlock(&cookie->stores_lock);
60692 spin_unlock(&object->lock);
60693
60694- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60695+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60696 op->store_limit = object->store_limit;
60697
60698 __fscache_use_cookie(cookie);
60699@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60700
60701 spin_unlock(&cookie->lock);
60702 radix_tree_preload_end();
60703- fscache_stat(&fscache_n_store_ops);
60704- fscache_stat(&fscache_n_stores_ok);
60705+ fscache_stat_unchecked(&fscache_n_store_ops);
60706+ fscache_stat_unchecked(&fscache_n_stores_ok);
60707
60708 /* the work queue now carries its own ref on the object */
60709 fscache_put_operation(&op->op);
60710@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60711 return 0;
60712
60713 already_queued:
60714- fscache_stat(&fscache_n_stores_again);
60715+ fscache_stat_unchecked(&fscache_n_stores_again);
60716 already_pending:
60717 spin_unlock(&cookie->stores_lock);
60718 spin_unlock(&object->lock);
60719 spin_unlock(&cookie->lock);
60720 radix_tree_preload_end();
60721 kfree(op);
60722- fscache_stat(&fscache_n_stores_ok);
60723+ fscache_stat_unchecked(&fscache_n_stores_ok);
60724 _leave(" = 0");
60725 return 0;
60726
60727@@ -1024,14 +1024,14 @@ nobufs:
60728 kfree(op);
60729 if (wake_cookie)
60730 __fscache_wake_unused_cookie(cookie);
60731- fscache_stat(&fscache_n_stores_nobufs);
60732+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
60733 _leave(" = -ENOBUFS");
60734 return -ENOBUFS;
60735
60736 nomem_free:
60737 kfree(op);
60738 nomem:
60739- fscache_stat(&fscache_n_stores_oom);
60740+ fscache_stat_unchecked(&fscache_n_stores_oom);
60741 _leave(" = -ENOMEM");
60742 return -ENOMEM;
60743 }
60744@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60745 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60746 ASSERTCMP(page, !=, NULL);
60747
60748- fscache_stat(&fscache_n_uncaches);
60749+ fscache_stat_unchecked(&fscache_n_uncaches);
60750
60751 /* cache withdrawal may beat us to it */
60752 if (!PageFsCache(page))
60753@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60754 struct fscache_cookie *cookie = op->op.object->cookie;
60755
60756 #ifdef CONFIG_FSCACHE_STATS
60757- atomic_inc(&fscache_n_marks);
60758+ atomic_inc_unchecked(&fscache_n_marks);
60759 #endif
60760
60761 _debug("- mark %p{%lx}", page, page->index);
60762diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60763index 40d13c7..ddf52b9 100644
60764--- a/fs/fscache/stats.c
60765+++ b/fs/fscache/stats.c
60766@@ -18,99 +18,99 @@
60767 /*
60768 * operation counters
60769 */
60770-atomic_t fscache_n_op_pend;
60771-atomic_t fscache_n_op_run;
60772-atomic_t fscache_n_op_enqueue;
60773-atomic_t fscache_n_op_requeue;
60774-atomic_t fscache_n_op_deferred_release;
60775-atomic_t fscache_n_op_release;
60776-atomic_t fscache_n_op_gc;
60777-atomic_t fscache_n_op_cancelled;
60778-atomic_t fscache_n_op_rejected;
60779+atomic_unchecked_t fscache_n_op_pend;
60780+atomic_unchecked_t fscache_n_op_run;
60781+atomic_unchecked_t fscache_n_op_enqueue;
60782+atomic_unchecked_t fscache_n_op_requeue;
60783+atomic_unchecked_t fscache_n_op_deferred_release;
60784+atomic_unchecked_t fscache_n_op_release;
60785+atomic_unchecked_t fscache_n_op_gc;
60786+atomic_unchecked_t fscache_n_op_cancelled;
60787+atomic_unchecked_t fscache_n_op_rejected;
60788
60789-atomic_t fscache_n_attr_changed;
60790-atomic_t fscache_n_attr_changed_ok;
60791-atomic_t fscache_n_attr_changed_nobufs;
60792-atomic_t fscache_n_attr_changed_nomem;
60793-atomic_t fscache_n_attr_changed_calls;
60794+atomic_unchecked_t fscache_n_attr_changed;
60795+atomic_unchecked_t fscache_n_attr_changed_ok;
60796+atomic_unchecked_t fscache_n_attr_changed_nobufs;
60797+atomic_unchecked_t fscache_n_attr_changed_nomem;
60798+atomic_unchecked_t fscache_n_attr_changed_calls;
60799
60800-atomic_t fscache_n_allocs;
60801-atomic_t fscache_n_allocs_ok;
60802-atomic_t fscache_n_allocs_wait;
60803-atomic_t fscache_n_allocs_nobufs;
60804-atomic_t fscache_n_allocs_intr;
60805-atomic_t fscache_n_allocs_object_dead;
60806-atomic_t fscache_n_alloc_ops;
60807-atomic_t fscache_n_alloc_op_waits;
60808+atomic_unchecked_t fscache_n_allocs;
60809+atomic_unchecked_t fscache_n_allocs_ok;
60810+atomic_unchecked_t fscache_n_allocs_wait;
60811+atomic_unchecked_t fscache_n_allocs_nobufs;
60812+atomic_unchecked_t fscache_n_allocs_intr;
60813+atomic_unchecked_t fscache_n_allocs_object_dead;
60814+atomic_unchecked_t fscache_n_alloc_ops;
60815+atomic_unchecked_t fscache_n_alloc_op_waits;
60816
60817-atomic_t fscache_n_retrievals;
60818-atomic_t fscache_n_retrievals_ok;
60819-atomic_t fscache_n_retrievals_wait;
60820-atomic_t fscache_n_retrievals_nodata;
60821-atomic_t fscache_n_retrievals_nobufs;
60822-atomic_t fscache_n_retrievals_intr;
60823-atomic_t fscache_n_retrievals_nomem;
60824-atomic_t fscache_n_retrievals_object_dead;
60825-atomic_t fscache_n_retrieval_ops;
60826-atomic_t fscache_n_retrieval_op_waits;
60827+atomic_unchecked_t fscache_n_retrievals;
60828+atomic_unchecked_t fscache_n_retrievals_ok;
60829+atomic_unchecked_t fscache_n_retrievals_wait;
60830+atomic_unchecked_t fscache_n_retrievals_nodata;
60831+atomic_unchecked_t fscache_n_retrievals_nobufs;
60832+atomic_unchecked_t fscache_n_retrievals_intr;
60833+atomic_unchecked_t fscache_n_retrievals_nomem;
60834+atomic_unchecked_t fscache_n_retrievals_object_dead;
60835+atomic_unchecked_t fscache_n_retrieval_ops;
60836+atomic_unchecked_t fscache_n_retrieval_op_waits;
60837
60838-atomic_t fscache_n_stores;
60839-atomic_t fscache_n_stores_ok;
60840-atomic_t fscache_n_stores_again;
60841-atomic_t fscache_n_stores_nobufs;
60842-atomic_t fscache_n_stores_oom;
60843-atomic_t fscache_n_store_ops;
60844-atomic_t fscache_n_store_calls;
60845-atomic_t fscache_n_store_pages;
60846-atomic_t fscache_n_store_radix_deletes;
60847-atomic_t fscache_n_store_pages_over_limit;
60848+atomic_unchecked_t fscache_n_stores;
60849+atomic_unchecked_t fscache_n_stores_ok;
60850+atomic_unchecked_t fscache_n_stores_again;
60851+atomic_unchecked_t fscache_n_stores_nobufs;
60852+atomic_unchecked_t fscache_n_stores_oom;
60853+atomic_unchecked_t fscache_n_store_ops;
60854+atomic_unchecked_t fscache_n_store_calls;
60855+atomic_unchecked_t fscache_n_store_pages;
60856+atomic_unchecked_t fscache_n_store_radix_deletes;
60857+atomic_unchecked_t fscache_n_store_pages_over_limit;
60858
60859-atomic_t fscache_n_store_vmscan_not_storing;
60860-atomic_t fscache_n_store_vmscan_gone;
60861-atomic_t fscache_n_store_vmscan_busy;
60862-atomic_t fscache_n_store_vmscan_cancelled;
60863-atomic_t fscache_n_store_vmscan_wait;
60864+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60865+atomic_unchecked_t fscache_n_store_vmscan_gone;
60866+atomic_unchecked_t fscache_n_store_vmscan_busy;
60867+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60868+atomic_unchecked_t fscache_n_store_vmscan_wait;
60869
60870-atomic_t fscache_n_marks;
60871-atomic_t fscache_n_uncaches;
60872+atomic_unchecked_t fscache_n_marks;
60873+atomic_unchecked_t fscache_n_uncaches;
60874
60875-atomic_t fscache_n_acquires;
60876-atomic_t fscache_n_acquires_null;
60877-atomic_t fscache_n_acquires_no_cache;
60878-atomic_t fscache_n_acquires_ok;
60879-atomic_t fscache_n_acquires_nobufs;
60880-atomic_t fscache_n_acquires_oom;
60881+atomic_unchecked_t fscache_n_acquires;
60882+atomic_unchecked_t fscache_n_acquires_null;
60883+atomic_unchecked_t fscache_n_acquires_no_cache;
60884+atomic_unchecked_t fscache_n_acquires_ok;
60885+atomic_unchecked_t fscache_n_acquires_nobufs;
60886+atomic_unchecked_t fscache_n_acquires_oom;
60887
60888-atomic_t fscache_n_invalidates;
60889-atomic_t fscache_n_invalidates_run;
60890+atomic_unchecked_t fscache_n_invalidates;
60891+atomic_unchecked_t fscache_n_invalidates_run;
60892
60893-atomic_t fscache_n_updates;
60894-atomic_t fscache_n_updates_null;
60895-atomic_t fscache_n_updates_run;
60896+atomic_unchecked_t fscache_n_updates;
60897+atomic_unchecked_t fscache_n_updates_null;
60898+atomic_unchecked_t fscache_n_updates_run;
60899
60900-atomic_t fscache_n_relinquishes;
60901-atomic_t fscache_n_relinquishes_null;
60902-atomic_t fscache_n_relinquishes_waitcrt;
60903-atomic_t fscache_n_relinquishes_retire;
60904+atomic_unchecked_t fscache_n_relinquishes;
60905+atomic_unchecked_t fscache_n_relinquishes_null;
60906+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60907+atomic_unchecked_t fscache_n_relinquishes_retire;
60908
60909-atomic_t fscache_n_cookie_index;
60910-atomic_t fscache_n_cookie_data;
60911-atomic_t fscache_n_cookie_special;
60912+atomic_unchecked_t fscache_n_cookie_index;
60913+atomic_unchecked_t fscache_n_cookie_data;
60914+atomic_unchecked_t fscache_n_cookie_special;
60915
60916-atomic_t fscache_n_object_alloc;
60917-atomic_t fscache_n_object_no_alloc;
60918-atomic_t fscache_n_object_lookups;
60919-atomic_t fscache_n_object_lookups_negative;
60920-atomic_t fscache_n_object_lookups_positive;
60921-atomic_t fscache_n_object_lookups_timed_out;
60922-atomic_t fscache_n_object_created;
60923-atomic_t fscache_n_object_avail;
60924-atomic_t fscache_n_object_dead;
60925+atomic_unchecked_t fscache_n_object_alloc;
60926+atomic_unchecked_t fscache_n_object_no_alloc;
60927+atomic_unchecked_t fscache_n_object_lookups;
60928+atomic_unchecked_t fscache_n_object_lookups_negative;
60929+atomic_unchecked_t fscache_n_object_lookups_positive;
60930+atomic_unchecked_t fscache_n_object_lookups_timed_out;
60931+atomic_unchecked_t fscache_n_object_created;
60932+atomic_unchecked_t fscache_n_object_avail;
60933+atomic_unchecked_t fscache_n_object_dead;
60934
60935-atomic_t fscache_n_checkaux_none;
60936-atomic_t fscache_n_checkaux_okay;
60937-atomic_t fscache_n_checkaux_update;
60938-atomic_t fscache_n_checkaux_obsolete;
60939+atomic_unchecked_t fscache_n_checkaux_none;
60940+atomic_unchecked_t fscache_n_checkaux_okay;
60941+atomic_unchecked_t fscache_n_checkaux_update;
60942+atomic_unchecked_t fscache_n_checkaux_obsolete;
60943
60944 atomic_t fscache_n_cop_alloc_object;
60945 atomic_t fscache_n_cop_lookup_object;
60946@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60947 seq_puts(m, "FS-Cache statistics\n");
60948
60949 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60950- atomic_read(&fscache_n_cookie_index),
60951- atomic_read(&fscache_n_cookie_data),
60952- atomic_read(&fscache_n_cookie_special));
60953+ atomic_read_unchecked(&fscache_n_cookie_index),
60954+ atomic_read_unchecked(&fscache_n_cookie_data),
60955+ atomic_read_unchecked(&fscache_n_cookie_special));
60956
60957 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60958- atomic_read(&fscache_n_object_alloc),
60959- atomic_read(&fscache_n_object_no_alloc),
60960- atomic_read(&fscache_n_object_avail),
60961- atomic_read(&fscache_n_object_dead));
60962+ atomic_read_unchecked(&fscache_n_object_alloc),
60963+ atomic_read_unchecked(&fscache_n_object_no_alloc),
60964+ atomic_read_unchecked(&fscache_n_object_avail),
60965+ atomic_read_unchecked(&fscache_n_object_dead));
60966 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60967- atomic_read(&fscache_n_checkaux_none),
60968- atomic_read(&fscache_n_checkaux_okay),
60969- atomic_read(&fscache_n_checkaux_update),
60970- atomic_read(&fscache_n_checkaux_obsolete));
60971+ atomic_read_unchecked(&fscache_n_checkaux_none),
60972+ atomic_read_unchecked(&fscache_n_checkaux_okay),
60973+ atomic_read_unchecked(&fscache_n_checkaux_update),
60974+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60975
60976 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60977- atomic_read(&fscache_n_marks),
60978- atomic_read(&fscache_n_uncaches));
60979+ atomic_read_unchecked(&fscache_n_marks),
60980+ atomic_read_unchecked(&fscache_n_uncaches));
60981
60982 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60983 " oom=%u\n",
60984- atomic_read(&fscache_n_acquires),
60985- atomic_read(&fscache_n_acquires_null),
60986- atomic_read(&fscache_n_acquires_no_cache),
60987- atomic_read(&fscache_n_acquires_ok),
60988- atomic_read(&fscache_n_acquires_nobufs),
60989- atomic_read(&fscache_n_acquires_oom));
60990+ atomic_read_unchecked(&fscache_n_acquires),
60991+ atomic_read_unchecked(&fscache_n_acquires_null),
60992+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
60993+ atomic_read_unchecked(&fscache_n_acquires_ok),
60994+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
60995+ atomic_read_unchecked(&fscache_n_acquires_oom));
60996
60997 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60998- atomic_read(&fscache_n_object_lookups),
60999- atomic_read(&fscache_n_object_lookups_negative),
61000- atomic_read(&fscache_n_object_lookups_positive),
61001- atomic_read(&fscache_n_object_created),
61002- atomic_read(&fscache_n_object_lookups_timed_out));
61003+ atomic_read_unchecked(&fscache_n_object_lookups),
61004+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
61005+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
61006+ atomic_read_unchecked(&fscache_n_object_created),
61007+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61008
61009 seq_printf(m, "Invals : n=%u run=%u\n",
61010- atomic_read(&fscache_n_invalidates),
61011- atomic_read(&fscache_n_invalidates_run));
61012+ atomic_read_unchecked(&fscache_n_invalidates),
61013+ atomic_read_unchecked(&fscache_n_invalidates_run));
61014
61015 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61016- atomic_read(&fscache_n_updates),
61017- atomic_read(&fscache_n_updates_null),
61018- atomic_read(&fscache_n_updates_run));
61019+ atomic_read_unchecked(&fscache_n_updates),
61020+ atomic_read_unchecked(&fscache_n_updates_null),
61021+ atomic_read_unchecked(&fscache_n_updates_run));
61022
61023 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61024- atomic_read(&fscache_n_relinquishes),
61025- atomic_read(&fscache_n_relinquishes_null),
61026- atomic_read(&fscache_n_relinquishes_waitcrt),
61027- atomic_read(&fscache_n_relinquishes_retire));
61028+ atomic_read_unchecked(&fscache_n_relinquishes),
61029+ atomic_read_unchecked(&fscache_n_relinquishes_null),
61030+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61031+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
61032
61033 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61034- atomic_read(&fscache_n_attr_changed),
61035- atomic_read(&fscache_n_attr_changed_ok),
61036- atomic_read(&fscache_n_attr_changed_nobufs),
61037- atomic_read(&fscache_n_attr_changed_nomem),
61038- atomic_read(&fscache_n_attr_changed_calls));
61039+ atomic_read_unchecked(&fscache_n_attr_changed),
61040+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
61041+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61042+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61043+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
61044
61045 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61046- atomic_read(&fscache_n_allocs),
61047- atomic_read(&fscache_n_allocs_ok),
61048- atomic_read(&fscache_n_allocs_wait),
61049- atomic_read(&fscache_n_allocs_nobufs),
61050- atomic_read(&fscache_n_allocs_intr));
61051+ atomic_read_unchecked(&fscache_n_allocs),
61052+ atomic_read_unchecked(&fscache_n_allocs_ok),
61053+ atomic_read_unchecked(&fscache_n_allocs_wait),
61054+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
61055+ atomic_read_unchecked(&fscache_n_allocs_intr));
61056 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61057- atomic_read(&fscache_n_alloc_ops),
61058- atomic_read(&fscache_n_alloc_op_waits),
61059- atomic_read(&fscache_n_allocs_object_dead));
61060+ atomic_read_unchecked(&fscache_n_alloc_ops),
61061+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
61062+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
61063
61064 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61065 " int=%u oom=%u\n",
61066- atomic_read(&fscache_n_retrievals),
61067- atomic_read(&fscache_n_retrievals_ok),
61068- atomic_read(&fscache_n_retrievals_wait),
61069- atomic_read(&fscache_n_retrievals_nodata),
61070- atomic_read(&fscache_n_retrievals_nobufs),
61071- atomic_read(&fscache_n_retrievals_intr),
61072- atomic_read(&fscache_n_retrievals_nomem));
61073+ atomic_read_unchecked(&fscache_n_retrievals),
61074+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61075+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61076+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61077+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61078+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61079+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61080 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61081- atomic_read(&fscache_n_retrieval_ops),
61082- atomic_read(&fscache_n_retrieval_op_waits),
61083- atomic_read(&fscache_n_retrievals_object_dead));
61084+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61085+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61086+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61087
61088 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61089- atomic_read(&fscache_n_stores),
61090- atomic_read(&fscache_n_stores_ok),
61091- atomic_read(&fscache_n_stores_again),
61092- atomic_read(&fscache_n_stores_nobufs),
61093- atomic_read(&fscache_n_stores_oom));
61094+ atomic_read_unchecked(&fscache_n_stores),
61095+ atomic_read_unchecked(&fscache_n_stores_ok),
61096+ atomic_read_unchecked(&fscache_n_stores_again),
61097+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61098+ atomic_read_unchecked(&fscache_n_stores_oom));
61099 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61100- atomic_read(&fscache_n_store_ops),
61101- atomic_read(&fscache_n_store_calls),
61102- atomic_read(&fscache_n_store_pages),
61103- atomic_read(&fscache_n_store_radix_deletes),
61104- atomic_read(&fscache_n_store_pages_over_limit));
61105+ atomic_read_unchecked(&fscache_n_store_ops),
61106+ atomic_read_unchecked(&fscache_n_store_calls),
61107+ atomic_read_unchecked(&fscache_n_store_pages),
61108+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61109+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61110
61111 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61112- atomic_read(&fscache_n_store_vmscan_not_storing),
61113- atomic_read(&fscache_n_store_vmscan_gone),
61114- atomic_read(&fscache_n_store_vmscan_busy),
61115- atomic_read(&fscache_n_store_vmscan_cancelled),
61116- atomic_read(&fscache_n_store_vmscan_wait));
61117+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61118+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61119+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61120+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61121+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61122
61123 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61124- atomic_read(&fscache_n_op_pend),
61125- atomic_read(&fscache_n_op_run),
61126- atomic_read(&fscache_n_op_enqueue),
61127- atomic_read(&fscache_n_op_cancelled),
61128- atomic_read(&fscache_n_op_rejected));
61129+ atomic_read_unchecked(&fscache_n_op_pend),
61130+ atomic_read_unchecked(&fscache_n_op_run),
61131+ atomic_read_unchecked(&fscache_n_op_enqueue),
61132+ atomic_read_unchecked(&fscache_n_op_cancelled),
61133+ atomic_read_unchecked(&fscache_n_op_rejected));
61134 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61135- atomic_read(&fscache_n_op_deferred_release),
61136- atomic_read(&fscache_n_op_release),
61137- atomic_read(&fscache_n_op_gc));
61138+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61139+ atomic_read_unchecked(&fscache_n_op_release),
61140+ atomic_read_unchecked(&fscache_n_op_gc));
61141
61142 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61143 atomic_read(&fscache_n_cop_alloc_object),
61144diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61145index 13b691a..1ffca5ae 100644
61146--- a/fs/fuse/cuse.c
61147+++ b/fs/fuse/cuse.c
61148@@ -607,10 +607,12 @@ static int __init cuse_init(void)
61149 INIT_LIST_HEAD(&cuse_conntbl[i]);
61150
61151 /* inherit and extend fuse_dev_operations */
61152- cuse_channel_fops = fuse_dev_operations;
61153- cuse_channel_fops.owner = THIS_MODULE;
61154- cuse_channel_fops.open = cuse_channel_open;
61155- cuse_channel_fops.release = cuse_channel_release;
61156+ pax_open_kernel();
61157+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61158+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61159+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61160+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61161+ pax_close_kernel();
61162
61163 cuse_class = class_create(THIS_MODULE, "cuse");
61164 if (IS_ERR(cuse_class))
61165diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61166index aac71ce..fcd6a1b 100644
61167--- a/fs/fuse/dev.c
61168+++ b/fs/fuse/dev.c
61169@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61170 ret = 0;
61171 pipe_lock(pipe);
61172
61173- if (!pipe->readers) {
61174+ if (!atomic_read(&pipe->readers)) {
61175 send_sig(SIGPIPE, current, 0);
61176 if (!ret)
61177 ret = -EPIPE;
61178@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61179 page_nr++;
61180 ret += buf->len;
61181
61182- if (pipe->files)
61183+ if (atomic_read(&pipe->files))
61184 do_wakeup = 1;
61185 }
61186
61187diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61188index 4219835..3473b7e 100644
61189--- a/fs/fuse/dir.c
61190+++ b/fs/fuse/dir.c
61191@@ -1478,7 +1478,7 @@ static char *read_link(struct dentry *dentry)
61192 return link;
61193 }
61194
61195-static void free_link(char *link)
61196+static void free_link(const char *link)
61197 {
61198 if (!IS_ERR(link))
61199 free_page((unsigned long) link);
61200diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61201index 9c470fd..aae410e 100644
61202--- a/fs/hostfs/hostfs_kern.c
61203+++ b/fs/hostfs/hostfs_kern.c
61204@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61205
61206 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61207 {
61208- char *s = nd_get_link(nd);
61209+ const char *s = nd_get_link(nd);
61210 if (!IS_ERR(s))
61211 __putname(s);
61212 }
61213diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61214index e19d4c0..8a357a9 100644
61215--- a/fs/hugetlbfs/inode.c
61216+++ b/fs/hugetlbfs/inode.c
61217@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61218 struct mm_struct *mm = current->mm;
61219 struct vm_area_struct *vma;
61220 struct hstate *h = hstate_file(file);
61221+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61222 struct vm_unmapped_area_info info;
61223
61224 if (len & ~huge_page_mask(h))
61225@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61226 return addr;
61227 }
61228
61229+#ifdef CONFIG_PAX_RANDMMAP
61230+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61231+#endif
61232+
61233 if (addr) {
61234 addr = ALIGN(addr, huge_page_size(h));
61235 vma = find_vma(mm, addr);
61236- if (TASK_SIZE - len >= addr &&
61237- (!vma || addr + len <= vma->vm_start))
61238+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61239 return addr;
61240 }
61241
61242 info.flags = 0;
61243 info.length = len;
61244 info.low_limit = TASK_UNMAPPED_BASE;
61245+
61246+#ifdef CONFIG_PAX_RANDMMAP
61247+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61248+ info.low_limit += mm->delta_mmap;
61249+#endif
61250+
61251 info.high_limit = TASK_SIZE;
61252 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61253 info.align_offset = 0;
61254@@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61255 };
61256 MODULE_ALIAS_FS("hugetlbfs");
61257
61258-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61259+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61260
61261 static int can_do_hugetlb_shm(void)
61262 {
61263diff --git a/fs/inode.c b/fs/inode.c
61264index d2fb2f2..a6444b0 100644
61265--- a/fs/inode.c
61266+++ b/fs/inode.c
61267@@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61268 unsigned int *p = &get_cpu_var(last_ino);
61269 unsigned int res = *p;
61270
61271+start:
61272+
61273 #ifdef CONFIG_SMP
61274 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61275- static atomic_t shared_last_ino;
61276- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61277+ static atomic_unchecked_t shared_last_ino;
61278+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61279
61280 res = next - LAST_INO_BATCH;
61281 }
61282 #endif
61283
61284- *p = ++res;
61285+ if (unlikely(!++res))
61286+ goto start; /* never zero */
61287+ *p = res;
61288 put_cpu_var(last_ino);
61289 return res;
61290 }
61291diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61292index 4a6cf28..d3a29d3 100644
61293--- a/fs/jffs2/erase.c
61294+++ b/fs/jffs2/erase.c
61295@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61296 struct jffs2_unknown_node marker = {
61297 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61298 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61299- .totlen = cpu_to_je32(c->cleanmarker_size)
61300+ .totlen = cpu_to_je32(c->cleanmarker_size),
61301+ .hdr_crc = cpu_to_je32(0)
61302 };
61303
61304 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61305diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61306index a6597d6..41b30ec 100644
61307--- a/fs/jffs2/wbuf.c
61308+++ b/fs/jffs2/wbuf.c
61309@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61310 {
61311 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61312 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61313- .totlen = constant_cpu_to_je32(8)
61314+ .totlen = constant_cpu_to_je32(8),
61315+ .hdr_crc = constant_cpu_to_je32(0)
61316 };
61317
61318 /*
61319diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61320index 97f7fda..09bd33d 100644
61321--- a/fs/jfs/super.c
61322+++ b/fs/jfs/super.c
61323@@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61324
61325 jfs_inode_cachep =
61326 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61327- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61328+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61329 init_once);
61330 if (jfs_inode_cachep == NULL)
61331 return -ENOMEM;
61332diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61333index ac127cd..d8079db 100644
61334--- a/fs/kernfs/dir.c
61335+++ b/fs/kernfs/dir.c
61336@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61337 *
61338 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61339 */
61340-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61341+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61342 {
61343 unsigned long hash = init_name_hash();
61344 unsigned int len = strlen(name);
61345diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61346index 5e9a80c..3853a24 100644
61347--- a/fs/kernfs/file.c
61348+++ b/fs/kernfs/file.c
61349@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61350
61351 struct kernfs_open_node {
61352 atomic_t refcnt;
61353- atomic_t event;
61354+ atomic_unchecked_t event;
61355 wait_queue_head_t poll;
61356 struct list_head files; /* goes through kernfs_open_file.list */
61357 };
61358@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61359 {
61360 struct kernfs_open_file *of = sf->private;
61361
61362- of->event = atomic_read(&of->kn->attr.open->event);
61363+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61364
61365 return of->kn->attr.ops->seq_show(sf, v);
61366 }
61367@@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61368 return ret;
61369 }
61370
61371-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61372- void *buf, int len, int write)
61373+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61374+ void *buf, size_t len, int write)
61375 {
61376 struct file *file = vma->vm_file;
61377 struct kernfs_open_file *of = kernfs_of(file);
61378- int ret;
61379+ ssize_t ret;
61380
61381 if (!of->vm_ops)
61382 return -EINVAL;
61383@@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61384 return -ENOMEM;
61385
61386 atomic_set(&new_on->refcnt, 0);
61387- atomic_set(&new_on->event, 1);
61388+ atomic_set_unchecked(&new_on->event, 1);
61389 init_waitqueue_head(&new_on->poll);
61390 INIT_LIST_HEAD(&new_on->files);
61391 goto retry;
61392@@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61393
61394 kernfs_put_active(kn);
61395
61396- if (of->event != atomic_read(&on->event))
61397+ if (of->event != atomic_read_unchecked(&on->event))
61398 goto trigger;
61399
61400 return DEFAULT_POLLMASK;
61401@@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
61402 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61403 on = kn->attr.open;
61404 if (on) {
61405- atomic_inc(&on->event);
61406+ atomic_inc_unchecked(&on->event);
61407 wake_up_interruptible(&on->poll);
61408 }
61409 }
61410diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61411index 8a19889..4c3069a 100644
61412--- a/fs/kernfs/symlink.c
61413+++ b/fs/kernfs/symlink.c
61414@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61415 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61416 void *cookie)
61417 {
61418- char *page = nd_get_link(nd);
61419+ const char *page = nd_get_link(nd);
61420 if (!IS_ERR(page))
61421 free_page((unsigned long)page);
61422 }
61423diff --git a/fs/libfs.c b/fs/libfs.c
61424index a184424..944ddce 100644
61425--- a/fs/libfs.c
61426+++ b/fs/libfs.c
61427@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61428
61429 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61430 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61431+ char d_name[sizeof(next->d_iname)];
61432+ const unsigned char *name;
61433+
61434 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61435 if (!simple_positive(next)) {
61436 spin_unlock(&next->d_lock);
61437@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61438
61439 spin_unlock(&next->d_lock);
61440 spin_unlock(&dentry->d_lock);
61441- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61442+ name = next->d_name.name;
61443+ if (name == next->d_iname) {
61444+ memcpy(d_name, name, next->d_name.len);
61445+ name = d_name;
61446+ }
61447+ if (!dir_emit(ctx, name, next->d_name.len,
61448 next->d_inode->i_ino, dt_type(next->d_inode)))
61449 return 0;
61450 spin_lock(&dentry->d_lock);
61451@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61452 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61453 void *cookie)
61454 {
61455- char *s = nd_get_link(nd);
61456+ const char *s = nd_get_link(nd);
61457 if (!IS_ERR(s))
61458 kfree(s);
61459 }
61460diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61461index acd3947..1f896e2 100644
61462--- a/fs/lockd/clntproc.c
61463+++ b/fs/lockd/clntproc.c
61464@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61465 /*
61466 * Cookie counter for NLM requests
61467 */
61468-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61469+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61470
61471 void nlmclnt_next_cookie(struct nlm_cookie *c)
61472 {
61473- u32 cookie = atomic_inc_return(&nlm_cookie);
61474+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61475
61476 memcpy(c->data, &cookie, 4);
61477 c->len=4;
61478diff --git a/fs/locks.c b/fs/locks.c
61479index e390bd9..c79870e 100644
61480--- a/fs/locks.c
61481+++ b/fs/locks.c
61482@@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
61483 locks_remove_posix(filp, (fl_owner_t)filp);
61484
61485 if (filp->f_op->flock) {
61486- struct file_lock fl = {
61487+ struct file_lock flock = {
61488 .fl_pid = current->tgid,
61489 .fl_file = filp,
61490 .fl_flags = FL_FLOCK,
61491 .fl_type = F_UNLCK,
61492 .fl_end = OFFSET_MAX,
61493 };
61494- filp->f_op->flock(filp, F_SETLKW, &fl);
61495- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61496- fl.fl_ops->fl_release_private(&fl);
61497+ filp->f_op->flock(filp, F_SETLKW, &flock);
61498+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61499+ flock.fl_ops->fl_release_private(&flock);
61500 }
61501
61502 spin_lock(&inode->i_lock);
61503diff --git a/fs/mount.h b/fs/mount.h
61504index d55297f..f5b28c5 100644
61505--- a/fs/mount.h
61506+++ b/fs/mount.h
61507@@ -11,7 +11,7 @@ struct mnt_namespace {
61508 u64 seq; /* Sequence number to prevent loops */
61509 wait_queue_head_t poll;
61510 u64 event;
61511-};
61512+} __randomize_layout;
61513
61514 struct mnt_pcp {
61515 int mnt_count;
61516@@ -57,7 +57,7 @@ struct mount {
61517 int mnt_expiry_mark; /* true if marked for expiry */
61518 int mnt_pinned;
61519 struct path mnt_ex_mountpoint;
61520-};
61521+} __randomize_layout;
61522
61523 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61524
61525diff --git a/fs/namei.c b/fs/namei.c
61526index 985c6f3..f67a0f8 100644
61527--- a/fs/namei.c
61528+++ b/fs/namei.c
61529@@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61530 if (ret != -EACCES)
61531 return ret;
61532
61533+#ifdef CONFIG_GRKERNSEC
61534+ /* we'll block if we have to log due to a denied capability use */
61535+ if (mask & MAY_NOT_BLOCK)
61536+ return -ECHILD;
61537+#endif
61538+
61539 if (S_ISDIR(inode->i_mode)) {
61540 /* DACs are overridable for directories */
61541- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61542- return 0;
61543 if (!(mask & MAY_WRITE))
61544- if (capable_wrt_inode_uidgid(inode,
61545- CAP_DAC_READ_SEARCH))
61546+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61547+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61548 return 0;
61549+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61550+ return 0;
61551 return -EACCES;
61552 }
61553 /*
61554+ * Searching includes executable on directories, else just read.
61555+ */
61556+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61557+ if (mask == MAY_READ)
61558+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61559+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61560+ return 0;
61561+
61562+ /*
61563 * Read/write DACs are always overridable.
61564 * Executable DACs are overridable when there is
61565 * at least one exec bit set.
61566@@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61567 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61568 return 0;
61569
61570- /*
61571- * Searching includes executable on directories, else just read.
61572- */
61573- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61574- if (mask == MAY_READ)
61575- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61576- return 0;
61577-
61578 return -EACCES;
61579 }
61580 EXPORT_SYMBOL(generic_permission);
61581@@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61582 {
61583 struct dentry *dentry = link->dentry;
61584 int error;
61585- char *s;
61586+ const char *s;
61587
61588 BUG_ON(nd->flags & LOOKUP_RCU);
61589
61590@@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61591 if (error)
61592 goto out_put_nd_path;
61593
61594+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61595+ dentry->d_inode, dentry, nd->path.mnt)) {
61596+ error = -EACCES;
61597+ goto out_put_nd_path;
61598+ }
61599+
61600 nd->last_type = LAST_BIND;
61601 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61602 error = PTR_ERR(*p);
61603@@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61604 if (res)
61605 break;
61606 res = walk_component(nd, path, LOOKUP_FOLLOW);
61607+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61608+ res = -EACCES;
61609 put_link(nd, &link, cookie);
61610 } while (res > 0);
61611
61612@@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
61613 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61614 {
61615 unsigned long a, b, adata, bdata, mask, hash, len;
61616- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61617+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61618
61619 hash = a = 0;
61620 len = -sizeof(unsigned long);
61621@@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
61622 if (err)
61623 break;
61624 err = lookup_last(nd, &path);
61625+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61626+ err = -EACCES;
61627 put_link(nd, &link, cookie);
61628 }
61629 }
61630@@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
61631 if (!err)
61632 err = complete_walk(nd);
61633
61634+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61635+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61636+ path_put(&nd->path);
61637+ err = -ENOENT;
61638+ }
61639+ }
61640+
61641 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61642 if (!d_can_lookup(nd->path.dentry)) {
61643 path_put(&nd->path);
61644@@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
61645 retval = path_lookupat(dfd, name->name,
61646 flags | LOOKUP_REVAL, nd);
61647
61648- if (likely(!retval))
61649+ if (likely(!retval)) {
61650 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61651+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61652+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61653+ path_put(&nd->path);
61654+ return -ENOENT;
61655+ }
61656+ }
61657+ }
61658 return retval;
61659 }
61660
61661@@ -2569,6 +2600,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61662 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61663 return -EPERM;
61664
61665+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61666+ return -EPERM;
61667+ if (gr_handle_rawio(inode))
61668+ return -EPERM;
61669+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61670+ return -EACCES;
61671+
61672 return 0;
61673 }
61674
61675@@ -2800,7 +2838,7 @@ looked_up:
61676 * cleared otherwise prior to returning.
61677 */
61678 static int lookup_open(struct nameidata *nd, struct path *path,
61679- struct file *file,
61680+ struct path *link, struct file *file,
61681 const struct open_flags *op,
61682 bool got_write, int *opened)
61683 {
61684@@ -2835,6 +2873,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61685 /* Negative dentry, just create the file */
61686 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61687 umode_t mode = op->mode;
61688+
61689+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61690+ error = -EACCES;
61691+ goto out_dput;
61692+ }
61693+
61694+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61695+ error = -EACCES;
61696+ goto out_dput;
61697+ }
61698+
61699 if (!IS_POSIXACL(dir->d_inode))
61700 mode &= ~current_umask();
61701 /*
61702@@ -2856,6 +2905,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61703 nd->flags & LOOKUP_EXCL);
61704 if (error)
61705 goto out_dput;
61706+ else
61707+ gr_handle_create(dentry, nd->path.mnt);
61708 }
61709 out_no_open:
61710 path->dentry = dentry;
61711@@ -2870,7 +2921,7 @@ out_dput:
61712 /*
61713 * Handle the last step of open()
61714 */
61715-static int do_last(struct nameidata *nd, struct path *path,
61716+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61717 struct file *file, const struct open_flags *op,
61718 int *opened, struct filename *name)
61719 {
61720@@ -2920,6 +2971,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61721 if (error)
61722 return error;
61723
61724+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61725+ error = -ENOENT;
61726+ goto out;
61727+ }
61728+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61729+ error = -EACCES;
61730+ goto out;
61731+ }
61732+
61733 audit_inode(name, dir, LOOKUP_PARENT);
61734 error = -EISDIR;
61735 /* trailing slashes? */
61736@@ -2939,7 +2999,7 @@ retry_lookup:
61737 */
61738 }
61739 mutex_lock(&dir->d_inode->i_mutex);
61740- error = lookup_open(nd, path, file, op, got_write, opened);
61741+ error = lookup_open(nd, path, link, file, op, got_write, opened);
61742 mutex_unlock(&dir->d_inode->i_mutex);
61743
61744 if (error <= 0) {
61745@@ -2963,11 +3023,28 @@ retry_lookup:
61746 goto finish_open_created;
61747 }
61748
61749+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61750+ error = -ENOENT;
61751+ goto exit_dput;
61752+ }
61753+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61754+ error = -EACCES;
61755+ goto exit_dput;
61756+ }
61757+
61758 /*
61759 * create/update audit record if it already exists.
61760 */
61761- if (d_is_positive(path->dentry))
61762+ if (d_is_positive(path->dentry)) {
61763+ /* only check if O_CREAT is specified, all other checks need to go
61764+ into may_open */
61765+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61766+ error = -EACCES;
61767+ goto exit_dput;
61768+ }
61769+
61770 audit_inode(name, path->dentry, 0);
61771+ }
61772
61773 /*
61774 * If atomic_open() acquired write access it is dropped now due to
61775@@ -3008,6 +3085,11 @@ finish_lookup:
61776 }
61777 }
61778 BUG_ON(inode != path->dentry->d_inode);
61779+ /* if we're resolving a symlink to another symlink */
61780+ if (link && gr_handle_symlink_owner(link, inode)) {
61781+ error = -EACCES;
61782+ goto out;
61783+ }
61784 return 1;
61785 }
61786
61787@@ -3017,7 +3099,6 @@ finish_lookup:
61788 save_parent.dentry = nd->path.dentry;
61789 save_parent.mnt = mntget(path->mnt);
61790 nd->path.dentry = path->dentry;
61791-
61792 }
61793 nd->inode = inode;
61794 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61795@@ -3027,7 +3108,18 @@ finish_open:
61796 path_put(&save_parent);
61797 return error;
61798 }
61799+
61800+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61801+ error = -ENOENT;
61802+ goto out;
61803+ }
61804+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61805+ error = -EACCES;
61806+ goto out;
61807+ }
61808+
61809 audit_inode(name, nd->path.dentry, 0);
61810+
61811 error = -EISDIR;
61812 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
61813 goto out;
61814@@ -3190,7 +3282,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61815 if (unlikely(error))
61816 goto out;
61817
61818- error = do_last(nd, &path, file, op, &opened, pathname);
61819+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61820 while (unlikely(error > 0)) { /* trailing symlink */
61821 struct path link = path;
61822 void *cookie;
61823@@ -3208,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61824 error = follow_link(&link, nd, &cookie);
61825 if (unlikely(error))
61826 break;
61827- error = do_last(nd, &path, file, op, &opened, pathname);
61828+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
61829 put_link(nd, &link, cookie);
61830 }
61831 out:
61832@@ -3308,9 +3400,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61833 goto unlock;
61834
61835 error = -EEXIST;
61836- if (d_is_positive(dentry))
61837+ if (d_is_positive(dentry)) {
61838+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61839+ error = -ENOENT;
61840 goto fail;
61841-
61842+ }
61843 /*
61844 * Special case - lookup gave negative, but... we had foo/bar/
61845 * From the vfs_mknod() POV we just have a negative dentry -
61846@@ -3362,6 +3456,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61847 }
61848 EXPORT_SYMBOL(user_path_create);
61849
61850+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61851+{
61852+ struct filename *tmp = getname(pathname);
61853+ struct dentry *res;
61854+ if (IS_ERR(tmp))
61855+ return ERR_CAST(tmp);
61856+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61857+ if (IS_ERR(res))
61858+ putname(tmp);
61859+ else
61860+ *to = tmp;
61861+ return res;
61862+}
61863+
61864 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61865 {
61866 int error = may_create(dir, dentry);
61867@@ -3425,6 +3533,17 @@ retry:
61868
61869 if (!IS_POSIXACL(path.dentry->d_inode))
61870 mode &= ~current_umask();
61871+
61872+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61873+ error = -EPERM;
61874+ goto out;
61875+ }
61876+
61877+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61878+ error = -EACCES;
61879+ goto out;
61880+ }
61881+
61882 error = security_path_mknod(&path, dentry, mode, dev);
61883 if (error)
61884 goto out;
61885@@ -3441,6 +3560,8 @@ retry:
61886 break;
61887 }
61888 out:
61889+ if (!error)
61890+ gr_handle_create(dentry, path.mnt);
61891 done_path_create(&path, dentry);
61892 if (retry_estale(error, lookup_flags)) {
61893 lookup_flags |= LOOKUP_REVAL;
61894@@ -3494,9 +3615,16 @@ retry:
61895
61896 if (!IS_POSIXACL(path.dentry->d_inode))
61897 mode &= ~current_umask();
61898+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61899+ error = -EACCES;
61900+ goto out;
61901+ }
61902 error = security_path_mkdir(&path, dentry, mode);
61903 if (!error)
61904 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61905+ if (!error)
61906+ gr_handle_create(dentry, path.mnt);
61907+out:
61908 done_path_create(&path, dentry);
61909 if (retry_estale(error, lookup_flags)) {
61910 lookup_flags |= LOOKUP_REVAL;
61911@@ -3579,6 +3707,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61912 struct filename *name;
61913 struct dentry *dentry;
61914 struct nameidata nd;
61915+ ino_t saved_ino = 0;
61916+ dev_t saved_dev = 0;
61917 unsigned int lookup_flags = 0;
61918 retry:
61919 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61920@@ -3611,10 +3741,21 @@ retry:
61921 error = -ENOENT;
61922 goto exit3;
61923 }
61924+
61925+ saved_ino = dentry->d_inode->i_ino;
61926+ saved_dev = gr_get_dev_from_dentry(dentry);
61927+
61928+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61929+ error = -EACCES;
61930+ goto exit3;
61931+ }
61932+
61933 error = security_path_rmdir(&nd.path, dentry);
61934 if (error)
61935 goto exit3;
61936 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61937+ if (!error && (saved_dev || saved_ino))
61938+ gr_handle_delete(saved_ino, saved_dev);
61939 exit3:
61940 dput(dentry);
61941 exit2:
61942@@ -3705,6 +3846,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61943 struct nameidata nd;
61944 struct inode *inode = NULL;
61945 struct inode *delegated_inode = NULL;
61946+ ino_t saved_ino = 0;
61947+ dev_t saved_dev = 0;
61948 unsigned int lookup_flags = 0;
61949 retry:
61950 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61951@@ -3731,10 +3874,22 @@ retry_deleg:
61952 if (d_is_negative(dentry))
61953 goto slashes;
61954 ihold(inode);
61955+
61956+ if (inode->i_nlink <= 1) {
61957+ saved_ino = inode->i_ino;
61958+ saved_dev = gr_get_dev_from_dentry(dentry);
61959+ }
61960+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61961+ error = -EACCES;
61962+ goto exit2;
61963+ }
61964+
61965 error = security_path_unlink(&nd.path, dentry);
61966 if (error)
61967 goto exit2;
61968 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61969+ if (!error && (saved_ino || saved_dev))
61970+ gr_handle_delete(saved_ino, saved_dev);
61971 exit2:
61972 dput(dentry);
61973 }
61974@@ -3823,9 +3978,17 @@ retry:
61975 if (IS_ERR(dentry))
61976 goto out_putname;
61977
61978+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61979+ error = -EACCES;
61980+ goto out;
61981+ }
61982+
61983 error = security_path_symlink(&path, dentry, from->name);
61984 if (!error)
61985 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61986+ if (!error)
61987+ gr_handle_create(dentry, path.mnt);
61988+out:
61989 done_path_create(&path, dentry);
61990 if (retry_estale(error, lookup_flags)) {
61991 lookup_flags |= LOOKUP_REVAL;
61992@@ -3929,6 +4092,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61993 struct dentry *new_dentry;
61994 struct path old_path, new_path;
61995 struct inode *delegated_inode = NULL;
61996+ struct filename *to = NULL;
61997 int how = 0;
61998 int error;
61999
62000@@ -3952,7 +4116,7 @@ retry:
62001 if (error)
62002 return error;
62003
62004- new_dentry = user_path_create(newdfd, newname, &new_path,
62005+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62006 (how & LOOKUP_REVAL));
62007 error = PTR_ERR(new_dentry);
62008 if (IS_ERR(new_dentry))
62009@@ -3964,11 +4128,28 @@ retry:
62010 error = may_linkat(&old_path);
62011 if (unlikely(error))
62012 goto out_dput;
62013+
62014+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62015+ old_path.dentry->d_inode,
62016+ old_path.dentry->d_inode->i_mode, to)) {
62017+ error = -EACCES;
62018+ goto out_dput;
62019+ }
62020+
62021+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62022+ old_path.dentry, old_path.mnt, to)) {
62023+ error = -EACCES;
62024+ goto out_dput;
62025+ }
62026+
62027 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62028 if (error)
62029 goto out_dput;
62030 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62031+ if (!error)
62032+ gr_handle_create(new_dentry, new_path.mnt);
62033 out_dput:
62034+ putname(to);
62035 done_path_create(&new_path, new_dentry);
62036 if (delegated_inode) {
62037 error = break_deleg_wait(&delegated_inode);
62038@@ -4278,6 +4459,12 @@ retry_deleg:
62039 if (new_dentry == trap)
62040 goto exit5;
62041
62042+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62043+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
62044+ to, flags);
62045+ if (error)
62046+ goto exit5;
62047+
62048 error = security_path_rename(&oldnd.path, old_dentry,
62049 &newnd.path, new_dentry, flags);
62050 if (error)
62051@@ -4285,6 +4472,9 @@ retry_deleg:
62052 error = vfs_rename(old_dir->d_inode, old_dentry,
62053 new_dir->d_inode, new_dentry,
62054 &delegated_inode, flags);
62055+ if (!error)
62056+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62057+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
62058 exit5:
62059 dput(new_dentry);
62060 exit4:
62061@@ -4327,14 +4517,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62062
62063 int readlink_copy(char __user *buffer, int buflen, const char *link)
62064 {
62065+ char tmpbuf[64];
62066+ const char *newlink;
62067 int len = PTR_ERR(link);
62068+
62069 if (IS_ERR(link))
62070 goto out;
62071
62072 len = strlen(link);
62073 if (len > (unsigned) buflen)
62074 len = buflen;
62075- if (copy_to_user(buffer, link, len))
62076+
62077+ if (len < sizeof(tmpbuf)) {
62078+ memcpy(tmpbuf, link, len);
62079+ newlink = tmpbuf;
62080+ } else
62081+ newlink = link;
62082+
62083+ if (copy_to_user(buffer, newlink, len))
62084 len = -EFAULT;
62085 out:
62086 return len;
62087diff --git a/fs/namespace.c b/fs/namespace.c
62088index 182bc41..72e3cf1 100644
62089--- a/fs/namespace.c
62090+++ b/fs/namespace.c
62091@@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
62092 if (!(sb->s_flags & MS_RDONLY))
62093 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62094 up_write(&sb->s_umount);
62095+
62096+ gr_log_remount(mnt->mnt_devname, retval);
62097+
62098 return retval;
62099 }
62100
62101@@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
62102 }
62103 unlock_mount_hash();
62104 namespace_unlock();
62105+
62106+ gr_log_unmount(mnt->mnt_devname, retval);
62107+
62108 return retval;
62109 }
62110
62111@@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
62112 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62113 */
62114
62115-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62116+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62117 {
62118 struct path path;
62119 struct mount *mnt;
62120@@ -1431,7 +1437,7 @@ out:
62121 /*
62122 * The 2.0 compatible umount. No flags.
62123 */
62124-SYSCALL_DEFINE1(oldumount, char __user *, name)
62125+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62126 {
62127 return sys_umount(name, 0);
62128 }
62129@@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62130 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62131 MS_STRICTATIME);
62132
62133+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62134+ retval = -EPERM;
62135+ goto dput_out;
62136+ }
62137+
62138+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62139+ retval = -EPERM;
62140+ goto dput_out;
62141+ }
62142+
62143 if (flags & MS_REMOUNT)
62144 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62145 data_page);
62146@@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62147 dev_name, data_page);
62148 dput_out:
62149 path_put(&path);
62150+
62151+ gr_log_mount(dev_name, dir_name, retval);
62152+
62153 return retval;
62154 }
62155
62156@@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62157 * number incrementing at 10Ghz will take 12,427 years to wrap which
62158 * is effectively never, so we can ignore the possibility.
62159 */
62160-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62161+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62162
62163 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62164 {
62165@@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62166 kfree(new_ns);
62167 return ERR_PTR(ret);
62168 }
62169- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62170+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62171 atomic_set(&new_ns->count, 1);
62172 new_ns->root = NULL;
62173 INIT_LIST_HEAD(&new_ns->list);
62174@@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62175 return new_ns;
62176 }
62177
62178-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62179+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62180 struct user_namespace *user_ns, struct fs_struct *new_fs)
62181 {
62182 struct mnt_namespace *new_ns;
62183@@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62184 }
62185 EXPORT_SYMBOL(mount_subtree);
62186
62187-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62188- char __user *, type, unsigned long, flags, void __user *, data)
62189+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62190+ const char __user *, type, unsigned long, flags, void __user *, data)
62191 {
62192 int ret;
62193 char *kernel_type;
62194@@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62195 if (error)
62196 goto out2;
62197
62198+ if (gr_handle_chroot_pivot()) {
62199+ error = -EPERM;
62200+ goto out2;
62201+ }
62202+
62203 get_fs_root(current->fs, &root);
62204 old_mp = lock_mount(&old);
62205 error = PTR_ERR(old_mp);
62206@@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62207 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62208 return -EPERM;
62209
62210- if (fs->users != 1)
62211+ if (atomic_read(&fs->users) != 1)
62212 return -EINVAL;
62213
62214 get_mnt_ns(mnt_ns);
62215diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62216index f4ccfe6..a5cf064 100644
62217--- a/fs/nfs/callback_xdr.c
62218+++ b/fs/nfs/callback_xdr.c
62219@@ -51,7 +51,7 @@ struct callback_op {
62220 callback_decode_arg_t decode_args;
62221 callback_encode_res_t encode_res;
62222 long res_maxsize;
62223-};
62224+} __do_const;
62225
62226 static struct callback_op callback_ops[];
62227
62228diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62229index 0c43897..0949f08 100644
62230--- a/fs/nfs/inode.c
62231+++ b/fs/nfs/inode.c
62232@@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62233 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62234 }
62235
62236-static atomic_long_t nfs_attr_generation_counter;
62237+static atomic_long_unchecked_t nfs_attr_generation_counter;
62238
62239 static unsigned long nfs_read_attr_generation_counter(void)
62240 {
62241- return atomic_long_read(&nfs_attr_generation_counter);
62242+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62243 }
62244
62245 unsigned long nfs_inc_attr_generation_counter(void)
62246 {
62247- return atomic_long_inc_return(&nfs_attr_generation_counter);
62248+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62249 }
62250
62251 void nfs_fattr_init(struct nfs_fattr *fattr)
62252diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62253index d543222..2cfa2a2 100644
62254--- a/fs/nfsd/nfs4proc.c
62255+++ b/fs/nfsd/nfs4proc.c
62256@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62257 nfsd4op_rsize op_rsize_bop;
62258 stateid_getter op_get_currentstateid;
62259 stateid_setter op_set_currentstateid;
62260-};
62261+} __do_const;
62262
62263 static struct nfsd4_operation nfsd4_ops[];
62264
62265diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62266index 18881f3..40e5bef 100644
62267--- a/fs/nfsd/nfs4xdr.c
62268+++ b/fs/nfsd/nfs4xdr.c
62269@@ -1530,7 +1530,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62270
62271 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62272
62273-static nfsd4_dec nfsd4_dec_ops[] = {
62274+static const nfsd4_dec nfsd4_dec_ops[] = {
62275 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62276 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62277 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62278diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62279index f8f060f..c4ba09a 100644
62280--- a/fs/nfsd/nfscache.c
62281+++ b/fs/nfsd/nfscache.c
62282@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62283 {
62284 struct svc_cacherep *rp = rqstp->rq_cacherep;
62285 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62286- int len;
62287+ long len;
62288 size_t bufsize = 0;
62289
62290 if (!rp)
62291 return;
62292
62293- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62294- len >>= 2;
62295+ if (statp) {
62296+ len = (char*)statp - (char*)resv->iov_base;
62297+ len = resv->iov_len - len;
62298+ len >>= 2;
62299+ }
62300
62301 /* Don't cache excessive amounts of data and XDR failures */
62302 if (!statp || len > (256 >> 2)) {
62303diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62304index 16f0673..1c2c30ab 100644
62305--- a/fs/nfsd/vfs.c
62306+++ b/fs/nfsd/vfs.c
62307@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62308 } else {
62309 oldfs = get_fs();
62310 set_fs(KERNEL_DS);
62311- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62312+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62313 set_fs(oldfs);
62314 }
62315
62316@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62317
62318 /* Write the data. */
62319 oldfs = get_fs(); set_fs(KERNEL_DS);
62320- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62321+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62322 set_fs(oldfs);
62323 if (host_err < 0)
62324 goto out_nfserr;
62325@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62326 */
62327
62328 oldfs = get_fs(); set_fs(KERNEL_DS);
62329- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62330+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62331 set_fs(oldfs);
62332
62333 if (host_err < 0)
62334diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62335index 52ccd34..43a53b1 100644
62336--- a/fs/nls/nls_base.c
62337+++ b/fs/nls/nls_base.c
62338@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62339
62340 int __register_nls(struct nls_table *nls, struct module *owner)
62341 {
62342- struct nls_table ** tmp = &tables;
62343+ struct nls_table *tmp = tables;
62344
62345 if (nls->next)
62346 return -EBUSY;
62347
62348- nls->owner = owner;
62349+ pax_open_kernel();
62350+ *(void **)&nls->owner = owner;
62351+ pax_close_kernel();
62352 spin_lock(&nls_lock);
62353- while (*tmp) {
62354- if (nls == *tmp) {
62355+ while (tmp) {
62356+ if (nls == tmp) {
62357 spin_unlock(&nls_lock);
62358 return -EBUSY;
62359 }
62360- tmp = &(*tmp)->next;
62361+ tmp = tmp->next;
62362 }
62363- nls->next = tables;
62364+ pax_open_kernel();
62365+ *(struct nls_table **)&nls->next = tables;
62366+ pax_close_kernel();
62367 tables = nls;
62368 spin_unlock(&nls_lock);
62369 return 0;
62370@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62371
62372 int unregister_nls(struct nls_table * nls)
62373 {
62374- struct nls_table ** tmp = &tables;
62375+ struct nls_table * const * tmp = &tables;
62376
62377 spin_lock(&nls_lock);
62378 while (*tmp) {
62379 if (nls == *tmp) {
62380- *tmp = nls->next;
62381+ pax_open_kernel();
62382+ *(struct nls_table **)tmp = nls->next;
62383+ pax_close_kernel();
62384 spin_unlock(&nls_lock);
62385 return 0;
62386 }
62387diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62388index 162b3f1..6076a7c 100644
62389--- a/fs/nls/nls_euc-jp.c
62390+++ b/fs/nls/nls_euc-jp.c
62391@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62392 p_nls = load_nls("cp932");
62393
62394 if (p_nls) {
62395- table.charset2upper = p_nls->charset2upper;
62396- table.charset2lower = p_nls->charset2lower;
62397+ pax_open_kernel();
62398+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62399+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62400+ pax_close_kernel();
62401 return register_nls(&table);
62402 }
62403
62404diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62405index a80a741..7b96e1b 100644
62406--- a/fs/nls/nls_koi8-ru.c
62407+++ b/fs/nls/nls_koi8-ru.c
62408@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62409 p_nls = load_nls("koi8-u");
62410
62411 if (p_nls) {
62412- table.charset2upper = p_nls->charset2upper;
62413- table.charset2lower = p_nls->charset2lower;
62414+ pax_open_kernel();
62415+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62416+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62417+ pax_close_kernel();
62418 return register_nls(&table);
62419 }
62420
62421diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62422index 732648b..d3b017f 100644
62423--- a/fs/notify/fanotify/fanotify_user.c
62424+++ b/fs/notify/fanotify/fanotify_user.c
62425@@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62426
62427 fd = fanotify_event_metadata.fd;
62428 ret = -EFAULT;
62429- if (copy_to_user(buf, &fanotify_event_metadata,
62430- fanotify_event_metadata.event_len))
62431+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62432+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62433 goto out_close_fd;
62434
62435 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62436diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62437index 1e58402..bb2d6f4 100644
62438--- a/fs/notify/notification.c
62439+++ b/fs/notify/notification.c
62440@@ -48,7 +48,7 @@
62441 #include <linux/fsnotify_backend.h>
62442 #include "fsnotify.h"
62443
62444-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62445+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62446
62447 /**
62448 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62449@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62450 */
62451 u32 fsnotify_get_cookie(void)
62452 {
62453- return atomic_inc_return(&fsnotify_sync_cookie);
62454+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62455 }
62456 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62457
62458diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62459index 9e38daf..5727cae 100644
62460--- a/fs/ntfs/dir.c
62461+++ b/fs/ntfs/dir.c
62462@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62463 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62464 ~(s64)(ndir->itype.index.block_size - 1)));
62465 /* Bounds checks. */
62466- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62467+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62468 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62469 "inode 0x%lx or driver bug.", vdir->i_ino);
62470 goto err_out;
62471diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62472index db9bd8a..8338fb6 100644
62473--- a/fs/ntfs/file.c
62474+++ b/fs/ntfs/file.c
62475@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62476 char *addr;
62477 size_t total = 0;
62478 unsigned len;
62479- int left;
62480+ unsigned left;
62481
62482 do {
62483 len = PAGE_CACHE_SIZE - ofs;
62484diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62485index 9de2491..3306095 100644
62486--- a/fs/ntfs/super.c
62487+++ b/fs/ntfs/super.c
62488@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62489 if (!silent)
62490 ntfs_error(sb, "Primary boot sector is invalid.");
62491 } else if (!silent)
62492- ntfs_error(sb, read_err_str, "primary");
62493+ ntfs_error(sb, read_err_str, "%s", "primary");
62494 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62495 if (bh_primary)
62496 brelse(bh_primary);
62497@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62498 goto hotfix_primary_boot_sector;
62499 brelse(bh_backup);
62500 } else if (!silent)
62501- ntfs_error(sb, read_err_str, "backup");
62502+ ntfs_error(sb, read_err_str, "%s", "backup");
62503 /* Try to read NT3.51- backup boot sector. */
62504 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62505 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62506@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62507 "sector.");
62508 brelse(bh_backup);
62509 } else if (!silent)
62510- ntfs_error(sb, read_err_str, "backup");
62511+ ntfs_error(sb, read_err_str, "%s", "backup");
62512 /* We failed. Cleanup and return. */
62513 if (bh_primary)
62514 brelse(bh_primary);
62515diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62516index 0440134..d52c93a 100644
62517--- a/fs/ocfs2/localalloc.c
62518+++ b/fs/ocfs2/localalloc.c
62519@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62520 goto bail;
62521 }
62522
62523- atomic_inc(&osb->alloc_stats.moves);
62524+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62525
62526 bail:
62527 if (handle)
62528diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62529index 8d64a97..c37665d 100644
62530--- a/fs/ocfs2/ocfs2.h
62531+++ b/fs/ocfs2/ocfs2.h
62532@@ -236,11 +236,11 @@ enum ocfs2_vol_state
62533
62534 struct ocfs2_alloc_stats
62535 {
62536- atomic_t moves;
62537- atomic_t local_data;
62538- atomic_t bitmap_data;
62539- atomic_t bg_allocs;
62540- atomic_t bg_extends;
62541+ atomic_unchecked_t moves;
62542+ atomic_unchecked_t local_data;
62543+ atomic_unchecked_t bitmap_data;
62544+ atomic_unchecked_t bg_allocs;
62545+ atomic_unchecked_t bg_extends;
62546 };
62547
62548 enum ocfs2_local_alloc_state
62549diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62550index 0cb889a..6a26b24 100644
62551--- a/fs/ocfs2/suballoc.c
62552+++ b/fs/ocfs2/suballoc.c
62553@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62554 mlog_errno(status);
62555 goto bail;
62556 }
62557- atomic_inc(&osb->alloc_stats.bg_extends);
62558+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62559
62560 /* You should never ask for this much metadata */
62561 BUG_ON(bits_wanted >
62562@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62563 mlog_errno(status);
62564 goto bail;
62565 }
62566- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62567+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62568
62569 *suballoc_loc = res.sr_bg_blkno;
62570 *suballoc_bit_start = res.sr_bit_offset;
62571@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62572 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62573 res->sr_bits);
62574
62575- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62576+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62577
62578 BUG_ON(res->sr_bits != 1);
62579
62580@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62581 mlog_errno(status);
62582 goto bail;
62583 }
62584- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62585+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62586
62587 BUG_ON(res.sr_bits != 1);
62588
62589@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62590 cluster_start,
62591 num_clusters);
62592 if (!status)
62593- atomic_inc(&osb->alloc_stats.local_data);
62594+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62595 } else {
62596 if (min_clusters > (osb->bitmap_cpg - 1)) {
62597 /* The only paths asking for contiguousness
62598@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62599 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62600 res.sr_bg_blkno,
62601 res.sr_bit_offset);
62602- atomic_inc(&osb->alloc_stats.bitmap_data);
62603+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62604 *num_clusters = res.sr_bits;
62605 }
62606 }
62607diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62608index a7cdd56..c583144 100644
62609--- a/fs/ocfs2/super.c
62610+++ b/fs/ocfs2/super.c
62611@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62612 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62613 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62614 "Stats",
62615- atomic_read(&osb->alloc_stats.bitmap_data),
62616- atomic_read(&osb->alloc_stats.local_data),
62617- atomic_read(&osb->alloc_stats.bg_allocs),
62618- atomic_read(&osb->alloc_stats.moves),
62619- atomic_read(&osb->alloc_stats.bg_extends));
62620+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62621+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62622+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62623+ atomic_read_unchecked(&osb->alloc_stats.moves),
62624+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62625
62626 out += snprintf(buf + out, len - out,
62627 "%10s => State: %u Descriptor: %llu Size: %u bits "
62628@@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62629
62630 mutex_init(&osb->system_file_mutex);
62631
62632- atomic_set(&osb->alloc_stats.moves, 0);
62633- atomic_set(&osb->alloc_stats.local_data, 0);
62634- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62635- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62636- atomic_set(&osb->alloc_stats.bg_extends, 0);
62637+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62638+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62639+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62640+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62641+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62642
62643 /* Copy the blockcheck stats from the superblock probe */
62644 osb->osb_ecc_stats = *stats;
62645diff --git a/fs/open.c b/fs/open.c
62646index 9d64679..75f925c 100644
62647--- a/fs/open.c
62648+++ b/fs/open.c
62649@@ -32,6 +32,8 @@
62650 #include <linux/dnotify.h>
62651 #include <linux/compat.h>
62652
62653+#define CREATE_TRACE_POINTS
62654+#include <trace/events/fs.h>
62655 #include "internal.h"
62656
62657 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62658@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62659 error = locks_verify_truncate(inode, NULL, length);
62660 if (!error)
62661 error = security_path_truncate(path);
62662+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62663+ error = -EACCES;
62664 if (!error)
62665 error = do_truncate(path->dentry, length, 0, NULL);
62666
62667@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62668 error = locks_verify_truncate(inode, f.file, length);
62669 if (!error)
62670 error = security_path_truncate(&f.file->f_path);
62671+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62672+ error = -EACCES;
62673 if (!error)
62674 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62675 sb_end_write(inode->i_sb);
62676@@ -381,6 +387,9 @@ retry:
62677 if (__mnt_is_readonly(path.mnt))
62678 res = -EROFS;
62679
62680+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62681+ res = -EACCES;
62682+
62683 out_path_release:
62684 path_put(&path);
62685 if (retry_estale(res, lookup_flags)) {
62686@@ -412,6 +421,8 @@ retry:
62687 if (error)
62688 goto dput_and_out;
62689
62690+ gr_log_chdir(path.dentry, path.mnt);
62691+
62692 set_fs_pwd(current->fs, &path);
62693
62694 dput_and_out:
62695@@ -441,6 +452,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62696 goto out_putf;
62697
62698 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62699+
62700+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62701+ error = -EPERM;
62702+
62703+ if (!error)
62704+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62705+
62706 if (!error)
62707 set_fs_pwd(current->fs, &f.file->f_path);
62708 out_putf:
62709@@ -470,7 +488,13 @@ retry:
62710 if (error)
62711 goto dput_and_out;
62712
62713+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62714+ goto dput_and_out;
62715+
62716 set_fs_root(current->fs, &path);
62717+
62718+ gr_handle_chroot_chdir(&path);
62719+
62720 error = 0;
62721 dput_and_out:
62722 path_put(&path);
62723@@ -494,6 +518,16 @@ static int chmod_common(struct path *path, umode_t mode)
62724 return error;
62725 retry_deleg:
62726 mutex_lock(&inode->i_mutex);
62727+
62728+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62729+ error = -EACCES;
62730+ goto out_unlock;
62731+ }
62732+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62733+ error = -EACCES;
62734+ goto out_unlock;
62735+ }
62736+
62737 error = security_path_chmod(path, mode);
62738 if (error)
62739 goto out_unlock;
62740@@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62741 uid = make_kuid(current_user_ns(), user);
62742 gid = make_kgid(current_user_ns(), group);
62743
62744+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
62745+ return -EACCES;
62746+
62747 newattrs.ia_valid = ATTR_CTIME;
62748 if (user != (uid_t) -1) {
62749 if (!uid_valid(uid))
62750@@ -978,6 +1015,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62751 } else {
62752 fsnotify_open(f);
62753 fd_install(fd, f);
62754+ trace_do_sys_open(tmp->name, flags, mode);
62755 }
62756 }
62757 putname(tmp);
62758diff --git a/fs/pipe.c b/fs/pipe.c
62759index 034bffa..6c6b522 100644
62760--- a/fs/pipe.c
62761+++ b/fs/pipe.c
62762@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62763
62764 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62765 {
62766- if (pipe->files)
62767+ if (atomic_read(&pipe->files))
62768 mutex_lock_nested(&pipe->mutex, subclass);
62769 }
62770
62771@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62772
62773 void pipe_unlock(struct pipe_inode_info *pipe)
62774 {
62775- if (pipe->files)
62776+ if (atomic_read(&pipe->files))
62777 mutex_unlock(&pipe->mutex);
62778 }
62779 EXPORT_SYMBOL(pipe_unlock);
62780@@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
62781 }
62782 if (bufs) /* More to do? */
62783 continue;
62784- if (!pipe->writers)
62785+ if (!atomic_read(&pipe->writers))
62786 break;
62787- if (!pipe->waiting_writers) {
62788+ if (!atomic_read(&pipe->waiting_writers)) {
62789 /* syscall merging: Usually we must not sleep
62790 * if O_NONBLOCK is set, or if we got some data.
62791 * But if a writer sleeps in kernel space, then
62792@@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62793 ret = 0;
62794 __pipe_lock(pipe);
62795
62796- if (!pipe->readers) {
62797+ if (!atomic_read(&pipe->readers)) {
62798 send_sig(SIGPIPE, current, 0);
62799 ret = -EPIPE;
62800 goto out;
62801@@ -461,7 +461,7 @@ redo1:
62802 for (;;) {
62803 int bufs;
62804
62805- if (!pipe->readers) {
62806+ if (!atomic_read(&pipe->readers)) {
62807 send_sig(SIGPIPE, current, 0);
62808 if (!ret)
62809 ret = -EPIPE;
62810@@ -552,9 +552,9 @@ redo2:
62811 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62812 do_wakeup = 0;
62813 }
62814- pipe->waiting_writers++;
62815+ atomic_inc(&pipe->waiting_writers);
62816 pipe_wait(pipe);
62817- pipe->waiting_writers--;
62818+ atomic_dec(&pipe->waiting_writers);
62819 }
62820 out:
62821 __pipe_unlock(pipe);
62822@@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62823 mask = 0;
62824 if (filp->f_mode & FMODE_READ) {
62825 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62826- if (!pipe->writers && filp->f_version != pipe->w_counter)
62827+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62828 mask |= POLLHUP;
62829 }
62830
62831@@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62832 * Most Unices do not set POLLERR for FIFOs but on Linux they
62833 * behave exactly like pipes for poll().
62834 */
62835- if (!pipe->readers)
62836+ if (!atomic_read(&pipe->readers))
62837 mask |= POLLERR;
62838 }
62839
62840@@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62841 int kill = 0;
62842
62843 spin_lock(&inode->i_lock);
62844- if (!--pipe->files) {
62845+ if (atomic_dec_and_test(&pipe->files)) {
62846 inode->i_pipe = NULL;
62847 kill = 1;
62848 }
62849@@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
62850
62851 __pipe_lock(pipe);
62852 if (file->f_mode & FMODE_READ)
62853- pipe->readers--;
62854+ atomic_dec(&pipe->readers);
62855 if (file->f_mode & FMODE_WRITE)
62856- pipe->writers--;
62857+ atomic_dec(&pipe->writers);
62858
62859- if (pipe->readers || pipe->writers) {
62860+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62861 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62862 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62863 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62864@@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62865 kfree(pipe);
62866 }
62867
62868-static struct vfsmount *pipe_mnt __read_mostly;
62869+struct vfsmount *pipe_mnt __read_mostly;
62870
62871 /*
62872 * pipefs_dname() is called from d_path().
62873@@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
62874 goto fail_iput;
62875
62876 inode->i_pipe = pipe;
62877- pipe->files = 2;
62878- pipe->readers = pipe->writers = 1;
62879+ atomic_set(&pipe->files, 2);
62880+ atomic_set(&pipe->readers, 1);
62881+ atomic_set(&pipe->writers, 1);
62882 inode->i_fop = &pipefifo_fops;
62883
62884 /*
62885@@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62886 spin_lock(&inode->i_lock);
62887 if (inode->i_pipe) {
62888 pipe = inode->i_pipe;
62889- pipe->files++;
62890+ atomic_inc(&pipe->files);
62891 spin_unlock(&inode->i_lock);
62892 } else {
62893 spin_unlock(&inode->i_lock);
62894 pipe = alloc_pipe_info();
62895 if (!pipe)
62896 return -ENOMEM;
62897- pipe->files = 1;
62898+ atomic_set(&pipe->files, 1);
62899 spin_lock(&inode->i_lock);
62900 if (unlikely(inode->i_pipe)) {
62901- inode->i_pipe->files++;
62902+ atomic_inc(&inode->i_pipe->files);
62903 spin_unlock(&inode->i_lock);
62904 free_pipe_info(pipe);
62905 pipe = inode->i_pipe;
62906@@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62907 * opened, even when there is no process writing the FIFO.
62908 */
62909 pipe->r_counter++;
62910- if (pipe->readers++ == 0)
62911+ if (atomic_inc_return(&pipe->readers) == 1)
62912 wake_up_partner(pipe);
62913
62914- if (!is_pipe && !pipe->writers) {
62915+ if (!is_pipe && !atomic_read(&pipe->writers)) {
62916 if ((filp->f_flags & O_NONBLOCK)) {
62917 /* suppress POLLHUP until we have
62918 * seen a writer */
62919@@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62920 * errno=ENXIO when there is no process reading the FIFO.
62921 */
62922 ret = -ENXIO;
62923- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62924+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62925 goto err;
62926
62927 pipe->w_counter++;
62928- if (!pipe->writers++)
62929+ if (atomic_inc_return(&pipe->writers) == 1)
62930 wake_up_partner(pipe);
62931
62932- if (!is_pipe && !pipe->readers) {
62933+ if (!is_pipe && !atomic_read(&pipe->readers)) {
62934 if (wait_for_partner(pipe, &pipe->r_counter))
62935 goto err_wr;
62936 }
62937@@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62938 * the process can at least talk to itself.
62939 */
62940
62941- pipe->readers++;
62942- pipe->writers++;
62943+ atomic_inc(&pipe->readers);
62944+ atomic_inc(&pipe->writers);
62945 pipe->r_counter++;
62946 pipe->w_counter++;
62947- if (pipe->readers == 1 || pipe->writers == 1)
62948+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62949 wake_up_partner(pipe);
62950 break;
62951
62952@@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62953 return 0;
62954
62955 err_rd:
62956- if (!--pipe->readers)
62957+ if (atomic_dec_and_test(&pipe->readers))
62958 wake_up_interruptible(&pipe->wait);
62959 ret = -ERESTARTSYS;
62960 goto err;
62961
62962 err_wr:
62963- if (!--pipe->writers)
62964+ if (atomic_dec_and_test(&pipe->writers))
62965 wake_up_interruptible(&pipe->wait);
62966 ret = -ERESTARTSYS;
62967 goto err;
62968diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62969index 0855f77..6787d50 100644
62970--- a/fs/posix_acl.c
62971+++ b/fs/posix_acl.c
62972@@ -20,6 +20,7 @@
62973 #include <linux/xattr.h>
62974 #include <linux/export.h>
62975 #include <linux/user_namespace.h>
62976+#include <linux/grsecurity.h>
62977
62978 struct posix_acl **acl_by_type(struct inode *inode, int type)
62979 {
62980@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62981 }
62982 }
62983 if (mode_p)
62984- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62985+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62986 return not_equiv;
62987 }
62988 EXPORT_SYMBOL(posix_acl_equiv_mode);
62989@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62990 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62991 }
62992
62993- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62994+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62995 return not_equiv;
62996 }
62997
62998@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62999 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63000 int err = -ENOMEM;
63001 if (clone) {
63002+ *mode_p &= ~gr_acl_umask();
63003+
63004 err = posix_acl_create_masq(clone, mode_p);
63005 if (err < 0) {
63006 posix_acl_release(clone);
63007@@ -659,11 +662,12 @@ struct posix_acl *
63008 posix_acl_from_xattr(struct user_namespace *user_ns,
63009 const void *value, size_t size)
63010 {
63011- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63012- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63013+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63014+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63015 int count;
63016 struct posix_acl *acl;
63017 struct posix_acl_entry *acl_e;
63018+ umode_t umask = gr_acl_umask();
63019
63020 if (!value)
63021 return NULL;
63022@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63023
63024 switch(acl_e->e_tag) {
63025 case ACL_USER_OBJ:
63026+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63027+ break;
63028 case ACL_GROUP_OBJ:
63029 case ACL_MASK:
63030+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63031+ break;
63032 case ACL_OTHER:
63033+ acl_e->e_perm &= ~(umask & S_IRWXO);
63034 break;
63035
63036 case ACL_USER:
63037+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63038 acl_e->e_uid =
63039 make_kuid(user_ns,
63040 le32_to_cpu(entry->e_id));
63041@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63042 goto fail;
63043 break;
63044 case ACL_GROUP:
63045+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63046 acl_e->e_gid =
63047 make_kgid(user_ns,
63048 le32_to_cpu(entry->e_id));
63049diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63050index 2183fcf..3c32a98 100644
63051--- a/fs/proc/Kconfig
63052+++ b/fs/proc/Kconfig
63053@@ -30,7 +30,7 @@ config PROC_FS
63054
63055 config PROC_KCORE
63056 bool "/proc/kcore support" if !ARM
63057- depends on PROC_FS && MMU
63058+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63059 help
63060 Provides a virtual ELF core file of the live kernel. This can
63061 be read with gdb and other ELF tools. No modifications can be
63062@@ -38,8 +38,8 @@ config PROC_KCORE
63063
63064 config PROC_VMCORE
63065 bool "/proc/vmcore support"
63066- depends on PROC_FS && CRASH_DUMP
63067- default y
63068+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63069+ default n
63070 help
63071 Exports the dump image of crashed kernel in ELF format.
63072
63073@@ -63,8 +63,8 @@ config PROC_SYSCTL
63074 limited in memory.
63075
63076 config PROC_PAGE_MONITOR
63077- default y
63078- depends on PROC_FS && MMU
63079+ default n
63080+ depends on PROC_FS && MMU && !GRKERNSEC
63081 bool "Enable /proc page monitoring" if EXPERT
63082 help
63083 Various /proc files exist to monitor process memory utilization:
63084diff --git a/fs/proc/array.c b/fs/proc/array.c
63085index 64db2bc..a8185d6 100644
63086--- a/fs/proc/array.c
63087+++ b/fs/proc/array.c
63088@@ -60,6 +60,7 @@
63089 #include <linux/tty.h>
63090 #include <linux/string.h>
63091 #include <linux/mman.h>
63092+#include <linux/grsecurity.h>
63093 #include <linux/proc_fs.h>
63094 #include <linux/ioport.h>
63095 #include <linux/uaccess.h>
63096@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63097 seq_putc(m, '\n');
63098 }
63099
63100+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63101+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63102+{
63103+ if (p->mm)
63104+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63105+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63106+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63107+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63108+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63109+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63110+ else
63111+ seq_printf(m, "PaX:\t-----\n");
63112+}
63113+#endif
63114+
63115 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63116 struct pid *pid, struct task_struct *task)
63117 {
63118@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63119 task_cpus_allowed(m, task);
63120 cpuset_task_status_allowed(m, task);
63121 task_context_switch_counts(m, task);
63122+
63123+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63124+ task_pax(m, task);
63125+#endif
63126+
63127+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63128+ task_grsec_rbac(m, task);
63129+#endif
63130+
63131 return 0;
63132 }
63133
63134+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63135+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63136+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63137+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63138+#endif
63139+
63140 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63141 struct pid *pid, struct task_struct *task, int whole)
63142 {
63143@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63144 char tcomm[sizeof(task->comm)];
63145 unsigned long flags;
63146
63147+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63148+ if (current->exec_id != m->exec_id) {
63149+ gr_log_badprocpid("stat");
63150+ return 0;
63151+ }
63152+#endif
63153+
63154 state = *get_task_state(task);
63155 vsize = eip = esp = 0;
63156 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63157@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63158 gtime = task_gtime(task);
63159 }
63160
63161+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63162+ if (PAX_RAND_FLAGS(mm)) {
63163+ eip = 0;
63164+ esp = 0;
63165+ wchan = 0;
63166+ }
63167+#endif
63168+#ifdef CONFIG_GRKERNSEC_HIDESYM
63169+ wchan = 0;
63170+ eip =0;
63171+ esp =0;
63172+#endif
63173+
63174 /* scale priority and nice values from timeslices to -20..20 */
63175 /* to make it look like a "normal" Unix priority/nice value */
63176 priority = task_prio(task);
63177@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63178 seq_put_decimal_ull(m, ' ', vsize);
63179 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63180 seq_put_decimal_ull(m, ' ', rsslim);
63181+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63182+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63183+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63184+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63185+#else
63186 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63187 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63188 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63189+#endif
63190 seq_put_decimal_ull(m, ' ', esp);
63191 seq_put_decimal_ull(m, ' ', eip);
63192 /* The signal information here is obsolete.
63193@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63194 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63195 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63196
63197- if (mm && permitted) {
63198+ if (mm && permitted
63199+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63200+ && !PAX_RAND_FLAGS(mm)
63201+#endif
63202+ ) {
63203 seq_put_decimal_ull(m, ' ', mm->start_data);
63204 seq_put_decimal_ull(m, ' ', mm->end_data);
63205 seq_put_decimal_ull(m, ' ', mm->start_brk);
63206@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63207 struct pid *pid, struct task_struct *task)
63208 {
63209 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63210- struct mm_struct *mm = get_task_mm(task);
63211+ struct mm_struct *mm;
63212
63213+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63214+ if (current->exec_id != m->exec_id) {
63215+ gr_log_badprocpid("statm");
63216+ return 0;
63217+ }
63218+#endif
63219+ mm = get_task_mm(task);
63220 if (mm) {
63221 size = task_statm(mm, &shared, &text, &data, &resident);
63222 mmput(mm);
63223@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63224 return 0;
63225 }
63226
63227+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63228+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63229+{
63230+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63231+}
63232+#endif
63233+
63234 #ifdef CONFIG_CHECKPOINT_RESTORE
63235 static struct pid *
63236 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63237diff --git a/fs/proc/base.c b/fs/proc/base.c
63238index 2d696b0..b9da447 100644
63239--- a/fs/proc/base.c
63240+++ b/fs/proc/base.c
63241@@ -113,6 +113,14 @@ struct pid_entry {
63242 union proc_op op;
63243 };
63244
63245+struct getdents_callback {
63246+ struct linux_dirent __user * current_dir;
63247+ struct linux_dirent __user * previous;
63248+ struct file * file;
63249+ int count;
63250+ int error;
63251+};
63252+
63253 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63254 .name = (NAME), \
63255 .len = sizeof(NAME) - 1, \
63256@@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63257 return get_cmdline(task, buffer, PAGE_SIZE);
63258 }
63259
63260+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63261+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63262+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63263+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63264+#endif
63265+
63266 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63267 {
63268 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63269 int res = PTR_ERR(mm);
63270 if (mm && !IS_ERR(mm)) {
63271 unsigned int nwords = 0;
63272+
63273+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63274+ /* allow if we're currently ptracing this task */
63275+ if (PAX_RAND_FLAGS(mm) &&
63276+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63277+ mmput(mm);
63278+ return 0;
63279+ }
63280+#endif
63281+
63282 do {
63283 nwords += 2;
63284 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63285@@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63286 }
63287
63288
63289-#ifdef CONFIG_KALLSYMS
63290+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63291 /*
63292 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63293 * Returns the resolved symbol. If that fails, simply return the address.
63294@@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63295 mutex_unlock(&task->signal->cred_guard_mutex);
63296 }
63297
63298-#ifdef CONFIG_STACKTRACE
63299+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63300
63301 #define MAX_STACK_TRACE_DEPTH 64
63302
63303@@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63304 return count;
63305 }
63306
63307-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63308+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63309 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63310 {
63311 long nr;
63312@@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63313 /************************************************************************/
63314
63315 /* permission checks */
63316-static int proc_fd_access_allowed(struct inode *inode)
63317+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63318 {
63319 struct task_struct *task;
63320 int allowed = 0;
63321@@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63322 */
63323 task = get_proc_task(inode);
63324 if (task) {
63325- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63326+ if (log)
63327+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63328+ else
63329+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63330 put_task_struct(task);
63331 }
63332 return allowed;
63333@@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63334 struct task_struct *task,
63335 int hide_pid_min)
63336 {
63337+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63338+ return false;
63339+
63340+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63341+ rcu_read_lock();
63342+ {
63343+ const struct cred *tmpcred = current_cred();
63344+ const struct cred *cred = __task_cred(task);
63345+
63346+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63347+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63348+ || in_group_p(grsec_proc_gid)
63349+#endif
63350+ ) {
63351+ rcu_read_unlock();
63352+ return true;
63353+ }
63354+ }
63355+ rcu_read_unlock();
63356+
63357+ if (!pid->hide_pid)
63358+ return false;
63359+#endif
63360+
63361 if (pid->hide_pid < hide_pid_min)
63362 return true;
63363 if (in_group_p(pid->pid_gid))
63364 return true;
63365+
63366 return ptrace_may_access(task, PTRACE_MODE_READ);
63367 }
63368
63369@@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63370 put_task_struct(task);
63371
63372 if (!has_perms) {
63373+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63374+ {
63375+#else
63376 if (pid->hide_pid == 2) {
63377+#endif
63378 /*
63379 * Let's make getdents(), stat(), and open()
63380 * consistent with each other. If a process
63381@@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63382 if (!task)
63383 return -ESRCH;
63384
63385+ if (gr_acl_handle_procpidmem(task)) {
63386+ put_task_struct(task);
63387+ return -EPERM;
63388+ }
63389+
63390 mm = mm_access(task, mode);
63391 put_task_struct(task);
63392
63393@@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63394
63395 file->private_data = mm;
63396
63397+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63398+ file->f_version = current->exec_id;
63399+#endif
63400+
63401 return 0;
63402 }
63403
63404@@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63405 ssize_t copied;
63406 char *page;
63407
63408+#ifdef CONFIG_GRKERNSEC
63409+ if (write)
63410+ return -EPERM;
63411+#endif
63412+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63413+ if (file->f_version != current->exec_id) {
63414+ gr_log_badprocpid("mem");
63415+ return 0;
63416+ }
63417+#endif
63418+
63419 if (!mm)
63420 return 0;
63421
63422@@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63423 goto free;
63424
63425 while (count > 0) {
63426- int this_len = min_t(int, count, PAGE_SIZE);
63427+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63428
63429 if (write && copy_from_user(page, buf, this_len)) {
63430 copied = -EFAULT;
63431@@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63432 if (!mm)
63433 return 0;
63434
63435+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63436+ if (file->f_version != current->exec_id) {
63437+ gr_log_badprocpid("environ");
63438+ return 0;
63439+ }
63440+#endif
63441+
63442 page = (char *)__get_free_page(GFP_TEMPORARY);
63443 if (!page)
63444 return -ENOMEM;
63445@@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63446 goto free;
63447 while (count > 0) {
63448 size_t this_len, max_len;
63449- int retval;
63450+ ssize_t retval;
63451
63452 if (src >= (mm->env_end - mm->env_start))
63453 break;
63454@@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63455 int error = -EACCES;
63456
63457 /* Are we allowed to snoop on the tasks file descriptors? */
63458- if (!proc_fd_access_allowed(inode))
63459+ if (!proc_fd_access_allowed(inode, 0))
63460 goto out;
63461
63462 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63463@@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63464 struct path path;
63465
63466 /* Are we allowed to snoop on the tasks file descriptors? */
63467- if (!proc_fd_access_allowed(inode))
63468- goto out;
63469+ /* logging this is needed for learning on chromium to work properly,
63470+ but we don't want to flood the logs from 'ps' which does a readlink
63471+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63472+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63473+ */
63474+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63475+ if (!proc_fd_access_allowed(inode,0))
63476+ goto out;
63477+ } else {
63478+ if (!proc_fd_access_allowed(inode,1))
63479+ goto out;
63480+ }
63481
63482 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63483 if (error)
63484@@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63485 rcu_read_lock();
63486 cred = __task_cred(task);
63487 inode->i_uid = cred->euid;
63488+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63489+ inode->i_gid = grsec_proc_gid;
63490+#else
63491 inode->i_gid = cred->egid;
63492+#endif
63493 rcu_read_unlock();
63494 }
63495 security_task_to_inode(task, inode);
63496@@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63497 return -ENOENT;
63498 }
63499 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63500+#ifdef CONFIG_GRKERNSEC_PROC_USER
63501+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63502+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63503+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63504+#endif
63505 task_dumpable(task)) {
63506 cred = __task_cred(task);
63507 stat->uid = cred->euid;
63508+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63509+ stat->gid = grsec_proc_gid;
63510+#else
63511 stat->gid = cred->egid;
63512+#endif
63513 }
63514 }
63515 rcu_read_unlock();
63516@@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63517
63518 if (task) {
63519 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63520+#ifdef CONFIG_GRKERNSEC_PROC_USER
63521+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63522+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63523+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63524+#endif
63525 task_dumpable(task)) {
63526 rcu_read_lock();
63527 cred = __task_cred(task);
63528 inode->i_uid = cred->euid;
63529+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63530+ inode->i_gid = grsec_proc_gid;
63531+#else
63532 inode->i_gid = cred->egid;
63533+#endif
63534 rcu_read_unlock();
63535 } else {
63536 inode->i_uid = GLOBAL_ROOT_UID;
63537@@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63538 if (!task)
63539 goto out_no_task;
63540
63541+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63542+ goto out;
63543+
63544 /*
63545 * Yes, it does not scale. And it should not. Don't add
63546 * new entries into /proc/<tgid>/ without very good reasons.
63547@@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63548 if (!task)
63549 return -ENOENT;
63550
63551+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63552+ goto out;
63553+
63554 if (!dir_emit_dots(file, ctx))
63555 goto out;
63556
63557@@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63558 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63559 #endif
63560 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63561-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63562+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63563 INF("syscall", S_IRUSR, proc_pid_syscall),
63564 #endif
63565 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63566@@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63567 #ifdef CONFIG_SECURITY
63568 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63569 #endif
63570-#ifdef CONFIG_KALLSYMS
63571+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63572 INF("wchan", S_IRUGO, proc_pid_wchan),
63573 #endif
63574-#ifdef CONFIG_STACKTRACE
63575+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63576 ONE("stack", S_IRUSR, proc_pid_stack),
63577 #endif
63578 #ifdef CONFIG_SCHEDSTATS
63579@@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63580 #ifdef CONFIG_HARDWALL
63581 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63582 #endif
63583+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63584+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63585+#endif
63586 #ifdef CONFIG_USER_NS
63587 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63588 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63589@@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
63590 if (!inode)
63591 goto out;
63592
63593+#ifdef CONFIG_GRKERNSEC_PROC_USER
63594+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63595+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63596+ inode->i_gid = grsec_proc_gid;
63597+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63598+#else
63599 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63600+#endif
63601 inode->i_op = &proc_tgid_base_inode_operations;
63602 inode->i_fop = &proc_tgid_base_operations;
63603 inode->i_flags|=S_IMMUTABLE;
63604@@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63605 if (!task)
63606 goto out;
63607
63608+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63609+ goto out_put_task;
63610+
63611 result = proc_pid_instantiate(dir, dentry, task, NULL);
63612+out_put_task:
63613 put_task_struct(task);
63614 out:
63615 return ERR_PTR(result);
63616@@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
63617 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63618 #endif
63619 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63620-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63621+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63622 INF("syscall", S_IRUSR, proc_pid_syscall),
63623 #endif
63624 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63625@@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
63626 #ifdef CONFIG_SECURITY
63627 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63628 #endif
63629-#ifdef CONFIG_KALLSYMS
63630+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63631 INF("wchan", S_IRUGO, proc_pid_wchan),
63632 #endif
63633-#ifdef CONFIG_STACKTRACE
63634+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63635 ONE("stack", S_IRUSR, proc_pid_stack),
63636 #endif
63637 #ifdef CONFIG_SCHEDSTATS
63638diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63639index cbd82df..c0407d2 100644
63640--- a/fs/proc/cmdline.c
63641+++ b/fs/proc/cmdline.c
63642@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63643
63644 static int __init proc_cmdline_init(void)
63645 {
63646+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63647+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63648+#else
63649 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63650+#endif
63651 return 0;
63652 }
63653 fs_initcall(proc_cmdline_init);
63654diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63655index 50493ed..248166b 100644
63656--- a/fs/proc/devices.c
63657+++ b/fs/proc/devices.c
63658@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63659
63660 static int __init proc_devices_init(void)
63661 {
63662+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63663+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63664+#else
63665 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63666+#endif
63667 return 0;
63668 }
63669 fs_initcall(proc_devices_init);
63670diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63671index 0788d09..9cc1385 100644
63672--- a/fs/proc/fd.c
63673+++ b/fs/proc/fd.c
63674@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
63675 if (!task)
63676 return -ENOENT;
63677
63678- files = get_files_struct(task);
63679+ if (!gr_acl_handle_procpidmem(task))
63680+ files = get_files_struct(task);
63681 put_task_struct(task);
63682
63683 if (files) {
63684@@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63685 */
63686 int proc_fd_permission(struct inode *inode, int mask)
63687 {
63688+ struct task_struct *task;
63689 int rv = generic_permission(inode, mask);
63690- if (rv == 0)
63691- return 0;
63692+
63693 if (task_tgid(current) == proc_pid(inode))
63694 rv = 0;
63695+
63696+ task = get_proc_task(inode);
63697+ if (task == NULL)
63698+ return rv;
63699+
63700+ if (gr_acl_handle_procpidmem(task))
63701+ rv = -EACCES;
63702+
63703+ put_task_struct(task);
63704+
63705 return rv;
63706 }
63707
63708diff --git a/fs/proc/generic.c b/fs/proc/generic.c
63709index b7f268e..3bea6b7 100644
63710--- a/fs/proc/generic.c
63711+++ b/fs/proc/generic.c
63712@@ -23,6 +23,7 @@
63713 #include <linux/bitops.h>
63714 #include <linux/spinlock.h>
63715 #include <linux/completion.h>
63716+#include <linux/grsecurity.h>
63717 #include <asm/uaccess.h>
63718
63719 #include "internal.h"
63720@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
63721 return proc_lookup_de(PDE(dir), dir, dentry);
63722 }
63723
63724+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
63725+ unsigned int flags)
63726+{
63727+ if (gr_proc_is_restricted())
63728+ return ERR_PTR(-EACCES);
63729+
63730+ return proc_lookup_de(PDE(dir), dir, dentry);
63731+}
63732+
63733 /*
63734 * This returns non-zero if at EOF, so that the /proc
63735 * root directory can use this and check if it should
63736@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
63737 return proc_readdir_de(PDE(inode), file, ctx);
63738 }
63739
63740+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
63741+{
63742+ struct inode *inode = file_inode(file);
63743+
63744+ if (gr_proc_is_restricted())
63745+ return -EACCES;
63746+
63747+ return proc_readdir_de(PDE(inode), file, ctx);
63748+}
63749+
63750 /*
63751 * These are the generic /proc directory operations. They
63752 * use the in-memory "struct proc_dir_entry" tree to parse
63753@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
63754 .iterate = proc_readdir,
63755 };
63756
63757+static const struct file_operations proc_dir_restricted_operations = {
63758+ .llseek = generic_file_llseek,
63759+ .read = generic_read_dir,
63760+ .iterate = proc_readdir_restrict,
63761+};
63762+
63763 /*
63764 * proc directories can do almost nothing..
63765 */
63766@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
63767 .setattr = proc_notify_change,
63768 };
63769
63770+static const struct inode_operations proc_dir_restricted_inode_operations = {
63771+ .lookup = proc_lookup_restrict,
63772+ .getattr = proc_getattr,
63773+ .setattr = proc_notify_change,
63774+};
63775+
63776 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
63777 {
63778 struct proc_dir_entry *tmp;
63779@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
63780 return ret;
63781
63782 if (S_ISDIR(dp->mode)) {
63783- dp->proc_fops = &proc_dir_operations;
63784- dp->proc_iops = &proc_dir_inode_operations;
63785+ if (dp->restricted) {
63786+ dp->proc_fops = &proc_dir_restricted_operations;
63787+ dp->proc_iops = &proc_dir_restricted_inode_operations;
63788+ } else {
63789+ dp->proc_fops = &proc_dir_operations;
63790+ dp->proc_iops = &proc_dir_inode_operations;
63791+ }
63792 dir->nlink++;
63793 } else if (S_ISLNK(dp->mode)) {
63794 dp->proc_iops = &proc_link_inode_operations;
63795@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
63796 }
63797 EXPORT_SYMBOL_GPL(proc_mkdir_data);
63798
63799+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
63800+ struct proc_dir_entry *parent, void *data)
63801+{
63802+ struct proc_dir_entry *ent;
63803+
63804+ if (mode == 0)
63805+ mode = S_IRUGO | S_IXUGO;
63806+
63807+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
63808+ if (ent) {
63809+ ent->data = data;
63810+ ent->restricted = 1;
63811+ if (proc_register(parent, ent) < 0) {
63812+ kfree(ent);
63813+ ent = NULL;
63814+ }
63815+ }
63816+ return ent;
63817+}
63818+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
63819+
63820 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
63821 struct proc_dir_entry *parent)
63822 {
63823@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
63824 }
63825 EXPORT_SYMBOL(proc_mkdir);
63826
63827+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
63828+ struct proc_dir_entry *parent)
63829+{
63830+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
63831+}
63832+EXPORT_SYMBOL(proc_mkdir_restrict);
63833+
63834 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
63835 struct proc_dir_entry *parent,
63836 const struct file_operations *proc_fops,
63837diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63838index 0adbc02..bee4d0b 100644
63839--- a/fs/proc/inode.c
63840+++ b/fs/proc/inode.c
63841@@ -23,11 +23,17 @@
63842 #include <linux/slab.h>
63843 #include <linux/mount.h>
63844 #include <linux/magic.h>
63845+#include <linux/grsecurity.h>
63846
63847 #include <asm/uaccess.h>
63848
63849 #include "internal.h"
63850
63851+#ifdef CONFIG_PROC_SYSCTL
63852+extern const struct inode_operations proc_sys_inode_operations;
63853+extern const struct inode_operations proc_sys_dir_operations;
63854+#endif
63855+
63856 static void proc_evict_inode(struct inode *inode)
63857 {
63858 struct proc_dir_entry *de;
63859@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63860 ns = PROC_I(inode)->ns.ns;
63861 if (ns_ops && ns)
63862 ns_ops->put(ns);
63863+
63864+#ifdef CONFIG_PROC_SYSCTL
63865+ if (inode->i_op == &proc_sys_inode_operations ||
63866+ inode->i_op == &proc_sys_dir_operations)
63867+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63868+#endif
63869+
63870 }
63871
63872 static struct kmem_cache * proc_inode_cachep;
63873@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63874 if (de->mode) {
63875 inode->i_mode = de->mode;
63876 inode->i_uid = de->uid;
63877+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63878+ inode->i_gid = grsec_proc_gid;
63879+#else
63880 inode->i_gid = de->gid;
63881+#endif
63882 }
63883 if (de->size)
63884 inode->i_size = de->size;
63885diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63886index 3ab6d14..b26174e 100644
63887--- a/fs/proc/internal.h
63888+++ b/fs/proc/internal.h
63889@@ -46,9 +46,10 @@ struct proc_dir_entry {
63890 struct completion *pde_unload_completion;
63891 struct list_head pde_openers; /* who did ->open, but not ->release */
63892 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63893+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
63894 u8 namelen;
63895 char name[];
63896-};
63897+} __randomize_layout;
63898
63899 union proc_op {
63900 int (*proc_get_link)(struct dentry *, struct path *);
63901@@ -67,7 +68,7 @@ struct proc_inode {
63902 struct ctl_table *sysctl_entry;
63903 struct proc_ns ns;
63904 struct inode vfs_inode;
63905-};
63906+} __randomize_layout;
63907
63908 /*
63909 * General functions
63910@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63911 struct pid *, struct task_struct *);
63912 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63913 struct pid *, struct task_struct *);
63914+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63915+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63916+#endif
63917
63918 /*
63919 * base.c
63920@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
63921 extern spinlock_t proc_subdir_lock;
63922
63923 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
63924+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
63925 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
63926 struct dentry *);
63927 extern int proc_readdir(struct file *, struct dir_context *);
63928+extern int proc_readdir_restrict(struct file *, struct dir_context *);
63929 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
63930
63931 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
63932diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63933index a352d57..cb94a5c 100644
63934--- a/fs/proc/interrupts.c
63935+++ b/fs/proc/interrupts.c
63936@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63937
63938 static int __init proc_interrupts_init(void)
63939 {
63940+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63941+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63942+#else
63943 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63944+#endif
63945 return 0;
63946 }
63947 fs_initcall(proc_interrupts_init);
63948diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63949index 39e6ef3..2f9cb5e 100644
63950--- a/fs/proc/kcore.c
63951+++ b/fs/proc/kcore.c
63952@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63953 * the addresses in the elf_phdr on our list.
63954 */
63955 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63956- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63957+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63958+ if (tsz > buflen)
63959 tsz = buflen;
63960-
63961+
63962 while (buflen) {
63963 struct kcore_list *m;
63964
63965@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63966 kfree(elf_buf);
63967 } else {
63968 if (kern_addr_valid(start)) {
63969- unsigned long n;
63970+ char *elf_buf;
63971+ mm_segment_t oldfs;
63972
63973- n = copy_to_user(buffer, (char *)start, tsz);
63974- /*
63975- * We cannot distinguish between fault on source
63976- * and fault on destination. When this happens
63977- * we clear too and hope it will trigger the
63978- * EFAULT again.
63979- */
63980- if (n) {
63981- if (clear_user(buffer + tsz - n,
63982- n))
63983+ elf_buf = kmalloc(tsz, GFP_KERNEL);
63984+ if (!elf_buf)
63985+ return -ENOMEM;
63986+ oldfs = get_fs();
63987+ set_fs(KERNEL_DS);
63988+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63989+ set_fs(oldfs);
63990+ if (copy_to_user(buffer, elf_buf, tsz)) {
63991+ kfree(elf_buf);
63992 return -EFAULT;
63993+ }
63994 }
63995+ set_fs(oldfs);
63996+ kfree(elf_buf);
63997 } else {
63998 if (clear_user(buffer, tsz))
63999 return -EFAULT;
64000@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64001
64002 static int open_kcore(struct inode *inode, struct file *filp)
64003 {
64004+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64005+ return -EPERM;
64006+#endif
64007 if (!capable(CAP_SYS_RAWIO))
64008 return -EPERM;
64009 if (kcore_need_update)
64010diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64011index 7445af0..7c5113c 100644
64012--- a/fs/proc/meminfo.c
64013+++ b/fs/proc/meminfo.c
64014@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64015 vmi.used >> 10,
64016 vmi.largest_chunk >> 10
64017 #ifdef CONFIG_MEMORY_FAILURE
64018- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64019+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64020 #endif
64021 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64022 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64023diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64024index d4a3574..b421ce9 100644
64025--- a/fs/proc/nommu.c
64026+++ b/fs/proc/nommu.c
64027@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64028
64029 if (file) {
64030 seq_pad(m, ' ');
64031- seq_path(m, &file->f_path, "");
64032+ seq_path(m, &file->f_path, "\n\\");
64033 }
64034
64035 seq_putc(m, '\n');
64036diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64037index 4677bb7..94067cd 100644
64038--- a/fs/proc/proc_net.c
64039+++ b/fs/proc/proc_net.c
64040@@ -23,6 +23,7 @@
64041 #include <linux/nsproxy.h>
64042 #include <net/net_namespace.h>
64043 #include <linux/seq_file.h>
64044+#include <linux/grsecurity.h>
64045
64046 #include "internal.h"
64047
64048@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
64049 return maybe_get_net(PDE_NET(PDE(inode)));
64050 }
64051
64052+extern const struct seq_operations dev_seq_ops;
64053+
64054 int seq_open_net(struct inode *ino, struct file *f,
64055 const struct seq_operations *ops, int size)
64056 {
64057@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
64058
64059 BUG_ON(size < sizeof(*p));
64060
64061+ /* only permit access to /proc/net/dev */
64062+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
64063+ return -EACCES;
64064+
64065 net = get_proc_net(ino);
64066 if (net == NULL)
64067 return -ENXIO;
64068@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
64069 int err;
64070 struct net *net;
64071
64072+ if (gr_proc_is_restricted())
64073+ return -EACCES;
64074+
64075 err = -ENXIO;
64076 net = get_proc_net(inode);
64077 if (net == NULL)
64078diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64079index 7129046..6914844 100644
64080--- a/fs/proc/proc_sysctl.c
64081+++ b/fs/proc/proc_sysctl.c
64082@@ -11,13 +11,21 @@
64083 #include <linux/namei.h>
64084 #include <linux/mm.h>
64085 #include <linux/module.h>
64086+#include <linux/nsproxy.h>
64087+#ifdef CONFIG_GRKERNSEC
64088+#include <net/net_namespace.h>
64089+#endif
64090 #include "internal.h"
64091
64092+extern int gr_handle_chroot_sysctl(const int op);
64093+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64094+ const int op);
64095+
64096 static const struct dentry_operations proc_sys_dentry_operations;
64097 static const struct file_operations proc_sys_file_operations;
64098-static const struct inode_operations proc_sys_inode_operations;
64099+const struct inode_operations proc_sys_inode_operations;
64100 static const struct file_operations proc_sys_dir_file_operations;
64101-static const struct inode_operations proc_sys_dir_operations;
64102+const struct inode_operations proc_sys_dir_operations;
64103
64104 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64105 {
64106@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64107
64108 err = NULL;
64109 d_set_d_op(dentry, &proc_sys_dentry_operations);
64110+
64111+ gr_handle_proc_create(dentry, inode);
64112+
64113 d_add(dentry, inode);
64114
64115 out:
64116@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64117 struct inode *inode = file_inode(filp);
64118 struct ctl_table_header *head = grab_header(inode);
64119 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64120+ int op = write ? MAY_WRITE : MAY_READ;
64121 ssize_t error;
64122 size_t res;
64123
64124@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64125 * and won't be until we finish.
64126 */
64127 error = -EPERM;
64128- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64129+ if (sysctl_perm(head, table, op))
64130 goto out;
64131
64132 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64133@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64134 if (!table->proc_handler)
64135 goto out;
64136
64137+#ifdef CONFIG_GRKERNSEC
64138+ error = -EPERM;
64139+ if (gr_handle_chroot_sysctl(op))
64140+ goto out;
64141+ dget(filp->f_path.dentry);
64142+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64143+ dput(filp->f_path.dentry);
64144+ goto out;
64145+ }
64146+ dput(filp->f_path.dentry);
64147+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64148+ goto out;
64149+ if (write) {
64150+ if (current->nsproxy->net_ns != table->extra2) {
64151+ if (!capable(CAP_SYS_ADMIN))
64152+ goto out;
64153+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64154+ goto out;
64155+ }
64156+#endif
64157+
64158 /* careful: calling conventions are nasty here */
64159 res = count;
64160 error = table->proc_handler(table, write, buf, &res, ppos);
64161@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64162 return false;
64163 } else {
64164 d_set_d_op(child, &proc_sys_dentry_operations);
64165+
64166+ gr_handle_proc_create(child, inode);
64167+
64168 d_add(child, inode);
64169 }
64170 } else {
64171@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64172 if ((*pos)++ < ctx->pos)
64173 return true;
64174
64175+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64176+ return 0;
64177+
64178 if (unlikely(S_ISLNK(table->mode)))
64179 res = proc_sys_link_fill_cache(file, ctx, head, table);
64180 else
64181@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64182 if (IS_ERR(head))
64183 return PTR_ERR(head);
64184
64185+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64186+ return -ENOENT;
64187+
64188 generic_fillattr(inode, stat);
64189 if (table)
64190 stat->mode = (stat->mode & S_IFMT) | table->mode;
64191@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64192 .llseek = generic_file_llseek,
64193 };
64194
64195-static const struct inode_operations proc_sys_inode_operations = {
64196+const struct inode_operations proc_sys_inode_operations = {
64197 .permission = proc_sys_permission,
64198 .setattr = proc_sys_setattr,
64199 .getattr = proc_sys_getattr,
64200 };
64201
64202-static const struct inode_operations proc_sys_dir_operations = {
64203+const struct inode_operations proc_sys_dir_operations = {
64204 .lookup = proc_sys_lookup,
64205 .permission = proc_sys_permission,
64206 .setattr = proc_sys_setattr,
64207@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64208 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64209 const char *name, int namelen)
64210 {
64211- struct ctl_table *table;
64212+ ctl_table_no_const *table;
64213 struct ctl_dir *new;
64214 struct ctl_node *node;
64215 char *new_name;
64216@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64217 return NULL;
64218
64219 node = (struct ctl_node *)(new + 1);
64220- table = (struct ctl_table *)(node + 1);
64221+ table = (ctl_table_no_const *)(node + 1);
64222 new_name = (char *)(table + 2);
64223 memcpy(new_name, name, namelen);
64224 new_name[namelen] = '\0';
64225@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64226 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64227 struct ctl_table_root *link_root)
64228 {
64229- struct ctl_table *link_table, *entry, *link;
64230+ ctl_table_no_const *link_table, *link;
64231+ struct ctl_table *entry;
64232 struct ctl_table_header *links;
64233 struct ctl_node *node;
64234 char *link_name;
64235@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64236 return NULL;
64237
64238 node = (struct ctl_node *)(links + 1);
64239- link_table = (struct ctl_table *)(node + nr_entries);
64240+ link_table = (ctl_table_no_const *)(node + nr_entries);
64241 link_name = (char *)&link_table[nr_entries + 1];
64242
64243 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64244@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64245 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64246 struct ctl_table *table)
64247 {
64248- struct ctl_table *ctl_table_arg = NULL;
64249- struct ctl_table *entry, *files;
64250+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64251+ struct ctl_table *entry;
64252 int nr_files = 0;
64253 int nr_dirs = 0;
64254 int err = -ENOMEM;
64255@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64256 nr_files++;
64257 }
64258
64259- files = table;
64260 /* If there are mixed files and directories we need a new table */
64261 if (nr_dirs && nr_files) {
64262- struct ctl_table *new;
64263+ ctl_table_no_const *new;
64264 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64265 GFP_KERNEL);
64266 if (!files)
64267@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64268 /* Register everything except a directory full of subdirectories */
64269 if (nr_files || !nr_dirs) {
64270 struct ctl_table_header *header;
64271- header = __register_sysctl_table(set, path, files);
64272+ header = __register_sysctl_table(set, path, files ? files : table);
64273 if (!header) {
64274 kfree(ctl_table_arg);
64275 goto out;
64276diff --git a/fs/proc/root.c b/fs/proc/root.c
64277index 5dbadec..473af2f 100644
64278--- a/fs/proc/root.c
64279+++ b/fs/proc/root.c
64280@@ -185,7 +185,15 @@ void __init proc_root_init(void)
64281 proc_mkdir("openprom", NULL);
64282 #endif
64283 proc_tty_init();
64284+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64285+#ifdef CONFIG_GRKERNSEC_PROC_USER
64286+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64287+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64288+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64289+#endif
64290+#else
64291 proc_mkdir("bus", NULL);
64292+#endif
64293 proc_sys_init();
64294 }
64295
64296diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64297index 9d231e9..2e1b51a 100644
64298--- a/fs/proc/stat.c
64299+++ b/fs/proc/stat.c
64300@@ -11,6 +11,7 @@
64301 #include <linux/irqnr.h>
64302 #include <linux/cputime.h>
64303 #include <linux/tick.h>
64304+#include <linux/grsecurity.h>
64305
64306 #ifndef arch_irq_stat_cpu
64307 #define arch_irq_stat_cpu(cpu) 0
64308@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64309 u64 sum_softirq = 0;
64310 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64311 struct timespec boottime;
64312+ int unrestricted = 1;
64313+
64314+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64315+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64316+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64317+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64318+ && !in_group_p(grsec_proc_gid)
64319+#endif
64320+ )
64321+ unrestricted = 0;
64322+#endif
64323+#endif
64324
64325 user = nice = system = idle = iowait =
64326 irq = softirq = steal = 0;
64327@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64328 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64329 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64330 idle += get_idle_time(i);
64331- iowait += get_iowait_time(i);
64332- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64333- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64334- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64335- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64336- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64337- sum += kstat_cpu_irqs_sum(i);
64338- sum += arch_irq_stat_cpu(i);
64339+ if (unrestricted) {
64340+ iowait += get_iowait_time(i);
64341+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64342+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64343+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64344+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64345+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64346+ sum += kstat_cpu_irqs_sum(i);
64347+ sum += arch_irq_stat_cpu(i);
64348+ for (j = 0; j < NR_SOFTIRQS; j++) {
64349+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64350
64351- for (j = 0; j < NR_SOFTIRQS; j++) {
64352- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64353-
64354- per_softirq_sums[j] += softirq_stat;
64355- sum_softirq += softirq_stat;
64356+ per_softirq_sums[j] += softirq_stat;
64357+ sum_softirq += softirq_stat;
64358+ }
64359 }
64360 }
64361- sum += arch_irq_stat();
64362+ if (unrestricted)
64363+ sum += arch_irq_stat();
64364
64365 seq_puts(p, "cpu ");
64366 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64367@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64368 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64369 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64370 idle = get_idle_time(i);
64371- iowait = get_iowait_time(i);
64372- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64373- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64374- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64375- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64376- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64377+ if (unrestricted) {
64378+ iowait = get_iowait_time(i);
64379+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64380+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64381+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64382+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64383+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64384+ }
64385 seq_printf(p, "cpu%d", i);
64386 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64387 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64388@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64389
64390 /* sum again ? it could be updated? */
64391 for_each_irq_nr(j)
64392- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64393+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64394
64395 seq_printf(p,
64396 "\nctxt %llu\n"
64397@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64398 "processes %lu\n"
64399 "procs_running %lu\n"
64400 "procs_blocked %lu\n",
64401- nr_context_switches(),
64402+ unrestricted ? nr_context_switches() : 0ULL,
64403 (unsigned long)jif,
64404- total_forks,
64405- nr_running(),
64406- nr_iowait());
64407+ unrestricted ? total_forks : 0UL,
64408+ unrestricted ? nr_running() : 0UL,
64409+ unrestricted ? nr_iowait() : 0UL);
64410
64411 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64412
64413diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64414index c4b2646..84f0d7b 100644
64415--- a/fs/proc/task_mmu.c
64416+++ b/fs/proc/task_mmu.c
64417@@ -13,12 +13,19 @@
64418 #include <linux/swap.h>
64419 #include <linux/swapops.h>
64420 #include <linux/mmu_notifier.h>
64421+#include <linux/grsecurity.h>
64422
64423 #include <asm/elf.h>
64424 #include <asm/uaccess.h>
64425 #include <asm/tlbflush.h>
64426 #include "internal.h"
64427
64428+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64429+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64430+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64431+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64432+#endif
64433+
64434 void task_mem(struct seq_file *m, struct mm_struct *mm)
64435 {
64436 unsigned long data, text, lib, swap;
64437@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64438 "VmExe:\t%8lu kB\n"
64439 "VmLib:\t%8lu kB\n"
64440 "VmPTE:\t%8lu kB\n"
64441- "VmSwap:\t%8lu kB\n",
64442- hiwater_vm << (PAGE_SHIFT-10),
64443+ "VmSwap:\t%8lu kB\n"
64444+
64445+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64446+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64447+#endif
64448+
64449+ ,hiwater_vm << (PAGE_SHIFT-10),
64450 total_vm << (PAGE_SHIFT-10),
64451 mm->locked_vm << (PAGE_SHIFT-10),
64452 mm->pinned_vm << (PAGE_SHIFT-10),
64453@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64454 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64455 (PTRS_PER_PTE * sizeof(pte_t) *
64456 atomic_long_read(&mm->nr_ptes)) >> 10,
64457- swap << (PAGE_SHIFT-10));
64458+ swap << (PAGE_SHIFT-10)
64459+
64460+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64461+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64462+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64463+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64464+#else
64465+ , mm->context.user_cs_base
64466+ , mm->context.user_cs_limit
64467+#endif
64468+#endif
64469+
64470+ );
64471 }
64472
64473 unsigned long task_vsize(struct mm_struct *mm)
64474@@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64475 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64476 }
64477
64478- /* We don't show the stack guard page in /proc/maps */
64479+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64480+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64481+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64482+#else
64483 start = vma->vm_start;
64484- if (stack_guard_page_start(vma, start))
64485- start += PAGE_SIZE;
64486 end = vma->vm_end;
64487- if (stack_guard_page_end(vma, end))
64488- end -= PAGE_SIZE;
64489+#endif
64490
64491 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64492 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64493@@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64494 flags & VM_WRITE ? 'w' : '-',
64495 flags & VM_EXEC ? 'x' : '-',
64496 flags & VM_MAYSHARE ? 's' : 'p',
64497+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64498+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64499+#else
64500 pgoff,
64501+#endif
64502 MAJOR(dev), MINOR(dev), ino);
64503
64504 /*
64505@@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64506 */
64507 if (file) {
64508 seq_pad(m, ' ');
64509- seq_path(m, &file->f_path, "\n");
64510+ seq_path(m, &file->f_path, "\n\\");
64511 goto done;
64512 }
64513
64514@@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64515 * Thread stack in /proc/PID/task/TID/maps or
64516 * the main process stack.
64517 */
64518- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64519- vma->vm_end >= mm->start_stack)) {
64520+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64521+ (vma->vm_start <= mm->start_stack &&
64522+ vma->vm_end >= mm->start_stack)) {
64523 name = "[stack]";
64524 } else {
64525 /* Thread stack in /proc/PID/maps */
64526@@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64527 struct proc_maps_private *priv = m->private;
64528 struct task_struct *task = priv->task;
64529
64530+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64531+ if (current->exec_id != m->exec_id) {
64532+ gr_log_badprocpid("maps");
64533+ return 0;
64534+ }
64535+#endif
64536+
64537 show_map_vma(m, vma, is_pid);
64538
64539 if (m->count < m->size) /* vma is copied successfully */
64540@@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64541 .private = &mss,
64542 };
64543
64544+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64545+ if (current->exec_id != m->exec_id) {
64546+ gr_log_badprocpid("smaps");
64547+ return 0;
64548+ }
64549+#endif
64550 memset(&mss, 0, sizeof mss);
64551- mss.vma = vma;
64552- /* mmap_sem is held in m_start */
64553- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64554- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64555-
64556+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64557+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64558+#endif
64559+ mss.vma = vma;
64560+ /* mmap_sem is held in m_start */
64561+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64562+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64563+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64564+ }
64565+#endif
64566 show_map_vma(m, vma, is_pid);
64567
64568 seq_printf(m,
64569@@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64570 "KernelPageSize: %8lu kB\n"
64571 "MMUPageSize: %8lu kB\n"
64572 "Locked: %8lu kB\n",
64573+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64574+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64575+#else
64576 (vma->vm_end - vma->vm_start) >> 10,
64577+#endif
64578 mss.resident >> 10,
64579 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64580 mss.shared_clean >> 10,
64581@@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64582 char buffer[64];
64583 int nid;
64584
64585+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64586+ if (current->exec_id != m->exec_id) {
64587+ gr_log_badprocpid("numa_maps");
64588+ return 0;
64589+ }
64590+#endif
64591+
64592 if (!mm)
64593 return 0;
64594
64595@@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64596 mpol_to_str(buffer, sizeof(buffer), pol);
64597 mpol_cond_put(pol);
64598
64599+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64600+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64601+#else
64602 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64603+#endif
64604
64605 if (file) {
64606 seq_printf(m, " file=");
64607- seq_path(m, &file->f_path, "\n\t= ");
64608+ seq_path(m, &file->f_path, "\n\t\\= ");
64609 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64610 seq_printf(m, " heap");
64611 } else {
64612diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64613index 678455d..ebd3245 100644
64614--- a/fs/proc/task_nommu.c
64615+++ b/fs/proc/task_nommu.c
64616@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64617 else
64618 bytes += kobjsize(mm);
64619
64620- if (current->fs && current->fs->users > 1)
64621+ if (current->fs && atomic_read(&current->fs->users) > 1)
64622 sbytes += kobjsize(current->fs);
64623 else
64624 bytes += kobjsize(current->fs);
64625@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64626
64627 if (file) {
64628 seq_pad(m, ' ');
64629- seq_path(m, &file->f_path, "");
64630+ seq_path(m, &file->f_path, "\n\\");
64631 } else if (mm) {
64632 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64633
64634diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64635index 6a8e785..41f2a6c 100644
64636--- a/fs/proc/vmcore.c
64637+++ b/fs/proc/vmcore.c
64638@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64639 nr_bytes = count;
64640
64641 /* If pfn is not ram, return zeros for sparse dump files */
64642- if (pfn_is_ram(pfn) == 0)
64643- memset(buf, 0, nr_bytes);
64644- else {
64645+ if (pfn_is_ram(pfn) == 0) {
64646+ if (userbuf) {
64647+ if (clear_user((char __force_user *)buf, nr_bytes))
64648+ return -EFAULT;
64649+ } else
64650+ memset(buf, 0, nr_bytes);
64651+ } else {
64652 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64653 offset, userbuf);
64654 if (tmp < 0)
64655@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64656 static int copy_to(void *target, void *src, size_t size, int userbuf)
64657 {
64658 if (userbuf) {
64659- if (copy_to_user((char __user *) target, src, size))
64660+ if (copy_to_user((char __force_user *) target, src, size))
64661 return -EFAULT;
64662 } else {
64663 memcpy(target, src, size);
64664@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64665 if (*fpos < m->offset + m->size) {
64666 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64667 start = m->paddr + *fpos - m->offset;
64668- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64669+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64670 if (tmp < 0)
64671 return tmp;
64672 buflen -= tsz;
64673@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64674 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64675 size_t buflen, loff_t *fpos)
64676 {
64677- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64678+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64679 }
64680
64681 /*
64682diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64683index b00fcc9..e0c6381 100644
64684--- a/fs/qnx6/qnx6.h
64685+++ b/fs/qnx6/qnx6.h
64686@@ -74,7 +74,7 @@ enum {
64687 BYTESEX_BE,
64688 };
64689
64690-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64691+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64692 {
64693 if (sbi->s_bytesex == BYTESEX_LE)
64694 return le64_to_cpu((__force __le64)n);
64695@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64696 return (__force __fs64)cpu_to_be64(n);
64697 }
64698
64699-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64700+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64701 {
64702 if (sbi->s_bytesex == BYTESEX_LE)
64703 return le32_to_cpu((__force __le32)n);
64704diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64705index 72d2917..c917c12 100644
64706--- a/fs/quota/netlink.c
64707+++ b/fs/quota/netlink.c
64708@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64709 void quota_send_warning(struct kqid qid, dev_t dev,
64710 const char warntype)
64711 {
64712- static atomic_t seq;
64713+ static atomic_unchecked_t seq;
64714 struct sk_buff *skb;
64715 void *msg_head;
64716 int ret;
64717@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64718 "VFS: Not enough memory to send quota warning.\n");
64719 return;
64720 }
64721- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64722+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64723 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64724 if (!msg_head) {
64725 printk(KERN_ERR
64726diff --git a/fs/read_write.c b/fs/read_write.c
64727index 31c6efa..a068805 100644
64728--- a/fs/read_write.c
64729+++ b/fs/read_write.c
64730@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64731
64732 old_fs = get_fs();
64733 set_fs(get_ds());
64734- p = (__force const char __user *)buf;
64735+ p = (const char __force_user *)buf;
64736 if (count > MAX_RW_COUNT)
64737 count = MAX_RW_COUNT;
64738 if (file->f_op->write)
64739diff --git a/fs/readdir.c b/fs/readdir.c
64740index 5b53d99..a6c3049 100644
64741--- a/fs/readdir.c
64742+++ b/fs/readdir.c
64743@@ -17,6 +17,7 @@
64744 #include <linux/security.h>
64745 #include <linux/syscalls.h>
64746 #include <linux/unistd.h>
64747+#include <linux/namei.h>
64748
64749 #include <asm/uaccess.h>
64750
64751@@ -69,6 +70,7 @@ struct old_linux_dirent {
64752 struct readdir_callback {
64753 struct dir_context ctx;
64754 struct old_linux_dirent __user * dirent;
64755+ struct file * file;
64756 int result;
64757 };
64758
64759@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64760 buf->result = -EOVERFLOW;
64761 return -EOVERFLOW;
64762 }
64763+
64764+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64765+ return 0;
64766+
64767 buf->result++;
64768 dirent = buf->dirent;
64769 if (!access_ok(VERIFY_WRITE, dirent,
64770@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64771 if (!f.file)
64772 return -EBADF;
64773
64774+ buf.file = f.file;
64775 error = iterate_dir(f.file, &buf.ctx);
64776 if (buf.result)
64777 error = buf.result;
64778@@ -142,6 +149,7 @@ struct getdents_callback {
64779 struct dir_context ctx;
64780 struct linux_dirent __user * current_dir;
64781 struct linux_dirent __user * previous;
64782+ struct file * file;
64783 int count;
64784 int error;
64785 };
64786@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64787 buf->error = -EOVERFLOW;
64788 return -EOVERFLOW;
64789 }
64790+
64791+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64792+ return 0;
64793+
64794 dirent = buf->previous;
64795 if (dirent) {
64796 if (__put_user(offset, &dirent->d_off))
64797@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64798 if (!f.file)
64799 return -EBADF;
64800
64801+ buf.file = f.file;
64802 error = iterate_dir(f.file, &buf.ctx);
64803 if (error >= 0)
64804 error = buf.error;
64805@@ -226,6 +239,7 @@ struct getdents_callback64 {
64806 struct dir_context ctx;
64807 struct linux_dirent64 __user * current_dir;
64808 struct linux_dirent64 __user * previous;
64809+ struct file *file;
64810 int count;
64811 int error;
64812 };
64813@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64814 buf->error = -EINVAL; /* only used if we fail.. */
64815 if (reclen > buf->count)
64816 return -EINVAL;
64817+
64818+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64819+ return 0;
64820+
64821 dirent = buf->previous;
64822 if (dirent) {
64823 if (__put_user(offset, &dirent->d_off))
64824@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64825 if (!f.file)
64826 return -EBADF;
64827
64828+ buf.file = f.file;
64829 error = iterate_dir(f.file, &buf.ctx);
64830 if (error >= 0)
64831 error = buf.error;
64832diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64833index 9a3c68c..767933e 100644
64834--- a/fs/reiserfs/do_balan.c
64835+++ b/fs/reiserfs/do_balan.c
64836@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64837 return;
64838 }
64839
64840- atomic_inc(&(fs_generation(tb->tb_sb)));
64841+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64842 do_balance_starts(tb);
64843
64844 /* balance leaf returns 0 except if combining L R and S into
64845diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64846index ee382ef..f4eb6eb5 100644
64847--- a/fs/reiserfs/item_ops.c
64848+++ b/fs/reiserfs/item_ops.c
64849@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64850 }
64851
64852 static struct item_operations errcatch_ops = {
64853- errcatch_bytes_number,
64854- errcatch_decrement_key,
64855- errcatch_is_left_mergeable,
64856- errcatch_print_item,
64857- errcatch_check_item,
64858+ .bytes_number = errcatch_bytes_number,
64859+ .decrement_key = errcatch_decrement_key,
64860+ .is_left_mergeable = errcatch_is_left_mergeable,
64861+ .print_item = errcatch_print_item,
64862+ .check_item = errcatch_check_item,
64863
64864- errcatch_create_vi,
64865- errcatch_check_left,
64866- errcatch_check_right,
64867- errcatch_part_size,
64868- errcatch_unit_num,
64869- errcatch_print_vi
64870+ .create_vi = errcatch_create_vi,
64871+ .check_left = errcatch_check_left,
64872+ .check_right = errcatch_check_right,
64873+ .part_size = errcatch_part_size,
64874+ .unit_num = errcatch_unit_num,
64875+ .print_vi = errcatch_print_vi
64876 };
64877
64878 //////////////////////////////////////////////////////////////////////////////
64879diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64880index 02b0b7d..c85018b 100644
64881--- a/fs/reiserfs/procfs.c
64882+++ b/fs/reiserfs/procfs.c
64883@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64884 "SMALL_TAILS " : "NO_TAILS ",
64885 replay_only(sb) ? "REPLAY_ONLY " : "",
64886 convert_reiserfs(sb) ? "CONV " : "",
64887- atomic_read(&r->s_generation_counter),
64888+ atomic_read_unchecked(&r->s_generation_counter),
64889 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64890 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64891 SF(s_good_search_by_key_reada), SF(s_bmaps),
64892diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64893index 83d4eac..04e39a7 100644
64894--- a/fs/reiserfs/reiserfs.h
64895+++ b/fs/reiserfs/reiserfs.h
64896@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64897 /* Comment? -Hans */
64898 wait_queue_head_t s_wait;
64899 /* To be obsoleted soon by per buffer seals.. -Hans */
64900- atomic_t s_generation_counter; // increased by one every time the
64901+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64902 // tree gets re-balanced
64903 unsigned long s_properties; /* File system properties. Currently holds
64904 on-disk FS format */
64905@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64906 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64907
64908 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64909-#define get_generation(s) atomic_read (&fs_generation(s))
64910+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64911 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64912 #define __fs_changed(gen,s) (gen != get_generation (s))
64913 #define fs_changed(gen,s) \
64914diff --git a/fs/select.c b/fs/select.c
64915index 467bb1c..cf9d65a 100644
64916--- a/fs/select.c
64917+++ b/fs/select.c
64918@@ -20,6 +20,7 @@
64919 #include <linux/export.h>
64920 #include <linux/slab.h>
64921 #include <linux/poll.h>
64922+#include <linux/security.h>
64923 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64924 #include <linux/file.h>
64925 #include <linux/fdtable.h>
64926@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64927 struct poll_list *walk = head;
64928 unsigned long todo = nfds;
64929
64930+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64931 if (nfds > rlimit(RLIMIT_NOFILE))
64932 return -EINVAL;
64933
64934diff --git a/fs/seq_file.c b/fs/seq_file.c
64935index 1d641bb..c2f4743 100644
64936--- a/fs/seq_file.c
64937+++ b/fs/seq_file.c
64938@@ -10,6 +10,8 @@
64939 #include <linux/seq_file.h>
64940 #include <linux/slab.h>
64941 #include <linux/cred.h>
64942+#include <linux/sched.h>
64943+#include <linux/grsecurity.h>
64944
64945 #include <asm/uaccess.h>
64946 #include <asm/page.h>
64947@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64948 #ifdef CONFIG_USER_NS
64949 p->user_ns = file->f_cred->user_ns;
64950 #endif
64951+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64952+ p->exec_id = current->exec_id;
64953+#endif
64954
64955 /*
64956 * Wrappers around seq_open(e.g. swaps_open) need to be
64957@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
64958 }
64959 EXPORT_SYMBOL(seq_open);
64960
64961+
64962+int seq_open_restrict(struct file *file, const struct seq_operations *op)
64963+{
64964+ if (gr_proc_is_restricted())
64965+ return -EACCES;
64966+
64967+ return seq_open(file, op);
64968+}
64969+EXPORT_SYMBOL(seq_open_restrict);
64970+
64971 static int traverse(struct seq_file *m, loff_t offset)
64972 {
64973 loff_t pos = 0, index;
64974@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64975 return 0;
64976 }
64977 if (!m->buf) {
64978- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64979+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64980 if (!m->buf)
64981 return -ENOMEM;
64982 }
64983@@ -137,7 +152,7 @@ Eoverflow:
64984 m->op->stop(m, p);
64985 kfree(m->buf);
64986 m->count = 0;
64987- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64988+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64989 return !m->buf ? -ENOMEM : -EAGAIN;
64990 }
64991
64992@@ -153,7 +168,7 @@ Eoverflow:
64993 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64994 {
64995 struct seq_file *m = file->private_data;
64996- size_t copied = 0;
64997+ ssize_t copied = 0;
64998 loff_t pos;
64999 size_t n;
65000 void *p;
65001@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65002
65003 /* grab buffer if we didn't have one */
65004 if (!m->buf) {
65005- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65006+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65007 if (!m->buf)
65008 goto Enomem;
65009 }
65010@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65011 m->op->stop(m, p);
65012 kfree(m->buf);
65013 m->count = 0;
65014- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65015+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65016 if (!m->buf)
65017 goto Enomem;
65018 m->version = 0;
65019@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65020 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65021 void *data)
65022 {
65023- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65024+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65025 int res = -ENOMEM;
65026
65027 if (op) {
65028@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65029 }
65030 EXPORT_SYMBOL(single_open_size);
65031
65032+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65033+ void *data)
65034+{
65035+ if (gr_proc_is_restricted())
65036+ return -EACCES;
65037+
65038+ return single_open(file, show, data);
65039+}
65040+EXPORT_SYMBOL(single_open_restrict);
65041+
65042+
65043 int single_release(struct inode *inode, struct file *file)
65044 {
65045 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65046diff --git a/fs/splice.c b/fs/splice.c
65047index e246954..bd4f5b5 100644
65048--- a/fs/splice.c
65049+++ b/fs/splice.c
65050@@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65051 pipe_lock(pipe);
65052
65053 for (;;) {
65054- if (!pipe->readers) {
65055+ if (!atomic_read(&pipe->readers)) {
65056 send_sig(SIGPIPE, current, 0);
65057 if (!ret)
65058 ret = -EPIPE;
65059@@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65060 page_nr++;
65061 ret += buf->len;
65062
65063- if (pipe->files)
65064+ if (atomic_read(&pipe->files))
65065 do_wakeup = 1;
65066
65067 if (!--spd->nr_pages)
65068@@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65069 do_wakeup = 0;
65070 }
65071
65072- pipe->waiting_writers++;
65073+ atomic_inc(&pipe->waiting_writers);
65074 pipe_wait(pipe);
65075- pipe->waiting_writers--;
65076+ atomic_dec(&pipe->waiting_writers);
65077 }
65078
65079 pipe_unlock(pipe);
65080@@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65081 old_fs = get_fs();
65082 set_fs(get_ds());
65083 /* The cast to a user pointer is valid due to the set_fs() */
65084- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65085+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65086 set_fs(old_fs);
65087
65088 return res;
65089@@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65090 old_fs = get_fs();
65091 set_fs(get_ds());
65092 /* The cast to a user pointer is valid due to the set_fs() */
65093- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65094+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65095 set_fs(old_fs);
65096
65097 return res;
65098@@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65099 goto err;
65100
65101 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65102- vec[i].iov_base = (void __user *) page_address(page);
65103+ vec[i].iov_base = (void __force_user *) page_address(page);
65104 vec[i].iov_len = this_len;
65105 spd.pages[i] = page;
65106 spd.nr_pages++;
65107@@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65108 ops->release(pipe, buf);
65109 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65110 pipe->nrbufs--;
65111- if (pipe->files)
65112+ if (atomic_read(&pipe->files))
65113 sd->need_wakeup = true;
65114 }
65115
65116@@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65117 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65118 {
65119 while (!pipe->nrbufs) {
65120- if (!pipe->writers)
65121+ if (!atomic_read(&pipe->writers))
65122 return 0;
65123
65124- if (!pipe->waiting_writers && sd->num_spliced)
65125+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65126 return 0;
65127
65128 if (sd->flags & SPLICE_F_NONBLOCK)
65129@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65130 * out of the pipe right after the splice_to_pipe(). So set
65131 * PIPE_READERS appropriately.
65132 */
65133- pipe->readers = 1;
65134+ atomic_set(&pipe->readers, 1);
65135
65136 current->splice_pipe = pipe;
65137 }
65138@@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65139
65140 partial[buffers].offset = off;
65141 partial[buffers].len = plen;
65142+ partial[buffers].private = 0;
65143
65144 off = 0;
65145 len -= plen;
65146@@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65147 ret = -ERESTARTSYS;
65148 break;
65149 }
65150- if (!pipe->writers)
65151+ if (!atomic_read(&pipe->writers))
65152 break;
65153- if (!pipe->waiting_writers) {
65154+ if (!atomic_read(&pipe->waiting_writers)) {
65155 if (flags & SPLICE_F_NONBLOCK) {
65156 ret = -EAGAIN;
65157 break;
65158@@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65159 pipe_lock(pipe);
65160
65161 while (pipe->nrbufs >= pipe->buffers) {
65162- if (!pipe->readers) {
65163+ if (!atomic_read(&pipe->readers)) {
65164 send_sig(SIGPIPE, current, 0);
65165 ret = -EPIPE;
65166 break;
65167@@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65168 ret = -ERESTARTSYS;
65169 break;
65170 }
65171- pipe->waiting_writers++;
65172+ atomic_inc(&pipe->waiting_writers);
65173 pipe_wait(pipe);
65174- pipe->waiting_writers--;
65175+ atomic_dec(&pipe->waiting_writers);
65176 }
65177
65178 pipe_unlock(pipe);
65179@@ -1806,14 +1807,14 @@ retry:
65180 pipe_double_lock(ipipe, opipe);
65181
65182 do {
65183- if (!opipe->readers) {
65184+ if (!atomic_read(&opipe->readers)) {
65185 send_sig(SIGPIPE, current, 0);
65186 if (!ret)
65187 ret = -EPIPE;
65188 break;
65189 }
65190
65191- if (!ipipe->nrbufs && !ipipe->writers)
65192+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65193 break;
65194
65195 /*
65196@@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65197 pipe_double_lock(ipipe, opipe);
65198
65199 do {
65200- if (!opipe->readers) {
65201+ if (!atomic_read(&opipe->readers)) {
65202 send_sig(SIGPIPE, current, 0);
65203 if (!ret)
65204 ret = -EPIPE;
65205@@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65206 * return EAGAIN if we have the potential of some data in the
65207 * future, otherwise just return 0
65208 */
65209- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65210+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65211 ret = -EAGAIN;
65212
65213 pipe_unlock(ipipe);
65214diff --git a/fs/stat.c b/fs/stat.c
65215index ae0c3ce..9ee641c 100644
65216--- a/fs/stat.c
65217+++ b/fs/stat.c
65218@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65219 stat->gid = inode->i_gid;
65220 stat->rdev = inode->i_rdev;
65221 stat->size = i_size_read(inode);
65222- stat->atime = inode->i_atime;
65223- stat->mtime = inode->i_mtime;
65224+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65225+ stat->atime = inode->i_ctime;
65226+ stat->mtime = inode->i_ctime;
65227+ } else {
65228+ stat->atime = inode->i_atime;
65229+ stat->mtime = inode->i_mtime;
65230+ }
65231 stat->ctime = inode->i_ctime;
65232 stat->blksize = (1 << inode->i_blkbits);
65233 stat->blocks = inode->i_blocks;
65234@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65235 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65236 {
65237 struct inode *inode = path->dentry->d_inode;
65238+ int retval;
65239
65240- if (inode->i_op->getattr)
65241- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65242+ if (inode->i_op->getattr) {
65243+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65244+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65245+ stat->atime = stat->ctime;
65246+ stat->mtime = stat->ctime;
65247+ }
65248+ return retval;
65249+ }
65250
65251 generic_fillattr(inode, stat);
65252 return 0;
65253diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65254index 0b45ff4..847de5b 100644
65255--- a/fs/sysfs/dir.c
65256+++ b/fs/sysfs/dir.c
65257@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65258 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65259 {
65260 struct kernfs_node *parent, *kn;
65261+ const char *name;
65262+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65263+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65264+ const char *parent_name;
65265+#endif
65266
65267 BUG_ON(!kobj);
65268
65269+ name = kobject_name(kobj);
65270+
65271 if (kobj->parent)
65272 parent = kobj->parent->sd;
65273 else
65274@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65275 if (!parent)
65276 return -ENOENT;
65277
65278- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65279- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65280+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65281+ parent_name = parent->name;
65282+ mode = S_IRWXU;
65283+
65284+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65285+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65286+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65287+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65288+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65289+#endif
65290+
65291+ kn = kernfs_create_dir_ns(parent, name,
65292+ mode, kobj, ns);
65293 if (IS_ERR(kn)) {
65294 if (PTR_ERR(kn) == -EEXIST)
65295- sysfs_warn_dup(parent, kobject_name(kobj));
65296+ sysfs_warn_dup(parent, name);
65297 return PTR_ERR(kn);
65298 }
65299
65300diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65301index 69d4889..a810bd4 100644
65302--- a/fs/sysv/sysv.h
65303+++ b/fs/sysv/sysv.h
65304@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65305 #endif
65306 }
65307
65308-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65309+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65310 {
65311 if (sbi->s_bytesex == BYTESEX_PDP)
65312 return PDP_swab((__force __u32)n);
65313diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65314index e18b988..f1d4ad0f 100644
65315--- a/fs/ubifs/io.c
65316+++ b/fs/ubifs/io.c
65317@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65318 return err;
65319 }
65320
65321-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65322+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65323 {
65324 int err;
65325
65326diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65327index c175b4d..8f36a16 100644
65328--- a/fs/udf/misc.c
65329+++ b/fs/udf/misc.c
65330@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65331
65332 u8 udf_tag_checksum(const struct tag *t)
65333 {
65334- u8 *data = (u8 *)t;
65335+ const u8 *data = (const u8 *)t;
65336 u8 checksum = 0;
65337 int i;
65338 for (i = 0; i < sizeof(struct tag); ++i)
65339diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65340index 8d974c4..b82f6ec 100644
65341--- a/fs/ufs/swab.h
65342+++ b/fs/ufs/swab.h
65343@@ -22,7 +22,7 @@ enum {
65344 BYTESEX_BE
65345 };
65346
65347-static inline u64
65348+static inline u64 __intentional_overflow(-1)
65349 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65350 {
65351 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65352@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65353 return (__force __fs64)cpu_to_be64(n);
65354 }
65355
65356-static inline u32
65357+static inline u32 __intentional_overflow(-1)
65358 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65359 {
65360 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65361diff --git a/fs/utimes.c b/fs/utimes.c
65362index aa138d6..5f3a811 100644
65363--- a/fs/utimes.c
65364+++ b/fs/utimes.c
65365@@ -1,6 +1,7 @@
65366 #include <linux/compiler.h>
65367 #include <linux/file.h>
65368 #include <linux/fs.h>
65369+#include <linux/security.h>
65370 #include <linux/linkage.h>
65371 #include <linux/mount.h>
65372 #include <linux/namei.h>
65373@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65374 }
65375 }
65376 retry_deleg:
65377+
65378+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65379+ error = -EACCES;
65380+ goto mnt_drop_write_and_out;
65381+ }
65382+
65383 mutex_lock(&inode->i_mutex);
65384 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65385 mutex_unlock(&inode->i_mutex);
65386diff --git a/fs/xattr.c b/fs/xattr.c
65387index 3377dff..f394815 100644
65388--- a/fs/xattr.c
65389+++ b/fs/xattr.c
65390@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65391 return rc;
65392 }
65393
65394+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65395+ssize_t
65396+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65397+{
65398+ struct inode *inode = dentry->d_inode;
65399+ ssize_t error;
65400+
65401+ error = inode_permission(inode, MAY_EXEC);
65402+ if (error)
65403+ return error;
65404+
65405+ if (inode->i_op->getxattr)
65406+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65407+ else
65408+ error = -EOPNOTSUPP;
65409+
65410+ return error;
65411+}
65412+EXPORT_SYMBOL(pax_getxattr);
65413+#endif
65414+
65415 ssize_t
65416 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65417 {
65418@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65419 * Extended attribute SET operations
65420 */
65421 static long
65422-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65423+setxattr(struct path *path, const char __user *name, const void __user *value,
65424 size_t size, int flags)
65425 {
65426 int error;
65427@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65428 posix_acl_fix_xattr_from_user(kvalue, size);
65429 }
65430
65431- error = vfs_setxattr(d, kname, kvalue, size, flags);
65432+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65433+ error = -EACCES;
65434+ goto out;
65435+ }
65436+
65437+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65438 out:
65439 if (vvalue)
65440 vfree(vvalue);
65441@@ -377,7 +403,7 @@ retry:
65442 return error;
65443 error = mnt_want_write(path.mnt);
65444 if (!error) {
65445- error = setxattr(path.dentry, name, value, size, flags);
65446+ error = setxattr(&path, name, value, size, flags);
65447 mnt_drop_write(path.mnt);
65448 }
65449 path_put(&path);
65450@@ -401,7 +427,7 @@ retry:
65451 return error;
65452 error = mnt_want_write(path.mnt);
65453 if (!error) {
65454- error = setxattr(path.dentry, name, value, size, flags);
65455+ error = setxattr(&path, name, value, size, flags);
65456 mnt_drop_write(path.mnt);
65457 }
65458 path_put(&path);
65459@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65460 const void __user *,value, size_t, size, int, flags)
65461 {
65462 struct fd f = fdget(fd);
65463- struct dentry *dentry;
65464 int error = -EBADF;
65465
65466 if (!f.file)
65467 return error;
65468- dentry = f.file->f_path.dentry;
65469- audit_inode(NULL, dentry, 0);
65470+ audit_inode(NULL, f.file->f_path.dentry, 0);
65471 error = mnt_want_write_file(f.file);
65472 if (!error) {
65473- error = setxattr(dentry, name, value, size, flags);
65474+ error = setxattr(&f.file->f_path, name, value, size, flags);
65475 mnt_drop_write_file(f.file);
65476 }
65477 fdput(f);
65478@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65479 * Extended attribute REMOVE operations
65480 */
65481 static long
65482-removexattr(struct dentry *d, const char __user *name)
65483+removexattr(struct path *path, const char __user *name)
65484 {
65485 int error;
65486 char kname[XATTR_NAME_MAX + 1];
65487@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65488 if (error < 0)
65489 return error;
65490
65491- return vfs_removexattr(d, kname);
65492+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65493+ return -EACCES;
65494+
65495+ return vfs_removexattr(path->dentry, kname);
65496 }
65497
65498 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65499@@ -652,7 +679,7 @@ retry:
65500 return error;
65501 error = mnt_want_write(path.mnt);
65502 if (!error) {
65503- error = removexattr(path.dentry, name);
65504+ error = removexattr(&path, name);
65505 mnt_drop_write(path.mnt);
65506 }
65507 path_put(&path);
65508@@ -675,7 +702,7 @@ retry:
65509 return error;
65510 error = mnt_want_write(path.mnt);
65511 if (!error) {
65512- error = removexattr(path.dentry, name);
65513+ error = removexattr(&path, name);
65514 mnt_drop_write(path.mnt);
65515 }
65516 path_put(&path);
65517@@ -689,16 +716,16 @@ retry:
65518 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65519 {
65520 struct fd f = fdget(fd);
65521- struct dentry *dentry;
65522+ struct path *path;
65523 int error = -EBADF;
65524
65525 if (!f.file)
65526 return error;
65527- dentry = f.file->f_path.dentry;
65528- audit_inode(NULL, dentry, 0);
65529+ path = &f.file->f_path;
65530+ audit_inode(NULL, path->dentry, 0);
65531 error = mnt_want_write_file(f.file);
65532 if (!error) {
65533- error = removexattr(dentry, name);
65534+ error = removexattr(path, name);
65535 mnt_drop_write_file(f.file);
65536 }
65537 fdput(f);
65538diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65539index f0efc7e..ba72910 100644
65540--- a/fs/xfs/xfs_bmap.c
65541+++ b/fs/xfs/xfs_bmap.c
65542@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65543
65544 #else
65545 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65546-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65547+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65548 #endif /* DEBUG */
65549
65550 /*
65551diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65552index aead369..0dfecfd 100644
65553--- a/fs/xfs/xfs_dir2_readdir.c
65554+++ b/fs/xfs/xfs_dir2_readdir.c
65555@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65556 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65557 filetype = dp->d_ops->sf_get_ftype(sfep);
65558 ctx->pos = off & 0x7fffffff;
65559- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65560+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65561+ char name[sfep->namelen];
65562+ memcpy(name, sfep->name, sfep->namelen);
65563+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65564+ return 0;
65565+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65566 xfs_dir3_get_dtype(mp, filetype)))
65567 return 0;
65568 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65569diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65570index 6152cbe..f0f9eaa 100644
65571--- a/fs/xfs/xfs_ioctl.c
65572+++ b/fs/xfs/xfs_ioctl.c
65573@@ -122,7 +122,7 @@ xfs_find_handle(
65574 }
65575
65576 error = -EFAULT;
65577- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65578+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65579 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65580 goto out_put;
65581
65582diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65583new file mode 100644
65584index 0000000..bfd482c
65585--- /dev/null
65586+++ b/grsecurity/Kconfig
65587@@ -0,0 +1,1176 @@
65588+#
65589+# grecurity configuration
65590+#
65591+menu "Memory Protections"
65592+depends on GRKERNSEC
65593+
65594+config GRKERNSEC_KMEM
65595+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65596+ default y if GRKERNSEC_CONFIG_AUTO
65597+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65598+ help
65599+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65600+ be written to or read from to modify or leak the contents of the running
65601+ kernel. /dev/port will also not be allowed to be opened, writing to
65602+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65603+ If you have module support disabled, enabling this will close up several
65604+ ways that are currently used to insert malicious code into the running
65605+ kernel.
65606+
65607+ Even with this feature enabled, we still highly recommend that
65608+ you use the RBAC system, as it is still possible for an attacker to
65609+ modify the running kernel through other more obscure methods.
65610+
65611+ It is highly recommended that you say Y here if you meet all the
65612+ conditions above.
65613+
65614+config GRKERNSEC_VM86
65615+ bool "Restrict VM86 mode"
65616+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65617+ depends on X86_32
65618+
65619+ help
65620+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65621+ make use of a special execution mode on 32bit x86 processors called
65622+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65623+ video cards and will still work with this option enabled. The purpose
65624+ of the option is to prevent exploitation of emulation errors in
65625+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65626+ Nearly all users should be able to enable this option.
65627+
65628+config GRKERNSEC_IO
65629+ bool "Disable privileged I/O"
65630+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65631+ depends on X86
65632+ select RTC_CLASS
65633+ select RTC_INTF_DEV
65634+ select RTC_DRV_CMOS
65635+
65636+ help
65637+ If you say Y here, all ioperm and iopl calls will return an error.
65638+ Ioperm and iopl can be used to modify the running kernel.
65639+ Unfortunately, some programs need this access to operate properly,
65640+ the most notable of which are XFree86 and hwclock. hwclock can be
65641+ remedied by having RTC support in the kernel, so real-time
65642+ clock support is enabled if this option is enabled, to ensure
65643+ that hwclock operates correctly. If hwclock still does not work,
65644+ either update udev or symlink /dev/rtc to /dev/rtc0.
65645+
65646+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65647+ you may not be able to boot into a graphical environment with this
65648+ option enabled. In this case, you should use the RBAC system instead.
65649+
65650+config GRKERNSEC_JIT_HARDEN
65651+ bool "Harden BPF JIT against spray attacks"
65652+ default y if GRKERNSEC_CONFIG_AUTO
65653+ depends on BPF_JIT && X86
65654+ help
65655+ If you say Y here, the native code generated by the kernel's Berkeley
65656+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65657+ attacks that attempt to fit attacker-beneficial instructions in
65658+ 32bit immediate fields of JIT-generated native instructions. The
65659+ attacker will generally aim to cause an unintended instruction sequence
65660+ of JIT-generated native code to execute by jumping into the middle of
65661+ a generated instruction. This feature effectively randomizes the 32bit
65662+ immediate constants present in the generated code to thwart such attacks.
65663+
65664+ If you're using KERNEXEC, it's recommended that you enable this option
65665+ to supplement the hardening of the kernel.
65666+
65667+config GRKERNSEC_PERF_HARDEN
65668+ bool "Disable unprivileged PERF_EVENTS usage by default"
65669+ default y if GRKERNSEC_CONFIG_AUTO
65670+ depends on PERF_EVENTS
65671+ help
65672+ If you say Y here, the range of acceptable values for the
65673+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65674+ default to a new value: 3. When the sysctl is set to this value, no
65675+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65676+
65677+ Though PERF_EVENTS can be used legitimately for performance monitoring
65678+ and low-level application profiling, it is forced on regardless of
65679+ configuration, has been at fault for several vulnerabilities, and
65680+ creates new opportunities for side channels and other information leaks.
65681+
65682+ This feature puts PERF_EVENTS into a secure default state and permits
65683+ the administrator to change out of it temporarily if unprivileged
65684+ application profiling is needed.
65685+
65686+config GRKERNSEC_RAND_THREADSTACK
65687+ bool "Insert random gaps between thread stacks"
65688+ default y if GRKERNSEC_CONFIG_AUTO
65689+ depends on PAX_RANDMMAP && !PPC
65690+ help
65691+ If you say Y here, a random-sized gap will be enforced between allocated
65692+ thread stacks. Glibc's NPTL and other threading libraries that
65693+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65694+ The implementation currently provides 8 bits of entropy for the gap.
65695+
65696+ Many distributions do not compile threaded remote services with the
65697+ -fstack-check argument to GCC, causing the variable-sized stack-based
65698+ allocator, alloca(), to not probe the stack on allocation. This
65699+ permits an unbounded alloca() to skip over any guard page and potentially
65700+ modify another thread's stack reliably. An enforced random gap
65701+ reduces the reliability of such an attack and increases the chance
65702+ that such a read/write to another thread's stack instead lands in
65703+ an unmapped area, causing a crash and triggering grsecurity's
65704+ anti-bruteforcing logic.
65705+
65706+config GRKERNSEC_PROC_MEMMAP
65707+ bool "Harden ASLR against information leaks and entropy reduction"
65708+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65709+ depends on PAX_NOEXEC || PAX_ASLR
65710+ help
65711+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65712+ give no information about the addresses of its mappings if
65713+ PaX features that rely on random addresses are enabled on the task.
65714+ In addition to sanitizing this information and disabling other
65715+ dangerous sources of information, this option causes reads of sensitive
65716+ /proc/<pid> entries where the file descriptor was opened in a different
65717+ task than the one performing the read. Such attempts are logged.
65718+ This option also limits argv/env strings for suid/sgid binaries
65719+ to 512KB to prevent a complete exhaustion of the stack entropy provided
65720+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65721+ binaries to prevent alternative mmap layouts from being abused.
65722+
65723+ If you use PaX it is essential that you say Y here as it closes up
65724+ several holes that make full ASLR useless locally.
65725+
65726+
65727+config GRKERNSEC_KSTACKOVERFLOW
65728+ bool "Prevent kernel stack overflows"
65729+ default y if GRKERNSEC_CONFIG_AUTO
65730+ depends on !IA64 && 64BIT
65731+ help
65732+ If you say Y here, the kernel's process stacks will be allocated
65733+ with vmalloc instead of the kernel's default allocator. This
65734+ introduces guard pages that in combination with the alloca checking
65735+ of the STACKLEAK feature prevents all forms of kernel process stack
65736+ overflow abuse. Note that this is different from kernel stack
65737+ buffer overflows.
65738+
65739+config GRKERNSEC_BRUTE
65740+ bool "Deter exploit bruteforcing"
65741+ default y if GRKERNSEC_CONFIG_AUTO
65742+ help
65743+ If you say Y here, attempts to bruteforce exploits against forking
65744+ daemons such as apache or sshd, as well as against suid/sgid binaries
65745+ will be deterred. When a child of a forking daemon is killed by PaX
65746+ or crashes due to an illegal instruction or other suspicious signal,
65747+ the parent process will be delayed 30 seconds upon every subsequent
65748+ fork until the administrator is able to assess the situation and
65749+ restart the daemon.
65750+ In the suid/sgid case, the attempt is logged, the user has all their
65751+ existing instances of the suid/sgid binary terminated and will
65752+ be unable to execute any suid/sgid binaries for 15 minutes.
65753+
65754+ It is recommended that you also enable signal logging in the auditing
65755+ section so that logs are generated when a process triggers a suspicious
65756+ signal.
65757+ If the sysctl option is enabled, a sysctl option with name
65758+ "deter_bruteforce" is created.
65759+
65760+config GRKERNSEC_MODHARDEN
65761+ bool "Harden module auto-loading"
65762+ default y if GRKERNSEC_CONFIG_AUTO
65763+ depends on MODULES
65764+ help
65765+ If you say Y here, module auto-loading in response to use of some
65766+ feature implemented by an unloaded module will be restricted to
65767+ root users. Enabling this option helps defend against attacks
65768+ by unprivileged users who abuse the auto-loading behavior to
65769+ cause a vulnerable module to load that is then exploited.
65770+
65771+ If this option prevents a legitimate use of auto-loading for a
65772+ non-root user, the administrator can execute modprobe manually
65773+ with the exact name of the module mentioned in the alert log.
65774+ Alternatively, the administrator can add the module to the list
65775+ of modules loaded at boot by modifying init scripts.
65776+
65777+ Modification of init scripts will most likely be needed on
65778+ Ubuntu servers with encrypted home directory support enabled,
65779+ as the first non-root user logging in will cause the ecb(aes),
65780+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65781+
65782+config GRKERNSEC_HIDESYM
65783+ bool "Hide kernel symbols"
65784+ default y if GRKERNSEC_CONFIG_AUTO
65785+ select PAX_USERCOPY_SLABS
65786+ help
65787+ If you say Y here, getting information on loaded modules, and
65788+ displaying all kernel symbols through a syscall will be restricted
65789+ to users with CAP_SYS_MODULE. For software compatibility reasons,
65790+ /proc/kallsyms will be restricted to the root user. The RBAC
65791+ system can hide that entry even from root.
65792+
65793+ This option also prevents leaking of kernel addresses through
65794+ several /proc entries.
65795+
65796+ Note that this option is only effective provided the following
65797+ conditions are met:
65798+ 1) The kernel using grsecurity is not precompiled by some distribution
65799+ 2) You have also enabled GRKERNSEC_DMESG
65800+ 3) You are using the RBAC system and hiding other files such as your
65801+ kernel image and System.map. Alternatively, enabling this option
65802+ causes the permissions on /boot, /lib/modules, and the kernel
65803+ source directory to change at compile time to prevent
65804+ reading by non-root users.
65805+ If the above conditions are met, this option will aid in providing a
65806+ useful protection against local kernel exploitation of overflows
65807+ and arbitrary read/write vulnerabilities.
65808+
65809+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65810+ in addition to this feature.
65811+
65812+config GRKERNSEC_RANDSTRUCT
65813+ bool "Randomize layout of sensitive kernel structures"
65814+ default y if GRKERNSEC_CONFIG_AUTO
65815+ select GRKERNSEC_HIDESYM
65816+ select MODVERSIONS if MODULES
65817+ help
65818+ If you say Y here, the layouts of a number of sensitive kernel
65819+ structures (task, fs, cred, etc) and all structures composed entirely
65820+ of function pointers (aka "ops" structs) will be randomized at compile-time.
65821+ This can introduce the requirement of an additional infoleak
65822+ vulnerability for exploits targeting these structure types.
65823+
65824+ Enabling this feature will introduce some performance impact, slightly
65825+ increase memory usage, and prevent the use of forensic tools like
65826+ Volatility against the system (unless the kernel source tree isn't
65827+ cleaned after kernel installation).
65828+
65829+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65830+ It remains after a make clean to allow for external modules to be compiled
65831+ with the existing seed and will be removed by a make mrproper or
65832+ make distclean.
65833+
65834+ Note that the implementation requires gcc 4.6.4. or newer. You may need
65835+ to install the supporting headers explicitly in addition to the normal
65836+ gcc package.
65837+
65838+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65839+ bool "Use cacheline-aware structure randomization"
65840+ depends on GRKERNSEC_RANDSTRUCT
65841+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65842+ help
65843+ If you say Y here, the RANDSTRUCT randomization will make a best effort
65844+ at restricting randomization to cacheline-sized groups of elements. It
65845+ will further not randomize bitfields in structures. This reduces the
65846+ performance hit of RANDSTRUCT at the cost of weakened randomization.
65847+
65848+config GRKERNSEC_KERN_LOCKOUT
65849+ bool "Active kernel exploit response"
65850+ default y if GRKERNSEC_CONFIG_AUTO
65851+ depends on X86 || ARM || PPC || SPARC
65852+ help
65853+ If you say Y here, when a PaX alert is triggered due to suspicious
65854+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65855+ or an OOPS occurs due to bad memory accesses, instead of just
65856+ terminating the offending process (and potentially allowing
65857+ a subsequent exploit from the same user), we will take one of two
65858+ actions:
65859+ If the user was root, we will panic the system
65860+ If the user was non-root, we will log the attempt, terminate
65861+ all processes owned by the user, then prevent them from creating
65862+ any new processes until the system is restarted
65863+ This deters repeated kernel exploitation/bruteforcing attempts
65864+ and is useful for later forensics.
65865+
65866+config GRKERNSEC_OLD_ARM_USERLAND
65867+ bool "Old ARM userland compatibility"
65868+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65869+ help
65870+ If you say Y here, stubs of executable code to perform such operations
65871+ as "compare-exchange" will be placed at fixed locations in the ARM vector
65872+ table. This is unfortunately needed for old ARM userland meant to run
65873+ across a wide range of processors. Without this option enabled,
65874+ the get_tls and data memory barrier stubs will be emulated by the kernel,
65875+ which is enough for Linaro userlands or other userlands designed for v6
65876+ and newer ARM CPUs. It's recommended that you try without this option enabled
65877+ first, and only enable it if your userland does not boot (it will likely fail
65878+ at init time).
65879+
65880+endmenu
65881+menu "Role Based Access Control Options"
65882+depends on GRKERNSEC
65883+
65884+config GRKERNSEC_RBAC_DEBUG
65885+ bool
65886+
65887+config GRKERNSEC_NO_RBAC
65888+ bool "Disable RBAC system"
65889+ help
65890+ If you say Y here, the /dev/grsec device will be removed from the kernel,
65891+ preventing the RBAC system from being enabled. You should only say Y
65892+ here if you have no intention of using the RBAC system, so as to prevent
65893+ an attacker with root access from misusing the RBAC system to hide files
65894+ and processes when loadable module support and /dev/[k]mem have been
65895+ locked down.
65896+
65897+config GRKERNSEC_ACL_HIDEKERN
65898+ bool "Hide kernel processes"
65899+ help
65900+ If you say Y here, all kernel threads will be hidden to all
65901+ processes but those whose subject has the "view hidden processes"
65902+ flag.
65903+
65904+config GRKERNSEC_ACL_MAXTRIES
65905+ int "Maximum tries before password lockout"
65906+ default 3
65907+ help
65908+ This option enforces the maximum number of times a user can attempt
65909+ to authorize themselves with the grsecurity RBAC system before being
65910+ denied the ability to attempt authorization again for a specified time.
65911+ The lower the number, the harder it will be to brute-force a password.
65912+
65913+config GRKERNSEC_ACL_TIMEOUT
65914+ int "Time to wait after max password tries, in seconds"
65915+ default 30
65916+ help
65917+ This option specifies the time the user must wait after attempting to
65918+ authorize to the RBAC system with the maximum number of invalid
65919+ passwords. The higher the number, the harder it will be to brute-force
65920+ a password.
65921+
65922+endmenu
65923+menu "Filesystem Protections"
65924+depends on GRKERNSEC
65925+
65926+config GRKERNSEC_PROC
65927+ bool "Proc restrictions"
65928+ default y if GRKERNSEC_CONFIG_AUTO
65929+ help
65930+ If you say Y here, the permissions of the /proc filesystem
65931+ will be altered to enhance system security and privacy. You MUST
65932+ choose either a user only restriction or a user and group restriction.
65933+ Depending upon the option you choose, you can either restrict users to
65934+ see only the processes they themselves run, or choose a group that can
65935+ view all processes and files normally restricted to root if you choose
65936+ the "restrict to user only" option. NOTE: If you're running identd or
65937+ ntpd as a non-root user, you will have to run it as the group you
65938+ specify here.
65939+
65940+config GRKERNSEC_PROC_USER
65941+ bool "Restrict /proc to user only"
65942+ depends on GRKERNSEC_PROC
65943+ help
65944+ If you say Y here, non-root users will only be able to view their own
65945+ processes, and restricts them from viewing network-related information,
65946+ and viewing kernel symbol and module information.
65947+
65948+config GRKERNSEC_PROC_USERGROUP
65949+ bool "Allow special group"
65950+ default y if GRKERNSEC_CONFIG_AUTO
65951+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65952+ help
65953+ If you say Y here, you will be able to select a group that will be
65954+ able to view all processes and network-related information. If you've
65955+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65956+ remain hidden. This option is useful if you want to run identd as
65957+ a non-root user. The group you select may also be chosen at boot time
65958+ via "grsec_proc_gid=" on the kernel commandline.
65959+
65960+config GRKERNSEC_PROC_GID
65961+ int "GID for special group"
65962+ depends on GRKERNSEC_PROC_USERGROUP
65963+ default 1001
65964+
65965+config GRKERNSEC_PROC_ADD
65966+ bool "Additional restrictions"
65967+ default y if GRKERNSEC_CONFIG_AUTO
65968+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65969+ help
65970+ If you say Y here, additional restrictions will be placed on
65971+ /proc that keep normal users from viewing device information and
65972+ slabinfo information that could be useful for exploits.
65973+
65974+config GRKERNSEC_LINK
65975+ bool "Linking restrictions"
65976+ default y if GRKERNSEC_CONFIG_AUTO
65977+ help
65978+ If you say Y here, /tmp race exploits will be prevented, since users
65979+ will no longer be able to follow symlinks owned by other users in
65980+ world-writable +t directories (e.g. /tmp), unless the owner of the
65981+ symlink is the owner of the directory. users will also not be
65982+ able to hardlink to files they do not own. If the sysctl option is
65983+ enabled, a sysctl option with name "linking_restrictions" is created.
65984+
65985+config GRKERNSEC_SYMLINKOWN
65986+ bool "Kernel-enforced SymlinksIfOwnerMatch"
65987+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65988+ help
65989+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
65990+ that prevents it from being used as a security feature. As Apache
65991+ verifies the symlink by performing a stat() against the target of
65992+ the symlink before it is followed, an attacker can setup a symlink
65993+ to point to a same-owned file, then replace the symlink with one
65994+ that targets another user's file just after Apache "validates" the
65995+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
65996+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65997+ will be in place for the group you specify. If the sysctl option
65998+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
65999+ created.
66000+
66001+config GRKERNSEC_SYMLINKOWN_GID
66002+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66003+ depends on GRKERNSEC_SYMLINKOWN
66004+ default 1006
66005+ help
66006+ Setting this GID determines what group kernel-enforced
66007+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66008+ is enabled, a sysctl option with name "symlinkown_gid" is created.
66009+
66010+config GRKERNSEC_FIFO
66011+ bool "FIFO restrictions"
66012+ default y if GRKERNSEC_CONFIG_AUTO
66013+ help
66014+ If you say Y here, users will not be able to write to FIFOs they don't
66015+ own in world-writable +t directories (e.g. /tmp), unless the owner of
66016+ the FIFO is the same owner of the directory it's held in. If the sysctl
66017+ option is enabled, a sysctl option with name "fifo_restrictions" is
66018+ created.
66019+
66020+config GRKERNSEC_SYSFS_RESTRICT
66021+ bool "Sysfs/debugfs restriction"
66022+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66023+ depends on SYSFS
66024+ help
66025+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66026+ any filesystem normally mounted under it (e.g. debugfs) will be
66027+ mostly accessible only by root. These filesystems generally provide access
66028+ to hardware and debug information that isn't appropriate for unprivileged
66029+ users of the system. Sysfs and debugfs have also become a large source
66030+ of new vulnerabilities, ranging from infoleaks to local compromise.
66031+ There has been very little oversight with an eye toward security involved
66032+ in adding new exporters of information to these filesystems, so their
66033+ use is discouraged.
66034+ For reasons of compatibility, a few directories have been whitelisted
66035+ for access by non-root users:
66036+ /sys/fs/selinux
66037+ /sys/fs/fuse
66038+ /sys/devices/system/cpu
66039+
66040+config GRKERNSEC_ROFS
66041+ bool "Runtime read-only mount protection"
66042+ depends on SYSCTL
66043+ help
66044+ If you say Y here, a sysctl option with name "romount_protect" will
66045+ be created. By setting this option to 1 at runtime, filesystems
66046+ will be protected in the following ways:
66047+ * No new writable mounts will be allowed
66048+ * Existing read-only mounts won't be able to be remounted read/write
66049+ * Write operations will be denied on all block devices
66050+ This option acts independently of grsec_lock: once it is set to 1,
66051+ it cannot be turned off. Therefore, please be mindful of the resulting
66052+ behavior if this option is enabled in an init script on a read-only
66053+ filesystem.
66054+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66055+ and GRKERNSEC_IO should be enabled and module loading disabled via
66056+ config or at runtime.
66057+ This feature is mainly intended for secure embedded systems.
66058+
66059+
66060+config GRKERNSEC_DEVICE_SIDECHANNEL
66061+ bool "Eliminate stat/notify-based device sidechannels"
66062+ default y if GRKERNSEC_CONFIG_AUTO
66063+ help
66064+ If you say Y here, timing analyses on block or character
66065+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66066+ will be thwarted for unprivileged users. If a process without
66067+ CAP_MKNOD stats such a device, the last access and last modify times
66068+ will match the device's create time. No access or modify events
66069+ will be triggered through inotify/dnotify/fanotify for such devices.
66070+ This feature will prevent attacks that may at a minimum
66071+ allow an attacker to determine the administrator's password length.
66072+
66073+config GRKERNSEC_CHROOT
66074+ bool "Chroot jail restrictions"
66075+ default y if GRKERNSEC_CONFIG_AUTO
66076+ help
66077+ If you say Y here, you will be able to choose several options that will
66078+ make breaking out of a chrooted jail much more difficult. If you
66079+ encounter no software incompatibilities with the following options, it
66080+ is recommended that you enable each one.
66081+
66082+ Note that the chroot restrictions are not intended to apply to "chroots"
66083+ to directories that are simple bind mounts of the global root filesystem.
66084+ For several other reasons, a user shouldn't expect any significant
66085+ security by performing such a chroot.
66086+
66087+config GRKERNSEC_CHROOT_MOUNT
66088+ bool "Deny mounts"
66089+ default y if GRKERNSEC_CONFIG_AUTO
66090+ depends on GRKERNSEC_CHROOT
66091+ help
66092+ If you say Y here, processes inside a chroot will not be able to
66093+ mount or remount filesystems. If the sysctl option is enabled, a
66094+ sysctl option with name "chroot_deny_mount" is created.
66095+
66096+config GRKERNSEC_CHROOT_DOUBLE
66097+ bool "Deny double-chroots"
66098+ default y if GRKERNSEC_CONFIG_AUTO
66099+ depends on GRKERNSEC_CHROOT
66100+ help
66101+ If you say Y here, processes inside a chroot will not be able to chroot
66102+ again outside the chroot. This is a widely used method of breaking
66103+ out of a chroot jail and should not be allowed. If the sysctl
66104+ option is enabled, a sysctl option with name
66105+ "chroot_deny_chroot" is created.
66106+
66107+config GRKERNSEC_CHROOT_PIVOT
66108+ bool "Deny pivot_root in chroot"
66109+ default y if GRKERNSEC_CONFIG_AUTO
66110+ depends on GRKERNSEC_CHROOT
66111+ help
66112+ If you say Y here, processes inside a chroot will not be able to use
66113+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66114+ works similar to chroot in that it changes the root filesystem. This
66115+ function could be misused in a chrooted process to attempt to break out
66116+ of the chroot, and therefore should not be allowed. If the sysctl
66117+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66118+ created.
66119+
66120+config GRKERNSEC_CHROOT_CHDIR
66121+ bool "Enforce chdir(\"/\") on all chroots"
66122+ default y if GRKERNSEC_CONFIG_AUTO
66123+ depends on GRKERNSEC_CHROOT
66124+ help
66125+ If you say Y here, the current working directory of all newly-chrooted
66126+ applications will be set to the the root directory of the chroot.
66127+ The man page on chroot(2) states:
66128+ Note that this call does not change the current working
66129+ directory, so that `.' can be outside the tree rooted at
66130+ `/'. In particular, the super-user can escape from a
66131+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66132+
66133+ It is recommended that you say Y here, since it's not known to break
66134+ any software. If the sysctl option is enabled, a sysctl option with
66135+ name "chroot_enforce_chdir" is created.
66136+
66137+config GRKERNSEC_CHROOT_CHMOD
66138+ bool "Deny (f)chmod +s"
66139+ default y if GRKERNSEC_CONFIG_AUTO
66140+ depends on GRKERNSEC_CHROOT
66141+ help
66142+ If you say Y here, processes inside a chroot will not be able to chmod
66143+ or fchmod files to make them have suid or sgid bits. This protects
66144+ against another published method of breaking a chroot. If the sysctl
66145+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66146+ created.
66147+
66148+config GRKERNSEC_CHROOT_FCHDIR
66149+ bool "Deny fchdir and fhandle out of chroot"
66150+ default y if GRKERNSEC_CONFIG_AUTO
66151+ depends on GRKERNSEC_CHROOT
66152+ help
66153+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66154+ to a file descriptor of the chrooting process that points to a directory
66155+ outside the filesystem will be stopped. Additionally, this option prevents
66156+ use of the recently-created syscall for opening files by a guessable "file
66157+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66158+ with name "chroot_deny_fchdir" is created.
66159+
66160+config GRKERNSEC_CHROOT_MKNOD
66161+ bool "Deny mknod"
66162+ default y if GRKERNSEC_CONFIG_AUTO
66163+ depends on GRKERNSEC_CHROOT
66164+ help
66165+ If you say Y here, processes inside a chroot will not be allowed to
66166+ mknod. The problem with using mknod inside a chroot is that it
66167+ would allow an attacker to create a device entry that is the same
66168+ as one on the physical root of your system, which could range from
66169+ anything from the console device to a device for your harddrive (which
66170+ they could then use to wipe the drive or steal data). It is recommended
66171+ that you say Y here, unless you run into software incompatibilities.
66172+ If the sysctl option is enabled, a sysctl option with name
66173+ "chroot_deny_mknod" is created.
66174+
66175+config GRKERNSEC_CHROOT_SHMAT
66176+ bool "Deny shmat() out of chroot"
66177+ default y if GRKERNSEC_CONFIG_AUTO
66178+ depends on GRKERNSEC_CHROOT
66179+ help
66180+ If you say Y here, processes inside a chroot will not be able to attach
66181+ to shared memory segments that were created outside of the chroot jail.
66182+ It is recommended that you say Y here. If the sysctl option is enabled,
66183+ a sysctl option with name "chroot_deny_shmat" is created.
66184+
66185+config GRKERNSEC_CHROOT_UNIX
66186+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66187+ default y if GRKERNSEC_CONFIG_AUTO
66188+ depends on GRKERNSEC_CHROOT
66189+ help
66190+ If you say Y here, processes inside a chroot will not be able to
66191+ connect to abstract (meaning not belonging to a filesystem) Unix
66192+ domain sockets that were bound outside of a chroot. It is recommended
66193+ that you say Y here. If the sysctl option is enabled, a sysctl option
66194+ with name "chroot_deny_unix" is created.
66195+
66196+config GRKERNSEC_CHROOT_FINDTASK
66197+ bool "Protect outside processes"
66198+ default y if GRKERNSEC_CONFIG_AUTO
66199+ depends on GRKERNSEC_CHROOT
66200+ help
66201+ If you say Y here, processes inside a chroot will not be able to
66202+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66203+ getsid, or view any process outside of the chroot. If the sysctl
66204+ option is enabled, a sysctl option with name "chroot_findtask" is
66205+ created.
66206+
66207+config GRKERNSEC_CHROOT_NICE
66208+ bool "Restrict priority changes"
66209+ default y if GRKERNSEC_CONFIG_AUTO
66210+ depends on GRKERNSEC_CHROOT
66211+ help
66212+ If you say Y here, processes inside a chroot will not be able to raise
66213+ the priority of processes in the chroot, or alter the priority of
66214+ processes outside the chroot. This provides more security than simply
66215+ removing CAP_SYS_NICE from the process' capability set. If the
66216+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66217+ is created.
66218+
66219+config GRKERNSEC_CHROOT_SYSCTL
66220+ bool "Deny sysctl writes"
66221+ default y if GRKERNSEC_CONFIG_AUTO
66222+ depends on GRKERNSEC_CHROOT
66223+ help
66224+ If you say Y here, an attacker in a chroot will not be able to
66225+ write to sysctl entries, either by sysctl(2) or through a /proc
66226+ interface. It is strongly recommended that you say Y here. If the
66227+ sysctl option is enabled, a sysctl option with name
66228+ "chroot_deny_sysctl" is created.
66229+
66230+config GRKERNSEC_CHROOT_CAPS
66231+ bool "Capability restrictions"
66232+ default y if GRKERNSEC_CONFIG_AUTO
66233+ depends on GRKERNSEC_CHROOT
66234+ help
66235+ If you say Y here, the capabilities on all processes within a
66236+ chroot jail will be lowered to stop module insertion, raw i/o,
66237+ system and net admin tasks, rebooting the system, modifying immutable
66238+ files, modifying IPC owned by another, and changing the system time.
66239+ This is left an option because it can break some apps. Disable this
66240+ if your chrooted apps are having problems performing those kinds of
66241+ tasks. If the sysctl option is enabled, a sysctl option with
66242+ name "chroot_caps" is created.
66243+
66244+config GRKERNSEC_CHROOT_INITRD
66245+ bool "Exempt initrd tasks from restrictions"
66246+ default y if GRKERNSEC_CONFIG_AUTO
66247+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66248+ help
66249+ If you say Y here, tasks started prior to init will be exempted from
66250+ grsecurity's chroot restrictions. This option is mainly meant to
66251+ resolve Plymouth's performing privileged operations unnecessarily
66252+ in a chroot.
66253+
66254+endmenu
66255+menu "Kernel Auditing"
66256+depends on GRKERNSEC
66257+
66258+config GRKERNSEC_AUDIT_GROUP
66259+ bool "Single group for auditing"
66260+ help
66261+ If you say Y here, the exec and chdir logging features will only operate
66262+ on a group you specify. This option is recommended if you only want to
66263+ watch certain users instead of having a large amount of logs from the
66264+ entire system. If the sysctl option is enabled, a sysctl option with
66265+ name "audit_group" is created.
66266+
66267+config GRKERNSEC_AUDIT_GID
66268+ int "GID for auditing"
66269+ depends on GRKERNSEC_AUDIT_GROUP
66270+ default 1007
66271+
66272+config GRKERNSEC_EXECLOG
66273+ bool "Exec logging"
66274+ help
66275+ If you say Y here, all execve() calls will be logged (since the
66276+ other exec*() calls are frontends to execve(), all execution
66277+ will be logged). Useful for shell-servers that like to keep track
66278+ of their users. If the sysctl option is enabled, a sysctl option with
66279+ name "exec_logging" is created.
66280+ WARNING: This option when enabled will produce a LOT of logs, especially
66281+ on an active system.
66282+
66283+config GRKERNSEC_RESLOG
66284+ bool "Resource logging"
66285+ default y if GRKERNSEC_CONFIG_AUTO
66286+ help
66287+ If you say Y here, all attempts to overstep resource limits will
66288+ be logged with the resource name, the requested size, and the current
66289+ limit. It is highly recommended that you say Y here. If the sysctl
66290+ option is enabled, a sysctl option with name "resource_logging" is
66291+ created. If the RBAC system is enabled, the sysctl value is ignored.
66292+
66293+config GRKERNSEC_CHROOT_EXECLOG
66294+ bool "Log execs within chroot"
66295+ help
66296+ If you say Y here, all executions inside a chroot jail will be logged
66297+ to syslog. This can cause a large amount of logs if certain
66298+ applications (eg. djb's daemontools) are installed on the system, and
66299+ is therefore left as an option. If the sysctl option is enabled, a
66300+ sysctl option with name "chroot_execlog" is created.
66301+
66302+config GRKERNSEC_AUDIT_PTRACE
66303+ bool "Ptrace logging"
66304+ help
66305+ If you say Y here, all attempts to attach to a process via ptrace
66306+ will be logged. If the sysctl option is enabled, a sysctl option
66307+ with name "audit_ptrace" is created.
66308+
66309+config GRKERNSEC_AUDIT_CHDIR
66310+ bool "Chdir logging"
66311+ help
66312+ If you say Y here, all chdir() calls will be logged. If the sysctl
66313+ option is enabled, a sysctl option with name "audit_chdir" is created.
66314+
66315+config GRKERNSEC_AUDIT_MOUNT
66316+ bool "(Un)Mount logging"
66317+ help
66318+ If you say Y here, all mounts and unmounts will be logged. If the
66319+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66320+ created.
66321+
66322+config GRKERNSEC_SIGNAL
66323+ bool "Signal logging"
66324+ default y if GRKERNSEC_CONFIG_AUTO
66325+ help
66326+ If you say Y here, certain important signals will be logged, such as
66327+ SIGSEGV, which will as a result inform you of when a error in a program
66328+ occurred, which in some cases could mean a possible exploit attempt.
66329+ If the sysctl option is enabled, a sysctl option with name
66330+ "signal_logging" is created.
66331+
66332+config GRKERNSEC_FORKFAIL
66333+ bool "Fork failure logging"
66334+ help
66335+ If you say Y here, all failed fork() attempts will be logged.
66336+ This could suggest a fork bomb, or someone attempting to overstep
66337+ their process limit. If the sysctl option is enabled, a sysctl option
66338+ with name "forkfail_logging" is created.
66339+
66340+config GRKERNSEC_TIME
66341+ bool "Time change logging"
66342+ default y if GRKERNSEC_CONFIG_AUTO
66343+ help
66344+ If you say Y here, any changes of the system clock will be logged.
66345+ If the sysctl option is enabled, a sysctl option with name
66346+ "timechange_logging" is created.
66347+
66348+config GRKERNSEC_PROC_IPADDR
66349+ bool "/proc/<pid>/ipaddr support"
66350+ default y if GRKERNSEC_CONFIG_AUTO
66351+ help
66352+ If you say Y here, a new entry will be added to each /proc/<pid>
66353+ directory that contains the IP address of the person using the task.
66354+ The IP is carried across local TCP and AF_UNIX stream sockets.
66355+ This information can be useful for IDS/IPSes to perform remote response
66356+ to a local attack. The entry is readable by only the owner of the
66357+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66358+ the RBAC system), and thus does not create privacy concerns.
66359+
66360+config GRKERNSEC_RWXMAP_LOG
66361+ bool 'Denied RWX mmap/mprotect logging'
66362+ default y if GRKERNSEC_CONFIG_AUTO
66363+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66364+ help
66365+ If you say Y here, calls to mmap() and mprotect() with explicit
66366+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66367+ denied by the PAX_MPROTECT feature. This feature will also
66368+ log other problematic scenarios that can occur when PAX_MPROTECT
66369+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66370+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66371+ is created.
66372+
66373+endmenu
66374+
66375+menu "Executable Protections"
66376+depends on GRKERNSEC
66377+
66378+config GRKERNSEC_DMESG
66379+ bool "Dmesg(8) restriction"
66380+ default y if GRKERNSEC_CONFIG_AUTO
66381+ help
66382+ If you say Y here, non-root users will not be able to use dmesg(8)
66383+ to view the contents of the kernel's circular log buffer.
66384+ The kernel's log buffer often contains kernel addresses and other
66385+ identifying information useful to an attacker in fingerprinting a
66386+ system for a targeted exploit.
66387+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66388+ created.
66389+
66390+config GRKERNSEC_HARDEN_PTRACE
66391+ bool "Deter ptrace-based process snooping"
66392+ default y if GRKERNSEC_CONFIG_AUTO
66393+ help
66394+ If you say Y here, TTY sniffers and other malicious monitoring
66395+ programs implemented through ptrace will be defeated. If you
66396+ have been using the RBAC system, this option has already been
66397+ enabled for several years for all users, with the ability to make
66398+ fine-grained exceptions.
66399+
66400+ This option only affects the ability of non-root users to ptrace
66401+ processes that are not a descendent of the ptracing process.
66402+ This means that strace ./binary and gdb ./binary will still work,
66403+ but attaching to arbitrary processes will not. If the sysctl
66404+ option is enabled, a sysctl option with name "harden_ptrace" is
66405+ created.
66406+
66407+config GRKERNSEC_PTRACE_READEXEC
66408+ bool "Require read access to ptrace sensitive binaries"
66409+ default y if GRKERNSEC_CONFIG_AUTO
66410+ help
66411+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66412+ binaries. This option is useful in environments that
66413+ remove the read bits (e.g. file mode 4711) from suid binaries to
66414+ prevent infoleaking of their contents. This option adds
66415+ consistency to the use of that file mode, as the binary could normally
66416+ be read out when run without privileges while ptracing.
66417+
66418+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66419+ is created.
66420+
66421+config GRKERNSEC_SETXID
66422+ bool "Enforce consistent multithreaded privileges"
66423+ default y if GRKERNSEC_CONFIG_AUTO
66424+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66425+ help
66426+ If you say Y here, a change from a root uid to a non-root uid
66427+ in a multithreaded application will cause the resulting uids,
66428+ gids, supplementary groups, and capabilities in that thread
66429+ to be propagated to the other threads of the process. In most
66430+ cases this is unnecessary, as glibc will emulate this behavior
66431+ on behalf of the application. Other libcs do not act in the
66432+ same way, allowing the other threads of the process to continue
66433+ running with root privileges. If the sysctl option is enabled,
66434+ a sysctl option with name "consistent_setxid" is created.
66435+
66436+config GRKERNSEC_HARDEN_IPC
66437+ bool "Disallow access to overly-permissive IPC objects"
66438+ default y if GRKERNSEC_CONFIG_AUTO
66439+ depends on SYSVIPC
66440+ help
66441+ If you say Y here, access to overly-permissive IPC objects (shared
66442+ memory, message queues, and semaphores) will be denied for processes
66443+ given the following criteria beyond normal permission checks:
66444+ 1) If the IPC object is world-accessible and the euid doesn't match
66445+ that of the creator or current uid for the IPC object
66446+ 2) If the IPC object is group-accessible and the egid doesn't
66447+ match that of the creator or current gid for the IPC object
66448+ It's a common error to grant too much permission to these objects,
66449+ with impact ranging from denial of service and information leaking to
66450+ privilege escalation. This feature was developed in response to
66451+ research by Tim Brown:
66452+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66453+ who found hundreds of such insecure usages. Processes with
66454+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66455+ If the sysctl option is enabled, a sysctl option with name
66456+ "harden_ipc" is created.
66457+
66458+config GRKERNSEC_TPE
66459+ bool "Trusted Path Execution (TPE)"
66460+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66461+ help
66462+ If you say Y here, you will be able to choose a gid to add to the
66463+ supplementary groups of users you want to mark as "untrusted."
66464+ These users will not be able to execute any files that are not in
66465+ root-owned directories writable only by root. If the sysctl option
66466+ is enabled, a sysctl option with name "tpe" is created.
66467+
66468+config GRKERNSEC_TPE_ALL
66469+ bool "Partially restrict all non-root users"
66470+ depends on GRKERNSEC_TPE
66471+ help
66472+ If you say Y here, all non-root users will be covered under
66473+ a weaker TPE restriction. This is separate from, and in addition to,
66474+ the main TPE options that you have selected elsewhere. Thus, if a
66475+ "trusted" GID is chosen, this restriction applies to even that GID.
66476+ Under this restriction, all non-root users will only be allowed to
66477+ execute files in directories they own that are not group or
66478+ world-writable, or in directories owned by root and writable only by
66479+ root. If the sysctl option is enabled, a sysctl option with name
66480+ "tpe_restrict_all" is created.
66481+
66482+config GRKERNSEC_TPE_INVERT
66483+ bool "Invert GID option"
66484+ depends on GRKERNSEC_TPE
66485+ help
66486+ If you say Y here, the group you specify in the TPE configuration will
66487+ decide what group TPE restrictions will be *disabled* for. This
66488+ option is useful if you want TPE restrictions to be applied to most
66489+ users on the system. If the sysctl option is enabled, a sysctl option
66490+ with name "tpe_invert" is created. Unlike other sysctl options, this
66491+ entry will default to on for backward-compatibility.
66492+
66493+config GRKERNSEC_TPE_GID
66494+ int
66495+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66496+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66497+
66498+config GRKERNSEC_TPE_UNTRUSTED_GID
66499+ int "GID for TPE-untrusted users"
66500+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66501+ default 1005
66502+ help
66503+ Setting this GID determines what group TPE restrictions will be
66504+ *enabled* for. If the sysctl option is enabled, a sysctl option
66505+ with name "tpe_gid" is created.
66506+
66507+config GRKERNSEC_TPE_TRUSTED_GID
66508+ int "GID for TPE-trusted users"
66509+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66510+ default 1005
66511+ help
66512+ Setting this GID determines what group TPE restrictions will be
66513+ *disabled* for. If the sysctl option is enabled, a sysctl option
66514+ with name "tpe_gid" is created.
66515+
66516+endmenu
66517+menu "Network Protections"
66518+depends on GRKERNSEC
66519+
66520+config GRKERNSEC_RANDNET
66521+ bool "Larger entropy pools"
66522+ default y if GRKERNSEC_CONFIG_AUTO
66523+ help
66524+ If you say Y here, the entropy pools used for many features of Linux
66525+ and grsecurity will be doubled in size. Since several grsecurity
66526+ features use additional randomness, it is recommended that you say Y
66527+ here. Saying Y here has a similar effect as modifying
66528+ /proc/sys/kernel/random/poolsize.
66529+
66530+config GRKERNSEC_BLACKHOLE
66531+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66532+ default y if GRKERNSEC_CONFIG_AUTO
66533+ depends on NET
66534+ help
66535+ If you say Y here, neither TCP resets nor ICMP
66536+ destination-unreachable packets will be sent in response to packets
66537+ sent to ports for which no associated listening process exists.
66538+ This feature supports both IPV4 and IPV6 and exempts the
66539+ loopback interface from blackholing. Enabling this feature
66540+ makes a host more resilient to DoS attacks and reduces network
66541+ visibility against scanners.
66542+
66543+ The blackhole feature as-implemented is equivalent to the FreeBSD
66544+ blackhole feature, as it prevents RST responses to all packets, not
66545+ just SYNs. Under most application behavior this causes no
66546+ problems, but applications (like haproxy) may not close certain
66547+ connections in a way that cleanly terminates them on the remote
66548+ end, leaving the remote host in LAST_ACK state. Because of this
66549+ side-effect and to prevent intentional LAST_ACK DoSes, this
66550+ feature also adds automatic mitigation against such attacks.
66551+ The mitigation drastically reduces the amount of time a socket
66552+ can spend in LAST_ACK state. If you're using haproxy and not
66553+ all servers it connects to have this option enabled, consider
66554+ disabling this feature on the haproxy host.
66555+
66556+ If the sysctl option is enabled, two sysctl options with names
66557+ "ip_blackhole" and "lastack_retries" will be created.
66558+ While "ip_blackhole" takes the standard zero/non-zero on/off
66559+ toggle, "lastack_retries" uses the same kinds of values as
66560+ "tcp_retries1" and "tcp_retries2". The default value of 4
66561+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66562+ state.
66563+
66564+config GRKERNSEC_NO_SIMULT_CONNECT
66565+ bool "Disable TCP Simultaneous Connect"
66566+ default y if GRKERNSEC_CONFIG_AUTO
66567+ depends on NET
66568+ help
66569+ If you say Y here, a feature by Willy Tarreau will be enabled that
66570+ removes a weakness in Linux's strict implementation of TCP that
66571+ allows two clients to connect to each other without either entering
66572+ a listening state. The weakness allows an attacker to easily prevent
66573+ a client from connecting to a known server provided the source port
66574+ for the connection is guessed correctly.
66575+
66576+ As the weakness could be used to prevent an antivirus or IPS from
66577+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66578+ it should be eliminated by enabling this option. Though Linux is
66579+ one of few operating systems supporting simultaneous connect, it
66580+ has no legitimate use in practice and is rarely supported by firewalls.
66581+
66582+config GRKERNSEC_SOCKET
66583+ bool "Socket restrictions"
66584+ depends on NET
66585+ help
66586+ If you say Y here, you will be able to choose from several options.
66587+ If you assign a GID on your system and add it to the supplementary
66588+ groups of users you want to restrict socket access to, this patch
66589+ will perform up to three things, based on the option(s) you choose.
66590+
66591+config GRKERNSEC_SOCKET_ALL
66592+ bool "Deny any sockets to group"
66593+ depends on GRKERNSEC_SOCKET
66594+ help
66595+ If you say Y here, you will be able to choose a GID of whose users will
66596+ be unable to connect to other hosts from your machine or run server
66597+ applications from your machine. If the sysctl option is enabled, a
66598+ sysctl option with name "socket_all" is created.
66599+
66600+config GRKERNSEC_SOCKET_ALL_GID
66601+ int "GID to deny all sockets for"
66602+ depends on GRKERNSEC_SOCKET_ALL
66603+ default 1004
66604+ help
66605+ Here you can choose the GID to disable socket access for. Remember to
66606+ add the users you want socket access disabled for to the GID
66607+ specified here. If the sysctl option is enabled, a sysctl option
66608+ with name "socket_all_gid" is created.
66609+
66610+config GRKERNSEC_SOCKET_CLIENT
66611+ bool "Deny client sockets to group"
66612+ depends on GRKERNSEC_SOCKET
66613+ help
66614+ If you say Y here, you will be able to choose a GID of whose users will
66615+ be unable to connect to other hosts from your machine, but will be
66616+ able to run servers. If this option is enabled, all users in the group
66617+ you specify will have to use passive mode when initiating ftp transfers
66618+ from the shell on your machine. If the sysctl option is enabled, a
66619+ sysctl option with name "socket_client" is created.
66620+
66621+config GRKERNSEC_SOCKET_CLIENT_GID
66622+ int "GID to deny client sockets for"
66623+ depends on GRKERNSEC_SOCKET_CLIENT
66624+ default 1003
66625+ help
66626+ Here you can choose the GID to disable client socket access for.
66627+ Remember to add the users you want client socket access disabled for to
66628+ the GID specified here. If the sysctl option is enabled, a sysctl
66629+ option with name "socket_client_gid" is created.
66630+
66631+config GRKERNSEC_SOCKET_SERVER
66632+ bool "Deny server sockets to group"
66633+ depends on GRKERNSEC_SOCKET
66634+ help
66635+ If you say Y here, you will be able to choose a GID of whose users will
66636+ be unable to run server applications from your machine. If the sysctl
66637+ option is enabled, a sysctl option with name "socket_server" is created.
66638+
66639+config GRKERNSEC_SOCKET_SERVER_GID
66640+ int "GID to deny server sockets for"
66641+ depends on GRKERNSEC_SOCKET_SERVER
66642+ default 1002
66643+ help
66644+ Here you can choose the GID to disable server socket access for.
66645+ Remember to add the users you want server socket access disabled for to
66646+ the GID specified here. If the sysctl option is enabled, a sysctl
66647+ option with name "socket_server_gid" is created.
66648+
66649+endmenu
66650+
66651+menu "Physical Protections"
66652+depends on GRKERNSEC
66653+
66654+config GRKERNSEC_DENYUSB
66655+ bool "Deny new USB connections after toggle"
66656+ default y if GRKERNSEC_CONFIG_AUTO
66657+ depends on SYSCTL && USB_SUPPORT
66658+ help
66659+ If you say Y here, a new sysctl option with name "deny_new_usb"
66660+ will be created. Setting its value to 1 will prevent any new
66661+ USB devices from being recognized by the OS. Any attempted USB
66662+ device insertion will be logged. This option is intended to be
66663+ used against custom USB devices designed to exploit vulnerabilities
66664+ in various USB device drivers.
66665+
66666+ For greatest effectiveness, this sysctl should be set after any
66667+ relevant init scripts. This option is safe to enable in distros
66668+ as each user can choose whether or not to toggle the sysctl.
66669+
66670+config GRKERNSEC_DENYUSB_FORCE
66671+ bool "Reject all USB devices not connected at boot"
66672+ select USB
66673+ depends on GRKERNSEC_DENYUSB
66674+ help
66675+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66676+ that doesn't involve a sysctl entry. This option should only be
66677+ enabled if you're sure you want to deny all new USB connections
66678+ at runtime and don't want to modify init scripts. This should not
66679+ be enabled by distros. It forces the core USB code to be built
66680+ into the kernel image so that all devices connected at boot time
66681+ can be recognized and new USB device connections can be prevented
66682+ prior to init running.
66683+
66684+endmenu
66685+
66686+menu "Sysctl Support"
66687+depends on GRKERNSEC && SYSCTL
66688+
66689+config GRKERNSEC_SYSCTL
66690+ bool "Sysctl support"
66691+ default y if GRKERNSEC_CONFIG_AUTO
66692+ help
66693+ If you say Y here, you will be able to change the options that
66694+ grsecurity runs with at bootup, without having to recompile your
66695+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66696+ to enable (1) or disable (0) various features. All the sysctl entries
66697+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66698+ All features enabled in the kernel configuration are disabled at boot
66699+ if you do not say Y to the "Turn on features by default" option.
66700+ All options should be set at startup, and the grsec_lock entry should
66701+ be set to a non-zero value after all the options are set.
66702+ *THIS IS EXTREMELY IMPORTANT*
66703+
66704+config GRKERNSEC_SYSCTL_DISTRO
66705+ bool "Extra sysctl support for distro makers (READ HELP)"
66706+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66707+ help
66708+ If you say Y here, additional sysctl options will be created
66709+ for features that affect processes running as root. Therefore,
66710+ it is critical when using this option that the grsec_lock entry be
66711+ enabled after boot. Only distros with prebuilt kernel packages
66712+ with this option enabled that can ensure grsec_lock is enabled
66713+ after boot should use this option.
66714+ *Failure to set grsec_lock after boot makes all grsec features
66715+ this option covers useless*
66716+
66717+ Currently this option creates the following sysctl entries:
66718+ "Disable Privileged I/O": "disable_priv_io"
66719+
66720+config GRKERNSEC_SYSCTL_ON
66721+ bool "Turn on features by default"
66722+ default y if GRKERNSEC_CONFIG_AUTO
66723+ depends on GRKERNSEC_SYSCTL
66724+ help
66725+ If you say Y here, instead of having all features enabled in the
66726+ kernel configuration disabled at boot time, the features will be
66727+ enabled at boot time. It is recommended you say Y here unless
66728+ there is some reason you would want all sysctl-tunable features to
66729+ be disabled by default. As mentioned elsewhere, it is important
66730+ to enable the grsec_lock entry once you have finished modifying
66731+ the sysctl entries.
66732+
66733+endmenu
66734+menu "Logging Options"
66735+depends on GRKERNSEC
66736+
66737+config GRKERNSEC_FLOODTIME
66738+ int "Seconds in between log messages (minimum)"
66739+ default 10
66740+ help
66741+ This option allows you to enforce the number of seconds between
66742+ grsecurity log messages. The default should be suitable for most
66743+ people, however, if you choose to change it, choose a value small enough
66744+ to allow informative logs to be produced, but large enough to
66745+ prevent flooding.
66746+
66747+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66748+ any rate limiting on grsecurity log messages.
66749+
66750+config GRKERNSEC_FLOODBURST
66751+ int "Number of messages in a burst (maximum)"
66752+ default 6
66753+ help
66754+ This option allows you to choose the maximum number of messages allowed
66755+ within the flood time interval you chose in a separate option. The
66756+ default should be suitable for most people, however if you find that
66757+ many of your logs are being interpreted as flooding, you may want to
66758+ raise this value.
66759+
66760+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66761+ any rate limiting on grsecurity log messages.
66762+
66763+endmenu
66764diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66765new file mode 100644
66766index 0000000..30ababb
66767--- /dev/null
66768+++ b/grsecurity/Makefile
66769@@ -0,0 +1,54 @@
66770+# grsecurity – access control and security hardening for Linux
66771+# All code in this directory and various hooks located throughout the Linux kernel are
66772+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66773+# http://www.grsecurity.net spender@grsecurity.net
66774+#
66775+# This program is free software; you can redistribute it and/or
66776+# modify it under the terms of the GNU General Public License version 2
66777+# as published by the Free Software Foundation.
66778+#
66779+# This program is distributed in the hope that it will be useful,
66780+# but WITHOUT ANY WARRANTY; without even the implied warranty of
66781+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66782+# GNU General Public License for more details.
66783+#
66784+# You should have received a copy of the GNU General Public License
66785+# along with this program; if not, write to the Free Software
66786+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66787+
66788+KBUILD_CFLAGS += -Werror
66789+
66790+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66791+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
66792+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66793+ grsec_usb.o grsec_ipc.o grsec_proc.o
66794+
66795+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66796+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66797+ gracl_learn.o grsec_log.o gracl_policy.o
66798+ifdef CONFIG_COMPAT
66799+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66800+endif
66801+
66802+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66803+
66804+ifdef CONFIG_NET
66805+obj-y += grsec_sock.o
66806+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66807+endif
66808+
66809+ifndef CONFIG_GRKERNSEC
66810+obj-y += grsec_disabled.o
66811+endif
66812+
66813+ifdef CONFIG_GRKERNSEC_HIDESYM
66814+extra-y := grsec_hidesym.o
66815+$(obj)/grsec_hidesym.o:
66816+ @-chmod -f 500 /boot
66817+ @-chmod -f 500 /lib/modules
66818+ @-chmod -f 500 /lib64/modules
66819+ @-chmod -f 500 /lib32/modules
66820+ @-chmod -f 700 .
66821+ @-chmod -f 700 $(objtree)
66822+ @echo ' grsec: protected kernel image paths'
66823+endif
66824diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66825new file mode 100644
66826index 0000000..58223f6
66827--- /dev/null
66828+++ b/grsecurity/gracl.c
66829@@ -0,0 +1,2702 @@
66830+#include <linux/kernel.h>
66831+#include <linux/module.h>
66832+#include <linux/sched.h>
66833+#include <linux/mm.h>
66834+#include <linux/file.h>
66835+#include <linux/fs.h>
66836+#include <linux/namei.h>
66837+#include <linux/mount.h>
66838+#include <linux/tty.h>
66839+#include <linux/proc_fs.h>
66840+#include <linux/lglock.h>
66841+#include <linux/slab.h>
66842+#include <linux/vmalloc.h>
66843+#include <linux/types.h>
66844+#include <linux/sysctl.h>
66845+#include <linux/netdevice.h>
66846+#include <linux/ptrace.h>
66847+#include <linux/gracl.h>
66848+#include <linux/gralloc.h>
66849+#include <linux/security.h>
66850+#include <linux/grinternal.h>
66851+#include <linux/pid_namespace.h>
66852+#include <linux/stop_machine.h>
66853+#include <linux/fdtable.h>
66854+#include <linux/percpu.h>
66855+#include <linux/lglock.h>
66856+#include <linux/hugetlb.h>
66857+#include <linux/posix-timers.h>
66858+#include <linux/prefetch.h>
66859+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66860+#include <linux/magic.h>
66861+#include <linux/pagemap.h>
66862+#include "../fs/btrfs/async-thread.h"
66863+#include "../fs/btrfs/ctree.h"
66864+#include "../fs/btrfs/btrfs_inode.h"
66865+#endif
66866+#include "../fs/mount.h"
66867+
66868+#include <asm/uaccess.h>
66869+#include <asm/errno.h>
66870+#include <asm/mman.h>
66871+
66872+#define FOR_EACH_ROLE_START(role) \
66873+ role = running_polstate.role_list; \
66874+ while (role) {
66875+
66876+#define FOR_EACH_ROLE_END(role) \
66877+ role = role->prev; \
66878+ }
66879+
66880+extern struct path gr_real_root;
66881+
66882+static struct gr_policy_state running_polstate;
66883+struct gr_policy_state *polstate = &running_polstate;
66884+extern struct gr_alloc_state *current_alloc_state;
66885+
66886+extern char *gr_shared_page[4];
66887+DEFINE_RWLOCK(gr_inode_lock);
66888+
66889+static unsigned int gr_status __read_only = GR_STATUS_INIT;
66890+
66891+#ifdef CONFIG_NET
66892+extern struct vfsmount *sock_mnt;
66893+#endif
66894+
66895+extern struct vfsmount *pipe_mnt;
66896+extern struct vfsmount *shm_mnt;
66897+
66898+#ifdef CONFIG_HUGETLBFS
66899+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66900+#endif
66901+
66902+extern u16 acl_sp_role_value;
66903+extern struct acl_object_label *fakefs_obj_rw;
66904+extern struct acl_object_label *fakefs_obj_rwx;
66905+
66906+int gr_acl_is_enabled(void)
66907+{
66908+ return (gr_status & GR_READY);
66909+}
66910+
66911+void gr_enable_rbac_system(void)
66912+{
66913+ pax_open_kernel();
66914+ gr_status |= GR_READY;
66915+ pax_close_kernel();
66916+}
66917+
66918+int gr_rbac_disable(void *unused)
66919+{
66920+ pax_open_kernel();
66921+ gr_status &= ~GR_READY;
66922+ pax_close_kernel();
66923+
66924+ return 0;
66925+}
66926+
66927+static inline dev_t __get_dev(const struct dentry *dentry)
66928+{
66929+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66930+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66931+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66932+ else
66933+#endif
66934+ return dentry->d_sb->s_dev;
66935+}
66936+
66937+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66938+{
66939+ return __get_dev(dentry);
66940+}
66941+
66942+static char gr_task_roletype_to_char(struct task_struct *task)
66943+{
66944+ switch (task->role->roletype &
66945+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66946+ GR_ROLE_SPECIAL)) {
66947+ case GR_ROLE_DEFAULT:
66948+ return 'D';
66949+ case GR_ROLE_USER:
66950+ return 'U';
66951+ case GR_ROLE_GROUP:
66952+ return 'G';
66953+ case GR_ROLE_SPECIAL:
66954+ return 'S';
66955+ }
66956+
66957+ return 'X';
66958+}
66959+
66960+char gr_roletype_to_char(void)
66961+{
66962+ return gr_task_roletype_to_char(current);
66963+}
66964+
66965+__inline__ int
66966+gr_acl_tpe_check(void)
66967+{
66968+ if (unlikely(!(gr_status & GR_READY)))
66969+ return 0;
66970+ if (current->role->roletype & GR_ROLE_TPE)
66971+ return 1;
66972+ else
66973+ return 0;
66974+}
66975+
66976+int
66977+gr_handle_rawio(const struct inode *inode)
66978+{
66979+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66980+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66981+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66982+ !capable(CAP_SYS_RAWIO))
66983+ return 1;
66984+#endif
66985+ return 0;
66986+}
66987+
66988+int
66989+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66990+{
66991+ if (likely(lena != lenb))
66992+ return 0;
66993+
66994+ return !memcmp(a, b, lena);
66995+}
66996+
66997+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66998+{
66999+ *buflen -= namelen;
67000+ if (*buflen < 0)
67001+ return -ENAMETOOLONG;
67002+ *buffer -= namelen;
67003+ memcpy(*buffer, str, namelen);
67004+ return 0;
67005+}
67006+
67007+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67008+{
67009+ return prepend(buffer, buflen, name->name, name->len);
67010+}
67011+
67012+static int prepend_path(const struct path *path, struct path *root,
67013+ char **buffer, int *buflen)
67014+{
67015+ struct dentry *dentry = path->dentry;
67016+ struct vfsmount *vfsmnt = path->mnt;
67017+ struct mount *mnt = real_mount(vfsmnt);
67018+ bool slash = false;
67019+ int error = 0;
67020+
67021+ while (dentry != root->dentry || vfsmnt != root->mnt) {
67022+ struct dentry * parent;
67023+
67024+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67025+ /* Global root? */
67026+ if (!mnt_has_parent(mnt)) {
67027+ goto out;
67028+ }
67029+ dentry = mnt->mnt_mountpoint;
67030+ mnt = mnt->mnt_parent;
67031+ vfsmnt = &mnt->mnt;
67032+ continue;
67033+ }
67034+ parent = dentry->d_parent;
67035+ prefetch(parent);
67036+ spin_lock(&dentry->d_lock);
67037+ error = prepend_name(buffer, buflen, &dentry->d_name);
67038+ spin_unlock(&dentry->d_lock);
67039+ if (!error)
67040+ error = prepend(buffer, buflen, "/", 1);
67041+ if (error)
67042+ break;
67043+
67044+ slash = true;
67045+ dentry = parent;
67046+ }
67047+
67048+out:
67049+ if (!error && !slash)
67050+ error = prepend(buffer, buflen, "/", 1);
67051+
67052+ return error;
67053+}
67054+
67055+/* this must be called with mount_lock and rename_lock held */
67056+
67057+static char *__our_d_path(const struct path *path, struct path *root,
67058+ char *buf, int buflen)
67059+{
67060+ char *res = buf + buflen;
67061+ int error;
67062+
67063+ prepend(&res, &buflen, "\0", 1);
67064+ error = prepend_path(path, root, &res, &buflen);
67065+ if (error)
67066+ return ERR_PTR(error);
67067+
67068+ return res;
67069+}
67070+
67071+static char *
67072+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67073+{
67074+ char *retval;
67075+
67076+ retval = __our_d_path(path, root, buf, buflen);
67077+ if (unlikely(IS_ERR(retval)))
67078+ retval = strcpy(buf, "<path too long>");
67079+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67080+ retval[1] = '\0';
67081+
67082+ return retval;
67083+}
67084+
67085+static char *
67086+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67087+ char *buf, int buflen)
67088+{
67089+ struct path path;
67090+ char *res;
67091+
67092+ path.dentry = (struct dentry *)dentry;
67093+ path.mnt = (struct vfsmount *)vfsmnt;
67094+
67095+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67096+ by the RBAC system */
67097+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67098+
67099+ return res;
67100+}
67101+
67102+static char *
67103+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67104+ char *buf, int buflen)
67105+{
67106+ char *res;
67107+ struct path path;
67108+ struct path root;
67109+ struct task_struct *reaper = init_pid_ns.child_reaper;
67110+
67111+ path.dentry = (struct dentry *)dentry;
67112+ path.mnt = (struct vfsmount *)vfsmnt;
67113+
67114+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67115+ get_fs_root(reaper->fs, &root);
67116+
67117+ read_seqlock_excl(&mount_lock);
67118+ write_seqlock(&rename_lock);
67119+ res = gen_full_path(&path, &root, buf, buflen);
67120+ write_sequnlock(&rename_lock);
67121+ read_sequnlock_excl(&mount_lock);
67122+
67123+ path_put(&root);
67124+ return res;
67125+}
67126+
67127+char *
67128+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67129+{
67130+ char *ret;
67131+ read_seqlock_excl(&mount_lock);
67132+ write_seqlock(&rename_lock);
67133+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67134+ PAGE_SIZE);
67135+ write_sequnlock(&rename_lock);
67136+ read_sequnlock_excl(&mount_lock);
67137+ return ret;
67138+}
67139+
67140+static char *
67141+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67142+{
67143+ char *ret;
67144+ char *buf;
67145+ int buflen;
67146+
67147+ read_seqlock_excl(&mount_lock);
67148+ write_seqlock(&rename_lock);
67149+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67150+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67151+ buflen = (int)(ret - buf);
67152+ if (buflen >= 5)
67153+ prepend(&ret, &buflen, "/proc", 5);
67154+ else
67155+ ret = strcpy(buf, "<path too long>");
67156+ write_sequnlock(&rename_lock);
67157+ read_sequnlock_excl(&mount_lock);
67158+ return ret;
67159+}
67160+
67161+char *
67162+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67163+{
67164+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67165+ PAGE_SIZE);
67166+}
67167+
67168+char *
67169+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67170+{
67171+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67172+ PAGE_SIZE);
67173+}
67174+
67175+char *
67176+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67177+{
67178+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67179+ PAGE_SIZE);
67180+}
67181+
67182+char *
67183+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67184+{
67185+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67186+ PAGE_SIZE);
67187+}
67188+
67189+char *
67190+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67191+{
67192+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67193+ PAGE_SIZE);
67194+}
67195+
67196+__inline__ __u32
67197+to_gr_audit(const __u32 reqmode)
67198+{
67199+ /* masks off auditable permission flags, then shifts them to create
67200+ auditing flags, and adds the special case of append auditing if
67201+ we're requesting write */
67202+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67203+}
67204+
67205+struct acl_role_label *
67206+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67207+ const gid_t gid)
67208+{
67209+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67210+ struct acl_role_label *match;
67211+ struct role_allowed_ip *ipp;
67212+ unsigned int x;
67213+ u32 curr_ip = task->signal->saved_ip;
67214+
67215+ match = state->acl_role_set.r_hash[index];
67216+
67217+ while (match) {
67218+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67219+ for (x = 0; x < match->domain_child_num; x++) {
67220+ if (match->domain_children[x] == uid)
67221+ goto found;
67222+ }
67223+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67224+ break;
67225+ match = match->next;
67226+ }
67227+found:
67228+ if (match == NULL) {
67229+ try_group:
67230+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67231+ match = state->acl_role_set.r_hash[index];
67232+
67233+ while (match) {
67234+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67235+ for (x = 0; x < match->domain_child_num; x++) {
67236+ if (match->domain_children[x] == gid)
67237+ goto found2;
67238+ }
67239+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67240+ break;
67241+ match = match->next;
67242+ }
67243+found2:
67244+ if (match == NULL)
67245+ match = state->default_role;
67246+ if (match->allowed_ips == NULL)
67247+ return match;
67248+ else {
67249+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67250+ if (likely
67251+ ((ntohl(curr_ip) & ipp->netmask) ==
67252+ (ntohl(ipp->addr) & ipp->netmask)))
67253+ return match;
67254+ }
67255+ match = state->default_role;
67256+ }
67257+ } else if (match->allowed_ips == NULL) {
67258+ return match;
67259+ } else {
67260+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67261+ if (likely
67262+ ((ntohl(curr_ip) & ipp->netmask) ==
67263+ (ntohl(ipp->addr) & ipp->netmask)))
67264+ return match;
67265+ }
67266+ goto try_group;
67267+ }
67268+
67269+ return match;
67270+}
67271+
67272+static struct acl_role_label *
67273+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67274+ const gid_t gid)
67275+{
67276+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67277+}
67278+
67279+struct acl_subject_label *
67280+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67281+ const struct acl_role_label *role)
67282+{
67283+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67284+ struct acl_subject_label *match;
67285+
67286+ match = role->subj_hash[index];
67287+
67288+ while (match && (match->inode != ino || match->device != dev ||
67289+ (match->mode & GR_DELETED))) {
67290+ match = match->next;
67291+ }
67292+
67293+ if (match && !(match->mode & GR_DELETED))
67294+ return match;
67295+ else
67296+ return NULL;
67297+}
67298+
67299+struct acl_subject_label *
67300+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67301+ const struct acl_role_label *role)
67302+{
67303+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67304+ struct acl_subject_label *match;
67305+
67306+ match = role->subj_hash[index];
67307+
67308+ while (match && (match->inode != ino || match->device != dev ||
67309+ !(match->mode & GR_DELETED))) {
67310+ match = match->next;
67311+ }
67312+
67313+ if (match && (match->mode & GR_DELETED))
67314+ return match;
67315+ else
67316+ return NULL;
67317+}
67318+
67319+static struct acl_object_label *
67320+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67321+ const struct acl_subject_label *subj)
67322+{
67323+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67324+ struct acl_object_label *match;
67325+
67326+ match = subj->obj_hash[index];
67327+
67328+ while (match && (match->inode != ino || match->device != dev ||
67329+ (match->mode & GR_DELETED))) {
67330+ match = match->next;
67331+ }
67332+
67333+ if (match && !(match->mode & GR_DELETED))
67334+ return match;
67335+ else
67336+ return NULL;
67337+}
67338+
67339+static struct acl_object_label *
67340+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67341+ const struct acl_subject_label *subj)
67342+{
67343+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67344+ struct acl_object_label *match;
67345+
67346+ match = subj->obj_hash[index];
67347+
67348+ while (match && (match->inode != ino || match->device != dev ||
67349+ !(match->mode & GR_DELETED))) {
67350+ match = match->next;
67351+ }
67352+
67353+ if (match && (match->mode & GR_DELETED))
67354+ return match;
67355+
67356+ match = subj->obj_hash[index];
67357+
67358+ while (match && (match->inode != ino || match->device != dev ||
67359+ (match->mode & GR_DELETED))) {
67360+ match = match->next;
67361+ }
67362+
67363+ if (match && !(match->mode & GR_DELETED))
67364+ return match;
67365+ else
67366+ return NULL;
67367+}
67368+
67369+struct name_entry *
67370+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67371+{
67372+ unsigned int len = strlen(name);
67373+ unsigned int key = full_name_hash(name, len);
67374+ unsigned int index = key % state->name_set.n_size;
67375+ struct name_entry *match;
67376+
67377+ match = state->name_set.n_hash[index];
67378+
67379+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67380+ match = match->next;
67381+
67382+ return match;
67383+}
67384+
67385+static struct name_entry *
67386+lookup_name_entry(const char *name)
67387+{
67388+ return __lookup_name_entry(&running_polstate, name);
67389+}
67390+
67391+static struct name_entry *
67392+lookup_name_entry_create(const char *name)
67393+{
67394+ unsigned int len = strlen(name);
67395+ unsigned int key = full_name_hash(name, len);
67396+ unsigned int index = key % running_polstate.name_set.n_size;
67397+ struct name_entry *match;
67398+
67399+ match = running_polstate.name_set.n_hash[index];
67400+
67401+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67402+ !match->deleted))
67403+ match = match->next;
67404+
67405+ if (match && match->deleted)
67406+ return match;
67407+
67408+ match = running_polstate.name_set.n_hash[index];
67409+
67410+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67411+ match->deleted))
67412+ match = match->next;
67413+
67414+ if (match && !match->deleted)
67415+ return match;
67416+ else
67417+ return NULL;
67418+}
67419+
67420+static struct inodev_entry *
67421+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67422+{
67423+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67424+ struct inodev_entry *match;
67425+
67426+ match = running_polstate.inodev_set.i_hash[index];
67427+
67428+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67429+ match = match->next;
67430+
67431+ return match;
67432+}
67433+
67434+void
67435+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67436+{
67437+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67438+ state->inodev_set.i_size);
67439+ struct inodev_entry **curr;
67440+
67441+ entry->prev = NULL;
67442+
67443+ curr = &state->inodev_set.i_hash[index];
67444+ if (*curr != NULL)
67445+ (*curr)->prev = entry;
67446+
67447+ entry->next = *curr;
67448+ *curr = entry;
67449+
67450+ return;
67451+}
67452+
67453+static void
67454+insert_inodev_entry(struct inodev_entry *entry)
67455+{
67456+ __insert_inodev_entry(&running_polstate, entry);
67457+}
67458+
67459+void
67460+insert_acl_obj_label(struct acl_object_label *obj,
67461+ struct acl_subject_label *subj)
67462+{
67463+ unsigned int index =
67464+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67465+ struct acl_object_label **curr;
67466+
67467+ obj->prev = NULL;
67468+
67469+ curr = &subj->obj_hash[index];
67470+ if (*curr != NULL)
67471+ (*curr)->prev = obj;
67472+
67473+ obj->next = *curr;
67474+ *curr = obj;
67475+
67476+ return;
67477+}
67478+
67479+void
67480+insert_acl_subj_label(struct acl_subject_label *obj,
67481+ struct acl_role_label *role)
67482+{
67483+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67484+ struct acl_subject_label **curr;
67485+
67486+ obj->prev = NULL;
67487+
67488+ curr = &role->subj_hash[index];
67489+ if (*curr != NULL)
67490+ (*curr)->prev = obj;
67491+
67492+ obj->next = *curr;
67493+ *curr = obj;
67494+
67495+ return;
67496+}
67497+
67498+/* derived from glibc fnmatch() 0: match, 1: no match*/
67499+
67500+static int
67501+glob_match(const char *p, const char *n)
67502+{
67503+ char c;
67504+
67505+ while ((c = *p++) != '\0') {
67506+ switch (c) {
67507+ case '?':
67508+ if (*n == '\0')
67509+ return 1;
67510+ else if (*n == '/')
67511+ return 1;
67512+ break;
67513+ case '\\':
67514+ if (*n != c)
67515+ return 1;
67516+ break;
67517+ case '*':
67518+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67519+ if (*n == '/')
67520+ return 1;
67521+ else if (c == '?') {
67522+ if (*n == '\0')
67523+ return 1;
67524+ else
67525+ ++n;
67526+ }
67527+ }
67528+ if (c == '\0') {
67529+ return 0;
67530+ } else {
67531+ const char *endp;
67532+
67533+ if ((endp = strchr(n, '/')) == NULL)
67534+ endp = n + strlen(n);
67535+
67536+ if (c == '[') {
67537+ for (--p; n < endp; ++n)
67538+ if (!glob_match(p, n))
67539+ return 0;
67540+ } else if (c == '/') {
67541+ while (*n != '\0' && *n != '/')
67542+ ++n;
67543+ if (*n == '/' && !glob_match(p, n + 1))
67544+ return 0;
67545+ } else {
67546+ for (--p; n < endp; ++n)
67547+ if (*n == c && !glob_match(p, n))
67548+ return 0;
67549+ }
67550+
67551+ return 1;
67552+ }
67553+ case '[':
67554+ {
67555+ int not;
67556+ char cold;
67557+
67558+ if (*n == '\0' || *n == '/')
67559+ return 1;
67560+
67561+ not = (*p == '!' || *p == '^');
67562+ if (not)
67563+ ++p;
67564+
67565+ c = *p++;
67566+ for (;;) {
67567+ unsigned char fn = (unsigned char)*n;
67568+
67569+ if (c == '\0')
67570+ return 1;
67571+ else {
67572+ if (c == fn)
67573+ goto matched;
67574+ cold = c;
67575+ c = *p++;
67576+
67577+ if (c == '-' && *p != ']') {
67578+ unsigned char cend = *p++;
67579+
67580+ if (cend == '\0')
67581+ return 1;
67582+
67583+ if (cold <= fn && fn <= cend)
67584+ goto matched;
67585+
67586+ c = *p++;
67587+ }
67588+ }
67589+
67590+ if (c == ']')
67591+ break;
67592+ }
67593+ if (!not)
67594+ return 1;
67595+ break;
67596+ matched:
67597+ while (c != ']') {
67598+ if (c == '\0')
67599+ return 1;
67600+
67601+ c = *p++;
67602+ }
67603+ if (not)
67604+ return 1;
67605+ }
67606+ break;
67607+ default:
67608+ if (c != *n)
67609+ return 1;
67610+ }
67611+
67612+ ++n;
67613+ }
67614+
67615+ if (*n == '\0')
67616+ return 0;
67617+
67618+ if (*n == '/')
67619+ return 0;
67620+
67621+ return 1;
67622+}
67623+
67624+static struct acl_object_label *
67625+chk_glob_label(struct acl_object_label *globbed,
67626+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67627+{
67628+ struct acl_object_label *tmp;
67629+
67630+ if (*path == NULL)
67631+ *path = gr_to_filename_nolock(dentry, mnt);
67632+
67633+ tmp = globbed;
67634+
67635+ while (tmp) {
67636+ if (!glob_match(tmp->filename, *path))
67637+ return tmp;
67638+ tmp = tmp->next;
67639+ }
67640+
67641+ return NULL;
67642+}
67643+
67644+static struct acl_object_label *
67645+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67646+ const ino_t curr_ino, const dev_t curr_dev,
67647+ const struct acl_subject_label *subj, char **path, const int checkglob)
67648+{
67649+ struct acl_subject_label *tmpsubj;
67650+ struct acl_object_label *retval;
67651+ struct acl_object_label *retval2;
67652+
67653+ tmpsubj = (struct acl_subject_label *) subj;
67654+ read_lock(&gr_inode_lock);
67655+ do {
67656+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67657+ if (retval) {
67658+ if (checkglob && retval->globbed) {
67659+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67660+ if (retval2)
67661+ retval = retval2;
67662+ }
67663+ break;
67664+ }
67665+ } while ((tmpsubj = tmpsubj->parent_subject));
67666+ read_unlock(&gr_inode_lock);
67667+
67668+ return retval;
67669+}
67670+
67671+static __inline__ struct acl_object_label *
67672+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67673+ struct dentry *curr_dentry,
67674+ const struct acl_subject_label *subj, char **path, const int checkglob)
67675+{
67676+ int newglob = checkglob;
67677+ ino_t inode;
67678+ dev_t device;
67679+
67680+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67681+ as we don't want a / * rule to match instead of the / object
67682+ don't do this for create lookups that call this function though, since they're looking up
67683+ on the parent and thus need globbing checks on all paths
67684+ */
67685+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67686+ newglob = GR_NO_GLOB;
67687+
67688+ spin_lock(&curr_dentry->d_lock);
67689+ inode = curr_dentry->d_inode->i_ino;
67690+ device = __get_dev(curr_dentry);
67691+ spin_unlock(&curr_dentry->d_lock);
67692+
67693+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67694+}
67695+
67696+#ifdef CONFIG_HUGETLBFS
67697+static inline bool
67698+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67699+{
67700+ int i;
67701+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67702+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67703+ return true;
67704+ }
67705+
67706+ return false;
67707+}
67708+#endif
67709+
67710+static struct acl_object_label *
67711+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67712+ const struct acl_subject_label *subj, char *path, const int checkglob)
67713+{
67714+ struct dentry *dentry = (struct dentry *) l_dentry;
67715+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67716+ struct mount *real_mnt = real_mount(mnt);
67717+ struct acl_object_label *retval;
67718+ struct dentry *parent;
67719+
67720+ read_seqlock_excl(&mount_lock);
67721+ write_seqlock(&rename_lock);
67722+
67723+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67724+#ifdef CONFIG_NET
67725+ mnt == sock_mnt ||
67726+#endif
67727+#ifdef CONFIG_HUGETLBFS
67728+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67729+#endif
67730+ /* ignore Eric Biederman */
67731+ IS_PRIVATE(l_dentry->d_inode))) {
67732+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67733+ goto out;
67734+ }
67735+
67736+ for (;;) {
67737+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67738+ break;
67739+
67740+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67741+ if (!mnt_has_parent(real_mnt))
67742+ break;
67743+
67744+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67745+ if (retval != NULL)
67746+ goto out;
67747+
67748+ dentry = real_mnt->mnt_mountpoint;
67749+ real_mnt = real_mnt->mnt_parent;
67750+ mnt = &real_mnt->mnt;
67751+ continue;
67752+ }
67753+
67754+ parent = dentry->d_parent;
67755+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67756+ if (retval != NULL)
67757+ goto out;
67758+
67759+ dentry = parent;
67760+ }
67761+
67762+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67763+
67764+ /* gr_real_root is pinned so we don't have to hold a reference */
67765+ if (retval == NULL)
67766+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67767+out:
67768+ write_sequnlock(&rename_lock);
67769+ read_sequnlock_excl(&mount_lock);
67770+
67771+ BUG_ON(retval == NULL);
67772+
67773+ return retval;
67774+}
67775+
67776+static __inline__ struct acl_object_label *
67777+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67778+ const struct acl_subject_label *subj)
67779+{
67780+ char *path = NULL;
67781+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67782+}
67783+
67784+static __inline__ struct acl_object_label *
67785+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67786+ const struct acl_subject_label *subj)
67787+{
67788+ char *path = NULL;
67789+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67790+}
67791+
67792+static __inline__ struct acl_object_label *
67793+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67794+ const struct acl_subject_label *subj, char *path)
67795+{
67796+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67797+}
67798+
67799+struct acl_subject_label *
67800+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67801+ const struct acl_role_label *role)
67802+{
67803+ struct dentry *dentry = (struct dentry *) l_dentry;
67804+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67805+ struct mount *real_mnt = real_mount(mnt);
67806+ struct acl_subject_label *retval;
67807+ struct dentry *parent;
67808+
67809+ read_seqlock_excl(&mount_lock);
67810+ write_seqlock(&rename_lock);
67811+
67812+ for (;;) {
67813+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67814+ break;
67815+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67816+ if (!mnt_has_parent(real_mnt))
67817+ break;
67818+
67819+ spin_lock(&dentry->d_lock);
67820+ read_lock(&gr_inode_lock);
67821+ retval =
67822+ lookup_acl_subj_label(dentry->d_inode->i_ino,
67823+ __get_dev(dentry), role);
67824+ read_unlock(&gr_inode_lock);
67825+ spin_unlock(&dentry->d_lock);
67826+ if (retval != NULL)
67827+ goto out;
67828+
67829+ dentry = real_mnt->mnt_mountpoint;
67830+ real_mnt = real_mnt->mnt_parent;
67831+ mnt = &real_mnt->mnt;
67832+ continue;
67833+ }
67834+
67835+ spin_lock(&dentry->d_lock);
67836+ read_lock(&gr_inode_lock);
67837+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67838+ __get_dev(dentry), role);
67839+ read_unlock(&gr_inode_lock);
67840+ parent = dentry->d_parent;
67841+ spin_unlock(&dentry->d_lock);
67842+
67843+ if (retval != NULL)
67844+ goto out;
67845+
67846+ dentry = parent;
67847+ }
67848+
67849+ spin_lock(&dentry->d_lock);
67850+ read_lock(&gr_inode_lock);
67851+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67852+ __get_dev(dentry), role);
67853+ read_unlock(&gr_inode_lock);
67854+ spin_unlock(&dentry->d_lock);
67855+
67856+ if (unlikely(retval == NULL)) {
67857+ /* gr_real_root is pinned, we don't need to hold a reference */
67858+ read_lock(&gr_inode_lock);
67859+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67860+ __get_dev(gr_real_root.dentry), role);
67861+ read_unlock(&gr_inode_lock);
67862+ }
67863+out:
67864+ write_sequnlock(&rename_lock);
67865+ read_sequnlock_excl(&mount_lock);
67866+
67867+ BUG_ON(retval == NULL);
67868+
67869+ return retval;
67870+}
67871+
67872+void
67873+assign_special_role(const char *rolename)
67874+{
67875+ struct acl_object_label *obj;
67876+ struct acl_role_label *r;
67877+ struct acl_role_label *assigned = NULL;
67878+ struct task_struct *tsk;
67879+ struct file *filp;
67880+
67881+ FOR_EACH_ROLE_START(r)
67882+ if (!strcmp(rolename, r->rolename) &&
67883+ (r->roletype & GR_ROLE_SPECIAL)) {
67884+ assigned = r;
67885+ break;
67886+ }
67887+ FOR_EACH_ROLE_END(r)
67888+
67889+ if (!assigned)
67890+ return;
67891+
67892+ read_lock(&tasklist_lock);
67893+ read_lock(&grsec_exec_file_lock);
67894+
67895+ tsk = current->real_parent;
67896+ if (tsk == NULL)
67897+ goto out_unlock;
67898+
67899+ filp = tsk->exec_file;
67900+ if (filp == NULL)
67901+ goto out_unlock;
67902+
67903+ tsk->is_writable = 0;
67904+ tsk->inherited = 0;
67905+
67906+ tsk->acl_sp_role = 1;
67907+ tsk->acl_role_id = ++acl_sp_role_value;
67908+ tsk->role = assigned;
67909+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67910+
67911+ /* ignore additional mmap checks for processes that are writable
67912+ by the default ACL */
67913+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67914+ if (unlikely(obj->mode & GR_WRITE))
67915+ tsk->is_writable = 1;
67916+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67917+ if (unlikely(obj->mode & GR_WRITE))
67918+ tsk->is_writable = 1;
67919+
67920+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67921+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67922+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67923+#endif
67924+
67925+out_unlock:
67926+ read_unlock(&grsec_exec_file_lock);
67927+ read_unlock(&tasklist_lock);
67928+ return;
67929+}
67930+
67931+
67932+static void
67933+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67934+{
67935+ struct task_struct *task = current;
67936+ const struct cred *cred = current_cred();
67937+
67938+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67939+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67940+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67941+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67942+
67943+ return;
67944+}
67945+
67946+static void
67947+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67948+{
67949+ struct task_struct *task = current;
67950+ const struct cred *cred = current_cred();
67951+
67952+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67953+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67954+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67955+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67956+
67957+ return;
67958+}
67959+
67960+static void
67961+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67962+{
67963+ struct task_struct *task = current;
67964+ const struct cred *cred = current_cred();
67965+
67966+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67967+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67968+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67969+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67970+
67971+ return;
67972+}
67973+
67974+static void
67975+gr_set_proc_res(struct task_struct *task)
67976+{
67977+ struct acl_subject_label *proc;
67978+ unsigned short i;
67979+
67980+ proc = task->acl;
67981+
67982+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67983+ return;
67984+
67985+ for (i = 0; i < RLIM_NLIMITS; i++) {
67986+ if (!(proc->resmask & (1U << i)))
67987+ continue;
67988+
67989+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67990+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67991+
67992+ if (i == RLIMIT_CPU)
67993+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
67994+ }
67995+
67996+ return;
67997+}
67998+
67999+/* both of the below must be called with
68000+ rcu_read_lock();
68001+ read_lock(&tasklist_lock);
68002+ read_lock(&grsec_exec_file_lock);
68003+*/
68004+
68005+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68006+{
68007+ char *tmpname;
68008+ struct acl_subject_label *tmpsubj;
68009+ struct file *filp;
68010+ struct name_entry *nmatch;
68011+
68012+ filp = task->exec_file;
68013+ if (filp == NULL)
68014+ return NULL;
68015+
68016+ /* the following is to apply the correct subject
68017+ on binaries running when the RBAC system
68018+ is enabled, when the binaries have been
68019+ replaced or deleted since their execution
68020+ -----
68021+ when the RBAC system starts, the inode/dev
68022+ from exec_file will be one the RBAC system
68023+ is unaware of. It only knows the inode/dev
68024+ of the present file on disk, or the absence
68025+ of it.
68026+ */
68027+
68028+ if (filename)
68029+ nmatch = __lookup_name_entry(state, filename);
68030+ else {
68031+ preempt_disable();
68032+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68033+
68034+ nmatch = __lookup_name_entry(state, tmpname);
68035+ preempt_enable();
68036+ }
68037+ tmpsubj = NULL;
68038+ if (nmatch) {
68039+ if (nmatch->deleted)
68040+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68041+ else
68042+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68043+ }
68044+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68045+ then we fall back to a normal lookup based on the binary's ino/dev
68046+ */
68047+ if (tmpsubj == NULL)
68048+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68049+
68050+ return tmpsubj;
68051+}
68052+
68053+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68054+{
68055+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68056+}
68057+
68058+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68059+{
68060+ struct acl_object_label *obj;
68061+ struct file *filp;
68062+
68063+ filp = task->exec_file;
68064+
68065+ task->acl = subj;
68066+ task->is_writable = 0;
68067+ /* ignore additional mmap checks for processes that are writable
68068+ by the default ACL */
68069+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68070+ if (unlikely(obj->mode & GR_WRITE))
68071+ task->is_writable = 1;
68072+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68073+ if (unlikely(obj->mode & GR_WRITE))
68074+ task->is_writable = 1;
68075+
68076+ gr_set_proc_res(task);
68077+
68078+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68079+ 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);
68080+#endif
68081+}
68082+
68083+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68084+{
68085+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68086+}
68087+
68088+__u32
68089+gr_search_file(const struct dentry * dentry, const __u32 mode,
68090+ const struct vfsmount * mnt)
68091+{
68092+ __u32 retval = mode;
68093+ struct acl_subject_label *curracl;
68094+ struct acl_object_label *currobj;
68095+
68096+ if (unlikely(!(gr_status & GR_READY)))
68097+ return (mode & ~GR_AUDITS);
68098+
68099+ curracl = current->acl;
68100+
68101+ currobj = chk_obj_label(dentry, mnt, curracl);
68102+ retval = currobj->mode & mode;
68103+
68104+ /* if we're opening a specified transfer file for writing
68105+ (e.g. /dev/initctl), then transfer our role to init
68106+ */
68107+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68108+ current->role->roletype & GR_ROLE_PERSIST)) {
68109+ struct task_struct *task = init_pid_ns.child_reaper;
68110+
68111+ if (task->role != current->role) {
68112+ struct acl_subject_label *subj;
68113+
68114+ task->acl_sp_role = 0;
68115+ task->acl_role_id = current->acl_role_id;
68116+ task->role = current->role;
68117+ rcu_read_lock();
68118+ read_lock(&grsec_exec_file_lock);
68119+ subj = gr_get_subject_for_task(task, NULL);
68120+ gr_apply_subject_to_task(task, subj);
68121+ read_unlock(&grsec_exec_file_lock);
68122+ rcu_read_unlock();
68123+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68124+ }
68125+ }
68126+
68127+ if (unlikely
68128+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68129+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68130+ __u32 new_mode = mode;
68131+
68132+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68133+
68134+ retval = new_mode;
68135+
68136+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68137+ new_mode |= GR_INHERIT;
68138+
68139+ if (!(mode & GR_NOLEARN))
68140+ gr_log_learn(dentry, mnt, new_mode);
68141+ }
68142+
68143+ return retval;
68144+}
68145+
68146+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68147+ const struct dentry *parent,
68148+ const struct vfsmount *mnt)
68149+{
68150+ struct name_entry *match;
68151+ struct acl_object_label *matchpo;
68152+ struct acl_subject_label *curracl;
68153+ char *path;
68154+
68155+ if (unlikely(!(gr_status & GR_READY)))
68156+ return NULL;
68157+
68158+ preempt_disable();
68159+ path = gr_to_filename_rbac(new_dentry, mnt);
68160+ match = lookup_name_entry_create(path);
68161+
68162+ curracl = current->acl;
68163+
68164+ if (match) {
68165+ read_lock(&gr_inode_lock);
68166+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68167+ read_unlock(&gr_inode_lock);
68168+
68169+ if (matchpo) {
68170+ preempt_enable();
68171+ return matchpo;
68172+ }
68173+ }
68174+
68175+ // lookup parent
68176+
68177+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68178+
68179+ preempt_enable();
68180+ return matchpo;
68181+}
68182+
68183+__u32
68184+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68185+ const struct vfsmount * mnt, const __u32 mode)
68186+{
68187+ struct acl_object_label *matchpo;
68188+ __u32 retval;
68189+
68190+ if (unlikely(!(gr_status & GR_READY)))
68191+ return (mode & ~GR_AUDITS);
68192+
68193+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68194+
68195+ retval = matchpo->mode & mode;
68196+
68197+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68198+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68199+ __u32 new_mode = mode;
68200+
68201+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68202+
68203+ gr_log_learn(new_dentry, mnt, new_mode);
68204+ return new_mode;
68205+ }
68206+
68207+ return retval;
68208+}
68209+
68210+__u32
68211+gr_check_link(const struct dentry * new_dentry,
68212+ const struct dentry * parent_dentry,
68213+ const struct vfsmount * parent_mnt,
68214+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68215+{
68216+ struct acl_object_label *obj;
68217+ __u32 oldmode, newmode;
68218+ __u32 needmode;
68219+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68220+ GR_DELETE | GR_INHERIT;
68221+
68222+ if (unlikely(!(gr_status & GR_READY)))
68223+ return (GR_CREATE | GR_LINK);
68224+
68225+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68226+ oldmode = obj->mode;
68227+
68228+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68229+ newmode = obj->mode;
68230+
68231+ needmode = newmode & checkmodes;
68232+
68233+ // old name for hardlink must have at least the permissions of the new name
68234+ if ((oldmode & needmode) != needmode)
68235+ goto bad;
68236+
68237+ // if old name had restrictions/auditing, make sure the new name does as well
68238+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68239+
68240+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68241+ if (is_privileged_binary(old_dentry))
68242+ needmode |= GR_SETID;
68243+
68244+ if ((newmode & needmode) != needmode)
68245+ goto bad;
68246+
68247+ // enforce minimum permissions
68248+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68249+ return newmode;
68250+bad:
68251+ needmode = oldmode;
68252+ if (is_privileged_binary(old_dentry))
68253+ needmode |= GR_SETID;
68254+
68255+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68256+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68257+ return (GR_CREATE | GR_LINK);
68258+ } else if (newmode & GR_SUPPRESS)
68259+ return GR_SUPPRESS;
68260+ else
68261+ return 0;
68262+}
68263+
68264+int
68265+gr_check_hidden_task(const struct task_struct *task)
68266+{
68267+ if (unlikely(!(gr_status & GR_READY)))
68268+ return 0;
68269+
68270+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68271+ return 1;
68272+
68273+ return 0;
68274+}
68275+
68276+int
68277+gr_check_protected_task(const struct task_struct *task)
68278+{
68279+ if (unlikely(!(gr_status & GR_READY) || !task))
68280+ return 0;
68281+
68282+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68283+ task->acl != current->acl)
68284+ return 1;
68285+
68286+ return 0;
68287+}
68288+
68289+int
68290+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68291+{
68292+ struct task_struct *p;
68293+ int ret = 0;
68294+
68295+ if (unlikely(!(gr_status & GR_READY) || !pid))
68296+ return ret;
68297+
68298+ read_lock(&tasklist_lock);
68299+ do_each_pid_task(pid, type, p) {
68300+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68301+ p->acl != current->acl) {
68302+ ret = 1;
68303+ goto out;
68304+ }
68305+ } while_each_pid_task(pid, type, p);
68306+out:
68307+ read_unlock(&tasklist_lock);
68308+
68309+ return ret;
68310+}
68311+
68312+void
68313+gr_copy_label(struct task_struct *tsk)
68314+{
68315+ struct task_struct *p = current;
68316+
68317+ tsk->inherited = p->inherited;
68318+ tsk->acl_sp_role = 0;
68319+ tsk->acl_role_id = p->acl_role_id;
68320+ tsk->acl = p->acl;
68321+ tsk->role = p->role;
68322+ tsk->signal->used_accept = 0;
68323+ tsk->signal->curr_ip = p->signal->curr_ip;
68324+ tsk->signal->saved_ip = p->signal->saved_ip;
68325+ if (p->exec_file)
68326+ get_file(p->exec_file);
68327+ tsk->exec_file = p->exec_file;
68328+ tsk->is_writable = p->is_writable;
68329+ if (unlikely(p->signal->used_accept)) {
68330+ p->signal->curr_ip = 0;
68331+ p->signal->saved_ip = 0;
68332+ }
68333+
68334+ return;
68335+}
68336+
68337+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68338+
68339+int
68340+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68341+{
68342+ unsigned int i;
68343+ __u16 num;
68344+ uid_t *uidlist;
68345+ uid_t curuid;
68346+ int realok = 0;
68347+ int effectiveok = 0;
68348+ int fsok = 0;
68349+ uid_t globalreal, globaleffective, globalfs;
68350+
68351+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68352+ struct user_struct *user;
68353+
68354+ if (!uid_valid(real))
68355+ goto skipit;
68356+
68357+ /* find user based on global namespace */
68358+
68359+ globalreal = GR_GLOBAL_UID(real);
68360+
68361+ user = find_user(make_kuid(&init_user_ns, globalreal));
68362+ if (user == NULL)
68363+ goto skipit;
68364+
68365+ if (gr_process_kernel_setuid_ban(user)) {
68366+ /* for find_user */
68367+ free_uid(user);
68368+ return 1;
68369+ }
68370+
68371+ /* for find_user */
68372+ free_uid(user);
68373+
68374+skipit:
68375+#endif
68376+
68377+ if (unlikely(!(gr_status & GR_READY)))
68378+ return 0;
68379+
68380+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68381+ gr_log_learn_uid_change(real, effective, fs);
68382+
68383+ num = current->acl->user_trans_num;
68384+ uidlist = current->acl->user_transitions;
68385+
68386+ if (uidlist == NULL)
68387+ return 0;
68388+
68389+ if (!uid_valid(real)) {
68390+ realok = 1;
68391+ globalreal = (uid_t)-1;
68392+ } else {
68393+ globalreal = GR_GLOBAL_UID(real);
68394+ }
68395+ if (!uid_valid(effective)) {
68396+ effectiveok = 1;
68397+ globaleffective = (uid_t)-1;
68398+ } else {
68399+ globaleffective = GR_GLOBAL_UID(effective);
68400+ }
68401+ if (!uid_valid(fs)) {
68402+ fsok = 1;
68403+ globalfs = (uid_t)-1;
68404+ } else {
68405+ globalfs = GR_GLOBAL_UID(fs);
68406+ }
68407+
68408+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68409+ for (i = 0; i < num; i++) {
68410+ curuid = uidlist[i];
68411+ if (globalreal == curuid)
68412+ realok = 1;
68413+ if (globaleffective == curuid)
68414+ effectiveok = 1;
68415+ if (globalfs == curuid)
68416+ fsok = 1;
68417+ }
68418+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68419+ for (i = 0; i < num; i++) {
68420+ curuid = uidlist[i];
68421+ if (globalreal == curuid)
68422+ break;
68423+ if (globaleffective == curuid)
68424+ break;
68425+ if (globalfs == curuid)
68426+ break;
68427+ }
68428+ /* not in deny list */
68429+ if (i == num) {
68430+ realok = 1;
68431+ effectiveok = 1;
68432+ fsok = 1;
68433+ }
68434+ }
68435+
68436+ if (realok && effectiveok && fsok)
68437+ return 0;
68438+ else {
68439+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68440+ return 1;
68441+ }
68442+}
68443+
68444+int
68445+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68446+{
68447+ unsigned int i;
68448+ __u16 num;
68449+ gid_t *gidlist;
68450+ gid_t curgid;
68451+ int realok = 0;
68452+ int effectiveok = 0;
68453+ int fsok = 0;
68454+ gid_t globalreal, globaleffective, globalfs;
68455+
68456+ if (unlikely(!(gr_status & GR_READY)))
68457+ return 0;
68458+
68459+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68460+ gr_log_learn_gid_change(real, effective, fs);
68461+
68462+ num = current->acl->group_trans_num;
68463+ gidlist = current->acl->group_transitions;
68464+
68465+ if (gidlist == NULL)
68466+ return 0;
68467+
68468+ if (!gid_valid(real)) {
68469+ realok = 1;
68470+ globalreal = (gid_t)-1;
68471+ } else {
68472+ globalreal = GR_GLOBAL_GID(real);
68473+ }
68474+ if (!gid_valid(effective)) {
68475+ effectiveok = 1;
68476+ globaleffective = (gid_t)-1;
68477+ } else {
68478+ globaleffective = GR_GLOBAL_GID(effective);
68479+ }
68480+ if (!gid_valid(fs)) {
68481+ fsok = 1;
68482+ globalfs = (gid_t)-1;
68483+ } else {
68484+ globalfs = GR_GLOBAL_GID(fs);
68485+ }
68486+
68487+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68488+ for (i = 0; i < num; i++) {
68489+ curgid = gidlist[i];
68490+ if (globalreal == curgid)
68491+ realok = 1;
68492+ if (globaleffective == curgid)
68493+ effectiveok = 1;
68494+ if (globalfs == curgid)
68495+ fsok = 1;
68496+ }
68497+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68498+ for (i = 0; i < num; i++) {
68499+ curgid = gidlist[i];
68500+ if (globalreal == curgid)
68501+ break;
68502+ if (globaleffective == curgid)
68503+ break;
68504+ if (globalfs == curgid)
68505+ break;
68506+ }
68507+ /* not in deny list */
68508+ if (i == num) {
68509+ realok = 1;
68510+ effectiveok = 1;
68511+ fsok = 1;
68512+ }
68513+ }
68514+
68515+ if (realok && effectiveok && fsok)
68516+ return 0;
68517+ else {
68518+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68519+ return 1;
68520+ }
68521+}
68522+
68523+extern int gr_acl_is_capable(const int cap);
68524+
68525+void
68526+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68527+{
68528+ struct acl_role_label *role = task->role;
68529+ struct acl_subject_label *subj = NULL;
68530+ struct acl_object_label *obj;
68531+ struct file *filp;
68532+ uid_t uid;
68533+ gid_t gid;
68534+
68535+ if (unlikely(!(gr_status & GR_READY)))
68536+ return;
68537+
68538+ uid = GR_GLOBAL_UID(kuid);
68539+ gid = GR_GLOBAL_GID(kgid);
68540+
68541+ filp = task->exec_file;
68542+
68543+ /* kernel process, we'll give them the kernel role */
68544+ if (unlikely(!filp)) {
68545+ task->role = running_polstate.kernel_role;
68546+ task->acl = running_polstate.kernel_role->root_label;
68547+ return;
68548+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68549+ /* save the current ip at time of role lookup so that the proper
68550+ IP will be learned for role_allowed_ip */
68551+ task->signal->saved_ip = task->signal->curr_ip;
68552+ role = lookup_acl_role_label(task, uid, gid);
68553+ }
68554+
68555+ /* don't change the role if we're not a privileged process */
68556+ if (role && task->role != role &&
68557+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68558+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68559+ return;
68560+
68561+ /* perform subject lookup in possibly new role
68562+ we can use this result below in the case where role == task->role
68563+ */
68564+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68565+
68566+ /* if we changed uid/gid, but result in the same role
68567+ and are using inheritance, don't lose the inherited subject
68568+ if current subject is other than what normal lookup
68569+ would result in, we arrived via inheritance, don't
68570+ lose subject
68571+ */
68572+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68573+ (subj == task->acl)))
68574+ task->acl = subj;
68575+
68576+ /* leave task->inherited unaffected */
68577+
68578+ task->role = role;
68579+
68580+ task->is_writable = 0;
68581+
68582+ /* ignore additional mmap checks for processes that are writable
68583+ by the default ACL */
68584+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68585+ if (unlikely(obj->mode & GR_WRITE))
68586+ task->is_writable = 1;
68587+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68588+ if (unlikely(obj->mode & GR_WRITE))
68589+ task->is_writable = 1;
68590+
68591+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68592+ 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);
68593+#endif
68594+
68595+ gr_set_proc_res(task);
68596+
68597+ return;
68598+}
68599+
68600+int
68601+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68602+ const int unsafe_flags)
68603+{
68604+ struct task_struct *task = current;
68605+ struct acl_subject_label *newacl;
68606+ struct acl_object_label *obj;
68607+ __u32 retmode;
68608+
68609+ if (unlikely(!(gr_status & GR_READY)))
68610+ return 0;
68611+
68612+ newacl = chk_subj_label(dentry, mnt, task->role);
68613+
68614+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68615+ did an exec
68616+ */
68617+ rcu_read_lock();
68618+ read_lock(&tasklist_lock);
68619+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68620+ (task->parent->acl->mode & GR_POVERRIDE))) {
68621+ read_unlock(&tasklist_lock);
68622+ rcu_read_unlock();
68623+ goto skip_check;
68624+ }
68625+ read_unlock(&tasklist_lock);
68626+ rcu_read_unlock();
68627+
68628+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68629+ !(task->role->roletype & GR_ROLE_GOD) &&
68630+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68631+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68632+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68633+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68634+ else
68635+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68636+ return -EACCES;
68637+ }
68638+
68639+skip_check:
68640+
68641+ obj = chk_obj_label(dentry, mnt, task->acl);
68642+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68643+
68644+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68645+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68646+ if (obj->nested)
68647+ task->acl = obj->nested;
68648+ else
68649+ task->acl = newacl;
68650+ task->inherited = 0;
68651+ } else {
68652+ task->inherited = 1;
68653+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68654+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68655+ }
68656+
68657+ task->is_writable = 0;
68658+
68659+ /* ignore additional mmap checks for processes that are writable
68660+ by the default ACL */
68661+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68662+ if (unlikely(obj->mode & GR_WRITE))
68663+ task->is_writable = 1;
68664+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68665+ if (unlikely(obj->mode & GR_WRITE))
68666+ task->is_writable = 1;
68667+
68668+ gr_set_proc_res(task);
68669+
68670+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68671+ 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);
68672+#endif
68673+ return 0;
68674+}
68675+
68676+/* always called with valid inodev ptr */
68677+static void
68678+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68679+{
68680+ struct acl_object_label *matchpo;
68681+ struct acl_subject_label *matchps;
68682+ struct acl_subject_label *subj;
68683+ struct acl_role_label *role;
68684+ unsigned int x;
68685+
68686+ FOR_EACH_ROLE_START(role)
68687+ FOR_EACH_SUBJECT_START(role, subj, x)
68688+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68689+ matchpo->mode |= GR_DELETED;
68690+ FOR_EACH_SUBJECT_END(subj,x)
68691+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68692+ /* nested subjects aren't in the role's subj_hash table */
68693+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68694+ matchpo->mode |= GR_DELETED;
68695+ FOR_EACH_NESTED_SUBJECT_END(subj)
68696+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68697+ matchps->mode |= GR_DELETED;
68698+ FOR_EACH_ROLE_END(role)
68699+
68700+ inodev->nentry->deleted = 1;
68701+
68702+ return;
68703+}
68704+
68705+void
68706+gr_handle_delete(const ino_t ino, const dev_t dev)
68707+{
68708+ struct inodev_entry *inodev;
68709+
68710+ if (unlikely(!(gr_status & GR_READY)))
68711+ return;
68712+
68713+ write_lock(&gr_inode_lock);
68714+ inodev = lookup_inodev_entry(ino, dev);
68715+ if (inodev != NULL)
68716+ do_handle_delete(inodev, ino, dev);
68717+ write_unlock(&gr_inode_lock);
68718+
68719+ return;
68720+}
68721+
68722+static void
68723+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68724+ const ino_t newinode, const dev_t newdevice,
68725+ struct acl_subject_label *subj)
68726+{
68727+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68728+ struct acl_object_label *match;
68729+
68730+ match = subj->obj_hash[index];
68731+
68732+ while (match && (match->inode != oldinode ||
68733+ match->device != olddevice ||
68734+ !(match->mode & GR_DELETED)))
68735+ match = match->next;
68736+
68737+ if (match && (match->inode == oldinode)
68738+ && (match->device == olddevice)
68739+ && (match->mode & GR_DELETED)) {
68740+ if (match->prev == NULL) {
68741+ subj->obj_hash[index] = match->next;
68742+ if (match->next != NULL)
68743+ match->next->prev = NULL;
68744+ } else {
68745+ match->prev->next = match->next;
68746+ if (match->next != NULL)
68747+ match->next->prev = match->prev;
68748+ }
68749+ match->prev = NULL;
68750+ match->next = NULL;
68751+ match->inode = newinode;
68752+ match->device = newdevice;
68753+ match->mode &= ~GR_DELETED;
68754+
68755+ insert_acl_obj_label(match, subj);
68756+ }
68757+
68758+ return;
68759+}
68760+
68761+static void
68762+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68763+ const ino_t newinode, const dev_t newdevice,
68764+ struct acl_role_label *role)
68765+{
68766+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68767+ struct acl_subject_label *match;
68768+
68769+ match = role->subj_hash[index];
68770+
68771+ while (match && (match->inode != oldinode ||
68772+ match->device != olddevice ||
68773+ !(match->mode & GR_DELETED)))
68774+ match = match->next;
68775+
68776+ if (match && (match->inode == oldinode)
68777+ && (match->device == olddevice)
68778+ && (match->mode & GR_DELETED)) {
68779+ if (match->prev == NULL) {
68780+ role->subj_hash[index] = match->next;
68781+ if (match->next != NULL)
68782+ match->next->prev = NULL;
68783+ } else {
68784+ match->prev->next = match->next;
68785+ if (match->next != NULL)
68786+ match->next->prev = match->prev;
68787+ }
68788+ match->prev = NULL;
68789+ match->next = NULL;
68790+ match->inode = newinode;
68791+ match->device = newdevice;
68792+ match->mode &= ~GR_DELETED;
68793+
68794+ insert_acl_subj_label(match, role);
68795+ }
68796+
68797+ return;
68798+}
68799+
68800+static void
68801+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68802+ const ino_t newinode, const dev_t newdevice)
68803+{
68804+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68805+ struct inodev_entry *match;
68806+
68807+ match = running_polstate.inodev_set.i_hash[index];
68808+
68809+ while (match && (match->nentry->inode != oldinode ||
68810+ match->nentry->device != olddevice || !match->nentry->deleted))
68811+ match = match->next;
68812+
68813+ if (match && (match->nentry->inode == oldinode)
68814+ && (match->nentry->device == olddevice) &&
68815+ match->nentry->deleted) {
68816+ if (match->prev == NULL) {
68817+ running_polstate.inodev_set.i_hash[index] = match->next;
68818+ if (match->next != NULL)
68819+ match->next->prev = NULL;
68820+ } else {
68821+ match->prev->next = match->next;
68822+ if (match->next != NULL)
68823+ match->next->prev = match->prev;
68824+ }
68825+ match->prev = NULL;
68826+ match->next = NULL;
68827+ match->nentry->inode = newinode;
68828+ match->nentry->device = newdevice;
68829+ match->nentry->deleted = 0;
68830+
68831+ insert_inodev_entry(match);
68832+ }
68833+
68834+ return;
68835+}
68836+
68837+static void
68838+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68839+{
68840+ struct acl_subject_label *subj;
68841+ struct acl_role_label *role;
68842+ unsigned int x;
68843+
68844+ FOR_EACH_ROLE_START(role)
68845+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68846+
68847+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68848+ if ((subj->inode == ino) && (subj->device == dev)) {
68849+ subj->inode = ino;
68850+ subj->device = dev;
68851+ }
68852+ /* nested subjects aren't in the role's subj_hash table */
68853+ update_acl_obj_label(matchn->inode, matchn->device,
68854+ ino, dev, subj);
68855+ FOR_EACH_NESTED_SUBJECT_END(subj)
68856+ FOR_EACH_SUBJECT_START(role, subj, x)
68857+ update_acl_obj_label(matchn->inode, matchn->device,
68858+ ino, dev, subj);
68859+ FOR_EACH_SUBJECT_END(subj,x)
68860+ FOR_EACH_ROLE_END(role)
68861+
68862+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68863+
68864+ return;
68865+}
68866+
68867+static void
68868+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68869+ const struct vfsmount *mnt)
68870+{
68871+ ino_t ino = dentry->d_inode->i_ino;
68872+ dev_t dev = __get_dev(dentry);
68873+
68874+ __do_handle_create(matchn, ino, dev);
68875+
68876+ return;
68877+}
68878+
68879+void
68880+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68881+{
68882+ struct name_entry *matchn;
68883+
68884+ if (unlikely(!(gr_status & GR_READY)))
68885+ return;
68886+
68887+ preempt_disable();
68888+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68889+
68890+ if (unlikely((unsigned long)matchn)) {
68891+ write_lock(&gr_inode_lock);
68892+ do_handle_create(matchn, dentry, mnt);
68893+ write_unlock(&gr_inode_lock);
68894+ }
68895+ preempt_enable();
68896+
68897+ return;
68898+}
68899+
68900+void
68901+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68902+{
68903+ struct name_entry *matchn;
68904+
68905+ if (unlikely(!(gr_status & GR_READY)))
68906+ return;
68907+
68908+ preempt_disable();
68909+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68910+
68911+ if (unlikely((unsigned long)matchn)) {
68912+ write_lock(&gr_inode_lock);
68913+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68914+ write_unlock(&gr_inode_lock);
68915+ }
68916+ preempt_enable();
68917+
68918+ return;
68919+}
68920+
68921+void
68922+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68923+ struct dentry *old_dentry,
68924+ struct dentry *new_dentry,
68925+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
68926+{
68927+ struct name_entry *matchn;
68928+ struct name_entry *matchn2 = NULL;
68929+ struct inodev_entry *inodev;
68930+ struct inode *inode = new_dentry->d_inode;
68931+ ino_t old_ino = old_dentry->d_inode->i_ino;
68932+ dev_t old_dev = __get_dev(old_dentry);
68933+ unsigned int exchange = flags & RENAME_EXCHANGE;
68934+
68935+ /* vfs_rename swaps the name and parent link for old_dentry and
68936+ new_dentry
68937+ at this point, old_dentry has the new name, parent link, and inode
68938+ for the renamed file
68939+ if a file is being replaced by a rename, new_dentry has the inode
68940+ and name for the replaced file
68941+ */
68942+
68943+ if (unlikely(!(gr_status & GR_READY)))
68944+ return;
68945+
68946+ preempt_disable();
68947+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68948+
68949+ /* exchange cases:
68950+ a filename exists for the source, but not dest
68951+ do a recreate on source
68952+ a filename exists for the dest, but not source
68953+ do a recreate on dest
68954+ a filename exists for both source and dest
68955+ delete source and dest, then create source and dest
68956+ a filename exists for neither source nor dest
68957+ no updates needed
68958+
68959+ the name entry lookups get us the old inode/dev associated with
68960+ each name, so do the deletes first (if possible) so that when
68961+ we do the create, we pick up on the right entries
68962+ */
68963+
68964+ if (exchange)
68965+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
68966+
68967+ /* we wouldn't have to check d_inode if it weren't for
68968+ NFS silly-renaming
68969+ */
68970+
68971+ write_lock(&gr_inode_lock);
68972+ if (unlikely((replace || exchange) && inode)) {
68973+ ino_t new_ino = inode->i_ino;
68974+ dev_t new_dev = __get_dev(new_dentry);
68975+
68976+ inodev = lookup_inodev_entry(new_ino, new_dev);
68977+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68978+ do_handle_delete(inodev, new_ino, new_dev);
68979+ }
68980+
68981+ inodev = lookup_inodev_entry(old_ino, old_dev);
68982+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68983+ do_handle_delete(inodev, old_ino, old_dev);
68984+
68985+ if (unlikely(matchn != NULL))
68986+ do_handle_create(matchn, old_dentry, mnt);
68987+
68988+ if (unlikely(matchn2 != NULL))
68989+ do_handle_create(matchn2, new_dentry, mnt);
68990+
68991+ write_unlock(&gr_inode_lock);
68992+ preempt_enable();
68993+
68994+ return;
68995+}
68996+
68997+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68998+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68999+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69000+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69001+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69002+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69003+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69004+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69005+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69006+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69007+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69008+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69009+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69010+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69011+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69012+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69013+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69014+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69015+};
69016+
69017+void
69018+gr_learn_resource(const struct task_struct *task,
69019+ const int res, const unsigned long wanted, const int gt)
69020+{
69021+ struct acl_subject_label *acl;
69022+ const struct cred *cred;
69023+
69024+ if (unlikely((gr_status & GR_READY) &&
69025+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69026+ goto skip_reslog;
69027+
69028+ gr_log_resource(task, res, wanted, gt);
69029+skip_reslog:
69030+
69031+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69032+ return;
69033+
69034+ acl = task->acl;
69035+
69036+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69037+ !(acl->resmask & (1U << (unsigned short) res))))
69038+ return;
69039+
69040+ if (wanted >= acl->res[res].rlim_cur) {
69041+ unsigned long res_add;
69042+
69043+ res_add = wanted + res_learn_bumps[res];
69044+
69045+ acl->res[res].rlim_cur = res_add;
69046+
69047+ if (wanted > acl->res[res].rlim_max)
69048+ acl->res[res].rlim_max = res_add;
69049+
69050+ /* only log the subject filename, since resource logging is supported for
69051+ single-subject learning only */
69052+ rcu_read_lock();
69053+ cred = __task_cred(task);
69054+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69055+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69056+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69057+ "", (unsigned long) res, &task->signal->saved_ip);
69058+ rcu_read_unlock();
69059+ }
69060+
69061+ return;
69062+}
69063+EXPORT_SYMBOL_GPL(gr_learn_resource);
69064+#endif
69065+
69066+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69067+void
69068+pax_set_initial_flags(struct linux_binprm *bprm)
69069+{
69070+ struct task_struct *task = current;
69071+ struct acl_subject_label *proc;
69072+ unsigned long flags;
69073+
69074+ if (unlikely(!(gr_status & GR_READY)))
69075+ return;
69076+
69077+ flags = pax_get_flags(task);
69078+
69079+ proc = task->acl;
69080+
69081+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69082+ flags &= ~MF_PAX_PAGEEXEC;
69083+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69084+ flags &= ~MF_PAX_SEGMEXEC;
69085+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69086+ flags &= ~MF_PAX_RANDMMAP;
69087+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69088+ flags &= ~MF_PAX_EMUTRAMP;
69089+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69090+ flags &= ~MF_PAX_MPROTECT;
69091+
69092+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69093+ flags |= MF_PAX_PAGEEXEC;
69094+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69095+ flags |= MF_PAX_SEGMEXEC;
69096+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69097+ flags |= MF_PAX_RANDMMAP;
69098+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69099+ flags |= MF_PAX_EMUTRAMP;
69100+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69101+ flags |= MF_PAX_MPROTECT;
69102+
69103+ pax_set_flags(task, flags);
69104+
69105+ return;
69106+}
69107+#endif
69108+
69109+int
69110+gr_handle_proc_ptrace(struct task_struct *task)
69111+{
69112+ struct file *filp;
69113+ struct task_struct *tmp = task;
69114+ struct task_struct *curtemp = current;
69115+ __u32 retmode;
69116+
69117+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69118+ if (unlikely(!(gr_status & GR_READY)))
69119+ return 0;
69120+#endif
69121+
69122+ read_lock(&tasklist_lock);
69123+ read_lock(&grsec_exec_file_lock);
69124+ filp = task->exec_file;
69125+
69126+ while (task_pid_nr(tmp) > 0) {
69127+ if (tmp == curtemp)
69128+ break;
69129+ tmp = tmp->real_parent;
69130+ }
69131+
69132+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69133+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69134+ read_unlock(&grsec_exec_file_lock);
69135+ read_unlock(&tasklist_lock);
69136+ return 1;
69137+ }
69138+
69139+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69140+ if (!(gr_status & GR_READY)) {
69141+ read_unlock(&grsec_exec_file_lock);
69142+ read_unlock(&tasklist_lock);
69143+ return 0;
69144+ }
69145+#endif
69146+
69147+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69148+ read_unlock(&grsec_exec_file_lock);
69149+ read_unlock(&tasklist_lock);
69150+
69151+ if (retmode & GR_NOPTRACE)
69152+ return 1;
69153+
69154+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69155+ && (current->acl != task->acl || (current->acl != current->role->root_label
69156+ && task_pid_nr(current) != task_pid_nr(task))))
69157+ return 1;
69158+
69159+ return 0;
69160+}
69161+
69162+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69163+{
69164+ if (unlikely(!(gr_status & GR_READY)))
69165+ return;
69166+
69167+ if (!(current->role->roletype & GR_ROLE_GOD))
69168+ return;
69169+
69170+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69171+ p->role->rolename, gr_task_roletype_to_char(p),
69172+ p->acl->filename);
69173+}
69174+
69175+int
69176+gr_handle_ptrace(struct task_struct *task, const long request)
69177+{
69178+ struct task_struct *tmp = task;
69179+ struct task_struct *curtemp = current;
69180+ __u32 retmode;
69181+
69182+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69183+ if (unlikely(!(gr_status & GR_READY)))
69184+ return 0;
69185+#endif
69186+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69187+ read_lock(&tasklist_lock);
69188+ while (task_pid_nr(tmp) > 0) {
69189+ if (tmp == curtemp)
69190+ break;
69191+ tmp = tmp->real_parent;
69192+ }
69193+
69194+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69195+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69196+ read_unlock(&tasklist_lock);
69197+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69198+ return 1;
69199+ }
69200+ read_unlock(&tasklist_lock);
69201+ }
69202+
69203+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69204+ if (!(gr_status & GR_READY))
69205+ return 0;
69206+#endif
69207+
69208+ read_lock(&grsec_exec_file_lock);
69209+ if (unlikely(!task->exec_file)) {
69210+ read_unlock(&grsec_exec_file_lock);
69211+ return 0;
69212+ }
69213+
69214+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69215+ read_unlock(&grsec_exec_file_lock);
69216+
69217+ if (retmode & GR_NOPTRACE) {
69218+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69219+ return 1;
69220+ }
69221+
69222+ if (retmode & GR_PTRACERD) {
69223+ switch (request) {
69224+ case PTRACE_SEIZE:
69225+ case PTRACE_POKETEXT:
69226+ case PTRACE_POKEDATA:
69227+ case PTRACE_POKEUSR:
69228+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69229+ case PTRACE_SETREGS:
69230+ case PTRACE_SETFPREGS:
69231+#endif
69232+#ifdef CONFIG_X86
69233+ case PTRACE_SETFPXREGS:
69234+#endif
69235+#ifdef CONFIG_ALTIVEC
69236+ case PTRACE_SETVRREGS:
69237+#endif
69238+ return 1;
69239+ default:
69240+ return 0;
69241+ }
69242+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69243+ !(current->role->roletype & GR_ROLE_GOD) &&
69244+ (current->acl != task->acl)) {
69245+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69246+ return 1;
69247+ }
69248+
69249+ return 0;
69250+}
69251+
69252+static int is_writable_mmap(const struct file *filp)
69253+{
69254+ struct task_struct *task = current;
69255+ struct acl_object_label *obj, *obj2;
69256+
69257+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69258+ !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))) {
69259+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69260+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69261+ task->role->root_label);
69262+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69263+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69264+ return 1;
69265+ }
69266+ }
69267+ return 0;
69268+}
69269+
69270+int
69271+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69272+{
69273+ __u32 mode;
69274+
69275+ if (unlikely(!file || !(prot & PROT_EXEC)))
69276+ return 1;
69277+
69278+ if (is_writable_mmap(file))
69279+ return 0;
69280+
69281+ mode =
69282+ gr_search_file(file->f_path.dentry,
69283+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69284+ file->f_path.mnt);
69285+
69286+ if (!gr_tpe_allow(file))
69287+ return 0;
69288+
69289+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69290+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69291+ return 0;
69292+ } else if (unlikely(!(mode & GR_EXEC))) {
69293+ return 0;
69294+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69295+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69296+ return 1;
69297+ }
69298+
69299+ return 1;
69300+}
69301+
69302+int
69303+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69304+{
69305+ __u32 mode;
69306+
69307+ if (unlikely(!file || !(prot & PROT_EXEC)))
69308+ return 1;
69309+
69310+ if (is_writable_mmap(file))
69311+ return 0;
69312+
69313+ mode =
69314+ gr_search_file(file->f_path.dentry,
69315+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69316+ file->f_path.mnt);
69317+
69318+ if (!gr_tpe_allow(file))
69319+ return 0;
69320+
69321+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69322+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69323+ return 0;
69324+ } else if (unlikely(!(mode & GR_EXEC))) {
69325+ return 0;
69326+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69327+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69328+ return 1;
69329+ }
69330+
69331+ return 1;
69332+}
69333+
69334+void
69335+gr_acl_handle_psacct(struct task_struct *task, const long code)
69336+{
69337+ unsigned long runtime, cputime;
69338+ cputime_t utime, stime;
69339+ unsigned int wday, cday;
69340+ __u8 whr, chr;
69341+ __u8 wmin, cmin;
69342+ __u8 wsec, csec;
69343+ struct timespec timeval;
69344+
69345+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69346+ !(task->acl->mode & GR_PROCACCT)))
69347+ return;
69348+
69349+ do_posix_clock_monotonic_gettime(&timeval);
69350+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69351+ wday = runtime / (60 * 60 * 24);
69352+ runtime -= wday * (60 * 60 * 24);
69353+ whr = runtime / (60 * 60);
69354+ runtime -= whr * (60 * 60);
69355+ wmin = runtime / 60;
69356+ runtime -= wmin * 60;
69357+ wsec = runtime;
69358+
69359+ task_cputime(task, &utime, &stime);
69360+ cputime = cputime_to_secs(utime + stime);
69361+ cday = cputime / (60 * 60 * 24);
69362+ cputime -= cday * (60 * 60 * 24);
69363+ chr = cputime / (60 * 60);
69364+ cputime -= chr * (60 * 60);
69365+ cmin = cputime / 60;
69366+ cputime -= cmin * 60;
69367+ csec = cputime;
69368+
69369+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69370+
69371+ return;
69372+}
69373+
69374+#ifdef CONFIG_TASKSTATS
69375+int gr_is_taskstats_denied(int pid)
69376+{
69377+ struct task_struct *task;
69378+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69379+ const struct cred *cred;
69380+#endif
69381+ int ret = 0;
69382+
69383+ /* restrict taskstats viewing to un-chrooted root users
69384+ who have the 'view' subject flag if the RBAC system is enabled
69385+ */
69386+
69387+ rcu_read_lock();
69388+ read_lock(&tasklist_lock);
69389+ task = find_task_by_vpid(pid);
69390+ if (task) {
69391+#ifdef CONFIG_GRKERNSEC_CHROOT
69392+ if (proc_is_chrooted(task))
69393+ ret = -EACCES;
69394+#endif
69395+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69396+ cred = __task_cred(task);
69397+#ifdef CONFIG_GRKERNSEC_PROC_USER
69398+ if (gr_is_global_nonroot(cred->uid))
69399+ ret = -EACCES;
69400+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69401+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69402+ ret = -EACCES;
69403+#endif
69404+#endif
69405+ if (gr_status & GR_READY) {
69406+ if (!(task->acl->mode & GR_VIEW))
69407+ ret = -EACCES;
69408+ }
69409+ } else
69410+ ret = -ENOENT;
69411+
69412+ read_unlock(&tasklist_lock);
69413+ rcu_read_unlock();
69414+
69415+ return ret;
69416+}
69417+#endif
69418+
69419+/* AUXV entries are filled via a descendant of search_binary_handler
69420+ after we've already applied the subject for the target
69421+*/
69422+int gr_acl_enable_at_secure(void)
69423+{
69424+ if (unlikely(!(gr_status & GR_READY)))
69425+ return 0;
69426+
69427+ if (current->acl->mode & GR_ATSECURE)
69428+ return 1;
69429+
69430+ return 0;
69431+}
69432+
69433+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69434+{
69435+ struct task_struct *task = current;
69436+ struct dentry *dentry = file->f_path.dentry;
69437+ struct vfsmount *mnt = file->f_path.mnt;
69438+ struct acl_object_label *obj, *tmp;
69439+ struct acl_subject_label *subj;
69440+ unsigned int bufsize;
69441+ int is_not_root;
69442+ char *path;
69443+ dev_t dev = __get_dev(dentry);
69444+
69445+ if (unlikely(!(gr_status & GR_READY)))
69446+ return 1;
69447+
69448+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69449+ return 1;
69450+
69451+ /* ignore Eric Biederman */
69452+ if (IS_PRIVATE(dentry->d_inode))
69453+ return 1;
69454+
69455+ subj = task->acl;
69456+ read_lock(&gr_inode_lock);
69457+ do {
69458+ obj = lookup_acl_obj_label(ino, dev, subj);
69459+ if (obj != NULL) {
69460+ read_unlock(&gr_inode_lock);
69461+ return (obj->mode & GR_FIND) ? 1 : 0;
69462+ }
69463+ } while ((subj = subj->parent_subject));
69464+ read_unlock(&gr_inode_lock);
69465+
69466+ /* this is purely an optimization since we're looking for an object
69467+ for the directory we're doing a readdir on
69468+ if it's possible for any globbed object to match the entry we're
69469+ filling into the directory, then the object we find here will be
69470+ an anchor point with attached globbed objects
69471+ */
69472+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69473+ if (obj->globbed == NULL)
69474+ return (obj->mode & GR_FIND) ? 1 : 0;
69475+
69476+ is_not_root = ((obj->filename[0] == '/') &&
69477+ (obj->filename[1] == '\0')) ? 0 : 1;
69478+ bufsize = PAGE_SIZE - namelen - is_not_root;
69479+
69480+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69481+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69482+ return 1;
69483+
69484+ preempt_disable();
69485+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69486+ bufsize);
69487+
69488+ bufsize = strlen(path);
69489+
69490+ /* if base is "/", don't append an additional slash */
69491+ if (is_not_root)
69492+ *(path + bufsize) = '/';
69493+ memcpy(path + bufsize + is_not_root, name, namelen);
69494+ *(path + bufsize + namelen + is_not_root) = '\0';
69495+
69496+ tmp = obj->globbed;
69497+ while (tmp) {
69498+ if (!glob_match(tmp->filename, path)) {
69499+ preempt_enable();
69500+ return (tmp->mode & GR_FIND) ? 1 : 0;
69501+ }
69502+ tmp = tmp->next;
69503+ }
69504+ preempt_enable();
69505+ return (obj->mode & GR_FIND) ? 1 : 0;
69506+}
69507+
69508+void gr_put_exec_file(struct task_struct *task)
69509+{
69510+ struct file *filp;
69511+
69512+ write_lock(&grsec_exec_file_lock);
69513+ filp = task->exec_file;
69514+ task->exec_file = NULL;
69515+ write_unlock(&grsec_exec_file_lock);
69516+
69517+ if (filp)
69518+ fput(filp);
69519+
69520+ return;
69521+}
69522+
69523+
69524+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69525+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69526+#endif
69527+#ifdef CONFIG_SECURITY
69528+EXPORT_SYMBOL_GPL(gr_check_user_change);
69529+EXPORT_SYMBOL_GPL(gr_check_group_change);
69530+#endif
69531+
69532diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69533new file mode 100644
69534index 0000000..18ffbbd
69535--- /dev/null
69536+++ b/grsecurity/gracl_alloc.c
69537@@ -0,0 +1,105 @@
69538+#include <linux/kernel.h>
69539+#include <linux/mm.h>
69540+#include <linux/slab.h>
69541+#include <linux/vmalloc.h>
69542+#include <linux/gracl.h>
69543+#include <linux/grsecurity.h>
69544+
69545+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69546+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69547+
69548+static __inline__ int
69549+alloc_pop(void)
69550+{
69551+ if (current_alloc_state->alloc_stack_next == 1)
69552+ return 0;
69553+
69554+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69555+
69556+ current_alloc_state->alloc_stack_next--;
69557+
69558+ return 1;
69559+}
69560+
69561+static __inline__ int
69562+alloc_push(void *buf)
69563+{
69564+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69565+ return 1;
69566+
69567+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69568+
69569+ current_alloc_state->alloc_stack_next++;
69570+
69571+ return 0;
69572+}
69573+
69574+void *
69575+acl_alloc(unsigned long len)
69576+{
69577+ void *ret = NULL;
69578+
69579+ if (!len || len > PAGE_SIZE)
69580+ goto out;
69581+
69582+ ret = kmalloc(len, GFP_KERNEL);
69583+
69584+ if (ret) {
69585+ if (alloc_push(ret)) {
69586+ kfree(ret);
69587+ ret = NULL;
69588+ }
69589+ }
69590+
69591+out:
69592+ return ret;
69593+}
69594+
69595+void *
69596+acl_alloc_num(unsigned long num, unsigned long len)
69597+{
69598+ if (!len || (num > (PAGE_SIZE / len)))
69599+ return NULL;
69600+
69601+ return acl_alloc(num * len);
69602+}
69603+
69604+void
69605+acl_free_all(void)
69606+{
69607+ if (!current_alloc_state->alloc_stack)
69608+ return;
69609+
69610+ while (alloc_pop()) ;
69611+
69612+ if (current_alloc_state->alloc_stack) {
69613+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69614+ kfree(current_alloc_state->alloc_stack);
69615+ else
69616+ vfree(current_alloc_state->alloc_stack);
69617+ }
69618+
69619+ current_alloc_state->alloc_stack = NULL;
69620+ current_alloc_state->alloc_stack_size = 1;
69621+ current_alloc_state->alloc_stack_next = 1;
69622+
69623+ return;
69624+}
69625+
69626+int
69627+acl_alloc_stack_init(unsigned long size)
69628+{
69629+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69630+ current_alloc_state->alloc_stack =
69631+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69632+ else
69633+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69634+
69635+ current_alloc_state->alloc_stack_size = size;
69636+ current_alloc_state->alloc_stack_next = 1;
69637+
69638+ if (!current_alloc_state->alloc_stack)
69639+ return 0;
69640+ else
69641+ return 1;
69642+}
69643diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69644new file mode 100644
69645index 0000000..bdd51ea
69646--- /dev/null
69647+++ b/grsecurity/gracl_cap.c
69648@@ -0,0 +1,110 @@
69649+#include <linux/kernel.h>
69650+#include <linux/module.h>
69651+#include <linux/sched.h>
69652+#include <linux/gracl.h>
69653+#include <linux/grsecurity.h>
69654+#include <linux/grinternal.h>
69655+
69656+extern const char *captab_log[];
69657+extern int captab_log_entries;
69658+
69659+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69660+{
69661+ struct acl_subject_label *curracl;
69662+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69663+ kernel_cap_t cap_audit = __cap_empty_set;
69664+
69665+ if (!gr_acl_is_enabled())
69666+ return 1;
69667+
69668+ curracl = task->acl;
69669+
69670+ cap_drop = curracl->cap_lower;
69671+ cap_mask = curracl->cap_mask;
69672+ cap_audit = curracl->cap_invert_audit;
69673+
69674+ while ((curracl = curracl->parent_subject)) {
69675+ /* if the cap isn't specified in the current computed mask but is specified in the
69676+ current level subject, and is lowered in the current level subject, then add
69677+ it to the set of dropped capabilities
69678+ otherwise, add the current level subject's mask to the current computed mask
69679+ */
69680+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69681+ cap_raise(cap_mask, cap);
69682+ if (cap_raised(curracl->cap_lower, cap))
69683+ cap_raise(cap_drop, cap);
69684+ if (cap_raised(curracl->cap_invert_audit, cap))
69685+ cap_raise(cap_audit, cap);
69686+ }
69687+ }
69688+
69689+ if (!cap_raised(cap_drop, cap)) {
69690+ if (cap_raised(cap_audit, cap))
69691+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69692+ return 1;
69693+ }
69694+
69695+ curracl = task->acl;
69696+
69697+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69698+ && cap_raised(cred->cap_effective, cap)) {
69699+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69700+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69701+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69702+ gr_to_filename(task->exec_file->f_path.dentry,
69703+ task->exec_file->f_path.mnt) : curracl->filename,
69704+ curracl->filename, 0UL,
69705+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69706+ return 1;
69707+ }
69708+
69709+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69710+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69711+
69712+ return 0;
69713+}
69714+
69715+int
69716+gr_acl_is_capable(const int cap)
69717+{
69718+ return gr_task_acl_is_capable(current, current_cred(), cap);
69719+}
69720+
69721+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69722+{
69723+ struct acl_subject_label *curracl;
69724+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69725+
69726+ if (!gr_acl_is_enabled())
69727+ return 1;
69728+
69729+ curracl = task->acl;
69730+
69731+ cap_drop = curracl->cap_lower;
69732+ cap_mask = curracl->cap_mask;
69733+
69734+ while ((curracl = curracl->parent_subject)) {
69735+ /* if the cap isn't specified in the current computed mask but is specified in the
69736+ current level subject, and is lowered in the current level subject, then add
69737+ it to the set of dropped capabilities
69738+ otherwise, add the current level subject's mask to the current computed mask
69739+ */
69740+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69741+ cap_raise(cap_mask, cap);
69742+ if (cap_raised(curracl->cap_lower, cap))
69743+ cap_raise(cap_drop, cap);
69744+ }
69745+ }
69746+
69747+ if (!cap_raised(cap_drop, cap))
69748+ return 1;
69749+
69750+ return 0;
69751+}
69752+
69753+int
69754+gr_acl_is_capable_nolog(const int cap)
69755+{
69756+ return gr_task_acl_is_capable_nolog(current, cap);
69757+}
69758+
69759diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69760new file mode 100644
69761index 0000000..ca25605
69762--- /dev/null
69763+++ b/grsecurity/gracl_compat.c
69764@@ -0,0 +1,270 @@
69765+#include <linux/kernel.h>
69766+#include <linux/gracl.h>
69767+#include <linux/compat.h>
69768+#include <linux/gracl_compat.h>
69769+
69770+#include <asm/uaccess.h>
69771+
69772+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69773+{
69774+ struct gr_arg_wrapper_compat uwrapcompat;
69775+
69776+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69777+ return -EFAULT;
69778+
69779+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69780+ (uwrapcompat.version != 0x2901)) ||
69781+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69782+ return -EINVAL;
69783+
69784+ uwrap->arg = compat_ptr(uwrapcompat.arg);
69785+ uwrap->version = uwrapcompat.version;
69786+ uwrap->size = sizeof(struct gr_arg);
69787+
69788+ return 0;
69789+}
69790+
69791+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69792+{
69793+ struct gr_arg_compat argcompat;
69794+
69795+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69796+ return -EFAULT;
69797+
69798+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69799+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69800+ arg->role_db.num_roles = argcompat.role_db.num_roles;
69801+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69802+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69803+ arg->role_db.num_objects = argcompat.role_db.num_objects;
69804+
69805+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69806+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69807+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69808+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69809+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69810+ arg->segv_device = argcompat.segv_device;
69811+ arg->segv_inode = argcompat.segv_inode;
69812+ arg->segv_uid = argcompat.segv_uid;
69813+ arg->num_sprole_pws = argcompat.num_sprole_pws;
69814+ arg->mode = argcompat.mode;
69815+
69816+ return 0;
69817+}
69818+
69819+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69820+{
69821+ struct acl_object_label_compat objcompat;
69822+
69823+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69824+ return -EFAULT;
69825+
69826+ obj->filename = compat_ptr(objcompat.filename);
69827+ obj->inode = objcompat.inode;
69828+ obj->device = objcompat.device;
69829+ obj->mode = objcompat.mode;
69830+
69831+ obj->nested = compat_ptr(objcompat.nested);
69832+ obj->globbed = compat_ptr(objcompat.globbed);
69833+
69834+ obj->prev = compat_ptr(objcompat.prev);
69835+ obj->next = compat_ptr(objcompat.next);
69836+
69837+ return 0;
69838+}
69839+
69840+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69841+{
69842+ unsigned int i;
69843+ struct acl_subject_label_compat subjcompat;
69844+
69845+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69846+ return -EFAULT;
69847+
69848+ subj->filename = compat_ptr(subjcompat.filename);
69849+ subj->inode = subjcompat.inode;
69850+ subj->device = subjcompat.device;
69851+ subj->mode = subjcompat.mode;
69852+ subj->cap_mask = subjcompat.cap_mask;
69853+ subj->cap_lower = subjcompat.cap_lower;
69854+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
69855+
69856+ for (i = 0; i < GR_NLIMITS; i++) {
69857+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69858+ subj->res[i].rlim_cur = RLIM_INFINITY;
69859+ else
69860+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69861+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69862+ subj->res[i].rlim_max = RLIM_INFINITY;
69863+ else
69864+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69865+ }
69866+ subj->resmask = subjcompat.resmask;
69867+
69868+ subj->user_trans_type = subjcompat.user_trans_type;
69869+ subj->group_trans_type = subjcompat.group_trans_type;
69870+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69871+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69872+ subj->user_trans_num = subjcompat.user_trans_num;
69873+ subj->group_trans_num = subjcompat.group_trans_num;
69874+
69875+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69876+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69877+ subj->ip_type = subjcompat.ip_type;
69878+ subj->ips = compat_ptr(subjcompat.ips);
69879+ subj->ip_num = subjcompat.ip_num;
69880+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
69881+
69882+ subj->crashes = subjcompat.crashes;
69883+ subj->expires = subjcompat.expires;
69884+
69885+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69886+ subj->hash = compat_ptr(subjcompat.hash);
69887+ subj->prev = compat_ptr(subjcompat.prev);
69888+ subj->next = compat_ptr(subjcompat.next);
69889+
69890+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69891+ subj->obj_hash_size = subjcompat.obj_hash_size;
69892+ subj->pax_flags = subjcompat.pax_flags;
69893+
69894+ return 0;
69895+}
69896+
69897+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69898+{
69899+ struct acl_role_label_compat rolecompat;
69900+
69901+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69902+ return -EFAULT;
69903+
69904+ role->rolename = compat_ptr(rolecompat.rolename);
69905+ role->uidgid = rolecompat.uidgid;
69906+ role->roletype = rolecompat.roletype;
69907+
69908+ role->auth_attempts = rolecompat.auth_attempts;
69909+ role->expires = rolecompat.expires;
69910+
69911+ role->root_label = compat_ptr(rolecompat.root_label);
69912+ role->hash = compat_ptr(rolecompat.hash);
69913+
69914+ role->prev = compat_ptr(rolecompat.prev);
69915+ role->next = compat_ptr(rolecompat.next);
69916+
69917+ role->transitions = compat_ptr(rolecompat.transitions);
69918+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69919+ role->domain_children = compat_ptr(rolecompat.domain_children);
69920+ role->domain_child_num = rolecompat.domain_child_num;
69921+
69922+ role->umask = rolecompat.umask;
69923+
69924+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
69925+ role->subj_hash_size = rolecompat.subj_hash_size;
69926+
69927+ return 0;
69928+}
69929+
69930+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69931+{
69932+ struct role_allowed_ip_compat roleip_compat;
69933+
69934+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69935+ return -EFAULT;
69936+
69937+ roleip->addr = roleip_compat.addr;
69938+ roleip->netmask = roleip_compat.netmask;
69939+
69940+ roleip->prev = compat_ptr(roleip_compat.prev);
69941+ roleip->next = compat_ptr(roleip_compat.next);
69942+
69943+ return 0;
69944+}
69945+
69946+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69947+{
69948+ struct role_transition_compat trans_compat;
69949+
69950+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69951+ return -EFAULT;
69952+
69953+ trans->rolename = compat_ptr(trans_compat.rolename);
69954+
69955+ trans->prev = compat_ptr(trans_compat.prev);
69956+ trans->next = compat_ptr(trans_compat.next);
69957+
69958+ return 0;
69959+
69960+}
69961+
69962+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69963+{
69964+ struct gr_hash_struct_compat hash_compat;
69965+
69966+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69967+ return -EFAULT;
69968+
69969+ hash->table = compat_ptr(hash_compat.table);
69970+ hash->nametable = compat_ptr(hash_compat.nametable);
69971+ hash->first = compat_ptr(hash_compat.first);
69972+
69973+ hash->table_size = hash_compat.table_size;
69974+ hash->used_size = hash_compat.used_size;
69975+
69976+ hash->type = hash_compat.type;
69977+
69978+ return 0;
69979+}
69980+
69981+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69982+{
69983+ compat_uptr_t ptrcompat;
69984+
69985+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69986+ return -EFAULT;
69987+
69988+ *(void **)ptr = compat_ptr(ptrcompat);
69989+
69990+ return 0;
69991+}
69992+
69993+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69994+{
69995+ struct acl_ip_label_compat ip_compat;
69996+
69997+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69998+ return -EFAULT;
69999+
70000+ ip->iface = compat_ptr(ip_compat.iface);
70001+ ip->addr = ip_compat.addr;
70002+ ip->netmask = ip_compat.netmask;
70003+ ip->low = ip_compat.low;
70004+ ip->high = ip_compat.high;
70005+ ip->mode = ip_compat.mode;
70006+ ip->type = ip_compat.type;
70007+
70008+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70009+
70010+ ip->prev = compat_ptr(ip_compat.prev);
70011+ ip->next = compat_ptr(ip_compat.next);
70012+
70013+ return 0;
70014+}
70015+
70016+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70017+{
70018+ struct sprole_pw_compat pw_compat;
70019+
70020+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70021+ return -EFAULT;
70022+
70023+ pw->rolename = compat_ptr(pw_compat.rolename);
70024+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70025+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70026+
70027+ return 0;
70028+}
70029+
70030+size_t get_gr_arg_wrapper_size_compat(void)
70031+{
70032+ return sizeof(struct gr_arg_wrapper_compat);
70033+}
70034+
70035diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70036new file mode 100644
70037index 0000000..4008fdc
70038--- /dev/null
70039+++ b/grsecurity/gracl_fs.c
70040@@ -0,0 +1,445 @@
70041+#include <linux/kernel.h>
70042+#include <linux/sched.h>
70043+#include <linux/types.h>
70044+#include <linux/fs.h>
70045+#include <linux/file.h>
70046+#include <linux/stat.h>
70047+#include <linux/grsecurity.h>
70048+#include <linux/grinternal.h>
70049+#include <linux/gracl.h>
70050+
70051+umode_t
70052+gr_acl_umask(void)
70053+{
70054+ if (unlikely(!gr_acl_is_enabled()))
70055+ return 0;
70056+
70057+ return current->role->umask;
70058+}
70059+
70060+__u32
70061+gr_acl_handle_hidden_file(const struct dentry * dentry,
70062+ const struct vfsmount * mnt)
70063+{
70064+ __u32 mode;
70065+
70066+ if (unlikely(d_is_negative(dentry)))
70067+ return GR_FIND;
70068+
70069+ mode =
70070+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70071+
70072+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70073+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70074+ return mode;
70075+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70076+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70077+ return 0;
70078+ } else if (unlikely(!(mode & GR_FIND)))
70079+ return 0;
70080+
70081+ return GR_FIND;
70082+}
70083+
70084+__u32
70085+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70086+ int acc_mode)
70087+{
70088+ __u32 reqmode = GR_FIND;
70089+ __u32 mode;
70090+
70091+ if (unlikely(d_is_negative(dentry)))
70092+ return reqmode;
70093+
70094+ if (acc_mode & MAY_APPEND)
70095+ reqmode |= GR_APPEND;
70096+ else if (acc_mode & MAY_WRITE)
70097+ reqmode |= GR_WRITE;
70098+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70099+ reqmode |= GR_READ;
70100+
70101+ mode =
70102+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70103+ mnt);
70104+
70105+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70106+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70107+ reqmode & GR_READ ? " reading" : "",
70108+ reqmode & GR_WRITE ? " writing" : reqmode &
70109+ GR_APPEND ? " appending" : "");
70110+ return reqmode;
70111+ } else
70112+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70113+ {
70114+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70115+ reqmode & GR_READ ? " reading" : "",
70116+ reqmode & GR_WRITE ? " writing" : reqmode &
70117+ GR_APPEND ? " appending" : "");
70118+ return 0;
70119+ } else if (unlikely((mode & reqmode) != reqmode))
70120+ return 0;
70121+
70122+ return reqmode;
70123+}
70124+
70125+__u32
70126+gr_acl_handle_creat(const struct dentry * dentry,
70127+ const struct dentry * p_dentry,
70128+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70129+ const int imode)
70130+{
70131+ __u32 reqmode = GR_WRITE | GR_CREATE;
70132+ __u32 mode;
70133+
70134+ if (acc_mode & MAY_APPEND)
70135+ reqmode |= GR_APPEND;
70136+ // if a directory was required or the directory already exists, then
70137+ // don't count this open as a read
70138+ if ((acc_mode & MAY_READ) &&
70139+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70140+ reqmode |= GR_READ;
70141+ if ((open_flags & O_CREAT) &&
70142+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70143+ reqmode |= GR_SETID;
70144+
70145+ mode =
70146+ gr_check_create(dentry, p_dentry, p_mnt,
70147+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70148+
70149+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70150+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70151+ reqmode & GR_READ ? " reading" : "",
70152+ reqmode & GR_WRITE ? " writing" : reqmode &
70153+ GR_APPEND ? " appending" : "");
70154+ return reqmode;
70155+ } else
70156+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70157+ {
70158+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70159+ reqmode & GR_READ ? " reading" : "",
70160+ reqmode & GR_WRITE ? " writing" : reqmode &
70161+ GR_APPEND ? " appending" : "");
70162+ return 0;
70163+ } else if (unlikely((mode & reqmode) != reqmode))
70164+ return 0;
70165+
70166+ return reqmode;
70167+}
70168+
70169+__u32
70170+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70171+ const int fmode)
70172+{
70173+ __u32 mode, reqmode = GR_FIND;
70174+
70175+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70176+ reqmode |= GR_EXEC;
70177+ if (fmode & S_IWOTH)
70178+ reqmode |= GR_WRITE;
70179+ if (fmode & S_IROTH)
70180+ reqmode |= GR_READ;
70181+
70182+ mode =
70183+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70184+ mnt);
70185+
70186+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70187+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70188+ reqmode & GR_READ ? " reading" : "",
70189+ reqmode & GR_WRITE ? " writing" : "",
70190+ reqmode & GR_EXEC ? " executing" : "");
70191+ return reqmode;
70192+ } else
70193+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70194+ {
70195+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70196+ reqmode & GR_READ ? " reading" : "",
70197+ reqmode & GR_WRITE ? " writing" : "",
70198+ reqmode & GR_EXEC ? " executing" : "");
70199+ return 0;
70200+ } else if (unlikely((mode & reqmode) != reqmode))
70201+ return 0;
70202+
70203+ return reqmode;
70204+}
70205+
70206+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70207+{
70208+ __u32 mode;
70209+
70210+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70211+
70212+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70213+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70214+ return mode;
70215+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70216+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70217+ return 0;
70218+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70219+ return 0;
70220+
70221+ return (reqmode);
70222+}
70223+
70224+__u32
70225+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70226+{
70227+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70228+}
70229+
70230+__u32
70231+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70232+{
70233+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70234+}
70235+
70236+__u32
70237+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70238+{
70239+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70240+}
70241+
70242+__u32
70243+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70244+{
70245+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70246+}
70247+
70248+__u32
70249+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70250+ umode_t *modeptr)
70251+{
70252+ umode_t mode;
70253+
70254+ *modeptr &= ~gr_acl_umask();
70255+ mode = *modeptr;
70256+
70257+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70258+ return 1;
70259+
70260+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70261+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70262+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70263+ GR_CHMOD_ACL_MSG);
70264+ } else {
70265+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70266+ }
70267+}
70268+
70269+__u32
70270+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70271+{
70272+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70273+}
70274+
70275+__u32
70276+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70277+{
70278+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70279+}
70280+
70281+__u32
70282+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70283+{
70284+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70285+}
70286+
70287+__u32
70288+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70289+{
70290+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70291+}
70292+
70293+__u32
70294+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70295+{
70296+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70297+ GR_UNIXCONNECT_ACL_MSG);
70298+}
70299+
70300+/* hardlinks require at minimum create and link permission,
70301+ any additional privilege required is based on the
70302+ privilege of the file being linked to
70303+*/
70304+__u32
70305+gr_acl_handle_link(const struct dentry * new_dentry,
70306+ const struct dentry * parent_dentry,
70307+ const struct vfsmount * parent_mnt,
70308+ const struct dentry * old_dentry,
70309+ const struct vfsmount * old_mnt, const struct filename *to)
70310+{
70311+ __u32 mode;
70312+ __u32 needmode = GR_CREATE | GR_LINK;
70313+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70314+
70315+ mode =
70316+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70317+ old_mnt);
70318+
70319+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70320+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70321+ return mode;
70322+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70323+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70324+ return 0;
70325+ } else if (unlikely((mode & needmode) != needmode))
70326+ return 0;
70327+
70328+ return 1;
70329+}
70330+
70331+__u32
70332+gr_acl_handle_symlink(const struct dentry * new_dentry,
70333+ const struct dentry * parent_dentry,
70334+ const struct vfsmount * parent_mnt, const struct filename *from)
70335+{
70336+ __u32 needmode = GR_WRITE | GR_CREATE;
70337+ __u32 mode;
70338+
70339+ mode =
70340+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70341+ GR_CREATE | GR_AUDIT_CREATE |
70342+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70343+
70344+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70345+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70346+ return mode;
70347+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70348+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70349+ return 0;
70350+ } else if (unlikely((mode & needmode) != needmode))
70351+ return 0;
70352+
70353+ return (GR_WRITE | GR_CREATE);
70354+}
70355+
70356+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)
70357+{
70358+ __u32 mode;
70359+
70360+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70361+
70362+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70363+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70364+ return mode;
70365+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70366+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70367+ return 0;
70368+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70369+ return 0;
70370+
70371+ return (reqmode);
70372+}
70373+
70374+__u32
70375+gr_acl_handle_mknod(const struct dentry * new_dentry,
70376+ const struct dentry * parent_dentry,
70377+ const struct vfsmount * parent_mnt,
70378+ const int mode)
70379+{
70380+ __u32 reqmode = GR_WRITE | GR_CREATE;
70381+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70382+ reqmode |= GR_SETID;
70383+
70384+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70385+ reqmode, GR_MKNOD_ACL_MSG);
70386+}
70387+
70388+__u32
70389+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70390+ const struct dentry *parent_dentry,
70391+ const struct vfsmount *parent_mnt)
70392+{
70393+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70394+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70395+}
70396+
70397+#define RENAME_CHECK_SUCCESS(old, new) \
70398+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70399+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70400+
70401+int
70402+gr_acl_handle_rename(struct dentry *new_dentry,
70403+ struct dentry *parent_dentry,
70404+ const struct vfsmount *parent_mnt,
70405+ struct dentry *old_dentry,
70406+ struct inode *old_parent_inode,
70407+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
70408+{
70409+ __u32 comp1, comp2;
70410+ int error = 0;
70411+
70412+ if (unlikely(!gr_acl_is_enabled()))
70413+ return 0;
70414+
70415+ if (flags & RENAME_EXCHANGE) {
70416+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70417+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70418+ GR_SUPPRESS, parent_mnt);
70419+ comp2 =
70420+ gr_search_file(old_dentry,
70421+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70422+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70423+ } else if (d_is_negative(new_dentry)) {
70424+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70425+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70426+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70427+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70428+ GR_DELETE | GR_AUDIT_DELETE |
70429+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70430+ GR_SUPPRESS, old_mnt);
70431+ } else {
70432+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70433+ GR_CREATE | GR_DELETE |
70434+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70435+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70436+ GR_SUPPRESS, parent_mnt);
70437+ comp2 =
70438+ gr_search_file(old_dentry,
70439+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70440+ GR_DELETE | GR_AUDIT_DELETE |
70441+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70442+ }
70443+
70444+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70445+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70446+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70447+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70448+ && !(comp2 & GR_SUPPRESS)) {
70449+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70450+ error = -EACCES;
70451+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70452+ error = -EACCES;
70453+
70454+ return error;
70455+}
70456+
70457+void
70458+gr_acl_handle_exit(void)
70459+{
70460+ u16 id;
70461+ char *rolename;
70462+
70463+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70464+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70465+ id = current->acl_role_id;
70466+ rolename = current->role->rolename;
70467+ gr_set_acls(1);
70468+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70469+ }
70470+
70471+ gr_put_exec_file(current);
70472+ return;
70473+}
70474+
70475+int
70476+gr_acl_handle_procpidmem(const struct task_struct *task)
70477+{
70478+ if (unlikely(!gr_acl_is_enabled()))
70479+ return 0;
70480+
70481+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70482+ return -EACCES;
70483+
70484+ return 0;
70485+}
70486diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70487new file mode 100644
70488index 0000000..f056b81
70489--- /dev/null
70490+++ b/grsecurity/gracl_ip.c
70491@@ -0,0 +1,386 @@
70492+#include <linux/kernel.h>
70493+#include <asm/uaccess.h>
70494+#include <asm/errno.h>
70495+#include <net/sock.h>
70496+#include <linux/file.h>
70497+#include <linux/fs.h>
70498+#include <linux/net.h>
70499+#include <linux/in.h>
70500+#include <linux/skbuff.h>
70501+#include <linux/ip.h>
70502+#include <linux/udp.h>
70503+#include <linux/types.h>
70504+#include <linux/sched.h>
70505+#include <linux/netdevice.h>
70506+#include <linux/inetdevice.h>
70507+#include <linux/gracl.h>
70508+#include <linux/grsecurity.h>
70509+#include <linux/grinternal.h>
70510+
70511+#define GR_BIND 0x01
70512+#define GR_CONNECT 0x02
70513+#define GR_INVERT 0x04
70514+#define GR_BINDOVERRIDE 0x08
70515+#define GR_CONNECTOVERRIDE 0x10
70516+#define GR_SOCK_FAMILY 0x20
70517+
70518+static const char * gr_protocols[IPPROTO_MAX] = {
70519+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70520+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70521+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70522+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70523+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70524+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70525+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70526+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70527+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70528+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70529+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70530+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70531+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70532+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70533+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70534+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70535+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70536+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70537+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70538+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70539+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70540+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70541+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70542+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70543+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70544+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70545+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70546+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70547+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70548+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70549+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70550+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70551+ };
70552+
70553+static const char * gr_socktypes[SOCK_MAX] = {
70554+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70555+ "unknown:7", "unknown:8", "unknown:9", "packet"
70556+ };
70557+
70558+static const char * gr_sockfamilies[AF_MAX+1] = {
70559+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70560+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70561+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70562+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70563+ };
70564+
70565+const char *
70566+gr_proto_to_name(unsigned char proto)
70567+{
70568+ return gr_protocols[proto];
70569+}
70570+
70571+const char *
70572+gr_socktype_to_name(unsigned char type)
70573+{
70574+ return gr_socktypes[type];
70575+}
70576+
70577+const char *
70578+gr_sockfamily_to_name(unsigned char family)
70579+{
70580+ return gr_sockfamilies[family];
70581+}
70582+
70583+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70584+
70585+int
70586+gr_search_socket(const int domain, const int type, const int protocol)
70587+{
70588+ struct acl_subject_label *curr;
70589+ const struct cred *cred = current_cred();
70590+
70591+ if (unlikely(!gr_acl_is_enabled()))
70592+ goto exit;
70593+
70594+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70595+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70596+ goto exit; // let the kernel handle it
70597+
70598+ curr = current->acl;
70599+
70600+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70601+ /* the family is allowed, if this is PF_INET allow it only if
70602+ the extra sock type/protocol checks pass */
70603+ if (domain == PF_INET)
70604+ goto inet_check;
70605+ goto exit;
70606+ } else {
70607+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70608+ __u32 fakeip = 0;
70609+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70610+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70611+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70612+ gr_to_filename(current->exec_file->f_path.dentry,
70613+ current->exec_file->f_path.mnt) :
70614+ curr->filename, curr->filename,
70615+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70616+ &current->signal->saved_ip);
70617+ goto exit;
70618+ }
70619+ goto exit_fail;
70620+ }
70621+
70622+inet_check:
70623+ /* the rest of this checking is for IPv4 only */
70624+ if (!curr->ips)
70625+ goto exit;
70626+
70627+ if ((curr->ip_type & (1U << type)) &&
70628+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70629+ goto exit;
70630+
70631+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70632+ /* we don't place acls on raw sockets , and sometimes
70633+ dgram/ip sockets are opened for ioctl and not
70634+ bind/connect, so we'll fake a bind learn log */
70635+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70636+ __u32 fakeip = 0;
70637+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70638+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70639+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70640+ gr_to_filename(current->exec_file->f_path.dentry,
70641+ current->exec_file->f_path.mnt) :
70642+ curr->filename, curr->filename,
70643+ &fakeip, 0, type,
70644+ protocol, GR_CONNECT, &current->signal->saved_ip);
70645+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70646+ __u32 fakeip = 0;
70647+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70648+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70649+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70650+ gr_to_filename(current->exec_file->f_path.dentry,
70651+ current->exec_file->f_path.mnt) :
70652+ curr->filename, curr->filename,
70653+ &fakeip, 0, type,
70654+ protocol, GR_BIND, &current->signal->saved_ip);
70655+ }
70656+ /* we'll log when they use connect or bind */
70657+ goto exit;
70658+ }
70659+
70660+exit_fail:
70661+ if (domain == PF_INET)
70662+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70663+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70664+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70665+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70666+ gr_socktype_to_name(type), protocol);
70667+
70668+ return 0;
70669+exit:
70670+ return 1;
70671+}
70672+
70673+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)
70674+{
70675+ if ((ip->mode & mode) &&
70676+ (ip_port >= ip->low) &&
70677+ (ip_port <= ip->high) &&
70678+ ((ntohl(ip_addr) & our_netmask) ==
70679+ (ntohl(our_addr) & our_netmask))
70680+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70681+ && (ip->type & (1U << type))) {
70682+ if (ip->mode & GR_INVERT)
70683+ return 2; // specifically denied
70684+ else
70685+ return 1; // allowed
70686+ }
70687+
70688+ return 0; // not specifically allowed, may continue parsing
70689+}
70690+
70691+static int
70692+gr_search_connectbind(const int full_mode, struct sock *sk,
70693+ struct sockaddr_in *addr, const int type)
70694+{
70695+ char iface[IFNAMSIZ] = {0};
70696+ struct acl_subject_label *curr;
70697+ struct acl_ip_label *ip;
70698+ struct inet_sock *isk;
70699+ struct net_device *dev;
70700+ struct in_device *idev;
70701+ unsigned long i;
70702+ int ret;
70703+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70704+ __u32 ip_addr = 0;
70705+ __u32 our_addr;
70706+ __u32 our_netmask;
70707+ char *p;
70708+ __u16 ip_port = 0;
70709+ const struct cred *cred = current_cred();
70710+
70711+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70712+ return 0;
70713+
70714+ curr = current->acl;
70715+ isk = inet_sk(sk);
70716+
70717+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70718+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70719+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70720+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70721+ struct sockaddr_in saddr;
70722+ int err;
70723+
70724+ saddr.sin_family = AF_INET;
70725+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70726+ saddr.sin_port = isk->inet_sport;
70727+
70728+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70729+ if (err)
70730+ return err;
70731+
70732+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70733+ if (err)
70734+ return err;
70735+ }
70736+
70737+ if (!curr->ips)
70738+ return 0;
70739+
70740+ ip_addr = addr->sin_addr.s_addr;
70741+ ip_port = ntohs(addr->sin_port);
70742+
70743+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70744+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70745+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70746+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70747+ gr_to_filename(current->exec_file->f_path.dentry,
70748+ current->exec_file->f_path.mnt) :
70749+ curr->filename, curr->filename,
70750+ &ip_addr, ip_port, type,
70751+ sk->sk_protocol, mode, &current->signal->saved_ip);
70752+ return 0;
70753+ }
70754+
70755+ for (i = 0; i < curr->ip_num; i++) {
70756+ ip = *(curr->ips + i);
70757+ if (ip->iface != NULL) {
70758+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
70759+ p = strchr(iface, ':');
70760+ if (p != NULL)
70761+ *p = '\0';
70762+ dev = dev_get_by_name(sock_net(sk), iface);
70763+ if (dev == NULL)
70764+ continue;
70765+ idev = in_dev_get(dev);
70766+ if (idev == NULL) {
70767+ dev_put(dev);
70768+ continue;
70769+ }
70770+ rcu_read_lock();
70771+ for_ifa(idev) {
70772+ if (!strcmp(ip->iface, ifa->ifa_label)) {
70773+ our_addr = ifa->ifa_address;
70774+ our_netmask = 0xffffffff;
70775+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70776+ if (ret == 1) {
70777+ rcu_read_unlock();
70778+ in_dev_put(idev);
70779+ dev_put(dev);
70780+ return 0;
70781+ } else if (ret == 2) {
70782+ rcu_read_unlock();
70783+ in_dev_put(idev);
70784+ dev_put(dev);
70785+ goto denied;
70786+ }
70787+ }
70788+ } endfor_ifa(idev);
70789+ rcu_read_unlock();
70790+ in_dev_put(idev);
70791+ dev_put(dev);
70792+ } else {
70793+ our_addr = ip->addr;
70794+ our_netmask = ip->netmask;
70795+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70796+ if (ret == 1)
70797+ return 0;
70798+ else if (ret == 2)
70799+ goto denied;
70800+ }
70801+ }
70802+
70803+denied:
70804+ if (mode == GR_BIND)
70805+ 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));
70806+ else if (mode == GR_CONNECT)
70807+ 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));
70808+
70809+ return -EACCES;
70810+}
70811+
70812+int
70813+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70814+{
70815+ /* always allow disconnection of dgram sockets with connect */
70816+ if (addr->sin_family == AF_UNSPEC)
70817+ return 0;
70818+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70819+}
70820+
70821+int
70822+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70823+{
70824+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70825+}
70826+
70827+int gr_search_listen(struct socket *sock)
70828+{
70829+ struct sock *sk = sock->sk;
70830+ struct sockaddr_in addr;
70831+
70832+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70833+ addr.sin_port = inet_sk(sk)->inet_sport;
70834+
70835+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70836+}
70837+
70838+int gr_search_accept(struct socket *sock)
70839+{
70840+ struct sock *sk = sock->sk;
70841+ struct sockaddr_in addr;
70842+
70843+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70844+ addr.sin_port = inet_sk(sk)->inet_sport;
70845+
70846+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70847+}
70848+
70849+int
70850+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70851+{
70852+ if (addr)
70853+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70854+ else {
70855+ struct sockaddr_in sin;
70856+ const struct inet_sock *inet = inet_sk(sk);
70857+
70858+ sin.sin_addr.s_addr = inet->inet_daddr;
70859+ sin.sin_port = inet->inet_dport;
70860+
70861+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70862+ }
70863+}
70864+
70865+int
70866+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70867+{
70868+ struct sockaddr_in sin;
70869+
70870+ if (unlikely(skb->len < sizeof (struct udphdr)))
70871+ return 0; // skip this packet
70872+
70873+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70874+ sin.sin_port = udp_hdr(skb)->source;
70875+
70876+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70877+}
70878diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70879new file mode 100644
70880index 0000000..25f54ef
70881--- /dev/null
70882+++ b/grsecurity/gracl_learn.c
70883@@ -0,0 +1,207 @@
70884+#include <linux/kernel.h>
70885+#include <linux/mm.h>
70886+#include <linux/sched.h>
70887+#include <linux/poll.h>
70888+#include <linux/string.h>
70889+#include <linux/file.h>
70890+#include <linux/types.h>
70891+#include <linux/vmalloc.h>
70892+#include <linux/grinternal.h>
70893+
70894+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70895+ size_t count, loff_t *ppos);
70896+extern int gr_acl_is_enabled(void);
70897+
70898+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70899+static int gr_learn_attached;
70900+
70901+/* use a 512k buffer */
70902+#define LEARN_BUFFER_SIZE (512 * 1024)
70903+
70904+static DEFINE_SPINLOCK(gr_learn_lock);
70905+static DEFINE_MUTEX(gr_learn_user_mutex);
70906+
70907+/* we need to maintain two buffers, so that the kernel context of grlearn
70908+ uses a semaphore around the userspace copying, and the other kernel contexts
70909+ use a spinlock when copying into the buffer, since they cannot sleep
70910+*/
70911+static char *learn_buffer;
70912+static char *learn_buffer_user;
70913+static int learn_buffer_len;
70914+static int learn_buffer_user_len;
70915+
70916+static ssize_t
70917+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70918+{
70919+ DECLARE_WAITQUEUE(wait, current);
70920+ ssize_t retval = 0;
70921+
70922+ add_wait_queue(&learn_wait, &wait);
70923+ set_current_state(TASK_INTERRUPTIBLE);
70924+ do {
70925+ mutex_lock(&gr_learn_user_mutex);
70926+ spin_lock(&gr_learn_lock);
70927+ if (learn_buffer_len)
70928+ break;
70929+ spin_unlock(&gr_learn_lock);
70930+ mutex_unlock(&gr_learn_user_mutex);
70931+ if (file->f_flags & O_NONBLOCK) {
70932+ retval = -EAGAIN;
70933+ goto out;
70934+ }
70935+ if (signal_pending(current)) {
70936+ retval = -ERESTARTSYS;
70937+ goto out;
70938+ }
70939+
70940+ schedule();
70941+ } while (1);
70942+
70943+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70944+ learn_buffer_user_len = learn_buffer_len;
70945+ retval = learn_buffer_len;
70946+ learn_buffer_len = 0;
70947+
70948+ spin_unlock(&gr_learn_lock);
70949+
70950+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70951+ retval = -EFAULT;
70952+
70953+ mutex_unlock(&gr_learn_user_mutex);
70954+out:
70955+ set_current_state(TASK_RUNNING);
70956+ remove_wait_queue(&learn_wait, &wait);
70957+ return retval;
70958+}
70959+
70960+static unsigned int
70961+poll_learn(struct file * file, poll_table * wait)
70962+{
70963+ poll_wait(file, &learn_wait, wait);
70964+
70965+ if (learn_buffer_len)
70966+ return (POLLIN | POLLRDNORM);
70967+
70968+ return 0;
70969+}
70970+
70971+void
70972+gr_clear_learn_entries(void)
70973+{
70974+ char *tmp;
70975+
70976+ mutex_lock(&gr_learn_user_mutex);
70977+ spin_lock(&gr_learn_lock);
70978+ tmp = learn_buffer;
70979+ learn_buffer = NULL;
70980+ spin_unlock(&gr_learn_lock);
70981+ if (tmp)
70982+ vfree(tmp);
70983+ if (learn_buffer_user != NULL) {
70984+ vfree(learn_buffer_user);
70985+ learn_buffer_user = NULL;
70986+ }
70987+ learn_buffer_len = 0;
70988+ mutex_unlock(&gr_learn_user_mutex);
70989+
70990+ return;
70991+}
70992+
70993+void
70994+gr_add_learn_entry(const char *fmt, ...)
70995+{
70996+ va_list args;
70997+ unsigned int len;
70998+
70999+ if (!gr_learn_attached)
71000+ return;
71001+
71002+ spin_lock(&gr_learn_lock);
71003+
71004+ /* leave a gap at the end so we know when it's "full" but don't have to
71005+ compute the exact length of the string we're trying to append
71006+ */
71007+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71008+ spin_unlock(&gr_learn_lock);
71009+ wake_up_interruptible(&learn_wait);
71010+ return;
71011+ }
71012+ if (learn_buffer == NULL) {
71013+ spin_unlock(&gr_learn_lock);
71014+ return;
71015+ }
71016+
71017+ va_start(args, fmt);
71018+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71019+ va_end(args);
71020+
71021+ learn_buffer_len += len + 1;
71022+
71023+ spin_unlock(&gr_learn_lock);
71024+ wake_up_interruptible(&learn_wait);
71025+
71026+ return;
71027+}
71028+
71029+static int
71030+open_learn(struct inode *inode, struct file *file)
71031+{
71032+ if (file->f_mode & FMODE_READ && gr_learn_attached)
71033+ return -EBUSY;
71034+ if (file->f_mode & FMODE_READ) {
71035+ int retval = 0;
71036+ mutex_lock(&gr_learn_user_mutex);
71037+ if (learn_buffer == NULL)
71038+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71039+ if (learn_buffer_user == NULL)
71040+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71041+ if (learn_buffer == NULL) {
71042+ retval = -ENOMEM;
71043+ goto out_error;
71044+ }
71045+ if (learn_buffer_user == NULL) {
71046+ retval = -ENOMEM;
71047+ goto out_error;
71048+ }
71049+ learn_buffer_len = 0;
71050+ learn_buffer_user_len = 0;
71051+ gr_learn_attached = 1;
71052+out_error:
71053+ mutex_unlock(&gr_learn_user_mutex);
71054+ return retval;
71055+ }
71056+ return 0;
71057+}
71058+
71059+static int
71060+close_learn(struct inode *inode, struct file *file)
71061+{
71062+ if (file->f_mode & FMODE_READ) {
71063+ char *tmp = NULL;
71064+ mutex_lock(&gr_learn_user_mutex);
71065+ spin_lock(&gr_learn_lock);
71066+ tmp = learn_buffer;
71067+ learn_buffer = NULL;
71068+ spin_unlock(&gr_learn_lock);
71069+ if (tmp)
71070+ vfree(tmp);
71071+ if (learn_buffer_user != NULL) {
71072+ vfree(learn_buffer_user);
71073+ learn_buffer_user = NULL;
71074+ }
71075+ learn_buffer_len = 0;
71076+ learn_buffer_user_len = 0;
71077+ gr_learn_attached = 0;
71078+ mutex_unlock(&gr_learn_user_mutex);
71079+ }
71080+
71081+ return 0;
71082+}
71083+
71084+const struct file_operations grsec_fops = {
71085+ .read = read_learn,
71086+ .write = write_grsec_handler,
71087+ .open = open_learn,
71088+ .release = close_learn,
71089+ .poll = poll_learn,
71090+};
71091diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71092new file mode 100644
71093index 0000000..361a099
71094--- /dev/null
71095+++ b/grsecurity/gracl_policy.c
71096@@ -0,0 +1,1782 @@
71097+#include <linux/kernel.h>
71098+#include <linux/module.h>
71099+#include <linux/sched.h>
71100+#include <linux/mm.h>
71101+#include <linux/file.h>
71102+#include <linux/fs.h>
71103+#include <linux/namei.h>
71104+#include <linux/mount.h>
71105+#include <linux/tty.h>
71106+#include <linux/proc_fs.h>
71107+#include <linux/lglock.h>
71108+#include <linux/slab.h>
71109+#include <linux/vmalloc.h>
71110+#include <linux/types.h>
71111+#include <linux/sysctl.h>
71112+#include <linux/netdevice.h>
71113+#include <linux/ptrace.h>
71114+#include <linux/gracl.h>
71115+#include <linux/gralloc.h>
71116+#include <linux/security.h>
71117+#include <linux/grinternal.h>
71118+#include <linux/pid_namespace.h>
71119+#include <linux/stop_machine.h>
71120+#include <linux/fdtable.h>
71121+#include <linux/percpu.h>
71122+#include <linux/lglock.h>
71123+#include <linux/hugetlb.h>
71124+#include <linux/posix-timers.h>
71125+#include "../fs/mount.h"
71126+
71127+#include <asm/uaccess.h>
71128+#include <asm/errno.h>
71129+#include <asm/mman.h>
71130+
71131+extern struct gr_policy_state *polstate;
71132+
71133+#define FOR_EACH_ROLE_START(role) \
71134+ role = polstate->role_list; \
71135+ while (role) {
71136+
71137+#define FOR_EACH_ROLE_END(role) \
71138+ role = role->prev; \
71139+ }
71140+
71141+struct path gr_real_root;
71142+
71143+extern struct gr_alloc_state *current_alloc_state;
71144+
71145+u16 acl_sp_role_value;
71146+
71147+static DEFINE_MUTEX(gr_dev_mutex);
71148+
71149+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71150+extern void gr_clear_learn_entries(void);
71151+
71152+static struct gr_arg gr_usermode;
71153+static unsigned char gr_system_salt[GR_SALT_LEN];
71154+static unsigned char gr_system_sum[GR_SHA_LEN];
71155+
71156+static unsigned int gr_auth_attempts = 0;
71157+static unsigned long gr_auth_expires = 0UL;
71158+
71159+struct acl_object_label *fakefs_obj_rw;
71160+struct acl_object_label *fakefs_obj_rwx;
71161+
71162+extern int gr_init_uidset(void);
71163+extern void gr_free_uidset(void);
71164+extern void gr_remove_uid(uid_t uid);
71165+extern int gr_find_uid(uid_t uid);
71166+
71167+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71168+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71169+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71170+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71171+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);
71172+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71173+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71174+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71175+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71176+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71177+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71178+extern void assign_special_role(const char *rolename);
71179+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71180+extern int gr_rbac_disable(void *unused);
71181+extern void gr_enable_rbac_system(void);
71182+
71183+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71184+{
71185+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71186+ return -EFAULT;
71187+
71188+ return 0;
71189+}
71190+
71191+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71192+{
71193+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71194+ return -EFAULT;
71195+
71196+ return 0;
71197+}
71198+
71199+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71200+{
71201+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71202+ return -EFAULT;
71203+
71204+ return 0;
71205+}
71206+
71207+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71208+{
71209+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71210+ return -EFAULT;
71211+
71212+ return 0;
71213+}
71214+
71215+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71216+{
71217+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71218+ return -EFAULT;
71219+
71220+ return 0;
71221+}
71222+
71223+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71224+{
71225+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71226+ return -EFAULT;
71227+
71228+ return 0;
71229+}
71230+
71231+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71232+{
71233+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71234+ return -EFAULT;
71235+
71236+ return 0;
71237+}
71238+
71239+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71240+{
71241+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71242+ return -EFAULT;
71243+
71244+ return 0;
71245+}
71246+
71247+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71248+{
71249+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71250+ return -EFAULT;
71251+
71252+ return 0;
71253+}
71254+
71255+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71256+{
71257+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71258+ return -EFAULT;
71259+
71260+ if (((uwrap->version != GRSECURITY_VERSION) &&
71261+ (uwrap->version != 0x2901)) ||
71262+ (uwrap->size != sizeof(struct gr_arg)))
71263+ return -EINVAL;
71264+
71265+ return 0;
71266+}
71267+
71268+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71269+{
71270+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71271+ return -EFAULT;
71272+
71273+ return 0;
71274+}
71275+
71276+static size_t get_gr_arg_wrapper_size_normal(void)
71277+{
71278+ return sizeof(struct gr_arg_wrapper);
71279+}
71280+
71281+#ifdef CONFIG_COMPAT
71282+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71283+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71284+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71285+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71286+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71287+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71288+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71289+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71290+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71291+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71292+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71293+extern size_t get_gr_arg_wrapper_size_compat(void);
71294+
71295+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71296+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71297+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71298+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71299+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71300+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71301+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71302+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71303+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71304+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71305+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71306+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71307+
71308+#else
71309+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71310+#define copy_gr_arg copy_gr_arg_normal
71311+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71312+#define copy_acl_object_label copy_acl_object_label_normal
71313+#define copy_acl_subject_label copy_acl_subject_label_normal
71314+#define copy_acl_role_label copy_acl_role_label_normal
71315+#define copy_acl_ip_label copy_acl_ip_label_normal
71316+#define copy_pointer_from_array copy_pointer_from_array_normal
71317+#define copy_sprole_pw copy_sprole_pw_normal
71318+#define copy_role_transition copy_role_transition_normal
71319+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71320+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71321+#endif
71322+
71323+static struct acl_subject_label *
71324+lookup_subject_map(const struct acl_subject_label *userp)
71325+{
71326+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71327+ struct subject_map *match;
71328+
71329+ match = polstate->subj_map_set.s_hash[index];
71330+
71331+ while (match && match->user != userp)
71332+ match = match->next;
71333+
71334+ if (match != NULL)
71335+ return match->kernel;
71336+ else
71337+ return NULL;
71338+}
71339+
71340+static void
71341+insert_subj_map_entry(struct subject_map *subjmap)
71342+{
71343+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71344+ struct subject_map **curr;
71345+
71346+ subjmap->prev = NULL;
71347+
71348+ curr = &polstate->subj_map_set.s_hash[index];
71349+ if (*curr != NULL)
71350+ (*curr)->prev = subjmap;
71351+
71352+ subjmap->next = *curr;
71353+ *curr = subjmap;
71354+
71355+ return;
71356+}
71357+
71358+static void
71359+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71360+{
71361+ unsigned int index =
71362+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71363+ struct acl_role_label **curr;
71364+ struct acl_role_label *tmp, *tmp2;
71365+
71366+ curr = &polstate->acl_role_set.r_hash[index];
71367+
71368+ /* simple case, slot is empty, just set it to our role */
71369+ if (*curr == NULL) {
71370+ *curr = role;
71371+ } else {
71372+ /* example:
71373+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71374+ 2 -> 3
71375+ */
71376+ /* first check to see if we can already be reached via this slot */
71377+ tmp = *curr;
71378+ while (tmp && tmp != role)
71379+ tmp = tmp->next;
71380+ if (tmp == role) {
71381+ /* we don't need to add ourselves to this slot's chain */
71382+ return;
71383+ }
71384+ /* we need to add ourselves to this chain, two cases */
71385+ if (role->next == NULL) {
71386+ /* simple case, append the current chain to our role */
71387+ role->next = *curr;
71388+ *curr = role;
71389+ } else {
71390+ /* 1 -> 2 -> 3 -> 4
71391+ 2 -> 3 -> 4
71392+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71393+ */
71394+ /* trickier case: walk our role's chain until we find
71395+ the role for the start of the current slot's chain */
71396+ tmp = role;
71397+ tmp2 = *curr;
71398+ while (tmp->next && tmp->next != tmp2)
71399+ tmp = tmp->next;
71400+ if (tmp->next == tmp2) {
71401+ /* from example above, we found 3, so just
71402+ replace this slot's chain with ours */
71403+ *curr = role;
71404+ } else {
71405+ /* we didn't find a subset of our role's chain
71406+ in the current slot's chain, so append their
71407+ chain to ours, and set us as the first role in
71408+ the slot's chain
71409+
71410+ we could fold this case with the case above,
71411+ but making it explicit for clarity
71412+ */
71413+ tmp->next = tmp2;
71414+ *curr = role;
71415+ }
71416+ }
71417+ }
71418+
71419+ return;
71420+}
71421+
71422+static void
71423+insert_acl_role_label(struct acl_role_label *role)
71424+{
71425+ int i;
71426+
71427+ if (polstate->role_list == NULL) {
71428+ polstate->role_list = role;
71429+ role->prev = NULL;
71430+ } else {
71431+ role->prev = polstate->role_list;
71432+ polstate->role_list = role;
71433+ }
71434+
71435+ /* used for hash chains */
71436+ role->next = NULL;
71437+
71438+ if (role->roletype & GR_ROLE_DOMAIN) {
71439+ for (i = 0; i < role->domain_child_num; i++)
71440+ __insert_acl_role_label(role, role->domain_children[i]);
71441+ } else
71442+ __insert_acl_role_label(role, role->uidgid);
71443+}
71444+
71445+static int
71446+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71447+{
71448+ struct name_entry **curr, *nentry;
71449+ struct inodev_entry *ientry;
71450+ unsigned int len = strlen(name);
71451+ unsigned int key = full_name_hash(name, len);
71452+ unsigned int index = key % polstate->name_set.n_size;
71453+
71454+ curr = &polstate->name_set.n_hash[index];
71455+
71456+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71457+ curr = &((*curr)->next);
71458+
71459+ if (*curr != NULL)
71460+ return 1;
71461+
71462+ nentry = acl_alloc(sizeof (struct name_entry));
71463+ if (nentry == NULL)
71464+ return 0;
71465+ ientry = acl_alloc(sizeof (struct inodev_entry));
71466+ if (ientry == NULL)
71467+ return 0;
71468+ ientry->nentry = nentry;
71469+
71470+ nentry->key = key;
71471+ nentry->name = name;
71472+ nentry->inode = inode;
71473+ nentry->device = device;
71474+ nentry->len = len;
71475+ nentry->deleted = deleted;
71476+
71477+ nentry->prev = NULL;
71478+ curr = &polstate->name_set.n_hash[index];
71479+ if (*curr != NULL)
71480+ (*curr)->prev = nentry;
71481+ nentry->next = *curr;
71482+ *curr = nentry;
71483+
71484+ /* insert us into the table searchable by inode/dev */
71485+ __insert_inodev_entry(polstate, ientry);
71486+
71487+ return 1;
71488+}
71489+
71490+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71491+
71492+static void *
71493+create_table(__u32 * len, int elementsize)
71494+{
71495+ unsigned int table_sizes[] = {
71496+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71497+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71498+ 4194301, 8388593, 16777213, 33554393, 67108859
71499+ };
71500+ void *newtable = NULL;
71501+ unsigned int pwr = 0;
71502+
71503+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71504+ table_sizes[pwr] <= *len)
71505+ pwr++;
71506+
71507+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71508+ return newtable;
71509+
71510+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71511+ newtable =
71512+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71513+ else
71514+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71515+
71516+ *len = table_sizes[pwr];
71517+
71518+ return newtable;
71519+}
71520+
71521+static int
71522+init_variables(const struct gr_arg *arg, bool reload)
71523+{
71524+ struct task_struct *reaper = init_pid_ns.child_reaper;
71525+ unsigned int stacksize;
71526+
71527+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71528+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71529+ polstate->name_set.n_size = arg->role_db.num_objects;
71530+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71531+
71532+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71533+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71534+ return 1;
71535+
71536+ if (!reload) {
71537+ if (!gr_init_uidset())
71538+ return 1;
71539+ }
71540+
71541+ /* set up the stack that holds allocation info */
71542+
71543+ stacksize = arg->role_db.num_pointers + 5;
71544+
71545+ if (!acl_alloc_stack_init(stacksize))
71546+ return 1;
71547+
71548+ if (!reload) {
71549+ /* grab reference for the real root dentry and vfsmount */
71550+ get_fs_root(reaper->fs, &gr_real_root);
71551+
71552+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71553+ 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);
71554+#endif
71555+
71556+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71557+ if (fakefs_obj_rw == NULL)
71558+ return 1;
71559+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71560+
71561+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71562+ if (fakefs_obj_rwx == NULL)
71563+ return 1;
71564+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71565+ }
71566+
71567+ polstate->subj_map_set.s_hash =
71568+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71569+ polstate->acl_role_set.r_hash =
71570+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71571+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71572+ polstate->inodev_set.i_hash =
71573+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71574+
71575+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71576+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71577+ return 1;
71578+
71579+ memset(polstate->subj_map_set.s_hash, 0,
71580+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71581+ memset(polstate->acl_role_set.r_hash, 0,
71582+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71583+ memset(polstate->name_set.n_hash, 0,
71584+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71585+ memset(polstate->inodev_set.i_hash, 0,
71586+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71587+
71588+ return 0;
71589+}
71590+
71591+/* free information not needed after startup
71592+ currently contains user->kernel pointer mappings for subjects
71593+*/
71594+
71595+static void
71596+free_init_variables(void)
71597+{
71598+ __u32 i;
71599+
71600+ if (polstate->subj_map_set.s_hash) {
71601+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71602+ if (polstate->subj_map_set.s_hash[i]) {
71603+ kfree(polstate->subj_map_set.s_hash[i]);
71604+ polstate->subj_map_set.s_hash[i] = NULL;
71605+ }
71606+ }
71607+
71608+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71609+ PAGE_SIZE)
71610+ kfree(polstate->subj_map_set.s_hash);
71611+ else
71612+ vfree(polstate->subj_map_set.s_hash);
71613+ }
71614+
71615+ return;
71616+}
71617+
71618+static void
71619+free_variables(bool reload)
71620+{
71621+ struct acl_subject_label *s;
71622+ struct acl_role_label *r;
71623+ struct task_struct *task, *task2;
71624+ unsigned int x;
71625+
71626+ if (!reload) {
71627+ gr_clear_learn_entries();
71628+
71629+ read_lock(&tasklist_lock);
71630+ do_each_thread(task2, task) {
71631+ task->acl_sp_role = 0;
71632+ task->acl_role_id = 0;
71633+ task->inherited = 0;
71634+ task->acl = NULL;
71635+ task->role = NULL;
71636+ } while_each_thread(task2, task);
71637+ read_unlock(&tasklist_lock);
71638+
71639+ kfree(fakefs_obj_rw);
71640+ fakefs_obj_rw = NULL;
71641+ kfree(fakefs_obj_rwx);
71642+ fakefs_obj_rwx = NULL;
71643+
71644+ /* release the reference to the real root dentry and vfsmount */
71645+ path_put(&gr_real_root);
71646+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71647+ }
71648+
71649+ /* free all object hash tables */
71650+
71651+ FOR_EACH_ROLE_START(r)
71652+ if (r->subj_hash == NULL)
71653+ goto next_role;
71654+ FOR_EACH_SUBJECT_START(r, s, x)
71655+ if (s->obj_hash == NULL)
71656+ break;
71657+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71658+ kfree(s->obj_hash);
71659+ else
71660+ vfree(s->obj_hash);
71661+ FOR_EACH_SUBJECT_END(s, x)
71662+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71663+ if (s->obj_hash == NULL)
71664+ break;
71665+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71666+ kfree(s->obj_hash);
71667+ else
71668+ vfree(s->obj_hash);
71669+ FOR_EACH_NESTED_SUBJECT_END(s)
71670+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71671+ kfree(r->subj_hash);
71672+ else
71673+ vfree(r->subj_hash);
71674+ r->subj_hash = NULL;
71675+next_role:
71676+ FOR_EACH_ROLE_END(r)
71677+
71678+ acl_free_all();
71679+
71680+ if (polstate->acl_role_set.r_hash) {
71681+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71682+ PAGE_SIZE)
71683+ kfree(polstate->acl_role_set.r_hash);
71684+ else
71685+ vfree(polstate->acl_role_set.r_hash);
71686+ }
71687+ if (polstate->name_set.n_hash) {
71688+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71689+ PAGE_SIZE)
71690+ kfree(polstate->name_set.n_hash);
71691+ else
71692+ vfree(polstate->name_set.n_hash);
71693+ }
71694+
71695+ if (polstate->inodev_set.i_hash) {
71696+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71697+ PAGE_SIZE)
71698+ kfree(polstate->inodev_set.i_hash);
71699+ else
71700+ vfree(polstate->inodev_set.i_hash);
71701+ }
71702+
71703+ if (!reload)
71704+ gr_free_uidset();
71705+
71706+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71707+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71708+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71709+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71710+
71711+ polstate->default_role = NULL;
71712+ polstate->kernel_role = NULL;
71713+ polstate->role_list = NULL;
71714+
71715+ return;
71716+}
71717+
71718+static struct acl_subject_label *
71719+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71720+
71721+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71722+{
71723+ unsigned int len = strnlen_user(*name, maxlen);
71724+ char *tmp;
71725+
71726+ if (!len || len >= maxlen)
71727+ return -EINVAL;
71728+
71729+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71730+ return -ENOMEM;
71731+
71732+ if (copy_from_user(tmp, *name, len))
71733+ return -EFAULT;
71734+
71735+ tmp[len-1] = '\0';
71736+ *name = tmp;
71737+
71738+ return 0;
71739+}
71740+
71741+static int
71742+copy_user_glob(struct acl_object_label *obj)
71743+{
71744+ struct acl_object_label *g_tmp, **guser;
71745+ int error;
71746+
71747+ if (obj->globbed == NULL)
71748+ return 0;
71749+
71750+ guser = &obj->globbed;
71751+ while (*guser) {
71752+ g_tmp = (struct acl_object_label *)
71753+ acl_alloc(sizeof (struct acl_object_label));
71754+ if (g_tmp == NULL)
71755+ return -ENOMEM;
71756+
71757+ if (copy_acl_object_label(g_tmp, *guser))
71758+ return -EFAULT;
71759+
71760+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71761+ if (error)
71762+ return error;
71763+
71764+ *guser = g_tmp;
71765+ guser = &(g_tmp->next);
71766+ }
71767+
71768+ return 0;
71769+}
71770+
71771+static int
71772+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71773+ struct acl_role_label *role)
71774+{
71775+ struct acl_object_label *o_tmp;
71776+ int ret;
71777+
71778+ while (userp) {
71779+ if ((o_tmp = (struct acl_object_label *)
71780+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
71781+ return -ENOMEM;
71782+
71783+ if (copy_acl_object_label(o_tmp, userp))
71784+ return -EFAULT;
71785+
71786+ userp = o_tmp->prev;
71787+
71788+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71789+ if (ret)
71790+ return ret;
71791+
71792+ insert_acl_obj_label(o_tmp, subj);
71793+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71794+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71795+ return -ENOMEM;
71796+
71797+ ret = copy_user_glob(o_tmp);
71798+ if (ret)
71799+ return ret;
71800+
71801+ if (o_tmp->nested) {
71802+ int already_copied;
71803+
71804+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71805+ if (IS_ERR(o_tmp->nested))
71806+ return PTR_ERR(o_tmp->nested);
71807+
71808+ /* insert into nested subject list if we haven't copied this one yet
71809+ to prevent duplicate entries */
71810+ if (!already_copied) {
71811+ o_tmp->nested->next = role->hash->first;
71812+ role->hash->first = o_tmp->nested;
71813+ }
71814+ }
71815+ }
71816+
71817+ return 0;
71818+}
71819+
71820+static __u32
71821+count_user_subjs(struct acl_subject_label *userp)
71822+{
71823+ struct acl_subject_label s_tmp;
71824+ __u32 num = 0;
71825+
71826+ while (userp) {
71827+ if (copy_acl_subject_label(&s_tmp, userp))
71828+ break;
71829+
71830+ userp = s_tmp.prev;
71831+ }
71832+
71833+ return num;
71834+}
71835+
71836+static int
71837+copy_user_allowedips(struct acl_role_label *rolep)
71838+{
71839+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71840+
71841+ ruserip = rolep->allowed_ips;
71842+
71843+ while (ruserip) {
71844+ rlast = rtmp;
71845+
71846+ if ((rtmp = (struct role_allowed_ip *)
71847+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71848+ return -ENOMEM;
71849+
71850+ if (copy_role_allowed_ip(rtmp, ruserip))
71851+ return -EFAULT;
71852+
71853+ ruserip = rtmp->prev;
71854+
71855+ if (!rlast) {
71856+ rtmp->prev = NULL;
71857+ rolep->allowed_ips = rtmp;
71858+ } else {
71859+ rlast->next = rtmp;
71860+ rtmp->prev = rlast;
71861+ }
71862+
71863+ if (!ruserip)
71864+ rtmp->next = NULL;
71865+ }
71866+
71867+ return 0;
71868+}
71869+
71870+static int
71871+copy_user_transitions(struct acl_role_label *rolep)
71872+{
71873+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
71874+ int error;
71875+
71876+ rusertp = rolep->transitions;
71877+
71878+ while (rusertp) {
71879+ rlast = rtmp;
71880+
71881+ if ((rtmp = (struct role_transition *)
71882+ acl_alloc(sizeof (struct role_transition))) == NULL)
71883+ return -ENOMEM;
71884+
71885+ if (copy_role_transition(rtmp, rusertp))
71886+ return -EFAULT;
71887+
71888+ rusertp = rtmp->prev;
71889+
71890+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71891+ if (error)
71892+ return error;
71893+
71894+ if (!rlast) {
71895+ rtmp->prev = NULL;
71896+ rolep->transitions = rtmp;
71897+ } else {
71898+ rlast->next = rtmp;
71899+ rtmp->prev = rlast;
71900+ }
71901+
71902+ if (!rusertp)
71903+ rtmp->next = NULL;
71904+ }
71905+
71906+ return 0;
71907+}
71908+
71909+static __u32 count_user_objs(const struct acl_object_label __user *userp)
71910+{
71911+ struct acl_object_label o_tmp;
71912+ __u32 num = 0;
71913+
71914+ while (userp) {
71915+ if (copy_acl_object_label(&o_tmp, userp))
71916+ break;
71917+
71918+ userp = o_tmp.prev;
71919+ num++;
71920+ }
71921+
71922+ return num;
71923+}
71924+
71925+static struct acl_subject_label *
71926+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71927+{
71928+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71929+ __u32 num_objs;
71930+ struct acl_ip_label **i_tmp, *i_utmp2;
71931+ struct gr_hash_struct ghash;
71932+ struct subject_map *subjmap;
71933+ unsigned int i_num;
71934+ int err;
71935+
71936+ if (already_copied != NULL)
71937+ *already_copied = 0;
71938+
71939+ s_tmp = lookup_subject_map(userp);
71940+
71941+ /* we've already copied this subject into the kernel, just return
71942+ the reference to it, and don't copy it over again
71943+ */
71944+ if (s_tmp) {
71945+ if (already_copied != NULL)
71946+ *already_copied = 1;
71947+ return(s_tmp);
71948+ }
71949+
71950+ if ((s_tmp = (struct acl_subject_label *)
71951+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71952+ return ERR_PTR(-ENOMEM);
71953+
71954+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71955+ if (subjmap == NULL)
71956+ return ERR_PTR(-ENOMEM);
71957+
71958+ subjmap->user = userp;
71959+ subjmap->kernel = s_tmp;
71960+ insert_subj_map_entry(subjmap);
71961+
71962+ if (copy_acl_subject_label(s_tmp, userp))
71963+ return ERR_PTR(-EFAULT);
71964+
71965+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71966+ if (err)
71967+ return ERR_PTR(err);
71968+
71969+ if (!strcmp(s_tmp->filename, "/"))
71970+ role->root_label = s_tmp;
71971+
71972+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71973+ return ERR_PTR(-EFAULT);
71974+
71975+ /* copy user and group transition tables */
71976+
71977+ if (s_tmp->user_trans_num) {
71978+ uid_t *uidlist;
71979+
71980+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71981+ if (uidlist == NULL)
71982+ return ERR_PTR(-ENOMEM);
71983+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71984+ return ERR_PTR(-EFAULT);
71985+
71986+ s_tmp->user_transitions = uidlist;
71987+ }
71988+
71989+ if (s_tmp->group_trans_num) {
71990+ gid_t *gidlist;
71991+
71992+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71993+ if (gidlist == NULL)
71994+ return ERR_PTR(-ENOMEM);
71995+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71996+ return ERR_PTR(-EFAULT);
71997+
71998+ s_tmp->group_transitions = gidlist;
71999+ }
72000+
72001+ /* set up object hash table */
72002+ num_objs = count_user_objs(ghash.first);
72003+
72004+ s_tmp->obj_hash_size = num_objs;
72005+ s_tmp->obj_hash =
72006+ (struct acl_object_label **)
72007+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72008+
72009+ if (!s_tmp->obj_hash)
72010+ return ERR_PTR(-ENOMEM);
72011+
72012+ memset(s_tmp->obj_hash, 0,
72013+ s_tmp->obj_hash_size *
72014+ sizeof (struct acl_object_label *));
72015+
72016+ /* add in objects */
72017+ err = copy_user_objs(ghash.first, s_tmp, role);
72018+
72019+ if (err)
72020+ return ERR_PTR(err);
72021+
72022+ /* set pointer for parent subject */
72023+ if (s_tmp->parent_subject) {
72024+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72025+
72026+ if (IS_ERR(s_tmp2))
72027+ return s_tmp2;
72028+
72029+ s_tmp->parent_subject = s_tmp2;
72030+ }
72031+
72032+ /* add in ip acls */
72033+
72034+ if (!s_tmp->ip_num) {
72035+ s_tmp->ips = NULL;
72036+ goto insert;
72037+ }
72038+
72039+ i_tmp =
72040+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72041+ sizeof (struct acl_ip_label *));
72042+
72043+ if (!i_tmp)
72044+ return ERR_PTR(-ENOMEM);
72045+
72046+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72047+ *(i_tmp + i_num) =
72048+ (struct acl_ip_label *)
72049+ acl_alloc(sizeof (struct acl_ip_label));
72050+ if (!*(i_tmp + i_num))
72051+ return ERR_PTR(-ENOMEM);
72052+
72053+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72054+ return ERR_PTR(-EFAULT);
72055+
72056+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72057+ return ERR_PTR(-EFAULT);
72058+
72059+ if ((*(i_tmp + i_num))->iface == NULL)
72060+ continue;
72061+
72062+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72063+ if (err)
72064+ return ERR_PTR(err);
72065+ }
72066+
72067+ s_tmp->ips = i_tmp;
72068+
72069+insert:
72070+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72071+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72072+ return ERR_PTR(-ENOMEM);
72073+
72074+ return s_tmp;
72075+}
72076+
72077+static int
72078+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72079+{
72080+ struct acl_subject_label s_pre;
72081+ struct acl_subject_label * ret;
72082+ int err;
72083+
72084+ while (userp) {
72085+ if (copy_acl_subject_label(&s_pre, userp))
72086+ return -EFAULT;
72087+
72088+ ret = do_copy_user_subj(userp, role, NULL);
72089+
72090+ err = PTR_ERR(ret);
72091+ if (IS_ERR(ret))
72092+ return err;
72093+
72094+ insert_acl_subj_label(ret, role);
72095+
72096+ userp = s_pre.prev;
72097+ }
72098+
72099+ return 0;
72100+}
72101+
72102+static int
72103+copy_user_acl(struct gr_arg *arg)
72104+{
72105+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72106+ struct acl_subject_label *subj_list;
72107+ struct sprole_pw *sptmp;
72108+ struct gr_hash_struct *ghash;
72109+ uid_t *domainlist;
72110+ unsigned int r_num;
72111+ int err = 0;
72112+ __u16 i;
72113+ __u32 num_subjs;
72114+
72115+ /* we need a default and kernel role */
72116+ if (arg->role_db.num_roles < 2)
72117+ return -EINVAL;
72118+
72119+ /* copy special role authentication info from userspace */
72120+
72121+ polstate->num_sprole_pws = arg->num_sprole_pws;
72122+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72123+
72124+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72125+ return -ENOMEM;
72126+
72127+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72128+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72129+ if (!sptmp)
72130+ return -ENOMEM;
72131+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72132+ return -EFAULT;
72133+
72134+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72135+ if (err)
72136+ return err;
72137+
72138+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72139+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72140+#endif
72141+
72142+ polstate->acl_special_roles[i] = sptmp;
72143+ }
72144+
72145+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72146+
72147+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72148+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72149+
72150+ if (!r_tmp)
72151+ return -ENOMEM;
72152+
72153+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72154+ return -EFAULT;
72155+
72156+ if (copy_acl_role_label(r_tmp, r_utmp2))
72157+ return -EFAULT;
72158+
72159+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72160+ if (err)
72161+ return err;
72162+
72163+ if (!strcmp(r_tmp->rolename, "default")
72164+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72165+ polstate->default_role = r_tmp;
72166+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72167+ polstate->kernel_role = r_tmp;
72168+ }
72169+
72170+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72171+ return -ENOMEM;
72172+
72173+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72174+ return -EFAULT;
72175+
72176+ r_tmp->hash = ghash;
72177+
72178+ num_subjs = count_user_subjs(r_tmp->hash->first);
72179+
72180+ r_tmp->subj_hash_size = num_subjs;
72181+ r_tmp->subj_hash =
72182+ (struct acl_subject_label **)
72183+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72184+
72185+ if (!r_tmp->subj_hash)
72186+ return -ENOMEM;
72187+
72188+ err = copy_user_allowedips(r_tmp);
72189+ if (err)
72190+ return err;
72191+
72192+ /* copy domain info */
72193+ if (r_tmp->domain_children != NULL) {
72194+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72195+ if (domainlist == NULL)
72196+ return -ENOMEM;
72197+
72198+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72199+ return -EFAULT;
72200+
72201+ r_tmp->domain_children = domainlist;
72202+ }
72203+
72204+ err = copy_user_transitions(r_tmp);
72205+ if (err)
72206+ return err;
72207+
72208+ memset(r_tmp->subj_hash, 0,
72209+ r_tmp->subj_hash_size *
72210+ sizeof (struct acl_subject_label *));
72211+
72212+ /* acquire the list of subjects, then NULL out
72213+ the list prior to parsing the subjects for this role,
72214+ as during this parsing the list is replaced with a list
72215+ of *nested* subjects for the role
72216+ */
72217+ subj_list = r_tmp->hash->first;
72218+
72219+ /* set nested subject list to null */
72220+ r_tmp->hash->first = NULL;
72221+
72222+ err = copy_user_subjs(subj_list, r_tmp);
72223+
72224+ if (err)
72225+ return err;
72226+
72227+ insert_acl_role_label(r_tmp);
72228+ }
72229+
72230+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72231+ return -EINVAL;
72232+
72233+ return err;
72234+}
72235+
72236+static int gracl_reload_apply_policies(void *reload)
72237+{
72238+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72239+ struct task_struct *task, *task2;
72240+ struct acl_role_label *role, *rtmp;
72241+ struct acl_subject_label *subj;
72242+ const struct cred *cred;
72243+ int role_applied;
72244+ int ret = 0;
72245+
72246+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72247+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72248+
72249+ /* first make sure we'll be able to apply the new policy cleanly */
72250+ do_each_thread(task2, task) {
72251+ if (task->exec_file == NULL)
72252+ continue;
72253+ role_applied = 0;
72254+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72255+ /* preserve special roles */
72256+ FOR_EACH_ROLE_START(role)
72257+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72258+ rtmp = task->role;
72259+ task->role = role;
72260+ role_applied = 1;
72261+ break;
72262+ }
72263+ FOR_EACH_ROLE_END(role)
72264+ }
72265+ if (!role_applied) {
72266+ cred = __task_cred(task);
72267+ rtmp = task->role;
72268+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72269+ }
72270+ /* this handles non-nested inherited subjects, nested subjects will still
72271+ be dropped currently */
72272+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72273+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72274+ /* change the role back so that we've made no modifications to the policy */
72275+ task->role = rtmp;
72276+
72277+ if (subj == NULL || task->tmpacl == NULL) {
72278+ ret = -EINVAL;
72279+ goto out;
72280+ }
72281+ } while_each_thread(task2, task);
72282+
72283+ /* now actually apply the policy */
72284+
72285+ do_each_thread(task2, task) {
72286+ if (task->exec_file) {
72287+ role_applied = 0;
72288+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72289+ /* preserve special roles */
72290+ FOR_EACH_ROLE_START(role)
72291+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72292+ task->role = role;
72293+ role_applied = 1;
72294+ break;
72295+ }
72296+ FOR_EACH_ROLE_END(role)
72297+ }
72298+ if (!role_applied) {
72299+ cred = __task_cred(task);
72300+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72301+ }
72302+ /* this handles non-nested inherited subjects, nested subjects will still
72303+ be dropped currently */
72304+ if (!reload_state->oldmode && task->inherited)
72305+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72306+ else {
72307+ /* looked up and tagged to the task previously */
72308+ subj = task->tmpacl;
72309+ }
72310+ /* subj will be non-null */
72311+ __gr_apply_subject_to_task(polstate, task, subj);
72312+ if (reload_state->oldmode) {
72313+ task->acl_role_id = 0;
72314+ task->acl_sp_role = 0;
72315+ task->inherited = 0;
72316+ }
72317+ } else {
72318+ // it's a kernel process
72319+ task->role = polstate->kernel_role;
72320+ task->acl = polstate->kernel_role->root_label;
72321+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72322+ task->acl->mode &= ~GR_PROCFIND;
72323+#endif
72324+ }
72325+ } while_each_thread(task2, task);
72326+
72327+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72328+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72329+
72330+out:
72331+
72332+ return ret;
72333+}
72334+
72335+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72336+{
72337+ struct gr_reload_state new_reload_state = { };
72338+ int err;
72339+
72340+ new_reload_state.oldpolicy_ptr = polstate;
72341+ new_reload_state.oldalloc_ptr = current_alloc_state;
72342+ new_reload_state.oldmode = oldmode;
72343+
72344+ current_alloc_state = &new_reload_state.newalloc;
72345+ polstate = &new_reload_state.newpolicy;
72346+
72347+ /* everything relevant is now saved off, copy in the new policy */
72348+ if (init_variables(args, true)) {
72349+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72350+ err = -ENOMEM;
72351+ goto error;
72352+ }
72353+
72354+ err = copy_user_acl(args);
72355+ free_init_variables();
72356+ if (err)
72357+ goto error;
72358+ /* the new policy is copied in, with the old policy available via saved_state
72359+ first go through applying roles, making sure to preserve special roles
72360+ then apply new subjects, making sure to preserve inherited and nested subjects,
72361+ though currently only inherited subjects will be preserved
72362+ */
72363+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72364+ if (err)
72365+ goto error;
72366+
72367+ /* we've now applied the new policy, so restore the old policy state to free it */
72368+ polstate = &new_reload_state.oldpolicy;
72369+ current_alloc_state = &new_reload_state.oldalloc;
72370+ free_variables(true);
72371+
72372+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72373+ to running_polstate/current_alloc_state inside stop_machine
72374+ */
72375+ err = 0;
72376+ goto out;
72377+error:
72378+ /* on error of loading the new policy, we'll just keep the previous
72379+ policy set around
72380+ */
72381+ free_variables(true);
72382+
72383+ /* doesn't affect runtime, but maintains consistent state */
72384+out:
72385+ polstate = new_reload_state.oldpolicy_ptr;
72386+ current_alloc_state = new_reload_state.oldalloc_ptr;
72387+
72388+ return err;
72389+}
72390+
72391+static int
72392+gracl_init(struct gr_arg *args)
72393+{
72394+ int error = 0;
72395+
72396+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72397+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72398+
72399+ if (init_variables(args, false)) {
72400+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72401+ error = -ENOMEM;
72402+ goto out;
72403+ }
72404+
72405+ error = copy_user_acl(args);
72406+ free_init_variables();
72407+ if (error)
72408+ goto out;
72409+
72410+ error = gr_set_acls(0);
72411+ if (error)
72412+ goto out;
72413+
72414+ gr_enable_rbac_system();
72415+
72416+ return 0;
72417+
72418+out:
72419+ free_variables(false);
72420+ return error;
72421+}
72422+
72423+static int
72424+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72425+ unsigned char **sum)
72426+{
72427+ struct acl_role_label *r;
72428+ struct role_allowed_ip *ipp;
72429+ struct role_transition *trans;
72430+ unsigned int i;
72431+ int found = 0;
72432+ u32 curr_ip = current->signal->curr_ip;
72433+
72434+ current->signal->saved_ip = curr_ip;
72435+
72436+ /* check transition table */
72437+
72438+ for (trans = current->role->transitions; trans; trans = trans->next) {
72439+ if (!strcmp(rolename, trans->rolename)) {
72440+ found = 1;
72441+ break;
72442+ }
72443+ }
72444+
72445+ if (!found)
72446+ return 0;
72447+
72448+ /* handle special roles that do not require authentication
72449+ and check ip */
72450+
72451+ FOR_EACH_ROLE_START(r)
72452+ if (!strcmp(rolename, r->rolename) &&
72453+ (r->roletype & GR_ROLE_SPECIAL)) {
72454+ found = 0;
72455+ if (r->allowed_ips != NULL) {
72456+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72457+ if ((ntohl(curr_ip) & ipp->netmask) ==
72458+ (ntohl(ipp->addr) & ipp->netmask))
72459+ found = 1;
72460+ }
72461+ } else
72462+ found = 2;
72463+ if (!found)
72464+ return 0;
72465+
72466+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72467+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72468+ *salt = NULL;
72469+ *sum = NULL;
72470+ return 1;
72471+ }
72472+ }
72473+ FOR_EACH_ROLE_END(r)
72474+
72475+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72476+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72477+ *salt = polstate->acl_special_roles[i]->salt;
72478+ *sum = polstate->acl_special_roles[i]->sum;
72479+ return 1;
72480+ }
72481+ }
72482+
72483+ return 0;
72484+}
72485+
72486+int gr_check_secure_terminal(struct task_struct *task)
72487+{
72488+ struct task_struct *p, *p2, *p3;
72489+ struct files_struct *files;
72490+ struct fdtable *fdt;
72491+ struct file *our_file = NULL, *file;
72492+ int i;
72493+
72494+ if (task->signal->tty == NULL)
72495+ return 1;
72496+
72497+ files = get_files_struct(task);
72498+ if (files != NULL) {
72499+ rcu_read_lock();
72500+ fdt = files_fdtable(files);
72501+ for (i=0; i < fdt->max_fds; i++) {
72502+ file = fcheck_files(files, i);
72503+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72504+ get_file(file);
72505+ our_file = file;
72506+ }
72507+ }
72508+ rcu_read_unlock();
72509+ put_files_struct(files);
72510+ }
72511+
72512+ if (our_file == NULL)
72513+ return 1;
72514+
72515+ read_lock(&tasklist_lock);
72516+ do_each_thread(p2, p) {
72517+ files = get_files_struct(p);
72518+ if (files == NULL ||
72519+ (p->signal && p->signal->tty == task->signal->tty)) {
72520+ if (files != NULL)
72521+ put_files_struct(files);
72522+ continue;
72523+ }
72524+ rcu_read_lock();
72525+ fdt = files_fdtable(files);
72526+ for (i=0; i < fdt->max_fds; i++) {
72527+ file = fcheck_files(files, i);
72528+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72529+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72530+ p3 = task;
72531+ while (task_pid_nr(p3) > 0) {
72532+ if (p3 == p)
72533+ break;
72534+ p3 = p3->real_parent;
72535+ }
72536+ if (p3 == p)
72537+ break;
72538+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72539+ gr_handle_alertkill(p);
72540+ rcu_read_unlock();
72541+ put_files_struct(files);
72542+ read_unlock(&tasklist_lock);
72543+ fput(our_file);
72544+ return 0;
72545+ }
72546+ }
72547+ rcu_read_unlock();
72548+ put_files_struct(files);
72549+ } while_each_thread(p2, p);
72550+ read_unlock(&tasklist_lock);
72551+
72552+ fput(our_file);
72553+ return 1;
72554+}
72555+
72556+ssize_t
72557+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72558+{
72559+ struct gr_arg_wrapper uwrap;
72560+ unsigned char *sprole_salt = NULL;
72561+ unsigned char *sprole_sum = NULL;
72562+ int error = 0;
72563+ int error2 = 0;
72564+ size_t req_count = 0;
72565+ unsigned char oldmode = 0;
72566+
72567+ mutex_lock(&gr_dev_mutex);
72568+
72569+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72570+ error = -EPERM;
72571+ goto out;
72572+ }
72573+
72574+#ifdef CONFIG_COMPAT
72575+ pax_open_kernel();
72576+ if (is_compat_task()) {
72577+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72578+ copy_gr_arg = &copy_gr_arg_compat;
72579+ copy_acl_object_label = &copy_acl_object_label_compat;
72580+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72581+ copy_acl_role_label = &copy_acl_role_label_compat;
72582+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72583+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72584+ copy_role_transition = &copy_role_transition_compat;
72585+ copy_sprole_pw = &copy_sprole_pw_compat;
72586+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72587+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72588+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72589+ } else {
72590+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72591+ copy_gr_arg = &copy_gr_arg_normal;
72592+ copy_acl_object_label = &copy_acl_object_label_normal;
72593+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72594+ copy_acl_role_label = &copy_acl_role_label_normal;
72595+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72596+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72597+ copy_role_transition = &copy_role_transition_normal;
72598+ copy_sprole_pw = &copy_sprole_pw_normal;
72599+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72600+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72601+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72602+ }
72603+ pax_close_kernel();
72604+#endif
72605+
72606+ req_count = get_gr_arg_wrapper_size();
72607+
72608+ if (count != req_count) {
72609+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72610+ error = -EINVAL;
72611+ goto out;
72612+ }
72613+
72614+
72615+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72616+ gr_auth_expires = 0;
72617+ gr_auth_attempts = 0;
72618+ }
72619+
72620+ error = copy_gr_arg_wrapper(buf, &uwrap);
72621+ if (error)
72622+ goto out;
72623+
72624+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72625+ if (error)
72626+ goto out;
72627+
72628+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72629+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72630+ time_after(gr_auth_expires, get_seconds())) {
72631+ error = -EBUSY;
72632+ goto out;
72633+ }
72634+
72635+ /* if non-root trying to do anything other than use a special role,
72636+ do not attempt authentication, do not count towards authentication
72637+ locking
72638+ */
72639+
72640+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72641+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72642+ gr_is_global_nonroot(current_uid())) {
72643+ error = -EPERM;
72644+ goto out;
72645+ }
72646+
72647+ /* ensure pw and special role name are null terminated */
72648+
72649+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72650+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72651+
72652+ /* Okay.
72653+ * We have our enough of the argument structure..(we have yet
72654+ * to copy_from_user the tables themselves) . Copy the tables
72655+ * only if we need them, i.e. for loading operations. */
72656+
72657+ switch (gr_usermode.mode) {
72658+ case GR_STATUS:
72659+ if (gr_acl_is_enabled()) {
72660+ error = 1;
72661+ if (!gr_check_secure_terminal(current))
72662+ error = 3;
72663+ } else
72664+ error = 2;
72665+ goto out;
72666+ case GR_SHUTDOWN:
72667+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72668+ stop_machine(gr_rbac_disable, NULL, NULL);
72669+ free_variables(false);
72670+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72671+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72672+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72673+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72674+ } else if (gr_acl_is_enabled()) {
72675+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72676+ error = -EPERM;
72677+ } else {
72678+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72679+ error = -EAGAIN;
72680+ }
72681+ break;
72682+ case GR_ENABLE:
72683+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72684+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72685+ else {
72686+ if (gr_acl_is_enabled())
72687+ error = -EAGAIN;
72688+ else
72689+ error = error2;
72690+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72691+ }
72692+ break;
72693+ case GR_OLDRELOAD:
72694+ oldmode = 1;
72695+ case GR_RELOAD:
72696+ if (!gr_acl_is_enabled()) {
72697+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72698+ error = -EAGAIN;
72699+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72700+ error2 = gracl_reload(&gr_usermode, oldmode);
72701+ if (!error2)
72702+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72703+ else {
72704+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72705+ error = error2;
72706+ }
72707+ } else {
72708+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72709+ error = -EPERM;
72710+ }
72711+ break;
72712+ case GR_SEGVMOD:
72713+ if (unlikely(!gr_acl_is_enabled())) {
72714+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72715+ error = -EAGAIN;
72716+ break;
72717+ }
72718+
72719+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72720+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72721+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72722+ struct acl_subject_label *segvacl;
72723+ segvacl =
72724+ lookup_acl_subj_label(gr_usermode.segv_inode,
72725+ gr_usermode.segv_device,
72726+ current->role);
72727+ if (segvacl) {
72728+ segvacl->crashes = 0;
72729+ segvacl->expires = 0;
72730+ }
72731+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72732+ gr_remove_uid(gr_usermode.segv_uid);
72733+ }
72734+ } else {
72735+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72736+ error = -EPERM;
72737+ }
72738+ break;
72739+ case GR_SPROLE:
72740+ case GR_SPROLEPAM:
72741+ if (unlikely(!gr_acl_is_enabled())) {
72742+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72743+ error = -EAGAIN;
72744+ break;
72745+ }
72746+
72747+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72748+ current->role->expires = 0;
72749+ current->role->auth_attempts = 0;
72750+ }
72751+
72752+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72753+ time_after(current->role->expires, get_seconds())) {
72754+ error = -EBUSY;
72755+ goto out;
72756+ }
72757+
72758+ if (lookup_special_role_auth
72759+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72760+ && ((!sprole_salt && !sprole_sum)
72761+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72762+ char *p = "";
72763+ assign_special_role(gr_usermode.sp_role);
72764+ read_lock(&tasklist_lock);
72765+ if (current->real_parent)
72766+ p = current->real_parent->role->rolename;
72767+ read_unlock(&tasklist_lock);
72768+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72769+ p, acl_sp_role_value);
72770+ } else {
72771+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72772+ error = -EPERM;
72773+ if(!(current->role->auth_attempts++))
72774+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72775+
72776+ goto out;
72777+ }
72778+ break;
72779+ case GR_UNSPROLE:
72780+ if (unlikely(!gr_acl_is_enabled())) {
72781+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72782+ error = -EAGAIN;
72783+ break;
72784+ }
72785+
72786+ if (current->role->roletype & GR_ROLE_SPECIAL) {
72787+ char *p = "";
72788+ int i = 0;
72789+
72790+ read_lock(&tasklist_lock);
72791+ if (current->real_parent) {
72792+ p = current->real_parent->role->rolename;
72793+ i = current->real_parent->acl_role_id;
72794+ }
72795+ read_unlock(&tasklist_lock);
72796+
72797+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72798+ gr_set_acls(1);
72799+ } else {
72800+ error = -EPERM;
72801+ goto out;
72802+ }
72803+ break;
72804+ default:
72805+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72806+ error = -EINVAL;
72807+ break;
72808+ }
72809+
72810+ if (error != -EPERM)
72811+ goto out;
72812+
72813+ if(!(gr_auth_attempts++))
72814+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72815+
72816+ out:
72817+ mutex_unlock(&gr_dev_mutex);
72818+
72819+ if (!error)
72820+ error = req_count;
72821+
72822+ return error;
72823+}
72824+
72825+int
72826+gr_set_acls(const int type)
72827+{
72828+ struct task_struct *task, *task2;
72829+ struct acl_role_label *role = current->role;
72830+ struct acl_subject_label *subj;
72831+ __u16 acl_role_id = current->acl_role_id;
72832+ const struct cred *cred;
72833+ int ret;
72834+
72835+ rcu_read_lock();
72836+ read_lock(&tasklist_lock);
72837+ read_lock(&grsec_exec_file_lock);
72838+ do_each_thread(task2, task) {
72839+ /* check to see if we're called from the exit handler,
72840+ if so, only replace ACLs that have inherited the admin
72841+ ACL */
72842+
72843+ if (type && (task->role != role ||
72844+ task->acl_role_id != acl_role_id))
72845+ continue;
72846+
72847+ task->acl_role_id = 0;
72848+ task->acl_sp_role = 0;
72849+ task->inherited = 0;
72850+
72851+ if (task->exec_file) {
72852+ cred = __task_cred(task);
72853+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72854+ subj = __gr_get_subject_for_task(polstate, task, NULL);
72855+ if (subj == NULL) {
72856+ ret = -EINVAL;
72857+ read_unlock(&grsec_exec_file_lock);
72858+ read_unlock(&tasklist_lock);
72859+ rcu_read_unlock();
72860+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72861+ return ret;
72862+ }
72863+ __gr_apply_subject_to_task(polstate, task, subj);
72864+ } else {
72865+ // it's a kernel process
72866+ task->role = polstate->kernel_role;
72867+ task->acl = polstate->kernel_role->root_label;
72868+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72869+ task->acl->mode &= ~GR_PROCFIND;
72870+#endif
72871+ }
72872+ } while_each_thread(task2, task);
72873+ read_unlock(&grsec_exec_file_lock);
72874+ read_unlock(&tasklist_lock);
72875+ rcu_read_unlock();
72876+
72877+ return 0;
72878+}
72879diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72880new file mode 100644
72881index 0000000..39645c9
72882--- /dev/null
72883+++ b/grsecurity/gracl_res.c
72884@@ -0,0 +1,68 @@
72885+#include <linux/kernel.h>
72886+#include <linux/sched.h>
72887+#include <linux/gracl.h>
72888+#include <linux/grinternal.h>
72889+
72890+static const char *restab_log[] = {
72891+ [RLIMIT_CPU] = "RLIMIT_CPU",
72892+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72893+ [RLIMIT_DATA] = "RLIMIT_DATA",
72894+ [RLIMIT_STACK] = "RLIMIT_STACK",
72895+ [RLIMIT_CORE] = "RLIMIT_CORE",
72896+ [RLIMIT_RSS] = "RLIMIT_RSS",
72897+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
72898+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72899+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72900+ [RLIMIT_AS] = "RLIMIT_AS",
72901+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72902+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72903+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72904+ [RLIMIT_NICE] = "RLIMIT_NICE",
72905+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72906+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72907+ [GR_CRASH_RES] = "RLIMIT_CRASH"
72908+};
72909+
72910+void
72911+gr_log_resource(const struct task_struct *task,
72912+ const int res, const unsigned long wanted, const int gt)
72913+{
72914+ const struct cred *cred;
72915+ unsigned long rlim;
72916+
72917+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
72918+ return;
72919+
72920+ // not yet supported resource
72921+ if (unlikely(!restab_log[res]))
72922+ return;
72923+
72924+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72925+ rlim = task_rlimit_max(task, res);
72926+ else
72927+ rlim = task_rlimit(task, res);
72928+
72929+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72930+ return;
72931+
72932+ rcu_read_lock();
72933+ cred = __task_cred(task);
72934+
72935+ if (res == RLIMIT_NPROC &&
72936+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72937+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72938+ goto out_rcu_unlock;
72939+ else if (res == RLIMIT_MEMLOCK &&
72940+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72941+ goto out_rcu_unlock;
72942+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72943+ goto out_rcu_unlock;
72944+ rcu_read_unlock();
72945+
72946+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72947+
72948+ return;
72949+out_rcu_unlock:
72950+ rcu_read_unlock();
72951+ return;
72952+}
72953diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72954new file mode 100644
72955index 0000000..2040e61
72956--- /dev/null
72957+++ b/grsecurity/gracl_segv.c
72958@@ -0,0 +1,313 @@
72959+#include <linux/kernel.h>
72960+#include <linux/mm.h>
72961+#include <asm/uaccess.h>
72962+#include <asm/errno.h>
72963+#include <asm/mman.h>
72964+#include <net/sock.h>
72965+#include <linux/file.h>
72966+#include <linux/fs.h>
72967+#include <linux/net.h>
72968+#include <linux/in.h>
72969+#include <linux/slab.h>
72970+#include <linux/types.h>
72971+#include <linux/sched.h>
72972+#include <linux/timer.h>
72973+#include <linux/gracl.h>
72974+#include <linux/grsecurity.h>
72975+#include <linux/grinternal.h>
72976+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72977+#include <linux/magic.h>
72978+#include <linux/pagemap.h>
72979+#include "../fs/btrfs/async-thread.h"
72980+#include "../fs/btrfs/ctree.h"
72981+#include "../fs/btrfs/btrfs_inode.h"
72982+#endif
72983+
72984+static struct crash_uid *uid_set;
72985+static unsigned short uid_used;
72986+static DEFINE_SPINLOCK(gr_uid_lock);
72987+extern rwlock_t gr_inode_lock;
72988+extern struct acl_subject_label *
72989+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72990+ struct acl_role_label *role);
72991+
72992+static inline dev_t __get_dev(const struct dentry *dentry)
72993+{
72994+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72995+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72996+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
72997+ else
72998+#endif
72999+ return dentry->d_sb->s_dev;
73000+}
73001+
73002+int
73003+gr_init_uidset(void)
73004+{
73005+ uid_set =
73006+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73007+ uid_used = 0;
73008+
73009+ return uid_set ? 1 : 0;
73010+}
73011+
73012+void
73013+gr_free_uidset(void)
73014+{
73015+ if (uid_set) {
73016+ struct crash_uid *tmpset;
73017+ spin_lock(&gr_uid_lock);
73018+ tmpset = uid_set;
73019+ uid_set = NULL;
73020+ uid_used = 0;
73021+ spin_unlock(&gr_uid_lock);
73022+ if (tmpset)
73023+ kfree(tmpset);
73024+ }
73025+
73026+ return;
73027+}
73028+
73029+int
73030+gr_find_uid(const uid_t uid)
73031+{
73032+ struct crash_uid *tmp = uid_set;
73033+ uid_t buid;
73034+ int low = 0, high = uid_used - 1, mid;
73035+
73036+ while (high >= low) {
73037+ mid = (low + high) >> 1;
73038+ buid = tmp[mid].uid;
73039+ if (buid == uid)
73040+ return mid;
73041+ if (buid > uid)
73042+ high = mid - 1;
73043+ if (buid < uid)
73044+ low = mid + 1;
73045+ }
73046+
73047+ return -1;
73048+}
73049+
73050+static __inline__ void
73051+gr_insertsort(void)
73052+{
73053+ unsigned short i, j;
73054+ struct crash_uid index;
73055+
73056+ for (i = 1; i < uid_used; i++) {
73057+ index = uid_set[i];
73058+ j = i;
73059+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73060+ uid_set[j] = uid_set[j - 1];
73061+ j--;
73062+ }
73063+ uid_set[j] = index;
73064+ }
73065+
73066+ return;
73067+}
73068+
73069+static __inline__ void
73070+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73071+{
73072+ int loc;
73073+ uid_t uid = GR_GLOBAL_UID(kuid);
73074+
73075+ if (uid_used == GR_UIDTABLE_MAX)
73076+ return;
73077+
73078+ loc = gr_find_uid(uid);
73079+
73080+ if (loc >= 0) {
73081+ uid_set[loc].expires = expires;
73082+ return;
73083+ }
73084+
73085+ uid_set[uid_used].uid = uid;
73086+ uid_set[uid_used].expires = expires;
73087+ uid_used++;
73088+
73089+ gr_insertsort();
73090+
73091+ return;
73092+}
73093+
73094+void
73095+gr_remove_uid(const unsigned short loc)
73096+{
73097+ unsigned short i;
73098+
73099+ for (i = loc + 1; i < uid_used; i++)
73100+ uid_set[i - 1] = uid_set[i];
73101+
73102+ uid_used--;
73103+
73104+ return;
73105+}
73106+
73107+int
73108+gr_check_crash_uid(const kuid_t kuid)
73109+{
73110+ int loc;
73111+ int ret = 0;
73112+ uid_t uid;
73113+
73114+ if (unlikely(!gr_acl_is_enabled()))
73115+ return 0;
73116+
73117+ uid = GR_GLOBAL_UID(kuid);
73118+
73119+ spin_lock(&gr_uid_lock);
73120+ loc = gr_find_uid(uid);
73121+
73122+ if (loc < 0)
73123+ goto out_unlock;
73124+
73125+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73126+ gr_remove_uid(loc);
73127+ else
73128+ ret = 1;
73129+
73130+out_unlock:
73131+ spin_unlock(&gr_uid_lock);
73132+ return ret;
73133+}
73134+
73135+static __inline__ int
73136+proc_is_setxid(const struct cred *cred)
73137+{
73138+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73139+ !uid_eq(cred->uid, cred->fsuid))
73140+ return 1;
73141+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73142+ !gid_eq(cred->gid, cred->fsgid))
73143+ return 1;
73144+
73145+ return 0;
73146+}
73147+
73148+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73149+
73150+void
73151+gr_handle_crash(struct task_struct *task, const int sig)
73152+{
73153+ struct acl_subject_label *curr;
73154+ struct task_struct *tsk, *tsk2;
73155+ const struct cred *cred;
73156+ const struct cred *cred2;
73157+
73158+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73159+ return;
73160+
73161+ if (unlikely(!gr_acl_is_enabled()))
73162+ return;
73163+
73164+ curr = task->acl;
73165+
73166+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73167+ return;
73168+
73169+ if (time_before_eq(curr->expires, get_seconds())) {
73170+ curr->expires = 0;
73171+ curr->crashes = 0;
73172+ }
73173+
73174+ curr->crashes++;
73175+
73176+ if (!curr->expires)
73177+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73178+
73179+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73180+ time_after(curr->expires, get_seconds())) {
73181+ rcu_read_lock();
73182+ cred = __task_cred(task);
73183+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73184+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73185+ spin_lock(&gr_uid_lock);
73186+ gr_insert_uid(cred->uid, curr->expires);
73187+ spin_unlock(&gr_uid_lock);
73188+ curr->expires = 0;
73189+ curr->crashes = 0;
73190+ read_lock(&tasklist_lock);
73191+ do_each_thread(tsk2, tsk) {
73192+ cred2 = __task_cred(tsk);
73193+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73194+ gr_fake_force_sig(SIGKILL, tsk);
73195+ } while_each_thread(tsk2, tsk);
73196+ read_unlock(&tasklist_lock);
73197+ } else {
73198+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73199+ read_lock(&tasklist_lock);
73200+ read_lock(&grsec_exec_file_lock);
73201+ do_each_thread(tsk2, tsk) {
73202+ if (likely(tsk != task)) {
73203+ // if this thread has the same subject as the one that triggered
73204+ // RES_CRASH and it's the same binary, kill it
73205+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73206+ gr_fake_force_sig(SIGKILL, tsk);
73207+ }
73208+ } while_each_thread(tsk2, tsk);
73209+ read_unlock(&grsec_exec_file_lock);
73210+ read_unlock(&tasklist_lock);
73211+ }
73212+ rcu_read_unlock();
73213+ }
73214+
73215+ return;
73216+}
73217+
73218+int
73219+gr_check_crash_exec(const struct file *filp)
73220+{
73221+ struct acl_subject_label *curr;
73222+
73223+ if (unlikely(!gr_acl_is_enabled()))
73224+ return 0;
73225+
73226+ read_lock(&gr_inode_lock);
73227+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73228+ __get_dev(filp->f_path.dentry),
73229+ current->role);
73230+ read_unlock(&gr_inode_lock);
73231+
73232+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73233+ (!curr->crashes && !curr->expires))
73234+ return 0;
73235+
73236+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73237+ time_after(curr->expires, get_seconds()))
73238+ return 1;
73239+ else if (time_before_eq(curr->expires, get_seconds())) {
73240+ curr->crashes = 0;
73241+ curr->expires = 0;
73242+ }
73243+
73244+ return 0;
73245+}
73246+
73247+void
73248+gr_handle_alertkill(struct task_struct *task)
73249+{
73250+ struct acl_subject_label *curracl;
73251+ __u32 curr_ip;
73252+ struct task_struct *p, *p2;
73253+
73254+ if (unlikely(!gr_acl_is_enabled()))
73255+ return;
73256+
73257+ curracl = task->acl;
73258+ curr_ip = task->signal->curr_ip;
73259+
73260+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73261+ read_lock(&tasklist_lock);
73262+ do_each_thread(p2, p) {
73263+ if (p->signal->curr_ip == curr_ip)
73264+ gr_fake_force_sig(SIGKILL, p);
73265+ } while_each_thread(p2, p);
73266+ read_unlock(&tasklist_lock);
73267+ } else if (curracl->mode & GR_KILLPROC)
73268+ gr_fake_force_sig(SIGKILL, task);
73269+
73270+ return;
73271+}
73272diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73273new file mode 100644
73274index 0000000..98011b0
73275--- /dev/null
73276+++ b/grsecurity/gracl_shm.c
73277@@ -0,0 +1,40 @@
73278+#include <linux/kernel.h>
73279+#include <linux/mm.h>
73280+#include <linux/sched.h>
73281+#include <linux/file.h>
73282+#include <linux/ipc.h>
73283+#include <linux/gracl.h>
73284+#include <linux/grsecurity.h>
73285+#include <linux/grinternal.h>
73286+
73287+int
73288+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73289+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73290+{
73291+ struct task_struct *task;
73292+
73293+ if (!gr_acl_is_enabled())
73294+ return 1;
73295+
73296+ rcu_read_lock();
73297+ read_lock(&tasklist_lock);
73298+
73299+ task = find_task_by_vpid(shm_cprid);
73300+
73301+ if (unlikely(!task))
73302+ task = find_task_by_vpid(shm_lapid);
73303+
73304+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73305+ (task_pid_nr(task) == shm_lapid)) &&
73306+ (task->acl->mode & GR_PROTSHM) &&
73307+ (task->acl != current->acl))) {
73308+ read_unlock(&tasklist_lock);
73309+ rcu_read_unlock();
73310+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73311+ return 0;
73312+ }
73313+ read_unlock(&tasklist_lock);
73314+ rcu_read_unlock();
73315+
73316+ return 1;
73317+}
73318diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73319new file mode 100644
73320index 0000000..bc0be01
73321--- /dev/null
73322+++ b/grsecurity/grsec_chdir.c
73323@@ -0,0 +1,19 @@
73324+#include <linux/kernel.h>
73325+#include <linux/sched.h>
73326+#include <linux/fs.h>
73327+#include <linux/file.h>
73328+#include <linux/grsecurity.h>
73329+#include <linux/grinternal.h>
73330+
73331+void
73332+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73333+{
73334+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73335+ if ((grsec_enable_chdir && grsec_enable_group &&
73336+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73337+ !grsec_enable_group)) {
73338+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73339+ }
73340+#endif
73341+ return;
73342+}
73343diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73344new file mode 100644
73345index 0000000..baa635c
73346--- /dev/null
73347+++ b/grsecurity/grsec_chroot.c
73348@@ -0,0 +1,387 @@
73349+#include <linux/kernel.h>
73350+#include <linux/module.h>
73351+#include <linux/sched.h>
73352+#include <linux/file.h>
73353+#include <linux/fs.h>
73354+#include <linux/mount.h>
73355+#include <linux/types.h>
73356+#include "../fs/mount.h"
73357+#include <linux/grsecurity.h>
73358+#include <linux/grinternal.h>
73359+
73360+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73361+int gr_init_ran;
73362+#endif
73363+
73364+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73365+{
73366+#ifdef CONFIG_GRKERNSEC
73367+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73368+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73369+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73370+ && gr_init_ran
73371+#endif
73372+ )
73373+ task->gr_is_chrooted = 1;
73374+ else {
73375+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73376+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73377+ gr_init_ran = 1;
73378+#endif
73379+ task->gr_is_chrooted = 0;
73380+ }
73381+
73382+ task->gr_chroot_dentry = path->dentry;
73383+#endif
73384+ return;
73385+}
73386+
73387+void gr_clear_chroot_entries(struct task_struct *task)
73388+{
73389+#ifdef CONFIG_GRKERNSEC
73390+ task->gr_is_chrooted = 0;
73391+ task->gr_chroot_dentry = NULL;
73392+#endif
73393+ return;
73394+}
73395+
73396+int
73397+gr_handle_chroot_unix(const pid_t pid)
73398+{
73399+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73400+ struct task_struct *p;
73401+
73402+ if (unlikely(!grsec_enable_chroot_unix))
73403+ return 1;
73404+
73405+ if (likely(!proc_is_chrooted(current)))
73406+ return 1;
73407+
73408+ rcu_read_lock();
73409+ read_lock(&tasklist_lock);
73410+ p = find_task_by_vpid_unrestricted(pid);
73411+ if (unlikely(p && !have_same_root(current, p))) {
73412+ read_unlock(&tasklist_lock);
73413+ rcu_read_unlock();
73414+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73415+ return 0;
73416+ }
73417+ read_unlock(&tasklist_lock);
73418+ rcu_read_unlock();
73419+#endif
73420+ return 1;
73421+}
73422+
73423+int
73424+gr_handle_chroot_nice(void)
73425+{
73426+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73427+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73428+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73429+ return -EPERM;
73430+ }
73431+#endif
73432+ return 0;
73433+}
73434+
73435+int
73436+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73437+{
73438+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73439+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73440+ && proc_is_chrooted(current)) {
73441+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73442+ return -EACCES;
73443+ }
73444+#endif
73445+ return 0;
73446+}
73447+
73448+int
73449+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73450+{
73451+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73452+ struct task_struct *p;
73453+ int ret = 0;
73454+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73455+ return ret;
73456+
73457+ read_lock(&tasklist_lock);
73458+ do_each_pid_task(pid, type, p) {
73459+ if (!have_same_root(current, p)) {
73460+ ret = 1;
73461+ goto out;
73462+ }
73463+ } while_each_pid_task(pid, type, p);
73464+out:
73465+ read_unlock(&tasklist_lock);
73466+ return ret;
73467+#endif
73468+ return 0;
73469+}
73470+
73471+int
73472+gr_pid_is_chrooted(struct task_struct *p)
73473+{
73474+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73475+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73476+ return 0;
73477+
73478+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73479+ !have_same_root(current, p)) {
73480+ return 1;
73481+ }
73482+#endif
73483+ return 0;
73484+}
73485+
73486+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73487+
73488+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73489+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73490+{
73491+ struct path path, currentroot;
73492+ int ret = 0;
73493+
73494+ path.dentry = (struct dentry *)u_dentry;
73495+ path.mnt = (struct vfsmount *)u_mnt;
73496+ get_fs_root(current->fs, &currentroot);
73497+ if (path_is_under(&path, &currentroot))
73498+ ret = 1;
73499+ path_put(&currentroot);
73500+
73501+ return ret;
73502+}
73503+#endif
73504+
73505+int
73506+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73507+{
73508+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73509+ if (!grsec_enable_chroot_fchdir)
73510+ return 1;
73511+
73512+ if (!proc_is_chrooted(current))
73513+ return 1;
73514+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73515+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73516+ return 0;
73517+ }
73518+#endif
73519+ return 1;
73520+}
73521+
73522+int
73523+gr_chroot_fhandle(void)
73524+{
73525+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73526+ if (!grsec_enable_chroot_fchdir)
73527+ return 1;
73528+
73529+ if (!proc_is_chrooted(current))
73530+ return 1;
73531+ else {
73532+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
73533+ return 0;
73534+ }
73535+#endif
73536+ return 1;
73537+}
73538+
73539+int
73540+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73541+ const time_t shm_createtime)
73542+{
73543+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73544+ struct task_struct *p;
73545+ time_t starttime;
73546+
73547+ if (unlikely(!grsec_enable_chroot_shmat))
73548+ return 1;
73549+
73550+ if (likely(!proc_is_chrooted(current)))
73551+ return 1;
73552+
73553+ rcu_read_lock();
73554+ read_lock(&tasklist_lock);
73555+
73556+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73557+ starttime = p->start_time.tv_sec;
73558+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73559+ if (have_same_root(current, p)) {
73560+ goto allow;
73561+ } else {
73562+ read_unlock(&tasklist_lock);
73563+ rcu_read_unlock();
73564+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73565+ return 0;
73566+ }
73567+ }
73568+ /* creator exited, pid reuse, fall through to next check */
73569+ }
73570+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73571+ if (unlikely(!have_same_root(current, p))) {
73572+ read_unlock(&tasklist_lock);
73573+ rcu_read_unlock();
73574+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73575+ return 0;
73576+ }
73577+ }
73578+
73579+allow:
73580+ read_unlock(&tasklist_lock);
73581+ rcu_read_unlock();
73582+#endif
73583+ return 1;
73584+}
73585+
73586+void
73587+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73588+{
73589+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73590+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73591+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73592+#endif
73593+ return;
73594+}
73595+
73596+int
73597+gr_handle_chroot_mknod(const struct dentry *dentry,
73598+ const struct vfsmount *mnt, const int mode)
73599+{
73600+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73601+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73602+ proc_is_chrooted(current)) {
73603+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73604+ return -EPERM;
73605+ }
73606+#endif
73607+ return 0;
73608+}
73609+
73610+int
73611+gr_handle_chroot_mount(const struct dentry *dentry,
73612+ const struct vfsmount *mnt, const char *dev_name)
73613+{
73614+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73615+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73616+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73617+ return -EPERM;
73618+ }
73619+#endif
73620+ return 0;
73621+}
73622+
73623+int
73624+gr_handle_chroot_pivot(void)
73625+{
73626+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73627+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73628+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73629+ return -EPERM;
73630+ }
73631+#endif
73632+ return 0;
73633+}
73634+
73635+int
73636+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73637+{
73638+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73639+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73640+ !gr_is_outside_chroot(dentry, mnt)) {
73641+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73642+ return -EPERM;
73643+ }
73644+#endif
73645+ return 0;
73646+}
73647+
73648+extern const char *captab_log[];
73649+extern int captab_log_entries;
73650+
73651+int
73652+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73653+{
73654+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73655+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73656+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73657+ if (cap_raised(chroot_caps, cap)) {
73658+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73659+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73660+ }
73661+ return 0;
73662+ }
73663+ }
73664+#endif
73665+ return 1;
73666+}
73667+
73668+int
73669+gr_chroot_is_capable(const int cap)
73670+{
73671+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73672+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73673+#endif
73674+ return 1;
73675+}
73676+
73677+int
73678+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73679+{
73680+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73681+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73682+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73683+ if (cap_raised(chroot_caps, cap)) {
73684+ return 0;
73685+ }
73686+ }
73687+#endif
73688+ return 1;
73689+}
73690+
73691+int
73692+gr_chroot_is_capable_nolog(const int cap)
73693+{
73694+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73695+ return gr_task_chroot_is_capable_nolog(current, cap);
73696+#endif
73697+ return 1;
73698+}
73699+
73700+int
73701+gr_handle_chroot_sysctl(const int op)
73702+{
73703+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73704+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73705+ proc_is_chrooted(current))
73706+ return -EACCES;
73707+#endif
73708+ return 0;
73709+}
73710+
73711+void
73712+gr_handle_chroot_chdir(const struct path *path)
73713+{
73714+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73715+ if (grsec_enable_chroot_chdir)
73716+ set_fs_pwd(current->fs, path);
73717+#endif
73718+ return;
73719+}
73720+
73721+int
73722+gr_handle_chroot_chmod(const struct dentry *dentry,
73723+ const struct vfsmount *mnt, const int mode)
73724+{
73725+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73726+ /* allow chmod +s on directories, but not files */
73727+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73728+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73729+ proc_is_chrooted(current)) {
73730+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73731+ return -EPERM;
73732+ }
73733+#endif
73734+ return 0;
73735+}
73736diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73737new file mode 100644
73738index 0000000..de31e65
73739--- /dev/null
73740+++ b/grsecurity/grsec_disabled.c
73741@@ -0,0 +1,434 @@
73742+#include <linux/kernel.h>
73743+#include <linux/module.h>
73744+#include <linux/sched.h>
73745+#include <linux/file.h>
73746+#include <linux/fs.h>
73747+#include <linux/kdev_t.h>
73748+#include <linux/net.h>
73749+#include <linux/in.h>
73750+#include <linux/ip.h>
73751+#include <linux/skbuff.h>
73752+#include <linux/sysctl.h>
73753+
73754+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73755+void
73756+pax_set_initial_flags(struct linux_binprm *bprm)
73757+{
73758+ return;
73759+}
73760+#endif
73761+
73762+#ifdef CONFIG_SYSCTL
73763+__u32
73764+gr_handle_sysctl(const struct ctl_table * table, const int op)
73765+{
73766+ return 0;
73767+}
73768+#endif
73769+
73770+#ifdef CONFIG_TASKSTATS
73771+int gr_is_taskstats_denied(int pid)
73772+{
73773+ return 0;
73774+}
73775+#endif
73776+
73777+int
73778+gr_acl_is_enabled(void)
73779+{
73780+ return 0;
73781+}
73782+
73783+void
73784+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73785+{
73786+ return;
73787+}
73788+
73789+int
73790+gr_handle_rawio(const struct inode *inode)
73791+{
73792+ return 0;
73793+}
73794+
73795+void
73796+gr_acl_handle_psacct(struct task_struct *task, const long code)
73797+{
73798+ return;
73799+}
73800+
73801+int
73802+gr_handle_ptrace(struct task_struct *task, const long request)
73803+{
73804+ return 0;
73805+}
73806+
73807+int
73808+gr_handle_proc_ptrace(struct task_struct *task)
73809+{
73810+ return 0;
73811+}
73812+
73813+int
73814+gr_set_acls(const int type)
73815+{
73816+ return 0;
73817+}
73818+
73819+int
73820+gr_check_hidden_task(const struct task_struct *tsk)
73821+{
73822+ return 0;
73823+}
73824+
73825+int
73826+gr_check_protected_task(const struct task_struct *task)
73827+{
73828+ return 0;
73829+}
73830+
73831+int
73832+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73833+{
73834+ return 0;
73835+}
73836+
73837+void
73838+gr_copy_label(struct task_struct *tsk)
73839+{
73840+ return;
73841+}
73842+
73843+void
73844+gr_set_pax_flags(struct task_struct *task)
73845+{
73846+ return;
73847+}
73848+
73849+int
73850+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73851+ const int unsafe_share)
73852+{
73853+ return 0;
73854+}
73855+
73856+void
73857+gr_handle_delete(const ino_t ino, const dev_t dev)
73858+{
73859+ return;
73860+}
73861+
73862+void
73863+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73864+{
73865+ return;
73866+}
73867+
73868+void
73869+gr_handle_crash(struct task_struct *task, const int sig)
73870+{
73871+ return;
73872+}
73873+
73874+int
73875+gr_check_crash_exec(const struct file *filp)
73876+{
73877+ return 0;
73878+}
73879+
73880+int
73881+gr_check_crash_uid(const kuid_t uid)
73882+{
73883+ return 0;
73884+}
73885+
73886+void
73887+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73888+ struct dentry *old_dentry,
73889+ struct dentry *new_dentry,
73890+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
73891+{
73892+ return;
73893+}
73894+
73895+int
73896+gr_search_socket(const int family, const int type, const int protocol)
73897+{
73898+ return 1;
73899+}
73900+
73901+int
73902+gr_search_connectbind(const int mode, const struct socket *sock,
73903+ const struct sockaddr_in *addr)
73904+{
73905+ return 0;
73906+}
73907+
73908+void
73909+gr_handle_alertkill(struct task_struct *task)
73910+{
73911+ return;
73912+}
73913+
73914+__u32
73915+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73916+{
73917+ return 1;
73918+}
73919+
73920+__u32
73921+gr_acl_handle_hidden_file(const struct dentry * dentry,
73922+ const struct vfsmount * mnt)
73923+{
73924+ return 1;
73925+}
73926+
73927+__u32
73928+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73929+ int acc_mode)
73930+{
73931+ return 1;
73932+}
73933+
73934+__u32
73935+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73936+{
73937+ return 1;
73938+}
73939+
73940+__u32
73941+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73942+{
73943+ return 1;
73944+}
73945+
73946+int
73947+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73948+ unsigned int *vm_flags)
73949+{
73950+ return 1;
73951+}
73952+
73953+__u32
73954+gr_acl_handle_truncate(const struct dentry * dentry,
73955+ const struct vfsmount * mnt)
73956+{
73957+ return 1;
73958+}
73959+
73960+__u32
73961+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73962+{
73963+ return 1;
73964+}
73965+
73966+__u32
73967+gr_acl_handle_access(const struct dentry * dentry,
73968+ const struct vfsmount * mnt, const int fmode)
73969+{
73970+ return 1;
73971+}
73972+
73973+__u32
73974+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73975+ umode_t *mode)
73976+{
73977+ return 1;
73978+}
73979+
73980+__u32
73981+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73982+{
73983+ return 1;
73984+}
73985+
73986+__u32
73987+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73988+{
73989+ return 1;
73990+}
73991+
73992+__u32
73993+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73994+{
73995+ return 1;
73996+}
73997+
73998+void
73999+grsecurity_init(void)
74000+{
74001+ return;
74002+}
74003+
74004+umode_t gr_acl_umask(void)
74005+{
74006+ return 0;
74007+}
74008+
74009+__u32
74010+gr_acl_handle_mknod(const struct dentry * new_dentry,
74011+ const struct dentry * parent_dentry,
74012+ const struct vfsmount * parent_mnt,
74013+ const int mode)
74014+{
74015+ return 1;
74016+}
74017+
74018+__u32
74019+gr_acl_handle_mkdir(const struct dentry * new_dentry,
74020+ const struct dentry * parent_dentry,
74021+ const struct vfsmount * parent_mnt)
74022+{
74023+ return 1;
74024+}
74025+
74026+__u32
74027+gr_acl_handle_symlink(const struct dentry * new_dentry,
74028+ const struct dentry * parent_dentry,
74029+ const struct vfsmount * parent_mnt, const struct filename *from)
74030+{
74031+ return 1;
74032+}
74033+
74034+__u32
74035+gr_acl_handle_link(const struct dentry * new_dentry,
74036+ const struct dentry * parent_dentry,
74037+ const struct vfsmount * parent_mnt,
74038+ const struct dentry * old_dentry,
74039+ const struct vfsmount * old_mnt, const struct filename *to)
74040+{
74041+ return 1;
74042+}
74043+
74044+int
74045+gr_acl_handle_rename(const struct dentry *new_dentry,
74046+ const struct dentry *parent_dentry,
74047+ const struct vfsmount *parent_mnt,
74048+ const struct dentry *old_dentry,
74049+ const struct inode *old_parent_inode,
74050+ const struct vfsmount *old_mnt, const struct filename *newname,
74051+ unsigned int flags)
74052+{
74053+ return 0;
74054+}
74055+
74056+int
74057+gr_acl_handle_filldir(const struct file *file, const char *name,
74058+ const int namelen, const ino_t ino)
74059+{
74060+ return 1;
74061+}
74062+
74063+int
74064+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74065+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74066+{
74067+ return 1;
74068+}
74069+
74070+int
74071+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74072+{
74073+ return 0;
74074+}
74075+
74076+int
74077+gr_search_accept(const struct socket *sock)
74078+{
74079+ return 0;
74080+}
74081+
74082+int
74083+gr_search_listen(const struct socket *sock)
74084+{
74085+ return 0;
74086+}
74087+
74088+int
74089+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74090+{
74091+ return 0;
74092+}
74093+
74094+__u32
74095+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74096+{
74097+ return 1;
74098+}
74099+
74100+__u32
74101+gr_acl_handle_creat(const struct dentry * dentry,
74102+ const struct dentry * p_dentry,
74103+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74104+ const int imode)
74105+{
74106+ return 1;
74107+}
74108+
74109+void
74110+gr_acl_handle_exit(void)
74111+{
74112+ return;
74113+}
74114+
74115+int
74116+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74117+{
74118+ return 1;
74119+}
74120+
74121+void
74122+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74123+{
74124+ return;
74125+}
74126+
74127+int
74128+gr_acl_handle_procpidmem(const struct task_struct *task)
74129+{
74130+ return 0;
74131+}
74132+
74133+int
74134+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74135+{
74136+ return 0;
74137+}
74138+
74139+int
74140+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74141+{
74142+ return 0;
74143+}
74144+
74145+int
74146+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74147+{
74148+ return 0;
74149+}
74150+
74151+int
74152+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74153+{
74154+ return 0;
74155+}
74156+
74157+int gr_acl_enable_at_secure(void)
74158+{
74159+ return 0;
74160+}
74161+
74162+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74163+{
74164+ return dentry->d_sb->s_dev;
74165+}
74166+
74167+void gr_put_exec_file(struct task_struct *task)
74168+{
74169+ return;
74170+}
74171+
74172+#ifdef CONFIG_SECURITY
74173+EXPORT_SYMBOL_GPL(gr_check_user_change);
74174+EXPORT_SYMBOL_GPL(gr_check_group_change);
74175+#endif
74176diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74177new file mode 100644
74178index 0000000..f35f454
74179--- /dev/null
74180+++ b/grsecurity/grsec_exec.c
74181@@ -0,0 +1,187 @@
74182+#include <linux/kernel.h>
74183+#include <linux/sched.h>
74184+#include <linux/file.h>
74185+#include <linux/binfmts.h>
74186+#include <linux/fs.h>
74187+#include <linux/types.h>
74188+#include <linux/grdefs.h>
74189+#include <linux/grsecurity.h>
74190+#include <linux/grinternal.h>
74191+#include <linux/capability.h>
74192+#include <linux/module.h>
74193+#include <linux/compat.h>
74194+
74195+#include <asm/uaccess.h>
74196+
74197+#ifdef CONFIG_GRKERNSEC_EXECLOG
74198+static char gr_exec_arg_buf[132];
74199+static DEFINE_MUTEX(gr_exec_arg_mutex);
74200+#endif
74201+
74202+struct user_arg_ptr {
74203+#ifdef CONFIG_COMPAT
74204+ bool is_compat;
74205+#endif
74206+ union {
74207+ const char __user *const __user *native;
74208+#ifdef CONFIG_COMPAT
74209+ const compat_uptr_t __user *compat;
74210+#endif
74211+ } ptr;
74212+};
74213+
74214+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74215+
74216+void
74217+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74218+{
74219+#ifdef CONFIG_GRKERNSEC_EXECLOG
74220+ char *grarg = gr_exec_arg_buf;
74221+ unsigned int i, x, execlen = 0;
74222+ char c;
74223+
74224+ if (!((grsec_enable_execlog && grsec_enable_group &&
74225+ in_group_p(grsec_audit_gid))
74226+ || (grsec_enable_execlog && !grsec_enable_group)))
74227+ return;
74228+
74229+ mutex_lock(&gr_exec_arg_mutex);
74230+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74231+
74232+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74233+ const char __user *p;
74234+ unsigned int len;
74235+
74236+ p = get_user_arg_ptr(argv, i);
74237+ if (IS_ERR(p))
74238+ goto log;
74239+
74240+ len = strnlen_user(p, 128 - execlen);
74241+ if (len > 128 - execlen)
74242+ len = 128 - execlen;
74243+ else if (len > 0)
74244+ len--;
74245+ if (copy_from_user(grarg + execlen, p, len))
74246+ goto log;
74247+
74248+ /* rewrite unprintable characters */
74249+ for (x = 0; x < len; x++) {
74250+ c = *(grarg + execlen + x);
74251+ if (c < 32 || c > 126)
74252+ *(grarg + execlen + x) = ' ';
74253+ }
74254+
74255+ execlen += len;
74256+ *(grarg + execlen) = ' ';
74257+ *(grarg + execlen + 1) = '\0';
74258+ execlen++;
74259+ }
74260+
74261+ log:
74262+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74263+ bprm->file->f_path.mnt, grarg);
74264+ mutex_unlock(&gr_exec_arg_mutex);
74265+#endif
74266+ return;
74267+}
74268+
74269+#ifdef CONFIG_GRKERNSEC
74270+extern int gr_acl_is_capable(const int cap);
74271+extern int gr_acl_is_capable_nolog(const int cap);
74272+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74273+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74274+extern int gr_chroot_is_capable(const int cap);
74275+extern int gr_chroot_is_capable_nolog(const int cap);
74276+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74277+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74278+#endif
74279+
74280+const char *captab_log[] = {
74281+ "CAP_CHOWN",
74282+ "CAP_DAC_OVERRIDE",
74283+ "CAP_DAC_READ_SEARCH",
74284+ "CAP_FOWNER",
74285+ "CAP_FSETID",
74286+ "CAP_KILL",
74287+ "CAP_SETGID",
74288+ "CAP_SETUID",
74289+ "CAP_SETPCAP",
74290+ "CAP_LINUX_IMMUTABLE",
74291+ "CAP_NET_BIND_SERVICE",
74292+ "CAP_NET_BROADCAST",
74293+ "CAP_NET_ADMIN",
74294+ "CAP_NET_RAW",
74295+ "CAP_IPC_LOCK",
74296+ "CAP_IPC_OWNER",
74297+ "CAP_SYS_MODULE",
74298+ "CAP_SYS_RAWIO",
74299+ "CAP_SYS_CHROOT",
74300+ "CAP_SYS_PTRACE",
74301+ "CAP_SYS_PACCT",
74302+ "CAP_SYS_ADMIN",
74303+ "CAP_SYS_BOOT",
74304+ "CAP_SYS_NICE",
74305+ "CAP_SYS_RESOURCE",
74306+ "CAP_SYS_TIME",
74307+ "CAP_SYS_TTY_CONFIG",
74308+ "CAP_MKNOD",
74309+ "CAP_LEASE",
74310+ "CAP_AUDIT_WRITE",
74311+ "CAP_AUDIT_CONTROL",
74312+ "CAP_SETFCAP",
74313+ "CAP_MAC_OVERRIDE",
74314+ "CAP_MAC_ADMIN",
74315+ "CAP_SYSLOG",
74316+ "CAP_WAKE_ALARM"
74317+};
74318+
74319+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74320+
74321+int gr_is_capable(const int cap)
74322+{
74323+#ifdef CONFIG_GRKERNSEC
74324+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74325+ return 1;
74326+ return 0;
74327+#else
74328+ return 1;
74329+#endif
74330+}
74331+
74332+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74333+{
74334+#ifdef CONFIG_GRKERNSEC
74335+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74336+ return 1;
74337+ return 0;
74338+#else
74339+ return 1;
74340+#endif
74341+}
74342+
74343+int gr_is_capable_nolog(const int cap)
74344+{
74345+#ifdef CONFIG_GRKERNSEC
74346+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74347+ return 1;
74348+ return 0;
74349+#else
74350+ return 1;
74351+#endif
74352+}
74353+
74354+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74355+{
74356+#ifdef CONFIG_GRKERNSEC
74357+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74358+ return 1;
74359+ return 0;
74360+#else
74361+ return 1;
74362+#endif
74363+}
74364+
74365+EXPORT_SYMBOL_GPL(gr_is_capable);
74366+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74367+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74368+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74369diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74370new file mode 100644
74371index 0000000..06cc6ea
74372--- /dev/null
74373+++ b/grsecurity/grsec_fifo.c
74374@@ -0,0 +1,24 @@
74375+#include <linux/kernel.h>
74376+#include <linux/sched.h>
74377+#include <linux/fs.h>
74378+#include <linux/file.h>
74379+#include <linux/grinternal.h>
74380+
74381+int
74382+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74383+ const struct dentry *dir, const int flag, const int acc_mode)
74384+{
74385+#ifdef CONFIG_GRKERNSEC_FIFO
74386+ const struct cred *cred = current_cred();
74387+
74388+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74389+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74390+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74391+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74392+ if (!inode_permission(dentry->d_inode, acc_mode))
74393+ 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));
74394+ return -EACCES;
74395+ }
74396+#endif
74397+ return 0;
74398+}
74399diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74400new file mode 100644
74401index 0000000..8ca18bf
74402--- /dev/null
74403+++ b/grsecurity/grsec_fork.c
74404@@ -0,0 +1,23 @@
74405+#include <linux/kernel.h>
74406+#include <linux/sched.h>
74407+#include <linux/grsecurity.h>
74408+#include <linux/grinternal.h>
74409+#include <linux/errno.h>
74410+
74411+void
74412+gr_log_forkfail(const int retval)
74413+{
74414+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74415+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74416+ switch (retval) {
74417+ case -EAGAIN:
74418+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74419+ break;
74420+ case -ENOMEM:
74421+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74422+ break;
74423+ }
74424+ }
74425+#endif
74426+ return;
74427+}
74428diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74429new file mode 100644
74430index 0000000..ae6c028
74431--- /dev/null
74432+++ b/grsecurity/grsec_init.c
74433@@ -0,0 +1,272 @@
74434+#include <linux/kernel.h>
74435+#include <linux/sched.h>
74436+#include <linux/mm.h>
74437+#include <linux/gracl.h>
74438+#include <linux/slab.h>
74439+#include <linux/vmalloc.h>
74440+#include <linux/percpu.h>
74441+#include <linux/module.h>
74442+
74443+int grsec_enable_ptrace_readexec;
74444+int grsec_enable_setxid;
74445+int grsec_enable_symlinkown;
74446+kgid_t grsec_symlinkown_gid;
74447+int grsec_enable_brute;
74448+int grsec_enable_link;
74449+int grsec_enable_dmesg;
74450+int grsec_enable_harden_ptrace;
74451+int grsec_enable_harden_ipc;
74452+int grsec_enable_fifo;
74453+int grsec_enable_execlog;
74454+int grsec_enable_signal;
74455+int grsec_enable_forkfail;
74456+int grsec_enable_audit_ptrace;
74457+int grsec_enable_time;
74458+int grsec_enable_group;
74459+kgid_t grsec_audit_gid;
74460+int grsec_enable_chdir;
74461+int grsec_enable_mount;
74462+int grsec_enable_rofs;
74463+int grsec_deny_new_usb;
74464+int grsec_enable_chroot_findtask;
74465+int grsec_enable_chroot_mount;
74466+int grsec_enable_chroot_shmat;
74467+int grsec_enable_chroot_fchdir;
74468+int grsec_enable_chroot_double;
74469+int grsec_enable_chroot_pivot;
74470+int grsec_enable_chroot_chdir;
74471+int grsec_enable_chroot_chmod;
74472+int grsec_enable_chroot_mknod;
74473+int grsec_enable_chroot_nice;
74474+int grsec_enable_chroot_execlog;
74475+int grsec_enable_chroot_caps;
74476+int grsec_enable_chroot_sysctl;
74477+int grsec_enable_chroot_unix;
74478+int grsec_enable_tpe;
74479+kgid_t grsec_tpe_gid;
74480+int grsec_enable_blackhole;
74481+#ifdef CONFIG_IPV6_MODULE
74482+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74483+#endif
74484+int grsec_lastack_retries;
74485+int grsec_enable_tpe_all;
74486+int grsec_enable_tpe_invert;
74487+int grsec_enable_socket_all;
74488+kgid_t grsec_socket_all_gid;
74489+int grsec_enable_socket_client;
74490+kgid_t grsec_socket_client_gid;
74491+int grsec_enable_socket_server;
74492+kgid_t grsec_socket_server_gid;
74493+int grsec_resource_logging;
74494+int grsec_disable_privio;
74495+int grsec_enable_log_rwxmaps;
74496+int grsec_lock;
74497+
74498+DEFINE_SPINLOCK(grsec_alert_lock);
74499+unsigned long grsec_alert_wtime = 0;
74500+unsigned long grsec_alert_fyet = 0;
74501+
74502+DEFINE_SPINLOCK(grsec_audit_lock);
74503+
74504+DEFINE_RWLOCK(grsec_exec_file_lock);
74505+
74506+char *gr_shared_page[4];
74507+
74508+char *gr_alert_log_fmt;
74509+char *gr_audit_log_fmt;
74510+char *gr_alert_log_buf;
74511+char *gr_audit_log_buf;
74512+
74513+void __init
74514+grsecurity_init(void)
74515+{
74516+ int j;
74517+ /* create the per-cpu shared pages */
74518+
74519+#ifdef CONFIG_X86
74520+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74521+#endif
74522+
74523+ for (j = 0; j < 4; j++) {
74524+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74525+ if (gr_shared_page[j] == NULL) {
74526+ panic("Unable to allocate grsecurity shared page");
74527+ return;
74528+ }
74529+ }
74530+
74531+ /* allocate log buffers */
74532+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74533+ if (!gr_alert_log_fmt) {
74534+ panic("Unable to allocate grsecurity alert log format buffer");
74535+ return;
74536+ }
74537+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74538+ if (!gr_audit_log_fmt) {
74539+ panic("Unable to allocate grsecurity audit log format buffer");
74540+ return;
74541+ }
74542+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74543+ if (!gr_alert_log_buf) {
74544+ panic("Unable to allocate grsecurity alert log buffer");
74545+ return;
74546+ }
74547+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74548+ if (!gr_audit_log_buf) {
74549+ panic("Unable to allocate grsecurity audit log buffer");
74550+ return;
74551+ }
74552+
74553+#ifdef CONFIG_GRKERNSEC_IO
74554+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74555+ grsec_disable_privio = 1;
74556+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74557+ grsec_disable_privio = 1;
74558+#else
74559+ grsec_disable_privio = 0;
74560+#endif
74561+#endif
74562+
74563+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74564+ /* for backward compatibility, tpe_invert always defaults to on if
74565+ enabled in the kernel
74566+ */
74567+ grsec_enable_tpe_invert = 1;
74568+#endif
74569+
74570+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74571+#ifndef CONFIG_GRKERNSEC_SYSCTL
74572+ grsec_lock = 1;
74573+#endif
74574+
74575+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74576+ grsec_enable_log_rwxmaps = 1;
74577+#endif
74578+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74579+ grsec_enable_group = 1;
74580+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74581+#endif
74582+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74583+ grsec_enable_ptrace_readexec = 1;
74584+#endif
74585+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74586+ grsec_enable_chdir = 1;
74587+#endif
74588+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74589+ grsec_enable_harden_ptrace = 1;
74590+#endif
74591+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74592+ grsec_enable_harden_ipc = 1;
74593+#endif
74594+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74595+ grsec_enable_mount = 1;
74596+#endif
74597+#ifdef CONFIG_GRKERNSEC_LINK
74598+ grsec_enable_link = 1;
74599+#endif
74600+#ifdef CONFIG_GRKERNSEC_BRUTE
74601+ grsec_enable_brute = 1;
74602+#endif
74603+#ifdef CONFIG_GRKERNSEC_DMESG
74604+ grsec_enable_dmesg = 1;
74605+#endif
74606+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74607+ grsec_enable_blackhole = 1;
74608+ grsec_lastack_retries = 4;
74609+#endif
74610+#ifdef CONFIG_GRKERNSEC_FIFO
74611+ grsec_enable_fifo = 1;
74612+#endif
74613+#ifdef CONFIG_GRKERNSEC_EXECLOG
74614+ grsec_enable_execlog = 1;
74615+#endif
74616+#ifdef CONFIG_GRKERNSEC_SETXID
74617+ grsec_enable_setxid = 1;
74618+#endif
74619+#ifdef CONFIG_GRKERNSEC_SIGNAL
74620+ grsec_enable_signal = 1;
74621+#endif
74622+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74623+ grsec_enable_forkfail = 1;
74624+#endif
74625+#ifdef CONFIG_GRKERNSEC_TIME
74626+ grsec_enable_time = 1;
74627+#endif
74628+#ifdef CONFIG_GRKERNSEC_RESLOG
74629+ grsec_resource_logging = 1;
74630+#endif
74631+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74632+ grsec_enable_chroot_findtask = 1;
74633+#endif
74634+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74635+ grsec_enable_chroot_unix = 1;
74636+#endif
74637+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74638+ grsec_enable_chroot_mount = 1;
74639+#endif
74640+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74641+ grsec_enable_chroot_fchdir = 1;
74642+#endif
74643+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74644+ grsec_enable_chroot_shmat = 1;
74645+#endif
74646+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74647+ grsec_enable_audit_ptrace = 1;
74648+#endif
74649+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74650+ grsec_enable_chroot_double = 1;
74651+#endif
74652+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74653+ grsec_enable_chroot_pivot = 1;
74654+#endif
74655+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74656+ grsec_enable_chroot_chdir = 1;
74657+#endif
74658+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74659+ grsec_enable_chroot_chmod = 1;
74660+#endif
74661+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74662+ grsec_enable_chroot_mknod = 1;
74663+#endif
74664+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74665+ grsec_enable_chroot_nice = 1;
74666+#endif
74667+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74668+ grsec_enable_chroot_execlog = 1;
74669+#endif
74670+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74671+ grsec_enable_chroot_caps = 1;
74672+#endif
74673+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74674+ grsec_enable_chroot_sysctl = 1;
74675+#endif
74676+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74677+ grsec_enable_symlinkown = 1;
74678+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74679+#endif
74680+#ifdef CONFIG_GRKERNSEC_TPE
74681+ grsec_enable_tpe = 1;
74682+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74683+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74684+ grsec_enable_tpe_all = 1;
74685+#endif
74686+#endif
74687+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74688+ grsec_enable_socket_all = 1;
74689+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74690+#endif
74691+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74692+ grsec_enable_socket_client = 1;
74693+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74694+#endif
74695+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74696+ grsec_enable_socket_server = 1;
74697+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74698+#endif
74699+#endif
74700+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74701+ grsec_deny_new_usb = 1;
74702+#endif
74703+
74704+ return;
74705+}
74706diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74707new file mode 100644
74708index 0000000..1773300
74709--- /dev/null
74710+++ b/grsecurity/grsec_ipc.c
74711@@ -0,0 +1,48 @@
74712+#include <linux/kernel.h>
74713+#include <linux/mm.h>
74714+#include <linux/sched.h>
74715+#include <linux/file.h>
74716+#include <linux/ipc.h>
74717+#include <linux/ipc_namespace.h>
74718+#include <linux/grsecurity.h>
74719+#include <linux/grinternal.h>
74720+
74721+int
74722+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74723+{
74724+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74725+ int write;
74726+ int orig_granted_mode;
74727+ kuid_t euid;
74728+ kgid_t egid;
74729+
74730+ if (!grsec_enable_harden_ipc)
74731+ return 1;
74732+
74733+ euid = current_euid();
74734+ egid = current_egid();
74735+
74736+ write = requested_mode & 00002;
74737+ orig_granted_mode = ipcp->mode;
74738+
74739+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74740+ orig_granted_mode >>= 6;
74741+ else {
74742+ /* if likely wrong permissions, lock to user */
74743+ if (orig_granted_mode & 0007)
74744+ orig_granted_mode = 0;
74745+ /* otherwise do a egid-only check */
74746+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74747+ orig_granted_mode >>= 3;
74748+ /* otherwise, no access */
74749+ else
74750+ orig_granted_mode = 0;
74751+ }
74752+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74753+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74754+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74755+ return 0;
74756+ }
74757+#endif
74758+ return 1;
74759+}
74760diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74761new file mode 100644
74762index 0000000..5e05e20
74763--- /dev/null
74764+++ b/grsecurity/grsec_link.c
74765@@ -0,0 +1,58 @@
74766+#include <linux/kernel.h>
74767+#include <linux/sched.h>
74768+#include <linux/fs.h>
74769+#include <linux/file.h>
74770+#include <linux/grinternal.h>
74771+
74772+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74773+{
74774+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74775+ const struct inode *link_inode = link->dentry->d_inode;
74776+
74777+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74778+ /* ignore root-owned links, e.g. /proc/self */
74779+ gr_is_global_nonroot(link_inode->i_uid) && target &&
74780+ !uid_eq(link_inode->i_uid, target->i_uid)) {
74781+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74782+ return 1;
74783+ }
74784+#endif
74785+ return 0;
74786+}
74787+
74788+int
74789+gr_handle_follow_link(const struct inode *parent,
74790+ const struct inode *inode,
74791+ const struct dentry *dentry, const struct vfsmount *mnt)
74792+{
74793+#ifdef CONFIG_GRKERNSEC_LINK
74794+ const struct cred *cred = current_cred();
74795+
74796+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74797+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74798+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74799+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74800+ return -EACCES;
74801+ }
74802+#endif
74803+ return 0;
74804+}
74805+
74806+int
74807+gr_handle_hardlink(const struct dentry *dentry,
74808+ const struct vfsmount *mnt,
74809+ struct inode *inode, const int mode, const struct filename *to)
74810+{
74811+#ifdef CONFIG_GRKERNSEC_LINK
74812+ const struct cred *cred = current_cred();
74813+
74814+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74815+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74816+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74817+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74818+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74819+ return -EPERM;
74820+ }
74821+#endif
74822+ return 0;
74823+}
74824diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74825new file mode 100644
74826index 0000000..dbe0a6b
74827--- /dev/null
74828+++ b/grsecurity/grsec_log.c
74829@@ -0,0 +1,341 @@
74830+#include <linux/kernel.h>
74831+#include <linux/sched.h>
74832+#include <linux/file.h>
74833+#include <linux/tty.h>
74834+#include <linux/fs.h>
74835+#include <linux/mm.h>
74836+#include <linux/grinternal.h>
74837+
74838+#ifdef CONFIG_TREE_PREEMPT_RCU
74839+#define DISABLE_PREEMPT() preempt_disable()
74840+#define ENABLE_PREEMPT() preempt_enable()
74841+#else
74842+#define DISABLE_PREEMPT()
74843+#define ENABLE_PREEMPT()
74844+#endif
74845+
74846+#define BEGIN_LOCKS(x) \
74847+ DISABLE_PREEMPT(); \
74848+ rcu_read_lock(); \
74849+ read_lock(&tasklist_lock); \
74850+ read_lock(&grsec_exec_file_lock); \
74851+ if (x != GR_DO_AUDIT) \
74852+ spin_lock(&grsec_alert_lock); \
74853+ else \
74854+ spin_lock(&grsec_audit_lock)
74855+
74856+#define END_LOCKS(x) \
74857+ if (x != GR_DO_AUDIT) \
74858+ spin_unlock(&grsec_alert_lock); \
74859+ else \
74860+ spin_unlock(&grsec_audit_lock); \
74861+ read_unlock(&grsec_exec_file_lock); \
74862+ read_unlock(&tasklist_lock); \
74863+ rcu_read_unlock(); \
74864+ ENABLE_PREEMPT(); \
74865+ if (x == GR_DONT_AUDIT) \
74866+ gr_handle_alertkill(current)
74867+
74868+enum {
74869+ FLOODING,
74870+ NO_FLOODING
74871+};
74872+
74873+extern char *gr_alert_log_fmt;
74874+extern char *gr_audit_log_fmt;
74875+extern char *gr_alert_log_buf;
74876+extern char *gr_audit_log_buf;
74877+
74878+static int gr_log_start(int audit)
74879+{
74880+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74881+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74882+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74883+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74884+ unsigned long curr_secs = get_seconds();
74885+
74886+ if (audit == GR_DO_AUDIT)
74887+ goto set_fmt;
74888+
74889+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74890+ grsec_alert_wtime = curr_secs;
74891+ grsec_alert_fyet = 0;
74892+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74893+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74894+ grsec_alert_fyet++;
74895+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74896+ grsec_alert_wtime = curr_secs;
74897+ grsec_alert_fyet++;
74898+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74899+ return FLOODING;
74900+ }
74901+ else return FLOODING;
74902+
74903+set_fmt:
74904+#endif
74905+ memset(buf, 0, PAGE_SIZE);
74906+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
74907+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74908+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74909+ } else if (current->signal->curr_ip) {
74910+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74911+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74912+ } else if (gr_acl_is_enabled()) {
74913+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74914+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74915+ } else {
74916+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
74917+ strcpy(buf, fmt);
74918+ }
74919+
74920+ return NO_FLOODING;
74921+}
74922+
74923+static void gr_log_middle(int audit, const char *msg, va_list ap)
74924+ __attribute__ ((format (printf, 2, 0)));
74925+
74926+static void gr_log_middle(int audit, const char *msg, va_list ap)
74927+{
74928+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74929+ unsigned int len = strlen(buf);
74930+
74931+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74932+
74933+ return;
74934+}
74935+
74936+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74937+ __attribute__ ((format (printf, 2, 3)));
74938+
74939+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74940+{
74941+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74942+ unsigned int len = strlen(buf);
74943+ va_list ap;
74944+
74945+ va_start(ap, msg);
74946+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74947+ va_end(ap);
74948+
74949+ return;
74950+}
74951+
74952+static void gr_log_end(int audit, int append_default)
74953+{
74954+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74955+ if (append_default) {
74956+ struct task_struct *task = current;
74957+ struct task_struct *parent = task->real_parent;
74958+ const struct cred *cred = __task_cred(task);
74959+ const struct cred *pcred = __task_cred(parent);
74960+ unsigned int len = strlen(buf);
74961+
74962+ 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));
74963+ }
74964+
74965+ printk("%s\n", buf);
74966+
74967+ return;
74968+}
74969+
74970+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74971+{
74972+ int logtype;
74973+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74974+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74975+ void *voidptr = NULL;
74976+ int num1 = 0, num2 = 0;
74977+ unsigned long ulong1 = 0, ulong2 = 0;
74978+ struct dentry *dentry = NULL;
74979+ struct vfsmount *mnt = NULL;
74980+ struct file *file = NULL;
74981+ struct task_struct *task = NULL;
74982+ struct vm_area_struct *vma = NULL;
74983+ const struct cred *cred, *pcred;
74984+ va_list ap;
74985+
74986+ BEGIN_LOCKS(audit);
74987+ logtype = gr_log_start(audit);
74988+ if (logtype == FLOODING) {
74989+ END_LOCKS(audit);
74990+ return;
74991+ }
74992+ va_start(ap, argtypes);
74993+ switch (argtypes) {
74994+ case GR_TTYSNIFF:
74995+ task = va_arg(ap, struct task_struct *);
74996+ 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));
74997+ break;
74998+ case GR_SYSCTL_HIDDEN:
74999+ str1 = va_arg(ap, char *);
75000+ gr_log_middle_varargs(audit, msg, result, str1);
75001+ break;
75002+ case GR_RBAC:
75003+ dentry = va_arg(ap, struct dentry *);
75004+ mnt = va_arg(ap, struct vfsmount *);
75005+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75006+ break;
75007+ case GR_RBAC_STR:
75008+ dentry = va_arg(ap, struct dentry *);
75009+ mnt = va_arg(ap, struct vfsmount *);
75010+ str1 = va_arg(ap, char *);
75011+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75012+ break;
75013+ case GR_STR_RBAC:
75014+ str1 = va_arg(ap, char *);
75015+ dentry = va_arg(ap, struct dentry *);
75016+ mnt = va_arg(ap, struct vfsmount *);
75017+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75018+ break;
75019+ case GR_RBAC_MODE2:
75020+ dentry = va_arg(ap, struct dentry *);
75021+ mnt = va_arg(ap, struct vfsmount *);
75022+ str1 = va_arg(ap, char *);
75023+ str2 = va_arg(ap, char *);
75024+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75025+ break;
75026+ case GR_RBAC_MODE3:
75027+ dentry = va_arg(ap, struct dentry *);
75028+ mnt = va_arg(ap, struct vfsmount *);
75029+ str1 = va_arg(ap, char *);
75030+ str2 = va_arg(ap, char *);
75031+ str3 = va_arg(ap, char *);
75032+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75033+ break;
75034+ case GR_FILENAME:
75035+ dentry = va_arg(ap, struct dentry *);
75036+ mnt = va_arg(ap, struct vfsmount *);
75037+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75038+ break;
75039+ case GR_STR_FILENAME:
75040+ str1 = va_arg(ap, char *);
75041+ dentry = va_arg(ap, struct dentry *);
75042+ mnt = va_arg(ap, struct vfsmount *);
75043+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75044+ break;
75045+ case GR_FILENAME_STR:
75046+ dentry = va_arg(ap, struct dentry *);
75047+ mnt = va_arg(ap, struct vfsmount *);
75048+ str1 = va_arg(ap, char *);
75049+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75050+ break;
75051+ case GR_FILENAME_TWO_INT:
75052+ dentry = va_arg(ap, struct dentry *);
75053+ mnt = va_arg(ap, struct vfsmount *);
75054+ num1 = va_arg(ap, int);
75055+ num2 = va_arg(ap, int);
75056+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75057+ break;
75058+ case GR_FILENAME_TWO_INT_STR:
75059+ dentry = va_arg(ap, struct dentry *);
75060+ mnt = va_arg(ap, struct vfsmount *);
75061+ num1 = va_arg(ap, int);
75062+ num2 = va_arg(ap, int);
75063+ str1 = va_arg(ap, char *);
75064+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75065+ break;
75066+ case GR_TEXTREL:
75067+ file = va_arg(ap, struct file *);
75068+ ulong1 = va_arg(ap, unsigned long);
75069+ ulong2 = va_arg(ap, unsigned long);
75070+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75071+ break;
75072+ case GR_PTRACE:
75073+ task = va_arg(ap, struct task_struct *);
75074+ 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));
75075+ break;
75076+ case GR_RESOURCE:
75077+ task = va_arg(ap, struct task_struct *);
75078+ cred = __task_cred(task);
75079+ pcred = __task_cred(task->real_parent);
75080+ ulong1 = va_arg(ap, unsigned long);
75081+ str1 = va_arg(ap, char *);
75082+ ulong2 = va_arg(ap, unsigned long);
75083+ 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));
75084+ break;
75085+ case GR_CAP:
75086+ task = va_arg(ap, struct task_struct *);
75087+ cred = __task_cred(task);
75088+ pcred = __task_cred(task->real_parent);
75089+ str1 = va_arg(ap, char *);
75090+ 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));
75091+ break;
75092+ case GR_SIG:
75093+ str1 = va_arg(ap, char *);
75094+ voidptr = va_arg(ap, void *);
75095+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75096+ break;
75097+ case GR_SIG2:
75098+ task = va_arg(ap, struct task_struct *);
75099+ cred = __task_cred(task);
75100+ pcred = __task_cred(task->real_parent);
75101+ num1 = va_arg(ap, int);
75102+ 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));
75103+ break;
75104+ case GR_CRASH1:
75105+ task = va_arg(ap, struct task_struct *);
75106+ cred = __task_cred(task);
75107+ pcred = __task_cred(task->real_parent);
75108+ ulong1 = va_arg(ap, unsigned long);
75109+ 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);
75110+ break;
75111+ case GR_CRASH2:
75112+ task = va_arg(ap, struct task_struct *);
75113+ cred = __task_cred(task);
75114+ pcred = __task_cred(task->real_parent);
75115+ ulong1 = va_arg(ap, unsigned long);
75116+ 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);
75117+ break;
75118+ case GR_RWXMAP:
75119+ file = va_arg(ap, struct file *);
75120+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75121+ break;
75122+ case GR_RWXMAPVMA:
75123+ vma = va_arg(ap, struct vm_area_struct *);
75124+ if (vma->vm_file)
75125+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75126+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75127+ str1 = "<stack>";
75128+ else if (vma->vm_start <= current->mm->brk &&
75129+ vma->vm_end >= current->mm->start_brk)
75130+ str1 = "<heap>";
75131+ else
75132+ str1 = "<anonymous mapping>";
75133+ gr_log_middle_varargs(audit, msg, str1);
75134+ break;
75135+ case GR_PSACCT:
75136+ {
75137+ unsigned int wday, cday;
75138+ __u8 whr, chr;
75139+ __u8 wmin, cmin;
75140+ __u8 wsec, csec;
75141+ char cur_tty[64] = { 0 };
75142+ char parent_tty[64] = { 0 };
75143+
75144+ task = va_arg(ap, struct task_struct *);
75145+ wday = va_arg(ap, unsigned int);
75146+ cday = va_arg(ap, unsigned int);
75147+ whr = va_arg(ap, int);
75148+ chr = va_arg(ap, int);
75149+ wmin = va_arg(ap, int);
75150+ cmin = va_arg(ap, int);
75151+ wsec = va_arg(ap, int);
75152+ csec = va_arg(ap, int);
75153+ ulong1 = va_arg(ap, unsigned long);
75154+ cred = __task_cred(task);
75155+ pcred = __task_cred(task->real_parent);
75156+
75157+ 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));
75158+ }
75159+ break;
75160+ default:
75161+ gr_log_middle(audit, msg, ap);
75162+ }
75163+ va_end(ap);
75164+ // these don't need DEFAULTSECARGS printed on the end
75165+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75166+ gr_log_end(audit, 0);
75167+ else
75168+ gr_log_end(audit, 1);
75169+ END_LOCKS(audit);
75170+}
75171diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75172new file mode 100644
75173index 0000000..0e39d8c
75174--- /dev/null
75175+++ b/grsecurity/grsec_mem.c
75176@@ -0,0 +1,48 @@
75177+#include <linux/kernel.h>
75178+#include <linux/sched.h>
75179+#include <linux/mm.h>
75180+#include <linux/mman.h>
75181+#include <linux/module.h>
75182+#include <linux/grinternal.h>
75183+
75184+void gr_handle_msr_write(void)
75185+{
75186+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75187+ return;
75188+}
75189+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75190+
75191+void
75192+gr_handle_ioperm(void)
75193+{
75194+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75195+ return;
75196+}
75197+
75198+void
75199+gr_handle_iopl(void)
75200+{
75201+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75202+ return;
75203+}
75204+
75205+void
75206+gr_handle_mem_readwrite(u64 from, u64 to)
75207+{
75208+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75209+ return;
75210+}
75211+
75212+void
75213+gr_handle_vm86(void)
75214+{
75215+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75216+ return;
75217+}
75218+
75219+void
75220+gr_log_badprocpid(const char *entry)
75221+{
75222+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75223+ return;
75224+}
75225diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75226new file mode 100644
75227index 0000000..cd9e124
75228--- /dev/null
75229+++ b/grsecurity/grsec_mount.c
75230@@ -0,0 +1,65 @@
75231+#include <linux/kernel.h>
75232+#include <linux/sched.h>
75233+#include <linux/mount.h>
75234+#include <linux/major.h>
75235+#include <linux/grsecurity.h>
75236+#include <linux/grinternal.h>
75237+
75238+void
75239+gr_log_remount(const char *devname, const int retval)
75240+{
75241+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75242+ if (grsec_enable_mount && (retval >= 0))
75243+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75244+#endif
75245+ return;
75246+}
75247+
75248+void
75249+gr_log_unmount(const char *devname, const int retval)
75250+{
75251+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75252+ if (grsec_enable_mount && (retval >= 0))
75253+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75254+#endif
75255+ return;
75256+}
75257+
75258+void
75259+gr_log_mount(const char *from, const char *to, const int retval)
75260+{
75261+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75262+ if (grsec_enable_mount && (retval >= 0))
75263+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75264+#endif
75265+ return;
75266+}
75267+
75268+int
75269+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75270+{
75271+#ifdef CONFIG_GRKERNSEC_ROFS
75272+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75273+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75274+ return -EPERM;
75275+ } else
75276+ return 0;
75277+#endif
75278+ return 0;
75279+}
75280+
75281+int
75282+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75283+{
75284+#ifdef CONFIG_GRKERNSEC_ROFS
75285+ struct inode *inode = dentry->d_inode;
75286+
75287+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75288+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75289+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75290+ return -EPERM;
75291+ } else
75292+ return 0;
75293+#endif
75294+ return 0;
75295+}
75296diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75297new file mode 100644
75298index 0000000..6ee9d50
75299--- /dev/null
75300+++ b/grsecurity/grsec_pax.c
75301@@ -0,0 +1,45 @@
75302+#include <linux/kernel.h>
75303+#include <linux/sched.h>
75304+#include <linux/mm.h>
75305+#include <linux/file.h>
75306+#include <linux/grinternal.h>
75307+#include <linux/grsecurity.h>
75308+
75309+void
75310+gr_log_textrel(struct vm_area_struct * vma)
75311+{
75312+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75313+ if (grsec_enable_log_rwxmaps)
75314+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75315+#endif
75316+ return;
75317+}
75318+
75319+void gr_log_ptgnustack(struct file *file)
75320+{
75321+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75322+ if (grsec_enable_log_rwxmaps)
75323+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75324+#endif
75325+ return;
75326+}
75327+
75328+void
75329+gr_log_rwxmmap(struct file *file)
75330+{
75331+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75332+ if (grsec_enable_log_rwxmaps)
75333+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75334+#endif
75335+ return;
75336+}
75337+
75338+void
75339+gr_log_rwxmprotect(struct vm_area_struct *vma)
75340+{
75341+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75342+ if (grsec_enable_log_rwxmaps)
75343+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75344+#endif
75345+ return;
75346+}
75347diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75348new file mode 100644
75349index 0000000..2005a3a
75350--- /dev/null
75351+++ b/grsecurity/grsec_proc.c
75352@@ -0,0 +1,20 @@
75353+#include <linux/kernel.h>
75354+#include <linux/sched.h>
75355+#include <linux/grsecurity.h>
75356+#include <linux/grinternal.h>
75357+
75358+int gr_proc_is_restricted(void)
75359+{
75360+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75361+ const struct cred *cred = current_cred();
75362+#endif
75363+
75364+#ifdef CONFIG_GRKERNSEC_PROC_USER
75365+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75366+ return -EACCES;
75367+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75368+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75369+ return -EACCES;
75370+#endif
75371+ return 0;
75372+}
75373diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75374new file mode 100644
75375index 0000000..f7f29aa
75376--- /dev/null
75377+++ b/grsecurity/grsec_ptrace.c
75378@@ -0,0 +1,30 @@
75379+#include <linux/kernel.h>
75380+#include <linux/sched.h>
75381+#include <linux/grinternal.h>
75382+#include <linux/security.h>
75383+
75384+void
75385+gr_audit_ptrace(struct task_struct *task)
75386+{
75387+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75388+ if (grsec_enable_audit_ptrace)
75389+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75390+#endif
75391+ return;
75392+}
75393+
75394+int
75395+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75396+{
75397+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75398+ const struct dentry *dentry = file->f_path.dentry;
75399+ const struct vfsmount *mnt = file->f_path.mnt;
75400+
75401+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75402+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75403+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75404+ return -EACCES;
75405+ }
75406+#endif
75407+ return 0;
75408+}
75409diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75410new file mode 100644
75411index 0000000..3860c7e
75412--- /dev/null
75413+++ b/grsecurity/grsec_sig.c
75414@@ -0,0 +1,236 @@
75415+#include <linux/kernel.h>
75416+#include <linux/sched.h>
75417+#include <linux/fs.h>
75418+#include <linux/delay.h>
75419+#include <linux/grsecurity.h>
75420+#include <linux/grinternal.h>
75421+#include <linux/hardirq.h>
75422+
75423+char *signames[] = {
75424+ [SIGSEGV] = "Segmentation fault",
75425+ [SIGILL] = "Illegal instruction",
75426+ [SIGABRT] = "Abort",
75427+ [SIGBUS] = "Invalid alignment/Bus error"
75428+};
75429+
75430+void
75431+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75432+{
75433+#ifdef CONFIG_GRKERNSEC_SIGNAL
75434+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75435+ (sig == SIGABRT) || (sig == SIGBUS))) {
75436+ if (task_pid_nr(t) == task_pid_nr(current)) {
75437+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75438+ } else {
75439+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75440+ }
75441+ }
75442+#endif
75443+ return;
75444+}
75445+
75446+int
75447+gr_handle_signal(const struct task_struct *p, const int sig)
75448+{
75449+#ifdef CONFIG_GRKERNSEC
75450+ /* ignore the 0 signal for protected task checks */
75451+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75452+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75453+ return -EPERM;
75454+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75455+ return -EPERM;
75456+ }
75457+#endif
75458+ return 0;
75459+}
75460+
75461+#ifdef CONFIG_GRKERNSEC
75462+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75463+
75464+int gr_fake_force_sig(int sig, struct task_struct *t)
75465+{
75466+ unsigned long int flags;
75467+ int ret, blocked, ignored;
75468+ struct k_sigaction *action;
75469+
75470+ spin_lock_irqsave(&t->sighand->siglock, flags);
75471+ action = &t->sighand->action[sig-1];
75472+ ignored = action->sa.sa_handler == SIG_IGN;
75473+ blocked = sigismember(&t->blocked, sig);
75474+ if (blocked || ignored) {
75475+ action->sa.sa_handler = SIG_DFL;
75476+ if (blocked) {
75477+ sigdelset(&t->blocked, sig);
75478+ recalc_sigpending_and_wake(t);
75479+ }
75480+ }
75481+ if (action->sa.sa_handler == SIG_DFL)
75482+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75483+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75484+
75485+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75486+
75487+ return ret;
75488+}
75489+#endif
75490+
75491+#define GR_USER_BAN_TIME (15 * 60)
75492+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75493+
75494+void gr_handle_brute_attach(int dumpable)
75495+{
75496+#ifdef CONFIG_GRKERNSEC_BRUTE
75497+ struct task_struct *p = current;
75498+ kuid_t uid = GLOBAL_ROOT_UID;
75499+ int daemon = 0;
75500+
75501+ if (!grsec_enable_brute)
75502+ return;
75503+
75504+ rcu_read_lock();
75505+ read_lock(&tasklist_lock);
75506+ read_lock(&grsec_exec_file_lock);
75507+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75508+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75509+ p->real_parent->brute = 1;
75510+ daemon = 1;
75511+ } else {
75512+ const struct cred *cred = __task_cred(p), *cred2;
75513+ struct task_struct *tsk, *tsk2;
75514+
75515+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75516+ struct user_struct *user;
75517+
75518+ uid = cred->uid;
75519+
75520+ /* this is put upon execution past expiration */
75521+ user = find_user(uid);
75522+ if (user == NULL)
75523+ goto unlock;
75524+ user->suid_banned = 1;
75525+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75526+ if (user->suid_ban_expires == ~0UL)
75527+ user->suid_ban_expires--;
75528+
75529+ /* only kill other threads of the same binary, from the same user */
75530+ do_each_thread(tsk2, tsk) {
75531+ cred2 = __task_cred(tsk);
75532+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75533+ gr_fake_force_sig(SIGKILL, tsk);
75534+ } while_each_thread(tsk2, tsk);
75535+ }
75536+ }
75537+unlock:
75538+ read_unlock(&grsec_exec_file_lock);
75539+ read_unlock(&tasklist_lock);
75540+ rcu_read_unlock();
75541+
75542+ if (gr_is_global_nonroot(uid))
75543+ 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);
75544+ else if (daemon)
75545+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75546+
75547+#endif
75548+ return;
75549+}
75550+
75551+void gr_handle_brute_check(void)
75552+{
75553+#ifdef CONFIG_GRKERNSEC_BRUTE
75554+ struct task_struct *p = current;
75555+
75556+ if (unlikely(p->brute)) {
75557+ if (!grsec_enable_brute)
75558+ p->brute = 0;
75559+ else if (time_before(get_seconds(), p->brute_expires))
75560+ msleep(30 * 1000);
75561+ }
75562+#endif
75563+ return;
75564+}
75565+
75566+void gr_handle_kernel_exploit(void)
75567+{
75568+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75569+ const struct cred *cred;
75570+ struct task_struct *tsk, *tsk2;
75571+ struct user_struct *user;
75572+ kuid_t uid;
75573+
75574+ if (in_irq() || in_serving_softirq() || in_nmi())
75575+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75576+
75577+ uid = current_uid();
75578+
75579+ if (gr_is_global_root(uid))
75580+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75581+ else {
75582+ /* kill all the processes of this user, hold a reference
75583+ to their creds struct, and prevent them from creating
75584+ another process until system reset
75585+ */
75586+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75587+ GR_GLOBAL_UID(uid));
75588+ /* we intentionally leak this ref */
75589+ user = get_uid(current->cred->user);
75590+ if (user)
75591+ user->kernel_banned = 1;
75592+
75593+ /* kill all processes of this user */
75594+ read_lock(&tasklist_lock);
75595+ do_each_thread(tsk2, tsk) {
75596+ cred = __task_cred(tsk);
75597+ if (uid_eq(cred->uid, uid))
75598+ gr_fake_force_sig(SIGKILL, tsk);
75599+ } while_each_thread(tsk2, tsk);
75600+ read_unlock(&tasklist_lock);
75601+ }
75602+#endif
75603+}
75604+
75605+#ifdef CONFIG_GRKERNSEC_BRUTE
75606+static bool suid_ban_expired(struct user_struct *user)
75607+{
75608+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75609+ user->suid_banned = 0;
75610+ user->suid_ban_expires = 0;
75611+ free_uid(user);
75612+ return true;
75613+ }
75614+
75615+ return false;
75616+}
75617+#endif
75618+
75619+int gr_process_kernel_exec_ban(void)
75620+{
75621+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75622+ if (unlikely(current->cred->user->kernel_banned))
75623+ return -EPERM;
75624+#endif
75625+ return 0;
75626+}
75627+
75628+int gr_process_kernel_setuid_ban(struct user_struct *user)
75629+{
75630+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75631+ if (unlikely(user->kernel_banned))
75632+ gr_fake_force_sig(SIGKILL, current);
75633+#endif
75634+ return 0;
75635+}
75636+
75637+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75638+{
75639+#ifdef CONFIG_GRKERNSEC_BRUTE
75640+ struct user_struct *user = current->cred->user;
75641+ if (unlikely(user->suid_banned)) {
75642+ if (suid_ban_expired(user))
75643+ return 0;
75644+ /* disallow execution of suid binaries only */
75645+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75646+ return -EPERM;
75647+ }
75648+#endif
75649+ return 0;
75650+}
75651diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75652new file mode 100644
75653index 0000000..c0aef3a
75654--- /dev/null
75655+++ b/grsecurity/grsec_sock.c
75656@@ -0,0 +1,244 @@
75657+#include <linux/kernel.h>
75658+#include <linux/module.h>
75659+#include <linux/sched.h>
75660+#include <linux/file.h>
75661+#include <linux/net.h>
75662+#include <linux/in.h>
75663+#include <linux/ip.h>
75664+#include <net/sock.h>
75665+#include <net/inet_sock.h>
75666+#include <linux/grsecurity.h>
75667+#include <linux/grinternal.h>
75668+#include <linux/gracl.h>
75669+
75670+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75671+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75672+
75673+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75674+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75675+
75676+#ifdef CONFIG_UNIX_MODULE
75677+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75678+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75679+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75680+EXPORT_SYMBOL_GPL(gr_handle_create);
75681+#endif
75682+
75683+#ifdef CONFIG_GRKERNSEC
75684+#define gr_conn_table_size 32749
75685+struct conn_table_entry {
75686+ struct conn_table_entry *next;
75687+ struct signal_struct *sig;
75688+};
75689+
75690+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75691+DEFINE_SPINLOCK(gr_conn_table_lock);
75692+
75693+extern const char * gr_socktype_to_name(unsigned char type);
75694+extern const char * gr_proto_to_name(unsigned char proto);
75695+extern const char * gr_sockfamily_to_name(unsigned char family);
75696+
75697+static __inline__ int
75698+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75699+{
75700+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75701+}
75702+
75703+static __inline__ int
75704+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75705+ __u16 sport, __u16 dport)
75706+{
75707+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75708+ sig->gr_sport == sport && sig->gr_dport == dport))
75709+ return 1;
75710+ else
75711+ return 0;
75712+}
75713+
75714+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75715+{
75716+ struct conn_table_entry **match;
75717+ unsigned int index;
75718+
75719+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75720+ sig->gr_sport, sig->gr_dport,
75721+ gr_conn_table_size);
75722+
75723+ newent->sig = sig;
75724+
75725+ match = &gr_conn_table[index];
75726+ newent->next = *match;
75727+ *match = newent;
75728+
75729+ return;
75730+}
75731+
75732+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75733+{
75734+ struct conn_table_entry *match, *last = NULL;
75735+ unsigned int index;
75736+
75737+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75738+ sig->gr_sport, sig->gr_dport,
75739+ gr_conn_table_size);
75740+
75741+ match = gr_conn_table[index];
75742+ while (match && !conn_match(match->sig,
75743+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75744+ sig->gr_dport)) {
75745+ last = match;
75746+ match = match->next;
75747+ }
75748+
75749+ if (match) {
75750+ if (last)
75751+ last->next = match->next;
75752+ else
75753+ gr_conn_table[index] = NULL;
75754+ kfree(match);
75755+ }
75756+
75757+ return;
75758+}
75759+
75760+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75761+ __u16 sport, __u16 dport)
75762+{
75763+ struct conn_table_entry *match;
75764+ unsigned int index;
75765+
75766+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75767+
75768+ match = gr_conn_table[index];
75769+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75770+ match = match->next;
75771+
75772+ if (match)
75773+ return match->sig;
75774+ else
75775+ return NULL;
75776+}
75777+
75778+#endif
75779+
75780+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75781+{
75782+#ifdef CONFIG_GRKERNSEC
75783+ struct signal_struct *sig = task->signal;
75784+ struct conn_table_entry *newent;
75785+
75786+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75787+ if (newent == NULL)
75788+ return;
75789+ /* no bh lock needed since we are called with bh disabled */
75790+ spin_lock(&gr_conn_table_lock);
75791+ gr_del_task_from_ip_table_nolock(sig);
75792+ sig->gr_saddr = inet->inet_rcv_saddr;
75793+ sig->gr_daddr = inet->inet_daddr;
75794+ sig->gr_sport = inet->inet_sport;
75795+ sig->gr_dport = inet->inet_dport;
75796+ gr_add_to_task_ip_table_nolock(sig, newent);
75797+ spin_unlock(&gr_conn_table_lock);
75798+#endif
75799+ return;
75800+}
75801+
75802+void gr_del_task_from_ip_table(struct task_struct *task)
75803+{
75804+#ifdef CONFIG_GRKERNSEC
75805+ spin_lock_bh(&gr_conn_table_lock);
75806+ gr_del_task_from_ip_table_nolock(task->signal);
75807+ spin_unlock_bh(&gr_conn_table_lock);
75808+#endif
75809+ return;
75810+}
75811+
75812+void
75813+gr_attach_curr_ip(const struct sock *sk)
75814+{
75815+#ifdef CONFIG_GRKERNSEC
75816+ struct signal_struct *p, *set;
75817+ const struct inet_sock *inet = inet_sk(sk);
75818+
75819+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75820+ return;
75821+
75822+ set = current->signal;
75823+
75824+ spin_lock_bh(&gr_conn_table_lock);
75825+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75826+ inet->inet_dport, inet->inet_sport);
75827+ if (unlikely(p != NULL)) {
75828+ set->curr_ip = p->curr_ip;
75829+ set->used_accept = 1;
75830+ gr_del_task_from_ip_table_nolock(p);
75831+ spin_unlock_bh(&gr_conn_table_lock);
75832+ return;
75833+ }
75834+ spin_unlock_bh(&gr_conn_table_lock);
75835+
75836+ set->curr_ip = inet->inet_daddr;
75837+ set->used_accept = 1;
75838+#endif
75839+ return;
75840+}
75841+
75842+int
75843+gr_handle_sock_all(const int family, const int type, const int protocol)
75844+{
75845+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75846+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75847+ (family != AF_UNIX)) {
75848+ if (family == AF_INET)
75849+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75850+ else
75851+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75852+ return -EACCES;
75853+ }
75854+#endif
75855+ return 0;
75856+}
75857+
75858+int
75859+gr_handle_sock_server(const struct sockaddr *sck)
75860+{
75861+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75862+ if (grsec_enable_socket_server &&
75863+ in_group_p(grsec_socket_server_gid) &&
75864+ sck && (sck->sa_family != AF_UNIX) &&
75865+ (sck->sa_family != AF_LOCAL)) {
75866+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75867+ return -EACCES;
75868+ }
75869+#endif
75870+ return 0;
75871+}
75872+
75873+int
75874+gr_handle_sock_server_other(const struct sock *sck)
75875+{
75876+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75877+ if (grsec_enable_socket_server &&
75878+ in_group_p(grsec_socket_server_gid) &&
75879+ sck && (sck->sk_family != AF_UNIX) &&
75880+ (sck->sk_family != AF_LOCAL)) {
75881+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75882+ return -EACCES;
75883+ }
75884+#endif
75885+ return 0;
75886+}
75887+
75888+int
75889+gr_handle_sock_client(const struct sockaddr *sck)
75890+{
75891+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75892+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75893+ sck && (sck->sa_family != AF_UNIX) &&
75894+ (sck->sa_family != AF_LOCAL)) {
75895+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75896+ return -EACCES;
75897+ }
75898+#endif
75899+ return 0;
75900+}
75901diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75902new file mode 100644
75903index 0000000..8159888
75904--- /dev/null
75905+++ b/grsecurity/grsec_sysctl.c
75906@@ -0,0 +1,479 @@
75907+#include <linux/kernel.h>
75908+#include <linux/sched.h>
75909+#include <linux/sysctl.h>
75910+#include <linux/grsecurity.h>
75911+#include <linux/grinternal.h>
75912+
75913+int
75914+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75915+{
75916+#ifdef CONFIG_GRKERNSEC_SYSCTL
75917+ if (dirname == NULL || name == NULL)
75918+ return 0;
75919+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75920+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75921+ return -EACCES;
75922+ }
75923+#endif
75924+ return 0;
75925+}
75926+
75927+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75928+static int __maybe_unused __read_only one = 1;
75929+#endif
75930+
75931+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75932+ defined(CONFIG_GRKERNSEC_DENYUSB)
75933+struct ctl_table grsecurity_table[] = {
75934+#ifdef CONFIG_GRKERNSEC_SYSCTL
75935+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75936+#ifdef CONFIG_GRKERNSEC_IO
75937+ {
75938+ .procname = "disable_priv_io",
75939+ .data = &grsec_disable_privio,
75940+ .maxlen = sizeof(int),
75941+ .mode = 0600,
75942+ .proc_handler = &proc_dointvec,
75943+ },
75944+#endif
75945+#endif
75946+#ifdef CONFIG_GRKERNSEC_LINK
75947+ {
75948+ .procname = "linking_restrictions",
75949+ .data = &grsec_enable_link,
75950+ .maxlen = sizeof(int),
75951+ .mode = 0600,
75952+ .proc_handler = &proc_dointvec,
75953+ },
75954+#endif
75955+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75956+ {
75957+ .procname = "enforce_symlinksifowner",
75958+ .data = &grsec_enable_symlinkown,
75959+ .maxlen = sizeof(int),
75960+ .mode = 0600,
75961+ .proc_handler = &proc_dointvec,
75962+ },
75963+ {
75964+ .procname = "symlinkown_gid",
75965+ .data = &grsec_symlinkown_gid,
75966+ .maxlen = sizeof(int),
75967+ .mode = 0600,
75968+ .proc_handler = &proc_dointvec,
75969+ },
75970+#endif
75971+#ifdef CONFIG_GRKERNSEC_BRUTE
75972+ {
75973+ .procname = "deter_bruteforce",
75974+ .data = &grsec_enable_brute,
75975+ .maxlen = sizeof(int),
75976+ .mode = 0600,
75977+ .proc_handler = &proc_dointvec,
75978+ },
75979+#endif
75980+#ifdef CONFIG_GRKERNSEC_FIFO
75981+ {
75982+ .procname = "fifo_restrictions",
75983+ .data = &grsec_enable_fifo,
75984+ .maxlen = sizeof(int),
75985+ .mode = 0600,
75986+ .proc_handler = &proc_dointvec,
75987+ },
75988+#endif
75989+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75990+ {
75991+ .procname = "ptrace_readexec",
75992+ .data = &grsec_enable_ptrace_readexec,
75993+ .maxlen = sizeof(int),
75994+ .mode = 0600,
75995+ .proc_handler = &proc_dointvec,
75996+ },
75997+#endif
75998+#ifdef CONFIG_GRKERNSEC_SETXID
75999+ {
76000+ .procname = "consistent_setxid",
76001+ .data = &grsec_enable_setxid,
76002+ .maxlen = sizeof(int),
76003+ .mode = 0600,
76004+ .proc_handler = &proc_dointvec,
76005+ },
76006+#endif
76007+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76008+ {
76009+ .procname = "ip_blackhole",
76010+ .data = &grsec_enable_blackhole,
76011+ .maxlen = sizeof(int),
76012+ .mode = 0600,
76013+ .proc_handler = &proc_dointvec,
76014+ },
76015+ {
76016+ .procname = "lastack_retries",
76017+ .data = &grsec_lastack_retries,
76018+ .maxlen = sizeof(int),
76019+ .mode = 0600,
76020+ .proc_handler = &proc_dointvec,
76021+ },
76022+#endif
76023+#ifdef CONFIG_GRKERNSEC_EXECLOG
76024+ {
76025+ .procname = "exec_logging",
76026+ .data = &grsec_enable_execlog,
76027+ .maxlen = sizeof(int),
76028+ .mode = 0600,
76029+ .proc_handler = &proc_dointvec,
76030+ },
76031+#endif
76032+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76033+ {
76034+ .procname = "rwxmap_logging",
76035+ .data = &grsec_enable_log_rwxmaps,
76036+ .maxlen = sizeof(int),
76037+ .mode = 0600,
76038+ .proc_handler = &proc_dointvec,
76039+ },
76040+#endif
76041+#ifdef CONFIG_GRKERNSEC_SIGNAL
76042+ {
76043+ .procname = "signal_logging",
76044+ .data = &grsec_enable_signal,
76045+ .maxlen = sizeof(int),
76046+ .mode = 0600,
76047+ .proc_handler = &proc_dointvec,
76048+ },
76049+#endif
76050+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76051+ {
76052+ .procname = "forkfail_logging",
76053+ .data = &grsec_enable_forkfail,
76054+ .maxlen = sizeof(int),
76055+ .mode = 0600,
76056+ .proc_handler = &proc_dointvec,
76057+ },
76058+#endif
76059+#ifdef CONFIG_GRKERNSEC_TIME
76060+ {
76061+ .procname = "timechange_logging",
76062+ .data = &grsec_enable_time,
76063+ .maxlen = sizeof(int),
76064+ .mode = 0600,
76065+ .proc_handler = &proc_dointvec,
76066+ },
76067+#endif
76068+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76069+ {
76070+ .procname = "chroot_deny_shmat",
76071+ .data = &grsec_enable_chroot_shmat,
76072+ .maxlen = sizeof(int),
76073+ .mode = 0600,
76074+ .proc_handler = &proc_dointvec,
76075+ },
76076+#endif
76077+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76078+ {
76079+ .procname = "chroot_deny_unix",
76080+ .data = &grsec_enable_chroot_unix,
76081+ .maxlen = sizeof(int),
76082+ .mode = 0600,
76083+ .proc_handler = &proc_dointvec,
76084+ },
76085+#endif
76086+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76087+ {
76088+ .procname = "chroot_deny_mount",
76089+ .data = &grsec_enable_chroot_mount,
76090+ .maxlen = sizeof(int),
76091+ .mode = 0600,
76092+ .proc_handler = &proc_dointvec,
76093+ },
76094+#endif
76095+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76096+ {
76097+ .procname = "chroot_deny_fchdir",
76098+ .data = &grsec_enable_chroot_fchdir,
76099+ .maxlen = sizeof(int),
76100+ .mode = 0600,
76101+ .proc_handler = &proc_dointvec,
76102+ },
76103+#endif
76104+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76105+ {
76106+ .procname = "chroot_deny_chroot",
76107+ .data = &grsec_enable_chroot_double,
76108+ .maxlen = sizeof(int),
76109+ .mode = 0600,
76110+ .proc_handler = &proc_dointvec,
76111+ },
76112+#endif
76113+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76114+ {
76115+ .procname = "chroot_deny_pivot",
76116+ .data = &grsec_enable_chroot_pivot,
76117+ .maxlen = sizeof(int),
76118+ .mode = 0600,
76119+ .proc_handler = &proc_dointvec,
76120+ },
76121+#endif
76122+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76123+ {
76124+ .procname = "chroot_enforce_chdir",
76125+ .data = &grsec_enable_chroot_chdir,
76126+ .maxlen = sizeof(int),
76127+ .mode = 0600,
76128+ .proc_handler = &proc_dointvec,
76129+ },
76130+#endif
76131+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76132+ {
76133+ .procname = "chroot_deny_chmod",
76134+ .data = &grsec_enable_chroot_chmod,
76135+ .maxlen = sizeof(int),
76136+ .mode = 0600,
76137+ .proc_handler = &proc_dointvec,
76138+ },
76139+#endif
76140+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76141+ {
76142+ .procname = "chroot_deny_mknod",
76143+ .data = &grsec_enable_chroot_mknod,
76144+ .maxlen = sizeof(int),
76145+ .mode = 0600,
76146+ .proc_handler = &proc_dointvec,
76147+ },
76148+#endif
76149+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76150+ {
76151+ .procname = "chroot_restrict_nice",
76152+ .data = &grsec_enable_chroot_nice,
76153+ .maxlen = sizeof(int),
76154+ .mode = 0600,
76155+ .proc_handler = &proc_dointvec,
76156+ },
76157+#endif
76158+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76159+ {
76160+ .procname = "chroot_execlog",
76161+ .data = &grsec_enable_chroot_execlog,
76162+ .maxlen = sizeof(int),
76163+ .mode = 0600,
76164+ .proc_handler = &proc_dointvec,
76165+ },
76166+#endif
76167+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76168+ {
76169+ .procname = "chroot_caps",
76170+ .data = &grsec_enable_chroot_caps,
76171+ .maxlen = sizeof(int),
76172+ .mode = 0600,
76173+ .proc_handler = &proc_dointvec,
76174+ },
76175+#endif
76176+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76177+ {
76178+ .procname = "chroot_deny_sysctl",
76179+ .data = &grsec_enable_chroot_sysctl,
76180+ .maxlen = sizeof(int),
76181+ .mode = 0600,
76182+ .proc_handler = &proc_dointvec,
76183+ },
76184+#endif
76185+#ifdef CONFIG_GRKERNSEC_TPE
76186+ {
76187+ .procname = "tpe",
76188+ .data = &grsec_enable_tpe,
76189+ .maxlen = sizeof(int),
76190+ .mode = 0600,
76191+ .proc_handler = &proc_dointvec,
76192+ },
76193+ {
76194+ .procname = "tpe_gid",
76195+ .data = &grsec_tpe_gid,
76196+ .maxlen = sizeof(int),
76197+ .mode = 0600,
76198+ .proc_handler = &proc_dointvec,
76199+ },
76200+#endif
76201+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76202+ {
76203+ .procname = "tpe_invert",
76204+ .data = &grsec_enable_tpe_invert,
76205+ .maxlen = sizeof(int),
76206+ .mode = 0600,
76207+ .proc_handler = &proc_dointvec,
76208+ },
76209+#endif
76210+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76211+ {
76212+ .procname = "tpe_restrict_all",
76213+ .data = &grsec_enable_tpe_all,
76214+ .maxlen = sizeof(int),
76215+ .mode = 0600,
76216+ .proc_handler = &proc_dointvec,
76217+ },
76218+#endif
76219+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76220+ {
76221+ .procname = "socket_all",
76222+ .data = &grsec_enable_socket_all,
76223+ .maxlen = sizeof(int),
76224+ .mode = 0600,
76225+ .proc_handler = &proc_dointvec,
76226+ },
76227+ {
76228+ .procname = "socket_all_gid",
76229+ .data = &grsec_socket_all_gid,
76230+ .maxlen = sizeof(int),
76231+ .mode = 0600,
76232+ .proc_handler = &proc_dointvec,
76233+ },
76234+#endif
76235+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76236+ {
76237+ .procname = "socket_client",
76238+ .data = &grsec_enable_socket_client,
76239+ .maxlen = sizeof(int),
76240+ .mode = 0600,
76241+ .proc_handler = &proc_dointvec,
76242+ },
76243+ {
76244+ .procname = "socket_client_gid",
76245+ .data = &grsec_socket_client_gid,
76246+ .maxlen = sizeof(int),
76247+ .mode = 0600,
76248+ .proc_handler = &proc_dointvec,
76249+ },
76250+#endif
76251+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76252+ {
76253+ .procname = "socket_server",
76254+ .data = &grsec_enable_socket_server,
76255+ .maxlen = sizeof(int),
76256+ .mode = 0600,
76257+ .proc_handler = &proc_dointvec,
76258+ },
76259+ {
76260+ .procname = "socket_server_gid",
76261+ .data = &grsec_socket_server_gid,
76262+ .maxlen = sizeof(int),
76263+ .mode = 0600,
76264+ .proc_handler = &proc_dointvec,
76265+ },
76266+#endif
76267+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76268+ {
76269+ .procname = "audit_group",
76270+ .data = &grsec_enable_group,
76271+ .maxlen = sizeof(int),
76272+ .mode = 0600,
76273+ .proc_handler = &proc_dointvec,
76274+ },
76275+ {
76276+ .procname = "audit_gid",
76277+ .data = &grsec_audit_gid,
76278+ .maxlen = sizeof(int),
76279+ .mode = 0600,
76280+ .proc_handler = &proc_dointvec,
76281+ },
76282+#endif
76283+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76284+ {
76285+ .procname = "audit_chdir",
76286+ .data = &grsec_enable_chdir,
76287+ .maxlen = sizeof(int),
76288+ .mode = 0600,
76289+ .proc_handler = &proc_dointvec,
76290+ },
76291+#endif
76292+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76293+ {
76294+ .procname = "audit_mount",
76295+ .data = &grsec_enable_mount,
76296+ .maxlen = sizeof(int),
76297+ .mode = 0600,
76298+ .proc_handler = &proc_dointvec,
76299+ },
76300+#endif
76301+#ifdef CONFIG_GRKERNSEC_DMESG
76302+ {
76303+ .procname = "dmesg",
76304+ .data = &grsec_enable_dmesg,
76305+ .maxlen = sizeof(int),
76306+ .mode = 0600,
76307+ .proc_handler = &proc_dointvec,
76308+ },
76309+#endif
76310+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76311+ {
76312+ .procname = "chroot_findtask",
76313+ .data = &grsec_enable_chroot_findtask,
76314+ .maxlen = sizeof(int),
76315+ .mode = 0600,
76316+ .proc_handler = &proc_dointvec,
76317+ },
76318+#endif
76319+#ifdef CONFIG_GRKERNSEC_RESLOG
76320+ {
76321+ .procname = "resource_logging",
76322+ .data = &grsec_resource_logging,
76323+ .maxlen = sizeof(int),
76324+ .mode = 0600,
76325+ .proc_handler = &proc_dointvec,
76326+ },
76327+#endif
76328+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76329+ {
76330+ .procname = "audit_ptrace",
76331+ .data = &grsec_enable_audit_ptrace,
76332+ .maxlen = sizeof(int),
76333+ .mode = 0600,
76334+ .proc_handler = &proc_dointvec,
76335+ },
76336+#endif
76337+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76338+ {
76339+ .procname = "harden_ptrace",
76340+ .data = &grsec_enable_harden_ptrace,
76341+ .maxlen = sizeof(int),
76342+ .mode = 0600,
76343+ .proc_handler = &proc_dointvec,
76344+ },
76345+#endif
76346+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76347+ {
76348+ .procname = "harden_ipc",
76349+ .data = &grsec_enable_harden_ipc,
76350+ .maxlen = sizeof(int),
76351+ .mode = 0600,
76352+ .proc_handler = &proc_dointvec,
76353+ },
76354+#endif
76355+ {
76356+ .procname = "grsec_lock",
76357+ .data = &grsec_lock,
76358+ .maxlen = sizeof(int),
76359+ .mode = 0600,
76360+ .proc_handler = &proc_dointvec,
76361+ },
76362+#endif
76363+#ifdef CONFIG_GRKERNSEC_ROFS
76364+ {
76365+ .procname = "romount_protect",
76366+ .data = &grsec_enable_rofs,
76367+ .maxlen = sizeof(int),
76368+ .mode = 0600,
76369+ .proc_handler = &proc_dointvec_minmax,
76370+ .extra1 = &one,
76371+ .extra2 = &one,
76372+ },
76373+#endif
76374+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76375+ {
76376+ .procname = "deny_new_usb",
76377+ .data = &grsec_deny_new_usb,
76378+ .maxlen = sizeof(int),
76379+ .mode = 0600,
76380+ .proc_handler = &proc_dointvec,
76381+ },
76382+#endif
76383+ { }
76384+};
76385+#endif
76386diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76387new file mode 100644
76388index 0000000..61b514e
76389--- /dev/null
76390+++ b/grsecurity/grsec_time.c
76391@@ -0,0 +1,16 @@
76392+#include <linux/kernel.h>
76393+#include <linux/sched.h>
76394+#include <linux/grinternal.h>
76395+#include <linux/module.h>
76396+
76397+void
76398+gr_log_timechange(void)
76399+{
76400+#ifdef CONFIG_GRKERNSEC_TIME
76401+ if (grsec_enable_time)
76402+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76403+#endif
76404+ return;
76405+}
76406+
76407+EXPORT_SYMBOL_GPL(gr_log_timechange);
76408diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76409new file mode 100644
76410index 0000000..d1953de
76411--- /dev/null
76412+++ b/grsecurity/grsec_tpe.c
76413@@ -0,0 +1,78 @@
76414+#include <linux/kernel.h>
76415+#include <linux/sched.h>
76416+#include <linux/file.h>
76417+#include <linux/fs.h>
76418+#include <linux/grinternal.h>
76419+
76420+extern int gr_acl_tpe_check(void);
76421+
76422+int
76423+gr_tpe_allow(const struct file *file)
76424+{
76425+#ifdef CONFIG_GRKERNSEC
76426+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76427+ struct inode *file_inode = file->f_path.dentry->d_inode;
76428+ const struct cred *cred = current_cred();
76429+ char *msg = NULL;
76430+ char *msg2 = NULL;
76431+
76432+ // never restrict root
76433+ if (gr_is_global_root(cred->uid))
76434+ return 1;
76435+
76436+ if (grsec_enable_tpe) {
76437+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76438+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76439+ msg = "not being in trusted group";
76440+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76441+ msg = "being in untrusted group";
76442+#else
76443+ if (in_group_p(grsec_tpe_gid))
76444+ msg = "being in untrusted group";
76445+#endif
76446+ }
76447+ if (!msg && gr_acl_tpe_check())
76448+ msg = "being in untrusted role";
76449+
76450+ // not in any affected group/role
76451+ if (!msg)
76452+ goto next_check;
76453+
76454+ if (gr_is_global_nonroot(inode->i_uid))
76455+ msg2 = "file in non-root-owned directory";
76456+ else if (inode->i_mode & S_IWOTH)
76457+ msg2 = "file in world-writable directory";
76458+ else if (inode->i_mode & S_IWGRP)
76459+ msg2 = "file in group-writable directory";
76460+ else if (file_inode->i_mode & S_IWOTH)
76461+ msg2 = "file is world-writable";
76462+
76463+ if (msg && msg2) {
76464+ char fullmsg[70] = {0};
76465+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76466+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76467+ return 0;
76468+ }
76469+ msg = NULL;
76470+next_check:
76471+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76472+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76473+ return 1;
76474+
76475+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76476+ msg = "directory not owned by user";
76477+ else if (inode->i_mode & S_IWOTH)
76478+ msg = "file in world-writable directory";
76479+ else if (inode->i_mode & S_IWGRP)
76480+ msg = "file in group-writable directory";
76481+ else if (file_inode->i_mode & S_IWOTH)
76482+ msg = "file is world-writable";
76483+
76484+ if (msg) {
76485+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76486+ return 0;
76487+ }
76488+#endif
76489+#endif
76490+ return 1;
76491+}
76492diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76493new file mode 100644
76494index 0000000..ae02d8e
76495--- /dev/null
76496+++ b/grsecurity/grsec_usb.c
76497@@ -0,0 +1,15 @@
76498+#include <linux/kernel.h>
76499+#include <linux/grinternal.h>
76500+#include <linux/module.h>
76501+
76502+int gr_handle_new_usb(void)
76503+{
76504+#ifdef CONFIG_GRKERNSEC_DENYUSB
76505+ if (grsec_deny_new_usb) {
76506+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76507+ return 1;
76508+ }
76509+#endif
76510+ return 0;
76511+}
76512+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76513diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76514new file mode 100644
76515index 0000000..9f7b1ac
76516--- /dev/null
76517+++ b/grsecurity/grsum.c
76518@@ -0,0 +1,61 @@
76519+#include <linux/err.h>
76520+#include <linux/kernel.h>
76521+#include <linux/sched.h>
76522+#include <linux/mm.h>
76523+#include <linux/scatterlist.h>
76524+#include <linux/crypto.h>
76525+#include <linux/gracl.h>
76526+
76527+
76528+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76529+#error "crypto and sha256 must be built into the kernel"
76530+#endif
76531+
76532+int
76533+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76534+{
76535+ char *p;
76536+ struct crypto_hash *tfm;
76537+ struct hash_desc desc;
76538+ struct scatterlist sg;
76539+ unsigned char temp_sum[GR_SHA_LEN];
76540+ volatile int retval = 0;
76541+ volatile int dummy = 0;
76542+ unsigned int i;
76543+
76544+ sg_init_table(&sg, 1);
76545+
76546+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76547+ if (IS_ERR(tfm)) {
76548+ /* should never happen, since sha256 should be built in */
76549+ return 1;
76550+ }
76551+
76552+ desc.tfm = tfm;
76553+ desc.flags = 0;
76554+
76555+ crypto_hash_init(&desc);
76556+
76557+ p = salt;
76558+ sg_set_buf(&sg, p, GR_SALT_LEN);
76559+ crypto_hash_update(&desc, &sg, sg.length);
76560+
76561+ p = entry->pw;
76562+ sg_set_buf(&sg, p, strlen(p));
76563+
76564+ crypto_hash_update(&desc, &sg, sg.length);
76565+
76566+ crypto_hash_final(&desc, temp_sum);
76567+
76568+ memset(entry->pw, 0, GR_PW_LEN);
76569+
76570+ for (i = 0; i < GR_SHA_LEN; i++)
76571+ if (sum[i] != temp_sum[i])
76572+ retval = 1;
76573+ else
76574+ dummy = 1; // waste a cycle
76575+
76576+ crypto_free_hash(tfm);
76577+
76578+ return retval;
76579+}
76580diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76581index 77ff547..181834f 100644
76582--- a/include/asm-generic/4level-fixup.h
76583+++ b/include/asm-generic/4level-fixup.h
76584@@ -13,8 +13,10 @@
76585 #define pmd_alloc(mm, pud, address) \
76586 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76587 NULL: pmd_offset(pud, address))
76588+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76589
76590 #define pud_alloc(mm, pgd, address) (pgd)
76591+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76592 #define pud_offset(pgd, start) (pgd)
76593 #define pud_none(pud) 0
76594 #define pud_bad(pud) 0
76595diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76596index b7babf0..97f4c4f 100644
76597--- a/include/asm-generic/atomic-long.h
76598+++ b/include/asm-generic/atomic-long.h
76599@@ -22,6 +22,12 @@
76600
76601 typedef atomic64_t atomic_long_t;
76602
76603+#ifdef CONFIG_PAX_REFCOUNT
76604+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76605+#else
76606+typedef atomic64_t atomic_long_unchecked_t;
76607+#endif
76608+
76609 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76610
76611 static inline long atomic_long_read(atomic_long_t *l)
76612@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76613 return (long)atomic64_read(v);
76614 }
76615
76616+#ifdef CONFIG_PAX_REFCOUNT
76617+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76618+{
76619+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76620+
76621+ return (long)atomic64_read_unchecked(v);
76622+}
76623+#endif
76624+
76625 static inline void atomic_long_set(atomic_long_t *l, long i)
76626 {
76627 atomic64_t *v = (atomic64_t *)l;
76628@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76629 atomic64_set(v, i);
76630 }
76631
76632+#ifdef CONFIG_PAX_REFCOUNT
76633+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76634+{
76635+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76636+
76637+ atomic64_set_unchecked(v, i);
76638+}
76639+#endif
76640+
76641 static inline void atomic_long_inc(atomic_long_t *l)
76642 {
76643 atomic64_t *v = (atomic64_t *)l;
76644@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76645 atomic64_inc(v);
76646 }
76647
76648+#ifdef CONFIG_PAX_REFCOUNT
76649+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76650+{
76651+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76652+
76653+ atomic64_inc_unchecked(v);
76654+}
76655+#endif
76656+
76657 static inline void atomic_long_dec(atomic_long_t *l)
76658 {
76659 atomic64_t *v = (atomic64_t *)l;
76660@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76661 atomic64_dec(v);
76662 }
76663
76664+#ifdef CONFIG_PAX_REFCOUNT
76665+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76666+{
76667+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76668+
76669+ atomic64_dec_unchecked(v);
76670+}
76671+#endif
76672+
76673 static inline void atomic_long_add(long i, atomic_long_t *l)
76674 {
76675 atomic64_t *v = (atomic64_t *)l;
76676@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76677 atomic64_add(i, v);
76678 }
76679
76680+#ifdef CONFIG_PAX_REFCOUNT
76681+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76682+{
76683+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76684+
76685+ atomic64_add_unchecked(i, v);
76686+}
76687+#endif
76688+
76689 static inline void atomic_long_sub(long i, atomic_long_t *l)
76690 {
76691 atomic64_t *v = (atomic64_t *)l;
76692@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76693 atomic64_sub(i, v);
76694 }
76695
76696+#ifdef CONFIG_PAX_REFCOUNT
76697+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76698+{
76699+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76700+
76701+ atomic64_sub_unchecked(i, v);
76702+}
76703+#endif
76704+
76705 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76706 {
76707 atomic64_t *v = (atomic64_t *)l;
76708@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76709 return atomic64_add_negative(i, v);
76710 }
76711
76712-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76713+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76714 {
76715 atomic64_t *v = (atomic64_t *)l;
76716
76717 return (long)atomic64_add_return(i, v);
76718 }
76719
76720+#ifdef CONFIG_PAX_REFCOUNT
76721+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76722+{
76723+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76724+
76725+ return (long)atomic64_add_return_unchecked(i, v);
76726+}
76727+#endif
76728+
76729 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76730 {
76731 atomic64_t *v = (atomic64_t *)l;
76732@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76733 return (long)atomic64_inc_return(v);
76734 }
76735
76736+#ifdef CONFIG_PAX_REFCOUNT
76737+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76738+{
76739+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76740+
76741+ return (long)atomic64_inc_return_unchecked(v);
76742+}
76743+#endif
76744+
76745 static inline long atomic_long_dec_return(atomic_long_t *l)
76746 {
76747 atomic64_t *v = (atomic64_t *)l;
76748@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76749
76750 typedef atomic_t atomic_long_t;
76751
76752+#ifdef CONFIG_PAX_REFCOUNT
76753+typedef atomic_unchecked_t atomic_long_unchecked_t;
76754+#else
76755+typedef atomic_t atomic_long_unchecked_t;
76756+#endif
76757+
76758 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76759 static inline long atomic_long_read(atomic_long_t *l)
76760 {
76761@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76762 return (long)atomic_read(v);
76763 }
76764
76765+#ifdef CONFIG_PAX_REFCOUNT
76766+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76767+{
76768+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76769+
76770+ return (long)atomic_read_unchecked(v);
76771+}
76772+#endif
76773+
76774 static inline void atomic_long_set(atomic_long_t *l, long i)
76775 {
76776 atomic_t *v = (atomic_t *)l;
76777@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76778 atomic_set(v, i);
76779 }
76780
76781+#ifdef CONFIG_PAX_REFCOUNT
76782+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76783+{
76784+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76785+
76786+ atomic_set_unchecked(v, i);
76787+}
76788+#endif
76789+
76790 static inline void atomic_long_inc(atomic_long_t *l)
76791 {
76792 atomic_t *v = (atomic_t *)l;
76793@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76794 atomic_inc(v);
76795 }
76796
76797+#ifdef CONFIG_PAX_REFCOUNT
76798+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76799+{
76800+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76801+
76802+ atomic_inc_unchecked(v);
76803+}
76804+#endif
76805+
76806 static inline void atomic_long_dec(atomic_long_t *l)
76807 {
76808 atomic_t *v = (atomic_t *)l;
76809@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76810 atomic_dec(v);
76811 }
76812
76813+#ifdef CONFIG_PAX_REFCOUNT
76814+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76815+{
76816+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76817+
76818+ atomic_dec_unchecked(v);
76819+}
76820+#endif
76821+
76822 static inline void atomic_long_add(long i, atomic_long_t *l)
76823 {
76824 atomic_t *v = (atomic_t *)l;
76825@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76826 atomic_add(i, v);
76827 }
76828
76829+#ifdef CONFIG_PAX_REFCOUNT
76830+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76831+{
76832+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76833+
76834+ atomic_add_unchecked(i, v);
76835+}
76836+#endif
76837+
76838 static inline void atomic_long_sub(long i, atomic_long_t *l)
76839 {
76840 atomic_t *v = (atomic_t *)l;
76841@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76842 atomic_sub(i, v);
76843 }
76844
76845+#ifdef CONFIG_PAX_REFCOUNT
76846+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76847+{
76848+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76849+
76850+ atomic_sub_unchecked(i, v);
76851+}
76852+#endif
76853+
76854 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76855 {
76856 atomic_t *v = (atomic_t *)l;
76857@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76858 return (long)atomic_add_return(i, v);
76859 }
76860
76861+#ifdef CONFIG_PAX_REFCOUNT
76862+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76863+{
76864+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76865+
76866+ return (long)atomic_add_return_unchecked(i, v);
76867+}
76868+
76869+#endif
76870+
76871 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76872 {
76873 atomic_t *v = (atomic_t *)l;
76874@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76875 return (long)atomic_inc_return(v);
76876 }
76877
76878+#ifdef CONFIG_PAX_REFCOUNT
76879+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76880+{
76881+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76882+
76883+ return (long)atomic_inc_return_unchecked(v);
76884+}
76885+#endif
76886+
76887 static inline long atomic_long_dec_return(atomic_long_t *l)
76888 {
76889 atomic_t *v = (atomic_t *)l;
76890@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76891
76892 #endif /* BITS_PER_LONG == 64 */
76893
76894+#ifdef CONFIG_PAX_REFCOUNT
76895+static inline void pax_refcount_needs_these_functions(void)
76896+{
76897+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
76898+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76899+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76900+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76901+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76902+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76903+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76904+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76905+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76906+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76907+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76908+#ifdef CONFIG_X86
76909+ atomic_clear_mask_unchecked(0, NULL);
76910+ atomic_set_mask_unchecked(0, NULL);
76911+#endif
76912+
76913+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76914+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76915+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76916+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76917+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76918+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76919+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76920+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76921+}
76922+#else
76923+#define atomic_read_unchecked(v) atomic_read(v)
76924+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76925+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76926+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76927+#define atomic_inc_unchecked(v) atomic_inc(v)
76928+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76929+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76930+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76931+#define atomic_dec_unchecked(v) atomic_dec(v)
76932+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76933+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76934+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76935+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76936+
76937+#define atomic_long_read_unchecked(v) atomic_long_read(v)
76938+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76939+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76940+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76941+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76942+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76943+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76944+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76945+#endif
76946+
76947 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76948diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76949index 33bd2de..f31bff97 100644
76950--- a/include/asm-generic/atomic.h
76951+++ b/include/asm-generic/atomic.h
76952@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76953 * Atomically clears the bits set in @mask from @v
76954 */
76955 #ifndef atomic_clear_mask
76956-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76957+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76958 {
76959 unsigned long flags;
76960
76961diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76962index b18ce4f..2ee2843 100644
76963--- a/include/asm-generic/atomic64.h
76964+++ b/include/asm-generic/atomic64.h
76965@@ -16,6 +16,8 @@ typedef struct {
76966 long long counter;
76967 } atomic64_t;
76968
76969+typedef atomic64_t atomic64_unchecked_t;
76970+
76971 #define ATOMIC64_INIT(i) { (i) }
76972
76973 extern long long atomic64_read(const atomic64_t *v);
76974@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76975 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76976 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76977
76978+#define atomic64_read_unchecked(v) atomic64_read(v)
76979+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76980+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76981+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76982+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76983+#define atomic64_inc_unchecked(v) atomic64_inc(v)
76984+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76985+#define atomic64_dec_unchecked(v) atomic64_dec(v)
76986+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76987+
76988 #endif /* _ASM_GENERIC_ATOMIC64_H */
76989diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
76990index 6f692f8..2ad9dd2 100644
76991--- a/include/asm-generic/barrier.h
76992+++ b/include/asm-generic/barrier.h
76993@@ -66,7 +66,7 @@
76994 do { \
76995 compiletime_assert_atomic_type(*p); \
76996 smp_mb(); \
76997- ACCESS_ONCE(*p) = (v); \
76998+ ACCESS_ONCE_RW(*p) = (v); \
76999 } while (0)
77000
77001 #define smp_load_acquire(p) \
77002diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77003index a60a7cc..0fe12f2 100644
77004--- a/include/asm-generic/bitops/__fls.h
77005+++ b/include/asm-generic/bitops/__fls.h
77006@@ -9,7 +9,7 @@
77007 *
77008 * Undefined if no set bit exists, so code should check against 0 first.
77009 */
77010-static __always_inline unsigned long __fls(unsigned long word)
77011+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77012 {
77013 int num = BITS_PER_LONG - 1;
77014
77015diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77016index 0576d1f..dad6c71 100644
77017--- a/include/asm-generic/bitops/fls.h
77018+++ b/include/asm-generic/bitops/fls.h
77019@@ -9,7 +9,7 @@
77020 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77021 */
77022
77023-static __always_inline int fls(int x)
77024+static __always_inline int __intentional_overflow(-1) fls(int x)
77025 {
77026 int r = 32;
77027
77028diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77029index b097cf8..3d40e14 100644
77030--- a/include/asm-generic/bitops/fls64.h
77031+++ b/include/asm-generic/bitops/fls64.h
77032@@ -15,7 +15,7 @@
77033 * at position 64.
77034 */
77035 #if BITS_PER_LONG == 32
77036-static __always_inline int fls64(__u64 x)
77037+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77038 {
77039 __u32 h = x >> 32;
77040 if (h)
77041@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77042 return fls(x);
77043 }
77044 #elif BITS_PER_LONG == 64
77045-static __always_inline int fls64(__u64 x)
77046+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77047 {
77048 if (x == 0)
77049 return 0;
77050diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77051index 1bfcfe5..e04c5c9 100644
77052--- a/include/asm-generic/cache.h
77053+++ b/include/asm-generic/cache.h
77054@@ -6,7 +6,7 @@
77055 * cache lines need to provide their own cache.h.
77056 */
77057
77058-#define L1_CACHE_SHIFT 5
77059-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77060+#define L1_CACHE_SHIFT 5UL
77061+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77062
77063 #endif /* __ASM_GENERIC_CACHE_H */
77064diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77065index 0d68a1e..b74a761 100644
77066--- a/include/asm-generic/emergency-restart.h
77067+++ b/include/asm-generic/emergency-restart.h
77068@@ -1,7 +1,7 @@
77069 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77070 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77071
77072-static inline void machine_emergency_restart(void)
77073+static inline __noreturn void machine_emergency_restart(void)
77074 {
77075 machine_restart(NULL);
77076 }
77077diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
77078index 975e1cc..0b8a083 100644
77079--- a/include/asm-generic/io.h
77080+++ b/include/asm-generic/io.h
77081@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
77082 * These are pretty trivial
77083 */
77084 #ifndef virt_to_phys
77085-static inline unsigned long virt_to_phys(volatile void *address)
77086+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
77087 {
77088 return __pa((unsigned long)address);
77089 }
77090diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77091index 90f99c7..00ce236 100644
77092--- a/include/asm-generic/kmap_types.h
77093+++ b/include/asm-generic/kmap_types.h
77094@@ -2,9 +2,9 @@
77095 #define _ASM_GENERIC_KMAP_TYPES_H
77096
77097 #ifdef __WITH_KM_FENCE
77098-# define KM_TYPE_NR 41
77099+# define KM_TYPE_NR 42
77100 #else
77101-# define KM_TYPE_NR 20
77102+# define KM_TYPE_NR 21
77103 #endif
77104
77105 #endif
77106diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77107index 9ceb03b..62b0b8f 100644
77108--- a/include/asm-generic/local.h
77109+++ b/include/asm-generic/local.h
77110@@ -23,24 +23,37 @@ typedef struct
77111 atomic_long_t a;
77112 } local_t;
77113
77114+typedef struct {
77115+ atomic_long_unchecked_t a;
77116+} local_unchecked_t;
77117+
77118 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77119
77120 #define local_read(l) atomic_long_read(&(l)->a)
77121+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77122 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77123+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77124 #define local_inc(l) atomic_long_inc(&(l)->a)
77125+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77126 #define local_dec(l) atomic_long_dec(&(l)->a)
77127+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77128 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77129+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77130 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77131+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77132
77133 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77134 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77135 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77136 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77137 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77138+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77139 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77140 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77141+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77142
77143 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77144+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77145 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77146 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77147 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77148diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77149index 725612b..9cc513a 100644
77150--- a/include/asm-generic/pgtable-nopmd.h
77151+++ b/include/asm-generic/pgtable-nopmd.h
77152@@ -1,14 +1,19 @@
77153 #ifndef _PGTABLE_NOPMD_H
77154 #define _PGTABLE_NOPMD_H
77155
77156-#ifndef __ASSEMBLY__
77157-
77158 #include <asm-generic/pgtable-nopud.h>
77159
77160-struct mm_struct;
77161-
77162 #define __PAGETABLE_PMD_FOLDED
77163
77164+#define PMD_SHIFT PUD_SHIFT
77165+#define PTRS_PER_PMD 1
77166+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77167+#define PMD_MASK (~(PMD_SIZE-1))
77168+
77169+#ifndef __ASSEMBLY__
77170+
77171+struct mm_struct;
77172+
77173 /*
77174 * Having the pmd type consist of a pud gets the size right, and allows
77175 * us to conceptually access the pud entry that this pmd is folded into
77176@@ -16,11 +21,6 @@ struct mm_struct;
77177 */
77178 typedef struct { pud_t pud; } pmd_t;
77179
77180-#define PMD_SHIFT PUD_SHIFT
77181-#define PTRS_PER_PMD 1
77182-#define PMD_SIZE (1UL << PMD_SHIFT)
77183-#define PMD_MASK (~(PMD_SIZE-1))
77184-
77185 /*
77186 * The "pud_xxx()" functions here are trivial for a folded two-level
77187 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77188diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77189index 810431d..0ec4804f 100644
77190--- a/include/asm-generic/pgtable-nopud.h
77191+++ b/include/asm-generic/pgtable-nopud.h
77192@@ -1,10 +1,15 @@
77193 #ifndef _PGTABLE_NOPUD_H
77194 #define _PGTABLE_NOPUD_H
77195
77196-#ifndef __ASSEMBLY__
77197-
77198 #define __PAGETABLE_PUD_FOLDED
77199
77200+#define PUD_SHIFT PGDIR_SHIFT
77201+#define PTRS_PER_PUD 1
77202+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77203+#define PUD_MASK (~(PUD_SIZE-1))
77204+
77205+#ifndef __ASSEMBLY__
77206+
77207 /*
77208 * Having the pud type consist of a pgd gets the size right, and allows
77209 * us to conceptually access the pgd entry that this pud is folded into
77210@@ -12,11 +17,6 @@
77211 */
77212 typedef struct { pgd_t pgd; } pud_t;
77213
77214-#define PUD_SHIFT PGDIR_SHIFT
77215-#define PTRS_PER_PUD 1
77216-#define PUD_SIZE (1UL << PUD_SHIFT)
77217-#define PUD_MASK (~(PUD_SIZE-1))
77218-
77219 /*
77220 * The "pgd_xxx()" functions here are trivial for a folded two-level
77221 * setup: the pud is never bad, and a pud always exists (as it's folded
77222@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77223 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77224
77225 #define pgd_populate(mm, pgd, pud) do { } while (0)
77226+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77227 /*
77228 * (puds are folded into pgds so this doesn't get actually called,
77229 * but the define is needed for a generic inline function.)
77230diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77231index a8015a7..7a4407b 100644
77232--- a/include/asm-generic/pgtable.h
77233+++ b/include/asm-generic/pgtable.h
77234@@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77235 }
77236 #endif /* CONFIG_NUMA_BALANCING */
77237
77238+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77239+#ifdef CONFIG_PAX_KERNEXEC
77240+#error KERNEXEC requires pax_open_kernel
77241+#else
77242+static inline unsigned long pax_open_kernel(void) { return 0; }
77243+#endif
77244+#endif
77245+
77246+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77247+#ifdef CONFIG_PAX_KERNEXEC
77248+#error KERNEXEC requires pax_close_kernel
77249+#else
77250+static inline unsigned long pax_close_kernel(void) { return 0; }
77251+#endif
77252+#endif
77253+
77254 #endif /* CONFIG_MMU */
77255
77256 #endif /* !__ASSEMBLY__ */
77257diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77258index 72d8803..cb9749c 100644
77259--- a/include/asm-generic/uaccess.h
77260+++ b/include/asm-generic/uaccess.h
77261@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77262 return __clear_user(to, n);
77263 }
77264
77265+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77266+#ifdef CONFIG_PAX_MEMORY_UDEREF
77267+#error UDEREF requires pax_open_userland
77268+#else
77269+static inline unsigned long pax_open_userland(void) { return 0; }
77270+#endif
77271+#endif
77272+
77273+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77274+#ifdef CONFIG_PAX_MEMORY_UDEREF
77275+#error UDEREF requires pax_close_userland
77276+#else
77277+static inline unsigned long pax_close_userland(void) { return 0; }
77278+#endif
77279+#endif
77280+
77281 #endif /* __ASM_GENERIC_UACCESS_H */
77282diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77283index 146e4ff..f4f9609 100644
77284--- a/include/asm-generic/vmlinux.lds.h
77285+++ b/include/asm-generic/vmlinux.lds.h
77286@@ -251,6 +251,7 @@
77287 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77288 VMLINUX_SYMBOL(__start_rodata) = .; \
77289 *(.rodata) *(.rodata.*) \
77290+ *(.data..read_only) \
77291 *(__vermagic) /* Kernel version magic */ \
77292 . = ALIGN(8); \
77293 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77294@@ -737,17 +738,18 @@
77295 * section in the linker script will go there too. @phdr should have
77296 * a leading colon.
77297 *
77298- * Note that this macros defines __per_cpu_load as an absolute symbol.
77299+ * Note that this macros defines per_cpu_load as an absolute symbol.
77300 * If there is no need to put the percpu section at a predetermined
77301 * address, use PERCPU_SECTION.
77302 */
77303 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77304- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77305- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77306+ per_cpu_load = .; \
77307+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77308 - LOAD_OFFSET) { \
77309+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77310 PERCPU_INPUT(cacheline) \
77311 } phdr \
77312- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77313+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77314
77315 /**
77316 * PERCPU_SECTION - define output section for percpu area, simple version
77317diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77318index 016c2f1..c4baa98 100644
77319--- a/include/crypto/algapi.h
77320+++ b/include/crypto/algapi.h
77321@@ -34,7 +34,7 @@ struct crypto_type {
77322 unsigned int maskclear;
77323 unsigned int maskset;
77324 unsigned int tfmsize;
77325-};
77326+} __do_const;
77327
77328 struct crypto_instance {
77329 struct crypto_alg alg;
77330diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77331index a7c2a86..078f1b6 100644
77332--- a/include/drm/drmP.h
77333+++ b/include/drm/drmP.h
77334@@ -68,6 +68,7 @@
77335 #include <linux/workqueue.h>
77336 #include <linux/poll.h>
77337 #include <asm/pgalloc.h>
77338+#include <asm/local.h>
77339 #include <drm/drm.h>
77340 #include <drm/drm_sarea.h>
77341 #include <drm/drm_vma_manager.h>
77342@@ -268,10 +269,12 @@ do { \
77343 * \param cmd command.
77344 * \param arg argument.
77345 */
77346-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77347+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77348+ struct drm_file *file_priv);
77349+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77350 struct drm_file *file_priv);
77351
77352-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77353+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77354 unsigned long arg);
77355
77356 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77357@@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77358 struct drm_ioctl_desc {
77359 unsigned int cmd;
77360 int flags;
77361- drm_ioctl_t *func;
77362+ drm_ioctl_t func;
77363 unsigned int cmd_drv;
77364 const char *name;
77365-};
77366+} __do_const;
77367
77368 /**
77369 * Creates a driver or general drm_ioctl_desc array entry for the given
77370@@ -1001,7 +1004,8 @@ struct drm_info_list {
77371 int (*show)(struct seq_file*, void*); /** show callback */
77372 u32 driver_features; /**< Required driver features for this entry */
77373 void *data;
77374-};
77375+} __do_const;
77376+typedef struct drm_info_list __no_const drm_info_list_no_const;
77377
77378 /**
77379 * debugfs node structure. This structure represents a debugfs file.
77380@@ -1083,7 +1087,7 @@ struct drm_device {
77381
77382 /** \name Usage Counters */
77383 /*@{ */
77384- int open_count; /**< Outstanding files open */
77385+ local_t open_count; /**< Outstanding files open */
77386 int buf_use; /**< Buffers in use -- cannot alloc */
77387 atomic_t buf_alloc; /**< Buffer allocation in progress */
77388 /*@} */
77389diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77390index 36a5feb..d9f01aa 100644
77391--- a/include/drm/drm_crtc_helper.h
77392+++ b/include/drm/drm_crtc_helper.h
77393@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77394 struct drm_connector *connector);
77395 /* disable encoder when not in use - more explicit than dpms off */
77396 void (*disable)(struct drm_encoder *encoder);
77397-};
77398+} __no_const;
77399
77400 /**
77401 * drm_connector_helper_funcs - helper operations for connectors
77402diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77403index 012d58f..d0a0642 100644
77404--- a/include/drm/i915_pciids.h
77405+++ b/include/drm/i915_pciids.h
77406@@ -37,7 +37,7 @@
77407 */
77408 #define INTEL_VGA_DEVICE(id, info) { \
77409 0x8086, id, \
77410- ~0, ~0, \
77411+ PCI_ANY_ID, PCI_ANY_ID, \
77412 0x030000, 0xff0000, \
77413 (unsigned long) info }
77414
77415diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77416index 72dcbe8..8db58d7 100644
77417--- a/include/drm/ttm/ttm_memory.h
77418+++ b/include/drm/ttm/ttm_memory.h
77419@@ -48,7 +48,7 @@
77420
77421 struct ttm_mem_shrink {
77422 int (*do_shrink) (struct ttm_mem_shrink *);
77423-};
77424+} __no_const;
77425
77426 /**
77427 * struct ttm_mem_global - Global memory accounting structure.
77428diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77429index 49a8284..9643967 100644
77430--- a/include/drm/ttm/ttm_page_alloc.h
77431+++ b/include/drm/ttm/ttm_page_alloc.h
77432@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77433 */
77434 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77435
77436+struct device;
77437 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77438 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77439
77440diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77441index 4b840e8..155d235 100644
77442--- a/include/keys/asymmetric-subtype.h
77443+++ b/include/keys/asymmetric-subtype.h
77444@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77445 /* Verify the signature on a key of this subtype (optional) */
77446 int (*verify_signature)(const struct key *key,
77447 const struct public_key_signature *sig);
77448-};
77449+} __do_const;
77450
77451 /**
77452 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77453diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77454index c1da539..1dcec55 100644
77455--- a/include/linux/atmdev.h
77456+++ b/include/linux/atmdev.h
77457@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77458 #endif
77459
77460 struct k_atm_aal_stats {
77461-#define __HANDLE_ITEM(i) atomic_t i
77462+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77463 __AAL_STAT_ITEMS
77464 #undef __HANDLE_ITEM
77465 };
77466@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77467 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77468 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77469 struct module *owner;
77470-};
77471+} __do_const ;
77472
77473 struct atmphy_ops {
77474 int (*start)(struct atm_dev *dev);
77475diff --git a/include/linux/audit.h b/include/linux/audit.h
77476index 22cfddb..ab759e8 100644
77477--- a/include/linux/audit.h
77478+++ b/include/linux/audit.h
77479@@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
77480 extern unsigned int audit_serial(void);
77481 extern int auditsc_get_stamp(struct audit_context *ctx,
77482 struct timespec *t, unsigned int *serial);
77483-extern int audit_set_loginuid(kuid_t loginuid);
77484+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77485
77486 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77487 {
77488diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77489index 61f29e5..e67c658 100644
77490--- a/include/linux/binfmts.h
77491+++ b/include/linux/binfmts.h
77492@@ -44,7 +44,7 @@ struct linux_binprm {
77493 unsigned interp_flags;
77494 unsigned interp_data;
77495 unsigned long loader, exec;
77496-};
77497+} __randomize_layout;
77498
77499 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77500 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77501@@ -73,8 +73,10 @@ struct linux_binfmt {
77502 int (*load_binary)(struct linux_binprm *);
77503 int (*load_shlib)(struct file *);
77504 int (*core_dump)(struct coredump_params *cprm);
77505+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77506+ void (*handle_mmap)(struct file *);
77507 unsigned long min_coredump; /* minimal dump size */
77508-};
77509+} __do_const __randomize_layout;
77510
77511 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77512
77513diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77514index be5fd38..d71192a 100644
77515--- a/include/linux/bitops.h
77516+++ b/include/linux/bitops.h
77517@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77518 * @word: value to rotate
77519 * @shift: bits to roll
77520 */
77521-static inline __u32 rol32(__u32 word, unsigned int shift)
77522+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77523 {
77524 return (word << shift) | (word >> (32 - shift));
77525 }
77526@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77527 * @word: value to rotate
77528 * @shift: bits to roll
77529 */
77530-static inline __u32 ror32(__u32 word, unsigned int shift)
77531+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77532 {
77533 return (word >> shift) | (word << (32 - shift));
77534 }
77535@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77536 return (__s32)(value << shift) >> shift;
77537 }
77538
77539-static inline unsigned fls_long(unsigned long l)
77540+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77541 {
77542 if (sizeof(l) == 4)
77543 return fls(l);
77544diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77545index 0d84981..bb741c0 100644
77546--- a/include/linux/blkdev.h
77547+++ b/include/linux/blkdev.h
77548@@ -1584,7 +1584,7 @@ struct block_device_operations {
77549 /* this callback is with swap_lock and sometimes page table lock held */
77550 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77551 struct module *owner;
77552-};
77553+} __do_const;
77554
77555 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77556 unsigned long);
77557diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77558index afc1343..9735539 100644
77559--- a/include/linux/blktrace_api.h
77560+++ b/include/linux/blktrace_api.h
77561@@ -25,7 +25,7 @@ struct blk_trace {
77562 struct dentry *dropped_file;
77563 struct dentry *msg_file;
77564 struct list_head running_list;
77565- atomic_t dropped;
77566+ atomic_unchecked_t dropped;
77567 };
77568
77569 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77570diff --git a/include/linux/cache.h b/include/linux/cache.h
77571index 17e7e82..1d7da26 100644
77572--- a/include/linux/cache.h
77573+++ b/include/linux/cache.h
77574@@ -16,6 +16,14 @@
77575 #define __read_mostly
77576 #endif
77577
77578+#ifndef __read_only
77579+#ifdef CONFIG_PAX_KERNEXEC
77580+#error KERNEXEC requires __read_only
77581+#else
77582+#define __read_only __read_mostly
77583+#endif
77584+#endif
77585+
77586 #ifndef ____cacheline_aligned
77587 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77588 #endif
77589diff --git a/include/linux/capability.h b/include/linux/capability.h
77590index 84b13ad..172cdee 100644
77591--- a/include/linux/capability.h
77592+++ b/include/linux/capability.h
77593@@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
77594 extern bool capable(int cap);
77595 extern bool ns_capable(struct user_namespace *ns, int cap);
77596 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
77597+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
77598 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77599+extern bool capable_nolog(int cap);
77600+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77601
77602 /* audit system wants to get cap info from files as well */
77603 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77604
77605+extern int is_privileged_binary(const struct dentry *dentry);
77606+
77607 #endif /* !_LINUX_CAPABILITY_H */
77608diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77609index 8609d57..86e4d79 100644
77610--- a/include/linux/cdrom.h
77611+++ b/include/linux/cdrom.h
77612@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77613
77614 /* driver specifications */
77615 const int capability; /* capability flags */
77616- int n_minors; /* number of active minor devices */
77617 /* handle uniform packets for scsi type devices (scsi,atapi) */
77618 int (*generic_packet) (struct cdrom_device_info *,
77619 struct packet_command *);
77620diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77621index 4ce9056..86caac6 100644
77622--- a/include/linux/cleancache.h
77623+++ b/include/linux/cleancache.h
77624@@ -31,7 +31,7 @@ struct cleancache_ops {
77625 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77626 void (*invalidate_inode)(int, struct cleancache_filekey);
77627 void (*invalidate_fs)(int);
77628-};
77629+} __no_const;
77630
77631 extern struct cleancache_ops *
77632 cleancache_register_ops(struct cleancache_ops *ops);
77633diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77634index 5119174..8e264f8 100644
77635--- a/include/linux/clk-provider.h
77636+++ b/include/linux/clk-provider.h
77637@@ -174,6 +174,7 @@ struct clk_ops {
77638 void (*init)(struct clk_hw *hw);
77639 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
77640 };
77641+typedef struct clk_ops __no_const clk_ops_no_const;
77642
77643 /**
77644 * struct clk_init_data - holds init data that's common to all clocks and is
77645diff --git a/include/linux/compat.h b/include/linux/compat.h
77646index e649426..a74047b 100644
77647--- a/include/linux/compat.h
77648+++ b/include/linux/compat.h
77649@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77650 compat_size_t __user *len_ptr);
77651
77652 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77653-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77654+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77655 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77656 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77657 compat_ssize_t msgsz, int msgflg);
77658@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77659 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77660 compat_ulong_t addr, compat_ulong_t data);
77661 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77662- compat_long_t addr, compat_long_t data);
77663+ compat_ulong_t addr, compat_ulong_t data);
77664
77665 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77666 /*
77667diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77668index 2507fd2..55203f8 100644
77669--- a/include/linux/compiler-gcc4.h
77670+++ b/include/linux/compiler-gcc4.h
77671@@ -39,9 +39,34 @@
77672 # define __compiletime_warning(message) __attribute__((warning(message)))
77673 # define __compiletime_error(message) __attribute__((error(message)))
77674 #endif /* __CHECKER__ */
77675+
77676+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77677+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77678+#define __bos0(ptr) __bos((ptr), 0)
77679+#define __bos1(ptr) __bos((ptr), 1)
77680 #endif /* GCC_VERSION >= 40300 */
77681
77682 #if GCC_VERSION >= 40500
77683+
77684+#ifdef RANDSTRUCT_PLUGIN
77685+#define __randomize_layout __attribute__((randomize_layout))
77686+#define __no_randomize_layout __attribute__((no_randomize_layout))
77687+#endif
77688+
77689+#ifdef CONSTIFY_PLUGIN
77690+#define __no_const __attribute__((no_const))
77691+#define __do_const __attribute__((do_const))
77692+#endif
77693+
77694+#ifdef SIZE_OVERFLOW_PLUGIN
77695+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77696+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77697+#endif
77698+
77699+#ifdef LATENT_ENTROPY_PLUGIN
77700+#define __latent_entropy __attribute__((latent_entropy))
77701+#endif
77702+
77703 /*
77704 * Mark a position in code as unreachable. This can be used to
77705 * suppress control flow warnings after asm blocks that transfer
77706diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77707index ee7239e..7c11769 100644
77708--- a/include/linux/compiler.h
77709+++ b/include/linux/compiler.h
77710@@ -5,11 +5,14 @@
77711
77712 #ifdef __CHECKER__
77713 # define __user __attribute__((noderef, address_space(1)))
77714+# define __force_user __force __user
77715 # define __kernel __attribute__((address_space(0)))
77716+# define __force_kernel __force __kernel
77717 # define __safe __attribute__((safe))
77718 # define __force __attribute__((force))
77719 # define __nocast __attribute__((nocast))
77720 # define __iomem __attribute__((noderef, address_space(2)))
77721+# define __force_iomem __force __iomem
77722 # define __must_hold(x) __attribute__((context(x,1,1)))
77723 # define __acquires(x) __attribute__((context(x,0,1)))
77724 # define __releases(x) __attribute__((context(x,1,0)))
77725@@ -17,20 +20,37 @@
77726 # define __release(x) __context__(x,-1)
77727 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77728 # define __percpu __attribute__((noderef, address_space(3)))
77729+# define __force_percpu __force __percpu
77730 #ifdef CONFIG_SPARSE_RCU_POINTER
77731 # define __rcu __attribute__((noderef, address_space(4)))
77732+# define __force_rcu __force __rcu
77733 #else
77734 # define __rcu
77735+# define __force_rcu
77736 #endif
77737 extern void __chk_user_ptr(const volatile void __user *);
77738 extern void __chk_io_ptr(const volatile void __iomem *);
77739 #else
77740-# define __user
77741-# define __kernel
77742+# ifdef CHECKER_PLUGIN
77743+//# define __user
77744+//# define __force_user
77745+//# define __kernel
77746+//# define __force_kernel
77747+# else
77748+# ifdef STRUCTLEAK_PLUGIN
77749+# define __user __attribute__((user))
77750+# else
77751+# define __user
77752+# endif
77753+# define __force_user
77754+# define __kernel
77755+# define __force_kernel
77756+# endif
77757 # define __safe
77758 # define __force
77759 # define __nocast
77760 # define __iomem
77761+# define __force_iomem
77762 # define __chk_user_ptr(x) (void)0
77763 # define __chk_io_ptr(x) (void)0
77764 # define __builtin_warning(x, y...) (1)
77765@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77766 # define __release(x) (void)0
77767 # define __cond_lock(x,c) (c)
77768 # define __percpu
77769+# define __force_percpu
77770 # define __rcu
77771+# define __force_rcu
77772 #endif
77773
77774 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77775@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77776 # define __attribute_const__ /* unimplemented */
77777 #endif
77778
77779+#ifndef __randomize_layout
77780+# define __randomize_layout
77781+#endif
77782+
77783+#ifndef __no_randomize_layout
77784+# define __no_randomize_layout
77785+#endif
77786+
77787+#ifndef __no_const
77788+# define __no_const
77789+#endif
77790+
77791+#ifndef __do_const
77792+# define __do_const
77793+#endif
77794+
77795+#ifndef __size_overflow
77796+# define __size_overflow(...)
77797+#endif
77798+
77799+#ifndef __intentional_overflow
77800+# define __intentional_overflow(...)
77801+#endif
77802+
77803+#ifndef __latent_entropy
77804+# define __latent_entropy
77805+#endif
77806+
77807 /*
77808 * Tell gcc if a function is cold. The compiler will assume any path
77809 * directly leading to the call is unlikely.
77810@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77811 #define __cold
77812 #endif
77813
77814+#ifndef __alloc_size
77815+#define __alloc_size(...)
77816+#endif
77817+
77818+#ifndef __bos
77819+#define __bos(ptr, arg)
77820+#endif
77821+
77822+#ifndef __bos0
77823+#define __bos0(ptr)
77824+#endif
77825+
77826+#ifndef __bos1
77827+#define __bos1(ptr)
77828+#endif
77829+
77830 /* Simple shorthand for a section definition */
77831 #ifndef __section
77832 # define __section(S) __attribute__ ((__section__(#S)))
77833@@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77834 * use is to mediate communication between process-level code and irq/NMI
77835 * handlers, all running on the same CPU.
77836 */
77837-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77838+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77839+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77840
77841 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77842 #ifdef CONFIG_KPROBES
77843diff --git a/include/linux/completion.h b/include/linux/completion.h
77844index 5d5aaae..0ea9b84 100644
77845--- a/include/linux/completion.h
77846+++ b/include/linux/completion.h
77847@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77848
77849 extern void wait_for_completion(struct completion *);
77850 extern void wait_for_completion_io(struct completion *);
77851-extern int wait_for_completion_interruptible(struct completion *x);
77852-extern int wait_for_completion_killable(struct completion *x);
77853+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77854+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77855 extern unsigned long wait_for_completion_timeout(struct completion *x,
77856- unsigned long timeout);
77857+ unsigned long timeout) __intentional_overflow(-1);
77858 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77859- unsigned long timeout);
77860+ unsigned long timeout) __intentional_overflow(-1);
77861 extern long wait_for_completion_interruptible_timeout(
77862- struct completion *x, unsigned long timeout);
77863+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77864 extern long wait_for_completion_killable_timeout(
77865- struct completion *x, unsigned long timeout);
77866+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77867 extern bool try_wait_for_completion(struct completion *x);
77868 extern bool completion_done(struct completion *x);
77869
77870diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77871index 34025df..d94bbbc 100644
77872--- a/include/linux/configfs.h
77873+++ b/include/linux/configfs.h
77874@@ -125,7 +125,7 @@ struct configfs_attribute {
77875 const char *ca_name;
77876 struct module *ca_owner;
77877 umode_t ca_mode;
77878-};
77879+} __do_const;
77880
77881 /*
77882 * Users often need to create attribute structures for their configurable
77883diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77884index 5ae5100..b809662 100644
77885--- a/include/linux/cpufreq.h
77886+++ b/include/linux/cpufreq.h
77887@@ -200,6 +200,7 @@ struct global_attr {
77888 ssize_t (*store)(struct kobject *a, struct attribute *b,
77889 const char *c, size_t count);
77890 };
77891+typedef struct global_attr __no_const global_attr_no_const;
77892
77893 #define define_one_global_ro(_name) \
77894 static struct global_attr _name = \
77895@@ -242,7 +243,7 @@ struct cpufreq_driver {
77896 bool boost_supported;
77897 bool boost_enabled;
77898 int (*set_boost) (int state);
77899-};
77900+} __do_const;
77901
77902 /* flags */
77903 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77904diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77905index b0238cb..db89e1e 100644
77906--- a/include/linux/cpuidle.h
77907+++ b/include/linux/cpuidle.h
77908@@ -50,7 +50,8 @@ struct cpuidle_state {
77909 int index);
77910
77911 int (*enter_dead) (struct cpuidle_device *dev, int index);
77912-};
77913+} __do_const;
77914+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77915
77916 /* Idle State Flags */
77917 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77918@@ -211,7 +212,7 @@ struct cpuidle_governor {
77919 void (*reflect) (struct cpuidle_device *dev, int index);
77920
77921 struct module *owner;
77922-};
77923+} __do_const;
77924
77925 #ifdef CONFIG_CPU_IDLE
77926 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77927diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77928index d08e4d2..95fad61 100644
77929--- a/include/linux/cpumask.h
77930+++ b/include/linux/cpumask.h
77931@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77932 }
77933
77934 /* Valid inputs for n are -1 and 0. */
77935-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77936+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77937 {
77938 return n+1;
77939 }
77940
77941-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77942+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77943 {
77944 return n+1;
77945 }
77946
77947-static inline unsigned int cpumask_next_and(int n,
77948+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77949 const struct cpumask *srcp,
77950 const struct cpumask *andp)
77951 {
77952@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77953 *
77954 * Returns >= nr_cpu_ids if no further cpus set.
77955 */
77956-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77957+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77958 {
77959 /* -1 is a legal arg here. */
77960 if (n != -1)
77961@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77962 *
77963 * Returns >= nr_cpu_ids if no further cpus unset.
77964 */
77965-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77966+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77967 {
77968 /* -1 is a legal arg here. */
77969 if (n != -1)
77970@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77971 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77972 }
77973
77974-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77975+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77976 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77977
77978 /**
77979diff --git a/include/linux/cred.h b/include/linux/cred.h
77980index f61d6c8..d372d95 100644
77981--- a/include/linux/cred.h
77982+++ b/include/linux/cred.h
77983@@ -35,7 +35,7 @@ struct group_info {
77984 int nblocks;
77985 kgid_t small_block[NGROUPS_SMALL];
77986 kgid_t *blocks[0];
77987-};
77988+} __randomize_layout;
77989
77990 /**
77991 * get_group_info - Get a reference to a group info structure
77992@@ -136,7 +136,7 @@ struct cred {
77993 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77994 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77995 struct rcu_head rcu; /* RCU deletion hook */
77996-};
77997+} __randomize_layout;
77998
77999 extern void __put_cred(struct cred *);
78000 extern void exit_creds(struct task_struct *);
78001@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78002 static inline void validate_process_creds(void)
78003 {
78004 }
78005+static inline void validate_task_creds(struct task_struct *task)
78006+{
78007+}
78008 #endif
78009
78010 /**
78011@@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
78012
78013 #define task_uid(task) (task_cred_xxx((task), uid))
78014 #define task_euid(task) (task_cred_xxx((task), euid))
78015+#define task_securebits(task) (task_cred_xxx((task), securebits))
78016
78017 #define current_cred_xxx(xxx) \
78018 ({ \
78019diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78020index b92eadf..b4ecdc1 100644
78021--- a/include/linux/crypto.h
78022+++ b/include/linux/crypto.h
78023@@ -373,7 +373,7 @@ struct cipher_tfm {
78024 const u8 *key, unsigned int keylen);
78025 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78026 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78027-};
78028+} __no_const;
78029
78030 struct hash_tfm {
78031 int (*init)(struct hash_desc *desc);
78032@@ -394,13 +394,13 @@ struct compress_tfm {
78033 int (*cot_decompress)(struct crypto_tfm *tfm,
78034 const u8 *src, unsigned int slen,
78035 u8 *dst, unsigned int *dlen);
78036-};
78037+} __no_const;
78038
78039 struct rng_tfm {
78040 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78041 unsigned int dlen);
78042 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78043-};
78044+} __no_const;
78045
78046 #define crt_ablkcipher crt_u.ablkcipher
78047 #define crt_aead crt_u.aead
78048diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78049index 653589e..4ef254a 100644
78050--- a/include/linux/ctype.h
78051+++ b/include/linux/ctype.h
78052@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78053 * Fast implementation of tolower() for internal usage. Do not use in your
78054 * code.
78055 */
78056-static inline char _tolower(const char c)
78057+static inline unsigned char _tolower(const unsigned char c)
78058 {
78059 return c | 0x20;
78060 }
78061diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78062index 3c7ec32..4ca97cc 100644
78063--- a/include/linux/dcache.h
78064+++ b/include/linux/dcache.h
78065@@ -133,7 +133,7 @@ struct dentry {
78066 } d_u;
78067 struct list_head d_subdirs; /* our children */
78068 struct hlist_node d_alias; /* inode alias list */
78069-};
78070+} __randomize_layout;
78071
78072 /*
78073 * dentry->d_lock spinlock nesting subclasses:
78074diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78075index 7925bf0..d5143d2 100644
78076--- a/include/linux/decompress/mm.h
78077+++ b/include/linux/decompress/mm.h
78078@@ -77,7 +77,7 @@ static void free(void *where)
78079 * warnings when not needed (indeed large_malloc / large_free are not
78080 * needed by inflate */
78081
78082-#define malloc(a) kmalloc(a, GFP_KERNEL)
78083+#define malloc(a) kmalloc((a), GFP_KERNEL)
78084 #define free(a) kfree(a)
78085
78086 #define large_malloc(a) vmalloc(a)
78087diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78088index d48dc00..211ee54 100644
78089--- a/include/linux/devfreq.h
78090+++ b/include/linux/devfreq.h
78091@@ -114,7 +114,7 @@ struct devfreq_governor {
78092 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78093 int (*event_handler)(struct devfreq *devfreq,
78094 unsigned int event, void *data);
78095-};
78096+} __do_const;
78097
78098 /**
78099 * struct devfreq - Device devfreq structure
78100diff --git a/include/linux/device.h b/include/linux/device.h
78101index d1d1c05..a90fdb0 100644
78102--- a/include/linux/device.h
78103+++ b/include/linux/device.h
78104@@ -310,7 +310,7 @@ struct subsys_interface {
78105 struct list_head node;
78106 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78107 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78108-};
78109+} __do_const;
78110
78111 int subsys_interface_register(struct subsys_interface *sif);
78112 void subsys_interface_unregister(struct subsys_interface *sif);
78113@@ -506,7 +506,7 @@ struct device_type {
78114 void (*release)(struct device *dev);
78115
78116 const struct dev_pm_ops *pm;
78117-};
78118+} __do_const;
78119
78120 /* interface for exporting device attributes */
78121 struct device_attribute {
78122@@ -516,11 +516,12 @@ struct device_attribute {
78123 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78124 const char *buf, size_t count);
78125 };
78126+typedef struct device_attribute __no_const device_attribute_no_const;
78127
78128 struct dev_ext_attribute {
78129 struct device_attribute attr;
78130 void *var;
78131-};
78132+} __do_const;
78133
78134 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78135 char *buf);
78136diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78137index fd4aee2..1f28db9 100644
78138--- a/include/linux/dma-mapping.h
78139+++ b/include/linux/dma-mapping.h
78140@@ -54,7 +54,7 @@ struct dma_map_ops {
78141 u64 (*get_required_mask)(struct device *dev);
78142 #endif
78143 int is_phys;
78144-};
78145+} __do_const;
78146
78147 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78148
78149diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78150index 72cb0dd..7fe9a4b 100644
78151--- a/include/linux/dmaengine.h
78152+++ b/include/linux/dmaengine.h
78153@@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78154 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78155 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78156
78157-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78158+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78159 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78160-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78161+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78162 struct dma_pinned_list *pinned_list, struct page *page,
78163 unsigned int offset, size_t len);
78164
78165diff --git a/include/linux/efi.h b/include/linux/efi.h
78166index 6c100ff..e3289b4 100644
78167--- a/include/linux/efi.h
78168+++ b/include/linux/efi.h
78169@@ -1009,6 +1009,7 @@ struct efivar_operations {
78170 efi_set_variable_t *set_variable;
78171 efi_query_variable_store_t *query_variable_store;
78172 };
78173+typedef struct efivar_operations __no_const efivar_operations_no_const;
78174
78175 struct efivars {
78176 /*
78177diff --git a/include/linux/elf.h b/include/linux/elf.h
78178index 67a5fa7..b817372 100644
78179--- a/include/linux/elf.h
78180+++ b/include/linux/elf.h
78181@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78182 #define elf_note elf32_note
78183 #define elf_addr_t Elf32_Off
78184 #define Elf_Half Elf32_Half
78185+#define elf_dyn Elf32_Dyn
78186
78187 #else
78188
78189@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78190 #define elf_note elf64_note
78191 #define elf_addr_t Elf64_Off
78192 #define Elf_Half Elf64_Half
78193+#define elf_dyn Elf64_Dyn
78194
78195 #endif
78196
78197diff --git a/include/linux/err.h b/include/linux/err.h
78198index a729120..6ede2c9 100644
78199--- a/include/linux/err.h
78200+++ b/include/linux/err.h
78201@@ -20,12 +20,12 @@
78202
78203 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78204
78205-static inline void * __must_check ERR_PTR(long error)
78206+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78207 {
78208 return (void *) error;
78209 }
78210
78211-static inline long __must_check PTR_ERR(__force const void *ptr)
78212+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78213 {
78214 return (long) ptr;
78215 }
78216diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78217index f488145..3b6b04e 100644
78218--- a/include/linux/extcon.h
78219+++ b/include/linux/extcon.h
78220@@ -135,7 +135,7 @@ struct extcon_dev {
78221 /* /sys/class/extcon/.../mutually_exclusive/... */
78222 struct attribute_group attr_g_muex;
78223 struct attribute **attrs_muex;
78224- struct device_attribute *d_attrs_muex;
78225+ device_attribute_no_const *d_attrs_muex;
78226 };
78227
78228 /**
78229diff --git a/include/linux/fb.h b/include/linux/fb.h
78230index fe6ac95..898d41d 100644
78231--- a/include/linux/fb.h
78232+++ b/include/linux/fb.h
78233@@ -304,7 +304,7 @@ struct fb_ops {
78234 /* called at KDB enter and leave time to prepare the console */
78235 int (*fb_debug_enter)(struct fb_info *info);
78236 int (*fb_debug_leave)(struct fb_info *info);
78237-};
78238+} __do_const;
78239
78240 #ifdef CONFIG_FB_TILEBLITTING
78241 #define FB_TILE_CURSOR_NONE 0
78242diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78243index 230f87b..1fd0485 100644
78244--- a/include/linux/fdtable.h
78245+++ b/include/linux/fdtable.h
78246@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78247 void put_files_struct(struct files_struct *fs);
78248 void reset_files_struct(struct files_struct *);
78249 int unshare_files(struct files_struct **);
78250-struct files_struct *dup_fd(struct files_struct *, int *);
78251+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78252 void do_close_on_exec(struct files_struct *);
78253 int iterate_fd(struct files_struct *, unsigned,
78254 int (*)(const void *, struct file *, unsigned),
78255diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78256index 8293262..2b3b8bd 100644
78257--- a/include/linux/frontswap.h
78258+++ b/include/linux/frontswap.h
78259@@ -11,7 +11,7 @@ struct frontswap_ops {
78260 int (*load)(unsigned, pgoff_t, struct page *);
78261 void (*invalidate_page)(unsigned, pgoff_t);
78262 void (*invalidate_area)(unsigned);
78263-};
78264+} __no_const;
78265
78266 extern bool frontswap_enabled;
78267 extern struct frontswap_ops *
78268diff --git a/include/linux/fs.h b/include/linux/fs.h
78269index 8780312..425cc22 100644
78270--- a/include/linux/fs.h
78271+++ b/include/linux/fs.h
78272@@ -398,7 +398,7 @@ struct address_space {
78273 spinlock_t private_lock; /* for use by the address_space */
78274 struct list_head private_list; /* ditto */
78275 void *private_data; /* ditto */
78276-} __attribute__((aligned(sizeof(long))));
78277+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78278 /*
78279 * On most architectures that alignment is already the case; but
78280 * must be enforced here for CRIS, to let the least significant bit
78281@@ -441,7 +441,7 @@ struct block_device {
78282 int bd_fsfreeze_count;
78283 /* Mutex for freeze */
78284 struct mutex bd_fsfreeze_mutex;
78285-};
78286+} __randomize_layout;
78287
78288 /*
78289 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78290@@ -585,7 +585,7 @@ struct inode {
78291 #endif
78292
78293 void *i_private; /* fs or device private pointer */
78294-};
78295+} __randomize_layout;
78296
78297 static inline int inode_unhashed(struct inode *inode)
78298 {
78299@@ -778,7 +778,7 @@ struct file {
78300 struct list_head f_tfile_llink;
78301 #endif /* #ifdef CONFIG_EPOLL */
78302 struct address_space *f_mapping;
78303-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78304+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78305
78306 struct file_handle {
78307 __u32 handle_bytes;
78308@@ -906,7 +906,7 @@ struct file_lock {
78309 int state; /* state of grant or error if -ve */
78310 } afs;
78311 } fl_u;
78312-};
78313+} __randomize_layout;
78314
78315 /* The following constant reflects the upper bound of the file/locking space */
78316 #ifndef OFFSET_MAX
78317@@ -1255,7 +1255,7 @@ struct super_block {
78318 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78319 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78320 struct rcu_head rcu;
78321-};
78322+} __randomize_layout;
78323
78324 extern struct timespec current_fs_time(struct super_block *sb);
78325
78326@@ -1477,7 +1477,8 @@ struct file_operations {
78327 long (*fallocate)(struct file *file, int mode, loff_t offset,
78328 loff_t len);
78329 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78330-};
78331+} __do_const __randomize_layout;
78332+typedef struct file_operations __no_const file_operations_no_const;
78333
78334 struct inode_operations {
78335 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78336@@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
78337 return !IS_DEADDIR(inode);
78338 }
78339
78340+static inline bool is_sidechannel_device(const struct inode *inode)
78341+{
78342+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78343+ umode_t mode = inode->i_mode;
78344+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78345+#else
78346+ return false;
78347+#endif
78348+}
78349+
78350 #endif /* _LINUX_FS_H */
78351diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78352index 0efc3e6..fd23610 100644
78353--- a/include/linux/fs_struct.h
78354+++ b/include/linux/fs_struct.h
78355@@ -6,13 +6,13 @@
78356 #include <linux/seqlock.h>
78357
78358 struct fs_struct {
78359- int users;
78360+ atomic_t users;
78361 spinlock_t lock;
78362 seqcount_t seq;
78363 int umask;
78364 int in_exec;
78365 struct path root, pwd;
78366-};
78367+} __randomize_layout;
78368
78369 extern struct kmem_cache *fs_cachep;
78370
78371diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78372index 7714849..a4a5c7a 100644
78373--- a/include/linux/fscache-cache.h
78374+++ b/include/linux/fscache-cache.h
78375@@ -113,7 +113,7 @@ struct fscache_operation {
78376 fscache_operation_release_t release;
78377 };
78378
78379-extern atomic_t fscache_op_debug_id;
78380+extern atomic_unchecked_t fscache_op_debug_id;
78381 extern void fscache_op_work_func(struct work_struct *work);
78382
78383 extern void fscache_enqueue_operation(struct fscache_operation *);
78384@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78385 INIT_WORK(&op->work, fscache_op_work_func);
78386 atomic_set(&op->usage, 1);
78387 op->state = FSCACHE_OP_ST_INITIALISED;
78388- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78389+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78390 op->processor = processor;
78391 op->release = release;
78392 INIT_LIST_HEAD(&op->pend_link);
78393diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78394index 115bb81..e7b812b 100644
78395--- a/include/linux/fscache.h
78396+++ b/include/linux/fscache.h
78397@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78398 * - this is mandatory for any object that may have data
78399 */
78400 void (*now_uncached)(void *cookie_netfs_data);
78401-};
78402+} __do_const;
78403
78404 /*
78405 * fscache cached network filesystem type
78406diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78407index 1c804b0..1432c2b 100644
78408--- a/include/linux/fsnotify.h
78409+++ b/include/linux/fsnotify.h
78410@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78411 struct inode *inode = file_inode(file);
78412 __u32 mask = FS_ACCESS;
78413
78414+ if (is_sidechannel_device(inode))
78415+ return;
78416+
78417 if (S_ISDIR(inode->i_mode))
78418 mask |= FS_ISDIR;
78419
78420@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78421 struct inode *inode = file_inode(file);
78422 __u32 mask = FS_MODIFY;
78423
78424+ if (is_sidechannel_device(inode))
78425+ return;
78426+
78427 if (S_ISDIR(inode->i_mode))
78428 mask |= FS_ISDIR;
78429
78430@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78431 */
78432 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78433 {
78434- return kstrdup(name, GFP_KERNEL);
78435+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78436 }
78437
78438 /*
78439diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78440index 9f3c275..8bdff5d 100644
78441--- a/include/linux/genhd.h
78442+++ b/include/linux/genhd.h
78443@@ -194,7 +194,7 @@ struct gendisk {
78444 struct kobject *slave_dir;
78445
78446 struct timer_rand_state *random;
78447- atomic_t sync_io; /* RAID */
78448+ atomic_unchecked_t sync_io; /* RAID */
78449 struct disk_events *ev;
78450 #ifdef CONFIG_BLK_DEV_INTEGRITY
78451 struct blk_integrity *integrity;
78452@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78453 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78454
78455 /* drivers/char/random.c */
78456-extern void add_disk_randomness(struct gendisk *disk);
78457+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78458 extern void rand_initialize_disk(struct gendisk *disk);
78459
78460 static inline sector_t get_start_sect(struct block_device *bdev)
78461diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78462index c0894dd..2fbf10c 100644
78463--- a/include/linux/genl_magic_func.h
78464+++ b/include/linux/genl_magic_func.h
78465@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78466 },
78467
78468 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78469-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78470+static struct genl_ops ZZZ_genl_ops[] = {
78471 #include GENL_MAGIC_INCLUDE_FILE
78472 };
78473
78474diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78475index 39b81dc..819dc51 100644
78476--- a/include/linux/gfp.h
78477+++ b/include/linux/gfp.h
78478@@ -36,6 +36,13 @@ struct vm_area_struct;
78479 #define ___GFP_NO_KSWAPD 0x400000u
78480 #define ___GFP_OTHER_NODE 0x800000u
78481 #define ___GFP_WRITE 0x1000000u
78482+
78483+#ifdef CONFIG_PAX_USERCOPY_SLABS
78484+#define ___GFP_USERCOPY 0x2000000u
78485+#else
78486+#define ___GFP_USERCOPY 0
78487+#endif
78488+
78489 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78490
78491 /*
78492@@ -93,6 +100,7 @@ struct vm_area_struct;
78493 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78494 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78495 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78496+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78497
78498 /*
78499 * This may seem redundant, but it's a way of annotating false positives vs.
78500@@ -100,7 +108,7 @@ struct vm_area_struct;
78501 */
78502 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78503
78504-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78505+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78506 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78507
78508 /* This equals 0, but use constants in case they ever change */
78509@@ -158,6 +166,8 @@ struct vm_area_struct;
78510 /* 4GB DMA on some platforms */
78511 #define GFP_DMA32 __GFP_DMA32
78512
78513+#define GFP_USERCOPY __GFP_USERCOPY
78514+
78515 /* Convert GFP flags to their corresponding migrate type */
78516 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78517 {
78518diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78519new file mode 100644
78520index 0000000..edb2cb6
78521--- /dev/null
78522+++ b/include/linux/gracl.h
78523@@ -0,0 +1,340 @@
78524+#ifndef GR_ACL_H
78525+#define GR_ACL_H
78526+
78527+#include <linux/grdefs.h>
78528+#include <linux/resource.h>
78529+#include <linux/capability.h>
78530+#include <linux/dcache.h>
78531+#include <asm/resource.h>
78532+
78533+/* Major status information */
78534+
78535+#define GR_VERSION "grsecurity 3.0"
78536+#define GRSECURITY_VERSION 0x3000
78537+
78538+enum {
78539+ GR_SHUTDOWN = 0,
78540+ GR_ENABLE = 1,
78541+ GR_SPROLE = 2,
78542+ GR_OLDRELOAD = 3,
78543+ GR_SEGVMOD = 4,
78544+ GR_STATUS = 5,
78545+ GR_UNSPROLE = 6,
78546+ GR_PASSSET = 7,
78547+ GR_SPROLEPAM = 8,
78548+ GR_RELOAD = 9,
78549+};
78550+
78551+/* Password setup definitions
78552+ * kernel/grhash.c */
78553+enum {
78554+ GR_PW_LEN = 128,
78555+ GR_SALT_LEN = 16,
78556+ GR_SHA_LEN = 32,
78557+};
78558+
78559+enum {
78560+ GR_SPROLE_LEN = 64,
78561+};
78562+
78563+enum {
78564+ GR_NO_GLOB = 0,
78565+ GR_REG_GLOB,
78566+ GR_CREATE_GLOB
78567+};
78568+
78569+#define GR_NLIMITS 32
78570+
78571+/* Begin Data Structures */
78572+
78573+struct sprole_pw {
78574+ unsigned char *rolename;
78575+ unsigned char salt[GR_SALT_LEN];
78576+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78577+};
78578+
78579+struct name_entry {
78580+ __u32 key;
78581+ ino_t inode;
78582+ dev_t device;
78583+ char *name;
78584+ __u16 len;
78585+ __u8 deleted;
78586+ struct name_entry *prev;
78587+ struct name_entry *next;
78588+};
78589+
78590+struct inodev_entry {
78591+ struct name_entry *nentry;
78592+ struct inodev_entry *prev;
78593+ struct inodev_entry *next;
78594+};
78595+
78596+struct acl_role_db {
78597+ struct acl_role_label **r_hash;
78598+ __u32 r_size;
78599+};
78600+
78601+struct inodev_db {
78602+ struct inodev_entry **i_hash;
78603+ __u32 i_size;
78604+};
78605+
78606+struct name_db {
78607+ struct name_entry **n_hash;
78608+ __u32 n_size;
78609+};
78610+
78611+struct crash_uid {
78612+ uid_t uid;
78613+ unsigned long expires;
78614+};
78615+
78616+struct gr_hash_struct {
78617+ void **table;
78618+ void **nametable;
78619+ void *first;
78620+ __u32 table_size;
78621+ __u32 used_size;
78622+ int type;
78623+};
78624+
78625+/* Userspace Grsecurity ACL data structures */
78626+
78627+struct acl_subject_label {
78628+ char *filename;
78629+ ino_t inode;
78630+ dev_t device;
78631+ __u32 mode;
78632+ kernel_cap_t cap_mask;
78633+ kernel_cap_t cap_lower;
78634+ kernel_cap_t cap_invert_audit;
78635+
78636+ struct rlimit res[GR_NLIMITS];
78637+ __u32 resmask;
78638+
78639+ __u8 user_trans_type;
78640+ __u8 group_trans_type;
78641+ uid_t *user_transitions;
78642+ gid_t *group_transitions;
78643+ __u16 user_trans_num;
78644+ __u16 group_trans_num;
78645+
78646+ __u32 sock_families[2];
78647+ __u32 ip_proto[8];
78648+ __u32 ip_type;
78649+ struct acl_ip_label **ips;
78650+ __u32 ip_num;
78651+ __u32 inaddr_any_override;
78652+
78653+ __u32 crashes;
78654+ unsigned long expires;
78655+
78656+ struct acl_subject_label *parent_subject;
78657+ struct gr_hash_struct *hash;
78658+ struct acl_subject_label *prev;
78659+ struct acl_subject_label *next;
78660+
78661+ struct acl_object_label **obj_hash;
78662+ __u32 obj_hash_size;
78663+ __u16 pax_flags;
78664+};
78665+
78666+struct role_allowed_ip {
78667+ __u32 addr;
78668+ __u32 netmask;
78669+
78670+ struct role_allowed_ip *prev;
78671+ struct role_allowed_ip *next;
78672+};
78673+
78674+struct role_transition {
78675+ char *rolename;
78676+
78677+ struct role_transition *prev;
78678+ struct role_transition *next;
78679+};
78680+
78681+struct acl_role_label {
78682+ char *rolename;
78683+ uid_t uidgid;
78684+ __u16 roletype;
78685+
78686+ __u16 auth_attempts;
78687+ unsigned long expires;
78688+
78689+ struct acl_subject_label *root_label;
78690+ struct gr_hash_struct *hash;
78691+
78692+ struct acl_role_label *prev;
78693+ struct acl_role_label *next;
78694+
78695+ struct role_transition *transitions;
78696+ struct role_allowed_ip *allowed_ips;
78697+ uid_t *domain_children;
78698+ __u16 domain_child_num;
78699+
78700+ umode_t umask;
78701+
78702+ struct acl_subject_label **subj_hash;
78703+ __u32 subj_hash_size;
78704+};
78705+
78706+struct user_acl_role_db {
78707+ struct acl_role_label **r_table;
78708+ __u32 num_pointers; /* Number of allocations to track */
78709+ __u32 num_roles; /* Number of roles */
78710+ __u32 num_domain_children; /* Number of domain children */
78711+ __u32 num_subjects; /* Number of subjects */
78712+ __u32 num_objects; /* Number of objects */
78713+};
78714+
78715+struct acl_object_label {
78716+ char *filename;
78717+ ino_t inode;
78718+ dev_t device;
78719+ __u32 mode;
78720+
78721+ struct acl_subject_label *nested;
78722+ struct acl_object_label *globbed;
78723+
78724+ /* next two structures not used */
78725+
78726+ struct acl_object_label *prev;
78727+ struct acl_object_label *next;
78728+};
78729+
78730+struct acl_ip_label {
78731+ char *iface;
78732+ __u32 addr;
78733+ __u32 netmask;
78734+ __u16 low, high;
78735+ __u8 mode;
78736+ __u32 type;
78737+ __u32 proto[8];
78738+
78739+ /* next two structures not used */
78740+
78741+ struct acl_ip_label *prev;
78742+ struct acl_ip_label *next;
78743+};
78744+
78745+struct gr_arg {
78746+ struct user_acl_role_db role_db;
78747+ unsigned char pw[GR_PW_LEN];
78748+ unsigned char salt[GR_SALT_LEN];
78749+ unsigned char sum[GR_SHA_LEN];
78750+ unsigned char sp_role[GR_SPROLE_LEN];
78751+ struct sprole_pw *sprole_pws;
78752+ dev_t segv_device;
78753+ ino_t segv_inode;
78754+ uid_t segv_uid;
78755+ __u16 num_sprole_pws;
78756+ __u16 mode;
78757+};
78758+
78759+struct gr_arg_wrapper {
78760+ struct gr_arg *arg;
78761+ __u32 version;
78762+ __u32 size;
78763+};
78764+
78765+struct subject_map {
78766+ struct acl_subject_label *user;
78767+ struct acl_subject_label *kernel;
78768+ struct subject_map *prev;
78769+ struct subject_map *next;
78770+};
78771+
78772+struct acl_subj_map_db {
78773+ struct subject_map **s_hash;
78774+ __u32 s_size;
78775+};
78776+
78777+struct gr_policy_state {
78778+ struct sprole_pw **acl_special_roles;
78779+ __u16 num_sprole_pws;
78780+ struct acl_role_label *kernel_role;
78781+ struct acl_role_label *role_list;
78782+ struct acl_role_label *default_role;
78783+ struct acl_role_db acl_role_set;
78784+ struct acl_subj_map_db subj_map_set;
78785+ struct name_db name_set;
78786+ struct inodev_db inodev_set;
78787+};
78788+
78789+struct gr_alloc_state {
78790+ unsigned long alloc_stack_next;
78791+ unsigned long alloc_stack_size;
78792+ void **alloc_stack;
78793+};
78794+
78795+struct gr_reload_state {
78796+ struct gr_policy_state oldpolicy;
78797+ struct gr_alloc_state oldalloc;
78798+ struct gr_policy_state newpolicy;
78799+ struct gr_alloc_state newalloc;
78800+ struct gr_policy_state *oldpolicy_ptr;
78801+ struct gr_alloc_state *oldalloc_ptr;
78802+ unsigned char oldmode;
78803+};
78804+
78805+/* End Data Structures Section */
78806+
78807+/* Hash functions generated by empirical testing by Brad Spengler
78808+ Makes good use of the low bits of the inode. Generally 0-1 times
78809+ in loop for successful match. 0-3 for unsuccessful match.
78810+ Shift/add algorithm with modulus of table size and an XOR*/
78811+
78812+static __inline__ unsigned int
78813+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78814+{
78815+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
78816+}
78817+
78818+ static __inline__ unsigned int
78819+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78820+{
78821+ return ((const unsigned long)userp % sz);
78822+}
78823+
78824+static __inline__ unsigned int
78825+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78826+{
78827+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78828+}
78829+
78830+static __inline__ unsigned int
78831+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78832+{
78833+ return full_name_hash((const unsigned char *)name, len) % sz;
78834+}
78835+
78836+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78837+ subj = NULL; \
78838+ iter = 0; \
78839+ while (iter < role->subj_hash_size) { \
78840+ if (subj == NULL) \
78841+ subj = role->subj_hash[iter]; \
78842+ if (subj == NULL) { \
78843+ iter++; \
78844+ continue; \
78845+ }
78846+
78847+#define FOR_EACH_SUBJECT_END(subj,iter) \
78848+ subj = subj->next; \
78849+ if (subj == NULL) \
78850+ iter++; \
78851+ }
78852+
78853+
78854+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78855+ subj = role->hash->first; \
78856+ while (subj != NULL) {
78857+
78858+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78859+ subj = subj->next; \
78860+ }
78861+
78862+#endif
78863+
78864diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78865new file mode 100644
78866index 0000000..33ebd1f
78867--- /dev/null
78868+++ b/include/linux/gracl_compat.h
78869@@ -0,0 +1,156 @@
78870+#ifndef GR_ACL_COMPAT_H
78871+#define GR_ACL_COMPAT_H
78872+
78873+#include <linux/resource.h>
78874+#include <asm/resource.h>
78875+
78876+struct sprole_pw_compat {
78877+ compat_uptr_t rolename;
78878+ unsigned char salt[GR_SALT_LEN];
78879+ unsigned char sum[GR_SHA_LEN];
78880+};
78881+
78882+struct gr_hash_struct_compat {
78883+ compat_uptr_t table;
78884+ compat_uptr_t nametable;
78885+ compat_uptr_t first;
78886+ __u32 table_size;
78887+ __u32 used_size;
78888+ int type;
78889+};
78890+
78891+struct acl_subject_label_compat {
78892+ compat_uptr_t filename;
78893+ compat_ino_t inode;
78894+ __u32 device;
78895+ __u32 mode;
78896+ kernel_cap_t cap_mask;
78897+ kernel_cap_t cap_lower;
78898+ kernel_cap_t cap_invert_audit;
78899+
78900+ struct compat_rlimit res[GR_NLIMITS];
78901+ __u32 resmask;
78902+
78903+ __u8 user_trans_type;
78904+ __u8 group_trans_type;
78905+ compat_uptr_t user_transitions;
78906+ compat_uptr_t group_transitions;
78907+ __u16 user_trans_num;
78908+ __u16 group_trans_num;
78909+
78910+ __u32 sock_families[2];
78911+ __u32 ip_proto[8];
78912+ __u32 ip_type;
78913+ compat_uptr_t ips;
78914+ __u32 ip_num;
78915+ __u32 inaddr_any_override;
78916+
78917+ __u32 crashes;
78918+ compat_ulong_t expires;
78919+
78920+ compat_uptr_t parent_subject;
78921+ compat_uptr_t hash;
78922+ compat_uptr_t prev;
78923+ compat_uptr_t next;
78924+
78925+ compat_uptr_t obj_hash;
78926+ __u32 obj_hash_size;
78927+ __u16 pax_flags;
78928+};
78929+
78930+struct role_allowed_ip_compat {
78931+ __u32 addr;
78932+ __u32 netmask;
78933+
78934+ compat_uptr_t prev;
78935+ compat_uptr_t next;
78936+};
78937+
78938+struct role_transition_compat {
78939+ compat_uptr_t rolename;
78940+
78941+ compat_uptr_t prev;
78942+ compat_uptr_t next;
78943+};
78944+
78945+struct acl_role_label_compat {
78946+ compat_uptr_t rolename;
78947+ uid_t uidgid;
78948+ __u16 roletype;
78949+
78950+ __u16 auth_attempts;
78951+ compat_ulong_t expires;
78952+
78953+ compat_uptr_t root_label;
78954+ compat_uptr_t hash;
78955+
78956+ compat_uptr_t prev;
78957+ compat_uptr_t next;
78958+
78959+ compat_uptr_t transitions;
78960+ compat_uptr_t allowed_ips;
78961+ compat_uptr_t domain_children;
78962+ __u16 domain_child_num;
78963+
78964+ umode_t umask;
78965+
78966+ compat_uptr_t subj_hash;
78967+ __u32 subj_hash_size;
78968+};
78969+
78970+struct user_acl_role_db_compat {
78971+ compat_uptr_t r_table;
78972+ __u32 num_pointers;
78973+ __u32 num_roles;
78974+ __u32 num_domain_children;
78975+ __u32 num_subjects;
78976+ __u32 num_objects;
78977+};
78978+
78979+struct acl_object_label_compat {
78980+ compat_uptr_t filename;
78981+ compat_ino_t inode;
78982+ __u32 device;
78983+ __u32 mode;
78984+
78985+ compat_uptr_t nested;
78986+ compat_uptr_t globbed;
78987+
78988+ compat_uptr_t prev;
78989+ compat_uptr_t next;
78990+};
78991+
78992+struct acl_ip_label_compat {
78993+ compat_uptr_t iface;
78994+ __u32 addr;
78995+ __u32 netmask;
78996+ __u16 low, high;
78997+ __u8 mode;
78998+ __u32 type;
78999+ __u32 proto[8];
79000+
79001+ compat_uptr_t prev;
79002+ compat_uptr_t next;
79003+};
79004+
79005+struct gr_arg_compat {
79006+ struct user_acl_role_db_compat role_db;
79007+ unsigned char pw[GR_PW_LEN];
79008+ unsigned char salt[GR_SALT_LEN];
79009+ unsigned char sum[GR_SHA_LEN];
79010+ unsigned char sp_role[GR_SPROLE_LEN];
79011+ compat_uptr_t sprole_pws;
79012+ __u32 segv_device;
79013+ compat_ino_t segv_inode;
79014+ uid_t segv_uid;
79015+ __u16 num_sprole_pws;
79016+ __u16 mode;
79017+};
79018+
79019+struct gr_arg_wrapper_compat {
79020+ compat_uptr_t arg;
79021+ __u32 version;
79022+ __u32 size;
79023+};
79024+
79025+#endif
79026diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79027new file mode 100644
79028index 0000000..323ecf2
79029--- /dev/null
79030+++ b/include/linux/gralloc.h
79031@@ -0,0 +1,9 @@
79032+#ifndef __GRALLOC_H
79033+#define __GRALLOC_H
79034+
79035+void acl_free_all(void);
79036+int acl_alloc_stack_init(unsigned long size);
79037+void *acl_alloc(unsigned long len);
79038+void *acl_alloc_num(unsigned long num, unsigned long len);
79039+
79040+#endif
79041diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79042new file mode 100644
79043index 0000000..be66033
79044--- /dev/null
79045+++ b/include/linux/grdefs.h
79046@@ -0,0 +1,140 @@
79047+#ifndef GRDEFS_H
79048+#define GRDEFS_H
79049+
79050+/* Begin grsecurity status declarations */
79051+
79052+enum {
79053+ GR_READY = 0x01,
79054+ GR_STATUS_INIT = 0x00 // disabled state
79055+};
79056+
79057+/* Begin ACL declarations */
79058+
79059+/* Role flags */
79060+
79061+enum {
79062+ GR_ROLE_USER = 0x0001,
79063+ GR_ROLE_GROUP = 0x0002,
79064+ GR_ROLE_DEFAULT = 0x0004,
79065+ GR_ROLE_SPECIAL = 0x0008,
79066+ GR_ROLE_AUTH = 0x0010,
79067+ GR_ROLE_NOPW = 0x0020,
79068+ GR_ROLE_GOD = 0x0040,
79069+ GR_ROLE_LEARN = 0x0080,
79070+ GR_ROLE_TPE = 0x0100,
79071+ GR_ROLE_DOMAIN = 0x0200,
79072+ GR_ROLE_PAM = 0x0400,
79073+ GR_ROLE_PERSIST = 0x0800
79074+};
79075+
79076+/* ACL Subject and Object mode flags */
79077+enum {
79078+ GR_DELETED = 0x80000000
79079+};
79080+
79081+/* ACL Object-only mode flags */
79082+enum {
79083+ GR_READ = 0x00000001,
79084+ GR_APPEND = 0x00000002,
79085+ GR_WRITE = 0x00000004,
79086+ GR_EXEC = 0x00000008,
79087+ GR_FIND = 0x00000010,
79088+ GR_INHERIT = 0x00000020,
79089+ GR_SETID = 0x00000040,
79090+ GR_CREATE = 0x00000080,
79091+ GR_DELETE = 0x00000100,
79092+ GR_LINK = 0x00000200,
79093+ GR_AUDIT_READ = 0x00000400,
79094+ GR_AUDIT_APPEND = 0x00000800,
79095+ GR_AUDIT_WRITE = 0x00001000,
79096+ GR_AUDIT_EXEC = 0x00002000,
79097+ GR_AUDIT_FIND = 0x00004000,
79098+ GR_AUDIT_INHERIT= 0x00008000,
79099+ GR_AUDIT_SETID = 0x00010000,
79100+ GR_AUDIT_CREATE = 0x00020000,
79101+ GR_AUDIT_DELETE = 0x00040000,
79102+ GR_AUDIT_LINK = 0x00080000,
79103+ GR_PTRACERD = 0x00100000,
79104+ GR_NOPTRACE = 0x00200000,
79105+ GR_SUPPRESS = 0x00400000,
79106+ GR_NOLEARN = 0x00800000,
79107+ GR_INIT_TRANSFER= 0x01000000
79108+};
79109+
79110+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79111+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79112+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79113+
79114+/* ACL subject-only mode flags */
79115+enum {
79116+ GR_KILL = 0x00000001,
79117+ GR_VIEW = 0x00000002,
79118+ GR_PROTECTED = 0x00000004,
79119+ GR_LEARN = 0x00000008,
79120+ GR_OVERRIDE = 0x00000010,
79121+ /* just a placeholder, this mode is only used in userspace */
79122+ GR_DUMMY = 0x00000020,
79123+ GR_PROTSHM = 0x00000040,
79124+ GR_KILLPROC = 0x00000080,
79125+ GR_KILLIPPROC = 0x00000100,
79126+ /* just a placeholder, this mode is only used in userspace */
79127+ GR_NOTROJAN = 0x00000200,
79128+ GR_PROTPROCFD = 0x00000400,
79129+ GR_PROCACCT = 0x00000800,
79130+ GR_RELAXPTRACE = 0x00001000,
79131+ //GR_NESTED = 0x00002000,
79132+ GR_INHERITLEARN = 0x00004000,
79133+ GR_PROCFIND = 0x00008000,
79134+ GR_POVERRIDE = 0x00010000,
79135+ GR_KERNELAUTH = 0x00020000,
79136+ GR_ATSECURE = 0x00040000,
79137+ GR_SHMEXEC = 0x00080000
79138+};
79139+
79140+enum {
79141+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79142+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79143+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79144+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79145+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79146+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79147+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79148+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79149+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79150+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79151+};
79152+
79153+enum {
79154+ GR_ID_USER = 0x01,
79155+ GR_ID_GROUP = 0x02,
79156+};
79157+
79158+enum {
79159+ GR_ID_ALLOW = 0x01,
79160+ GR_ID_DENY = 0x02,
79161+};
79162+
79163+#define GR_CRASH_RES 31
79164+#define GR_UIDTABLE_MAX 500
79165+
79166+/* begin resource learning section */
79167+enum {
79168+ GR_RLIM_CPU_BUMP = 60,
79169+ GR_RLIM_FSIZE_BUMP = 50000,
79170+ GR_RLIM_DATA_BUMP = 10000,
79171+ GR_RLIM_STACK_BUMP = 1000,
79172+ GR_RLIM_CORE_BUMP = 10000,
79173+ GR_RLIM_RSS_BUMP = 500000,
79174+ GR_RLIM_NPROC_BUMP = 1,
79175+ GR_RLIM_NOFILE_BUMP = 5,
79176+ GR_RLIM_MEMLOCK_BUMP = 50000,
79177+ GR_RLIM_AS_BUMP = 500000,
79178+ GR_RLIM_LOCKS_BUMP = 2,
79179+ GR_RLIM_SIGPENDING_BUMP = 5,
79180+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79181+ GR_RLIM_NICE_BUMP = 1,
79182+ GR_RLIM_RTPRIO_BUMP = 1,
79183+ GR_RLIM_RTTIME_BUMP = 1000000
79184+};
79185+
79186+#endif
79187diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79188new file mode 100644
79189index 0000000..d25522e
79190--- /dev/null
79191+++ b/include/linux/grinternal.h
79192@@ -0,0 +1,229 @@
79193+#ifndef __GRINTERNAL_H
79194+#define __GRINTERNAL_H
79195+
79196+#ifdef CONFIG_GRKERNSEC
79197+
79198+#include <linux/fs.h>
79199+#include <linux/mnt_namespace.h>
79200+#include <linux/nsproxy.h>
79201+#include <linux/gracl.h>
79202+#include <linux/grdefs.h>
79203+#include <linux/grmsg.h>
79204+
79205+void gr_add_learn_entry(const char *fmt, ...)
79206+ __attribute__ ((format (printf, 1, 2)));
79207+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79208+ const struct vfsmount *mnt);
79209+__u32 gr_check_create(const struct dentry *new_dentry,
79210+ const struct dentry *parent,
79211+ const struct vfsmount *mnt, const __u32 mode);
79212+int gr_check_protected_task(const struct task_struct *task);
79213+__u32 to_gr_audit(const __u32 reqmode);
79214+int gr_set_acls(const int type);
79215+int gr_acl_is_enabled(void);
79216+char gr_roletype_to_char(void);
79217+
79218+void gr_handle_alertkill(struct task_struct *task);
79219+char *gr_to_filename(const struct dentry *dentry,
79220+ const struct vfsmount *mnt);
79221+char *gr_to_filename1(const struct dentry *dentry,
79222+ const struct vfsmount *mnt);
79223+char *gr_to_filename2(const struct dentry *dentry,
79224+ const struct vfsmount *mnt);
79225+char *gr_to_filename3(const struct dentry *dentry,
79226+ const struct vfsmount *mnt);
79227+
79228+extern int grsec_enable_ptrace_readexec;
79229+extern int grsec_enable_harden_ptrace;
79230+extern int grsec_enable_link;
79231+extern int grsec_enable_fifo;
79232+extern int grsec_enable_execve;
79233+extern int grsec_enable_shm;
79234+extern int grsec_enable_execlog;
79235+extern int grsec_enable_signal;
79236+extern int grsec_enable_audit_ptrace;
79237+extern int grsec_enable_forkfail;
79238+extern int grsec_enable_time;
79239+extern int grsec_enable_rofs;
79240+extern int grsec_deny_new_usb;
79241+extern int grsec_enable_chroot_shmat;
79242+extern int grsec_enable_chroot_mount;
79243+extern int grsec_enable_chroot_double;
79244+extern int grsec_enable_chroot_pivot;
79245+extern int grsec_enable_chroot_chdir;
79246+extern int grsec_enable_chroot_chmod;
79247+extern int grsec_enable_chroot_mknod;
79248+extern int grsec_enable_chroot_fchdir;
79249+extern int grsec_enable_chroot_nice;
79250+extern int grsec_enable_chroot_execlog;
79251+extern int grsec_enable_chroot_caps;
79252+extern int grsec_enable_chroot_sysctl;
79253+extern int grsec_enable_chroot_unix;
79254+extern int grsec_enable_symlinkown;
79255+extern kgid_t grsec_symlinkown_gid;
79256+extern int grsec_enable_tpe;
79257+extern kgid_t grsec_tpe_gid;
79258+extern int grsec_enable_tpe_all;
79259+extern int grsec_enable_tpe_invert;
79260+extern int grsec_enable_socket_all;
79261+extern kgid_t grsec_socket_all_gid;
79262+extern int grsec_enable_socket_client;
79263+extern kgid_t grsec_socket_client_gid;
79264+extern int grsec_enable_socket_server;
79265+extern kgid_t grsec_socket_server_gid;
79266+extern kgid_t grsec_audit_gid;
79267+extern int grsec_enable_group;
79268+extern int grsec_enable_log_rwxmaps;
79269+extern int grsec_enable_mount;
79270+extern int grsec_enable_chdir;
79271+extern int grsec_resource_logging;
79272+extern int grsec_enable_blackhole;
79273+extern int grsec_lastack_retries;
79274+extern int grsec_enable_brute;
79275+extern int grsec_enable_harden_ipc;
79276+extern int grsec_lock;
79277+
79278+extern spinlock_t grsec_alert_lock;
79279+extern unsigned long grsec_alert_wtime;
79280+extern unsigned long grsec_alert_fyet;
79281+
79282+extern spinlock_t grsec_audit_lock;
79283+
79284+extern rwlock_t grsec_exec_file_lock;
79285+
79286+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79287+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79288+ (tsk)->exec_file->f_path.mnt) : "/")
79289+
79290+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79291+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79292+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79293+
79294+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79295+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79296+ (tsk)->exec_file->f_path.mnt) : "/")
79297+
79298+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79299+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79300+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79301+
79302+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79303+
79304+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79305+
79306+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79307+{
79308+ if (file1 && file2) {
79309+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79310+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79311+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79312+ return true;
79313+ }
79314+
79315+ return false;
79316+}
79317+
79318+#define GR_CHROOT_CAPS {{ \
79319+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79320+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79321+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79322+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79323+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79324+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79325+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79326+
79327+#define security_learn(normal_msg,args...) \
79328+({ \
79329+ read_lock(&grsec_exec_file_lock); \
79330+ gr_add_learn_entry(normal_msg "\n", ## args); \
79331+ read_unlock(&grsec_exec_file_lock); \
79332+})
79333+
79334+enum {
79335+ GR_DO_AUDIT,
79336+ GR_DONT_AUDIT,
79337+ /* used for non-audit messages that we shouldn't kill the task on */
79338+ GR_DONT_AUDIT_GOOD
79339+};
79340+
79341+enum {
79342+ GR_TTYSNIFF,
79343+ GR_RBAC,
79344+ GR_RBAC_STR,
79345+ GR_STR_RBAC,
79346+ GR_RBAC_MODE2,
79347+ GR_RBAC_MODE3,
79348+ GR_FILENAME,
79349+ GR_SYSCTL_HIDDEN,
79350+ GR_NOARGS,
79351+ GR_ONE_INT,
79352+ GR_ONE_INT_TWO_STR,
79353+ GR_ONE_STR,
79354+ GR_STR_INT,
79355+ GR_TWO_STR_INT,
79356+ GR_TWO_INT,
79357+ GR_TWO_U64,
79358+ GR_THREE_INT,
79359+ GR_FIVE_INT_TWO_STR,
79360+ GR_TWO_STR,
79361+ GR_THREE_STR,
79362+ GR_FOUR_STR,
79363+ GR_STR_FILENAME,
79364+ GR_FILENAME_STR,
79365+ GR_FILENAME_TWO_INT,
79366+ GR_FILENAME_TWO_INT_STR,
79367+ GR_TEXTREL,
79368+ GR_PTRACE,
79369+ GR_RESOURCE,
79370+ GR_CAP,
79371+ GR_SIG,
79372+ GR_SIG2,
79373+ GR_CRASH1,
79374+ GR_CRASH2,
79375+ GR_PSACCT,
79376+ GR_RWXMAP,
79377+ GR_RWXMAPVMA
79378+};
79379+
79380+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79381+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79382+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79383+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79384+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79385+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79386+#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)
79387+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79388+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79389+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79390+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79391+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79392+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79393+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79394+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79395+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79396+#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)
79397+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79398+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79399+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79400+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79401+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79402+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79403+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79404+#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)
79405+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79406+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79407+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79408+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79409+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79410+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79411+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79412+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79413+#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)
79414+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79415+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79416+
79417+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79418+
79419+#endif
79420+
79421+#endif
79422diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79423new file mode 100644
79424index 0000000..b02ba9d
79425--- /dev/null
79426+++ b/include/linux/grmsg.h
79427@@ -0,0 +1,117 @@
79428+#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"
79429+#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"
79430+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79431+#define GR_STOPMOD_MSG "denied modification of module state by "
79432+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79433+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79434+#define GR_IOPERM_MSG "denied use of ioperm() by "
79435+#define GR_IOPL_MSG "denied use of iopl() by "
79436+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79437+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79438+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79439+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79440+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79441+#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"
79442+#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"
79443+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79444+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79445+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79446+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79447+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79448+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79449+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79450+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79451+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79452+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79453+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79454+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79455+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79456+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79457+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79458+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79459+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79460+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79461+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79462+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79463+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79464+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79465+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79466+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79467+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79468+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79469+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79470+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79471+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79472+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79473+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79474+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
79475+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79476+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79477+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79478+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79479+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79480+#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"
79481+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79482+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79483+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79484+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79485+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79486+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79487+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79488+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79489+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79490+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79491+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79492+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79493+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79494+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79495+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79496+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79497+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79498+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79499+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79500+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79501+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79502+#define GR_NICE_CHROOT_MSG "denied priority change by "
79503+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79504+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79505+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79506+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79507+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79508+#define GR_TIME_MSG "time set by "
79509+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79510+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79511+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79512+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79513+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79514+#define GR_BIND_MSG "denied bind() by "
79515+#define GR_CONNECT_MSG "denied connect() by "
79516+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79517+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79518+#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"
79519+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79520+#define GR_CAP_ACL_MSG "use of %s denied for "
79521+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79522+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79523+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79524+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79525+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79526+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79527+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79528+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79529+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79530+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79531+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79532+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79533+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79534+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79535+#define GR_VM86_MSG "denied use of vm86 by "
79536+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79537+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79538+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79539+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79540+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79541+#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 "
79542+#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 "
79543+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79544+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79545diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79546new file mode 100644
79547index 0000000..13ac2e2
79548--- /dev/null
79549+++ b/include/linux/grsecurity.h
79550@@ -0,0 +1,249 @@
79551+#ifndef GR_SECURITY_H
79552+#define GR_SECURITY_H
79553+#include <linux/fs.h>
79554+#include <linux/fs_struct.h>
79555+#include <linux/binfmts.h>
79556+#include <linux/gracl.h>
79557+
79558+/* notify of brain-dead configs */
79559+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79560+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79561+#endif
79562+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79563+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79564+#endif
79565+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79566+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79567+#endif
79568+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79569+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79570+#endif
79571+
79572+int gr_handle_new_usb(void);
79573+
79574+void gr_handle_brute_attach(int dumpable);
79575+void gr_handle_brute_check(void);
79576+void gr_handle_kernel_exploit(void);
79577+
79578+char gr_roletype_to_char(void);
79579+
79580+int gr_proc_is_restricted(void);
79581+
79582+int gr_acl_enable_at_secure(void);
79583+
79584+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79585+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79586+
79587+void gr_del_task_from_ip_table(struct task_struct *p);
79588+
79589+int gr_pid_is_chrooted(struct task_struct *p);
79590+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79591+int gr_handle_chroot_nice(void);
79592+int gr_handle_chroot_sysctl(const int op);
79593+int gr_handle_chroot_setpriority(struct task_struct *p,
79594+ const int niceval);
79595+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79596+int gr_chroot_fhandle(void);
79597+int gr_handle_chroot_chroot(const struct dentry *dentry,
79598+ const struct vfsmount *mnt);
79599+void gr_handle_chroot_chdir(const struct path *path);
79600+int gr_handle_chroot_chmod(const struct dentry *dentry,
79601+ const struct vfsmount *mnt, const int mode);
79602+int gr_handle_chroot_mknod(const struct dentry *dentry,
79603+ const struct vfsmount *mnt, const int mode);
79604+int gr_handle_chroot_mount(const struct dentry *dentry,
79605+ const struct vfsmount *mnt,
79606+ const char *dev_name);
79607+int gr_handle_chroot_pivot(void);
79608+int gr_handle_chroot_unix(const pid_t pid);
79609+
79610+int gr_handle_rawio(const struct inode *inode);
79611+
79612+void gr_handle_ioperm(void);
79613+void gr_handle_iopl(void);
79614+void gr_handle_msr_write(void);
79615+
79616+umode_t gr_acl_umask(void);
79617+
79618+int gr_tpe_allow(const struct file *file);
79619+
79620+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79621+void gr_clear_chroot_entries(struct task_struct *task);
79622+
79623+void gr_log_forkfail(const int retval);
79624+void gr_log_timechange(void);
79625+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79626+void gr_log_chdir(const struct dentry *dentry,
79627+ const struct vfsmount *mnt);
79628+void gr_log_chroot_exec(const struct dentry *dentry,
79629+ const struct vfsmount *mnt);
79630+void gr_log_remount(const char *devname, const int retval);
79631+void gr_log_unmount(const char *devname, const int retval);
79632+void gr_log_mount(const char *from, const char *to, const int retval);
79633+void gr_log_textrel(struct vm_area_struct *vma);
79634+void gr_log_ptgnustack(struct file *file);
79635+void gr_log_rwxmmap(struct file *file);
79636+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79637+
79638+int gr_handle_follow_link(const struct inode *parent,
79639+ const struct inode *inode,
79640+ const struct dentry *dentry,
79641+ const struct vfsmount *mnt);
79642+int gr_handle_fifo(const struct dentry *dentry,
79643+ const struct vfsmount *mnt,
79644+ const struct dentry *dir, const int flag,
79645+ const int acc_mode);
79646+int gr_handle_hardlink(const struct dentry *dentry,
79647+ const struct vfsmount *mnt,
79648+ struct inode *inode,
79649+ const int mode, const struct filename *to);
79650+
79651+int gr_is_capable(const int cap);
79652+int gr_is_capable_nolog(const int cap);
79653+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79654+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79655+
79656+void gr_copy_label(struct task_struct *tsk);
79657+void gr_handle_crash(struct task_struct *task, const int sig);
79658+int gr_handle_signal(const struct task_struct *p, const int sig);
79659+int gr_check_crash_uid(const kuid_t uid);
79660+int gr_check_protected_task(const struct task_struct *task);
79661+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79662+int gr_acl_handle_mmap(const struct file *file,
79663+ const unsigned long prot);
79664+int gr_acl_handle_mprotect(const struct file *file,
79665+ const unsigned long prot);
79666+int gr_check_hidden_task(const struct task_struct *tsk);
79667+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79668+ const struct vfsmount *mnt);
79669+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79670+ const struct vfsmount *mnt);
79671+__u32 gr_acl_handle_access(const struct dentry *dentry,
79672+ const struct vfsmount *mnt, const int fmode);
79673+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79674+ const struct vfsmount *mnt, umode_t *mode);
79675+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79676+ const struct vfsmount *mnt);
79677+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79678+ const struct vfsmount *mnt);
79679+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79680+ const struct vfsmount *mnt);
79681+int gr_handle_ptrace(struct task_struct *task, const long request);
79682+int gr_handle_proc_ptrace(struct task_struct *task);
79683+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79684+ const struct vfsmount *mnt);
79685+int gr_check_crash_exec(const struct file *filp);
79686+int gr_acl_is_enabled(void);
79687+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79688+ const kgid_t gid);
79689+int gr_set_proc_label(const struct dentry *dentry,
79690+ const struct vfsmount *mnt,
79691+ const int unsafe_flags);
79692+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79693+ const struct vfsmount *mnt);
79694+__u32 gr_acl_handle_open(const struct dentry *dentry,
79695+ const struct vfsmount *mnt, int acc_mode);
79696+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79697+ const struct dentry *p_dentry,
79698+ const struct vfsmount *p_mnt,
79699+ int open_flags, int acc_mode, const int imode);
79700+void gr_handle_create(const struct dentry *dentry,
79701+ const struct vfsmount *mnt);
79702+void gr_handle_proc_create(const struct dentry *dentry,
79703+ const struct inode *inode);
79704+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79705+ const struct dentry *parent_dentry,
79706+ const struct vfsmount *parent_mnt,
79707+ const int mode);
79708+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79709+ const struct dentry *parent_dentry,
79710+ const struct vfsmount *parent_mnt);
79711+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79712+ const struct vfsmount *mnt);
79713+void gr_handle_delete(const ino_t ino, const dev_t dev);
79714+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79715+ const struct vfsmount *mnt);
79716+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79717+ const struct dentry *parent_dentry,
79718+ const struct vfsmount *parent_mnt,
79719+ const struct filename *from);
79720+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79721+ const struct dentry *parent_dentry,
79722+ const struct vfsmount *parent_mnt,
79723+ const struct dentry *old_dentry,
79724+ const struct vfsmount *old_mnt, const struct filename *to);
79725+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79726+int gr_acl_handle_rename(struct dentry *new_dentry,
79727+ struct dentry *parent_dentry,
79728+ const struct vfsmount *parent_mnt,
79729+ struct dentry *old_dentry,
79730+ struct inode *old_parent_inode,
79731+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
79732+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79733+ struct dentry *old_dentry,
79734+ struct dentry *new_dentry,
79735+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
79736+__u32 gr_check_link(const struct dentry *new_dentry,
79737+ const struct dentry *parent_dentry,
79738+ const struct vfsmount *parent_mnt,
79739+ const struct dentry *old_dentry,
79740+ const struct vfsmount *old_mnt);
79741+int gr_acl_handle_filldir(const struct file *file, const char *name,
79742+ const unsigned int namelen, const ino_t ino);
79743+
79744+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79745+ const struct vfsmount *mnt);
79746+void gr_acl_handle_exit(void);
79747+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79748+int gr_acl_handle_procpidmem(const struct task_struct *task);
79749+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79750+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79751+void gr_audit_ptrace(struct task_struct *task);
79752+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79753+void gr_put_exec_file(struct task_struct *task);
79754+
79755+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79756+
79757+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79758+extern void gr_learn_resource(const struct task_struct *task, const int res,
79759+ const unsigned long wanted, const int gt);
79760+#else
79761+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79762+ const unsigned long wanted, const int gt)
79763+{
79764+}
79765+#endif
79766+
79767+#ifdef CONFIG_GRKERNSEC_RESLOG
79768+extern void gr_log_resource(const struct task_struct *task, const int res,
79769+ const unsigned long wanted, const int gt);
79770+#else
79771+static inline void gr_log_resource(const struct task_struct *task, const int res,
79772+ const unsigned long wanted, const int gt)
79773+{
79774+}
79775+#endif
79776+
79777+#ifdef CONFIG_GRKERNSEC
79778+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79779+void gr_handle_vm86(void);
79780+void gr_handle_mem_readwrite(u64 from, u64 to);
79781+
79782+void gr_log_badprocpid(const char *entry);
79783+
79784+extern int grsec_enable_dmesg;
79785+extern int grsec_disable_privio;
79786+
79787+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79788+extern kgid_t grsec_proc_gid;
79789+#endif
79790+
79791+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79792+extern int grsec_enable_chroot_findtask;
79793+#endif
79794+#ifdef CONFIG_GRKERNSEC_SETXID
79795+extern int grsec_enable_setxid;
79796+#endif
79797+#endif
79798+
79799+#endif
79800diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79801new file mode 100644
79802index 0000000..e7ffaaf
79803--- /dev/null
79804+++ b/include/linux/grsock.h
79805@@ -0,0 +1,19 @@
79806+#ifndef __GRSOCK_H
79807+#define __GRSOCK_H
79808+
79809+extern void gr_attach_curr_ip(const struct sock *sk);
79810+extern int gr_handle_sock_all(const int family, const int type,
79811+ const int protocol);
79812+extern int gr_handle_sock_server(const struct sockaddr *sck);
79813+extern int gr_handle_sock_server_other(const struct sock *sck);
79814+extern int gr_handle_sock_client(const struct sockaddr *sck);
79815+extern int gr_search_connect(struct socket * sock,
79816+ struct sockaddr_in * addr);
79817+extern int gr_search_bind(struct socket * sock,
79818+ struct sockaddr_in * addr);
79819+extern int gr_search_listen(struct socket * sock);
79820+extern int gr_search_accept(struct socket * sock);
79821+extern int gr_search_socket(const int domain, const int type,
79822+ const int protocol);
79823+
79824+#endif
79825diff --git a/include/linux/hash.h b/include/linux/hash.h
79826index bd1754c..8240892 100644
79827--- a/include/linux/hash.h
79828+++ b/include/linux/hash.h
79829@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79830 struct fast_hash_ops {
79831 u32 (*hash)(const void *data, u32 len, u32 seed);
79832 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79833-};
79834+} __no_const;
79835
79836 /**
79837 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79838diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79839index 7fb31da..08b5114 100644
79840--- a/include/linux/highmem.h
79841+++ b/include/linux/highmem.h
79842@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79843 kunmap_atomic(kaddr);
79844 }
79845
79846+static inline void sanitize_highpage(struct page *page)
79847+{
79848+ void *kaddr;
79849+ unsigned long flags;
79850+
79851+ local_irq_save(flags);
79852+ kaddr = kmap_atomic(page);
79853+ clear_page(kaddr);
79854+ kunmap_atomic(kaddr);
79855+ local_irq_restore(flags);
79856+}
79857+
79858 static inline void zero_user_segments(struct page *page,
79859 unsigned start1, unsigned end1,
79860 unsigned start2, unsigned end2)
79861diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79862index 1c7b89a..7dda400 100644
79863--- a/include/linux/hwmon-sysfs.h
79864+++ b/include/linux/hwmon-sysfs.h
79865@@ -25,7 +25,8 @@
79866 struct sensor_device_attribute{
79867 struct device_attribute dev_attr;
79868 int index;
79869-};
79870+} __do_const;
79871+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79872 #define to_sensor_dev_attr(_dev_attr) \
79873 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79874
79875@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79876 struct device_attribute dev_attr;
79877 u8 index;
79878 u8 nr;
79879-};
79880+} __do_const;
79881+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79882 #define to_sensor_dev_attr_2(_dev_attr) \
79883 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79884
79885diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79886index b556e0a..c10a515 100644
79887--- a/include/linux/i2c.h
79888+++ b/include/linux/i2c.h
79889@@ -378,6 +378,7 @@ struct i2c_algorithm {
79890 /* To determine what the adapter supports */
79891 u32 (*functionality) (struct i2c_adapter *);
79892 };
79893+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79894
79895 /**
79896 * struct i2c_bus_recovery_info - I2C bus recovery information
79897diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79898index d23c3c2..eb63c81 100644
79899--- a/include/linux/i2o.h
79900+++ b/include/linux/i2o.h
79901@@ -565,7 +565,7 @@ struct i2o_controller {
79902 struct i2o_device *exec; /* Executive */
79903 #if BITS_PER_LONG == 64
79904 spinlock_t context_list_lock; /* lock for context_list */
79905- atomic_t context_list_counter; /* needed for unique contexts */
79906+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79907 struct list_head context_list; /* list of context id's
79908 and pointers */
79909 #endif
79910diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79911index aff7ad8..3942bbd 100644
79912--- a/include/linux/if_pppox.h
79913+++ b/include/linux/if_pppox.h
79914@@ -76,7 +76,7 @@ struct pppox_proto {
79915 int (*ioctl)(struct socket *sock, unsigned int cmd,
79916 unsigned long arg);
79917 struct module *owner;
79918-};
79919+} __do_const;
79920
79921 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79922 extern void unregister_pppox_proto(int proto_num);
79923diff --git a/include/linux/init.h b/include/linux/init.h
79924index a3ba270..a1b6604 100644
79925--- a/include/linux/init.h
79926+++ b/include/linux/init.h
79927@@ -37,9 +37,17 @@
79928 * section.
79929 */
79930
79931+#define add_init_latent_entropy __latent_entropy
79932+
79933+#ifdef CONFIG_MEMORY_HOTPLUG
79934+#define add_meminit_latent_entropy
79935+#else
79936+#define add_meminit_latent_entropy __latent_entropy
79937+#endif
79938+
79939 /* These are for everybody (although not all archs will actually
79940 discard it in modules) */
79941-#define __init __section(.init.text) __cold notrace
79942+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79943 #define __initdata __section(.init.data)
79944 #define __initconst __constsection(.init.rodata)
79945 #define __exitdata __section(.exit.data)
79946@@ -100,7 +108,7 @@
79947 #define __cpuexitconst
79948
79949 /* Used for MEMORY_HOTPLUG */
79950-#define __meminit __section(.meminit.text) __cold notrace
79951+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79952 #define __meminitdata __section(.meminit.data)
79953 #define __meminitconst __constsection(.meminit.rodata)
79954 #define __memexit __section(.memexit.text) __exitused __cold notrace
79955diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79956index 6df7f9f..d0bf699 100644
79957--- a/include/linux/init_task.h
79958+++ b/include/linux/init_task.h
79959@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79960
79961 #define INIT_TASK_COMM "swapper"
79962
79963+#ifdef CONFIG_X86
79964+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79965+#else
79966+#define INIT_TASK_THREAD_INFO
79967+#endif
79968+
79969 #ifdef CONFIG_RT_MUTEXES
79970 # define INIT_RT_MUTEXES(tsk) \
79971 .pi_waiters = RB_ROOT, \
79972@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79973 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79974 .comm = INIT_TASK_COMM, \
79975 .thread = INIT_THREAD, \
79976+ INIT_TASK_THREAD_INFO \
79977 .fs = &init_fs, \
79978 .files = &init_files, \
79979 .signal = &init_signals, \
79980diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79981index 051c850..431f83a 100644
79982--- a/include/linux/interrupt.h
79983+++ b/include/linux/interrupt.h
79984@@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79985
79986 struct softirq_action
79987 {
79988- void (*action)(struct softirq_action *);
79989-};
79990+ void (*action)(void);
79991+} __no_const;
79992
79993 asmlinkage void do_softirq(void);
79994 asmlinkage void __do_softirq(void);
79995@@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
79996 }
79997 #endif
79998
79999-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80000+extern void open_softirq(int nr, void (*action)(void));
80001 extern void softirq_init(void);
80002 extern void __raise_softirq_irqoff(unsigned int nr);
80003
80004diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80005index b96a5b2..2732d1c 100644
80006--- a/include/linux/iommu.h
80007+++ b/include/linux/iommu.h
80008@@ -131,7 +131,7 @@ struct iommu_ops {
80009 u32 (*domain_get_windows)(struct iommu_domain *domain);
80010
80011 unsigned long pgsize_bitmap;
80012-};
80013+} __do_const;
80014
80015 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80016 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80017diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80018index 5e3a906..3131d0f 100644
80019--- a/include/linux/ioport.h
80020+++ b/include/linux/ioport.h
80021@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80022 int adjust_resource(struct resource *res, resource_size_t start,
80023 resource_size_t size);
80024 resource_size_t resource_alignment(struct resource *res);
80025-static inline resource_size_t resource_size(const struct resource *res)
80026+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80027 {
80028 return res->end - res->start + 1;
80029 }
80030diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80031index 35e7eca..6afb7ad 100644
80032--- a/include/linux/ipc_namespace.h
80033+++ b/include/linux/ipc_namespace.h
80034@@ -69,7 +69,7 @@ struct ipc_namespace {
80035 struct user_namespace *user_ns;
80036
80037 unsigned int proc_inum;
80038-};
80039+} __randomize_layout;
80040
80041 extern struct ipc_namespace init_ipc_ns;
80042 extern atomic_t nr_ipc_ns;
80043diff --git a/include/linux/irq.h b/include/linux/irq.h
80044index 5c57efb..965a62b 100644
80045--- a/include/linux/irq.h
80046+++ b/include/linux/irq.h
80047@@ -344,7 +344,8 @@ struct irq_chip {
80048 void (*irq_release_resources)(struct irq_data *data);
80049
80050 unsigned long flags;
80051-};
80052+} __do_const;
80053+typedef struct irq_chip __no_const irq_chip_no_const;
80054
80055 /*
80056 * irq_chip specific flags
80057diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80058index 7ed92d0..589abf5 100644
80059--- a/include/linux/irqchip/arm-gic.h
80060+++ b/include/linux/irqchip/arm-gic.h
80061@@ -73,9 +73,11 @@
80062
80063 #ifndef __ASSEMBLY__
80064
80065+#include <linux/irq.h>
80066+
80067 struct device_node;
80068
80069-extern struct irq_chip gic_arch_extn;
80070+extern irq_chip_no_const gic_arch_extn;
80071
80072 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80073 u32 offset, struct device_node *);
80074diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80075index 1f44466..b481806 100644
80076--- a/include/linux/jiffies.h
80077+++ b/include/linux/jiffies.h
80078@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80079 /*
80080 * Convert various time units to each other:
80081 */
80082-extern unsigned int jiffies_to_msecs(const unsigned long j);
80083-extern unsigned int jiffies_to_usecs(const unsigned long j);
80084+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80085+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80086
80087-static inline u64 jiffies_to_nsecs(const unsigned long j)
80088+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80089 {
80090 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80091 }
80092
80093-extern unsigned long msecs_to_jiffies(const unsigned int m);
80094-extern unsigned long usecs_to_jiffies(const unsigned int u);
80095+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80096+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80097 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80098 extern void jiffies_to_timespec(const unsigned long jiffies,
80099- struct timespec *value);
80100-extern unsigned long timeval_to_jiffies(const struct timeval *value);
80101+ struct timespec *value) __intentional_overflow(-1);
80102+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80103 extern void jiffies_to_timeval(const unsigned long jiffies,
80104 struct timeval *value);
80105
80106diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80107index 6883e19..e854fcb 100644
80108--- a/include/linux/kallsyms.h
80109+++ b/include/linux/kallsyms.h
80110@@ -15,7 +15,8 @@
80111
80112 struct module;
80113
80114-#ifdef CONFIG_KALLSYMS
80115+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80116+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80117 /* Lookup the address for a symbol. Returns 0 if not found. */
80118 unsigned long kallsyms_lookup_name(const char *name);
80119
80120@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80121 /* Stupid that this does nothing, but I didn't create this mess. */
80122 #define __print_symbol(fmt, addr)
80123 #endif /*CONFIG_KALLSYMS*/
80124+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80125+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80126+extern unsigned long kallsyms_lookup_name(const char *name);
80127+extern void __print_symbol(const char *fmt, unsigned long address);
80128+extern int sprint_backtrace(char *buffer, unsigned long address);
80129+extern int sprint_symbol(char *buffer, unsigned long address);
80130+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80131+const char *kallsyms_lookup(unsigned long addr,
80132+ unsigned long *symbolsize,
80133+ unsigned long *offset,
80134+ char **modname, char *namebuf);
80135+extern int kallsyms_lookup_size_offset(unsigned long addr,
80136+ unsigned long *symbolsize,
80137+ unsigned long *offset);
80138+#endif
80139
80140 /* This macro allows us to keep printk typechecking */
80141 static __printf(1, 2)
80142diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80143index a74c3a8..28d3f21 100644
80144--- a/include/linux/key-type.h
80145+++ b/include/linux/key-type.h
80146@@ -131,7 +131,7 @@ struct key_type {
80147 /* internal fields */
80148 struct list_head link; /* link in types list */
80149 struct lock_class_key lock_class; /* key->sem lock class */
80150-};
80151+} __do_const;
80152
80153 extern struct key_type key_type_keyring;
80154
80155diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80156index 6b06d37..c134867 100644
80157--- a/include/linux/kgdb.h
80158+++ b/include/linux/kgdb.h
80159@@ -52,7 +52,7 @@ extern int kgdb_connected;
80160 extern int kgdb_io_module_registered;
80161
80162 extern atomic_t kgdb_setting_breakpoint;
80163-extern atomic_t kgdb_cpu_doing_single_step;
80164+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80165
80166 extern struct task_struct *kgdb_usethread;
80167 extern struct task_struct *kgdb_contthread;
80168@@ -254,7 +254,7 @@ struct kgdb_arch {
80169 void (*correct_hw_break)(void);
80170
80171 void (*enable_nmi)(bool on);
80172-};
80173+} __do_const;
80174
80175 /**
80176 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80177@@ -279,7 +279,7 @@ struct kgdb_io {
80178 void (*pre_exception) (void);
80179 void (*post_exception) (void);
80180 int is_console;
80181-};
80182+} __do_const;
80183
80184 extern struct kgdb_arch arch_kgdb_ops;
80185
80186diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80187index 0555cc6..40116ce 100644
80188--- a/include/linux/kmod.h
80189+++ b/include/linux/kmod.h
80190@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80191 * usually useless though. */
80192 extern __printf(2, 3)
80193 int __request_module(bool wait, const char *name, ...);
80194+extern __printf(3, 4)
80195+int ___request_module(bool wait, char *param_name, const char *name, ...);
80196 #define request_module(mod...) __request_module(true, mod)
80197 #define request_module_nowait(mod...) __request_module(false, mod)
80198 #define try_then_request_module(x, mod...) \
80199@@ -57,6 +59,9 @@ struct subprocess_info {
80200 struct work_struct work;
80201 struct completion *complete;
80202 char *path;
80203+#ifdef CONFIG_GRKERNSEC
80204+ char *origpath;
80205+#endif
80206 char **argv;
80207 char **envp;
80208 int wait;
80209diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80210index f896a33..f2eb10f 100644
80211--- a/include/linux/kobject.h
80212+++ b/include/linux/kobject.h
80213@@ -116,7 +116,7 @@ struct kobj_type {
80214 struct attribute **default_attrs;
80215 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80216 const void *(*namespace)(struct kobject *kobj);
80217-};
80218+} __do_const;
80219
80220 struct kobj_uevent_env {
80221 char *argv[3];
80222@@ -140,6 +140,7 @@ struct kobj_attribute {
80223 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80224 const char *buf, size_t count);
80225 };
80226+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80227
80228 extern const struct sysfs_ops kobj_sysfs_ops;
80229
80230@@ -167,7 +168,7 @@ struct kset {
80231 spinlock_t list_lock;
80232 struct kobject kobj;
80233 const struct kset_uevent_ops *uevent_ops;
80234-};
80235+} __randomize_layout;
80236
80237 extern void kset_init(struct kset *kset);
80238 extern int __must_check kset_register(struct kset *kset);
80239diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80240index df32d25..fb52e27 100644
80241--- a/include/linux/kobject_ns.h
80242+++ b/include/linux/kobject_ns.h
80243@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80244 const void *(*netlink_ns)(struct sock *sk);
80245 const void *(*initial_ns)(void);
80246 void (*drop_ns)(void *);
80247-};
80248+} __do_const;
80249
80250 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80251 int kobj_ns_type_registered(enum kobj_ns_type type);
80252diff --git a/include/linux/kref.h b/include/linux/kref.h
80253index 484604d..0f6c5b6 100644
80254--- a/include/linux/kref.h
80255+++ b/include/linux/kref.h
80256@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80257 static inline int kref_sub(struct kref *kref, unsigned int count,
80258 void (*release)(struct kref *kref))
80259 {
80260- WARN_ON(release == NULL);
80261+ BUG_ON(release == NULL);
80262
80263 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80264 release(kref);
80265diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80266index 7d21cf9..bc0c81f 100644
80267--- a/include/linux/kvm_host.h
80268+++ b/include/linux/kvm_host.h
80269@@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80270 {
80271 }
80272 #endif
80273-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80274+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80275 struct module *module);
80276 void kvm_exit(void);
80277
80278@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80279 struct kvm_guest_debug *dbg);
80280 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80281
80282-int kvm_arch_init(void *opaque);
80283+int kvm_arch_init(const void *opaque);
80284 void kvm_arch_exit(void);
80285
80286 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80287diff --git a/include/linux/libata.h b/include/linux/libata.h
80288index 5ab4e3a..2fe237b 100644
80289--- a/include/linux/libata.h
80290+++ b/include/linux/libata.h
80291@@ -975,7 +975,7 @@ struct ata_port_operations {
80292 * fields must be pointers.
80293 */
80294 const struct ata_port_operations *inherits;
80295-};
80296+} __do_const;
80297
80298 struct ata_port_info {
80299 unsigned long flags;
80300diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80301index a6a42dd..6c5ebce 100644
80302--- a/include/linux/linkage.h
80303+++ b/include/linux/linkage.h
80304@@ -36,6 +36,7 @@
80305 #endif
80306
80307 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80308+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80309 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80310
80311 /*
80312diff --git a/include/linux/list.h b/include/linux/list.h
80313index ef95941..82db65a 100644
80314--- a/include/linux/list.h
80315+++ b/include/linux/list.h
80316@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80317 extern void list_del(struct list_head *entry);
80318 #endif
80319
80320+extern void __pax_list_add(struct list_head *new,
80321+ struct list_head *prev,
80322+ struct list_head *next);
80323+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80324+{
80325+ __pax_list_add(new, head, head->next);
80326+}
80327+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80328+{
80329+ __pax_list_add(new, head->prev, head);
80330+}
80331+extern void pax_list_del(struct list_head *entry);
80332+
80333 /**
80334 * list_replace - replace old entry by new one
80335 * @old : the element to be replaced
80336@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80337 INIT_LIST_HEAD(entry);
80338 }
80339
80340+extern void pax_list_del_init(struct list_head *entry);
80341+
80342 /**
80343 * list_move - delete from one list and add as another's head
80344 * @list: the entry to move
80345diff --git a/include/linux/math64.h b/include/linux/math64.h
80346index c45c089..298841c 100644
80347--- a/include/linux/math64.h
80348+++ b/include/linux/math64.h
80349@@ -15,7 +15,7 @@
80350 * This is commonly provided by 32bit archs to provide an optimized 64bit
80351 * divide.
80352 */
80353-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80354+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80355 {
80356 *remainder = dividend % divisor;
80357 return dividend / divisor;
80358@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80359 /**
80360 * div64_u64 - unsigned 64bit divide with 64bit divisor
80361 */
80362-static inline u64 div64_u64(u64 dividend, u64 divisor)
80363+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80364 {
80365 return dividend / divisor;
80366 }
80367@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80368 #define div64_ul(x, y) div_u64((x), (y))
80369
80370 #ifndef div_u64_rem
80371-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80372+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80373 {
80374 *remainder = do_div(dividend, divisor);
80375 return dividend;
80376@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80377 #endif
80378
80379 #ifndef div64_u64
80380-extern u64 div64_u64(u64 dividend, u64 divisor);
80381+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80382 #endif
80383
80384 #ifndef div64_s64
80385@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80386 * divide.
80387 */
80388 #ifndef div_u64
80389-static inline u64 div_u64(u64 dividend, u32 divisor)
80390+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80391 {
80392 u32 remainder;
80393 return div_u64_rem(dividend, divisor, &remainder);
80394diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80395index f230a97..714c006 100644
80396--- a/include/linux/mempolicy.h
80397+++ b/include/linux/mempolicy.h
80398@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80399 }
80400
80401 #define vma_policy(vma) ((vma)->vm_policy)
80402+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80403+{
80404+ vma->vm_policy = pol;
80405+}
80406
80407 static inline void mpol_get(struct mempolicy *pol)
80408 {
80409@@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80410 }
80411
80412 #define vma_policy(vma) NULL
80413+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80414+{
80415+}
80416
80417 static inline int
80418 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80419diff --git a/include/linux/mm.h b/include/linux/mm.h
80420index d677706..673408c 100644
80421--- a/include/linux/mm.h
80422+++ b/include/linux/mm.h
80423@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80424 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80425 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80426 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80427+
80428+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80429+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80430+#endif
80431+
80432 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80433
80434 #ifdef CONFIG_MEM_SOFT_DIRTY
80435@@ -237,8 +242,8 @@ struct vm_operations_struct {
80436 /* called by access_process_vm when get_user_pages() fails, typically
80437 * for use by special VMAs that can switch between memory and hardware
80438 */
80439- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80440- void *buf, int len, int write);
80441+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80442+ void *buf, size_t len, int write);
80443 #ifdef CONFIG_NUMA
80444 /*
80445 * set_policy() op must add a reference to any non-NULL @new mempolicy
80446@@ -268,6 +273,7 @@ struct vm_operations_struct {
80447 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80448 unsigned long size, pgoff_t pgoff);
80449 };
80450+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80451
80452 struct mmu_gather;
80453 struct inode;
80454@@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80455 unsigned long *pfn);
80456 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80457 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80458-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80459- void *buf, int len, int write);
80460+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80461+ void *buf, size_t len, int write);
80462
80463 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80464 loff_t const holebegin, loff_t const holelen)
80465@@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80466 }
80467 #endif
80468
80469-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80470-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80471- void *buf, int len, int write);
80472+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80473+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80474+ void *buf, size_t len, int write);
80475
80476 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80477 unsigned long start, unsigned long nr_pages,
80478@@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
80479 int clear_page_dirty_for_io(struct page *page);
80480 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
80481
80482-/* Is the vma a continuation of the stack vma above it? */
80483-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80484-{
80485- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80486-}
80487-
80488-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80489- unsigned long addr)
80490-{
80491- return (vma->vm_flags & VM_GROWSDOWN) &&
80492- (vma->vm_start == addr) &&
80493- !vma_growsdown(vma->vm_prev, addr);
80494-}
80495-
80496-/* Is the vma a continuation of the stack vma below it? */
80497-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80498-{
80499- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80500-}
80501-
80502-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80503- unsigned long addr)
80504-{
80505- return (vma->vm_flags & VM_GROWSUP) &&
80506- (vma->vm_end == addr) &&
80507- !vma_growsup(vma->vm_next, addr);
80508-}
80509-
80510 extern pid_t
80511 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80512
80513@@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80514 }
80515 #endif
80516
80517+#ifdef CONFIG_MMU
80518+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80519+#else
80520+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80521+{
80522+ return __pgprot(0);
80523+}
80524+#endif
80525+
80526 int vma_wants_writenotify(struct vm_area_struct *vma);
80527
80528 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80529@@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80530 {
80531 return 0;
80532 }
80533+
80534+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80535+ unsigned long address)
80536+{
80537+ return 0;
80538+}
80539 #else
80540 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80541+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80542 #endif
80543
80544 #ifdef __PAGETABLE_PMD_FOLDED
80545@@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80546 {
80547 return 0;
80548 }
80549+
80550+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80551+ unsigned long address)
80552+{
80553+ return 0;
80554+}
80555 #else
80556 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80557+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80558 #endif
80559
80560 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80561@@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80562 NULL: pud_offset(pgd, address);
80563 }
80564
80565+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80566+{
80567+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80568+ NULL: pud_offset(pgd, address);
80569+}
80570+
80571 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80572 {
80573 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80574 NULL: pmd_offset(pud, address);
80575 }
80576+
80577+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80578+{
80579+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80580+ NULL: pmd_offset(pud, address);
80581+}
80582 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80583
80584 #if USE_SPLIT_PTE_PTLOCKS
80585@@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80586 unsigned long addr, unsigned long len,
80587 unsigned long flags, struct page **pages);
80588
80589-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80590+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80591
80592 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80593 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80594@@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80595 unsigned long len, unsigned long prot, unsigned long flags,
80596 unsigned long pgoff, unsigned long *populate);
80597 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80598+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80599
80600 #ifdef CONFIG_MMU
80601 extern int __mm_populate(unsigned long addr, unsigned long len,
80602@@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
80603 unsigned long high_limit;
80604 unsigned long align_mask;
80605 unsigned long align_offset;
80606+ unsigned long threadstack_offset;
80607 };
80608
80609-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80610-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80611+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80612+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80613
80614 /*
80615 * Search for an unmapped address range.
80616@@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80617 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80618 */
80619 static inline unsigned long
80620-vm_unmapped_area(struct vm_unmapped_area_info *info)
80621+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80622 {
80623 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80624 return unmapped_area(info);
80625@@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80626 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80627 struct vm_area_struct **pprev);
80628
80629+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80630+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80631+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80632+
80633 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80634 NULL if none. Assume start_addr < end_addr. */
80635 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80636@@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80637 return vma;
80638 }
80639
80640-#ifdef CONFIG_MMU
80641-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80642-#else
80643-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80644-{
80645- return __pgprot(0);
80646-}
80647-#endif
80648-
80649 #ifdef CONFIG_NUMA_BALANCING
80650 unsigned long change_prot_numa(struct vm_area_struct *vma,
80651 unsigned long start, unsigned long end);
80652@@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80653 static inline void vm_stat_account(struct mm_struct *mm,
80654 unsigned long flags, struct file *file, long pages)
80655 {
80656+
80657+#ifdef CONFIG_PAX_RANDMMAP
80658+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80659+#endif
80660+
80661 mm->total_vm += pages;
80662 }
80663 #endif /* CONFIG_PROC_FS */
80664@@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
80665 extern int sysctl_memory_failure_early_kill;
80666 extern int sysctl_memory_failure_recovery;
80667 extern void shake_page(struct page *p, int access);
80668-extern atomic_long_t num_poisoned_pages;
80669+extern atomic_long_unchecked_t num_poisoned_pages;
80670 extern int soft_offline_page(struct page *page, int flags);
80671
80672 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80673@@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
80674 static inline void setup_nr_node_ids(void) {}
80675 #endif
80676
80677+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80678+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80679+#else
80680+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80681+#endif
80682+
80683 #endif /* __KERNEL__ */
80684 #endif /* _LINUX_MM_H */
80685diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80686index 8967e20..61f7900 100644
80687--- a/include/linux/mm_types.h
80688+++ b/include/linux/mm_types.h
80689@@ -308,7 +308,9 @@ struct vm_area_struct {
80690 #ifdef CONFIG_NUMA
80691 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80692 #endif
80693-};
80694+
80695+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80696+} __randomize_layout;
80697
80698 struct core_thread {
80699 struct task_struct *task;
80700@@ -454,7 +456,25 @@ struct mm_struct {
80701 bool tlb_flush_pending;
80702 #endif
80703 struct uprobes_state uprobes_state;
80704-};
80705+
80706+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80707+ unsigned long pax_flags;
80708+#endif
80709+
80710+#ifdef CONFIG_PAX_DLRESOLVE
80711+ unsigned long call_dl_resolve;
80712+#endif
80713+
80714+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80715+ unsigned long call_syscall;
80716+#endif
80717+
80718+#ifdef CONFIG_PAX_ASLR
80719+ unsigned long delta_mmap; /* randomized offset */
80720+ unsigned long delta_stack; /* randomized offset */
80721+#endif
80722+
80723+} __randomize_layout;
80724
80725 static inline void mm_init_cpumask(struct mm_struct *mm)
80726 {
80727diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80728index c5d5278..f0b68c8 100644
80729--- a/include/linux/mmiotrace.h
80730+++ b/include/linux/mmiotrace.h
80731@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80732 /* Called from ioremap.c */
80733 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80734 void __iomem *addr);
80735-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80736+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80737
80738 /* For anyone to insert markers. Remember trailing newline. */
80739 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80740@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80741 {
80742 }
80743
80744-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80745+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80746 {
80747 }
80748
80749diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80750index 835aa3d..676b387 100644
80751--- a/include/linux/mmzone.h
80752+++ b/include/linux/mmzone.h
80753@@ -406,7 +406,7 @@ struct zone {
80754 unsigned long flags; /* zone flags, see below */
80755
80756 /* Zone statistics */
80757- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80758+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80759
80760 /*
80761 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80762diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80763index 44eeef0..a92d3f9 100644
80764--- a/include/linux/mod_devicetable.h
80765+++ b/include/linux/mod_devicetable.h
80766@@ -139,7 +139,7 @@ struct usb_device_id {
80767 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80768 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80769
80770-#define HID_ANY_ID (~0)
80771+#define HID_ANY_ID (~0U)
80772 #define HID_BUS_ANY 0xffff
80773 #define HID_GROUP_ANY 0x0000
80774
80775@@ -475,7 +475,7 @@ struct dmi_system_id {
80776 const char *ident;
80777 struct dmi_strmatch matches[4];
80778 void *driver_data;
80779-};
80780+} __do_const;
80781 /*
80782 * struct dmi_device_id appears during expansion of
80783 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80784diff --git a/include/linux/module.h b/include/linux/module.h
80785index f520a76..5f898ef 100644
80786--- a/include/linux/module.h
80787+++ b/include/linux/module.h
80788@@ -17,9 +17,11 @@
80789 #include <linux/moduleparam.h>
80790 #include <linux/jump_label.h>
80791 #include <linux/export.h>
80792+#include <linux/fs.h>
80793
80794 #include <linux/percpu.h>
80795 #include <asm/module.h>
80796+#include <asm/pgtable.h>
80797
80798 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80799 #define MODULE_SIG_STRING "~Module signature appended~\n"
80800@@ -42,7 +44,7 @@ struct module_kobject {
80801 struct kobject *drivers_dir;
80802 struct module_param_attrs *mp;
80803 struct completion *kobj_completion;
80804-};
80805+} __randomize_layout;
80806
80807 struct module_attribute {
80808 struct attribute attr;
80809@@ -54,12 +56,13 @@ struct module_attribute {
80810 int (*test)(struct module *);
80811 void (*free)(struct module *);
80812 };
80813+typedef struct module_attribute __no_const module_attribute_no_const;
80814
80815 struct module_version_attribute {
80816 struct module_attribute mattr;
80817 const char *module_name;
80818 const char *version;
80819-} __attribute__ ((__aligned__(sizeof(void *))));
80820+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80821
80822 extern ssize_t __modver_version_show(struct module_attribute *,
80823 struct module_kobject *, char *);
80824@@ -235,7 +238,7 @@ struct module {
80825
80826 /* Sysfs stuff. */
80827 struct module_kobject mkobj;
80828- struct module_attribute *modinfo_attrs;
80829+ module_attribute_no_const *modinfo_attrs;
80830 const char *version;
80831 const char *srcversion;
80832 struct kobject *holders_dir;
80833@@ -284,19 +287,16 @@ struct module {
80834 int (*init)(void);
80835
80836 /* If this is non-NULL, vfree after init() returns */
80837- void *module_init;
80838+ void *module_init_rx, *module_init_rw;
80839
80840 /* Here is the actual code + data, vfree'd on unload. */
80841- void *module_core;
80842+ void *module_core_rx, *module_core_rw;
80843
80844 /* Here are the sizes of the init and core sections */
80845- unsigned int init_size, core_size;
80846+ unsigned int init_size_rw, core_size_rw;
80847
80848 /* The size of the executable code in each section. */
80849- unsigned int init_text_size, core_text_size;
80850-
80851- /* Size of RO sections of the module (text+rodata) */
80852- unsigned int init_ro_size, core_ro_size;
80853+ unsigned int init_size_rx, core_size_rx;
80854
80855 /* Arch-specific module values */
80856 struct mod_arch_specific arch;
80857@@ -352,6 +352,10 @@ struct module {
80858 #ifdef CONFIG_EVENT_TRACING
80859 struct ftrace_event_call **trace_events;
80860 unsigned int num_trace_events;
80861+ struct file_operations trace_id;
80862+ struct file_operations trace_enable;
80863+ struct file_operations trace_format;
80864+ struct file_operations trace_filter;
80865 #endif
80866 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80867 unsigned int num_ftrace_callsites;
80868@@ -375,7 +379,7 @@ struct module {
80869 ctor_fn_t *ctors;
80870 unsigned int num_ctors;
80871 #endif
80872-};
80873+} __randomize_layout;
80874 #ifndef MODULE_ARCH_INIT
80875 #define MODULE_ARCH_INIT {}
80876 #endif
80877@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
80878 bool is_module_percpu_address(unsigned long addr);
80879 bool is_module_text_address(unsigned long addr);
80880
80881+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80882+{
80883+
80884+#ifdef CONFIG_PAX_KERNEXEC
80885+ if (ktla_ktva(addr) >= (unsigned long)start &&
80886+ ktla_ktva(addr) < (unsigned long)start + size)
80887+ return 1;
80888+#endif
80889+
80890+ return ((void *)addr >= start && (void *)addr < start + size);
80891+}
80892+
80893+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80894+{
80895+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80896+}
80897+
80898+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80899+{
80900+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80901+}
80902+
80903+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80904+{
80905+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80906+}
80907+
80908+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80909+{
80910+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80911+}
80912+
80913 static inline int within_module_core(unsigned long addr, const struct module *mod)
80914 {
80915- return (unsigned long)mod->module_core <= addr &&
80916- addr < (unsigned long)mod->module_core + mod->core_size;
80917+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80918 }
80919
80920 static inline int within_module_init(unsigned long addr, const struct module *mod)
80921 {
80922- return (unsigned long)mod->module_init <= addr &&
80923- addr < (unsigned long)mod->module_init + mod->init_size;
80924+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80925 }
80926
80927 /* Search for module by name: must hold module_mutex. */
80928diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80929index 560ca53..ef621ef 100644
80930--- a/include/linux/moduleloader.h
80931+++ b/include/linux/moduleloader.h
80932@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80933 sections. Returns NULL on failure. */
80934 void *module_alloc(unsigned long size);
80935
80936+#ifdef CONFIG_PAX_KERNEXEC
80937+void *module_alloc_exec(unsigned long size);
80938+#else
80939+#define module_alloc_exec(x) module_alloc(x)
80940+#endif
80941+
80942 /* Free memory returned from module_alloc. */
80943 void module_free(struct module *mod, void *module_region);
80944
80945+#ifdef CONFIG_PAX_KERNEXEC
80946+void module_free_exec(struct module *mod, void *module_region);
80947+#else
80948+#define module_free_exec(x, y) module_free((x), (y))
80949+#endif
80950+
80951 /*
80952 * Apply the given relocation to the (simplified) ELF. Return -error
80953 * or 0.
80954@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80955 unsigned int relsec,
80956 struct module *me)
80957 {
80958+#ifdef CONFIG_MODULES
80959 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80960+#endif
80961 return -ENOEXEC;
80962 }
80963 #endif
80964@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80965 unsigned int relsec,
80966 struct module *me)
80967 {
80968+#ifdef CONFIG_MODULES
80969 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80970+#endif
80971 return -ENOEXEC;
80972 }
80973 #endif
80974diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80975index 204a677..e9b486a 100644
80976--- a/include/linux/moduleparam.h
80977+++ b/include/linux/moduleparam.h
80978@@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
80979 * @len is usually just sizeof(string).
80980 */
80981 #define module_param_string(name, string, len, perm) \
80982- static const struct kparam_string __param_string_##name \
80983+ static const struct kparam_string __param_string_##name __used \
80984 = { len, string }; \
80985 __module_param_call(MODULE_PARAM_PREFIX, name, \
80986 &param_ops_string, \
80987@@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80988 */
80989 #define module_param_array_named(name, array, type, nump, perm) \
80990 param_check_##type(name, &(array)[0]); \
80991- static const struct kparam_array __param_arr_##name \
80992+ static const struct kparam_array __param_arr_##name __used \
80993 = { .max = ARRAY_SIZE(array), .num = nump, \
80994 .ops = &param_ops_##type, \
80995 .elemsize = sizeof(array[0]), .elem = array }; \
80996diff --git a/include/linux/mount.h b/include/linux/mount.h
80997index 839bac2..a96b37c 100644
80998--- a/include/linux/mount.h
80999+++ b/include/linux/mount.h
81000@@ -59,7 +59,7 @@ struct vfsmount {
81001 struct dentry *mnt_root; /* root of the mounted tree */
81002 struct super_block *mnt_sb; /* pointer to superblock */
81003 int mnt_flags;
81004-};
81005+} __randomize_layout;
81006
81007 struct file; /* forward dec */
81008
81009diff --git a/include/linux/namei.h b/include/linux/namei.h
81010index 492de72..1bddcd4 100644
81011--- a/include/linux/namei.h
81012+++ b/include/linux/namei.h
81013@@ -19,7 +19,7 @@ struct nameidata {
81014 unsigned seq, m_seq;
81015 int last_type;
81016 unsigned depth;
81017- char *saved_names[MAX_NESTED_LINKS + 1];
81018+ const char *saved_names[MAX_NESTED_LINKS + 1];
81019 };
81020
81021 /*
81022@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81023
81024 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81025
81026-static inline void nd_set_link(struct nameidata *nd, char *path)
81027+static inline void nd_set_link(struct nameidata *nd, const char *path)
81028 {
81029 nd->saved_names[nd->depth] = path;
81030 }
81031
81032-static inline char *nd_get_link(struct nameidata *nd)
81033+static inline const char *nd_get_link(const struct nameidata *nd)
81034 {
81035 return nd->saved_names[nd->depth];
81036 }
81037diff --git a/include/linux/net.h b/include/linux/net.h
81038index 17d8339..81656c0 100644
81039--- a/include/linux/net.h
81040+++ b/include/linux/net.h
81041@@ -192,7 +192,7 @@ struct net_proto_family {
81042 int (*create)(struct net *net, struct socket *sock,
81043 int protocol, int kern);
81044 struct module *owner;
81045-};
81046+} __do_const;
81047
81048 struct iovec;
81049 struct kvec;
81050diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81051index b42d07b..7f45ae2 100644
81052--- a/include/linux/netdevice.h
81053+++ b/include/linux/netdevice.h
81054@@ -1146,6 +1146,7 @@ struct net_device_ops {
81055 void *priv);
81056 int (*ndo_get_lock_subclass)(struct net_device *dev);
81057 };
81058+typedef struct net_device_ops __no_const net_device_ops_no_const;
81059
81060 /**
81061 * enum net_device_priv_flags - &struct net_device priv_flags
81062@@ -1313,11 +1314,11 @@ struct net_device {
81063 struct net_device_stats stats;
81064
81065 /* dropped packets by core network, Do not use this in drivers */
81066- atomic_long_t rx_dropped;
81067- atomic_long_t tx_dropped;
81068+ atomic_long_unchecked_t rx_dropped;
81069+ atomic_long_unchecked_t tx_dropped;
81070
81071 /* Stats to monitor carrier on<->off transitions */
81072- atomic_t carrier_changes;
81073+ atomic_unchecked_t carrier_changes;
81074
81075 #ifdef CONFIG_WIRELESS_EXT
81076 /* List of functions to handle Wireless Extensions (instead of ioctl).
81077diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81078index 2077489..a15e561 100644
81079--- a/include/linux/netfilter.h
81080+++ b/include/linux/netfilter.h
81081@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81082 #endif
81083 /* Use the module struct to lock set/get code in place */
81084 struct module *owner;
81085-};
81086+} __do_const;
81087
81088 /* Function to register/unregister hook points. */
81089 int nf_register_hook(struct nf_hook_ops *reg);
81090diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81091index e955d47..04a5338 100644
81092--- a/include/linux/netfilter/nfnetlink.h
81093+++ b/include/linux/netfilter/nfnetlink.h
81094@@ -19,7 +19,7 @@ struct nfnl_callback {
81095 const struct nlattr * const cda[]);
81096 const struct nla_policy *policy; /* netlink attribute policy */
81097 const u_int16_t attr_count; /* number of nlattr's */
81098-};
81099+} __do_const;
81100
81101 struct nfnetlink_subsystem {
81102 const char *name;
81103diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81104new file mode 100644
81105index 0000000..33f4af8
81106--- /dev/null
81107+++ b/include/linux/netfilter/xt_gradm.h
81108@@ -0,0 +1,9 @@
81109+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81110+#define _LINUX_NETFILTER_XT_GRADM_H 1
81111+
81112+struct xt_gradm_mtinfo {
81113+ __u16 flags;
81114+ __u16 invflags;
81115+};
81116+
81117+#endif
81118diff --git a/include/linux/nls.h b/include/linux/nls.h
81119index 520681b..1d67ed2 100644
81120--- a/include/linux/nls.h
81121+++ b/include/linux/nls.h
81122@@ -31,7 +31,7 @@ struct nls_table {
81123 const unsigned char *charset2upper;
81124 struct module *owner;
81125 struct nls_table *next;
81126-};
81127+} __do_const;
81128
81129 /* this value hold the maximum octet of charset */
81130 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81131diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81132index d14a4c3..a078786 100644
81133--- a/include/linux/notifier.h
81134+++ b/include/linux/notifier.h
81135@@ -54,7 +54,8 @@ struct notifier_block {
81136 notifier_fn_t notifier_call;
81137 struct notifier_block __rcu *next;
81138 int priority;
81139-};
81140+} __do_const;
81141+typedef struct notifier_block __no_const notifier_block_no_const;
81142
81143 struct atomic_notifier_head {
81144 spinlock_t lock;
81145diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81146index b2a0f15..4d7da32 100644
81147--- a/include/linux/oprofile.h
81148+++ b/include/linux/oprofile.h
81149@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81150 int oprofilefs_create_ro_ulong(struct dentry * root,
81151 char const * name, ulong * val);
81152
81153-/** Create a file for read-only access to an atomic_t. */
81154+/** Create a file for read-only access to an atomic_unchecked_t. */
81155 int oprofilefs_create_ro_atomic(struct dentry * root,
81156- char const * name, atomic_t * val);
81157+ char const * name, atomic_unchecked_t * val);
81158
81159 /** create a directory */
81160 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81161diff --git a/include/linux/padata.h b/include/linux/padata.h
81162index 4386946..f50c615 100644
81163--- a/include/linux/padata.h
81164+++ b/include/linux/padata.h
81165@@ -129,7 +129,7 @@ struct parallel_data {
81166 struct padata_serial_queue __percpu *squeue;
81167 atomic_t reorder_objects;
81168 atomic_t refcnt;
81169- atomic_t seq_nr;
81170+ atomic_unchecked_t seq_nr;
81171 struct padata_cpumask cpumask;
81172 spinlock_t lock ____cacheline_aligned;
81173 unsigned int processed;
81174diff --git a/include/linux/path.h b/include/linux/path.h
81175index d137218..be0c176 100644
81176--- a/include/linux/path.h
81177+++ b/include/linux/path.h
81178@@ -1,13 +1,15 @@
81179 #ifndef _LINUX_PATH_H
81180 #define _LINUX_PATH_H
81181
81182+#include <linux/compiler.h>
81183+
81184 struct dentry;
81185 struct vfsmount;
81186
81187 struct path {
81188 struct vfsmount *mnt;
81189 struct dentry *dentry;
81190-};
81191+} __randomize_layout;
81192
81193 extern void path_get(const struct path *);
81194 extern void path_put(const struct path *);
81195diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81196index 5f2e559..7d59314 100644
81197--- a/include/linux/pci_hotplug.h
81198+++ b/include/linux/pci_hotplug.h
81199@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81200 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81201 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81202 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81203-};
81204+} __do_const;
81205+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81206
81207 /**
81208 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81209diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81210index 3ef6ea1..ed1a248 100644
81211--- a/include/linux/perf_event.h
81212+++ b/include/linux/perf_event.h
81213@@ -328,8 +328,8 @@ struct perf_event {
81214
81215 enum perf_event_active_state state;
81216 unsigned int attach_state;
81217- local64_t count;
81218- atomic64_t child_count;
81219+ local64_t count; /* PaX: fix it one day */
81220+ atomic64_unchecked_t child_count;
81221
81222 /*
81223 * These are the total time in nanoseconds that the event
81224@@ -380,8 +380,8 @@ struct perf_event {
81225 * These accumulate total time (in nanoseconds) that children
81226 * events have been enabled and running, respectively.
81227 */
81228- atomic64_t child_total_time_enabled;
81229- atomic64_t child_total_time_running;
81230+ atomic64_unchecked_t child_total_time_enabled;
81231+ atomic64_unchecked_t child_total_time_running;
81232
81233 /*
81234 * Protect attach/detach and child_list:
81235@@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81236 entry->ip[entry->nr++] = ip;
81237 }
81238
81239-extern int sysctl_perf_event_paranoid;
81240+extern int sysctl_perf_event_legitimately_concerned;
81241 extern int sysctl_perf_event_mlock;
81242 extern int sysctl_perf_event_sample_rate;
81243 extern int sysctl_perf_cpu_time_max_percent;
81244@@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81245 loff_t *ppos);
81246
81247
81248+static inline bool perf_paranoid_any(void)
81249+{
81250+ return sysctl_perf_event_legitimately_concerned > 2;
81251+}
81252+
81253 static inline bool perf_paranoid_tracepoint_raw(void)
81254 {
81255- return sysctl_perf_event_paranoid > -1;
81256+ return sysctl_perf_event_legitimately_concerned > -1;
81257 }
81258
81259 static inline bool perf_paranoid_cpu(void)
81260 {
81261- return sysctl_perf_event_paranoid > 0;
81262+ return sysctl_perf_event_legitimately_concerned > 0;
81263 }
81264
81265 static inline bool perf_paranoid_kernel(void)
81266 {
81267- return sysctl_perf_event_paranoid > 1;
81268+ return sysctl_perf_event_legitimately_concerned > 1;
81269 }
81270
81271 extern void perf_event_init(void);
81272@@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81273 struct device_attribute attr;
81274 u64 id;
81275 const char *event_str;
81276-};
81277+} __do_const;
81278
81279 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81280 static struct perf_pmu_events_attr _var = { \
81281diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81282index 7246ef3..1539ea4 100644
81283--- a/include/linux/pid_namespace.h
81284+++ b/include/linux/pid_namespace.h
81285@@ -43,7 +43,7 @@ struct pid_namespace {
81286 int hide_pid;
81287 int reboot; /* group exit code if this pidns was rebooted */
81288 unsigned int proc_inum;
81289-};
81290+} __randomize_layout;
81291
81292 extern struct pid_namespace init_pid_ns;
81293
81294diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81295index eb8b8ac..62649e1 100644
81296--- a/include/linux/pipe_fs_i.h
81297+++ b/include/linux/pipe_fs_i.h
81298@@ -47,10 +47,10 @@ struct pipe_inode_info {
81299 struct mutex mutex;
81300 wait_queue_head_t wait;
81301 unsigned int nrbufs, curbuf, buffers;
81302- unsigned int readers;
81303- unsigned int writers;
81304- unsigned int files;
81305- unsigned int waiting_writers;
81306+ atomic_t readers;
81307+ atomic_t writers;
81308+ atomic_t files;
81309+ atomic_t waiting_writers;
81310 unsigned int r_counter;
81311 unsigned int w_counter;
81312 struct page *tmp_page;
81313diff --git a/include/linux/pm.h b/include/linux/pm.h
81314index d915d03..0531037 100644
81315--- a/include/linux/pm.h
81316+++ b/include/linux/pm.h
81317@@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81318 struct dev_pm_domain {
81319 struct dev_pm_ops ops;
81320 };
81321+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81322
81323 /*
81324 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81325diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81326index 7c1d252..0e7061d 100644
81327--- a/include/linux/pm_domain.h
81328+++ b/include/linux/pm_domain.h
81329@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81330 int (*thaw_early)(struct device *dev);
81331 int (*thaw)(struct device *dev);
81332 bool (*active_wakeup)(struct device *dev);
81333-};
81334+} __no_const;
81335
81336 struct gpd_cpu_data {
81337 unsigned int saved_exit_latency;
81338- struct cpuidle_state *idle_state;
81339+ cpuidle_state_no_const *idle_state;
81340 };
81341
81342 struct generic_pm_domain {
81343diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81344index 2a5897a..4f9af63 100644
81345--- a/include/linux/pm_runtime.h
81346+++ b/include/linux/pm_runtime.h
81347@@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81348
81349 static inline void pm_runtime_mark_last_busy(struct device *dev)
81350 {
81351- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81352+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81353 }
81354
81355 #else /* !CONFIG_PM_RUNTIME */
81356diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81357index 195aafc..49a7bc2 100644
81358--- a/include/linux/pnp.h
81359+++ b/include/linux/pnp.h
81360@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81361 struct pnp_fixup {
81362 char id[7];
81363 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81364-};
81365+} __do_const;
81366
81367 /* config parameters */
81368 #define PNP_CONFIG_NORMAL 0x0001
81369diff --git a/include/linux/poison.h b/include/linux/poison.h
81370index 2110a81..13a11bb 100644
81371--- a/include/linux/poison.h
81372+++ b/include/linux/poison.h
81373@@ -19,8 +19,8 @@
81374 * under normal circumstances, used to verify that nobody uses
81375 * non-initialized list entries.
81376 */
81377-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81378-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81379+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81380+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81381
81382 /********** include/linux/timer.h **********/
81383 /*
81384diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81385index d8b187c3..9a9257a 100644
81386--- a/include/linux/power/smartreflex.h
81387+++ b/include/linux/power/smartreflex.h
81388@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81389 int (*notify)(struct omap_sr *sr, u32 status);
81390 u8 notify_flags;
81391 u8 class_type;
81392-};
81393+} __do_const;
81394
81395 /**
81396 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81397diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81398index 4ea1d37..80f4b33 100644
81399--- a/include/linux/ppp-comp.h
81400+++ b/include/linux/ppp-comp.h
81401@@ -84,7 +84,7 @@ struct compressor {
81402 struct module *owner;
81403 /* Extra skb space needed by the compressor algorithm */
81404 unsigned int comp_extra;
81405-};
81406+} __do_const;
81407
81408 /*
81409 * The return value from decompress routine is the length of the
81410diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81411index de83b4e..c4b997d 100644
81412--- a/include/linux/preempt.h
81413+++ b/include/linux/preempt.h
81414@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81415 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81416 #endif
81417
81418+#define raw_preempt_count_add(val) __preempt_count_add(val)
81419+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81420+
81421 #define __preempt_count_inc() __preempt_count_add(1)
81422 #define __preempt_count_dec() __preempt_count_sub(1)
81423
81424 #define preempt_count_inc() preempt_count_add(1)
81425+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81426 #define preempt_count_dec() preempt_count_sub(1)
81427+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81428
81429 #ifdef CONFIG_PREEMPT_COUNT
81430
81431@@ -41,6 +46,12 @@ do { \
81432 barrier(); \
81433 } while (0)
81434
81435+#define raw_preempt_disable() \
81436+do { \
81437+ raw_preempt_count_inc(); \
81438+ barrier(); \
81439+} while (0)
81440+
81441 #define sched_preempt_enable_no_resched() \
81442 do { \
81443 barrier(); \
81444@@ -49,6 +60,12 @@ do { \
81445
81446 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81447
81448+#define raw_preempt_enable_no_resched() \
81449+do { \
81450+ barrier(); \
81451+ raw_preempt_count_dec(); \
81452+} while (0)
81453+
81454 #ifdef CONFIG_PREEMPT
81455 #define preempt_enable() \
81456 do { \
81457@@ -113,8 +130,10 @@ do { \
81458 * region.
81459 */
81460 #define preempt_disable() barrier()
81461+#define raw_preempt_disable() barrier()
81462 #define sched_preempt_enable_no_resched() barrier()
81463 #define preempt_enable_no_resched() barrier()
81464+#define raw_preempt_enable_no_resched() barrier()
81465 #define preempt_enable() barrier()
81466 #define preempt_check_resched() do { } while (0)
81467
81468@@ -128,11 +147,13 @@ do { \
81469 /*
81470 * Modules have no business playing preemption tricks.
81471 */
81472+#ifndef CONFIG_PAX_KERNEXEC
81473 #undef sched_preempt_enable_no_resched
81474 #undef preempt_enable_no_resched
81475 #undef preempt_enable_no_resched_notrace
81476 #undef preempt_check_resched
81477 #endif
81478+#endif
81479
81480 #define preempt_set_need_resched() \
81481 do { \
81482diff --git a/include/linux/printk.h b/include/linux/printk.h
81483index 8752f75..2b80c0f 100644
81484--- a/include/linux/printk.h
81485+++ b/include/linux/printk.h
81486@@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
81487 void early_printk(const char *s, ...) { }
81488 #endif
81489
81490+extern int kptr_restrict;
81491+
81492 #ifdef CONFIG_PRINTK
81493 asmlinkage __printf(5, 0)
81494 int vprintk_emit(int facility, int level,
81495@@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81496
81497 extern int printk_delay_msec;
81498 extern int dmesg_restrict;
81499-extern int kptr_restrict;
81500
81501 extern void wake_up_klogd(void);
81502
81503diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81504index 608e60a..79cfb18 100644
81505--- a/include/linux/proc_fs.h
81506+++ b/include/linux/proc_fs.h
81507@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81508 extern struct proc_dir_entry *proc_symlink(const char *,
81509 struct proc_dir_entry *, const char *);
81510 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81511+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81512 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81513 struct proc_dir_entry *, void *);
81514+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81515+ struct proc_dir_entry *, void *);
81516 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81517 struct proc_dir_entry *);
81518
81519@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81520 return proc_create_data(name, mode, parent, proc_fops, NULL);
81521 }
81522
81523+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81524+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81525+{
81526+#ifdef CONFIG_GRKERNSEC_PROC_USER
81527+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81528+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81529+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81530+#else
81531+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81532+#endif
81533+}
81534+
81535+
81536 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81537 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81538 extern void *PDE_DATA(const struct inode *);
81539@@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
81540 struct proc_dir_entry *parent,const char *dest) { return NULL;}
81541 static inline struct proc_dir_entry *proc_mkdir(const char *name,
81542 struct proc_dir_entry *parent) {return NULL;}
81543+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
81544+ struct proc_dir_entry *parent) { return NULL; }
81545 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
81546 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81547+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
81548+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81549 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
81550 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
81551 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
81552@@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81553 static inline struct proc_dir_entry *proc_net_mkdir(
81554 struct net *net, const char *name, struct proc_dir_entry *parent)
81555 {
81556- return proc_mkdir_data(name, 0, parent, net);
81557+ return proc_mkdir_data_restrict(name, 0, parent, net);
81558 }
81559
81560 #endif /* _LINUX_PROC_FS_H */
81561diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81562index 34a1e10..70f6bde 100644
81563--- a/include/linux/proc_ns.h
81564+++ b/include/linux/proc_ns.h
81565@@ -14,7 +14,7 @@ struct proc_ns_operations {
81566 void (*put)(void *ns);
81567 int (*install)(struct nsproxy *nsproxy, void *ns);
81568 unsigned int (*inum)(void *ns);
81569-};
81570+} __do_const __randomize_layout;
81571
81572 struct proc_ns {
81573 void *ns;
81574diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
81575index 077904c..cc79eff 100644
81576--- a/include/linux/ptrace.h
81577+++ b/include/linux/ptrace.h
81578@@ -334,6 +334,9 @@ static inline void user_single_step_siginfo(struct task_struct *tsk,
81579 * calling arch_ptrace_stop() when it would be superfluous. For example,
81580 * if the thread has not been back to user mode since the last stop, the
81581 * thread state might indicate that nothing needs to be done.
81582+ *
81583+ * This is guaranteed to be invoked once before a task stops for ptrace and
81584+ * may include arch-specific operations necessary prior to a ptrace stop.
81585 */
81586 #define arch_ptrace_stop_needed(code, info) (0)
81587 #endif
81588diff --git a/include/linux/quota.h b/include/linux/quota.h
81589index cc7494a..1e27036 100644
81590--- a/include/linux/quota.h
81591+++ b/include/linux/quota.h
81592@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81593
81594 extern bool qid_eq(struct kqid left, struct kqid right);
81595 extern bool qid_lt(struct kqid left, struct kqid right);
81596-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81597+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81598 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81599 extern bool qid_valid(struct kqid qid);
81600
81601diff --git a/include/linux/random.h b/include/linux/random.h
81602index 57fbbff..2331f3f 100644
81603--- a/include/linux/random.h
81604+++ b/include/linux/random.h
81605@@ -9,9 +9,19 @@
81606 #include <uapi/linux/random.h>
81607
81608 extern void add_device_randomness(const void *, unsigned int);
81609+
81610+static inline void add_latent_entropy(void)
81611+{
81612+
81613+#ifdef LATENT_ENTROPY_PLUGIN
81614+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81615+#endif
81616+
81617+}
81618+
81619 extern void add_input_randomness(unsigned int type, unsigned int code,
81620- unsigned int value);
81621-extern void add_interrupt_randomness(int irq, int irq_flags);
81622+ unsigned int value) __latent_entropy;
81623+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81624
81625 extern void get_random_bytes(void *buf, int nbytes);
81626 extern void get_random_bytes_arch(void *buf, int nbytes);
81627@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81628 extern const struct file_operations random_fops, urandom_fops;
81629 #endif
81630
81631-unsigned int get_random_int(void);
81632+unsigned int __intentional_overflow(-1) get_random_int(void);
81633 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81634
81635-u32 prandom_u32(void);
81636+u32 prandom_u32(void) __intentional_overflow(-1);
81637 void prandom_bytes(void *buf, int nbytes);
81638 void prandom_seed(u32 seed);
81639 void prandom_reseed_late(void);
81640@@ -37,6 +47,11 @@ struct rnd_state {
81641 u32 prandom_u32_state(struct rnd_state *state);
81642 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81643
81644+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81645+{
81646+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81647+}
81648+
81649 /**
81650 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81651 * @ep_ro: right open interval endpoint
81652diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81653index fea49b5..2ac22bb 100644
81654--- a/include/linux/rbtree_augmented.h
81655+++ b/include/linux/rbtree_augmented.h
81656@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81657 old->rbaugmented = rbcompute(old); \
81658 } \
81659 rbstatic const struct rb_augment_callbacks rbname = { \
81660- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81661+ .propagate = rbname ## _propagate, \
81662+ .copy = rbname ## _copy, \
81663+ .rotate = rbname ## _rotate \
81664 };
81665
81666
81667diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81668index 8183b46..a388711 100644
81669--- a/include/linux/rculist.h
81670+++ b/include/linux/rculist.h
81671@@ -29,8 +29,8 @@
81672 */
81673 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81674 {
81675- ACCESS_ONCE(list->next) = list;
81676- ACCESS_ONCE(list->prev) = list;
81677+ ACCESS_ONCE_RW(list->next) = list;
81678+ ACCESS_ONCE_RW(list->prev) = list;
81679 }
81680
81681 /*
81682@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81683 struct list_head *prev, struct list_head *next);
81684 #endif
81685
81686+void __pax_list_add_rcu(struct list_head *new,
81687+ struct list_head *prev, struct list_head *next);
81688+
81689 /**
81690 * list_add_rcu - add a new entry to rcu-protected list
81691 * @new: new entry to be added
81692@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81693 __list_add_rcu(new, head, head->next);
81694 }
81695
81696+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81697+{
81698+ __pax_list_add_rcu(new, head, head->next);
81699+}
81700+
81701 /**
81702 * list_add_tail_rcu - add a new entry to rcu-protected list
81703 * @new: new entry to be added
81704@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81705 __list_add_rcu(new, head->prev, head);
81706 }
81707
81708+static inline void pax_list_add_tail_rcu(struct list_head *new,
81709+ struct list_head *head)
81710+{
81711+ __pax_list_add_rcu(new, head->prev, head);
81712+}
81713+
81714 /**
81715 * list_del_rcu - deletes entry from list without re-initialization
81716 * @entry: the element to delete from the list.
81717@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81718 entry->prev = LIST_POISON2;
81719 }
81720
81721+extern void pax_list_del_rcu(struct list_head *entry);
81722+
81723 /**
81724 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81725 * @n: the element to delete from the hash list.
81726diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81727index 48bf152..d38b785 100644
81728--- a/include/linux/reboot.h
81729+++ b/include/linux/reboot.h
81730@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81731 */
81732
81733 extern void migrate_to_reboot_cpu(void);
81734-extern void machine_restart(char *cmd);
81735-extern void machine_halt(void);
81736-extern void machine_power_off(void);
81737+extern void machine_restart(char *cmd) __noreturn;
81738+extern void machine_halt(void) __noreturn;
81739+extern void machine_power_off(void) __noreturn;
81740
81741 extern void machine_shutdown(void);
81742 struct pt_regs;
81743@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81744 */
81745
81746 extern void kernel_restart_prepare(char *cmd);
81747-extern void kernel_restart(char *cmd);
81748-extern void kernel_halt(void);
81749-extern void kernel_power_off(void);
81750+extern void kernel_restart(char *cmd) __noreturn;
81751+extern void kernel_halt(void) __noreturn;
81752+extern void kernel_power_off(void) __noreturn;
81753
81754 extern int C_A_D; /* for sysctl */
81755 void ctrl_alt_del(void);
81756@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81757 * Emergency restart, callable from an interrupt handler.
81758 */
81759
81760-extern void emergency_restart(void);
81761+extern void emergency_restart(void) __noreturn;
81762 #include <asm/emergency-restart.h>
81763
81764 #endif /* _LINUX_REBOOT_H */
81765diff --git a/include/linux/regset.h b/include/linux/regset.h
81766index 8e0c9fe..ac4d221 100644
81767--- a/include/linux/regset.h
81768+++ b/include/linux/regset.h
81769@@ -161,7 +161,8 @@ struct user_regset {
81770 unsigned int align;
81771 unsigned int bias;
81772 unsigned int core_note_type;
81773-};
81774+} __do_const;
81775+typedef struct user_regset __no_const user_regset_no_const;
81776
81777 /**
81778 * struct user_regset_view - available regsets
81779diff --git a/include/linux/relay.h b/include/linux/relay.h
81780index d7c8359..818daf5 100644
81781--- a/include/linux/relay.h
81782+++ b/include/linux/relay.h
81783@@ -157,7 +157,7 @@ struct rchan_callbacks
81784 * The callback should return 0 if successful, negative if not.
81785 */
81786 int (*remove_buf_file)(struct dentry *dentry);
81787-};
81788+} __no_const;
81789
81790 /*
81791 * CONFIG_RELAY kernel API, kernel/relay.c
81792diff --git a/include/linux/rio.h b/include/linux/rio.h
81793index 6bda06f..bf39a9b 100644
81794--- a/include/linux/rio.h
81795+++ b/include/linux/rio.h
81796@@ -358,7 +358,7 @@ struct rio_ops {
81797 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81798 u64 rstart, u32 size, u32 flags);
81799 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81800-};
81801+} __no_const;
81802
81803 #define RIO_RESOURCE_MEM 0x00000100
81804 #define RIO_RESOURCE_DOORBELL 0x00000200
81805diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81806index b66c211..13d2915 100644
81807--- a/include/linux/rmap.h
81808+++ b/include/linux/rmap.h
81809@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81810 void anon_vma_init(void); /* create anon_vma_cachep */
81811 int anon_vma_prepare(struct vm_area_struct *);
81812 void unlink_anon_vmas(struct vm_area_struct *);
81813-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81814-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81815+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81816+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81817
81818 static inline void anon_vma_merge(struct vm_area_struct *vma,
81819 struct vm_area_struct *next)
81820diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
81821index a964f72..b475afb 100644
81822--- a/include/linux/scatterlist.h
81823+++ b/include/linux/scatterlist.h
81824@@ -1,6 +1,7 @@
81825 #ifndef _LINUX_SCATTERLIST_H
81826 #define _LINUX_SCATTERLIST_H
81827
81828+#include <linux/sched.h>
81829 #include <linux/string.h>
81830 #include <linux/bug.h>
81831 #include <linux/mm.h>
81832@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
81833 #ifdef CONFIG_DEBUG_SG
81834 BUG_ON(!virt_addr_valid(buf));
81835 #endif
81836+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81837+ if (object_starts_on_stack(buf)) {
81838+ void *adjbuf = buf - current->stack + current->lowmem_stack;
81839+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
81840+ } else
81841+#endif
81842 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
81843 }
81844
81845diff --git a/include/linux/sched.h b/include/linux/sched.h
81846index 221b2bd..e2e5f82 100644
81847--- a/include/linux/sched.h
81848+++ b/include/linux/sched.h
81849@@ -131,6 +131,7 @@ struct fs_struct;
81850 struct perf_event_context;
81851 struct blk_plug;
81852 struct filename;
81853+struct linux_binprm;
81854
81855 #define VMACACHE_BITS 2
81856 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
81857@@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
81858 extern int in_sched_functions(unsigned long addr);
81859
81860 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81861-extern signed long schedule_timeout(signed long timeout);
81862+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81863 extern signed long schedule_timeout_interruptible(signed long timeout);
81864 extern signed long schedule_timeout_killable(signed long timeout);
81865 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81866@@ -391,6 +392,19 @@ struct nsproxy;
81867 struct user_namespace;
81868
81869 #ifdef CONFIG_MMU
81870+
81871+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81872+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81873+#else
81874+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81875+{
81876+ return 0;
81877+}
81878+#endif
81879+
81880+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81881+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81882+
81883 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81884 extern unsigned long
81885 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81886@@ -688,6 +702,17 @@ struct signal_struct {
81887 #ifdef CONFIG_TASKSTATS
81888 struct taskstats *stats;
81889 #endif
81890+
81891+#ifdef CONFIG_GRKERNSEC
81892+ u32 curr_ip;
81893+ u32 saved_ip;
81894+ u32 gr_saddr;
81895+ u32 gr_daddr;
81896+ u16 gr_sport;
81897+ u16 gr_dport;
81898+ u8 used_accept:1;
81899+#endif
81900+
81901 #ifdef CONFIG_AUDIT
81902 unsigned audit_tty;
81903 unsigned audit_tty_log_passwd;
81904@@ -714,7 +739,7 @@ struct signal_struct {
81905 struct mutex cred_guard_mutex; /* guard against foreign influences on
81906 * credential calculations
81907 * (notably. ptrace) */
81908-};
81909+} __randomize_layout;
81910
81911 /*
81912 * Bits in flags field of signal_struct.
81913@@ -768,6 +793,14 @@ struct user_struct {
81914 struct key *session_keyring; /* UID's default session keyring */
81915 #endif
81916
81917+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81918+ unsigned char kernel_banned;
81919+#endif
81920+#ifdef CONFIG_GRKERNSEC_BRUTE
81921+ unsigned char suid_banned;
81922+ unsigned long suid_ban_expires;
81923+#endif
81924+
81925 /* Hash table maintenance information */
81926 struct hlist_node uidhash_node;
81927 kuid_t uid;
81928@@ -775,7 +808,7 @@ struct user_struct {
81929 #ifdef CONFIG_PERF_EVENTS
81930 atomic_long_t locked_vm;
81931 #endif
81932-};
81933+} __randomize_layout;
81934
81935 extern int uids_sysfs_init(void);
81936
81937@@ -1179,6 +1212,9 @@ enum perf_event_task_context {
81938 struct task_struct {
81939 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
81940 void *stack;
81941+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81942+ void *lowmem_stack;
81943+#endif
81944 atomic_t usage;
81945 unsigned int flags; /* per process flags, defined below */
81946 unsigned int ptrace;
81947@@ -1304,8 +1340,8 @@ struct task_struct {
81948 struct list_head thread_node;
81949
81950 struct completion *vfork_done; /* for vfork() */
81951- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81952- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81953+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81954+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81955
81956 cputime_t utime, stime, utimescaled, stimescaled;
81957 cputime_t gtime;
81958@@ -1330,11 +1366,6 @@ struct task_struct {
81959 struct task_cputime cputime_expires;
81960 struct list_head cpu_timers[3];
81961
81962-/* process credentials */
81963- const struct cred __rcu *real_cred; /* objective and real subjective task
81964- * credentials (COW) */
81965- const struct cred __rcu *cred; /* effective (overridable) subjective task
81966- * credentials (COW) */
81967 char comm[TASK_COMM_LEN]; /* executable name excluding path
81968 - access with [gs]et_task_comm (which lock
81969 it with task_lock())
81970@@ -1351,6 +1382,10 @@ struct task_struct {
81971 #endif
81972 /* CPU-specific state of this task */
81973 struct thread_struct thread;
81974+/* thread_info moved to task_struct */
81975+#ifdef CONFIG_X86
81976+ struct thread_info tinfo;
81977+#endif
81978 /* filesystem information */
81979 struct fs_struct *fs;
81980 /* open file information */
81981@@ -1427,6 +1462,10 @@ struct task_struct {
81982 gfp_t lockdep_reclaim_gfp;
81983 #endif
81984
81985+/* process credentials */
81986+ const struct cred __rcu *real_cred; /* objective and real subjective task
81987+ * credentials (COW) */
81988+
81989 /* journalling filesystem info */
81990 void *journal_info;
81991
81992@@ -1465,6 +1504,10 @@ struct task_struct {
81993 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81994 struct list_head cg_list;
81995 #endif
81996+
81997+ const struct cred __rcu *cred; /* effective (overridable) subjective task
81998+ * credentials (COW) */
81999+
82000 #ifdef CONFIG_FUTEX
82001 struct robust_list_head __user *robust_list;
82002 #ifdef CONFIG_COMPAT
82003@@ -1610,7 +1653,78 @@ struct task_struct {
82004 unsigned int sequential_io;
82005 unsigned int sequential_io_avg;
82006 #endif
82007-};
82008+
82009+#ifdef CONFIG_GRKERNSEC
82010+ /* grsecurity */
82011+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82012+ u64 exec_id;
82013+#endif
82014+#ifdef CONFIG_GRKERNSEC_SETXID
82015+ const struct cred *delayed_cred;
82016+#endif
82017+ struct dentry *gr_chroot_dentry;
82018+ struct acl_subject_label *acl;
82019+ struct acl_subject_label *tmpacl;
82020+ struct acl_role_label *role;
82021+ struct file *exec_file;
82022+ unsigned long brute_expires;
82023+ u16 acl_role_id;
82024+ u8 inherited;
82025+ /* is this the task that authenticated to the special role */
82026+ u8 acl_sp_role;
82027+ u8 is_writable;
82028+ u8 brute;
82029+ u8 gr_is_chrooted;
82030+#endif
82031+
82032+} __randomize_layout;
82033+
82034+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82035+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82036+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82037+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82038+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82039+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82040+
82041+#ifdef CONFIG_PAX_SOFTMODE
82042+extern int pax_softmode;
82043+#endif
82044+
82045+extern int pax_check_flags(unsigned long *);
82046+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82047+
82048+/* if tsk != current then task_lock must be held on it */
82049+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82050+static inline unsigned long pax_get_flags(struct task_struct *tsk)
82051+{
82052+ if (likely(tsk->mm))
82053+ return tsk->mm->pax_flags;
82054+ else
82055+ return 0UL;
82056+}
82057+
82058+/* if tsk != current then task_lock must be held on it */
82059+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82060+{
82061+ if (likely(tsk->mm)) {
82062+ tsk->mm->pax_flags = flags;
82063+ return 0;
82064+ }
82065+ return -EINVAL;
82066+}
82067+#endif
82068+
82069+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82070+extern void pax_set_initial_flags(struct linux_binprm *bprm);
82071+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82072+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82073+#endif
82074+
82075+struct path;
82076+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82077+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82078+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82079+extern void pax_report_refcount_overflow(struct pt_regs *regs);
82080
82081 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82082 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82083@@ -1692,7 +1806,7 @@ struct pid_namespace;
82084 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82085 struct pid_namespace *ns);
82086
82087-static inline pid_t task_pid_nr(struct task_struct *tsk)
82088+static inline pid_t task_pid_nr(const struct task_struct *tsk)
82089 {
82090 return tsk->pid;
82091 }
82092@@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
82093
82094 extern void sched_clock_init(void);
82095
82096+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82097+static inline void populate_stack(void)
82098+{
82099+ struct task_struct *curtask = current;
82100+ int c;
82101+ int *ptr = curtask->stack;
82102+ int *end = curtask->stack + THREAD_SIZE;
82103+
82104+ while (ptr < end) {
82105+ c = *(volatile int *)ptr;
82106+ ptr += PAGE_SIZE/sizeof(int);
82107+ }
82108+}
82109+#else
82110+static inline void populate_stack(void)
82111+{
82112+}
82113+#endif
82114+
82115 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82116 static inline void sched_clock_tick(void)
82117 {
82118@@ -2172,7 +2305,9 @@ void yield(void);
82119 extern struct exec_domain default_exec_domain;
82120
82121 union thread_union {
82122+#ifndef CONFIG_X86
82123 struct thread_info thread_info;
82124+#endif
82125 unsigned long stack[THREAD_SIZE/sizeof(long)];
82126 };
82127
82128@@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82129 */
82130
82131 extern struct task_struct *find_task_by_vpid(pid_t nr);
82132+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82133 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82134 struct pid_namespace *ns);
82135
82136@@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82137 extern void exit_itimers(struct signal_struct *);
82138 extern void flush_itimer_signals(void);
82139
82140-extern void do_group_exit(int);
82141+extern __noreturn void do_group_exit(int);
82142
82143 extern int allow_signal(int);
82144 extern int disallow_signal(int);
82145@@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82146
82147 #endif
82148
82149-static inline int object_is_on_stack(void *obj)
82150+static inline int object_starts_on_stack(const void *obj)
82151 {
82152- void *stack = task_stack_page(current);
82153+ const void *stack = task_stack_page(current);
82154
82155 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82156 }
82157diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82158index 8045a55..c959cd5 100644
82159--- a/include/linux/sched/sysctl.h
82160+++ b/include/linux/sched/sysctl.h
82161@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82162 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82163
82164 extern int sysctl_max_map_count;
82165+extern unsigned long sysctl_heap_stack_gap;
82166
82167 extern unsigned int sysctl_sched_latency;
82168 extern unsigned int sysctl_sched_min_granularity;
82169diff --git a/include/linux/security.h b/include/linux/security.h
82170index 6478ce3..5e6ad6e 100644
82171--- a/include/linux/security.h
82172+++ b/include/linux/security.h
82173@@ -27,6 +27,7 @@
82174 #include <linux/slab.h>
82175 #include <linux/err.h>
82176 #include <linux/string.h>
82177+#include <linux/grsecurity.h>
82178
82179 struct linux_binprm;
82180 struct cred;
82181@@ -116,8 +117,6 @@ struct seq_file;
82182
82183 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82184
82185-void reset_security_ops(void);
82186-
82187 #ifdef CONFIG_MMU
82188 extern unsigned long mmap_min_addr;
82189 extern unsigned long dac_mmap_min_addr;
82190@@ -1719,7 +1718,7 @@ struct security_operations {
82191 struct audit_context *actx);
82192 void (*audit_rule_free) (void *lsmrule);
82193 #endif /* CONFIG_AUDIT */
82194-};
82195+} __randomize_layout;
82196
82197 /* prototypes */
82198 extern int security_init(void);
82199diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82200index dc368b8..e895209 100644
82201--- a/include/linux/semaphore.h
82202+++ b/include/linux/semaphore.h
82203@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82204 }
82205
82206 extern void down(struct semaphore *sem);
82207-extern int __must_check down_interruptible(struct semaphore *sem);
82208+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82209 extern int __must_check down_killable(struct semaphore *sem);
82210 extern int __must_check down_trylock(struct semaphore *sem);
82211 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82212diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82213index 52e0097..383f21d 100644
82214--- a/include/linux/seq_file.h
82215+++ b/include/linux/seq_file.h
82216@@ -27,6 +27,9 @@ struct seq_file {
82217 struct mutex lock;
82218 const struct seq_operations *op;
82219 int poll_event;
82220+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82221+ u64 exec_id;
82222+#endif
82223 #ifdef CONFIG_USER_NS
82224 struct user_namespace *user_ns;
82225 #endif
82226@@ -39,6 +42,7 @@ struct seq_operations {
82227 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82228 int (*show) (struct seq_file *m, void *v);
82229 };
82230+typedef struct seq_operations __no_const seq_operations_no_const;
82231
82232 #define SEQ_SKIP 1
82233
82234@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82235
82236 char *mangle_path(char *s, const char *p, const char *esc);
82237 int seq_open(struct file *, const struct seq_operations *);
82238+int seq_open_restrict(struct file *, const struct seq_operations *);
82239 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82240 loff_t seq_lseek(struct file *, loff_t, int);
82241 int seq_release(struct inode *, struct file *);
82242@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82243 }
82244
82245 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82246+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82247 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82248 int single_release(struct inode *, struct file *);
82249 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82250diff --git a/include/linux/shm.h b/include/linux/shm.h
82251index 1e2cd2e..0288750 100644
82252--- a/include/linux/shm.h
82253+++ b/include/linux/shm.h
82254@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82255
82256 /* The task created the shm object. NULL if the task is dead. */
82257 struct task_struct *shm_creator;
82258+#ifdef CONFIG_GRKERNSEC
82259+ time_t shm_createtime;
82260+ pid_t shm_lapid;
82261+#endif
82262 };
82263
82264 /* shm_mode upper byte flags */
82265diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82266index 08074a8..e2ae280 100644
82267--- a/include/linux/skbuff.h
82268+++ b/include/linux/skbuff.h
82269@@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82270 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82271 int node);
82272 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82273-static inline struct sk_buff *alloc_skb(unsigned int size,
82274+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82275 gfp_t priority)
82276 {
82277 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82278@@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82279 return skb->inner_transport_header - skb->inner_network_header;
82280 }
82281
82282-static inline int skb_network_offset(const struct sk_buff *skb)
82283+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82284 {
82285 return skb_network_header(skb) - skb->data;
82286 }
82287@@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82288 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82289 */
82290 #ifndef NET_SKB_PAD
82291-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82292+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82293 #endif
82294
82295 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82296@@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82297 int *err);
82298 unsigned int datagram_poll(struct file *file, struct socket *sock,
82299 struct poll_table_struct *wait);
82300-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82301+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82302 struct iovec *to, int size);
82303 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82304 struct iovec *iov);
82305@@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82306 nf_bridge_put(skb->nf_bridge);
82307 skb->nf_bridge = NULL;
82308 #endif
82309+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82310+ skb->nf_trace = 0;
82311+#endif
82312 }
82313
82314 static inline void nf_reset_trace(struct sk_buff *skb)
82315diff --git a/include/linux/slab.h b/include/linux/slab.h
82316index 307bfbe..a999cf3 100644
82317--- a/include/linux/slab.h
82318+++ b/include/linux/slab.h
82319@@ -14,15 +14,29 @@
82320 #include <linux/gfp.h>
82321 #include <linux/types.h>
82322 #include <linux/workqueue.h>
82323-
82324+#include <linux/err.h>
82325
82326 /*
82327 * Flags to pass to kmem_cache_create().
82328 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82329 */
82330 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82331+
82332+#ifdef CONFIG_PAX_USERCOPY_SLABS
82333+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82334+#else
82335+#define SLAB_USERCOPY 0x00000000UL
82336+#endif
82337+
82338 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82339 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82340+
82341+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82342+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82343+#else
82344+#define SLAB_NO_SANITIZE 0x00000000UL
82345+#endif
82346+
82347 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82348 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82349 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82350@@ -98,10 +112,13 @@
82351 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82352 * Both make kfree a no-op.
82353 */
82354-#define ZERO_SIZE_PTR ((void *)16)
82355+#define ZERO_SIZE_PTR \
82356+({ \
82357+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82358+ (void *)(-MAX_ERRNO-1L); \
82359+})
82360
82361-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82362- (unsigned long)ZERO_SIZE_PTR)
82363+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82364
82365 #include <linux/kmemleak.h>
82366
82367@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82368 void kfree(const void *);
82369 void kzfree(const void *);
82370 size_t ksize(const void *);
82371+const char *check_heap_object(const void *ptr, unsigned long n);
82372+bool is_usercopy_object(const void *ptr);
82373
82374 /*
82375 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82376@@ -174,7 +193,7 @@ struct kmem_cache {
82377 unsigned int align; /* Alignment as calculated */
82378 unsigned long flags; /* Active flags on the slab */
82379 const char *name; /* Slab name for sysfs */
82380- int refcount; /* Use counter */
82381+ atomic_t refcount; /* Use counter */
82382 void (*ctor)(void *); /* Called on object slot creation */
82383 struct list_head list; /* List of all slab caches on the system */
82384 };
82385@@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82386 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82387 #endif
82388
82389+#ifdef CONFIG_PAX_USERCOPY_SLABS
82390+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82391+#endif
82392+
82393 /*
82394 * Figure out which kmalloc slab an allocation of a certain size
82395 * belongs to.
82396@@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82397 * 2 = 120 .. 192 bytes
82398 * n = 2^(n-1) .. 2^n -1
82399 */
82400-static __always_inline int kmalloc_index(size_t size)
82401+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82402 {
82403 if (!size)
82404 return 0;
82405@@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
82406 }
82407 #endif /* !CONFIG_SLOB */
82408
82409-void *__kmalloc(size_t size, gfp_t flags);
82410+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82411 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82412
82413 #ifdef CONFIG_NUMA
82414-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82415+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82416 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82417 #else
82418 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82419diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82420index 8235dfb..47ce586 100644
82421--- a/include/linux/slab_def.h
82422+++ b/include/linux/slab_def.h
82423@@ -38,7 +38,7 @@ struct kmem_cache {
82424 /* 4) cache creation/removal */
82425 const char *name;
82426 struct list_head list;
82427- int refcount;
82428+ atomic_t refcount;
82429 int object_size;
82430 int align;
82431
82432@@ -54,10 +54,14 @@ struct kmem_cache {
82433 unsigned long node_allocs;
82434 unsigned long node_frees;
82435 unsigned long node_overflow;
82436- atomic_t allochit;
82437- atomic_t allocmiss;
82438- atomic_t freehit;
82439- atomic_t freemiss;
82440+ atomic_unchecked_t allochit;
82441+ atomic_unchecked_t allocmiss;
82442+ atomic_unchecked_t freehit;
82443+ atomic_unchecked_t freemiss;
82444+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82445+ atomic_unchecked_t sanitized;
82446+ atomic_unchecked_t not_sanitized;
82447+#endif
82448
82449 /*
82450 * If debugging is enabled, then the allocator can add additional
82451diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82452index d82abd4..408c3a0 100644
82453--- a/include/linux/slub_def.h
82454+++ b/include/linux/slub_def.h
82455@@ -74,7 +74,7 @@ struct kmem_cache {
82456 struct kmem_cache_order_objects max;
82457 struct kmem_cache_order_objects min;
82458 gfp_t allocflags; /* gfp flags to use on each alloc */
82459- int refcount; /* Refcount for slab cache destroy */
82460+ atomic_t refcount; /* Refcount for slab cache destroy */
82461 void (*ctor)(void *);
82462 int inuse; /* Offset to metadata */
82463 int align; /* Alignment */
82464diff --git a/include/linux/smp.h b/include/linux/smp.h
82465index 633f5ed..6c3dc3f 100644
82466--- a/include/linux/smp.h
82467+++ b/include/linux/smp.h
82468@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
82469 #endif
82470
82471 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82472+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82473 #define put_cpu() preempt_enable()
82474+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82475
82476 /*
82477 * Callback to arch code if there's nosmp or maxcpus=0 on the
82478diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82479index 46cca4c..3323536 100644
82480--- a/include/linux/sock_diag.h
82481+++ b/include/linux/sock_diag.h
82482@@ -11,7 +11,7 @@ struct sock;
82483 struct sock_diag_handler {
82484 __u8 family;
82485 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82486-};
82487+} __do_const;
82488
82489 int sock_diag_register(const struct sock_diag_handler *h);
82490 void sock_diag_unregister(const struct sock_diag_handler *h);
82491diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82492index 680f9a3..f13aeb0 100644
82493--- a/include/linux/sonet.h
82494+++ b/include/linux/sonet.h
82495@@ -7,7 +7,7 @@
82496 #include <uapi/linux/sonet.h>
82497
82498 struct k_sonet_stats {
82499-#define __HANDLE_ITEM(i) atomic_t i
82500+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82501 __SONET_ITEMS
82502 #undef __HANDLE_ITEM
82503 };
82504diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82505index 07d8e53..dc934c9 100644
82506--- a/include/linux/sunrpc/addr.h
82507+++ b/include/linux/sunrpc/addr.h
82508@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82509 {
82510 switch (sap->sa_family) {
82511 case AF_INET:
82512- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82513+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82514 case AF_INET6:
82515- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82516+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82517 }
82518 return 0;
82519 }
82520@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82521 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82522 const struct sockaddr *src)
82523 {
82524- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82525+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82526 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82527
82528 dsin->sin_family = ssin->sin_family;
82529@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82530 if (sa->sa_family != AF_INET6)
82531 return 0;
82532
82533- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82534+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82535 }
82536
82537 #endif /* _LINUX_SUNRPC_ADDR_H */
82538diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82539index 70736b9..37f33db 100644
82540--- a/include/linux/sunrpc/clnt.h
82541+++ b/include/linux/sunrpc/clnt.h
82542@@ -97,7 +97,7 @@ struct rpc_procinfo {
82543 unsigned int p_timer; /* Which RTT timer to use */
82544 u32 p_statidx; /* Which procedure to account */
82545 const char * p_name; /* name of procedure */
82546-};
82547+} __do_const;
82548
82549 #ifdef __KERNEL__
82550
82551diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82552index 04e7632..2e2a8a3 100644
82553--- a/include/linux/sunrpc/svc.h
82554+++ b/include/linux/sunrpc/svc.h
82555@@ -412,7 +412,7 @@ struct svc_procedure {
82556 unsigned int pc_count; /* call count */
82557 unsigned int pc_cachetype; /* cache info (NFS) */
82558 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82559-};
82560+} __do_const;
82561
82562 /*
82563 * Function prototypes.
82564diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82565index 0b8e3e6..33e0a01 100644
82566--- a/include/linux/sunrpc/svc_rdma.h
82567+++ b/include/linux/sunrpc/svc_rdma.h
82568@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82569 extern unsigned int svcrdma_max_requests;
82570 extern unsigned int svcrdma_max_req_size;
82571
82572-extern atomic_t rdma_stat_recv;
82573-extern atomic_t rdma_stat_read;
82574-extern atomic_t rdma_stat_write;
82575-extern atomic_t rdma_stat_sq_starve;
82576-extern atomic_t rdma_stat_rq_starve;
82577-extern atomic_t rdma_stat_rq_poll;
82578-extern atomic_t rdma_stat_rq_prod;
82579-extern atomic_t rdma_stat_sq_poll;
82580-extern atomic_t rdma_stat_sq_prod;
82581+extern atomic_unchecked_t rdma_stat_recv;
82582+extern atomic_unchecked_t rdma_stat_read;
82583+extern atomic_unchecked_t rdma_stat_write;
82584+extern atomic_unchecked_t rdma_stat_sq_starve;
82585+extern atomic_unchecked_t rdma_stat_rq_starve;
82586+extern atomic_unchecked_t rdma_stat_rq_poll;
82587+extern atomic_unchecked_t rdma_stat_rq_prod;
82588+extern atomic_unchecked_t rdma_stat_sq_poll;
82589+extern atomic_unchecked_t rdma_stat_sq_prod;
82590
82591 #define RPCRDMA_VERSION 1
82592
82593diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82594index 8d71d65..f79586e 100644
82595--- a/include/linux/sunrpc/svcauth.h
82596+++ b/include/linux/sunrpc/svcauth.h
82597@@ -120,7 +120,7 @@ struct auth_ops {
82598 int (*release)(struct svc_rqst *rq);
82599 void (*domain_release)(struct auth_domain *);
82600 int (*set_client)(struct svc_rqst *rq);
82601-};
82602+} __do_const;
82603
82604 #define SVC_GARBAGE 1
82605 #define SVC_SYSERR 2
82606diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82607index a5ffd32..0935dea 100644
82608--- a/include/linux/swiotlb.h
82609+++ b/include/linux/swiotlb.h
82610@@ -60,7 +60,8 @@ extern void
82611
82612 extern void
82613 swiotlb_free_coherent(struct device *hwdev, size_t size,
82614- void *vaddr, dma_addr_t dma_handle);
82615+ void *vaddr, dma_addr_t dma_handle,
82616+ struct dma_attrs *attrs);
82617
82618 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82619 unsigned long offset, size_t size,
82620diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82621index a4a0588..752870e 100644
82622--- a/include/linux/syscalls.h
82623+++ b/include/linux/syscalls.h
82624@@ -98,10 +98,16 @@ struct sigaltstack;
82625 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82626
82627 #define __SC_DECL(t, a) t a
82628+#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))
82629 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
82630 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
82631 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82632-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82633+#define __SC_LONG(t, a) __typeof( \
82634+ __builtin_choose_expr( \
82635+ sizeof(t) > sizeof(int), \
82636+ (t) 0, \
82637+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82638+ )) a
82639 #define __SC_CAST(t, a) (t) a
82640 #define __SC_ARGS(t, a) a
82641 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82642@@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
82643 asmlinkage long sys_fsync(unsigned int fd);
82644 asmlinkage long sys_fdatasync(unsigned int fd);
82645 asmlinkage long sys_bdflush(int func, long data);
82646-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82647- char __user *type, unsigned long flags,
82648+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82649+ const char __user *type, unsigned long flags,
82650 void __user *data);
82651-asmlinkage long sys_umount(char __user *name, int flags);
82652-asmlinkage long sys_oldumount(char __user *name);
82653+asmlinkage long sys_umount(const char __user *name, int flags);
82654+asmlinkage long sys_oldumount(const char __user *name);
82655 asmlinkage long sys_truncate(const char __user *path, long length);
82656 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82657 asmlinkage long sys_stat(const char __user *filename,
82658@@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82659 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82660 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82661 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82662- struct sockaddr __user *, int);
82663+ struct sockaddr __user *, int) __intentional_overflow(0);
82664 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82665 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82666 unsigned int vlen, unsigned flags);
82667diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82668index 27b3b0b..e093dd9 100644
82669--- a/include/linux/syscore_ops.h
82670+++ b/include/linux/syscore_ops.h
82671@@ -16,7 +16,7 @@ struct syscore_ops {
82672 int (*suspend)(void);
82673 void (*resume)(void);
82674 void (*shutdown)(void);
82675-};
82676+} __do_const;
82677
82678 extern void register_syscore_ops(struct syscore_ops *ops);
82679 extern void unregister_syscore_ops(struct syscore_ops *ops);
82680diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82681index 14a8ff2..fa95f3a 100644
82682--- a/include/linux/sysctl.h
82683+++ b/include/linux/sysctl.h
82684@@ -34,13 +34,13 @@ struct ctl_table_root;
82685 struct ctl_table_header;
82686 struct ctl_dir;
82687
82688-typedef struct ctl_table ctl_table;
82689-
82690 typedef int proc_handler (struct ctl_table *ctl, int write,
82691 void __user *buffer, size_t *lenp, loff_t *ppos);
82692
82693 extern int proc_dostring(struct ctl_table *, int,
82694 void __user *, size_t *, loff_t *);
82695+extern int proc_dostring_modpriv(struct ctl_table *, int,
82696+ void __user *, size_t *, loff_t *);
82697 extern int proc_dointvec(struct ctl_table *, int,
82698 void __user *, size_t *, loff_t *);
82699 extern int proc_dointvec_minmax(struct ctl_table *, int,
82700@@ -115,7 +115,9 @@ struct ctl_table
82701 struct ctl_table_poll *poll;
82702 void *extra1;
82703 void *extra2;
82704-};
82705+} __do_const __randomize_layout;
82706+typedef struct ctl_table __no_const ctl_table_no_const;
82707+typedef struct ctl_table ctl_table;
82708
82709 struct ctl_node {
82710 struct rb_node node;
82711diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82712index 5ffaa34..fe3e31c 100644
82713--- a/include/linux/sysfs.h
82714+++ b/include/linux/sysfs.h
82715@@ -34,7 +34,8 @@ struct attribute {
82716 struct lock_class_key *key;
82717 struct lock_class_key skey;
82718 #endif
82719-};
82720+} __do_const;
82721+typedef struct attribute __no_const attribute_no_const;
82722
82723 /**
82724 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82725@@ -63,7 +64,8 @@ struct attribute_group {
82726 struct attribute *, int);
82727 struct attribute **attrs;
82728 struct bin_attribute **bin_attrs;
82729-};
82730+} __do_const;
82731+typedef struct attribute_group __no_const attribute_group_no_const;
82732
82733 /**
82734 * Use these macros to make defining attributes easier. See include/linux/device.h
82735@@ -128,7 +130,8 @@ struct bin_attribute {
82736 char *, loff_t, size_t);
82737 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82738 struct vm_area_struct *vma);
82739-};
82740+} __do_const;
82741+typedef struct bin_attribute __no_const bin_attribute_no_const;
82742
82743 /**
82744 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82745diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82746index 387fa7d..3fcde6b 100644
82747--- a/include/linux/sysrq.h
82748+++ b/include/linux/sysrq.h
82749@@ -16,6 +16,7 @@
82750
82751 #include <linux/errno.h>
82752 #include <linux/types.h>
82753+#include <linux/compiler.h>
82754
82755 /* Possible values of bitmask for enabling sysrq functions */
82756 /* 0x0001 is reserved for enable everything */
82757@@ -33,7 +34,7 @@ struct sysrq_key_op {
82758 char *help_msg;
82759 char *action_msg;
82760 int enable_mask;
82761-};
82762+} __do_const;
82763
82764 #ifdef CONFIG_MAGIC_SYSRQ
82765
82766diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82767index fddbe20..a0e76ab 100644
82768--- a/include/linux/thread_info.h
82769+++ b/include/linux/thread_info.h
82770@@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
82771 #error "no set_restore_sigmask() provided and default one won't work"
82772 #endif
82773
82774+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
82775+
82776+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82777+{
82778+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
82779+}
82780+
82781 #endif /* __KERNEL__ */
82782
82783 #endif /* _LINUX_THREAD_INFO_H */
82784diff --git a/include/linux/tty.h b/include/linux/tty.h
82785index 1c3316a..ae83b9f 100644
82786--- a/include/linux/tty.h
82787+++ b/include/linux/tty.h
82788@@ -202,7 +202,7 @@ struct tty_port {
82789 const struct tty_port_operations *ops; /* Port operations */
82790 spinlock_t lock; /* Lock protecting tty field */
82791 int blocked_open; /* Waiting to open */
82792- int count; /* Usage count */
82793+ atomic_t count; /* Usage count */
82794 wait_queue_head_t open_wait; /* Open waiters */
82795 wait_queue_head_t close_wait; /* Close waiters */
82796 wait_queue_head_t delta_msr_wait; /* Modem status change */
82797@@ -284,7 +284,7 @@ struct tty_struct {
82798 /* If the tty has a pending do_SAK, queue it here - akpm */
82799 struct work_struct SAK_work;
82800 struct tty_port *port;
82801-};
82802+} __randomize_layout;
82803
82804 /* Each of a tty's open files has private_data pointing to tty_file_private */
82805 struct tty_file_private {
82806@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82807 struct tty_struct *tty, struct file *filp);
82808 static inline int tty_port_users(struct tty_port *port)
82809 {
82810- return port->count + port->blocked_open;
82811+ return atomic_read(&port->count) + port->blocked_open;
82812 }
82813
82814 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82815diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82816index 756a609..89db85e 100644
82817--- a/include/linux/tty_driver.h
82818+++ b/include/linux/tty_driver.h
82819@@ -285,7 +285,7 @@ struct tty_operations {
82820 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82821 #endif
82822 const struct file_operations *proc_fops;
82823-};
82824+} __do_const __randomize_layout;
82825
82826 struct tty_driver {
82827 int magic; /* magic number for this structure */
82828@@ -319,7 +319,7 @@ struct tty_driver {
82829
82830 const struct tty_operations *ops;
82831 struct list_head tty_drivers;
82832-};
82833+} __randomize_layout;
82834
82835 extern struct list_head tty_drivers;
82836
82837diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82838index add26da..22c00bef 100644
82839--- a/include/linux/tty_ldisc.h
82840+++ b/include/linux/tty_ldisc.h
82841@@ -212,7 +212,7 @@ struct tty_ldisc_ops {
82842
82843 struct module *owner;
82844
82845- int refcount;
82846+ atomic_t refcount;
82847 };
82848
82849 struct tty_ldisc {
82850diff --git a/include/linux/types.h b/include/linux/types.h
82851index 4d118ba..c3ee9bf 100644
82852--- a/include/linux/types.h
82853+++ b/include/linux/types.h
82854@@ -176,10 +176,26 @@ typedef struct {
82855 int counter;
82856 } atomic_t;
82857
82858+#ifdef CONFIG_PAX_REFCOUNT
82859+typedef struct {
82860+ int counter;
82861+} atomic_unchecked_t;
82862+#else
82863+typedef atomic_t atomic_unchecked_t;
82864+#endif
82865+
82866 #ifdef CONFIG_64BIT
82867 typedef struct {
82868 long counter;
82869 } atomic64_t;
82870+
82871+#ifdef CONFIG_PAX_REFCOUNT
82872+typedef struct {
82873+ long counter;
82874+} atomic64_unchecked_t;
82875+#else
82876+typedef atomic64_t atomic64_unchecked_t;
82877+#endif
82878 #endif
82879
82880 struct list_head {
82881diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82882index ecd3319..8a36ded 100644
82883--- a/include/linux/uaccess.h
82884+++ b/include/linux/uaccess.h
82885@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82886 long ret; \
82887 mm_segment_t old_fs = get_fs(); \
82888 \
82889- set_fs(KERNEL_DS); \
82890 pagefault_disable(); \
82891- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82892- pagefault_enable(); \
82893+ set_fs(KERNEL_DS); \
82894+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82895 set_fs(old_fs); \
82896+ pagefault_enable(); \
82897 ret; \
82898 })
82899
82900diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82901index 2d1f9b6..d7a9fce 100644
82902--- a/include/linux/uidgid.h
82903+++ b/include/linux/uidgid.h
82904@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82905
82906 #endif /* CONFIG_USER_NS */
82907
82908+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82909+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82910+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82911+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82912+
82913 #endif /* _LINUX_UIDGID_H */
82914diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82915index 99c1b4d..562e6f3 100644
82916--- a/include/linux/unaligned/access_ok.h
82917+++ b/include/linux/unaligned/access_ok.h
82918@@ -4,34 +4,34 @@
82919 #include <linux/kernel.h>
82920 #include <asm/byteorder.h>
82921
82922-static inline u16 get_unaligned_le16(const void *p)
82923+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82924 {
82925- return le16_to_cpup((__le16 *)p);
82926+ return le16_to_cpup((const __le16 *)p);
82927 }
82928
82929-static inline u32 get_unaligned_le32(const void *p)
82930+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82931 {
82932- return le32_to_cpup((__le32 *)p);
82933+ return le32_to_cpup((const __le32 *)p);
82934 }
82935
82936-static inline u64 get_unaligned_le64(const void *p)
82937+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82938 {
82939- return le64_to_cpup((__le64 *)p);
82940+ return le64_to_cpup((const __le64 *)p);
82941 }
82942
82943-static inline u16 get_unaligned_be16(const void *p)
82944+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82945 {
82946- return be16_to_cpup((__be16 *)p);
82947+ return be16_to_cpup((const __be16 *)p);
82948 }
82949
82950-static inline u32 get_unaligned_be32(const void *p)
82951+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82952 {
82953- return be32_to_cpup((__be32 *)p);
82954+ return be32_to_cpup((const __be32 *)p);
82955 }
82956
82957-static inline u64 get_unaligned_be64(const void *p)
82958+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82959 {
82960- return be64_to_cpup((__be64 *)p);
82961+ return be64_to_cpup((const __be64 *)p);
82962 }
82963
82964 static inline void put_unaligned_le16(u16 val, void *p)
82965diff --git a/include/linux/usb.h b/include/linux/usb.h
82966index 6b7ec37..4428419 100644
82967--- a/include/linux/usb.h
82968+++ b/include/linux/usb.h
82969@@ -569,7 +569,7 @@ struct usb_device {
82970 int maxchild;
82971
82972 u32 quirks;
82973- atomic_t urbnum;
82974+ atomic_unchecked_t urbnum;
82975
82976 unsigned long active_duration;
82977
82978@@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82979
82980 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82981 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82982- void *data, __u16 size, int timeout);
82983+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
82984 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82985 void *data, int len, int *actual_length, int timeout);
82986 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82987diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82988index e452ba6..78f8e80 100644
82989--- a/include/linux/usb/renesas_usbhs.h
82990+++ b/include/linux/usb/renesas_usbhs.h
82991@@ -39,7 +39,7 @@ enum {
82992 */
82993 struct renesas_usbhs_driver_callback {
82994 int (*notify_hotplug)(struct platform_device *pdev);
82995-};
82996+} __no_const;
82997
82998 /*
82999 * callback functions for platform
83000diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83001index 4836ba3..603f6ee 100644
83002--- a/include/linux/user_namespace.h
83003+++ b/include/linux/user_namespace.h
83004@@ -33,7 +33,7 @@ struct user_namespace {
83005 struct key *persistent_keyring_register;
83006 struct rw_semaphore persistent_keyring_register_sem;
83007 #endif
83008-};
83009+} __randomize_layout;
83010
83011 extern struct user_namespace init_user_ns;
83012
83013diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83014index 239e277..22a5cf5 100644
83015--- a/include/linux/utsname.h
83016+++ b/include/linux/utsname.h
83017@@ -24,7 +24,7 @@ struct uts_namespace {
83018 struct new_utsname name;
83019 struct user_namespace *user_ns;
83020 unsigned int proc_inum;
83021-};
83022+} __randomize_layout;
83023 extern struct uts_namespace init_uts_ns;
83024
83025 #ifdef CONFIG_UTS_NS
83026diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83027index 6f8fbcf..4efc177 100644
83028--- a/include/linux/vermagic.h
83029+++ b/include/linux/vermagic.h
83030@@ -25,9 +25,42 @@
83031 #define MODULE_ARCH_VERMAGIC ""
83032 #endif
83033
83034+#ifdef CONFIG_PAX_REFCOUNT
83035+#define MODULE_PAX_REFCOUNT "REFCOUNT "
83036+#else
83037+#define MODULE_PAX_REFCOUNT ""
83038+#endif
83039+
83040+#ifdef CONSTIFY_PLUGIN
83041+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83042+#else
83043+#define MODULE_CONSTIFY_PLUGIN ""
83044+#endif
83045+
83046+#ifdef STACKLEAK_PLUGIN
83047+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83048+#else
83049+#define MODULE_STACKLEAK_PLUGIN ""
83050+#endif
83051+
83052+#ifdef RANDSTRUCT_PLUGIN
83053+#include <generated/randomize_layout_hash.h>
83054+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83055+#else
83056+#define MODULE_RANDSTRUCT_PLUGIN
83057+#endif
83058+
83059+#ifdef CONFIG_GRKERNSEC
83060+#define MODULE_GRSEC "GRSEC "
83061+#else
83062+#define MODULE_GRSEC ""
83063+#endif
83064+
83065 #define VERMAGIC_STRING \
83066 UTS_RELEASE " " \
83067 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83068 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83069- MODULE_ARCH_VERMAGIC
83070+ MODULE_ARCH_VERMAGIC \
83071+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83072+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83073
83074diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83075index 502073a..a7de024 100644
83076--- a/include/linux/vga_switcheroo.h
83077+++ b/include/linux/vga_switcheroo.h
83078@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83079
83080 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83081
83082-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83083-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83084+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83085+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83086 #else
83087
83088 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83089@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83090
83091 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83092
83093-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83094-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83095+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83096+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83097
83098 #endif
83099 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83100diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83101index 4b8a891..e9a2863 100644
83102--- a/include/linux/vmalloc.h
83103+++ b/include/linux/vmalloc.h
83104@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83105 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83106 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83107 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83108+
83109+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83110+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83111+#endif
83112+
83113 /* bits [20..32] reserved for arch specific ioremap internals */
83114
83115 /*
83116@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
83117 unsigned long flags, pgprot_t prot);
83118 extern void vunmap(const void *addr);
83119
83120+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83121+extern void unmap_process_stacks(struct task_struct *task);
83122+#endif
83123+
83124 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83125 unsigned long uaddr, void *kaddr,
83126 unsigned long size);
83127@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83128
83129 /* for /dev/kmem */
83130 extern long vread(char *buf, char *addr, unsigned long count);
83131-extern long vwrite(char *buf, char *addr, unsigned long count);
83132+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83133
83134 /*
83135 * Internals. Dont't use..
83136diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83137index 45c9cd1..20bd0bf 100644
83138--- a/include/linux/vmstat.h
83139+++ b/include/linux/vmstat.h
83140@@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83141 /*
83142 * Zone based page accounting with per cpu differentials.
83143 */
83144-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83145+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83146
83147 static inline void zone_page_state_add(long x, struct zone *zone,
83148 enum zone_stat_item item)
83149 {
83150- atomic_long_add(x, &zone->vm_stat[item]);
83151- atomic_long_add(x, &vm_stat[item]);
83152+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83153+ atomic_long_add_unchecked(x, &vm_stat[item]);
83154 }
83155
83156-static inline unsigned long global_page_state(enum zone_stat_item item)
83157+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83158 {
83159- long x = atomic_long_read(&vm_stat[item]);
83160+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83161 #ifdef CONFIG_SMP
83162 if (x < 0)
83163 x = 0;
83164@@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83165 return x;
83166 }
83167
83168-static inline unsigned long zone_page_state(struct zone *zone,
83169+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83170 enum zone_stat_item item)
83171 {
83172- long x = atomic_long_read(&zone->vm_stat[item]);
83173+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83174 #ifdef CONFIG_SMP
83175 if (x < 0)
83176 x = 0;
83177@@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83178 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83179 enum zone_stat_item item)
83180 {
83181- long x = atomic_long_read(&zone->vm_stat[item]);
83182+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83183
83184 #ifdef CONFIG_SMP
83185 int cpu;
83186@@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83187
83188 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83189 {
83190- atomic_long_inc(&zone->vm_stat[item]);
83191- atomic_long_inc(&vm_stat[item]);
83192+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83193+ atomic_long_inc_unchecked(&vm_stat[item]);
83194 }
83195
83196 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83197 {
83198- atomic_long_dec(&zone->vm_stat[item]);
83199- atomic_long_dec(&vm_stat[item]);
83200+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83201+ atomic_long_dec_unchecked(&vm_stat[item]);
83202 }
83203
83204 static inline void __inc_zone_page_state(struct page *page,
83205diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83206index 91b0a68..0e9adf6 100644
83207--- a/include/linux/xattr.h
83208+++ b/include/linux/xattr.h
83209@@ -28,7 +28,7 @@ struct xattr_handler {
83210 size_t size, int handler_flags);
83211 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83212 size_t size, int flags, int handler_flags);
83213-};
83214+} __do_const;
83215
83216 struct xattr {
83217 const char *name;
83218@@ -37,6 +37,9 @@ struct xattr {
83219 };
83220
83221 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83222+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83223+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83224+#endif
83225 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83226 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83227 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83228diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83229index 9c5a6b4..09c9438 100644
83230--- a/include/linux/zlib.h
83231+++ b/include/linux/zlib.h
83232@@ -31,6 +31,7 @@
83233 #define _ZLIB_H
83234
83235 #include <linux/zconf.h>
83236+#include <linux/compiler.h>
83237
83238 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83239 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83240@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83241
83242 /* basic functions */
83243
83244-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83245+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83246 /*
83247 Returns the number of bytes that needs to be allocated for a per-
83248 stream workspace with the specified parameters. A pointer to this
83249diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83250index eec6e46..82d5641 100644
83251--- a/include/media/v4l2-dev.h
83252+++ b/include/media/v4l2-dev.h
83253@@ -77,7 +77,7 @@ struct v4l2_file_operations {
83254 int (*mmap) (struct file *, struct vm_area_struct *);
83255 int (*open) (struct file *);
83256 int (*release) (struct file *);
83257-};
83258+} __do_const;
83259
83260 /*
83261 * Newer version of video_device, handled by videodev2.c
83262diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83263index c9b1593..a572459 100644
83264--- a/include/media/v4l2-device.h
83265+++ b/include/media/v4l2-device.h
83266@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83267 this function returns 0. If the name ends with a digit (e.g. cx18),
83268 then the name will be set to cx18-0 since cx180 looks really odd. */
83269 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83270- atomic_t *instance);
83271+ atomic_unchecked_t *instance);
83272
83273 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83274 Since the parent disappears this ensures that v4l2_dev doesn't have an
83275diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83276index d9fa68f..45c88d1 100644
83277--- a/include/net/9p/transport.h
83278+++ b/include/net/9p/transport.h
83279@@ -63,7 +63,7 @@ struct p9_trans_module {
83280 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83281 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83282 char *, char *, int , int, int, int);
83283-};
83284+} __do_const;
83285
83286 void v9fs_register_trans(struct p9_trans_module *m);
83287 void v9fs_unregister_trans(struct p9_trans_module *m);
83288diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83289index a175ba4..196eb82 100644
83290--- a/include/net/af_unix.h
83291+++ b/include/net/af_unix.h
83292@@ -36,7 +36,7 @@ struct unix_skb_parms {
83293 u32 secid; /* Security ID */
83294 #endif
83295 u32 consumed;
83296-};
83297+} __randomize_layout;
83298
83299 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83300 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83301diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83302index 4abdcb2..945c5cc 100644
83303--- a/include/net/bluetooth/l2cap.h
83304+++ b/include/net/bluetooth/l2cap.h
83305@@ -601,7 +601,7 @@ struct l2cap_ops {
83306 long (*get_sndtimeo) (struct l2cap_chan *chan);
83307 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83308 unsigned long len, int nb);
83309-};
83310+} __do_const;
83311
83312 struct l2cap_conn {
83313 struct hci_conn *hcon;
83314diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83315index f2ae33d..c457cf0 100644
83316--- a/include/net/caif/cfctrl.h
83317+++ b/include/net/caif/cfctrl.h
83318@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83319 void (*radioset_rsp)(void);
83320 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83321 struct cflayer *client_layer);
83322-};
83323+} __no_const;
83324
83325 /* Link Setup Parameters for CAIF-Links. */
83326 struct cfctrl_link_param {
83327@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83328 struct cfctrl {
83329 struct cfsrvl serv;
83330 struct cfctrl_rsp res;
83331- atomic_t req_seq_no;
83332- atomic_t rsp_seq_no;
83333+ atomic_unchecked_t req_seq_no;
83334+ atomic_unchecked_t rsp_seq_no;
83335 struct list_head list;
83336 /* Protects from simultaneous access to first_req list */
83337 spinlock_t info_list_lock;
83338diff --git a/include/net/flow.h b/include/net/flow.h
83339index 8109a15..504466d 100644
83340--- a/include/net/flow.h
83341+++ b/include/net/flow.h
83342@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
83343
83344 void flow_cache_flush(struct net *net);
83345 void flow_cache_flush_deferred(struct net *net);
83346-extern atomic_t flow_cache_genid;
83347+extern atomic_unchecked_t flow_cache_genid;
83348
83349 #endif
83350diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83351index 93695f0..766d71c 100644
83352--- a/include/net/genetlink.h
83353+++ b/include/net/genetlink.h
83354@@ -120,7 +120,7 @@ struct genl_ops {
83355 u8 cmd;
83356 u8 internal_flags;
83357 u8 flags;
83358-};
83359+} __do_const;
83360
83361 int __genl_register_family(struct genl_family *family);
83362
83363diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83364index 734d9b5..48a9a4b 100644
83365--- a/include/net/gro_cells.h
83366+++ b/include/net/gro_cells.h
83367@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83368 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83369
83370 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83371- atomic_long_inc(&dev->rx_dropped);
83372+ atomic_long_inc_unchecked(&dev->rx_dropped);
83373 kfree_skb(skb);
83374 return;
83375 }
83376diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83377index 7a43138..bc76865 100644
83378--- a/include/net/inet_connection_sock.h
83379+++ b/include/net/inet_connection_sock.h
83380@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83381 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83382 int (*bind_conflict)(const struct sock *sk,
83383 const struct inet_bind_bucket *tb, bool relax);
83384-};
83385+} __do_const;
83386
83387 /** inet_connection_sock - INET connection oriented sock
83388 *
83389diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83390index 058271b..1a44af7 100644
83391--- a/include/net/inetpeer.h
83392+++ b/include/net/inetpeer.h
83393@@ -47,8 +47,8 @@ struct inet_peer {
83394 */
83395 union {
83396 struct {
83397- atomic_t rid; /* Frag reception counter */
83398- atomic_t ip_id_count; /* IP ID for the next packet */
83399+ atomic_unchecked_t rid; /* Frag reception counter */
83400+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83401 };
83402 struct rcu_head rcu;
83403 struct inet_peer *gc_next;
83404@@ -179,7 +179,7 @@ static inline int inet_getid(struct inet_peer *p, int more)
83405 {
83406 more++;
83407 inet_peer_refcheck(p);
83408- return atomic_add_return(more, &p->ip_id_count) - more;
83409+ return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
83410 }
83411
83412 #endif /* _NET_INETPEER_H */
83413diff --git a/include/net/ip.h b/include/net/ip.h
83414index 3ec2b0f..72435b6 100644
83415--- a/include/net/ip.h
83416+++ b/include/net/ip.h
83417@@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83418
83419 void inet_get_local_port_range(struct net *net, int *low, int *high);
83420
83421-extern unsigned long *sysctl_local_reserved_ports;
83422+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83423 static inline int inet_is_reserved_local_port(int port)
83424 {
83425 return test_bit(port, sysctl_local_reserved_ports);
83426diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83427index 9922093..a1755d6 100644
83428--- a/include/net/ip_fib.h
83429+++ b/include/net/ip_fib.h
83430@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83431
83432 #define FIB_RES_SADDR(net, res) \
83433 ((FIB_RES_NH(res).nh_saddr_genid == \
83434- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83435+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83436 FIB_RES_NH(res).nh_saddr : \
83437 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83438 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83439diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83440index 5679d92..2e7a690 100644
83441--- a/include/net/ip_vs.h
83442+++ b/include/net/ip_vs.h
83443@@ -558,7 +558,7 @@ struct ip_vs_conn {
83444 struct ip_vs_conn *control; /* Master control connection */
83445 atomic_t n_control; /* Number of controlled ones */
83446 struct ip_vs_dest *dest; /* real server */
83447- atomic_t in_pkts; /* incoming packet counter */
83448+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83449
83450 /* packet transmitter for different forwarding methods. If it
83451 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83452@@ -705,7 +705,7 @@ struct ip_vs_dest {
83453 __be16 port; /* port number of the server */
83454 union nf_inet_addr addr; /* IP address of the server */
83455 volatile unsigned int flags; /* dest status flags */
83456- atomic_t conn_flags; /* flags to copy to conn */
83457+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83458 atomic_t weight; /* server weight */
83459
83460 atomic_t refcnt; /* reference counter */
83461@@ -960,11 +960,11 @@ struct netns_ipvs {
83462 /* ip_vs_lblc */
83463 int sysctl_lblc_expiration;
83464 struct ctl_table_header *lblc_ctl_header;
83465- struct ctl_table *lblc_ctl_table;
83466+ ctl_table_no_const *lblc_ctl_table;
83467 /* ip_vs_lblcr */
83468 int sysctl_lblcr_expiration;
83469 struct ctl_table_header *lblcr_ctl_header;
83470- struct ctl_table *lblcr_ctl_table;
83471+ ctl_table_no_const *lblcr_ctl_table;
83472 /* ip_vs_est */
83473 struct list_head est_list; /* estimator list */
83474 spinlock_t est_lock;
83475diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83476index 8d4f588..2e37ad2 100644
83477--- a/include/net/irda/ircomm_tty.h
83478+++ b/include/net/irda/ircomm_tty.h
83479@@ -33,6 +33,7 @@
83480 #include <linux/termios.h>
83481 #include <linux/timer.h>
83482 #include <linux/tty.h> /* struct tty_struct */
83483+#include <asm/local.h>
83484
83485 #include <net/irda/irias_object.h>
83486 #include <net/irda/ircomm_core.h>
83487diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83488index 714cc9a..ea05f3e 100644
83489--- a/include/net/iucv/af_iucv.h
83490+++ b/include/net/iucv/af_iucv.h
83491@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83492 struct iucv_sock_list {
83493 struct hlist_head head;
83494 rwlock_t lock;
83495- atomic_t autobind_name;
83496+ atomic_unchecked_t autobind_name;
83497 };
83498
83499 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83500diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83501index f3be818..bf46196 100644
83502--- a/include/net/llc_c_ac.h
83503+++ b/include/net/llc_c_ac.h
83504@@ -87,7 +87,7 @@
83505 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83506 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83507
83508-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83509+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83510
83511 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83512 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83513diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83514index 3948cf1..83b28c4 100644
83515--- a/include/net/llc_c_ev.h
83516+++ b/include/net/llc_c_ev.h
83517@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83518 return (struct llc_conn_state_ev *)skb->cb;
83519 }
83520
83521-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83522-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83523+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83524+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83525
83526 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83527 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83528diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83529index 0e79cfb..f46db31 100644
83530--- a/include/net/llc_c_st.h
83531+++ b/include/net/llc_c_st.h
83532@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83533 u8 next_state;
83534 llc_conn_ev_qfyr_t *ev_qualifiers;
83535 llc_conn_action_t *ev_actions;
83536-};
83537+} __do_const;
83538
83539 struct llc_conn_state {
83540 u8 current_state;
83541diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83542index a61b98c..aade1eb 100644
83543--- a/include/net/llc_s_ac.h
83544+++ b/include/net/llc_s_ac.h
83545@@ -23,7 +23,7 @@
83546 #define SAP_ACT_TEST_IND 9
83547
83548 /* All action functions must look like this */
83549-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83550+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83551
83552 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83553 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83554diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83555index 567c681..cd73ac02 100644
83556--- a/include/net/llc_s_st.h
83557+++ b/include/net/llc_s_st.h
83558@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83559 llc_sap_ev_t ev;
83560 u8 next_state;
83561 llc_sap_action_t *ev_actions;
83562-};
83563+} __do_const;
83564
83565 struct llc_sap_state {
83566 u8 curr_state;
83567diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83568index 8248e39..7610eec 100644
83569--- a/include/net/mac80211.h
83570+++ b/include/net/mac80211.h
83571@@ -4467,7 +4467,7 @@ struct rate_control_ops {
83572 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83573 struct dentry *dir);
83574 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83575-};
83576+} __do_const;
83577
83578 static inline int rate_supported(struct ieee80211_sta *sta,
83579 enum ieee80211_band band,
83580diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83581index 7277caf..fd095bc 100644
83582--- a/include/net/neighbour.h
83583+++ b/include/net/neighbour.h
83584@@ -163,7 +163,7 @@ struct neigh_ops {
83585 void (*error_report)(struct neighbour *, struct sk_buff *);
83586 int (*output)(struct neighbour *, struct sk_buff *);
83587 int (*connected_output)(struct neighbour *, struct sk_buff *);
83588-};
83589+} __do_const;
83590
83591 struct pneigh_entry {
83592 struct pneigh_entry *next;
83593@@ -203,7 +203,6 @@ struct neigh_table {
83594 void (*proxy_redo)(struct sk_buff *skb);
83595 char *id;
83596 struct neigh_parms parms;
83597- /* HACK. gc_* should follow parms without a gap! */
83598 int gc_interval;
83599 int gc_thresh1;
83600 int gc_thresh2;
83601@@ -218,7 +217,7 @@ struct neigh_table {
83602 struct neigh_statistics __percpu *stats;
83603 struct neigh_hash_table __rcu *nht;
83604 struct pneigh_entry **phash_buckets;
83605-};
83606+} __randomize_layout;
83607
83608 static inline int neigh_parms_family(struct neigh_parms *p)
83609 {
83610diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83611index 5f9eb26..85699c4 100644
83612--- a/include/net/net_namespace.h
83613+++ b/include/net/net_namespace.h
83614@@ -129,8 +129,8 @@ struct net {
83615 struct netns_ipvs *ipvs;
83616 #endif
83617 struct sock *diag_nlsk;
83618- atomic_t fnhe_genid;
83619-};
83620+ atomic_unchecked_t fnhe_genid;
83621+} __randomize_layout;
83622
83623 #include <linux/seq_file_net.h>
83624
83625@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83626 #define __net_init __init
83627 #define __net_exit __exit_refok
83628 #define __net_initdata __initdata
83629+#ifdef CONSTIFY_PLUGIN
83630 #define __net_initconst __initconst
83631+#else
83632+#define __net_initconst __initdata
83633+#endif
83634 #endif
83635
83636 struct pernet_operations {
83637@@ -296,7 +300,7 @@ struct pernet_operations {
83638 void (*exit_batch)(struct list_head *net_exit_list);
83639 int *id;
83640 size_t size;
83641-};
83642+} __do_const;
83643
83644 /*
83645 * Use these carefully. If you implement a network device and it
83646@@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83647
83648 static inline int rt_genid_ipv4(struct net *net)
83649 {
83650- return atomic_read(&net->ipv4.rt_genid);
83651+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83652 }
83653
83654 static inline void rt_genid_bump_ipv4(struct net *net)
83655 {
83656- atomic_inc(&net->ipv4.rt_genid);
83657+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83658 }
83659
83660 #if IS_ENABLED(CONFIG_IPV6)
83661 static inline int rt_genid_ipv6(struct net *net)
83662 {
83663- return atomic_read(&net->ipv6.rt_genid);
83664+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83665 }
83666
83667 static inline void rt_genid_bump_ipv6(struct net *net)
83668 {
83669- atomic_inc(&net->ipv6.rt_genid);
83670+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83671 }
83672 #else
83673 static inline int rt_genid_ipv6(struct net *net)
83674@@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
83675
83676 static inline int fnhe_genid(struct net *net)
83677 {
83678- return atomic_read(&net->fnhe_genid);
83679+ return atomic_read_unchecked(&net->fnhe_genid);
83680 }
83681
83682 static inline void fnhe_genid_bump(struct net *net)
83683 {
83684- atomic_inc(&net->fnhe_genid);
83685+ atomic_inc_unchecked(&net->fnhe_genid);
83686 }
83687
83688 #endif /* __NET_NET_NAMESPACE_H */
83689diff --git a/include/net/netdma.h b/include/net/netdma.h
83690index 8ba8ce2..99b7fff 100644
83691--- a/include/net/netdma.h
83692+++ b/include/net/netdma.h
83693@@ -24,7 +24,7 @@
83694 #include <linux/dmaengine.h>
83695 #include <linux/skbuff.h>
83696
83697-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83698+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83699 struct sk_buff *skb, int offset, struct iovec *to,
83700 size_t len, struct dma_pinned_list *pinned_list);
83701
83702diff --git a/include/net/netlink.h b/include/net/netlink.h
83703index 2b47eaa..6d5bcc2 100644
83704--- a/include/net/netlink.h
83705+++ b/include/net/netlink.h
83706@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83707 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83708 {
83709 if (mark)
83710- skb_trim(skb, (unsigned char *) mark - skb->data);
83711+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83712 }
83713
83714 /**
83715diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83716index 773cce3..6a11852 100644
83717--- a/include/net/netns/conntrack.h
83718+++ b/include/net/netns/conntrack.h
83719@@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
83720 struct nf_proto_net {
83721 #ifdef CONFIG_SYSCTL
83722 struct ctl_table_header *ctl_table_header;
83723- struct ctl_table *ctl_table;
83724+ ctl_table_no_const *ctl_table;
83725 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83726 struct ctl_table_header *ctl_compat_header;
83727- struct ctl_table *ctl_compat_table;
83728+ ctl_table_no_const *ctl_compat_table;
83729 #endif
83730 #endif
83731 unsigned int users;
83732@@ -59,7 +59,7 @@ struct nf_ip_net {
83733 struct nf_icmp_net icmpv6;
83734 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83735 struct ctl_table_header *ctl_table_header;
83736- struct ctl_table *ctl_table;
83737+ ctl_table_no_const *ctl_table;
83738 #endif
83739 };
83740
83741diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83742index b2704fd0..421d717 100644
83743--- a/include/net/netns/ipv4.h
83744+++ b/include/net/netns/ipv4.h
83745@@ -79,7 +79,7 @@ struct netns_ipv4 {
83746
83747 struct ping_group_range ping_group_range;
83748
83749- atomic_t dev_addr_genid;
83750+ atomic_unchecked_t dev_addr_genid;
83751
83752 #ifdef CONFIG_IP_MROUTE
83753 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83754@@ -89,6 +89,6 @@ struct netns_ipv4 {
83755 struct fib_rules_ops *mr_rules_ops;
83756 #endif
83757 #endif
83758- atomic_t rt_genid;
83759+ atomic_unchecked_t rt_genid;
83760 };
83761 #endif
83762diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83763index 21edaf1..4c5faae 100644
83764--- a/include/net/netns/ipv6.h
83765+++ b/include/net/netns/ipv6.h
83766@@ -73,8 +73,8 @@ struct netns_ipv6 {
83767 struct fib_rules_ops *mr6_rules_ops;
83768 #endif
83769 #endif
83770- atomic_t dev_addr_genid;
83771- atomic_t rt_genid;
83772+ atomic_unchecked_t dev_addr_genid;
83773+ atomic_unchecked_t rt_genid;
83774 };
83775
83776 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83777diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
83778index 3492434..209f58c 100644
83779--- a/include/net/netns/xfrm.h
83780+++ b/include/net/netns/xfrm.h
83781@@ -64,7 +64,7 @@ struct netns_xfrm {
83782
83783 /* flow cache part */
83784 struct flow_cache flow_cache_global;
83785- atomic_t flow_cache_genid;
83786+ atomic_unchecked_t flow_cache_genid;
83787 struct list_head flow_cache_gc_list;
83788 spinlock_t flow_cache_gc_lock;
83789 struct work_struct flow_cache_gc_work;
83790diff --git a/include/net/ping.h b/include/net/ping.h
83791index 026479b..d9b2829 100644
83792--- a/include/net/ping.h
83793+++ b/include/net/ping.h
83794@@ -54,7 +54,7 @@ struct ping_iter_state {
83795
83796 extern struct proto ping_prot;
83797 #if IS_ENABLED(CONFIG_IPV6)
83798-extern struct pingv6_ops pingv6_ops;
83799+extern struct pingv6_ops *pingv6_ops;
83800 #endif
83801
83802 struct pingfakehdr {
83803diff --git a/include/net/protocol.h b/include/net/protocol.h
83804index a7e986b..dc67bce 100644
83805--- a/include/net/protocol.h
83806+++ b/include/net/protocol.h
83807@@ -49,7 +49,7 @@ struct net_protocol {
83808 * socket lookup?
83809 */
83810 icmp_strict_tag_validation:1;
83811-};
83812+} __do_const;
83813
83814 #if IS_ENABLED(CONFIG_IPV6)
83815 struct inet6_protocol {
83816@@ -62,7 +62,7 @@ struct inet6_protocol {
83817 u8 type, u8 code, int offset,
83818 __be32 info);
83819 unsigned int flags; /* INET6_PROTO_xxx */
83820-};
83821+} __do_const;
83822
83823 #define INET6_PROTO_NOPOLICY 0x1
83824 #define INET6_PROTO_FINAL 0x2
83825diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83826index 72240e5..8c14bef 100644
83827--- a/include/net/rtnetlink.h
83828+++ b/include/net/rtnetlink.h
83829@@ -93,7 +93,7 @@ struct rtnl_link_ops {
83830 int (*fill_slave_info)(struct sk_buff *skb,
83831 const struct net_device *dev,
83832 const struct net_device *slave_dev);
83833-};
83834+} __do_const;
83835
83836 int __rtnl_link_register(struct rtnl_link_ops *ops);
83837 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83838diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83839index 4a5b9a3..ca27d73 100644
83840--- a/include/net/sctp/checksum.h
83841+++ b/include/net/sctp/checksum.h
83842@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83843 unsigned int offset)
83844 {
83845 struct sctphdr *sh = sctp_hdr(skb);
83846- __le32 ret, old = sh->checksum;
83847- const struct skb_checksum_ops ops = {
83848+ __le32 ret, old = sh->checksum;
83849+ static const struct skb_checksum_ops ops = {
83850 .update = sctp_csum_update,
83851 .combine = sctp_csum_combine,
83852 };
83853diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83854index 7f4eeb3..37e8fe1 100644
83855--- a/include/net/sctp/sm.h
83856+++ b/include/net/sctp/sm.h
83857@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83858 typedef struct {
83859 sctp_state_fn_t *fn;
83860 const char *name;
83861-} sctp_sm_table_entry_t;
83862+} __do_const sctp_sm_table_entry_t;
83863
83864 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83865 * currently in use.
83866@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83867 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83868
83869 /* Extern declarations for major data structures. */
83870-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83871+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83872
83873
83874 /* Get the size of a DATA chunk payload. */
83875diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83876index 0dfcc92..7967849 100644
83877--- a/include/net/sctp/structs.h
83878+++ b/include/net/sctp/structs.h
83879@@ -507,7 +507,7 @@ struct sctp_pf {
83880 struct sctp_association *asoc);
83881 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83882 struct sctp_af *af;
83883-};
83884+} __do_const;
83885
83886
83887 /* Structure to track chunk fragments that have been acked, but peer
83888diff --git a/include/net/sock.h b/include/net/sock.h
83889index 21569cf..dd60300 100644
83890--- a/include/net/sock.h
83891+++ b/include/net/sock.h
83892@@ -348,7 +348,7 @@ struct sock {
83893 unsigned int sk_napi_id;
83894 unsigned int sk_ll_usec;
83895 #endif
83896- atomic_t sk_drops;
83897+ atomic_unchecked_t sk_drops;
83898 int sk_rcvbuf;
83899
83900 struct sk_filter __rcu *sk_filter;
83901@@ -1036,7 +1036,7 @@ struct proto {
83902 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83903 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83904 #endif
83905-};
83906+} __randomize_layout;
83907
83908 /*
83909 * Bits in struct cg_proto.flags
83910@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83911 return ret >> PAGE_SHIFT;
83912 }
83913
83914-static inline long
83915+static inline long __intentional_overflow(-1)
83916 sk_memory_allocated(const struct sock *sk)
83917 {
83918 struct proto *prot = sk->sk_prot;
83919@@ -1368,7 +1368,7 @@ struct sock_iocb {
83920 struct scm_cookie *scm;
83921 struct msghdr *msg, async_msg;
83922 struct kiocb *kiocb;
83923-};
83924+} __randomize_layout;
83925
83926 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83927 {
83928@@ -1728,8 +1728,8 @@ sk_dst_get(struct sock *sk)
83929
83930 rcu_read_lock();
83931 dst = rcu_dereference(sk->sk_dst_cache);
83932- if (dst)
83933- dst_hold(dst);
83934+ if (dst && !atomic_inc_not_zero(&dst->__refcnt))
83935+ dst = NULL;
83936 rcu_read_unlock();
83937 return dst;
83938 }
83939@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83940 }
83941
83942 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83943- char __user *from, char *to,
83944+ char __user *from, unsigned char *to,
83945 int copy, int offset)
83946 {
83947 if (skb->ip_summed == CHECKSUM_NONE) {
83948@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83949 }
83950 }
83951
83952-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83953+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83954
83955 /**
83956 * sk_page_frag - return an appropriate page_frag
83957diff --git a/include/net/tcp.h b/include/net/tcp.h
83958index 87d8774..cf214f8 100644
83959--- a/include/net/tcp.h
83960+++ b/include/net/tcp.h
83961@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83962 void tcp_xmit_retransmit_queue(struct sock *);
83963 void tcp_simple_retransmit(struct sock *);
83964 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83965-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83966+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83967
83968 void tcp_send_probe0(struct sock *);
83969 void tcp_send_partial(struct sock *);
83970@@ -715,8 +715,8 @@ struct tcp_skb_cb {
83971 struct inet6_skb_parm h6;
83972 #endif
83973 } header; /* For incoming frames */
83974- __u32 seq; /* Starting sequence number */
83975- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83976+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
83977+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83978 __u32 when; /* used to compute rtt's */
83979 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83980
83981@@ -730,7 +730,7 @@ struct tcp_skb_cb {
83982
83983 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83984 /* 1 byte hole */
83985- __u32 ack_seq; /* Sequence number ACK'd */
83986+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83987 };
83988
83989 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83990diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83991index 116e9c7..3070537 100644
83992--- a/include/net/xfrm.h
83993+++ b/include/net/xfrm.h
83994@@ -285,7 +285,6 @@ struct xfrm_dst;
83995 struct xfrm_policy_afinfo {
83996 unsigned short family;
83997 struct dst_ops *dst_ops;
83998- void (*garbage_collect)(struct net *net);
83999 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84000 const xfrm_address_t *saddr,
84001 const xfrm_address_t *daddr);
84002@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
84003 struct net_device *dev,
84004 const struct flowi *fl);
84005 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84006-};
84007+} __do_const;
84008
84009 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84010 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84011@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
84012 int (*transport_finish)(struct sk_buff *skb,
84013 int async);
84014 void (*local_error)(struct sk_buff *skb, u32 mtu);
84015-};
84016+} __do_const;
84017
84018 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84019 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84020@@ -437,7 +436,7 @@ struct xfrm_mode {
84021 struct module *owner;
84022 unsigned int encap;
84023 int flags;
84024-};
84025+} __do_const;
84026
84027 /* Flags for xfrm_mode. */
84028 enum {
84029@@ -534,7 +533,7 @@ struct xfrm_policy {
84030 struct timer_list timer;
84031
84032 struct flow_cache_object flo;
84033- atomic_t genid;
84034+ atomic_unchecked_t genid;
84035 u32 priority;
84036 u32 index;
84037 struct xfrm_mark mark;
84038@@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84039 }
84040
84041 void xfrm_garbage_collect(struct net *net);
84042+void xfrm_garbage_collect_deferred(struct net *net);
84043
84044 #else
84045
84046@@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84047 static inline void xfrm_garbage_collect(struct net *net)
84048 {
84049 }
84050+static inline void xfrm_garbage_collect_deferred(struct net *net)
84051+{
84052+}
84053 #endif
84054
84055 static __inline__
84056diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84057index 1017e0b..227aa4d 100644
84058--- a/include/rdma/iw_cm.h
84059+++ b/include/rdma/iw_cm.h
84060@@ -122,7 +122,7 @@ struct iw_cm_verbs {
84061 int backlog);
84062
84063 int (*destroy_listen)(struct iw_cm_id *cm_id);
84064-};
84065+} __no_const;
84066
84067 /**
84068 * iw_create_cm_id - Create an IW CM identifier.
84069diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84070index 52beadf..598734c 100644
84071--- a/include/scsi/libfc.h
84072+++ b/include/scsi/libfc.h
84073@@ -771,6 +771,7 @@ struct libfc_function_template {
84074 */
84075 void (*disc_stop_final) (struct fc_lport *);
84076 };
84077+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84078
84079 /**
84080 * struct fc_disc - Discovery context
84081@@ -875,7 +876,7 @@ struct fc_lport {
84082 struct fc_vport *vport;
84083
84084 /* Operational Information */
84085- struct libfc_function_template tt;
84086+ libfc_function_template_no_const tt;
84087 u8 link_up;
84088 u8 qfull;
84089 enum fc_lport_state state;
84090diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84091index 5853c91..1e355a8 100644
84092--- a/include/scsi/scsi_device.h
84093+++ b/include/scsi/scsi_device.h
84094@@ -186,9 +186,9 @@ struct scsi_device {
84095 unsigned int max_device_blocked; /* what device_blocked counts down from */
84096 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84097
84098- atomic_t iorequest_cnt;
84099- atomic_t iodone_cnt;
84100- atomic_t ioerr_cnt;
84101+ atomic_unchecked_t iorequest_cnt;
84102+ atomic_unchecked_t iodone_cnt;
84103+ atomic_unchecked_t ioerr_cnt;
84104
84105 struct device sdev_gendev,
84106 sdev_dev;
84107diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84108index 8c79980..723f6f9 100644
84109--- a/include/scsi/scsi_transport_fc.h
84110+++ b/include/scsi/scsi_transport_fc.h
84111@@ -752,7 +752,8 @@ struct fc_function_template {
84112 unsigned long show_host_system_hostname:1;
84113
84114 unsigned long disable_target_scan:1;
84115-};
84116+} __do_const;
84117+typedef struct fc_function_template __no_const fc_function_template_no_const;
84118
84119
84120 /**
84121diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84122index ae6c3b8..fd748ac 100644
84123--- a/include/sound/compress_driver.h
84124+++ b/include/sound/compress_driver.h
84125@@ -128,7 +128,7 @@ struct snd_compr_ops {
84126 struct snd_compr_caps *caps);
84127 int (*get_codec_caps) (struct snd_compr_stream *stream,
84128 struct snd_compr_codec_caps *codec);
84129-};
84130+} __no_const;
84131
84132 /**
84133 * struct snd_compr: Compressed device
84134diff --git a/include/sound/soc.h b/include/sound/soc.h
84135index 0b83168..d67280a 100644
84136--- a/include/sound/soc.h
84137+++ b/include/sound/soc.h
84138@@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84139 /* probe ordering - for components with runtime dependencies */
84140 int probe_order;
84141 int remove_order;
84142-};
84143+} __do_const;
84144
84145 /* SoC platform interface */
84146 struct snd_soc_platform_driver {
84147@@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84148 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84149 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84150 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84151-};
84152+} __do_const;
84153
84154 struct snd_soc_platform {
84155 const char *name;
84156diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84157index 9ec9864..e2ee1ee 100644
84158--- a/include/target/target_core_base.h
84159+++ b/include/target/target_core_base.h
84160@@ -761,7 +761,7 @@ struct se_device {
84161 atomic_long_t write_bytes;
84162 /* Active commands on this virtual SE device */
84163 atomic_t simple_cmds;
84164- atomic_t dev_ordered_id;
84165+ atomic_unchecked_t dev_ordered_id;
84166 atomic_t dev_ordered_sync;
84167 atomic_t dev_qf_count;
84168 int export_count;
84169diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84170new file mode 100644
84171index 0000000..fb634b7
84172--- /dev/null
84173+++ b/include/trace/events/fs.h
84174@@ -0,0 +1,53 @@
84175+#undef TRACE_SYSTEM
84176+#define TRACE_SYSTEM fs
84177+
84178+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84179+#define _TRACE_FS_H
84180+
84181+#include <linux/fs.h>
84182+#include <linux/tracepoint.h>
84183+
84184+TRACE_EVENT(do_sys_open,
84185+
84186+ TP_PROTO(const char *filename, int flags, int mode),
84187+
84188+ TP_ARGS(filename, flags, mode),
84189+
84190+ TP_STRUCT__entry(
84191+ __string( filename, filename )
84192+ __field( int, flags )
84193+ __field( int, mode )
84194+ ),
84195+
84196+ TP_fast_assign(
84197+ __assign_str(filename, filename);
84198+ __entry->flags = flags;
84199+ __entry->mode = mode;
84200+ ),
84201+
84202+ TP_printk("\"%s\" %x %o",
84203+ __get_str(filename), __entry->flags, __entry->mode)
84204+);
84205+
84206+TRACE_EVENT(open_exec,
84207+
84208+ TP_PROTO(const char *filename),
84209+
84210+ TP_ARGS(filename),
84211+
84212+ TP_STRUCT__entry(
84213+ __string( filename, filename )
84214+ ),
84215+
84216+ TP_fast_assign(
84217+ __assign_str(filename, filename);
84218+ ),
84219+
84220+ TP_printk("\"%s\"",
84221+ __get_str(filename))
84222+);
84223+
84224+#endif /* _TRACE_FS_H */
84225+
84226+/* This part must be outside protection */
84227+#include <trace/define_trace.h>
84228diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84229index 1c09820..7f5ec79 100644
84230--- a/include/trace/events/irq.h
84231+++ b/include/trace/events/irq.h
84232@@ -36,7 +36,7 @@ struct softirq_action;
84233 */
84234 TRACE_EVENT(irq_handler_entry,
84235
84236- TP_PROTO(int irq, struct irqaction *action),
84237+ TP_PROTO(int irq, const struct irqaction *action),
84238
84239 TP_ARGS(irq, action),
84240
84241@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84242 */
84243 TRACE_EVENT(irq_handler_exit,
84244
84245- TP_PROTO(int irq, struct irqaction *action, int ret),
84246+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84247
84248 TP_ARGS(irq, action, ret),
84249
84250diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84251index 7caf44c..23c6f27 100644
84252--- a/include/uapi/linux/a.out.h
84253+++ b/include/uapi/linux/a.out.h
84254@@ -39,6 +39,14 @@ enum machine_type {
84255 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84256 };
84257
84258+/* Constants for the N_FLAGS field */
84259+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84260+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84261+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84262+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84263+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84264+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84265+
84266 #if !defined (N_MAGIC)
84267 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84268 #endif
84269diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84270index 22b6ad3..aeba37e 100644
84271--- a/include/uapi/linux/bcache.h
84272+++ b/include/uapi/linux/bcache.h
84273@@ -5,6 +5,7 @@
84274 * Bcache on disk data structures
84275 */
84276
84277+#include <linux/compiler.h>
84278 #include <asm/types.h>
84279
84280 #define BITMASK(name, type, field, offset, size) \
84281@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84282 /* Btree keys - all units are in sectors */
84283
84284 struct bkey {
84285- __u64 high;
84286- __u64 low;
84287+ __u64 high __intentional_overflow(-1);
84288+ __u64 low __intentional_overflow(-1);
84289 __u64 ptr[];
84290 };
84291
84292diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84293index d876736..ccce5c0 100644
84294--- a/include/uapi/linux/byteorder/little_endian.h
84295+++ b/include/uapi/linux/byteorder/little_endian.h
84296@@ -42,51 +42,51 @@
84297
84298 static inline __le64 __cpu_to_le64p(const __u64 *p)
84299 {
84300- return (__force __le64)*p;
84301+ return (__force const __le64)*p;
84302 }
84303-static inline __u64 __le64_to_cpup(const __le64 *p)
84304+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84305 {
84306- return (__force __u64)*p;
84307+ return (__force const __u64)*p;
84308 }
84309 static inline __le32 __cpu_to_le32p(const __u32 *p)
84310 {
84311- return (__force __le32)*p;
84312+ return (__force const __le32)*p;
84313 }
84314 static inline __u32 __le32_to_cpup(const __le32 *p)
84315 {
84316- return (__force __u32)*p;
84317+ return (__force const __u32)*p;
84318 }
84319 static inline __le16 __cpu_to_le16p(const __u16 *p)
84320 {
84321- return (__force __le16)*p;
84322+ return (__force const __le16)*p;
84323 }
84324 static inline __u16 __le16_to_cpup(const __le16 *p)
84325 {
84326- return (__force __u16)*p;
84327+ return (__force const __u16)*p;
84328 }
84329 static inline __be64 __cpu_to_be64p(const __u64 *p)
84330 {
84331- return (__force __be64)__swab64p(p);
84332+ return (__force const __be64)__swab64p(p);
84333 }
84334 static inline __u64 __be64_to_cpup(const __be64 *p)
84335 {
84336- return __swab64p((__u64 *)p);
84337+ return __swab64p((const __u64 *)p);
84338 }
84339 static inline __be32 __cpu_to_be32p(const __u32 *p)
84340 {
84341- return (__force __be32)__swab32p(p);
84342+ return (__force const __be32)__swab32p(p);
84343 }
84344-static inline __u32 __be32_to_cpup(const __be32 *p)
84345+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84346 {
84347- return __swab32p((__u32 *)p);
84348+ return __swab32p((const __u32 *)p);
84349 }
84350 static inline __be16 __cpu_to_be16p(const __u16 *p)
84351 {
84352- return (__force __be16)__swab16p(p);
84353+ return (__force const __be16)__swab16p(p);
84354 }
84355 static inline __u16 __be16_to_cpup(const __be16 *p)
84356 {
84357- return __swab16p((__u16 *)p);
84358+ return __swab16p((const __u16 *)p);
84359 }
84360 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84361 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84362diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84363index ef6103b..d4e65dd 100644
84364--- a/include/uapi/linux/elf.h
84365+++ b/include/uapi/linux/elf.h
84366@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84367 #define PT_GNU_EH_FRAME 0x6474e550
84368
84369 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84370+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84371+
84372+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84373+
84374+/* Constants for the e_flags field */
84375+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84376+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84377+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84378+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84379+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84380+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84381
84382 /*
84383 * Extended Numbering
84384@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84385 #define DT_DEBUG 21
84386 #define DT_TEXTREL 22
84387 #define DT_JMPREL 23
84388+#define DT_FLAGS 30
84389+ #define DF_TEXTREL 0x00000004
84390 #define DT_ENCODING 32
84391 #define OLD_DT_LOOS 0x60000000
84392 #define DT_LOOS 0x6000000d
84393@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84394 #define PF_W 0x2
84395 #define PF_X 0x1
84396
84397+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84398+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84399+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84400+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84401+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84402+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84403+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84404+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84405+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84406+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84407+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84408+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84409+
84410 typedef struct elf32_phdr{
84411 Elf32_Word p_type;
84412 Elf32_Off p_offset;
84413@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84414 #define EI_OSABI 7
84415 #define EI_PAD 8
84416
84417+#define EI_PAX 14
84418+
84419 #define ELFMAG0 0x7f /* EI_MAG */
84420 #define ELFMAG1 'E'
84421 #define ELFMAG2 'L'
84422diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84423index aa169c4..6a2771d 100644
84424--- a/include/uapi/linux/personality.h
84425+++ b/include/uapi/linux/personality.h
84426@@ -30,6 +30,7 @@ enum {
84427 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84428 ADDR_NO_RANDOMIZE | \
84429 ADDR_COMPAT_LAYOUT | \
84430+ ADDR_LIMIT_3GB | \
84431 MMAP_PAGE_ZERO)
84432
84433 /*
84434diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84435index 7530e74..e714828 100644
84436--- a/include/uapi/linux/screen_info.h
84437+++ b/include/uapi/linux/screen_info.h
84438@@ -43,7 +43,8 @@ struct screen_info {
84439 __u16 pages; /* 0x32 */
84440 __u16 vesa_attributes; /* 0x34 */
84441 __u32 capabilities; /* 0x36 */
84442- __u8 _reserved[6]; /* 0x3a */
84443+ __u16 vesapm_size; /* 0x3a */
84444+ __u8 _reserved[4]; /* 0x3c */
84445 } __attribute__((packed));
84446
84447 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84448diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84449index 0e011eb..82681b1 100644
84450--- a/include/uapi/linux/swab.h
84451+++ b/include/uapi/linux/swab.h
84452@@ -43,7 +43,7 @@
84453 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84454 */
84455
84456-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84457+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84458 {
84459 #ifdef __HAVE_BUILTIN_BSWAP16__
84460 return __builtin_bswap16(val);
84461@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84462 #endif
84463 }
84464
84465-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84466+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84467 {
84468 #ifdef __HAVE_BUILTIN_BSWAP32__
84469 return __builtin_bswap32(val);
84470@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84471 #endif
84472 }
84473
84474-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84475+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84476 {
84477 #ifdef __HAVE_BUILTIN_BSWAP64__
84478 return __builtin_bswap64(val);
84479diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84480index 6d67213..552fdd9 100644
84481--- a/include/uapi/linux/sysctl.h
84482+++ b/include/uapi/linux/sysctl.h
84483@@ -155,8 +155,6 @@ enum
84484 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84485 };
84486
84487-
84488-
84489 /* CTL_VM names: */
84490 enum
84491 {
84492diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84493index ea468ee..4d367a5 100644
84494--- a/include/uapi/linux/videodev2.h
84495+++ b/include/uapi/linux/videodev2.h
84496@@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
84497 union {
84498 __s32 value;
84499 __s64 value64;
84500- char *string;
84501+ char __user *string;
84502 };
84503 } __attribute__ ((packed));
84504
84505diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84506index c38355c..17a57bc 100644
84507--- a/include/uapi/linux/xattr.h
84508+++ b/include/uapi/linux/xattr.h
84509@@ -73,5 +73,9 @@
84510 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84511 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84512
84513+/* User namespace */
84514+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84515+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84516+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84517
84518 #endif /* _UAPI_LINUX_XATTR_H */
84519diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84520index f9466fa..f4e2b81 100644
84521--- a/include/video/udlfb.h
84522+++ b/include/video/udlfb.h
84523@@ -53,10 +53,10 @@ struct dlfb_data {
84524 u32 pseudo_palette[256];
84525 int blank_mode; /*one of FB_BLANK_ */
84526 /* blit-only rendering path metrics, exposed through sysfs */
84527- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84528- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84529- atomic_t bytes_sent; /* to usb, after compression including overhead */
84530- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84531+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84532+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84533+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84534+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84535 };
84536
84537 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84538diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84539index 30f5362..8ed8ac9 100644
84540--- a/include/video/uvesafb.h
84541+++ b/include/video/uvesafb.h
84542@@ -122,6 +122,7 @@ struct uvesafb_par {
84543 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84544 u8 pmi_setpal; /* PMI for palette changes */
84545 u16 *pmi_base; /* protected mode interface location */
84546+ u8 *pmi_code; /* protected mode code location */
84547 void *pmi_start;
84548 void *pmi_pal;
84549 u8 *vbe_state_orig; /*
84550diff --git a/init/Kconfig b/init/Kconfig
84551index 9d3585b..ad45d34 100644
84552--- a/init/Kconfig
84553+++ b/init/Kconfig
84554@@ -1093,6 +1093,7 @@ endif # CGROUPS
84555
84556 config CHECKPOINT_RESTORE
84557 bool "Checkpoint/restore support" if EXPERT
84558+ depends on !GRKERNSEC
84559 default n
84560 help
84561 Enables additional kernel features in a sake of checkpoint/restore.
84562@@ -1570,7 +1571,7 @@ config SLUB_DEBUG
84563
84564 config COMPAT_BRK
84565 bool "Disable heap randomization"
84566- default y
84567+ default n
84568 help
84569 Randomizing heap placement makes heap exploits harder, but it
84570 also breaks ancient binaries (including anything libc5 based).
84571@@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
84572 config STOP_MACHINE
84573 bool
84574 default y
84575- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84576+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84577 help
84578 Need stop_machine() primitive.
84579
84580diff --git a/init/Makefile b/init/Makefile
84581index 7bc47ee..6da2dc7 100644
84582--- a/init/Makefile
84583+++ b/init/Makefile
84584@@ -2,6 +2,9 @@
84585 # Makefile for the linux kernel.
84586 #
84587
84588+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84589+asflags-y := $(GCC_PLUGINS_AFLAGS)
84590+
84591 obj-y := main.o version.o mounts.o
84592 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84593 obj-y += noinitramfs.o
84594diff --git a/init/do_mounts.c b/init/do_mounts.c
84595index 82f2288..ea1430a 100644
84596--- a/init/do_mounts.c
84597+++ b/init/do_mounts.c
84598@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84599 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84600 {
84601 struct super_block *s;
84602- int err = sys_mount(name, "/root", fs, flags, data);
84603+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84604 if (err)
84605 return err;
84606
84607- sys_chdir("/root");
84608+ sys_chdir((const char __force_user *)"/root");
84609 s = current->fs->pwd.dentry->d_sb;
84610 ROOT_DEV = s->s_dev;
84611 printk(KERN_INFO
84612@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84613 va_start(args, fmt);
84614 vsprintf(buf, fmt, args);
84615 va_end(args);
84616- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84617+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84618 if (fd >= 0) {
84619 sys_ioctl(fd, FDEJECT, 0);
84620 sys_close(fd);
84621 }
84622 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84623- fd = sys_open("/dev/console", O_RDWR, 0);
84624+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84625 if (fd >= 0) {
84626 sys_ioctl(fd, TCGETS, (long)&termios);
84627 termios.c_lflag &= ~ICANON;
84628 sys_ioctl(fd, TCSETSF, (long)&termios);
84629- sys_read(fd, &c, 1);
84630+ sys_read(fd, (char __user *)&c, 1);
84631 termios.c_lflag |= ICANON;
84632 sys_ioctl(fd, TCSETSF, (long)&termios);
84633 sys_close(fd);
84634@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84635 mount_root();
84636 out:
84637 devtmpfs_mount("dev");
84638- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84639- sys_chroot(".");
84640+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84641+ sys_chroot((const char __force_user *)".");
84642 }
84643
84644 static bool is_tmpfs;
84645diff --git a/init/do_mounts.h b/init/do_mounts.h
84646index f5b978a..69dbfe8 100644
84647--- a/init/do_mounts.h
84648+++ b/init/do_mounts.h
84649@@ -15,15 +15,15 @@ extern int root_mountflags;
84650
84651 static inline int create_dev(char *name, dev_t dev)
84652 {
84653- sys_unlink(name);
84654- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84655+ sys_unlink((char __force_user *)name);
84656+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84657 }
84658
84659 #if BITS_PER_LONG == 32
84660 static inline u32 bstat(char *name)
84661 {
84662 struct stat64 stat;
84663- if (sys_stat64(name, &stat) != 0)
84664+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84665 return 0;
84666 if (!S_ISBLK(stat.st_mode))
84667 return 0;
84668@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84669 static inline u32 bstat(char *name)
84670 {
84671 struct stat stat;
84672- if (sys_newstat(name, &stat) != 0)
84673+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84674 return 0;
84675 if (!S_ISBLK(stat.st_mode))
84676 return 0;
84677diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84678index 3e0878e..8a9d7a0 100644
84679--- a/init/do_mounts_initrd.c
84680+++ b/init/do_mounts_initrd.c
84681@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84682 {
84683 sys_unshare(CLONE_FS | CLONE_FILES);
84684 /* stdin/stdout/stderr for /linuxrc */
84685- sys_open("/dev/console", O_RDWR, 0);
84686+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84687 sys_dup(0);
84688 sys_dup(0);
84689 /* move initrd over / and chdir/chroot in initrd root */
84690- sys_chdir("/root");
84691- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84692- sys_chroot(".");
84693+ sys_chdir((const char __force_user *)"/root");
84694+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84695+ sys_chroot((const char __force_user *)".");
84696 sys_setsid();
84697 return 0;
84698 }
84699@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84700 create_dev("/dev/root.old", Root_RAM0);
84701 /* mount initrd on rootfs' /root */
84702 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84703- sys_mkdir("/old", 0700);
84704- sys_chdir("/old");
84705+ sys_mkdir((const char __force_user *)"/old", 0700);
84706+ sys_chdir((const char __force_user *)"/old");
84707
84708 /* try loading default modules from initrd */
84709 load_default_modules();
84710@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84711 current->flags &= ~PF_FREEZER_SKIP;
84712
84713 /* move initrd to rootfs' /old */
84714- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84715+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84716 /* switch root and cwd back to / of rootfs */
84717- sys_chroot("..");
84718+ sys_chroot((const char __force_user *)"..");
84719
84720 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84721- sys_chdir("/old");
84722+ sys_chdir((const char __force_user *)"/old");
84723 return;
84724 }
84725
84726- sys_chdir("/");
84727+ sys_chdir((const char __force_user *)"/");
84728 ROOT_DEV = new_decode_dev(real_root_dev);
84729 mount_root();
84730
84731 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84732- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84733+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84734 if (!error)
84735 printk("okay\n");
84736 else {
84737- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84738+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84739 if (error == -ENOENT)
84740 printk("/initrd does not exist. Ignored.\n");
84741 else
84742 printk("failed\n");
84743 printk(KERN_NOTICE "Unmounting old root\n");
84744- sys_umount("/old", MNT_DETACH);
84745+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84746 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84747 if (fd < 0) {
84748 error = fd;
84749@@ -127,11 +127,11 @@ int __init initrd_load(void)
84750 * mounted in the normal path.
84751 */
84752 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84753- sys_unlink("/initrd.image");
84754+ sys_unlink((const char __force_user *)"/initrd.image");
84755 handle_initrd();
84756 return 1;
84757 }
84758 }
84759- sys_unlink("/initrd.image");
84760+ sys_unlink((const char __force_user *)"/initrd.image");
84761 return 0;
84762 }
84763diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84764index 8cb6db5..d729f50 100644
84765--- a/init/do_mounts_md.c
84766+++ b/init/do_mounts_md.c
84767@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84768 partitioned ? "_d" : "", minor,
84769 md_setup_args[ent].device_names);
84770
84771- fd = sys_open(name, 0, 0);
84772+ fd = sys_open((char __force_user *)name, 0, 0);
84773 if (fd < 0) {
84774 printk(KERN_ERR "md: open failed - cannot start "
84775 "array %s\n", name);
84776@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84777 * array without it
84778 */
84779 sys_close(fd);
84780- fd = sys_open(name, 0, 0);
84781+ fd = sys_open((char __force_user *)name, 0, 0);
84782 sys_ioctl(fd, BLKRRPART, 0);
84783 }
84784 sys_close(fd);
84785@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84786
84787 wait_for_device_probe();
84788
84789- fd = sys_open("/dev/md0", 0, 0);
84790+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84791 if (fd >= 0) {
84792 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84793 sys_close(fd);
84794diff --git a/init/init_task.c b/init/init_task.c
84795index ba0a7f36..2bcf1d5 100644
84796--- a/init/init_task.c
84797+++ b/init/init_task.c
84798@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84799 * Initial thread structure. Alignment of this is handled by a special
84800 * linker map entry.
84801 */
84802+#ifdef CONFIG_X86
84803+union thread_union init_thread_union __init_task_data;
84804+#else
84805 union thread_union init_thread_union __init_task_data =
84806 { INIT_THREAD_INFO(init_task) };
84807+#endif
84808diff --git a/init/initramfs.c b/init/initramfs.c
84809index a8497fa..35b3c90 100644
84810--- a/init/initramfs.c
84811+++ b/init/initramfs.c
84812@@ -84,7 +84,7 @@ static void __init free_hash(void)
84813 }
84814 }
84815
84816-static long __init do_utime(char *filename, time_t mtime)
84817+static long __init do_utime(char __force_user *filename, time_t mtime)
84818 {
84819 struct timespec t[2];
84820
84821@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84822 struct dir_entry *de, *tmp;
84823 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84824 list_del(&de->list);
84825- do_utime(de->name, de->mtime);
84826+ do_utime((char __force_user *)de->name, de->mtime);
84827 kfree(de->name);
84828 kfree(de);
84829 }
84830@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84831 if (nlink >= 2) {
84832 char *old = find_link(major, minor, ino, mode, collected);
84833 if (old)
84834- return (sys_link(old, collected) < 0) ? -1 : 1;
84835+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84836 }
84837 return 0;
84838 }
84839@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84840 {
84841 struct stat st;
84842
84843- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84844+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84845 if (S_ISDIR(st.st_mode))
84846- sys_rmdir(path);
84847+ sys_rmdir((char __force_user *)path);
84848 else
84849- sys_unlink(path);
84850+ sys_unlink((char __force_user *)path);
84851 }
84852 }
84853
84854@@ -315,7 +315,7 @@ static int __init do_name(void)
84855 int openflags = O_WRONLY|O_CREAT;
84856 if (ml != 1)
84857 openflags |= O_TRUNC;
84858- wfd = sys_open(collected, openflags, mode);
84859+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84860
84861 if (wfd >= 0) {
84862 sys_fchown(wfd, uid, gid);
84863@@ -327,17 +327,17 @@ static int __init do_name(void)
84864 }
84865 }
84866 } else if (S_ISDIR(mode)) {
84867- sys_mkdir(collected, mode);
84868- sys_chown(collected, uid, gid);
84869- sys_chmod(collected, mode);
84870+ sys_mkdir((char __force_user *)collected, mode);
84871+ sys_chown((char __force_user *)collected, uid, gid);
84872+ sys_chmod((char __force_user *)collected, mode);
84873 dir_add(collected, mtime);
84874 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84875 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84876 if (maybe_link() == 0) {
84877- sys_mknod(collected, mode, rdev);
84878- sys_chown(collected, uid, gid);
84879- sys_chmod(collected, mode);
84880- do_utime(collected, mtime);
84881+ sys_mknod((char __force_user *)collected, mode, rdev);
84882+ sys_chown((char __force_user *)collected, uid, gid);
84883+ sys_chmod((char __force_user *)collected, mode);
84884+ do_utime((char __force_user *)collected, mtime);
84885 }
84886 }
84887 return 0;
84888@@ -346,15 +346,15 @@ static int __init do_name(void)
84889 static int __init do_copy(void)
84890 {
84891 if (count >= body_len) {
84892- sys_write(wfd, victim, body_len);
84893+ sys_write(wfd, (char __force_user *)victim, body_len);
84894 sys_close(wfd);
84895- do_utime(vcollected, mtime);
84896+ do_utime((char __force_user *)vcollected, mtime);
84897 kfree(vcollected);
84898 eat(body_len);
84899 state = SkipIt;
84900 return 0;
84901 } else {
84902- sys_write(wfd, victim, count);
84903+ sys_write(wfd, (char __force_user *)victim, count);
84904 body_len -= count;
84905 eat(count);
84906 return 1;
84907@@ -365,9 +365,9 @@ static int __init do_symlink(void)
84908 {
84909 collected[N_ALIGN(name_len) + body_len] = '\0';
84910 clean_path(collected, 0);
84911- sys_symlink(collected + N_ALIGN(name_len), collected);
84912- sys_lchown(collected, uid, gid);
84913- do_utime(collected, mtime);
84914+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84915+ sys_lchown((char __force_user *)collected, uid, gid);
84916+ do_utime((char __force_user *)collected, mtime);
84917 state = SkipIt;
84918 next_state = Reset;
84919 return 0;
84920diff --git a/init/main.c b/init/main.c
84921index 48655ce..d0113e4 100644
84922--- a/init/main.c
84923+++ b/init/main.c
84924@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84925 static inline void mark_rodata_ro(void) { }
84926 #endif
84927
84928+extern void grsecurity_init(void);
84929+
84930 /*
84931 * Debug helper: via this flag we know that we are in 'early bootup code'
84932 * where only the boot processor is running with IRQ disabled. This means
84933@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84934
84935 __setup("reset_devices", set_reset_devices);
84936
84937+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84938+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84939+static int __init setup_grsec_proc_gid(char *str)
84940+{
84941+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84942+ return 1;
84943+}
84944+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84945+#endif
84946+
84947+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84948+unsigned long pax_user_shadow_base __read_only;
84949+EXPORT_SYMBOL(pax_user_shadow_base);
84950+extern char pax_enter_kernel_user[];
84951+extern char pax_exit_kernel_user[];
84952+#endif
84953+
84954+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84955+static int __init setup_pax_nouderef(char *str)
84956+{
84957+#ifdef CONFIG_X86_32
84958+ unsigned int cpu;
84959+ struct desc_struct *gdt;
84960+
84961+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84962+ gdt = get_cpu_gdt_table(cpu);
84963+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84964+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84965+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84966+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84967+ }
84968+ loadsegment(ds, __KERNEL_DS);
84969+ loadsegment(es, __KERNEL_DS);
84970+ loadsegment(ss, __KERNEL_DS);
84971+#else
84972+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84973+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84974+ clone_pgd_mask = ~(pgdval_t)0UL;
84975+ pax_user_shadow_base = 0UL;
84976+ setup_clear_cpu_cap(X86_FEATURE_PCID);
84977+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84978+#endif
84979+
84980+ return 0;
84981+}
84982+early_param("pax_nouderef", setup_pax_nouderef);
84983+
84984+#ifdef CONFIG_X86_64
84985+static int __init setup_pax_weakuderef(char *str)
84986+{
84987+ if (clone_pgd_mask != ~(pgdval_t)0UL)
84988+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84989+ return 1;
84990+}
84991+__setup("pax_weakuderef", setup_pax_weakuderef);
84992+#endif
84993+#endif
84994+
84995+#ifdef CONFIG_PAX_SOFTMODE
84996+int pax_softmode;
84997+
84998+static int __init setup_pax_softmode(char *str)
84999+{
85000+ get_option(&str, &pax_softmode);
85001+ return 1;
85002+}
85003+__setup("pax_softmode=", setup_pax_softmode);
85004+#endif
85005+
85006 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85007 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85008 static const char *panic_later, *panic_param;
85009@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85010 {
85011 int count = preempt_count();
85012 int ret;
85013- char msgbuf[64];
85014+ const char *msg1 = "", *msg2 = "";
85015
85016 if (initcall_debug)
85017 ret = do_one_initcall_debug(fn);
85018 else
85019 ret = fn();
85020
85021- msgbuf[0] = 0;
85022-
85023 if (preempt_count() != count) {
85024- sprintf(msgbuf, "preemption imbalance ");
85025+ msg1 = " preemption imbalance";
85026 preempt_count_set(count);
85027 }
85028 if (irqs_disabled()) {
85029- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85030+ msg2 = " disabled interrupts";
85031 local_irq_enable();
85032 }
85033- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85034+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85035
85036+ add_latent_entropy();
85037 return ret;
85038 }
85039
85040@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
85041 {
85042 argv_init[0] = init_filename;
85043 return do_execve(getname_kernel(init_filename),
85044- (const char __user *const __user *)argv_init,
85045- (const char __user *const __user *)envp_init);
85046+ (const char __user *const __force_user *)argv_init,
85047+ (const char __user *const __force_user *)envp_init);
85048 }
85049
85050 static int try_to_run_init_process(const char *init_filename)
85051@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
85052 return ret;
85053 }
85054
85055+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85056+extern int gr_init_ran;
85057+#endif
85058+
85059 static noinline void __init kernel_init_freeable(void);
85060
85061 static int __ref kernel_init(void *unused)
85062@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85063 ramdisk_execute_command, ret);
85064 }
85065
85066+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85067+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
85068+ gr_init_ran = 1;
85069+#endif
85070+
85071 /*
85072 * We try each of these until one succeeds.
85073 *
85074@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85075 do_basic_setup();
85076
85077 /* Open the /dev/console on the rootfs, this should never fail */
85078- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85079+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85080 pr_err("Warning: unable to open an initial console.\n");
85081
85082 (void) sys_dup(0);
85083@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85084 if (!ramdisk_execute_command)
85085 ramdisk_execute_command = "/init";
85086
85087- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85088+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85089 ramdisk_execute_command = NULL;
85090 prepare_namespace();
85091 }
85092
85093+ grsecurity_init();
85094+
85095 /*
85096 * Ok, we have completed the initial bootup, and
85097 * we're essentially up and running. Get rid of the
85098diff --git a/ipc/compat.c b/ipc/compat.c
85099index 45d035d..e4a7f99 100644
85100--- a/ipc/compat.c
85101+++ b/ipc/compat.c
85102@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85103 COMPAT_SHMLBA);
85104 if (err < 0)
85105 return err;
85106- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85107+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85108 }
85109 case SHMDT:
85110 return sys_shmdt(compat_ptr(ptr));
85111diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85112index 998d31b..30c24df 100644
85113--- a/ipc/ipc_sysctl.c
85114+++ b/ipc/ipc_sysctl.c
85115@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85116 static int proc_ipc_dointvec(ctl_table *table, int write,
85117 void __user *buffer, size_t *lenp, loff_t *ppos)
85118 {
85119- struct ctl_table ipc_table;
85120+ ctl_table_no_const ipc_table;
85121
85122 memcpy(&ipc_table, table, sizeof(ipc_table));
85123 ipc_table.data = get_ipc(table);
85124@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85125 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85126 void __user *buffer, size_t *lenp, loff_t *ppos)
85127 {
85128- struct ctl_table ipc_table;
85129+ ctl_table_no_const ipc_table;
85130
85131 memcpy(&ipc_table, table, sizeof(ipc_table));
85132 ipc_table.data = get_ipc(table);
85133@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85134 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85135 void __user *buffer, size_t *lenp, loff_t *ppos)
85136 {
85137- struct ctl_table ipc_table;
85138+ ctl_table_no_const ipc_table;
85139 size_t lenp_bef = *lenp;
85140 int rc;
85141
85142@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85143 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85144 void __user *buffer, size_t *lenp, loff_t *ppos)
85145 {
85146- struct ctl_table ipc_table;
85147+ ctl_table_no_const ipc_table;
85148 memcpy(&ipc_table, table, sizeof(ipc_table));
85149 ipc_table.data = get_ipc(table);
85150
85151@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85152 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85153 void __user *buffer, size_t *lenp, loff_t *ppos)
85154 {
85155- struct ctl_table ipc_table;
85156+ ctl_table_no_const ipc_table;
85157 size_t lenp_bef = *lenp;
85158 int oldval;
85159 int rc;
85160diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85161index 5bb8bfe..a38ec05 100644
85162--- a/ipc/mq_sysctl.c
85163+++ b/ipc/mq_sysctl.c
85164@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85165 static int proc_mq_dointvec(ctl_table *table, int write,
85166 void __user *buffer, size_t *lenp, loff_t *ppos)
85167 {
85168- struct ctl_table mq_table;
85169+ ctl_table_no_const mq_table;
85170 memcpy(&mq_table, table, sizeof(mq_table));
85171 mq_table.data = get_mq(table);
85172
85173@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85174 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85175 void __user *buffer, size_t *lenp, loff_t *ppos)
85176 {
85177- struct ctl_table mq_table;
85178+ ctl_table_no_const mq_table;
85179 memcpy(&mq_table, table, sizeof(mq_table));
85180 mq_table.data = get_mq(table);
85181
85182diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85183index 4fcf39a..d3cc2ec 100644
85184--- a/ipc/mqueue.c
85185+++ b/ipc/mqueue.c
85186@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85187 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85188 info->attr.mq_msgsize);
85189
85190+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85191 spin_lock(&mq_lock);
85192 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85193 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85194diff --git a/ipc/msg.c b/ipc/msg.c
85195index 6498531..b0ff3c8 100644
85196--- a/ipc/msg.c
85197+++ b/ipc/msg.c
85198@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85199 return security_msg_queue_associate(msq, msgflg);
85200 }
85201
85202+static struct ipc_ops msg_ops = {
85203+ .getnew = newque,
85204+ .associate = msg_security,
85205+ .more_checks = NULL
85206+};
85207+
85208 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85209 {
85210 struct ipc_namespace *ns;
85211- struct ipc_ops msg_ops;
85212 struct ipc_params msg_params;
85213
85214 ns = current->nsproxy->ipc_ns;
85215
85216- msg_ops.getnew = newque;
85217- msg_ops.associate = msg_security;
85218- msg_ops.more_checks = NULL;
85219-
85220 msg_params.key = key;
85221 msg_params.flg = msgflg;
85222
85223diff --git a/ipc/sem.c b/ipc/sem.c
85224index bee5554..e9af81dd 100644
85225--- a/ipc/sem.c
85226+++ b/ipc/sem.c
85227@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85228 return 0;
85229 }
85230
85231+static struct ipc_ops sem_ops = {
85232+ .getnew = newary,
85233+ .associate = sem_security,
85234+ .more_checks = sem_more_checks
85235+};
85236+
85237 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85238 {
85239 struct ipc_namespace *ns;
85240- struct ipc_ops sem_ops;
85241 struct ipc_params sem_params;
85242
85243 ns = current->nsproxy->ipc_ns;
85244@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85245 if (nsems < 0 || nsems > ns->sc_semmsl)
85246 return -EINVAL;
85247
85248- sem_ops.getnew = newary;
85249- sem_ops.associate = sem_security;
85250- sem_ops.more_checks = sem_more_checks;
85251-
85252 sem_params.key = key;
85253 sem_params.flg = semflg;
85254 sem_params.u.nsems = nsems;
85255diff --git a/ipc/shm.c b/ipc/shm.c
85256index 7645961..afc7f02 100644
85257--- a/ipc/shm.c
85258+++ b/ipc/shm.c
85259@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85260 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85261 #endif
85262
85263+#ifdef CONFIG_GRKERNSEC
85264+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85265+ const time_t shm_createtime, const kuid_t cuid,
85266+ const int shmid);
85267+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85268+ const time_t shm_createtime);
85269+#endif
85270+
85271 void shm_init_ns(struct ipc_namespace *ns)
85272 {
85273 ns->shm_ctlmax = SHMMAX;
85274@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85275 shp->shm_lprid = 0;
85276 shp->shm_atim = shp->shm_dtim = 0;
85277 shp->shm_ctim = get_seconds();
85278+#ifdef CONFIG_GRKERNSEC
85279+ {
85280+ struct timespec timeval;
85281+ do_posix_clock_monotonic_gettime(&timeval);
85282+
85283+ shp->shm_createtime = timeval.tv_sec;
85284+ }
85285+#endif
85286 shp->shm_segsz = size;
85287 shp->shm_nattch = 0;
85288 shp->shm_file = file;
85289@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85290 return 0;
85291 }
85292
85293+static struct ipc_ops shm_ops = {
85294+ .getnew = newseg,
85295+ .associate = shm_security,
85296+ .more_checks = shm_more_checks
85297+};
85298+
85299 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85300 {
85301 struct ipc_namespace *ns;
85302- struct ipc_ops shm_ops;
85303 struct ipc_params shm_params;
85304
85305 ns = current->nsproxy->ipc_ns;
85306
85307- shm_ops.getnew = newseg;
85308- shm_ops.associate = shm_security;
85309- shm_ops.more_checks = shm_more_checks;
85310-
85311 shm_params.key = key;
85312 shm_params.flg = shmflg;
85313 shm_params.u.size = size;
85314@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85315 f_mode = FMODE_READ | FMODE_WRITE;
85316 }
85317 if (shmflg & SHM_EXEC) {
85318+
85319+#ifdef CONFIG_PAX_MPROTECT
85320+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85321+ goto out;
85322+#endif
85323+
85324 prot |= PROT_EXEC;
85325 acc_mode |= S_IXUGO;
85326 }
85327@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85328 if (err)
85329 goto out_unlock;
85330
85331+#ifdef CONFIG_GRKERNSEC
85332+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85333+ shp->shm_perm.cuid, shmid) ||
85334+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85335+ err = -EACCES;
85336+ goto out_unlock;
85337+ }
85338+#endif
85339+
85340 ipc_lock_object(&shp->shm_perm);
85341
85342 /* check if shm_destroy() is tearing down shp */
85343@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85344 path = shp->shm_file->f_path;
85345 path_get(&path);
85346 shp->shm_nattch++;
85347+#ifdef CONFIG_GRKERNSEC
85348+ shp->shm_lapid = current->pid;
85349+#endif
85350 size = i_size_read(path.dentry->d_inode);
85351 ipc_unlock_object(&shp->shm_perm);
85352 rcu_read_unlock();
85353diff --git a/ipc/util.c b/ipc/util.c
85354index 2eb0d1e..0308564 100644
85355--- a/ipc/util.c
85356+++ b/ipc/util.c
85357@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85358 int (*show)(struct seq_file *, void *);
85359 };
85360
85361+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85362+
85363 static void ipc_memory_notifier(struct work_struct *work)
85364 {
85365 ipcns_notify(IPCNS_MEMCHANGED);
85366@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85367 granted_mode >>= 6;
85368 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85369 granted_mode >>= 3;
85370+
85371+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85372+ return -1;
85373+
85374 /* is there some bit set in requested_mode but not in granted_mode? */
85375 if ((requested_mode & ~granted_mode & 0007) &&
85376 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85377diff --git a/kernel/acct.c b/kernel/acct.c
85378index 8d6e145..33e0b1e 100644
85379--- a/kernel/acct.c
85380+++ b/kernel/acct.c
85381@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85382 */
85383 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85384 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85385- file->f_op->write(file, (char *)&ac,
85386+ file->f_op->write(file, (char __force_user *)&ac,
85387 sizeof(acct_t), &file->f_pos);
85388 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85389 set_fs(fs);
85390diff --git a/kernel/audit.c b/kernel/audit.c
85391index 47845c5..bd9dd5b 100644
85392--- a/kernel/audit.c
85393+++ b/kernel/audit.c
85394@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85395 3) suppressed due to audit_rate_limit
85396 4) suppressed due to audit_backlog_limit
85397 */
85398-static atomic_t audit_lost = ATOMIC_INIT(0);
85399+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85400
85401 /* The netlink socket. */
85402 static struct sock *audit_sock;
85403@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85404 unsigned long now;
85405 int print;
85406
85407- atomic_inc(&audit_lost);
85408+ atomic_inc_unchecked(&audit_lost);
85409
85410 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85411
85412@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85413 if (print) {
85414 if (printk_ratelimit())
85415 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85416- atomic_read(&audit_lost),
85417+ atomic_read_unchecked(&audit_lost),
85418 audit_rate_limit,
85419 audit_backlog_limit);
85420 audit_panic(message);
85421@@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85422 s.pid = audit_pid;
85423 s.rate_limit = audit_rate_limit;
85424 s.backlog_limit = audit_backlog_limit;
85425- s.lost = atomic_read(&audit_lost);
85426+ s.lost = atomic_read_unchecked(&audit_lost);
85427 s.backlog = skb_queue_len(&audit_skb_queue);
85428 s.version = AUDIT_VERSION_LATEST;
85429 s.backlog_wait_time = audit_backlog_wait_time;
85430diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85431index 21eae3c..66db239 100644
85432--- a/kernel/auditsc.c
85433+++ b/kernel/auditsc.c
85434@@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85435 }
85436
85437 /* global counter which is incremented every time something logs in */
85438-static atomic_t session_id = ATOMIC_INIT(0);
85439+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85440
85441 static int audit_set_loginuid_perm(kuid_t loginuid)
85442 {
85443@@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
85444
85445 /* are we setting or clearing? */
85446 if (uid_valid(loginuid))
85447- sessionid = (unsigned int)atomic_inc_return(&session_id);
85448+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85449
85450 task->sessionid = sessionid;
85451 task->loginuid = loginuid;
85452diff --git a/kernel/capability.c b/kernel/capability.c
85453index 24663b3..b926ae1 100644
85454--- a/kernel/capability.c
85455+++ b/kernel/capability.c
85456@@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85457 * before modification is attempted and the application
85458 * fails.
85459 */
85460+ if (tocopy > ARRAY_SIZE(kdata))
85461+ return -EFAULT;
85462+
85463 if (copy_to_user(dataptr, kdata, tocopy
85464 * sizeof(struct __user_cap_data_struct))) {
85465 return -EFAULT;
85466@@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
85467 int ret;
85468
85469 rcu_read_lock();
85470- ret = security_capable(__task_cred(t), ns, cap);
85471+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85472+ gr_task_is_capable(t, __task_cred(t), cap);
85473 rcu_read_unlock();
85474
85475- return (ret == 0);
85476+ return ret;
85477 }
85478
85479 /**
85480@@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85481 int ret;
85482
85483 rcu_read_lock();
85484- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85485+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85486 rcu_read_unlock();
85487
85488- return (ret == 0);
85489+ return ret;
85490 }
85491
85492 /**
85493@@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85494 BUG();
85495 }
85496
85497- if (security_capable(current_cred(), ns, cap) == 0) {
85498+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85499 current->flags |= PF_SUPERPRIV;
85500 return true;
85501 }
85502@@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85503 }
85504 EXPORT_SYMBOL(ns_capable);
85505
85506+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85507+{
85508+ if (unlikely(!cap_valid(cap))) {
85509+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85510+ BUG();
85511+ }
85512+
85513+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85514+ current->flags |= PF_SUPERPRIV;
85515+ return true;
85516+ }
85517+ return false;
85518+}
85519+EXPORT_SYMBOL(ns_capable_nolog);
85520+
85521 /**
85522 * file_ns_capable - Determine if the file's opener had a capability in effect
85523 * @file: The file we want to check
85524@@ -423,6 +442,12 @@ bool capable(int cap)
85525 }
85526 EXPORT_SYMBOL(capable);
85527
85528+bool capable_nolog(int cap)
85529+{
85530+ return ns_capable_nolog(&init_user_ns, cap);
85531+}
85532+EXPORT_SYMBOL(capable_nolog);
85533+
85534 /**
85535 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
85536 * @inode: The inode in question
85537@@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
85538 kgid_has_mapping(ns, inode->i_gid);
85539 }
85540 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
85541+
85542+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
85543+{
85544+ struct user_namespace *ns = current_user_ns();
85545+
85546+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
85547+ kgid_has_mapping(ns, inode->i_gid);
85548+}
85549+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
85550diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85551index ceee0c5..d6f81dd 100644
85552--- a/kernel/cgroup.c
85553+++ b/kernel/cgroup.c
85554@@ -4757,7 +4757,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85555 struct task_struct *task;
85556 int count = 0;
85557
85558- seq_printf(seq, "css_set %p\n", cset);
85559+ seq_printf(seq, "css_set %pK\n", cset);
85560
85561 list_for_each_entry(task, &cset->tasks, cg_list) {
85562 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
85563diff --git a/kernel/compat.c b/kernel/compat.c
85564index e40b043..3da8f51 100644
85565--- a/kernel/compat.c
85566+++ b/kernel/compat.c
85567@@ -13,6 +13,7 @@
85568
85569 #include <linux/linkage.h>
85570 #include <linux/compat.h>
85571+#include <linux/module.h>
85572 #include <linux/errno.h>
85573 #include <linux/time.h>
85574 #include <linux/signal.h>
85575@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85576 mm_segment_t oldfs;
85577 long ret;
85578
85579- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85580+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85581 oldfs = get_fs();
85582 set_fs(KERNEL_DS);
85583 ret = hrtimer_nanosleep_restart(restart);
85584@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
85585 oldfs = get_fs();
85586 set_fs(KERNEL_DS);
85587 ret = hrtimer_nanosleep(&tu,
85588- rmtp ? (struct timespec __user *)&rmt : NULL,
85589+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85590 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85591 set_fs(oldfs);
85592
85593@@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
85594 mm_segment_t old_fs = get_fs();
85595
85596 set_fs(KERNEL_DS);
85597- ret = sys_sigpending((old_sigset_t __user *) &s);
85598+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85599 set_fs(old_fs);
85600 if (ret == 0)
85601 ret = put_user(s, set);
85602@@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
85603 mm_segment_t old_fs = get_fs();
85604
85605 set_fs(KERNEL_DS);
85606- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
85607+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85608 set_fs(old_fs);
85609
85610 if (!ret) {
85611@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85612 set_fs (KERNEL_DS);
85613 ret = sys_wait4(pid,
85614 (stat_addr ?
85615- (unsigned int __user *) &status : NULL),
85616- options, (struct rusage __user *) &r);
85617+ (unsigned int __force_user *) &status : NULL),
85618+ options, (struct rusage __force_user *) &r);
85619 set_fs (old_fs);
85620
85621 if (ret > 0) {
85622@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85623 memset(&info, 0, sizeof(info));
85624
85625 set_fs(KERNEL_DS);
85626- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85627- uru ? (struct rusage __user *)&ru : NULL);
85628+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85629+ uru ? (struct rusage __force_user *)&ru : NULL);
85630 set_fs(old_fs);
85631
85632 if ((ret < 0) || (info.si_signo == 0))
85633@@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
85634 oldfs = get_fs();
85635 set_fs(KERNEL_DS);
85636 err = sys_timer_settime(timer_id, flags,
85637- (struct itimerspec __user *) &newts,
85638- (struct itimerspec __user *) &oldts);
85639+ (struct itimerspec __force_user *) &newts,
85640+ (struct itimerspec __force_user *) &oldts);
85641 set_fs(oldfs);
85642 if (!err && old && put_compat_itimerspec(old, &oldts))
85643 return -EFAULT;
85644@@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
85645 oldfs = get_fs();
85646 set_fs(KERNEL_DS);
85647 err = sys_timer_gettime(timer_id,
85648- (struct itimerspec __user *) &ts);
85649+ (struct itimerspec __force_user *) &ts);
85650 set_fs(oldfs);
85651 if (!err && put_compat_itimerspec(setting, &ts))
85652 return -EFAULT;
85653@@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
85654 oldfs = get_fs();
85655 set_fs(KERNEL_DS);
85656 err = sys_clock_settime(which_clock,
85657- (struct timespec __user *) &ts);
85658+ (struct timespec __force_user *) &ts);
85659 set_fs(oldfs);
85660 return err;
85661 }
85662@@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
85663 oldfs = get_fs();
85664 set_fs(KERNEL_DS);
85665 err = sys_clock_gettime(which_clock,
85666- (struct timespec __user *) &ts);
85667+ (struct timespec __force_user *) &ts);
85668 set_fs(oldfs);
85669 if (!err && compat_put_timespec(&ts, tp))
85670 return -EFAULT;
85671@@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
85672
85673 oldfs = get_fs();
85674 set_fs(KERNEL_DS);
85675- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85676+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85677 set_fs(oldfs);
85678
85679 err = compat_put_timex(utp, &txc);
85680@@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
85681 oldfs = get_fs();
85682 set_fs(KERNEL_DS);
85683 err = sys_clock_getres(which_clock,
85684- (struct timespec __user *) &ts);
85685+ (struct timespec __force_user *) &ts);
85686 set_fs(oldfs);
85687 if (!err && tp && compat_put_timespec(&ts, tp))
85688 return -EFAULT;
85689@@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85690 struct timespec tu;
85691 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85692
85693- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85694+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85695 oldfs = get_fs();
85696 set_fs(KERNEL_DS);
85697 err = clock_nanosleep_restart(restart);
85698@@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
85699 oldfs = get_fs();
85700 set_fs(KERNEL_DS);
85701 err = sys_clock_nanosleep(which_clock, flags,
85702- (struct timespec __user *) &in,
85703- (struct timespec __user *) &out);
85704+ (struct timespec __force_user *) &in,
85705+ (struct timespec __force_user *) &out);
85706 set_fs(oldfs);
85707
85708 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85709@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85710 mm_segment_t old_fs = get_fs();
85711
85712 set_fs(KERNEL_DS);
85713- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85714+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85715 set_fs(old_fs);
85716 if (compat_put_timespec(&t, interval))
85717 return -EFAULT;
85718diff --git a/kernel/configs.c b/kernel/configs.c
85719index c18b1f1..b9a0132 100644
85720--- a/kernel/configs.c
85721+++ b/kernel/configs.c
85722@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85723 struct proc_dir_entry *entry;
85724
85725 /* create the current config file */
85726+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85727+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85728+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85729+ &ikconfig_file_ops);
85730+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85731+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85732+ &ikconfig_file_ops);
85733+#endif
85734+#else
85735 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85736 &ikconfig_file_ops);
85737+#endif
85738+
85739 if (!entry)
85740 return -ENOMEM;
85741
85742diff --git a/kernel/cred.c b/kernel/cred.c
85743index e0573a4..26c0fd3 100644
85744--- a/kernel/cred.c
85745+++ b/kernel/cred.c
85746@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85747 validate_creds(cred);
85748 alter_cred_subscribers(cred, -1);
85749 put_cred(cred);
85750+
85751+#ifdef CONFIG_GRKERNSEC_SETXID
85752+ cred = (struct cred *) tsk->delayed_cred;
85753+ if (cred != NULL) {
85754+ tsk->delayed_cred = NULL;
85755+ validate_creds(cred);
85756+ alter_cred_subscribers(cred, -1);
85757+ put_cred(cred);
85758+ }
85759+#endif
85760 }
85761
85762 /**
85763@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85764 * Always returns 0 thus allowing this function to be tail-called at the end
85765 * of, say, sys_setgid().
85766 */
85767-int commit_creds(struct cred *new)
85768+static int __commit_creds(struct cred *new)
85769 {
85770 struct task_struct *task = current;
85771 const struct cred *old = task->real_cred;
85772@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85773
85774 get_cred(new); /* we will require a ref for the subj creds too */
85775
85776+ gr_set_role_label(task, new->uid, new->gid);
85777+
85778 /* dumpability changes */
85779 if (!uid_eq(old->euid, new->euid) ||
85780 !gid_eq(old->egid, new->egid) ||
85781@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
85782 put_cred(old);
85783 return 0;
85784 }
85785+#ifdef CONFIG_GRKERNSEC_SETXID
85786+extern int set_user(struct cred *new);
85787+
85788+void gr_delayed_cred_worker(void)
85789+{
85790+ const struct cred *new = current->delayed_cred;
85791+ struct cred *ncred;
85792+
85793+ current->delayed_cred = NULL;
85794+
85795+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85796+ // from doing get_cred on it when queueing this
85797+ put_cred(new);
85798+ return;
85799+ } else if (new == NULL)
85800+ return;
85801+
85802+ ncred = prepare_creds();
85803+ if (!ncred)
85804+ goto die;
85805+ // uids
85806+ ncred->uid = new->uid;
85807+ ncred->euid = new->euid;
85808+ ncred->suid = new->suid;
85809+ ncred->fsuid = new->fsuid;
85810+ // gids
85811+ ncred->gid = new->gid;
85812+ ncred->egid = new->egid;
85813+ ncred->sgid = new->sgid;
85814+ ncred->fsgid = new->fsgid;
85815+ // groups
85816+ set_groups(ncred, new->group_info);
85817+ // caps
85818+ ncred->securebits = new->securebits;
85819+ ncred->cap_inheritable = new->cap_inheritable;
85820+ ncred->cap_permitted = new->cap_permitted;
85821+ ncred->cap_effective = new->cap_effective;
85822+ ncred->cap_bset = new->cap_bset;
85823+
85824+ if (set_user(ncred)) {
85825+ abort_creds(ncred);
85826+ goto die;
85827+ }
85828+
85829+ // from doing get_cred on it when queueing this
85830+ put_cred(new);
85831+
85832+ __commit_creds(ncred);
85833+ return;
85834+die:
85835+ // from doing get_cred on it when queueing this
85836+ put_cred(new);
85837+ do_group_exit(SIGKILL);
85838+}
85839+#endif
85840+
85841+int commit_creds(struct cred *new)
85842+{
85843+#ifdef CONFIG_GRKERNSEC_SETXID
85844+ int ret;
85845+ int schedule_it = 0;
85846+ struct task_struct *t;
85847+ unsigned oldsecurebits = current_cred()->securebits;
85848+
85849+ /* we won't get called with tasklist_lock held for writing
85850+ and interrupts disabled as the cred struct in that case is
85851+ init_cred
85852+ */
85853+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85854+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85855+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85856+ schedule_it = 1;
85857+ }
85858+ ret = __commit_creds(new);
85859+ if (schedule_it) {
85860+ rcu_read_lock();
85861+ read_lock(&tasklist_lock);
85862+ for (t = next_thread(current); t != current;
85863+ t = next_thread(t)) {
85864+ /* we'll check if the thread has uid 0 in
85865+ * the delayed worker routine
85866+ */
85867+ if (task_securebits(t) == oldsecurebits &&
85868+ t->delayed_cred == NULL) {
85869+ t->delayed_cred = get_cred(new);
85870+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85871+ set_tsk_need_resched(t);
85872+ }
85873+ }
85874+ read_unlock(&tasklist_lock);
85875+ rcu_read_unlock();
85876+ }
85877+
85878+ return ret;
85879+#else
85880+ return __commit_creds(new);
85881+#endif
85882+}
85883+
85884 EXPORT_SYMBOL(commit_creds);
85885
85886 /**
85887diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85888index 2956c8d..cfe1e2e 100644
85889--- a/kernel/debug/debug_core.c
85890+++ b/kernel/debug/debug_core.c
85891@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85892 */
85893 static atomic_t masters_in_kgdb;
85894 static atomic_t slaves_in_kgdb;
85895-static atomic_t kgdb_break_tasklet_var;
85896+static atomic_unchecked_t kgdb_break_tasklet_var;
85897 atomic_t kgdb_setting_breakpoint;
85898
85899 struct task_struct *kgdb_usethread;
85900@@ -134,7 +134,7 @@ int kgdb_single_step;
85901 static pid_t kgdb_sstep_pid;
85902
85903 /* to keep track of the CPU which is doing the single stepping*/
85904-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85905+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85906
85907 /*
85908 * If you are debugging a problem where roundup (the collection of
85909@@ -549,7 +549,7 @@ return_normal:
85910 * kernel will only try for the value of sstep_tries before
85911 * giving up and continuing on.
85912 */
85913- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85914+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85915 (kgdb_info[cpu].task &&
85916 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85917 atomic_set(&kgdb_active, -1);
85918@@ -647,8 +647,8 @@ cpu_master_loop:
85919 }
85920
85921 kgdb_restore:
85922- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85923- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85924+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85925+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85926 if (kgdb_info[sstep_cpu].task)
85927 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85928 else
85929@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
85930 static void kgdb_tasklet_bpt(unsigned long ing)
85931 {
85932 kgdb_breakpoint();
85933- atomic_set(&kgdb_break_tasklet_var, 0);
85934+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85935 }
85936
85937 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85938
85939 void kgdb_schedule_breakpoint(void)
85940 {
85941- if (atomic_read(&kgdb_break_tasklet_var) ||
85942+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85943 atomic_read(&kgdb_active) != -1 ||
85944 atomic_read(&kgdb_setting_breakpoint))
85945 return;
85946- atomic_inc(&kgdb_break_tasklet_var);
85947+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
85948 tasklet_schedule(&kgdb_tasklet_breakpoint);
85949 }
85950 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85951diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85952index 0b097c8..11dd5c5 100644
85953--- a/kernel/debug/kdb/kdb_main.c
85954+++ b/kernel/debug/kdb/kdb_main.c
85955@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85956 continue;
85957
85958 kdb_printf("%-20s%8u 0x%p ", mod->name,
85959- mod->core_size, (void *)mod);
85960+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
85961 #ifdef CONFIG_MODULE_UNLOAD
85962 kdb_printf("%4ld ", module_refcount(mod));
85963 #endif
85964@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85965 kdb_printf(" (Loading)");
85966 else
85967 kdb_printf(" (Live)");
85968- kdb_printf(" 0x%p", mod->module_core);
85969+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85970
85971 #ifdef CONFIG_MODULE_UNLOAD
85972 {
85973diff --git a/kernel/events/core.c b/kernel/events/core.c
85974index 440eefc..0909f02 100644
85975--- a/kernel/events/core.c
85976+++ b/kernel/events/core.c
85977@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85978 * 0 - disallow raw tracepoint access for unpriv
85979 * 1 - disallow cpu events for unpriv
85980 * 2 - disallow kernel profiling for unpriv
85981+ * 3 - disallow all unpriv perf event use
85982 */
85983-int sysctl_perf_event_paranoid __read_mostly = 1;
85984+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85985+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85986+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85987+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85988+#else
85989+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85990+#endif
85991
85992 /* Minimum for 512 kiB + 1 user control page */
85993 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85994@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85995
85996 tmp *= sysctl_perf_cpu_time_max_percent;
85997 do_div(tmp, 100);
85998- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85999+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86000 }
86001
86002 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86003@@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86004 }
86005 }
86006
86007-static atomic64_t perf_event_id;
86008+static atomic64_unchecked_t perf_event_id;
86009
86010 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86011 enum event_type_t event_type);
86012@@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
86013
86014 static inline u64 perf_event_count(struct perf_event *event)
86015 {
86016- return local64_read(&event->count) + atomic64_read(&event->child_count);
86017+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86018 }
86019
86020 static u64 perf_event_read(struct perf_event *event)
86021@@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86022 mutex_lock(&event->child_mutex);
86023 total += perf_event_read(event);
86024 *enabled += event->total_time_enabled +
86025- atomic64_read(&event->child_total_time_enabled);
86026+ atomic64_read_unchecked(&event->child_total_time_enabled);
86027 *running += event->total_time_running +
86028- atomic64_read(&event->child_total_time_running);
86029+ atomic64_read_unchecked(&event->child_total_time_running);
86030
86031 list_for_each_entry(child, &event->child_list, child_list) {
86032 total += perf_event_read(child);
86033@@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
86034 userpg->offset -= local64_read(&event->hw.prev_count);
86035
86036 userpg->time_enabled = enabled +
86037- atomic64_read(&event->child_total_time_enabled);
86038+ atomic64_read_unchecked(&event->child_total_time_enabled);
86039
86040 userpg->time_running = running +
86041- atomic64_read(&event->child_total_time_running);
86042+ atomic64_read_unchecked(&event->child_total_time_running);
86043
86044 arch_perf_update_userpage(userpg, now);
86045
86046@@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86047
86048 /* Data. */
86049 sp = perf_user_stack_pointer(regs);
86050- rem = __output_copy_user(handle, (void *) sp, dump_size);
86051+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86052 dyn_size = dump_size - rem;
86053
86054 perf_output_skip(handle, rem);
86055@@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86056 values[n++] = perf_event_count(event);
86057 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86058 values[n++] = enabled +
86059- atomic64_read(&event->child_total_time_enabled);
86060+ atomic64_read_unchecked(&event->child_total_time_enabled);
86061 }
86062 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86063 values[n++] = running +
86064- atomic64_read(&event->child_total_time_running);
86065+ atomic64_read_unchecked(&event->child_total_time_running);
86066 }
86067 if (read_format & PERF_FORMAT_ID)
86068 values[n++] = primary_event_id(event);
86069@@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86070 event->parent = parent_event;
86071
86072 event->ns = get_pid_ns(task_active_pid_ns(current));
86073- event->id = atomic64_inc_return(&perf_event_id);
86074+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
86075
86076 event->state = PERF_EVENT_STATE_INACTIVE;
86077
86078@@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
86079 if (flags & ~PERF_FLAG_ALL)
86080 return -EINVAL;
86081
86082+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86083+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86084+ return -EACCES;
86085+#endif
86086+
86087 err = perf_copy_attr(attr_uptr, &attr);
86088 if (err)
86089 return err;
86090@@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
86091 /*
86092 * Add back the child's count to the parent's count:
86093 */
86094- atomic64_add(child_val, &parent_event->child_count);
86095- atomic64_add(child_event->total_time_enabled,
86096+ atomic64_add_unchecked(child_val, &parent_event->child_count);
86097+ atomic64_add_unchecked(child_event->total_time_enabled,
86098 &parent_event->child_total_time_enabled);
86099- atomic64_add(child_event->total_time_running,
86100+ atomic64_add_unchecked(child_event->total_time_running,
86101 &parent_event->child_total_time_running);
86102
86103 /*
86104diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86105index 569b2187..19940d9 100644
86106--- a/kernel/events/internal.h
86107+++ b/kernel/events/internal.h
86108@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86109 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86110 }
86111
86112-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86113+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86114 static inline unsigned long \
86115 func_name(struct perf_output_handle *handle, \
86116- const void *buf, unsigned long len) \
86117+ const void user *buf, unsigned long len) \
86118 { \
86119 unsigned long size, written; \
86120 \
86121@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86122 return 0;
86123 }
86124
86125-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86126+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86127
86128 static inline unsigned long
86129 memcpy_skip(void *dst, const void *src, unsigned long n)
86130@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86131 return 0;
86132 }
86133
86134-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86135+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86136
86137 #ifndef arch_perf_out_copy_user
86138 #define arch_perf_out_copy_user arch_perf_out_copy_user
86139@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86140 }
86141 #endif
86142
86143-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86144+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86145
86146 /* Callchain handling */
86147 extern struct perf_callchain_entry *
86148diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86149index 04709b6..d330828 100644
86150--- a/kernel/events/uprobes.c
86151+++ b/kernel/events/uprobes.c
86152@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86153 {
86154 struct page *page;
86155 uprobe_opcode_t opcode;
86156- int result;
86157+ long result;
86158
86159 pagefault_disable();
86160 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86161diff --git a/kernel/exit.c b/kernel/exit.c
86162index 6ed6a1d..edecb0e 100644
86163--- a/kernel/exit.c
86164+++ b/kernel/exit.c
86165@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86166 struct task_struct *leader;
86167 int zap_leader;
86168 repeat:
86169+#ifdef CONFIG_NET
86170+ gr_del_task_from_ip_table(p);
86171+#endif
86172+
86173 /* don't need to get the RCU readlock here - the process is dead and
86174 * can't be modifying its own credentials. But shut RCU-lockdep up */
86175 rcu_read_lock();
86176@@ -330,7 +334,7 @@ int allow_signal(int sig)
86177 * know it'll be handled, so that they don't get converted to
86178 * SIGKILL or just silently dropped.
86179 */
86180- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86181+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86182 recalc_sigpending();
86183 spin_unlock_irq(&current->sighand->siglock);
86184 return 0;
86185@@ -699,6 +703,8 @@ void do_exit(long code)
86186 struct task_struct *tsk = current;
86187 int group_dead;
86188
86189+ set_fs(USER_DS);
86190+
86191 profile_task_exit(tsk);
86192
86193 WARN_ON(blk_needs_flush_plug(tsk));
86194@@ -715,7 +721,6 @@ void do_exit(long code)
86195 * mm_release()->clear_child_tid() from writing to a user-controlled
86196 * kernel address.
86197 */
86198- set_fs(USER_DS);
86199
86200 ptrace_event(PTRACE_EVENT_EXIT, code);
86201
86202@@ -774,6 +779,9 @@ void do_exit(long code)
86203 tsk->exit_code = code;
86204 taskstats_exit(tsk, group_dead);
86205
86206+ gr_acl_handle_psacct(tsk, code);
86207+ gr_acl_handle_exit();
86208+
86209 exit_mm(tsk);
86210
86211 if (group_dead)
86212@@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86213 * Take down every thread in the group. This is called by fatal signals
86214 * as well as by sys_exit_group (below).
86215 */
86216-void
86217+__noreturn void
86218 do_group_exit(int exit_code)
86219 {
86220 struct signal_struct *sig = current->signal;
86221diff --git a/kernel/fork.c b/kernel/fork.c
86222index 1429043..9d95f16 100644
86223--- a/kernel/fork.c
86224+++ b/kernel/fork.c
86225@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86226 # endif
86227 #endif
86228
86229+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86230+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86231+ int node, void **lowmem_stack)
86232+{
86233+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
86234+ void *ret = NULL;
86235+ unsigned int i;
86236+
86237+ *lowmem_stack = alloc_thread_info_node(tsk, node);
86238+ if (*lowmem_stack == NULL)
86239+ goto out;
86240+
86241+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86242+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86243+
86244+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86245+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86246+ if (ret == NULL) {
86247+ free_thread_info(*lowmem_stack);
86248+ *lowmem_stack = NULL;
86249+ }
86250+
86251+out:
86252+ return ret;
86253+}
86254+
86255+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86256+{
86257+ unmap_process_stacks(tsk);
86258+}
86259+#else
86260+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86261+ int node, void **lowmem_stack)
86262+{
86263+ return alloc_thread_info_node(tsk, node);
86264+}
86265+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86266+{
86267+ free_thread_info(ti);
86268+}
86269+#endif
86270+
86271 /* SLAB cache for signal_struct structures (tsk->signal) */
86272 static struct kmem_cache *signal_cachep;
86273
86274@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86275 /* SLAB cache for mm_struct structures (tsk->mm) */
86276 static struct kmem_cache *mm_cachep;
86277
86278-static void account_kernel_stack(struct thread_info *ti, int account)
86279+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86280 {
86281+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86282+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86283+#else
86284 struct zone *zone = page_zone(virt_to_page(ti));
86285+#endif
86286
86287 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86288 }
86289
86290 void free_task(struct task_struct *tsk)
86291 {
86292- account_kernel_stack(tsk->stack, -1);
86293+ account_kernel_stack(tsk, tsk->stack, -1);
86294 arch_release_thread_info(tsk->stack);
86295- free_thread_info(tsk->stack);
86296+ gr_free_thread_info(tsk, tsk->stack);
86297 rt_mutex_debug_task_free(tsk);
86298 ftrace_graph_exit_task(tsk);
86299 put_seccomp_filter(tsk);
86300@@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86301 struct task_struct *tsk;
86302 struct thread_info *ti;
86303 unsigned long *stackend;
86304+ void *lowmem_stack;
86305 int node = tsk_fork_get_node(orig);
86306 int err;
86307
86308@@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86309 if (!tsk)
86310 return NULL;
86311
86312- ti = alloc_thread_info_node(tsk, node);
86313+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86314 if (!ti)
86315 goto free_tsk;
86316
86317@@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86318 goto free_ti;
86319
86320 tsk->stack = ti;
86321+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86322+ tsk->lowmem_stack = lowmem_stack;
86323+#endif
86324
86325 setup_thread_stack(tsk, orig);
86326 clear_user_return_notifier(tsk);
86327@@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86328 *stackend = STACK_END_MAGIC; /* for overflow detection */
86329
86330 #ifdef CONFIG_CC_STACKPROTECTOR
86331- tsk->stack_canary = get_random_int();
86332+ tsk->stack_canary = pax_get_random_long();
86333 #endif
86334
86335 /*
86336@@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86337 tsk->splice_pipe = NULL;
86338 tsk->task_frag.page = NULL;
86339
86340- account_kernel_stack(ti, 1);
86341+ account_kernel_stack(tsk, ti, 1);
86342
86343 return tsk;
86344
86345 free_ti:
86346- free_thread_info(ti);
86347+ gr_free_thread_info(tsk, ti);
86348 free_tsk:
86349 free_task_struct(tsk);
86350 return NULL;
86351 }
86352
86353 #ifdef CONFIG_MMU
86354-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86355+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86356+{
86357+ struct vm_area_struct *tmp;
86358+ unsigned long charge;
86359+ struct file *file;
86360+ int retval;
86361+
86362+ charge = 0;
86363+ if (mpnt->vm_flags & VM_ACCOUNT) {
86364+ unsigned long len = vma_pages(mpnt);
86365+
86366+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86367+ goto fail_nomem;
86368+ charge = len;
86369+ }
86370+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86371+ if (!tmp)
86372+ goto fail_nomem;
86373+ *tmp = *mpnt;
86374+ tmp->vm_mm = mm;
86375+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86376+ retval = vma_dup_policy(mpnt, tmp);
86377+ if (retval)
86378+ goto fail_nomem_policy;
86379+ if (anon_vma_fork(tmp, mpnt))
86380+ goto fail_nomem_anon_vma_fork;
86381+ tmp->vm_flags &= ~VM_LOCKED;
86382+ tmp->vm_next = tmp->vm_prev = NULL;
86383+ tmp->vm_mirror = NULL;
86384+ file = tmp->vm_file;
86385+ if (file) {
86386+ struct inode *inode = file_inode(file);
86387+ struct address_space *mapping = file->f_mapping;
86388+
86389+ get_file(file);
86390+ if (tmp->vm_flags & VM_DENYWRITE)
86391+ atomic_dec(&inode->i_writecount);
86392+ mutex_lock(&mapping->i_mmap_mutex);
86393+ if (tmp->vm_flags & VM_SHARED)
86394+ mapping->i_mmap_writable++;
86395+ flush_dcache_mmap_lock(mapping);
86396+ /* insert tmp into the share list, just after mpnt */
86397+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86398+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86399+ else
86400+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86401+ flush_dcache_mmap_unlock(mapping);
86402+ mutex_unlock(&mapping->i_mmap_mutex);
86403+ }
86404+
86405+ /*
86406+ * Clear hugetlb-related page reserves for children. This only
86407+ * affects MAP_PRIVATE mappings. Faults generated by the child
86408+ * are not guaranteed to succeed, even if read-only
86409+ */
86410+ if (is_vm_hugetlb_page(tmp))
86411+ reset_vma_resv_huge_pages(tmp);
86412+
86413+ return tmp;
86414+
86415+fail_nomem_anon_vma_fork:
86416+ mpol_put(vma_policy(tmp));
86417+fail_nomem_policy:
86418+ kmem_cache_free(vm_area_cachep, tmp);
86419+fail_nomem:
86420+ vm_unacct_memory(charge);
86421+ return NULL;
86422+}
86423+
86424+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86425 {
86426 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86427 struct rb_node **rb_link, *rb_parent;
86428 int retval;
86429- unsigned long charge;
86430
86431 uprobe_start_dup_mmap();
86432 down_write(&oldmm->mmap_sem);
86433@@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86434
86435 prev = NULL;
86436 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86437- struct file *file;
86438-
86439 if (mpnt->vm_flags & VM_DONTCOPY) {
86440 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86441 -vma_pages(mpnt));
86442 continue;
86443 }
86444- charge = 0;
86445- if (mpnt->vm_flags & VM_ACCOUNT) {
86446- unsigned long len = vma_pages(mpnt);
86447-
86448- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86449- goto fail_nomem;
86450- charge = len;
86451- }
86452- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86453- if (!tmp)
86454- goto fail_nomem;
86455- *tmp = *mpnt;
86456- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86457- retval = vma_dup_policy(mpnt, tmp);
86458- if (retval)
86459- goto fail_nomem_policy;
86460- tmp->vm_mm = mm;
86461- if (anon_vma_fork(tmp, mpnt))
86462- goto fail_nomem_anon_vma_fork;
86463- tmp->vm_flags &= ~VM_LOCKED;
86464- tmp->vm_next = tmp->vm_prev = NULL;
86465- file = tmp->vm_file;
86466- if (file) {
86467- struct inode *inode = file_inode(file);
86468- struct address_space *mapping = file->f_mapping;
86469-
86470- get_file(file);
86471- if (tmp->vm_flags & VM_DENYWRITE)
86472- atomic_dec(&inode->i_writecount);
86473- mutex_lock(&mapping->i_mmap_mutex);
86474- if (tmp->vm_flags & VM_SHARED)
86475- mapping->i_mmap_writable++;
86476- flush_dcache_mmap_lock(mapping);
86477- /* insert tmp into the share list, just after mpnt */
86478- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86479- vma_nonlinear_insert(tmp,
86480- &mapping->i_mmap_nonlinear);
86481- else
86482- vma_interval_tree_insert_after(tmp, mpnt,
86483- &mapping->i_mmap);
86484- flush_dcache_mmap_unlock(mapping);
86485- mutex_unlock(&mapping->i_mmap_mutex);
86486+ tmp = dup_vma(mm, oldmm, mpnt);
86487+ if (!tmp) {
86488+ retval = -ENOMEM;
86489+ goto out;
86490 }
86491
86492 /*
86493@@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86494 if (retval)
86495 goto out;
86496 }
86497+
86498+#ifdef CONFIG_PAX_SEGMEXEC
86499+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86500+ struct vm_area_struct *mpnt_m;
86501+
86502+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86503+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86504+
86505+ if (!mpnt->vm_mirror)
86506+ continue;
86507+
86508+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86509+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86510+ mpnt->vm_mirror = mpnt_m;
86511+ } else {
86512+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86513+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86514+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86515+ mpnt->vm_mirror->vm_mirror = mpnt;
86516+ }
86517+ }
86518+ BUG_ON(mpnt_m);
86519+ }
86520+#endif
86521+
86522 /* a new mm has just been created */
86523 arch_dup_mmap(oldmm, mm);
86524 retval = 0;
86525@@ -472,14 +575,6 @@ out:
86526 up_write(&oldmm->mmap_sem);
86527 uprobe_end_dup_mmap();
86528 return retval;
86529-fail_nomem_anon_vma_fork:
86530- mpol_put(vma_policy(tmp));
86531-fail_nomem_policy:
86532- kmem_cache_free(vm_area_cachep, tmp);
86533-fail_nomem:
86534- retval = -ENOMEM;
86535- vm_unacct_memory(charge);
86536- goto out;
86537 }
86538
86539 static inline int mm_alloc_pgd(struct mm_struct *mm)
86540@@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86541 return ERR_PTR(err);
86542
86543 mm = get_task_mm(task);
86544- if (mm && mm != current->mm &&
86545- !ptrace_may_access(task, mode)) {
86546+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86547+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86548 mmput(mm);
86549 mm = ERR_PTR(-EACCES);
86550 }
86551@@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86552 spin_unlock(&fs->lock);
86553 return -EAGAIN;
86554 }
86555- fs->users++;
86556+ atomic_inc(&fs->users);
86557 spin_unlock(&fs->lock);
86558 return 0;
86559 }
86560 tsk->fs = copy_fs_struct(fs);
86561 if (!tsk->fs)
86562 return -ENOMEM;
86563+ /* Carry through gr_chroot_dentry and is_chrooted instead
86564+ of recomputing it here. Already copied when the task struct
86565+ is duplicated. This allows pivot_root to not be treated as
86566+ a chroot
86567+ */
86568+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86569+
86570 return 0;
86571 }
86572
86573@@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86574 * parts of the process environment (as per the clone
86575 * flags). The actual kick-off is left to the caller.
86576 */
86577-static struct task_struct *copy_process(unsigned long clone_flags,
86578+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86579 unsigned long stack_start,
86580 unsigned long stack_size,
86581 int __user *child_tidptr,
86582@@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86583 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86584 #endif
86585 retval = -EAGAIN;
86586+
86587+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86588+
86589 if (atomic_read(&p->real_cred->user->processes) >=
86590 task_rlimit(p, RLIMIT_NPROC)) {
86591 if (p->real_cred->user != INIT_USER &&
86592@@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86593 goto bad_fork_free_pid;
86594 }
86595
86596+ /* synchronizes with gr_set_acls()
86597+ we need to call this past the point of no return for fork()
86598+ */
86599+ gr_copy_label(p);
86600+
86601 if (likely(p->pid)) {
86602 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86603
86604@@ -1539,6 +1649,8 @@ bad_fork_cleanup_count:
86605 bad_fork_free:
86606 free_task(p);
86607 fork_out:
86608+ gr_log_forkfail(retval);
86609+
86610 return ERR_PTR(retval);
86611 }
86612
86613@@ -1600,6 +1712,7 @@ long do_fork(unsigned long clone_flags,
86614
86615 p = copy_process(clone_flags, stack_start, stack_size,
86616 child_tidptr, NULL, trace);
86617+ add_latent_entropy();
86618 /*
86619 * Do this prior waking up the new thread - the thread pointer
86620 * might get invalid after that point, if the thread exits quickly.
86621@@ -1616,6 +1729,8 @@ long do_fork(unsigned long clone_flags,
86622 if (clone_flags & CLONE_PARENT_SETTID)
86623 put_user(nr, parent_tidptr);
86624
86625+ gr_handle_brute_check();
86626+
86627 if (clone_flags & CLONE_VFORK) {
86628 p->vfork_done = &vfork;
86629 init_completion(&vfork);
86630@@ -1734,7 +1849,7 @@ void __init proc_caches_init(void)
86631 mm_cachep = kmem_cache_create("mm_struct",
86632 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86633 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86634- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86635+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86636 mmap_init();
86637 nsproxy_cache_init();
86638 }
86639@@ -1774,7 +1889,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86640 return 0;
86641
86642 /* don't need lock here; in the worst case we'll do useless copy */
86643- if (fs->users == 1)
86644+ if (atomic_read(&fs->users) == 1)
86645 return 0;
86646
86647 *new_fsp = copy_fs_struct(fs);
86648@@ -1881,7 +1996,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86649 fs = current->fs;
86650 spin_lock(&fs->lock);
86651 current->fs = new_fs;
86652- if (--fs->users)
86653+ gr_set_chroot_entries(current, &current->fs->root);
86654+ if (atomic_dec_return(&fs->users))
86655 new_fs = NULL;
86656 else
86657 new_fs = fs;
86658diff --git a/kernel/futex.c b/kernel/futex.c
86659index de938d2..c566038 100644
86660--- a/kernel/futex.c
86661+++ b/kernel/futex.c
86662@@ -202,7 +202,7 @@ struct futex_pi_state {
86663 atomic_t refcount;
86664
86665 union futex_key key;
86666-};
86667+} __randomize_layout;
86668
86669 /**
86670 * struct futex_q - The hashed futex queue entry, one per waiting task
86671@@ -236,7 +236,7 @@ struct futex_q {
86672 struct rt_mutex_waiter *rt_waiter;
86673 union futex_key *requeue_pi_key;
86674 u32 bitset;
86675-};
86676+} __randomize_layout;
86677
86678 static const struct futex_q futex_q_init = {
86679 /* list gets initialized in queue_me()*/
86680@@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86681 struct page *page, *page_head;
86682 int err, ro = 0;
86683
86684+#ifdef CONFIG_PAX_SEGMEXEC
86685+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86686+ return -EFAULT;
86687+#endif
86688+
86689 /*
86690 * The futex address must be "naturally" aligned.
86691 */
86692@@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86693
86694 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86695 {
86696- int ret;
86697+ unsigned long ret;
86698
86699 pagefault_disable();
86700 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86701@@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
86702 {
86703 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86704 u32 curval;
86705+ mm_segment_t oldfs;
86706
86707 /*
86708 * This will fail and we want it. Some arch implementations do
86709@@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
86710 * implementation, the non-functional ones will return
86711 * -ENOSYS.
86712 */
86713+ oldfs = get_fs();
86714+ set_fs(USER_DS);
86715 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86716 futex_cmpxchg_enabled = 1;
86717+ set_fs(oldfs);
86718 #endif
86719 }
86720
86721diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86722index 55c8c93..9ba7ad6 100644
86723--- a/kernel/futex_compat.c
86724+++ b/kernel/futex_compat.c
86725@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86726 return 0;
86727 }
86728
86729-static void __user *futex_uaddr(struct robust_list __user *entry,
86730+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86731 compat_long_t futex_offset)
86732 {
86733 compat_uptr_t base = ptr_to_compat(entry);
86734diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86735index f45b75b..bfac6d5 100644
86736--- a/kernel/gcov/base.c
86737+++ b/kernel/gcov/base.c
86738@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86739 }
86740
86741 #ifdef CONFIG_MODULES
86742-static inline int within(void *addr, void *start, unsigned long size)
86743-{
86744- return ((addr >= start) && (addr < start + size));
86745-}
86746-
86747 /* Update list and generate events when modules are unloaded. */
86748 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86749 void *data)
86750@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86751
86752 /* Remove entries located in module from linked list. */
86753 while ((info = gcov_info_next(info))) {
86754- if (within(info, mod->module_core, mod->core_size)) {
86755+ if (within_module_core_rw((unsigned long)info, mod)) {
86756 gcov_info_unlink(prev, info);
86757 if (gcov_events_enabled)
86758 gcov_event(GCOV_REMOVE, info);
86759diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86760index e0501fe..312edd6 100644
86761--- a/kernel/hrtimer.c
86762+++ b/kernel/hrtimer.c
86763@@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
86764 local_irq_restore(flags);
86765 }
86766
86767-static void run_hrtimer_softirq(struct softirq_action *h)
86768+static __latent_entropy void run_hrtimer_softirq(void)
86769 {
86770 hrtimer_peek_ahead_timers();
86771 }
86772diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86773index a82170e..5b01e7f 100644
86774--- a/kernel/irq_work.c
86775+++ b/kernel/irq_work.c
86776@@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86777 return NOTIFY_OK;
86778 }
86779
86780-static struct notifier_block cpu_notify;
86781+static struct notifier_block cpu_notify = {
86782+ .notifier_call = irq_work_cpu_notify,
86783+ .priority = 0,
86784+};
86785
86786 static __init int irq_work_init_cpu_notifier(void)
86787 {
86788- cpu_notify.notifier_call = irq_work_cpu_notify;
86789- cpu_notify.priority = 0;
86790 register_cpu_notifier(&cpu_notify);
86791 return 0;
86792 }
86793diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86794index 9019f15..9a3c42e 100644
86795--- a/kernel/jump_label.c
86796+++ b/kernel/jump_label.c
86797@@ -14,6 +14,7 @@
86798 #include <linux/err.h>
86799 #include <linux/static_key.h>
86800 #include <linux/jump_label_ratelimit.h>
86801+#include <linux/mm.h>
86802
86803 #ifdef HAVE_JUMP_LABEL
86804
86805@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86806
86807 size = (((unsigned long)stop - (unsigned long)start)
86808 / sizeof(struct jump_entry));
86809+ pax_open_kernel();
86810 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86811+ pax_close_kernel();
86812 }
86813
86814 static void jump_label_update(struct static_key *key, int enable);
86815@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86816 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86817 struct jump_entry *iter;
86818
86819+ pax_open_kernel();
86820 for (iter = iter_start; iter < iter_stop; iter++) {
86821 if (within_module_init(iter->code, mod))
86822 iter->code = 0;
86823 }
86824+ pax_close_kernel();
86825 }
86826
86827 static int
86828diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86829index cb0cf37..b69e161 100644
86830--- a/kernel/kallsyms.c
86831+++ b/kernel/kallsyms.c
86832@@ -11,6 +11,9 @@
86833 * Changed the compression method from stem compression to "table lookup"
86834 * compression (see scripts/kallsyms.c for a more complete description)
86835 */
86836+#ifdef CONFIG_GRKERNSEC_HIDESYM
86837+#define __INCLUDED_BY_HIDESYM 1
86838+#endif
86839 #include <linux/kallsyms.h>
86840 #include <linux/module.h>
86841 #include <linux/init.h>
86842@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
86843
86844 static inline int is_kernel_inittext(unsigned long addr)
86845 {
86846+ if (system_state != SYSTEM_BOOTING)
86847+ return 0;
86848+
86849 if (addr >= (unsigned long)_sinittext
86850 && addr <= (unsigned long)_einittext)
86851 return 1;
86852 return 0;
86853 }
86854
86855+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86856+#ifdef CONFIG_MODULES
86857+static inline int is_module_text(unsigned long addr)
86858+{
86859+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86860+ return 1;
86861+
86862+ addr = ktla_ktva(addr);
86863+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86864+}
86865+#else
86866+static inline int is_module_text(unsigned long addr)
86867+{
86868+ return 0;
86869+}
86870+#endif
86871+#endif
86872+
86873 static inline int is_kernel_text(unsigned long addr)
86874 {
86875 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86876@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
86877
86878 static inline int is_kernel(unsigned long addr)
86879 {
86880+
86881+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86882+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86883+ return 1;
86884+
86885+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86886+#else
86887 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86888+#endif
86889+
86890 return 1;
86891 return in_gate_area_no_mm(addr);
86892 }
86893
86894 static int is_ksym_addr(unsigned long addr)
86895 {
86896+
86897+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86898+ if (is_module_text(addr))
86899+ return 0;
86900+#endif
86901+
86902 if (all_var)
86903 return is_kernel(addr);
86904
86905@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86906
86907 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86908 {
86909- iter->name[0] = '\0';
86910 iter->nameoff = get_symbol_offset(new_pos);
86911 iter->pos = new_pos;
86912 }
86913@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
86914 {
86915 struct kallsym_iter *iter = m->private;
86916
86917+#ifdef CONFIG_GRKERNSEC_HIDESYM
86918+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86919+ return 0;
86920+#endif
86921+
86922 /* Some debugging symbols have no name. Ignore them. */
86923 if (!iter->name[0])
86924 return 0;
86925@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
86926 */
86927 type = iter->exported ? toupper(iter->type) :
86928 tolower(iter->type);
86929+
86930 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86931 type, iter->name, iter->module_name);
86932 } else
86933@@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86934 struct kallsym_iter *iter;
86935 int ret;
86936
86937- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86938+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86939 if (!iter)
86940 return -ENOMEM;
86941 reset_iter(iter, 0);
86942diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86943index e30ac0f..3528cac 100644
86944--- a/kernel/kcmp.c
86945+++ b/kernel/kcmp.c
86946@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86947 struct task_struct *task1, *task2;
86948 int ret;
86949
86950+#ifdef CONFIG_GRKERNSEC
86951+ return -ENOSYS;
86952+#endif
86953+
86954 rcu_read_lock();
86955
86956 /*
86957diff --git a/kernel/kexec.c b/kernel/kexec.c
86958index 28c5706..bfc8388 100644
86959--- a/kernel/kexec.c
86960+++ b/kernel/kexec.c
86961@@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
86962 compat_ulong_t, flags)
86963 {
86964 struct compat_kexec_segment in;
86965- struct kexec_segment out, __user *ksegments;
86966+ struct kexec_segment out;
86967+ struct kexec_segment __user *ksegments;
86968 unsigned long i, result;
86969
86970 /* Don't allow clients that don't understand the native
86971diff --git a/kernel/kmod.c b/kernel/kmod.c
86972index 6b375af..eaff670 100644
86973--- a/kernel/kmod.c
86974+++ b/kernel/kmod.c
86975@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86976 kfree(info->argv);
86977 }
86978
86979-static int call_modprobe(char *module_name, int wait)
86980+static int call_modprobe(char *module_name, char *module_param, int wait)
86981 {
86982 struct subprocess_info *info;
86983 static char *envp[] = {
86984@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86985 NULL
86986 };
86987
86988- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86989+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86990 if (!argv)
86991 goto out;
86992
86993@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86994 argv[1] = "-q";
86995 argv[2] = "--";
86996 argv[3] = module_name; /* check free_modprobe_argv() */
86997- argv[4] = NULL;
86998+ argv[4] = module_param;
86999+ argv[5] = NULL;
87000
87001 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87002 NULL, free_modprobe_argv, NULL);
87003@@ -129,9 +130,8 @@ out:
87004 * If module auto-loading support is disabled then this function
87005 * becomes a no-operation.
87006 */
87007-int __request_module(bool wait, const char *fmt, ...)
87008+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87009 {
87010- va_list args;
87011 char module_name[MODULE_NAME_LEN];
87012 unsigned int max_modprobes;
87013 int ret;
87014@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87015 if (!modprobe_path[0])
87016 return 0;
87017
87018- va_start(args, fmt);
87019- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87020- va_end(args);
87021+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87022 if (ret >= MODULE_NAME_LEN)
87023 return -ENAMETOOLONG;
87024
87025@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87026 if (ret)
87027 return ret;
87028
87029+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87030+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87031+ /* hack to workaround consolekit/udisks stupidity */
87032+ read_lock(&tasklist_lock);
87033+ if (!strcmp(current->comm, "mount") &&
87034+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87035+ read_unlock(&tasklist_lock);
87036+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87037+ return -EPERM;
87038+ }
87039+ read_unlock(&tasklist_lock);
87040+ }
87041+#endif
87042+
87043 /* If modprobe needs a service that is in a module, we get a recursive
87044 * loop. Limit the number of running kmod threads to max_threads/2 or
87045 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87046@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87047
87048 trace_module_request(module_name, wait, _RET_IP_);
87049
87050- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87051+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87052
87053 atomic_dec(&kmod_concurrent);
87054 return ret;
87055 }
87056+
87057+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87058+{
87059+ va_list args;
87060+ int ret;
87061+
87062+ va_start(args, fmt);
87063+ ret = ____request_module(wait, module_param, fmt, args);
87064+ va_end(args);
87065+
87066+ return ret;
87067+}
87068+
87069+int __request_module(bool wait, const char *fmt, ...)
87070+{
87071+ va_list args;
87072+ int ret;
87073+
87074+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87075+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87076+ char module_param[MODULE_NAME_LEN];
87077+
87078+ memset(module_param, 0, sizeof(module_param));
87079+
87080+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87081+
87082+ va_start(args, fmt);
87083+ ret = ____request_module(wait, module_param, fmt, args);
87084+ va_end(args);
87085+
87086+ return ret;
87087+ }
87088+#endif
87089+
87090+ va_start(args, fmt);
87091+ ret = ____request_module(wait, NULL, fmt, args);
87092+ va_end(args);
87093+
87094+ return ret;
87095+}
87096+
87097 EXPORT_SYMBOL(__request_module);
87098 #endif /* CONFIG_MODULES */
87099
87100@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87101 */
87102 set_user_nice(current, 0);
87103
87104+#ifdef CONFIG_GRKERNSEC
87105+ /* this is race-free as far as userland is concerned as we copied
87106+ out the path to be used prior to this point and are now operating
87107+ on that copy
87108+ */
87109+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87110+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87111+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87112+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87113+ retval = -EPERM;
87114+ goto fail;
87115+ }
87116+#endif
87117+
87118 retval = -ENOMEM;
87119 new = prepare_kernel_cred(current);
87120 if (!new)
87121@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87122 commit_creds(new);
87123
87124 retval = do_execve(getname_kernel(sub_info->path),
87125- (const char __user *const __user *)sub_info->argv,
87126- (const char __user *const __user *)sub_info->envp);
87127+ (const char __user *const __force_user *)sub_info->argv,
87128+ (const char __user *const __force_user *)sub_info->envp);
87129 if (!retval)
87130 return 0;
87131
87132@@ -260,6 +327,10 @@ static int call_helper(void *data)
87133
87134 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87135 {
87136+#ifdef CONFIG_GRKERNSEC
87137+ kfree(info->path);
87138+ info->path = info->origpath;
87139+#endif
87140 if (info->cleanup)
87141 (*info->cleanup)(info);
87142 kfree(info);
87143@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87144 *
87145 * Thus the __user pointer cast is valid here.
87146 */
87147- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87148+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87149
87150 /*
87151 * If ret is 0, either ____call_usermodehelper failed and the
87152@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87153 goto out;
87154
87155 INIT_WORK(&sub_info->work, __call_usermodehelper);
87156+#ifdef CONFIG_GRKERNSEC
87157+ sub_info->origpath = path;
87158+ sub_info->path = kstrdup(path, gfp_mask);
87159+#else
87160 sub_info->path = path;
87161+#endif
87162 sub_info->argv = argv;
87163 sub_info->envp = envp;
87164
87165@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87166 static int proc_cap_handler(struct ctl_table *table, int write,
87167 void __user *buffer, size_t *lenp, loff_t *ppos)
87168 {
87169- struct ctl_table t;
87170+ ctl_table_no_const t;
87171 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87172 kernel_cap_t new_cap;
87173 int err, i;
87174diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87175index ceeadfc..11c18b6 100644
87176--- a/kernel/kprobes.c
87177+++ b/kernel/kprobes.c
87178@@ -31,6 +31,9 @@
87179 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87180 * <prasanna@in.ibm.com> added function-return probes.
87181 */
87182+#ifdef CONFIG_GRKERNSEC_HIDESYM
87183+#define __INCLUDED_BY_HIDESYM 1
87184+#endif
87185 #include <linux/kprobes.h>
87186 #include <linux/hash.h>
87187 #include <linux/init.h>
87188@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87189
87190 static void *alloc_insn_page(void)
87191 {
87192- return module_alloc(PAGE_SIZE);
87193+ return module_alloc_exec(PAGE_SIZE);
87194 }
87195
87196 static void free_insn_page(void *page)
87197 {
87198- module_free(NULL, page);
87199+ module_free_exec(NULL, page);
87200 }
87201
87202 struct kprobe_insn_cache kprobe_insn_slots = {
87203@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87204 kprobe_type = "k";
87205
87206 if (sym)
87207- seq_printf(pi, "%p %s %s+0x%x %s ",
87208+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87209 p->addr, kprobe_type, sym, offset,
87210 (modname ? modname : " "));
87211 else
87212- seq_printf(pi, "%p %s %p ",
87213+ seq_printf(pi, "%pK %s %pK ",
87214 p->addr, kprobe_type, p->addr);
87215
87216 if (!pp)
87217diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87218index 2495a9b..071b906 100644
87219--- a/kernel/ksysfs.c
87220+++ b/kernel/ksysfs.c
87221@@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87222 {
87223 if (count+1 > UEVENT_HELPER_PATH_LEN)
87224 return -ENOENT;
87225+ if (!capable(CAP_SYS_ADMIN))
87226+ return -EPERM;
87227 memcpy(uevent_helper, buf, count);
87228 uevent_helper[count] = '\0';
87229 if (count && uevent_helper[count-1] == '\n')
87230@@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87231 return count;
87232 }
87233
87234-static struct bin_attribute notes_attr = {
87235+static bin_attribute_no_const notes_attr __read_only = {
87236 .attr = {
87237 .name = "notes",
87238 .mode = S_IRUGO,
87239diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87240index d24e433..fa04fb8 100644
87241--- a/kernel/locking/lockdep.c
87242+++ b/kernel/locking/lockdep.c
87243@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87244 end = (unsigned long) &_end,
87245 addr = (unsigned long) obj;
87246
87247+#ifdef CONFIG_PAX_KERNEXEC
87248+ start = ktla_ktva(start);
87249+#endif
87250+
87251 /*
87252 * static variable?
87253 */
87254@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87255 if (!static_obj(lock->key)) {
87256 debug_locks_off();
87257 printk("INFO: trying to register non-static key.\n");
87258+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87259 printk("the code is fine but needs lockdep annotation.\n");
87260 printk("turning off the locking correctness validator.\n");
87261 dump_stack();
87262@@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87263 if (!class)
87264 return 0;
87265 }
87266- atomic_inc((atomic_t *)&class->ops);
87267+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87268 if (very_verbose(class)) {
87269 printk("\nacquire class [%p] %s", class->key, class->name);
87270 if (class->name_version > 1)
87271diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87272index ef43ac4..2720dfa 100644
87273--- a/kernel/locking/lockdep_proc.c
87274+++ b/kernel/locking/lockdep_proc.c
87275@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87276 return 0;
87277 }
87278
87279- seq_printf(m, "%p", class->key);
87280+ seq_printf(m, "%pK", class->key);
87281 #ifdef CONFIG_DEBUG_LOCKDEP
87282 seq_printf(m, " OPS:%8ld", class->ops);
87283 #endif
87284@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87285
87286 list_for_each_entry(entry, &class->locks_after, entry) {
87287 if (entry->distance == 1) {
87288- seq_printf(m, " -> [%p] ", entry->class->key);
87289+ seq_printf(m, " -> [%pK] ", entry->class->key);
87290 print_name(m, entry->class);
87291 seq_puts(m, "\n");
87292 }
87293@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87294 if (!class->key)
87295 continue;
87296
87297- seq_printf(m, "[%p] ", class->key);
87298+ seq_printf(m, "[%pK] ", class->key);
87299 print_name(m, class);
87300 seq_puts(m, "\n");
87301 }
87302@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87303 if (!i)
87304 seq_line(m, '-', 40-namelen, namelen);
87305
87306- snprintf(ip, sizeof(ip), "[<%p>]",
87307+ snprintf(ip, sizeof(ip), "[<%pK>]",
87308 (void *)class->contention_point[i]);
87309 seq_printf(m, "%40s %14lu %29s %pS\n",
87310 name, stats->contention_point[i],
87311@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87312 if (!i)
87313 seq_line(m, '-', 40-namelen, namelen);
87314
87315- snprintf(ip, sizeof(ip), "[<%p>]",
87316+ snprintf(ip, sizeof(ip), "[<%pK>]",
87317 (void *)class->contending_point[i]);
87318 seq_printf(m, "%40s %14lu %29s %pS\n",
87319 name, stats->contending_point[i],
87320diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87321index 838dc9e..760e158 100644
87322--- a/kernel/locking/mcs_spinlock.c
87323+++ b/kernel/locking/mcs_spinlock.c
87324@@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87325 if (likely(prev == NULL))
87326 return true;
87327
87328- ACCESS_ONCE(prev->next) = node;
87329+ ACCESS_ONCE_RW(prev->next) = node;
87330
87331 /*
87332 * Normally @prev is untouchable after the above store; because at that
87333@@ -143,8 +143,8 @@ unqueue:
87334 * it will wait in Step-A.
87335 */
87336
87337- ACCESS_ONCE(next->prev) = prev;
87338- ACCESS_ONCE(prev->next) = next;
87339+ ACCESS_ONCE_RW(next->prev) = prev;
87340+ ACCESS_ONCE_RW(prev->next) = next;
87341
87342 return false;
87343 }
87344@@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
87345 */
87346 next = xchg(&node->next, NULL);
87347 if (next) {
87348- ACCESS_ONCE(next->locked) = 1;
87349+ ACCESS_ONCE_RW(next->locked) = 1;
87350 return;
87351 }
87352
87353 next = osq_wait_next(lock, node, NULL);
87354 if (next)
87355- ACCESS_ONCE(next->locked) = 1;
87356+ ACCESS_ONCE_RW(next->locked) = 1;
87357 }
87358
87359 #endif
87360diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
87361index a2dbac4..e02a34a 100644
87362--- a/kernel/locking/mcs_spinlock.h
87363+++ b/kernel/locking/mcs_spinlock.h
87364@@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
87365 */
87366 return;
87367 }
87368- ACCESS_ONCE(prev->next) = node;
87369+ ACCESS_ONCE_RW(prev->next) = node;
87370
87371 /* Wait until the lock holder passes the lock down. */
87372 arch_mcs_spin_lock_contended(&node->locked);
87373diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87374index 5cf6731..ce3bc5a 100644
87375--- a/kernel/locking/mutex-debug.c
87376+++ b/kernel/locking/mutex-debug.c
87377@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87378 }
87379
87380 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87381- struct thread_info *ti)
87382+ struct task_struct *task)
87383 {
87384 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87385
87386 /* Mark the current thread as blocked on the lock: */
87387- ti->task->blocked_on = waiter;
87388+ task->blocked_on = waiter;
87389 }
87390
87391 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87392- struct thread_info *ti)
87393+ struct task_struct *task)
87394 {
87395 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87396- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87397- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87398- ti->task->blocked_on = NULL;
87399+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87400+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87401+ task->blocked_on = NULL;
87402
87403 list_del_init(&waiter->list);
87404 waiter->task = NULL;
87405diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87406index 0799fd3..d06ae3b 100644
87407--- a/kernel/locking/mutex-debug.h
87408+++ b/kernel/locking/mutex-debug.h
87409@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87410 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87411 extern void debug_mutex_add_waiter(struct mutex *lock,
87412 struct mutex_waiter *waiter,
87413- struct thread_info *ti);
87414+ struct task_struct *task);
87415 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87416- struct thread_info *ti);
87417+ struct task_struct *task);
87418 extern void debug_mutex_unlock(struct mutex *lock);
87419 extern void debug_mutex_init(struct mutex *lock, const char *name,
87420 struct lock_class_key *key);
87421diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87422index bc73d33..6f308aa 100644
87423--- a/kernel/locking/mutex.c
87424+++ b/kernel/locking/mutex.c
87425@@ -490,7 +490,7 @@ slowpath:
87426 goto skip_wait;
87427
87428 debug_mutex_lock_common(lock, &waiter);
87429- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87430+ debug_mutex_add_waiter(lock, &waiter, task);
87431
87432 /* add waiting tasks to the end of the waitqueue (FIFO): */
87433 list_add_tail(&waiter.list, &lock->wait_list);
87434@@ -534,7 +534,7 @@ slowpath:
87435 schedule_preempt_disabled();
87436 spin_lock_mutex(&lock->wait_lock, flags);
87437 }
87438- mutex_remove_waiter(lock, &waiter, current_thread_info());
87439+ mutex_remove_waiter(lock, &waiter, task);
87440 /* set it to 0 if there are no waiters left: */
87441 if (likely(list_empty(&lock->wait_list)))
87442 atomic_set(&lock->count, 0);
87443@@ -571,7 +571,7 @@ skip_wait:
87444 return 0;
87445
87446 err:
87447- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87448+ mutex_remove_waiter(lock, &waiter, task);
87449 spin_unlock_mutex(&lock->wait_lock, flags);
87450 debug_mutex_free_waiter(&waiter);
87451 mutex_release(&lock->dep_map, 1, ip);
87452diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87453index 1d96dd0..994ff19 100644
87454--- a/kernel/locking/rtmutex-tester.c
87455+++ b/kernel/locking/rtmutex-tester.c
87456@@ -22,7 +22,7 @@
87457 #define MAX_RT_TEST_MUTEXES 8
87458
87459 static spinlock_t rttest_lock;
87460-static atomic_t rttest_event;
87461+static atomic_unchecked_t rttest_event;
87462
87463 struct test_thread_data {
87464 int opcode;
87465@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87466
87467 case RTTEST_LOCKCONT:
87468 td->mutexes[td->opdata] = 1;
87469- td->event = atomic_add_return(1, &rttest_event);
87470+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87471 return 0;
87472
87473 case RTTEST_RESET:
87474@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87475 return 0;
87476
87477 case RTTEST_RESETEVENT:
87478- atomic_set(&rttest_event, 0);
87479+ atomic_set_unchecked(&rttest_event, 0);
87480 return 0;
87481
87482 default:
87483@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87484 return ret;
87485
87486 td->mutexes[id] = 1;
87487- td->event = atomic_add_return(1, &rttest_event);
87488+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87489 rt_mutex_lock(&mutexes[id]);
87490- td->event = atomic_add_return(1, &rttest_event);
87491+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87492 td->mutexes[id] = 4;
87493 return 0;
87494
87495@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87496 return ret;
87497
87498 td->mutexes[id] = 1;
87499- td->event = atomic_add_return(1, &rttest_event);
87500+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87501 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87502- td->event = atomic_add_return(1, &rttest_event);
87503+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87504 td->mutexes[id] = ret ? 0 : 4;
87505 return ret ? -EINTR : 0;
87506
87507@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87508 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87509 return ret;
87510
87511- td->event = atomic_add_return(1, &rttest_event);
87512+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87513 rt_mutex_unlock(&mutexes[id]);
87514- td->event = atomic_add_return(1, &rttest_event);
87515+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87516 td->mutexes[id] = 0;
87517 return 0;
87518
87519@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87520 break;
87521
87522 td->mutexes[dat] = 2;
87523- td->event = atomic_add_return(1, &rttest_event);
87524+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87525 break;
87526
87527 default:
87528@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87529 return;
87530
87531 td->mutexes[dat] = 3;
87532- td->event = atomic_add_return(1, &rttest_event);
87533+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87534 break;
87535
87536 case RTTEST_LOCKNOWAIT:
87537@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87538 return;
87539
87540 td->mutexes[dat] = 1;
87541- td->event = atomic_add_return(1, &rttest_event);
87542+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87543 return;
87544
87545 default:
87546diff --git a/kernel/module.c b/kernel/module.c
87547index 079c461..741f79c 100644
87548--- a/kernel/module.c
87549+++ b/kernel/module.c
87550@@ -61,6 +61,7 @@
87551 #include <linux/pfn.h>
87552 #include <linux/bsearch.h>
87553 #include <linux/fips.h>
87554+#include <linux/grsecurity.h>
87555 #include <uapi/linux/module.h>
87556 #include "module-internal.h"
87557
87558@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87559
87560 /* Bounds of module allocation, for speeding __module_address.
87561 * Protected by module_mutex. */
87562-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87563+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87564+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87565
87566 int register_module_notifier(struct notifier_block * nb)
87567 {
87568@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87569 return true;
87570
87571 list_for_each_entry_rcu(mod, &modules, list) {
87572- struct symsearch arr[] = {
87573+ struct symsearch modarr[] = {
87574 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87575 NOT_GPL_ONLY, false },
87576 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87577@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87578 if (mod->state == MODULE_STATE_UNFORMED)
87579 continue;
87580
87581- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87582+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87583 return true;
87584 }
87585 return false;
87586@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87587 if (!pcpusec->sh_size)
87588 return 0;
87589
87590- if (align > PAGE_SIZE) {
87591+ if (align-1 >= PAGE_SIZE) {
87592 pr_warn("%s: per-cpu alignment %li > %li\n",
87593 mod->name, align, PAGE_SIZE);
87594 align = PAGE_SIZE;
87595@@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
87596 static ssize_t show_coresize(struct module_attribute *mattr,
87597 struct module_kobject *mk, char *buffer)
87598 {
87599- return sprintf(buffer, "%u\n", mk->mod->core_size);
87600+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87601 }
87602
87603 static struct module_attribute modinfo_coresize =
87604@@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
87605 static ssize_t show_initsize(struct module_attribute *mattr,
87606 struct module_kobject *mk, char *buffer)
87607 {
87608- return sprintf(buffer, "%u\n", mk->mod->init_size);
87609+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87610 }
87611
87612 static struct module_attribute modinfo_initsize =
87613@@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
87614 goto bad_version;
87615 }
87616
87617+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87618+ /*
87619+ * avoid potentially printing jibberish on attempted load
87620+ * of a module randomized with a different seed
87621+ */
87622+ pr_warn("no symbol version for %s\n", symname);
87623+#else
87624 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87625+#endif
87626 return 0;
87627
87628 bad_version:
87629+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87630+ /*
87631+ * avoid potentially printing jibberish on attempted load
87632+ * of a module randomized with a different seed
87633+ */
87634+ printk("attempted module disagrees about version of symbol %s\n",
87635+ symname);
87636+#else
87637 printk("%s: disagrees about version of symbol %s\n",
87638 mod->name, symname);
87639+#endif
87640 return 0;
87641 }
87642
87643@@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
87644 */
87645 #ifdef CONFIG_SYSFS
87646
87647-#ifdef CONFIG_KALLSYMS
87648+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87649 static inline bool sect_empty(const Elf_Shdr *sect)
87650 {
87651 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87652@@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87653 {
87654 unsigned int notes, loaded, i;
87655 struct module_notes_attrs *notes_attrs;
87656- struct bin_attribute *nattr;
87657+ bin_attribute_no_const *nattr;
87658
87659 /* failed to create section attributes, so can't create notes */
87660 if (!mod->sect_attrs)
87661@@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
87662 static int module_add_modinfo_attrs(struct module *mod)
87663 {
87664 struct module_attribute *attr;
87665- struct module_attribute *temp_attr;
87666+ module_attribute_no_const *temp_attr;
87667 int error = 0;
87668 int i;
87669
87670@@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
87671
87672 static void unset_module_core_ro_nx(struct module *mod)
87673 {
87674- set_page_attributes(mod->module_core + mod->core_text_size,
87675- mod->module_core + mod->core_size,
87676+ set_page_attributes(mod->module_core_rw,
87677+ mod->module_core_rw + mod->core_size_rw,
87678 set_memory_x);
87679- set_page_attributes(mod->module_core,
87680- mod->module_core + mod->core_ro_size,
87681+ set_page_attributes(mod->module_core_rx,
87682+ mod->module_core_rx + mod->core_size_rx,
87683 set_memory_rw);
87684 }
87685
87686 static void unset_module_init_ro_nx(struct module *mod)
87687 {
87688- set_page_attributes(mod->module_init + mod->init_text_size,
87689- mod->module_init + mod->init_size,
87690+ set_page_attributes(mod->module_init_rw,
87691+ mod->module_init_rw + mod->init_size_rw,
87692 set_memory_x);
87693- set_page_attributes(mod->module_init,
87694- mod->module_init + mod->init_ro_size,
87695+ set_page_attributes(mod->module_init_rx,
87696+ mod->module_init_rx + mod->init_size_rx,
87697 set_memory_rw);
87698 }
87699
87700@@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
87701 list_for_each_entry_rcu(mod, &modules, list) {
87702 if (mod->state == MODULE_STATE_UNFORMED)
87703 continue;
87704- if ((mod->module_core) && (mod->core_text_size)) {
87705- set_page_attributes(mod->module_core,
87706- mod->module_core + mod->core_text_size,
87707+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87708+ set_page_attributes(mod->module_core_rx,
87709+ mod->module_core_rx + mod->core_size_rx,
87710 set_memory_rw);
87711 }
87712- if ((mod->module_init) && (mod->init_text_size)) {
87713- set_page_attributes(mod->module_init,
87714- mod->module_init + mod->init_text_size,
87715+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87716+ set_page_attributes(mod->module_init_rx,
87717+ mod->module_init_rx + mod->init_size_rx,
87718 set_memory_rw);
87719 }
87720 }
87721@@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
87722 list_for_each_entry_rcu(mod, &modules, list) {
87723 if (mod->state == MODULE_STATE_UNFORMED)
87724 continue;
87725- if ((mod->module_core) && (mod->core_text_size)) {
87726- set_page_attributes(mod->module_core,
87727- mod->module_core + mod->core_text_size,
87728+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87729+ set_page_attributes(mod->module_core_rx,
87730+ mod->module_core_rx + mod->core_size_rx,
87731 set_memory_ro);
87732 }
87733- if ((mod->module_init) && (mod->init_text_size)) {
87734- set_page_attributes(mod->module_init,
87735- mod->module_init + mod->init_text_size,
87736+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87737+ set_page_attributes(mod->module_init_rx,
87738+ mod->module_init_rx + mod->init_size_rx,
87739 set_memory_ro);
87740 }
87741 }
87742@@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
87743
87744 /* This may be NULL, but that's OK */
87745 unset_module_init_ro_nx(mod);
87746- module_free(mod, mod->module_init);
87747+ module_free(mod, mod->module_init_rw);
87748+ module_free_exec(mod, mod->module_init_rx);
87749 kfree(mod->args);
87750 percpu_modfree(mod);
87751
87752 /* Free lock-classes: */
87753- lockdep_free_key_range(mod->module_core, mod->core_size);
87754+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87755+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87756
87757 /* Finally, free the core (containing the module structure) */
87758 unset_module_core_ro_nx(mod);
87759- module_free(mod, mod->module_core);
87760+ module_free_exec(mod, mod->module_core_rx);
87761+ module_free(mod, mod->module_core_rw);
87762
87763 #ifdef CONFIG_MPU
87764 update_protections(current->mm);
87765@@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87766 int ret = 0;
87767 const struct kernel_symbol *ksym;
87768
87769+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87770+ int is_fs_load = 0;
87771+ int register_filesystem_found = 0;
87772+ char *p;
87773+
87774+ p = strstr(mod->args, "grsec_modharden_fs");
87775+ if (p) {
87776+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87777+ /* copy \0 as well */
87778+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87779+ is_fs_load = 1;
87780+ }
87781+#endif
87782+
87783 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87784 const char *name = info->strtab + sym[i].st_name;
87785
87786+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87787+ /* it's a real shame this will never get ripped and copied
87788+ upstream! ;(
87789+ */
87790+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87791+ register_filesystem_found = 1;
87792+#endif
87793+
87794 switch (sym[i].st_shndx) {
87795 case SHN_COMMON:
87796 /* Ignore common symbols */
87797@@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87798 ksym = resolve_symbol_wait(mod, info, name);
87799 /* Ok if resolved. */
87800 if (ksym && !IS_ERR(ksym)) {
87801+ pax_open_kernel();
87802 sym[i].st_value = ksym->value;
87803+ pax_close_kernel();
87804 break;
87805 }
87806
87807@@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87808 secbase = (unsigned long)mod_percpu(mod);
87809 else
87810 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87811+ pax_open_kernel();
87812 sym[i].st_value += secbase;
87813+ pax_close_kernel();
87814 break;
87815 }
87816 }
87817
87818+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87819+ if (is_fs_load && !register_filesystem_found) {
87820+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87821+ ret = -EPERM;
87822+ }
87823+#endif
87824+
87825 return ret;
87826 }
87827
87828@@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87829 || s->sh_entsize != ~0UL
87830 || strstarts(sname, ".init"))
87831 continue;
87832- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87833+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87834+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87835+ else
87836+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87837 pr_debug("\t%s\n", sname);
87838 }
87839- switch (m) {
87840- case 0: /* executable */
87841- mod->core_size = debug_align(mod->core_size);
87842- mod->core_text_size = mod->core_size;
87843- break;
87844- case 1: /* RO: text and ro-data */
87845- mod->core_size = debug_align(mod->core_size);
87846- mod->core_ro_size = mod->core_size;
87847- break;
87848- case 3: /* whole core */
87849- mod->core_size = debug_align(mod->core_size);
87850- break;
87851- }
87852 }
87853
87854 pr_debug("Init section allocation order:\n");
87855@@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87856 || s->sh_entsize != ~0UL
87857 || !strstarts(sname, ".init"))
87858 continue;
87859- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87860- | INIT_OFFSET_MASK);
87861+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87862+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87863+ else
87864+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87865+ s->sh_entsize |= INIT_OFFSET_MASK;
87866 pr_debug("\t%s\n", sname);
87867 }
87868- switch (m) {
87869- case 0: /* executable */
87870- mod->init_size = debug_align(mod->init_size);
87871- mod->init_text_size = mod->init_size;
87872- break;
87873- case 1: /* RO: text and ro-data */
87874- mod->init_size = debug_align(mod->init_size);
87875- mod->init_ro_size = mod->init_size;
87876- break;
87877- case 3: /* whole init */
87878- mod->init_size = debug_align(mod->init_size);
87879- break;
87880- }
87881 }
87882 }
87883
87884@@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87885
87886 /* Put symbol section at end of init part of module. */
87887 symsect->sh_flags |= SHF_ALLOC;
87888- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87889+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87890 info->index.sym) | INIT_OFFSET_MASK;
87891 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87892
87893@@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87894 }
87895
87896 /* Append room for core symbols at end of core part. */
87897- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87898- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87899- mod->core_size += strtab_size;
87900+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87901+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87902+ mod->core_size_rx += strtab_size;
87903
87904 /* Put string table section at end of init part of module. */
87905 strsect->sh_flags |= SHF_ALLOC;
87906- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87907+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87908 info->index.str) | INIT_OFFSET_MASK;
87909 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87910 }
87911@@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87912 /* Make sure we get permanent strtab: don't use info->strtab. */
87913 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87914
87915+ pax_open_kernel();
87916+
87917 /* Set types up while we still have access to sections. */
87918 for (i = 0; i < mod->num_symtab; i++)
87919 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87920
87921- mod->core_symtab = dst = mod->module_core + info->symoffs;
87922- mod->core_strtab = s = mod->module_core + info->stroffs;
87923+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87924+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87925 src = mod->symtab;
87926 for (ndst = i = 0; i < mod->num_symtab; i++) {
87927 if (i == 0 ||
87928@@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87929 }
87930 }
87931 mod->core_num_syms = ndst;
87932+
87933+ pax_close_kernel();
87934 }
87935 #else
87936 static inline void layout_symtab(struct module *mod, struct load_info *info)
87937@@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
87938 return vmalloc_exec(size);
87939 }
87940
87941-static void *module_alloc_update_bounds(unsigned long size)
87942+static void *module_alloc_update_bounds_rw(unsigned long size)
87943 {
87944 void *ret = module_alloc(size);
87945
87946 if (ret) {
87947 mutex_lock(&module_mutex);
87948 /* Update module bounds. */
87949- if ((unsigned long)ret < module_addr_min)
87950- module_addr_min = (unsigned long)ret;
87951- if ((unsigned long)ret + size > module_addr_max)
87952- module_addr_max = (unsigned long)ret + size;
87953+ if ((unsigned long)ret < module_addr_min_rw)
87954+ module_addr_min_rw = (unsigned long)ret;
87955+ if ((unsigned long)ret + size > module_addr_max_rw)
87956+ module_addr_max_rw = (unsigned long)ret + size;
87957+ mutex_unlock(&module_mutex);
87958+ }
87959+ return ret;
87960+}
87961+
87962+static void *module_alloc_update_bounds_rx(unsigned long size)
87963+{
87964+ void *ret = module_alloc_exec(size);
87965+
87966+ if (ret) {
87967+ mutex_lock(&module_mutex);
87968+ /* Update module bounds. */
87969+ if ((unsigned long)ret < module_addr_min_rx)
87970+ module_addr_min_rx = (unsigned long)ret;
87971+ if ((unsigned long)ret + size > module_addr_max_rx)
87972+ module_addr_max_rx = (unsigned long)ret + size;
87973 mutex_unlock(&module_mutex);
87974 }
87975 return ret;
87976@@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87977 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87978
87979 if (info->index.sym == 0) {
87980+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87981+ /*
87982+ * avoid potentially printing jibberish on attempted load
87983+ * of a module randomized with a different seed
87984+ */
87985+ pr_warn("module has no symbols (stripped?)\n");
87986+#else
87987 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87988+#endif
87989 return ERR_PTR(-ENOEXEC);
87990 }
87991
87992@@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87993 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87994 {
87995 const char *modmagic = get_modinfo(info, "vermagic");
87996+ const char *license = get_modinfo(info, "license");
87997 int err;
87998
87999+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88000+ if (!license || !license_is_gpl_compatible(license))
88001+ return -ENOEXEC;
88002+#endif
88003+
88004 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88005 modmagic = NULL;
88006
88007@@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88008 }
88009
88010 /* Set up license info based on the info section */
88011- set_license(mod, get_modinfo(info, "license"));
88012+ set_license(mod, license);
88013
88014 return 0;
88015 }
88016@@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
88017 void *ptr;
88018
88019 /* Do the allocs. */
88020- ptr = module_alloc_update_bounds(mod->core_size);
88021+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88022 /*
88023 * The pointer to this block is stored in the module structure
88024 * which is inside the block. Just mark it as not being a
88025@@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
88026 if (!ptr)
88027 return -ENOMEM;
88028
88029- memset(ptr, 0, mod->core_size);
88030- mod->module_core = ptr;
88031+ memset(ptr, 0, mod->core_size_rw);
88032+ mod->module_core_rw = ptr;
88033
88034- if (mod->init_size) {
88035- ptr = module_alloc_update_bounds(mod->init_size);
88036+ if (mod->init_size_rw) {
88037+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88038 /*
88039 * The pointer to this block is stored in the module structure
88040 * which is inside the block. This block doesn't need to be
88041@@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
88042 */
88043 kmemleak_ignore(ptr);
88044 if (!ptr) {
88045- module_free(mod, mod->module_core);
88046+ module_free(mod, mod->module_core_rw);
88047 return -ENOMEM;
88048 }
88049- memset(ptr, 0, mod->init_size);
88050- mod->module_init = ptr;
88051+ memset(ptr, 0, mod->init_size_rw);
88052+ mod->module_init_rw = ptr;
88053 } else
88054- mod->module_init = NULL;
88055+ mod->module_init_rw = NULL;
88056+
88057+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88058+ kmemleak_not_leak(ptr);
88059+ if (!ptr) {
88060+ if (mod->module_init_rw)
88061+ module_free(mod, mod->module_init_rw);
88062+ module_free(mod, mod->module_core_rw);
88063+ return -ENOMEM;
88064+ }
88065+
88066+ pax_open_kernel();
88067+ memset(ptr, 0, mod->core_size_rx);
88068+ pax_close_kernel();
88069+ mod->module_core_rx = ptr;
88070+
88071+ if (mod->init_size_rx) {
88072+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88073+ kmemleak_ignore(ptr);
88074+ if (!ptr && mod->init_size_rx) {
88075+ module_free_exec(mod, mod->module_core_rx);
88076+ if (mod->module_init_rw)
88077+ module_free(mod, mod->module_init_rw);
88078+ module_free(mod, mod->module_core_rw);
88079+ return -ENOMEM;
88080+ }
88081+
88082+ pax_open_kernel();
88083+ memset(ptr, 0, mod->init_size_rx);
88084+ pax_close_kernel();
88085+ mod->module_init_rx = ptr;
88086+ } else
88087+ mod->module_init_rx = NULL;
88088
88089 /* Transfer each section which specifies SHF_ALLOC */
88090 pr_debug("final section addresses:\n");
88091@@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
88092 if (!(shdr->sh_flags & SHF_ALLOC))
88093 continue;
88094
88095- if (shdr->sh_entsize & INIT_OFFSET_MASK)
88096- dest = mod->module_init
88097- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88098- else
88099- dest = mod->module_core + shdr->sh_entsize;
88100+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88101+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88102+ dest = mod->module_init_rw
88103+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88104+ else
88105+ dest = mod->module_init_rx
88106+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88107+ } else {
88108+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88109+ dest = mod->module_core_rw + shdr->sh_entsize;
88110+ else
88111+ dest = mod->module_core_rx + shdr->sh_entsize;
88112+ }
88113+
88114+ if (shdr->sh_type != SHT_NOBITS) {
88115+
88116+#ifdef CONFIG_PAX_KERNEXEC
88117+#ifdef CONFIG_X86_64
88118+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88119+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88120+#endif
88121+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88122+ pax_open_kernel();
88123+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88124+ pax_close_kernel();
88125+ } else
88126+#endif
88127
88128- if (shdr->sh_type != SHT_NOBITS)
88129 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88130+ }
88131 /* Update sh_addr to point to copy in image. */
88132- shdr->sh_addr = (unsigned long)dest;
88133+
88134+#ifdef CONFIG_PAX_KERNEXEC
88135+ if (shdr->sh_flags & SHF_EXECINSTR)
88136+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88137+ else
88138+#endif
88139+
88140+ shdr->sh_addr = (unsigned long)dest;
88141 pr_debug("\t0x%lx %s\n",
88142 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88143 }
88144@@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88145 * Do it before processing of module parameters, so the module
88146 * can provide parameter accessor functions of its own.
88147 */
88148- if (mod->module_init)
88149- flush_icache_range((unsigned long)mod->module_init,
88150- (unsigned long)mod->module_init
88151- + mod->init_size);
88152- flush_icache_range((unsigned long)mod->module_core,
88153- (unsigned long)mod->module_core + mod->core_size);
88154+ if (mod->module_init_rx)
88155+ flush_icache_range((unsigned long)mod->module_init_rx,
88156+ (unsigned long)mod->module_init_rx
88157+ + mod->init_size_rx);
88158+ flush_icache_range((unsigned long)mod->module_core_rx,
88159+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88160
88161 set_fs(old_fs);
88162 }
88163@@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88164 static void module_deallocate(struct module *mod, struct load_info *info)
88165 {
88166 percpu_modfree(mod);
88167- module_free(mod, mod->module_init);
88168- module_free(mod, mod->module_core);
88169+ module_free_exec(mod, mod->module_init_rx);
88170+ module_free_exec(mod, mod->module_core_rx);
88171+ module_free(mod, mod->module_init_rw);
88172+ module_free(mod, mod->module_core_rw);
88173 }
88174
88175 int __weak module_finalize(const Elf_Ehdr *hdr,
88176@@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88177 static int post_relocation(struct module *mod, const struct load_info *info)
88178 {
88179 /* Sort exception table now relocations are done. */
88180+ pax_open_kernel();
88181 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88182+ pax_close_kernel();
88183
88184 /* Copy relocated percpu area over. */
88185 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88186@@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88187 MODULE_STATE_COMING, mod);
88188
88189 /* Set RO and NX regions for core */
88190- set_section_ro_nx(mod->module_core,
88191- mod->core_text_size,
88192- mod->core_ro_size,
88193- mod->core_size);
88194+ set_section_ro_nx(mod->module_core_rx,
88195+ mod->core_size_rx,
88196+ mod->core_size_rx,
88197+ mod->core_size_rx);
88198
88199 /* Set RO and NX regions for init */
88200- set_section_ro_nx(mod->module_init,
88201- mod->init_text_size,
88202- mod->init_ro_size,
88203- mod->init_size);
88204+ set_section_ro_nx(mod->module_init_rx,
88205+ mod->init_size_rx,
88206+ mod->init_size_rx,
88207+ mod->init_size_rx);
88208
88209 do_mod_ctors(mod);
88210 /* Start the module */
88211@@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88212 mod->strtab = mod->core_strtab;
88213 #endif
88214 unset_module_init_ro_nx(mod);
88215- module_free(mod, mod->module_init);
88216- mod->module_init = NULL;
88217- mod->init_size = 0;
88218- mod->init_ro_size = 0;
88219- mod->init_text_size = 0;
88220+ module_free(mod, mod->module_init_rw);
88221+ module_free_exec(mod, mod->module_init_rx);
88222+ mod->module_init_rw = NULL;
88223+ mod->module_init_rx = NULL;
88224+ mod->init_size_rw = 0;
88225+ mod->init_size_rx = 0;
88226 mutex_unlock(&module_mutex);
88227 wake_up_all(&module_wq);
88228
88229@@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88230 if (err)
88231 goto free_unload;
88232
88233+ /* Now copy in args */
88234+ mod->args = strndup_user(uargs, ~0UL >> 1);
88235+ if (IS_ERR(mod->args)) {
88236+ err = PTR_ERR(mod->args);
88237+ goto free_unload;
88238+ }
88239+
88240 /* Set up MODINFO_ATTR fields */
88241 setup_modinfo(mod, info);
88242
88243+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88244+ {
88245+ char *p, *p2;
88246+
88247+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88248+ 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);
88249+ err = -EPERM;
88250+ goto free_modinfo;
88251+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88252+ p += sizeof("grsec_modharden_normal") - 1;
88253+ p2 = strstr(p, "_");
88254+ if (p2) {
88255+ *p2 = '\0';
88256+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88257+ *p2 = '_';
88258+ }
88259+ err = -EPERM;
88260+ goto free_modinfo;
88261+ }
88262+ }
88263+#endif
88264+
88265 /* Fix up syms, so that st_value is a pointer to location. */
88266 err = simplify_symbols(mod, info);
88267 if (err < 0)
88268@@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88269
88270 flush_module_icache(mod);
88271
88272- /* Now copy in args */
88273- mod->args = strndup_user(uargs, ~0UL >> 1);
88274- if (IS_ERR(mod->args)) {
88275- err = PTR_ERR(mod->args);
88276- goto free_arch_cleanup;
88277- }
88278-
88279 dynamic_debug_setup(info->debug, info->num_debug);
88280
88281 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88282@@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88283 ddebug_cleanup:
88284 dynamic_debug_remove(info->debug);
88285 synchronize_sched();
88286- kfree(mod->args);
88287- free_arch_cleanup:
88288 module_arch_cleanup(mod);
88289 free_modinfo:
88290 free_modinfo(mod);
88291+ kfree(mod->args);
88292 free_unload:
88293 module_unload_free(mod);
88294 unlink_mod:
88295@@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88296 unsigned long nextval;
88297
88298 /* At worse, next value is at end of module */
88299- if (within_module_init(addr, mod))
88300- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88301+ if (within_module_init_rx(addr, mod))
88302+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88303+ else if (within_module_init_rw(addr, mod))
88304+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88305+ else if (within_module_core_rx(addr, mod))
88306+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88307+ else if (within_module_core_rw(addr, mod))
88308+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88309 else
88310- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88311+ return NULL;
88312
88313 /* Scan for closest preceding symbol, and next symbol. (ELF
88314 starts real symbols at 1). */
88315@@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88316 return 0;
88317
88318 seq_printf(m, "%s %u",
88319- mod->name, mod->init_size + mod->core_size);
88320+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88321 print_unload_info(m, mod);
88322
88323 /* Informative for users. */
88324@@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88325 mod->state == MODULE_STATE_COMING ? "Loading":
88326 "Live");
88327 /* Used by oprofile and other similar tools. */
88328- seq_printf(m, " 0x%pK", mod->module_core);
88329+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88330
88331 /* Taints info */
88332 if (mod->taints)
88333@@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
88334
88335 static int __init proc_modules_init(void)
88336 {
88337+#ifndef CONFIG_GRKERNSEC_HIDESYM
88338+#ifdef CONFIG_GRKERNSEC_PROC_USER
88339+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88340+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88341+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88342+#else
88343 proc_create("modules", 0, NULL, &proc_modules_operations);
88344+#endif
88345+#else
88346+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88347+#endif
88348 return 0;
88349 }
88350 module_init(proc_modules_init);
88351@@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
88352 {
88353 struct module *mod;
88354
88355- if (addr < module_addr_min || addr > module_addr_max)
88356+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88357+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88358 return NULL;
88359
88360 list_for_each_entry_rcu(mod, &modules, list) {
88361 if (mod->state == MODULE_STATE_UNFORMED)
88362 continue;
88363- if (within_module_core(addr, mod)
88364- || within_module_init(addr, mod))
88365+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88366 return mod;
88367 }
88368 return NULL;
88369@@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
88370 */
88371 struct module *__module_text_address(unsigned long addr)
88372 {
88373- struct module *mod = __module_address(addr);
88374+ struct module *mod;
88375+
88376+#ifdef CONFIG_X86_32
88377+ addr = ktla_ktva(addr);
88378+#endif
88379+
88380+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88381+ return NULL;
88382+
88383+ mod = __module_address(addr);
88384+
88385 if (mod) {
88386 /* Make sure it's within the text section. */
88387- if (!within(addr, mod->module_init, mod->init_text_size)
88388- && !within(addr, mod->module_core, mod->core_text_size))
88389+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88390 mod = NULL;
88391 }
88392 return mod;
88393diff --git a/kernel/notifier.c b/kernel/notifier.c
88394index db4c8b0..ad011c5 100644
88395--- a/kernel/notifier.c
88396+++ b/kernel/notifier.c
88397@@ -5,6 +5,7 @@
88398 #include <linux/rcupdate.h>
88399 #include <linux/vmalloc.h>
88400 #include <linux/reboot.h>
88401+#include <linux/mm.h>
88402
88403 /*
88404 * Notifier list for kernel code which wants to be called
88405@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88406 while ((*nl) != NULL) {
88407 if (n->priority > (*nl)->priority)
88408 break;
88409- nl = &((*nl)->next);
88410+ nl = (struct notifier_block **)&((*nl)->next);
88411 }
88412- n->next = *nl;
88413+ pax_open_kernel();
88414+ *(const void **)&n->next = *nl;
88415 rcu_assign_pointer(*nl, n);
88416+ pax_close_kernel();
88417 return 0;
88418 }
88419
88420@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88421 return 0;
88422 if (n->priority > (*nl)->priority)
88423 break;
88424- nl = &((*nl)->next);
88425+ nl = (struct notifier_block **)&((*nl)->next);
88426 }
88427- n->next = *nl;
88428+ pax_open_kernel();
88429+ *(const void **)&n->next = *nl;
88430 rcu_assign_pointer(*nl, n);
88431+ pax_close_kernel();
88432 return 0;
88433 }
88434
88435@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88436 {
88437 while ((*nl) != NULL) {
88438 if ((*nl) == n) {
88439+ pax_open_kernel();
88440 rcu_assign_pointer(*nl, n->next);
88441+ pax_close_kernel();
88442 return 0;
88443 }
88444- nl = &((*nl)->next);
88445+ nl = (struct notifier_block **)&((*nl)->next);
88446 }
88447 return -ENOENT;
88448 }
88449diff --git a/kernel/padata.c b/kernel/padata.c
88450index 161402f..598814c 100644
88451--- a/kernel/padata.c
88452+++ b/kernel/padata.c
88453@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88454 * seq_nr mod. number of cpus in use.
88455 */
88456
88457- seq_nr = atomic_inc_return(&pd->seq_nr);
88458+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88459 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88460
88461 return padata_index_to_cpu(pd, cpu_index);
88462@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88463 padata_init_pqueues(pd);
88464 padata_init_squeues(pd);
88465 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88466- atomic_set(&pd->seq_nr, -1);
88467+ atomic_set_unchecked(&pd->seq_nr, -1);
88468 atomic_set(&pd->reorder_objects, 0);
88469 atomic_set(&pd->refcnt, 0);
88470 pd->pinst = pinst;
88471diff --git a/kernel/panic.c b/kernel/panic.c
88472index d02fa9f..9faec0a 100644
88473--- a/kernel/panic.c
88474+++ b/kernel/panic.c
88475@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88476 /*
88477 * Stop ourself in panic -- architecture code may override this
88478 */
88479-void __weak panic_smp_self_stop(void)
88480+void __weak __noreturn panic_smp_self_stop(void)
88481 {
88482 while (1)
88483 cpu_relax();
88484@@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88485 disable_trace_on_warning();
88486
88487 pr_warn("------------[ cut here ]------------\n");
88488- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88489+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88490 raw_smp_processor_id(), current->pid, file, line, caller);
88491
88492 if (args)
88493@@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88494 */
88495 __visible void __stack_chk_fail(void)
88496 {
88497- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88498+ dump_stack();
88499+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88500 __builtin_return_address(0));
88501 }
88502 EXPORT_SYMBOL(__stack_chk_fail);
88503diff --git a/kernel/pid.c b/kernel/pid.c
88504index 9b9a266..c20ef80 100644
88505--- a/kernel/pid.c
88506+++ b/kernel/pid.c
88507@@ -33,6 +33,7 @@
88508 #include <linux/rculist.h>
88509 #include <linux/bootmem.h>
88510 #include <linux/hash.h>
88511+#include <linux/security.h>
88512 #include <linux/pid_namespace.h>
88513 #include <linux/init_task.h>
88514 #include <linux/syscalls.h>
88515@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88516
88517 int pid_max = PID_MAX_DEFAULT;
88518
88519-#define RESERVED_PIDS 300
88520+#define RESERVED_PIDS 500
88521
88522 int pid_max_min = RESERVED_PIDS + 1;
88523 int pid_max_max = PID_MAX_LIMIT;
88524@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88525 */
88526 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88527 {
88528+ struct task_struct *task;
88529+
88530 rcu_lockdep_assert(rcu_read_lock_held(),
88531 "find_task_by_pid_ns() needs rcu_read_lock()"
88532 " protection");
88533- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88534+
88535+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88536+
88537+ if (gr_pid_is_chrooted(task))
88538+ return NULL;
88539+
88540+ return task;
88541 }
88542
88543 struct task_struct *find_task_by_vpid(pid_t vnr)
88544@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88545 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88546 }
88547
88548+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88549+{
88550+ rcu_lockdep_assert(rcu_read_lock_held(),
88551+ "find_task_by_pid_ns() needs rcu_read_lock()"
88552+ " protection");
88553+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88554+}
88555+
88556 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88557 {
88558 struct pid *pid;
88559diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88560index db95d8e..a0ca23f 100644
88561--- a/kernel/pid_namespace.c
88562+++ b/kernel/pid_namespace.c
88563@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88564 void __user *buffer, size_t *lenp, loff_t *ppos)
88565 {
88566 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88567- struct ctl_table tmp = *table;
88568+ ctl_table_no_const tmp = *table;
88569
88570 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88571 return -EPERM;
88572diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88573index 3b89464..5e38379 100644
88574--- a/kernel/posix-cpu-timers.c
88575+++ b/kernel/posix-cpu-timers.c
88576@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88577
88578 static __init int init_posix_cpu_timers(void)
88579 {
88580- struct k_clock process = {
88581+ static struct k_clock process = {
88582 .clock_getres = process_cpu_clock_getres,
88583 .clock_get = process_cpu_clock_get,
88584 .timer_create = process_cpu_timer_create,
88585 .nsleep = process_cpu_nsleep,
88586 .nsleep_restart = process_cpu_nsleep_restart,
88587 };
88588- struct k_clock thread = {
88589+ static struct k_clock thread = {
88590 .clock_getres = thread_cpu_clock_getres,
88591 .clock_get = thread_cpu_clock_get,
88592 .timer_create = thread_cpu_timer_create,
88593diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88594index 424c2d4..679242f 100644
88595--- a/kernel/posix-timers.c
88596+++ b/kernel/posix-timers.c
88597@@ -43,6 +43,7 @@
88598 #include <linux/hash.h>
88599 #include <linux/posix-clock.h>
88600 #include <linux/posix-timers.h>
88601+#include <linux/grsecurity.h>
88602 #include <linux/syscalls.h>
88603 #include <linux/wait.h>
88604 #include <linux/workqueue.h>
88605@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88606 * which we beg off on and pass to do_sys_settimeofday().
88607 */
88608
88609-static struct k_clock posix_clocks[MAX_CLOCKS];
88610+static struct k_clock *posix_clocks[MAX_CLOCKS];
88611
88612 /*
88613 * These ones are defined below.
88614@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88615 */
88616 static __init int init_posix_timers(void)
88617 {
88618- struct k_clock clock_realtime = {
88619+ static struct k_clock clock_realtime = {
88620 .clock_getres = hrtimer_get_res,
88621 .clock_get = posix_clock_realtime_get,
88622 .clock_set = posix_clock_realtime_set,
88623@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88624 .timer_get = common_timer_get,
88625 .timer_del = common_timer_del,
88626 };
88627- struct k_clock clock_monotonic = {
88628+ static struct k_clock clock_monotonic = {
88629 .clock_getres = hrtimer_get_res,
88630 .clock_get = posix_ktime_get_ts,
88631 .nsleep = common_nsleep,
88632@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88633 .timer_get = common_timer_get,
88634 .timer_del = common_timer_del,
88635 };
88636- struct k_clock clock_monotonic_raw = {
88637+ static struct k_clock clock_monotonic_raw = {
88638 .clock_getres = hrtimer_get_res,
88639 .clock_get = posix_get_monotonic_raw,
88640 };
88641- struct k_clock clock_realtime_coarse = {
88642+ static struct k_clock clock_realtime_coarse = {
88643 .clock_getres = posix_get_coarse_res,
88644 .clock_get = posix_get_realtime_coarse,
88645 };
88646- struct k_clock clock_monotonic_coarse = {
88647+ static struct k_clock clock_monotonic_coarse = {
88648 .clock_getres = posix_get_coarse_res,
88649 .clock_get = posix_get_monotonic_coarse,
88650 };
88651- struct k_clock clock_tai = {
88652+ static struct k_clock clock_tai = {
88653 .clock_getres = hrtimer_get_res,
88654 .clock_get = posix_get_tai,
88655 .nsleep = common_nsleep,
88656@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88657 .timer_get = common_timer_get,
88658 .timer_del = common_timer_del,
88659 };
88660- struct k_clock clock_boottime = {
88661+ static struct k_clock clock_boottime = {
88662 .clock_getres = hrtimer_get_res,
88663 .clock_get = posix_get_boottime,
88664 .nsleep = common_nsleep,
88665@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88666 return;
88667 }
88668
88669- posix_clocks[clock_id] = *new_clock;
88670+ posix_clocks[clock_id] = new_clock;
88671 }
88672 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88673
88674@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88675 return (id & CLOCKFD_MASK) == CLOCKFD ?
88676 &clock_posix_dynamic : &clock_posix_cpu;
88677
88678- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88679+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88680 return NULL;
88681- return &posix_clocks[id];
88682+ return posix_clocks[id];
88683 }
88684
88685 static int common_timer_create(struct k_itimer *new_timer)
88686@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88687 struct k_clock *kc = clockid_to_kclock(which_clock);
88688 struct k_itimer *new_timer;
88689 int error, new_timer_id;
88690- sigevent_t event;
88691+ sigevent_t event = { };
88692 int it_id_set = IT_ID_NOT_SET;
88693
88694 if (!kc)
88695@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88696 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88697 return -EFAULT;
88698
88699+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88700+ have their clock_set fptr set to a nosettime dummy function
88701+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88702+ call common_clock_set, which calls do_sys_settimeofday, which
88703+ we hook
88704+ */
88705+
88706 return kc->clock_set(which_clock, &new_tp);
88707 }
88708
88709diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88710index 2fac9cc..56fef29 100644
88711--- a/kernel/power/Kconfig
88712+++ b/kernel/power/Kconfig
88713@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88714 config HIBERNATION
88715 bool "Hibernation (aka 'suspend to disk')"
88716 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88717+ depends on !GRKERNSEC_KMEM
88718+ depends on !PAX_MEMORY_SANITIZE
88719 select HIBERNATE_CALLBACKS
88720 select LZO_COMPRESS
88721 select LZO_DECOMPRESS
88722diff --git a/kernel/power/process.c b/kernel/power/process.c
88723index 06ec886..9dba35e 100644
88724--- a/kernel/power/process.c
88725+++ b/kernel/power/process.c
88726@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88727 unsigned int elapsed_msecs;
88728 bool wakeup = false;
88729 int sleep_usecs = USEC_PER_MSEC;
88730+ bool timedout = false;
88731
88732 do_gettimeofday(&start);
88733
88734@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88735
88736 while (true) {
88737 todo = 0;
88738+ if (time_after(jiffies, end_time))
88739+ timedout = true;
88740 read_lock(&tasklist_lock);
88741 do_each_thread(g, p) {
88742 if (p == current || !freeze_task(p))
88743 continue;
88744
88745- if (!freezer_should_skip(p))
88746+ if (!freezer_should_skip(p)) {
88747 todo++;
88748+ if (timedout) {
88749+ printk(KERN_ERR "Task refusing to freeze:\n");
88750+ sched_show_task(p);
88751+ }
88752+ }
88753 } while_each_thread(g, p);
88754 read_unlock(&tasklist_lock);
88755
88756@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88757 todo += wq_busy;
88758 }
88759
88760- if (!todo || time_after(jiffies, end_time))
88761+ if (!todo || timedout)
88762 break;
88763
88764 if (pm_wakeup_pending()) {
88765diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88766index 221229c..c76ca0a 100644
88767--- a/kernel/printk/printk.c
88768+++ b/kernel/printk/printk.c
88769@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88770 if (from_file && type != SYSLOG_ACTION_OPEN)
88771 return 0;
88772
88773+#ifdef CONFIG_GRKERNSEC_DMESG
88774+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88775+ return -EPERM;
88776+#endif
88777+
88778 if (syslog_action_restricted(type)) {
88779 if (capable(CAP_SYSLOG))
88780 return 0;
88781diff --git a/kernel/profile.c b/kernel/profile.c
88782index cb980f0..ccd8782 100644
88783--- a/kernel/profile.c
88784+++ b/kernel/profile.c
88785@@ -37,7 +37,7 @@ struct profile_hit {
88786 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88787 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88788
88789-static atomic_t *prof_buffer;
88790+static atomic_unchecked_t *prof_buffer;
88791 static unsigned long prof_len, prof_shift;
88792
88793 int prof_on __read_mostly;
88794@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88795 hits[i].pc = 0;
88796 continue;
88797 }
88798- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88799+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88800 hits[i].hits = hits[i].pc = 0;
88801 }
88802 }
88803@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88804 * Add the current hit(s) and flush the write-queue out
88805 * to the global buffer:
88806 */
88807- atomic_add(nr_hits, &prof_buffer[pc]);
88808+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88809 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88810- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88811+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88812 hits[i].pc = hits[i].hits = 0;
88813 }
88814 out:
88815@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88816 {
88817 unsigned long pc;
88818 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88819- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88820+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88821 }
88822 #endif /* !CONFIG_SMP */
88823
88824@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88825 return -EFAULT;
88826 buf++; p++; count--; read++;
88827 }
88828- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88829+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88830 if (copy_to_user(buf, (void *)pnt, count))
88831 return -EFAULT;
88832 read += count;
88833@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88834 }
88835 #endif
88836 profile_discard_flip_buffers();
88837- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88838+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88839 return count;
88840 }
88841
88842diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88843index adf9862..9d86345 100644
88844--- a/kernel/ptrace.c
88845+++ b/kernel/ptrace.c
88846@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88847 if (seize)
88848 flags |= PT_SEIZED;
88849 rcu_read_lock();
88850- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88851+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88852 flags |= PT_PTRACE_CAP;
88853 rcu_read_unlock();
88854 task->ptrace = flags;
88855@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88856 break;
88857 return -EIO;
88858 }
88859- if (copy_to_user(dst, buf, retval))
88860+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88861 return -EFAULT;
88862 copied += retval;
88863 src += retval;
88864@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88865 bool seized = child->ptrace & PT_SEIZED;
88866 int ret = -EIO;
88867 siginfo_t siginfo, *si;
88868- void __user *datavp = (void __user *) data;
88869+ void __user *datavp = (__force void __user *) data;
88870 unsigned long __user *datalp = datavp;
88871 unsigned long flags;
88872
88873@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88874 goto out;
88875 }
88876
88877+ if (gr_handle_ptrace(child, request)) {
88878+ ret = -EPERM;
88879+ goto out_put_task_struct;
88880+ }
88881+
88882 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88883 ret = ptrace_attach(child, request, addr, data);
88884 /*
88885 * Some architectures need to do book-keeping after
88886 * a ptrace attach.
88887 */
88888- if (!ret)
88889+ if (!ret) {
88890 arch_ptrace_attach(child);
88891+ gr_audit_ptrace(child);
88892+ }
88893 goto out_put_task_struct;
88894 }
88895
88896@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88897 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88898 if (copied != sizeof(tmp))
88899 return -EIO;
88900- return put_user(tmp, (unsigned long __user *)data);
88901+ return put_user(tmp, (__force unsigned long __user *)data);
88902 }
88903
88904 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88905@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88906 }
88907
88908 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
88909- compat_long_t, addr, compat_long_t, data)
88910+ compat_ulong_t, addr, compat_ulong_t, data)
88911 {
88912 struct task_struct *child;
88913 long ret;
88914@@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
88915 goto out;
88916 }
88917
88918+ if (gr_handle_ptrace(child, request)) {
88919+ ret = -EPERM;
88920+ goto out_put_task_struct;
88921+ }
88922+
88923 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88924 ret = ptrace_attach(child, request, addr, data);
88925 /*
88926 * Some architectures need to do book-keeping after
88927 * a ptrace attach.
88928 */
88929- if (!ret)
88930+ if (!ret) {
88931 arch_ptrace_attach(child);
88932+ gr_audit_ptrace(child);
88933+ }
88934 goto out_put_task_struct;
88935 }
88936
88937diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
88938index bd30bc6..dce23da 100644
88939--- a/kernel/rcu/rcutorture.c
88940+++ b/kernel/rcu/rcutorture.c
88941@@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
88942 rcu_torture_count) = { 0 };
88943 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
88944 rcu_torture_batch) = { 0 };
88945-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88946-static atomic_t n_rcu_torture_alloc;
88947-static atomic_t n_rcu_torture_alloc_fail;
88948-static atomic_t n_rcu_torture_free;
88949-static atomic_t n_rcu_torture_mberror;
88950-static atomic_t n_rcu_torture_error;
88951+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88952+static atomic_unchecked_t n_rcu_torture_alloc;
88953+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88954+static atomic_unchecked_t n_rcu_torture_free;
88955+static atomic_unchecked_t n_rcu_torture_mberror;
88956+static atomic_unchecked_t n_rcu_torture_error;
88957 static long n_rcu_torture_barrier_error;
88958 static long n_rcu_torture_boost_ktrerror;
88959 static long n_rcu_torture_boost_rterror;
88960@@ -186,11 +186,11 @@ rcu_torture_alloc(void)
88961
88962 spin_lock_bh(&rcu_torture_lock);
88963 if (list_empty(&rcu_torture_freelist)) {
88964- atomic_inc(&n_rcu_torture_alloc_fail);
88965+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88966 spin_unlock_bh(&rcu_torture_lock);
88967 return NULL;
88968 }
88969- atomic_inc(&n_rcu_torture_alloc);
88970+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88971 p = rcu_torture_freelist.next;
88972 list_del_init(p);
88973 spin_unlock_bh(&rcu_torture_lock);
88974@@ -203,7 +203,7 @@ rcu_torture_alloc(void)
88975 static void
88976 rcu_torture_free(struct rcu_torture *p)
88977 {
88978- atomic_inc(&n_rcu_torture_free);
88979+ atomic_inc_unchecked(&n_rcu_torture_free);
88980 spin_lock_bh(&rcu_torture_lock);
88981 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88982 spin_unlock_bh(&rcu_torture_lock);
88983@@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
88984 i = rp->rtort_pipe_count;
88985 if (i > RCU_TORTURE_PIPE_LEN)
88986 i = RCU_TORTURE_PIPE_LEN;
88987- atomic_inc(&rcu_torture_wcount[i]);
88988+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88989 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88990 rp->rtort_mbtest = 0;
88991 rcu_torture_free(rp);
88992@@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
88993 i = old_rp->rtort_pipe_count;
88994 if (i > RCU_TORTURE_PIPE_LEN)
88995 i = RCU_TORTURE_PIPE_LEN;
88996- atomic_inc(&rcu_torture_wcount[i]);
88997+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88998 old_rp->rtort_pipe_count++;
88999 if (gp_normal == gp_exp)
89000 exp = !!(torture_random(&rand) & 0x80);
89001@@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
89002 i = rp->rtort_pipe_count;
89003 if (i > RCU_TORTURE_PIPE_LEN)
89004 i = RCU_TORTURE_PIPE_LEN;
89005- atomic_inc(&rcu_torture_wcount[i]);
89006+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89007 if (++rp->rtort_pipe_count >=
89008 RCU_TORTURE_PIPE_LEN) {
89009 rp->rtort_mbtest = 0;
89010@@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
89011 return;
89012 }
89013 if (p->rtort_mbtest == 0)
89014- atomic_inc(&n_rcu_torture_mberror);
89015+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89016 spin_lock(&rand_lock);
89017 cur_ops->read_delay(&rand);
89018 n_rcu_torture_timers++;
89019@@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
89020 continue;
89021 }
89022 if (p->rtort_mbtest == 0)
89023- atomic_inc(&n_rcu_torture_mberror);
89024+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89025 cur_ops->read_delay(&rand);
89026 preempt_disable();
89027 pipe_count = p->rtort_pipe_count;
89028@@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
89029 }
89030 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89031 page += sprintf(page,
89032- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89033+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89034 rcu_torture_current,
89035 rcu_torture_current_version,
89036 list_empty(&rcu_torture_freelist),
89037- atomic_read(&n_rcu_torture_alloc),
89038- atomic_read(&n_rcu_torture_alloc_fail),
89039- atomic_read(&n_rcu_torture_free));
89040+ atomic_read_unchecked(&n_rcu_torture_alloc),
89041+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89042+ atomic_read_unchecked(&n_rcu_torture_free));
89043 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89044- atomic_read(&n_rcu_torture_mberror),
89045+ atomic_read_unchecked(&n_rcu_torture_mberror),
89046 n_rcu_torture_boost_ktrerror,
89047 n_rcu_torture_boost_rterror);
89048 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89049@@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
89050 n_barrier_attempts,
89051 n_rcu_torture_barrier_error);
89052 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89053- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89054+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89055 n_rcu_torture_barrier_error != 0 ||
89056 n_rcu_torture_boost_ktrerror != 0 ||
89057 n_rcu_torture_boost_rterror != 0 ||
89058 n_rcu_torture_boost_failure != 0 ||
89059 i > 1) {
89060 page += sprintf(page, "!!! ");
89061- atomic_inc(&n_rcu_torture_error);
89062+ atomic_inc_unchecked(&n_rcu_torture_error);
89063 WARN_ON_ONCE(1);
89064 }
89065 page += sprintf(page, "Reader Pipe: ");
89066@@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
89067 page += sprintf(page, "Free-Block Circulation: ");
89068 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89069 page += sprintf(page, " %d",
89070- atomic_read(&rcu_torture_wcount[i]));
89071+ atomic_read_unchecked(&rcu_torture_wcount[i]));
89072 }
89073 page += sprintf(page, "\n");
89074 if (cur_ops->stats)
89075@@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
89076
89077 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89078
89079- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89080+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89081 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89082 else if (torture_onoff_failures())
89083 rcu_torture_print_module_parms(cur_ops,
89084@@ -1460,18 +1460,18 @@ rcu_torture_init(void)
89085
89086 rcu_torture_current = NULL;
89087 rcu_torture_current_version = 0;
89088- atomic_set(&n_rcu_torture_alloc, 0);
89089- atomic_set(&n_rcu_torture_alloc_fail, 0);
89090- atomic_set(&n_rcu_torture_free, 0);
89091- atomic_set(&n_rcu_torture_mberror, 0);
89092- atomic_set(&n_rcu_torture_error, 0);
89093+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89094+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89095+ atomic_set_unchecked(&n_rcu_torture_free, 0);
89096+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89097+ atomic_set_unchecked(&n_rcu_torture_error, 0);
89098 n_rcu_torture_barrier_error = 0;
89099 n_rcu_torture_boost_ktrerror = 0;
89100 n_rcu_torture_boost_rterror = 0;
89101 n_rcu_torture_boost_failure = 0;
89102 n_rcu_torture_boosts = 0;
89103 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89104- atomic_set(&rcu_torture_wcount[i], 0);
89105+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89106 for_each_possible_cpu(cpu) {
89107 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89108 per_cpu(rcu_torture_count, cpu)[i] = 0;
89109diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89110index c639556..cf0a0d5 100644
89111--- a/kernel/rcu/srcu.c
89112+++ b/kernel/rcu/srcu.c
89113@@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89114
89115 idx = ACCESS_ONCE(sp->completed) & 0x1;
89116 preempt_disable();
89117- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89118+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89119 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89120- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89121+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89122 preempt_enable();
89123 return idx;
89124 }
89125diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89126index d9efcc1..ea543e9 100644
89127--- a/kernel/rcu/tiny.c
89128+++ b/kernel/rcu/tiny.c
89129@@ -42,7 +42,7 @@
89130 /* Forward declarations for tiny_plugin.h. */
89131 struct rcu_ctrlblk;
89132 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89133-static void rcu_process_callbacks(struct softirq_action *unused);
89134+static void rcu_process_callbacks(void);
89135 static void __call_rcu(struct rcu_head *head,
89136 void (*func)(struct rcu_head *rcu),
89137 struct rcu_ctrlblk *rcp);
89138@@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89139 false));
89140 }
89141
89142-static void rcu_process_callbacks(struct softirq_action *unused)
89143+static __latent_entropy void rcu_process_callbacks(void)
89144 {
89145 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89146 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89147diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89148index 0c47e30..a084591 100644
89149--- a/kernel/rcu/tree.c
89150+++ b/kernel/rcu/tree.c
89151@@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89152 rcu_prepare_for_idle(smp_processor_id());
89153 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89154 smp_mb__before_atomic_inc(); /* See above. */
89155- atomic_inc(&rdtp->dynticks);
89156+ atomic_inc_unchecked(&rdtp->dynticks);
89157 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89158- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89159+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89160
89161 /*
89162 * It is illegal to enter an extended quiescent state while
89163@@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89164 int user)
89165 {
89166 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89167- atomic_inc(&rdtp->dynticks);
89168+ atomic_inc_unchecked(&rdtp->dynticks);
89169 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89170 smp_mb__after_atomic_inc(); /* See above. */
89171- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89172+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89173 rcu_cleanup_after_idle(smp_processor_id());
89174 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89175 if (!user && !is_idle_task(current)) {
89176@@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89177 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89178
89179 if (rdtp->dynticks_nmi_nesting == 0 &&
89180- (atomic_read(&rdtp->dynticks) & 0x1))
89181+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89182 return;
89183 rdtp->dynticks_nmi_nesting++;
89184 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89185- atomic_inc(&rdtp->dynticks);
89186+ atomic_inc_unchecked(&rdtp->dynticks);
89187 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89188 smp_mb__after_atomic_inc(); /* See above. */
89189- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89190+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89191 }
89192
89193 /**
89194@@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89195 return;
89196 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89197 smp_mb__before_atomic_inc(); /* See above. */
89198- atomic_inc(&rdtp->dynticks);
89199+ atomic_inc_unchecked(&rdtp->dynticks);
89200 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89201- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89202+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89203 }
89204
89205 /**
89206@@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89207 */
89208 bool notrace __rcu_is_watching(void)
89209 {
89210- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89211+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89212 }
89213
89214 /**
89215@@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89216 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89217 bool *isidle, unsigned long *maxj)
89218 {
89219- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89220+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89221 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89222 return (rdp->dynticks_snap & 0x1) == 0;
89223 }
89224@@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89225 unsigned int curr;
89226 unsigned int snap;
89227
89228- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89229+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89230 snap = (unsigned int)rdp->dynticks_snap;
89231
89232 /*
89233@@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89234 rdp = this_cpu_ptr(rsp->rda);
89235 rcu_preempt_check_blocked_tasks(rnp);
89236 rnp->qsmask = rnp->qsmaskinit;
89237- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89238+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89239 WARN_ON_ONCE(rnp->completed != rsp->completed);
89240- ACCESS_ONCE(rnp->completed) = rsp->completed;
89241+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89242 if (rnp == rdp->mynode)
89243 __note_gp_changes(rsp, rnp, rdp);
89244 rcu_preempt_boost_start_gp(rnp);
89245@@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89246 rcu_for_each_node_breadth_first(rsp, rnp) {
89247 raw_spin_lock_irq(&rnp->lock);
89248 smp_mb__after_unlock_lock();
89249- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89250+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89251 rdp = this_cpu_ptr(rsp->rda);
89252 if (rnp == rdp->mynode)
89253 __note_gp_changes(rsp, rnp, rdp);
89254@@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89255 rcu_nocb_gp_set(rnp, nocb);
89256
89257 /* Declare grace period done. */
89258- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89259+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89260 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89261 rsp->fqs_state = RCU_GP_IDLE;
89262 rdp = this_cpu_ptr(rsp->rda);
89263@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89264 rsp->qlen += rdp->qlen;
89265 rdp->n_cbs_orphaned += rdp->qlen;
89266 rdp->qlen_lazy = 0;
89267- ACCESS_ONCE(rdp->qlen) = 0;
89268+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89269 }
89270
89271 /*
89272@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89273 }
89274 smp_mb(); /* List handling before counting for rcu_barrier(). */
89275 rdp->qlen_lazy -= count_lazy;
89276- ACCESS_ONCE(rdp->qlen) -= count;
89277+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89278 rdp->n_cbs_invoked += count;
89279
89280 /* Reinstate batch limit if we have worked down the excess. */
89281@@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89282 if (rnp_old != NULL)
89283 raw_spin_unlock(&rnp_old->fqslock);
89284 if (ret) {
89285- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89286+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89287 return;
89288 }
89289 rnp_old = rnp;
89290@@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89291 smp_mb__after_unlock_lock();
89292 raw_spin_unlock(&rnp_old->fqslock);
89293 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89294- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89295+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89296 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89297 return; /* Someone beat us to it. */
89298 }
89299@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89300 /*
89301 * Do RCU core processing for the current CPU.
89302 */
89303-static void rcu_process_callbacks(struct softirq_action *unused)
89304+static void rcu_process_callbacks(void)
89305 {
89306 struct rcu_state *rsp;
89307
89308@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89309 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89310 if (debug_rcu_head_queue(head)) {
89311 /* Probable double call_rcu(), so leak the callback. */
89312- ACCESS_ONCE(head->func) = rcu_leak_callback;
89313+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89314 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89315 return;
89316 }
89317@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89318 local_irq_restore(flags);
89319 return;
89320 }
89321- ACCESS_ONCE(rdp->qlen)++;
89322+ ACCESS_ONCE_RW(rdp->qlen)++;
89323 if (lazy)
89324 rdp->qlen_lazy++;
89325 else
89326@@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89327 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89328 * course be required on a 64-bit system.
89329 */
89330- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89331+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89332 (ulong)atomic_long_read(&rsp->expedited_done) +
89333 ULONG_MAX / 8)) {
89334 synchronize_sched();
89335- atomic_long_inc(&rsp->expedited_wrap);
89336+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
89337 return;
89338 }
89339
89340@@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
89341 * Take a ticket. Note that atomic_inc_return() implies a
89342 * full memory barrier.
89343 */
89344- snap = atomic_long_inc_return(&rsp->expedited_start);
89345+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89346 firstsnap = snap;
89347 get_online_cpus();
89348 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89349@@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
89350 synchronize_sched_expedited_cpu_stop,
89351 NULL) == -EAGAIN) {
89352 put_online_cpus();
89353- atomic_long_inc(&rsp->expedited_tryfail);
89354+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89355
89356 /* Check to see if someone else did our work for us. */
89357 s = atomic_long_read(&rsp->expedited_done);
89358 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89359 /* ensure test happens before caller kfree */
89360 smp_mb__before_atomic_inc(); /* ^^^ */
89361- atomic_long_inc(&rsp->expedited_workdone1);
89362+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89363 return;
89364 }
89365
89366@@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
89367 udelay(trycount * num_online_cpus());
89368 } else {
89369 wait_rcu_gp(call_rcu_sched);
89370- atomic_long_inc(&rsp->expedited_normal);
89371+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89372 return;
89373 }
89374
89375@@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
89376 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89377 /* ensure test happens before caller kfree */
89378 smp_mb__before_atomic_inc(); /* ^^^ */
89379- atomic_long_inc(&rsp->expedited_workdone2);
89380+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89381 return;
89382 }
89383
89384@@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
89385 * period works for us.
89386 */
89387 get_online_cpus();
89388- snap = atomic_long_read(&rsp->expedited_start);
89389+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89390 smp_mb(); /* ensure read is before try_stop_cpus(). */
89391 }
89392- atomic_long_inc(&rsp->expedited_stoppedcpus);
89393+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89394
89395 /*
89396 * Everyone up to our most recent fetch is covered by our grace
89397@@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
89398 * than we did already did their update.
89399 */
89400 do {
89401- atomic_long_inc(&rsp->expedited_done_tries);
89402+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89403 s = atomic_long_read(&rsp->expedited_done);
89404 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89405 /* ensure test happens before caller kfree */
89406 smp_mb__before_atomic_inc(); /* ^^^ */
89407- atomic_long_inc(&rsp->expedited_done_lost);
89408+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89409 break;
89410 }
89411 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89412- atomic_long_inc(&rsp->expedited_done_exit);
89413+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89414
89415 put_online_cpus();
89416 }
89417@@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89418 * ACCESS_ONCE() to prevent the compiler from speculating
89419 * the increment to precede the early-exit check.
89420 */
89421- ACCESS_ONCE(rsp->n_barrier_done)++;
89422+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89423 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89424 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89425 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89426@@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89427
89428 /* Increment ->n_barrier_done to prevent duplicate work. */
89429 smp_mb(); /* Keep increment after above mechanism. */
89430- ACCESS_ONCE(rsp->n_barrier_done)++;
89431+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89432 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89433 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89434 smp_mb(); /* Keep increment before caller's subsequent code. */
89435@@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89436 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89437 init_callback_list(rdp);
89438 rdp->qlen_lazy = 0;
89439- ACCESS_ONCE(rdp->qlen) = 0;
89440+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89441 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89442 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89443- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89444+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89445 rdp->cpu = cpu;
89446 rdp->rsp = rsp;
89447 rcu_boot_init_nocb_percpu_data(rdp);
89448@@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89449 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89450 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89451 rcu_sysidle_init_percpu_data(rdp->dynticks);
89452- atomic_set(&rdp->dynticks->dynticks,
89453- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89454+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89455+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89456 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89457
89458 /* Add CPU to rcu_node bitmasks. */
89459diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89460index 75dc3c3..b95d624 100644
89461--- a/kernel/rcu/tree.h
89462+++ b/kernel/rcu/tree.h
89463@@ -87,11 +87,11 @@ struct rcu_dynticks {
89464 long long dynticks_nesting; /* Track irq/process nesting level. */
89465 /* Process level is worth LLONG_MAX/2. */
89466 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89467- atomic_t dynticks; /* Even value for idle, else odd. */
89468+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89469 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89470 long long dynticks_idle_nesting;
89471 /* irq/process nesting level from idle. */
89472- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89473+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89474 /* "Idle" excludes userspace execution. */
89475 unsigned long dynticks_idle_jiffies;
89476 /* End of last non-NMI non-idle period. */
89477@@ -431,17 +431,17 @@ struct rcu_state {
89478 /* _rcu_barrier(). */
89479 /* End of fields guarded by barrier_mutex. */
89480
89481- atomic_long_t expedited_start; /* Starting ticket. */
89482- atomic_long_t expedited_done; /* Done ticket. */
89483- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89484- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89485- atomic_long_t expedited_workdone1; /* # done by others #1. */
89486- atomic_long_t expedited_workdone2; /* # done by others #2. */
89487- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89488- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89489- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89490- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89491- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89492+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89493+ atomic_long_t expedited_done; /* Done ticket. */
89494+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89495+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89496+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89497+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89498+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89499+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89500+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89501+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89502+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89503
89504 unsigned long jiffies_force_qs; /* Time at which to invoke */
89505 /* force_quiescent_state(). */
89506diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89507index 962d1d5..c6c62d12d 100644
89508--- a/kernel/rcu/tree_plugin.h
89509+++ b/kernel/rcu/tree_plugin.h
89510@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89511 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89512 {
89513 return !rcu_preempted_readers_exp(rnp) &&
89514- ACCESS_ONCE(rnp->expmask) == 0;
89515+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89516 }
89517
89518 /*
89519@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89520
89521 /* Clean up and exit. */
89522 smp_mb(); /* ensure expedited GP seen before counter increment. */
89523- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89524+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89525 unlock_mb_ret:
89526 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89527 mb_ret:
89528@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89529 free_cpumask_var(cm);
89530 }
89531
89532-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89533+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89534 .store = &rcu_cpu_kthread_task,
89535 .thread_should_run = rcu_cpu_kthread_should_run,
89536 .thread_fn = rcu_cpu_kthread,
89537@@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89538 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89539 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89540 cpu, ticks_value, ticks_title,
89541- atomic_read(&rdtp->dynticks) & 0xfff,
89542+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89543 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89544 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89545 fast_no_hz);
89546@@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89547
89548 /* Enqueue the callback on the nocb list and update counts. */
89549 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89550- ACCESS_ONCE(*old_rhpp) = rhp;
89551+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89552 atomic_long_add(rhcount, &rdp->nocb_q_count);
89553 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89554
89555@@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
89556 * Extract queued callbacks, update counts, and wait
89557 * for a grace period to elapse.
89558 */
89559- ACCESS_ONCE(rdp->nocb_head) = NULL;
89560+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89561 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89562 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89563 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89564- ACCESS_ONCE(rdp->nocb_p_count) += c;
89565- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89566+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89567+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89568 rcu_nocb_wait_gp(rdp);
89569
89570 /* Each pass through the following loop invokes a callback. */
89571@@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
89572 list = next;
89573 }
89574 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89575- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89576- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89577+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89578+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89579 rdp->n_nocbs_invoked += c;
89580 }
89581 return 0;
89582@@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89583 {
89584 if (!rcu_nocb_need_deferred_wakeup(rdp))
89585 return;
89586- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89587+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89588 wake_up(&rdp->nocb_wq);
89589 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89590 }
89591@@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89592 t = kthread_run(rcu_nocb_kthread, rdp,
89593 "rcuo%c/%d", rsp->abbr, cpu);
89594 BUG_ON(IS_ERR(t));
89595- ACCESS_ONCE(rdp->nocb_kthread) = t;
89596+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89597 }
89598 }
89599
89600@@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89601
89602 /* Record start of fully idle period. */
89603 j = jiffies;
89604- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89605+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89606 smp_mb__before_atomic_inc();
89607- atomic_inc(&rdtp->dynticks_idle);
89608+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89609 smp_mb__after_atomic_inc();
89610- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89611+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89612 }
89613
89614 /*
89615@@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89616
89617 /* Record end of idle period. */
89618 smp_mb__before_atomic_inc();
89619- atomic_inc(&rdtp->dynticks_idle);
89620+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89621 smp_mb__after_atomic_inc();
89622- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89623+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89624
89625 /*
89626 * If we are the timekeeping CPU, we are permitted to be non-idle
89627@@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89628 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89629
89630 /* Pick up current idle and NMI-nesting counter and check. */
89631- cur = atomic_read(&rdtp->dynticks_idle);
89632+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89633 if (cur & 0x1) {
89634 *isidle = false; /* We are not idle! */
89635 return;
89636@@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
89637 case RCU_SYSIDLE_NOT:
89638
89639 /* First time all are idle, so note a short idle period. */
89640- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89641+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89642 break;
89643
89644 case RCU_SYSIDLE_SHORT:
89645@@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
89646 static void rcu_sysidle_cancel(void)
89647 {
89648 smp_mb();
89649- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89650+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89651 }
89652
89653 /*
89654@@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89655 smp_mb(); /* grace period precedes setting inuse. */
89656
89657 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89658- ACCESS_ONCE(rshp->inuse) = 0;
89659+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89660 }
89661
89662 /*
89663diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89664index 5cdc62e..cc52e88 100644
89665--- a/kernel/rcu/tree_trace.c
89666+++ b/kernel/rcu/tree_trace.c
89667@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89668 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89669 rdp->passed_quiesce, rdp->qs_pending);
89670 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89671- atomic_read(&rdp->dynticks->dynticks),
89672+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89673 rdp->dynticks->dynticks_nesting,
89674 rdp->dynticks->dynticks_nmi_nesting,
89675 rdp->dynticks_fqs);
89676@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89677 struct rcu_state *rsp = (struct rcu_state *)m->private;
89678
89679 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",
89680- atomic_long_read(&rsp->expedited_start),
89681+ atomic_long_read_unchecked(&rsp->expedited_start),
89682 atomic_long_read(&rsp->expedited_done),
89683- atomic_long_read(&rsp->expedited_wrap),
89684- atomic_long_read(&rsp->expedited_tryfail),
89685- atomic_long_read(&rsp->expedited_workdone1),
89686- atomic_long_read(&rsp->expedited_workdone2),
89687- atomic_long_read(&rsp->expedited_normal),
89688- atomic_long_read(&rsp->expedited_stoppedcpus),
89689- atomic_long_read(&rsp->expedited_done_tries),
89690- atomic_long_read(&rsp->expedited_done_lost),
89691- atomic_long_read(&rsp->expedited_done_exit));
89692+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89693+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89694+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89695+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89696+ atomic_long_read_unchecked(&rsp->expedited_normal),
89697+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89698+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89699+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89700+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89701 return 0;
89702 }
89703
89704diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89705index 4c0a9b0..7e81362 100644
89706--- a/kernel/rcu/update.c
89707+++ b/kernel/rcu/update.c
89708@@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
89709 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89710 */
89711 if (till_stall_check < 3) {
89712- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89713+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89714 till_stall_check = 3;
89715 } else if (till_stall_check > 300) {
89716- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89717+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89718 till_stall_check = 300;
89719 }
89720 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89721diff --git a/kernel/resource.c b/kernel/resource.c
89722index 8957d68..770cbe4 100644
89723--- a/kernel/resource.c
89724+++ b/kernel/resource.c
89725@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89726
89727 static int __init ioresources_init(void)
89728 {
89729+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89730+#ifdef CONFIG_GRKERNSEC_PROC_USER
89731+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89732+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89733+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89734+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89735+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89736+#endif
89737+#else
89738 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89739 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89740+#endif
89741 return 0;
89742 }
89743 __initcall(ioresources_init);
89744diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89745index e73efba..c9bfbd4 100644
89746--- a/kernel/sched/auto_group.c
89747+++ b/kernel/sched/auto_group.c
89748@@ -11,7 +11,7 @@
89749
89750 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89751 static struct autogroup autogroup_default;
89752-static atomic_t autogroup_seq_nr;
89753+static atomic_unchecked_t autogroup_seq_nr;
89754
89755 void __init autogroup_init(struct task_struct *init_task)
89756 {
89757@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89758
89759 kref_init(&ag->kref);
89760 init_rwsem(&ag->lock);
89761- ag->id = atomic_inc_return(&autogroup_seq_nr);
89762+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89763 ag->tg = tg;
89764 #ifdef CONFIG_RT_GROUP_SCHED
89765 /*
89766diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89767index a63f4dc..349bbb0 100644
89768--- a/kernel/sched/completion.c
89769+++ b/kernel/sched/completion.c
89770@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89771 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89772 * or number of jiffies left till timeout) if completed.
89773 */
89774-long __sched
89775+long __sched __intentional_overflow(-1)
89776 wait_for_completion_interruptible_timeout(struct completion *x,
89777 unsigned long timeout)
89778 {
89779@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89780 *
89781 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89782 */
89783-int __sched wait_for_completion_killable(struct completion *x)
89784+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89785 {
89786 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89787 if (t == -ERESTARTSYS)
89788@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89789 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89790 * or number of jiffies left till timeout) if completed.
89791 */
89792-long __sched
89793+long __sched __intentional_overflow(-1)
89794 wait_for_completion_killable_timeout(struct completion *x,
89795 unsigned long timeout)
89796 {
89797diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89798index 084d17f..e416b9f 100644
89799--- a/kernel/sched/core.c
89800+++ b/kernel/sched/core.c
89801@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89802 int sysctl_numa_balancing(struct ctl_table *table, int write,
89803 void __user *buffer, size_t *lenp, loff_t *ppos)
89804 {
89805- struct ctl_table t;
89806+ ctl_table_no_const t;
89807 int err;
89808 int state = numabalancing_enabled;
89809
89810@@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
89811 next->active_mm = oldmm;
89812 atomic_inc(&oldmm->mm_count);
89813 enter_lazy_tlb(oldmm, next);
89814- } else
89815+ } else {
89816 switch_mm(oldmm, mm, next);
89817+ populate_stack();
89818+ }
89819
89820 if (!prev->mm) {
89821 prev->active_mm = NULL;
89822@@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
89823 /* convert nice value [19,-20] to rlimit style value [1,40] */
89824 int nice_rlim = 20 - nice;
89825
89826+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89827+
89828 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89829 capable(CAP_SYS_NICE));
89830 }
89831@@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89832 if (nice > MAX_NICE)
89833 nice = MAX_NICE;
89834
89835- if (increment < 0 && !can_nice(current, nice))
89836+ if (increment < 0 && (!can_nice(current, nice) ||
89837+ gr_handle_chroot_nice()))
89838 return -EPERM;
89839
89840 retval = security_task_setnice(current, nice);
89841@@ -3310,6 +3315,7 @@ recheck:
89842 if (policy != p->policy && !rlim_rtprio)
89843 return -EPERM;
89844
89845+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89846 /* can't increase priority */
89847 if (attr->sched_priority > p->rt_priority &&
89848 attr->sched_priority > rlim_rtprio)
89849@@ -4708,6 +4714,7 @@ void idle_task_exit(void)
89850
89851 if (mm != &init_mm) {
89852 switch_mm(mm, &init_mm, current);
89853+ populate_stack();
89854 finish_arch_post_lock_switch();
89855 }
89856 mmdrop(mm);
89857@@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89858
89859 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89860
89861-static struct ctl_table sd_ctl_dir[] = {
89862+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89863 {
89864 .procname = "sched_domain",
89865 .mode = 0555,
89866@@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
89867 {}
89868 };
89869
89870-static struct ctl_table *sd_alloc_ctl_entry(int n)
89871+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89872 {
89873- struct ctl_table *entry =
89874+ ctl_table_no_const *entry =
89875 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89876
89877 return entry;
89878 }
89879
89880-static void sd_free_ctl_entry(struct ctl_table **tablep)
89881+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89882 {
89883- struct ctl_table *entry;
89884+ ctl_table_no_const *entry;
89885
89886 /*
89887 * In the intermediate directories, both the child directory and
89888@@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89889 * will always be set. In the lowest directory the names are
89890 * static strings and all have proc handlers.
89891 */
89892- for (entry = *tablep; entry->mode; entry++) {
89893- if (entry->child)
89894- sd_free_ctl_entry(&entry->child);
89895+ for (entry = tablep; entry->mode; entry++) {
89896+ if (entry->child) {
89897+ sd_free_ctl_entry(entry->child);
89898+ pax_open_kernel();
89899+ entry->child = NULL;
89900+ pax_close_kernel();
89901+ }
89902 if (entry->proc_handler == NULL)
89903 kfree(entry->procname);
89904 }
89905
89906- kfree(*tablep);
89907- *tablep = NULL;
89908+ kfree(tablep);
89909 }
89910
89911 static int min_load_idx = 0;
89912 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89913
89914 static void
89915-set_table_entry(struct ctl_table *entry,
89916+set_table_entry(ctl_table_no_const *entry,
89917 const char *procname, void *data, int maxlen,
89918 umode_t mode, proc_handler *proc_handler,
89919 bool load_idx)
89920@@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
89921 static struct ctl_table *
89922 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89923 {
89924- struct ctl_table *table = sd_alloc_ctl_entry(14);
89925+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
89926
89927 if (table == NULL)
89928 return NULL;
89929@@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89930 return table;
89931 }
89932
89933-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89934+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89935 {
89936- struct ctl_table *entry, *table;
89937+ ctl_table_no_const *entry, *table;
89938 struct sched_domain *sd;
89939 int domain_num = 0, i;
89940 char buf[32];
89941@@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
89942 static void register_sched_domain_sysctl(void)
89943 {
89944 int i, cpu_num = num_possible_cpus();
89945- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89946+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89947 char buf[32];
89948
89949 WARN_ON(sd_ctl_dir[0].child);
89950+ pax_open_kernel();
89951 sd_ctl_dir[0].child = entry;
89952+ pax_close_kernel();
89953
89954 if (entry == NULL)
89955 return;
89956@@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
89957 if (sd_sysctl_header)
89958 unregister_sysctl_table(sd_sysctl_header);
89959 sd_sysctl_header = NULL;
89960- if (sd_ctl_dir[0].child)
89961- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89962+ if (sd_ctl_dir[0].child) {
89963+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89964+ pax_open_kernel();
89965+ sd_ctl_dir[0].child = NULL;
89966+ pax_close_kernel();
89967+ }
89968 }
89969 #else
89970 static void register_sched_domain_sysctl(void)
89971diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89972index 8cbe2d2..61f20a1 100644
89973--- a/kernel/sched/fair.c
89974+++ b/kernel/sched/fair.c
89975@@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
89976
89977 static void reset_ptenuma_scan(struct task_struct *p)
89978 {
89979- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89980+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89981 p->mm->numa_scan_offset = 0;
89982 }
89983
89984@@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89985 * run_rebalance_domains is triggered when needed from the scheduler tick.
89986 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89987 */
89988-static void run_rebalance_domains(struct softirq_action *h)
89989+static __latent_entropy void run_rebalance_domains(void)
89990 {
89991 struct rq *this_rq = this_rq();
89992 enum cpu_idle_type idle = this_rq->idle_balance ?
89993diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89994index 369b4d6..fa4eb3b 100644
89995--- a/kernel/sched/sched.h
89996+++ b/kernel/sched/sched.h
89997@@ -1157,7 +1157,7 @@ struct sched_class {
89998 #ifdef CONFIG_FAIR_GROUP_SCHED
89999 void (*task_move_group) (struct task_struct *p, int on_rq);
90000 #endif
90001-};
90002+} __do_const;
90003
90004 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
90005 {
90006diff --git a/kernel/signal.c b/kernel/signal.c
90007index 6ea13c0..31e3b25 100644
90008--- a/kernel/signal.c
90009+++ b/kernel/signal.c
90010@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
90011
90012 int print_fatal_signals __read_mostly;
90013
90014-static void __user *sig_handler(struct task_struct *t, int sig)
90015+static __sighandler_t sig_handler(struct task_struct *t, int sig)
90016 {
90017 return t->sighand->action[sig - 1].sa.sa_handler;
90018 }
90019
90020-static int sig_handler_ignored(void __user *handler, int sig)
90021+static int sig_handler_ignored(__sighandler_t handler, int sig)
90022 {
90023 /* Is it explicitly or implicitly ignored? */
90024 return handler == SIG_IGN ||
90025@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90026
90027 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90028 {
90029- void __user *handler;
90030+ __sighandler_t handler;
90031
90032 handler = sig_handler(t, sig);
90033
90034@@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90035 atomic_inc(&user->sigpending);
90036 rcu_read_unlock();
90037
90038+ if (!override_rlimit)
90039+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90040+
90041 if (override_rlimit ||
90042 atomic_read(&user->sigpending) <=
90043 task_rlimit(t, RLIMIT_SIGPENDING)) {
90044@@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90045
90046 int unhandled_signal(struct task_struct *tsk, int sig)
90047 {
90048- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90049+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90050 if (is_global_init(tsk))
90051 return 1;
90052 if (handler != SIG_IGN && handler != SIG_DFL)
90053@@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90054 }
90055 }
90056
90057+ /* allow glibc communication via tgkill to other threads in our
90058+ thread group */
90059+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90060+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90061+ && gr_handle_signal(t, sig))
90062+ return -EPERM;
90063+
90064 return security_task_kill(t, info, sig, 0);
90065 }
90066
90067@@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90068 return send_signal(sig, info, p, 1);
90069 }
90070
90071-static int
90072+int
90073 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90074 {
90075 return send_signal(sig, info, t, 0);
90076@@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90077 unsigned long int flags;
90078 int ret, blocked, ignored;
90079 struct k_sigaction *action;
90080+ int is_unhandled = 0;
90081
90082 spin_lock_irqsave(&t->sighand->siglock, flags);
90083 action = &t->sighand->action[sig-1];
90084@@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90085 }
90086 if (action->sa.sa_handler == SIG_DFL)
90087 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90088+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90089+ is_unhandled = 1;
90090 ret = specific_send_sig_info(sig, info, t);
90091 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90092
90093+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
90094+ normal operation */
90095+ if (is_unhandled) {
90096+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90097+ gr_handle_crash(t, sig);
90098+ }
90099+
90100 return ret;
90101 }
90102
90103@@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90104 ret = check_kill_permission(sig, info, p);
90105 rcu_read_unlock();
90106
90107- if (!ret && sig)
90108+ if (!ret && sig) {
90109 ret = do_send_sig_info(sig, info, p, true);
90110+ if (!ret)
90111+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90112+ }
90113
90114 return ret;
90115 }
90116@@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90117 int error = -ESRCH;
90118
90119 rcu_read_lock();
90120- p = find_task_by_vpid(pid);
90121+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90122+ /* allow glibc communication via tgkill to other threads in our
90123+ thread group */
90124+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90125+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90126+ p = find_task_by_vpid_unrestricted(pid);
90127+ else
90128+#endif
90129+ p = find_task_by_vpid(pid);
90130 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90131 error = check_kill_permission(sig, info, p);
90132 /*
90133@@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90134 }
90135 seg = get_fs();
90136 set_fs(KERNEL_DS);
90137- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90138- (stack_t __force __user *) &uoss,
90139+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90140+ (stack_t __force_user *) &uoss,
90141 compat_user_stack_pointer());
90142 set_fs(seg);
90143 if (ret >= 0 && uoss_ptr) {
90144diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90145index eb89e18..a4e6792 100644
90146--- a/kernel/smpboot.c
90147+++ b/kernel/smpboot.c
90148@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90149 }
90150 smpboot_unpark_thread(plug_thread, cpu);
90151 }
90152- list_add(&plug_thread->list, &hotplug_threads);
90153+ pax_list_add(&plug_thread->list, &hotplug_threads);
90154 out:
90155 mutex_unlock(&smpboot_threads_lock);
90156 return ret;
90157@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90158 {
90159 get_online_cpus();
90160 mutex_lock(&smpboot_threads_lock);
90161- list_del(&plug_thread->list);
90162+ pax_list_del(&plug_thread->list);
90163 smpboot_destroy_threads(plug_thread);
90164 mutex_unlock(&smpboot_threads_lock);
90165 put_online_cpus();
90166diff --git a/kernel/softirq.c b/kernel/softirq.c
90167index 92f24f5..db41501 100644
90168--- a/kernel/softirq.c
90169+++ b/kernel/softirq.c
90170@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90171 EXPORT_SYMBOL(irq_stat);
90172 #endif
90173
90174-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90175+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90176
90177 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90178
90179@@ -268,7 +268,7 @@ restart:
90180 kstat_incr_softirqs_this_cpu(vec_nr);
90181
90182 trace_softirq_entry(vec_nr);
90183- h->action(h);
90184+ h->action();
90185 trace_softirq_exit(vec_nr);
90186 if (unlikely(prev_count != preempt_count())) {
90187 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90188@@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90189 or_softirq_pending(1UL << nr);
90190 }
90191
90192-void open_softirq(int nr, void (*action)(struct softirq_action *))
90193+void __init open_softirq(int nr, void (*action)(void))
90194 {
90195 softirq_vec[nr].action = action;
90196 }
90197@@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90198 }
90199 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90200
90201-static void tasklet_action(struct softirq_action *a)
90202+static void tasklet_action(void)
90203 {
90204 struct tasklet_struct *list;
90205
90206@@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90207 }
90208 }
90209
90210-static void tasklet_hi_action(struct softirq_action *a)
90211+static __latent_entropy void tasklet_hi_action(void)
90212 {
90213 struct tasklet_struct *list;
90214
90215@@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90216 .notifier_call = cpu_callback
90217 };
90218
90219-static struct smp_hotplug_thread softirq_threads = {
90220+static struct smp_hotplug_thread softirq_threads __read_only = {
90221 .store = &ksoftirqd,
90222 .thread_should_run = ksoftirqd_should_run,
90223 .thread_fn = run_ksoftirqd,
90224diff --git a/kernel/sys.c b/kernel/sys.c
90225index fba0f29..84400e2 100644
90226--- a/kernel/sys.c
90227+++ b/kernel/sys.c
90228@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90229 error = -EACCES;
90230 goto out;
90231 }
90232+
90233+ if (gr_handle_chroot_setpriority(p, niceval)) {
90234+ error = -EACCES;
90235+ goto out;
90236+ }
90237+
90238 no_nice = security_task_setnice(p, niceval);
90239 if (no_nice) {
90240 error = no_nice;
90241@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90242 goto error;
90243 }
90244
90245+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90246+ goto error;
90247+
90248 if (rgid != (gid_t) -1 ||
90249 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90250 new->sgid = new->egid;
90251@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90252 old = current_cred();
90253
90254 retval = -EPERM;
90255+
90256+ if (gr_check_group_change(kgid, kgid, kgid))
90257+ goto error;
90258+
90259 if (ns_capable(old->user_ns, CAP_SETGID))
90260 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90261 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90262@@ -403,7 +416,7 @@ error:
90263 /*
90264 * change the user struct in a credentials set to match the new UID
90265 */
90266-static int set_user(struct cred *new)
90267+int set_user(struct cred *new)
90268 {
90269 struct user_struct *new_user;
90270
90271@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90272 goto error;
90273 }
90274
90275+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90276+ goto error;
90277+
90278 if (!uid_eq(new->uid, old->uid)) {
90279 retval = set_user(new);
90280 if (retval < 0)
90281@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90282 old = current_cred();
90283
90284 retval = -EPERM;
90285+
90286+ if (gr_check_crash_uid(kuid))
90287+ goto error;
90288+ if (gr_check_user_change(kuid, kuid, kuid))
90289+ goto error;
90290+
90291 if (ns_capable(old->user_ns, CAP_SETUID)) {
90292 new->suid = new->uid = kuid;
90293 if (!uid_eq(kuid, old->uid)) {
90294@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90295 goto error;
90296 }
90297
90298+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90299+ goto error;
90300+
90301 if (ruid != (uid_t) -1) {
90302 new->uid = kruid;
90303 if (!uid_eq(kruid, old->uid)) {
90304@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90305 goto error;
90306 }
90307
90308+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90309+ goto error;
90310+
90311 if (rgid != (gid_t) -1)
90312 new->gid = krgid;
90313 if (egid != (gid_t) -1)
90314@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90315 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90316 ns_capable(old->user_ns, CAP_SETUID)) {
90317 if (!uid_eq(kuid, old->fsuid)) {
90318+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90319+ goto error;
90320+
90321 new->fsuid = kuid;
90322 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90323 goto change_okay;
90324 }
90325 }
90326
90327+error:
90328 abort_creds(new);
90329 return old_fsuid;
90330
90331@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90332 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90333 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90334 ns_capable(old->user_ns, CAP_SETGID)) {
90335+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90336+ goto error;
90337+
90338 if (!gid_eq(kgid, old->fsgid)) {
90339 new->fsgid = kgid;
90340 goto change_okay;
90341 }
90342 }
90343
90344+error:
90345 abort_creds(new);
90346 return old_fsgid;
90347
90348@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90349 return -EFAULT;
90350
90351 down_read(&uts_sem);
90352- error = __copy_to_user(&name->sysname, &utsname()->sysname,
90353+ error = __copy_to_user(name->sysname, &utsname()->sysname,
90354 __OLD_UTS_LEN);
90355 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90356- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90357+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
90358 __OLD_UTS_LEN);
90359 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90360- error |= __copy_to_user(&name->release, &utsname()->release,
90361+ error |= __copy_to_user(name->release, &utsname()->release,
90362 __OLD_UTS_LEN);
90363 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90364- error |= __copy_to_user(&name->version, &utsname()->version,
90365+ error |= __copy_to_user(name->version, &utsname()->version,
90366 __OLD_UTS_LEN);
90367 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90368- error |= __copy_to_user(&name->machine, &utsname()->machine,
90369+ error |= __copy_to_user(name->machine, &utsname()->machine,
90370 __OLD_UTS_LEN);
90371 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90372 up_read(&uts_sem);
90373@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90374 */
90375 new_rlim->rlim_cur = 1;
90376 }
90377+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90378+ is changed to a lower value. Since tasks can be created by the same
90379+ user in between this limit change and an execve by this task, force
90380+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90381+ */
90382+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90383+ tsk->flags |= PF_NPROC_EXCEEDED;
90384 }
90385 if (!retval) {
90386 if (old_rlim)
90387diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90388index 74f5b58..65ba165 100644
90389--- a/kernel/sysctl.c
90390+++ b/kernel/sysctl.c
90391@@ -94,7 +94,6 @@
90392
90393
90394 #if defined(CONFIG_SYSCTL)
90395-
90396 /* External variables not in a header file. */
90397 extern int max_threads;
90398 extern int suid_dumpable;
90399@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
90400
90401 /* Constants used for minimum and maximum */
90402 #ifdef CONFIG_LOCKUP_DETECTOR
90403-static int sixty = 60;
90404+static int sixty __read_only = 60;
90405 #endif
90406
90407-static int __maybe_unused neg_one = -1;
90408+static int __maybe_unused neg_one __read_only = -1;
90409
90410-static int zero;
90411-static int __maybe_unused one = 1;
90412-static int __maybe_unused two = 2;
90413-static int __maybe_unused four = 4;
90414-static unsigned long one_ul = 1;
90415-static int one_hundred = 100;
90416+static int zero __read_only = 0;
90417+static int __maybe_unused one __read_only = 1;
90418+static int __maybe_unused two __read_only = 2;
90419+static int __maybe_unused three __read_only = 3;
90420+static int __maybe_unused four __read_only = 4;
90421+static unsigned long one_ul __read_only = 1;
90422+static int one_hundred __read_only = 100;
90423 #ifdef CONFIG_PRINTK
90424-static int ten_thousand = 10000;
90425+static int ten_thousand __read_only = 10000;
90426 #endif
90427
90428 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90429@@ -179,10 +179,8 @@ static int proc_taint(struct ctl_table *table, int write,
90430 void __user *buffer, size_t *lenp, loff_t *ppos);
90431 #endif
90432
90433-#ifdef CONFIG_PRINTK
90434 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90435 void __user *buffer, size_t *lenp, loff_t *ppos);
90436-#endif
90437
90438 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90439 void __user *buffer, size_t *lenp, loff_t *ppos);
90440@@ -213,6 +211,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90441
90442 #endif
90443
90444+extern struct ctl_table grsecurity_table[];
90445+
90446 static struct ctl_table kern_table[];
90447 static struct ctl_table vm_table[];
90448 static struct ctl_table fs_table[];
90449@@ -227,6 +227,20 @@ extern struct ctl_table epoll_table[];
90450 int sysctl_legacy_va_layout;
90451 #endif
90452
90453+#ifdef CONFIG_PAX_SOFTMODE
90454+static ctl_table pax_table[] = {
90455+ {
90456+ .procname = "softmode",
90457+ .data = &pax_softmode,
90458+ .maxlen = sizeof(unsigned int),
90459+ .mode = 0600,
90460+ .proc_handler = &proc_dointvec,
90461+ },
90462+
90463+ { }
90464+};
90465+#endif
90466+
90467 /* The default sysctl tables: */
90468
90469 static struct ctl_table sysctl_base_table[] = {
90470@@ -275,6 +289,22 @@ static int max_extfrag_threshold = 1000;
90471 #endif
90472
90473 static struct ctl_table kern_table[] = {
90474+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90475+ {
90476+ .procname = "grsecurity",
90477+ .mode = 0500,
90478+ .child = grsecurity_table,
90479+ },
90480+#endif
90481+
90482+#ifdef CONFIG_PAX_SOFTMODE
90483+ {
90484+ .procname = "pax",
90485+ .mode = 0500,
90486+ .child = pax_table,
90487+ },
90488+#endif
90489+
90490 {
90491 .procname = "sched_child_runs_first",
90492 .data = &sysctl_sched_child_runs_first,
90493@@ -630,7 +660,7 @@ static struct ctl_table kern_table[] = {
90494 .data = &modprobe_path,
90495 .maxlen = KMOD_PATH_LEN,
90496 .mode = 0644,
90497- .proc_handler = proc_dostring,
90498+ .proc_handler = proc_dostring_modpriv,
90499 },
90500 {
90501 .procname = "modules_disabled",
90502@@ -797,16 +827,20 @@ static struct ctl_table kern_table[] = {
90503 .extra1 = &zero,
90504 .extra2 = &one,
90505 },
90506+#endif
90507 {
90508 .procname = "kptr_restrict",
90509 .data = &kptr_restrict,
90510 .maxlen = sizeof(int),
90511 .mode = 0644,
90512 .proc_handler = proc_dointvec_minmax_sysadmin,
90513+#ifdef CONFIG_GRKERNSEC_HIDESYM
90514+ .extra1 = &two,
90515+#else
90516 .extra1 = &zero,
90517+#endif
90518 .extra2 = &two,
90519 },
90520-#endif
90521 {
90522 .procname = "ngroups_max",
90523 .data = &ngroups_max,
90524@@ -1051,10 +1085,17 @@ static struct ctl_table kern_table[] = {
90525 */
90526 {
90527 .procname = "perf_event_paranoid",
90528- .data = &sysctl_perf_event_paranoid,
90529- .maxlen = sizeof(sysctl_perf_event_paranoid),
90530+ .data = &sysctl_perf_event_legitimately_concerned,
90531+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90532 .mode = 0644,
90533- .proc_handler = proc_dointvec,
90534+ /* go ahead, be a hero */
90535+ .proc_handler = proc_dointvec_minmax_sysadmin,
90536+ .extra1 = &neg_one,
90537+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90538+ .extra2 = &three,
90539+#else
90540+ .extra2 = &two,
90541+#endif
90542 },
90543 {
90544 .procname = "perf_event_mlock_kb",
90545@@ -1316,6 +1357,13 @@ static struct ctl_table vm_table[] = {
90546 .proc_handler = proc_dointvec_minmax,
90547 .extra1 = &zero,
90548 },
90549+ {
90550+ .procname = "heap_stack_gap",
90551+ .data = &sysctl_heap_stack_gap,
90552+ .maxlen = sizeof(sysctl_heap_stack_gap),
90553+ .mode = 0644,
90554+ .proc_handler = proc_doulongvec_minmax,
90555+ },
90556 #else
90557 {
90558 .procname = "nr_trim_pages",
90559@@ -1780,6 +1828,16 @@ int proc_dostring(struct ctl_table *table, int write,
90560 buffer, lenp, ppos);
90561 }
90562
90563+int proc_dostring_modpriv(struct ctl_table *table, int write,
90564+ void __user *buffer, size_t *lenp, loff_t *ppos)
90565+{
90566+ if (write && !capable(CAP_SYS_MODULE))
90567+ return -EPERM;
90568+
90569+ return _proc_do_string(table->data, table->maxlen, write,
90570+ buffer, lenp, ppos);
90571+}
90572+
90573 static size_t proc_skip_spaces(char **buf)
90574 {
90575 size_t ret;
90576@@ -1885,6 +1943,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90577 len = strlen(tmp);
90578 if (len > *size)
90579 len = *size;
90580+ if (len > sizeof(tmp))
90581+ len = sizeof(tmp);
90582 if (copy_to_user(*buf, tmp, len))
90583 return -EFAULT;
90584 *size -= len;
90585@@ -2049,7 +2109,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90586 static int proc_taint(struct ctl_table *table, int write,
90587 void __user *buffer, size_t *lenp, loff_t *ppos)
90588 {
90589- struct ctl_table t;
90590+ ctl_table_no_const t;
90591 unsigned long tmptaint = get_taint();
90592 int err;
90593
90594@@ -2077,7 +2137,6 @@ static int proc_taint(struct ctl_table *table, int write,
90595 return err;
90596 }
90597
90598-#ifdef CONFIG_PRINTK
90599 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90600 void __user *buffer, size_t *lenp, loff_t *ppos)
90601 {
90602@@ -2086,7 +2145,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90603
90604 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90605 }
90606-#endif
90607
90608 struct do_proc_dointvec_minmax_conv_param {
90609 int *min;
90610@@ -2633,6 +2691,12 @@ int proc_dostring(struct ctl_table *table, int write,
90611 return -ENOSYS;
90612 }
90613
90614+int proc_dostring_modpriv(struct ctl_table *table, int write,
90615+ void __user *buffer, size_t *lenp, loff_t *ppos)
90616+{
90617+ return -ENOSYS;
90618+}
90619+
90620 int proc_dointvec(struct ctl_table *table, int write,
90621 void __user *buffer, size_t *lenp, loff_t *ppos)
90622 {
90623@@ -2689,5 +2753,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90624 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90625 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90626 EXPORT_SYMBOL(proc_dostring);
90627+EXPORT_SYMBOL(proc_dostring_modpriv);
90628 EXPORT_SYMBOL(proc_doulongvec_minmax);
90629 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90630diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90631index 13d2f7c..c93d0b0 100644
90632--- a/kernel/taskstats.c
90633+++ b/kernel/taskstats.c
90634@@ -28,9 +28,12 @@
90635 #include <linux/fs.h>
90636 #include <linux/file.h>
90637 #include <linux/pid_namespace.h>
90638+#include <linux/grsecurity.h>
90639 #include <net/genetlink.h>
90640 #include <linux/atomic.h>
90641
90642+extern int gr_is_taskstats_denied(int pid);
90643+
90644 /*
90645 * Maximum length of a cpumask that can be specified in
90646 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90647@@ -576,6 +579,9 @@ err:
90648
90649 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90650 {
90651+ if (gr_is_taskstats_denied(current->pid))
90652+ return -EACCES;
90653+
90654 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90655 return cmd_attr_register_cpumask(info);
90656 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90657diff --git a/kernel/time.c b/kernel/time.c
90658index 7c7964c..2a0d412 100644
90659--- a/kernel/time.c
90660+++ b/kernel/time.c
90661@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90662 return error;
90663
90664 if (tz) {
90665+ /* we log in do_settimeofday called below, so don't log twice
90666+ */
90667+ if (!tv)
90668+ gr_log_timechange();
90669+
90670 sys_tz = *tz;
90671 update_vsyscall_tz();
90672 if (firsttime) {
90673diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90674index 88c9c65..7497ebc 100644
90675--- a/kernel/time/alarmtimer.c
90676+++ b/kernel/time/alarmtimer.c
90677@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90678 struct platform_device *pdev;
90679 int error = 0;
90680 int i;
90681- struct k_clock alarm_clock = {
90682+ static struct k_clock alarm_clock = {
90683 .clock_getres = alarm_clock_getres,
90684 .clock_get = alarm_clock_get,
90685 .timer_create = alarm_timer_create,
90686diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90687index f7df8ea..0810193 100644
90688--- a/kernel/time/timekeeping.c
90689+++ b/kernel/time/timekeeping.c
90690@@ -15,6 +15,7 @@
90691 #include <linux/init.h>
90692 #include <linux/mm.h>
90693 #include <linux/sched.h>
90694+#include <linux/grsecurity.h>
90695 #include <linux/syscore_ops.h>
90696 #include <linux/clocksource.h>
90697 #include <linux/jiffies.h>
90698@@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
90699 if (!timespec_valid_strict(tv))
90700 return -EINVAL;
90701
90702+ gr_log_timechange();
90703+
90704 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90705 write_seqcount_begin(&timekeeper_seq);
90706
90707diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90708index 61ed862..3b52c65 100644
90709--- a/kernel/time/timer_list.c
90710+++ b/kernel/time/timer_list.c
90711@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90712
90713 static void print_name_offset(struct seq_file *m, void *sym)
90714 {
90715+#ifdef CONFIG_GRKERNSEC_HIDESYM
90716+ SEQ_printf(m, "<%p>", NULL);
90717+#else
90718 char symname[KSYM_NAME_LEN];
90719
90720 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90721 SEQ_printf(m, "<%pK>", sym);
90722 else
90723 SEQ_printf(m, "%s", symname);
90724+#endif
90725 }
90726
90727 static void
90728@@ -119,7 +123,11 @@ next_one:
90729 static void
90730 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90731 {
90732+#ifdef CONFIG_GRKERNSEC_HIDESYM
90733+ SEQ_printf(m, " .base: %p\n", NULL);
90734+#else
90735 SEQ_printf(m, " .base: %pK\n", base);
90736+#endif
90737 SEQ_printf(m, " .index: %d\n",
90738 base->index);
90739 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90740@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90741 {
90742 struct proc_dir_entry *pe;
90743
90744+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90745+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90746+#else
90747 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90748+#endif
90749 if (!pe)
90750 return -ENOMEM;
90751 return 0;
90752diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90753index 1fb08f2..ca4bb1e 100644
90754--- a/kernel/time/timer_stats.c
90755+++ b/kernel/time/timer_stats.c
90756@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90757 static unsigned long nr_entries;
90758 static struct entry entries[MAX_ENTRIES];
90759
90760-static atomic_t overflow_count;
90761+static atomic_unchecked_t overflow_count;
90762
90763 /*
90764 * The entries are in a hash-table, for fast lookup:
90765@@ -140,7 +140,7 @@ static void reset_entries(void)
90766 nr_entries = 0;
90767 memset(entries, 0, sizeof(entries));
90768 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90769- atomic_set(&overflow_count, 0);
90770+ atomic_set_unchecked(&overflow_count, 0);
90771 }
90772
90773 static struct entry *alloc_entry(void)
90774@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90775 if (likely(entry))
90776 entry->count++;
90777 else
90778- atomic_inc(&overflow_count);
90779+ atomic_inc_unchecked(&overflow_count);
90780
90781 out_unlock:
90782 raw_spin_unlock_irqrestore(lock, flags);
90783@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90784
90785 static void print_name_offset(struct seq_file *m, unsigned long addr)
90786 {
90787+#ifdef CONFIG_GRKERNSEC_HIDESYM
90788+ seq_printf(m, "<%p>", NULL);
90789+#else
90790 char symname[KSYM_NAME_LEN];
90791
90792 if (lookup_symbol_name(addr, symname) < 0)
90793- seq_printf(m, "<%p>", (void *)addr);
90794+ seq_printf(m, "<%pK>", (void *)addr);
90795 else
90796 seq_printf(m, "%s", symname);
90797+#endif
90798 }
90799
90800 static int tstats_show(struct seq_file *m, void *v)
90801@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90802
90803 seq_puts(m, "Timer Stats Version: v0.3\n");
90804 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90805- if (atomic_read(&overflow_count))
90806- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90807+ if (atomic_read_unchecked(&overflow_count))
90808+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90809 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90810
90811 for (i = 0; i < nr_entries; i++) {
90812@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90813 {
90814 struct proc_dir_entry *pe;
90815
90816+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90817+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90818+#else
90819 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90820+#endif
90821 if (!pe)
90822 return -ENOMEM;
90823 return 0;
90824diff --git a/kernel/timer.c b/kernel/timer.c
90825index 3bb01a3..0e7760e 100644
90826--- a/kernel/timer.c
90827+++ b/kernel/timer.c
90828@@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
90829 /*
90830 * This function runs timers and the timer-tq in bottom half context.
90831 */
90832-static void run_timer_softirq(struct softirq_action *h)
90833+static __latent_entropy void run_timer_softirq(void)
90834 {
90835 struct tvec_base *base = __this_cpu_read(tvec_bases);
90836
90837@@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
90838 *
90839 * In all cases the return value is guaranteed to be non-negative.
90840 */
90841-signed long __sched schedule_timeout(signed long timeout)
90842+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90843 {
90844 struct timer_list timer;
90845 unsigned long expire;
90846diff --git a/kernel/torture.c b/kernel/torture.c
90847index acc9afc..4f9eb49 100644
90848--- a/kernel/torture.c
90849+++ b/kernel/torture.c
90850@@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
90851 mutex_lock(&fullstop_mutex);
90852 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
90853 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
90854- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
90855+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
90856 } else {
90857 pr_warn("Concurrent rmmod and shutdown illegal!\n");
90858 }
90859@@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
90860 do {
90861 if (!torture_must_stop()) {
90862 schedule_timeout_interruptible(stutter);
90863- ACCESS_ONCE(stutter_pause_test) = 1;
90864+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
90865 }
90866 if (!torture_must_stop())
90867 schedule_timeout_interruptible(stutter);
90868- ACCESS_ONCE(stutter_pause_test) = 0;
90869+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
90870 torture_shutdown_absorb("torture_stutter");
90871 } while (!torture_must_stop());
90872 torture_kthread_stopping("torture_stutter");
90873@@ -636,7 +636,7 @@ bool torture_cleanup(void)
90874 schedule_timeout_uninterruptible(10);
90875 return true;
90876 }
90877- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
90878+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
90879 mutex_unlock(&fullstop_mutex);
90880 torture_shutdown_cleanup();
90881 torture_shuffle_cleanup();
90882diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90883index c1bd4ad..4b861dc 100644
90884--- a/kernel/trace/blktrace.c
90885+++ b/kernel/trace/blktrace.c
90886@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90887 struct blk_trace *bt = filp->private_data;
90888 char buf[16];
90889
90890- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90891+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90892
90893 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90894 }
90895@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90896 return 1;
90897
90898 bt = buf->chan->private_data;
90899- atomic_inc(&bt->dropped);
90900+ atomic_inc_unchecked(&bt->dropped);
90901 return 0;
90902 }
90903
90904@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90905
90906 bt->dir = dir;
90907 bt->dev = dev;
90908- atomic_set(&bt->dropped, 0);
90909+ atomic_set_unchecked(&bt->dropped, 0);
90910 INIT_LIST_HEAD(&bt->running_list);
90911
90912 ret = -EIO;
90913diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90914index 4a54a25..7ca9c89 100644
90915--- a/kernel/trace/ftrace.c
90916+++ b/kernel/trace/ftrace.c
90917@@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90918 if (unlikely(ftrace_disabled))
90919 return 0;
90920
90921+ ret = ftrace_arch_code_modify_prepare();
90922+ FTRACE_WARN_ON(ret);
90923+ if (ret)
90924+ return 0;
90925+
90926 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90927+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90928 if (ret) {
90929 ftrace_bug(ret, ip);
90930- return 0;
90931 }
90932- return 1;
90933+ return ret ? 0 : 1;
90934 }
90935
90936 /*
90937@@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
90938 if (!count)
90939 return 0;
90940
90941+ pax_open_kernel();
90942 sort(start, count, sizeof(*start),
90943 ftrace_cmp_ips, ftrace_swap_ips);
90944+ pax_close_kernel();
90945
90946 start_pg = ftrace_allocate_pages(count);
90947 if (!start_pg)
90948@@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90949 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90950
90951 static int ftrace_graph_active;
90952-static struct notifier_block ftrace_suspend_notifier;
90953-
90954 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90955 {
90956 return 0;
90957@@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
90958 ftrace_graph_entry = ftrace_graph_entry_test;
90959 }
90960
90961+static struct notifier_block ftrace_suspend_notifier = {
90962+ .notifier_call = ftrace_suspend_notifier_call
90963+};
90964+
90965 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90966 trace_func_graph_ent_t entryfunc)
90967 {
90968@@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90969 goto out;
90970 }
90971
90972- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90973 register_pm_notifier(&ftrace_suspend_notifier);
90974
90975 ftrace_graph_active++;
90976diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90977index c634868..00d0d19 100644
90978--- a/kernel/trace/ring_buffer.c
90979+++ b/kernel/trace/ring_buffer.c
90980@@ -352,9 +352,9 @@ struct buffer_data_page {
90981 */
90982 struct buffer_page {
90983 struct list_head list; /* list of buffer pages */
90984- local_t write; /* index for next write */
90985+ local_unchecked_t write; /* index for next write */
90986 unsigned read; /* index for next read */
90987- local_t entries; /* entries on this page */
90988+ local_unchecked_t entries; /* entries on this page */
90989 unsigned long real_end; /* real end of data */
90990 struct buffer_data_page *page; /* Actual data page */
90991 };
90992@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90993 unsigned long last_overrun;
90994 local_t entries_bytes;
90995 local_t entries;
90996- local_t overrun;
90997- local_t commit_overrun;
90998+ local_unchecked_t overrun;
90999+ local_unchecked_t commit_overrun;
91000 local_t dropped_events;
91001 local_t committing;
91002 local_t commits;
91003@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91004 *
91005 * We add a counter to the write field to denote this.
91006 */
91007- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
91008- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
91009+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
91010+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
91011
91012 /*
91013 * Just make sure we have seen our old_write and synchronize
91014@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91015 * cmpxchg to only update if an interrupt did not already
91016 * do it for us. If the cmpxchg fails, we don't care.
91017 */
91018- (void)local_cmpxchg(&next_page->write, old_write, val);
91019- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
91020+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
91021+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
91022
91023 /*
91024 * No need to worry about races with clearing out the commit.
91025@@ -1389,12 +1389,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
91026
91027 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
91028 {
91029- return local_read(&bpage->entries) & RB_WRITE_MASK;
91030+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
91031 }
91032
91033 static inline unsigned long rb_page_write(struct buffer_page *bpage)
91034 {
91035- return local_read(&bpage->write) & RB_WRITE_MASK;
91036+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
91037 }
91038
91039 static int
91040@@ -1489,7 +1489,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
91041 * bytes consumed in ring buffer from here.
91042 * Increment overrun to account for the lost events.
91043 */
91044- local_add(page_entries, &cpu_buffer->overrun);
91045+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
91046 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91047 }
91048
91049@@ -2067,7 +2067,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91050 * it is our responsibility to update
91051 * the counters.
91052 */
91053- local_add(entries, &cpu_buffer->overrun);
91054+ local_add_unchecked(entries, &cpu_buffer->overrun);
91055 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91056
91057 /*
91058@@ -2217,7 +2217,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91059 if (tail == BUF_PAGE_SIZE)
91060 tail_page->real_end = 0;
91061
91062- local_sub(length, &tail_page->write);
91063+ local_sub_unchecked(length, &tail_page->write);
91064 return;
91065 }
91066
91067@@ -2252,7 +2252,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91068 rb_event_set_padding(event);
91069
91070 /* Set the write back to the previous setting */
91071- local_sub(length, &tail_page->write);
91072+ local_sub_unchecked(length, &tail_page->write);
91073 return;
91074 }
91075
91076@@ -2264,7 +2264,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91077
91078 /* Set write to end of buffer */
91079 length = (tail + length) - BUF_PAGE_SIZE;
91080- local_sub(length, &tail_page->write);
91081+ local_sub_unchecked(length, &tail_page->write);
91082 }
91083
91084 /*
91085@@ -2290,7 +2290,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91086 * about it.
91087 */
91088 if (unlikely(next_page == commit_page)) {
91089- local_inc(&cpu_buffer->commit_overrun);
91090+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91091 goto out_reset;
91092 }
91093
91094@@ -2346,7 +2346,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91095 cpu_buffer->tail_page) &&
91096 (cpu_buffer->commit_page ==
91097 cpu_buffer->reader_page))) {
91098- local_inc(&cpu_buffer->commit_overrun);
91099+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91100 goto out_reset;
91101 }
91102 }
91103@@ -2394,7 +2394,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91104 length += RB_LEN_TIME_EXTEND;
91105
91106 tail_page = cpu_buffer->tail_page;
91107- write = local_add_return(length, &tail_page->write);
91108+ write = local_add_return_unchecked(length, &tail_page->write);
91109
91110 /* set write to only the index of the write */
91111 write &= RB_WRITE_MASK;
91112@@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91113 kmemcheck_annotate_bitfield(event, bitfield);
91114 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91115
91116- local_inc(&tail_page->entries);
91117+ local_inc_unchecked(&tail_page->entries);
91118
91119 /*
91120 * If this is the first commit on the page, then update
91121@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91122
91123 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91124 unsigned long write_mask =
91125- local_read(&bpage->write) & ~RB_WRITE_MASK;
91126+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91127 unsigned long event_length = rb_event_length(event);
91128 /*
91129 * This is on the tail page. It is possible that
91130@@ -2461,7 +2461,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91131 */
91132 old_index += write_mask;
91133 new_index += write_mask;
91134- index = local_cmpxchg(&bpage->write, old_index, new_index);
91135+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91136 if (index == old_index) {
91137 /* update counters */
91138 local_sub(event_length, &cpu_buffer->entries_bytes);
91139@@ -2853,7 +2853,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91140
91141 /* Do the likely case first */
91142 if (likely(bpage->page == (void *)addr)) {
91143- local_dec(&bpage->entries);
91144+ local_dec_unchecked(&bpage->entries);
91145 return;
91146 }
91147
91148@@ -2865,7 +2865,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91149 start = bpage;
91150 do {
91151 if (bpage->page == (void *)addr) {
91152- local_dec(&bpage->entries);
91153+ local_dec_unchecked(&bpage->entries);
91154 return;
91155 }
91156 rb_inc_page(cpu_buffer, &bpage);
91157@@ -3149,7 +3149,7 @@ static inline unsigned long
91158 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91159 {
91160 return local_read(&cpu_buffer->entries) -
91161- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91162+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91163 }
91164
91165 /**
91166@@ -3238,7 +3238,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91167 return 0;
91168
91169 cpu_buffer = buffer->buffers[cpu];
91170- ret = local_read(&cpu_buffer->overrun);
91171+ ret = local_read_unchecked(&cpu_buffer->overrun);
91172
91173 return ret;
91174 }
91175@@ -3261,7 +3261,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91176 return 0;
91177
91178 cpu_buffer = buffer->buffers[cpu];
91179- ret = local_read(&cpu_buffer->commit_overrun);
91180+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91181
91182 return ret;
91183 }
91184@@ -3346,7 +3346,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91185 /* if you care about this being correct, lock the buffer */
91186 for_each_buffer_cpu(buffer, cpu) {
91187 cpu_buffer = buffer->buffers[cpu];
91188- overruns += local_read(&cpu_buffer->overrun);
91189+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91190 }
91191
91192 return overruns;
91193@@ -3522,8 +3522,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91194 /*
91195 * Reset the reader page to size zero.
91196 */
91197- local_set(&cpu_buffer->reader_page->write, 0);
91198- local_set(&cpu_buffer->reader_page->entries, 0);
91199+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91200+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91201 local_set(&cpu_buffer->reader_page->page->commit, 0);
91202 cpu_buffer->reader_page->real_end = 0;
91203
91204@@ -3557,7 +3557,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91205 * want to compare with the last_overrun.
91206 */
91207 smp_mb();
91208- overwrite = local_read(&(cpu_buffer->overrun));
91209+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91210
91211 /*
91212 * Here's the tricky part.
91213@@ -4127,8 +4127,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91214
91215 cpu_buffer->head_page
91216 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91217- local_set(&cpu_buffer->head_page->write, 0);
91218- local_set(&cpu_buffer->head_page->entries, 0);
91219+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91220+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91221 local_set(&cpu_buffer->head_page->page->commit, 0);
91222
91223 cpu_buffer->head_page->read = 0;
91224@@ -4138,14 +4138,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91225
91226 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91227 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91228- local_set(&cpu_buffer->reader_page->write, 0);
91229- local_set(&cpu_buffer->reader_page->entries, 0);
91230+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91231+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91232 local_set(&cpu_buffer->reader_page->page->commit, 0);
91233 cpu_buffer->reader_page->read = 0;
91234
91235 local_set(&cpu_buffer->entries_bytes, 0);
91236- local_set(&cpu_buffer->overrun, 0);
91237- local_set(&cpu_buffer->commit_overrun, 0);
91238+ local_set_unchecked(&cpu_buffer->overrun, 0);
91239+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91240 local_set(&cpu_buffer->dropped_events, 0);
91241 local_set(&cpu_buffer->entries, 0);
91242 local_set(&cpu_buffer->committing, 0);
91243@@ -4550,8 +4550,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91244 rb_init_page(bpage);
91245 bpage = reader->page;
91246 reader->page = *data_page;
91247- local_set(&reader->write, 0);
91248- local_set(&reader->entries, 0);
91249+ local_set_unchecked(&reader->write, 0);
91250+ local_set_unchecked(&reader->entries, 0);
91251 reader->read = 0;
91252 *data_page = bpage;
91253
91254diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91255index 737b0ef..bd21ea6 100644
91256--- a/kernel/trace/trace.c
91257+++ b/kernel/trace/trace.c
91258@@ -3448,7 +3448,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91259 return 0;
91260 }
91261
91262-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91263+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91264 {
91265 /* do nothing if flag is already set */
91266 if (!!(trace_flags & mask) == !!enabled)
91267diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91268index 2e29d7b..61367d7 100644
91269--- a/kernel/trace/trace.h
91270+++ b/kernel/trace/trace.h
91271@@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91272 void trace_printk_init_buffers(void);
91273 void trace_printk_start_comm(void);
91274 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91275-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91276+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91277
91278 /*
91279 * Normal trace_printk() and friends allocates special buffers
91280diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91281index 26dc348..8708ca7 100644
91282--- a/kernel/trace/trace_clock.c
91283+++ b/kernel/trace/trace_clock.c
91284@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91285 return now;
91286 }
91287
91288-static atomic64_t trace_counter;
91289+static atomic64_unchecked_t trace_counter;
91290
91291 /*
91292 * trace_clock_counter(): simply an atomic counter.
91293@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91294 */
91295 u64 notrace trace_clock_counter(void)
91296 {
91297- return atomic64_add_return(1, &trace_counter);
91298+ return atomic64_inc_return_unchecked(&trace_counter);
91299 }
91300diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91301index 3ddfd8f..41a10fe 100644
91302--- a/kernel/trace/trace_events.c
91303+++ b/kernel/trace/trace_events.c
91304@@ -1718,7 +1718,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91305 return 0;
91306 }
91307
91308-struct ftrace_module_file_ops;
91309 static void __add_event_to_tracers(struct ftrace_event_call *call);
91310
91311 /* Add an additional event_call dynamically */
91312diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91313index 0abd9b8..6a663a2 100644
91314--- a/kernel/trace/trace_mmiotrace.c
91315+++ b/kernel/trace/trace_mmiotrace.c
91316@@ -24,7 +24,7 @@ struct header_iter {
91317 static struct trace_array *mmio_trace_array;
91318 static bool overrun_detected;
91319 static unsigned long prev_overruns;
91320-static atomic_t dropped_count;
91321+static atomic_unchecked_t dropped_count;
91322
91323 static void mmio_reset_data(struct trace_array *tr)
91324 {
91325@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91326
91327 static unsigned long count_overruns(struct trace_iterator *iter)
91328 {
91329- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91330+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91331 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91332
91333 if (over > prev_overruns)
91334@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91335 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91336 sizeof(*entry), 0, pc);
91337 if (!event) {
91338- atomic_inc(&dropped_count);
91339+ atomic_inc_unchecked(&dropped_count);
91340 return;
91341 }
91342 entry = ring_buffer_event_data(event);
91343@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91344 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91345 sizeof(*entry), 0, pc);
91346 if (!event) {
91347- atomic_inc(&dropped_count);
91348+ atomic_inc_unchecked(&dropped_count);
91349 return;
91350 }
91351 entry = ring_buffer_event_data(event);
91352diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91353index a436de1..f64dde2 100644
91354--- a/kernel/trace/trace_output.c
91355+++ b/kernel/trace/trace_output.c
91356@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91357
91358 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91359 if (!IS_ERR(p)) {
91360- p = mangle_path(s->buffer + s->len, p, "\n");
91361+ p = mangle_path(s->buffer + s->len, p, "\n\\");
91362 if (p) {
91363 s->len = p - s->buffer;
91364 return 1;
91365@@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
91366 goto out;
91367 }
91368
91369+ pax_open_kernel();
91370 if (event->funcs->trace == NULL)
91371- event->funcs->trace = trace_nop_print;
91372+ *(void **)&event->funcs->trace = trace_nop_print;
91373 if (event->funcs->raw == NULL)
91374- event->funcs->raw = trace_nop_print;
91375+ *(void **)&event->funcs->raw = trace_nop_print;
91376 if (event->funcs->hex == NULL)
91377- event->funcs->hex = trace_nop_print;
91378+ *(void **)&event->funcs->hex = trace_nop_print;
91379 if (event->funcs->binary == NULL)
91380- event->funcs->binary = trace_nop_print;
91381+ *(void **)&event->funcs->binary = trace_nop_print;
91382+ pax_close_kernel();
91383
91384 key = event->type & (EVENT_HASHSIZE - 1);
91385
91386diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91387index 21b320e..40607bc 100644
91388--- a/kernel/trace/trace_stack.c
91389+++ b/kernel/trace/trace_stack.c
91390@@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91391 return;
91392
91393 /* we do not handle interrupt stacks yet */
91394- if (!object_is_on_stack(stack))
91395+ if (!object_starts_on_stack(stack))
91396 return;
91397
91398 local_irq_save(flags);
91399diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91400index bf71b4b..04dee68 100644
91401--- a/kernel/user_namespace.c
91402+++ b/kernel/user_namespace.c
91403@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91404 !kgid_has_mapping(parent_ns, group))
91405 return -EPERM;
91406
91407+#ifdef CONFIG_GRKERNSEC
91408+ /*
91409+ * This doesn't really inspire confidence:
91410+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91411+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91412+ * Increases kernel attack surface in areas developers
91413+ * previously cared little about ("low importance due
91414+ * to requiring "root" capability")
91415+ * To be removed when this code receives *proper* review
91416+ */
91417+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91418+ !capable(CAP_SETGID))
91419+ return -EPERM;
91420+#endif
91421+
91422 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91423 if (!ns)
91424 return -ENOMEM;
91425@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91426 if (atomic_read(&current->mm->mm_users) > 1)
91427 return -EINVAL;
91428
91429- if (current->fs->users != 1)
91430+ if (atomic_read(&current->fs->users) != 1)
91431 return -EINVAL;
91432
91433 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91434diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91435index 4f69f9a..7c6f8f8 100644
91436--- a/kernel/utsname_sysctl.c
91437+++ b/kernel/utsname_sysctl.c
91438@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91439 static int proc_do_uts_string(ctl_table *table, int write,
91440 void __user *buffer, size_t *lenp, loff_t *ppos)
91441 {
91442- struct ctl_table uts_table;
91443+ ctl_table_no_const uts_table;
91444 int r;
91445 memcpy(&uts_table, table, sizeof(uts_table));
91446 uts_table.data = get_uts(table, write);
91447diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91448index 516203e..ecc58d1 100644
91449--- a/kernel/watchdog.c
91450+++ b/kernel/watchdog.c
91451@@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91452 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91453 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91454
91455-static struct smp_hotplug_thread watchdog_threads = {
91456+static struct smp_hotplug_thread watchdog_threads __read_only = {
91457 .store = &softlockup_watchdog,
91458 .thread_should_run = watchdog_should_run,
91459 .thread_fn = watchdog,
91460diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91461index 8edc8718..b6a70b9 100644
91462--- a/kernel/workqueue.c
91463+++ b/kernel/workqueue.c
91464@@ -4709,7 +4709,7 @@ static void rebind_workers(struct worker_pool *pool)
91465 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91466 worker_flags |= WORKER_REBOUND;
91467 worker_flags &= ~WORKER_UNBOUND;
91468- ACCESS_ONCE(worker->flags) = worker_flags;
91469+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91470 }
91471
91472 spin_unlock_irq(&pool->lock);
91473diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91474index 819ac51..1c8a65e 100644
91475--- a/lib/Kconfig.debug
91476+++ b/lib/Kconfig.debug
91477@@ -853,7 +853,7 @@ config DEBUG_MUTEXES
91478
91479 config DEBUG_WW_MUTEX_SLOWPATH
91480 bool "Wait/wound mutex debugging: Slowpath testing"
91481- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91482+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91483 select DEBUG_LOCK_ALLOC
91484 select DEBUG_SPINLOCK
91485 select DEBUG_MUTEXES
91486@@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91487
91488 config DEBUG_LOCK_ALLOC
91489 bool "Lock debugging: detect incorrect freeing of live locks"
91490- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91491+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91492 select DEBUG_SPINLOCK
91493 select DEBUG_MUTEXES
91494 select LOCKDEP
91495@@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
91496
91497 config PROVE_LOCKING
91498 bool "Lock debugging: prove locking correctness"
91499- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91500+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91501 select LOCKDEP
91502 select DEBUG_SPINLOCK
91503 select DEBUG_MUTEXES
91504@@ -931,7 +931,7 @@ config LOCKDEP
91505
91506 config LOCK_STAT
91507 bool "Lock usage statistics"
91508- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91509+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91510 select LOCKDEP
91511 select DEBUG_SPINLOCK
91512 select DEBUG_MUTEXES
91513@@ -1403,6 +1403,7 @@ config LATENCYTOP
91514 depends on DEBUG_KERNEL
91515 depends on STACKTRACE_SUPPORT
91516 depends on PROC_FS
91517+ depends on !GRKERNSEC_HIDESYM
91518 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91519 select KALLSYMS
91520 select KALLSYMS_ALL
91521@@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91522 config DEBUG_STRICT_USER_COPY_CHECKS
91523 bool "Strict user copy size checks"
91524 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91525- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91526+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91527 help
91528 Enabling this option turns a certain set of sanity checks for user
91529 copy operations into compile time failures.
91530@@ -1538,7 +1539,7 @@ endmenu # runtime tests
91531
91532 config PROVIDE_OHCI1394_DMA_INIT
91533 bool "Remote debugging over FireWire early on boot"
91534- depends on PCI && X86
91535+ depends on PCI && X86 && !GRKERNSEC
91536 help
91537 If you want to debug problems which hang or crash the kernel early
91538 on boot and the crashing machine has a FireWire port, you can use
91539diff --git a/lib/Makefile b/lib/Makefile
91540index 0cd7b68..e149e37 100644
91541--- a/lib/Makefile
91542+++ b/lib/Makefile
91543@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91544 obj-$(CONFIG_BTREE) += btree.o
91545 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91546 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91547-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91548+obj-y += list_debug.o
91549 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91550
91551 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91552diff --git a/lib/average.c b/lib/average.c
91553index 114d1be..ab0350c 100644
91554--- a/lib/average.c
91555+++ b/lib/average.c
91556@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91557 {
91558 unsigned long internal = ACCESS_ONCE(avg->internal);
91559
91560- ACCESS_ONCE(avg->internal) = internal ?
91561+ ACCESS_ONCE_RW(avg->internal) = internal ?
91562 (((internal << avg->weight) - internal) +
91563 (val << avg->factor)) >> avg->weight :
91564 (val << avg->factor);
91565diff --git a/lib/bitmap.c b/lib/bitmap.c
91566index 06f7e4f..f3cf2b0 100644
91567--- a/lib/bitmap.c
91568+++ b/lib/bitmap.c
91569@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91570 {
91571 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91572 u32 chunk;
91573- const char __user __force *ubuf = (const char __user __force *)buf;
91574+ const char __user *ubuf = (const char __force_user *)buf;
91575
91576 bitmap_zero(maskp, nmaskbits);
91577
91578@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91579 {
91580 if (!access_ok(VERIFY_READ, ubuf, ulen))
91581 return -EFAULT;
91582- return __bitmap_parse((const char __force *)ubuf,
91583+ return __bitmap_parse((const char __force_kernel *)ubuf,
91584 ulen, 1, maskp, nmaskbits);
91585
91586 }
91587@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91588 {
91589 unsigned a, b;
91590 int c, old_c, totaldigits;
91591- const char __user __force *ubuf = (const char __user __force *)buf;
91592+ const char __user *ubuf = (const char __force_user *)buf;
91593 int exp_digit, in_range;
91594
91595 totaldigits = c = 0;
91596@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91597 {
91598 if (!access_ok(VERIFY_READ, ubuf, ulen))
91599 return -EFAULT;
91600- return __bitmap_parselist((const char __force *)ubuf,
91601+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91602 ulen, 1, maskp, nmaskbits);
91603 }
91604 EXPORT_SYMBOL(bitmap_parselist_user);
91605diff --git a/lib/bug.c b/lib/bug.c
91606index 1686034..a9c00c8 100644
91607--- a/lib/bug.c
91608+++ b/lib/bug.c
91609@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91610 return BUG_TRAP_TYPE_NONE;
91611
91612 bug = find_bug(bugaddr);
91613+ if (!bug)
91614+ return BUG_TRAP_TYPE_NONE;
91615
91616 file = NULL;
91617 line = 0;
91618diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91619index e0731c3..ad66444 100644
91620--- a/lib/debugobjects.c
91621+++ b/lib/debugobjects.c
91622@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91623 if (limit > 4)
91624 return;
91625
91626- is_on_stack = object_is_on_stack(addr);
91627+ is_on_stack = object_starts_on_stack(addr);
91628 if (is_on_stack == onstack)
91629 return;
91630
91631diff --git a/lib/div64.c b/lib/div64.c
91632index 4382ad7..08aa558 100644
91633--- a/lib/div64.c
91634+++ b/lib/div64.c
91635@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91636 EXPORT_SYMBOL(__div64_32);
91637
91638 #ifndef div_s64_rem
91639-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91640+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91641 {
91642 u64 quotient;
91643
91644@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91645 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91646 */
91647 #ifndef div64_u64
91648-u64 div64_u64(u64 dividend, u64 divisor)
91649+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91650 {
91651 u32 high = divisor >> 32;
91652 u64 quot;
91653diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91654index 98f2d7e..899da5c 100644
91655--- a/lib/dma-debug.c
91656+++ b/lib/dma-debug.c
91657@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91658
91659 void dma_debug_add_bus(struct bus_type *bus)
91660 {
91661- struct notifier_block *nb;
91662+ notifier_block_no_const *nb;
91663
91664 if (global_disable)
91665 return;
91666@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91667
91668 static void check_for_stack(struct device *dev, void *addr)
91669 {
91670- if (object_is_on_stack(addr))
91671+ if (object_starts_on_stack(addr))
91672 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91673 "stack [addr=%p]\n", addr);
91674 }
91675diff --git a/lib/hash.c b/lib/hash.c
91676index fea973f..386626f 100644
91677--- a/lib/hash.c
91678+++ b/lib/hash.c
91679@@ -14,7 +14,7 @@
91680 #include <linux/hash.h>
91681 #include <linux/cache.h>
91682
91683-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91684+static struct fast_hash_ops arch_hash_ops __read_only = {
91685 .hash = jhash,
91686 .hash2 = jhash2,
91687 };
91688diff --git a/lib/inflate.c b/lib/inflate.c
91689index 013a761..c28f3fc 100644
91690--- a/lib/inflate.c
91691+++ b/lib/inflate.c
91692@@ -269,7 +269,7 @@ static void free(void *where)
91693 malloc_ptr = free_mem_ptr;
91694 }
91695 #else
91696-#define malloc(a) kmalloc(a, GFP_KERNEL)
91697+#define malloc(a) kmalloc((a), GFP_KERNEL)
91698 #define free(a) kfree(a)
91699 #endif
91700
91701diff --git a/lib/ioremap.c b/lib/ioremap.c
91702index 0c9216c..863bd89 100644
91703--- a/lib/ioremap.c
91704+++ b/lib/ioremap.c
91705@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91706 unsigned long next;
91707
91708 phys_addr -= addr;
91709- pmd = pmd_alloc(&init_mm, pud, addr);
91710+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91711 if (!pmd)
91712 return -ENOMEM;
91713 do {
91714@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91715 unsigned long next;
91716
91717 phys_addr -= addr;
91718- pud = pud_alloc(&init_mm, pgd, addr);
91719+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91720 if (!pud)
91721 return -ENOMEM;
91722 do {
91723diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91724index bd2bea9..6b3c95e 100644
91725--- a/lib/is_single_threaded.c
91726+++ b/lib/is_single_threaded.c
91727@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91728 struct task_struct *p, *t;
91729 bool ret;
91730
91731+ if (!mm)
91732+ return true;
91733+
91734 if (atomic_read(&task->signal->live) != 1)
91735 return false;
91736
91737diff --git a/lib/kobject.c b/lib/kobject.c
91738index 58751bb..93a1853 100644
91739--- a/lib/kobject.c
91740+++ b/lib/kobject.c
91741@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91742
91743
91744 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91745-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91746+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91747
91748-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91749+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91750 {
91751 enum kobj_ns_type type = ops->type;
91752 int error;
91753diff --git a/lib/list_debug.c b/lib/list_debug.c
91754index c24c2f7..f0296f4 100644
91755--- a/lib/list_debug.c
91756+++ b/lib/list_debug.c
91757@@ -11,7 +11,9 @@
91758 #include <linux/bug.h>
91759 #include <linux/kernel.h>
91760 #include <linux/rculist.h>
91761+#include <linux/mm.h>
91762
91763+#ifdef CONFIG_DEBUG_LIST
91764 /*
91765 * Insert a new entry between two known consecutive entries.
91766 *
91767@@ -19,21 +21,40 @@
91768 * the prev/next entries already!
91769 */
91770
91771+static bool __list_add_debug(struct list_head *new,
91772+ struct list_head *prev,
91773+ struct list_head *next)
91774+{
91775+ if (unlikely(next->prev != prev)) {
91776+ printk(KERN_ERR "list_add corruption. next->prev should be "
91777+ "prev (%p), but was %p. (next=%p).\n",
91778+ prev, next->prev, next);
91779+ BUG();
91780+ return false;
91781+ }
91782+ if (unlikely(prev->next != next)) {
91783+ printk(KERN_ERR "list_add corruption. prev->next should be "
91784+ "next (%p), but was %p. (prev=%p).\n",
91785+ next, prev->next, prev);
91786+ BUG();
91787+ return false;
91788+ }
91789+ if (unlikely(new == prev || new == next)) {
91790+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91791+ new, prev, next);
91792+ BUG();
91793+ return false;
91794+ }
91795+ return true;
91796+}
91797+
91798 void __list_add(struct list_head *new,
91799- struct list_head *prev,
91800- struct list_head *next)
91801+ struct list_head *prev,
91802+ struct list_head *next)
91803 {
91804- WARN(next->prev != prev,
91805- "list_add corruption. next->prev should be "
91806- "prev (%p), but was %p. (next=%p).\n",
91807- prev, next->prev, next);
91808- WARN(prev->next != next,
91809- "list_add corruption. prev->next should be "
91810- "next (%p), but was %p. (prev=%p).\n",
91811- next, prev->next, prev);
91812- WARN(new == prev || new == next,
91813- "list_add double add: new=%p, prev=%p, next=%p.\n",
91814- new, prev, next);
91815+ if (!__list_add_debug(new, prev, next))
91816+ return;
91817+
91818 next->prev = new;
91819 new->next = next;
91820 new->prev = prev;
91821@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91822 }
91823 EXPORT_SYMBOL(__list_add);
91824
91825-void __list_del_entry(struct list_head *entry)
91826+static bool __list_del_entry_debug(struct list_head *entry)
91827 {
91828 struct list_head *prev, *next;
91829
91830 prev = entry->prev;
91831 next = entry->next;
91832
91833- if (WARN(next == LIST_POISON1,
91834- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91835- entry, LIST_POISON1) ||
91836- WARN(prev == LIST_POISON2,
91837- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91838- entry, LIST_POISON2) ||
91839- WARN(prev->next != entry,
91840- "list_del corruption. prev->next should be %p, "
91841- "but was %p\n", entry, prev->next) ||
91842- WARN(next->prev != entry,
91843- "list_del corruption. next->prev should be %p, "
91844- "but was %p\n", entry, next->prev))
91845+ if (unlikely(next == LIST_POISON1)) {
91846+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91847+ entry, LIST_POISON1);
91848+ BUG();
91849+ return false;
91850+ }
91851+ if (unlikely(prev == LIST_POISON2)) {
91852+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91853+ entry, LIST_POISON2);
91854+ BUG();
91855+ return false;
91856+ }
91857+ if (unlikely(entry->prev->next != entry)) {
91858+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91859+ "but was %p\n", entry, prev->next);
91860+ BUG();
91861+ return false;
91862+ }
91863+ if (unlikely(entry->next->prev != entry)) {
91864+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91865+ "but was %p\n", entry, next->prev);
91866+ BUG();
91867+ return false;
91868+ }
91869+ return true;
91870+}
91871+
91872+void __list_del_entry(struct list_head *entry)
91873+{
91874+ if (!__list_del_entry_debug(entry))
91875 return;
91876
91877- __list_del(prev, next);
91878+ __list_del(entry->prev, entry->next);
91879 }
91880 EXPORT_SYMBOL(__list_del_entry);
91881
91882@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91883 void __list_add_rcu(struct list_head *new,
91884 struct list_head *prev, struct list_head *next)
91885 {
91886- WARN(next->prev != prev,
91887- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91888- prev, next->prev, next);
91889- WARN(prev->next != next,
91890- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91891- next, prev->next, prev);
91892+ if (!__list_add_debug(new, prev, next))
91893+ return;
91894+
91895 new->next = next;
91896 new->prev = prev;
91897 rcu_assign_pointer(list_next_rcu(prev), new);
91898 next->prev = new;
91899 }
91900 EXPORT_SYMBOL(__list_add_rcu);
91901+#endif
91902+
91903+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91904+{
91905+#ifdef CONFIG_DEBUG_LIST
91906+ if (!__list_add_debug(new, prev, next))
91907+ return;
91908+#endif
91909+
91910+ pax_open_kernel();
91911+ next->prev = new;
91912+ new->next = next;
91913+ new->prev = prev;
91914+ prev->next = new;
91915+ pax_close_kernel();
91916+}
91917+EXPORT_SYMBOL(__pax_list_add);
91918+
91919+void pax_list_del(struct list_head *entry)
91920+{
91921+#ifdef CONFIG_DEBUG_LIST
91922+ if (!__list_del_entry_debug(entry))
91923+ return;
91924+#endif
91925+
91926+ pax_open_kernel();
91927+ __list_del(entry->prev, entry->next);
91928+ entry->next = LIST_POISON1;
91929+ entry->prev = LIST_POISON2;
91930+ pax_close_kernel();
91931+}
91932+EXPORT_SYMBOL(pax_list_del);
91933+
91934+void pax_list_del_init(struct list_head *entry)
91935+{
91936+ pax_open_kernel();
91937+ __list_del(entry->prev, entry->next);
91938+ INIT_LIST_HEAD(entry);
91939+ pax_close_kernel();
91940+}
91941+EXPORT_SYMBOL(pax_list_del_init);
91942+
91943+void __pax_list_add_rcu(struct list_head *new,
91944+ struct list_head *prev, struct list_head *next)
91945+{
91946+#ifdef CONFIG_DEBUG_LIST
91947+ if (!__list_add_debug(new, prev, next))
91948+ return;
91949+#endif
91950+
91951+ pax_open_kernel();
91952+ new->next = next;
91953+ new->prev = prev;
91954+ rcu_assign_pointer(list_next_rcu(prev), new);
91955+ next->prev = new;
91956+ pax_close_kernel();
91957+}
91958+EXPORT_SYMBOL(__pax_list_add_rcu);
91959+
91960+void pax_list_del_rcu(struct list_head *entry)
91961+{
91962+#ifdef CONFIG_DEBUG_LIST
91963+ if (!__list_del_entry_debug(entry))
91964+ return;
91965+#endif
91966+
91967+ pax_open_kernel();
91968+ __list_del(entry->prev, entry->next);
91969+ entry->next = LIST_POISON1;
91970+ entry->prev = LIST_POISON2;
91971+ pax_close_kernel();
91972+}
91973+EXPORT_SYMBOL(pax_list_del_rcu);
91974diff --git a/lib/lz4/lz4_decompress.c b/lib/lz4/lz4_decompress.c
91975index b74da44..7a85967 100644
91976--- a/lib/lz4/lz4_decompress.c
91977+++ b/lib/lz4/lz4_decompress.c
91978@@ -192,6 +192,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest,
91979 int s = 255;
91980 while ((ip < iend) && (s == 255)) {
91981 s = *ip++;
91982+ if (unlikely(length > (size_t)(length + s)))
91983+ goto _output_error;
91984 length += s;
91985 }
91986 }
91987@@ -232,6 +234,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest,
91988 if (length == ML_MASK) {
91989 while (ip < iend) {
91990 int s = *ip++;
91991+ if (unlikely(length > (size_t)(length + s)))
91992+ goto _output_error;
91993 length += s;
91994 if (s == 255)
91995 continue;
91996@@ -284,7 +288,7 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest,
91997
91998 /* write overflow error detected */
91999 _output_error:
92000- return (int) (-(((char *) ip) - source));
92001+ return -1;
92002 }
92003
92004 int lz4_decompress(const unsigned char *src, size_t *src_len,
92005diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
92006index 963b703..438bc51 100644
92007--- a/lib/percpu-refcount.c
92008+++ b/lib/percpu-refcount.c
92009@@ -29,7 +29,7 @@
92010 * can't hit 0 before we've added up all the percpu refs.
92011 */
92012
92013-#define PCPU_COUNT_BIAS (1U << 31)
92014+#define PCPU_COUNT_BIAS (1U << 30)
92015
92016 /**
92017 * percpu_ref_init - initialize a percpu refcount
92018diff --git a/lib/radix-tree.c b/lib/radix-tree.c
92019index 9599aa7..9cf6c72 100644
92020--- a/lib/radix-tree.c
92021+++ b/lib/radix-tree.c
92022@@ -66,7 +66,7 @@ struct radix_tree_preload {
92023 int nr;
92024 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
92025 };
92026-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
92027+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
92028
92029 static inline void *ptr_to_indirect(void *ptr)
92030 {
92031diff --git a/lib/random32.c b/lib/random32.c
92032index fa5da61..35fe9af 100644
92033--- a/lib/random32.c
92034+++ b/lib/random32.c
92035@@ -42,7 +42,7 @@
92036 static void __init prandom_state_selftest(void);
92037 #endif
92038
92039-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
92040+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
92041
92042 /**
92043 * prandom_u32_state - seeded pseudo-random number generator.
92044diff --git a/lib/rbtree.c b/lib/rbtree.c
92045index 65f4eff..2cfa167 100644
92046--- a/lib/rbtree.c
92047+++ b/lib/rbtree.c
92048@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
92049 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
92050
92051 static const struct rb_augment_callbacks dummy_callbacks = {
92052- dummy_propagate, dummy_copy, dummy_rotate
92053+ .propagate = dummy_propagate,
92054+ .copy = dummy_copy,
92055+ .rotate = dummy_rotate
92056 };
92057
92058 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92059diff --git a/lib/show_mem.c b/lib/show_mem.c
92060index 0922579..9d7adb9 100644
92061--- a/lib/show_mem.c
92062+++ b/lib/show_mem.c
92063@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92064 quicklist_total_size());
92065 #endif
92066 #ifdef CONFIG_MEMORY_FAILURE
92067- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92068+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92069 #endif
92070 }
92071diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92072index bb2b201..46abaf9 100644
92073--- a/lib/strncpy_from_user.c
92074+++ b/lib/strncpy_from_user.c
92075@@ -21,7 +21,7 @@
92076 */
92077 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92078 {
92079- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92080+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92081 long res = 0;
92082
92083 /*
92084diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92085index a28df52..3d55877 100644
92086--- a/lib/strnlen_user.c
92087+++ b/lib/strnlen_user.c
92088@@ -26,7 +26,7 @@
92089 */
92090 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92091 {
92092- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92093+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92094 long align, res = 0;
92095 unsigned long c;
92096
92097diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92098index b604b83..c0547f6 100644
92099--- a/lib/swiotlb.c
92100+++ b/lib/swiotlb.c
92101@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92102
92103 void
92104 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92105- dma_addr_t dev_addr)
92106+ dma_addr_t dev_addr, struct dma_attrs *attrs)
92107 {
92108 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92109
92110diff --git a/lib/usercopy.c b/lib/usercopy.c
92111index 4f5b1dd..7cab418 100644
92112--- a/lib/usercopy.c
92113+++ b/lib/usercopy.c
92114@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92115 WARN(1, "Buffer overflow detected!\n");
92116 }
92117 EXPORT_SYMBOL(copy_from_user_overflow);
92118+
92119+void copy_to_user_overflow(void)
92120+{
92121+ WARN(1, "Buffer overflow detected!\n");
92122+}
92123+EXPORT_SYMBOL(copy_to_user_overflow);
92124diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92125index 0648291..42bf42b 100644
92126--- a/lib/vsprintf.c
92127+++ b/lib/vsprintf.c
92128@@ -16,6 +16,9 @@
92129 * - scnprintf and vscnprintf
92130 */
92131
92132+#ifdef CONFIG_GRKERNSEC_HIDESYM
92133+#define __INCLUDED_BY_HIDESYM 1
92134+#endif
92135 #include <stdarg.h>
92136 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92137 #include <linux/types.h>
92138@@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
92139 return number(buf, end, num, spec);
92140 }
92141
92142+#ifdef CONFIG_GRKERNSEC_HIDESYM
92143+int kptr_restrict __read_mostly = 2;
92144+#else
92145 int kptr_restrict __read_mostly;
92146+#endif
92147
92148 /*
92149 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92150@@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92151 * - 'f' For simple symbolic function names without offset
92152 * - 'S' For symbolic direct pointers with offset
92153 * - 's' For symbolic direct pointers without offset
92154+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92155 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92156 * - 'B' For backtraced symbolic direct pointers with offset
92157 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92158@@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92159
92160 if (!ptr && *fmt != 'K') {
92161 /*
92162- * Print (null) with the same width as a pointer so it makes
92163+ * Print (nil) with the same width as a pointer so it makes
92164 * tabular output look nice.
92165 */
92166 if (spec.field_width == -1)
92167 spec.field_width = default_width;
92168- return string(buf, end, "(null)", spec);
92169+ return string(buf, end, "(nil)", spec);
92170 }
92171
92172 switch (*fmt) {
92173@@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92174 /* Fallthrough */
92175 case 'S':
92176 case 's':
92177+#ifdef CONFIG_GRKERNSEC_HIDESYM
92178+ break;
92179+#else
92180+ return symbol_string(buf, end, ptr, spec, fmt);
92181+#endif
92182+ case 'A':
92183 case 'B':
92184 return symbol_string(buf, end, ptr, spec, fmt);
92185 case 'R':
92186@@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92187 va_end(va);
92188 return buf;
92189 }
92190+ case 'P':
92191+ break;
92192 case 'K':
92193 /*
92194 * %pK cannot be used in IRQ context because its test
92195@@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92196 ((const struct file *)ptr)->f_path.dentry,
92197 spec, fmt);
92198 }
92199+
92200+#ifdef CONFIG_GRKERNSEC_HIDESYM
92201+ /* 'P' = approved pointers to copy to userland,
92202+ as in the /proc/kallsyms case, as we make it display nothing
92203+ for non-root users, and the real contents for root users
92204+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92205+ above
92206+ */
92207+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92208+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92209+ dump_stack();
92210+ ptr = NULL;
92211+ }
92212+#endif
92213+
92214 spec.flags |= SMALL;
92215 if (spec.field_width == -1) {
92216 spec.field_width = default_width;
92217@@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92218 typeof(type) value; \
92219 if (sizeof(type) == 8) { \
92220 args = PTR_ALIGN(args, sizeof(u32)); \
92221- *(u32 *)&value = *(u32 *)args; \
92222- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92223+ *(u32 *)&value = *(const u32 *)args; \
92224+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92225 } else { \
92226 args = PTR_ALIGN(args, sizeof(type)); \
92227- value = *(typeof(type) *)args; \
92228+ value = *(const typeof(type) *)args; \
92229 } \
92230 args += sizeof(type); \
92231 value; \
92232@@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92233 case FORMAT_TYPE_STR: {
92234 const char *str_arg = args;
92235 args += strlen(str_arg) + 1;
92236- str = string(str, end, (char *)str_arg, spec);
92237+ str = string(str, end, str_arg, spec);
92238 break;
92239 }
92240
92241diff --git a/localversion-grsec b/localversion-grsec
92242new file mode 100644
92243index 0000000..7cd6065
92244--- /dev/null
92245+++ b/localversion-grsec
92246@@ -0,0 +1 @@
92247+-grsec
92248diff --git a/mm/Kconfig b/mm/Kconfig
92249index 2f42b9c..6095e14 100644
92250--- a/mm/Kconfig
92251+++ b/mm/Kconfig
92252@@ -330,10 +330,11 @@ config KSM
92253 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92254
92255 config DEFAULT_MMAP_MIN_ADDR
92256- int "Low address space to protect from user allocation"
92257+ int "Low address space to protect from user allocation"
92258 depends on MMU
92259- default 4096
92260- help
92261+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92262+ default 65536
92263+ help
92264 This is the portion of low virtual memory which should be protected
92265 from userspace allocation. Keeping a user from writing to low pages
92266 can help reduce the impact of kernel NULL pointer bugs.
92267@@ -364,7 +365,7 @@ config MEMORY_FAILURE
92268
92269 config HWPOISON_INJECT
92270 tristate "HWPoison pages injector"
92271- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92272+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92273 select PROC_PAGE_MONITOR
92274
92275 config NOMMU_INITIAL_TRIM_EXCESS
92276diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92277index 09d9591..165bb75 100644
92278--- a/mm/backing-dev.c
92279+++ b/mm/backing-dev.c
92280@@ -12,7 +12,7 @@
92281 #include <linux/device.h>
92282 #include <trace/events/writeback.h>
92283
92284-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92285+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92286
92287 struct backing_dev_info default_backing_dev_info = {
92288 .name = "default",
92289@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92290 return err;
92291
92292 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92293- atomic_long_inc_return(&bdi_seq));
92294+ atomic_long_inc_return_unchecked(&bdi_seq));
92295 if (err) {
92296 bdi_destroy(bdi);
92297 return err;
92298diff --git a/mm/filemap.c b/mm/filemap.c
92299index 088358c..bb415bf 100644
92300--- a/mm/filemap.c
92301+++ b/mm/filemap.c
92302@@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92303 struct address_space *mapping = file->f_mapping;
92304
92305 if (!mapping->a_ops->readpage)
92306- return -ENOEXEC;
92307+ return -ENODEV;
92308 file_accessed(file);
92309 vma->vm_ops = &generic_file_vm_ops;
92310 return 0;
92311@@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92312 *pos = i_size_read(inode);
92313
92314 if (limit != RLIM_INFINITY) {
92315+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92316 if (*pos >= limit) {
92317 send_sig(SIGXFSZ, current, 0);
92318 return -EFBIG;
92319diff --git a/mm/fremap.c b/mm/fremap.c
92320index 34feba6..315fe78 100644
92321--- a/mm/fremap.c
92322+++ b/mm/fremap.c
92323@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92324 retry:
92325 vma = find_vma(mm, start);
92326
92327+#ifdef CONFIG_PAX_SEGMEXEC
92328+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92329+ goto out;
92330+#endif
92331+
92332 /*
92333 * Make sure the vma is shared, that it supports prefaulting,
92334 * and that the remapped range is valid and fully within
92335diff --git a/mm/highmem.c b/mm/highmem.c
92336index b32b70c..e512eb0 100644
92337--- a/mm/highmem.c
92338+++ b/mm/highmem.c
92339@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92340 * So no dangers, even with speculative execution.
92341 */
92342 page = pte_page(pkmap_page_table[i]);
92343+ pax_open_kernel();
92344 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92345-
92346+ pax_close_kernel();
92347 set_page_address(page, NULL);
92348 need_flush = 1;
92349 }
92350@@ -198,9 +199,11 @@ start:
92351 }
92352 }
92353 vaddr = PKMAP_ADDR(last_pkmap_nr);
92354+
92355+ pax_open_kernel();
92356 set_pte_at(&init_mm, vaddr,
92357 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92358-
92359+ pax_close_kernel();
92360 pkmap_count[last_pkmap_nr] = 1;
92361 set_page_address(page, (void *)vaddr);
92362
92363diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92364index c82290b..863d466 100644
92365--- a/mm/hugetlb.c
92366+++ b/mm/hugetlb.c
92367@@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92368 struct hstate *h = &default_hstate;
92369 unsigned long tmp;
92370 int ret;
92371+ ctl_table_no_const hugetlb_table;
92372
92373 if (!hugepages_supported())
92374 return -ENOTSUPP;
92375@@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92376 if (write && h->order >= MAX_ORDER)
92377 return -EINVAL;
92378
92379- table->data = &tmp;
92380- table->maxlen = sizeof(unsigned long);
92381- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92382+ hugetlb_table = *table;
92383+ hugetlb_table.data = &tmp;
92384+ hugetlb_table.maxlen = sizeof(unsigned long);
92385+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92386 if (ret)
92387 goto out;
92388
92389@@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92390 struct hstate *h = &default_hstate;
92391 unsigned long tmp;
92392 int ret;
92393+ ctl_table_no_const hugetlb_table;
92394
92395 if (!hugepages_supported())
92396 return -ENOTSUPP;
92397@@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92398 if (write && h->order >= MAX_ORDER)
92399 return -EINVAL;
92400
92401- table->data = &tmp;
92402- table->maxlen = sizeof(unsigned long);
92403- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92404+ hugetlb_table = *table;
92405+ hugetlb_table.data = &tmp;
92406+ hugetlb_table.maxlen = sizeof(unsigned long);
92407+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92408 if (ret)
92409 goto out;
92410
92411@@ -2639,6 +2643,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92412 return 1;
92413 }
92414
92415+#ifdef CONFIG_PAX_SEGMEXEC
92416+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92417+{
92418+ struct mm_struct *mm = vma->vm_mm;
92419+ struct vm_area_struct *vma_m;
92420+ unsigned long address_m;
92421+ pte_t *ptep_m;
92422+
92423+ vma_m = pax_find_mirror_vma(vma);
92424+ if (!vma_m)
92425+ return;
92426+
92427+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92428+ address_m = address + SEGMEXEC_TASK_SIZE;
92429+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92430+ get_page(page_m);
92431+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92432+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92433+}
92434+#endif
92435+
92436 /*
92437 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92438 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92439@@ -2756,6 +2781,11 @@ retry_avoidcopy:
92440 make_huge_pte(vma, new_page, 1));
92441 page_remove_rmap(old_page);
92442 hugepage_add_new_anon_rmap(new_page, vma, address);
92443+
92444+#ifdef CONFIG_PAX_SEGMEXEC
92445+ pax_mirror_huge_pte(vma, address, new_page);
92446+#endif
92447+
92448 /* Make the old page be freed below */
92449 new_page = old_page;
92450 }
92451@@ -2915,6 +2945,10 @@ retry:
92452 && (vma->vm_flags & VM_SHARED)));
92453 set_huge_pte_at(mm, address, ptep, new_pte);
92454
92455+#ifdef CONFIG_PAX_SEGMEXEC
92456+ pax_mirror_huge_pte(vma, address, page);
92457+#endif
92458+
92459 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92460 /* Optimization, do the COW without a second fault */
92461 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92462@@ -2981,6 +3015,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92463 struct hstate *h = hstate_vma(vma);
92464 struct address_space *mapping;
92465
92466+#ifdef CONFIG_PAX_SEGMEXEC
92467+ struct vm_area_struct *vma_m;
92468+#endif
92469+
92470 address &= huge_page_mask(h);
92471
92472 ptep = huge_pte_offset(mm, address);
92473@@ -2994,6 +3032,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92474 VM_FAULT_SET_HINDEX(hstate_index(h));
92475 }
92476
92477+#ifdef CONFIG_PAX_SEGMEXEC
92478+ vma_m = pax_find_mirror_vma(vma);
92479+ if (vma_m) {
92480+ unsigned long address_m;
92481+
92482+ if (vma->vm_start > vma_m->vm_start) {
92483+ address_m = address;
92484+ address -= SEGMEXEC_TASK_SIZE;
92485+ vma = vma_m;
92486+ h = hstate_vma(vma);
92487+ } else
92488+ address_m = address + SEGMEXEC_TASK_SIZE;
92489+
92490+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92491+ return VM_FAULT_OOM;
92492+ address_m &= HPAGE_MASK;
92493+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92494+ }
92495+#endif
92496+
92497 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92498 if (!ptep)
92499 return VM_FAULT_OOM;
92500diff --git a/mm/internal.h b/mm/internal.h
92501index 07b6736..ae8da20 100644
92502--- a/mm/internal.h
92503+++ b/mm/internal.h
92504@@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92505 * in mm/page_alloc.c
92506 */
92507 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92508+extern void free_compound_page(struct page *page);
92509 extern void prep_compound_page(struct page *page, unsigned long order);
92510 #ifdef CONFIG_MEMORY_FAILURE
92511 extern bool is_free_buddy_page(struct page *page);
92512@@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
92513
92514 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92515 unsigned long, unsigned long,
92516- unsigned long, unsigned long);
92517+ unsigned long, unsigned long) __intentional_overflow(-1);
92518
92519 extern void set_pageblock_order(void);
92520 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92521diff --git a/mm/iov_iter.c b/mm/iov_iter.c
92522index 10e46cd..e3052f6 100644
92523--- a/mm/iov_iter.c
92524+++ b/mm/iov_iter.c
92525@@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92526
92527 while (bytes) {
92528 char __user *buf = iov->iov_base + base;
92529- int copy = min(bytes, iov->iov_len - base);
92530+ size_t copy = min(bytes, iov->iov_len - base);
92531
92532 base = 0;
92533 left = __copy_from_user_inatomic(vaddr, buf, copy);
92534@@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92535
92536 kaddr = kmap_atomic(page);
92537 if (likely(i->nr_segs == 1)) {
92538- int left;
92539+ size_t left;
92540 char __user *buf = i->iov->iov_base + i->iov_offset;
92541 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92542 copied = bytes - left;
92543@@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92544
92545 kaddr = kmap(page);
92546 if (likely(i->nr_segs == 1)) {
92547- int left;
92548+ size_t left;
92549 char __user *buf = i->iov->iov_base + i->iov_offset;
92550 left = __copy_from_user(kaddr + offset, buf, bytes);
92551 copied = bytes - left;
92552@@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92553 * zero-length segments (without overruning the iovec).
92554 */
92555 while (bytes || unlikely(i->count && !iov->iov_len)) {
92556- int copy;
92557+ size_t copy;
92558
92559 copy = min(bytes, iov->iov_len - base);
92560 BUG_ON(!i->count || i->count < copy);
92561diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92562index 8d2fcdf..6dd9f1a 100644
92563--- a/mm/kmemleak.c
92564+++ b/mm/kmemleak.c
92565@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
92566
92567 for (i = 0; i < object->trace_len; i++) {
92568 void *ptr = (void *)object->trace[i];
92569- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92570+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92571 }
92572 }
92573
92574@@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
92575 return -ENOMEM;
92576 }
92577
92578- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92579+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92580 &kmemleak_fops);
92581 if (!dentry)
92582 pr_warning("Failed to create the debugfs kmemleak file\n");
92583diff --git a/mm/maccess.c b/mm/maccess.c
92584index d53adf9..03a24bf 100644
92585--- a/mm/maccess.c
92586+++ b/mm/maccess.c
92587@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92588 set_fs(KERNEL_DS);
92589 pagefault_disable();
92590 ret = __copy_from_user_inatomic(dst,
92591- (__force const void __user *)src, size);
92592+ (const void __force_user *)src, size);
92593 pagefault_enable();
92594 set_fs(old_fs);
92595
92596@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92597
92598 set_fs(KERNEL_DS);
92599 pagefault_disable();
92600- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92601+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92602 pagefault_enable();
92603 set_fs(old_fs);
92604
92605diff --git a/mm/madvise.c b/mm/madvise.c
92606index a402f8f..f5e5daa 100644
92607--- a/mm/madvise.c
92608+++ b/mm/madvise.c
92609@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92610 pgoff_t pgoff;
92611 unsigned long new_flags = vma->vm_flags;
92612
92613+#ifdef CONFIG_PAX_SEGMEXEC
92614+ struct vm_area_struct *vma_m;
92615+#endif
92616+
92617 switch (behavior) {
92618 case MADV_NORMAL:
92619 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92620@@ -126,6 +130,13 @@ success:
92621 /*
92622 * vm_flags is protected by the mmap_sem held in write mode.
92623 */
92624+
92625+#ifdef CONFIG_PAX_SEGMEXEC
92626+ vma_m = pax_find_mirror_vma(vma);
92627+ if (vma_m)
92628+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92629+#endif
92630+
92631 vma->vm_flags = new_flags;
92632
92633 out:
92634@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92635 struct vm_area_struct **prev,
92636 unsigned long start, unsigned long end)
92637 {
92638+
92639+#ifdef CONFIG_PAX_SEGMEXEC
92640+ struct vm_area_struct *vma_m;
92641+#endif
92642+
92643 *prev = vma;
92644 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92645 return -EINVAL;
92646@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92647 zap_page_range(vma, start, end - start, &details);
92648 } else
92649 zap_page_range(vma, start, end - start, NULL);
92650+
92651+#ifdef CONFIG_PAX_SEGMEXEC
92652+ vma_m = pax_find_mirror_vma(vma);
92653+ if (vma_m) {
92654+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92655+ struct zap_details details = {
92656+ .nonlinear_vma = vma_m,
92657+ .last_index = ULONG_MAX,
92658+ };
92659+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92660+ } else
92661+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92662+ }
92663+#endif
92664+
92665 return 0;
92666 }
92667
92668@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92669 if (end < start)
92670 return error;
92671
92672+#ifdef CONFIG_PAX_SEGMEXEC
92673+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92674+ if (end > SEGMEXEC_TASK_SIZE)
92675+ return error;
92676+ } else
92677+#endif
92678+
92679+ if (end > TASK_SIZE)
92680+ return error;
92681+
92682 error = 0;
92683 if (end == start)
92684 return error;
92685diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92686index eb8fb72..ae36cf3 100644
92687--- a/mm/memory-failure.c
92688+++ b/mm/memory-failure.c
92689@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92690
92691 int sysctl_memory_failure_recovery __read_mostly = 1;
92692
92693-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92694+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92695
92696 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92697
92698@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92699 pfn, t->comm, t->pid);
92700 si.si_signo = SIGBUS;
92701 si.si_errno = 0;
92702- si.si_addr = (void *)addr;
92703+ si.si_addr = (void __user *)addr;
92704 #ifdef __ARCH_SI_TRAPNO
92705 si.si_trapno = trapno;
92706 #endif
92707@@ -791,7 +791,7 @@ static struct page_state {
92708 unsigned long res;
92709 char *msg;
92710 int (*action)(struct page *p, unsigned long pfn);
92711-} error_states[] = {
92712+} __do_const error_states[] = {
92713 { reserved, reserved, "reserved kernel", me_kernel },
92714 /*
92715 * free pages are specially detected outside this table:
92716@@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92717 nr_pages = 1 << compound_order(hpage);
92718 else /* normal page or thp */
92719 nr_pages = 1;
92720- atomic_long_add(nr_pages, &num_poisoned_pages);
92721+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92722
92723 /*
92724 * We need/can do nothing about count=0 pages.
92725@@ -1120,7 +1120,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92726 if (PageHWPoison(hpage)) {
92727 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
92728 || (p != hpage && TestSetPageHWPoison(hpage))) {
92729- atomic_long_sub(nr_pages, &num_poisoned_pages);
92730+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92731 unlock_page(hpage);
92732 return 0;
92733 }
92734@@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92735 */
92736 if (!PageHWPoison(p)) {
92737 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
92738- atomic_long_sub(nr_pages, &num_poisoned_pages);
92739+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92740 put_page(hpage);
92741 res = 0;
92742 goto out;
92743 }
92744 if (hwpoison_filter(p)) {
92745 if (TestClearPageHWPoison(p))
92746- atomic_long_sub(nr_pages, &num_poisoned_pages);
92747+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92748 unlock_page(hpage);
92749 put_page(hpage);
92750 return 0;
92751@@ -1415,7 +1415,7 @@ int unpoison_memory(unsigned long pfn)
92752 return 0;
92753 }
92754 if (TestClearPageHWPoison(p))
92755- atomic_long_dec(&num_poisoned_pages);
92756+ atomic_long_dec_unchecked(&num_poisoned_pages);
92757 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92758 return 0;
92759 }
92760@@ -1429,7 +1429,7 @@ int unpoison_memory(unsigned long pfn)
92761 */
92762 if (TestClearPageHWPoison(page)) {
92763 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92764- atomic_long_sub(nr_pages, &num_poisoned_pages);
92765+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92766 freeit = 1;
92767 if (PageHuge(page))
92768 clear_page_hwpoison_huge_page(page);
92769@@ -1554,11 +1554,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92770 if (PageHuge(page)) {
92771 set_page_hwpoison_huge_page(hpage);
92772 dequeue_hwpoisoned_huge_page(hpage);
92773- atomic_long_add(1 << compound_order(hpage),
92774+ atomic_long_add_unchecked(1 << compound_order(hpage),
92775 &num_poisoned_pages);
92776 } else {
92777 SetPageHWPoison(page);
92778- atomic_long_inc(&num_poisoned_pages);
92779+ atomic_long_inc_unchecked(&num_poisoned_pages);
92780 }
92781 }
92782 return ret;
92783@@ -1597,7 +1597,7 @@ static int __soft_offline_page(struct page *page, int flags)
92784 put_page(page);
92785 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92786 SetPageHWPoison(page);
92787- atomic_long_inc(&num_poisoned_pages);
92788+ atomic_long_inc_unchecked(&num_poisoned_pages);
92789 return 0;
92790 }
92791
92792@@ -1648,7 +1648,7 @@ static int __soft_offline_page(struct page *page, int flags)
92793 if (!is_free_buddy_page(page))
92794 pr_info("soft offline: %#lx: page leaked\n",
92795 pfn);
92796- atomic_long_inc(&num_poisoned_pages);
92797+ atomic_long_inc_unchecked(&num_poisoned_pages);
92798 }
92799 } else {
92800 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92801@@ -1722,11 +1722,11 @@ int soft_offline_page(struct page *page, int flags)
92802 if (PageHuge(page)) {
92803 set_page_hwpoison_huge_page(hpage);
92804 dequeue_hwpoisoned_huge_page(hpage);
92805- atomic_long_add(1 << compound_order(hpage),
92806+ atomic_long_add_unchecked(1 << compound_order(hpage),
92807 &num_poisoned_pages);
92808 } else {
92809 SetPageHWPoison(page);
92810- atomic_long_inc(&num_poisoned_pages);
92811+ atomic_long_inc_unchecked(&num_poisoned_pages);
92812 }
92813 }
92814 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92815diff --git a/mm/memory.c b/mm/memory.c
92816index 037b812..948123c 100644
92817--- a/mm/memory.c
92818+++ b/mm/memory.c
92819@@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92820 free_pte_range(tlb, pmd, addr);
92821 } while (pmd++, addr = next, addr != end);
92822
92823+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92824 start &= PUD_MASK;
92825 if (start < floor)
92826 return;
92827@@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92828 pmd = pmd_offset(pud, start);
92829 pud_clear(pud);
92830 pmd_free_tlb(tlb, pmd, start);
92831+#endif
92832+
92833 }
92834
92835 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92836@@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92837 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92838 } while (pud++, addr = next, addr != end);
92839
92840+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92841 start &= PGDIR_MASK;
92842 if (start < floor)
92843 return;
92844@@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92845 pud = pud_offset(pgd, start);
92846 pgd_clear(pgd);
92847 pud_free_tlb(tlb, pud, start);
92848+#endif
92849+
92850 }
92851
92852 /*
92853@@ -1652,12 +1658,6 @@ no_page_table:
92854 return page;
92855 }
92856
92857-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92858-{
92859- return stack_guard_page_start(vma, addr) ||
92860- stack_guard_page_end(vma, addr+PAGE_SIZE);
92861-}
92862-
92863 /**
92864 * __get_user_pages() - pin user pages in memory
92865 * @tsk: task_struct of target task
92866@@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92867
92868 i = 0;
92869
92870- do {
92871+ while (nr_pages) {
92872 struct vm_area_struct *vma;
92873
92874- vma = find_extend_vma(mm, start);
92875+ vma = find_vma(mm, start);
92876 if (!vma && in_gate_area(mm, start)) {
92877 unsigned long pg = start & PAGE_MASK;
92878 pgd_t *pgd;
92879@@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92880 goto next_page;
92881 }
92882
92883- if (!vma)
92884+ if (!vma || start < vma->vm_start)
92885 goto efault;
92886 vm_flags = vma->vm_flags;
92887 if (vm_flags & (VM_IO | VM_PFNMAP))
92888@@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92889 int ret;
92890 unsigned int fault_flags = 0;
92891
92892- /* For mlock, just skip the stack guard page. */
92893- if (foll_flags & FOLL_MLOCK) {
92894- if (stack_guard_page(vma, start))
92895- goto next_page;
92896- }
92897 if (foll_flags & FOLL_WRITE)
92898 fault_flags |= FAULT_FLAG_WRITE;
92899 if (nonblocking)
92900@@ -1932,7 +1927,7 @@ next_page:
92901 start += page_increm * PAGE_SIZE;
92902 nr_pages -= page_increm;
92903 } while (nr_pages && start < vma->vm_end);
92904- } while (nr_pages);
92905+ }
92906 return i;
92907 efault:
92908 return i ? : -EFAULT;
92909@@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92910 page_add_file_rmap(page);
92911 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92912
92913+#ifdef CONFIG_PAX_SEGMEXEC
92914+ pax_mirror_file_pte(vma, addr, page, ptl);
92915+#endif
92916+
92917 retval = 0;
92918 pte_unmap_unlock(pte, ptl);
92919 return retval;
92920@@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92921 if (!page_count(page))
92922 return -EINVAL;
92923 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92924+
92925+#ifdef CONFIG_PAX_SEGMEXEC
92926+ struct vm_area_struct *vma_m;
92927+#endif
92928+
92929 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92930 BUG_ON(vma->vm_flags & VM_PFNMAP);
92931 vma->vm_flags |= VM_MIXEDMAP;
92932+
92933+#ifdef CONFIG_PAX_SEGMEXEC
92934+ vma_m = pax_find_mirror_vma(vma);
92935+ if (vma_m)
92936+ vma_m->vm_flags |= VM_MIXEDMAP;
92937+#endif
92938+
92939 }
92940 return insert_page(vma, addr, page, vma->vm_page_prot);
92941 }
92942@@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92943 unsigned long pfn)
92944 {
92945 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92946+ BUG_ON(vma->vm_mirror);
92947
92948 if (addr < vma->vm_start || addr >= vma->vm_end)
92949 return -EFAULT;
92950@@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92951
92952 BUG_ON(pud_huge(*pud));
92953
92954- pmd = pmd_alloc(mm, pud, addr);
92955+ pmd = (mm == &init_mm) ?
92956+ pmd_alloc_kernel(mm, pud, addr) :
92957+ pmd_alloc(mm, pud, addr);
92958 if (!pmd)
92959 return -ENOMEM;
92960 do {
92961@@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92962 unsigned long next;
92963 int err;
92964
92965- pud = pud_alloc(mm, pgd, addr);
92966+ pud = (mm == &init_mm) ?
92967+ pud_alloc_kernel(mm, pgd, addr) :
92968+ pud_alloc(mm, pgd, addr);
92969 if (!pud)
92970 return -ENOMEM;
92971 do {
92972@@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
92973 return ret;
92974 }
92975
92976+#ifdef CONFIG_PAX_SEGMEXEC
92977+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92978+{
92979+ struct mm_struct *mm = vma->vm_mm;
92980+ spinlock_t *ptl;
92981+ pte_t *pte, entry;
92982+
92983+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92984+ entry = *pte;
92985+ if (!pte_present(entry)) {
92986+ if (!pte_none(entry)) {
92987+ BUG_ON(pte_file(entry));
92988+ free_swap_and_cache(pte_to_swp_entry(entry));
92989+ pte_clear_not_present_full(mm, address, pte, 0);
92990+ }
92991+ } else {
92992+ struct page *page;
92993+
92994+ flush_cache_page(vma, address, pte_pfn(entry));
92995+ entry = ptep_clear_flush(vma, address, pte);
92996+ BUG_ON(pte_dirty(entry));
92997+ page = vm_normal_page(vma, address, entry);
92998+ if (page) {
92999+ update_hiwater_rss(mm);
93000+ if (PageAnon(page))
93001+ dec_mm_counter_fast(mm, MM_ANONPAGES);
93002+ else
93003+ dec_mm_counter_fast(mm, MM_FILEPAGES);
93004+ page_remove_rmap(page);
93005+ page_cache_release(page);
93006+ }
93007+ }
93008+ pte_unmap_unlock(pte, ptl);
93009+}
93010+
93011+/* PaX: if vma is mirrored, synchronize the mirror's PTE
93012+ *
93013+ * the ptl of the lower mapped page is held on entry and is not released on exit
93014+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
93015+ */
93016+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93017+{
93018+ struct mm_struct *mm = vma->vm_mm;
93019+ unsigned long address_m;
93020+ spinlock_t *ptl_m;
93021+ struct vm_area_struct *vma_m;
93022+ pmd_t *pmd_m;
93023+ pte_t *pte_m, entry_m;
93024+
93025+ BUG_ON(!page_m || !PageAnon(page_m));
93026+
93027+ vma_m = pax_find_mirror_vma(vma);
93028+ if (!vma_m)
93029+ return;
93030+
93031+ BUG_ON(!PageLocked(page_m));
93032+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93033+ address_m = address + SEGMEXEC_TASK_SIZE;
93034+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93035+ pte_m = pte_offset_map(pmd_m, address_m);
93036+ ptl_m = pte_lockptr(mm, pmd_m);
93037+ if (ptl != ptl_m) {
93038+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93039+ if (!pte_none(*pte_m))
93040+ goto out;
93041+ }
93042+
93043+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93044+ page_cache_get(page_m);
93045+ page_add_anon_rmap(page_m, vma_m, address_m);
93046+ inc_mm_counter_fast(mm, MM_ANONPAGES);
93047+ set_pte_at(mm, address_m, pte_m, entry_m);
93048+ update_mmu_cache(vma_m, address_m, pte_m);
93049+out:
93050+ if (ptl != ptl_m)
93051+ spin_unlock(ptl_m);
93052+ pte_unmap(pte_m);
93053+ unlock_page(page_m);
93054+}
93055+
93056+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93057+{
93058+ struct mm_struct *mm = vma->vm_mm;
93059+ unsigned long address_m;
93060+ spinlock_t *ptl_m;
93061+ struct vm_area_struct *vma_m;
93062+ pmd_t *pmd_m;
93063+ pte_t *pte_m, entry_m;
93064+
93065+ BUG_ON(!page_m || PageAnon(page_m));
93066+
93067+ vma_m = pax_find_mirror_vma(vma);
93068+ if (!vma_m)
93069+ return;
93070+
93071+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93072+ address_m = address + SEGMEXEC_TASK_SIZE;
93073+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93074+ pte_m = pte_offset_map(pmd_m, address_m);
93075+ ptl_m = pte_lockptr(mm, pmd_m);
93076+ if (ptl != ptl_m) {
93077+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93078+ if (!pte_none(*pte_m))
93079+ goto out;
93080+ }
93081+
93082+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93083+ page_cache_get(page_m);
93084+ page_add_file_rmap(page_m);
93085+ inc_mm_counter_fast(mm, MM_FILEPAGES);
93086+ set_pte_at(mm, address_m, pte_m, entry_m);
93087+ update_mmu_cache(vma_m, address_m, pte_m);
93088+out:
93089+ if (ptl != ptl_m)
93090+ spin_unlock(ptl_m);
93091+ pte_unmap(pte_m);
93092+}
93093+
93094+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93095+{
93096+ struct mm_struct *mm = vma->vm_mm;
93097+ unsigned long address_m;
93098+ spinlock_t *ptl_m;
93099+ struct vm_area_struct *vma_m;
93100+ pmd_t *pmd_m;
93101+ pte_t *pte_m, entry_m;
93102+
93103+ vma_m = pax_find_mirror_vma(vma);
93104+ if (!vma_m)
93105+ return;
93106+
93107+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93108+ address_m = address + SEGMEXEC_TASK_SIZE;
93109+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93110+ pte_m = pte_offset_map(pmd_m, address_m);
93111+ ptl_m = pte_lockptr(mm, pmd_m);
93112+ if (ptl != ptl_m) {
93113+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93114+ if (!pte_none(*pte_m))
93115+ goto out;
93116+ }
93117+
93118+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93119+ set_pte_at(mm, address_m, pte_m, entry_m);
93120+out:
93121+ if (ptl != ptl_m)
93122+ spin_unlock(ptl_m);
93123+ pte_unmap(pte_m);
93124+}
93125+
93126+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93127+{
93128+ struct page *page_m;
93129+ pte_t entry;
93130+
93131+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93132+ goto out;
93133+
93134+ entry = *pte;
93135+ page_m = vm_normal_page(vma, address, entry);
93136+ if (!page_m)
93137+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93138+ else if (PageAnon(page_m)) {
93139+ if (pax_find_mirror_vma(vma)) {
93140+ pte_unmap_unlock(pte, ptl);
93141+ lock_page(page_m);
93142+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93143+ if (pte_same(entry, *pte))
93144+ pax_mirror_anon_pte(vma, address, page_m, ptl);
93145+ else
93146+ unlock_page(page_m);
93147+ }
93148+ } else
93149+ pax_mirror_file_pte(vma, address, page_m, ptl);
93150+
93151+out:
93152+ pte_unmap_unlock(pte, ptl);
93153+}
93154+#endif
93155+
93156 /*
93157 * This routine handles present pages, when users try to write
93158 * to a shared page. It is done by copying the page to a new address
93159@@ -2860,6 +3056,12 @@ gotten:
93160 */
93161 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93162 if (likely(pte_same(*page_table, orig_pte))) {
93163+
93164+#ifdef CONFIG_PAX_SEGMEXEC
93165+ if (pax_find_mirror_vma(vma))
93166+ BUG_ON(!trylock_page(new_page));
93167+#endif
93168+
93169 if (old_page) {
93170 if (!PageAnon(old_page)) {
93171 dec_mm_counter_fast(mm, MM_FILEPAGES);
93172@@ -2911,6 +3113,10 @@ gotten:
93173 page_remove_rmap(old_page);
93174 }
93175
93176+#ifdef CONFIG_PAX_SEGMEXEC
93177+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93178+#endif
93179+
93180 /* Free the old page.. */
93181 new_page = old_page;
93182 ret |= VM_FAULT_WRITE;
93183@@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93184 swap_free(entry);
93185 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93186 try_to_free_swap(page);
93187+
93188+#ifdef CONFIG_PAX_SEGMEXEC
93189+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93190+#endif
93191+
93192 unlock_page(page);
93193 if (page != swapcache) {
93194 /*
93195@@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93196
93197 /* No need to invalidate - it was non-present before */
93198 update_mmu_cache(vma, address, page_table);
93199+
93200+#ifdef CONFIG_PAX_SEGMEXEC
93201+ pax_mirror_anon_pte(vma, address, page, ptl);
93202+#endif
93203+
93204 unlock:
93205 pte_unmap_unlock(page_table, ptl);
93206 out:
93207@@ -3226,40 +3442,6 @@ out_release:
93208 }
93209
93210 /*
93211- * This is like a special single-page "expand_{down|up}wards()",
93212- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93213- * doesn't hit another vma.
93214- */
93215-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93216-{
93217- address &= PAGE_MASK;
93218- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93219- struct vm_area_struct *prev = vma->vm_prev;
93220-
93221- /*
93222- * Is there a mapping abutting this one below?
93223- *
93224- * That's only ok if it's the same stack mapping
93225- * that has gotten split..
93226- */
93227- if (prev && prev->vm_end == address)
93228- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93229-
93230- expand_downwards(vma, address - PAGE_SIZE);
93231- }
93232- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93233- struct vm_area_struct *next = vma->vm_next;
93234-
93235- /* As VM_GROWSDOWN but s/below/above/ */
93236- if (next && next->vm_start == address + PAGE_SIZE)
93237- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93238-
93239- expand_upwards(vma, address + PAGE_SIZE);
93240- }
93241- return 0;
93242-}
93243-
93244-/*
93245 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93246 * but allow concurrent faults), and pte mapped but not yet locked.
93247 * We return with mmap_sem still held, but pte unmapped and unlocked.
93248@@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93249 unsigned long address, pte_t *page_table, pmd_t *pmd,
93250 unsigned int flags)
93251 {
93252- struct page *page;
93253+ struct page *page = NULL;
93254 spinlock_t *ptl;
93255 pte_t entry;
93256
93257- pte_unmap(page_table);
93258-
93259- /* Check if we need to add a guard page to the stack */
93260- if (check_stack_guard_page(vma, address) < 0)
93261- return VM_FAULT_SIGBUS;
93262-
93263- /* Use the zero-page for reads */
93264 if (!(flags & FAULT_FLAG_WRITE)) {
93265 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93266 vma->vm_page_prot));
93267- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93268+ ptl = pte_lockptr(mm, pmd);
93269+ spin_lock(ptl);
93270 if (!pte_none(*page_table))
93271 goto unlock;
93272 goto setpte;
93273 }
93274
93275 /* Allocate our own private page. */
93276+ pte_unmap(page_table);
93277+
93278 if (unlikely(anon_vma_prepare(vma)))
93279 goto oom;
93280 page = alloc_zeroed_user_highpage_movable(vma, address);
93281@@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93282 if (!pte_none(*page_table))
93283 goto release;
93284
93285+#ifdef CONFIG_PAX_SEGMEXEC
93286+ if (pax_find_mirror_vma(vma))
93287+ BUG_ON(!trylock_page(page));
93288+#endif
93289+
93290 inc_mm_counter_fast(mm, MM_ANONPAGES);
93291 page_add_new_anon_rmap(page, vma, address);
93292 setpte:
93293@@ -3319,6 +3502,12 @@ setpte:
93294
93295 /* No need to invalidate - it was non-present before */
93296 update_mmu_cache(vma, address, page_table);
93297+
93298+#ifdef CONFIG_PAX_SEGMEXEC
93299+ if (page)
93300+ pax_mirror_anon_pte(vma, address, page, ptl);
93301+#endif
93302+
93303 unlock:
93304 pte_unmap_unlock(page_table, ptl);
93305 return 0;
93306@@ -3535,6 +3724,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93307 return ret;
93308 }
93309 do_set_pte(vma, address, fault_page, pte, false, false);
93310+
93311+#ifdef CONFIG_PAX_SEGMEXEC
93312+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93313+#endif
93314+
93315 unlock_page(fault_page);
93316 unlock_out:
93317 pte_unmap_unlock(pte, ptl);
93318@@ -3576,7 +3770,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93319 page_cache_release(fault_page);
93320 goto uncharge_out;
93321 }
93322+
93323+#ifdef CONFIG_PAX_SEGMEXEC
93324+ if (pax_find_mirror_vma(vma))
93325+ BUG_ON(!trylock_page(new_page));
93326+#endif
93327+
93328 do_set_pte(vma, address, new_page, pte, true, true);
93329+
93330+#ifdef CONFIG_PAX_SEGMEXEC
93331+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93332+#endif
93333+
93334 pte_unmap_unlock(pte, ptl);
93335 unlock_page(fault_page);
93336 page_cache_release(fault_page);
93337@@ -3624,6 +3829,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93338 return ret;
93339 }
93340 do_set_pte(vma, address, fault_page, pte, true, false);
93341+
93342+#ifdef CONFIG_PAX_SEGMEXEC
93343+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93344+#endif
93345+
93346 pte_unmap_unlock(pte, ptl);
93347
93348 if (set_page_dirty(fault_page))
93349@@ -3854,6 +4064,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93350 if (flags & FAULT_FLAG_WRITE)
93351 flush_tlb_fix_spurious_fault(vma, address);
93352 }
93353+
93354+#ifdef CONFIG_PAX_SEGMEXEC
93355+ pax_mirror_pte(vma, address, pte, pmd, ptl);
93356+ return 0;
93357+#endif
93358+
93359 unlock:
93360 pte_unmap_unlock(pte, ptl);
93361 return 0;
93362@@ -3870,9 +4086,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93363 pmd_t *pmd;
93364 pte_t *pte;
93365
93366+#ifdef CONFIG_PAX_SEGMEXEC
93367+ struct vm_area_struct *vma_m;
93368+#endif
93369+
93370 if (unlikely(is_vm_hugetlb_page(vma)))
93371 return hugetlb_fault(mm, vma, address, flags);
93372
93373+#ifdef CONFIG_PAX_SEGMEXEC
93374+ vma_m = pax_find_mirror_vma(vma);
93375+ if (vma_m) {
93376+ unsigned long address_m;
93377+ pgd_t *pgd_m;
93378+ pud_t *pud_m;
93379+ pmd_t *pmd_m;
93380+
93381+ if (vma->vm_start > vma_m->vm_start) {
93382+ address_m = address;
93383+ address -= SEGMEXEC_TASK_SIZE;
93384+ vma = vma_m;
93385+ } else
93386+ address_m = address + SEGMEXEC_TASK_SIZE;
93387+
93388+ pgd_m = pgd_offset(mm, address_m);
93389+ pud_m = pud_alloc(mm, pgd_m, address_m);
93390+ if (!pud_m)
93391+ return VM_FAULT_OOM;
93392+ pmd_m = pmd_alloc(mm, pud_m, address_m);
93393+ if (!pmd_m)
93394+ return VM_FAULT_OOM;
93395+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93396+ return VM_FAULT_OOM;
93397+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93398+ }
93399+#endif
93400+
93401 pgd = pgd_offset(mm, address);
93402 pud = pud_alloc(mm, pgd, address);
93403 if (!pud)
93404@@ -4003,6 +4251,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93405 spin_unlock(&mm->page_table_lock);
93406 return 0;
93407 }
93408+
93409+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93410+{
93411+ pud_t *new = pud_alloc_one(mm, address);
93412+ if (!new)
93413+ return -ENOMEM;
93414+
93415+ smp_wmb(); /* See comment in __pte_alloc */
93416+
93417+ spin_lock(&mm->page_table_lock);
93418+ if (pgd_present(*pgd)) /* Another has populated it */
93419+ pud_free(mm, new);
93420+ else
93421+ pgd_populate_kernel(mm, pgd, new);
93422+ spin_unlock(&mm->page_table_lock);
93423+ return 0;
93424+}
93425 #endif /* __PAGETABLE_PUD_FOLDED */
93426
93427 #ifndef __PAGETABLE_PMD_FOLDED
93428@@ -4033,6 +4298,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93429 spin_unlock(&mm->page_table_lock);
93430 return 0;
93431 }
93432+
93433+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93434+{
93435+ pmd_t *new = pmd_alloc_one(mm, address);
93436+ if (!new)
93437+ return -ENOMEM;
93438+
93439+ smp_wmb(); /* See comment in __pte_alloc */
93440+
93441+ spin_lock(&mm->page_table_lock);
93442+#ifndef __ARCH_HAS_4LEVEL_HACK
93443+ if (pud_present(*pud)) /* Another has populated it */
93444+ pmd_free(mm, new);
93445+ else
93446+ pud_populate_kernel(mm, pud, new);
93447+#else
93448+ if (pgd_present(*pud)) /* Another has populated it */
93449+ pmd_free(mm, new);
93450+ else
93451+ pgd_populate_kernel(mm, pud, new);
93452+#endif /* __ARCH_HAS_4LEVEL_HACK */
93453+ spin_unlock(&mm->page_table_lock);
93454+ return 0;
93455+}
93456 #endif /* __PAGETABLE_PMD_FOLDED */
93457
93458 #if !defined(__HAVE_ARCH_GATE_AREA)
93459@@ -4046,7 +4335,7 @@ static int __init gate_vma_init(void)
93460 gate_vma.vm_start = FIXADDR_USER_START;
93461 gate_vma.vm_end = FIXADDR_USER_END;
93462 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93463- gate_vma.vm_page_prot = __P101;
93464+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93465
93466 return 0;
93467 }
93468@@ -4180,8 +4469,8 @@ out:
93469 return ret;
93470 }
93471
93472-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93473- void *buf, int len, int write)
93474+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93475+ void *buf, size_t len, int write)
93476 {
93477 resource_size_t phys_addr;
93478 unsigned long prot = 0;
93479@@ -4207,8 +4496,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93480 * Access another process' address space as given in mm. If non-NULL, use the
93481 * given task for page fault accounting.
93482 */
93483-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93484- unsigned long addr, void *buf, int len, int write)
93485+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93486+ unsigned long addr, void *buf, size_t len, int write)
93487 {
93488 struct vm_area_struct *vma;
93489 void *old_buf = buf;
93490@@ -4216,7 +4505,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93491 down_read(&mm->mmap_sem);
93492 /* ignore errors, just check how much was successfully transferred */
93493 while (len) {
93494- int bytes, ret, offset;
93495+ ssize_t bytes, ret, offset;
93496 void *maddr;
93497 struct page *page = NULL;
93498
93499@@ -4275,8 +4564,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93500 *
93501 * The caller must hold a reference on @mm.
93502 */
93503-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93504- void *buf, int len, int write)
93505+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93506+ void *buf, size_t len, int write)
93507 {
93508 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93509 }
93510@@ -4286,11 +4575,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93511 * Source/target buffer must be kernel space,
93512 * Do not walk the page table directly, use get_user_pages
93513 */
93514-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93515- void *buf, int len, int write)
93516+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93517+ void *buf, size_t len, int write)
93518 {
93519 struct mm_struct *mm;
93520- int ret;
93521+ ssize_t ret;
93522
93523 mm = get_task_mm(tsk);
93524 if (!mm)
93525diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93526index 30cc47f8..c12ef34 100644
93527--- a/mm/mempolicy.c
93528+++ b/mm/mempolicy.c
93529@@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93530 unsigned long vmstart;
93531 unsigned long vmend;
93532
93533+#ifdef CONFIG_PAX_SEGMEXEC
93534+ struct vm_area_struct *vma_m;
93535+#endif
93536+
93537 vma = find_vma(mm, start);
93538 if (!vma || vma->vm_start > start)
93539 return -EFAULT;
93540@@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93541 err = vma_replace_policy(vma, new_pol);
93542 if (err)
93543 goto out;
93544+
93545+#ifdef CONFIG_PAX_SEGMEXEC
93546+ vma_m = pax_find_mirror_vma(vma);
93547+ if (vma_m) {
93548+ err = vma_replace_policy(vma_m, new_pol);
93549+ if (err)
93550+ goto out;
93551+ }
93552+#endif
93553+
93554 }
93555
93556 out:
93557@@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93558
93559 if (end < start)
93560 return -EINVAL;
93561+
93562+#ifdef CONFIG_PAX_SEGMEXEC
93563+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93564+ if (end > SEGMEXEC_TASK_SIZE)
93565+ return -EINVAL;
93566+ } else
93567+#endif
93568+
93569+ if (end > TASK_SIZE)
93570+ return -EINVAL;
93571+
93572 if (end == start)
93573 return 0;
93574
93575@@ -1453,8 +1478,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93576 */
93577 tcred = __task_cred(task);
93578 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93579- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93580- !capable(CAP_SYS_NICE)) {
93581+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93582 rcu_read_unlock();
93583 err = -EPERM;
93584 goto out_put;
93585@@ -1485,6 +1509,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93586 goto out;
93587 }
93588
93589+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93590+ if (mm != current->mm &&
93591+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93592+ mmput(mm);
93593+ err = -EPERM;
93594+ goto out;
93595+ }
93596+#endif
93597+
93598 err = do_migrate_pages(mm, old, new,
93599 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93600
93601diff --git a/mm/migrate.c b/mm/migrate.c
93602index bed4880..a493f67 100644
93603--- a/mm/migrate.c
93604+++ b/mm/migrate.c
93605@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93606 */
93607 tcred = __task_cred(task);
93608 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93609- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93610- !capable(CAP_SYS_NICE)) {
93611+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93612 rcu_read_unlock();
93613 err = -EPERM;
93614 goto out;
93615diff --git a/mm/mlock.c b/mm/mlock.c
93616index b1eb536..091d154 100644
93617--- a/mm/mlock.c
93618+++ b/mm/mlock.c
93619@@ -14,6 +14,7 @@
93620 #include <linux/pagevec.h>
93621 #include <linux/mempolicy.h>
93622 #include <linux/syscalls.h>
93623+#include <linux/security.h>
93624 #include <linux/sched.h>
93625 #include <linux/export.h>
93626 #include <linux/rmap.h>
93627@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93628 {
93629 unsigned long nstart, end, tmp;
93630 struct vm_area_struct * vma, * prev;
93631- int error;
93632+ int error = 0;
93633
93634 VM_BUG_ON(start & ~PAGE_MASK);
93635 VM_BUG_ON(len != PAGE_ALIGN(len));
93636@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93637 return -EINVAL;
93638 if (end == start)
93639 return 0;
93640+ if (end > TASK_SIZE)
93641+ return -EINVAL;
93642+
93643 vma = find_vma(current->mm, start);
93644 if (!vma || vma->vm_start > start)
93645 return -ENOMEM;
93646@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93647 for (nstart = start ; ; ) {
93648 vm_flags_t newflags;
93649
93650+#ifdef CONFIG_PAX_SEGMEXEC
93651+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93652+ break;
93653+#endif
93654+
93655 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93656
93657 newflags = vma->vm_flags & ~VM_LOCKED;
93658@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93659 locked += current->mm->locked_vm;
93660
93661 /* check against resource limits */
93662+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93663 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93664 error = do_mlock(start, len, 1);
93665
93666@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93667 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93668 vm_flags_t newflags;
93669
93670+#ifdef CONFIG_PAX_SEGMEXEC
93671+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93672+ break;
93673+#endif
93674+
93675 newflags = vma->vm_flags & ~VM_LOCKED;
93676 if (flags & MCL_CURRENT)
93677 newflags |= VM_LOCKED;
93678@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93679 lock_limit >>= PAGE_SHIFT;
93680
93681 ret = -ENOMEM;
93682+
93683+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93684+
93685 down_write(&current->mm->mmap_sem);
93686-
93687 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93688 capable(CAP_IPC_LOCK))
93689 ret = do_mlockall(flags);
93690diff --git a/mm/mmap.c b/mm/mmap.c
93691index b1202cf..ee487f8 100644
93692--- a/mm/mmap.c
93693+++ b/mm/mmap.c
93694@@ -37,6 +37,7 @@
93695 #include <linux/sched/sysctl.h>
93696 #include <linux/notifier.h>
93697 #include <linux/memory.h>
93698+#include <linux/random.h>
93699
93700 #include <asm/uaccess.h>
93701 #include <asm/cacheflush.h>
93702@@ -53,6 +54,16 @@
93703 #define arch_rebalance_pgtables(addr, len) (addr)
93704 #endif
93705
93706+static inline void verify_mm_writelocked(struct mm_struct *mm)
93707+{
93708+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93709+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93710+ up_read(&mm->mmap_sem);
93711+ BUG();
93712+ }
93713+#endif
93714+}
93715+
93716 static void unmap_region(struct mm_struct *mm,
93717 struct vm_area_struct *vma, struct vm_area_struct *prev,
93718 unsigned long start, unsigned long end);
93719@@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
93720 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93721 *
93722 */
93723-pgprot_t protection_map[16] = {
93724+pgprot_t protection_map[16] __read_only = {
93725 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93726 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93727 };
93728
93729-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93730+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93731 {
93732- return __pgprot(pgprot_val(protection_map[vm_flags &
93733+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93734 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93735 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93736+
93737+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93738+ if (!(__supported_pte_mask & _PAGE_NX) &&
93739+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93740+ (vm_flags & (VM_READ | VM_WRITE)))
93741+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93742+#endif
93743+
93744+ return prot;
93745 }
93746 EXPORT_SYMBOL(vm_get_page_prot);
93747
93748@@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93749 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93750 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93751 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93752+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93753 /*
93754 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93755 * other variables. It can be updated by several CPUs frequently.
93756@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93757 struct vm_area_struct *next = vma->vm_next;
93758
93759 might_sleep();
93760+ BUG_ON(vma->vm_mirror);
93761 if (vma->vm_ops && vma->vm_ops->close)
93762 vma->vm_ops->close(vma);
93763 if (vma->vm_file)
93764@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93765 * not page aligned -Ram Gupta
93766 */
93767 rlim = rlimit(RLIMIT_DATA);
93768+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93769 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93770 (mm->end_data - mm->start_data) > rlim)
93771 goto out;
93772@@ -942,6 +965,12 @@ static int
93773 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93774 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93775 {
93776+
93777+#ifdef CONFIG_PAX_SEGMEXEC
93778+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93779+ return 0;
93780+#endif
93781+
93782 if (is_mergeable_vma(vma, file, vm_flags) &&
93783 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93784 if (vma->vm_pgoff == vm_pgoff)
93785@@ -961,6 +990,12 @@ static int
93786 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93787 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93788 {
93789+
93790+#ifdef CONFIG_PAX_SEGMEXEC
93791+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93792+ return 0;
93793+#endif
93794+
93795 if (is_mergeable_vma(vma, file, vm_flags) &&
93796 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93797 pgoff_t vm_pglen;
93798@@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93799 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93800 struct vm_area_struct *prev, unsigned long addr,
93801 unsigned long end, unsigned long vm_flags,
93802- struct anon_vma *anon_vma, struct file *file,
93803+ struct anon_vma *anon_vma, struct file *file,
93804 pgoff_t pgoff, struct mempolicy *policy)
93805 {
93806 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93807 struct vm_area_struct *area, *next;
93808 int err;
93809
93810+#ifdef CONFIG_PAX_SEGMEXEC
93811+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93812+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93813+
93814+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93815+#endif
93816+
93817 /*
93818 * We later require that vma->vm_flags == vm_flags,
93819 * so this tests vma->vm_flags & VM_SPECIAL, too.
93820@@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93821 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93822 next = next->vm_next;
93823
93824+#ifdef CONFIG_PAX_SEGMEXEC
93825+ if (prev)
93826+ prev_m = pax_find_mirror_vma(prev);
93827+ if (area)
93828+ area_m = pax_find_mirror_vma(area);
93829+ if (next)
93830+ next_m = pax_find_mirror_vma(next);
93831+#endif
93832+
93833 /*
93834 * Can it merge with the predecessor?
93835 */
93836@@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93837 /* cases 1, 6 */
93838 err = vma_adjust(prev, prev->vm_start,
93839 next->vm_end, prev->vm_pgoff, NULL);
93840- } else /* cases 2, 5, 7 */
93841+
93842+#ifdef CONFIG_PAX_SEGMEXEC
93843+ if (!err && prev_m)
93844+ err = vma_adjust(prev_m, prev_m->vm_start,
93845+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93846+#endif
93847+
93848+ } else { /* cases 2, 5, 7 */
93849 err = vma_adjust(prev, prev->vm_start,
93850 end, prev->vm_pgoff, NULL);
93851+
93852+#ifdef CONFIG_PAX_SEGMEXEC
93853+ if (!err && prev_m)
93854+ err = vma_adjust(prev_m, prev_m->vm_start,
93855+ end_m, prev_m->vm_pgoff, NULL);
93856+#endif
93857+
93858+ }
93859 if (err)
93860 return NULL;
93861 khugepaged_enter_vma_merge(prev);
93862@@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93863 mpol_equal(policy, vma_policy(next)) &&
93864 can_vma_merge_before(next, vm_flags,
93865 anon_vma, file, pgoff+pglen)) {
93866- if (prev && addr < prev->vm_end) /* case 4 */
93867+ if (prev && addr < prev->vm_end) { /* case 4 */
93868 err = vma_adjust(prev, prev->vm_start,
93869 addr, prev->vm_pgoff, NULL);
93870- else /* cases 3, 8 */
93871+
93872+#ifdef CONFIG_PAX_SEGMEXEC
93873+ if (!err && prev_m)
93874+ err = vma_adjust(prev_m, prev_m->vm_start,
93875+ addr_m, prev_m->vm_pgoff, NULL);
93876+#endif
93877+
93878+ } else { /* cases 3, 8 */
93879 err = vma_adjust(area, addr, next->vm_end,
93880 next->vm_pgoff - pglen, NULL);
93881+
93882+#ifdef CONFIG_PAX_SEGMEXEC
93883+ if (!err && area_m)
93884+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93885+ next_m->vm_pgoff - pglen, NULL);
93886+#endif
93887+
93888+ }
93889 if (err)
93890 return NULL;
93891 khugepaged_enter_vma_merge(area);
93892@@ -1174,8 +1255,10 @@ none:
93893 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93894 struct file *file, long pages)
93895 {
93896- const unsigned long stack_flags
93897- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93898+
93899+#ifdef CONFIG_PAX_RANDMMAP
93900+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93901+#endif
93902
93903 mm->total_vm += pages;
93904
93905@@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93906 mm->shared_vm += pages;
93907 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93908 mm->exec_vm += pages;
93909- } else if (flags & stack_flags)
93910+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93911 mm->stack_vm += pages;
93912 }
93913 #endif /* CONFIG_PROC_FS */
93914@@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93915 locked += mm->locked_vm;
93916 lock_limit = rlimit(RLIMIT_MEMLOCK);
93917 lock_limit >>= PAGE_SHIFT;
93918+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93919 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93920 return -EAGAIN;
93921 }
93922@@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93923 * (the exception is when the underlying filesystem is noexec
93924 * mounted, in which case we dont add PROT_EXEC.)
93925 */
93926- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93927+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93928 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93929 prot |= PROT_EXEC;
93930
93931@@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93932 /* Obtain the address to map to. we verify (or select) it and ensure
93933 * that it represents a valid section of the address space.
93934 */
93935- addr = get_unmapped_area(file, addr, len, pgoff, flags);
93936+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93937 if (addr & ~PAGE_MASK)
93938 return addr;
93939
93940@@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93941 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93942 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93943
93944+#ifdef CONFIG_PAX_MPROTECT
93945+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93946+
93947+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93948+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93949+ mm->binfmt->handle_mmap)
93950+ mm->binfmt->handle_mmap(file);
93951+#endif
93952+
93953+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93954+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93955+ gr_log_rwxmmap(file);
93956+
93957+#ifdef CONFIG_PAX_EMUPLT
93958+ vm_flags &= ~VM_EXEC;
93959+#else
93960+ return -EPERM;
93961+#endif
93962+
93963+ }
93964+
93965+ if (!(vm_flags & VM_EXEC))
93966+ vm_flags &= ~VM_MAYEXEC;
93967+#else
93968+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93969+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93970+#endif
93971+ else
93972+ vm_flags &= ~VM_MAYWRITE;
93973+ }
93974+#endif
93975+
93976+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93977+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93978+ vm_flags &= ~VM_PAGEEXEC;
93979+#endif
93980+
93981 if (flags & MAP_LOCKED)
93982 if (!can_do_mlock())
93983 return -EPERM;
93984@@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93985 vm_flags |= VM_NORESERVE;
93986 }
93987
93988+ if (!gr_acl_handle_mmap(file, prot))
93989+ return -EACCES;
93990+
93991 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93992 if (!IS_ERR_VALUE(addr) &&
93993 ((vm_flags & VM_LOCKED) ||
93994@@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93995 vm_flags_t vm_flags = vma->vm_flags;
93996
93997 /* If it was private or non-writable, the write bit is already clear */
93998- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93999+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
94000 return 0;
94001
94002 /* The backer wishes to know when pages are first written to? */
94003@@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94004 struct rb_node **rb_link, *rb_parent;
94005 unsigned long charged = 0;
94006
94007+#ifdef CONFIG_PAX_SEGMEXEC
94008+ struct vm_area_struct *vma_m = NULL;
94009+#endif
94010+
94011+ /*
94012+ * mm->mmap_sem is required to protect against another thread
94013+ * changing the mappings in case we sleep.
94014+ */
94015+ verify_mm_writelocked(mm);
94016+
94017 /* Check against address space limit. */
94018+
94019+#ifdef CONFIG_PAX_RANDMMAP
94020+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94021+#endif
94022+
94023 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
94024 unsigned long nr_pages;
94025
94026@@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94027
94028 /* Clear old maps */
94029 error = -ENOMEM;
94030-munmap_back:
94031 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94032 if (do_munmap(mm, addr, len))
94033 return -ENOMEM;
94034- goto munmap_back;
94035+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94036 }
94037
94038 /*
94039@@ -1556,6 +1694,16 @@ munmap_back:
94040 goto unacct_error;
94041 }
94042
94043+#ifdef CONFIG_PAX_SEGMEXEC
94044+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
94045+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94046+ if (!vma_m) {
94047+ error = -ENOMEM;
94048+ goto free_vma;
94049+ }
94050+ }
94051+#endif
94052+
94053 vma->vm_mm = mm;
94054 vma->vm_start = addr;
94055 vma->vm_end = addr + len;
94056@@ -1575,6 +1723,13 @@ munmap_back:
94057 if (error)
94058 goto unmap_and_free_vma;
94059
94060+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94061+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
94062+ vma->vm_flags |= VM_PAGEEXEC;
94063+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94064+ }
94065+#endif
94066+
94067 /* Can addr have changed??
94068 *
94069 * Answer: Yes, several device drivers can do it in their
94070@@ -1608,6 +1763,12 @@ munmap_back:
94071 }
94072
94073 vma_link(mm, vma, prev, rb_link, rb_parent);
94074+
94075+#ifdef CONFIG_PAX_SEGMEXEC
94076+ if (vma_m)
94077+ BUG_ON(pax_mirror_vma(vma_m, vma));
94078+#endif
94079+
94080 /* Once vma denies write, undo our temporary denial count */
94081 if (vm_flags & VM_DENYWRITE)
94082 allow_write_access(file);
94083@@ -1616,6 +1777,7 @@ out:
94084 perf_event_mmap(vma);
94085
94086 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94087+ track_exec_limit(mm, addr, addr + len, vm_flags);
94088 if (vm_flags & VM_LOCKED) {
94089 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94090 vma == get_gate_vma(current->mm)))
94091@@ -1648,6 +1810,12 @@ unmap_and_free_vma:
94092 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94093 charged = 0;
94094 free_vma:
94095+
94096+#ifdef CONFIG_PAX_SEGMEXEC
94097+ if (vma_m)
94098+ kmem_cache_free(vm_area_cachep, vma_m);
94099+#endif
94100+
94101 kmem_cache_free(vm_area_cachep, vma);
94102 unacct_error:
94103 if (charged)
94104@@ -1655,7 +1823,63 @@ unacct_error:
94105 return error;
94106 }
94107
94108-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94109+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94110+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94111+{
94112+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94113+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94114+
94115+ return 0;
94116+}
94117+#endif
94118+
94119+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94120+{
94121+ if (!vma) {
94122+#ifdef CONFIG_STACK_GROWSUP
94123+ if (addr > sysctl_heap_stack_gap)
94124+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94125+ else
94126+ vma = find_vma(current->mm, 0);
94127+ if (vma && (vma->vm_flags & VM_GROWSUP))
94128+ return false;
94129+#endif
94130+ return true;
94131+ }
94132+
94133+ if (addr + len > vma->vm_start)
94134+ return false;
94135+
94136+ if (vma->vm_flags & VM_GROWSDOWN)
94137+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94138+#ifdef CONFIG_STACK_GROWSUP
94139+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94140+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94141+#endif
94142+ else if (offset)
94143+ return offset <= vma->vm_start - addr - len;
94144+
94145+ return true;
94146+}
94147+
94148+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94149+{
94150+ if (vma->vm_start < len)
94151+ return -ENOMEM;
94152+
94153+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94154+ if (offset <= vma->vm_start - len)
94155+ return vma->vm_start - len - offset;
94156+ else
94157+ return -ENOMEM;
94158+ }
94159+
94160+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94161+ return vma->vm_start - len - sysctl_heap_stack_gap;
94162+ return -ENOMEM;
94163+}
94164+
94165+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94166 {
94167 /*
94168 * We implement the search by looking for an rbtree node that
94169@@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94170 }
94171 }
94172
94173- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94174+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94175 check_current:
94176 /* Check if current node has a suitable gap */
94177 if (gap_start > high_limit)
94178 return -ENOMEM;
94179+
94180+ if (gap_end - gap_start > info->threadstack_offset)
94181+ gap_start += info->threadstack_offset;
94182+ else
94183+ gap_start = gap_end;
94184+
94185+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94186+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94187+ gap_start += sysctl_heap_stack_gap;
94188+ else
94189+ gap_start = gap_end;
94190+ }
94191+ if (vma->vm_flags & VM_GROWSDOWN) {
94192+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94193+ gap_end -= sysctl_heap_stack_gap;
94194+ else
94195+ gap_end = gap_start;
94196+ }
94197 if (gap_end >= low_limit && gap_end - gap_start >= length)
94198 goto found;
94199
94200@@ -1757,7 +1999,7 @@ found:
94201 return gap_start;
94202 }
94203
94204-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94205+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94206 {
94207 struct mm_struct *mm = current->mm;
94208 struct vm_area_struct *vma;
94209@@ -1811,6 +2053,24 @@ check_current:
94210 gap_end = vma->vm_start;
94211 if (gap_end < low_limit)
94212 return -ENOMEM;
94213+
94214+ if (gap_end - gap_start > info->threadstack_offset)
94215+ gap_end -= info->threadstack_offset;
94216+ else
94217+ gap_end = gap_start;
94218+
94219+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94220+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94221+ gap_start += sysctl_heap_stack_gap;
94222+ else
94223+ gap_start = gap_end;
94224+ }
94225+ if (vma->vm_flags & VM_GROWSDOWN) {
94226+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94227+ gap_end -= sysctl_heap_stack_gap;
94228+ else
94229+ gap_end = gap_start;
94230+ }
94231 if (gap_start <= high_limit && gap_end - gap_start >= length)
94232 goto found;
94233
94234@@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94235 struct mm_struct *mm = current->mm;
94236 struct vm_area_struct *vma;
94237 struct vm_unmapped_area_info info;
94238+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94239
94240 if (len > TASK_SIZE - mmap_min_addr)
94241 return -ENOMEM;
94242@@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94243 if (flags & MAP_FIXED)
94244 return addr;
94245
94246+#ifdef CONFIG_PAX_RANDMMAP
94247+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94248+#endif
94249+
94250 if (addr) {
94251 addr = PAGE_ALIGN(addr);
94252 vma = find_vma(mm, addr);
94253 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94254- (!vma || addr + len <= vma->vm_start))
94255+ check_heap_stack_gap(vma, addr, len, offset))
94256 return addr;
94257 }
94258
94259@@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94260 info.low_limit = mm->mmap_base;
94261 info.high_limit = TASK_SIZE;
94262 info.align_mask = 0;
94263+ info.threadstack_offset = offset;
94264 return vm_unmapped_area(&info);
94265 }
94266 #endif
94267@@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94268 struct mm_struct *mm = current->mm;
94269 unsigned long addr = addr0;
94270 struct vm_unmapped_area_info info;
94271+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94272
94273 /* requested length too big for entire address space */
94274 if (len > TASK_SIZE - mmap_min_addr)
94275@@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94276 if (flags & MAP_FIXED)
94277 return addr;
94278
94279+#ifdef CONFIG_PAX_RANDMMAP
94280+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94281+#endif
94282+
94283 /* requesting a specific address */
94284 if (addr) {
94285 addr = PAGE_ALIGN(addr);
94286 vma = find_vma(mm, addr);
94287 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94288- (!vma || addr + len <= vma->vm_start))
94289+ check_heap_stack_gap(vma, addr, len, offset))
94290 return addr;
94291 }
94292
94293@@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94294 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94295 info.high_limit = mm->mmap_base;
94296 info.align_mask = 0;
94297+ info.threadstack_offset = offset;
94298 addr = vm_unmapped_area(&info);
94299
94300 /*
94301@@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94302 VM_BUG_ON(addr != -ENOMEM);
94303 info.flags = 0;
94304 info.low_limit = TASK_UNMAPPED_BASE;
94305+
94306+#ifdef CONFIG_PAX_RANDMMAP
94307+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94308+ info.low_limit += mm->delta_mmap;
94309+#endif
94310+
94311 info.high_limit = TASK_SIZE;
94312 addr = vm_unmapped_area(&info);
94313 }
94314@@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94315 return vma;
94316 }
94317
94318+#ifdef CONFIG_PAX_SEGMEXEC
94319+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94320+{
94321+ struct vm_area_struct *vma_m;
94322+
94323+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94324+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94325+ BUG_ON(vma->vm_mirror);
94326+ return NULL;
94327+ }
94328+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94329+ vma_m = vma->vm_mirror;
94330+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94331+ BUG_ON(vma->vm_file != vma_m->vm_file);
94332+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94333+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94334+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94335+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94336+ return vma_m;
94337+}
94338+#endif
94339+
94340 /*
94341 * Verify that the stack growth is acceptable and
94342 * update accounting. This is shared with both the
94343@@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94344 return -ENOMEM;
94345
94346 /* Stack limit test */
94347+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94348 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94349 return -ENOMEM;
94350
94351@@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94352 locked = mm->locked_vm + grow;
94353 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94354 limit >>= PAGE_SHIFT;
94355+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94356 if (locked > limit && !capable(CAP_IPC_LOCK))
94357 return -ENOMEM;
94358 }
94359@@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94360 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94361 * vma is the last one with address > vma->vm_end. Have to extend vma.
94362 */
94363+#ifndef CONFIG_IA64
94364+static
94365+#endif
94366 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94367 {
94368 int error;
94369+ bool locknext;
94370
94371 if (!(vma->vm_flags & VM_GROWSUP))
94372 return -EFAULT;
94373
94374+ /* Also guard against wrapping around to address 0. */
94375+ if (address < PAGE_ALIGN(address+1))
94376+ address = PAGE_ALIGN(address+1);
94377+ else
94378+ return -ENOMEM;
94379+
94380 /*
94381 * We must make sure the anon_vma is allocated
94382 * so that the anon_vma locking is not a noop.
94383 */
94384 if (unlikely(anon_vma_prepare(vma)))
94385 return -ENOMEM;
94386+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94387+ if (locknext && anon_vma_prepare(vma->vm_next))
94388+ return -ENOMEM;
94389 vma_lock_anon_vma(vma);
94390+ if (locknext)
94391+ vma_lock_anon_vma(vma->vm_next);
94392
94393 /*
94394 * vma->vm_start/vm_end cannot change under us because the caller
94395 * is required to hold the mmap_sem in read mode. We need the
94396- * anon_vma lock to serialize against concurrent expand_stacks.
94397- * Also guard against wrapping around to address 0.
94398+ * anon_vma locks to serialize against concurrent expand_stacks
94399+ * and expand_upwards.
94400 */
94401- if (address < PAGE_ALIGN(address+4))
94402- address = PAGE_ALIGN(address+4);
94403- else {
94404- vma_unlock_anon_vma(vma);
94405- return -ENOMEM;
94406- }
94407 error = 0;
94408
94409 /* Somebody else might have raced and expanded it already */
94410- if (address > vma->vm_end) {
94411+ 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)
94412+ error = -ENOMEM;
94413+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94414 unsigned long size, grow;
94415
94416 size = address - vma->vm_start;
94417@@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94418 }
94419 }
94420 }
94421+ if (locknext)
94422+ vma_unlock_anon_vma(vma->vm_next);
94423 vma_unlock_anon_vma(vma);
94424 khugepaged_enter_vma_merge(vma);
94425 validate_mm(vma->vm_mm);
94426@@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
94427 unsigned long address)
94428 {
94429 int error;
94430+ bool lockprev = false;
94431+ struct vm_area_struct *prev;
94432
94433 /*
94434 * We must make sure the anon_vma is allocated
94435@@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
94436 if (error)
94437 return error;
94438
94439+ prev = vma->vm_prev;
94440+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94441+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94442+#endif
94443+ if (lockprev && anon_vma_prepare(prev))
94444+ return -ENOMEM;
94445+ if (lockprev)
94446+ vma_lock_anon_vma(prev);
94447+
94448 vma_lock_anon_vma(vma);
94449
94450 /*
94451@@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
94452 */
94453
94454 /* Somebody else might have raced and expanded it already */
94455- if (address < vma->vm_start) {
94456+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94457+ error = -ENOMEM;
94458+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94459 unsigned long size, grow;
94460
94461+#ifdef CONFIG_PAX_SEGMEXEC
94462+ struct vm_area_struct *vma_m;
94463+
94464+ vma_m = pax_find_mirror_vma(vma);
94465+#endif
94466+
94467 size = vma->vm_end - address;
94468 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94469
94470@@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
94471 vma->vm_pgoff -= grow;
94472 anon_vma_interval_tree_post_update_vma(vma);
94473 vma_gap_update(vma);
94474+
94475+#ifdef CONFIG_PAX_SEGMEXEC
94476+ if (vma_m) {
94477+ anon_vma_interval_tree_pre_update_vma(vma_m);
94478+ vma_m->vm_start -= grow << PAGE_SHIFT;
94479+ vma_m->vm_pgoff -= grow;
94480+ anon_vma_interval_tree_post_update_vma(vma_m);
94481+ vma_gap_update(vma_m);
94482+ }
94483+#endif
94484+
94485 spin_unlock(&vma->vm_mm->page_table_lock);
94486
94487+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94488 perf_event_mmap(vma);
94489 }
94490 }
94491 }
94492 vma_unlock_anon_vma(vma);
94493+ if (lockprev)
94494+ vma_unlock_anon_vma(prev);
94495 khugepaged_enter_vma_merge(vma);
94496 validate_mm(vma->vm_mm);
94497 return error;
94498@@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94499 do {
94500 long nrpages = vma_pages(vma);
94501
94502+#ifdef CONFIG_PAX_SEGMEXEC
94503+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94504+ vma = remove_vma(vma);
94505+ continue;
94506+ }
94507+#endif
94508+
94509 if (vma->vm_flags & VM_ACCOUNT)
94510 nr_accounted += nrpages;
94511 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94512@@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94513 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94514 vma->vm_prev = NULL;
94515 do {
94516+
94517+#ifdef CONFIG_PAX_SEGMEXEC
94518+ if (vma->vm_mirror) {
94519+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94520+ vma->vm_mirror->vm_mirror = NULL;
94521+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94522+ vma->vm_mirror = NULL;
94523+ }
94524+#endif
94525+
94526 vma_rb_erase(vma, &mm->mm_rb);
94527 mm->map_count--;
94528 tail_vma = vma;
94529@@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94530 struct vm_area_struct *new;
94531 int err = -ENOMEM;
94532
94533+#ifdef CONFIG_PAX_SEGMEXEC
94534+ struct vm_area_struct *vma_m, *new_m = NULL;
94535+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94536+#endif
94537+
94538 if (is_vm_hugetlb_page(vma) && (addr &
94539 ~(huge_page_mask(hstate_vma(vma)))))
94540 return -EINVAL;
94541
94542+#ifdef CONFIG_PAX_SEGMEXEC
94543+ vma_m = pax_find_mirror_vma(vma);
94544+#endif
94545+
94546 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94547 if (!new)
94548 goto out_err;
94549
94550+#ifdef CONFIG_PAX_SEGMEXEC
94551+ if (vma_m) {
94552+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94553+ if (!new_m) {
94554+ kmem_cache_free(vm_area_cachep, new);
94555+ goto out_err;
94556+ }
94557+ }
94558+#endif
94559+
94560 /* most fields are the same, copy all, and then fixup */
94561 *new = *vma;
94562
94563@@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94564 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94565 }
94566
94567+#ifdef CONFIG_PAX_SEGMEXEC
94568+ if (vma_m) {
94569+ *new_m = *vma_m;
94570+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94571+ new_m->vm_mirror = new;
94572+ new->vm_mirror = new_m;
94573+
94574+ if (new_below)
94575+ new_m->vm_end = addr_m;
94576+ else {
94577+ new_m->vm_start = addr_m;
94578+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94579+ }
94580+ }
94581+#endif
94582+
94583 err = vma_dup_policy(vma, new);
94584 if (err)
94585 goto out_free_vma;
94586@@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94587 else
94588 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94589
94590+#ifdef CONFIG_PAX_SEGMEXEC
94591+ if (!err && vma_m) {
94592+ struct mempolicy *pol = vma_policy(new);
94593+
94594+ if (anon_vma_clone(new_m, vma_m))
94595+ goto out_free_mpol;
94596+
94597+ mpol_get(pol);
94598+ set_vma_policy(new_m, pol);
94599+
94600+ if (new_m->vm_file)
94601+ get_file(new_m->vm_file);
94602+
94603+ if (new_m->vm_ops && new_m->vm_ops->open)
94604+ new_m->vm_ops->open(new_m);
94605+
94606+ if (new_below)
94607+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94608+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94609+ else
94610+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94611+
94612+ if (err) {
94613+ if (new_m->vm_ops && new_m->vm_ops->close)
94614+ new_m->vm_ops->close(new_m);
94615+ if (new_m->vm_file)
94616+ fput(new_m->vm_file);
94617+ mpol_put(pol);
94618+ }
94619+ }
94620+#endif
94621+
94622 /* Success. */
94623 if (!err)
94624 return 0;
94625@@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94626 new->vm_ops->close(new);
94627 if (new->vm_file)
94628 fput(new->vm_file);
94629- unlink_anon_vmas(new);
94630 out_free_mpol:
94631 mpol_put(vma_policy(new));
94632 out_free_vma:
94633+
94634+#ifdef CONFIG_PAX_SEGMEXEC
94635+ if (new_m) {
94636+ unlink_anon_vmas(new_m);
94637+ kmem_cache_free(vm_area_cachep, new_m);
94638+ }
94639+#endif
94640+
94641+ unlink_anon_vmas(new);
94642 kmem_cache_free(vm_area_cachep, new);
94643 out_err:
94644 return err;
94645@@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94646 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94647 unsigned long addr, int new_below)
94648 {
94649+
94650+#ifdef CONFIG_PAX_SEGMEXEC
94651+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94652+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94653+ if (mm->map_count >= sysctl_max_map_count-1)
94654+ return -ENOMEM;
94655+ } else
94656+#endif
94657+
94658 if (mm->map_count >= sysctl_max_map_count)
94659 return -ENOMEM;
94660
94661@@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94662 * work. This now handles partial unmappings.
94663 * Jeremy Fitzhardinge <jeremy@goop.org>
94664 */
94665+#ifdef CONFIG_PAX_SEGMEXEC
94666 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94667 {
94668+ int ret = __do_munmap(mm, start, len);
94669+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94670+ return ret;
94671+
94672+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94673+}
94674+
94675+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94676+#else
94677+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94678+#endif
94679+{
94680 unsigned long end;
94681 struct vm_area_struct *vma, *prev, *last;
94682
94683+ /*
94684+ * mm->mmap_sem is required to protect against another thread
94685+ * changing the mappings in case we sleep.
94686+ */
94687+ verify_mm_writelocked(mm);
94688+
94689 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94690 return -EINVAL;
94691
94692@@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94693 /* Fix up all other VM information */
94694 remove_vma_list(mm, vma);
94695
94696+ track_exec_limit(mm, start, end, 0UL);
94697+
94698 return 0;
94699 }
94700
94701@@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
94702 int ret;
94703 struct mm_struct *mm = current->mm;
94704
94705+
94706+#ifdef CONFIG_PAX_SEGMEXEC
94707+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94708+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94709+ return -EINVAL;
94710+#endif
94711+
94712 down_write(&mm->mmap_sem);
94713 ret = do_munmap(mm, start, len);
94714 up_write(&mm->mmap_sem);
94715@@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94716 return vm_munmap(addr, len);
94717 }
94718
94719-static inline void verify_mm_writelocked(struct mm_struct *mm)
94720-{
94721-#ifdef CONFIG_DEBUG_VM
94722- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94723- WARN_ON(1);
94724- up_read(&mm->mmap_sem);
94725- }
94726-#endif
94727-}
94728-
94729 /*
94730 * this is really a simplified "do_mmap". it only handles
94731 * anonymous maps. eventually we may be able to do some
94732@@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94733 struct rb_node ** rb_link, * rb_parent;
94734 pgoff_t pgoff = addr >> PAGE_SHIFT;
94735 int error;
94736+ unsigned long charged;
94737
94738 len = PAGE_ALIGN(len);
94739 if (!len)
94740@@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94741
94742 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94743
94744+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94745+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94746+ flags &= ~VM_EXEC;
94747+
94748+#ifdef CONFIG_PAX_MPROTECT
94749+ if (mm->pax_flags & MF_PAX_MPROTECT)
94750+ flags &= ~VM_MAYEXEC;
94751+#endif
94752+
94753+ }
94754+#endif
94755+
94756 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94757 if (error & ~PAGE_MASK)
94758 return error;
94759
94760+ charged = len >> PAGE_SHIFT;
94761+
94762 error = mlock_future_check(mm, mm->def_flags, len);
94763 if (error)
94764 return error;
94765@@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94766 /*
94767 * Clear old maps. this also does some error checking for us
94768 */
94769- munmap_back:
94770 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94771 if (do_munmap(mm, addr, len))
94772 return -ENOMEM;
94773- goto munmap_back;
94774+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94775 }
94776
94777 /* Check against address space limits *after* clearing old maps... */
94778- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94779+ if (!may_expand_vm(mm, charged))
94780 return -ENOMEM;
94781
94782 if (mm->map_count > sysctl_max_map_count)
94783 return -ENOMEM;
94784
94785- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94786+ if (security_vm_enough_memory_mm(mm, charged))
94787 return -ENOMEM;
94788
94789 /* Can we just expand an old private anonymous mapping? */
94790@@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94791 */
94792 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94793 if (!vma) {
94794- vm_unacct_memory(len >> PAGE_SHIFT);
94795+ vm_unacct_memory(charged);
94796 return -ENOMEM;
94797 }
94798
94799@@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94800 vma_link(mm, vma, prev, rb_link, rb_parent);
94801 out:
94802 perf_event_mmap(vma);
94803- mm->total_vm += len >> PAGE_SHIFT;
94804+ mm->total_vm += charged;
94805 if (flags & VM_LOCKED)
94806- mm->locked_vm += (len >> PAGE_SHIFT);
94807+ mm->locked_vm += charged;
94808 vma->vm_flags |= VM_SOFTDIRTY;
94809+ track_exec_limit(mm, addr, addr + len, flags);
94810 return addr;
94811 }
94812
94813@@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
94814 while (vma) {
94815 if (vma->vm_flags & VM_ACCOUNT)
94816 nr_accounted += vma_pages(vma);
94817+ vma->vm_mirror = NULL;
94818 vma = remove_vma(vma);
94819 }
94820 vm_unacct_memory(nr_accounted);
94821@@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94822 struct vm_area_struct *prev;
94823 struct rb_node **rb_link, *rb_parent;
94824
94825+#ifdef CONFIG_PAX_SEGMEXEC
94826+ struct vm_area_struct *vma_m = NULL;
94827+#endif
94828+
94829+ if (security_mmap_addr(vma->vm_start))
94830+ return -EPERM;
94831+
94832 /*
94833 * The vm_pgoff of a purely anonymous vma should be irrelevant
94834 * until its first write fault, when page's anon_vma and index
94835@@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94836 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94837 return -ENOMEM;
94838
94839+#ifdef CONFIG_PAX_SEGMEXEC
94840+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94841+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94842+ if (!vma_m)
94843+ return -ENOMEM;
94844+ }
94845+#endif
94846+
94847 vma_link(mm, vma, prev, rb_link, rb_parent);
94848+
94849+#ifdef CONFIG_PAX_SEGMEXEC
94850+ if (vma_m)
94851+ BUG_ON(pax_mirror_vma(vma_m, vma));
94852+#endif
94853+
94854 return 0;
94855 }
94856
94857@@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94858 struct rb_node **rb_link, *rb_parent;
94859 bool faulted_in_anon_vma = true;
94860
94861+ BUG_ON(vma->vm_mirror);
94862+
94863 /*
94864 * If anonymous vma has not yet been faulted, update new pgoff
94865 * to match new location, to increase its chance of merging.
94866@@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94867 return NULL;
94868 }
94869
94870+#ifdef CONFIG_PAX_SEGMEXEC
94871+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94872+{
94873+ struct vm_area_struct *prev_m;
94874+ struct rb_node **rb_link_m, *rb_parent_m;
94875+ struct mempolicy *pol_m;
94876+
94877+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94878+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94879+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94880+ *vma_m = *vma;
94881+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94882+ if (anon_vma_clone(vma_m, vma))
94883+ return -ENOMEM;
94884+ pol_m = vma_policy(vma_m);
94885+ mpol_get(pol_m);
94886+ set_vma_policy(vma_m, pol_m);
94887+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94888+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94889+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94890+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94891+ if (vma_m->vm_file)
94892+ get_file(vma_m->vm_file);
94893+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94894+ vma_m->vm_ops->open(vma_m);
94895+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94896+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94897+ vma_m->vm_mirror = vma;
94898+ vma->vm_mirror = vma_m;
94899+ return 0;
94900+}
94901+#endif
94902+
94903 /*
94904 * Return true if the calling process may expand its vm space by the passed
94905 * number of pages
94906@@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94907
94908 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94909
94910+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94911 if (cur + npages > lim)
94912 return 0;
94913 return 1;
94914@@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
94915 vma->vm_start = addr;
94916 vma->vm_end = addr + len;
94917
94918+#ifdef CONFIG_PAX_MPROTECT
94919+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94920+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94921+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94922+ return ERR_PTR(-EPERM);
94923+ if (!(vm_flags & VM_EXEC))
94924+ vm_flags &= ~VM_MAYEXEC;
94925+#else
94926+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94927+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94928+#endif
94929+ else
94930+ vm_flags &= ~VM_MAYWRITE;
94931+ }
94932+#endif
94933+
94934 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94935 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94936
94937diff --git a/mm/mprotect.c b/mm/mprotect.c
94938index c43d557..0b7ccd2 100644
94939--- a/mm/mprotect.c
94940+++ b/mm/mprotect.c
94941@@ -24,10 +24,18 @@
94942 #include <linux/migrate.h>
94943 #include <linux/perf_event.h>
94944 #include <linux/ksm.h>
94945+#include <linux/sched/sysctl.h>
94946+
94947+#ifdef CONFIG_PAX_MPROTECT
94948+#include <linux/elf.h>
94949+#include <linux/binfmts.h>
94950+#endif
94951+
94952 #include <asm/uaccess.h>
94953 #include <asm/pgtable.h>
94954 #include <asm/cacheflush.h>
94955 #include <asm/tlbflush.h>
94956+#include <asm/mmu_context.h>
94957
94958 #ifndef pgprot_modify
94959 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94960@@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94961 return pages;
94962 }
94963
94964+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94965+/* called while holding the mmap semaphor for writing except stack expansion */
94966+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94967+{
94968+ unsigned long oldlimit, newlimit = 0UL;
94969+
94970+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94971+ return;
94972+
94973+ spin_lock(&mm->page_table_lock);
94974+ oldlimit = mm->context.user_cs_limit;
94975+ if ((prot & VM_EXEC) && oldlimit < end)
94976+ /* USER_CS limit moved up */
94977+ newlimit = end;
94978+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94979+ /* USER_CS limit moved down */
94980+ newlimit = start;
94981+
94982+ if (newlimit) {
94983+ mm->context.user_cs_limit = newlimit;
94984+
94985+#ifdef CONFIG_SMP
94986+ wmb();
94987+ cpus_clear(mm->context.cpu_user_cs_mask);
94988+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94989+#endif
94990+
94991+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94992+ }
94993+ spin_unlock(&mm->page_table_lock);
94994+ if (newlimit == end) {
94995+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94996+
94997+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94998+ if (is_vm_hugetlb_page(vma))
94999+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
95000+ else
95001+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
95002+ }
95003+}
95004+#endif
95005+
95006 int
95007 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95008 unsigned long start, unsigned long end, unsigned long newflags)
95009@@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95010 int error;
95011 int dirty_accountable = 0;
95012
95013+#ifdef CONFIG_PAX_SEGMEXEC
95014+ struct vm_area_struct *vma_m = NULL;
95015+ unsigned long start_m, end_m;
95016+
95017+ start_m = start + SEGMEXEC_TASK_SIZE;
95018+ end_m = end + SEGMEXEC_TASK_SIZE;
95019+#endif
95020+
95021 if (newflags == oldflags) {
95022 *pprev = vma;
95023 return 0;
95024 }
95025
95026+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
95027+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
95028+
95029+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
95030+ return -ENOMEM;
95031+
95032+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
95033+ return -ENOMEM;
95034+ }
95035+
95036 /*
95037 * If we make a private mapping writable we increase our commit;
95038 * but (without finer accounting) cannot reduce our commit if we
95039@@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95040 }
95041 }
95042
95043+#ifdef CONFIG_PAX_SEGMEXEC
95044+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
95045+ if (start != vma->vm_start) {
95046+ error = split_vma(mm, vma, start, 1);
95047+ if (error)
95048+ goto fail;
95049+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
95050+ *pprev = (*pprev)->vm_next;
95051+ }
95052+
95053+ if (end != vma->vm_end) {
95054+ error = split_vma(mm, vma, end, 0);
95055+ if (error)
95056+ goto fail;
95057+ }
95058+
95059+ if (pax_find_mirror_vma(vma)) {
95060+ error = __do_munmap(mm, start_m, end_m - start_m);
95061+ if (error)
95062+ goto fail;
95063+ } else {
95064+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95065+ if (!vma_m) {
95066+ error = -ENOMEM;
95067+ goto fail;
95068+ }
95069+ vma->vm_flags = newflags;
95070+ error = pax_mirror_vma(vma_m, vma);
95071+ if (error) {
95072+ vma->vm_flags = oldflags;
95073+ goto fail;
95074+ }
95075+ }
95076+ }
95077+#endif
95078+
95079 /*
95080 * First try to merge with previous and/or next vma.
95081 */
95082@@ -319,9 +423,21 @@ success:
95083 * vm_flags and vm_page_prot are protected by the mmap_sem
95084 * held in write mode.
95085 */
95086+
95087+#ifdef CONFIG_PAX_SEGMEXEC
95088+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95089+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95090+#endif
95091+
95092 vma->vm_flags = newflags;
95093+
95094+#ifdef CONFIG_PAX_MPROTECT
95095+ if (mm->binfmt && mm->binfmt->handle_mprotect)
95096+ mm->binfmt->handle_mprotect(vma, newflags);
95097+#endif
95098+
95099 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95100- vm_get_page_prot(newflags));
95101+ vm_get_page_prot(vma->vm_flags));
95102
95103 if (vma_wants_writenotify(vma)) {
95104 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95105@@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95106 end = start + len;
95107 if (end <= start)
95108 return -ENOMEM;
95109+
95110+#ifdef CONFIG_PAX_SEGMEXEC
95111+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95112+ if (end > SEGMEXEC_TASK_SIZE)
95113+ return -EINVAL;
95114+ } else
95115+#endif
95116+
95117+ if (end > TASK_SIZE)
95118+ return -EINVAL;
95119+
95120 if (!arch_validate_prot(prot))
95121 return -EINVAL;
95122
95123@@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95124 /*
95125 * Does the application expect PROT_READ to imply PROT_EXEC:
95126 */
95127- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95128+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95129 prot |= PROT_EXEC;
95130
95131 vm_flags = calc_vm_prot_bits(prot);
95132@@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95133 if (start > vma->vm_start)
95134 prev = vma;
95135
95136+#ifdef CONFIG_PAX_MPROTECT
95137+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95138+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
95139+#endif
95140+
95141 for (nstart = start ; ; ) {
95142 unsigned long newflags;
95143
95144@@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95145
95146 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95147 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95148+ if (prot & (PROT_WRITE | PROT_EXEC))
95149+ gr_log_rwxmprotect(vma);
95150+
95151+ error = -EACCES;
95152+ goto out;
95153+ }
95154+
95155+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95156 error = -EACCES;
95157 goto out;
95158 }
95159@@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95160 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95161 if (error)
95162 goto out;
95163+
95164+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95165+
95166 nstart = tmp;
95167
95168 if (nstart < prev->vm_end)
95169diff --git a/mm/mremap.c b/mm/mremap.c
95170index 05f1180..c3cde48 100644
95171--- a/mm/mremap.c
95172+++ b/mm/mremap.c
95173@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95174 continue;
95175 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95176 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95177+
95178+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95179+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95180+ pte = pte_exprotect(pte);
95181+#endif
95182+
95183 pte = move_soft_dirty_pte(pte);
95184 set_pte_at(mm, new_addr, new_pte, pte);
95185 }
95186@@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95187 if (is_vm_hugetlb_page(vma))
95188 goto Einval;
95189
95190+#ifdef CONFIG_PAX_SEGMEXEC
95191+ if (pax_find_mirror_vma(vma))
95192+ goto Einval;
95193+#endif
95194+
95195 /* We can't remap across vm area boundaries */
95196 if (old_len > vma->vm_end - addr)
95197 goto Efault;
95198@@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95199 unsigned long ret = -EINVAL;
95200 unsigned long charged = 0;
95201 unsigned long map_flags;
95202+ unsigned long pax_task_size = TASK_SIZE;
95203
95204 if (new_addr & ~PAGE_MASK)
95205 goto out;
95206
95207- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95208+#ifdef CONFIG_PAX_SEGMEXEC
95209+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95210+ pax_task_size = SEGMEXEC_TASK_SIZE;
95211+#endif
95212+
95213+ pax_task_size -= PAGE_SIZE;
95214+
95215+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95216 goto out;
95217
95218 /* Check if the location we're moving into overlaps the
95219 * old location at all, and fail if it does.
95220 */
95221- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95222- goto out;
95223-
95224- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95225+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95226 goto out;
95227
95228 ret = do_munmap(mm, new_addr, new_len);
95229@@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95230 unsigned long ret = -EINVAL;
95231 unsigned long charged = 0;
95232 bool locked = false;
95233+ unsigned long pax_task_size = TASK_SIZE;
95234
95235 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95236 return ret;
95237@@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95238 if (!new_len)
95239 return ret;
95240
95241+#ifdef CONFIG_PAX_SEGMEXEC
95242+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95243+ pax_task_size = SEGMEXEC_TASK_SIZE;
95244+#endif
95245+
95246+ pax_task_size -= PAGE_SIZE;
95247+
95248+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95249+ old_len > pax_task_size || addr > pax_task_size-old_len)
95250+ return ret;
95251+
95252 down_write(&current->mm->mmap_sem);
95253
95254 if (flags & MREMAP_FIXED) {
95255@@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95256 new_addr = addr;
95257 }
95258 ret = addr;
95259+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95260 goto out;
95261 }
95262 }
95263@@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95264 goto out;
95265 }
95266
95267+ map_flags = vma->vm_flags;
95268 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95269+ if (!(ret & ~PAGE_MASK)) {
95270+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95271+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95272+ }
95273 }
95274 out:
95275 if (ret & ~PAGE_MASK)
95276diff --git a/mm/nommu.c b/mm/nommu.c
95277index 85f8d66..b3375fa 100644
95278--- a/mm/nommu.c
95279+++ b/mm/nommu.c
95280@@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95281 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95282 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95283 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95284-int heap_stack_gap = 0;
95285
95286 atomic_long_t mmap_pages_allocated;
95287
95288@@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95289 EXPORT_SYMBOL(find_vma);
95290
95291 /*
95292- * find a VMA
95293- * - we don't extend stack VMAs under NOMMU conditions
95294- */
95295-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95296-{
95297- return find_vma(mm, addr);
95298-}
95299-
95300-/*
95301 * expand a stack to a given address
95302 * - not supported under NOMMU conditions
95303 */
95304@@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95305
95306 /* most fields are the same, copy all, and then fixup */
95307 *new = *vma;
95308+ INIT_LIST_HEAD(&new->anon_vma_chain);
95309 *region = *vma->vm_region;
95310 new->vm_region = region;
95311
95312@@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95313 }
95314 EXPORT_SYMBOL(generic_file_remap_pages);
95315
95316-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95317- unsigned long addr, void *buf, int len, int write)
95318+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95319+ unsigned long addr, void *buf, size_t len, int write)
95320 {
95321 struct vm_area_struct *vma;
95322
95323@@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95324 *
95325 * The caller must hold a reference on @mm.
95326 */
95327-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95328- void *buf, int len, int write)
95329+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95330+ void *buf, size_t len, int write)
95331 {
95332 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95333 }
95334@@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95335 * Access another process' address space.
95336 * - source/target buffer must be kernel space
95337 */
95338-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95339+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95340 {
95341 struct mm_struct *mm;
95342
95343diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95344index 154af21..86e447f 100644
95345--- a/mm/page-writeback.c
95346+++ b/mm/page-writeback.c
95347@@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95348 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95349 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95350 */
95351-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95352+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95353 unsigned long thresh,
95354 unsigned long bg_thresh,
95355 unsigned long dirty,
95356diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95357index 56eb0eb..bb5e928 100644
95358--- a/mm/page_alloc.c
95359+++ b/mm/page_alloc.c
95360@@ -61,6 +61,7 @@
95361 #include <linux/page-debug-flags.h>
95362 #include <linux/hugetlb.h>
95363 #include <linux/sched/rt.h>
95364+#include <linux/random.h>
95365
95366 #include <asm/sections.h>
95367 #include <asm/tlbflush.h>
95368@@ -355,7 +356,7 @@ out:
95369 * This usage means that zero-order pages may not be compound.
95370 */
95371
95372-static void free_compound_page(struct page *page)
95373+void free_compound_page(struct page *page)
95374 {
95375 __free_pages_ok(page, compound_order(page));
95376 }
95377@@ -729,6 +730,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95378 int i;
95379 int bad = 0;
95380
95381+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95382+ unsigned long index = 1UL << order;
95383+#endif
95384+
95385 trace_mm_page_free(page, order);
95386 kmemcheck_free_shadow(page, order);
95387
95388@@ -745,6 +750,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95389 debug_check_no_obj_freed(page_address(page),
95390 PAGE_SIZE << order);
95391 }
95392+
95393+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95394+ for (; index; --index)
95395+ sanitize_highpage(page + index - 1);
95396+#endif
95397+
95398 arch_free_page(page, order);
95399 kernel_map_pages(page, 1 << order, 0);
95400
95401@@ -767,6 +778,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95402 local_irq_restore(flags);
95403 }
95404
95405+#ifdef CONFIG_PAX_LATENT_ENTROPY
95406+bool __meminitdata extra_latent_entropy;
95407+
95408+static int __init setup_pax_extra_latent_entropy(char *str)
95409+{
95410+ extra_latent_entropy = true;
95411+ return 0;
95412+}
95413+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95414+
95415+volatile u64 latent_entropy __latent_entropy;
95416+EXPORT_SYMBOL(latent_entropy);
95417+#endif
95418+
95419 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95420 {
95421 unsigned int nr_pages = 1 << order;
95422@@ -782,6 +807,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95423 __ClearPageReserved(p);
95424 set_page_count(p, 0);
95425
95426+#ifdef CONFIG_PAX_LATENT_ENTROPY
95427+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95428+ u64 hash = 0;
95429+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95430+ const u64 *data = lowmem_page_address(page);
95431+
95432+ for (index = 0; index < end; index++)
95433+ hash ^= hash + data[index];
95434+ latent_entropy ^= hash;
95435+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95436+ }
95437+#endif
95438+
95439 page_zone(page)->managed_pages += nr_pages;
95440 set_page_refcounted(page);
95441 __free_pages(page, order);
95442@@ -898,8 +936,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95443 arch_alloc_page(page, order);
95444 kernel_map_pages(page, 1 << order, 1);
95445
95446+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95447 if (gfp_flags & __GFP_ZERO)
95448 prep_zero_page(page, order, gfp_flags);
95449+#endif
95450
95451 if (order && (gfp_flags & __GFP_COMP))
95452 prep_compound_page(page, order);
95453@@ -2402,7 +2442,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95454 continue;
95455 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95456 high_wmark_pages(zone) - low_wmark_pages(zone) -
95457- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95458+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95459 }
95460 }
95461
95462diff --git a/mm/page_io.c b/mm/page_io.c
95463index 7c59ef6..1358905 100644
95464--- a/mm/page_io.c
95465+++ b/mm/page_io.c
95466@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95467 struct file *swap_file = sis->swap_file;
95468 struct address_space *mapping = swap_file->f_mapping;
95469 struct iovec iov = {
95470- .iov_base = kmap(page),
95471+ .iov_base = (void __force_user *)kmap(page),
95472 .iov_len = PAGE_SIZE,
95473 };
95474
95475diff --git a/mm/percpu.c b/mm/percpu.c
95476index 2ddf9a9..f8fc075 100644
95477--- a/mm/percpu.c
95478+++ b/mm/percpu.c
95479@@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95480 static unsigned int pcpu_high_unit_cpu __read_mostly;
95481
95482 /* the address of the first chunk which starts with the kernel static area */
95483-void *pcpu_base_addr __read_mostly;
95484+void *pcpu_base_addr __read_only;
95485 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95486
95487 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95488diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95489index 8505c92..946bfc9 100644
95490--- a/mm/process_vm_access.c
95491+++ b/mm/process_vm_access.c
95492@@ -13,6 +13,7 @@
95493 #include <linux/uio.h>
95494 #include <linux/sched.h>
95495 #include <linux/highmem.h>
95496+#include <linux/security.h>
95497 #include <linux/ptrace.h>
95498 #include <linux/slab.h>
95499 #include <linux/syscalls.h>
95500@@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95501 ssize_t iov_len;
95502 size_t total_len = iov_iter_count(iter);
95503
95504+ return -ENOSYS; // PaX: until properly audited
95505+
95506 /*
95507 * Work out how many pages of struct pages we're going to need
95508 * when eventually calling get_user_pages
95509 */
95510 for (i = 0; i < riovcnt; i++) {
95511 iov_len = rvec[i].iov_len;
95512- if (iov_len > 0) {
95513- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95514- + iov_len)
95515- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95516- / PAGE_SIZE + 1;
95517- nr_pages = max(nr_pages, nr_pages_iov);
95518- }
95519+ if (iov_len <= 0)
95520+ continue;
95521+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95522+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95523+ nr_pages = max(nr_pages, nr_pages_iov);
95524 }
95525
95526 if (nr_pages == 0)
95527@@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95528 goto free_proc_pages;
95529 }
95530
95531+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95532+ rc = -EPERM;
95533+ goto put_task_struct;
95534+ }
95535+
95536 mm = mm_access(task, PTRACE_MODE_ATTACH);
95537 if (!mm || IS_ERR(mm)) {
95538 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95539diff --git a/mm/rmap.c b/mm/rmap.c
95540index 14d1e28..3777962 100644
95541--- a/mm/rmap.c
95542+++ b/mm/rmap.c
95543@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95544 struct anon_vma *anon_vma = vma->anon_vma;
95545 struct anon_vma_chain *avc;
95546
95547+#ifdef CONFIG_PAX_SEGMEXEC
95548+ struct anon_vma_chain *avc_m = NULL;
95549+#endif
95550+
95551 might_sleep();
95552 if (unlikely(!anon_vma)) {
95553 struct mm_struct *mm = vma->vm_mm;
95554@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95555 if (!avc)
95556 goto out_enomem;
95557
95558+#ifdef CONFIG_PAX_SEGMEXEC
95559+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95560+ if (!avc_m)
95561+ goto out_enomem_free_avc;
95562+#endif
95563+
95564 anon_vma = find_mergeable_anon_vma(vma);
95565 allocated = NULL;
95566 if (!anon_vma) {
95567@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95568 /* page_table_lock to protect against threads */
95569 spin_lock(&mm->page_table_lock);
95570 if (likely(!vma->anon_vma)) {
95571+
95572+#ifdef CONFIG_PAX_SEGMEXEC
95573+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95574+
95575+ if (vma_m) {
95576+ BUG_ON(vma_m->anon_vma);
95577+ vma_m->anon_vma = anon_vma;
95578+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95579+ avc_m = NULL;
95580+ }
95581+#endif
95582+
95583 vma->anon_vma = anon_vma;
95584 anon_vma_chain_link(vma, avc, anon_vma);
95585 allocated = NULL;
95586@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95587
95588 if (unlikely(allocated))
95589 put_anon_vma(allocated);
95590+
95591+#ifdef CONFIG_PAX_SEGMEXEC
95592+ if (unlikely(avc_m))
95593+ anon_vma_chain_free(avc_m);
95594+#endif
95595+
95596 if (unlikely(avc))
95597 anon_vma_chain_free(avc);
95598 }
95599 return 0;
95600
95601 out_enomem_free_avc:
95602+
95603+#ifdef CONFIG_PAX_SEGMEXEC
95604+ if (avc_m)
95605+ anon_vma_chain_free(avc_m);
95606+#endif
95607+
95608 anon_vma_chain_free(avc);
95609 out_enomem:
95610 return -ENOMEM;
95611@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95612 * Attach the anon_vmas from src to dst.
95613 * Returns 0 on success, -ENOMEM on failure.
95614 */
95615-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95616+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95617 {
95618 struct anon_vma_chain *avc, *pavc;
95619 struct anon_vma *root = NULL;
95620@@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95621 * the corresponding VMA in the parent process is attached to.
95622 * Returns 0 on success, non-zero on failure.
95623 */
95624-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95625+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95626 {
95627 struct anon_vma_chain *avc;
95628 struct anon_vma *anon_vma;
95629@@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
95630 void __init anon_vma_init(void)
95631 {
95632 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95633- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95634- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95635+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95636+ anon_vma_ctor);
95637+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95638+ SLAB_PANIC|SLAB_NO_SANITIZE);
95639 }
95640
95641 /*
95642diff --git a/mm/shmem.c b/mm/shmem.c
95643index a2801ba..b8651e6 100644
95644--- a/mm/shmem.c
95645+++ b/mm/shmem.c
95646@@ -33,7 +33,7 @@
95647 #include <linux/swap.h>
95648 #include <linux/aio.h>
95649
95650-static struct vfsmount *shm_mnt;
95651+struct vfsmount *shm_mnt;
95652
95653 #ifdef CONFIG_SHMEM
95654 /*
95655@@ -77,14 +77,15 @@ static struct vfsmount *shm_mnt;
95656 #define BOGO_DIRENT_SIZE 20
95657
95658 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95659-#define SHORT_SYMLINK_LEN 128
95660+#define SHORT_SYMLINK_LEN 64
95661
95662 /*
95663- * shmem_fallocate and shmem_writepage communicate via inode->i_private
95664- * (with i_mutex making sure that it has only one user at a time):
95665- * we would prefer not to enlarge the shmem inode just for that.
95666+ * shmem_fallocate communicates with shmem_fault or shmem_writepage via
95667+ * inode->i_private (with i_mutex making sure that it has only one user at
95668+ * a time): we would prefer not to enlarge the shmem inode just for that.
95669 */
95670 struct shmem_falloc {
95671+ int mode; /* FALLOC_FL mode currently operating */
95672 pgoff_t start; /* start of range currently being fallocated */
95673 pgoff_t next; /* the next page offset to be fallocated */
95674 pgoff_t nr_falloced; /* how many new pages have been fallocated */
95675@@ -759,6 +760,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
95676 spin_lock(&inode->i_lock);
95677 shmem_falloc = inode->i_private;
95678 if (shmem_falloc &&
95679+ !shmem_falloc->mode &&
95680 index >= shmem_falloc->start &&
95681 index < shmem_falloc->next)
95682 shmem_falloc->nr_unswapped++;
95683@@ -1233,6 +1235,43 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
95684 int error;
95685 int ret = VM_FAULT_LOCKED;
95686
95687+ /*
95688+ * Trinity finds that probing a hole which tmpfs is punching can
95689+ * prevent the hole-punch from ever completing: which in turn
95690+ * locks writers out with its hold on i_mutex. So refrain from
95691+ * faulting pages into the hole while it's being punched, and
95692+ * wait on i_mutex to be released if vmf->flags permits,
95693+ */
95694+ if (unlikely(inode->i_private)) {
95695+ struct shmem_falloc *shmem_falloc;
95696+ spin_lock(&inode->i_lock);
95697+ shmem_falloc = inode->i_private;
95698+ if (!shmem_falloc ||
95699+ shmem_falloc->mode != FALLOC_FL_PUNCH_HOLE ||
95700+ vmf->pgoff < shmem_falloc->start ||
95701+ vmf->pgoff >= shmem_falloc->next)
95702+ shmem_falloc = NULL;
95703+ spin_unlock(&inode->i_lock);
95704+ /*
95705+ * i_lock has protected us from taking shmem_falloc seriously
95706+ * once return from shmem_fallocate() went back up that stack.
95707+ * i_lock does not serialize with i_mutex at all, but it does
95708+ * not matter if sometimes we wait unnecessarily, or sometimes
95709+ * miss out on waiting: we just need to make those cases rare.
95710+ */
95711+ if (shmem_falloc) {
95712+ if ((vmf->flags & FAULT_FLAG_ALLOW_RETRY) &&
95713+ !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
95714+ up_read(&vma->vm_mm->mmap_sem);
95715+ mutex_lock(&inode->i_mutex);
95716+ mutex_unlock(&inode->i_mutex);
95717+ return VM_FAULT_RETRY;
95718+ }
95719+ /* cond_resched? Leave that to GUP or return to user */
95720+ return VM_FAULT_NOPAGE;
95721+ }
95722+ }
95723+
95724 error = shmem_getpage(inode, vmf->pgoff, &vmf->page, SGP_CACHE, &ret);
95725 if (error)
95726 return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
95727@@ -1733,18 +1772,26 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
95728
95729 mutex_lock(&inode->i_mutex);
95730
95731+ shmem_falloc.mode = mode & ~FALLOC_FL_KEEP_SIZE;
95732+
95733 if (mode & FALLOC_FL_PUNCH_HOLE) {
95734 struct address_space *mapping = file->f_mapping;
95735 loff_t unmap_start = round_up(offset, PAGE_SIZE);
95736 loff_t unmap_end = round_down(offset + len, PAGE_SIZE) - 1;
95737
95738+ shmem_falloc.start = unmap_start >> PAGE_SHIFT;
95739+ shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT;
95740+ spin_lock(&inode->i_lock);
95741+ inode->i_private = &shmem_falloc;
95742+ spin_unlock(&inode->i_lock);
95743+
95744 if ((u64)unmap_end > (u64)unmap_start)
95745 unmap_mapping_range(mapping, unmap_start,
95746 1 + unmap_end - unmap_start, 0);
95747 shmem_truncate_range(inode, offset, offset + len - 1);
95748 /* No need to unmap again: hole-punching leaves COWed pages */
95749 error = 0;
95750- goto out;
95751+ goto undone;
95752 }
95753
95754 /* We need to check rlimit even when FALLOC_FL_KEEP_SIZE */
95755@@ -2138,6 +2185,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95756 static int shmem_xattr_validate(const char *name)
95757 {
95758 struct { const char *prefix; size_t len; } arr[] = {
95759+
95760+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95761+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95762+#endif
95763+
95764 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95765 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95766 };
95767@@ -2193,6 +2245,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95768 if (err)
95769 return err;
95770
95771+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95772+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95773+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95774+ return -EOPNOTSUPP;
95775+ if (size > 8)
95776+ return -EINVAL;
95777+ }
95778+#endif
95779+
95780 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95781 }
95782
95783@@ -2505,8 +2566,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95784 int err = -ENOMEM;
95785
95786 /* Round up to L1_CACHE_BYTES to resist false sharing */
95787- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95788- L1_CACHE_BYTES), GFP_KERNEL);
95789+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95790 if (!sbinfo)
95791 return -ENOMEM;
95792
95793diff --git a/mm/slab.c b/mm/slab.c
95794index 9432556..e0dc685 100644
95795--- a/mm/slab.c
95796+++ b/mm/slab.c
95797@@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95798 if ((x)->max_freeable < i) \
95799 (x)->max_freeable = i; \
95800 } while (0)
95801-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95802-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95803-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95804-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95805+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95806+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95807+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95808+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95809+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95810+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95811 #else
95812 #define STATS_INC_ACTIVE(x) do { } while (0)
95813 #define STATS_DEC_ACTIVE(x) do { } while (0)
95814@@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95815 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95816 #define STATS_INC_FREEHIT(x) do { } while (0)
95817 #define STATS_INC_FREEMISS(x) do { } while (0)
95818+#define STATS_INC_SANITIZED(x) do { } while (0)
95819+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95820 #endif
95821
95822 #if DEBUG
95823@@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95824 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95825 */
95826 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95827- const struct page *page, void *obj)
95828+ const struct page *page, const void *obj)
95829 {
95830 u32 offset = (obj - page->s_mem);
95831 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95832@@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
95833 */
95834
95835 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95836- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95837+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95838
95839 if (INDEX_AC != INDEX_NODE)
95840 kmalloc_caches[INDEX_NODE] =
95841 create_kmalloc_cache("kmalloc-node",
95842- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95843+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95844
95845 slab_early_init = 0;
95846
95847@@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95848 struct array_cache *ac = cpu_cache_get(cachep);
95849
95850 check_irq_off();
95851+
95852+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95853+ if (pax_sanitize_slab) {
95854+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95855+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95856+
95857+ if (cachep->ctor)
95858+ cachep->ctor(objp);
95859+
95860+ STATS_INC_SANITIZED(cachep);
95861+ } else
95862+ STATS_INC_NOT_SANITIZED(cachep);
95863+ }
95864+#endif
95865+
95866 kmemleak_free_recursive(objp, cachep->flags);
95867 objp = cache_free_debugcheck(cachep, objp, caller);
95868
95869@@ -3748,6 +3767,7 @@ void kfree(const void *objp)
95870
95871 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95872 return;
95873+ VM_BUG_ON(!virt_addr_valid(objp));
95874 local_irq_save(flags);
95875 kfree_debugcheck(objp);
95876 c = virt_to_cache(objp);
95877@@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95878 }
95879 /* cpu stats */
95880 {
95881- unsigned long allochit = atomic_read(&cachep->allochit);
95882- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95883- unsigned long freehit = atomic_read(&cachep->freehit);
95884- unsigned long freemiss = atomic_read(&cachep->freemiss);
95885+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95886+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95887+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95888+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95889
95890 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95891 allochit, allocmiss, freehit, freemiss);
95892 }
95893+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95894+ {
95895+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95896+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95897+
95898+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95899+ }
95900+#endif
95901 #endif
95902 }
95903
95904@@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
95905 static int __init slab_proc_init(void)
95906 {
95907 #ifdef CONFIG_DEBUG_SLAB_LEAK
95908- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95909+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95910 #endif
95911 return 0;
95912 }
95913 module_init(slab_proc_init);
95914 #endif
95915
95916+bool is_usercopy_object(const void *ptr)
95917+{
95918+ struct page *page;
95919+ struct kmem_cache *cachep;
95920+
95921+ if (ZERO_OR_NULL_PTR(ptr))
95922+ return false;
95923+
95924+ if (!slab_is_available())
95925+ return false;
95926+
95927+ if (!virt_addr_valid(ptr))
95928+ return false;
95929+
95930+ page = virt_to_head_page(ptr);
95931+
95932+ if (!PageSlab(page))
95933+ return false;
95934+
95935+ cachep = page->slab_cache;
95936+ return cachep->flags & SLAB_USERCOPY;
95937+}
95938+
95939+#ifdef CONFIG_PAX_USERCOPY
95940+const char *check_heap_object(const void *ptr, unsigned long n)
95941+{
95942+ struct page *page;
95943+ struct kmem_cache *cachep;
95944+ unsigned int objnr;
95945+ unsigned long offset;
95946+
95947+ if (ZERO_OR_NULL_PTR(ptr))
95948+ return "<null>";
95949+
95950+ if (!virt_addr_valid(ptr))
95951+ return NULL;
95952+
95953+ page = virt_to_head_page(ptr);
95954+
95955+ if (!PageSlab(page))
95956+ return NULL;
95957+
95958+ cachep = page->slab_cache;
95959+ if (!(cachep->flags & SLAB_USERCOPY))
95960+ return cachep->name;
95961+
95962+ objnr = obj_to_index(cachep, page, ptr);
95963+ BUG_ON(objnr >= cachep->num);
95964+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95965+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95966+ return NULL;
95967+
95968+ return cachep->name;
95969+}
95970+#endif
95971+
95972 /**
95973 * ksize - get the actual amount of memory allocated for a given object
95974 * @objp: Pointer to the object
95975diff --git a/mm/slab.h b/mm/slab.h
95976index 6bd4c35..97565a1 100644
95977--- a/mm/slab.h
95978+++ b/mm/slab.h
95979@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95980 /* The slab cache that manages slab cache information */
95981 extern struct kmem_cache *kmem_cache;
95982
95983+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95984+#ifdef CONFIG_X86_64
95985+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95986+#else
95987+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95988+#endif
95989+extern bool pax_sanitize_slab;
95990+#endif
95991+
95992 unsigned long calculate_alignment(unsigned long flags,
95993 unsigned long align, unsigned long size);
95994
95995@@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
95996
95997 /* Legal flag mask for kmem_cache_create(), for various configurations */
95998 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95999- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
96000+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
96001+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
96002
96003 #if defined(CONFIG_DEBUG_SLAB)
96004 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
96005@@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
96006 return s;
96007
96008 page = virt_to_head_page(x);
96009+
96010+ BUG_ON(!PageSlab(page));
96011+
96012 cachep = page->slab_cache;
96013 if (slab_equal_or_root(cachep, s))
96014 return cachep;
96015diff --git a/mm/slab_common.c b/mm/slab_common.c
96016index 102cc6f..c7aab3d 100644
96017--- a/mm/slab_common.c
96018+++ b/mm/slab_common.c
96019@@ -23,11 +23,22 @@
96020
96021 #include "slab.h"
96022
96023-enum slab_state slab_state;
96024+enum slab_state slab_state __read_only;
96025 LIST_HEAD(slab_caches);
96026 DEFINE_MUTEX(slab_mutex);
96027 struct kmem_cache *kmem_cache;
96028
96029+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96030+bool pax_sanitize_slab __read_only = true;
96031+static int __init pax_sanitize_slab_setup(char *str)
96032+{
96033+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
96034+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
96035+ return 1;
96036+}
96037+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
96038+#endif
96039+
96040 #ifdef CONFIG_DEBUG_VM
96041 static int kmem_cache_sanity_check(const char *name, size_t size)
96042 {
96043@@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
96044 if (err)
96045 goto out_free_cache;
96046
96047- s->refcount = 1;
96048+ atomic_set(&s->refcount, 1);
96049 list_add(&s->list, &slab_caches);
96050 memcg_register_cache(s);
96051 out:
96052@@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96053 get_online_cpus();
96054 mutex_lock(&slab_mutex);
96055
96056- s->refcount--;
96057- if (s->refcount)
96058+ if (!atomic_dec_and_test(&s->refcount))
96059 goto out_unlock;
96060
96061 if (kmem_cache_destroy_memcg_children(s) != 0)
96062@@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96063 rcu_barrier();
96064
96065 memcg_free_cache_params(s);
96066-#ifdef SLAB_SUPPORTS_SYSFS
96067+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96068 sysfs_slab_remove(s);
96069 #else
96070 slab_kmem_cache_release(s);
96071@@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
96072 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
96073 name, size, err);
96074
96075- s->refcount = -1; /* Exempt from merging for now */
96076+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
96077 }
96078
96079 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96080@@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96081
96082 create_boot_cache(s, name, size, flags);
96083 list_add(&s->list, &slab_caches);
96084- s->refcount = 1;
96085+ atomic_set(&s->refcount, 1);
96086 return s;
96087 }
96088
96089@@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96090 EXPORT_SYMBOL(kmalloc_dma_caches);
96091 #endif
96092
96093+#ifdef CONFIG_PAX_USERCOPY_SLABS
96094+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96095+EXPORT_SYMBOL(kmalloc_usercopy_caches);
96096+#endif
96097+
96098 /*
96099 * Conversion table for small slabs sizes / 8 to the index in the
96100 * kmalloc array. This is necessary for slabs < 192 since we have non power
96101@@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96102 return kmalloc_dma_caches[index];
96103
96104 #endif
96105+
96106+#ifdef CONFIG_PAX_USERCOPY_SLABS
96107+ if (unlikely((flags & GFP_USERCOPY)))
96108+ return kmalloc_usercopy_caches[index];
96109+
96110+#endif
96111+
96112 return kmalloc_caches[index];
96113 }
96114
96115@@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96116 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96117 if (!kmalloc_caches[i]) {
96118 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96119- 1 << i, flags);
96120+ 1 << i, SLAB_USERCOPY | flags);
96121 }
96122
96123 /*
96124@@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96125 * earlier power of two caches
96126 */
96127 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96128- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96129+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96130
96131 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96132- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96133+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96134 }
96135
96136 /* Kmalloc array is now usable */
96137@@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96138 }
96139 }
96140 #endif
96141+
96142+#ifdef CONFIG_PAX_USERCOPY_SLABS
96143+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96144+ struct kmem_cache *s = kmalloc_caches[i];
96145+
96146+ if (s) {
96147+ int size = kmalloc_size(i);
96148+ char *n = kasprintf(GFP_NOWAIT,
96149+ "usercopy-kmalloc-%d", size);
96150+
96151+ BUG_ON(!n);
96152+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96153+ size, SLAB_USERCOPY | flags);
96154+ }
96155+ }
96156+#endif
96157+
96158 }
96159 #endif /* !CONFIG_SLOB */
96160
96161@@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96162 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96163 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96164 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96165+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96166+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
96167+#endif
96168 #endif
96169 seq_putc(m, '\n');
96170 }
96171diff --git a/mm/slob.c b/mm/slob.c
96172index 730cad4..8cfd442 100644
96173--- a/mm/slob.c
96174+++ b/mm/slob.c
96175@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96176 /*
96177 * Return the size of a slob block.
96178 */
96179-static slobidx_t slob_units(slob_t *s)
96180+static slobidx_t slob_units(const slob_t *s)
96181 {
96182 if (s->units > 0)
96183 return s->units;
96184@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96185 /*
96186 * Return the next free slob block pointer after this one.
96187 */
96188-static slob_t *slob_next(slob_t *s)
96189+static slob_t *slob_next(const slob_t *s)
96190 {
96191 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96192 slobidx_t next;
96193@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96194 /*
96195 * Returns true if s is the last free block in its page.
96196 */
96197-static int slob_last(slob_t *s)
96198+static int slob_last(const slob_t *s)
96199 {
96200 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96201 }
96202
96203-static void *slob_new_pages(gfp_t gfp, int order, int node)
96204+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96205 {
96206- void *page;
96207+ struct page *page;
96208
96209 #ifdef CONFIG_NUMA
96210 if (node != NUMA_NO_NODE)
96211@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96212 if (!page)
96213 return NULL;
96214
96215- return page_address(page);
96216+ __SetPageSlab(page);
96217+ return page;
96218 }
96219
96220-static void slob_free_pages(void *b, int order)
96221+static void slob_free_pages(struct page *sp, int order)
96222 {
96223 if (current->reclaim_state)
96224 current->reclaim_state->reclaimed_slab += 1 << order;
96225- free_pages((unsigned long)b, order);
96226+ __ClearPageSlab(sp);
96227+ page_mapcount_reset(sp);
96228+ sp->private = 0;
96229+ __free_pages(sp, order);
96230 }
96231
96232 /*
96233@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96234
96235 /* Not enough space: must allocate a new page */
96236 if (!b) {
96237- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96238- if (!b)
96239+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96240+ if (!sp)
96241 return NULL;
96242- sp = virt_to_page(b);
96243- __SetPageSlab(sp);
96244+ b = page_address(sp);
96245
96246 spin_lock_irqsave(&slob_lock, flags);
96247 sp->units = SLOB_UNITS(PAGE_SIZE);
96248 sp->freelist = b;
96249+ sp->private = 0;
96250 INIT_LIST_HEAD(&sp->lru);
96251 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96252 set_slob_page_free(sp, slob_list);
96253@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96254 if (slob_page_free(sp))
96255 clear_slob_page_free(sp);
96256 spin_unlock_irqrestore(&slob_lock, flags);
96257- __ClearPageSlab(sp);
96258- page_mapcount_reset(sp);
96259- slob_free_pages(b, 0);
96260+ slob_free_pages(sp, 0);
96261 return;
96262 }
96263
96264+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96265+ if (pax_sanitize_slab)
96266+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96267+#endif
96268+
96269 if (!slob_page_free(sp)) {
96270 /* This slob page is about to become partially free. Easy! */
96271 sp->units = units;
96272@@ -424,11 +431,10 @@ out:
96273 */
96274
96275 static __always_inline void *
96276-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96277+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96278 {
96279- unsigned int *m;
96280- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96281- void *ret;
96282+ slob_t *m;
96283+ void *ret = NULL;
96284
96285 gfp &= gfp_allowed_mask;
96286
96287@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96288
96289 if (!m)
96290 return NULL;
96291- *m = size;
96292+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96293+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96294+ m[0].units = size;
96295+ m[1].units = align;
96296 ret = (void *)m + align;
96297
96298 trace_kmalloc_node(caller, ret,
96299 size, size + align, gfp, node);
96300 } else {
96301 unsigned int order = get_order(size);
96302+ struct page *page;
96303
96304 if (likely(order))
96305 gfp |= __GFP_COMP;
96306- ret = slob_new_pages(gfp, order, node);
96307+ page = slob_new_pages(gfp, order, node);
96308+ if (page) {
96309+ ret = page_address(page);
96310+ page->private = size;
96311+ }
96312
96313 trace_kmalloc_node(caller, ret,
96314 size, PAGE_SIZE << order, gfp, node);
96315 }
96316
96317- kmemleak_alloc(ret, size, 1, gfp);
96318+ return ret;
96319+}
96320+
96321+static __always_inline void *
96322+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96323+{
96324+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96325+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96326+
96327+ if (!ZERO_OR_NULL_PTR(ret))
96328+ kmemleak_alloc(ret, size, 1, gfp);
96329 return ret;
96330 }
96331
96332@@ -493,34 +517,112 @@ void kfree(const void *block)
96333 return;
96334 kmemleak_free(block);
96335
96336+ VM_BUG_ON(!virt_addr_valid(block));
96337 sp = virt_to_page(block);
96338- if (PageSlab(sp)) {
96339+ VM_BUG_ON(!PageSlab(sp));
96340+ if (!sp->private) {
96341 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96342- unsigned int *m = (unsigned int *)(block - align);
96343- slob_free(m, *m + align);
96344- } else
96345+ slob_t *m = (slob_t *)(block - align);
96346+ slob_free(m, m[0].units + align);
96347+ } else {
96348+ __ClearPageSlab(sp);
96349+ page_mapcount_reset(sp);
96350+ sp->private = 0;
96351 __free_pages(sp, compound_order(sp));
96352+ }
96353 }
96354 EXPORT_SYMBOL(kfree);
96355
96356+bool is_usercopy_object(const void *ptr)
96357+{
96358+ if (!slab_is_available())
96359+ return false;
96360+
96361+ // PAX: TODO
96362+
96363+ return false;
96364+}
96365+
96366+#ifdef CONFIG_PAX_USERCOPY
96367+const char *check_heap_object(const void *ptr, unsigned long n)
96368+{
96369+ struct page *page;
96370+ const slob_t *free;
96371+ const void *base;
96372+ unsigned long flags;
96373+
96374+ if (ZERO_OR_NULL_PTR(ptr))
96375+ return "<null>";
96376+
96377+ if (!virt_addr_valid(ptr))
96378+ return NULL;
96379+
96380+ page = virt_to_head_page(ptr);
96381+ if (!PageSlab(page))
96382+ return NULL;
96383+
96384+ if (page->private) {
96385+ base = page;
96386+ if (base <= ptr && n <= page->private - (ptr - base))
96387+ return NULL;
96388+ return "<slob>";
96389+ }
96390+
96391+ /* some tricky double walking to find the chunk */
96392+ spin_lock_irqsave(&slob_lock, flags);
96393+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96394+ free = page->freelist;
96395+
96396+ while (!slob_last(free) && (void *)free <= ptr) {
96397+ base = free + slob_units(free);
96398+ free = slob_next(free);
96399+ }
96400+
96401+ while (base < (void *)free) {
96402+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96403+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96404+ int offset;
96405+
96406+ if (ptr < base + align)
96407+ break;
96408+
96409+ offset = ptr - base - align;
96410+ if (offset >= m) {
96411+ base += size;
96412+ continue;
96413+ }
96414+
96415+ if (n > m - offset)
96416+ break;
96417+
96418+ spin_unlock_irqrestore(&slob_lock, flags);
96419+ return NULL;
96420+ }
96421+
96422+ spin_unlock_irqrestore(&slob_lock, flags);
96423+ return "<slob>";
96424+}
96425+#endif
96426+
96427 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96428 size_t ksize(const void *block)
96429 {
96430 struct page *sp;
96431 int align;
96432- unsigned int *m;
96433+ slob_t *m;
96434
96435 BUG_ON(!block);
96436 if (unlikely(block == ZERO_SIZE_PTR))
96437 return 0;
96438
96439 sp = virt_to_page(block);
96440- if (unlikely(!PageSlab(sp)))
96441- return PAGE_SIZE << compound_order(sp);
96442+ VM_BUG_ON(!PageSlab(sp));
96443+ if (sp->private)
96444+ return sp->private;
96445
96446 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96447- m = (unsigned int *)(block - align);
96448- return SLOB_UNITS(*m) * SLOB_UNIT;
96449+ m = (slob_t *)(block - align);
96450+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96451 }
96452 EXPORT_SYMBOL(ksize);
96453
96454@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96455
96456 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96457 {
96458- void *b;
96459+ void *b = NULL;
96460
96461 flags &= gfp_allowed_mask;
96462
96463 lockdep_trace_alloc(flags);
96464
96465+#ifdef CONFIG_PAX_USERCOPY_SLABS
96466+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96467+#else
96468 if (c->size < PAGE_SIZE) {
96469 b = slob_alloc(c->size, flags, c->align, node);
96470 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96471 SLOB_UNITS(c->size) * SLOB_UNIT,
96472 flags, node);
96473 } else {
96474- b = slob_new_pages(flags, get_order(c->size), node);
96475+ struct page *sp;
96476+
96477+ sp = slob_new_pages(flags, get_order(c->size), node);
96478+ if (sp) {
96479+ b = page_address(sp);
96480+ sp->private = c->size;
96481+ }
96482 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96483 PAGE_SIZE << get_order(c->size),
96484 flags, node);
96485 }
96486+#endif
96487
96488 if (b && c->ctor)
96489 c->ctor(b);
96490@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96491
96492 static void __kmem_cache_free(void *b, int size)
96493 {
96494- if (size < PAGE_SIZE)
96495+ struct page *sp;
96496+
96497+ sp = virt_to_page(b);
96498+ BUG_ON(!PageSlab(sp));
96499+ if (!sp->private)
96500 slob_free(b, size);
96501 else
96502- slob_free_pages(b, get_order(size));
96503+ slob_free_pages(sp, get_order(size));
96504 }
96505
96506 static void kmem_rcu_free(struct rcu_head *head)
96507@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96508
96509 void kmem_cache_free(struct kmem_cache *c, void *b)
96510 {
96511+ int size = c->size;
96512+
96513+#ifdef CONFIG_PAX_USERCOPY_SLABS
96514+ if (size + c->align < PAGE_SIZE) {
96515+ size += c->align;
96516+ b -= c->align;
96517+ }
96518+#endif
96519+
96520 kmemleak_free_recursive(b, c->flags);
96521 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96522 struct slob_rcu *slob_rcu;
96523- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96524- slob_rcu->size = c->size;
96525+ slob_rcu = b + (size - sizeof(struct slob_rcu));
96526+ slob_rcu->size = size;
96527 call_rcu(&slob_rcu->head, kmem_rcu_free);
96528 } else {
96529- __kmem_cache_free(b, c->size);
96530+ __kmem_cache_free(b, size);
96531 }
96532
96533+#ifdef CONFIG_PAX_USERCOPY_SLABS
96534+ trace_kfree(_RET_IP_, b);
96535+#else
96536 trace_kmem_cache_free(_RET_IP_, b);
96537+#endif
96538+
96539 }
96540 EXPORT_SYMBOL(kmem_cache_free);
96541
96542diff --git a/mm/slub.c b/mm/slub.c
96543index 2b1ce69..4a2193f 100644
96544--- a/mm/slub.c
96545+++ b/mm/slub.c
96546@@ -207,7 +207,7 @@ struct track {
96547
96548 enum track_item { TRACK_ALLOC, TRACK_FREE };
96549
96550-#ifdef CONFIG_SYSFS
96551+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96552 static int sysfs_slab_add(struct kmem_cache *);
96553 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96554 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
96555@@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
96556 if (!t->addr)
96557 return;
96558
96559- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96560+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96561 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96562 #ifdef CONFIG_STACKTRACE
96563 {
96564@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96565
96566 slab_free_hook(s, x);
96567
96568+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96569+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96570+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96571+ if (s->ctor)
96572+ s->ctor(x);
96573+ }
96574+#endif
96575+
96576 redo:
96577 /*
96578 * Determine the currently cpus per cpu slab.
96579@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96580 * Merge control. If this is set then no merging of slab caches will occur.
96581 * (Could be removed. This was introduced to pacify the merge skeptics.)
96582 */
96583-static int slub_nomerge;
96584+static int slub_nomerge = 1;
96585
96586 /*
96587 * Calculate the order of allocation given an slab object size.
96588@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96589 s->inuse = size;
96590
96591 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96592+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96593+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96594+#endif
96595 s->ctor)) {
96596 /*
96597 * Relocate free pointer after the object if it is not
96598@@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96599 EXPORT_SYMBOL(__kmalloc_node);
96600 #endif
96601
96602+bool is_usercopy_object(const void *ptr)
96603+{
96604+ struct page *page;
96605+ struct kmem_cache *s;
96606+
96607+ if (ZERO_OR_NULL_PTR(ptr))
96608+ return false;
96609+
96610+ if (!slab_is_available())
96611+ return false;
96612+
96613+ if (!virt_addr_valid(ptr))
96614+ return false;
96615+
96616+ page = virt_to_head_page(ptr);
96617+
96618+ if (!PageSlab(page))
96619+ return false;
96620+
96621+ s = page->slab_cache;
96622+ return s->flags & SLAB_USERCOPY;
96623+}
96624+
96625+#ifdef CONFIG_PAX_USERCOPY
96626+const char *check_heap_object(const void *ptr, unsigned long n)
96627+{
96628+ struct page *page;
96629+ struct kmem_cache *s;
96630+ unsigned long offset;
96631+
96632+ if (ZERO_OR_NULL_PTR(ptr))
96633+ return "<null>";
96634+
96635+ if (!virt_addr_valid(ptr))
96636+ return NULL;
96637+
96638+ page = virt_to_head_page(ptr);
96639+
96640+ if (!PageSlab(page))
96641+ return NULL;
96642+
96643+ s = page->slab_cache;
96644+ if (!(s->flags & SLAB_USERCOPY))
96645+ return s->name;
96646+
96647+ offset = (ptr - page_address(page)) % s->size;
96648+ if (offset <= s->object_size && n <= s->object_size - offset)
96649+ return NULL;
96650+
96651+ return s->name;
96652+}
96653+#endif
96654+
96655 size_t ksize(const void *object)
96656 {
96657 struct page *page;
96658@@ -3371,6 +3435,7 @@ void kfree(const void *x)
96659 if (unlikely(ZERO_OR_NULL_PTR(x)))
96660 return;
96661
96662+ VM_BUG_ON(!virt_addr_valid(x));
96663 page = virt_to_head_page(x);
96664 if (unlikely(!PageSlab(page))) {
96665 BUG_ON(!PageCompound(page));
96666@@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96667 /*
96668 * We may have set a slab to be unmergeable during bootstrap.
96669 */
96670- if (s->refcount < 0)
96671+ if (atomic_read(&s->refcount) < 0)
96672 return 1;
96673
96674 return 0;
96675@@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96676 int i;
96677 struct kmem_cache *c;
96678
96679- s->refcount++;
96680+ atomic_inc(&s->refcount);
96681
96682 /*
96683 * Adjust the object sizes so that we clear
96684@@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96685 }
96686
96687 if (sysfs_slab_alias(s, name)) {
96688- s->refcount--;
96689+ atomic_dec(&s->refcount);
96690 s = NULL;
96691 }
96692 }
96693@@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96694 }
96695 #endif
96696
96697-#ifdef CONFIG_SYSFS
96698+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96699 static int count_inuse(struct page *page)
96700 {
96701 return page->inuse;
96702@@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
96703 len += sprintf(buf + len, "%7ld ", l->count);
96704
96705 if (l->addr)
96706+#ifdef CONFIG_GRKERNSEC_HIDESYM
96707+ len += sprintf(buf + len, "%pS", NULL);
96708+#else
96709 len += sprintf(buf + len, "%pS", (void *)l->addr);
96710+#endif
96711 else
96712 len += sprintf(buf + len, "<not-available>");
96713
96714@@ -4261,12 +4330,12 @@ static void resiliency_test(void)
96715 validate_slab_cache(kmalloc_caches[9]);
96716 }
96717 #else
96718-#ifdef CONFIG_SYSFS
96719+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96720 static void resiliency_test(void) {};
96721 #endif
96722 #endif
96723
96724-#ifdef CONFIG_SYSFS
96725+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96726 enum slab_stat_type {
96727 SL_ALL, /* All slabs */
96728 SL_PARTIAL, /* Only partially allocated slabs */
96729@@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
96730 {
96731 if (!s->ctor)
96732 return 0;
96733+#ifdef CONFIG_GRKERNSEC_HIDESYM
96734+ return sprintf(buf, "%pS\n", NULL);
96735+#else
96736 return sprintf(buf, "%pS\n", s->ctor);
96737+#endif
96738 }
96739 SLAB_ATTR_RO(ctor);
96740
96741 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96742 {
96743- return sprintf(buf, "%d\n", s->refcount - 1);
96744+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96745 }
96746 SLAB_ATTR_RO(aliases);
96747
96748@@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96749 SLAB_ATTR_RO(cache_dma);
96750 #endif
96751
96752+#ifdef CONFIG_PAX_USERCOPY_SLABS
96753+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96754+{
96755+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96756+}
96757+SLAB_ATTR_RO(usercopy);
96758+#endif
96759+
96760 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96761 {
96762 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96763@@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
96764 #ifdef CONFIG_ZONE_DMA
96765 &cache_dma_attr.attr,
96766 #endif
96767+#ifdef CONFIG_PAX_USERCOPY_SLABS
96768+ &usercopy_attr.attr,
96769+#endif
96770 #ifdef CONFIG_NUMA
96771 &remote_node_defrag_ratio_attr.attr,
96772 #endif
96773@@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
96774 return name;
96775 }
96776
96777+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96778 static int sysfs_slab_add(struct kmem_cache *s)
96779 {
96780 int err;
96781@@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
96782 kobject_del(&s->kobj);
96783 kobject_put(&s->kobj);
96784 }
96785+#endif
96786
96787 /*
96788 * Need to buffer aliases during bootup until sysfs becomes
96789@@ -5270,6 +5356,7 @@ struct saved_alias {
96790
96791 static struct saved_alias *alias_list;
96792
96793+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96794 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96795 {
96796 struct saved_alias *al;
96797@@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96798 alias_list = al;
96799 return 0;
96800 }
96801+#endif
96802
96803 static int __init slab_sysfs_init(void)
96804 {
96805diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96806index 4cba9c2..b4f9fcc 100644
96807--- a/mm/sparse-vmemmap.c
96808+++ b/mm/sparse-vmemmap.c
96809@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96810 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96811 if (!p)
96812 return NULL;
96813- pud_populate(&init_mm, pud, p);
96814+ pud_populate_kernel(&init_mm, pud, p);
96815 }
96816 return pud;
96817 }
96818@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96819 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96820 if (!p)
96821 return NULL;
96822- pgd_populate(&init_mm, pgd, p);
96823+ pgd_populate_kernel(&init_mm, pgd, p);
96824 }
96825 return pgd;
96826 }
96827diff --git a/mm/sparse.c b/mm/sparse.c
96828index d1b48b6..6e8590e 100644
96829--- a/mm/sparse.c
96830+++ b/mm/sparse.c
96831@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96832
96833 for (i = 0; i < PAGES_PER_SECTION; i++) {
96834 if (PageHWPoison(&memmap[i])) {
96835- atomic_long_sub(1, &num_poisoned_pages);
96836+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96837 ClearPageHWPoison(&memmap[i]);
96838 }
96839 }
96840diff --git a/mm/swap.c b/mm/swap.c
96841index 9ce43ba..43bdc4c 100644
96842--- a/mm/swap.c
96843+++ b/mm/swap.c
96844@@ -31,6 +31,7 @@
96845 #include <linux/memcontrol.h>
96846 #include <linux/gfp.h>
96847 #include <linux/uio.h>
96848+#include <linux/hugetlb.h>
96849
96850 #include "internal.h"
96851
96852@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96853
96854 __page_cache_release(page);
96855 dtor = get_compound_page_dtor(page);
96856+ if (!PageHuge(page))
96857+ BUG_ON(dtor != free_compound_page);
96858 (*dtor)(page);
96859 }
96860
96861diff --git a/mm/swapfile.c b/mm/swapfile.c
96862index 4a7f7e6..22cddf5 100644
96863--- a/mm/swapfile.c
96864+++ b/mm/swapfile.c
96865@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96866
96867 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96868 /* Activity counter to indicate that a swapon or swapoff has occurred */
96869-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96870+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96871
96872 static inline unsigned char swap_count(unsigned char ent)
96873 {
96874@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96875 spin_unlock(&swap_lock);
96876
96877 err = 0;
96878- atomic_inc(&proc_poll_event);
96879+ atomic_inc_unchecked(&proc_poll_event);
96880 wake_up_interruptible(&proc_poll_wait);
96881
96882 out_dput:
96883@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96884
96885 poll_wait(file, &proc_poll_wait, wait);
96886
96887- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96888- seq->poll_event = atomic_read(&proc_poll_event);
96889+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96890+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96891 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96892 }
96893
96894@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96895 return ret;
96896
96897 seq = file->private_data;
96898- seq->poll_event = atomic_read(&proc_poll_event);
96899+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96900 return 0;
96901 }
96902
96903@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96904 (frontswap_map) ? "FS" : "");
96905
96906 mutex_unlock(&swapon_mutex);
96907- atomic_inc(&proc_poll_event);
96908+ atomic_inc_unchecked(&proc_poll_event);
96909 wake_up_interruptible(&proc_poll_wait);
96910
96911 if (S_ISREG(inode->i_mode))
96912diff --git a/mm/util.c b/mm/util.c
96913index d5ea733..e8953f9 100644
96914--- a/mm/util.c
96915+++ b/mm/util.c
96916@@ -299,6 +299,12 @@ done:
96917 void arch_pick_mmap_layout(struct mm_struct *mm)
96918 {
96919 mm->mmap_base = TASK_UNMAPPED_BASE;
96920+
96921+#ifdef CONFIG_PAX_RANDMMAP
96922+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96923+ mm->mmap_base += mm->delta_mmap;
96924+#endif
96925+
96926 mm->get_unmapped_area = arch_get_unmapped_area;
96927 }
96928 #endif
96929@@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
96930 if (!mm->arg_end)
96931 goto out_mm; /* Shh! No looking before we're done */
96932
96933+ if (gr_acl_handle_procpidmem(task))
96934+ goto out_mm;
96935+
96936 len = mm->arg_end - mm->arg_start;
96937
96938 if (len > buflen)
96939diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96940index bf233b2..1dfa1bc 100644
96941--- a/mm/vmalloc.c
96942+++ b/mm/vmalloc.c
96943@@ -40,6 +40,21 @@ struct vfree_deferred {
96944 };
96945 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
96946
96947+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96948+struct stack_deferred_llist {
96949+ struct llist_head list;
96950+ void *stack;
96951+ void *lowmem_stack;
96952+};
96953+
96954+struct stack_deferred {
96955+ struct stack_deferred_llist list;
96956+ struct work_struct wq;
96957+};
96958+
96959+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
96960+#endif
96961+
96962 static void __vunmap(const void *, int);
96963
96964 static void free_work(struct work_struct *w)
96965@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
96966 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
96967 struct llist_node *llnode = llist_del_all(&p->list);
96968 while (llnode) {
96969- void *p = llnode;
96970+ void *x = llnode;
96971 llnode = llist_next(llnode);
96972- __vunmap(p, 1);
96973+ __vunmap(x, 1);
96974 }
96975 }
96976
96977+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96978+static void unmap_work(struct work_struct *w)
96979+{
96980+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
96981+ struct llist_node *llnode = llist_del_all(&p->list.list);
96982+ while (llnode) {
96983+ struct stack_deferred_llist *x =
96984+ llist_entry((struct llist_head *)llnode,
96985+ struct stack_deferred_llist, list);
96986+ void *stack = ACCESS_ONCE(x->stack);
96987+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
96988+ llnode = llist_next(llnode);
96989+ __vunmap(stack, 0);
96990+ free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
96991+ }
96992+}
96993+#endif
96994+
96995 /*** Page table manipulation functions ***/
96996
96997 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96998@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96999
97000 pte = pte_offset_kernel(pmd, addr);
97001 do {
97002- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97003- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97004+
97005+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97006+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
97007+ BUG_ON(!pte_exec(*pte));
97008+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
97009+ continue;
97010+ }
97011+#endif
97012+
97013+ {
97014+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97015+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97016+ }
97017 } while (pte++, addr += PAGE_SIZE, addr != end);
97018 }
97019
97020@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
97021 pte = pte_alloc_kernel(pmd, addr);
97022 if (!pte)
97023 return -ENOMEM;
97024+
97025+ pax_open_kernel();
97026 do {
97027 struct page *page = pages[*nr];
97028
97029- if (WARN_ON(!pte_none(*pte)))
97030+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97031+ if (pgprot_val(prot) & _PAGE_NX)
97032+#endif
97033+
97034+ if (!pte_none(*pte)) {
97035+ pax_close_kernel();
97036+ WARN_ON(1);
97037 return -EBUSY;
97038- if (WARN_ON(!page))
97039+ }
97040+ if (!page) {
97041+ pax_close_kernel();
97042+ WARN_ON(1);
97043 return -ENOMEM;
97044+ }
97045 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
97046 (*nr)++;
97047 } while (pte++, addr += PAGE_SIZE, addr != end);
97048+ pax_close_kernel();
97049 return 0;
97050 }
97051
97052@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
97053 pmd_t *pmd;
97054 unsigned long next;
97055
97056- pmd = pmd_alloc(&init_mm, pud, addr);
97057+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
97058 if (!pmd)
97059 return -ENOMEM;
97060 do {
97061@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
97062 pud_t *pud;
97063 unsigned long next;
97064
97065- pud = pud_alloc(&init_mm, pgd, addr);
97066+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
97067 if (!pud)
97068 return -ENOMEM;
97069 do {
97070@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
97071 if (addr >= MODULES_VADDR && addr < MODULES_END)
97072 return 1;
97073 #endif
97074+
97075+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97076+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
97077+ return 1;
97078+#endif
97079+
97080 return is_vmalloc_addr(x);
97081 }
97082
97083@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
97084
97085 if (!pgd_none(*pgd)) {
97086 pud_t *pud = pud_offset(pgd, addr);
97087+#ifdef CONFIG_X86
97088+ if (!pud_large(*pud))
97089+#endif
97090 if (!pud_none(*pud)) {
97091 pmd_t *pmd = pmd_offset(pud, addr);
97092+#ifdef CONFIG_X86
97093+ if (!pmd_large(*pmd))
97094+#endif
97095 if (!pmd_none(*pmd)) {
97096 pte_t *ptep, pte;
97097
97098@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
97099 for_each_possible_cpu(i) {
97100 struct vmap_block_queue *vbq;
97101 struct vfree_deferred *p;
97102+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97103+ struct stack_deferred *p2;
97104+#endif
97105
97106 vbq = &per_cpu(vmap_block_queue, i);
97107 spin_lock_init(&vbq->lock);
97108 INIT_LIST_HEAD(&vbq->free);
97109+
97110 p = &per_cpu(vfree_deferred, i);
97111 init_llist_head(&p->list);
97112 INIT_WORK(&p->wq, free_work);
97113+
97114+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97115+ p2 = &per_cpu(stack_deferred, i);
97116+ init_llist_head(&p2->list.list);
97117+ INIT_WORK(&p2->wq, unmap_work);
97118+#endif
97119 }
97120
97121 /* Import existing vmlist entries. */
97122@@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97123 struct vm_struct *area;
97124
97125 BUG_ON(in_interrupt());
97126+
97127+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97128+ if (flags & VM_KERNEXEC) {
97129+ if (start != VMALLOC_START || end != VMALLOC_END)
97130+ return NULL;
97131+ start = (unsigned long)MODULES_EXEC_VADDR;
97132+ end = (unsigned long)MODULES_EXEC_END;
97133+ }
97134+#endif
97135+
97136 if (flags & VM_IOREMAP)
97137 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97138
97139@@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
97140 }
97141 EXPORT_SYMBOL(vunmap);
97142
97143+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97144+void unmap_process_stacks(struct task_struct *task)
97145+{
97146+ if (unlikely(in_interrupt())) {
97147+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
97148+ struct stack_deferred_llist *list = task->stack;
97149+ list->stack = task->stack;
97150+ list->lowmem_stack = task->lowmem_stack;
97151+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
97152+ schedule_work(&p->wq);
97153+ } else {
97154+ __vunmap(task->stack, 0);
97155+ free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97156+ }
97157+}
97158+#endif
97159+
97160 /**
97161 * vmap - map an array of pages into virtually contiguous space
97162 * @pages: array of page pointers
97163@@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97164 if (count > totalram_pages)
97165 return NULL;
97166
97167+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97168+ if (!(pgprot_val(prot) & _PAGE_NX))
97169+ flags |= VM_KERNEXEC;
97170+#endif
97171+
97172 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97173 __builtin_return_address(0));
97174 if (!area)
97175@@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97176 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97177 goto fail;
97178
97179+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97180+ if (!(pgprot_val(prot) & _PAGE_NX))
97181+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97182+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97183+ else
97184+#endif
97185+
97186 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97187 start, end, node, gfp_mask, caller);
97188 if (!area)
97189@@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97190 * For tight control over page level allocator and protection flags
97191 * use __vmalloc() instead.
97192 */
97193-
97194 void *vmalloc_exec(unsigned long size)
97195 {
97196- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97197+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97198 NUMA_NO_NODE, __builtin_return_address(0));
97199 }
97200
97201@@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97202 {
97203 struct vm_struct *area;
97204
97205+ BUG_ON(vma->vm_mirror);
97206+
97207 size = PAGE_ALIGN(size);
97208
97209 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97210@@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97211 v->addr, v->addr + v->size, v->size);
97212
97213 if (v->caller)
97214+#ifdef CONFIG_GRKERNSEC_HIDESYM
97215+ seq_printf(m, " %pK", v->caller);
97216+#else
97217 seq_printf(m, " %pS", v->caller);
97218+#endif
97219
97220 if (v->nr_pages)
97221 seq_printf(m, " pages=%d", v->nr_pages);
97222diff --git a/mm/vmstat.c b/mm/vmstat.c
97223index 302dd07..3841f1c 100644
97224--- a/mm/vmstat.c
97225+++ b/mm/vmstat.c
97226@@ -20,6 +20,7 @@
97227 #include <linux/writeback.h>
97228 #include <linux/compaction.h>
97229 #include <linux/mm_inline.h>
97230+#include <linux/grsecurity.h>
97231
97232 #include "internal.h"
97233
97234@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97235 *
97236 * vm_stat contains the global counters
97237 */
97238-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97239+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97240 EXPORT_SYMBOL(vm_stat);
97241
97242 #ifdef CONFIG_SMP
97243@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97244
97245 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97246 if (diff[i])
97247- atomic_long_add(diff[i], &vm_stat[i]);
97248+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97249 }
97250
97251 /*
97252@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97253 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97254 if (v) {
97255
97256- atomic_long_add(v, &zone->vm_stat[i]);
97257+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97258 global_diff[i] += v;
97259 #ifdef CONFIG_NUMA
97260 /* 3 seconds idle till flush */
97261@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97262
97263 v = p->vm_stat_diff[i];
97264 p->vm_stat_diff[i] = 0;
97265- atomic_long_add(v, &zone->vm_stat[i]);
97266+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97267 global_diff[i] += v;
97268 }
97269 }
97270@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97271 if (pset->vm_stat_diff[i]) {
97272 int v = pset->vm_stat_diff[i];
97273 pset->vm_stat_diff[i] = 0;
97274- atomic_long_add(v, &zone->vm_stat[i]);
97275- atomic_long_add(v, &vm_stat[i]);
97276+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97277+ atomic_long_add_unchecked(v, &vm_stat[i]);
97278 }
97279 }
97280 #endif
97281@@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97282 stat_items_size += sizeof(struct vm_event_state);
97283 #endif
97284
97285- v = kmalloc(stat_items_size, GFP_KERNEL);
97286+ v = kzalloc(stat_items_size, GFP_KERNEL);
97287 m->private = v;
97288 if (!v)
97289 return ERR_PTR(-ENOMEM);
97290+
97291+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97292+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97293+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97294+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97295+ && !in_group_p(grsec_proc_gid)
97296+#endif
97297+ )
97298+ return (unsigned long *)m->private + *pos;
97299+#endif
97300+#endif
97301+
97302 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97303 v[i] = global_page_state(i);
97304 v += NR_VM_ZONE_STAT_ITEMS;
97305@@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97306 cpu_notifier_register_done();
97307 #endif
97308 #ifdef CONFIG_PROC_FS
97309- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97310- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97311- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97312- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97313+ {
97314+ mode_t gr_mode = S_IRUGO;
97315+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97316+ gr_mode = S_IRUSR;
97317+#endif
97318+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97319+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97320+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97321+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97322+ }
97323 #endif
97324 return 0;
97325 }
97326diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97327index 44ebd5c..1f732bae 100644
97328--- a/net/8021q/vlan.c
97329+++ b/net/8021q/vlan.c
97330@@ -475,7 +475,7 @@ out:
97331 return NOTIFY_DONE;
97332 }
97333
97334-static struct notifier_block vlan_notifier_block __read_mostly = {
97335+static struct notifier_block vlan_notifier_block = {
97336 .notifier_call = vlan_device_event,
97337 };
97338
97339@@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97340 err = -EPERM;
97341 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97342 break;
97343- if ((args.u.name_type >= 0) &&
97344- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97345+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97346 struct vlan_net *vn;
97347
97348 vn = net_generic(net, vlan_net_id);
97349diff --git a/net/9p/client.c b/net/9p/client.c
97350index 0004cba..feba240 100644
97351--- a/net/9p/client.c
97352+++ b/net/9p/client.c
97353@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97354 len - inline_len);
97355 } else {
97356 err = copy_from_user(ename + inline_len,
97357- uidata, len - inline_len);
97358+ (char __force_user *)uidata, len - inline_len);
97359 if (err) {
97360 err = -EFAULT;
97361 goto out_err;
97362@@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97363 kernel_buf = 1;
97364 indata = data;
97365 } else
97366- indata = (__force char *)udata;
97367+ indata = (__force_kernel char *)udata;
97368 /*
97369 * response header len is 11
97370 * PDU Header(7) + IO Size (4)
97371@@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97372 kernel_buf = 1;
97373 odata = data;
97374 } else
97375- odata = (char *)udata;
97376+ odata = (char __force_kernel *)udata;
97377 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97378 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97379 fid->fid, offset, rsize);
97380diff --git a/net/9p/mod.c b/net/9p/mod.c
97381index 6ab36ae..6f1841b 100644
97382--- a/net/9p/mod.c
97383+++ b/net/9p/mod.c
97384@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97385 void v9fs_register_trans(struct p9_trans_module *m)
97386 {
97387 spin_lock(&v9fs_trans_lock);
97388- list_add_tail(&m->list, &v9fs_trans_list);
97389+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97390 spin_unlock(&v9fs_trans_lock);
97391 }
97392 EXPORT_SYMBOL(v9fs_register_trans);
97393@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97394 void v9fs_unregister_trans(struct p9_trans_module *m)
97395 {
97396 spin_lock(&v9fs_trans_lock);
97397- list_del_init(&m->list);
97398+ pax_list_del_init((struct list_head *)&m->list);
97399 spin_unlock(&v9fs_trans_lock);
97400 }
97401 EXPORT_SYMBOL(v9fs_unregister_trans);
97402diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97403index 80d08f6..de63fd1 100644
97404--- a/net/9p/trans_fd.c
97405+++ b/net/9p/trans_fd.c
97406@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97407 oldfs = get_fs();
97408 set_fs(get_ds());
97409 /* The cast to a user pointer is valid due to the set_fs() */
97410- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97411+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97412 set_fs(oldfs);
97413
97414 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97415diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97416index af46bc4..f9adfcd 100644
97417--- a/net/appletalk/atalk_proc.c
97418+++ b/net/appletalk/atalk_proc.c
97419@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97420 struct proc_dir_entry *p;
97421 int rc = -ENOMEM;
97422
97423- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97424+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97425 if (!atalk_proc_dir)
97426 goto out;
97427
97428diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97429index 876fbe8..8bbea9f 100644
97430--- a/net/atm/atm_misc.c
97431+++ b/net/atm/atm_misc.c
97432@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97433 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97434 return 1;
97435 atm_return(vcc, truesize);
97436- atomic_inc(&vcc->stats->rx_drop);
97437+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97438 return 0;
97439 }
97440 EXPORT_SYMBOL(atm_charge);
97441@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97442 }
97443 }
97444 atm_return(vcc, guess);
97445- atomic_inc(&vcc->stats->rx_drop);
97446+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97447 return NULL;
97448 }
97449 EXPORT_SYMBOL(atm_alloc_charge);
97450@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97451
97452 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97453 {
97454-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97455+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97456 __SONET_ITEMS
97457 #undef __HANDLE_ITEM
97458 }
97459@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97460
97461 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97462 {
97463-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97464+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97465 __SONET_ITEMS
97466 #undef __HANDLE_ITEM
97467 }
97468diff --git a/net/atm/lec.c b/net/atm/lec.c
97469index 4c5b8ba..95f7005 100644
97470--- a/net/atm/lec.c
97471+++ b/net/atm/lec.c
97472@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97473 }
97474
97475 static struct lane2_ops lane2_ops = {
97476- lane2_resolve, /* resolve, spec 3.1.3 */
97477- lane2_associate_req, /* associate_req, spec 3.1.4 */
97478- NULL /* associate indicator, spec 3.1.5 */
97479+ .resolve = lane2_resolve,
97480+ .associate_req = lane2_associate_req,
97481+ .associate_indicator = NULL
97482 };
97483
97484 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97485diff --git a/net/atm/lec.h b/net/atm/lec.h
97486index 4149db1..f2ab682 100644
97487--- a/net/atm/lec.h
97488+++ b/net/atm/lec.h
97489@@ -48,7 +48,7 @@ struct lane2_ops {
97490 const u8 *tlvs, u32 sizeoftlvs);
97491 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97492 const u8 *tlvs, u32 sizeoftlvs);
97493-};
97494+} __no_const;
97495
97496 /*
97497 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97498diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97499index d1b2d9a..d549f7f 100644
97500--- a/net/atm/mpoa_caches.c
97501+++ b/net/atm/mpoa_caches.c
97502@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97503
97504
97505 static struct in_cache_ops ingress_ops = {
97506- in_cache_add_entry, /* add_entry */
97507- in_cache_get, /* get */
97508- in_cache_get_with_mask, /* get_with_mask */
97509- in_cache_get_by_vcc, /* get_by_vcc */
97510- in_cache_put, /* put */
97511- in_cache_remove_entry, /* remove_entry */
97512- cache_hit, /* cache_hit */
97513- clear_count_and_expired, /* clear_count */
97514- check_resolving_entries, /* check_resolving */
97515- refresh_entries, /* refresh */
97516- in_destroy_cache /* destroy_cache */
97517+ .add_entry = in_cache_add_entry,
97518+ .get = in_cache_get,
97519+ .get_with_mask = in_cache_get_with_mask,
97520+ .get_by_vcc = in_cache_get_by_vcc,
97521+ .put = in_cache_put,
97522+ .remove_entry = in_cache_remove_entry,
97523+ .cache_hit = cache_hit,
97524+ .clear_count = clear_count_and_expired,
97525+ .check_resolving = check_resolving_entries,
97526+ .refresh = refresh_entries,
97527+ .destroy_cache = in_destroy_cache
97528 };
97529
97530 static struct eg_cache_ops egress_ops = {
97531- eg_cache_add_entry, /* add_entry */
97532- eg_cache_get_by_cache_id, /* get_by_cache_id */
97533- eg_cache_get_by_tag, /* get_by_tag */
97534- eg_cache_get_by_vcc, /* get_by_vcc */
97535- eg_cache_get_by_src_ip, /* get_by_src_ip */
97536- eg_cache_put, /* put */
97537- eg_cache_remove_entry, /* remove_entry */
97538- update_eg_cache_entry, /* update */
97539- clear_expired, /* clear_expired */
97540- eg_destroy_cache /* destroy_cache */
97541+ .add_entry = eg_cache_add_entry,
97542+ .get_by_cache_id = eg_cache_get_by_cache_id,
97543+ .get_by_tag = eg_cache_get_by_tag,
97544+ .get_by_vcc = eg_cache_get_by_vcc,
97545+ .get_by_src_ip = eg_cache_get_by_src_ip,
97546+ .put = eg_cache_put,
97547+ .remove_entry = eg_cache_remove_entry,
97548+ .update = update_eg_cache_entry,
97549+ .clear_expired = clear_expired,
97550+ .destroy_cache = eg_destroy_cache
97551 };
97552
97553
97554diff --git a/net/atm/proc.c b/net/atm/proc.c
97555index bbb6461..cf04016 100644
97556--- a/net/atm/proc.c
97557+++ b/net/atm/proc.c
97558@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97559 const struct k_atm_aal_stats *stats)
97560 {
97561 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97562- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97563- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97564- atomic_read(&stats->rx_drop));
97565+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97566+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97567+ atomic_read_unchecked(&stats->rx_drop));
97568 }
97569
97570 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97571diff --git a/net/atm/resources.c b/net/atm/resources.c
97572index 0447d5d..3cf4728 100644
97573--- a/net/atm/resources.c
97574+++ b/net/atm/resources.c
97575@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97576 static void copy_aal_stats(struct k_atm_aal_stats *from,
97577 struct atm_aal_stats *to)
97578 {
97579-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97580+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97581 __AAL_STAT_ITEMS
97582 #undef __HANDLE_ITEM
97583 }
97584@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97585 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97586 struct atm_aal_stats *to)
97587 {
97588-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97589+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97590 __AAL_STAT_ITEMS
97591 #undef __HANDLE_ITEM
97592 }
97593diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97594index 919a5ce..cc6b444 100644
97595--- a/net/ax25/sysctl_net_ax25.c
97596+++ b/net/ax25/sysctl_net_ax25.c
97597@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97598 {
97599 char path[sizeof("net/ax25/") + IFNAMSIZ];
97600 int k;
97601- struct ctl_table *table;
97602+ ctl_table_no_const *table;
97603
97604 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97605 if (!table)
97606diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97607index f04224c..f326579 100644
97608--- a/net/batman-adv/bat_iv_ogm.c
97609+++ b/net/batman-adv/bat_iv_ogm.c
97610@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97611
97612 /* randomize initial seqno to avoid collision */
97613 get_random_bytes(&random_seqno, sizeof(random_seqno));
97614- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97615+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97616
97617 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97618 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97619@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97620 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97621
97622 /* change sequence number to network order */
97623- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97624+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97625 batadv_ogm_packet->seqno = htonl(seqno);
97626- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97627+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97628
97629 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97630
97631@@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97632 return;
97633
97634 /* could be changed by schedule_own_packet() */
97635- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97636+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97637
97638 if (ogm_packet->flags & BATADV_DIRECTLINK)
97639 has_directlink_flag = true;
97640diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97641index f14e54a..66f3e2e 100644
97642--- a/net/batman-adv/fragmentation.c
97643+++ b/net/batman-adv/fragmentation.c
97644@@ -446,7 +446,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97645 frag_header.packet_type = BATADV_UNICAST_FRAG;
97646 frag_header.version = BATADV_COMPAT_VERSION;
97647 frag_header.ttl = BATADV_TTL;
97648- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97649+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97650 frag_header.reserved = 0;
97651 frag_header.no = 0;
97652 frag_header.total_size = htons(skb->len);
97653diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97654index 744a59b..8fd037c 100644
97655--- a/net/batman-adv/soft-interface.c
97656+++ b/net/batman-adv/soft-interface.c
97657@@ -296,7 +296,7 @@ send:
97658 primary_if->net_dev->dev_addr);
97659
97660 /* set broadcast sequence number */
97661- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97662+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97663 bcast_packet->seqno = htonl(seqno);
97664
97665 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97666@@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97667 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97668
97669 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97670- atomic_set(&bat_priv->bcast_seqno, 1);
97671+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97672 atomic_set(&bat_priv->tt.vn, 0);
97673 atomic_set(&bat_priv->tt.local_changes, 0);
97674 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97675@@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97676
97677 /* randomize initial seqno to avoid collision */
97678 get_random_bytes(&random_seqno, sizeof(random_seqno));
97679- atomic_set(&bat_priv->frag_seqno, random_seqno);
97680+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97681
97682 bat_priv->primary_if = NULL;
97683 bat_priv->num_ifaces = 0;
97684diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97685index 34891a5..3cfece0 100644
97686--- a/net/batman-adv/types.h
97687+++ b/net/batman-adv/types.h
97688@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
97689 struct batadv_hard_iface_bat_iv {
97690 unsigned char *ogm_buff;
97691 int ogm_buff_len;
97692- atomic_t ogm_seqno;
97693+ atomic_unchecked_t ogm_seqno;
97694 };
97695
97696 /**
97697@@ -766,7 +766,7 @@ struct batadv_priv {
97698 atomic_t bonding;
97699 atomic_t fragmentation;
97700 atomic_t packet_size_max;
97701- atomic_t frag_seqno;
97702+ atomic_unchecked_t frag_seqno;
97703 #ifdef CONFIG_BATMAN_ADV_BLA
97704 atomic_t bridge_loop_avoidance;
97705 #endif
97706@@ -785,7 +785,7 @@ struct batadv_priv {
97707 #endif
97708 uint32_t isolation_mark;
97709 uint32_t isolation_mark_mask;
97710- atomic_t bcast_seqno;
97711+ atomic_unchecked_t bcast_seqno;
97712 atomic_t bcast_queue_left;
97713 atomic_t batman_queue_left;
97714 char num_ifaces;
97715diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97716index b9a418e..2af862a 100644
97717--- a/net/bluetooth/hci_sock.c
97718+++ b/net/bluetooth/hci_sock.c
97719@@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97720 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97721 }
97722
97723- len = min_t(unsigned int, len, sizeof(uf));
97724+ len = min((size_t)len, sizeof(uf));
97725 if (copy_from_user(&uf, optval, len)) {
97726 err = -EFAULT;
97727 break;
97728diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97729index dc4d301..4975bac 100644
97730--- a/net/bluetooth/l2cap_core.c
97731+++ b/net/bluetooth/l2cap_core.c
97732@@ -3536,8 +3536,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97733 break;
97734
97735 case L2CAP_CONF_RFC:
97736- if (olen == sizeof(rfc))
97737- memcpy(&rfc, (void *)val, olen);
97738+ if (olen != sizeof(rfc))
97739+ break;
97740+
97741+ memcpy(&rfc, (void *)val, olen);
97742
97743 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97744 rfc.mode != chan->mode)
97745diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97746index ade3fb4..df37cb4 100644
97747--- a/net/bluetooth/l2cap_sock.c
97748+++ b/net/bluetooth/l2cap_sock.c
97749@@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97750 struct sock *sk = sock->sk;
97751 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97752 struct l2cap_options opts;
97753- int len, err = 0;
97754+ int err = 0;
97755+ size_t len = optlen;
97756 u32 opt;
97757
97758 BT_DBG("sk %p", sk);
97759@@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97760 opts.max_tx = chan->max_tx;
97761 opts.txwin_size = chan->tx_win;
97762
97763- len = min_t(unsigned int, sizeof(opts), optlen);
97764+ len = min(sizeof(opts), len);
97765 if (copy_from_user((char *) &opts, optval, len)) {
97766 err = -EFAULT;
97767 break;
97768@@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97769 struct bt_security sec;
97770 struct bt_power pwr;
97771 struct l2cap_conn *conn;
97772- int len, err = 0;
97773+ int err = 0;
97774+ size_t len = optlen;
97775 u32 opt;
97776
97777 BT_DBG("sk %p", sk);
97778@@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97779
97780 sec.level = BT_SECURITY_LOW;
97781
97782- len = min_t(unsigned int, sizeof(sec), optlen);
97783+ len = min(sizeof(sec), len);
97784 if (copy_from_user((char *) &sec, optval, len)) {
97785 err = -EFAULT;
97786 break;
97787@@ -866,7 +868,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97788
97789 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97790
97791- len = min_t(unsigned int, sizeof(pwr), optlen);
97792+ len = min(sizeof(pwr), len);
97793 if (copy_from_user((char *) &pwr, optval, len)) {
97794 err = -EFAULT;
97795 break;
97796diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97797index c603a5e..7f08991 100644
97798--- a/net/bluetooth/rfcomm/sock.c
97799+++ b/net/bluetooth/rfcomm/sock.c
97800@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97801 struct sock *sk = sock->sk;
97802 struct bt_security sec;
97803 int err = 0;
97804- size_t len;
97805+ size_t len = optlen;
97806 u32 opt;
97807
97808 BT_DBG("sk %p", sk);
97809@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97810
97811 sec.level = BT_SECURITY_LOW;
97812
97813- len = min_t(unsigned int, sizeof(sec), optlen);
97814+ len = min(sizeof(sec), len);
97815 if (copy_from_user((char *) &sec, optval, len)) {
97816 err = -EFAULT;
97817 break;
97818diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97819index 403ec09..a21a003 100644
97820--- a/net/bluetooth/rfcomm/tty.c
97821+++ b/net/bluetooth/rfcomm/tty.c
97822@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97823 BT_DBG("tty %p id %d", tty, tty->index);
97824
97825 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97826- dev->channel, dev->port.count);
97827+ dev->channel, atomic_read(&dev->port.count));
97828
97829 err = tty_port_open(&dev->port, tty, filp);
97830 if (err)
97831@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97832 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97833
97834 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97835- dev->port.count);
97836+ atomic_read(&dev->port.count));
97837
97838 tty_port_close(&dev->port, tty, filp);
97839 }
97840diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97841index 1059ed3..d70846a 100644
97842--- a/net/bridge/netfilter/ebtables.c
97843+++ b/net/bridge/netfilter/ebtables.c
97844@@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97845 tmp.valid_hooks = t->table->valid_hooks;
97846 }
97847 mutex_unlock(&ebt_mutex);
97848- if (copy_to_user(user, &tmp, *len) != 0) {
97849+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97850 BUGPRINT("c2u Didn't work\n");
97851 ret = -EFAULT;
97852 break;
97853@@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97854 goto out;
97855 tmp.valid_hooks = t->valid_hooks;
97856
97857- if (copy_to_user(user, &tmp, *len) != 0) {
97858+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97859 ret = -EFAULT;
97860 break;
97861 }
97862@@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97863 tmp.entries_size = t->table->entries_size;
97864 tmp.valid_hooks = t->table->valid_hooks;
97865
97866- if (copy_to_user(user, &tmp, *len) != 0) {
97867+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97868 ret = -EFAULT;
97869 break;
97870 }
97871diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97872index 0f45522..dab651f 100644
97873--- a/net/caif/cfctrl.c
97874+++ b/net/caif/cfctrl.c
97875@@ -10,6 +10,7 @@
97876 #include <linux/spinlock.h>
97877 #include <linux/slab.h>
97878 #include <linux/pkt_sched.h>
97879+#include <linux/sched.h>
97880 #include <net/caif/caif_layer.h>
97881 #include <net/caif/cfpkt.h>
97882 #include <net/caif/cfctrl.h>
97883@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97884 memset(&dev_info, 0, sizeof(dev_info));
97885 dev_info.id = 0xff;
97886 cfsrvl_init(&this->serv, 0, &dev_info, false);
97887- atomic_set(&this->req_seq_no, 1);
97888- atomic_set(&this->rsp_seq_no, 1);
97889+ atomic_set_unchecked(&this->req_seq_no, 1);
97890+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97891 this->serv.layer.receive = cfctrl_recv;
97892 sprintf(this->serv.layer.name, "ctrl");
97893 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97894@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97895 struct cfctrl_request_info *req)
97896 {
97897 spin_lock_bh(&ctrl->info_list_lock);
97898- atomic_inc(&ctrl->req_seq_no);
97899- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97900+ atomic_inc_unchecked(&ctrl->req_seq_no);
97901+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97902 list_add_tail(&req->list, &ctrl->list);
97903 spin_unlock_bh(&ctrl->info_list_lock);
97904 }
97905@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97906 if (p != first)
97907 pr_warn("Requests are not received in order\n");
97908
97909- atomic_set(&ctrl->rsp_seq_no,
97910+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97911 p->sequence_no);
97912 list_del(&p->list);
97913 goto out;
97914diff --git a/net/can/af_can.c b/net/can/af_can.c
97915index a27f8aa..67174a3 100644
97916--- a/net/can/af_can.c
97917+++ b/net/can/af_can.c
97918@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97919 };
97920
97921 /* notifier block for netdevice event */
97922-static struct notifier_block can_netdev_notifier __read_mostly = {
97923+static struct notifier_block can_netdev_notifier = {
97924 .notifier_call = can_notifier,
97925 };
97926
97927diff --git a/net/can/bcm.c b/net/can/bcm.c
97928index dcb75c0..24b1b43 100644
97929--- a/net/can/bcm.c
97930+++ b/net/can/bcm.c
97931@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97932 }
97933
97934 /* create /proc/net/can-bcm directory */
97935- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97936+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97937 return 0;
97938 }
97939
97940diff --git a/net/can/gw.c b/net/can/gw.c
97941index 050a211..bb9fe33 100644
97942--- a/net/can/gw.c
97943+++ b/net/can/gw.c
97944@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97945 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97946
97947 static HLIST_HEAD(cgw_list);
97948-static struct notifier_block notifier;
97949
97950 static struct kmem_cache *cgw_cache __read_mostly;
97951
97952@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97953 return err;
97954 }
97955
97956+static struct notifier_block notifier = {
97957+ .notifier_call = cgw_notifier
97958+};
97959+
97960 static __init int cgw_module_init(void)
97961 {
97962 /* sanitize given module parameter */
97963@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97964 return -ENOMEM;
97965
97966 /* set notifier */
97967- notifier.notifier_call = cgw_notifier;
97968 register_netdevice_notifier(&notifier);
97969
97970 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97971diff --git a/net/can/proc.c b/net/can/proc.c
97972index b543470..d2ddae2 100644
97973--- a/net/can/proc.c
97974+++ b/net/can/proc.c
97975@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97976 void can_init_proc(void)
97977 {
97978 /* create /proc/net/can directory */
97979- can_dir = proc_mkdir("can", init_net.proc_net);
97980+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97981
97982 if (!can_dir) {
97983 printk(KERN_INFO "can: failed to create /proc/net/can . "
97984diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97985index 1948d59..9e854d5 100644
97986--- a/net/ceph/messenger.c
97987+++ b/net/ceph/messenger.c
97988@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97989 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97990
97991 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97992-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97993+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97994
97995 static struct page *zero_page; /* used in certain error cases */
97996
97997@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97998 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97999 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
98000
98001- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98002+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98003 s = addr_str[i];
98004
98005 switch (ss->ss_family) {
98006diff --git a/net/compat.c b/net/compat.c
98007index 9a76eaf..5b8ccfd 100644
98008--- a/net/compat.c
98009+++ b/net/compat.c
98010@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
98011 return -EFAULT;
98012 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
98013 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
98014- kmsg->msg_name = compat_ptr(tmp1);
98015- kmsg->msg_iov = compat_ptr(tmp2);
98016- kmsg->msg_control = compat_ptr(tmp3);
98017+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
98018+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
98019+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
98020 return 0;
98021 }
98022
98023@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98024
98025 if (kern_msg->msg_namelen) {
98026 if (mode == VERIFY_READ) {
98027- int err = move_addr_to_kernel(kern_msg->msg_name,
98028+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
98029 kern_msg->msg_namelen,
98030 kern_address);
98031 if (err < 0)
98032@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98033 kern_msg->msg_name = NULL;
98034
98035 tot_len = iov_from_user_compat_to_kern(kern_iov,
98036- (struct compat_iovec __user *)kern_msg->msg_iov,
98037+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
98038 kern_msg->msg_iovlen);
98039 if (tot_len >= 0)
98040 kern_msg->msg_iov = kern_iov;
98041@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98042
98043 #define CMSG_COMPAT_FIRSTHDR(msg) \
98044 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
98045- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
98046+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
98047 (struct compat_cmsghdr __user *)NULL)
98048
98049 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
98050 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
98051 (ucmlen) <= (unsigned long) \
98052 ((mhdr)->msg_controllen - \
98053- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
98054+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
98055
98056 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
98057 struct compat_cmsghdr __user *cmsg, int cmsg_len)
98058 {
98059 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
98060- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
98061+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
98062 msg->msg_controllen)
98063 return NULL;
98064 return (struct compat_cmsghdr __user *)ptr;
98065@@ -222,7 +222,7 @@ Efault:
98066
98067 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
98068 {
98069- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98070+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98071 struct compat_cmsghdr cmhdr;
98072 struct compat_timeval ctv;
98073 struct compat_timespec cts[3];
98074@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
98075
98076 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
98077 {
98078- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98079+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98080 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
98081 int fdnum = scm->fp->count;
98082 struct file **fp = scm->fp->fp;
98083@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
98084 return -EFAULT;
98085 old_fs = get_fs();
98086 set_fs(KERNEL_DS);
98087- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
98088+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
98089 set_fs(old_fs);
98090
98091 return err;
98092@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98093 len = sizeof(ktime);
98094 old_fs = get_fs();
98095 set_fs(KERNEL_DS);
98096- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98097+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98098 set_fs(old_fs);
98099
98100 if (!err) {
98101@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98102 case MCAST_JOIN_GROUP:
98103 case MCAST_LEAVE_GROUP:
98104 {
98105- struct compat_group_req __user *gr32 = (void *)optval;
98106+ struct compat_group_req __user *gr32 = (void __user *)optval;
98107 struct group_req __user *kgr =
98108 compat_alloc_user_space(sizeof(struct group_req));
98109 u32 interface;
98110@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98111 case MCAST_BLOCK_SOURCE:
98112 case MCAST_UNBLOCK_SOURCE:
98113 {
98114- struct compat_group_source_req __user *gsr32 = (void *)optval;
98115+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98116 struct group_source_req __user *kgsr = compat_alloc_user_space(
98117 sizeof(struct group_source_req));
98118 u32 interface;
98119@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98120 }
98121 case MCAST_MSFILTER:
98122 {
98123- struct compat_group_filter __user *gf32 = (void *)optval;
98124+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98125 struct group_filter __user *kgf;
98126 u32 interface, fmode, numsrc;
98127
98128@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98129 char __user *optval, int __user *optlen,
98130 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98131 {
98132- struct compat_group_filter __user *gf32 = (void *)optval;
98133+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98134 struct group_filter __user *kgf;
98135 int __user *koptlen;
98136 u32 interface, fmode, numsrc;
98137@@ -803,7 +803,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
98138
98139 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98140 return -EINVAL;
98141- if (copy_from_user(a, args, nas[call]))
98142+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98143 return -EFAULT;
98144 a0 = a[0];
98145 a1 = a[1];
98146diff --git a/net/core/datagram.c b/net/core/datagram.c
98147index a16ed7b..eb44d17 100644
98148--- a/net/core/datagram.c
98149+++ b/net/core/datagram.c
98150@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98151 }
98152
98153 kfree_skb(skb);
98154- atomic_inc(&sk->sk_drops);
98155+ atomic_inc_unchecked(&sk->sk_drops);
98156 sk_mem_reclaim_partial(sk);
98157
98158 return err;
98159diff --git a/net/core/dev.c b/net/core/dev.c
98160index a30bef1..51d3e33 100644
98161--- a/net/core/dev.c
98162+++ b/net/core/dev.c
98163@@ -1683,14 +1683,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98164 {
98165 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98166 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98167- atomic_long_inc(&dev->rx_dropped);
98168+ atomic_long_inc_unchecked(&dev->rx_dropped);
98169 kfree_skb(skb);
98170 return NET_RX_DROP;
98171 }
98172 }
98173
98174 if (unlikely(!is_skb_forwardable(dev, skb))) {
98175- atomic_long_inc(&dev->rx_dropped);
98176+ atomic_long_inc_unchecked(&dev->rx_dropped);
98177 kfree_skb(skb);
98178 return NET_RX_DROP;
98179 }
98180@@ -2463,7 +2463,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98181
98182 struct dev_gso_cb {
98183 void (*destructor)(struct sk_buff *skb);
98184-};
98185+} __no_const;
98186
98187 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98188
98189@@ -2893,7 +2893,7 @@ recursion_alert:
98190 rc = -ENETDOWN;
98191 rcu_read_unlock_bh();
98192
98193- atomic_long_inc(&dev->tx_dropped);
98194+ atomic_long_inc_unchecked(&dev->tx_dropped);
98195 kfree_skb(skb);
98196 return rc;
98197 out:
98198@@ -3237,7 +3237,7 @@ enqueue:
98199
98200 local_irq_restore(flags);
98201
98202- atomic_long_inc(&skb->dev->rx_dropped);
98203+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98204 kfree_skb(skb);
98205 return NET_RX_DROP;
98206 }
98207@@ -3314,7 +3314,7 @@ int netif_rx_ni(struct sk_buff *skb)
98208 }
98209 EXPORT_SYMBOL(netif_rx_ni);
98210
98211-static void net_tx_action(struct softirq_action *h)
98212+static __latent_entropy void net_tx_action(void)
98213 {
98214 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98215
98216@@ -3647,7 +3647,7 @@ ncls:
98217 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98218 } else {
98219 drop:
98220- atomic_long_inc(&skb->dev->rx_dropped);
98221+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98222 kfree_skb(skb);
98223 /* Jamal, now you will not able to escape explaining
98224 * me how you were going to use this. :-)
98225@@ -4366,7 +4366,7 @@ void netif_napi_del(struct napi_struct *napi)
98226 }
98227 EXPORT_SYMBOL(netif_napi_del);
98228
98229-static void net_rx_action(struct softirq_action *h)
98230+static __latent_entropy void net_rx_action(void)
98231 {
98232 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98233 unsigned long time_limit = jiffies + 2;
98234@@ -6366,8 +6366,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98235 } else {
98236 netdev_stats_to_stats64(storage, &dev->stats);
98237 }
98238- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98239- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98240+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98241+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98242 return storage;
98243 }
98244 EXPORT_SYMBOL(dev_get_stats);
98245diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98246index cf999e0..c59a975 100644
98247--- a/net/core/dev_ioctl.c
98248+++ b/net/core/dev_ioctl.c
98249@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98250 if (no_module && capable(CAP_NET_ADMIN))
98251 no_module = request_module("netdev-%s", name);
98252 if (no_module && capable(CAP_SYS_MODULE)) {
98253+#ifdef CONFIG_GRKERNSEC_MODHARDEN
98254+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
98255+#else
98256 if (!request_module("%s", name))
98257 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98258 name);
98259+#endif
98260 }
98261 }
98262 EXPORT_SYMBOL(dev_load);
98263diff --git a/net/core/dst.c b/net/core/dst.c
98264index 80d6286..a028409 100644
98265--- a/net/core/dst.c
98266+++ b/net/core/dst.c
98267@@ -269,6 +269,15 @@ again:
98268 }
98269 EXPORT_SYMBOL(dst_destroy);
98270
98271+static void dst_destroy_rcu(struct rcu_head *head)
98272+{
98273+ struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head);
98274+
98275+ dst = dst_destroy(dst);
98276+ if (dst)
98277+ __dst_free(dst);
98278+}
98279+
98280 void dst_release(struct dst_entry *dst)
98281 {
98282 if (dst) {
98283@@ -276,11 +285,8 @@ void dst_release(struct dst_entry *dst)
98284
98285 newrefcnt = atomic_dec_return(&dst->__refcnt);
98286 WARN_ON(newrefcnt < 0);
98287- if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt) {
98288- dst = dst_destroy(dst);
98289- if (dst)
98290- __dst_free(dst);
98291- }
98292+ if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt)
98293+ call_rcu(&dst->rcu_head, dst_destroy_rcu);
98294 }
98295 }
98296 EXPORT_SYMBOL(dst_release);
98297diff --git a/net/core/filter.c b/net/core/filter.c
98298index 4aec7b9..5cf605c 100644
98299--- a/net/core/filter.c
98300+++ b/net/core/filter.c
98301@@ -1121,7 +1121,11 @@ do_pass:
98302 break;
98303
98304 default:
98305- goto err;
98306+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98307+ fp->code, fp->jt, fp->jf, fp->k);
98308+ kfree(addrs);
98309+ BUG();
98310+ return -EINVAL;
98311 }
98312
98313 insn++;
98314@@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98315 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98316 int pc, ret = 0;
98317
98318- BUILD_BUG_ON(BPF_MEMWORDS > 16);
98319+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
98320 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98321 if (!masks)
98322 return -ENOMEM;
98323@@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98324 if (!fp)
98325 return -ENOMEM;
98326
98327- memcpy(fp->insns, fprog->filter, fsize);
98328+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98329
98330 atomic_set(&fp->refcnt, 1);
98331 fp->len = fprog->len;
98332diff --git a/net/core/flow.c b/net/core/flow.c
98333index a0348fd..6951c76 100644
98334--- a/net/core/flow.c
98335+++ b/net/core/flow.c
98336@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98337 static int flow_entry_valid(struct flow_cache_entry *fle,
98338 struct netns_xfrm *xfrm)
98339 {
98340- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98341+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98342 return 0;
98343 if (fle->object && !fle->object->ops->check(fle->object))
98344 return 0;
98345@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98346 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98347 fcp->hash_count++;
98348 }
98349- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98350+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98351 flo = fle->object;
98352 if (!flo)
98353 goto ret_object;
98354@@ -263,7 +263,7 @@ nocache:
98355 }
98356 flo = resolver(net, key, family, dir, flo, ctx);
98357 if (fle) {
98358- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98359+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98360 if (!IS_ERR(flo))
98361 fle->object = flo;
98362 else
98363diff --git a/net/core/iovec.c b/net/core/iovec.c
98364index b618694..192bbba 100644
98365--- a/net/core/iovec.c
98366+++ b/net/core/iovec.c
98367@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98368 if (m->msg_namelen) {
98369 if (mode == VERIFY_READ) {
98370 void __user *namep;
98371- namep = (void __user __force *) m->msg_name;
98372+ namep = (void __force_user *) m->msg_name;
98373 err = move_addr_to_kernel(namep, m->msg_namelen,
98374 address);
98375 if (err < 0)
98376@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98377 }
98378
98379 size = m->msg_iovlen * sizeof(struct iovec);
98380- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98381+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98382 return -EFAULT;
98383
98384 m->msg_iov = iov;
98385diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98386index 32d872e..487e769 100644
98387--- a/net/core/neighbour.c
98388+++ b/net/core/neighbour.c
98389@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98390 void __user *buffer, size_t *lenp, loff_t *ppos)
98391 {
98392 int size, ret;
98393- struct ctl_table tmp = *ctl;
98394+ ctl_table_no_const tmp = *ctl;
98395
98396 tmp.extra1 = &zero;
98397 tmp.extra2 = &unres_qlen_max;
98398@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98399 void __user *buffer,
98400 size_t *lenp, loff_t *ppos)
98401 {
98402- struct ctl_table tmp = *ctl;
98403+ ctl_table_no_const tmp = *ctl;
98404 int ret;
98405
98406 tmp.extra1 = &zero;
98407@@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98408 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98409 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98410 } else {
98411+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98412 dev_name_source = "default";
98413- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98414- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98415- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98416- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98417+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98418+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98419+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98420+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98421 }
98422
98423 if (handler) {
98424diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98425index 2bf8329..2eb1423 100644
98426--- a/net/core/net-procfs.c
98427+++ b/net/core/net-procfs.c
98428@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98429 struct rtnl_link_stats64 temp;
98430 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98431
98432- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98433+ if (gr_proc_is_restricted())
98434+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98435+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98436+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98437+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98438+ else
98439+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98440 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98441 dev->name, stats->rx_bytes, stats->rx_packets,
98442 stats->rx_errors,
98443@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98444 return 0;
98445 }
98446
98447-static const struct seq_operations dev_seq_ops = {
98448+const struct seq_operations dev_seq_ops = {
98449 .start = dev_seq_start,
98450 .next = dev_seq_next,
98451 .stop = dev_seq_stop,
98452@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98453
98454 static int softnet_seq_open(struct inode *inode, struct file *file)
98455 {
98456- return seq_open(file, &softnet_seq_ops);
98457+ return seq_open_restrict(file, &softnet_seq_ops);
98458 }
98459
98460 static const struct file_operations softnet_seq_fops = {
98461@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98462 else
98463 seq_printf(seq, "%04x", ntohs(pt->type));
98464
98465+#ifdef CONFIG_GRKERNSEC_HIDESYM
98466+ seq_printf(seq, " %-8s %pf\n",
98467+ pt->dev ? pt->dev->name : "", NULL);
98468+#else
98469 seq_printf(seq, " %-8s %pf\n",
98470 pt->dev ? pt->dev->name : "", pt->func);
98471+#endif
98472 }
98473
98474 return 0;
98475diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98476index 1cac29e..fb482f3 100644
98477--- a/net/core/net-sysfs.c
98478+++ b/net/core/net-sysfs.c
98479@@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
98480 {
98481 struct net_device *netdev = to_net_dev(dev);
98482 return sprintf(buf, fmt_dec,
98483- atomic_read(&netdev->carrier_changes));
98484+ atomic_read_unchecked(&netdev->carrier_changes));
98485 }
98486 static DEVICE_ATTR_RO(carrier_changes);
98487
98488diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98489index 7c8ffd9..0cb3687 100644
98490--- a/net/core/net_namespace.c
98491+++ b/net/core/net_namespace.c
98492@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98493 int error;
98494 LIST_HEAD(net_exit_list);
98495
98496- list_add_tail(&ops->list, list);
98497+ pax_list_add_tail((struct list_head *)&ops->list, list);
98498 if (ops->init || (ops->id && ops->size)) {
98499 for_each_net(net) {
98500 error = ops_init(ops, net);
98501@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98502
98503 out_undo:
98504 /* If I have an error cleanup all namespaces I initialized */
98505- list_del(&ops->list);
98506+ pax_list_del((struct list_head *)&ops->list);
98507 ops_exit_list(ops, &net_exit_list);
98508 ops_free_list(ops, &net_exit_list);
98509 return error;
98510@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98511 struct net *net;
98512 LIST_HEAD(net_exit_list);
98513
98514- list_del(&ops->list);
98515+ pax_list_del((struct list_head *)&ops->list);
98516 for_each_net(net)
98517 list_add_tail(&net->exit_list, &net_exit_list);
98518 ops_exit_list(ops, &net_exit_list);
98519@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98520 mutex_lock(&net_mutex);
98521 error = register_pernet_operations(&pernet_list, ops);
98522 if (!error && (first_device == &pernet_list))
98523- first_device = &ops->list;
98524+ first_device = (struct list_head *)&ops->list;
98525 mutex_unlock(&net_mutex);
98526 return error;
98527 }
98528diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98529index e33937f..b2b4981 100644
98530--- a/net/core/netpoll.c
98531+++ b/net/core/netpoll.c
98532@@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98533 struct udphdr *udph;
98534 struct iphdr *iph;
98535 struct ethhdr *eth;
98536- static atomic_t ip_ident;
98537+ static atomic_unchecked_t ip_ident;
98538 struct ipv6hdr *ip6h;
98539
98540 udp_len = len + sizeof(*udph);
98541@@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98542 put_unaligned(0x45, (unsigned char *)iph);
98543 iph->tos = 0;
98544 put_unaligned(htons(ip_len), &(iph->tot_len));
98545- iph->id = htons(atomic_inc_return(&ip_ident));
98546+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98547 iph->frag_off = 0;
98548 iph->ttl = 64;
98549 iph->protocol = IPPROTO_UDP;
98550diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98551index 0304f98..ddfead6 100644
98552--- a/net/core/pktgen.c
98553+++ b/net/core/pktgen.c
98554@@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
98555 pn->net = net;
98556 INIT_LIST_HEAD(&pn->pktgen_threads);
98557 pn->pktgen_exiting = false;
98558- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98559+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98560 if (!pn->proc_dir) {
98561 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98562 return -ENODEV;
98563diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98564index 1999ed8..1e6e58a 100644
98565--- a/net/core/rtnetlink.c
98566+++ b/net/core/rtnetlink.c
98567@@ -58,7 +58,7 @@ struct rtnl_link {
98568 rtnl_doit_func doit;
98569 rtnl_dumpit_func dumpit;
98570 rtnl_calcit_func calcit;
98571-};
98572+} __no_const;
98573
98574 static DEFINE_MUTEX(rtnl_mutex);
98575
98576@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98577 if (rtnl_link_ops_get(ops->kind))
98578 return -EEXIST;
98579
98580- if (!ops->dellink)
98581- ops->dellink = unregister_netdevice_queue;
98582+ if (!ops->dellink) {
98583+ pax_open_kernel();
98584+ *(void **)&ops->dellink = unregister_netdevice_queue;
98585+ pax_close_kernel();
98586+ }
98587
98588- list_add_tail(&ops->list, &link_ops);
98589+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98590 return 0;
98591 }
98592 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98593@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98594 for_each_net(net) {
98595 __rtnl_kill_links(net, ops);
98596 }
98597- list_del(&ops->list);
98598+ pax_list_del((struct list_head *)&ops->list);
98599 }
98600 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98601
98602@@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
98603 (dev->ifalias &&
98604 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
98605 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
98606- atomic_read(&dev->carrier_changes)))
98607+ atomic_read_unchecked(&dev->carrier_changes)))
98608 goto nla_put_failure;
98609
98610 if (1) {
98611diff --git a/net/core/scm.c b/net/core/scm.c
98612index b442e7e..6f5b5a2 100644
98613--- a/net/core/scm.c
98614+++ b/net/core/scm.c
98615@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98616 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98617 {
98618 struct cmsghdr __user *cm
98619- = (__force struct cmsghdr __user *)msg->msg_control;
98620+ = (struct cmsghdr __force_user *)msg->msg_control;
98621 struct cmsghdr cmhdr;
98622 int cmlen = CMSG_LEN(len);
98623 int err;
98624@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98625 err = -EFAULT;
98626 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98627 goto out;
98628- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98629+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98630 goto out;
98631 cmlen = CMSG_SPACE(len);
98632 if (msg->msg_controllen < cmlen)
98633@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98634 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98635 {
98636 struct cmsghdr __user *cm
98637- = (__force struct cmsghdr __user*)msg->msg_control;
98638+ = (struct cmsghdr __force_user *)msg->msg_control;
98639
98640 int fdmax = 0;
98641 int fdnum = scm->fp->count;
98642@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98643 if (fdnum < fdmax)
98644 fdmax = fdnum;
98645
98646- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98647+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98648 i++, cmfptr++)
98649 {
98650 struct socket *sock;
98651diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98652index 8383b2b..6397efb 100644
98653--- a/net/core/skbuff.c
98654+++ b/net/core/skbuff.c
98655@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98656 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98657 int len, __wsum csum)
98658 {
98659- const struct skb_checksum_ops ops = {
98660+ static const struct skb_checksum_ops ops = {
98661 .update = csum_partial_ext,
98662 .combine = csum_block_add_ext,
98663 };
98664@@ -3220,13 +3220,15 @@ void __init skb_init(void)
98665 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98666 sizeof(struct sk_buff),
98667 0,
98668- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98669+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98670+ SLAB_NO_SANITIZE,
98671 NULL);
98672 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98673 (2*sizeof(struct sk_buff)) +
98674 sizeof(atomic_t),
98675 0,
98676- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98677+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98678+ SLAB_NO_SANITIZE,
98679 NULL);
98680 }
98681
98682diff --git a/net/core/sock.c b/net/core/sock.c
98683index 664ee42..aaf9e6e 100644
98684--- a/net/core/sock.c
98685+++ b/net/core/sock.c
98686@@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98687 struct sk_buff_head *list = &sk->sk_receive_queue;
98688
98689 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98690- atomic_inc(&sk->sk_drops);
98691+ atomic_inc_unchecked(&sk->sk_drops);
98692 trace_sock_rcvqueue_full(sk, skb);
98693 return -ENOMEM;
98694 }
98695@@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98696 return err;
98697
98698 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98699- atomic_inc(&sk->sk_drops);
98700+ atomic_inc_unchecked(&sk->sk_drops);
98701 return -ENOBUFS;
98702 }
98703
98704@@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98705 skb_dst_force(skb);
98706
98707 spin_lock_irqsave(&list->lock, flags);
98708- skb->dropcount = atomic_read(&sk->sk_drops);
98709+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98710 __skb_queue_tail(list, skb);
98711 spin_unlock_irqrestore(&list->lock, flags);
98712
98713@@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98714 skb->dev = NULL;
98715
98716 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98717- atomic_inc(&sk->sk_drops);
98718+ atomic_inc_unchecked(&sk->sk_drops);
98719 goto discard_and_relse;
98720 }
98721 if (nested)
98722@@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98723 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98724 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98725 bh_unlock_sock(sk);
98726- atomic_inc(&sk->sk_drops);
98727+ atomic_inc_unchecked(&sk->sk_drops);
98728 goto discard_and_relse;
98729 }
98730
98731@@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98732 struct timeval tm;
98733 } v;
98734
98735- int lv = sizeof(int);
98736- int len;
98737+ unsigned int lv = sizeof(int);
98738+ unsigned int len;
98739
98740 if (get_user(len, optlen))
98741 return -EFAULT;
98742- if (len < 0)
98743+ if (len > INT_MAX)
98744 return -EINVAL;
98745
98746 memset(&v, 0, sizeof(v));
98747@@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98748
98749 case SO_PEERNAME:
98750 {
98751- char address[128];
98752+ char address[_K_SS_MAXSIZE];
98753
98754 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98755 return -ENOTCONN;
98756- if (lv < len)
98757+ if (lv < len || sizeof address < len)
98758 return -EINVAL;
98759 if (copy_to_user(optval, address, len))
98760 return -EFAULT;
98761@@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98762
98763 if (len > lv)
98764 len = lv;
98765- if (copy_to_user(optval, &v, len))
98766+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
98767 return -EFAULT;
98768 lenout:
98769 if (put_user(len, optlen))
98770@@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98771 */
98772 smp_wmb();
98773 atomic_set(&sk->sk_refcnt, 1);
98774- atomic_set(&sk->sk_drops, 0);
98775+ atomic_set_unchecked(&sk->sk_drops, 0);
98776 }
98777 EXPORT_SYMBOL(sock_init_data);
98778
98779@@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98780 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98781 int level, int type)
98782 {
98783+ struct sock_extended_err ee;
98784 struct sock_exterr_skb *serr;
98785 struct sk_buff *skb, *skb2;
98786 int copied, err;
98787@@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98788 sock_recv_timestamp(msg, sk, skb);
98789
98790 serr = SKB_EXT_ERR(skb);
98791- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98792+ ee = serr->ee;
98793+ put_cmsg(msg, level, type, sizeof ee, &ee);
98794
98795 msg->msg_flags |= MSG_ERRQUEUE;
98796 err = copied;
98797diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98798index a4216a4..1c07687 100644
98799--- a/net/core/sock_diag.c
98800+++ b/net/core/sock_diag.c
98801@@ -9,26 +9,33 @@
98802 #include <linux/inet_diag.h>
98803 #include <linux/sock_diag.h>
98804
98805-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98806+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98807 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98808 static DEFINE_MUTEX(sock_diag_table_mutex);
98809
98810 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98811 {
98812+#ifndef CONFIG_GRKERNSEC_HIDESYM
98813 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98814 cookie[1] != INET_DIAG_NOCOOKIE) &&
98815 ((u32)(unsigned long)sk != cookie[0] ||
98816 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98817 return -ESTALE;
98818 else
98819+#endif
98820 return 0;
98821 }
98822 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98823
98824 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98825 {
98826+#ifdef CONFIG_GRKERNSEC_HIDESYM
98827+ cookie[0] = 0;
98828+ cookie[1] = 0;
98829+#else
98830 cookie[0] = (u32)(unsigned long)sk;
98831 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98832+#endif
98833 }
98834 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98835
98836@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98837 mutex_lock(&sock_diag_table_mutex);
98838 if (sock_diag_handlers[hndl->family])
98839 err = -EBUSY;
98840- else
98841+ else {
98842+ pax_open_kernel();
98843 sock_diag_handlers[hndl->family] = hndl;
98844+ pax_close_kernel();
98845+ }
98846 mutex_unlock(&sock_diag_table_mutex);
98847
98848 return err;
98849@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98850
98851 mutex_lock(&sock_diag_table_mutex);
98852 BUG_ON(sock_diag_handlers[family] != hnld);
98853+ pax_open_kernel();
98854 sock_diag_handlers[family] = NULL;
98855+ pax_close_kernel();
98856 mutex_unlock(&sock_diag_table_mutex);
98857 }
98858 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98859diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98860index cf9cd13..8b56af3 100644
98861--- a/net/core/sysctl_net_core.c
98862+++ b/net/core/sysctl_net_core.c
98863@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98864 {
98865 unsigned int orig_size, size;
98866 int ret, i;
98867- struct ctl_table tmp = {
98868+ ctl_table_no_const tmp = {
98869 .data = &size,
98870 .maxlen = sizeof(size),
98871 .mode = table->mode
98872@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98873 void __user *buffer, size_t *lenp, loff_t *ppos)
98874 {
98875 char id[IFNAMSIZ];
98876- struct ctl_table tbl = {
98877+ ctl_table_no_const tbl = {
98878 .data = id,
98879 .maxlen = IFNAMSIZ,
98880 };
98881@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98882
98883 static __net_init int sysctl_core_net_init(struct net *net)
98884 {
98885- struct ctl_table *tbl;
98886+ ctl_table_no_const *tbl = NULL;
98887
98888 net->core.sysctl_somaxconn = SOMAXCONN;
98889
98890- tbl = netns_core_table;
98891 if (!net_eq(net, &init_net)) {
98892- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98893+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98894 if (tbl == NULL)
98895 goto err_dup;
98896
98897@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98898 if (net->user_ns != &init_user_ns) {
98899 tbl[0].procname = NULL;
98900 }
98901- }
98902-
98903- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98904+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98905+ } else
98906+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98907 if (net->core.sysctl_hdr == NULL)
98908 goto err_reg;
98909
98910 return 0;
98911
98912 err_reg:
98913- if (tbl != netns_core_table)
98914- kfree(tbl);
98915+ kfree(tbl);
98916 err_dup:
98917 return -ENOMEM;
98918 }
98919@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98920 kfree(tbl);
98921 }
98922
98923-static __net_initdata struct pernet_operations sysctl_core_ops = {
98924+static __net_initconst struct pernet_operations sysctl_core_ops = {
98925 .init = sysctl_core_net_init,
98926 .exit = sysctl_core_net_exit,
98927 };
98928diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98929index 4c04848..f575934 100644
98930--- a/net/decnet/af_decnet.c
98931+++ b/net/decnet/af_decnet.c
98932@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98933 .sysctl_rmem = sysctl_decnet_rmem,
98934 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98935 .obj_size = sizeof(struct dn_sock),
98936+ .slab_flags = SLAB_USERCOPY,
98937 };
98938
98939 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98940diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98941index 3b726f3..1af6368 100644
98942--- a/net/decnet/dn_dev.c
98943+++ b/net/decnet/dn_dev.c
98944@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98945 .extra1 = &min_t3,
98946 .extra2 = &max_t3
98947 },
98948- {0}
98949+ { }
98950 },
98951 };
98952
98953diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98954index 5325b54..a0d4d69 100644
98955--- a/net/decnet/sysctl_net_decnet.c
98956+++ b/net/decnet/sysctl_net_decnet.c
98957@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98958
98959 if (len > *lenp) len = *lenp;
98960
98961- if (copy_to_user(buffer, addr, len))
98962+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98963 return -EFAULT;
98964
98965 *lenp = len;
98966@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98967
98968 if (len > *lenp) len = *lenp;
98969
98970- if (copy_to_user(buffer, devname, len))
98971+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98972 return -EFAULT;
98973
98974 *lenp = len;
98975diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
98976index ef2d543..5b9b73f 100644
98977--- a/net/ieee802154/reassembly.c
98978+++ b/net/ieee802154/reassembly.c
98979@@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
98980
98981 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98982 {
98983- struct ctl_table *table;
98984+ ctl_table_no_const *table = NULL;
98985 struct ctl_table_header *hdr;
98986
98987- table = lowpan_frags_ns_ctl_table;
98988 if (!net_eq(net, &init_net)) {
98989- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
98990+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
98991 GFP_KERNEL);
98992 if (table == NULL)
98993 goto err_alloc;
98994@@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98995 /* Don't export sysctls to unprivileged users */
98996 if (net->user_ns != &init_user_ns)
98997 table[0].procname = NULL;
98998- }
98999-
99000- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99001+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99002+ } else
99003+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
99004 if (hdr == NULL)
99005 goto err_reg;
99006
99007@@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99008 return 0;
99009
99010 err_reg:
99011- if (!net_eq(net, &init_net))
99012- kfree(table);
99013+ kfree(table);
99014 err_alloc:
99015 return -ENOMEM;
99016 }
99017diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
99018index 6d6dd34..e5c9bec 100644
99019--- a/net/ipv4/af_inet.c
99020+++ b/net/ipv4/af_inet.c
99021@@ -1736,13 +1736,9 @@ static int __init inet_init(void)
99022
99023 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
99024
99025- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
99026- if (!sysctl_local_reserved_ports)
99027- goto out;
99028-
99029 rc = proto_register(&tcp_prot, 1);
99030 if (rc)
99031- goto out_free_reserved_ports;
99032+ goto out;
99033
99034 rc = proto_register(&udp_prot, 1);
99035 if (rc)
99036@@ -1852,8 +1848,6 @@ out_unregister_udp_proto:
99037 proto_unregister(&udp_prot);
99038 out_unregister_tcp_proto:
99039 proto_unregister(&tcp_prot);
99040-out_free_reserved_ports:
99041- kfree(sysctl_local_reserved_ports);
99042 goto out;
99043 }
99044
99045diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
99046index bdbf68b..deb4759 100644
99047--- a/net/ipv4/devinet.c
99048+++ b/net/ipv4/devinet.c
99049@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
99050 idx = 0;
99051 head = &net->dev_index_head[h];
99052 rcu_read_lock();
99053- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99054+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99055 net->dev_base_seq;
99056 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99057 if (idx < s_idx)
99058@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
99059 idx = 0;
99060 head = &net->dev_index_head[h];
99061 rcu_read_lock();
99062- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99063+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99064 net->dev_base_seq;
99065 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99066 if (idx < s_idx)
99067@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
99068 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
99069 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
99070
99071-static struct devinet_sysctl_table {
99072+static const struct devinet_sysctl_table {
99073 struct ctl_table_header *sysctl_header;
99074 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
99075 } devinet_sysctl = {
99076@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
99077 int err;
99078 struct ipv4_devconf *all, *dflt;
99079 #ifdef CONFIG_SYSCTL
99080- struct ctl_table *tbl = ctl_forward_entry;
99081+ ctl_table_no_const *tbl = NULL;
99082 struct ctl_table_header *forw_hdr;
99083 #endif
99084
99085@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
99086 goto err_alloc_dflt;
99087
99088 #ifdef CONFIG_SYSCTL
99089- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99090+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99091 if (tbl == NULL)
99092 goto err_alloc_ctl;
99093
99094@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99095 goto err_reg_dflt;
99096
99097 err = -ENOMEM;
99098- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99099+ if (!net_eq(net, &init_net))
99100+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99101+ else
99102+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99103 if (forw_hdr == NULL)
99104 goto err_reg_ctl;
99105 net->ipv4.forw_hdr = forw_hdr;
99106@@ -2272,8 +2275,7 @@ err_reg_ctl:
99107 err_reg_dflt:
99108 __devinet_sysctl_unregister(all);
99109 err_reg_all:
99110- if (tbl != ctl_forward_entry)
99111- kfree(tbl);
99112+ kfree(tbl);
99113 err_alloc_ctl:
99114 #endif
99115 if (dflt != &ipv4_devconf_dflt)
99116diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99117index 255aa99..45c78f8 100644
99118--- a/net/ipv4/fib_frontend.c
99119+++ b/net/ipv4/fib_frontend.c
99120@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99121 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99122 fib_sync_up(dev);
99123 #endif
99124- atomic_inc(&net->ipv4.dev_addr_genid);
99125+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99126 rt_cache_flush(dev_net(dev));
99127 break;
99128 case NETDEV_DOWN:
99129 fib_del_ifaddr(ifa, NULL);
99130- atomic_inc(&net->ipv4.dev_addr_genid);
99131+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99132 if (ifa->ifa_dev->ifa_list == NULL) {
99133 /* Last address was deleted from this interface.
99134 * Disable IP.
99135@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99136 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99137 fib_sync_up(dev);
99138 #endif
99139- atomic_inc(&net->ipv4.dev_addr_genid);
99140+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99141 rt_cache_flush(net);
99142 break;
99143 case NETDEV_DOWN:
99144diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99145index b10cd43a..22327f9 100644
99146--- a/net/ipv4/fib_semantics.c
99147+++ b/net/ipv4/fib_semantics.c
99148@@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99149 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99150 nh->nh_gw,
99151 nh->nh_parent->fib_scope);
99152- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99153+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99154
99155 return nh->nh_saddr;
99156 }
99157diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99158index a56b8e6..5be2a30 100644
99159--- a/net/ipv4/inet_connection_sock.c
99160+++ b/net/ipv4/inet_connection_sock.c
99161@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99162 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99163 #endif
99164
99165-unsigned long *sysctl_local_reserved_ports;
99166+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99167 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99168
99169 void inet_get_local_port_range(struct net *net, int *low, int *high)
99170diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99171index 8b9cf27..0d8d592 100644
99172--- a/net/ipv4/inet_hashtables.c
99173+++ b/net/ipv4/inet_hashtables.c
99174@@ -18,6 +18,7 @@
99175 #include <linux/sched.h>
99176 #include <linux/slab.h>
99177 #include <linux/wait.h>
99178+#include <linux/security.h>
99179
99180 #include <net/inet_connection_sock.h>
99181 #include <net/inet_hashtables.h>
99182@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99183 return inet_ehashfn(net, laddr, lport, faddr, fport);
99184 }
99185
99186+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99187+
99188 /*
99189 * Allocate and initialize a new local port bind bucket.
99190 * The bindhash mutex for snum's hash chain must be held here.
99191@@ -554,6 +557,8 @@ ok:
99192 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99193 spin_unlock(&head->lock);
99194
99195+ gr_update_task_in_ip_table(current, inet_sk(sk));
99196+
99197 if (tw) {
99198 inet_twsk_deschedule(tw, death_row);
99199 while (twrefcnt) {
99200diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99201index 48f4244..f56d83a 100644
99202--- a/net/ipv4/inetpeer.c
99203+++ b/net/ipv4/inetpeer.c
99204@@ -496,8 +496,8 @@ relookup:
99205 if (p) {
99206 p->daddr = *daddr;
99207 atomic_set(&p->refcnt, 1);
99208- atomic_set(&p->rid, 0);
99209- atomic_set(&p->ip_id_count,
99210+ atomic_set_unchecked(&p->rid, 0);
99211+ atomic_set_unchecked(&p->ip_id_count,
99212 (daddr->family == AF_INET) ?
99213 secure_ip_id(daddr->addr.a4) :
99214 secure_ipv6_id(daddr->addr.a6));
99215diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99216index ed32313..3762abe 100644
99217--- a/net/ipv4/ip_fragment.c
99218+++ b/net/ipv4/ip_fragment.c
99219@@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99220 return 0;
99221
99222 start = qp->rid;
99223- end = atomic_inc_return(&peer->rid);
99224+ end = atomic_inc_return_unchecked(&peer->rid);
99225 qp->rid = end;
99226
99227 rc = qp->q.fragments && (end - start) > max;
99228@@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99229
99230 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99231 {
99232- struct ctl_table *table;
99233+ ctl_table_no_const *table = NULL;
99234 struct ctl_table_header *hdr;
99235
99236- table = ip4_frags_ns_ctl_table;
99237 if (!net_eq(net, &init_net)) {
99238- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99239+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99240 if (table == NULL)
99241 goto err_alloc;
99242
99243@@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99244 /* Don't export sysctls to unprivileged users */
99245 if (net->user_ns != &init_user_ns)
99246 table[0].procname = NULL;
99247- }
99248+ hdr = register_net_sysctl(net, "net/ipv4", table);
99249+ } else
99250+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99251
99252- hdr = register_net_sysctl(net, "net/ipv4", table);
99253 if (hdr == NULL)
99254 goto err_reg;
99255
99256@@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99257 return 0;
99258
99259 err_reg:
99260- if (!net_eq(net, &init_net))
99261- kfree(table);
99262+ kfree(table);
99263 err_alloc:
99264 return -ENOMEM;
99265 }
99266diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99267index 94213c8..8bdb342 100644
99268--- a/net/ipv4/ip_gre.c
99269+++ b/net/ipv4/ip_gre.c
99270@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99271 module_param(log_ecn_error, bool, 0644);
99272 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99273
99274-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99275+static struct rtnl_link_ops ipgre_link_ops;
99276 static int ipgre_tunnel_init(struct net_device *dev);
99277
99278 static int ipgre_net_id __read_mostly;
99279@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99280 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99281 };
99282
99283-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99284+static struct rtnl_link_ops ipgre_link_ops = {
99285 .kind = "gre",
99286 .maxtype = IFLA_GRE_MAX,
99287 .policy = ipgre_policy,
99288@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99289 .fill_info = ipgre_fill_info,
99290 };
99291
99292-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99293+static struct rtnl_link_ops ipgre_tap_ops = {
99294 .kind = "gretap",
99295 .maxtype = IFLA_GRE_MAX,
99296 .policy = ipgre_policy,
99297diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99298index 64741b9..6f334a2 100644
99299--- a/net/ipv4/ip_sockglue.c
99300+++ b/net/ipv4/ip_sockglue.c
99301@@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99302 len = min_t(unsigned int, len, opt->optlen);
99303 if (put_user(len, optlen))
99304 return -EFAULT;
99305- if (copy_to_user(optval, opt->__data, len))
99306+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99307+ copy_to_user(optval, opt->__data, len))
99308 return -EFAULT;
99309 return 0;
99310 }
99311@@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99312 if (sk->sk_type != SOCK_STREAM)
99313 return -ENOPROTOOPT;
99314
99315- msg.msg_control = optval;
99316+ msg.msg_control = (void __force_kernel *)optval;
99317 msg.msg_controllen = len;
99318 msg.msg_flags = flags;
99319
99320diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
99321index 2acc233..b93143f 100644
99322--- a/net/ipv4/ip_tunnel.c
99323+++ b/net/ipv4/ip_tunnel.c
99324@@ -73,12 +73,7 @@ static void __tunnel_dst_set(struct ip_tunnel_dst *idst,
99325 {
99326 struct dst_entry *old_dst;
99327
99328- if (dst) {
99329- if (dst->flags & DST_NOCACHE)
99330- dst = NULL;
99331- else
99332- dst_clone(dst);
99333- }
99334+ dst_clone(dst);
99335 old_dst = xchg((__force struct dst_entry **)&idst->dst, dst);
99336 dst_release(old_dst);
99337 }
99338@@ -108,13 +103,14 @@ static struct rtable *tunnel_rtable_get(struct ip_tunnel *t, u32 cookie)
99339
99340 rcu_read_lock();
99341 dst = rcu_dereference(this_cpu_ptr(t->dst_cache)->dst);
99342+ if (dst && !atomic_inc_not_zero(&dst->__refcnt))
99343+ dst = NULL;
99344 if (dst) {
99345 if (dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
99346- rcu_read_unlock();
99347 tunnel_dst_reset(t);
99348- return NULL;
99349+ dst_release(dst);
99350+ dst = NULL;
99351 }
99352- dst_hold(dst);
99353 }
99354 rcu_read_unlock();
99355 return (struct rtable *)dst;
99356diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99357index 13ef00f..8ffca25 100644
99358--- a/net/ipv4/ip_vti.c
99359+++ b/net/ipv4/ip_vti.c
99360@@ -45,7 +45,7 @@
99361 #include <net/net_namespace.h>
99362 #include <net/netns/generic.h>
99363
99364-static struct rtnl_link_ops vti_link_ops __read_mostly;
99365+static struct rtnl_link_ops vti_link_ops;
99366
99367 static int vti_net_id __read_mostly;
99368 static int vti_tunnel_init(struct net_device *dev);
99369@@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99370 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99371 };
99372
99373-static struct rtnl_link_ops vti_link_ops __read_mostly = {
99374+static struct rtnl_link_ops vti_link_ops = {
99375 .kind = "vti",
99376 .maxtype = IFLA_VTI_MAX,
99377 .policy = vti_policy,
99378diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99379index b3e86ea..18ce98c 100644
99380--- a/net/ipv4/ipconfig.c
99381+++ b/net/ipv4/ipconfig.c
99382@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99383
99384 mm_segment_t oldfs = get_fs();
99385 set_fs(get_ds());
99386- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99387+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99388 set_fs(oldfs);
99389 return res;
99390 }
99391@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99392
99393 mm_segment_t oldfs = get_fs();
99394 set_fs(get_ds());
99395- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99396+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99397 set_fs(oldfs);
99398 return res;
99399 }
99400@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99401
99402 mm_segment_t oldfs = get_fs();
99403 set_fs(get_ds());
99404- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99405+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99406 set_fs(oldfs);
99407 return res;
99408 }
99409diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99410index 62eaa00..29b2dc2 100644
99411--- a/net/ipv4/ipip.c
99412+++ b/net/ipv4/ipip.c
99413@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99414 static int ipip_net_id __read_mostly;
99415
99416 static int ipip_tunnel_init(struct net_device *dev);
99417-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99418+static struct rtnl_link_ops ipip_link_ops;
99419
99420 static int ipip_err(struct sk_buff *skb, u32 info)
99421 {
99422@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99423 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99424 };
99425
99426-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99427+static struct rtnl_link_ops ipip_link_ops = {
99428 .kind = "ipip",
99429 .maxtype = IFLA_IPTUN_MAX,
99430 .policy = ipip_policy,
99431diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99432index f95b6f9..2ee2097 100644
99433--- a/net/ipv4/netfilter/arp_tables.c
99434+++ b/net/ipv4/netfilter/arp_tables.c
99435@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99436 #endif
99437
99438 static int get_info(struct net *net, void __user *user,
99439- const int *len, int compat)
99440+ int len, int compat)
99441 {
99442 char name[XT_TABLE_MAXNAMELEN];
99443 struct xt_table *t;
99444 int ret;
99445
99446- if (*len != sizeof(struct arpt_getinfo)) {
99447- duprintf("length %u != %Zu\n", *len,
99448+ if (len != sizeof(struct arpt_getinfo)) {
99449+ duprintf("length %u != %Zu\n", len,
99450 sizeof(struct arpt_getinfo));
99451 return -EINVAL;
99452 }
99453@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99454 info.size = private->size;
99455 strcpy(info.name, name);
99456
99457- if (copy_to_user(user, &info, *len) != 0)
99458+ if (copy_to_user(user, &info, len) != 0)
99459 ret = -EFAULT;
99460 else
99461 ret = 0;
99462@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99463
99464 switch (cmd) {
99465 case ARPT_SO_GET_INFO:
99466- ret = get_info(sock_net(sk), user, len, 1);
99467+ ret = get_info(sock_net(sk), user, *len, 1);
99468 break;
99469 case ARPT_SO_GET_ENTRIES:
99470 ret = compat_get_entries(sock_net(sk), user, len);
99471@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99472
99473 switch (cmd) {
99474 case ARPT_SO_GET_INFO:
99475- ret = get_info(sock_net(sk), user, len, 0);
99476+ ret = get_info(sock_net(sk), user, *len, 0);
99477 break;
99478
99479 case ARPT_SO_GET_ENTRIES:
99480diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99481index 99e810f..3711b81 100644
99482--- a/net/ipv4/netfilter/ip_tables.c
99483+++ b/net/ipv4/netfilter/ip_tables.c
99484@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99485 #endif
99486
99487 static int get_info(struct net *net, void __user *user,
99488- const int *len, int compat)
99489+ int len, int compat)
99490 {
99491 char name[XT_TABLE_MAXNAMELEN];
99492 struct xt_table *t;
99493 int ret;
99494
99495- if (*len != sizeof(struct ipt_getinfo)) {
99496- duprintf("length %u != %zu\n", *len,
99497+ if (len != sizeof(struct ipt_getinfo)) {
99498+ duprintf("length %u != %zu\n", len,
99499 sizeof(struct ipt_getinfo));
99500 return -EINVAL;
99501 }
99502@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99503 info.size = private->size;
99504 strcpy(info.name, name);
99505
99506- if (copy_to_user(user, &info, *len) != 0)
99507+ if (copy_to_user(user, &info, len) != 0)
99508 ret = -EFAULT;
99509 else
99510 ret = 0;
99511@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99512
99513 switch (cmd) {
99514 case IPT_SO_GET_INFO:
99515- ret = get_info(sock_net(sk), user, len, 1);
99516+ ret = get_info(sock_net(sk), user, *len, 1);
99517 break;
99518 case IPT_SO_GET_ENTRIES:
99519 ret = compat_get_entries(sock_net(sk), user, len);
99520@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99521
99522 switch (cmd) {
99523 case IPT_SO_GET_INFO:
99524- ret = get_info(sock_net(sk), user, len, 0);
99525+ ret = get_info(sock_net(sk), user, *len, 0);
99526 break;
99527
99528 case IPT_SO_GET_ENTRIES:
99529diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99530index 2510c02..cfb34fa 100644
99531--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99532+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99533@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99534 spin_lock_init(&cn->lock);
99535
99536 #ifdef CONFIG_PROC_FS
99537- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99538+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99539 if (!cn->procdir) {
99540 pr_err("Unable to proc dir entry\n");
99541 return -ENOMEM;
99542diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99543index 044a0dd..e0c1971 100644
99544--- a/net/ipv4/ping.c
99545+++ b/net/ipv4/ping.c
99546@@ -59,7 +59,7 @@ struct ping_table {
99547 };
99548
99549 static struct ping_table ping_table;
99550-struct pingv6_ops pingv6_ops;
99551+struct pingv6_ops *pingv6_ops;
99552 EXPORT_SYMBOL_GPL(pingv6_ops);
99553
99554 static u16 ping_port_rover;
99555@@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99556 return -ENODEV;
99557 }
99558 }
99559- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99560+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99561 scoped);
99562 rcu_read_unlock();
99563
99564@@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99565 }
99566 #if IS_ENABLED(CONFIG_IPV6)
99567 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99568- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99569+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99570 #endif
99571 }
99572
99573@@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99574 info, (u8 *)icmph);
99575 #if IS_ENABLED(CONFIG_IPV6)
99576 } else if (family == AF_INET6) {
99577- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99578+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99579 info, (u8 *)icmph);
99580 #endif
99581 }
99582@@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99583 {
99584 struct inet_sock *isk = inet_sk(sk);
99585 int family = sk->sk_family;
99586+ struct sockaddr_in *sin;
99587+ struct sockaddr_in6 *sin6;
99588 struct sk_buff *skb;
99589 int copied, err;
99590
99591@@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99592 if (flags & MSG_OOB)
99593 goto out;
99594
99595+ if (addr_len) {
99596+ if (family == AF_INET)
99597+ *addr_len = sizeof(*sin);
99598+ else if (family == AF_INET6 && addr_len)
99599+ *addr_len = sizeof(*sin6);
99600+ }
99601+
99602 if (flags & MSG_ERRQUEUE) {
99603 if (family == AF_INET) {
99604 return ip_recv_error(sk, msg, len, addr_len);
99605 #if IS_ENABLED(CONFIG_IPV6)
99606 } else if (family == AF_INET6) {
99607- return pingv6_ops.ipv6_recv_error(sk, msg, len,
99608+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
99609 addr_len);
99610 #endif
99611 }
99612@@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99613 sin->sin_port = 0 /* skb->h.uh->source */;
99614 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99615 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99616- *addr_len = sizeof(*sin);
99617 }
99618
99619 if (isk->cmsg_flags)
99620@@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99621 sin6->sin6_scope_id =
99622 ipv6_iface_scope_id(&sin6->sin6_addr,
99623 IP6CB(skb)->iif);
99624- *addr_len = sizeof(*sin6);
99625 }
99626
99627 if (inet6_sk(sk)->rxopt.all)
99628- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99629+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99630 if (skb->protocol == htons(ETH_P_IPV6) &&
99631 inet6_sk(sk)->rxopt.all)
99632- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99633+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99634 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99635 ip_cmsg_recv(msg, skb);
99636 #endif
99637@@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99638 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99639 0, sock_i_ino(sp),
99640 atomic_read(&sp->sk_refcnt), sp,
99641- atomic_read(&sp->sk_drops));
99642+ atomic_read_unchecked(&sp->sk_drops));
99643 }
99644
99645 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99646diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99647index a9dbe58..46f577f 100644
99648--- a/net/ipv4/raw.c
99649+++ b/net/ipv4/raw.c
99650@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99651 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99652 {
99653 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99654- atomic_inc(&sk->sk_drops);
99655+ atomic_inc_unchecked(&sk->sk_drops);
99656 kfree_skb(skb);
99657 return NET_RX_DROP;
99658 }
99659@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99660 if (flags & MSG_OOB)
99661 goto out;
99662
99663+ if (addr_len)
99664+ *addr_len = sizeof(*sin);
99665+
99666 if (flags & MSG_ERRQUEUE) {
99667 err = ip_recv_error(sk, msg, len, addr_len);
99668 goto out;
99669@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99670 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99671 sin->sin_port = 0;
99672 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99673- *addr_len = sizeof(*sin);
99674 }
99675 if (inet->cmsg_flags)
99676 ip_cmsg_recv(msg, skb);
99677@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99678
99679 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99680 {
99681+ struct icmp_filter filter;
99682+
99683 if (optlen > sizeof(struct icmp_filter))
99684 optlen = sizeof(struct icmp_filter);
99685- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99686+ if (copy_from_user(&filter, optval, optlen))
99687 return -EFAULT;
99688+ raw_sk(sk)->filter = filter;
99689 return 0;
99690 }
99691
99692 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99693 {
99694 int len, ret = -EFAULT;
99695+ struct icmp_filter filter;
99696
99697 if (get_user(len, optlen))
99698 goto out;
99699@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99700 if (len > sizeof(struct icmp_filter))
99701 len = sizeof(struct icmp_filter);
99702 ret = -EFAULT;
99703- if (put_user(len, optlen) ||
99704- copy_to_user(optval, &raw_sk(sk)->filter, len))
99705+ filter = raw_sk(sk)->filter;
99706+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99707 goto out;
99708 ret = 0;
99709 out: return ret;
99710@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99711 0, 0L, 0,
99712 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99713 0, sock_i_ino(sp),
99714- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99715+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99716 }
99717
99718 static int raw_seq_show(struct seq_file *seq, void *v)
99719diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99720index 5e676be..f6c62f1 100644
99721--- a/net/ipv4/route.c
99722+++ b/net/ipv4/route.c
99723@@ -227,7 +227,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99724
99725 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99726 {
99727- return seq_open(file, &rt_cache_seq_ops);
99728+ return seq_open_restrict(file, &rt_cache_seq_ops);
99729 }
99730
99731 static const struct file_operations rt_cache_seq_fops = {
99732@@ -318,7 +318,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99733
99734 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99735 {
99736- return seq_open(file, &rt_cpu_seq_ops);
99737+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99738 }
99739
99740 static const struct file_operations rt_cpu_seq_fops = {
99741@@ -356,7 +356,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99742
99743 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99744 {
99745- return single_open(file, rt_acct_proc_show, NULL);
99746+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99747 }
99748
99749 static const struct file_operations rt_acct_proc_fops = {
99750@@ -2610,34 +2610,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99751 .maxlen = sizeof(int),
99752 .mode = 0200,
99753 .proc_handler = ipv4_sysctl_rtcache_flush,
99754+ .extra1 = &init_net,
99755 },
99756 { },
99757 };
99758
99759 static __net_init int sysctl_route_net_init(struct net *net)
99760 {
99761- struct ctl_table *tbl;
99762+ ctl_table_no_const *tbl = NULL;
99763
99764- tbl = ipv4_route_flush_table;
99765 if (!net_eq(net, &init_net)) {
99766- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99767+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99768 if (tbl == NULL)
99769 goto err_dup;
99770
99771 /* Don't export sysctls to unprivileged users */
99772 if (net->user_ns != &init_user_ns)
99773 tbl[0].procname = NULL;
99774- }
99775- tbl[0].extra1 = net;
99776+ tbl[0].extra1 = net;
99777+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99778+ } else
99779+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99780
99781- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99782 if (net->ipv4.route_hdr == NULL)
99783 goto err_reg;
99784 return 0;
99785
99786 err_reg:
99787- if (tbl != ipv4_route_flush_table)
99788- kfree(tbl);
99789+ kfree(tbl);
99790 err_dup:
99791 return -ENOMEM;
99792 }
99793@@ -2660,8 +2660,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99794
99795 static __net_init int rt_genid_init(struct net *net)
99796 {
99797- atomic_set(&net->ipv4.rt_genid, 0);
99798- atomic_set(&net->fnhe_genid, 0);
99799+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99800+ atomic_set_unchecked(&net->fnhe_genid, 0);
99801 get_random_bytes(&net->ipv4.dev_addr_genid,
99802 sizeof(net->ipv4.dev_addr_genid));
99803 return 0;
99804diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99805index 5cde8f2..5f5684e 100644
99806--- a/net/ipv4/sysctl_net_ipv4.c
99807+++ b/net/ipv4/sysctl_net_ipv4.c
99808@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99809 container_of(table->data, struct net, ipv4.ip_local_ports.range);
99810 int ret;
99811 int range[2];
99812- struct ctl_table tmp = {
99813+ ctl_table_no_const tmp = {
99814 .data = &range,
99815 .maxlen = sizeof(range),
99816 .mode = table->mode,
99817@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99818 int ret;
99819 gid_t urange[2];
99820 kgid_t low, high;
99821- struct ctl_table tmp = {
99822+ ctl_table_no_const tmp = {
99823 .data = &urange,
99824 .maxlen = sizeof(urange),
99825 .mode = table->mode,
99826@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99827 void __user *buffer, size_t *lenp, loff_t *ppos)
99828 {
99829 char val[TCP_CA_NAME_MAX];
99830- struct ctl_table tbl = {
99831+ ctl_table_no_const tbl = {
99832 .data = val,
99833 .maxlen = TCP_CA_NAME_MAX,
99834 };
99835@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99836 void __user *buffer, size_t *lenp,
99837 loff_t *ppos)
99838 {
99839- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99840+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99841 int ret;
99842
99843 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99844@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99845 void __user *buffer, size_t *lenp,
99846 loff_t *ppos)
99847 {
99848- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99849+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99850 int ret;
99851
99852 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99853@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99854 void __user *buffer, size_t *lenp,
99855 loff_t *ppos)
99856 {
99857- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99858+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99859 struct tcp_fastopen_context *ctxt;
99860 int ret;
99861 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99862@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99863 },
99864 {
99865 .procname = "ip_local_reserved_ports",
99866- .data = NULL, /* initialized in sysctl_ipv4_init */
99867+ .data = sysctl_local_reserved_ports,
99868 .maxlen = 65536,
99869 .mode = 0644,
99870 .proc_handler = proc_do_large_bitmap,
99871@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99872
99873 static __net_init int ipv4_sysctl_init_net(struct net *net)
99874 {
99875- struct ctl_table *table;
99876+ ctl_table_no_const *table = NULL;
99877
99878- table = ipv4_net_table;
99879 if (!net_eq(net, &init_net)) {
99880 int i;
99881
99882- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99883+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99884 if (table == NULL)
99885 goto err_alloc;
99886
99887@@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99888 table[i].data += (void *)net - (void *)&init_net;
99889 }
99890
99891- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99892+ if (!net_eq(net, &init_net))
99893+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99894+ else
99895+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99896 if (net->ipv4.ipv4_hdr == NULL)
99897 goto err_reg;
99898
99899 return 0;
99900
99901 err_reg:
99902- if (!net_eq(net, &init_net))
99903- kfree(table);
99904+ kfree(table);
99905 err_alloc:
99906 return -ENOMEM;
99907 }
99908@@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99909 static __init int sysctl_ipv4_init(void)
99910 {
99911 struct ctl_table_header *hdr;
99912- struct ctl_table *i;
99913-
99914- for (i = ipv4_table; i->procname; i++) {
99915- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99916- i->data = sysctl_local_reserved_ports;
99917- break;
99918- }
99919- }
99920- if (!i->procname)
99921- return -EINVAL;
99922
99923 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99924 if (hdr == NULL)
99925diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99926index 3a26b3b..8bbe4ae 100644
99927--- a/net/ipv4/tcp_input.c
99928+++ b/net/ipv4/tcp_input.c
99929@@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99930 * without any lock. We want to make sure compiler wont store
99931 * intermediate values in this location.
99932 */
99933- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99934+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99935 sk->sk_max_pacing_rate);
99936 }
99937
99938@@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99939 * simplifies code)
99940 */
99941 static void
99942-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99943+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99944 struct sk_buff *head, struct sk_buff *tail,
99945 u32 start, u32 end)
99946 {
99947@@ -5558,6 +5558,7 @@ discard:
99948 tcp_paws_reject(&tp->rx_opt, 0))
99949 goto discard_and_undo;
99950
99951+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99952 if (th->syn) {
99953 /* We see SYN without ACK. It is attempt of
99954 * simultaneous connect with crossed SYNs.
99955@@ -5608,6 +5609,7 @@ discard:
99956 goto discard;
99957 #endif
99958 }
99959+#endif
99960 /* "fifth, if neither of the SYN or RST bits is set then
99961 * drop the segment and return."
99962 */
99963@@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99964 goto discard;
99965
99966 if (th->syn) {
99967- if (th->fin)
99968+ if (th->fin || th->urg || th->psh)
99969 goto discard;
99970 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99971 return 1;
99972diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99973index 438f3b9..bc9e1ad 100644
99974--- a/net/ipv4/tcp_ipv4.c
99975+++ b/net/ipv4/tcp_ipv4.c
99976@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99977 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99978
99979
99980+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99981+extern int grsec_enable_blackhole;
99982+#endif
99983+
99984 #ifdef CONFIG_TCP_MD5SIG
99985 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99986 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99987@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99988 return 0;
99989
99990 reset:
99991+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99992+ if (!grsec_enable_blackhole)
99993+#endif
99994 tcp_v4_send_reset(rsk, skb);
99995 discard:
99996 kfree_skb(skb);
99997@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99998 TCP_SKB_CB(skb)->sacked = 0;
99999
100000 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100001- if (!sk)
100002+ if (!sk) {
100003+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100004+ ret = 1;
100005+#endif
100006 goto no_tcp_socket;
100007-
100008+ }
100009 process:
100010- if (sk->sk_state == TCP_TIME_WAIT)
100011+ if (sk->sk_state == TCP_TIME_WAIT) {
100012+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100013+ ret = 2;
100014+#endif
100015 goto do_time_wait;
100016+ }
100017
100018 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
100019 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100020@@ -2033,6 +2047,10 @@ csum_error:
100021 bad_packet:
100022 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100023 } else {
100024+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100025+ if (!grsec_enable_blackhole || (ret == 1 &&
100026+ (skb->dev->flags & IFF_LOOPBACK)))
100027+#endif
100028 tcp_v4_send_reset(NULL, skb);
100029 }
100030
100031diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
100032index 05c1b15..3e9344b 100644
100033--- a/net/ipv4/tcp_minisocks.c
100034+++ b/net/ipv4/tcp_minisocks.c
100035@@ -27,6 +27,10 @@
100036 #include <net/inet_common.h>
100037 #include <net/xfrm.h>
100038
100039+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100040+extern int grsec_enable_blackhole;
100041+#endif
100042+
100043 int sysctl_tcp_syncookies __read_mostly = 1;
100044 EXPORT_SYMBOL(sysctl_tcp_syncookies);
100045
100046@@ -709,7 +713,10 @@ embryonic_reset:
100047 * avoid becoming vulnerable to outside attack aiming at
100048 * resetting legit local connections.
100049 */
100050- req->rsk_ops->send_reset(sk, skb);
100051+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100052+ if (!grsec_enable_blackhole)
100053+#endif
100054+ req->rsk_ops->send_reset(sk, skb);
100055 } else if (fastopen) { /* received a valid RST pkt */
100056 reqsk_fastopen_remove(sk, req, true);
100057 tcp_reset(sk);
100058diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
100059index 3b66610..bfbe23a 100644
100060--- a/net/ipv4/tcp_probe.c
100061+++ b/net/ipv4/tcp_probe.c
100062@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
100063 if (cnt + width >= len)
100064 break;
100065
100066- if (copy_to_user(buf + cnt, tbuf, width))
100067+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
100068 return -EFAULT;
100069 cnt += width;
100070 }
100071diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
100072index 286227a..c495a76 100644
100073--- a/net/ipv4/tcp_timer.c
100074+++ b/net/ipv4/tcp_timer.c
100075@@ -22,6 +22,10 @@
100076 #include <linux/gfp.h>
100077 #include <net/tcp.h>
100078
100079+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100080+extern int grsec_lastack_retries;
100081+#endif
100082+
100083 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
100084 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
100085 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
100086@@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
100087 }
100088 }
100089
100090+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100091+ if ((sk->sk_state == TCP_LAST_ACK) &&
100092+ (grsec_lastack_retries > 0) &&
100093+ (grsec_lastack_retries < retry_until))
100094+ retry_until = grsec_lastack_retries;
100095+#endif
100096+
100097 if (retransmits_timed_out(sk, retry_until,
100098 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100099 /* Has it gone just too far? */
100100diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100101index 54a5fe9..78fea00 100644
100102--- a/net/ipv4/udp.c
100103+++ b/net/ipv4/udp.c
100104@@ -87,6 +87,7 @@
100105 #include <linux/types.h>
100106 #include <linux/fcntl.h>
100107 #include <linux/module.h>
100108+#include <linux/security.h>
100109 #include <linux/socket.h>
100110 #include <linux/sockios.h>
100111 #include <linux/igmp.h>
100112@@ -113,6 +114,10 @@
100113 #include <net/busy_poll.h>
100114 #include "udp_impl.h"
100115
100116+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100117+extern int grsec_enable_blackhole;
100118+#endif
100119+
100120 struct udp_table udp_table __read_mostly;
100121 EXPORT_SYMBOL(udp_table);
100122
100123@@ -615,6 +620,9 @@ found:
100124 return s;
100125 }
100126
100127+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100128+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100129+
100130 /*
100131 * This routine is called by the ICMP module when it gets some
100132 * sort of error condition. If err < 0 then the socket should
100133@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100134 dport = usin->sin_port;
100135 if (dport == 0)
100136 return -EINVAL;
100137+
100138+ err = gr_search_udp_sendmsg(sk, usin);
100139+ if (err)
100140+ return err;
100141 } else {
100142 if (sk->sk_state != TCP_ESTABLISHED)
100143 return -EDESTADDRREQ;
100144+
100145+ err = gr_search_udp_sendmsg(sk, NULL);
100146+ if (err)
100147+ return err;
100148+
100149 daddr = inet->inet_daddr;
100150 dport = inet->inet_dport;
100151 /* Open fast path for connected socket.
100152@@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100153 IS_UDPLITE(sk));
100154 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100155 IS_UDPLITE(sk));
100156- atomic_inc(&sk->sk_drops);
100157+ atomic_inc_unchecked(&sk->sk_drops);
100158 __skb_unlink(skb, rcvq);
100159 __skb_queue_tail(&list_kill, skb);
100160 }
100161@@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100162 int is_udplite = IS_UDPLITE(sk);
100163 bool slow;
100164
100165+ /*
100166+ * Check any passed addresses
100167+ */
100168+ if (addr_len)
100169+ *addr_len = sizeof(*sin);
100170+
100171 if (flags & MSG_ERRQUEUE)
100172 return ip_recv_error(sk, msg, len, addr_len);
100173
100174@@ -1244,6 +1267,10 @@ try_again:
100175 if (!skb)
100176 goto out;
100177
100178+ err = gr_search_udp_recvmsg(sk, skb);
100179+ if (err)
100180+ goto out_free;
100181+
100182 ulen = skb->len - sizeof(struct udphdr);
100183 copied = len;
100184 if (copied > ulen)
100185@@ -1277,7 +1304,7 @@ try_again:
100186 if (unlikely(err)) {
100187 trace_kfree_skb(skb, udp_recvmsg);
100188 if (!peeked) {
100189- atomic_inc(&sk->sk_drops);
100190+ atomic_inc_unchecked(&sk->sk_drops);
100191 UDP_INC_STATS_USER(sock_net(sk),
100192 UDP_MIB_INERRORS, is_udplite);
100193 }
100194@@ -1296,7 +1323,6 @@ try_again:
100195 sin->sin_port = udp_hdr(skb)->source;
100196 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100197 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100198- *addr_len = sizeof(*sin);
100199 }
100200 if (inet->cmsg_flags)
100201 ip_cmsg_recv(msg, skb);
100202@@ -1567,7 +1593,7 @@ csum_error:
100203 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100204 drop:
100205 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100206- atomic_inc(&sk->sk_drops);
100207+ atomic_inc_unchecked(&sk->sk_drops);
100208 kfree_skb(skb);
100209 return -1;
100210 }
100211@@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100212 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100213
100214 if (!skb1) {
100215- atomic_inc(&sk->sk_drops);
100216+ atomic_inc_unchecked(&sk->sk_drops);
100217 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100218 IS_UDPLITE(sk));
100219 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100220@@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100221 goto csum_error;
100222
100223 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100224+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100225+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100226+#endif
100227 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100228
100229 /*
100230@@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100231 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100232 0, sock_i_ino(sp),
100233 atomic_read(&sp->sk_refcnt), sp,
100234- atomic_read(&sp->sk_drops));
100235+ atomic_read_unchecked(&sp->sk_drops));
100236 }
100237
100238 int udp4_seq_show(struct seq_file *seq, void *v)
100239diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100240index 6156f68..d6ab46d 100644
100241--- a/net/ipv4/xfrm4_policy.c
100242+++ b/net/ipv4/xfrm4_policy.c
100243@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100244 fl4->flowi4_tos = iph->tos;
100245 }
100246
100247-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100248+static int xfrm4_garbage_collect(struct dst_ops *ops)
100249 {
100250 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100251
100252- xfrm4_policy_afinfo.garbage_collect(net);
100253+ xfrm_garbage_collect_deferred(net);
100254 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100255 }
100256
100257@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100258
100259 static int __net_init xfrm4_net_init(struct net *net)
100260 {
100261- struct ctl_table *table;
100262+ ctl_table_no_const *table = NULL;
100263 struct ctl_table_header *hdr;
100264
100265- table = xfrm4_policy_table;
100266 if (!net_eq(net, &init_net)) {
100267- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100268+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100269 if (!table)
100270 goto err_alloc;
100271
100272 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100273- }
100274-
100275- hdr = register_net_sysctl(net, "net/ipv4", table);
100276+ hdr = register_net_sysctl(net, "net/ipv4", table);
100277+ } else
100278+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100279 if (!hdr)
100280 goto err_reg;
100281
100282@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100283 return 0;
100284
100285 err_reg:
100286- if (!net_eq(net, &init_net))
100287- kfree(table);
100288+ kfree(table);
100289 err_alloc:
100290 return -ENOMEM;
100291 }
100292diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100293index 6c7fa08..285086c 100644
100294--- a/net/ipv6/addrconf.c
100295+++ b/net/ipv6/addrconf.c
100296@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100297 idx = 0;
100298 head = &net->dev_index_head[h];
100299 rcu_read_lock();
100300- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100301+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100302 net->dev_base_seq;
100303 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100304 if (idx < s_idx)
100305@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100306 p.iph.ihl = 5;
100307 p.iph.protocol = IPPROTO_IPV6;
100308 p.iph.ttl = 64;
100309- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100310+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100311
100312 if (ops->ndo_do_ioctl) {
100313 mm_segment_t oldfs = get_fs();
100314@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100315 s_ip_idx = ip_idx = cb->args[2];
100316
100317 rcu_read_lock();
100318- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100319+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100320 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100321 idx = 0;
100322 head = &net->dev_index_head[h];
100323@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100324 dst_free(&ifp->rt->dst);
100325 break;
100326 }
100327- atomic_inc(&net->ipv6.dev_addr_genid);
100328+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100329 rt_genid_bump_ipv6(net);
100330 }
100331
100332@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100333 int *valp = ctl->data;
100334 int val = *valp;
100335 loff_t pos = *ppos;
100336- struct ctl_table lctl;
100337+ ctl_table_no_const lctl;
100338 int ret;
100339
100340 /*
100341@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100342 int *valp = ctl->data;
100343 int val = *valp;
100344 loff_t pos = *ppos;
100345- struct ctl_table lctl;
100346+ ctl_table_no_const lctl;
100347 int ret;
100348
100349 /*
100350diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100351index d935889..2f64330 100644
100352--- a/net/ipv6/af_inet6.c
100353+++ b/net/ipv6/af_inet6.c
100354@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100355 net->ipv6.sysctl.bindv6only = 0;
100356 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100357 net->ipv6.sysctl.flowlabel_consistency = 1;
100358- atomic_set(&net->ipv6.rt_genid, 0);
100359+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100360
100361 err = ipv6_init_mibs(net);
100362 if (err)
100363diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100364index c3bf2d2..1f00573 100644
100365--- a/net/ipv6/datagram.c
100366+++ b/net/ipv6/datagram.c
100367@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100368 0,
100369 sock_i_ino(sp),
100370 atomic_read(&sp->sk_refcnt), sp,
100371- atomic_read(&sp->sk_drops));
100372+ atomic_read_unchecked(&sp->sk_drops));
100373 }
100374diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100375index 7b32652..0bc348b 100644
100376--- a/net/ipv6/icmp.c
100377+++ b/net/ipv6/icmp.c
100378@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100379
100380 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100381 {
100382- struct ctl_table *table;
100383+ ctl_table_no_const *table;
100384
100385 table = kmemdup(ipv6_icmp_table_template,
100386 sizeof(ipv6_icmp_table_template),
100387diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100388index 9d92146..d986c6a 100644
100389--- a/net/ipv6/ip6_gre.c
100390+++ b/net/ipv6/ip6_gre.c
100391@@ -71,7 +71,7 @@ struct ip6gre_net {
100392 struct net_device *fb_tunnel_dev;
100393 };
100394
100395-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100396+static struct rtnl_link_ops ip6gre_link_ops;
100397 static int ip6gre_tunnel_init(struct net_device *dev);
100398 static void ip6gre_tunnel_setup(struct net_device *dev);
100399 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100400@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100401 }
100402
100403
100404-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100405+static struct inet6_protocol ip6gre_protocol = {
100406 .handler = ip6gre_rcv,
100407 .err_handler = ip6gre_err,
100408 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100409@@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100410 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100411 };
100412
100413-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100414+static struct rtnl_link_ops ip6gre_link_ops = {
100415 .kind = "ip6gre",
100416 .maxtype = IFLA_GRE_MAX,
100417 .policy = ip6gre_policy,
100418@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100419 .fill_info = ip6gre_fill_info,
100420 };
100421
100422-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100423+static struct rtnl_link_ops ip6gre_tap_ops = {
100424 .kind = "ip6gretap",
100425 .maxtype = IFLA_GRE_MAX,
100426 .policy = ip6gre_policy,
100427diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100428index afa0824..04ba530 100644
100429--- a/net/ipv6/ip6_tunnel.c
100430+++ b/net/ipv6/ip6_tunnel.c
100431@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100432
100433 static int ip6_tnl_dev_init(struct net_device *dev);
100434 static void ip6_tnl_dev_setup(struct net_device *dev);
100435-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100436+static struct rtnl_link_ops ip6_link_ops;
100437
100438 static int ip6_tnl_net_id __read_mostly;
100439 struct ip6_tnl_net {
100440@@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100441 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100442 };
100443
100444-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100445+static struct rtnl_link_ops ip6_link_ops = {
100446 .kind = "ip6tnl",
100447 .maxtype = IFLA_IPTUN_MAX,
100448 .policy = ip6_tnl_policy,
100449diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100450index 6cc9f93..6e5bb7c 100644
100451--- a/net/ipv6/ip6_vti.c
100452+++ b/net/ipv6/ip6_vti.c
100453@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100454
100455 static int vti6_dev_init(struct net_device *dev);
100456 static void vti6_dev_setup(struct net_device *dev);
100457-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100458+static struct rtnl_link_ops vti6_link_ops;
100459
100460 static int vti6_net_id __read_mostly;
100461 struct vti6_net {
100462@@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100463 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100464 };
100465
100466-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100467+static struct rtnl_link_ops vti6_link_ops = {
100468 .kind = "vti6",
100469 .maxtype = IFLA_VTI_MAX,
100470 .policy = vti6_policy,
100471diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100472index edb58af..78de133 100644
100473--- a/net/ipv6/ipv6_sockglue.c
100474+++ b/net/ipv6/ipv6_sockglue.c
100475@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100476 if (sk->sk_type != SOCK_STREAM)
100477 return -ENOPROTOOPT;
100478
100479- msg.msg_control = optval;
100480+ msg.msg_control = (void __force_kernel *)optval;
100481 msg.msg_controllen = len;
100482 msg.msg_flags = flags;
100483
100484diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100485index e080fbb..412b3cf 100644
100486--- a/net/ipv6/netfilter/ip6_tables.c
100487+++ b/net/ipv6/netfilter/ip6_tables.c
100488@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100489 #endif
100490
100491 static int get_info(struct net *net, void __user *user,
100492- const int *len, int compat)
100493+ int len, int compat)
100494 {
100495 char name[XT_TABLE_MAXNAMELEN];
100496 struct xt_table *t;
100497 int ret;
100498
100499- if (*len != sizeof(struct ip6t_getinfo)) {
100500- duprintf("length %u != %zu\n", *len,
100501+ if (len != sizeof(struct ip6t_getinfo)) {
100502+ duprintf("length %u != %zu\n", len,
100503 sizeof(struct ip6t_getinfo));
100504 return -EINVAL;
100505 }
100506@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100507 info.size = private->size;
100508 strcpy(info.name, name);
100509
100510- if (copy_to_user(user, &info, *len) != 0)
100511+ if (copy_to_user(user, &info, len) != 0)
100512 ret = -EFAULT;
100513 else
100514 ret = 0;
100515@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100516
100517 switch (cmd) {
100518 case IP6T_SO_GET_INFO:
100519- ret = get_info(sock_net(sk), user, len, 1);
100520+ ret = get_info(sock_net(sk), user, *len, 1);
100521 break;
100522 case IP6T_SO_GET_ENTRIES:
100523 ret = compat_get_entries(sock_net(sk), user, len);
100524@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100525
100526 switch (cmd) {
100527 case IP6T_SO_GET_INFO:
100528- ret = get_info(sock_net(sk), user, len, 0);
100529+ ret = get_info(sock_net(sk), user, *len, 0);
100530 break;
100531
100532 case IP6T_SO_GET_ENTRIES:
100533diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100534index 767ab8d..c5ec70a 100644
100535--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100536+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100537@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100538
100539 static int nf_ct_frag6_sysctl_register(struct net *net)
100540 {
100541- struct ctl_table *table;
100542+ ctl_table_no_const *table = NULL;
100543 struct ctl_table_header *hdr;
100544
100545- table = nf_ct_frag6_sysctl_table;
100546 if (!net_eq(net, &init_net)) {
100547- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100548+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100549 GFP_KERNEL);
100550 if (table == NULL)
100551 goto err_alloc;
100552@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100553 table[0].data = &net->nf_frag.frags.timeout;
100554 table[1].data = &net->nf_frag.frags.low_thresh;
100555 table[2].data = &net->nf_frag.frags.high_thresh;
100556- }
100557-
100558- hdr = register_net_sysctl(net, "net/netfilter", table);
100559+ hdr = register_net_sysctl(net, "net/netfilter", table);
100560+ } else
100561+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100562 if (hdr == NULL)
100563 goto err_reg;
100564
100565@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100566 return 0;
100567
100568 err_reg:
100569- if (!net_eq(net, &init_net))
100570- kfree(table);
100571+ kfree(table);
100572 err_alloc:
100573 return -ENOMEM;
100574 }
100575diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100576index 56596ce..c734618 100644
100577--- a/net/ipv6/output_core.c
100578+++ b/net/ipv6/output_core.c
100579@@ -10,7 +10,7 @@
100580
100581 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100582 {
100583- static atomic_t ipv6_fragmentation_id;
100584+ static atomic_unchecked_t ipv6_fragmentation_id;
100585 struct in6_addr addr;
100586 int ident;
100587
100588@@ -26,7 +26,7 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100589 return;
100590 }
100591 #endif
100592- ident = atomic_inc_return(&ipv6_fragmentation_id);
100593+ ident = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100594
100595 addr = rt->rt6i_dst.addr;
100596 addr.s6_addr32[0] ^= (__force __be32)ident;
100597diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100598index bda7429..469b26b 100644
100599--- a/net/ipv6/ping.c
100600+++ b/net/ipv6/ping.c
100601@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100602 };
100603 #endif
100604
100605+static struct pingv6_ops real_pingv6_ops = {
100606+ .ipv6_recv_error = ipv6_recv_error,
100607+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100608+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100609+ .icmpv6_err_convert = icmpv6_err_convert,
100610+ .ipv6_icmp_error = ipv6_icmp_error,
100611+ .ipv6_chk_addr = ipv6_chk_addr,
100612+};
100613+
100614+static struct pingv6_ops dummy_pingv6_ops = {
100615+ .ipv6_recv_error = dummy_ipv6_recv_error,
100616+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100617+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100618+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
100619+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
100620+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
100621+};
100622+
100623 int __init pingv6_init(void)
100624 {
100625 #ifdef CONFIG_PROC_FS
100626@@ -253,13 +271,7 @@ int __init pingv6_init(void)
100627 if (ret)
100628 return ret;
100629 #endif
100630- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100631- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100632- pingv6_ops.ip6_datagram_recv_specific_ctl =
100633- ip6_datagram_recv_specific_ctl;
100634- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100635- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100636- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100637+ pingv6_ops = &real_pingv6_ops;
100638 return inet6_register_protosw(&pingv6_protosw);
100639 }
100640
100641@@ -268,14 +280,9 @@ int __init pingv6_init(void)
100642 */
100643 void pingv6_exit(void)
100644 {
100645- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100646- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100647- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100648- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100649- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100650- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100651 #ifdef CONFIG_PROC_FS
100652 unregister_pernet_subsys(&ping_v6_net_ops);
100653 #endif
100654+ pingv6_ops = &dummy_pingv6_ops;
100655 inet6_unregister_protosw(&pingv6_protosw);
100656 }
100657diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100658index 091d066..139d410 100644
100659--- a/net/ipv6/proc.c
100660+++ b/net/ipv6/proc.c
100661@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100662 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100663 goto proc_snmp6_fail;
100664
100665- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100666+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100667 if (!net->mib.proc_net_devsnmp6)
100668 goto proc_dev_snmp6_fail;
100669 return 0;
100670diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100671index 1f29996..46fe0c7 100644
100672--- a/net/ipv6/raw.c
100673+++ b/net/ipv6/raw.c
100674@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100675 {
100676 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100677 skb_checksum_complete(skb)) {
100678- atomic_inc(&sk->sk_drops);
100679+ atomic_inc_unchecked(&sk->sk_drops);
100680 kfree_skb(skb);
100681 return NET_RX_DROP;
100682 }
100683@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100684 struct raw6_sock *rp = raw6_sk(sk);
100685
100686 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100687- atomic_inc(&sk->sk_drops);
100688+ atomic_inc_unchecked(&sk->sk_drops);
100689 kfree_skb(skb);
100690 return NET_RX_DROP;
100691 }
100692@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100693
100694 if (inet->hdrincl) {
100695 if (skb_checksum_complete(skb)) {
100696- atomic_inc(&sk->sk_drops);
100697+ atomic_inc_unchecked(&sk->sk_drops);
100698 kfree_skb(skb);
100699 return NET_RX_DROP;
100700 }
100701@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100702 if (flags & MSG_OOB)
100703 return -EOPNOTSUPP;
100704
100705+ if (addr_len)
100706+ *addr_len=sizeof(*sin6);
100707+
100708 if (flags & MSG_ERRQUEUE)
100709 return ipv6_recv_error(sk, msg, len, addr_len);
100710
100711@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100712 sin6->sin6_flowinfo = 0;
100713 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100714 IP6CB(skb)->iif);
100715- *addr_len = sizeof(*sin6);
100716 }
100717
100718 sock_recv_ts_and_drops(msg, sk, skb);
100719@@ -610,7 +612,7 @@ out:
100720 return err;
100721 }
100722
100723-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100724+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100725 struct flowi6 *fl6, struct dst_entry **dstp,
100726 unsigned int flags)
100727 {
100728@@ -922,12 +924,15 @@ do_confirm:
100729 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100730 char __user *optval, int optlen)
100731 {
100732+ struct icmp6_filter filter;
100733+
100734 switch (optname) {
100735 case ICMPV6_FILTER:
100736 if (optlen > sizeof(struct icmp6_filter))
100737 optlen = sizeof(struct icmp6_filter);
100738- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100739+ if (copy_from_user(&filter, optval, optlen))
100740 return -EFAULT;
100741+ raw6_sk(sk)->filter = filter;
100742 return 0;
100743 default:
100744 return -ENOPROTOOPT;
100745@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100746 char __user *optval, int __user *optlen)
100747 {
100748 int len;
100749+ struct icmp6_filter filter;
100750
100751 switch (optname) {
100752 case ICMPV6_FILTER:
100753@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100754 len = sizeof(struct icmp6_filter);
100755 if (put_user(len, optlen))
100756 return -EFAULT;
100757- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100758+ filter = raw6_sk(sk)->filter;
100759+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
100760 return -EFAULT;
100761 return 0;
100762 default:
100763diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100764index cc85a9b..526a133 100644
100765--- a/net/ipv6/reassembly.c
100766+++ b/net/ipv6/reassembly.c
100767@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100768
100769 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100770 {
100771- struct ctl_table *table;
100772+ ctl_table_no_const *table = NULL;
100773 struct ctl_table_header *hdr;
100774
100775- table = ip6_frags_ns_ctl_table;
100776 if (!net_eq(net, &init_net)) {
100777- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100778+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100779 if (table == NULL)
100780 goto err_alloc;
100781
100782@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100783 /* Don't export sysctls to unprivileged users */
100784 if (net->user_ns != &init_user_ns)
100785 table[0].procname = NULL;
100786- }
100787+ hdr = register_net_sysctl(net, "net/ipv6", table);
100788+ } else
100789+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100790
100791- hdr = register_net_sysctl(net, "net/ipv6", table);
100792 if (hdr == NULL)
100793 goto err_reg;
100794
100795@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100796 return 0;
100797
100798 err_reg:
100799- if (!net_eq(net, &init_net))
100800- kfree(table);
100801+ kfree(table);
100802 err_alloc:
100803 return -ENOMEM;
100804 }
100805diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100806index 6ebdb7b6..f225ab1 100644
100807--- a/net/ipv6/route.c
100808+++ b/net/ipv6/route.c
100809@@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
100810
100811 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100812 {
100813- struct ctl_table *table;
100814+ ctl_table_no_const *table;
100815
100816 table = kmemdup(ipv6_route_table_template,
100817 sizeof(ipv6_route_table_template),
100818diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100819index 4f40817..54dcbef 100644
100820--- a/net/ipv6/sit.c
100821+++ b/net/ipv6/sit.c
100822@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100823 static void ipip6_dev_free(struct net_device *dev);
100824 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100825 __be32 *v4dst);
100826-static struct rtnl_link_ops sit_link_ops __read_mostly;
100827+static struct rtnl_link_ops sit_link_ops;
100828
100829 static int sit_net_id __read_mostly;
100830 struct sit_net {
100831@@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100832 unregister_netdevice_queue(dev, head);
100833 }
100834
100835-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100836+static struct rtnl_link_ops sit_link_ops = {
100837 .kind = "sit",
100838 .maxtype = IFLA_IPTUN_MAX,
100839 .policy = ipip6_policy,
100840diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100841index 7f405a1..eabef92 100644
100842--- a/net/ipv6/sysctl_net_ipv6.c
100843+++ b/net/ipv6/sysctl_net_ipv6.c
100844@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100845
100846 static int __net_init ipv6_sysctl_net_init(struct net *net)
100847 {
100848- struct ctl_table *ipv6_table;
100849+ ctl_table_no_const *ipv6_table;
100850 struct ctl_table *ipv6_route_table;
100851 struct ctl_table *ipv6_icmp_table;
100852 int err;
100853diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100854index e289830..79a5718 100644
100855--- a/net/ipv6/tcp_ipv6.c
100856+++ b/net/ipv6/tcp_ipv6.c
100857@@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100858 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100859 }
100860
100861+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100862+extern int grsec_enable_blackhole;
100863+#endif
100864+
100865 static void tcp_v6_hash(struct sock *sk)
100866 {
100867 if (sk->sk_state != TCP_CLOSE) {
100868@@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100869 return 0;
100870
100871 reset:
100872+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100873+ if (!grsec_enable_blackhole)
100874+#endif
100875 tcp_v6_send_reset(sk, skb);
100876 discard:
100877 if (opt_skb)
100878@@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100879 TCP_SKB_CB(skb)->sacked = 0;
100880
100881 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100882- if (!sk)
100883+ if (!sk) {
100884+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100885+ ret = 1;
100886+#endif
100887 goto no_tcp_socket;
100888+ }
100889
100890 process:
100891- if (sk->sk_state == TCP_TIME_WAIT)
100892+ if (sk->sk_state == TCP_TIME_WAIT) {
100893+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100894+ ret = 2;
100895+#endif
100896 goto do_time_wait;
100897+ }
100898
100899 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100900 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100901@@ -1557,6 +1572,10 @@ csum_error:
100902 bad_packet:
100903 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100904 } else {
100905+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100906+ if (!grsec_enable_blackhole || (ret == 1 &&
100907+ (skb->dev->flags & IFF_LOOPBACK)))
100908+#endif
100909 tcp_v6_send_reset(NULL, skb);
100910 }
100911
100912diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100913index 20b63d2..13be908 100644
100914--- a/net/ipv6/udp.c
100915+++ b/net/ipv6/udp.c
100916@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100917 udp_ipv6_hash_secret + net_hash_mix(net));
100918 }
100919
100920+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100921+extern int grsec_enable_blackhole;
100922+#endif
100923+
100924 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100925 {
100926 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100927@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100928 int is_udp4;
100929 bool slow;
100930
100931+ if (addr_len)
100932+ *addr_len = sizeof(struct sockaddr_in6);
100933+
100934 if (flags & MSG_ERRQUEUE)
100935 return ipv6_recv_error(sk, msg, len, addr_len);
100936
100937@@ -435,7 +442,7 @@ try_again:
100938 if (unlikely(err)) {
100939 trace_kfree_skb(skb, udpv6_recvmsg);
100940 if (!peeked) {
100941- atomic_inc(&sk->sk_drops);
100942+ atomic_inc_unchecked(&sk->sk_drops);
100943 if (is_udp4)
100944 UDP_INC_STATS_USER(sock_net(sk),
100945 UDP_MIB_INERRORS,
100946@@ -475,7 +482,7 @@ try_again:
100947 ipv6_iface_scope_id(&sin6->sin6_addr,
100948 IP6CB(skb)->iif);
100949 }
100950- *addr_len = sizeof(*sin6);
100951+
100952 }
100953
100954 if (np->rxopt.all)
100955@@ -690,7 +697,7 @@ csum_error:
100956 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100957 drop:
100958 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100959- atomic_inc(&sk->sk_drops);
100960+ atomic_inc_unchecked(&sk->sk_drops);
100961 kfree_skb(skb);
100962 return -1;
100963 }
100964@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100965 if (likely(skb1 == NULL))
100966 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100967 if (!skb1) {
100968- atomic_inc(&sk->sk_drops);
100969+ atomic_inc_unchecked(&sk->sk_drops);
100970 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100971 IS_UDPLITE(sk));
100972 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100973@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100974 goto csum_error;
100975
100976 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100977+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100978+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100979+#endif
100980 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100981
100982 kfree_skb(skb);
100983diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100984index 2a0bbda..d75ca57 100644
100985--- a/net/ipv6/xfrm6_policy.c
100986+++ b/net/ipv6/xfrm6_policy.c
100987@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100988 }
100989 }
100990
100991-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100992+static int xfrm6_garbage_collect(struct dst_ops *ops)
100993 {
100994 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100995
100996- xfrm6_policy_afinfo.garbage_collect(net);
100997+ xfrm_garbage_collect_deferred(net);
100998 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100999 }
101000
101001@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
101002
101003 static int __net_init xfrm6_net_init(struct net *net)
101004 {
101005- struct ctl_table *table;
101006+ ctl_table_no_const *table = NULL;
101007 struct ctl_table_header *hdr;
101008
101009- table = xfrm6_policy_table;
101010 if (!net_eq(net, &init_net)) {
101011- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101012+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101013 if (!table)
101014 goto err_alloc;
101015
101016 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
101017- }
101018+ hdr = register_net_sysctl(net, "net/ipv6", table);
101019+ } else
101020+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
101021
101022- hdr = register_net_sysctl(net, "net/ipv6", table);
101023 if (!hdr)
101024 goto err_reg;
101025
101026@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
101027 return 0;
101028
101029 err_reg:
101030- if (!net_eq(net, &init_net))
101031- kfree(table);
101032+ kfree(table);
101033 err_alloc:
101034 return -ENOMEM;
101035 }
101036diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
101037index e15c16a..7cf07aa 100644
101038--- a/net/ipx/ipx_proc.c
101039+++ b/net/ipx/ipx_proc.c
101040@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
101041 struct proc_dir_entry *p;
101042 int rc = -ENOMEM;
101043
101044- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
101045+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
101046
101047 if (!ipx_proc_dir)
101048 goto out;
101049diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
101050index 2ba8b97..6d33010 100644
101051--- a/net/irda/ircomm/ircomm_tty.c
101052+++ b/net/irda/ircomm/ircomm_tty.c
101053@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101054 add_wait_queue(&port->open_wait, &wait);
101055
101056 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
101057- __FILE__, __LINE__, tty->driver->name, port->count);
101058+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101059
101060 spin_lock_irqsave(&port->lock, flags);
101061 if (!tty_hung_up_p(filp))
101062- port->count--;
101063+ atomic_dec(&port->count);
101064 port->blocked_open++;
101065 spin_unlock_irqrestore(&port->lock, flags);
101066
101067@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101068 }
101069
101070 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
101071- __FILE__, __LINE__, tty->driver->name, port->count);
101072+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101073
101074 schedule();
101075 }
101076@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101077
101078 spin_lock_irqsave(&port->lock, flags);
101079 if (!tty_hung_up_p(filp))
101080- port->count++;
101081+ atomic_inc(&port->count);
101082 port->blocked_open--;
101083 spin_unlock_irqrestore(&port->lock, flags);
101084
101085 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
101086- __FILE__, __LINE__, tty->driver->name, port->count);
101087+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101088
101089 if (!retval)
101090 port->flags |= ASYNC_NORMAL_ACTIVE;
101091@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101092
101093 /* ++ is not atomic, so this should be protected - Jean II */
101094 spin_lock_irqsave(&self->port.lock, flags);
101095- self->port.count++;
101096+ atomic_inc(&self->port.count);
101097 spin_unlock_irqrestore(&self->port.lock, flags);
101098 tty_port_tty_set(&self->port, tty);
101099
101100 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101101- self->line, self->port.count);
101102+ self->line, atomic_read(&self->port.count));
101103
101104 /* Not really used by us, but lets do it anyway */
101105 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101106@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101107 tty_kref_put(port->tty);
101108 }
101109 port->tty = NULL;
101110- port->count = 0;
101111+ atomic_set(&port->count, 0);
101112 spin_unlock_irqrestore(&port->lock, flags);
101113
101114 wake_up_interruptible(&port->open_wait);
101115@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101116 seq_putc(m, '\n');
101117
101118 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101119- seq_printf(m, "Open count: %d\n", self->port.count);
101120+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101121 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101122 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101123
101124diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101125index b9ac598..f88cc56 100644
101126--- a/net/irda/irproc.c
101127+++ b/net/irda/irproc.c
101128@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101129 {
101130 int i;
101131
101132- proc_irda = proc_mkdir("irda", init_net.proc_net);
101133+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101134 if (proc_irda == NULL)
101135 return;
101136
101137diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101138index 8c9d730..66c6305 100644
101139--- a/net/iucv/af_iucv.c
101140+++ b/net/iucv/af_iucv.c
101141@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101142
101143 write_lock_bh(&iucv_sk_list.lock);
101144
101145- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101146+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101147 while (__iucv_get_sock_by_name(name)) {
101148 sprintf(name, "%08x",
101149- atomic_inc_return(&iucv_sk_list.autobind_name));
101150+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101151 }
101152
101153 write_unlock_bh(&iucv_sk_list.lock);
101154diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101155index da78793..bdd78cf 100644
101156--- a/net/iucv/iucv.c
101157+++ b/net/iucv/iucv.c
101158@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101159 return NOTIFY_OK;
101160 }
101161
101162-static struct notifier_block __refdata iucv_cpu_notifier = {
101163+static struct notifier_block iucv_cpu_notifier = {
101164 .notifier_call = iucv_cpu_notify,
101165 };
101166
101167diff --git a/net/key/af_key.c b/net/key/af_key.c
101168index f3c8307..7127791 100644
101169--- a/net/key/af_key.c
101170+++ b/net/key/af_key.c
101171@@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101172 static u32 get_acqseq(void)
101173 {
101174 u32 res;
101175- static atomic_t acqseq;
101176+ static atomic_unchecked_t acqseq;
101177
101178 do {
101179- res = atomic_inc_return(&acqseq);
101180+ res = atomic_inc_return_unchecked(&acqseq);
101181 } while (!res);
101182 return res;
101183 }
101184diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101185index 76125c5..e474828 100644
101186--- a/net/l2tp/l2tp_eth.c
101187+++ b/net/l2tp/l2tp_eth.c
101188@@ -42,12 +42,12 @@ struct l2tp_eth {
101189 struct sock *tunnel_sock;
101190 struct l2tp_session *session;
101191 struct list_head list;
101192- atomic_long_t tx_bytes;
101193- atomic_long_t tx_packets;
101194- atomic_long_t tx_dropped;
101195- atomic_long_t rx_bytes;
101196- atomic_long_t rx_packets;
101197- atomic_long_t rx_errors;
101198+ atomic_long_unchecked_t tx_bytes;
101199+ atomic_long_unchecked_t tx_packets;
101200+ atomic_long_unchecked_t tx_dropped;
101201+ atomic_long_unchecked_t rx_bytes;
101202+ atomic_long_unchecked_t rx_packets;
101203+ atomic_long_unchecked_t rx_errors;
101204 };
101205
101206 /* via l2tp_session_priv() */
101207@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101208 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101209
101210 if (likely(ret == NET_XMIT_SUCCESS)) {
101211- atomic_long_add(len, &priv->tx_bytes);
101212- atomic_long_inc(&priv->tx_packets);
101213+ atomic_long_add_unchecked(len, &priv->tx_bytes);
101214+ atomic_long_inc_unchecked(&priv->tx_packets);
101215 } else {
101216- atomic_long_inc(&priv->tx_dropped);
101217+ atomic_long_inc_unchecked(&priv->tx_dropped);
101218 }
101219 return NETDEV_TX_OK;
101220 }
101221@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101222 {
101223 struct l2tp_eth *priv = netdev_priv(dev);
101224
101225- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101226- stats->tx_packets = atomic_long_read(&priv->tx_packets);
101227- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101228- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101229- stats->rx_packets = atomic_long_read(&priv->rx_packets);
101230- stats->rx_errors = atomic_long_read(&priv->rx_errors);
101231+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101232+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101233+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101234+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101235+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101236+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101237 return stats;
101238 }
101239
101240@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101241 nf_reset(skb);
101242
101243 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101244- atomic_long_inc(&priv->rx_packets);
101245- atomic_long_add(data_len, &priv->rx_bytes);
101246+ atomic_long_inc_unchecked(&priv->rx_packets);
101247+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101248 } else {
101249- atomic_long_inc(&priv->rx_errors);
101250+ atomic_long_inc_unchecked(&priv->rx_errors);
101251 }
101252 return;
101253
101254 error:
101255- atomic_long_inc(&priv->rx_errors);
101256+ atomic_long_inc_unchecked(&priv->rx_errors);
101257 kfree_skb(skb);
101258 }
101259
101260diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101261index 3397fe6..861fd1a 100644
101262--- a/net/l2tp/l2tp_ip.c
101263+++ b/net/l2tp/l2tp_ip.c
101264@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101265 if (flags & MSG_OOB)
101266 goto out;
101267
101268+ if (addr_len)
101269+ *addr_len = sizeof(*sin);
101270+
101271 skb = skb_recv_datagram(sk, flags, noblock, &err);
101272 if (!skb)
101273 goto out;
101274@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101275 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101276 sin->sin_port = 0;
101277 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101278- *addr_len = sizeof(*sin);
101279 }
101280 if (inet->cmsg_flags)
101281 ip_cmsg_recv(msg, skb);
101282diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101283index 1a3c7e0..80f8b0c 100644
101284--- a/net/llc/llc_proc.c
101285+++ b/net/llc/llc_proc.c
101286@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101287 int rc = -ENOMEM;
101288 struct proc_dir_entry *p;
101289
101290- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101291+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101292 if (!llc_proc_dir)
101293 goto out;
101294
101295diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101296index aaa59d7..21a2c4a 100644
101297--- a/net/mac80211/cfg.c
101298+++ b/net/mac80211/cfg.c
101299@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101300 ret = ieee80211_vif_use_channel(sdata, chandef,
101301 IEEE80211_CHANCTX_EXCLUSIVE);
101302 }
101303- } else if (local->open_count == local->monitors) {
101304+ } else if (local_read(&local->open_count) == local->monitors) {
101305 local->_oper_chandef = *chandef;
101306 ieee80211_hw_config(local, 0);
101307 }
101308@@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101309 else
101310 local->probe_req_reg--;
101311
101312- if (!local->open_count)
101313+ if (!local_read(&local->open_count))
101314 break;
101315
101316 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101317@@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101318 if (chanctx_conf) {
101319 *chandef = chanctx_conf->def;
101320 ret = 0;
101321- } else if (local->open_count > 0 &&
101322- local->open_count == local->monitors &&
101323+ } else if (local_read(&local->open_count) > 0 &&
101324+ local_read(&local->open_count) == local->monitors &&
101325 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101326 if (local->use_chanctx)
101327 *chandef = local->monitor_chandef;
101328diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101329index f169b6e..a5dc4eb 100644
101330--- a/net/mac80211/ieee80211_i.h
101331+++ b/net/mac80211/ieee80211_i.h
101332@@ -28,6 +28,7 @@
101333 #include <net/ieee80211_radiotap.h>
101334 #include <net/cfg80211.h>
101335 #include <net/mac80211.h>
101336+#include <asm/local.h>
101337 #include "key.h"
101338 #include "sta_info.h"
101339 #include "debug.h"
101340@@ -999,7 +1000,7 @@ struct ieee80211_local {
101341 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101342 spinlock_t queue_stop_reason_lock;
101343
101344- int open_count;
101345+ local_t open_count;
101346 int monitors, cooked_mntrs;
101347 /* number of interfaces with corresponding FIF_ flags */
101348 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101349diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101350index 34799e0..b411290 100644
101351--- a/net/mac80211/iface.c
101352+++ b/net/mac80211/iface.c
101353@@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101354 break;
101355 }
101356
101357- if (local->open_count == 0) {
101358+ if (local_read(&local->open_count) == 0) {
101359 res = drv_start(local);
101360 if (res)
101361 goto err_del_bss;
101362@@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101363 res = drv_add_interface(local, sdata);
101364 if (res)
101365 goto err_stop;
101366- } else if (local->monitors == 0 && local->open_count == 0) {
101367+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101368 res = ieee80211_add_virtual_monitor(local);
101369 if (res)
101370 goto err_stop;
101371@@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101372 atomic_inc(&local->iff_promiscs);
101373
101374 if (coming_up)
101375- local->open_count++;
101376+ local_inc(&local->open_count);
101377
101378 if (hw_reconf_flags)
101379 ieee80211_hw_config(local, hw_reconf_flags);
101380@@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101381 err_del_interface:
101382 drv_remove_interface(local, sdata);
101383 err_stop:
101384- if (!local->open_count)
101385+ if (!local_read(&local->open_count))
101386 drv_stop(local);
101387 err_del_bss:
101388 sdata->bss = NULL;
101389@@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101390 }
101391
101392 if (going_down)
101393- local->open_count--;
101394+ local_dec(&local->open_count);
101395
101396 switch (sdata->vif.type) {
101397 case NL80211_IFTYPE_AP_VLAN:
101398@@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101399 }
101400 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101401
101402- if (local->open_count == 0)
101403+ if (local_read(&local->open_count) == 0)
101404 ieee80211_clear_tx_pending(local);
101405
101406 /*
101407@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101408
101409 ieee80211_recalc_ps(local, -1);
101410
101411- if (local->open_count == 0) {
101412+ if (local_read(&local->open_count) == 0) {
101413 ieee80211_stop_device(local);
101414
101415 /* no reconfiguring after stop! */
101416@@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101417 ieee80211_configure_filter(local);
101418 ieee80211_hw_config(local, hw_reconf_flags);
101419
101420- if (local->monitors == local->open_count)
101421+ if (local->monitors == local_read(&local->open_count))
101422 ieee80211_add_virtual_monitor(local);
101423 }
101424
101425diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101426index 4c1bf61..00b449b 100644
101427--- a/net/mac80211/main.c
101428+++ b/net/mac80211/main.c
101429@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101430 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101431 IEEE80211_CONF_CHANGE_POWER);
101432
101433- if (changed && local->open_count) {
101434+ if (changed && local_read(&local->open_count)) {
101435 ret = drv_config(local, changed);
101436 /*
101437 * Goal:
101438diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101439index d478b88..8c8d157 100644
101440--- a/net/mac80211/pm.c
101441+++ b/net/mac80211/pm.c
101442@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101443 struct ieee80211_sub_if_data *sdata;
101444 struct sta_info *sta;
101445
101446- if (!local->open_count)
101447+ if (!local_read(&local->open_count))
101448 goto suspend;
101449
101450 ieee80211_scan_cancel(local);
101451@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101452 cancel_work_sync(&local->dynamic_ps_enable_work);
101453 del_timer_sync(&local->dynamic_ps_timer);
101454
101455- local->wowlan = wowlan && local->open_count;
101456+ local->wowlan = wowlan && local_read(&local->open_count);
101457 if (local->wowlan) {
101458 int err = drv_suspend(local, wowlan);
101459 if (err < 0) {
101460@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101461 WARN_ON(!list_empty(&local->chanctx_list));
101462
101463 /* stop hardware - this must stop RX */
101464- if (local->open_count)
101465+ if (local_read(&local->open_count))
101466 ieee80211_stop_device(local);
101467
101468 suspend:
101469diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101470index 8fdadfd..a4f72b8 100644
101471--- a/net/mac80211/rate.c
101472+++ b/net/mac80211/rate.c
101473@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101474
101475 ASSERT_RTNL();
101476
101477- if (local->open_count)
101478+ if (local_read(&local->open_count))
101479 return -EBUSY;
101480
101481 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101482diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101483index 6ff1346..936ca9a 100644
101484--- a/net/mac80211/rc80211_pid_debugfs.c
101485+++ b/net/mac80211/rc80211_pid_debugfs.c
101486@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101487
101488 spin_unlock_irqrestore(&events->lock, status);
101489
101490- if (copy_to_user(buf, pb, p))
101491+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101492 return -EFAULT;
101493
101494 return p;
101495diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101496index 3c36583..12887fe 100644
101497--- a/net/mac80211/util.c
101498+++ b/net/mac80211/util.c
101499@@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101500 }
101501 #endif
101502 /* everything else happens only if HW was up & running */
101503- if (!local->open_count)
101504+ if (!local_read(&local->open_count))
101505 goto wake_up;
101506
101507 /*
101508@@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101509 local->in_reconfig = false;
101510 barrier();
101511
101512- if (local->monitors == local->open_count && local->monitors > 0)
101513+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101514 ieee80211_add_virtual_monitor(local);
101515
101516 /*
101517diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101518index e9410d1..77b6378 100644
101519--- a/net/netfilter/Kconfig
101520+++ b/net/netfilter/Kconfig
101521@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101522
101523 To compile it as a module, choose M here. If unsure, say N.
101524
101525+config NETFILTER_XT_MATCH_GRADM
101526+ tristate '"gradm" match support'
101527+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101528+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101529+ ---help---
101530+ The gradm match allows to match on grsecurity RBAC being enabled.
101531+ It is useful when iptables rules are applied early on bootup to
101532+ prevent connections to the machine (except from a trusted host)
101533+ while the RBAC system is disabled.
101534+
101535 config NETFILTER_XT_MATCH_HASHLIMIT
101536 tristate '"hashlimit" match support'
101537 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101538diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101539index bffdad7..f9317d1 100644
101540--- a/net/netfilter/Makefile
101541+++ b/net/netfilter/Makefile
101542@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101543 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101544 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101545 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101546+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101547 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101548 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101549 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101550diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101551index 1172083..986f1c1 100644
101552--- a/net/netfilter/ipset/ip_set_core.c
101553+++ b/net/netfilter/ipset/ip_set_core.c
101554@@ -1924,7 +1924,7 @@ done:
101555 return ret;
101556 }
101557
101558-static struct nf_sockopt_ops so_set __read_mostly = {
101559+static struct nf_sockopt_ops so_set = {
101560 .pf = PF_INET,
101561 .get_optmin = SO_IP_SET,
101562 .get_optmax = SO_IP_SET + 1,
101563diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101564index a8eb0a8..86f2de4 100644
101565--- a/net/netfilter/ipvs/ip_vs_conn.c
101566+++ b/net/netfilter/ipvs/ip_vs_conn.c
101567@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101568 /* Increase the refcnt counter of the dest */
101569 ip_vs_dest_hold(dest);
101570
101571- conn_flags = atomic_read(&dest->conn_flags);
101572+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
101573 if (cp->protocol != IPPROTO_UDP)
101574 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101575 flags = cp->flags;
101576@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101577
101578 cp->control = NULL;
101579 atomic_set(&cp->n_control, 0);
101580- atomic_set(&cp->in_pkts, 0);
101581+ atomic_set_unchecked(&cp->in_pkts, 0);
101582
101583 cp->packet_xmit = NULL;
101584 cp->app = NULL;
101585@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101586
101587 /* Don't drop the entry if its number of incoming packets is not
101588 located in [0, 8] */
101589- i = atomic_read(&cp->in_pkts);
101590+ i = atomic_read_unchecked(&cp->in_pkts);
101591 if (i > 8 || i < 0) return 0;
101592
101593 if (!todrop_rate[i]) return 0;
101594diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101595index 3d2d2c8..c87e4d3 100644
101596--- a/net/netfilter/ipvs/ip_vs_core.c
101597+++ b/net/netfilter/ipvs/ip_vs_core.c
101598@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101599 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101600 /* do not touch skb anymore */
101601
101602- atomic_inc(&cp->in_pkts);
101603+ atomic_inc_unchecked(&cp->in_pkts);
101604 ip_vs_conn_put(cp);
101605 return ret;
101606 }
101607@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101608 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101609 pkts = sysctl_sync_threshold(ipvs);
101610 else
101611- pkts = atomic_add_return(1, &cp->in_pkts);
101612+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101613
101614 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101615 ip_vs_sync_conn(net, cp, pkts);
101616diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101617index c42e83d..a6a3f8b 100644
101618--- a/net/netfilter/ipvs/ip_vs_ctl.c
101619+++ b/net/netfilter/ipvs/ip_vs_ctl.c
101620@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101621 */
101622 ip_vs_rs_hash(ipvs, dest);
101623 }
101624- atomic_set(&dest->conn_flags, conn_flags);
101625+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
101626
101627 /* bind the service */
101628 old_svc = rcu_dereference_protected(dest->svc, 1);
101629@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101630 * align with netns init in ip_vs_control_net_init()
101631 */
101632
101633-static struct ctl_table vs_vars[] = {
101634+static ctl_table_no_const vs_vars[] __read_only = {
101635 {
101636 .procname = "amemthresh",
101637 .maxlen = sizeof(int),
101638@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101639 " %-7s %-6d %-10d %-10d\n",
101640 &dest->addr.in6,
101641 ntohs(dest->port),
101642- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101643+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101644 atomic_read(&dest->weight),
101645 atomic_read(&dest->activeconns),
101646 atomic_read(&dest->inactconns));
101647@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101648 "%-7s %-6d %-10d %-10d\n",
101649 ntohl(dest->addr.ip),
101650 ntohs(dest->port),
101651- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101652+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101653 atomic_read(&dest->weight),
101654 atomic_read(&dest->activeconns),
101655 atomic_read(&dest->inactconns));
101656@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101657
101658 entry.addr = dest->addr.ip;
101659 entry.port = dest->port;
101660- entry.conn_flags = atomic_read(&dest->conn_flags);
101661+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101662 entry.weight = atomic_read(&dest->weight);
101663 entry.u_threshold = dest->u_threshold;
101664 entry.l_threshold = dest->l_threshold;
101665@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101666 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101667 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101668 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101669- (atomic_read(&dest->conn_flags) &
101670+ (atomic_read_unchecked(&dest->conn_flags) &
101671 IP_VS_CONN_F_FWD_MASK)) ||
101672 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101673 atomic_read(&dest->weight)) ||
101674@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101675 {
101676 int idx;
101677 struct netns_ipvs *ipvs = net_ipvs(net);
101678- struct ctl_table *tbl;
101679+ ctl_table_no_const *tbl;
101680
101681 atomic_set(&ipvs->dropentry, 0);
101682 spin_lock_init(&ipvs->dropentry_lock);
101683diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101684index 547ff33..c8c8117 100644
101685--- a/net/netfilter/ipvs/ip_vs_lblc.c
101686+++ b/net/netfilter/ipvs/ip_vs_lblc.c
101687@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101688 * IPVS LBLC sysctl table
101689 */
101690 #ifdef CONFIG_SYSCTL
101691-static struct ctl_table vs_vars_table[] = {
101692+static ctl_table_no_const vs_vars_table[] __read_only = {
101693 {
101694 .procname = "lblc_expiration",
101695 .data = NULL,
101696diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101697index 3f21a2f..a112e85 100644
101698--- a/net/netfilter/ipvs/ip_vs_lblcr.c
101699+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101700@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101701 * IPVS LBLCR sysctl table
101702 */
101703
101704-static struct ctl_table vs_vars_table[] = {
101705+static ctl_table_no_const vs_vars_table[] __read_only = {
101706 {
101707 .procname = "lblcr_expiration",
101708 .data = NULL,
101709diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101710index db80126..ef7110e 100644
101711--- a/net/netfilter/ipvs/ip_vs_sync.c
101712+++ b/net/netfilter/ipvs/ip_vs_sync.c
101713@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101714 cp = cp->control;
101715 if (cp) {
101716 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101717- pkts = atomic_add_return(1, &cp->in_pkts);
101718+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101719 else
101720 pkts = sysctl_sync_threshold(ipvs);
101721 ip_vs_sync_conn(net, cp->control, pkts);
101722@@ -771,7 +771,7 @@ control:
101723 if (!cp)
101724 return;
101725 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101726- pkts = atomic_add_return(1, &cp->in_pkts);
101727+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101728 else
101729 pkts = sysctl_sync_threshold(ipvs);
101730 goto sloop;
101731@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101732
101733 if (opt)
101734 memcpy(&cp->in_seq, opt, sizeof(*opt));
101735- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101736+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101737 cp->state = state;
101738 cp->old_state = cp->state;
101739 /*
101740diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101741index c47444e..b0961c6 100644
101742--- a/net/netfilter/ipvs/ip_vs_xmit.c
101743+++ b/net/netfilter/ipvs/ip_vs_xmit.c
101744@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101745 else
101746 rc = NF_ACCEPT;
101747 /* do not touch skb anymore */
101748- atomic_inc(&cp->in_pkts);
101749+ atomic_inc_unchecked(&cp->in_pkts);
101750 goto out;
101751 }
101752
101753@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101754 else
101755 rc = NF_ACCEPT;
101756 /* do not touch skb anymore */
101757- atomic_inc(&cp->in_pkts);
101758+ atomic_inc_unchecked(&cp->in_pkts);
101759 goto out;
101760 }
101761
101762diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101763index a4b5e2a..13b1de3 100644
101764--- a/net/netfilter/nf_conntrack_acct.c
101765+++ b/net/netfilter/nf_conntrack_acct.c
101766@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101767 #ifdef CONFIG_SYSCTL
101768 static int nf_conntrack_acct_init_sysctl(struct net *net)
101769 {
101770- struct ctl_table *table;
101771+ ctl_table_no_const *table;
101772
101773 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101774 GFP_KERNEL);
101775diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101776index 75421f2..054c1fc 100644
101777--- a/net/netfilter/nf_conntrack_core.c
101778+++ b/net/netfilter/nf_conntrack_core.c
101779@@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
101780 #define DYING_NULLS_VAL ((1<<30)+1)
101781 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101782
101783+#ifdef CONFIG_GRKERNSEC_HIDESYM
101784+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101785+#endif
101786+
101787 int nf_conntrack_init_net(struct net *net)
101788 {
101789 int ret = -ENOMEM;
101790@@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
101791 if (!net->ct.stat)
101792 goto err_pcpu_lists;
101793
101794+#ifdef CONFIG_GRKERNSEC_HIDESYM
101795+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101796+#else
101797 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101798+#endif
101799 if (!net->ct.slabname)
101800 goto err_slabname;
101801
101802diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101803index 1df1761..ce8b88a 100644
101804--- a/net/netfilter/nf_conntrack_ecache.c
101805+++ b/net/netfilter/nf_conntrack_ecache.c
101806@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101807 #ifdef CONFIG_SYSCTL
101808 static int nf_conntrack_event_init_sysctl(struct net *net)
101809 {
101810- struct ctl_table *table;
101811+ ctl_table_no_const *table;
101812
101813 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101814 GFP_KERNEL);
101815diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101816index 5b3eae7..dd4b8fe 100644
101817--- a/net/netfilter/nf_conntrack_helper.c
101818+++ b/net/netfilter/nf_conntrack_helper.c
101819@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101820
101821 static int nf_conntrack_helper_init_sysctl(struct net *net)
101822 {
101823- struct ctl_table *table;
101824+ ctl_table_no_const *table;
101825
101826 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101827 GFP_KERNEL);
101828diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101829index b65d586..beec902 100644
101830--- a/net/netfilter/nf_conntrack_proto.c
101831+++ b/net/netfilter/nf_conntrack_proto.c
101832@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101833
101834 static void
101835 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101836- struct ctl_table **table,
101837+ ctl_table_no_const **table,
101838 unsigned int users)
101839 {
101840 if (users > 0)
101841diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101842index f641751..d3c5b51 100644
101843--- a/net/netfilter/nf_conntrack_standalone.c
101844+++ b/net/netfilter/nf_conntrack_standalone.c
101845@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101846
101847 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101848 {
101849- struct ctl_table *table;
101850+ ctl_table_no_const *table;
101851
101852 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101853 GFP_KERNEL);
101854diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101855index 7a394df..bd91a8a 100644
101856--- a/net/netfilter/nf_conntrack_timestamp.c
101857+++ b/net/netfilter/nf_conntrack_timestamp.c
101858@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101859 #ifdef CONFIG_SYSCTL
101860 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101861 {
101862- struct ctl_table *table;
101863+ ctl_table_no_const *table;
101864
101865 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101866 GFP_KERNEL);
101867diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101868index 85296d4..8becdec 100644
101869--- a/net/netfilter/nf_log.c
101870+++ b/net/netfilter/nf_log.c
101871@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101872
101873 #ifdef CONFIG_SYSCTL
101874 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101875-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101876+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101877
101878 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101879 void __user *buffer, size_t *lenp, loff_t *ppos)
101880@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101881 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101882 mutex_unlock(&nf_log_mutex);
101883 } else {
101884+ ctl_table_no_const nf_log_table = *table;
101885+
101886 mutex_lock(&nf_log_mutex);
101887 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101888 lockdep_is_held(&nf_log_mutex));
101889 if (!logger)
101890- table->data = "NONE";
101891+ nf_log_table.data = "NONE";
101892 else
101893- table->data = logger->name;
101894- r = proc_dostring(table, write, buffer, lenp, ppos);
101895+ nf_log_table.data = logger->name;
101896+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101897 mutex_unlock(&nf_log_mutex);
101898 }
101899
101900diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101901index f042ae5..30ea486 100644
101902--- a/net/netfilter/nf_sockopt.c
101903+++ b/net/netfilter/nf_sockopt.c
101904@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101905 }
101906 }
101907
101908- list_add(&reg->list, &nf_sockopts);
101909+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101910 out:
101911 mutex_unlock(&nf_sockopt_mutex);
101912 return ret;
101913@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101914 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101915 {
101916 mutex_lock(&nf_sockopt_mutex);
101917- list_del(&reg->list);
101918+ pax_list_del((struct list_head *)&reg->list);
101919 mutex_unlock(&nf_sockopt_mutex);
101920 }
101921 EXPORT_SYMBOL(nf_unregister_sockopt);
101922diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101923index d292c8d..9f1e166 100644
101924--- a/net/netfilter/nfnetlink_log.c
101925+++ b/net/netfilter/nfnetlink_log.c
101926@@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
101927 struct nfnl_log_net {
101928 spinlock_t instances_lock;
101929 struct hlist_head instance_table[INSTANCE_BUCKETS];
101930- atomic_t global_seq;
101931+ atomic_unchecked_t global_seq;
101932 };
101933
101934 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101935@@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
101936 /* global sequence number */
101937 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101938 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101939- htonl(atomic_inc_return(&log->global_seq))))
101940+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101941 goto nla_put_failure;
101942
101943 if (data_len) {
101944diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101945index 8a779be..1551d4c 100644
101946--- a/net/netfilter/nft_compat.c
101947+++ b/net/netfilter/nft_compat.c
101948@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101949 /* We want to reuse existing compat_to_user */
101950 old_fs = get_fs();
101951 set_fs(KERNEL_DS);
101952- t->compat_to_user(out, in);
101953+ t->compat_to_user((void __force_user *)out, in);
101954 set_fs(old_fs);
101955 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101956 kfree(out);
101957@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101958 /* We want to reuse existing compat_to_user */
101959 old_fs = get_fs();
101960 set_fs(KERNEL_DS);
101961- m->compat_to_user(out, in);
101962+ m->compat_to_user((void __force_user *)out, in);
101963 set_fs(old_fs);
101964 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101965 kfree(out);
101966diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101967new file mode 100644
101968index 0000000..c566332
101969--- /dev/null
101970+++ b/net/netfilter/xt_gradm.c
101971@@ -0,0 +1,51 @@
101972+/*
101973+ * gradm match for netfilter
101974