]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.15.10-201408192020.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.15.10-201408192020.patch
CommitLineData
a82e731d
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 76b75f7b84..34cd7f7 100644
291--- a/Makefile
292+++ b/Makefile
293@@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298-HOSTCXXFLAGS = -O2
299+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301+HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
302
303 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
304 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
305@@ -438,8 +439,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
306 # Rules shared between *config targets and build targets
307
308 # Basic helpers built in scripts/
309-PHONY += scripts_basic
310-scripts_basic:
311+PHONY += scripts_basic gcc-plugins
312+scripts_basic: gcc-plugins
313 $(Q)$(MAKE) $(build)=scripts/basic
314 $(Q)rm -f .tmp_quiet_recordmcount
315
316@@ -600,6 +601,75 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320+# Tell gcc to never replace conditional load with a non-conditional one
321+KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
322+
323+ifndef DISABLE_PAX_PLUGINS
324+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
325+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
326+else
327+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
328+endif
329+ifneq ($(PLUGINCC),)
330+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
331+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
332+endif
333+ifdef CONFIG_PAX_MEMORY_STACKLEAK
334+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
335+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
336+endif
337+ifdef CONFIG_KALLOCSTAT_PLUGIN
338+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
339+endif
340+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
341+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
342+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
343+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
344+endif
345+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
346+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
347+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
348+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
349+endif
350+endif
351+ifdef CONFIG_CHECKER_PLUGIN
352+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
353+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
354+endif
355+endif
356+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
357+ifdef CONFIG_PAX_SIZE_OVERFLOW
358+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
359+endif
360+ifdef CONFIG_PAX_LATENT_ENTROPY
361+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
362+endif
363+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
364+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
365+endif
366+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
367+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
368+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
369+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
370+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
371+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
372+ifeq ($(KBUILD_EXTMOD),)
373+gcc-plugins:
374+ $(Q)$(MAKE) $(build)=tools/gcc
375+else
376+gcc-plugins: ;
377+endif
378+else
379+gcc-plugins:
380+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
381+ $(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.))
382+else
383+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
384+endif
385+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
386+endif
387+endif
388+
389 include $(srctree)/arch/$(SRCARCH)/Makefile
390
391 ifdef CONFIG_READABLE_ASM
392@@ -818,7 +888,7 @@ export mod_sign_cmd
393
394
395 ifeq ($(KBUILD_EXTMOD),)
396-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
397+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
398
399 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
400 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
401@@ -867,6 +937,8 @@ endif
402
403 # The actual objects are generated when descending,
404 # make sure no implicit rule kicks in
405+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
406+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
407 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408
409 # Handle descending into subdirectories listed in $(vmlinux-dirs)
410@@ -876,7 +948,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
411 # Error messages still appears in the original language
412
413 PHONY += $(vmlinux-dirs)
414-$(vmlinux-dirs): prepare scripts
415+$(vmlinux-dirs): gcc-plugins prepare scripts
416 $(Q)$(MAKE) $(build)=$@
417
418 define filechk_kernel.release
419@@ -919,10 +991,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
420
421 archprepare: archheaders archscripts prepare1 scripts_basic
422
423+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
424+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
425 prepare0: archprepare FORCE
426 $(Q)$(MAKE) $(build)=.
427
428 # All the preparing..
429+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
430 prepare: prepare0
431
432 # Generate some files
433@@ -1030,6 +1105,8 @@ all: modules
434 # using awk while concatenating to the final file.
435
436 PHONY += modules
437+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
438+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
439 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
440 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
441 @$(kecho) ' Building modules, stage 2.';
442@@ -1045,7 +1122,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
443
444 # Target to prepare building external modules
445 PHONY += modules_prepare
446-modules_prepare: prepare scripts
447+modules_prepare: gcc-plugins prepare scripts
448
449 # Target to install modules
450 PHONY += modules_install
451@@ -1111,7 +1188,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
452 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
453 signing_key.priv signing_key.x509 x509.genkey \
454 extra_certificates signing_key.x509.keyid \
455- signing_key.x509.signer include/linux/version.h
456+ signing_key.x509.signer include/linux/version.h \
457+ tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
458+ tools/gcc/size_overflow_plugin/size_overflow_hash.h \
459+ tools/gcc/randomize_layout_seed.h
460
461 # clean - Delete most, but leave enough to build external modules
462 #
463@@ -1150,7 +1230,7 @@ distclean: mrproper
464 @find $(srctree) $(RCS_FIND_IGNORE) \
465 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
466 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
467- -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
468+ -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
469 -type f -print | xargs rm -f
470
471
472@@ -1311,6 +1391,8 @@ PHONY += $(module-dirs) modules
473 $(module-dirs): crmodverdir $(objtree)/Module.symvers
474 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
475
476+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
477+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
478 modules: $(module-dirs)
479 @$(kecho) ' Building modules, stage 2.';
480 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
481@@ -1450,17 +1532,21 @@ else
482 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
483 endif
484
485-%.s: %.c prepare scripts FORCE
486+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
487+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
488+%.s: %.c gcc-plugins prepare scripts FORCE
489 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
490 %.i: %.c prepare scripts FORCE
491 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
492-%.o: %.c prepare scripts FORCE
493+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495+%.o: %.c gcc-plugins prepare scripts FORCE
496 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
497 %.lst: %.c prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499-%.s: %.S prepare scripts FORCE
500+%.s: %.S gcc-plugins prepare scripts FORCE
501 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
502-%.o: %.S prepare scripts FORCE
503+%.o: %.S gcc-plugins prepare scripts FORCE
504 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
505 %.symtypes: %.c prepare scripts FORCE
506 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
507@@ -1470,11 +1556,15 @@ endif
508 $(cmd_crmodverdir)
509 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
510 $(build)=$(build-dir)
511-%/: prepare scripts FORCE
512+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514+%/: gcc-plugins prepare scripts FORCE
515 $(cmd_crmodverdir)
516 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
517 $(build)=$(build-dir)
518-%.ko: prepare scripts FORCE
519+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
520+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
521+%.ko: gcc-plugins prepare scripts FORCE
522 $(cmd_crmodverdir)
523 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
524 $(build)=$(build-dir) $(@:.ko=.o)
525diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
526index 78b03ef..da28a51 100644
527--- a/arch/alpha/include/asm/atomic.h
528+++ b/arch/alpha/include/asm/atomic.h
529@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
530 #define atomic_dec(v) atomic_sub(1,(v))
531 #define atomic64_dec(v) atomic64_sub(1,(v))
532
533+#define atomic64_read_unchecked(v) atomic64_read(v)
534+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
535+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
536+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
537+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
538+#define atomic64_inc_unchecked(v) atomic64_inc(v)
539+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
540+#define atomic64_dec_unchecked(v) atomic64_dec(v)
541+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
542+
543 #define smp_mb__before_atomic_dec() smp_mb()
544 #define smp_mb__after_atomic_dec() smp_mb()
545 #define smp_mb__before_atomic_inc() smp_mb()
546diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
547index ad368a9..fbe0f25 100644
548--- a/arch/alpha/include/asm/cache.h
549+++ b/arch/alpha/include/asm/cache.h
550@@ -4,19 +4,19 @@
551 #ifndef __ARCH_ALPHA_CACHE_H
552 #define __ARCH_ALPHA_CACHE_H
553
554+#include <linux/const.h>
555
556 /* Bytes per L1 (data) cache line. */
557 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
558-# define L1_CACHE_BYTES 64
559 # define L1_CACHE_SHIFT 6
560 #else
561 /* Both EV4 and EV5 are write-through, read-allocate,
562 direct-mapped, physical.
563 */
564-# define L1_CACHE_BYTES 32
565 # define L1_CACHE_SHIFT 5
566 #endif
567
568+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
569 #define SMP_CACHE_BYTES L1_CACHE_BYTES
570
571 #endif
572diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
573index 968d999..d36b2df 100644
574--- a/arch/alpha/include/asm/elf.h
575+++ b/arch/alpha/include/asm/elf.h
576@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
577
578 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
579
580+#ifdef CONFIG_PAX_ASLR
581+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
582+
583+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
584+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
585+#endif
586+
587 /* $0 is set by ld.so to a pointer to a function which might be
588 registered using atexit. This provides a mean for the dynamic
589 linker to call DT_FINI functions for shared libraries that have
590diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
591index aab14a0..b4fa3e7 100644
592--- a/arch/alpha/include/asm/pgalloc.h
593+++ b/arch/alpha/include/asm/pgalloc.h
594@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
595 pgd_set(pgd, pmd);
596 }
597
598+static inline void
599+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
600+{
601+ pgd_populate(mm, pgd, pmd);
602+}
603+
604 extern pgd_t *pgd_alloc(struct mm_struct *mm);
605
606 static inline void
607diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
608index d8f9b7e..f6222fa 100644
609--- a/arch/alpha/include/asm/pgtable.h
610+++ b/arch/alpha/include/asm/pgtable.h
611@@ -102,6 +102,17 @@ struct vm_area_struct;
612 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
613 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
614 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
615+
616+#ifdef CONFIG_PAX_PAGEEXEC
617+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
618+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
619+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
620+#else
621+# define PAGE_SHARED_NOEXEC PAGE_SHARED
622+# define PAGE_COPY_NOEXEC PAGE_COPY
623+# define PAGE_READONLY_NOEXEC PAGE_READONLY
624+#endif
625+
626 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
627
628 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
629diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
630index 2fd00b7..cfd5069 100644
631--- a/arch/alpha/kernel/module.c
632+++ b/arch/alpha/kernel/module.c
633@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
634
635 /* The small sections were sorted to the end of the segment.
636 The following should definitely cover them. */
637- gp = (u64)me->module_core + me->core_size - 0x8000;
638+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
639 got = sechdrs[me->arch.gotsecindex].sh_addr;
640
641 for (i = 0; i < n; i++) {
642diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
643index 1402fcc..0b1abd2 100644
644--- a/arch/alpha/kernel/osf_sys.c
645+++ b/arch/alpha/kernel/osf_sys.c
646@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
647 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
648
649 static unsigned long
650-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
651- unsigned long limit)
652+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
653+ unsigned long limit, unsigned long flags)
654 {
655 struct vm_unmapped_area_info info;
656+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
657
658 info.flags = 0;
659 info.length = len;
660@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
661 info.high_limit = limit;
662 info.align_mask = 0;
663 info.align_offset = 0;
664+ info.threadstack_offset = offset;
665 return vm_unmapped_area(&info);
666 }
667
668@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
669 merely specific addresses, but regions of memory -- perhaps
670 this feature should be incorporated into all ports? */
671
672+#ifdef CONFIG_PAX_RANDMMAP
673+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
674+#endif
675+
676 if (addr) {
677- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
678+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
679 if (addr != (unsigned long) -ENOMEM)
680 return addr;
681 }
682
683 /* Next, try allocating at TASK_UNMAPPED_BASE. */
684- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
685- len, limit);
686+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
687+
688 if (addr != (unsigned long) -ENOMEM)
689 return addr;
690
691 /* Finally, try allocating in low memory. */
692- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
693+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
694
695 return addr;
696 }
697diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
698index 98838a0..b304fb4 100644
699--- a/arch/alpha/mm/fault.c
700+++ b/arch/alpha/mm/fault.c
701@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
702 __reload_thread(pcb);
703 }
704
705+#ifdef CONFIG_PAX_PAGEEXEC
706+/*
707+ * PaX: decide what to do with offenders (regs->pc = fault address)
708+ *
709+ * returns 1 when task should be killed
710+ * 2 when patched PLT trampoline was detected
711+ * 3 when unpatched PLT trampoline was detected
712+ */
713+static int pax_handle_fetch_fault(struct pt_regs *regs)
714+{
715+
716+#ifdef CONFIG_PAX_EMUPLT
717+ int err;
718+
719+ do { /* PaX: patched PLT emulation #1 */
720+ unsigned int ldah, ldq, jmp;
721+
722+ err = get_user(ldah, (unsigned int *)regs->pc);
723+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
724+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
725+
726+ if (err)
727+ break;
728+
729+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
730+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
731+ jmp == 0x6BFB0000U)
732+ {
733+ unsigned long r27, addr;
734+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
735+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
736+
737+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
738+ err = get_user(r27, (unsigned long *)addr);
739+ if (err)
740+ break;
741+
742+ regs->r27 = r27;
743+ regs->pc = r27;
744+ return 2;
745+ }
746+ } while (0);
747+
748+ do { /* PaX: patched PLT emulation #2 */
749+ unsigned int ldah, lda, br;
750+
751+ err = get_user(ldah, (unsigned int *)regs->pc);
752+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
753+ err |= get_user(br, (unsigned int *)(regs->pc+8));
754+
755+ if (err)
756+ break;
757+
758+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
759+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
760+ (br & 0xFFE00000U) == 0xC3E00000U)
761+ {
762+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
763+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
764+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
765+
766+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
767+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
768+ return 2;
769+ }
770+ } while (0);
771+
772+ do { /* PaX: unpatched PLT emulation */
773+ unsigned int br;
774+
775+ err = get_user(br, (unsigned int *)regs->pc);
776+
777+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
778+ unsigned int br2, ldq, nop, jmp;
779+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
780+
781+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
782+ err = get_user(br2, (unsigned int *)addr);
783+ err |= get_user(ldq, (unsigned int *)(addr+4));
784+ err |= get_user(nop, (unsigned int *)(addr+8));
785+ err |= get_user(jmp, (unsigned int *)(addr+12));
786+ err |= get_user(resolver, (unsigned long *)(addr+16));
787+
788+ if (err)
789+ break;
790+
791+ if (br2 == 0xC3600000U &&
792+ ldq == 0xA77B000CU &&
793+ nop == 0x47FF041FU &&
794+ jmp == 0x6B7B0000U)
795+ {
796+ regs->r28 = regs->pc+4;
797+ regs->r27 = addr+16;
798+ regs->pc = resolver;
799+ return 3;
800+ }
801+ }
802+ } while (0);
803+#endif
804+
805+ return 1;
806+}
807+
808+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
809+{
810+ unsigned long i;
811+
812+ printk(KERN_ERR "PAX: bytes at PC: ");
813+ for (i = 0; i < 5; i++) {
814+ unsigned int c;
815+ if (get_user(c, (unsigned int *)pc+i))
816+ printk(KERN_CONT "???????? ");
817+ else
818+ printk(KERN_CONT "%08x ", c);
819+ }
820+ printk("\n");
821+}
822+#endif
823
824 /*
825 * This routine handles page faults. It determines the address,
826@@ -133,8 +251,29 @@ retry:
827 good_area:
828 si_code = SEGV_ACCERR;
829 if (cause < 0) {
830- if (!(vma->vm_flags & VM_EXEC))
831+ if (!(vma->vm_flags & VM_EXEC)) {
832+
833+#ifdef CONFIG_PAX_PAGEEXEC
834+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
835+ goto bad_area;
836+
837+ up_read(&mm->mmap_sem);
838+ switch (pax_handle_fetch_fault(regs)) {
839+
840+#ifdef CONFIG_PAX_EMUPLT
841+ case 2:
842+ case 3:
843+ return;
844+#endif
845+
846+ }
847+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
848+ do_group_exit(SIGKILL);
849+#else
850 goto bad_area;
851+#endif
852+
853+ }
854 } else if (!cause) {
855 /* Allow reads even for write-only mappings */
856 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
857diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
858index 34c7a24..592fca9 100644
859--- a/arch/arm/Kconfig
860+++ b/arch/arm/Kconfig
861@@ -1878,7 +1878,7 @@ config ALIGNMENT_TRAP
862
863 config UACCESS_WITH_MEMCPY
864 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
865- depends on MMU
866+ depends on MMU && !PAX_MEMORY_UDEREF
867 default y if CPU_FEROCEON
868 help
869 Implement faster copy_to_user and clear_user methods for CPU
870@@ -2142,6 +2142,7 @@ config XIP_PHYS_ADDR
871 config KEXEC
872 bool "Kexec system call (EXPERIMENTAL)"
873 depends on (!SMP || PM_SLEEP_SMP)
874+ depends on !GRKERNSEC_KMEM
875 help
876 kexec is a system call that implements the ability to shutdown your
877 current kernel, and to start another kernel. It is like a reboot
878diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
879index 9a92fd7..3502a80 100644
880--- a/arch/arm/include/asm/atomic.h
881+++ b/arch/arm/include/asm/atomic.h
882@@ -18,17 +18,35 @@
883 #include <asm/barrier.h>
884 #include <asm/cmpxchg.h>
885
886+#ifdef CONFIG_GENERIC_ATOMIC64
887+#include <asm-generic/atomic64.h>
888+#endif
889+
890 #define ATOMIC_INIT(i) { (i) }
891
892 #ifdef __KERNEL__
893
894+#define _ASM_EXTABLE(from, to) \
895+" .pushsection __ex_table,\"a\"\n"\
896+" .align 3\n" \
897+" .long " #from ", " #to"\n" \
898+" .popsection"
899+
900 /*
901 * On ARM, ordinary assignment (str instruction) doesn't clear the local
902 * strex/ldrex monitor on some implementations. The reason we can use it for
903 * atomic_set() is the clrex or dummy strex done on every exception return.
904 */
905 #define atomic_read(v) (*(volatile int *)&(v)->counter)
906+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
907+{
908+ return v->counter;
909+}
910 #define atomic_set(v,i) (((v)->counter) = (i))
911+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
912+{
913+ v->counter = i;
914+}
915
916 #if __LINUX_ARM_ARCH__ >= 6
917
918@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
919
920 prefetchw(&v->counter);
921 __asm__ __volatile__("@ atomic_add\n"
922+"1: ldrex %1, [%3]\n"
923+" adds %0, %1, %4\n"
924+
925+#ifdef CONFIG_PAX_REFCOUNT
926+" bvc 3f\n"
927+"2: bkpt 0xf103\n"
928+"3:\n"
929+#endif
930+
931+" strex %1, %0, [%3]\n"
932+" teq %1, #0\n"
933+" bne 1b"
934+
935+#ifdef CONFIG_PAX_REFCOUNT
936+"\n4:\n"
937+ _ASM_EXTABLE(2b, 4b)
938+#endif
939+
940+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
941+ : "r" (&v->counter), "Ir" (i)
942+ : "cc");
943+}
944+
945+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
946+{
947+ unsigned long tmp;
948+ int result;
949+
950+ prefetchw(&v->counter);
951+ __asm__ __volatile__("@ atomic_add_unchecked\n"
952 "1: ldrex %0, [%3]\n"
953 " add %0, %0, %4\n"
954 " strex %1, %0, [%3]\n"
955@@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
956 prefetchw(&v->counter);
957
958 __asm__ __volatile__("@ atomic_add_return\n"
959+"1: ldrex %1, [%3]\n"
960+" adds %0, %1, %4\n"
961+
962+#ifdef CONFIG_PAX_REFCOUNT
963+" bvc 3f\n"
964+" mov %0, %1\n"
965+"2: bkpt 0xf103\n"
966+"3:\n"
967+#endif
968+
969+" strex %1, %0, [%3]\n"
970+" teq %1, #0\n"
971+" bne 1b"
972+
973+#ifdef CONFIG_PAX_REFCOUNT
974+"\n4:\n"
975+ _ASM_EXTABLE(2b, 4b)
976+#endif
977+
978+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
979+ : "r" (&v->counter), "Ir" (i)
980+ : "cc");
981+
982+ smp_mb();
983+
984+ return result;
985+}
986+
987+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
988+{
989+ unsigned long tmp;
990+ int result;
991+
992+ smp_mb();
993+ prefetchw(&v->counter);
994+
995+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
996 "1: ldrex %0, [%3]\n"
997 " add %0, %0, %4\n"
998 " strex %1, %0, [%3]\n"
999@@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1000
1001 prefetchw(&v->counter);
1002 __asm__ __volatile__("@ atomic_sub\n"
1003+"1: ldrex %1, [%3]\n"
1004+" subs %0, %1, %4\n"
1005+
1006+#ifdef CONFIG_PAX_REFCOUNT
1007+" bvc 3f\n"
1008+"2: bkpt 0xf103\n"
1009+"3:\n"
1010+#endif
1011+
1012+" strex %1, %0, [%3]\n"
1013+" teq %1, #0\n"
1014+" bne 1b"
1015+
1016+#ifdef CONFIG_PAX_REFCOUNT
1017+"\n4:\n"
1018+ _ASM_EXTABLE(2b, 4b)
1019+#endif
1020+
1021+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1022+ : "r" (&v->counter), "Ir" (i)
1023+ : "cc");
1024+}
1025+
1026+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1027+{
1028+ unsigned long tmp;
1029+ int result;
1030+
1031+ prefetchw(&v->counter);
1032+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1033 "1: ldrex %0, [%3]\n"
1034 " sub %0, %0, %4\n"
1035 " strex %1, %0, [%3]\n"
1036@@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1037 prefetchw(&v->counter);
1038
1039 __asm__ __volatile__("@ atomic_sub_return\n"
1040-"1: ldrex %0, [%3]\n"
1041-" sub %0, %0, %4\n"
1042+"1: ldrex %1, [%3]\n"
1043+" subs %0, %1, %4\n"
1044+
1045+#ifdef CONFIG_PAX_REFCOUNT
1046+" bvc 3f\n"
1047+" mov %0, %1\n"
1048+"2: bkpt 0xf103\n"
1049+"3:\n"
1050+#endif
1051+
1052 " strex %1, %0, [%3]\n"
1053 " teq %1, #0\n"
1054 " bne 1b"
1055+
1056+#ifdef CONFIG_PAX_REFCOUNT
1057+"\n4:\n"
1058+ _ASM_EXTABLE(2b, 4b)
1059+#endif
1060+
1061 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1062 : "r" (&v->counter), "Ir" (i)
1063 : "cc");
1064@@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1065 __asm__ __volatile__ ("@ atomic_add_unless\n"
1066 "1: ldrex %0, [%4]\n"
1067 " teq %0, %5\n"
1068-" beq 2f\n"
1069-" add %1, %0, %6\n"
1070+" beq 4f\n"
1071+" adds %1, %0, %6\n"
1072+
1073+#ifdef CONFIG_PAX_REFCOUNT
1074+" bvc 3f\n"
1075+"2: bkpt 0xf103\n"
1076+"3:\n"
1077+#endif
1078+
1079 " strex %2, %1, [%4]\n"
1080 " teq %2, #0\n"
1081 " bne 1b\n"
1082-"2:"
1083+"4:"
1084+
1085+#ifdef CONFIG_PAX_REFCOUNT
1086+ _ASM_EXTABLE(2b, 4b)
1087+#endif
1088+
1089 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1090 : "r" (&v->counter), "r" (u), "r" (a)
1091 : "cc");
1092@@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1093 return oldval;
1094 }
1095
1096+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1097+{
1098+ unsigned long oldval, res;
1099+
1100+ smp_mb();
1101+
1102+ do {
1103+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1104+ "ldrex %1, [%3]\n"
1105+ "mov %0, #0\n"
1106+ "teq %1, %4\n"
1107+ "strexeq %0, %5, [%3]\n"
1108+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1109+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1110+ : "cc");
1111+ } while (res);
1112+
1113+ smp_mb();
1114+
1115+ return oldval;
1116+}
1117+
1118 #else /* ARM_ARCH_6 */
1119
1120 #ifdef CONFIG_SMP
1121@@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1122
1123 return val;
1124 }
1125+
1126+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1127+{
1128+ return atomic_add_return(i, v);
1129+}
1130+
1131 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1132+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1133+{
1134+ (void) atomic_add_return(i, v);
1135+}
1136
1137 static inline int atomic_sub_return(int i, atomic_t *v)
1138 {
1139@@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1140 return val;
1141 }
1142 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1143+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1144+{
1145+ (void) atomic_sub_return(i, v);
1146+}
1147
1148 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1149 {
1150@@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1151 return ret;
1152 }
1153
1154+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1155+{
1156+ return atomic_cmpxchg(v, old, new);
1157+}
1158+
1159 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1160 {
1161 int c, old;
1162@@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1163 #endif /* __LINUX_ARM_ARCH__ */
1164
1165 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1166+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1167+{
1168+ return xchg(&v->counter, new);
1169+}
1170
1171 #define atomic_inc(v) atomic_add(1, v)
1172+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1173+{
1174+ atomic_add_unchecked(1, v);
1175+}
1176 #define atomic_dec(v) atomic_sub(1, v)
1177+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1178+{
1179+ atomic_sub_unchecked(1, v);
1180+}
1181
1182 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1183+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1184+{
1185+ return atomic_add_return_unchecked(1, v) == 0;
1186+}
1187 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1188 #define atomic_inc_return(v) (atomic_add_return(1, v))
1189+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1190+{
1191+ return atomic_add_return_unchecked(1, v);
1192+}
1193 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1194 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1195
1196@@ -251,6 +453,14 @@ typedef struct {
1197 long long counter;
1198 } atomic64_t;
1199
1200+#ifdef CONFIG_PAX_REFCOUNT
1201+typedef struct {
1202+ long long counter;
1203+} atomic64_unchecked_t;
1204+#else
1205+typedef atomic64_t atomic64_unchecked_t;
1206+#endif
1207+
1208 #define ATOMIC64_INIT(i) { (i) }
1209
1210 #ifdef CONFIG_ARM_LPAE
1211@@ -267,6 +477,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1212 return result;
1213 }
1214
1215+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1216+{
1217+ long long result;
1218+
1219+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1220+" ldrd %0, %H0, [%1]"
1221+ : "=&r" (result)
1222+ : "r" (&v->counter), "Qo" (v->counter)
1223+ );
1224+
1225+ return result;
1226+}
1227+
1228 static inline void atomic64_set(atomic64_t *v, long long i)
1229 {
1230 __asm__ __volatile__("@ atomic64_set\n"
1231@@ -275,6 +498,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1232 : "r" (&v->counter), "r" (i)
1233 );
1234 }
1235+
1236+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1237+{
1238+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1239+" strd %2, %H2, [%1]"
1240+ : "=Qo" (v->counter)
1241+ : "r" (&v->counter), "r" (i)
1242+ );
1243+}
1244 #else
1245 static inline long long atomic64_read(const atomic64_t *v)
1246 {
1247@@ -289,6 +521,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1248 return result;
1249 }
1250
1251+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1252+{
1253+ long long result;
1254+
1255+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1256+" ldrexd %0, %H0, [%1]"
1257+ : "=&r" (result)
1258+ : "r" (&v->counter), "Qo" (v->counter)
1259+ );
1260+
1261+ return result;
1262+}
1263+
1264 static inline void atomic64_set(atomic64_t *v, long long i)
1265 {
1266 long long tmp;
1267@@ -303,6 +548,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1268 : "r" (&v->counter), "r" (i)
1269 : "cc");
1270 }
1271+
1272+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1273+{
1274+ long long tmp;
1275+
1276+ prefetchw(&v->counter);
1277+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1278+"1: ldrexd %0, %H0, [%2]\n"
1279+" strexd %0, %3, %H3, [%2]\n"
1280+" teq %0, #0\n"
1281+" bne 1b"
1282+ : "=&r" (tmp), "=Qo" (v->counter)
1283+ : "r" (&v->counter), "r" (i)
1284+ : "cc");
1285+}
1286 #endif
1287
1288 static inline void atomic64_add(long long i, atomic64_t *v)
1289@@ -314,6 +574,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1290 __asm__ __volatile__("@ atomic64_add\n"
1291 "1: ldrexd %0, %H0, [%3]\n"
1292 " adds %Q0, %Q0, %Q4\n"
1293+" adcs %R0, %R0, %R4\n"
1294+
1295+#ifdef CONFIG_PAX_REFCOUNT
1296+" bvc 3f\n"
1297+"2: bkpt 0xf103\n"
1298+"3:\n"
1299+#endif
1300+
1301+" strexd %1, %0, %H0, [%3]\n"
1302+" teq %1, #0\n"
1303+" bne 1b"
1304+
1305+#ifdef CONFIG_PAX_REFCOUNT
1306+"\n4:\n"
1307+ _ASM_EXTABLE(2b, 4b)
1308+#endif
1309+
1310+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1311+ : "r" (&v->counter), "r" (i)
1312+ : "cc");
1313+}
1314+
1315+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1316+{
1317+ long long result;
1318+ unsigned long tmp;
1319+
1320+ prefetchw(&v->counter);
1321+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1322+"1: ldrexd %0, %H0, [%3]\n"
1323+" adds %Q0, %Q0, %Q4\n"
1324 " adc %R0, %R0, %R4\n"
1325 " strexd %1, %0, %H0, [%3]\n"
1326 " teq %1, #0\n"
1327@@ -334,6 +625,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1328 __asm__ __volatile__("@ atomic64_add_return\n"
1329 "1: ldrexd %0, %H0, [%3]\n"
1330 " adds %Q0, %Q0, %Q4\n"
1331+" adcs %R0, %R0, %R4\n"
1332+
1333+#ifdef CONFIG_PAX_REFCOUNT
1334+" bvc 3f\n"
1335+" mov %0, %1\n"
1336+" mov %H0, %H1\n"
1337+"2: bkpt 0xf103\n"
1338+"3:\n"
1339+#endif
1340+
1341+" strexd %1, %0, %H0, [%3]\n"
1342+" teq %1, #0\n"
1343+" bne 1b"
1344+
1345+#ifdef CONFIG_PAX_REFCOUNT
1346+"\n4:\n"
1347+ _ASM_EXTABLE(2b, 4b)
1348+#endif
1349+
1350+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1351+ : "r" (&v->counter), "r" (i)
1352+ : "cc");
1353+
1354+ smp_mb();
1355+
1356+ return result;
1357+}
1358+
1359+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1360+{
1361+ long long result;
1362+ unsigned long tmp;
1363+
1364+ smp_mb();
1365+
1366+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1367+"1: ldrexd %0, %H0, [%3]\n"
1368+" adds %Q0, %Q0, %Q4\n"
1369 " adc %R0, %R0, %R4\n"
1370 " strexd %1, %0, %H0, [%3]\n"
1371 " teq %1, #0\n"
1372@@ -356,6 +685,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1373 __asm__ __volatile__("@ atomic64_sub\n"
1374 "1: ldrexd %0, %H0, [%3]\n"
1375 " subs %Q0, %Q0, %Q4\n"
1376+" sbcs %R0, %R0, %R4\n"
1377+
1378+#ifdef CONFIG_PAX_REFCOUNT
1379+" bvc 3f\n"
1380+"2: bkpt 0xf103\n"
1381+"3:\n"
1382+#endif
1383+
1384+" strexd %1, %0, %H0, [%3]\n"
1385+" teq %1, #0\n"
1386+" bne 1b"
1387+
1388+#ifdef CONFIG_PAX_REFCOUNT
1389+"\n4:\n"
1390+ _ASM_EXTABLE(2b, 4b)
1391+#endif
1392+
1393+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1394+ : "r" (&v->counter), "r" (i)
1395+ : "cc");
1396+}
1397+
1398+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1399+{
1400+ long long result;
1401+ unsigned long tmp;
1402+
1403+ prefetchw(&v->counter);
1404+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1405+"1: ldrexd %0, %H0, [%3]\n"
1406+" subs %Q0, %Q0, %Q4\n"
1407 " sbc %R0, %R0, %R4\n"
1408 " strexd %1, %0, %H0, [%3]\n"
1409 " teq %1, #0\n"
1410@@ -376,16 +736,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1411 __asm__ __volatile__("@ atomic64_sub_return\n"
1412 "1: ldrexd %0, %H0, [%3]\n"
1413 " subs %Q0, %Q0, %Q4\n"
1414-" sbc %R0, %R0, %R4\n"
1415+" sbcs %R0, %R0, %R4\n"
1416+
1417+#ifdef CONFIG_PAX_REFCOUNT
1418+" bvc 3f\n"
1419+" mov %0, %1\n"
1420+" mov %H0, %H1\n"
1421+"2: bkpt 0xf103\n"
1422+"3:\n"
1423+#endif
1424+
1425 " strexd %1, %0, %H0, [%3]\n"
1426 " teq %1, #0\n"
1427 " bne 1b"
1428+
1429+#ifdef CONFIG_PAX_REFCOUNT
1430+"\n4:\n"
1431+ _ASM_EXTABLE(2b, 4b)
1432+#endif
1433+
1434 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1435 : "r" (&v->counter), "r" (i)
1436 : "cc");
1437
1438- smp_mb();
1439-
1440 return result;
1441 }
1442
1443@@ -415,6 +788,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1444 return oldval;
1445 }
1446
1447+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1448+ long long new)
1449+{
1450+ long long oldval;
1451+ unsigned long res;
1452+
1453+ smp_mb();
1454+
1455+ do {
1456+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1457+ "ldrexd %1, %H1, [%3]\n"
1458+ "mov %0, #0\n"
1459+ "teq %1, %4\n"
1460+ "teqeq %H1, %H4\n"
1461+ "strexdeq %0, %5, %H5, [%3]"
1462+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1463+ : "r" (&ptr->counter), "r" (old), "r" (new)
1464+ : "cc");
1465+ } while (res);
1466+
1467+ smp_mb();
1468+
1469+ return oldval;
1470+}
1471+
1472 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1473 {
1474 long long result;
1475@@ -440,21 +838,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1476 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1477 {
1478 long long result;
1479- unsigned long tmp;
1480+ u64 tmp;
1481
1482 smp_mb();
1483 prefetchw(&v->counter);
1484
1485 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1486-"1: ldrexd %0, %H0, [%3]\n"
1487-" subs %Q0, %Q0, #1\n"
1488-" sbc %R0, %R0, #0\n"
1489+"1: ldrexd %1, %H1, [%3]\n"
1490+" subs %Q0, %Q1, #1\n"
1491+" sbcs %R0, %R1, #0\n"
1492+
1493+#ifdef CONFIG_PAX_REFCOUNT
1494+" bvc 3f\n"
1495+" mov %Q0, %Q1\n"
1496+" mov %R0, %R1\n"
1497+"2: bkpt 0xf103\n"
1498+"3:\n"
1499+#endif
1500+
1501 " teq %R0, #0\n"
1502-" bmi 2f\n"
1503+" bmi 4f\n"
1504 " strexd %1, %0, %H0, [%3]\n"
1505 " teq %1, #0\n"
1506 " bne 1b\n"
1507-"2:"
1508+"4:\n"
1509+
1510+#ifdef CONFIG_PAX_REFCOUNT
1511+ _ASM_EXTABLE(2b, 4b)
1512+#endif
1513+
1514 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1515 : "r" (&v->counter)
1516 : "cc");
1517@@ -478,13 +890,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1518 " teq %0, %5\n"
1519 " teqeq %H0, %H5\n"
1520 " moveq %1, #0\n"
1521-" beq 2f\n"
1522+" beq 4f\n"
1523 " adds %Q0, %Q0, %Q6\n"
1524-" adc %R0, %R0, %R6\n"
1525+" adcs %R0, %R0, %R6\n"
1526+
1527+#ifdef CONFIG_PAX_REFCOUNT
1528+" bvc 3f\n"
1529+"2: bkpt 0xf103\n"
1530+"3:\n"
1531+#endif
1532+
1533 " strexd %2, %0, %H0, [%4]\n"
1534 " teq %2, #0\n"
1535 " bne 1b\n"
1536-"2:"
1537+"4:\n"
1538+
1539+#ifdef CONFIG_PAX_REFCOUNT
1540+ _ASM_EXTABLE(2b, 4b)
1541+#endif
1542+
1543 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1544 : "r" (&v->counter), "r" (u), "r" (a)
1545 : "cc");
1546@@ -497,10 +921,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1547
1548 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1549 #define atomic64_inc(v) atomic64_add(1LL, (v))
1550+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1551 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1552+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1553 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1554 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1555 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1556+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1557 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1558 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1559 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1560diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1561index 2f59f74..1594659 100644
1562--- a/arch/arm/include/asm/barrier.h
1563+++ b/arch/arm/include/asm/barrier.h
1564@@ -63,7 +63,7 @@
1565 do { \
1566 compiletime_assert_atomic_type(*p); \
1567 smp_mb(); \
1568- ACCESS_ONCE(*p) = (v); \
1569+ ACCESS_ONCE_RW(*p) = (v); \
1570 } while (0)
1571
1572 #define smp_load_acquire(p) \
1573diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1574index 75fe66b..ba3dee4 100644
1575--- a/arch/arm/include/asm/cache.h
1576+++ b/arch/arm/include/asm/cache.h
1577@@ -4,8 +4,10 @@
1578 #ifndef __ASMARM_CACHE_H
1579 #define __ASMARM_CACHE_H
1580
1581+#include <linux/const.h>
1582+
1583 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1584-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1585+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1586
1587 /*
1588 * Memory returned by kmalloc() may be used for DMA, so we must make
1589@@ -24,5 +26,6 @@
1590 #endif
1591
1592 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1593+#define __read_only __attribute__ ((__section__(".data..read_only")))
1594
1595 #endif
1596diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1597index 8b8b616..d973d24 100644
1598--- a/arch/arm/include/asm/cacheflush.h
1599+++ b/arch/arm/include/asm/cacheflush.h
1600@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1601 void (*dma_unmap_area)(const void *, size_t, int);
1602
1603 void (*dma_flush_range)(const void *, const void *);
1604-};
1605+} __no_const;
1606
1607 /*
1608 * Select the calling method
1609diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1610index 5233151..87a71fa 100644
1611--- a/arch/arm/include/asm/checksum.h
1612+++ b/arch/arm/include/asm/checksum.h
1613@@ -37,7 +37,19 @@ __wsum
1614 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1615
1616 __wsum
1617-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1618+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1619+
1620+static inline __wsum
1621+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1622+{
1623+ __wsum ret;
1624+ pax_open_userland();
1625+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1626+ pax_close_userland();
1627+ return ret;
1628+}
1629+
1630+
1631
1632 /*
1633 * Fold a partial checksum without adding pseudo headers
1634diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1635index abb2c37..96db950 100644
1636--- a/arch/arm/include/asm/cmpxchg.h
1637+++ b/arch/arm/include/asm/cmpxchg.h
1638@@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1639
1640 #define xchg(ptr,x) \
1641 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1642+#define xchg_unchecked(ptr,x) \
1643+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1644
1645 #include <asm-generic/cmpxchg-local.h>
1646
1647diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1648index 6ddbe44..b5e38b1 100644
1649--- a/arch/arm/include/asm/domain.h
1650+++ b/arch/arm/include/asm/domain.h
1651@@ -48,18 +48,37 @@
1652 * Domain types
1653 */
1654 #define DOMAIN_NOACCESS 0
1655-#define DOMAIN_CLIENT 1
1656 #ifdef CONFIG_CPU_USE_DOMAINS
1657+#define DOMAIN_USERCLIENT 1
1658+#define DOMAIN_KERNELCLIENT 1
1659 #define DOMAIN_MANAGER 3
1660+#define DOMAIN_VECTORS DOMAIN_USER
1661 #else
1662+
1663+#ifdef CONFIG_PAX_KERNEXEC
1664 #define DOMAIN_MANAGER 1
1665+#define DOMAIN_KERNEXEC 3
1666+#else
1667+#define DOMAIN_MANAGER 1
1668+#endif
1669+
1670+#ifdef CONFIG_PAX_MEMORY_UDEREF
1671+#define DOMAIN_USERCLIENT 0
1672+#define DOMAIN_UDEREF 1
1673+#define DOMAIN_VECTORS DOMAIN_KERNEL
1674+#else
1675+#define DOMAIN_USERCLIENT 1
1676+#define DOMAIN_VECTORS DOMAIN_USER
1677+#endif
1678+#define DOMAIN_KERNELCLIENT 1
1679+
1680 #endif
1681
1682 #define domain_val(dom,type) ((type) << (2*(dom)))
1683
1684 #ifndef __ASSEMBLY__
1685
1686-#ifdef CONFIG_CPU_USE_DOMAINS
1687+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1688 static inline void set_domain(unsigned val)
1689 {
1690 asm volatile(
1691@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1692 isb();
1693 }
1694
1695-#define modify_domain(dom,type) \
1696- do { \
1697- struct thread_info *thread = current_thread_info(); \
1698- unsigned int domain = thread->cpu_domain; \
1699- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1700- thread->cpu_domain = domain | domain_val(dom, type); \
1701- set_domain(thread->cpu_domain); \
1702- } while (0)
1703-
1704+extern void modify_domain(unsigned int dom, unsigned int type);
1705 #else
1706 static inline void set_domain(unsigned val) { }
1707 static inline void modify_domain(unsigned dom, unsigned type) { }
1708diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1709index f4b46d3..abc9b2b 100644
1710--- a/arch/arm/include/asm/elf.h
1711+++ b/arch/arm/include/asm/elf.h
1712@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1713 the loader. We need to make sure that it is out of the way of the program
1714 that it will "exec", and that there is sufficient room for the brk. */
1715
1716-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1717+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1718+
1719+#ifdef CONFIG_PAX_ASLR
1720+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1721+
1722+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1723+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1724+#endif
1725
1726 /* When the program starts, a1 contains a pointer to a function to be
1727 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1728@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1729 extern void elf_set_personality(const struct elf32_hdr *);
1730 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1731
1732-struct mm_struct;
1733-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1734-#define arch_randomize_brk arch_randomize_brk
1735-
1736 #ifdef CONFIG_MMU
1737 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1738 struct linux_binprm;
1739diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1740index de53547..52b9a28 100644
1741--- a/arch/arm/include/asm/fncpy.h
1742+++ b/arch/arm/include/asm/fncpy.h
1743@@ -81,7 +81,9 @@
1744 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1745 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1746 \
1747+ pax_open_kernel(); \
1748 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1749+ pax_close_kernel(); \
1750 flush_icache_range((unsigned long)(dest_buf), \
1751 (unsigned long)(dest_buf) + (size)); \
1752 \
1753diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1754index 53e69da..3fdc896 100644
1755--- a/arch/arm/include/asm/futex.h
1756+++ b/arch/arm/include/asm/futex.h
1757@@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1758 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1759 return -EFAULT;
1760
1761+ pax_open_userland();
1762+
1763 smp_mb();
1764 /* Prefetching cannot fault */
1765 prefetchw(uaddr);
1766@@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1767 : "cc", "memory");
1768 smp_mb();
1769
1770+ pax_close_userland();
1771+
1772 *uval = val;
1773 return ret;
1774 }
1775@@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1776 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1777 return -EFAULT;
1778
1779+ pax_open_userland();
1780+
1781 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1782 "1: " TUSER(ldr) " %1, [%4]\n"
1783 " teq %1, %2\n"
1784@@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1785 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1786 : "cc", "memory");
1787
1788+ pax_close_userland();
1789+
1790 *uval = val;
1791 return ret;
1792 }
1793@@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1794 return -EFAULT;
1795
1796 pagefault_disable(); /* implies preempt_disable() */
1797+ pax_open_userland();
1798
1799 switch (op) {
1800 case FUTEX_OP_SET:
1801@@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1802 ret = -ENOSYS;
1803 }
1804
1805+ pax_close_userland();
1806 pagefault_enable(); /* subsumes preempt_enable() */
1807
1808 if (!ret) {
1809diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1810index 83eb2f7..ed77159 100644
1811--- a/arch/arm/include/asm/kmap_types.h
1812+++ b/arch/arm/include/asm/kmap_types.h
1813@@ -4,6 +4,6 @@
1814 /*
1815 * This is the "bare minimum". AIO seems to require this.
1816 */
1817-#define KM_TYPE_NR 16
1818+#define KM_TYPE_NR 17
1819
1820 #endif
1821diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1822index 9e614a1..3302cca 100644
1823--- a/arch/arm/include/asm/mach/dma.h
1824+++ b/arch/arm/include/asm/mach/dma.h
1825@@ -22,7 +22,7 @@ struct dma_ops {
1826 int (*residue)(unsigned int, dma_t *); /* optional */
1827 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1828 const char *type;
1829-};
1830+} __do_const;
1831
1832 struct dma_struct {
1833 void *addr; /* single DMA address */
1834diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1835index f98c7f3..e5c626d 100644
1836--- a/arch/arm/include/asm/mach/map.h
1837+++ b/arch/arm/include/asm/mach/map.h
1838@@ -23,17 +23,19 @@ struct map_desc {
1839
1840 /* types 0-3 are defined in asm/io.h */
1841 enum {
1842- MT_UNCACHED = 4,
1843- MT_CACHECLEAN,
1844- MT_MINICLEAN,
1845+ MT_UNCACHED_RW = 4,
1846+ MT_CACHECLEAN_RO,
1847+ MT_MINICLEAN_RO,
1848 MT_LOW_VECTORS,
1849 MT_HIGH_VECTORS,
1850- MT_MEMORY_RWX,
1851+ __MT_MEMORY_RWX,
1852 MT_MEMORY_RW,
1853- MT_ROM,
1854- MT_MEMORY_RWX_NONCACHED,
1855+ MT_MEMORY_RX,
1856+ MT_ROM_RX,
1857+ MT_MEMORY_RW_NONCACHED,
1858+ MT_MEMORY_RX_NONCACHED,
1859 MT_MEMORY_RW_DTCM,
1860- MT_MEMORY_RWX_ITCM,
1861+ MT_MEMORY_RX_ITCM,
1862 MT_MEMORY_RW_SO,
1863 MT_MEMORY_DMA_READY,
1864 };
1865diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1866index f94784f..9a09a4a 100644
1867--- a/arch/arm/include/asm/outercache.h
1868+++ b/arch/arm/include/asm/outercache.h
1869@@ -35,7 +35,7 @@ struct outer_cache_fns {
1870 #endif
1871 void (*set_debug)(unsigned long);
1872 void (*resume)(void);
1873-};
1874+} __no_const;
1875
1876 extern struct outer_cache_fns outer_cache;
1877
1878diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1879index 4355f0e..cd9168e 100644
1880--- a/arch/arm/include/asm/page.h
1881+++ b/arch/arm/include/asm/page.h
1882@@ -23,6 +23,7 @@
1883
1884 #else
1885
1886+#include <linux/compiler.h>
1887 #include <asm/glue.h>
1888
1889 /*
1890@@ -114,7 +115,7 @@ struct cpu_user_fns {
1891 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1892 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1893 unsigned long vaddr, struct vm_area_struct *vma);
1894-};
1895+} __no_const;
1896
1897 #ifdef MULTI_USER
1898 extern struct cpu_user_fns cpu_user;
1899diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1900index 78a7793..e3dc06c 100644
1901--- a/arch/arm/include/asm/pgalloc.h
1902+++ b/arch/arm/include/asm/pgalloc.h
1903@@ -17,6 +17,7 @@
1904 #include <asm/processor.h>
1905 #include <asm/cacheflush.h>
1906 #include <asm/tlbflush.h>
1907+#include <asm/system_info.h>
1908
1909 #define check_pgt_cache() do { } while (0)
1910
1911@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1912 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1913 }
1914
1915+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1916+{
1917+ pud_populate(mm, pud, pmd);
1918+}
1919+
1920 #else /* !CONFIG_ARM_LPAE */
1921
1922 /*
1923@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1924 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1925 #define pmd_free(mm, pmd) do { } while (0)
1926 #define pud_populate(mm,pmd,pte) BUG()
1927+#define pud_populate_kernel(mm,pmd,pte) BUG()
1928
1929 #endif /* CONFIG_ARM_LPAE */
1930
1931@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1932 __free_page(pte);
1933 }
1934
1935+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1936+{
1937+#ifdef CONFIG_ARM_LPAE
1938+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1939+#else
1940+ if (addr & SECTION_SIZE)
1941+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1942+ else
1943+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1944+#endif
1945+ flush_pmd_entry(pmdp);
1946+}
1947+
1948 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1949 pmdval_t prot)
1950 {
1951@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1952 static inline void
1953 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1954 {
1955- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1956+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1957 }
1958 #define pmd_pgtable(pmd) pmd_page(pmd)
1959
1960diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1961index 5cfba15..f415e1a 100644
1962--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1963+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1964@@ -20,12 +20,15 @@
1965 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1966 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1967 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1968+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1969 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1970 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1971 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1972+
1973 /*
1974 * - section
1975 */
1976+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1977 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1978 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1979 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1980@@ -37,6 +40,7 @@
1981 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1982 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1983 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1984+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1985
1986 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1987 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1988@@ -66,6 +70,7 @@
1989 * - extended small page/tiny page
1990 */
1991 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1992+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1993 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1994 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1995 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1996diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1997index 219ac88..73ec32a 100644
1998--- a/arch/arm/include/asm/pgtable-2level.h
1999+++ b/arch/arm/include/asm/pgtable-2level.h
2000@@ -126,6 +126,9 @@
2001 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2002 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2003
2004+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2005+#define L_PTE_PXN (_AT(pteval_t, 0))
2006+
2007 /*
2008 * These are the memory types, defined to be compatible with
2009 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2010diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2011index 626989f..9d67a33 100644
2012--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2013+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2014@@ -75,6 +75,7 @@
2015 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2016 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2017 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2018+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2019 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2020
2021 /*
2022diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2023index 85c60ad..b0bbd7e 100644
2024--- a/arch/arm/include/asm/pgtable-3level.h
2025+++ b/arch/arm/include/asm/pgtable-3level.h
2026@@ -82,6 +82,7 @@
2027 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2028 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2029 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2030+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2031 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2032 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2033 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2034@@ -95,6 +96,7 @@
2035 /*
2036 * To be used in assembly code with the upper page attributes.
2037 */
2038+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2039 #define L_PTE_XN_HIGH (1 << (54 - 32))
2040 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2041
2042diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2043index 5478e5d..f5b5cb3 100644
2044--- a/arch/arm/include/asm/pgtable.h
2045+++ b/arch/arm/include/asm/pgtable.h
2046@@ -33,6 +33,9 @@
2047 #include <asm/pgtable-2level.h>
2048 #endif
2049
2050+#define ktla_ktva(addr) (addr)
2051+#define ktva_ktla(addr) (addr)
2052+
2053 /*
2054 * Just any arbitrary offset to the start of the vmalloc VM area: the
2055 * current 8MB value just means that there will be a 8MB "hole" after the
2056@@ -48,6 +51,9 @@
2057 #define LIBRARY_TEXT_START 0x0c000000
2058
2059 #ifndef __ASSEMBLY__
2060+extern pteval_t __supported_pte_mask;
2061+extern pmdval_t __supported_pmd_mask;
2062+
2063 extern void __pte_error(const char *file, int line, pte_t);
2064 extern void __pmd_error(const char *file, int line, pmd_t);
2065 extern void __pgd_error(const char *file, int line, pgd_t);
2066@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2067 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2068 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2069
2070+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2071+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2072+
2073+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2074+#include <asm/domain.h>
2075+#include <linux/thread_info.h>
2076+#include <linux/preempt.h>
2077+
2078+static inline int test_domain(int domain, int domaintype)
2079+{
2080+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2081+}
2082+#endif
2083+
2084+#ifdef CONFIG_PAX_KERNEXEC
2085+static inline unsigned long pax_open_kernel(void) {
2086+#ifdef CONFIG_ARM_LPAE
2087+ /* TODO */
2088+#else
2089+ preempt_disable();
2090+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2091+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2092+#endif
2093+ return 0;
2094+}
2095+
2096+static inline unsigned long pax_close_kernel(void) {
2097+#ifdef CONFIG_ARM_LPAE
2098+ /* TODO */
2099+#else
2100+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2101+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2102+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2103+ preempt_enable_no_resched();
2104+#endif
2105+ return 0;
2106+}
2107+#else
2108+static inline unsigned long pax_open_kernel(void) { return 0; }
2109+static inline unsigned long pax_close_kernel(void) { return 0; }
2110+#endif
2111+
2112 /*
2113 * This is the lowest virtual address we can permit any user space
2114 * mapping to be mapped at. This is particularly important for
2115@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2116 /*
2117 * The pgprot_* and protection_map entries will be fixed up in runtime
2118 * to include the cachable and bufferable bits based on memory policy,
2119- * as well as any architecture dependent bits like global/ASID and SMP
2120- * shared mapping bits.
2121+ * as well as any architecture dependent bits like global/ASID, PXN,
2122+ * and SMP shared mapping bits.
2123 */
2124 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2125
2126@@ -265,7 +313,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2127 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2128 {
2129 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2130- L_PTE_NONE | L_PTE_VALID;
2131+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2132 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2133 return pte;
2134 }
2135diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2136index c4ae171..ea0c0c2 100644
2137--- a/arch/arm/include/asm/psci.h
2138+++ b/arch/arm/include/asm/psci.h
2139@@ -29,7 +29,7 @@ struct psci_operations {
2140 int (*cpu_off)(struct psci_power_state state);
2141 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2142 int (*migrate)(unsigned long cpuid);
2143-};
2144+} __no_const;
2145
2146 extern struct psci_operations psci_ops;
2147 extern struct smp_operations psci_smp_ops;
2148diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2149index 2ec765c..beb1fe16 100644
2150--- a/arch/arm/include/asm/smp.h
2151+++ b/arch/arm/include/asm/smp.h
2152@@ -113,7 +113,7 @@ struct smp_operations {
2153 int (*cpu_disable)(unsigned int cpu);
2154 #endif
2155 #endif
2156-};
2157+} __no_const;
2158
2159 struct of_cpu_method {
2160 const char *method;
2161diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2162index f989d7c..e8aa7f0 100644
2163--- a/arch/arm/include/asm/thread_info.h
2164+++ b/arch/arm/include/asm/thread_info.h
2165@@ -88,9 +88,9 @@ struct thread_info {
2166 .flags = 0, \
2167 .preempt_count = INIT_PREEMPT_COUNT, \
2168 .addr_limit = KERNEL_DS, \
2169- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2170- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2171- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2172+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2173+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2174+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2175 .restart_block = { \
2176 .fn = do_no_restart_syscall, \
2177 }, \
2178@@ -158,7 +158,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2179 #define TIF_SYSCALL_AUDIT 9
2180 #define TIF_SYSCALL_TRACEPOINT 10
2181 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2182-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2183+/* within 8 bits of TIF_SYSCALL_TRACE
2184+ * to meet flexible second operand requirements
2185+ */
2186+#define TIF_GRSEC_SETXID 12
2187+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2188 #define TIF_USING_IWMMXT 17
2189 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2190 #define TIF_RESTORE_SIGMASK 20
2191@@ -172,10 +176,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2192 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2193 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2194 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2195+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2196
2197 /* Checks for any syscall work in entry-common.S */
2198 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2199- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2200+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2201
2202 /*
2203 * Change these and you break ASM code in entry-common.S
2204diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2205index 75d9579..b5b40e4 100644
2206--- a/arch/arm/include/asm/uaccess.h
2207+++ b/arch/arm/include/asm/uaccess.h
2208@@ -18,6 +18,7 @@
2209 #include <asm/domain.h>
2210 #include <asm/unified.h>
2211 #include <asm/compiler.h>
2212+#include <asm/pgtable.h>
2213
2214 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2215 #include <asm-generic/uaccess-unaligned.h>
2216@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2217 static inline void set_fs(mm_segment_t fs)
2218 {
2219 current_thread_info()->addr_limit = fs;
2220- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2221+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2222 }
2223
2224 #define segment_eq(a,b) ((a) == (b))
2225
2226+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2227+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2228+
2229+static inline void pax_open_userland(void)
2230+{
2231+
2232+#ifdef CONFIG_PAX_MEMORY_UDEREF
2233+ if (segment_eq(get_fs(), USER_DS)) {
2234+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2235+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2236+ }
2237+#endif
2238+
2239+}
2240+
2241+static inline void pax_close_userland(void)
2242+{
2243+
2244+#ifdef CONFIG_PAX_MEMORY_UDEREF
2245+ if (segment_eq(get_fs(), USER_DS)) {
2246+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2247+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2248+ }
2249+#endif
2250+
2251+}
2252+
2253 #define __addr_ok(addr) ({ \
2254 unsigned long flag; \
2255 __asm__("cmp %2, %0; movlo %0, #0" \
2256@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2257
2258 #define get_user(x,p) \
2259 ({ \
2260+ int __e; \
2261 might_fault(); \
2262- __get_user_check(x,p); \
2263+ pax_open_userland(); \
2264+ __e = __get_user_check(x,p); \
2265+ pax_close_userland(); \
2266+ __e; \
2267 })
2268
2269 extern int __put_user_1(void *, unsigned int);
2270@@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2271
2272 #define put_user(x,p) \
2273 ({ \
2274+ int __e; \
2275 might_fault(); \
2276- __put_user_check(x,p); \
2277+ pax_open_userland(); \
2278+ __e = __put_user_check(x,p); \
2279+ pax_close_userland(); \
2280+ __e; \
2281 })
2282
2283 #else /* CONFIG_MMU */
2284@@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2285
2286 #endif /* CONFIG_MMU */
2287
2288+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2289 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2290
2291 #define user_addr_max() \
2292@@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2293 #define __get_user(x,ptr) \
2294 ({ \
2295 long __gu_err = 0; \
2296+ pax_open_userland(); \
2297 __get_user_err((x),(ptr),__gu_err); \
2298+ pax_close_userland(); \
2299 __gu_err; \
2300 })
2301
2302 #define __get_user_error(x,ptr,err) \
2303 ({ \
2304+ pax_open_userland(); \
2305 __get_user_err((x),(ptr),err); \
2306+ pax_close_userland(); \
2307 (void) 0; \
2308 })
2309
2310@@ -320,13 +361,17 @@ do { \
2311 #define __put_user(x,ptr) \
2312 ({ \
2313 long __pu_err = 0; \
2314+ pax_open_userland(); \
2315 __put_user_err((x),(ptr),__pu_err); \
2316+ pax_close_userland(); \
2317 __pu_err; \
2318 })
2319
2320 #define __put_user_error(x,ptr,err) \
2321 ({ \
2322+ pax_open_userland(); \
2323 __put_user_err((x),(ptr),err); \
2324+ pax_close_userland(); \
2325 (void) 0; \
2326 })
2327
2328@@ -426,11 +471,44 @@ do { \
2329
2330
2331 #ifdef CONFIG_MMU
2332-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2333-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2334+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2335+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2336+
2337+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2338+{
2339+ unsigned long ret;
2340+
2341+ check_object_size(to, n, false);
2342+ pax_open_userland();
2343+ ret = ___copy_from_user(to, from, n);
2344+ pax_close_userland();
2345+ return ret;
2346+}
2347+
2348+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2349+{
2350+ unsigned long ret;
2351+
2352+ check_object_size(from, n, true);
2353+ pax_open_userland();
2354+ ret = ___copy_to_user(to, from, n);
2355+ pax_close_userland();
2356+ return ret;
2357+}
2358+
2359 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2360-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2361+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2362 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2363+
2364+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2365+{
2366+ unsigned long ret;
2367+ pax_open_userland();
2368+ ret = ___clear_user(addr, n);
2369+ pax_close_userland();
2370+ return ret;
2371+}
2372+
2373 #else
2374 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2375 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2376@@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2377
2378 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2379 {
2380+ if ((long)n < 0)
2381+ return n;
2382+
2383 if (access_ok(VERIFY_READ, from, n))
2384 n = __copy_from_user(to, from, n);
2385 else /* security hole - plug it */
2386@@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2387
2388 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2389 {
2390+ if ((long)n < 0)
2391+ return n;
2392+
2393 if (access_ok(VERIFY_WRITE, to, n))
2394 n = __copy_to_user(to, from, n);
2395 return n;
2396diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2397index 5af0ed1..cea83883 100644
2398--- a/arch/arm/include/uapi/asm/ptrace.h
2399+++ b/arch/arm/include/uapi/asm/ptrace.h
2400@@ -92,7 +92,7 @@
2401 * ARMv7 groups of PSR bits
2402 */
2403 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2404-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2405+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2406 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2407 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2408
2409diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2410index f7b450f..f5364c5 100644
2411--- a/arch/arm/kernel/armksyms.c
2412+++ b/arch/arm/kernel/armksyms.c
2413@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2414
2415 /* networking */
2416 EXPORT_SYMBOL(csum_partial);
2417-EXPORT_SYMBOL(csum_partial_copy_from_user);
2418+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2419 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2420 EXPORT_SYMBOL(__csum_ipv6_magic);
2421
2422@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2423 #ifdef CONFIG_MMU
2424 EXPORT_SYMBOL(copy_page);
2425
2426-EXPORT_SYMBOL(__copy_from_user);
2427-EXPORT_SYMBOL(__copy_to_user);
2428-EXPORT_SYMBOL(__clear_user);
2429+EXPORT_SYMBOL(___copy_from_user);
2430+EXPORT_SYMBOL(___copy_to_user);
2431+EXPORT_SYMBOL(___clear_user);
2432
2433 EXPORT_SYMBOL(__get_user_1);
2434 EXPORT_SYMBOL(__get_user_2);
2435diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2436index 1879e8d..5602dd4 100644
2437--- a/arch/arm/kernel/entry-armv.S
2438+++ b/arch/arm/kernel/entry-armv.S
2439@@ -47,6 +47,87 @@
2440 9997:
2441 .endm
2442
2443+ .macro pax_enter_kernel
2444+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2445+ @ make aligned space for saved DACR
2446+ sub sp, sp, #8
2447+ @ save regs
2448+ stmdb sp!, {r1, r2}
2449+ @ read DACR from cpu_domain into r1
2450+ mov r2, sp
2451+ @ assume 8K pages, since we have to split the immediate in two
2452+ bic r2, r2, #(0x1fc0)
2453+ bic r2, r2, #(0x3f)
2454+ ldr r1, [r2, #TI_CPU_DOMAIN]
2455+ @ store old DACR on stack
2456+ str r1, [sp, #8]
2457+#ifdef CONFIG_PAX_KERNEXEC
2458+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2459+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2460+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2461+#endif
2462+#ifdef CONFIG_PAX_MEMORY_UDEREF
2463+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2464+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2465+#endif
2466+ @ write r1 to current_thread_info()->cpu_domain
2467+ str r1, [r2, #TI_CPU_DOMAIN]
2468+ @ write r1 to DACR
2469+ mcr p15, 0, r1, c3, c0, 0
2470+ @ instruction sync
2471+ instr_sync
2472+ @ restore regs
2473+ ldmia sp!, {r1, r2}
2474+#endif
2475+ .endm
2476+
2477+ .macro pax_open_userland
2478+#ifdef CONFIG_PAX_MEMORY_UDEREF
2479+ @ save regs
2480+ stmdb sp!, {r0, r1}
2481+ @ read DACR from cpu_domain into r1
2482+ mov r0, sp
2483+ @ assume 8K pages, since we have to split the immediate in two
2484+ bic r0, r0, #(0x1fc0)
2485+ bic r0, r0, #(0x3f)
2486+ ldr r1, [r0, #TI_CPU_DOMAIN]
2487+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2488+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2489+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2490+ @ write r1 to current_thread_info()->cpu_domain
2491+ str r1, [r0, #TI_CPU_DOMAIN]
2492+ @ write r1 to DACR
2493+ mcr p15, 0, r1, c3, c0, 0
2494+ @ instruction sync
2495+ instr_sync
2496+ @ restore regs
2497+ ldmia sp!, {r0, r1}
2498+#endif
2499+ .endm
2500+
2501+ .macro pax_close_userland
2502+#ifdef CONFIG_PAX_MEMORY_UDEREF
2503+ @ save regs
2504+ stmdb sp!, {r0, r1}
2505+ @ read DACR from cpu_domain into r1
2506+ mov r0, sp
2507+ @ assume 8K pages, since we have to split the immediate in two
2508+ bic r0, r0, #(0x1fc0)
2509+ bic r0, r0, #(0x3f)
2510+ ldr r1, [r0, #TI_CPU_DOMAIN]
2511+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2512+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2513+ @ write r1 to current_thread_info()->cpu_domain
2514+ str r1, [r0, #TI_CPU_DOMAIN]
2515+ @ write r1 to DACR
2516+ mcr p15, 0, r1, c3, c0, 0
2517+ @ instruction sync
2518+ instr_sync
2519+ @ restore regs
2520+ ldmia sp!, {r0, r1}
2521+#endif
2522+ .endm
2523+
2524 .macro pabt_helper
2525 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2526 #ifdef MULTI_PABORT
2527@@ -89,11 +170,15 @@
2528 * Invalid mode handlers
2529 */
2530 .macro inv_entry, reason
2531+
2532+ pax_enter_kernel
2533+
2534 sub sp, sp, #S_FRAME_SIZE
2535 ARM( stmib sp, {r1 - lr} )
2536 THUMB( stmia sp, {r0 - r12} )
2537 THUMB( str sp, [sp, #S_SP] )
2538 THUMB( str lr, [sp, #S_LR] )
2539+
2540 mov r1, #\reason
2541 .endm
2542
2543@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2544 .macro svc_entry, stack_hole=0
2545 UNWIND(.fnstart )
2546 UNWIND(.save {r0 - pc} )
2547+
2548+ pax_enter_kernel
2549+
2550 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2551+
2552 #ifdef CONFIG_THUMB2_KERNEL
2553 SPFIX( str r0, [sp] ) @ temporarily saved
2554 SPFIX( mov r0, sp )
2555@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2556 ldmia r0, {r3 - r5}
2557 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2558 mov r6, #-1 @ "" "" "" ""
2559+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2560+ @ offset sp by 8 as done in pax_enter_kernel
2561+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2562+#else
2563 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2564+#endif
2565 SPFIX( addeq r2, r2, #4 )
2566 str r3, [sp, #-4]! @ save the "real" r0 copied
2567 @ from the exception stack
2568@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2569 .macro usr_entry
2570 UNWIND(.fnstart )
2571 UNWIND(.cantunwind ) @ don't unwind the user space
2572+
2573+ pax_enter_kernel_user
2574+
2575 sub sp, sp, #S_FRAME_SIZE
2576 ARM( stmib sp, {r1 - r12} )
2577 THUMB( stmia sp, {r0 - r12} )
2578@@ -416,7 +513,9 @@ __und_usr:
2579 tst r3, #PSR_T_BIT @ Thumb mode?
2580 bne __und_usr_thumb
2581 sub r4, r2, #4 @ ARM instr at LR - 4
2582+ pax_open_userland
2583 1: ldrt r0, [r4]
2584+ pax_close_userland
2585 ARM_BE8(rev r0, r0) @ little endian instruction
2586
2587 @ r0 = 32-bit ARM instruction which caused the exception
2588@@ -450,11 +549,15 @@ __und_usr_thumb:
2589 */
2590 .arch armv6t2
2591 #endif
2592+ pax_open_userland
2593 2: ldrht r5, [r4]
2594+ pax_close_userland
2595 ARM_BE8(rev16 r5, r5) @ little endian instruction
2596 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2597 blo __und_usr_fault_16 @ 16bit undefined instruction
2598+ pax_open_userland
2599 3: ldrht r0, [r2]
2600+ pax_close_userland
2601 ARM_BE8(rev16 r0, r0) @ little endian instruction
2602 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2603 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2604@@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2605 */
2606 .pushsection .fixup, "ax"
2607 .align 2
2608-4: mov pc, r9
2609+4: pax_close_userland
2610+ mov pc, r9
2611 .popsection
2612 .pushsection __ex_table,"a"
2613 .long 1b, 4b
2614@@ -694,7 +798,7 @@ ENTRY(__switch_to)
2615 THUMB( str lr, [ip], #4 )
2616 ldr r4, [r2, #TI_TP_VALUE]
2617 ldr r5, [r2, #TI_TP_VALUE + 4]
2618-#ifdef CONFIG_CPU_USE_DOMAINS
2619+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2620 ldr r6, [r2, #TI_CPU_DOMAIN]
2621 #endif
2622 switch_tls r1, r4, r5, r3, r7
2623@@ -703,7 +807,7 @@ ENTRY(__switch_to)
2624 ldr r8, =__stack_chk_guard
2625 ldr r7, [r7, #TSK_STACK_CANARY]
2626 #endif
2627-#ifdef CONFIG_CPU_USE_DOMAINS
2628+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2629 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2630 #endif
2631 mov r5, r0
2632diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2633index a2dcafd..1048b5a 100644
2634--- a/arch/arm/kernel/entry-common.S
2635+++ b/arch/arm/kernel/entry-common.S
2636@@ -10,18 +10,46 @@
2637
2638 #include <asm/unistd.h>
2639 #include <asm/ftrace.h>
2640+#include <asm/domain.h>
2641 #include <asm/unwind.h>
2642
2643+#include "entry-header.S"
2644+
2645 #ifdef CONFIG_NEED_RET_TO_USER
2646 #include <mach/entry-macro.S>
2647 #else
2648 .macro arch_ret_to_user, tmp1, tmp2
2649+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2650+ @ save regs
2651+ stmdb sp!, {r1, r2}
2652+ @ read DACR from cpu_domain into r1
2653+ mov r2, sp
2654+ @ assume 8K pages, since we have to split the immediate in two
2655+ bic r2, r2, #(0x1fc0)
2656+ bic r2, r2, #(0x3f)
2657+ ldr r1, [r2, #TI_CPU_DOMAIN]
2658+#ifdef CONFIG_PAX_KERNEXEC
2659+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2660+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2661+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2662+#endif
2663+#ifdef CONFIG_PAX_MEMORY_UDEREF
2664+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2665+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2666+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2667+#endif
2668+ @ write r1 to current_thread_info()->cpu_domain
2669+ str r1, [r2, #TI_CPU_DOMAIN]
2670+ @ write r1 to DACR
2671+ mcr p15, 0, r1, c3, c0, 0
2672+ @ instruction sync
2673+ instr_sync
2674+ @ restore regs
2675+ ldmia sp!, {r1, r2}
2676+#endif
2677 .endm
2678 #endif
2679
2680-#include "entry-header.S"
2681-
2682-
2683 .align 5
2684 /*
2685 * This is the fast syscall return path. We do as little as
2686@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2687 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2688 #endif
2689
2690+ /*
2691+ * do this here to avoid a performance hit of wrapping the code above
2692+ * that directly dereferences userland to parse the SWI instruction
2693+ */
2694+ pax_enter_kernel_user
2695+
2696 adr tbl, sys_call_table @ load syscall table pointer
2697
2698 #if defined(CONFIG_OABI_COMPAT)
2699diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2700index efb208d..d34bd02 100644
2701--- a/arch/arm/kernel/entry-header.S
2702+++ b/arch/arm/kernel/entry-header.S
2703@@ -188,6 +188,60 @@
2704 msr cpsr_c, \rtemp @ switch back to the SVC mode
2705 .endm
2706
2707+ .macro pax_enter_kernel_user
2708+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2709+ @ save regs
2710+ stmdb sp!, {r0, r1}
2711+ @ read DACR from cpu_domain into r1
2712+ mov r0, sp
2713+ @ assume 8K pages, since we have to split the immediate in two
2714+ bic r0, r0, #(0x1fc0)
2715+ bic r0, r0, #(0x3f)
2716+ ldr r1, [r0, #TI_CPU_DOMAIN]
2717+#ifdef CONFIG_PAX_MEMORY_UDEREF
2718+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2719+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2720+#endif
2721+#ifdef CONFIG_PAX_KERNEXEC
2722+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2723+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2724+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2725+#endif
2726+ @ write r1 to current_thread_info()->cpu_domain
2727+ str r1, [r0, #TI_CPU_DOMAIN]
2728+ @ write r1 to DACR
2729+ mcr p15, 0, r1, c3, c0, 0
2730+ @ instruction sync
2731+ instr_sync
2732+ @ restore regs
2733+ ldmia sp!, {r0, r1}
2734+#endif
2735+ .endm
2736+
2737+ .macro pax_exit_kernel
2738+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2739+ @ save regs
2740+ stmdb sp!, {r0, r1}
2741+ @ read old DACR from stack into r1
2742+ ldr r1, [sp, #(8 + S_SP)]
2743+ sub r1, r1, #8
2744+ ldr r1, [r1]
2745+
2746+ @ write r1 to current_thread_info()->cpu_domain
2747+ mov r0, sp
2748+ @ assume 8K pages, since we have to split the immediate in two
2749+ bic r0, r0, #(0x1fc0)
2750+ bic r0, r0, #(0x3f)
2751+ str r1, [r0, #TI_CPU_DOMAIN]
2752+ @ write r1 to DACR
2753+ mcr p15, 0, r1, c3, c0, 0
2754+ @ instruction sync
2755+ instr_sync
2756+ @ restore regs
2757+ ldmia sp!, {r0, r1}
2758+#endif
2759+ .endm
2760+
2761 #ifndef CONFIG_THUMB2_KERNEL
2762 .macro svc_exit, rpsr, irq = 0
2763 .if \irq != 0
2764@@ -207,6 +261,9 @@
2765 blne trace_hardirqs_off
2766 #endif
2767 .endif
2768+
2769+ pax_exit_kernel
2770+
2771 msr spsr_cxsf, \rpsr
2772 #if defined(CONFIG_CPU_V6)
2773 ldr r0, [sp]
2774@@ -265,6 +322,9 @@
2775 blne trace_hardirqs_off
2776 #endif
2777 .endif
2778+
2779+ pax_exit_kernel
2780+
2781 ldr lr, [sp, #S_SP] @ top of the stack
2782 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2783 clrex @ clear the exclusive monitor
2784diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2785index 918875d..cd5fa27 100644
2786--- a/arch/arm/kernel/fiq.c
2787+++ b/arch/arm/kernel/fiq.c
2788@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2789 void *base = vectors_page;
2790 unsigned offset = FIQ_OFFSET;
2791
2792+ pax_open_kernel();
2793 memcpy(base + offset, start, length);
2794+ pax_close_kernel();
2795+
2796 if (!cache_is_vipt_nonaliasing())
2797 flush_icache_range((unsigned long)base + offset, offset +
2798 length);
2799diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2800index 591d6e4..8322a26 100644
2801--- a/arch/arm/kernel/head.S
2802+++ b/arch/arm/kernel/head.S
2803@@ -437,7 +437,7 @@ __enable_mmu:
2804 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2805 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2806 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2807- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2808+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2809 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2810 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2811 #endif
2812diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2813index 45e4781..8eac93d 100644
2814--- a/arch/arm/kernel/module.c
2815+++ b/arch/arm/kernel/module.c
2816@@ -38,12 +38,39 @@
2817 #endif
2818
2819 #ifdef CONFIG_MMU
2820-void *module_alloc(unsigned long size)
2821+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2822 {
2823+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2824+ return NULL;
2825 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2826- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2827+ GFP_KERNEL, prot, NUMA_NO_NODE,
2828 __builtin_return_address(0));
2829 }
2830+
2831+void *module_alloc(unsigned long size)
2832+{
2833+
2834+#ifdef CONFIG_PAX_KERNEXEC
2835+ return __module_alloc(size, PAGE_KERNEL);
2836+#else
2837+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2838+#endif
2839+
2840+}
2841+
2842+#ifdef CONFIG_PAX_KERNEXEC
2843+void module_free_exec(struct module *mod, void *module_region)
2844+{
2845+ module_free(mod, module_region);
2846+}
2847+EXPORT_SYMBOL(module_free_exec);
2848+
2849+void *module_alloc_exec(unsigned long size)
2850+{
2851+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2852+}
2853+EXPORT_SYMBOL(module_alloc_exec);
2854+#endif
2855 #endif
2856
2857 int
2858diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2859index 07314af..c46655c 100644
2860--- a/arch/arm/kernel/patch.c
2861+++ b/arch/arm/kernel/patch.c
2862@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2863 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2864 int size;
2865
2866+ pax_open_kernel();
2867 if (thumb2 && __opcode_is_thumb16(insn)) {
2868 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2869 size = sizeof(u16);
2870@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2871 *(u32 *)addr = insn;
2872 size = sizeof(u32);
2873 }
2874+ pax_close_kernel();
2875
2876 flush_icache_range((uintptr_t)(addr),
2877 (uintptr_t)(addr) + size);
2878diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2879index 81ef686..f4130b8 100644
2880--- a/arch/arm/kernel/process.c
2881+++ b/arch/arm/kernel/process.c
2882@@ -212,6 +212,7 @@ void machine_power_off(void)
2883
2884 if (pm_power_off)
2885 pm_power_off();
2886+ BUG();
2887 }
2888
2889 /*
2890@@ -225,7 +226,7 @@ void machine_power_off(void)
2891 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2892 * to use. Implementing such co-ordination would be essentially impossible.
2893 */
2894-void machine_restart(char *cmd)
2895+__noreturn void machine_restart(char *cmd)
2896 {
2897 local_irq_disable();
2898 smp_send_stop();
2899@@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
2900
2901 show_regs_print_info(KERN_DEFAULT);
2902
2903- print_symbol("PC is at %s\n", instruction_pointer(regs));
2904- print_symbol("LR is at %s\n", regs->ARM_lr);
2905+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2906+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2907 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2908 "sp : %08lx ip : %08lx fp : %08lx\n",
2909 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2910@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2911 return 0;
2912 }
2913
2914-unsigned long arch_randomize_brk(struct mm_struct *mm)
2915-{
2916- unsigned long range_end = mm->brk + 0x02000000;
2917- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2918-}
2919-
2920 #ifdef CONFIG_MMU
2921 #ifdef CONFIG_KUSER_HELPERS
2922 /*
2923@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2924
2925 static int __init gate_vma_init(void)
2926 {
2927- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2928+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2929 return 0;
2930 }
2931 arch_initcall(gate_vma_init);
2932@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2933
2934 const char *arch_vma_name(struct vm_area_struct *vma)
2935 {
2936- return is_gate_vma(vma) ? "[vectors]" :
2937- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2938- "[sigpage]" : NULL;
2939+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2940 }
2941
2942-static struct page *signal_page;
2943-extern struct page *get_signal_page(void);
2944-
2945 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2946 {
2947 struct mm_struct *mm = current->mm;
2948- unsigned long addr;
2949- int ret;
2950-
2951- if (!signal_page)
2952- signal_page = get_signal_page();
2953- if (!signal_page)
2954- return -ENOMEM;
2955
2956 down_write(&mm->mmap_sem);
2957- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2958- if (IS_ERR_VALUE(addr)) {
2959- ret = addr;
2960- goto up_fail;
2961- }
2962-
2963- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2964- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2965- &signal_page);
2966-
2967- if (ret == 0)
2968- mm->context.sigpage = addr;
2969-
2970- up_fail:
2971+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2972 up_write(&mm->mmap_sem);
2973- return ret;
2974+ return 0;
2975 }
2976 #endif
2977diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2978index 4693188..4596c5e 100644
2979--- a/arch/arm/kernel/psci.c
2980+++ b/arch/arm/kernel/psci.c
2981@@ -24,7 +24,7 @@
2982 #include <asm/opcodes-virt.h>
2983 #include <asm/psci.h>
2984
2985-struct psci_operations psci_ops;
2986+struct psci_operations psci_ops __read_only;
2987
2988 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2989
2990diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2991index 0dd3b79..b67388e 100644
2992--- a/arch/arm/kernel/ptrace.c
2993+++ b/arch/arm/kernel/ptrace.c
2994@@ -908,7 +908,7 @@ enum ptrace_syscall_dir {
2995 PTRACE_SYSCALL_EXIT,
2996 };
2997
2998-static int tracehook_report_syscall(struct pt_regs *regs,
2999+static void tracehook_report_syscall(struct pt_regs *regs,
3000 enum ptrace_syscall_dir dir)
3001 {
3002 unsigned long ip;
3003@@ -926,19 +926,29 @@ static int tracehook_report_syscall(struct pt_regs *regs,
3004 current_thread_info()->syscall = -1;
3005
3006 regs->ARM_ip = ip;
3007- return current_thread_info()->syscall;
3008 }
3009
3010+#ifdef CONFIG_GRKERNSEC_SETXID
3011+extern void gr_delayed_cred_worker(void);
3012+#endif
3013+
3014 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3015 {
3016 current_thread_info()->syscall = scno;
3017
3018+#ifdef CONFIG_GRKERNSEC_SETXID
3019+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3020+ gr_delayed_cred_worker();
3021+#endif
3022+
3023 /* Do the secure computing check first; failures should be fast. */
3024 if (secure_computing(scno) == -1)
3025 return -1;
3026
3027 if (test_thread_flag(TIF_SYSCALL_TRACE))
3028- scno = tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3029+ tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3030+
3031+ scno = current_thread_info()->syscall;
3032
3033 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
3034 trace_sys_enter(regs, scno);
3035diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3036index 50e198c..a8b5f49 100644
3037--- a/arch/arm/kernel/setup.c
3038+++ b/arch/arm/kernel/setup.c
3039@@ -103,21 +103,23 @@ EXPORT_SYMBOL(elf_hwcap);
3040 unsigned int elf_hwcap2 __read_mostly;
3041 EXPORT_SYMBOL(elf_hwcap2);
3042
3043+pteval_t __supported_pte_mask __read_only;
3044+pmdval_t __supported_pmd_mask __read_only;
3045
3046 #ifdef MULTI_CPU
3047-struct processor processor __read_mostly;
3048+struct processor processor __read_only;
3049 #endif
3050 #ifdef MULTI_TLB
3051-struct cpu_tlb_fns cpu_tlb __read_mostly;
3052+struct cpu_tlb_fns cpu_tlb __read_only;
3053 #endif
3054 #ifdef MULTI_USER
3055-struct cpu_user_fns cpu_user __read_mostly;
3056+struct cpu_user_fns cpu_user __read_only;
3057 #endif
3058 #ifdef MULTI_CACHE
3059-struct cpu_cache_fns cpu_cache __read_mostly;
3060+struct cpu_cache_fns cpu_cache __read_only;
3061 #endif
3062 #ifdef CONFIG_OUTER_CACHE
3063-struct outer_cache_fns outer_cache __read_mostly;
3064+struct outer_cache_fns outer_cache __read_only;
3065 EXPORT_SYMBOL(outer_cache);
3066 #endif
3067
3068@@ -250,9 +252,13 @@ static int __get_cpu_architecture(void)
3069 asm("mrc p15, 0, %0, c0, c1, 4"
3070 : "=r" (mmfr0));
3071 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3072- (mmfr0 & 0x000000f0) >= 0x00000030)
3073+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3074 cpu_arch = CPU_ARCH_ARMv7;
3075- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3076+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3077+ __supported_pte_mask |= L_PTE_PXN;
3078+ __supported_pmd_mask |= PMD_PXNTABLE;
3079+ }
3080+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3081 (mmfr0 & 0x000000f0) == 0x00000020)
3082 cpu_arch = CPU_ARCH_ARMv6;
3083 else
3084diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3085index bd19834..e4d8c66 100644
3086--- a/arch/arm/kernel/signal.c
3087+++ b/arch/arm/kernel/signal.c
3088@@ -24,8 +24,6 @@
3089
3090 extern const unsigned long sigreturn_codes[7];
3091
3092-static unsigned long signal_return_offset;
3093-
3094 #ifdef CONFIG_CRUNCH
3095 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3096 {
3097@@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3098 * except when the MPU has protected the vectors
3099 * page from PL0
3100 */
3101- retcode = mm->context.sigpage + signal_return_offset +
3102- (idx << 2) + thumb;
3103+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3104 } else
3105 #endif
3106 {
3107@@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3108 } while (thread_flags & _TIF_WORK_MASK);
3109 return 0;
3110 }
3111-
3112-struct page *get_signal_page(void)
3113-{
3114- unsigned long ptr;
3115- unsigned offset;
3116- struct page *page;
3117- void *addr;
3118-
3119- page = alloc_pages(GFP_KERNEL, 0);
3120-
3121- if (!page)
3122- return NULL;
3123-
3124- addr = page_address(page);
3125-
3126- /* Give the signal return code some randomness */
3127- offset = 0x200 + (get_random_int() & 0x7fc);
3128- signal_return_offset = offset;
3129-
3130- /*
3131- * Copy signal return handlers into the vector page, and
3132- * set sigreturn to be a pointer to these.
3133- */
3134- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3135-
3136- ptr = (unsigned long)addr + offset;
3137- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3138-
3139- return page;
3140-}
3141diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3142index 7c4fada..8581286 100644
3143--- a/arch/arm/kernel/smp.c
3144+++ b/arch/arm/kernel/smp.c
3145@@ -73,7 +73,7 @@ enum ipi_msg_type {
3146
3147 static DECLARE_COMPLETION(cpu_running);
3148
3149-static struct smp_operations smp_ops;
3150+static struct smp_operations smp_ops __read_only;
3151
3152 void __init smp_set_ops(struct smp_operations *ops)
3153 {
3154diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3155index 7a3be1d..b00c7de 100644
3156--- a/arch/arm/kernel/tcm.c
3157+++ b/arch/arm/kernel/tcm.c
3158@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3159 .virtual = ITCM_OFFSET,
3160 .pfn = __phys_to_pfn(ITCM_OFFSET),
3161 .length = 0,
3162- .type = MT_MEMORY_RWX_ITCM,
3163+ .type = MT_MEMORY_RX_ITCM,
3164 }
3165 };
3166
3167@@ -267,7 +267,9 @@ no_dtcm:
3168 start = &__sitcm_text;
3169 end = &__eitcm_text;
3170 ram = &__itcm_start;
3171+ pax_open_kernel();
3172 memcpy(start, ram, itcm_code_sz);
3173+ pax_close_kernel();
3174 pr_debug("CPU ITCM: copied code from %p - %p\n",
3175 start, end);
3176 itcm_present = true;
3177diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3178index abd2fc0..895dbb6 100644
3179--- a/arch/arm/kernel/traps.c
3180+++ b/arch/arm/kernel/traps.c
3181@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3182 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3183 {
3184 #ifdef CONFIG_KALLSYMS
3185- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3186+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3187 #else
3188 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3189 #endif
3190@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3191 static int die_owner = -1;
3192 static unsigned int die_nest_count;
3193
3194+extern void gr_handle_kernel_exploit(void);
3195+
3196 static unsigned long oops_begin(void)
3197 {
3198 int cpu;
3199@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3200 panic("Fatal exception in interrupt");
3201 if (panic_on_oops)
3202 panic("Fatal exception");
3203+
3204+ gr_handle_kernel_exploit();
3205+
3206 if (signr)
3207 do_exit(signr);
3208 }
3209@@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3210 * The user helper at 0xffff0fe0 must be used instead.
3211 * (see entry-armv.S for details)
3212 */
3213+ pax_open_kernel();
3214 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3215+ pax_close_kernel();
3216 }
3217 return 0;
3218
3219@@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3220 kuser_init(vectors_base);
3221
3222 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3223- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3224+
3225+#ifndef CONFIG_PAX_MEMORY_UDEREF
3226+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3227+#endif
3228+
3229 #else /* ifndef CONFIG_CPU_V7M */
3230 /*
3231 * on V7-M there is no need to copy the vector table to a dedicated
3232diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3233index 7bcee5c..e2f3249 100644
3234--- a/arch/arm/kernel/vmlinux.lds.S
3235+++ b/arch/arm/kernel/vmlinux.lds.S
3236@@ -8,7 +8,11 @@
3237 #include <asm/thread_info.h>
3238 #include <asm/memory.h>
3239 #include <asm/page.h>
3240-
3241+
3242+#ifdef CONFIG_PAX_KERNEXEC
3243+#include <asm/pgtable.h>
3244+#endif
3245+
3246 #define PROC_INFO \
3247 . = ALIGN(4); \
3248 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3249@@ -34,7 +38,7 @@
3250 #endif
3251
3252 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3253- defined(CONFIG_GENERIC_BUG)
3254+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3255 #define ARM_EXIT_KEEP(x) x
3256 #define ARM_EXIT_DISCARD(x)
3257 #else
3258@@ -90,6 +94,11 @@ SECTIONS
3259 _text = .;
3260 HEAD_TEXT
3261 }
3262+
3263+#ifdef CONFIG_PAX_KERNEXEC
3264+ . = ALIGN(1<<SECTION_SHIFT);
3265+#endif
3266+
3267 .text : { /* Real text segment */
3268 _stext = .; /* Text and read-only data */
3269 __exception_text_start = .;
3270@@ -112,6 +121,8 @@ SECTIONS
3271 ARM_CPU_KEEP(PROC_INFO)
3272 }
3273
3274+ _etext = .; /* End of text section */
3275+
3276 RO_DATA(PAGE_SIZE)
3277
3278 . = ALIGN(4);
3279@@ -142,7 +153,9 @@ SECTIONS
3280
3281 NOTES
3282
3283- _etext = .; /* End of text and rodata section */
3284+#ifdef CONFIG_PAX_KERNEXEC
3285+ . = ALIGN(1<<SECTION_SHIFT);
3286+#endif
3287
3288 #ifndef CONFIG_XIP_KERNEL
3289 . = ALIGN(PAGE_SIZE);
3290@@ -220,6 +233,11 @@ SECTIONS
3291 . = PAGE_OFFSET + TEXT_OFFSET;
3292 #else
3293 __init_end = .;
3294+
3295+#ifdef CONFIG_PAX_KERNEXEC
3296+ . = ALIGN(1<<SECTION_SHIFT);
3297+#endif
3298+
3299 . = ALIGN(THREAD_SIZE);
3300 __data_loc = .;
3301 #endif
3302diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3303index f0e50a0..cab3a75 100644
3304--- a/arch/arm/kvm/arm.c
3305+++ b/arch/arm/kvm/arm.c
3306@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3307 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3308
3309 /* The VMID used in the VTTBR */
3310-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3311+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3312 static u8 kvm_next_vmid;
3313 static DEFINE_SPINLOCK(kvm_vmid_lock);
3314
3315@@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3316 */
3317 static bool need_new_vmid_gen(struct kvm *kvm)
3318 {
3319- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3320+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3321 }
3322
3323 /**
3324@@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3325
3326 /* First user of a new VMID generation? */
3327 if (unlikely(kvm_next_vmid == 0)) {
3328- atomic64_inc(&kvm_vmid_gen);
3329+ atomic64_inc_unchecked(&kvm_vmid_gen);
3330 kvm_next_vmid = 1;
3331
3332 /*
3333@@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3334 kvm_call_hyp(__kvm_flush_vm_context);
3335 }
3336
3337- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3338+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3339 kvm->arch.vmid = kvm_next_vmid;
3340 kvm_next_vmid++;
3341
3342@@ -1033,7 +1033,7 @@ static void check_kvm_target_cpu(void *ret)
3343 /**
3344 * Initialize Hyp-mode and memory mappings on all CPUs.
3345 */
3346-int kvm_arch_init(void *opaque)
3347+int kvm_arch_init(const void *opaque)
3348 {
3349 int err;
3350 int ret, cpu;
3351diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3352index 14a0d98..7771a7d 100644
3353--- a/arch/arm/lib/clear_user.S
3354+++ b/arch/arm/lib/clear_user.S
3355@@ -12,14 +12,14 @@
3356
3357 .text
3358
3359-/* Prototype: int __clear_user(void *addr, size_t sz)
3360+/* Prototype: int ___clear_user(void *addr, size_t sz)
3361 * Purpose : clear some user memory
3362 * Params : addr - user memory address to clear
3363 * : sz - number of bytes to clear
3364 * Returns : number of bytes NOT cleared
3365 */
3366 ENTRY(__clear_user_std)
3367-WEAK(__clear_user)
3368+WEAK(___clear_user)
3369 stmfd sp!, {r1, lr}
3370 mov r2, #0
3371 cmp r1, #4
3372@@ -44,7 +44,7 @@ WEAK(__clear_user)
3373 USER( strnebt r2, [r0])
3374 mov r0, #0
3375 ldmfd sp!, {r1, pc}
3376-ENDPROC(__clear_user)
3377+ENDPROC(___clear_user)
3378 ENDPROC(__clear_user_std)
3379
3380 .pushsection .fixup,"ax"
3381diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3382index 66a477a..bee61d3 100644
3383--- a/arch/arm/lib/copy_from_user.S
3384+++ b/arch/arm/lib/copy_from_user.S
3385@@ -16,7 +16,7 @@
3386 /*
3387 * Prototype:
3388 *
3389- * size_t __copy_from_user(void *to, const void *from, size_t n)
3390+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3391 *
3392 * Purpose:
3393 *
3394@@ -84,11 +84,11 @@
3395
3396 .text
3397
3398-ENTRY(__copy_from_user)
3399+ENTRY(___copy_from_user)
3400
3401 #include "copy_template.S"
3402
3403-ENDPROC(__copy_from_user)
3404+ENDPROC(___copy_from_user)
3405
3406 .pushsection .fixup,"ax"
3407 .align 0
3408diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3409index 6ee2f67..d1cce76 100644
3410--- a/arch/arm/lib/copy_page.S
3411+++ b/arch/arm/lib/copy_page.S
3412@@ -10,6 +10,7 @@
3413 * ASM optimised string functions
3414 */
3415 #include <linux/linkage.h>
3416+#include <linux/const.h>
3417 #include <asm/assembler.h>
3418 #include <asm/asm-offsets.h>
3419 #include <asm/cache.h>
3420diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3421index d066df6..df28194 100644
3422--- a/arch/arm/lib/copy_to_user.S
3423+++ b/arch/arm/lib/copy_to_user.S
3424@@ -16,7 +16,7 @@
3425 /*
3426 * Prototype:
3427 *
3428- * size_t __copy_to_user(void *to, const void *from, size_t n)
3429+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3430 *
3431 * Purpose:
3432 *
3433@@ -88,11 +88,11 @@
3434 .text
3435
3436 ENTRY(__copy_to_user_std)
3437-WEAK(__copy_to_user)
3438+WEAK(___copy_to_user)
3439
3440 #include "copy_template.S"
3441
3442-ENDPROC(__copy_to_user)
3443+ENDPROC(___copy_to_user)
3444 ENDPROC(__copy_to_user_std)
3445
3446 .pushsection .fixup,"ax"
3447diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3448index 7d08b43..f7ca7ea 100644
3449--- a/arch/arm/lib/csumpartialcopyuser.S
3450+++ b/arch/arm/lib/csumpartialcopyuser.S
3451@@ -57,8 +57,8 @@
3452 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3453 */
3454
3455-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3456-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3457+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3458+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3459
3460 #include "csumpartialcopygeneric.S"
3461
3462diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3463index 5306de3..aed6d03 100644
3464--- a/arch/arm/lib/delay.c
3465+++ b/arch/arm/lib/delay.c
3466@@ -28,7 +28,7 @@
3467 /*
3468 * Default to the loop-based delay implementation.
3469 */
3470-struct arm_delay_ops arm_delay_ops = {
3471+struct arm_delay_ops arm_delay_ops __read_only = {
3472 .delay = __loop_delay,
3473 .const_udelay = __loop_const_udelay,
3474 .udelay = __loop_udelay,
3475diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3476index 3e58d71..029817c 100644
3477--- a/arch/arm/lib/uaccess_with_memcpy.c
3478+++ b/arch/arm/lib/uaccess_with_memcpy.c
3479@@ -136,7 +136,7 @@ out:
3480 }
3481
3482 unsigned long
3483-__copy_to_user(void __user *to, const void *from, unsigned long n)
3484+___copy_to_user(void __user *to, const void *from, unsigned long n)
3485 {
3486 /*
3487 * This test is stubbed out of the main function above to keep
3488@@ -190,7 +190,7 @@ out:
3489 return n;
3490 }
3491
3492-unsigned long __clear_user(void __user *addr, unsigned long n)
3493+unsigned long ___clear_user(void __user *addr, unsigned long n)
3494 {
3495 /* See rational for this in __copy_to_user() above. */
3496 if (n < 64)
3497diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3498index f7a07a5..258e1f7 100644
3499--- a/arch/arm/mach-at91/setup.c
3500+++ b/arch/arm/mach-at91/setup.c
3501@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3502
3503 desc->pfn = __phys_to_pfn(base);
3504 desc->length = length;
3505- desc->type = MT_MEMORY_RWX_NONCACHED;
3506+ desc->type = MT_MEMORY_RW_NONCACHED;
3507
3508 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3509 base, length, desc->virtual);
3510diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3511index 255f33a..507b157 100644
3512--- a/arch/arm/mach-kirkwood/common.c
3513+++ b/arch/arm/mach-kirkwood/common.c
3514@@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3515 clk_gate_ops.disable(hw);
3516 }
3517
3518-static struct clk_ops clk_gate_fn_ops;
3519+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3520+{
3521+ return clk_gate_ops.is_enabled(hw);
3522+}
3523+
3524+static struct clk_ops clk_gate_fn_ops = {
3525+ .enable = clk_gate_fn_enable,
3526+ .disable = clk_gate_fn_disable,
3527+ .is_enabled = clk_gate_fn_is_enabled,
3528+};
3529
3530 static struct clk __init *clk_register_gate_fn(struct device *dev,
3531 const char *name,
3532@@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3533 gate_fn->fn_en = fn_en;
3534 gate_fn->fn_dis = fn_dis;
3535
3536- /* ops is the gate ops, but with our enable/disable functions */
3537- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3538- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3539- clk_gate_fn_ops = clk_gate_ops;
3540- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3541- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3542- }
3543-
3544 clk = clk_register(dev, &gate_fn->gate.hw);
3545
3546 if (IS_ERR(clk))
3547diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3548index aead77a..a2253fa 100644
3549--- a/arch/arm/mach-omap2/board-n8x0.c
3550+++ b/arch/arm/mach-omap2/board-n8x0.c
3551@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3552 }
3553 #endif
3554
3555-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3556+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3557 .late_init = n8x0_menelaus_late_init,
3558 };
3559
3560diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3561index 9fe8c94..c014a4d 100644
3562--- a/arch/arm/mach-omap2/gpmc.c
3563+++ b/arch/arm/mach-omap2/gpmc.c
3564@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3565 };
3566
3567 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3568-static struct irq_chip gpmc_irq_chip;
3569 static int gpmc_irq_start;
3570
3571 static struct resource gpmc_mem_root;
3572@@ -727,6 +726,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3573
3574 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3575
3576+static struct irq_chip gpmc_irq_chip = {
3577+ .name = "gpmc",
3578+ .irq_startup = gpmc_irq_noop_ret,
3579+ .irq_enable = gpmc_irq_enable,
3580+ .irq_disable = gpmc_irq_disable,
3581+ .irq_shutdown = gpmc_irq_noop,
3582+ .irq_ack = gpmc_irq_noop,
3583+ .irq_mask = gpmc_irq_noop,
3584+ .irq_unmask = gpmc_irq_noop,
3585+
3586+};
3587+
3588 static int gpmc_setup_irq(void)
3589 {
3590 int i;
3591@@ -741,15 +752,6 @@ static int gpmc_setup_irq(void)
3592 return gpmc_irq_start;
3593 }
3594
3595- gpmc_irq_chip.name = "gpmc";
3596- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3597- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3598- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3599- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3600- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3601- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3602- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3603-
3604 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3605 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3606
3607diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3608index 667915d..2ee1219 100644
3609--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3610+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3611@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3612 int (*finish_suspend)(unsigned long cpu_state);
3613 void (*resume)(void);
3614 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3615-};
3616+} __no_const;
3617
3618 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3619 static struct powerdomain *mpuss_pd;
3620@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3621 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3622 {}
3623
3624-struct cpu_pm_ops omap_pm_ops = {
3625+static struct cpu_pm_ops omap_pm_ops __read_only = {
3626 .finish_suspend = default_finish_suspend,
3627 .resume = dummy_cpu_resume,
3628 .scu_prepare = dummy_scu_prepare,
3629diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3630index 693fe48..c15ea73 100644
3631--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3632+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3633@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3634 return NOTIFY_OK;
3635 }
3636
3637-static struct notifier_block __refdata irq_hotplug_notifier = {
3638+static struct notifier_block irq_hotplug_notifier = {
3639 .notifier_call = irq_cpu_hotplug_notify,
3640 };
3641
3642diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3643index 01ef59d..32ae28a8 100644
3644--- a/arch/arm/mach-omap2/omap_device.c
3645+++ b/arch/arm/mach-omap2/omap_device.c
3646@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3647 struct platform_device __init *omap_device_build(const char *pdev_name,
3648 int pdev_id,
3649 struct omap_hwmod *oh,
3650- void *pdata, int pdata_len)
3651+ const void *pdata, int pdata_len)
3652 {
3653 struct omap_hwmod *ohs[] = { oh };
3654
3655@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3656 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3657 int pdev_id,
3658 struct omap_hwmod **ohs,
3659- int oh_cnt, void *pdata,
3660+ int oh_cnt, const void *pdata,
3661 int pdata_len)
3662 {
3663 int ret = -ENOMEM;
3664diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3665index 78c02b3..c94109a 100644
3666--- a/arch/arm/mach-omap2/omap_device.h
3667+++ b/arch/arm/mach-omap2/omap_device.h
3668@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3669 /* Core code interface */
3670
3671 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3672- struct omap_hwmod *oh, void *pdata,
3673+ struct omap_hwmod *oh, const void *pdata,
3674 int pdata_len);
3675
3676 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3677 struct omap_hwmod **oh, int oh_cnt,
3678- void *pdata, int pdata_len);
3679+ const void *pdata, int pdata_len);
3680
3681 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3682 struct omap_hwmod **ohs, int oh_cnt);
3683diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3684index 66c60fe..c78950d 100644
3685--- a/arch/arm/mach-omap2/omap_hwmod.c
3686+++ b/arch/arm/mach-omap2/omap_hwmod.c
3687@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3688 int (*init_clkdm)(struct omap_hwmod *oh);
3689 void (*update_context_lost)(struct omap_hwmod *oh);
3690 int (*get_context_lost)(struct omap_hwmod *oh);
3691-};
3692+} __no_const;
3693
3694 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3695-static struct omap_hwmod_soc_ops soc_ops;
3696+static struct omap_hwmod_soc_ops soc_ops __read_only;
3697
3698 /* omap_hwmod_list contains all registered struct omap_hwmods */
3699 static LIST_HEAD(omap_hwmod_list);
3700diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3701index 95fee54..cfa9cf1 100644
3702--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3703+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3704@@ -10,6 +10,7 @@
3705
3706 #include <linux/kernel.h>
3707 #include <linux/init.h>
3708+#include <asm/pgtable.h>
3709
3710 #include "powerdomain.h"
3711
3712@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3713
3714 void __init am43xx_powerdomains_init(void)
3715 {
3716- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3717+ pax_open_kernel();
3718+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3719+ pax_close_kernel();
3720 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3721 pwrdm_register_pwrdms(powerdomains_am43xx);
3722 pwrdm_complete_init();
3723diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3724index d15c7bb..b2d1f0c 100644
3725--- a/arch/arm/mach-omap2/wd_timer.c
3726+++ b/arch/arm/mach-omap2/wd_timer.c
3727@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3728 struct omap_hwmod *oh;
3729 char *oh_name = "wd_timer2";
3730 char *dev_name = "omap_wdt";
3731- struct omap_wd_timer_platform_data pdata;
3732+ static struct omap_wd_timer_platform_data pdata = {
3733+ .read_reset_sources = prm_read_reset_sources
3734+ };
3735
3736 if (!cpu_class_is_omap2() || of_have_populated_dt())
3737 return 0;
3738@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3739 return -EINVAL;
3740 }
3741
3742- pdata.read_reset_sources = prm_read_reset_sources;
3743-
3744 pdev = omap_device_build(dev_name, id, oh, &pdata,
3745 sizeof(struct omap_wd_timer_platform_data));
3746 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3747diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3748index b82dcae..44ee5b6 100644
3749--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3750+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3751@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3752 bool entered_lp2 = false;
3753
3754 if (tegra_pending_sgi())
3755- ACCESS_ONCE(abort_flag) = true;
3756+ ACCESS_ONCE_RW(abort_flag) = true;
3757
3758 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3759
3760diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3761index 2dea8b5..6499da2 100644
3762--- a/arch/arm/mach-ux500/setup.h
3763+++ b/arch/arm/mach-ux500/setup.h
3764@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3765 .type = MT_DEVICE, \
3766 }
3767
3768-#define __MEM_DEV_DESC(x, sz) { \
3769- .virtual = IO_ADDRESS(x), \
3770- .pfn = __phys_to_pfn(x), \
3771- .length = sz, \
3772- .type = MT_MEMORY_RWX, \
3773-}
3774-
3775 extern struct smp_operations ux500_smp_ops;
3776 extern void ux500_cpu_die(unsigned int cpu);
3777
3778diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3779index 5bf7c3c..571e67e 100644
3780--- a/arch/arm/mm/Kconfig
3781+++ b/arch/arm/mm/Kconfig
3782@@ -446,6 +446,7 @@ config CPU_32v5
3783
3784 config CPU_32v6
3785 bool
3786+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3787 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3788
3789 config CPU_32v6K
3790@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3791
3792 config CPU_USE_DOMAINS
3793 bool
3794+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3795 help
3796 This option enables or disables the use of domain switching
3797 via the set_fs() function.
3798@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3799 config KUSER_HELPERS
3800 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3801 default y
3802+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3803 help
3804 Warning: disabling this option may break user programs.
3805
3806@@ -811,7 +814,7 @@ config KUSER_HELPERS
3807 See Documentation/arm/kernel_user_helpers.txt for details.
3808
3809 However, the fixed address nature of these helpers can be used
3810- by ROP (return orientated programming) authors when creating
3811+ by ROP (Return Oriented Programming) authors when creating
3812 exploits.
3813
3814 If all of the binaries and libraries which run on your platform
3815diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3816index 9240364..a2b8cf3 100644
3817--- a/arch/arm/mm/alignment.c
3818+++ b/arch/arm/mm/alignment.c
3819@@ -212,10 +212,12 @@ union offset_union {
3820 #define __get16_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) ? 8 : 0); \
3826 __get8_unaligned_check(ins,v,a,err); \
3827 val |= v << ((BE) ? 0 : 8); \
3828+ pax_close_userland(); \
3829 if (err) \
3830 goto fault; \
3831 } while (0)
3832@@ -229,6 +231,7 @@ union offset_union {
3833 #define __get32_unaligned_check(ins,val,addr) \
3834 do { \
3835 unsigned int err = 0, v, a = addr; \
3836+ pax_open_userland(); \
3837 __get8_unaligned_check(ins,v,a,err); \
3838 val = v << ((BE) ? 24 : 0); \
3839 __get8_unaligned_check(ins,v,a,err); \
3840@@ -237,6 +240,7 @@ union offset_union {
3841 val |= v << ((BE) ? 8 : 16); \
3842 __get8_unaligned_check(ins,v,a,err); \
3843 val |= v << ((BE) ? 0 : 24); \
3844+ pax_close_userland(); \
3845 if (err) \
3846 goto fault; \
3847 } while (0)
3848@@ -250,6 +254,7 @@ union offset_union {
3849 #define __put16_unaligned_check(ins,val,addr) \
3850 do { \
3851 unsigned int err = 0, v = val, a = addr; \
3852+ pax_open_userland(); \
3853 __asm__( FIRST_BYTE_16 \
3854 ARM( "1: "ins" %1, [%2], #1\n" ) \
3855 THUMB( "1: "ins" %1, [%2]\n" ) \
3856@@ -269,6 +274,7 @@ union offset_union {
3857 " .popsection\n" \
3858 : "=r" (err), "=&r" (v), "=&r" (a) \
3859 : "0" (err), "1" (v), "2" (a)); \
3860+ pax_close_userland(); \
3861 if (err) \
3862 goto fault; \
3863 } while (0)
3864@@ -282,6 +288,7 @@ union offset_union {
3865 #define __put32_unaligned_check(ins,val,addr) \
3866 do { \
3867 unsigned int err = 0, v = val, a = addr; \
3868+ pax_open_userland(); \
3869 __asm__( FIRST_BYTE_32 \
3870 ARM( "1: "ins" %1, [%2], #1\n" ) \
3871 THUMB( "1: "ins" %1, [%2]\n" ) \
3872@@ -311,6 +318,7 @@ union offset_union {
3873 " .popsection\n" \
3874 : "=r" (err), "=&r" (v), "=&r" (a) \
3875 : "0" (err), "1" (v), "2" (a)); \
3876+ pax_close_userland(); \
3877 if (err) \
3878 goto fault; \
3879 } while (0)
3880diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3881index 7abde2c..9df495f 100644
3882--- a/arch/arm/mm/cache-l2x0.c
3883+++ b/arch/arm/mm/cache-l2x0.c
3884@@ -46,7 +46,7 @@ struct l2x0_of_data {
3885 void (*setup)(const struct device_node *, u32 *, u32 *);
3886 void (*save)(void);
3887 struct outer_cache_fns outer_cache;
3888-};
3889+} __do_const;
3890
3891 static bool of_init = false;
3892
3893diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3894index 6eb97b3..ac509f6 100644
3895--- a/arch/arm/mm/context.c
3896+++ b/arch/arm/mm/context.c
3897@@ -43,7 +43,7 @@
3898 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3899
3900 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3901-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3902+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3903 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3904
3905 static DEFINE_PER_CPU(atomic64_t, active_asids);
3906@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3907 {
3908 static u32 cur_idx = 1;
3909 u64 asid = atomic64_read(&mm->context.id);
3910- u64 generation = atomic64_read(&asid_generation);
3911+ u64 generation = atomic64_read_unchecked(&asid_generation);
3912
3913 if (asid != 0 && is_reserved_asid(asid)) {
3914 /*
3915@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3916 */
3917 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3918 if (asid == NUM_USER_ASIDS) {
3919- generation = atomic64_add_return(ASID_FIRST_VERSION,
3920+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3921 &asid_generation);
3922 flush_context(cpu);
3923 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3924@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3925 cpu_set_reserved_ttbr0();
3926
3927 asid = atomic64_read(&mm->context.id);
3928- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3929+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3930 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3931 goto switch_mm_fastpath;
3932
3933 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3934 /* Check that our ASID belongs to the current generation. */
3935 asid = atomic64_read(&mm->context.id);
3936- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3937+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3938 asid = new_context(mm, cpu);
3939 atomic64_set(&mm->context.id, asid);
3940 }
3941diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3942index eb8830a..5360ce7 100644
3943--- a/arch/arm/mm/fault.c
3944+++ b/arch/arm/mm/fault.c
3945@@ -25,6 +25,7 @@
3946 #include <asm/system_misc.h>
3947 #include <asm/system_info.h>
3948 #include <asm/tlbflush.h>
3949+#include <asm/sections.h>
3950
3951 #include "fault.h"
3952
3953@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3954 if (fixup_exception(regs))
3955 return;
3956
3957+#ifdef CONFIG_PAX_MEMORY_UDEREF
3958+ if (addr < TASK_SIZE) {
3959+ if (current->signal->curr_ip)
3960+ 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),
3961+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3962+ else
3963+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3964+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3965+ }
3966+#endif
3967+
3968+#ifdef CONFIG_PAX_KERNEXEC
3969+ if ((fsr & FSR_WRITE) &&
3970+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3971+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3972+ {
3973+ if (current->signal->curr_ip)
3974+ 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),
3975+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3976+ else
3977+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3978+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3979+ }
3980+#endif
3981+
3982 /*
3983 * No handler, we'll have to terminate things with extreme prejudice.
3984 */
3985@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3986 }
3987 #endif
3988
3989+#ifdef CONFIG_PAX_PAGEEXEC
3990+ if (fsr & FSR_LNX_PF) {
3991+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3992+ do_group_exit(SIGKILL);
3993+ }
3994+#endif
3995+
3996 tsk->thread.address = addr;
3997 tsk->thread.error_code = fsr;
3998 tsk->thread.trap_no = 14;
3999@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4000 }
4001 #endif /* CONFIG_MMU */
4002
4003+#ifdef CONFIG_PAX_PAGEEXEC
4004+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4005+{
4006+ long i;
4007+
4008+ printk(KERN_ERR "PAX: bytes at PC: ");
4009+ for (i = 0; i < 20; i++) {
4010+ unsigned char c;
4011+ if (get_user(c, (__force unsigned char __user *)pc+i))
4012+ printk(KERN_CONT "?? ");
4013+ else
4014+ printk(KERN_CONT "%02x ", c);
4015+ }
4016+ printk("\n");
4017+
4018+ printk(KERN_ERR "PAX: bytes at SP-4: ");
4019+ for (i = -1; i < 20; i++) {
4020+ unsigned long c;
4021+ if (get_user(c, (__force unsigned long __user *)sp+i))
4022+ printk(KERN_CONT "???????? ");
4023+ else
4024+ printk(KERN_CONT "%08lx ", c);
4025+ }
4026+ printk("\n");
4027+}
4028+#endif
4029+
4030 /*
4031 * First Level Translation Fault Handler
4032 *
4033@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4034 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4035 struct siginfo info;
4036
4037+#ifdef CONFIG_PAX_MEMORY_UDEREF
4038+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4039+ if (current->signal->curr_ip)
4040+ 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),
4041+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4042+ else
4043+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4044+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4045+ goto die;
4046+ }
4047+#endif
4048+
4049 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4050 return;
4051
4052+die:
4053 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4054 inf->name, fsr, addr);
4055
4056@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4057 ifsr_info[nr].name = name;
4058 }
4059
4060+asmlinkage int sys_sigreturn(struct pt_regs *regs);
4061+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4062+
4063 asmlinkage void __exception
4064 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4065 {
4066 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4067 struct siginfo info;
4068+ unsigned long pc = instruction_pointer(regs);
4069+
4070+ if (user_mode(regs)) {
4071+ unsigned long sigpage = current->mm->context.sigpage;
4072+
4073+ if (sigpage <= pc && pc < sigpage + 7*4) {
4074+ if (pc < sigpage + 3*4)
4075+ sys_sigreturn(regs);
4076+ else
4077+ sys_rt_sigreturn(regs);
4078+ return;
4079+ }
4080+ if (pc == 0xffff0f60UL) {
4081+ /*
4082+ * PaX: __kuser_cmpxchg64 emulation
4083+ */
4084+ // TODO
4085+ //regs->ARM_pc = regs->ARM_lr;
4086+ //return;
4087+ }
4088+ if (pc == 0xffff0fa0UL) {
4089+ /*
4090+ * PaX: __kuser_memory_barrier emulation
4091+ */
4092+ // dmb(); implied by the exception
4093+ regs->ARM_pc = regs->ARM_lr;
4094+ return;
4095+ }
4096+ if (pc == 0xffff0fc0UL) {
4097+ /*
4098+ * PaX: __kuser_cmpxchg emulation
4099+ */
4100+ // TODO
4101+ //long new;
4102+ //int op;
4103+
4104+ //op = FUTEX_OP_SET << 28;
4105+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4106+ //regs->ARM_r0 = old != new;
4107+ //regs->ARM_pc = regs->ARM_lr;
4108+ //return;
4109+ }
4110+ if (pc == 0xffff0fe0UL) {
4111+ /*
4112+ * PaX: __kuser_get_tls emulation
4113+ */
4114+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4115+ regs->ARM_pc = regs->ARM_lr;
4116+ return;
4117+ }
4118+ }
4119+
4120+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4121+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4122+ if (current->signal->curr_ip)
4123+ 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),
4124+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4125+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4126+ else
4127+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4128+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4129+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4130+ goto die;
4131+ }
4132+#endif
4133+
4134+#ifdef CONFIG_PAX_REFCOUNT
4135+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4136+ unsigned int bkpt;
4137+
4138+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4139+ current->thread.error_code = ifsr;
4140+ current->thread.trap_no = 0;
4141+ pax_report_refcount_overflow(regs);
4142+ fixup_exception(regs);
4143+ return;
4144+ }
4145+ }
4146+#endif
4147
4148 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4149 return;
4150
4151+die:
4152 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4153 inf->name, ifsr, addr);
4154
4155diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4156index cf08bdf..772656c 100644
4157--- a/arch/arm/mm/fault.h
4158+++ b/arch/arm/mm/fault.h
4159@@ -3,6 +3,7 @@
4160
4161 /*
4162 * Fault status register encodings. We steal bit 31 for our own purposes.
4163+ * Set when the FSR value is from an instruction fault.
4164 */
4165 #define FSR_LNX_PF (1 << 31)
4166 #define FSR_WRITE (1 << 11)
4167@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4168 }
4169 #endif
4170
4171+/* valid for LPAE and !LPAE */
4172+static inline int is_xn_fault(unsigned int fsr)
4173+{
4174+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4175+}
4176+
4177+static inline int is_domain_fault(unsigned int fsr)
4178+{
4179+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4180+}
4181+
4182 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4183 unsigned long search_exception_table(unsigned long addr);
4184
4185diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4186index 2a77ba8..68e6a7a 100644
4187--- a/arch/arm/mm/init.c
4188+++ b/arch/arm/mm/init.c
4189@@ -30,6 +30,8 @@
4190 #include <asm/setup.h>
4191 #include <asm/tlb.h>
4192 #include <asm/fixmap.h>
4193+#include <asm/system_info.h>
4194+#include <asm/cp15.h>
4195
4196 #include <asm/mach/arch.h>
4197 #include <asm/mach/map.h>
4198@@ -627,7 +629,46 @@ void free_initmem(void)
4199 {
4200 #ifdef CONFIG_HAVE_TCM
4201 extern char __tcm_start, __tcm_end;
4202+#endif
4203
4204+#ifdef CONFIG_PAX_KERNEXEC
4205+ unsigned long addr;
4206+ pgd_t *pgd;
4207+ pud_t *pud;
4208+ pmd_t *pmd;
4209+ int cpu_arch = cpu_architecture();
4210+ unsigned int cr = get_cr();
4211+
4212+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4213+ /* make pages tables, etc before .text NX */
4214+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4215+ pgd = pgd_offset_k(addr);
4216+ pud = pud_offset(pgd, addr);
4217+ pmd = pmd_offset(pud, addr);
4218+ __section_update(pmd, addr, PMD_SECT_XN);
4219+ }
4220+ /* make init NX */
4221+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4222+ pgd = pgd_offset_k(addr);
4223+ pud = pud_offset(pgd, addr);
4224+ pmd = pmd_offset(pud, addr);
4225+ __section_update(pmd, addr, PMD_SECT_XN);
4226+ }
4227+ /* make kernel code/rodata RX */
4228+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4229+ pgd = pgd_offset_k(addr);
4230+ pud = pud_offset(pgd, addr);
4231+ pmd = pmd_offset(pud, addr);
4232+#ifdef CONFIG_ARM_LPAE
4233+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4234+#else
4235+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4236+#endif
4237+ }
4238+ }
4239+#endif
4240+
4241+#ifdef CONFIG_HAVE_TCM
4242 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4243 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4244 #endif
4245diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4246index f9c32ba..8540068 100644
4247--- a/arch/arm/mm/ioremap.c
4248+++ b/arch/arm/mm/ioremap.c
4249@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4250 unsigned int mtype;
4251
4252 if (cached)
4253- mtype = MT_MEMORY_RWX;
4254+ mtype = MT_MEMORY_RX;
4255 else
4256- mtype = MT_MEMORY_RWX_NONCACHED;
4257+ mtype = MT_MEMORY_RX_NONCACHED;
4258
4259 return __arm_ioremap_caller(phys_addr, size, mtype,
4260 __builtin_return_address(0));
4261diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4262index 5e85ed3..b10a7ed 100644
4263--- a/arch/arm/mm/mmap.c
4264+++ b/arch/arm/mm/mmap.c
4265@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4266 struct vm_area_struct *vma;
4267 int do_align = 0;
4268 int aliasing = cache_is_vipt_aliasing();
4269+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4270 struct vm_unmapped_area_info info;
4271
4272 /*
4273@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4274 if (len > TASK_SIZE)
4275 return -ENOMEM;
4276
4277+#ifdef CONFIG_PAX_RANDMMAP
4278+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4279+#endif
4280+
4281 if (addr) {
4282 if (do_align)
4283 addr = COLOUR_ALIGN(addr, pgoff);
4284@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4285 addr = PAGE_ALIGN(addr);
4286
4287 vma = find_vma(mm, addr);
4288- if (TASK_SIZE - len >= addr &&
4289- (!vma || addr + len <= vma->vm_start))
4290+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4291 return addr;
4292 }
4293
4294@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4295 info.high_limit = TASK_SIZE;
4296 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4297 info.align_offset = pgoff << PAGE_SHIFT;
4298+ info.threadstack_offset = offset;
4299 return vm_unmapped_area(&info);
4300 }
4301
4302@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4303 unsigned long addr = addr0;
4304 int do_align = 0;
4305 int aliasing = cache_is_vipt_aliasing();
4306+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4307 struct vm_unmapped_area_info info;
4308
4309 /*
4310@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4311 return addr;
4312 }
4313
4314+#ifdef CONFIG_PAX_RANDMMAP
4315+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4316+#endif
4317+
4318 /* requesting a specific address */
4319 if (addr) {
4320 if (do_align)
4321@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4322 else
4323 addr = PAGE_ALIGN(addr);
4324 vma = find_vma(mm, addr);
4325- if (TASK_SIZE - len >= addr &&
4326- (!vma || addr + len <= vma->vm_start))
4327+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4328 return addr;
4329 }
4330
4331@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4332 info.high_limit = mm->mmap_base;
4333 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4334 info.align_offset = pgoff << PAGE_SHIFT;
4335+ info.threadstack_offset = offset;
4336 addr = vm_unmapped_area(&info);
4337
4338 /*
4339@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4340 {
4341 unsigned long random_factor = 0UL;
4342
4343+#ifdef CONFIG_PAX_RANDMMAP
4344+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4345+#endif
4346+
4347 /* 8 bits of randomness in 20 address space bits */
4348 if ((current->flags & PF_RANDOMIZE) &&
4349 !(current->personality & ADDR_NO_RANDOMIZE))
4350@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4351
4352 if (mmap_is_legacy()) {
4353 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4354+
4355+#ifdef CONFIG_PAX_RANDMMAP
4356+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4357+ mm->mmap_base += mm->delta_mmap;
4358+#endif
4359+
4360 mm->get_unmapped_area = arch_get_unmapped_area;
4361 } else {
4362 mm->mmap_base = mmap_base(random_factor);
4363+
4364+#ifdef CONFIG_PAX_RANDMMAP
4365+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4366+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4367+#endif
4368+
4369 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4370 }
4371 }
4372diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4373index f15c22e..d830561 100644
4374--- a/arch/arm/mm/mmu.c
4375+++ b/arch/arm/mm/mmu.c
4376@@ -39,6 +39,22 @@
4377 #include "mm.h"
4378 #include "tcm.h"
4379
4380+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4381+void modify_domain(unsigned int dom, unsigned int type)
4382+{
4383+ struct thread_info *thread = current_thread_info();
4384+ unsigned int domain = thread->cpu_domain;
4385+ /*
4386+ * DOMAIN_MANAGER might be defined to some other value,
4387+ * use the arch-defined constant
4388+ */
4389+ domain &= ~domain_val(dom, 3);
4390+ thread->cpu_domain = domain | domain_val(dom, type);
4391+ set_domain(thread->cpu_domain);
4392+}
4393+EXPORT_SYMBOL(modify_domain);
4394+#endif
4395+
4396 /*
4397 * empty_zero_page is a special page that is used for
4398 * zero-initialized data and COW.
4399@@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4400 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4401 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4402
4403-static struct mem_type mem_types[] = {
4404+#ifdef CONFIG_PAX_KERNEXEC
4405+#define L_PTE_KERNEXEC L_PTE_RDONLY
4406+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4407+#else
4408+#define L_PTE_KERNEXEC L_PTE_DIRTY
4409+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4410+#endif
4411+
4412+static struct mem_type mem_types[] __read_only = {
4413 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4414 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4415 L_PTE_SHARED,
4416@@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4417 .prot_sect = PROT_SECT_DEVICE,
4418 .domain = DOMAIN_IO,
4419 },
4420- [MT_UNCACHED] = {
4421+ [MT_UNCACHED_RW] = {
4422 .prot_pte = PROT_PTE_DEVICE,
4423 .prot_l1 = PMD_TYPE_TABLE,
4424 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4425 .domain = DOMAIN_IO,
4426 },
4427- [MT_CACHECLEAN] = {
4428- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4429+ [MT_CACHECLEAN_RO] = {
4430+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4431 .domain = DOMAIN_KERNEL,
4432 },
4433 #ifndef CONFIG_ARM_LPAE
4434- [MT_MINICLEAN] = {
4435- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4436+ [MT_MINICLEAN_RO] = {
4437+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4438 .domain = DOMAIN_KERNEL,
4439 },
4440 #endif
4441@@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4442 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4443 L_PTE_RDONLY,
4444 .prot_l1 = PMD_TYPE_TABLE,
4445- .domain = DOMAIN_USER,
4446+ .domain = DOMAIN_VECTORS,
4447 },
4448 [MT_HIGH_VECTORS] = {
4449 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4450 L_PTE_USER | L_PTE_RDONLY,
4451 .prot_l1 = PMD_TYPE_TABLE,
4452- .domain = DOMAIN_USER,
4453+ .domain = DOMAIN_VECTORS,
4454 },
4455- [MT_MEMORY_RWX] = {
4456+ [__MT_MEMORY_RWX] = {
4457 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4458 .prot_l1 = PMD_TYPE_TABLE,
4459 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4460@@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4461 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4462 .domain = DOMAIN_KERNEL,
4463 },
4464- [MT_ROM] = {
4465- .prot_sect = PMD_TYPE_SECT,
4466+ [MT_MEMORY_RX] = {
4467+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4468+ .prot_l1 = PMD_TYPE_TABLE,
4469+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4470+ .domain = DOMAIN_KERNEL,
4471+ },
4472+ [MT_ROM_RX] = {
4473+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4474 .domain = DOMAIN_KERNEL,
4475 },
4476- [MT_MEMORY_RWX_NONCACHED] = {
4477+ [MT_MEMORY_RW_NONCACHED] = {
4478 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4479 L_PTE_MT_BUFFERABLE,
4480 .prot_l1 = PMD_TYPE_TABLE,
4481 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4482 .domain = DOMAIN_KERNEL,
4483 },
4484+ [MT_MEMORY_RX_NONCACHED] = {
4485+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4486+ L_PTE_MT_BUFFERABLE,
4487+ .prot_l1 = PMD_TYPE_TABLE,
4488+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4489+ .domain = DOMAIN_KERNEL,
4490+ },
4491 [MT_MEMORY_RW_DTCM] = {
4492 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4493 L_PTE_XN,
4494@@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4495 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4496 .domain = DOMAIN_KERNEL,
4497 },
4498- [MT_MEMORY_RWX_ITCM] = {
4499- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4500+ [MT_MEMORY_RX_ITCM] = {
4501+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4502 .prot_l1 = PMD_TYPE_TABLE,
4503+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4504 .domain = DOMAIN_KERNEL,
4505 },
4506 [MT_MEMORY_RW_SO] = {
4507@@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4508 * Mark cache clean areas and XIP ROM read only
4509 * from SVC mode and no access from userspace.
4510 */
4511- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4512- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4513- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4514+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4515+#ifdef CONFIG_PAX_KERNEXEC
4516+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4517+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4518+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4519+#endif
4520+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4521+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4522 #endif
4523
4524 if (is_smp()) {
4525@@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4526 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4527 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4528 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4529- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4530- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4531+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4532+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4533 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4534 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4535+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4536+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4537 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4538- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4539- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4540+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4541+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4542+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4543+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4544 }
4545 }
4546
4547@@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4548 if (cpu_arch >= CPU_ARCH_ARMv6) {
4549 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4550 /* Non-cacheable Normal is XCB = 001 */
4551- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4552+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4553+ PMD_SECT_BUFFERED;
4554+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4555 PMD_SECT_BUFFERED;
4556 } else {
4557 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4558- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4559+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4560+ PMD_SECT_TEX(1);
4561+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4562 PMD_SECT_TEX(1);
4563 }
4564 } else {
4565- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4566+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4567+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4568 }
4569
4570 #ifdef CONFIG_ARM_LPAE
4571@@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4572 vecs_pgprot |= PTE_EXT_AF;
4573 #endif
4574
4575+ user_pgprot |= __supported_pte_mask;
4576+
4577 for (i = 0; i < 16; i++) {
4578 pteval_t v = pgprot_val(protection_map[i]);
4579 protection_map[i] = __pgprot(v | user_pgprot);
4580@@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4581
4582 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4583 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4584- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4585- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4586+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4587+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4588 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4589 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4590+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4591+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4592 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4593- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4594- mem_types[MT_ROM].prot_sect |= cp->pmd;
4595+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4596+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4597+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4598
4599 switch (cp->pmd) {
4600 case PMD_SECT_WT:
4601- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4602+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4603 break;
4604 case PMD_SECT_WB:
4605 case PMD_SECT_WBWA:
4606- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4607+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4608 break;
4609 }
4610 pr_info("Memory policy: %sData cache %s\n",
4611@@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4612 return;
4613 }
4614
4615- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4616+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4617 md->virtual >= PAGE_OFFSET &&
4618 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4619 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4620@@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4621 * called function. This means you can't use any function or debugging
4622 * method which may touch any device, otherwise the kernel _will_ crash.
4623 */
4624+
4625+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4626+
4627 static void __init devicemaps_init(const struct machine_desc *mdesc)
4628 {
4629 struct map_desc map;
4630 unsigned long addr;
4631- void *vectors;
4632
4633- /*
4634- * Allocate the vector page early.
4635- */
4636- vectors = early_alloc(PAGE_SIZE * 2);
4637-
4638- early_trap_init(vectors);
4639+ early_trap_init(&vectors);
4640
4641 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4642 pmd_clear(pmd_off_k(addr));
4643@@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4644 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4645 map.virtual = MODULES_VADDR;
4646 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4647- map.type = MT_ROM;
4648+ map.type = MT_ROM_RX;
4649 create_mapping(&map);
4650 #endif
4651
4652@@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4653 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4654 map.virtual = FLUSH_BASE;
4655 map.length = SZ_1M;
4656- map.type = MT_CACHECLEAN;
4657+ map.type = MT_CACHECLEAN_RO;
4658 create_mapping(&map);
4659 #endif
4660 #ifdef FLUSH_BASE_MINICACHE
4661 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4662 map.virtual = FLUSH_BASE_MINICACHE;
4663 map.length = SZ_1M;
4664- map.type = MT_MINICLEAN;
4665+ map.type = MT_MINICLEAN_RO;
4666 create_mapping(&map);
4667 #endif
4668
4669@@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4670 * location (0xffff0000). If we aren't using high-vectors, also
4671 * create a mapping at the low-vectors virtual address.
4672 */
4673- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4674+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4675 map.virtual = 0xffff0000;
4676 map.length = PAGE_SIZE;
4677 #ifdef CONFIG_KUSER_HELPERS
4678@@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4679 static void __init map_lowmem(void)
4680 {
4681 struct memblock_region *reg;
4682+#ifndef CONFIG_PAX_KERNEXEC
4683 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4684 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4685+#endif
4686
4687 /* Map all the lowmem memory banks. */
4688 for_each_memblock(memory, reg) {
4689@@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4690 if (start >= end)
4691 break;
4692
4693+#ifdef CONFIG_PAX_KERNEXEC
4694+ map.pfn = __phys_to_pfn(start);
4695+ map.virtual = __phys_to_virt(start);
4696+ map.length = end - start;
4697+
4698+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4699+ struct map_desc kernel;
4700+ struct map_desc initmap;
4701+
4702+ /* when freeing initmem we will make this RW */
4703+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4704+ initmap.virtual = (unsigned long)__init_begin;
4705+ initmap.length = _sdata - __init_begin;
4706+ initmap.type = __MT_MEMORY_RWX;
4707+ create_mapping(&initmap);
4708+
4709+ /* when freeing initmem we will make this RX */
4710+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4711+ kernel.virtual = (unsigned long)_stext;
4712+ kernel.length = __init_begin - _stext;
4713+ kernel.type = __MT_MEMORY_RWX;
4714+ create_mapping(&kernel);
4715+
4716+ if (map.virtual < (unsigned long)_stext) {
4717+ map.length = (unsigned long)_stext - map.virtual;
4718+ map.type = __MT_MEMORY_RWX;
4719+ create_mapping(&map);
4720+ }
4721+
4722+ map.pfn = __phys_to_pfn(__pa(_sdata));
4723+ map.virtual = (unsigned long)_sdata;
4724+ map.length = end - __pa(_sdata);
4725+ }
4726+
4727+ map.type = MT_MEMORY_RW;
4728+ create_mapping(&map);
4729+#else
4730 if (end < kernel_x_start || start >= kernel_x_end) {
4731 map.pfn = __phys_to_pfn(start);
4732 map.virtual = __phys_to_virt(start);
4733 map.length = end - start;
4734- map.type = MT_MEMORY_RWX;
4735+ map.type = __MT_MEMORY_RWX;
4736
4737 create_mapping(&map);
4738 } else {
4739@@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4740 map.pfn = __phys_to_pfn(kernel_x_start);
4741 map.virtual = __phys_to_virt(kernel_x_start);
4742 map.length = kernel_x_end - kernel_x_start;
4743- map.type = MT_MEMORY_RWX;
4744+ map.type = __MT_MEMORY_RWX;
4745
4746 create_mapping(&map);
4747
4748@@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4749 create_mapping(&map);
4750 }
4751 }
4752+#endif
4753 }
4754 }
4755
4756diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4757index 5b217f4..c23f40e 100644
4758--- a/arch/arm/plat-iop/setup.c
4759+++ b/arch/arm/plat-iop/setup.c
4760@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4761 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4762 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4763 .length = IOP3XX_PERIPHERAL_SIZE,
4764- .type = MT_UNCACHED,
4765+ .type = MT_UNCACHED_RW,
4766 },
4767 };
4768
4769diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4770index a5bc92d..0bb4730 100644
4771--- a/arch/arm/plat-omap/sram.c
4772+++ b/arch/arm/plat-omap/sram.c
4773@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4774 * Looks like we need to preserve some bootloader code at the
4775 * beginning of SRAM for jumping to flash for reboot to work...
4776 */
4777+ pax_open_kernel();
4778 memset_io(omap_sram_base + omap_sram_skip, 0,
4779 omap_sram_size - omap_sram_skip);
4780+ pax_close_kernel();
4781 }
4782diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4783index ce6d763..cfea917 100644
4784--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4785+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4786@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4787 int (*started)(unsigned ch);
4788 int (*flush)(unsigned ch);
4789 int (*stop)(unsigned ch);
4790-};
4791+} __no_const;
4792
4793 extern void *samsung_dmadev_get_ops(void);
4794 extern void *s3c_dma_get_ops(void);
4795diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4796index 66eb764..b529b84 100644
4797--- a/arch/arm64/include/asm/barrier.h
4798+++ b/arch/arm64/include/asm/barrier.h
4799@@ -41,7 +41,7 @@
4800 do { \
4801 compiletime_assert_atomic_type(*p); \
4802 smp_mb(); \
4803- ACCESS_ONCE(*p) = (v); \
4804+ ACCESS_ONCE_RW(*p) = (v); \
4805 } while (0)
4806
4807 #define smp_load_acquire(p) \
4808diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4809index 3bf8f4e..5dd5491 100644
4810--- a/arch/arm64/include/asm/uaccess.h
4811+++ b/arch/arm64/include/asm/uaccess.h
4812@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4813 flag; \
4814 })
4815
4816+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4817 #define access_ok(type, addr, size) __range_ok(addr, size)
4818 #define user_addr_max get_fs
4819
4820diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4821index c3a58a1..78fbf54 100644
4822--- a/arch/avr32/include/asm/cache.h
4823+++ b/arch/avr32/include/asm/cache.h
4824@@ -1,8 +1,10 @@
4825 #ifndef __ASM_AVR32_CACHE_H
4826 #define __ASM_AVR32_CACHE_H
4827
4828+#include <linux/const.h>
4829+
4830 #define L1_CACHE_SHIFT 5
4831-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4832+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4833
4834 /*
4835 * Memory returned by kmalloc() may be used for DMA, so we must make
4836diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4837index d232888..87c8df1 100644
4838--- a/arch/avr32/include/asm/elf.h
4839+++ b/arch/avr32/include/asm/elf.h
4840@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4841 the loader. We need to make sure that it is out of the way of the program
4842 that it will "exec", and that there is sufficient room for the brk. */
4843
4844-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4845+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4846
4847+#ifdef CONFIG_PAX_ASLR
4848+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4849+
4850+#define PAX_DELTA_MMAP_LEN 15
4851+#define PAX_DELTA_STACK_LEN 15
4852+#endif
4853
4854 /* This yields a mask that user programs can use to figure out what
4855 instruction set this CPU supports. This could be done in user space,
4856diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4857index 479330b..53717a8 100644
4858--- a/arch/avr32/include/asm/kmap_types.h
4859+++ b/arch/avr32/include/asm/kmap_types.h
4860@@ -2,9 +2,9 @@
4861 #define __ASM_AVR32_KMAP_TYPES_H
4862
4863 #ifdef CONFIG_DEBUG_HIGHMEM
4864-# define KM_TYPE_NR 29
4865+# define KM_TYPE_NR 30
4866 #else
4867-# define KM_TYPE_NR 14
4868+# define KM_TYPE_NR 15
4869 #endif
4870
4871 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4872diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4873index 0eca933..eb78c7b 100644
4874--- a/arch/avr32/mm/fault.c
4875+++ b/arch/avr32/mm/fault.c
4876@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4877
4878 int exception_trace = 1;
4879
4880+#ifdef CONFIG_PAX_PAGEEXEC
4881+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4882+{
4883+ unsigned long i;
4884+
4885+ printk(KERN_ERR "PAX: bytes at PC: ");
4886+ for (i = 0; i < 20; i++) {
4887+ unsigned char c;
4888+ if (get_user(c, (unsigned char *)pc+i))
4889+ printk(KERN_CONT "???????? ");
4890+ else
4891+ printk(KERN_CONT "%02x ", c);
4892+ }
4893+ printk("\n");
4894+}
4895+#endif
4896+
4897 /*
4898 * This routine handles page faults. It determines the address and the
4899 * problem, and then passes it off to one of the appropriate routines.
4900@@ -176,6 +193,16 @@ bad_area:
4901 up_read(&mm->mmap_sem);
4902
4903 if (user_mode(regs)) {
4904+
4905+#ifdef CONFIG_PAX_PAGEEXEC
4906+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4907+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4908+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4909+ do_group_exit(SIGKILL);
4910+ }
4911+ }
4912+#endif
4913+
4914 if (exception_trace && printk_ratelimit())
4915 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4916 "sp %08lx ecr %lu\n",
4917diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4918index 568885a..f8008df 100644
4919--- a/arch/blackfin/include/asm/cache.h
4920+++ b/arch/blackfin/include/asm/cache.h
4921@@ -7,6 +7,7 @@
4922 #ifndef __ARCH_BLACKFIN_CACHE_H
4923 #define __ARCH_BLACKFIN_CACHE_H
4924
4925+#include <linux/const.h>
4926 #include <linux/linkage.h> /* for asmlinkage */
4927
4928 /*
4929@@ -14,7 +15,7 @@
4930 * Blackfin loads 32 bytes for cache
4931 */
4932 #define L1_CACHE_SHIFT 5
4933-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4934+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4935 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4936
4937 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4938diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4939index aea2718..3639a60 100644
4940--- a/arch/cris/include/arch-v10/arch/cache.h
4941+++ b/arch/cris/include/arch-v10/arch/cache.h
4942@@ -1,8 +1,9 @@
4943 #ifndef _ASM_ARCH_CACHE_H
4944 #define _ASM_ARCH_CACHE_H
4945
4946+#include <linux/const.h>
4947 /* Etrax 100LX have 32-byte cache-lines. */
4948-#define L1_CACHE_BYTES 32
4949 #define L1_CACHE_SHIFT 5
4950+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4951
4952 #endif /* _ASM_ARCH_CACHE_H */
4953diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4954index 7caf25d..ee65ac5 100644
4955--- a/arch/cris/include/arch-v32/arch/cache.h
4956+++ b/arch/cris/include/arch-v32/arch/cache.h
4957@@ -1,11 +1,12 @@
4958 #ifndef _ASM_CRIS_ARCH_CACHE_H
4959 #define _ASM_CRIS_ARCH_CACHE_H
4960
4961+#include <linux/const.h>
4962 #include <arch/hwregs/dma.h>
4963
4964 /* A cache-line is 32 bytes. */
4965-#define L1_CACHE_BYTES 32
4966 #define L1_CACHE_SHIFT 5
4967+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4968
4969 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4970
4971diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4972index b86329d..6709906 100644
4973--- a/arch/frv/include/asm/atomic.h
4974+++ b/arch/frv/include/asm/atomic.h
4975@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4976 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4977 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4978
4979+#define atomic64_read_unchecked(v) atomic64_read(v)
4980+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4981+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4982+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4983+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4984+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4985+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4986+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4987+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4988+
4989 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4990 {
4991 int c, old;
4992diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4993index 2797163..c2a401d 100644
4994--- a/arch/frv/include/asm/cache.h
4995+++ b/arch/frv/include/asm/cache.h
4996@@ -12,10 +12,11 @@
4997 #ifndef __ASM_CACHE_H
4998 #define __ASM_CACHE_H
4999
5000+#include <linux/const.h>
5001
5002 /* bytes per L1 cache line */
5003 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5004-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5005+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5006
5007 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5008 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5009diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5010index 43901f2..0d8b865 100644
5011--- a/arch/frv/include/asm/kmap_types.h
5012+++ b/arch/frv/include/asm/kmap_types.h
5013@@ -2,6 +2,6 @@
5014 #ifndef _ASM_KMAP_TYPES_H
5015 #define _ASM_KMAP_TYPES_H
5016
5017-#define KM_TYPE_NR 17
5018+#define KM_TYPE_NR 18
5019
5020 #endif
5021diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5022index 836f147..4cf23f5 100644
5023--- a/arch/frv/mm/elf-fdpic.c
5024+++ b/arch/frv/mm/elf-fdpic.c
5025@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5026 {
5027 struct vm_area_struct *vma;
5028 struct vm_unmapped_area_info info;
5029+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5030
5031 if (len > TASK_SIZE)
5032 return -ENOMEM;
5033@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5034 if (addr) {
5035 addr = PAGE_ALIGN(addr);
5036 vma = find_vma(current->mm, addr);
5037- if (TASK_SIZE - len >= addr &&
5038- (!vma || addr + len <= vma->vm_start))
5039+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5040 goto success;
5041 }
5042
5043@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5044 info.high_limit = (current->mm->start_stack - 0x00200000);
5045 info.align_mask = 0;
5046 info.align_offset = 0;
5047+ info.threadstack_offset = offset;
5048 addr = vm_unmapped_area(&info);
5049 if (!(addr & ~PAGE_MASK))
5050 goto success;
5051diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5052index f4ca594..adc72fd6 100644
5053--- a/arch/hexagon/include/asm/cache.h
5054+++ b/arch/hexagon/include/asm/cache.h
5055@@ -21,9 +21,11 @@
5056 #ifndef __ASM_CACHE_H
5057 #define __ASM_CACHE_H
5058
5059+#include <linux/const.h>
5060+
5061 /* Bytes per L1 cache line */
5062-#define L1_CACHE_SHIFT (5)
5063-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5064+#define L1_CACHE_SHIFT 5
5065+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5066
5067 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5068 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5069diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5070index 12c3afe..b1abab2 100644
5071--- a/arch/ia64/Kconfig
5072+++ b/arch/ia64/Kconfig
5073@@ -546,6 +546,7 @@ source "drivers/sn/Kconfig"
5074 config KEXEC
5075 bool "kexec system call"
5076 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5077+ depends on !GRKERNSEC_KMEM
5078 help
5079 kexec is a system call that implements the ability to shutdown your
5080 current kernel, and to start another kernel. It is like a reboot
5081diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5082index 6e6fe18..a6ae668 100644
5083--- a/arch/ia64/include/asm/atomic.h
5084+++ b/arch/ia64/include/asm/atomic.h
5085@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5086 #define atomic64_inc(v) atomic64_add(1, (v))
5087 #define atomic64_dec(v) atomic64_sub(1, (v))
5088
5089+#define atomic64_read_unchecked(v) atomic64_read(v)
5090+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5091+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5092+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5093+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5094+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5095+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5096+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5097+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5098+
5099 /* Atomic operations are already serializing */
5100 #define smp_mb__before_atomic_dec() barrier()
5101 #define smp_mb__after_atomic_dec() barrier()
5102diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5103index d0a69aa..142f878 100644
5104--- a/arch/ia64/include/asm/barrier.h
5105+++ b/arch/ia64/include/asm/barrier.h
5106@@ -64,7 +64,7 @@
5107 do { \
5108 compiletime_assert_atomic_type(*p); \
5109 barrier(); \
5110- ACCESS_ONCE(*p) = (v); \
5111+ ACCESS_ONCE_RW(*p) = (v); \
5112 } while (0)
5113
5114 #define smp_load_acquire(p) \
5115diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5116index 988254a..e1ee885 100644
5117--- a/arch/ia64/include/asm/cache.h
5118+++ b/arch/ia64/include/asm/cache.h
5119@@ -1,6 +1,7 @@
5120 #ifndef _ASM_IA64_CACHE_H
5121 #define _ASM_IA64_CACHE_H
5122
5123+#include <linux/const.h>
5124
5125 /*
5126 * Copyright (C) 1998-2000 Hewlett-Packard Co
5127@@ -9,7 +10,7 @@
5128
5129 /* Bytes per L1 (data) cache line. */
5130 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5131-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5132+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5133
5134 #ifdef CONFIG_SMP
5135 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5136diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5137index 5a83c5c..4d7f553 100644
5138--- a/arch/ia64/include/asm/elf.h
5139+++ b/arch/ia64/include/asm/elf.h
5140@@ -42,6 +42,13 @@
5141 */
5142 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5143
5144+#ifdef CONFIG_PAX_ASLR
5145+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5146+
5147+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5148+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5149+#endif
5150+
5151 #define PT_IA_64_UNWIND 0x70000001
5152
5153 /* IA-64 relocations: */
5154diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5155index 5767cdf..7462574 100644
5156--- a/arch/ia64/include/asm/pgalloc.h
5157+++ b/arch/ia64/include/asm/pgalloc.h
5158@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5159 pgd_val(*pgd_entry) = __pa(pud);
5160 }
5161
5162+static inline void
5163+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5164+{
5165+ pgd_populate(mm, pgd_entry, pud);
5166+}
5167+
5168 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5169 {
5170 return quicklist_alloc(0, GFP_KERNEL, NULL);
5171@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5172 pud_val(*pud_entry) = __pa(pmd);
5173 }
5174
5175+static inline void
5176+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5177+{
5178+ pud_populate(mm, pud_entry, pmd);
5179+}
5180+
5181 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5182 {
5183 return quicklist_alloc(0, GFP_KERNEL, NULL);
5184diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5185index 7935115..c0eca6a 100644
5186--- a/arch/ia64/include/asm/pgtable.h
5187+++ b/arch/ia64/include/asm/pgtable.h
5188@@ -12,7 +12,7 @@
5189 * David Mosberger-Tang <davidm@hpl.hp.com>
5190 */
5191
5192-
5193+#include <linux/const.h>
5194 #include <asm/mman.h>
5195 #include <asm/page.h>
5196 #include <asm/processor.h>
5197@@ -142,6 +142,17 @@
5198 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5199 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5200 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5201+
5202+#ifdef CONFIG_PAX_PAGEEXEC
5203+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5204+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5205+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5206+#else
5207+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5208+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5209+# define PAGE_COPY_NOEXEC PAGE_COPY
5210+#endif
5211+
5212 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5213 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5214 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5215diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5216index 45698cd..e8e2dbc 100644
5217--- a/arch/ia64/include/asm/spinlock.h
5218+++ b/arch/ia64/include/asm/spinlock.h
5219@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5220 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5221
5222 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5223- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5224+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5225 }
5226
5227 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5228diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5229index 449c8c0..3d4b1e9 100644
5230--- a/arch/ia64/include/asm/uaccess.h
5231+++ b/arch/ia64/include/asm/uaccess.h
5232@@ -70,6 +70,7 @@
5233 && ((segment).seg == KERNEL_DS.seg \
5234 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5235 })
5236+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5237 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5238
5239 /*
5240@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5241 static inline unsigned long
5242 __copy_to_user (void __user *to, const void *from, unsigned long count)
5243 {
5244+ if (count > INT_MAX)
5245+ return count;
5246+
5247+ if (!__builtin_constant_p(count))
5248+ check_object_size(from, count, true);
5249+
5250 return __copy_user(to, (__force void __user *) from, count);
5251 }
5252
5253 static inline unsigned long
5254 __copy_from_user (void *to, const void __user *from, unsigned long count)
5255 {
5256+ if (count > INT_MAX)
5257+ return count;
5258+
5259+ if (!__builtin_constant_p(count))
5260+ check_object_size(to, count, false);
5261+
5262 return __copy_user((__force void __user *) to, from, count);
5263 }
5264
5265@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5266 ({ \
5267 void __user *__cu_to = (to); \
5268 const void *__cu_from = (from); \
5269- long __cu_len = (n); \
5270+ unsigned long __cu_len = (n); \
5271 \
5272- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5273+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5274+ if (!__builtin_constant_p(n)) \
5275+ check_object_size(__cu_from, __cu_len, true); \
5276 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5277+ } \
5278 __cu_len; \
5279 })
5280
5281@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5282 ({ \
5283 void *__cu_to = (to); \
5284 const void __user *__cu_from = (from); \
5285- long __cu_len = (n); \
5286+ unsigned long __cu_len = (n); \
5287 \
5288 __chk_user_ptr(__cu_from); \
5289- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5290+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5291+ if (!__builtin_constant_p(n)) \
5292+ check_object_size(__cu_to, __cu_len, false); \
5293 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5294+ } \
5295 __cu_len; \
5296 })
5297
5298diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5299index 24603be..948052d 100644
5300--- a/arch/ia64/kernel/module.c
5301+++ b/arch/ia64/kernel/module.c
5302@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5303 void
5304 module_free (struct module *mod, void *module_region)
5305 {
5306- if (mod && mod->arch.init_unw_table &&
5307- module_region == mod->module_init) {
5308+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5309 unw_remove_unwind_table(mod->arch.init_unw_table);
5310 mod->arch.init_unw_table = NULL;
5311 }
5312@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5313 }
5314
5315 static inline int
5316+in_init_rx (const struct module *mod, uint64_t addr)
5317+{
5318+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5319+}
5320+
5321+static inline int
5322+in_init_rw (const struct module *mod, uint64_t addr)
5323+{
5324+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5325+}
5326+
5327+static inline int
5328 in_init (const struct module *mod, uint64_t addr)
5329 {
5330- return addr - (uint64_t) mod->module_init < mod->init_size;
5331+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5332+}
5333+
5334+static inline int
5335+in_core_rx (const struct module *mod, uint64_t addr)
5336+{
5337+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5338+}
5339+
5340+static inline int
5341+in_core_rw (const struct module *mod, uint64_t addr)
5342+{
5343+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5344 }
5345
5346 static inline int
5347 in_core (const struct module *mod, uint64_t addr)
5348 {
5349- return addr - (uint64_t) mod->module_core < mod->core_size;
5350+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5351 }
5352
5353 static inline int
5354@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5355 break;
5356
5357 case RV_BDREL:
5358- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5359+ if (in_init_rx(mod, val))
5360+ val -= (uint64_t) mod->module_init_rx;
5361+ else if (in_init_rw(mod, val))
5362+ val -= (uint64_t) mod->module_init_rw;
5363+ else if (in_core_rx(mod, val))
5364+ val -= (uint64_t) mod->module_core_rx;
5365+ else if (in_core_rw(mod, val))
5366+ val -= (uint64_t) mod->module_core_rw;
5367 break;
5368
5369 case RV_LTV:
5370@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5371 * addresses have been selected...
5372 */
5373 uint64_t gp;
5374- if (mod->core_size > MAX_LTOFF)
5375+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5376 /*
5377 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5378 * at the end of the module.
5379 */
5380- gp = mod->core_size - MAX_LTOFF / 2;
5381+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5382 else
5383- gp = mod->core_size / 2;
5384- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5385+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5386+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5387 mod->arch.gp = gp;
5388 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5389 }
5390diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5391index c39c3cd..3c77738 100644
5392--- a/arch/ia64/kernel/palinfo.c
5393+++ b/arch/ia64/kernel/palinfo.c
5394@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5395 return NOTIFY_OK;
5396 }
5397
5398-static struct notifier_block __refdata palinfo_cpu_notifier =
5399+static struct notifier_block palinfo_cpu_notifier =
5400 {
5401 .notifier_call = palinfo_cpu_callback,
5402 .priority = 0,
5403diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5404index 41e33f8..65180b2a 100644
5405--- a/arch/ia64/kernel/sys_ia64.c
5406+++ b/arch/ia64/kernel/sys_ia64.c
5407@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5408 unsigned long align_mask = 0;
5409 struct mm_struct *mm = current->mm;
5410 struct vm_unmapped_area_info info;
5411+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5412
5413 if (len > RGN_MAP_LIMIT)
5414 return -ENOMEM;
5415@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5416 if (REGION_NUMBER(addr) == RGN_HPAGE)
5417 addr = 0;
5418 #endif
5419+
5420+#ifdef CONFIG_PAX_RANDMMAP
5421+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5422+ addr = mm->free_area_cache;
5423+ else
5424+#endif
5425+
5426 if (!addr)
5427 addr = TASK_UNMAPPED_BASE;
5428
5429@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5430 info.high_limit = TASK_SIZE;
5431 info.align_mask = align_mask;
5432 info.align_offset = 0;
5433+ info.threadstack_offset = offset;
5434 return vm_unmapped_area(&info);
5435 }
5436
5437diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5438index 84f8a52..7c76178 100644
5439--- a/arch/ia64/kernel/vmlinux.lds.S
5440+++ b/arch/ia64/kernel/vmlinux.lds.S
5441@@ -192,7 +192,7 @@ SECTIONS {
5442 /* Per-cpu data: */
5443 . = ALIGN(PERCPU_PAGE_SIZE);
5444 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5445- __phys_per_cpu_start = __per_cpu_load;
5446+ __phys_per_cpu_start = per_cpu_load;
5447 /*
5448 * ensure percpu data fits
5449 * into percpu page size
5450diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5451index 7225dad..2a7c8256 100644
5452--- a/arch/ia64/mm/fault.c
5453+++ b/arch/ia64/mm/fault.c
5454@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5455 return pte_present(pte);
5456 }
5457
5458+#ifdef CONFIG_PAX_PAGEEXEC
5459+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5460+{
5461+ unsigned long i;
5462+
5463+ printk(KERN_ERR "PAX: bytes at PC: ");
5464+ for (i = 0; i < 8; i++) {
5465+ unsigned int c;
5466+ if (get_user(c, (unsigned int *)pc+i))
5467+ printk(KERN_CONT "???????? ");
5468+ else
5469+ printk(KERN_CONT "%08x ", c);
5470+ }
5471+ printk("\n");
5472+}
5473+#endif
5474+
5475 # define VM_READ_BIT 0
5476 # define VM_WRITE_BIT 1
5477 # define VM_EXEC_BIT 2
5478@@ -151,8 +168,21 @@ retry:
5479 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5480 goto bad_area;
5481
5482- if ((vma->vm_flags & mask) != mask)
5483+ if ((vma->vm_flags & mask) != mask) {
5484+
5485+#ifdef CONFIG_PAX_PAGEEXEC
5486+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5487+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5488+ goto bad_area;
5489+
5490+ up_read(&mm->mmap_sem);
5491+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5492+ do_group_exit(SIGKILL);
5493+ }
5494+#endif
5495+
5496 goto bad_area;
5497+ }
5498
5499 /*
5500 * If for any reason at all we couldn't handle the fault, make
5501diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5502index 76069c1..c2aa816 100644
5503--- a/arch/ia64/mm/hugetlbpage.c
5504+++ b/arch/ia64/mm/hugetlbpage.c
5505@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5506 unsigned long pgoff, unsigned long flags)
5507 {
5508 struct vm_unmapped_area_info info;
5509+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5510
5511 if (len > RGN_MAP_LIMIT)
5512 return -ENOMEM;
5513@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5514 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5515 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5516 info.align_offset = 0;
5517+ info.threadstack_offset = offset;
5518 return vm_unmapped_area(&info);
5519 }
5520
5521diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5522index 25c3502..560dae7 100644
5523--- a/arch/ia64/mm/init.c
5524+++ b/arch/ia64/mm/init.c
5525@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5526 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5527 vma->vm_end = vma->vm_start + PAGE_SIZE;
5528 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5529+
5530+#ifdef CONFIG_PAX_PAGEEXEC
5531+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5532+ vma->vm_flags &= ~VM_EXEC;
5533+
5534+#ifdef CONFIG_PAX_MPROTECT
5535+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5536+ vma->vm_flags &= ~VM_MAYEXEC;
5537+#endif
5538+
5539+ }
5540+#endif
5541+
5542 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5543 down_write(&current->mm->mmap_sem);
5544 if (insert_vm_struct(current->mm, vma)) {
5545diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5546index 40b3ee9..8c2c112 100644
5547--- a/arch/m32r/include/asm/cache.h
5548+++ b/arch/m32r/include/asm/cache.h
5549@@ -1,8 +1,10 @@
5550 #ifndef _ASM_M32R_CACHE_H
5551 #define _ASM_M32R_CACHE_H
5552
5553+#include <linux/const.h>
5554+
5555 /* L1 cache line size */
5556 #define L1_CACHE_SHIFT 4
5557-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5558+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5559
5560 #endif /* _ASM_M32R_CACHE_H */
5561diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5562index 82abd15..d95ae5d 100644
5563--- a/arch/m32r/lib/usercopy.c
5564+++ b/arch/m32r/lib/usercopy.c
5565@@ -14,6 +14,9 @@
5566 unsigned long
5567 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5568 {
5569+ if ((long)n < 0)
5570+ return n;
5571+
5572 prefetch(from);
5573 if (access_ok(VERIFY_WRITE, to, n))
5574 __copy_user(to,from,n);
5575@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5576 unsigned long
5577 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5578 {
5579+ if ((long)n < 0)
5580+ return n;
5581+
5582 prefetchw(to);
5583 if (access_ok(VERIFY_READ, from, n))
5584 __copy_user_zeroing(to,from,n);
5585diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5586index 0395c51..5f26031 100644
5587--- a/arch/m68k/include/asm/cache.h
5588+++ b/arch/m68k/include/asm/cache.h
5589@@ -4,9 +4,11 @@
5590 #ifndef __ARCH_M68K_CACHE_H
5591 #define __ARCH_M68K_CACHE_H
5592
5593+#include <linux/const.h>
5594+
5595 /* bytes per L1 cache line */
5596 #define L1_CACHE_SHIFT 4
5597-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5598+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5599
5600 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5601
5602diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5603index 2d6f0de..de5f5ac 100644
5604--- a/arch/metag/include/asm/barrier.h
5605+++ b/arch/metag/include/asm/barrier.h
5606@@ -89,7 +89,7 @@ static inline void fence(void)
5607 do { \
5608 compiletime_assert_atomic_type(*p); \
5609 smp_mb(); \
5610- ACCESS_ONCE(*p) = (v); \
5611+ ACCESS_ONCE_RW(*p) = (v); \
5612 } while (0)
5613
5614 #define smp_load_acquire(p) \
5615diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5616index 3c52fa6..11b2ad8 100644
5617--- a/arch/metag/mm/hugetlbpage.c
5618+++ b/arch/metag/mm/hugetlbpage.c
5619@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5620 info.high_limit = TASK_SIZE;
5621 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5622 info.align_offset = 0;
5623+ info.threadstack_offset = 0;
5624 return vm_unmapped_area(&info);
5625 }
5626
5627diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5628index 4efe96a..60e8699 100644
5629--- a/arch/microblaze/include/asm/cache.h
5630+++ b/arch/microblaze/include/asm/cache.h
5631@@ -13,11 +13,12 @@
5632 #ifndef _ASM_MICROBLAZE_CACHE_H
5633 #define _ASM_MICROBLAZE_CACHE_H
5634
5635+#include <linux/const.h>
5636 #include <asm/registers.h>
5637
5638 #define L1_CACHE_SHIFT 5
5639 /* word-granular cache in microblaze */
5640-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5641+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5642
5643 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5644
5645diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5646index 5cd695f..9a24ad0 100644
5647--- a/arch/mips/Kconfig
5648+++ b/arch/mips/Kconfig
5649@@ -2395,6 +2395,7 @@ source "kernel/Kconfig.preempt"
5650
5651 config KEXEC
5652 bool "Kexec system call"
5653+ depends on !GRKERNSEC_KMEM
5654 help
5655 kexec is a system call that implements the ability to shutdown your
5656 current kernel, and to start another kernel. It is like a reboot
5657diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5658index 02f2444..506969c 100644
5659--- a/arch/mips/cavium-octeon/dma-octeon.c
5660+++ b/arch/mips/cavium-octeon/dma-octeon.c
5661@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5662 if (dma_release_from_coherent(dev, order, vaddr))
5663 return;
5664
5665- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5666+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5667 }
5668
5669 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5670diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5671index e8eb3d5..2e665d1 100644
5672--- a/arch/mips/include/asm/atomic.h
5673+++ b/arch/mips/include/asm/atomic.h
5674@@ -21,15 +21,39 @@
5675 #include <asm/cmpxchg.h>
5676 #include <asm/war.h>
5677
5678+#ifdef CONFIG_GENERIC_ATOMIC64
5679+#include <asm-generic/atomic64.h>
5680+#endif
5681+
5682 #define ATOMIC_INIT(i) { (i) }
5683
5684+#ifdef CONFIG_64BIT
5685+#define _ASM_EXTABLE(from, to) \
5686+" .section __ex_table,\"a\"\n" \
5687+" .dword " #from ", " #to"\n" \
5688+" .previous\n"
5689+#else
5690+#define _ASM_EXTABLE(from, to) \
5691+" .section __ex_table,\"a\"\n" \
5692+" .word " #from ", " #to"\n" \
5693+" .previous\n"
5694+#endif
5695+
5696 /*
5697 * atomic_read - read atomic variable
5698 * @v: pointer of type atomic_t
5699 *
5700 * Atomically reads the value of @v.
5701 */
5702-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5703+static inline int atomic_read(const atomic_t *v)
5704+{
5705+ return (*(volatile const int *) &v->counter);
5706+}
5707+
5708+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5709+{
5710+ return (*(volatile const int *) &v->counter);
5711+}
5712
5713 /*
5714 * atomic_set - set atomic variable
5715@@ -38,7 +62,15 @@
5716 *
5717 * Atomically sets the value of @v to @i.
5718 */
5719-#define atomic_set(v, i) ((v)->counter = (i))
5720+static inline void atomic_set(atomic_t *v, int i)
5721+{
5722+ v->counter = i;
5723+}
5724+
5725+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5726+{
5727+ v->counter = i;
5728+}
5729
5730 /*
5731 * atomic_add - add integer to atomic variable
5732@@ -47,7 +79,67 @@
5733 *
5734 * Atomically adds @i to @v.
5735 */
5736-static __inline__ void atomic_add(int i, atomic_t * v)
5737+static __inline__ void atomic_add(int i, atomic_t *v)
5738+{
5739+ int temp;
5740+
5741+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5742+ __asm__ __volatile__(
5743+ " .set mips3 \n"
5744+ "1: ll %0, %1 # atomic_add \n"
5745+#ifdef CONFIG_PAX_REFCOUNT
5746+ /* Exception on overflow. */
5747+ "2: add %0, %2 \n"
5748+#else
5749+ " addu %0, %2 \n"
5750+#endif
5751+ " sc %0, %1 \n"
5752+ " beqzl %0, 1b \n"
5753+#ifdef CONFIG_PAX_REFCOUNT
5754+ "3: \n"
5755+ _ASM_EXTABLE(2b, 3b)
5756+#endif
5757+ " .set mips0 \n"
5758+ : "=&r" (temp), "+m" (v->counter)
5759+ : "Ir" (i));
5760+ } else if (kernel_uses_llsc) {
5761+ __asm__ __volatile__(
5762+ " .set mips3 \n"
5763+ "1: ll %0, %1 # atomic_add \n"
5764+#ifdef CONFIG_PAX_REFCOUNT
5765+ /* Exception on overflow. */
5766+ "2: add %0, %2 \n"
5767+#else
5768+ " addu %0, %2 \n"
5769+#endif
5770+ " sc %0, %1 \n"
5771+ " beqz %0, 1b \n"
5772+#ifdef CONFIG_PAX_REFCOUNT
5773+ "3: \n"
5774+ _ASM_EXTABLE(2b, 3b)
5775+#endif
5776+ " .set mips0 \n"
5777+ : "=&r" (temp), "+m" (v->counter)
5778+ : "Ir" (i));
5779+ } else {
5780+ unsigned long flags;
5781+
5782+ raw_local_irq_save(flags);
5783+ __asm__ __volatile__(
5784+#ifdef CONFIG_PAX_REFCOUNT
5785+ /* Exception on overflow. */
5786+ "1: add %0, %1 \n"
5787+ "2: \n"
5788+ _ASM_EXTABLE(1b, 2b)
5789+#else
5790+ " addu %0, %1 \n"
5791+#endif
5792+ : "+r" (v->counter) : "Ir" (i));
5793+ raw_local_irq_restore(flags);
5794+ }
5795+}
5796+
5797+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5798 {
5799 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5800 int temp;
5801@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5802 *
5803 * Atomically subtracts @i from @v.
5804 */
5805-static __inline__ void atomic_sub(int i, atomic_t * v)
5806+static __inline__ void atomic_sub(int i, atomic_t *v)
5807+{
5808+ int temp;
5809+
5810+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5811+ __asm__ __volatile__(
5812+ " .set mips3 \n"
5813+ "1: ll %0, %1 # atomic64_sub \n"
5814+#ifdef CONFIG_PAX_REFCOUNT
5815+ /* Exception on overflow. */
5816+ "2: sub %0, %2 \n"
5817+#else
5818+ " subu %0, %2 \n"
5819+#endif
5820+ " sc %0, %1 \n"
5821+ " beqzl %0, 1b \n"
5822+#ifdef CONFIG_PAX_REFCOUNT
5823+ "3: \n"
5824+ _ASM_EXTABLE(2b, 3b)
5825+#endif
5826+ " .set mips0 \n"
5827+ : "=&r" (temp), "+m" (v->counter)
5828+ : "Ir" (i));
5829+ } else if (kernel_uses_llsc) {
5830+ __asm__ __volatile__(
5831+ " .set mips3 \n"
5832+ "1: ll %0, %1 # atomic64_sub \n"
5833+#ifdef CONFIG_PAX_REFCOUNT
5834+ /* Exception on overflow. */
5835+ "2: sub %0, %2 \n"
5836+#else
5837+ " subu %0, %2 \n"
5838+#endif
5839+ " sc %0, %1 \n"
5840+ " beqz %0, 1b \n"
5841+#ifdef CONFIG_PAX_REFCOUNT
5842+ "3: \n"
5843+ _ASM_EXTABLE(2b, 3b)
5844+#endif
5845+ " .set mips0 \n"
5846+ : "=&r" (temp), "+m" (v->counter)
5847+ : "Ir" (i));
5848+ } else {
5849+ unsigned long flags;
5850+
5851+ raw_local_irq_save(flags);
5852+ __asm__ __volatile__(
5853+#ifdef CONFIG_PAX_REFCOUNT
5854+ /* Exception on overflow. */
5855+ "1: sub %0, %1 \n"
5856+ "2: \n"
5857+ _ASM_EXTABLE(1b, 2b)
5858+#else
5859+ " subu %0, %1 \n"
5860+#endif
5861+ : "+r" (v->counter) : "Ir" (i));
5862+ raw_local_irq_restore(flags);
5863+ }
5864+}
5865+
5866+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5867 {
5868 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5869 int temp;
5870@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5871 /*
5872 * Same as above, but return the result value
5873 */
5874-static __inline__ int atomic_add_return(int i, atomic_t * v)
5875+static __inline__ int atomic_add_return(int i, atomic_t *v)
5876+{
5877+ int result;
5878+ int temp;
5879+
5880+ smp_mb__before_llsc();
5881+
5882+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5883+ __asm__ __volatile__(
5884+ " .set mips3 \n"
5885+ "1: ll %1, %2 # atomic_add_return \n"
5886+#ifdef CONFIG_PAX_REFCOUNT
5887+ "2: add %0, %1, %3 \n"
5888+#else
5889+ " addu %0, %1, %3 \n"
5890+#endif
5891+ " sc %0, %2 \n"
5892+ " beqzl %0, 1b \n"
5893+#ifdef CONFIG_PAX_REFCOUNT
5894+ " b 4f \n"
5895+ " .set noreorder \n"
5896+ "3: b 5f \n"
5897+ " move %0, %1 \n"
5898+ " .set reorder \n"
5899+ _ASM_EXTABLE(2b, 3b)
5900+#endif
5901+ "4: addu %0, %1, %3 \n"
5902+#ifdef CONFIG_PAX_REFCOUNT
5903+ "5: \n"
5904+#endif
5905+ " .set mips0 \n"
5906+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5907+ : "Ir" (i));
5908+ } else if (kernel_uses_llsc) {
5909+ __asm__ __volatile__(
5910+ " .set mips3 \n"
5911+ "1: ll %1, %2 # atomic_add_return \n"
5912+#ifdef CONFIG_PAX_REFCOUNT
5913+ "2: add %0, %1, %3 \n"
5914+#else
5915+ " addu %0, %1, %3 \n"
5916+#endif
5917+ " sc %0, %2 \n"
5918+ " bnez %0, 4f \n"
5919+ " b 1b \n"
5920+#ifdef CONFIG_PAX_REFCOUNT
5921+ " .set noreorder \n"
5922+ "3: b 5f \n"
5923+ " move %0, %1 \n"
5924+ " .set reorder \n"
5925+ _ASM_EXTABLE(2b, 3b)
5926+#endif
5927+ "4: addu %0, %1, %3 \n"
5928+#ifdef CONFIG_PAX_REFCOUNT
5929+ "5: \n"
5930+#endif
5931+ " .set mips0 \n"
5932+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5933+ : "Ir" (i));
5934+ } else {
5935+ unsigned long flags;
5936+
5937+ raw_local_irq_save(flags);
5938+ __asm__ __volatile__(
5939+ " lw %0, %1 \n"
5940+#ifdef CONFIG_PAX_REFCOUNT
5941+ /* Exception on overflow. */
5942+ "1: add %0, %2 \n"
5943+#else
5944+ " addu %0, %2 \n"
5945+#endif
5946+ " sw %0, %1 \n"
5947+#ifdef CONFIG_PAX_REFCOUNT
5948+ /* Note: Dest reg is not modified on overflow */
5949+ "2: \n"
5950+ _ASM_EXTABLE(1b, 2b)
5951+#endif
5952+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5953+ raw_local_irq_restore(flags);
5954+ }
5955+
5956+ smp_llsc_mb();
5957+
5958+ return result;
5959+}
5960+
5961+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5962 {
5963 int result;
5964
5965@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5966 return result;
5967 }
5968
5969-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5970+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5971+{
5972+ int result;
5973+ int temp;
5974+
5975+ smp_mb__before_llsc();
5976+
5977+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5978+ __asm__ __volatile__(
5979+ " .set mips3 \n"
5980+ "1: ll %1, %2 # atomic_sub_return \n"
5981+#ifdef CONFIG_PAX_REFCOUNT
5982+ "2: sub %0, %1, %3 \n"
5983+#else
5984+ " subu %0, %1, %3 \n"
5985+#endif
5986+ " sc %0, %2 \n"
5987+ " beqzl %0, 1b \n"
5988+#ifdef CONFIG_PAX_REFCOUNT
5989+ " b 4f \n"
5990+ " .set noreorder \n"
5991+ "3: b 5f \n"
5992+ " move %0, %1 \n"
5993+ " .set reorder \n"
5994+ _ASM_EXTABLE(2b, 3b)
5995+#endif
5996+ "4: subu %0, %1, %3 \n"
5997+#ifdef CONFIG_PAX_REFCOUNT
5998+ "5: \n"
5999+#endif
6000+ " .set mips0 \n"
6001+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6002+ : "Ir" (i), "m" (v->counter)
6003+ : "memory");
6004+ } else if (kernel_uses_llsc) {
6005+ __asm__ __volatile__(
6006+ " .set mips3 \n"
6007+ "1: ll %1, %2 # atomic_sub_return \n"
6008+#ifdef CONFIG_PAX_REFCOUNT
6009+ "2: sub %0, %1, %3 \n"
6010+#else
6011+ " subu %0, %1, %3 \n"
6012+#endif
6013+ " sc %0, %2 \n"
6014+ " bnez %0, 4f \n"
6015+ " b 1b \n"
6016+#ifdef CONFIG_PAX_REFCOUNT
6017+ " .set noreorder \n"
6018+ "3: b 5f \n"
6019+ " move %0, %1 \n"
6020+ " .set reorder \n"
6021+ _ASM_EXTABLE(2b, 3b)
6022+#endif
6023+ "4: subu %0, %1, %3 \n"
6024+#ifdef CONFIG_PAX_REFCOUNT
6025+ "5: \n"
6026+#endif
6027+ " .set mips0 \n"
6028+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6029+ : "Ir" (i));
6030+ } else {
6031+ unsigned long flags;
6032+
6033+ raw_local_irq_save(flags);
6034+ __asm__ __volatile__(
6035+ " lw %0, %1 \n"
6036+#ifdef CONFIG_PAX_REFCOUNT
6037+ /* Exception on overflow. */
6038+ "1: sub %0, %2 \n"
6039+#else
6040+ " subu %0, %2 \n"
6041+#endif
6042+ " sw %0, %1 \n"
6043+#ifdef CONFIG_PAX_REFCOUNT
6044+ /* Note: Dest reg is not modified on overflow */
6045+ "2: \n"
6046+ _ASM_EXTABLE(1b, 2b)
6047+#endif
6048+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6049+ raw_local_irq_restore(flags);
6050+ }
6051+
6052+ smp_llsc_mb();
6053+
6054+ return result;
6055+}
6056+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6057 {
6058 int result;
6059
6060@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6061 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6062 * The function returns the old value of @v minus @i.
6063 */
6064-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6065+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6066 {
6067 int result;
6068
6069@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6070 return result;
6071 }
6072
6073-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6074-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6075+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6076+{
6077+ return cmpxchg(&v->counter, old, new);
6078+}
6079+
6080+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6081+ int new)
6082+{
6083+ return cmpxchg(&(v->counter), old, new);
6084+}
6085+
6086+static inline int atomic_xchg(atomic_t *v, int new)
6087+{
6088+ return xchg(&v->counter, new);
6089+}
6090+
6091+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6092+{
6093+ return xchg(&(v->counter), new);
6094+}
6095
6096 /**
6097 * __atomic_add_unless - add unless the number is a given value
6098@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6099
6100 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6101 #define atomic_inc_return(v) atomic_add_return(1, (v))
6102+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6103+{
6104+ return atomic_add_return_unchecked(1, v);
6105+}
6106
6107 /*
6108 * atomic_sub_and_test - subtract value from variable and test result
6109@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6110 * other cases.
6111 */
6112 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6113+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6114+{
6115+ return atomic_add_return_unchecked(1, v) == 0;
6116+}
6117
6118 /*
6119 * atomic_dec_and_test - decrement by 1 and test
6120@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6121 * Atomically increments @v by 1.
6122 */
6123 #define atomic_inc(v) atomic_add(1, (v))
6124+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6125+{
6126+ atomic_add_unchecked(1, v);
6127+}
6128
6129 /*
6130 * atomic_dec - decrement and test
6131@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6132 * Atomically decrements @v by 1.
6133 */
6134 #define atomic_dec(v) atomic_sub(1, (v))
6135+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6136+{
6137+ atomic_sub_unchecked(1, v);
6138+}
6139
6140 /*
6141 * atomic_add_negative - add and test if negative
6142@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6143 * @v: pointer of type atomic64_t
6144 *
6145 */
6146-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6147+static inline long atomic64_read(const atomic64_t *v)
6148+{
6149+ return (*(volatile const long *) &v->counter);
6150+}
6151+
6152+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6153+{
6154+ return (*(volatile const long *) &v->counter);
6155+}
6156
6157 /*
6158 * atomic64_set - set atomic variable
6159 * @v: pointer of type atomic64_t
6160 * @i: required value
6161 */
6162-#define atomic64_set(v, i) ((v)->counter = (i))
6163+static inline void atomic64_set(atomic64_t *v, long i)
6164+{
6165+ v->counter = i;
6166+}
6167+
6168+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6169+{
6170+ v->counter = i;
6171+}
6172
6173 /*
6174 * atomic64_add - add integer to atomic variable
6175@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6176 *
6177 * Atomically adds @i to @v.
6178 */
6179-static __inline__ void atomic64_add(long i, atomic64_t * v)
6180+static __inline__ void atomic64_add(long i, atomic64_t *v)
6181+{
6182+ long temp;
6183+
6184+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6185+ __asm__ __volatile__(
6186+ " .set mips3 \n"
6187+ "1: lld %0, %1 # atomic64_add \n"
6188+#ifdef CONFIG_PAX_REFCOUNT
6189+ /* Exception on overflow. */
6190+ "2: dadd %0, %2 \n"
6191+#else
6192+ " daddu %0, %2 \n"
6193+#endif
6194+ " scd %0, %1 \n"
6195+ " beqzl %0, 1b \n"
6196+#ifdef CONFIG_PAX_REFCOUNT
6197+ "3: \n"
6198+ _ASM_EXTABLE(2b, 3b)
6199+#endif
6200+ " .set mips0 \n"
6201+ : "=&r" (temp), "+m" (v->counter)
6202+ : "Ir" (i));
6203+ } else if (kernel_uses_llsc) {
6204+ __asm__ __volatile__(
6205+ " .set mips3 \n"
6206+ "1: lld %0, %1 # atomic64_add \n"
6207+#ifdef CONFIG_PAX_REFCOUNT
6208+ /* Exception on overflow. */
6209+ "2: dadd %0, %2 \n"
6210+#else
6211+ " daddu %0, %2 \n"
6212+#endif
6213+ " scd %0, %1 \n"
6214+ " beqz %0, 1b \n"
6215+#ifdef CONFIG_PAX_REFCOUNT
6216+ "3: \n"
6217+ _ASM_EXTABLE(2b, 3b)
6218+#endif
6219+ " .set mips0 \n"
6220+ : "=&r" (temp), "+m" (v->counter)
6221+ : "Ir" (i));
6222+ } else {
6223+ unsigned long flags;
6224+
6225+ raw_local_irq_save(flags);
6226+ __asm__ __volatile__(
6227+#ifdef CONFIG_PAX_REFCOUNT
6228+ /* Exception on overflow. */
6229+ "1: dadd %0, %1 \n"
6230+ "2: \n"
6231+ _ASM_EXTABLE(1b, 2b)
6232+#else
6233+ " daddu %0, %1 \n"
6234+#endif
6235+ : "+r" (v->counter) : "Ir" (i));
6236+ raw_local_irq_restore(flags);
6237+ }
6238+}
6239+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6240 {
6241 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6242 long temp;
6243@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6244 *
6245 * Atomically subtracts @i from @v.
6246 */
6247-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6248+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6249+{
6250+ long temp;
6251+
6252+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6253+ __asm__ __volatile__(
6254+ " .set mips3 \n"
6255+ "1: lld %0, %1 # atomic64_sub \n"
6256+#ifdef CONFIG_PAX_REFCOUNT
6257+ /* Exception on overflow. */
6258+ "2: dsub %0, %2 \n"
6259+#else
6260+ " dsubu %0, %2 \n"
6261+#endif
6262+ " scd %0, %1 \n"
6263+ " beqzl %0, 1b \n"
6264+#ifdef CONFIG_PAX_REFCOUNT
6265+ "3: \n"
6266+ _ASM_EXTABLE(2b, 3b)
6267+#endif
6268+ " .set mips0 \n"
6269+ : "=&r" (temp), "+m" (v->counter)
6270+ : "Ir" (i));
6271+ } else if (kernel_uses_llsc) {
6272+ __asm__ __volatile__(
6273+ " .set mips3 \n"
6274+ "1: lld %0, %1 # atomic64_sub \n"
6275+#ifdef CONFIG_PAX_REFCOUNT
6276+ /* Exception on overflow. */
6277+ "2: dsub %0, %2 \n"
6278+#else
6279+ " dsubu %0, %2 \n"
6280+#endif
6281+ " scd %0, %1 \n"
6282+ " beqz %0, 1b \n"
6283+#ifdef CONFIG_PAX_REFCOUNT
6284+ "3: \n"
6285+ _ASM_EXTABLE(2b, 3b)
6286+#endif
6287+ " .set mips0 \n"
6288+ : "=&r" (temp), "+m" (v->counter)
6289+ : "Ir" (i));
6290+ } else {
6291+ unsigned long flags;
6292+
6293+ raw_local_irq_save(flags);
6294+ __asm__ __volatile__(
6295+#ifdef CONFIG_PAX_REFCOUNT
6296+ /* Exception on overflow. */
6297+ "1: dsub %0, %1 \n"
6298+ "2: \n"
6299+ _ASM_EXTABLE(1b, 2b)
6300+#else
6301+ " dsubu %0, %1 \n"
6302+#endif
6303+ : "+r" (v->counter) : "Ir" (i));
6304+ raw_local_irq_restore(flags);
6305+ }
6306+}
6307+
6308+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6309 {
6310 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6311 long temp;
6312@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6313 /*
6314 * Same as above, but return the result value
6315 */
6316-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6317+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6318+{
6319+ long result;
6320+ long temp;
6321+
6322+ smp_mb__before_llsc();
6323+
6324+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6325+ __asm__ __volatile__(
6326+ " .set mips3 \n"
6327+ "1: lld %1, %2 # atomic64_add_return \n"
6328+#ifdef CONFIG_PAX_REFCOUNT
6329+ "2: dadd %0, %1, %3 \n"
6330+#else
6331+ " daddu %0, %1, %3 \n"
6332+#endif
6333+ " scd %0, %2 \n"
6334+ " beqzl %0, 1b \n"
6335+#ifdef CONFIG_PAX_REFCOUNT
6336+ " b 4f \n"
6337+ " .set noreorder \n"
6338+ "3: b 5f \n"
6339+ " move %0, %1 \n"
6340+ " .set reorder \n"
6341+ _ASM_EXTABLE(2b, 3b)
6342+#endif
6343+ "4: daddu %0, %1, %3 \n"
6344+#ifdef CONFIG_PAX_REFCOUNT
6345+ "5: \n"
6346+#endif
6347+ " .set mips0 \n"
6348+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6349+ : "Ir" (i));
6350+ } else if (kernel_uses_llsc) {
6351+ __asm__ __volatile__(
6352+ " .set mips3 \n"
6353+ "1: lld %1, %2 # atomic64_add_return \n"
6354+#ifdef CONFIG_PAX_REFCOUNT
6355+ "2: dadd %0, %1, %3 \n"
6356+#else
6357+ " daddu %0, %1, %3 \n"
6358+#endif
6359+ " scd %0, %2 \n"
6360+ " bnez %0, 4f \n"
6361+ " b 1b \n"
6362+#ifdef CONFIG_PAX_REFCOUNT
6363+ " .set noreorder \n"
6364+ "3: b 5f \n"
6365+ " move %0, %1 \n"
6366+ " .set reorder \n"
6367+ _ASM_EXTABLE(2b, 3b)
6368+#endif
6369+ "4: daddu %0, %1, %3 \n"
6370+#ifdef CONFIG_PAX_REFCOUNT
6371+ "5: \n"
6372+#endif
6373+ " .set mips0 \n"
6374+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6375+ : "Ir" (i), "m" (v->counter)
6376+ : "memory");
6377+ } else {
6378+ unsigned long flags;
6379+
6380+ raw_local_irq_save(flags);
6381+ __asm__ __volatile__(
6382+ " ld %0, %1 \n"
6383+#ifdef CONFIG_PAX_REFCOUNT
6384+ /* Exception on overflow. */
6385+ "1: dadd %0, %2 \n"
6386+#else
6387+ " daddu %0, %2 \n"
6388+#endif
6389+ " sd %0, %1 \n"
6390+#ifdef CONFIG_PAX_REFCOUNT
6391+ /* Note: Dest reg is not modified on overflow */
6392+ "2: \n"
6393+ _ASM_EXTABLE(1b, 2b)
6394+#endif
6395+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6396+ raw_local_irq_restore(flags);
6397+ }
6398+
6399+ smp_llsc_mb();
6400+
6401+ return result;
6402+}
6403+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6404 {
6405 long result;
6406
6407@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6408 return result;
6409 }
6410
6411-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6412+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6413+{
6414+ long result;
6415+ long temp;
6416+
6417+ smp_mb__before_llsc();
6418+
6419+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6420+ long temp;
6421+
6422+ __asm__ __volatile__(
6423+ " .set mips3 \n"
6424+ "1: lld %1, %2 # atomic64_sub_return \n"
6425+#ifdef CONFIG_PAX_REFCOUNT
6426+ "2: dsub %0, %1, %3 \n"
6427+#else
6428+ " dsubu %0, %1, %3 \n"
6429+#endif
6430+ " scd %0, %2 \n"
6431+ " beqzl %0, 1b \n"
6432+#ifdef CONFIG_PAX_REFCOUNT
6433+ " b 4f \n"
6434+ " .set noreorder \n"
6435+ "3: b 5f \n"
6436+ " move %0, %1 \n"
6437+ " .set reorder \n"
6438+ _ASM_EXTABLE(2b, 3b)
6439+#endif
6440+ "4: dsubu %0, %1, %3 \n"
6441+#ifdef CONFIG_PAX_REFCOUNT
6442+ "5: \n"
6443+#endif
6444+ " .set mips0 \n"
6445+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6446+ : "Ir" (i), "m" (v->counter)
6447+ : "memory");
6448+ } else if (kernel_uses_llsc) {
6449+ __asm__ __volatile__(
6450+ " .set mips3 \n"
6451+ "1: lld %1, %2 # atomic64_sub_return \n"
6452+#ifdef CONFIG_PAX_REFCOUNT
6453+ "2: dsub %0, %1, %3 \n"
6454+#else
6455+ " dsubu %0, %1, %3 \n"
6456+#endif
6457+ " scd %0, %2 \n"
6458+ " bnez %0, 4f \n"
6459+ " b 1b \n"
6460+#ifdef CONFIG_PAX_REFCOUNT
6461+ " .set noreorder \n"
6462+ "3: b 5f \n"
6463+ " move %0, %1 \n"
6464+ " .set reorder \n"
6465+ _ASM_EXTABLE(2b, 3b)
6466+#endif
6467+ "4: dsubu %0, %1, %3 \n"
6468+#ifdef CONFIG_PAX_REFCOUNT
6469+ "5: \n"
6470+#endif
6471+ " .set mips0 \n"
6472+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6473+ : "Ir" (i), "m" (v->counter)
6474+ : "memory");
6475+ } else {
6476+ unsigned long flags;
6477+
6478+ raw_local_irq_save(flags);
6479+ __asm__ __volatile__(
6480+ " ld %0, %1 \n"
6481+#ifdef CONFIG_PAX_REFCOUNT
6482+ /* Exception on overflow. */
6483+ "1: dsub %0, %2 \n"
6484+#else
6485+ " dsubu %0, %2 \n"
6486+#endif
6487+ " sd %0, %1 \n"
6488+#ifdef CONFIG_PAX_REFCOUNT
6489+ /* Note: Dest reg is not modified on overflow */
6490+ "2: \n"
6491+ _ASM_EXTABLE(1b, 2b)
6492+#endif
6493+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6494+ raw_local_irq_restore(flags);
6495+ }
6496+
6497+ smp_llsc_mb();
6498+
6499+ return result;
6500+}
6501+
6502+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6503 {
6504 long result;
6505
6506@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6507 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6508 * The function returns the old value of @v minus @i.
6509 */
6510-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6511+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6512 {
6513 long result;
6514
6515@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6516 return result;
6517 }
6518
6519-#define atomic64_cmpxchg(v, o, n) \
6520- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6521-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6522+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6523+{
6524+ return cmpxchg(&v->counter, old, new);
6525+}
6526+
6527+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6528+ long new)
6529+{
6530+ return cmpxchg(&(v->counter), old, new);
6531+}
6532+
6533+static inline long atomic64_xchg(atomic64_t *v, long new)
6534+{
6535+ return xchg(&v->counter, new);
6536+}
6537+
6538+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6539+{
6540+ return xchg(&(v->counter), new);
6541+}
6542
6543 /**
6544 * atomic64_add_unless - add unless the number is a given value
6545@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6546
6547 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6548 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6549+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6550
6551 /*
6552 * atomic64_sub_and_test - subtract value from variable and test result
6553@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6554 * other cases.
6555 */
6556 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6557+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6558
6559 /*
6560 * atomic64_dec_and_test - decrement by 1 and test
6561@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6562 * Atomically increments @v by 1.
6563 */
6564 #define atomic64_inc(v) atomic64_add(1, (v))
6565+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6566
6567 /*
6568 * atomic64_dec - decrement and test
6569@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6570 * Atomically decrements @v by 1.
6571 */
6572 #define atomic64_dec(v) atomic64_sub(1, (v))
6573+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6574
6575 /*
6576 * atomic64_add_negative - add and test if negative
6577diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6578index e1aa4e4..670b68b 100644
6579--- a/arch/mips/include/asm/barrier.h
6580+++ b/arch/mips/include/asm/barrier.h
6581@@ -184,7 +184,7 @@
6582 do { \
6583 compiletime_assert_atomic_type(*p); \
6584 smp_mb(); \
6585- ACCESS_ONCE(*p) = (v); \
6586+ ACCESS_ONCE_RW(*p) = (v); \
6587 } while (0)
6588
6589 #define smp_load_acquire(p) \
6590diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6591index b4db69f..8f3b093 100644
6592--- a/arch/mips/include/asm/cache.h
6593+++ b/arch/mips/include/asm/cache.h
6594@@ -9,10 +9,11 @@
6595 #ifndef _ASM_CACHE_H
6596 #define _ASM_CACHE_H
6597
6598+#include <linux/const.h>
6599 #include <kmalloc.h>
6600
6601 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6602-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6603+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6604
6605 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6606 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6607diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6608index d414405..6bb4ba2 100644
6609--- a/arch/mips/include/asm/elf.h
6610+++ b/arch/mips/include/asm/elf.h
6611@@ -398,13 +398,16 @@ extern const char *__elf_platform;
6612 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6613 #endif
6614
6615+#ifdef CONFIG_PAX_ASLR
6616+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6617+
6618+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6619+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6620+#endif
6621+
6622 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6623 struct linux_binprm;
6624 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6625 int uses_interp);
6626
6627-struct mm_struct;
6628-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6629-#define arch_randomize_brk arch_randomize_brk
6630-
6631 #endif /* _ASM_ELF_H */
6632diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6633index c1f6afa..38cc6e9 100644
6634--- a/arch/mips/include/asm/exec.h
6635+++ b/arch/mips/include/asm/exec.h
6636@@ -12,6 +12,6 @@
6637 #ifndef _ASM_EXEC_H
6638 #define _ASM_EXEC_H
6639
6640-extern unsigned long arch_align_stack(unsigned long sp);
6641+#define arch_align_stack(x) ((x) & ~0xfUL)
6642
6643 #endif /* _ASM_EXEC_H */
6644diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6645index 9e8ef59..1139d6b 100644
6646--- a/arch/mips/include/asm/hw_irq.h
6647+++ b/arch/mips/include/asm/hw_irq.h
6648@@ -10,7 +10,7 @@
6649
6650 #include <linux/atomic.h>
6651
6652-extern atomic_t irq_err_count;
6653+extern atomic_unchecked_t irq_err_count;
6654
6655 /*
6656 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6657diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6658index 46dfc3c..a16b13a 100644
6659--- a/arch/mips/include/asm/local.h
6660+++ b/arch/mips/include/asm/local.h
6661@@ -12,15 +12,25 @@ typedef struct
6662 atomic_long_t a;
6663 } local_t;
6664
6665+typedef struct {
6666+ atomic_long_unchecked_t a;
6667+} local_unchecked_t;
6668+
6669 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6670
6671 #define local_read(l) atomic_long_read(&(l)->a)
6672+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6673 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6674+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6675
6676 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6677+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6678 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6679+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6680 #define local_inc(l) atomic_long_inc(&(l)->a)
6681+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6682 #define local_dec(l) atomic_long_dec(&(l)->a)
6683+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6684
6685 /*
6686 * Same as above, but return the result value
6687@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6688 return result;
6689 }
6690
6691+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6692+{
6693+ unsigned long result;
6694+
6695+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6696+ unsigned long temp;
6697+
6698+ __asm__ __volatile__(
6699+ " .set mips3 \n"
6700+ "1:" __LL "%1, %2 # local_add_return \n"
6701+ " addu %0, %1, %3 \n"
6702+ __SC "%0, %2 \n"
6703+ " beqzl %0, 1b \n"
6704+ " addu %0, %1, %3 \n"
6705+ " .set mips0 \n"
6706+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6707+ : "Ir" (i), "m" (l->a.counter)
6708+ : "memory");
6709+ } else if (kernel_uses_llsc) {
6710+ unsigned long temp;
6711+
6712+ __asm__ __volatile__(
6713+ " .set mips3 \n"
6714+ "1:" __LL "%1, %2 # local_add_return \n"
6715+ " addu %0, %1, %3 \n"
6716+ __SC "%0, %2 \n"
6717+ " beqz %0, 1b \n"
6718+ " addu %0, %1, %3 \n"
6719+ " .set mips0 \n"
6720+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6721+ : "Ir" (i), "m" (l->a.counter)
6722+ : "memory");
6723+ } else {
6724+ unsigned long flags;
6725+
6726+ local_irq_save(flags);
6727+ result = l->a.counter;
6728+ result += i;
6729+ l->a.counter = result;
6730+ local_irq_restore(flags);
6731+ }
6732+
6733+ return result;
6734+}
6735+
6736 static __inline__ long local_sub_return(long i, local_t * l)
6737 {
6738 unsigned long result;
6739@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6740
6741 #define local_cmpxchg(l, o, n) \
6742 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6743+#define local_cmpxchg_unchecked(l, o, n) \
6744+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6745 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6746
6747 /**
6748diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6749index 5699ec3..95def83 100644
6750--- a/arch/mips/include/asm/page.h
6751+++ b/arch/mips/include/asm/page.h
6752@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6753 #ifdef CONFIG_CPU_MIPS32
6754 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6755 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6756- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6757+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6758 #else
6759 typedef struct { unsigned long long pte; } pte_t;
6760 #define pte_val(x) ((x).pte)
6761diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6762index b336037..5b874cc 100644
6763--- a/arch/mips/include/asm/pgalloc.h
6764+++ b/arch/mips/include/asm/pgalloc.h
6765@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6766 {
6767 set_pud(pud, __pud((unsigned long)pmd));
6768 }
6769+
6770+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6771+{
6772+ pud_populate(mm, pud, pmd);
6773+}
6774 #endif
6775
6776 /*
6777diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6778index 008324d..f67c239 100644
6779--- a/arch/mips/include/asm/pgtable.h
6780+++ b/arch/mips/include/asm/pgtable.h
6781@@ -20,6 +20,9 @@
6782 #include <asm/io.h>
6783 #include <asm/pgtable-bits.h>
6784
6785+#define ktla_ktva(addr) (addr)
6786+#define ktva_ktla(addr) (addr)
6787+
6788 struct mm_struct;
6789 struct vm_area_struct;
6790
6791diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6792index 25da651..ae2a259 100644
6793--- a/arch/mips/include/asm/smtc_proc.h
6794+++ b/arch/mips/include/asm/smtc_proc.h
6795@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6796
6797 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6798
6799-extern atomic_t smtc_fpu_recoveries;
6800+extern atomic_unchecked_t smtc_fpu_recoveries;
6801
6802 #endif /* __ASM_SMTC_PROC_H */
6803diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6804index d2d961d..a674df0 100644
6805--- a/arch/mips/include/asm/thread_info.h
6806+++ b/arch/mips/include/asm/thread_info.h
6807@@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6808 #define TIF_SECCOMP 4 /* secure computing */
6809 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6810 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6811+/* li takes a 32bit immediate */
6812+#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6813+
6814 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6815 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6816 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6817@@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6818 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6819 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6820 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6821+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6822
6823 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6824 _TIF_SYSCALL_AUDIT | \
6825- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6826+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6827+ _TIF_GRSEC_SETXID)
6828
6829 /* work to do in syscall_trace_leave() */
6830 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6831- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6832+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6833
6834 /* work to do on interrupt/exception return */
6835 #define _TIF_WORK_MASK \
6836@@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6837 /* work to do on any return to u-space */
6838 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6839 _TIF_WORK_SYSCALL_EXIT | \
6840- _TIF_SYSCALL_TRACEPOINT)
6841+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6842
6843 /*
6844 * We stash processor id into a COP0 register to retrieve it fast
6845diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6846index a109510..94ee3f6 100644
6847--- a/arch/mips/include/asm/uaccess.h
6848+++ b/arch/mips/include/asm/uaccess.h
6849@@ -130,6 +130,7 @@ extern u64 __ua_limit;
6850 __ok == 0; \
6851 })
6852
6853+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6854 #define access_ok(type, addr, size) \
6855 likely(__access_ok((addr), (size), __access_mask))
6856
6857diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6858index 1188e00..41cf144 100644
6859--- a/arch/mips/kernel/binfmt_elfn32.c
6860+++ b/arch/mips/kernel/binfmt_elfn32.c
6861@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6862 #undef ELF_ET_DYN_BASE
6863 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6864
6865+#ifdef CONFIG_PAX_ASLR
6866+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6867+
6868+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6869+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6870+#endif
6871+
6872 #include <asm/processor.h>
6873 #include <linux/module.h>
6874 #include <linux/elfcore.h>
6875diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6876index 7faf5f2..f3d3cf4 100644
6877--- a/arch/mips/kernel/binfmt_elfo32.c
6878+++ b/arch/mips/kernel/binfmt_elfo32.c
6879@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6880 #undef ELF_ET_DYN_BASE
6881 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6882
6883+#ifdef CONFIG_PAX_ASLR
6884+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6885+
6886+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6887+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6888+#endif
6889+
6890 #include <asm/processor.h>
6891
6892 /*
6893diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6894index 2b91fe8..fe4f6b4 100644
6895--- a/arch/mips/kernel/i8259.c
6896+++ b/arch/mips/kernel/i8259.c
6897@@ -205,7 +205,7 @@ spurious_8259A_irq:
6898 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6899 spurious_irq_mask |= irqmask;
6900 }
6901- atomic_inc(&irq_err_count);
6902+ atomic_inc_unchecked(&irq_err_count);
6903 /*
6904 * Theoretically we do not have to handle this IRQ,
6905 * but in Linux this does not cause problems and is
6906diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6907index 44a1f79..2bd6aa3 100644
6908--- a/arch/mips/kernel/irq-gt641xx.c
6909+++ b/arch/mips/kernel/irq-gt641xx.c
6910@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6911 }
6912 }
6913
6914- atomic_inc(&irq_err_count);
6915+ atomic_inc_unchecked(&irq_err_count);
6916 }
6917
6918 void __init gt641xx_irq_init(void)
6919diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6920index d1fea7a..2e591b0 100644
6921--- a/arch/mips/kernel/irq.c
6922+++ b/arch/mips/kernel/irq.c
6923@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6924 printk("unexpected IRQ # %d\n", irq);
6925 }
6926
6927-atomic_t irq_err_count;
6928+atomic_unchecked_t irq_err_count;
6929
6930 int arch_show_interrupts(struct seq_file *p, int prec)
6931 {
6932- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6933+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6934 return 0;
6935 }
6936
6937 asmlinkage void spurious_interrupt(void)
6938 {
6939- atomic_inc(&irq_err_count);
6940+ atomic_inc_unchecked(&irq_err_count);
6941 }
6942
6943 void __init init_IRQ(void)
6944@@ -110,7 +110,10 @@ void __init init_IRQ(void)
6945 #endif
6946 }
6947
6948+
6949 #ifdef DEBUG_STACKOVERFLOW
6950+extern void gr_handle_kernel_exploit(void);
6951+
6952 static inline void check_stack_overflow(void)
6953 {
6954 unsigned long sp;
6955@@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6956 printk("do_IRQ: stack overflow: %ld\n",
6957 sp - sizeof(struct thread_info));
6958 dump_stack();
6959+ gr_handle_kernel_exploit();
6960 }
6961 }
6962 #else
6963diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6964index 60e39dc..b4829bf 100644
6965--- a/arch/mips/kernel/process.c
6966+++ b/arch/mips/kernel/process.c
6967@@ -579,15 +579,3 @@ unsigned long get_wchan(struct task_struct *task)
6968 out:
6969 return pc;
6970 }
6971-
6972-/*
6973- * Don't forget that the stack pointer must be aligned on a 8 bytes
6974- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6975- */
6976-unsigned long arch_align_stack(unsigned long sp)
6977-{
6978- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6979- sp -= get_random_int() & ~PAGE_MASK;
6980-
6981- return sp & ALMASK;
6982-}
6983diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6984index f639ccd..e4b110d 100644
6985--- a/arch/mips/kernel/ptrace.c
6986+++ b/arch/mips/kernel/ptrace.c
6987@@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
6988 return ret;
6989 }
6990
6991+#ifdef CONFIG_GRKERNSEC_SETXID
6992+extern void gr_delayed_cred_worker(void);
6993+#endif
6994+
6995 /*
6996 * Notification of system call entry/exit
6997 * - triggered by current->work.syscall_trace
6998@@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6999 tracehook_report_syscall_entry(regs))
7000 ret = -1;
7001
7002+#ifdef CONFIG_GRKERNSEC_SETXID
7003+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7004+ gr_delayed_cred_worker();
7005+#endif
7006+
7007 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7008 trace_sys_enter(regs, regs->regs[2]);
7009
7010diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7011index 07fc524..b9d7f28 100644
7012--- a/arch/mips/kernel/reset.c
7013+++ b/arch/mips/kernel/reset.c
7014@@ -13,6 +13,7 @@
7015 #include <linux/reboot.h>
7016
7017 #include <asm/reboot.h>
7018+#include <asm/bug.h>
7019
7020 /*
7021 * Urgs ... Too many MIPS machines to handle this in a generic way.
7022@@ -29,16 +30,19 @@ void machine_restart(char *command)
7023 {
7024 if (_machine_restart)
7025 _machine_restart(command);
7026+ BUG();
7027 }
7028
7029 void machine_halt(void)
7030 {
7031 if (_machine_halt)
7032 _machine_halt();
7033+ BUG();
7034 }
7035
7036 void machine_power_off(void)
7037 {
7038 if (pm_power_off)
7039 pm_power_off();
7040+ BUG();
7041 }
7042diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
7043index 38635a9..3fcd5e0 100644
7044--- a/arch/mips/kernel/smtc-proc.c
7045+++ b/arch/mips/kernel/smtc-proc.c
7046@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
7047
7048 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
7049
7050-atomic_t smtc_fpu_recoveries;
7051+atomic_unchecked_t smtc_fpu_recoveries;
7052
7053 static int smtc_proc_show(struct seq_file *m, void *v)
7054 {
7055@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
7056 for(i = 0; i < NR_CPUS; i++)
7057 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
7058 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
7059- atomic_read(&smtc_fpu_recoveries));
7060+ atomic_read_unchecked(&smtc_fpu_recoveries));
7061 return 0;
7062 }
7063
7064@@ -73,7 +73,7 @@ void init_smtc_stats(void)
7065 smtc_cpu_stats[i].selfipis = 0;
7066 }
7067
7068- atomic_set(&smtc_fpu_recoveries, 0);
7069+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
7070
7071 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
7072 }
7073diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
7074index c1681d6..9f881d1 100644
7075--- a/arch/mips/kernel/smtc.c
7076+++ b/arch/mips/kernel/smtc.c
7077@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
7078 }
7079 smtc_ipi_qdump();
7080 printk("%d Recoveries of \"stolen\" FPU\n",
7081- atomic_read(&smtc_fpu_recoveries));
7082+ atomic_read_unchecked(&smtc_fpu_recoveries));
7083 }
7084
7085
7086diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7087index c24ad5f..9983ab2 100644
7088--- a/arch/mips/kernel/sync-r4k.c
7089+++ b/arch/mips/kernel/sync-r4k.c
7090@@ -20,8 +20,8 @@
7091 #include <asm/mipsregs.h>
7092
7093 static atomic_t count_start_flag = ATOMIC_INIT(0);
7094-static atomic_t count_count_start = ATOMIC_INIT(0);
7095-static atomic_t count_count_stop = ATOMIC_INIT(0);
7096+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7097+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7098 static atomic_t count_reference = ATOMIC_INIT(0);
7099
7100 #define COUNTON 100
7101@@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
7102
7103 for (i = 0; i < NR_LOOPS; i++) {
7104 /* slaves loop on '!= 2' */
7105- while (atomic_read(&count_count_start) != 1)
7106+ while (atomic_read_unchecked(&count_count_start) != 1)
7107 mb();
7108- atomic_set(&count_count_stop, 0);
7109+ atomic_set_unchecked(&count_count_stop, 0);
7110 smp_wmb();
7111
7112 /* this lets the slaves write their count register */
7113- atomic_inc(&count_count_start);
7114+ atomic_inc_unchecked(&count_count_start);
7115
7116 /*
7117 * Everyone initialises count in the last loop:
7118@@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
7119 /*
7120 * Wait for all slaves to leave the synchronization point:
7121 */
7122- while (atomic_read(&count_count_stop) != 1)
7123+ while (atomic_read_unchecked(&count_count_stop) != 1)
7124 mb();
7125- atomic_set(&count_count_start, 0);
7126+ atomic_set_unchecked(&count_count_start, 0);
7127 smp_wmb();
7128- atomic_inc(&count_count_stop);
7129+ atomic_inc_unchecked(&count_count_stop);
7130 }
7131 /* Arrange for an interrupt in a short while */
7132 write_c0_compare(read_c0_count() + COUNTON);
7133@@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7134 initcount = atomic_read(&count_reference);
7135
7136 for (i = 0; i < NR_LOOPS; i++) {
7137- atomic_inc(&count_count_start);
7138- while (atomic_read(&count_count_start) != 2)
7139+ atomic_inc_unchecked(&count_count_start);
7140+ while (atomic_read_unchecked(&count_count_start) != 2)
7141 mb();
7142
7143 /*
7144@@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7145 if (i == NR_LOOPS-1)
7146 write_c0_count(initcount);
7147
7148- atomic_inc(&count_count_stop);
7149- while (atomic_read(&count_count_stop) != 2)
7150+ atomic_inc_unchecked(&count_count_stop);
7151+ while (atomic_read_unchecked(&count_count_stop) != 2)
7152 mb();
7153 }
7154 /* Arrange for an interrupt in a short while */
7155diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7156index 8119ac2..b229939 100644
7157--- a/arch/mips/kernel/traps.c
7158+++ b/arch/mips/kernel/traps.c
7159@@ -695,7 +695,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7160 siginfo_t info;
7161
7162 prev_state = exception_enter();
7163- die_if_kernel("Integer overflow", regs);
7164+ if (unlikely(!user_mode(regs))) {
7165+
7166+#ifdef CONFIG_PAX_REFCOUNT
7167+ if (fixup_exception(regs)) {
7168+ pax_report_refcount_overflow(regs);
7169+ exception_exit(prev_state);
7170+ return;
7171+ }
7172+#endif
7173+
7174+ die("Integer overflow", regs);
7175+ }
7176
7177 info.si_code = FPE_INTOVF;
7178 info.si_signo = SIGFPE;
7179diff --git a/arch/mips/kvm/kvm_mips.c b/arch/mips/kvm/kvm_mips.c
7180index 3e0ff8d..9eafbf0b 100644
7181--- a/arch/mips/kvm/kvm_mips.c
7182+++ b/arch/mips/kvm/kvm_mips.c
7183@@ -832,7 +832,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7184 return r;
7185 }
7186
7187-int kvm_arch_init(void *opaque)
7188+int kvm_arch_init(const void *opaque)
7189 {
7190 int ret;
7191
7192diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7193index becc42b..9e43d4b 100644
7194--- a/arch/mips/mm/fault.c
7195+++ b/arch/mips/mm/fault.c
7196@@ -28,6 +28,23 @@
7197 #include <asm/highmem.h> /* For VMALLOC_END */
7198 #include <linux/kdebug.h>
7199
7200+#ifdef CONFIG_PAX_PAGEEXEC
7201+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7202+{
7203+ unsigned long i;
7204+
7205+ printk(KERN_ERR "PAX: bytes at PC: ");
7206+ for (i = 0; i < 5; i++) {
7207+ unsigned int c;
7208+ if (get_user(c, (unsigned int *)pc+i))
7209+ printk(KERN_CONT "???????? ");
7210+ else
7211+ printk(KERN_CONT "%08x ", c);
7212+ }
7213+ printk("\n");
7214+}
7215+#endif
7216+
7217 /*
7218 * This routine handles page faults. It determines the address,
7219 * and the problem, and then passes it off to one of the appropriate
7220@@ -199,6 +216,14 @@ bad_area:
7221 bad_area_nosemaphore:
7222 /* User mode accesses just cause a SIGSEGV */
7223 if (user_mode(regs)) {
7224+
7225+#ifdef CONFIG_PAX_PAGEEXEC
7226+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7227+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7228+ do_group_exit(SIGKILL);
7229+ }
7230+#endif
7231+
7232 tsk->thread.cp0_badvaddr = address;
7233 tsk->thread.error_code = write;
7234 #if 0
7235diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7236index f1baadd..5472dca 100644
7237--- a/arch/mips/mm/mmap.c
7238+++ b/arch/mips/mm/mmap.c
7239@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7240 struct vm_area_struct *vma;
7241 unsigned long addr = addr0;
7242 int do_color_align;
7243+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7244 struct vm_unmapped_area_info info;
7245
7246 if (unlikely(len > TASK_SIZE))
7247@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7248 do_color_align = 1;
7249
7250 /* requesting a specific address */
7251+
7252+#ifdef CONFIG_PAX_RANDMMAP
7253+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7254+#endif
7255+
7256 if (addr) {
7257 if (do_color_align)
7258 addr = COLOUR_ALIGN(addr, pgoff);
7259@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7260 addr = PAGE_ALIGN(addr);
7261
7262 vma = find_vma(mm, addr);
7263- if (TASK_SIZE - len >= addr &&
7264- (!vma || addr + len <= vma->vm_start))
7265+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7266 return addr;
7267 }
7268
7269 info.length = len;
7270 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7271 info.align_offset = pgoff << PAGE_SHIFT;
7272+ info.threadstack_offset = offset;
7273
7274 if (dir == DOWN) {
7275 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7276@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7277 {
7278 unsigned long random_factor = 0UL;
7279
7280+#ifdef CONFIG_PAX_RANDMMAP
7281+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7282+#endif
7283+
7284 if (current->flags & PF_RANDOMIZE) {
7285 random_factor = get_random_int();
7286 random_factor = random_factor << PAGE_SHIFT;
7287@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7288
7289 if (mmap_is_legacy()) {
7290 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7291+
7292+#ifdef CONFIG_PAX_RANDMMAP
7293+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7294+ mm->mmap_base += mm->delta_mmap;
7295+#endif
7296+
7297 mm->get_unmapped_area = arch_get_unmapped_area;
7298 } else {
7299 mm->mmap_base = mmap_base(random_factor);
7300+
7301+#ifdef CONFIG_PAX_RANDMMAP
7302+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7303+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7304+#endif
7305+
7306 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7307 }
7308 }
7309
7310-static inline unsigned long brk_rnd(void)
7311-{
7312- unsigned long rnd = get_random_int();
7313-
7314- rnd = rnd << PAGE_SHIFT;
7315- /* 8MB for 32bit, 256MB for 64bit */
7316- if (TASK_IS_32BIT_ADDR)
7317- rnd = rnd & 0x7ffffful;
7318- else
7319- rnd = rnd & 0xffffffful;
7320-
7321- return rnd;
7322-}
7323-
7324-unsigned long arch_randomize_brk(struct mm_struct *mm)
7325-{
7326- unsigned long base = mm->brk;
7327- unsigned long ret;
7328-
7329- ret = PAGE_ALIGN(base + brk_rnd());
7330-
7331- if (ret < mm->brk)
7332- return mm->brk;
7333-
7334- return ret;
7335-}
7336-
7337 int __virt_addr_valid(const volatile void *kaddr)
7338 {
7339 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7340diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7341index 59cccd9..f39ac2f 100644
7342--- a/arch/mips/pci/pci-octeon.c
7343+++ b/arch/mips/pci/pci-octeon.c
7344@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7345
7346
7347 static struct pci_ops octeon_pci_ops = {
7348- octeon_read_config,
7349- octeon_write_config,
7350+ .read = octeon_read_config,
7351+ .write = octeon_write_config,
7352 };
7353
7354 static struct resource octeon_pci_mem_resource = {
7355diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7356index 5e36c33..eb4a17b 100644
7357--- a/arch/mips/pci/pcie-octeon.c
7358+++ b/arch/mips/pci/pcie-octeon.c
7359@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7360 }
7361
7362 static struct pci_ops octeon_pcie0_ops = {
7363- octeon_pcie0_read_config,
7364- octeon_pcie0_write_config,
7365+ .read = octeon_pcie0_read_config,
7366+ .write = octeon_pcie0_write_config,
7367 };
7368
7369 static struct resource octeon_pcie0_mem_resource = {
7370@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7371 };
7372
7373 static struct pci_ops octeon_pcie1_ops = {
7374- octeon_pcie1_read_config,
7375- octeon_pcie1_write_config,
7376+ .read = octeon_pcie1_read_config,
7377+ .write = octeon_pcie1_write_config,
7378 };
7379
7380 static struct resource octeon_pcie1_mem_resource = {
7381@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7382 };
7383
7384 static struct pci_ops octeon_dummy_ops = {
7385- octeon_dummy_read_config,
7386- octeon_dummy_write_config,
7387+ .read = octeon_dummy_read_config,
7388+ .write = octeon_dummy_write_config,
7389 };
7390
7391 static struct resource octeon_dummy_mem_resource = {
7392diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7393index a2358b4..7cead4f 100644
7394--- a/arch/mips/sgi-ip27/ip27-nmi.c
7395+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7396@@ -187,9 +187,9 @@ void
7397 cont_nmi_dump(void)
7398 {
7399 #ifndef REAL_NMI_SIGNAL
7400- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7401+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7402
7403- atomic_inc(&nmied_cpus);
7404+ atomic_inc_unchecked(&nmied_cpus);
7405 #endif
7406 /*
7407 * Only allow 1 cpu to proceed
7408@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7409 udelay(10000);
7410 }
7411 #else
7412- while (atomic_read(&nmied_cpus) != num_online_cpus());
7413+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7414 #endif
7415
7416 /*
7417diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7418index a046b30..6799527 100644
7419--- a/arch/mips/sni/rm200.c
7420+++ b/arch/mips/sni/rm200.c
7421@@ -270,7 +270,7 @@ spurious_8259A_irq:
7422 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7423 spurious_irq_mask |= irqmask;
7424 }
7425- atomic_inc(&irq_err_count);
7426+ atomic_inc_unchecked(&irq_err_count);
7427 /*
7428 * Theoretically we do not have to handle this IRQ,
7429 * but in Linux this does not cause problems and is
7430diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7431index 41e873b..34d33a7 100644
7432--- a/arch/mips/vr41xx/common/icu.c
7433+++ b/arch/mips/vr41xx/common/icu.c
7434@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7435
7436 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7437
7438- atomic_inc(&irq_err_count);
7439+ atomic_inc_unchecked(&irq_err_count);
7440
7441 return -1;
7442 }
7443diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7444index ae0e4ee..e8f0692 100644
7445--- a/arch/mips/vr41xx/common/irq.c
7446+++ b/arch/mips/vr41xx/common/irq.c
7447@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7448 irq_cascade_t *cascade;
7449
7450 if (irq >= NR_IRQS) {
7451- atomic_inc(&irq_err_count);
7452+ atomic_inc_unchecked(&irq_err_count);
7453 return;
7454 }
7455
7456@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7457 ret = cascade->get_irq(irq);
7458 irq = ret;
7459 if (ret < 0)
7460- atomic_inc(&irq_err_count);
7461+ atomic_inc_unchecked(&irq_err_count);
7462 else
7463 irq_dispatch(irq);
7464 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7465diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7466index 967d144..db12197 100644
7467--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7468+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7469@@ -11,12 +11,14 @@
7470 #ifndef _ASM_PROC_CACHE_H
7471 #define _ASM_PROC_CACHE_H
7472
7473+#include <linux/const.h>
7474+
7475 /* L1 cache */
7476
7477 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7478 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7479-#define L1_CACHE_BYTES 16 /* bytes per entry */
7480 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7481+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7482 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7483
7484 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7485diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7486index bcb5df2..84fabd2 100644
7487--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7488+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7489@@ -16,13 +16,15 @@
7490 #ifndef _ASM_PROC_CACHE_H
7491 #define _ASM_PROC_CACHE_H
7492
7493+#include <linux/const.h>
7494+
7495 /*
7496 * L1 cache
7497 */
7498 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7499 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7500-#define L1_CACHE_BYTES 32 /* bytes per entry */
7501 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7502+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7503 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7504
7505 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7506diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7507index 4ce7a01..449202a 100644
7508--- a/arch/openrisc/include/asm/cache.h
7509+++ b/arch/openrisc/include/asm/cache.h
7510@@ -19,11 +19,13 @@
7511 #ifndef __ASM_OPENRISC_CACHE_H
7512 #define __ASM_OPENRISC_CACHE_H
7513
7514+#include <linux/const.h>
7515+
7516 /* FIXME: How can we replace these with values from the CPU...
7517 * they shouldn't be hard-coded!
7518 */
7519
7520-#define L1_CACHE_BYTES 16
7521 #define L1_CACHE_SHIFT 4
7522+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7523
7524 #endif /* __ASM_OPENRISC_CACHE_H */
7525diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7526index 472886c..00e7df9 100644
7527--- a/arch/parisc/include/asm/atomic.h
7528+++ b/arch/parisc/include/asm/atomic.h
7529@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7530 return dec;
7531 }
7532
7533+#define atomic64_read_unchecked(v) atomic64_read(v)
7534+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7535+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7536+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7537+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7538+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7539+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7540+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7541+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7542+
7543 #endif /* !CONFIG_64BIT */
7544
7545
7546diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7547index 47f11c7..3420df2 100644
7548--- a/arch/parisc/include/asm/cache.h
7549+++ b/arch/parisc/include/asm/cache.h
7550@@ -5,6 +5,7 @@
7551 #ifndef __ARCH_PARISC_CACHE_H
7552 #define __ARCH_PARISC_CACHE_H
7553
7554+#include <linux/const.h>
7555
7556 /*
7557 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7558@@ -15,13 +16,13 @@
7559 * just ruin performance.
7560 */
7561 #ifdef CONFIG_PA20
7562-#define L1_CACHE_BYTES 64
7563 #define L1_CACHE_SHIFT 6
7564 #else
7565-#define L1_CACHE_BYTES 32
7566 #define L1_CACHE_SHIFT 5
7567 #endif
7568
7569+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7570+
7571 #ifndef __ASSEMBLY__
7572
7573 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7574diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7575index 3391d06..c23a2cc 100644
7576--- a/arch/parisc/include/asm/elf.h
7577+++ b/arch/parisc/include/asm/elf.h
7578@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7579
7580 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7581
7582+#ifdef CONFIG_PAX_ASLR
7583+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7584+
7585+#define PAX_DELTA_MMAP_LEN 16
7586+#define PAX_DELTA_STACK_LEN 16
7587+#endif
7588+
7589 /* This yields a mask that user programs can use to figure out what
7590 instruction set this CPU supports. This could be done in user space,
7591 but it's not easy, and we've already done it here. */
7592diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7593index f213f5b..0af3e8e 100644
7594--- a/arch/parisc/include/asm/pgalloc.h
7595+++ b/arch/parisc/include/asm/pgalloc.h
7596@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7597 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7598 }
7599
7600+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7601+{
7602+ pgd_populate(mm, pgd, pmd);
7603+}
7604+
7605 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7606 {
7607 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7608@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7609 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7610 #define pmd_free(mm, x) do { } while (0)
7611 #define pgd_populate(mm, pmd, pte) BUG()
7612+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7613
7614 #endif
7615
7616diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7617index 22b89d1..ce34230 100644
7618--- a/arch/parisc/include/asm/pgtable.h
7619+++ b/arch/parisc/include/asm/pgtable.h
7620@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7621 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7622 #define PAGE_COPY PAGE_EXECREAD
7623 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7624+
7625+#ifdef CONFIG_PAX_PAGEEXEC
7626+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7627+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7628+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7629+#else
7630+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7631+# define PAGE_COPY_NOEXEC PAGE_COPY
7632+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7633+#endif
7634+
7635 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7636 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7637 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7638diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7639index 4006964..fcb3cc2 100644
7640--- a/arch/parisc/include/asm/uaccess.h
7641+++ b/arch/parisc/include/asm/uaccess.h
7642@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7643 const void __user *from,
7644 unsigned long n)
7645 {
7646- int sz = __compiletime_object_size(to);
7647+ size_t sz = __compiletime_object_size(to);
7648 int ret = -EFAULT;
7649
7650- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7651+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7652 ret = __copy_from_user(to, from, n);
7653 else
7654 copy_from_user_overflow();
7655diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7656index 50dfafc..b9fc230 100644
7657--- a/arch/parisc/kernel/module.c
7658+++ b/arch/parisc/kernel/module.c
7659@@ -98,16 +98,38 @@
7660
7661 /* three functions to determine where in the module core
7662 * or init pieces the location is */
7663+static inline int in_init_rx(struct module *me, void *loc)
7664+{
7665+ return (loc >= me->module_init_rx &&
7666+ loc < (me->module_init_rx + me->init_size_rx));
7667+}
7668+
7669+static inline int in_init_rw(struct module *me, void *loc)
7670+{
7671+ return (loc >= me->module_init_rw &&
7672+ loc < (me->module_init_rw + me->init_size_rw));
7673+}
7674+
7675 static inline int in_init(struct module *me, void *loc)
7676 {
7677- return (loc >= me->module_init &&
7678- loc <= (me->module_init + me->init_size));
7679+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7680+}
7681+
7682+static inline int in_core_rx(struct module *me, void *loc)
7683+{
7684+ return (loc >= me->module_core_rx &&
7685+ loc < (me->module_core_rx + me->core_size_rx));
7686+}
7687+
7688+static inline int in_core_rw(struct module *me, void *loc)
7689+{
7690+ return (loc >= me->module_core_rw &&
7691+ loc < (me->module_core_rw + me->core_size_rw));
7692 }
7693
7694 static inline int in_core(struct module *me, void *loc)
7695 {
7696- return (loc >= me->module_core &&
7697- loc <= (me->module_core + me->core_size));
7698+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7699 }
7700
7701 static inline int in_local(struct module *me, void *loc)
7702@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7703 }
7704
7705 /* align things a bit */
7706- me->core_size = ALIGN(me->core_size, 16);
7707- me->arch.got_offset = me->core_size;
7708- me->core_size += gots * sizeof(struct got_entry);
7709+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7710+ me->arch.got_offset = me->core_size_rw;
7711+ me->core_size_rw += gots * sizeof(struct got_entry);
7712
7713- me->core_size = ALIGN(me->core_size, 16);
7714- me->arch.fdesc_offset = me->core_size;
7715- me->core_size += fdescs * sizeof(Elf_Fdesc);
7716+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7717+ me->arch.fdesc_offset = me->core_size_rw;
7718+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7719
7720 me->arch.got_max = gots;
7721 me->arch.fdesc_max = fdescs;
7722@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7723
7724 BUG_ON(value == 0);
7725
7726- got = me->module_core + me->arch.got_offset;
7727+ got = me->module_core_rw + me->arch.got_offset;
7728 for (i = 0; got[i].addr; i++)
7729 if (got[i].addr == value)
7730 goto out;
7731@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7732 #ifdef CONFIG_64BIT
7733 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7734 {
7735- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7736+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7737
7738 if (!value) {
7739 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7740@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7741
7742 /* Create new one */
7743 fdesc->addr = value;
7744- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7745+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7746 return (Elf_Addr)fdesc;
7747 }
7748 #endif /* CONFIG_64BIT */
7749@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7750
7751 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7752 end = table + sechdrs[me->arch.unwind_section].sh_size;
7753- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7754+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7755
7756 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7757 me->arch.unwind_section, table, end, gp);
7758diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7759index e1ffea2..46ed66e 100644
7760--- a/arch/parisc/kernel/sys_parisc.c
7761+++ b/arch/parisc/kernel/sys_parisc.c
7762@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7763 unsigned long task_size = TASK_SIZE;
7764 int do_color_align, last_mmap;
7765 struct vm_unmapped_area_info info;
7766+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7767
7768 if (len > task_size)
7769 return -ENOMEM;
7770@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7771 goto found_addr;
7772 }
7773
7774+#ifdef CONFIG_PAX_RANDMMAP
7775+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7776+#endif
7777+
7778 if (addr) {
7779 if (do_color_align && last_mmap)
7780 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7781@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7782 info.high_limit = mmap_upper_limit();
7783 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7784 info.align_offset = shared_align_offset(last_mmap, pgoff);
7785+ info.threadstack_offset = offset;
7786 addr = vm_unmapped_area(&info);
7787
7788 found_addr:
7789@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7790 unsigned long addr = addr0;
7791 int do_color_align, last_mmap;
7792 struct vm_unmapped_area_info info;
7793+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7794
7795 #ifdef CONFIG_64BIT
7796 /* This should only ever run for 32-bit processes. */
7797@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7798 }
7799
7800 /* requesting a specific address */
7801+#ifdef CONFIG_PAX_RANDMMAP
7802+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7803+#endif
7804+
7805 if (addr) {
7806 if (do_color_align && last_mmap)
7807 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7808@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7809 info.high_limit = mm->mmap_base;
7810 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7811 info.align_offset = shared_align_offset(last_mmap, pgoff);
7812+ info.threadstack_offset = offset;
7813 addr = vm_unmapped_area(&info);
7814 if (!(addr & ~PAGE_MASK))
7815 goto found_addr;
7816@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7817 mm->mmap_legacy_base = mmap_legacy_base();
7818 mm->mmap_base = mmap_upper_limit();
7819
7820+#ifdef CONFIG_PAX_RANDMMAP
7821+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7822+ mm->mmap_legacy_base += mm->delta_mmap;
7823+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7824+ }
7825+#endif
7826+
7827 if (mmap_is_legacy()) {
7828 mm->mmap_base = mm->mmap_legacy_base;
7829 mm->get_unmapped_area = arch_get_unmapped_area;
7830diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7831index 47ee620..1107387 100644
7832--- a/arch/parisc/kernel/traps.c
7833+++ b/arch/parisc/kernel/traps.c
7834@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7835
7836 down_read(&current->mm->mmap_sem);
7837 vma = find_vma(current->mm,regs->iaoq[0]);
7838- if (vma && (regs->iaoq[0] >= vma->vm_start)
7839- && (vma->vm_flags & VM_EXEC)) {
7840-
7841+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7842 fault_address = regs->iaoq[0];
7843 fault_space = regs->iasq[0];
7844
7845diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7846index 3ca9c11..d163ef7 100644
7847--- a/arch/parisc/mm/fault.c
7848+++ b/arch/parisc/mm/fault.c
7849@@ -15,6 +15,7 @@
7850 #include <linux/sched.h>
7851 #include <linux/interrupt.h>
7852 #include <linux/module.h>
7853+#include <linux/unistd.h>
7854
7855 #include <asm/uaccess.h>
7856 #include <asm/traps.h>
7857@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7858 static unsigned long
7859 parisc_acctyp(unsigned long code, unsigned int inst)
7860 {
7861- if (code == 6 || code == 16)
7862+ if (code == 6 || code == 7 || code == 16)
7863 return VM_EXEC;
7864
7865 switch (inst & 0xf0000000) {
7866@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7867 }
7868 #endif
7869
7870+#ifdef CONFIG_PAX_PAGEEXEC
7871+/*
7872+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7873+ *
7874+ * returns 1 when task should be killed
7875+ * 2 when rt_sigreturn trampoline was detected
7876+ * 3 when unpatched PLT trampoline was detected
7877+ */
7878+static int pax_handle_fetch_fault(struct pt_regs *regs)
7879+{
7880+
7881+#ifdef CONFIG_PAX_EMUPLT
7882+ int err;
7883+
7884+ do { /* PaX: unpatched PLT emulation */
7885+ unsigned int bl, depwi;
7886+
7887+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7888+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7889+
7890+ if (err)
7891+ break;
7892+
7893+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7894+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7895+
7896+ err = get_user(ldw, (unsigned int *)addr);
7897+ err |= get_user(bv, (unsigned int *)(addr+4));
7898+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7899+
7900+ if (err)
7901+ break;
7902+
7903+ if (ldw == 0x0E801096U &&
7904+ bv == 0xEAC0C000U &&
7905+ ldw2 == 0x0E881095U)
7906+ {
7907+ unsigned int resolver, map;
7908+
7909+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7910+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7911+ if (err)
7912+ break;
7913+
7914+ regs->gr[20] = instruction_pointer(regs)+8;
7915+ regs->gr[21] = map;
7916+ regs->gr[22] = resolver;
7917+ regs->iaoq[0] = resolver | 3UL;
7918+ regs->iaoq[1] = regs->iaoq[0] + 4;
7919+ return 3;
7920+ }
7921+ }
7922+ } while (0);
7923+#endif
7924+
7925+#ifdef CONFIG_PAX_EMUTRAMP
7926+
7927+#ifndef CONFIG_PAX_EMUSIGRT
7928+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7929+ return 1;
7930+#endif
7931+
7932+ do { /* PaX: rt_sigreturn emulation */
7933+ unsigned int ldi1, ldi2, bel, nop;
7934+
7935+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7936+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7937+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7938+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7939+
7940+ if (err)
7941+ break;
7942+
7943+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7944+ ldi2 == 0x3414015AU &&
7945+ bel == 0xE4008200U &&
7946+ nop == 0x08000240U)
7947+ {
7948+ regs->gr[25] = (ldi1 & 2) >> 1;
7949+ regs->gr[20] = __NR_rt_sigreturn;
7950+ regs->gr[31] = regs->iaoq[1] + 16;
7951+ regs->sr[0] = regs->iasq[1];
7952+ regs->iaoq[0] = 0x100UL;
7953+ regs->iaoq[1] = regs->iaoq[0] + 4;
7954+ regs->iasq[0] = regs->sr[2];
7955+ regs->iasq[1] = regs->sr[2];
7956+ return 2;
7957+ }
7958+ } while (0);
7959+#endif
7960+
7961+ return 1;
7962+}
7963+
7964+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7965+{
7966+ unsigned long i;
7967+
7968+ printk(KERN_ERR "PAX: bytes at PC: ");
7969+ for (i = 0; i < 5; i++) {
7970+ unsigned int c;
7971+ if (get_user(c, (unsigned int *)pc+i))
7972+ printk(KERN_CONT "???????? ");
7973+ else
7974+ printk(KERN_CONT "%08x ", c);
7975+ }
7976+ printk("\n");
7977+}
7978+#endif
7979+
7980 int fixup_exception(struct pt_regs *regs)
7981 {
7982 const struct exception_table_entry *fix;
7983@@ -234,8 +345,33 @@ retry:
7984
7985 good_area:
7986
7987- if ((vma->vm_flags & acc_type) != acc_type)
7988+ if ((vma->vm_flags & acc_type) != acc_type) {
7989+
7990+#ifdef CONFIG_PAX_PAGEEXEC
7991+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7992+ (address & ~3UL) == instruction_pointer(regs))
7993+ {
7994+ up_read(&mm->mmap_sem);
7995+ switch (pax_handle_fetch_fault(regs)) {
7996+
7997+#ifdef CONFIG_PAX_EMUPLT
7998+ case 3:
7999+ return;
8000+#endif
8001+
8002+#ifdef CONFIG_PAX_EMUTRAMP
8003+ case 2:
8004+ return;
8005+#endif
8006+
8007+ }
8008+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8009+ do_group_exit(SIGKILL);
8010+ }
8011+#endif
8012+
8013 goto bad_area;
8014+ }
8015
8016 /*
8017 * If for any reason at all we couldn't handle the fault, make
8018diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8019index 004851f..c15e65a 100644
8020--- a/arch/powerpc/Kconfig
8021+++ b/arch/powerpc/Kconfig
8022@@ -398,6 +398,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8023 config KEXEC
8024 bool "kexec system call"
8025 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8026+ depends on !GRKERNSEC_KMEM
8027 help
8028 kexec is a system call that implements the ability to shutdown your
8029 current kernel, and to start another kernel. It is like a reboot
8030diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8031index e3b1d41..8e81edf 100644
8032--- a/arch/powerpc/include/asm/atomic.h
8033+++ b/arch/powerpc/include/asm/atomic.h
8034@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8035 return t1;
8036 }
8037
8038+#define atomic64_read_unchecked(v) atomic64_read(v)
8039+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8040+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8041+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8042+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8043+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8044+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8045+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8046+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8047+
8048 #endif /* __powerpc64__ */
8049
8050 #endif /* __KERNEL__ */
8051diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8052index f89da80..7f5b05a 100644
8053--- a/arch/powerpc/include/asm/barrier.h
8054+++ b/arch/powerpc/include/asm/barrier.h
8055@@ -73,7 +73,7 @@
8056 do { \
8057 compiletime_assert_atomic_type(*p); \
8058 __lwsync(); \
8059- ACCESS_ONCE(*p) = (v); \
8060+ ACCESS_ONCE_RW(*p) = (v); \
8061 } while (0)
8062
8063 #define smp_load_acquire(p) \
8064diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8065index ed0afc1..0332825 100644
8066--- a/arch/powerpc/include/asm/cache.h
8067+++ b/arch/powerpc/include/asm/cache.h
8068@@ -3,6 +3,7 @@
8069
8070 #ifdef __KERNEL__
8071
8072+#include <linux/const.h>
8073
8074 /* bytes per L1 cache line */
8075 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8076@@ -22,7 +23,7 @@
8077 #define L1_CACHE_SHIFT 7
8078 #endif
8079
8080-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8081+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8082
8083 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8084
8085diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8086index 935b5e7..7001d2d 100644
8087--- a/arch/powerpc/include/asm/elf.h
8088+++ b/arch/powerpc/include/asm/elf.h
8089@@ -28,8 +28,19 @@
8090 the loader. We need to make sure that it is out of the way of the program
8091 that it will "exec", and that there is sufficient room for the brk. */
8092
8093-extern unsigned long randomize_et_dyn(unsigned long base);
8094-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8095+#define ELF_ET_DYN_BASE (0x20000000)
8096+
8097+#ifdef CONFIG_PAX_ASLR
8098+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8099+
8100+#ifdef __powerpc64__
8101+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8102+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8103+#else
8104+#define PAX_DELTA_MMAP_LEN 15
8105+#define PAX_DELTA_STACK_LEN 15
8106+#endif
8107+#endif
8108
8109 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8110
8111@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8112 (0x7ff >> (PAGE_SHIFT - 12)) : \
8113 (0x3ffff >> (PAGE_SHIFT - 12)))
8114
8115-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8116-#define arch_randomize_brk arch_randomize_brk
8117-
8118-
8119 #ifdef CONFIG_SPU_BASE
8120 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8121 #define NT_SPU 1
8122diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8123index 8196e9c..d83a9f3 100644
8124--- a/arch/powerpc/include/asm/exec.h
8125+++ b/arch/powerpc/include/asm/exec.h
8126@@ -4,6 +4,6 @@
8127 #ifndef _ASM_POWERPC_EXEC_H
8128 #define _ASM_POWERPC_EXEC_H
8129
8130-extern unsigned long arch_align_stack(unsigned long sp);
8131+#define arch_align_stack(x) ((x) & ~0xfUL)
8132
8133 #endif /* _ASM_POWERPC_EXEC_H */
8134diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8135index 5acabbd..7ea14fa 100644
8136--- a/arch/powerpc/include/asm/kmap_types.h
8137+++ b/arch/powerpc/include/asm/kmap_types.h
8138@@ -10,7 +10,7 @@
8139 * 2 of the License, or (at your option) any later version.
8140 */
8141
8142-#define KM_TYPE_NR 16
8143+#define KM_TYPE_NR 17
8144
8145 #endif /* __KERNEL__ */
8146 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8147diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8148index b8da913..60b608a 100644
8149--- a/arch/powerpc/include/asm/local.h
8150+++ b/arch/powerpc/include/asm/local.h
8151@@ -9,15 +9,26 @@ typedef struct
8152 atomic_long_t a;
8153 } local_t;
8154
8155+typedef struct
8156+{
8157+ atomic_long_unchecked_t a;
8158+} local_unchecked_t;
8159+
8160 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8161
8162 #define local_read(l) atomic_long_read(&(l)->a)
8163+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8164 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8165+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8166
8167 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8168+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8169 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8170+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8171 #define local_inc(l) atomic_long_inc(&(l)->a)
8172+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8173 #define local_dec(l) atomic_long_dec(&(l)->a)
8174+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8175
8176 static __inline__ long local_add_return(long a, local_t *l)
8177 {
8178@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8179
8180 return t;
8181 }
8182+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8183
8184 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8185
8186@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8187
8188 return t;
8189 }
8190+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8191
8192 static __inline__ long local_inc_return(local_t *l)
8193 {
8194@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8195
8196 #define local_cmpxchg(l, o, n) \
8197 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8198+#define local_cmpxchg_unchecked(l, o, n) \
8199+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8200 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8201
8202 /**
8203diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8204index 8565c25..2865190 100644
8205--- a/arch/powerpc/include/asm/mman.h
8206+++ b/arch/powerpc/include/asm/mman.h
8207@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8208 }
8209 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8210
8211-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8212+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8213 {
8214 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8215 }
8216diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8217index 32e4e21..62afb12 100644
8218--- a/arch/powerpc/include/asm/page.h
8219+++ b/arch/powerpc/include/asm/page.h
8220@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8221 * and needs to be executable. This means the whole heap ends
8222 * up being executable.
8223 */
8224-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8225- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8226+#define VM_DATA_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_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8231 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8232@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8233 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8234 #endif
8235
8236+#define ktla_ktva(addr) (addr)
8237+#define ktva_ktla(addr) (addr)
8238+
8239 #ifndef CONFIG_PPC_BOOK3S_64
8240 /*
8241 * Use the top bit of the higher-level page table entries to indicate whether
8242diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8243index 88693ce..ac6f9ab 100644
8244--- a/arch/powerpc/include/asm/page_64.h
8245+++ b/arch/powerpc/include/asm/page_64.h
8246@@ -153,15 +153,18 @@ do { \
8247 * stack by default, so in the absence of a PT_GNU_STACK program header
8248 * we turn execute permission off.
8249 */
8250-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8251- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8252+#define VM_STACK_DEFAULT_FLAGS32 \
8253+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8254+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8255
8256 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8257 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8258
8259+#ifndef CONFIG_PAX_PAGEEXEC
8260 #define VM_STACK_DEFAULT_FLAGS \
8261 (is_32bit_task() ? \
8262 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8263+#endif
8264
8265 #include <asm-generic/getorder.h>
8266
8267diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8268index 4b0be20..c15a27d 100644
8269--- a/arch/powerpc/include/asm/pgalloc-64.h
8270+++ b/arch/powerpc/include/asm/pgalloc-64.h
8271@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8272 #ifndef CONFIG_PPC_64K_PAGES
8273
8274 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8275+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8276
8277 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8278 {
8279@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8280 pud_set(pud, (unsigned long)pmd);
8281 }
8282
8283+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8284+{
8285+ pud_populate(mm, pud, pmd);
8286+}
8287+
8288 #define pmd_populate(mm, pmd, pte_page) \
8289 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8290 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8291@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8292 #endif
8293
8294 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8295+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8296
8297 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8298 pte_t *pte)
8299diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8300index 3ebb188..e17dddf 100644
8301--- a/arch/powerpc/include/asm/pgtable.h
8302+++ b/arch/powerpc/include/asm/pgtable.h
8303@@ -2,6 +2,7 @@
8304 #define _ASM_POWERPC_PGTABLE_H
8305 #ifdef __KERNEL__
8306
8307+#include <linux/const.h>
8308 #ifndef __ASSEMBLY__
8309 #include <linux/mmdebug.h>
8310 #include <asm/processor.h> /* For TASK_SIZE */
8311diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8312index 4aad413..85d86bf 100644
8313--- a/arch/powerpc/include/asm/pte-hash32.h
8314+++ b/arch/powerpc/include/asm/pte-hash32.h
8315@@ -21,6 +21,7 @@
8316 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8317 #define _PAGE_USER 0x004 /* usermode access allowed */
8318 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8319+#define _PAGE_EXEC _PAGE_GUARDED
8320 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8321 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8322 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8323diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8324index e5d2e0b..9ac74b1 100644
8325--- a/arch/powerpc/include/asm/reg.h
8326+++ b/arch/powerpc/include/asm/reg.h
8327@@ -249,6 +249,7 @@
8328 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8329 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8330 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8331+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8332 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8333 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8334 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8335diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8336index ff51046..b982dd4 100644
8337--- a/arch/powerpc/include/asm/smp.h
8338+++ b/arch/powerpc/include/asm/smp.h
8339@@ -51,7 +51,7 @@ struct smp_ops_t {
8340 int (*cpu_disable)(void);
8341 void (*cpu_die)(unsigned int nr);
8342 int (*cpu_bootable)(unsigned int nr);
8343-};
8344+} __no_const;
8345
8346 extern void smp_send_debugger_break(void);
8347 extern void start_secondary_resume(void);
8348diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8349index b034ecd..af7e31f 100644
8350--- a/arch/powerpc/include/asm/thread_info.h
8351+++ b/arch/powerpc/include/asm/thread_info.h
8352@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8353 #if defined(CONFIG_PPC64)
8354 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8355 #endif
8356+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8357+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8358
8359 /* as above, but as bit values */
8360 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8361@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8362 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8363 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8364 #define _TIF_NOHZ (1<<TIF_NOHZ)
8365+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8366 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8367 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8368- _TIF_NOHZ)
8369+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8370
8371 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8372 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8373diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8374index 9485b43..3bd3c16 100644
8375--- a/arch/powerpc/include/asm/uaccess.h
8376+++ b/arch/powerpc/include/asm/uaccess.h
8377@@ -58,6 +58,7 @@
8378
8379 #endif
8380
8381+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8382 #define access_ok(type, addr, size) \
8383 (__chk_user_ptr(addr), \
8384 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8385@@ -318,52 +319,6 @@ do { \
8386 extern unsigned long __copy_tofrom_user(void __user *to,
8387 const void __user *from, unsigned long size);
8388
8389-#ifndef __powerpc64__
8390-
8391-static inline unsigned long copy_from_user(void *to,
8392- const void __user *from, unsigned long n)
8393-{
8394- unsigned long over;
8395-
8396- if (access_ok(VERIFY_READ, from, n))
8397- return __copy_tofrom_user((__force void __user *)to, from, n);
8398- if ((unsigned long)from < TASK_SIZE) {
8399- over = (unsigned long)from + n - TASK_SIZE;
8400- return __copy_tofrom_user((__force void __user *)to, from,
8401- n - over) + over;
8402- }
8403- return n;
8404-}
8405-
8406-static inline unsigned long copy_to_user(void __user *to,
8407- const void *from, unsigned long n)
8408-{
8409- unsigned long over;
8410-
8411- if (access_ok(VERIFY_WRITE, to, n))
8412- return __copy_tofrom_user(to, (__force void __user *)from, n);
8413- if ((unsigned long)to < TASK_SIZE) {
8414- over = (unsigned long)to + n - TASK_SIZE;
8415- return __copy_tofrom_user(to, (__force void __user *)from,
8416- n - over) + over;
8417- }
8418- return n;
8419-}
8420-
8421-#else /* __powerpc64__ */
8422-
8423-#define __copy_in_user(to, from, size) \
8424- __copy_tofrom_user((to), (from), (size))
8425-
8426-extern unsigned long copy_from_user(void *to, const void __user *from,
8427- unsigned long n);
8428-extern unsigned long copy_to_user(void __user *to, const void *from,
8429- unsigned long n);
8430-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8431- unsigned long n);
8432-
8433-#endif /* __powerpc64__ */
8434-
8435 static inline unsigned long __copy_from_user_inatomic(void *to,
8436 const void __user *from, unsigned long n)
8437 {
8438@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8439 if (ret == 0)
8440 return 0;
8441 }
8442+
8443+ if (!__builtin_constant_p(n))
8444+ check_object_size(to, n, false);
8445+
8446 return __copy_tofrom_user((__force void __user *)to, from, n);
8447 }
8448
8449@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8450 if (ret == 0)
8451 return 0;
8452 }
8453+
8454+ if (!__builtin_constant_p(n))
8455+ check_object_size(from, n, true);
8456+
8457 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8458 }
8459
8460@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8461 return __copy_to_user_inatomic(to, from, size);
8462 }
8463
8464+#ifndef __powerpc64__
8465+
8466+static inline unsigned long __must_check copy_from_user(void *to,
8467+ const void __user *from, unsigned long n)
8468+{
8469+ unsigned long over;
8470+
8471+ if ((long)n < 0)
8472+ return n;
8473+
8474+ if (access_ok(VERIFY_READ, from, n)) {
8475+ if (!__builtin_constant_p(n))
8476+ check_object_size(to, n, false);
8477+ return __copy_tofrom_user((__force void __user *)to, from, n);
8478+ }
8479+ if ((unsigned long)from < TASK_SIZE) {
8480+ over = (unsigned long)from + n - TASK_SIZE;
8481+ if (!__builtin_constant_p(n - over))
8482+ check_object_size(to, n - over, false);
8483+ return __copy_tofrom_user((__force void __user *)to, from,
8484+ n - over) + over;
8485+ }
8486+ return n;
8487+}
8488+
8489+static inline unsigned long __must_check copy_to_user(void __user *to,
8490+ const void *from, unsigned long n)
8491+{
8492+ unsigned long over;
8493+
8494+ if ((long)n < 0)
8495+ return n;
8496+
8497+ if (access_ok(VERIFY_WRITE, to, n)) {
8498+ if (!__builtin_constant_p(n))
8499+ check_object_size(from, n, true);
8500+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8501+ }
8502+ if ((unsigned long)to < TASK_SIZE) {
8503+ over = (unsigned long)to + n - TASK_SIZE;
8504+ if (!__builtin_constant_p(n))
8505+ check_object_size(from, n - over, true);
8506+ return __copy_tofrom_user(to, (__force void __user *)from,
8507+ n - over) + over;
8508+ }
8509+ return n;
8510+}
8511+
8512+#else /* __powerpc64__ */
8513+
8514+#define __copy_in_user(to, from, size) \
8515+ __copy_tofrom_user((to), (from), (size))
8516+
8517+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8518+{
8519+ if ((long)n < 0 || n > INT_MAX)
8520+ return n;
8521+
8522+ if (!__builtin_constant_p(n))
8523+ check_object_size(to, n, false);
8524+
8525+ if (likely(access_ok(VERIFY_READ, from, n)))
8526+ n = __copy_from_user(to, from, n);
8527+ else
8528+ memset(to, 0, n);
8529+ return n;
8530+}
8531+
8532+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8533+{
8534+ if ((long)n < 0 || n > INT_MAX)
8535+ return n;
8536+
8537+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8538+ if (!__builtin_constant_p(n))
8539+ check_object_size(from, n, true);
8540+ n = __copy_to_user(to, from, n);
8541+ }
8542+ return n;
8543+}
8544+
8545+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8546+ unsigned long n);
8547+
8548+#endif /* __powerpc64__ */
8549+
8550 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8551
8552 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8553diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8554index fcc9a89..07be2bb 100644
8555--- a/arch/powerpc/kernel/Makefile
8556+++ b/arch/powerpc/kernel/Makefile
8557@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8558 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8559 endif
8560
8561+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8562+
8563 obj-y := cputable.o ptrace.o syscalls.o \
8564 irq.o align.o signal_32.o pmc.o vdso.o \
8565 process.o systbl.o idle.o \
8566diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8567index c1bee3c..5b42583 100644
8568--- a/arch/powerpc/kernel/exceptions-64e.S
8569+++ b/arch/powerpc/kernel/exceptions-64e.S
8570@@ -1010,6 +1010,7 @@ storage_fault_common:
8571 std r14,_DAR(r1)
8572 std r15,_DSISR(r1)
8573 addi r3,r1,STACK_FRAME_OVERHEAD
8574+ bl .save_nvgprs
8575 mr r4,r14
8576 mr r5,r15
8577 ld r14,PACA_EXGEN+EX_R14(r13)
8578@@ -1018,8 +1019,7 @@ storage_fault_common:
8579 cmpdi r3,0
8580 bne- 1f
8581 b .ret_from_except_lite
8582-1: bl .save_nvgprs
8583- mr r5,r3
8584+1: mr r5,r3
8585 addi r3,r1,STACK_FRAME_OVERHEAD
8586 ld r4,_DAR(r1)
8587 bl .bad_page_fault
8588diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8589index 3afd391..18f9e36 100644
8590--- a/arch/powerpc/kernel/exceptions-64s.S
8591+++ b/arch/powerpc/kernel/exceptions-64s.S
8592@@ -1587,10 +1587,10 @@ handle_page_fault:
8593 11: ld r4,_DAR(r1)
8594 ld r5,_DSISR(r1)
8595 addi r3,r1,STACK_FRAME_OVERHEAD
8596+ bl .save_nvgprs
8597 bl .do_page_fault
8598 cmpdi r3,0
8599 beq+ 12f
8600- bl .save_nvgprs
8601 mr r5,r3
8602 addi r3,r1,STACK_FRAME_OVERHEAD
8603 lwz r4,_DAR(r1)
8604diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8605index ca1cd74..6f0241a 100644
8606--- a/arch/powerpc/kernel/irq.c
8607+++ b/arch/powerpc/kernel/irq.c
8608@@ -447,6 +447,8 @@ void migrate_irqs(void)
8609 }
8610 #endif
8611
8612+extern void gr_handle_kernel_exploit(void);
8613+
8614 static inline void check_stack_overflow(void)
8615 {
8616 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8617@@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8618 printk("do_IRQ: stack overflow: %ld\n",
8619 sp - sizeof(struct thread_info));
8620 dump_stack();
8621+ gr_handle_kernel_exploit();
8622 }
8623 #endif
8624 }
8625diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8626index 6cff040..74ac5d1b 100644
8627--- a/arch/powerpc/kernel/module_32.c
8628+++ b/arch/powerpc/kernel/module_32.c
8629@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8630 me->arch.core_plt_section = i;
8631 }
8632 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8633- printk("Module doesn't contain .plt or .init.plt sections.\n");
8634+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8635 return -ENOEXEC;
8636 }
8637
8638@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8639
8640 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8641 /* Init, or core PLT? */
8642- if (location >= mod->module_core
8643- && location < mod->module_core + mod->core_size)
8644+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8645+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8646 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8647- else
8648+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8649+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8650 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8651+ else {
8652+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8653+ return ~0UL;
8654+ }
8655
8656 /* Find this entry, or if that fails, the next avail. entry */
8657 while (entry->jump[0]) {
8658@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8659 }
8660 #ifdef CONFIG_DYNAMIC_FTRACE
8661 module->arch.tramp =
8662- do_plt_call(module->module_core,
8663+ do_plt_call(module->module_core_rx,
8664 (unsigned long)ftrace_caller,
8665 sechdrs, module);
8666 #endif
8667diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8668index 31d0215..206af70 100644
8669--- a/arch/powerpc/kernel/process.c
8670+++ b/arch/powerpc/kernel/process.c
8671@@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8672 * Lookup NIP late so we have the best change of getting the
8673 * above info out without failing
8674 */
8675- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8676- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8677+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8678+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8679 #endif
8680 show_stack(current, (unsigned long *) regs->gpr[1]);
8681 if (!user_mode(regs))
8682@@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8683 newsp = stack[0];
8684 ip = stack[STACK_FRAME_LR_SAVE];
8685 if (!firstframe || ip != lr) {
8686- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8687+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8688 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8689 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8690- printk(" (%pS)",
8691+ printk(" (%pA)",
8692 (void *)current->ret_stack[curr_frame].ret);
8693 curr_frame--;
8694 }
8695@@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8696 struct pt_regs *regs = (struct pt_regs *)
8697 (sp + STACK_FRAME_OVERHEAD);
8698 lr = regs->link;
8699- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8700+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8701 regs->trap, (void *)regs->nip, (void *)lr);
8702 firstframe = 1;
8703 }
8704@@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8705 mtspr(SPRN_CTRLT, ctrl);
8706 }
8707 #endif /* CONFIG_PPC64 */
8708-
8709-unsigned long arch_align_stack(unsigned long sp)
8710-{
8711- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8712- sp -= get_random_int() & ~PAGE_MASK;
8713- return sp & ~0xf;
8714-}
8715-
8716-static inline unsigned long brk_rnd(void)
8717-{
8718- unsigned long rnd = 0;
8719-
8720- /* 8MB for 32bit, 1GB for 64bit */
8721- if (is_32bit_task())
8722- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8723- else
8724- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8725-
8726- return rnd << PAGE_SHIFT;
8727-}
8728-
8729-unsigned long arch_randomize_brk(struct mm_struct *mm)
8730-{
8731- unsigned long base = mm->brk;
8732- unsigned long ret;
8733-
8734-#ifdef CONFIG_PPC_STD_MMU_64
8735- /*
8736- * If we are using 1TB segments and we are allowed to randomise
8737- * the heap, we can put it above 1TB so it is backed by a 1TB
8738- * segment. Otherwise the heap will be in the bottom 1TB
8739- * which always uses 256MB segments and this may result in a
8740- * performance penalty.
8741- */
8742- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8743- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8744-#endif
8745-
8746- ret = PAGE_ALIGN(base + brk_rnd());
8747-
8748- if (ret < mm->brk)
8749- return mm->brk;
8750-
8751- return ret;
8752-}
8753-
8754-unsigned long randomize_et_dyn(unsigned long base)
8755-{
8756- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8757-
8758- if (ret < base)
8759- return base;
8760-
8761- return ret;
8762-}
8763diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8764index 2e3d2bf..35df241 100644
8765--- a/arch/powerpc/kernel/ptrace.c
8766+++ b/arch/powerpc/kernel/ptrace.c
8767@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8768 return ret;
8769 }
8770
8771+#ifdef CONFIG_GRKERNSEC_SETXID
8772+extern void gr_delayed_cred_worker(void);
8773+#endif
8774+
8775 /*
8776 * We must return the syscall number to actually look up in the table.
8777 * This can be -1L to skip running any syscall at all.
8778@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8779
8780 secure_computing_strict(regs->gpr[0]);
8781
8782+#ifdef CONFIG_GRKERNSEC_SETXID
8783+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8784+ gr_delayed_cred_worker();
8785+#endif
8786+
8787 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8788 tracehook_report_syscall_entry(regs))
8789 /*
8790@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8791 {
8792 int step;
8793
8794+#ifdef CONFIG_GRKERNSEC_SETXID
8795+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8796+ gr_delayed_cred_worker();
8797+#endif
8798+
8799 audit_syscall_exit(regs);
8800
8801 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8802diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8803index 4e47db6..6dcc96e 100644
8804--- a/arch/powerpc/kernel/signal_32.c
8805+++ b/arch/powerpc/kernel/signal_32.c
8806@@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8807 /* Save user registers on the stack */
8808 frame = &rt_sf->uc.uc_mcontext;
8809 addr = frame;
8810- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8811+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8812 sigret = 0;
8813 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8814 } else {
8815diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8816index d501dc4..e5a0de0 100644
8817--- a/arch/powerpc/kernel/signal_64.c
8818+++ b/arch/powerpc/kernel/signal_64.c
8819@@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8820 current->thread.fp_state.fpscr = 0;
8821
8822 /* Set up to return from userspace. */
8823- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8824+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8825 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8826 } else {
8827 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8828diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8829index 1bd7ca2..9b78c2f 100644
8830--- a/arch/powerpc/kernel/traps.c
8831+++ b/arch/powerpc/kernel/traps.c
8832@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8833 return flags;
8834 }
8835
8836+extern void gr_handle_kernel_exploit(void);
8837+
8838 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8839 int signr)
8840 {
8841@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8842 panic("Fatal exception in interrupt");
8843 if (panic_on_oops)
8844 panic("Fatal exception");
8845+
8846+ gr_handle_kernel_exploit();
8847+
8848 do_exit(signr);
8849 }
8850
8851diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8852index ce74c33..0803371 100644
8853--- a/arch/powerpc/kernel/vdso.c
8854+++ b/arch/powerpc/kernel/vdso.c
8855@@ -35,6 +35,7 @@
8856 #include <asm/vdso.h>
8857 #include <asm/vdso_datapage.h>
8858 #include <asm/setup.h>
8859+#include <asm/mman.h>
8860
8861 #undef DEBUG
8862
8863@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8864 vdso_base = VDSO32_MBASE;
8865 #endif
8866
8867- current->mm->context.vdso_base = 0;
8868+ current->mm->context.vdso_base = ~0UL;
8869
8870 /* vDSO has a problem and was disabled, just don't "enable" it for the
8871 * process
8872@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8873 vdso_base = get_unmapped_area(NULL, vdso_base,
8874 (vdso_pages << PAGE_SHIFT) +
8875 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8876- 0, 0);
8877+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8878 if (IS_ERR_VALUE(vdso_base)) {
8879 rc = vdso_base;
8880 goto fail_mmapsem;
8881diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8882index 3cf541a..ab2d825 100644
8883--- a/arch/powerpc/kvm/powerpc.c
8884+++ b/arch/powerpc/kvm/powerpc.c
8885@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8886 }
8887 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8888
8889-int kvm_arch_init(void *opaque)
8890+int kvm_arch_init(const void *opaque)
8891 {
8892 return 0;
8893 }
8894diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8895index 5eea6f3..5d10396 100644
8896--- a/arch/powerpc/lib/usercopy_64.c
8897+++ b/arch/powerpc/lib/usercopy_64.c
8898@@ -9,22 +9,6 @@
8899 #include <linux/module.h>
8900 #include <asm/uaccess.h>
8901
8902-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8903-{
8904- if (likely(access_ok(VERIFY_READ, from, n)))
8905- n = __copy_from_user(to, from, n);
8906- else
8907- memset(to, 0, n);
8908- return n;
8909-}
8910-
8911-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8912-{
8913- if (likely(access_ok(VERIFY_WRITE, to, n)))
8914- n = __copy_to_user(to, from, n);
8915- return n;
8916-}
8917-
8918 unsigned long copy_in_user(void __user *to, const void __user *from,
8919 unsigned long n)
8920 {
8921@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8922 return n;
8923 }
8924
8925-EXPORT_SYMBOL(copy_from_user);
8926-EXPORT_SYMBOL(copy_to_user);
8927 EXPORT_SYMBOL(copy_in_user);
8928
8929diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8930index 51ab9e7..7d3c78b 100644
8931--- a/arch/powerpc/mm/fault.c
8932+++ b/arch/powerpc/mm/fault.c
8933@@ -33,6 +33,10 @@
8934 #include <linux/magic.h>
8935 #include <linux/ratelimit.h>
8936 #include <linux/context_tracking.h>
8937+#include <linux/slab.h>
8938+#include <linux/pagemap.h>
8939+#include <linux/compiler.h>
8940+#include <linux/unistd.h>
8941
8942 #include <asm/firmware.h>
8943 #include <asm/page.h>
8944@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8945 }
8946 #endif
8947
8948+#ifdef CONFIG_PAX_PAGEEXEC
8949+/*
8950+ * PaX: decide what to do with offenders (regs->nip = fault address)
8951+ *
8952+ * returns 1 when task should be killed
8953+ */
8954+static int pax_handle_fetch_fault(struct pt_regs *regs)
8955+{
8956+ return 1;
8957+}
8958+
8959+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8960+{
8961+ unsigned long i;
8962+
8963+ printk(KERN_ERR "PAX: bytes at PC: ");
8964+ for (i = 0; i < 5; i++) {
8965+ unsigned int c;
8966+ if (get_user(c, (unsigned int __user *)pc+i))
8967+ printk(KERN_CONT "???????? ");
8968+ else
8969+ printk(KERN_CONT "%08x ", c);
8970+ }
8971+ printk("\n");
8972+}
8973+#endif
8974+
8975 /*
8976 * Check whether the instruction at regs->nip is a store using
8977 * an update addressing form which will update r1.
8978@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8979 * indicate errors in DSISR but can validly be set in SRR1.
8980 */
8981 if (trap == 0x400)
8982- error_code &= 0x48200000;
8983+ error_code &= 0x58200000;
8984 else
8985 is_write = error_code & DSISR_ISSTORE;
8986 #else
8987@@ -378,7 +409,7 @@ good_area:
8988 * "undefined". Of those that can be set, this is the only
8989 * one which seems bad.
8990 */
8991- if (error_code & 0x10000000)
8992+ if (error_code & DSISR_GUARDED)
8993 /* Guarded storage error. */
8994 goto bad_area;
8995 #endif /* CONFIG_8xx */
8996@@ -393,7 +424,7 @@ good_area:
8997 * processors use the same I/D cache coherency mechanism
8998 * as embedded.
8999 */
9000- if (error_code & DSISR_PROTFAULT)
9001+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9002 goto bad_area;
9003 #endif /* CONFIG_PPC_STD_MMU */
9004
9005@@ -483,6 +514,23 @@ bad_area:
9006 bad_area_nosemaphore:
9007 /* User mode accesses cause a SIGSEGV */
9008 if (user_mode(regs)) {
9009+
9010+#ifdef CONFIG_PAX_PAGEEXEC
9011+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9012+#ifdef CONFIG_PPC_STD_MMU
9013+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9014+#else
9015+ if (is_exec && regs->nip == address) {
9016+#endif
9017+ switch (pax_handle_fetch_fault(regs)) {
9018+ }
9019+
9020+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9021+ do_group_exit(SIGKILL);
9022+ }
9023+ }
9024+#endif
9025+
9026 _exception(SIGSEGV, regs, code, address);
9027 goto bail;
9028 }
9029diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9030index cb8bdbe..cde4bc7 100644
9031--- a/arch/powerpc/mm/mmap.c
9032+++ b/arch/powerpc/mm/mmap.c
9033@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9034 return sysctl_legacy_va_layout;
9035 }
9036
9037-static unsigned long mmap_rnd(void)
9038+static unsigned long mmap_rnd(struct mm_struct *mm)
9039 {
9040 unsigned long rnd = 0;
9041
9042+#ifdef CONFIG_PAX_RANDMMAP
9043+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9044+#endif
9045+
9046 if (current->flags & PF_RANDOMIZE) {
9047 /* 8MB for 32bit, 1GB for 64bit */
9048 if (is_32bit_task())
9049@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9050 return rnd << PAGE_SHIFT;
9051 }
9052
9053-static inline unsigned long mmap_base(void)
9054+static inline unsigned long mmap_base(struct mm_struct *mm)
9055 {
9056 unsigned long gap = rlimit(RLIMIT_STACK);
9057
9058@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9059 else if (gap > MAX_GAP)
9060 gap = MAX_GAP;
9061
9062- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9063+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9064 }
9065
9066 /*
9067@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9068 */
9069 if (mmap_is_legacy()) {
9070 mm->mmap_base = TASK_UNMAPPED_BASE;
9071+
9072+#ifdef CONFIG_PAX_RANDMMAP
9073+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9074+ mm->mmap_base += mm->delta_mmap;
9075+#endif
9076+
9077 mm->get_unmapped_area = arch_get_unmapped_area;
9078 } else {
9079- mm->mmap_base = mmap_base();
9080+ mm->mmap_base = mmap_base(mm);
9081+
9082+#ifdef CONFIG_PAX_RANDMMAP
9083+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9084+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9085+#endif
9086+
9087 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9088 }
9089 }
9090diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9091index b0c75cc..ef7fb93 100644
9092--- a/arch/powerpc/mm/slice.c
9093+++ b/arch/powerpc/mm/slice.c
9094@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9095 if ((mm->task_size - len) < addr)
9096 return 0;
9097 vma = find_vma(mm, addr);
9098- return (!vma || (addr + len) <= vma->vm_start);
9099+ return check_heap_stack_gap(vma, addr, len, 0);
9100 }
9101
9102 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9103@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9104 info.align_offset = 0;
9105
9106 addr = TASK_UNMAPPED_BASE;
9107+
9108+#ifdef CONFIG_PAX_RANDMMAP
9109+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9110+ addr += mm->delta_mmap;
9111+#endif
9112+
9113 while (addr < TASK_SIZE) {
9114 info.low_limit = addr;
9115 if (!slice_scan_available(addr, available, 1, &addr))
9116@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9117 if (fixed && addr > (mm->task_size - len))
9118 return -ENOMEM;
9119
9120+#ifdef CONFIG_PAX_RANDMMAP
9121+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9122+ addr = 0;
9123+#endif
9124+
9125 /* If hint, make sure it matches our alignment restrictions */
9126 if (!fixed && addr) {
9127 addr = _ALIGN_UP(addr, 1ul << pshift);
9128diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9129index 4278acf..67fd0e6 100644
9130--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9131+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9132@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9133 }
9134
9135 static struct pci_ops scc_pciex_pci_ops = {
9136- scc_pciex_read_config,
9137- scc_pciex_write_config,
9138+ .read = scc_pciex_read_config,
9139+ .write = scc_pciex_write_config,
9140 };
9141
9142 static void pciex_clear_intr_all(unsigned int __iomem *base)
9143diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9144index 9098692..3d54cd1 100644
9145--- a/arch/powerpc/platforms/cell/spufs/file.c
9146+++ b/arch/powerpc/platforms/cell/spufs/file.c
9147@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9148 return VM_FAULT_NOPAGE;
9149 }
9150
9151-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9152+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9153 unsigned long address,
9154- void *buf, int len, int write)
9155+ void *buf, size_t len, int write)
9156 {
9157 struct spu_context *ctx = vma->vm_file->private_data;
9158 unsigned long offset = address - vma->vm_start;
9159diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9160index 1d47061..0714963 100644
9161--- a/arch/s390/include/asm/atomic.h
9162+++ b/arch/s390/include/asm/atomic.h
9163@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9164 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9165 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9166
9167+#define atomic64_read_unchecked(v) atomic64_read(v)
9168+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9169+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9170+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9171+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9172+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9173+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9174+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9175+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9176+
9177 #define smp_mb__before_atomic_dec() smp_mb()
9178 #define smp_mb__after_atomic_dec() smp_mb()
9179 #define smp_mb__before_atomic_inc() smp_mb()
9180diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9181index 578680f..0eb3b11 100644
9182--- a/arch/s390/include/asm/barrier.h
9183+++ b/arch/s390/include/asm/barrier.h
9184@@ -36,7 +36,7 @@
9185 do { \
9186 compiletime_assert_atomic_type(*p); \
9187 barrier(); \
9188- ACCESS_ONCE(*p) = (v); \
9189+ ACCESS_ONCE_RW(*p) = (v); \
9190 } while (0)
9191
9192 #define smp_load_acquire(p) \
9193diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9194index 4d7ccac..d03d0ad 100644
9195--- a/arch/s390/include/asm/cache.h
9196+++ b/arch/s390/include/asm/cache.h
9197@@ -9,8 +9,10 @@
9198 #ifndef __ARCH_S390_CACHE_H
9199 #define __ARCH_S390_CACHE_H
9200
9201-#define L1_CACHE_BYTES 256
9202+#include <linux/const.h>
9203+
9204 #define L1_CACHE_SHIFT 8
9205+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9206 #define NET_SKB_PAD 32
9207
9208 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9209diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9210index 78f4f87..598ce39 100644
9211--- a/arch/s390/include/asm/elf.h
9212+++ b/arch/s390/include/asm/elf.h
9213@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9214 the loader. We need to make sure that it is out of the way of the program
9215 that it will "exec", and that there is sufficient room for the brk. */
9216
9217-extern unsigned long randomize_et_dyn(unsigned long base);
9218-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9219+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9220+
9221+#ifdef CONFIG_PAX_ASLR
9222+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9223+
9224+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9225+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9226+#endif
9227
9228 /* This yields a mask that user programs can use to figure out what
9229 instruction set this CPU supports. */
9230@@ -222,9 +228,6 @@ struct linux_binprm;
9231 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9232 int arch_setup_additional_pages(struct linux_binprm *, int);
9233
9234-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9235-#define arch_randomize_brk arch_randomize_brk
9236-
9237 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9238
9239 #endif
9240diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9241index c4a93d6..4d2a9b4 100644
9242--- a/arch/s390/include/asm/exec.h
9243+++ b/arch/s390/include/asm/exec.h
9244@@ -7,6 +7,6 @@
9245 #ifndef __ASM_EXEC_H
9246 #define __ASM_EXEC_H
9247
9248-extern unsigned long arch_align_stack(unsigned long sp);
9249+#define arch_align_stack(x) ((x) & ~0xfUL)
9250
9251 #endif /* __ASM_EXEC_H */
9252diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9253index 1be64a1..086839d1 100644
9254--- a/arch/s390/include/asm/uaccess.h
9255+++ b/arch/s390/include/asm/uaccess.h
9256@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9257 __range_ok((unsigned long)(addr), (size)); \
9258 })
9259
9260+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9261 #define access_ok(type, addr, size) __access_ok(addr, size)
9262
9263 /*
9264@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9265 copy_to_user(void __user *to, const void *from, unsigned long n)
9266 {
9267 might_fault();
9268+
9269+ if ((long)n < 0)
9270+ return n;
9271+
9272 return __copy_to_user(to, from, n);
9273 }
9274
9275@@ -273,10 +278,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9276 static inline unsigned long __must_check
9277 copy_from_user(void *to, const void __user *from, unsigned long n)
9278 {
9279- unsigned int sz = __compiletime_object_size(to);
9280+ size_t sz = __compiletime_object_size(to);
9281
9282 might_fault();
9283- if (unlikely(sz != -1 && sz < n)) {
9284+
9285+ if ((long)n < 0)
9286+ return n;
9287+
9288+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9289 copy_from_user_overflow();
9290 return n;
9291 }
9292diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9293index b89b591..fd9609d 100644
9294--- a/arch/s390/kernel/module.c
9295+++ b/arch/s390/kernel/module.c
9296@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9297
9298 /* Increase core size by size of got & plt and set start
9299 offsets for got and plt. */
9300- me->core_size = ALIGN(me->core_size, 4);
9301- me->arch.got_offset = me->core_size;
9302- me->core_size += me->arch.got_size;
9303- me->arch.plt_offset = me->core_size;
9304- me->core_size += me->arch.plt_size;
9305+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9306+ me->arch.got_offset = me->core_size_rw;
9307+ me->core_size_rw += me->arch.got_size;
9308+ me->arch.plt_offset = me->core_size_rx;
9309+ me->core_size_rx += me->arch.plt_size;
9310 return 0;
9311 }
9312
9313@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9314 if (info->got_initialized == 0) {
9315 Elf_Addr *gotent;
9316
9317- gotent = me->module_core + me->arch.got_offset +
9318+ gotent = me->module_core_rw + me->arch.got_offset +
9319 info->got_offset;
9320 *gotent = val;
9321 info->got_initialized = 1;
9322@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9323 rc = apply_rela_bits(loc, val, 0, 64, 0);
9324 else if (r_type == R_390_GOTENT ||
9325 r_type == R_390_GOTPLTENT) {
9326- val += (Elf_Addr) me->module_core - loc;
9327+ val += (Elf_Addr) me->module_core_rw - loc;
9328 rc = apply_rela_bits(loc, val, 1, 32, 1);
9329 }
9330 break;
9331@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9332 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9333 if (info->plt_initialized == 0) {
9334 unsigned int *ip;
9335- ip = me->module_core + me->arch.plt_offset +
9336+ ip = me->module_core_rx + me->arch.plt_offset +
9337 info->plt_offset;
9338 #ifndef CONFIG_64BIT
9339 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9340@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9341 val - loc + 0xffffUL < 0x1ffffeUL) ||
9342 (r_type == R_390_PLT32DBL &&
9343 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9344- val = (Elf_Addr) me->module_core +
9345+ val = (Elf_Addr) me->module_core_rx +
9346 me->arch.plt_offset +
9347 info->plt_offset;
9348 val += rela->r_addend - loc;
9349@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9350 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9351 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9352 val = val + rela->r_addend -
9353- ((Elf_Addr) me->module_core + me->arch.got_offset);
9354+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9355 if (r_type == R_390_GOTOFF16)
9356 rc = apply_rela_bits(loc, val, 0, 16, 0);
9357 else if (r_type == R_390_GOTOFF32)
9358@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9359 break;
9360 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9361 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9362- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9363+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9364 rela->r_addend - loc;
9365 if (r_type == R_390_GOTPC)
9366 rc = apply_rela_bits(loc, val, 1, 32, 0);
9367diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9368index dd14532..1dfc145 100644
9369--- a/arch/s390/kernel/process.c
9370+++ b/arch/s390/kernel/process.c
9371@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9372 }
9373 return 0;
9374 }
9375-
9376-unsigned long arch_align_stack(unsigned long sp)
9377-{
9378- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9379- sp -= get_random_int() & ~PAGE_MASK;
9380- return sp & ~0xf;
9381-}
9382-
9383-static inline unsigned long brk_rnd(void)
9384-{
9385- /* 8MB for 32bit, 1GB for 64bit */
9386- if (is_32bit_task())
9387- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9388- else
9389- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9390-}
9391-
9392-unsigned long arch_randomize_brk(struct mm_struct *mm)
9393-{
9394- unsigned long ret;
9395-
9396- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9397- return (ret > mm->brk) ? ret : mm->brk;
9398-}
9399-
9400-unsigned long randomize_et_dyn(unsigned long base)
9401-{
9402- unsigned long ret;
9403-
9404- if (!(current->flags & PF_RANDOMIZE))
9405- return base;
9406- ret = PAGE_ALIGN(base + brk_rnd());
9407- return (ret > base) ? ret : base;
9408-}
9409diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9410index 9b436c2..54fbf0a 100644
9411--- a/arch/s390/mm/mmap.c
9412+++ b/arch/s390/mm/mmap.c
9413@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9414 */
9415 if (mmap_is_legacy()) {
9416 mm->mmap_base = mmap_base_legacy();
9417+
9418+#ifdef CONFIG_PAX_RANDMMAP
9419+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9420+ mm->mmap_base += mm->delta_mmap;
9421+#endif
9422+
9423 mm->get_unmapped_area = arch_get_unmapped_area;
9424 } else {
9425 mm->mmap_base = mmap_base();
9426+
9427+#ifdef CONFIG_PAX_RANDMMAP
9428+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9429+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9430+#endif
9431+
9432 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9433 }
9434 }
9435@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9436 */
9437 if (mmap_is_legacy()) {
9438 mm->mmap_base = mmap_base_legacy();
9439+
9440+#ifdef CONFIG_PAX_RANDMMAP
9441+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9442+ mm->mmap_base += mm->delta_mmap;
9443+#endif
9444+
9445 mm->get_unmapped_area = s390_get_unmapped_area;
9446 } else {
9447 mm->mmap_base = mmap_base();
9448+
9449+#ifdef CONFIG_PAX_RANDMMAP
9450+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9451+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9452+#endif
9453+
9454 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9455 }
9456 }
9457diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9458index ae3d59f..f65f075 100644
9459--- a/arch/score/include/asm/cache.h
9460+++ b/arch/score/include/asm/cache.h
9461@@ -1,7 +1,9 @@
9462 #ifndef _ASM_SCORE_CACHE_H
9463 #define _ASM_SCORE_CACHE_H
9464
9465+#include <linux/const.h>
9466+
9467 #define L1_CACHE_SHIFT 4
9468-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9469+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9470
9471 #endif /* _ASM_SCORE_CACHE_H */
9472diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9473index f9f3cd5..58ff438 100644
9474--- a/arch/score/include/asm/exec.h
9475+++ b/arch/score/include/asm/exec.h
9476@@ -1,6 +1,6 @@
9477 #ifndef _ASM_SCORE_EXEC_H
9478 #define _ASM_SCORE_EXEC_H
9479
9480-extern unsigned long arch_align_stack(unsigned long sp);
9481+#define arch_align_stack(x) (x)
9482
9483 #endif /* _ASM_SCORE_EXEC_H */
9484diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9485index a1519ad3..e8ac1ff 100644
9486--- a/arch/score/kernel/process.c
9487+++ b/arch/score/kernel/process.c
9488@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9489
9490 return task_pt_regs(task)->cp0_epc;
9491 }
9492-
9493-unsigned long arch_align_stack(unsigned long sp)
9494-{
9495- return sp;
9496-}
9497diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9498index ef9e555..331bd29 100644
9499--- a/arch/sh/include/asm/cache.h
9500+++ b/arch/sh/include/asm/cache.h
9501@@ -9,10 +9,11 @@
9502 #define __ASM_SH_CACHE_H
9503 #ifdef __KERNEL__
9504
9505+#include <linux/const.h>
9506 #include <linux/init.h>
9507 #include <cpu/cache.h>
9508
9509-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9510+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9511
9512 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9513
9514diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9515index 6777177..cb5e44f 100644
9516--- a/arch/sh/mm/mmap.c
9517+++ b/arch/sh/mm/mmap.c
9518@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9519 struct mm_struct *mm = current->mm;
9520 struct vm_area_struct *vma;
9521 int do_colour_align;
9522+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9523 struct vm_unmapped_area_info info;
9524
9525 if (flags & MAP_FIXED) {
9526@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9527 if (filp || (flags & MAP_SHARED))
9528 do_colour_align = 1;
9529
9530+#ifdef CONFIG_PAX_RANDMMAP
9531+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9532+#endif
9533+
9534 if (addr) {
9535 if (do_colour_align)
9536 addr = COLOUR_ALIGN(addr, pgoff);
9537@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9538 addr = PAGE_ALIGN(addr);
9539
9540 vma = find_vma(mm, addr);
9541- if (TASK_SIZE - len >= addr &&
9542- (!vma || addr + len <= vma->vm_start))
9543+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9544 return addr;
9545 }
9546
9547 info.flags = 0;
9548 info.length = len;
9549- info.low_limit = TASK_UNMAPPED_BASE;
9550+ info.low_limit = mm->mmap_base;
9551 info.high_limit = TASK_SIZE;
9552 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9553 info.align_offset = pgoff << PAGE_SHIFT;
9554@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9555 struct mm_struct *mm = current->mm;
9556 unsigned long addr = addr0;
9557 int do_colour_align;
9558+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9559 struct vm_unmapped_area_info info;
9560
9561 if (flags & MAP_FIXED) {
9562@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9563 if (filp || (flags & MAP_SHARED))
9564 do_colour_align = 1;
9565
9566+#ifdef CONFIG_PAX_RANDMMAP
9567+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9568+#endif
9569+
9570 /* requesting a specific address */
9571 if (addr) {
9572 if (do_colour_align)
9573@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9574 addr = PAGE_ALIGN(addr);
9575
9576 vma = find_vma(mm, addr);
9577- if (TASK_SIZE - len >= addr &&
9578- (!vma || addr + len <= vma->vm_start))
9579+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9580 return addr;
9581 }
9582
9583@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9584 VM_BUG_ON(addr != -ENOMEM);
9585 info.flags = 0;
9586 info.low_limit = TASK_UNMAPPED_BASE;
9587+
9588+#ifdef CONFIG_PAX_RANDMMAP
9589+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9590+ info.low_limit += mm->delta_mmap;
9591+#endif
9592+
9593 info.high_limit = TASK_SIZE;
9594 addr = vm_unmapped_area(&info);
9595 }
9596diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9597index be56a24..443328f 100644
9598--- a/arch/sparc/include/asm/atomic_64.h
9599+++ b/arch/sparc/include/asm/atomic_64.h
9600@@ -14,18 +14,40 @@
9601 #define ATOMIC64_INIT(i) { (i) }
9602
9603 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9604+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9605+{
9606+ return v->counter;
9607+}
9608 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9609+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9610+{
9611+ return v->counter;
9612+}
9613
9614 #define atomic_set(v, i) (((v)->counter) = i)
9615+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9616+{
9617+ v->counter = i;
9618+}
9619 #define atomic64_set(v, i) (((v)->counter) = i)
9620+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9621+{
9622+ v->counter = i;
9623+}
9624
9625 extern void atomic_add(int, atomic_t *);
9626+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9627 extern void atomic64_add(long, atomic64_t *);
9628+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9629 extern void atomic_sub(int, atomic_t *);
9630+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9631 extern void atomic64_sub(long, atomic64_t *);
9632+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9633
9634 extern int atomic_add_ret(int, atomic_t *);
9635+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9636 extern long atomic64_add_ret(long, atomic64_t *);
9637+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9638 extern int atomic_sub_ret(int, atomic_t *);
9639 extern long atomic64_sub_ret(long, atomic64_t *);
9640
9641@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9642 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9643
9644 #define atomic_inc_return(v) atomic_add_ret(1, v)
9645+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9646+{
9647+ return atomic_add_ret_unchecked(1, v);
9648+}
9649 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9650+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9651+{
9652+ return atomic64_add_ret_unchecked(1, v);
9653+}
9654
9655 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9656 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9657
9658 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9659+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9660+{
9661+ return atomic_add_ret_unchecked(i, v);
9662+}
9663 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9664+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9665+{
9666+ return atomic64_add_ret_unchecked(i, v);
9667+}
9668
9669 /*
9670 * atomic_inc_and_test - increment and test
9671@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9672 * other cases.
9673 */
9674 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9675+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9676+{
9677+ return atomic_inc_return_unchecked(v) == 0;
9678+}
9679 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9680
9681 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9682@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9683 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9684
9685 #define atomic_inc(v) atomic_add(1, v)
9686+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9687+{
9688+ atomic_add_unchecked(1, v);
9689+}
9690 #define atomic64_inc(v) atomic64_add(1, v)
9691+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9692+{
9693+ atomic64_add_unchecked(1, v);
9694+}
9695
9696 #define atomic_dec(v) atomic_sub(1, v)
9697+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9698+{
9699+ atomic_sub_unchecked(1, v);
9700+}
9701 #define atomic64_dec(v) atomic64_sub(1, v)
9702+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9703+{
9704+ atomic64_sub_unchecked(1, v);
9705+}
9706
9707 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9708 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9709
9710 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9711+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9712+{
9713+ return cmpxchg(&v->counter, old, new);
9714+}
9715 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9716+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9717+{
9718+ return xchg(&v->counter, new);
9719+}
9720
9721 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9722 {
9723- int c, old;
9724+ int c, old, new;
9725 c = atomic_read(v);
9726 for (;;) {
9727- if (unlikely(c == (u)))
9728+ if (unlikely(c == u))
9729 break;
9730- old = atomic_cmpxchg((v), c, c + (a));
9731+
9732+ asm volatile("addcc %2, %0, %0\n"
9733+
9734+#ifdef CONFIG_PAX_REFCOUNT
9735+ "tvs %%icc, 6\n"
9736+#endif
9737+
9738+ : "=r" (new)
9739+ : "0" (c), "ir" (a)
9740+ : "cc");
9741+
9742+ old = atomic_cmpxchg(v, c, new);
9743 if (likely(old == c))
9744 break;
9745 c = old;
9746@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9747 #define atomic64_cmpxchg(v, o, n) \
9748 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9749 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9750+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9751+{
9752+ return xchg(&v->counter, new);
9753+}
9754
9755 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9756 {
9757- long c, old;
9758+ long c, old, new;
9759 c = atomic64_read(v);
9760 for (;;) {
9761- if (unlikely(c == (u)))
9762+ if (unlikely(c == u))
9763 break;
9764- old = atomic64_cmpxchg((v), c, c + (a));
9765+
9766+ asm volatile("addcc %2, %0, %0\n"
9767+
9768+#ifdef CONFIG_PAX_REFCOUNT
9769+ "tvs %%xcc, 6\n"
9770+#endif
9771+
9772+ : "=r" (new)
9773+ : "0" (c), "ir" (a)
9774+ : "cc");
9775+
9776+ old = atomic64_cmpxchg(v, c, new);
9777 if (likely(old == c))
9778 break;
9779 c = old;
9780 }
9781- return c != (u);
9782+ return c != u;
9783 }
9784
9785 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9786diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
9787index b5aad96..99d7465 100644
9788--- a/arch/sparc/include/asm/barrier_64.h
9789+++ b/arch/sparc/include/asm/barrier_64.h
9790@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
9791 do { \
9792 compiletime_assert_atomic_type(*p); \
9793 barrier(); \
9794- ACCESS_ONCE(*p) = (v); \
9795+ ACCESS_ONCE_RW(*p) = (v); \
9796 } while (0)
9797
9798 #define smp_load_acquire(p) \
9799diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9800index 5bb6991..5c2132e 100644
9801--- a/arch/sparc/include/asm/cache.h
9802+++ b/arch/sparc/include/asm/cache.h
9803@@ -7,10 +7,12 @@
9804 #ifndef _SPARC_CACHE_H
9805 #define _SPARC_CACHE_H
9806
9807+#include <linux/const.h>
9808+
9809 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9810
9811 #define L1_CACHE_SHIFT 5
9812-#define L1_CACHE_BYTES 32
9813+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9814
9815 #ifdef CONFIG_SPARC32
9816 #define SMP_CACHE_BYTES_SHIFT 5
9817diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9818index a24e41f..47677ff 100644
9819--- a/arch/sparc/include/asm/elf_32.h
9820+++ b/arch/sparc/include/asm/elf_32.h
9821@@ -114,6 +114,13 @@ typedef struct {
9822
9823 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9824
9825+#ifdef CONFIG_PAX_ASLR
9826+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9827+
9828+#define PAX_DELTA_MMAP_LEN 16
9829+#define PAX_DELTA_STACK_LEN 16
9830+#endif
9831+
9832 /* This yields a mask that user programs can use to figure out what
9833 instruction set this cpu supports. This can NOT be done in userspace
9834 on Sparc. */
9835diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9836index 370ca1e..d4f4a98 100644
9837--- a/arch/sparc/include/asm/elf_64.h
9838+++ b/arch/sparc/include/asm/elf_64.h
9839@@ -189,6 +189,13 @@ typedef struct {
9840 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9841 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9842
9843+#ifdef CONFIG_PAX_ASLR
9844+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9845+
9846+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9847+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9848+#endif
9849+
9850 extern unsigned long sparc64_elf_hwcap;
9851 #define ELF_HWCAP sparc64_elf_hwcap
9852
9853diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9854index 9b1c36d..209298b 100644
9855--- a/arch/sparc/include/asm/pgalloc_32.h
9856+++ b/arch/sparc/include/asm/pgalloc_32.h
9857@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9858 }
9859
9860 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9861+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9862
9863 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9864 unsigned long address)
9865diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9866index bcfe063..b333142 100644
9867--- a/arch/sparc/include/asm/pgalloc_64.h
9868+++ b/arch/sparc/include/asm/pgalloc_64.h
9869@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9870 }
9871
9872 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9873+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9874
9875 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9876 {
9877diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9878index 59ba6f6..4518128 100644
9879--- a/arch/sparc/include/asm/pgtable.h
9880+++ b/arch/sparc/include/asm/pgtable.h
9881@@ -5,4 +5,8 @@
9882 #else
9883 #include <asm/pgtable_32.h>
9884 #endif
9885+
9886+#define ktla_ktva(addr) (addr)
9887+#define ktva_ktla(addr) (addr)
9888+
9889 #endif
9890diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9891index 502f632..da1917f 100644
9892--- a/arch/sparc/include/asm/pgtable_32.h
9893+++ b/arch/sparc/include/asm/pgtable_32.h
9894@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9895 #define PAGE_SHARED SRMMU_PAGE_SHARED
9896 #define PAGE_COPY SRMMU_PAGE_COPY
9897 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9898+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9899+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9900+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9901 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9902
9903 /* Top-level page directory - dummy used by init-mm.
9904@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9905
9906 /* xwr */
9907 #define __P000 PAGE_NONE
9908-#define __P001 PAGE_READONLY
9909-#define __P010 PAGE_COPY
9910-#define __P011 PAGE_COPY
9911+#define __P001 PAGE_READONLY_NOEXEC
9912+#define __P010 PAGE_COPY_NOEXEC
9913+#define __P011 PAGE_COPY_NOEXEC
9914 #define __P100 PAGE_READONLY
9915 #define __P101 PAGE_READONLY
9916 #define __P110 PAGE_COPY
9917 #define __P111 PAGE_COPY
9918
9919 #define __S000 PAGE_NONE
9920-#define __S001 PAGE_READONLY
9921-#define __S010 PAGE_SHARED
9922-#define __S011 PAGE_SHARED
9923+#define __S001 PAGE_READONLY_NOEXEC
9924+#define __S010 PAGE_SHARED_NOEXEC
9925+#define __S011 PAGE_SHARED_NOEXEC
9926 #define __S100 PAGE_READONLY
9927 #define __S101 PAGE_READONLY
9928 #define __S110 PAGE_SHARED
9929diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9930index 79da178..c2eede8 100644
9931--- a/arch/sparc/include/asm/pgtsrmmu.h
9932+++ b/arch/sparc/include/asm/pgtsrmmu.h
9933@@ -115,6 +115,11 @@
9934 SRMMU_EXEC | SRMMU_REF)
9935 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9936 SRMMU_EXEC | SRMMU_REF)
9937+
9938+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9939+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9940+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9941+
9942 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9943 SRMMU_DIRTY | SRMMU_REF)
9944
9945diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9946index 9689176..63c18ea 100644
9947--- a/arch/sparc/include/asm/spinlock_64.h
9948+++ b/arch/sparc/include/asm/spinlock_64.h
9949@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9950
9951 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9952
9953-static void inline arch_read_lock(arch_rwlock_t *lock)
9954+static inline void arch_read_lock(arch_rwlock_t *lock)
9955 {
9956 unsigned long tmp1, tmp2;
9957
9958 __asm__ __volatile__ (
9959 "1: ldsw [%2], %0\n"
9960 " brlz,pn %0, 2f\n"
9961-"4: add %0, 1, %1\n"
9962+"4: addcc %0, 1, %1\n"
9963+
9964+#ifdef CONFIG_PAX_REFCOUNT
9965+" tvs %%icc, 6\n"
9966+#endif
9967+
9968 " cas [%2], %0, %1\n"
9969 " cmp %0, %1\n"
9970 " bne,pn %%icc, 1b\n"
9971@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9972 " .previous"
9973 : "=&r" (tmp1), "=&r" (tmp2)
9974 : "r" (lock)
9975- : "memory");
9976+ : "memory", "cc");
9977 }
9978
9979-static int inline arch_read_trylock(arch_rwlock_t *lock)
9980+static inline int arch_read_trylock(arch_rwlock_t *lock)
9981 {
9982 int tmp1, tmp2;
9983
9984@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9985 "1: ldsw [%2], %0\n"
9986 " brlz,a,pn %0, 2f\n"
9987 " mov 0, %0\n"
9988-" add %0, 1, %1\n"
9989+" addcc %0, 1, %1\n"
9990+
9991+#ifdef CONFIG_PAX_REFCOUNT
9992+" tvs %%icc, 6\n"
9993+#endif
9994+
9995 " cas [%2], %0, %1\n"
9996 " cmp %0, %1\n"
9997 " bne,pn %%icc, 1b\n"
9998@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9999 return tmp1;
10000 }
10001
10002-static void inline arch_read_unlock(arch_rwlock_t *lock)
10003+static inline void arch_read_unlock(arch_rwlock_t *lock)
10004 {
10005 unsigned long tmp1, tmp2;
10006
10007 __asm__ __volatile__(
10008 "1: lduw [%2], %0\n"
10009-" sub %0, 1, %1\n"
10010+" subcc %0, 1, %1\n"
10011+
10012+#ifdef CONFIG_PAX_REFCOUNT
10013+" tvs %%icc, 6\n"
10014+#endif
10015+
10016 " cas [%2], %0, %1\n"
10017 " cmp %0, %1\n"
10018 " bne,pn %%xcc, 1b\n"
10019@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10020 : "memory");
10021 }
10022
10023-static void inline arch_write_lock(arch_rwlock_t *lock)
10024+static inline void arch_write_lock(arch_rwlock_t *lock)
10025 {
10026 unsigned long mask, tmp1, tmp2;
10027
10028@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10029 : "memory");
10030 }
10031
10032-static void inline arch_write_unlock(arch_rwlock_t *lock)
10033+static inline void arch_write_unlock(arch_rwlock_t *lock)
10034 {
10035 __asm__ __volatile__(
10036 " stw %%g0, [%0]"
10037@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10038 : "memory");
10039 }
10040
10041-static int inline arch_write_trylock(arch_rwlock_t *lock)
10042+static inline int arch_write_trylock(arch_rwlock_t *lock)
10043 {
10044 unsigned long mask, tmp1, tmp2, result;
10045
10046diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10047index 96efa7a..16858bf 100644
10048--- a/arch/sparc/include/asm/thread_info_32.h
10049+++ b/arch/sparc/include/asm/thread_info_32.h
10050@@ -49,6 +49,8 @@ struct thread_info {
10051 unsigned long w_saved;
10052
10053 struct restart_block restart_block;
10054+
10055+ unsigned long lowest_stack;
10056 };
10057
10058 /*
10059diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10060index a5f01ac..703b554 100644
10061--- a/arch/sparc/include/asm/thread_info_64.h
10062+++ b/arch/sparc/include/asm/thread_info_64.h
10063@@ -63,6 +63,8 @@ struct thread_info {
10064 struct pt_regs *kern_una_regs;
10065 unsigned int kern_una_insn;
10066
10067+ unsigned long lowest_stack;
10068+
10069 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10070 };
10071
10072@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10073 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10074 /* flag bit 4 is available */
10075 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10076-/* flag bit 6 is available */
10077+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10078 #define TIF_32BIT 7 /* 32-bit binary */
10079 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10080 #define TIF_SECCOMP 9 /* secure computing */
10081 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10082 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10083+
10084 /* NOTE: Thread flags >= 12 should be ones we have no interest
10085 * in using in assembly, else we can't use the mask as
10086 * an immediate value in instructions such as andcc.
10087@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10088 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10089 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10090 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10091+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10092
10093 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10094 _TIF_DO_NOTIFY_RESUME_MASK | \
10095 _TIF_NEED_RESCHED)
10096 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10097
10098+#define _TIF_WORK_SYSCALL \
10099+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10100+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10101+
10102+
10103 /*
10104 * Thread-synchronous status.
10105 *
10106diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10107index 0167d26..767bb0c 100644
10108--- a/arch/sparc/include/asm/uaccess.h
10109+++ b/arch/sparc/include/asm/uaccess.h
10110@@ -1,5 +1,6 @@
10111 #ifndef ___ASM_SPARC_UACCESS_H
10112 #define ___ASM_SPARC_UACCESS_H
10113+
10114 #if defined(__sparc__) && defined(__arch64__)
10115 #include <asm/uaccess_64.h>
10116 #else
10117diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10118index 53a28dd..50c38c3 100644
10119--- a/arch/sparc/include/asm/uaccess_32.h
10120+++ b/arch/sparc/include/asm/uaccess_32.h
10121@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10122
10123 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10124 {
10125- if (n && __access_ok((unsigned long) to, n))
10126+ if ((long)n < 0)
10127+ return n;
10128+
10129+ if (n && __access_ok((unsigned long) to, n)) {
10130+ if (!__builtin_constant_p(n))
10131+ check_object_size(from, n, true);
10132 return __copy_user(to, (__force void __user *) from, n);
10133- else
10134+ } else
10135 return n;
10136 }
10137
10138 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10139 {
10140+ if ((long)n < 0)
10141+ return n;
10142+
10143+ if (!__builtin_constant_p(n))
10144+ check_object_size(from, n, true);
10145+
10146 return __copy_user(to, (__force void __user *) from, n);
10147 }
10148
10149 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10150 {
10151- if (n && __access_ok((unsigned long) from, n))
10152+ if ((long)n < 0)
10153+ return n;
10154+
10155+ if (n && __access_ok((unsigned long) from, n)) {
10156+ if (!__builtin_constant_p(n))
10157+ check_object_size(to, n, false);
10158 return __copy_user((__force void __user *) to, from, n);
10159- else
10160+ } else
10161 return n;
10162 }
10163
10164 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10165 {
10166+ if ((long)n < 0)
10167+ return n;
10168+
10169 return __copy_user((__force void __user *) to, from, n);
10170 }
10171
10172diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10173index ad7e178..c9e7423 100644
10174--- a/arch/sparc/include/asm/uaccess_64.h
10175+++ b/arch/sparc/include/asm/uaccess_64.h
10176@@ -10,6 +10,7 @@
10177 #include <linux/compiler.h>
10178 #include <linux/string.h>
10179 #include <linux/thread_info.h>
10180+#include <linux/kernel.h>
10181 #include <asm/asi.h>
10182 #include <asm/spitfire.h>
10183 #include <asm-generic/uaccess-unaligned.h>
10184@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10185 static inline unsigned long __must_check
10186 copy_from_user(void *to, const void __user *from, unsigned long size)
10187 {
10188- unsigned long ret = ___copy_from_user(to, from, size);
10189+ unsigned long ret;
10190
10191+ if ((long)size < 0 || size > INT_MAX)
10192+ return size;
10193+
10194+ if (!__builtin_constant_p(size))
10195+ check_object_size(to, size, false);
10196+
10197+ ret = ___copy_from_user(to, from, size);
10198 if (unlikely(ret))
10199 ret = copy_from_user_fixup(to, from, size);
10200
10201@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10202 static inline unsigned long __must_check
10203 copy_to_user(void __user *to, const void *from, unsigned long size)
10204 {
10205- unsigned long ret = ___copy_to_user(to, from, size);
10206+ unsigned long ret;
10207
10208+ if ((long)size < 0 || size > INT_MAX)
10209+ return size;
10210+
10211+ if (!__builtin_constant_p(size))
10212+ check_object_size(from, size, true);
10213+
10214+ ret = ___copy_to_user(to, from, size);
10215 if (unlikely(ret))
10216 ret = copy_to_user_fixup(to, from, size);
10217 return ret;
10218diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10219index d15cc17..d0ae796 100644
10220--- a/arch/sparc/kernel/Makefile
10221+++ b/arch/sparc/kernel/Makefile
10222@@ -4,7 +4,7 @@
10223 #
10224
10225 asflags-y := -ansi
10226-ccflags-y := -Werror
10227+#ccflags-y := -Werror
10228
10229 extra-y := head_$(BITS).o
10230
10231diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10232index 510baec..9ff2607 100644
10233--- a/arch/sparc/kernel/process_32.c
10234+++ b/arch/sparc/kernel/process_32.c
10235@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10236
10237 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10238 r->psr, r->pc, r->npc, r->y, print_tainted());
10239- printk("PC: <%pS>\n", (void *) r->pc);
10240+ printk("PC: <%pA>\n", (void *) r->pc);
10241 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10242 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10243 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10244 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10245 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10246 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10247- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10248+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10249
10250 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10251 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10252@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10253 rw = (struct reg_window32 *) fp;
10254 pc = rw->ins[7];
10255 printk("[%08lx : ", pc);
10256- printk("%pS ] ", (void *) pc);
10257+ printk("%pA ] ", (void *) pc);
10258 fp = rw->ins[6];
10259 } while (++count < 16);
10260 printk("\n");
10261diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10262index d7b4967..2edf827 100644
10263--- a/arch/sparc/kernel/process_64.c
10264+++ b/arch/sparc/kernel/process_64.c
10265@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10266 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10267 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10268 if (regs->tstate & TSTATE_PRIV)
10269- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10270+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10271 }
10272
10273 void show_regs(struct pt_regs *regs)
10274@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10275
10276 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10277 regs->tpc, regs->tnpc, regs->y, print_tainted());
10278- printk("TPC: <%pS>\n", (void *) regs->tpc);
10279+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10280 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10281 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10282 regs->u_regs[3]);
10283@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10284 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10285 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10286 regs->u_regs[15]);
10287- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10288+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10289 show_regwindow(regs);
10290 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10291 }
10292@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10293 ((tp && tp->task) ? tp->task->pid : -1));
10294
10295 if (gp->tstate & TSTATE_PRIV) {
10296- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10297+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10298 (void *) gp->tpc,
10299 (void *) gp->o7,
10300 (void *) gp->i7,
10301diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10302index 79cc0d1..ec62734 100644
10303--- a/arch/sparc/kernel/prom_common.c
10304+++ b/arch/sparc/kernel/prom_common.c
10305@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10306
10307 unsigned int prom_early_allocated __initdata;
10308
10309-static struct of_pdt_ops prom_sparc_ops __initdata = {
10310+static struct of_pdt_ops prom_sparc_ops __initconst = {
10311 .nextprop = prom_common_nextprop,
10312 .getproplen = prom_getproplen,
10313 .getproperty = prom_getproperty,
10314diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10315index c13c9f2..d572c34 100644
10316--- a/arch/sparc/kernel/ptrace_64.c
10317+++ b/arch/sparc/kernel/ptrace_64.c
10318@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10319 return ret;
10320 }
10321
10322+#ifdef CONFIG_GRKERNSEC_SETXID
10323+extern void gr_delayed_cred_worker(void);
10324+#endif
10325+
10326 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10327 {
10328 int ret = 0;
10329@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10330 if (test_thread_flag(TIF_NOHZ))
10331 user_exit();
10332
10333+#ifdef CONFIG_GRKERNSEC_SETXID
10334+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10335+ gr_delayed_cred_worker();
10336+#endif
10337+
10338 if (test_thread_flag(TIF_SYSCALL_TRACE))
10339 ret = tracehook_report_syscall_entry(regs);
10340
10341@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10342 if (test_thread_flag(TIF_NOHZ))
10343 user_exit();
10344
10345+#ifdef CONFIG_GRKERNSEC_SETXID
10346+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10347+ gr_delayed_cred_worker();
10348+#endif
10349+
10350 audit_syscall_exit(regs);
10351
10352 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10353diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10354index 745a363..b5566b1 100644
10355--- a/arch/sparc/kernel/smp_64.c
10356+++ b/arch/sparc/kernel/smp_64.c
10357@@ -868,8 +868,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10358 extern unsigned long xcall_flush_dcache_page_spitfire;
10359
10360 #ifdef CONFIG_DEBUG_DCFLUSH
10361-extern atomic_t dcpage_flushes;
10362-extern atomic_t dcpage_flushes_xcall;
10363+extern atomic_unchecked_t dcpage_flushes;
10364+extern atomic_unchecked_t dcpage_flushes_xcall;
10365 #endif
10366
10367 static inline void __local_flush_dcache_page(struct page *page)
10368@@ -893,7 +893,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10369 return;
10370
10371 #ifdef CONFIG_DEBUG_DCFLUSH
10372- atomic_inc(&dcpage_flushes);
10373+ atomic_inc_unchecked(&dcpage_flushes);
10374 #endif
10375
10376 this_cpu = get_cpu();
10377@@ -917,7 +917,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10378 xcall_deliver(data0, __pa(pg_addr),
10379 (u64) pg_addr, cpumask_of(cpu));
10380 #ifdef CONFIG_DEBUG_DCFLUSH
10381- atomic_inc(&dcpage_flushes_xcall);
10382+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10383 #endif
10384 }
10385 }
10386@@ -936,7 +936,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10387 preempt_disable();
10388
10389 #ifdef CONFIG_DEBUG_DCFLUSH
10390- atomic_inc(&dcpage_flushes);
10391+ atomic_inc_unchecked(&dcpage_flushes);
10392 #endif
10393 data0 = 0;
10394 pg_addr = page_address(page);
10395@@ -953,7 +953,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10396 xcall_deliver(data0, __pa(pg_addr),
10397 (u64) pg_addr, cpu_online_mask);
10398 #ifdef CONFIG_DEBUG_DCFLUSH
10399- atomic_inc(&dcpage_flushes_xcall);
10400+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10401 #endif
10402 }
10403 __local_flush_dcache_page(page);
10404diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10405index 3a8d184..49498a8 100644
10406--- a/arch/sparc/kernel/sys_sparc_32.c
10407+++ b/arch/sparc/kernel/sys_sparc_32.c
10408@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10409 if (len > TASK_SIZE - PAGE_SIZE)
10410 return -ENOMEM;
10411 if (!addr)
10412- addr = TASK_UNMAPPED_BASE;
10413+ addr = current->mm->mmap_base;
10414
10415 info.flags = 0;
10416 info.length = len;
10417diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10418index beb0b5a..5a153f7 100644
10419--- a/arch/sparc/kernel/sys_sparc_64.c
10420+++ b/arch/sparc/kernel/sys_sparc_64.c
10421@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10422 struct vm_area_struct * vma;
10423 unsigned long task_size = TASK_SIZE;
10424 int do_color_align;
10425+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10426 struct vm_unmapped_area_info info;
10427
10428 if (flags & MAP_FIXED) {
10429 /* We do not accept a shared mapping if it would violate
10430 * cache aliasing constraints.
10431 */
10432- if ((flags & MAP_SHARED) &&
10433+ if ((filp || (flags & MAP_SHARED)) &&
10434 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10435 return -EINVAL;
10436 return addr;
10437@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10438 if (filp || (flags & MAP_SHARED))
10439 do_color_align = 1;
10440
10441+#ifdef CONFIG_PAX_RANDMMAP
10442+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10443+#endif
10444+
10445 if (addr) {
10446 if (do_color_align)
10447 addr = COLOR_ALIGN(addr, pgoff);
10448@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10449 addr = PAGE_ALIGN(addr);
10450
10451 vma = find_vma(mm, addr);
10452- if (task_size - len >= addr &&
10453- (!vma || addr + len <= vma->vm_start))
10454+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10455 return addr;
10456 }
10457
10458 info.flags = 0;
10459 info.length = len;
10460- info.low_limit = TASK_UNMAPPED_BASE;
10461+ info.low_limit = mm->mmap_base;
10462 info.high_limit = min(task_size, VA_EXCLUDE_START);
10463 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10464 info.align_offset = pgoff << PAGE_SHIFT;
10465+ info.threadstack_offset = offset;
10466 addr = vm_unmapped_area(&info);
10467
10468 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10469 VM_BUG_ON(addr != -ENOMEM);
10470 info.low_limit = VA_EXCLUDE_END;
10471+
10472+#ifdef CONFIG_PAX_RANDMMAP
10473+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10474+ info.low_limit += mm->delta_mmap;
10475+#endif
10476+
10477 info.high_limit = task_size;
10478 addr = vm_unmapped_area(&info);
10479 }
10480@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10481 unsigned long task_size = STACK_TOP32;
10482 unsigned long addr = addr0;
10483 int do_color_align;
10484+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10485 struct vm_unmapped_area_info info;
10486
10487 /* This should only ever run for 32-bit processes. */
10488@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10489 /* We do not accept a shared mapping if it would violate
10490 * cache aliasing constraints.
10491 */
10492- if ((flags & MAP_SHARED) &&
10493+ if ((filp || (flags & MAP_SHARED)) &&
10494 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10495 return -EINVAL;
10496 return addr;
10497@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10498 if (filp || (flags & MAP_SHARED))
10499 do_color_align = 1;
10500
10501+#ifdef CONFIG_PAX_RANDMMAP
10502+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10503+#endif
10504+
10505 /* requesting a specific address */
10506 if (addr) {
10507 if (do_color_align)
10508@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10509 addr = PAGE_ALIGN(addr);
10510
10511 vma = find_vma(mm, addr);
10512- if (task_size - len >= addr &&
10513- (!vma || addr + len <= vma->vm_start))
10514+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10515 return addr;
10516 }
10517
10518@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10519 info.high_limit = mm->mmap_base;
10520 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10521 info.align_offset = pgoff << PAGE_SHIFT;
10522+ info.threadstack_offset = offset;
10523 addr = vm_unmapped_area(&info);
10524
10525 /*
10526@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10527 VM_BUG_ON(addr != -ENOMEM);
10528 info.flags = 0;
10529 info.low_limit = TASK_UNMAPPED_BASE;
10530+
10531+#ifdef CONFIG_PAX_RANDMMAP
10532+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10533+ info.low_limit += mm->delta_mmap;
10534+#endif
10535+
10536 info.high_limit = STACK_TOP32;
10537 addr = vm_unmapped_area(&info);
10538 }
10539@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10540 EXPORT_SYMBOL(get_fb_unmapped_area);
10541
10542 /* Essentially the same as PowerPC. */
10543-static unsigned long mmap_rnd(void)
10544+static unsigned long mmap_rnd(struct mm_struct *mm)
10545 {
10546 unsigned long rnd = 0UL;
10547
10548+#ifdef CONFIG_PAX_RANDMMAP
10549+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10550+#endif
10551+
10552 if (current->flags & PF_RANDOMIZE) {
10553 unsigned long val = get_random_int();
10554 if (test_thread_flag(TIF_32BIT))
10555@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10556
10557 void arch_pick_mmap_layout(struct mm_struct *mm)
10558 {
10559- unsigned long random_factor = mmap_rnd();
10560+ unsigned long random_factor = mmap_rnd(mm);
10561 unsigned long gap;
10562
10563 /*
10564@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10565 gap == RLIM_INFINITY ||
10566 sysctl_legacy_va_layout) {
10567 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10568+
10569+#ifdef CONFIG_PAX_RANDMMAP
10570+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10571+ mm->mmap_base += mm->delta_mmap;
10572+#endif
10573+
10574 mm->get_unmapped_area = arch_get_unmapped_area;
10575 } else {
10576 /* We know it's 32-bit */
10577@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10578 gap = (task_size / 6 * 5);
10579
10580 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10581+
10582+#ifdef CONFIG_PAX_RANDMMAP
10583+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10584+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10585+#endif
10586+
10587 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10588 }
10589 }
10590diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10591index 33a17e7..d87fb1f 100644
10592--- a/arch/sparc/kernel/syscalls.S
10593+++ b/arch/sparc/kernel/syscalls.S
10594@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10595 #endif
10596 .align 32
10597 1: ldx [%g6 + TI_FLAGS], %l5
10598- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10599+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10600 be,pt %icc, rtrap
10601 nop
10602 call syscall_trace_leave
10603@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10604
10605 srl %i3, 0, %o3 ! IEU0
10606 srl %i2, 0, %o2 ! IEU0 Group
10607- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10608+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10609 bne,pn %icc, linux_syscall_trace32 ! CTI
10610 mov %i0, %l5 ! IEU1
10611 5: call %l7 ! CTI Group brk forced
10612@@ -208,7 +208,7 @@ linux_sparc_syscall:
10613
10614 mov %i3, %o3 ! IEU1
10615 mov %i4, %o4 ! IEU0 Group
10616- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10617+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10618 bne,pn %icc, linux_syscall_trace ! CTI Group
10619 mov %i0, %l5 ! IEU0
10620 2: call %l7 ! CTI Group brk forced
10621@@ -223,7 +223,7 @@ ret_sys_call:
10622
10623 cmp %o0, -ERESTART_RESTARTBLOCK
10624 bgeu,pn %xcc, 1f
10625- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10626+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10627 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10628
10629 2:
10630diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10631index 6629829..036032d 100644
10632--- a/arch/sparc/kernel/traps_32.c
10633+++ b/arch/sparc/kernel/traps_32.c
10634@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10635 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10636 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10637
10638+extern void gr_handle_kernel_exploit(void);
10639+
10640 void die_if_kernel(char *str, struct pt_regs *regs)
10641 {
10642 static int die_counter;
10643@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10644 count++ < 30 &&
10645 (((unsigned long) rw) >= PAGE_OFFSET) &&
10646 !(((unsigned long) rw) & 0x7)) {
10647- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10648+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10649 (void *) rw->ins[7]);
10650 rw = (struct reg_window32 *)rw->ins[6];
10651 }
10652 }
10653 printk("Instruction DUMP:");
10654 instruction_dump ((unsigned long *) regs->pc);
10655- if(regs->psr & PSR_PS)
10656+ if(regs->psr & PSR_PS) {
10657+ gr_handle_kernel_exploit();
10658 do_exit(SIGKILL);
10659+ }
10660 do_exit(SIGSEGV);
10661 }
10662
10663diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10664index 4ced92f..965eeed 100644
10665--- a/arch/sparc/kernel/traps_64.c
10666+++ b/arch/sparc/kernel/traps_64.c
10667@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10668 i + 1,
10669 p->trapstack[i].tstate, p->trapstack[i].tpc,
10670 p->trapstack[i].tnpc, p->trapstack[i].tt);
10671- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10672+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10673 }
10674 }
10675
10676@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10677
10678 lvl -= 0x100;
10679 if (regs->tstate & TSTATE_PRIV) {
10680+
10681+#ifdef CONFIG_PAX_REFCOUNT
10682+ if (lvl == 6)
10683+ pax_report_refcount_overflow(regs);
10684+#endif
10685+
10686 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10687 die_if_kernel(buffer, regs);
10688 }
10689@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10690 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10691 {
10692 char buffer[32];
10693-
10694+
10695 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10696 0, lvl, SIGTRAP) == NOTIFY_STOP)
10697 return;
10698
10699+#ifdef CONFIG_PAX_REFCOUNT
10700+ if (lvl == 6)
10701+ pax_report_refcount_overflow(regs);
10702+#endif
10703+
10704 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10705
10706 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10707@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10708 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10709 printk("%s" "ERROR(%d): ",
10710 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10711- printk("TPC<%pS>\n", (void *) regs->tpc);
10712+ printk("TPC<%pA>\n", (void *) regs->tpc);
10713 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10714 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10715 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10716@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10717 smp_processor_id(),
10718 (type & 0x1) ? 'I' : 'D',
10719 regs->tpc);
10720- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10721+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10722 panic("Irrecoverable Cheetah+ parity error.");
10723 }
10724
10725@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10726 smp_processor_id(),
10727 (type & 0x1) ? 'I' : 'D',
10728 regs->tpc);
10729- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10730+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10731 }
10732
10733 struct sun4v_error_entry {
10734@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10735 /*0x38*/u64 reserved_5;
10736 };
10737
10738-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10739-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10740+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10741+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10742
10743 static const char *sun4v_err_type_to_str(u8 type)
10744 {
10745@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10746 }
10747
10748 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10749- int cpu, const char *pfx, atomic_t *ocnt)
10750+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10751 {
10752 u64 *raw_ptr = (u64 *) ent;
10753 u32 attrs;
10754@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10755
10756 show_regs(regs);
10757
10758- if ((cnt = atomic_read(ocnt)) != 0) {
10759- atomic_set(ocnt, 0);
10760+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10761+ atomic_set_unchecked(ocnt, 0);
10762 wmb();
10763 printk("%s: Queue overflowed %d times.\n",
10764 pfx, cnt);
10765@@ -2046,7 +2057,7 @@ out:
10766 */
10767 void sun4v_resum_overflow(struct pt_regs *regs)
10768 {
10769- atomic_inc(&sun4v_resum_oflow_cnt);
10770+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10771 }
10772
10773 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10774@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10775 /* XXX Actually even this can make not that much sense. Perhaps
10776 * XXX we should just pull the plug and panic directly from here?
10777 */
10778- atomic_inc(&sun4v_nonresum_oflow_cnt);
10779+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10780 }
10781
10782 unsigned long sun4v_err_itlb_vaddr;
10783@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10784
10785 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10786 regs->tpc, tl);
10787- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10788+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10789 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10790- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10791+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10792 (void *) regs->u_regs[UREG_I7]);
10793 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10794 "pte[%lx] error[%lx]\n",
10795@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10796
10797 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10798 regs->tpc, tl);
10799- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10800+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10801 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10802- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10803+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10804 (void *) regs->u_regs[UREG_I7]);
10805 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10806 "pte[%lx] error[%lx]\n",
10807@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10808 fp = (unsigned long)sf->fp + STACK_BIAS;
10809 }
10810
10811- printk(" [%016lx] %pS\n", pc, (void *) pc);
10812+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10813 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10814 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10815 int index = tsk->curr_ret_stack;
10816 if (tsk->ret_stack && index >= graph) {
10817 pc = tsk->ret_stack[index - graph].ret;
10818- printk(" [%016lx] %pS\n", pc, (void *) pc);
10819+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10820 graph++;
10821 }
10822 }
10823@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10824 return (struct reg_window *) (fp + STACK_BIAS);
10825 }
10826
10827+extern void gr_handle_kernel_exploit(void);
10828+
10829 void die_if_kernel(char *str, struct pt_regs *regs)
10830 {
10831 static int die_counter;
10832@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10833 while (rw &&
10834 count++ < 30 &&
10835 kstack_valid(tp, (unsigned long) rw)) {
10836- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10837+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10838 (void *) rw->ins[7]);
10839
10840 rw = kernel_stack_up(rw);
10841@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10842 }
10843 user_instruction_dump ((unsigned int __user *) regs->tpc);
10844 }
10845- if (regs->tstate & TSTATE_PRIV)
10846+ if (regs->tstate & TSTATE_PRIV) {
10847+ gr_handle_kernel_exploit();
10848 do_exit(SIGKILL);
10849+ }
10850 do_exit(SIGSEGV);
10851 }
10852 EXPORT_SYMBOL(die_if_kernel);
10853diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10854index 35ab8b6..9046547 100644
10855--- a/arch/sparc/kernel/unaligned_64.c
10856+++ b/arch/sparc/kernel/unaligned_64.c
10857@@ -295,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10858 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10859
10860 if (__ratelimit(&ratelimit)) {
10861- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10862+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10863 regs->tpc, (void *) regs->tpc);
10864 }
10865 }
10866diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10867index dbe119b..089c7c1 100644
10868--- a/arch/sparc/lib/Makefile
10869+++ b/arch/sparc/lib/Makefile
10870@@ -2,7 +2,7 @@
10871 #
10872
10873 asflags-y := -ansi -DST_DIV0=0x02
10874-ccflags-y := -Werror
10875+#ccflags-y := -Werror
10876
10877 lib-$(CONFIG_SPARC32) += ashrdi3.o
10878 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10879diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10880index 85c233d..68500e0 100644
10881--- a/arch/sparc/lib/atomic_64.S
10882+++ b/arch/sparc/lib/atomic_64.S
10883@@ -17,7 +17,12 @@
10884 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10885 BACKOFF_SETUP(%o2)
10886 1: lduw [%o1], %g1
10887- add %g1, %o0, %g7
10888+ addcc %g1, %o0, %g7
10889+
10890+#ifdef CONFIG_PAX_REFCOUNT
10891+ tvs %icc, 6
10892+#endif
10893+
10894 cas [%o1], %g1, %g7
10895 cmp %g1, %g7
10896 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10897@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10898 2: BACKOFF_SPIN(%o2, %o3, 1b)
10899 ENDPROC(atomic_add)
10900
10901+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10902+ BACKOFF_SETUP(%o2)
10903+1: lduw [%o1], %g1
10904+ add %g1, %o0, %g7
10905+ cas [%o1], %g1, %g7
10906+ cmp %g1, %g7
10907+ bne,pn %icc, 2f
10908+ nop
10909+ retl
10910+ nop
10911+2: BACKOFF_SPIN(%o2, %o3, 1b)
10912+ENDPROC(atomic_add_unchecked)
10913+
10914 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10915 BACKOFF_SETUP(%o2)
10916 1: lduw [%o1], %g1
10917- sub %g1, %o0, %g7
10918+ subcc %g1, %o0, %g7
10919+
10920+#ifdef CONFIG_PAX_REFCOUNT
10921+ tvs %icc, 6
10922+#endif
10923+
10924 cas [%o1], %g1, %g7
10925 cmp %g1, %g7
10926 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10927@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10928 2: BACKOFF_SPIN(%o2, %o3, 1b)
10929 ENDPROC(atomic_sub)
10930
10931+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10932+ BACKOFF_SETUP(%o2)
10933+1: lduw [%o1], %g1
10934+ sub %g1, %o0, %g7
10935+ cas [%o1], %g1, %g7
10936+ cmp %g1, %g7
10937+ bne,pn %icc, 2f
10938+ nop
10939+ retl
10940+ nop
10941+2: BACKOFF_SPIN(%o2, %o3, 1b)
10942+ENDPROC(atomic_sub_unchecked)
10943+
10944 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10945 BACKOFF_SETUP(%o2)
10946 1: lduw [%o1], %g1
10947- add %g1, %o0, %g7
10948+ addcc %g1, %o0, %g7
10949+
10950+#ifdef CONFIG_PAX_REFCOUNT
10951+ tvs %icc, 6
10952+#endif
10953+
10954 cas [%o1], %g1, %g7
10955 cmp %g1, %g7
10956 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10957@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10958 2: BACKOFF_SPIN(%o2, %o3, 1b)
10959 ENDPROC(atomic_add_ret)
10960
10961+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10962+ BACKOFF_SETUP(%o2)
10963+1: lduw [%o1], %g1
10964+ addcc %g1, %o0, %g7
10965+ cas [%o1], %g1, %g7
10966+ cmp %g1, %g7
10967+ bne,pn %icc, 2f
10968+ add %g7, %o0, %g7
10969+ sra %g7, 0, %o0
10970+ retl
10971+ nop
10972+2: BACKOFF_SPIN(%o2, %o3, 1b)
10973+ENDPROC(atomic_add_ret_unchecked)
10974+
10975 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10976 BACKOFF_SETUP(%o2)
10977 1: lduw [%o1], %g1
10978- sub %g1, %o0, %g7
10979+ subcc %g1, %o0, %g7
10980+
10981+#ifdef CONFIG_PAX_REFCOUNT
10982+ tvs %icc, 6
10983+#endif
10984+
10985 cas [%o1], %g1, %g7
10986 cmp %g1, %g7
10987 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10988@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10989 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10990 BACKOFF_SETUP(%o2)
10991 1: ldx [%o1], %g1
10992- add %g1, %o0, %g7
10993+ addcc %g1, %o0, %g7
10994+
10995+#ifdef CONFIG_PAX_REFCOUNT
10996+ tvs %xcc, 6
10997+#endif
10998+
10999 casx [%o1], %g1, %g7
11000 cmp %g1, %g7
11001 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11002@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11003 2: BACKOFF_SPIN(%o2, %o3, 1b)
11004 ENDPROC(atomic64_add)
11005
11006+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11007+ BACKOFF_SETUP(%o2)
11008+1: ldx [%o1], %g1
11009+ addcc %g1, %o0, %g7
11010+ casx [%o1], %g1, %g7
11011+ cmp %g1, %g7
11012+ bne,pn %xcc, 2f
11013+ nop
11014+ retl
11015+ nop
11016+2: BACKOFF_SPIN(%o2, %o3, 1b)
11017+ENDPROC(atomic64_add_unchecked)
11018+
11019 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11020 BACKOFF_SETUP(%o2)
11021 1: ldx [%o1], %g1
11022- sub %g1, %o0, %g7
11023+ subcc %g1, %o0, %g7
11024+
11025+#ifdef CONFIG_PAX_REFCOUNT
11026+ tvs %xcc, 6
11027+#endif
11028+
11029 casx [%o1], %g1, %g7
11030 cmp %g1, %g7
11031 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11032@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11033 2: BACKOFF_SPIN(%o2, %o3, 1b)
11034 ENDPROC(atomic64_sub)
11035
11036+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11037+ BACKOFF_SETUP(%o2)
11038+1: ldx [%o1], %g1
11039+ subcc %g1, %o0, %g7
11040+ casx [%o1], %g1, %g7
11041+ cmp %g1, %g7
11042+ bne,pn %xcc, 2f
11043+ nop
11044+ retl
11045+ nop
11046+2: BACKOFF_SPIN(%o2, %o3, 1b)
11047+ENDPROC(atomic64_sub_unchecked)
11048+
11049 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11050 BACKOFF_SETUP(%o2)
11051 1: ldx [%o1], %g1
11052- add %g1, %o0, %g7
11053+ addcc %g1, %o0, %g7
11054+
11055+#ifdef CONFIG_PAX_REFCOUNT
11056+ tvs %xcc, 6
11057+#endif
11058+
11059 casx [%o1], %g1, %g7
11060 cmp %g1, %g7
11061 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11062@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11063 2: BACKOFF_SPIN(%o2, %o3, 1b)
11064 ENDPROC(atomic64_add_ret)
11065
11066+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11067+ BACKOFF_SETUP(%o2)
11068+1: ldx [%o1], %g1
11069+ addcc %g1, %o0, %g7
11070+ casx [%o1], %g1, %g7
11071+ cmp %g1, %g7
11072+ bne,pn %xcc, 2f
11073+ add %g7, %o0, %g7
11074+ mov %g7, %o0
11075+ retl
11076+ nop
11077+2: BACKOFF_SPIN(%o2, %o3, 1b)
11078+ENDPROC(atomic64_add_ret_unchecked)
11079+
11080 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11081 BACKOFF_SETUP(%o2)
11082 1: ldx [%o1], %g1
11083- sub %g1, %o0, %g7
11084+ subcc %g1, %o0, %g7
11085+
11086+#ifdef CONFIG_PAX_REFCOUNT
11087+ tvs %xcc, 6
11088+#endif
11089+
11090 casx [%o1], %g1, %g7
11091 cmp %g1, %g7
11092 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11093diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11094index 323335b..ed85ea2 100644
11095--- a/arch/sparc/lib/ksyms.c
11096+++ b/arch/sparc/lib/ksyms.c
11097@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11098
11099 /* Atomic counter implementation. */
11100 EXPORT_SYMBOL(atomic_add);
11101+EXPORT_SYMBOL(atomic_add_unchecked);
11102 EXPORT_SYMBOL(atomic_add_ret);
11103+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11104 EXPORT_SYMBOL(atomic_sub);
11105+EXPORT_SYMBOL(atomic_sub_unchecked);
11106 EXPORT_SYMBOL(atomic_sub_ret);
11107 EXPORT_SYMBOL(atomic64_add);
11108+EXPORT_SYMBOL(atomic64_add_unchecked);
11109 EXPORT_SYMBOL(atomic64_add_ret);
11110+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11111 EXPORT_SYMBOL(atomic64_sub);
11112+EXPORT_SYMBOL(atomic64_sub_unchecked);
11113 EXPORT_SYMBOL(atomic64_sub_ret);
11114 EXPORT_SYMBOL(atomic64_dec_if_positive);
11115
11116diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11117index 30c3ecc..736f015 100644
11118--- a/arch/sparc/mm/Makefile
11119+++ b/arch/sparc/mm/Makefile
11120@@ -2,7 +2,7 @@
11121 #
11122
11123 asflags-y := -ansi
11124-ccflags-y := -Werror
11125+#ccflags-y := -Werror
11126
11127 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11128 obj-y += fault_$(BITS).o
11129diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11130index 59dbd46..1dd7f5e 100644
11131--- a/arch/sparc/mm/fault_32.c
11132+++ b/arch/sparc/mm/fault_32.c
11133@@ -21,6 +21,9 @@
11134 #include <linux/perf_event.h>
11135 #include <linux/interrupt.h>
11136 #include <linux/kdebug.h>
11137+#include <linux/slab.h>
11138+#include <linux/pagemap.h>
11139+#include <linux/compiler.h>
11140
11141 #include <asm/page.h>
11142 #include <asm/pgtable.h>
11143@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11144 return safe_compute_effective_address(regs, insn);
11145 }
11146
11147+#ifdef CONFIG_PAX_PAGEEXEC
11148+#ifdef CONFIG_PAX_DLRESOLVE
11149+static void pax_emuplt_close(struct vm_area_struct *vma)
11150+{
11151+ vma->vm_mm->call_dl_resolve = 0UL;
11152+}
11153+
11154+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11155+{
11156+ unsigned int *kaddr;
11157+
11158+ vmf->page = alloc_page(GFP_HIGHUSER);
11159+ if (!vmf->page)
11160+ return VM_FAULT_OOM;
11161+
11162+ kaddr = kmap(vmf->page);
11163+ memset(kaddr, 0, PAGE_SIZE);
11164+ kaddr[0] = 0x9DE3BFA8U; /* save */
11165+ flush_dcache_page(vmf->page);
11166+ kunmap(vmf->page);
11167+ return VM_FAULT_MAJOR;
11168+}
11169+
11170+static const struct vm_operations_struct pax_vm_ops = {
11171+ .close = pax_emuplt_close,
11172+ .fault = pax_emuplt_fault
11173+};
11174+
11175+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11176+{
11177+ int ret;
11178+
11179+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11180+ vma->vm_mm = current->mm;
11181+ vma->vm_start = addr;
11182+ vma->vm_end = addr + PAGE_SIZE;
11183+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11184+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11185+ vma->vm_ops = &pax_vm_ops;
11186+
11187+ ret = insert_vm_struct(current->mm, vma);
11188+ if (ret)
11189+ return ret;
11190+
11191+ ++current->mm->total_vm;
11192+ return 0;
11193+}
11194+#endif
11195+
11196+/*
11197+ * PaX: decide what to do with offenders (regs->pc = fault address)
11198+ *
11199+ * returns 1 when task should be killed
11200+ * 2 when patched PLT trampoline was detected
11201+ * 3 when unpatched PLT trampoline was detected
11202+ */
11203+static int pax_handle_fetch_fault(struct pt_regs *regs)
11204+{
11205+
11206+#ifdef CONFIG_PAX_EMUPLT
11207+ int err;
11208+
11209+ do { /* PaX: patched PLT emulation #1 */
11210+ unsigned int sethi1, sethi2, jmpl;
11211+
11212+ err = get_user(sethi1, (unsigned int *)regs->pc);
11213+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11214+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11215+
11216+ if (err)
11217+ break;
11218+
11219+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11220+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11221+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11222+ {
11223+ unsigned int addr;
11224+
11225+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11226+ addr = regs->u_regs[UREG_G1];
11227+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11228+ regs->pc = addr;
11229+ regs->npc = addr+4;
11230+ return 2;
11231+ }
11232+ } while (0);
11233+
11234+ do { /* PaX: patched PLT emulation #2 */
11235+ unsigned int ba;
11236+
11237+ err = get_user(ba, (unsigned int *)regs->pc);
11238+
11239+ if (err)
11240+ break;
11241+
11242+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11243+ unsigned int addr;
11244+
11245+ if ((ba & 0xFFC00000U) == 0x30800000U)
11246+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11247+ else
11248+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11249+ regs->pc = addr;
11250+ regs->npc = addr+4;
11251+ return 2;
11252+ }
11253+ } while (0);
11254+
11255+ do { /* PaX: patched PLT emulation #3 */
11256+ unsigned int sethi, bajmpl, nop;
11257+
11258+ err = get_user(sethi, (unsigned int *)regs->pc);
11259+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11260+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11261+
11262+ if (err)
11263+ break;
11264+
11265+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11266+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11267+ nop == 0x01000000U)
11268+ {
11269+ unsigned int addr;
11270+
11271+ addr = (sethi & 0x003FFFFFU) << 10;
11272+ regs->u_regs[UREG_G1] = addr;
11273+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11274+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11275+ else
11276+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11277+ regs->pc = addr;
11278+ regs->npc = addr+4;
11279+ return 2;
11280+ }
11281+ } while (0);
11282+
11283+ do { /* PaX: unpatched PLT emulation step 1 */
11284+ unsigned int sethi, ba, nop;
11285+
11286+ err = get_user(sethi, (unsigned int *)regs->pc);
11287+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11288+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11289+
11290+ if (err)
11291+ break;
11292+
11293+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11294+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11295+ nop == 0x01000000U)
11296+ {
11297+ unsigned int addr, save, call;
11298+
11299+ if ((ba & 0xFFC00000U) == 0x30800000U)
11300+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11301+ else
11302+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11303+
11304+ err = get_user(save, (unsigned int *)addr);
11305+ err |= get_user(call, (unsigned int *)(addr+4));
11306+ err |= get_user(nop, (unsigned int *)(addr+8));
11307+ if (err)
11308+ break;
11309+
11310+#ifdef CONFIG_PAX_DLRESOLVE
11311+ if (save == 0x9DE3BFA8U &&
11312+ (call & 0xC0000000U) == 0x40000000U &&
11313+ nop == 0x01000000U)
11314+ {
11315+ struct vm_area_struct *vma;
11316+ unsigned long call_dl_resolve;
11317+
11318+ down_read(&current->mm->mmap_sem);
11319+ call_dl_resolve = current->mm->call_dl_resolve;
11320+ up_read(&current->mm->mmap_sem);
11321+ if (likely(call_dl_resolve))
11322+ goto emulate;
11323+
11324+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11325+
11326+ down_write(&current->mm->mmap_sem);
11327+ if (current->mm->call_dl_resolve) {
11328+ call_dl_resolve = current->mm->call_dl_resolve;
11329+ up_write(&current->mm->mmap_sem);
11330+ if (vma)
11331+ kmem_cache_free(vm_area_cachep, vma);
11332+ goto emulate;
11333+ }
11334+
11335+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11336+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11337+ up_write(&current->mm->mmap_sem);
11338+ if (vma)
11339+ kmem_cache_free(vm_area_cachep, vma);
11340+ return 1;
11341+ }
11342+
11343+ if (pax_insert_vma(vma, call_dl_resolve)) {
11344+ up_write(&current->mm->mmap_sem);
11345+ kmem_cache_free(vm_area_cachep, vma);
11346+ return 1;
11347+ }
11348+
11349+ current->mm->call_dl_resolve = call_dl_resolve;
11350+ up_write(&current->mm->mmap_sem);
11351+
11352+emulate:
11353+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11354+ regs->pc = call_dl_resolve;
11355+ regs->npc = addr+4;
11356+ return 3;
11357+ }
11358+#endif
11359+
11360+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11361+ if ((save & 0xFFC00000U) == 0x05000000U &&
11362+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11363+ nop == 0x01000000U)
11364+ {
11365+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11366+ regs->u_regs[UREG_G2] = addr + 4;
11367+ addr = (save & 0x003FFFFFU) << 10;
11368+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11369+ regs->pc = addr;
11370+ regs->npc = addr+4;
11371+ return 3;
11372+ }
11373+ }
11374+ } while (0);
11375+
11376+ do { /* PaX: unpatched PLT emulation step 2 */
11377+ unsigned int save, call, nop;
11378+
11379+ err = get_user(save, (unsigned int *)(regs->pc-4));
11380+ err |= get_user(call, (unsigned int *)regs->pc);
11381+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11382+ if (err)
11383+ break;
11384+
11385+ if (save == 0x9DE3BFA8U &&
11386+ (call & 0xC0000000U) == 0x40000000U &&
11387+ nop == 0x01000000U)
11388+ {
11389+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11390+
11391+ regs->u_regs[UREG_RETPC] = regs->pc;
11392+ regs->pc = dl_resolve;
11393+ regs->npc = dl_resolve+4;
11394+ return 3;
11395+ }
11396+ } while (0);
11397+#endif
11398+
11399+ return 1;
11400+}
11401+
11402+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11403+{
11404+ unsigned long i;
11405+
11406+ printk(KERN_ERR "PAX: bytes at PC: ");
11407+ for (i = 0; i < 8; i++) {
11408+ unsigned int c;
11409+ if (get_user(c, (unsigned int *)pc+i))
11410+ printk(KERN_CONT "???????? ");
11411+ else
11412+ printk(KERN_CONT "%08x ", c);
11413+ }
11414+ printk("\n");
11415+}
11416+#endif
11417+
11418 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11419 int text_fault)
11420 {
11421@@ -229,6 +503,24 @@ good_area:
11422 if (!(vma->vm_flags & VM_WRITE))
11423 goto bad_area;
11424 } else {
11425+
11426+#ifdef CONFIG_PAX_PAGEEXEC
11427+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11428+ up_read(&mm->mmap_sem);
11429+ switch (pax_handle_fetch_fault(regs)) {
11430+
11431+#ifdef CONFIG_PAX_EMUPLT
11432+ case 2:
11433+ case 3:
11434+ return;
11435+#endif
11436+
11437+ }
11438+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11439+ do_group_exit(SIGKILL);
11440+ }
11441+#endif
11442+
11443 /* Allow reads even for write-only mappings */
11444 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11445 goto bad_area;
11446diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11447index 4ced3fc..234f1e4 100644
11448--- a/arch/sparc/mm/fault_64.c
11449+++ b/arch/sparc/mm/fault_64.c
11450@@ -22,6 +22,9 @@
11451 #include <linux/kdebug.h>
11452 #include <linux/percpu.h>
11453 #include <linux/context_tracking.h>
11454+#include <linux/slab.h>
11455+#include <linux/pagemap.h>
11456+#include <linux/compiler.h>
11457
11458 #include <asm/page.h>
11459 #include <asm/pgtable.h>
11460@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11461 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11462 regs->tpc);
11463 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11464- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11465+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11466 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11467 dump_stack();
11468 unhandled_fault(regs->tpc, current, regs);
11469@@ -281,6 +284,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11470 show_regs(regs);
11471 }
11472
11473+#ifdef CONFIG_PAX_PAGEEXEC
11474+#ifdef CONFIG_PAX_DLRESOLVE
11475+static void pax_emuplt_close(struct vm_area_struct *vma)
11476+{
11477+ vma->vm_mm->call_dl_resolve = 0UL;
11478+}
11479+
11480+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11481+{
11482+ unsigned int *kaddr;
11483+
11484+ vmf->page = alloc_page(GFP_HIGHUSER);
11485+ if (!vmf->page)
11486+ return VM_FAULT_OOM;
11487+
11488+ kaddr = kmap(vmf->page);
11489+ memset(kaddr, 0, PAGE_SIZE);
11490+ kaddr[0] = 0x9DE3BFA8U; /* save */
11491+ flush_dcache_page(vmf->page);
11492+ kunmap(vmf->page);
11493+ return VM_FAULT_MAJOR;
11494+}
11495+
11496+static const struct vm_operations_struct pax_vm_ops = {
11497+ .close = pax_emuplt_close,
11498+ .fault = pax_emuplt_fault
11499+};
11500+
11501+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11502+{
11503+ int ret;
11504+
11505+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11506+ vma->vm_mm = current->mm;
11507+ vma->vm_start = addr;
11508+ vma->vm_end = addr + PAGE_SIZE;
11509+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11510+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11511+ vma->vm_ops = &pax_vm_ops;
11512+
11513+ ret = insert_vm_struct(current->mm, vma);
11514+ if (ret)
11515+ return ret;
11516+
11517+ ++current->mm->total_vm;
11518+ return 0;
11519+}
11520+#endif
11521+
11522+/*
11523+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11524+ *
11525+ * returns 1 when task should be killed
11526+ * 2 when patched PLT trampoline was detected
11527+ * 3 when unpatched PLT trampoline was detected
11528+ */
11529+static int pax_handle_fetch_fault(struct pt_regs *regs)
11530+{
11531+
11532+#ifdef CONFIG_PAX_EMUPLT
11533+ int err;
11534+
11535+ do { /* PaX: patched PLT emulation #1 */
11536+ unsigned int sethi1, sethi2, jmpl;
11537+
11538+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11539+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11540+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11541+
11542+ if (err)
11543+ break;
11544+
11545+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11546+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11547+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11548+ {
11549+ unsigned long addr;
11550+
11551+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11552+ addr = regs->u_regs[UREG_G1];
11553+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11554+
11555+ if (test_thread_flag(TIF_32BIT))
11556+ addr &= 0xFFFFFFFFUL;
11557+
11558+ regs->tpc = addr;
11559+ regs->tnpc = addr+4;
11560+ return 2;
11561+ }
11562+ } while (0);
11563+
11564+ do { /* PaX: patched PLT emulation #2 */
11565+ unsigned int ba;
11566+
11567+ err = get_user(ba, (unsigned int *)regs->tpc);
11568+
11569+ if (err)
11570+ break;
11571+
11572+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11573+ unsigned long addr;
11574+
11575+ if ((ba & 0xFFC00000U) == 0x30800000U)
11576+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11577+ else
11578+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11579+
11580+ if (test_thread_flag(TIF_32BIT))
11581+ addr &= 0xFFFFFFFFUL;
11582+
11583+ regs->tpc = addr;
11584+ regs->tnpc = addr+4;
11585+ return 2;
11586+ }
11587+ } while (0);
11588+
11589+ do { /* PaX: patched PLT emulation #3 */
11590+ unsigned int sethi, bajmpl, nop;
11591+
11592+ err = get_user(sethi, (unsigned int *)regs->tpc);
11593+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11594+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11595+
11596+ if (err)
11597+ break;
11598+
11599+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11600+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11601+ nop == 0x01000000U)
11602+ {
11603+ unsigned long addr;
11604+
11605+ addr = (sethi & 0x003FFFFFU) << 10;
11606+ regs->u_regs[UREG_G1] = addr;
11607+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11608+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11609+ else
11610+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11611+
11612+ if (test_thread_flag(TIF_32BIT))
11613+ addr &= 0xFFFFFFFFUL;
11614+
11615+ regs->tpc = addr;
11616+ regs->tnpc = addr+4;
11617+ return 2;
11618+ }
11619+ } while (0);
11620+
11621+ do { /* PaX: patched PLT emulation #4 */
11622+ unsigned int sethi, mov1, call, mov2;
11623+
11624+ err = get_user(sethi, (unsigned int *)regs->tpc);
11625+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11626+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11627+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11628+
11629+ if (err)
11630+ break;
11631+
11632+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11633+ mov1 == 0x8210000FU &&
11634+ (call & 0xC0000000U) == 0x40000000U &&
11635+ mov2 == 0x9E100001U)
11636+ {
11637+ unsigned long addr;
11638+
11639+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11640+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11641+
11642+ if (test_thread_flag(TIF_32BIT))
11643+ addr &= 0xFFFFFFFFUL;
11644+
11645+ regs->tpc = addr;
11646+ regs->tnpc = addr+4;
11647+ return 2;
11648+ }
11649+ } while (0);
11650+
11651+ do { /* PaX: patched PLT emulation #5 */
11652+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11653+
11654+ err = get_user(sethi, (unsigned int *)regs->tpc);
11655+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11656+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11657+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11658+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11659+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11660+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11661+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11662+
11663+ if (err)
11664+ break;
11665+
11666+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11667+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11668+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11669+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11670+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11671+ sllx == 0x83287020U &&
11672+ jmpl == 0x81C04005U &&
11673+ nop == 0x01000000U)
11674+ {
11675+ unsigned long addr;
11676+
11677+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11678+ regs->u_regs[UREG_G1] <<= 32;
11679+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11680+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11681+ regs->tpc = addr;
11682+ regs->tnpc = addr+4;
11683+ return 2;
11684+ }
11685+ } while (0);
11686+
11687+ do { /* PaX: patched PLT emulation #6 */
11688+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11689+
11690+ err = get_user(sethi, (unsigned int *)regs->tpc);
11691+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11692+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11693+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11694+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11695+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11696+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11697+
11698+ if (err)
11699+ break;
11700+
11701+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11702+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11703+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11704+ sllx == 0x83287020U &&
11705+ (or & 0xFFFFE000U) == 0x8A116000U &&
11706+ jmpl == 0x81C04005U &&
11707+ nop == 0x01000000U)
11708+ {
11709+ unsigned long addr;
11710+
11711+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11712+ regs->u_regs[UREG_G1] <<= 32;
11713+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11714+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11715+ regs->tpc = addr;
11716+ regs->tnpc = addr+4;
11717+ return 2;
11718+ }
11719+ } while (0);
11720+
11721+ do { /* PaX: unpatched PLT emulation step 1 */
11722+ unsigned int sethi, ba, nop;
11723+
11724+ err = get_user(sethi, (unsigned int *)regs->tpc);
11725+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11726+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11727+
11728+ if (err)
11729+ break;
11730+
11731+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11732+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11733+ nop == 0x01000000U)
11734+ {
11735+ unsigned long addr;
11736+ unsigned int save, call;
11737+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11738+
11739+ if ((ba & 0xFFC00000U) == 0x30800000U)
11740+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11741+ else
11742+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11743+
11744+ if (test_thread_flag(TIF_32BIT))
11745+ addr &= 0xFFFFFFFFUL;
11746+
11747+ err = get_user(save, (unsigned int *)addr);
11748+ err |= get_user(call, (unsigned int *)(addr+4));
11749+ err |= get_user(nop, (unsigned int *)(addr+8));
11750+ if (err)
11751+ break;
11752+
11753+#ifdef CONFIG_PAX_DLRESOLVE
11754+ if (save == 0x9DE3BFA8U &&
11755+ (call & 0xC0000000U) == 0x40000000U &&
11756+ nop == 0x01000000U)
11757+ {
11758+ struct vm_area_struct *vma;
11759+ unsigned long call_dl_resolve;
11760+
11761+ down_read(&current->mm->mmap_sem);
11762+ call_dl_resolve = current->mm->call_dl_resolve;
11763+ up_read(&current->mm->mmap_sem);
11764+ if (likely(call_dl_resolve))
11765+ goto emulate;
11766+
11767+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11768+
11769+ down_write(&current->mm->mmap_sem);
11770+ if (current->mm->call_dl_resolve) {
11771+ call_dl_resolve = current->mm->call_dl_resolve;
11772+ up_write(&current->mm->mmap_sem);
11773+ if (vma)
11774+ kmem_cache_free(vm_area_cachep, vma);
11775+ goto emulate;
11776+ }
11777+
11778+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11779+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11780+ up_write(&current->mm->mmap_sem);
11781+ if (vma)
11782+ kmem_cache_free(vm_area_cachep, vma);
11783+ return 1;
11784+ }
11785+
11786+ if (pax_insert_vma(vma, call_dl_resolve)) {
11787+ up_write(&current->mm->mmap_sem);
11788+ kmem_cache_free(vm_area_cachep, vma);
11789+ return 1;
11790+ }
11791+
11792+ current->mm->call_dl_resolve = call_dl_resolve;
11793+ up_write(&current->mm->mmap_sem);
11794+
11795+emulate:
11796+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11797+ regs->tpc = call_dl_resolve;
11798+ regs->tnpc = addr+4;
11799+ return 3;
11800+ }
11801+#endif
11802+
11803+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11804+ if ((save & 0xFFC00000U) == 0x05000000U &&
11805+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11806+ nop == 0x01000000U)
11807+ {
11808+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11809+ regs->u_regs[UREG_G2] = addr + 4;
11810+ addr = (save & 0x003FFFFFU) << 10;
11811+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11812+
11813+ if (test_thread_flag(TIF_32BIT))
11814+ addr &= 0xFFFFFFFFUL;
11815+
11816+ regs->tpc = addr;
11817+ regs->tnpc = addr+4;
11818+ return 3;
11819+ }
11820+
11821+ /* PaX: 64-bit PLT stub */
11822+ err = get_user(sethi1, (unsigned int *)addr);
11823+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11824+ err |= get_user(or1, (unsigned int *)(addr+8));
11825+ err |= get_user(or2, (unsigned int *)(addr+12));
11826+ err |= get_user(sllx, (unsigned int *)(addr+16));
11827+ err |= get_user(add, (unsigned int *)(addr+20));
11828+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11829+ err |= get_user(nop, (unsigned int *)(addr+28));
11830+ if (err)
11831+ break;
11832+
11833+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11834+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11835+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11836+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11837+ sllx == 0x89293020U &&
11838+ add == 0x8A010005U &&
11839+ jmpl == 0x89C14000U &&
11840+ nop == 0x01000000U)
11841+ {
11842+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11843+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11844+ regs->u_regs[UREG_G4] <<= 32;
11845+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11846+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11847+ regs->u_regs[UREG_G4] = addr + 24;
11848+ addr = regs->u_regs[UREG_G5];
11849+ regs->tpc = addr;
11850+ regs->tnpc = addr+4;
11851+ return 3;
11852+ }
11853+ }
11854+ } while (0);
11855+
11856+#ifdef CONFIG_PAX_DLRESOLVE
11857+ do { /* PaX: unpatched PLT emulation step 2 */
11858+ unsigned int save, call, nop;
11859+
11860+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11861+ err |= get_user(call, (unsigned int *)regs->tpc);
11862+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11863+ if (err)
11864+ break;
11865+
11866+ if (save == 0x9DE3BFA8U &&
11867+ (call & 0xC0000000U) == 0x40000000U &&
11868+ nop == 0x01000000U)
11869+ {
11870+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11871+
11872+ if (test_thread_flag(TIF_32BIT))
11873+ dl_resolve &= 0xFFFFFFFFUL;
11874+
11875+ regs->u_regs[UREG_RETPC] = regs->tpc;
11876+ regs->tpc = dl_resolve;
11877+ regs->tnpc = dl_resolve+4;
11878+ return 3;
11879+ }
11880+ } while (0);
11881+#endif
11882+
11883+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11884+ unsigned int sethi, ba, nop;
11885+
11886+ err = get_user(sethi, (unsigned int *)regs->tpc);
11887+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11888+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11889+
11890+ if (err)
11891+ break;
11892+
11893+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11894+ (ba & 0xFFF00000U) == 0x30600000U &&
11895+ nop == 0x01000000U)
11896+ {
11897+ unsigned long addr;
11898+
11899+ addr = (sethi & 0x003FFFFFU) << 10;
11900+ regs->u_regs[UREG_G1] = addr;
11901+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11902+
11903+ if (test_thread_flag(TIF_32BIT))
11904+ addr &= 0xFFFFFFFFUL;
11905+
11906+ regs->tpc = addr;
11907+ regs->tnpc = addr+4;
11908+ return 2;
11909+ }
11910+ } while (0);
11911+
11912+#endif
11913+
11914+ return 1;
11915+}
11916+
11917+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11918+{
11919+ unsigned long i;
11920+
11921+ printk(KERN_ERR "PAX: bytes at PC: ");
11922+ for (i = 0; i < 8; i++) {
11923+ unsigned int c;
11924+ if (get_user(c, (unsigned int *)pc+i))
11925+ printk(KERN_CONT "???????? ");
11926+ else
11927+ printk(KERN_CONT "%08x ", c);
11928+ }
11929+ printk("\n");
11930+}
11931+#endif
11932+
11933 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11934 {
11935 enum ctx_state prev_state = exception_enter();
11936@@ -352,6 +815,29 @@ retry:
11937 if (!vma)
11938 goto bad_area;
11939
11940+#ifdef CONFIG_PAX_PAGEEXEC
11941+ /* PaX: detect ITLB misses on non-exec pages */
11942+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11943+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11944+ {
11945+ if (address != regs->tpc)
11946+ goto good_area;
11947+
11948+ up_read(&mm->mmap_sem);
11949+ switch (pax_handle_fetch_fault(regs)) {
11950+
11951+#ifdef CONFIG_PAX_EMUPLT
11952+ case 2:
11953+ case 3:
11954+ return;
11955+#endif
11956+
11957+ }
11958+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11959+ do_group_exit(SIGKILL);
11960+ }
11961+#endif
11962+
11963 /* Pure DTLB misses do not tell us whether the fault causing
11964 * load/store/atomic was a write or not, it only says that there
11965 * was no match. So in such a case we (carefully) read the
11966diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11967index d329537..2c3746a 100644
11968--- a/arch/sparc/mm/hugetlbpage.c
11969+++ b/arch/sparc/mm/hugetlbpage.c
11970@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11971 unsigned long addr,
11972 unsigned long len,
11973 unsigned long pgoff,
11974- unsigned long flags)
11975+ unsigned long flags,
11976+ unsigned long offset)
11977 {
11978+ struct mm_struct *mm = current->mm;
11979 unsigned long task_size = TASK_SIZE;
11980 struct vm_unmapped_area_info info;
11981
11982@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11983
11984 info.flags = 0;
11985 info.length = len;
11986- info.low_limit = TASK_UNMAPPED_BASE;
11987+ info.low_limit = mm->mmap_base;
11988 info.high_limit = min(task_size, VA_EXCLUDE_START);
11989 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11990 info.align_offset = 0;
11991+ info.threadstack_offset = offset;
11992 addr = vm_unmapped_area(&info);
11993
11994 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11995 VM_BUG_ON(addr != -ENOMEM);
11996 info.low_limit = VA_EXCLUDE_END;
11997+
11998+#ifdef CONFIG_PAX_RANDMMAP
11999+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12000+ info.low_limit += mm->delta_mmap;
12001+#endif
12002+
12003 info.high_limit = task_size;
12004 addr = vm_unmapped_area(&info);
12005 }
12006@@ -55,7 +64,8 @@ static unsigned long
12007 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12008 const unsigned long len,
12009 const unsigned long pgoff,
12010- const unsigned long flags)
12011+ const unsigned long flags,
12012+ const unsigned long offset)
12013 {
12014 struct mm_struct *mm = current->mm;
12015 unsigned long addr = addr0;
12016@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12017 info.high_limit = mm->mmap_base;
12018 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12019 info.align_offset = 0;
12020+ info.threadstack_offset = offset;
12021 addr = vm_unmapped_area(&info);
12022
12023 /*
12024@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12025 VM_BUG_ON(addr != -ENOMEM);
12026 info.flags = 0;
12027 info.low_limit = TASK_UNMAPPED_BASE;
12028+
12029+#ifdef CONFIG_PAX_RANDMMAP
12030+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12031+ info.low_limit += mm->delta_mmap;
12032+#endif
12033+
12034 info.high_limit = STACK_TOP32;
12035 addr = vm_unmapped_area(&info);
12036 }
12037@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12038 struct mm_struct *mm = current->mm;
12039 struct vm_area_struct *vma;
12040 unsigned long task_size = TASK_SIZE;
12041+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12042
12043 if (test_thread_flag(TIF_32BIT))
12044 task_size = STACK_TOP32;
12045@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12046 return addr;
12047 }
12048
12049+#ifdef CONFIG_PAX_RANDMMAP
12050+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12051+#endif
12052+
12053 if (addr) {
12054 addr = ALIGN(addr, HPAGE_SIZE);
12055 vma = find_vma(mm, addr);
12056- if (task_size - len >= addr &&
12057- (!vma || addr + len <= vma->vm_start))
12058+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12059 return addr;
12060 }
12061 if (mm->get_unmapped_area == arch_get_unmapped_area)
12062 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12063- pgoff, flags);
12064+ pgoff, flags, offset);
12065 else
12066 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12067- pgoff, flags);
12068+ pgoff, flags, offset);
12069 }
12070
12071 pte_t *huge_pte_alloc(struct mm_struct *mm,
12072diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12073index 9686224..dfbdb10 100644
12074--- a/arch/sparc/mm/init_64.c
12075+++ b/arch/sparc/mm/init_64.c
12076@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12077 int num_kernel_image_mappings;
12078
12079 #ifdef CONFIG_DEBUG_DCFLUSH
12080-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12081+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12082 #ifdef CONFIG_SMP
12083-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12084+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12085 #endif
12086 #endif
12087
12088@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12089 {
12090 BUG_ON(tlb_type == hypervisor);
12091 #ifdef CONFIG_DEBUG_DCFLUSH
12092- atomic_inc(&dcpage_flushes);
12093+ atomic_inc_unchecked(&dcpage_flushes);
12094 #endif
12095
12096 #ifdef DCACHE_ALIASING_POSSIBLE
12097@@ -470,10 +470,10 @@ void mmu_info(struct seq_file *m)
12098
12099 #ifdef CONFIG_DEBUG_DCFLUSH
12100 seq_printf(m, "DCPageFlushes\t: %d\n",
12101- atomic_read(&dcpage_flushes));
12102+ atomic_read_unchecked(&dcpage_flushes));
12103 #ifdef CONFIG_SMP
12104 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12105- atomic_read(&dcpage_flushes_xcall));
12106+ atomic_read_unchecked(&dcpage_flushes_xcall));
12107 #endif /* CONFIG_SMP */
12108 #endif /* CONFIG_DEBUG_DCFLUSH */
12109 }
12110diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12111index 85258ca..df97c79 100644
12112--- a/arch/tile/Kconfig
12113+++ b/arch/tile/Kconfig
12114@@ -190,6 +190,7 @@ source "kernel/Kconfig.hz"
12115
12116 config KEXEC
12117 bool "kexec system call"
12118+ depends on !GRKERNSEC_KMEM
12119 ---help---
12120 kexec is a system call that implements the ability to shutdown your
12121 current kernel, and to start another kernel. It is like a reboot
12122diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12123index ad220ee..2f537b3 100644
12124--- a/arch/tile/include/asm/atomic_64.h
12125+++ b/arch/tile/include/asm/atomic_64.h
12126@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12127
12128 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12129
12130+#define atomic64_read_unchecked(v) atomic64_read(v)
12131+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12132+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12133+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12134+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12135+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12136+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12137+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12138+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12139+
12140 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12141 #define smp_mb__before_atomic_dec() smp_mb()
12142 #define smp_mb__after_atomic_dec() smp_mb()
12143diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12144index 6160761..00cac88 100644
12145--- a/arch/tile/include/asm/cache.h
12146+++ b/arch/tile/include/asm/cache.h
12147@@ -15,11 +15,12 @@
12148 #ifndef _ASM_TILE_CACHE_H
12149 #define _ASM_TILE_CACHE_H
12150
12151+#include <linux/const.h>
12152 #include <arch/chip.h>
12153
12154 /* bytes per L1 data cache line */
12155 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12156-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12157+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12158
12159 /* bytes per L2 cache line */
12160 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12161diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12162index b6cde32..c0cb736 100644
12163--- a/arch/tile/include/asm/uaccess.h
12164+++ b/arch/tile/include/asm/uaccess.h
12165@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12166 const void __user *from,
12167 unsigned long n)
12168 {
12169- int sz = __compiletime_object_size(to);
12170+ size_t sz = __compiletime_object_size(to);
12171
12172- if (likely(sz == -1 || sz >= n))
12173+ if (likely(sz == (size_t)-1 || sz >= n))
12174 n = _copy_from_user(to, from, n);
12175 else
12176 copy_from_user_overflow();
12177diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12178index e514899..f8743c4 100644
12179--- a/arch/tile/mm/hugetlbpage.c
12180+++ b/arch/tile/mm/hugetlbpage.c
12181@@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12182 info.high_limit = TASK_SIZE;
12183 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12184 info.align_offset = 0;
12185+ info.threadstack_offset = 0;
12186 return vm_unmapped_area(&info);
12187 }
12188
12189@@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12190 info.high_limit = current->mm->mmap_base;
12191 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12192 info.align_offset = 0;
12193+ info.threadstack_offset = 0;
12194 addr = vm_unmapped_area(&info);
12195
12196 /*
12197diff --git a/arch/um/Makefile b/arch/um/Makefile
12198index 36e658a..71a5c5a 100644
12199--- a/arch/um/Makefile
12200+++ b/arch/um/Makefile
12201@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12202 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12203 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12204
12205+ifdef CONSTIFY_PLUGIN
12206+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12207+endif
12208+
12209 #This will adjust *FLAGS accordingly to the platform.
12210 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12211
12212diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12213index 19e1bdd..3665b77 100644
12214--- a/arch/um/include/asm/cache.h
12215+++ b/arch/um/include/asm/cache.h
12216@@ -1,6 +1,7 @@
12217 #ifndef __UM_CACHE_H
12218 #define __UM_CACHE_H
12219
12220+#include <linux/const.h>
12221
12222 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12223 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12224@@ -12,6 +13,6 @@
12225 # define L1_CACHE_SHIFT 5
12226 #endif
12227
12228-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12229+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12230
12231 #endif
12232diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12233index 2e0a6b1..a64d0f5 100644
12234--- a/arch/um/include/asm/kmap_types.h
12235+++ b/arch/um/include/asm/kmap_types.h
12236@@ -8,6 +8,6 @@
12237
12238 /* No more #include "asm/arch/kmap_types.h" ! */
12239
12240-#define KM_TYPE_NR 14
12241+#define KM_TYPE_NR 15
12242
12243 #endif
12244diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12245index 5ff53d9..5850cdf 100644
12246--- a/arch/um/include/asm/page.h
12247+++ b/arch/um/include/asm/page.h
12248@@ -14,6 +14,9 @@
12249 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12250 #define PAGE_MASK (~(PAGE_SIZE-1))
12251
12252+#define ktla_ktva(addr) (addr)
12253+#define ktva_ktla(addr) (addr)
12254+
12255 #ifndef __ASSEMBLY__
12256
12257 struct page;
12258diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12259index 0032f92..cd151e0 100644
12260--- a/arch/um/include/asm/pgtable-3level.h
12261+++ b/arch/um/include/asm/pgtable-3level.h
12262@@ -58,6 +58,7 @@
12263 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12264 #define pud_populate(mm, pud, pmd) \
12265 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12266+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12267
12268 #ifdef CONFIG_64BIT
12269 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12270diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12271index f17bca8..48adb87 100644
12272--- a/arch/um/kernel/process.c
12273+++ b/arch/um/kernel/process.c
12274@@ -356,22 +356,6 @@ int singlestepping(void * t)
12275 return 2;
12276 }
12277
12278-/*
12279- * Only x86 and x86_64 have an arch_align_stack().
12280- * All other arches have "#define arch_align_stack(x) (x)"
12281- * in their asm/exec.h
12282- * As this is included in UML from asm-um/system-generic.h,
12283- * we can use it to behave as the subarch does.
12284- */
12285-#ifndef arch_align_stack
12286-unsigned long arch_align_stack(unsigned long sp)
12287-{
12288- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12289- sp -= get_random_int() % 8192;
12290- return sp & ~0xf;
12291-}
12292-#endif
12293-
12294 unsigned long get_wchan(struct task_struct *p)
12295 {
12296 unsigned long stack_page, sp, ip;
12297diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12298index ad8f795..2c7eec6 100644
12299--- a/arch/unicore32/include/asm/cache.h
12300+++ b/arch/unicore32/include/asm/cache.h
12301@@ -12,8 +12,10 @@
12302 #ifndef __UNICORE_CACHE_H__
12303 #define __UNICORE_CACHE_H__
12304
12305-#define L1_CACHE_SHIFT (5)
12306-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12307+#include <linux/const.h>
12308+
12309+#define L1_CACHE_SHIFT 5
12310+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12311
12312 /*
12313 * Memory returned by kmalloc() may be used for DMA, so we must make
12314diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12315index 1dd1408..be4ce12 100644
12316--- a/arch/x86/Kconfig
12317+++ b/arch/x86/Kconfig
12318@@ -127,7 +127,7 @@ config X86
12319 select RTC_LIB
12320 select HAVE_DEBUG_STACKOVERFLOW
12321 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12322- select HAVE_CC_STACKPROTECTOR
12323+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12324 select GENERIC_CPU_AUTOPROBE
12325 select HAVE_ARCH_AUDITSYSCALL
12326 select ARCH_SUPPORTS_ATOMIC_RMW
12327@@ -252,7 +252,7 @@ config X86_HT
12328
12329 config X86_32_LAZY_GS
12330 def_bool y
12331- depends on X86_32 && !CC_STACKPROTECTOR
12332+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12333
12334 config ARCH_HWEIGHT_CFLAGS
12335 string
12336@@ -546,6 +546,7 @@ config SCHED_OMIT_FRAME_POINTER
12337
12338 menuconfig HYPERVISOR_GUEST
12339 bool "Linux guest support"
12340+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12341 ---help---
12342 Say Y here to enable options for running Linux under various hyper-
12343 visors. This option enables basic hypervisor detection and platform
12344@@ -1072,6 +1073,7 @@ choice
12345
12346 config NOHIGHMEM
12347 bool "off"
12348+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12349 ---help---
12350 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12351 However, the address space of 32-bit x86 processors is only 4
12352@@ -1108,6 +1110,7 @@ config NOHIGHMEM
12353
12354 config HIGHMEM4G
12355 bool "4GB"
12356+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12357 ---help---
12358 Select this if you have a 32-bit processor and between 1 and 4
12359 gigabytes of physical RAM.
12360@@ -1160,7 +1163,7 @@ config PAGE_OFFSET
12361 hex
12362 default 0xB0000000 if VMSPLIT_3G_OPT
12363 default 0x80000000 if VMSPLIT_2G
12364- default 0x78000000 if VMSPLIT_2G_OPT
12365+ default 0x70000000 if VMSPLIT_2G_OPT
12366 default 0x40000000 if VMSPLIT_1G
12367 default 0xC0000000
12368 depends on X86_32
12369@@ -1573,6 +1576,7 @@ source kernel/Kconfig.hz
12370
12371 config KEXEC
12372 bool "kexec system call"
12373+ depends on !GRKERNSEC_KMEM
12374 ---help---
12375 kexec is a system call that implements the ability to shutdown your
12376 current kernel, and to start another kernel. It is like a reboot
12377@@ -1724,7 +1728,9 @@ config X86_NEED_RELOCS
12378
12379 config PHYSICAL_ALIGN
12380 hex "Alignment value to which kernel should be aligned"
12381- default "0x200000"
12382+ default "0x1000000"
12383+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12384+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12385 range 0x2000 0x1000000 if X86_32
12386 range 0x200000 0x1000000 if X86_64
12387 ---help---
12388@@ -1807,6 +1813,7 @@ config COMPAT_VDSO
12389 def_bool n
12390 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12391 depends on X86_32 || IA32_EMULATION
12392+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12393 ---help---
12394 Certain buggy versions of glibc will crash if they are
12395 presented with a 32-bit vDSO that is not mapped at the address
12396diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12397index 6983314..54ad7e8 100644
12398--- a/arch/x86/Kconfig.cpu
12399+++ b/arch/x86/Kconfig.cpu
12400@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12401
12402 config X86_F00F_BUG
12403 def_bool y
12404- depends on M586MMX || M586TSC || M586 || M486
12405+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12406
12407 config X86_INVD_BUG
12408 def_bool y
12409@@ -327,7 +327,7 @@ config X86_INVD_BUG
12410
12411 config X86_ALIGNMENT_16
12412 def_bool y
12413- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12414+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12415
12416 config X86_INTEL_USERCOPY
12417 def_bool y
12418@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12419 # generates cmov.
12420 config X86_CMOV
12421 def_bool y
12422- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12423+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12424
12425 config X86_MINIMUM_CPU_FAMILY
12426 int
12427diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12428index 61bd2ad..50b625d 100644
12429--- a/arch/x86/Kconfig.debug
12430+++ b/arch/x86/Kconfig.debug
12431@@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12432 config DEBUG_RODATA
12433 bool "Write protect kernel read-only data structures"
12434 default y
12435- depends on DEBUG_KERNEL
12436+ depends on DEBUG_KERNEL && BROKEN
12437 ---help---
12438 Mark the kernel read-only data as write-protected in the pagetables,
12439 in order to catch accidental (and incorrect) writes to such const
12440@@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12441
12442 config DEBUG_SET_MODULE_RONX
12443 bool "Set loadable kernel module data as NX and text as RO"
12444- depends on MODULES
12445+ depends on MODULES && BROKEN
12446 ---help---
12447 This option helps catch unintended modifications to loadable
12448 kernel module's text and read-only data. It also prevents execution
12449diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12450index 33f71b0..c2cefa2 100644
12451--- a/arch/x86/Makefile
12452+++ b/arch/x86/Makefile
12453@@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12454 # CPU-specific tuning. Anything which can be shared with UML should go here.
12455 include $(srctree)/arch/x86/Makefile_32.cpu
12456 KBUILD_CFLAGS += $(cflags-y)
12457-
12458- # temporary until string.h is fixed
12459- KBUILD_CFLAGS += -ffreestanding
12460 else
12461 BITS := 64
12462 UTS_MACHINE := x86_64
12463@@ -114,6 +111,9 @@ else
12464 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12465 endif
12466
12467+# temporary until string.h is fixed
12468+KBUILD_CFLAGS += -ffreestanding
12469+
12470 # Make sure compiler does not have buggy stack-protector support.
12471 ifdef CONFIG_CC_STACKPROTECTOR
12472 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12473@@ -271,3 +271,12 @@ define archhelp
12474 echo ' FDINITRD=file initrd for the booted kernel'
12475 echo ' kvmconfig - Enable additional options for guest kernel support'
12476 endef
12477+
12478+define OLD_LD
12479+
12480+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12481+*** Please upgrade your binutils to 2.18 or newer
12482+endef
12483+
12484+archprepare:
12485+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12486diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12487index dbe8dd2..2f0a98f 100644
12488--- a/arch/x86/boot/Makefile
12489+++ b/arch/x86/boot/Makefile
12490@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12491 # ---------------------------------------------------------------------------
12492
12493 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12494+ifdef CONSTIFY_PLUGIN
12495+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12496+endif
12497 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12498 GCOV_PROFILE := n
12499
12500diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12501index 878e4b9..20537ab 100644
12502--- a/arch/x86/boot/bitops.h
12503+++ b/arch/x86/boot/bitops.h
12504@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12505 u8 v;
12506 const u32 *p = (const u32 *)addr;
12507
12508- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12509+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12510 return v;
12511 }
12512
12513@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12514
12515 static inline void set_bit(int nr, void *addr)
12516 {
12517- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12518+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12519 }
12520
12521 #endif /* BOOT_BITOPS_H */
12522diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12523index bd49ec6..94c7f58 100644
12524--- a/arch/x86/boot/boot.h
12525+++ b/arch/x86/boot/boot.h
12526@@ -84,7 +84,7 @@ static inline void io_delay(void)
12527 static inline u16 ds(void)
12528 {
12529 u16 seg;
12530- asm("movw %%ds,%0" : "=rm" (seg));
12531+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12532 return seg;
12533 }
12534
12535diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12536index 0fcd913..3bb5c42 100644
12537--- a/arch/x86/boot/compressed/Makefile
12538+++ b/arch/x86/boot/compressed/Makefile
12539@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12540 KBUILD_CFLAGS += -mno-mmx -mno-sse
12541 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12542 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12543+ifdef CONSTIFY_PLUGIN
12544+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12545+endif
12546
12547 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12548 GCOV_PROFILE := n
12549diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12550index a53440e..c3dbf1e 100644
12551--- a/arch/x86/boot/compressed/efi_stub_32.S
12552+++ b/arch/x86/boot/compressed/efi_stub_32.S
12553@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12554 * parameter 2, ..., param n. To make things easy, we save the return
12555 * address of efi_call_phys in a global variable.
12556 */
12557- popl %ecx
12558- movl %ecx, saved_return_addr(%edx)
12559- /* get the function pointer into ECX*/
12560- popl %ecx
12561- movl %ecx, efi_rt_function_ptr(%edx)
12562+ popl saved_return_addr(%edx)
12563+ popl efi_rt_function_ptr(%edx)
12564
12565 /*
12566 * 3. Call the physical function.
12567 */
12568- call *%ecx
12569+ call *efi_rt_function_ptr(%edx)
12570
12571 /*
12572 * 4. Balance the stack. And because EAX contain the return value,
12573@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12574 1: popl %edx
12575 subl $1b, %edx
12576
12577- movl efi_rt_function_ptr(%edx), %ecx
12578- pushl %ecx
12579+ pushl efi_rt_function_ptr(%edx)
12580
12581 /*
12582 * 10. Push the saved return address onto the stack and return.
12583 */
12584- movl saved_return_addr(%edx), %ecx
12585- pushl %ecx
12586- ret
12587+ jmpl *saved_return_addr(%edx)
12588 ENDPROC(efi_call_phys)
12589 .previous
12590
12591diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12592index cbed140..5f2ca57 100644
12593--- a/arch/x86/boot/compressed/head_32.S
12594+++ b/arch/x86/boot/compressed/head_32.S
12595@@ -140,10 +140,10 @@ preferred_addr:
12596 addl %eax, %ebx
12597 notl %eax
12598 andl %eax, %ebx
12599- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12600+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12601 jge 1f
12602 #endif
12603- movl $LOAD_PHYSICAL_ADDR, %ebx
12604+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12605 1:
12606
12607 /* Target address to relocate to for decompression */
12608diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12609index 0d558ee..58f257e 100644
12610--- a/arch/x86/boot/compressed/head_64.S
12611+++ b/arch/x86/boot/compressed/head_64.S
12612@@ -94,10 +94,10 @@ ENTRY(startup_32)
12613 addl %eax, %ebx
12614 notl %eax
12615 andl %eax, %ebx
12616- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12617+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12618 jge 1f
12619 #endif
12620- movl $LOAD_PHYSICAL_ADDR, %ebx
12621+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12622 1:
12623
12624 /* Target address to relocate to for decompression */
12625@@ -322,10 +322,10 @@ preferred_addr:
12626 addq %rax, %rbp
12627 notq %rax
12628 andq %rax, %rbp
12629- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12630+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12631 jge 1f
12632 #endif
12633- movq $LOAD_PHYSICAL_ADDR, %rbp
12634+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12635 1:
12636
12637 /* Target address to relocate to for decompression */
12638@@ -431,8 +431,8 @@ gdt:
12639 .long gdt
12640 .word 0
12641 .quad 0x0000000000000000 /* NULL descriptor */
12642- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12643- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12644+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12645+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12646 .quad 0x0080890000000000 /* TS descriptor */
12647 .quad 0x0000000000000000 /* TS continued */
12648 gdt_end:
12649diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12650index 57ab74d..7c52182 100644
12651--- a/arch/x86/boot/compressed/misc.c
12652+++ b/arch/x86/boot/compressed/misc.c
12653@@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12654 * Calculate the delta between where vmlinux was linked to load
12655 * and where it was actually loaded.
12656 */
12657- delta = min_addr - LOAD_PHYSICAL_ADDR;
12658+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12659 if (!delta) {
12660 debug_putstr("No relocation needed... ");
12661 return;
12662@@ -312,7 +312,7 @@ static void parse_elf(void *output)
12663 Elf32_Ehdr ehdr;
12664 Elf32_Phdr *phdrs, *phdr;
12665 #endif
12666- void *dest;
12667+ void *dest, *prev;
12668 int i;
12669
12670 memcpy(&ehdr, output, sizeof(ehdr));
12671@@ -339,13 +339,16 @@ static void parse_elf(void *output)
12672 case PT_LOAD:
12673 #ifdef CONFIG_RELOCATABLE
12674 dest = output;
12675- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12676+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12677 #else
12678 dest = (void *)(phdr->p_paddr);
12679 #endif
12680 memcpy(dest,
12681 output + phdr->p_offset,
12682 phdr->p_filesz);
12683+ if (i)
12684+ memset(prev, 0xff, dest - prev);
12685+ prev = dest + phdr->p_filesz;
12686 break;
12687 default: /* Ignore other PT_* */ break;
12688 }
12689@@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12690 error("Destination address too large");
12691 #endif
12692 #ifndef CONFIG_RELOCATABLE
12693- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12694+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12695 error("Wrong destination address");
12696 #endif
12697
12698diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12699index 1fd7d57..0f7d096 100644
12700--- a/arch/x86/boot/cpucheck.c
12701+++ b/arch/x86/boot/cpucheck.c
12702@@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12703 u32 ecx = MSR_K7_HWCR;
12704 u32 eax, edx;
12705
12706- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12707+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12708 eax &= ~(1 << 15);
12709- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12710+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12711
12712 get_cpuflags(); /* Make sure it really did something */
12713 err = check_cpuflags();
12714@@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12715 u32 ecx = MSR_VIA_FCR;
12716 u32 eax, edx;
12717
12718- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12719+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12720 eax |= (1<<1)|(1<<7);
12721- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12722+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12723
12724 set_bit(X86_FEATURE_CX8, cpu.flags);
12725 err = check_cpuflags();
12726@@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12727 u32 eax, edx;
12728 u32 level = 1;
12729
12730- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12731- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12732- asm("cpuid"
12733+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12734+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12735+ asm volatile("cpuid"
12736 : "+a" (level), "=d" (cpu.flags[0])
12737 : : "ecx", "ebx");
12738- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12739+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12740
12741 err = check_cpuflags();
12742 } else if (err == 0x01 &&
12743diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12744index 7a6d43a..edf6e40 100644
12745--- a/arch/x86/boot/header.S
12746+++ b/arch/x86/boot/header.S
12747@@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12748 # single linked list of
12749 # struct setup_data
12750
12751-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12752+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12753
12754 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12755+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12756+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12757+#else
12758 #define VO_INIT_SIZE (VO__end - VO__text)
12759+#endif
12760 #if ZO_INIT_SIZE > VO_INIT_SIZE
12761 #define INIT_SIZE ZO_INIT_SIZE
12762 #else
12763diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12764index db75d07..8e6d0af 100644
12765--- a/arch/x86/boot/memory.c
12766+++ b/arch/x86/boot/memory.c
12767@@ -19,7 +19,7 @@
12768
12769 static int detect_memory_e820(void)
12770 {
12771- int count = 0;
12772+ unsigned int count = 0;
12773 struct biosregs ireg, oreg;
12774 struct e820entry *desc = boot_params.e820_map;
12775 static struct e820entry buf; /* static so it is zeroed */
12776diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12777index ba3e100..6501b8f 100644
12778--- a/arch/x86/boot/video-vesa.c
12779+++ b/arch/x86/boot/video-vesa.c
12780@@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
12781
12782 boot_params.screen_info.vesapm_seg = oreg.es;
12783 boot_params.screen_info.vesapm_off = oreg.di;
12784+ boot_params.screen_info.vesapm_size = oreg.cx;
12785 }
12786
12787 /*
12788diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12789index 43eda28..5ab5fdb 100644
12790--- a/arch/x86/boot/video.c
12791+++ b/arch/x86/boot/video.c
12792@@ -96,7 +96,7 @@ static void store_mode_params(void)
12793 static unsigned int get_entry(void)
12794 {
12795 char entry_buf[4];
12796- int i, len = 0;
12797+ unsigned int i, len = 0;
12798 int key;
12799 unsigned int v;
12800
12801diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12802index 9105655..41779c1 100644
12803--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12804+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12805@@ -8,6 +8,8 @@
12806 * including this sentence is retained in full.
12807 */
12808
12809+#include <asm/alternative-asm.h>
12810+
12811 .extern crypto_ft_tab
12812 .extern crypto_it_tab
12813 .extern crypto_fl_tab
12814@@ -70,6 +72,8 @@
12815 je B192; \
12816 leaq 32(r9),r9;
12817
12818+#define ret pax_force_retaddr; ret
12819+
12820 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12821 movq r1,r2; \
12822 movq r3,r4; \
12823diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12824index 477e9d7..c92c7d8 100644
12825--- a/arch/x86/crypto/aesni-intel_asm.S
12826+++ b/arch/x86/crypto/aesni-intel_asm.S
12827@@ -31,6 +31,7 @@
12828
12829 #include <linux/linkage.h>
12830 #include <asm/inst.h>
12831+#include <asm/alternative-asm.h>
12832
12833 #ifdef __x86_64__
12834 .data
12835@@ -205,7 +206,7 @@ enc: .octa 0x2
12836 * num_initial_blocks = b mod 4
12837 * encrypt the initial num_initial_blocks blocks and apply ghash on
12838 * the ciphertext
12839-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12840+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12841 * are clobbered
12842 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12843 */
12844@@ -214,8 +215,8 @@ enc: .octa 0x2
12845 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12846 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12847 mov arg7, %r10 # %r10 = AAD
12848- mov arg8, %r12 # %r12 = aadLen
12849- mov %r12, %r11
12850+ mov arg8, %r15 # %r15 = aadLen
12851+ mov %r15, %r11
12852 pxor %xmm\i, %xmm\i
12853 _get_AAD_loop\num_initial_blocks\operation:
12854 movd (%r10), \TMP1
12855@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12856 psrldq $4, %xmm\i
12857 pxor \TMP1, %xmm\i
12858 add $4, %r10
12859- sub $4, %r12
12860+ sub $4, %r15
12861 jne _get_AAD_loop\num_initial_blocks\operation
12862 cmp $16, %r11
12863 je _get_AAD_loop2_done\num_initial_blocks\operation
12864- mov $16, %r12
12865+ mov $16, %r15
12866 _get_AAD_loop2\num_initial_blocks\operation:
12867 psrldq $4, %xmm\i
12868- sub $4, %r12
12869- cmp %r11, %r12
12870+ sub $4, %r15
12871+ cmp %r11, %r15
12872 jne _get_AAD_loop2\num_initial_blocks\operation
12873 _get_AAD_loop2_done\num_initial_blocks\operation:
12874 movdqa SHUF_MASK(%rip), %xmm14
12875@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12876 * num_initial_blocks = b mod 4
12877 * encrypt the initial num_initial_blocks blocks and apply ghash on
12878 * the ciphertext
12879-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12880+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12881 * are clobbered
12882 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12883 */
12884@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12885 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12886 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12887 mov arg7, %r10 # %r10 = AAD
12888- mov arg8, %r12 # %r12 = aadLen
12889- mov %r12, %r11
12890+ mov arg8, %r15 # %r15 = aadLen
12891+ mov %r15, %r11
12892 pxor %xmm\i, %xmm\i
12893 _get_AAD_loop\num_initial_blocks\operation:
12894 movd (%r10), \TMP1
12895@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12896 psrldq $4, %xmm\i
12897 pxor \TMP1, %xmm\i
12898 add $4, %r10
12899- sub $4, %r12
12900+ sub $4, %r15
12901 jne _get_AAD_loop\num_initial_blocks\operation
12902 cmp $16, %r11
12903 je _get_AAD_loop2_done\num_initial_blocks\operation
12904- mov $16, %r12
12905+ mov $16, %r15
12906 _get_AAD_loop2\num_initial_blocks\operation:
12907 psrldq $4, %xmm\i
12908- sub $4, %r12
12909- cmp %r11, %r12
12910+ sub $4, %r15
12911+ cmp %r11, %r15
12912 jne _get_AAD_loop2\num_initial_blocks\operation
12913 _get_AAD_loop2_done\num_initial_blocks\operation:
12914 movdqa SHUF_MASK(%rip), %xmm14
12915@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12916 *
12917 *****************************************************************************/
12918 ENTRY(aesni_gcm_dec)
12919- push %r12
12920+ push %r15
12921 push %r13
12922 push %r14
12923 mov %rsp, %r14
12924@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12925 */
12926 sub $VARIABLE_OFFSET, %rsp
12927 and $~63, %rsp # align rsp to 64 bytes
12928- mov %arg6, %r12
12929- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12930+ mov %arg6, %r15
12931+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12932 movdqa SHUF_MASK(%rip), %xmm2
12933 PSHUFB_XMM %xmm2, %xmm13
12934
12935@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12936 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12937 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12938 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12939- mov %r13, %r12
12940- and $(3<<4), %r12
12941+ mov %r13, %r15
12942+ and $(3<<4), %r15
12943 jz _initial_num_blocks_is_0_decrypt
12944- cmp $(2<<4), %r12
12945+ cmp $(2<<4), %r15
12946 jb _initial_num_blocks_is_1_decrypt
12947 je _initial_num_blocks_is_2_decrypt
12948 _initial_num_blocks_is_3_decrypt:
12949@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12950 sub $16, %r11
12951 add %r13, %r11
12952 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12953- lea SHIFT_MASK+16(%rip), %r12
12954- sub %r13, %r12
12955+ lea SHIFT_MASK+16(%rip), %r15
12956+ sub %r13, %r15
12957 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12958 # (%r13 is the number of bytes in plaintext mod 16)
12959- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12960+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12961 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12962
12963 movdqa %xmm1, %xmm2
12964 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12965- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12966+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12967 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12968 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12969 pand %xmm1, %xmm2
12970@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12971 sub $1, %r13
12972 jne _less_than_8_bytes_left_decrypt
12973 _multiple_of_16_bytes_decrypt:
12974- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12975- shl $3, %r12 # convert into number of bits
12976- movd %r12d, %xmm15 # len(A) in %xmm15
12977+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12978+ shl $3, %r15 # convert into number of bits
12979+ movd %r15d, %xmm15 # len(A) in %xmm15
12980 shl $3, %arg4 # len(C) in bits (*128)
12981 MOVQ_R64_XMM %arg4, %xmm1
12982 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12983@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12984 mov %r14, %rsp
12985 pop %r14
12986 pop %r13
12987- pop %r12
12988+ pop %r15
12989+ pax_force_retaddr
12990 ret
12991 ENDPROC(aesni_gcm_dec)
12992
12993@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12994 * poly = x^128 + x^127 + x^126 + x^121 + 1
12995 ***************************************************************************/
12996 ENTRY(aesni_gcm_enc)
12997- push %r12
12998+ push %r15
12999 push %r13
13000 push %r14
13001 mov %rsp, %r14
13002@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13003 #
13004 sub $VARIABLE_OFFSET, %rsp
13005 and $~63, %rsp
13006- mov %arg6, %r12
13007- movdqu (%r12), %xmm13
13008+ mov %arg6, %r15
13009+ movdqu (%r15), %xmm13
13010 movdqa SHUF_MASK(%rip), %xmm2
13011 PSHUFB_XMM %xmm2, %xmm13
13012
13013@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13014 movdqa %xmm13, HashKey(%rsp)
13015 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13016 and $-16, %r13
13017- mov %r13, %r12
13018+ mov %r13, %r15
13019
13020 # Encrypt first few blocks
13021
13022- and $(3<<4), %r12
13023+ and $(3<<4), %r15
13024 jz _initial_num_blocks_is_0_encrypt
13025- cmp $(2<<4), %r12
13026+ cmp $(2<<4), %r15
13027 jb _initial_num_blocks_is_1_encrypt
13028 je _initial_num_blocks_is_2_encrypt
13029 _initial_num_blocks_is_3_encrypt:
13030@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13031 sub $16, %r11
13032 add %r13, %r11
13033 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13034- lea SHIFT_MASK+16(%rip), %r12
13035- sub %r13, %r12
13036+ lea SHIFT_MASK+16(%rip), %r15
13037+ sub %r13, %r15
13038 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13039 # (%r13 is the number of bytes in plaintext mod 16)
13040- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13041+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13042 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13043 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13044- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13045+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13046 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13047 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13048 movdqa SHUF_MASK(%rip), %xmm10
13049@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13050 sub $1, %r13
13051 jne _less_than_8_bytes_left_encrypt
13052 _multiple_of_16_bytes_encrypt:
13053- mov arg8, %r12 # %r12 = addLen (number of bytes)
13054- shl $3, %r12
13055- movd %r12d, %xmm15 # len(A) in %xmm15
13056+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13057+ shl $3, %r15
13058+ movd %r15d, %xmm15 # len(A) in %xmm15
13059 shl $3, %arg4 # len(C) in bits (*128)
13060 MOVQ_R64_XMM %arg4, %xmm1
13061 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13062@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13063 mov %r14, %rsp
13064 pop %r14
13065 pop %r13
13066- pop %r12
13067+ pop %r15
13068+ pax_force_retaddr
13069 ret
13070 ENDPROC(aesni_gcm_enc)
13071
13072@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13073 pxor %xmm1, %xmm0
13074 movaps %xmm0, (TKEYP)
13075 add $0x10, TKEYP
13076+ pax_force_retaddr
13077 ret
13078 ENDPROC(_key_expansion_128)
13079 ENDPROC(_key_expansion_256a)
13080@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13081 shufps $0b01001110, %xmm2, %xmm1
13082 movaps %xmm1, 0x10(TKEYP)
13083 add $0x20, TKEYP
13084+ pax_force_retaddr
13085 ret
13086 ENDPROC(_key_expansion_192a)
13087
13088@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13089
13090 movaps %xmm0, (TKEYP)
13091 add $0x10, TKEYP
13092+ pax_force_retaddr
13093 ret
13094 ENDPROC(_key_expansion_192b)
13095
13096@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13097 pxor %xmm1, %xmm2
13098 movaps %xmm2, (TKEYP)
13099 add $0x10, TKEYP
13100+ pax_force_retaddr
13101 ret
13102 ENDPROC(_key_expansion_256b)
13103
13104@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13105 #ifndef __x86_64__
13106 popl KEYP
13107 #endif
13108+ pax_force_retaddr
13109 ret
13110 ENDPROC(aesni_set_key)
13111
13112@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13113 popl KLEN
13114 popl KEYP
13115 #endif
13116+ pax_force_retaddr
13117 ret
13118 ENDPROC(aesni_enc)
13119
13120@@ -1974,6 +1983,7 @@ _aesni_enc1:
13121 AESENC KEY STATE
13122 movaps 0x70(TKEYP), KEY
13123 AESENCLAST KEY STATE
13124+ pax_force_retaddr
13125 ret
13126 ENDPROC(_aesni_enc1)
13127
13128@@ -2083,6 +2093,7 @@ _aesni_enc4:
13129 AESENCLAST KEY STATE2
13130 AESENCLAST KEY STATE3
13131 AESENCLAST KEY STATE4
13132+ pax_force_retaddr
13133 ret
13134 ENDPROC(_aesni_enc4)
13135
13136@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13137 popl KLEN
13138 popl KEYP
13139 #endif
13140+ pax_force_retaddr
13141 ret
13142 ENDPROC(aesni_dec)
13143
13144@@ -2164,6 +2176,7 @@ _aesni_dec1:
13145 AESDEC KEY STATE
13146 movaps 0x70(TKEYP), KEY
13147 AESDECLAST KEY STATE
13148+ pax_force_retaddr
13149 ret
13150 ENDPROC(_aesni_dec1)
13151
13152@@ -2273,6 +2286,7 @@ _aesni_dec4:
13153 AESDECLAST KEY STATE2
13154 AESDECLAST KEY STATE3
13155 AESDECLAST KEY STATE4
13156+ pax_force_retaddr
13157 ret
13158 ENDPROC(_aesni_dec4)
13159
13160@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13161 popl KEYP
13162 popl LEN
13163 #endif
13164+ pax_force_retaddr
13165 ret
13166 ENDPROC(aesni_ecb_enc)
13167
13168@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13169 popl KEYP
13170 popl LEN
13171 #endif
13172+ pax_force_retaddr
13173 ret
13174 ENDPROC(aesni_ecb_dec)
13175
13176@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13177 popl LEN
13178 popl IVP
13179 #endif
13180+ pax_force_retaddr
13181 ret
13182 ENDPROC(aesni_cbc_enc)
13183
13184@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13185 popl LEN
13186 popl IVP
13187 #endif
13188+ pax_force_retaddr
13189 ret
13190 ENDPROC(aesni_cbc_dec)
13191
13192@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13193 mov $1, TCTR_LOW
13194 MOVQ_R64_XMM TCTR_LOW INC
13195 MOVQ_R64_XMM CTR TCTR_LOW
13196+ pax_force_retaddr
13197 ret
13198 ENDPROC(_aesni_inc_init)
13199
13200@@ -2579,6 +2598,7 @@ _aesni_inc:
13201 .Linc_low:
13202 movaps CTR, IV
13203 PSHUFB_XMM BSWAP_MASK IV
13204+ pax_force_retaddr
13205 ret
13206 ENDPROC(_aesni_inc)
13207
13208@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13209 .Lctr_enc_ret:
13210 movups IV, (IVP)
13211 .Lctr_enc_just_ret:
13212+ pax_force_retaddr
13213 ret
13214 ENDPROC(aesni_ctr_enc)
13215
13216@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13217 pxor INC, STATE4
13218 movdqu STATE4, 0x70(OUTP)
13219
13220+ pax_force_retaddr
13221 ret
13222 ENDPROC(aesni_xts_crypt8)
13223
13224diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13225index 246c670..466e2d6 100644
13226--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13227+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13228@@ -21,6 +21,7 @@
13229 */
13230
13231 #include <linux/linkage.h>
13232+#include <asm/alternative-asm.h>
13233
13234 .file "blowfish-x86_64-asm.S"
13235 .text
13236@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13237 jnz .L__enc_xor;
13238
13239 write_block();
13240+ pax_force_retaddr
13241 ret;
13242 .L__enc_xor:
13243 xor_block();
13244+ pax_force_retaddr
13245 ret;
13246 ENDPROC(__blowfish_enc_blk)
13247
13248@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13249
13250 movq %r11, %rbp;
13251
13252+ pax_force_retaddr
13253 ret;
13254 ENDPROC(blowfish_dec_blk)
13255
13256@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13257
13258 popq %rbx;
13259 popq %rbp;
13260+ pax_force_retaddr
13261 ret;
13262
13263 .L__enc_xor4:
13264@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13265
13266 popq %rbx;
13267 popq %rbp;
13268+ pax_force_retaddr
13269 ret;
13270 ENDPROC(__blowfish_enc_blk_4way)
13271
13272@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13273 popq %rbx;
13274 popq %rbp;
13275
13276+ pax_force_retaddr
13277 ret;
13278 ENDPROC(blowfish_dec_blk_4way)
13279diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13280index ce71f92..1dce7ec 100644
13281--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13282+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13283@@ -16,6 +16,7 @@
13284 */
13285
13286 #include <linux/linkage.h>
13287+#include <asm/alternative-asm.h>
13288
13289 #define CAMELLIA_TABLE_BYTE_LEN 272
13290
13291@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13292 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13293 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13294 %rcx, (%r9));
13295+ pax_force_retaddr
13296 ret;
13297 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13298
13299@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13300 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13301 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13302 %rax, (%r9));
13303+ pax_force_retaddr
13304 ret;
13305 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13306
13307@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13308 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13309 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13310
13311+ pax_force_retaddr
13312 ret;
13313
13314 .align 8
13315@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13316 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13317 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13318
13319+ pax_force_retaddr
13320 ret;
13321
13322 .align 8
13323@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13324 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13325 %xmm8, %rsi);
13326
13327+ pax_force_retaddr
13328 ret;
13329 ENDPROC(camellia_ecb_enc_16way)
13330
13331@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13332 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13333 %xmm8, %rsi);
13334
13335+ pax_force_retaddr
13336 ret;
13337 ENDPROC(camellia_ecb_dec_16way)
13338
13339@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13340 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13341 %xmm8, %rsi);
13342
13343+ pax_force_retaddr
13344 ret;
13345 ENDPROC(camellia_cbc_dec_16way)
13346
13347@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13348 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13349 %xmm8, %rsi);
13350
13351+ pax_force_retaddr
13352 ret;
13353 ENDPROC(camellia_ctr_16way)
13354
13355@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13356 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13357 %xmm8, %rsi);
13358
13359+ pax_force_retaddr
13360 ret;
13361 ENDPROC(camellia_xts_crypt_16way)
13362
13363diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13364index 0e0b886..5a3123c 100644
13365--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13366+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13367@@ -11,6 +11,7 @@
13368 */
13369
13370 #include <linux/linkage.h>
13371+#include <asm/alternative-asm.h>
13372
13373 #define CAMELLIA_TABLE_BYTE_LEN 272
13374
13375@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13376 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13377 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13378 %rcx, (%r9));
13379+ pax_force_retaddr
13380 ret;
13381 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13382
13383@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13384 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13385 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13386 %rax, (%r9));
13387+ pax_force_retaddr
13388 ret;
13389 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13390
13391@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13392 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13393 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13394
13395+ pax_force_retaddr
13396 ret;
13397
13398 .align 8
13399@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13400 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13401 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13402
13403+ pax_force_retaddr
13404 ret;
13405
13406 .align 8
13407@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13408
13409 vzeroupper;
13410
13411+ pax_force_retaddr
13412 ret;
13413 ENDPROC(camellia_ecb_enc_32way)
13414
13415@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13416
13417 vzeroupper;
13418
13419+ pax_force_retaddr
13420 ret;
13421 ENDPROC(camellia_ecb_dec_32way)
13422
13423@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13424
13425 vzeroupper;
13426
13427+ pax_force_retaddr
13428 ret;
13429 ENDPROC(camellia_cbc_dec_32way)
13430
13431@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13432
13433 vzeroupper;
13434
13435+ pax_force_retaddr
13436 ret;
13437 ENDPROC(camellia_ctr_32way)
13438
13439@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13440
13441 vzeroupper;
13442
13443+ pax_force_retaddr
13444 ret;
13445 ENDPROC(camellia_xts_crypt_32way)
13446
13447diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13448index 310319c..db3d7b5 100644
13449--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13450+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13451@@ -21,6 +21,7 @@
13452 */
13453
13454 #include <linux/linkage.h>
13455+#include <asm/alternative-asm.h>
13456
13457 .file "camellia-x86_64-asm_64.S"
13458 .text
13459@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13460 enc_outunpack(mov, RT1);
13461
13462 movq RRBP, %rbp;
13463+ pax_force_retaddr
13464 ret;
13465
13466 .L__enc_xor:
13467 enc_outunpack(xor, RT1);
13468
13469 movq RRBP, %rbp;
13470+ pax_force_retaddr
13471 ret;
13472 ENDPROC(__camellia_enc_blk)
13473
13474@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13475 dec_outunpack();
13476
13477 movq RRBP, %rbp;
13478+ pax_force_retaddr
13479 ret;
13480 ENDPROC(camellia_dec_blk)
13481
13482@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13483
13484 movq RRBP, %rbp;
13485 popq %rbx;
13486+ pax_force_retaddr
13487 ret;
13488
13489 .L__enc2_xor:
13490@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13491
13492 movq RRBP, %rbp;
13493 popq %rbx;
13494+ pax_force_retaddr
13495 ret;
13496 ENDPROC(__camellia_enc_blk_2way)
13497
13498@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13499
13500 movq RRBP, %rbp;
13501 movq RXOR, %rbx;
13502+ pax_force_retaddr
13503 ret;
13504 ENDPROC(camellia_dec_blk_2way)
13505diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13506index c35fd5d..2d8c7db 100644
13507--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13508+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13509@@ -24,6 +24,7 @@
13510 */
13511
13512 #include <linux/linkage.h>
13513+#include <asm/alternative-asm.h>
13514
13515 .file "cast5-avx-x86_64-asm_64.S"
13516
13517@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13518 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13519 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13520
13521+ pax_force_retaddr
13522 ret;
13523 ENDPROC(__cast5_enc_blk16)
13524
13525@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13526 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13527 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13528
13529+ pax_force_retaddr
13530 ret;
13531
13532 .L__skip_dec:
13533@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13534 vmovdqu RR4, (6*4*4)(%r11);
13535 vmovdqu RL4, (7*4*4)(%r11);
13536
13537+ pax_force_retaddr
13538 ret;
13539 ENDPROC(cast5_ecb_enc_16way)
13540
13541@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13542 vmovdqu RR4, (6*4*4)(%r11);
13543 vmovdqu RL4, (7*4*4)(%r11);
13544
13545+ pax_force_retaddr
13546 ret;
13547 ENDPROC(cast5_ecb_dec_16way)
13548
13549@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13550 * %rdx: src
13551 */
13552
13553- pushq %r12;
13554+ pushq %r14;
13555
13556 movq %rsi, %r11;
13557- movq %rdx, %r12;
13558+ movq %rdx, %r14;
13559
13560 vmovdqu (0*16)(%rdx), RL1;
13561 vmovdqu (1*16)(%rdx), RR1;
13562@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13563 call __cast5_dec_blk16;
13564
13565 /* xor with src */
13566- vmovq (%r12), RX;
13567+ vmovq (%r14), RX;
13568 vpshufd $0x4f, RX, RX;
13569 vpxor RX, RR1, RR1;
13570- vpxor 0*16+8(%r12), RL1, RL1;
13571- vpxor 1*16+8(%r12), RR2, RR2;
13572- vpxor 2*16+8(%r12), RL2, RL2;
13573- vpxor 3*16+8(%r12), RR3, RR3;
13574- vpxor 4*16+8(%r12), RL3, RL3;
13575- vpxor 5*16+8(%r12), RR4, RR4;
13576- vpxor 6*16+8(%r12), RL4, RL4;
13577+ vpxor 0*16+8(%r14), RL1, RL1;
13578+ vpxor 1*16+8(%r14), RR2, RR2;
13579+ vpxor 2*16+8(%r14), RL2, RL2;
13580+ vpxor 3*16+8(%r14), RR3, RR3;
13581+ vpxor 4*16+8(%r14), RL3, RL3;
13582+ vpxor 5*16+8(%r14), RR4, RR4;
13583+ vpxor 6*16+8(%r14), RL4, RL4;
13584
13585 vmovdqu RR1, (0*16)(%r11);
13586 vmovdqu RL1, (1*16)(%r11);
13587@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13588 vmovdqu RR4, (6*16)(%r11);
13589 vmovdqu RL4, (7*16)(%r11);
13590
13591- popq %r12;
13592+ popq %r14;
13593
13594+ pax_force_retaddr
13595 ret;
13596 ENDPROC(cast5_cbc_dec_16way)
13597
13598@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13599 * %rcx: iv (big endian, 64bit)
13600 */
13601
13602- pushq %r12;
13603+ pushq %r14;
13604
13605 movq %rsi, %r11;
13606- movq %rdx, %r12;
13607+ movq %rdx, %r14;
13608
13609 vpcmpeqd RTMP, RTMP, RTMP;
13610 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13611@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13612 call __cast5_enc_blk16;
13613
13614 /* dst = src ^ iv */
13615- vpxor (0*16)(%r12), RR1, RR1;
13616- vpxor (1*16)(%r12), RL1, RL1;
13617- vpxor (2*16)(%r12), RR2, RR2;
13618- vpxor (3*16)(%r12), RL2, RL2;
13619- vpxor (4*16)(%r12), RR3, RR3;
13620- vpxor (5*16)(%r12), RL3, RL3;
13621- vpxor (6*16)(%r12), RR4, RR4;
13622- vpxor (7*16)(%r12), RL4, RL4;
13623+ vpxor (0*16)(%r14), RR1, RR1;
13624+ vpxor (1*16)(%r14), RL1, RL1;
13625+ vpxor (2*16)(%r14), RR2, RR2;
13626+ vpxor (3*16)(%r14), RL2, RL2;
13627+ vpxor (4*16)(%r14), RR3, RR3;
13628+ vpxor (5*16)(%r14), RL3, RL3;
13629+ vpxor (6*16)(%r14), RR4, RR4;
13630+ vpxor (7*16)(%r14), RL4, RL4;
13631 vmovdqu RR1, (0*16)(%r11);
13632 vmovdqu RL1, (1*16)(%r11);
13633 vmovdqu RR2, (2*16)(%r11);
13634@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13635 vmovdqu RR4, (6*16)(%r11);
13636 vmovdqu RL4, (7*16)(%r11);
13637
13638- popq %r12;
13639+ popq %r14;
13640
13641+ pax_force_retaddr
13642 ret;
13643 ENDPROC(cast5_ctr_16way)
13644diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13645index e3531f8..e123f35 100644
13646--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13647+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13648@@ -24,6 +24,7 @@
13649 */
13650
13651 #include <linux/linkage.h>
13652+#include <asm/alternative-asm.h>
13653 #include "glue_helper-asm-avx.S"
13654
13655 .file "cast6-avx-x86_64-asm_64.S"
13656@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13657 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13658 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13659
13660+ pax_force_retaddr
13661 ret;
13662 ENDPROC(__cast6_enc_blk8)
13663
13664@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13665 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13666 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13667
13668+ pax_force_retaddr
13669 ret;
13670 ENDPROC(__cast6_dec_blk8)
13671
13672@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13673
13674 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13675
13676+ pax_force_retaddr
13677 ret;
13678 ENDPROC(cast6_ecb_enc_8way)
13679
13680@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13681
13682 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13683
13684+ pax_force_retaddr
13685 ret;
13686 ENDPROC(cast6_ecb_dec_8way)
13687
13688@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13689 * %rdx: src
13690 */
13691
13692- pushq %r12;
13693+ pushq %r14;
13694
13695 movq %rsi, %r11;
13696- movq %rdx, %r12;
13697+ movq %rdx, %r14;
13698
13699 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13700
13701 call __cast6_dec_blk8;
13702
13703- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13704+ store_cbc_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_cbc_dec_8way)
13712
13713@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13714 * %rcx: iv (little endian, 128bit)
13715 */
13716
13717- pushq %r12;
13718+ pushq %r14;
13719
13720 movq %rsi, %r11;
13721- movq %rdx, %r12;
13722+ movq %rdx, %r14;
13723
13724 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13725 RD2, RX, RKR, RKM);
13726
13727 call __cast6_enc_blk8;
13728
13729- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13730+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13731
13732- popq %r12;
13733+ popq %r14;
13734
13735+ pax_force_retaddr
13736 ret;
13737 ENDPROC(cast6_ctr_8way)
13738
13739@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13740 /* dst <= regs xor IVs(in dst) */
13741 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13742
13743+ pax_force_retaddr
13744 ret;
13745 ENDPROC(cast6_xts_enc_8way)
13746
13747@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13748 /* dst <= regs xor IVs(in dst) */
13749 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13750
13751+ pax_force_retaddr
13752 ret;
13753 ENDPROC(cast6_xts_dec_8way)
13754diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13755index dbc4339..de6e120 100644
13756--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13757+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13758@@ -45,6 +45,7 @@
13759
13760 #include <asm/inst.h>
13761 #include <linux/linkage.h>
13762+#include <asm/alternative-asm.h>
13763
13764 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13765
13766@@ -312,6 +313,7 @@ do_return:
13767 popq %rsi
13768 popq %rdi
13769 popq %rbx
13770+ pax_force_retaddr
13771 ret
13772
13773 ################################################################
13774diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13775index 185fad4..ff4cd36 100644
13776--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13777+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13778@@ -18,6 +18,7 @@
13779
13780 #include <linux/linkage.h>
13781 #include <asm/inst.h>
13782+#include <asm/alternative-asm.h>
13783
13784 .data
13785
13786@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13787 psrlq $1, T2
13788 pxor T2, T1
13789 pxor T1, DATA
13790+ pax_force_retaddr
13791 ret
13792 ENDPROC(__clmul_gf128mul_ble)
13793
13794@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13795 call __clmul_gf128mul_ble
13796 PSHUFB_XMM BSWAP DATA
13797 movups DATA, (%rdi)
13798+ pax_force_retaddr
13799 ret
13800 ENDPROC(clmul_ghash_mul)
13801
13802@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13803 PSHUFB_XMM BSWAP DATA
13804 movups DATA, (%rdi)
13805 .Lupdate_just_ret:
13806+ pax_force_retaddr
13807 ret
13808 ENDPROC(clmul_ghash_update)
13809diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13810index 9279e0b..c4b3d2c 100644
13811--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13812+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13813@@ -1,4 +1,5 @@
13814 #include <linux/linkage.h>
13815+#include <asm/alternative-asm.h>
13816
13817 # enter salsa20_encrypt_bytes
13818 ENTRY(salsa20_encrypt_bytes)
13819@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13820 add %r11,%rsp
13821 mov %rdi,%rax
13822 mov %rsi,%rdx
13823+ pax_force_retaddr
13824 ret
13825 # bytesatleast65:
13826 ._bytesatleast65:
13827@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13828 add %r11,%rsp
13829 mov %rdi,%rax
13830 mov %rsi,%rdx
13831+ pax_force_retaddr
13832 ret
13833 ENDPROC(salsa20_keysetup)
13834
13835@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13836 add %r11,%rsp
13837 mov %rdi,%rax
13838 mov %rsi,%rdx
13839+ pax_force_retaddr
13840 ret
13841 ENDPROC(salsa20_ivsetup)
13842diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13843index 2f202f4..d9164d6 100644
13844--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13845+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13846@@ -24,6 +24,7 @@
13847 */
13848
13849 #include <linux/linkage.h>
13850+#include <asm/alternative-asm.h>
13851 #include "glue_helper-asm-avx.S"
13852
13853 .file "serpent-avx-x86_64-asm_64.S"
13854@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13855 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13856 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13857
13858+ pax_force_retaddr
13859 ret;
13860 ENDPROC(__serpent_enc_blk8_avx)
13861
13862@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13863 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13864 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13865
13866+ pax_force_retaddr
13867 ret;
13868 ENDPROC(__serpent_dec_blk8_avx)
13869
13870@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13871
13872 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13873
13874+ pax_force_retaddr
13875 ret;
13876 ENDPROC(serpent_ecb_enc_8way_avx)
13877
13878@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13879
13880 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13881
13882+ pax_force_retaddr
13883 ret;
13884 ENDPROC(serpent_ecb_dec_8way_avx)
13885
13886@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13887
13888 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13889
13890+ pax_force_retaddr
13891 ret;
13892 ENDPROC(serpent_cbc_dec_8way_avx)
13893
13894@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13895
13896 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13897
13898+ pax_force_retaddr
13899 ret;
13900 ENDPROC(serpent_ctr_8way_avx)
13901
13902@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13903 /* dst <= regs xor IVs(in dst) */
13904 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13905
13906+ pax_force_retaddr
13907 ret;
13908 ENDPROC(serpent_xts_enc_8way_avx)
13909
13910@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13911 /* dst <= regs xor IVs(in dst) */
13912 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13913
13914+ pax_force_retaddr
13915 ret;
13916 ENDPROC(serpent_xts_dec_8way_avx)
13917diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13918index b222085..abd483c 100644
13919--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13920+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13921@@ -15,6 +15,7 @@
13922 */
13923
13924 #include <linux/linkage.h>
13925+#include <asm/alternative-asm.h>
13926 #include "glue_helper-asm-avx2.S"
13927
13928 .file "serpent-avx2-asm_64.S"
13929@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13930 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13931 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13932
13933+ pax_force_retaddr
13934 ret;
13935 ENDPROC(__serpent_enc_blk16)
13936
13937@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13938 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13939 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13940
13941+ pax_force_retaddr
13942 ret;
13943 ENDPROC(__serpent_dec_blk16)
13944
13945@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13946
13947 vzeroupper;
13948
13949+ pax_force_retaddr
13950 ret;
13951 ENDPROC(serpent_ecb_enc_16way)
13952
13953@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13954
13955 vzeroupper;
13956
13957+ pax_force_retaddr
13958 ret;
13959 ENDPROC(serpent_ecb_dec_16way)
13960
13961@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13962
13963 vzeroupper;
13964
13965+ pax_force_retaddr
13966 ret;
13967 ENDPROC(serpent_cbc_dec_16way)
13968
13969@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13970
13971 vzeroupper;
13972
13973+ pax_force_retaddr
13974 ret;
13975 ENDPROC(serpent_ctr_16way)
13976
13977@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13978
13979 vzeroupper;
13980
13981+ pax_force_retaddr
13982 ret;
13983 ENDPROC(serpent_xts_enc_16way)
13984
13985@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13986
13987 vzeroupper;
13988
13989+ pax_force_retaddr
13990 ret;
13991 ENDPROC(serpent_xts_dec_16way)
13992diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13993index acc066c..1559cc4 100644
13994--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13995+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13996@@ -25,6 +25,7 @@
13997 */
13998
13999 #include <linux/linkage.h>
14000+#include <asm/alternative-asm.h>
14001
14002 .file "serpent-sse2-x86_64-asm_64.S"
14003 .text
14004@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14005 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14006 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14007
14008+ pax_force_retaddr
14009 ret;
14010
14011 .L__enc_xor8:
14012 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14013 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14014
14015+ pax_force_retaddr
14016 ret;
14017 ENDPROC(__serpent_enc_blk_8way)
14018
14019@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14020 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14021 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14022
14023+ pax_force_retaddr
14024 ret;
14025 ENDPROC(serpent_dec_blk_8way)
14026diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14027index a410950..9dfe7ad 100644
14028--- a/arch/x86/crypto/sha1_ssse3_asm.S
14029+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14030@@ -29,6 +29,7 @@
14031 */
14032
14033 #include <linux/linkage.h>
14034+#include <asm/alternative-asm.h>
14035
14036 #define CTX %rdi // arg1
14037 #define BUF %rsi // arg2
14038@@ -75,9 +76,9 @@
14039
14040 push %rbx
14041 push %rbp
14042- push %r12
14043+ push %r14
14044
14045- mov %rsp, %r12
14046+ mov %rsp, %r14
14047 sub $64, %rsp # allocate workspace
14048 and $~15, %rsp # align stack
14049
14050@@ -99,11 +100,12 @@
14051 xor %rax, %rax
14052 rep stosq
14053
14054- mov %r12, %rsp # deallocate workspace
14055+ mov %r14, %rsp # deallocate workspace
14056
14057- pop %r12
14058+ pop %r14
14059 pop %rbp
14060 pop %rbx
14061+ pax_force_retaddr
14062 ret
14063
14064 ENDPROC(\name)
14065diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14066index 642f156..51a513c 100644
14067--- a/arch/x86/crypto/sha256-avx-asm.S
14068+++ b/arch/x86/crypto/sha256-avx-asm.S
14069@@ -49,6 +49,7 @@
14070
14071 #ifdef CONFIG_AS_AVX
14072 #include <linux/linkage.h>
14073+#include <asm/alternative-asm.h>
14074
14075 ## assume buffers not aligned
14076 #define VMOVDQ vmovdqu
14077@@ -460,6 +461,7 @@ done_hash:
14078 popq %r13
14079 popq %rbp
14080 popq %rbx
14081+ pax_force_retaddr
14082 ret
14083 ENDPROC(sha256_transform_avx)
14084
14085diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14086index 9e86944..3795e6a 100644
14087--- a/arch/x86/crypto/sha256-avx2-asm.S
14088+++ b/arch/x86/crypto/sha256-avx2-asm.S
14089@@ -50,6 +50,7 @@
14090
14091 #ifdef CONFIG_AS_AVX2
14092 #include <linux/linkage.h>
14093+#include <asm/alternative-asm.h>
14094
14095 ## assume buffers not aligned
14096 #define VMOVDQ vmovdqu
14097@@ -720,6 +721,7 @@ done_hash:
14098 popq %r12
14099 popq %rbp
14100 popq %rbx
14101+ pax_force_retaddr
14102 ret
14103 ENDPROC(sha256_transform_rorx)
14104
14105diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14106index f833b74..8c62a9e 100644
14107--- a/arch/x86/crypto/sha256-ssse3-asm.S
14108+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14109@@ -47,6 +47,7 @@
14110 ########################################################################
14111
14112 #include <linux/linkage.h>
14113+#include <asm/alternative-asm.h>
14114
14115 ## assume buffers not aligned
14116 #define MOVDQ movdqu
14117@@ -471,6 +472,7 @@ done_hash:
14118 popq %rbp
14119 popq %rbx
14120
14121+ pax_force_retaddr
14122 ret
14123 ENDPROC(sha256_transform_ssse3)
14124
14125diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14126index 974dde9..a823ff9 100644
14127--- a/arch/x86/crypto/sha512-avx-asm.S
14128+++ b/arch/x86/crypto/sha512-avx-asm.S
14129@@ -49,6 +49,7 @@
14130
14131 #ifdef CONFIG_AS_AVX
14132 #include <linux/linkage.h>
14133+#include <asm/alternative-asm.h>
14134
14135 .text
14136
14137@@ -364,6 +365,7 @@ updateblock:
14138 mov frame_RSPSAVE(%rsp), %rsp
14139
14140 nowork:
14141+ pax_force_retaddr
14142 ret
14143 ENDPROC(sha512_transform_avx)
14144
14145diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14146index 568b961..ed20c37 100644
14147--- a/arch/x86/crypto/sha512-avx2-asm.S
14148+++ b/arch/x86/crypto/sha512-avx2-asm.S
14149@@ -51,6 +51,7 @@
14150
14151 #ifdef CONFIG_AS_AVX2
14152 #include <linux/linkage.h>
14153+#include <asm/alternative-asm.h>
14154
14155 .text
14156
14157@@ -678,6 +679,7 @@ done_hash:
14158
14159 # Restore Stack Pointer
14160 mov frame_RSPSAVE(%rsp), %rsp
14161+ pax_force_retaddr
14162 ret
14163 ENDPROC(sha512_transform_rorx)
14164
14165diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14166index fb56855..6edd768 100644
14167--- a/arch/x86/crypto/sha512-ssse3-asm.S
14168+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14169@@ -48,6 +48,7 @@
14170 ########################################################################
14171
14172 #include <linux/linkage.h>
14173+#include <asm/alternative-asm.h>
14174
14175 .text
14176
14177@@ -363,6 +364,7 @@ updateblock:
14178 mov frame_RSPSAVE(%rsp), %rsp
14179
14180 nowork:
14181+ pax_force_retaddr
14182 ret
14183 ENDPROC(sha512_transform_ssse3)
14184
14185diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14186index 0505813..b067311 100644
14187--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14188+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14189@@ -24,6 +24,7 @@
14190 */
14191
14192 #include <linux/linkage.h>
14193+#include <asm/alternative-asm.h>
14194 #include "glue_helper-asm-avx.S"
14195
14196 .file "twofish-avx-x86_64-asm_64.S"
14197@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14198 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14199 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14200
14201+ pax_force_retaddr
14202 ret;
14203 ENDPROC(__twofish_enc_blk8)
14204
14205@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14206 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14207 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14208
14209+ pax_force_retaddr
14210 ret;
14211 ENDPROC(__twofish_dec_blk8)
14212
14213@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14214
14215 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14216
14217+ pax_force_retaddr
14218 ret;
14219 ENDPROC(twofish_ecb_enc_8way)
14220
14221@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14222
14223 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14224
14225+ pax_force_retaddr
14226 ret;
14227 ENDPROC(twofish_ecb_dec_8way)
14228
14229@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14230 * %rdx: src
14231 */
14232
14233- pushq %r12;
14234+ pushq %r14;
14235
14236 movq %rsi, %r11;
14237- movq %rdx, %r12;
14238+ movq %rdx, %r14;
14239
14240 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14241
14242 call __twofish_dec_blk8;
14243
14244- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14245+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14246
14247- popq %r12;
14248+ popq %r14;
14249
14250+ pax_force_retaddr
14251 ret;
14252 ENDPROC(twofish_cbc_dec_8way)
14253
14254@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14255 * %rcx: iv (little endian, 128bit)
14256 */
14257
14258- pushq %r12;
14259+ pushq %r14;
14260
14261 movq %rsi, %r11;
14262- movq %rdx, %r12;
14263+ movq %rdx, %r14;
14264
14265 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14266 RD2, RX0, RX1, RY0);
14267
14268 call __twofish_enc_blk8;
14269
14270- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14271+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14272
14273- popq %r12;
14274+ popq %r14;
14275
14276+ pax_force_retaddr
14277 ret;
14278 ENDPROC(twofish_ctr_8way)
14279
14280@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14281 /* dst <= regs xor IVs(in dst) */
14282 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14283
14284+ pax_force_retaddr
14285 ret;
14286 ENDPROC(twofish_xts_enc_8way)
14287
14288@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14289 /* dst <= regs xor IVs(in dst) */
14290 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14291
14292+ pax_force_retaddr
14293 ret;
14294 ENDPROC(twofish_xts_dec_8way)
14295diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14296index 1c3b7ce..02f578d 100644
14297--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14298+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14299@@ -21,6 +21,7 @@
14300 */
14301
14302 #include <linux/linkage.h>
14303+#include <asm/alternative-asm.h>
14304
14305 .file "twofish-x86_64-asm-3way.S"
14306 .text
14307@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14308 popq %r13;
14309 popq %r14;
14310 popq %r15;
14311+ pax_force_retaddr
14312 ret;
14313
14314 .L__enc_xor3:
14315@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14316 popq %r13;
14317 popq %r14;
14318 popq %r15;
14319+ pax_force_retaddr
14320 ret;
14321 ENDPROC(__twofish_enc_blk_3way)
14322
14323@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14324 popq %r13;
14325 popq %r14;
14326 popq %r15;
14327+ pax_force_retaddr
14328 ret;
14329 ENDPROC(twofish_dec_blk_3way)
14330diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14331index a039d21..524b8b2 100644
14332--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14333+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14334@@ -22,6 +22,7 @@
14335
14336 #include <linux/linkage.h>
14337 #include <asm/asm-offsets.h>
14338+#include <asm/alternative-asm.h>
14339
14340 #define a_offset 0
14341 #define b_offset 4
14342@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14343
14344 popq R1
14345 movq $1,%rax
14346+ pax_force_retaddr
14347 ret
14348 ENDPROC(twofish_enc_blk)
14349
14350@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14351
14352 popq R1
14353 movq $1,%rax
14354+ pax_force_retaddr
14355 ret
14356 ENDPROC(twofish_dec_blk)
14357diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14358index d21ff89..6da8e6e 100644
14359--- a/arch/x86/ia32/ia32_aout.c
14360+++ b/arch/x86/ia32/ia32_aout.c
14361@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14362 unsigned long dump_start, dump_size;
14363 struct user32 dump;
14364
14365+ memset(&dump, 0, sizeof(dump));
14366+
14367 fs = get_fs();
14368 set_fs(KERNEL_DS);
14369 has_dumped = 1;
14370diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14371index 2206757..85cbcfa 100644
14372--- a/arch/x86/ia32/ia32_signal.c
14373+++ b/arch/x86/ia32/ia32_signal.c
14374@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14375 if (__get_user(set.sig[0], &frame->sc.oldmask)
14376 || (_COMPAT_NSIG_WORDS > 1
14377 && __copy_from_user((((char *) &set.sig) + 4),
14378- &frame->extramask,
14379+ frame->extramask,
14380 sizeof(frame->extramask))))
14381 goto badframe;
14382
14383@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14384 sp -= frame_size;
14385 /* Align the stack pointer according to the i386 ABI,
14386 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14387- sp = ((sp + 4) & -16ul) - 4;
14388+ sp = ((sp - 12) & -16ul) - 4;
14389 return (void __user *) sp;
14390 }
14391
14392@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14393 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14394 sigreturn);
14395 else
14396- restorer = &frame->retcode;
14397+ restorer = frame->retcode;
14398 }
14399
14400 put_user_try {
14401@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14402 * These are actually not used anymore, but left because some
14403 * gdb versions depend on them as a marker.
14404 */
14405- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14406+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14407 } put_user_catch(err);
14408
14409 if (err)
14410@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14411 0xb8,
14412 __NR_ia32_rt_sigreturn,
14413 0x80cd,
14414- 0,
14415+ 0
14416 };
14417
14418 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14419@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14420
14421 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14422 restorer = ksig->ka.sa.sa_restorer;
14423+ else if (current->mm->context.vdso)
14424+ /* Return stub is in 32bit vsyscall page */
14425+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14426 else
14427- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14428- rt_sigreturn);
14429+ restorer = frame->retcode;
14430 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14431
14432 /*
14433 * Not actually used anymore, but left because some gdb
14434 * versions need it.
14435 */
14436- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14437+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14438 } put_user_catch(err);
14439
14440 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14441diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14442index 4299eb0..fefe70e 100644
14443--- a/arch/x86/ia32/ia32entry.S
14444+++ b/arch/x86/ia32/ia32entry.S
14445@@ -15,8 +15,10 @@
14446 #include <asm/irqflags.h>
14447 #include <asm/asm.h>
14448 #include <asm/smap.h>
14449+#include <asm/pgtable.h>
14450 #include <linux/linkage.h>
14451 #include <linux/err.h>
14452+#include <asm/alternative-asm.h>
14453
14454 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14455 #include <linux/elf-em.h>
14456@@ -62,12 +64,12 @@
14457 */
14458 .macro LOAD_ARGS32 offset, _r9=0
14459 .if \_r9
14460- movl \offset+16(%rsp),%r9d
14461+ movl \offset+R9(%rsp),%r9d
14462 .endif
14463- movl \offset+40(%rsp),%ecx
14464- movl \offset+48(%rsp),%edx
14465- movl \offset+56(%rsp),%esi
14466- movl \offset+64(%rsp),%edi
14467+ movl \offset+RCX(%rsp),%ecx
14468+ movl \offset+RDX(%rsp),%edx
14469+ movl \offset+RSI(%rsp),%esi
14470+ movl \offset+RDI(%rsp),%edi
14471 movl %eax,%eax /* zero extension */
14472 .endm
14473
14474@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14475 ENDPROC(native_irq_enable_sysexit)
14476 #endif
14477
14478+ .macro pax_enter_kernel_user
14479+ pax_set_fptr_mask
14480+#ifdef CONFIG_PAX_MEMORY_UDEREF
14481+ call pax_enter_kernel_user
14482+#endif
14483+ .endm
14484+
14485+ .macro pax_exit_kernel_user
14486+#ifdef CONFIG_PAX_MEMORY_UDEREF
14487+ call pax_exit_kernel_user
14488+#endif
14489+#ifdef CONFIG_PAX_RANDKSTACK
14490+ pushq %rax
14491+ pushq %r11
14492+ call pax_randomize_kstack
14493+ popq %r11
14494+ popq %rax
14495+#endif
14496+ .endm
14497+
14498+ .macro pax_erase_kstack
14499+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14500+ call pax_erase_kstack
14501+#endif
14502+ .endm
14503+
14504 /*
14505 * 32bit SYSENTER instruction entry.
14506 *
14507@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14508 CFI_REGISTER rsp,rbp
14509 SWAPGS_UNSAFE_STACK
14510 movq PER_CPU_VAR(kernel_stack), %rsp
14511- addq $(KERNEL_STACK_OFFSET),%rsp
14512- /*
14513- * No need to follow this irqs on/off section: the syscall
14514- * disabled irqs, here we enable it straight after entry:
14515- */
14516- ENABLE_INTERRUPTS(CLBR_NONE)
14517 movl %ebp,%ebp /* zero extension */
14518 pushq_cfi $__USER32_DS
14519 /*CFI_REL_OFFSET ss,0*/
14520@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14521 CFI_REL_OFFSET rsp,0
14522 pushfq_cfi
14523 /*CFI_REL_OFFSET rflags,0*/
14524- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14525- CFI_REGISTER rip,r10
14526+ orl $X86_EFLAGS_IF,(%rsp)
14527+ GET_THREAD_INFO(%r11)
14528+ movl TI_sysenter_return(%r11), %r11d
14529+ CFI_REGISTER rip,r11
14530 pushq_cfi $__USER32_CS
14531 /*CFI_REL_OFFSET cs,0*/
14532 movl %eax, %eax
14533- pushq_cfi %r10
14534+ pushq_cfi %r11
14535 CFI_REL_OFFSET rip,0
14536 pushq_cfi %rax
14537 cld
14538 SAVE_ARGS 0,1,0
14539+ pax_enter_kernel_user
14540+
14541+#ifdef CONFIG_PAX_RANDKSTACK
14542+ pax_erase_kstack
14543+#endif
14544+
14545+ /*
14546+ * No need to follow this irqs on/off section: the syscall
14547+ * disabled irqs, here we enable it straight after entry:
14548+ */
14549+ ENABLE_INTERRUPTS(CLBR_NONE)
14550 /* no need to do an access_ok check here because rbp has been
14551 32bit zero extended */
14552+
14553+#ifdef CONFIG_PAX_MEMORY_UDEREF
14554+ addq pax_user_shadow_base,%rbp
14555+ ASM_PAX_OPEN_USERLAND
14556+#endif
14557+
14558 ASM_STAC
14559 1: movl (%rbp),%ebp
14560 _ASM_EXTABLE(1b,ia32_badarg)
14561 ASM_CLAC
14562- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14563- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14564+
14565+#ifdef CONFIG_PAX_MEMORY_UDEREF
14566+ ASM_PAX_CLOSE_USERLAND
14567+#endif
14568+
14569+ GET_THREAD_INFO(%r11)
14570+ orl $TS_COMPAT,TI_status(%r11)
14571+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14572 CFI_REMEMBER_STATE
14573 jnz sysenter_tracesys
14574 cmpq $(IA32_NR_syscalls-1),%rax
14575@@ -162,15 +209,18 @@ sysenter_do_call:
14576 sysenter_dispatch:
14577 call *ia32_sys_call_table(,%rax,8)
14578 movq %rax,RAX-ARGOFFSET(%rsp)
14579+ GET_THREAD_INFO(%r11)
14580 DISABLE_INTERRUPTS(CLBR_NONE)
14581 TRACE_IRQS_OFF
14582- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14583+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14584 jnz sysexit_audit
14585 sysexit_from_sys_call:
14586- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14587+ pax_exit_kernel_user
14588+ pax_erase_kstack
14589+ andl $~TS_COMPAT,TI_status(%r11)
14590 /* clear IF, that popfq doesn't enable interrupts early */
14591- andl $~0x200,EFLAGS-R11(%rsp)
14592- movl RIP-R11(%rsp),%edx /* User %eip */
14593+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14594+ movl RIP(%rsp),%edx /* User %eip */
14595 CFI_REGISTER rip,rdx
14596 RESTORE_ARGS 0,24,0,0,0,0
14597 xorq %r8,%r8
14598@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14599 movl %eax,%esi /* 2nd arg: syscall number */
14600 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14601 call __audit_syscall_entry
14602+
14603+ pax_erase_kstack
14604+
14605 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14606 cmpq $(IA32_NR_syscalls-1),%rax
14607 ja ia32_badsys
14608@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14609 .endm
14610
14611 .macro auditsys_exit exit
14612- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14613+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14614 jnz ia32_ret_from_sys_call
14615 TRACE_IRQS_ON
14616 ENABLE_INTERRUPTS(CLBR_NONE)
14617@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14618 1: setbe %al /* 1 if error, 0 if not */
14619 movzbl %al,%edi /* zero-extend that into %edi */
14620 call __audit_syscall_exit
14621+ GET_THREAD_INFO(%r11)
14622 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14623 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14624 DISABLE_INTERRUPTS(CLBR_NONE)
14625 TRACE_IRQS_OFF
14626- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14627+ testl %edi,TI_flags(%r11)
14628 jz \exit
14629 CLEAR_RREGS -ARGOFFSET
14630 jmp int_with_check
14631@@ -237,7 +291,7 @@ sysexit_audit:
14632
14633 sysenter_tracesys:
14634 #ifdef CONFIG_AUDITSYSCALL
14635- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14636+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14637 jz sysenter_auditsys
14638 #endif
14639 SAVE_REST
14640@@ -249,6 +303,9 @@ sysenter_tracesys:
14641 RESTORE_REST
14642 cmpq $(IA32_NR_syscalls-1),%rax
14643 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14644+
14645+ pax_erase_kstack
14646+
14647 jmp sysenter_do_call
14648 CFI_ENDPROC
14649 ENDPROC(ia32_sysenter_target)
14650@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14651 ENTRY(ia32_cstar_target)
14652 CFI_STARTPROC32 simple
14653 CFI_SIGNAL_FRAME
14654- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14655+ CFI_DEF_CFA rsp,0
14656 CFI_REGISTER rip,rcx
14657 /*CFI_REGISTER rflags,r11*/
14658 SWAPGS_UNSAFE_STACK
14659 movl %esp,%r8d
14660 CFI_REGISTER rsp,r8
14661 movq PER_CPU_VAR(kernel_stack),%rsp
14662+ SAVE_ARGS 8*6,0,0
14663+ pax_enter_kernel_user
14664+
14665+#ifdef CONFIG_PAX_RANDKSTACK
14666+ pax_erase_kstack
14667+#endif
14668+
14669 /*
14670 * No need to follow this irqs on/off section: the syscall
14671 * disabled irqs and here we enable it straight after entry:
14672 */
14673 ENABLE_INTERRUPTS(CLBR_NONE)
14674- SAVE_ARGS 8,0,0
14675 movl %eax,%eax /* zero extension */
14676 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14677 movq %rcx,RIP-ARGOFFSET(%rsp)
14678@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14679 /* no need to do an access_ok check here because r8 has been
14680 32bit zero extended */
14681 /* hardware stack frame is complete now */
14682+
14683+#ifdef CONFIG_PAX_MEMORY_UDEREF
14684+ ASM_PAX_OPEN_USERLAND
14685+ movq pax_user_shadow_base,%r8
14686+ addq RSP-ARGOFFSET(%rsp),%r8
14687+#endif
14688+
14689 ASM_STAC
14690 1: movl (%r8),%r9d
14691 _ASM_EXTABLE(1b,ia32_badarg)
14692 ASM_CLAC
14693- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14694- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14695+
14696+#ifdef CONFIG_PAX_MEMORY_UDEREF
14697+ ASM_PAX_CLOSE_USERLAND
14698+#endif
14699+
14700+ GET_THREAD_INFO(%r11)
14701+ orl $TS_COMPAT,TI_status(%r11)
14702+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14703 CFI_REMEMBER_STATE
14704 jnz cstar_tracesys
14705 cmpq $IA32_NR_syscalls-1,%rax
14706@@ -319,13 +395,16 @@ cstar_do_call:
14707 cstar_dispatch:
14708 call *ia32_sys_call_table(,%rax,8)
14709 movq %rax,RAX-ARGOFFSET(%rsp)
14710+ GET_THREAD_INFO(%r11)
14711 DISABLE_INTERRUPTS(CLBR_NONE)
14712 TRACE_IRQS_OFF
14713- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14714+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14715 jnz sysretl_audit
14716 sysretl_from_sys_call:
14717- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14718- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14719+ pax_exit_kernel_user
14720+ pax_erase_kstack
14721+ andl $~TS_COMPAT,TI_status(%r11)
14722+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14723 movl RIP-ARGOFFSET(%rsp),%ecx
14724 CFI_REGISTER rip,rcx
14725 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14726@@ -352,7 +431,7 @@ sysretl_audit:
14727
14728 cstar_tracesys:
14729 #ifdef CONFIG_AUDITSYSCALL
14730- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14731+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14732 jz cstar_auditsys
14733 #endif
14734 xchgl %r9d,%ebp
14735@@ -366,11 +445,19 @@ cstar_tracesys:
14736 xchgl %ebp,%r9d
14737 cmpq $(IA32_NR_syscalls-1),%rax
14738 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14739+
14740+ pax_erase_kstack
14741+
14742 jmp cstar_do_call
14743 END(ia32_cstar_target)
14744
14745 ia32_badarg:
14746 ASM_CLAC
14747+
14748+#ifdef CONFIG_PAX_MEMORY_UDEREF
14749+ ASM_PAX_CLOSE_USERLAND
14750+#endif
14751+
14752 movq $-EFAULT,%rax
14753 jmp ia32_sysret
14754 CFI_ENDPROC
14755@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14756 CFI_REL_OFFSET rip,RIP-RIP
14757 PARAVIRT_ADJUST_EXCEPTION_FRAME
14758 SWAPGS
14759- /*
14760- * No need to follow this irqs on/off section: the syscall
14761- * disabled irqs and here we enable it straight after entry:
14762- */
14763- ENABLE_INTERRUPTS(CLBR_NONE)
14764 movl %eax,%eax
14765 pushq_cfi %rax
14766 cld
14767 /* note the registers are not zero extended to the sf.
14768 this could be a problem. */
14769 SAVE_ARGS 0,1,0
14770- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14771- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14772+ pax_enter_kernel_user
14773+
14774+#ifdef CONFIG_PAX_RANDKSTACK
14775+ pax_erase_kstack
14776+#endif
14777+
14778+ /*
14779+ * No need to follow this irqs on/off section: the syscall
14780+ * disabled irqs and here we enable it straight after entry:
14781+ */
14782+ ENABLE_INTERRUPTS(CLBR_NONE)
14783+ GET_THREAD_INFO(%r11)
14784+ orl $TS_COMPAT,TI_status(%r11)
14785+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14786 jnz ia32_tracesys
14787 cmpq $(IA32_NR_syscalls-1),%rax
14788 ja ia32_badsys
14789@@ -442,6 +536,9 @@ ia32_tracesys:
14790 RESTORE_REST
14791 cmpq $(IA32_NR_syscalls-1),%rax
14792 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14793+
14794+ pax_erase_kstack
14795+
14796 jmp ia32_do_call
14797 END(ia32_syscall)
14798
14799diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14800index 8e0ceec..af13504 100644
14801--- a/arch/x86/ia32/sys_ia32.c
14802+++ b/arch/x86/ia32/sys_ia32.c
14803@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14804 */
14805 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14806 {
14807- typeof(ubuf->st_uid) uid = 0;
14808- typeof(ubuf->st_gid) gid = 0;
14809+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14810+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14811 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14812 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14813 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14814diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14815index 372231c..51b537d 100644
14816--- a/arch/x86/include/asm/alternative-asm.h
14817+++ b/arch/x86/include/asm/alternative-asm.h
14818@@ -18,6 +18,45 @@
14819 .endm
14820 #endif
14821
14822+#ifdef KERNEXEC_PLUGIN
14823+ .macro pax_force_retaddr_bts rip=0
14824+ btsq $63,\rip(%rsp)
14825+ .endm
14826+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14827+ .macro pax_force_retaddr rip=0, reload=0
14828+ btsq $63,\rip(%rsp)
14829+ .endm
14830+ .macro pax_force_fptr ptr
14831+ btsq $63,\ptr
14832+ .endm
14833+ .macro pax_set_fptr_mask
14834+ .endm
14835+#endif
14836+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14837+ .macro pax_force_retaddr rip=0, reload=0
14838+ .if \reload
14839+ pax_set_fptr_mask
14840+ .endif
14841+ orq %r12,\rip(%rsp)
14842+ .endm
14843+ .macro pax_force_fptr ptr
14844+ orq %r12,\ptr
14845+ .endm
14846+ .macro pax_set_fptr_mask
14847+ movabs $0x8000000000000000,%r12
14848+ .endm
14849+#endif
14850+#else
14851+ .macro pax_force_retaddr rip=0, reload=0
14852+ .endm
14853+ .macro pax_force_fptr ptr
14854+ .endm
14855+ .macro pax_force_retaddr_bts rip=0
14856+ .endm
14857+ .macro pax_set_fptr_mask
14858+ .endm
14859+#endif
14860+
14861 .macro altinstruction_entry orig alt feature orig_len alt_len
14862 .long \orig - .
14863 .long \alt - .
14864diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14865index 0a3f9c9..c9d081d 100644
14866--- a/arch/x86/include/asm/alternative.h
14867+++ b/arch/x86/include/asm/alternative.h
14868@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14869 ".pushsection .discard,\"aw\",@progbits\n" \
14870 DISCARD_ENTRY(1) \
14871 ".popsection\n" \
14872- ".pushsection .altinstr_replacement, \"ax\"\n" \
14873+ ".pushsection .altinstr_replacement, \"a\"\n" \
14874 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14875 ".popsection"
14876
14877@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14878 DISCARD_ENTRY(1) \
14879 DISCARD_ENTRY(2) \
14880 ".popsection\n" \
14881- ".pushsection .altinstr_replacement, \"ax\"\n" \
14882+ ".pushsection .altinstr_replacement, \"a\"\n" \
14883 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14884 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14885 ".popsection"
14886diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14887index 19b0eba..12254cd 100644
14888--- a/arch/x86/include/asm/apic.h
14889+++ b/arch/x86/include/asm/apic.h
14890@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14891
14892 #ifdef CONFIG_X86_LOCAL_APIC
14893
14894-extern unsigned int apic_verbosity;
14895+extern int apic_verbosity;
14896 extern int local_apic_timer_c2_ok;
14897
14898 extern int disable_apic;
14899diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14900index 20370c6..a2eb9b0 100644
14901--- a/arch/x86/include/asm/apm.h
14902+++ b/arch/x86/include/asm/apm.h
14903@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14904 __asm__ __volatile__(APM_DO_ZERO_SEGS
14905 "pushl %%edi\n\t"
14906 "pushl %%ebp\n\t"
14907- "lcall *%%cs:apm_bios_entry\n\t"
14908+ "lcall *%%ss:apm_bios_entry\n\t"
14909 "setc %%al\n\t"
14910 "popl %%ebp\n\t"
14911 "popl %%edi\n\t"
14912@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14913 __asm__ __volatile__(APM_DO_ZERO_SEGS
14914 "pushl %%edi\n\t"
14915 "pushl %%ebp\n\t"
14916- "lcall *%%cs:apm_bios_entry\n\t"
14917+ "lcall *%%ss:apm_bios_entry\n\t"
14918 "setc %%bl\n\t"
14919 "popl %%ebp\n\t"
14920 "popl %%edi\n\t"
14921diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14922index b17f4f4..9620151 100644
14923--- a/arch/x86/include/asm/atomic.h
14924+++ b/arch/x86/include/asm/atomic.h
14925@@ -23,7 +23,18 @@
14926 */
14927 static inline int atomic_read(const atomic_t *v)
14928 {
14929- return (*(volatile int *)&(v)->counter);
14930+ return (*(volatile const int *)&(v)->counter);
14931+}
14932+
14933+/**
14934+ * atomic_read_unchecked - read atomic variable
14935+ * @v: pointer of type atomic_unchecked_t
14936+ *
14937+ * Atomically reads the value of @v.
14938+ */
14939+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14940+{
14941+ return (*(volatile const int *)&(v)->counter);
14942 }
14943
14944 /**
14945@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14946 }
14947
14948 /**
14949+ * atomic_set_unchecked - set atomic variable
14950+ * @v: pointer of type atomic_unchecked_t
14951+ * @i: required value
14952+ *
14953+ * Atomically sets the value of @v to @i.
14954+ */
14955+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14956+{
14957+ v->counter = i;
14958+}
14959+
14960+/**
14961 * atomic_add - add integer to atomic variable
14962 * @i: integer value to add
14963 * @v: pointer of type atomic_t
14964@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14965 */
14966 static inline void atomic_add(int i, atomic_t *v)
14967 {
14968- asm volatile(LOCK_PREFIX "addl %1,%0"
14969+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14970+
14971+#ifdef CONFIG_PAX_REFCOUNT
14972+ "jno 0f\n"
14973+ LOCK_PREFIX "subl %1,%0\n"
14974+ "int $4\n0:\n"
14975+ _ASM_EXTABLE(0b, 0b)
14976+#endif
14977+
14978+ : "+m" (v->counter)
14979+ : "ir" (i));
14980+}
14981+
14982+/**
14983+ * atomic_add_unchecked - add integer to atomic variable
14984+ * @i: integer value to add
14985+ * @v: pointer of type atomic_unchecked_t
14986+ *
14987+ * Atomically adds @i to @v.
14988+ */
14989+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14990+{
14991+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14992 : "+m" (v->counter)
14993 : "ir" (i));
14994 }
14995@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14996 */
14997 static inline void atomic_sub(int i, atomic_t *v)
14998 {
14999- asm volatile(LOCK_PREFIX "subl %1,%0"
15000+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15001+
15002+#ifdef CONFIG_PAX_REFCOUNT
15003+ "jno 0f\n"
15004+ LOCK_PREFIX "addl %1,%0\n"
15005+ "int $4\n0:\n"
15006+ _ASM_EXTABLE(0b, 0b)
15007+#endif
15008+
15009+ : "+m" (v->counter)
15010+ : "ir" (i));
15011+}
15012+
15013+/**
15014+ * atomic_sub_unchecked - subtract integer from atomic variable
15015+ * @i: integer value to subtract
15016+ * @v: pointer of type atomic_unchecked_t
15017+ *
15018+ * Atomically subtracts @i from @v.
15019+ */
15020+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15021+{
15022+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15023 : "+m" (v->counter)
15024 : "ir" (i));
15025 }
15026@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15027 */
15028 static inline int atomic_sub_and_test(int i, atomic_t *v)
15029 {
15030- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15031+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15032 }
15033
15034 /**
15035@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15036 */
15037 static inline void atomic_inc(atomic_t *v)
15038 {
15039- asm volatile(LOCK_PREFIX "incl %0"
15040+ asm volatile(LOCK_PREFIX "incl %0\n"
15041+
15042+#ifdef CONFIG_PAX_REFCOUNT
15043+ "jno 0f\n"
15044+ LOCK_PREFIX "decl %0\n"
15045+ "int $4\n0:\n"
15046+ _ASM_EXTABLE(0b, 0b)
15047+#endif
15048+
15049+ : "+m" (v->counter));
15050+}
15051+
15052+/**
15053+ * atomic_inc_unchecked - increment atomic variable
15054+ * @v: pointer of type atomic_unchecked_t
15055+ *
15056+ * Atomically increments @v by 1.
15057+ */
15058+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15059+{
15060+ asm volatile(LOCK_PREFIX "incl %0\n"
15061 : "+m" (v->counter));
15062 }
15063
15064@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15065 */
15066 static inline void atomic_dec(atomic_t *v)
15067 {
15068- asm volatile(LOCK_PREFIX "decl %0"
15069+ asm volatile(LOCK_PREFIX "decl %0\n"
15070+
15071+#ifdef CONFIG_PAX_REFCOUNT
15072+ "jno 0f\n"
15073+ LOCK_PREFIX "incl %0\n"
15074+ "int $4\n0:\n"
15075+ _ASM_EXTABLE(0b, 0b)
15076+#endif
15077+
15078+ : "+m" (v->counter));
15079+}
15080+
15081+/**
15082+ * atomic_dec_unchecked - decrement atomic variable
15083+ * @v: pointer of type atomic_unchecked_t
15084+ *
15085+ * Atomically decrements @v by 1.
15086+ */
15087+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15088+{
15089+ asm volatile(LOCK_PREFIX "decl %0\n"
15090 : "+m" (v->counter));
15091 }
15092
15093@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15094 */
15095 static inline int atomic_dec_and_test(atomic_t *v)
15096 {
15097- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15098+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15099 }
15100
15101 /**
15102@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15103 */
15104 static inline int atomic_inc_and_test(atomic_t *v)
15105 {
15106- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15107+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15108+}
15109+
15110+/**
15111+ * atomic_inc_and_test_unchecked - increment and test
15112+ * @v: pointer of type atomic_unchecked_t
15113+ *
15114+ * Atomically increments @v by 1
15115+ * and returns true if the result is zero, or false for all
15116+ * other cases.
15117+ */
15118+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15119+{
15120+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15121 }
15122
15123 /**
15124@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15125 */
15126 static inline int atomic_add_negative(int i, atomic_t *v)
15127 {
15128- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15129+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15130 }
15131
15132 /**
15133@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15134 */
15135 static inline int atomic_add_return(int i, atomic_t *v)
15136 {
15137+ return i + xadd_check_overflow(&v->counter, i);
15138+}
15139+
15140+/**
15141+ * atomic_add_return_unchecked - add integer and return
15142+ * @i: integer value to add
15143+ * @v: pointer of type atomic_unchecked_t
15144+ *
15145+ * Atomically adds @i to @v and returns @i + @v
15146+ */
15147+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15148+{
15149 return i + xadd(&v->counter, i);
15150 }
15151
15152@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15153 }
15154
15155 #define atomic_inc_return(v) (atomic_add_return(1, v))
15156+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15157+{
15158+ return atomic_add_return_unchecked(1, v);
15159+}
15160 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15161
15162-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15163+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15164+{
15165+ return cmpxchg(&v->counter, old, new);
15166+}
15167+
15168+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15169 {
15170 return cmpxchg(&v->counter, old, new);
15171 }
15172@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15173 return xchg(&v->counter, new);
15174 }
15175
15176+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15177+{
15178+ return xchg(&v->counter, new);
15179+}
15180+
15181 /**
15182 * __atomic_add_unless - add unless the number is already a given value
15183 * @v: pointer of type atomic_t
15184@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15185 * Atomically adds @a to @v, so long as @v was not already @u.
15186 * Returns the old value of @v.
15187 */
15188-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15189+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15190 {
15191- int c, old;
15192+ int c, old, new;
15193 c = atomic_read(v);
15194 for (;;) {
15195- if (unlikely(c == (u)))
15196+ if (unlikely(c == u))
15197 break;
15198- old = atomic_cmpxchg((v), c, c + (a));
15199+
15200+ asm volatile("addl %2,%0\n"
15201+
15202+#ifdef CONFIG_PAX_REFCOUNT
15203+ "jno 0f\n"
15204+ "subl %2,%0\n"
15205+ "int $4\n0:\n"
15206+ _ASM_EXTABLE(0b, 0b)
15207+#endif
15208+
15209+ : "=r" (new)
15210+ : "0" (c), "ir" (a));
15211+
15212+ old = atomic_cmpxchg(v, c, new);
15213 if (likely(old == c))
15214 break;
15215 c = old;
15216@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15217 }
15218
15219 /**
15220+ * atomic_inc_not_zero_hint - increment if not null
15221+ * @v: pointer of type atomic_t
15222+ * @hint: probable value of the atomic before the increment
15223+ *
15224+ * This version of atomic_inc_not_zero() gives a hint of probable
15225+ * value of the atomic. This helps processor to not read the memory
15226+ * before doing the atomic read/modify/write cycle, lowering
15227+ * number of bus transactions on some arches.
15228+ *
15229+ * Returns: 0 if increment was not done, 1 otherwise.
15230+ */
15231+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15232+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15233+{
15234+ int val, c = hint, new;
15235+
15236+ /* sanity test, should be removed by compiler if hint is a constant */
15237+ if (!hint)
15238+ return __atomic_add_unless(v, 1, 0);
15239+
15240+ do {
15241+ asm volatile("incl %0\n"
15242+
15243+#ifdef CONFIG_PAX_REFCOUNT
15244+ "jno 0f\n"
15245+ "decl %0\n"
15246+ "int $4\n0:\n"
15247+ _ASM_EXTABLE(0b, 0b)
15248+#endif
15249+
15250+ : "=r" (new)
15251+ : "0" (c));
15252+
15253+ val = atomic_cmpxchg(v, c, new);
15254+ if (val == c)
15255+ return 1;
15256+ c = val;
15257+ } while (c);
15258+
15259+ return 0;
15260+}
15261+
15262+/**
15263 * atomic_inc_short - increment of a short integer
15264 * @v: pointer to type int
15265 *
15266@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15267 #endif
15268
15269 /* These are x86-specific, used by some header files */
15270-#define atomic_clear_mask(mask, addr) \
15271- asm volatile(LOCK_PREFIX "andl %0,%1" \
15272- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15273+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15274+{
15275+ asm volatile(LOCK_PREFIX "andl %1,%0"
15276+ : "+m" (v->counter)
15277+ : "r" (~(mask))
15278+ : "memory");
15279+}
15280
15281-#define atomic_set_mask(mask, addr) \
15282- asm volatile(LOCK_PREFIX "orl %0,%1" \
15283- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15284- : "memory")
15285+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15286+{
15287+ asm volatile(LOCK_PREFIX "andl %1,%0"
15288+ : "+m" (v->counter)
15289+ : "r" (~(mask))
15290+ : "memory");
15291+}
15292+
15293+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15294+{
15295+ asm volatile(LOCK_PREFIX "orl %1,%0"
15296+ : "+m" (v->counter)
15297+ : "r" (mask)
15298+ : "memory");
15299+}
15300+
15301+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15302+{
15303+ asm volatile(LOCK_PREFIX "orl %1,%0"
15304+ : "+m" (v->counter)
15305+ : "r" (mask)
15306+ : "memory");
15307+}
15308
15309 /* Atomic operations are already serializing on x86 */
15310 #define smp_mb__before_atomic_dec() barrier()
15311diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15312index b154de7..bf18a5a 100644
15313--- a/arch/x86/include/asm/atomic64_32.h
15314+++ b/arch/x86/include/asm/atomic64_32.h
15315@@ -12,6 +12,14 @@ typedef struct {
15316 u64 __aligned(8) counter;
15317 } atomic64_t;
15318
15319+#ifdef CONFIG_PAX_REFCOUNT
15320+typedef struct {
15321+ u64 __aligned(8) counter;
15322+} atomic64_unchecked_t;
15323+#else
15324+typedef atomic64_t atomic64_unchecked_t;
15325+#endif
15326+
15327 #define ATOMIC64_INIT(val) { (val) }
15328
15329 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15330@@ -37,21 +45,31 @@ typedef struct {
15331 ATOMIC64_DECL_ONE(sym##_386)
15332
15333 ATOMIC64_DECL_ONE(add_386);
15334+ATOMIC64_DECL_ONE(add_unchecked_386);
15335 ATOMIC64_DECL_ONE(sub_386);
15336+ATOMIC64_DECL_ONE(sub_unchecked_386);
15337 ATOMIC64_DECL_ONE(inc_386);
15338+ATOMIC64_DECL_ONE(inc_unchecked_386);
15339 ATOMIC64_DECL_ONE(dec_386);
15340+ATOMIC64_DECL_ONE(dec_unchecked_386);
15341 #endif
15342
15343 #define alternative_atomic64(f, out, in...) \
15344 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15345
15346 ATOMIC64_DECL(read);
15347+ATOMIC64_DECL(read_unchecked);
15348 ATOMIC64_DECL(set);
15349+ATOMIC64_DECL(set_unchecked);
15350 ATOMIC64_DECL(xchg);
15351 ATOMIC64_DECL(add_return);
15352+ATOMIC64_DECL(add_return_unchecked);
15353 ATOMIC64_DECL(sub_return);
15354+ATOMIC64_DECL(sub_return_unchecked);
15355 ATOMIC64_DECL(inc_return);
15356+ATOMIC64_DECL(inc_return_unchecked);
15357 ATOMIC64_DECL(dec_return);
15358+ATOMIC64_DECL(dec_return_unchecked);
15359 ATOMIC64_DECL(dec_if_positive);
15360 ATOMIC64_DECL(inc_not_zero);
15361 ATOMIC64_DECL(add_unless);
15362@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15363 }
15364
15365 /**
15366+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15367+ * @p: pointer to type atomic64_unchecked_t
15368+ * @o: expected value
15369+ * @n: new value
15370+ *
15371+ * Atomically sets @v to @n if it was equal to @o and returns
15372+ * the old value.
15373+ */
15374+
15375+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15376+{
15377+ return cmpxchg64(&v->counter, o, n);
15378+}
15379+
15380+/**
15381 * atomic64_xchg - xchg atomic64 variable
15382 * @v: pointer to type atomic64_t
15383 * @n: value to assign
15384@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15385 }
15386
15387 /**
15388+ * atomic64_set_unchecked - set atomic64 variable
15389+ * @v: pointer to type atomic64_unchecked_t
15390+ * @n: value to assign
15391+ *
15392+ * Atomically sets the value of @v to @n.
15393+ */
15394+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15395+{
15396+ unsigned high = (unsigned)(i >> 32);
15397+ unsigned low = (unsigned)i;
15398+ alternative_atomic64(set, /* no output */,
15399+ "S" (v), "b" (low), "c" (high)
15400+ : "eax", "edx", "memory");
15401+}
15402+
15403+/**
15404 * atomic64_read - read atomic64 variable
15405 * @v: pointer to type atomic64_t
15406 *
15407@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15408 }
15409
15410 /**
15411+ * atomic64_read_unchecked - read atomic64 variable
15412+ * @v: pointer to type atomic64_unchecked_t
15413+ *
15414+ * Atomically reads the value of @v and returns it.
15415+ */
15416+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15417+{
15418+ long long r;
15419+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15420+ return r;
15421+ }
15422+
15423+/**
15424 * atomic64_add_return - add and return
15425 * @i: integer value to add
15426 * @v: pointer to type atomic64_t
15427@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15428 return i;
15429 }
15430
15431+/**
15432+ * atomic64_add_return_unchecked - add and return
15433+ * @i: integer value to add
15434+ * @v: pointer to type atomic64_unchecked_t
15435+ *
15436+ * Atomically adds @i to @v and returns @i + *@v
15437+ */
15438+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15439+{
15440+ alternative_atomic64(add_return_unchecked,
15441+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15442+ ASM_NO_INPUT_CLOBBER("memory"));
15443+ return i;
15444+}
15445+
15446 /*
15447 * Other variants with different arithmetic operators:
15448 */
15449@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15450 return a;
15451 }
15452
15453+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15454+{
15455+ long long a;
15456+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15457+ "S" (v) : "memory", "ecx");
15458+ return a;
15459+}
15460+
15461 static inline long long atomic64_dec_return(atomic64_t *v)
15462 {
15463 long long a;
15464@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15465 }
15466
15467 /**
15468+ * atomic64_add_unchecked - add integer to atomic64 variable
15469+ * @i: integer value to add
15470+ * @v: pointer to type atomic64_unchecked_t
15471+ *
15472+ * Atomically adds @i to @v.
15473+ */
15474+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15475+{
15476+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15477+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15478+ ASM_NO_INPUT_CLOBBER("memory"));
15479+ return i;
15480+}
15481+
15482+/**
15483 * atomic64_sub - subtract the atomic64 variable
15484 * @i: integer value to subtract
15485 * @v: pointer to type atomic64_t
15486diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15487index 46e9052..ae45136 100644
15488--- a/arch/x86/include/asm/atomic64_64.h
15489+++ b/arch/x86/include/asm/atomic64_64.h
15490@@ -18,7 +18,19 @@
15491 */
15492 static inline long atomic64_read(const atomic64_t *v)
15493 {
15494- return (*(volatile long *)&(v)->counter);
15495+ return (*(volatile const long *)&(v)->counter);
15496+}
15497+
15498+/**
15499+ * atomic64_read_unchecked - read atomic64 variable
15500+ * @v: pointer of type atomic64_unchecked_t
15501+ *
15502+ * Atomically reads the value of @v.
15503+ * Doesn't imply a read memory barrier.
15504+ */
15505+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15506+{
15507+ return (*(volatile const long *)&(v)->counter);
15508 }
15509
15510 /**
15511@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15512 }
15513
15514 /**
15515+ * atomic64_set_unchecked - set atomic64 variable
15516+ * @v: pointer to type atomic64_unchecked_t
15517+ * @i: required value
15518+ *
15519+ * Atomically sets the value of @v to @i.
15520+ */
15521+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15522+{
15523+ v->counter = i;
15524+}
15525+
15526+/**
15527 * atomic64_add - add integer to atomic64 variable
15528 * @i: integer value to add
15529 * @v: pointer to type atomic64_t
15530@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15531 */
15532 static inline void atomic64_add(long i, atomic64_t *v)
15533 {
15534+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15535+
15536+#ifdef CONFIG_PAX_REFCOUNT
15537+ "jno 0f\n"
15538+ LOCK_PREFIX "subq %1,%0\n"
15539+ "int $4\n0:\n"
15540+ _ASM_EXTABLE(0b, 0b)
15541+#endif
15542+
15543+ : "=m" (v->counter)
15544+ : "er" (i), "m" (v->counter));
15545+}
15546+
15547+/**
15548+ * atomic64_add_unchecked - add integer to atomic64 variable
15549+ * @i: integer value to add
15550+ * @v: pointer to type atomic64_unchecked_t
15551+ *
15552+ * Atomically adds @i to @v.
15553+ */
15554+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15555+{
15556 asm volatile(LOCK_PREFIX "addq %1,%0"
15557 : "=m" (v->counter)
15558 : "er" (i), "m" (v->counter));
15559@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15560 */
15561 static inline void atomic64_sub(long i, atomic64_t *v)
15562 {
15563- asm volatile(LOCK_PREFIX "subq %1,%0"
15564+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15565+
15566+#ifdef CONFIG_PAX_REFCOUNT
15567+ "jno 0f\n"
15568+ LOCK_PREFIX "addq %1,%0\n"
15569+ "int $4\n0:\n"
15570+ _ASM_EXTABLE(0b, 0b)
15571+#endif
15572+
15573+ : "=m" (v->counter)
15574+ : "er" (i), "m" (v->counter));
15575+}
15576+
15577+/**
15578+ * atomic64_sub_unchecked - subtract the atomic64 variable
15579+ * @i: integer value to subtract
15580+ * @v: pointer to type atomic64_unchecked_t
15581+ *
15582+ * Atomically subtracts @i from @v.
15583+ */
15584+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15585+{
15586+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15587 : "=m" (v->counter)
15588 : "er" (i), "m" (v->counter));
15589 }
15590@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15591 */
15592 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15593 {
15594- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15595+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15596 }
15597
15598 /**
15599@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15600 */
15601 static inline void atomic64_inc(atomic64_t *v)
15602 {
15603+ asm volatile(LOCK_PREFIX "incq %0\n"
15604+
15605+#ifdef CONFIG_PAX_REFCOUNT
15606+ "jno 0f\n"
15607+ LOCK_PREFIX "decq %0\n"
15608+ "int $4\n0:\n"
15609+ _ASM_EXTABLE(0b, 0b)
15610+#endif
15611+
15612+ : "=m" (v->counter)
15613+ : "m" (v->counter));
15614+}
15615+
15616+/**
15617+ * atomic64_inc_unchecked - increment atomic64 variable
15618+ * @v: pointer to type atomic64_unchecked_t
15619+ *
15620+ * Atomically increments @v by 1.
15621+ */
15622+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15623+{
15624 asm volatile(LOCK_PREFIX "incq %0"
15625 : "=m" (v->counter)
15626 : "m" (v->counter));
15627@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15628 */
15629 static inline void atomic64_dec(atomic64_t *v)
15630 {
15631- asm volatile(LOCK_PREFIX "decq %0"
15632+ asm volatile(LOCK_PREFIX "decq %0\n"
15633+
15634+#ifdef CONFIG_PAX_REFCOUNT
15635+ "jno 0f\n"
15636+ LOCK_PREFIX "incq %0\n"
15637+ "int $4\n0:\n"
15638+ _ASM_EXTABLE(0b, 0b)
15639+#endif
15640+
15641+ : "=m" (v->counter)
15642+ : "m" (v->counter));
15643+}
15644+
15645+/**
15646+ * atomic64_dec_unchecked - decrement atomic64 variable
15647+ * @v: pointer to type atomic64_t
15648+ *
15649+ * Atomically decrements @v by 1.
15650+ */
15651+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15652+{
15653+ asm volatile(LOCK_PREFIX "decq %0\n"
15654 : "=m" (v->counter)
15655 : "m" (v->counter));
15656 }
15657@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15658 */
15659 static inline int atomic64_dec_and_test(atomic64_t *v)
15660 {
15661- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15662+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15663 }
15664
15665 /**
15666@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15667 */
15668 static inline int atomic64_inc_and_test(atomic64_t *v)
15669 {
15670- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15671+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15672 }
15673
15674 /**
15675@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15676 */
15677 static inline int atomic64_add_negative(long i, atomic64_t *v)
15678 {
15679- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15680+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15681 }
15682
15683 /**
15684@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15685 */
15686 static inline long atomic64_add_return(long i, atomic64_t *v)
15687 {
15688+ return i + xadd_check_overflow(&v->counter, i);
15689+}
15690+
15691+/**
15692+ * atomic64_add_return_unchecked - add and return
15693+ * @i: integer value to add
15694+ * @v: pointer to type atomic64_unchecked_t
15695+ *
15696+ * Atomically adds @i to @v and returns @i + @v
15697+ */
15698+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15699+{
15700 return i + xadd(&v->counter, i);
15701 }
15702
15703@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15704 }
15705
15706 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15707+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15708+{
15709+ return atomic64_add_return_unchecked(1, v);
15710+}
15711 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15712
15713 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15714@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15715 return cmpxchg(&v->counter, old, new);
15716 }
15717
15718+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15719+{
15720+ return cmpxchg(&v->counter, old, new);
15721+}
15722+
15723 static inline long atomic64_xchg(atomic64_t *v, long new)
15724 {
15725 return xchg(&v->counter, new);
15726@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15727 */
15728 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15729 {
15730- long c, old;
15731+ long c, old, new;
15732 c = atomic64_read(v);
15733 for (;;) {
15734- if (unlikely(c == (u)))
15735+ if (unlikely(c == u))
15736 break;
15737- old = atomic64_cmpxchg((v), c, c + (a));
15738+
15739+ asm volatile("add %2,%0\n"
15740+
15741+#ifdef CONFIG_PAX_REFCOUNT
15742+ "jno 0f\n"
15743+ "sub %2,%0\n"
15744+ "int $4\n0:\n"
15745+ _ASM_EXTABLE(0b, 0b)
15746+#endif
15747+
15748+ : "=r" (new)
15749+ : "0" (c), "ir" (a));
15750+
15751+ old = atomic64_cmpxchg(v, c, new);
15752 if (likely(old == c))
15753 break;
15754 c = old;
15755 }
15756- return c != (u);
15757+ return c != u;
15758 }
15759
15760 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15761diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
15762index 69bbb48..32517fe 100644
15763--- a/arch/x86/include/asm/barrier.h
15764+++ b/arch/x86/include/asm/barrier.h
15765@@ -107,7 +107,7 @@
15766 do { \
15767 compiletime_assert_atomic_type(*p); \
15768 smp_mb(); \
15769- ACCESS_ONCE(*p) = (v); \
15770+ ACCESS_ONCE_RW(*p) = (v); \
15771 } while (0)
15772
15773 #define smp_load_acquire(p) \
15774@@ -124,7 +124,7 @@ do { \
15775 do { \
15776 compiletime_assert_atomic_type(*p); \
15777 barrier(); \
15778- ACCESS_ONCE(*p) = (v); \
15779+ ACCESS_ONCE_RW(*p) = (v); \
15780 } while (0)
15781
15782 #define smp_load_acquire(p) \
15783diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15784index 9fc1af7..776d75a 100644
15785--- a/arch/x86/include/asm/bitops.h
15786+++ b/arch/x86/include/asm/bitops.h
15787@@ -49,7 +49,7 @@
15788 * a mask operation on a byte.
15789 */
15790 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15791-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15792+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15793 #define CONST_MASK(nr) (1 << ((nr) & 7))
15794
15795 /**
15796@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15797 */
15798 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15799 {
15800- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15801+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15802 }
15803
15804 /**
15805@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15806 */
15807 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15808 {
15809- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15810+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15811 }
15812
15813 /**
15814@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15815 */
15816 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15817 {
15818- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15819+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15820 }
15821
15822 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15823@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15824 *
15825 * Undefined if no bit exists, so code should check against 0 first.
15826 */
15827-static inline unsigned long __ffs(unsigned long word)
15828+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15829 {
15830 asm("rep; bsf %1,%0"
15831 : "=r" (word)
15832@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15833 *
15834 * Undefined if no zero exists, so code should check against ~0UL first.
15835 */
15836-static inline unsigned long ffz(unsigned long word)
15837+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15838 {
15839 asm("rep; bsf %1,%0"
15840 : "=r" (word)
15841@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15842 *
15843 * Undefined if no set bit exists, so code should check against 0 first.
15844 */
15845-static inline unsigned long __fls(unsigned long word)
15846+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15847 {
15848 asm("bsr %1,%0"
15849 : "=r" (word)
15850@@ -436,7 +436,7 @@ static inline int ffs(int x)
15851 * set bit if value is nonzero. The last (most significant) bit is
15852 * at position 32.
15853 */
15854-static inline int fls(int x)
15855+static inline int __intentional_overflow(-1) fls(int x)
15856 {
15857 int r;
15858
15859@@ -478,7 +478,7 @@ static inline int fls(int x)
15860 * at position 64.
15861 */
15862 #ifdef CONFIG_X86_64
15863-static __always_inline int fls64(__u64 x)
15864+static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
15865 {
15866 int bitpos = -1;
15867 /*
15868diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15869index 4fa687a..60f2d39 100644
15870--- a/arch/x86/include/asm/boot.h
15871+++ b/arch/x86/include/asm/boot.h
15872@@ -6,10 +6,15 @@
15873 #include <uapi/asm/boot.h>
15874
15875 /* Physical address where kernel should be loaded. */
15876-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15877+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15878 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15879 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15880
15881+#ifndef __ASSEMBLY__
15882+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15883+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15884+#endif
15885+
15886 /* Minimum kernel alignment, as a power of two */
15887 #ifdef CONFIG_X86_64
15888 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15889diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15890index 48f99f1..d78ebf9 100644
15891--- a/arch/x86/include/asm/cache.h
15892+++ b/arch/x86/include/asm/cache.h
15893@@ -5,12 +5,13 @@
15894
15895 /* L1 cache line size */
15896 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15897-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15898+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15899
15900 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15901+#define __read_only __attribute__((__section__(".data..read_only")))
15902
15903 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15904-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15905+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15906
15907 #ifdef CONFIG_X86_VSMP
15908 #ifdef CONFIG_SMP
15909diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15910index 9863ee3..4a1f8e1 100644
15911--- a/arch/x86/include/asm/cacheflush.h
15912+++ b/arch/x86/include/asm/cacheflush.h
15913@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15914 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15915
15916 if (pg_flags == _PGMT_DEFAULT)
15917- return -1;
15918+ return ~0UL;
15919 else if (pg_flags == _PGMT_WC)
15920 return _PAGE_CACHE_WC;
15921 else if (pg_flags == _PGMT_UC_MINUS)
15922diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15923index cb4c73b..c473c29 100644
15924--- a/arch/x86/include/asm/calling.h
15925+++ b/arch/x86/include/asm/calling.h
15926@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15927 #define RSP 152
15928 #define SS 160
15929
15930-#define ARGOFFSET R11
15931-#define SWFRAME ORIG_RAX
15932+#define ARGOFFSET R15
15933
15934 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15935- subq $9*8+\addskip, %rsp
15936- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15937- movq_cfi rdi, 8*8
15938- movq_cfi rsi, 7*8
15939- movq_cfi rdx, 6*8
15940+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15941+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15942+ movq_cfi rdi, RDI
15943+ movq_cfi rsi, RSI
15944+ movq_cfi rdx, RDX
15945
15946 .if \save_rcx
15947- movq_cfi rcx, 5*8
15948+ movq_cfi rcx, RCX
15949 .endif
15950
15951- movq_cfi rax, 4*8
15952+ movq_cfi rax, RAX
15953
15954 .if \save_r891011
15955- movq_cfi r8, 3*8
15956- movq_cfi r9, 2*8
15957- movq_cfi r10, 1*8
15958- movq_cfi r11, 0*8
15959+ movq_cfi r8, R8
15960+ movq_cfi r9, R9
15961+ movq_cfi r10, R10
15962+ movq_cfi r11, R11
15963 .endif
15964
15965+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15966+ movq_cfi r12, R12
15967+#endif
15968+
15969 .endm
15970
15971-#define ARG_SKIP (9*8)
15972+#define ARG_SKIP ORIG_RAX
15973
15974 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15975 rstor_r8910=1, rstor_rdx=1
15976+
15977+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15978+ movq_cfi_restore R12, r12
15979+#endif
15980+
15981 .if \rstor_r11
15982- movq_cfi_restore 0*8, r11
15983+ movq_cfi_restore R11, r11
15984 .endif
15985
15986 .if \rstor_r8910
15987- movq_cfi_restore 1*8, r10
15988- movq_cfi_restore 2*8, r9
15989- movq_cfi_restore 3*8, r8
15990+ movq_cfi_restore R10, r10
15991+ movq_cfi_restore R9, r9
15992+ movq_cfi_restore R8, r8
15993 .endif
15994
15995 .if \rstor_rax
15996- movq_cfi_restore 4*8, rax
15997+ movq_cfi_restore RAX, rax
15998 .endif
15999
16000 .if \rstor_rcx
16001- movq_cfi_restore 5*8, rcx
16002+ movq_cfi_restore RCX, rcx
16003 .endif
16004
16005 .if \rstor_rdx
16006- movq_cfi_restore 6*8, rdx
16007+ movq_cfi_restore RDX, rdx
16008 .endif
16009
16010- movq_cfi_restore 7*8, rsi
16011- movq_cfi_restore 8*8, rdi
16012+ movq_cfi_restore RSI, rsi
16013+ movq_cfi_restore RDI, rdi
16014
16015- .if ARG_SKIP+\addskip > 0
16016- addq $ARG_SKIP+\addskip, %rsp
16017- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16018+ .if ORIG_RAX+\addskip > 0
16019+ addq $ORIG_RAX+\addskip, %rsp
16020+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16021 .endif
16022 .endm
16023
16024- .macro LOAD_ARGS offset, skiprax=0
16025- movq \offset(%rsp), %r11
16026- movq \offset+8(%rsp), %r10
16027- movq \offset+16(%rsp), %r9
16028- movq \offset+24(%rsp), %r8
16029- movq \offset+40(%rsp), %rcx
16030- movq \offset+48(%rsp), %rdx
16031- movq \offset+56(%rsp), %rsi
16032- movq \offset+64(%rsp), %rdi
16033+ .macro LOAD_ARGS skiprax=0
16034+ movq R11(%rsp), %r11
16035+ movq R10(%rsp), %r10
16036+ movq R9(%rsp), %r9
16037+ movq R8(%rsp), %r8
16038+ movq RCX(%rsp), %rcx
16039+ movq RDX(%rsp), %rdx
16040+ movq RSI(%rsp), %rsi
16041+ movq RDI(%rsp), %rdi
16042 .if \skiprax
16043 .else
16044- movq \offset+72(%rsp), %rax
16045+ movq RAX(%rsp), %rax
16046 .endif
16047 .endm
16048
16049-#define REST_SKIP (6*8)
16050-
16051 .macro SAVE_REST
16052- subq $REST_SKIP, %rsp
16053- CFI_ADJUST_CFA_OFFSET REST_SKIP
16054- movq_cfi rbx, 5*8
16055- movq_cfi rbp, 4*8
16056- movq_cfi r12, 3*8
16057- movq_cfi r13, 2*8
16058- movq_cfi r14, 1*8
16059- movq_cfi r15, 0*8
16060+ movq_cfi rbx, RBX
16061+ movq_cfi rbp, RBP
16062+
16063+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16064+ movq_cfi r12, R12
16065+#endif
16066+
16067+ movq_cfi r13, R13
16068+ movq_cfi r14, R14
16069+ movq_cfi r15, R15
16070 .endm
16071
16072 .macro RESTORE_REST
16073- movq_cfi_restore 0*8, r15
16074- movq_cfi_restore 1*8, r14
16075- movq_cfi_restore 2*8, r13
16076- movq_cfi_restore 3*8, r12
16077- movq_cfi_restore 4*8, rbp
16078- movq_cfi_restore 5*8, rbx
16079- addq $REST_SKIP, %rsp
16080- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16081+ movq_cfi_restore R15, r15
16082+ movq_cfi_restore R14, r14
16083+ movq_cfi_restore R13, r13
16084+
16085+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16086+ movq_cfi_restore R12, r12
16087+#endif
16088+
16089+ movq_cfi_restore RBP, rbp
16090+ movq_cfi_restore RBX, rbx
16091 .endm
16092
16093 .macro SAVE_ALL
16094diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16095index f50de69..2b0a458 100644
16096--- a/arch/x86/include/asm/checksum_32.h
16097+++ b/arch/x86/include/asm/checksum_32.h
16098@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16099 int len, __wsum sum,
16100 int *src_err_ptr, int *dst_err_ptr);
16101
16102+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16103+ int len, __wsum sum,
16104+ int *src_err_ptr, int *dst_err_ptr);
16105+
16106+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16107+ int len, __wsum sum,
16108+ int *src_err_ptr, int *dst_err_ptr);
16109+
16110 /*
16111 * Note: when you get a NULL pointer exception here this means someone
16112 * passed in an incorrect kernel address to one of these functions.
16113@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16114
16115 might_sleep();
16116 stac();
16117- ret = csum_partial_copy_generic((__force void *)src, dst,
16118+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16119 len, sum, err_ptr, NULL);
16120 clac();
16121
16122@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16123 might_sleep();
16124 if (access_ok(VERIFY_WRITE, dst, len)) {
16125 stac();
16126- ret = csum_partial_copy_generic(src, (__force void *)dst,
16127+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16128 len, sum, NULL, err_ptr);
16129 clac();
16130 return ret;
16131diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16132index d47786a..2d8883e 100644
16133--- a/arch/x86/include/asm/cmpxchg.h
16134+++ b/arch/x86/include/asm/cmpxchg.h
16135@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16136 __compiletime_error("Bad argument size for cmpxchg");
16137 extern void __xadd_wrong_size(void)
16138 __compiletime_error("Bad argument size for xadd");
16139+extern void __xadd_check_overflow_wrong_size(void)
16140+ __compiletime_error("Bad argument size for xadd_check_overflow");
16141 extern void __add_wrong_size(void)
16142 __compiletime_error("Bad argument size for add");
16143+extern void __add_check_overflow_wrong_size(void)
16144+ __compiletime_error("Bad argument size for add_check_overflow");
16145
16146 /*
16147 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16148@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16149 __ret; \
16150 })
16151
16152+#ifdef CONFIG_PAX_REFCOUNT
16153+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16154+ ({ \
16155+ __typeof__ (*(ptr)) __ret = (arg); \
16156+ switch (sizeof(*(ptr))) { \
16157+ case __X86_CASE_L: \
16158+ asm volatile (lock #op "l %0, %1\n" \
16159+ "jno 0f\n" \
16160+ "mov %0,%1\n" \
16161+ "int $4\n0:\n" \
16162+ _ASM_EXTABLE(0b, 0b) \
16163+ : "+r" (__ret), "+m" (*(ptr)) \
16164+ : : "memory", "cc"); \
16165+ break; \
16166+ case __X86_CASE_Q: \
16167+ asm volatile (lock #op "q %q0, %1\n" \
16168+ "jno 0f\n" \
16169+ "mov %0,%1\n" \
16170+ "int $4\n0:\n" \
16171+ _ASM_EXTABLE(0b, 0b) \
16172+ : "+r" (__ret), "+m" (*(ptr)) \
16173+ : : "memory", "cc"); \
16174+ break; \
16175+ default: \
16176+ __ ## op ## _check_overflow_wrong_size(); \
16177+ } \
16178+ __ret; \
16179+ })
16180+#else
16181+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16182+#endif
16183+
16184 /*
16185 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16186 * Since this is generally used to protect other memory information, we
16187@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16188 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16189 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16190
16191+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16192+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16193+
16194 #define __add(ptr, inc, lock) \
16195 ({ \
16196 __typeof__ (*(ptr)) __ret = (inc); \
16197diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16198index 59c6c40..5e0b22c 100644
16199--- a/arch/x86/include/asm/compat.h
16200+++ b/arch/x86/include/asm/compat.h
16201@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16202 typedef u32 compat_uint_t;
16203 typedef u32 compat_ulong_t;
16204 typedef u64 __attribute__((aligned(4))) compat_u64;
16205-typedef u32 compat_uptr_t;
16206+typedef u32 __user compat_uptr_t;
16207
16208 struct compat_timespec {
16209 compat_time_t tv_sec;
16210diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16211index e265ff9..72c253b 100644
16212--- a/arch/x86/include/asm/cpufeature.h
16213+++ b/arch/x86/include/asm/cpufeature.h
16214@@ -203,7 +203,7 @@
16215 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16216 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16217 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16218-
16219+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16220
16221 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16222 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16223@@ -211,7 +211,7 @@
16224 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16225 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16226 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16227-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16228+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16229 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16230 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16231 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16232@@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16233 #undef cpu_has_centaur_mcr
16234 #define cpu_has_centaur_mcr 0
16235
16236+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16237 #endif /* CONFIG_X86_64 */
16238
16239 #if __GNUC__ >= 4
16240@@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16241
16242 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16243 t_warn:
16244- warn_pre_alternatives();
16245+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16246+ warn_pre_alternatives();
16247 return false;
16248 #endif
16249
16250@@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16251 ".section .discard,\"aw\",@progbits\n"
16252 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16253 ".previous\n"
16254- ".section .altinstr_replacement,\"ax\"\n"
16255+ ".section .altinstr_replacement,\"a\"\n"
16256 "3: movb $1,%0\n"
16257 "4:\n"
16258 ".previous\n"
16259@@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16260 " .byte 2b - 1b\n" /* src len */
16261 " .byte 4f - 3f\n" /* repl len */
16262 ".previous\n"
16263- ".section .altinstr_replacement,\"ax\"\n"
16264+ ".section .altinstr_replacement,\"a\"\n"
16265 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16266 "4:\n"
16267 ".previous\n"
16268@@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16269 ".section .discard,\"aw\",@progbits\n"
16270 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16271 ".previous\n"
16272- ".section .altinstr_replacement,\"ax\"\n"
16273+ ".section .altinstr_replacement,\"a\"\n"
16274 "3: movb $0,%0\n"
16275 "4:\n"
16276 ".previous\n"
16277@@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16278 ".section .discard,\"aw\",@progbits\n"
16279 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16280 ".previous\n"
16281- ".section .altinstr_replacement,\"ax\"\n"
16282+ ".section .altinstr_replacement,\"a\"\n"
16283 "5: movb $1,%0\n"
16284 "6:\n"
16285 ".previous\n"
16286diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16287index 50d033a..37deb26 100644
16288--- a/arch/x86/include/asm/desc.h
16289+++ b/arch/x86/include/asm/desc.h
16290@@ -4,6 +4,7 @@
16291 #include <asm/desc_defs.h>
16292 #include <asm/ldt.h>
16293 #include <asm/mmu.h>
16294+#include <asm/pgtable.h>
16295
16296 #include <linux/smp.h>
16297 #include <linux/percpu.h>
16298@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16299
16300 desc->type = (info->read_exec_only ^ 1) << 1;
16301 desc->type |= info->contents << 2;
16302+ desc->type |= info->seg_not_present ^ 1;
16303
16304 desc->s = 1;
16305 desc->dpl = 0x3;
16306@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16307 }
16308
16309 extern struct desc_ptr idt_descr;
16310-extern gate_desc idt_table[];
16311-extern struct desc_ptr debug_idt_descr;
16312-extern gate_desc debug_idt_table[];
16313-
16314-struct gdt_page {
16315- struct desc_struct gdt[GDT_ENTRIES];
16316-} __attribute__((aligned(PAGE_SIZE)));
16317-
16318-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16319+extern gate_desc idt_table[IDT_ENTRIES];
16320+extern const struct desc_ptr debug_idt_descr;
16321+extern gate_desc debug_idt_table[IDT_ENTRIES];
16322
16323+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16324 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16325 {
16326- return per_cpu(gdt_page, cpu).gdt;
16327+ return cpu_gdt_table[cpu];
16328 }
16329
16330 #ifdef CONFIG_X86_64
16331@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16332 unsigned long base, unsigned dpl, unsigned flags,
16333 unsigned short seg)
16334 {
16335- gate->a = (seg << 16) | (base & 0xffff);
16336- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16337+ gate->gate.offset_low = base;
16338+ gate->gate.seg = seg;
16339+ gate->gate.reserved = 0;
16340+ gate->gate.type = type;
16341+ gate->gate.s = 0;
16342+ gate->gate.dpl = dpl;
16343+ gate->gate.p = 1;
16344+ gate->gate.offset_high = base >> 16;
16345 }
16346
16347 #endif
16348@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16349
16350 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16351 {
16352+ pax_open_kernel();
16353 memcpy(&idt[entry], gate, sizeof(*gate));
16354+ pax_close_kernel();
16355 }
16356
16357 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16358 {
16359+ pax_open_kernel();
16360 memcpy(&ldt[entry], desc, 8);
16361+ pax_close_kernel();
16362 }
16363
16364 static inline void
16365@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16366 default: size = sizeof(*gdt); break;
16367 }
16368
16369+ pax_open_kernel();
16370 memcpy(&gdt[entry], desc, size);
16371+ pax_close_kernel();
16372 }
16373
16374 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16375@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16376
16377 static inline void native_load_tr_desc(void)
16378 {
16379+ pax_open_kernel();
16380 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16381+ pax_close_kernel();
16382 }
16383
16384 static inline void native_load_gdt(const struct desc_ptr *dtr)
16385@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16386 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16387 unsigned int i;
16388
16389+ pax_open_kernel();
16390 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16391 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16392+ pax_close_kernel();
16393 }
16394
16395 #define _LDT_empty(info) \
16396@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16397 preempt_enable();
16398 }
16399
16400-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16401+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16402 {
16403 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16404 }
16405@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16406 }
16407
16408 #ifdef CONFIG_X86_64
16409-static inline void set_nmi_gate(int gate, void *addr)
16410+static inline void set_nmi_gate(int gate, const void *addr)
16411 {
16412 gate_desc s;
16413
16414@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16415 #endif
16416
16417 #ifdef CONFIG_TRACING
16418-extern struct desc_ptr trace_idt_descr;
16419-extern gate_desc trace_idt_table[];
16420+extern const struct desc_ptr trace_idt_descr;
16421+extern gate_desc trace_idt_table[IDT_ENTRIES];
16422 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16423 {
16424 write_idt_entry(trace_idt_table, entry, gate);
16425 }
16426
16427-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16428+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16429 unsigned dpl, unsigned ist, unsigned seg)
16430 {
16431 gate_desc s;
16432@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16433 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16434 #endif
16435
16436-static inline void _set_gate(int gate, unsigned type, void *addr,
16437+static inline void _set_gate(int gate, unsigned type, const void *addr,
16438 unsigned dpl, unsigned ist, unsigned seg)
16439 {
16440 gate_desc s;
16441@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16442 #define set_intr_gate(n, addr) \
16443 do { \
16444 BUG_ON((unsigned)n > 0xFF); \
16445- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16446+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16447 __KERNEL_CS); \
16448- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16449+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16450 0, 0, __KERNEL_CS); \
16451 } while (0)
16452
16453@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16454 /*
16455 * This routine sets up an interrupt gate at directory privilege level 3.
16456 */
16457-static inline void set_system_intr_gate(unsigned int n, void *addr)
16458+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16459 {
16460 BUG_ON((unsigned)n > 0xFF);
16461 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16462 }
16463
16464-static inline void set_system_trap_gate(unsigned int n, void *addr)
16465+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16466 {
16467 BUG_ON((unsigned)n > 0xFF);
16468 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16469 }
16470
16471-static inline void set_trap_gate(unsigned int n, void *addr)
16472+static inline void set_trap_gate(unsigned int n, const void *addr)
16473 {
16474 BUG_ON((unsigned)n > 0xFF);
16475 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16476@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16477 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16478 {
16479 BUG_ON((unsigned)n > 0xFF);
16480- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16481+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16482 }
16483
16484-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16485+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16486 {
16487 BUG_ON((unsigned)n > 0xFF);
16488 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16489 }
16490
16491-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16492+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16493 {
16494 BUG_ON((unsigned)n > 0xFF);
16495 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16496@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16497 else
16498 load_idt((const struct desc_ptr *)&idt_descr);
16499 }
16500+
16501+#ifdef CONFIG_X86_32
16502+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16503+{
16504+ struct desc_struct d;
16505+
16506+ if (likely(limit))
16507+ limit = (limit - 1UL) >> PAGE_SHIFT;
16508+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16509+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16510+}
16511+#endif
16512+
16513 #endif /* _ASM_X86_DESC_H */
16514diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16515index 278441f..b95a174 100644
16516--- a/arch/x86/include/asm/desc_defs.h
16517+++ b/arch/x86/include/asm/desc_defs.h
16518@@ -31,6 +31,12 @@ struct desc_struct {
16519 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16520 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16521 };
16522+ struct {
16523+ u16 offset_low;
16524+ u16 seg;
16525+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16526+ unsigned offset_high: 16;
16527+ } gate;
16528 };
16529 } __attribute__((packed));
16530
16531diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16532index ced283a..ffe04cc 100644
16533--- a/arch/x86/include/asm/div64.h
16534+++ b/arch/x86/include/asm/div64.h
16535@@ -39,7 +39,7 @@
16536 __mod; \
16537 })
16538
16539-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16540+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16541 {
16542 union {
16543 u64 v64;
16544diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16545index 2c71182..731124d 100644
16546--- a/arch/x86/include/asm/elf.h
16547+++ b/arch/x86/include/asm/elf.h
16548@@ -243,7 +243,25 @@ extern int force_personality32;
16549 the loader. We need to make sure that it is out of the way of the program
16550 that it will "exec", and that there is sufficient room for the brk. */
16551
16552+#ifdef CONFIG_PAX_SEGMEXEC
16553+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16554+#else
16555 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16556+#endif
16557+
16558+#ifdef CONFIG_PAX_ASLR
16559+#ifdef CONFIG_X86_32
16560+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16561+
16562+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16563+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16564+#else
16565+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16566+
16567+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16568+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16569+#endif
16570+#endif
16571
16572 /* This yields a mask that user programs can use to figure out what
16573 instruction set this CPU supports. This could be done in user space,
16574@@ -292,16 +310,12 @@ do { \
16575
16576 #define ARCH_DLINFO \
16577 do { \
16578- if (vdso_enabled) \
16579- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16580- (unsigned long)current->mm->context.vdso); \
16581+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16582 } while (0)
16583
16584 #define ARCH_DLINFO_X32 \
16585 do { \
16586- if (vdso_enabled) \
16587- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16588- (unsigned long)current->mm->context.vdso); \
16589+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16590 } while (0)
16591
16592 #define AT_SYSINFO 32
16593@@ -316,7 +330,7 @@ else \
16594
16595 #endif /* !CONFIG_X86_32 */
16596
16597-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16598+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16599
16600 #define VDSO_ENTRY \
16601 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16602@@ -332,9 +346,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16603 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16604 #define compat_arch_setup_additional_pages syscall32_setup_pages
16605
16606-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16607-#define arch_randomize_brk arch_randomize_brk
16608-
16609 /*
16610 * True on X86_32 or when emulating IA32 on X86_64
16611 */
16612diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16613index 77a99ac..39ff7f5 100644
16614--- a/arch/x86/include/asm/emergency-restart.h
16615+++ b/arch/x86/include/asm/emergency-restart.h
16616@@ -1,6 +1,6 @@
16617 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16618 #define _ASM_X86_EMERGENCY_RESTART_H
16619
16620-extern void machine_emergency_restart(void);
16621+extern void machine_emergency_restart(void) __noreturn;
16622
16623 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16624diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16625index 1c7eefe..d0e4702 100644
16626--- a/arch/x86/include/asm/floppy.h
16627+++ b/arch/x86/include/asm/floppy.h
16628@@ -229,18 +229,18 @@ static struct fd_routine_l {
16629 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16630 } fd_routine[] = {
16631 {
16632- request_dma,
16633- free_dma,
16634- get_dma_residue,
16635- dma_mem_alloc,
16636- hard_dma_setup
16637+ ._request_dma = request_dma,
16638+ ._free_dma = free_dma,
16639+ ._get_dma_residue = get_dma_residue,
16640+ ._dma_mem_alloc = dma_mem_alloc,
16641+ ._dma_setup = hard_dma_setup
16642 },
16643 {
16644- vdma_request_dma,
16645- vdma_nop,
16646- vdma_get_dma_residue,
16647- vdma_mem_alloc,
16648- vdma_dma_setup
16649+ ._request_dma = vdma_request_dma,
16650+ ._free_dma = vdma_nop,
16651+ ._get_dma_residue = vdma_get_dma_residue,
16652+ ._dma_mem_alloc = vdma_mem_alloc,
16653+ ._dma_setup = vdma_dma_setup
16654 }
16655 };
16656
16657diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16658index cea1c76..6c0d79b 100644
16659--- a/arch/x86/include/asm/fpu-internal.h
16660+++ b/arch/x86/include/asm/fpu-internal.h
16661@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16662 #define user_insn(insn, output, input...) \
16663 ({ \
16664 int err; \
16665+ pax_open_userland(); \
16666 asm volatile(ASM_STAC "\n" \
16667- "1:" #insn "\n\t" \
16668+ "1:" \
16669+ __copyuser_seg \
16670+ #insn "\n\t" \
16671 "2: " ASM_CLAC "\n" \
16672 ".section .fixup,\"ax\"\n" \
16673 "3: movl $-1,%[err]\n" \
16674@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16675 _ASM_EXTABLE(1b, 3b) \
16676 : [err] "=r" (err), output \
16677 : "0"(0), input); \
16678+ pax_close_userland(); \
16679 err; \
16680 })
16681
16682@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16683 "fnclex\n\t"
16684 "emms\n\t"
16685 "fildl %P[addr]" /* set F?P to defined value */
16686- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16687+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16688 }
16689
16690 return fpu_restore_checking(&tsk->thread.fpu);
16691diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16692index b4c1f54..e290c08 100644
16693--- a/arch/x86/include/asm/futex.h
16694+++ b/arch/x86/include/asm/futex.h
16695@@ -12,6 +12,7 @@
16696 #include <asm/smap.h>
16697
16698 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16699+ typecheck(u32 __user *, uaddr); \
16700 asm volatile("\t" ASM_STAC "\n" \
16701 "1:\t" insn "\n" \
16702 "2:\t" ASM_CLAC "\n" \
16703@@ -20,15 +21,16 @@
16704 "\tjmp\t2b\n" \
16705 "\t.previous\n" \
16706 _ASM_EXTABLE(1b, 3b) \
16707- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16708+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16709 : "i" (-EFAULT), "0" (oparg), "1" (0))
16710
16711 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16712+ typecheck(u32 __user *, uaddr); \
16713 asm volatile("\t" ASM_STAC "\n" \
16714 "1:\tmovl %2, %0\n" \
16715 "\tmovl\t%0, %3\n" \
16716 "\t" insn "\n" \
16717- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16718+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16719 "\tjnz\t1b\n" \
16720 "3:\t" ASM_CLAC "\n" \
16721 "\t.section .fixup,\"ax\"\n" \
16722@@ -38,7 +40,7 @@
16723 _ASM_EXTABLE(1b, 4b) \
16724 _ASM_EXTABLE(2b, 4b) \
16725 : "=&a" (oldval), "=&r" (ret), \
16726- "+m" (*uaddr), "=&r" (tem) \
16727+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16728 : "r" (oparg), "i" (-EFAULT), "1" (0))
16729
16730 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16731@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16732
16733 pagefault_disable();
16734
16735+ pax_open_userland();
16736 switch (op) {
16737 case FUTEX_OP_SET:
16738- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16739+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16740 break;
16741 case FUTEX_OP_ADD:
16742- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16743+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16744 uaddr, oparg);
16745 break;
16746 case FUTEX_OP_OR:
16747@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16748 default:
16749 ret = -ENOSYS;
16750 }
16751+ pax_close_userland();
16752
16753 pagefault_enable();
16754
16755diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16756index a307b75..ec74ca2 100644
16757--- a/arch/x86/include/asm/hw_irq.h
16758+++ b/arch/x86/include/asm/hw_irq.h
16759@@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
16760 extern void enable_IO_APIC(void);
16761
16762 /* Statistics */
16763-extern atomic_t irq_err_count;
16764-extern atomic_t irq_mis_count;
16765+extern atomic_unchecked_t irq_err_count;
16766+extern atomic_unchecked_t irq_mis_count;
16767
16768 /* EISA */
16769 extern void eisa_set_level_irq(unsigned int irq);
16770diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16771index a203659..9889f1c 100644
16772--- a/arch/x86/include/asm/i8259.h
16773+++ b/arch/x86/include/asm/i8259.h
16774@@ -62,7 +62,7 @@ struct legacy_pic {
16775 void (*init)(int auto_eoi);
16776 int (*irq_pending)(unsigned int irq);
16777 void (*make_irq)(unsigned int irq);
16778-};
16779+} __do_const;
16780
16781 extern struct legacy_pic *legacy_pic;
16782 extern struct legacy_pic null_legacy_pic;
16783diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16784index b8237d8..3e8864e 100644
16785--- a/arch/x86/include/asm/io.h
16786+++ b/arch/x86/include/asm/io.h
16787@@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16788 "m" (*(volatile type __force *)addr) barrier); }
16789
16790 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16791-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16792-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16793+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16794+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16795
16796 build_mmio_read(__readb, "b", unsigned char, "=q", )
16797-build_mmio_read(__readw, "w", unsigned short, "=r", )
16798-build_mmio_read(__readl, "l", unsigned int, "=r", )
16799+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16800+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16801
16802 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16803 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16804@@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
16805 * this function
16806 */
16807
16808-static inline phys_addr_t virt_to_phys(volatile void *address)
16809+static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
16810 {
16811 return __pa(address);
16812 }
16813@@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16814 return ioremap_nocache(offset, size);
16815 }
16816
16817-extern void iounmap(volatile void __iomem *addr);
16818+extern void iounmap(const volatile void __iomem *addr);
16819
16820 extern void set_iounmap_nonlazy(void);
16821
16822@@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
16823
16824 #include <linux/vmalloc.h>
16825
16826+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16827+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16828+{
16829+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16830+}
16831+
16832+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16833+{
16834+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16835+}
16836+
16837 /*
16838 * Convert a virtual cached pointer to an uncached pointer
16839 */
16840diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16841index 0a8b519..80e7d5b 100644
16842--- a/arch/x86/include/asm/irqflags.h
16843+++ b/arch/x86/include/asm/irqflags.h
16844@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16845 sti; \
16846 sysexit
16847
16848+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16849+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16850+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16851+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16852+
16853 #else
16854 #define INTERRUPT_RETURN iret
16855 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16856diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16857index 9454c16..e4100e3 100644
16858--- a/arch/x86/include/asm/kprobes.h
16859+++ b/arch/x86/include/asm/kprobes.h
16860@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16861 #define RELATIVEJUMP_SIZE 5
16862 #define RELATIVECALL_OPCODE 0xe8
16863 #define RELATIVE_ADDR_SIZE 4
16864-#define MAX_STACK_SIZE 64
16865-#define MIN_STACK_SIZE(ADDR) \
16866- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16867- THREAD_SIZE - (unsigned long)(ADDR))) \
16868- ? (MAX_STACK_SIZE) \
16869- : (((unsigned long)current_thread_info()) + \
16870- THREAD_SIZE - (unsigned long)(ADDR)))
16871+#define MAX_STACK_SIZE 64UL
16872+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16873
16874 #define flush_insn_slot(p) do { } while (0)
16875
16876diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16877index 4ad6560..75c7bdd 100644
16878--- a/arch/x86/include/asm/local.h
16879+++ b/arch/x86/include/asm/local.h
16880@@ -10,33 +10,97 @@ typedef struct {
16881 atomic_long_t a;
16882 } local_t;
16883
16884+typedef struct {
16885+ atomic_long_unchecked_t a;
16886+} local_unchecked_t;
16887+
16888 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16889
16890 #define local_read(l) atomic_long_read(&(l)->a)
16891+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16892 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16893+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16894
16895 static inline void local_inc(local_t *l)
16896 {
16897- asm volatile(_ASM_INC "%0"
16898+ asm volatile(_ASM_INC "%0\n"
16899+
16900+#ifdef CONFIG_PAX_REFCOUNT
16901+ "jno 0f\n"
16902+ _ASM_DEC "%0\n"
16903+ "int $4\n0:\n"
16904+ _ASM_EXTABLE(0b, 0b)
16905+#endif
16906+
16907+ : "+m" (l->a.counter));
16908+}
16909+
16910+static inline void local_inc_unchecked(local_unchecked_t *l)
16911+{
16912+ asm volatile(_ASM_INC "%0\n"
16913 : "+m" (l->a.counter));
16914 }
16915
16916 static inline void local_dec(local_t *l)
16917 {
16918- asm volatile(_ASM_DEC "%0"
16919+ asm volatile(_ASM_DEC "%0\n"
16920+
16921+#ifdef CONFIG_PAX_REFCOUNT
16922+ "jno 0f\n"
16923+ _ASM_INC "%0\n"
16924+ "int $4\n0:\n"
16925+ _ASM_EXTABLE(0b, 0b)
16926+#endif
16927+
16928+ : "+m" (l->a.counter));
16929+}
16930+
16931+static inline void local_dec_unchecked(local_unchecked_t *l)
16932+{
16933+ asm volatile(_ASM_DEC "%0\n"
16934 : "+m" (l->a.counter));
16935 }
16936
16937 static inline void local_add(long i, local_t *l)
16938 {
16939- asm volatile(_ASM_ADD "%1,%0"
16940+ asm volatile(_ASM_ADD "%1,%0\n"
16941+
16942+#ifdef CONFIG_PAX_REFCOUNT
16943+ "jno 0f\n"
16944+ _ASM_SUB "%1,%0\n"
16945+ "int $4\n0:\n"
16946+ _ASM_EXTABLE(0b, 0b)
16947+#endif
16948+
16949+ : "+m" (l->a.counter)
16950+ : "ir" (i));
16951+}
16952+
16953+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16954+{
16955+ asm volatile(_ASM_ADD "%1,%0\n"
16956 : "+m" (l->a.counter)
16957 : "ir" (i));
16958 }
16959
16960 static inline void local_sub(long i, local_t *l)
16961 {
16962- asm volatile(_ASM_SUB "%1,%0"
16963+ asm volatile(_ASM_SUB "%1,%0\n"
16964+
16965+#ifdef CONFIG_PAX_REFCOUNT
16966+ "jno 0f\n"
16967+ _ASM_ADD "%1,%0\n"
16968+ "int $4\n0:\n"
16969+ _ASM_EXTABLE(0b, 0b)
16970+#endif
16971+
16972+ : "+m" (l->a.counter)
16973+ : "ir" (i));
16974+}
16975+
16976+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16977+{
16978+ asm volatile(_ASM_SUB "%1,%0\n"
16979 : "+m" (l->a.counter)
16980 : "ir" (i));
16981 }
16982@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16983 */
16984 static inline int local_sub_and_test(long i, local_t *l)
16985 {
16986- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16987+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16988 }
16989
16990 /**
16991@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16992 */
16993 static inline int local_dec_and_test(local_t *l)
16994 {
16995- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16996+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16997 }
16998
16999 /**
17000@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17001 */
17002 static inline int local_inc_and_test(local_t *l)
17003 {
17004- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17005+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17006 }
17007
17008 /**
17009@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17010 */
17011 static inline int local_add_negative(long i, local_t *l)
17012 {
17013- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17014+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17015 }
17016
17017 /**
17018@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17019 static inline long local_add_return(long i, local_t *l)
17020 {
17021 long __i = i;
17022+ asm volatile(_ASM_XADD "%0, %1\n"
17023+
17024+#ifdef CONFIG_PAX_REFCOUNT
17025+ "jno 0f\n"
17026+ _ASM_MOV "%0,%1\n"
17027+ "int $4\n0:\n"
17028+ _ASM_EXTABLE(0b, 0b)
17029+#endif
17030+
17031+ : "+r" (i), "+m" (l->a.counter)
17032+ : : "memory");
17033+ return i + __i;
17034+}
17035+
17036+/**
17037+ * local_add_return_unchecked - add and return
17038+ * @i: integer value to add
17039+ * @l: pointer to type local_unchecked_t
17040+ *
17041+ * Atomically adds @i to @l and returns @i + @l
17042+ */
17043+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17044+{
17045+ long __i = i;
17046 asm volatile(_ASM_XADD "%0, %1;"
17047 : "+r" (i), "+m" (l->a.counter)
17048 : : "memory");
17049@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17050
17051 #define local_cmpxchg(l, o, n) \
17052 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17053+#define local_cmpxchg_unchecked(l, o, n) \
17054+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17055 /* Always has a lock prefix */
17056 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17057
17058diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17059new file mode 100644
17060index 0000000..2bfd3ba
17061--- /dev/null
17062+++ b/arch/x86/include/asm/mman.h
17063@@ -0,0 +1,15 @@
17064+#ifndef _X86_MMAN_H
17065+#define _X86_MMAN_H
17066+
17067+#include <uapi/asm/mman.h>
17068+
17069+#ifdef __KERNEL__
17070+#ifndef __ASSEMBLY__
17071+#ifdef CONFIG_X86_32
17072+#define arch_mmap_check i386_mmap_check
17073+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17074+#endif
17075+#endif
17076+#endif
17077+
17078+#endif /* X86_MMAN_H */
17079diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17080index 5f55e69..e20bfb1 100644
17081--- a/arch/x86/include/asm/mmu.h
17082+++ b/arch/x86/include/asm/mmu.h
17083@@ -9,7 +9,7 @@
17084 * we put the segment information here.
17085 */
17086 typedef struct {
17087- void *ldt;
17088+ struct desc_struct *ldt;
17089 int size;
17090
17091 #ifdef CONFIG_X86_64
17092@@ -18,7 +18,19 @@ typedef struct {
17093 #endif
17094
17095 struct mutex lock;
17096- void *vdso;
17097+ unsigned long vdso;
17098+
17099+#ifdef CONFIG_X86_32
17100+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17101+ unsigned long user_cs_base;
17102+ unsigned long user_cs_limit;
17103+
17104+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17105+ cpumask_t cpu_user_cs_mask;
17106+#endif
17107+
17108+#endif
17109+#endif
17110 } mm_context_t;
17111
17112 #ifdef CONFIG_SMP
17113diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17114index be12c53..4d24039 100644
17115--- a/arch/x86/include/asm/mmu_context.h
17116+++ b/arch/x86/include/asm/mmu_context.h
17117@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17118
17119 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17120 {
17121+
17122+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17123+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17124+ unsigned int i;
17125+ pgd_t *pgd;
17126+
17127+ pax_open_kernel();
17128+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17129+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17130+ set_pgd_batched(pgd+i, native_make_pgd(0));
17131+ pax_close_kernel();
17132+ }
17133+#endif
17134+
17135 #ifdef CONFIG_SMP
17136 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17137 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17138@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17139 struct task_struct *tsk)
17140 {
17141 unsigned cpu = smp_processor_id();
17142+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17143+ int tlbstate = TLBSTATE_OK;
17144+#endif
17145
17146 if (likely(prev != next)) {
17147 #ifdef CONFIG_SMP
17148+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17149+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17150+#endif
17151 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17152 this_cpu_write(cpu_tlbstate.active_mm, next);
17153 #endif
17154 cpumask_set_cpu(cpu, mm_cpumask(next));
17155
17156 /* Re-load page tables */
17157+#ifdef CONFIG_PAX_PER_CPU_PGD
17158+ pax_open_kernel();
17159+
17160+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17161+ if (static_cpu_has(X86_FEATURE_PCID))
17162+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17163+ else
17164+#endif
17165+
17166+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17167+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17168+ pax_close_kernel();
17169+ 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));
17170+
17171+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17172+ if (static_cpu_has(X86_FEATURE_PCID)) {
17173+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17174+ u64 descriptor[2];
17175+ descriptor[0] = PCID_USER;
17176+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17177+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17178+ descriptor[0] = PCID_KERNEL;
17179+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17180+ }
17181+ } else {
17182+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17183+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17184+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17185+ else
17186+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17187+ }
17188+ } else
17189+#endif
17190+
17191+ load_cr3(get_cpu_pgd(cpu, kernel));
17192+#else
17193 load_cr3(next->pgd);
17194+#endif
17195
17196 /* Stop flush ipis for the previous mm */
17197 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17198@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17199 /* Load the LDT, if the LDT is different: */
17200 if (unlikely(prev->context.ldt != next->context.ldt))
17201 load_LDT_nolock(&next->context);
17202+
17203+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17204+ if (!(__supported_pte_mask & _PAGE_NX)) {
17205+ smp_mb__before_clear_bit();
17206+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17207+ smp_mb__after_clear_bit();
17208+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17209+ }
17210+#endif
17211+
17212+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17213+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17214+ prev->context.user_cs_limit != next->context.user_cs_limit))
17215+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17216+#ifdef CONFIG_SMP
17217+ else if (unlikely(tlbstate != TLBSTATE_OK))
17218+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17219+#endif
17220+#endif
17221+
17222 }
17223+ else {
17224+
17225+#ifdef CONFIG_PAX_PER_CPU_PGD
17226+ pax_open_kernel();
17227+
17228+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17229+ if (static_cpu_has(X86_FEATURE_PCID))
17230+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17231+ else
17232+#endif
17233+
17234+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17235+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17236+ pax_close_kernel();
17237+ 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));
17238+
17239+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17240+ if (static_cpu_has(X86_FEATURE_PCID)) {
17241+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17242+ u64 descriptor[2];
17243+ descriptor[0] = PCID_USER;
17244+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17245+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17246+ descriptor[0] = PCID_KERNEL;
17247+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17248+ }
17249+ } else {
17250+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17251+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17252+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17253+ else
17254+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17255+ }
17256+ } else
17257+#endif
17258+
17259+ load_cr3(get_cpu_pgd(cpu, kernel));
17260+#endif
17261+
17262 #ifdef CONFIG_SMP
17263- else {
17264 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17265 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17266
17267@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17268 * tlb flush IPI delivery. We must reload CR3
17269 * to make sure to use no freed page tables.
17270 */
17271+
17272+#ifndef CONFIG_PAX_PER_CPU_PGD
17273 load_cr3(next->pgd);
17274+#endif
17275+
17276 load_LDT_nolock(&next->context);
17277+
17278+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17279+ if (!(__supported_pte_mask & _PAGE_NX))
17280+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17281+#endif
17282+
17283+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17284+#ifdef CONFIG_PAX_PAGEEXEC
17285+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17286+#endif
17287+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17288+#endif
17289+
17290 }
17291+#endif
17292 }
17293-#endif
17294 }
17295
17296 #define activate_mm(prev, next) \
17297diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17298index e3b7819..b257c64 100644
17299--- a/arch/x86/include/asm/module.h
17300+++ b/arch/x86/include/asm/module.h
17301@@ -5,6 +5,7 @@
17302
17303 #ifdef CONFIG_X86_64
17304 /* X86_64 does not define MODULE_PROC_FAMILY */
17305+#define MODULE_PROC_FAMILY ""
17306 #elif defined CONFIG_M486
17307 #define MODULE_PROC_FAMILY "486 "
17308 #elif defined CONFIG_M586
17309@@ -57,8 +58,20 @@
17310 #error unknown processor family
17311 #endif
17312
17313-#ifdef CONFIG_X86_32
17314-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17315+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17316+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17317+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17318+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17319+#else
17320+#define MODULE_PAX_KERNEXEC ""
17321 #endif
17322
17323+#ifdef CONFIG_PAX_MEMORY_UDEREF
17324+#define MODULE_PAX_UDEREF "UDEREF "
17325+#else
17326+#define MODULE_PAX_UDEREF ""
17327+#endif
17328+
17329+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17330+
17331 #endif /* _ASM_X86_MODULE_H */
17332diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17333index 5f2fc44..106caa6 100644
17334--- a/arch/x86/include/asm/nmi.h
17335+++ b/arch/x86/include/asm/nmi.h
17336@@ -36,26 +36,35 @@ enum {
17337
17338 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17339
17340+struct nmiaction;
17341+
17342+struct nmiwork {
17343+ const struct nmiaction *action;
17344+ u64 max_duration;
17345+ struct irq_work irq_work;
17346+};
17347+
17348 struct nmiaction {
17349 struct list_head list;
17350 nmi_handler_t handler;
17351- u64 max_duration;
17352- struct irq_work irq_work;
17353 unsigned long flags;
17354 const char *name;
17355-};
17356+ struct nmiwork *work;
17357+} __do_const;
17358
17359 #define register_nmi_handler(t, fn, fg, n, init...) \
17360 ({ \
17361- static struct nmiaction init fn##_na = { \
17362+ static struct nmiwork fn##_nw; \
17363+ static const struct nmiaction init fn##_na = { \
17364 .handler = (fn), \
17365 .name = (n), \
17366 .flags = (fg), \
17367+ .work = &fn##_nw, \
17368 }; \
17369 __register_nmi_handler((t), &fn##_na); \
17370 })
17371
17372-int __register_nmi_handler(unsigned int, struct nmiaction *);
17373+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17374
17375 void unregister_nmi_handler(unsigned int, const char *);
17376
17377diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17378index 775873d..04cd306 100644
17379--- a/arch/x86/include/asm/page.h
17380+++ b/arch/x86/include/asm/page.h
17381@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17382 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17383
17384 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17385+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17386
17387 #define __boot_va(x) __va(x)
17388 #define __boot_pa(x) __pa(x)
17389@@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17390 * virt_to_page(kaddr) returns a valid pointer if and only if
17391 * virt_addr_valid(kaddr) returns true.
17392 */
17393-#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17394 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17395 extern bool __virt_addr_valid(unsigned long kaddr);
17396 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17397
17398+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17399+#define virt_to_page(kaddr) \
17400+ ({ \
17401+ const void *__kaddr = (const void *)(kaddr); \
17402+ BUG_ON(!virt_addr_valid(__kaddr)); \
17403+ pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17404+ })
17405+#else
17406+#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17407+#endif
17408+
17409 #endif /* __ASSEMBLY__ */
17410
17411 #include <asm-generic/memory_model.h>
17412diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17413index 0f1ddee..e2fc3d1 100644
17414--- a/arch/x86/include/asm/page_64.h
17415+++ b/arch/x86/include/asm/page_64.h
17416@@ -7,9 +7,9 @@
17417
17418 /* duplicated to the one in bootmem.h */
17419 extern unsigned long max_pfn;
17420-extern unsigned long phys_base;
17421+extern const unsigned long phys_base;
17422
17423-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17424+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17425 {
17426 unsigned long y = x - __START_KERNEL_map;
17427
17428diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17429index cd6e1610..70f4418 100644
17430--- a/arch/x86/include/asm/paravirt.h
17431+++ b/arch/x86/include/asm/paravirt.h
17432@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17433 return (pmd_t) { ret };
17434 }
17435
17436-static inline pmdval_t pmd_val(pmd_t pmd)
17437+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17438 {
17439 pmdval_t ret;
17440
17441@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17442 val);
17443 }
17444
17445+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17446+{
17447+ pgdval_t val = native_pgd_val(pgd);
17448+
17449+ if (sizeof(pgdval_t) > sizeof(long))
17450+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17451+ val, (u64)val >> 32);
17452+ else
17453+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17454+ val);
17455+}
17456+
17457 static inline void pgd_clear(pgd_t *pgdp)
17458 {
17459 set_pgd(pgdp, __pgd(0));
17460@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17461 pv_mmu_ops.set_fixmap(idx, phys, flags);
17462 }
17463
17464+#ifdef CONFIG_PAX_KERNEXEC
17465+static inline unsigned long pax_open_kernel(void)
17466+{
17467+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17468+}
17469+
17470+static inline unsigned long pax_close_kernel(void)
17471+{
17472+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17473+}
17474+#else
17475+static inline unsigned long pax_open_kernel(void) { return 0; }
17476+static inline unsigned long pax_close_kernel(void) { return 0; }
17477+#endif
17478+
17479 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17480
17481 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17482@@ -906,7 +933,7 @@ extern void default_banner(void);
17483
17484 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17485 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17486-#define PARA_INDIRECT(addr) *%cs:addr
17487+#define PARA_INDIRECT(addr) *%ss:addr
17488 #endif
17489
17490 #define INTERRUPT_RETURN \
17491@@ -981,6 +1008,21 @@ extern void default_banner(void);
17492 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17493 CLBR_NONE, \
17494 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17495+
17496+#define GET_CR0_INTO_RDI \
17497+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17498+ mov %rax,%rdi
17499+
17500+#define SET_RDI_INTO_CR0 \
17501+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17502+
17503+#define GET_CR3_INTO_RDI \
17504+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17505+ mov %rax,%rdi
17506+
17507+#define SET_RDI_INTO_CR3 \
17508+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17509+
17510 #endif /* CONFIG_X86_32 */
17511
17512 #endif /* __ASSEMBLY__ */
17513diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17514index 7549b8b..f0edfda 100644
17515--- a/arch/x86/include/asm/paravirt_types.h
17516+++ b/arch/x86/include/asm/paravirt_types.h
17517@@ -84,7 +84,7 @@ struct pv_init_ops {
17518 */
17519 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17520 unsigned long addr, unsigned len);
17521-};
17522+} __no_const __no_randomize_layout;
17523
17524
17525 struct pv_lazy_ops {
17526@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17527 void (*enter)(void);
17528 void (*leave)(void);
17529 void (*flush)(void);
17530-};
17531+} __no_randomize_layout;
17532
17533 struct pv_time_ops {
17534 unsigned long long (*sched_clock)(void);
17535 unsigned long long (*steal_clock)(int cpu);
17536 unsigned long (*get_tsc_khz)(void);
17537-};
17538+} __no_const __no_randomize_layout;
17539
17540 struct pv_cpu_ops {
17541 /* hooks for various privileged instructions */
17542@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17543
17544 void (*start_context_switch)(struct task_struct *prev);
17545 void (*end_context_switch)(struct task_struct *next);
17546-};
17547+} __no_const __no_randomize_layout;
17548
17549 struct pv_irq_ops {
17550 /*
17551@@ -215,7 +215,7 @@ struct pv_irq_ops {
17552 #ifdef CONFIG_X86_64
17553 void (*adjust_exception_frame)(void);
17554 #endif
17555-};
17556+} __no_randomize_layout;
17557
17558 struct pv_apic_ops {
17559 #ifdef CONFIG_X86_LOCAL_APIC
17560@@ -223,7 +223,7 @@ struct pv_apic_ops {
17561 unsigned long start_eip,
17562 unsigned long start_esp);
17563 #endif
17564-};
17565+} __no_const __no_randomize_layout;
17566
17567 struct pv_mmu_ops {
17568 unsigned long (*read_cr2)(void);
17569@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17570 struct paravirt_callee_save make_pud;
17571
17572 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17573+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17574 #endif /* PAGETABLE_LEVELS == 4 */
17575 #endif /* PAGETABLE_LEVELS >= 3 */
17576
17577@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17578 an mfn. We can tell which is which from the index. */
17579 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17580 phys_addr_t phys, pgprot_t flags);
17581-};
17582+
17583+#ifdef CONFIG_PAX_KERNEXEC
17584+ unsigned long (*pax_open_kernel)(void);
17585+ unsigned long (*pax_close_kernel)(void);
17586+#endif
17587+
17588+} __no_randomize_layout;
17589
17590 struct arch_spinlock;
17591 #ifdef CONFIG_SMP
17592@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17593 struct pv_lock_ops {
17594 struct paravirt_callee_save lock_spinning;
17595 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17596-};
17597+} __no_randomize_layout;
17598
17599 /* This contains all the paravirt structures: we get a convenient
17600 * number for each function using the offset which we use to indicate
17601- * what to patch. */
17602+ * what to patch.
17603+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17604+ */
17605+
17606 struct paravirt_patch_template {
17607 struct pv_init_ops pv_init_ops;
17608 struct pv_time_ops pv_time_ops;
17609@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17610 struct pv_apic_ops pv_apic_ops;
17611 struct pv_mmu_ops pv_mmu_ops;
17612 struct pv_lock_ops pv_lock_ops;
17613-};
17614+} __no_randomize_layout;
17615
17616 extern struct pv_info pv_info;
17617 extern struct pv_init_ops pv_init_ops;
17618diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17619index c4412e9..90e88c5 100644
17620--- a/arch/x86/include/asm/pgalloc.h
17621+++ b/arch/x86/include/asm/pgalloc.h
17622@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17623 pmd_t *pmd, pte_t *pte)
17624 {
17625 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17626+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17627+}
17628+
17629+static inline void pmd_populate_user(struct mm_struct *mm,
17630+ pmd_t *pmd, pte_t *pte)
17631+{
17632+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17633 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17634 }
17635
17636@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17637
17638 #ifdef CONFIG_X86_PAE
17639 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17640+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17641+{
17642+ pud_populate(mm, pudp, pmd);
17643+}
17644 #else /* !CONFIG_X86_PAE */
17645 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17646 {
17647 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17648 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17649 }
17650+
17651+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17652+{
17653+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17654+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17655+}
17656 #endif /* CONFIG_X86_PAE */
17657
17658 #if PAGETABLE_LEVELS > 3
17659@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17660 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17661 }
17662
17663+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17664+{
17665+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17666+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17667+}
17668+
17669 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17670 {
17671 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17672diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17673index 0d193e2..bf59aeb 100644
17674--- a/arch/x86/include/asm/pgtable-2level.h
17675+++ b/arch/x86/include/asm/pgtable-2level.h
17676@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17677
17678 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17679 {
17680+ pax_open_kernel();
17681 *pmdp = pmd;
17682+ pax_close_kernel();
17683 }
17684
17685 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17686diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17687index 81bb91b..9392125 100644
17688--- a/arch/x86/include/asm/pgtable-3level.h
17689+++ b/arch/x86/include/asm/pgtable-3level.h
17690@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17691
17692 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17693 {
17694+ pax_open_kernel();
17695 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17696+ pax_close_kernel();
17697 }
17698
17699 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17700 {
17701+ pax_open_kernel();
17702 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17703+ pax_close_kernel();
17704 }
17705
17706 /*
17707diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17708index b459ddf..b44081b 100644
17709--- a/arch/x86/include/asm/pgtable.h
17710+++ b/arch/x86/include/asm/pgtable.h
17711@@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17712
17713 #ifndef __PAGETABLE_PUD_FOLDED
17714 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17715+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17716 #define pgd_clear(pgd) native_pgd_clear(pgd)
17717 #endif
17718
17719@@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17720
17721 #define arch_end_context_switch(prev) do {} while(0)
17722
17723+#define pax_open_kernel() native_pax_open_kernel()
17724+#define pax_close_kernel() native_pax_close_kernel()
17725 #endif /* CONFIG_PARAVIRT */
17726
17727+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17728+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17729+
17730+#ifdef CONFIG_PAX_KERNEXEC
17731+static inline unsigned long native_pax_open_kernel(void)
17732+{
17733+ unsigned long cr0;
17734+
17735+ preempt_disable();
17736+ barrier();
17737+ cr0 = read_cr0() ^ X86_CR0_WP;
17738+ BUG_ON(cr0 & X86_CR0_WP);
17739+ write_cr0(cr0);
17740+ return cr0 ^ X86_CR0_WP;
17741+}
17742+
17743+static inline unsigned long native_pax_close_kernel(void)
17744+{
17745+ unsigned long cr0;
17746+
17747+ cr0 = read_cr0() ^ X86_CR0_WP;
17748+ BUG_ON(!(cr0 & X86_CR0_WP));
17749+ write_cr0(cr0);
17750+ barrier();
17751+ preempt_enable_no_resched();
17752+ return cr0 ^ X86_CR0_WP;
17753+}
17754+#else
17755+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17756+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17757+#endif
17758+
17759 /*
17760 * The following only work if pte_present() is true.
17761 * Undefined behaviour if not..
17762 */
17763+static inline int pte_user(pte_t pte)
17764+{
17765+ return pte_val(pte) & _PAGE_USER;
17766+}
17767+
17768 static inline int pte_dirty(pte_t pte)
17769 {
17770 return pte_flags(pte) & _PAGE_DIRTY;
17771@@ -149,6 +189,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17772 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17773 }
17774
17775+static inline unsigned long pgd_pfn(pgd_t pgd)
17776+{
17777+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17778+}
17779+
17780 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17781
17782 static inline int pmd_large(pmd_t pte)
17783@@ -202,9 +247,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17784 return pte_clear_flags(pte, _PAGE_RW);
17785 }
17786
17787+static inline pte_t pte_mkread(pte_t pte)
17788+{
17789+ return __pte(pte_val(pte) | _PAGE_USER);
17790+}
17791+
17792 static inline pte_t pte_mkexec(pte_t pte)
17793 {
17794- return pte_clear_flags(pte, _PAGE_NX);
17795+#ifdef CONFIG_X86_PAE
17796+ if (__supported_pte_mask & _PAGE_NX)
17797+ return pte_clear_flags(pte, _PAGE_NX);
17798+ else
17799+#endif
17800+ return pte_set_flags(pte, _PAGE_USER);
17801+}
17802+
17803+static inline pte_t pte_exprotect(pte_t pte)
17804+{
17805+#ifdef CONFIG_X86_PAE
17806+ if (__supported_pte_mask & _PAGE_NX)
17807+ return pte_set_flags(pte, _PAGE_NX);
17808+ else
17809+#endif
17810+ return pte_clear_flags(pte, _PAGE_USER);
17811 }
17812
17813 static inline pte_t pte_mkdirty(pte_t pte)
17814@@ -431,6 +496,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17815 #endif
17816
17817 #ifndef __ASSEMBLY__
17818+
17819+#ifdef CONFIG_PAX_PER_CPU_PGD
17820+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17821+enum cpu_pgd_type {kernel = 0, user = 1};
17822+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17823+{
17824+ return cpu_pgd[cpu][type];
17825+}
17826+#endif
17827+
17828 #include <linux/mm_types.h>
17829 #include <linux/mmdebug.h>
17830 #include <linux/log2.h>
17831@@ -571,7 +646,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17832 * Currently stuck as a macro due to indirect forward reference to
17833 * linux/mmzone.h's __section_mem_map_addr() definition:
17834 */
17835-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17836+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17837
17838 /* Find an entry in the second-level page table.. */
17839 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17840@@ -611,7 +686,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17841 * Currently stuck as a macro due to indirect forward reference to
17842 * linux/mmzone.h's __section_mem_map_addr() definition:
17843 */
17844-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17845+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17846
17847 /* to find an entry in a page-table-directory. */
17848 static inline unsigned long pud_index(unsigned long address)
17849@@ -626,7 +701,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17850
17851 static inline int pgd_bad(pgd_t pgd)
17852 {
17853- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17854+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17855 }
17856
17857 static inline int pgd_none(pgd_t pgd)
17858@@ -649,7 +724,12 @@ static inline int pgd_none(pgd_t pgd)
17859 * pgd_offset() returns a (pgd_t *)
17860 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17861 */
17862-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17863+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17864+
17865+#ifdef CONFIG_PAX_PER_CPU_PGD
17866+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17867+#endif
17868+
17869 /*
17870 * a shortcut which implies the use of the kernel's pgd, instead
17871 * of a process's
17872@@ -660,6 +740,23 @@ static inline int pgd_none(pgd_t pgd)
17873 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17874 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17875
17876+#ifdef CONFIG_X86_32
17877+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17878+#else
17879+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17880+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17881+
17882+#ifdef CONFIG_PAX_MEMORY_UDEREF
17883+#ifdef __ASSEMBLY__
17884+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17885+#else
17886+extern unsigned long pax_user_shadow_base;
17887+extern pgdval_t clone_pgd_mask;
17888+#endif
17889+#endif
17890+
17891+#endif
17892+
17893 #ifndef __ASSEMBLY__
17894
17895 extern int direct_gbpages;
17896@@ -826,11 +923,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17897 * dst and src can be on the same page, but the range must not overlap,
17898 * and must not cross a page boundary.
17899 */
17900-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17901+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17902 {
17903- memcpy(dst, src, count * sizeof(pgd_t));
17904+ pax_open_kernel();
17905+ while (count--)
17906+ *dst++ = *src++;
17907+ pax_close_kernel();
17908 }
17909
17910+#ifdef CONFIG_PAX_PER_CPU_PGD
17911+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17912+#endif
17913+
17914+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17915+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17916+#else
17917+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17918+#endif
17919+
17920 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17921 static inline int page_level_shift(enum pg_level level)
17922 {
17923diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17924index 9ee3221..b979c6b 100644
17925--- a/arch/x86/include/asm/pgtable_32.h
17926+++ b/arch/x86/include/asm/pgtable_32.h
17927@@ -25,9 +25,6 @@
17928 struct mm_struct;
17929 struct vm_area_struct;
17930
17931-extern pgd_t swapper_pg_dir[1024];
17932-extern pgd_t initial_page_table[1024];
17933-
17934 static inline void pgtable_cache_init(void) { }
17935 static inline void check_pgt_cache(void) { }
17936 void paging_init(void);
17937@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17938 # include <asm/pgtable-2level.h>
17939 #endif
17940
17941+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17942+extern pgd_t initial_page_table[PTRS_PER_PGD];
17943+#ifdef CONFIG_X86_PAE
17944+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17945+#endif
17946+
17947 #if defined(CONFIG_HIGHPTE)
17948 #define pte_offset_map(dir, address) \
17949 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17950@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17951 /* Clear a kernel PTE and flush it from the TLB */
17952 #define kpte_clear_flush(ptep, vaddr) \
17953 do { \
17954+ pax_open_kernel(); \
17955 pte_clear(&init_mm, (vaddr), (ptep)); \
17956+ pax_close_kernel(); \
17957 __flush_tlb_one((vaddr)); \
17958 } while (0)
17959
17960 #endif /* !__ASSEMBLY__ */
17961
17962+#define HAVE_ARCH_UNMAPPED_AREA
17963+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17964+
17965 /*
17966 * kern_addr_valid() is (1) for FLATMEM and (0) for
17967 * SPARSEMEM and DISCONTIGMEM
17968diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17969index ed5903b..c7fe163 100644
17970--- a/arch/x86/include/asm/pgtable_32_types.h
17971+++ b/arch/x86/include/asm/pgtable_32_types.h
17972@@ -8,7 +8,7 @@
17973 */
17974 #ifdef CONFIG_X86_PAE
17975 # include <asm/pgtable-3level_types.h>
17976-# define PMD_SIZE (1UL << PMD_SHIFT)
17977+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17978 # define PMD_MASK (~(PMD_SIZE - 1))
17979 #else
17980 # include <asm/pgtable-2level_types.h>
17981@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17982 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17983 #endif
17984
17985+#ifdef CONFIG_PAX_KERNEXEC
17986+#ifndef __ASSEMBLY__
17987+extern unsigned char MODULES_EXEC_VADDR[];
17988+extern unsigned char MODULES_EXEC_END[];
17989+#endif
17990+#include <asm/boot.h>
17991+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17992+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17993+#else
17994+#define ktla_ktva(addr) (addr)
17995+#define ktva_ktla(addr) (addr)
17996+#endif
17997+
17998 #define MODULES_VADDR VMALLOC_START
17999 #define MODULES_END VMALLOC_END
18000 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18001diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18002index e22c1db..23a625a 100644
18003--- a/arch/x86/include/asm/pgtable_64.h
18004+++ b/arch/x86/include/asm/pgtable_64.h
18005@@ -16,10 +16,14 @@
18006
18007 extern pud_t level3_kernel_pgt[512];
18008 extern pud_t level3_ident_pgt[512];
18009+extern pud_t level3_vmalloc_start_pgt[512];
18010+extern pud_t level3_vmalloc_end_pgt[512];
18011+extern pud_t level3_vmemmap_pgt[512];
18012+extern pud_t level2_vmemmap_pgt[512];
18013 extern pmd_t level2_kernel_pgt[512];
18014 extern pmd_t level2_fixmap_pgt[512];
18015-extern pmd_t level2_ident_pgt[512];
18016-extern pgd_t init_level4_pgt[];
18017+extern pmd_t level2_ident_pgt[512*2];
18018+extern pgd_t init_level4_pgt[512];
18019
18020 #define swapper_pg_dir init_level4_pgt
18021
18022@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18023
18024 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18025 {
18026+ pax_open_kernel();
18027 *pmdp = pmd;
18028+ pax_close_kernel();
18029 }
18030
18031 static inline void native_pmd_clear(pmd_t *pmd)
18032@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18033
18034 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18035 {
18036+ pax_open_kernel();
18037 *pudp = pud;
18038+ pax_close_kernel();
18039 }
18040
18041 static inline void native_pud_clear(pud_t *pud)
18042@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18043
18044 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18045 {
18046+ pax_open_kernel();
18047+ *pgdp = pgd;
18048+ pax_close_kernel();
18049+}
18050+
18051+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18052+{
18053 *pgdp = pgd;
18054 }
18055
18056diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18057index 7166e25..baaa6fe 100644
18058--- a/arch/x86/include/asm/pgtable_64_types.h
18059+++ b/arch/x86/include/asm/pgtable_64_types.h
18060@@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18061 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18062 #define MODULES_END _AC(0xffffffffff000000, UL)
18063 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18064+#define MODULES_EXEC_VADDR MODULES_VADDR
18065+#define MODULES_EXEC_END MODULES_END
18066 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18067 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18068
18069+#define ktla_ktva(addr) (addr)
18070+#define ktva_ktla(addr) (addr)
18071+
18072 #define EARLY_DYNAMIC_PAGE_TABLES 64
18073
18074 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18075diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18076index eb3d449..8d95316 100644
18077--- a/arch/x86/include/asm/pgtable_types.h
18078+++ b/arch/x86/include/asm/pgtable_types.h
18079@@ -16,13 +16,12 @@
18080 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18081 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18082 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18083-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18084+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18085 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18086 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18087 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18088-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18089-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18090-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18091+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18092+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18093 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18094
18095 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18096@@ -40,7 +39,6 @@
18097 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18098 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18099 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18100-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18101 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18102 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18103 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18104@@ -87,8 +85,10 @@
18105
18106 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18107 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18108-#else
18109+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18110 #define _PAGE_NX (_AT(pteval_t, 0))
18111+#else
18112+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18113 #endif
18114
18115 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18116@@ -147,6 +147,9 @@
18117 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18118 _PAGE_ACCESSED)
18119
18120+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18121+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18122+
18123 #define __PAGE_KERNEL_EXEC \
18124 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18125 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18126@@ -157,7 +160,7 @@
18127 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18128 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18129 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18130-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18131+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18132 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18133 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18134 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18135@@ -214,7 +217,7 @@
18136 #ifdef CONFIG_X86_64
18137 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18138 #else
18139-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18140+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18141 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18142 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18143 #endif
18144@@ -253,7 +256,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18145 {
18146 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18147 }
18148+#endif
18149
18150+#if PAGETABLE_LEVELS == 3
18151+#include <asm-generic/pgtable-nopud.h>
18152+#endif
18153+
18154+#if PAGETABLE_LEVELS == 2
18155+#include <asm-generic/pgtable-nopmd.h>
18156+#endif
18157+
18158+#ifndef __ASSEMBLY__
18159 #if PAGETABLE_LEVELS > 3
18160 typedef struct { pudval_t pud; } pud_t;
18161
18162@@ -267,8 +280,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18163 return pud.pud;
18164 }
18165 #else
18166-#include <asm-generic/pgtable-nopud.h>
18167-
18168 static inline pudval_t native_pud_val(pud_t pud)
18169 {
18170 return native_pgd_val(pud.pgd);
18171@@ -288,8 +299,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18172 return pmd.pmd;
18173 }
18174 #else
18175-#include <asm-generic/pgtable-nopmd.h>
18176-
18177 static inline pmdval_t native_pmd_val(pmd_t pmd)
18178 {
18179 return native_pgd_val(pmd.pud.pgd);
18180@@ -329,7 +338,6 @@ typedef struct page *pgtable_t;
18181
18182 extern pteval_t __supported_pte_mask;
18183 extern void set_nx(void);
18184-extern int nx_enabled;
18185
18186 #define pgprot_writecombine pgprot_writecombine
18187 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18188diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18189index 7024c12..71c46b9 100644
18190--- a/arch/x86/include/asm/preempt.h
18191+++ b/arch/x86/include/asm/preempt.h
18192@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18193 */
18194 static __always_inline bool __preempt_count_dec_and_test(void)
18195 {
18196- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18197+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18198 }
18199
18200 /*
18201diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18202index a4ea023..33aa874 100644
18203--- a/arch/x86/include/asm/processor.h
18204+++ b/arch/x86/include/asm/processor.h
18205@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18206 /* Index into per_cpu list: */
18207 u16 cpu_index;
18208 u32 microcode;
18209-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18210+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18211
18212 #define X86_VENDOR_INTEL 0
18213 #define X86_VENDOR_CYRIX 1
18214@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18215 : "memory");
18216 }
18217
18218+/* invpcid (%rdx),%rax */
18219+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18220+
18221+#define INVPCID_SINGLE_ADDRESS 0UL
18222+#define INVPCID_SINGLE_CONTEXT 1UL
18223+#define INVPCID_ALL_GLOBAL 2UL
18224+#define INVPCID_ALL_MONGLOBAL 3UL
18225+
18226+#define PCID_KERNEL 0UL
18227+#define PCID_USER 1UL
18228+#define PCID_NOFLUSH (1UL << 63)
18229+
18230 static inline void load_cr3(pgd_t *pgdir)
18231 {
18232- write_cr3(__pa(pgdir));
18233+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18234 }
18235
18236 #ifdef CONFIG_X86_32
18237@@ -283,7 +295,7 @@ struct tss_struct {
18238
18239 } ____cacheline_aligned;
18240
18241-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18242+extern struct tss_struct init_tss[NR_CPUS];
18243
18244 /*
18245 * Save the original ist values for checking stack pointers during debugging
18246@@ -479,6 +491,7 @@ struct thread_struct {
18247 unsigned short ds;
18248 unsigned short fsindex;
18249 unsigned short gsindex;
18250+ unsigned short ss;
18251 #endif
18252 #ifdef CONFIG_X86_32
18253 unsigned long ip;
18254@@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18255 extern unsigned long mmu_cr4_features;
18256 extern u32 *trampoline_cr4_features;
18257
18258-static inline void set_in_cr4(unsigned long mask)
18259-{
18260- unsigned long cr4;
18261-
18262- mmu_cr4_features |= mask;
18263- if (trampoline_cr4_features)
18264- *trampoline_cr4_features = mmu_cr4_features;
18265- cr4 = read_cr4();
18266- cr4 |= mask;
18267- write_cr4(cr4);
18268-}
18269-
18270-static inline void clear_in_cr4(unsigned long mask)
18271-{
18272- unsigned long cr4;
18273-
18274- mmu_cr4_features &= ~mask;
18275- if (trampoline_cr4_features)
18276- *trampoline_cr4_features = mmu_cr4_features;
18277- cr4 = read_cr4();
18278- cr4 &= ~mask;
18279- write_cr4(cr4);
18280-}
18281+extern void set_in_cr4(unsigned long mask);
18282+extern void clear_in_cr4(unsigned long mask);
18283
18284 typedef struct {
18285 unsigned long seg;
18286@@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18287 */
18288 #define TASK_SIZE PAGE_OFFSET
18289 #define TASK_SIZE_MAX TASK_SIZE
18290+
18291+#ifdef CONFIG_PAX_SEGMEXEC
18292+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18293+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18294+#else
18295 #define STACK_TOP TASK_SIZE
18296-#define STACK_TOP_MAX STACK_TOP
18297+#endif
18298+
18299+#define STACK_TOP_MAX TASK_SIZE
18300
18301 #define INIT_THREAD { \
18302- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18303+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18304 .vm86_info = NULL, \
18305 .sysenter_cs = __KERNEL_CS, \
18306 .io_bitmap_ptr = NULL, \
18307@@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18308 */
18309 #define INIT_TSS { \
18310 .x86_tss = { \
18311- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18312+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18313 .ss0 = __KERNEL_DS, \
18314 .ss1 = __KERNEL_CS, \
18315 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18316@@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18317 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18318
18319 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18320-#define KSTK_TOP(info) \
18321-({ \
18322- unsigned long *__ptr = (unsigned long *)(info); \
18323- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18324-})
18325+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18326
18327 /*
18328 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18329@@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18330 #define task_pt_regs(task) \
18331 ({ \
18332 struct pt_regs *__regs__; \
18333- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18334+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18335 __regs__ - 1; \
18336 })
18337
18338@@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18339 /*
18340 * User space process size. 47bits minus one guard page.
18341 */
18342-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18343+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18344
18345 /* This decides where the kernel will search for a free chunk of vm
18346 * space during mmap's.
18347 */
18348 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18349- 0xc0000000 : 0xFFFFe000)
18350+ 0xc0000000 : 0xFFFFf000)
18351
18352 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18353 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18354@@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18355 #define STACK_TOP_MAX TASK_SIZE_MAX
18356
18357 #define INIT_THREAD { \
18358- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18359+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18360 }
18361
18362 #define INIT_TSS { \
18363- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18364+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18365 }
18366
18367 /*
18368@@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18369 */
18370 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18371
18372+#ifdef CONFIG_PAX_SEGMEXEC
18373+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18374+#endif
18375+
18376 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18377
18378 /* Get/set a process' ability to use the timestamp counter instruction */
18379@@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18380 return 0;
18381 }
18382
18383-extern unsigned long arch_align_stack(unsigned long sp);
18384+#define arch_align_stack(x) ((x) & ~0xfUL)
18385 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18386
18387 void default_idle(void);
18388@@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18389 #define xen_set_default_idle 0
18390 #endif
18391
18392-void stop_this_cpu(void *dummy);
18393+void stop_this_cpu(void *dummy) __noreturn;
18394 void df_debug(struct pt_regs *regs, long error_code);
18395 #endif /* _ASM_X86_PROCESSOR_H */
18396diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18397index 6205f0c..688a3a9 100644
18398--- a/arch/x86/include/asm/ptrace.h
18399+++ b/arch/x86/include/asm/ptrace.h
18400@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18401 }
18402
18403 /*
18404- * user_mode_vm(regs) determines whether a register set came from user mode.
18405+ * user_mode(regs) determines whether a register set came from user mode.
18406 * This is true if V8086 mode was enabled OR if the register set was from
18407 * protected mode with RPL-3 CS value. This tricky test checks that with
18408 * one comparison. Many places in the kernel can bypass this full check
18409- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18410+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18411+ * be used.
18412 */
18413-static inline int user_mode(struct pt_regs *regs)
18414+static inline int user_mode_novm(struct pt_regs *regs)
18415 {
18416 #ifdef CONFIG_X86_32
18417 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18418 #else
18419- return !!(regs->cs & 3);
18420+ return !!(regs->cs & SEGMENT_RPL_MASK);
18421 #endif
18422 }
18423
18424-static inline int user_mode_vm(struct pt_regs *regs)
18425+static inline int user_mode(struct pt_regs *regs)
18426 {
18427 #ifdef CONFIG_X86_32
18428 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18429 USER_RPL;
18430 #else
18431- return user_mode(regs);
18432+ return user_mode_novm(regs);
18433 #endif
18434 }
18435
18436@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18437 #ifdef CONFIG_X86_64
18438 static inline bool user_64bit_mode(struct pt_regs *regs)
18439 {
18440+ unsigned long cs = regs->cs & 0xffff;
18441 #ifndef CONFIG_PARAVIRT
18442 /*
18443 * On non-paravirt systems, this is the only long mode CPL 3
18444 * selector. We do not allow long mode selectors in the LDT.
18445 */
18446- return regs->cs == __USER_CS;
18447+ return cs == __USER_CS;
18448 #else
18449 /* Headers are too twisted for this to go in paravirt.h. */
18450- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18451+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18452 #endif
18453 }
18454
18455@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18456 * Traps from the kernel do not save sp and ss.
18457 * Use the helper function to retrieve sp.
18458 */
18459- if (offset == offsetof(struct pt_regs, sp) &&
18460- regs->cs == __KERNEL_CS)
18461- return kernel_stack_pointer(regs);
18462+ if (offset == offsetof(struct pt_regs, sp)) {
18463+ unsigned long cs = regs->cs & 0xffff;
18464+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18465+ return kernel_stack_pointer(regs);
18466+ }
18467 #endif
18468 return *(unsigned long *)((unsigned long)regs + offset);
18469 }
18470diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18471index 9c6b890..5305f53 100644
18472--- a/arch/x86/include/asm/realmode.h
18473+++ b/arch/x86/include/asm/realmode.h
18474@@ -22,16 +22,14 @@ struct real_mode_header {
18475 #endif
18476 /* APM/BIOS reboot */
18477 u32 machine_real_restart_asm;
18478-#ifdef CONFIG_X86_64
18479 u32 machine_real_restart_seg;
18480-#endif
18481 };
18482
18483 /* This must match data at trampoline_32/64.S */
18484 struct trampoline_header {
18485 #ifdef CONFIG_X86_32
18486 u32 start;
18487- u16 gdt_pad;
18488+ u16 boot_cs;
18489 u16 gdt_limit;
18490 u32 gdt_base;
18491 #else
18492diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18493index a82c4f1..ac45053 100644
18494--- a/arch/x86/include/asm/reboot.h
18495+++ b/arch/x86/include/asm/reboot.h
18496@@ -6,13 +6,13 @@
18497 struct pt_regs;
18498
18499 struct machine_ops {
18500- void (*restart)(char *cmd);
18501- void (*halt)(void);
18502- void (*power_off)(void);
18503+ void (* __noreturn restart)(char *cmd);
18504+ void (* __noreturn halt)(void);
18505+ void (* __noreturn power_off)(void);
18506 void (*shutdown)(void);
18507 void (*crash_shutdown)(struct pt_regs *);
18508- void (*emergency_restart)(void);
18509-};
18510+ void (* __noreturn emergency_restart)(void);
18511+} __no_const;
18512
18513 extern struct machine_ops machine_ops;
18514
18515diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18516index 8f7866a..e442f20 100644
18517--- a/arch/x86/include/asm/rmwcc.h
18518+++ b/arch/x86/include/asm/rmwcc.h
18519@@ -3,7 +3,34 @@
18520
18521 #ifdef CC_HAVE_ASM_GOTO
18522
18523-#define __GEN_RMWcc(fullop, var, cc, ...) \
18524+#ifdef CONFIG_PAX_REFCOUNT
18525+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18526+do { \
18527+ asm_volatile_goto (fullop \
18528+ ";jno 0f\n" \
18529+ fullantiop \
18530+ ";int $4\n0:\n" \
18531+ _ASM_EXTABLE(0b, 0b) \
18532+ ";j" cc " %l[cc_label]" \
18533+ : : "m" (var), ## __VA_ARGS__ \
18534+ : "memory" : cc_label); \
18535+ return 0; \
18536+cc_label: \
18537+ return 1; \
18538+} while (0)
18539+#else
18540+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18541+do { \
18542+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18543+ : : "m" (var), ## __VA_ARGS__ \
18544+ : "memory" : cc_label); \
18545+ return 0; \
18546+cc_label: \
18547+ return 1; \
18548+} while (0)
18549+#endif
18550+
18551+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18552 do { \
18553 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18554 : : "m" (var), ## __VA_ARGS__ \
18555@@ -13,15 +40,46 @@ cc_label: \
18556 return 1; \
18557 } while (0)
18558
18559-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18560- __GEN_RMWcc(op " " arg0, var, cc)
18561+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18562+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18563
18564-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18565- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18566+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18567+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18568+
18569+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18570+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18571+
18572+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18573+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18574
18575 #else /* !CC_HAVE_ASM_GOTO */
18576
18577-#define __GEN_RMWcc(fullop, var, cc, ...) \
18578+#ifdef CONFIG_PAX_REFCOUNT
18579+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18580+do { \
18581+ char c; \
18582+ asm volatile (fullop \
18583+ ";jno 0f\n" \
18584+ fullantiop \
18585+ ";int $4\n0:\n" \
18586+ _ASM_EXTABLE(0b, 0b) \
18587+ "; set" cc " %1" \
18588+ : "+m" (var), "=qm" (c) \
18589+ : __VA_ARGS__ : "memory"); \
18590+ return c != 0; \
18591+} while (0)
18592+#else
18593+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18594+do { \
18595+ char c; \
18596+ asm volatile (fullop "; set" cc " %1" \
18597+ : "+m" (var), "=qm" (c) \
18598+ : __VA_ARGS__ : "memory"); \
18599+ return c != 0; \
18600+} while (0)
18601+#endif
18602+
18603+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18604 do { \
18605 char c; \
18606 asm volatile (fullop "; set" cc " %1" \
18607@@ -30,11 +88,17 @@ do { \
18608 return c != 0; \
18609 } while (0)
18610
18611-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18612- __GEN_RMWcc(op " " arg0, var, cc)
18613+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18614+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18615+
18616+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18617+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18618+
18619+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18620+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18621
18622-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18623- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18624+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18625+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18626
18627 #endif /* CC_HAVE_ASM_GOTO */
18628
18629diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18630index cad82c9..2e5c5c1 100644
18631--- a/arch/x86/include/asm/rwsem.h
18632+++ b/arch/x86/include/asm/rwsem.h
18633@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18634 {
18635 asm volatile("# beginning down_read\n\t"
18636 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18637+
18638+#ifdef CONFIG_PAX_REFCOUNT
18639+ "jno 0f\n"
18640+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18641+ "int $4\n0:\n"
18642+ _ASM_EXTABLE(0b, 0b)
18643+#endif
18644+
18645 /* adds 0x00000001 */
18646 " jns 1f\n"
18647 " call call_rwsem_down_read_failed\n"
18648@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18649 "1:\n\t"
18650 " mov %1,%2\n\t"
18651 " add %3,%2\n\t"
18652+
18653+#ifdef CONFIG_PAX_REFCOUNT
18654+ "jno 0f\n"
18655+ "sub %3,%2\n"
18656+ "int $4\n0:\n"
18657+ _ASM_EXTABLE(0b, 0b)
18658+#endif
18659+
18660 " jle 2f\n\t"
18661 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18662 " jnz 1b\n\t"
18663@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18664 long tmp;
18665 asm volatile("# beginning down_write\n\t"
18666 LOCK_PREFIX " xadd %1,(%2)\n\t"
18667+
18668+#ifdef CONFIG_PAX_REFCOUNT
18669+ "jno 0f\n"
18670+ "mov %1,(%2)\n"
18671+ "int $4\n0:\n"
18672+ _ASM_EXTABLE(0b, 0b)
18673+#endif
18674+
18675 /* adds 0xffff0001, returns the old value */
18676 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18677 /* was the active mask 0 before? */
18678@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18679 long tmp;
18680 asm volatile("# beginning __up_read\n\t"
18681 LOCK_PREFIX " xadd %1,(%2)\n\t"
18682+
18683+#ifdef CONFIG_PAX_REFCOUNT
18684+ "jno 0f\n"
18685+ "mov %1,(%2)\n"
18686+ "int $4\n0:\n"
18687+ _ASM_EXTABLE(0b, 0b)
18688+#endif
18689+
18690 /* subtracts 1, returns the old value */
18691 " jns 1f\n\t"
18692 " call call_rwsem_wake\n" /* expects old value in %edx */
18693@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18694 long tmp;
18695 asm volatile("# beginning __up_write\n\t"
18696 LOCK_PREFIX " xadd %1,(%2)\n\t"
18697+
18698+#ifdef CONFIG_PAX_REFCOUNT
18699+ "jno 0f\n"
18700+ "mov %1,(%2)\n"
18701+ "int $4\n0:\n"
18702+ _ASM_EXTABLE(0b, 0b)
18703+#endif
18704+
18705 /* subtracts 0xffff0001, returns the old value */
18706 " jns 1f\n\t"
18707 " call call_rwsem_wake\n" /* expects old value in %edx */
18708@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18709 {
18710 asm volatile("# beginning __downgrade_write\n\t"
18711 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18712+
18713+#ifdef CONFIG_PAX_REFCOUNT
18714+ "jno 0f\n"
18715+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18716+ "int $4\n0:\n"
18717+ _ASM_EXTABLE(0b, 0b)
18718+#endif
18719+
18720 /*
18721 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18722 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18723@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18724 */
18725 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18726 {
18727- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18728+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18729+
18730+#ifdef CONFIG_PAX_REFCOUNT
18731+ "jno 0f\n"
18732+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18733+ "int $4\n0:\n"
18734+ _ASM_EXTABLE(0b, 0b)
18735+#endif
18736+
18737 : "+m" (sem->count)
18738 : "er" (delta));
18739 }
18740@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18741 */
18742 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18743 {
18744- return delta + xadd(&sem->count, delta);
18745+ return delta + xadd_check_overflow(&sem->count, delta);
18746 }
18747
18748 #endif /* __KERNEL__ */
18749diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18750index 6f1c3a8..7744f19 100644
18751--- a/arch/x86/include/asm/segment.h
18752+++ b/arch/x86/include/asm/segment.h
18753@@ -64,10 +64,15 @@
18754 * 26 - ESPFIX small SS
18755 * 27 - per-cpu [ offset to per-cpu data area ]
18756 * 28 - stack_canary-20 [ for stack protector ]
18757- * 29 - unused
18758- * 30 - unused
18759+ * 29 - PCI BIOS CS
18760+ * 30 - PCI BIOS DS
18761 * 31 - TSS for double fault handler
18762 */
18763+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18764+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18765+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18766+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18767+
18768 #define GDT_ENTRY_TLS_MIN 6
18769 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18770
18771@@ -79,6 +84,8 @@
18772
18773 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18774
18775+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18776+
18777 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18778
18779 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18780@@ -104,6 +111,12 @@
18781 #define __KERNEL_STACK_CANARY 0
18782 #endif
18783
18784+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18785+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18786+
18787+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18788+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18789+
18790 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18791
18792 /*
18793@@ -141,7 +154,7 @@
18794 */
18795
18796 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18797-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18798+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18799
18800
18801 #else
18802@@ -165,6 +178,8 @@
18803 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18804 #define __USER32_DS __USER_DS
18805
18806+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18807+
18808 #define GDT_ENTRY_TSS 8 /* needs two entries */
18809 #define GDT_ENTRY_LDT 10 /* needs two entries */
18810 #define GDT_ENTRY_TLS_MIN 12
18811@@ -173,6 +188,8 @@
18812 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18813 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18814
18815+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18816+
18817 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18818 #define FS_TLS 0
18819 #define GS_TLS 1
18820@@ -180,12 +197,14 @@
18821 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18822 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18823
18824-#define GDT_ENTRIES 16
18825+#define GDT_ENTRIES 17
18826
18827 #endif
18828
18829 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18830+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18831 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18832+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18833 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18834 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18835 #ifndef CONFIG_PARAVIRT
18836@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18837 {
18838 unsigned long __limit;
18839 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18840- return __limit + 1;
18841+ return __limit;
18842 }
18843
18844 #endif /* !__ASSEMBLY__ */
18845diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18846index 8d3120f..352b440 100644
18847--- a/arch/x86/include/asm/smap.h
18848+++ b/arch/x86/include/asm/smap.h
18849@@ -25,11 +25,40 @@
18850
18851 #include <asm/alternative-asm.h>
18852
18853+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18854+#define ASM_PAX_OPEN_USERLAND \
18855+ 661: jmp 663f; \
18856+ .pushsection .altinstr_replacement, "a" ; \
18857+ 662: pushq %rax; nop; \
18858+ .popsection ; \
18859+ .pushsection .altinstructions, "a" ; \
18860+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18861+ .popsection ; \
18862+ call __pax_open_userland; \
18863+ popq %rax; \
18864+ 663:
18865+
18866+#define ASM_PAX_CLOSE_USERLAND \
18867+ 661: jmp 663f; \
18868+ .pushsection .altinstr_replacement, "a" ; \
18869+ 662: pushq %rax; nop; \
18870+ .popsection; \
18871+ .pushsection .altinstructions, "a" ; \
18872+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18873+ .popsection; \
18874+ call __pax_close_userland; \
18875+ popq %rax; \
18876+ 663:
18877+#else
18878+#define ASM_PAX_OPEN_USERLAND
18879+#define ASM_PAX_CLOSE_USERLAND
18880+#endif
18881+
18882 #ifdef CONFIG_X86_SMAP
18883
18884 #define ASM_CLAC \
18885 661: ASM_NOP3 ; \
18886- .pushsection .altinstr_replacement, "ax" ; \
18887+ .pushsection .altinstr_replacement, "a" ; \
18888 662: __ASM_CLAC ; \
18889 .popsection ; \
18890 .pushsection .altinstructions, "a" ; \
18891@@ -38,7 +67,7 @@
18892
18893 #define ASM_STAC \
18894 661: ASM_NOP3 ; \
18895- .pushsection .altinstr_replacement, "ax" ; \
18896+ .pushsection .altinstr_replacement, "a" ; \
18897 662: __ASM_STAC ; \
18898 .popsection ; \
18899 .pushsection .altinstructions, "a" ; \
18900@@ -56,6 +85,37 @@
18901
18902 #include <asm/alternative.h>
18903
18904+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18905+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18906+
18907+extern void __pax_open_userland(void);
18908+static __always_inline unsigned long pax_open_userland(void)
18909+{
18910+
18911+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18912+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18913+ :
18914+ : [open] "i" (__pax_open_userland)
18915+ : "memory", "rax");
18916+#endif
18917+
18918+ return 0;
18919+}
18920+
18921+extern void __pax_close_userland(void);
18922+static __always_inline unsigned long pax_close_userland(void)
18923+{
18924+
18925+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18926+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18927+ :
18928+ : [close] "i" (__pax_close_userland)
18929+ : "memory", "rax");
18930+#endif
18931+
18932+ return 0;
18933+}
18934+
18935 #ifdef CONFIG_X86_SMAP
18936
18937 static __always_inline void clac(void)
18938diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18939index 8cd27e0..7f05ec8 100644
18940--- a/arch/x86/include/asm/smp.h
18941+++ b/arch/x86/include/asm/smp.h
18942@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18943 /* cpus sharing the last level cache: */
18944 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18945 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18946-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18947+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18948
18949 static inline struct cpumask *cpu_sibling_mask(int cpu)
18950 {
18951@@ -78,7 +78,7 @@ struct smp_ops {
18952
18953 void (*send_call_func_ipi)(const struct cpumask *mask);
18954 void (*send_call_func_single_ipi)(int cpu);
18955-};
18956+} __no_const;
18957
18958 /* Globals due to paravirt */
18959 extern void set_cpu_sibling_map(int cpu);
18960@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18961 extern int safe_smp_processor_id(void);
18962
18963 #elif defined(CONFIG_X86_64_SMP)
18964-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18965-
18966-#define stack_smp_processor_id() \
18967-({ \
18968- struct thread_info *ti; \
18969- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18970- ti->cpu; \
18971-})
18972+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18973+#define stack_smp_processor_id() raw_smp_processor_id()
18974 #define safe_smp_processor_id() smp_processor_id()
18975
18976 #endif
18977diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18978index 0f62f54..cb5d0dd 100644
18979--- a/arch/x86/include/asm/spinlock.h
18980+++ b/arch/x86/include/asm/spinlock.h
18981@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18982 static inline void arch_read_lock(arch_rwlock_t *rw)
18983 {
18984 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18985+
18986+#ifdef CONFIG_PAX_REFCOUNT
18987+ "jno 0f\n"
18988+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18989+ "int $4\n0:\n"
18990+ _ASM_EXTABLE(0b, 0b)
18991+#endif
18992+
18993 "jns 1f\n"
18994 "call __read_lock_failed\n\t"
18995 "1:\n"
18996@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18997 static inline void arch_write_lock(arch_rwlock_t *rw)
18998 {
18999 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19000+
19001+#ifdef CONFIG_PAX_REFCOUNT
19002+ "jno 0f\n"
19003+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19004+ "int $4\n0:\n"
19005+ _ASM_EXTABLE(0b, 0b)
19006+#endif
19007+
19008 "jz 1f\n"
19009 "call __write_lock_failed\n\t"
19010 "1:\n"
19011@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19012
19013 static inline void arch_read_unlock(arch_rwlock_t *rw)
19014 {
19015- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19016+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19017+
19018+#ifdef CONFIG_PAX_REFCOUNT
19019+ "jno 0f\n"
19020+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19021+ "int $4\n0:\n"
19022+ _ASM_EXTABLE(0b, 0b)
19023+#endif
19024+
19025 :"+m" (rw->lock) : : "memory");
19026 }
19027
19028 static inline void arch_write_unlock(arch_rwlock_t *rw)
19029 {
19030- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19031+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19032+
19033+#ifdef CONFIG_PAX_REFCOUNT
19034+ "jno 0f\n"
19035+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19036+ "int $4\n0:\n"
19037+ _ASM_EXTABLE(0b, 0b)
19038+#endif
19039+
19040 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19041 }
19042
19043diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19044index 6a99859..03cb807 100644
19045--- a/arch/x86/include/asm/stackprotector.h
19046+++ b/arch/x86/include/asm/stackprotector.h
19047@@ -47,7 +47,7 @@
19048 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19049 */
19050 #define GDT_STACK_CANARY_INIT \
19051- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19052+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19053
19054 /*
19055 * Initialize the stackprotector canary value.
19056@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19057
19058 static inline void load_stack_canary_segment(void)
19059 {
19060-#ifdef CONFIG_X86_32
19061+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19062 asm volatile ("mov %0, %%gs" : : "r" (0));
19063 #endif
19064 }
19065diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19066index 70bbe39..4ae2bd4 100644
19067--- a/arch/x86/include/asm/stacktrace.h
19068+++ b/arch/x86/include/asm/stacktrace.h
19069@@ -11,28 +11,20 @@
19070
19071 extern int kstack_depth_to_print;
19072
19073-struct thread_info;
19074+struct task_struct;
19075 struct stacktrace_ops;
19076
19077-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19078- unsigned long *stack,
19079- unsigned long bp,
19080- const struct stacktrace_ops *ops,
19081- void *data,
19082- unsigned long *end,
19083- int *graph);
19084+typedef unsigned long walk_stack_t(struct task_struct *task,
19085+ void *stack_start,
19086+ unsigned long *stack,
19087+ unsigned long bp,
19088+ const struct stacktrace_ops *ops,
19089+ void *data,
19090+ unsigned long *end,
19091+ int *graph);
19092
19093-extern unsigned long
19094-print_context_stack(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-
19099-extern unsigned long
19100-print_context_stack_bp(struct thread_info *tinfo,
19101- unsigned long *stack, unsigned long bp,
19102- const struct stacktrace_ops *ops, void *data,
19103- unsigned long *end, int *graph);
19104+extern walk_stack_t print_context_stack;
19105+extern walk_stack_t print_context_stack_bp;
19106
19107 /* Generic stack tracer with callbacks */
19108
19109@@ -40,7 +32,7 @@ struct stacktrace_ops {
19110 void (*address)(void *data, unsigned long address, int reliable);
19111 /* On negative return stop dumping */
19112 int (*stack)(void *data, char *name);
19113- walk_stack_t walk_stack;
19114+ walk_stack_t *walk_stack;
19115 };
19116
19117 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19118diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19119index d7f3b3b..3cc39f1 100644
19120--- a/arch/x86/include/asm/switch_to.h
19121+++ b/arch/x86/include/asm/switch_to.h
19122@@ -108,7 +108,7 @@ do { \
19123 "call __switch_to\n\t" \
19124 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19125 __switch_canary \
19126- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19127+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19128 "movq %%rax,%%rdi\n\t" \
19129 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19130 "jnz ret_from_fork\n\t" \
19131@@ -119,7 +119,7 @@ do { \
19132 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19133 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19134 [_tif_fork] "i" (_TIF_FORK), \
19135- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19136+ [thread_info] "m" (current_tinfo), \
19137 [current_task] "m" (current_task) \
19138 __switch_canary_iparam \
19139 : "memory", "cc" __EXTRA_CLOBBER)
19140diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19141index 47e5de2..d3dda54 100644
19142--- a/arch/x86/include/asm/thread_info.h
19143+++ b/arch/x86/include/asm/thread_info.h
19144@@ -24,7 +24,6 @@ struct exec_domain;
19145 #include <linux/atomic.h>
19146
19147 struct thread_info {
19148- struct task_struct *task; /* main task structure */
19149 struct exec_domain *exec_domain; /* execution domain */
19150 __u32 flags; /* low level flags */
19151 __u32 status; /* thread synchronous flags */
19152@@ -33,13 +32,13 @@ struct thread_info {
19153 mm_segment_t addr_limit;
19154 struct restart_block restart_block;
19155 void __user *sysenter_return;
19156+ unsigned long lowest_stack;
19157 unsigned int sig_on_uaccess_error:1;
19158 unsigned int uaccess_err:1; /* uaccess failed */
19159 };
19160
19161-#define INIT_THREAD_INFO(tsk) \
19162+#define INIT_THREAD_INFO \
19163 { \
19164- .task = &tsk, \
19165 .exec_domain = &default_exec_domain, \
19166 .flags = 0, \
19167 .cpu = 0, \
19168@@ -50,7 +49,7 @@ struct thread_info {
19169 }, \
19170 }
19171
19172-#define init_thread_info (init_thread_union.thread_info)
19173+#define init_thread_info (init_thread_union.stack)
19174 #define init_stack (init_thread_union.stack)
19175
19176 #else /* !__ASSEMBLY__ */
19177@@ -90,6 +89,7 @@ struct thread_info {
19178 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19179 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19180 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19181+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19182
19183 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19184 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19185@@ -113,17 +113,18 @@ struct thread_info {
19186 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19187 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19188 #define _TIF_X32 (1 << TIF_X32)
19189+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19190
19191 /* work to do in syscall_trace_enter() */
19192 #define _TIF_WORK_SYSCALL_ENTRY \
19193 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19194 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19195- _TIF_NOHZ)
19196+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19197
19198 /* work to do in syscall_trace_leave() */
19199 #define _TIF_WORK_SYSCALL_EXIT \
19200 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19201- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19202+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19203
19204 /* work to do on interrupt/exception return */
19205 #define _TIF_WORK_MASK \
19206@@ -134,7 +135,7 @@ struct thread_info {
19207 /* work to do on any return to user space */
19208 #define _TIF_ALLWORK_MASK \
19209 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19210- _TIF_NOHZ)
19211+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19212
19213 /* Only used for 64 bit */
19214 #define _TIF_DO_NOTIFY_MASK \
19215@@ -149,7 +150,6 @@ struct thread_info {
19216 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19217
19218 #define STACK_WARN (THREAD_SIZE/8)
19219-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19220
19221 /*
19222 * macros/functions for gaining access to the thread information structure
19223@@ -160,26 +160,18 @@ struct thread_info {
19224
19225 DECLARE_PER_CPU(unsigned long, kernel_stack);
19226
19227+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19228+
19229 static inline struct thread_info *current_thread_info(void)
19230 {
19231- struct thread_info *ti;
19232- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19233- KERNEL_STACK_OFFSET - THREAD_SIZE);
19234- return ti;
19235+ return this_cpu_read_stable(current_tinfo);
19236 }
19237
19238 #else /* !__ASSEMBLY__ */
19239
19240 /* how to get the thread information struct from ASM */
19241 #define GET_THREAD_INFO(reg) \
19242- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19243- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19244-
19245-/*
19246- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19247- * a certain register (to be used in assembler memory operands).
19248- */
19249-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19250+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19251
19252 #endif
19253
19254@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19255 extern void arch_task_cache_init(void);
19256 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19257 extern void arch_release_task_struct(struct task_struct *tsk);
19258+
19259+#define __HAVE_THREAD_FUNCTIONS
19260+#define task_thread_info(task) (&(task)->tinfo)
19261+#define task_stack_page(task) ((task)->stack)
19262+#define setup_thread_stack(p, org) do {} while (0)
19263+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19264+
19265 #endif
19266 #endif /* _ASM_X86_THREAD_INFO_H */
19267diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19268index 04905bf..49203ca 100644
19269--- a/arch/x86/include/asm/tlbflush.h
19270+++ b/arch/x86/include/asm/tlbflush.h
19271@@ -17,18 +17,44 @@
19272
19273 static inline void __native_flush_tlb(void)
19274 {
19275+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19276+ u64 descriptor[2];
19277+
19278+ descriptor[0] = PCID_KERNEL;
19279+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19280+ return;
19281+ }
19282+
19283+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19284+ if (static_cpu_has(X86_FEATURE_PCID)) {
19285+ unsigned int cpu = raw_get_cpu();
19286+
19287+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19288+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19289+ raw_put_cpu_no_resched();
19290+ return;
19291+ }
19292+#endif
19293+
19294 native_write_cr3(native_read_cr3());
19295 }
19296
19297 static inline void __native_flush_tlb_global_irq_disabled(void)
19298 {
19299- unsigned long cr4;
19300+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19301+ u64 descriptor[2];
19302
19303- cr4 = native_read_cr4();
19304- /* clear PGE */
19305- native_write_cr4(cr4 & ~X86_CR4_PGE);
19306- /* write old PGE again and flush TLBs */
19307- native_write_cr4(cr4);
19308+ descriptor[0] = PCID_KERNEL;
19309+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19310+ } else {
19311+ unsigned long cr4;
19312+
19313+ cr4 = native_read_cr4();
19314+ /* clear PGE */
19315+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19316+ /* write old PGE again and flush TLBs */
19317+ native_write_cr4(cr4);
19318+ }
19319 }
19320
19321 static inline void __native_flush_tlb_global(void)
19322@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19323
19324 static inline void __native_flush_tlb_single(unsigned long addr)
19325 {
19326+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19327+ u64 descriptor[2];
19328+
19329+ descriptor[0] = PCID_KERNEL;
19330+ descriptor[1] = addr;
19331+
19332+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19333+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19334+ if (addr < TASK_SIZE_MAX)
19335+ descriptor[1] += pax_user_shadow_base;
19336+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19337+ }
19338+
19339+ descriptor[0] = PCID_USER;
19340+ descriptor[1] = addr;
19341+#endif
19342+
19343+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19344+ return;
19345+ }
19346+
19347+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19348+ if (static_cpu_has(X86_FEATURE_PCID)) {
19349+ unsigned int cpu = raw_get_cpu();
19350+
19351+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19352+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19353+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19354+ raw_put_cpu_no_resched();
19355+
19356+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19357+ addr += pax_user_shadow_base;
19358+ }
19359+#endif
19360+
19361 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19362 }
19363
19364diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19365index 0d592e0..526f797 100644
19366--- a/arch/x86/include/asm/uaccess.h
19367+++ b/arch/x86/include/asm/uaccess.h
19368@@ -7,6 +7,7 @@
19369 #include <linux/compiler.h>
19370 #include <linux/thread_info.h>
19371 #include <linux/string.h>
19372+#include <linux/spinlock.h>
19373 #include <asm/asm.h>
19374 #include <asm/page.h>
19375 #include <asm/smap.h>
19376@@ -29,7 +30,12 @@
19377
19378 #define get_ds() (KERNEL_DS)
19379 #define get_fs() (current_thread_info()->addr_limit)
19380+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19381+void __set_fs(mm_segment_t x);
19382+void set_fs(mm_segment_t x);
19383+#else
19384 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19385+#endif
19386
19387 #define segment_eq(a, b) ((a).seg == (b).seg)
19388
19389@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19390 * checks that the pointer is in the user space range - after calling
19391 * this function, memory access functions may still return -EFAULT.
19392 */
19393-#define access_ok(type, addr, size) \
19394- likely(!__range_not_ok(addr, size, user_addr_max()))
19395+extern int _cond_resched(void);
19396+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19397+#define access_ok(type, addr, size) \
19398+({ \
19399+ unsigned long __size = size; \
19400+ unsigned long __addr = (unsigned long)addr; \
19401+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19402+ if (__ret_ao && __size) { \
19403+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19404+ unsigned long __end_ao = __addr + __size - 1; \
19405+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19406+ while (__addr_ao <= __end_ao) { \
19407+ char __c_ao; \
19408+ __addr_ao += PAGE_SIZE; \
19409+ if (__size > PAGE_SIZE) \
19410+ _cond_resched(); \
19411+ if (__get_user(__c_ao, (char __user *)__addr)) \
19412+ break; \
19413+ if (type != VERIFY_WRITE) { \
19414+ __addr = __addr_ao; \
19415+ continue; \
19416+ } \
19417+ if (__put_user(__c_ao, (char __user *)__addr)) \
19418+ break; \
19419+ __addr = __addr_ao; \
19420+ } \
19421+ } \
19422+ } \
19423+ __ret_ao; \
19424+})
19425
19426 /*
19427 * The exception table consists of pairs of addresses relative to the
19428@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19429 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19430 __chk_user_ptr(ptr); \
19431 might_fault(); \
19432+ pax_open_userland(); \
19433 asm volatile("call __get_user_%P3" \
19434 : "=a" (__ret_gu), "=r" (__val_gu) \
19435 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19436 (x) = (__typeof__(*(ptr))) __val_gu; \
19437+ pax_close_userland(); \
19438 __ret_gu; \
19439 })
19440
19441@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19442 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19443 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19444
19445-
19446+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19447+#define __copyuser_seg "gs;"
19448+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19449+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19450+#else
19451+#define __copyuser_seg
19452+#define __COPYUSER_SET_ES
19453+#define __COPYUSER_RESTORE_ES
19454+#endif
19455
19456 #ifdef CONFIG_X86_32
19457 #define __put_user_asm_u64(x, addr, err, errret) \
19458 asm volatile(ASM_STAC "\n" \
19459- "1: movl %%eax,0(%2)\n" \
19460- "2: movl %%edx,4(%2)\n" \
19461+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19462+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19463 "3: " ASM_CLAC "\n" \
19464 ".section .fixup,\"ax\"\n" \
19465 "4: movl %3,%0\n" \
19466@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19467
19468 #define __put_user_asm_ex_u64(x, addr) \
19469 asm volatile(ASM_STAC "\n" \
19470- "1: movl %%eax,0(%1)\n" \
19471- "2: movl %%edx,4(%1)\n" \
19472+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19473+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19474 "3: " ASM_CLAC "\n" \
19475 _ASM_EXTABLE_EX(1b, 2b) \
19476 _ASM_EXTABLE_EX(2b, 3b) \
19477@@ -257,7 +301,8 @@ extern void __put_user_8(void);
19478 __typeof__(*(ptr)) __pu_val; \
19479 __chk_user_ptr(ptr); \
19480 might_fault(); \
19481- __pu_val = x; \
19482+ __pu_val = (x); \
19483+ pax_open_userland(); \
19484 switch (sizeof(*(ptr))) { \
19485 case 1: \
19486 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19487@@ -275,6 +320,7 @@ extern void __put_user_8(void);
19488 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19489 break; \
19490 } \
19491+ pax_close_userland(); \
19492 __ret_pu; \
19493 })
19494
19495@@ -355,8 +401,10 @@ do { \
19496 } while (0)
19497
19498 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19499+do { \
19500+ pax_open_userland(); \
19501 asm volatile(ASM_STAC "\n" \
19502- "1: mov"itype" %2,%"rtype"1\n" \
19503+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19504 "2: " ASM_CLAC "\n" \
19505 ".section .fixup,\"ax\"\n" \
19506 "3: mov %3,%0\n" \
19507@@ -364,8 +412,10 @@ do { \
19508 " jmp 2b\n" \
19509 ".previous\n" \
19510 _ASM_EXTABLE(1b, 3b) \
19511- : "=r" (err), ltype(x) \
19512- : "m" (__m(addr)), "i" (errret), "0" (err))
19513+ : "=r" (err), ltype (x) \
19514+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19515+ pax_close_userland(); \
19516+} while (0)
19517
19518 #define __get_user_size_ex(x, ptr, size) \
19519 do { \
19520@@ -389,7 +439,7 @@ do { \
19521 } while (0)
19522
19523 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19524- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19525+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19526 "2:\n" \
19527 _ASM_EXTABLE_EX(1b, 2b) \
19528 : ltype(x) : "m" (__m(addr)))
19529@@ -406,13 +456,24 @@ do { \
19530 int __gu_err; \
19531 unsigned long __gu_val; \
19532 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19533- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19534+ (x) = (__typeof__(*(ptr)))__gu_val; \
19535 __gu_err; \
19536 })
19537
19538 /* FIXME: this hack is definitely wrong -AK */
19539 struct __large_struct { unsigned long buf[100]; };
19540-#define __m(x) (*(struct __large_struct __user *)(x))
19541+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19542+#define ____m(x) \
19543+({ \
19544+ unsigned long ____x = (unsigned long)(x); \
19545+ if (____x < pax_user_shadow_base) \
19546+ ____x += pax_user_shadow_base; \
19547+ (typeof(x))____x; \
19548+})
19549+#else
19550+#define ____m(x) (x)
19551+#endif
19552+#define __m(x) (*(struct __large_struct __user *)____m(x))
19553
19554 /*
19555 * Tell gcc we read from memory instead of writing: this is because
19556@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19557 * aliasing issues.
19558 */
19559 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19560+do { \
19561+ pax_open_userland(); \
19562 asm volatile(ASM_STAC "\n" \
19563- "1: mov"itype" %"rtype"1,%2\n" \
19564+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19565 "2: " ASM_CLAC "\n" \
19566 ".section .fixup,\"ax\"\n" \
19567 "3: mov %3,%0\n" \
19568@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19569 ".previous\n" \
19570 _ASM_EXTABLE(1b, 3b) \
19571 : "=r"(err) \
19572- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19573+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19574+ pax_close_userland(); \
19575+} while (0)
19576
19577 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19578- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19579+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19580 "2:\n" \
19581 _ASM_EXTABLE_EX(1b, 2b) \
19582 : : ltype(x), "m" (__m(addr)))
19583@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19584 */
19585 #define uaccess_try do { \
19586 current_thread_info()->uaccess_err = 0; \
19587+ pax_open_userland(); \
19588 stac(); \
19589 barrier();
19590
19591 #define uaccess_catch(err) \
19592 clac(); \
19593+ pax_close_userland(); \
19594 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19595 } while (0)
19596
19597@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19598 * On error, the variable @x is set to zero.
19599 */
19600
19601+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19602+#define __get_user(x, ptr) get_user((x), (ptr))
19603+#else
19604 #define __get_user(x, ptr) \
19605 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19606+#endif
19607
19608 /**
19609 * __put_user: - Write a simple value into user space, with less checking.
19610@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19611 * Returns zero on success, or -EFAULT on error.
19612 */
19613
19614+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19615+#define __put_user(x, ptr) put_user((x), (ptr))
19616+#else
19617 #define __put_user(x, ptr) \
19618 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19619+#endif
19620
19621 #define __get_user_unaligned __get_user
19622 #define __put_user_unaligned __put_user
19623@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19624 #define get_user_ex(x, ptr) do { \
19625 unsigned long __gue_val; \
19626 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19627- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19628+ (x) = (__typeof__(*(ptr)))__gue_val; \
19629 } while (0)
19630
19631 #define put_user_try uaccess_try
19632@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19633 __typeof__(ptr) __uval = (uval); \
19634 __typeof__(*(ptr)) __old = (old); \
19635 __typeof__(*(ptr)) __new = (new); \
19636+ pax_open_userland(); \
19637 switch (size) { \
19638 case 1: \
19639 { \
19640 asm volatile("\t" ASM_STAC "\n" \
19641- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19642+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19643 "2:\t" ASM_CLAC "\n" \
19644 "\t.section .fixup, \"ax\"\n" \
19645 "3:\tmov %3, %0\n" \
19646 "\tjmp 2b\n" \
19647 "\t.previous\n" \
19648 _ASM_EXTABLE(1b, 3b) \
19649- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19650+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19651 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19652 : "memory" \
19653 ); \
19654@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19655 case 2: \
19656 { \
19657 asm volatile("\t" ASM_STAC "\n" \
19658- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19659+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19660 "2:\t" ASM_CLAC "\n" \
19661 "\t.section .fixup, \"ax\"\n" \
19662 "3:\tmov %3, %0\n" \
19663 "\tjmp 2b\n" \
19664 "\t.previous\n" \
19665 _ASM_EXTABLE(1b, 3b) \
19666- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19667+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19668 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19669 : "memory" \
19670 ); \
19671@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19672 case 4: \
19673 { \
19674 asm volatile("\t" ASM_STAC "\n" \
19675- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19676+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19677 "2:\t" ASM_CLAC "\n" \
19678 "\t.section .fixup, \"ax\"\n" \
19679 "3:\tmov %3, %0\n" \
19680 "\tjmp 2b\n" \
19681 "\t.previous\n" \
19682 _ASM_EXTABLE(1b, 3b) \
19683- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19684+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19685 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19686 : "memory" \
19687 ); \
19688@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19689 __cmpxchg_wrong_size(); \
19690 \
19691 asm volatile("\t" ASM_STAC "\n" \
19692- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19693+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19694 "2:\t" ASM_CLAC "\n" \
19695 "\t.section .fixup, \"ax\"\n" \
19696 "3:\tmov %3, %0\n" \
19697 "\tjmp 2b\n" \
19698 "\t.previous\n" \
19699 _ASM_EXTABLE(1b, 3b) \
19700- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19701+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19702 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19703 : "memory" \
19704 ); \
19705@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19706 default: \
19707 __cmpxchg_wrong_size(); \
19708 } \
19709+ pax_close_userland(); \
19710 *__uval = __old; \
19711 __ret; \
19712 })
19713@@ -636,17 +713,6 @@ extern struct movsl_mask {
19714
19715 #define ARCH_HAS_NOCACHE_UACCESS 1
19716
19717-#ifdef CONFIG_X86_32
19718-# include <asm/uaccess_32.h>
19719-#else
19720-# include <asm/uaccess_64.h>
19721-#endif
19722-
19723-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19724- unsigned n);
19725-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19726- unsigned n);
19727-
19728 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19729 # define copy_user_diag __compiletime_error
19730 #else
19731@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19732 extern void copy_user_diag("copy_from_user() buffer size is too small")
19733 copy_from_user_overflow(void);
19734 extern void copy_user_diag("copy_to_user() buffer size is too small")
19735-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19736+copy_to_user_overflow(void);
19737
19738 #undef copy_user_diag
19739
19740@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19741
19742 extern void
19743 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19744-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19745+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19746 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19747
19748 #else
19749@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19750
19751 #endif
19752
19753+#ifdef CONFIG_X86_32
19754+# include <asm/uaccess_32.h>
19755+#else
19756+# include <asm/uaccess_64.h>
19757+#endif
19758+
19759 static inline unsigned long __must_check
19760 copy_from_user(void *to, const void __user *from, unsigned long n)
19761 {
19762- int sz = __compiletime_object_size(to);
19763+ size_t sz = __compiletime_object_size(to);
19764
19765 might_fault();
19766
19767@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19768 * case, and do only runtime checking for non-constant sizes.
19769 */
19770
19771- if (likely(sz < 0 || sz >= n))
19772- n = _copy_from_user(to, from, n);
19773- else if(__builtin_constant_p(n))
19774- copy_from_user_overflow();
19775- else
19776- __copy_from_user_overflow(sz, n);
19777+ if (likely(sz != (size_t)-1 && sz < n)) {
19778+ if(__builtin_constant_p(n))
19779+ copy_from_user_overflow();
19780+ else
19781+ __copy_from_user_overflow(sz, n);
19782+ } else if (access_ok(VERIFY_READ, from, n))
19783+ n = __copy_from_user(to, from, n);
19784+ else if ((long)n > 0)
19785+ memset(to, 0, n);
19786
19787 return n;
19788 }
19789@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19790 static inline unsigned long __must_check
19791 copy_to_user(void __user *to, const void *from, unsigned long n)
19792 {
19793- int sz = __compiletime_object_size(from);
19794+ size_t sz = __compiletime_object_size(from);
19795
19796 might_fault();
19797
19798 /* See the comment in copy_from_user() above. */
19799- if (likely(sz < 0 || sz >= n))
19800- n = _copy_to_user(to, from, n);
19801- else if(__builtin_constant_p(n))
19802- copy_to_user_overflow();
19803- else
19804- __copy_to_user_overflow(sz, n);
19805+ if (likely(sz != (size_t)-1 && sz < n)) {
19806+ if(__builtin_constant_p(n))
19807+ copy_to_user_overflow();
19808+ else
19809+ __copy_to_user_overflow(sz, n);
19810+ } else if (access_ok(VERIFY_WRITE, to, n))
19811+ n = __copy_to_user(to, from, n);
19812
19813 return n;
19814 }
19815diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19816index 3c03a5d..1071638 100644
19817--- a/arch/x86/include/asm/uaccess_32.h
19818+++ b/arch/x86/include/asm/uaccess_32.h
19819@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19820 static __always_inline unsigned long __must_check
19821 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19822 {
19823+ if ((long)n < 0)
19824+ return n;
19825+
19826+ check_object_size(from, n, true);
19827+
19828 if (__builtin_constant_p(n)) {
19829 unsigned long ret;
19830
19831@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19832 __copy_to_user(void __user *to, const void *from, unsigned long n)
19833 {
19834 might_fault();
19835+
19836 return __copy_to_user_inatomic(to, from, n);
19837 }
19838
19839 static __always_inline unsigned long
19840 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19841 {
19842+ if ((long)n < 0)
19843+ return n;
19844+
19845 /* Avoid zeroing the tail if the copy fails..
19846 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19847 * but as the zeroing behaviour is only significant when n is not
19848@@ -137,6 +146,12 @@ static __always_inline unsigned long
19849 __copy_from_user(void *to, const void __user *from, unsigned long n)
19850 {
19851 might_fault();
19852+
19853+ if ((long)n < 0)
19854+ return n;
19855+
19856+ check_object_size(to, n, false);
19857+
19858 if (__builtin_constant_p(n)) {
19859 unsigned long ret;
19860
19861@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19862 const void __user *from, unsigned long n)
19863 {
19864 might_fault();
19865+
19866+ if ((long)n < 0)
19867+ return n;
19868+
19869 if (__builtin_constant_p(n)) {
19870 unsigned long ret;
19871
19872@@ -181,7 +200,10 @@ static __always_inline unsigned long
19873 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19874 unsigned long n)
19875 {
19876- return __copy_from_user_ll_nocache_nozero(to, from, n);
19877+ if ((long)n < 0)
19878+ return n;
19879+
19880+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19881 }
19882
19883 #endif /* _ASM_X86_UACCESS_32_H */
19884diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19885index 12a26b9..206c200 100644
19886--- a/arch/x86/include/asm/uaccess_64.h
19887+++ b/arch/x86/include/asm/uaccess_64.h
19888@@ -10,6 +10,9 @@
19889 #include <asm/alternative.h>
19890 #include <asm/cpufeature.h>
19891 #include <asm/page.h>
19892+#include <asm/pgtable.h>
19893+
19894+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19895
19896 /*
19897 * Copy To/From Userspace
19898@@ -17,14 +20,14 @@
19899
19900 /* Handles exceptions in both to and from, but doesn't do access_ok */
19901 __must_check unsigned long
19902-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19903+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19904 __must_check unsigned long
19905-copy_user_generic_string(void *to, const void *from, unsigned len);
19906+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19907 __must_check unsigned long
19908-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19909+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19910
19911 static __always_inline __must_check unsigned long
19912-copy_user_generic(void *to, const void *from, unsigned len)
19913+copy_user_generic(void *to, const void *from, unsigned long len)
19914 {
19915 unsigned ret;
19916
19917@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19918 }
19919
19920 __must_check unsigned long
19921-copy_in_user(void __user *to, const void __user *from, unsigned len);
19922+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19923
19924 static __always_inline __must_check
19925-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19926+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19927 {
19928- int ret = 0;
19929+ size_t sz = __compiletime_object_size(dst);
19930+ unsigned ret = 0;
19931+
19932+ if (size > INT_MAX)
19933+ return size;
19934+
19935+ check_object_size(dst, size, false);
19936+
19937+#ifdef CONFIG_PAX_MEMORY_UDEREF
19938+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19939+ return size;
19940+#endif
19941+
19942+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19943+ if(__builtin_constant_p(size))
19944+ copy_from_user_overflow();
19945+ else
19946+ __copy_from_user_overflow(sz, size);
19947+ return size;
19948+ }
19949
19950 if (!__builtin_constant_p(size))
19951- return copy_user_generic(dst, (__force void *)src, size);
19952+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19953 switch (size) {
19954- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19955+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19956 ret, "b", "b", "=q", 1);
19957 return ret;
19958- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19959+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19960 ret, "w", "w", "=r", 2);
19961 return ret;
19962- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19963+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19964 ret, "l", "k", "=r", 4);
19965 return ret;
19966- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19967+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19968 ret, "q", "", "=r", 8);
19969 return ret;
19970 case 10:
19971- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19972+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19973 ret, "q", "", "=r", 10);
19974 if (unlikely(ret))
19975 return ret;
19976 __get_user_asm(*(u16 *)(8 + (char *)dst),
19977- (u16 __user *)(8 + (char __user *)src),
19978+ (const u16 __user *)(8 + (const char __user *)src),
19979 ret, "w", "w", "=r", 2);
19980 return ret;
19981 case 16:
19982- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19983+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19984 ret, "q", "", "=r", 16);
19985 if (unlikely(ret))
19986 return ret;
19987 __get_user_asm(*(u64 *)(8 + (char *)dst),
19988- (u64 __user *)(8 + (char __user *)src),
19989+ (const u64 __user *)(8 + (const char __user *)src),
19990 ret, "q", "", "=r", 8);
19991 return ret;
19992 default:
19993- return copy_user_generic(dst, (__force void *)src, size);
19994+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19995 }
19996 }
19997
19998 static __always_inline __must_check
19999-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20000+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20001 {
20002 might_fault();
20003 return __copy_from_user_nocheck(dst, src, size);
20004 }
20005
20006 static __always_inline __must_check
20007-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20008+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20009 {
20010- int ret = 0;
20011+ size_t sz = __compiletime_object_size(src);
20012+ unsigned ret = 0;
20013+
20014+ if (size > INT_MAX)
20015+ return size;
20016+
20017+ check_object_size(src, size, true);
20018+
20019+#ifdef CONFIG_PAX_MEMORY_UDEREF
20020+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20021+ return size;
20022+#endif
20023+
20024+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20025+ if(__builtin_constant_p(size))
20026+ copy_to_user_overflow();
20027+ else
20028+ __copy_to_user_overflow(sz, size);
20029+ return size;
20030+ }
20031
20032 if (!__builtin_constant_p(size))
20033- return copy_user_generic((__force void *)dst, src, size);
20034+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20035 switch (size) {
20036- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20037+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20038 ret, "b", "b", "iq", 1);
20039 return ret;
20040- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20041+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20042 ret, "w", "w", "ir", 2);
20043 return ret;
20044- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20045+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20046 ret, "l", "k", "ir", 4);
20047 return ret;
20048- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20049+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20050 ret, "q", "", "er", 8);
20051 return ret;
20052 case 10:
20053- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20054+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20055 ret, "q", "", "er", 10);
20056 if (unlikely(ret))
20057 return ret;
20058 asm("":::"memory");
20059- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20060+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20061 ret, "w", "w", "ir", 2);
20062 return ret;
20063 case 16:
20064- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20065+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20066 ret, "q", "", "er", 16);
20067 if (unlikely(ret))
20068 return ret;
20069 asm("":::"memory");
20070- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20071+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20072 ret, "q", "", "er", 8);
20073 return ret;
20074 default:
20075- return copy_user_generic((__force void *)dst, src, size);
20076+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20077 }
20078 }
20079
20080 static __always_inline __must_check
20081-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20082+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20083 {
20084 might_fault();
20085 return __copy_to_user_nocheck(dst, src, size);
20086 }
20087
20088 static __always_inline __must_check
20089-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20090+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20091 {
20092- int ret = 0;
20093+ unsigned ret = 0;
20094
20095 might_fault();
20096+
20097+ if (size > INT_MAX)
20098+ return size;
20099+
20100+#ifdef CONFIG_PAX_MEMORY_UDEREF
20101+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20102+ return size;
20103+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20104+ return size;
20105+#endif
20106+
20107 if (!__builtin_constant_p(size))
20108- return copy_user_generic((__force void *)dst,
20109- (__force void *)src, size);
20110+ return copy_user_generic((__force_kernel void *)____m(dst),
20111+ (__force_kernel const void *)____m(src), size);
20112 switch (size) {
20113 case 1: {
20114 u8 tmp;
20115- __get_user_asm(tmp, (u8 __user *)src,
20116+ __get_user_asm(tmp, (const u8 __user *)src,
20117 ret, "b", "b", "=q", 1);
20118 if (likely(!ret))
20119 __put_user_asm(tmp, (u8 __user *)dst,
20120@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20121 }
20122 case 2: {
20123 u16 tmp;
20124- __get_user_asm(tmp, (u16 __user *)src,
20125+ __get_user_asm(tmp, (const u16 __user *)src,
20126 ret, "w", "w", "=r", 2);
20127 if (likely(!ret))
20128 __put_user_asm(tmp, (u16 __user *)dst,
20129@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20130
20131 case 4: {
20132 u32 tmp;
20133- __get_user_asm(tmp, (u32 __user *)src,
20134+ __get_user_asm(tmp, (const u32 __user *)src,
20135 ret, "l", "k", "=r", 4);
20136 if (likely(!ret))
20137 __put_user_asm(tmp, (u32 __user *)dst,
20138@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20139 }
20140 case 8: {
20141 u64 tmp;
20142- __get_user_asm(tmp, (u64 __user *)src,
20143+ __get_user_asm(tmp, (const u64 __user *)src,
20144 ret, "q", "", "=r", 8);
20145 if (likely(!ret))
20146 __put_user_asm(tmp, (u64 __user *)dst,
20147@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20148 return ret;
20149 }
20150 default:
20151- return copy_user_generic((__force void *)dst,
20152- (__force void *)src, size);
20153+ return copy_user_generic((__force_kernel void *)____m(dst),
20154+ (__force_kernel const void *)____m(src), size);
20155 }
20156 }
20157
20158-static __must_check __always_inline int
20159-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20160+static __must_check __always_inline unsigned long
20161+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20162 {
20163 return __copy_from_user_nocheck(dst, src, size);
20164 }
20165
20166-static __must_check __always_inline int
20167-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20168+static __must_check __always_inline unsigned long
20169+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20170 {
20171 return __copy_to_user_nocheck(dst, src, size);
20172 }
20173
20174-extern long __copy_user_nocache(void *dst, const void __user *src,
20175- unsigned size, int zerorest);
20176+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20177+ unsigned long size, int zerorest);
20178
20179-static inline int
20180-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20181+static inline unsigned long
20182+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20183 {
20184 might_fault();
20185+
20186+ if (size > INT_MAX)
20187+ return size;
20188+
20189+#ifdef CONFIG_PAX_MEMORY_UDEREF
20190+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20191+ return size;
20192+#endif
20193+
20194 return __copy_user_nocache(dst, src, size, 1);
20195 }
20196
20197-static inline int
20198+static inline unsigned long
20199 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20200- unsigned size)
20201+ unsigned long size)
20202 {
20203+ if (size > INT_MAX)
20204+ return size;
20205+
20206+#ifdef CONFIG_PAX_MEMORY_UDEREF
20207+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20208+ return size;
20209+#endif
20210+
20211 return __copy_user_nocache(dst, src, size, 0);
20212 }
20213
20214 unsigned long
20215-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20216+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20217
20218 #endif /* _ASM_X86_UACCESS_64_H */
20219diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20220index 5b238981..77fdd78 100644
20221--- a/arch/x86/include/asm/word-at-a-time.h
20222+++ b/arch/x86/include/asm/word-at-a-time.h
20223@@ -11,7 +11,7 @@
20224 * and shift, for example.
20225 */
20226 struct word_at_a_time {
20227- const unsigned long one_bits, high_bits;
20228+ unsigned long one_bits, high_bits;
20229 };
20230
20231 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20232diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20233index e45e4da..44e8572 100644
20234--- a/arch/x86/include/asm/x86_init.h
20235+++ b/arch/x86/include/asm/x86_init.h
20236@@ -129,7 +129,7 @@ struct x86_init_ops {
20237 struct x86_init_timers timers;
20238 struct x86_init_iommu iommu;
20239 struct x86_init_pci pci;
20240-};
20241+} __no_const;
20242
20243 /**
20244 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20245@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20246 void (*setup_percpu_clockev)(void);
20247 void (*early_percpu_clock_init)(void);
20248 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20249-};
20250+} __no_const;
20251
20252 struct timespec;
20253
20254@@ -168,7 +168,7 @@ struct x86_platform_ops {
20255 void (*save_sched_clock_state)(void);
20256 void (*restore_sched_clock_state)(void);
20257 void (*apic_post_init)(void);
20258-};
20259+} __no_const;
20260
20261 struct pci_dev;
20262 struct msi_msg;
20263@@ -185,7 +185,7 @@ struct x86_msi_ops {
20264 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20265 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20266 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20267-};
20268+} __no_const;
20269
20270 struct IO_APIC_route_entry;
20271 struct io_apic_irq_attr;
20272@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20273 unsigned int destination, int vector,
20274 struct io_apic_irq_attr *attr);
20275 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20276-};
20277+} __no_const;
20278
20279 extern struct x86_init_ops x86_init;
20280 extern struct x86_cpuinit_ops x86_cpuinit;
20281diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20282index c949923..c22bfa4 100644
20283--- a/arch/x86/include/asm/xen/page.h
20284+++ b/arch/x86/include/asm/xen/page.h
20285@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20286 extern struct page *m2p_find_override(unsigned long mfn);
20287 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20288
20289-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20290+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20291 {
20292 unsigned long mfn;
20293
20294diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20295index d949ef2..479b9d1 100644
20296--- a/arch/x86/include/asm/xsave.h
20297+++ b/arch/x86/include/asm/xsave.h
20298@@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20299 if (unlikely(err))
20300 return -EFAULT;
20301
20302+ pax_open_userland();
20303 __asm__ __volatile__(ASM_STAC "\n"
20304- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20305+ "1:"
20306+ __copyuser_seg
20307+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20308 "2: " ASM_CLAC "\n"
20309 ".section .fixup,\"ax\"\n"
20310 "3: movl $-1,%[err]\n"
20311@@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20312 : [err] "=r" (err)
20313 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20314 : "memory");
20315+ pax_close_userland();
20316 return err;
20317 }
20318
20319 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20320 {
20321 int err;
20322- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20323+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20324 u32 lmask = mask;
20325 u32 hmask = mask >> 32;
20326
20327+ pax_open_userland();
20328 __asm__ __volatile__(ASM_STAC "\n"
20329- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20330+ "1:"
20331+ __copyuser_seg
20332+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20333 "2: " ASM_CLAC "\n"
20334 ".section .fixup,\"ax\"\n"
20335 "3: movl $-1,%[err]\n"
20336@@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20337 : [err] "=r" (err)
20338 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20339 : "memory"); /* memory required? */
20340+ pax_close_userland();
20341 return err;
20342 }
20343
20344diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20345index bbae024..e1528f9 100644
20346--- a/arch/x86/include/uapi/asm/e820.h
20347+++ b/arch/x86/include/uapi/asm/e820.h
20348@@ -63,7 +63,7 @@ struct e820map {
20349 #define ISA_START_ADDRESS 0xa0000
20350 #define ISA_END_ADDRESS 0x100000
20351
20352-#define BIOS_BEGIN 0x000a0000
20353+#define BIOS_BEGIN 0x000c0000
20354 #define BIOS_END 0x00100000
20355
20356 #define BIOS_ROM_BASE 0xffe00000
20357diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20358index 7b0a55a..ad115bf 100644
20359--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20360+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20361@@ -49,7 +49,6 @@
20362 #define EFLAGS 144
20363 #define RSP 152
20364 #define SS 160
20365-#define ARGOFFSET R11
20366 #endif /* __ASSEMBLY__ */
20367
20368 /* top of stack page */
20369diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20370index 491ef3e..7da98ce 100644
20371--- a/arch/x86/kernel/Makefile
20372+++ b/arch/x86/kernel/Makefile
20373@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20374 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20375 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20376 obj-y += probe_roms.o
20377-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20378+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20379 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20380 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20381 obj-$(CONFIG_X86_64) += vsyscall_64.o
20382diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20383index 86281ff..e046fc2 100644
20384--- a/arch/x86/kernel/acpi/boot.c
20385+++ b/arch/x86/kernel/acpi/boot.c
20386@@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20387 * If your system is blacklisted here, but you find that acpi=force
20388 * works for you, please contact linux-acpi@vger.kernel.org
20389 */
20390-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20391+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20392 /*
20393 * Boxes that need ACPI disabled
20394 */
20395@@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20396 };
20397
20398 /* second table for DMI checks that should run after early-quirks */
20399-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20400+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20401 /*
20402 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20403 * which includes some code which overrides all temperature
20404diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20405index 3136820..e2c6577 100644
20406--- a/arch/x86/kernel/acpi/sleep.c
20407+++ b/arch/x86/kernel/acpi/sleep.c
20408@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20409 #else /* CONFIG_64BIT */
20410 #ifdef CONFIG_SMP
20411 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20412+
20413+ pax_open_kernel();
20414 early_gdt_descr.address =
20415 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20416+ pax_close_kernel();
20417+
20418 initial_gs = per_cpu_offset(smp_processor_id());
20419 #endif
20420 initial_code = (unsigned long)wakeup_long64;
20421diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20422index 665c6b7..eae4d56 100644
20423--- a/arch/x86/kernel/acpi/wakeup_32.S
20424+++ b/arch/x86/kernel/acpi/wakeup_32.S
20425@@ -29,13 +29,11 @@ wakeup_pmode_return:
20426 # and restore the stack ... but you need gdt for this to work
20427 movl saved_context_esp, %esp
20428
20429- movl %cs:saved_magic, %eax
20430- cmpl $0x12345678, %eax
20431+ cmpl $0x12345678, saved_magic
20432 jne bogus_magic
20433
20434 # jump to place where we left off
20435- movl saved_eip, %eax
20436- jmp *%eax
20437+ jmp *(saved_eip)
20438
20439 bogus_magic:
20440 jmp bogus_magic
20441diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20442index df94598..b7162f9 100644
20443--- a/arch/x86/kernel/alternative.c
20444+++ b/arch/x86/kernel/alternative.c
20445@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20446 */
20447 for (a = start; a < end; a++) {
20448 instr = (u8 *)&a->instr_offset + a->instr_offset;
20449+
20450+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20451+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20452+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20453+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20454+#endif
20455+
20456 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20457 BUG_ON(a->replacementlen > a->instrlen);
20458 BUG_ON(a->instrlen > sizeof(insnbuf));
20459@@ -285,6 +292,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20460 add_nops(insnbuf + a->replacementlen,
20461 a->instrlen - a->replacementlen);
20462
20463+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20464+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20465+ instr = ktva_ktla(instr);
20466+#endif
20467+
20468 text_poke_early(instr, insnbuf, a->instrlen);
20469 }
20470 }
20471@@ -300,10 +312,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20472 for (poff = start; poff < end; poff++) {
20473 u8 *ptr = (u8 *)poff + *poff;
20474
20475+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20476+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20477+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20478+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20479+#endif
20480+
20481 if (!*poff || ptr < text || ptr >= text_end)
20482 continue;
20483 /* turn DS segment override prefix into lock prefix */
20484- if (*ptr == 0x3e)
20485+ if (*ktla_ktva(ptr) == 0x3e)
20486 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20487 }
20488 mutex_unlock(&text_mutex);
20489@@ -318,10 +336,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20490 for (poff = start; poff < end; poff++) {
20491 u8 *ptr = (u8 *)poff + *poff;
20492
20493+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20494+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20495+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20496+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20497+#endif
20498+
20499 if (!*poff || ptr < text || ptr >= text_end)
20500 continue;
20501 /* turn lock prefix into DS segment override prefix */
20502- if (*ptr == 0xf0)
20503+ if (*ktla_ktva(ptr) == 0xf0)
20504 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20505 }
20506 mutex_unlock(&text_mutex);
20507@@ -458,7 +482,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20508
20509 BUG_ON(p->len > MAX_PATCH_LEN);
20510 /* prep the buffer with the original instructions */
20511- memcpy(insnbuf, p->instr, p->len);
20512+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20513 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20514 (unsigned long)p->instr, p->len);
20515
20516@@ -505,7 +529,7 @@ void __init alternative_instructions(void)
20517 if (!uniproc_patched || num_possible_cpus() == 1)
20518 free_init_pages("SMP alternatives",
20519 (unsigned long)__smp_locks,
20520- (unsigned long)__smp_locks_end);
20521+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20522 #endif
20523
20524 apply_paravirt(__parainstructions, __parainstructions_end);
20525@@ -525,13 +549,17 @@ void __init alternative_instructions(void)
20526 * instructions. And on the local CPU you need to be protected again NMI or MCE
20527 * handlers seeing an inconsistent instruction while you patch.
20528 */
20529-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20530+void *__kprobes text_poke_early(void *addr, const void *opcode,
20531 size_t len)
20532 {
20533 unsigned long flags;
20534 local_irq_save(flags);
20535- memcpy(addr, opcode, len);
20536+
20537+ pax_open_kernel();
20538+ memcpy(ktla_ktva(addr), opcode, len);
20539 sync_core();
20540+ pax_close_kernel();
20541+
20542 local_irq_restore(flags);
20543 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20544 that causes hangs on some VIA CPUs. */
20545@@ -553,36 +581,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20546 */
20547 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20548 {
20549- unsigned long flags;
20550- char *vaddr;
20551+ unsigned char *vaddr = ktla_ktva(addr);
20552 struct page *pages[2];
20553- int i;
20554+ size_t i;
20555
20556 if (!core_kernel_text((unsigned long)addr)) {
20557- pages[0] = vmalloc_to_page(addr);
20558- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20559+ pages[0] = vmalloc_to_page(vaddr);
20560+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20561 } else {
20562- pages[0] = virt_to_page(addr);
20563+ pages[0] = virt_to_page(vaddr);
20564 WARN_ON(!PageReserved(pages[0]));
20565- pages[1] = virt_to_page(addr + PAGE_SIZE);
20566+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20567 }
20568 BUG_ON(!pages[0]);
20569- local_irq_save(flags);
20570- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20571- if (pages[1])
20572- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20573- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20574- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20575- clear_fixmap(FIX_TEXT_POKE0);
20576- if (pages[1])
20577- clear_fixmap(FIX_TEXT_POKE1);
20578- local_flush_tlb();
20579- sync_core();
20580- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20581- that causes hangs on some VIA CPUs. */
20582+ text_poke_early(addr, opcode, len);
20583 for (i = 0; i < len; i++)
20584- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20585- local_irq_restore(flags);
20586+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20587 return addr;
20588 }
20589
20590@@ -602,7 +616,7 @@ int poke_int3_handler(struct pt_regs *regs)
20591 if (likely(!bp_patching_in_progress))
20592 return 0;
20593
20594- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20595+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20596 return 0;
20597
20598 /* set up the specified breakpoint handler */
20599@@ -636,7 +650,7 @@ int poke_int3_handler(struct pt_regs *regs)
20600 */
20601 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20602 {
20603- unsigned char int3 = 0xcc;
20604+ const unsigned char int3 = 0xcc;
20605
20606 bp_int3_handler = handler;
20607 bp_int3_addr = (u8 *)addr + sizeof(int3);
20608diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20609index ad28db7..c538b2c 100644
20610--- a/arch/x86/kernel/apic/apic.c
20611+++ b/arch/x86/kernel/apic/apic.c
20612@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20613 /*
20614 * Debug level, exported for io_apic.c
20615 */
20616-unsigned int apic_verbosity;
20617+int apic_verbosity;
20618
20619 int pic_mode;
20620
20621@@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20622 apic_write(APIC_ESR, 0);
20623 v = apic_read(APIC_ESR);
20624 ack_APIC_irq();
20625- atomic_inc(&irq_err_count);
20626+ atomic_inc_unchecked(&irq_err_count);
20627
20628 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20629 smp_processor_id(), v);
20630diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20631index 7c1b294..e71d27f 100644
20632--- a/arch/x86/kernel/apic/apic_flat_64.c
20633+++ b/arch/x86/kernel/apic/apic_flat_64.c
20634@@ -154,7 +154,7 @@ static int flat_probe(void)
20635 return 1;
20636 }
20637
20638-static struct apic apic_flat = {
20639+static struct apic apic_flat __read_only = {
20640 .name = "flat",
20641 .probe = flat_probe,
20642 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20643@@ -268,7 +268,7 @@ static int physflat_probe(void)
20644 return 0;
20645 }
20646
20647-static struct apic apic_physflat = {
20648+static struct apic apic_physflat __read_only = {
20649
20650 .name = "physical flat",
20651 .probe = physflat_probe,
20652diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20653index 8c7c982..a225910 100644
20654--- a/arch/x86/kernel/apic/apic_noop.c
20655+++ b/arch/x86/kernel/apic/apic_noop.c
20656@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20657 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20658 }
20659
20660-struct apic apic_noop = {
20661+struct apic apic_noop __read_only = {
20662 .name = "noop",
20663 .probe = noop_probe,
20664 .acpi_madt_oem_check = NULL,
20665diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20666index e4840aa..e7d9dac 100644
20667--- a/arch/x86/kernel/apic/bigsmp_32.c
20668+++ b/arch/x86/kernel/apic/bigsmp_32.c
20669@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20670 return dmi_bigsmp;
20671 }
20672
20673-static struct apic apic_bigsmp = {
20674+static struct apic apic_bigsmp __read_only = {
20675
20676 .name = "bigsmp",
20677 .probe = probe_bigsmp,
20678diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20679index 992060e..ecdc3b3 100644
20680--- a/arch/x86/kernel/apic/io_apic.c
20681+++ b/arch/x86/kernel/apic/io_apic.c
20682@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20683 }
20684 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20685
20686-void lock_vector_lock(void)
20687+void lock_vector_lock(void) __acquires(vector_lock)
20688 {
20689 /* Used to the online set of cpus does not change
20690 * during assign_irq_vector.
20691@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20692 raw_spin_lock(&vector_lock);
20693 }
20694
20695-void unlock_vector_lock(void)
20696+void unlock_vector_lock(void) __releases(vector_lock)
20697 {
20698 raw_spin_unlock(&vector_lock);
20699 }
20700@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20701 ack_APIC_irq();
20702 }
20703
20704-atomic_t irq_mis_count;
20705+atomic_unchecked_t irq_mis_count;
20706
20707 #ifdef CONFIG_GENERIC_PENDING_IRQ
20708 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20709@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20710 * at the cpu.
20711 */
20712 if (!(v & (1 << (i & 0x1f)))) {
20713- atomic_inc(&irq_mis_count);
20714+ atomic_inc_unchecked(&irq_mis_count);
20715
20716 eoi_ioapic_irq(irq, cfg);
20717 }
20718diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20719index cceb352..a635fd8 100644
20720--- a/arch/x86/kernel/apic/probe_32.c
20721+++ b/arch/x86/kernel/apic/probe_32.c
20722@@ -72,7 +72,7 @@ static int probe_default(void)
20723 return 1;
20724 }
20725
20726-static struct apic apic_default = {
20727+static struct apic apic_default __read_only = {
20728
20729 .name = "default",
20730 .probe = probe_default,
20731diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20732index e66766b..1c008ba 100644
20733--- a/arch/x86/kernel/apic/x2apic_cluster.c
20734+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20735@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20736 return notifier_from_errno(err);
20737 }
20738
20739-static struct notifier_block __refdata x2apic_cpu_notifier = {
20740+static struct notifier_block x2apic_cpu_notifier = {
20741 .notifier_call = update_clusterinfo,
20742 };
20743
20744@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20745 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20746 }
20747
20748-static struct apic apic_x2apic_cluster = {
20749+static struct apic apic_x2apic_cluster __read_only = {
20750
20751 .name = "cluster x2apic",
20752 .probe = x2apic_cluster_probe,
20753diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20754index 6d600eb..0300c00 100644
20755--- a/arch/x86/kernel/apic/x2apic_phys.c
20756+++ b/arch/x86/kernel/apic/x2apic_phys.c
20757@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20758 return apic == &apic_x2apic_phys;
20759 }
20760
20761-static struct apic apic_x2apic_phys = {
20762+static struct apic apic_x2apic_phys __read_only = {
20763
20764 .name = "physical x2apic",
20765 .probe = x2apic_phys_probe,
20766diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20767index 7834389..4ffc9c8 100644
20768--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20769+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20770@@ -350,7 +350,7 @@ static int uv_probe(void)
20771 return apic == &apic_x2apic_uv_x;
20772 }
20773
20774-static struct apic __refdata apic_x2apic_uv_x = {
20775+static struct apic apic_x2apic_uv_x __read_only = {
20776
20777 .name = "UV large system",
20778 .probe = uv_probe,
20779diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20780index 3ab0343..814c4787 100644
20781--- a/arch/x86/kernel/apm_32.c
20782+++ b/arch/x86/kernel/apm_32.c
20783@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20784 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20785 * even though they are called in protected mode.
20786 */
20787-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20788+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20789 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20790
20791 static const char driver_version[] = "1.16ac"; /* no spaces */
20792@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20793 BUG_ON(cpu != 0);
20794 gdt = get_cpu_gdt_table(cpu);
20795 save_desc_40 = gdt[0x40 / 8];
20796+
20797+ pax_open_kernel();
20798 gdt[0x40 / 8] = bad_bios_desc;
20799+ pax_close_kernel();
20800
20801 apm_irq_save(flags);
20802 APM_DO_SAVE_SEGS;
20803@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20804 &call->esi);
20805 APM_DO_RESTORE_SEGS;
20806 apm_irq_restore(flags);
20807+
20808+ pax_open_kernel();
20809 gdt[0x40 / 8] = save_desc_40;
20810+ pax_close_kernel();
20811+
20812 put_cpu();
20813
20814 return call->eax & 0xff;
20815@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20816 BUG_ON(cpu != 0);
20817 gdt = get_cpu_gdt_table(cpu);
20818 save_desc_40 = gdt[0x40 / 8];
20819+
20820+ pax_open_kernel();
20821 gdt[0x40 / 8] = bad_bios_desc;
20822+ pax_close_kernel();
20823
20824 apm_irq_save(flags);
20825 APM_DO_SAVE_SEGS;
20826@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20827 &call->eax);
20828 APM_DO_RESTORE_SEGS;
20829 apm_irq_restore(flags);
20830+
20831+ pax_open_kernel();
20832 gdt[0x40 / 8] = save_desc_40;
20833+ pax_close_kernel();
20834+
20835 put_cpu();
20836 return error;
20837 }
20838@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20839 * code to that CPU.
20840 */
20841 gdt = get_cpu_gdt_table(0);
20842+
20843+ pax_open_kernel();
20844 set_desc_base(&gdt[APM_CS >> 3],
20845 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20846 set_desc_base(&gdt[APM_CS_16 >> 3],
20847 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20848 set_desc_base(&gdt[APM_DS >> 3],
20849 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20850+ pax_close_kernel();
20851
20852 proc_create("apm", 0, NULL, &apm_file_ops);
20853
20854diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20855index 9f6b934..cf5ffb3 100644
20856--- a/arch/x86/kernel/asm-offsets.c
20857+++ b/arch/x86/kernel/asm-offsets.c
20858@@ -32,6 +32,8 @@ void common(void) {
20859 OFFSET(TI_flags, thread_info, flags);
20860 OFFSET(TI_status, thread_info, status);
20861 OFFSET(TI_addr_limit, thread_info, addr_limit);
20862+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20863+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20864
20865 BLANK();
20866 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20867@@ -52,8 +54,26 @@ void common(void) {
20868 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20869 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20870 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20871+
20872+#ifdef CONFIG_PAX_KERNEXEC
20873+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20874 #endif
20875
20876+#ifdef CONFIG_PAX_MEMORY_UDEREF
20877+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20878+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20879+#ifdef CONFIG_X86_64
20880+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20881+#endif
20882+#endif
20883+
20884+#endif
20885+
20886+ BLANK();
20887+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20888+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20889+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20890+
20891 #ifdef CONFIG_XEN
20892 BLANK();
20893 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20894diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20895index e7c798b..2b2019b 100644
20896--- a/arch/x86/kernel/asm-offsets_64.c
20897+++ b/arch/x86/kernel/asm-offsets_64.c
20898@@ -77,6 +77,7 @@ int main(void)
20899 BLANK();
20900 #undef ENTRY
20901
20902+ DEFINE(TSS_size, sizeof(struct tss_struct));
20903 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20904 BLANK();
20905
20906diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20907index 7fd54f0..0691410 100644
20908--- a/arch/x86/kernel/cpu/Makefile
20909+++ b/arch/x86/kernel/cpu/Makefile
20910@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20911 CFLAGS_REMOVE_perf_event.o = -pg
20912 endif
20913
20914-# Make sure load_percpu_segment has no stackprotector
20915-nostackp := $(call cc-option, -fno-stack-protector)
20916-CFLAGS_common.o := $(nostackp)
20917-
20918 obj-y := intel_cacheinfo.o scattered.o topology.o
20919 obj-y += proc.o capflags.o powerflags.o common.o
20920 obj-y += rdrand.o
20921diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20922index ce8b8ff..d7d8851 100644
20923--- a/arch/x86/kernel/cpu/amd.c
20924+++ b/arch/x86/kernel/cpu/amd.c
20925@@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20926 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20927 {
20928 /* AMD errata T13 (order #21922) */
20929- if ((c->x86 == 6)) {
20930+ if (c->x86 == 6) {
20931 /* Duron Rev A0 */
20932 if (c->x86_model == 3 && c->x86_mask == 0)
20933 size = 64;
20934diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20935index a135239..41fb30a 100644
20936--- a/arch/x86/kernel/cpu/common.c
20937+++ b/arch/x86/kernel/cpu/common.c
20938@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20939
20940 static const struct cpu_dev *this_cpu = &default_cpu;
20941
20942-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20943-#ifdef CONFIG_X86_64
20944- /*
20945- * We need valid kernel segments for data and code in long mode too
20946- * IRET will check the segment types kkeil 2000/10/28
20947- * Also sysret mandates a special GDT layout
20948- *
20949- * TLS descriptors are currently at a different place compared to i386.
20950- * Hopefully nobody expects them at a fixed place (Wine?)
20951- */
20952- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20953- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20954- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20955- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20956- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20957- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20958-#else
20959- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20960- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20961- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20962- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20963- /*
20964- * Segments used for calling PnP BIOS have byte granularity.
20965- * They code segments and data segments have fixed 64k limits,
20966- * the transfer segment sizes are set at run time.
20967- */
20968- /* 32-bit code */
20969- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20970- /* 16-bit code */
20971- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20972- /* 16-bit data */
20973- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20974- /* 16-bit data */
20975- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20976- /* 16-bit data */
20977- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20978- /*
20979- * The APM segments have byte granularity and their bases
20980- * are set at run time. All have 64k limits.
20981- */
20982- /* 32-bit code */
20983- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20984- /* 16-bit code */
20985- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20986- /* data */
20987- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20988-
20989- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20990- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20991- GDT_STACK_CANARY_INIT
20992-#endif
20993-} };
20994-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20995-
20996 static int __init x86_xsave_setup(char *s)
20997 {
20998 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20999@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21000 }
21001 }
21002
21003+#ifdef CONFIG_X86_64
21004+static __init int setup_disable_pcid(char *arg)
21005+{
21006+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21007+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21008+
21009+#ifdef CONFIG_PAX_MEMORY_UDEREF
21010+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21011+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21012+#endif
21013+
21014+ return 1;
21015+}
21016+__setup("nopcid", setup_disable_pcid);
21017+
21018+static void setup_pcid(struct cpuinfo_x86 *c)
21019+{
21020+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21021+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21022+
21023+#ifdef CONFIG_PAX_MEMORY_UDEREF
21024+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21025+ pax_open_kernel();
21026+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21027+ pax_close_kernel();
21028+ printk("PAX: slow and weak UDEREF enabled\n");
21029+ } else
21030+ printk("PAX: UDEREF disabled\n");
21031+#endif
21032+
21033+ return;
21034+ }
21035+
21036+ printk("PAX: PCID detected\n");
21037+ set_in_cr4(X86_CR4_PCIDE);
21038+
21039+#ifdef CONFIG_PAX_MEMORY_UDEREF
21040+ pax_open_kernel();
21041+ clone_pgd_mask = ~(pgdval_t)0UL;
21042+ pax_close_kernel();
21043+ if (pax_user_shadow_base)
21044+ printk("PAX: weak UDEREF enabled\n");
21045+ else {
21046+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21047+ printk("PAX: strong UDEREF enabled\n");
21048+ }
21049+#endif
21050+
21051+ if (cpu_has(c, X86_FEATURE_INVPCID))
21052+ printk("PAX: INVPCID detected\n");
21053+}
21054+#endif
21055+
21056 /*
21057 * Some CPU features depend on higher CPUID levels, which may not always
21058 * be available due to CPUID level capping or broken virtualization
21059@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21060 {
21061 struct desc_ptr gdt_descr;
21062
21063- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21064+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21065 gdt_descr.size = GDT_SIZE - 1;
21066 load_gdt(&gdt_descr);
21067 /* Reload the per-cpu base */
21068@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21069 setup_smep(c);
21070 setup_smap(c);
21071
21072+#ifdef CONFIG_X86_64
21073+ setup_pcid(c);
21074+#endif
21075+
21076 /*
21077 * The vendor-specific functions might have changed features.
21078 * Now we do "generic changes."
21079@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21080 /* Filter out anything that depends on CPUID levels we don't have */
21081 filter_cpuid_features(c, true);
21082
21083+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21084+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21085+#endif
21086+
21087 /* If the model name is still unset, do table lookup. */
21088 if (!c->x86_model_id[0]) {
21089 const char *p;
21090@@ -1079,14 +1086,16 @@ static __init int setup_disablecpuid(char *arg)
21091 }
21092 __setup("clearcpuid=", setup_disablecpuid);
21093
21094+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21095+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21096+
21097 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21098- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21099+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21100 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21101
21102 #ifdef CONFIG_X86_64
21103-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21104-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21105- (unsigned long) debug_idt_table };
21106+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21107+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21108
21109 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21110 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21111@@ -1246,7 +1255,7 @@ void cpu_init(void)
21112 load_ucode_ap();
21113
21114 cpu = stack_smp_processor_id();
21115- t = &per_cpu(init_tss, cpu);
21116+ t = init_tss + cpu;
21117 oist = &per_cpu(orig_ist, cpu);
21118
21119 #ifdef CONFIG_NUMA
21120@@ -1281,7 +1290,6 @@ void cpu_init(void)
21121 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21122 barrier();
21123
21124- x86_configure_nx();
21125 enable_x2apic();
21126
21127 /*
21128@@ -1333,7 +1341,7 @@ void cpu_init(void)
21129 {
21130 int cpu = smp_processor_id();
21131 struct task_struct *curr = current;
21132- struct tss_struct *t = &per_cpu(init_tss, cpu);
21133+ struct tss_struct *t = init_tss + cpu;
21134 struct thread_struct *thread = &curr->thread;
21135
21136 show_ucode_info_early();
21137diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21138index a952e9c..58a4cbb 100644
21139--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21140+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21141@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21142 };
21143
21144 #ifdef CONFIG_AMD_NB
21145+static struct attribute *default_attrs_amd_nb[] = {
21146+ &type.attr,
21147+ &level.attr,
21148+ &coherency_line_size.attr,
21149+ &physical_line_partition.attr,
21150+ &ways_of_associativity.attr,
21151+ &number_of_sets.attr,
21152+ &size.attr,
21153+ &shared_cpu_map.attr,
21154+ &shared_cpu_list.attr,
21155+ NULL,
21156+ NULL,
21157+ NULL,
21158+ NULL
21159+};
21160+
21161 static struct attribute **amd_l3_attrs(void)
21162 {
21163 static struct attribute **attrs;
21164@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21165
21166 n = ARRAY_SIZE(default_attrs);
21167
21168- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21169- n += 2;
21170-
21171- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21172- n += 1;
21173-
21174- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21175- if (attrs == NULL)
21176- return attrs = default_attrs;
21177-
21178- for (n = 0; default_attrs[n]; n++)
21179- attrs[n] = default_attrs[n];
21180+ attrs = default_attrs_amd_nb;
21181
21182 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21183 attrs[n++] = &cache_disable_0.attr;
21184@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21185 .default_attrs = default_attrs,
21186 };
21187
21188+#ifdef CONFIG_AMD_NB
21189+static struct kobj_type ktype_cache_amd_nb = {
21190+ .sysfs_ops = &sysfs_ops,
21191+ .default_attrs = default_attrs_amd_nb,
21192+};
21193+#endif
21194+
21195 static struct kobj_type ktype_percpu_entry = {
21196 .sysfs_ops = &sysfs_ops,
21197 };
21198@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21199 return retval;
21200 }
21201
21202+#ifdef CONFIG_AMD_NB
21203+ amd_l3_attrs();
21204+#endif
21205+
21206 for (i = 0; i < num_cache_leaves; i++) {
21207+ struct kobj_type *ktype;
21208+
21209 this_object = INDEX_KOBJECT_PTR(cpu, i);
21210 this_object->cpu = cpu;
21211 this_object->index = i;
21212
21213 this_leaf = CPUID4_INFO_IDX(cpu, i);
21214
21215- ktype_cache.default_attrs = default_attrs;
21216+ ktype = &ktype_cache;
21217 #ifdef CONFIG_AMD_NB
21218 if (this_leaf->base.nb)
21219- ktype_cache.default_attrs = amd_l3_attrs();
21220+ ktype = &ktype_cache_amd_nb;
21221 #endif
21222 retval = kobject_init_and_add(&(this_object->kobj),
21223- &ktype_cache,
21224+ ktype,
21225 per_cpu(ici_cache_kobject, cpu),
21226 "index%1lu", i);
21227 if (unlikely(retval)) {
21228diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21229index 68317c8..c860d41 100644
21230--- a/arch/x86/kernel/cpu/mcheck/mce.c
21231+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21232@@ -45,6 +45,7 @@
21233 #include <asm/processor.h>
21234 #include <asm/mce.h>
21235 #include <asm/msr.h>
21236+#include <asm/local.h>
21237
21238 #include "mce-internal.h"
21239
21240@@ -261,7 +262,7 @@ static void print_mce(struct mce *m)
21241 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21242 m->cs, m->ip);
21243
21244- if (m->cs == __KERNEL_CS)
21245+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21246 print_symbol("{%s}", m->ip);
21247 pr_cont("\n");
21248 }
21249@@ -294,10 +295,10 @@ static void print_mce(struct mce *m)
21250
21251 #define PANIC_TIMEOUT 5 /* 5 seconds */
21252
21253-static atomic_t mce_paniced;
21254+static atomic_unchecked_t mce_paniced;
21255
21256 static int fake_panic;
21257-static atomic_t mce_fake_paniced;
21258+static atomic_unchecked_t mce_fake_paniced;
21259
21260 /* Panic in progress. Enable interrupts and wait for final IPI */
21261 static void wait_for_panic(void)
21262@@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21263 /*
21264 * Make sure only one CPU runs in machine check panic
21265 */
21266- if (atomic_inc_return(&mce_paniced) > 1)
21267+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21268 wait_for_panic();
21269 barrier();
21270
21271@@ -329,7 +330,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21272 console_verbose();
21273 } else {
21274 /* Don't log too much for fake panic */
21275- if (atomic_inc_return(&mce_fake_paniced) > 1)
21276+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21277 return;
21278 }
21279 /* First print corrected ones that are still unlogged */
21280@@ -368,7 +369,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21281 if (!fake_panic) {
21282 if (panic_timeout == 0)
21283 panic_timeout = mca_cfg.panic_timeout;
21284- panic(msg);
21285+ panic("%s", msg);
21286 } else
21287 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21288 }
21289@@ -699,7 +700,7 @@ static int mce_timed_out(u64 *t)
21290 * might have been modified by someone else.
21291 */
21292 rmb();
21293- if (atomic_read(&mce_paniced))
21294+ if (atomic_read_unchecked(&mce_paniced))
21295 wait_for_panic();
21296 if (!mca_cfg.monarch_timeout)
21297 goto out;
21298@@ -1680,7 +1681,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21299 }
21300
21301 /* Call the installed machine check handler for this CPU setup. */
21302-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21303+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21304 unexpected_machine_check;
21305
21306 /*
21307@@ -1703,7 +1704,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21308 return;
21309 }
21310
21311+ pax_open_kernel();
21312 machine_check_vector = do_machine_check;
21313+ pax_close_kernel();
21314
21315 __mcheck_cpu_init_generic();
21316 __mcheck_cpu_init_vendor(c);
21317@@ -1717,7 +1720,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21318 */
21319
21320 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21321-static int mce_chrdev_open_count; /* #times opened */
21322+static local_t mce_chrdev_open_count; /* #times opened */
21323 static int mce_chrdev_open_exclu; /* already open exclusive? */
21324
21325 static int mce_chrdev_open(struct inode *inode, struct file *file)
21326@@ -1725,7 +1728,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21327 spin_lock(&mce_chrdev_state_lock);
21328
21329 if (mce_chrdev_open_exclu ||
21330- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21331+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21332 spin_unlock(&mce_chrdev_state_lock);
21333
21334 return -EBUSY;
21335@@ -1733,7 +1736,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21336
21337 if (file->f_flags & O_EXCL)
21338 mce_chrdev_open_exclu = 1;
21339- mce_chrdev_open_count++;
21340+ local_inc(&mce_chrdev_open_count);
21341
21342 spin_unlock(&mce_chrdev_state_lock);
21343
21344@@ -1744,7 +1747,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21345 {
21346 spin_lock(&mce_chrdev_state_lock);
21347
21348- mce_chrdev_open_count--;
21349+ local_dec(&mce_chrdev_open_count);
21350 mce_chrdev_open_exclu = 0;
21351
21352 spin_unlock(&mce_chrdev_state_lock);
21353@@ -2420,7 +2423,7 @@ static __init void mce_init_banks(void)
21354
21355 for (i = 0; i < mca_cfg.banks; i++) {
21356 struct mce_bank *b = &mce_banks[i];
21357- struct device_attribute *a = &b->attr;
21358+ device_attribute_no_const *a = &b->attr;
21359
21360 sysfs_attr_init(&a->attr);
21361 a->attr.name = b->attrname;
21362@@ -2492,7 +2495,7 @@ struct dentry *mce_get_debugfs_dir(void)
21363 static void mce_reset(void)
21364 {
21365 cpu_missing = 0;
21366- atomic_set(&mce_fake_paniced, 0);
21367+ atomic_set_unchecked(&mce_fake_paniced, 0);
21368 atomic_set(&mce_executing, 0);
21369 atomic_set(&mce_callin, 0);
21370 atomic_set(&global_nwo, 0);
21371diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21372index a304298..49b6d06 100644
21373--- a/arch/x86/kernel/cpu/mcheck/p5.c
21374+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21375@@ -10,6 +10,7 @@
21376 #include <asm/processor.h>
21377 #include <asm/mce.h>
21378 #include <asm/msr.h>
21379+#include <asm/pgtable.h>
21380
21381 /* By default disabled */
21382 int mce_p5_enabled __read_mostly;
21383@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21384 if (!cpu_has(c, X86_FEATURE_MCE))
21385 return;
21386
21387+ pax_open_kernel();
21388 machine_check_vector = pentium_machine_check;
21389+ pax_close_kernel();
21390 /* Make sure the vector pointer is visible before we enable MCEs: */
21391 wmb();
21392
21393diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21394index 7dc5564..1273569 100644
21395--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21396+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21397@@ -9,6 +9,7 @@
21398 #include <asm/processor.h>
21399 #include <asm/mce.h>
21400 #include <asm/msr.h>
21401+#include <asm/pgtable.h>
21402
21403 /* Machine check handler for WinChip C6: */
21404 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21405@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21406 {
21407 u32 lo, hi;
21408
21409+ pax_open_kernel();
21410 machine_check_vector = winchip_machine_check;
21411+ pax_close_kernel();
21412 /* Make sure the vector pointer is visible before we enable MCEs: */
21413 wmb();
21414
21415diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21416index 15c9876..0a43909 100644
21417--- a/arch/x86/kernel/cpu/microcode/core.c
21418+++ b/arch/x86/kernel/cpu/microcode/core.c
21419@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21420 return NOTIFY_OK;
21421 }
21422
21423-static struct notifier_block __refdata mc_cpu_notifier = {
21424+static struct notifier_block mc_cpu_notifier = {
21425 .notifier_call = mc_cpu_callback,
21426 };
21427
21428diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21429index a276fa7..e66810f 100644
21430--- a/arch/x86/kernel/cpu/microcode/intel.c
21431+++ b/arch/x86/kernel/cpu/microcode/intel.c
21432@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21433
21434 static int get_ucode_user(void *to, const void *from, size_t n)
21435 {
21436- return copy_from_user(to, from, n);
21437+ return copy_from_user(to, (const void __force_user *)from, n);
21438 }
21439
21440 static enum ucode_state
21441 request_microcode_user(int cpu, const void __user *buf, size_t size)
21442 {
21443- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21444+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21445 }
21446
21447 static void microcode_fini_cpu(int cpu)
21448diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21449index f961de9..8a9d332 100644
21450--- a/arch/x86/kernel/cpu/mtrr/main.c
21451+++ b/arch/x86/kernel/cpu/mtrr/main.c
21452@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21453 u64 size_or_mask, size_and_mask;
21454 static bool mtrr_aps_delayed_init;
21455
21456-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21457+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21458
21459 const struct mtrr_ops *mtrr_if;
21460
21461diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21462index df5e41f..816c719 100644
21463--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21464+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21465@@ -25,7 +25,7 @@ struct mtrr_ops {
21466 int (*validate_add_page)(unsigned long base, unsigned long size,
21467 unsigned int type);
21468 int (*have_wrcomb)(void);
21469-};
21470+} __do_const;
21471
21472 extern int generic_get_free_region(unsigned long base, unsigned long size,
21473 int replace_reg);
21474diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21475index ae407f7..39c5b00 100644
21476--- a/arch/x86/kernel/cpu/perf_event.c
21477+++ b/arch/x86/kernel/cpu/perf_event.c
21478@@ -1367,7 +1367,7 @@ static void __init pmu_check_apic(void)
21479 pr_info("no hardware sampling interrupt available.\n");
21480 }
21481
21482-static struct attribute_group x86_pmu_format_group = {
21483+static attribute_group_no_const x86_pmu_format_group = {
21484 .name = "format",
21485 .attrs = NULL,
21486 };
21487@@ -1466,7 +1466,7 @@ static struct attribute *events_attr[] = {
21488 NULL,
21489 };
21490
21491-static struct attribute_group x86_pmu_events_group = {
21492+static attribute_group_no_const x86_pmu_events_group = {
21493 .name = "events",
21494 .attrs = events_attr,
21495 };
21496@@ -1990,7 +1990,7 @@ static unsigned long get_segment_base(unsigned int segment)
21497 if (idx > GDT_ENTRIES)
21498 return 0;
21499
21500- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21501+ desc = get_cpu_gdt_table(smp_processor_id());
21502 }
21503
21504 return get_desc_base(desc + idx);
21505@@ -2080,7 +2080,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21506 break;
21507
21508 perf_callchain_store(entry, frame.return_address);
21509- fp = frame.next_frame;
21510+ fp = (const void __force_user *)frame.next_frame;
21511 }
21512 }
21513
21514diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21515index 639d128..e92d7e5 100644
21516--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21517+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21518@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21519 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21520 {
21521 struct attribute **attrs;
21522- struct attribute_group *attr_group;
21523+ attribute_group_no_const *attr_group;
21524 int i = 0, j;
21525
21526 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21527diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21528index 07846d7..a40ec4a 100644
21529--- a/arch/x86/kernel/cpu/perf_event_intel.c
21530+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21531@@ -2317,10 +2317,10 @@ __init int intel_pmu_init(void)
21532 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21533
21534 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21535- u64 capabilities;
21536+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21537
21538- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21539- x86_pmu.intel_cap.capabilities = capabilities;
21540+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21541+ x86_pmu.intel_cap.capabilities = capabilities;
21542 }
21543
21544 intel_ds_init();
21545diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21546index 619f769..d510008 100644
21547--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21548+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21549@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21550 NULL,
21551 };
21552
21553-static struct attribute_group rapl_pmu_events_group = {
21554+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21555 .name = "events",
21556 .attrs = NULL, /* patched at runtime */
21557 };
21558diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21559index 65bbbea..1438d9e 100644
21560--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21561+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21562@@ -3693,7 +3693,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21563 static int __init uncore_type_init(struct intel_uncore_type *type)
21564 {
21565 struct intel_uncore_pmu *pmus;
21566- struct attribute_group *attr_group;
21567+ attribute_group_no_const *attr_group;
21568 struct attribute **attrs;
21569 int i, j;
21570
21571diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21572index 90236f0..54cb20d 100644
21573--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21574+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21575@@ -503,7 +503,7 @@ struct intel_uncore_box {
21576 struct uncore_event_desc {
21577 struct kobj_attribute attr;
21578 const char *config;
21579-};
21580+} __do_const;
21581
21582 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21583 { \
21584diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21585index 3225ae6c..ee3c6db 100644
21586--- a/arch/x86/kernel/cpuid.c
21587+++ b/arch/x86/kernel/cpuid.c
21588@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21589 return notifier_from_errno(err);
21590 }
21591
21592-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21593+static struct notifier_block cpuid_class_cpu_notifier =
21594 {
21595 .notifier_call = cpuid_class_cpu_callback,
21596 };
21597diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21598index 507de80..ebaae2a 100644
21599--- a/arch/x86/kernel/crash.c
21600+++ b/arch/x86/kernel/crash.c
21601@@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21602 #ifdef CONFIG_X86_32
21603 struct pt_regs fixed_regs;
21604
21605- if (!user_mode_vm(regs)) {
21606+ if (!user_mode(regs)) {
21607 crash_fixup_ss_esp(&fixed_regs, regs);
21608 regs = &fixed_regs;
21609 }
21610diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21611index afa64ad..dce67dd 100644
21612--- a/arch/x86/kernel/crash_dump_64.c
21613+++ b/arch/x86/kernel/crash_dump_64.c
21614@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21615 return -ENOMEM;
21616
21617 if (userbuf) {
21618- if (copy_to_user(buf, vaddr + offset, csize)) {
21619+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21620 iounmap(vaddr);
21621 return -EFAULT;
21622 }
21623diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21624index f6dfd93..892ade4 100644
21625--- a/arch/x86/kernel/doublefault.c
21626+++ b/arch/x86/kernel/doublefault.c
21627@@ -12,7 +12,7 @@
21628
21629 #define DOUBLEFAULT_STACKSIZE (1024)
21630 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21631-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21632+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21633
21634 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21635
21636@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21637 unsigned long gdt, tss;
21638
21639 native_store_gdt(&gdt_desc);
21640- gdt = gdt_desc.address;
21641+ gdt = (unsigned long)gdt_desc.address;
21642
21643 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21644
21645@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21646 /* 0x2 bit is always set */
21647 .flags = X86_EFLAGS_SF | 0x2,
21648 .sp = STACK_START,
21649- .es = __USER_DS,
21650+ .es = __KERNEL_DS,
21651 .cs = __KERNEL_CS,
21652 .ss = __KERNEL_DS,
21653- .ds = __USER_DS,
21654+ .ds = __KERNEL_DS,
21655 .fs = __KERNEL_PERCPU,
21656
21657 .__cr3 = __pa_nodebug(swapper_pg_dir),
21658diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21659index d9c12d3..7858b62 100644
21660--- a/arch/x86/kernel/dumpstack.c
21661+++ b/arch/x86/kernel/dumpstack.c
21662@@ -2,6 +2,9 @@
21663 * Copyright (C) 1991, 1992 Linus Torvalds
21664 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21665 */
21666+#ifdef CONFIG_GRKERNSEC_HIDESYM
21667+#define __INCLUDED_BY_HIDESYM 1
21668+#endif
21669 #include <linux/kallsyms.h>
21670 #include <linux/kprobes.h>
21671 #include <linux/uaccess.h>
21672@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21673 static void
21674 print_ftrace_graph_addr(unsigned long addr, void *data,
21675 const struct stacktrace_ops *ops,
21676- struct thread_info *tinfo, int *graph)
21677+ struct task_struct *task, int *graph)
21678 {
21679- struct task_struct *task;
21680 unsigned long ret_addr;
21681 int index;
21682
21683 if (addr != (unsigned long)return_to_handler)
21684 return;
21685
21686- task = tinfo->task;
21687 index = task->curr_ret_stack;
21688
21689 if (!task->ret_stack || index < *graph)
21690@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21691 static inline void
21692 print_ftrace_graph_addr(unsigned long addr, void *data,
21693 const struct stacktrace_ops *ops,
21694- struct thread_info *tinfo, int *graph)
21695+ struct task_struct *task, int *graph)
21696 { }
21697 #endif
21698
21699@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21700 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21701 */
21702
21703-static inline int valid_stack_ptr(struct thread_info *tinfo,
21704- void *p, unsigned int size, void *end)
21705+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21706 {
21707- void *t = tinfo;
21708 if (end) {
21709 if (p < end && p >= (end-THREAD_SIZE))
21710 return 1;
21711@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21712 }
21713
21714 unsigned long
21715-print_context_stack(struct thread_info *tinfo,
21716+print_context_stack(struct task_struct *task, void *stack_start,
21717 unsigned long *stack, unsigned long bp,
21718 const struct stacktrace_ops *ops, void *data,
21719 unsigned long *end, int *graph)
21720 {
21721 struct stack_frame *frame = (struct stack_frame *)bp;
21722
21723- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21724+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21725 unsigned long addr;
21726
21727 addr = *stack;
21728@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21729 } else {
21730 ops->address(data, addr, 0);
21731 }
21732- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21733+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21734 }
21735 stack++;
21736 }
21737@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21738 EXPORT_SYMBOL_GPL(print_context_stack);
21739
21740 unsigned long
21741-print_context_stack_bp(struct thread_info *tinfo,
21742+print_context_stack_bp(struct task_struct *task, void *stack_start,
21743 unsigned long *stack, unsigned long bp,
21744 const struct stacktrace_ops *ops, void *data,
21745 unsigned long *end, int *graph)
21746@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21747 struct stack_frame *frame = (struct stack_frame *)bp;
21748 unsigned long *ret_addr = &frame->return_address;
21749
21750- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21751+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21752 unsigned long addr = *ret_addr;
21753
21754 if (!__kernel_text_address(addr))
21755@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21756 ops->address(data, addr, 1);
21757 frame = frame->next_frame;
21758 ret_addr = &frame->return_address;
21759- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21760+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21761 }
21762
21763 return (unsigned long)frame;
21764@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21765 static void print_trace_address(void *data, unsigned long addr, int reliable)
21766 {
21767 touch_nmi_watchdog();
21768- printk(data);
21769+ printk("%s", (char *)data);
21770 printk_stack_address(addr, reliable);
21771 }
21772
21773@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21774 }
21775 EXPORT_SYMBOL_GPL(oops_begin);
21776
21777+extern void gr_handle_kernel_exploit(void);
21778+
21779 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21780 {
21781 if (regs && kexec_should_crash(current))
21782@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21783 panic("Fatal exception in interrupt");
21784 if (panic_on_oops)
21785 panic("Fatal exception");
21786- do_exit(signr);
21787+
21788+ gr_handle_kernel_exploit();
21789+
21790+ do_group_exit(signr);
21791 }
21792
21793 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21794@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21795 print_modules();
21796 show_regs(regs);
21797 #ifdef CONFIG_X86_32
21798- if (user_mode_vm(regs)) {
21799+ if (user_mode(regs)) {
21800 sp = regs->sp;
21801 ss = regs->ss & 0xffff;
21802 } else {
21803@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21804 unsigned long flags = oops_begin();
21805 int sig = SIGSEGV;
21806
21807- if (!user_mode_vm(regs))
21808+ if (!user_mode(regs))
21809 report_bug(regs->ip, regs);
21810
21811 if (__die(str, regs, err))
21812diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21813index 5abd4cd..c65733b 100644
21814--- a/arch/x86/kernel/dumpstack_32.c
21815+++ b/arch/x86/kernel/dumpstack_32.c
21816@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21817 bp = stack_frame(task, regs);
21818
21819 for (;;) {
21820- struct thread_info *context;
21821+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21822 void *end_stack;
21823
21824 end_stack = is_hardirq_stack(stack, cpu);
21825 if (!end_stack)
21826 end_stack = is_softirq_stack(stack, cpu);
21827
21828- context = task_thread_info(task);
21829- bp = ops->walk_stack(context, stack, bp, ops, data,
21830+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
21831 end_stack, &graph);
21832
21833 /* Stop if not on irq stack */
21834@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
21835 int i;
21836
21837 show_regs_print_info(KERN_EMERG);
21838- __show_regs(regs, !user_mode_vm(regs));
21839+ __show_regs(regs, !user_mode(regs));
21840
21841 /*
21842 * When in-kernel, we also print out the stack and code at the
21843 * time of the fault..
21844 */
21845- if (!user_mode_vm(regs)) {
21846+ if (!user_mode(regs)) {
21847 unsigned int code_prologue = code_bytes * 43 / 64;
21848 unsigned int code_len = code_bytes;
21849 unsigned char c;
21850 u8 *ip;
21851+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21852
21853 pr_emerg("Stack:\n");
21854 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21855
21856 pr_emerg("Code:");
21857
21858- ip = (u8 *)regs->ip - code_prologue;
21859+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21860 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21861 /* try starting at IP */
21862- ip = (u8 *)regs->ip;
21863+ ip = (u8 *)regs->ip + cs_base;
21864 code_len = code_len - code_prologue + 1;
21865 }
21866 for (i = 0; i < code_len; i++, ip++) {
21867@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
21868 pr_cont(" Bad EIP value.");
21869 break;
21870 }
21871- if (ip == (u8 *)regs->ip)
21872+ if (ip == (u8 *)regs->ip + cs_base)
21873 pr_cont(" <%02x>", c);
21874 else
21875 pr_cont(" %02x", c);
21876@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
21877 {
21878 unsigned short ud2;
21879
21880+ ip = ktla_ktva(ip);
21881 if (ip < PAGE_OFFSET)
21882 return 0;
21883 if (probe_kernel_address((unsigned short *)ip, ud2))
21884@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
21885
21886 return ud2 == 0x0b0f;
21887 }
21888+
21889+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21890+void pax_check_alloca(unsigned long size)
21891+{
21892+ unsigned long sp = (unsigned long)&sp, stack_left;
21893+
21894+ /* all kernel stacks are of the same size */
21895+ stack_left = sp & (THREAD_SIZE - 1);
21896+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21897+}
21898+EXPORT_SYMBOL(pax_check_alloca);
21899+#endif
21900diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21901index 1abcb50..6c8d702 100644
21902--- a/arch/x86/kernel/dumpstack_64.c
21903+++ b/arch/x86/kernel/dumpstack_64.c
21904@@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21905 const struct stacktrace_ops *ops, void *data)
21906 {
21907 const unsigned cpu = get_cpu();
21908- struct thread_info *tinfo;
21909 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21910 unsigned long dummy;
21911 unsigned used = 0;
21912 int graph = 0;
21913 int done = 0;
21914+ void *stack_start;
21915
21916 if (!task)
21917 task = current;
21918@@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21919 * current stack address. If the stacks consist of nested
21920 * exceptions
21921 */
21922- tinfo = task_thread_info(task);
21923 while (!done) {
21924 unsigned long *stack_end;
21925 enum stack_type stype;
21926@@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21927 if (ops->stack(data, id) < 0)
21928 break;
21929
21930- bp = ops->walk_stack(tinfo, stack, bp, ops,
21931+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
21932 data, stack_end, &graph);
21933 ops->stack(data, "<EOE>");
21934 /*
21935@@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21936 * second-to-last pointer (index -2 to end) in the
21937 * exception stack:
21938 */
21939+ if ((u16)stack_end[-1] != __KERNEL_DS)
21940+ goto out;
21941 stack = (unsigned long *) stack_end[-2];
21942 done = 0;
21943 break;
21944@@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21945
21946 if (ops->stack(data, "IRQ") < 0)
21947 break;
21948- bp = ops->walk_stack(tinfo, stack, bp,
21949+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21950 ops, data, stack_end, &graph);
21951 /*
21952 * We link to the next stack (which would be
21953@@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21954 /*
21955 * This handles the process stack:
21956 */
21957- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21958+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21959+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21960+out:
21961 put_cpu();
21962 }
21963 EXPORT_SYMBOL(dump_trace);
21964@@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
21965
21966 return ud2 == 0x0b0f;
21967 }
21968+
21969+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21970+void pax_check_alloca(unsigned long size)
21971+{
21972+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21973+ unsigned cpu, used;
21974+ char *id;
21975+
21976+ /* check the process stack first */
21977+ stack_start = (unsigned long)task_stack_page(current);
21978+ stack_end = stack_start + THREAD_SIZE;
21979+ if (likely(stack_start <= sp && sp < stack_end)) {
21980+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21981+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21982+ return;
21983+ }
21984+
21985+ cpu = get_cpu();
21986+
21987+ /* check the irq stacks */
21988+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21989+ stack_start = stack_end - IRQ_STACK_SIZE;
21990+ if (stack_start <= sp && sp < stack_end) {
21991+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21992+ put_cpu();
21993+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21994+ return;
21995+ }
21996+
21997+ /* check the exception stacks */
21998+ used = 0;
21999+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22000+ stack_start = stack_end - EXCEPTION_STKSZ;
22001+ if (stack_end && stack_start <= sp && sp < stack_end) {
22002+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22003+ put_cpu();
22004+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22005+ return;
22006+ }
22007+
22008+ put_cpu();
22009+
22010+ /* unknown stack */
22011+ BUG();
22012+}
22013+EXPORT_SYMBOL(pax_check_alloca);
22014+#endif
22015diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22016index 988c00a..4f673b6 100644
22017--- a/arch/x86/kernel/e820.c
22018+++ b/arch/x86/kernel/e820.c
22019@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22020
22021 static void early_panic(char *msg)
22022 {
22023- early_printk(msg);
22024- panic(msg);
22025+ early_printk("%s", msg);
22026+ panic("%s", msg);
22027 }
22028
22029 static int userdef __initdata;
22030diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22031index 01d1c18..8073693 100644
22032--- a/arch/x86/kernel/early_printk.c
22033+++ b/arch/x86/kernel/early_printk.c
22034@@ -7,6 +7,7 @@
22035 #include <linux/pci_regs.h>
22036 #include <linux/pci_ids.h>
22037 #include <linux/errno.h>
22038+#include <linux/sched.h>
22039 #include <asm/io.h>
22040 #include <asm/processor.h>
22041 #include <asm/fcntl.h>
22042diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22043index c5a9cb9..228d280 100644
22044--- a/arch/x86/kernel/entry_32.S
22045+++ b/arch/x86/kernel/entry_32.S
22046@@ -177,13 +177,153 @@
22047 /*CFI_REL_OFFSET gs, PT_GS*/
22048 .endm
22049 .macro SET_KERNEL_GS reg
22050+
22051+#ifdef CONFIG_CC_STACKPROTECTOR
22052 movl $(__KERNEL_STACK_CANARY), \reg
22053+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22054+ movl $(__USER_DS), \reg
22055+#else
22056+ xorl \reg, \reg
22057+#endif
22058+
22059 movl \reg, %gs
22060 .endm
22061
22062 #endif /* CONFIG_X86_32_LAZY_GS */
22063
22064-.macro SAVE_ALL
22065+.macro pax_enter_kernel
22066+#ifdef CONFIG_PAX_KERNEXEC
22067+ call pax_enter_kernel
22068+#endif
22069+.endm
22070+
22071+.macro pax_exit_kernel
22072+#ifdef CONFIG_PAX_KERNEXEC
22073+ call pax_exit_kernel
22074+#endif
22075+.endm
22076+
22077+#ifdef CONFIG_PAX_KERNEXEC
22078+ENTRY(pax_enter_kernel)
22079+#ifdef CONFIG_PARAVIRT
22080+ pushl %eax
22081+ pushl %ecx
22082+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22083+ mov %eax, %esi
22084+#else
22085+ mov %cr0, %esi
22086+#endif
22087+ bts $16, %esi
22088+ jnc 1f
22089+ mov %cs, %esi
22090+ cmp $__KERNEL_CS, %esi
22091+ jz 3f
22092+ ljmp $__KERNEL_CS, $3f
22093+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22094+2:
22095+#ifdef CONFIG_PARAVIRT
22096+ mov %esi, %eax
22097+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22098+#else
22099+ mov %esi, %cr0
22100+#endif
22101+3:
22102+#ifdef CONFIG_PARAVIRT
22103+ popl %ecx
22104+ popl %eax
22105+#endif
22106+ ret
22107+ENDPROC(pax_enter_kernel)
22108+
22109+ENTRY(pax_exit_kernel)
22110+#ifdef CONFIG_PARAVIRT
22111+ pushl %eax
22112+ pushl %ecx
22113+#endif
22114+ mov %cs, %esi
22115+ cmp $__KERNEXEC_KERNEL_CS, %esi
22116+ jnz 2f
22117+#ifdef CONFIG_PARAVIRT
22118+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22119+ mov %eax, %esi
22120+#else
22121+ mov %cr0, %esi
22122+#endif
22123+ btr $16, %esi
22124+ ljmp $__KERNEL_CS, $1f
22125+1:
22126+#ifdef CONFIG_PARAVIRT
22127+ mov %esi, %eax
22128+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22129+#else
22130+ mov %esi, %cr0
22131+#endif
22132+2:
22133+#ifdef CONFIG_PARAVIRT
22134+ popl %ecx
22135+ popl %eax
22136+#endif
22137+ ret
22138+ENDPROC(pax_exit_kernel)
22139+#endif
22140+
22141+ .macro pax_erase_kstack
22142+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22143+ call pax_erase_kstack
22144+#endif
22145+ .endm
22146+
22147+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22148+/*
22149+ * ebp: thread_info
22150+ */
22151+ENTRY(pax_erase_kstack)
22152+ pushl %edi
22153+ pushl %ecx
22154+ pushl %eax
22155+
22156+ mov TI_lowest_stack(%ebp), %edi
22157+ mov $-0xBEEF, %eax
22158+ std
22159+
22160+1: mov %edi, %ecx
22161+ and $THREAD_SIZE_asm - 1, %ecx
22162+ shr $2, %ecx
22163+ repne scasl
22164+ jecxz 2f
22165+
22166+ cmp $2*16, %ecx
22167+ jc 2f
22168+
22169+ mov $2*16, %ecx
22170+ repe scasl
22171+ jecxz 2f
22172+ jne 1b
22173+
22174+2: cld
22175+ mov %esp, %ecx
22176+ sub %edi, %ecx
22177+
22178+ cmp $THREAD_SIZE_asm, %ecx
22179+ jb 3f
22180+ ud2
22181+3:
22182+
22183+ shr $2, %ecx
22184+ rep stosl
22185+
22186+ mov TI_task_thread_sp0(%ebp), %edi
22187+ sub $128, %edi
22188+ mov %edi, TI_lowest_stack(%ebp)
22189+
22190+ popl %eax
22191+ popl %ecx
22192+ popl %edi
22193+ ret
22194+ENDPROC(pax_erase_kstack)
22195+#endif
22196+
22197+.macro __SAVE_ALL _DS
22198 cld
22199 PUSH_GS
22200 pushl_cfi %fs
22201@@ -206,7 +346,7 @@
22202 CFI_REL_OFFSET ecx, 0
22203 pushl_cfi %ebx
22204 CFI_REL_OFFSET ebx, 0
22205- movl $(__USER_DS), %edx
22206+ movl $\_DS, %edx
22207 movl %edx, %ds
22208 movl %edx, %es
22209 movl $(__KERNEL_PERCPU), %edx
22210@@ -214,6 +354,15 @@
22211 SET_KERNEL_GS %edx
22212 .endm
22213
22214+.macro SAVE_ALL
22215+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22216+ __SAVE_ALL __KERNEL_DS
22217+ pax_enter_kernel
22218+#else
22219+ __SAVE_ALL __USER_DS
22220+#endif
22221+.endm
22222+
22223 .macro RESTORE_INT_REGS
22224 popl_cfi %ebx
22225 CFI_RESTORE ebx
22226@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22227 popfl_cfi
22228 jmp syscall_exit
22229 CFI_ENDPROC
22230-END(ret_from_fork)
22231+ENDPROC(ret_from_fork)
22232
22233 ENTRY(ret_from_kernel_thread)
22234 CFI_STARTPROC
22235@@ -344,7 +493,15 @@ ret_from_intr:
22236 andl $SEGMENT_RPL_MASK, %eax
22237 #endif
22238 cmpl $USER_RPL, %eax
22239+
22240+#ifdef CONFIG_PAX_KERNEXEC
22241+ jae resume_userspace
22242+
22243+ pax_exit_kernel
22244+ jmp resume_kernel
22245+#else
22246 jb resume_kernel # not returning to v8086 or userspace
22247+#endif
22248
22249 ENTRY(resume_userspace)
22250 LOCKDEP_SYS_EXIT
22251@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22252 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22253 # int/exception return?
22254 jne work_pending
22255- jmp restore_all
22256-END(ret_from_exception)
22257+ jmp restore_all_pax
22258+ENDPROC(ret_from_exception)
22259
22260 #ifdef CONFIG_PREEMPT
22261 ENTRY(resume_kernel)
22262@@ -369,7 +526,7 @@ need_resched:
22263 jz restore_all
22264 call preempt_schedule_irq
22265 jmp need_resched
22266-END(resume_kernel)
22267+ENDPROC(resume_kernel)
22268 #endif
22269 CFI_ENDPROC
22270 /*
22271@@ -403,30 +560,45 @@ sysenter_past_esp:
22272 /*CFI_REL_OFFSET cs, 0*/
22273 /*
22274 * Push current_thread_info()->sysenter_return to the stack.
22275- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22276- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22277 */
22278- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22279+ pushl_cfi $0
22280 CFI_REL_OFFSET eip, 0
22281
22282 pushl_cfi %eax
22283 SAVE_ALL
22284+ GET_THREAD_INFO(%ebp)
22285+ movl TI_sysenter_return(%ebp),%ebp
22286+ movl %ebp,PT_EIP(%esp)
22287 ENABLE_INTERRUPTS(CLBR_NONE)
22288
22289 /*
22290 * Load the potential sixth argument from user stack.
22291 * Careful about security.
22292 */
22293+ movl PT_OLDESP(%esp),%ebp
22294+
22295+#ifdef CONFIG_PAX_MEMORY_UDEREF
22296+ mov PT_OLDSS(%esp),%ds
22297+1: movl %ds:(%ebp),%ebp
22298+ push %ss
22299+ pop %ds
22300+#else
22301 cmpl $__PAGE_OFFSET-3,%ebp
22302 jae syscall_fault
22303 ASM_STAC
22304 1: movl (%ebp),%ebp
22305 ASM_CLAC
22306+#endif
22307+
22308 movl %ebp,PT_EBP(%esp)
22309 _ASM_EXTABLE(1b,syscall_fault)
22310
22311 GET_THREAD_INFO(%ebp)
22312
22313+#ifdef CONFIG_PAX_RANDKSTACK
22314+ pax_erase_kstack
22315+#endif
22316+
22317 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22318 jnz sysenter_audit
22319 sysenter_do_call:
22320@@ -442,12 +614,24 @@ sysenter_after_call:
22321 testl $_TIF_ALLWORK_MASK, %ecx
22322 jne sysexit_audit
22323 sysenter_exit:
22324+
22325+#ifdef CONFIG_PAX_RANDKSTACK
22326+ pushl_cfi %eax
22327+ movl %esp, %eax
22328+ call pax_randomize_kstack
22329+ popl_cfi %eax
22330+#endif
22331+
22332+ pax_erase_kstack
22333+
22334 /* if something modifies registers it must also disable sysexit */
22335 movl PT_EIP(%esp), %edx
22336 movl PT_OLDESP(%esp), %ecx
22337 xorl %ebp,%ebp
22338 TRACE_IRQS_ON
22339 1: mov PT_FS(%esp), %fs
22340+2: mov PT_DS(%esp), %ds
22341+3: mov PT_ES(%esp), %es
22342 PTGS_TO_GS
22343 ENABLE_INTERRUPTS_SYSEXIT
22344
22345@@ -464,6 +648,9 @@ sysenter_audit:
22346 movl %eax,%edx /* 2nd arg: syscall number */
22347 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22348 call __audit_syscall_entry
22349+
22350+ pax_erase_kstack
22351+
22352 pushl_cfi %ebx
22353 movl PT_EAX(%esp),%eax /* reload syscall number */
22354 jmp sysenter_do_call
22355@@ -489,10 +676,16 @@ sysexit_audit:
22356
22357 CFI_ENDPROC
22358 .pushsection .fixup,"ax"
22359-2: movl $0,PT_FS(%esp)
22360+4: movl $0,PT_FS(%esp)
22361+ jmp 1b
22362+5: movl $0,PT_DS(%esp)
22363+ jmp 1b
22364+6: movl $0,PT_ES(%esp)
22365 jmp 1b
22366 .popsection
22367- _ASM_EXTABLE(1b,2b)
22368+ _ASM_EXTABLE(1b,4b)
22369+ _ASM_EXTABLE(2b,5b)
22370+ _ASM_EXTABLE(3b,6b)
22371 PTGS_TO_GS_EX
22372 ENDPROC(ia32_sysenter_target)
22373
22374@@ -507,6 +700,11 @@ ENTRY(system_call)
22375 pushl_cfi %eax # save orig_eax
22376 SAVE_ALL
22377 GET_THREAD_INFO(%ebp)
22378+
22379+#ifdef CONFIG_PAX_RANDKSTACK
22380+ pax_erase_kstack
22381+#endif
22382+
22383 # system call tracing in operation / emulation
22384 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22385 jnz syscall_trace_entry
22386@@ -526,6 +724,15 @@ syscall_exit:
22387 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22388 jne syscall_exit_work
22389
22390+restore_all_pax:
22391+
22392+#ifdef CONFIG_PAX_RANDKSTACK
22393+ movl %esp, %eax
22394+ call pax_randomize_kstack
22395+#endif
22396+
22397+ pax_erase_kstack
22398+
22399 restore_all:
22400 TRACE_IRQS_IRET
22401 restore_all_notrace:
22402@@ -580,14 +787,34 @@ ldt_ss:
22403 * compensating for the offset by changing to the ESPFIX segment with
22404 * a base address that matches for the difference.
22405 */
22406-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22407+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22408 mov %esp, %edx /* load kernel esp */
22409 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22410 mov %dx, %ax /* eax: new kernel esp */
22411 sub %eax, %edx /* offset (low word is 0) */
22412+#ifdef CONFIG_SMP
22413+ movl PER_CPU_VAR(cpu_number), %ebx
22414+ shll $PAGE_SHIFT_asm, %ebx
22415+ addl $cpu_gdt_table, %ebx
22416+#else
22417+ movl $cpu_gdt_table, %ebx
22418+#endif
22419 shr $16, %edx
22420- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22421- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22422+
22423+#ifdef CONFIG_PAX_KERNEXEC
22424+ mov %cr0, %esi
22425+ btr $16, %esi
22426+ mov %esi, %cr0
22427+#endif
22428+
22429+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22430+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22431+
22432+#ifdef CONFIG_PAX_KERNEXEC
22433+ bts $16, %esi
22434+ mov %esi, %cr0
22435+#endif
22436+
22437 pushl_cfi $__ESPFIX_SS
22438 pushl_cfi %eax /* new kernel esp */
22439 /* Disable interrupts, but do not irqtrace this section: we
22440@@ -617,20 +844,18 @@ work_resched:
22441 movl TI_flags(%ebp), %ecx
22442 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22443 # than syscall tracing?
22444- jz restore_all
22445+ jz restore_all_pax
22446 testb $_TIF_NEED_RESCHED, %cl
22447 jnz work_resched
22448
22449 work_notifysig: # deal with pending signals and
22450 # notify-resume requests
22451+ movl %esp, %eax
22452 #ifdef CONFIG_VM86
22453 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22454- movl %esp, %eax
22455 jne work_notifysig_v86 # returning to kernel-space or
22456 # vm86-space
22457 1:
22458-#else
22459- movl %esp, %eax
22460 #endif
22461 TRACE_IRQS_ON
22462 ENABLE_INTERRUPTS(CLBR_NONE)
22463@@ -651,7 +876,7 @@ work_notifysig_v86:
22464 movl %eax, %esp
22465 jmp 1b
22466 #endif
22467-END(work_pending)
22468+ENDPROC(work_pending)
22469
22470 # perform syscall exit tracing
22471 ALIGN
22472@@ -659,11 +884,14 @@ syscall_trace_entry:
22473 movl $-ENOSYS,PT_EAX(%esp)
22474 movl %esp, %eax
22475 call syscall_trace_enter
22476+
22477+ pax_erase_kstack
22478+
22479 /* What it returned is what we'll actually use. */
22480 cmpl $(NR_syscalls), %eax
22481 jnae syscall_call
22482 jmp syscall_exit
22483-END(syscall_trace_entry)
22484+ENDPROC(syscall_trace_entry)
22485
22486 # perform syscall exit tracing
22487 ALIGN
22488@@ -676,26 +904,30 @@ syscall_exit_work:
22489 movl %esp, %eax
22490 call syscall_trace_leave
22491 jmp resume_userspace
22492-END(syscall_exit_work)
22493+ENDPROC(syscall_exit_work)
22494 CFI_ENDPROC
22495
22496 RING0_INT_FRAME # can't unwind into user space anyway
22497 syscall_fault:
22498+#ifdef CONFIG_PAX_MEMORY_UDEREF
22499+ push %ss
22500+ pop %ds
22501+#endif
22502 ASM_CLAC
22503 GET_THREAD_INFO(%ebp)
22504 movl $-EFAULT,PT_EAX(%esp)
22505 jmp resume_userspace
22506-END(syscall_fault)
22507+ENDPROC(syscall_fault)
22508
22509 syscall_badsys:
22510 movl $-ENOSYS,%eax
22511 jmp syscall_after_call
22512-END(syscall_badsys)
22513+ENDPROC(syscall_badsys)
22514
22515 sysenter_badsys:
22516 movl $-ENOSYS,%eax
22517 jmp sysenter_after_call
22518-END(syscall_badsys)
22519+ENDPROC(sysenter_badsys)
22520 CFI_ENDPROC
22521 /*
22522 * End of kprobes section
22523@@ -712,8 +944,15 @@ END(syscall_badsys)
22524 */
22525 #ifdef CONFIG_X86_ESPFIX32
22526 /* fixup the stack */
22527- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22528- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22529+#ifdef CONFIG_SMP
22530+ movl PER_CPU_VAR(cpu_number), %ebx
22531+ shll $PAGE_SHIFT_asm, %ebx
22532+ addl $cpu_gdt_table, %ebx
22533+#else
22534+ movl $cpu_gdt_table, %ebx
22535+#endif
22536+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22537+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22538 shl $16, %eax
22539 addl %esp, %eax /* the adjusted stack pointer */
22540 pushl_cfi $__KERNEL_DS
22541@@ -769,7 +1008,7 @@ vector=vector+1
22542 .endr
22543 2: jmp common_interrupt
22544 .endr
22545-END(irq_entries_start)
22546+ENDPROC(irq_entries_start)
22547
22548 .previous
22549 END(interrupt)
22550@@ -830,7 +1069,7 @@ ENTRY(coprocessor_error)
22551 pushl_cfi $do_coprocessor_error
22552 jmp error_code
22553 CFI_ENDPROC
22554-END(coprocessor_error)
22555+ENDPROC(coprocessor_error)
22556
22557 ENTRY(simd_coprocessor_error)
22558 RING0_INT_FRAME
22559@@ -843,7 +1082,7 @@ ENTRY(simd_coprocessor_error)
22560 .section .altinstructions,"a"
22561 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22562 .previous
22563-.section .altinstr_replacement,"ax"
22564+.section .altinstr_replacement,"a"
22565 663: pushl $do_simd_coprocessor_error
22566 664:
22567 .previous
22568@@ -852,7 +1091,7 @@ ENTRY(simd_coprocessor_error)
22569 #endif
22570 jmp error_code
22571 CFI_ENDPROC
22572-END(simd_coprocessor_error)
22573+ENDPROC(simd_coprocessor_error)
22574
22575 ENTRY(device_not_available)
22576 RING0_INT_FRAME
22577@@ -861,18 +1100,18 @@ ENTRY(device_not_available)
22578 pushl_cfi $do_device_not_available
22579 jmp error_code
22580 CFI_ENDPROC
22581-END(device_not_available)
22582+ENDPROC(device_not_available)
22583
22584 #ifdef CONFIG_PARAVIRT
22585 ENTRY(native_iret)
22586 iret
22587 _ASM_EXTABLE(native_iret, iret_exc)
22588-END(native_iret)
22589+ENDPROC(native_iret)
22590
22591 ENTRY(native_irq_enable_sysexit)
22592 sti
22593 sysexit
22594-END(native_irq_enable_sysexit)
22595+ENDPROC(native_irq_enable_sysexit)
22596 #endif
22597
22598 ENTRY(overflow)
22599@@ -882,7 +1121,7 @@ ENTRY(overflow)
22600 pushl_cfi $do_overflow
22601 jmp error_code
22602 CFI_ENDPROC
22603-END(overflow)
22604+ENDPROC(overflow)
22605
22606 ENTRY(bounds)
22607 RING0_INT_FRAME
22608@@ -891,7 +1130,7 @@ ENTRY(bounds)
22609 pushl_cfi $do_bounds
22610 jmp error_code
22611 CFI_ENDPROC
22612-END(bounds)
22613+ENDPROC(bounds)
22614
22615 ENTRY(invalid_op)
22616 RING0_INT_FRAME
22617@@ -900,7 +1139,7 @@ ENTRY(invalid_op)
22618 pushl_cfi $do_invalid_op
22619 jmp error_code
22620 CFI_ENDPROC
22621-END(invalid_op)
22622+ENDPROC(invalid_op)
22623
22624 ENTRY(coprocessor_segment_overrun)
22625 RING0_INT_FRAME
22626@@ -909,7 +1148,7 @@ ENTRY(coprocessor_segment_overrun)
22627 pushl_cfi $do_coprocessor_segment_overrun
22628 jmp error_code
22629 CFI_ENDPROC
22630-END(coprocessor_segment_overrun)
22631+ENDPROC(coprocessor_segment_overrun)
22632
22633 ENTRY(invalid_TSS)
22634 RING0_EC_FRAME
22635@@ -917,7 +1156,7 @@ ENTRY(invalid_TSS)
22636 pushl_cfi $do_invalid_TSS
22637 jmp error_code
22638 CFI_ENDPROC
22639-END(invalid_TSS)
22640+ENDPROC(invalid_TSS)
22641
22642 ENTRY(segment_not_present)
22643 RING0_EC_FRAME
22644@@ -925,7 +1164,7 @@ ENTRY(segment_not_present)
22645 pushl_cfi $do_segment_not_present
22646 jmp error_code
22647 CFI_ENDPROC
22648-END(segment_not_present)
22649+ENDPROC(segment_not_present)
22650
22651 ENTRY(stack_segment)
22652 RING0_EC_FRAME
22653@@ -933,7 +1172,7 @@ ENTRY(stack_segment)
22654 pushl_cfi $do_stack_segment
22655 jmp error_code
22656 CFI_ENDPROC
22657-END(stack_segment)
22658+ENDPROC(stack_segment)
22659
22660 ENTRY(alignment_check)
22661 RING0_EC_FRAME
22662@@ -941,7 +1180,7 @@ ENTRY(alignment_check)
22663 pushl_cfi $do_alignment_check
22664 jmp error_code
22665 CFI_ENDPROC
22666-END(alignment_check)
22667+ENDPROC(alignment_check)
22668
22669 ENTRY(divide_error)
22670 RING0_INT_FRAME
22671@@ -950,7 +1189,7 @@ ENTRY(divide_error)
22672 pushl_cfi $do_divide_error
22673 jmp error_code
22674 CFI_ENDPROC
22675-END(divide_error)
22676+ENDPROC(divide_error)
22677
22678 #ifdef CONFIG_X86_MCE
22679 ENTRY(machine_check)
22680@@ -960,7 +1199,7 @@ ENTRY(machine_check)
22681 pushl_cfi machine_check_vector
22682 jmp error_code
22683 CFI_ENDPROC
22684-END(machine_check)
22685+ENDPROC(machine_check)
22686 #endif
22687
22688 ENTRY(spurious_interrupt_bug)
22689@@ -970,7 +1209,7 @@ ENTRY(spurious_interrupt_bug)
22690 pushl_cfi $do_spurious_interrupt_bug
22691 jmp error_code
22692 CFI_ENDPROC
22693-END(spurious_interrupt_bug)
22694+ENDPROC(spurious_interrupt_bug)
22695 /*
22696 * End of kprobes section
22697 */
22698@@ -1080,7 +1319,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22699
22700 ENTRY(mcount)
22701 ret
22702-END(mcount)
22703+ENDPROC(mcount)
22704
22705 ENTRY(ftrace_caller)
22706 cmpl $0, function_trace_stop
22707@@ -1113,7 +1352,7 @@ ftrace_graph_call:
22708 .globl ftrace_stub
22709 ftrace_stub:
22710 ret
22711-END(ftrace_caller)
22712+ENDPROC(ftrace_caller)
22713
22714 ENTRY(ftrace_regs_caller)
22715 pushf /* push flags before compare (in cs location) */
22716@@ -1217,7 +1456,7 @@ trace:
22717 popl %ecx
22718 popl %eax
22719 jmp ftrace_stub
22720-END(mcount)
22721+ENDPROC(mcount)
22722 #endif /* CONFIG_DYNAMIC_FTRACE */
22723 #endif /* CONFIG_FUNCTION_TRACER */
22724
22725@@ -1235,7 +1474,7 @@ ENTRY(ftrace_graph_caller)
22726 popl %ecx
22727 popl %eax
22728 ret
22729-END(ftrace_graph_caller)
22730+ENDPROC(ftrace_graph_caller)
22731
22732 .globl return_to_handler
22733 return_to_handler:
22734@@ -1301,15 +1540,18 @@ error_code:
22735 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22736 REG_TO_PTGS %ecx
22737 SET_KERNEL_GS %ecx
22738- movl $(__USER_DS), %ecx
22739+ movl $(__KERNEL_DS), %ecx
22740 movl %ecx, %ds
22741 movl %ecx, %es
22742+
22743+ pax_enter_kernel
22744+
22745 TRACE_IRQS_OFF
22746 movl %esp,%eax # pt_regs pointer
22747 call *%edi
22748 jmp ret_from_exception
22749 CFI_ENDPROC
22750-END(page_fault)
22751+ENDPROC(page_fault)
22752
22753 /*
22754 * Debug traps and NMI can happen at the one SYSENTER instruction
22755@@ -1352,7 +1594,7 @@ debug_stack_correct:
22756 call do_debug
22757 jmp ret_from_exception
22758 CFI_ENDPROC
22759-END(debug)
22760+ENDPROC(debug)
22761
22762 /*
22763 * NMI is doubly nasty. It can happen _while_ we're handling
22764@@ -1392,6 +1634,9 @@ nmi_stack_correct:
22765 xorl %edx,%edx # zero error code
22766 movl %esp,%eax # pt_regs pointer
22767 call do_nmi
22768+
22769+ pax_exit_kernel
22770+
22771 jmp restore_all_notrace
22772 CFI_ENDPROC
22773
22774@@ -1429,13 +1674,16 @@ nmi_espfix_stack:
22775 FIXUP_ESPFIX_STACK # %eax == %esp
22776 xorl %edx,%edx # zero error code
22777 call do_nmi
22778+
22779+ pax_exit_kernel
22780+
22781 RESTORE_REGS
22782 lss 12+4(%esp), %esp # back to espfix stack
22783 CFI_ADJUST_CFA_OFFSET -24
22784 jmp irq_return
22785 #endif
22786 CFI_ENDPROC
22787-END(nmi)
22788+ENDPROC(nmi)
22789
22790 ENTRY(int3)
22791 RING0_INT_FRAME
22792@@ -1448,14 +1696,14 @@ ENTRY(int3)
22793 call do_int3
22794 jmp ret_from_exception
22795 CFI_ENDPROC
22796-END(int3)
22797+ENDPROC(int3)
22798
22799 ENTRY(general_protection)
22800 RING0_EC_FRAME
22801 pushl_cfi $do_general_protection
22802 jmp error_code
22803 CFI_ENDPROC
22804-END(general_protection)
22805+ENDPROC(general_protection)
22806
22807 #ifdef CONFIG_KVM_GUEST
22808 ENTRY(async_page_fault)
22809@@ -1464,7 +1712,7 @@ ENTRY(async_page_fault)
22810 pushl_cfi $do_async_page_fault
22811 jmp error_code
22812 CFI_ENDPROC
22813-END(async_page_fault)
22814+ENDPROC(async_page_fault)
22815 #endif
22816
22817 /*
22818diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22819index 03cd2a8..05a9aed 100644
22820--- a/arch/x86/kernel/entry_64.S
22821+++ b/arch/x86/kernel/entry_64.S
22822@@ -60,6 +60,8 @@
22823 #include <asm/smap.h>
22824 #include <asm/pgtable_types.h>
22825 #include <linux/err.h>
22826+#include <asm/pgtable.h>
22827+#include <asm/alternative-asm.h>
22828
22829 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22830 #include <linux/elf-em.h>
22831@@ -81,8 +83,9 @@
22832 #ifdef CONFIG_DYNAMIC_FTRACE
22833
22834 ENTRY(function_hook)
22835+ pax_force_retaddr
22836 retq
22837-END(function_hook)
22838+ENDPROC(function_hook)
22839
22840 /* skip is set if stack has been adjusted */
22841 .macro ftrace_caller_setup skip=0
22842@@ -123,8 +126,9 @@ GLOBAL(ftrace_graph_call)
22843 #endif
22844
22845 GLOBAL(ftrace_stub)
22846+ pax_force_retaddr
22847 retq
22848-END(ftrace_caller)
22849+ENDPROC(ftrace_caller)
22850
22851 ENTRY(ftrace_regs_caller)
22852 /* Save the current flags before compare (in SS location)*/
22853@@ -192,7 +196,7 @@ ftrace_restore_flags:
22854 popfq
22855 jmp ftrace_stub
22856
22857-END(ftrace_regs_caller)
22858+ENDPROC(ftrace_regs_caller)
22859
22860
22861 #else /* ! CONFIG_DYNAMIC_FTRACE */
22862@@ -213,6 +217,7 @@ ENTRY(function_hook)
22863 #endif
22864
22865 GLOBAL(ftrace_stub)
22866+ pax_force_retaddr
22867 retq
22868
22869 trace:
22870@@ -226,12 +231,13 @@ trace:
22871 #endif
22872 subq $MCOUNT_INSN_SIZE, %rdi
22873
22874+ pax_force_fptr ftrace_trace_function
22875 call *ftrace_trace_function
22876
22877 MCOUNT_RESTORE_FRAME
22878
22879 jmp ftrace_stub
22880-END(function_hook)
22881+ENDPROC(function_hook)
22882 #endif /* CONFIG_DYNAMIC_FTRACE */
22883 #endif /* CONFIG_FUNCTION_TRACER */
22884
22885@@ -253,8 +259,9 @@ ENTRY(ftrace_graph_caller)
22886
22887 MCOUNT_RESTORE_FRAME
22888
22889+ pax_force_retaddr
22890 retq
22891-END(ftrace_graph_caller)
22892+ENDPROC(ftrace_graph_caller)
22893
22894 GLOBAL(return_to_handler)
22895 subq $24, %rsp
22896@@ -270,7 +277,9 @@ GLOBAL(return_to_handler)
22897 movq 8(%rsp), %rdx
22898 movq (%rsp), %rax
22899 addq $24, %rsp
22900+ pax_force_fptr %rdi
22901 jmp *%rdi
22902+ENDPROC(return_to_handler)
22903 #endif
22904
22905
22906@@ -285,6 +294,430 @@ ENTRY(native_usergs_sysret64)
22907 ENDPROC(native_usergs_sysret64)
22908 #endif /* CONFIG_PARAVIRT */
22909
22910+ .macro ljmpq sel, off
22911+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22912+ .byte 0x48; ljmp *1234f(%rip)
22913+ .pushsection .rodata
22914+ .align 16
22915+ 1234: .quad \off; .word \sel
22916+ .popsection
22917+#else
22918+ pushq $\sel
22919+ pushq $\off
22920+ lretq
22921+#endif
22922+ .endm
22923+
22924+ .macro pax_enter_kernel
22925+ pax_set_fptr_mask
22926+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22927+ call pax_enter_kernel
22928+#endif
22929+ .endm
22930+
22931+ .macro pax_exit_kernel
22932+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22933+ call pax_exit_kernel
22934+#endif
22935+
22936+ .endm
22937+
22938+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22939+ENTRY(pax_enter_kernel)
22940+ pushq %rdi
22941+
22942+#ifdef CONFIG_PARAVIRT
22943+ PV_SAVE_REGS(CLBR_RDI)
22944+#endif
22945+
22946+#ifdef CONFIG_PAX_KERNEXEC
22947+ GET_CR0_INTO_RDI
22948+ bts $16,%rdi
22949+ jnc 3f
22950+ mov %cs,%edi
22951+ cmp $__KERNEL_CS,%edi
22952+ jnz 2f
22953+1:
22954+#endif
22955+
22956+#ifdef CONFIG_PAX_MEMORY_UDEREF
22957+ 661: jmp 111f
22958+ .pushsection .altinstr_replacement, "a"
22959+ 662: ASM_NOP2
22960+ .popsection
22961+ .pushsection .altinstructions, "a"
22962+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22963+ .popsection
22964+ GET_CR3_INTO_RDI
22965+ cmp $0,%dil
22966+ jnz 112f
22967+ mov $__KERNEL_DS,%edi
22968+ mov %edi,%ss
22969+ jmp 111f
22970+112: cmp $1,%dil
22971+ jz 113f
22972+ ud2
22973+113: sub $4097,%rdi
22974+ bts $63,%rdi
22975+ SET_RDI_INTO_CR3
22976+ mov $__UDEREF_KERNEL_DS,%edi
22977+ mov %edi,%ss
22978+111:
22979+#endif
22980+
22981+#ifdef CONFIG_PARAVIRT
22982+ PV_RESTORE_REGS(CLBR_RDI)
22983+#endif
22984+
22985+ popq %rdi
22986+ pax_force_retaddr
22987+ retq
22988+
22989+#ifdef CONFIG_PAX_KERNEXEC
22990+2: ljmpq __KERNEL_CS,1b
22991+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22992+4: SET_RDI_INTO_CR0
22993+ jmp 1b
22994+#endif
22995+ENDPROC(pax_enter_kernel)
22996+
22997+ENTRY(pax_exit_kernel)
22998+ pushq %rdi
22999+
23000+#ifdef CONFIG_PARAVIRT
23001+ PV_SAVE_REGS(CLBR_RDI)
23002+#endif
23003+
23004+#ifdef CONFIG_PAX_KERNEXEC
23005+ mov %cs,%rdi
23006+ cmp $__KERNEXEC_KERNEL_CS,%edi
23007+ jz 2f
23008+ GET_CR0_INTO_RDI
23009+ bts $16,%rdi
23010+ jnc 4f
23011+1:
23012+#endif
23013+
23014+#ifdef CONFIG_PAX_MEMORY_UDEREF
23015+ 661: jmp 111f
23016+ .pushsection .altinstr_replacement, "a"
23017+ 662: ASM_NOP2
23018+ .popsection
23019+ .pushsection .altinstructions, "a"
23020+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23021+ .popsection
23022+ mov %ss,%edi
23023+ cmp $__UDEREF_KERNEL_DS,%edi
23024+ jnz 111f
23025+ GET_CR3_INTO_RDI
23026+ cmp $0,%dil
23027+ jz 112f
23028+ ud2
23029+112: add $4097,%rdi
23030+ bts $63,%rdi
23031+ SET_RDI_INTO_CR3
23032+ mov $__KERNEL_DS,%edi
23033+ mov %edi,%ss
23034+111:
23035+#endif
23036+
23037+#ifdef CONFIG_PARAVIRT
23038+ PV_RESTORE_REGS(CLBR_RDI);
23039+#endif
23040+
23041+ popq %rdi
23042+ pax_force_retaddr
23043+ retq
23044+
23045+#ifdef CONFIG_PAX_KERNEXEC
23046+2: GET_CR0_INTO_RDI
23047+ btr $16,%rdi
23048+ jnc 4f
23049+ ljmpq __KERNEL_CS,3f
23050+3: SET_RDI_INTO_CR0
23051+ jmp 1b
23052+4: ud2
23053+ jmp 4b
23054+#endif
23055+ENDPROC(pax_exit_kernel)
23056+#endif
23057+
23058+ .macro pax_enter_kernel_user
23059+ pax_set_fptr_mask
23060+#ifdef CONFIG_PAX_MEMORY_UDEREF
23061+ call pax_enter_kernel_user
23062+#endif
23063+ .endm
23064+
23065+ .macro pax_exit_kernel_user
23066+#ifdef CONFIG_PAX_MEMORY_UDEREF
23067+ call pax_exit_kernel_user
23068+#endif
23069+#ifdef CONFIG_PAX_RANDKSTACK
23070+ pushq %rax
23071+ pushq %r11
23072+ call pax_randomize_kstack
23073+ popq %r11
23074+ popq %rax
23075+#endif
23076+ .endm
23077+
23078+#ifdef CONFIG_PAX_MEMORY_UDEREF
23079+ENTRY(pax_enter_kernel_user)
23080+ pushq %rdi
23081+ pushq %rbx
23082+
23083+#ifdef CONFIG_PARAVIRT
23084+ PV_SAVE_REGS(CLBR_RDI)
23085+#endif
23086+
23087+ 661: jmp 111f
23088+ .pushsection .altinstr_replacement, "a"
23089+ 662: ASM_NOP2
23090+ .popsection
23091+ .pushsection .altinstructions, "a"
23092+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23093+ .popsection
23094+ GET_CR3_INTO_RDI
23095+ cmp $1,%dil
23096+ jnz 4f
23097+ sub $4097,%rdi
23098+ bts $63,%rdi
23099+ SET_RDI_INTO_CR3
23100+ jmp 3f
23101+111:
23102+
23103+ GET_CR3_INTO_RDI
23104+ mov %rdi,%rbx
23105+ add $__START_KERNEL_map,%rbx
23106+ sub phys_base(%rip),%rbx
23107+
23108+#ifdef CONFIG_PARAVIRT
23109+ cmpl $0, pv_info+PARAVIRT_enabled
23110+ jz 1f
23111+ pushq %rdi
23112+ i = 0
23113+ .rept USER_PGD_PTRS
23114+ mov i*8(%rbx),%rsi
23115+ mov $0,%sil
23116+ lea i*8(%rbx),%rdi
23117+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23118+ i = i + 1
23119+ .endr
23120+ popq %rdi
23121+ jmp 2f
23122+1:
23123+#endif
23124+
23125+ i = 0
23126+ .rept USER_PGD_PTRS
23127+ movb $0,i*8(%rbx)
23128+ i = i + 1
23129+ .endr
23130+
23131+2: SET_RDI_INTO_CR3
23132+
23133+#ifdef CONFIG_PAX_KERNEXEC
23134+ GET_CR0_INTO_RDI
23135+ bts $16,%rdi
23136+ SET_RDI_INTO_CR0
23137+#endif
23138+
23139+3:
23140+
23141+#ifdef CONFIG_PARAVIRT
23142+ PV_RESTORE_REGS(CLBR_RDI)
23143+#endif
23144+
23145+ popq %rbx
23146+ popq %rdi
23147+ pax_force_retaddr
23148+ retq
23149+4: ud2
23150+ENDPROC(pax_enter_kernel_user)
23151+
23152+ENTRY(pax_exit_kernel_user)
23153+ pushq %rdi
23154+ pushq %rbx
23155+
23156+#ifdef CONFIG_PARAVIRT
23157+ PV_SAVE_REGS(CLBR_RDI)
23158+#endif
23159+
23160+ GET_CR3_INTO_RDI
23161+ 661: jmp 1f
23162+ .pushsection .altinstr_replacement, "a"
23163+ 662: ASM_NOP2
23164+ .popsection
23165+ .pushsection .altinstructions, "a"
23166+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23167+ .popsection
23168+ cmp $0,%dil
23169+ jnz 3f
23170+ add $4097,%rdi
23171+ bts $63,%rdi
23172+ SET_RDI_INTO_CR3
23173+ jmp 2f
23174+1:
23175+
23176+ mov %rdi,%rbx
23177+
23178+#ifdef CONFIG_PAX_KERNEXEC
23179+ GET_CR0_INTO_RDI
23180+ btr $16,%rdi
23181+ jnc 3f
23182+ SET_RDI_INTO_CR0
23183+#endif
23184+
23185+ add $__START_KERNEL_map,%rbx
23186+ sub phys_base(%rip),%rbx
23187+
23188+#ifdef CONFIG_PARAVIRT
23189+ cmpl $0, pv_info+PARAVIRT_enabled
23190+ jz 1f
23191+ i = 0
23192+ .rept USER_PGD_PTRS
23193+ mov i*8(%rbx),%rsi
23194+ mov $0x67,%sil
23195+ lea i*8(%rbx),%rdi
23196+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23197+ i = i + 1
23198+ .endr
23199+ jmp 2f
23200+1:
23201+#endif
23202+
23203+ i = 0
23204+ .rept USER_PGD_PTRS
23205+ movb $0x67,i*8(%rbx)
23206+ i = i + 1
23207+ .endr
23208+2:
23209+
23210+#ifdef CONFIG_PARAVIRT
23211+ PV_RESTORE_REGS(CLBR_RDI)
23212+#endif
23213+
23214+ popq %rbx
23215+ popq %rdi
23216+ pax_force_retaddr
23217+ retq
23218+3: ud2
23219+ENDPROC(pax_exit_kernel_user)
23220+#endif
23221+
23222+ .macro pax_enter_kernel_nmi
23223+ pax_set_fptr_mask
23224+
23225+#ifdef CONFIG_PAX_KERNEXEC
23226+ GET_CR0_INTO_RDI
23227+ bts $16,%rdi
23228+ jc 110f
23229+ SET_RDI_INTO_CR0
23230+ or $2,%ebx
23231+110:
23232+#endif
23233+
23234+#ifdef CONFIG_PAX_MEMORY_UDEREF
23235+ 661: jmp 111f
23236+ .pushsection .altinstr_replacement, "a"
23237+ 662: ASM_NOP2
23238+ .popsection
23239+ .pushsection .altinstructions, "a"
23240+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23241+ .popsection
23242+ GET_CR3_INTO_RDI
23243+ cmp $0,%dil
23244+ jz 111f
23245+ sub $4097,%rdi
23246+ or $4,%ebx
23247+ bts $63,%rdi
23248+ SET_RDI_INTO_CR3
23249+ mov $__UDEREF_KERNEL_DS,%edi
23250+ mov %edi,%ss
23251+111:
23252+#endif
23253+ .endm
23254+
23255+ .macro pax_exit_kernel_nmi
23256+#ifdef CONFIG_PAX_KERNEXEC
23257+ btr $1,%ebx
23258+ jnc 110f
23259+ GET_CR0_INTO_RDI
23260+ btr $16,%rdi
23261+ SET_RDI_INTO_CR0
23262+110:
23263+#endif
23264+
23265+#ifdef CONFIG_PAX_MEMORY_UDEREF
23266+ btr $2,%ebx
23267+ jnc 111f
23268+ GET_CR3_INTO_RDI
23269+ add $4097,%rdi
23270+ bts $63,%rdi
23271+ SET_RDI_INTO_CR3
23272+ mov $__KERNEL_DS,%edi
23273+ mov %edi,%ss
23274+111:
23275+#endif
23276+ .endm
23277+
23278+ .macro pax_erase_kstack
23279+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23280+ call pax_erase_kstack
23281+#endif
23282+ .endm
23283+
23284+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23285+ENTRY(pax_erase_kstack)
23286+ pushq %rdi
23287+ pushq %rcx
23288+ pushq %rax
23289+ pushq %r11
23290+
23291+ GET_THREAD_INFO(%r11)
23292+ mov TI_lowest_stack(%r11), %rdi
23293+ mov $-0xBEEF, %rax
23294+ std
23295+
23296+1: mov %edi, %ecx
23297+ and $THREAD_SIZE_asm - 1, %ecx
23298+ shr $3, %ecx
23299+ repne scasq
23300+ jecxz 2f
23301+
23302+ cmp $2*8, %ecx
23303+ jc 2f
23304+
23305+ mov $2*8, %ecx
23306+ repe scasq
23307+ jecxz 2f
23308+ jne 1b
23309+
23310+2: cld
23311+ mov %esp, %ecx
23312+ sub %edi, %ecx
23313+
23314+ cmp $THREAD_SIZE_asm, %rcx
23315+ jb 3f
23316+ ud2
23317+3:
23318+
23319+ shr $3, %ecx
23320+ rep stosq
23321+
23322+ mov TI_task_thread_sp0(%r11), %rdi
23323+ sub $256, %rdi
23324+ mov %rdi, TI_lowest_stack(%r11)
23325+
23326+ popq %r11
23327+ popq %rax
23328+ popq %rcx
23329+ popq %rdi
23330+ pax_force_retaddr
23331+ ret
23332+ENDPROC(pax_erase_kstack)
23333+#endif
23334
23335 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23336 #ifdef CONFIG_TRACE_IRQFLAGS
23337@@ -321,7 +754,7 @@ ENDPROC(native_usergs_sysret64)
23338 .endm
23339
23340 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23341- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23342+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23343 jnc 1f
23344 TRACE_IRQS_ON_DEBUG
23345 1:
23346@@ -359,27 +792,6 @@ ENDPROC(native_usergs_sysret64)
23347 movq \tmp,R11+\offset(%rsp)
23348 .endm
23349
23350- .macro FAKE_STACK_FRAME child_rip
23351- /* push in order ss, rsp, eflags, cs, rip */
23352- xorl %eax, %eax
23353- pushq_cfi $__KERNEL_DS /* ss */
23354- /*CFI_REL_OFFSET ss,0*/
23355- pushq_cfi %rax /* rsp */
23356- CFI_REL_OFFSET rsp,0
23357- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23358- /*CFI_REL_OFFSET rflags,0*/
23359- pushq_cfi $__KERNEL_CS /* cs */
23360- /*CFI_REL_OFFSET cs,0*/
23361- pushq_cfi \child_rip /* rip */
23362- CFI_REL_OFFSET rip,0
23363- pushq_cfi %rax /* orig rax */
23364- .endm
23365-
23366- .macro UNFAKE_STACK_FRAME
23367- addq $8*6, %rsp
23368- CFI_ADJUST_CFA_OFFSET -(6*8)
23369- .endm
23370-
23371 /*
23372 * initial frame state for interrupts (and exceptions without error code)
23373 */
23374@@ -446,25 +858,26 @@ ENDPROC(native_usergs_sysret64)
23375 /* save partial stack frame */
23376 .macro SAVE_ARGS_IRQ
23377 cld
23378- /* start from rbp in pt_regs and jump over */
23379- movq_cfi rdi, (RDI-RBP)
23380- movq_cfi rsi, (RSI-RBP)
23381- movq_cfi rdx, (RDX-RBP)
23382- movq_cfi rcx, (RCX-RBP)
23383- movq_cfi rax, (RAX-RBP)
23384- movq_cfi r8, (R8-RBP)
23385- movq_cfi r9, (R9-RBP)
23386- movq_cfi r10, (R10-RBP)
23387- movq_cfi r11, (R11-RBP)
23388+ /* start from r15 in pt_regs and jump over */
23389+ movq_cfi rdi, RDI
23390+ movq_cfi rsi, RSI
23391+ movq_cfi rdx, RDX
23392+ movq_cfi rcx, RCX
23393+ movq_cfi rax, RAX
23394+ movq_cfi r8, R8
23395+ movq_cfi r9, R9
23396+ movq_cfi r10, R10
23397+ movq_cfi r11, R11
23398+ movq_cfi r12, R12
23399
23400 /* Save rbp so that we can unwind from get_irq_regs() */
23401- movq_cfi rbp, 0
23402+ movq_cfi rbp, RBP
23403
23404 /* Save previous stack value */
23405 movq %rsp, %rsi
23406
23407- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23408- testl $3, CS-RBP(%rsi)
23409+ movq %rsp,%rdi /* arg1 for handler */
23410+ testb $3, CS(%rsi)
23411 je 1f
23412 SWAPGS
23413 /*
23414@@ -484,6 +897,18 @@ ENDPROC(native_usergs_sysret64)
23415 0x06 /* DW_OP_deref */, \
23416 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23417 0x22 /* DW_OP_plus */
23418+
23419+#ifdef CONFIG_PAX_MEMORY_UDEREF
23420+ testb $3, CS(%rdi)
23421+ jnz 1f
23422+ pax_enter_kernel
23423+ jmp 2f
23424+1: pax_enter_kernel_user
23425+2:
23426+#else
23427+ pax_enter_kernel
23428+#endif
23429+
23430 /* We entered an interrupt context - irqs are off: */
23431 TRACE_IRQS_OFF
23432 .endm
23433@@ -515,9 +940,52 @@ ENTRY(save_paranoid)
23434 js 1f /* negative -> in kernel */
23435 SWAPGS
23436 xorl %ebx,%ebx
23437-1: ret
23438+1:
23439+#ifdef CONFIG_PAX_MEMORY_UDEREF
23440+ testb $3, CS+8(%rsp)
23441+ jnz 1f
23442+ pax_enter_kernel
23443+ jmp 2f
23444+1: pax_enter_kernel_user
23445+2:
23446+#else
23447+ pax_enter_kernel
23448+#endif
23449+ pax_force_retaddr
23450+ ret
23451 CFI_ENDPROC
23452-END(save_paranoid)
23453+ENDPROC(save_paranoid)
23454+
23455+ENTRY(save_paranoid_nmi)
23456+ XCPT_FRAME 1 RDI+8
23457+ cld
23458+ movq_cfi rdi, RDI+8
23459+ movq_cfi rsi, RSI+8
23460+ movq_cfi rdx, RDX+8
23461+ movq_cfi rcx, RCX+8
23462+ movq_cfi rax, RAX+8
23463+ movq_cfi r8, R8+8
23464+ movq_cfi r9, R9+8
23465+ movq_cfi r10, R10+8
23466+ movq_cfi r11, R11+8
23467+ movq_cfi rbx, RBX+8
23468+ movq_cfi rbp, RBP+8
23469+ movq_cfi r12, R12+8
23470+ movq_cfi r13, R13+8
23471+ movq_cfi r14, R14+8
23472+ movq_cfi r15, R15+8
23473+ movl $1,%ebx
23474+ movl $MSR_GS_BASE,%ecx
23475+ rdmsr
23476+ testl %edx,%edx
23477+ js 1f /* negative -> in kernel */
23478+ SWAPGS
23479+ xorl %ebx,%ebx
23480+1: pax_enter_kernel_nmi
23481+ pax_force_retaddr
23482+ ret
23483+ CFI_ENDPROC
23484+ENDPROC(save_paranoid_nmi)
23485 .popsection
23486
23487 /*
23488@@ -539,7 +1007,7 @@ ENTRY(ret_from_fork)
23489
23490 RESTORE_REST
23491
23492- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23493+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23494 jz 1f
23495
23496 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23497@@ -549,15 +1017,13 @@ ENTRY(ret_from_fork)
23498 jmp ret_from_sys_call # go to the SYSRET fastpath
23499
23500 1:
23501- subq $REST_SKIP, %rsp # leave space for volatiles
23502- CFI_ADJUST_CFA_OFFSET REST_SKIP
23503 movq %rbp, %rdi
23504 call *%rbx
23505 movl $0, RAX(%rsp)
23506 RESTORE_REST
23507 jmp int_ret_from_sys_call
23508 CFI_ENDPROC
23509-END(ret_from_fork)
23510+ENDPROC(ret_from_fork)
23511
23512 /*
23513 * System call entry. Up to 6 arguments in registers are supported.
23514@@ -594,7 +1060,7 @@ END(ret_from_fork)
23515 ENTRY(system_call)
23516 CFI_STARTPROC simple
23517 CFI_SIGNAL_FRAME
23518- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23519+ CFI_DEF_CFA rsp,0
23520 CFI_REGISTER rip,rcx
23521 /*CFI_REGISTER rflags,r11*/
23522 SWAPGS_UNSAFE_STACK
23523@@ -607,16 +1073,23 @@ GLOBAL(system_call_after_swapgs)
23524
23525 movq %rsp,PER_CPU_VAR(old_rsp)
23526 movq PER_CPU_VAR(kernel_stack),%rsp
23527+ SAVE_ARGS 8*6,0
23528+ pax_enter_kernel_user
23529+
23530+#ifdef CONFIG_PAX_RANDKSTACK
23531+ pax_erase_kstack
23532+#endif
23533+
23534 /*
23535 * No need to follow this irqs off/on section - it's straight
23536 * and short:
23537 */
23538 ENABLE_INTERRUPTS(CLBR_NONE)
23539- SAVE_ARGS 8,0
23540 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23541 movq %rcx,RIP-ARGOFFSET(%rsp)
23542 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23543- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23544+ GET_THREAD_INFO(%rcx)
23545+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23546 jnz tracesys
23547 system_call_fastpath:
23548 #if __SYSCALL_MASK == ~0
23549@@ -640,10 +1113,13 @@ sysret_check:
23550 LOCKDEP_SYS_EXIT
23551 DISABLE_INTERRUPTS(CLBR_NONE)
23552 TRACE_IRQS_OFF
23553- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23554+ GET_THREAD_INFO(%rcx)
23555+ movl TI_flags(%rcx),%edx
23556 andl %edi,%edx
23557 jnz sysret_careful
23558 CFI_REMEMBER_STATE
23559+ pax_exit_kernel_user
23560+ pax_erase_kstack
23561 /*
23562 * sysretq will re-enable interrupts:
23563 */
23564@@ -702,6 +1178,9 @@ auditsys:
23565 movq %rax,%rsi /* 2nd arg: syscall number */
23566 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23567 call __audit_syscall_entry
23568+
23569+ pax_erase_kstack
23570+
23571 LOAD_ARGS 0 /* reload call-clobbered registers */
23572 jmp system_call_fastpath
23573
23574@@ -723,7 +1202,7 @@ sysret_audit:
23575 /* Do syscall tracing */
23576 tracesys:
23577 #ifdef CONFIG_AUDITSYSCALL
23578- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23579+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23580 jz auditsys
23581 #endif
23582 SAVE_REST
23583@@ -731,12 +1210,15 @@ tracesys:
23584 FIXUP_TOP_OF_STACK %rdi
23585 movq %rsp,%rdi
23586 call syscall_trace_enter
23587+
23588+ pax_erase_kstack
23589+
23590 /*
23591 * Reload arg registers from stack in case ptrace changed them.
23592 * We don't reload %rax because syscall_trace_enter() returned
23593 * the value it wants us to use in the table lookup.
23594 */
23595- LOAD_ARGS ARGOFFSET, 1
23596+ LOAD_ARGS 1
23597 RESTORE_REST
23598 #if __SYSCALL_MASK == ~0
23599 cmpq $__NR_syscall_max,%rax
23600@@ -766,7 +1248,9 @@ GLOBAL(int_with_check)
23601 andl %edi,%edx
23602 jnz int_careful
23603 andl $~TS_COMPAT,TI_status(%rcx)
23604- jmp retint_swapgs
23605+ pax_exit_kernel_user
23606+ pax_erase_kstack
23607+ jmp retint_swapgs_pax
23608
23609 /* Either reschedule or signal or syscall exit tracking needed. */
23610 /* First do a reschedule test. */
23611@@ -812,7 +1296,7 @@ int_restore_rest:
23612 TRACE_IRQS_OFF
23613 jmp int_with_check
23614 CFI_ENDPROC
23615-END(system_call)
23616+ENDPROC(system_call)
23617
23618 .macro FORK_LIKE func
23619 ENTRY(stub_\func)
23620@@ -825,9 +1309,10 @@ ENTRY(stub_\func)
23621 DEFAULT_FRAME 0 8 /* offset 8: return address */
23622 call sys_\func
23623 RESTORE_TOP_OF_STACK %r11, 8
23624- ret $REST_SKIP /* pop extended registers */
23625+ pax_force_retaddr
23626+ ret
23627 CFI_ENDPROC
23628-END(stub_\func)
23629+ENDPROC(stub_\func)
23630 .endm
23631
23632 .macro FIXED_FRAME label,func
23633@@ -837,9 +1322,10 @@ ENTRY(\label)
23634 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23635 call \func
23636 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23637+ pax_force_retaddr
23638 ret
23639 CFI_ENDPROC
23640-END(\label)
23641+ENDPROC(\label)
23642 .endm
23643
23644 FORK_LIKE clone
23645@@ -847,19 +1333,6 @@ END(\label)
23646 FORK_LIKE vfork
23647 FIXED_FRAME stub_iopl, sys_iopl
23648
23649-ENTRY(ptregscall_common)
23650- DEFAULT_FRAME 1 8 /* offset 8: return address */
23651- RESTORE_TOP_OF_STACK %r11, 8
23652- movq_cfi_restore R15+8, r15
23653- movq_cfi_restore R14+8, r14
23654- movq_cfi_restore R13+8, r13
23655- movq_cfi_restore R12+8, r12
23656- movq_cfi_restore RBP+8, rbp
23657- movq_cfi_restore RBX+8, rbx
23658- ret $REST_SKIP /* pop extended registers */
23659- CFI_ENDPROC
23660-END(ptregscall_common)
23661-
23662 ENTRY(stub_execve)
23663 CFI_STARTPROC
23664 addq $8, %rsp
23665@@ -871,7 +1344,7 @@ ENTRY(stub_execve)
23666 RESTORE_REST
23667 jmp int_ret_from_sys_call
23668 CFI_ENDPROC
23669-END(stub_execve)
23670+ENDPROC(stub_execve)
23671
23672 /*
23673 * sigreturn is special because it needs to restore all registers on return.
23674@@ -888,7 +1361,7 @@ ENTRY(stub_rt_sigreturn)
23675 RESTORE_REST
23676 jmp int_ret_from_sys_call
23677 CFI_ENDPROC
23678-END(stub_rt_sigreturn)
23679+ENDPROC(stub_rt_sigreturn)
23680
23681 #ifdef CONFIG_X86_X32_ABI
23682 ENTRY(stub_x32_rt_sigreturn)
23683@@ -902,7 +1375,7 @@ ENTRY(stub_x32_rt_sigreturn)
23684 RESTORE_REST
23685 jmp int_ret_from_sys_call
23686 CFI_ENDPROC
23687-END(stub_x32_rt_sigreturn)
23688+ENDPROC(stub_x32_rt_sigreturn)
23689
23690 ENTRY(stub_x32_execve)
23691 CFI_STARTPROC
23692@@ -916,7 +1389,7 @@ ENTRY(stub_x32_execve)
23693 RESTORE_REST
23694 jmp int_ret_from_sys_call
23695 CFI_ENDPROC
23696-END(stub_x32_execve)
23697+ENDPROC(stub_x32_execve)
23698
23699 #endif
23700
23701@@ -953,7 +1426,7 @@ vector=vector+1
23702 2: jmp common_interrupt
23703 .endr
23704 CFI_ENDPROC
23705-END(irq_entries_start)
23706+ENDPROC(irq_entries_start)
23707
23708 .previous
23709 END(interrupt)
23710@@ -970,8 +1443,8 @@ END(interrupt)
23711 /* 0(%rsp): ~(interrupt number) */
23712 .macro interrupt func
23713 /* reserve pt_regs for scratch regs and rbp */
23714- subq $ORIG_RAX-RBP, %rsp
23715- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23716+ subq $ORIG_RAX, %rsp
23717+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23718 SAVE_ARGS_IRQ
23719 call \func
23720 .endm
23721@@ -998,14 +1471,14 @@ ret_from_intr:
23722
23723 /* Restore saved previous stack */
23724 popq %rsi
23725- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23726- leaq ARGOFFSET-RBP(%rsi), %rsp
23727+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23728+ movq %rsi, %rsp
23729 CFI_DEF_CFA_REGISTER rsp
23730- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23731+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23732
23733 exit_intr:
23734 GET_THREAD_INFO(%rcx)
23735- testl $3,CS-ARGOFFSET(%rsp)
23736+ testb $3,CS-ARGOFFSET(%rsp)
23737 je retint_kernel
23738
23739 /* Interrupt came from user space */
23740@@ -1027,12 +1500,16 @@ retint_swapgs: /* return to user-space */
23741 * The iretq could re-enable interrupts:
23742 */
23743 DISABLE_INTERRUPTS(CLBR_ANY)
23744+ pax_exit_kernel_user
23745+retint_swapgs_pax:
23746 TRACE_IRQS_IRETQ
23747 SWAPGS
23748 jmp restore_args
23749
23750 retint_restore_args: /* return to kernel space */
23751 DISABLE_INTERRUPTS(CLBR_ANY)
23752+ pax_exit_kernel
23753+ pax_force_retaddr (RIP-ARGOFFSET)
23754 /*
23755 * The iretq could re-enable interrupts:
23756 */
23757@@ -1145,7 +1622,7 @@ ENTRY(retint_kernel)
23758 jmp exit_intr
23759 #endif
23760 CFI_ENDPROC
23761-END(common_interrupt)
23762+ENDPROC(common_interrupt)
23763
23764 /*
23765 * If IRET takes a fault on the espfix stack, then we
23766@@ -1167,13 +1644,13 @@ __do_double_fault:
23767 cmpq $native_irq_return_iret,%rax
23768 jne do_double_fault /* This shouldn't happen... */
23769 movq PER_CPU_VAR(kernel_stack),%rax
23770- subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
23771+ subq $(6*8),%rax /* Reset to original stack */
23772 movq %rax,RSP(%rdi)
23773 movq $0,(%rax) /* Missing (lost) #GP error code */
23774 movq $general_protection,RIP(%rdi)
23775 retq
23776 CFI_ENDPROC
23777-END(__do_double_fault)
23778+ENDPROC(__do_double_fault)
23779 #else
23780 # define __do_double_fault do_double_fault
23781 #endif
23782@@ -1195,7 +1672,7 @@ ENTRY(\sym)
23783 interrupt \do_sym
23784 jmp ret_from_intr
23785 CFI_ENDPROC
23786-END(\sym)
23787+ENDPROC(\sym)
23788 .endm
23789
23790 #ifdef CONFIG_TRACING
23791@@ -1283,7 +1760,7 @@ ENTRY(\sym)
23792 call \do_sym
23793 jmp error_exit /* %ebx: no swapgs flag */
23794 CFI_ENDPROC
23795-END(\sym)
23796+ENDPROC(\sym)
23797 .endm
23798
23799 .macro paranoidzeroentry sym do_sym
23800@@ -1301,10 +1778,10 @@ ENTRY(\sym)
23801 call \do_sym
23802 jmp paranoid_exit /* %ebx: no swapgs flag */
23803 CFI_ENDPROC
23804-END(\sym)
23805+ENDPROC(\sym)
23806 .endm
23807
23808-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23809+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23810 .macro paranoidzeroentry_ist sym do_sym ist
23811 ENTRY(\sym)
23812 INTR_FRAME
23813@@ -1317,12 +1794,18 @@ ENTRY(\sym)
23814 TRACE_IRQS_OFF_DEBUG
23815 movq %rsp,%rdi /* pt_regs pointer */
23816 xorl %esi,%esi /* no error code */
23817+#ifdef CONFIG_SMP
23818+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23819+ lea init_tss(%r13), %r13
23820+#else
23821+ lea init_tss(%rip), %r13
23822+#endif
23823 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23824 call \do_sym
23825 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23826 jmp paranoid_exit /* %ebx: no swapgs flag */
23827 CFI_ENDPROC
23828-END(\sym)
23829+ENDPROC(\sym)
23830 .endm
23831
23832 .macro errorentry sym do_sym
23833@@ -1340,7 +1823,7 @@ ENTRY(\sym)
23834 call \do_sym
23835 jmp error_exit /* %ebx: no swapgs flag */
23836 CFI_ENDPROC
23837-END(\sym)
23838+ENDPROC(\sym)
23839 .endm
23840
23841 #ifdef CONFIG_TRACING
23842@@ -1371,7 +1854,7 @@ ENTRY(\sym)
23843 call \do_sym
23844 jmp paranoid_exit /* %ebx: no swapgs flag */
23845 CFI_ENDPROC
23846-END(\sym)
23847+ENDPROC(\sym)
23848 .endm
23849
23850 zeroentry divide_error do_divide_error
23851@@ -1401,9 +1884,10 @@ gs_change:
23852 2: mfence /* workaround */
23853 SWAPGS
23854 popfq_cfi
23855+ pax_force_retaddr
23856 ret
23857 CFI_ENDPROC
23858-END(native_load_gs_index)
23859+ENDPROC(native_load_gs_index)
23860
23861 _ASM_EXTABLE(gs_change,bad_gs)
23862 .section .fixup,"ax"
23863@@ -1431,9 +1915,10 @@ ENTRY(do_softirq_own_stack)
23864 CFI_DEF_CFA_REGISTER rsp
23865 CFI_ADJUST_CFA_OFFSET -8
23866 decl PER_CPU_VAR(irq_count)
23867+ pax_force_retaddr
23868 ret
23869 CFI_ENDPROC
23870-END(do_softirq_own_stack)
23871+ENDPROC(do_softirq_own_stack)
23872
23873 #ifdef CONFIG_XEN
23874 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23875@@ -1471,7 +1956,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23876 decl PER_CPU_VAR(irq_count)
23877 jmp error_exit
23878 CFI_ENDPROC
23879-END(xen_do_hypervisor_callback)
23880+ENDPROC(xen_do_hypervisor_callback)
23881
23882 /*
23883 * Hypervisor uses this for application faults while it executes.
23884@@ -1530,7 +2015,7 @@ ENTRY(xen_failsafe_callback)
23885 SAVE_ALL
23886 jmp error_exit
23887 CFI_ENDPROC
23888-END(xen_failsafe_callback)
23889+ENDPROC(xen_failsafe_callback)
23890
23891 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23892 xen_hvm_callback_vector xen_evtchn_do_upcall
23893@@ -1582,18 +2067,33 @@ ENTRY(paranoid_exit)
23894 DEFAULT_FRAME
23895 DISABLE_INTERRUPTS(CLBR_NONE)
23896 TRACE_IRQS_OFF_DEBUG
23897- testl %ebx,%ebx /* swapgs needed? */
23898+ testl $1,%ebx /* swapgs needed? */
23899 jnz paranoid_restore
23900- testl $3,CS(%rsp)
23901+ testb $3,CS(%rsp)
23902 jnz paranoid_userspace
23903+#ifdef CONFIG_PAX_MEMORY_UDEREF
23904+ pax_exit_kernel
23905+ TRACE_IRQS_IRETQ 0
23906+ SWAPGS_UNSAFE_STACK
23907+ RESTORE_ALL 8
23908+ pax_force_retaddr_bts
23909+ jmp irq_return
23910+#endif
23911 paranoid_swapgs:
23912+#ifdef CONFIG_PAX_MEMORY_UDEREF
23913+ pax_exit_kernel_user
23914+#else
23915+ pax_exit_kernel
23916+#endif
23917 TRACE_IRQS_IRETQ 0
23918 SWAPGS_UNSAFE_STACK
23919 RESTORE_ALL 8
23920 jmp irq_return
23921 paranoid_restore:
23922+ pax_exit_kernel
23923 TRACE_IRQS_IRETQ_DEBUG 0
23924 RESTORE_ALL 8
23925+ pax_force_retaddr_bts
23926 jmp irq_return
23927 paranoid_userspace:
23928 GET_THREAD_INFO(%rcx)
23929@@ -1622,7 +2122,7 @@ paranoid_schedule:
23930 TRACE_IRQS_OFF
23931 jmp paranoid_userspace
23932 CFI_ENDPROC
23933-END(paranoid_exit)
23934+ENDPROC(paranoid_exit)
23935
23936 /*
23937 * Exception entry point. This expects an error code/orig_rax on the stack.
23938@@ -1649,12 +2149,23 @@ ENTRY(error_entry)
23939 movq_cfi r14, R14+8
23940 movq_cfi r15, R15+8
23941 xorl %ebx,%ebx
23942- testl $3,CS+8(%rsp)
23943+ testb $3,CS+8(%rsp)
23944 je error_kernelspace
23945 error_swapgs:
23946 SWAPGS
23947 error_sti:
23948+#ifdef CONFIG_PAX_MEMORY_UDEREF
23949+ testb $3, CS+8(%rsp)
23950+ jnz 1f
23951+ pax_enter_kernel
23952+ jmp 2f
23953+1: pax_enter_kernel_user
23954+2:
23955+#else
23956+ pax_enter_kernel
23957+#endif
23958 TRACE_IRQS_OFF
23959+ pax_force_retaddr
23960 ret
23961
23962 /*
23963@@ -1681,7 +2192,7 @@ bstep_iret:
23964 movq %rcx,RIP+8(%rsp)
23965 jmp error_swapgs
23966 CFI_ENDPROC
23967-END(error_entry)
23968+ENDPROC(error_entry)
23969
23970
23971 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23972@@ -1692,7 +2203,7 @@ ENTRY(error_exit)
23973 DISABLE_INTERRUPTS(CLBR_NONE)
23974 TRACE_IRQS_OFF
23975 GET_THREAD_INFO(%rcx)
23976- testl %eax,%eax
23977+ testl $1,%eax
23978 jne retint_kernel
23979 LOCKDEP_SYS_EXIT_IRQ
23980 movl TI_flags(%rcx),%edx
23981@@ -1701,7 +2212,7 @@ ENTRY(error_exit)
23982 jnz retint_careful
23983 jmp retint_swapgs
23984 CFI_ENDPROC
23985-END(error_exit)
23986+ENDPROC(error_exit)
23987
23988 /*
23989 * Test if a given stack is an NMI stack or not.
23990@@ -1759,9 +2270,11 @@ ENTRY(nmi)
23991 * If %cs was not the kernel segment, then the NMI triggered in user
23992 * space, which means it is definitely not nested.
23993 */
23994+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23995+ je 1f
23996 cmpl $__KERNEL_CS, 16(%rsp)
23997 jne first_nmi
23998-
23999+1:
24000 /*
24001 * Check the special variable on the stack to see if NMIs are
24002 * executing.
24003@@ -1795,8 +2308,7 @@ nested_nmi:
24004
24005 1:
24006 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24007- leaq -1*8(%rsp), %rdx
24008- movq %rdx, %rsp
24009+ subq $8, %rsp
24010 CFI_ADJUST_CFA_OFFSET 1*8
24011 leaq -10*8(%rsp), %rdx
24012 pushq_cfi $__KERNEL_DS
24013@@ -1814,6 +2326,7 @@ nested_nmi_out:
24014 CFI_RESTORE rdx
24015
24016 /* No need to check faults here */
24017+# pax_force_retaddr_bts
24018 INTERRUPT_RETURN
24019
24020 CFI_RESTORE_STATE
24021@@ -1910,13 +2423,13 @@ end_repeat_nmi:
24022 subq $ORIG_RAX-R15, %rsp
24023 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24024 /*
24025- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24026+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24027 * as we should not be calling schedule in NMI context.
24028 * Even with normal interrupts enabled. An NMI should not be
24029 * setting NEED_RESCHED or anything that normal interrupts and
24030 * exceptions might do.
24031 */
24032- call save_paranoid
24033+ call save_paranoid_nmi
24034 DEFAULT_FRAME 0
24035
24036 /*
24037@@ -1926,9 +2439,9 @@ end_repeat_nmi:
24038 * NMI itself takes a page fault, the page fault that was preempted
24039 * will read the information from the NMI page fault and not the
24040 * origin fault. Save it off and restore it if it changes.
24041- * Use the r12 callee-saved register.
24042+ * Use the r13 callee-saved register.
24043 */
24044- movq %cr2, %r12
24045+ movq %cr2, %r13
24046
24047 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24048 movq %rsp,%rdi
24049@@ -1937,31 +2450,36 @@ end_repeat_nmi:
24050
24051 /* Did the NMI take a page fault? Restore cr2 if it did */
24052 movq %cr2, %rcx
24053- cmpq %rcx, %r12
24054+ cmpq %rcx, %r13
24055 je 1f
24056- movq %r12, %cr2
24057+ movq %r13, %cr2
24058 1:
24059
24060- testl %ebx,%ebx /* swapgs needed? */
24061+ testl $1,%ebx /* swapgs needed? */
24062 jnz nmi_restore
24063 nmi_swapgs:
24064 SWAPGS_UNSAFE_STACK
24065 nmi_restore:
24066+ pax_exit_kernel_nmi
24067 /* Pop the extra iret frame at once */
24068 RESTORE_ALL 6*8
24069+ testb $3, 8(%rsp)
24070+ jnz 1f
24071+ pax_force_retaddr_bts
24072+1:
24073
24074 /* Clear the NMI executing stack variable */
24075 movq $0, 5*8(%rsp)
24076 jmp irq_return
24077 CFI_ENDPROC
24078-END(nmi)
24079+ENDPROC(nmi)
24080
24081 ENTRY(ignore_sysret)
24082 CFI_STARTPROC
24083 mov $-ENOSYS,%eax
24084 sysret
24085 CFI_ENDPROC
24086-END(ignore_sysret)
24087+ENDPROC(ignore_sysret)
24088
24089 /*
24090 * End of kprobes section
24091diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24092index 94d857f..bf1f0bf 100644
24093--- a/arch/x86/kernel/espfix_64.c
24094+++ b/arch/x86/kernel/espfix_64.c
24095@@ -197,7 +197,7 @@ void init_espfix_ap(void)
24096 set_pte(&pte_p[n*PTE_STRIDE], pte);
24097
24098 /* Job is done for this CPU and any CPU which shares this page */
24099- ACCESS_ONCE(espfix_pages[page]) = stack_page;
24100+ ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24101
24102 unlock_done:
24103 mutex_unlock(&espfix_init_mutex);
24104diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24105index 52819e8..b6d1dbd 100644
24106--- a/arch/x86/kernel/ftrace.c
24107+++ b/arch/x86/kernel/ftrace.c
24108@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24109 {
24110 unsigned char replaced[MCOUNT_INSN_SIZE];
24111
24112+ ip = ktla_ktva(ip);
24113+
24114 /*
24115 * Note: Due to modules and __init, code can
24116 * disappear and change, we need to protect against faulting
24117@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24118 unsigned char old[MCOUNT_INSN_SIZE];
24119 int ret;
24120
24121- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24122+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24123
24124 ftrace_update_func = ip;
24125 /* Make sure the breakpoints see the ftrace_update_func update */
24126@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24127 * kernel identity mapping to modify code.
24128 */
24129 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24130- ip = (unsigned long)__va(__pa_symbol(ip));
24131+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24132
24133 if (probe_kernel_write((void *)ip, val, size))
24134 return -EPERM;
24135@@ -319,7 +321,7 @@ static int add_break(unsigned long ip, const char *old)
24136 unsigned char replaced[MCOUNT_INSN_SIZE];
24137 unsigned char brk = BREAKPOINT_INSTRUCTION;
24138
24139- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24140+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24141 return -EFAULT;
24142
24143 /* Make sure it is what we expect it to be */
24144diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24145index 068054f..c248bcd 100644
24146--- a/arch/x86/kernel/head64.c
24147+++ b/arch/x86/kernel/head64.c
24148@@ -67,12 +67,12 @@ again:
24149 pgd = *pgd_p;
24150
24151 /*
24152- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24153- * critical -- __PAGE_OFFSET would point us back into the dynamic
24154+ * The use of __early_va rather than __va here is critical:
24155+ * __va would point us back into the dynamic
24156 * range and we might end up looping forever...
24157 */
24158 if (pgd)
24159- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24160+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24161 else {
24162 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24163 reset_early_page_tables();
24164@@ -82,13 +82,13 @@ again:
24165 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24166 for (i = 0; i < PTRS_PER_PUD; i++)
24167 pud_p[i] = 0;
24168- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24169+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24170 }
24171 pud_p += pud_index(address);
24172 pud = *pud_p;
24173
24174 if (pud)
24175- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24176+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24177 else {
24178 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24179 reset_early_page_tables();
24180@@ -98,7 +98,7 @@ again:
24181 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24182 for (i = 0; i < PTRS_PER_PMD; i++)
24183 pmd_p[i] = 0;
24184- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24185+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24186 }
24187 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24188 pmd_p[pmd_index(address)] = pmd;
24189@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24190 if (console_loglevel == 10)
24191 early_printk("Kernel alive\n");
24192
24193- clear_page(init_level4_pgt);
24194 /* set init_level4_pgt kernel high mapping*/
24195 init_level4_pgt[511] = early_level4_pgt[511];
24196
24197diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24198index f36bd42..0ab4474 100644
24199--- a/arch/x86/kernel/head_32.S
24200+++ b/arch/x86/kernel/head_32.S
24201@@ -26,6 +26,12 @@
24202 /* Physical address */
24203 #define pa(X) ((X) - __PAGE_OFFSET)
24204
24205+#ifdef CONFIG_PAX_KERNEXEC
24206+#define ta(X) (X)
24207+#else
24208+#define ta(X) ((X) - __PAGE_OFFSET)
24209+#endif
24210+
24211 /*
24212 * References to members of the new_cpu_data structure.
24213 */
24214@@ -55,11 +61,7 @@
24215 * and small than max_low_pfn, otherwise will waste some page table entries
24216 */
24217
24218-#if PTRS_PER_PMD > 1
24219-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24220-#else
24221-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24222-#endif
24223+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24224
24225 /* Number of possible pages in the lowmem region */
24226 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24227@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24228 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24229
24230 /*
24231+ * Real beginning of normal "text" segment
24232+ */
24233+ENTRY(stext)
24234+ENTRY(_stext)
24235+
24236+/*
24237 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24238 * %esi points to the real-mode code as a 32-bit pointer.
24239 * CS and DS must be 4 GB flat segments, but we don't depend on
24240@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24241 * can.
24242 */
24243 __HEAD
24244+
24245+#ifdef CONFIG_PAX_KERNEXEC
24246+ jmp startup_32
24247+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24248+.fill PAGE_SIZE-5,1,0xcc
24249+#endif
24250+
24251 ENTRY(startup_32)
24252 movl pa(stack_start),%ecx
24253
24254@@ -106,6 +121,59 @@ ENTRY(startup_32)
24255 2:
24256 leal -__PAGE_OFFSET(%ecx),%esp
24257
24258+#ifdef CONFIG_SMP
24259+ movl $pa(cpu_gdt_table),%edi
24260+ movl $__per_cpu_load,%eax
24261+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24262+ rorl $16,%eax
24263+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24264+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24265+ movl $__per_cpu_end - 1,%eax
24266+ subl $__per_cpu_start,%eax
24267+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24268+#endif
24269+
24270+#ifdef CONFIG_PAX_MEMORY_UDEREF
24271+ movl $NR_CPUS,%ecx
24272+ movl $pa(cpu_gdt_table),%edi
24273+1:
24274+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24275+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24276+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24277+ addl $PAGE_SIZE_asm,%edi
24278+ loop 1b
24279+#endif
24280+
24281+#ifdef CONFIG_PAX_KERNEXEC
24282+ movl $pa(boot_gdt),%edi
24283+ movl $__LOAD_PHYSICAL_ADDR,%eax
24284+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24285+ rorl $16,%eax
24286+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24287+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24288+ rorl $16,%eax
24289+
24290+ ljmp $(__BOOT_CS),$1f
24291+1:
24292+
24293+ movl $NR_CPUS,%ecx
24294+ movl $pa(cpu_gdt_table),%edi
24295+ addl $__PAGE_OFFSET,%eax
24296+1:
24297+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24298+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24299+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24300+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24301+ rorl $16,%eax
24302+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24303+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24304+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24305+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24306+ rorl $16,%eax
24307+ addl $PAGE_SIZE_asm,%edi
24308+ loop 1b
24309+#endif
24310+
24311 /*
24312 * Clear BSS first so that there are no surprises...
24313 */
24314@@ -201,8 +269,11 @@ ENTRY(startup_32)
24315 movl %eax, pa(max_pfn_mapped)
24316
24317 /* Do early initialization of the fixmap area */
24318- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24319- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24320+#ifdef CONFIG_COMPAT_VDSO
24321+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24322+#else
24323+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24324+#endif
24325 #else /* Not PAE */
24326
24327 page_pde_offset = (__PAGE_OFFSET >> 20);
24328@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24329 movl %eax, pa(max_pfn_mapped)
24330
24331 /* Do early initialization of the fixmap area */
24332- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24333- movl %eax,pa(initial_page_table+0xffc)
24334+#ifdef CONFIG_COMPAT_VDSO
24335+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24336+#else
24337+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24338+#endif
24339 #endif
24340
24341 #ifdef CONFIG_PARAVIRT
24342@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24343 cmpl $num_subarch_entries, %eax
24344 jae bad_subarch
24345
24346- movl pa(subarch_entries)(,%eax,4), %eax
24347- subl $__PAGE_OFFSET, %eax
24348- jmp *%eax
24349+ jmp *pa(subarch_entries)(,%eax,4)
24350
24351 bad_subarch:
24352 WEAK(lguest_entry)
24353@@ -261,10 +333,10 @@ WEAK(xen_entry)
24354 __INITDATA
24355
24356 subarch_entries:
24357- .long default_entry /* normal x86/PC */
24358- .long lguest_entry /* lguest hypervisor */
24359- .long xen_entry /* Xen hypervisor */
24360- .long default_entry /* Moorestown MID */
24361+ .long ta(default_entry) /* normal x86/PC */
24362+ .long ta(lguest_entry) /* lguest hypervisor */
24363+ .long ta(xen_entry) /* Xen hypervisor */
24364+ .long ta(default_entry) /* Moorestown MID */
24365 num_subarch_entries = (. - subarch_entries) / 4
24366 .previous
24367 #else
24368@@ -354,6 +426,7 @@ default_entry:
24369 movl pa(mmu_cr4_features),%eax
24370 movl %eax,%cr4
24371
24372+#ifdef CONFIG_X86_PAE
24373 testb $X86_CR4_PAE, %al # check if PAE is enabled
24374 jz enable_paging
24375
24376@@ -382,6 +455,9 @@ default_entry:
24377 /* Make changes effective */
24378 wrmsr
24379
24380+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24381+#endif
24382+
24383 enable_paging:
24384
24385 /*
24386@@ -449,14 +525,20 @@ is486:
24387 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24388 movl %eax,%ss # after changing gdt.
24389
24390- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24391+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24392 movl %eax,%ds
24393 movl %eax,%es
24394
24395 movl $(__KERNEL_PERCPU), %eax
24396 movl %eax,%fs # set this cpu's percpu
24397
24398+#ifdef CONFIG_CC_STACKPROTECTOR
24399 movl $(__KERNEL_STACK_CANARY),%eax
24400+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24401+ movl $(__USER_DS),%eax
24402+#else
24403+ xorl %eax,%eax
24404+#endif
24405 movl %eax,%gs
24406
24407 xorl %eax,%eax # Clear LDT
24408@@ -512,8 +594,11 @@ setup_once:
24409 * relocation. Manually set base address in stack canary
24410 * segment descriptor.
24411 */
24412- movl $gdt_page,%eax
24413+ movl $cpu_gdt_table,%eax
24414 movl $stack_canary,%ecx
24415+#ifdef CONFIG_SMP
24416+ addl $__per_cpu_load,%ecx
24417+#endif
24418 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24419 shrl $16, %ecx
24420 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24421@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24422 cmpl $2,(%esp) # X86_TRAP_NMI
24423 je is_nmi # Ignore NMI
24424
24425- cmpl $2,%ss:early_recursion_flag
24426+ cmpl $1,%ss:early_recursion_flag
24427 je hlt_loop
24428 incl %ss:early_recursion_flag
24429
24430@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24431 pushl (20+6*4)(%esp) /* trapno */
24432 pushl $fault_msg
24433 call printk
24434-#endif
24435 call dump_stack
24436+#endif
24437 hlt_loop:
24438 hlt
24439 jmp hlt_loop
24440@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24441 /* This is the default interrupt "handler" :-) */
24442 ALIGN
24443 ignore_int:
24444- cld
24445 #ifdef CONFIG_PRINTK
24446+ cmpl $2,%ss:early_recursion_flag
24447+ je hlt_loop
24448+ incl %ss:early_recursion_flag
24449+ cld
24450 pushl %eax
24451 pushl %ecx
24452 pushl %edx
24453@@ -617,9 +705,6 @@ ignore_int:
24454 movl $(__KERNEL_DS),%eax
24455 movl %eax,%ds
24456 movl %eax,%es
24457- cmpl $2,early_recursion_flag
24458- je hlt_loop
24459- incl early_recursion_flag
24460 pushl 16(%esp)
24461 pushl 24(%esp)
24462 pushl 32(%esp)
24463@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24464 /*
24465 * BSS section
24466 */
24467-__PAGE_ALIGNED_BSS
24468- .align PAGE_SIZE
24469 #ifdef CONFIG_X86_PAE
24470+.section .initial_pg_pmd,"a",@progbits
24471 initial_pg_pmd:
24472 .fill 1024*KPMDS,4,0
24473 #else
24474+.section .initial_page_table,"a",@progbits
24475 ENTRY(initial_page_table)
24476 .fill 1024,4,0
24477 #endif
24478+.section .initial_pg_fixmap,"a",@progbits
24479 initial_pg_fixmap:
24480 .fill 1024,4,0
24481+.section .empty_zero_page,"a",@progbits
24482 ENTRY(empty_zero_page)
24483 .fill 4096,1,0
24484+.section .swapper_pg_dir,"a",@progbits
24485 ENTRY(swapper_pg_dir)
24486+#ifdef CONFIG_X86_PAE
24487+ .fill 4,8,0
24488+#else
24489 .fill 1024,4,0
24490+#endif
24491
24492 /*
24493 * This starts the data section.
24494 */
24495 #ifdef CONFIG_X86_PAE
24496-__PAGE_ALIGNED_DATA
24497- /* Page-aligned for the benefit of paravirt? */
24498- .align PAGE_SIZE
24499+.section .initial_page_table,"a",@progbits
24500 ENTRY(initial_page_table)
24501 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24502 # if KPMDS == 3
24503@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24504 # error "Kernel PMDs should be 1, 2 or 3"
24505 # endif
24506 .align PAGE_SIZE /* needs to be page-sized too */
24507+
24508+#ifdef CONFIG_PAX_PER_CPU_PGD
24509+ENTRY(cpu_pgd)
24510+ .rept 2*NR_CPUS
24511+ .fill 4,8,0
24512+ .endr
24513+#endif
24514+
24515 #endif
24516
24517 .data
24518 .balign 4
24519 ENTRY(stack_start)
24520- .long init_thread_union+THREAD_SIZE
24521+ .long init_thread_union+THREAD_SIZE-8
24522
24523 __INITRODATA
24524 int_msg:
24525@@ -727,7 +825,7 @@ fault_msg:
24526 * segment size, and 32-bit linear address value:
24527 */
24528
24529- .data
24530+.section .rodata,"a",@progbits
24531 .globl boot_gdt_descr
24532 .globl idt_descr
24533
24534@@ -736,7 +834,7 @@ fault_msg:
24535 .word 0 # 32 bit align gdt_desc.address
24536 boot_gdt_descr:
24537 .word __BOOT_DS+7
24538- .long boot_gdt - __PAGE_OFFSET
24539+ .long pa(boot_gdt)
24540
24541 .word 0 # 32-bit align idt_desc.address
24542 idt_descr:
24543@@ -747,7 +845,7 @@ idt_descr:
24544 .word 0 # 32 bit align gdt_desc.address
24545 ENTRY(early_gdt_descr)
24546 .word GDT_ENTRIES*8-1
24547- .long gdt_page /* Overwritten for secondary CPUs */
24548+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24549
24550 /*
24551 * The boot_gdt must mirror the equivalent in setup.S and is
24552@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24553 .align L1_CACHE_BYTES
24554 ENTRY(boot_gdt)
24555 .fill GDT_ENTRY_BOOT_CS,8,0
24556- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24557- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24558+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24559+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24560+
24561+ .align PAGE_SIZE_asm
24562+ENTRY(cpu_gdt_table)
24563+ .rept NR_CPUS
24564+ .quad 0x0000000000000000 /* NULL descriptor */
24565+ .quad 0x0000000000000000 /* 0x0b reserved */
24566+ .quad 0x0000000000000000 /* 0x13 reserved */
24567+ .quad 0x0000000000000000 /* 0x1b reserved */
24568+
24569+#ifdef CONFIG_PAX_KERNEXEC
24570+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24571+#else
24572+ .quad 0x0000000000000000 /* 0x20 unused */
24573+#endif
24574+
24575+ .quad 0x0000000000000000 /* 0x28 unused */
24576+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24577+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24578+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24579+ .quad 0x0000000000000000 /* 0x4b reserved */
24580+ .quad 0x0000000000000000 /* 0x53 reserved */
24581+ .quad 0x0000000000000000 /* 0x5b reserved */
24582+
24583+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24584+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24585+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24586+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24587+
24588+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24589+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24590+
24591+ /*
24592+ * Segments used for calling PnP BIOS have byte granularity.
24593+ * The code segments and data segments have fixed 64k limits,
24594+ * the transfer segment sizes are set at run time.
24595+ */
24596+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24597+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24598+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24599+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24600+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24601+
24602+ /*
24603+ * The APM segments have byte granularity and their bases
24604+ * are set at run time. All have 64k limits.
24605+ */
24606+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24607+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24608+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24609+
24610+ .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24611+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24612+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24613+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24614+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24615+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24616+
24617+ /* Be sure this is zeroed to avoid false validations in Xen */
24618+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24619+ .endr
24620diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24621index a468c0a..c7dec74 100644
24622--- a/arch/x86/kernel/head_64.S
24623+++ b/arch/x86/kernel/head_64.S
24624@@ -20,6 +20,8 @@
24625 #include <asm/processor-flags.h>
24626 #include <asm/percpu.h>
24627 #include <asm/nops.h>
24628+#include <asm/cpufeature.h>
24629+#include <asm/alternative-asm.h>
24630
24631 #ifdef CONFIG_PARAVIRT
24632 #include <asm/asm-offsets.h>
24633@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24634 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24635 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24636 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24637+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24638+L3_VMALLOC_START = pud_index(VMALLOC_START)
24639+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24640+L3_VMALLOC_END = pud_index(VMALLOC_END)
24641+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24642+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24643
24644 .text
24645 __HEAD
24646@@ -89,11 +97,24 @@ startup_64:
24647 * Fixup the physical addresses in the page table
24648 */
24649 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24650+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24651+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24652+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24653+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24654+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24655
24656- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24657- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24658+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24659+#ifndef CONFIG_XEN
24660+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24661+#endif
24662+
24663+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24664+
24665+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24666+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24667
24668 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24669+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24670
24671 /*
24672 * Set up the identity mapping for the switchover. These
24673@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24674 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24675 1:
24676
24677- /* Enable PAE mode and PGE */
24678- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24679+ /* Enable PAE mode and PSE/PGE */
24680+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24681 movq %rcx, %cr4
24682
24683 /* Setup early boot stage 4 level pagetables. */
24684@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24685 movl $MSR_EFER, %ecx
24686 rdmsr
24687 btsl $_EFER_SCE, %eax /* Enable System Call */
24688- btl $20,%edi /* No Execute supported? */
24689+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24690 jnc 1f
24691 btsl $_EFER_NX, %eax
24692 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24693+#ifndef CONFIG_EFI
24694+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24695+#endif
24696+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24697+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24698+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24699+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24700+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24701+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24702 1: wrmsr /* Make changes effective */
24703
24704 /* Setup cr0 */
24705@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24706 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24707 * address given in m16:64.
24708 */
24709+ pax_set_fptr_mask
24710 movq initial_code(%rip),%rax
24711 pushq $0 # fake return address to stop unwinder
24712 pushq $__KERNEL_CS # set correct cs
24713@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24714 .quad INIT_PER_CPU_VAR(irq_stack_union)
24715
24716 GLOBAL(stack_start)
24717- .quad init_thread_union+THREAD_SIZE-8
24718+ .quad init_thread_union+THREAD_SIZE-16
24719 .word 0
24720 __FINITDATA
24721
24722@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24723 call dump_stack
24724 #ifdef CONFIG_KALLSYMS
24725 leaq early_idt_ripmsg(%rip),%rdi
24726- movq 40(%rsp),%rsi # %rip again
24727+ movq 88(%rsp),%rsi # %rip again
24728 call __print_symbol
24729 #endif
24730 #endif /* EARLY_PRINTK */
24731@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24732 early_recursion_flag:
24733 .long 0
24734
24735+ .section .rodata,"a",@progbits
24736 #ifdef CONFIG_EARLY_PRINTK
24737 early_idt_msg:
24738 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24739@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24740 NEXT_PAGE(early_dynamic_pgts)
24741 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24742
24743- .data
24744+ .section .rodata,"a",@progbits
24745
24746-#ifndef CONFIG_XEN
24747 NEXT_PAGE(init_level4_pgt)
24748- .fill 512,8,0
24749-#else
24750-NEXT_PAGE(init_level4_pgt)
24751- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24752 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24753 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24754+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24755+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24756+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24757+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24758+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24759+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24760 .org init_level4_pgt + L4_START_KERNEL*8, 0
24761 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24762 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24763
24764+#ifdef CONFIG_PAX_PER_CPU_PGD
24765+NEXT_PAGE(cpu_pgd)
24766+ .rept 2*NR_CPUS
24767+ .fill 512,8,0
24768+ .endr
24769+#endif
24770+
24771 NEXT_PAGE(level3_ident_pgt)
24772 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24773+#ifdef CONFIG_XEN
24774 .fill 511, 8, 0
24775+#else
24776+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24777+ .fill 510,8,0
24778+#endif
24779+
24780+NEXT_PAGE(level3_vmalloc_start_pgt)
24781+ .fill 512,8,0
24782+
24783+NEXT_PAGE(level3_vmalloc_end_pgt)
24784+ .fill 512,8,0
24785+
24786+NEXT_PAGE(level3_vmemmap_pgt)
24787+ .fill L3_VMEMMAP_START,8,0
24788+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24789+
24790 NEXT_PAGE(level2_ident_pgt)
24791- /* Since I easily can, map the first 1G.
24792+ /* Since I easily can, map the first 2G.
24793 * Don't set NX because code runs from these pages.
24794 */
24795- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24796-#endif
24797+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24798
24799 NEXT_PAGE(level3_kernel_pgt)
24800 .fill L3_START_KERNEL,8,0
24801@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24802 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24803 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24804
24805+NEXT_PAGE(level2_vmemmap_pgt)
24806+ .fill 512,8,0
24807+
24808 NEXT_PAGE(level2_kernel_pgt)
24809 /*
24810 * 512 MB kernel mapping. We spend a full page on this pagetable
24811@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24812 NEXT_PAGE(level2_fixmap_pgt)
24813 .fill 506,8,0
24814 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24815- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24816- .fill 5,8,0
24817+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24818+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24819+ .fill 4,8,0
24820
24821 NEXT_PAGE(level1_fixmap_pgt)
24822 .fill 512,8,0
24823
24824+NEXT_PAGE(level1_vsyscall_pgt)
24825+ .fill 512,8,0
24826+
24827 #undef PMDS
24828
24829- .data
24830+ .align PAGE_SIZE
24831+ENTRY(cpu_gdt_table)
24832+ .rept NR_CPUS
24833+ .quad 0x0000000000000000 /* NULL descriptor */
24834+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24835+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24836+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24837+ .quad 0x00cffb000000ffff /* __USER32_CS */
24838+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24839+ .quad 0x00affb000000ffff /* __USER_CS */
24840+
24841+#ifdef CONFIG_PAX_KERNEXEC
24842+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24843+#else
24844+ .quad 0x0 /* unused */
24845+#endif
24846+
24847+ .quad 0,0 /* TSS */
24848+ .quad 0,0 /* LDT */
24849+ .quad 0,0,0 /* three TLS descriptors */
24850+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24851+ /* asm/segment.h:GDT_ENTRIES must match this */
24852+
24853+#ifdef CONFIG_PAX_MEMORY_UDEREF
24854+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24855+#else
24856+ .quad 0x0 /* unused */
24857+#endif
24858+
24859+ /* zero the remaining page */
24860+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24861+ .endr
24862+
24863 .align 16
24864 .globl early_gdt_descr
24865 early_gdt_descr:
24866 .word GDT_ENTRIES*8-1
24867 early_gdt_descr_base:
24868- .quad INIT_PER_CPU_VAR(gdt_page)
24869+ .quad cpu_gdt_table
24870
24871 ENTRY(phys_base)
24872 /* This must match the first entry in level2_kernel_pgt */
24873 .quad 0x0000000000000000
24874
24875 #include "../../x86/xen/xen-head.S"
24876-
24877- __PAGE_ALIGNED_BSS
24878+
24879+ .section .rodata,"a",@progbits
24880 NEXT_PAGE(empty_zero_page)
24881 .skip PAGE_SIZE
24882diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24883index 05fd74f..c3548b1 100644
24884--- a/arch/x86/kernel/i386_ksyms_32.c
24885+++ b/arch/x86/kernel/i386_ksyms_32.c
24886@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24887 EXPORT_SYMBOL(cmpxchg8b_emu);
24888 #endif
24889
24890+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24891+
24892 /* Networking helper routines. */
24893 EXPORT_SYMBOL(csum_partial_copy_generic);
24894+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24895+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24896
24897 EXPORT_SYMBOL(__get_user_1);
24898 EXPORT_SYMBOL(__get_user_2);
24899@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24900 EXPORT_SYMBOL(___preempt_schedule_context);
24901 #endif
24902 #endif
24903+
24904+#ifdef CONFIG_PAX_KERNEXEC
24905+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24906+#endif
24907+
24908+#ifdef CONFIG_PAX_PER_CPU_PGD
24909+EXPORT_SYMBOL(cpu_pgd);
24910+#endif
24911diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24912index d5dd808..b6432cf 100644
24913--- a/arch/x86/kernel/i387.c
24914+++ b/arch/x86/kernel/i387.c
24915@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24916 static inline bool interrupted_user_mode(void)
24917 {
24918 struct pt_regs *regs = get_irq_regs();
24919- return regs && user_mode_vm(regs);
24920+ return regs && user_mode(regs);
24921 }
24922
24923 /*
24924diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24925index 2e977b5..5f2c273 100644
24926--- a/arch/x86/kernel/i8259.c
24927+++ b/arch/x86/kernel/i8259.c
24928@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24929 static void make_8259A_irq(unsigned int irq)
24930 {
24931 disable_irq_nosync(irq);
24932- io_apic_irqs &= ~(1<<irq);
24933+ io_apic_irqs &= ~(1UL<<irq);
24934 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24935 i8259A_chip.name);
24936 enable_irq(irq);
24937@@ -209,7 +209,7 @@ spurious_8259A_irq:
24938 "spurious 8259A interrupt: IRQ%d.\n", irq);
24939 spurious_irq_mask |= irqmask;
24940 }
24941- atomic_inc(&irq_err_count);
24942+ atomic_inc_unchecked(&irq_err_count);
24943 /*
24944 * Theoretically we do not have to handle this IRQ,
24945 * but in Linux this does not cause problems and is
24946@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24947 /* (slave's support for AEOI in flat mode is to be investigated) */
24948 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24949
24950+ pax_open_kernel();
24951 if (auto_eoi)
24952 /*
24953 * In AEOI mode we just have to mask the interrupt
24954 * when acking.
24955 */
24956- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24957+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24958 else
24959- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24960+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24961+ pax_close_kernel();
24962
24963 udelay(100); /* wait for 8259A to initialize */
24964
24965diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24966index a979b5b..1d6db75 100644
24967--- a/arch/x86/kernel/io_delay.c
24968+++ b/arch/x86/kernel/io_delay.c
24969@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24970 * Quirk table for systems that misbehave (lock up, etc.) if port
24971 * 0x80 is used:
24972 */
24973-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24974+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24975 {
24976 .callback = dmi_io_delay_0xed_port,
24977 .ident = "Compaq Presario V6000",
24978diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24979index 4ddaf66..49d5c18 100644
24980--- a/arch/x86/kernel/ioport.c
24981+++ b/arch/x86/kernel/ioport.c
24982@@ -6,6 +6,7 @@
24983 #include <linux/sched.h>
24984 #include <linux/kernel.h>
24985 #include <linux/capability.h>
24986+#include <linux/security.h>
24987 #include <linux/errno.h>
24988 #include <linux/types.h>
24989 #include <linux/ioport.h>
24990@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24991 return -EINVAL;
24992 if (turn_on && !capable(CAP_SYS_RAWIO))
24993 return -EPERM;
24994+#ifdef CONFIG_GRKERNSEC_IO
24995+ if (turn_on && grsec_disable_privio) {
24996+ gr_handle_ioperm();
24997+ return -ENODEV;
24998+ }
24999+#endif
25000
25001 /*
25002 * If it's the first ioperm() call in this thread's lifetime, set the
25003@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25004 * because the ->io_bitmap_max value must match the bitmap
25005 * contents:
25006 */
25007- tss = &per_cpu(init_tss, get_cpu());
25008+ tss = init_tss + get_cpu();
25009
25010 if (turn_on)
25011 bitmap_clear(t->io_bitmap_ptr, from, num);
25012@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25013 if (level > old) {
25014 if (!capable(CAP_SYS_RAWIO))
25015 return -EPERM;
25016+#ifdef CONFIG_GRKERNSEC_IO
25017+ if (grsec_disable_privio) {
25018+ gr_handle_iopl();
25019+ return -ENODEV;
25020+ }
25021+#endif
25022 }
25023 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25024 t->iopl = level << 12;
25025diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25026index 11ccfb0..ec1e46f 100644
25027--- a/arch/x86/kernel/irq.c
25028+++ b/arch/x86/kernel/irq.c
25029@@ -22,7 +22,7 @@
25030 #define CREATE_TRACE_POINTS
25031 #include <asm/trace/irq_vectors.h>
25032
25033-atomic_t irq_err_count;
25034+atomic_unchecked_t irq_err_count;
25035
25036 /* Function pointer for generic interrupt vector handling */
25037 void (*x86_platform_ipi_callback)(void) = NULL;
25038@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25039 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25040 seq_printf(p, " Hypervisor callback interrupts\n");
25041 #endif
25042- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25043+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25044 #if defined(CONFIG_X86_IO_APIC)
25045- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25046+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25047 #endif
25048 return 0;
25049 }
25050@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25051
25052 u64 arch_irq_stat(void)
25053 {
25054- u64 sum = atomic_read(&irq_err_count);
25055+ u64 sum = atomic_read_unchecked(&irq_err_count);
25056 return sum;
25057 }
25058
25059diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25060index 63ce838..2ea3e06 100644
25061--- a/arch/x86/kernel/irq_32.c
25062+++ b/arch/x86/kernel/irq_32.c
25063@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25064
25065 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25066
25067+extern void gr_handle_kernel_exploit(void);
25068+
25069 int sysctl_panic_on_stackoverflow __read_mostly;
25070
25071 /* Debugging check for stack overflow: is there less than 1KB free? */
25072@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25073 __asm__ __volatile__("andl %%esp,%0" :
25074 "=r" (sp) : "0" (THREAD_SIZE - 1));
25075
25076- return sp < (sizeof(struct thread_info) + STACK_WARN);
25077+ return sp < STACK_WARN;
25078 }
25079
25080 static void print_stack_overflow(void)
25081 {
25082 printk(KERN_WARNING "low stack detected by irq handler\n");
25083 dump_stack();
25084+ gr_handle_kernel_exploit();
25085 if (sysctl_panic_on_stackoverflow)
25086 panic("low stack detected by irq handler - check messages\n");
25087 }
25088@@ -84,10 +87,9 @@ static inline void *current_stack(void)
25089 static inline int
25090 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25091 {
25092- struct irq_stack *curstk, *irqstk;
25093+ struct irq_stack *irqstk;
25094 u32 *isp, *prev_esp, arg1, arg2;
25095
25096- curstk = (struct irq_stack *) current_stack();
25097 irqstk = __this_cpu_read(hardirq_stack);
25098
25099 /*
25100@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25101 * handler) we can't do that and just have to keep using the
25102 * current stack (which is the irq stack already after all)
25103 */
25104- if (unlikely(curstk == irqstk))
25105+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25106 return 0;
25107
25108- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25109+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25110
25111 /* Save the next esp at the bottom of the stack */
25112 prev_esp = (u32 *)irqstk;
25113 *prev_esp = current_stack_pointer;
25114
25115+#ifdef CONFIG_PAX_MEMORY_UDEREF
25116+ __set_fs(MAKE_MM_SEG(0));
25117+#endif
25118+
25119 if (unlikely(overflow))
25120 call_on_stack(print_stack_overflow, isp);
25121
25122@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25123 : "0" (irq), "1" (desc), "2" (isp),
25124 "D" (desc->handle_irq)
25125 : "memory", "cc", "ecx");
25126+
25127+#ifdef CONFIG_PAX_MEMORY_UDEREF
25128+ __set_fs(current_thread_info()->addr_limit);
25129+#endif
25130+
25131 return 1;
25132 }
25133
25134@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25135 */
25136 void irq_ctx_init(int cpu)
25137 {
25138- struct irq_stack *irqstk;
25139-
25140 if (per_cpu(hardirq_stack, cpu))
25141 return;
25142
25143- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25144- THREADINFO_GFP,
25145- THREAD_SIZE_ORDER));
25146- per_cpu(hardirq_stack, cpu) = irqstk;
25147-
25148- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25149- THREADINFO_GFP,
25150- THREAD_SIZE_ORDER));
25151- per_cpu(softirq_stack, cpu) = irqstk;
25152-
25153- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25154- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25155+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25156+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25157 }
25158
25159 void do_softirq_own_stack(void)
25160 {
25161- struct thread_info *curstk;
25162 struct irq_stack *irqstk;
25163 u32 *isp, *prev_esp;
25164
25165- curstk = current_stack();
25166 irqstk = __this_cpu_read(softirq_stack);
25167
25168 /* build the stack frame on the softirq stack */
25169@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25170 prev_esp = (u32 *)irqstk;
25171 *prev_esp = current_stack_pointer;
25172
25173+#ifdef CONFIG_PAX_MEMORY_UDEREF
25174+ __set_fs(MAKE_MM_SEG(0));
25175+#endif
25176+
25177 call_on_stack(__do_softirq, isp);
25178+
25179+#ifdef CONFIG_PAX_MEMORY_UDEREF
25180+ __set_fs(current_thread_info()->addr_limit);
25181+#endif
25182+
25183 }
25184
25185 bool handle_irq(unsigned irq, struct pt_regs *regs)
25186@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25187 if (unlikely(!desc))
25188 return false;
25189
25190- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25191+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25192 if (unlikely(overflow))
25193 print_stack_overflow();
25194 desc->handle_irq(irq, desc);
25195diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25196index 4d1c746..55a22d6 100644
25197--- a/arch/x86/kernel/irq_64.c
25198+++ b/arch/x86/kernel/irq_64.c
25199@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25200 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25201 EXPORT_PER_CPU_SYMBOL(irq_regs);
25202
25203+extern void gr_handle_kernel_exploit(void);
25204+
25205 int sysctl_panic_on_stackoverflow;
25206
25207 /*
25208@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25209 u64 estack_top, estack_bottom;
25210 u64 curbase = (u64)task_stack_page(current);
25211
25212- if (user_mode_vm(regs))
25213+ if (user_mode(regs))
25214 return;
25215
25216 if (regs->sp >= curbase + sizeof(struct thread_info) +
25217@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25218 irq_stack_top, irq_stack_bottom,
25219 estack_top, estack_bottom);
25220
25221+ gr_handle_kernel_exploit();
25222+
25223 if (sysctl_panic_on_stackoverflow)
25224 panic("low stack detected by irq handler - check messages\n");
25225 #endif
25226diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25227index 26d5a55..a01160a 100644
25228--- a/arch/x86/kernel/jump_label.c
25229+++ b/arch/x86/kernel/jump_label.c
25230@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25231 * Jump label is enabled for the first time.
25232 * So we expect a default_nop...
25233 */
25234- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25235+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25236 != 0))
25237 bug_at((void *)entry->code, __LINE__);
25238 } else {
25239@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25240 * ...otherwise expect an ideal_nop. Otherwise
25241 * something went horribly wrong.
25242 */
25243- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25244+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25245 != 0))
25246 bug_at((void *)entry->code, __LINE__);
25247 }
25248@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25249 * are converting the default nop to the ideal nop.
25250 */
25251 if (init) {
25252- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25253+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25254 bug_at((void *)entry->code, __LINE__);
25255 } else {
25256 code.jump = 0xe9;
25257 code.offset = entry->target -
25258 (entry->code + JUMP_LABEL_NOP_SIZE);
25259- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25260+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25261 bug_at((void *)entry->code, __LINE__);
25262 }
25263 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25264diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25265index 7ec1d5f..5a7d130 100644
25266--- a/arch/x86/kernel/kgdb.c
25267+++ b/arch/x86/kernel/kgdb.c
25268@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25269 #ifdef CONFIG_X86_32
25270 switch (regno) {
25271 case GDB_SS:
25272- if (!user_mode_vm(regs))
25273+ if (!user_mode(regs))
25274 *(unsigned long *)mem = __KERNEL_DS;
25275 break;
25276 case GDB_SP:
25277- if (!user_mode_vm(regs))
25278+ if (!user_mode(regs))
25279 *(unsigned long *)mem = kernel_stack_pointer(regs);
25280 break;
25281 case GDB_GS:
25282@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25283 bp->attr.bp_addr = breakinfo[breakno].addr;
25284 bp->attr.bp_len = breakinfo[breakno].len;
25285 bp->attr.bp_type = breakinfo[breakno].type;
25286- info->address = breakinfo[breakno].addr;
25287+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25288+ info->address = ktla_ktva(breakinfo[breakno].addr);
25289+ else
25290+ info->address = breakinfo[breakno].addr;
25291 info->len = breakinfo[breakno].len;
25292 info->type = breakinfo[breakno].type;
25293 val = arch_install_hw_breakpoint(bp);
25294@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25295 case 'k':
25296 /* clear the trace bit */
25297 linux_regs->flags &= ~X86_EFLAGS_TF;
25298- atomic_set(&kgdb_cpu_doing_single_step, -1);
25299+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25300
25301 /* set the trace bit if we're stepping */
25302 if (remcomInBuffer[0] == 's') {
25303 linux_regs->flags |= X86_EFLAGS_TF;
25304- atomic_set(&kgdb_cpu_doing_single_step,
25305+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25306 raw_smp_processor_id());
25307 }
25308
25309@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25310
25311 switch (cmd) {
25312 case DIE_DEBUG:
25313- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25314+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25315 if (user_mode(regs))
25316 return single_step_cont(regs, args);
25317 break;
25318@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25319 #endif /* CONFIG_DEBUG_RODATA */
25320
25321 bpt->type = BP_BREAKPOINT;
25322- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25323+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25324 BREAK_INSTR_SIZE);
25325 if (err)
25326 return err;
25327- err = probe_kernel_write((char *)bpt->bpt_addr,
25328+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25329 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25330 #ifdef CONFIG_DEBUG_RODATA
25331 if (!err)
25332@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25333 return -EBUSY;
25334 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25335 BREAK_INSTR_SIZE);
25336- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25337+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25338 if (err)
25339 return err;
25340 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25341@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25342 if (mutex_is_locked(&text_mutex))
25343 goto knl_write;
25344 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25345- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25346+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25347 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25348 goto knl_write;
25349 return err;
25350 knl_write:
25351 #endif /* CONFIG_DEBUG_RODATA */
25352- return probe_kernel_write((char *)bpt->bpt_addr,
25353+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25354 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25355 }
25356
25357diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25358index 61b17dc..784bfe9 100644
25359--- a/arch/x86/kernel/kprobes/core.c
25360+++ b/arch/x86/kernel/kprobes/core.c
25361@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25362 s32 raddr;
25363 } __packed *insn;
25364
25365- insn = (struct __arch_relative_insn *)from;
25366+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25367+
25368+ pax_open_kernel();
25369 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25370 insn->op = op;
25371+ pax_close_kernel();
25372 }
25373
25374 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25375@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25376 kprobe_opcode_t opcode;
25377 kprobe_opcode_t *orig_opcodes = opcodes;
25378
25379- if (search_exception_tables((unsigned long)opcodes))
25380+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25381 return 0; /* Page fault may occur on this address. */
25382
25383 retry:
25384@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25385 * for the first byte, we can recover the original instruction
25386 * from it and kp->opcode.
25387 */
25388- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25389+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25390 buf[0] = kp->opcode;
25391- return (unsigned long)buf;
25392+ return ktva_ktla((unsigned long)buf);
25393 }
25394
25395 /*
25396@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25397 /* Another subsystem puts a breakpoint, failed to recover */
25398 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25399 return 0;
25400+ pax_open_kernel();
25401 memcpy(dest, insn.kaddr, insn.length);
25402+ pax_close_kernel();
25403
25404 #ifdef CONFIG_X86_64
25405 if (insn_rip_relative(&insn)) {
25406@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25407 return 0;
25408 }
25409 disp = (u8 *) dest + insn_offset_displacement(&insn);
25410+ pax_open_kernel();
25411 *(s32 *) disp = (s32) newdisp;
25412+ pax_close_kernel();
25413 }
25414 #endif
25415 return insn.length;
25416@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25417 * nor set current_kprobe, because it doesn't use single
25418 * stepping.
25419 */
25420- regs->ip = (unsigned long)p->ainsn.insn;
25421+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25422 preempt_enable_no_resched();
25423 return;
25424 }
25425@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25426 regs->flags &= ~X86_EFLAGS_IF;
25427 /* single step inline if the instruction is an int3 */
25428 if (p->opcode == BREAKPOINT_INSTRUCTION)
25429- regs->ip = (unsigned long)p->addr;
25430+ regs->ip = ktla_ktva((unsigned long)p->addr);
25431 else
25432- regs->ip = (unsigned long)p->ainsn.insn;
25433+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25434 }
25435
25436 /*
25437@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25438 setup_singlestep(p, regs, kcb, 0);
25439 return 1;
25440 }
25441- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25442+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25443 /*
25444 * The breakpoint instruction was removed right
25445 * after we hit it. Another cpu has removed
25446@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25447 " movq %rax, 152(%rsp)\n"
25448 RESTORE_REGS_STRING
25449 " popfq\n"
25450+#ifdef KERNEXEC_PLUGIN
25451+ " btsq $63,(%rsp)\n"
25452+#endif
25453 #else
25454 " pushf\n"
25455 SAVE_REGS_STRING
25456@@ -779,7 +789,7 @@ static void __kprobes
25457 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25458 {
25459 unsigned long *tos = stack_addr(regs);
25460- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25461+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25462 unsigned long orig_ip = (unsigned long)p->addr;
25463 kprobe_opcode_t *insn = p->ainsn.insn;
25464
25465@@ -959,7 +969,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25466 struct die_args *args = data;
25467 int ret = NOTIFY_DONE;
25468
25469- if (args->regs && user_mode_vm(args->regs))
25470+ if (args->regs && user_mode(args->regs))
25471 return ret;
25472
25473 switch (val) {
25474diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25475index 898160b..758cde8 100644
25476--- a/arch/x86/kernel/kprobes/opt.c
25477+++ b/arch/x86/kernel/kprobes/opt.c
25478@@ -79,6 +79,7 @@ found:
25479 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25480 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25481 {
25482+ pax_open_kernel();
25483 #ifdef CONFIG_X86_64
25484 *addr++ = 0x48;
25485 *addr++ = 0xbf;
25486@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25487 *addr++ = 0xb8;
25488 #endif
25489 *(unsigned long *)addr = val;
25490+ pax_close_kernel();
25491 }
25492
25493 asm (
25494@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25495 * Verify if the address gap is in 2GB range, because this uses
25496 * a relative jump.
25497 */
25498- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25499+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25500 if (abs(rel) > 0x7fffffff)
25501 return -ERANGE;
25502
25503@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25504 op->optinsn.size = ret;
25505
25506 /* Copy arch-dep-instance from template */
25507- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25508+ pax_open_kernel();
25509+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25510+ pax_close_kernel();
25511
25512 /* Set probe information */
25513 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25514
25515 /* Set probe function call */
25516- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25517+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25518
25519 /* Set returning jmp instruction at the tail of out-of-line buffer */
25520- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25521+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25522 (u8 *)op->kp.addr + op->optinsn.size);
25523
25524 flush_icache_range((unsigned long) buf,
25525@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25526 WARN_ON(kprobe_disabled(&op->kp));
25527
25528 /* Backup instructions which will be replaced by jump address */
25529- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25530+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25531 RELATIVE_ADDR_SIZE);
25532
25533 insn_buf[0] = RELATIVEJUMP_OPCODE;
25534@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25535 /* This kprobe is really able to run optimized path. */
25536 op = container_of(p, struct optimized_kprobe, kp);
25537 /* Detour through copied instructions */
25538- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25539+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25540 if (!reenter)
25541 reset_current_kprobe();
25542 preempt_enable_no_resched();
25543diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25544index c2bedae..25e7ab60 100644
25545--- a/arch/x86/kernel/ksysfs.c
25546+++ b/arch/x86/kernel/ksysfs.c
25547@@ -184,7 +184,7 @@ out:
25548
25549 static struct kobj_attribute type_attr = __ATTR_RO(type);
25550
25551-static struct bin_attribute data_attr = {
25552+static bin_attribute_no_const data_attr __read_only = {
25553 .attr = {
25554 .name = "data",
25555 .mode = S_IRUGO,
25556diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25557index c37886d..d851d32 100644
25558--- a/arch/x86/kernel/ldt.c
25559+++ b/arch/x86/kernel/ldt.c
25560@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25561 if (reload) {
25562 #ifdef CONFIG_SMP
25563 preempt_disable();
25564- load_LDT(pc);
25565+ load_LDT_nolock(pc);
25566 if (!cpumask_equal(mm_cpumask(current->mm),
25567 cpumask_of(smp_processor_id())))
25568 smp_call_function(flush_ldt, current->mm, 1);
25569 preempt_enable();
25570 #else
25571- load_LDT(pc);
25572+ load_LDT_nolock(pc);
25573 #endif
25574 }
25575 if (oldsize) {
25576@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25577 return err;
25578
25579 for (i = 0; i < old->size; i++)
25580- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25581+ write_ldt_entry(new->ldt, i, old->ldt + i);
25582 return 0;
25583 }
25584
25585@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25586 retval = copy_ldt(&mm->context, &old_mm->context);
25587 mutex_unlock(&old_mm->context.lock);
25588 }
25589+
25590+ if (tsk == current) {
25591+ mm->context.vdso = 0;
25592+
25593+#ifdef CONFIG_X86_32
25594+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25595+ mm->context.user_cs_base = 0UL;
25596+ mm->context.user_cs_limit = ~0UL;
25597+
25598+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25599+ cpus_clear(mm->context.cpu_user_cs_mask);
25600+#endif
25601+
25602+#endif
25603+#endif
25604+
25605+ }
25606+
25607 return retval;
25608 }
25609
25610@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25611 }
25612 }
25613
25614+#ifdef CONFIG_PAX_SEGMEXEC
25615+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25616+ error = -EINVAL;
25617+ goto out_unlock;
25618+ }
25619+#endif
25620+
25621 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25622 error = -EINVAL;
25623 goto out_unlock;
25624diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25625index 1667b1d..16492c5 100644
25626--- a/arch/x86/kernel/machine_kexec_32.c
25627+++ b/arch/x86/kernel/machine_kexec_32.c
25628@@ -25,7 +25,7 @@
25629 #include <asm/cacheflush.h>
25630 #include <asm/debugreg.h>
25631
25632-static void set_idt(void *newidt, __u16 limit)
25633+static void set_idt(struct desc_struct *newidt, __u16 limit)
25634 {
25635 struct desc_ptr curidt;
25636
25637@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25638 }
25639
25640
25641-static void set_gdt(void *newgdt, __u16 limit)
25642+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25643 {
25644 struct desc_ptr curgdt;
25645
25646@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25647 }
25648
25649 control_page = page_address(image->control_code_page);
25650- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25651+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25652
25653 relocate_kernel_ptr = control_page;
25654 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25655diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25656index e69f988..da078ea 100644
25657--- a/arch/x86/kernel/module.c
25658+++ b/arch/x86/kernel/module.c
25659@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25660 }
25661 #endif
25662
25663-void *module_alloc(unsigned long size)
25664+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25665 {
25666- if (PAGE_ALIGN(size) > MODULES_LEN)
25667+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25668 return NULL;
25669 return __vmalloc_node_range(size, 1,
25670 MODULES_VADDR + get_module_load_offset(),
25671- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25672- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25673+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25674+ prot, NUMA_NO_NODE,
25675 __builtin_return_address(0));
25676 }
25677
25678+void *module_alloc(unsigned long size)
25679+{
25680+
25681+#ifdef CONFIG_PAX_KERNEXEC
25682+ return __module_alloc(size, PAGE_KERNEL);
25683+#else
25684+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25685+#endif
25686+
25687+}
25688+
25689+#ifdef CONFIG_PAX_KERNEXEC
25690+#ifdef CONFIG_X86_32
25691+void *module_alloc_exec(unsigned long size)
25692+{
25693+ struct vm_struct *area;
25694+
25695+ if (size == 0)
25696+ return NULL;
25697+
25698+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25699+return area ? area->addr : NULL;
25700+}
25701+EXPORT_SYMBOL(module_alloc_exec);
25702+
25703+void module_free_exec(struct module *mod, void *module_region)
25704+{
25705+ vunmap(module_region);
25706+}
25707+EXPORT_SYMBOL(module_free_exec);
25708+#else
25709+void module_free_exec(struct module *mod, void *module_region)
25710+{
25711+ module_free(mod, module_region);
25712+}
25713+EXPORT_SYMBOL(module_free_exec);
25714+
25715+void *module_alloc_exec(unsigned long size)
25716+{
25717+ return __module_alloc(size, PAGE_KERNEL_RX);
25718+}
25719+EXPORT_SYMBOL(module_alloc_exec);
25720+#endif
25721+#endif
25722+
25723 #ifdef CONFIG_X86_32
25724 int apply_relocate(Elf32_Shdr *sechdrs,
25725 const char *strtab,
25726@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25727 unsigned int i;
25728 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25729 Elf32_Sym *sym;
25730- uint32_t *location;
25731+ uint32_t *plocation, location;
25732
25733 DEBUGP("Applying relocate section %u to %u\n",
25734 relsec, sechdrs[relsec].sh_info);
25735 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25736 /* This is where to make the change */
25737- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25738- + rel[i].r_offset;
25739+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25740+ location = (uint32_t)plocation;
25741+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25742+ plocation = ktla_ktva((void *)plocation);
25743 /* This is the symbol it is referring to. Note that all
25744 undefined symbols have been resolved. */
25745 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25746@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25747 switch (ELF32_R_TYPE(rel[i].r_info)) {
25748 case R_386_32:
25749 /* We add the value into the location given */
25750- *location += sym->st_value;
25751+ pax_open_kernel();
25752+ *plocation += sym->st_value;
25753+ pax_close_kernel();
25754 break;
25755 case R_386_PC32:
25756 /* Add the value, subtract its position */
25757- *location += sym->st_value - (uint32_t)location;
25758+ pax_open_kernel();
25759+ *plocation += sym->st_value - location;
25760+ pax_close_kernel();
25761 break;
25762 default:
25763 pr_err("%s: Unknown relocation: %u\n",
25764@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25765 case R_X86_64_NONE:
25766 break;
25767 case R_X86_64_64:
25768+ pax_open_kernel();
25769 *(u64 *)loc = val;
25770+ pax_close_kernel();
25771 break;
25772 case R_X86_64_32:
25773+ pax_open_kernel();
25774 *(u32 *)loc = val;
25775+ pax_close_kernel();
25776 if (val != *(u32 *)loc)
25777 goto overflow;
25778 break;
25779 case R_X86_64_32S:
25780+ pax_open_kernel();
25781 *(s32 *)loc = val;
25782+ pax_close_kernel();
25783 if ((s64)val != *(s32 *)loc)
25784 goto overflow;
25785 break;
25786 case R_X86_64_PC32:
25787 val -= (u64)loc;
25788+ pax_open_kernel();
25789 *(u32 *)loc = val;
25790+ pax_close_kernel();
25791+
25792 #if 0
25793 if ((s64)val != *(s32 *)loc)
25794 goto overflow;
25795diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25796index c9603ac..9f88728 100644
25797--- a/arch/x86/kernel/msr.c
25798+++ b/arch/x86/kernel/msr.c
25799@@ -37,6 +37,7 @@
25800 #include <linux/notifier.h>
25801 #include <linux/uaccess.h>
25802 #include <linux/gfp.h>
25803+#include <linux/grsecurity.h>
25804
25805 #include <asm/processor.h>
25806 #include <asm/msr.h>
25807@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25808 int err = 0;
25809 ssize_t bytes = 0;
25810
25811+#ifdef CONFIG_GRKERNSEC_KMEM
25812+ gr_handle_msr_write();
25813+ return -EPERM;
25814+#endif
25815+
25816 if (count % 8)
25817 return -EINVAL; /* Invalid chunk size */
25818
25819@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25820 err = -EBADF;
25821 break;
25822 }
25823+#ifdef CONFIG_GRKERNSEC_KMEM
25824+ gr_handle_msr_write();
25825+ return -EPERM;
25826+#endif
25827 if (copy_from_user(&regs, uregs, sizeof regs)) {
25828 err = -EFAULT;
25829 break;
25830@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25831 return notifier_from_errno(err);
25832 }
25833
25834-static struct notifier_block __refdata msr_class_cpu_notifier = {
25835+static struct notifier_block msr_class_cpu_notifier = {
25836 .notifier_call = msr_class_cpu_callback,
25837 };
25838
25839diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25840index b4872b9..5bf0684 100644
25841--- a/arch/x86/kernel/nmi.c
25842+++ b/arch/x86/kernel/nmi.c
25843@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
25844
25845 static void nmi_max_handler(struct irq_work *w)
25846 {
25847- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
25848+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
25849 int remainder_ns, decimal_msecs;
25850- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
25851+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
25852
25853 remainder_ns = do_div(whole_msecs, (1000 * 1000));
25854 decimal_msecs = remainder_ns / 1000;
25855
25856 printk_ratelimited(KERN_INFO
25857 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
25858- a->handler, whole_msecs, decimal_msecs);
25859+ n->action->handler, whole_msecs, decimal_msecs);
25860 }
25861
25862 static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
25863@@ -134,11 +134,11 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25864 delta = sched_clock() - delta;
25865 trace_nmi_handler(a->handler, (int)delta, thishandled);
25866
25867- if (delta < nmi_longest_ns || delta < a->max_duration)
25868+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
25869 continue;
25870
25871- a->max_duration = delta;
25872- irq_work_queue(&a->irq_work);
25873+ a->work->max_duration = delta;
25874+ irq_work_queue(&a->work->irq_work);
25875 }
25876
25877 rcu_read_unlock();
25878@@ -147,7 +147,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25879 return handled;
25880 }
25881
25882-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25883+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25884 {
25885 struct nmi_desc *desc = nmi_to_desc(type);
25886 unsigned long flags;
25887@@ -155,7 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25888 if (!action->handler)
25889 return -EINVAL;
25890
25891- init_irq_work(&action->irq_work, nmi_max_handler);
25892+ action->work->action = action;
25893+ init_irq_work(&action->work->irq_work, nmi_max_handler);
25894
25895 spin_lock_irqsave(&desc->lock, flags);
25896
25897@@ -173,9 +174,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25898 * event confuses some handlers (kdump uses this flag)
25899 */
25900 if (action->flags & NMI_FLAG_FIRST)
25901- list_add_rcu(&action->list, &desc->head);
25902+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25903 else
25904- list_add_tail_rcu(&action->list, &desc->head);
25905+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25906
25907 spin_unlock_irqrestore(&desc->lock, flags);
25908 return 0;
25909@@ -198,7 +199,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25910 if (!strcmp(n->name, name)) {
25911 WARN(in_nmi(),
25912 "Trying to free NMI (%s) from NMI context!\n", n->name);
25913- list_del_rcu(&n->list);
25914+ pax_list_del_rcu((struct list_head *)&n->list);
25915 break;
25916 }
25917 }
25918@@ -523,6 +524,17 @@ static inline void nmi_nesting_postprocess(void)
25919 dotraplinkage notrace __kprobes void
25920 do_nmi(struct pt_regs *regs, long error_code)
25921 {
25922+
25923+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25924+ if (!user_mode(regs)) {
25925+ unsigned long cs = regs->cs & 0xFFFF;
25926+ unsigned long ip = ktva_ktla(regs->ip);
25927+
25928+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25929+ regs->ip = ip;
25930+ }
25931+#endif
25932+
25933 nmi_nesting_preprocess(regs);
25934
25935 nmi_enter();
25936diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25937index 6d9582e..f746287 100644
25938--- a/arch/x86/kernel/nmi_selftest.c
25939+++ b/arch/x86/kernel/nmi_selftest.c
25940@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25941 {
25942 /* trap all the unknown NMIs we may generate */
25943 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25944- __initdata);
25945+ __initconst);
25946 }
25947
25948 static void __init cleanup_nmi_testsuite(void)
25949@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25950 unsigned long timeout;
25951
25952 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25953- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25954+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25955 nmi_fail = FAILURE;
25956 return;
25957 }
25958diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25959index bbb6c73..24a58ef 100644
25960--- a/arch/x86/kernel/paravirt-spinlocks.c
25961+++ b/arch/x86/kernel/paravirt-spinlocks.c
25962@@ -8,7 +8,7 @@
25963
25964 #include <asm/paravirt.h>
25965
25966-struct pv_lock_ops pv_lock_ops = {
25967+struct pv_lock_ops pv_lock_ops __read_only = {
25968 #ifdef CONFIG_SMP
25969 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25970 .unlock_kick = paravirt_nop,
25971diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25972index 1b10af8..45bfbec 100644
25973--- a/arch/x86/kernel/paravirt.c
25974+++ b/arch/x86/kernel/paravirt.c
25975@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25976 {
25977 return x;
25978 }
25979+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25980+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25981+#endif
25982
25983 void __init default_banner(void)
25984 {
25985@@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25986
25987 if (opfunc == NULL)
25988 /* If there's no function, patch it with a ud2a (BUG) */
25989- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25990- else if (opfunc == _paravirt_nop)
25991+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
25992+ else if (opfunc == (void *)_paravirt_nop)
25993 /* If the operation is a nop, then nop the callsite */
25994 ret = paravirt_patch_nop();
25995
25996 /* identity functions just return their single argument */
25997- else if (opfunc == _paravirt_ident_32)
25998+ else if (opfunc == (void *)_paravirt_ident_32)
25999 ret = paravirt_patch_ident_32(insnbuf, len);
26000- else if (opfunc == _paravirt_ident_64)
26001+ else if (opfunc == (void *)_paravirt_ident_64)
26002 ret = paravirt_patch_ident_64(insnbuf, len);
26003+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26004+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26005+ ret = paravirt_patch_ident_64(insnbuf, len);
26006+#endif
26007
26008 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26009 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26010@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26011 if (insn_len > len || start == NULL)
26012 insn_len = len;
26013 else
26014- memcpy(insnbuf, start, insn_len);
26015+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26016
26017 return insn_len;
26018 }
26019@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26020 return this_cpu_read(paravirt_lazy_mode);
26021 }
26022
26023-struct pv_info pv_info = {
26024+struct pv_info pv_info __read_only = {
26025 .name = "bare hardware",
26026 .paravirt_enabled = 0,
26027 .kernel_rpl = 0,
26028@@ -310,16 +317,16 @@ struct pv_info pv_info = {
26029 #endif
26030 };
26031
26032-struct pv_init_ops pv_init_ops = {
26033+struct pv_init_ops pv_init_ops __read_only = {
26034 .patch = native_patch,
26035 };
26036
26037-struct pv_time_ops pv_time_ops = {
26038+struct pv_time_ops pv_time_ops __read_only = {
26039 .sched_clock = native_sched_clock,
26040 .steal_clock = native_steal_clock,
26041 };
26042
26043-__visible struct pv_irq_ops pv_irq_ops = {
26044+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26045 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26046 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26047 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26048@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26049 #endif
26050 };
26051
26052-__visible struct pv_cpu_ops pv_cpu_ops = {
26053+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26054 .cpuid = native_cpuid,
26055 .get_debugreg = native_get_debugreg,
26056 .set_debugreg = native_set_debugreg,
26057@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26058 .end_context_switch = paravirt_nop,
26059 };
26060
26061-struct pv_apic_ops pv_apic_ops = {
26062+struct pv_apic_ops pv_apic_ops __read_only= {
26063 #ifdef CONFIG_X86_LOCAL_APIC
26064 .startup_ipi_hook = paravirt_nop,
26065 #endif
26066 };
26067
26068-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26069+#ifdef CONFIG_X86_32
26070+#ifdef CONFIG_X86_PAE
26071+/* 64-bit pagetable entries */
26072+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26073+#else
26074 /* 32-bit pagetable entries */
26075 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26076+#endif
26077 #else
26078 /* 64-bit pagetable entries */
26079 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26080 #endif
26081
26082-struct pv_mmu_ops pv_mmu_ops = {
26083+struct pv_mmu_ops pv_mmu_ops __read_only = {
26084
26085 .read_cr2 = native_read_cr2,
26086 .write_cr2 = native_write_cr2,
26087@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26088 .make_pud = PTE_IDENT,
26089
26090 .set_pgd = native_set_pgd,
26091+ .set_pgd_batched = native_set_pgd_batched,
26092 #endif
26093 #endif /* PAGETABLE_LEVELS >= 3 */
26094
26095@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26096 },
26097
26098 .set_fixmap = native_set_fixmap,
26099+
26100+#ifdef CONFIG_PAX_KERNEXEC
26101+ .pax_open_kernel = native_pax_open_kernel,
26102+ .pax_close_kernel = native_pax_close_kernel,
26103+#endif
26104+
26105 };
26106
26107 EXPORT_SYMBOL_GPL(pv_time_ops);
26108diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26109index 0497f71..7186c0d 100644
26110--- a/arch/x86/kernel/pci-calgary_64.c
26111+++ b/arch/x86/kernel/pci-calgary_64.c
26112@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26113 tce_space = be64_to_cpu(readq(target));
26114 tce_space = tce_space & TAR_SW_BITS;
26115
26116- tce_space = tce_space & (~specified_table_size);
26117+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26118 info->tce_space = (u64 *)__va(tce_space);
26119 }
26120 }
26121diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26122index 35ccf75..7a15747 100644
26123--- a/arch/x86/kernel/pci-iommu_table.c
26124+++ b/arch/x86/kernel/pci-iommu_table.c
26125@@ -2,7 +2,7 @@
26126 #include <asm/iommu_table.h>
26127 #include <linux/string.h>
26128 #include <linux/kallsyms.h>
26129-
26130+#include <linux/sched.h>
26131
26132 #define DEBUG 1
26133
26134diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26135index 6c483ba..d10ce2f 100644
26136--- a/arch/x86/kernel/pci-swiotlb.c
26137+++ b/arch/x86/kernel/pci-swiotlb.c
26138@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26139 void *vaddr, dma_addr_t dma_addr,
26140 struct dma_attrs *attrs)
26141 {
26142- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26143+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26144 }
26145
26146 static struct dma_map_ops swiotlb_dma_ops = {
26147diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26148index ca7f0d5..8996469 100644
26149--- a/arch/x86/kernel/preempt.S
26150+++ b/arch/x86/kernel/preempt.S
26151@@ -3,12 +3,14 @@
26152 #include <asm/dwarf2.h>
26153 #include <asm/asm.h>
26154 #include <asm/calling.h>
26155+#include <asm/alternative-asm.h>
26156
26157 ENTRY(___preempt_schedule)
26158 CFI_STARTPROC
26159 SAVE_ALL
26160 call preempt_schedule
26161 RESTORE_ALL
26162+ pax_force_retaddr
26163 ret
26164 CFI_ENDPROC
26165
26166@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26167 SAVE_ALL
26168 call preempt_schedule_context
26169 RESTORE_ALL
26170+ pax_force_retaddr
26171 ret
26172 CFI_ENDPROC
26173
26174diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26175index 4505e2a..ae28b0d 100644
26176--- a/arch/x86/kernel/process.c
26177+++ b/arch/x86/kernel/process.c
26178@@ -36,7 +36,8 @@
26179 * section. Since TSS's are completely CPU-local, we want them
26180 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26181 */
26182-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26183+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26184+EXPORT_SYMBOL(init_tss);
26185
26186 #ifdef CONFIG_X86_64
26187 static DEFINE_PER_CPU(unsigned char, is_idle);
26188@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26189 task_xstate_cachep =
26190 kmem_cache_create("task_xstate", xstate_size,
26191 __alignof__(union thread_xstate),
26192- SLAB_PANIC | SLAB_NOTRACK, NULL);
26193+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26194 }
26195
26196 /*
26197@@ -105,7 +106,7 @@ void exit_thread(void)
26198 unsigned long *bp = t->io_bitmap_ptr;
26199
26200 if (bp) {
26201- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26202+ struct tss_struct *tss = init_tss + get_cpu();
26203
26204 t->io_bitmap_ptr = NULL;
26205 clear_thread_flag(TIF_IO_BITMAP);
26206@@ -125,6 +126,9 @@ void flush_thread(void)
26207 {
26208 struct task_struct *tsk = current;
26209
26210+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26211+ loadsegment(gs, 0);
26212+#endif
26213 flush_ptrace_hw_breakpoint(tsk);
26214 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26215 drop_init_fpu(tsk);
26216@@ -271,7 +275,7 @@ static void __exit_idle(void)
26217 void exit_idle(void)
26218 {
26219 /* idle loop has pid 0 */
26220- if (current->pid)
26221+ if (task_pid_nr(current))
26222 return;
26223 __exit_idle();
26224 }
26225@@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26226 return ret;
26227 }
26228 #endif
26229-void stop_this_cpu(void *dummy)
26230+__noreturn void stop_this_cpu(void *dummy)
26231 {
26232 local_irq_disable();
26233 /*
26234@@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26235 }
26236 early_param("idle", idle_setup);
26237
26238-unsigned long arch_align_stack(unsigned long sp)
26239+#ifdef CONFIG_PAX_RANDKSTACK
26240+void pax_randomize_kstack(struct pt_regs *regs)
26241 {
26242- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26243- sp -= get_random_int() % 8192;
26244- return sp & ~0xf;
26245-}
26246+ struct thread_struct *thread = &current->thread;
26247+ unsigned long time;
26248
26249-unsigned long arch_randomize_brk(struct mm_struct *mm)
26250-{
26251- unsigned long range_end = mm->brk + 0x02000000;
26252- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26253-}
26254+ if (!randomize_va_space)
26255+ return;
26256+
26257+ if (v8086_mode(regs))
26258+ return;
26259
26260+ rdtscl(time);
26261+
26262+ /* P4 seems to return a 0 LSB, ignore it */
26263+#ifdef CONFIG_MPENTIUM4
26264+ time &= 0x3EUL;
26265+ time <<= 2;
26266+#elif defined(CONFIG_X86_64)
26267+ time &= 0xFUL;
26268+ time <<= 4;
26269+#else
26270+ time &= 0x1FUL;
26271+ time <<= 3;
26272+#endif
26273+
26274+ thread->sp0 ^= time;
26275+ load_sp0(init_tss + smp_processor_id(), thread);
26276+
26277+#ifdef CONFIG_X86_64
26278+ this_cpu_write(kernel_stack, thread->sp0);
26279+#endif
26280+}
26281+#endif
26282diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26283index 7bc86bb..0ea06e8 100644
26284--- a/arch/x86/kernel/process_32.c
26285+++ b/arch/x86/kernel/process_32.c
26286@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26287 unsigned long thread_saved_pc(struct task_struct *tsk)
26288 {
26289 return ((unsigned long *)tsk->thread.sp)[3];
26290+//XXX return tsk->thread.eip;
26291 }
26292
26293 void __show_regs(struct pt_regs *regs, int all)
26294@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26295 unsigned long sp;
26296 unsigned short ss, gs;
26297
26298- if (user_mode_vm(regs)) {
26299+ if (user_mode(regs)) {
26300 sp = regs->sp;
26301 ss = regs->ss & 0xffff;
26302- gs = get_user_gs(regs);
26303 } else {
26304 sp = kernel_stack_pointer(regs);
26305 savesegment(ss, ss);
26306- savesegment(gs, gs);
26307 }
26308+ gs = get_user_gs(regs);
26309
26310 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26311 (u16)regs->cs, regs->ip, regs->flags,
26312- smp_processor_id());
26313+ raw_smp_processor_id());
26314 print_symbol("EIP is at %s\n", regs->ip);
26315
26316 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26317@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26318 int copy_thread(unsigned long clone_flags, unsigned long sp,
26319 unsigned long arg, struct task_struct *p)
26320 {
26321- struct pt_regs *childregs = task_pt_regs(p);
26322+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26323 struct task_struct *tsk;
26324 int err;
26325
26326 p->thread.sp = (unsigned long) childregs;
26327 p->thread.sp0 = (unsigned long) (childregs+1);
26328+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26329
26330 if (unlikely(p->flags & PF_KTHREAD)) {
26331 /* kernel thread */
26332 memset(childregs, 0, sizeof(struct pt_regs));
26333 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26334- task_user_gs(p) = __KERNEL_STACK_CANARY;
26335- childregs->ds = __USER_DS;
26336- childregs->es = __USER_DS;
26337+ savesegment(gs, childregs->gs);
26338+ childregs->ds = __KERNEL_DS;
26339+ childregs->es = __KERNEL_DS;
26340 childregs->fs = __KERNEL_PERCPU;
26341 childregs->bx = sp; /* function */
26342 childregs->bp = arg;
26343@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26344 struct thread_struct *prev = &prev_p->thread,
26345 *next = &next_p->thread;
26346 int cpu = smp_processor_id();
26347- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26348+ struct tss_struct *tss = init_tss + cpu;
26349 fpu_switch_t fpu;
26350
26351 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26352@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26353 */
26354 lazy_save_gs(prev->gs);
26355
26356+#ifdef CONFIG_PAX_MEMORY_UDEREF
26357+ __set_fs(task_thread_info(next_p)->addr_limit);
26358+#endif
26359+
26360 /*
26361 * Load the per-thread Thread-Local Storage descriptor.
26362 */
26363@@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26364 */
26365 arch_end_context_switch(next_p);
26366
26367- this_cpu_write(kernel_stack,
26368- (unsigned long)task_stack_page(next_p) +
26369- THREAD_SIZE - KERNEL_STACK_OFFSET);
26370+ this_cpu_write(current_task, next_p);
26371+ this_cpu_write(current_tinfo, &next_p->tinfo);
26372+ this_cpu_write(kernel_stack, next->sp0);
26373
26374 /*
26375 * Restore %gs if needed (which is common)
26376@@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26377
26378 switch_fpu_finish(next_p, fpu);
26379
26380- this_cpu_write(current_task, next_p);
26381-
26382 return prev_p;
26383 }
26384
26385@@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26386 } while (count++ < 16);
26387 return 0;
26388 }
26389-
26390diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26391index 898d077..4c458ff 100644
26392--- a/arch/x86/kernel/process_64.c
26393+++ b/arch/x86/kernel/process_64.c
26394@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26395 struct pt_regs *childregs;
26396 struct task_struct *me = current;
26397
26398- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26399+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26400 childregs = task_pt_regs(p);
26401 p->thread.sp = (unsigned long) childregs;
26402 p->thread.usersp = me->thread.usersp;
26403+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26404 set_tsk_thread_flag(p, TIF_FORK);
26405 p->thread.fpu_counter = 0;
26406 p->thread.io_bitmap_ptr = NULL;
26407@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26408 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26409 savesegment(es, p->thread.es);
26410 savesegment(ds, p->thread.ds);
26411+ savesegment(ss, p->thread.ss);
26412+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26413 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26414
26415 if (unlikely(p->flags & PF_KTHREAD)) {
26416@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26417 struct thread_struct *prev = &prev_p->thread;
26418 struct thread_struct *next = &next_p->thread;
26419 int cpu = smp_processor_id();
26420- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26421+ struct tss_struct *tss = init_tss + cpu;
26422 unsigned fsindex, gsindex;
26423 fpu_switch_t fpu;
26424
26425@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26426 if (unlikely(next->ds | prev->ds))
26427 loadsegment(ds, next->ds);
26428
26429+ savesegment(ss, prev->ss);
26430+ if (unlikely(next->ss != prev->ss))
26431+ loadsegment(ss, next->ss);
26432
26433 /* We must save %fs and %gs before load_TLS() because
26434 * %fs and %gs may be cleared by load_TLS().
26435@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26436 prev->usersp = this_cpu_read(old_rsp);
26437 this_cpu_write(old_rsp, next->usersp);
26438 this_cpu_write(current_task, next_p);
26439+ this_cpu_write(current_tinfo, &next_p->tinfo);
26440
26441 /*
26442 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26443@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26444 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26445 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26446
26447- this_cpu_write(kernel_stack,
26448- (unsigned long)task_stack_page(next_p) +
26449- THREAD_SIZE - KERNEL_STACK_OFFSET);
26450+ this_cpu_write(kernel_stack, next->sp0);
26451
26452 /*
26453 * Now maybe reload the debug registers and handle I/O bitmaps
26454@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26455 if (!p || p == current || p->state == TASK_RUNNING)
26456 return 0;
26457 stack = (unsigned long)task_stack_page(p);
26458- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26459+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26460 return 0;
26461 fp = *(u64 *)(p->thread.sp);
26462 do {
26463- if (fp < (unsigned long)stack ||
26464- fp >= (unsigned long)stack+THREAD_SIZE)
26465+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26466 return 0;
26467 ip = *(u64 *)(fp+8);
26468 if (!in_sched_functions(ip))
26469diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26470index 678c0ad..2fc2a7b 100644
26471--- a/arch/x86/kernel/ptrace.c
26472+++ b/arch/x86/kernel/ptrace.c
26473@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26474 unsigned long sp = (unsigned long)&regs->sp;
26475 u32 *prev_esp;
26476
26477- if (context == (sp & ~(THREAD_SIZE - 1)))
26478+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26479 return sp;
26480
26481- prev_esp = (u32 *)(context);
26482+ prev_esp = *(u32 **)(context);
26483 if (prev_esp)
26484 return (unsigned long)prev_esp;
26485
26486@@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26487 if (child->thread.gs != value)
26488 return do_arch_prctl(child, ARCH_SET_GS, value);
26489 return 0;
26490+
26491+ case offsetof(struct user_regs_struct,ip):
26492+ /*
26493+ * Protect against any attempt to set ip to an
26494+ * impossible address. There are dragons lurking if the
26495+ * address is noncanonical. (This explicitly allows
26496+ * setting ip to TASK_SIZE_MAX, because user code can do
26497+ * that all by itself by running off the end of its
26498+ * address space.
26499+ */
26500+ if (value > TASK_SIZE_MAX)
26501+ return -EIO;
26502+ break;
26503+
26504 #endif
26505 }
26506
26507@@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26508 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26509 {
26510 int i;
26511- int dr7 = 0;
26512+ unsigned long dr7 = 0;
26513 struct arch_hw_breakpoint *info;
26514
26515 for (i = 0; i < HBP_NUM; i++) {
26516@@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26517 unsigned long addr, unsigned long data)
26518 {
26519 int ret;
26520- unsigned long __user *datap = (unsigned long __user *)data;
26521+ unsigned long __user *datap = (__force unsigned long __user *)data;
26522
26523 switch (request) {
26524 /* read the word at location addr in the USER area. */
26525@@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26526 if ((int) addr < 0)
26527 return -EIO;
26528 ret = do_get_thread_area(child, addr,
26529- (struct user_desc __user *)data);
26530+ (__force struct user_desc __user *) data);
26531 break;
26532
26533 case PTRACE_SET_THREAD_AREA:
26534 if ((int) addr < 0)
26535 return -EIO;
26536 ret = do_set_thread_area(child, addr,
26537- (struct user_desc __user *)data, 0);
26538+ (__force struct user_desc __user *) data, 0);
26539 break;
26540 #endif
26541
26542@@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26543
26544 #ifdef CONFIG_X86_64
26545
26546-static struct user_regset x86_64_regsets[] __read_mostly = {
26547+static user_regset_no_const x86_64_regsets[] __read_only = {
26548 [REGSET_GENERAL] = {
26549 .core_note_type = NT_PRSTATUS,
26550 .n = sizeof(struct user_regs_struct) / sizeof(long),
26551@@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26552 #endif /* CONFIG_X86_64 */
26553
26554 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26555-static struct user_regset x86_32_regsets[] __read_mostly = {
26556+static user_regset_no_const x86_32_regsets[] __read_only = {
26557 [REGSET_GENERAL] = {
26558 .core_note_type = NT_PRSTATUS,
26559 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26560@@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26561 */
26562 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26563
26564-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26565+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26566 {
26567 #ifdef CONFIG_X86_64
26568 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26569@@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26570 memset(info, 0, sizeof(*info));
26571 info->si_signo = SIGTRAP;
26572 info->si_code = si_code;
26573- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26574+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26575 }
26576
26577 void user_single_step_siginfo(struct task_struct *tsk,
26578@@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26579 # define IS_IA32 0
26580 #endif
26581
26582+#ifdef CONFIG_GRKERNSEC_SETXID
26583+extern void gr_delayed_cred_worker(void);
26584+#endif
26585+
26586 /*
26587 * We must return the syscall number to actually look up in the table.
26588 * This can be -1L to skip running any syscall at all.
26589@@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26590
26591 user_exit();
26592
26593+#ifdef CONFIG_GRKERNSEC_SETXID
26594+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26595+ gr_delayed_cred_worker();
26596+#endif
26597+
26598 /*
26599 * If we stepped into a sysenter/syscall insn, it trapped in
26600 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26601@@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26602 */
26603 user_exit();
26604
26605+#ifdef CONFIG_GRKERNSEC_SETXID
26606+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26607+ gr_delayed_cred_worker();
26608+#endif
26609+
26610 audit_syscall_exit(regs);
26611
26612 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26613diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26614index 2f355d2..e75ed0a 100644
26615--- a/arch/x86/kernel/pvclock.c
26616+++ b/arch/x86/kernel/pvclock.c
26617@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26618 reset_hung_task_detector();
26619 }
26620
26621-static atomic64_t last_value = ATOMIC64_INIT(0);
26622+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26623
26624 void pvclock_resume(void)
26625 {
26626- atomic64_set(&last_value, 0);
26627+ atomic64_set_unchecked(&last_value, 0);
26628 }
26629
26630 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26631@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26632 * updating at the same time, and one of them could be slightly behind,
26633 * making the assumption that last_value always go forward fail to hold.
26634 */
26635- last = atomic64_read(&last_value);
26636+ last = atomic64_read_unchecked(&last_value);
26637 do {
26638 if (ret < last)
26639 return last;
26640- last = atomic64_cmpxchg(&last_value, last, ret);
26641+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26642 } while (unlikely(last != ret));
26643
26644 return ret;
26645diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26646index 52b1157..c6e67c4 100644
26647--- a/arch/x86/kernel/reboot.c
26648+++ b/arch/x86/kernel/reboot.c
26649@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26650
26651 void __noreturn machine_real_restart(unsigned int type)
26652 {
26653+
26654+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26655+ struct desc_struct *gdt;
26656+#endif
26657+
26658 local_irq_disable();
26659
26660 /*
26661@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26662
26663 /* Jump to the identity-mapped low memory code */
26664 #ifdef CONFIG_X86_32
26665- asm volatile("jmpl *%0" : :
26666+
26667+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26668+ gdt = get_cpu_gdt_table(smp_processor_id());
26669+ pax_open_kernel();
26670+#ifdef CONFIG_PAX_MEMORY_UDEREF
26671+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26672+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26673+ loadsegment(ds, __KERNEL_DS);
26674+ loadsegment(es, __KERNEL_DS);
26675+ loadsegment(ss, __KERNEL_DS);
26676+#endif
26677+#ifdef CONFIG_PAX_KERNEXEC
26678+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26679+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26680+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26681+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26682+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26683+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26684+#endif
26685+ pax_close_kernel();
26686+#endif
26687+
26688+ asm volatile("ljmpl *%0" : :
26689 "rm" (real_mode_header->machine_real_restart_asm),
26690 "a" (type));
26691 #else
26692@@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26693 * This means that this function can never return, it can misbehave
26694 * by not rebooting properly and hanging.
26695 */
26696-static void native_machine_emergency_restart(void)
26697+static void __noreturn native_machine_emergency_restart(void)
26698 {
26699 int i;
26700 int attempt = 0;
26701@@ -610,13 +637,13 @@ void native_machine_shutdown(void)
26702 #endif
26703 }
26704
26705-static void __machine_emergency_restart(int emergency)
26706+static void __noreturn __machine_emergency_restart(int emergency)
26707 {
26708 reboot_emergency = emergency;
26709 machine_ops.emergency_restart();
26710 }
26711
26712-static void native_machine_restart(char *__unused)
26713+static void __noreturn native_machine_restart(char *__unused)
26714 {
26715 pr_notice("machine restart\n");
26716
26717@@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
26718 __machine_emergency_restart(0);
26719 }
26720
26721-static void native_machine_halt(void)
26722+static void __noreturn native_machine_halt(void)
26723 {
26724 /* Stop other cpus and apics */
26725 machine_shutdown();
26726@@ -635,7 +662,7 @@ static void native_machine_halt(void)
26727 stop_this_cpu(NULL);
26728 }
26729
26730-static void native_machine_power_off(void)
26731+static void __noreturn native_machine_power_off(void)
26732 {
26733 if (pm_power_off) {
26734 if (!reboot_force)
26735@@ -644,9 +671,10 @@ static void native_machine_power_off(void)
26736 }
26737 /* A fallback in case there is no PM info available */
26738 tboot_shutdown(TB_SHUTDOWN_HALT);
26739+ unreachable();
26740 }
26741
26742-struct machine_ops machine_ops = {
26743+struct machine_ops machine_ops __read_only = {
26744 .power_off = native_machine_power_off,
26745 .shutdown = native_machine_shutdown,
26746 .emergency_restart = native_machine_emergency_restart,
26747diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26748index c8e41e9..64049ef 100644
26749--- a/arch/x86/kernel/reboot_fixups_32.c
26750+++ b/arch/x86/kernel/reboot_fixups_32.c
26751@@ -57,7 +57,7 @@ struct device_fixup {
26752 unsigned int vendor;
26753 unsigned int device;
26754 void (*reboot_fixup)(struct pci_dev *);
26755-};
26756+} __do_const;
26757
26758 /*
26759 * PCI ids solely used for fixups_table go here
26760diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26761index 3fd2c69..a444264 100644
26762--- a/arch/x86/kernel/relocate_kernel_64.S
26763+++ b/arch/x86/kernel/relocate_kernel_64.S
26764@@ -96,8 +96,7 @@ relocate_kernel:
26765
26766 /* jump to identity mapped page */
26767 addq $(identity_mapped - relocate_kernel), %r8
26768- pushq %r8
26769- ret
26770+ jmp *%r8
26771
26772 identity_mapped:
26773 /* set return address to 0 if not preserving context */
26774diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26775index 09c76d2..7f33fc2 100644
26776--- a/arch/x86/kernel/setup.c
26777+++ b/arch/x86/kernel/setup.c
26778@@ -110,6 +110,7 @@
26779 #include <asm/mce.h>
26780 #include <asm/alternative.h>
26781 #include <asm/prom.h>
26782+#include <asm/boot.h>
26783
26784 /*
26785 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26786@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26787 #endif
26788
26789
26790-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26791-__visible unsigned long mmu_cr4_features;
26792+#ifdef CONFIG_X86_64
26793+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26794+#elif defined(CONFIG_X86_PAE)
26795+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26796 #else
26797-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26798+__visible unsigned long mmu_cr4_features __read_only;
26799 #endif
26800
26801+void set_in_cr4(unsigned long mask)
26802+{
26803+ unsigned long cr4 = read_cr4();
26804+
26805+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26806+ return;
26807+
26808+ pax_open_kernel();
26809+ mmu_cr4_features |= mask;
26810+ pax_close_kernel();
26811+
26812+ if (trampoline_cr4_features)
26813+ *trampoline_cr4_features = mmu_cr4_features;
26814+ cr4 |= mask;
26815+ write_cr4(cr4);
26816+}
26817+EXPORT_SYMBOL(set_in_cr4);
26818+
26819+void clear_in_cr4(unsigned long mask)
26820+{
26821+ unsigned long cr4 = read_cr4();
26822+
26823+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26824+ return;
26825+
26826+ pax_open_kernel();
26827+ mmu_cr4_features &= ~mask;
26828+ pax_close_kernel();
26829+
26830+ if (trampoline_cr4_features)
26831+ *trampoline_cr4_features = mmu_cr4_features;
26832+ cr4 &= ~mask;
26833+ write_cr4(cr4);
26834+}
26835+EXPORT_SYMBOL(clear_in_cr4);
26836+
26837 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26838 int bootloader_type, bootloader_version;
26839
26840@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26841 * area (640->1Mb) as ram even though it is not.
26842 * take them out.
26843 */
26844- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26845+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26846
26847 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26848 }
26849@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26850 /* called before trim_bios_range() to spare extra sanitize */
26851 static void __init e820_add_kernel_range(void)
26852 {
26853- u64 start = __pa_symbol(_text);
26854+ u64 start = __pa_symbol(ktla_ktva(_text));
26855 u64 size = __pa_symbol(_end) - start;
26856
26857 /*
26858@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26859
26860 void __init setup_arch(char **cmdline_p)
26861 {
26862+#ifdef CONFIG_X86_32
26863+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26864+#else
26865 memblock_reserve(__pa_symbol(_text),
26866 (unsigned long)__bss_stop - (unsigned long)_text);
26867+#endif
26868
26869 early_reserve_initrd();
26870
26871@@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
26872
26873 if (!boot_params.hdr.root_flags)
26874 root_mountflags &= ~MS_RDONLY;
26875- init_mm.start_code = (unsigned long) _text;
26876- init_mm.end_code = (unsigned long) _etext;
26877+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26878+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26879 init_mm.end_data = (unsigned long) _edata;
26880 init_mm.brk = _brk_end;
26881
26882- code_resource.start = __pa_symbol(_text);
26883- code_resource.end = __pa_symbol(_etext)-1;
26884- data_resource.start = __pa_symbol(_etext);
26885+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26886+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26887+ data_resource.start = __pa_symbol(_sdata);
26888 data_resource.end = __pa_symbol(_edata)-1;
26889 bss_resource.start = __pa_symbol(__bss_start);
26890 bss_resource.end = __pa_symbol(__bss_stop)-1;
26891diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26892index 5cdff03..80fa283 100644
26893--- a/arch/x86/kernel/setup_percpu.c
26894+++ b/arch/x86/kernel/setup_percpu.c
26895@@ -21,19 +21,17 @@
26896 #include <asm/cpu.h>
26897 #include <asm/stackprotector.h>
26898
26899-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26900+#ifdef CONFIG_SMP
26901+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26902 EXPORT_PER_CPU_SYMBOL(cpu_number);
26903+#endif
26904
26905-#ifdef CONFIG_X86_64
26906 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26907-#else
26908-#define BOOT_PERCPU_OFFSET 0
26909-#endif
26910
26911 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26912 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26913
26914-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26915+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26916 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26917 };
26918 EXPORT_SYMBOL(__per_cpu_offset);
26919@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26920 {
26921 #ifdef CONFIG_NEED_MULTIPLE_NODES
26922 pg_data_t *last = NULL;
26923- unsigned int cpu;
26924+ int cpu;
26925
26926 for_each_possible_cpu(cpu) {
26927 int node = early_cpu_to_node(cpu);
26928@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26929 {
26930 #ifdef CONFIG_X86_32
26931 struct desc_struct gdt;
26932+ unsigned long base = per_cpu_offset(cpu);
26933
26934- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26935- 0x2 | DESCTYPE_S, 0x8);
26936- gdt.s = 1;
26937+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26938+ 0x83 | DESCTYPE_S, 0xC);
26939 write_gdt_entry(get_cpu_gdt_table(cpu),
26940 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26941 #endif
26942@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26943 /* alrighty, percpu areas up and running */
26944 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26945 for_each_possible_cpu(cpu) {
26946+#ifdef CONFIG_CC_STACKPROTECTOR
26947+#ifdef CONFIG_X86_32
26948+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26949+#endif
26950+#endif
26951 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26952 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26953 per_cpu(cpu_number, cpu) = cpu;
26954@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26955 */
26956 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26957 #endif
26958+#ifdef CONFIG_CC_STACKPROTECTOR
26959+#ifdef CONFIG_X86_32
26960+ if (!cpu)
26961+ per_cpu(stack_canary.canary, cpu) = canary;
26962+#endif
26963+#endif
26964 /*
26965 * Up to this point, the boot CPU has been using .init.data
26966 * area. Reload any changed state for the boot CPU.
26967diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26968index 9e5de68..147c254 100644
26969--- a/arch/x86/kernel/signal.c
26970+++ b/arch/x86/kernel/signal.c
26971@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26972 * Align the stack pointer according to the i386 ABI,
26973 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26974 */
26975- sp = ((sp + 4) & -16ul) - 4;
26976+ sp = ((sp - 12) & -16ul) - 4;
26977 #else /* !CONFIG_X86_32 */
26978 sp = round_down(sp, 16) - 8;
26979 #endif
26980@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26981 }
26982
26983 if (current->mm->context.vdso)
26984- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26985+ restorer = (void __force_user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26986 else
26987- restorer = &frame->retcode;
26988+ restorer = (void __user *)&frame->retcode;
26989 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26990 restorer = ksig->ka.sa.sa_restorer;
26991
26992@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26993 * reasons and because gdb uses it as a signature to notice
26994 * signal handler stack frames.
26995 */
26996- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26997+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26998
26999 if (err)
27000 return -EFAULT;
27001@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27002 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27003
27004 /* Set up to return from userspace. */
27005- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27006+ if (current->mm->context.vdso)
27007+ restorer = (void __force_user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27008+ else
27009+ restorer = (void __user *)&frame->retcode;
27010 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27011 restorer = ksig->ka.sa.sa_restorer;
27012 put_user_ex(restorer, &frame->pretcode);
27013@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27014 * reasons and because gdb uses it as a signature to notice
27015 * signal handler stack frames.
27016 */
27017- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27018+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27019 } put_user_catch(err);
27020
27021 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27022@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27023 {
27024 int usig = signr_convert(ksig->sig);
27025 sigset_t *set = sigmask_to_save();
27026- compat_sigset_t *cset = (compat_sigset_t *) set;
27027+ sigset_t sigcopy;
27028+ compat_sigset_t *cset;
27029+
27030+ sigcopy = *set;
27031+
27032+ cset = (compat_sigset_t *) &sigcopy;
27033
27034 /* Set up the stack frame */
27035 if (is_ia32_frame()) {
27036@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27037 } else if (is_x32_frame()) {
27038 return x32_setup_rt_frame(ksig, cset, regs);
27039 } else {
27040- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27041+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27042 }
27043 }
27044
27045diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27046index be8e1bd..a3d93fa 100644
27047--- a/arch/x86/kernel/smp.c
27048+++ b/arch/x86/kernel/smp.c
27049@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27050
27051 __setup("nonmi_ipi", nonmi_ipi_setup);
27052
27053-struct smp_ops smp_ops = {
27054+struct smp_ops smp_ops __read_only = {
27055 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27056 .smp_prepare_cpus = native_smp_prepare_cpus,
27057 .smp_cpus_done = native_smp_cpus_done,
27058diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27059index 5492798..a3bd4f2 100644
27060--- a/arch/x86/kernel/smpboot.c
27061+++ b/arch/x86/kernel/smpboot.c
27062@@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27063
27064 enable_start_cpu0 = 0;
27065
27066-#ifdef CONFIG_X86_32
27067+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
27068+ barrier();
27069+
27070 /* switch away from the initial page table */
27071+#ifdef CONFIG_PAX_PER_CPU_PGD
27072+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27073+#else
27074 load_cr3(swapper_pg_dir);
27075+#endif
27076 __flush_tlb_all();
27077-#endif
27078
27079- /* otherwise gcc will move up smp_processor_id before the cpu_init */
27080- barrier();
27081 /*
27082 * Check TSC synchronization with the BP:
27083 */
27084@@ -764,8 +767,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27085 alternatives_enable_smp();
27086
27087 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27088- (THREAD_SIZE + task_stack_page(idle))) - 1);
27089+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27090 per_cpu(current_task, cpu) = idle;
27091+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27092
27093 #ifdef CONFIG_X86_32
27094 /* Stack for startup_32 can be just as for start_secondary onwards */
27095@@ -774,10 +778,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27096 clear_tsk_thread_flag(idle, TIF_FORK);
27097 initial_gs = per_cpu_offset(cpu);
27098 #endif
27099- per_cpu(kernel_stack, cpu) =
27100- (unsigned long)task_stack_page(idle) -
27101- KERNEL_STACK_OFFSET + THREAD_SIZE;
27102+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27103+ pax_open_kernel();
27104 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27105+ pax_close_kernel();
27106 initial_code = (unsigned long)start_secondary;
27107 stack_start = idle->thread.sp;
27108
27109@@ -923,6 +927,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27110 /* the FPU context is blank, nobody can own it */
27111 __cpu_disable_lazy_restore(cpu);
27112
27113+#ifdef CONFIG_PAX_PER_CPU_PGD
27114+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27115+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27116+ KERNEL_PGD_PTRS);
27117+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27118+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27119+ KERNEL_PGD_PTRS);
27120+#endif
27121+
27122 err = do_boot_cpu(apicid, cpu, tidle);
27123 if (err) {
27124 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27125diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27126index 9b4d51d..5d28b58 100644
27127--- a/arch/x86/kernel/step.c
27128+++ b/arch/x86/kernel/step.c
27129@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27130 struct desc_struct *desc;
27131 unsigned long base;
27132
27133- seg &= ~7UL;
27134+ seg >>= 3;
27135
27136 mutex_lock(&child->mm->context.lock);
27137- if (unlikely((seg >> 3) >= child->mm->context.size))
27138+ if (unlikely(seg >= child->mm->context.size))
27139 addr = -1L; /* bogus selector, access would fault */
27140 else {
27141 desc = child->mm->context.ldt + seg;
27142@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27143 addr += base;
27144 }
27145 mutex_unlock(&child->mm->context.lock);
27146- }
27147+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27148+ addr = ktla_ktva(addr);
27149
27150 return addr;
27151 }
27152@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27153 unsigned char opcode[15];
27154 unsigned long addr = convert_ip_to_linear(child, regs);
27155
27156+ if (addr == -EINVAL)
27157+ return 0;
27158+
27159 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27160 for (i = 0; i < copied; i++) {
27161 switch (opcode[i]) {
27162diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27163new file mode 100644
27164index 0000000..5877189
27165--- /dev/null
27166+++ b/arch/x86/kernel/sys_i386_32.c
27167@@ -0,0 +1,189 @@
27168+/*
27169+ * This file contains various random system calls that
27170+ * have a non-standard calling sequence on the Linux/i386
27171+ * platform.
27172+ */
27173+
27174+#include <linux/errno.h>
27175+#include <linux/sched.h>
27176+#include <linux/mm.h>
27177+#include <linux/fs.h>
27178+#include <linux/smp.h>
27179+#include <linux/sem.h>
27180+#include <linux/msg.h>
27181+#include <linux/shm.h>
27182+#include <linux/stat.h>
27183+#include <linux/syscalls.h>
27184+#include <linux/mman.h>
27185+#include <linux/file.h>
27186+#include <linux/utsname.h>
27187+#include <linux/ipc.h>
27188+#include <linux/elf.h>
27189+
27190+#include <linux/uaccess.h>
27191+#include <linux/unistd.h>
27192+
27193+#include <asm/syscalls.h>
27194+
27195+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27196+{
27197+ unsigned long pax_task_size = TASK_SIZE;
27198+
27199+#ifdef CONFIG_PAX_SEGMEXEC
27200+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27201+ pax_task_size = SEGMEXEC_TASK_SIZE;
27202+#endif
27203+
27204+ if (flags & MAP_FIXED)
27205+ if (len > pax_task_size || addr > pax_task_size - len)
27206+ return -EINVAL;
27207+
27208+ return 0;
27209+}
27210+
27211+/*
27212+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27213+ */
27214+static unsigned long get_align_mask(void)
27215+{
27216+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27217+ return 0;
27218+
27219+ if (!(current->flags & PF_RANDOMIZE))
27220+ return 0;
27221+
27222+ return va_align.mask;
27223+}
27224+
27225+unsigned long
27226+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27227+ unsigned long len, unsigned long pgoff, unsigned long flags)
27228+{
27229+ struct mm_struct *mm = current->mm;
27230+ struct vm_area_struct *vma;
27231+ unsigned long pax_task_size = TASK_SIZE;
27232+ struct vm_unmapped_area_info info;
27233+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27234+
27235+#ifdef CONFIG_PAX_SEGMEXEC
27236+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27237+ pax_task_size = SEGMEXEC_TASK_SIZE;
27238+#endif
27239+
27240+ pax_task_size -= PAGE_SIZE;
27241+
27242+ if (len > pax_task_size)
27243+ return -ENOMEM;
27244+
27245+ if (flags & MAP_FIXED)
27246+ return addr;
27247+
27248+#ifdef CONFIG_PAX_RANDMMAP
27249+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27250+#endif
27251+
27252+ if (addr) {
27253+ addr = PAGE_ALIGN(addr);
27254+ if (pax_task_size - len >= addr) {
27255+ vma = find_vma(mm, addr);
27256+ if (check_heap_stack_gap(vma, addr, len, offset))
27257+ return addr;
27258+ }
27259+ }
27260+
27261+ info.flags = 0;
27262+ info.length = len;
27263+ info.align_mask = filp ? get_align_mask() : 0;
27264+ info.align_offset = pgoff << PAGE_SHIFT;
27265+ info.threadstack_offset = offset;
27266+
27267+#ifdef CONFIG_PAX_PAGEEXEC
27268+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27269+ info.low_limit = 0x00110000UL;
27270+ info.high_limit = mm->start_code;
27271+
27272+#ifdef CONFIG_PAX_RANDMMAP
27273+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27274+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27275+#endif
27276+
27277+ if (info.low_limit < info.high_limit) {
27278+ addr = vm_unmapped_area(&info);
27279+ if (!IS_ERR_VALUE(addr))
27280+ return addr;
27281+ }
27282+ } else
27283+#endif
27284+
27285+ info.low_limit = mm->mmap_base;
27286+ info.high_limit = pax_task_size;
27287+
27288+ return vm_unmapped_area(&info);
27289+}
27290+
27291+unsigned long
27292+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27293+ const unsigned long len, const unsigned long pgoff,
27294+ const unsigned long flags)
27295+{
27296+ struct vm_area_struct *vma;
27297+ struct mm_struct *mm = current->mm;
27298+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27299+ struct vm_unmapped_area_info info;
27300+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27301+
27302+#ifdef CONFIG_PAX_SEGMEXEC
27303+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27304+ pax_task_size = SEGMEXEC_TASK_SIZE;
27305+#endif
27306+
27307+ pax_task_size -= PAGE_SIZE;
27308+
27309+ /* requested length too big for entire address space */
27310+ if (len > pax_task_size)
27311+ return -ENOMEM;
27312+
27313+ if (flags & MAP_FIXED)
27314+ return addr;
27315+
27316+#ifdef CONFIG_PAX_PAGEEXEC
27317+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27318+ goto bottomup;
27319+#endif
27320+
27321+#ifdef CONFIG_PAX_RANDMMAP
27322+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27323+#endif
27324+
27325+ /* requesting a specific address */
27326+ if (addr) {
27327+ addr = PAGE_ALIGN(addr);
27328+ if (pax_task_size - len >= addr) {
27329+ vma = find_vma(mm, addr);
27330+ if (check_heap_stack_gap(vma, addr, len, offset))
27331+ return addr;
27332+ }
27333+ }
27334+
27335+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27336+ info.length = len;
27337+ info.low_limit = PAGE_SIZE;
27338+ info.high_limit = mm->mmap_base;
27339+ info.align_mask = filp ? get_align_mask() : 0;
27340+ info.align_offset = pgoff << PAGE_SHIFT;
27341+ info.threadstack_offset = offset;
27342+
27343+ addr = vm_unmapped_area(&info);
27344+ if (!(addr & ~PAGE_MASK))
27345+ return addr;
27346+ VM_BUG_ON(addr != -ENOMEM);
27347+
27348+bottomup:
27349+ /*
27350+ * A failed mmap() very likely causes application failure,
27351+ * so fall back to the bottom-up function here. This scenario
27352+ * can happen with large stack limits and large mmap()
27353+ * allocations.
27354+ */
27355+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27356+}
27357diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27358index 30277e2..5664a29 100644
27359--- a/arch/x86/kernel/sys_x86_64.c
27360+++ b/arch/x86/kernel/sys_x86_64.c
27361@@ -81,8 +81,8 @@ out:
27362 return error;
27363 }
27364
27365-static void find_start_end(unsigned long flags, unsigned long *begin,
27366- unsigned long *end)
27367+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27368+ unsigned long *begin, unsigned long *end)
27369 {
27370 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27371 unsigned long new_begin;
27372@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27373 *begin = new_begin;
27374 }
27375 } else {
27376- *begin = current->mm->mmap_legacy_base;
27377+ *begin = mm->mmap_legacy_base;
27378 *end = TASK_SIZE;
27379 }
27380 }
27381@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27382 struct vm_area_struct *vma;
27383 struct vm_unmapped_area_info info;
27384 unsigned long begin, end;
27385+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27386
27387 if (flags & MAP_FIXED)
27388 return addr;
27389
27390- find_start_end(flags, &begin, &end);
27391+ find_start_end(mm, flags, &begin, &end);
27392
27393 if (len > end)
27394 return -ENOMEM;
27395
27396+#ifdef CONFIG_PAX_RANDMMAP
27397+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27398+#endif
27399+
27400 if (addr) {
27401 addr = PAGE_ALIGN(addr);
27402 vma = find_vma(mm, addr);
27403- if (end - len >= addr &&
27404- (!vma || addr + len <= vma->vm_start))
27405+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27406 return addr;
27407 }
27408
27409@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27410 info.high_limit = end;
27411 info.align_mask = filp ? get_align_mask() : 0;
27412 info.align_offset = pgoff << PAGE_SHIFT;
27413+ info.threadstack_offset = offset;
27414 return vm_unmapped_area(&info);
27415 }
27416
27417@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27418 struct mm_struct *mm = current->mm;
27419 unsigned long addr = addr0;
27420 struct vm_unmapped_area_info info;
27421+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27422
27423 /* requested length too big for entire address space */
27424 if (len > TASK_SIZE)
27425@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27426 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27427 goto bottomup;
27428
27429+#ifdef CONFIG_PAX_RANDMMAP
27430+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27431+#endif
27432+
27433 /* requesting a specific address */
27434 if (addr) {
27435 addr = PAGE_ALIGN(addr);
27436 vma = find_vma(mm, addr);
27437- if (TASK_SIZE - len >= addr &&
27438- (!vma || addr + len <= vma->vm_start))
27439+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27440 return addr;
27441 }
27442
27443@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27444 info.high_limit = mm->mmap_base;
27445 info.align_mask = filp ? get_align_mask() : 0;
27446 info.align_offset = pgoff << PAGE_SHIFT;
27447+ info.threadstack_offset = offset;
27448 addr = vm_unmapped_area(&info);
27449 if (!(addr & ~PAGE_MASK))
27450 return addr;
27451diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27452index 91a4496..bb87552 100644
27453--- a/arch/x86/kernel/tboot.c
27454+++ b/arch/x86/kernel/tboot.c
27455@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27456
27457 void tboot_shutdown(u32 shutdown_type)
27458 {
27459- void (*shutdown)(void);
27460+ void (* __noreturn shutdown)(void);
27461
27462 if (!tboot_enabled())
27463 return;
27464@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27465
27466 switch_to_tboot_pt();
27467
27468- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27469+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27470 shutdown();
27471
27472 /* should not reach here */
27473@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27474 return -ENODEV;
27475 }
27476
27477-static atomic_t ap_wfs_count;
27478+static atomic_unchecked_t ap_wfs_count;
27479
27480 static int tboot_wait_for_aps(int num_aps)
27481 {
27482@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27483 {
27484 switch (action) {
27485 case CPU_DYING:
27486- atomic_inc(&ap_wfs_count);
27487+ atomic_inc_unchecked(&ap_wfs_count);
27488 if (num_online_cpus() == 1)
27489- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27490+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27491 return NOTIFY_BAD;
27492 break;
27493 }
27494@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27495
27496 tboot_create_trampoline();
27497
27498- atomic_set(&ap_wfs_count, 0);
27499+ atomic_set_unchecked(&ap_wfs_count, 0);
27500 register_hotcpu_notifier(&tboot_cpu_notifier);
27501
27502 #ifdef CONFIG_DEBUG_FS
27503diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27504index bf7ef5c..59d0ac9 100644
27505--- a/arch/x86/kernel/time.c
27506+++ b/arch/x86/kernel/time.c
27507@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27508 {
27509 unsigned long pc = instruction_pointer(regs);
27510
27511- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27512+ if (!user_mode(regs) && in_lock_functions(pc)) {
27513 #ifdef CONFIG_FRAME_POINTER
27514- return *(unsigned long *)(regs->bp + sizeof(long));
27515+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27516 #else
27517 unsigned long *sp =
27518 (unsigned long *)kernel_stack_pointer(regs);
27519@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27520 * or above a saved flags. Eflags has bits 22-31 zero,
27521 * kernel addresses don't.
27522 */
27523+
27524+#ifdef CONFIG_PAX_KERNEXEC
27525+ return ktla_ktva(sp[0]);
27526+#else
27527 if (sp[0] >> 22)
27528 return sp[0];
27529 if (sp[1] >> 22)
27530 return sp[1];
27531 #endif
27532+
27533+#endif
27534 }
27535 return pc;
27536 }
27537diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27538index f7fec09..9991981 100644
27539--- a/arch/x86/kernel/tls.c
27540+++ b/arch/x86/kernel/tls.c
27541@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27542 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27543 return -EINVAL;
27544
27545+#ifdef CONFIG_PAX_SEGMEXEC
27546+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27547+ return -EINVAL;
27548+#endif
27549+
27550 set_tls_desc(p, idx, &info, 1);
27551
27552 return 0;
27553@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27554
27555 if (kbuf)
27556 info = kbuf;
27557- else if (__copy_from_user(infobuf, ubuf, count))
27558+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27559 return -EFAULT;
27560 else
27561 info = infobuf;
27562diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27563index 1c113db..287b42e 100644
27564--- a/arch/x86/kernel/tracepoint.c
27565+++ b/arch/x86/kernel/tracepoint.c
27566@@ -9,11 +9,11 @@
27567 #include <linux/atomic.h>
27568
27569 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27570-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27571+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27572 (unsigned long) trace_idt_table };
27573
27574 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27575-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27576+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27577
27578 static int trace_irq_vector_refcount;
27579 static DEFINE_MUTEX(irq_vector_mutex);
27580diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27581index f73b5d4..0adcc9a 100644
27582--- a/arch/x86/kernel/traps.c
27583+++ b/arch/x86/kernel/traps.c
27584@@ -66,7 +66,7 @@
27585 #include <asm/proto.h>
27586
27587 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27588-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27589+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27590 #else
27591 #include <asm/processor-flags.h>
27592 #include <asm/setup.h>
27593@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27594 #endif
27595
27596 /* Must be page-aligned because the real IDT is used in a fixmap. */
27597-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27598+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27599
27600 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27601 EXPORT_SYMBOL_GPL(used_vectors);
27602@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27603 }
27604
27605 static int __kprobes
27606-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27607+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27608 struct pt_regs *regs, long error_code)
27609 {
27610 #ifdef CONFIG_X86_32
27611- if (regs->flags & X86_VM_MASK) {
27612+ if (v8086_mode(regs)) {
27613 /*
27614 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27615 * On nmi (interrupt 2), do_trap should not be called.
27616@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27617 return -1;
27618 }
27619 #endif
27620- if (!user_mode(regs)) {
27621+ if (!user_mode_novm(regs)) {
27622 if (!fixup_exception(regs)) {
27623 tsk->thread.error_code = error_code;
27624 tsk->thread.trap_nr = trapnr;
27625+
27626+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27627+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27628+ str = "PAX: suspicious stack segment fault";
27629+#endif
27630+
27631 die(str, regs, error_code);
27632 }
27633+
27634+#ifdef CONFIG_PAX_REFCOUNT
27635+ if (trapnr == X86_TRAP_OF)
27636+ pax_report_refcount_overflow(regs);
27637+#endif
27638+
27639 return 0;
27640 }
27641
27642@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27643 }
27644
27645 static void __kprobes
27646-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27647+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27648 long error_code, siginfo_t *info)
27649 {
27650 struct task_struct *tsk = current;
27651@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27652 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27653 printk_ratelimit()) {
27654 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27655- tsk->comm, tsk->pid, str,
27656+ tsk->comm, task_pid_nr(tsk), str,
27657 regs->ip, regs->sp, error_code);
27658 print_vma_addr(" in ", regs->ip);
27659 pr_cont("\n");
27660@@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27661 tsk->thread.error_code = error_code;
27662 tsk->thread.trap_nr = X86_TRAP_DF;
27663
27664+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27665+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27666+ die("grsec: kernel stack overflow detected", regs, error_code);
27667+#endif
27668+
27669 #ifdef CONFIG_DOUBLEFAULT
27670 df_debug(regs, error_code);
27671 #endif
27672@@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27673 conditional_sti(regs);
27674
27675 #ifdef CONFIG_X86_32
27676- if (regs->flags & X86_VM_MASK) {
27677+ if (v8086_mode(regs)) {
27678 local_irq_enable();
27679 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27680 goto exit;
27681@@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27682 #endif
27683
27684 tsk = current;
27685- if (!user_mode(regs)) {
27686+ if (!user_mode_novm(regs)) {
27687 if (fixup_exception(regs))
27688 goto exit;
27689
27690 tsk->thread.error_code = error_code;
27691 tsk->thread.trap_nr = X86_TRAP_GP;
27692 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27693- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27694+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27695+
27696+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27697+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27698+ die("PAX: suspicious general protection fault", regs, error_code);
27699+ else
27700+#endif
27701+
27702 die("general protection fault", regs, error_code);
27703+ }
27704 goto exit;
27705 }
27706
27707+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27708+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27709+ struct mm_struct *mm = tsk->mm;
27710+ unsigned long limit;
27711+
27712+ down_write(&mm->mmap_sem);
27713+ limit = mm->context.user_cs_limit;
27714+ if (limit < TASK_SIZE) {
27715+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27716+ up_write(&mm->mmap_sem);
27717+ return;
27718+ }
27719+ up_write(&mm->mmap_sem);
27720+ }
27721+#endif
27722+
27723 tsk->thread.error_code = error_code;
27724 tsk->thread.trap_nr = X86_TRAP_GP;
27725
27726@@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27727 /* It's safe to allow irq's after DR6 has been saved */
27728 preempt_conditional_sti(regs);
27729
27730- if (regs->flags & X86_VM_MASK) {
27731+ if (v8086_mode(regs)) {
27732 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27733 X86_TRAP_DB);
27734 preempt_conditional_cli(regs);
27735@@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27736 * We already checked v86 mode above, so we can check for kernel mode
27737 * by just checking the CPL of CS.
27738 */
27739- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27740+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27741 tsk->thread.debugreg6 &= ~DR_STEP;
27742 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27743 regs->flags &= ~X86_EFLAGS_TF;
27744@@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27745 return;
27746 conditional_sti(regs);
27747
27748- if (!user_mode_vm(regs))
27749+ if (!user_mode(regs))
27750 {
27751 if (!fixup_exception(regs)) {
27752 task->thread.error_code = error_code;
27753diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27754index ea03031..34a5cdda 100644
27755--- a/arch/x86/kernel/tsc.c
27756+++ b/arch/x86/kernel/tsc.c
27757@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27758 */
27759 smp_wmb();
27760
27761- ACCESS_ONCE(c2n->head) = data;
27762+ ACCESS_ONCE_RW(c2n->head) = data;
27763 }
27764
27765 /*
27766diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27767index 2ed8459..7cf329f 100644
27768--- a/arch/x86/kernel/uprobes.c
27769+++ b/arch/x86/kernel/uprobes.c
27770@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27771 int ret = NOTIFY_DONE;
27772
27773 /* We are only interested in userspace traps */
27774- if (regs && !user_mode_vm(regs))
27775+ if (regs && !user_mode(regs))
27776 return NOTIFY_DONE;
27777
27778 switch (val) {
27779@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27780
27781 if (ncopied != rasize) {
27782 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27783- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27784+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27785
27786 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27787 }
27788diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27789index b9242ba..50c5edd 100644
27790--- a/arch/x86/kernel/verify_cpu.S
27791+++ b/arch/x86/kernel/verify_cpu.S
27792@@ -20,6 +20,7 @@
27793 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27794 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27795 * arch/x86/kernel/head_32.S: processor startup
27796+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27797 *
27798 * verify_cpu, returns the status of longmode and SSE in register %eax.
27799 * 0: Success 1: Failure
27800diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27801index e8edcf5..27f9344 100644
27802--- a/arch/x86/kernel/vm86_32.c
27803+++ b/arch/x86/kernel/vm86_32.c
27804@@ -44,6 +44,7 @@
27805 #include <linux/ptrace.h>
27806 #include <linux/audit.h>
27807 #include <linux/stddef.h>
27808+#include <linux/grsecurity.h>
27809
27810 #include <asm/uaccess.h>
27811 #include <asm/io.h>
27812@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27813 do_exit(SIGSEGV);
27814 }
27815
27816- tss = &per_cpu(init_tss, get_cpu());
27817+ tss = init_tss + get_cpu();
27818 current->thread.sp0 = current->thread.saved_sp0;
27819 current->thread.sysenter_cs = __KERNEL_CS;
27820 load_sp0(tss, &current->thread);
27821@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27822
27823 if (tsk->thread.saved_sp0)
27824 return -EPERM;
27825+
27826+#ifdef CONFIG_GRKERNSEC_VM86
27827+ if (!capable(CAP_SYS_RAWIO)) {
27828+ gr_handle_vm86();
27829+ return -EPERM;
27830+ }
27831+#endif
27832+
27833 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27834 offsetof(struct kernel_vm86_struct, vm86plus) -
27835 sizeof(info.regs));
27836@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27837 int tmp;
27838 struct vm86plus_struct __user *v86;
27839
27840+#ifdef CONFIG_GRKERNSEC_VM86
27841+ if (!capable(CAP_SYS_RAWIO)) {
27842+ gr_handle_vm86();
27843+ return -EPERM;
27844+ }
27845+#endif
27846+
27847 tsk = current;
27848 switch (cmd) {
27849 case VM86_REQUEST_IRQ:
27850@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27851 tsk->thread.saved_fs = info->regs32->fs;
27852 tsk->thread.saved_gs = get_user_gs(info->regs32);
27853
27854- tss = &per_cpu(init_tss, get_cpu());
27855+ tss = init_tss + get_cpu();
27856 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27857 if (cpu_has_sep)
27858 tsk->thread.sysenter_cs = 0;
27859@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27860 goto cannot_handle;
27861 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27862 goto cannot_handle;
27863- intr_ptr = (unsigned long __user *) (i << 2);
27864+ intr_ptr = (__force unsigned long __user *) (i << 2);
27865 if (get_user(segoffs, intr_ptr))
27866 goto cannot_handle;
27867 if ((segoffs >> 16) == BIOSSEG)
27868diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27869index 49edf2d..c0d1362 100644
27870--- a/arch/x86/kernel/vmlinux.lds.S
27871+++ b/arch/x86/kernel/vmlinux.lds.S
27872@@ -26,6 +26,13 @@
27873 #include <asm/page_types.h>
27874 #include <asm/cache.h>
27875 #include <asm/boot.h>
27876+#include <asm/segment.h>
27877+
27878+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27879+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27880+#else
27881+#define __KERNEL_TEXT_OFFSET 0
27882+#endif
27883
27884 #undef i386 /* in case the preprocessor is a 32bit one */
27885
27886@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27887
27888 PHDRS {
27889 text PT_LOAD FLAGS(5); /* R_E */
27890+#ifdef CONFIG_X86_32
27891+ module PT_LOAD FLAGS(5); /* R_E */
27892+#endif
27893+#ifdef CONFIG_XEN
27894+ rodata PT_LOAD FLAGS(5); /* R_E */
27895+#else
27896+ rodata PT_LOAD FLAGS(4); /* R__ */
27897+#endif
27898 data PT_LOAD FLAGS(6); /* RW_ */
27899-#ifdef CONFIG_X86_64
27900+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27901 #ifdef CONFIG_SMP
27902 percpu PT_LOAD FLAGS(6); /* RW_ */
27903 #endif
27904+ text.init PT_LOAD FLAGS(5); /* R_E */
27905+ text.exit PT_LOAD FLAGS(5); /* R_E */
27906 init PT_LOAD FLAGS(7); /* RWE */
27907-#endif
27908 note PT_NOTE FLAGS(0); /* ___ */
27909 }
27910
27911 SECTIONS
27912 {
27913 #ifdef CONFIG_X86_32
27914- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27915- phys_startup_32 = startup_32 - LOAD_OFFSET;
27916+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27917 #else
27918- . = __START_KERNEL;
27919- phys_startup_64 = startup_64 - LOAD_OFFSET;
27920+ . = __START_KERNEL;
27921 #endif
27922
27923 /* Text and read-only data */
27924- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27925- _text = .;
27926+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27927 /* bootstrapping code */
27928+#ifdef CONFIG_X86_32
27929+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27930+#else
27931+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27932+#endif
27933+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27934+ _text = .;
27935 HEAD_TEXT
27936 . = ALIGN(8);
27937 _stext = .;
27938@@ -104,13 +124,47 @@ SECTIONS
27939 IRQENTRY_TEXT
27940 *(.fixup)
27941 *(.gnu.warning)
27942- /* End of text section */
27943- _etext = .;
27944 } :text = 0x9090
27945
27946- NOTES :text :note
27947+ . += __KERNEL_TEXT_OFFSET;
27948
27949- EXCEPTION_TABLE(16) :text = 0x9090
27950+#ifdef CONFIG_X86_32
27951+ . = ALIGN(PAGE_SIZE);
27952+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27953+
27954+#ifdef CONFIG_PAX_KERNEXEC
27955+ MODULES_EXEC_VADDR = .;
27956+ BYTE(0)
27957+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27958+ . = ALIGN(HPAGE_SIZE) - 1;
27959+ MODULES_EXEC_END = .;
27960+#endif
27961+
27962+ } :module
27963+#endif
27964+
27965+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27966+ /* End of text section */
27967+ BYTE(0)
27968+ _etext = . - __KERNEL_TEXT_OFFSET;
27969+ }
27970+
27971+#ifdef CONFIG_X86_32
27972+ . = ALIGN(PAGE_SIZE);
27973+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27974+ . = ALIGN(PAGE_SIZE);
27975+ *(.empty_zero_page)
27976+ *(.initial_pg_fixmap)
27977+ *(.initial_pg_pmd)
27978+ *(.initial_page_table)
27979+ *(.swapper_pg_dir)
27980+ } :rodata
27981+#endif
27982+
27983+ . = ALIGN(PAGE_SIZE);
27984+ NOTES :rodata :note
27985+
27986+ EXCEPTION_TABLE(16) :rodata
27987
27988 #if defined(CONFIG_DEBUG_RODATA)
27989 /* .text should occupy whole number of pages */
27990@@ -122,16 +176,20 @@ SECTIONS
27991
27992 /* Data */
27993 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27994+
27995+#ifdef CONFIG_PAX_KERNEXEC
27996+ . = ALIGN(HPAGE_SIZE);
27997+#else
27998+ . = ALIGN(PAGE_SIZE);
27999+#endif
28000+
28001 /* Start of data section */
28002 _sdata = .;
28003
28004 /* init_task */
28005 INIT_TASK_DATA(THREAD_SIZE)
28006
28007-#ifdef CONFIG_X86_32
28008- /* 32 bit has nosave before _edata */
28009 NOSAVE_DATA
28010-#endif
28011
28012 PAGE_ALIGNED_DATA(PAGE_SIZE)
28013
28014@@ -174,12 +232,19 @@ SECTIONS
28015 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28016
28017 /* Init code and data - will be freed after init */
28018- . = ALIGN(PAGE_SIZE);
28019 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28020+ BYTE(0)
28021+
28022+#ifdef CONFIG_PAX_KERNEXEC
28023+ . = ALIGN(HPAGE_SIZE);
28024+#else
28025+ . = ALIGN(PAGE_SIZE);
28026+#endif
28027+
28028 __init_begin = .; /* paired with __init_end */
28029- }
28030+ } :init.begin
28031
28032-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28033+#ifdef CONFIG_SMP
28034 /*
28035 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28036 * output PHDR, so the next output section - .init.text - should
28037@@ -188,12 +253,27 @@ SECTIONS
28038 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28039 #endif
28040
28041- INIT_TEXT_SECTION(PAGE_SIZE)
28042-#ifdef CONFIG_X86_64
28043- :init
28044-#endif
28045+ . = ALIGN(PAGE_SIZE);
28046+ init_begin = .;
28047+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28048+ VMLINUX_SYMBOL(_sinittext) = .;
28049+ INIT_TEXT
28050+ VMLINUX_SYMBOL(_einittext) = .;
28051+ . = ALIGN(PAGE_SIZE);
28052+ } :text.init
28053
28054- INIT_DATA_SECTION(16)
28055+ /*
28056+ * .exit.text is discard at runtime, not link time, to deal with
28057+ * references from .altinstructions and .eh_frame
28058+ */
28059+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28060+ EXIT_TEXT
28061+ . = ALIGN(16);
28062+ } :text.exit
28063+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28064+
28065+ . = ALIGN(PAGE_SIZE);
28066+ INIT_DATA_SECTION(16) :init
28067
28068 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28069 __x86_cpu_dev_start = .;
28070@@ -264,19 +344,12 @@ SECTIONS
28071 }
28072
28073 . = ALIGN(8);
28074- /*
28075- * .exit.text is discard at runtime, not link time, to deal with
28076- * references from .altinstructions and .eh_frame
28077- */
28078- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28079- EXIT_TEXT
28080- }
28081
28082 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28083 EXIT_DATA
28084 }
28085
28086-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28087+#ifndef CONFIG_SMP
28088 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28089 #endif
28090
28091@@ -295,16 +368,10 @@ SECTIONS
28092 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28093 __smp_locks = .;
28094 *(.smp_locks)
28095- . = ALIGN(PAGE_SIZE);
28096 __smp_locks_end = .;
28097+ . = ALIGN(PAGE_SIZE);
28098 }
28099
28100-#ifdef CONFIG_X86_64
28101- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28102- NOSAVE_DATA
28103- }
28104-#endif
28105-
28106 /* BSS */
28107 . = ALIGN(PAGE_SIZE);
28108 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28109@@ -320,6 +387,7 @@ SECTIONS
28110 __brk_base = .;
28111 . += 64 * 1024; /* 64k alignment slop space */
28112 *(.brk_reservation) /* areas brk users have reserved */
28113+ . = ALIGN(HPAGE_SIZE);
28114 __brk_limit = .;
28115 }
28116
28117@@ -346,13 +414,12 @@ SECTIONS
28118 * for the boot processor.
28119 */
28120 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28121-INIT_PER_CPU(gdt_page);
28122 INIT_PER_CPU(irq_stack_union);
28123
28124 /*
28125 * Build-time check on the image size:
28126 */
28127-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28128+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28129 "kernel image bigger than KERNEL_IMAGE_SIZE");
28130
28131 #ifdef CONFIG_SMP
28132diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28133index 8b3b3eb..9395aa9 100644
28134--- a/arch/x86/kernel/vsyscall_64.c
28135+++ b/arch/x86/kernel/vsyscall_64.c
28136@@ -54,15 +54,13 @@
28137
28138 DEFINE_VVAR(int, vgetcpu_mode);
28139
28140-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28141+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28142
28143 static int __init vsyscall_setup(char *str)
28144 {
28145 if (str) {
28146 if (!strcmp("emulate", str))
28147 vsyscall_mode = EMULATE;
28148- else if (!strcmp("native", str))
28149- vsyscall_mode = NATIVE;
28150 else if (!strcmp("none", str))
28151 vsyscall_mode = NONE;
28152 else
28153@@ -279,8 +277,7 @@ do_ret:
28154 return true;
28155
28156 sigsegv:
28157- force_sig(SIGSEGV, current);
28158- return true;
28159+ do_group_exit(SIGKILL);
28160 }
28161
28162 /*
28163@@ -332,10 +329,7 @@ void __init map_vsyscall(void)
28164 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28165 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28166
28167- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28168- vsyscall_mode == NATIVE
28169- ? PAGE_KERNEL_VSYSCALL
28170- : PAGE_KERNEL_VVAR);
28171+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28172 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28173 (unsigned long)VSYSCALL_START);
28174
28175diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28176index 04068192..4d75aa6 100644
28177--- a/arch/x86/kernel/x8664_ksyms_64.c
28178+++ b/arch/x86/kernel/x8664_ksyms_64.c
28179@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28180 EXPORT_SYMBOL(copy_user_generic_unrolled);
28181 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28182 EXPORT_SYMBOL(__copy_user_nocache);
28183-EXPORT_SYMBOL(_copy_from_user);
28184-EXPORT_SYMBOL(_copy_to_user);
28185
28186 EXPORT_SYMBOL(copy_page);
28187 EXPORT_SYMBOL(clear_page);
28188@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28189 EXPORT_SYMBOL(___preempt_schedule_context);
28190 #endif
28191 #endif
28192+
28193+#ifdef CONFIG_PAX_PER_CPU_PGD
28194+EXPORT_SYMBOL(cpu_pgd);
28195+#endif
28196diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28197index e48b674..a451dd9 100644
28198--- a/arch/x86/kernel/x86_init.c
28199+++ b/arch/x86/kernel/x86_init.c
28200@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28201 static void default_nmi_init(void) { };
28202 static int default_i8042_detect(void) { return 1; };
28203
28204-struct x86_platform_ops x86_platform = {
28205+struct x86_platform_ops x86_platform __read_only = {
28206 .calibrate_tsc = native_calibrate_tsc,
28207 .get_wallclock = mach_get_cmos_time,
28208 .set_wallclock = mach_set_rtc_mmss,
28209@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28210 EXPORT_SYMBOL_GPL(x86_platform);
28211
28212 #if defined(CONFIG_PCI_MSI)
28213-struct x86_msi_ops x86_msi = {
28214+struct x86_msi_ops x86_msi __read_only = {
28215 .setup_msi_irqs = native_setup_msi_irqs,
28216 .compose_msi_msg = native_compose_msi_msg,
28217 .teardown_msi_irq = native_teardown_msi_irq,
28218@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28219 }
28220 #endif
28221
28222-struct x86_io_apic_ops x86_io_apic_ops = {
28223+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28224 .init = native_io_apic_init_mappings,
28225 .read = native_io_apic_read,
28226 .write = native_io_apic_write,
28227diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28228index a4b451c..8dfe1ad 100644
28229--- a/arch/x86/kernel/xsave.c
28230+++ b/arch/x86/kernel/xsave.c
28231@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28232
28233 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28234 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28235- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28236+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28237
28238 if (!use_xsave())
28239 return err;
28240
28241- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28242+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28243
28244 /*
28245 * Read the xstate_bv which we copied (directly from the cpu or
28246 * from the state in task struct) to the user buffers.
28247 */
28248- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28249+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28250
28251 /*
28252 * For legacy compatible, we always set FP/SSE bits in the bit
28253@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28254 */
28255 xstate_bv |= XSTATE_FPSSE;
28256
28257- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28258+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28259
28260 return err;
28261 }
28262@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28263 {
28264 int err;
28265
28266+ buf = (struct xsave_struct __user *)____m(buf);
28267 if (use_xsave())
28268 err = xsave_user(buf);
28269 else if (use_fxsr())
28270@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28271 */
28272 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28273 {
28274+ buf = (void __user *)____m(buf);
28275 if (use_xsave()) {
28276 if ((unsigned long)buf % 64 || fx_only) {
28277 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28278diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28279index f47a104..5ce59a8 100644
28280--- a/arch/x86/kvm/cpuid.c
28281+++ b/arch/x86/kvm/cpuid.c
28282@@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28283 struct kvm_cpuid2 *cpuid,
28284 struct kvm_cpuid_entry2 __user *entries)
28285 {
28286- int r;
28287+ int r, i;
28288
28289 r = -E2BIG;
28290 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28291 goto out;
28292 r = -EFAULT;
28293- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28294- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28295+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28296 goto out;
28297+ for (i = 0; i < cpuid->nent; ++i) {
28298+ struct kvm_cpuid_entry2 cpuid_entry;
28299+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28300+ goto out;
28301+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28302+ }
28303 vcpu->arch.cpuid_nent = cpuid->nent;
28304 kvm_apic_set_version(vcpu);
28305 kvm_x86_ops->cpuid_update(vcpu);
28306@@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28307 struct kvm_cpuid2 *cpuid,
28308 struct kvm_cpuid_entry2 __user *entries)
28309 {
28310- int r;
28311+ int r, i;
28312
28313 r = -E2BIG;
28314 if (cpuid->nent < vcpu->arch.cpuid_nent)
28315 goto out;
28316 r = -EFAULT;
28317- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28318- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28319+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28320 goto out;
28321+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28322+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28323+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28324+ goto out;
28325+ }
28326 return 0;
28327
28328 out:
28329diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28330index 0069118..c28ec0a 100644
28331--- a/arch/x86/kvm/lapic.c
28332+++ b/arch/x86/kvm/lapic.c
28333@@ -55,7 +55,7 @@
28334 #define APIC_BUS_CYCLE_NS 1
28335
28336 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28337-#define apic_debug(fmt, arg...)
28338+#define apic_debug(fmt, arg...) do {} while (0)
28339
28340 #define APIC_LVT_NUM 6
28341 /* 14 is the version for Xeon and Pentium 8.4.8*/
28342diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28343index 123efd3..ad7726e 100644
28344--- a/arch/x86/kvm/paging_tmpl.h
28345+++ b/arch/x86/kvm/paging_tmpl.h
28346@@ -331,7 +331,7 @@ retry_walk:
28347 if (unlikely(kvm_is_error_hva(host_addr)))
28348 goto error;
28349
28350- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28351+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28352 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28353 goto error;
28354 walker->ptep_user[walker->level - 1] = ptep_user;
28355diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28356index 7f4f9c2..67b1db0 100644
28357--- a/arch/x86/kvm/svm.c
28358+++ b/arch/x86/kvm/svm.c
28359@@ -3535,7 +3535,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28360 int cpu = raw_smp_processor_id();
28361
28362 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28363+
28364+ pax_open_kernel();
28365 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28366+ pax_close_kernel();
28367+
28368 load_TR_desc();
28369 }
28370
28371@@ -3936,6 +3940,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28372 #endif
28373 #endif
28374
28375+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28376+ __set_fs(current_thread_info()->addr_limit);
28377+#endif
28378+
28379 reload_tss(vcpu);
28380
28381 local_irq_disable();
28382diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28383index 138ceff..2e584f0 100644
28384--- a/arch/x86/kvm/vmx.c
28385+++ b/arch/x86/kvm/vmx.c
28386@@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28387 #endif
28388 }
28389
28390-static void vmcs_clear_bits(unsigned long field, u32 mask)
28391+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28392 {
28393 vmcs_writel(field, vmcs_readl(field) & ~mask);
28394 }
28395
28396-static void vmcs_set_bits(unsigned long field, u32 mask)
28397+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28398 {
28399 vmcs_writel(field, vmcs_readl(field) | mask);
28400 }
28401@@ -1604,7 +1604,11 @@ static void reload_tss(void)
28402 struct desc_struct *descs;
28403
28404 descs = (void *)gdt->address;
28405+
28406+ pax_open_kernel();
28407 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28408+ pax_close_kernel();
28409+
28410 load_TR_desc();
28411 }
28412
28413@@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28414 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28415 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28416
28417+#ifdef CONFIG_PAX_PER_CPU_PGD
28418+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28419+#endif
28420+
28421 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28422 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28423 vmx->loaded_vmcs->cpu = cpu;
28424@@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28425 * reads and returns guest's timestamp counter "register"
28426 * guest_tsc = host_tsc + tsc_offset -- 21.3
28427 */
28428-static u64 guest_read_tsc(void)
28429+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28430 {
28431 u64 host_tsc, tsc_offset;
28432
28433@@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28434 if (!cpu_has_vmx_flexpriority())
28435 flexpriority_enabled = 0;
28436
28437- if (!cpu_has_vmx_tpr_shadow())
28438- kvm_x86_ops->update_cr8_intercept = NULL;
28439+ if (!cpu_has_vmx_tpr_shadow()) {
28440+ pax_open_kernel();
28441+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28442+ pax_close_kernel();
28443+ }
28444
28445 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28446 kvm_disable_largepages();
28447@@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28448 if (!cpu_has_vmx_apicv())
28449 enable_apicv = 0;
28450
28451+ pax_open_kernel();
28452 if (enable_apicv)
28453- kvm_x86_ops->update_cr8_intercept = NULL;
28454+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28455 else {
28456- kvm_x86_ops->hwapic_irr_update = NULL;
28457- kvm_x86_ops->deliver_posted_interrupt = NULL;
28458- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28459+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28460+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28461+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28462 }
28463+ pax_close_kernel();
28464
28465 if (nested)
28466 nested_vmx_setup_ctls_msrs();
28467@@ -4235,7 +4248,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28468
28469 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28470 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28471+
28472+#ifndef CONFIG_PAX_PER_CPU_PGD
28473 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28474+#endif
28475
28476 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28477 #ifdef CONFIG_X86_64
28478@@ -4257,7 +4273,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28479 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28480 vmx->host_idt_base = dt.address;
28481
28482- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28483+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28484
28485 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28486 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28487@@ -7333,6 +7349,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28488 "jmp 2f \n\t"
28489 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28490 "2: "
28491+
28492+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28493+ "ljmp %[cs],$3f\n\t"
28494+ "3: "
28495+#endif
28496+
28497 /* Save guest registers, load host registers, keep flags */
28498 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28499 "pop %0 \n\t"
28500@@ -7385,6 +7407,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28501 #endif
28502 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28503 [wordsize]"i"(sizeof(ulong))
28504+
28505+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28506+ ,[cs]"i"(__KERNEL_CS)
28507+#endif
28508+
28509 : "cc", "memory"
28510 #ifdef CONFIG_X86_64
28511 , "rax", "rbx", "rdi", "rsi"
28512@@ -7398,7 +7425,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28513 if (debugctlmsr)
28514 update_debugctlmsr(debugctlmsr);
28515
28516-#ifndef CONFIG_X86_64
28517+#ifdef CONFIG_X86_32
28518 /*
28519 * The sysexit path does not restore ds/es, so we must set them to
28520 * a reasonable value ourselves.
28521@@ -7407,8 +7434,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28522 * may be executed in interrupt context, which saves and restore segments
28523 * around it, nullifying its effect.
28524 */
28525- loadsegment(ds, __USER_DS);
28526- loadsegment(es, __USER_DS);
28527+ loadsegment(ds, __KERNEL_DS);
28528+ loadsegment(es, __KERNEL_DS);
28529+ loadsegment(ss, __KERNEL_DS);
28530+
28531+#ifdef CONFIG_PAX_KERNEXEC
28532+ loadsegment(fs, __KERNEL_PERCPU);
28533+#endif
28534+
28535+#ifdef CONFIG_PAX_MEMORY_UDEREF
28536+ __set_fs(current_thread_info()->addr_limit);
28537+#endif
28538+
28539 #endif
28540
28541 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28542diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28543index 5521f7c..691b7a3 100644
28544--- a/arch/x86/kvm/x86.c
28545+++ b/arch/x86/kvm/x86.c
28546@@ -1822,8 +1822,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28547 {
28548 struct kvm *kvm = vcpu->kvm;
28549 int lm = is_long_mode(vcpu);
28550- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28551- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28552+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28553+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28554 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28555 : kvm->arch.xen_hvm_config.blob_size_32;
28556 u32 page_num = data & ~PAGE_MASK;
28557@@ -2738,6 +2738,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28558 if (n < msr_list.nmsrs)
28559 goto out;
28560 r = -EFAULT;
28561+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28562+ goto out;
28563 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28564 num_msrs_to_save * sizeof(u32)))
28565 goto out;
28566@@ -5574,7 +5576,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28567 };
28568 #endif
28569
28570-int kvm_arch_init(void *opaque)
28571+int kvm_arch_init(const void *opaque)
28572 {
28573 int r;
28574 struct kvm_x86_ops *ops = opaque;
28575diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28576index aae9413..d11e829 100644
28577--- a/arch/x86/lguest/boot.c
28578+++ b/arch/x86/lguest/boot.c
28579@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28580 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28581 * Launcher to reboot us.
28582 */
28583-static void lguest_restart(char *reason)
28584+static __noreturn void lguest_restart(char *reason)
28585 {
28586 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28587+ BUG();
28588 }
28589
28590 /*G:050
28591diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28592index 00933d5..3a64af9 100644
28593--- a/arch/x86/lib/atomic64_386_32.S
28594+++ b/arch/x86/lib/atomic64_386_32.S
28595@@ -48,6 +48,10 @@ BEGIN(read)
28596 movl (v), %eax
28597 movl 4(v), %edx
28598 RET_ENDP
28599+BEGIN(read_unchecked)
28600+ movl (v), %eax
28601+ movl 4(v), %edx
28602+RET_ENDP
28603 #undef v
28604
28605 #define v %esi
28606@@ -55,6 +59,10 @@ BEGIN(set)
28607 movl %ebx, (v)
28608 movl %ecx, 4(v)
28609 RET_ENDP
28610+BEGIN(set_unchecked)
28611+ movl %ebx, (v)
28612+ movl %ecx, 4(v)
28613+RET_ENDP
28614 #undef v
28615
28616 #define v %esi
28617@@ -70,6 +78,20 @@ RET_ENDP
28618 BEGIN(add)
28619 addl %eax, (v)
28620 adcl %edx, 4(v)
28621+
28622+#ifdef CONFIG_PAX_REFCOUNT
28623+ jno 0f
28624+ subl %eax, (v)
28625+ sbbl %edx, 4(v)
28626+ int $4
28627+0:
28628+ _ASM_EXTABLE(0b, 0b)
28629+#endif
28630+
28631+RET_ENDP
28632+BEGIN(add_unchecked)
28633+ addl %eax, (v)
28634+ adcl %edx, 4(v)
28635 RET_ENDP
28636 #undef v
28637
28638@@ -77,6 +99,24 @@ RET_ENDP
28639 BEGIN(add_return)
28640 addl (v), %eax
28641 adcl 4(v), %edx
28642+
28643+#ifdef CONFIG_PAX_REFCOUNT
28644+ into
28645+1234:
28646+ _ASM_EXTABLE(1234b, 2f)
28647+#endif
28648+
28649+ movl %eax, (v)
28650+ movl %edx, 4(v)
28651+
28652+#ifdef CONFIG_PAX_REFCOUNT
28653+2:
28654+#endif
28655+
28656+RET_ENDP
28657+BEGIN(add_return_unchecked)
28658+ addl (v), %eax
28659+ adcl 4(v), %edx
28660 movl %eax, (v)
28661 movl %edx, 4(v)
28662 RET_ENDP
28663@@ -86,6 +126,20 @@ RET_ENDP
28664 BEGIN(sub)
28665 subl %eax, (v)
28666 sbbl %edx, 4(v)
28667+
28668+#ifdef CONFIG_PAX_REFCOUNT
28669+ jno 0f
28670+ addl %eax, (v)
28671+ adcl %edx, 4(v)
28672+ int $4
28673+0:
28674+ _ASM_EXTABLE(0b, 0b)
28675+#endif
28676+
28677+RET_ENDP
28678+BEGIN(sub_unchecked)
28679+ subl %eax, (v)
28680+ sbbl %edx, 4(v)
28681 RET_ENDP
28682 #undef v
28683
28684@@ -96,6 +150,27 @@ BEGIN(sub_return)
28685 sbbl $0, %edx
28686 addl (v), %eax
28687 adcl 4(v), %edx
28688+
28689+#ifdef CONFIG_PAX_REFCOUNT
28690+ into
28691+1234:
28692+ _ASM_EXTABLE(1234b, 2f)
28693+#endif
28694+
28695+ movl %eax, (v)
28696+ movl %edx, 4(v)
28697+
28698+#ifdef CONFIG_PAX_REFCOUNT
28699+2:
28700+#endif
28701+
28702+RET_ENDP
28703+BEGIN(sub_return_unchecked)
28704+ negl %edx
28705+ negl %eax
28706+ sbbl $0, %edx
28707+ addl (v), %eax
28708+ adcl 4(v), %edx
28709 movl %eax, (v)
28710 movl %edx, 4(v)
28711 RET_ENDP
28712@@ -105,6 +180,20 @@ RET_ENDP
28713 BEGIN(inc)
28714 addl $1, (v)
28715 adcl $0, 4(v)
28716+
28717+#ifdef CONFIG_PAX_REFCOUNT
28718+ jno 0f
28719+ subl $1, (v)
28720+ sbbl $0, 4(v)
28721+ int $4
28722+0:
28723+ _ASM_EXTABLE(0b, 0b)
28724+#endif
28725+
28726+RET_ENDP
28727+BEGIN(inc_unchecked)
28728+ addl $1, (v)
28729+ adcl $0, 4(v)
28730 RET_ENDP
28731 #undef v
28732
28733@@ -114,6 +203,26 @@ BEGIN(inc_return)
28734 movl 4(v), %edx
28735 addl $1, %eax
28736 adcl $0, %edx
28737+
28738+#ifdef CONFIG_PAX_REFCOUNT
28739+ into
28740+1234:
28741+ _ASM_EXTABLE(1234b, 2f)
28742+#endif
28743+
28744+ movl %eax, (v)
28745+ movl %edx, 4(v)
28746+
28747+#ifdef CONFIG_PAX_REFCOUNT
28748+2:
28749+#endif
28750+
28751+RET_ENDP
28752+BEGIN(inc_return_unchecked)
28753+ movl (v), %eax
28754+ movl 4(v), %edx
28755+ addl $1, %eax
28756+ adcl $0, %edx
28757 movl %eax, (v)
28758 movl %edx, 4(v)
28759 RET_ENDP
28760@@ -123,6 +232,20 @@ RET_ENDP
28761 BEGIN(dec)
28762 subl $1, (v)
28763 sbbl $0, 4(v)
28764+
28765+#ifdef CONFIG_PAX_REFCOUNT
28766+ jno 0f
28767+ addl $1, (v)
28768+ adcl $0, 4(v)
28769+ int $4
28770+0:
28771+ _ASM_EXTABLE(0b, 0b)
28772+#endif
28773+
28774+RET_ENDP
28775+BEGIN(dec_unchecked)
28776+ subl $1, (v)
28777+ sbbl $0, 4(v)
28778 RET_ENDP
28779 #undef v
28780
28781@@ -132,6 +255,26 @@ BEGIN(dec_return)
28782 movl 4(v), %edx
28783 subl $1, %eax
28784 sbbl $0, %edx
28785+
28786+#ifdef CONFIG_PAX_REFCOUNT
28787+ into
28788+1234:
28789+ _ASM_EXTABLE(1234b, 2f)
28790+#endif
28791+
28792+ movl %eax, (v)
28793+ movl %edx, 4(v)
28794+
28795+#ifdef CONFIG_PAX_REFCOUNT
28796+2:
28797+#endif
28798+
28799+RET_ENDP
28800+BEGIN(dec_return_unchecked)
28801+ movl (v), %eax
28802+ movl 4(v), %edx
28803+ subl $1, %eax
28804+ sbbl $0, %edx
28805 movl %eax, (v)
28806 movl %edx, 4(v)
28807 RET_ENDP
28808@@ -143,6 +286,13 @@ BEGIN(add_unless)
28809 adcl %edx, %edi
28810 addl (v), %eax
28811 adcl 4(v), %edx
28812+
28813+#ifdef CONFIG_PAX_REFCOUNT
28814+ into
28815+1234:
28816+ _ASM_EXTABLE(1234b, 2f)
28817+#endif
28818+
28819 cmpl %eax, %ecx
28820 je 3f
28821 1:
28822@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28823 1:
28824 addl $1, %eax
28825 adcl $0, %edx
28826+
28827+#ifdef CONFIG_PAX_REFCOUNT
28828+ into
28829+1234:
28830+ _ASM_EXTABLE(1234b, 2f)
28831+#endif
28832+
28833 movl %eax, (v)
28834 movl %edx, 4(v)
28835 movl $1, %eax
28836@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28837 movl 4(v), %edx
28838 subl $1, %eax
28839 sbbl $0, %edx
28840+
28841+#ifdef CONFIG_PAX_REFCOUNT
28842+ into
28843+1234:
28844+ _ASM_EXTABLE(1234b, 1f)
28845+#endif
28846+
28847 js 1f
28848 movl %eax, (v)
28849 movl %edx, 4(v)
28850diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28851index f5cc9eb..51fa319 100644
28852--- a/arch/x86/lib/atomic64_cx8_32.S
28853+++ b/arch/x86/lib/atomic64_cx8_32.S
28854@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28855 CFI_STARTPROC
28856
28857 read64 %ecx
28858+ pax_force_retaddr
28859 ret
28860 CFI_ENDPROC
28861 ENDPROC(atomic64_read_cx8)
28862
28863+ENTRY(atomic64_read_unchecked_cx8)
28864+ CFI_STARTPROC
28865+
28866+ read64 %ecx
28867+ pax_force_retaddr
28868+ ret
28869+ CFI_ENDPROC
28870+ENDPROC(atomic64_read_unchecked_cx8)
28871+
28872 ENTRY(atomic64_set_cx8)
28873 CFI_STARTPROC
28874
28875@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28876 cmpxchg8b (%esi)
28877 jne 1b
28878
28879+ pax_force_retaddr
28880 ret
28881 CFI_ENDPROC
28882 ENDPROC(atomic64_set_cx8)
28883
28884+ENTRY(atomic64_set_unchecked_cx8)
28885+ CFI_STARTPROC
28886+
28887+1:
28888+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28889+ * are atomic on 586 and newer */
28890+ cmpxchg8b (%esi)
28891+ jne 1b
28892+
28893+ pax_force_retaddr
28894+ ret
28895+ CFI_ENDPROC
28896+ENDPROC(atomic64_set_unchecked_cx8)
28897+
28898 ENTRY(atomic64_xchg_cx8)
28899 CFI_STARTPROC
28900
28901@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28902 cmpxchg8b (%esi)
28903 jne 1b
28904
28905+ pax_force_retaddr
28906 ret
28907 CFI_ENDPROC
28908 ENDPROC(atomic64_xchg_cx8)
28909
28910-.macro addsub_return func ins insc
28911-ENTRY(atomic64_\func\()_return_cx8)
28912+.macro addsub_return func ins insc unchecked=""
28913+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28914 CFI_STARTPROC
28915 SAVE ebp
28916 SAVE ebx
28917@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28918 movl %edx, %ecx
28919 \ins\()l %esi, %ebx
28920 \insc\()l %edi, %ecx
28921+
28922+.ifb \unchecked
28923+#ifdef CONFIG_PAX_REFCOUNT
28924+ into
28925+2:
28926+ _ASM_EXTABLE(2b, 3f)
28927+#endif
28928+.endif
28929+
28930 LOCK_PREFIX
28931 cmpxchg8b (%ebp)
28932 jne 1b
28933-
28934-10:
28935 movl %ebx, %eax
28936 movl %ecx, %edx
28937+
28938+.ifb \unchecked
28939+#ifdef CONFIG_PAX_REFCOUNT
28940+3:
28941+#endif
28942+.endif
28943+
28944 RESTORE edi
28945 RESTORE esi
28946 RESTORE ebx
28947 RESTORE ebp
28948+ pax_force_retaddr
28949 ret
28950 CFI_ENDPROC
28951-ENDPROC(atomic64_\func\()_return_cx8)
28952+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28953 .endm
28954
28955 addsub_return add add adc
28956 addsub_return sub sub sbb
28957+addsub_return add add adc _unchecked
28958+addsub_return sub sub sbb _unchecked
28959
28960-.macro incdec_return func ins insc
28961-ENTRY(atomic64_\func\()_return_cx8)
28962+.macro incdec_return func ins insc unchecked=""
28963+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28964 CFI_STARTPROC
28965 SAVE ebx
28966
28967@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28968 movl %edx, %ecx
28969 \ins\()l $1, %ebx
28970 \insc\()l $0, %ecx
28971+
28972+.ifb \unchecked
28973+#ifdef CONFIG_PAX_REFCOUNT
28974+ into
28975+2:
28976+ _ASM_EXTABLE(2b, 3f)
28977+#endif
28978+.endif
28979+
28980 LOCK_PREFIX
28981 cmpxchg8b (%esi)
28982 jne 1b
28983
28984-10:
28985 movl %ebx, %eax
28986 movl %ecx, %edx
28987+
28988+.ifb \unchecked
28989+#ifdef CONFIG_PAX_REFCOUNT
28990+3:
28991+#endif
28992+.endif
28993+
28994 RESTORE ebx
28995+ pax_force_retaddr
28996 ret
28997 CFI_ENDPROC
28998-ENDPROC(atomic64_\func\()_return_cx8)
28999+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29000 .endm
29001
29002 incdec_return inc add adc
29003 incdec_return dec sub sbb
29004+incdec_return inc add adc _unchecked
29005+incdec_return dec sub sbb _unchecked
29006
29007 ENTRY(atomic64_dec_if_positive_cx8)
29008 CFI_STARTPROC
29009@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29010 movl %edx, %ecx
29011 subl $1, %ebx
29012 sbb $0, %ecx
29013+
29014+#ifdef CONFIG_PAX_REFCOUNT
29015+ into
29016+1234:
29017+ _ASM_EXTABLE(1234b, 2f)
29018+#endif
29019+
29020 js 2f
29021 LOCK_PREFIX
29022 cmpxchg8b (%esi)
29023@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29024 movl %ebx, %eax
29025 movl %ecx, %edx
29026 RESTORE ebx
29027+ pax_force_retaddr
29028 ret
29029 CFI_ENDPROC
29030 ENDPROC(atomic64_dec_if_positive_cx8)
29031@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29032 movl %edx, %ecx
29033 addl %ebp, %ebx
29034 adcl %edi, %ecx
29035+
29036+#ifdef CONFIG_PAX_REFCOUNT
29037+ into
29038+1234:
29039+ _ASM_EXTABLE(1234b, 3f)
29040+#endif
29041+
29042 LOCK_PREFIX
29043 cmpxchg8b (%esi)
29044 jne 1b
29045@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29046 CFI_ADJUST_CFA_OFFSET -8
29047 RESTORE ebx
29048 RESTORE ebp
29049+ pax_force_retaddr
29050 ret
29051 4:
29052 cmpl %edx, 4(%esp)
29053@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29054 xorl %ecx, %ecx
29055 addl $1, %ebx
29056 adcl %edx, %ecx
29057+
29058+#ifdef CONFIG_PAX_REFCOUNT
29059+ into
29060+1234:
29061+ _ASM_EXTABLE(1234b, 3f)
29062+#endif
29063+
29064 LOCK_PREFIX
29065 cmpxchg8b (%esi)
29066 jne 1b
29067@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29068 movl $1, %eax
29069 3:
29070 RESTORE ebx
29071+ pax_force_retaddr
29072 ret
29073 CFI_ENDPROC
29074 ENDPROC(atomic64_inc_not_zero_cx8)
29075diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29076index e78b8ee..7e173a8 100644
29077--- a/arch/x86/lib/checksum_32.S
29078+++ b/arch/x86/lib/checksum_32.S
29079@@ -29,7 +29,8 @@
29080 #include <asm/dwarf2.h>
29081 #include <asm/errno.h>
29082 #include <asm/asm.h>
29083-
29084+#include <asm/segment.h>
29085+
29086 /*
29087 * computes a partial checksum, e.g. for TCP/UDP fragments
29088 */
29089@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29090
29091 #define ARGBASE 16
29092 #define FP 12
29093-
29094-ENTRY(csum_partial_copy_generic)
29095+
29096+ENTRY(csum_partial_copy_generic_to_user)
29097 CFI_STARTPROC
29098+
29099+#ifdef CONFIG_PAX_MEMORY_UDEREF
29100+ pushl_cfi %gs
29101+ popl_cfi %es
29102+ jmp csum_partial_copy_generic
29103+#endif
29104+
29105+ENTRY(csum_partial_copy_generic_from_user)
29106+
29107+#ifdef CONFIG_PAX_MEMORY_UDEREF
29108+ pushl_cfi %gs
29109+ popl_cfi %ds
29110+#endif
29111+
29112+ENTRY(csum_partial_copy_generic)
29113 subl $4,%esp
29114 CFI_ADJUST_CFA_OFFSET 4
29115 pushl_cfi %edi
29116@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29117 jmp 4f
29118 SRC(1: movw (%esi), %bx )
29119 addl $2, %esi
29120-DST( movw %bx, (%edi) )
29121+DST( movw %bx, %es:(%edi) )
29122 addl $2, %edi
29123 addw %bx, %ax
29124 adcl $0, %eax
29125@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29126 SRC(1: movl (%esi), %ebx )
29127 SRC( movl 4(%esi), %edx )
29128 adcl %ebx, %eax
29129-DST( movl %ebx, (%edi) )
29130+DST( movl %ebx, %es:(%edi) )
29131 adcl %edx, %eax
29132-DST( movl %edx, 4(%edi) )
29133+DST( movl %edx, %es:4(%edi) )
29134
29135 SRC( movl 8(%esi), %ebx )
29136 SRC( movl 12(%esi), %edx )
29137 adcl %ebx, %eax
29138-DST( movl %ebx, 8(%edi) )
29139+DST( movl %ebx, %es:8(%edi) )
29140 adcl %edx, %eax
29141-DST( movl %edx, 12(%edi) )
29142+DST( movl %edx, %es:12(%edi) )
29143
29144 SRC( movl 16(%esi), %ebx )
29145 SRC( movl 20(%esi), %edx )
29146 adcl %ebx, %eax
29147-DST( movl %ebx, 16(%edi) )
29148+DST( movl %ebx, %es:16(%edi) )
29149 adcl %edx, %eax
29150-DST( movl %edx, 20(%edi) )
29151+DST( movl %edx, %es:20(%edi) )
29152
29153 SRC( movl 24(%esi), %ebx )
29154 SRC( movl 28(%esi), %edx )
29155 adcl %ebx, %eax
29156-DST( movl %ebx, 24(%edi) )
29157+DST( movl %ebx, %es:24(%edi) )
29158 adcl %edx, %eax
29159-DST( movl %edx, 28(%edi) )
29160+DST( movl %edx, %es:28(%edi) )
29161
29162 lea 32(%esi), %esi
29163 lea 32(%edi), %edi
29164@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29165 shrl $2, %edx # This clears CF
29166 SRC(3: movl (%esi), %ebx )
29167 adcl %ebx, %eax
29168-DST( movl %ebx, (%edi) )
29169+DST( movl %ebx, %es:(%edi) )
29170 lea 4(%esi), %esi
29171 lea 4(%edi), %edi
29172 dec %edx
29173@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29174 jb 5f
29175 SRC( movw (%esi), %cx )
29176 leal 2(%esi), %esi
29177-DST( movw %cx, (%edi) )
29178+DST( movw %cx, %es:(%edi) )
29179 leal 2(%edi), %edi
29180 je 6f
29181 shll $16,%ecx
29182 SRC(5: movb (%esi), %cl )
29183-DST( movb %cl, (%edi) )
29184+DST( movb %cl, %es:(%edi) )
29185 6: addl %ecx, %eax
29186 adcl $0, %eax
29187 7:
29188@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29189
29190 6001:
29191 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29192- movl $-EFAULT, (%ebx)
29193+ movl $-EFAULT, %ss:(%ebx)
29194
29195 # zero the complete destination - computing the rest
29196 # is too much work
29197@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29198
29199 6002:
29200 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29201- movl $-EFAULT,(%ebx)
29202+ movl $-EFAULT,%ss:(%ebx)
29203 jmp 5000b
29204
29205 .previous
29206
29207+ pushl_cfi %ss
29208+ popl_cfi %ds
29209+ pushl_cfi %ss
29210+ popl_cfi %es
29211 popl_cfi %ebx
29212 CFI_RESTORE ebx
29213 popl_cfi %esi
29214@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29215 popl_cfi %ecx # equivalent to addl $4,%esp
29216 ret
29217 CFI_ENDPROC
29218-ENDPROC(csum_partial_copy_generic)
29219+ENDPROC(csum_partial_copy_generic_to_user)
29220
29221 #else
29222
29223 /* Version for PentiumII/PPro */
29224
29225 #define ROUND1(x) \
29226+ nop; nop; nop; \
29227 SRC(movl x(%esi), %ebx ) ; \
29228 addl %ebx, %eax ; \
29229- DST(movl %ebx, x(%edi) ) ;
29230+ DST(movl %ebx, %es:x(%edi)) ;
29231
29232 #define ROUND(x) \
29233+ nop; nop; nop; \
29234 SRC(movl x(%esi), %ebx ) ; \
29235 adcl %ebx, %eax ; \
29236- DST(movl %ebx, x(%edi) ) ;
29237+ DST(movl %ebx, %es:x(%edi)) ;
29238
29239 #define ARGBASE 12
29240-
29241-ENTRY(csum_partial_copy_generic)
29242+
29243+ENTRY(csum_partial_copy_generic_to_user)
29244 CFI_STARTPROC
29245+
29246+#ifdef CONFIG_PAX_MEMORY_UDEREF
29247+ pushl_cfi %gs
29248+ popl_cfi %es
29249+ jmp csum_partial_copy_generic
29250+#endif
29251+
29252+ENTRY(csum_partial_copy_generic_from_user)
29253+
29254+#ifdef CONFIG_PAX_MEMORY_UDEREF
29255+ pushl_cfi %gs
29256+ popl_cfi %ds
29257+#endif
29258+
29259+ENTRY(csum_partial_copy_generic)
29260 pushl_cfi %ebx
29261 CFI_REL_OFFSET ebx, 0
29262 pushl_cfi %edi
29263@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29264 subl %ebx, %edi
29265 lea -1(%esi),%edx
29266 andl $-32,%edx
29267- lea 3f(%ebx,%ebx), %ebx
29268+ lea 3f(%ebx,%ebx,2), %ebx
29269 testl %esi, %esi
29270 jmp *%ebx
29271 1: addl $64,%esi
29272@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29273 jb 5f
29274 SRC( movw (%esi), %dx )
29275 leal 2(%esi), %esi
29276-DST( movw %dx, (%edi) )
29277+DST( movw %dx, %es:(%edi) )
29278 leal 2(%edi), %edi
29279 je 6f
29280 shll $16,%edx
29281 5:
29282 SRC( movb (%esi), %dl )
29283-DST( movb %dl, (%edi) )
29284+DST( movb %dl, %es:(%edi) )
29285 6: addl %edx, %eax
29286 adcl $0, %eax
29287 7:
29288 .section .fixup, "ax"
29289 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29290- movl $-EFAULT, (%ebx)
29291+ movl $-EFAULT, %ss:(%ebx)
29292 # zero the complete destination (computing the rest is too much work)
29293 movl ARGBASE+8(%esp),%edi # dst
29294 movl ARGBASE+12(%esp),%ecx # len
29295@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29296 rep; stosb
29297 jmp 7b
29298 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29299- movl $-EFAULT, (%ebx)
29300+ movl $-EFAULT, %ss:(%ebx)
29301 jmp 7b
29302 .previous
29303
29304+#ifdef CONFIG_PAX_MEMORY_UDEREF
29305+ pushl_cfi %ss
29306+ popl_cfi %ds
29307+ pushl_cfi %ss
29308+ popl_cfi %es
29309+#endif
29310+
29311 popl_cfi %esi
29312 CFI_RESTORE esi
29313 popl_cfi %edi
29314@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29315 CFI_RESTORE ebx
29316 ret
29317 CFI_ENDPROC
29318-ENDPROC(csum_partial_copy_generic)
29319+ENDPROC(csum_partial_copy_generic_to_user)
29320
29321 #undef ROUND
29322 #undef ROUND1
29323diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29324index f2145cf..cea889d 100644
29325--- a/arch/x86/lib/clear_page_64.S
29326+++ b/arch/x86/lib/clear_page_64.S
29327@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29328 movl $4096/8,%ecx
29329 xorl %eax,%eax
29330 rep stosq
29331+ pax_force_retaddr
29332 ret
29333 CFI_ENDPROC
29334 ENDPROC(clear_page_c)
29335@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29336 movl $4096,%ecx
29337 xorl %eax,%eax
29338 rep stosb
29339+ pax_force_retaddr
29340 ret
29341 CFI_ENDPROC
29342 ENDPROC(clear_page_c_e)
29343@@ -43,6 +45,7 @@ ENTRY(clear_page)
29344 leaq 64(%rdi),%rdi
29345 jnz .Lloop
29346 nop
29347+ pax_force_retaddr
29348 ret
29349 CFI_ENDPROC
29350 .Lclear_page_end:
29351@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29352
29353 #include <asm/cpufeature.h>
29354
29355- .section .altinstr_replacement,"ax"
29356+ .section .altinstr_replacement,"a"
29357 1: .byte 0xeb /* jmp <disp8> */
29358 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29359 2: .byte 0xeb /* jmp <disp8> */
29360diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29361index 1e572c5..2a162cd 100644
29362--- a/arch/x86/lib/cmpxchg16b_emu.S
29363+++ b/arch/x86/lib/cmpxchg16b_emu.S
29364@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29365
29366 popf
29367 mov $1, %al
29368+ pax_force_retaddr
29369 ret
29370
29371 not_same:
29372 popf
29373 xor %al,%al
29374+ pax_force_retaddr
29375 ret
29376
29377 CFI_ENDPROC
29378diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29379index 176cca6..e0d658e 100644
29380--- a/arch/x86/lib/copy_page_64.S
29381+++ b/arch/x86/lib/copy_page_64.S
29382@@ -9,6 +9,7 @@ copy_page_rep:
29383 CFI_STARTPROC
29384 movl $4096/8, %ecx
29385 rep movsq
29386+ pax_force_retaddr
29387 ret
29388 CFI_ENDPROC
29389 ENDPROC(copy_page_rep)
29390@@ -24,8 +25,8 @@ ENTRY(copy_page)
29391 CFI_ADJUST_CFA_OFFSET 2*8
29392 movq %rbx, (%rsp)
29393 CFI_REL_OFFSET rbx, 0
29394- movq %r12, 1*8(%rsp)
29395- CFI_REL_OFFSET r12, 1*8
29396+ movq %r13, 1*8(%rsp)
29397+ CFI_REL_OFFSET r13, 1*8
29398
29399 movl $(4096/64)-5, %ecx
29400 .p2align 4
29401@@ -38,7 +39,7 @@ ENTRY(copy_page)
29402 movq 0x8*4(%rsi), %r9
29403 movq 0x8*5(%rsi), %r10
29404 movq 0x8*6(%rsi), %r11
29405- movq 0x8*7(%rsi), %r12
29406+ movq 0x8*7(%rsi), %r13
29407
29408 prefetcht0 5*64(%rsi)
29409
29410@@ -49,7 +50,7 @@ ENTRY(copy_page)
29411 movq %r9, 0x8*4(%rdi)
29412 movq %r10, 0x8*5(%rdi)
29413 movq %r11, 0x8*6(%rdi)
29414- movq %r12, 0x8*7(%rdi)
29415+ movq %r13, 0x8*7(%rdi)
29416
29417 leaq 64 (%rsi), %rsi
29418 leaq 64 (%rdi), %rdi
29419@@ -68,7 +69,7 @@ ENTRY(copy_page)
29420 movq 0x8*4(%rsi), %r9
29421 movq 0x8*5(%rsi), %r10
29422 movq 0x8*6(%rsi), %r11
29423- movq 0x8*7(%rsi), %r12
29424+ movq 0x8*7(%rsi), %r13
29425
29426 movq %rax, 0x8*0(%rdi)
29427 movq %rbx, 0x8*1(%rdi)
29428@@ -77,7 +78,7 @@ ENTRY(copy_page)
29429 movq %r9, 0x8*4(%rdi)
29430 movq %r10, 0x8*5(%rdi)
29431 movq %r11, 0x8*6(%rdi)
29432- movq %r12, 0x8*7(%rdi)
29433+ movq %r13, 0x8*7(%rdi)
29434
29435 leaq 64(%rdi), %rdi
29436 leaq 64(%rsi), %rsi
29437@@ -85,10 +86,11 @@ ENTRY(copy_page)
29438
29439 movq (%rsp), %rbx
29440 CFI_RESTORE rbx
29441- movq 1*8(%rsp), %r12
29442- CFI_RESTORE r12
29443+ movq 1*8(%rsp), %r13
29444+ CFI_RESTORE r13
29445 addq $2*8, %rsp
29446 CFI_ADJUST_CFA_OFFSET -2*8
29447+ pax_force_retaddr
29448 ret
29449 .Lcopy_page_end:
29450 CFI_ENDPROC
29451@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29452
29453 #include <asm/cpufeature.h>
29454
29455- .section .altinstr_replacement,"ax"
29456+ .section .altinstr_replacement,"a"
29457 1: .byte 0xeb /* jmp <disp8> */
29458 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29459 2:
29460diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29461index dee945d..a84067b 100644
29462--- a/arch/x86/lib/copy_user_64.S
29463+++ b/arch/x86/lib/copy_user_64.S
29464@@ -18,31 +18,7 @@
29465 #include <asm/alternative-asm.h>
29466 #include <asm/asm.h>
29467 #include <asm/smap.h>
29468-
29469-/*
29470- * By placing feature2 after feature1 in altinstructions section, we logically
29471- * implement:
29472- * If CPU has feature2, jmp to alt2 is used
29473- * else if CPU has feature1, jmp to alt1 is used
29474- * else jmp to orig is used.
29475- */
29476- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29477-0:
29478- .byte 0xe9 /* 32bit jump */
29479- .long \orig-1f /* by default jump to orig */
29480-1:
29481- .section .altinstr_replacement,"ax"
29482-2: .byte 0xe9 /* near jump with 32bit immediate */
29483- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29484-3: .byte 0xe9 /* near jump with 32bit immediate */
29485- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29486- .previous
29487-
29488- .section .altinstructions,"a"
29489- altinstruction_entry 0b,2b,\feature1,5,5
29490- altinstruction_entry 0b,3b,\feature2,5,5
29491- .previous
29492- .endm
29493+#include <asm/pgtable.h>
29494
29495 .macro ALIGN_DESTINATION
29496 #ifdef FIX_ALIGNMENT
29497@@ -70,52 +46,6 @@
29498 #endif
29499 .endm
29500
29501-/* Standard copy_to_user with segment limit checking */
29502-ENTRY(_copy_to_user)
29503- CFI_STARTPROC
29504- GET_THREAD_INFO(%rax)
29505- movq %rdi,%rcx
29506- addq %rdx,%rcx
29507- jc bad_to_user
29508- cmpq TI_addr_limit(%rax),%rcx
29509- ja bad_to_user
29510- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29511- copy_user_generic_unrolled,copy_user_generic_string, \
29512- copy_user_enhanced_fast_string
29513- CFI_ENDPROC
29514-ENDPROC(_copy_to_user)
29515-
29516-/* Standard copy_from_user with segment limit checking */
29517-ENTRY(_copy_from_user)
29518- CFI_STARTPROC
29519- GET_THREAD_INFO(%rax)
29520- movq %rsi,%rcx
29521- addq %rdx,%rcx
29522- jc bad_from_user
29523- cmpq TI_addr_limit(%rax),%rcx
29524- ja bad_from_user
29525- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29526- copy_user_generic_unrolled,copy_user_generic_string, \
29527- copy_user_enhanced_fast_string
29528- CFI_ENDPROC
29529-ENDPROC(_copy_from_user)
29530-
29531- .section .fixup,"ax"
29532- /* must zero dest */
29533-ENTRY(bad_from_user)
29534-bad_from_user:
29535- CFI_STARTPROC
29536- movl %edx,%ecx
29537- xorl %eax,%eax
29538- rep
29539- stosb
29540-bad_to_user:
29541- movl %edx,%eax
29542- ret
29543- CFI_ENDPROC
29544-ENDPROC(bad_from_user)
29545- .previous
29546-
29547 /*
29548 * copy_user_generic_unrolled - memory copy with exception handling.
29549 * This version is for CPUs like P4 that don't have efficient micro
29550@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29551 */
29552 ENTRY(copy_user_generic_unrolled)
29553 CFI_STARTPROC
29554+ ASM_PAX_OPEN_USERLAND
29555 ASM_STAC
29556 cmpl $8,%edx
29557 jb 20f /* less then 8 bytes, go to byte copy loop */
29558@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29559 jnz 21b
29560 23: xor %eax,%eax
29561 ASM_CLAC
29562+ ASM_PAX_CLOSE_USERLAND
29563+ pax_force_retaddr
29564 ret
29565
29566 .section .fixup,"ax"
29567@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29568 */
29569 ENTRY(copy_user_generic_string)
29570 CFI_STARTPROC
29571+ ASM_PAX_OPEN_USERLAND
29572 ASM_STAC
29573 cmpl $8,%edx
29574 jb 2f /* less than 8 bytes, go to byte copy loop */
29575@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29576 movsb
29577 xorl %eax,%eax
29578 ASM_CLAC
29579+ ASM_PAX_CLOSE_USERLAND
29580+ pax_force_retaddr
29581 ret
29582
29583 .section .fixup,"ax"
29584@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29585 */
29586 ENTRY(copy_user_enhanced_fast_string)
29587 CFI_STARTPROC
29588+ ASM_PAX_OPEN_USERLAND
29589 ASM_STAC
29590 movl %edx,%ecx
29591 1: rep
29592 movsb
29593 xorl %eax,%eax
29594 ASM_CLAC
29595+ ASM_PAX_CLOSE_USERLAND
29596+ pax_force_retaddr
29597 ret
29598
29599 .section .fixup,"ax"
29600diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29601index 6a4f43c..c70fb52 100644
29602--- a/arch/x86/lib/copy_user_nocache_64.S
29603+++ b/arch/x86/lib/copy_user_nocache_64.S
29604@@ -8,6 +8,7 @@
29605
29606 #include <linux/linkage.h>
29607 #include <asm/dwarf2.h>
29608+#include <asm/alternative-asm.h>
29609
29610 #define FIX_ALIGNMENT 1
29611
29612@@ -16,6 +17,7 @@
29613 #include <asm/thread_info.h>
29614 #include <asm/asm.h>
29615 #include <asm/smap.h>
29616+#include <asm/pgtable.h>
29617
29618 .macro ALIGN_DESTINATION
29619 #ifdef FIX_ALIGNMENT
29620@@ -49,6 +51,16 @@
29621 */
29622 ENTRY(__copy_user_nocache)
29623 CFI_STARTPROC
29624+
29625+#ifdef CONFIG_PAX_MEMORY_UDEREF
29626+ mov pax_user_shadow_base,%rcx
29627+ cmp %rcx,%rsi
29628+ jae 1f
29629+ add %rcx,%rsi
29630+1:
29631+#endif
29632+
29633+ ASM_PAX_OPEN_USERLAND
29634 ASM_STAC
29635 cmpl $8,%edx
29636 jb 20f /* less then 8 bytes, go to byte copy loop */
29637@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29638 jnz 21b
29639 23: xorl %eax,%eax
29640 ASM_CLAC
29641+ ASM_PAX_CLOSE_USERLAND
29642 sfence
29643+ pax_force_retaddr
29644 ret
29645
29646 .section .fixup,"ax"
29647diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29648index 2419d5f..fe52d0e 100644
29649--- a/arch/x86/lib/csum-copy_64.S
29650+++ b/arch/x86/lib/csum-copy_64.S
29651@@ -9,6 +9,7 @@
29652 #include <asm/dwarf2.h>
29653 #include <asm/errno.h>
29654 #include <asm/asm.h>
29655+#include <asm/alternative-asm.h>
29656
29657 /*
29658 * Checksum copy with exception handling.
29659@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29660 CFI_ADJUST_CFA_OFFSET 7*8
29661 movq %rbx, 2*8(%rsp)
29662 CFI_REL_OFFSET rbx, 2*8
29663- movq %r12, 3*8(%rsp)
29664- CFI_REL_OFFSET r12, 3*8
29665+ movq %r15, 3*8(%rsp)
29666+ CFI_REL_OFFSET r15, 3*8
29667 movq %r14, 4*8(%rsp)
29668 CFI_REL_OFFSET r14, 4*8
29669 movq %r13, 5*8(%rsp)
29670@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29671 movl %edx, %ecx
29672
29673 xorl %r9d, %r9d
29674- movq %rcx, %r12
29675+ movq %rcx, %r15
29676
29677- shrq $6, %r12
29678+ shrq $6, %r15
29679 jz .Lhandle_tail /* < 64 */
29680
29681 clc
29682
29683 /* main loop. clear in 64 byte blocks */
29684 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29685- /* r11: temp3, rdx: temp4, r12 loopcnt */
29686+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29687 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29688 .p2align 4
29689 .Lloop:
29690@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29691 adcq %r14, %rax
29692 adcq %r13, %rax
29693
29694- decl %r12d
29695+ decl %r15d
29696
29697 dest
29698 movq %rbx, (%rsi)
29699@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29700 .Lende:
29701 movq 2*8(%rsp), %rbx
29702 CFI_RESTORE rbx
29703- movq 3*8(%rsp), %r12
29704- CFI_RESTORE r12
29705+ movq 3*8(%rsp), %r15
29706+ CFI_RESTORE r15
29707 movq 4*8(%rsp), %r14
29708 CFI_RESTORE r14
29709 movq 5*8(%rsp), %r13
29710@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29711 CFI_RESTORE rbp
29712 addq $7*8, %rsp
29713 CFI_ADJUST_CFA_OFFSET -7*8
29714+ pax_force_retaddr
29715 ret
29716 CFI_RESTORE_STATE
29717
29718diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29719index 7609e0e..b449b98 100644
29720--- a/arch/x86/lib/csum-wrappers_64.c
29721+++ b/arch/x86/lib/csum-wrappers_64.c
29722@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29723 len -= 2;
29724 }
29725 }
29726+ pax_open_userland();
29727 stac();
29728- isum = csum_partial_copy_generic((__force const void *)src,
29729+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29730 dst, len, isum, errp, NULL);
29731 clac();
29732+ pax_close_userland();
29733 if (unlikely(*errp))
29734 goto out_err;
29735
29736@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29737 }
29738
29739 *errp = 0;
29740+ pax_open_userland();
29741 stac();
29742- ret = csum_partial_copy_generic(src, (void __force *)dst,
29743+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29744 len, isum, NULL, errp);
29745 clac();
29746+ pax_close_userland();
29747 return ret;
29748 }
29749 EXPORT_SYMBOL(csum_partial_copy_to_user);
29750diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29751index a451235..1daa956 100644
29752--- a/arch/x86/lib/getuser.S
29753+++ b/arch/x86/lib/getuser.S
29754@@ -33,17 +33,40 @@
29755 #include <asm/thread_info.h>
29756 #include <asm/asm.h>
29757 #include <asm/smap.h>
29758+#include <asm/segment.h>
29759+#include <asm/pgtable.h>
29760+#include <asm/alternative-asm.h>
29761+
29762+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29763+#define __copyuser_seg gs;
29764+#else
29765+#define __copyuser_seg
29766+#endif
29767
29768 .text
29769 ENTRY(__get_user_1)
29770 CFI_STARTPROC
29771+
29772+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29773 GET_THREAD_INFO(%_ASM_DX)
29774 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29775 jae bad_get_user
29776 ASM_STAC
29777-1: movzbl (%_ASM_AX),%edx
29778+
29779+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29780+ mov pax_user_shadow_base,%_ASM_DX
29781+ cmp %_ASM_DX,%_ASM_AX
29782+ jae 1234f
29783+ add %_ASM_DX,%_ASM_AX
29784+1234:
29785+#endif
29786+
29787+#endif
29788+
29789+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29790 xor %eax,%eax
29791 ASM_CLAC
29792+ pax_force_retaddr
29793 ret
29794 CFI_ENDPROC
29795 ENDPROC(__get_user_1)
29796@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29797 ENTRY(__get_user_2)
29798 CFI_STARTPROC
29799 add $1,%_ASM_AX
29800+
29801+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29802 jc bad_get_user
29803 GET_THREAD_INFO(%_ASM_DX)
29804 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29805 jae bad_get_user
29806 ASM_STAC
29807-2: movzwl -1(%_ASM_AX),%edx
29808+
29809+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29810+ mov pax_user_shadow_base,%_ASM_DX
29811+ cmp %_ASM_DX,%_ASM_AX
29812+ jae 1234f
29813+ add %_ASM_DX,%_ASM_AX
29814+1234:
29815+#endif
29816+
29817+#endif
29818+
29819+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29820 xor %eax,%eax
29821 ASM_CLAC
29822+ pax_force_retaddr
29823 ret
29824 CFI_ENDPROC
29825 ENDPROC(__get_user_2)
29826@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29827 ENTRY(__get_user_4)
29828 CFI_STARTPROC
29829 add $3,%_ASM_AX
29830+
29831+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29832 jc bad_get_user
29833 GET_THREAD_INFO(%_ASM_DX)
29834 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29835 jae bad_get_user
29836 ASM_STAC
29837-3: movl -3(%_ASM_AX),%edx
29838+
29839+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29840+ mov pax_user_shadow_base,%_ASM_DX
29841+ cmp %_ASM_DX,%_ASM_AX
29842+ jae 1234f
29843+ add %_ASM_DX,%_ASM_AX
29844+1234:
29845+#endif
29846+
29847+#endif
29848+
29849+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29850 xor %eax,%eax
29851 ASM_CLAC
29852+ pax_force_retaddr
29853 ret
29854 CFI_ENDPROC
29855 ENDPROC(__get_user_4)
29856@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29857 GET_THREAD_INFO(%_ASM_DX)
29858 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29859 jae bad_get_user
29860+
29861+#ifdef CONFIG_PAX_MEMORY_UDEREF
29862+ mov pax_user_shadow_base,%_ASM_DX
29863+ cmp %_ASM_DX,%_ASM_AX
29864+ jae 1234f
29865+ add %_ASM_DX,%_ASM_AX
29866+1234:
29867+#endif
29868+
29869 ASM_STAC
29870 4: movq -7(%_ASM_AX),%rdx
29871 xor %eax,%eax
29872 ASM_CLAC
29873+ pax_force_retaddr
29874 ret
29875 #else
29876 add $7,%_ASM_AX
29877@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29878 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29879 jae bad_get_user_8
29880 ASM_STAC
29881-4: movl -7(%_ASM_AX),%edx
29882-5: movl -3(%_ASM_AX),%ecx
29883+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29884+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29885 xor %eax,%eax
29886 ASM_CLAC
29887+ pax_force_retaddr
29888 ret
29889 #endif
29890 CFI_ENDPROC
29891@@ -113,6 +175,7 @@ bad_get_user:
29892 xor %edx,%edx
29893 mov $(-EFAULT),%_ASM_AX
29894 ASM_CLAC
29895+ pax_force_retaddr
29896 ret
29897 CFI_ENDPROC
29898 END(bad_get_user)
29899@@ -124,6 +187,7 @@ bad_get_user_8:
29900 xor %ecx,%ecx
29901 mov $(-EFAULT),%_ASM_AX
29902 ASM_CLAC
29903+ pax_force_retaddr
29904 ret
29905 CFI_ENDPROC
29906 END(bad_get_user_8)
29907diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29908index 54fcffe..7be149e 100644
29909--- a/arch/x86/lib/insn.c
29910+++ b/arch/x86/lib/insn.c
29911@@ -20,8 +20,10 @@
29912
29913 #ifdef __KERNEL__
29914 #include <linux/string.h>
29915+#include <asm/pgtable_types.h>
29916 #else
29917 #include <string.h>
29918+#define ktla_ktva(addr) addr
29919 #endif
29920 #include <asm/inat.h>
29921 #include <asm/insn.h>
29922@@ -53,8 +55,8 @@
29923 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29924 {
29925 memset(insn, 0, sizeof(*insn));
29926- insn->kaddr = kaddr;
29927- insn->next_byte = kaddr;
29928+ insn->kaddr = ktla_ktva(kaddr);
29929+ insn->next_byte = ktla_ktva(kaddr);
29930 insn->x86_64 = x86_64 ? 1 : 0;
29931 insn->opnd_bytes = 4;
29932 if (x86_64)
29933diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29934index 05a95e7..326f2fa 100644
29935--- a/arch/x86/lib/iomap_copy_64.S
29936+++ b/arch/x86/lib/iomap_copy_64.S
29937@@ -17,6 +17,7 @@
29938
29939 #include <linux/linkage.h>
29940 #include <asm/dwarf2.h>
29941+#include <asm/alternative-asm.h>
29942
29943 /*
29944 * override generic version in lib/iomap_copy.c
29945@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29946 CFI_STARTPROC
29947 movl %edx,%ecx
29948 rep movsd
29949+ pax_force_retaddr
29950 ret
29951 CFI_ENDPROC
29952 ENDPROC(__iowrite32_copy)
29953diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29954index 56313a3..0db417e 100644
29955--- a/arch/x86/lib/memcpy_64.S
29956+++ b/arch/x86/lib/memcpy_64.S
29957@@ -24,7 +24,7 @@
29958 * This gets patched over the unrolled variant (below) via the
29959 * alternative instructions framework:
29960 */
29961- .section .altinstr_replacement, "ax", @progbits
29962+ .section .altinstr_replacement, "a", @progbits
29963 .Lmemcpy_c:
29964 movq %rdi, %rax
29965 movq %rdx, %rcx
29966@@ -33,6 +33,7 @@
29967 rep movsq
29968 movl %edx, %ecx
29969 rep movsb
29970+ pax_force_retaddr
29971 ret
29972 .Lmemcpy_e:
29973 .previous
29974@@ -44,11 +45,12 @@
29975 * This gets patched over the unrolled variant (below) via the
29976 * alternative instructions framework:
29977 */
29978- .section .altinstr_replacement, "ax", @progbits
29979+ .section .altinstr_replacement, "a", @progbits
29980 .Lmemcpy_c_e:
29981 movq %rdi, %rax
29982 movq %rdx, %rcx
29983 rep movsb
29984+ pax_force_retaddr
29985 ret
29986 .Lmemcpy_e_e:
29987 .previous
29988@@ -136,6 +138,7 @@ ENTRY(memcpy)
29989 movq %r9, 1*8(%rdi)
29990 movq %r10, -2*8(%rdi, %rdx)
29991 movq %r11, -1*8(%rdi, %rdx)
29992+ pax_force_retaddr
29993 retq
29994 .p2align 4
29995 .Lless_16bytes:
29996@@ -148,6 +151,7 @@ ENTRY(memcpy)
29997 movq -1*8(%rsi, %rdx), %r9
29998 movq %r8, 0*8(%rdi)
29999 movq %r9, -1*8(%rdi, %rdx)
30000+ pax_force_retaddr
30001 retq
30002 .p2align 4
30003 .Lless_8bytes:
30004@@ -161,6 +165,7 @@ ENTRY(memcpy)
30005 movl -4(%rsi, %rdx), %r8d
30006 movl %ecx, (%rdi)
30007 movl %r8d, -4(%rdi, %rdx)
30008+ pax_force_retaddr
30009 retq
30010 .p2align 4
30011 .Lless_3bytes:
30012@@ -179,6 +184,7 @@ ENTRY(memcpy)
30013 movb %cl, (%rdi)
30014
30015 .Lend:
30016+ pax_force_retaddr
30017 retq
30018 CFI_ENDPROC
30019 ENDPROC(memcpy)
30020diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30021index 65268a6..dd1de11 100644
30022--- a/arch/x86/lib/memmove_64.S
30023+++ b/arch/x86/lib/memmove_64.S
30024@@ -202,14 +202,16 @@ ENTRY(memmove)
30025 movb (%rsi), %r11b
30026 movb %r11b, (%rdi)
30027 13:
30028+ pax_force_retaddr
30029 retq
30030 CFI_ENDPROC
30031
30032- .section .altinstr_replacement,"ax"
30033+ .section .altinstr_replacement,"a"
30034 .Lmemmove_begin_forward_efs:
30035 /* Forward moving data. */
30036 movq %rdx, %rcx
30037 rep movsb
30038+ pax_force_retaddr
30039 retq
30040 .Lmemmove_end_forward_efs:
30041 .previous
30042diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30043index 2dcb380..2eb79fe 100644
30044--- a/arch/x86/lib/memset_64.S
30045+++ b/arch/x86/lib/memset_64.S
30046@@ -16,7 +16,7 @@
30047 *
30048 * rax original destination
30049 */
30050- .section .altinstr_replacement, "ax", @progbits
30051+ .section .altinstr_replacement, "a", @progbits
30052 .Lmemset_c:
30053 movq %rdi,%r9
30054 movq %rdx,%rcx
30055@@ -30,6 +30,7 @@
30056 movl %edx,%ecx
30057 rep stosb
30058 movq %r9,%rax
30059+ pax_force_retaddr
30060 ret
30061 .Lmemset_e:
30062 .previous
30063@@ -45,13 +46,14 @@
30064 *
30065 * rax original destination
30066 */
30067- .section .altinstr_replacement, "ax", @progbits
30068+ .section .altinstr_replacement, "a", @progbits
30069 .Lmemset_c_e:
30070 movq %rdi,%r9
30071 movb %sil,%al
30072 movq %rdx,%rcx
30073 rep stosb
30074 movq %r9,%rax
30075+ pax_force_retaddr
30076 ret
30077 .Lmemset_e_e:
30078 .previous
30079@@ -118,6 +120,7 @@ ENTRY(__memset)
30080
30081 .Lende:
30082 movq %r10,%rax
30083+ pax_force_retaddr
30084 ret
30085
30086 CFI_RESTORE_STATE
30087diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30088index c9f2d9b..e7fd2c0 100644
30089--- a/arch/x86/lib/mmx_32.c
30090+++ b/arch/x86/lib/mmx_32.c
30091@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30092 {
30093 void *p;
30094 int i;
30095+ unsigned long cr0;
30096
30097 if (unlikely(in_interrupt()))
30098 return __memcpy(to, from, len);
30099@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30100 kernel_fpu_begin();
30101
30102 __asm__ __volatile__ (
30103- "1: prefetch (%0)\n" /* This set is 28 bytes */
30104- " prefetch 64(%0)\n"
30105- " prefetch 128(%0)\n"
30106- " prefetch 192(%0)\n"
30107- " prefetch 256(%0)\n"
30108+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30109+ " prefetch 64(%1)\n"
30110+ " prefetch 128(%1)\n"
30111+ " prefetch 192(%1)\n"
30112+ " prefetch 256(%1)\n"
30113 "2: \n"
30114 ".section .fixup, \"ax\"\n"
30115- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30116+ "3: \n"
30117+
30118+#ifdef CONFIG_PAX_KERNEXEC
30119+ " movl %%cr0, %0\n"
30120+ " movl %0, %%eax\n"
30121+ " andl $0xFFFEFFFF, %%eax\n"
30122+ " movl %%eax, %%cr0\n"
30123+#endif
30124+
30125+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30126+
30127+#ifdef CONFIG_PAX_KERNEXEC
30128+ " movl %0, %%cr0\n"
30129+#endif
30130+
30131 " jmp 2b\n"
30132 ".previous\n"
30133 _ASM_EXTABLE(1b, 3b)
30134- : : "r" (from));
30135+ : "=&r" (cr0) : "r" (from) : "ax");
30136
30137 for ( ; i > 5; i--) {
30138 __asm__ __volatile__ (
30139- "1: prefetch 320(%0)\n"
30140- "2: movq (%0), %%mm0\n"
30141- " movq 8(%0), %%mm1\n"
30142- " movq 16(%0), %%mm2\n"
30143- " movq 24(%0), %%mm3\n"
30144- " movq %%mm0, (%1)\n"
30145- " movq %%mm1, 8(%1)\n"
30146- " movq %%mm2, 16(%1)\n"
30147- " movq %%mm3, 24(%1)\n"
30148- " movq 32(%0), %%mm0\n"
30149- " movq 40(%0), %%mm1\n"
30150- " movq 48(%0), %%mm2\n"
30151- " movq 56(%0), %%mm3\n"
30152- " movq %%mm0, 32(%1)\n"
30153- " movq %%mm1, 40(%1)\n"
30154- " movq %%mm2, 48(%1)\n"
30155- " movq %%mm3, 56(%1)\n"
30156+ "1: prefetch 320(%1)\n"
30157+ "2: movq (%1), %%mm0\n"
30158+ " movq 8(%1), %%mm1\n"
30159+ " movq 16(%1), %%mm2\n"
30160+ " movq 24(%1), %%mm3\n"
30161+ " movq %%mm0, (%2)\n"
30162+ " movq %%mm1, 8(%2)\n"
30163+ " movq %%mm2, 16(%2)\n"
30164+ " movq %%mm3, 24(%2)\n"
30165+ " movq 32(%1), %%mm0\n"
30166+ " movq 40(%1), %%mm1\n"
30167+ " movq 48(%1), %%mm2\n"
30168+ " movq 56(%1), %%mm3\n"
30169+ " movq %%mm0, 32(%2)\n"
30170+ " movq %%mm1, 40(%2)\n"
30171+ " movq %%mm2, 48(%2)\n"
30172+ " movq %%mm3, 56(%2)\n"
30173 ".section .fixup, \"ax\"\n"
30174- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30175+ "3:\n"
30176+
30177+#ifdef CONFIG_PAX_KERNEXEC
30178+ " movl %%cr0, %0\n"
30179+ " movl %0, %%eax\n"
30180+ " andl $0xFFFEFFFF, %%eax\n"
30181+ " movl %%eax, %%cr0\n"
30182+#endif
30183+
30184+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30185+
30186+#ifdef CONFIG_PAX_KERNEXEC
30187+ " movl %0, %%cr0\n"
30188+#endif
30189+
30190 " jmp 2b\n"
30191 ".previous\n"
30192 _ASM_EXTABLE(1b, 3b)
30193- : : "r" (from), "r" (to) : "memory");
30194+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30195
30196 from += 64;
30197 to += 64;
30198@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30199 static void fast_copy_page(void *to, void *from)
30200 {
30201 int i;
30202+ unsigned long cr0;
30203
30204 kernel_fpu_begin();
30205
30206@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30207 * but that is for later. -AV
30208 */
30209 __asm__ __volatile__(
30210- "1: prefetch (%0)\n"
30211- " prefetch 64(%0)\n"
30212- " prefetch 128(%0)\n"
30213- " prefetch 192(%0)\n"
30214- " prefetch 256(%0)\n"
30215+ "1: prefetch (%1)\n"
30216+ " prefetch 64(%1)\n"
30217+ " prefetch 128(%1)\n"
30218+ " prefetch 192(%1)\n"
30219+ " prefetch 256(%1)\n"
30220 "2: \n"
30221 ".section .fixup, \"ax\"\n"
30222- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30223+ "3: \n"
30224+
30225+#ifdef CONFIG_PAX_KERNEXEC
30226+ " movl %%cr0, %0\n"
30227+ " movl %0, %%eax\n"
30228+ " andl $0xFFFEFFFF, %%eax\n"
30229+ " movl %%eax, %%cr0\n"
30230+#endif
30231+
30232+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30233+
30234+#ifdef CONFIG_PAX_KERNEXEC
30235+ " movl %0, %%cr0\n"
30236+#endif
30237+
30238 " jmp 2b\n"
30239 ".previous\n"
30240- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30241+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30242
30243 for (i = 0; i < (4096-320)/64; i++) {
30244 __asm__ __volatile__ (
30245- "1: prefetch 320(%0)\n"
30246- "2: movq (%0), %%mm0\n"
30247- " movntq %%mm0, (%1)\n"
30248- " movq 8(%0), %%mm1\n"
30249- " movntq %%mm1, 8(%1)\n"
30250- " movq 16(%0), %%mm2\n"
30251- " movntq %%mm2, 16(%1)\n"
30252- " movq 24(%0), %%mm3\n"
30253- " movntq %%mm3, 24(%1)\n"
30254- " movq 32(%0), %%mm4\n"
30255- " movntq %%mm4, 32(%1)\n"
30256- " movq 40(%0), %%mm5\n"
30257- " movntq %%mm5, 40(%1)\n"
30258- " movq 48(%0), %%mm6\n"
30259- " movntq %%mm6, 48(%1)\n"
30260- " movq 56(%0), %%mm7\n"
30261- " movntq %%mm7, 56(%1)\n"
30262+ "1: prefetch 320(%1)\n"
30263+ "2: movq (%1), %%mm0\n"
30264+ " movntq %%mm0, (%2)\n"
30265+ " movq 8(%1), %%mm1\n"
30266+ " movntq %%mm1, 8(%2)\n"
30267+ " movq 16(%1), %%mm2\n"
30268+ " movntq %%mm2, 16(%2)\n"
30269+ " movq 24(%1), %%mm3\n"
30270+ " movntq %%mm3, 24(%2)\n"
30271+ " movq 32(%1), %%mm4\n"
30272+ " movntq %%mm4, 32(%2)\n"
30273+ " movq 40(%1), %%mm5\n"
30274+ " movntq %%mm5, 40(%2)\n"
30275+ " movq 48(%1), %%mm6\n"
30276+ " movntq %%mm6, 48(%2)\n"
30277+ " movq 56(%1), %%mm7\n"
30278+ " movntq %%mm7, 56(%2)\n"
30279 ".section .fixup, \"ax\"\n"
30280- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30281+ "3:\n"
30282+
30283+#ifdef CONFIG_PAX_KERNEXEC
30284+ " movl %%cr0, %0\n"
30285+ " movl %0, %%eax\n"
30286+ " andl $0xFFFEFFFF, %%eax\n"
30287+ " movl %%eax, %%cr0\n"
30288+#endif
30289+
30290+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30291+
30292+#ifdef CONFIG_PAX_KERNEXEC
30293+ " movl %0, %%cr0\n"
30294+#endif
30295+
30296 " jmp 2b\n"
30297 ".previous\n"
30298- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30299+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30300
30301 from += 64;
30302 to += 64;
30303@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30304 static void fast_copy_page(void *to, void *from)
30305 {
30306 int i;
30307+ unsigned long cr0;
30308
30309 kernel_fpu_begin();
30310
30311 __asm__ __volatile__ (
30312- "1: prefetch (%0)\n"
30313- " prefetch 64(%0)\n"
30314- " prefetch 128(%0)\n"
30315- " prefetch 192(%0)\n"
30316- " prefetch 256(%0)\n"
30317+ "1: prefetch (%1)\n"
30318+ " prefetch 64(%1)\n"
30319+ " prefetch 128(%1)\n"
30320+ " prefetch 192(%1)\n"
30321+ " prefetch 256(%1)\n"
30322 "2: \n"
30323 ".section .fixup, \"ax\"\n"
30324- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30325+ "3: \n"
30326+
30327+#ifdef CONFIG_PAX_KERNEXEC
30328+ " movl %%cr0, %0\n"
30329+ " movl %0, %%eax\n"
30330+ " andl $0xFFFEFFFF, %%eax\n"
30331+ " movl %%eax, %%cr0\n"
30332+#endif
30333+
30334+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30335+
30336+#ifdef CONFIG_PAX_KERNEXEC
30337+ " movl %0, %%cr0\n"
30338+#endif
30339+
30340 " jmp 2b\n"
30341 ".previous\n"
30342- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30343+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30344
30345 for (i = 0; i < 4096/64; i++) {
30346 __asm__ __volatile__ (
30347- "1: prefetch 320(%0)\n"
30348- "2: movq (%0), %%mm0\n"
30349- " movq 8(%0), %%mm1\n"
30350- " movq 16(%0), %%mm2\n"
30351- " movq 24(%0), %%mm3\n"
30352- " movq %%mm0, (%1)\n"
30353- " movq %%mm1, 8(%1)\n"
30354- " movq %%mm2, 16(%1)\n"
30355- " movq %%mm3, 24(%1)\n"
30356- " movq 32(%0), %%mm0\n"
30357- " movq 40(%0), %%mm1\n"
30358- " movq 48(%0), %%mm2\n"
30359- " movq 56(%0), %%mm3\n"
30360- " movq %%mm0, 32(%1)\n"
30361- " movq %%mm1, 40(%1)\n"
30362- " movq %%mm2, 48(%1)\n"
30363- " movq %%mm3, 56(%1)\n"
30364+ "1: prefetch 320(%1)\n"
30365+ "2: movq (%1), %%mm0\n"
30366+ " movq 8(%1), %%mm1\n"
30367+ " movq 16(%1), %%mm2\n"
30368+ " movq 24(%1), %%mm3\n"
30369+ " movq %%mm0, (%2)\n"
30370+ " movq %%mm1, 8(%2)\n"
30371+ " movq %%mm2, 16(%2)\n"
30372+ " movq %%mm3, 24(%2)\n"
30373+ " movq 32(%1), %%mm0\n"
30374+ " movq 40(%1), %%mm1\n"
30375+ " movq 48(%1), %%mm2\n"
30376+ " movq 56(%1), %%mm3\n"
30377+ " movq %%mm0, 32(%2)\n"
30378+ " movq %%mm1, 40(%2)\n"
30379+ " movq %%mm2, 48(%2)\n"
30380+ " movq %%mm3, 56(%2)\n"
30381 ".section .fixup, \"ax\"\n"
30382- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30383+ "3:\n"
30384+
30385+#ifdef CONFIG_PAX_KERNEXEC
30386+ " movl %%cr0, %0\n"
30387+ " movl %0, %%eax\n"
30388+ " andl $0xFFFEFFFF, %%eax\n"
30389+ " movl %%eax, %%cr0\n"
30390+#endif
30391+
30392+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30393+
30394+#ifdef CONFIG_PAX_KERNEXEC
30395+ " movl %0, %%cr0\n"
30396+#endif
30397+
30398 " jmp 2b\n"
30399 ".previous\n"
30400 _ASM_EXTABLE(1b, 3b)
30401- : : "r" (from), "r" (to) : "memory");
30402+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30403
30404 from += 64;
30405 to += 64;
30406diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30407index f6d13ee..d789440 100644
30408--- a/arch/x86/lib/msr-reg.S
30409+++ b/arch/x86/lib/msr-reg.S
30410@@ -3,6 +3,7 @@
30411 #include <asm/dwarf2.h>
30412 #include <asm/asm.h>
30413 #include <asm/msr.h>
30414+#include <asm/alternative-asm.h>
30415
30416 #ifdef CONFIG_X86_64
30417 /*
30418@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30419 movl %edi, 28(%r10)
30420 popq_cfi %rbp
30421 popq_cfi %rbx
30422+ pax_force_retaddr
30423 ret
30424 3:
30425 CFI_RESTORE_STATE
30426diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30427index fc6ba17..d4d989d 100644
30428--- a/arch/x86/lib/putuser.S
30429+++ b/arch/x86/lib/putuser.S
30430@@ -16,7 +16,9 @@
30431 #include <asm/errno.h>
30432 #include <asm/asm.h>
30433 #include <asm/smap.h>
30434-
30435+#include <asm/segment.h>
30436+#include <asm/pgtable.h>
30437+#include <asm/alternative-asm.h>
30438
30439 /*
30440 * __put_user_X
30441@@ -30,57 +32,125 @@
30442 * as they get called from within inline assembly.
30443 */
30444
30445-#define ENTER CFI_STARTPROC ; \
30446- GET_THREAD_INFO(%_ASM_BX)
30447-#define EXIT ASM_CLAC ; \
30448- ret ; \
30449+#define ENTER CFI_STARTPROC
30450+#define EXIT ASM_CLAC ; \
30451+ pax_force_retaddr ; \
30452+ ret ; \
30453 CFI_ENDPROC
30454
30455+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30456+#define _DEST %_ASM_CX,%_ASM_BX
30457+#else
30458+#define _DEST %_ASM_CX
30459+#endif
30460+
30461+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30462+#define __copyuser_seg gs;
30463+#else
30464+#define __copyuser_seg
30465+#endif
30466+
30467 .text
30468 ENTRY(__put_user_1)
30469 ENTER
30470+
30471+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30472+ GET_THREAD_INFO(%_ASM_BX)
30473 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30474 jae bad_put_user
30475 ASM_STAC
30476-1: movb %al,(%_ASM_CX)
30477+
30478+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30479+ mov pax_user_shadow_base,%_ASM_BX
30480+ cmp %_ASM_BX,%_ASM_CX
30481+ jb 1234f
30482+ xor %ebx,%ebx
30483+1234:
30484+#endif
30485+
30486+#endif
30487+
30488+1: __copyuser_seg movb %al,(_DEST)
30489 xor %eax,%eax
30490 EXIT
30491 ENDPROC(__put_user_1)
30492
30493 ENTRY(__put_user_2)
30494 ENTER
30495+
30496+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30497+ GET_THREAD_INFO(%_ASM_BX)
30498 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30499 sub $1,%_ASM_BX
30500 cmp %_ASM_BX,%_ASM_CX
30501 jae bad_put_user
30502 ASM_STAC
30503-2: movw %ax,(%_ASM_CX)
30504+
30505+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30506+ mov pax_user_shadow_base,%_ASM_BX
30507+ cmp %_ASM_BX,%_ASM_CX
30508+ jb 1234f
30509+ xor %ebx,%ebx
30510+1234:
30511+#endif
30512+
30513+#endif
30514+
30515+2: __copyuser_seg movw %ax,(_DEST)
30516 xor %eax,%eax
30517 EXIT
30518 ENDPROC(__put_user_2)
30519
30520 ENTRY(__put_user_4)
30521 ENTER
30522+
30523+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30524+ GET_THREAD_INFO(%_ASM_BX)
30525 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30526 sub $3,%_ASM_BX
30527 cmp %_ASM_BX,%_ASM_CX
30528 jae bad_put_user
30529 ASM_STAC
30530-3: movl %eax,(%_ASM_CX)
30531+
30532+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30533+ mov pax_user_shadow_base,%_ASM_BX
30534+ cmp %_ASM_BX,%_ASM_CX
30535+ jb 1234f
30536+ xor %ebx,%ebx
30537+1234:
30538+#endif
30539+
30540+#endif
30541+
30542+3: __copyuser_seg movl %eax,(_DEST)
30543 xor %eax,%eax
30544 EXIT
30545 ENDPROC(__put_user_4)
30546
30547 ENTRY(__put_user_8)
30548 ENTER
30549+
30550+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30551+ GET_THREAD_INFO(%_ASM_BX)
30552 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30553 sub $7,%_ASM_BX
30554 cmp %_ASM_BX,%_ASM_CX
30555 jae bad_put_user
30556 ASM_STAC
30557-4: mov %_ASM_AX,(%_ASM_CX)
30558+
30559+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30560+ mov pax_user_shadow_base,%_ASM_BX
30561+ cmp %_ASM_BX,%_ASM_CX
30562+ jb 1234f
30563+ xor %ebx,%ebx
30564+1234:
30565+#endif
30566+
30567+#endif
30568+
30569+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30570 #ifdef CONFIG_X86_32
30571-5: movl %edx,4(%_ASM_CX)
30572+5: __copyuser_seg movl %edx,4(_DEST)
30573 #endif
30574 xor %eax,%eax
30575 EXIT
30576diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30577index 1cad221..de671ee 100644
30578--- a/arch/x86/lib/rwlock.S
30579+++ b/arch/x86/lib/rwlock.S
30580@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30581 FRAME
30582 0: LOCK_PREFIX
30583 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30584+
30585+#ifdef CONFIG_PAX_REFCOUNT
30586+ jno 1234f
30587+ LOCK_PREFIX
30588+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30589+ int $4
30590+1234:
30591+ _ASM_EXTABLE(1234b, 1234b)
30592+#endif
30593+
30594 1: rep; nop
30595 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30596 jne 1b
30597 LOCK_PREFIX
30598 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30599+
30600+#ifdef CONFIG_PAX_REFCOUNT
30601+ jno 1234f
30602+ LOCK_PREFIX
30603+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30604+ int $4
30605+1234:
30606+ _ASM_EXTABLE(1234b, 1234b)
30607+#endif
30608+
30609 jnz 0b
30610 ENDFRAME
30611+ pax_force_retaddr
30612 ret
30613 CFI_ENDPROC
30614 END(__write_lock_failed)
30615@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30616 FRAME
30617 0: LOCK_PREFIX
30618 READ_LOCK_SIZE(inc) (%__lock_ptr)
30619+
30620+#ifdef CONFIG_PAX_REFCOUNT
30621+ jno 1234f
30622+ LOCK_PREFIX
30623+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30624+ int $4
30625+1234:
30626+ _ASM_EXTABLE(1234b, 1234b)
30627+#endif
30628+
30629 1: rep; nop
30630 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30631 js 1b
30632 LOCK_PREFIX
30633 READ_LOCK_SIZE(dec) (%__lock_ptr)
30634+
30635+#ifdef CONFIG_PAX_REFCOUNT
30636+ jno 1234f
30637+ LOCK_PREFIX
30638+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30639+ int $4
30640+1234:
30641+ _ASM_EXTABLE(1234b, 1234b)
30642+#endif
30643+
30644 js 0b
30645 ENDFRAME
30646+ pax_force_retaddr
30647 ret
30648 CFI_ENDPROC
30649 END(__read_lock_failed)
30650diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30651index 5dff5f0..cadebf4 100644
30652--- a/arch/x86/lib/rwsem.S
30653+++ b/arch/x86/lib/rwsem.S
30654@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30655 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30656 CFI_RESTORE __ASM_REG(dx)
30657 restore_common_regs
30658+ pax_force_retaddr
30659 ret
30660 CFI_ENDPROC
30661 ENDPROC(call_rwsem_down_read_failed)
30662@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30663 movq %rax,%rdi
30664 call rwsem_down_write_failed
30665 restore_common_regs
30666+ pax_force_retaddr
30667 ret
30668 CFI_ENDPROC
30669 ENDPROC(call_rwsem_down_write_failed)
30670@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30671 movq %rax,%rdi
30672 call rwsem_wake
30673 restore_common_regs
30674-1: ret
30675+1: pax_force_retaddr
30676+ ret
30677 CFI_ENDPROC
30678 ENDPROC(call_rwsem_wake)
30679
30680@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30681 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30682 CFI_RESTORE __ASM_REG(dx)
30683 restore_common_regs
30684+ pax_force_retaddr
30685 ret
30686 CFI_ENDPROC
30687 ENDPROC(call_rwsem_downgrade_wake)
30688diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30689index a63efd6..8149fbe 100644
30690--- a/arch/x86/lib/thunk_64.S
30691+++ b/arch/x86/lib/thunk_64.S
30692@@ -8,6 +8,7 @@
30693 #include <linux/linkage.h>
30694 #include <asm/dwarf2.h>
30695 #include <asm/calling.h>
30696+#include <asm/alternative-asm.h>
30697
30698 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30699 .macro THUNK name, func, put_ret_addr_in_rdi=0
30700@@ -15,11 +16,11 @@
30701 \name:
30702 CFI_STARTPROC
30703
30704- /* this one pushes 9 elems, the next one would be %rIP */
30705- SAVE_ARGS
30706+ /* this one pushes 15+1 elems, the next one would be %rIP */
30707+ SAVE_ARGS 8
30708
30709 .if \put_ret_addr_in_rdi
30710- movq_cfi_restore 9*8, rdi
30711+ movq_cfi_restore RIP, rdi
30712 .endif
30713
30714 call \func
30715@@ -38,8 +39,9 @@
30716
30717 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30718 CFI_STARTPROC
30719- SAVE_ARGS
30720+ SAVE_ARGS 8
30721 restore:
30722- RESTORE_ARGS
30723+ RESTORE_ARGS 1,8
30724+ pax_force_retaddr
30725 ret
30726 CFI_ENDPROC
30727diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30728index e2f5e21..4b22130 100644
30729--- a/arch/x86/lib/usercopy_32.c
30730+++ b/arch/x86/lib/usercopy_32.c
30731@@ -42,11 +42,13 @@ do { \
30732 int __d0; \
30733 might_fault(); \
30734 __asm__ __volatile__( \
30735+ __COPYUSER_SET_ES \
30736 ASM_STAC "\n" \
30737 "0: rep; stosl\n" \
30738 " movl %2,%0\n" \
30739 "1: rep; stosb\n" \
30740 "2: " ASM_CLAC "\n" \
30741+ __COPYUSER_RESTORE_ES \
30742 ".section .fixup,\"ax\"\n" \
30743 "3: lea 0(%2,%0,4),%0\n" \
30744 " jmp 2b\n" \
30745@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30746
30747 #ifdef CONFIG_X86_INTEL_USERCOPY
30748 static unsigned long
30749-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30750+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30751 {
30752 int d0, d1;
30753 __asm__ __volatile__(
30754@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30755 " .align 2,0x90\n"
30756 "3: movl 0(%4), %%eax\n"
30757 "4: movl 4(%4), %%edx\n"
30758- "5: movl %%eax, 0(%3)\n"
30759- "6: movl %%edx, 4(%3)\n"
30760+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30761+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30762 "7: movl 8(%4), %%eax\n"
30763 "8: movl 12(%4),%%edx\n"
30764- "9: movl %%eax, 8(%3)\n"
30765- "10: movl %%edx, 12(%3)\n"
30766+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30767+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30768 "11: movl 16(%4), %%eax\n"
30769 "12: movl 20(%4), %%edx\n"
30770- "13: movl %%eax, 16(%3)\n"
30771- "14: movl %%edx, 20(%3)\n"
30772+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30773+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30774 "15: movl 24(%4), %%eax\n"
30775 "16: movl 28(%4), %%edx\n"
30776- "17: movl %%eax, 24(%3)\n"
30777- "18: movl %%edx, 28(%3)\n"
30778+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30779+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30780 "19: movl 32(%4), %%eax\n"
30781 "20: movl 36(%4), %%edx\n"
30782- "21: movl %%eax, 32(%3)\n"
30783- "22: movl %%edx, 36(%3)\n"
30784+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30785+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30786 "23: movl 40(%4), %%eax\n"
30787 "24: movl 44(%4), %%edx\n"
30788- "25: movl %%eax, 40(%3)\n"
30789- "26: movl %%edx, 44(%3)\n"
30790+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30791+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30792 "27: movl 48(%4), %%eax\n"
30793 "28: movl 52(%4), %%edx\n"
30794- "29: movl %%eax, 48(%3)\n"
30795- "30: movl %%edx, 52(%3)\n"
30796+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30797+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30798 "31: movl 56(%4), %%eax\n"
30799 "32: movl 60(%4), %%edx\n"
30800- "33: movl %%eax, 56(%3)\n"
30801- "34: movl %%edx, 60(%3)\n"
30802+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30803+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30804 " addl $-64, %0\n"
30805 " addl $64, %4\n"
30806 " addl $64, %3\n"
30807@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30808 " shrl $2, %0\n"
30809 " andl $3, %%eax\n"
30810 " cld\n"
30811+ __COPYUSER_SET_ES
30812 "99: rep; movsl\n"
30813 "36: movl %%eax, %0\n"
30814 "37: rep; movsb\n"
30815 "100:\n"
30816+ __COPYUSER_RESTORE_ES
30817+ ".section .fixup,\"ax\"\n"
30818+ "101: lea 0(%%eax,%0,4),%0\n"
30819+ " jmp 100b\n"
30820+ ".previous\n"
30821+ _ASM_EXTABLE(1b,100b)
30822+ _ASM_EXTABLE(2b,100b)
30823+ _ASM_EXTABLE(3b,100b)
30824+ _ASM_EXTABLE(4b,100b)
30825+ _ASM_EXTABLE(5b,100b)
30826+ _ASM_EXTABLE(6b,100b)
30827+ _ASM_EXTABLE(7b,100b)
30828+ _ASM_EXTABLE(8b,100b)
30829+ _ASM_EXTABLE(9b,100b)
30830+ _ASM_EXTABLE(10b,100b)
30831+ _ASM_EXTABLE(11b,100b)
30832+ _ASM_EXTABLE(12b,100b)
30833+ _ASM_EXTABLE(13b,100b)
30834+ _ASM_EXTABLE(14b,100b)
30835+ _ASM_EXTABLE(15b,100b)
30836+ _ASM_EXTABLE(16b,100b)
30837+ _ASM_EXTABLE(17b,100b)
30838+ _ASM_EXTABLE(18b,100b)
30839+ _ASM_EXTABLE(19b,100b)
30840+ _ASM_EXTABLE(20b,100b)
30841+ _ASM_EXTABLE(21b,100b)
30842+ _ASM_EXTABLE(22b,100b)
30843+ _ASM_EXTABLE(23b,100b)
30844+ _ASM_EXTABLE(24b,100b)
30845+ _ASM_EXTABLE(25b,100b)
30846+ _ASM_EXTABLE(26b,100b)
30847+ _ASM_EXTABLE(27b,100b)
30848+ _ASM_EXTABLE(28b,100b)
30849+ _ASM_EXTABLE(29b,100b)
30850+ _ASM_EXTABLE(30b,100b)
30851+ _ASM_EXTABLE(31b,100b)
30852+ _ASM_EXTABLE(32b,100b)
30853+ _ASM_EXTABLE(33b,100b)
30854+ _ASM_EXTABLE(34b,100b)
30855+ _ASM_EXTABLE(35b,100b)
30856+ _ASM_EXTABLE(36b,100b)
30857+ _ASM_EXTABLE(37b,100b)
30858+ _ASM_EXTABLE(99b,101b)
30859+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30860+ : "1"(to), "2"(from), "0"(size)
30861+ : "eax", "edx", "memory");
30862+ return size;
30863+}
30864+
30865+static unsigned long
30866+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30867+{
30868+ int d0, d1;
30869+ __asm__ __volatile__(
30870+ " .align 2,0x90\n"
30871+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30872+ " cmpl $67, %0\n"
30873+ " jbe 3f\n"
30874+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30875+ " .align 2,0x90\n"
30876+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30877+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30878+ "5: movl %%eax, 0(%3)\n"
30879+ "6: movl %%edx, 4(%3)\n"
30880+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30881+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30882+ "9: movl %%eax, 8(%3)\n"
30883+ "10: movl %%edx, 12(%3)\n"
30884+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30885+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30886+ "13: movl %%eax, 16(%3)\n"
30887+ "14: movl %%edx, 20(%3)\n"
30888+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30889+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30890+ "17: movl %%eax, 24(%3)\n"
30891+ "18: movl %%edx, 28(%3)\n"
30892+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30893+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30894+ "21: movl %%eax, 32(%3)\n"
30895+ "22: movl %%edx, 36(%3)\n"
30896+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30897+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30898+ "25: movl %%eax, 40(%3)\n"
30899+ "26: movl %%edx, 44(%3)\n"
30900+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30901+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30902+ "29: movl %%eax, 48(%3)\n"
30903+ "30: movl %%edx, 52(%3)\n"
30904+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30905+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30906+ "33: movl %%eax, 56(%3)\n"
30907+ "34: movl %%edx, 60(%3)\n"
30908+ " addl $-64, %0\n"
30909+ " addl $64, %4\n"
30910+ " addl $64, %3\n"
30911+ " cmpl $63, %0\n"
30912+ " ja 1b\n"
30913+ "35: movl %0, %%eax\n"
30914+ " shrl $2, %0\n"
30915+ " andl $3, %%eax\n"
30916+ " cld\n"
30917+ "99: rep; "__copyuser_seg" movsl\n"
30918+ "36: movl %%eax, %0\n"
30919+ "37: rep; "__copyuser_seg" movsb\n"
30920+ "100:\n"
30921 ".section .fixup,\"ax\"\n"
30922 "101: lea 0(%%eax,%0,4),%0\n"
30923 " jmp 100b\n"
30924@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30925 int d0, d1;
30926 __asm__ __volatile__(
30927 " .align 2,0x90\n"
30928- "0: movl 32(%4), %%eax\n"
30929+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30930 " cmpl $67, %0\n"
30931 " jbe 2f\n"
30932- "1: movl 64(%4), %%eax\n"
30933+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30934 " .align 2,0x90\n"
30935- "2: movl 0(%4), %%eax\n"
30936- "21: movl 4(%4), %%edx\n"
30937+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30938+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30939 " movl %%eax, 0(%3)\n"
30940 " movl %%edx, 4(%3)\n"
30941- "3: movl 8(%4), %%eax\n"
30942- "31: movl 12(%4),%%edx\n"
30943+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30944+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30945 " movl %%eax, 8(%3)\n"
30946 " movl %%edx, 12(%3)\n"
30947- "4: movl 16(%4), %%eax\n"
30948- "41: movl 20(%4), %%edx\n"
30949+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30950+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30951 " movl %%eax, 16(%3)\n"
30952 " movl %%edx, 20(%3)\n"
30953- "10: movl 24(%4), %%eax\n"
30954- "51: movl 28(%4), %%edx\n"
30955+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30956+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30957 " movl %%eax, 24(%3)\n"
30958 " movl %%edx, 28(%3)\n"
30959- "11: movl 32(%4), %%eax\n"
30960- "61: movl 36(%4), %%edx\n"
30961+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30962+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30963 " movl %%eax, 32(%3)\n"
30964 " movl %%edx, 36(%3)\n"
30965- "12: movl 40(%4), %%eax\n"
30966- "71: movl 44(%4), %%edx\n"
30967+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30968+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30969 " movl %%eax, 40(%3)\n"
30970 " movl %%edx, 44(%3)\n"
30971- "13: movl 48(%4), %%eax\n"
30972- "81: movl 52(%4), %%edx\n"
30973+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30974+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30975 " movl %%eax, 48(%3)\n"
30976 " movl %%edx, 52(%3)\n"
30977- "14: movl 56(%4), %%eax\n"
30978- "91: movl 60(%4), %%edx\n"
30979+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30980+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30981 " movl %%eax, 56(%3)\n"
30982 " movl %%edx, 60(%3)\n"
30983 " addl $-64, %0\n"
30984@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30985 " shrl $2, %0\n"
30986 " andl $3, %%eax\n"
30987 " cld\n"
30988- "6: rep; movsl\n"
30989+ "6: rep; "__copyuser_seg" movsl\n"
30990 " movl %%eax,%0\n"
30991- "7: rep; movsb\n"
30992+ "7: rep; "__copyuser_seg" movsb\n"
30993 "8:\n"
30994 ".section .fixup,\"ax\"\n"
30995 "9: lea 0(%%eax,%0,4),%0\n"
30996@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30997
30998 __asm__ __volatile__(
30999 " .align 2,0x90\n"
31000- "0: movl 32(%4), %%eax\n"
31001+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31002 " cmpl $67, %0\n"
31003 " jbe 2f\n"
31004- "1: movl 64(%4), %%eax\n"
31005+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31006 " .align 2,0x90\n"
31007- "2: movl 0(%4), %%eax\n"
31008- "21: movl 4(%4), %%edx\n"
31009+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31010+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31011 " movnti %%eax, 0(%3)\n"
31012 " movnti %%edx, 4(%3)\n"
31013- "3: movl 8(%4), %%eax\n"
31014- "31: movl 12(%4),%%edx\n"
31015+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31016+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31017 " movnti %%eax, 8(%3)\n"
31018 " movnti %%edx, 12(%3)\n"
31019- "4: movl 16(%4), %%eax\n"
31020- "41: movl 20(%4), %%edx\n"
31021+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31022+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31023 " movnti %%eax, 16(%3)\n"
31024 " movnti %%edx, 20(%3)\n"
31025- "10: movl 24(%4), %%eax\n"
31026- "51: movl 28(%4), %%edx\n"
31027+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31028+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31029 " movnti %%eax, 24(%3)\n"
31030 " movnti %%edx, 28(%3)\n"
31031- "11: movl 32(%4), %%eax\n"
31032- "61: movl 36(%4), %%edx\n"
31033+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31034+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31035 " movnti %%eax, 32(%3)\n"
31036 " movnti %%edx, 36(%3)\n"
31037- "12: movl 40(%4), %%eax\n"
31038- "71: movl 44(%4), %%edx\n"
31039+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31040+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31041 " movnti %%eax, 40(%3)\n"
31042 " movnti %%edx, 44(%3)\n"
31043- "13: movl 48(%4), %%eax\n"
31044- "81: movl 52(%4), %%edx\n"
31045+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31046+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31047 " movnti %%eax, 48(%3)\n"
31048 " movnti %%edx, 52(%3)\n"
31049- "14: movl 56(%4), %%eax\n"
31050- "91: movl 60(%4), %%edx\n"
31051+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31052+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31053 " movnti %%eax, 56(%3)\n"
31054 " movnti %%edx, 60(%3)\n"
31055 " addl $-64, %0\n"
31056@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31057 " shrl $2, %0\n"
31058 " andl $3, %%eax\n"
31059 " cld\n"
31060- "6: rep; movsl\n"
31061+ "6: rep; "__copyuser_seg" movsl\n"
31062 " movl %%eax,%0\n"
31063- "7: rep; movsb\n"
31064+ "7: rep; "__copyuser_seg" movsb\n"
31065 "8:\n"
31066 ".section .fixup,\"ax\"\n"
31067 "9: lea 0(%%eax,%0,4),%0\n"
31068@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31069
31070 __asm__ __volatile__(
31071 " .align 2,0x90\n"
31072- "0: movl 32(%4), %%eax\n"
31073+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31074 " cmpl $67, %0\n"
31075 " jbe 2f\n"
31076- "1: movl 64(%4), %%eax\n"
31077+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31078 " .align 2,0x90\n"
31079- "2: movl 0(%4), %%eax\n"
31080- "21: movl 4(%4), %%edx\n"
31081+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31082+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31083 " movnti %%eax, 0(%3)\n"
31084 " movnti %%edx, 4(%3)\n"
31085- "3: movl 8(%4), %%eax\n"
31086- "31: movl 12(%4),%%edx\n"
31087+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31088+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31089 " movnti %%eax, 8(%3)\n"
31090 " movnti %%edx, 12(%3)\n"
31091- "4: movl 16(%4), %%eax\n"
31092- "41: movl 20(%4), %%edx\n"
31093+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31094+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31095 " movnti %%eax, 16(%3)\n"
31096 " movnti %%edx, 20(%3)\n"
31097- "10: movl 24(%4), %%eax\n"
31098- "51: movl 28(%4), %%edx\n"
31099+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31100+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31101 " movnti %%eax, 24(%3)\n"
31102 " movnti %%edx, 28(%3)\n"
31103- "11: movl 32(%4), %%eax\n"
31104- "61: movl 36(%4), %%edx\n"
31105+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31106+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31107 " movnti %%eax, 32(%3)\n"
31108 " movnti %%edx, 36(%3)\n"
31109- "12: movl 40(%4), %%eax\n"
31110- "71: movl 44(%4), %%edx\n"
31111+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31112+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31113 " movnti %%eax, 40(%3)\n"
31114 " movnti %%edx, 44(%3)\n"
31115- "13: movl 48(%4), %%eax\n"
31116- "81: movl 52(%4), %%edx\n"
31117+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31118+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31119 " movnti %%eax, 48(%3)\n"
31120 " movnti %%edx, 52(%3)\n"
31121- "14: movl 56(%4), %%eax\n"
31122- "91: movl 60(%4), %%edx\n"
31123+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31124+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31125 " movnti %%eax, 56(%3)\n"
31126 " movnti %%edx, 60(%3)\n"
31127 " addl $-64, %0\n"
31128@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31129 " shrl $2, %0\n"
31130 " andl $3, %%eax\n"
31131 " cld\n"
31132- "6: rep; movsl\n"
31133+ "6: rep; "__copyuser_seg" movsl\n"
31134 " movl %%eax,%0\n"
31135- "7: rep; movsb\n"
31136+ "7: rep; "__copyuser_seg" movsb\n"
31137 "8:\n"
31138 ".section .fixup,\"ax\"\n"
31139 "9: lea 0(%%eax,%0,4),%0\n"
31140@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31141 */
31142 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31143 unsigned long size);
31144-unsigned long __copy_user_intel(void __user *to, const void *from,
31145+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31146+ unsigned long size);
31147+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31148 unsigned long size);
31149 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31150 const void __user *from, unsigned long size);
31151 #endif /* CONFIG_X86_INTEL_USERCOPY */
31152
31153 /* Generic arbitrary sized copy. */
31154-#define __copy_user(to, from, size) \
31155+#define __copy_user(to, from, size, prefix, set, restore) \
31156 do { \
31157 int __d0, __d1, __d2; \
31158 __asm__ __volatile__( \
31159+ set \
31160 " cmp $7,%0\n" \
31161 " jbe 1f\n" \
31162 " movl %1,%0\n" \
31163 " negl %0\n" \
31164 " andl $7,%0\n" \
31165 " subl %0,%3\n" \
31166- "4: rep; movsb\n" \
31167+ "4: rep; "prefix"movsb\n" \
31168 " movl %3,%0\n" \
31169 " shrl $2,%0\n" \
31170 " andl $3,%3\n" \
31171 " .align 2,0x90\n" \
31172- "0: rep; movsl\n" \
31173+ "0: rep; "prefix"movsl\n" \
31174 " movl %3,%0\n" \
31175- "1: rep; movsb\n" \
31176+ "1: rep; "prefix"movsb\n" \
31177 "2:\n" \
31178+ restore \
31179 ".section .fixup,\"ax\"\n" \
31180 "5: addl %3,%0\n" \
31181 " jmp 2b\n" \
31182@@ -538,14 +650,14 @@ do { \
31183 " negl %0\n" \
31184 " andl $7,%0\n" \
31185 " subl %0,%3\n" \
31186- "4: rep; movsb\n" \
31187+ "4: rep; "__copyuser_seg"movsb\n" \
31188 " movl %3,%0\n" \
31189 " shrl $2,%0\n" \
31190 " andl $3,%3\n" \
31191 " .align 2,0x90\n" \
31192- "0: rep; movsl\n" \
31193+ "0: rep; "__copyuser_seg"movsl\n" \
31194 " movl %3,%0\n" \
31195- "1: rep; movsb\n" \
31196+ "1: rep; "__copyuser_seg"movsb\n" \
31197 "2:\n" \
31198 ".section .fixup,\"ax\"\n" \
31199 "5: addl %3,%0\n" \
31200@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31201 {
31202 stac();
31203 if (movsl_is_ok(to, from, n))
31204- __copy_user(to, from, n);
31205+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31206 else
31207- n = __copy_user_intel(to, from, n);
31208+ n = __generic_copy_to_user_intel(to, from, n);
31209 clac();
31210 return n;
31211 }
31212@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31213 {
31214 stac();
31215 if (movsl_is_ok(to, from, n))
31216- __copy_user(to, from, n);
31217+ __copy_user(to, from, n, __copyuser_seg, "", "");
31218 else
31219- n = __copy_user_intel((void __user *)to,
31220- (const void *)from, n);
31221+ n = __generic_copy_from_user_intel(to, from, n);
31222 clac();
31223 return n;
31224 }
31225@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31226 if (n > 64 && cpu_has_xmm2)
31227 n = __copy_user_intel_nocache(to, from, n);
31228 else
31229- __copy_user(to, from, n);
31230+ __copy_user(to, from, n, __copyuser_seg, "", "");
31231 #else
31232- __copy_user(to, from, n);
31233+ __copy_user(to, from, n, __copyuser_seg, "", "");
31234 #endif
31235 clac();
31236 return n;
31237 }
31238 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31239
31240-/**
31241- * copy_to_user: - Copy a block of data into user space.
31242- * @to: Destination address, in user space.
31243- * @from: Source address, in kernel space.
31244- * @n: Number of bytes to copy.
31245- *
31246- * Context: User context only. This function may sleep.
31247- *
31248- * Copy data from kernel space to user space.
31249- *
31250- * Returns number of bytes that could not be copied.
31251- * On success, this will be zero.
31252- */
31253-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31254+#ifdef CONFIG_PAX_MEMORY_UDEREF
31255+void __set_fs(mm_segment_t x)
31256 {
31257- if (access_ok(VERIFY_WRITE, to, n))
31258- n = __copy_to_user(to, from, n);
31259- return n;
31260+ switch (x.seg) {
31261+ case 0:
31262+ loadsegment(gs, 0);
31263+ break;
31264+ case TASK_SIZE_MAX:
31265+ loadsegment(gs, __USER_DS);
31266+ break;
31267+ case -1UL:
31268+ loadsegment(gs, __KERNEL_DS);
31269+ break;
31270+ default:
31271+ BUG();
31272+ }
31273 }
31274-EXPORT_SYMBOL(_copy_to_user);
31275+EXPORT_SYMBOL(__set_fs);
31276
31277-/**
31278- * copy_from_user: - Copy a block of data from user space.
31279- * @to: Destination address, in kernel space.
31280- * @from: Source address, in user space.
31281- * @n: Number of bytes to copy.
31282- *
31283- * Context: User context only. This function may sleep.
31284- *
31285- * Copy data from user space to kernel space.
31286- *
31287- * Returns number of bytes that could not be copied.
31288- * On success, this will be zero.
31289- *
31290- * If some data could not be copied, this function will pad the copied
31291- * data to the requested size using zero bytes.
31292- */
31293-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31294+void set_fs(mm_segment_t x)
31295 {
31296- if (access_ok(VERIFY_READ, from, n))
31297- n = __copy_from_user(to, from, n);
31298- else
31299- memset(to, 0, n);
31300- return n;
31301+ current_thread_info()->addr_limit = x;
31302+ __set_fs(x);
31303 }
31304-EXPORT_SYMBOL(_copy_from_user);
31305+EXPORT_SYMBOL(set_fs);
31306+#endif
31307diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31308index c905e89..01ab928 100644
31309--- a/arch/x86/lib/usercopy_64.c
31310+++ b/arch/x86/lib/usercopy_64.c
31311@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31312 might_fault();
31313 /* no memory constraint because it doesn't change any memory gcc knows
31314 about */
31315+ pax_open_userland();
31316 stac();
31317 asm volatile(
31318 " testq %[size8],%[size8]\n"
31319@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31320 _ASM_EXTABLE(0b,3b)
31321 _ASM_EXTABLE(1b,2b)
31322 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31323- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31324+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31325 [zero] "r" (0UL), [eight] "r" (8UL));
31326 clac();
31327+ pax_close_userland();
31328 return size;
31329 }
31330 EXPORT_SYMBOL(__clear_user);
31331@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31332 }
31333 EXPORT_SYMBOL(clear_user);
31334
31335-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31336+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31337 {
31338- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31339- return copy_user_generic((__force void *)to, (__force void *)from, len);
31340- }
31341- return len;
31342+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31343+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31344+ return len;
31345 }
31346 EXPORT_SYMBOL(copy_in_user);
31347
31348@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31349 * it is not necessary to optimize tail handling.
31350 */
31351 __visible unsigned long
31352-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31353+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31354 {
31355 char c;
31356 unsigned zero_len;
31357
31358+ clac();
31359+ pax_close_userland();
31360 for (; len; --len, to++) {
31361 if (__get_user_nocheck(c, from++, sizeof(char)))
31362 break;
31363@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31364 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31365 if (__put_user_nocheck(c, to++, sizeof(char)))
31366 break;
31367- clac();
31368 return len;
31369 }
31370diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31371index 6a19ad9..1c48f9a 100644
31372--- a/arch/x86/mm/Makefile
31373+++ b/arch/x86/mm/Makefile
31374@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31375 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31376
31377 obj-$(CONFIG_MEMTEST) += memtest.o
31378+
31379+quote:="
31380+obj-$(CONFIG_X86_64) += uderef_64.o
31381+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31382diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31383index 903ec1e..c4166b2 100644
31384--- a/arch/x86/mm/extable.c
31385+++ b/arch/x86/mm/extable.c
31386@@ -6,12 +6,24 @@
31387 static inline unsigned long
31388 ex_insn_addr(const struct exception_table_entry *x)
31389 {
31390- return (unsigned long)&x->insn + x->insn;
31391+ unsigned long reloc = 0;
31392+
31393+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31394+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31395+#endif
31396+
31397+ return (unsigned long)&x->insn + x->insn + reloc;
31398 }
31399 static inline unsigned long
31400 ex_fixup_addr(const struct exception_table_entry *x)
31401 {
31402- return (unsigned long)&x->fixup + x->fixup;
31403+ unsigned long reloc = 0;
31404+
31405+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31406+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31407+#endif
31408+
31409+ return (unsigned long)&x->fixup + x->fixup + reloc;
31410 }
31411
31412 int fixup_exception(struct pt_regs *regs)
31413@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31414 unsigned long new_ip;
31415
31416 #ifdef CONFIG_PNPBIOS
31417- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31418+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31419 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31420 extern u32 pnp_bios_is_utter_crap;
31421 pnp_bios_is_utter_crap = 1;
31422@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31423 i += 4;
31424 p->fixup -= i;
31425 i += 4;
31426+
31427+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31428+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31429+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31430+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31431+#endif
31432+
31433 }
31434 }
31435
31436diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31437index 8e57229..31cce89 100644
31438--- a/arch/x86/mm/fault.c
31439+++ b/arch/x86/mm/fault.c
31440@@ -14,11 +14,18 @@
31441 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31442 #include <linux/prefetch.h> /* prefetchw */
31443 #include <linux/context_tracking.h> /* exception_enter(), ... */
31444+#include <linux/unistd.h>
31445+#include <linux/compiler.h>
31446
31447 #include <asm/traps.h> /* dotraplinkage, ... */
31448 #include <asm/pgalloc.h> /* pgd_*(), ... */
31449 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31450 #include <asm/fixmap.h> /* VSYSCALL_START */
31451+#include <asm/tlbflush.h>
31452+
31453+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31454+#include <asm/stacktrace.h>
31455+#endif
31456
31457 #define CREATE_TRACE_POINTS
31458 #include <asm/trace/exceptions.h>
31459@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31460 int ret = 0;
31461
31462 /* kprobe_running() needs smp_processor_id() */
31463- if (kprobes_built_in() && !user_mode_vm(regs)) {
31464+ if (kprobes_built_in() && !user_mode(regs)) {
31465 preempt_disable();
31466 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31467 ret = 1;
31468@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31469 return !instr_lo || (instr_lo>>1) == 1;
31470 case 0x00:
31471 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31472- if (probe_kernel_address(instr, opcode))
31473+ if (user_mode(regs)) {
31474+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31475+ return 0;
31476+ } else if (probe_kernel_address(instr, opcode))
31477 return 0;
31478
31479 *prefetch = (instr_lo == 0xF) &&
31480@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31481 while (instr < max_instr) {
31482 unsigned char opcode;
31483
31484- if (probe_kernel_address(instr, opcode))
31485+ if (user_mode(regs)) {
31486+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31487+ break;
31488+ } else if (probe_kernel_address(instr, opcode))
31489 break;
31490
31491 instr++;
31492@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31493 force_sig_info(si_signo, &info, tsk);
31494 }
31495
31496+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31497+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31498+#endif
31499+
31500+#ifdef CONFIG_PAX_EMUTRAMP
31501+static int pax_handle_fetch_fault(struct pt_regs *regs);
31502+#endif
31503+
31504+#ifdef CONFIG_PAX_PAGEEXEC
31505+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31506+{
31507+ pgd_t *pgd;
31508+ pud_t *pud;
31509+ pmd_t *pmd;
31510+
31511+ pgd = pgd_offset(mm, address);
31512+ if (!pgd_present(*pgd))
31513+ return NULL;
31514+ pud = pud_offset(pgd, address);
31515+ if (!pud_present(*pud))
31516+ return NULL;
31517+ pmd = pmd_offset(pud, address);
31518+ if (!pmd_present(*pmd))
31519+ return NULL;
31520+ return pmd;
31521+}
31522+#endif
31523+
31524 DEFINE_SPINLOCK(pgd_lock);
31525 LIST_HEAD(pgd_list);
31526
31527@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31528 for (address = VMALLOC_START & PMD_MASK;
31529 address >= TASK_SIZE && address < FIXADDR_TOP;
31530 address += PMD_SIZE) {
31531+
31532+#ifdef CONFIG_PAX_PER_CPU_PGD
31533+ unsigned long cpu;
31534+#else
31535 struct page *page;
31536+#endif
31537
31538 spin_lock(&pgd_lock);
31539+
31540+#ifdef CONFIG_PAX_PER_CPU_PGD
31541+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31542+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31543+ pmd_t *ret;
31544+
31545+ ret = vmalloc_sync_one(pgd, address);
31546+ if (!ret)
31547+ break;
31548+ pgd = get_cpu_pgd(cpu, kernel);
31549+#else
31550 list_for_each_entry(page, &pgd_list, lru) {
31551+ pgd_t *pgd;
31552 spinlock_t *pgt_lock;
31553 pmd_t *ret;
31554
31555@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31556 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31557
31558 spin_lock(pgt_lock);
31559- ret = vmalloc_sync_one(page_address(page), address);
31560+ pgd = page_address(page);
31561+#endif
31562+
31563+ ret = vmalloc_sync_one(pgd, address);
31564+
31565+#ifndef CONFIG_PAX_PER_CPU_PGD
31566 spin_unlock(pgt_lock);
31567+#endif
31568
31569 if (!ret)
31570 break;
31571@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31572 * an interrupt in the middle of a task switch..
31573 */
31574 pgd_paddr = read_cr3();
31575+
31576+#ifdef CONFIG_PAX_PER_CPU_PGD
31577+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31578+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31579+#endif
31580+
31581 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31582 if (!pmd_k)
31583 return -1;
31584@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31585 * happen within a race in page table update. In the later
31586 * case just flush:
31587 */
31588- pgd = pgd_offset(current->active_mm, address);
31589+
31590 pgd_ref = pgd_offset_k(address);
31591 if (pgd_none(*pgd_ref))
31592 return -1;
31593
31594+#ifdef CONFIG_PAX_PER_CPU_PGD
31595+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31596+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31597+ if (pgd_none(*pgd)) {
31598+ set_pgd(pgd, *pgd_ref);
31599+ arch_flush_lazy_mmu_mode();
31600+ } else {
31601+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31602+ }
31603+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31604+#else
31605+ pgd = pgd_offset(current->active_mm, address);
31606+#endif
31607+
31608 if (pgd_none(*pgd)) {
31609 set_pgd(pgd, *pgd_ref);
31610 arch_flush_lazy_mmu_mode();
31611@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31612 static int is_errata100(struct pt_regs *regs, unsigned long address)
31613 {
31614 #ifdef CONFIG_X86_64
31615- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31616+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31617 return 1;
31618 #endif
31619 return 0;
31620@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31621 }
31622
31623 static const char nx_warning[] = KERN_CRIT
31624-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31625+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31626
31627 static void
31628 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31629@@ -582,7 +666,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31630 if (!oops_may_print())
31631 return;
31632
31633- if (error_code & PF_INSTR) {
31634+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31635 unsigned int level;
31636 pgd_t *pgd;
31637 pte_t *pte;
31638@@ -593,9 +677,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31639 pte = lookup_address_in_pgd(pgd, address, &level);
31640
31641 if (pte && pte_present(*pte) && !pte_exec(*pte))
31642- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31643+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31644 }
31645
31646+#ifdef CONFIG_PAX_KERNEXEC
31647+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31648+ if (current->signal->curr_ip)
31649+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31650+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31651+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31652+ else
31653+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31654+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31655+ }
31656+#endif
31657+
31658 printk(KERN_ALERT "BUG: unable to handle kernel ");
31659 if (address < PAGE_SIZE)
31660 printk(KERN_CONT "NULL pointer dereference");
31661@@ -776,6 +872,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31662 return;
31663 }
31664 #endif
31665+
31666+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31667+ if (pax_is_fetch_fault(regs, error_code, address)) {
31668+
31669+#ifdef CONFIG_PAX_EMUTRAMP
31670+ switch (pax_handle_fetch_fault(regs)) {
31671+ case 2:
31672+ return;
31673+ }
31674+#endif
31675+
31676+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31677+ do_group_exit(SIGKILL);
31678+ }
31679+#endif
31680+
31681 /* Kernel addresses are always protection faults: */
31682 if (address >= TASK_SIZE)
31683 error_code |= PF_PROT;
31684@@ -861,7 +973,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31685 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31686 printk(KERN_ERR
31687 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31688- tsk->comm, tsk->pid, address);
31689+ tsk->comm, task_pid_nr(tsk), address);
31690 code = BUS_MCEERR_AR;
31691 }
31692 #endif
31693@@ -915,6 +1027,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31694 return 1;
31695 }
31696
31697+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31698+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31699+{
31700+ pte_t *pte;
31701+ pmd_t *pmd;
31702+ spinlock_t *ptl;
31703+ unsigned char pte_mask;
31704+
31705+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31706+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31707+ return 0;
31708+
31709+ /* PaX: it's our fault, let's handle it if we can */
31710+
31711+ /* PaX: take a look at read faults before acquiring any locks */
31712+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31713+ /* instruction fetch attempt from a protected page in user mode */
31714+ up_read(&mm->mmap_sem);
31715+
31716+#ifdef CONFIG_PAX_EMUTRAMP
31717+ switch (pax_handle_fetch_fault(regs)) {
31718+ case 2:
31719+ return 1;
31720+ }
31721+#endif
31722+
31723+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31724+ do_group_exit(SIGKILL);
31725+ }
31726+
31727+ pmd = pax_get_pmd(mm, address);
31728+ if (unlikely(!pmd))
31729+ return 0;
31730+
31731+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31732+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31733+ pte_unmap_unlock(pte, ptl);
31734+ return 0;
31735+ }
31736+
31737+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31738+ /* write attempt to a protected page in user mode */
31739+ pte_unmap_unlock(pte, ptl);
31740+ return 0;
31741+ }
31742+
31743+#ifdef CONFIG_SMP
31744+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31745+#else
31746+ if (likely(address > get_limit(regs->cs)))
31747+#endif
31748+ {
31749+ set_pte(pte, pte_mkread(*pte));
31750+ __flush_tlb_one(address);
31751+ pte_unmap_unlock(pte, ptl);
31752+ up_read(&mm->mmap_sem);
31753+ return 1;
31754+ }
31755+
31756+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31757+
31758+ /*
31759+ * PaX: fill DTLB with user rights and retry
31760+ */
31761+ __asm__ __volatile__ (
31762+ "orb %2,(%1)\n"
31763+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31764+/*
31765+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31766+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31767+ * page fault when examined during a TLB load attempt. this is true not only
31768+ * for PTEs holding a non-present entry but also present entries that will
31769+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31770+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31771+ * for our target pages since their PTEs are simply not in the TLBs at all.
31772+
31773+ * the best thing in omitting it is that we gain around 15-20% speed in the
31774+ * fast path of the page fault handler and can get rid of tracing since we
31775+ * can no longer flush unintended entries.
31776+ */
31777+ "invlpg (%0)\n"
31778+#endif
31779+ __copyuser_seg"testb $0,(%0)\n"
31780+ "xorb %3,(%1)\n"
31781+ :
31782+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31783+ : "memory", "cc");
31784+ pte_unmap_unlock(pte, ptl);
31785+ up_read(&mm->mmap_sem);
31786+ return 1;
31787+}
31788+#endif
31789+
31790 /*
31791 * Handle a spurious fault caused by a stale TLB entry.
31792 *
31793@@ -981,6 +1186,9 @@ int show_unhandled_signals = 1;
31794 static inline int
31795 access_error(unsigned long error_code, struct vm_area_struct *vma)
31796 {
31797+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31798+ return 1;
31799+
31800 if (error_code & PF_WRITE) {
31801 /* write, present and write, not present: */
31802 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31803@@ -1015,7 +1223,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31804 if (error_code & PF_USER)
31805 return false;
31806
31807- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31808+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31809 return false;
31810
31811 return true;
31812@@ -1043,6 +1251,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31813 tsk = current;
31814 mm = tsk->mm;
31815
31816+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31817+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31818+ if (!search_exception_tables(regs->ip)) {
31819+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31820+ bad_area_nosemaphore(regs, error_code, address);
31821+ return;
31822+ }
31823+ if (address < pax_user_shadow_base) {
31824+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31825+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31826+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31827+ } else
31828+ address -= pax_user_shadow_base;
31829+ }
31830+#endif
31831+
31832 /*
31833 * Detect and handle instructions that would cause a page fault for
31834 * both a tracked kernel page and a userspace page.
31835@@ -1120,7 +1344,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31836 * User-mode registers count as a user access even for any
31837 * potential system fault or CPU buglet:
31838 */
31839- if (user_mode_vm(regs)) {
31840+ if (user_mode(regs)) {
31841 local_irq_enable();
31842 error_code |= PF_USER;
31843 flags |= FAULT_FLAG_USER;
31844@@ -1167,6 +1391,11 @@ retry:
31845 might_sleep();
31846 }
31847
31848+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31849+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31850+ return;
31851+#endif
31852+
31853 vma = find_vma(mm, address);
31854 if (unlikely(!vma)) {
31855 bad_area(regs, error_code, address);
31856@@ -1178,18 +1407,24 @@ retry:
31857 bad_area(regs, error_code, address);
31858 return;
31859 }
31860- if (error_code & PF_USER) {
31861- /*
31862- * Accessing the stack below %sp is always a bug.
31863- * The large cushion allows instructions like enter
31864- * and pusha to work. ("enter $65535, $31" pushes
31865- * 32 pointers and then decrements %sp by 65535.)
31866- */
31867- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31868- bad_area(regs, error_code, address);
31869- return;
31870- }
31871+ /*
31872+ * Accessing the stack below %sp is always a bug.
31873+ * The large cushion allows instructions like enter
31874+ * and pusha to work. ("enter $65535, $31" pushes
31875+ * 32 pointers and then decrements %sp by 65535.)
31876+ */
31877+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31878+ bad_area(regs, error_code, address);
31879+ return;
31880 }
31881+
31882+#ifdef CONFIG_PAX_SEGMEXEC
31883+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31884+ bad_area(regs, error_code, address);
31885+ return;
31886+ }
31887+#endif
31888+
31889 if (unlikely(expand_stack(vma, address))) {
31890 bad_area(regs, error_code, address);
31891 return;
31892@@ -1301,3 +1536,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31893 exception_exit(prev_state);
31894 }
31895 #endif /* CONFIG_TRACING */
31896+
31897+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31898+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31899+{
31900+ struct mm_struct *mm = current->mm;
31901+ unsigned long ip = regs->ip;
31902+
31903+ if (v8086_mode(regs))
31904+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31905+
31906+#ifdef CONFIG_PAX_PAGEEXEC
31907+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31908+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31909+ return true;
31910+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31911+ return true;
31912+ return false;
31913+ }
31914+#endif
31915+
31916+#ifdef CONFIG_PAX_SEGMEXEC
31917+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31918+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31919+ return true;
31920+ return false;
31921+ }
31922+#endif
31923+
31924+ return false;
31925+}
31926+#endif
31927+
31928+#ifdef CONFIG_PAX_EMUTRAMP
31929+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31930+{
31931+ int err;
31932+
31933+ do { /* PaX: libffi trampoline emulation */
31934+ unsigned char mov, jmp;
31935+ unsigned int addr1, addr2;
31936+
31937+#ifdef CONFIG_X86_64
31938+ if ((regs->ip + 9) >> 32)
31939+ break;
31940+#endif
31941+
31942+ err = get_user(mov, (unsigned char __user *)regs->ip);
31943+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31944+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31945+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31946+
31947+ if (err)
31948+ break;
31949+
31950+ if (mov == 0xB8 && jmp == 0xE9) {
31951+ regs->ax = addr1;
31952+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31953+ return 2;
31954+ }
31955+ } while (0);
31956+
31957+ do { /* PaX: gcc trampoline emulation #1 */
31958+ unsigned char mov1, mov2;
31959+ unsigned short jmp;
31960+ unsigned int addr1, addr2;
31961+
31962+#ifdef CONFIG_X86_64
31963+ if ((regs->ip + 11) >> 32)
31964+ break;
31965+#endif
31966+
31967+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31968+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31969+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31970+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31971+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31972+
31973+ if (err)
31974+ break;
31975+
31976+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31977+ regs->cx = addr1;
31978+ regs->ax = addr2;
31979+ regs->ip = addr2;
31980+ return 2;
31981+ }
31982+ } while (0);
31983+
31984+ do { /* PaX: gcc trampoline emulation #2 */
31985+ unsigned char mov, jmp;
31986+ unsigned int addr1, addr2;
31987+
31988+#ifdef CONFIG_X86_64
31989+ if ((regs->ip + 9) >> 32)
31990+ break;
31991+#endif
31992+
31993+ err = get_user(mov, (unsigned char __user *)regs->ip);
31994+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31995+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31996+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31997+
31998+ if (err)
31999+ break;
32000+
32001+ if (mov == 0xB9 && jmp == 0xE9) {
32002+ regs->cx = addr1;
32003+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32004+ return 2;
32005+ }
32006+ } while (0);
32007+
32008+ return 1; /* PaX in action */
32009+}
32010+
32011+#ifdef CONFIG_X86_64
32012+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32013+{
32014+ int err;
32015+
32016+ do { /* PaX: libffi trampoline emulation */
32017+ unsigned short mov1, mov2, jmp1;
32018+ unsigned char stcclc, jmp2;
32019+ unsigned long addr1, addr2;
32020+
32021+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32022+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32023+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32024+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32025+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32026+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32027+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32028+
32029+ if (err)
32030+ break;
32031+
32032+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32033+ regs->r11 = addr1;
32034+ regs->r10 = addr2;
32035+ if (stcclc == 0xF8)
32036+ regs->flags &= ~X86_EFLAGS_CF;
32037+ else
32038+ regs->flags |= X86_EFLAGS_CF;
32039+ regs->ip = addr1;
32040+ return 2;
32041+ }
32042+ } while (0);
32043+
32044+ do { /* PaX: gcc trampoline emulation #1 */
32045+ unsigned short mov1, mov2, jmp1;
32046+ unsigned char jmp2;
32047+ unsigned int addr1;
32048+ unsigned long addr2;
32049+
32050+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32051+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32052+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32053+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32054+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32055+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32056+
32057+ if (err)
32058+ break;
32059+
32060+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32061+ regs->r11 = addr1;
32062+ regs->r10 = addr2;
32063+ regs->ip = addr1;
32064+ return 2;
32065+ }
32066+ } while (0);
32067+
32068+ do { /* PaX: gcc trampoline emulation #2 */
32069+ unsigned short mov1, mov2, jmp1;
32070+ unsigned char jmp2;
32071+ unsigned long addr1, addr2;
32072+
32073+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32074+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32075+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32076+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32077+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32078+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32079+
32080+ if (err)
32081+ break;
32082+
32083+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32084+ regs->r11 = addr1;
32085+ regs->r10 = addr2;
32086+ regs->ip = addr1;
32087+ return 2;
32088+ }
32089+ } while (0);
32090+
32091+ return 1; /* PaX in action */
32092+}
32093+#endif
32094+
32095+/*
32096+ * PaX: decide what to do with offenders (regs->ip = fault address)
32097+ *
32098+ * returns 1 when task should be killed
32099+ * 2 when gcc trampoline was detected
32100+ */
32101+static int pax_handle_fetch_fault(struct pt_regs *regs)
32102+{
32103+ if (v8086_mode(regs))
32104+ return 1;
32105+
32106+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32107+ return 1;
32108+
32109+#ifdef CONFIG_X86_32
32110+ return pax_handle_fetch_fault_32(regs);
32111+#else
32112+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32113+ return pax_handle_fetch_fault_32(regs);
32114+ else
32115+ return pax_handle_fetch_fault_64(regs);
32116+#endif
32117+}
32118+#endif
32119+
32120+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32121+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32122+{
32123+ long i;
32124+
32125+ printk(KERN_ERR "PAX: bytes at PC: ");
32126+ for (i = 0; i < 20; i++) {
32127+ unsigned char c;
32128+ if (get_user(c, (unsigned char __force_user *)pc+i))
32129+ printk(KERN_CONT "?? ");
32130+ else
32131+ printk(KERN_CONT "%02x ", c);
32132+ }
32133+ printk("\n");
32134+
32135+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32136+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32137+ unsigned long c;
32138+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32139+#ifdef CONFIG_X86_32
32140+ printk(KERN_CONT "???????? ");
32141+#else
32142+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32143+ printk(KERN_CONT "???????? ???????? ");
32144+ else
32145+ printk(KERN_CONT "???????????????? ");
32146+#endif
32147+ } else {
32148+#ifdef CONFIG_X86_64
32149+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32150+ printk(KERN_CONT "%08x ", (unsigned int)c);
32151+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32152+ } else
32153+#endif
32154+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32155+ }
32156+ }
32157+ printk("\n");
32158+}
32159+#endif
32160+
32161+/**
32162+ * probe_kernel_write(): safely attempt to write to a location
32163+ * @dst: address to write to
32164+ * @src: pointer to the data that shall be written
32165+ * @size: size of the data chunk
32166+ *
32167+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32168+ * happens, handle that and return -EFAULT.
32169+ */
32170+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32171+{
32172+ long ret;
32173+ mm_segment_t old_fs = get_fs();
32174+
32175+ set_fs(KERNEL_DS);
32176+ pagefault_disable();
32177+ pax_open_kernel();
32178+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32179+ pax_close_kernel();
32180+ pagefault_enable();
32181+ set_fs(old_fs);
32182+
32183+ return ret ? -EFAULT : 0;
32184+}
32185diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32186index 207d9aef..69030980 100644
32187--- a/arch/x86/mm/gup.c
32188+++ b/arch/x86/mm/gup.c
32189@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32190 addr = start;
32191 len = (unsigned long) nr_pages << PAGE_SHIFT;
32192 end = start + len;
32193- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32194+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32195 (void __user *)start, len)))
32196 return 0;
32197
32198@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32199 goto slow_irqon;
32200 #endif
32201
32202+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32203+ (void __user *)start, len)))
32204+ return 0;
32205+
32206 /*
32207 * XXX: batch / limit 'nr', to avoid large irq off latency
32208 * needs some instrumenting to determine the common sizes used by
32209diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32210index 4500142..53a363c 100644
32211--- a/arch/x86/mm/highmem_32.c
32212+++ b/arch/x86/mm/highmem_32.c
32213@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32214 idx = type + KM_TYPE_NR*smp_processor_id();
32215 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32216 BUG_ON(!pte_none(*(kmap_pte-idx)));
32217+
32218+ pax_open_kernel();
32219 set_pte(kmap_pte-idx, mk_pte(page, prot));
32220+ pax_close_kernel();
32221+
32222 arch_flush_lazy_mmu_mode();
32223
32224 return (void *)vaddr;
32225diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32226index 8b977eb..4732c33 100644
32227--- a/arch/x86/mm/hugetlbpage.c
32228+++ b/arch/x86/mm/hugetlbpage.c
32229@@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32230 #ifdef CONFIG_HUGETLB_PAGE
32231 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32232 unsigned long addr, unsigned long len,
32233- unsigned long pgoff, unsigned long flags)
32234+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32235 {
32236 struct hstate *h = hstate_file(file);
32237 struct vm_unmapped_area_info info;
32238-
32239+
32240 info.flags = 0;
32241 info.length = len;
32242 info.low_limit = current->mm->mmap_legacy_base;
32243 info.high_limit = TASK_SIZE;
32244 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32245 info.align_offset = 0;
32246+ info.threadstack_offset = offset;
32247 return vm_unmapped_area(&info);
32248 }
32249
32250 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32251 unsigned long addr0, unsigned long len,
32252- unsigned long pgoff, unsigned long flags)
32253+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32254 {
32255 struct hstate *h = hstate_file(file);
32256 struct vm_unmapped_area_info info;
32257@@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32258 info.high_limit = current->mm->mmap_base;
32259 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32260 info.align_offset = 0;
32261+ info.threadstack_offset = offset;
32262 addr = vm_unmapped_area(&info);
32263
32264 /*
32265@@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32266 VM_BUG_ON(addr != -ENOMEM);
32267 info.flags = 0;
32268 info.low_limit = TASK_UNMAPPED_BASE;
32269+
32270+#ifdef CONFIG_PAX_RANDMMAP
32271+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32272+ info.low_limit += current->mm->delta_mmap;
32273+#endif
32274+
32275 info.high_limit = TASK_SIZE;
32276 addr = vm_unmapped_area(&info);
32277 }
32278@@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32279 struct hstate *h = hstate_file(file);
32280 struct mm_struct *mm = current->mm;
32281 struct vm_area_struct *vma;
32282+ unsigned long pax_task_size = TASK_SIZE;
32283+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32284
32285 if (len & ~huge_page_mask(h))
32286 return -EINVAL;
32287- if (len > TASK_SIZE)
32288+
32289+#ifdef CONFIG_PAX_SEGMEXEC
32290+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32291+ pax_task_size = SEGMEXEC_TASK_SIZE;
32292+#endif
32293+
32294+ pax_task_size -= PAGE_SIZE;
32295+
32296+ if (len > pax_task_size)
32297 return -ENOMEM;
32298
32299 if (flags & MAP_FIXED) {
32300@@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32301 return addr;
32302 }
32303
32304+#ifdef CONFIG_PAX_RANDMMAP
32305+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32306+#endif
32307+
32308 if (addr) {
32309 addr = ALIGN(addr, huge_page_size(h));
32310 vma = find_vma(mm, addr);
32311- if (TASK_SIZE - len >= addr &&
32312- (!vma || addr + len <= vma->vm_start))
32313+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32314 return addr;
32315 }
32316 if (mm->get_unmapped_area == arch_get_unmapped_area)
32317 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32318- pgoff, flags);
32319+ pgoff, flags, offset);
32320 else
32321 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32322- pgoff, flags);
32323+ pgoff, flags, offset);
32324 }
32325 #endif /* CONFIG_HUGETLB_PAGE */
32326
32327diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32328index f971306..e83e0f6 100644
32329--- a/arch/x86/mm/init.c
32330+++ b/arch/x86/mm/init.c
32331@@ -4,6 +4,7 @@
32332 #include <linux/swap.h>
32333 #include <linux/memblock.h>
32334 #include <linux/bootmem.h> /* for max_low_pfn */
32335+#include <linux/tboot.h>
32336
32337 #include <asm/cacheflush.h>
32338 #include <asm/e820.h>
32339@@ -17,6 +18,8 @@
32340 #include <asm/proto.h>
32341 #include <asm/dma.h> /* for MAX_DMA_PFN */
32342 #include <asm/microcode.h>
32343+#include <asm/desc.h>
32344+#include <asm/bios_ebda.h>
32345
32346 #include "mm_internal.h"
32347
32348@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32349 early_ioremap_page_table_range_init();
32350 #endif
32351
32352+#ifdef CONFIG_PAX_PER_CPU_PGD
32353+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32354+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32355+ KERNEL_PGD_PTRS);
32356+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32357+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32358+ KERNEL_PGD_PTRS);
32359+ load_cr3(get_cpu_pgd(0, kernel));
32360+#else
32361 load_cr3(swapper_pg_dir);
32362+#endif
32363+
32364 __flush_tlb_all();
32365
32366 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32367@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32368 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32369 * mmio resources as well as potential bios/acpi data regions.
32370 */
32371+
32372+#ifdef CONFIG_GRKERNSEC_KMEM
32373+static unsigned int ebda_start __read_only;
32374+static unsigned int ebda_end __read_only;
32375+#endif
32376+
32377 int devmem_is_allowed(unsigned long pagenr)
32378 {
32379- if (pagenr < 256)
32380+#ifdef CONFIG_GRKERNSEC_KMEM
32381+ /* allow BDA */
32382+ if (!pagenr)
32383 return 1;
32384+ /* allow EBDA */
32385+ if (pagenr >= ebda_start && pagenr < ebda_end)
32386+ return 1;
32387+ /* if tboot is in use, allow access to its hardcoded serial log range */
32388+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32389+ return 1;
32390+#else
32391+ if (!pagenr)
32392+ return 1;
32393+#ifdef CONFIG_VM86
32394+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32395+ return 1;
32396+#endif
32397+#endif
32398+
32399+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32400+ return 1;
32401+#ifdef CONFIG_GRKERNSEC_KMEM
32402+ /* throw out everything else below 1MB */
32403+ if (pagenr <= 256)
32404+ return 0;
32405+#endif
32406 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32407 return 0;
32408 if (!page_is_ram(pagenr))
32409@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32410 #endif
32411 }
32412
32413+#ifdef CONFIG_GRKERNSEC_KMEM
32414+static inline void gr_init_ebda(void)
32415+{
32416+ unsigned int ebda_addr;
32417+ unsigned int ebda_size = 0;
32418+
32419+ ebda_addr = get_bios_ebda();
32420+ if (ebda_addr) {
32421+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32422+ ebda_size <<= 10;
32423+ }
32424+ if (ebda_addr && ebda_size) {
32425+ ebda_start = ebda_addr >> PAGE_SHIFT;
32426+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32427+ } else {
32428+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32429+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32430+ }
32431+}
32432+#else
32433+static inline void gr_init_ebda(void) { }
32434+#endif
32435+
32436 void free_initmem(void)
32437 {
32438+#ifdef CONFIG_PAX_KERNEXEC
32439+#ifdef CONFIG_X86_32
32440+ /* PaX: limit KERNEL_CS to actual size */
32441+ unsigned long addr, limit;
32442+ struct desc_struct d;
32443+ int cpu;
32444+#else
32445+ pgd_t *pgd;
32446+ pud_t *pud;
32447+ pmd_t *pmd;
32448+ unsigned long addr, end;
32449+#endif
32450+#endif
32451+
32452+ gr_init_ebda();
32453+
32454+#ifdef CONFIG_PAX_KERNEXEC
32455+#ifdef CONFIG_X86_32
32456+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32457+ limit = (limit - 1UL) >> PAGE_SHIFT;
32458+
32459+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32460+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32461+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32462+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32463+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32464+ }
32465+
32466+ /* PaX: make KERNEL_CS read-only */
32467+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32468+ if (!paravirt_enabled())
32469+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32470+/*
32471+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32472+ pgd = pgd_offset_k(addr);
32473+ pud = pud_offset(pgd, addr);
32474+ pmd = pmd_offset(pud, addr);
32475+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32476+ }
32477+*/
32478+#ifdef CONFIG_X86_PAE
32479+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32480+/*
32481+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32482+ pgd = pgd_offset_k(addr);
32483+ pud = pud_offset(pgd, addr);
32484+ pmd = pmd_offset(pud, addr);
32485+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32486+ }
32487+*/
32488+#endif
32489+
32490+#ifdef CONFIG_MODULES
32491+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32492+#endif
32493+
32494+#else
32495+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32496+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32497+ pgd = pgd_offset_k(addr);
32498+ pud = pud_offset(pgd, addr);
32499+ pmd = pmd_offset(pud, addr);
32500+ if (!pmd_present(*pmd))
32501+ continue;
32502+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32503+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32504+ else
32505+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32506+ }
32507+
32508+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32509+ end = addr + KERNEL_IMAGE_SIZE;
32510+ for (; addr < end; addr += PMD_SIZE) {
32511+ pgd = pgd_offset_k(addr);
32512+ pud = pud_offset(pgd, addr);
32513+ pmd = pmd_offset(pud, addr);
32514+ if (!pmd_present(*pmd))
32515+ continue;
32516+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32517+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32518+ }
32519+#endif
32520+
32521+ flush_tlb_all();
32522+#endif
32523+
32524 free_init_pages("unused kernel",
32525 (unsigned long)(&__init_begin),
32526 (unsigned long)(&__init_end));
32527diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32528index e395048..cd38278 100644
32529--- a/arch/x86/mm/init_32.c
32530+++ b/arch/x86/mm/init_32.c
32531@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32532 bool __read_mostly __vmalloc_start_set = false;
32533
32534 /*
32535- * Creates a middle page table and puts a pointer to it in the
32536- * given global directory entry. This only returns the gd entry
32537- * in non-PAE compilation mode, since the middle layer is folded.
32538- */
32539-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32540-{
32541- pud_t *pud;
32542- pmd_t *pmd_table;
32543-
32544-#ifdef CONFIG_X86_PAE
32545- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32546- pmd_table = (pmd_t *)alloc_low_page();
32547- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32548- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32549- pud = pud_offset(pgd, 0);
32550- BUG_ON(pmd_table != pmd_offset(pud, 0));
32551-
32552- return pmd_table;
32553- }
32554-#endif
32555- pud = pud_offset(pgd, 0);
32556- pmd_table = pmd_offset(pud, 0);
32557-
32558- return pmd_table;
32559-}
32560-
32561-/*
32562 * Create a page table and place a pointer to it in a middle page
32563 * directory entry:
32564 */
32565@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32566 pte_t *page_table = (pte_t *)alloc_low_page();
32567
32568 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32569+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32570+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32571+#else
32572 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32573+#endif
32574 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32575 }
32576
32577 return pte_offset_kernel(pmd, 0);
32578 }
32579
32580+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32581+{
32582+ pud_t *pud;
32583+ pmd_t *pmd_table;
32584+
32585+ pud = pud_offset(pgd, 0);
32586+ pmd_table = pmd_offset(pud, 0);
32587+
32588+ return pmd_table;
32589+}
32590+
32591 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32592 {
32593 int pgd_idx = pgd_index(vaddr);
32594@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32595 int pgd_idx, pmd_idx;
32596 unsigned long vaddr;
32597 pgd_t *pgd;
32598+ pud_t *pud;
32599 pmd_t *pmd;
32600 pte_t *pte = NULL;
32601 unsigned long count = page_table_range_init_count(start, end);
32602@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32603 pgd = pgd_base + pgd_idx;
32604
32605 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32606- pmd = one_md_table_init(pgd);
32607- pmd = pmd + pmd_index(vaddr);
32608+ pud = pud_offset(pgd, vaddr);
32609+ pmd = pmd_offset(pud, vaddr);
32610+
32611+#ifdef CONFIG_X86_PAE
32612+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32613+#endif
32614+
32615 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32616 pmd++, pmd_idx++) {
32617 pte = page_table_kmap_check(one_page_table_init(pmd),
32618@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32619 }
32620 }
32621
32622-static inline int is_kernel_text(unsigned long addr)
32623+static inline int is_kernel_text(unsigned long start, unsigned long end)
32624 {
32625- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32626- return 1;
32627- return 0;
32628+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32629+ end <= ktla_ktva((unsigned long)_stext)) &&
32630+ (start >= ktla_ktva((unsigned long)_einittext) ||
32631+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32632+
32633+#ifdef CONFIG_ACPI_SLEEP
32634+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32635+#endif
32636+
32637+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32638+ return 0;
32639+ return 1;
32640 }
32641
32642 /*
32643@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32644 unsigned long last_map_addr = end;
32645 unsigned long start_pfn, end_pfn;
32646 pgd_t *pgd_base = swapper_pg_dir;
32647- int pgd_idx, pmd_idx, pte_ofs;
32648+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32649 unsigned long pfn;
32650 pgd_t *pgd;
32651+ pud_t *pud;
32652 pmd_t *pmd;
32653 pte_t *pte;
32654 unsigned pages_2m, pages_4k;
32655@@ -291,8 +295,13 @@ repeat:
32656 pfn = start_pfn;
32657 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32658 pgd = pgd_base + pgd_idx;
32659- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32660- pmd = one_md_table_init(pgd);
32661+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32662+ pud = pud_offset(pgd, 0);
32663+ pmd = pmd_offset(pud, 0);
32664+
32665+#ifdef CONFIG_X86_PAE
32666+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32667+#endif
32668
32669 if (pfn >= end_pfn)
32670 continue;
32671@@ -304,14 +313,13 @@ repeat:
32672 #endif
32673 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32674 pmd++, pmd_idx++) {
32675- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32676+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32677
32678 /*
32679 * Map with big pages if possible, otherwise
32680 * create normal page tables:
32681 */
32682 if (use_pse) {
32683- unsigned int addr2;
32684 pgprot_t prot = PAGE_KERNEL_LARGE;
32685 /*
32686 * first pass will use the same initial
32687@@ -322,11 +330,7 @@ repeat:
32688 _PAGE_PSE);
32689
32690 pfn &= PMD_MASK >> PAGE_SHIFT;
32691- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32692- PAGE_OFFSET + PAGE_SIZE-1;
32693-
32694- if (is_kernel_text(addr) ||
32695- is_kernel_text(addr2))
32696+ if (is_kernel_text(address, address + PMD_SIZE))
32697 prot = PAGE_KERNEL_LARGE_EXEC;
32698
32699 pages_2m++;
32700@@ -343,7 +347,7 @@ repeat:
32701 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32702 pte += pte_ofs;
32703 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32704- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32705+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32706 pgprot_t prot = PAGE_KERNEL;
32707 /*
32708 * first pass will use the same initial
32709@@ -351,7 +355,7 @@ repeat:
32710 */
32711 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32712
32713- if (is_kernel_text(addr))
32714+ if (is_kernel_text(address, address + PAGE_SIZE))
32715 prot = PAGE_KERNEL_EXEC;
32716
32717 pages_4k++;
32718@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32719
32720 pud = pud_offset(pgd, va);
32721 pmd = pmd_offset(pud, va);
32722- if (!pmd_present(*pmd))
32723+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32724 break;
32725
32726 /* should not be large page here */
32727@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32728
32729 static void __init pagetable_init(void)
32730 {
32731- pgd_t *pgd_base = swapper_pg_dir;
32732-
32733- permanent_kmaps_init(pgd_base);
32734+ permanent_kmaps_init(swapper_pg_dir);
32735 }
32736
32737-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32738+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32739 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32740
32741 /* user-defined highmem size */
32742@@ -787,10 +789,10 @@ void __init mem_init(void)
32743 ((unsigned long)&__init_end -
32744 (unsigned long)&__init_begin) >> 10,
32745
32746- (unsigned long)&_etext, (unsigned long)&_edata,
32747- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32748+ (unsigned long)&_sdata, (unsigned long)&_edata,
32749+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32750
32751- (unsigned long)&_text, (unsigned long)&_etext,
32752+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32753 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32754
32755 /*
32756@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32757 if (!kernel_set_to_readonly)
32758 return;
32759
32760+ start = ktla_ktva(start);
32761 pr_debug("Set kernel text: %lx - %lx for read write\n",
32762 start, start+size);
32763
32764@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32765 if (!kernel_set_to_readonly)
32766 return;
32767
32768+ start = ktla_ktva(start);
32769 pr_debug("Set kernel text: %lx - %lx for read only\n",
32770 start, start+size);
32771
32772@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32773 unsigned long start = PFN_ALIGN(_text);
32774 unsigned long size = PFN_ALIGN(_etext) - start;
32775
32776+ start = ktla_ktva(start);
32777 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32778 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32779 size >> 10);
32780diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32781index f35c66c..84b95ef 100644
32782--- a/arch/x86/mm/init_64.c
32783+++ b/arch/x86/mm/init_64.c
32784@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32785 * around without checking the pgd every time.
32786 */
32787
32788-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32789+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32790 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32791
32792 int force_personality32;
32793@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32794
32795 for (address = start; address <= end; address += PGDIR_SIZE) {
32796 const pgd_t *pgd_ref = pgd_offset_k(address);
32797+
32798+#ifdef CONFIG_PAX_PER_CPU_PGD
32799+ unsigned long cpu;
32800+#else
32801 struct page *page;
32802+#endif
32803
32804 if (pgd_none(*pgd_ref))
32805 continue;
32806
32807 spin_lock(&pgd_lock);
32808+
32809+#ifdef CONFIG_PAX_PER_CPU_PGD
32810+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32811+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32812+
32813+ if (pgd_none(*pgd))
32814+ set_pgd(pgd, *pgd_ref);
32815+ else
32816+ BUG_ON(pgd_page_vaddr(*pgd)
32817+ != pgd_page_vaddr(*pgd_ref));
32818+ pgd = pgd_offset_cpu(cpu, kernel, address);
32819+#else
32820 list_for_each_entry(page, &pgd_list, lru) {
32821 pgd_t *pgd;
32822 spinlock_t *pgt_lock;
32823@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32824 /* the pgt_lock only for Xen */
32825 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32826 spin_lock(pgt_lock);
32827+#endif
32828
32829 if (pgd_none(*pgd))
32830 set_pgd(pgd, *pgd_ref);
32831@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32832 BUG_ON(pgd_page_vaddr(*pgd)
32833 != pgd_page_vaddr(*pgd_ref));
32834
32835+#ifndef CONFIG_PAX_PER_CPU_PGD
32836 spin_unlock(pgt_lock);
32837+#endif
32838+
32839 }
32840 spin_unlock(&pgd_lock);
32841 }
32842@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32843 {
32844 if (pgd_none(*pgd)) {
32845 pud_t *pud = (pud_t *)spp_getpage();
32846- pgd_populate(&init_mm, pgd, pud);
32847+ pgd_populate_kernel(&init_mm, pgd, pud);
32848 if (pud != pud_offset(pgd, 0))
32849 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32850 pud, pud_offset(pgd, 0));
32851@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32852 {
32853 if (pud_none(*pud)) {
32854 pmd_t *pmd = (pmd_t *) spp_getpage();
32855- pud_populate(&init_mm, pud, pmd);
32856+ pud_populate_kernel(&init_mm, pud, pmd);
32857 if (pmd != pmd_offset(pud, 0))
32858 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32859 pmd, pmd_offset(pud, 0));
32860@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32861 pmd = fill_pmd(pud, vaddr);
32862 pte = fill_pte(pmd, vaddr);
32863
32864+ pax_open_kernel();
32865 set_pte(pte, new_pte);
32866+ pax_close_kernel();
32867
32868 /*
32869 * It's enough to flush this one mapping.
32870@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32871 pgd = pgd_offset_k((unsigned long)__va(phys));
32872 if (pgd_none(*pgd)) {
32873 pud = (pud_t *) spp_getpage();
32874- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32875- _PAGE_USER));
32876+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32877 }
32878 pud = pud_offset(pgd, (unsigned long)__va(phys));
32879 if (pud_none(*pud)) {
32880 pmd = (pmd_t *) spp_getpage();
32881- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32882- _PAGE_USER));
32883+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32884 }
32885 pmd = pmd_offset(pud, phys);
32886 BUG_ON(!pmd_none(*pmd));
32887@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32888 prot);
32889
32890 spin_lock(&init_mm.page_table_lock);
32891- pud_populate(&init_mm, pud, pmd);
32892+ pud_populate_kernel(&init_mm, pud, pmd);
32893 spin_unlock(&init_mm.page_table_lock);
32894 }
32895 __flush_tlb_all();
32896@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32897 page_size_mask);
32898
32899 spin_lock(&init_mm.page_table_lock);
32900- pgd_populate(&init_mm, pgd, pud);
32901+ pgd_populate_kernel(&init_mm, pgd, pud);
32902 spin_unlock(&init_mm.page_table_lock);
32903 pgd_changed = true;
32904 }
32905@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32906 static struct vm_area_struct gate_vma = {
32907 .vm_start = VSYSCALL_START,
32908 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32909- .vm_page_prot = PAGE_READONLY_EXEC,
32910- .vm_flags = VM_READ | VM_EXEC
32911+ .vm_page_prot = PAGE_READONLY,
32912+ .vm_flags = VM_READ
32913 };
32914
32915 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32916@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32917
32918 const char *arch_vma_name(struct vm_area_struct *vma)
32919 {
32920- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32921+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32922 return "[vdso]";
32923 if (vma == &gate_vma)
32924 return "[vsyscall]";
32925diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32926index 7b179b4..6bd17777 100644
32927--- a/arch/x86/mm/iomap_32.c
32928+++ b/arch/x86/mm/iomap_32.c
32929@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32930 type = kmap_atomic_idx_push();
32931 idx = type + KM_TYPE_NR * smp_processor_id();
32932 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32933+
32934+ pax_open_kernel();
32935 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32936+ pax_close_kernel();
32937+
32938 arch_flush_lazy_mmu_mode();
32939
32940 return (void *)vaddr;
32941diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32942index bc7527e..5e2c495 100644
32943--- a/arch/x86/mm/ioremap.c
32944+++ b/arch/x86/mm/ioremap.c
32945@@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
32946 unsigned long i;
32947
32948 for (i = 0; i < nr_pages; ++i)
32949- if (pfn_valid(start_pfn + i) &&
32950- !PageReserved(pfn_to_page(start_pfn + i)))
32951+ if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
32952+ !PageReserved(pfn_to_page(start_pfn + i))))
32953 return 1;
32954
32955 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
32956@@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
32957 *
32958 * Caller must ensure there is only one unmapping for the same pointer.
32959 */
32960-void iounmap(volatile void __iomem *addr)
32961+void iounmap(const volatile void __iomem *addr)
32962 {
32963 struct vm_struct *p, *o;
32964
32965@@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32966
32967 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32968 if (page_is_ram(start >> PAGE_SHIFT))
32969+#ifdef CONFIG_HIGHMEM
32970+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32971+#endif
32972 return __va(phys);
32973
32974 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32975@@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32976 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32977 {
32978 if (page_is_ram(phys >> PAGE_SHIFT))
32979+#ifdef CONFIG_HIGHMEM
32980+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32981+#endif
32982 return;
32983
32984 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32985 return;
32986 }
32987
32988-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32989+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32990
32991 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32992 {
32993@@ -370,8 +376,7 @@ void __init early_ioremap_init(void)
32994 early_ioremap_setup();
32995
32996 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32997- memset(bm_pte, 0, sizeof(bm_pte));
32998- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32999+ pmd_populate_user(&init_mm, pmd, bm_pte);
33000
33001 /*
33002 * The boot-ioremap range spans multiple pmds, for which
33003diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33004index dd89a13..d77bdcc 100644
33005--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33006+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33007@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33008 * memory (e.g. tracked pages)? For now, we need this to avoid
33009 * invoking kmemcheck for PnP BIOS calls.
33010 */
33011- if (regs->flags & X86_VM_MASK)
33012+ if (v8086_mode(regs))
33013 return false;
33014- if (regs->cs != __KERNEL_CS)
33015+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33016 return false;
33017
33018 pte = kmemcheck_pte_lookup(address);
33019diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33020index 25e7e13..1964579 100644
33021--- a/arch/x86/mm/mmap.c
33022+++ b/arch/x86/mm/mmap.c
33023@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33024 * Leave an at least ~128 MB hole with possible stack randomization.
33025 */
33026 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33027-#define MAX_GAP (TASK_SIZE/6*5)
33028+#define MAX_GAP (pax_task_size/6*5)
33029
33030 static int mmap_is_legacy(void)
33031 {
33032@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33033 return rnd << PAGE_SHIFT;
33034 }
33035
33036-static unsigned long mmap_base(void)
33037+static unsigned long mmap_base(struct mm_struct *mm)
33038 {
33039 unsigned long gap = rlimit(RLIMIT_STACK);
33040+ unsigned long pax_task_size = TASK_SIZE;
33041+
33042+#ifdef CONFIG_PAX_SEGMEXEC
33043+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33044+ pax_task_size = SEGMEXEC_TASK_SIZE;
33045+#endif
33046
33047 if (gap < MIN_GAP)
33048 gap = MIN_GAP;
33049 else if (gap > MAX_GAP)
33050 gap = MAX_GAP;
33051
33052- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33053+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33054 }
33055
33056 /*
33057 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33058 * does, but not when emulating X86_32
33059 */
33060-static unsigned long mmap_legacy_base(void)
33061+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33062 {
33063- if (mmap_is_ia32())
33064+ if (mmap_is_ia32()) {
33065+
33066+#ifdef CONFIG_PAX_SEGMEXEC
33067+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33068+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33069+ else
33070+#endif
33071+
33072 return TASK_UNMAPPED_BASE;
33073- else
33074+ } else
33075 return TASK_UNMAPPED_BASE + mmap_rnd();
33076 }
33077
33078@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33079 */
33080 void arch_pick_mmap_layout(struct mm_struct *mm)
33081 {
33082- mm->mmap_legacy_base = mmap_legacy_base();
33083- mm->mmap_base = mmap_base();
33084+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33085+ mm->mmap_base = mmap_base(mm);
33086+
33087+#ifdef CONFIG_PAX_RANDMMAP
33088+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33089+ mm->mmap_legacy_base += mm->delta_mmap;
33090+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33091+ }
33092+#endif
33093
33094 if (mmap_is_legacy()) {
33095 mm->mmap_base = mm->mmap_legacy_base;
33096diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33097index 0057a7a..95c7edd 100644
33098--- a/arch/x86/mm/mmio-mod.c
33099+++ b/arch/x86/mm/mmio-mod.c
33100@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33101 break;
33102 default:
33103 {
33104- unsigned char *ip = (unsigned char *)instptr;
33105+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33106 my_trace->opcode = MMIO_UNKNOWN_OP;
33107 my_trace->width = 0;
33108 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33109@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33110 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33111 void __iomem *addr)
33112 {
33113- static atomic_t next_id;
33114+ static atomic_unchecked_t next_id;
33115 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33116 /* These are page-unaligned. */
33117 struct mmiotrace_map map = {
33118@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33119 .private = trace
33120 },
33121 .phys = offset,
33122- .id = atomic_inc_return(&next_id)
33123+ .id = atomic_inc_return_unchecked(&next_id)
33124 };
33125 map.map_id = trace->id;
33126
33127@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33128 ioremap_trace_core(offset, size, addr);
33129 }
33130
33131-static void iounmap_trace_core(volatile void __iomem *addr)
33132+static void iounmap_trace_core(const volatile void __iomem *addr)
33133 {
33134 struct mmiotrace_map map = {
33135 .phys = 0,
33136@@ -328,7 +328,7 @@ not_enabled:
33137 }
33138 }
33139
33140-void mmiotrace_iounmap(volatile void __iomem *addr)
33141+void mmiotrace_iounmap(const volatile void __iomem *addr)
33142 {
33143 might_sleep();
33144 if (is_enabled()) /* recheck and proper locking in *_core() */
33145diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33146index 1d045f9..3a00249 100644
33147--- a/arch/x86/mm/numa.c
33148+++ b/arch/x86/mm/numa.c
33149@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33150 return true;
33151 }
33152
33153-static int __init numa_register_memblks(struct numa_meminfo *mi)
33154+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33155 {
33156 unsigned long uninitialized_var(pfn_align);
33157 int i, nid;
33158diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33159index 461bc82..4e091a3 100644
33160--- a/arch/x86/mm/pageattr-test.c
33161+++ b/arch/x86/mm/pageattr-test.c
33162@@ -35,7 +35,7 @@ enum {
33163
33164 static int pte_testbit(pte_t pte)
33165 {
33166- return pte_flags(pte) & _PAGE_UNUSED1;
33167+ return pte_flags(pte) & _PAGE_CPA_TEST;
33168 }
33169
33170 struct split_state {
33171diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33172index ae242a7..1c7998f 100644
33173--- a/arch/x86/mm/pageattr.c
33174+++ b/arch/x86/mm/pageattr.c
33175@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33176 */
33177 #ifdef CONFIG_PCI_BIOS
33178 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33179- pgprot_val(forbidden) |= _PAGE_NX;
33180+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33181 #endif
33182
33183 /*
33184@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33185 * Does not cover __inittext since that is gone later on. On
33186 * 64bit we do not enforce !NX on the low mapping
33187 */
33188- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33189- pgprot_val(forbidden) |= _PAGE_NX;
33190+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33191+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33192
33193+#ifdef CONFIG_DEBUG_RODATA
33194 /*
33195 * The .rodata section needs to be read-only. Using the pfn
33196 * catches all aliases.
33197@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33198 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33199 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33200 pgprot_val(forbidden) |= _PAGE_RW;
33201+#endif
33202
33203 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33204 /*
33205@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33206 }
33207 #endif
33208
33209+#ifdef CONFIG_PAX_KERNEXEC
33210+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33211+ pgprot_val(forbidden) |= _PAGE_RW;
33212+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33213+ }
33214+#endif
33215+
33216 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33217
33218 return prot;
33219@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33220 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33221 {
33222 /* change init_mm */
33223+ pax_open_kernel();
33224 set_pte_atomic(kpte, pte);
33225+
33226 #ifdef CONFIG_X86_32
33227 if (!SHARED_KERNEL_PMD) {
33228+
33229+#ifdef CONFIG_PAX_PER_CPU_PGD
33230+ unsigned long cpu;
33231+#else
33232 struct page *page;
33233+#endif
33234
33235+#ifdef CONFIG_PAX_PER_CPU_PGD
33236+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33237+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33238+#else
33239 list_for_each_entry(page, &pgd_list, lru) {
33240- pgd_t *pgd;
33241+ pgd_t *pgd = (pgd_t *)page_address(page);
33242+#endif
33243+
33244 pud_t *pud;
33245 pmd_t *pmd;
33246
33247- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33248+ pgd += pgd_index(address);
33249 pud = pud_offset(pgd, address);
33250 pmd = pmd_offset(pud, address);
33251 set_pte_atomic((pte_t *)pmd, pte);
33252 }
33253 }
33254 #endif
33255+ pax_close_kernel();
33256 }
33257
33258 static int
33259diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33260index 6574388..87e9bef 100644
33261--- a/arch/x86/mm/pat.c
33262+++ b/arch/x86/mm/pat.c
33263@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33264
33265 if (!entry) {
33266 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33267- current->comm, current->pid, start, end - 1);
33268+ current->comm, task_pid_nr(current), start, end - 1);
33269 return -EINVAL;
33270 }
33271
33272@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33273
33274 while (cursor < to) {
33275 if (!devmem_is_allowed(pfn)) {
33276- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33277- current->comm, from, to - 1);
33278+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33279+ current->comm, from, to - 1, cursor);
33280 return 0;
33281 }
33282 cursor += PAGE_SIZE;
33283@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33284 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33285 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33286 "for [mem %#010Lx-%#010Lx]\n",
33287- current->comm, current->pid,
33288+ current->comm, task_pid_nr(current),
33289 cattr_name(flags),
33290 base, (unsigned long long)(base + size-1));
33291 return -EINVAL;
33292@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33293 flags = lookup_memtype(paddr);
33294 if (want_flags != flags) {
33295 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33296- current->comm, current->pid,
33297+ current->comm, task_pid_nr(current),
33298 cattr_name(want_flags),
33299 (unsigned long long)paddr,
33300 (unsigned long long)(paddr + size - 1),
33301@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33302 free_memtype(paddr, paddr + size);
33303 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33304 " for [mem %#010Lx-%#010Lx], got %s\n",
33305- current->comm, current->pid,
33306+ current->comm, task_pid_nr(current),
33307 cattr_name(want_flags),
33308 (unsigned long long)paddr,
33309 (unsigned long long)(paddr + size - 1),
33310diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33311index 415f6c4..d319983 100644
33312--- a/arch/x86/mm/pat_rbtree.c
33313+++ b/arch/x86/mm/pat_rbtree.c
33314@@ -160,7 +160,7 @@ success:
33315
33316 failure:
33317 printk(KERN_INFO "%s:%d conflicting memory types "
33318- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33319+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33320 end, cattr_name(found_type), cattr_name(match->type));
33321 return -EBUSY;
33322 }
33323diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33324index 9f0614d..92ae64a 100644
33325--- a/arch/x86/mm/pf_in.c
33326+++ b/arch/x86/mm/pf_in.c
33327@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33328 int i;
33329 enum reason_type rv = OTHERS;
33330
33331- p = (unsigned char *)ins_addr;
33332+ p = (unsigned char *)ktla_ktva(ins_addr);
33333 p += skip_prefix(p, &prf);
33334 p += get_opcode(p, &opcode);
33335
33336@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33337 struct prefix_bits prf;
33338 int i;
33339
33340- p = (unsigned char *)ins_addr;
33341+ p = (unsigned char *)ktla_ktva(ins_addr);
33342 p += skip_prefix(p, &prf);
33343 p += get_opcode(p, &opcode);
33344
33345@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33346 struct prefix_bits prf;
33347 int i;
33348
33349- p = (unsigned char *)ins_addr;
33350+ p = (unsigned char *)ktla_ktva(ins_addr);
33351 p += skip_prefix(p, &prf);
33352 p += get_opcode(p, &opcode);
33353
33354@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33355 struct prefix_bits prf;
33356 int i;
33357
33358- p = (unsigned char *)ins_addr;
33359+ p = (unsigned char *)ktla_ktva(ins_addr);
33360 p += skip_prefix(p, &prf);
33361 p += get_opcode(p, &opcode);
33362 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33363@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33364 struct prefix_bits prf;
33365 int i;
33366
33367- p = (unsigned char *)ins_addr;
33368+ p = (unsigned char *)ktla_ktva(ins_addr);
33369 p += skip_prefix(p, &prf);
33370 p += get_opcode(p, &opcode);
33371 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33372diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33373index c96314a..433b127 100644
33374--- a/arch/x86/mm/pgtable.c
33375+++ b/arch/x86/mm/pgtable.c
33376@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33377 list_del(&page->lru);
33378 }
33379
33380-#define UNSHARED_PTRS_PER_PGD \
33381- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33382+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33383+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33384
33385+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33386+{
33387+ unsigned int count = USER_PGD_PTRS;
33388
33389+ if (!pax_user_shadow_base)
33390+ return;
33391+
33392+ while (count--)
33393+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33394+}
33395+#endif
33396+
33397+#ifdef CONFIG_PAX_PER_CPU_PGD
33398+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33399+{
33400+ unsigned int count = USER_PGD_PTRS;
33401+
33402+ while (count--) {
33403+ pgd_t pgd;
33404+
33405+#ifdef CONFIG_X86_64
33406+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33407+#else
33408+ pgd = *src++;
33409+#endif
33410+
33411+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33412+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33413+#endif
33414+
33415+ *dst++ = pgd;
33416+ }
33417+
33418+}
33419+#endif
33420+
33421+#ifdef CONFIG_X86_64
33422+#define pxd_t pud_t
33423+#define pyd_t pgd_t
33424+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33425+#define pgtable_pxd_page_ctor(page) true
33426+#define pgtable_pxd_page_dtor(page)
33427+#define pxd_free(mm, pud) pud_free((mm), (pud))
33428+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33429+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33430+#define PYD_SIZE PGDIR_SIZE
33431+#else
33432+#define pxd_t pmd_t
33433+#define pyd_t pud_t
33434+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33435+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33436+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33437+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33438+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33439+#define pyd_offset(mm, address) pud_offset((mm), (address))
33440+#define PYD_SIZE PUD_SIZE
33441+#endif
33442+
33443+#ifdef CONFIG_PAX_PER_CPU_PGD
33444+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33445+static inline void pgd_dtor(pgd_t *pgd) {}
33446+#else
33447 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33448 {
33449 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33450@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33451 pgd_list_del(pgd);
33452 spin_unlock(&pgd_lock);
33453 }
33454+#endif
33455
33456 /*
33457 * List of all pgd's needed for non-PAE so it can invalidate entries
33458@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33459 * -- nyc
33460 */
33461
33462-#ifdef CONFIG_X86_PAE
33463+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33464 /*
33465 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33466 * updating the top-level pagetable entries to guarantee the
33467@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33468 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33469 * and initialize the kernel pmds here.
33470 */
33471-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33472+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33473
33474 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33475 {
33476@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33477 */
33478 flush_tlb_mm(mm);
33479 }
33480+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33481+#define PREALLOCATED_PXDS USER_PGD_PTRS
33482 #else /* !CONFIG_X86_PAE */
33483
33484 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33485-#define PREALLOCATED_PMDS 0
33486+#define PREALLOCATED_PXDS 0
33487
33488 #endif /* CONFIG_X86_PAE */
33489
33490-static void free_pmds(pmd_t *pmds[])
33491+static void free_pxds(pxd_t *pxds[])
33492 {
33493 int i;
33494
33495- for(i = 0; i < PREALLOCATED_PMDS; i++)
33496- if (pmds[i]) {
33497- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33498- free_page((unsigned long)pmds[i]);
33499+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33500+ if (pxds[i]) {
33501+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33502+ free_page((unsigned long)pxds[i]);
33503 }
33504 }
33505
33506-static int preallocate_pmds(pmd_t *pmds[])
33507+static int preallocate_pxds(pxd_t *pxds[])
33508 {
33509 int i;
33510 bool failed = false;
33511
33512- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33513- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33514- if (!pmd)
33515+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33516+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33517+ if (!pxd)
33518 failed = true;
33519- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33520- free_page((unsigned long)pmd);
33521- pmd = NULL;
33522+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33523+ free_page((unsigned long)pxd);
33524+ pxd = NULL;
33525 failed = true;
33526 }
33527- pmds[i] = pmd;
33528+ pxds[i] = pxd;
33529 }
33530
33531 if (failed) {
33532- free_pmds(pmds);
33533+ free_pxds(pxds);
33534 return -ENOMEM;
33535 }
33536
33537@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33538 * preallocate which never got a corresponding vma will need to be
33539 * freed manually.
33540 */
33541-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33542+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33543 {
33544 int i;
33545
33546- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33547+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33548 pgd_t pgd = pgdp[i];
33549
33550 if (pgd_val(pgd) != 0) {
33551- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33552+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33553
33554- pgdp[i] = native_make_pgd(0);
33555+ set_pgd(pgdp + i, native_make_pgd(0));
33556
33557- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33558- pmd_free(mm, pmd);
33559+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33560+ pxd_free(mm, pxd);
33561 }
33562 }
33563 }
33564
33565-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33566+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33567 {
33568- pud_t *pud;
33569+ pyd_t *pyd;
33570 int i;
33571
33572- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33573+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33574 return;
33575
33576- pud = pud_offset(pgd, 0);
33577-
33578- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33579- pmd_t *pmd = pmds[i];
33580+#ifdef CONFIG_X86_64
33581+ pyd = pyd_offset(mm, 0L);
33582+#else
33583+ pyd = pyd_offset(pgd, 0L);
33584+#endif
33585
33586+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33587+ pxd_t *pxd = pxds[i];
33588 if (i >= KERNEL_PGD_BOUNDARY)
33589- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33590- sizeof(pmd_t) * PTRS_PER_PMD);
33591+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33592+ sizeof(pxd_t) * PTRS_PER_PMD);
33593
33594- pud_populate(mm, pud, pmd);
33595+ pyd_populate(mm, pyd, pxd);
33596 }
33597 }
33598
33599 pgd_t *pgd_alloc(struct mm_struct *mm)
33600 {
33601 pgd_t *pgd;
33602- pmd_t *pmds[PREALLOCATED_PMDS];
33603+ pxd_t *pxds[PREALLOCATED_PXDS];
33604
33605 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33606
33607@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33608
33609 mm->pgd = pgd;
33610
33611- if (preallocate_pmds(pmds) != 0)
33612+ if (preallocate_pxds(pxds) != 0)
33613 goto out_free_pgd;
33614
33615 if (paravirt_pgd_alloc(mm) != 0)
33616- goto out_free_pmds;
33617+ goto out_free_pxds;
33618
33619 /*
33620 * Make sure that pre-populating the pmds is atomic with
33621@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33622 spin_lock(&pgd_lock);
33623
33624 pgd_ctor(mm, pgd);
33625- pgd_prepopulate_pmd(mm, pgd, pmds);
33626+ pgd_prepopulate_pxd(mm, pgd, pxds);
33627
33628 spin_unlock(&pgd_lock);
33629
33630 return pgd;
33631
33632-out_free_pmds:
33633- free_pmds(pmds);
33634+out_free_pxds:
33635+ free_pxds(pxds);
33636 out_free_pgd:
33637 free_page((unsigned long)pgd);
33638 out:
33639@@ -313,7 +380,7 @@ out:
33640
33641 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33642 {
33643- pgd_mop_up_pmds(mm, pgd);
33644+ pgd_mop_up_pxds(mm, pgd);
33645 pgd_dtor(pgd);
33646 paravirt_pgd_free(mm, pgd);
33647 free_page((unsigned long)pgd);
33648diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33649index 4dd8cf6..f9d143e 100644
33650--- a/arch/x86/mm/pgtable_32.c
33651+++ b/arch/x86/mm/pgtable_32.c
33652@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33653 return;
33654 }
33655 pte = pte_offset_kernel(pmd, vaddr);
33656+
33657+ pax_open_kernel();
33658 if (pte_val(pteval))
33659 set_pte_at(&init_mm, vaddr, pte, pteval);
33660 else
33661 pte_clear(&init_mm, vaddr, pte);
33662+ pax_close_kernel();
33663
33664 /*
33665 * It's enough to flush this one mapping.
33666diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33667index e666cbb..61788c45 100644
33668--- a/arch/x86/mm/physaddr.c
33669+++ b/arch/x86/mm/physaddr.c
33670@@ -10,7 +10,7 @@
33671 #ifdef CONFIG_X86_64
33672
33673 #ifdef CONFIG_DEBUG_VIRTUAL
33674-unsigned long __phys_addr(unsigned long x)
33675+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33676 {
33677 unsigned long y = x - __START_KERNEL_map;
33678
33679@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33680 #else
33681
33682 #ifdef CONFIG_DEBUG_VIRTUAL
33683-unsigned long __phys_addr(unsigned long x)
33684+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33685 {
33686 unsigned long phys_addr = x - PAGE_OFFSET;
33687 /* VMALLOC_* aren't constants */
33688diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33689index 90555bf..f5f1828 100644
33690--- a/arch/x86/mm/setup_nx.c
33691+++ b/arch/x86/mm/setup_nx.c
33692@@ -5,8 +5,10 @@
33693 #include <asm/pgtable.h>
33694 #include <asm/proto.h>
33695
33696+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33697 static int disable_nx;
33698
33699+#ifndef CONFIG_PAX_PAGEEXEC
33700 /*
33701 * noexec = on|off
33702 *
33703@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33704 return 0;
33705 }
33706 early_param("noexec", noexec_setup);
33707+#endif
33708+
33709+#endif
33710
33711 void x86_configure_nx(void)
33712 {
33713+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33714 if (cpu_has_nx && !disable_nx)
33715 __supported_pte_mask |= _PAGE_NX;
33716 else
33717+#endif
33718 __supported_pte_mask &= ~_PAGE_NX;
33719 }
33720
33721diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33722index dd8dda1..9e9b0f6 100644
33723--- a/arch/x86/mm/tlb.c
33724+++ b/arch/x86/mm/tlb.c
33725@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33726 BUG();
33727 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33728 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33729+
33730+#ifndef CONFIG_PAX_PER_CPU_PGD
33731 load_cr3(swapper_pg_dir);
33732+#endif
33733+
33734 }
33735 }
33736 EXPORT_SYMBOL_GPL(leave_mm);
33737diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33738new file mode 100644
33739index 0000000..dace51c
33740--- /dev/null
33741+++ b/arch/x86/mm/uderef_64.c
33742@@ -0,0 +1,37 @@
33743+#include <linux/mm.h>
33744+#include <asm/pgtable.h>
33745+#include <asm/uaccess.h>
33746+
33747+#ifdef CONFIG_PAX_MEMORY_UDEREF
33748+/* PaX: due to the special call convention these functions must
33749+ * - remain leaf functions under all configurations,
33750+ * - never be called directly, only dereferenced from the wrappers.
33751+ */
33752+void __pax_open_userland(void)
33753+{
33754+ unsigned int cpu;
33755+
33756+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33757+ return;
33758+
33759+ cpu = raw_get_cpu();
33760+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33761+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33762+ raw_put_cpu_no_resched();
33763+}
33764+EXPORT_SYMBOL(__pax_open_userland);
33765+
33766+void __pax_close_userland(void)
33767+{
33768+ unsigned int cpu;
33769+
33770+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33771+ return;
33772+
33773+ cpu = raw_get_cpu();
33774+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33775+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33776+ raw_put_cpu_no_resched();
33777+}
33778+EXPORT_SYMBOL(__pax_close_userland);
33779+#endif
33780diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33781index 0149575..f746de8 100644
33782--- a/arch/x86/net/bpf_jit.S
33783+++ b/arch/x86/net/bpf_jit.S
33784@@ -9,6 +9,7 @@
33785 */
33786 #include <linux/linkage.h>
33787 #include <asm/dwarf2.h>
33788+#include <asm/alternative-asm.h>
33789
33790 /*
33791 * Calling convention :
33792@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33793 jle bpf_slow_path_word
33794 mov (SKBDATA,%rsi),%eax
33795 bswap %eax /* ntohl() */
33796+ pax_force_retaddr
33797 ret
33798
33799 sk_load_half:
33800@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33801 jle bpf_slow_path_half
33802 movzwl (SKBDATA,%rsi),%eax
33803 rol $8,%ax # ntohs()
33804+ pax_force_retaddr
33805 ret
33806
33807 sk_load_byte:
33808@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33809 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33810 jle bpf_slow_path_byte
33811 movzbl (SKBDATA,%rsi),%eax
33812+ pax_force_retaddr
33813 ret
33814
33815 /**
33816@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33817 movzbl (SKBDATA,%rsi),%ebx
33818 and $15,%bl
33819 shl $2,%bl
33820+ pax_force_retaddr
33821 ret
33822
33823 /* rsi contains offset and can be scratched */
33824@@ -109,6 +114,7 @@ bpf_slow_path_word:
33825 js bpf_error
33826 mov -12(%rbp),%eax
33827 bswap %eax
33828+ pax_force_retaddr
33829 ret
33830
33831 bpf_slow_path_half:
33832@@ -117,12 +123,14 @@ bpf_slow_path_half:
33833 mov -12(%rbp),%ax
33834 rol $8,%ax
33835 movzwl %ax,%eax
33836+ pax_force_retaddr
33837 ret
33838
33839 bpf_slow_path_byte:
33840 bpf_slow_path_common(1)
33841 js bpf_error
33842 movzbl -12(%rbp),%eax
33843+ pax_force_retaddr
33844 ret
33845
33846 bpf_slow_path_byte_msh:
33847@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33848 and $15,%al
33849 shl $2,%al
33850 xchg %eax,%ebx
33851+ pax_force_retaddr
33852 ret
33853
33854 #define sk_negative_common(SIZE) \
33855@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33856 sk_negative_common(4)
33857 mov (%rax), %eax
33858 bswap %eax
33859+ pax_force_retaddr
33860 ret
33861
33862 bpf_slow_path_half_neg:
33863@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33864 mov (%rax),%ax
33865 rol $8,%ax
33866 movzwl %ax,%eax
33867+ pax_force_retaddr
33868 ret
33869
33870 bpf_slow_path_byte_neg:
33871@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33872 .globl sk_load_byte_negative_offset
33873 sk_negative_common(1)
33874 movzbl (%rax), %eax
33875+ pax_force_retaddr
33876 ret
33877
33878 bpf_slow_path_byte_msh_neg:
33879@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33880 and $15,%al
33881 shl $2,%al
33882 xchg %eax,%ebx
33883+ pax_force_retaddr
33884 ret
33885
33886 bpf_error:
33887@@ -197,4 +210,5 @@ bpf_error:
33888 xor %eax,%eax
33889 mov -8(%rbp),%rbx
33890 leaveq
33891+ pax_force_retaddr
33892 ret
33893diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33894index 6d5663a..f1ec380 100644
33895--- a/arch/x86/net/bpf_jit_comp.c
33896+++ b/arch/x86/net/bpf_jit_comp.c
33897@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33898 return ptr + len;
33899 }
33900
33901+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33902+#define MAX_INSTR_CODE_SIZE 96
33903+#else
33904+#define MAX_INSTR_CODE_SIZE 64
33905+#endif
33906+
33907 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33908
33909 #define EMIT1(b1) EMIT(b1, 1)
33910 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33911 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33912 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33913+
33914+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33915+/* original constant will appear in ecx */
33916+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33917+do { \
33918+ /* mov ecx, randkey */ \
33919+ EMIT1(0xb9); \
33920+ EMIT(_key, 4); \
33921+ /* xor ecx, randkey ^ off */ \
33922+ EMIT2(0x81, 0xf1); \
33923+ EMIT((_key) ^ (_off), 4); \
33924+} while (0)
33925+
33926+#define EMIT1_off32(b1, _off) \
33927+do { \
33928+ switch (b1) { \
33929+ case 0x05: /* add eax, imm32 */ \
33930+ case 0x2d: /* sub eax, imm32 */ \
33931+ case 0x25: /* and eax, imm32 */ \
33932+ case 0x0d: /* or eax, imm32 */ \
33933+ case 0xb8: /* mov eax, imm32 */ \
33934+ case 0x35: /* xor eax, imm32 */ \
33935+ case 0x3d: /* cmp eax, imm32 */ \
33936+ case 0xa9: /* test eax, imm32 */ \
33937+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33938+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33939+ break; \
33940+ case 0xbb: /* mov ebx, imm32 */ \
33941+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33942+ /* mov ebx, ecx */ \
33943+ EMIT2(0x89, 0xcb); \
33944+ break; \
33945+ case 0xbe: /* mov esi, imm32 */ \
33946+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33947+ /* mov esi, ecx */ \
33948+ EMIT2(0x89, 0xce); \
33949+ break; \
33950+ case 0xe8: /* call rel imm32, always to known funcs */ \
33951+ EMIT1(b1); \
33952+ EMIT(_off, 4); \
33953+ break; \
33954+ case 0xe9: /* jmp rel imm32 */ \
33955+ EMIT1(b1); \
33956+ EMIT(_off, 4); \
33957+ /* prevent fall-through, we're not called if off = 0 */ \
33958+ EMIT(0xcccccccc, 4); \
33959+ EMIT(0xcccccccc, 4); \
33960+ break; \
33961+ default: \
33962+ BUILD_BUG(); \
33963+ } \
33964+} while (0)
33965+
33966+#define EMIT2_off32(b1, b2, _off) \
33967+do { \
33968+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33969+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33970+ EMIT(randkey, 4); \
33971+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33972+ EMIT((_off) - randkey, 4); \
33973+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33974+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33975+ /* imul eax, ecx */ \
33976+ EMIT3(0x0f, 0xaf, 0xc1); \
33977+ } else { \
33978+ BUILD_BUG(); \
33979+ } \
33980+} while (0)
33981+#else
33982 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33983+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33984+#endif
33985
33986 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33987 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33988@@ -91,6 +168,24 @@ do { \
33989 #define X86_JBE 0x76
33990 #define X86_JA 0x77
33991
33992+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33993+#define APPEND_FLOW_VERIFY() \
33994+do { \
33995+ /* mov ecx, randkey */ \
33996+ EMIT1(0xb9); \
33997+ EMIT(randkey, 4); \
33998+ /* cmp ecx, randkey */ \
33999+ EMIT2(0x81, 0xf9); \
34000+ EMIT(randkey, 4); \
34001+ /* jz after 8 int 3s */ \
34002+ EMIT2(0x74, 0x08); \
34003+ EMIT(0xcccccccc, 4); \
34004+ EMIT(0xcccccccc, 4); \
34005+} while (0)
34006+#else
34007+#define APPEND_FLOW_VERIFY() do { } while (0)
34008+#endif
34009+
34010 #define EMIT_COND_JMP(op, offset) \
34011 do { \
34012 if (is_near(offset)) \
34013@@ -98,6 +193,7 @@ do { \
34014 else { \
34015 EMIT2(0x0f, op + 0x10); \
34016 EMIT(offset, 4); /* jxx .+off32 */ \
34017+ APPEND_FLOW_VERIFY(); \
34018 } \
34019 } while (0)
34020
34021@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
34022 return -1;
34023 }
34024
34025-struct bpf_binary_header {
34026- unsigned int pages;
34027- /* Note : for security reasons, bpf code will follow a randomly
34028- * sized amount of int3 instructions
34029- */
34030- u8 image[];
34031-};
34032-
34033-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34034+/* Note : for security reasons, bpf code will follow a randomly
34035+ * sized amount of int3 instructions
34036+ */
34037+static u8 *bpf_alloc_binary(unsigned int proglen,
34038 u8 **image_ptr)
34039 {
34040 unsigned int sz, hole;
34041- struct bpf_binary_header *header;
34042+ u8 *header;
34043
34044 /* Most of BPF filters are really small,
34045 * but if some of them fill a page, allow at least
34046 * 128 extra bytes to insert a random section of int3
34047 */
34048- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34049- header = module_alloc(sz);
34050+ sz = round_up(proglen + 128, PAGE_SIZE);
34051+ header = module_alloc_exec(sz);
34052 if (!header)
34053 return NULL;
34054
34055+ pax_open_kernel();
34056 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34057+ pax_close_kernel();
34058
34059- header->pages = sz / PAGE_SIZE;
34060- hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34061+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34062
34063 /* insert a random number of int3 instructions before BPF code */
34064- *image_ptr = &header->image[prandom_u32() % hole];
34065+ *image_ptr = &header[prandom_u32() % hole];
34066 return header;
34067 }
34068
34069 void bpf_jit_compile(struct sk_filter *fp)
34070 {
34071- u8 temp[64];
34072+ u8 temp[MAX_INSTR_CODE_SIZE];
34073 u8 *prog;
34074 unsigned int proglen, oldproglen = 0;
34075 int ilen, i;
34076 int t_offset, f_offset;
34077 u8 t_op, f_op, seen = 0, pass;
34078 u8 *image = NULL;
34079- struct bpf_binary_header *header = NULL;
34080+ u8 *header = NULL;
34081 u8 *func;
34082 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34083 unsigned int cleanup_addr; /* epilogue code offset */
34084 unsigned int *addrs;
34085 const struct sock_filter *filter = fp->insns;
34086 int flen = fp->len;
34087+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34088+ unsigned int randkey;
34089+#endif
34090
34091 if (!bpf_jit_enable)
34092 return;
34093@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34094 return;
34095
34096 /* Before first pass, make a rough estimation of addrs[]
34097- * each bpf instruction is translated to less than 64 bytes
34098+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34099 */
34100 for (proglen = 0, i = 0; i < flen; i++) {
34101- proglen += 64;
34102+ proglen += MAX_INSTR_CODE_SIZE;
34103 addrs[i] = proglen;
34104 }
34105 cleanup_addr = proglen; /* epilogue address */
34106@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34107 for (i = 0; i < flen; i++) {
34108 unsigned int K = filter[i].k;
34109
34110+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34111+ randkey = prandom_u32();
34112+#endif
34113+
34114 switch (filter[i].code) {
34115 case BPF_S_ALU_ADD_X: /* A += X; */
34116 seen |= SEEN_XREG;
34117@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34118 case BPF_S_ALU_MUL_K: /* A *= K */
34119 if (is_imm8(K))
34120 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34121- else {
34122- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34123- EMIT(K, 4);
34124- }
34125+ else
34126+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34127 break;
34128 case BPF_S_ALU_DIV_X: /* A /= X; */
34129 seen |= SEEN_XREG;
34130@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34131 break;
34132 }
34133 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34134+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34135+ DILUTE_CONST_SEQUENCE(K, randkey);
34136+#else
34137 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34138+#endif
34139 EMIT2(0xf7, 0xf1); /* div %ecx */
34140 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34141 break;
34142@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34143 if (K == 1)
34144 break;
34145 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34146+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34147+ DILUTE_CONST_SEQUENCE(K, randkey);
34148+#else
34149 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34150+#endif
34151 EMIT2(0xf7, 0xf1); /* div %ecx */
34152 break;
34153 case BPF_S_ALU_AND_X:
34154@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34155 if (is_imm8(K)) {
34156 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34157 } else {
34158- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34159- EMIT(K, 4);
34160+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34161 }
34162 } else {
34163 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34164@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34165 if (unlikely(proglen + ilen > oldproglen)) {
34166 pr_err("bpb_jit_compile fatal error\n");
34167 kfree(addrs);
34168- module_free(NULL, header);
34169+ module_free_exec(NULL, image);
34170 return;
34171 }
34172+ pax_open_kernel();
34173 memcpy(image + proglen, temp, ilen);
34174+ pax_close_kernel();
34175 }
34176 proglen += ilen;
34177 addrs[i] = proglen;
34178@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34179
34180 if (image) {
34181 bpf_flush_icache(header, image + proglen);
34182- set_memory_ro((unsigned long)header, header->pages);
34183 fp->bpf_func = (void *)image;
34184 fp->jited = 1;
34185 }
34186@@ -783,10 +888,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34187 {
34188 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34189 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34190- struct bpf_binary_header *header = (void *)addr;
34191
34192- set_memory_rw(addr, header->pages);
34193- module_free(NULL, header);
34194+ set_memory_rw(addr, 1);
34195+ module_free_exec(NULL, (void *)addr);
34196 kfree(fp);
34197 }
34198
34199diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34200index 5d04be5..2beeaa2 100644
34201--- a/arch/x86/oprofile/backtrace.c
34202+++ b/arch/x86/oprofile/backtrace.c
34203@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34204 struct stack_frame_ia32 *fp;
34205 unsigned long bytes;
34206
34207- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34208+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34209 if (bytes != 0)
34210 return NULL;
34211
34212- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34213+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34214
34215 oprofile_add_trace(bufhead[0].return_address);
34216
34217@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34218 struct stack_frame bufhead[2];
34219 unsigned long bytes;
34220
34221- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34222+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34223 if (bytes != 0)
34224 return NULL;
34225
34226@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34227 {
34228 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34229
34230- if (!user_mode_vm(regs)) {
34231+ if (!user_mode(regs)) {
34232 unsigned long stack = kernel_stack_pointer(regs);
34233 if (depth)
34234 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34235diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34236index 379e8bd..6386e09 100644
34237--- a/arch/x86/oprofile/nmi_int.c
34238+++ b/arch/x86/oprofile/nmi_int.c
34239@@ -23,6 +23,7 @@
34240 #include <asm/nmi.h>
34241 #include <asm/msr.h>
34242 #include <asm/apic.h>
34243+#include <asm/pgtable.h>
34244
34245 #include "op_counter.h"
34246 #include "op_x86_model.h"
34247@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34248 if (ret)
34249 return ret;
34250
34251- if (!model->num_virt_counters)
34252- model->num_virt_counters = model->num_counters;
34253+ if (!model->num_virt_counters) {
34254+ pax_open_kernel();
34255+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34256+ pax_close_kernel();
34257+ }
34258
34259 mux_init(ops);
34260
34261diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34262index 50d86c0..7985318 100644
34263--- a/arch/x86/oprofile/op_model_amd.c
34264+++ b/arch/x86/oprofile/op_model_amd.c
34265@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34266 num_counters = AMD64_NUM_COUNTERS;
34267 }
34268
34269- op_amd_spec.num_counters = num_counters;
34270- op_amd_spec.num_controls = num_counters;
34271- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34272+ pax_open_kernel();
34273+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34274+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34275+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34276+ pax_close_kernel();
34277
34278 return 0;
34279 }
34280diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34281index d90528e..0127e2b 100644
34282--- a/arch/x86/oprofile/op_model_ppro.c
34283+++ b/arch/x86/oprofile/op_model_ppro.c
34284@@ -19,6 +19,7 @@
34285 #include <asm/msr.h>
34286 #include <asm/apic.h>
34287 #include <asm/nmi.h>
34288+#include <asm/pgtable.h>
34289
34290 #include "op_x86_model.h"
34291 #include "op_counter.h"
34292@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34293
34294 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34295
34296- op_arch_perfmon_spec.num_counters = num_counters;
34297- op_arch_perfmon_spec.num_controls = num_counters;
34298+ pax_open_kernel();
34299+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34300+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34301+ pax_close_kernel();
34302 }
34303
34304 static int arch_perfmon_init(struct oprofile_operations *ignore)
34305diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34306index 71e8a67..6a313bb 100644
34307--- a/arch/x86/oprofile/op_x86_model.h
34308+++ b/arch/x86/oprofile/op_x86_model.h
34309@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34310 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34311 struct op_msrs const * const msrs);
34312 #endif
34313-};
34314+} __do_const;
34315
34316 struct op_counter_config;
34317
34318diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34319index 84b9d67..260e5ff 100644
34320--- a/arch/x86/pci/intel_mid_pci.c
34321+++ b/arch/x86/pci/intel_mid_pci.c
34322@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34323 pr_info("Intel MID platform detected, using MID PCI ops\n");
34324 pci_mmcfg_late_init();
34325 pcibios_enable_irq = intel_mid_pci_irq_enable;
34326- pci_root_ops = intel_mid_pci_ops;
34327+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34328 pci_soc_mode = 1;
34329 /* Continue with standard init */
34330 return 1;
34331diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34332index 84112f5..6334d60 100644
34333--- a/arch/x86/pci/irq.c
34334+++ b/arch/x86/pci/irq.c
34335@@ -50,7 +50,7 @@ struct irq_router {
34336 struct irq_router_handler {
34337 u16 vendor;
34338 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34339-};
34340+} __do_const;
34341
34342 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34343 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34344@@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34345 return 0;
34346 }
34347
34348-static __initdata struct irq_router_handler pirq_routers[] = {
34349+static __initconst const struct irq_router_handler pirq_routers[] = {
34350 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34351 { PCI_VENDOR_ID_AL, ali_router_probe },
34352 { PCI_VENDOR_ID_ITE, ite_router_probe },
34353@@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
34354 static void __init pirq_find_router(struct irq_router *r)
34355 {
34356 struct irq_routing_table *rt = pirq_table;
34357- struct irq_router_handler *h;
34358+ const struct irq_router_handler *h;
34359
34360 #ifdef CONFIG_PCI_BIOS
34361 if (!rt->signature) {
34362@@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34363 return 0;
34364 }
34365
34366-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34367+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34368 {
34369 .callback = fix_broken_hp_bios_irq9,
34370 .ident = "HP Pavilion N5400 Series Laptop",
34371diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34372index c77b24a..c979855 100644
34373--- a/arch/x86/pci/pcbios.c
34374+++ b/arch/x86/pci/pcbios.c
34375@@ -79,7 +79,7 @@ union bios32 {
34376 static struct {
34377 unsigned long address;
34378 unsigned short segment;
34379-} bios32_indirect = { 0, __KERNEL_CS };
34380+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34381
34382 /*
34383 * Returns the entry point for the given service, NULL on error
34384@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34385 unsigned long length; /* %ecx */
34386 unsigned long entry; /* %edx */
34387 unsigned long flags;
34388+ struct desc_struct d, *gdt;
34389
34390 local_irq_save(flags);
34391- __asm__("lcall *(%%edi); cld"
34392+
34393+ gdt = get_cpu_gdt_table(smp_processor_id());
34394+
34395+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34396+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34397+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34398+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34399+
34400+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34401 : "=a" (return_code),
34402 "=b" (address),
34403 "=c" (length),
34404 "=d" (entry)
34405 : "0" (service),
34406 "1" (0),
34407- "D" (&bios32_indirect));
34408+ "D" (&bios32_indirect),
34409+ "r"(__PCIBIOS_DS)
34410+ : "memory");
34411+
34412+ pax_open_kernel();
34413+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34414+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34415+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34416+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34417+ pax_close_kernel();
34418+
34419 local_irq_restore(flags);
34420
34421 switch (return_code) {
34422- case 0:
34423- return address + entry;
34424- case 0x80: /* Not present */
34425- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34426- return 0;
34427- default: /* Shouldn't happen */
34428- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34429- service, return_code);
34430+ case 0: {
34431+ int cpu;
34432+ unsigned char flags;
34433+
34434+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34435+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34436+ printk(KERN_WARNING "bios32_service: not valid\n");
34437 return 0;
34438+ }
34439+ address = address + PAGE_OFFSET;
34440+ length += 16UL; /* some BIOSs underreport this... */
34441+ flags = 4;
34442+ if (length >= 64*1024*1024) {
34443+ length >>= PAGE_SHIFT;
34444+ flags |= 8;
34445+ }
34446+
34447+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34448+ gdt = get_cpu_gdt_table(cpu);
34449+ pack_descriptor(&d, address, length, 0x9b, flags);
34450+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34451+ pack_descriptor(&d, address, length, 0x93, flags);
34452+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34453+ }
34454+ return entry;
34455+ }
34456+ case 0x80: /* Not present */
34457+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34458+ return 0;
34459+ default: /* Shouldn't happen */
34460+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34461+ service, return_code);
34462+ return 0;
34463 }
34464 }
34465
34466 static struct {
34467 unsigned long address;
34468 unsigned short segment;
34469-} pci_indirect = { 0, __KERNEL_CS };
34470+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34471
34472-static int pci_bios_present;
34473+static int pci_bios_present __read_only;
34474
34475 static int check_pcibios(void)
34476 {
34477@@ -131,11 +174,13 @@ static int check_pcibios(void)
34478 unsigned long flags, pcibios_entry;
34479
34480 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34481- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34482+ pci_indirect.address = pcibios_entry;
34483
34484 local_irq_save(flags);
34485- __asm__(
34486- "lcall *(%%edi); cld\n\t"
34487+ __asm__("movw %w6, %%ds\n\t"
34488+ "lcall *%%ss:(%%edi); cld\n\t"
34489+ "push %%ss\n\t"
34490+ "pop %%ds\n\t"
34491 "jc 1f\n\t"
34492 "xor %%ah, %%ah\n"
34493 "1:"
34494@@ -144,7 +189,8 @@ static int check_pcibios(void)
34495 "=b" (ebx),
34496 "=c" (ecx)
34497 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34498- "D" (&pci_indirect)
34499+ "D" (&pci_indirect),
34500+ "r" (__PCIBIOS_DS)
34501 : "memory");
34502 local_irq_restore(flags);
34503
34504@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34505
34506 switch (len) {
34507 case 1:
34508- __asm__("lcall *(%%esi); cld\n\t"
34509+ __asm__("movw %w6, %%ds\n\t"
34510+ "lcall *%%ss:(%%esi); cld\n\t"
34511+ "push %%ss\n\t"
34512+ "pop %%ds\n\t"
34513 "jc 1f\n\t"
34514 "xor %%ah, %%ah\n"
34515 "1:"
34516@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34517 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34518 "b" (bx),
34519 "D" ((long)reg),
34520- "S" (&pci_indirect));
34521+ "S" (&pci_indirect),
34522+ "r" (__PCIBIOS_DS));
34523 /*
34524 * Zero-extend the result beyond 8 bits, do not trust the
34525 * BIOS having done it:
34526@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34527 *value &= 0xff;
34528 break;
34529 case 2:
34530- __asm__("lcall *(%%esi); cld\n\t"
34531+ __asm__("movw %w6, %%ds\n\t"
34532+ "lcall *%%ss:(%%esi); cld\n\t"
34533+ "push %%ss\n\t"
34534+ "pop %%ds\n\t"
34535 "jc 1f\n\t"
34536 "xor %%ah, %%ah\n"
34537 "1:"
34538@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34539 : "1" (PCIBIOS_READ_CONFIG_WORD),
34540 "b" (bx),
34541 "D" ((long)reg),
34542- "S" (&pci_indirect));
34543+ "S" (&pci_indirect),
34544+ "r" (__PCIBIOS_DS));
34545 /*
34546 * Zero-extend the result beyond 16 bits, do not trust the
34547 * BIOS having done it:
34548@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34549 *value &= 0xffff;
34550 break;
34551 case 4:
34552- __asm__("lcall *(%%esi); cld\n\t"
34553+ __asm__("movw %w6, %%ds\n\t"
34554+ "lcall *%%ss:(%%esi); cld\n\t"
34555+ "push %%ss\n\t"
34556+ "pop %%ds\n\t"
34557 "jc 1f\n\t"
34558 "xor %%ah, %%ah\n"
34559 "1:"
34560@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34561 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34562 "b" (bx),
34563 "D" ((long)reg),
34564- "S" (&pci_indirect));
34565+ "S" (&pci_indirect),
34566+ "r" (__PCIBIOS_DS));
34567 break;
34568 }
34569
34570@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34571
34572 switch (len) {
34573 case 1:
34574- __asm__("lcall *(%%esi); cld\n\t"
34575+ __asm__("movw %w6, %%ds\n\t"
34576+ "lcall *%%ss:(%%esi); cld\n\t"
34577+ "push %%ss\n\t"
34578+ "pop %%ds\n\t"
34579 "jc 1f\n\t"
34580 "xor %%ah, %%ah\n"
34581 "1:"
34582@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34583 "c" (value),
34584 "b" (bx),
34585 "D" ((long)reg),
34586- "S" (&pci_indirect));
34587+ "S" (&pci_indirect),
34588+ "r" (__PCIBIOS_DS));
34589 break;
34590 case 2:
34591- __asm__("lcall *(%%esi); cld\n\t"
34592+ __asm__("movw %w6, %%ds\n\t"
34593+ "lcall *%%ss:(%%esi); cld\n\t"
34594+ "push %%ss\n\t"
34595+ "pop %%ds\n\t"
34596 "jc 1f\n\t"
34597 "xor %%ah, %%ah\n"
34598 "1:"
34599@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34600 "c" (value),
34601 "b" (bx),
34602 "D" ((long)reg),
34603- "S" (&pci_indirect));
34604+ "S" (&pci_indirect),
34605+ "r" (__PCIBIOS_DS));
34606 break;
34607 case 4:
34608- __asm__("lcall *(%%esi); cld\n\t"
34609+ __asm__("movw %w6, %%ds\n\t"
34610+ "lcall *%%ss:(%%esi); cld\n\t"
34611+ "push %%ss\n\t"
34612+ "pop %%ds\n\t"
34613 "jc 1f\n\t"
34614 "xor %%ah, %%ah\n"
34615 "1:"
34616@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34617 "c" (value),
34618 "b" (bx),
34619 "D" ((long)reg),
34620- "S" (&pci_indirect));
34621+ "S" (&pci_indirect),
34622+ "r" (__PCIBIOS_DS));
34623 break;
34624 }
34625
34626@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34627
34628 DBG("PCI: Fetching IRQ routing table... ");
34629 __asm__("push %%es\n\t"
34630+ "movw %w8, %%ds\n\t"
34631 "push %%ds\n\t"
34632 "pop %%es\n\t"
34633- "lcall *(%%esi); cld\n\t"
34634+ "lcall *%%ss:(%%esi); cld\n\t"
34635 "pop %%es\n\t"
34636+ "push %%ss\n\t"
34637+ "pop %%ds\n"
34638 "jc 1f\n\t"
34639 "xor %%ah, %%ah\n"
34640 "1:"
34641@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34642 "1" (0),
34643 "D" ((long) &opt),
34644 "S" (&pci_indirect),
34645- "m" (opt)
34646+ "m" (opt),
34647+ "r" (__PCIBIOS_DS)
34648 : "memory");
34649 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34650 if (ret & 0xff00)
34651@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34652 {
34653 int ret;
34654
34655- __asm__("lcall *(%%esi); cld\n\t"
34656+ __asm__("movw %w5, %%ds\n\t"
34657+ "lcall *%%ss:(%%esi); cld\n\t"
34658+ "push %%ss\n\t"
34659+ "pop %%ds\n"
34660 "jc 1f\n\t"
34661 "xor %%ah, %%ah\n"
34662 "1:"
34663@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34664 : "0" (PCIBIOS_SET_PCI_HW_INT),
34665 "b" ((dev->bus->number << 8) | dev->devfn),
34666 "c" ((irq << 8) | (pin + 10)),
34667- "S" (&pci_indirect));
34668+ "S" (&pci_indirect),
34669+ "r" (__PCIBIOS_DS));
34670 return !(ret & 0xff00);
34671 }
34672 EXPORT_SYMBOL(pcibios_set_irq_routing);
34673diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34674index 9ee3491..872192f 100644
34675--- a/arch/x86/platform/efi/efi_32.c
34676+++ b/arch/x86/platform/efi/efi_32.c
34677@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34678 {
34679 struct desc_ptr gdt_descr;
34680
34681+#ifdef CONFIG_PAX_KERNEXEC
34682+ struct desc_struct d;
34683+#endif
34684+
34685 local_irq_save(efi_rt_eflags);
34686
34687 load_cr3(initial_page_table);
34688 __flush_tlb_all();
34689
34690+#ifdef CONFIG_PAX_KERNEXEC
34691+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34692+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34693+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34694+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34695+#endif
34696+
34697 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34698 gdt_descr.size = GDT_SIZE - 1;
34699 load_gdt(&gdt_descr);
34700@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34701 {
34702 struct desc_ptr gdt_descr;
34703
34704+#ifdef CONFIG_PAX_KERNEXEC
34705+ struct desc_struct d;
34706+
34707+ memset(&d, 0, sizeof d);
34708+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34709+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34710+#endif
34711+
34712 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34713 gdt_descr.size = GDT_SIZE - 1;
34714 load_gdt(&gdt_descr);
34715
34716+#ifdef CONFIG_PAX_PER_CPU_PGD
34717+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34718+#else
34719 load_cr3(swapper_pg_dir);
34720+#endif
34721+
34722 __flush_tlb_all();
34723
34724 local_irq_restore(efi_rt_eflags);
34725diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34726index 290d397..3906bcd 100644
34727--- a/arch/x86/platform/efi/efi_64.c
34728+++ b/arch/x86/platform/efi/efi_64.c
34729@@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
34730 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34731 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34732 }
34733+
34734+#ifdef CONFIG_PAX_PER_CPU_PGD
34735+ load_cr3(swapper_pg_dir);
34736+#endif
34737+
34738 __flush_tlb_all();
34739 }
34740
34741@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34742 for (pgd = 0; pgd < n_pgds; pgd++)
34743 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34744 kfree(save_pgd);
34745+
34746+#ifdef CONFIG_PAX_PER_CPU_PGD
34747+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34748+#endif
34749+
34750 __flush_tlb_all();
34751 local_irq_restore(efi_flags);
34752 early_code_mapping_set_exec(0);
34753diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34754index fbe66e6..eae5e38 100644
34755--- a/arch/x86/platform/efi/efi_stub_32.S
34756+++ b/arch/x86/platform/efi/efi_stub_32.S
34757@@ -6,7 +6,9 @@
34758 */
34759
34760 #include <linux/linkage.h>
34761+#include <linux/init.h>
34762 #include <asm/page_types.h>
34763+#include <asm/segment.h>
34764
34765 /*
34766 * efi_call_phys(void *, ...) is a function with variable parameters.
34767@@ -20,7 +22,7 @@
34768 * service functions will comply with gcc calling convention, too.
34769 */
34770
34771-.text
34772+__INIT
34773 ENTRY(efi_call_phys)
34774 /*
34775 * 0. The function can only be called in Linux kernel. So CS has been
34776@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34777 * The mapping of lower virtual memory has been created in prelog and
34778 * epilog.
34779 */
34780- movl $1f, %edx
34781- subl $__PAGE_OFFSET, %edx
34782- jmp *%edx
34783+#ifdef CONFIG_PAX_KERNEXEC
34784+ movl $(__KERNEXEC_EFI_DS), %edx
34785+ mov %edx, %ds
34786+ mov %edx, %es
34787+ mov %edx, %ss
34788+ addl $2f,(1f)
34789+ ljmp *(1f)
34790+
34791+__INITDATA
34792+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34793+.previous
34794+
34795+2:
34796+ subl $2b,(1b)
34797+#else
34798+ jmp 1f-__PAGE_OFFSET
34799 1:
34800+#endif
34801
34802 /*
34803 * 2. Now on the top of stack is the return
34804@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34805 * parameter 2, ..., param n. To make things easy, we save the return
34806 * address of efi_call_phys in a global variable.
34807 */
34808- popl %edx
34809- movl %edx, saved_return_addr
34810- /* get the function pointer into ECX*/
34811- popl %ecx
34812- movl %ecx, efi_rt_function_ptr
34813- movl $2f, %edx
34814- subl $__PAGE_OFFSET, %edx
34815- pushl %edx
34816+ popl (saved_return_addr)
34817+ popl (efi_rt_function_ptr)
34818
34819 /*
34820 * 3. Clear PG bit in %CR0.
34821@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34822 /*
34823 * 5. Call the physical function.
34824 */
34825- jmp *%ecx
34826+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34827
34828-2:
34829 /*
34830 * 6. After EFI runtime service returns, control will return to
34831 * following instruction. We'd better readjust stack pointer first.
34832@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34833 movl %cr0, %edx
34834 orl $0x80000000, %edx
34835 movl %edx, %cr0
34836- jmp 1f
34837-1:
34838+
34839 /*
34840 * 8. Now restore the virtual mode from flat mode by
34841 * adding EIP with PAGE_OFFSET.
34842 */
34843- movl $1f, %edx
34844- jmp *%edx
34845+#ifdef CONFIG_PAX_KERNEXEC
34846+ movl $(__KERNEL_DS), %edx
34847+ mov %edx, %ds
34848+ mov %edx, %es
34849+ mov %edx, %ss
34850+ ljmp $(__KERNEL_CS),$1f
34851+#else
34852+ jmp 1f+__PAGE_OFFSET
34853+#endif
34854 1:
34855
34856 /*
34857 * 9. Balance the stack. And because EAX contain the return value,
34858 * we'd better not clobber it.
34859 */
34860- leal efi_rt_function_ptr, %edx
34861- movl (%edx), %ecx
34862- pushl %ecx
34863+ pushl (efi_rt_function_ptr)
34864
34865 /*
34866- * 10. Push the saved return address onto the stack and return.
34867+ * 10. Return to the saved return address.
34868 */
34869- leal saved_return_addr, %edx
34870- movl (%edx), %ecx
34871- pushl %ecx
34872- ret
34873+ jmpl *(saved_return_addr)
34874 ENDPROC(efi_call_phys)
34875 .previous
34876
34877-.data
34878+__INITDATA
34879 saved_return_addr:
34880 .long 0
34881 efi_rt_function_ptr:
34882diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34883index e0984ef..a062dac 100644
34884--- a/arch/x86/platform/efi/efi_stub_64.S
34885+++ b/arch/x86/platform/efi/efi_stub_64.S
34886@@ -11,6 +11,7 @@
34887 #include <asm/msr.h>
34888 #include <asm/processor-flags.h>
34889 #include <asm/page_types.h>
34890+#include <asm/alternative-asm.h>
34891
34892 #define SAVE_XMM \
34893 mov %rsp, %rax; \
34894@@ -81,6 +82,7 @@ ENTRY(efi_call0)
34895 RESTORE_PGT
34896 addq $32, %rsp
34897 RESTORE_XMM
34898+ pax_force_retaddr 0, 1
34899 ret
34900 ENDPROC(efi_call0)
34901
34902@@ -93,6 +95,7 @@ ENTRY(efi_call1)
34903 RESTORE_PGT
34904 addq $32, %rsp
34905 RESTORE_XMM
34906+ pax_force_retaddr 0, 1
34907 ret
34908 ENDPROC(efi_call1)
34909
34910@@ -105,6 +108,7 @@ ENTRY(efi_call2)
34911 RESTORE_PGT
34912 addq $32, %rsp
34913 RESTORE_XMM
34914+ pax_force_retaddr 0, 1
34915 ret
34916 ENDPROC(efi_call2)
34917
34918@@ -118,6 +122,7 @@ ENTRY(efi_call3)
34919 RESTORE_PGT
34920 addq $32, %rsp
34921 RESTORE_XMM
34922+ pax_force_retaddr 0, 1
34923 ret
34924 ENDPROC(efi_call3)
34925
34926@@ -132,6 +137,7 @@ ENTRY(efi_call4)
34927 RESTORE_PGT
34928 addq $32, %rsp
34929 RESTORE_XMM
34930+ pax_force_retaddr 0, 1
34931 ret
34932 ENDPROC(efi_call4)
34933
34934@@ -147,6 +153,7 @@ ENTRY(efi_call5)
34935 RESTORE_PGT
34936 addq $48, %rsp
34937 RESTORE_XMM
34938+ pax_force_retaddr 0, 1
34939 ret
34940 ENDPROC(efi_call5)
34941
34942@@ -165,6 +172,7 @@ ENTRY(efi_call6)
34943 RESTORE_PGT
34944 addq $48, %rsp
34945 RESTORE_XMM
34946+ pax_force_retaddr 0, 1
34947 ret
34948 ENDPROC(efi_call6)
34949
34950diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34951index 1bbedc4..eb795b5 100644
34952--- a/arch/x86/platform/intel-mid/intel-mid.c
34953+++ b/arch/x86/platform/intel-mid/intel-mid.c
34954@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34955 {
34956 };
34957
34958-static void intel_mid_reboot(void)
34959+static void __noreturn intel_mid_reboot(void)
34960 {
34961 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34962+ BUG();
34963 }
34964
34965 static unsigned long __init intel_mid_calibrate_tsc(void)
34966diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34967index d6ee929..3637cb5 100644
34968--- a/arch/x86/platform/olpc/olpc_dt.c
34969+++ b/arch/x86/platform/olpc/olpc_dt.c
34970@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34971 return res;
34972 }
34973
34974-static struct of_pdt_ops prom_olpc_ops __initdata = {
34975+static struct of_pdt_ops prom_olpc_ops __initconst = {
34976 .nextprop = olpc_dt_nextprop,
34977 .getproplen = olpc_dt_getproplen,
34978 .getproperty = olpc_dt_getproperty,
34979diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34980index 424f4c9..f2a2988 100644
34981--- a/arch/x86/power/cpu.c
34982+++ b/arch/x86/power/cpu.c
34983@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34984 static void fix_processor_context(void)
34985 {
34986 int cpu = smp_processor_id();
34987- struct tss_struct *t = &per_cpu(init_tss, cpu);
34988-#ifdef CONFIG_X86_64
34989- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34990- tss_desc tss;
34991-#endif
34992+ struct tss_struct *t = init_tss + cpu;
34993+
34994 set_tss_desc(cpu, t); /*
34995 * This just modifies memory; should not be
34996 * necessary. But... This is necessary, because
34997@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34998 */
34999
35000 #ifdef CONFIG_X86_64
35001- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35002- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35003- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35004-
35005 syscall_init(); /* This sets MSR_*STAR and related */
35006 #endif
35007 load_TR_desc(); /* This does ltr */
35008diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35009index bad628a..a102610 100644
35010--- a/arch/x86/realmode/init.c
35011+++ b/arch/x86/realmode/init.c
35012@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35013 __va(real_mode_header->trampoline_header);
35014
35015 #ifdef CONFIG_X86_32
35016- trampoline_header->start = __pa_symbol(startup_32_smp);
35017+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35018+
35019+#ifdef CONFIG_PAX_KERNEXEC
35020+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35021+#endif
35022+
35023+ trampoline_header->boot_cs = __BOOT_CS;
35024 trampoline_header->gdt_limit = __BOOT_DS + 7;
35025 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35026 #else
35027@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35028 *trampoline_cr4_features = read_cr4();
35029
35030 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35031- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35032+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35033 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35034 #endif
35035 }
35036diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35037index 3497f14..cc73b92 100644
35038--- a/arch/x86/realmode/rm/Makefile
35039+++ b/arch/x86/realmode/rm/Makefile
35040@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35041
35042 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35043 -I$(srctree)/arch/x86/boot
35044+ifdef CONSTIFY_PLUGIN
35045+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35046+endif
35047 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35048 GCOV_PROFILE := n
35049diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35050index a28221d..93c40f1 100644
35051--- a/arch/x86/realmode/rm/header.S
35052+++ b/arch/x86/realmode/rm/header.S
35053@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35054 #endif
35055 /* APM/BIOS reboot */
35056 .long pa_machine_real_restart_asm
35057-#ifdef CONFIG_X86_64
35058+#ifdef CONFIG_X86_32
35059+ .long __KERNEL_CS
35060+#else
35061 .long __KERNEL32_CS
35062 #endif
35063 END(real_mode_header)
35064diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35065index 48ddd76..c26749f 100644
35066--- a/arch/x86/realmode/rm/trampoline_32.S
35067+++ b/arch/x86/realmode/rm/trampoline_32.S
35068@@ -24,6 +24,12 @@
35069 #include <asm/page_types.h>
35070 #include "realmode.h"
35071
35072+#ifdef CONFIG_PAX_KERNEXEC
35073+#define ta(X) (X)
35074+#else
35075+#define ta(X) (pa_ ## X)
35076+#endif
35077+
35078 .text
35079 .code16
35080
35081@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35082
35083 cli # We should be safe anyway
35084
35085- movl tr_start, %eax # where we need to go
35086-
35087 movl $0xA5A5A5A5, trampoline_status
35088 # write marker for master knows we're running
35089
35090@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35091 movw $1, %dx # protected mode (PE) bit
35092 lmsw %dx # into protected mode
35093
35094- ljmpl $__BOOT_CS, $pa_startup_32
35095+ ljmpl *(trampoline_header)
35096
35097 .section ".text32","ax"
35098 .code32
35099@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35100 .balign 8
35101 GLOBAL(trampoline_header)
35102 tr_start: .space 4
35103- tr_gdt_pad: .space 2
35104+ tr_boot_cs: .space 2
35105 tr_gdt: .space 6
35106 END(trampoline_header)
35107
35108diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35109index dac7b20..72dbaca 100644
35110--- a/arch/x86/realmode/rm/trampoline_64.S
35111+++ b/arch/x86/realmode/rm/trampoline_64.S
35112@@ -93,6 +93,7 @@ ENTRY(startup_32)
35113 movl %edx, %gs
35114
35115 movl pa_tr_cr4, %eax
35116+ andl $~X86_CR4_PCIDE, %eax
35117 movl %eax, %cr4 # Enable PAE mode
35118
35119 # Setup trampoline 4 level pagetables
35120@@ -106,7 +107,7 @@ ENTRY(startup_32)
35121 wrmsr
35122
35123 # Enable paging and in turn activate Long Mode
35124- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35125+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35126 movl %eax, %cr0
35127
35128 /*
35129diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35130index 9e7e147..25a4158 100644
35131--- a/arch/x86/realmode/rm/wakeup_asm.S
35132+++ b/arch/x86/realmode/rm/wakeup_asm.S
35133@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35134 lgdtl pmode_gdt
35135
35136 /* This really couldn't... */
35137- movl pmode_entry, %eax
35138 movl pmode_cr0, %ecx
35139 movl %ecx, %cr0
35140- ljmpl $__KERNEL_CS, $pa_startup_32
35141- /* -> jmp *%eax in trampoline_32.S */
35142+
35143+ ljmpl *pmode_entry
35144 #else
35145 jmp trampoline_start
35146 #endif
35147diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35148index 604a37e..e49702a 100644
35149--- a/arch/x86/tools/Makefile
35150+++ b/arch/x86/tools/Makefile
35151@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35152
35153 $(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
35154
35155-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35156+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35157 hostprogs-y += relocs
35158 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35159 PHONY += relocs
35160diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35161index bbb1d22..e505211 100644
35162--- a/arch/x86/tools/relocs.c
35163+++ b/arch/x86/tools/relocs.c
35164@@ -1,5 +1,7 @@
35165 /* This is included from relocs_32/64.c */
35166
35167+#include "../../../include/generated/autoconf.h"
35168+
35169 #define ElfW(type) _ElfW(ELF_BITS, type)
35170 #define _ElfW(bits, type) __ElfW(bits, type)
35171 #define __ElfW(bits, type) Elf##bits##_##type
35172@@ -11,6 +13,7 @@
35173 #define Elf_Sym ElfW(Sym)
35174
35175 static Elf_Ehdr ehdr;
35176+static Elf_Phdr *phdr;
35177
35178 struct relocs {
35179 uint32_t *offset;
35180@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35181 }
35182 }
35183
35184+static void read_phdrs(FILE *fp)
35185+{
35186+ unsigned int i;
35187+
35188+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35189+ if (!phdr) {
35190+ die("Unable to allocate %d program headers\n",
35191+ ehdr.e_phnum);
35192+ }
35193+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35194+ die("Seek to %d failed: %s\n",
35195+ ehdr.e_phoff, strerror(errno));
35196+ }
35197+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35198+ die("Cannot read ELF program headers: %s\n",
35199+ strerror(errno));
35200+ }
35201+ for(i = 0; i < ehdr.e_phnum; i++) {
35202+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35203+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35204+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35205+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35206+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35207+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35208+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35209+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35210+ }
35211+
35212+}
35213+
35214 static void read_shdrs(FILE *fp)
35215 {
35216- int i;
35217+ unsigned int i;
35218 Elf_Shdr shdr;
35219
35220 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35221@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35222
35223 static void read_strtabs(FILE *fp)
35224 {
35225- int i;
35226+ unsigned int i;
35227 for (i = 0; i < ehdr.e_shnum; i++) {
35228 struct section *sec = &secs[i];
35229 if (sec->shdr.sh_type != SHT_STRTAB) {
35230@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35231
35232 static void read_symtabs(FILE *fp)
35233 {
35234- int i,j;
35235+ unsigned int i,j;
35236 for (i = 0; i < ehdr.e_shnum; i++) {
35237 struct section *sec = &secs[i];
35238 if (sec->shdr.sh_type != SHT_SYMTAB) {
35239@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35240 }
35241
35242
35243-static void read_relocs(FILE *fp)
35244+static void read_relocs(FILE *fp, int use_real_mode)
35245 {
35246- int i,j;
35247+ unsigned int i,j;
35248+ uint32_t base;
35249+
35250 for (i = 0; i < ehdr.e_shnum; i++) {
35251 struct section *sec = &secs[i];
35252 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35253@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35254 die("Cannot read symbol table: %s\n",
35255 strerror(errno));
35256 }
35257+ base = 0;
35258+
35259+#ifdef CONFIG_X86_32
35260+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35261+ if (phdr[j].p_type != PT_LOAD )
35262+ continue;
35263+ 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)
35264+ continue;
35265+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35266+ break;
35267+ }
35268+#endif
35269+
35270 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35271 Elf_Rel *rel = &sec->reltab[j];
35272- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35273+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35274 rel->r_info = elf_xword_to_cpu(rel->r_info);
35275 #if (SHT_REL_TYPE == SHT_RELA)
35276 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35277@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35278
35279 static void print_absolute_symbols(void)
35280 {
35281- int i;
35282+ unsigned int i;
35283 const char *format;
35284
35285 if (ELF_BITS == 64)
35286@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35287 for (i = 0; i < ehdr.e_shnum; i++) {
35288 struct section *sec = &secs[i];
35289 char *sym_strtab;
35290- int j;
35291+ unsigned int j;
35292
35293 if (sec->shdr.sh_type != SHT_SYMTAB) {
35294 continue;
35295@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35296
35297 static void print_absolute_relocs(void)
35298 {
35299- int i, printed = 0;
35300+ unsigned int i, printed = 0;
35301 const char *format;
35302
35303 if (ELF_BITS == 64)
35304@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35305 struct section *sec_applies, *sec_symtab;
35306 char *sym_strtab;
35307 Elf_Sym *sh_symtab;
35308- int j;
35309+ unsigned int j;
35310 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35311 continue;
35312 }
35313@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35314 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35315 Elf_Sym *sym, const char *symname))
35316 {
35317- int i;
35318+ unsigned int i;
35319 /* Walk through the relocations */
35320 for (i = 0; i < ehdr.e_shnum; i++) {
35321 char *sym_strtab;
35322 Elf_Sym *sh_symtab;
35323 struct section *sec_applies, *sec_symtab;
35324- int j;
35325+ unsigned int j;
35326 struct section *sec = &secs[i];
35327
35328 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35329@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35330 {
35331 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35332 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35333+ char *sym_strtab = sec->link->link->strtab;
35334+
35335+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35336+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35337+ return 0;
35338+
35339+#ifdef CONFIG_PAX_KERNEXEC
35340+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35341+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35342+ return 0;
35343+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35344+ return 0;
35345+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35346+ return 0;
35347+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35348+ return 0;
35349+#endif
35350
35351 switch (r_type) {
35352 case R_386_NONE:
35353@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35354
35355 static void emit_relocs(int as_text, int use_real_mode)
35356 {
35357- int i;
35358+ unsigned int i;
35359 int (*write_reloc)(uint32_t, FILE *) = write32;
35360 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35361 const char *symname);
35362@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35363 {
35364 regex_init(use_real_mode);
35365 read_ehdr(fp);
35366+ read_phdrs(fp);
35367 read_shdrs(fp);
35368 read_strtabs(fp);
35369 read_symtabs(fp);
35370- read_relocs(fp);
35371+ read_relocs(fp, use_real_mode);
35372 if (ELF_BITS == 64)
35373 percpu_init();
35374 if (show_absolute_syms) {
35375diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35376index f40281e..92728c9 100644
35377--- a/arch/x86/um/mem_32.c
35378+++ b/arch/x86/um/mem_32.c
35379@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35380 gate_vma.vm_start = FIXADDR_USER_START;
35381 gate_vma.vm_end = FIXADDR_USER_END;
35382 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35383- gate_vma.vm_page_prot = __P101;
35384+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35385
35386 return 0;
35387 }
35388diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35389index 80ffa5b..a33bd15 100644
35390--- a/arch/x86/um/tls_32.c
35391+++ b/arch/x86/um/tls_32.c
35392@@ -260,7 +260,7 @@ out:
35393 if (unlikely(task == current &&
35394 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35395 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35396- "without flushed TLS.", current->pid);
35397+ "without flushed TLS.", task_pid_nr(current));
35398 }
35399
35400 return 0;
35401diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35402index c580d12..0a0ba35 100644
35403--- a/arch/x86/vdso/Makefile
35404+++ b/arch/x86/vdso/Makefile
35405@@ -196,7 +196,7 @@ quiet_cmd_vdso = VDSO $@
35406 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35407 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35408
35409-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35410+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35411 $(LTO_CFLAGS)
35412 GCOV_PROFILE := n
35413
35414diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35415index 3adf2e6..a0b5576 100644
35416--- a/arch/x86/vdso/vdso32-setup.c
35417+++ b/arch/x86/vdso/vdso32-setup.c
35418@@ -29,6 +29,7 @@
35419 #include <asm/fixmap.h>
35420 #include <asm/hpet.h>
35421 #include <asm/vvar.h>
35422+#include <asm/mman.h>
35423
35424 #ifdef CONFIG_COMPAT_VDSO
35425 #define VDSO_DEFAULT 0
35426@@ -98,7 +99,7 @@ void syscall32_cpu_init(void)
35427 void enable_sep_cpu(void)
35428 {
35429 int cpu = get_cpu();
35430- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35431+ struct tss_struct *tss = init_tss + cpu;
35432
35433 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35434 put_cpu();
35435@@ -166,7 +167,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35436
35437 down_write(&mm->mmap_sem);
35438
35439- addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, 0);
35440+ addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, MAP_EXECUTABLE);
35441 if (IS_ERR_VALUE(addr)) {
35442 ret = addr;
35443 goto up_fail;
35444@@ -174,7 +175,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35445
35446 addr += VDSO_OFFSET(VDSO_PREV_PAGES);
35447
35448- current->mm->context.vdso = (void *)addr;
35449+ current->mm->context.vdso = addr;
35450
35451 /*
35452 * MAYWRITE to allow gdb to COW and set breakpoints
35453@@ -223,11 +224,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35454 #endif
35455
35456 current_thread_info()->sysenter_return =
35457- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35458+ (void __force_user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35459
35460 up_fail:
35461 if (ret)
35462- current->mm->context.vdso = NULL;
35463+ current->mm->context.vdso = 0;
35464
35465 up_write(&mm->mmap_sem);
35466
35467@@ -274,8 +275,14 @@ __initcall(ia32_binfmt_init);
35468
35469 const char *arch_vma_name(struct vm_area_struct *vma)
35470 {
35471- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35472+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35473 return "[vdso]";
35474+
35475+#ifdef CONFIG_PAX_SEGMEXEC
35476+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35477+ return "[vdso]";
35478+#endif
35479+
35480 return NULL;
35481 }
35482
35483diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35484index 1ad1026..1a08abe 100644
35485--- a/arch/x86/vdso/vma.c
35486+++ b/arch/x86/vdso/vma.c
35487@@ -17,8 +17,6 @@
35488 #include <asm/page.h>
35489
35490 #if defined(CONFIG_X86_64)
35491-unsigned int __read_mostly vdso_enabled = 1;
35492-
35493 DECLARE_VDSO_IMAGE(vdso);
35494 extern unsigned short vdso_sync_cpuid;
35495 static unsigned vdso_size;
35496@@ -144,7 +142,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35497 * unaligned here as a result of stack start randomization.
35498 */
35499 addr = PAGE_ALIGN(addr);
35500- addr = align_vdso_addr(addr);
35501
35502 return addr;
35503 }
35504@@ -157,30 +154,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35505 unsigned size)
35506 {
35507 struct mm_struct *mm = current->mm;
35508- unsigned long addr;
35509+ unsigned long addr = 0;
35510 int ret;
35511
35512- if (!vdso_enabled)
35513- return 0;
35514-
35515 down_write(&mm->mmap_sem);
35516+
35517+#ifdef CONFIG_PAX_RANDMMAP
35518+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35519+#endif
35520+
35521 addr = vdso_addr(mm->start_stack, size);
35522+ addr = align_vdso_addr(addr);
35523 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35524 if (IS_ERR_VALUE(addr)) {
35525 ret = addr;
35526 goto up_fail;
35527 }
35528
35529- current->mm->context.vdso = (void *)addr;
35530+ mm->context.vdso = addr;
35531
35532 ret = install_special_mapping(mm, addr, size,
35533 VM_READ|VM_EXEC|
35534 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35535 pages);
35536- if (ret) {
35537- current->mm->context.vdso = NULL;
35538- goto up_fail;
35539- }
35540+ if (ret)
35541+ mm->context.vdso = 0;
35542
35543 up_fail:
35544 up_write(&mm->mmap_sem);
35545@@ -200,11 +198,4 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35546 vdsox32_size);
35547 }
35548 #endif
35549-
35550-static __init int vdso_setup(char *s)
35551-{
35552- vdso_enabled = simple_strtoul(s, NULL, 0);
35553- return 0;
35554-}
35555-__setup("vdso=", vdso_setup);
35556 #endif
35557diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35558index e88fda8..76ce7ce 100644
35559--- a/arch/x86/xen/Kconfig
35560+++ b/arch/x86/xen/Kconfig
35561@@ -9,6 +9,7 @@ config XEN
35562 select XEN_HAVE_PVMMU
35563 depends on X86_64 || (X86_32 && X86_PAE)
35564 depends on X86_TSC
35565+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35566 help
35567 This is the Linux Xen port. Enabling this will allow the
35568 kernel to boot in a paravirtualized environment under the
35569diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35570index c34bfc4..e599673 100644
35571--- a/arch/x86/xen/enlighten.c
35572+++ b/arch/x86/xen/enlighten.c
35573@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35574
35575 struct shared_info xen_dummy_shared_info;
35576
35577-void *xen_initial_gdt;
35578-
35579 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35580 __read_mostly int xen_have_vector_callback;
35581 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35582@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35583 {
35584 unsigned long va = dtr->address;
35585 unsigned int size = dtr->size + 1;
35586- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35587- unsigned long frames[pages];
35588+ unsigned long frames[65536 / PAGE_SIZE];
35589 int f;
35590
35591 /*
35592@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35593 {
35594 unsigned long va = dtr->address;
35595 unsigned int size = dtr->size + 1;
35596- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35597- unsigned long frames[pages];
35598+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35599 int f;
35600
35601 /*
35602@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35603 * 8-byte entries, or 16 4k pages..
35604 */
35605
35606- BUG_ON(size > 65536);
35607+ BUG_ON(size > GDT_SIZE);
35608 BUG_ON(va & ~PAGE_MASK);
35609
35610 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35611@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35612 return 0;
35613 }
35614
35615-static void set_xen_basic_apic_ops(void)
35616+static void __init set_xen_basic_apic_ops(void)
35617 {
35618 apic->read = xen_apic_read;
35619 apic->write = xen_apic_write;
35620@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35621 #endif
35622 };
35623
35624-static void xen_reboot(int reason)
35625+static __noreturn void xen_reboot(int reason)
35626 {
35627 struct sched_shutdown r = { .reason = reason };
35628
35629- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35630- BUG();
35631+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35632+ BUG();
35633 }
35634
35635-static void xen_restart(char *msg)
35636+static __noreturn void xen_restart(char *msg)
35637 {
35638 xen_reboot(SHUTDOWN_reboot);
35639 }
35640
35641-static void xen_emergency_restart(void)
35642+static __noreturn void xen_emergency_restart(void)
35643 {
35644 xen_reboot(SHUTDOWN_reboot);
35645 }
35646
35647-static void xen_machine_halt(void)
35648+static __noreturn void xen_machine_halt(void)
35649 {
35650 xen_reboot(SHUTDOWN_poweroff);
35651 }
35652
35653-static void xen_machine_power_off(void)
35654+static __noreturn void xen_machine_power_off(void)
35655 {
35656 if (pm_power_off)
35657 pm_power_off();
35658@@ -1564,7 +1560,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35659 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35660
35661 /* Work out if we support NX */
35662- x86_configure_nx();
35663+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35664+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35665+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35666+ unsigned l, h;
35667+
35668+ __supported_pte_mask |= _PAGE_NX;
35669+ rdmsr(MSR_EFER, l, h);
35670+ l |= EFER_NX;
35671+ wrmsr(MSR_EFER, l, h);
35672+ }
35673+#endif
35674
35675 /* Get mfn list */
35676 xen_build_dynamic_phys_to_machine();
35677@@ -1592,13 +1598,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35678
35679 machine_ops = xen_machine_ops;
35680
35681- /*
35682- * The only reliable way to retain the initial address of the
35683- * percpu gdt_page is to remember it here, so we can go and
35684- * mark it RW later, when the initial percpu area is freed.
35685- */
35686- xen_initial_gdt = &per_cpu(gdt_page, 0);
35687-
35688 xen_smp_init();
35689
35690 #ifdef CONFIG_ACPI_NUMA
35691diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35692index 86e02ea..e3705ca 100644
35693--- a/arch/x86/xen/mmu.c
35694+++ b/arch/x86/xen/mmu.c
35695@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35696 return val;
35697 }
35698
35699-static pteval_t pte_pfn_to_mfn(pteval_t val)
35700+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35701 {
35702 if (val & _PAGE_PRESENT) {
35703 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35704@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35705 /* L3_k[510] -> level2_kernel_pgt
35706 * L3_i[511] -> level2_fixmap_pgt */
35707 convert_pfn_mfn(level3_kernel_pgt);
35708+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35709+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35710+ convert_pfn_mfn(level3_vmemmap_pgt);
35711 }
35712 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35713 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35714@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35715 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35716 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35717 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35718+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35719+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35720+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35721 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35722 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35723+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35724 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35725 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35726
35727@@ -2122,6 +2129,7 @@ static void __init xen_post_allocator_init(void)
35728 pv_mmu_ops.set_pud = xen_set_pud;
35729 #if PAGETABLE_LEVELS == 4
35730 pv_mmu_ops.set_pgd = xen_set_pgd;
35731+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35732 #endif
35733
35734 /* This will work as long as patching hasn't happened yet
35735@@ -2200,6 +2208,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35736 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35737 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35738 .set_pgd = xen_set_pgd_hyper,
35739+ .set_pgd_batched = xen_set_pgd_hyper,
35740
35741 .alloc_pud = xen_alloc_pmd_init,
35742 .release_pud = xen_release_pmd_init,
35743diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35744index 7005974..54fb05f 100644
35745--- a/arch/x86/xen/smp.c
35746+++ b/arch/x86/xen/smp.c
35747@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35748
35749 if (xen_pv_domain()) {
35750 if (!xen_feature(XENFEAT_writable_page_tables))
35751- /* We've switched to the "real" per-cpu gdt, so make
35752- * sure the old memory can be recycled. */
35753- make_lowmem_page_readwrite(xen_initial_gdt);
35754-
35755 #ifdef CONFIG_X86_32
35756 /*
35757 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35758 * expects __USER_DS
35759 */
35760- loadsegment(ds, __USER_DS);
35761- loadsegment(es, __USER_DS);
35762+ loadsegment(ds, __KERNEL_DS);
35763+ loadsegment(es, __KERNEL_DS);
35764 #endif
35765
35766 xen_filter_cpu_maps();
35767@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35768 #ifdef CONFIG_X86_32
35769 /* Note: PVH is not yet supported on x86_32. */
35770 ctxt->user_regs.fs = __KERNEL_PERCPU;
35771- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35772+ savesegment(gs, ctxt->user_regs.gs);
35773 #endif
35774 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35775
35776@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35777 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35778 ctxt->flags = VGCF_IN_KERNEL;
35779 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35780- ctxt->user_regs.ds = __USER_DS;
35781- ctxt->user_regs.es = __USER_DS;
35782+ ctxt->user_regs.ds = __KERNEL_DS;
35783+ ctxt->user_regs.es = __KERNEL_DS;
35784 ctxt->user_regs.ss = __KERNEL_DS;
35785
35786 xen_copy_trap_info(ctxt->trap_ctxt);
35787@@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35788 int rc;
35789
35790 per_cpu(current_task, cpu) = idle;
35791+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35792 #ifdef CONFIG_X86_32
35793 irq_ctx_init(cpu);
35794 #else
35795 clear_tsk_thread_flag(idle, TIF_FORK);
35796 #endif
35797- per_cpu(kernel_stack, cpu) =
35798- (unsigned long)task_stack_page(idle) -
35799- KERNEL_STACK_OFFSET + THREAD_SIZE;
35800+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35801
35802 xen_setup_runstate_info(cpu);
35803 xen_setup_timer(cpu);
35804@@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35805
35806 void __init xen_smp_init(void)
35807 {
35808- smp_ops = xen_smp_ops;
35809+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35810 xen_fill_possible_map();
35811 }
35812
35813diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35814index fd92a64..1f72641 100644
35815--- a/arch/x86/xen/xen-asm_32.S
35816+++ b/arch/x86/xen/xen-asm_32.S
35817@@ -99,7 +99,7 @@ ENTRY(xen_iret)
35818 pushw %fs
35819 movl $(__KERNEL_PERCPU), %eax
35820 movl %eax, %fs
35821- movl %fs:xen_vcpu, %eax
35822+ mov PER_CPU_VAR(xen_vcpu), %eax
35823 POP_FS
35824 #else
35825 movl %ss:xen_vcpu, %eax
35826diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35827index 485b695..fda3e7c 100644
35828--- a/arch/x86/xen/xen-head.S
35829+++ b/arch/x86/xen/xen-head.S
35830@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35831 #ifdef CONFIG_X86_32
35832 mov %esi,xen_start_info
35833 mov $init_thread_union+THREAD_SIZE,%esp
35834+#ifdef CONFIG_SMP
35835+ movl $cpu_gdt_table,%edi
35836+ movl $__per_cpu_load,%eax
35837+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35838+ rorl $16,%eax
35839+ movb %al,__KERNEL_PERCPU + 4(%edi)
35840+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35841+ movl $__per_cpu_end - 1,%eax
35842+ subl $__per_cpu_start,%eax
35843+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35844+#endif
35845 #else
35846 mov %rsi,xen_start_info
35847 mov $init_thread_union+THREAD_SIZE,%rsp
35848diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35849index 1cb6f4c..9981524 100644
35850--- a/arch/x86/xen/xen-ops.h
35851+++ b/arch/x86/xen/xen-ops.h
35852@@ -10,8 +10,6 @@
35853 extern const char xen_hypervisor_callback[];
35854 extern const char xen_failsafe_callback[];
35855
35856-extern void *xen_initial_gdt;
35857-
35858 struct trap_info;
35859 void xen_copy_trap_info(struct trap_info *traps);
35860
35861diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35862index 525bd3d..ef888b1 100644
35863--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35864+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35865@@ -119,9 +119,9 @@
35866 ----------------------------------------------------------------------*/
35867
35868 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35869-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35870 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35871 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35872+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35873
35874 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35875 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35876diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35877index 2f33760..835e50a 100644
35878--- a/arch/xtensa/variants/fsf/include/variant/core.h
35879+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35880@@ -11,6 +11,7 @@
35881 #ifndef _XTENSA_CORE_H
35882 #define _XTENSA_CORE_H
35883
35884+#include <linux/const.h>
35885
35886 /****************************************************************************
35887 Parameters Useful for Any Code, USER or PRIVILEGED
35888@@ -112,9 +113,9 @@
35889 ----------------------------------------------------------------------*/
35890
35891 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35892-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35893 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35894 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35895+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35896
35897 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35898 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35899diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35900index af00795..2bb8105 100644
35901--- a/arch/xtensa/variants/s6000/include/variant/core.h
35902+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35903@@ -11,6 +11,7 @@
35904 #ifndef _XTENSA_CORE_CONFIGURATION_H
35905 #define _XTENSA_CORE_CONFIGURATION_H
35906
35907+#include <linux/const.h>
35908
35909 /****************************************************************************
35910 Parameters Useful for Any Code, USER or PRIVILEGED
35911@@ -118,9 +119,9 @@
35912 ----------------------------------------------------------------------*/
35913
35914 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35915-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35916 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35917 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35918+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35919
35920 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35921 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35922diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35923index f1e3803..05e2d06 100644
35924--- a/block/blk-cgroup.c
35925+++ b/block/blk-cgroup.c
35926@@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35927 static struct cgroup_subsys_state *
35928 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35929 {
35930- static atomic64_t id_seq = ATOMIC64_INIT(0);
35931+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35932 struct blkcg *blkcg;
35933
35934 if (!parent_css) {
35935@@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35936
35937 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35938 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35939- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35940+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35941 done:
35942 spin_lock_init(&blkcg->lock);
35943 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35944diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35945index c11d24e..e915d24 100644
35946--- a/block/blk-iopoll.c
35947+++ b/block/blk-iopoll.c
35948@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35949 }
35950 EXPORT_SYMBOL(blk_iopoll_complete);
35951
35952-static void blk_iopoll_softirq(struct softirq_action *h)
35953+static __latent_entropy void blk_iopoll_softirq(void)
35954 {
35955 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35956 int rearm = 0, budget = blk_iopoll_budget;
35957diff --git a/block/blk-map.c b/block/blk-map.c
35958index f7b22bc..ec2ddf4 100644
35959--- a/block/blk-map.c
35960+++ b/block/blk-map.c
35961@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35962 if (!len || !kbuf)
35963 return -EINVAL;
35964
35965- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35966+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35967 if (do_copy)
35968 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35969 else
35970diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35971index 53b1737..08177d2e 100644
35972--- a/block/blk-softirq.c
35973+++ b/block/blk-softirq.c
35974@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35975 * Softirq action handler - move entries to local list and loop over them
35976 * while passing them to the queue registered handler.
35977 */
35978-static void blk_done_softirq(struct softirq_action *h)
35979+static __latent_entropy void blk_done_softirq(void)
35980 {
35981 struct list_head *cpu_list, local_list;
35982
35983diff --git a/block/bsg.c b/block/bsg.c
35984index 420a5a9..23834aa 100644
35985--- a/block/bsg.c
35986+++ b/block/bsg.c
35987@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35988 struct sg_io_v4 *hdr, struct bsg_device *bd,
35989 fmode_t has_write_perm)
35990 {
35991+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35992+ unsigned char *cmdptr;
35993+
35994 if (hdr->request_len > BLK_MAX_CDB) {
35995 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35996 if (!rq->cmd)
35997 return -ENOMEM;
35998- }
35999+ cmdptr = rq->cmd;
36000+ } else
36001+ cmdptr = tmpcmd;
36002
36003- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36004+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36005 hdr->request_len))
36006 return -EFAULT;
36007
36008+ if (cmdptr != rq->cmd)
36009+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36010+
36011 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36012 if (blk_verify_command(rq->cmd, has_write_perm))
36013 return -EPERM;
36014diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36015index a0926a6..b2b14b2 100644
36016--- a/block/compat_ioctl.c
36017+++ b/block/compat_ioctl.c
36018@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36019 cgc = compat_alloc_user_space(sizeof(*cgc));
36020 cgc32 = compat_ptr(arg);
36021
36022- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36023+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36024 get_user(data, &cgc32->buffer) ||
36025 put_user(compat_ptr(data), &cgc->buffer) ||
36026 copy_in_user(&cgc->buflen, &cgc32->buflen,
36027@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36028 err |= __get_user(f->spec1, &uf->spec1);
36029 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36030 err |= __get_user(name, &uf->name);
36031- f->name = compat_ptr(name);
36032+ f->name = (void __force_kernel *)compat_ptr(name);
36033 if (err) {
36034 err = -EFAULT;
36035 goto out;
36036diff --git a/block/genhd.c b/block/genhd.c
36037index 791f419..89f21c4 100644
36038--- a/block/genhd.c
36039+++ b/block/genhd.c
36040@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36041
36042 /*
36043 * Register device numbers dev..(dev+range-1)
36044- * range must be nonzero
36045+ * Noop if @range is zero.
36046 * The hash chain is sorted on range, so that subranges can override.
36047 */
36048 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36049 struct kobject *(*probe)(dev_t, int *, void *),
36050 int (*lock)(dev_t, void *), void *data)
36051 {
36052- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36053+ if (range)
36054+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36055 }
36056
36057 EXPORT_SYMBOL(blk_register_region);
36058
36059+/* undo blk_register_region(), noop if @range is zero */
36060 void blk_unregister_region(dev_t devt, unsigned long range)
36061 {
36062- kobj_unmap(bdev_map, devt, range);
36063+ if (range)
36064+ kobj_unmap(bdev_map, devt, range);
36065 }
36066
36067 EXPORT_SYMBOL(blk_unregister_region);
36068diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36069index dc51f46..d5446a8 100644
36070--- a/block/partitions/efi.c
36071+++ b/block/partitions/efi.c
36072@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36073 if (!gpt)
36074 return NULL;
36075
36076+ if (!le32_to_cpu(gpt->num_partition_entries))
36077+ return NULL;
36078+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36079+ if (!pte)
36080+ return NULL;
36081+
36082 count = le32_to_cpu(gpt->num_partition_entries) *
36083 le32_to_cpu(gpt->sizeof_partition_entry);
36084- if (!count)
36085- return NULL;
36086- pte = kmalloc(count, GFP_KERNEL);
36087- if (!pte)
36088- return NULL;
36089-
36090 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36091 (u8 *) pte, count) < count) {
36092 kfree(pte);
36093diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36094index 2648797..92ed21f 100644
36095--- a/block/scsi_ioctl.c
36096+++ b/block/scsi_ioctl.c
36097@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36098 return put_user(0, p);
36099 }
36100
36101-static int sg_get_timeout(struct request_queue *q)
36102+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36103 {
36104 return jiffies_to_clock_t(q->sg_timeout);
36105 }
36106@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36107 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36108 struct sg_io_hdr *hdr, fmode_t mode)
36109 {
36110- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36111+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36112+ unsigned char *cmdptr;
36113+
36114+ if (rq->cmd != rq->__cmd)
36115+ cmdptr = rq->cmd;
36116+ else
36117+ cmdptr = tmpcmd;
36118+
36119+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36120 return -EFAULT;
36121+
36122+ if (cmdptr != rq->cmd)
36123+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36124+
36125 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36126 return -EPERM;
36127
36128@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36129 int err;
36130 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36131 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36132+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36133+ unsigned char *cmdptr;
36134
36135 if (!sic)
36136 return -EINVAL;
36137@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36138 */
36139 err = -EFAULT;
36140 rq->cmd_len = cmdlen;
36141- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36142+
36143+ if (rq->cmd != rq->__cmd)
36144+ cmdptr = rq->cmd;
36145+ else
36146+ cmdptr = tmpcmd;
36147+
36148+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36149 goto error;
36150
36151+ if (rq->cmd != cmdptr)
36152+ memcpy(rq->cmd, cmdptr, cmdlen);
36153+
36154 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36155 goto error;
36156
36157diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36158index 7bdd61b..afec999 100644
36159--- a/crypto/cryptd.c
36160+++ b/crypto/cryptd.c
36161@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36162
36163 struct cryptd_blkcipher_request_ctx {
36164 crypto_completion_t complete;
36165-};
36166+} __no_const;
36167
36168 struct cryptd_hash_ctx {
36169 struct crypto_shash *child;
36170@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36171
36172 struct cryptd_aead_request_ctx {
36173 crypto_completion_t complete;
36174-};
36175+} __no_const;
36176
36177 static void cryptd_queue_worker(struct work_struct *work);
36178
36179diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36180index 309d345..1632720 100644
36181--- a/crypto/pcrypt.c
36182+++ b/crypto/pcrypt.c
36183@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36184 int ret;
36185
36186 pinst->kobj.kset = pcrypt_kset;
36187- ret = kobject_add(&pinst->kobj, NULL, name);
36188+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36189 if (!ret)
36190 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36191
36192diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36193index 6921c7f..78e1af7 100644
36194--- a/drivers/acpi/acpica/hwxfsleep.c
36195+++ b/drivers/acpi/acpica/hwxfsleep.c
36196@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36197 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36198
36199 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36200- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36201- acpi_hw_extended_sleep},
36202- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36203- acpi_hw_extended_wake_prep},
36204- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36205+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36206+ .extended_function = acpi_hw_extended_sleep},
36207+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36208+ .extended_function = acpi_hw_extended_wake_prep},
36209+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36210+ .extended_function = acpi_hw_extended_wake}
36211 };
36212
36213 /*
36214diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36215index e5bcd91..74f050d 100644
36216--- a/drivers/acpi/apei/apei-internal.h
36217+++ b/drivers/acpi/apei/apei-internal.h
36218@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36219 struct apei_exec_ins_type {
36220 u32 flags;
36221 apei_exec_ins_func_t run;
36222-};
36223+} __do_const;
36224
36225 struct apei_exec_context {
36226 u32 ip;
36227diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36228index dab7cb7..f0d2994 100644
36229--- a/drivers/acpi/apei/ghes.c
36230+++ b/drivers/acpi/apei/ghes.c
36231@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36232 const struct acpi_hest_generic *generic,
36233 const struct acpi_generic_status *estatus)
36234 {
36235- static atomic_t seqno;
36236+ static atomic_unchecked_t seqno;
36237 unsigned int curr_seqno;
36238 char pfx_seq[64];
36239
36240@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36241 else
36242 pfx = KERN_ERR;
36243 }
36244- curr_seqno = atomic_inc_return(&seqno);
36245+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36246 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36247 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36248 pfx_seq, generic->header.source_id);
36249diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36250index a83e3c6..c3d617f 100644
36251--- a/drivers/acpi/bgrt.c
36252+++ b/drivers/acpi/bgrt.c
36253@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36254 if (!bgrt_image)
36255 return -ENODEV;
36256
36257- bin_attr_image.private = bgrt_image;
36258- bin_attr_image.size = bgrt_image_size;
36259+ pax_open_kernel();
36260+ *(void **)&bin_attr_image.private = bgrt_image;
36261+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36262+ pax_close_kernel();
36263
36264 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36265 if (!bgrt_kobj)
36266diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36267index 3d8413d..95f638c 100644
36268--- a/drivers/acpi/blacklist.c
36269+++ b/drivers/acpi/blacklist.c
36270@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36271 u32 is_critical_error;
36272 };
36273
36274-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36275+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36276
36277 /*
36278 * POLICY: If *anything* doesn't work, put it on the blacklist.
36279@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36280 return 0;
36281 }
36282
36283-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36284+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36285 {
36286 .callback = dmi_disable_osi_vista,
36287 .ident = "Fujitsu Siemens",
36288diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36289index c68e724..e863008 100644
36290--- a/drivers/acpi/custom_method.c
36291+++ b/drivers/acpi/custom_method.c
36292@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36293 struct acpi_table_header table;
36294 acpi_status status;
36295
36296+#ifdef CONFIG_GRKERNSEC_KMEM
36297+ return -EPERM;
36298+#endif
36299+
36300 if (!(*ppos)) {
36301 /* parse the table header to get the table length */
36302 if (count <= sizeof(struct acpi_table_header))
36303diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36304index 3dca36d..abaf070 100644
36305--- a/drivers/acpi/processor_idle.c
36306+++ b/drivers/acpi/processor_idle.c
36307@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36308 {
36309 int i, count = CPUIDLE_DRIVER_STATE_START;
36310 struct acpi_processor_cx *cx;
36311- struct cpuidle_state *state;
36312+ cpuidle_state_no_const *state;
36313 struct cpuidle_driver *drv = &acpi_idle_driver;
36314
36315 if (!pr->flags.power_setup_done)
36316diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36317index 38cb978..352c761 100644
36318--- a/drivers/acpi/sysfs.c
36319+++ b/drivers/acpi/sysfs.c
36320@@ -423,11 +423,11 @@ static u32 num_counters;
36321 static struct attribute **all_attrs;
36322 static u32 acpi_gpe_count;
36323
36324-static struct attribute_group interrupt_stats_attr_group = {
36325+static attribute_group_no_const interrupt_stats_attr_group = {
36326 .name = "interrupts",
36327 };
36328
36329-static struct kobj_attribute *counter_attrs;
36330+static kobj_attribute_no_const *counter_attrs;
36331
36332 static void delete_gpe_attr_array(void)
36333 {
36334diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36335index b986145..82bddb8 100644
36336--- a/drivers/ata/libahci.c
36337+++ b/drivers/ata/libahci.c
36338@@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36339 }
36340 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36341
36342-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36343+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36344 struct ata_taskfile *tf, int is_cmd, u16 flags,
36345 unsigned long timeout_msec)
36346 {
36347diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36348index 677c0c1..354b89b 100644
36349--- a/drivers/ata/libata-core.c
36350+++ b/drivers/ata/libata-core.c
36351@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36352 static void ata_dev_xfermask(struct ata_device *dev);
36353 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36354
36355-atomic_t ata_print_id = ATOMIC_INIT(0);
36356+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36357
36358 struct ata_force_param {
36359 const char *name;
36360@@ -4863,7 +4863,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36361 struct ata_port *ap;
36362 unsigned int tag;
36363
36364- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36365+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36366 ap = qc->ap;
36367
36368 qc->flags = 0;
36369@@ -4879,7 +4879,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36370 struct ata_port *ap;
36371 struct ata_link *link;
36372
36373- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36374+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36375 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36376 ap = qc->ap;
36377 link = qc->dev->link;
36378@@ -5983,6 +5983,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36379 return;
36380
36381 spin_lock(&lock);
36382+ pax_open_kernel();
36383
36384 for (cur = ops->inherits; cur; cur = cur->inherits) {
36385 void **inherit = (void **)cur;
36386@@ -5996,8 +5997,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36387 if (IS_ERR(*pp))
36388 *pp = NULL;
36389
36390- ops->inherits = NULL;
36391+ *(struct ata_port_operations **)&ops->inherits = NULL;
36392
36393+ pax_close_kernel();
36394 spin_unlock(&lock);
36395 }
36396
36397@@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36398
36399 /* give ports names and add SCSI hosts */
36400 for (i = 0; i < host->n_ports; i++) {
36401- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36402+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36403 host->ports[i]->local_port_no = i + 1;
36404 }
36405
36406diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36407index ef8567d..8bdbd03 100644
36408--- a/drivers/ata/libata-scsi.c
36409+++ b/drivers/ata/libata-scsi.c
36410@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36411
36412 if (rc)
36413 return rc;
36414- ap->print_id = atomic_inc_return(&ata_print_id);
36415+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36416 return 0;
36417 }
36418 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36419diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36420index 45b5ab3..98446b8 100644
36421--- a/drivers/ata/libata.h
36422+++ b/drivers/ata/libata.h
36423@@ -53,7 +53,7 @@ enum {
36424 ATA_DNXFER_QUIET = (1 << 31),
36425 };
36426
36427-extern atomic_t ata_print_id;
36428+extern atomic_unchecked_t ata_print_id;
36429 extern int atapi_passthru16;
36430 extern int libata_fua;
36431 extern int libata_noacpi;
36432diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36433index 4edb1a8..84e1658 100644
36434--- a/drivers/ata/pata_arasan_cf.c
36435+++ b/drivers/ata/pata_arasan_cf.c
36436@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36437 /* Handle platform specific quirks */
36438 if (quirk) {
36439 if (quirk & CF_BROKEN_PIO) {
36440- ap->ops->set_piomode = NULL;
36441+ pax_open_kernel();
36442+ *(void **)&ap->ops->set_piomode = NULL;
36443+ pax_close_kernel();
36444 ap->pio_mask = 0;
36445 }
36446 if (quirk & CF_BROKEN_MWDMA)
36447diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36448index f9b983a..887b9d8 100644
36449--- a/drivers/atm/adummy.c
36450+++ b/drivers/atm/adummy.c
36451@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36452 vcc->pop(vcc, skb);
36453 else
36454 dev_kfree_skb_any(skb);
36455- atomic_inc(&vcc->stats->tx);
36456+ atomic_inc_unchecked(&vcc->stats->tx);
36457
36458 return 0;
36459 }
36460diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36461index f1a9198..f466a4a 100644
36462--- a/drivers/atm/ambassador.c
36463+++ b/drivers/atm/ambassador.c
36464@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36465 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36466
36467 // VC layer stats
36468- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36469+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36470
36471 // free the descriptor
36472 kfree (tx_descr);
36473@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36474 dump_skb ("<<<", vc, skb);
36475
36476 // VC layer stats
36477- atomic_inc(&atm_vcc->stats->rx);
36478+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36479 __net_timestamp(skb);
36480 // end of our responsibility
36481 atm_vcc->push (atm_vcc, skb);
36482@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36483 } else {
36484 PRINTK (KERN_INFO, "dropped over-size frame");
36485 // should we count this?
36486- atomic_inc(&atm_vcc->stats->rx_drop);
36487+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36488 }
36489
36490 } else {
36491@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36492 }
36493
36494 if (check_area (skb->data, skb->len)) {
36495- atomic_inc(&atm_vcc->stats->tx_err);
36496+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36497 return -ENOMEM; // ?
36498 }
36499
36500diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36501index 0e3f8f9..765a7a5 100644
36502--- a/drivers/atm/atmtcp.c
36503+++ b/drivers/atm/atmtcp.c
36504@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36505 if (vcc->pop) vcc->pop(vcc,skb);
36506 else dev_kfree_skb(skb);
36507 if (dev_data) return 0;
36508- atomic_inc(&vcc->stats->tx_err);
36509+ atomic_inc_unchecked(&vcc->stats->tx_err);
36510 return -ENOLINK;
36511 }
36512 size = skb->len+sizeof(struct atmtcp_hdr);
36513@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36514 if (!new_skb) {
36515 if (vcc->pop) vcc->pop(vcc,skb);
36516 else dev_kfree_skb(skb);
36517- atomic_inc(&vcc->stats->tx_err);
36518+ atomic_inc_unchecked(&vcc->stats->tx_err);
36519 return -ENOBUFS;
36520 }
36521 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36522@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36523 if (vcc->pop) vcc->pop(vcc,skb);
36524 else dev_kfree_skb(skb);
36525 out_vcc->push(out_vcc,new_skb);
36526- atomic_inc(&vcc->stats->tx);
36527- atomic_inc(&out_vcc->stats->rx);
36528+ atomic_inc_unchecked(&vcc->stats->tx);
36529+ atomic_inc_unchecked(&out_vcc->stats->rx);
36530 return 0;
36531 }
36532
36533@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36534 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36535 read_unlock(&vcc_sklist_lock);
36536 if (!out_vcc) {
36537- atomic_inc(&vcc->stats->tx_err);
36538+ atomic_inc_unchecked(&vcc->stats->tx_err);
36539 goto done;
36540 }
36541 skb_pull(skb,sizeof(struct atmtcp_hdr));
36542@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36543 __net_timestamp(new_skb);
36544 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36545 out_vcc->push(out_vcc,new_skb);
36546- atomic_inc(&vcc->stats->tx);
36547- atomic_inc(&out_vcc->stats->rx);
36548+ atomic_inc_unchecked(&vcc->stats->tx);
36549+ atomic_inc_unchecked(&out_vcc->stats->rx);
36550 done:
36551 if (vcc->pop) vcc->pop(vcc,skb);
36552 else dev_kfree_skb(skb);
36553diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36554index b1955ba..b179940 100644
36555--- a/drivers/atm/eni.c
36556+++ b/drivers/atm/eni.c
36557@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36558 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36559 vcc->dev->number);
36560 length = 0;
36561- atomic_inc(&vcc->stats->rx_err);
36562+ atomic_inc_unchecked(&vcc->stats->rx_err);
36563 }
36564 else {
36565 length = ATM_CELL_SIZE-1; /* no HEC */
36566@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36567 size);
36568 }
36569 eff = length = 0;
36570- atomic_inc(&vcc->stats->rx_err);
36571+ atomic_inc_unchecked(&vcc->stats->rx_err);
36572 }
36573 else {
36574 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36575@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36576 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36577 vcc->dev->number,vcc->vci,length,size << 2,descr);
36578 length = eff = 0;
36579- atomic_inc(&vcc->stats->rx_err);
36580+ atomic_inc_unchecked(&vcc->stats->rx_err);
36581 }
36582 }
36583 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36584@@ -767,7 +767,7 @@ rx_dequeued++;
36585 vcc->push(vcc,skb);
36586 pushed++;
36587 }
36588- atomic_inc(&vcc->stats->rx);
36589+ atomic_inc_unchecked(&vcc->stats->rx);
36590 }
36591 wake_up(&eni_dev->rx_wait);
36592 }
36593@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36594 PCI_DMA_TODEVICE);
36595 if (vcc->pop) vcc->pop(vcc,skb);
36596 else dev_kfree_skb_irq(skb);
36597- atomic_inc(&vcc->stats->tx);
36598+ atomic_inc_unchecked(&vcc->stats->tx);
36599 wake_up(&eni_dev->tx_wait);
36600 dma_complete++;
36601 }
36602diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36603index 82f2ae0..f205c02 100644
36604--- a/drivers/atm/firestream.c
36605+++ b/drivers/atm/firestream.c
36606@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36607 }
36608 }
36609
36610- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36611+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36612
36613 fs_dprintk (FS_DEBUG_TXMEM, "i");
36614 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36615@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36616 #endif
36617 skb_put (skb, qe->p1 & 0xffff);
36618 ATM_SKB(skb)->vcc = atm_vcc;
36619- atomic_inc(&atm_vcc->stats->rx);
36620+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36621 __net_timestamp(skb);
36622 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36623 atm_vcc->push (atm_vcc, skb);
36624@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36625 kfree (pe);
36626 }
36627 if (atm_vcc)
36628- atomic_inc(&atm_vcc->stats->rx_drop);
36629+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36630 break;
36631 case 0x1f: /* Reassembly abort: no buffers. */
36632 /* Silently increment error counter. */
36633 if (atm_vcc)
36634- atomic_inc(&atm_vcc->stats->rx_drop);
36635+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36636 break;
36637 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36638 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36639diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36640index 204814e..cede831 100644
36641--- a/drivers/atm/fore200e.c
36642+++ b/drivers/atm/fore200e.c
36643@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36644 #endif
36645 /* check error condition */
36646 if (*entry->status & STATUS_ERROR)
36647- atomic_inc(&vcc->stats->tx_err);
36648+ atomic_inc_unchecked(&vcc->stats->tx_err);
36649 else
36650- atomic_inc(&vcc->stats->tx);
36651+ atomic_inc_unchecked(&vcc->stats->tx);
36652 }
36653 }
36654
36655@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36656 if (skb == NULL) {
36657 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36658
36659- atomic_inc(&vcc->stats->rx_drop);
36660+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36661 return -ENOMEM;
36662 }
36663
36664@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36665
36666 dev_kfree_skb_any(skb);
36667
36668- atomic_inc(&vcc->stats->rx_drop);
36669+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36670 return -ENOMEM;
36671 }
36672
36673 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36674
36675 vcc->push(vcc, skb);
36676- atomic_inc(&vcc->stats->rx);
36677+ atomic_inc_unchecked(&vcc->stats->rx);
36678
36679 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36680
36681@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36682 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36683 fore200e->atm_dev->number,
36684 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36685- atomic_inc(&vcc->stats->rx_err);
36686+ atomic_inc_unchecked(&vcc->stats->rx_err);
36687 }
36688 }
36689
36690@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36691 goto retry_here;
36692 }
36693
36694- atomic_inc(&vcc->stats->tx_err);
36695+ atomic_inc_unchecked(&vcc->stats->tx_err);
36696
36697 fore200e->tx_sat++;
36698 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36699diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36700index aa6be26..f70a785 100644
36701--- a/drivers/atm/he.c
36702+++ b/drivers/atm/he.c
36703@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36704
36705 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36706 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36707- atomic_inc(&vcc->stats->rx_drop);
36708+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36709 goto return_host_buffers;
36710 }
36711
36712@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36713 RBRQ_LEN_ERR(he_dev->rbrq_head)
36714 ? "LEN_ERR" : "",
36715 vcc->vpi, vcc->vci);
36716- atomic_inc(&vcc->stats->rx_err);
36717+ atomic_inc_unchecked(&vcc->stats->rx_err);
36718 goto return_host_buffers;
36719 }
36720
36721@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36722 vcc->push(vcc, skb);
36723 spin_lock(&he_dev->global_lock);
36724
36725- atomic_inc(&vcc->stats->rx);
36726+ atomic_inc_unchecked(&vcc->stats->rx);
36727
36728 return_host_buffers:
36729 ++pdus_assembled;
36730@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36731 tpd->vcc->pop(tpd->vcc, tpd->skb);
36732 else
36733 dev_kfree_skb_any(tpd->skb);
36734- atomic_inc(&tpd->vcc->stats->tx_err);
36735+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36736 }
36737 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36738 return;
36739@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36740 vcc->pop(vcc, skb);
36741 else
36742 dev_kfree_skb_any(skb);
36743- atomic_inc(&vcc->stats->tx_err);
36744+ atomic_inc_unchecked(&vcc->stats->tx_err);
36745 return -EINVAL;
36746 }
36747
36748@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36749 vcc->pop(vcc, skb);
36750 else
36751 dev_kfree_skb_any(skb);
36752- atomic_inc(&vcc->stats->tx_err);
36753+ atomic_inc_unchecked(&vcc->stats->tx_err);
36754 return -EINVAL;
36755 }
36756 #endif
36757@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36758 vcc->pop(vcc, skb);
36759 else
36760 dev_kfree_skb_any(skb);
36761- atomic_inc(&vcc->stats->tx_err);
36762+ atomic_inc_unchecked(&vcc->stats->tx_err);
36763 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36764 return -ENOMEM;
36765 }
36766@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36767 vcc->pop(vcc, skb);
36768 else
36769 dev_kfree_skb_any(skb);
36770- atomic_inc(&vcc->stats->tx_err);
36771+ atomic_inc_unchecked(&vcc->stats->tx_err);
36772 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36773 return -ENOMEM;
36774 }
36775@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36776 __enqueue_tpd(he_dev, tpd, cid);
36777 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36778
36779- atomic_inc(&vcc->stats->tx);
36780+ atomic_inc_unchecked(&vcc->stats->tx);
36781
36782 return 0;
36783 }
36784diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36785index 1dc0519..1aadaf7 100644
36786--- a/drivers/atm/horizon.c
36787+++ b/drivers/atm/horizon.c
36788@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36789 {
36790 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36791 // VC layer stats
36792- atomic_inc(&vcc->stats->rx);
36793+ atomic_inc_unchecked(&vcc->stats->rx);
36794 __net_timestamp(skb);
36795 // end of our responsibility
36796 vcc->push (vcc, skb);
36797@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36798 dev->tx_iovec = NULL;
36799
36800 // VC layer stats
36801- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36802+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36803
36804 // free the skb
36805 hrz_kfree_skb (skb);
36806diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36807index 1bdf104..9dc44b1 100644
36808--- a/drivers/atm/idt77252.c
36809+++ b/drivers/atm/idt77252.c
36810@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36811 else
36812 dev_kfree_skb(skb);
36813
36814- atomic_inc(&vcc->stats->tx);
36815+ atomic_inc_unchecked(&vcc->stats->tx);
36816 }
36817
36818 atomic_dec(&scq->used);
36819@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36820 if ((sb = dev_alloc_skb(64)) == NULL) {
36821 printk("%s: Can't allocate buffers for aal0.\n",
36822 card->name);
36823- atomic_add(i, &vcc->stats->rx_drop);
36824+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36825 break;
36826 }
36827 if (!atm_charge(vcc, sb->truesize)) {
36828 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36829 card->name);
36830- atomic_add(i - 1, &vcc->stats->rx_drop);
36831+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36832 dev_kfree_skb(sb);
36833 break;
36834 }
36835@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36836 ATM_SKB(sb)->vcc = vcc;
36837 __net_timestamp(sb);
36838 vcc->push(vcc, sb);
36839- atomic_inc(&vcc->stats->rx);
36840+ atomic_inc_unchecked(&vcc->stats->rx);
36841
36842 cell += ATM_CELL_PAYLOAD;
36843 }
36844@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36845 "(CDC: %08x)\n",
36846 card->name, len, rpp->len, readl(SAR_REG_CDC));
36847 recycle_rx_pool_skb(card, rpp);
36848- atomic_inc(&vcc->stats->rx_err);
36849+ atomic_inc_unchecked(&vcc->stats->rx_err);
36850 return;
36851 }
36852 if (stat & SAR_RSQE_CRC) {
36853 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36854 recycle_rx_pool_skb(card, rpp);
36855- atomic_inc(&vcc->stats->rx_err);
36856+ atomic_inc_unchecked(&vcc->stats->rx_err);
36857 return;
36858 }
36859 if (skb_queue_len(&rpp->queue) > 1) {
36860@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36861 RXPRINTK("%s: Can't alloc RX skb.\n",
36862 card->name);
36863 recycle_rx_pool_skb(card, rpp);
36864- atomic_inc(&vcc->stats->rx_err);
36865+ atomic_inc_unchecked(&vcc->stats->rx_err);
36866 return;
36867 }
36868 if (!atm_charge(vcc, skb->truesize)) {
36869@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36870 __net_timestamp(skb);
36871
36872 vcc->push(vcc, skb);
36873- atomic_inc(&vcc->stats->rx);
36874+ atomic_inc_unchecked(&vcc->stats->rx);
36875
36876 return;
36877 }
36878@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36879 __net_timestamp(skb);
36880
36881 vcc->push(vcc, skb);
36882- atomic_inc(&vcc->stats->rx);
36883+ atomic_inc_unchecked(&vcc->stats->rx);
36884
36885 if (skb->truesize > SAR_FB_SIZE_3)
36886 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36887@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36888 if (vcc->qos.aal != ATM_AAL0) {
36889 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36890 card->name, vpi, vci);
36891- atomic_inc(&vcc->stats->rx_drop);
36892+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36893 goto drop;
36894 }
36895
36896 if ((sb = dev_alloc_skb(64)) == NULL) {
36897 printk("%s: Can't allocate buffers for AAL0.\n",
36898 card->name);
36899- atomic_inc(&vcc->stats->rx_err);
36900+ atomic_inc_unchecked(&vcc->stats->rx_err);
36901 goto drop;
36902 }
36903
36904@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36905 ATM_SKB(sb)->vcc = vcc;
36906 __net_timestamp(sb);
36907 vcc->push(vcc, sb);
36908- atomic_inc(&vcc->stats->rx);
36909+ atomic_inc_unchecked(&vcc->stats->rx);
36910
36911 drop:
36912 skb_pull(queue, 64);
36913@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36914
36915 if (vc == NULL) {
36916 printk("%s: NULL connection in send().\n", card->name);
36917- atomic_inc(&vcc->stats->tx_err);
36918+ atomic_inc_unchecked(&vcc->stats->tx_err);
36919 dev_kfree_skb(skb);
36920 return -EINVAL;
36921 }
36922 if (!test_bit(VCF_TX, &vc->flags)) {
36923 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36924- atomic_inc(&vcc->stats->tx_err);
36925+ atomic_inc_unchecked(&vcc->stats->tx_err);
36926 dev_kfree_skb(skb);
36927 return -EINVAL;
36928 }
36929@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36930 break;
36931 default:
36932 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36933- atomic_inc(&vcc->stats->tx_err);
36934+ atomic_inc_unchecked(&vcc->stats->tx_err);
36935 dev_kfree_skb(skb);
36936 return -EINVAL;
36937 }
36938
36939 if (skb_shinfo(skb)->nr_frags != 0) {
36940 printk("%s: No scatter-gather yet.\n", card->name);
36941- atomic_inc(&vcc->stats->tx_err);
36942+ atomic_inc_unchecked(&vcc->stats->tx_err);
36943 dev_kfree_skb(skb);
36944 return -EINVAL;
36945 }
36946@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36947
36948 err = queue_skb(card, vc, skb, oam);
36949 if (err) {
36950- atomic_inc(&vcc->stats->tx_err);
36951+ atomic_inc_unchecked(&vcc->stats->tx_err);
36952 dev_kfree_skb(skb);
36953 return err;
36954 }
36955@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36956 skb = dev_alloc_skb(64);
36957 if (!skb) {
36958 printk("%s: Out of memory in send_oam().\n", card->name);
36959- atomic_inc(&vcc->stats->tx_err);
36960+ atomic_inc_unchecked(&vcc->stats->tx_err);
36961 return -ENOMEM;
36962 }
36963 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36964diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36965index 4217f29..88f547a 100644
36966--- a/drivers/atm/iphase.c
36967+++ b/drivers/atm/iphase.c
36968@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36969 status = (u_short) (buf_desc_ptr->desc_mode);
36970 if (status & (RX_CER | RX_PTE | RX_OFL))
36971 {
36972- atomic_inc(&vcc->stats->rx_err);
36973+ atomic_inc_unchecked(&vcc->stats->rx_err);
36974 IF_ERR(printk("IA: bad packet, dropping it");)
36975 if (status & RX_CER) {
36976 IF_ERR(printk(" cause: packet CRC error\n");)
36977@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36978 len = dma_addr - buf_addr;
36979 if (len > iadev->rx_buf_sz) {
36980 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36981- atomic_inc(&vcc->stats->rx_err);
36982+ atomic_inc_unchecked(&vcc->stats->rx_err);
36983 goto out_free_desc;
36984 }
36985
36986@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36987 ia_vcc = INPH_IA_VCC(vcc);
36988 if (ia_vcc == NULL)
36989 {
36990- atomic_inc(&vcc->stats->rx_err);
36991+ atomic_inc_unchecked(&vcc->stats->rx_err);
36992 atm_return(vcc, skb->truesize);
36993 dev_kfree_skb_any(skb);
36994 goto INCR_DLE;
36995@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36996 if ((length > iadev->rx_buf_sz) || (length >
36997 (skb->len - sizeof(struct cpcs_trailer))))
36998 {
36999- atomic_inc(&vcc->stats->rx_err);
37000+ atomic_inc_unchecked(&vcc->stats->rx_err);
37001 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37002 length, skb->len);)
37003 atm_return(vcc, skb->truesize);
37004@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37005
37006 IF_RX(printk("rx_dle_intr: skb push");)
37007 vcc->push(vcc,skb);
37008- atomic_inc(&vcc->stats->rx);
37009+ atomic_inc_unchecked(&vcc->stats->rx);
37010 iadev->rx_pkt_cnt++;
37011 }
37012 INCR_DLE:
37013@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37014 {
37015 struct k_sonet_stats *stats;
37016 stats = &PRIV(_ia_dev[board])->sonet_stats;
37017- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37018- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37019- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37020- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37021- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37022- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37023- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37024- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37025- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37026+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37027+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37028+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37029+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37030+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37031+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37032+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37033+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37034+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37035 }
37036 ia_cmds.status = 0;
37037 break;
37038@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37039 if ((desc == 0) || (desc > iadev->num_tx_desc))
37040 {
37041 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37042- atomic_inc(&vcc->stats->tx);
37043+ atomic_inc_unchecked(&vcc->stats->tx);
37044 if (vcc->pop)
37045 vcc->pop(vcc, skb);
37046 else
37047@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37048 ATM_DESC(skb) = vcc->vci;
37049 skb_queue_tail(&iadev->tx_dma_q, skb);
37050
37051- atomic_inc(&vcc->stats->tx);
37052+ atomic_inc_unchecked(&vcc->stats->tx);
37053 iadev->tx_pkt_cnt++;
37054 /* Increment transaction counter */
37055 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37056
37057 #if 0
37058 /* add flow control logic */
37059- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37060+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37061 if (iavcc->vc_desc_cnt > 10) {
37062 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37063 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37064diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37065index fa7d7019..1e404c7 100644
37066--- a/drivers/atm/lanai.c
37067+++ b/drivers/atm/lanai.c
37068@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37069 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37070 lanai_endtx(lanai, lvcc);
37071 lanai_free_skb(lvcc->tx.atmvcc, skb);
37072- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37073+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37074 }
37075
37076 /* Try to fill the buffer - don't call unless there is backlog */
37077@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37078 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37079 __net_timestamp(skb);
37080 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37081- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37082+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37083 out:
37084 lvcc->rx.buf.ptr = end;
37085 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37086@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37087 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37088 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37089 lanai->stats.service_rxnotaal5++;
37090- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37091+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37092 return 0;
37093 }
37094 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37095@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37096 int bytes;
37097 read_unlock(&vcc_sklist_lock);
37098 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37099- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37100+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37101 lvcc->stats.x.aal5.service_trash++;
37102 bytes = (SERVICE_GET_END(s) * 16) -
37103 (((unsigned long) lvcc->rx.buf.ptr) -
37104@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37105 }
37106 if (s & SERVICE_STREAM) {
37107 read_unlock(&vcc_sklist_lock);
37108- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37109+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37110 lvcc->stats.x.aal5.service_stream++;
37111 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37112 "PDU on VCI %d!\n", lanai->number, vci);
37113@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37114 return 0;
37115 }
37116 DPRINTK("got rx crc error on vci %d\n", vci);
37117- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37118+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37119 lvcc->stats.x.aal5.service_rxcrc++;
37120 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37121 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37122diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37123index 9988ac9..7c52585 100644
37124--- a/drivers/atm/nicstar.c
37125+++ b/drivers/atm/nicstar.c
37126@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37127 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37128 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37129 card->index);
37130- atomic_inc(&vcc->stats->tx_err);
37131+ atomic_inc_unchecked(&vcc->stats->tx_err);
37132 dev_kfree_skb_any(skb);
37133 return -EINVAL;
37134 }
37135@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37136 if (!vc->tx) {
37137 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37138 card->index);
37139- atomic_inc(&vcc->stats->tx_err);
37140+ atomic_inc_unchecked(&vcc->stats->tx_err);
37141 dev_kfree_skb_any(skb);
37142 return -EINVAL;
37143 }
37144@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37145 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37146 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37147 card->index);
37148- atomic_inc(&vcc->stats->tx_err);
37149+ atomic_inc_unchecked(&vcc->stats->tx_err);
37150 dev_kfree_skb_any(skb);
37151 return -EINVAL;
37152 }
37153
37154 if (skb_shinfo(skb)->nr_frags != 0) {
37155 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37156- atomic_inc(&vcc->stats->tx_err);
37157+ atomic_inc_unchecked(&vcc->stats->tx_err);
37158 dev_kfree_skb_any(skb);
37159 return -EINVAL;
37160 }
37161@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37162 }
37163
37164 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37165- atomic_inc(&vcc->stats->tx_err);
37166+ atomic_inc_unchecked(&vcc->stats->tx_err);
37167 dev_kfree_skb_any(skb);
37168 return -EIO;
37169 }
37170- atomic_inc(&vcc->stats->tx);
37171+ atomic_inc_unchecked(&vcc->stats->tx);
37172
37173 return 0;
37174 }
37175@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37176 printk
37177 ("nicstar%d: Can't allocate buffers for aal0.\n",
37178 card->index);
37179- atomic_add(i, &vcc->stats->rx_drop);
37180+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37181 break;
37182 }
37183 if (!atm_charge(vcc, sb->truesize)) {
37184 RXPRINTK
37185 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37186 card->index);
37187- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37188+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37189 dev_kfree_skb_any(sb);
37190 break;
37191 }
37192@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37193 ATM_SKB(sb)->vcc = vcc;
37194 __net_timestamp(sb);
37195 vcc->push(vcc, sb);
37196- atomic_inc(&vcc->stats->rx);
37197+ atomic_inc_unchecked(&vcc->stats->rx);
37198 cell += ATM_CELL_PAYLOAD;
37199 }
37200
37201@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37202 if (iovb == NULL) {
37203 printk("nicstar%d: Out of iovec buffers.\n",
37204 card->index);
37205- atomic_inc(&vcc->stats->rx_drop);
37206+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37207 recycle_rx_buf(card, skb);
37208 return;
37209 }
37210@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37211 small or large buffer itself. */
37212 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37213 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37214- atomic_inc(&vcc->stats->rx_err);
37215+ atomic_inc_unchecked(&vcc->stats->rx_err);
37216 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37217 NS_MAX_IOVECS);
37218 NS_PRV_IOVCNT(iovb) = 0;
37219@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37220 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37221 card->index);
37222 which_list(card, skb);
37223- atomic_inc(&vcc->stats->rx_err);
37224+ atomic_inc_unchecked(&vcc->stats->rx_err);
37225 recycle_rx_buf(card, skb);
37226 vc->rx_iov = NULL;
37227 recycle_iov_buf(card, iovb);
37228@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37229 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37230 card->index);
37231 which_list(card, skb);
37232- atomic_inc(&vcc->stats->rx_err);
37233+ atomic_inc_unchecked(&vcc->stats->rx_err);
37234 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37235 NS_PRV_IOVCNT(iovb));
37236 vc->rx_iov = NULL;
37237@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37238 printk(" - PDU size mismatch.\n");
37239 else
37240 printk(".\n");
37241- atomic_inc(&vcc->stats->rx_err);
37242+ atomic_inc_unchecked(&vcc->stats->rx_err);
37243 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37244 NS_PRV_IOVCNT(iovb));
37245 vc->rx_iov = NULL;
37246@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37247 /* skb points to a small buffer */
37248 if (!atm_charge(vcc, skb->truesize)) {
37249 push_rxbufs(card, skb);
37250- atomic_inc(&vcc->stats->rx_drop);
37251+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37252 } else {
37253 skb_put(skb, len);
37254 dequeue_sm_buf(card, skb);
37255@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37256 ATM_SKB(skb)->vcc = vcc;
37257 __net_timestamp(skb);
37258 vcc->push(vcc, skb);
37259- atomic_inc(&vcc->stats->rx);
37260+ atomic_inc_unchecked(&vcc->stats->rx);
37261 }
37262 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37263 struct sk_buff *sb;
37264@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37265 if (len <= NS_SMBUFSIZE) {
37266 if (!atm_charge(vcc, sb->truesize)) {
37267 push_rxbufs(card, sb);
37268- atomic_inc(&vcc->stats->rx_drop);
37269+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37270 } else {
37271 skb_put(sb, len);
37272 dequeue_sm_buf(card, sb);
37273@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37274 ATM_SKB(sb)->vcc = vcc;
37275 __net_timestamp(sb);
37276 vcc->push(vcc, sb);
37277- atomic_inc(&vcc->stats->rx);
37278+ atomic_inc_unchecked(&vcc->stats->rx);
37279 }
37280
37281 push_rxbufs(card, skb);
37282@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37283
37284 if (!atm_charge(vcc, skb->truesize)) {
37285 push_rxbufs(card, skb);
37286- atomic_inc(&vcc->stats->rx_drop);
37287+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37288 } else {
37289 dequeue_lg_buf(card, skb);
37290 #ifdef NS_USE_DESTRUCTORS
37291@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37292 ATM_SKB(skb)->vcc = vcc;
37293 __net_timestamp(skb);
37294 vcc->push(vcc, skb);
37295- atomic_inc(&vcc->stats->rx);
37296+ atomic_inc_unchecked(&vcc->stats->rx);
37297 }
37298
37299 push_rxbufs(card, sb);
37300@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37301 printk
37302 ("nicstar%d: Out of huge buffers.\n",
37303 card->index);
37304- atomic_inc(&vcc->stats->rx_drop);
37305+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37306 recycle_iovec_rx_bufs(card,
37307 (struct iovec *)
37308 iovb->data,
37309@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37310 card->hbpool.count++;
37311 } else
37312 dev_kfree_skb_any(hb);
37313- atomic_inc(&vcc->stats->rx_drop);
37314+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37315 } else {
37316 /* Copy the small buffer to the huge buffer */
37317 sb = (struct sk_buff *)iov->iov_base;
37318@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37319 #endif /* NS_USE_DESTRUCTORS */
37320 __net_timestamp(hb);
37321 vcc->push(vcc, hb);
37322- atomic_inc(&vcc->stats->rx);
37323+ atomic_inc_unchecked(&vcc->stats->rx);
37324 }
37325 }
37326
37327diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37328index 943cf0d..37d15d5 100644
37329--- a/drivers/atm/solos-pci.c
37330+++ b/drivers/atm/solos-pci.c
37331@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37332 }
37333 atm_charge(vcc, skb->truesize);
37334 vcc->push(vcc, skb);
37335- atomic_inc(&vcc->stats->rx);
37336+ atomic_inc_unchecked(&vcc->stats->rx);
37337 break;
37338
37339 case PKT_STATUS:
37340@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37341 vcc = SKB_CB(oldskb)->vcc;
37342
37343 if (vcc) {
37344- atomic_inc(&vcc->stats->tx);
37345+ atomic_inc_unchecked(&vcc->stats->tx);
37346 solos_pop(vcc, oldskb);
37347 } else {
37348 dev_kfree_skb_irq(oldskb);
37349diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37350index 0215934..ce9f5b1 100644
37351--- a/drivers/atm/suni.c
37352+++ b/drivers/atm/suni.c
37353@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37354
37355
37356 #define ADD_LIMITED(s,v) \
37357- atomic_add((v),&stats->s); \
37358- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37359+ atomic_add_unchecked((v),&stats->s); \
37360+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37361
37362
37363 static void suni_hz(unsigned long from_timer)
37364diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37365index 5120a96..e2572bd 100644
37366--- a/drivers/atm/uPD98402.c
37367+++ b/drivers/atm/uPD98402.c
37368@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37369 struct sonet_stats tmp;
37370 int error = 0;
37371
37372- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37373+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37374 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37375 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37376 if (zero && !error) {
37377@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37378
37379
37380 #define ADD_LIMITED(s,v) \
37381- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37382- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37383- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37384+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37385+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37386+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37387
37388
37389 static void stat_event(struct atm_dev *dev)
37390@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37391 if (reason & uPD98402_INT_PFM) stat_event(dev);
37392 if (reason & uPD98402_INT_PCO) {
37393 (void) GET(PCOCR); /* clear interrupt cause */
37394- atomic_add(GET(HECCT),
37395+ atomic_add_unchecked(GET(HECCT),
37396 &PRIV(dev)->sonet_stats.uncorr_hcs);
37397 }
37398 if ((reason & uPD98402_INT_RFO) &&
37399@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37400 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37401 uPD98402_INT_LOS),PIMR); /* enable them */
37402 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37403- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37404- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37405- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37406+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37407+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37408+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37409 return 0;
37410 }
37411
37412diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37413index 969c3c2..9b72956 100644
37414--- a/drivers/atm/zatm.c
37415+++ b/drivers/atm/zatm.c
37416@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37417 }
37418 if (!size) {
37419 dev_kfree_skb_irq(skb);
37420- if (vcc) atomic_inc(&vcc->stats->rx_err);
37421+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37422 continue;
37423 }
37424 if (!atm_charge(vcc,skb->truesize)) {
37425@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37426 skb->len = size;
37427 ATM_SKB(skb)->vcc = vcc;
37428 vcc->push(vcc,skb);
37429- atomic_inc(&vcc->stats->rx);
37430+ atomic_inc_unchecked(&vcc->stats->rx);
37431 }
37432 zout(pos & 0xffff,MTA(mbx));
37433 #if 0 /* probably a stupid idea */
37434@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37435 skb_queue_head(&zatm_vcc->backlog,skb);
37436 break;
37437 }
37438- atomic_inc(&vcc->stats->tx);
37439+ atomic_inc_unchecked(&vcc->stats->tx);
37440 wake_up(&zatm_vcc->tx_wait);
37441 }
37442
37443diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37444index 83e910a..b224a73 100644
37445--- a/drivers/base/bus.c
37446+++ b/drivers/base/bus.c
37447@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37448 return -EINVAL;
37449
37450 mutex_lock(&subsys->p->mutex);
37451- list_add_tail(&sif->node, &subsys->p->interfaces);
37452+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37453 if (sif->add_dev) {
37454 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37455 while ((dev = subsys_dev_iter_next(&iter)))
37456@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37457 subsys = sif->subsys;
37458
37459 mutex_lock(&subsys->p->mutex);
37460- list_del_init(&sif->node);
37461+ pax_list_del_init((struct list_head *)&sif->node);
37462 if (sif->remove_dev) {
37463 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37464 while ((dev = subsys_dev_iter_next(&iter)))
37465diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37466index 25798db..15f130e 100644
37467--- a/drivers/base/devtmpfs.c
37468+++ b/drivers/base/devtmpfs.c
37469@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37470 if (!thread)
37471 return 0;
37472
37473- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37474+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37475 if (err)
37476 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37477 else
37478@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37479 *err = sys_unshare(CLONE_NEWNS);
37480 if (*err)
37481 goto out;
37482- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37483+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37484 if (*err)
37485 goto out;
37486- sys_chdir("/.."); /* will traverse into overmounted root */
37487- sys_chroot(".");
37488+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37489+ sys_chroot((char __force_user *)".");
37490 complete(&setup_done);
37491 while (1) {
37492 spin_lock(&req_lock);
37493diff --git a/drivers/base/node.c b/drivers/base/node.c
37494index 8f7ed99..700dd0c 100644
37495--- a/drivers/base/node.c
37496+++ b/drivers/base/node.c
37497@@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37498 struct node_attr {
37499 struct device_attribute attr;
37500 enum node_states state;
37501-};
37502+} __do_const;
37503
37504 static ssize_t show_node_state(struct device *dev,
37505 struct device_attribute *attr, char *buf)
37506diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37507index ae098a2..0999830 100644
37508--- a/drivers/base/power/domain.c
37509+++ b/drivers/base/power/domain.c
37510@@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37511
37512 if (dev->power.subsys_data->domain_data) {
37513 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37514- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37515+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37516 if (clear_td)
37517- gpd_data->td = (struct gpd_timing_data){ 0 };
37518+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37519
37520 if (--gpd_data->refcount == 0) {
37521 dev->power.subsys_data->domain_data = NULL;
37522@@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37523 {
37524 struct cpuidle_driver *cpuidle_drv;
37525 struct gpd_cpu_data *cpu_data;
37526- struct cpuidle_state *idle_state;
37527+ cpuidle_state_no_const *idle_state;
37528 int ret = 0;
37529
37530 if (IS_ERR_OR_NULL(genpd) || state < 0)
37531@@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37532 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37533 {
37534 struct gpd_cpu_data *cpu_data;
37535- struct cpuidle_state *idle_state;
37536+ cpuidle_state_no_const *idle_state;
37537 int ret = 0;
37538
37539 if (IS_ERR_OR_NULL(genpd))
37540diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37541index 95b181d1..c4f0e19 100644
37542--- a/drivers/base/power/sysfs.c
37543+++ b/drivers/base/power/sysfs.c
37544@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37545 return -EIO;
37546 }
37547 }
37548- return sprintf(buf, p);
37549+ return sprintf(buf, "%s", p);
37550 }
37551
37552 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37553diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37554index 2d56f41..8830f19 100644
37555--- a/drivers/base/power/wakeup.c
37556+++ b/drivers/base/power/wakeup.c
37557@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37558 * They need to be modified together atomically, so it's better to use one
37559 * atomic variable to hold them both.
37560 */
37561-static atomic_t combined_event_count = ATOMIC_INIT(0);
37562+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37563
37564 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37565 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37566
37567 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37568 {
37569- unsigned int comb = atomic_read(&combined_event_count);
37570+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37571
37572 *cnt = (comb >> IN_PROGRESS_BITS);
37573 *inpr = comb & MAX_IN_PROGRESS;
37574@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37575 ws->start_prevent_time = ws->last_time;
37576
37577 /* Increment the counter of events in progress. */
37578- cec = atomic_inc_return(&combined_event_count);
37579+ cec = atomic_inc_return_unchecked(&combined_event_count);
37580
37581 trace_wakeup_source_activate(ws->name, cec);
37582 }
37583@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37584 * Increment the counter of registered wakeup events and decrement the
37585 * couter of wakeup events in progress simultaneously.
37586 */
37587- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37588+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37589 trace_wakeup_source_deactivate(ws->name, cec);
37590
37591 split_counters(&cnt, &inpr);
37592diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37593index e8d11b6..7b1b36f 100644
37594--- a/drivers/base/syscore.c
37595+++ b/drivers/base/syscore.c
37596@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37597 void register_syscore_ops(struct syscore_ops *ops)
37598 {
37599 mutex_lock(&syscore_ops_lock);
37600- list_add_tail(&ops->node, &syscore_ops_list);
37601+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37602 mutex_unlock(&syscore_ops_lock);
37603 }
37604 EXPORT_SYMBOL_GPL(register_syscore_ops);
37605@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37606 void unregister_syscore_ops(struct syscore_ops *ops)
37607 {
37608 mutex_lock(&syscore_ops_lock);
37609- list_del(&ops->node);
37610+ pax_list_del((struct list_head *)&ops->node);
37611 mutex_unlock(&syscore_ops_lock);
37612 }
37613 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37614diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37615index 73894ca..69f64ef 100644
37616--- a/drivers/block/cciss.c
37617+++ b/drivers/block/cciss.c
37618@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37619 while (!list_empty(&h->reqQ)) {
37620 c = list_entry(h->reqQ.next, CommandList_struct, list);
37621 /* can't do anything if fifo is full */
37622- if ((h->access.fifo_full(h))) {
37623+ if ((h->access->fifo_full(h))) {
37624 dev_warn(&h->pdev->dev, "fifo full\n");
37625 break;
37626 }
37627@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37628 h->Qdepth--;
37629
37630 /* Tell the controller execute command */
37631- h->access.submit_command(h, c);
37632+ h->access->submit_command(h, c);
37633
37634 /* Put job onto the completed Q */
37635 addQ(&h->cmpQ, c);
37636@@ -3447,17 +3447,17 @@ startio:
37637
37638 static inline unsigned long get_next_completion(ctlr_info_t *h)
37639 {
37640- return h->access.command_completed(h);
37641+ return h->access->command_completed(h);
37642 }
37643
37644 static inline int interrupt_pending(ctlr_info_t *h)
37645 {
37646- return h->access.intr_pending(h);
37647+ return h->access->intr_pending(h);
37648 }
37649
37650 static inline long interrupt_not_for_us(ctlr_info_t *h)
37651 {
37652- return ((h->access.intr_pending(h) == 0) ||
37653+ return ((h->access->intr_pending(h) == 0) ||
37654 (h->interrupts_enabled == 0));
37655 }
37656
37657@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37658 u32 a;
37659
37660 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37661- return h->access.command_completed(h);
37662+ return h->access->command_completed(h);
37663
37664 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37665 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37666@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37667 trans_support & CFGTBL_Trans_use_short_tags);
37668
37669 /* Change the access methods to the performant access methods */
37670- h->access = SA5_performant_access;
37671+ h->access = &SA5_performant_access;
37672 h->transMethod = CFGTBL_Trans_Performant;
37673
37674 return;
37675@@ -4325,7 +4325,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37676 if (prod_index < 0)
37677 return -ENODEV;
37678 h->product_name = products[prod_index].product_name;
37679- h->access = *(products[prod_index].access);
37680+ h->access = products[prod_index].access;
37681
37682 if (cciss_board_disabled(h)) {
37683 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37684@@ -5057,7 +5057,7 @@ reinit_after_soft_reset:
37685 }
37686
37687 /* make sure the board interrupts are off */
37688- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37689+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37690 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37691 if (rc)
37692 goto clean2;
37693@@ -5107,7 +5107,7 @@ reinit_after_soft_reset:
37694 * fake ones to scoop up any residual completions.
37695 */
37696 spin_lock_irqsave(&h->lock, flags);
37697- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37698+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37699 spin_unlock_irqrestore(&h->lock, flags);
37700 free_irq(h->intr[h->intr_mode], h);
37701 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37702@@ -5127,9 +5127,9 @@ reinit_after_soft_reset:
37703 dev_info(&h->pdev->dev, "Board READY.\n");
37704 dev_info(&h->pdev->dev,
37705 "Waiting for stale completions to drain.\n");
37706- h->access.set_intr_mask(h, CCISS_INTR_ON);
37707+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37708 msleep(10000);
37709- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37710+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37711
37712 rc = controller_reset_failed(h->cfgtable);
37713 if (rc)
37714@@ -5152,7 +5152,7 @@ reinit_after_soft_reset:
37715 cciss_scsi_setup(h);
37716
37717 /* Turn the interrupts on so we can service requests */
37718- h->access.set_intr_mask(h, CCISS_INTR_ON);
37719+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37720
37721 /* Get the firmware version */
37722 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37723@@ -5224,7 +5224,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37724 kfree(flush_buf);
37725 if (return_code != IO_OK)
37726 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37727- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37728+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37729 free_irq(h->intr[h->intr_mode], h);
37730 }
37731
37732diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37733index 7fda30e..2f27946 100644
37734--- a/drivers/block/cciss.h
37735+++ b/drivers/block/cciss.h
37736@@ -101,7 +101,7 @@ struct ctlr_info
37737 /* information about each logical volume */
37738 drive_info_struct *drv[CISS_MAX_LUN];
37739
37740- struct access_method access;
37741+ struct access_method *access;
37742
37743 /* queue and queue Info */
37744 struct list_head reqQ;
37745@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37746 }
37747
37748 static struct access_method SA5_access = {
37749- SA5_submit_command,
37750- SA5_intr_mask,
37751- SA5_fifo_full,
37752- SA5_intr_pending,
37753- SA5_completed,
37754+ .submit_command = SA5_submit_command,
37755+ .set_intr_mask = SA5_intr_mask,
37756+ .fifo_full = SA5_fifo_full,
37757+ .intr_pending = SA5_intr_pending,
37758+ .command_completed = SA5_completed,
37759 };
37760
37761 static struct access_method SA5B_access = {
37762- SA5_submit_command,
37763- SA5B_intr_mask,
37764- SA5_fifo_full,
37765- SA5B_intr_pending,
37766- SA5_completed,
37767+ .submit_command = SA5_submit_command,
37768+ .set_intr_mask = SA5B_intr_mask,
37769+ .fifo_full = SA5_fifo_full,
37770+ .intr_pending = SA5B_intr_pending,
37771+ .command_completed = SA5_completed,
37772 };
37773
37774 static struct access_method SA5_performant_access = {
37775- SA5_submit_command,
37776- SA5_performant_intr_mask,
37777- SA5_fifo_full,
37778- SA5_performant_intr_pending,
37779- SA5_performant_completed,
37780+ .submit_command = SA5_submit_command,
37781+ .set_intr_mask = SA5_performant_intr_mask,
37782+ .fifo_full = SA5_fifo_full,
37783+ .intr_pending = SA5_performant_intr_pending,
37784+ .command_completed = SA5_performant_completed,
37785 };
37786
37787 struct board_type {
37788diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37789index 2b94403..fd6ad1f 100644
37790--- a/drivers/block/cpqarray.c
37791+++ b/drivers/block/cpqarray.c
37792@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37793 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37794 goto Enomem4;
37795 }
37796- hba[i]->access.set_intr_mask(hba[i], 0);
37797+ hba[i]->access->set_intr_mask(hba[i], 0);
37798 if (request_irq(hba[i]->intr, do_ida_intr,
37799 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37800 {
37801@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37802 add_timer(&hba[i]->timer);
37803
37804 /* Enable IRQ now that spinlock and rate limit timer are set up */
37805- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37806+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37807
37808 for(j=0; j<NWD; j++) {
37809 struct gendisk *disk = ida_gendisk[i][j];
37810@@ -694,7 +694,7 @@ DBGINFO(
37811 for(i=0; i<NR_PRODUCTS; i++) {
37812 if (board_id == products[i].board_id) {
37813 c->product_name = products[i].product_name;
37814- c->access = *(products[i].access);
37815+ c->access = products[i].access;
37816 break;
37817 }
37818 }
37819@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37820 hba[ctlr]->intr = intr;
37821 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37822 hba[ctlr]->product_name = products[j].product_name;
37823- hba[ctlr]->access = *(products[j].access);
37824+ hba[ctlr]->access = products[j].access;
37825 hba[ctlr]->ctlr = ctlr;
37826 hba[ctlr]->board_id = board_id;
37827 hba[ctlr]->pci_dev = NULL; /* not PCI */
37828@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37829
37830 while((c = h->reqQ) != NULL) {
37831 /* Can't do anything if we're busy */
37832- if (h->access.fifo_full(h) == 0)
37833+ if (h->access->fifo_full(h) == 0)
37834 return;
37835
37836 /* Get the first entry from the request Q */
37837@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37838 h->Qdepth--;
37839
37840 /* Tell the controller to do our bidding */
37841- h->access.submit_command(h, c);
37842+ h->access->submit_command(h, c);
37843
37844 /* Get onto the completion Q */
37845 addQ(&h->cmpQ, c);
37846@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37847 unsigned long flags;
37848 __u32 a,a1;
37849
37850- istat = h->access.intr_pending(h);
37851+ istat = h->access->intr_pending(h);
37852 /* Is this interrupt for us? */
37853 if (istat == 0)
37854 return IRQ_NONE;
37855@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37856 */
37857 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37858 if (istat & FIFO_NOT_EMPTY) {
37859- while((a = h->access.command_completed(h))) {
37860+ while((a = h->access->command_completed(h))) {
37861 a1 = a; a &= ~3;
37862 if ((c = h->cmpQ) == NULL)
37863 {
37864@@ -1448,11 +1448,11 @@ static int sendcmd(
37865 /*
37866 * Disable interrupt
37867 */
37868- info_p->access.set_intr_mask(info_p, 0);
37869+ info_p->access->set_intr_mask(info_p, 0);
37870 /* Make sure there is room in the command FIFO */
37871 /* Actually it should be completely empty at this time. */
37872 for (i = 200000; i > 0; i--) {
37873- temp = info_p->access.fifo_full(info_p);
37874+ temp = info_p->access->fifo_full(info_p);
37875 if (temp != 0) {
37876 break;
37877 }
37878@@ -1465,7 +1465,7 @@ DBG(
37879 /*
37880 * Send the cmd
37881 */
37882- info_p->access.submit_command(info_p, c);
37883+ info_p->access->submit_command(info_p, c);
37884 complete = pollcomplete(ctlr);
37885
37886 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37887@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37888 * we check the new geometry. Then turn interrupts back on when
37889 * we're done.
37890 */
37891- host->access.set_intr_mask(host, 0);
37892+ host->access->set_intr_mask(host, 0);
37893 getgeometry(ctlr);
37894- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37895+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37896
37897 for(i=0; i<NWD; i++) {
37898 struct gendisk *disk = ida_gendisk[ctlr][i];
37899@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37900 /* Wait (up to 2 seconds) for a command to complete */
37901
37902 for (i = 200000; i > 0; i--) {
37903- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37904+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37905 if (done == 0) {
37906 udelay(10); /* a short fixed delay */
37907 } else
37908diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37909index be73e9d..7fbf140 100644
37910--- a/drivers/block/cpqarray.h
37911+++ b/drivers/block/cpqarray.h
37912@@ -99,7 +99,7 @@ struct ctlr_info {
37913 drv_info_t drv[NWD];
37914 struct proc_dir_entry *proc;
37915
37916- struct access_method access;
37917+ struct access_method *access;
37918
37919 cmdlist_t *reqQ;
37920 cmdlist_t *cmpQ;
37921diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37922index e7093d4..b364085 100644
37923--- a/drivers/block/drbd/drbd_int.h
37924+++ b/drivers/block/drbd/drbd_int.h
37925@@ -331,7 +331,7 @@ struct drbd_epoch {
37926 struct drbd_connection *connection;
37927 struct list_head list;
37928 unsigned int barrier_nr;
37929- atomic_t epoch_size; /* increased on every request added. */
37930+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37931 atomic_t active; /* increased on every req. added, and dec on every finished. */
37932 unsigned long flags;
37933 };
37934@@ -787,7 +787,7 @@ struct drbd_device {
37935 unsigned int al_tr_number;
37936 int al_tr_cycle;
37937 wait_queue_head_t seq_wait;
37938- atomic_t packet_seq;
37939+ atomic_unchecked_t packet_seq;
37940 unsigned int peer_seq;
37941 spinlock_t peer_seq_lock;
37942 unsigned int minor;
37943@@ -1361,7 +1361,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37944 char __user *uoptval;
37945 int err;
37946
37947- uoptval = (char __user __force *)optval;
37948+ uoptval = (char __force_user *)optval;
37949
37950 set_fs(KERNEL_DS);
37951 if (level == SOL_SOCKET)
37952diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37953index 89c497c..9c736ae 100644
37954--- a/drivers/block/drbd/drbd_interval.c
37955+++ b/drivers/block/drbd/drbd_interval.c
37956@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37957 }
37958
37959 static const struct rb_augment_callbacks augment_callbacks = {
37960- augment_propagate,
37961- augment_copy,
37962- augment_rotate,
37963+ .propagate = augment_propagate,
37964+ .copy = augment_copy,
37965+ .rotate = augment_rotate,
37966 };
37967
37968 /**
37969diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37970index 331e5cc..6d657bce 100644
37971--- a/drivers/block/drbd/drbd_main.c
37972+++ b/drivers/block/drbd/drbd_main.c
37973@@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
37974 p->sector = sector;
37975 p->block_id = block_id;
37976 p->blksize = blksize;
37977- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
37978+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
37979 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
37980 }
37981
37982@@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
37983 return -EIO;
37984 p->sector = cpu_to_be64(req->i.sector);
37985 p->block_id = (unsigned long)req;
37986- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
37987+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
37988 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
37989 if (device->state.conn >= C_SYNC_SOURCE &&
37990 device->state.conn <= C_PAUSED_SYNC_T)
37991@@ -2658,8 +2658,8 @@ void drbd_destroy_connection(struct kref *kref)
37992 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
37993 struct drbd_resource *resource = connection->resource;
37994
37995- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
37996- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
37997+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
37998+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
37999 kfree(connection->current_epoch);
38000
38001 idr_destroy(&connection->peer_devices);
38002diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38003index 526414b..4eb8184 100644
38004--- a/drivers/block/drbd/drbd_nl.c
38005+++ b/drivers/block/drbd/drbd_nl.c
38006@@ -3505,7 +3505,7 @@ out:
38007
38008 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38009 {
38010- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38011+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38012 struct sk_buff *msg;
38013 struct drbd_genlmsghdr *d_out;
38014 unsigned seq;
38015@@ -3518,7 +3518,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38016 return;
38017 }
38018
38019- seq = atomic_inc_return(&drbd_genl_seq);
38020+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38021 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38022 if (!msg)
38023 goto failed;
38024diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38025index 68e3992..1aca24a 100644
38026--- a/drivers/block/drbd/drbd_receiver.c
38027+++ b/drivers/block/drbd/drbd_receiver.c
38028@@ -826,7 +826,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38029 struct drbd_device *device = peer_device->device;
38030 int err;
38031
38032- atomic_set(&device->packet_seq, 0);
38033+ atomic_set_unchecked(&device->packet_seq, 0);
38034 device->peer_seq = 0;
38035
38036 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38037@@ -1188,7 +1188,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38038 do {
38039 next_epoch = NULL;
38040
38041- epoch_size = atomic_read(&epoch->epoch_size);
38042+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38043
38044 switch (ev & ~EV_CLEANUP) {
38045 case EV_PUT:
38046@@ -1228,7 +1228,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38047 rv = FE_DESTROYED;
38048 } else {
38049 epoch->flags = 0;
38050- atomic_set(&epoch->epoch_size, 0);
38051+ atomic_set_unchecked(&epoch->epoch_size, 0);
38052 /* atomic_set(&epoch->active, 0); is already zero */
38053 if (rv == FE_STILL_LIVE)
38054 rv = FE_RECYCLED;
38055@@ -1456,7 +1456,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38056 conn_wait_active_ee_empty(connection);
38057 drbd_flush(connection);
38058
38059- if (atomic_read(&connection->current_epoch->epoch_size)) {
38060+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38061 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38062 if (epoch)
38063 break;
38064@@ -1469,11 +1469,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38065 }
38066
38067 epoch->flags = 0;
38068- atomic_set(&epoch->epoch_size, 0);
38069+ atomic_set_unchecked(&epoch->epoch_size, 0);
38070 atomic_set(&epoch->active, 0);
38071
38072 spin_lock(&connection->epoch_lock);
38073- if (atomic_read(&connection->current_epoch->epoch_size)) {
38074+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38075 list_add(&epoch->list, &connection->current_epoch->list);
38076 connection->current_epoch = epoch;
38077 connection->epochs++;
38078@@ -2182,7 +2182,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38079
38080 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38081 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38082- atomic_inc(&connection->current_epoch->epoch_size);
38083+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38084 err2 = drbd_drain_block(peer_device, pi->size);
38085 if (!err)
38086 err = err2;
38087@@ -2216,7 +2216,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38088
38089 spin_lock(&connection->epoch_lock);
38090 peer_req->epoch = connection->current_epoch;
38091- atomic_inc(&peer_req->epoch->epoch_size);
38092+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38093 atomic_inc(&peer_req->epoch->active);
38094 spin_unlock(&connection->epoch_lock);
38095
38096@@ -4396,7 +4396,7 @@ struct data_cmd {
38097 int expect_payload;
38098 size_t pkt_size;
38099 int (*fn)(struct drbd_connection *, struct packet_info *);
38100-};
38101+} __do_const;
38102
38103 static struct data_cmd drbd_cmd_handler[] = {
38104 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38105@@ -4506,7 +4506,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38106 if (!list_empty(&connection->current_epoch->list))
38107 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38108 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38109- atomic_set(&connection->current_epoch->epoch_size, 0);
38110+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38111 connection->send.seen_any_write_yet = false;
38112
38113 drbd_info(connection, "Connection closed\n");
38114@@ -5281,7 +5281,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38115 struct asender_cmd {
38116 size_t pkt_size;
38117 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38118-};
38119+} __do_const;
38120
38121 static struct asender_cmd asender_tbl[] = {
38122 [P_PING] = { 0, got_Ping },
38123diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38124index f70a230..9dc90d5 100644
38125--- a/drivers/block/loop.c
38126+++ b/drivers/block/loop.c
38127@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38128
38129 file_start_write(file);
38130 set_fs(get_ds());
38131- bw = file->f_op->write(file, buf, len, &pos);
38132+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38133 set_fs(old_fs);
38134 file_end_write(file);
38135 if (likely(bw == len))
38136diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38137index 091b9ea..f5428f8 100644
38138--- a/drivers/block/null_blk.c
38139+++ b/drivers/block/null_blk.c
38140@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38141 return 0;
38142 }
38143
38144-static struct blk_mq_ops null_mq_ops = {
38145- .queue_rq = null_queue_rq,
38146- .map_queue = blk_mq_map_queue,
38147+static struct blk_mq_ops null_mq_single_ops = {
38148+ .queue_rq = null_queue_rq,
38149+ .map_queue = blk_mq_map_queue,
38150 .init_hctx = null_init_hctx,
38151 .complete = null_softirq_done_fn,
38152+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38153+ .free_hctx = blk_mq_free_single_hw_queue,
38154+};
38155+
38156+static struct blk_mq_ops null_mq_per_node_ops = {
38157+ .queue_rq = null_queue_rq,
38158+ .map_queue = blk_mq_map_queue,
38159+ .init_hctx = null_init_hctx,
38160+ .alloc_hctx = null_alloc_hctx,
38161+ .free_hctx = null_free_hctx,
38162 };
38163
38164 static struct blk_mq_reg null_mq_reg = {
38165- .ops = &null_mq_ops,
38166+ .ops = &null_mq_single_ops,
38167 .queue_depth = 64,
38168 .cmd_size = sizeof(struct nullb_cmd),
38169 .flags = BLK_MQ_F_SHOULD_MERGE,
38170@@ -521,13 +531,8 @@ static int null_add_dev(void)
38171 null_mq_reg.queue_depth = hw_queue_depth;
38172 null_mq_reg.nr_hw_queues = submit_queues;
38173
38174- if (use_per_node_hctx) {
38175- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38176- null_mq_reg.ops->free_hctx = null_free_hctx;
38177- } else {
38178- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38179- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38180- }
38181+ if (use_per_node_hctx)
38182+ null_mq_reg.ops = &null_mq_per_node_ops;
38183
38184 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38185 } else if (queue_mode == NULL_Q_BIO) {
38186diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38187index a2af73d..c0b8f61 100644
38188--- a/drivers/block/pktcdvd.c
38189+++ b/drivers/block/pktcdvd.c
38190@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38191
38192 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38193 {
38194- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38195+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38196 }
38197
38198 /*
38199@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38200 return -EROFS;
38201 }
38202 pd->settings.fp = ti.fp;
38203- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38204+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38205
38206 if (ti.nwa_v) {
38207 pd->nwa = be32_to_cpu(ti.next_writable);
38208diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38209index e5565fb..71be10b4 100644
38210--- a/drivers/block/smart1,2.h
38211+++ b/drivers/block/smart1,2.h
38212@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38213 }
38214
38215 static struct access_method smart4_access = {
38216- smart4_submit_command,
38217- smart4_intr_mask,
38218- smart4_fifo_full,
38219- smart4_intr_pending,
38220- smart4_completed,
38221+ .submit_command = smart4_submit_command,
38222+ .set_intr_mask = smart4_intr_mask,
38223+ .fifo_full = smart4_fifo_full,
38224+ .intr_pending = smart4_intr_pending,
38225+ .command_completed = smart4_completed,
38226 };
38227
38228 /*
38229@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38230 }
38231
38232 static struct access_method smart2_access = {
38233- smart2_submit_command,
38234- smart2_intr_mask,
38235- smart2_fifo_full,
38236- smart2_intr_pending,
38237- smart2_completed,
38238+ .submit_command = smart2_submit_command,
38239+ .set_intr_mask = smart2_intr_mask,
38240+ .fifo_full = smart2_fifo_full,
38241+ .intr_pending = smart2_intr_pending,
38242+ .command_completed = smart2_completed,
38243 };
38244
38245 /*
38246@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38247 }
38248
38249 static struct access_method smart2e_access = {
38250- smart2e_submit_command,
38251- smart2e_intr_mask,
38252- smart2e_fifo_full,
38253- smart2e_intr_pending,
38254- smart2e_completed,
38255+ .submit_command = smart2e_submit_command,
38256+ .set_intr_mask = smart2e_intr_mask,
38257+ .fifo_full = smart2e_fifo_full,
38258+ .intr_pending = smart2e_intr_pending,
38259+ .command_completed = smart2e_completed,
38260 };
38261
38262 /*
38263@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38264 }
38265
38266 static struct access_method smart1_access = {
38267- smart1_submit_command,
38268- smart1_intr_mask,
38269- smart1_fifo_full,
38270- smart1_intr_pending,
38271- smart1_completed,
38272+ .submit_command = smart1_submit_command,
38273+ .set_intr_mask = smart1_intr_mask,
38274+ .fifo_full = smart1_fifo_full,
38275+ .intr_pending = smart1_intr_pending,
38276+ .command_completed = smart1_completed,
38277 };
38278diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38279index f038dba..bb74c08 100644
38280--- a/drivers/bluetooth/btwilink.c
38281+++ b/drivers/bluetooth/btwilink.c
38282@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38283
38284 static int bt_ti_probe(struct platform_device *pdev)
38285 {
38286- static struct ti_st *hst;
38287+ struct ti_st *hst;
38288 struct hci_dev *hdev;
38289 int err;
38290
38291diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38292index 8a3aff7..d7538c2 100644
38293--- a/drivers/cdrom/cdrom.c
38294+++ b/drivers/cdrom/cdrom.c
38295@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38296 ENSURE(reset, CDC_RESET);
38297 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38298 cdi->mc_flags = 0;
38299- cdo->n_minors = 0;
38300 cdi->options = CDO_USE_FFLAGS;
38301
38302 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38303@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38304 else
38305 cdi->cdda_method = CDDA_OLD;
38306
38307- if (!cdo->generic_packet)
38308- cdo->generic_packet = cdrom_dummy_generic_packet;
38309+ if (!cdo->generic_packet) {
38310+ pax_open_kernel();
38311+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38312+ pax_close_kernel();
38313+ }
38314
38315 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38316 mutex_lock(&cdrom_mutex);
38317@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38318 if (cdi->exit)
38319 cdi->exit(cdi);
38320
38321- cdi->ops->n_minors--;
38322 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38323 }
38324
38325@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38326 */
38327 nr = nframes;
38328 do {
38329- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38330+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38331 if (cgc.buffer)
38332 break;
38333
38334@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38335 struct cdrom_device_info *cdi;
38336 int ret;
38337
38338- ret = scnprintf(info + *pos, max_size - *pos, header);
38339+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38340 if (!ret)
38341 return 1;
38342
38343diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38344index 51e75ad..39c4c76 100644
38345--- a/drivers/cdrom/gdrom.c
38346+++ b/drivers/cdrom/gdrom.c
38347@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38348 .audio_ioctl = gdrom_audio_ioctl,
38349 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38350 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38351- .n_minors = 1,
38352 };
38353
38354 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38355diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38356index 6e9f74a..50c7cea 100644
38357--- a/drivers/char/Kconfig
38358+++ b/drivers/char/Kconfig
38359@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38360
38361 config DEVKMEM
38362 bool "/dev/kmem virtual device support"
38363- default y
38364+ default n
38365+ depends on !GRKERNSEC_KMEM
38366 help
38367 Say Y here if you want to support the /dev/kmem device. The
38368 /dev/kmem device is rarely used, but can be used for certain
38369@@ -577,6 +578,7 @@ config DEVPORT
38370 bool
38371 depends on !M68K
38372 depends on ISA || PCI
38373+ depends on !GRKERNSEC_KMEM
38374 default y
38375
38376 source "drivers/s390/char/Kconfig"
38377diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38378index a48e05b..6bac831 100644
38379--- a/drivers/char/agp/compat_ioctl.c
38380+++ b/drivers/char/agp/compat_ioctl.c
38381@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38382 return -ENOMEM;
38383 }
38384
38385- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38386+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38387 sizeof(*usegment) * ureserve.seg_count)) {
38388 kfree(usegment);
38389 kfree(ksegment);
38390diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38391index b297033..fa217ca 100644
38392--- a/drivers/char/agp/frontend.c
38393+++ b/drivers/char/agp/frontend.c
38394@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38395 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38396 return -EFAULT;
38397
38398- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38399+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38400 return -EFAULT;
38401
38402 client = agp_find_client_by_pid(reserve.pid);
38403@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38404 if (segment == NULL)
38405 return -ENOMEM;
38406
38407- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38408+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38409 sizeof(struct agp_segment) * reserve.seg_count)) {
38410 kfree(segment);
38411 return -EFAULT;
38412diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38413index 4f94375..413694e 100644
38414--- a/drivers/char/genrtc.c
38415+++ b/drivers/char/genrtc.c
38416@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38417 switch (cmd) {
38418
38419 case RTC_PLL_GET:
38420+ memset(&pll, 0, sizeof(pll));
38421 if (get_rtc_pll(&pll))
38422 return -EINVAL;
38423 else
38424diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38425index d5d4cd8..22d561d 100644
38426--- a/drivers/char/hpet.c
38427+++ b/drivers/char/hpet.c
38428@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38429 }
38430
38431 static int
38432-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38433+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38434 struct hpet_info *info)
38435 {
38436 struct hpet_timer __iomem *timer;
38437diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38438index 86fe45c..c0ea948 100644
38439--- a/drivers/char/hw_random/intel-rng.c
38440+++ b/drivers/char/hw_random/intel-rng.c
38441@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38442
38443 if (no_fwh_detect)
38444 return -ENODEV;
38445- printk(warning);
38446+ printk("%s", warning);
38447 return -EBUSY;
38448 }
38449
38450diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38451index e6db938..835e3a2 100644
38452--- a/drivers/char/ipmi/ipmi_msghandler.c
38453+++ b/drivers/char/ipmi/ipmi_msghandler.c
38454@@ -438,7 +438,7 @@ struct ipmi_smi {
38455 struct proc_dir_entry *proc_dir;
38456 char proc_dir_name[10];
38457
38458- atomic_t stats[IPMI_NUM_STATS];
38459+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38460
38461 /*
38462 * run_to_completion duplicate of smb_info, smi_info
38463@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38464 static DEFINE_MUTEX(smi_watchers_mutex);
38465
38466 #define ipmi_inc_stat(intf, stat) \
38467- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38468+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38469 #define ipmi_get_stat(intf, stat) \
38470- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38471+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38472
38473 static int is_lan_addr(struct ipmi_addr *addr)
38474 {
38475@@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38476 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38477 init_waitqueue_head(&intf->waitq);
38478 for (i = 0; i < IPMI_NUM_STATS; i++)
38479- atomic_set(&intf->stats[i], 0);
38480+ atomic_set_unchecked(&intf->stats[i], 0);
38481
38482 intf->proc_dir = NULL;
38483
38484diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38485index 1c4bb4f..719e873 100644
38486--- a/drivers/char/ipmi/ipmi_si_intf.c
38487+++ b/drivers/char/ipmi/ipmi_si_intf.c
38488@@ -285,7 +285,7 @@ struct smi_info {
38489 unsigned char slave_addr;
38490
38491 /* Counters and things for the proc filesystem. */
38492- atomic_t stats[SI_NUM_STATS];
38493+ atomic_unchecked_t stats[SI_NUM_STATS];
38494
38495 struct task_struct *thread;
38496
38497@@ -294,9 +294,9 @@ struct smi_info {
38498 };
38499
38500 #define smi_inc_stat(smi, stat) \
38501- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38502+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38503 #define smi_get_stat(smi, stat) \
38504- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38505+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38506
38507 #define SI_MAX_PARMS 4
38508
38509@@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
38510 atomic_set(&new_smi->req_events, 0);
38511 new_smi->run_to_completion = false;
38512 for (i = 0; i < SI_NUM_STATS; i++)
38513- atomic_set(&new_smi->stats[i], 0);
38514+ atomic_set_unchecked(&new_smi->stats[i], 0);
38515
38516 new_smi->interrupt_disabled = true;
38517 atomic_set(&new_smi->stop_operation, 0);
38518diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38519index 917403f..dddd899 100644
38520--- a/drivers/char/mem.c
38521+++ b/drivers/char/mem.c
38522@@ -18,6 +18,7 @@
38523 #include <linux/raw.h>
38524 #include <linux/tty.h>
38525 #include <linux/capability.h>
38526+#include <linux/security.h>
38527 #include <linux/ptrace.h>
38528 #include <linux/device.h>
38529 #include <linux/highmem.h>
38530@@ -36,6 +37,10 @@
38531
38532 #define DEVPORT_MINOR 4
38533
38534+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38535+extern const struct file_operations grsec_fops;
38536+#endif
38537+
38538 static inline unsigned long size_inside_page(unsigned long start,
38539 unsigned long size)
38540 {
38541@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38542
38543 while (cursor < to) {
38544 if (!devmem_is_allowed(pfn)) {
38545+#ifdef CONFIG_GRKERNSEC_KMEM
38546+ gr_handle_mem_readwrite(from, to);
38547+#else
38548 printk(KERN_INFO
38549 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38550 current->comm, from, to);
38551+#endif
38552 return 0;
38553 }
38554 cursor += PAGE_SIZE;
38555@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38556 }
38557 return 1;
38558 }
38559+#elif defined(CONFIG_GRKERNSEC_KMEM)
38560+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38561+{
38562+ return 0;
38563+}
38564 #else
38565 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38566 {
38567@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38568
38569 while (count > 0) {
38570 unsigned long remaining;
38571+ char *temp;
38572
38573 sz = size_inside_page(p, count);
38574
38575@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38576 if (!ptr)
38577 return -EFAULT;
38578
38579- remaining = copy_to_user(buf, ptr, sz);
38580+#ifdef CONFIG_PAX_USERCOPY
38581+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38582+ if (!temp) {
38583+ unxlate_dev_mem_ptr(p, ptr);
38584+ return -ENOMEM;
38585+ }
38586+ memcpy(temp, ptr, sz);
38587+#else
38588+ temp = ptr;
38589+#endif
38590+
38591+ remaining = copy_to_user(buf, temp, sz);
38592+
38593+#ifdef CONFIG_PAX_USERCOPY
38594+ kfree(temp);
38595+#endif
38596+
38597 unxlate_dev_mem_ptr(p, ptr);
38598 if (remaining)
38599 return -EFAULT;
38600@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38601 size_t count, loff_t *ppos)
38602 {
38603 unsigned long p = *ppos;
38604- ssize_t low_count, read, sz;
38605+ ssize_t low_count, read, sz, err = 0;
38606 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38607- int err = 0;
38608
38609 read = 0;
38610 if (p < (unsigned long) high_memory) {
38611@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38612 }
38613 #endif
38614 while (low_count > 0) {
38615+ char *temp;
38616+
38617 sz = size_inside_page(p, low_count);
38618
38619 /*
38620@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38621 */
38622 kbuf = xlate_dev_kmem_ptr((char *)p);
38623
38624- if (copy_to_user(buf, kbuf, sz))
38625+#ifdef CONFIG_PAX_USERCOPY
38626+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38627+ if (!temp)
38628+ return -ENOMEM;
38629+ memcpy(temp, kbuf, sz);
38630+#else
38631+ temp = kbuf;
38632+#endif
38633+
38634+ err = copy_to_user(buf, temp, sz);
38635+
38636+#ifdef CONFIG_PAX_USERCOPY
38637+ kfree(temp);
38638+#endif
38639+
38640+ if (err)
38641 return -EFAULT;
38642 buf += sz;
38643 p += sz;
38644@@ -827,6 +874,9 @@ static const struct memdev {
38645 #ifdef CONFIG_PRINTK
38646 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38647 #endif
38648+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38649+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38650+#endif
38651 };
38652
38653 static int memory_open(struct inode *inode, struct file *filp)
38654@@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
38655 continue;
38656
38657 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38658- NULL, devlist[minor].name);
38659+ NULL, "%s", devlist[minor].name);
38660 }
38661
38662 return tty_init();
38663diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38664index 9df78e2..01ba9ae 100644
38665--- a/drivers/char/nvram.c
38666+++ b/drivers/char/nvram.c
38667@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38668
38669 spin_unlock_irq(&rtc_lock);
38670
38671- if (copy_to_user(buf, contents, tmp - contents))
38672+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38673 return -EFAULT;
38674
38675 *ppos = i;
38676diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38677index 8320abd..ec48108 100644
38678--- a/drivers/char/pcmcia/synclink_cs.c
38679+++ b/drivers/char/pcmcia/synclink_cs.c
38680@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38681
38682 if (debug_level >= DEBUG_LEVEL_INFO)
38683 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38684- __FILE__, __LINE__, info->device_name, port->count);
38685+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38686
38687- WARN_ON(!port->count);
38688+ WARN_ON(!atomic_read(&port->count));
38689
38690 if (tty_port_close_start(port, tty, filp) == 0)
38691 goto cleanup;
38692@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38693 cleanup:
38694 if (debug_level >= DEBUG_LEVEL_INFO)
38695 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38696- tty->driver->name, port->count);
38697+ tty->driver->name, atomic_read(&port->count));
38698 }
38699
38700 /* Wait until the transmitter is empty.
38701@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38702
38703 if (debug_level >= DEBUG_LEVEL_INFO)
38704 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38705- __FILE__, __LINE__, tty->driver->name, port->count);
38706+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38707
38708 /* If port is closing, signal caller to try again */
38709 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38710@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38711 goto cleanup;
38712 }
38713 spin_lock(&port->lock);
38714- port->count++;
38715+ atomic_inc(&port->count);
38716 spin_unlock(&port->lock);
38717 spin_unlock_irqrestore(&info->netlock, flags);
38718
38719- if (port->count == 1) {
38720+ if (atomic_read(&port->count) == 1) {
38721 /* 1st open on this device, init hardware */
38722 retval = startup(info, tty);
38723 if (retval < 0)
38724@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38725 unsigned short new_crctype;
38726
38727 /* return error if TTY interface open */
38728- if (info->port.count)
38729+ if (atomic_read(&info->port.count))
38730 return -EBUSY;
38731
38732 switch (encoding)
38733@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38734
38735 /* arbitrate between network and tty opens */
38736 spin_lock_irqsave(&info->netlock, flags);
38737- if (info->port.count != 0 || info->netcount != 0) {
38738+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38739 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38740 spin_unlock_irqrestore(&info->netlock, flags);
38741 return -EBUSY;
38742@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38743 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38744
38745 /* return error if TTY interface open */
38746- if (info->port.count)
38747+ if (atomic_read(&info->port.count))
38748 return -EBUSY;
38749
38750 if (cmd != SIOCWANDEV)
38751diff --git a/drivers/char/random.c b/drivers/char/random.c
38752index 18ec404..32033f3 100644
38753--- a/drivers/char/random.c
38754+++ b/drivers/char/random.c
38755@@ -270,10 +270,17 @@
38756 /*
38757 * Configuration information
38758 */
38759+#ifdef CONFIG_GRKERNSEC_RANDNET
38760+#define INPUT_POOL_SHIFT 14
38761+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38762+#define OUTPUT_POOL_SHIFT 12
38763+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38764+#else
38765 #define INPUT_POOL_SHIFT 12
38766 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38767 #define OUTPUT_POOL_SHIFT 10
38768 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38769+#endif
38770 #define SEC_XFER_SIZE 512
38771 #define EXTRACT_SIZE 10
38772
38773@@ -284,9 +291,6 @@
38774 /*
38775 * To allow fractional bits to be tracked, the entropy_count field is
38776 * denominated in units of 1/8th bits.
38777- *
38778- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38779- * credit_entropy_bits() needs to be 64 bits wide.
38780 */
38781 #define ENTROPY_SHIFT 3
38782 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38783@@ -361,12 +365,19 @@ static struct poolinfo {
38784 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38785 int tap1, tap2, tap3, tap4, tap5;
38786 } poolinfo_table[] = {
38787+#ifdef CONFIG_GRKERNSEC_RANDNET
38788+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38789+ { S(512), 411, 308, 208, 104, 1 },
38790+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38791+ { S(128), 104, 76, 51, 25, 1 },
38792+#else
38793 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38794 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38795 { S(128), 104, 76, 51, 25, 1 },
38796 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38797 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38798 { S(32), 26, 19, 14, 7, 1 },
38799+#endif
38800 #if 0
38801 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38802 { S(2048), 1638, 1231, 819, 411, 1 },
38803@@ -433,9 +444,9 @@ struct entropy_store {
38804 };
38805
38806 static void push_to_pool(struct work_struct *work);
38807-static __u32 input_pool_data[INPUT_POOL_WORDS];
38808-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38809-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38810+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38811+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38812+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38813
38814 static struct entropy_store input_pool = {
38815 .poolinfo = &poolinfo_table[0],
38816@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38817 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38818 }
38819
38820- ACCESS_ONCE(r->input_rotate) = input_rotate;
38821- ACCESS_ONCE(r->add_ptr) = i;
38822+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38823+ ACCESS_ONCE_RW(r->add_ptr) = i;
38824 smp_wmb();
38825
38826 if (out)
38827@@ -632,7 +643,7 @@ retry:
38828 /* The +2 corresponds to the /4 in the denominator */
38829
38830 do {
38831- unsigned int anfrac = min(pnfrac, pool_size/2);
38832+ u64 anfrac = min(pnfrac, pool_size/2);
38833 unsigned int add =
38834 ((pool_size - entropy_count)*anfrac*3) >> s;
38835
38836@@ -1176,7 +1187,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38837
38838 extract_buf(r, tmp);
38839 i = min_t(int, nbytes, EXTRACT_SIZE);
38840- if (copy_to_user(buf, tmp, i)) {
38841+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38842 ret = -EFAULT;
38843 break;
38844 }
38845@@ -1566,7 +1577,7 @@ static char sysctl_bootid[16];
38846 static int proc_do_uuid(struct ctl_table *table, int write,
38847 void __user *buffer, size_t *lenp, loff_t *ppos)
38848 {
38849- struct ctl_table fake_table;
38850+ ctl_table_no_const fake_table;
38851 unsigned char buf[64], tmp_uuid[16], *uuid;
38852
38853 uuid = table->data;
38854@@ -1596,7 +1607,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38855 static int proc_do_entropy(ctl_table *table, int write,
38856 void __user *buffer, size_t *lenp, loff_t *ppos)
38857 {
38858- ctl_table fake_table;
38859+ ctl_table_no_const fake_table;
38860 int entropy_count;
38861
38862 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38863diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38864index 7cc1fe22..b602d6b 100644
38865--- a/drivers/char/sonypi.c
38866+++ b/drivers/char/sonypi.c
38867@@ -54,6 +54,7 @@
38868
38869 #include <asm/uaccess.h>
38870 #include <asm/io.h>
38871+#include <asm/local.h>
38872
38873 #include <linux/sonypi.h>
38874
38875@@ -490,7 +491,7 @@ static struct sonypi_device {
38876 spinlock_t fifo_lock;
38877 wait_queue_head_t fifo_proc_list;
38878 struct fasync_struct *fifo_async;
38879- int open_count;
38880+ local_t open_count;
38881 int model;
38882 struct input_dev *input_jog_dev;
38883 struct input_dev *input_key_dev;
38884@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38885 static int sonypi_misc_release(struct inode *inode, struct file *file)
38886 {
38887 mutex_lock(&sonypi_device.lock);
38888- sonypi_device.open_count--;
38889+ local_dec(&sonypi_device.open_count);
38890 mutex_unlock(&sonypi_device.lock);
38891 return 0;
38892 }
38893@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38894 {
38895 mutex_lock(&sonypi_device.lock);
38896 /* Flush input queue on first open */
38897- if (!sonypi_device.open_count)
38898+ if (!local_read(&sonypi_device.open_count))
38899 kfifo_reset(&sonypi_device.fifo);
38900- sonypi_device.open_count++;
38901+ local_inc(&sonypi_device.open_count);
38902 mutex_unlock(&sonypi_device.lock);
38903
38904 return 0;
38905diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38906index b9a57fa..5bb9e38 100644
38907--- a/drivers/char/tpm/tpm_acpi.c
38908+++ b/drivers/char/tpm/tpm_acpi.c
38909@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38910 virt = acpi_os_map_memory(start, len);
38911 if (!virt) {
38912 kfree(log->bios_event_log);
38913+ log->bios_event_log = NULL;
38914 printk("%s: ERROR - Unable to map memory\n", __func__);
38915 return -EIO;
38916 }
38917
38918- memcpy_fromio(log->bios_event_log, virt, len);
38919+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38920
38921 acpi_os_unmap_memory(virt, len);
38922 return 0;
38923diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38924index 59f7cb2..bac8b6d 100644
38925--- a/drivers/char/tpm/tpm_eventlog.c
38926+++ b/drivers/char/tpm/tpm_eventlog.c
38927@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38928 event = addr;
38929
38930 if ((event->event_type == 0 && event->event_size == 0) ||
38931- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38932+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38933 return NULL;
38934
38935 return addr;
38936@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38937 return NULL;
38938
38939 if ((event->event_type == 0 && event->event_size == 0) ||
38940- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38941+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38942 return NULL;
38943
38944 (*pos)++;
38945@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38946 int i;
38947
38948 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38949- seq_putc(m, data[i]);
38950+ if (!seq_putc(m, data[i]))
38951+ return -EFAULT;
38952
38953 return 0;
38954 }
38955diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38956index 60aafb8..10c08e0 100644
38957--- a/drivers/char/virtio_console.c
38958+++ b/drivers/char/virtio_console.c
38959@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38960 if (to_user) {
38961 ssize_t ret;
38962
38963- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38964+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38965 if (ret)
38966 return -EFAULT;
38967 } else {
38968@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38969 if (!port_has_data(port) && !port->host_connected)
38970 return 0;
38971
38972- return fill_readbuf(port, ubuf, count, true);
38973+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38974 }
38975
38976 static int wait_port_writable(struct port *port, bool nonblock)
38977diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38978index 57a078e..c17cde8 100644
38979--- a/drivers/clk/clk-composite.c
38980+++ b/drivers/clk/clk-composite.c
38981@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38982 struct clk *clk;
38983 struct clk_init_data init;
38984 struct clk_composite *composite;
38985- struct clk_ops *clk_composite_ops;
38986+ clk_ops_no_const *clk_composite_ops;
38987
38988 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38989 if (!composite) {
38990diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38991index 501d513..fb0ecf9 100644
38992--- a/drivers/clk/socfpga/clk-gate.c
38993+++ b/drivers/clk/socfpga/clk-gate.c
38994@@ -22,6 +22,7 @@
38995 #include <linux/mfd/syscon.h>
38996 #include <linux/of.h>
38997 #include <linux/regmap.h>
38998+#include <asm/pgtable.h>
38999
39000 #include "clk.h"
39001
39002@@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39003 return 0;
39004 }
39005
39006-static struct clk_ops gateclk_ops = {
39007+static clk_ops_no_const gateclk_ops __read_only = {
39008 .prepare = socfpga_clk_prepare,
39009 .recalc_rate = socfpga_clk_recalc_rate,
39010 .get_parent = socfpga_clk_get_parent,
39011@@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39012 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39013 socfpga_clk->hw.bit_idx = clk_gate[1];
39014
39015- gateclk_ops.enable = clk_gate_ops.enable;
39016- gateclk_ops.disable = clk_gate_ops.disable;
39017+ pax_open_kernel();
39018+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39019+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39020+ pax_close_kernel();
39021 }
39022
39023 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39024diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39025index de6da95..c98278b 100644
39026--- a/drivers/clk/socfpga/clk-pll.c
39027+++ b/drivers/clk/socfpga/clk-pll.c
39028@@ -21,6 +21,7 @@
39029 #include <linux/io.h>
39030 #include <linux/of.h>
39031 #include <linux/of_address.h>
39032+#include <asm/pgtable.h>
39033
39034 #include "clk.h"
39035
39036@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39037 CLK_MGR_PLL_CLK_SRC_MASK;
39038 }
39039
39040-static struct clk_ops clk_pll_ops = {
39041+static clk_ops_no_const clk_pll_ops __read_only = {
39042 .recalc_rate = clk_pll_recalc_rate,
39043 .get_parent = clk_pll_get_parent,
39044 };
39045@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39046 pll_clk->hw.hw.init = &init;
39047
39048 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39049- clk_pll_ops.enable = clk_gate_ops.enable;
39050- clk_pll_ops.disable = clk_gate_ops.disable;
39051+ pax_open_kernel();
39052+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39053+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39054+ pax_close_kernel();
39055
39056 clk = clk_register(NULL, &pll_clk->hw.hw);
39057 if (WARN_ON(IS_ERR(clk))) {
39058diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39059index 000e4e0..4770351 100644
39060--- a/drivers/cpufreq/acpi-cpufreq.c
39061+++ b/drivers/cpufreq/acpi-cpufreq.c
39062@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39063 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39064 per_cpu(acfreq_data, cpu) = data;
39065
39066- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39067- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39068+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39069+ pax_open_kernel();
39070+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39071+ pax_close_kernel();
39072+ }
39073
39074 result = acpi_processor_register_performance(data->acpi_data, cpu);
39075 if (result)
39076@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39077 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39078 break;
39079 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39080- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39081+ pax_open_kernel();
39082+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39083+ pax_close_kernel();
39084 break;
39085 default:
39086 break;
39087@@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
39088 if (!msrs)
39089 return;
39090
39091- acpi_cpufreq_driver.boost_supported = true;
39092- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39093+ pax_open_kernel();
39094+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39095+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39096+ pax_close_kernel();
39097
39098 cpu_notifier_register_begin();
39099
39100diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39101index dcac12d..f12df60 100644
39102--- a/drivers/cpufreq/cpufreq.c
39103+++ b/drivers/cpufreq/cpufreq.c
39104@@ -2024,7 +2024,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39105 }
39106
39107 mutex_lock(&cpufreq_governor_mutex);
39108- list_del(&governor->governor_list);
39109+ pax_list_del(&governor->governor_list);
39110 mutex_unlock(&cpufreq_governor_mutex);
39111 return;
39112 }
39113@@ -2240,7 +2240,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39114 return NOTIFY_OK;
39115 }
39116
39117-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39118+static struct notifier_block cpufreq_cpu_notifier = {
39119 .notifier_call = cpufreq_cpu_callback,
39120 };
39121
39122@@ -2280,13 +2280,17 @@ int cpufreq_boost_trigger_state(int state)
39123 return 0;
39124
39125 write_lock_irqsave(&cpufreq_driver_lock, flags);
39126- cpufreq_driver->boost_enabled = state;
39127+ pax_open_kernel();
39128+ *(bool *)&cpufreq_driver->boost_enabled = state;
39129+ pax_close_kernel();
39130 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39131
39132 ret = cpufreq_driver->set_boost(state);
39133 if (ret) {
39134 write_lock_irqsave(&cpufreq_driver_lock, flags);
39135- cpufreq_driver->boost_enabled = !state;
39136+ pax_open_kernel();
39137+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39138+ pax_close_kernel();
39139 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39140
39141 pr_err("%s: Cannot %s BOOST\n",
39142@@ -2342,8 +2346,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39143
39144 pr_debug("trying to register driver %s\n", driver_data->name);
39145
39146- if (driver_data->setpolicy)
39147- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39148+ if (driver_data->setpolicy) {
39149+ pax_open_kernel();
39150+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39151+ pax_close_kernel();
39152+ }
39153
39154 write_lock_irqsave(&cpufreq_driver_lock, flags);
39155 if (cpufreq_driver) {
39156@@ -2358,8 +2365,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39157 * Check if driver provides function to enable boost -
39158 * if not, use cpufreq_boost_set_sw as default
39159 */
39160- if (!cpufreq_driver->set_boost)
39161- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39162+ if (!cpufreq_driver->set_boost) {
39163+ pax_open_kernel();
39164+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39165+ pax_close_kernel();
39166+ }
39167
39168 ret = cpufreq_sysfs_create_file(&boost.attr);
39169 if (ret) {
39170diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39171index e1c6433..31203ae 100644
39172--- a/drivers/cpufreq/cpufreq_governor.c
39173+++ b/drivers/cpufreq/cpufreq_governor.c
39174@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39175 struct dbs_data *dbs_data;
39176 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39177 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39178- struct od_ops *od_ops = NULL;
39179+ const struct od_ops *od_ops = NULL;
39180 struct od_dbs_tuners *od_tuners = NULL;
39181 struct cs_dbs_tuners *cs_tuners = NULL;
39182 struct cpu_dbs_common_info *cpu_cdbs;
39183@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39184
39185 if ((cdata->governor == GOV_CONSERVATIVE) &&
39186 (!policy->governor->initialized)) {
39187- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39188+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39189
39190 cpufreq_register_notifier(cs_ops->notifier_block,
39191 CPUFREQ_TRANSITION_NOTIFIER);
39192@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39193
39194 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39195 (policy->governor->initialized == 1)) {
39196- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39197+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39198
39199 cpufreq_unregister_notifier(cs_ops->notifier_block,
39200 CPUFREQ_TRANSITION_NOTIFIER);
39201diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39202index bfb9ae1..e1d3a7e 100644
39203--- a/drivers/cpufreq/cpufreq_governor.h
39204+++ b/drivers/cpufreq/cpufreq_governor.h
39205@@ -205,7 +205,7 @@ struct common_dbs_data {
39206 void (*exit)(struct dbs_data *dbs_data);
39207
39208 /* Governor specific ops, see below */
39209- void *gov_ops;
39210+ const void *gov_ops;
39211 };
39212
39213 /* Governor Per policy data */
39214@@ -225,7 +225,7 @@ struct od_ops {
39215 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39216 unsigned int freq_next, unsigned int relation);
39217 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39218-};
39219+} __no_const;
39220
39221 struct cs_ops {
39222 struct notifier_block *notifier_block;
39223diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39224index 18d4091..434be15 100644
39225--- a/drivers/cpufreq/cpufreq_ondemand.c
39226+++ b/drivers/cpufreq/cpufreq_ondemand.c
39227@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39228
39229 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39230
39231-static struct od_ops od_ops = {
39232+static struct od_ops od_ops __read_only = {
39233 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39234 .powersave_bias_target = generic_powersave_bias_target,
39235 .freq_increase = dbs_freq_increase,
39236@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39237 (struct cpufreq_policy *, unsigned int, unsigned int),
39238 unsigned int powersave_bias)
39239 {
39240- od_ops.powersave_bias_target = f;
39241+ pax_open_kernel();
39242+ *(void **)&od_ops.powersave_bias_target = f;
39243+ pax_close_kernel();
39244 od_set_powersave_bias(powersave_bias);
39245 }
39246 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39247
39248 void od_unregister_powersave_bias_handler(void)
39249 {
39250- od_ops.powersave_bias_target = generic_powersave_bias_target;
39251+ pax_open_kernel();
39252+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39253+ pax_close_kernel();
39254 od_set_powersave_bias(0);
39255 }
39256 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39257diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39258index 870eecc..787bbca 100644
39259--- a/drivers/cpufreq/intel_pstate.c
39260+++ b/drivers/cpufreq/intel_pstate.c
39261@@ -125,10 +125,10 @@ struct pstate_funcs {
39262 struct cpu_defaults {
39263 struct pstate_adjust_policy pid_policy;
39264 struct pstate_funcs funcs;
39265-};
39266+} __do_const;
39267
39268 static struct pstate_adjust_policy pid_params;
39269-static struct pstate_funcs pstate_funcs;
39270+static struct pstate_funcs *pstate_funcs;
39271
39272 struct perf_limits {
39273 int no_turbo;
39274@@ -530,7 +530,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39275
39276 cpu->pstate.current_pstate = pstate;
39277
39278- pstate_funcs.set(cpu, pstate);
39279+ pstate_funcs->set(cpu, pstate);
39280 }
39281
39282 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39283@@ -552,12 +552,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39284 {
39285 sprintf(cpu->name, "Intel 2nd generation core");
39286
39287- cpu->pstate.min_pstate = pstate_funcs.get_min();
39288- cpu->pstate.max_pstate = pstate_funcs.get_max();
39289- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39290+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39291+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39292+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39293
39294- if (pstate_funcs.get_vid)
39295- pstate_funcs.get_vid(cpu);
39296+ if (pstate_funcs->get_vid)
39297+ pstate_funcs->get_vid(cpu);
39298 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39299 }
39300
39301@@ -847,9 +847,9 @@ static int intel_pstate_msrs_not_valid(void)
39302 rdmsrl(MSR_IA32_APERF, aperf);
39303 rdmsrl(MSR_IA32_MPERF, mperf);
39304
39305- if (!pstate_funcs.get_max() ||
39306- !pstate_funcs.get_min() ||
39307- !pstate_funcs.get_turbo())
39308+ if (!pstate_funcs->get_max() ||
39309+ !pstate_funcs->get_min() ||
39310+ !pstate_funcs->get_turbo())
39311 return -ENODEV;
39312
39313 rdmsrl(MSR_IA32_APERF, tmp);
39314@@ -863,7 +863,7 @@ static int intel_pstate_msrs_not_valid(void)
39315 return 0;
39316 }
39317
39318-static void copy_pid_params(struct pstate_adjust_policy *policy)
39319+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39320 {
39321 pid_params.sample_rate_ms = policy->sample_rate_ms;
39322 pid_params.p_gain_pct = policy->p_gain_pct;
39323@@ -875,11 +875,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39324
39325 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39326 {
39327- pstate_funcs.get_max = funcs->get_max;
39328- pstate_funcs.get_min = funcs->get_min;
39329- pstate_funcs.get_turbo = funcs->get_turbo;
39330- pstate_funcs.set = funcs->set;
39331- pstate_funcs.get_vid = funcs->get_vid;
39332+ pstate_funcs = funcs;
39333 }
39334
39335 #if IS_ENABLED(CONFIG_ACPI)
39336diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39337index 529cfd9..0e28fff 100644
39338--- a/drivers/cpufreq/p4-clockmod.c
39339+++ b/drivers/cpufreq/p4-clockmod.c
39340@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39341 case 0x0F: /* Core Duo */
39342 case 0x16: /* Celeron Core */
39343 case 0x1C: /* Atom */
39344- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39345+ pax_open_kernel();
39346+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39347+ pax_close_kernel();
39348 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39349 case 0x0D: /* Pentium M (Dothan) */
39350- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39351+ pax_open_kernel();
39352+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39353+ pax_close_kernel();
39354 /* fall through */
39355 case 0x09: /* Pentium M (Banias) */
39356 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39357@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39358
39359 /* on P-4s, the TSC runs with constant frequency independent whether
39360 * throttling is active or not. */
39361- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39362+ pax_open_kernel();
39363+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39364+ pax_close_kernel();
39365
39366 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39367 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39368diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39369index 9bb42ba..b01b4a2 100644
39370--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39371+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39372@@ -18,14 +18,12 @@
39373 #include <asm/head.h>
39374 #include <asm/timer.h>
39375
39376-static struct cpufreq_driver *cpufreq_us3_driver;
39377-
39378 struct us3_freq_percpu_info {
39379 struct cpufreq_frequency_table table[4];
39380 };
39381
39382 /* Indexed by cpu number. */
39383-static struct us3_freq_percpu_info *us3_freq_table;
39384+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39385
39386 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39387 * in the Safari config register.
39388@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39389
39390 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39391 {
39392- if (cpufreq_us3_driver)
39393- us3_freq_target(policy, 0);
39394+ us3_freq_target(policy, 0);
39395
39396 return 0;
39397 }
39398
39399+static int __init us3_freq_init(void);
39400+static void __exit us3_freq_exit(void);
39401+
39402+static struct cpufreq_driver cpufreq_us3_driver = {
39403+ .init = us3_freq_cpu_init,
39404+ .verify = cpufreq_generic_frequency_table_verify,
39405+ .target_index = us3_freq_target,
39406+ .get = us3_freq_get,
39407+ .exit = us3_freq_cpu_exit,
39408+ .name = "UltraSPARC-III",
39409+
39410+};
39411+
39412 static int __init us3_freq_init(void)
39413 {
39414 unsigned long manuf, impl, ver;
39415- int ret;
39416
39417 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39418 return -ENODEV;
39419@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39420 (impl == CHEETAH_IMPL ||
39421 impl == CHEETAH_PLUS_IMPL ||
39422 impl == JAGUAR_IMPL ||
39423- impl == PANTHER_IMPL)) {
39424- struct cpufreq_driver *driver;
39425-
39426- ret = -ENOMEM;
39427- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39428- if (!driver)
39429- goto err_out;
39430-
39431- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39432- GFP_KERNEL);
39433- if (!us3_freq_table)
39434- goto err_out;
39435-
39436- driver->init = us3_freq_cpu_init;
39437- driver->verify = cpufreq_generic_frequency_table_verify;
39438- driver->target_index = us3_freq_target;
39439- driver->get = us3_freq_get;
39440- driver->exit = us3_freq_cpu_exit;
39441- strcpy(driver->name, "UltraSPARC-III");
39442-
39443- cpufreq_us3_driver = driver;
39444- ret = cpufreq_register_driver(driver);
39445- if (ret)
39446- goto err_out;
39447-
39448- return 0;
39449-
39450-err_out:
39451- if (driver) {
39452- kfree(driver);
39453- cpufreq_us3_driver = NULL;
39454- }
39455- kfree(us3_freq_table);
39456- us3_freq_table = NULL;
39457- return ret;
39458- }
39459+ impl == PANTHER_IMPL))
39460+ return cpufreq_register_driver(&cpufreq_us3_driver);
39461
39462 return -ENODEV;
39463 }
39464
39465 static void __exit us3_freq_exit(void)
39466 {
39467- if (cpufreq_us3_driver) {
39468- cpufreq_unregister_driver(cpufreq_us3_driver);
39469- kfree(cpufreq_us3_driver);
39470- cpufreq_us3_driver = NULL;
39471- kfree(us3_freq_table);
39472- us3_freq_table = NULL;
39473- }
39474+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39475 }
39476
39477 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39478diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39479index 6723f03..3465190 100644
39480--- a/drivers/cpufreq/speedstep-centrino.c
39481+++ b/drivers/cpufreq/speedstep-centrino.c
39482@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39483 !cpu_has(cpu, X86_FEATURE_EST))
39484 return -ENODEV;
39485
39486- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39487- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39488+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39489+ pax_open_kernel();
39490+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39491+ pax_close_kernel();
39492+ }
39493
39494 if (policy->cpu != 0)
39495 return -ENODEV;
39496diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39497index 136d6a2..06e373d 100644
39498--- a/drivers/cpuidle/driver.c
39499+++ b/drivers/cpuidle/driver.c
39500@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39501
39502 static void poll_idle_init(struct cpuidle_driver *drv)
39503 {
39504- struct cpuidle_state *state = &drv->states[0];
39505+ cpuidle_state_no_const *state = &drv->states[0];
39506
39507 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39508 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39509diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39510index ca89412..a7b9c49 100644
39511--- a/drivers/cpuidle/governor.c
39512+++ b/drivers/cpuidle/governor.c
39513@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39514 mutex_lock(&cpuidle_lock);
39515 if (__cpuidle_find_governor(gov->name) == NULL) {
39516 ret = 0;
39517- list_add_tail(&gov->governor_list, &cpuidle_governors);
39518+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39519 if (!cpuidle_curr_governor ||
39520 cpuidle_curr_governor->rating < gov->rating)
39521 cpuidle_switch_governor(gov);
39522diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39523index efe2f17..b8124f9 100644
39524--- a/drivers/cpuidle/sysfs.c
39525+++ b/drivers/cpuidle/sysfs.c
39526@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39527 NULL
39528 };
39529
39530-static struct attribute_group cpuidle_attr_group = {
39531+static attribute_group_no_const cpuidle_attr_group = {
39532 .attrs = cpuidle_default_attrs,
39533 .name = "cpuidle",
39534 };
39535diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39536index 12fea3e..1e28f47 100644
39537--- a/drivers/crypto/hifn_795x.c
39538+++ b/drivers/crypto/hifn_795x.c
39539@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39540 MODULE_PARM_DESC(hifn_pll_ref,
39541 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39542
39543-static atomic_t hifn_dev_number;
39544+static atomic_unchecked_t hifn_dev_number;
39545
39546 #define ACRYPTO_OP_DECRYPT 0
39547 #define ACRYPTO_OP_ENCRYPT 1
39548@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39549 goto err_out_disable_pci_device;
39550
39551 snprintf(name, sizeof(name), "hifn%d",
39552- atomic_inc_return(&hifn_dev_number)-1);
39553+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39554
39555 err = pci_request_regions(pdev, name);
39556 if (err)
39557diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39558index 2042ec3..a9ce67f 100644
39559--- a/drivers/devfreq/devfreq.c
39560+++ b/drivers/devfreq/devfreq.c
39561@@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39562 goto err_out;
39563 }
39564
39565- list_add(&governor->node, &devfreq_governor_list);
39566+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39567
39568 list_for_each_entry(devfreq, &devfreq_list, node) {
39569 int ret = 0;
39570@@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39571 }
39572 }
39573
39574- list_del(&governor->node);
39575+ pax_list_del((struct list_head *)&governor->node);
39576 err_out:
39577 mutex_unlock(&devfreq_list_lock);
39578
39579diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39580index 5239677..1cb71a8 100644
39581--- a/drivers/dma/sh/shdma-base.c
39582+++ b/drivers/dma/sh/shdma-base.c
39583@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39584 schan->slave_id = -EINVAL;
39585 }
39586
39587- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39588- sdev->desc_size, GFP_KERNEL);
39589+ schan->desc = kcalloc(sdev->desc_size,
39590+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39591 if (!schan->desc) {
39592 ret = -ENOMEM;
39593 goto edescalloc;
39594diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39595index dda7e75..0a4c867 100644
39596--- a/drivers/dma/sh/shdmac.c
39597+++ b/drivers/dma/sh/shdmac.c
39598@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39599 return ret;
39600 }
39601
39602-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39603+static struct notifier_block sh_dmae_nmi_notifier = {
39604 .notifier_call = sh_dmae_nmi_handler,
39605
39606 /* Run before NMI debug handler and KGDB */
39607diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39608index 592af5f..bb1d583 100644
39609--- a/drivers/edac/edac_device.c
39610+++ b/drivers/edac/edac_device.c
39611@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39612 */
39613 int edac_device_alloc_index(void)
39614 {
39615- static atomic_t device_indexes = ATOMIC_INIT(0);
39616+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39617
39618- return atomic_inc_return(&device_indexes) - 1;
39619+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39620 }
39621 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39622
39623diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39624index 01fae82..1dd8289 100644
39625--- a/drivers/edac/edac_mc_sysfs.c
39626+++ b/drivers/edac/edac_mc_sysfs.c
39627@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39628 struct dev_ch_attribute {
39629 struct device_attribute attr;
39630 int channel;
39631-};
39632+} __do_const;
39633
39634 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39635 struct dev_ch_attribute dev_attr_legacy_##_name = \
39636@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39637 }
39638
39639 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39640+ pax_open_kernel();
39641 if (mci->get_sdram_scrub_rate) {
39642- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39643- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39644+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39645+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39646 }
39647 if (mci->set_sdram_scrub_rate) {
39648- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39649- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39650+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39651+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39652 }
39653+ pax_close_kernel();
39654 err = device_create_file(&mci->dev,
39655 &dev_attr_sdram_scrub_rate);
39656 if (err) {
39657diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39658index 2cf44b4d..6dd2dc7 100644
39659--- a/drivers/edac/edac_pci.c
39660+++ b/drivers/edac/edac_pci.c
39661@@ -29,7 +29,7 @@
39662
39663 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39664 static LIST_HEAD(edac_pci_list);
39665-static atomic_t pci_indexes = ATOMIC_INIT(0);
39666+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39667
39668 /*
39669 * edac_pci_alloc_ctl_info
39670@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39671 */
39672 int edac_pci_alloc_index(void)
39673 {
39674- return atomic_inc_return(&pci_indexes) - 1;
39675+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39676 }
39677 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39678
39679diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39680index e8658e4..22746d6 100644
39681--- a/drivers/edac/edac_pci_sysfs.c
39682+++ b/drivers/edac/edac_pci_sysfs.c
39683@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39684 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39685 static int edac_pci_poll_msec = 1000; /* one second workq period */
39686
39687-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39688-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39689+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39690+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39691
39692 static struct kobject *edac_pci_top_main_kobj;
39693 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39694@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39695 void *value;
39696 ssize_t(*show) (void *, char *);
39697 ssize_t(*store) (void *, const char *, size_t);
39698-};
39699+} __do_const;
39700
39701 /* Set of show/store abstract level functions for PCI Parity object */
39702 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39703@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39704 edac_printk(KERN_CRIT, EDAC_PCI,
39705 "Signaled System Error on %s\n",
39706 pci_name(dev));
39707- atomic_inc(&pci_nonparity_count);
39708+ atomic_inc_unchecked(&pci_nonparity_count);
39709 }
39710
39711 if (status & (PCI_STATUS_PARITY)) {
39712@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39713 "Master Data Parity Error on %s\n",
39714 pci_name(dev));
39715
39716- atomic_inc(&pci_parity_count);
39717+ atomic_inc_unchecked(&pci_parity_count);
39718 }
39719
39720 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39721@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39722 "Detected Parity Error on %s\n",
39723 pci_name(dev));
39724
39725- atomic_inc(&pci_parity_count);
39726+ atomic_inc_unchecked(&pci_parity_count);
39727 }
39728 }
39729
39730@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39731 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39732 "Signaled System Error on %s\n",
39733 pci_name(dev));
39734- atomic_inc(&pci_nonparity_count);
39735+ atomic_inc_unchecked(&pci_nonparity_count);
39736 }
39737
39738 if (status & (PCI_STATUS_PARITY)) {
39739@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39740 "Master Data Parity Error on "
39741 "%s\n", pci_name(dev));
39742
39743- atomic_inc(&pci_parity_count);
39744+ atomic_inc_unchecked(&pci_parity_count);
39745 }
39746
39747 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39748@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39749 "Detected Parity Error on %s\n",
39750 pci_name(dev));
39751
39752- atomic_inc(&pci_parity_count);
39753+ atomic_inc_unchecked(&pci_parity_count);
39754 }
39755 }
39756 }
39757@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39758 if (!check_pci_errors)
39759 return;
39760
39761- before_count = atomic_read(&pci_parity_count);
39762+ before_count = atomic_read_unchecked(&pci_parity_count);
39763
39764 /* scan all PCI devices looking for a Parity Error on devices and
39765 * bridges.
39766@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39767 /* Only if operator has selected panic on PCI Error */
39768 if (edac_pci_get_panic_on_pe()) {
39769 /* If the count is different 'after' from 'before' */
39770- if (before_count != atomic_read(&pci_parity_count))
39771+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39772 panic("EDAC: PCI Parity Error");
39773 }
39774 }
39775diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39776index 51b7e3a..aa8a3e8 100644
39777--- a/drivers/edac/mce_amd.h
39778+++ b/drivers/edac/mce_amd.h
39779@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39780 bool (*mc0_mce)(u16, u8);
39781 bool (*mc1_mce)(u16, u8);
39782 bool (*mc2_mce)(u16, u8);
39783-};
39784+} __no_const;
39785
39786 void amd_report_gart_errors(bool);
39787 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39788diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39789index 57ea7f4..af06b76 100644
39790--- a/drivers/firewire/core-card.c
39791+++ b/drivers/firewire/core-card.c
39792@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39793 const struct fw_card_driver *driver,
39794 struct device *device)
39795 {
39796- static atomic_t index = ATOMIC_INIT(-1);
39797+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39798
39799- card->index = atomic_inc_return(&index);
39800+ card->index = atomic_inc_return_unchecked(&index);
39801 card->driver = driver;
39802 card->device = device;
39803 card->current_tlabel = 0;
39804@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39805
39806 void fw_core_remove_card(struct fw_card *card)
39807 {
39808- struct fw_card_driver dummy_driver = dummy_driver_template;
39809+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39810
39811 card->driver->update_phy_reg(card, 4,
39812 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39813diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39814index 2c6d5e1..a2cca6b 100644
39815--- a/drivers/firewire/core-device.c
39816+++ b/drivers/firewire/core-device.c
39817@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39818 struct config_rom_attribute {
39819 struct device_attribute attr;
39820 u32 key;
39821-};
39822+} __do_const;
39823
39824 static ssize_t show_immediate(struct device *dev,
39825 struct device_attribute *dattr, char *buf)
39826diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39827index eb6935c..3cc2bfa 100644
39828--- a/drivers/firewire/core-transaction.c
39829+++ b/drivers/firewire/core-transaction.c
39830@@ -38,6 +38,7 @@
39831 #include <linux/timer.h>
39832 #include <linux/types.h>
39833 #include <linux/workqueue.h>
39834+#include <linux/sched.h>
39835
39836 #include <asm/byteorder.h>
39837
39838diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39839index f477308..2795f24 100644
39840--- a/drivers/firewire/core.h
39841+++ b/drivers/firewire/core.h
39842@@ -111,6 +111,7 @@ struct fw_card_driver {
39843
39844 int (*stop_iso)(struct fw_iso_context *ctx);
39845 };
39846+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39847
39848 void fw_card_initialize(struct fw_card *card,
39849 const struct fw_card_driver *driver, struct device *device);
39850diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39851index 586f2f7..3545ad2 100644
39852--- a/drivers/firewire/ohci.c
39853+++ b/drivers/firewire/ohci.c
39854@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39855 be32_to_cpu(ohci->next_header));
39856 }
39857
39858+#ifndef CONFIG_GRKERNSEC
39859 if (param_remote_dma) {
39860 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39861 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39862 }
39863+#endif
39864
39865 spin_unlock_irq(&ohci->lock);
39866
39867@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39868 unsigned long flags;
39869 int n, ret = 0;
39870
39871+#ifndef CONFIG_GRKERNSEC
39872 if (param_remote_dma)
39873 return 0;
39874+#endif
39875
39876 /*
39877 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39878diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39879index 94a58a0..f5eba42 100644
39880--- a/drivers/firmware/dmi-id.c
39881+++ b/drivers/firmware/dmi-id.c
39882@@ -16,7 +16,7 @@
39883 struct dmi_device_attribute{
39884 struct device_attribute dev_attr;
39885 int field;
39886-};
39887+} __do_const;
39888 #define to_dmi_dev_attr(_dev_attr) \
39889 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39890
39891diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39892index 17afc51..0ef90cd 100644
39893--- a/drivers/firmware/dmi_scan.c
39894+++ b/drivers/firmware/dmi_scan.c
39895@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39896 if (buf == NULL)
39897 return -1;
39898
39899- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39900+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39901
39902 dmi_unmap(buf);
39903 return 0;
39904diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39905index 1491dd4..aa910db 100644
39906--- a/drivers/firmware/efi/cper.c
39907+++ b/drivers/firmware/efi/cper.c
39908@@ -41,12 +41,12 @@
39909 */
39910 u64 cper_next_record_id(void)
39911 {
39912- static atomic64_t seq;
39913+ static atomic64_unchecked_t seq;
39914
39915- if (!atomic64_read(&seq))
39916- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39917+ if (!atomic64_read_unchecked(&seq))
39918+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39919
39920- return atomic64_inc_return(&seq);
39921+ return atomic64_inc_return_unchecked(&seq);
39922 }
39923 EXPORT_SYMBOL_GPL(cper_next_record_id);
39924
39925diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39926index af20f17..4e4e545 100644
39927--- a/drivers/firmware/efi/efi.c
39928+++ b/drivers/firmware/efi/efi.c
39929@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39930 };
39931
39932 static struct efivars generic_efivars;
39933-static struct efivar_operations generic_ops;
39934+static efivar_operations_no_const generic_ops __read_only;
39935
39936 static int generic_ops_register(void)
39937 {
39938- generic_ops.get_variable = efi.get_variable;
39939- generic_ops.set_variable = efi.set_variable;
39940- generic_ops.get_next_variable = efi.get_next_variable;
39941- generic_ops.query_variable_store = efi_query_variable_store;
39942+ pax_open_kernel();
39943+ *(void **)&generic_ops.get_variable = efi.get_variable;
39944+ *(void **)&generic_ops.set_variable = efi.set_variable;
39945+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39946+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39947+ pax_close_kernel();
39948
39949 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39950 }
39951diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39952index 50ea412..caccd6e9 100644
39953--- a/drivers/firmware/efi/efivars.c
39954+++ b/drivers/firmware/efi/efivars.c
39955@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39956 static int
39957 create_efivars_bin_attributes(void)
39958 {
39959- struct bin_attribute *attr;
39960+ bin_attribute_no_const *attr;
39961 int error;
39962
39963 /* new_var */
39964diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39965index 2f569aa..c95f4fb 100644
39966--- a/drivers/firmware/google/memconsole.c
39967+++ b/drivers/firmware/google/memconsole.c
39968@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39969 if (!found_memconsole())
39970 return -ENODEV;
39971
39972- memconsole_bin_attr.size = memconsole_length;
39973+ pax_open_kernel();
39974+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39975+ pax_close_kernel();
39976+
39977 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39978 }
39979
39980diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39981index 8765bd6..2e5b147 100644
39982--- a/drivers/gpio/gpio-em.c
39983+++ b/drivers/gpio/gpio-em.c
39984@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39985 struct em_gio_priv *p;
39986 struct resource *io[2], *irq[2];
39987 struct gpio_chip *gpio_chip;
39988- struct irq_chip *irq_chip;
39989+ irq_chip_no_const *irq_chip;
39990 const char *name = dev_name(&pdev->dev);
39991 int ret;
39992
39993diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39994index 7030422..42a3fe9 100644
39995--- a/drivers/gpio/gpio-ich.c
39996+++ b/drivers/gpio/gpio-ich.c
39997@@ -94,7 +94,7 @@ struct ichx_desc {
39998 * this option allows driver caching written output values
39999 */
40000 bool use_outlvl_cache;
40001-};
40002+} __do_const;
40003
40004 static struct {
40005 spinlock_t lock;
40006diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40007index 03c9148..c66e753 100644
40008--- a/drivers/gpio/gpio-rcar.c
40009+++ b/drivers/gpio/gpio-rcar.c
40010@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40011 struct gpio_rcar_priv *p;
40012 struct resource *io, *irq;
40013 struct gpio_chip *gpio_chip;
40014- struct irq_chip *irq_chip;
40015+ irq_chip_no_const *irq_chip;
40016 struct device *dev = &pdev->dev;
40017 const char *name = dev_name(dev);
40018 int ret;
40019diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40020index 66cbcc1..0c5e622 100644
40021--- a/drivers/gpio/gpio-vr41xx.c
40022+++ b/drivers/gpio/gpio-vr41xx.c
40023@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40024 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40025 maskl, pendl, maskh, pendh);
40026
40027- atomic_inc(&irq_err_count);
40028+ atomic_inc_unchecked(&irq_err_count);
40029
40030 return -EINVAL;
40031 }
40032diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40033index f48817d..d35d7f8 100644
40034--- a/drivers/gpio/gpiolib.c
40035+++ b/drivers/gpio/gpiolib.c
40036@@ -1458,8 +1458,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40037 }
40038
40039 if (gpiochip->irqchip) {
40040- gpiochip->irqchip->irq_request_resources = NULL;
40041- gpiochip->irqchip->irq_release_resources = NULL;
40042+ pax_open_kernel();
40043+ *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40044+ *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40045+ pax_close_kernel();
40046 gpiochip->irqchip = NULL;
40047 }
40048 }
40049@@ -1524,8 +1526,10 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40050 gpiochip->irqchip = NULL;
40051 return -EINVAL;
40052 }
40053- irqchip->irq_request_resources = gpiochip_irq_reqres;
40054- irqchip->irq_release_resources = gpiochip_irq_relres;
40055+ pax_open_kernel();
40056+ *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40057+ *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40058+ pax_close_kernel();
40059
40060 /*
40061 * Prepare the mapping since the irqchip shall be orthogonal to
40062diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40063index d8b7099..8a314a5 100644
40064--- a/drivers/gpu/drm/drm_crtc.c
40065+++ b/drivers/gpu/drm/drm_crtc.c
40066@@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40067 goto done;
40068 }
40069
40070- if (copy_to_user(&enum_ptr[copied].name,
40071+ if (copy_to_user(enum_ptr[copied].name,
40072 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40073 ret = -EFAULT;
40074 goto done;
40075diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40076old mode 100644
40077new mode 100755
40078index 8218078..9960928a
40079--- a/drivers/gpu/drm/drm_drv.c
40080+++ b/drivers/gpu/drm/drm_drv.c
40081@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40082 /**
40083 * Copy and IOCTL return string to user space
40084 */
40085-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40086+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40087 {
40088 int len;
40089
40090@@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
40091 struct drm_file *file_priv = filp->private_data;
40092 struct drm_device *dev;
40093 const struct drm_ioctl_desc *ioctl = NULL;
40094- drm_ioctl_t *func;
40095+ drm_ioctl_no_const_t func;
40096 unsigned int nr = DRM_IOCTL_NR(cmd);
40097 int retcode = -EINVAL;
40098 char stack_kdata[128];
40099diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40100index e1eba0b..98f69f9 100644
40101--- a/drivers/gpu/drm/drm_fops.c
40102+++ b/drivers/gpu/drm/drm_fops.c
40103@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40104 return PTR_ERR(minor);
40105
40106 dev = minor->dev;
40107- if (!dev->open_count++)
40108+ if (local_inc_return(&dev->open_count) == 1)
40109 need_setup = 1;
40110
40111 /* share address_space across all char-devs of a single device */
40112@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40113 return 0;
40114
40115 err_undo:
40116- dev->open_count--;
40117+ local_dec(&dev->open_count);
40118 drm_minor_release(minor);
40119 return retcode;
40120 }
40121@@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
40122
40123 mutex_lock(&drm_global_mutex);
40124
40125- DRM_DEBUG("open_count = %d\n", dev->open_count);
40126+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40127
40128 if (dev->driver->preclose)
40129 dev->driver->preclose(dev, file_priv);
40130@@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
40131 * Begin inline drm_release
40132 */
40133
40134- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40135+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40136 task_pid_nr(current),
40137 (long)old_encode_dev(file_priv->minor->kdev->devt),
40138- dev->open_count);
40139+ local_read(&dev->open_count));
40140
40141 /* Release any auth tokens that might point to this file_priv,
40142 (do that under the drm_global_mutex) */
40143@@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40144 * End inline drm_release
40145 */
40146
40147- if (!--dev->open_count) {
40148+ if (local_dec_and_test(&dev->open_count)) {
40149 retcode = drm_lastclose(dev);
40150 if (drm_device_is_unplugged(dev))
40151 drm_put_dev(dev);
40152diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40153index 3d2e91c..d31c4c9 100644
40154--- a/drivers/gpu/drm/drm_global.c
40155+++ b/drivers/gpu/drm/drm_global.c
40156@@ -36,7 +36,7 @@
40157 struct drm_global_item {
40158 struct mutex mutex;
40159 void *object;
40160- int refcount;
40161+ atomic_t refcount;
40162 };
40163
40164 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40165@@ -49,7 +49,7 @@ void drm_global_init(void)
40166 struct drm_global_item *item = &glob[i];
40167 mutex_init(&item->mutex);
40168 item->object = NULL;
40169- item->refcount = 0;
40170+ atomic_set(&item->refcount, 0);
40171 }
40172 }
40173
40174@@ -59,7 +59,7 @@ void drm_global_release(void)
40175 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40176 struct drm_global_item *item = &glob[i];
40177 BUG_ON(item->object != NULL);
40178- BUG_ON(item->refcount != 0);
40179+ BUG_ON(atomic_read(&item->refcount) != 0);
40180 }
40181 }
40182
40183@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40184 struct drm_global_item *item = &glob[ref->global_type];
40185
40186 mutex_lock(&item->mutex);
40187- if (item->refcount == 0) {
40188+ if (atomic_read(&item->refcount) == 0) {
40189 item->object = kzalloc(ref->size, GFP_KERNEL);
40190 if (unlikely(item->object == NULL)) {
40191 ret = -ENOMEM;
40192@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40193 goto out_err;
40194
40195 }
40196- ++item->refcount;
40197+ atomic_inc(&item->refcount);
40198 ref->object = item->object;
40199 mutex_unlock(&item->mutex);
40200 return 0;
40201@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40202 struct drm_global_item *item = &glob[ref->global_type];
40203
40204 mutex_lock(&item->mutex);
40205- BUG_ON(item->refcount == 0);
40206+ BUG_ON(atomic_read(&item->refcount) == 0);
40207 BUG_ON(ref->object != item->object);
40208- if (--item->refcount == 0) {
40209+ if (atomic_dec_and_test(&item->refcount)) {
40210 ref->release(ref);
40211 item->object = NULL;
40212 }
40213diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40214index 7473035..a48b9c5 100644
40215--- a/drivers/gpu/drm/drm_info.c
40216+++ b/drivers/gpu/drm/drm_info.c
40217@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40218 struct drm_local_map *map;
40219 struct drm_map_list *r_list;
40220
40221- /* Hardcoded from _DRM_FRAME_BUFFER,
40222- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40223- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40224- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40225+ static const char * const types[] = {
40226+ [_DRM_FRAME_BUFFER] = "FB",
40227+ [_DRM_REGISTERS] = "REG",
40228+ [_DRM_SHM] = "SHM",
40229+ [_DRM_AGP] = "AGP",
40230+ [_DRM_SCATTER_GATHER] = "SG",
40231+ [_DRM_CONSISTENT] = "PCI"};
40232 const char *type;
40233 int i;
40234
40235@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40236 map = r_list->map;
40237 if (!map)
40238 continue;
40239- if (map->type < 0 || map->type > 5)
40240+ if (map->type >= ARRAY_SIZE(types))
40241 type = "??";
40242 else
40243 type = types[map->type];
40244@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40245 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40246 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40247 vma->vm_flags & VM_IO ? 'i' : '-',
40248+#ifdef CONFIG_GRKERNSEC_HIDESYM
40249+ 0);
40250+#else
40251 vma->vm_pgoff);
40252+#endif
40253
40254 #if defined(__i386__)
40255 pgprot = pgprot_val(vma->vm_page_prot);
40256diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40257index 2f4c4343..dd12cd2 100644
40258--- a/drivers/gpu/drm/drm_ioc32.c
40259+++ b/drivers/gpu/drm/drm_ioc32.c
40260@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40261 request = compat_alloc_user_space(nbytes);
40262 if (!access_ok(VERIFY_WRITE, request, nbytes))
40263 return -EFAULT;
40264- list = (struct drm_buf_desc *) (request + 1);
40265+ list = (struct drm_buf_desc __user *) (request + 1);
40266
40267 if (__put_user(count, &request->count)
40268 || __put_user(list, &request->list))
40269@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40270 request = compat_alloc_user_space(nbytes);
40271 if (!access_ok(VERIFY_WRITE, request, nbytes))
40272 return -EFAULT;
40273- list = (struct drm_buf_pub *) (request + 1);
40274+ list = (struct drm_buf_pub __user *) (request + 1);
40275
40276 if (__put_user(count, &request->count)
40277 || __put_user(list, &request->list))
40278@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40279 return 0;
40280 }
40281
40282-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40283+drm_ioctl_compat_t drm_compat_ioctls[] = {
40284 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40285 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40286 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40287@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40288 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40289 {
40290 unsigned int nr = DRM_IOCTL_NR(cmd);
40291- drm_ioctl_compat_t *fn;
40292 int ret;
40293
40294 /* Assume that ioctls without an explicit compat routine will just
40295@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40296 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40297 return drm_ioctl(filp, cmd, arg);
40298
40299- fn = drm_compat_ioctls[nr];
40300-
40301- if (fn != NULL)
40302- ret = (*fn) (filp, cmd, arg);
40303+ if (drm_compat_ioctls[nr] != NULL)
40304+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40305 else
40306 ret = drm_ioctl(filp, cmd, arg);
40307
40308diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40309index 4c24c3a..c903cab 100644
40310--- a/drivers/gpu/drm/drm_stub.c
40311+++ b/drivers/gpu/drm/drm_stub.c
40312@@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40313
40314 drm_device_set_unplugged(dev);
40315
40316- if (dev->open_count == 0) {
40317+ if (local_read(&dev->open_count) == 0) {
40318 drm_put_dev(dev);
40319 }
40320 mutex_unlock(&drm_global_mutex);
40321diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40322index c22c309..ae758c3 100644
40323--- a/drivers/gpu/drm/drm_sysfs.c
40324+++ b/drivers/gpu/drm/drm_sysfs.c
40325@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40326 */
40327 int drm_sysfs_device_add(struct drm_minor *minor)
40328 {
40329- char *minor_str;
40330+ const char *minor_str;
40331 int r;
40332
40333 if (minor->type == DRM_MINOR_CONTROL)
40334diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40335index d4d16ed..8fb0b51 100644
40336--- a/drivers/gpu/drm/i810/i810_drv.h
40337+++ b/drivers/gpu/drm/i810/i810_drv.h
40338@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40339 int page_flipping;
40340
40341 wait_queue_head_t irq_queue;
40342- atomic_t irq_received;
40343- atomic_t irq_emitted;
40344+ atomic_unchecked_t irq_received;
40345+ atomic_unchecked_t irq_emitted;
40346
40347 int front_offset;
40348 } drm_i810_private_t;
40349diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40350index eedb023..25076a4 100644
40351--- a/drivers/gpu/drm/i915/i915_dma.c
40352+++ b/drivers/gpu/drm/i915/i915_dma.c
40353@@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40354 bool can_switch;
40355
40356 spin_lock(&dev->count_lock);
40357- can_switch = (dev->open_count == 0);
40358+ can_switch = (local_read(&dev->open_count) == 0);
40359 spin_unlock(&dev->count_lock);
40360 return can_switch;
40361 }
40362diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40363index 20fef6c..76c78fb 100644
40364--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40365+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40366@@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40367
40368 static int
40369 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40370- int count)
40371+ unsigned int count)
40372 {
40373- int i;
40374+ unsigned int i;
40375 unsigned relocs_total = 0;
40376 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40377
40378diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40379index 3c59584..500f2e9 100644
40380--- a/drivers/gpu/drm/i915/i915_ioc32.c
40381+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40382@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40383 (unsigned long)request);
40384 }
40385
40386-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40387+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40388 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40389 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40390 [DRM_I915_GETPARAM] = compat_i915_getparam,
40391@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40392 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40393 {
40394 unsigned int nr = DRM_IOCTL_NR(cmd);
40395- drm_ioctl_compat_t *fn = NULL;
40396 int ret;
40397
40398 if (nr < DRM_COMMAND_BASE)
40399 return drm_compat_ioctl(filp, cmd, arg);
40400
40401- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40402- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40403-
40404- if (fn != NULL)
40405+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40406+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40407 ret = (*fn) (filp, cmd, arg);
40408- else
40409+ } else
40410 ret = drm_ioctl(filp, cmd, arg);
40411
40412 return ret;
40413diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40414index c83eb75..d205e5b2 100644
40415--- a/drivers/gpu/drm/i915/intel_display.c
40416+++ b/drivers/gpu/drm/i915/intel_display.c
40417@@ -11179,13 +11179,13 @@ struct intel_quirk {
40418 int subsystem_vendor;
40419 int subsystem_device;
40420 void (*hook)(struct drm_device *dev);
40421-};
40422+} __do_const;
40423
40424 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40425 struct intel_dmi_quirk {
40426 void (*hook)(struct drm_device *dev);
40427 const struct dmi_system_id (*dmi_id_list)[];
40428-};
40429+} __do_const;
40430
40431 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40432 {
40433@@ -11193,18 +11193,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40434 return 1;
40435 }
40436
40437-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40438+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40439 {
40440- .dmi_id_list = &(const struct dmi_system_id[]) {
40441- {
40442- .callback = intel_dmi_reverse_brightness,
40443- .ident = "NCR Corporation",
40444- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40445- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40446- },
40447- },
40448- { } /* terminating entry */
40449+ .callback = intel_dmi_reverse_brightness,
40450+ .ident = "NCR Corporation",
40451+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40452+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40453 },
40454+ },
40455+ { } /* terminating entry */
40456+};
40457+
40458+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40459+ {
40460+ .dmi_id_list = &intel_dmi_quirks_table,
40461 .hook = quirk_invert_brightness,
40462 },
40463 };
40464diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40465index fe45321..836fdca 100644
40466--- a/drivers/gpu/drm/mga/mga_drv.h
40467+++ b/drivers/gpu/drm/mga/mga_drv.h
40468@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40469 u32 clear_cmd;
40470 u32 maccess;
40471
40472- atomic_t vbl_received; /**< Number of vblanks received. */
40473+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40474 wait_queue_head_t fence_queue;
40475- atomic_t last_fence_retired;
40476+ atomic_unchecked_t last_fence_retired;
40477 u32 next_fence_to_post;
40478
40479 unsigned int fb_cpp;
40480diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40481index 86b4bb8..ae237ad 100644
40482--- a/drivers/gpu/drm/mga/mga_ioc32.c
40483+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40484@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40485 return 0;
40486 }
40487
40488-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40489+drm_ioctl_compat_t mga_compat_ioctls[] = {
40490 [DRM_MGA_INIT] = compat_mga_init,
40491 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40492 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40493@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40494 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40495 {
40496 unsigned int nr = DRM_IOCTL_NR(cmd);
40497- drm_ioctl_compat_t *fn = NULL;
40498 int ret;
40499
40500 if (nr < DRM_COMMAND_BASE)
40501 return drm_compat_ioctl(filp, cmd, arg);
40502
40503- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40504- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40505-
40506- if (fn != NULL)
40507+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40508+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40509 ret = (*fn) (filp, cmd, arg);
40510- else
40511+ } else
40512 ret = drm_ioctl(filp, cmd, arg);
40513
40514 return ret;
40515diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40516index 1b071b8..de8601a 100644
40517--- a/drivers/gpu/drm/mga/mga_irq.c
40518+++ b/drivers/gpu/drm/mga/mga_irq.c
40519@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40520 if (crtc != 0)
40521 return 0;
40522
40523- return atomic_read(&dev_priv->vbl_received);
40524+ return atomic_read_unchecked(&dev_priv->vbl_received);
40525 }
40526
40527
40528@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40529 /* VBLANK interrupt */
40530 if (status & MGA_VLINEPEN) {
40531 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40532- atomic_inc(&dev_priv->vbl_received);
40533+ atomic_inc_unchecked(&dev_priv->vbl_received);
40534 drm_handle_vblank(dev, 0);
40535 handled = 1;
40536 }
40537@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40538 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40539 MGA_WRITE(MGA_PRIMEND, prim_end);
40540
40541- atomic_inc(&dev_priv->last_fence_retired);
40542+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40543 wake_up(&dev_priv->fence_queue);
40544 handled = 1;
40545 }
40546@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40547 * using fences.
40548 */
40549 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40550- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40551+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40552 - *sequence) <= (1 << 23)));
40553
40554 *sequence = cur_fence;
40555diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40556index 8268a4c..5105708 100644
40557--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40558+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40559@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40560 struct bit_table {
40561 const char id;
40562 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40563-};
40564+} __no_const;
40565
40566 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40567
40568diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40569index 7efbafa..19f8087 100644
40570--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40571+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40572@@ -97,7 +97,6 @@ struct nouveau_drm {
40573 struct drm_global_reference mem_global_ref;
40574 struct ttm_bo_global_ref bo_global_ref;
40575 struct ttm_bo_device bdev;
40576- atomic_t validate_sequence;
40577 int (*move)(struct nouveau_channel *,
40578 struct ttm_buffer_object *,
40579 struct ttm_mem_reg *, struct ttm_mem_reg *);
40580diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40581index c1a7e5a..38b8539 100644
40582--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40583+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40584@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40585 unsigned long arg)
40586 {
40587 unsigned int nr = DRM_IOCTL_NR(cmd);
40588- drm_ioctl_compat_t *fn = NULL;
40589+ drm_ioctl_compat_t fn = NULL;
40590 int ret;
40591
40592 if (nr < DRM_COMMAND_BASE)
40593diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40594index ab0228f..20b756b 100644
40595--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40596+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40597@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40598 }
40599
40600 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40601- nouveau_vram_manager_init,
40602- nouveau_vram_manager_fini,
40603- nouveau_vram_manager_new,
40604- nouveau_vram_manager_del,
40605- nouveau_vram_manager_debug
40606+ .init = nouveau_vram_manager_init,
40607+ .takedown = nouveau_vram_manager_fini,
40608+ .get_node = nouveau_vram_manager_new,
40609+ .put_node = nouveau_vram_manager_del,
40610+ .debug = nouveau_vram_manager_debug
40611 };
40612
40613 static int
40614@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40615 }
40616
40617 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40618- nouveau_gart_manager_init,
40619- nouveau_gart_manager_fini,
40620- nouveau_gart_manager_new,
40621- nouveau_gart_manager_del,
40622- nouveau_gart_manager_debug
40623+ .init = nouveau_gart_manager_init,
40624+ .takedown = nouveau_gart_manager_fini,
40625+ .get_node = nouveau_gart_manager_new,
40626+ .put_node = nouveau_gart_manager_del,
40627+ .debug = nouveau_gart_manager_debug
40628 };
40629
40630 #include <core/subdev/vm/nv04.h>
40631@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40632 }
40633
40634 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40635- nv04_gart_manager_init,
40636- nv04_gart_manager_fini,
40637- nv04_gart_manager_new,
40638- nv04_gart_manager_del,
40639- nv04_gart_manager_debug
40640+ .init = nv04_gart_manager_init,
40641+ .takedown = nv04_gart_manager_fini,
40642+ .get_node = nv04_gart_manager_new,
40643+ .put_node = nv04_gart_manager_del,
40644+ .debug = nv04_gart_manager_debug
40645 };
40646
40647 int
40648diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40649index fb84da3..d7ee463 100644
40650--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40651+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40652@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40653 bool can_switch;
40654
40655 spin_lock(&dev->count_lock);
40656- can_switch = (dev->open_count == 0);
40657+ can_switch = (local_read(&dev->open_count) == 0);
40658 spin_unlock(&dev->count_lock);
40659 return can_switch;
40660 }
40661diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40662index eb89653..613cf71 100644
40663--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40664+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40665@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40666 int ret;
40667
40668 mutex_lock(&qdev->async_io_mutex);
40669- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40670+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40671 if (qdev->last_sent_io_cmd > irq_num) {
40672 if (intr)
40673 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40674- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40675+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40676 else
40677 ret = wait_event_timeout(qdev->io_cmd_event,
40678- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40679+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40680 /* 0 is timeout, just bail the "hw" has gone away */
40681 if (ret <= 0)
40682 goto out;
40683- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40684+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40685 }
40686 outb(val, addr);
40687 qdev->last_sent_io_cmd = irq_num + 1;
40688 if (intr)
40689 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40690- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40691+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40692 else
40693 ret = wait_event_timeout(qdev->io_cmd_event,
40694- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40695+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40696 out:
40697 if (ret > 0)
40698 ret = 0;
40699diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40700index c3c2bbd..bc3c0fb 100644
40701--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40702+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40703@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40704 struct drm_info_node *node = (struct drm_info_node *) m->private;
40705 struct qxl_device *qdev = node->minor->dev->dev_private;
40706
40707- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40708- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40709- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40710- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40711+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40712+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40713+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40714+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40715 seq_printf(m, "%d\n", qdev->irq_received_error);
40716 return 0;
40717 }
40718diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40719index 36ed40b..0397633 100644
40720--- a/drivers/gpu/drm/qxl/qxl_drv.h
40721+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40722@@ -290,10 +290,10 @@ struct qxl_device {
40723 unsigned int last_sent_io_cmd;
40724
40725 /* interrupt handling */
40726- atomic_t irq_received;
40727- atomic_t irq_received_display;
40728- atomic_t irq_received_cursor;
40729- atomic_t irq_received_io_cmd;
40730+ atomic_unchecked_t irq_received;
40731+ atomic_unchecked_t irq_received_display;
40732+ atomic_unchecked_t irq_received_cursor;
40733+ atomic_unchecked_t irq_received_io_cmd;
40734 unsigned irq_received_error;
40735 wait_queue_head_t display_event;
40736 wait_queue_head_t cursor_event;
40737diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40738index 0bb86e6..d41416d 100644
40739--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40740+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40741@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40742
40743 /* TODO copy slow path code from i915 */
40744 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40745- 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);
40746+ 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);
40747
40748 {
40749 struct qxl_drawable *draw = fb_cmd;
40750@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40751 struct drm_qxl_reloc reloc;
40752
40753 if (copy_from_user(&reloc,
40754- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40755+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40756 sizeof(reloc))) {
40757 ret = -EFAULT;
40758 goto out_free_bos;
40759@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40760
40761 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40762
40763- struct drm_qxl_command *commands =
40764- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40765+ struct drm_qxl_command __user *commands =
40766+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40767
40768- if (copy_from_user(&user_cmd, &commands[cmd_num],
40769+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40770 sizeof(user_cmd)))
40771 return -EFAULT;
40772
40773diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40774index 3485bdc..20d26e3 100644
40775--- a/drivers/gpu/drm/qxl/qxl_irq.c
40776+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40777@@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40778 if (!pending)
40779 return IRQ_NONE;
40780
40781- atomic_inc(&qdev->irq_received);
40782+ atomic_inc_unchecked(&qdev->irq_received);
40783
40784 if (pending & QXL_INTERRUPT_DISPLAY) {
40785- atomic_inc(&qdev->irq_received_display);
40786+ atomic_inc_unchecked(&qdev->irq_received_display);
40787 wake_up_all(&qdev->display_event);
40788 qxl_queue_garbage_collect(qdev, false);
40789 }
40790 if (pending & QXL_INTERRUPT_CURSOR) {
40791- atomic_inc(&qdev->irq_received_cursor);
40792+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40793 wake_up_all(&qdev->cursor_event);
40794 }
40795 if (pending & QXL_INTERRUPT_IO_CMD) {
40796- atomic_inc(&qdev->irq_received_io_cmd);
40797+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40798 wake_up_all(&qdev->io_cmd_event);
40799 }
40800 if (pending & QXL_INTERRUPT_ERROR) {
40801@@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40802 init_waitqueue_head(&qdev->io_cmd_event);
40803 INIT_WORK(&qdev->client_monitors_config_work,
40804 qxl_client_monitors_config_work_func);
40805- atomic_set(&qdev->irq_received, 0);
40806- atomic_set(&qdev->irq_received_display, 0);
40807- atomic_set(&qdev->irq_received_cursor, 0);
40808- atomic_set(&qdev->irq_received_io_cmd, 0);
40809+ atomic_set_unchecked(&qdev->irq_received, 0);
40810+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40811+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40812+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40813 qdev->irq_received_error = 0;
40814 ret = drm_irq_install(qdev->ddev);
40815 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40816diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40817index d52c275..4e6b43d 100644
40818--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40819+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40820@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40821 }
40822 }
40823
40824-static struct vm_operations_struct qxl_ttm_vm_ops;
40825+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40826 static const struct vm_operations_struct *ttm_vm_ops;
40827
40828 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40829@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40830 return r;
40831 if (unlikely(ttm_vm_ops == NULL)) {
40832 ttm_vm_ops = vma->vm_ops;
40833+ pax_open_kernel();
40834 qxl_ttm_vm_ops = *ttm_vm_ops;
40835 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40836+ pax_close_kernel();
40837 }
40838 vma->vm_ops = &qxl_ttm_vm_ops;
40839 return 0;
40840@@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40841 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40842 {
40843 #if defined(CONFIG_DEBUG_FS)
40844- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40845- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40846- unsigned i;
40847+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40848+ {
40849+ .name = "qxl_mem_mm",
40850+ .show = &qxl_mm_dump_table,
40851+ },
40852+ {
40853+ .name = "qxl_surf_mm",
40854+ .show = &qxl_mm_dump_table,
40855+ }
40856+ };
40857
40858- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40859- if (i == 0)
40860- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40861- else
40862- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40863- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40864- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40865- qxl_mem_types_list[i].driver_features = 0;
40866- if (i == 0)
40867- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40868- else
40869- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40870+ pax_open_kernel();
40871+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40872+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40873+ pax_close_kernel();
40874
40875- }
40876- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40877+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40878 #else
40879 return 0;
40880 #endif
40881diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40882index 59459fe..be26b31 100644
40883--- a/drivers/gpu/drm/r128/r128_cce.c
40884+++ b/drivers/gpu/drm/r128/r128_cce.c
40885@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40886
40887 /* GH: Simple idle check.
40888 */
40889- atomic_set(&dev_priv->idle_count, 0);
40890+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40891
40892 /* We don't support anything other than bus-mastering ring mode,
40893 * but the ring can be in either AGP or PCI space for the ring
40894diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40895index 5bf3f5f..7000661 100644
40896--- a/drivers/gpu/drm/r128/r128_drv.h
40897+++ b/drivers/gpu/drm/r128/r128_drv.h
40898@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40899 int is_pci;
40900 unsigned long cce_buffers_offset;
40901
40902- atomic_t idle_count;
40903+ atomic_unchecked_t idle_count;
40904
40905 int page_flipping;
40906 int current_page;
40907 u32 crtc_offset;
40908 u32 crtc_offset_cntl;
40909
40910- atomic_t vbl_received;
40911+ atomic_unchecked_t vbl_received;
40912
40913 u32 color_fmt;
40914 unsigned int front_offset;
40915diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40916index b0d0fd3..a6fbbe4 100644
40917--- a/drivers/gpu/drm/r128/r128_ioc32.c
40918+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40919@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40920 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40921 }
40922
40923-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40924+drm_ioctl_compat_t r128_compat_ioctls[] = {
40925 [DRM_R128_INIT] = compat_r128_init,
40926 [DRM_R128_DEPTH] = compat_r128_depth,
40927 [DRM_R128_STIPPLE] = compat_r128_stipple,
40928@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40929 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40930 {
40931 unsigned int nr = DRM_IOCTL_NR(cmd);
40932- drm_ioctl_compat_t *fn = NULL;
40933 int ret;
40934
40935 if (nr < DRM_COMMAND_BASE)
40936 return drm_compat_ioctl(filp, cmd, arg);
40937
40938- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40939- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40940-
40941- if (fn != NULL)
40942+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40943+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40944 ret = (*fn) (filp, cmd, arg);
40945- else
40946+ } else
40947 ret = drm_ioctl(filp, cmd, arg);
40948
40949 return ret;
40950diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40951index c2ae496..30b5993 100644
40952--- a/drivers/gpu/drm/r128/r128_irq.c
40953+++ b/drivers/gpu/drm/r128/r128_irq.c
40954@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40955 if (crtc != 0)
40956 return 0;
40957
40958- return atomic_read(&dev_priv->vbl_received);
40959+ return atomic_read_unchecked(&dev_priv->vbl_received);
40960 }
40961
40962 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40963@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40964 /* VBLANK interrupt */
40965 if (status & R128_CRTC_VBLANK_INT) {
40966 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40967- atomic_inc(&dev_priv->vbl_received);
40968+ atomic_inc_unchecked(&dev_priv->vbl_received);
40969 drm_handle_vblank(dev, 0);
40970 return IRQ_HANDLED;
40971 }
40972diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40973index e806dac..f81d32f 100644
40974--- a/drivers/gpu/drm/r128/r128_state.c
40975+++ b/drivers/gpu/drm/r128/r128_state.c
40976@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40977
40978 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40979 {
40980- if (atomic_read(&dev_priv->idle_count) == 0)
40981+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40982 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40983 else
40984- atomic_set(&dev_priv->idle_count, 0);
40985+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40986 }
40987
40988 #endif
40989diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40990index 4a85bb6..aaea819 100644
40991--- a/drivers/gpu/drm/radeon/mkregtable.c
40992+++ b/drivers/gpu/drm/radeon/mkregtable.c
40993@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40994 regex_t mask_rex;
40995 regmatch_t match[4];
40996 char buf[1024];
40997- size_t end;
40998+ long end;
40999 int len;
41000 int done = 0;
41001 int r;
41002 unsigned o;
41003 struct offset *offset;
41004 char last_reg_s[10];
41005- int last_reg;
41006+ unsigned long last_reg;
41007
41008 if (regcomp
41009 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41010diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41011index 2cd144c..a01c95a 100644
41012--- a/drivers/gpu/drm/radeon/radeon_device.c
41013+++ b/drivers/gpu/drm/radeon/radeon_device.c
41014@@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41015 bool can_switch;
41016
41017 spin_lock(&dev->count_lock);
41018- can_switch = (dev->open_count == 0);
41019+ can_switch = (local_read(&dev->open_count) == 0);
41020 spin_unlock(&dev->count_lock);
41021 return can_switch;
41022 }
41023diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41024index dafd812..1bf20c7 100644
41025--- a/drivers/gpu/drm/radeon/radeon_drv.h
41026+++ b/drivers/gpu/drm/radeon/radeon_drv.h
41027@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
41028
41029 /* SW interrupt */
41030 wait_queue_head_t swi_queue;
41031- atomic_t swi_emitted;
41032+ atomic_unchecked_t swi_emitted;
41033 int vblank_crtc;
41034 uint32_t irq_enable_reg;
41035 uint32_t r500_disp_irq_reg;
41036diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41037index bdb0f93..5ff558f 100644
41038--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41039+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41040@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41041 request = compat_alloc_user_space(sizeof(*request));
41042 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41043 || __put_user(req32.param, &request->param)
41044- || __put_user((void __user *)(unsigned long)req32.value,
41045+ || __put_user((unsigned long)req32.value,
41046 &request->value))
41047 return -EFAULT;
41048
41049@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41050 #define compat_radeon_cp_setparam NULL
41051 #endif /* X86_64 || IA64 */
41052
41053-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41054+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41055 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41056 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41057 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41058@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41059 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41060 {
41061 unsigned int nr = DRM_IOCTL_NR(cmd);
41062- drm_ioctl_compat_t *fn = NULL;
41063 int ret;
41064
41065 if (nr < DRM_COMMAND_BASE)
41066 return drm_compat_ioctl(filp, cmd, arg);
41067
41068- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41069- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41070-
41071- if (fn != NULL)
41072+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41073+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41074 ret = (*fn) (filp, cmd, arg);
41075- else
41076+ } else
41077 ret = drm_ioctl(filp, cmd, arg);
41078
41079 return ret;
41080diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41081index 244b19b..c19226d 100644
41082--- a/drivers/gpu/drm/radeon/radeon_irq.c
41083+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41084@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41085 unsigned int ret;
41086 RING_LOCALS;
41087
41088- atomic_inc(&dev_priv->swi_emitted);
41089- ret = atomic_read(&dev_priv->swi_emitted);
41090+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41091+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41092
41093 BEGIN_RING(4);
41094 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41095@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41096 drm_radeon_private_t *dev_priv =
41097 (drm_radeon_private_t *) dev->dev_private;
41098
41099- atomic_set(&dev_priv->swi_emitted, 0);
41100+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41101 init_waitqueue_head(&dev_priv->swi_queue);
41102
41103 dev->max_vblank_count = 0x001fffff;
41104diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41105index 956ab7f..fbd36d8 100644
41106--- a/drivers/gpu/drm/radeon/radeon_state.c
41107+++ b/drivers/gpu/drm/radeon/radeon_state.c
41108@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41109 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41110 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41111
41112- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41113+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41114 sarea_priv->nbox * sizeof(depth_boxes[0])))
41115 return -EFAULT;
41116
41117@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41118 {
41119 drm_radeon_private_t *dev_priv = dev->dev_private;
41120 drm_radeon_getparam_t *param = data;
41121- int value;
41122+ int value = 0;
41123
41124 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41125
41126diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41127index c8a8a51..219dacc 100644
41128--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41129+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41130@@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41131 man->size = size >> PAGE_SHIFT;
41132 }
41133
41134-static struct vm_operations_struct radeon_ttm_vm_ops;
41135+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41136 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41137
41138 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41139@@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41140 }
41141 if (unlikely(ttm_vm_ops == NULL)) {
41142 ttm_vm_ops = vma->vm_ops;
41143+ pax_open_kernel();
41144 radeon_ttm_vm_ops = *ttm_vm_ops;
41145 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41146+ pax_close_kernel();
41147 }
41148 vma->vm_ops = &radeon_ttm_vm_ops;
41149 return 0;
41150diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41151index edb871d..a275c6ed 100644
41152--- a/drivers/gpu/drm/tegra/dc.c
41153+++ b/drivers/gpu/drm/tegra/dc.c
41154@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41155 }
41156
41157 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41158- dc->debugfs_files[i].data = dc;
41159+ *(void **)&dc->debugfs_files[i].data = dc;
41160
41161 err = drm_debugfs_create_files(dc->debugfs_files,
41162 ARRAY_SIZE(debugfs_files),
41163diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41164index 0e599f0..c9ea7c7 100644
41165--- a/drivers/gpu/drm/tegra/dsi.c
41166+++ b/drivers/gpu/drm/tegra/dsi.c
41167@@ -39,7 +39,7 @@ struct tegra_dsi {
41168 struct clk *clk_lp;
41169 struct clk *clk;
41170
41171- struct drm_info_list *debugfs_files;
41172+ drm_info_list_no_const *debugfs_files;
41173 struct drm_minor *minor;
41174 struct dentry *debugfs;
41175
41176diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41177index 6928015..c9853e7 100644
41178--- a/drivers/gpu/drm/tegra/hdmi.c
41179+++ b/drivers/gpu/drm/tegra/hdmi.c
41180@@ -59,7 +59,7 @@ struct tegra_hdmi {
41181 bool stereo;
41182 bool dvi;
41183
41184- struct drm_info_list *debugfs_files;
41185+ drm_info_list_no_const *debugfs_files;
41186 struct drm_minor *minor;
41187 struct dentry *debugfs;
41188 };
41189diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41190index bd850c9..d9f3573 100644
41191--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41192+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41193@@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41194 }
41195
41196 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41197- ttm_bo_man_init,
41198- ttm_bo_man_takedown,
41199- ttm_bo_man_get_node,
41200- ttm_bo_man_put_node,
41201- ttm_bo_man_debug
41202+ .init = ttm_bo_man_init,
41203+ .takedown = ttm_bo_man_takedown,
41204+ .get_node = ttm_bo_man_get_node,
41205+ .put_node = ttm_bo_man_put_node,
41206+ .debug = ttm_bo_man_debug
41207 };
41208 EXPORT_SYMBOL(ttm_bo_manager_func);
41209diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41210index dbc2def..0a9f710 100644
41211--- a/drivers/gpu/drm/ttm/ttm_memory.c
41212+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41213@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41214 zone->glob = glob;
41215 glob->zone_kernel = zone;
41216 ret = kobject_init_and_add(
41217- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41218+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41219 if (unlikely(ret != 0)) {
41220 kobject_put(&zone->kobj);
41221 return ret;
41222@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41223 zone->glob = glob;
41224 glob->zone_dma32 = zone;
41225 ret = kobject_init_and_add(
41226- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41227+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41228 if (unlikely(ret != 0)) {
41229 kobject_put(&zone->kobj);
41230 return ret;
41231diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41232index 863bef9..cba15cf 100644
41233--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41234+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41235@@ -391,9 +391,9 @@ out:
41236 static unsigned long
41237 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41238 {
41239- static atomic_t start_pool = ATOMIC_INIT(0);
41240+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41241 unsigned i;
41242- unsigned pool_offset = atomic_add_return(1, &start_pool);
41243+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41244 struct ttm_page_pool *pool;
41245 int shrink_pages = sc->nr_to_scan;
41246 unsigned long freed = 0;
41247diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41248index 3771763..883f206 100644
41249--- a/drivers/gpu/drm/udl/udl_fb.c
41250+++ b/drivers/gpu/drm/udl/udl_fb.c
41251@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41252 fb_deferred_io_cleanup(info);
41253 kfree(info->fbdefio);
41254 info->fbdefio = NULL;
41255- info->fbops->fb_mmap = udl_fb_mmap;
41256 }
41257
41258 pr_warn("released /dev/fb%d user=%d count=%d\n",
41259diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41260index ad02732..144f5ed 100644
41261--- a/drivers/gpu/drm/via/via_drv.h
41262+++ b/drivers/gpu/drm/via/via_drv.h
41263@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41264 typedef uint32_t maskarray_t[5];
41265
41266 typedef struct drm_via_irq {
41267- atomic_t irq_received;
41268+ atomic_unchecked_t irq_received;
41269 uint32_t pending_mask;
41270 uint32_t enable_mask;
41271 wait_queue_head_t irq_queue;
41272@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41273 struct timeval last_vblank;
41274 int last_vblank_valid;
41275 unsigned usec_per_vblank;
41276- atomic_t vbl_received;
41277+ atomic_unchecked_t vbl_received;
41278 drm_via_state_t hc_state;
41279 char pci_buf[VIA_PCI_BUF_SIZE];
41280 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41281diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41282index 1319433..a993b0c 100644
41283--- a/drivers/gpu/drm/via/via_irq.c
41284+++ b/drivers/gpu/drm/via/via_irq.c
41285@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41286 if (crtc != 0)
41287 return 0;
41288
41289- return atomic_read(&dev_priv->vbl_received);
41290+ return atomic_read_unchecked(&dev_priv->vbl_received);
41291 }
41292
41293 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41294@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41295
41296 status = VIA_READ(VIA_REG_INTERRUPT);
41297 if (status & VIA_IRQ_VBLANK_PENDING) {
41298- atomic_inc(&dev_priv->vbl_received);
41299- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41300+ atomic_inc_unchecked(&dev_priv->vbl_received);
41301+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41302 do_gettimeofday(&cur_vblank);
41303 if (dev_priv->last_vblank_valid) {
41304 dev_priv->usec_per_vblank =
41305@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41306 dev_priv->last_vblank = cur_vblank;
41307 dev_priv->last_vblank_valid = 1;
41308 }
41309- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41310+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41311 DRM_DEBUG("US per vblank is: %u\n",
41312 dev_priv->usec_per_vblank);
41313 }
41314@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41315
41316 for (i = 0; i < dev_priv->num_irqs; ++i) {
41317 if (status & cur_irq->pending_mask) {
41318- atomic_inc(&cur_irq->irq_received);
41319+ atomic_inc_unchecked(&cur_irq->irq_received);
41320 wake_up(&cur_irq->irq_queue);
41321 handled = 1;
41322 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41323@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41324 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41325 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41326 masks[irq][4]));
41327- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41328+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41329 } else {
41330 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41331 (((cur_irq_sequence =
41332- atomic_read(&cur_irq->irq_received)) -
41333+ atomic_read_unchecked(&cur_irq->irq_received)) -
41334 *sequence) <= (1 << 23)));
41335 }
41336 *sequence = cur_irq_sequence;
41337@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41338 }
41339
41340 for (i = 0; i < dev_priv->num_irqs; ++i) {
41341- atomic_set(&cur_irq->irq_received, 0);
41342+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41343 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41344 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41345 init_waitqueue_head(&cur_irq->irq_queue);
41346@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41347 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41348 case VIA_IRQ_RELATIVE:
41349 irqwait->request.sequence +=
41350- atomic_read(&cur_irq->irq_received);
41351+ atomic_read_unchecked(&cur_irq->irq_received);
41352 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41353 case VIA_IRQ_ABSOLUTE:
41354 break;
41355diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41356index 6b252a8..5975dfe 100644
41357--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41358+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41359@@ -437,7 +437,7 @@ struct vmw_private {
41360 * Fencing and IRQs.
41361 */
41362
41363- atomic_t marker_seq;
41364+ atomic_unchecked_t marker_seq;
41365 wait_queue_head_t fence_queue;
41366 wait_queue_head_t fifo_queue;
41367 int fence_queue_waiters; /* Protected by hw_mutex */
41368diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41369index 6ccd993..618d592 100644
41370--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41371+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41372@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41373 (unsigned int) min,
41374 (unsigned int) fifo->capabilities);
41375
41376- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41377+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41378 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41379 vmw_marker_queue_init(&fifo->marker_queue);
41380 return vmw_fifo_send_fence(dev_priv, &dummy);
41381@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41382 if (reserveable)
41383 iowrite32(bytes, fifo_mem +
41384 SVGA_FIFO_RESERVED);
41385- return fifo_mem + (next_cmd >> 2);
41386+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41387 } else {
41388 need_bounce = true;
41389 }
41390@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41391
41392 fm = vmw_fifo_reserve(dev_priv, bytes);
41393 if (unlikely(fm == NULL)) {
41394- *seqno = atomic_read(&dev_priv->marker_seq);
41395+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41396 ret = -ENOMEM;
41397 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41398 false, 3*HZ);
41399@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41400 }
41401
41402 do {
41403- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41404+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41405 } while (*seqno == 0);
41406
41407 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41408diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41409index b1273e8..9c274fd 100644
41410--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41411+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41412@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41413 }
41414
41415 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41416- vmw_gmrid_man_init,
41417- vmw_gmrid_man_takedown,
41418- vmw_gmrid_man_get_node,
41419- vmw_gmrid_man_put_node,
41420- vmw_gmrid_man_debug
41421+ .init = vmw_gmrid_man_init,
41422+ .takedown = vmw_gmrid_man_takedown,
41423+ .get_node = vmw_gmrid_man_get_node,
41424+ .put_node = vmw_gmrid_man_put_node,
41425+ .debug = vmw_gmrid_man_debug
41426 };
41427diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41428index 37881ec..319065d 100644
41429--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41430+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41431@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41432 int ret;
41433
41434 num_clips = arg->num_clips;
41435- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41436+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41437
41438 if (unlikely(num_clips == 0))
41439 return 0;
41440@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41441 int ret;
41442
41443 num_clips = arg->num_clips;
41444- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41445+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41446
41447 if (unlikely(num_clips == 0))
41448 return 0;
41449diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41450index 0c42376..6febe77 100644
41451--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41452+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41453@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41454 * emitted. Then the fence is stale and signaled.
41455 */
41456
41457- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41458+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41459 > VMW_FENCE_WRAP);
41460
41461 return ret;
41462@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41463
41464 if (fifo_idle)
41465 down_read(&fifo_state->rwsem);
41466- signal_seq = atomic_read(&dev_priv->marker_seq);
41467+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41468 ret = 0;
41469
41470 for (;;) {
41471diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41472index 8a8725c2..afed796 100644
41473--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41474+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41475@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41476 while (!vmw_lag_lt(queue, us)) {
41477 spin_lock(&queue->lock);
41478 if (list_empty(&queue->head))
41479- seqno = atomic_read(&dev_priv->marker_seq);
41480+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41481 else {
41482 marker = list_first_entry(&queue->head,
41483 struct vmw_marker, head);
41484diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41485index 6866448..2ad2b34 100644
41486--- a/drivers/gpu/vga/vga_switcheroo.c
41487+++ b/drivers/gpu/vga/vga_switcheroo.c
41488@@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41489
41490 /* this version is for the case where the power switch is separate
41491 to the device being powered down. */
41492-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41493+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41494 {
41495 /* copy over all the bus versions */
41496 if (dev->bus && dev->bus->pm) {
41497@@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41498 return ret;
41499 }
41500
41501-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41502+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41503 {
41504 /* copy over all the bus versions */
41505 if (dev->bus && dev->bus->pm) {
41506diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41507index a5c7927..025a2b4 100644
41508--- a/drivers/hid/hid-core.c
41509+++ b/drivers/hid/hid-core.c
41510@@ -2476,7 +2476,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41511
41512 int hid_add_device(struct hid_device *hdev)
41513 {
41514- static atomic_t id = ATOMIC_INIT(0);
41515+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41516 int ret;
41517
41518 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41519@@ -2518,7 +2518,7 @@ int hid_add_device(struct hid_device *hdev)
41520 /* XXX hack, any other cleaner solution after the driver core
41521 * is converted to allow more than 20 bytes as the device name? */
41522 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41523- hdev->vendor, hdev->product, atomic_inc_return(&id));
41524+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41525
41526 hid_debug_register(hdev, dev_name(&hdev->dev));
41527 ret = device_add(&hdev->dev);
41528diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41529index c13fb5b..55a3802 100644
41530--- a/drivers/hid/hid-wiimote-debug.c
41531+++ b/drivers/hid/hid-wiimote-debug.c
41532@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41533 else if (size == 0)
41534 return -EIO;
41535
41536- if (copy_to_user(u, buf, size))
41537+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41538 return -EFAULT;
41539
41540 *off += size;
41541diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41542index 0d078c3..cd0962c 100644
41543--- a/drivers/hid/uhid.c
41544+++ b/drivers/hid/uhid.c
41545@@ -47,7 +47,7 @@ struct uhid_device {
41546 struct mutex report_lock;
41547 wait_queue_head_t report_wait;
41548 atomic_t report_done;
41549- atomic_t report_id;
41550+ atomic_unchecked_t report_id;
41551 struct uhid_event report_buf;
41552 };
41553
41554@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41555
41556 spin_lock_irqsave(&uhid->qlock, flags);
41557 ev->type = UHID_FEATURE;
41558- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41559+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41560 ev->u.feature.rnum = rnum;
41561 ev->u.feature.rtype = report_type;
41562
41563@@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41564 spin_lock_irqsave(&uhid->qlock, flags);
41565
41566 /* id for old report; drop it silently */
41567- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41568+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41569 goto unlock;
41570 if (atomic_read(&uhid->report_done))
41571 goto unlock;
41572diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41573index 602ca86..10a6573 100644
41574--- a/drivers/hv/channel.c
41575+++ b/drivers/hv/channel.c
41576@@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41577 int ret = 0;
41578 int t;
41579
41580- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41581- atomic_inc(&vmbus_connection.next_gpadl_handle);
41582+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41583+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41584
41585 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41586 if (ret)
41587diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41588index bcb4950..61dba6c 100644
41589--- a/drivers/hv/hv.c
41590+++ b/drivers/hv/hv.c
41591@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41592 u64 output_address = (output) ? virt_to_phys(output) : 0;
41593 u32 output_address_hi = output_address >> 32;
41594 u32 output_address_lo = output_address & 0xFFFFFFFF;
41595- void *hypercall_page = hv_context.hypercall_page;
41596+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41597
41598 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41599 "=a"(hv_status_lo) : "d" (control_hi),
41600@@ -154,7 +154,7 @@ int hv_init(void)
41601 /* See if the hypercall page is already set */
41602 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41603
41604- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41605+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41606
41607 if (!virtaddr)
41608 goto cleanup;
41609diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41610index 5e90c5d..d8fcefb 100644
41611--- a/drivers/hv/hv_balloon.c
41612+++ b/drivers/hv/hv_balloon.c
41613@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41614
41615 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41616 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41617-static atomic_t trans_id = ATOMIC_INIT(0);
41618+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41619
41620 static int dm_ring_size = (5 * PAGE_SIZE);
41621
41622@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41623 pr_info("Memory hot add failed\n");
41624
41625 dm->state = DM_INITIALIZED;
41626- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41627+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41628 vmbus_sendpacket(dm->dev->channel, &resp,
41629 sizeof(struct dm_hot_add_response),
41630 (unsigned long)NULL,
41631@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41632 memset(&status, 0, sizeof(struct dm_status));
41633 status.hdr.type = DM_STATUS_REPORT;
41634 status.hdr.size = sizeof(struct dm_status);
41635- status.hdr.trans_id = atomic_inc_return(&trans_id);
41636+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41637
41638 /*
41639 * The host expects the guest to report free memory.
41640@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41641 * send the status. This can happen if we were interrupted
41642 * after we picked our transaction ID.
41643 */
41644- if (status.hdr.trans_id != atomic_read(&trans_id))
41645+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41646 return;
41647
41648 /*
41649@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41650 */
41651
41652 do {
41653- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41654+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41655 ret = vmbus_sendpacket(dm_device.dev->channel,
41656 bl_resp,
41657 bl_resp->hdr.size,
41658@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41659
41660 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41661 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41662- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41663+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41664 resp.hdr.size = sizeof(struct dm_unballoon_response);
41665
41666 vmbus_sendpacket(dm_device.dev->channel, &resp,
41667@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41668 memset(&version_req, 0, sizeof(struct dm_version_request));
41669 version_req.hdr.type = DM_VERSION_REQUEST;
41670 version_req.hdr.size = sizeof(struct dm_version_request);
41671- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41672+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41673 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41674 version_req.is_last_attempt = 1;
41675
41676@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41677 memset(&version_req, 0, sizeof(struct dm_version_request));
41678 version_req.hdr.type = DM_VERSION_REQUEST;
41679 version_req.hdr.size = sizeof(struct dm_version_request);
41680- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41681+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41682 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41683 version_req.is_last_attempt = 0;
41684
41685@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41686 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41687 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41688 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41689- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41690+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41691
41692 cap_msg.caps.cap_bits.balloon = 1;
41693 cap_msg.caps.cap_bits.hot_add = 1;
41694diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41695index 860134d..ea3a79a 100644
41696--- a/drivers/hv/hyperv_vmbus.h
41697+++ b/drivers/hv/hyperv_vmbus.h
41698@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41699 struct vmbus_connection {
41700 enum vmbus_connect_state conn_state;
41701
41702- atomic_t next_gpadl_handle;
41703+ atomic_unchecked_t next_gpadl_handle;
41704
41705 /*
41706 * Represents channel interrupts. Each bit position represents a
41707diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41708index 8e53a3c..7a64e44 100644
41709--- a/drivers/hv/vmbus_drv.c
41710+++ b/drivers/hv/vmbus_drv.c
41711@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41712 {
41713 int ret = 0;
41714
41715- static atomic_t device_num = ATOMIC_INIT(0);
41716+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41717
41718 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41719- atomic_inc_return(&device_num));
41720+ atomic_inc_return_unchecked(&device_num));
41721
41722 child_device_obj->device.bus = &hv_bus;
41723 child_device_obj->device.parent = &hv_acpi_dev->dev;
41724diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41725index 579bdf9..75118b5 100644
41726--- a/drivers/hwmon/acpi_power_meter.c
41727+++ b/drivers/hwmon/acpi_power_meter.c
41728@@ -116,7 +116,7 @@ struct sensor_template {
41729 struct device_attribute *devattr,
41730 const char *buf, size_t count);
41731 int index;
41732-};
41733+} __do_const;
41734
41735 /* Averaging interval */
41736 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41737@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41738 struct sensor_template *attrs)
41739 {
41740 struct device *dev = &resource->acpi_dev->dev;
41741- struct sensor_device_attribute *sensors =
41742+ sensor_device_attribute_no_const *sensors =
41743 &resource->sensors[resource->num_sensors];
41744 int res = 0;
41745
41746diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41747index 3288f13..71cfb4e 100644
41748--- a/drivers/hwmon/applesmc.c
41749+++ b/drivers/hwmon/applesmc.c
41750@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41751 {
41752 struct applesmc_node_group *grp;
41753 struct applesmc_dev_attr *node;
41754- struct attribute *attr;
41755+ attribute_no_const *attr;
41756 int ret, i;
41757
41758 for (grp = groups; grp->format; grp++) {
41759diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41760index ae208f6..48b6c5b 100644
41761--- a/drivers/hwmon/asus_atk0110.c
41762+++ b/drivers/hwmon/asus_atk0110.c
41763@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41764 struct atk_sensor_data {
41765 struct list_head list;
41766 struct atk_data *data;
41767- struct device_attribute label_attr;
41768- struct device_attribute input_attr;
41769- struct device_attribute limit1_attr;
41770- struct device_attribute limit2_attr;
41771+ device_attribute_no_const label_attr;
41772+ device_attribute_no_const input_attr;
41773+ device_attribute_no_const limit1_attr;
41774+ device_attribute_no_const limit2_attr;
41775 char label_attr_name[ATTR_NAME_SIZE];
41776 char input_attr_name[ATTR_NAME_SIZE];
41777 char limit1_attr_name[ATTR_NAME_SIZE];
41778@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41779 static struct device_attribute atk_name_attr =
41780 __ATTR(name, 0444, atk_name_show, NULL);
41781
41782-static void atk_init_attribute(struct device_attribute *attr, char *name,
41783+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41784 sysfs_show_func show)
41785 {
41786 sysfs_attr_init(&attr->attr);
41787diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41788index d76f0b7..55ae976 100644
41789--- a/drivers/hwmon/coretemp.c
41790+++ b/drivers/hwmon/coretemp.c
41791@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41792 return NOTIFY_OK;
41793 }
41794
41795-static struct notifier_block coretemp_cpu_notifier __refdata = {
41796+static struct notifier_block coretemp_cpu_notifier = {
41797 .notifier_call = coretemp_cpu_callback,
41798 };
41799
41800diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41801index 632f1dc..57e6a58 100644
41802--- a/drivers/hwmon/ibmaem.c
41803+++ b/drivers/hwmon/ibmaem.c
41804@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41805 struct aem_rw_sensor_template *rw)
41806 {
41807 struct device *dev = &data->pdev->dev;
41808- struct sensor_device_attribute *sensors = data->sensors;
41809+ sensor_device_attribute_no_const *sensors = data->sensors;
41810 int err;
41811
41812 /* Set up read-only sensors */
41813diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41814index 9fbb1b1..efbaa3e 100644
41815--- a/drivers/hwmon/iio_hwmon.c
41816+++ b/drivers/hwmon/iio_hwmon.c
41817@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41818 {
41819 struct device *dev = &pdev->dev;
41820 struct iio_hwmon_state *st;
41821- struct sensor_device_attribute *a;
41822+ sensor_device_attribute_no_const *a;
41823 int ret, i;
41824 int in_i = 1, temp_i = 1, curr_i = 1;
41825 enum iio_chan_type type;
41826diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41827index 38d5a63..cf2c2ea 100644
41828--- a/drivers/hwmon/nct6775.c
41829+++ b/drivers/hwmon/nct6775.c
41830@@ -944,10 +944,10 @@ static struct attribute_group *
41831 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41832 int repeat)
41833 {
41834- struct attribute_group *group;
41835+ attribute_group_no_const *group;
41836 struct sensor_device_attr_u *su;
41837- struct sensor_device_attribute *a;
41838- struct sensor_device_attribute_2 *a2;
41839+ sensor_device_attribute_no_const *a;
41840+ sensor_device_attribute_2_no_const *a2;
41841 struct attribute **attrs;
41842 struct sensor_device_template **t;
41843 int i, count;
41844diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41845index 291d11f..3f0dbbd 100644
41846--- a/drivers/hwmon/pmbus/pmbus_core.c
41847+++ b/drivers/hwmon/pmbus/pmbus_core.c
41848@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41849 return 0;
41850 }
41851
41852-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41853+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41854 const char *name,
41855 umode_t mode,
41856 ssize_t (*show)(struct device *dev,
41857@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41858 dev_attr->store = store;
41859 }
41860
41861-static void pmbus_attr_init(struct sensor_device_attribute *a,
41862+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41863 const char *name,
41864 umode_t mode,
41865 ssize_t (*show)(struct device *dev,
41866@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41867 u16 reg, u8 mask)
41868 {
41869 struct pmbus_boolean *boolean;
41870- struct sensor_device_attribute *a;
41871+ sensor_device_attribute_no_const *a;
41872
41873 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41874 if (!boolean)
41875@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41876 bool update, bool readonly)
41877 {
41878 struct pmbus_sensor *sensor;
41879- struct device_attribute *a;
41880+ device_attribute_no_const *a;
41881
41882 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41883 if (!sensor)
41884@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41885 const char *lstring, int index)
41886 {
41887 struct pmbus_label *label;
41888- struct device_attribute *a;
41889+ device_attribute_no_const *a;
41890
41891 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41892 if (!label)
41893diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41894index 97cd45a..ac54d8b 100644
41895--- a/drivers/hwmon/sht15.c
41896+++ b/drivers/hwmon/sht15.c
41897@@ -169,7 +169,7 @@ struct sht15_data {
41898 int supply_uv;
41899 bool supply_uv_valid;
41900 struct work_struct update_supply_work;
41901- atomic_t interrupt_handled;
41902+ atomic_unchecked_t interrupt_handled;
41903 };
41904
41905 /**
41906@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41907 ret = gpio_direction_input(data->pdata->gpio_data);
41908 if (ret)
41909 return ret;
41910- atomic_set(&data->interrupt_handled, 0);
41911+ atomic_set_unchecked(&data->interrupt_handled, 0);
41912
41913 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41914 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41915 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41916 /* Only relevant if the interrupt hasn't occurred. */
41917- if (!atomic_read(&data->interrupt_handled))
41918+ if (!atomic_read_unchecked(&data->interrupt_handled))
41919 schedule_work(&data->read_work);
41920 }
41921 ret = wait_event_timeout(data->wait_queue,
41922@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41923
41924 /* First disable the interrupt */
41925 disable_irq_nosync(irq);
41926- atomic_inc(&data->interrupt_handled);
41927+ atomic_inc_unchecked(&data->interrupt_handled);
41928 /* Then schedule a reading work struct */
41929 if (data->state != SHT15_READING_NOTHING)
41930 schedule_work(&data->read_work);
41931@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41932 * If not, then start the interrupt again - care here as could
41933 * have gone low in meantime so verify it hasn't!
41934 */
41935- atomic_set(&data->interrupt_handled, 0);
41936+ atomic_set_unchecked(&data->interrupt_handled, 0);
41937 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41938 /* If still not occurred or another handler was scheduled */
41939 if (gpio_get_value(data->pdata->gpio_data)
41940- || atomic_read(&data->interrupt_handled))
41941+ || atomic_read_unchecked(&data->interrupt_handled))
41942 return;
41943 }
41944
41945diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41946index 8df43c5..b07b91d 100644
41947--- a/drivers/hwmon/via-cputemp.c
41948+++ b/drivers/hwmon/via-cputemp.c
41949@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41950 return NOTIFY_OK;
41951 }
41952
41953-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41954+static struct notifier_block via_cputemp_cpu_notifier = {
41955 .notifier_call = via_cputemp_cpu_callback,
41956 };
41957
41958diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41959index 41fc683..a39cfea 100644
41960--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41961+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41962@@ -43,7 +43,7 @@
41963 extern struct i2c_adapter amd756_smbus;
41964
41965 static struct i2c_adapter *s4882_adapter;
41966-static struct i2c_algorithm *s4882_algo;
41967+static i2c_algorithm_no_const *s4882_algo;
41968
41969 /* Wrapper access functions for multiplexed SMBus */
41970 static DEFINE_MUTEX(amd756_lock);
41971diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41972index 721f7eb..0fd2a09 100644
41973--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41974+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41975@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41976 /* usb layer */
41977
41978 /* Send command to device, and get response. */
41979-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41980+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41981 {
41982 int ret = 0;
41983 int actual;
41984diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41985index b170bdf..3c76427 100644
41986--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41987+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41988@@ -41,7 +41,7 @@
41989 extern struct i2c_adapter *nforce2_smbus;
41990
41991 static struct i2c_adapter *s4985_adapter;
41992-static struct i2c_algorithm *s4985_algo;
41993+static i2c_algorithm_no_const *s4985_algo;
41994
41995 /* Wrapper access functions for multiplexed SMBus */
41996 static DEFINE_MUTEX(nforce2_lock);
41997diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41998index 80b47e8..1a6040d9 100644
41999--- a/drivers/i2c/i2c-dev.c
42000+++ b/drivers/i2c/i2c-dev.c
42001@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42002 break;
42003 }
42004
42005- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42006+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42007 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42008 if (IS_ERR(rdwr_pa[i].buf)) {
42009 res = PTR_ERR(rdwr_pa[i].buf);
42010diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42011index 0b510ba..4fbb5085 100644
42012--- a/drivers/ide/ide-cd.c
42013+++ b/drivers/ide/ide-cd.c
42014@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42015 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42016 if ((unsigned long)buf & alignment
42017 || blk_rq_bytes(rq) & q->dma_pad_mask
42018- || object_is_on_stack(buf))
42019+ || object_starts_on_stack(buf))
42020 drive->dma = 0;
42021 }
42022 }
42023diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42024index ede16aec..e423e8a 100644
42025--- a/drivers/iio/industrialio-core.c
42026+++ b/drivers/iio/industrialio-core.c
42027@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42028 }
42029
42030 static
42031-int __iio_device_attr_init(struct device_attribute *dev_attr,
42032+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42033 const char *postfix,
42034 struct iio_chan_spec const *chan,
42035 ssize_t (*readfunc)(struct device *dev,
42036diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42037index c323917..6ddea8b 100644
42038--- a/drivers/infiniband/core/cm.c
42039+++ b/drivers/infiniband/core/cm.c
42040@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42041
42042 struct cm_counter_group {
42043 struct kobject obj;
42044- atomic_long_t counter[CM_ATTR_COUNT];
42045+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42046 };
42047
42048 struct cm_counter_attribute {
42049@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42050 struct ib_mad_send_buf *msg = NULL;
42051 int ret;
42052
42053- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42054+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42055 counter[CM_REQ_COUNTER]);
42056
42057 /* Quick state check to discard duplicate REQs. */
42058@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42059 if (!cm_id_priv)
42060 return;
42061
42062- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42063+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42064 counter[CM_REP_COUNTER]);
42065 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42066 if (ret)
42067@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42068 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42069 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42070 spin_unlock_irq(&cm_id_priv->lock);
42071- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42072+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42073 counter[CM_RTU_COUNTER]);
42074 goto out;
42075 }
42076@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42077 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42078 dreq_msg->local_comm_id);
42079 if (!cm_id_priv) {
42080- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42081+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42082 counter[CM_DREQ_COUNTER]);
42083 cm_issue_drep(work->port, work->mad_recv_wc);
42084 return -EINVAL;
42085@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42086 case IB_CM_MRA_REP_RCVD:
42087 break;
42088 case IB_CM_TIMEWAIT:
42089- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42090+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42091 counter[CM_DREQ_COUNTER]);
42092 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42093 goto unlock;
42094@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42095 cm_free_msg(msg);
42096 goto deref;
42097 case IB_CM_DREQ_RCVD:
42098- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42099+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42100 counter[CM_DREQ_COUNTER]);
42101 goto unlock;
42102 default:
42103@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42104 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42105 cm_id_priv->msg, timeout)) {
42106 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42107- atomic_long_inc(&work->port->
42108+ atomic_long_inc_unchecked(&work->port->
42109 counter_group[CM_RECV_DUPLICATES].
42110 counter[CM_MRA_COUNTER]);
42111 goto out;
42112@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42113 break;
42114 case IB_CM_MRA_REQ_RCVD:
42115 case IB_CM_MRA_REP_RCVD:
42116- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42117+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42118 counter[CM_MRA_COUNTER]);
42119 /* fall through */
42120 default:
42121@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42122 case IB_CM_LAP_IDLE:
42123 break;
42124 case IB_CM_MRA_LAP_SENT:
42125- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42126+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42127 counter[CM_LAP_COUNTER]);
42128 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42129 goto unlock;
42130@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42131 cm_free_msg(msg);
42132 goto deref;
42133 case IB_CM_LAP_RCVD:
42134- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42135+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42136 counter[CM_LAP_COUNTER]);
42137 goto unlock;
42138 default:
42139@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42140 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42141 if (cur_cm_id_priv) {
42142 spin_unlock_irq(&cm.lock);
42143- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42144+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42145 counter[CM_SIDR_REQ_COUNTER]);
42146 goto out; /* Duplicate message. */
42147 }
42148@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42149 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42150 msg->retries = 1;
42151
42152- atomic_long_add(1 + msg->retries,
42153+ atomic_long_add_unchecked(1 + msg->retries,
42154 &port->counter_group[CM_XMIT].counter[attr_index]);
42155 if (msg->retries)
42156- atomic_long_add(msg->retries,
42157+ atomic_long_add_unchecked(msg->retries,
42158 &port->counter_group[CM_XMIT_RETRIES].
42159 counter[attr_index]);
42160
42161@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42162 }
42163
42164 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42165- atomic_long_inc(&port->counter_group[CM_RECV].
42166+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42167 counter[attr_id - CM_ATTR_ID_OFFSET]);
42168
42169 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42170@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42171 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42172
42173 return sprintf(buf, "%ld\n",
42174- atomic_long_read(&group->counter[cm_attr->index]));
42175+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42176 }
42177
42178 static const struct sysfs_ops cm_counter_ops = {
42179diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42180index 9f5ad7c..588cd84 100644
42181--- a/drivers/infiniband/core/fmr_pool.c
42182+++ b/drivers/infiniband/core/fmr_pool.c
42183@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42184
42185 struct task_struct *thread;
42186
42187- atomic_t req_ser;
42188- atomic_t flush_ser;
42189+ atomic_unchecked_t req_ser;
42190+ atomic_unchecked_t flush_ser;
42191
42192 wait_queue_head_t force_wait;
42193 };
42194@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42195 struct ib_fmr_pool *pool = pool_ptr;
42196
42197 do {
42198- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42199+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42200 ib_fmr_batch_release(pool);
42201
42202- atomic_inc(&pool->flush_ser);
42203+ atomic_inc_unchecked(&pool->flush_ser);
42204 wake_up_interruptible(&pool->force_wait);
42205
42206 if (pool->flush_function)
42207@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42208 }
42209
42210 set_current_state(TASK_INTERRUPTIBLE);
42211- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42212+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42213 !kthread_should_stop())
42214 schedule();
42215 __set_current_state(TASK_RUNNING);
42216@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42217 pool->dirty_watermark = params->dirty_watermark;
42218 pool->dirty_len = 0;
42219 spin_lock_init(&pool->pool_lock);
42220- atomic_set(&pool->req_ser, 0);
42221- atomic_set(&pool->flush_ser, 0);
42222+ atomic_set_unchecked(&pool->req_ser, 0);
42223+ atomic_set_unchecked(&pool->flush_ser, 0);
42224 init_waitqueue_head(&pool->force_wait);
42225
42226 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42227@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42228 }
42229 spin_unlock_irq(&pool->pool_lock);
42230
42231- serial = atomic_inc_return(&pool->req_ser);
42232+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42233 wake_up_process(pool->thread);
42234
42235 if (wait_event_interruptible(pool->force_wait,
42236- atomic_read(&pool->flush_ser) - serial >= 0))
42237+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42238 return -EINTR;
42239
42240 return 0;
42241@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42242 } else {
42243 list_add_tail(&fmr->list, &pool->dirty_list);
42244 if (++pool->dirty_len >= pool->dirty_watermark) {
42245- atomic_inc(&pool->req_ser);
42246+ atomic_inc_unchecked(&pool->req_ser);
42247 wake_up_process(pool->thread);
42248 }
42249 }
42250diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42251index ec7a298..8742e59 100644
42252--- a/drivers/infiniband/hw/cxgb4/mem.c
42253+++ b/drivers/infiniband/hw/cxgb4/mem.c
42254@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42255 int err;
42256 struct fw_ri_tpte tpt;
42257 u32 stag_idx;
42258- static atomic_t key;
42259+ static atomic_unchecked_t key;
42260
42261 if (c4iw_fatal_error(rdev))
42262 return -EIO;
42263@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42264 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42265 rdev->stats.stag.max = rdev->stats.stag.cur;
42266 mutex_unlock(&rdev->stats.lock);
42267- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42268+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42269 }
42270 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42271 __func__, stag_state, type, pdid, stag_idx);
42272diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42273index 79b3dbc..96e5fcc 100644
42274--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42275+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42276@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42277 struct ib_atomic_eth *ateth;
42278 struct ipath_ack_entry *e;
42279 u64 vaddr;
42280- atomic64_t *maddr;
42281+ atomic64_unchecked_t *maddr;
42282 u64 sdata;
42283 u32 rkey;
42284 u8 next;
42285@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42286 IB_ACCESS_REMOTE_ATOMIC)))
42287 goto nack_acc_unlck;
42288 /* Perform atomic OP and save result. */
42289- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42290+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42291 sdata = be64_to_cpu(ateth->swap_data);
42292 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42293 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42294- (u64) atomic64_add_return(sdata, maddr) - sdata :
42295+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42296 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42297 be64_to_cpu(ateth->compare_data),
42298 sdata);
42299diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42300index 1f95bba..9530f87 100644
42301--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42302+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42303@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42304 unsigned long flags;
42305 struct ib_wc wc;
42306 u64 sdata;
42307- atomic64_t *maddr;
42308+ atomic64_unchecked_t *maddr;
42309 enum ib_wc_status send_status;
42310
42311 /*
42312@@ -382,11 +382,11 @@ again:
42313 IB_ACCESS_REMOTE_ATOMIC)))
42314 goto acc_err;
42315 /* Perform atomic OP and save result. */
42316- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42317+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42318 sdata = wqe->wr.wr.atomic.compare_add;
42319 *(u64 *) sqp->s_sge.sge.vaddr =
42320 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42321- (u64) atomic64_add_return(sdata, maddr) - sdata :
42322+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42323 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42324 sdata, wqe->wr.wr.atomic.swap);
42325 goto send_comp;
42326diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42327index fd36ec6..a6a082f 100644
42328--- a/drivers/infiniband/hw/mlx4/mad.c
42329+++ b/drivers/infiniband/hw/mlx4/mad.c
42330@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42331
42332 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42333 {
42334- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42335+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42336 cpu_to_be64(0xff00000000000000LL);
42337 }
42338
42339diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42340index ed327e6..ca1739e0 100644
42341--- a/drivers/infiniband/hw/mlx4/mcg.c
42342+++ b/drivers/infiniband/hw/mlx4/mcg.c
42343@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42344 {
42345 char name[20];
42346
42347- atomic_set(&ctx->tid, 0);
42348+ atomic_set_unchecked(&ctx->tid, 0);
42349 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42350 ctx->mcg_wq = create_singlethread_workqueue(name);
42351 if (!ctx->mcg_wq)
42352diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42353index 66b0b7d..f14836a 100644
42354--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42355+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42356@@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42357 struct list_head mcg_mgid0_list;
42358 struct workqueue_struct *mcg_wq;
42359 struct mlx4_ib_demux_pv_ctx **tun;
42360- atomic_t tid;
42361+ atomic_unchecked_t tid;
42362 int flushing; /* flushing the work queue */
42363 };
42364
42365diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42366index 9d3e5c1..6f166df 100644
42367--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42368+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42369@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42370 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42371 }
42372
42373-int mthca_QUERY_FW(struct mthca_dev *dev)
42374+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42375 {
42376 struct mthca_mailbox *mailbox;
42377 u32 *outbox;
42378@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42379 CMD_TIME_CLASS_B);
42380 }
42381
42382-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42383+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42384 int num_mtt)
42385 {
42386 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42387@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42388 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42389 }
42390
42391-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42392+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42393 int eq_num)
42394 {
42395 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42396@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42397 CMD_TIME_CLASS_B);
42398 }
42399
42400-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42401+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42402 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42403 void *in_mad, void *response_mad)
42404 {
42405diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42406index ded76c1..0cf0a08 100644
42407--- a/drivers/infiniband/hw/mthca/mthca_main.c
42408+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42409@@ -692,7 +692,7 @@ err_close:
42410 return err;
42411 }
42412
42413-static int mthca_setup_hca(struct mthca_dev *dev)
42414+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42415 {
42416 int err;
42417
42418diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42419index ed9a989..6aa5dc2 100644
42420--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42421+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42422@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42423 * through the bitmaps)
42424 */
42425
42426-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42427+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42428 {
42429 int o;
42430 int m;
42431@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42432 return key;
42433 }
42434
42435-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42436+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42437 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42438 {
42439 struct mthca_mailbox *mailbox;
42440@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42441 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42442 }
42443
42444-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42445+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42446 u64 *buffer_list, int buffer_size_shift,
42447 int list_len, u64 iova, u64 total_size,
42448 u32 access, struct mthca_mr *mr)
42449diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42450index 415f8e1..e34214e 100644
42451--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42452+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42453@@ -764,7 +764,7 @@ unlock:
42454 return 0;
42455 }
42456
42457-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42458+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42459 {
42460 struct mthca_dev *dev = to_mdev(ibcq->device);
42461 struct mthca_cq *cq = to_mcq(ibcq);
42462diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42463index 353c7b0..c6ce921 100644
42464--- a/drivers/infiniband/hw/nes/nes.c
42465+++ b/drivers/infiniband/hw/nes/nes.c
42466@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42467 LIST_HEAD(nes_adapter_list);
42468 static LIST_HEAD(nes_dev_list);
42469
42470-atomic_t qps_destroyed;
42471+atomic_unchecked_t qps_destroyed;
42472
42473 static unsigned int ee_flsh_adapter;
42474 static unsigned int sysfs_nonidx_addr;
42475@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42476 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42477 struct nes_adapter *nesadapter = nesdev->nesadapter;
42478
42479- atomic_inc(&qps_destroyed);
42480+ atomic_inc_unchecked(&qps_destroyed);
42481
42482 /* Free the control structures */
42483
42484diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42485index 33cc589..3bd6538 100644
42486--- a/drivers/infiniband/hw/nes/nes.h
42487+++ b/drivers/infiniband/hw/nes/nes.h
42488@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42489 extern unsigned int wqm_quanta;
42490 extern struct list_head nes_adapter_list;
42491
42492-extern atomic_t cm_connects;
42493-extern atomic_t cm_accepts;
42494-extern atomic_t cm_disconnects;
42495-extern atomic_t cm_closes;
42496-extern atomic_t cm_connecteds;
42497-extern atomic_t cm_connect_reqs;
42498-extern atomic_t cm_rejects;
42499-extern atomic_t mod_qp_timouts;
42500-extern atomic_t qps_created;
42501-extern atomic_t qps_destroyed;
42502-extern atomic_t sw_qps_destroyed;
42503+extern atomic_unchecked_t cm_connects;
42504+extern atomic_unchecked_t cm_accepts;
42505+extern atomic_unchecked_t cm_disconnects;
42506+extern atomic_unchecked_t cm_closes;
42507+extern atomic_unchecked_t cm_connecteds;
42508+extern atomic_unchecked_t cm_connect_reqs;
42509+extern atomic_unchecked_t cm_rejects;
42510+extern atomic_unchecked_t mod_qp_timouts;
42511+extern atomic_unchecked_t qps_created;
42512+extern atomic_unchecked_t qps_destroyed;
42513+extern atomic_unchecked_t sw_qps_destroyed;
42514 extern u32 mh_detected;
42515 extern u32 mh_pauses_sent;
42516 extern u32 cm_packets_sent;
42517@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42518 extern u32 cm_packets_received;
42519 extern u32 cm_packets_dropped;
42520 extern u32 cm_packets_retrans;
42521-extern atomic_t cm_listens_created;
42522-extern atomic_t cm_listens_destroyed;
42523+extern atomic_unchecked_t cm_listens_created;
42524+extern atomic_unchecked_t cm_listens_destroyed;
42525 extern u32 cm_backlog_drops;
42526-extern atomic_t cm_loopbacks;
42527-extern atomic_t cm_nodes_created;
42528-extern atomic_t cm_nodes_destroyed;
42529-extern atomic_t cm_accel_dropped_pkts;
42530-extern atomic_t cm_resets_recvd;
42531-extern atomic_t pau_qps_created;
42532-extern atomic_t pau_qps_destroyed;
42533+extern atomic_unchecked_t cm_loopbacks;
42534+extern atomic_unchecked_t cm_nodes_created;
42535+extern atomic_unchecked_t cm_nodes_destroyed;
42536+extern atomic_unchecked_t cm_accel_dropped_pkts;
42537+extern atomic_unchecked_t cm_resets_recvd;
42538+extern atomic_unchecked_t pau_qps_created;
42539+extern atomic_unchecked_t pau_qps_destroyed;
42540
42541 extern u32 int_mod_timer_init;
42542 extern u32 int_mod_cq_depth_256;
42543diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42544index dfa9df4..6bf7221 100644
42545--- a/drivers/infiniband/hw/nes/nes_cm.c
42546+++ b/drivers/infiniband/hw/nes/nes_cm.c
42547@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42548 u32 cm_packets_retrans;
42549 u32 cm_packets_created;
42550 u32 cm_packets_received;
42551-atomic_t cm_listens_created;
42552-atomic_t cm_listens_destroyed;
42553+atomic_unchecked_t cm_listens_created;
42554+atomic_unchecked_t cm_listens_destroyed;
42555 u32 cm_backlog_drops;
42556-atomic_t cm_loopbacks;
42557-atomic_t cm_nodes_created;
42558-atomic_t cm_nodes_destroyed;
42559-atomic_t cm_accel_dropped_pkts;
42560-atomic_t cm_resets_recvd;
42561+atomic_unchecked_t cm_loopbacks;
42562+atomic_unchecked_t cm_nodes_created;
42563+atomic_unchecked_t cm_nodes_destroyed;
42564+atomic_unchecked_t cm_accel_dropped_pkts;
42565+atomic_unchecked_t cm_resets_recvd;
42566
42567 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42568 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42569@@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42570 /* instance of function pointers for client API */
42571 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42572 static struct nes_cm_ops nes_cm_api = {
42573- mini_cm_accelerated,
42574- mini_cm_listen,
42575- mini_cm_del_listen,
42576- mini_cm_connect,
42577- mini_cm_close,
42578- mini_cm_accept,
42579- mini_cm_reject,
42580- mini_cm_recv_pkt,
42581- mini_cm_dealloc_core,
42582- mini_cm_get,
42583- mini_cm_set
42584+ .accelerated = mini_cm_accelerated,
42585+ .listen = mini_cm_listen,
42586+ .stop_listener = mini_cm_del_listen,
42587+ .connect = mini_cm_connect,
42588+ .close = mini_cm_close,
42589+ .accept = mini_cm_accept,
42590+ .reject = mini_cm_reject,
42591+ .recv_pkt = mini_cm_recv_pkt,
42592+ .destroy_cm_core = mini_cm_dealloc_core,
42593+ .get = mini_cm_get,
42594+ .set = mini_cm_set
42595 };
42596
42597 static struct nes_cm_core *g_cm_core;
42598
42599-atomic_t cm_connects;
42600-atomic_t cm_accepts;
42601-atomic_t cm_disconnects;
42602-atomic_t cm_closes;
42603-atomic_t cm_connecteds;
42604-atomic_t cm_connect_reqs;
42605-atomic_t cm_rejects;
42606+atomic_unchecked_t cm_connects;
42607+atomic_unchecked_t cm_accepts;
42608+atomic_unchecked_t cm_disconnects;
42609+atomic_unchecked_t cm_closes;
42610+atomic_unchecked_t cm_connecteds;
42611+atomic_unchecked_t cm_connect_reqs;
42612+atomic_unchecked_t cm_rejects;
42613
42614 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42615 {
42616@@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42617 kfree(listener);
42618 listener = NULL;
42619 ret = 0;
42620- atomic_inc(&cm_listens_destroyed);
42621+ atomic_inc_unchecked(&cm_listens_destroyed);
42622 } else {
42623 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42624 }
42625@@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42626 cm_node->rem_mac);
42627
42628 add_hte_node(cm_core, cm_node);
42629- atomic_inc(&cm_nodes_created);
42630+ atomic_inc_unchecked(&cm_nodes_created);
42631
42632 return cm_node;
42633 }
42634@@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42635 }
42636
42637 atomic_dec(&cm_core->node_cnt);
42638- atomic_inc(&cm_nodes_destroyed);
42639+ atomic_inc_unchecked(&cm_nodes_destroyed);
42640 nesqp = cm_node->nesqp;
42641 if (nesqp) {
42642 nesqp->cm_node = NULL;
42643@@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42644
42645 static void drop_packet(struct sk_buff *skb)
42646 {
42647- atomic_inc(&cm_accel_dropped_pkts);
42648+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42649 dev_kfree_skb_any(skb);
42650 }
42651
42652@@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42653 {
42654
42655 int reset = 0; /* whether to send reset in case of err.. */
42656- atomic_inc(&cm_resets_recvd);
42657+ atomic_inc_unchecked(&cm_resets_recvd);
42658 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42659 " refcnt=%d\n", cm_node, cm_node->state,
42660 atomic_read(&cm_node->ref_count));
42661@@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42662 rem_ref_cm_node(cm_node->cm_core, cm_node);
42663 return NULL;
42664 }
42665- atomic_inc(&cm_loopbacks);
42666+ atomic_inc_unchecked(&cm_loopbacks);
42667 loopbackremotenode->loopbackpartner = cm_node;
42668 loopbackremotenode->tcp_cntxt.rcv_wscale =
42669 NES_CM_DEFAULT_RCV_WND_SCALE;
42670@@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42671 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42672 else {
42673 rem_ref_cm_node(cm_core, cm_node);
42674- atomic_inc(&cm_accel_dropped_pkts);
42675+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42676 dev_kfree_skb_any(skb);
42677 }
42678 break;
42679@@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42680
42681 if ((cm_id) && (cm_id->event_handler)) {
42682 if (issue_disconn) {
42683- atomic_inc(&cm_disconnects);
42684+ atomic_inc_unchecked(&cm_disconnects);
42685 cm_event.event = IW_CM_EVENT_DISCONNECT;
42686 cm_event.status = disconn_status;
42687 cm_event.local_addr = cm_id->local_addr;
42688@@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42689 }
42690
42691 if (issue_close) {
42692- atomic_inc(&cm_closes);
42693+ atomic_inc_unchecked(&cm_closes);
42694 nes_disconnect(nesqp, 1);
42695
42696 cm_id->provider_data = nesqp;
42697@@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42698
42699 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42700 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42701- atomic_inc(&cm_accepts);
42702+ atomic_inc_unchecked(&cm_accepts);
42703
42704 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42705 netdev_refcnt_read(nesvnic->netdev));
42706@@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42707 struct nes_cm_core *cm_core;
42708 u8 *start_buff;
42709
42710- atomic_inc(&cm_rejects);
42711+ atomic_inc_unchecked(&cm_rejects);
42712 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42713 loopback = cm_node->loopbackpartner;
42714 cm_core = cm_node->cm_core;
42715@@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42716 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42717 ntohs(laddr->sin_port));
42718
42719- atomic_inc(&cm_connects);
42720+ atomic_inc_unchecked(&cm_connects);
42721 nesqp->active_conn = 1;
42722
42723 /* cache the cm_id in the qp */
42724@@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42725 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42726 return err;
42727 }
42728- atomic_inc(&cm_listens_created);
42729+ atomic_inc_unchecked(&cm_listens_created);
42730 }
42731
42732 cm_id->add_ref(cm_id);
42733@@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42734
42735 if (nesqp->destroyed)
42736 return;
42737- atomic_inc(&cm_connecteds);
42738+ atomic_inc_unchecked(&cm_connecteds);
42739 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42740 " local port 0x%04X. jiffies = %lu.\n",
42741 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42742@@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42743
42744 cm_id->add_ref(cm_id);
42745 ret = cm_id->event_handler(cm_id, &cm_event);
42746- atomic_inc(&cm_closes);
42747+ atomic_inc_unchecked(&cm_closes);
42748 cm_event.event = IW_CM_EVENT_CLOSE;
42749 cm_event.status = 0;
42750 cm_event.provider_data = cm_id->provider_data;
42751@@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42752 return;
42753 cm_id = cm_node->cm_id;
42754
42755- atomic_inc(&cm_connect_reqs);
42756+ atomic_inc_unchecked(&cm_connect_reqs);
42757 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42758 cm_node, cm_id, jiffies);
42759
42760@@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42761 return;
42762 cm_id = cm_node->cm_id;
42763
42764- atomic_inc(&cm_connect_reqs);
42765+ atomic_inc_unchecked(&cm_connect_reqs);
42766 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42767 cm_node, cm_id, jiffies);
42768
42769diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42770index 4166452..fc952c3 100644
42771--- a/drivers/infiniband/hw/nes/nes_mgt.c
42772+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42773@@ -40,8 +40,8 @@
42774 #include "nes.h"
42775 #include "nes_mgt.h"
42776
42777-atomic_t pau_qps_created;
42778-atomic_t pau_qps_destroyed;
42779+atomic_unchecked_t pau_qps_created;
42780+atomic_unchecked_t pau_qps_destroyed;
42781
42782 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42783 {
42784@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42785 {
42786 struct sk_buff *skb;
42787 unsigned long flags;
42788- atomic_inc(&pau_qps_destroyed);
42789+ atomic_inc_unchecked(&pau_qps_destroyed);
42790
42791 /* Free packets that have not yet been forwarded */
42792 /* Lock is acquired by skb_dequeue when removing the skb */
42793@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42794 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42795 skb_queue_head_init(&nesqp->pau_list);
42796 spin_lock_init(&nesqp->pau_lock);
42797- atomic_inc(&pau_qps_created);
42798+ atomic_inc_unchecked(&pau_qps_created);
42799 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42800 }
42801
42802diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42803index 49eb511..a774366 100644
42804--- a/drivers/infiniband/hw/nes/nes_nic.c
42805+++ b/drivers/infiniband/hw/nes/nes_nic.c
42806@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42807 target_stat_values[++index] = mh_detected;
42808 target_stat_values[++index] = mh_pauses_sent;
42809 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42810- target_stat_values[++index] = atomic_read(&cm_connects);
42811- target_stat_values[++index] = atomic_read(&cm_accepts);
42812- target_stat_values[++index] = atomic_read(&cm_disconnects);
42813- target_stat_values[++index] = atomic_read(&cm_connecteds);
42814- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42815- target_stat_values[++index] = atomic_read(&cm_rejects);
42816- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42817- target_stat_values[++index] = atomic_read(&qps_created);
42818- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42819- target_stat_values[++index] = atomic_read(&qps_destroyed);
42820- target_stat_values[++index] = atomic_read(&cm_closes);
42821+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42822+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42823+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42824+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42825+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42826+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42827+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42828+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42829+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42830+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42831+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42832 target_stat_values[++index] = cm_packets_sent;
42833 target_stat_values[++index] = cm_packets_bounced;
42834 target_stat_values[++index] = cm_packets_created;
42835 target_stat_values[++index] = cm_packets_received;
42836 target_stat_values[++index] = cm_packets_dropped;
42837 target_stat_values[++index] = cm_packets_retrans;
42838- target_stat_values[++index] = atomic_read(&cm_listens_created);
42839- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42840+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42841+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42842 target_stat_values[++index] = cm_backlog_drops;
42843- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42844- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42845- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42846- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42847- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42848+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42849+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42850+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42851+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42852+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42853 target_stat_values[++index] = nesadapter->free_4kpbl;
42854 target_stat_values[++index] = nesadapter->free_256pbl;
42855 target_stat_values[++index] = int_mod_timer_init;
42856 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42857 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42858 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42859- target_stat_values[++index] = atomic_read(&pau_qps_created);
42860- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42861+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42862+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42863 }
42864
42865 /**
42866diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42867index 218dd35..97ce31d 100644
42868--- a/drivers/infiniband/hw/nes/nes_verbs.c
42869+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42870@@ -46,9 +46,9 @@
42871
42872 #include <rdma/ib_umem.h>
42873
42874-atomic_t mod_qp_timouts;
42875-atomic_t qps_created;
42876-atomic_t sw_qps_destroyed;
42877+atomic_unchecked_t mod_qp_timouts;
42878+atomic_unchecked_t qps_created;
42879+atomic_unchecked_t sw_qps_destroyed;
42880
42881 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42882
42883@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42884 if (init_attr->create_flags)
42885 return ERR_PTR(-EINVAL);
42886
42887- atomic_inc(&qps_created);
42888+ atomic_inc_unchecked(&qps_created);
42889 switch (init_attr->qp_type) {
42890 case IB_QPT_RC:
42891 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42892@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42893 struct iw_cm_event cm_event;
42894 int ret = 0;
42895
42896- atomic_inc(&sw_qps_destroyed);
42897+ atomic_inc_unchecked(&sw_qps_destroyed);
42898 nesqp->destroyed = 1;
42899
42900 /* Blow away the connection if it exists. */
42901diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42902index c00ae09..04e91be 100644
42903--- a/drivers/infiniband/hw/qib/qib.h
42904+++ b/drivers/infiniband/hw/qib/qib.h
42905@@ -52,6 +52,7 @@
42906 #include <linux/kref.h>
42907 #include <linux/sched.h>
42908 #include <linux/kthread.h>
42909+#include <linux/slab.h>
42910
42911 #include "qib_common.h"
42912 #include "qib_verbs.h"
42913diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42914index 24c41ba..102d71f 100644
42915--- a/drivers/input/gameport/gameport.c
42916+++ b/drivers/input/gameport/gameport.c
42917@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42918 */
42919 static void gameport_init_port(struct gameport *gameport)
42920 {
42921- static atomic_t gameport_no = ATOMIC_INIT(0);
42922+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42923
42924 __module_get(THIS_MODULE);
42925
42926 mutex_init(&gameport->drv_mutex);
42927 device_initialize(&gameport->dev);
42928 dev_set_name(&gameport->dev, "gameport%lu",
42929- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42930+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42931 gameport->dev.bus = &gameport_bus;
42932 gameport->dev.release = gameport_release_port;
42933 if (gameport->parent)
42934diff --git a/drivers/input/input.c b/drivers/input/input.c
42935index 29ca0bb..f4bc2e3 100644
42936--- a/drivers/input/input.c
42937+++ b/drivers/input/input.c
42938@@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
42939 */
42940 struct input_dev *input_allocate_device(void)
42941 {
42942- static atomic_t input_no = ATOMIC_INIT(0);
42943+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42944 struct input_dev *dev;
42945
42946 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42947@@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
42948 INIT_LIST_HEAD(&dev->node);
42949
42950 dev_set_name(&dev->dev, "input%ld",
42951- (unsigned long) atomic_inc_return(&input_no) - 1);
42952+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42953
42954 __module_get(THIS_MODULE);
42955 }
42956diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42957index 4a95b22..874c182 100644
42958--- a/drivers/input/joystick/sidewinder.c
42959+++ b/drivers/input/joystick/sidewinder.c
42960@@ -30,6 +30,7 @@
42961 #include <linux/kernel.h>
42962 #include <linux/module.h>
42963 #include <linux/slab.h>
42964+#include <linux/sched.h>
42965 #include <linux/input.h>
42966 #include <linux/gameport.h>
42967 #include <linux/jiffies.h>
42968diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42969index 603fe0d..f63decc 100644
42970--- a/drivers/input/joystick/xpad.c
42971+++ b/drivers/input/joystick/xpad.c
42972@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42973
42974 static int xpad_led_probe(struct usb_xpad *xpad)
42975 {
42976- static atomic_t led_seq = ATOMIC_INIT(0);
42977+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42978 long led_no;
42979 struct xpad_led *led;
42980 struct led_classdev *led_cdev;
42981@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42982 if (!led)
42983 return -ENOMEM;
42984
42985- led_no = (long)atomic_inc_return(&led_seq) - 1;
42986+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42987
42988 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42989 led->xpad = xpad;
42990diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42991index 5a73639..d586683 100644
42992--- a/drivers/input/misc/ims-pcu.c
42993+++ b/drivers/input/misc/ims-pcu.c
42994@@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42995
42996 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42997 {
42998- static atomic_t device_no = ATOMIC_INIT(0);
42999+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43000
43001 const struct ims_pcu_device_info *info;
43002 int error;
43003@@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43004 }
43005
43006 /* Device appears to be operable, complete initialization */
43007- pcu->device_no = atomic_inc_return(&device_no) - 1;
43008+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43009
43010 /*
43011 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43012diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43013index 2f0b39d..7370f13 100644
43014--- a/drivers/input/mouse/psmouse.h
43015+++ b/drivers/input/mouse/psmouse.h
43016@@ -116,7 +116,7 @@ struct psmouse_attribute {
43017 ssize_t (*set)(struct psmouse *psmouse, void *data,
43018 const char *buf, size_t count);
43019 bool protect;
43020-};
43021+} __do_const;
43022 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43023
43024 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43025diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43026index b604564..3f14ae4 100644
43027--- a/drivers/input/mousedev.c
43028+++ b/drivers/input/mousedev.c
43029@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43030
43031 spin_unlock_irq(&client->packet_lock);
43032
43033- if (copy_to_user(buffer, data, count))
43034+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43035 return -EFAULT;
43036
43037 return count;
43038diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43039index b29134d..394deb0 100644
43040--- a/drivers/input/serio/serio.c
43041+++ b/drivers/input/serio/serio.c
43042@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43043 */
43044 static void serio_init_port(struct serio *serio)
43045 {
43046- static atomic_t serio_no = ATOMIC_INIT(0);
43047+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43048
43049 __module_get(THIS_MODULE);
43050
43051@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43052 mutex_init(&serio->drv_mutex);
43053 device_initialize(&serio->dev);
43054 dev_set_name(&serio->dev, "serio%ld",
43055- (long)atomic_inc_return(&serio_no) - 1);
43056+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
43057 serio->dev.bus = &serio_bus;
43058 serio->dev.release = serio_release_port;
43059 serio->dev.groups = serio_device_attr_groups;
43060diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43061index c9a02fe..0debc75 100644
43062--- a/drivers/input/serio/serio_raw.c
43063+++ b/drivers/input/serio/serio_raw.c
43064@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43065
43066 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43067 {
43068- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43069+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43070 struct serio_raw *serio_raw;
43071 int err;
43072
43073@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43074 }
43075
43076 snprintf(serio_raw->name, sizeof(serio_raw->name),
43077- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43078+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43079 kref_init(&serio_raw->kref);
43080 INIT_LIST_HEAD(&serio_raw->client_list);
43081 init_waitqueue_head(&serio_raw->wait);
43082diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43083index e5555fc..937986d 100644
43084--- a/drivers/iommu/iommu.c
43085+++ b/drivers/iommu/iommu.c
43086@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43087 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43088 {
43089 bus_register_notifier(bus, &iommu_bus_nb);
43090- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43091+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43092 }
43093
43094 /**
43095diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43096index 228632c9..edfe331 100644
43097--- a/drivers/iommu/irq_remapping.c
43098+++ b/drivers/iommu/irq_remapping.c
43099@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43100 void panic_if_irq_remap(const char *msg)
43101 {
43102 if (irq_remapping_enabled)
43103- panic(msg);
43104+ panic("%s", msg);
43105 }
43106
43107 static void ir_ack_apic_edge(struct irq_data *data)
43108@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43109
43110 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43111 {
43112- chip->irq_print_chip = ir_print_prefix;
43113- chip->irq_ack = ir_ack_apic_edge;
43114- chip->irq_eoi = ir_ack_apic_level;
43115- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43116+ pax_open_kernel();
43117+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43118+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43119+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43120+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43121+ pax_close_kernel();
43122 }
43123
43124 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43125diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43126index 739ca67..42ee3f1 100644
43127--- a/drivers/irqchip/irq-gic.c
43128+++ b/drivers/irqchip/irq-gic.c
43129@@ -85,7 +85,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43130 * Supported arch specific GIC irq extension.
43131 * Default make them NULL.
43132 */
43133-struct irq_chip gic_arch_extn = {
43134+irq_chip_no_const gic_arch_extn = {
43135 .irq_eoi = NULL,
43136 .irq_mask = NULL,
43137 .irq_unmask = NULL,
43138@@ -337,7 +337,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43139 chained_irq_exit(chip, desc);
43140 }
43141
43142-static struct irq_chip gic_chip = {
43143+static irq_chip_no_const gic_chip __read_only = {
43144 .name = "GIC",
43145 .irq_mask = gic_mask_irq,
43146 .irq_unmask = gic_unmask_irq,
43147diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43148index 8777065..a4a9967 100644
43149--- a/drivers/irqchip/irq-renesas-irqc.c
43150+++ b/drivers/irqchip/irq-renesas-irqc.c
43151@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43152 struct irqc_priv *p;
43153 struct resource *io;
43154 struct resource *irq;
43155- struct irq_chip *irq_chip;
43156+ irq_chip_no_const *irq_chip;
43157 const char *name = dev_name(&pdev->dev);
43158 int ret;
43159 int k;
43160diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43161index ac6f72b..81150f2 100644
43162--- a/drivers/isdn/capi/capi.c
43163+++ b/drivers/isdn/capi/capi.c
43164@@ -81,8 +81,8 @@ struct capiminor {
43165
43166 struct capi20_appl *ap;
43167 u32 ncci;
43168- atomic_t datahandle;
43169- atomic_t msgid;
43170+ atomic_unchecked_t datahandle;
43171+ atomic_unchecked_t msgid;
43172
43173 struct tty_port port;
43174 int ttyinstop;
43175@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43176 capimsg_setu16(s, 2, mp->ap->applid);
43177 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43178 capimsg_setu8 (s, 5, CAPI_RESP);
43179- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43180+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43181 capimsg_setu32(s, 8, mp->ncci);
43182 capimsg_setu16(s, 12, datahandle);
43183 }
43184@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43185 mp->outbytes -= len;
43186 spin_unlock_bh(&mp->outlock);
43187
43188- datahandle = atomic_inc_return(&mp->datahandle);
43189+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43190 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43191 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43192 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43193 capimsg_setu16(skb->data, 2, mp->ap->applid);
43194 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43195 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43196- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43197+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43198 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43199 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43200 capimsg_setu16(skb->data, 16, len); /* Data length */
43201diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43202index c44950d..10ac276 100644
43203--- a/drivers/isdn/gigaset/bas-gigaset.c
43204+++ b/drivers/isdn/gigaset/bas-gigaset.c
43205@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43206
43207
43208 static const struct gigaset_ops gigops = {
43209- gigaset_write_cmd,
43210- gigaset_write_room,
43211- gigaset_chars_in_buffer,
43212- gigaset_brkchars,
43213- gigaset_init_bchannel,
43214- gigaset_close_bchannel,
43215- gigaset_initbcshw,
43216- gigaset_freebcshw,
43217- gigaset_reinitbcshw,
43218- gigaset_initcshw,
43219- gigaset_freecshw,
43220- gigaset_set_modem_ctrl,
43221- gigaset_baud_rate,
43222- gigaset_set_line_ctrl,
43223- gigaset_isoc_send_skb,
43224- gigaset_isoc_input,
43225+ .write_cmd = gigaset_write_cmd,
43226+ .write_room = gigaset_write_room,
43227+ .chars_in_buffer = gigaset_chars_in_buffer,
43228+ .brkchars = gigaset_brkchars,
43229+ .init_bchannel = gigaset_init_bchannel,
43230+ .close_bchannel = gigaset_close_bchannel,
43231+ .initbcshw = gigaset_initbcshw,
43232+ .freebcshw = gigaset_freebcshw,
43233+ .reinitbcshw = gigaset_reinitbcshw,
43234+ .initcshw = gigaset_initcshw,
43235+ .freecshw = gigaset_freecshw,
43236+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43237+ .baud_rate = gigaset_baud_rate,
43238+ .set_line_ctrl = gigaset_set_line_ctrl,
43239+ .send_skb = gigaset_isoc_send_skb,
43240+ .handle_input = gigaset_isoc_input,
43241 };
43242
43243 /* bas_gigaset_init
43244diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43245index 600c79b..3752bab 100644
43246--- a/drivers/isdn/gigaset/interface.c
43247+++ b/drivers/isdn/gigaset/interface.c
43248@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43249 }
43250 tty->driver_data = cs;
43251
43252- ++cs->port.count;
43253+ atomic_inc(&cs->port.count);
43254
43255- if (cs->port.count == 1) {
43256+ if (atomic_read(&cs->port.count) == 1) {
43257 tty_port_tty_set(&cs->port, tty);
43258 cs->port.low_latency = 1;
43259 }
43260@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43261
43262 if (!cs->connected)
43263 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43264- else if (!cs->port.count)
43265+ else if (!atomic_read(&cs->port.count))
43266 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43267- else if (!--cs->port.count)
43268+ else if (!atomic_dec_return(&cs->port.count))
43269 tty_port_tty_set(&cs->port, NULL);
43270
43271 mutex_unlock(&cs->mutex);
43272diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43273index 8c91fd5..14f13ce 100644
43274--- a/drivers/isdn/gigaset/ser-gigaset.c
43275+++ b/drivers/isdn/gigaset/ser-gigaset.c
43276@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43277 }
43278
43279 static const struct gigaset_ops ops = {
43280- gigaset_write_cmd,
43281- gigaset_write_room,
43282- gigaset_chars_in_buffer,
43283- gigaset_brkchars,
43284- gigaset_init_bchannel,
43285- gigaset_close_bchannel,
43286- gigaset_initbcshw,
43287- gigaset_freebcshw,
43288- gigaset_reinitbcshw,
43289- gigaset_initcshw,
43290- gigaset_freecshw,
43291- gigaset_set_modem_ctrl,
43292- gigaset_baud_rate,
43293- gigaset_set_line_ctrl,
43294- gigaset_m10x_send_skb, /* asyncdata.c */
43295- gigaset_m10x_input, /* asyncdata.c */
43296+ .write_cmd = gigaset_write_cmd,
43297+ .write_room = gigaset_write_room,
43298+ .chars_in_buffer = gigaset_chars_in_buffer,
43299+ .brkchars = gigaset_brkchars,
43300+ .init_bchannel = gigaset_init_bchannel,
43301+ .close_bchannel = gigaset_close_bchannel,
43302+ .initbcshw = gigaset_initbcshw,
43303+ .freebcshw = gigaset_freebcshw,
43304+ .reinitbcshw = gigaset_reinitbcshw,
43305+ .initcshw = gigaset_initcshw,
43306+ .freecshw = gigaset_freecshw,
43307+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43308+ .baud_rate = gigaset_baud_rate,
43309+ .set_line_ctrl = gigaset_set_line_ctrl,
43310+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43311+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43312 };
43313
43314
43315diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43316index d0a41cb..b953e50 100644
43317--- a/drivers/isdn/gigaset/usb-gigaset.c
43318+++ b/drivers/isdn/gigaset/usb-gigaset.c
43319@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43320 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43321 memcpy(cs->hw.usb->bchars, buf, 6);
43322 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43323- 0, 0, &buf, 6, 2000);
43324+ 0, 0, buf, 6, 2000);
43325 }
43326
43327 static void gigaset_freebcshw(struct bc_state *bcs)
43328@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43329 }
43330
43331 static const struct gigaset_ops ops = {
43332- gigaset_write_cmd,
43333- gigaset_write_room,
43334- gigaset_chars_in_buffer,
43335- gigaset_brkchars,
43336- gigaset_init_bchannel,
43337- gigaset_close_bchannel,
43338- gigaset_initbcshw,
43339- gigaset_freebcshw,
43340- gigaset_reinitbcshw,
43341- gigaset_initcshw,
43342- gigaset_freecshw,
43343- gigaset_set_modem_ctrl,
43344- gigaset_baud_rate,
43345- gigaset_set_line_ctrl,
43346- gigaset_m10x_send_skb,
43347- gigaset_m10x_input,
43348+ .write_cmd = gigaset_write_cmd,
43349+ .write_room = gigaset_write_room,
43350+ .chars_in_buffer = gigaset_chars_in_buffer,
43351+ .brkchars = gigaset_brkchars,
43352+ .init_bchannel = gigaset_init_bchannel,
43353+ .close_bchannel = gigaset_close_bchannel,
43354+ .initbcshw = gigaset_initbcshw,
43355+ .freebcshw = gigaset_freebcshw,
43356+ .reinitbcshw = gigaset_reinitbcshw,
43357+ .initcshw = gigaset_initcshw,
43358+ .freecshw = gigaset_freecshw,
43359+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43360+ .baud_rate = gigaset_baud_rate,
43361+ .set_line_ctrl = gigaset_set_line_ctrl,
43362+ .send_skb = gigaset_m10x_send_skb,
43363+ .handle_input = gigaset_m10x_input,
43364 };
43365
43366 /*
43367diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43368index 4d9b195..455075c 100644
43369--- a/drivers/isdn/hardware/avm/b1.c
43370+++ b/drivers/isdn/hardware/avm/b1.c
43371@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43372 }
43373 if (left) {
43374 if (t4file->user) {
43375- if (copy_from_user(buf, dp, left))
43376+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43377 return -EFAULT;
43378 } else {
43379 memcpy(buf, dp, left);
43380@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43381 }
43382 if (left) {
43383 if (config->user) {
43384- if (copy_from_user(buf, dp, left))
43385+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43386 return -EFAULT;
43387 } else {
43388 memcpy(buf, dp, left);
43389diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43390index 9b856e1..fa03c92 100644
43391--- a/drivers/isdn/i4l/isdn_common.c
43392+++ b/drivers/isdn/i4l/isdn_common.c
43393@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43394 } else
43395 return -EINVAL;
43396 case IIOCDBGVAR:
43397+ if (!capable(CAP_SYS_RAWIO))
43398+ return -EPERM;
43399 if (arg) {
43400 if (copy_to_user(argp, &dev, sizeof(ulong)))
43401 return -EFAULT;
43402diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43403index 91d5730..336523e 100644
43404--- a/drivers/isdn/i4l/isdn_concap.c
43405+++ b/drivers/isdn/i4l/isdn_concap.c
43406@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43407 }
43408
43409 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43410- &isdn_concap_dl_data_req,
43411- &isdn_concap_dl_connect_req,
43412- &isdn_concap_dl_disconn_req
43413+ .data_req = &isdn_concap_dl_data_req,
43414+ .connect_req = &isdn_concap_dl_connect_req,
43415+ .disconn_req = &isdn_concap_dl_disconn_req
43416 };
43417
43418 /* The following should better go into a dedicated source file such that
43419diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43420index 3c5f249..5fac4d0 100644
43421--- a/drivers/isdn/i4l/isdn_tty.c
43422+++ b/drivers/isdn/i4l/isdn_tty.c
43423@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43424
43425 #ifdef ISDN_DEBUG_MODEM_OPEN
43426 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43427- port->count);
43428+ atomic_read(&port->count));
43429 #endif
43430- port->count++;
43431+ atomic_inc(&port->count);
43432 port->tty = tty;
43433 /*
43434 * Start up serial port
43435@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43436 #endif
43437 return;
43438 }
43439- if ((tty->count == 1) && (port->count != 1)) {
43440+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43441 /*
43442 * Uh, oh. tty->count is 1, which means that the tty
43443 * structure will be freed. Info->count should always
43444@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43445 * serial port won't be shutdown.
43446 */
43447 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43448- "info->count is %d\n", port->count);
43449- port->count = 1;
43450+ "info->count is %d\n", atomic_read(&port->count));
43451+ atomic_set(&port->count, 1);
43452 }
43453- if (--port->count < 0) {
43454+ if (atomic_dec_return(&port->count) < 0) {
43455 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43456- info->line, port->count);
43457- port->count = 0;
43458+ info->line, atomic_read(&port->count));
43459+ atomic_set(&port->count, 0);
43460 }
43461- if (port->count) {
43462+ if (atomic_read(&port->count)) {
43463 #ifdef ISDN_DEBUG_MODEM_OPEN
43464 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43465 #endif
43466@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43467 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43468 return;
43469 isdn_tty_shutdown(info);
43470- port->count = 0;
43471+ atomic_set(&port->count, 0);
43472 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43473 port->tty = NULL;
43474 wake_up_interruptible(&port->open_wait);
43475@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43476 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43477 modem_info *info = &dev->mdm.info[i];
43478
43479- if (info->port.count == 0)
43480+ if (atomic_read(&info->port.count) == 0)
43481 continue;
43482 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43483 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43484diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43485index e2d4e58..40cd045 100644
43486--- a/drivers/isdn/i4l/isdn_x25iface.c
43487+++ b/drivers/isdn/i4l/isdn_x25iface.c
43488@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43489
43490
43491 static struct concap_proto_ops ix25_pops = {
43492- &isdn_x25iface_proto_new,
43493- &isdn_x25iface_proto_del,
43494- &isdn_x25iface_proto_restart,
43495- &isdn_x25iface_proto_close,
43496- &isdn_x25iface_xmit,
43497- &isdn_x25iface_receive,
43498- &isdn_x25iface_connect_ind,
43499- &isdn_x25iface_disconn_ind
43500+ .proto_new = &isdn_x25iface_proto_new,
43501+ .proto_del = &isdn_x25iface_proto_del,
43502+ .restart = &isdn_x25iface_proto_restart,
43503+ .close = &isdn_x25iface_proto_close,
43504+ .encap_and_xmit = &isdn_x25iface_xmit,
43505+ .data_ind = &isdn_x25iface_receive,
43506+ .connect_ind = &isdn_x25iface_connect_ind,
43507+ .disconn_ind = &isdn_x25iface_disconn_ind
43508 };
43509
43510 /* error message helper function */
43511diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43512index 6a7447c..cae33fe 100644
43513--- a/drivers/isdn/icn/icn.c
43514+++ b/drivers/isdn/icn/icn.c
43515@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43516 if (count > len)
43517 count = len;
43518 if (user) {
43519- if (copy_from_user(msg, buf, count))
43520+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43521 return -EFAULT;
43522 } else
43523 memcpy(msg, buf, count);
43524diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43525index a4f05c5..1433bc5 100644
43526--- a/drivers/isdn/mISDN/dsp_cmx.c
43527+++ b/drivers/isdn/mISDN/dsp_cmx.c
43528@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43529 static u16 dsp_count; /* last sample count */
43530 static int dsp_count_valid; /* if we have last sample count */
43531
43532-void
43533+void __intentional_overflow(-1)
43534 dsp_cmx_send(void *arg)
43535 {
43536 struct dsp_conf *conf;
43537diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43538index f58a354..fbae176 100644
43539--- a/drivers/leds/leds-clevo-mail.c
43540+++ b/drivers/leds/leds-clevo-mail.c
43541@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43542 * detected as working, but in reality it is not) as low as
43543 * possible.
43544 */
43545-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43546+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43547 {
43548 .callback = clevo_mail_led_dmi_callback,
43549 .ident = "Clevo D410J",
43550diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43551index 2eb3ef6..295891f 100644
43552--- a/drivers/leds/leds-ss4200.c
43553+++ b/drivers/leds/leds-ss4200.c
43554@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43555 * detected as working, but in reality it is not) as low as
43556 * possible.
43557 */
43558-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43559+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43560 {
43561 .callback = ss4200_led_dmi_callback,
43562 .ident = "Intel SS4200-E",
43563diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43564index 0bf1e4e..b4bf44e 100644
43565--- a/drivers/lguest/core.c
43566+++ b/drivers/lguest/core.c
43567@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43568 * The end address needs +1 because __get_vm_area allocates an
43569 * extra guard page, so we need space for that.
43570 */
43571+
43572+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43573+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43574+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43575+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43576+#else
43577 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43578 VM_ALLOC, switcher_addr, switcher_addr
43579 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43580+#endif
43581+
43582 if (!switcher_vma) {
43583 err = -ENOMEM;
43584 printk("lguest: could not map switcher pages high\n");
43585@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43586 * Now the Switcher is mapped at the right address, we can't fail!
43587 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43588 */
43589- memcpy(switcher_vma->addr, start_switcher_text,
43590+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43591 end_switcher_text - start_switcher_text);
43592
43593 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43594diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43595index e8b55c3..3514c37 100644
43596--- a/drivers/lguest/page_tables.c
43597+++ b/drivers/lguest/page_tables.c
43598@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43599 /*:*/
43600
43601 #ifdef CONFIG_X86_PAE
43602-static void release_pmd(pmd_t *spmd)
43603+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43604 {
43605 /* If the entry's not present, there's nothing to release. */
43606 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43607diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43608index 922a1ac..9dd0c2a 100644
43609--- a/drivers/lguest/x86/core.c
43610+++ b/drivers/lguest/x86/core.c
43611@@ -59,7 +59,7 @@ static struct {
43612 /* Offset from where switcher.S was compiled to where we've copied it */
43613 static unsigned long switcher_offset(void)
43614 {
43615- return switcher_addr - (unsigned long)start_switcher_text;
43616+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43617 }
43618
43619 /* This cpu's struct lguest_pages (after the Switcher text page) */
43620@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43621 * These copies are pretty cheap, so we do them unconditionally: */
43622 /* Save the current Host top-level page directory.
43623 */
43624+
43625+#ifdef CONFIG_PAX_PER_CPU_PGD
43626+ pages->state.host_cr3 = read_cr3();
43627+#else
43628 pages->state.host_cr3 = __pa(current->mm->pgd);
43629+#endif
43630+
43631 /*
43632 * Set up the Guest's page tables to see this CPU's pages (and no
43633 * other CPU's pages).
43634@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43635 * compiled-in switcher code and the high-mapped copy we just made.
43636 */
43637 for (i = 0; i < IDT_ENTRIES; i++)
43638- default_idt_entries[i] += switcher_offset();
43639+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43640
43641 /*
43642 * Set up the Switcher's per-cpu areas.
43643@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43644 * it will be undisturbed when we switch. To change %cs and jump we
43645 * need this structure to feed to Intel's "lcall" instruction.
43646 */
43647- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43648+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43649 lguest_entry.segment = LGUEST_CS;
43650
43651 /*
43652diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43653index 40634b0..4f5855e 100644
43654--- a/drivers/lguest/x86/switcher_32.S
43655+++ b/drivers/lguest/x86/switcher_32.S
43656@@ -87,6 +87,7 @@
43657 #include <asm/page.h>
43658 #include <asm/segment.h>
43659 #include <asm/lguest.h>
43660+#include <asm/processor-flags.h>
43661
43662 // We mark the start of the code to copy
43663 // It's placed in .text tho it's never run here
43664@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43665 // Changes type when we load it: damn Intel!
43666 // For after we switch over our page tables
43667 // That entry will be read-only: we'd crash.
43668+
43669+#ifdef CONFIG_PAX_KERNEXEC
43670+ mov %cr0, %edx
43671+ xor $X86_CR0_WP, %edx
43672+ mov %edx, %cr0
43673+#endif
43674+
43675 movl $(GDT_ENTRY_TSS*8), %edx
43676 ltr %dx
43677
43678@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43679 // Let's clear it again for our return.
43680 // The GDT descriptor of the Host
43681 // Points to the table after two "size" bytes
43682- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43683+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43684 // Clear "used" from type field (byte 5, bit 2)
43685- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43686+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43687+
43688+#ifdef CONFIG_PAX_KERNEXEC
43689+ mov %cr0, %eax
43690+ xor $X86_CR0_WP, %eax
43691+ mov %eax, %cr0
43692+#endif
43693
43694 // Once our page table's switched, the Guest is live!
43695 // The Host fades as we run this final step.
43696@@ -295,13 +309,12 @@ deliver_to_host:
43697 // I consulted gcc, and it gave
43698 // These instructions, which I gladly credit:
43699 leal (%edx,%ebx,8), %eax
43700- movzwl (%eax),%edx
43701- movl 4(%eax), %eax
43702- xorw %ax, %ax
43703- orl %eax, %edx
43704+ movl 4(%eax), %edx
43705+ movw (%eax), %dx
43706 // Now the address of the handler's in %edx
43707 // We call it now: its "iret" drops us home.
43708- jmp *%edx
43709+ ljmp $__KERNEL_CS, $1f
43710+1: jmp *%edx
43711
43712 // Every interrupt can come to us here
43713 // But we must truly tell each apart.
43714diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43715index 7ef7461..5a09dac 100644
43716--- a/drivers/md/bcache/closure.h
43717+++ b/drivers/md/bcache/closure.h
43718@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43719 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43720 struct workqueue_struct *wq)
43721 {
43722- BUG_ON(object_is_on_stack(cl));
43723+ BUG_ON(object_starts_on_stack(cl));
43724 closure_set_ip(cl);
43725 cl->fn = fn;
43726 cl->wq = wq;
43727diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43728index 9a8e66a..10cc762 100644
43729--- a/drivers/md/bitmap.c
43730+++ b/drivers/md/bitmap.c
43731@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43732 chunk_kb ? "KB" : "B");
43733 if (bitmap->storage.file) {
43734 seq_printf(seq, ", file: ");
43735- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43736+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43737 }
43738
43739 seq_printf(seq, "\n");
43740diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43741index 5152142..623d141 100644
43742--- a/drivers/md/dm-ioctl.c
43743+++ b/drivers/md/dm-ioctl.c
43744@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43745 cmd == DM_LIST_VERSIONS_CMD)
43746 return 0;
43747
43748- if ((cmd == DM_DEV_CREATE_CMD)) {
43749+ if (cmd == DM_DEV_CREATE_CMD) {
43750 if (!*param->name) {
43751 DMWARN("name not supplied when creating device");
43752 return -EINVAL;
43753diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43754index 7dfdb5c..4caada6 100644
43755--- a/drivers/md/dm-raid1.c
43756+++ b/drivers/md/dm-raid1.c
43757@@ -40,7 +40,7 @@ enum dm_raid1_error {
43758
43759 struct mirror {
43760 struct mirror_set *ms;
43761- atomic_t error_count;
43762+ atomic_unchecked_t error_count;
43763 unsigned long error_type;
43764 struct dm_dev *dev;
43765 sector_t offset;
43766@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43767 struct mirror *m;
43768
43769 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43770- if (!atomic_read(&m->error_count))
43771+ if (!atomic_read_unchecked(&m->error_count))
43772 return m;
43773
43774 return NULL;
43775@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43776 * simple way to tell if a device has encountered
43777 * errors.
43778 */
43779- atomic_inc(&m->error_count);
43780+ atomic_inc_unchecked(&m->error_count);
43781
43782 if (test_and_set_bit(error_type, &m->error_type))
43783 return;
43784@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43785 struct mirror *m = get_default_mirror(ms);
43786
43787 do {
43788- if (likely(!atomic_read(&m->error_count)))
43789+ if (likely(!atomic_read_unchecked(&m->error_count)))
43790 return m;
43791
43792 if (m-- == ms->mirror)
43793@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43794 {
43795 struct mirror *default_mirror = get_default_mirror(m->ms);
43796
43797- return !atomic_read(&default_mirror->error_count);
43798+ return !atomic_read_unchecked(&default_mirror->error_count);
43799 }
43800
43801 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43802@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43803 */
43804 if (likely(region_in_sync(ms, region, 1)))
43805 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43806- else if (m && atomic_read(&m->error_count))
43807+ else if (m && atomic_read_unchecked(&m->error_count))
43808 m = NULL;
43809
43810 if (likely(m))
43811@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43812 }
43813
43814 ms->mirror[mirror].ms = ms;
43815- atomic_set(&(ms->mirror[mirror].error_count), 0);
43816+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43817 ms->mirror[mirror].error_type = 0;
43818 ms->mirror[mirror].offset = offset;
43819
43820@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43821 */
43822 static char device_status_char(struct mirror *m)
43823 {
43824- if (!atomic_read(&(m->error_count)))
43825+ if (!atomic_read_unchecked(&(m->error_count)))
43826 return 'A';
43827
43828 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43829diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43830index 28a9012..9c0f6a5 100644
43831--- a/drivers/md/dm-stats.c
43832+++ b/drivers/md/dm-stats.c
43833@@ -382,7 +382,7 @@ do_sync_free:
43834 synchronize_rcu_expedited();
43835 dm_stat_free(&s->rcu_head);
43836 } else {
43837- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43838+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43839 call_rcu(&s->rcu_head, dm_stat_free);
43840 }
43841 return 0;
43842@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43843 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43844 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43845 ));
43846- ACCESS_ONCE(last->last_sector) = end_sector;
43847- ACCESS_ONCE(last->last_rw) = bi_rw;
43848+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43849+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43850 }
43851
43852 rcu_read_lock();
43853diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43854index d1600d2..4c3af3a 100644
43855--- a/drivers/md/dm-stripe.c
43856+++ b/drivers/md/dm-stripe.c
43857@@ -21,7 +21,7 @@ struct stripe {
43858 struct dm_dev *dev;
43859 sector_t physical_start;
43860
43861- atomic_t error_count;
43862+ atomic_unchecked_t error_count;
43863 };
43864
43865 struct stripe_c {
43866@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43867 kfree(sc);
43868 return r;
43869 }
43870- atomic_set(&(sc->stripe[i].error_count), 0);
43871+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43872 }
43873
43874 ti->private = sc;
43875@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43876 DMEMIT("%d ", sc->stripes);
43877 for (i = 0; i < sc->stripes; i++) {
43878 DMEMIT("%s ", sc->stripe[i].dev->name);
43879- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43880+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43881 'D' : 'A';
43882 }
43883 buffer[i] = '\0';
43884@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43885 */
43886 for (i = 0; i < sc->stripes; i++)
43887 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43888- atomic_inc(&(sc->stripe[i].error_count));
43889- if (atomic_read(&(sc->stripe[i].error_count)) <
43890+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43891+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43892 DM_IO_ERROR_THRESHOLD)
43893 schedule_work(&sc->trigger_event);
43894 }
43895diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43896index 50601ec..6d3b9dc 100644
43897--- a/drivers/md/dm-table.c
43898+++ b/drivers/md/dm-table.c
43899@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43900 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43901 struct mapped_device *md)
43902 {
43903- static char *_claim_ptr = "I belong to device-mapper";
43904+ static char _claim_ptr[] = "I belong to device-mapper";
43905 struct block_device *bdev;
43906
43907 int r;
43908@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43909 if (!dev_size)
43910 return 0;
43911
43912- if ((start >= dev_size) || (start + len > dev_size)) {
43913+ if ((start >= dev_size) || (len > dev_size - start)) {
43914 DMWARN("%s: %s too small for target: "
43915 "start=%llu, len=%llu, dev_size=%llu",
43916 dm_device_name(ti->table->md), bdevname(bdev, b),
43917diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43918index e9d33ad..dae9880d 100644
43919--- a/drivers/md/dm-thin-metadata.c
43920+++ b/drivers/md/dm-thin-metadata.c
43921@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43922 {
43923 pmd->info.tm = pmd->tm;
43924 pmd->info.levels = 2;
43925- pmd->info.value_type.context = pmd->data_sm;
43926+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43927 pmd->info.value_type.size = sizeof(__le64);
43928 pmd->info.value_type.inc = data_block_inc;
43929 pmd->info.value_type.dec = data_block_dec;
43930@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43931
43932 pmd->bl_info.tm = pmd->tm;
43933 pmd->bl_info.levels = 1;
43934- pmd->bl_info.value_type.context = pmd->data_sm;
43935+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43936 pmd->bl_info.value_type.size = sizeof(__le64);
43937 pmd->bl_info.value_type.inc = data_block_inc;
43938 pmd->bl_info.value_type.dec = data_block_dec;
43939diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43940index 490ac23..b9790cd 100644
43941--- a/drivers/md/dm.c
43942+++ b/drivers/md/dm.c
43943@@ -180,9 +180,9 @@ struct mapped_device {
43944 /*
43945 * Event handling.
43946 */
43947- atomic_t event_nr;
43948+ atomic_unchecked_t event_nr;
43949 wait_queue_head_t eventq;
43950- atomic_t uevent_seq;
43951+ atomic_unchecked_t uevent_seq;
43952 struct list_head uevent_list;
43953 spinlock_t uevent_lock; /* Protect access to uevent_list */
43954
43955@@ -1895,8 +1895,8 @@ static struct mapped_device *alloc_dev(int minor)
43956 spin_lock_init(&md->deferred_lock);
43957 atomic_set(&md->holders, 1);
43958 atomic_set(&md->open_count, 0);
43959- atomic_set(&md->event_nr, 0);
43960- atomic_set(&md->uevent_seq, 0);
43961+ atomic_set_unchecked(&md->event_nr, 0);
43962+ atomic_set_unchecked(&md->uevent_seq, 0);
43963 INIT_LIST_HEAD(&md->uevent_list);
43964 spin_lock_init(&md->uevent_lock);
43965
43966@@ -2050,7 +2050,7 @@ static void event_callback(void *context)
43967
43968 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43969
43970- atomic_inc(&md->event_nr);
43971+ atomic_inc_unchecked(&md->event_nr);
43972 wake_up(&md->eventq);
43973 }
43974
43975@@ -2743,18 +2743,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43976
43977 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43978 {
43979- return atomic_add_return(1, &md->uevent_seq);
43980+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43981 }
43982
43983 uint32_t dm_get_event_nr(struct mapped_device *md)
43984 {
43985- return atomic_read(&md->event_nr);
43986+ return atomic_read_unchecked(&md->event_nr);
43987 }
43988
43989 int dm_wait_event(struct mapped_device *md, int event_nr)
43990 {
43991 return wait_event_interruptible(md->eventq,
43992- (event_nr != atomic_read(&md->event_nr)));
43993+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43994 }
43995
43996 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43997diff --git a/drivers/md/md.c b/drivers/md/md.c
43998index 9a18209..ec4d3ec 100644
43999--- a/drivers/md/md.c
44000+++ b/drivers/md/md.c
44001@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44002 * start build, activate spare
44003 */
44004 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44005-static atomic_t md_event_count;
44006+static atomic_unchecked_t md_event_count;
44007 void md_new_event(struct mddev *mddev)
44008 {
44009- atomic_inc(&md_event_count);
44010+ atomic_inc_unchecked(&md_event_count);
44011 wake_up(&md_event_waiters);
44012 }
44013 EXPORT_SYMBOL_GPL(md_new_event);
44014@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44015 */
44016 static void md_new_event_inintr(struct mddev *mddev)
44017 {
44018- atomic_inc(&md_event_count);
44019+ atomic_inc_unchecked(&md_event_count);
44020 wake_up(&md_event_waiters);
44021 }
44022
44023@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44024 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44025 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44026 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44027- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44028+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44029
44030 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44031 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44032@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44033 else
44034 sb->resync_offset = cpu_to_le64(0);
44035
44036- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44037+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44038
44039 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44040 sb->size = cpu_to_le64(mddev->dev_sectors);
44041@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44042 static ssize_t
44043 errors_show(struct md_rdev *rdev, char *page)
44044 {
44045- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44046+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44047 }
44048
44049 static ssize_t
44050@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44051 char *e;
44052 unsigned long n = simple_strtoul(buf, &e, 10);
44053 if (*buf && (*e == 0 || *e == '\n')) {
44054- atomic_set(&rdev->corrected_errors, n);
44055+ atomic_set_unchecked(&rdev->corrected_errors, n);
44056 return len;
44057 }
44058 return -EINVAL;
44059@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44060 rdev->sb_loaded = 0;
44061 rdev->bb_page = NULL;
44062 atomic_set(&rdev->nr_pending, 0);
44063- atomic_set(&rdev->read_errors, 0);
44064- atomic_set(&rdev->corrected_errors, 0);
44065+ atomic_set_unchecked(&rdev->read_errors, 0);
44066+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44067
44068 INIT_LIST_HEAD(&rdev->same_set);
44069 init_waitqueue_head(&rdev->blocked_wait);
44070@@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44071
44072 spin_unlock(&pers_lock);
44073 seq_printf(seq, "\n");
44074- seq->poll_event = atomic_read(&md_event_count);
44075+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44076 return 0;
44077 }
44078 if (v == (void*)2) {
44079@@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44080 return error;
44081
44082 seq = file->private_data;
44083- seq->poll_event = atomic_read(&md_event_count);
44084+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44085 return error;
44086 }
44087
44088@@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44089 /* always allow read */
44090 mask = POLLIN | POLLRDNORM;
44091
44092- if (seq->poll_event != atomic_read(&md_event_count))
44093+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44094 mask |= POLLERR | POLLPRI;
44095 return mask;
44096 }
44097@@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44098 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44099 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44100 (int)part_stat_read(&disk->part0, sectors[1]) -
44101- atomic_read(&disk->sync_io);
44102+ atomic_read_unchecked(&disk->sync_io);
44103 /* sync IO will cause sync_io to increase before the disk_stats
44104 * as sync_io is counted when a request starts, and
44105 * disk_stats is counted when it completes.
44106diff --git a/drivers/md/md.h b/drivers/md/md.h
44107index a49d991..3582bb7 100644
44108--- a/drivers/md/md.h
44109+++ b/drivers/md/md.h
44110@@ -94,13 +94,13 @@ struct md_rdev {
44111 * only maintained for arrays that
44112 * support hot removal
44113 */
44114- atomic_t read_errors; /* number of consecutive read errors that
44115+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44116 * we have tried to ignore.
44117 */
44118 struct timespec last_read_error; /* monotonic time since our
44119 * last read error
44120 */
44121- atomic_t corrected_errors; /* number of corrected read errors,
44122+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44123 * for reporting to userspace and storing
44124 * in superblock.
44125 */
44126@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44127
44128 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44129 {
44130- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44131+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44132 }
44133
44134 struct md_personality
44135diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44136index 786b689..ea8c956 100644
44137--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44138+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44139@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44140 * Flick into a mode where all blocks get allocated in the new area.
44141 */
44142 smm->begin = old_len;
44143- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44144+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44145
44146 /*
44147 * Extend.
44148@@ -710,7 +710,7 @@ out:
44149 /*
44150 * Switch back to normal behaviour.
44151 */
44152- memcpy(sm, &ops, sizeof(*sm));
44153+ memcpy((void *)sm, &ops, sizeof(*sm));
44154 return r;
44155 }
44156
44157diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44158index 3e6d115..ffecdeb 100644
44159--- a/drivers/md/persistent-data/dm-space-map.h
44160+++ b/drivers/md/persistent-data/dm-space-map.h
44161@@ -71,6 +71,7 @@ struct dm_space_map {
44162 dm_sm_threshold_fn fn,
44163 void *context);
44164 };
44165+typedef struct dm_space_map __no_const dm_space_map_no_const;
44166
44167 /*----------------------------------------------------------------*/
44168
44169diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44170index 56e24c0..e1c8e1f 100644
44171--- a/drivers/md/raid1.c
44172+++ b/drivers/md/raid1.c
44173@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44174 if (r1_sync_page_io(rdev, sect, s,
44175 bio->bi_io_vec[idx].bv_page,
44176 READ) != 0)
44177- atomic_add(s, &rdev->corrected_errors);
44178+ atomic_add_unchecked(s, &rdev->corrected_errors);
44179 }
44180 sectors -= s;
44181 sect += s;
44182@@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44183 test_bit(In_sync, &rdev->flags)) {
44184 if (r1_sync_page_io(rdev, sect, s,
44185 conf->tmppage, READ)) {
44186- atomic_add(s, &rdev->corrected_errors);
44187+ atomic_add_unchecked(s, &rdev->corrected_errors);
44188 printk(KERN_INFO
44189 "md/raid1:%s: read error corrected "
44190 "(%d sectors at %llu on %s)\n",
44191diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44192index cb882aa..cb8aeca 100644
44193--- a/drivers/md/raid10.c
44194+++ b/drivers/md/raid10.c
44195@@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44196 /* The write handler will notice the lack of
44197 * R10BIO_Uptodate and record any errors etc
44198 */
44199- atomic_add(r10_bio->sectors,
44200+ atomic_add_unchecked(r10_bio->sectors,
44201 &conf->mirrors[d].rdev->corrected_errors);
44202
44203 /* for reconstruct, we always reschedule after a read.
44204@@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44205 {
44206 struct timespec cur_time_mon;
44207 unsigned long hours_since_last;
44208- unsigned int read_errors = atomic_read(&rdev->read_errors);
44209+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44210
44211 ktime_get_ts(&cur_time_mon);
44212
44213@@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44214 * overflowing the shift of read_errors by hours_since_last.
44215 */
44216 if (hours_since_last >= 8 * sizeof(read_errors))
44217- atomic_set(&rdev->read_errors, 0);
44218+ atomic_set_unchecked(&rdev->read_errors, 0);
44219 else
44220- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44221+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44222 }
44223
44224 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44225@@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44226 return;
44227
44228 check_decay_read_errors(mddev, rdev);
44229- atomic_inc(&rdev->read_errors);
44230- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44231+ atomic_inc_unchecked(&rdev->read_errors);
44232+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44233 char b[BDEVNAME_SIZE];
44234 bdevname(rdev->bdev, b);
44235
44236@@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44237 "md/raid10:%s: %s: Raid device exceeded "
44238 "read_error threshold [cur %d:max %d]\n",
44239 mdname(mddev), b,
44240- atomic_read(&rdev->read_errors), max_read_errors);
44241+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44242 printk(KERN_NOTICE
44243 "md/raid10:%s: %s: Failing raid device\n",
44244 mdname(mddev), b);
44245@@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44246 sect +
44247 choose_data_offset(r10_bio, rdev)),
44248 bdevname(rdev->bdev, b));
44249- atomic_add(s, &rdev->corrected_errors);
44250+ atomic_add_unchecked(s, &rdev->corrected_errors);
44251 }
44252
44253 rdev_dec_pending(rdev, mddev);
44254@@ -2954,6 +2954,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
44255 */
44256 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
44257 end_reshape(conf);
44258+ close_sync(conf);
44259 return 0;
44260 }
44261
44262@@ -4411,7 +4412,7 @@ read_more:
44263 read_bio->bi_private = r10_bio;
44264 read_bio->bi_end_io = end_sync_read;
44265 read_bio->bi_rw = READ;
44266- read_bio->bi_flags &= ~(BIO_POOL_MASK - 1);
44267+ read_bio->bi_flags &= (~0UL << BIO_RESET_BITS);
44268 read_bio->bi_flags |= 1 << BIO_UPTODATE;
44269 read_bio->bi_vcnt = 0;
44270 read_bio->bi_iter.bi_size = 0;
44271diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44272index ad1b9be..c6316b5 100644
44273--- a/drivers/md/raid5.c
44274+++ b/drivers/md/raid5.c
44275@@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44276 return 1;
44277 }
44278
44279+#ifdef CONFIG_GRKERNSEC_HIDESYM
44280+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44281+#endif
44282+
44283 static int grow_stripes(struct r5conf *conf, int num)
44284 {
44285 struct kmem_cache *sc;
44286@@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44287 "raid%d-%s", conf->level, mdname(conf->mddev));
44288 else
44289 sprintf(conf->cache_name[0],
44290+#ifdef CONFIG_GRKERNSEC_HIDESYM
44291+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44292+#else
44293 "raid%d-%p", conf->level, conf->mddev);
44294+#endif
44295 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44296
44297 conf->active_name = 0;
44298@@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44299 mdname(conf->mddev), STRIPE_SECTORS,
44300 (unsigned long long)s,
44301 bdevname(rdev->bdev, b));
44302- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44303+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44304 clear_bit(R5_ReadError, &sh->dev[i].flags);
44305 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44306 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44307 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44308
44309- if (atomic_read(&rdev->read_errors))
44310- atomic_set(&rdev->read_errors, 0);
44311+ if (atomic_read_unchecked(&rdev->read_errors))
44312+ atomic_set_unchecked(&rdev->read_errors, 0);
44313 } else {
44314 const char *bdn = bdevname(rdev->bdev, b);
44315 int retry = 0;
44316 int set_bad = 0;
44317
44318 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44319- atomic_inc(&rdev->read_errors);
44320+ atomic_inc_unchecked(&rdev->read_errors);
44321 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44322 printk_ratelimited(
44323 KERN_WARNING
44324@@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44325 mdname(conf->mddev),
44326 (unsigned long long)s,
44327 bdn);
44328- } else if (atomic_read(&rdev->read_errors)
44329+ } else if (atomic_read_unchecked(&rdev->read_errors)
44330 > conf->max_nr_stripes)
44331 printk(KERN_WARNING
44332 "md/raid:%s: Too many read errors, failing device %s.\n",
44333@@ -3774,6 +3782,8 @@ static void handle_stripe(struct stripe_head *sh)
44334 set_bit(R5_Wantwrite, &dev->flags);
44335 if (prexor)
44336 continue;
44337+ if (s.failed > 1)
44338+ continue;
44339 if (!test_bit(R5_Insync, &dev->flags) ||
44340 ((i == sh->pd_idx || i == sh->qd_idx) &&
44341 s.failed == 0))
44342diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44343index 983db75..ef9248c 100644
44344--- a/drivers/media/dvb-core/dvbdev.c
44345+++ b/drivers/media/dvb-core/dvbdev.c
44346@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44347 const struct dvb_device *template, void *priv, int type)
44348 {
44349 struct dvb_device *dvbdev;
44350- struct file_operations *dvbdevfops;
44351+ file_operations_no_const *dvbdevfops;
44352 struct device *clsdev;
44353 int minor;
44354 int id;
44355diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44356index 539f4db..cdd403b 100644
44357--- a/drivers/media/dvb-frontends/af9033.h
44358+++ b/drivers/media/dvb-frontends/af9033.h
44359@@ -82,7 +82,7 @@ struct af9033_ops {
44360 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44361 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44362 int onoff);
44363-};
44364+} __no_const;
44365
44366
44367 #if IS_ENABLED(CONFIG_DVB_AF9033)
44368diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44369index 9b6c3bb..baeb5c7 100644
44370--- a/drivers/media/dvb-frontends/dib3000.h
44371+++ b/drivers/media/dvb-frontends/dib3000.h
44372@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44373 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44374 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44375 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44376-};
44377+} __no_const;
44378
44379 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44380 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44381diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44382index ed8cb90..5ef7f79 100644
44383--- a/drivers/media/pci/cx88/cx88-video.c
44384+++ b/drivers/media/pci/cx88/cx88-video.c
44385@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44386
44387 /* ------------------------------------------------------------------ */
44388
44389-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44390-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44391-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44392+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44393+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44394+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44395
44396 module_param_array(video_nr, int, NULL, 0444);
44397 module_param_array(vbi_nr, int, NULL, 0444);
44398diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44399index 802642d..5534900 100644
44400--- a/drivers/media/pci/ivtv/ivtv-driver.c
44401+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44402@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44403 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44404
44405 /* ivtv instance counter */
44406-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44407+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44408
44409 /* Parameter declarations */
44410 static int cardtype[IVTV_MAX_CARDS];
44411diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44412index 9a726ea..f5e9b52 100644
44413--- a/drivers/media/platform/omap/omap_vout.c
44414+++ b/drivers/media/platform/omap/omap_vout.c
44415@@ -63,7 +63,6 @@ enum omap_vout_channels {
44416 OMAP_VIDEO2,
44417 };
44418
44419-static struct videobuf_queue_ops video_vbq_ops;
44420 /* Variables configurable through module params*/
44421 static u32 video1_numbuffers = 3;
44422 static u32 video2_numbuffers = 3;
44423@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44424 {
44425 struct videobuf_queue *q;
44426 struct omap_vout_device *vout = NULL;
44427+ static struct videobuf_queue_ops video_vbq_ops = {
44428+ .buf_setup = omap_vout_buffer_setup,
44429+ .buf_prepare = omap_vout_buffer_prepare,
44430+ .buf_release = omap_vout_buffer_release,
44431+ .buf_queue = omap_vout_buffer_queue,
44432+ };
44433
44434 vout = video_drvdata(file);
44435 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44436@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44437 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44438
44439 q = &vout->vbq;
44440- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44441- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44442- video_vbq_ops.buf_release = omap_vout_buffer_release;
44443- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44444 spin_lock_init(&vout->vbq_lock);
44445
44446 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44447diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44448index fb2acc5..a2fcbdc4 100644
44449--- a/drivers/media/platform/s5p-tv/mixer.h
44450+++ b/drivers/media/platform/s5p-tv/mixer.h
44451@@ -156,7 +156,7 @@ struct mxr_layer {
44452 /** layer index (unique identifier) */
44453 int idx;
44454 /** callbacks for layer methods */
44455- struct mxr_layer_ops ops;
44456+ struct mxr_layer_ops *ops;
44457 /** format array */
44458 const struct mxr_format **fmt_array;
44459 /** size of format array */
44460diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44461index 74344c7..a39e70e 100644
44462--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44463+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44464@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44465 {
44466 struct mxr_layer *layer;
44467 int ret;
44468- struct mxr_layer_ops ops = {
44469+ static struct mxr_layer_ops ops = {
44470 .release = mxr_graph_layer_release,
44471 .buffer_set = mxr_graph_buffer_set,
44472 .stream_set = mxr_graph_stream_set,
44473diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44474index b713403..53cb5ad 100644
44475--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44476+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44477@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44478 layer->update_buf = next;
44479 }
44480
44481- layer->ops.buffer_set(layer, layer->update_buf);
44482+ layer->ops->buffer_set(layer, layer->update_buf);
44483
44484 if (done && done != layer->shadow_buf)
44485 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44486diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44487index a1ce55f..4a3c4d9 100644
44488--- a/drivers/media/platform/s5p-tv/mixer_video.c
44489+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44490@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44491 layer->geo.src.height = layer->geo.src.full_height;
44492
44493 mxr_geometry_dump(mdev, &layer->geo);
44494- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44495+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44496 mxr_geometry_dump(mdev, &layer->geo);
44497 }
44498
44499@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44500 layer->geo.dst.full_width = mbus_fmt.width;
44501 layer->geo.dst.full_height = mbus_fmt.height;
44502 layer->geo.dst.field = mbus_fmt.field;
44503- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44504+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44505
44506 mxr_geometry_dump(mdev, &layer->geo);
44507 }
44508@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44509 /* set source size to highest accepted value */
44510 geo->src.full_width = max(geo->dst.full_width, pix->width);
44511 geo->src.full_height = max(geo->dst.full_height, pix->height);
44512- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44513+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44514 mxr_geometry_dump(mdev, &layer->geo);
44515 /* set cropping to total visible screen */
44516 geo->src.width = pix->width;
44517@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44518 geo->src.x_offset = 0;
44519 geo->src.y_offset = 0;
44520 /* assure consistency of geometry */
44521- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44522+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44523 mxr_geometry_dump(mdev, &layer->geo);
44524 /* set full size to lowest possible value */
44525 geo->src.full_width = 0;
44526 geo->src.full_height = 0;
44527- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44528+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44529 mxr_geometry_dump(mdev, &layer->geo);
44530
44531 /* returning results */
44532@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44533 target->width = s->r.width;
44534 target->height = s->r.height;
44535
44536- layer->ops.fix_geometry(layer, stage, s->flags);
44537+ layer->ops->fix_geometry(layer, stage, s->flags);
44538
44539 /* retrieve update selection rectangle */
44540 res.left = target->x_offset;
44541@@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44542 mxr_output_get(mdev);
44543
44544 mxr_layer_update_output(layer);
44545- layer->ops.format_set(layer);
44546+ layer->ops->format_set(layer);
44547 /* enabling layer in hardware */
44548 spin_lock_irqsave(&layer->enq_slock, flags);
44549 layer->state = MXR_LAYER_STREAMING;
44550 spin_unlock_irqrestore(&layer->enq_slock, flags);
44551
44552- layer->ops.stream_set(layer, MXR_ENABLE);
44553+ layer->ops->stream_set(layer, MXR_ENABLE);
44554 mxr_streamer_get(mdev);
44555
44556 return 0;
44557@@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44558 spin_unlock_irqrestore(&layer->enq_slock, flags);
44559
44560 /* disabling layer in hardware */
44561- layer->ops.stream_set(layer, MXR_DISABLE);
44562+ layer->ops->stream_set(layer, MXR_DISABLE);
44563 /* remove one streamer */
44564 mxr_streamer_put(mdev);
44565 /* allow changes in output configuration */
44566@@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44567
44568 void mxr_layer_release(struct mxr_layer *layer)
44569 {
44570- if (layer->ops.release)
44571- layer->ops.release(layer);
44572+ if (layer->ops->release)
44573+ layer->ops->release(layer);
44574 }
44575
44576 void mxr_base_layer_release(struct mxr_layer *layer)
44577@@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44578
44579 layer->mdev = mdev;
44580 layer->idx = idx;
44581- layer->ops = *ops;
44582+ layer->ops = ops;
44583
44584 spin_lock_init(&layer->enq_slock);
44585 INIT_LIST_HEAD(&layer->enq_list);
44586diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44587index c9388c4..ce71ece 100644
44588--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44589+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44590@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44591 {
44592 struct mxr_layer *layer;
44593 int ret;
44594- struct mxr_layer_ops ops = {
44595+ static struct mxr_layer_ops ops = {
44596 .release = mxr_vp_layer_release,
44597 .buffer_set = mxr_vp_buffer_set,
44598 .stream_set = mxr_vp_stream_set,
44599diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44600index 3890f4f..b5c7511 100644
44601--- a/drivers/media/platform/vivi.c
44602+++ b/drivers/media/platform/vivi.c
44603@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44604 MODULE_LICENSE("Dual BSD/GPL");
44605 MODULE_VERSION(VIVI_VERSION);
44606
44607-static unsigned video_nr = -1;
44608-module_param(video_nr, uint, 0644);
44609+static int video_nr = -1;
44610+module_param(video_nr, int, 0644);
44611 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44612
44613 static unsigned n_devs = 1;
44614diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44615index d719e59..63f3470 100644
44616--- a/drivers/media/radio/radio-cadet.c
44617+++ b/drivers/media/radio/radio-cadet.c
44618@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44619 unsigned char readbuf[RDS_BUFFER];
44620 int i = 0;
44621
44622+ if (count > RDS_BUFFER)
44623+ return -EFAULT;
44624 mutex_lock(&dev->lock);
44625 if (dev->rdsstat == 0)
44626 cadet_start_rds(dev);
44627@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44628 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44629 mutex_unlock(&dev->lock);
44630
44631- if (i && copy_to_user(data, readbuf, i))
44632- return -EFAULT;
44633+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44634+ i = -EFAULT;
44635+
44636 return i;
44637 }
44638
44639diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44640index 5236035..c622c74 100644
44641--- a/drivers/media/radio/radio-maxiradio.c
44642+++ b/drivers/media/radio/radio-maxiradio.c
44643@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44644 /* TEA5757 pin mappings */
44645 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44646
44647-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44648+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44649
44650 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44651 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44652diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44653index 050b3bb..79f62b9 100644
44654--- a/drivers/media/radio/radio-shark.c
44655+++ b/drivers/media/radio/radio-shark.c
44656@@ -79,7 +79,7 @@ struct shark_device {
44657 u32 last_val;
44658 };
44659
44660-static atomic_t shark_instance = ATOMIC_INIT(0);
44661+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44662
44663 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44664 {
44665diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44666index 8654e0d..0608a64 100644
44667--- a/drivers/media/radio/radio-shark2.c
44668+++ b/drivers/media/radio/radio-shark2.c
44669@@ -74,7 +74,7 @@ struct shark_device {
44670 u8 *transfer_buffer;
44671 };
44672
44673-static atomic_t shark_instance = ATOMIC_INIT(0);
44674+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44675
44676 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44677 {
44678diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44679index 2fd9009..278cc1e 100644
44680--- a/drivers/media/radio/radio-si476x.c
44681+++ b/drivers/media/radio/radio-si476x.c
44682@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44683 struct si476x_radio *radio;
44684 struct v4l2_ctrl *ctrl;
44685
44686- static atomic_t instance = ATOMIC_INIT(0);
44687+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44688
44689 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44690 if (!radio)
44691diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44692index a1c641e..3007da9 100644
44693--- a/drivers/media/usb/dvb-usb/cxusb.c
44694+++ b/drivers/media/usb/dvb-usb/cxusb.c
44695@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44696
44697 struct dib0700_adapter_state {
44698 int (*set_param_save) (struct dvb_frontend *);
44699-};
44700+} __no_const;
44701
44702 static int dib7070_set_param_override(struct dvb_frontend *fe)
44703 {
44704diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44705index 733a7ff..f8b52e3 100644
44706--- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44707+++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44708@@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
44709
44710 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
44711 {
44712- struct hexline hx;
44713- u8 reset;
44714+ struct hexline *hx;
44715+ u8 *reset;
44716 int ret,pos=0;
44717
44718+ reset = kmalloc(1, GFP_KERNEL);
44719+ if (reset == NULL)
44720+ return -ENOMEM;
44721+
44722+ hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
44723+ if (hx == NULL) {
44724+ kfree(reset);
44725+ return -ENOMEM;
44726+ }
44727+
44728 /* stop the CPU */
44729- reset = 1;
44730- if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
44731+ reset[0] = 1;
44732+ if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
44733 err("could not stop the USB controller CPU.");
44734
44735- while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
44736- deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
44737- ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
44738+ while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
44739+ deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
44740+ ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
44741
44742- if (ret != hx.len) {
44743+ if (ret != hx->len) {
44744 err("error while transferring firmware "
44745 "(transferred size: %d, block size: %d)",
44746- ret,hx.len);
44747+ ret,hx->len);
44748 ret = -EINVAL;
44749 break;
44750 }
44751 }
44752 if (ret < 0) {
44753 err("firmware download failed at %d with %d",pos,ret);
44754+ kfree(reset);
44755+ kfree(hx);
44756 return ret;
44757 }
44758
44759 if (ret == 0) {
44760 /* restart the CPU */
44761- reset = 0;
44762- if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
44763+ reset[0] = 0;
44764+ if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
44765 err("could not restart the USB controller CPU.");
44766 ret = -EINVAL;
44767 }
44768 } else
44769 ret = -EIO;
44770
44771+ kfree(reset);
44772+ kfree(hx);
44773+
44774 return ret;
44775 }
44776 EXPORT_SYMBOL(usb_cypress_load_firmware);
44777diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44778index ae0f56a..ec71784 100644
44779--- a/drivers/media/usb/dvb-usb/dw2102.c
44780+++ b/drivers/media/usb/dvb-usb/dw2102.c
44781@@ -118,7 +118,7 @@ struct su3000_state {
44782
44783 struct s6x0_state {
44784 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44785-};
44786+} __no_const;
44787
44788 /* debug */
44789 static int dvb_usb_dw2102_debug;
44790diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
44791index 98d24ae..bc22415 100644
44792--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
44793+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
44794@@ -87,8 +87,11 @@ struct technisat_usb2_state {
44795 static int technisat_usb2_i2c_access(struct usb_device *udev,
44796 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
44797 {
44798- u8 b[64];
44799- int ret, actual_length;
44800+ u8 *b = kmalloc(64, GFP_KERNEL);
44801+ int ret, actual_length, error = 0;
44802+
44803+ if (b == NULL)
44804+ return -ENOMEM;
44805
44806 deb_i2c("i2c-access: %02x, tx: ", device_addr);
44807 debug_dump(tx, txlen, deb_i2c);
44808@@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44809
44810 if (ret < 0) {
44811 err("i2c-error: out failed %02x = %d", device_addr, ret);
44812- return -ENODEV;
44813+ error = -ENODEV;
44814+ goto out;
44815 }
44816
44817 ret = usb_bulk_msg(udev,
44818@@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44819 b, 64, &actual_length, 1000);
44820 if (ret < 0) {
44821 err("i2c-error: in failed %02x = %d", device_addr, ret);
44822- return -ENODEV;
44823+ error = -ENODEV;
44824+ goto out;
44825 }
44826
44827 if (b[0] != I2C_STATUS_OK) {
44828@@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44829 /* handle tuner-i2c-nak */
44830 if (!(b[0] == I2C_STATUS_NAK &&
44831 device_addr == 0x60
44832- /* && device_is_technisat_usb2 */))
44833- return -ENODEV;
44834+ /* && device_is_technisat_usb2 */)) {
44835+ error = -ENODEV;
44836+ goto out;
44837+ }
44838 }
44839
44840 deb_i2c("status: %d, ", b[0]);
44841@@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44842
44843 deb_i2c("\n");
44844
44845- return 0;
44846+out:
44847+ kfree(b);
44848+ return error;
44849 }
44850
44851 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
44852@@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44853 {
44854 int ret;
44855
44856- u8 led[8] = {
44857- red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44858- 0
44859- };
44860+ u8 *led = kzalloc(8, GFP_KERNEL);
44861+
44862+ if (led == NULL)
44863+ return -ENOMEM;
44864
44865 if (disable_led_control && state != LED_OFF)
44866 return 0;
44867
44868+ led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
44869+
44870 switch (state) {
44871 case LED_ON:
44872 led[1] = 0x82;
44873@@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44874 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44875 USB_TYPE_VENDOR | USB_DIR_OUT,
44876 0, 0,
44877- led, sizeof(led), 500);
44878+ led, 8, 500);
44879
44880 mutex_unlock(&d->i2c_mutex);
44881+
44882+ kfree(led);
44883+
44884 return ret;
44885 }
44886
44887 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
44888 {
44889 int ret;
44890- u8 b = 0;
44891+ u8 *b = kzalloc(1, GFP_KERNEL);
44892+
44893+ if (b == NULL)
44894+ return -ENOMEM;
44895
44896 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
44897 return -EAGAIN;
44898@@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
44899 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
44900 USB_TYPE_VENDOR | USB_DIR_OUT,
44901 (red << 8) | green, 0,
44902- &b, 1, 500);
44903+ b, 1, 500);
44904
44905 mutex_unlock(&d->i2c_mutex);
44906
44907+ kfree(b);
44908+
44909 return ret;
44910 }
44911
44912@@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44913 struct dvb_usb_device_description **desc, int *cold)
44914 {
44915 int ret;
44916- u8 version[3];
44917+ u8 *version = kmalloc(3, GFP_KERNEL);
44918
44919 /* first select the interface */
44920 if (usb_set_interface(udev, 0, 1) != 0)
44921@@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44922
44923 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
44924
44925+ if (version == NULL)
44926+ return 0;
44927+
44928 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
44929 GET_VERSION_INFO_VENDOR_REQUEST,
44930 USB_TYPE_VENDOR | USB_DIR_IN,
44931 0, 0,
44932- version, sizeof(version), 500);
44933+ version, 3, 500);
44934
44935 if (ret < 0)
44936 *cold = 1;
44937@@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44938 *cold = 0;
44939 }
44940
44941+ kfree(version);
44942+
44943 return 0;
44944 }
44945
44946@@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
44947
44948 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
44949 {
44950- u8 buf[62], *b;
44951+ u8 *buf, *b;
44952 int ret;
44953 struct ir_raw_event ev;
44954
44955+ buf = kmalloc(62, GFP_KERNEL);
44956+
44957+ if (buf == NULL)
44958+ return -ENOMEM;
44959+
44960 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
44961 buf[1] = 0x08;
44962 buf[2] = 0x8f;
44963@@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
44964 GET_IR_DATA_VENDOR_REQUEST,
44965 USB_TYPE_VENDOR | USB_DIR_IN,
44966 0x8080, 0,
44967- buf, sizeof(buf), 500);
44968+ buf, 62, 500);
44969
44970 unlock:
44971 mutex_unlock(&d->i2c_mutex);
44972
44973- if (ret < 0)
44974+ if (ret < 0) {
44975+ kfree(buf);
44976 return ret;
44977+ }
44978
44979- if (ret == 1)
44980+ if (ret == 1) {
44981+ kfree(buf);
44982 return 0; /* no key pressed */
44983+ }
44984
44985 /* decoding */
44986 b = buf+1;
44987@@ -653,6 +686,8 @@ unlock:
44988
44989 ir_raw_event_handle(d->rc_dev);
44990
44991+ kfree(buf);
44992+
44993 return 1;
44994 }
44995
44996diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44997index 7e2411c..cef73ca 100644
44998--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44999+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45000@@ -328,7 +328,7 @@ struct v4l2_buffer32 {
45001 __u32 reserved;
45002 };
45003
45004-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45005+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45006 enum v4l2_memory memory)
45007 {
45008 void __user *up_pln;
45009@@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45010 return 0;
45011 }
45012
45013-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45014+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45015 enum v4l2_memory memory)
45016 {
45017 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
45018@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45019 * by passing a very big num_planes value */
45020 uplane = compat_alloc_user_space(num_planes *
45021 sizeof(struct v4l2_plane));
45022- kp->m.planes = uplane;
45023+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
45024
45025 while (--num_planes >= 0) {
45026 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45027@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45028 if (num_planes == 0)
45029 return 0;
45030
45031- uplane = kp->m.planes;
45032+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45033 if (get_user(p, &up->m.planes))
45034 return -EFAULT;
45035 uplane32 = compat_ptr(p);
45036@@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45037 get_user(kp->capability, &up->capability) ||
45038 get_user(kp->flags, &up->flags))
45039 return -EFAULT;
45040- kp->base = compat_ptr(tmp);
45041+ kp->base = (void __force_kernel *)compat_ptr(tmp);
45042 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45043 return 0;
45044 }
45045@@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45046 n * sizeof(struct v4l2_ext_control32)))
45047 return -EFAULT;
45048 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45049- kp->controls = kcontrols;
45050+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45051 while (--n >= 0) {
45052 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45053 return -EFAULT;
45054@@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45055 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45056 {
45057 struct v4l2_ext_control32 __user *ucontrols;
45058- struct v4l2_ext_control __user *kcontrols = kp->controls;
45059+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45060 int n = kp->count;
45061 compat_caddr_t p;
45062
45063@@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
45064 put_user(kp->start_block, &up->start_block) ||
45065 put_user(kp->blocks, &up->blocks) ||
45066 put_user(tmp, &up->edid) ||
45067- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45068+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45069 return -EFAULT;
45070 return 0;
45071 }
45072diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45073index 55c6832..a91c7a6 100644
45074--- a/drivers/media/v4l2-core/v4l2-ctrls.c
45075+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45076@@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45077 return 0;
45078
45079 case V4L2_CTRL_TYPE_STRING:
45080- len = strlen(c->string);
45081- if (len < ctrl->minimum)
45082+ len = strlen_user(c->string);
45083+ if (!len || len < ctrl->minimum)
45084 return -ERANGE;
45085 if ((len - ctrl->minimum) % ctrl->step)
45086 return -ERANGE;
45087diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45088index 02d1b63..5fd6b16 100644
45089--- a/drivers/media/v4l2-core/v4l2-device.c
45090+++ b/drivers/media/v4l2-core/v4l2-device.c
45091@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45092 EXPORT_SYMBOL_GPL(v4l2_device_put);
45093
45094 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45095- atomic_t *instance)
45096+ atomic_unchecked_t *instance)
45097 {
45098- int num = atomic_inc_return(instance) - 1;
45099+ int num = atomic_inc_return_unchecked(instance) - 1;
45100 int len = strlen(basename);
45101
45102 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45103diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45104index d9113cc..7de6ccc 100644
45105--- a/drivers/media/v4l2-core/v4l2-ioctl.c
45106+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45107@@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
45108 struct file *file, void *fh, void *p);
45109 } u;
45110 void (*debug)(const void *arg, bool write_only);
45111-};
45112+} __do_const;
45113+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45114
45115 /* This control needs a priority check */
45116 #define INFO_FL_PRIO (1 << 0)
45117@@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
45118 struct video_device *vfd = video_devdata(file);
45119 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45120 bool write_only = false;
45121- struct v4l2_ioctl_info default_info;
45122+ v4l2_ioctl_info_no_const default_info;
45123 const struct v4l2_ioctl_info *info;
45124 void *fh = file->private_data;
45125 struct v4l2_fh *vfh = NULL;
45126@@ -2260,7 +2261,7 @@ done:
45127 }
45128
45129 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45130- void * __user *user_ptr, void ***kernel_ptr)
45131+ void __user **user_ptr, void ***kernel_ptr)
45132 {
45133 int ret = 0;
45134
45135@@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45136 ret = -EINVAL;
45137 break;
45138 }
45139- *user_ptr = (void __user *)buf->m.planes;
45140+ *user_ptr = (void __force_user *)buf->m.planes;
45141 *kernel_ptr = (void *)&buf->m.planes;
45142 *array_size = sizeof(struct v4l2_plane) * buf->length;
45143 ret = 1;
45144@@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45145 ret = -EINVAL;
45146 break;
45147 }
45148- *user_ptr = (void __user *)ctrls->controls;
45149+ *user_ptr = (void __force_user *)ctrls->controls;
45150 *kernel_ptr = (void *)&ctrls->controls;
45151 *array_size = sizeof(struct v4l2_ext_control)
45152 * ctrls->count;
45153@@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45154 }
45155
45156 if (has_array_args) {
45157- *kernel_ptr = user_ptr;
45158+ *kernel_ptr = (void __force_kernel *)user_ptr;
45159 if (copy_to_user(user_ptr, mbuf, array_size))
45160 err = -EFAULT;
45161 goto out_array_args;
45162diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45163index 570b18a..f880314 100644
45164--- a/drivers/message/fusion/mptbase.c
45165+++ b/drivers/message/fusion/mptbase.c
45166@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45167 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45168 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45169
45170+#ifdef CONFIG_GRKERNSEC_HIDESYM
45171+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45172+#else
45173 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45174 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45175+#endif
45176+
45177 /*
45178 * Rounding UP to nearest 4-kB boundary here...
45179 */
45180@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45181 ioc->facts.GlobalCredits);
45182
45183 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45184+#ifdef CONFIG_GRKERNSEC_HIDESYM
45185+ NULL, NULL);
45186+#else
45187 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45188+#endif
45189 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45190 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45191 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45192diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45193index 00d339c..2ea899d 100644
45194--- a/drivers/message/fusion/mptsas.c
45195+++ b/drivers/message/fusion/mptsas.c
45196@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45197 return 0;
45198 }
45199
45200+static inline void
45201+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45202+{
45203+ if (phy_info->port_details) {
45204+ phy_info->port_details->rphy = rphy;
45205+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45206+ ioc->name, rphy));
45207+ }
45208+
45209+ if (rphy) {
45210+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45211+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45212+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45213+ ioc->name, rphy, rphy->dev.release));
45214+ }
45215+}
45216+
45217 /* no mutex */
45218 static void
45219 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45220@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45221 return NULL;
45222 }
45223
45224-static inline void
45225-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45226-{
45227- if (phy_info->port_details) {
45228- phy_info->port_details->rphy = rphy;
45229- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45230- ioc->name, rphy));
45231- }
45232-
45233- if (rphy) {
45234- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45235- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45236- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45237- ioc->name, rphy, rphy->dev.release));
45238- }
45239-}
45240-
45241 static inline struct sas_port *
45242 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45243 {
45244diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45245index 727819c..ad74694 100644
45246--- a/drivers/message/fusion/mptscsih.c
45247+++ b/drivers/message/fusion/mptscsih.c
45248@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45249
45250 h = shost_priv(SChost);
45251
45252- if (h) {
45253- if (h->info_kbuf == NULL)
45254- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45255- return h->info_kbuf;
45256- h->info_kbuf[0] = '\0';
45257+ if (!h)
45258+ return NULL;
45259
45260- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45261- h->info_kbuf[size-1] = '\0';
45262- }
45263+ if (h->info_kbuf == NULL)
45264+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45265+ return h->info_kbuf;
45266+ h->info_kbuf[0] = '\0';
45267+
45268+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45269+ h->info_kbuf[size-1] = '\0';
45270
45271 return h->info_kbuf;
45272 }
45273diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45274index b7d87cd..3fb36da 100644
45275--- a/drivers/message/i2o/i2o_proc.c
45276+++ b/drivers/message/i2o/i2o_proc.c
45277@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45278 "Array Controller Device"
45279 };
45280
45281-static char *chtostr(char *tmp, u8 *chars, int n)
45282-{
45283- tmp[0] = 0;
45284- return strncat(tmp, (char *)chars, n);
45285-}
45286-
45287 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45288 char *group)
45289 {
45290@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45291 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45292 {
45293 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45294- static u32 work32[5];
45295- static u8 *work8 = (u8 *) work32;
45296- static u16 *work16 = (u16 *) work32;
45297+ u32 work32[5];
45298+ u8 *work8 = (u8 *) work32;
45299+ u16 *work16 = (u16 *) work32;
45300 int token;
45301 u32 hwcap;
45302
45303@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45304 } *result;
45305
45306 i2o_exec_execute_ddm_table ddm_table;
45307- char tmp[28 + 1];
45308
45309 result = kmalloc(sizeof(*result), GFP_KERNEL);
45310 if (!result)
45311@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45312
45313 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45314 seq_printf(seq, "%-#8x", ddm_table.module_id);
45315- seq_printf(seq, "%-29s",
45316- chtostr(tmp, ddm_table.module_name_version, 28));
45317+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45318 seq_printf(seq, "%9d ", ddm_table.data_size);
45319 seq_printf(seq, "%8d", ddm_table.code_size);
45320
45321@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45322
45323 i2o_driver_result_table *result;
45324 i2o_driver_store_table *dst;
45325- char tmp[28 + 1];
45326
45327 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45328 if (result == NULL)
45329@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45330
45331 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45332 seq_printf(seq, "%-#8x", dst->module_id);
45333- seq_printf(seq, "%-29s",
45334- chtostr(tmp, dst->module_name_version, 28));
45335- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45336+ seq_printf(seq, "%-.28s", dst->module_name_version);
45337+ seq_printf(seq, "%-.8s", dst->date);
45338 seq_printf(seq, "%8d ", dst->module_size);
45339 seq_printf(seq, "%8d ", dst->mpb_size);
45340 seq_printf(seq, "0x%04x", dst->module_flags);
45341@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45342 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45343 {
45344 struct i2o_device *d = (struct i2o_device *)seq->private;
45345- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45346+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45347 // == (allow) 512d bytes (max)
45348- static u16 *work16 = (u16 *) work32;
45349+ u16 *work16 = (u16 *) work32;
45350 int token;
45351- char tmp[16 + 1];
45352
45353 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45354
45355@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45356 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45357 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45358 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45359- seq_printf(seq, "Vendor info : %s\n",
45360- chtostr(tmp, (u8 *) (work32 + 2), 16));
45361- seq_printf(seq, "Product info : %s\n",
45362- chtostr(tmp, (u8 *) (work32 + 6), 16));
45363- seq_printf(seq, "Description : %s\n",
45364- chtostr(tmp, (u8 *) (work32 + 10), 16));
45365- seq_printf(seq, "Product rev. : %s\n",
45366- chtostr(tmp, (u8 *) (work32 + 14), 8));
45367+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45368+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45369+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45370+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45371
45372 seq_printf(seq, "Serial number : ");
45373 print_serial_number(seq, (u8 *) (work32 + 16),
45374@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45375 u8 pad[256]; // allow up to 256 byte (max) serial number
45376 } result;
45377
45378- char tmp[24 + 1];
45379-
45380 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45381
45382 if (token < 0) {
45383@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45384 }
45385
45386 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45387- seq_printf(seq, "Module name : %s\n",
45388- chtostr(tmp, result.module_name, 24));
45389- seq_printf(seq, "Module revision : %s\n",
45390- chtostr(tmp, result.module_rev, 8));
45391+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45392+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45393
45394 seq_printf(seq, "Serial number : ");
45395 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45396@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45397 u8 instance_number[4];
45398 } result;
45399
45400- char tmp[64 + 1];
45401-
45402 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45403
45404 if (token < 0) {
45405@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45406 return 0;
45407 }
45408
45409- seq_printf(seq, "Device name : %s\n",
45410- chtostr(tmp, result.device_name, 64));
45411- seq_printf(seq, "Service name : %s\n",
45412- chtostr(tmp, result.service_name, 64));
45413- seq_printf(seq, "Physical name : %s\n",
45414- chtostr(tmp, result.physical_location, 64));
45415- seq_printf(seq, "Instance number : %s\n",
45416- chtostr(tmp, result.instance_number, 4));
45417+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45418+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45419+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45420+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45421
45422 return 0;
45423 }
45424@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45425 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45426 {
45427 struct i2o_device *d = (struct i2o_device *)seq->private;
45428- static u32 work32[12];
45429- static u16 *work16 = (u16 *) work32;
45430- static u8 *work8 = (u8 *) work32;
45431+ u32 work32[12];
45432+ u16 *work16 = (u16 *) work32;
45433+ u8 *work8 = (u8 *) work32;
45434 int token;
45435
45436 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45437diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45438index 92752fb..a7494f6 100644
45439--- a/drivers/message/i2o/iop.c
45440+++ b/drivers/message/i2o/iop.c
45441@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45442
45443 spin_lock_irqsave(&c->context_list_lock, flags);
45444
45445- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45446- atomic_inc(&c->context_list_counter);
45447+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45448+ atomic_inc_unchecked(&c->context_list_counter);
45449
45450- entry->context = atomic_read(&c->context_list_counter);
45451+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45452
45453 list_add(&entry->list, &c->context_list);
45454
45455@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45456
45457 #if BITS_PER_LONG == 64
45458 spin_lock_init(&c->context_list_lock);
45459- atomic_set(&c->context_list_counter, 0);
45460+ atomic_set_unchecked(&c->context_list_counter, 0);
45461 INIT_LIST_HEAD(&c->context_list);
45462 #endif
45463
45464diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45465index d1a22aa..d0f7bf7 100644
45466--- a/drivers/mfd/ab8500-debugfs.c
45467+++ b/drivers/mfd/ab8500-debugfs.c
45468@@ -100,7 +100,7 @@ static int irq_last;
45469 static u32 *irq_count;
45470 static int num_irqs;
45471
45472-static struct device_attribute **dev_attr;
45473+static device_attribute_no_const **dev_attr;
45474 static char **event_name;
45475
45476 static u8 avg_sample = SAMPLE_16;
45477diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45478index a83eed5..62a58a9 100644
45479--- a/drivers/mfd/max8925-i2c.c
45480+++ b/drivers/mfd/max8925-i2c.c
45481@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45482 const struct i2c_device_id *id)
45483 {
45484 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45485- static struct max8925_chip *chip;
45486+ struct max8925_chip *chip;
45487 struct device_node *node = client->dev.of_node;
45488
45489 if (node && !pdata) {
45490diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45491index 460a014..21d3061 100644
45492--- a/drivers/mfd/tps65910.c
45493+++ b/drivers/mfd/tps65910.c
45494@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45495 struct tps65910_platform_data *pdata)
45496 {
45497 int ret = 0;
45498- static struct regmap_irq_chip *tps6591x_irqs_chip;
45499+ struct regmap_irq_chip *tps6591x_irqs_chip;
45500
45501 if (!irq) {
45502 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45503diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45504index 596b1f6..5b6ab74 100644
45505--- a/drivers/mfd/twl4030-irq.c
45506+++ b/drivers/mfd/twl4030-irq.c
45507@@ -34,6 +34,7 @@
45508 #include <linux/of.h>
45509 #include <linux/irqdomain.h>
45510 #include <linux/i2c/twl.h>
45511+#include <asm/pgtable.h>
45512
45513 #include "twl-core.h"
45514
45515@@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45516 * Install an irq handler for each of the SIH modules;
45517 * clone dummy irq_chip since PIH can't *do* anything
45518 */
45519- twl4030_irq_chip = dummy_irq_chip;
45520- twl4030_irq_chip.name = "twl4030";
45521+ pax_open_kernel();
45522+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45523+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45524
45525- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45526+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45527+ pax_close_kernel();
45528
45529 for (i = irq_base; i < irq_end; i++) {
45530 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45531diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45532index 464419b..64bae8d 100644
45533--- a/drivers/misc/c2port/core.c
45534+++ b/drivers/misc/c2port/core.c
45535@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45536 goto error_idr_alloc;
45537 c2dev->id = ret;
45538
45539- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45540+ pax_open_kernel();
45541+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45542+ pax_close_kernel();
45543
45544 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45545 "c2port%d", c2dev->id);
45546diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45547index 3f2b625..945e179 100644
45548--- a/drivers/misc/eeprom/sunxi_sid.c
45549+++ b/drivers/misc/eeprom/sunxi_sid.c
45550@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45551
45552 platform_set_drvdata(pdev, sid_data);
45553
45554- sid_bin_attr.size = sid_data->keysize;
45555+ pax_open_kernel();
45556+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45557+ pax_close_kernel();
45558 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45559 return -ENODEV;
45560
45561diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45562index 36f5d52..32311c3 100644
45563--- a/drivers/misc/kgdbts.c
45564+++ b/drivers/misc/kgdbts.c
45565@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45566 char before[BREAK_INSTR_SIZE];
45567 char after[BREAK_INSTR_SIZE];
45568
45569- probe_kernel_read(before, (char *)kgdbts_break_test,
45570+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45571 BREAK_INSTR_SIZE);
45572 init_simple_test();
45573 ts.tst = plant_and_detach_test;
45574@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45575 /* Activate test with initial breakpoint */
45576 if (!is_early)
45577 kgdb_breakpoint();
45578- probe_kernel_read(after, (char *)kgdbts_break_test,
45579+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45580 BREAK_INSTR_SIZE);
45581 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45582 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45583diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45584index 3ef4627..8d00486 100644
45585--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45586+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45587@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45588 * the lid is closed. This leads to interrupts as soon as a little move
45589 * is done.
45590 */
45591- atomic_inc(&lis3->count);
45592+ atomic_inc_unchecked(&lis3->count);
45593
45594 wake_up_interruptible(&lis3->misc_wait);
45595 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45596@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45597 if (lis3->pm_dev)
45598 pm_runtime_get_sync(lis3->pm_dev);
45599
45600- atomic_set(&lis3->count, 0);
45601+ atomic_set_unchecked(&lis3->count, 0);
45602 return 0;
45603 }
45604
45605@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45606 add_wait_queue(&lis3->misc_wait, &wait);
45607 while (true) {
45608 set_current_state(TASK_INTERRUPTIBLE);
45609- data = atomic_xchg(&lis3->count, 0);
45610+ data = atomic_xchg_unchecked(&lis3->count, 0);
45611 if (data)
45612 break;
45613
45614@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45615 struct lis3lv02d, miscdev);
45616
45617 poll_wait(file, &lis3->misc_wait, wait);
45618- if (atomic_read(&lis3->count))
45619+ if (atomic_read_unchecked(&lis3->count))
45620 return POLLIN | POLLRDNORM;
45621 return 0;
45622 }
45623diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45624index c439c82..1f20f57 100644
45625--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45626+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45627@@ -297,7 +297,7 @@ struct lis3lv02d {
45628 struct input_polled_dev *idev; /* input device */
45629 struct platform_device *pdev; /* platform device */
45630 struct regulator_bulk_data regulators[2];
45631- atomic_t count; /* interrupt count after last read */
45632+ atomic_unchecked_t count; /* interrupt count after last read */
45633 union axis_conversion ac; /* hw -> logical axis */
45634 int mapped_btns[3];
45635
45636diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45637index 2f30bad..c4c13d0 100644
45638--- a/drivers/misc/sgi-gru/gruhandles.c
45639+++ b/drivers/misc/sgi-gru/gruhandles.c
45640@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45641 unsigned long nsec;
45642
45643 nsec = CLKS2NSEC(clks);
45644- atomic_long_inc(&mcs_op_statistics[op].count);
45645- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45646+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45647+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45648 if (mcs_op_statistics[op].max < nsec)
45649 mcs_op_statistics[op].max = nsec;
45650 }
45651diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45652index 4f76359..cdfcb2e 100644
45653--- a/drivers/misc/sgi-gru/gruprocfs.c
45654+++ b/drivers/misc/sgi-gru/gruprocfs.c
45655@@ -32,9 +32,9 @@
45656
45657 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45658
45659-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45660+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45661 {
45662- unsigned long val = atomic_long_read(v);
45663+ unsigned long val = atomic_long_read_unchecked(v);
45664
45665 seq_printf(s, "%16lu %s\n", val, id);
45666 }
45667@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45668
45669 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45670 for (op = 0; op < mcsop_last; op++) {
45671- count = atomic_long_read(&mcs_op_statistics[op].count);
45672- total = atomic_long_read(&mcs_op_statistics[op].total);
45673+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45674+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45675 max = mcs_op_statistics[op].max;
45676 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45677 count ? total / count : 0, max);
45678diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45679index 5c3ce24..4915ccb 100644
45680--- a/drivers/misc/sgi-gru/grutables.h
45681+++ b/drivers/misc/sgi-gru/grutables.h
45682@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45683 * GRU statistics.
45684 */
45685 struct gru_stats_s {
45686- atomic_long_t vdata_alloc;
45687- atomic_long_t vdata_free;
45688- atomic_long_t gts_alloc;
45689- atomic_long_t gts_free;
45690- atomic_long_t gms_alloc;
45691- atomic_long_t gms_free;
45692- atomic_long_t gts_double_allocate;
45693- atomic_long_t assign_context;
45694- atomic_long_t assign_context_failed;
45695- atomic_long_t free_context;
45696- atomic_long_t load_user_context;
45697- atomic_long_t load_kernel_context;
45698- atomic_long_t lock_kernel_context;
45699- atomic_long_t unlock_kernel_context;
45700- atomic_long_t steal_user_context;
45701- atomic_long_t steal_kernel_context;
45702- atomic_long_t steal_context_failed;
45703- atomic_long_t nopfn;
45704- atomic_long_t asid_new;
45705- atomic_long_t asid_next;
45706- atomic_long_t asid_wrap;
45707- atomic_long_t asid_reuse;
45708- atomic_long_t intr;
45709- atomic_long_t intr_cbr;
45710- atomic_long_t intr_tfh;
45711- atomic_long_t intr_spurious;
45712- atomic_long_t intr_mm_lock_failed;
45713- atomic_long_t call_os;
45714- atomic_long_t call_os_wait_queue;
45715- atomic_long_t user_flush_tlb;
45716- atomic_long_t user_unload_context;
45717- atomic_long_t user_exception;
45718- atomic_long_t set_context_option;
45719- atomic_long_t check_context_retarget_intr;
45720- atomic_long_t check_context_unload;
45721- atomic_long_t tlb_dropin;
45722- atomic_long_t tlb_preload_page;
45723- atomic_long_t tlb_dropin_fail_no_asid;
45724- atomic_long_t tlb_dropin_fail_upm;
45725- atomic_long_t tlb_dropin_fail_invalid;
45726- atomic_long_t tlb_dropin_fail_range_active;
45727- atomic_long_t tlb_dropin_fail_idle;
45728- atomic_long_t tlb_dropin_fail_fmm;
45729- atomic_long_t tlb_dropin_fail_no_exception;
45730- atomic_long_t tfh_stale_on_fault;
45731- atomic_long_t mmu_invalidate_range;
45732- atomic_long_t mmu_invalidate_page;
45733- atomic_long_t flush_tlb;
45734- atomic_long_t flush_tlb_gru;
45735- atomic_long_t flush_tlb_gru_tgh;
45736- atomic_long_t flush_tlb_gru_zero_asid;
45737+ atomic_long_unchecked_t vdata_alloc;
45738+ atomic_long_unchecked_t vdata_free;
45739+ atomic_long_unchecked_t gts_alloc;
45740+ atomic_long_unchecked_t gts_free;
45741+ atomic_long_unchecked_t gms_alloc;
45742+ atomic_long_unchecked_t gms_free;
45743+ atomic_long_unchecked_t gts_double_allocate;
45744+ atomic_long_unchecked_t assign_context;
45745+ atomic_long_unchecked_t assign_context_failed;
45746+ atomic_long_unchecked_t free_context;
45747+ atomic_long_unchecked_t load_user_context;
45748+ atomic_long_unchecked_t load_kernel_context;
45749+ atomic_long_unchecked_t lock_kernel_context;
45750+ atomic_long_unchecked_t unlock_kernel_context;
45751+ atomic_long_unchecked_t steal_user_context;
45752+ atomic_long_unchecked_t steal_kernel_context;
45753+ atomic_long_unchecked_t steal_context_failed;
45754+ atomic_long_unchecked_t nopfn;
45755+ atomic_long_unchecked_t asid_new;
45756+ atomic_long_unchecked_t asid_next;
45757+ atomic_long_unchecked_t asid_wrap;
45758+ atomic_long_unchecked_t asid_reuse;
45759+ atomic_long_unchecked_t intr;
45760+ atomic_long_unchecked_t intr_cbr;
45761+ atomic_long_unchecked_t intr_tfh;
45762+ atomic_long_unchecked_t intr_spurious;
45763+ atomic_long_unchecked_t intr_mm_lock_failed;
45764+ atomic_long_unchecked_t call_os;
45765+ atomic_long_unchecked_t call_os_wait_queue;
45766+ atomic_long_unchecked_t user_flush_tlb;
45767+ atomic_long_unchecked_t user_unload_context;
45768+ atomic_long_unchecked_t user_exception;
45769+ atomic_long_unchecked_t set_context_option;
45770+ atomic_long_unchecked_t check_context_retarget_intr;
45771+ atomic_long_unchecked_t check_context_unload;
45772+ atomic_long_unchecked_t tlb_dropin;
45773+ atomic_long_unchecked_t tlb_preload_page;
45774+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45775+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45776+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45777+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45778+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45779+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45780+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45781+ atomic_long_unchecked_t tfh_stale_on_fault;
45782+ atomic_long_unchecked_t mmu_invalidate_range;
45783+ atomic_long_unchecked_t mmu_invalidate_page;
45784+ atomic_long_unchecked_t flush_tlb;
45785+ atomic_long_unchecked_t flush_tlb_gru;
45786+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45787+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45788
45789- atomic_long_t copy_gpa;
45790- atomic_long_t read_gpa;
45791+ atomic_long_unchecked_t copy_gpa;
45792+ atomic_long_unchecked_t read_gpa;
45793
45794- atomic_long_t mesq_receive;
45795- atomic_long_t mesq_receive_none;
45796- atomic_long_t mesq_send;
45797- atomic_long_t mesq_send_failed;
45798- atomic_long_t mesq_noop;
45799- atomic_long_t mesq_send_unexpected_error;
45800- atomic_long_t mesq_send_lb_overflow;
45801- atomic_long_t mesq_send_qlimit_reached;
45802- atomic_long_t mesq_send_amo_nacked;
45803- atomic_long_t mesq_send_put_nacked;
45804- atomic_long_t mesq_page_overflow;
45805- atomic_long_t mesq_qf_locked;
45806- atomic_long_t mesq_qf_noop_not_full;
45807- atomic_long_t mesq_qf_switch_head_failed;
45808- atomic_long_t mesq_qf_unexpected_error;
45809- atomic_long_t mesq_noop_unexpected_error;
45810- atomic_long_t mesq_noop_lb_overflow;
45811- atomic_long_t mesq_noop_qlimit_reached;
45812- atomic_long_t mesq_noop_amo_nacked;
45813- atomic_long_t mesq_noop_put_nacked;
45814- atomic_long_t mesq_noop_page_overflow;
45815+ atomic_long_unchecked_t mesq_receive;
45816+ atomic_long_unchecked_t mesq_receive_none;
45817+ atomic_long_unchecked_t mesq_send;
45818+ atomic_long_unchecked_t mesq_send_failed;
45819+ atomic_long_unchecked_t mesq_noop;
45820+ atomic_long_unchecked_t mesq_send_unexpected_error;
45821+ atomic_long_unchecked_t mesq_send_lb_overflow;
45822+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45823+ atomic_long_unchecked_t mesq_send_amo_nacked;
45824+ atomic_long_unchecked_t mesq_send_put_nacked;
45825+ atomic_long_unchecked_t mesq_page_overflow;
45826+ atomic_long_unchecked_t mesq_qf_locked;
45827+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45828+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45829+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45830+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45831+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45832+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45833+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45834+ atomic_long_unchecked_t mesq_noop_put_nacked;
45835+ atomic_long_unchecked_t mesq_noop_page_overflow;
45836
45837 };
45838
45839@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45840 tghop_invalidate, mcsop_last};
45841
45842 struct mcs_op_statistic {
45843- atomic_long_t count;
45844- atomic_long_t total;
45845+ atomic_long_unchecked_t count;
45846+ atomic_long_unchecked_t total;
45847 unsigned long max;
45848 };
45849
45850@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45851
45852 #define STAT(id) do { \
45853 if (gru_options & OPT_STATS) \
45854- atomic_long_inc(&gru_stats.id); \
45855+ atomic_long_inc_unchecked(&gru_stats.id); \
45856 } while (0)
45857
45858 #ifdef CONFIG_SGI_GRU_DEBUG
45859diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45860index c862cd4..0d176fe 100644
45861--- a/drivers/misc/sgi-xp/xp.h
45862+++ b/drivers/misc/sgi-xp/xp.h
45863@@ -288,7 +288,7 @@ struct xpc_interface {
45864 xpc_notify_func, void *);
45865 void (*received) (short, int, void *);
45866 enum xp_retval (*partid_to_nasids) (short, void *);
45867-};
45868+} __no_const;
45869
45870 extern struct xpc_interface xpc_interface;
45871
45872diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45873index 01be66d..e3a0c7e 100644
45874--- a/drivers/misc/sgi-xp/xp_main.c
45875+++ b/drivers/misc/sgi-xp/xp_main.c
45876@@ -78,13 +78,13 @@ xpc_notloaded(void)
45877 }
45878
45879 struct xpc_interface xpc_interface = {
45880- (void (*)(int))xpc_notloaded,
45881- (void (*)(int))xpc_notloaded,
45882- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45883- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45884+ .connect = (void (*)(int))xpc_notloaded,
45885+ .disconnect = (void (*)(int))xpc_notloaded,
45886+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45887+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45888 void *))xpc_notloaded,
45889- (void (*)(short, int, void *))xpc_notloaded,
45890- (enum xp_retval(*)(short, void *))xpc_notloaded
45891+ .received = (void (*)(short, int, void *))xpc_notloaded,
45892+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45893 };
45894 EXPORT_SYMBOL_GPL(xpc_interface);
45895
45896diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45897index b94d5f7..7f494c5 100644
45898--- a/drivers/misc/sgi-xp/xpc.h
45899+++ b/drivers/misc/sgi-xp/xpc.h
45900@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45901 void (*received_payload) (struct xpc_channel *, void *);
45902 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45903 };
45904+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45905
45906 /* struct xpc_partition act_state values (for XPC HB) */
45907
45908@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45909 /* found in xpc_main.c */
45910 extern struct device *xpc_part;
45911 extern struct device *xpc_chan;
45912-extern struct xpc_arch_operations xpc_arch_ops;
45913+extern xpc_arch_operations_no_const xpc_arch_ops;
45914 extern int xpc_disengage_timelimit;
45915 extern int xpc_disengage_timedout;
45916 extern int xpc_activate_IRQ_rcvd;
45917diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45918index 82dc574..8539ab2 100644
45919--- a/drivers/misc/sgi-xp/xpc_main.c
45920+++ b/drivers/misc/sgi-xp/xpc_main.c
45921@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45922 .notifier_call = xpc_system_die,
45923 };
45924
45925-struct xpc_arch_operations xpc_arch_ops;
45926+xpc_arch_operations_no_const xpc_arch_ops;
45927
45928 /*
45929 * Timer function to enforce the timelimit on the partition disengage.
45930@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45931
45932 if (((die_args->trapnr == X86_TRAP_MF) ||
45933 (die_args->trapnr == X86_TRAP_XF)) &&
45934- !user_mode_vm(die_args->regs))
45935+ !user_mode(die_args->regs))
45936 xpc_die_deactivate();
45937
45938 break;
45939diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45940index 452782b..0c10e40 100644
45941--- a/drivers/mmc/card/block.c
45942+++ b/drivers/mmc/card/block.c
45943@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45944 if (idata->ic.postsleep_min_us)
45945 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45946
45947- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45948+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45949 err = -EFAULT;
45950 goto cmd_rel_host;
45951 }
45952diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45953index f51b5ba..86614a7 100644
45954--- a/drivers/mmc/core/mmc_ops.c
45955+++ b/drivers/mmc/core/mmc_ops.c
45956@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45957 void *data_buf;
45958 int is_on_stack;
45959
45960- is_on_stack = object_is_on_stack(buf);
45961+ is_on_stack = object_starts_on_stack(buf);
45962 if (is_on_stack) {
45963 /*
45964 * dma onto stack is unsafe/nonportable, but callers to this
45965diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45966index 6834977..824ee1b 100644
45967--- a/drivers/mmc/host/dw_mmc.h
45968+++ b/drivers/mmc/host/dw_mmc.h
45969@@ -259,5 +259,5 @@ struct dw_mci_drv_data {
45970 int (*parse_dt)(struct dw_mci *host);
45971 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45972 struct dw_mci_tuning_data *tuning_data);
45973-};
45974+} __do_const;
45975 #endif /* _DW_MMC_H_ */
45976diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45977index 771c60a..12cb615 100644
45978--- a/drivers/mmc/host/mmci.c
45979+++ b/drivers/mmc/host/mmci.c
45980@@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
45981 mmc->caps2 = plat->capabilities2;
45982
45983 if (variant->busy_detect) {
45984- mmci_ops.card_busy = mmci_card_busy;
45985+ pax_open_kernel();
45986+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45987+ pax_close_kernel();
45988 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45989 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
45990 mmc->max_busy_timeout = 0;
45991diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45992index b841bb7..d82712f5 100644
45993--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45994+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45995@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45996 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45997 }
45998
45999- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46000- sdhci_esdhc_ops.platform_execute_tuning =
46001+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46002+ pax_open_kernel();
46003+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46004 esdhc_executing_tuning;
46005+ pax_close_kernel();
46006+ }
46007
46008 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46009 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46010diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46011index d61eb5a..88c0f5d 100644
46012--- a/drivers/mmc/host/sdhci-s3c.c
46013+++ b/drivers/mmc/host/sdhci-s3c.c
46014@@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46015 * we can use overriding functions instead of default.
46016 */
46017 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
46018- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46019- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46020- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46021+ pax_open_kernel();
46022+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46023+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46024+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46025+ pax_close_kernel();
46026 }
46027
46028 /* It supports additional host capabilities if needed */
46029diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46030index 6293855..3415551 100644
46031--- a/drivers/mtd/chips/cfi_cmdset_0020.c
46032+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46033@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46034 size_t totlen = 0, thislen;
46035 int ret = 0;
46036 size_t buflen = 0;
46037- static char *buffer;
46038+ char *buffer;
46039
46040 if (!ECCBUF_SIZE) {
46041 /* We should fall back to a general writev implementation.
46042diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46043index c07cd57..61c4fbd 100644
46044--- a/drivers/mtd/nand/denali.c
46045+++ b/drivers/mtd/nand/denali.c
46046@@ -24,6 +24,7 @@
46047 #include <linux/slab.h>
46048 #include <linux/mtd/mtd.h>
46049 #include <linux/module.h>
46050+#include <linux/slab.h>
46051
46052 #include "denali.h"
46053
46054diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46055index bb77f75..47539b1 100644
46056--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46057+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46058@@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46059
46060 /* first try to map the upper buffer directly */
46061 if (virt_addr_valid(this->upper_buf) &&
46062- !object_is_on_stack(this->upper_buf)) {
46063+ !object_starts_on_stack(this->upper_buf)) {
46064 sg_init_one(sgl, this->upper_buf, this->upper_len);
46065 ret = dma_map_sg(this->dev, sgl, 1, dr);
46066 if (ret == 0)
46067diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46068index 51b9d6a..52af9a7 100644
46069--- a/drivers/mtd/nftlmount.c
46070+++ b/drivers/mtd/nftlmount.c
46071@@ -24,6 +24,7 @@
46072 #include <asm/errno.h>
46073 #include <linux/delay.h>
46074 #include <linux/slab.h>
46075+#include <linux/sched.h>
46076 #include <linux/mtd/mtd.h>
46077 #include <linux/mtd/nand.h>
46078 #include <linux/mtd/nftl.h>
46079diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46080index cf49c22..971b133 100644
46081--- a/drivers/mtd/sm_ftl.c
46082+++ b/drivers/mtd/sm_ftl.c
46083@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46084 #define SM_CIS_VENDOR_OFFSET 0x59
46085 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46086 {
46087- struct attribute_group *attr_group;
46088+ attribute_group_no_const *attr_group;
46089 struct attribute **attributes;
46090 struct sm_sysfs_attribute *vendor_attribute;
46091 char *vendor;
46092diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46093index f847e16..fc8dbe9 100644
46094--- a/drivers/net/bonding/bond_netlink.c
46095+++ b/drivers/net/bonding/bond_netlink.c
46096@@ -542,7 +542,7 @@ nla_put_failure:
46097 return -EMSGSIZE;
46098 }
46099
46100-struct rtnl_link_ops bond_link_ops __read_mostly = {
46101+struct rtnl_link_ops bond_link_ops = {
46102 .kind = "bond",
46103 .priv_size = sizeof(struct bonding),
46104 .setup = bond_setup,
46105diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46106index 9e7d95d..d447b88 100644
46107--- a/drivers/net/can/Kconfig
46108+++ b/drivers/net/can/Kconfig
46109@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46110
46111 config CAN_FLEXCAN
46112 tristate "Support for Freescale FLEXCAN based chips"
46113- depends on ARM || PPC
46114+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46115 ---help---
46116 Say Y here if you want to support for Freescale FlexCAN.
46117
46118diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46119index 455d4c3..3353ee7 100644
46120--- a/drivers/net/ethernet/8390/ax88796.c
46121+++ b/drivers/net/ethernet/8390/ax88796.c
46122@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46123 if (ax->plat->reg_offsets)
46124 ei_local->reg_offset = ax->plat->reg_offsets;
46125 else {
46126+ resource_size_t _mem_size = mem_size;
46127+ do_div(_mem_size, 0x18);
46128 ei_local->reg_offset = ax->reg_offsets;
46129 for (ret = 0; ret < 0x18; ret++)
46130- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46131+ ax->reg_offsets[ret] = _mem_size * ret;
46132 }
46133
46134 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46135diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
46136index 7330681..7e9e463 100644
46137--- a/drivers/net/ethernet/altera/altera_tse_main.c
46138+++ b/drivers/net/ethernet/altera/altera_tse_main.c
46139@@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
46140 return 0;
46141 }
46142
46143-static struct net_device_ops altera_tse_netdev_ops = {
46144+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
46145 .ndo_open = tse_open,
46146 .ndo_stop = tse_shutdown,
46147 .ndo_start_xmit = tse_start_xmit,
46148@@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
46149 ndev->netdev_ops = &altera_tse_netdev_ops;
46150 altera_tse_set_ethtool_ops(ndev);
46151
46152+ pax_open_kernel();
46153 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
46154
46155 if (priv->hash_filter)
46156 altera_tse_netdev_ops.ndo_set_rx_mode =
46157 tse_set_rx_mode_hashfilter;
46158+ pax_close_kernel();
46159
46160 /* Scatter/gather IO is not supported,
46161 * so it is turned off
46162diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46163index 3448cc0..67b2dc4 100644
46164--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46165+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46166@@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46167 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46168 {
46169 /* RX_MODE controlling object */
46170- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46171+ bnx2x_init_rx_mode_obj(bp);
46172
46173 /* multicast configuration controlling object */
46174 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46175diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46176index 31297266..944cf6e 100644
46177--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46178+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46179@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46180 return rc;
46181 }
46182
46183-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46184- struct bnx2x_rx_mode_obj *o)
46185+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46186 {
46187 if (CHIP_IS_E1x(bp)) {
46188- o->wait_comp = bnx2x_empty_rx_mode_wait;
46189- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46190+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46191+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46192 } else {
46193- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46194- o->config_rx_mode = bnx2x_set_rx_mode_e2;
46195+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46196+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46197 }
46198 }
46199
46200diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46201index 80f6c79..fb7d12d 100644
46202--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46203+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46204@@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46205
46206 /********************* RX MODE ****************/
46207
46208-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46209- struct bnx2x_rx_mode_obj *o);
46210+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46211
46212 /**
46213 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46214diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46215index 6929adb..cc68830 100644
46216--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46217+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46218@@ -571,7 +571,7 @@ static inline void __iomem *bnx2x_vf_doorbells(struct bnx2x *bp)
46219 return NULL;
46220 }
46221
46222-static inline void bnx2x_vf_pci_dealloc(struct bnx2 *bp) {return 0; }
46223+static inline void bnx2x_vf_pci_dealloc(struct bnx2x *bp) { }
46224 static inline int bnx2x_vf_pci_alloc(struct bnx2x *bp) {return 0; }
46225 static inline void bnx2x_pf_set_vfs_vlan(struct bnx2x *bp) {}
46226 static inline int bnx2x_sriov_configure(struct pci_dev *dev, int num_vfs) {return 0; }
46227diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46228index 04321e5..b51cdc4 100644
46229--- a/drivers/net/ethernet/broadcom/tg3.h
46230+++ b/drivers/net/ethernet/broadcom/tg3.h
46231@@ -150,6 +150,7 @@
46232 #define CHIPREV_ID_5750_A0 0x4000
46233 #define CHIPREV_ID_5750_A1 0x4001
46234 #define CHIPREV_ID_5750_A3 0x4003
46235+#define CHIPREV_ID_5750_C1 0x4201
46236 #define CHIPREV_ID_5750_C2 0x4202
46237 #define CHIPREV_ID_5752_A0_HW 0x5000
46238 #define CHIPREV_ID_5752_A0 0x6000
46239diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46240index 13f9636..228040f 100644
46241--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46242+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46243@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46244 }
46245
46246 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46247- bna_cb_ioceth_enable,
46248- bna_cb_ioceth_disable,
46249- bna_cb_ioceth_hbfail,
46250- bna_cb_ioceth_reset
46251+ .enable_cbfn = bna_cb_ioceth_enable,
46252+ .disable_cbfn = bna_cb_ioceth_disable,
46253+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
46254+ .reset_cbfn = bna_cb_ioceth_reset
46255 };
46256
46257 static void bna_attr_init(struct bna_ioceth *ioceth)
46258diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46259index 8cffcdf..aadf043 100644
46260--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46261+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46262@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46263 */
46264 struct l2t_skb_cb {
46265 arp_failure_handler_func arp_failure_handler;
46266-};
46267+} __no_const;
46268
46269 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46270
46271diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46272index 24e16e3..bfe6ef2 100644
46273--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46274+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46275@@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46276
46277 int i;
46278 struct adapter *ap = netdev2adap(dev);
46279- static const unsigned int *reg_ranges;
46280+ const unsigned int *reg_ranges;
46281 int arr_size = 0, buf_size = 0;
46282
46283 if (is_t4(ap->params.chip)) {
46284diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46285index c05b66d..ed69872 100644
46286--- a/drivers/net/ethernet/dec/tulip/de4x5.c
46287+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46288@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46289 for (i=0; i<ETH_ALEN; i++) {
46290 tmp.addr[i] = dev->dev_addr[i];
46291 }
46292- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46293+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46294 break;
46295
46296 case DE4X5_SET_HWADDR: /* Set the hardware address */
46297@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46298 spin_lock_irqsave(&lp->lock, flags);
46299 memcpy(&statbuf, &lp->pktStats, ioc->len);
46300 spin_unlock_irqrestore(&lp->lock, flags);
46301- if (copy_to_user(ioc->data, &statbuf, ioc->len))
46302+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46303 return -EFAULT;
46304 break;
46305 }
46306diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46307index 2b5ab7c..20e2e7f 100644
46308--- a/drivers/net/ethernet/emulex/benet/be_main.c
46309+++ b/drivers/net/ethernet/emulex/benet/be_main.c
46310@@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46311
46312 if (wrapped)
46313 newacc += 65536;
46314- ACCESS_ONCE(*acc) = newacc;
46315+ ACCESS_ONCE_RW(*acc) = newacc;
46316 }
46317
46318 static void populate_erx_stats(struct be_adapter *adapter,
46319diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46320index 68069ea..c4484f6 100644
46321--- a/drivers/net/ethernet/faraday/ftgmac100.c
46322+++ b/drivers/net/ethernet/faraday/ftgmac100.c
46323@@ -30,6 +30,8 @@
46324 #include <linux/netdevice.h>
46325 #include <linux/phy.h>
46326 #include <linux/platform_device.h>
46327+#include <linux/interrupt.h>
46328+#include <linux/irqreturn.h>
46329 #include <net/ip.h>
46330
46331 #include "ftgmac100.h"
46332diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46333index 8be5b40..081bc1b 100644
46334--- a/drivers/net/ethernet/faraday/ftmac100.c
46335+++ b/drivers/net/ethernet/faraday/ftmac100.c
46336@@ -31,6 +31,8 @@
46337 #include <linux/module.h>
46338 #include <linux/netdevice.h>
46339 #include <linux/platform_device.h>
46340+#include <linux/interrupt.h>
46341+#include <linux/irqreturn.h>
46342
46343 #include "ftmac100.h"
46344
46345diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46346index e61e637..9117795 100644
46347--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46348+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46349@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46350 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46351
46352 /* Update the base adjustement value. */
46353- ACCESS_ONCE(pf->ptp_base_adj) = incval;
46354+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46355 smp_mb(); /* Force the above update. */
46356 }
46357
46358diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46359index 8902ae6..e7bcdce 100644
46360--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46361+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46362@@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46363 }
46364
46365 /* update the base incval used to calculate frequency adjustment */
46366- ACCESS_ONCE(adapter->base_incval) = incval;
46367+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
46368 smp_mb();
46369
46370 /* need lock to prevent incorrect read while modifying cyclecounter */
46371diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46372index 089b713..28d87ae 100644
46373--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46374+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46375@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46376 struct __vxge_hw_fifo *fifo;
46377 struct vxge_hw_fifo_config *config;
46378 u32 txdl_size, txdl_per_memblock;
46379- struct vxge_hw_mempool_cbs fifo_mp_callback;
46380+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46381+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46382+ };
46383+
46384 struct __vxge_hw_virtualpath *vpath;
46385
46386 if ((vp == NULL) || (attr == NULL)) {
46387@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46388 goto exit;
46389 }
46390
46391- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46392-
46393 fifo->mempool =
46394 __vxge_hw_mempool_create(vpath->hldev,
46395 fifo->config->memblock_size,
46396diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46397index ba20c72..f30c0fe 100644
46398--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46399+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46400@@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46401 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46402 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46403 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46404- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46405+ pax_open_kernel();
46406+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46407+ pax_close_kernel();
46408 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46409 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46410 max_tx_rings = QLCNIC_MAX_TX_RINGS;
46411diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46412index be7d7a6..a8983f8 100644
46413--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46414+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46415@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46416 case QLCNIC_NON_PRIV_FUNC:
46417 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46418 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46419- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46420+ pax_open_kernel();
46421+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46422+ pax_close_kernel();
46423 break;
46424 case QLCNIC_PRIV_FUNC:
46425 ahw->op_mode = QLCNIC_PRIV_FUNC;
46426 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46427- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46428+ pax_open_kernel();
46429+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46430+ pax_close_kernel();
46431 break;
46432 case QLCNIC_MGMT_FUNC:
46433 ahw->op_mode = QLCNIC_MGMT_FUNC;
46434 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46435- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46436+ pax_open_kernel();
46437+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46438+ pax_close_kernel();
46439 break;
46440 default:
46441 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46442diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46443index 37b979b..50f5b95 100644
46444--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46445+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46446@@ -1217,7 +1217,7 @@ flash_temp:
46447 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46448 {
46449 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46450- static const struct qlcnic_dump_operations *fw_dump_ops;
46451+ const struct qlcnic_dump_operations *fw_dump_ops;
46452 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46453 u32 entry_offset, dump, no_entries, buf_offset = 0;
46454 int i, k, ops_cnt, ops_index, dump_size = 0;
46455diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46456index aa1c079..2b1a3e8 100644
46457--- a/drivers/net/ethernet/realtek/r8169.c
46458+++ b/drivers/net/ethernet/realtek/r8169.c
46459@@ -758,22 +758,22 @@ struct rtl8169_private {
46460 struct mdio_ops {
46461 void (*write)(struct rtl8169_private *, int, int);
46462 int (*read)(struct rtl8169_private *, int);
46463- } mdio_ops;
46464+ } __no_const mdio_ops;
46465
46466 struct pll_power_ops {
46467 void (*down)(struct rtl8169_private *);
46468 void (*up)(struct rtl8169_private *);
46469- } pll_power_ops;
46470+ } __no_const pll_power_ops;
46471
46472 struct jumbo_ops {
46473 void (*enable)(struct rtl8169_private *);
46474 void (*disable)(struct rtl8169_private *);
46475- } jumbo_ops;
46476+ } __no_const jumbo_ops;
46477
46478 struct csi_ops {
46479 void (*write)(struct rtl8169_private *, int, int);
46480 u32 (*read)(struct rtl8169_private *, int);
46481- } csi_ops;
46482+ } __no_const csi_ops;
46483
46484 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46485 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46486diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46487index 6b861e3..204ac86 100644
46488--- a/drivers/net/ethernet/sfc/ptp.c
46489+++ b/drivers/net/ethernet/sfc/ptp.c
46490@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46491 ptp->start.dma_addr);
46492
46493 /* Clear flag that signals MC ready */
46494- ACCESS_ONCE(*start) = 0;
46495+ ACCESS_ONCE_RW(*start) = 0;
46496 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46497 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46498 EFX_BUG_ON_PARANOID(rc);
46499diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46500index 50617c5..b13724c 100644
46501--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46502+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46503@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46504
46505 writel(value, ioaddr + MMC_CNTRL);
46506
46507- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46508- MMC_CNTRL, value);
46509+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46510+// MMC_CNTRL, value);
46511 }
46512
46513 /* To mask all all interrupts.*/
46514diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46515index d18f711d..5755800 100644
46516--- a/drivers/net/hyperv/hyperv_net.h
46517+++ b/drivers/net/hyperv/hyperv_net.h
46518@@ -101,7 +101,7 @@ struct rndis_device {
46519
46520 enum rndis_device_state state;
46521 bool link_state;
46522- atomic_t new_req_id;
46523+ atomic_unchecked_t new_req_id;
46524
46525 spinlock_t request_lock;
46526 struct list_head req_list;
46527diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46528index 143a98c..d54fbaa 100644
46529--- a/drivers/net/hyperv/rndis_filter.c
46530+++ b/drivers/net/hyperv/rndis_filter.c
46531@@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46532 * template
46533 */
46534 set = &rndis_msg->msg.set_req;
46535- set->req_id = atomic_inc_return(&dev->new_req_id);
46536+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46537
46538 /* Add to the request list */
46539 spin_lock_irqsave(&dev->request_lock, flags);
46540@@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46541
46542 /* Setup the rndis set */
46543 halt = &request->request_msg.msg.halt_req;
46544- halt->req_id = atomic_inc_return(&dev->new_req_id);
46545+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46546
46547 /* Ignore return since this msg is optional. */
46548 rndis_filter_send_request(dev, request);
46549diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46550index 78f18be..1d19c62 100644
46551--- a/drivers/net/ieee802154/fakehard.c
46552+++ b/drivers/net/ieee802154/fakehard.c
46553@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46554 phy->transmit_power = 0xbf;
46555
46556 dev->netdev_ops = &fake_ops;
46557- dev->ml_priv = &fake_mlme;
46558+ dev->ml_priv = (void *)&fake_mlme;
46559
46560 priv = netdev_priv(dev);
46561 priv->phy = phy;
46562diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46563index d650b91..7717c68 100644
46564--- a/drivers/net/macvlan.c
46565+++ b/drivers/net/macvlan.c
46566@@ -985,13 +985,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46567 int macvlan_link_register(struct rtnl_link_ops *ops)
46568 {
46569 /* common fields */
46570- ops->priv_size = sizeof(struct macvlan_dev);
46571- ops->validate = macvlan_validate;
46572- ops->maxtype = IFLA_MACVLAN_MAX;
46573- ops->policy = macvlan_policy;
46574- ops->changelink = macvlan_changelink;
46575- ops->get_size = macvlan_get_size;
46576- ops->fill_info = macvlan_fill_info;
46577+ pax_open_kernel();
46578+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46579+ *(void **)&ops->validate = macvlan_validate;
46580+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46581+ *(const void **)&ops->policy = macvlan_policy;
46582+ *(void **)&ops->changelink = macvlan_changelink;
46583+ *(void **)&ops->get_size = macvlan_get_size;
46584+ *(void **)&ops->fill_info = macvlan_fill_info;
46585+ pax_close_kernel();
46586
46587 return rtnl_link_register(ops);
46588 };
46589@@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46590 return NOTIFY_DONE;
46591 }
46592
46593-static struct notifier_block macvlan_notifier_block __read_mostly = {
46594+static struct notifier_block macvlan_notifier_block = {
46595 .notifier_call = macvlan_device_event,
46596 };
46597
46598diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46599index 3381c4f..dea5fd5 100644
46600--- a/drivers/net/macvtap.c
46601+++ b/drivers/net/macvtap.c
46602@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46603 }
46604
46605 ret = 0;
46606- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46607+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46608 put_user(q->flags, &ifr->ifr_flags))
46609 ret = -EFAULT;
46610 macvtap_put_vlan(vlan);
46611@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46612 return NOTIFY_DONE;
46613 }
46614
46615-static struct notifier_block macvtap_notifier_block __read_mostly = {
46616+static struct notifier_block macvtap_notifier_block = {
46617 .notifier_call = macvtap_device_event,
46618 };
46619
46620diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46621index 3c41a83..5fe2d7f 100644
46622--- a/drivers/net/ppp/ppp_generic.c
46623+++ b/drivers/net/ppp/ppp_generic.c
46624@@ -1016,7 +1016,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46625 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46626 struct ppp_stats stats;
46627 struct ppp_comp_stats cstats;
46628- char *vers;
46629
46630 switch (cmd) {
46631 case SIOCGPPPSTATS:
46632@@ -1038,8 +1037,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46633 break;
46634
46635 case SIOCGPPPVER:
46636- vers = PPP_VERSION;
46637- if (copy_to_user(addr, vers, strlen(vers) + 1))
46638+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46639 break;
46640 err = 0;
46641 break;
46642diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46643index 1252d9c..80e660b 100644
46644--- a/drivers/net/slip/slhc.c
46645+++ b/drivers/net/slip/slhc.c
46646@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46647 register struct tcphdr *thp;
46648 register struct iphdr *ip;
46649 register struct cstate *cs;
46650- int len, hdrlen;
46651+ long len, hdrlen;
46652 unsigned char *cp = icp;
46653
46654 /* We've got a compressed packet; read the change byte */
46655diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46656index ce4989b..b40b328 100644
46657--- a/drivers/net/team/team.c
46658+++ b/drivers/net/team/team.c
46659@@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46660 return NOTIFY_DONE;
46661 }
46662
46663-static struct notifier_block team_notifier_block __read_mostly = {
46664+static struct notifier_block team_notifier_block = {
46665 .notifier_call = team_device_event,
46666 };
46667
46668diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46669index ee328ba..c4a0041 100644
46670--- a/drivers/net/tun.c
46671+++ b/drivers/net/tun.c
46672@@ -1876,7 +1876,7 @@ unlock:
46673 }
46674
46675 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46676- unsigned long arg, int ifreq_len)
46677+ unsigned long arg, size_t ifreq_len)
46678 {
46679 struct tun_file *tfile = file->private_data;
46680 struct tun_struct *tun;
46681@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46682 unsigned int ifindex;
46683 int ret;
46684
46685+ if (ifreq_len > sizeof ifr)
46686+ return -EFAULT;
46687+
46688 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46689 if (copy_from_user(&ifr, argp, ifreq_len))
46690 return -EFAULT;
46691diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46692index 660bd5e..ac59452 100644
46693--- a/drivers/net/usb/hso.c
46694+++ b/drivers/net/usb/hso.c
46695@@ -71,7 +71,7 @@
46696 #include <asm/byteorder.h>
46697 #include <linux/serial_core.h>
46698 #include <linux/serial.h>
46699-
46700+#include <asm/local.h>
46701
46702 #define MOD_AUTHOR "Option Wireless"
46703 #define MOD_DESCRIPTION "USB High Speed Option driver"
46704@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46705 struct urb *urb;
46706
46707 urb = serial->rx_urb[0];
46708- if (serial->port.count > 0) {
46709+ if (atomic_read(&serial->port.count) > 0) {
46710 count = put_rxbuf_data(urb, serial);
46711 if (count == -1)
46712 return;
46713@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46714 DUMP1(urb->transfer_buffer, urb->actual_length);
46715
46716 /* Anyone listening? */
46717- if (serial->port.count == 0)
46718+ if (atomic_read(&serial->port.count) == 0)
46719 return;
46720
46721 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46722@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46723 tty_port_tty_set(&serial->port, tty);
46724
46725 /* check for port already opened, if not set the termios */
46726- serial->port.count++;
46727- if (serial->port.count == 1) {
46728+ if (atomic_inc_return(&serial->port.count) == 1) {
46729 serial->rx_state = RX_IDLE;
46730 /* Force default termio settings */
46731 _hso_serial_set_termios(tty, NULL);
46732@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46733 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46734 if (result) {
46735 hso_stop_serial_device(serial->parent);
46736- serial->port.count--;
46737+ atomic_dec(&serial->port.count);
46738 kref_put(&serial->parent->ref, hso_serial_ref_free);
46739 }
46740 } else {
46741@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46742
46743 /* reset the rts and dtr */
46744 /* do the actual close */
46745- serial->port.count--;
46746+ atomic_dec(&serial->port.count);
46747
46748- if (serial->port.count <= 0) {
46749- serial->port.count = 0;
46750+ if (atomic_read(&serial->port.count) <= 0) {
46751+ atomic_set(&serial->port.count, 0);
46752 tty_port_tty_set(&serial->port, NULL);
46753 if (!usb_gone)
46754 hso_stop_serial_device(serial->parent);
46755@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46756
46757 /* the actual setup */
46758 spin_lock_irqsave(&serial->serial_lock, flags);
46759- if (serial->port.count)
46760+ if (atomic_read(&serial->port.count))
46761 _hso_serial_set_termios(tty, old);
46762 else
46763 tty->termios = *old;
46764@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46765 D1("Pending read interrupt on port %d\n", i);
46766 spin_lock(&serial->serial_lock);
46767 if (serial->rx_state == RX_IDLE &&
46768- serial->port.count > 0) {
46769+ atomic_read(&serial->port.count) > 0) {
46770 /* Setup and send a ctrl req read on
46771 * port i */
46772 if (!serial->rx_urb_filled[0]) {
46773@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46774 /* Start all serial ports */
46775 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46776 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46777- if (dev2ser(serial_table[i])->port.count) {
46778+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46779 result =
46780 hso_start_serial_device(serial_table[i], GFP_NOIO);
46781 hso_kick_transmit(dev2ser(serial_table[i]));
46782diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46783index d2c0070..3c3da43 100644
46784--- a/drivers/net/usb/r8152.c
46785+++ b/drivers/net/usb/r8152.c
46786@@ -567,7 +567,7 @@ struct r8152 {
46787 void (*up)(struct r8152 *);
46788 void (*down)(struct r8152 *);
46789 void (*unload)(struct r8152 *);
46790- } rtl_ops;
46791+ } __no_const rtl_ops;
46792
46793 int intr_interval;
46794 u32 saved_wolopts;
46795diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46796index a2515887..6d13233 100644
46797--- a/drivers/net/usb/sierra_net.c
46798+++ b/drivers/net/usb/sierra_net.c
46799@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46800 /* atomic counter partially included in MAC address to make sure 2 devices
46801 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46802 */
46803-static atomic_t iface_counter = ATOMIC_INIT(0);
46804+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46805
46806 /*
46807 * SYNC Timer Delay definition used to set the expiry time
46808@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46809 dev->net->netdev_ops = &sierra_net_device_ops;
46810
46811 /* change MAC addr to include, ifacenum, and to be unique */
46812- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46813+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46814 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46815
46816 /* we will have to manufacture ethernet headers, prepare template */
46817diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
46818index 8a852b5..668a4b6 100644
46819--- a/drivers/net/virtio_net.c
46820+++ b/drivers/net/virtio_net.c
46821@@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
46822 #define RECEIVE_AVG_WEIGHT 64
46823
46824 /* Minimum alignment for mergeable packet buffers. */
46825-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
46826+#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
46827
46828 #define VIRTNET_DRIVER_VERSION "1.0.0"
46829
46830diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46831index 77dcf92..549924a 100644
46832--- a/drivers/net/vxlan.c
46833+++ b/drivers/net/vxlan.c
46834@@ -2839,7 +2839,7 @@ nla_put_failure:
46835 return -EMSGSIZE;
46836 }
46837
46838-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46839+static struct rtnl_link_ops vxlan_link_ops = {
46840 .kind = "vxlan",
46841 .maxtype = IFLA_VXLAN_MAX,
46842 .policy = vxlan_policy,
46843@@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46844 return NOTIFY_DONE;
46845 }
46846
46847-static struct notifier_block vxlan_notifier_block __read_mostly = {
46848+static struct notifier_block vxlan_notifier_block = {
46849 .notifier_call = vxlan_lowerdev_event,
46850 };
46851
46852diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46853index 5920c99..ff2e4a5 100644
46854--- a/drivers/net/wan/lmc/lmc_media.c
46855+++ b/drivers/net/wan/lmc/lmc_media.c
46856@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46857 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46858
46859 lmc_media_t lmc_ds3_media = {
46860- lmc_ds3_init, /* special media init stuff */
46861- lmc_ds3_default, /* reset to default state */
46862- lmc_ds3_set_status, /* reset status to state provided */
46863- lmc_dummy_set_1, /* set clock source */
46864- lmc_dummy_set2_1, /* set line speed */
46865- lmc_ds3_set_100ft, /* set cable length */
46866- lmc_ds3_set_scram, /* set scrambler */
46867- lmc_ds3_get_link_status, /* get link status */
46868- lmc_dummy_set_1, /* set link status */
46869- lmc_ds3_set_crc_length, /* set CRC length */
46870- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46871- lmc_ds3_watchdog
46872+ .init = lmc_ds3_init, /* special media init stuff */
46873+ .defaults = lmc_ds3_default, /* reset to default state */
46874+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46875+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46876+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46877+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46878+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46879+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46880+ .set_link_status = lmc_dummy_set_1, /* set link status */
46881+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46882+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46883+ .watchdog = lmc_ds3_watchdog
46884 };
46885
46886 lmc_media_t lmc_hssi_media = {
46887- lmc_hssi_init, /* special media init stuff */
46888- lmc_hssi_default, /* reset to default state */
46889- lmc_hssi_set_status, /* reset status to state provided */
46890- lmc_hssi_set_clock, /* set clock source */
46891- lmc_dummy_set2_1, /* set line speed */
46892- lmc_dummy_set_1, /* set cable length */
46893- lmc_dummy_set_1, /* set scrambler */
46894- lmc_hssi_get_link_status, /* get link status */
46895- lmc_hssi_set_link_status, /* set link status */
46896- lmc_hssi_set_crc_length, /* set CRC length */
46897- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46898- lmc_hssi_watchdog
46899+ .init = lmc_hssi_init, /* special media init stuff */
46900+ .defaults = lmc_hssi_default, /* reset to default state */
46901+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46902+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46903+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46904+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46905+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46906+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46907+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46908+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46909+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46910+ .watchdog = lmc_hssi_watchdog
46911 };
46912
46913-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46914- lmc_ssi_default, /* reset to default state */
46915- lmc_ssi_set_status, /* reset status to state provided */
46916- lmc_ssi_set_clock, /* set clock source */
46917- lmc_ssi_set_speed, /* set line speed */
46918- lmc_dummy_set_1, /* set cable length */
46919- lmc_dummy_set_1, /* set scrambler */
46920- lmc_ssi_get_link_status, /* get link status */
46921- lmc_ssi_set_link_status, /* set link status */
46922- lmc_ssi_set_crc_length, /* set CRC length */
46923- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46924- lmc_ssi_watchdog
46925+lmc_media_t lmc_ssi_media = {
46926+ .init = lmc_ssi_init, /* special media init stuff */
46927+ .defaults = lmc_ssi_default, /* reset to default state */
46928+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46929+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46930+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46931+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46932+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46933+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46934+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46935+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46936+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46937+ .watchdog = lmc_ssi_watchdog
46938 };
46939
46940 lmc_media_t lmc_t1_media = {
46941- lmc_t1_init, /* special media init stuff */
46942- lmc_t1_default, /* reset to default state */
46943- lmc_t1_set_status, /* reset status to state provided */
46944- lmc_t1_set_clock, /* set clock source */
46945- lmc_dummy_set2_1, /* set line speed */
46946- lmc_dummy_set_1, /* set cable length */
46947- lmc_dummy_set_1, /* set scrambler */
46948- lmc_t1_get_link_status, /* get link status */
46949- lmc_dummy_set_1, /* set link status */
46950- lmc_t1_set_crc_length, /* set CRC length */
46951- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46952- lmc_t1_watchdog
46953+ .init = lmc_t1_init, /* special media init stuff */
46954+ .defaults = lmc_t1_default, /* reset to default state */
46955+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46956+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46957+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46958+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46959+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46960+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46961+ .set_link_status = lmc_dummy_set_1, /* set link status */
46962+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46963+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46964+ .watchdog = lmc_t1_watchdog
46965 };
46966
46967 static void
46968diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
46969index 5895f19..fa9fdfa 100644
46970--- a/drivers/net/wan/x25_asy.c
46971+++ b/drivers/net/wan/x25_asy.c
46972@@ -122,8 +122,12 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu)
46973 {
46974 struct x25_asy *sl = netdev_priv(dev);
46975 unsigned char *xbuff, *rbuff;
46976- int len = 2 * newmtu;
46977+ int len;
46978
46979+ if (newmtu > 65534)
46980+ return -EINVAL;
46981+
46982+ len = 2 * newmtu;
46983 xbuff = kmalloc(len + 4, GFP_ATOMIC);
46984 rbuff = kmalloc(len + 4, GFP_ATOMIC);
46985
46986diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46987index feacc3b..5bac0de 100644
46988--- a/drivers/net/wan/z85230.c
46989+++ b/drivers/net/wan/z85230.c
46990@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46991
46992 struct z8530_irqhandler z8530_sync =
46993 {
46994- z8530_rx,
46995- z8530_tx,
46996- z8530_status
46997+ .rx = z8530_rx,
46998+ .tx = z8530_tx,
46999+ .status = z8530_status
47000 };
47001
47002 EXPORT_SYMBOL(z8530_sync);
47003@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
47004 }
47005
47006 static struct z8530_irqhandler z8530_dma_sync = {
47007- z8530_dma_rx,
47008- z8530_dma_tx,
47009- z8530_dma_status
47010+ .rx = z8530_dma_rx,
47011+ .tx = z8530_dma_tx,
47012+ .status = z8530_dma_status
47013 };
47014
47015 static struct z8530_irqhandler z8530_txdma_sync = {
47016- z8530_rx,
47017- z8530_dma_tx,
47018- z8530_dma_status
47019+ .rx = z8530_rx,
47020+ .tx = z8530_dma_tx,
47021+ .status = z8530_dma_status
47022 };
47023
47024 /**
47025@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47026
47027 struct z8530_irqhandler z8530_nop=
47028 {
47029- z8530_rx_clear,
47030- z8530_tx_clear,
47031- z8530_status_clear
47032+ .rx = z8530_rx_clear,
47033+ .tx = z8530_tx_clear,
47034+ .status = z8530_status_clear
47035 };
47036
47037
47038diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47039index 0b60295..b8bfa5b 100644
47040--- a/drivers/net/wimax/i2400m/rx.c
47041+++ b/drivers/net/wimax/i2400m/rx.c
47042@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47043 if (i2400m->rx_roq == NULL)
47044 goto error_roq_alloc;
47045
47046- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47047+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47048 GFP_KERNEL);
47049 if (rd == NULL) {
47050 result = -ENOMEM;
47051diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47052index 64747d4..17c4cf3 100644
47053--- a/drivers/net/wireless/airo.c
47054+++ b/drivers/net/wireless/airo.c
47055@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47056 struct airo_info *ai = dev->ml_priv;
47057 int ridcode;
47058 int enabled;
47059- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47060+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47061 unsigned char *iobuf;
47062
47063 /* Only super-user can write RIDs */
47064diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47065index 99b3bfa..9559372 100644
47066--- a/drivers/net/wireless/at76c50x-usb.c
47067+++ b/drivers/net/wireless/at76c50x-usb.c
47068@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47069 }
47070
47071 /* Convert timeout from the DFU status to jiffies */
47072-static inline unsigned long at76_get_timeout(struct dfu_status *s)
47073+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47074 {
47075 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47076 | (s->poll_timeout[1] << 8)
47077diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47078index 7f1bccd..ca2ffca 100644
47079--- a/drivers/net/wireless/ath/ath10k/htc.c
47080+++ b/drivers/net/wireless/ath/ath10k/htc.c
47081@@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47082 /* registered target arrival callback from the HIF layer */
47083 int ath10k_htc_init(struct ath10k *ar)
47084 {
47085- struct ath10k_hif_cb htc_callbacks;
47086+ static struct ath10k_hif_cb htc_callbacks = {
47087+ .rx_completion = ath10k_htc_rx_completion_handler,
47088+ .tx_completion = ath10k_htc_tx_completion_handler,
47089+ };
47090 struct ath10k_htc_ep *ep = NULL;
47091 struct ath10k_htc *htc = &ar->htc;
47092
47093@@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
47094 ath10k_htc_reset_endpoint_states(htc);
47095
47096 /* setup HIF layer callbacks */
47097- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47098- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47099 htc->ar = ar;
47100
47101 /* Get HIF default pipe for HTC message exchange */
47102diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47103index 4716d33..a688310 100644
47104--- a/drivers/net/wireless/ath/ath10k/htc.h
47105+++ b/drivers/net/wireless/ath/ath10k/htc.h
47106@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47107
47108 struct ath10k_htc_ops {
47109 void (*target_send_suspend_complete)(struct ath10k *ar);
47110-};
47111+} __no_const;
47112
47113 struct ath10k_htc_ep_ops {
47114 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47115 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47116 void (*ep_tx_credits)(struct ath10k *);
47117-};
47118+} __no_const;
47119
47120 /* service connection information */
47121 struct ath10k_htc_svc_conn_req {
47122diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47123index 741b38d..b7ae41b 100644
47124--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47125+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47126@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47127 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47128 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47129
47130- ACCESS_ONCE(ads->ds_link) = i->link;
47131- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47132+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
47133+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47134
47135 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47136 ctl6 = SM(i->keytype, AR_EncrType);
47137@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47138
47139 if ((i->is_first || i->is_last) &&
47140 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47141- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47142+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47143 | set11nTries(i->rates, 1)
47144 | set11nTries(i->rates, 2)
47145 | set11nTries(i->rates, 3)
47146 | (i->dur_update ? AR_DurUpdateEna : 0)
47147 | SM(0, AR_BurstDur);
47148
47149- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47150+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47151 | set11nRate(i->rates, 1)
47152 | set11nRate(i->rates, 2)
47153 | set11nRate(i->rates, 3);
47154 } else {
47155- ACCESS_ONCE(ads->ds_ctl2) = 0;
47156- ACCESS_ONCE(ads->ds_ctl3) = 0;
47157+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47158+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47159 }
47160
47161 if (!i->is_first) {
47162- ACCESS_ONCE(ads->ds_ctl0) = 0;
47163- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47164- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47165+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47166+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47167+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47168 return;
47169 }
47170
47171@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47172 break;
47173 }
47174
47175- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47176+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47177 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47178 | SM(i->txpower, AR_XmitPower)
47179 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47180@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47181 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47182 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47183
47184- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47185- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47186+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47187+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47188
47189 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47190 return;
47191
47192- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47193+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47194 | set11nPktDurRTSCTS(i->rates, 1);
47195
47196- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47197+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47198 | set11nPktDurRTSCTS(i->rates, 3);
47199
47200- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47201+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47202 | set11nRateFlags(i->rates, 1)
47203 | set11nRateFlags(i->rates, 2)
47204 | set11nRateFlags(i->rates, 3)
47205diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47206index 729ffbf..49f50e3 100644
47207--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47208+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47209@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47210 (i->qcu << AR_TxQcuNum_S) | desc_len;
47211
47212 checksum += val;
47213- ACCESS_ONCE(ads->info) = val;
47214+ ACCESS_ONCE_RW(ads->info) = val;
47215
47216 checksum += i->link;
47217- ACCESS_ONCE(ads->link) = i->link;
47218+ ACCESS_ONCE_RW(ads->link) = i->link;
47219
47220 checksum += i->buf_addr[0];
47221- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47222+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47223 checksum += i->buf_addr[1];
47224- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47225+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47226 checksum += i->buf_addr[2];
47227- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47228+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47229 checksum += i->buf_addr[3];
47230- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47231+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47232
47233 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47234- ACCESS_ONCE(ads->ctl3) = val;
47235+ ACCESS_ONCE_RW(ads->ctl3) = val;
47236 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47237- ACCESS_ONCE(ads->ctl5) = val;
47238+ ACCESS_ONCE_RW(ads->ctl5) = val;
47239 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47240- ACCESS_ONCE(ads->ctl7) = val;
47241+ ACCESS_ONCE_RW(ads->ctl7) = val;
47242 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47243- ACCESS_ONCE(ads->ctl9) = val;
47244+ ACCESS_ONCE_RW(ads->ctl9) = val;
47245
47246 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47247- ACCESS_ONCE(ads->ctl10) = checksum;
47248+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
47249
47250 if (i->is_first || i->is_last) {
47251- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47252+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47253 | set11nTries(i->rates, 1)
47254 | set11nTries(i->rates, 2)
47255 | set11nTries(i->rates, 3)
47256 | (i->dur_update ? AR_DurUpdateEna : 0)
47257 | SM(0, AR_BurstDur);
47258
47259- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47260+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47261 | set11nRate(i->rates, 1)
47262 | set11nRate(i->rates, 2)
47263 | set11nRate(i->rates, 3);
47264 } else {
47265- ACCESS_ONCE(ads->ctl13) = 0;
47266- ACCESS_ONCE(ads->ctl14) = 0;
47267+ ACCESS_ONCE_RW(ads->ctl13) = 0;
47268+ ACCESS_ONCE_RW(ads->ctl14) = 0;
47269 }
47270
47271 ads->ctl20 = 0;
47272@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47273
47274 ctl17 = SM(i->keytype, AR_EncrType);
47275 if (!i->is_first) {
47276- ACCESS_ONCE(ads->ctl11) = 0;
47277- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47278- ACCESS_ONCE(ads->ctl15) = 0;
47279- ACCESS_ONCE(ads->ctl16) = 0;
47280- ACCESS_ONCE(ads->ctl17) = ctl17;
47281- ACCESS_ONCE(ads->ctl18) = 0;
47282- ACCESS_ONCE(ads->ctl19) = 0;
47283+ ACCESS_ONCE_RW(ads->ctl11) = 0;
47284+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47285+ ACCESS_ONCE_RW(ads->ctl15) = 0;
47286+ ACCESS_ONCE_RW(ads->ctl16) = 0;
47287+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47288+ ACCESS_ONCE_RW(ads->ctl18) = 0;
47289+ ACCESS_ONCE_RW(ads->ctl19) = 0;
47290 return;
47291 }
47292
47293- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47294+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47295 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47296 | SM(i->txpower, AR_XmitPower)
47297 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47298@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47299 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47300 ctl12 |= SM(val, AR_PAPRDChainMask);
47301
47302- ACCESS_ONCE(ads->ctl12) = ctl12;
47303- ACCESS_ONCE(ads->ctl17) = ctl17;
47304+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47305+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47306
47307- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47308+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47309 | set11nPktDurRTSCTS(i->rates, 1);
47310
47311- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47312+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47313 | set11nPktDurRTSCTS(i->rates, 3);
47314
47315- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47316+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47317 | set11nRateFlags(i->rates, 1)
47318 | set11nRateFlags(i->rates, 2)
47319 | set11nRateFlags(i->rates, 3)
47320 | SM(i->rtscts_rate, AR_RTSCTSRate);
47321
47322- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47323+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47324 }
47325
47326 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47327diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47328index 0acd4b5..0591c91 100644
47329--- a/drivers/net/wireless/ath/ath9k/hw.h
47330+++ b/drivers/net/wireless/ath/ath9k/hw.h
47331@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47332
47333 /* ANI */
47334 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47335-};
47336+} __no_const;
47337
47338 /**
47339 * struct ath_spec_scan - parameters for Atheros spectral scan
47340@@ -706,7 +706,7 @@ struct ath_hw_ops {
47341 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47342 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47343 #endif
47344-};
47345+} __no_const;
47346
47347 struct ath_nf_limits {
47348 s16 max;
47349diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47350index 92190da..f3a4c4c 100644
47351--- a/drivers/net/wireless/b43/phy_lp.c
47352+++ b/drivers/net/wireless/b43/phy_lp.c
47353@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47354 {
47355 struct ssb_bus *bus = dev->dev->sdev->bus;
47356
47357- static const struct b206x_channel *chandata = NULL;
47358+ const struct b206x_channel *chandata = NULL;
47359 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47360 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47361 u16 old_comm15, scale;
47362diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47363index dc1d20c..f7a4f06 100644
47364--- a/drivers/net/wireless/iwlegacy/3945-mac.c
47365+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47366@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47367 */
47368 if (il3945_mod_params.disable_hw_scan) {
47369 D_INFO("Disabling hw_scan\n");
47370- il3945_mac_ops.hw_scan = NULL;
47371+ pax_open_kernel();
47372+ *(void **)&il3945_mac_ops.hw_scan = NULL;
47373+ pax_close_kernel();
47374 }
47375
47376 D_INFO("*** LOAD DRIVER ***\n");
47377diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47378index d2fe259..0c4c682 100644
47379--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47380+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47381@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47382 {
47383 struct iwl_priv *priv = file->private_data;
47384 char buf[64];
47385- int buf_size;
47386+ size_t buf_size;
47387 u32 offset, len;
47388
47389 memset(buf, 0, sizeof(buf));
47390@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47391 struct iwl_priv *priv = file->private_data;
47392
47393 char buf[8];
47394- int buf_size;
47395+ size_t buf_size;
47396 u32 reset_flag;
47397
47398 memset(buf, 0, sizeof(buf));
47399@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47400 {
47401 struct iwl_priv *priv = file->private_data;
47402 char buf[8];
47403- int buf_size;
47404+ size_t buf_size;
47405 int ht40;
47406
47407 memset(buf, 0, sizeof(buf));
47408@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47409 {
47410 struct iwl_priv *priv = file->private_data;
47411 char buf[8];
47412- int buf_size;
47413+ size_t buf_size;
47414 int value;
47415
47416 memset(buf, 0, sizeof(buf));
47417@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47418 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47419 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47420
47421-static const char *fmt_value = " %-30s %10u\n";
47422-static const char *fmt_hex = " %-30s 0x%02X\n";
47423-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47424-static const char *fmt_header =
47425+static const char fmt_value[] = " %-30s %10u\n";
47426+static const char fmt_hex[] = " %-30s 0x%02X\n";
47427+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47428+static const char fmt_header[] =
47429 "%-32s current cumulative delta max\n";
47430
47431 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47432@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47433 {
47434 struct iwl_priv *priv = file->private_data;
47435 char buf[8];
47436- int buf_size;
47437+ size_t buf_size;
47438 int clear;
47439
47440 memset(buf, 0, sizeof(buf));
47441@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47442 {
47443 struct iwl_priv *priv = file->private_data;
47444 char buf[8];
47445- int buf_size;
47446+ size_t buf_size;
47447 int trace;
47448
47449 memset(buf, 0, sizeof(buf));
47450@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47451 {
47452 struct iwl_priv *priv = file->private_data;
47453 char buf[8];
47454- int buf_size;
47455+ size_t buf_size;
47456 int missed;
47457
47458 memset(buf, 0, sizeof(buf));
47459@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47460
47461 struct iwl_priv *priv = file->private_data;
47462 char buf[8];
47463- int buf_size;
47464+ size_t buf_size;
47465 int plcp;
47466
47467 memset(buf, 0, sizeof(buf));
47468@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47469
47470 struct iwl_priv *priv = file->private_data;
47471 char buf[8];
47472- int buf_size;
47473+ size_t buf_size;
47474 int flush;
47475
47476 memset(buf, 0, sizeof(buf));
47477@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47478
47479 struct iwl_priv *priv = file->private_data;
47480 char buf[8];
47481- int buf_size;
47482+ size_t buf_size;
47483 int rts;
47484
47485 if (!priv->cfg->ht_params)
47486@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47487 {
47488 struct iwl_priv *priv = file->private_data;
47489 char buf[8];
47490- int buf_size;
47491+ size_t buf_size;
47492
47493 memset(buf, 0, sizeof(buf));
47494 buf_size = min(count, sizeof(buf) - 1);
47495@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47496 struct iwl_priv *priv = file->private_data;
47497 u32 event_log_flag;
47498 char buf[8];
47499- int buf_size;
47500+ size_t buf_size;
47501
47502 /* check that the interface is up */
47503 if (!iwl_is_ready(priv))
47504@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47505 struct iwl_priv *priv = file->private_data;
47506 char buf[8];
47507 u32 calib_disabled;
47508- int buf_size;
47509+ size_t buf_size;
47510
47511 memset(buf, 0, sizeof(buf));
47512 buf_size = min(count, sizeof(buf) - 1);
47513diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47514index 6a6df71..eb5c93a 100644
47515--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47516+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47517@@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47518 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47519 {
47520 struct iwl_nvm_data *data = priv->nvm_data;
47521- char *debug_msg;
47522+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47523
47524 if (data->sku_cap_11n_enable &&
47525 !priv->cfg->ht_params) {
47526@@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47527 return -EINVAL;
47528 }
47529
47530- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47531 IWL_DEBUG_INFO(priv, debug_msg,
47532 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47533 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47534diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47535index 295b24c..cb4f823 100644
47536--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47537+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47538@@ -1558,7 +1558,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47539 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47540
47541 char buf[8];
47542- int buf_size;
47543+ size_t buf_size;
47544 u32 reset_flag;
47545
47546 memset(buf, 0, sizeof(buf));
47547@@ -1579,7 +1579,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47548 {
47549 struct iwl_trans *trans = file->private_data;
47550 char buf[8];
47551- int buf_size;
47552+ size_t buf_size;
47553 int csr;
47554
47555 memset(buf, 0, sizeof(buf));
47556diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47557index 9d7a52f..2729a99 100644
47558--- a/drivers/net/wireless/mac80211_hwsim.c
47559+++ b/drivers/net/wireless/mac80211_hwsim.c
47560@@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47561 if (channels < 1)
47562 return -EINVAL;
47563
47564- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47565- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47566- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47567- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47568- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47569- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47570- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47571- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47572- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47573- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47574- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47575- mac80211_hwsim_assign_vif_chanctx;
47576- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47577- mac80211_hwsim_unassign_vif_chanctx;
47578+ pax_open_kernel();
47579+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47580+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47581+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47582+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47583+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47584+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47585+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47586+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47587+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47588+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47589+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47590+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47591+ pax_close_kernel();
47592
47593 spin_lock_init(&hwsim_radio_lock);
47594 INIT_LIST_HEAD(&hwsim_radios);
47595diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47596index 39d22a1..4ec8612 100644
47597--- a/drivers/net/wireless/rndis_wlan.c
47598+++ b/drivers/net/wireless/rndis_wlan.c
47599@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47600
47601 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47602
47603- if (rts_threshold < 0 || rts_threshold > 2347)
47604+ if (rts_threshold > 2347)
47605 rts_threshold = 2347;
47606
47607 tmp = cpu_to_le32(rts_threshold);
47608diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47609index 5d45a1a..6f5f041 100644
47610--- a/drivers/net/wireless/rt2x00/rt2x00.h
47611+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47612@@ -375,7 +375,7 @@ struct rt2x00_intf {
47613 * for hardware which doesn't support hardware
47614 * sequence counting.
47615 */
47616- atomic_t seqno;
47617+ atomic_unchecked_t seqno;
47618 };
47619
47620 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47621diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47622index 5642ccc..01f03eb 100644
47623--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47624+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47625@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47626 * sequence counter given by mac80211.
47627 */
47628 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47629- seqno = atomic_add_return(0x10, &intf->seqno);
47630+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47631 else
47632- seqno = atomic_read(&intf->seqno);
47633+ seqno = atomic_read_unchecked(&intf->seqno);
47634
47635 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47636 hdr->seq_ctrl |= cpu_to_le16(seqno);
47637diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47638index b661f896..ddf7d2b 100644
47639--- a/drivers/net/wireless/ti/wl1251/sdio.c
47640+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47641@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47642
47643 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47644
47645- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47646- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47647+ pax_open_kernel();
47648+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47649+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47650+ pax_close_kernel();
47651
47652 wl1251_info("using dedicated interrupt line");
47653 } else {
47654- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47655- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47656+ pax_open_kernel();
47657+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47658+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47659+ pax_close_kernel();
47660
47661 wl1251_info("using SDIO interrupt");
47662 }
47663diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47664index d50dfac..0a6f5be3 100644
47665--- a/drivers/net/wireless/ti/wl12xx/main.c
47666+++ b/drivers/net/wireless/ti/wl12xx/main.c
47667@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47668 sizeof(wl->conf.mem));
47669
47670 /* read data preparation is only needed by wl127x */
47671- wl->ops->prepare_read = wl127x_prepare_read;
47672+ pax_open_kernel();
47673+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47674+ pax_close_kernel();
47675
47676 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47677 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47678@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47679 sizeof(wl->conf.mem));
47680
47681 /* read data preparation is only needed by wl127x */
47682- wl->ops->prepare_read = wl127x_prepare_read;
47683+ pax_open_kernel();
47684+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47685+ pax_close_kernel();
47686
47687 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47688 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47689diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47690index de5b4fa..7996ec6 100644
47691--- a/drivers/net/wireless/ti/wl18xx/main.c
47692+++ b/drivers/net/wireless/ti/wl18xx/main.c
47693@@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47694 }
47695
47696 if (!checksum_param) {
47697- wl18xx_ops.set_rx_csum = NULL;
47698- wl18xx_ops.init_vif = NULL;
47699+ pax_open_kernel();
47700+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47701+ *(void **)&wl18xx_ops.init_vif = NULL;
47702+ pax_close_kernel();
47703 }
47704
47705 /* Enable 11a Band only if we have 5G antennas */
47706diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47707index a912dc0..a8225ba 100644
47708--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47709+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47710@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47711 {
47712 struct zd_usb *usb = urb->context;
47713 struct zd_usb_interrupt *intr = &usb->intr;
47714- int len;
47715+ unsigned int len;
47716 u16 int_num;
47717
47718 ZD_ASSERT(in_interrupt());
47719diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47720index 683671a..4519fc2 100644
47721--- a/drivers/nfc/nfcwilink.c
47722+++ b/drivers/nfc/nfcwilink.c
47723@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47724
47725 static int nfcwilink_probe(struct platform_device *pdev)
47726 {
47727- static struct nfcwilink *drv;
47728+ struct nfcwilink *drv;
47729 int rc;
47730 __u32 protocols;
47731
47732diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47733index d93b2b6..ae50401 100644
47734--- a/drivers/oprofile/buffer_sync.c
47735+++ b/drivers/oprofile/buffer_sync.c
47736@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47737 if (cookie == NO_COOKIE)
47738 offset = pc;
47739 if (cookie == INVALID_COOKIE) {
47740- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47741+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47742 offset = pc;
47743 }
47744 if (cookie != last_cookie) {
47745@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47746 /* add userspace sample */
47747
47748 if (!mm) {
47749- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47750+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47751 return 0;
47752 }
47753
47754 cookie = lookup_dcookie(mm, s->eip, &offset);
47755
47756 if (cookie == INVALID_COOKIE) {
47757- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47758+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47759 return 0;
47760 }
47761
47762@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47763 /* ignore backtraces if failed to add a sample */
47764 if (state == sb_bt_start) {
47765 state = sb_bt_ignore;
47766- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47767+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47768 }
47769 }
47770 release_mm(mm);
47771diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47772index c0cc4e7..44d4e54 100644
47773--- a/drivers/oprofile/event_buffer.c
47774+++ b/drivers/oprofile/event_buffer.c
47775@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47776 }
47777
47778 if (buffer_pos == buffer_size) {
47779- atomic_inc(&oprofile_stats.event_lost_overflow);
47780+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47781 return;
47782 }
47783
47784diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47785index ed2c3ec..deda85a 100644
47786--- a/drivers/oprofile/oprof.c
47787+++ b/drivers/oprofile/oprof.c
47788@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47789 if (oprofile_ops.switch_events())
47790 return;
47791
47792- atomic_inc(&oprofile_stats.multiplex_counter);
47793+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47794 start_switch_worker();
47795 }
47796
47797diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47798index ee2cfce..7f8f699 100644
47799--- a/drivers/oprofile/oprofile_files.c
47800+++ b/drivers/oprofile/oprofile_files.c
47801@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47802
47803 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47804
47805-static ssize_t timeout_read(struct file *file, char __user *buf,
47806+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47807 size_t count, loff_t *offset)
47808 {
47809 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47810diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47811index 59659ce..6c860a0 100644
47812--- a/drivers/oprofile/oprofile_stats.c
47813+++ b/drivers/oprofile/oprofile_stats.c
47814@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47815 cpu_buf->sample_invalid_eip = 0;
47816 }
47817
47818- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47819- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47820- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47821- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47822- atomic_set(&oprofile_stats.multiplex_counter, 0);
47823+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47824+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47825+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47826+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47827+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47828 }
47829
47830
47831diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47832index 1fc622b..8c48fc3 100644
47833--- a/drivers/oprofile/oprofile_stats.h
47834+++ b/drivers/oprofile/oprofile_stats.h
47835@@ -13,11 +13,11 @@
47836 #include <linux/atomic.h>
47837
47838 struct oprofile_stat_struct {
47839- atomic_t sample_lost_no_mm;
47840- atomic_t sample_lost_no_mapping;
47841- atomic_t bt_lost_no_mapping;
47842- atomic_t event_lost_overflow;
47843- atomic_t multiplex_counter;
47844+ atomic_unchecked_t sample_lost_no_mm;
47845+ atomic_unchecked_t sample_lost_no_mapping;
47846+ atomic_unchecked_t bt_lost_no_mapping;
47847+ atomic_unchecked_t event_lost_overflow;
47848+ atomic_unchecked_t multiplex_counter;
47849 };
47850
47851 extern struct oprofile_stat_struct oprofile_stats;
47852diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47853index 3f49345..c750d0b 100644
47854--- a/drivers/oprofile/oprofilefs.c
47855+++ b/drivers/oprofile/oprofilefs.c
47856@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47857
47858 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47859 {
47860- atomic_t *val = file->private_data;
47861- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47862+ atomic_unchecked_t *val = file->private_data;
47863+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47864 }
47865
47866
47867@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47868
47869
47870 int oprofilefs_create_ro_atomic(struct dentry *root,
47871- char const *name, atomic_t *val)
47872+ char const *name, atomic_unchecked_t *val)
47873 {
47874 return __oprofilefs_create_file(root, name,
47875 &atomic_ro_fops, 0444, val);
47876diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47877index 61be1d9..dec05d7 100644
47878--- a/drivers/oprofile/timer_int.c
47879+++ b/drivers/oprofile/timer_int.c
47880@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47881 return NOTIFY_OK;
47882 }
47883
47884-static struct notifier_block __refdata oprofile_cpu_notifier = {
47885+static struct notifier_block oprofile_cpu_notifier = {
47886 .notifier_call = oprofile_cpu_notify,
47887 };
47888
47889diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47890index 92ed045..62d39bd7 100644
47891--- a/drivers/parport/procfs.c
47892+++ b/drivers/parport/procfs.c
47893@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47894
47895 *ppos += len;
47896
47897- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47898+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47899 }
47900
47901 #ifdef CONFIG_PARPORT_1284
47902@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47903
47904 *ppos += len;
47905
47906- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47907+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47908 }
47909 #endif /* IEEE1284.3 support. */
47910
47911diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47912index 8dcccff..35d701d 100644
47913--- a/drivers/pci/hotplug/acpiphp_ibm.c
47914+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47915@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47916 goto init_cleanup;
47917 }
47918
47919- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47920+ pax_open_kernel();
47921+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47922+ pax_close_kernel();
47923 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47924
47925 return retval;
47926diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47927index 7536eef..52dc8fa 100644
47928--- a/drivers/pci/hotplug/cpcihp_generic.c
47929+++ b/drivers/pci/hotplug/cpcihp_generic.c
47930@@ -73,7 +73,6 @@ static u16 port;
47931 static unsigned int enum_bit;
47932 static u8 enum_mask;
47933
47934-static struct cpci_hp_controller_ops generic_hpc_ops;
47935 static struct cpci_hp_controller generic_hpc;
47936
47937 static int __init validate_parameters(void)
47938@@ -139,6 +138,10 @@ static int query_enum(void)
47939 return ((value & enum_mask) == enum_mask);
47940 }
47941
47942+static struct cpci_hp_controller_ops generic_hpc_ops = {
47943+ .query_enum = query_enum,
47944+};
47945+
47946 static int __init cpcihp_generic_init(void)
47947 {
47948 int status;
47949@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47950 pci_dev_put(dev);
47951
47952 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47953- generic_hpc_ops.query_enum = query_enum;
47954 generic_hpc.ops = &generic_hpc_ops;
47955
47956 status = cpci_hp_register_controller(&generic_hpc);
47957diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47958index e8c4a7c..7046f5c 100644
47959--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47960+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47961@@ -59,7 +59,6 @@
47962 /* local variables */
47963 static bool debug;
47964 static bool poll;
47965-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47966 static struct cpci_hp_controller zt5550_hpc;
47967
47968 /* Primary cPCI bus bridge device */
47969@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47970 return 0;
47971 }
47972
47973+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47974+ .query_enum = zt5550_hc_query_enum,
47975+};
47976+
47977 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47978 {
47979 int status;
47980@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47981 dbg("returned from zt5550_hc_config");
47982
47983 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47984- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47985 zt5550_hpc.ops = &zt5550_hpc_ops;
47986 if(!poll) {
47987 zt5550_hpc.irq = hc_dev->irq;
47988 zt5550_hpc.irq_flags = IRQF_SHARED;
47989 zt5550_hpc.dev_id = hc_dev;
47990
47991- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47992- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47993- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47994+ pax_open_kernel();
47995+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47996+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47997+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47998+ pax_open_kernel();
47999 } else {
48000 info("using ENUM# polling mode");
48001 }
48002diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
48003index 76ba8a1..20ca857 100644
48004--- a/drivers/pci/hotplug/cpqphp_nvram.c
48005+++ b/drivers/pci/hotplug/cpqphp_nvram.c
48006@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
48007
48008 void compaq_nvram_init (void __iomem *rom_start)
48009 {
48010+
48011+#ifndef CONFIG_PAX_KERNEXEC
48012 if (rom_start) {
48013 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
48014 }
48015+#endif
48016+
48017 dbg("int15 entry = %p\n", compaq_int15_entry_point);
48018
48019 /* initialize our int15 lock */
48020diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
48021index cfa92a9..29539c5 100644
48022--- a/drivers/pci/hotplug/pci_hotplug_core.c
48023+++ b/drivers/pci/hotplug/pci_hotplug_core.c
48024@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
48025 return -EINVAL;
48026 }
48027
48028- slot->ops->owner = owner;
48029- slot->ops->mod_name = mod_name;
48030+ pax_open_kernel();
48031+ *(struct module **)&slot->ops->owner = owner;
48032+ *(const char **)&slot->ops->mod_name = mod_name;
48033+ pax_close_kernel();
48034
48035 mutex_lock(&pci_hp_mutex);
48036 /*
48037diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48038index 0e0a2ff..29dff57 100644
48039--- a/drivers/pci/hotplug/pciehp_core.c
48040+++ b/drivers/pci/hotplug/pciehp_core.c
48041@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48042 struct slot *slot = ctrl->slot;
48043 struct hotplug_slot *hotplug = NULL;
48044 struct hotplug_slot_info *info = NULL;
48045- struct hotplug_slot_ops *ops = NULL;
48046+ hotplug_slot_ops_no_const *ops = NULL;
48047 char name[SLOT_NAME_SIZE];
48048 int retval = -ENOMEM;
48049
48050diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48051index fb02fc2..83dc2c3 100644
48052--- a/drivers/pci/msi.c
48053+++ b/drivers/pci/msi.c
48054@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48055 {
48056 struct attribute **msi_attrs;
48057 struct attribute *msi_attr;
48058- struct device_attribute *msi_dev_attr;
48059- struct attribute_group *msi_irq_group;
48060+ device_attribute_no_const *msi_dev_attr;
48061+ attribute_group_no_const *msi_irq_group;
48062 const struct attribute_group **msi_irq_groups;
48063 struct msi_desc *entry;
48064 int ret = -ENOMEM;
48065@@ -589,7 +589,7 @@ error_attrs:
48066 count = 0;
48067 msi_attr = msi_attrs[count];
48068 while (msi_attr) {
48069- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48070+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48071 kfree(msi_attr->name);
48072 kfree(msi_dev_attr);
48073 ++count;
48074diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48075index 4e0acef..bd98e31 100644
48076--- a/drivers/pci/pci-sysfs.c
48077+++ b/drivers/pci/pci-sysfs.c
48078@@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48079 {
48080 /* allocate attribute structure, piggyback attribute name */
48081 int name_len = write_combine ? 13 : 10;
48082- struct bin_attribute *res_attr;
48083+ bin_attribute_no_const *res_attr;
48084 int retval;
48085
48086 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48087@@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48088 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48089 {
48090 int retval;
48091- struct bin_attribute *attr;
48092+ bin_attribute_no_const *attr;
48093
48094 /* If the device has VPD, try to expose it in sysfs. */
48095 if (dev->vpd) {
48096@@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48097 {
48098 int retval;
48099 int rom_size = 0;
48100- struct bin_attribute *attr;
48101+ bin_attribute_no_const *attr;
48102
48103 if (!sysfs_initialized)
48104 return -EACCES;
48105diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48106index 6bd0822..35bc2b3 100644
48107--- a/drivers/pci/pci.h
48108+++ b/drivers/pci/pci.h
48109@@ -91,7 +91,7 @@ struct pci_vpd_ops {
48110 struct pci_vpd {
48111 unsigned int len;
48112 const struct pci_vpd_ops *ops;
48113- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48114+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48115 };
48116
48117 int pci_vpd_pci22_init(struct pci_dev *dev);
48118diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48119index e1e7026..d28dd33 100644
48120--- a/drivers/pci/pcie/aspm.c
48121+++ b/drivers/pci/pcie/aspm.c
48122@@ -27,9 +27,9 @@
48123 #define MODULE_PARAM_PREFIX "pcie_aspm."
48124
48125 /* Note: those are not register definitions */
48126-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48127-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48128-#define ASPM_STATE_L1 (4) /* L1 state */
48129+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48130+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48131+#define ASPM_STATE_L1 (4U) /* L1 state */
48132 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48133 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48134
48135diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48136index ef09f5f..49ac62f 100644
48137--- a/drivers/pci/probe.c
48138+++ b/drivers/pci/probe.c
48139@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48140 struct pci_bus_region region, inverted_region;
48141 bool bar_too_big = false, bar_disabled = false;
48142
48143- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48144+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48145
48146 /* No printks while decoding is disabled! */
48147 if (!dev->mmio_always_on) {
48148diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48149index 46d1378..30e452b 100644
48150--- a/drivers/pci/proc.c
48151+++ b/drivers/pci/proc.c
48152@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48153 static int __init pci_proc_init(void)
48154 {
48155 struct pci_dev *dev = NULL;
48156+
48157+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48158+#ifdef CONFIG_GRKERNSEC_PROC_USER
48159+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48160+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48161+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48162+#endif
48163+#else
48164 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48165+#endif
48166 proc_create("devices", 0, proc_bus_pci_dir,
48167 &proc_bus_pci_dev_operations);
48168 proc_initialized = 1;
48169diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48170index 7f3aad0..7d604bb 100644
48171--- a/drivers/platform/chrome/chromeos_laptop.c
48172+++ b/drivers/platform/chrome/chromeos_laptop.c
48173@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48174 .callback = chromeos_laptop_dmi_matched, \
48175 .driver_data = (void *)&board_
48176
48177-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48178+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48179 {
48180 .ident = "Samsung Series 5 550",
48181 .matches = {
48182diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
48183index 541f951..4dfd598 100644
48184--- a/drivers/platform/x86/alienware-wmi.c
48185+++ b/drivers/platform/x86/alienware-wmi.c
48186@@ -132,7 +132,7 @@ struct wmax_led_args {
48187 } __packed;
48188
48189 static struct platform_device *platform_device;
48190-static struct device_attribute *zone_dev_attrs;
48191+static device_attribute_no_const *zone_dev_attrs;
48192 static struct attribute **zone_attrs;
48193 static struct platform_zone *zone_data;
48194
48195@@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
48196 }
48197 };
48198
48199-static struct attribute_group zone_attribute_group = {
48200+static attribute_group_no_const zone_attribute_group = {
48201 .name = "rgb_zones",
48202 };
48203
48204diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48205index c5e082f..d6307a0 100644
48206--- a/drivers/platform/x86/asus-wmi.c
48207+++ b/drivers/platform/x86/asus-wmi.c
48208@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48209 int err;
48210 u32 retval = -1;
48211
48212+#ifdef CONFIG_GRKERNSEC_KMEM
48213+ return -EPERM;
48214+#endif
48215+
48216 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48217
48218 if (err < 0)
48219@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48220 int err;
48221 u32 retval = -1;
48222
48223+#ifdef CONFIG_GRKERNSEC_KMEM
48224+ return -EPERM;
48225+#endif
48226+
48227 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48228 &retval);
48229
48230@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48231 union acpi_object *obj;
48232 acpi_status status;
48233
48234+#ifdef CONFIG_GRKERNSEC_KMEM
48235+ return -EPERM;
48236+#endif
48237+
48238 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48239 1, asus->debug.method_id,
48240 &input, &output);
48241diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48242index 62f8030..c7f2a45 100644
48243--- a/drivers/platform/x86/msi-laptop.c
48244+++ b/drivers/platform/x86/msi-laptop.c
48245@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48246
48247 if (!quirks->ec_read_only) {
48248 /* allow userland write sysfs file */
48249- dev_attr_bluetooth.store = store_bluetooth;
48250- dev_attr_wlan.store = store_wlan;
48251- dev_attr_threeg.store = store_threeg;
48252- dev_attr_bluetooth.attr.mode |= S_IWUSR;
48253- dev_attr_wlan.attr.mode |= S_IWUSR;
48254- dev_attr_threeg.attr.mode |= S_IWUSR;
48255+ pax_open_kernel();
48256+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48257+ *(void **)&dev_attr_wlan.store = store_wlan;
48258+ *(void **)&dev_attr_threeg.store = store_threeg;
48259+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48260+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48261+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48262+ pax_close_kernel();
48263 }
48264
48265 /* disable hardware control by fn key */
48266diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48267index 70222f2..8c8ce66 100644
48268--- a/drivers/platform/x86/msi-wmi.c
48269+++ b/drivers/platform/x86/msi-wmi.c
48270@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48271 static void msi_wmi_notify(u32 value, void *context)
48272 {
48273 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48274- static struct key_entry *key;
48275+ struct key_entry *key;
48276 union acpi_object *obj;
48277 acpi_status status;
48278
48279diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48280index 9c5a074..06c976a 100644
48281--- a/drivers/platform/x86/sony-laptop.c
48282+++ b/drivers/platform/x86/sony-laptop.c
48283@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48284 }
48285
48286 /* High speed charging function */
48287-static struct device_attribute *hsc_handle;
48288+static device_attribute_no_const *hsc_handle;
48289
48290 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48291 struct device_attribute *attr,
48292@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
48293 }
48294
48295 /* low battery function */
48296-static struct device_attribute *lowbatt_handle;
48297+static device_attribute_no_const *lowbatt_handle;
48298
48299 static ssize_t sony_nc_lowbatt_store(struct device *dev,
48300 struct device_attribute *attr,
48301@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
48302 }
48303
48304 /* fan speed function */
48305-static struct device_attribute *fan_handle, *hsf_handle;
48306+static device_attribute_no_const *fan_handle, *hsf_handle;
48307
48308 static ssize_t sony_nc_hsfan_store(struct device *dev,
48309 struct device_attribute *attr,
48310@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
48311 }
48312
48313 /* USB charge function */
48314-static struct device_attribute *uc_handle;
48315+static device_attribute_no_const *uc_handle;
48316
48317 static ssize_t sony_nc_usb_charge_store(struct device *dev,
48318 struct device_attribute *attr,
48319@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
48320 }
48321
48322 /* Panel ID function */
48323-static struct device_attribute *panel_handle;
48324+static device_attribute_no_const *panel_handle;
48325
48326 static ssize_t sony_nc_panelid_show(struct device *dev,
48327 struct device_attribute *attr, char *buffer)
48328@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
48329 }
48330
48331 /* smart connect function */
48332-static struct device_attribute *sc_handle;
48333+static device_attribute_no_const *sc_handle;
48334
48335 static ssize_t sony_nc_smart_conn_store(struct device *dev,
48336 struct device_attribute *attr,
48337diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48338index 15e61c1..40a39c7 100644
48339--- a/drivers/platform/x86/thinkpad_acpi.c
48340+++ b/drivers/platform/x86/thinkpad_acpi.c
48341@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48342 return 0;
48343 }
48344
48345-void static hotkey_mask_warn_incomplete_mask(void)
48346+static void hotkey_mask_warn_incomplete_mask(void)
48347 {
48348 /* log only what the user can fix... */
48349 const u32 wantedmask = hotkey_driver_mask &
48350@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48351 && !tp_features.bright_unkfw)
48352 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48353 }
48354+}
48355
48356 #undef TPACPI_COMPARE_KEY
48357 #undef TPACPI_MAY_SEND_KEY
48358-}
48359
48360 /*
48361 * Polling driver
48362diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48363index 438d4c7..ca8a2fb 100644
48364--- a/drivers/pnp/pnpbios/bioscalls.c
48365+++ b/drivers/pnp/pnpbios/bioscalls.c
48366@@ -59,7 +59,7 @@ do { \
48367 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48368 } while(0)
48369
48370-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48371+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48372 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48373
48374 /*
48375@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48376
48377 cpu = get_cpu();
48378 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48379+
48380+ pax_open_kernel();
48381 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48382+ pax_close_kernel();
48383
48384 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48385 spin_lock_irqsave(&pnp_bios_lock, flags);
48386@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48387 :"memory");
48388 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48389
48390+ pax_open_kernel();
48391 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48392+ pax_close_kernel();
48393+
48394 put_cpu();
48395
48396 /* If we get here and this is set then the PnP BIOS faulted on us. */
48397@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48398 return status;
48399 }
48400
48401-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48402+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48403 {
48404 int i;
48405
48406@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48407 pnp_bios_callpoint.offset = header->fields.pm16offset;
48408 pnp_bios_callpoint.segment = PNP_CS16;
48409
48410+ pax_open_kernel();
48411+
48412 for_each_possible_cpu(i) {
48413 struct desc_struct *gdt = get_cpu_gdt_table(i);
48414 if (!gdt)
48415@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48416 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48417 (unsigned long)__va(header->fields.pm16dseg));
48418 }
48419+
48420+ pax_close_kernel();
48421 }
48422diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48423index 01712cb..782e822 100644
48424--- a/drivers/pnp/resource.c
48425+++ b/drivers/pnp/resource.c
48426@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48427 return 1;
48428
48429 /* check if the resource is valid */
48430- if (*irq < 0 || *irq > 15)
48431+ if (*irq > 15)
48432 return 0;
48433
48434 /* check if the resource is reserved */
48435@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48436 return 1;
48437
48438 /* check if the resource is valid */
48439- if (*dma < 0 || *dma == 4 || *dma > 7)
48440+ if (*dma == 4 || *dma > 7)
48441 return 0;
48442
48443 /* check if the resource is reserved */
48444diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48445index 0c52e2a..3421ab7 100644
48446--- a/drivers/power/pda_power.c
48447+++ b/drivers/power/pda_power.c
48448@@ -37,7 +37,11 @@ static int polling;
48449
48450 #if IS_ENABLED(CONFIG_USB_PHY)
48451 static struct usb_phy *transceiver;
48452-static struct notifier_block otg_nb;
48453+static int otg_handle_notification(struct notifier_block *nb,
48454+ unsigned long event, void *unused);
48455+static struct notifier_block otg_nb = {
48456+ .notifier_call = otg_handle_notification
48457+};
48458 #endif
48459
48460 static struct regulator *ac_draw;
48461@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48462
48463 #if IS_ENABLED(CONFIG_USB_PHY)
48464 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48465- otg_nb.notifier_call = otg_handle_notification;
48466 ret = usb_register_notifier(transceiver, &otg_nb);
48467 if (ret) {
48468 dev_err(dev, "failure to register otg notifier\n");
48469diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48470index cc439fd..8fa30df 100644
48471--- a/drivers/power/power_supply.h
48472+++ b/drivers/power/power_supply.h
48473@@ -16,12 +16,12 @@ struct power_supply;
48474
48475 #ifdef CONFIG_SYSFS
48476
48477-extern void power_supply_init_attrs(struct device_type *dev_type);
48478+extern void power_supply_init_attrs(void);
48479 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48480
48481 #else
48482
48483-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48484+static inline void power_supply_init_attrs(void) {}
48485 #define power_supply_uevent NULL
48486
48487 #endif /* CONFIG_SYSFS */
48488diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48489index 2660664..75fcb04 100644
48490--- a/drivers/power/power_supply_core.c
48491+++ b/drivers/power/power_supply_core.c
48492@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48493 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48494 EXPORT_SYMBOL_GPL(power_supply_notifier);
48495
48496-static struct device_type power_supply_dev_type;
48497+extern const struct attribute_group *power_supply_attr_groups[];
48498+static struct device_type power_supply_dev_type = {
48499+ .groups = power_supply_attr_groups,
48500+};
48501
48502 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48503 struct power_supply *supply)
48504@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48505 return PTR_ERR(power_supply_class);
48506
48507 power_supply_class->dev_uevent = power_supply_uevent;
48508- power_supply_init_attrs(&power_supply_dev_type);
48509+ power_supply_init_attrs();
48510
48511 return 0;
48512 }
48513diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48514index 44420d1..967126e 100644
48515--- a/drivers/power/power_supply_sysfs.c
48516+++ b/drivers/power/power_supply_sysfs.c
48517@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48518 .is_visible = power_supply_attr_is_visible,
48519 };
48520
48521-static const struct attribute_group *power_supply_attr_groups[] = {
48522+const struct attribute_group *power_supply_attr_groups[] = {
48523 &power_supply_attr_group,
48524 NULL,
48525 };
48526
48527-void power_supply_init_attrs(struct device_type *dev_type)
48528+void power_supply_init_attrs(void)
48529 {
48530 int i;
48531
48532- dev_type->groups = power_supply_attr_groups;
48533-
48534 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48535 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48536 }
48537diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48538index 84419af..268ede8 100644
48539--- a/drivers/powercap/powercap_sys.c
48540+++ b/drivers/powercap/powercap_sys.c
48541@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48542 struct device_attribute name_attr;
48543 };
48544
48545+static ssize_t show_constraint_name(struct device *dev,
48546+ struct device_attribute *dev_attr,
48547+ char *buf);
48548+
48549 static struct powercap_constraint_attr
48550- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48551+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48552+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48553+ .power_limit_attr = {
48554+ .attr = {
48555+ .name = NULL,
48556+ .mode = S_IWUSR | S_IRUGO
48557+ },
48558+ .show = show_constraint_power_limit_uw,
48559+ .store = store_constraint_power_limit_uw
48560+ },
48561+
48562+ .time_window_attr = {
48563+ .attr = {
48564+ .name = NULL,
48565+ .mode = S_IWUSR | S_IRUGO
48566+ },
48567+ .show = show_constraint_time_window_us,
48568+ .store = store_constraint_time_window_us
48569+ },
48570+
48571+ .max_power_attr = {
48572+ .attr = {
48573+ .name = NULL,
48574+ .mode = S_IRUGO
48575+ },
48576+ .show = show_constraint_max_power_uw,
48577+ .store = NULL
48578+ },
48579+
48580+ .min_power_attr = {
48581+ .attr = {
48582+ .name = NULL,
48583+ .mode = S_IRUGO
48584+ },
48585+ .show = show_constraint_min_power_uw,
48586+ .store = NULL
48587+ },
48588+
48589+ .max_time_window_attr = {
48590+ .attr = {
48591+ .name = NULL,
48592+ .mode = S_IRUGO
48593+ },
48594+ .show = show_constraint_max_time_window_us,
48595+ .store = NULL
48596+ },
48597+
48598+ .min_time_window_attr = {
48599+ .attr = {
48600+ .name = NULL,
48601+ .mode = S_IRUGO
48602+ },
48603+ .show = show_constraint_min_time_window_us,
48604+ .store = NULL
48605+ },
48606+
48607+ .name_attr = {
48608+ .attr = {
48609+ .name = NULL,
48610+ .mode = S_IRUGO
48611+ },
48612+ .show = show_constraint_name,
48613+ .store = NULL
48614+ }
48615+ }
48616+};
48617
48618 /* A list of powercap control_types */
48619 static LIST_HEAD(powercap_cntrl_list);
48620@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48621 }
48622
48623 static int create_constraint_attribute(int id, const char *name,
48624- int mode,
48625- struct device_attribute *dev_attr,
48626- ssize_t (*show)(struct device *,
48627- struct device_attribute *, char *),
48628- ssize_t (*store)(struct device *,
48629- struct device_attribute *,
48630- const char *, size_t)
48631- )
48632+ struct device_attribute *dev_attr)
48633 {
48634+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48635
48636- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48637- id, name);
48638- if (!dev_attr->attr.name)
48639+ if (!name)
48640 return -ENOMEM;
48641- dev_attr->attr.mode = mode;
48642- dev_attr->show = show;
48643- dev_attr->store = store;
48644+
48645+ pax_open_kernel();
48646+ *(const char **)&dev_attr->attr.name = name;
48647+ pax_close_kernel();
48648
48649 return 0;
48650 }
48651@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48652
48653 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48654 ret = create_constraint_attribute(i, "power_limit_uw",
48655- S_IWUSR | S_IRUGO,
48656- &constraint_attrs[i].power_limit_attr,
48657- show_constraint_power_limit_uw,
48658- store_constraint_power_limit_uw);
48659+ &constraint_attrs[i].power_limit_attr);
48660 if (ret)
48661 goto err_alloc;
48662 ret = create_constraint_attribute(i, "time_window_us",
48663- S_IWUSR | S_IRUGO,
48664- &constraint_attrs[i].time_window_attr,
48665- show_constraint_time_window_us,
48666- store_constraint_time_window_us);
48667+ &constraint_attrs[i].time_window_attr);
48668 if (ret)
48669 goto err_alloc;
48670- ret = create_constraint_attribute(i, "name", S_IRUGO,
48671- &constraint_attrs[i].name_attr,
48672- show_constraint_name,
48673- NULL);
48674+ ret = create_constraint_attribute(i, "name",
48675+ &constraint_attrs[i].name_attr);
48676 if (ret)
48677 goto err_alloc;
48678- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48679- &constraint_attrs[i].max_power_attr,
48680- show_constraint_max_power_uw,
48681- NULL);
48682+ ret = create_constraint_attribute(i, "max_power_uw",
48683+ &constraint_attrs[i].max_power_attr);
48684 if (ret)
48685 goto err_alloc;
48686- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48687- &constraint_attrs[i].min_power_attr,
48688- show_constraint_min_power_uw,
48689- NULL);
48690+ ret = create_constraint_attribute(i, "min_power_uw",
48691+ &constraint_attrs[i].min_power_attr);
48692 if (ret)
48693 goto err_alloc;
48694 ret = create_constraint_attribute(i, "max_time_window_us",
48695- S_IRUGO,
48696- &constraint_attrs[i].max_time_window_attr,
48697- show_constraint_max_time_window_us,
48698- NULL);
48699+ &constraint_attrs[i].max_time_window_attr);
48700 if (ret)
48701 goto err_alloc;
48702 ret = create_constraint_attribute(i, "min_time_window_us",
48703- S_IRUGO,
48704- &constraint_attrs[i].min_time_window_attr,
48705- show_constraint_min_time_window_us,
48706- NULL);
48707+ &constraint_attrs[i].min_time_window_attr);
48708 if (ret)
48709 goto err_alloc;
48710
48711@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48712 power_zone->zone_dev_attrs[count++] =
48713 &dev_attr_max_energy_range_uj.attr;
48714 if (power_zone->ops->get_energy_uj) {
48715+ pax_open_kernel();
48716 if (power_zone->ops->reset_energy_uj)
48717- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48718+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48719 else
48720- dev_attr_energy_uj.attr.mode = S_IRUGO;
48721+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48722+ pax_close_kernel();
48723 power_zone->zone_dev_attrs[count++] =
48724 &dev_attr_energy_uj.attr;
48725 }
48726diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48727index 9c5d414..c7900ce 100644
48728--- a/drivers/ptp/ptp_private.h
48729+++ b/drivers/ptp/ptp_private.h
48730@@ -51,7 +51,7 @@ struct ptp_clock {
48731 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48732 wait_queue_head_t tsev_wq;
48733 int defunct; /* tells readers to go away when clock is being removed */
48734- struct device_attribute *pin_dev_attr;
48735+ device_attribute_no_const *pin_dev_attr;
48736 struct attribute **pin_attr;
48737 struct attribute_group pin_attr_group;
48738 };
48739diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48740index 302e626..12579af 100644
48741--- a/drivers/ptp/ptp_sysfs.c
48742+++ b/drivers/ptp/ptp_sysfs.c
48743@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48744 goto no_pin_attr;
48745
48746 for (i = 0; i < n_pins; i++) {
48747- struct device_attribute *da = &ptp->pin_dev_attr[i];
48748+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48749 sysfs_attr_init(&da->attr);
48750 da->attr.name = info->pin_config[i].name;
48751 da->attr.mode = 0644;
48752diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48753index 9a09f3c..450b523 100644
48754--- a/drivers/regulator/core.c
48755+++ b/drivers/regulator/core.c
48756@@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48757 {
48758 const struct regulation_constraints *constraints = NULL;
48759 const struct regulator_init_data *init_data;
48760- static atomic_t regulator_no = ATOMIC_INIT(0);
48761+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48762 struct regulator_dev *rdev;
48763 struct device *dev;
48764 int ret, i;
48765@@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48766 rdev->dev.of_node = config->of_node;
48767 rdev->dev.parent = dev;
48768 dev_set_name(&rdev->dev, "regulator.%d",
48769- atomic_inc_return(&regulator_no) - 1);
48770+ atomic_inc_return_unchecked(&regulator_no) - 1);
48771 ret = device_register(&rdev->dev);
48772 if (ret != 0) {
48773 put_device(&rdev->dev);
48774diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48775index 2fc4111..6aa88ca 100644
48776--- a/drivers/regulator/max8660.c
48777+++ b/drivers/regulator/max8660.c
48778@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48779 max8660->shadow_regs[MAX8660_OVER1] = 5;
48780 } else {
48781 /* Otherwise devices can be toggled via software */
48782- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48783- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48784+ pax_open_kernel();
48785+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48786+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48787+ pax_close_kernel();
48788 }
48789
48790 /*
48791diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48792index dbedf17..18ff6b7 100644
48793--- a/drivers/regulator/max8973-regulator.c
48794+++ b/drivers/regulator/max8973-regulator.c
48795@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48796 if (!pdata || !pdata->enable_ext_control) {
48797 max->desc.enable_reg = MAX8973_VOUT;
48798 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48799- max->ops.enable = regulator_enable_regmap;
48800- max->ops.disable = regulator_disable_regmap;
48801- max->ops.is_enabled = regulator_is_enabled_regmap;
48802+ pax_open_kernel();
48803+ *(void **)&max->ops.enable = regulator_enable_regmap;
48804+ *(void **)&max->ops.disable = regulator_disable_regmap;
48805+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48806+ pax_close_kernel();
48807 }
48808
48809 if (pdata) {
48810diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48811index f374fa5..26f0683 100644
48812--- a/drivers/regulator/mc13892-regulator.c
48813+++ b/drivers/regulator/mc13892-regulator.c
48814@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48815 }
48816 mc13xxx_unlock(mc13892);
48817
48818- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48819+ pax_open_kernel();
48820+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48821 = mc13892_vcam_set_mode;
48822- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48823+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48824 = mc13892_vcam_get_mode;
48825+ pax_close_kernel();
48826
48827 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48828 ARRAY_SIZE(mc13892_regulators));
48829diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48830index 0963c93..ea29cce 100644
48831--- a/drivers/rtc/rtc-cmos.c
48832+++ b/drivers/rtc/rtc-cmos.c
48833@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48834 hpet_rtc_timer_init();
48835
48836 /* export at least the first block of NVRAM */
48837- nvram.size = address_space - NVRAM_OFFSET;
48838+ pax_open_kernel();
48839+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48840+ pax_close_kernel();
48841 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48842 if (retval < 0) {
48843 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48844diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48845index d049393..bb20be0 100644
48846--- a/drivers/rtc/rtc-dev.c
48847+++ b/drivers/rtc/rtc-dev.c
48848@@ -16,6 +16,7 @@
48849 #include <linux/module.h>
48850 #include <linux/rtc.h>
48851 #include <linux/sched.h>
48852+#include <linux/grsecurity.h>
48853 #include "rtc-core.h"
48854
48855 static dev_t rtc_devt;
48856@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48857 if (copy_from_user(&tm, uarg, sizeof(tm)))
48858 return -EFAULT;
48859
48860+ gr_log_timechange();
48861+
48862 return rtc_set_time(rtc, &tm);
48863
48864 case RTC_PIE_ON:
48865diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48866index f03d5ba..8325bf6 100644
48867--- a/drivers/rtc/rtc-ds1307.c
48868+++ b/drivers/rtc/rtc-ds1307.c
48869@@ -107,7 +107,7 @@ struct ds1307 {
48870 u8 offset; /* register's offset */
48871 u8 regs[11];
48872 u16 nvram_offset;
48873- struct bin_attribute *nvram;
48874+ bin_attribute_no_const *nvram;
48875 enum ds_type type;
48876 unsigned long flags;
48877 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48878diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48879index 11880c1..b823aa4 100644
48880--- a/drivers/rtc/rtc-m48t59.c
48881+++ b/drivers/rtc/rtc-m48t59.c
48882@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48883 if (IS_ERR(m48t59->rtc))
48884 return PTR_ERR(m48t59->rtc);
48885
48886- m48t59_nvram_attr.size = pdata->offset;
48887+ pax_open_kernel();
48888+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48889+ pax_close_kernel();
48890
48891 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48892 if (ret)
48893diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48894index 14b5f8d..cc9bd26 100644
48895--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48896+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48897@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48898 for (bit = 0; bit < 8; bit++) {
48899
48900 if ((pci_status[i] & (0x1 << bit)) != 0) {
48901- static const char *s;
48902+ const char *s;
48903
48904 s = pci_status_strings[bit];
48905 if (i == 7/*TARG*/ && bit == 3)
48906@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48907
48908 for (bit = 0; bit < 8; bit++) {
48909
48910- if ((split_status[i] & (0x1 << bit)) != 0) {
48911- static const char *s;
48912-
48913- s = split_status_strings[bit];
48914- printk(s, ahd_name(ahd),
48915+ if ((split_status[i] & (0x1 << bit)) != 0)
48916+ printk(split_status_strings[bit], ahd_name(ahd),
48917 split_status_source[i]);
48918- }
48919
48920 if (i > 1)
48921 continue;
48922
48923- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48924- static const char *s;
48925-
48926- s = split_status_strings[bit];
48927- printk(s, ahd_name(ahd), "SG");
48928- }
48929+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48930+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48931 }
48932 }
48933 /*
48934diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48935index e693af6..2e525b6 100644
48936--- a/drivers/scsi/bfa/bfa_fcpim.h
48937+++ b/drivers/scsi/bfa/bfa_fcpim.h
48938@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48939
48940 struct bfa_itn_s {
48941 bfa_isr_func_t isr;
48942-};
48943+} __no_const;
48944
48945 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48946 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48947diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48948index a3ab5cc..8143622 100644
48949--- a/drivers/scsi/bfa/bfa_fcs.c
48950+++ b/drivers/scsi/bfa/bfa_fcs.c
48951@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48952 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48953
48954 static struct bfa_fcs_mod_s fcs_modules[] = {
48955- { bfa_fcs_port_attach, NULL, NULL },
48956- { bfa_fcs_uf_attach, NULL, NULL },
48957- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48958- bfa_fcs_fabric_modexit },
48959+ {
48960+ .attach = bfa_fcs_port_attach,
48961+ .modinit = NULL,
48962+ .modexit = NULL
48963+ },
48964+ {
48965+ .attach = bfa_fcs_uf_attach,
48966+ .modinit = NULL,
48967+ .modexit = NULL
48968+ },
48969+ {
48970+ .attach = bfa_fcs_fabric_attach,
48971+ .modinit = bfa_fcs_fabric_modinit,
48972+ .modexit = bfa_fcs_fabric_modexit
48973+ },
48974 };
48975
48976 /*
48977diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48978index ff75ef8..2dfe00a 100644
48979--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48980+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48981@@ -89,15 +89,26 @@ static struct {
48982 void (*offline) (struct bfa_fcs_lport_s *port);
48983 } __port_action[] = {
48984 {
48985- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48986- bfa_fcs_lport_unknown_offline}, {
48987- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48988- bfa_fcs_lport_fab_offline}, {
48989- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48990- bfa_fcs_lport_n2n_offline}, {
48991- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48992- bfa_fcs_lport_loop_offline},
48993- };
48994+ .init = bfa_fcs_lport_unknown_init,
48995+ .online = bfa_fcs_lport_unknown_online,
48996+ .offline = bfa_fcs_lport_unknown_offline
48997+ },
48998+ {
48999+ .init = bfa_fcs_lport_fab_init,
49000+ .online = bfa_fcs_lport_fab_online,
49001+ .offline = bfa_fcs_lport_fab_offline
49002+ },
49003+ {
49004+ .init = bfa_fcs_lport_n2n_init,
49005+ .online = bfa_fcs_lport_n2n_online,
49006+ .offline = bfa_fcs_lport_n2n_offline
49007+ },
49008+ {
49009+ .init = bfa_fcs_lport_loop_init,
49010+ .online = bfa_fcs_lport_loop_online,
49011+ .offline = bfa_fcs_lport_loop_offline
49012+ },
49013+};
49014
49015 /*
49016 * fcs_port_sm FCS logical port state machine
49017diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
49018index 2e28392..9d865b6 100644
49019--- a/drivers/scsi/bfa/bfa_ioc.h
49020+++ b/drivers/scsi/bfa/bfa_ioc.h
49021@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
49022 bfa_ioc_disable_cbfn_t disable_cbfn;
49023 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
49024 bfa_ioc_reset_cbfn_t reset_cbfn;
49025-};
49026+} __no_const;
49027
49028 /*
49029 * IOC event notification mechanism.
49030@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49031 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49032 enum bfi_ioc_state fwstate);
49033 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49034-};
49035+} __no_const;
49036
49037 /*
49038 * Queue element to wait for room in request queue. FIFO order is
49039diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49040index a14c784..6de6790 100644
49041--- a/drivers/scsi/bfa/bfa_modules.h
49042+++ b/drivers/scsi/bfa/bfa_modules.h
49043@@ -78,12 +78,12 @@ enum {
49044 \
49045 extern struct bfa_module_s hal_mod_ ## __mod; \
49046 struct bfa_module_s hal_mod_ ## __mod = { \
49047- bfa_ ## __mod ## _meminfo, \
49048- bfa_ ## __mod ## _attach, \
49049- bfa_ ## __mod ## _detach, \
49050- bfa_ ## __mod ## _start, \
49051- bfa_ ## __mod ## _stop, \
49052- bfa_ ## __mod ## _iocdisable, \
49053+ .meminfo = bfa_ ## __mod ## _meminfo, \
49054+ .attach = bfa_ ## __mod ## _attach, \
49055+ .detach = bfa_ ## __mod ## _detach, \
49056+ .start = bfa_ ## __mod ## _start, \
49057+ .stop = bfa_ ## __mod ## _stop, \
49058+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
49059 }
49060
49061 #define BFA_CACHELINE_SZ (256)
49062diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49063index 045c4e1..13de803 100644
49064--- a/drivers/scsi/fcoe/fcoe_sysfs.c
49065+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49066@@ -33,8 +33,8 @@
49067 */
49068 #include "libfcoe.h"
49069
49070-static atomic_t ctlr_num;
49071-static atomic_t fcf_num;
49072+static atomic_unchecked_t ctlr_num;
49073+static atomic_unchecked_t fcf_num;
49074
49075 /*
49076 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49077@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49078 if (!ctlr)
49079 goto out;
49080
49081- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49082+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49083 ctlr->f = f;
49084 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49085 INIT_LIST_HEAD(&ctlr->fcfs);
49086@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49087 fcf->dev.parent = &ctlr->dev;
49088 fcf->dev.bus = &fcoe_bus_type;
49089 fcf->dev.type = &fcoe_fcf_device_type;
49090- fcf->id = atomic_inc_return(&fcf_num) - 1;
49091+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49092 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49093
49094 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49095@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49096 {
49097 int error;
49098
49099- atomic_set(&ctlr_num, 0);
49100- atomic_set(&fcf_num, 0);
49101+ atomic_set_unchecked(&ctlr_num, 0);
49102+ atomic_set_unchecked(&fcf_num, 0);
49103
49104 error = bus_register(&fcoe_bus_type);
49105 if (error)
49106diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49107index 3cbb57a..95e47a3 100644
49108--- a/drivers/scsi/hosts.c
49109+++ b/drivers/scsi/hosts.c
49110@@ -42,7 +42,7 @@
49111 #include "scsi_logging.h"
49112
49113
49114-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49115+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49116
49117
49118 static void scsi_host_cls_release(struct device *dev)
49119@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49120 * subtract one because we increment first then return, but we need to
49121 * know what the next host number was before increment
49122 */
49123- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49124+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49125 shost->dma_channel = 0xff;
49126
49127 /* These three are default values which can be overridden */
49128diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49129index fda6cf1..7a6b5d8 100644
49130--- a/drivers/scsi/hpsa.c
49131+++ b/drivers/scsi/hpsa.c
49132@@ -699,10 +699,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49133 unsigned long flags;
49134
49135 if (h->transMethod & CFGTBL_Trans_io_accel1)
49136- return h->access.command_completed(h, q);
49137+ return h->access->command_completed(h, q);
49138
49139 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49140- return h->access.command_completed(h, q);
49141+ return h->access->command_completed(h, q);
49142
49143 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49144 a = rq->head[rq->current_entry];
49145@@ -5460,7 +5460,7 @@ static void start_io(struct ctlr_info *h)
49146 while (!list_empty(&h->reqQ)) {
49147 c = list_entry(h->reqQ.next, struct CommandList, list);
49148 /* can't do anything if fifo is full */
49149- if ((h->access.fifo_full(h))) {
49150+ if ((h->access->fifo_full(h))) {
49151 h->fifo_recently_full = 1;
49152 dev_warn(&h->pdev->dev, "fifo full\n");
49153 break;
49154@@ -5484,7 +5484,7 @@ static void start_io(struct ctlr_info *h)
49155
49156 /* Tell the controller execute command */
49157 spin_unlock_irqrestore(&h->lock, flags);
49158- h->access.submit_command(h, c);
49159+ h->access->submit_command(h, c);
49160 spin_lock_irqsave(&h->lock, flags);
49161 }
49162 spin_unlock_irqrestore(&h->lock, flags);
49163@@ -5492,17 +5492,17 @@ static void start_io(struct ctlr_info *h)
49164
49165 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49166 {
49167- return h->access.command_completed(h, q);
49168+ return h->access->command_completed(h, q);
49169 }
49170
49171 static inline bool interrupt_pending(struct ctlr_info *h)
49172 {
49173- return h->access.intr_pending(h);
49174+ return h->access->intr_pending(h);
49175 }
49176
49177 static inline long interrupt_not_for_us(struct ctlr_info *h)
49178 {
49179- return (h->access.intr_pending(h) == 0) ||
49180+ return (h->access->intr_pending(h) == 0) ||
49181 (h->interrupts_enabled == 0);
49182 }
49183
49184@@ -6456,7 +6456,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49185 if (prod_index < 0)
49186 return -ENODEV;
49187 h->product_name = products[prod_index].product_name;
49188- h->access = *(products[prod_index].access);
49189+ h->access = products[prod_index].access;
49190
49191 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49192 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49193@@ -6735,7 +6735,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49194 {
49195 unsigned long flags;
49196
49197- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49198+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49199 spin_lock_irqsave(&h->lock, flags);
49200 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49201 spin_unlock_irqrestore(&h->lock, flags);
49202@@ -6963,7 +6963,7 @@ reinit_after_soft_reset:
49203 }
49204
49205 /* make sure the board interrupts are off */
49206- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49207+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49208
49209 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49210 goto clean2;
49211@@ -6998,7 +6998,7 @@ reinit_after_soft_reset:
49212 * fake ones to scoop up any residual completions.
49213 */
49214 spin_lock_irqsave(&h->lock, flags);
49215- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49216+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49217 spin_unlock_irqrestore(&h->lock, flags);
49218 free_irqs(h);
49219 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49220@@ -7017,9 +7017,9 @@ reinit_after_soft_reset:
49221 dev_info(&h->pdev->dev, "Board READY.\n");
49222 dev_info(&h->pdev->dev,
49223 "Waiting for stale completions to drain.\n");
49224- h->access.set_intr_mask(h, HPSA_INTR_ON);
49225+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49226 msleep(10000);
49227- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49228+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49229
49230 rc = controller_reset_failed(h->cfgtable);
49231 if (rc)
49232@@ -7045,7 +7045,7 @@ reinit_after_soft_reset:
49233 h->drv_req_rescan = 0;
49234
49235 /* Turn the interrupts on so we can service requests */
49236- h->access.set_intr_mask(h, HPSA_INTR_ON);
49237+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49238
49239 hpsa_hba_inquiry(h);
49240 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49241@@ -7114,7 +7114,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49242 * To write all data in the battery backed cache to disks
49243 */
49244 hpsa_flush_cache(h);
49245- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49246+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49247 hpsa_free_irqs_and_disable_msix(h);
49248 }
49249
49250@@ -7232,7 +7232,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49251 CFGTBL_Trans_enable_directed_msix |
49252 (trans_support & (CFGTBL_Trans_io_accel1 |
49253 CFGTBL_Trans_io_accel2));
49254- struct access_method access = SA5_performant_access;
49255+ struct access_method *access = &SA5_performant_access;
49256
49257 /* This is a bit complicated. There are 8 registers on
49258 * the controller which we write to to tell it 8 different
49259@@ -7297,12 +7297,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49260 * enable outbound interrupt coalescing in accelerator mode;
49261 */
49262 if (trans_support & CFGTBL_Trans_io_accel1) {
49263- access = SA5_ioaccel_mode1_access;
49264+ access = &SA5_ioaccel_mode1_access;
49265 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49266 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49267 } else {
49268 if (trans_support & CFGTBL_Trans_io_accel2) {
49269- access = SA5_ioaccel_mode2_access;
49270+ access = &SA5_ioaccel_mode2_access;
49271 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49272 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49273 }
49274diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49275index 44235a2..962e91b 100644
49276--- a/drivers/scsi/hpsa.h
49277+++ b/drivers/scsi/hpsa.h
49278@@ -128,7 +128,7 @@ struct ctlr_info {
49279 unsigned int msix_vector;
49280 unsigned int msi_vector;
49281 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49282- struct access_method access;
49283+ struct access_method *access;
49284 char hba_mode_enabled;
49285
49286 /* queue and queue Info */
49287@@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
49288 }
49289
49290 static struct access_method SA5_access = {
49291- SA5_submit_command,
49292- SA5_intr_mask,
49293- SA5_fifo_full,
49294- SA5_intr_pending,
49295- SA5_completed,
49296+ .submit_command = SA5_submit_command,
49297+ .set_intr_mask = SA5_intr_mask,
49298+ .fifo_full = SA5_fifo_full,
49299+ .intr_pending = SA5_intr_pending,
49300+ .command_completed = SA5_completed,
49301 };
49302
49303 static struct access_method SA5_ioaccel_mode1_access = {
49304- SA5_submit_command,
49305- SA5_performant_intr_mask,
49306- SA5_fifo_full,
49307- SA5_ioaccel_mode1_intr_pending,
49308- SA5_ioaccel_mode1_completed,
49309+ .submit_command = SA5_submit_command,
49310+ .set_intr_mask = SA5_performant_intr_mask,
49311+ .fifo_full = SA5_fifo_full,
49312+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
49313+ .command_completed = SA5_ioaccel_mode1_completed,
49314 };
49315
49316 static struct access_method SA5_ioaccel_mode2_access = {
49317- SA5_submit_command_ioaccel2,
49318- SA5_performant_intr_mask,
49319- SA5_fifo_full,
49320- SA5_performant_intr_pending,
49321- SA5_performant_completed,
49322+ .submit_command = SA5_submit_command_ioaccel2,
49323+ .set_intr_mask = SA5_performant_intr_mask,
49324+ .fifo_full = SA5_fifo_full,
49325+ .intr_pending = SA5_performant_intr_pending,
49326+ .command_completed = SA5_performant_completed,
49327 };
49328
49329 static struct access_method SA5_performant_access = {
49330- SA5_submit_command,
49331- SA5_performant_intr_mask,
49332- SA5_fifo_full,
49333- SA5_performant_intr_pending,
49334- SA5_performant_completed,
49335+ .submit_command = SA5_submit_command,
49336+ .set_intr_mask = SA5_performant_intr_mask,
49337+ .fifo_full = SA5_fifo_full,
49338+ .intr_pending = SA5_performant_intr_pending,
49339+ .command_completed = SA5_performant_completed,
49340 };
49341
49342 struct board_type {
49343diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49344index 1b3a094..068e683 100644
49345--- a/drivers/scsi/libfc/fc_exch.c
49346+++ b/drivers/scsi/libfc/fc_exch.c
49347@@ -101,12 +101,12 @@ struct fc_exch_mgr {
49348 u16 pool_max_index;
49349
49350 struct {
49351- atomic_t no_free_exch;
49352- atomic_t no_free_exch_xid;
49353- atomic_t xid_not_found;
49354- atomic_t xid_busy;
49355- atomic_t seq_not_found;
49356- atomic_t non_bls_resp;
49357+ atomic_unchecked_t no_free_exch;
49358+ atomic_unchecked_t no_free_exch_xid;
49359+ atomic_unchecked_t xid_not_found;
49360+ atomic_unchecked_t xid_busy;
49361+ atomic_unchecked_t seq_not_found;
49362+ atomic_unchecked_t non_bls_resp;
49363 } stats;
49364 };
49365
49366@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49367 /* allocate memory for exchange */
49368 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49369 if (!ep) {
49370- atomic_inc(&mp->stats.no_free_exch);
49371+ atomic_inc_unchecked(&mp->stats.no_free_exch);
49372 goto out;
49373 }
49374 memset(ep, 0, sizeof(*ep));
49375@@ -874,7 +874,7 @@ out:
49376 return ep;
49377 err:
49378 spin_unlock_bh(&pool->lock);
49379- atomic_inc(&mp->stats.no_free_exch_xid);
49380+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49381 mempool_free(ep, mp->ep_pool);
49382 return NULL;
49383 }
49384@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49385 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49386 ep = fc_exch_find(mp, xid);
49387 if (!ep) {
49388- atomic_inc(&mp->stats.xid_not_found);
49389+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49390 reject = FC_RJT_OX_ID;
49391 goto out;
49392 }
49393@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49394 ep = fc_exch_find(mp, xid);
49395 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49396 if (ep) {
49397- atomic_inc(&mp->stats.xid_busy);
49398+ atomic_inc_unchecked(&mp->stats.xid_busy);
49399 reject = FC_RJT_RX_ID;
49400 goto rel;
49401 }
49402@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49403 }
49404 xid = ep->xid; /* get our XID */
49405 } else if (!ep) {
49406- atomic_inc(&mp->stats.xid_not_found);
49407+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49408 reject = FC_RJT_RX_ID; /* XID not found */
49409 goto out;
49410 }
49411@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49412 } else {
49413 sp = &ep->seq;
49414 if (sp->id != fh->fh_seq_id) {
49415- atomic_inc(&mp->stats.seq_not_found);
49416+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49417 if (f_ctl & FC_FC_END_SEQ) {
49418 /*
49419 * Update sequence_id based on incoming last
49420@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49421
49422 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49423 if (!ep) {
49424- atomic_inc(&mp->stats.xid_not_found);
49425+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49426 goto out;
49427 }
49428 if (ep->esb_stat & ESB_ST_COMPLETE) {
49429- atomic_inc(&mp->stats.xid_not_found);
49430+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49431 goto rel;
49432 }
49433 if (ep->rxid == FC_XID_UNKNOWN)
49434 ep->rxid = ntohs(fh->fh_rx_id);
49435 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49436- atomic_inc(&mp->stats.xid_not_found);
49437+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49438 goto rel;
49439 }
49440 if (ep->did != ntoh24(fh->fh_s_id) &&
49441 ep->did != FC_FID_FLOGI) {
49442- atomic_inc(&mp->stats.xid_not_found);
49443+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49444 goto rel;
49445 }
49446 sof = fr_sof(fp);
49447@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49448 sp->ssb_stat |= SSB_ST_RESP;
49449 sp->id = fh->fh_seq_id;
49450 } else if (sp->id != fh->fh_seq_id) {
49451- atomic_inc(&mp->stats.seq_not_found);
49452+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49453 goto rel;
49454 }
49455
49456@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49457 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49458
49459 if (!sp)
49460- atomic_inc(&mp->stats.xid_not_found);
49461+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49462 else
49463- atomic_inc(&mp->stats.non_bls_resp);
49464+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49465
49466 fc_frame_free(fp);
49467 }
49468@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49469
49470 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49471 mp = ema->mp;
49472- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49473+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49474 st->fc_no_free_exch_xid +=
49475- atomic_read(&mp->stats.no_free_exch_xid);
49476- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49477- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49478- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49479- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49480+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49481+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49482+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49483+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49484+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49485 }
49486 }
49487 EXPORT_SYMBOL(fc_exch_update_stats);
49488diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49489index 766098a..1c6c971 100644
49490--- a/drivers/scsi/libsas/sas_ata.c
49491+++ b/drivers/scsi/libsas/sas_ata.c
49492@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49493 .postreset = ata_std_postreset,
49494 .error_handler = ata_std_error_handler,
49495 .post_internal_cmd = sas_ata_post_internal,
49496- .qc_defer = ata_std_qc_defer,
49497+ .qc_defer = ata_std_qc_defer,
49498 .qc_prep = ata_noop_qc_prep,
49499 .qc_issue = sas_ata_qc_issue,
49500 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49501diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49502index 94a3caf..a118dec 100644
49503--- a/drivers/scsi/lpfc/lpfc.h
49504+++ b/drivers/scsi/lpfc/lpfc.h
49505@@ -430,7 +430,7 @@ struct lpfc_vport {
49506 struct dentry *debug_nodelist;
49507 struct dentry *vport_debugfs_root;
49508 struct lpfc_debugfs_trc *disc_trc;
49509- atomic_t disc_trc_cnt;
49510+ atomic_unchecked_t disc_trc_cnt;
49511 #endif
49512 uint8_t stat_data_enabled;
49513 uint8_t stat_data_blocked;
49514@@ -879,8 +879,8 @@ struct lpfc_hba {
49515 struct timer_list fabric_block_timer;
49516 unsigned long bit_flags;
49517 #define FABRIC_COMANDS_BLOCKED 0
49518- atomic_t num_rsrc_err;
49519- atomic_t num_cmd_success;
49520+ atomic_unchecked_t num_rsrc_err;
49521+ atomic_unchecked_t num_cmd_success;
49522 unsigned long last_rsrc_error_time;
49523 unsigned long last_ramp_down_time;
49524 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49525@@ -915,7 +915,7 @@ struct lpfc_hba {
49526
49527 struct dentry *debug_slow_ring_trc;
49528 struct lpfc_debugfs_trc *slow_ring_trc;
49529- atomic_t slow_ring_trc_cnt;
49530+ atomic_unchecked_t slow_ring_trc_cnt;
49531 /* iDiag debugfs sub-directory */
49532 struct dentry *idiag_root;
49533 struct dentry *idiag_pci_cfg;
49534diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49535index 828c08e..e3378e0 100644
49536--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49537+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49538@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49539
49540 #include <linux/debugfs.h>
49541
49542-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49543+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49544 static unsigned long lpfc_debugfs_start_time = 0L;
49545
49546 /* iDiag */
49547@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49548 lpfc_debugfs_enable = 0;
49549
49550 len = 0;
49551- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49552+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49553 (lpfc_debugfs_max_disc_trc - 1);
49554 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49555 dtp = vport->disc_trc + i;
49556@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49557 lpfc_debugfs_enable = 0;
49558
49559 len = 0;
49560- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49561+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49562 (lpfc_debugfs_max_slow_ring_trc - 1);
49563 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49564 dtp = phba->slow_ring_trc + i;
49565@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49566 !vport || !vport->disc_trc)
49567 return;
49568
49569- index = atomic_inc_return(&vport->disc_trc_cnt) &
49570+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49571 (lpfc_debugfs_max_disc_trc - 1);
49572 dtp = vport->disc_trc + index;
49573 dtp->fmt = fmt;
49574 dtp->data1 = data1;
49575 dtp->data2 = data2;
49576 dtp->data3 = data3;
49577- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49578+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49579 dtp->jif = jiffies;
49580 #endif
49581 return;
49582@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49583 !phba || !phba->slow_ring_trc)
49584 return;
49585
49586- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49587+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49588 (lpfc_debugfs_max_slow_ring_trc - 1);
49589 dtp = phba->slow_ring_trc + index;
49590 dtp->fmt = fmt;
49591 dtp->data1 = data1;
49592 dtp->data2 = data2;
49593 dtp->data3 = data3;
49594- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49595+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49596 dtp->jif = jiffies;
49597 #endif
49598 return;
49599@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49600 "slow_ring buffer\n");
49601 goto debug_failed;
49602 }
49603- atomic_set(&phba->slow_ring_trc_cnt, 0);
49604+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49605 memset(phba->slow_ring_trc, 0,
49606 (sizeof(struct lpfc_debugfs_trc) *
49607 lpfc_debugfs_max_slow_ring_trc));
49608@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49609 "buffer\n");
49610 goto debug_failed;
49611 }
49612- atomic_set(&vport->disc_trc_cnt, 0);
49613+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49614
49615 snprintf(name, sizeof(name), "discovery_trace");
49616 vport->debug_disc_trc =
49617diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49618index 635eeb3..038aef6 100644
49619--- a/drivers/scsi/lpfc/lpfc_init.c
49620+++ b/drivers/scsi/lpfc/lpfc_init.c
49621@@ -11194,8 +11194,10 @@ lpfc_init(void)
49622 "misc_register returned with status %d", error);
49623
49624 if (lpfc_enable_npiv) {
49625- lpfc_transport_functions.vport_create = lpfc_vport_create;
49626- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49627+ pax_open_kernel();
49628+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49629+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49630+ pax_close_kernel();
49631 }
49632 lpfc_transport_template =
49633 fc_attach_transport(&lpfc_transport_functions);
49634diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49635index 462453e..c0023a6 100644
49636--- a/drivers/scsi/lpfc/lpfc_scsi.c
49637+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49638@@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49639 uint32_t evt_posted;
49640
49641 spin_lock_irqsave(&phba->hbalock, flags);
49642- atomic_inc(&phba->num_rsrc_err);
49643+ atomic_inc_unchecked(&phba->num_rsrc_err);
49644 phba->last_rsrc_error_time = jiffies;
49645
49646 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49647@@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49648 unsigned long num_rsrc_err, num_cmd_success;
49649 int i;
49650
49651- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49652- num_cmd_success = atomic_read(&phba->num_cmd_success);
49653+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49654+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49655
49656 /*
49657 * The error and success command counters are global per
49658@@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49659 }
49660 }
49661 lpfc_destroy_vport_work_array(phba, vports);
49662- atomic_set(&phba->num_rsrc_err, 0);
49663- atomic_set(&phba->num_cmd_success, 0);
49664+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49665+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49666 }
49667
49668 /**
49669diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49670index 6fd7d40..b444223 100644
49671--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49672+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49673@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49674 {
49675 struct scsi_device *sdev = to_scsi_device(dev);
49676 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49677- static struct _raid_device *raid_device;
49678+ struct _raid_device *raid_device;
49679 unsigned long flags;
49680 Mpi2RaidVolPage0_t vol_pg0;
49681 Mpi2ConfigReply_t mpi_reply;
49682@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49683 {
49684 struct scsi_device *sdev = to_scsi_device(dev);
49685 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49686- static struct _raid_device *raid_device;
49687+ struct _raid_device *raid_device;
49688 unsigned long flags;
49689 Mpi2RaidVolPage0_t vol_pg0;
49690 Mpi2ConfigReply_t mpi_reply;
49691@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49692 struct fw_event_work *fw_event)
49693 {
49694 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49695- static struct _raid_device *raid_device;
49696+ struct _raid_device *raid_device;
49697 unsigned long flags;
49698 u16 handle;
49699
49700@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49701 u64 sas_address;
49702 struct _sas_device *sas_device;
49703 struct _sas_node *expander_device;
49704- static struct _raid_device *raid_device;
49705+ struct _raid_device *raid_device;
49706 u8 retry_count;
49707 unsigned long flags;
49708
49709diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49710index be8ce54..94ed33a 100644
49711--- a/drivers/scsi/pmcraid.c
49712+++ b/drivers/scsi/pmcraid.c
49713@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49714 res->scsi_dev = scsi_dev;
49715 scsi_dev->hostdata = res;
49716 res->change_detected = 0;
49717- atomic_set(&res->read_failures, 0);
49718- atomic_set(&res->write_failures, 0);
49719+ atomic_set_unchecked(&res->read_failures, 0);
49720+ atomic_set_unchecked(&res->write_failures, 0);
49721 rc = 0;
49722 }
49723 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49724@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49725
49726 /* If this was a SCSI read/write command keep count of errors */
49727 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49728- atomic_inc(&res->read_failures);
49729+ atomic_inc_unchecked(&res->read_failures);
49730 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49731- atomic_inc(&res->write_failures);
49732+ atomic_inc_unchecked(&res->write_failures);
49733
49734 if (!RES_IS_GSCSI(res->cfg_entry) &&
49735 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49736@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49737 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49738 * hrrq_id assigned here in queuecommand
49739 */
49740- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49741+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49742 pinstance->num_hrrq;
49743 cmd->cmd_done = pmcraid_io_done;
49744
49745@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49746 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49747 * hrrq_id assigned here in queuecommand
49748 */
49749- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49750+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49751 pinstance->num_hrrq;
49752
49753 if (request_size) {
49754@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49755
49756 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49757 /* add resources only after host is added into system */
49758- if (!atomic_read(&pinstance->expose_resources))
49759+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49760 return;
49761
49762 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49763@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49764 init_waitqueue_head(&pinstance->reset_wait_q);
49765
49766 atomic_set(&pinstance->outstanding_cmds, 0);
49767- atomic_set(&pinstance->last_message_id, 0);
49768- atomic_set(&pinstance->expose_resources, 0);
49769+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49770+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49771
49772 INIT_LIST_HEAD(&pinstance->free_res_q);
49773 INIT_LIST_HEAD(&pinstance->used_res_q);
49774@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49775 /* Schedule worker thread to handle CCN and take care of adding and
49776 * removing devices to OS
49777 */
49778- atomic_set(&pinstance->expose_resources, 1);
49779+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49780 schedule_work(&pinstance->worker_q);
49781 return rc;
49782
49783diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49784index e1d150f..6c6df44 100644
49785--- a/drivers/scsi/pmcraid.h
49786+++ b/drivers/scsi/pmcraid.h
49787@@ -748,7 +748,7 @@ struct pmcraid_instance {
49788 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49789
49790 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49791- atomic_t last_message_id;
49792+ atomic_unchecked_t last_message_id;
49793
49794 /* configuration table */
49795 struct pmcraid_config_table *cfg_table;
49796@@ -777,7 +777,7 @@ struct pmcraid_instance {
49797 atomic_t outstanding_cmds;
49798
49799 /* should add/delete resources to mid-layer now ?*/
49800- atomic_t expose_resources;
49801+ atomic_unchecked_t expose_resources;
49802
49803
49804
49805@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49806 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49807 };
49808 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49809- atomic_t read_failures; /* count of failed READ commands */
49810- atomic_t write_failures; /* count of failed WRITE commands */
49811+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49812+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49813
49814 /* To indicate add/delete/modify during CCN */
49815 u8 change_detected;
49816diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49817index 07befcf..c0bff13 100644
49818--- a/drivers/scsi/qla2xxx/qla_attr.c
49819+++ b/drivers/scsi/qla2xxx/qla_attr.c
49820@@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49821 return 0;
49822 }
49823
49824-struct fc_function_template qla2xxx_transport_functions = {
49825+fc_function_template_no_const qla2xxx_transport_functions = {
49826
49827 .show_host_node_name = 1,
49828 .show_host_port_name = 1,
49829@@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49830 .bsg_timeout = qla24xx_bsg_timeout,
49831 };
49832
49833-struct fc_function_template qla2xxx_transport_vport_functions = {
49834+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49835
49836 .show_host_node_name = 1,
49837 .show_host_port_name = 1,
49838diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49839index e665e81..16e84e6 100644
49840--- a/drivers/scsi/qla2xxx/qla_gbl.h
49841+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49842@@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49843 struct device_attribute;
49844 extern struct device_attribute *qla2x00_host_attrs[];
49845 struct fc_function_template;
49846-extern struct fc_function_template qla2xxx_transport_functions;
49847-extern struct fc_function_template qla2xxx_transport_vport_functions;
49848+extern fc_function_template_no_const qla2xxx_transport_functions;
49849+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49850 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49851 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49852 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49853diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49854index 19e99cc..b3c0b7b 100644
49855--- a/drivers/scsi/qla2xxx/qla_os.c
49856+++ b/drivers/scsi/qla2xxx/qla_os.c
49857@@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49858 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49859 /* Ok, a 64bit DMA mask is applicable. */
49860 ha->flags.enable_64bit_addressing = 1;
49861- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49862- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49863+ pax_open_kernel();
49864+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49865+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49866+ pax_close_kernel();
49867 return;
49868 }
49869 }
49870diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49871index 73a5022..4e0797c 100644
49872--- a/drivers/scsi/qla4xxx/ql4_def.h
49873+++ b/drivers/scsi/qla4xxx/ql4_def.h
49874@@ -305,7 +305,7 @@ struct ddb_entry {
49875 * (4000 only) */
49876 atomic_t relogin_timer; /* Max Time to wait for
49877 * relogin to complete */
49878- atomic_t relogin_retry_count; /* Num of times relogin has been
49879+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49880 * retried */
49881 uint32_t default_time2wait; /* Default Min time between
49882 * relogins (+aens) */
49883diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49884index 459b9f7..2930a68 100644
49885--- a/drivers/scsi/qla4xxx/ql4_os.c
49886+++ b/drivers/scsi/qla4xxx/ql4_os.c
49887@@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49888 */
49889 if (!iscsi_is_session_online(cls_sess)) {
49890 /* Reset retry relogin timer */
49891- atomic_inc(&ddb_entry->relogin_retry_count);
49892+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49893 DEBUG2(ql4_printk(KERN_INFO, ha,
49894 "%s: index[%d] relogin timed out-retrying"
49895 " relogin (%d), retry (%d)\n", __func__,
49896 ddb_entry->fw_ddb_index,
49897- atomic_read(&ddb_entry->relogin_retry_count),
49898+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49899 ddb_entry->default_time2wait + 4));
49900 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49901 atomic_set(&ddb_entry->retry_relogin_timer,
49902@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49903
49904 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49905 atomic_set(&ddb_entry->relogin_timer, 0);
49906- atomic_set(&ddb_entry->relogin_retry_count, 0);
49907+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49908 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49909 ddb_entry->default_relogin_timeout =
49910 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49911diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49912index 88d46fe..7351be5 100644
49913--- a/drivers/scsi/scsi.c
49914+++ b/drivers/scsi/scsi.c
49915@@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49916 struct Scsi_Host *host = cmd->device->host;
49917 int rtn = 0;
49918
49919- atomic_inc(&cmd->device->iorequest_cnt);
49920+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49921
49922 /* check if the device is still usable */
49923 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49924diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49925index d99ab3b..c4ccdef 100644
49926--- a/drivers/scsi/scsi_lib.c
49927+++ b/drivers/scsi/scsi_lib.c
49928@@ -1472,7 +1472,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49929 shost = sdev->host;
49930 scsi_init_cmd_errh(cmd);
49931 cmd->result = DID_NO_CONNECT << 16;
49932- atomic_inc(&cmd->device->iorequest_cnt);
49933+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49934
49935 /*
49936 * SCSI request completion path will do scsi_device_unbusy(),
49937@@ -1498,9 +1498,9 @@ static void scsi_softirq_done(struct request *rq)
49938
49939 INIT_LIST_HEAD(&cmd->eh_entry);
49940
49941- atomic_inc(&cmd->device->iodone_cnt);
49942+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49943 if (cmd->result)
49944- atomic_inc(&cmd->device->ioerr_cnt);
49945+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49946
49947 disposition = scsi_decide_disposition(cmd);
49948 if (disposition != SUCCESS &&
49949diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49950index 074e8cc..f612e5c 100644
49951--- a/drivers/scsi/scsi_sysfs.c
49952+++ b/drivers/scsi/scsi_sysfs.c
49953@@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49954 char *buf) \
49955 { \
49956 struct scsi_device *sdev = to_scsi_device(dev); \
49957- unsigned long long count = atomic_read(&sdev->field); \
49958+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49959 return snprintf(buf, 20, "0x%llx\n", count); \
49960 } \
49961 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49962diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49963index e51add0..1e06a96 100644
49964--- a/drivers/scsi/scsi_tgt_lib.c
49965+++ b/drivers/scsi/scsi_tgt_lib.c
49966@@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49967 int err;
49968
49969 dprintk("%lx %u\n", uaddr, len);
49970- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49971+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49972 if (err) {
49973 /*
49974 * TODO: need to fixup sg_tablesize, max_segment_size,
49975diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49976index f80908f..22aba76 100644
49977--- a/drivers/scsi/scsi_transport_fc.c
49978+++ b/drivers/scsi/scsi_transport_fc.c
49979@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49980 * Netlink Infrastructure
49981 */
49982
49983-static atomic_t fc_event_seq;
49984+static atomic_unchecked_t fc_event_seq;
49985
49986 /**
49987 * fc_get_event_number - Obtain the next sequential FC event number
49988@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
49989 u32
49990 fc_get_event_number(void)
49991 {
49992- return atomic_add_return(1, &fc_event_seq);
49993+ return atomic_add_return_unchecked(1, &fc_event_seq);
49994 }
49995 EXPORT_SYMBOL(fc_get_event_number);
49996
49997@@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
49998 {
49999 int error;
50000
50001- atomic_set(&fc_event_seq, 0);
50002+ atomic_set_unchecked(&fc_event_seq, 0);
50003
50004 error = transport_class_register(&fc_host_class);
50005 if (error)
50006@@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
50007 char *cp;
50008
50009 *val = simple_strtoul(buf, &cp, 0);
50010- if ((*cp && (*cp != '\n')) || (*val < 0))
50011+ if (*cp && (*cp != '\n'))
50012 return -EINVAL;
50013 /*
50014 * Check for overflow; dev_loss_tmo is u32
50015diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
50016index 0102a2d..cc3f8e9 100644
50017--- a/drivers/scsi/scsi_transport_iscsi.c
50018+++ b/drivers/scsi/scsi_transport_iscsi.c
50019@@ -79,7 +79,7 @@ struct iscsi_internal {
50020 struct transport_container session_cont;
50021 };
50022
50023-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
50024+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
50025 static struct workqueue_struct *iscsi_eh_timer_workq;
50026
50027 static DEFINE_IDA(iscsi_sess_ida);
50028@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50029 int err;
50030
50031 ihost = shost->shost_data;
50032- session->sid = atomic_add_return(1, &iscsi_session_nr);
50033+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50034
50035 if (target_id == ISCSI_MAX_TARGET) {
50036 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50037@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50038 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50039 ISCSI_TRANSPORT_VERSION);
50040
50041- atomic_set(&iscsi_session_nr, 0);
50042+ atomic_set_unchecked(&iscsi_session_nr, 0);
50043
50044 err = class_register(&iscsi_transport_class);
50045 if (err)
50046diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50047index 13e8983..d306a68 100644
50048--- a/drivers/scsi/scsi_transport_srp.c
50049+++ b/drivers/scsi/scsi_transport_srp.c
50050@@ -36,7 +36,7 @@
50051 #include "scsi_transport_srp_internal.h"
50052
50053 struct srp_host_attrs {
50054- atomic_t next_port_id;
50055+ atomic_unchecked_t next_port_id;
50056 };
50057 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50058
50059@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50060 struct Scsi_Host *shost = dev_to_shost(dev);
50061 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50062
50063- atomic_set(&srp_host->next_port_id, 0);
50064+ atomic_set_unchecked(&srp_host->next_port_id, 0);
50065 return 0;
50066 }
50067
50068@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50069 rport_fast_io_fail_timedout);
50070 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50071
50072- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50073+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50074 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50075
50076 transport_setup_device(&rport->dev);
50077diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50078index bffbd4b..cb1b68a 100644
50079--- a/drivers/scsi/sd.c
50080+++ b/drivers/scsi/sd.c
50081@@ -2971,7 +2971,7 @@ static int sd_probe(struct device *dev)
50082 sdkp->disk = gd;
50083 sdkp->index = index;
50084 atomic_set(&sdkp->openers, 0);
50085- atomic_set(&sdkp->device->ioerr_cnt, 0);
50086+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50087
50088 if (!sdp->request_queue->rq_timeout) {
50089 if (sdp->type != TYPE_MOD)
50090diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50091index df5e961..df6b97f 100644
50092--- a/drivers/scsi/sg.c
50093+++ b/drivers/scsi/sg.c
50094@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50095 sdp->disk->disk_name,
50096 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50097 NULL,
50098- (char *)arg);
50099+ (char __user *)arg);
50100 case BLKTRACESTART:
50101 return blk_trace_startstop(sdp->device->request_queue, 1);
50102 case BLKTRACESTOP:
50103diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50104index 939edf4..3f50423 100644
50105--- a/drivers/spi/spi.c
50106+++ b/drivers/spi/spi.c
50107@@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
50108 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50109
50110 /* portable code must never pass more than 32 bytes */
50111-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50112+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50113
50114 static u8 *buf;
50115
50116diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50117index 2c61783..4d49e4e 100644
50118--- a/drivers/staging/android/timed_output.c
50119+++ b/drivers/staging/android/timed_output.c
50120@@ -25,7 +25,7 @@
50121 #include "timed_output.h"
50122
50123 static struct class *timed_output_class;
50124-static atomic_t device_count;
50125+static atomic_unchecked_t device_count;
50126
50127 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50128 char *buf)
50129@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50130 timed_output_class = class_create(THIS_MODULE, "timed_output");
50131 if (IS_ERR(timed_output_class))
50132 return PTR_ERR(timed_output_class);
50133- atomic_set(&device_count, 0);
50134+ atomic_set_unchecked(&device_count, 0);
50135 timed_output_class->dev_groups = timed_output_groups;
50136 }
50137
50138@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50139 if (ret < 0)
50140 return ret;
50141
50142- tdev->index = atomic_inc_return(&device_count);
50143+ tdev->index = atomic_inc_return_unchecked(&device_count);
50144 tdev->dev = device_create(timed_output_class, NULL,
50145 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50146 if (IS_ERR(tdev->dev))
50147diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50148index fe47cd3..19a1bd1 100644
50149--- a/drivers/staging/gdm724x/gdm_tty.c
50150+++ b/drivers/staging/gdm724x/gdm_tty.c
50151@@ -44,7 +44,7 @@
50152 #define gdm_tty_send_control(n, r, v, d, l) (\
50153 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50154
50155-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50156+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50157
50158 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50159 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50160diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50161index c270c9a..94ddf82 100644
50162--- a/drivers/staging/imx-drm/imx-drm-core.c
50163+++ b/drivers/staging/imx-drm/imx-drm-core.c
50164@@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
50165 if (imxdrm->pipes >= MAX_CRTC)
50166 return -EINVAL;
50167
50168- if (imxdrm->drm->open_count)
50169+ if (local_read(&imxdrm->drm->open_count))
50170 return -EBUSY;
50171
50172 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
50173diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50174index 3f8020c..649fded 100644
50175--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50176+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50177@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50178 return 0;
50179 }
50180
50181-sfw_test_client_ops_t brw_test_client;
50182-void brw_init_test_client(void)
50183-{
50184- brw_test_client.tso_init = brw_client_init;
50185- brw_test_client.tso_fini = brw_client_fini;
50186- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50187- brw_test_client.tso_done_rpc = brw_client_done_rpc;
50188+sfw_test_client_ops_t brw_test_client = {
50189+ .tso_init = brw_client_init,
50190+ .tso_fini = brw_client_fini,
50191+ .tso_prep_rpc = brw_client_prep_rpc,
50192+ .tso_done_rpc = brw_client_done_rpc,
50193 };
50194
50195 srpc_service_t brw_test_service;
50196diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50197index 050723a..fa6fdf1 100644
50198--- a/drivers/staging/lustre/lnet/selftest/framework.c
50199+++ b/drivers/staging/lustre/lnet/selftest/framework.c
50200@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50201
50202 extern sfw_test_client_ops_t ping_test_client;
50203 extern srpc_service_t ping_test_service;
50204-extern void ping_init_test_client(void);
50205 extern void ping_init_test_service(void);
50206
50207 extern sfw_test_client_ops_t brw_test_client;
50208 extern srpc_service_t brw_test_service;
50209-extern void brw_init_test_client(void);
50210 extern void brw_init_test_service(void);
50211
50212
50213@@ -1684,12 +1682,10 @@ sfw_startup (void)
50214 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50215 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50216
50217- brw_init_test_client();
50218 brw_init_test_service();
50219 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50220 LASSERT (rc == 0);
50221
50222- ping_init_test_client();
50223 ping_init_test_service();
50224 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50225 LASSERT (rc == 0);
50226diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50227index 750cac4..e4d751f 100644
50228--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50229+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50230@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50231 return 0;
50232 }
50233
50234-sfw_test_client_ops_t ping_test_client;
50235-void ping_init_test_client(void)
50236-{
50237- ping_test_client.tso_init = ping_client_init;
50238- ping_test_client.tso_fini = ping_client_fini;
50239- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50240- ping_test_client.tso_done_rpc = ping_client_done_rpc;
50241-}
50242+sfw_test_client_ops_t ping_test_client = {
50243+ .tso_init = ping_client_init,
50244+ .tso_fini = ping_client_fini,
50245+ .tso_prep_rpc = ping_client_prep_rpc,
50246+ .tso_done_rpc = ping_client_done_rpc,
50247+};
50248
50249 srpc_service_t ping_test_service;
50250 void ping_init_test_service(void)
50251diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50252index 3e25f00..0d59cf5 100644
50253--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50254+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50255@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50256 ldlm_completion_callback lcs_completion;
50257 ldlm_blocking_callback lcs_blocking;
50258 ldlm_glimpse_callback lcs_glimpse;
50259-};
50260+} __no_const;
50261
50262 /* ldlm_lockd.c */
50263 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50264diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50265index 72cf3fe..4beac19 100644
50266--- a/drivers/staging/lustre/lustre/include/obd.h
50267+++ b/drivers/staging/lustre/lustre/include/obd.h
50268@@ -1427,7 +1427,7 @@ struct md_ops {
50269 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50270 * wrapper function in include/linux/obd_class.h.
50271 */
50272-};
50273+} __no_const;
50274
50275 struct lsm_operations {
50276 void (*lsm_free)(struct lov_stripe_md *);
50277diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50278index 986bf38..eab2558f 100644
50279--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50280+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50281@@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50282 int added = (mode == LCK_NL);
50283 int overlaps = 0;
50284 int splitted = 0;
50285- const struct ldlm_callback_suite null_cbs = { NULL };
50286+ const struct ldlm_callback_suite null_cbs = { };
50287
50288 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50289 LPU64" end "LPU64"\n", *flags,
50290diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50291index e947b91..f408990 100644
50292--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50293+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50294@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50295 int LL_PROC_PROTO(proc_console_max_delay_cs)
50296 {
50297 int rc, max_delay_cs;
50298- ctl_table_t dummy = *table;
50299+ ctl_table_no_const dummy = *table;
50300 cfs_duration_t d;
50301
50302 dummy.data = &max_delay_cs;
50303@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50304 int LL_PROC_PROTO(proc_console_min_delay_cs)
50305 {
50306 int rc, min_delay_cs;
50307- ctl_table_t dummy = *table;
50308+ ctl_table_no_const dummy = *table;
50309 cfs_duration_t d;
50310
50311 dummy.data = &min_delay_cs;
50312@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50313 int LL_PROC_PROTO(proc_console_backoff)
50314 {
50315 int rc, backoff;
50316- ctl_table_t dummy = *table;
50317+ ctl_table_no_const dummy = *table;
50318
50319 dummy.data = &backoff;
50320 dummy.proc_handler = &proc_dointvec;
50321diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50322index 24ae26d..9d09cab 100644
50323--- a/drivers/staging/lustre/lustre/libcfs/module.c
50324+++ b/drivers/staging/lustre/lustre/libcfs/module.c
50325@@ -313,11 +313,11 @@ out:
50326
50327
50328 struct cfs_psdev_ops libcfs_psdev_ops = {
50329- libcfs_psdev_open,
50330- libcfs_psdev_release,
50331- NULL,
50332- NULL,
50333- libcfs_ioctl
50334+ .p_open = libcfs_psdev_open,
50335+ .p_close = libcfs_psdev_release,
50336+ .p_read = NULL,
50337+ .p_write = NULL,
50338+ .p_ioctl = libcfs_ioctl
50339 };
50340
50341 extern int insert_proc(void);
50342diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50343index 7fbc18e..f982071 100644
50344--- a/drivers/staging/lustre/lustre/llite/dir.c
50345+++ b/drivers/staging/lustre/lustre/llite/dir.c
50346@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50347 int mode;
50348 int err;
50349
50350- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50351+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50352 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50353 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50354 lump);
50355diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50356index f670469..03b7438 100644
50357--- a/drivers/staging/media/solo6x10/solo6x10-core.c
50358+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50359@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50360
50361 static int solo_sysfs_init(struct solo_dev *solo_dev)
50362 {
50363- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50364+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50365 struct device *dev = &solo_dev->dev;
50366 const char *driver;
50367 int i;
50368diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50369index 74f037b..5b5bb76 100644
50370--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50371+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50372@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50373
50374 int solo_g723_init(struct solo_dev *solo_dev)
50375 {
50376- static struct snd_device_ops ops = { NULL };
50377+ static struct snd_device_ops ops = { };
50378 struct snd_card *card;
50379 struct snd_kcontrol_new kctl;
50380 char name[32];
50381diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50382index 7f2f247..d999137 100644
50383--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50384+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50385@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50386
50387 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50388 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50389- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50390+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50391 if (p2m_id < 0)
50392 p2m_id = -p2m_id;
50393 }
50394diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50395index 8964f8b..36eb087 100644
50396--- a/drivers/staging/media/solo6x10/solo6x10.h
50397+++ b/drivers/staging/media/solo6x10/solo6x10.h
50398@@ -237,7 +237,7 @@ struct solo_dev {
50399
50400 /* P2M DMA Engine */
50401 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50402- atomic_t p2m_count;
50403+ atomic_unchecked_t p2m_count;
50404 int p2m_jiffies;
50405 unsigned int p2m_timeouts;
50406
50407diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50408index a0f4868..139f1fb 100644
50409--- a/drivers/staging/octeon/ethernet-rx.c
50410+++ b/drivers/staging/octeon/ethernet-rx.c
50411@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50412 /* Increment RX stats for virtual ports */
50413 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50414 #ifdef CONFIG_64BIT
50415- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50416- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50417+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50418+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50419 #else
50420- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50421- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50422+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50423+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50424 #endif
50425 }
50426 netif_receive_skb(skb);
50427@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50428 dev->name);
50429 */
50430 #ifdef CONFIG_64BIT
50431- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50432+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50433 #else
50434- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50435+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50436 #endif
50437 dev_kfree_skb_irq(skb);
50438 }
50439diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50440index ff7214a..6dd90f0 100644
50441--- a/drivers/staging/octeon/ethernet.c
50442+++ b/drivers/staging/octeon/ethernet.c
50443@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50444 * since the RX tasklet also increments it.
50445 */
50446 #ifdef CONFIG_64BIT
50447- atomic64_add(rx_status.dropped_packets,
50448- (atomic64_t *)&priv->stats.rx_dropped);
50449+ atomic64_add_unchecked(rx_status.dropped_packets,
50450+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50451 #else
50452- atomic_add(rx_status.dropped_packets,
50453- (atomic_t *)&priv->stats.rx_dropped);
50454+ atomic_add_unchecked(rx_status.dropped_packets,
50455+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50456 #endif
50457 }
50458
50459diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50460index c274b34..f84de76 100644
50461--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50462+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50463@@ -271,7 +271,7 @@ struct hal_ops {
50464 s32 (*c2h_handler)(struct adapter *padapter,
50465 struct c2h_evt_hdr *c2h_evt);
50466 c2h_id_filter c2h_id_filter_ccx;
50467-};
50468+} __no_const;
50469
50470 enum rt_eeprom_type {
50471 EEPROM_93C46,
50472diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50473index e8790f8..b4a5980 100644
50474--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50475+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50476@@ -124,7 +124,7 @@ struct _io_ops {
50477 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50478 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50479 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50480-};
50481+} __no_const;
50482
50483 struct io_req {
50484 struct list_head list;
50485diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50486index dc23395..cf7e9b1 100644
50487--- a/drivers/staging/rtl8712/rtl871x_io.h
50488+++ b/drivers/staging/rtl8712/rtl871x_io.h
50489@@ -108,7 +108,7 @@ struct _io_ops {
50490 u8 *pmem);
50491 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50492 u8 *pmem);
50493-};
50494+} __no_const;
50495
50496 struct io_req {
50497 struct list_head list;
50498diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50499index d183f4b..3f4903d 100644
50500--- a/drivers/staging/rtl8723au/include/hal_intf.h
50501+++ b/drivers/staging/rtl8723au/include/hal_intf.h
50502@@ -251,7 +251,7 @@ struct hal_ops {
50503 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50504 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50505 c2h_id_filter c2h_id_filter_ccx;
50506-};
50507+} __no_const;
50508
50509 enum rt_eeprom_type {
50510 EEPROM_93C46,
50511diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50512index 8d39d800..3f21c0c 100644
50513--- a/drivers/staging/rtl8723au/include/rtw_io.h
50514+++ b/drivers/staging/rtl8723au/include/rtw_io.h
50515@@ -130,7 +130,7 @@ struct _io_ops
50516 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50517 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50518
50519-};
50520+} __no_const;
50521
50522 struct io_req {
50523 struct list_head list;
50524diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50525index fe6c951..72935ba 100644
50526--- a/drivers/staging/sbe-2t3e3/netdev.c
50527+++ b/drivers/staging/sbe-2t3e3/netdev.c
50528@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50529 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50530
50531 if (rlen)
50532- if (copy_to_user(data, &resp, rlen))
50533+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50534 return -EFAULT;
50535
50536 return 0;
50537diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50538index a863a98..d272795 100644
50539--- a/drivers/staging/usbip/vhci.h
50540+++ b/drivers/staging/usbip/vhci.h
50541@@ -83,7 +83,7 @@ struct vhci_hcd {
50542 unsigned resuming:1;
50543 unsigned long re_timeout;
50544
50545- atomic_t seqnum;
50546+ atomic_unchecked_t seqnum;
50547
50548 /*
50549 * NOTE:
50550diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50551index 70e1755..de41855 100644
50552--- a/drivers/staging/usbip/vhci_hcd.c
50553+++ b/drivers/staging/usbip/vhci_hcd.c
50554@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50555
50556 spin_lock(&vdev->priv_lock);
50557
50558- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50559+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50560 if (priv->seqnum == 0xffff)
50561 dev_info(&urb->dev->dev, "seqnum max\n");
50562
50563@@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50564 return -ENOMEM;
50565 }
50566
50567- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50568+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50569 if (unlink->seqnum == 0xffff)
50570 pr_info("seqnum max\n");
50571
50572@@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50573 vdev->rhport = rhport;
50574 }
50575
50576- atomic_set(&vhci->seqnum, 0);
50577+ atomic_set_unchecked(&vhci->seqnum, 0);
50578 spin_lock_init(&vhci->lock);
50579
50580 hcd->power_budget = 0; /* no limit */
50581diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50582index d07fcb5..358e1e1 100644
50583--- a/drivers/staging/usbip/vhci_rx.c
50584+++ b/drivers/staging/usbip/vhci_rx.c
50585@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50586 if (!urb) {
50587 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50588 pr_info("max seqnum %d\n",
50589- atomic_read(&the_controller->seqnum));
50590+ atomic_read_unchecked(&the_controller->seqnum));
50591 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50592 return;
50593 }
50594diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50595index 6eecd53..29317c6 100644
50596--- a/drivers/staging/vt6655/hostap.c
50597+++ b/drivers/staging/vt6655/hostap.c
50598@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50599 *
50600 */
50601
50602+static net_device_ops_no_const apdev_netdev_ops;
50603+
50604 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50605 {
50606 PSDevice apdev_priv;
50607 struct net_device *dev = pDevice->dev;
50608 int ret;
50609- const struct net_device_ops apdev_netdev_ops = {
50610- .ndo_start_xmit = pDevice->tx_80211,
50611- };
50612
50613 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50614
50615@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50616 *apdev_priv = *pDevice;
50617 eth_hw_addr_inherit(pDevice->apdev, dev);
50618
50619+ /* only half broken now */
50620+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50621 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50622
50623 pDevice->apdev->type = ARPHRD_IEEE80211;
50624diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50625index 67ba48b..24e602f 100644
50626--- a/drivers/staging/vt6656/hostap.c
50627+++ b/drivers/staging/vt6656/hostap.c
50628@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50629 *
50630 */
50631
50632+static net_device_ops_no_const apdev_netdev_ops;
50633+
50634 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50635 {
50636 struct vnt_private *apdev_priv;
50637 struct net_device *dev = pDevice->dev;
50638 int ret;
50639- const struct net_device_ops apdev_netdev_ops = {
50640- .ndo_start_xmit = pDevice->tx_80211,
50641- };
50642
50643 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50644
50645@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50646 *apdev_priv = *pDevice;
50647 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50648
50649+ /* only half broken now */
50650+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50651 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50652
50653 pDevice->apdev->type = ARPHRD_IEEE80211;
50654diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50655index e7e9372..161f530 100644
50656--- a/drivers/target/sbp/sbp_target.c
50657+++ b/drivers/target/sbp/sbp_target.c
50658@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50659
50660 #define SESSION_MAINTENANCE_INTERVAL HZ
50661
50662-static atomic_t login_id = ATOMIC_INIT(0);
50663+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50664
50665 static void session_maintenance_work(struct work_struct *);
50666 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50667@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50668 login->lun = se_lun;
50669 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50670 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50671- login->login_id = atomic_inc_return(&login_id);
50672+ login->login_id = atomic_inc_return_unchecked(&login_id);
50673
50674 login->tgt_agt = sbp_target_agent_register(login);
50675 if (IS_ERR(login->tgt_agt)) {
50676diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50677index 6ea95d2..88607b4 100644
50678--- a/drivers/target/target_core_device.c
50679+++ b/drivers/target/target_core_device.c
50680@@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50681 spin_lock_init(&dev->se_tmr_lock);
50682 spin_lock_init(&dev->qf_cmd_lock);
50683 sema_init(&dev->caw_sem, 1);
50684- atomic_set(&dev->dev_ordered_id, 0);
50685+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50686 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50687 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50688 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50689diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50690index 14772e9..42d9f63 100644
50691--- a/drivers/target/target_core_transport.c
50692+++ b/drivers/target/target_core_transport.c
50693@@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50694 * Used to determine when ORDERED commands should go from
50695 * Dormant to Active status.
50696 */
50697- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50698+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50699 smp_mb__after_atomic_inc();
50700 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50701 cmd->se_ordered_id, cmd->sam_task_attr,
50702diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50703index 04b1be7..5eff86d 100644
50704--- a/drivers/thermal/of-thermal.c
50705+++ b/drivers/thermal/of-thermal.c
50706@@ -30,6 +30,7 @@
50707 #include <linux/err.h>
50708 #include <linux/export.h>
50709 #include <linux/string.h>
50710+#include <linux/mm.h>
50711
50712 #include "thermal_core.h"
50713
50714@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50715 tz->get_trend = get_trend;
50716 tz->sensor_data = data;
50717
50718- tzd->ops->get_temp = of_thermal_get_temp;
50719- tzd->ops->get_trend = of_thermal_get_trend;
50720+ pax_open_kernel();
50721+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50722+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50723+ pax_close_kernel();
50724 mutex_unlock(&tzd->lock);
50725
50726 return tzd;
50727@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50728 return;
50729
50730 mutex_lock(&tzd->lock);
50731- tzd->ops->get_temp = NULL;
50732- tzd->ops->get_trend = NULL;
50733+ pax_open_kernel();
50734+ *(void **)&tzd->ops->get_temp = NULL;
50735+ *(void **)&tzd->ops->get_trend = NULL;
50736+ pax_close_kernel();
50737
50738 tz->get_temp = NULL;
50739 tz->get_trend = NULL;
50740diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50741index a57bb5a..1f727d33 100644
50742--- a/drivers/tty/cyclades.c
50743+++ b/drivers/tty/cyclades.c
50744@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50745 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50746 info->port.count);
50747 #endif
50748- info->port.count++;
50749+ atomic_inc(&info->port.count);
50750 #ifdef CY_DEBUG_COUNT
50751 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50752- current->pid, info->port.count);
50753+ current->pid, atomic_read(&info->port.count));
50754 #endif
50755
50756 /*
50757@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50758 for (j = 0; j < cy_card[i].nports; j++) {
50759 info = &cy_card[i].ports[j];
50760
50761- if (info->port.count) {
50762+ if (atomic_read(&info->port.count)) {
50763 /* XXX is the ldisc num worth this? */
50764 struct tty_struct *tty;
50765 struct tty_ldisc *ld;
50766diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50767index 0ff7fda..dbc7d52 100644
50768--- a/drivers/tty/hvc/hvc_console.c
50769+++ b/drivers/tty/hvc/hvc_console.c
50770@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50771
50772 spin_lock_irqsave(&hp->port.lock, flags);
50773 /* Check and then increment for fast path open. */
50774- if (hp->port.count++ > 0) {
50775+ if (atomic_inc_return(&hp->port.count) > 1) {
50776 spin_unlock_irqrestore(&hp->port.lock, flags);
50777 hvc_kick();
50778 return 0;
50779@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50780
50781 spin_lock_irqsave(&hp->port.lock, flags);
50782
50783- if (--hp->port.count == 0) {
50784+ if (atomic_dec_return(&hp->port.count) == 0) {
50785 spin_unlock_irqrestore(&hp->port.lock, flags);
50786 /* We are done with the tty pointer now. */
50787 tty_port_tty_set(&hp->port, NULL);
50788@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50789 */
50790 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50791 } else {
50792- if (hp->port.count < 0)
50793+ if (atomic_read(&hp->port.count) < 0)
50794 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50795- hp->vtermno, hp->port.count);
50796+ hp->vtermno, atomic_read(&hp->port.count));
50797 spin_unlock_irqrestore(&hp->port.lock, flags);
50798 }
50799 }
50800@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50801 * open->hangup case this can be called after the final close so prevent
50802 * that from happening for now.
50803 */
50804- if (hp->port.count <= 0) {
50805+ if (atomic_read(&hp->port.count) <= 0) {
50806 spin_unlock_irqrestore(&hp->port.lock, flags);
50807 return;
50808 }
50809
50810- hp->port.count = 0;
50811+ atomic_set(&hp->port.count, 0);
50812 spin_unlock_irqrestore(&hp->port.lock, flags);
50813 tty_port_tty_set(&hp->port, NULL);
50814
50815@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50816 return -EPIPE;
50817
50818 /* FIXME what's this (unprotected) check for? */
50819- if (hp->port.count <= 0)
50820+ if (atomic_read(&hp->port.count) <= 0)
50821 return -EIO;
50822
50823 spin_lock_irqsave(&hp->lock, flags);
50824diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50825index 81e939e..95ead10 100644
50826--- a/drivers/tty/hvc/hvcs.c
50827+++ b/drivers/tty/hvc/hvcs.c
50828@@ -83,6 +83,7 @@
50829 #include <asm/hvcserver.h>
50830 #include <asm/uaccess.h>
50831 #include <asm/vio.h>
50832+#include <asm/local.h>
50833
50834 /*
50835 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50836@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50837
50838 spin_lock_irqsave(&hvcsd->lock, flags);
50839
50840- if (hvcsd->port.count > 0) {
50841+ if (atomic_read(&hvcsd->port.count) > 0) {
50842 spin_unlock_irqrestore(&hvcsd->lock, flags);
50843 printk(KERN_INFO "HVCS: vterm state unchanged. "
50844 "The hvcs device node is still in use.\n");
50845@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50846 }
50847 }
50848
50849- hvcsd->port.count = 0;
50850+ atomic_set(&hvcsd->port.count, 0);
50851 hvcsd->port.tty = tty;
50852 tty->driver_data = hvcsd;
50853
50854@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50855 unsigned long flags;
50856
50857 spin_lock_irqsave(&hvcsd->lock, flags);
50858- hvcsd->port.count++;
50859+ atomic_inc(&hvcsd->port.count);
50860 hvcsd->todo_mask |= HVCS_SCHED_READ;
50861 spin_unlock_irqrestore(&hvcsd->lock, flags);
50862
50863@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50864 hvcsd = tty->driver_data;
50865
50866 spin_lock_irqsave(&hvcsd->lock, flags);
50867- if (--hvcsd->port.count == 0) {
50868+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50869
50870 vio_disable_interrupts(hvcsd->vdev);
50871
50872@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50873
50874 free_irq(irq, hvcsd);
50875 return;
50876- } else if (hvcsd->port.count < 0) {
50877+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50878 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50879 " is missmanaged.\n",
50880- hvcsd->vdev->unit_address, hvcsd->port.count);
50881+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50882 }
50883
50884 spin_unlock_irqrestore(&hvcsd->lock, flags);
50885@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50886
50887 spin_lock_irqsave(&hvcsd->lock, flags);
50888 /* Preserve this so that we know how many kref refs to put */
50889- temp_open_count = hvcsd->port.count;
50890+ temp_open_count = atomic_read(&hvcsd->port.count);
50891
50892 /*
50893 * Don't kref put inside the spinlock because the destruction
50894@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50895 tty->driver_data = NULL;
50896 hvcsd->port.tty = NULL;
50897
50898- hvcsd->port.count = 0;
50899+ atomic_set(&hvcsd->port.count, 0);
50900
50901 /* This will drop any buffered data on the floor which is OK in a hangup
50902 * scenario. */
50903@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50904 * the middle of a write operation? This is a crummy place to do this
50905 * but we want to keep it all in the spinlock.
50906 */
50907- if (hvcsd->port.count <= 0) {
50908+ if (atomic_read(&hvcsd->port.count) <= 0) {
50909 spin_unlock_irqrestore(&hvcsd->lock, flags);
50910 return -ENODEV;
50911 }
50912@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50913 {
50914 struct hvcs_struct *hvcsd = tty->driver_data;
50915
50916- if (!hvcsd || hvcsd->port.count <= 0)
50917+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50918 return 0;
50919
50920 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50921diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50922index 4190199..06d5bfa 100644
50923--- a/drivers/tty/hvc/hvsi.c
50924+++ b/drivers/tty/hvc/hvsi.c
50925@@ -85,7 +85,7 @@ struct hvsi_struct {
50926 int n_outbuf;
50927 uint32_t vtermno;
50928 uint32_t virq;
50929- atomic_t seqno; /* HVSI packet sequence number */
50930+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50931 uint16_t mctrl;
50932 uint8_t state; /* HVSI protocol state */
50933 uint8_t flags;
50934@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50935
50936 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50937 packet.hdr.len = sizeof(struct hvsi_query_response);
50938- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50939+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50940 packet.verb = VSV_SEND_VERSION_NUMBER;
50941 packet.u.version = HVSI_VERSION;
50942 packet.query_seqno = query_seqno+1;
50943@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50944
50945 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50946 packet.hdr.len = sizeof(struct hvsi_query);
50947- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50948+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50949 packet.verb = verb;
50950
50951 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50952@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50953 int wrote;
50954
50955 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50956- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50957+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50958 packet.hdr.len = sizeof(struct hvsi_control);
50959 packet.verb = VSV_SET_MODEM_CTL;
50960 packet.mask = HVSI_TSDTR;
50961@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50962 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50963
50964 packet.hdr.type = VS_DATA_PACKET_HEADER;
50965- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50966+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50967 packet.hdr.len = count + sizeof(struct hvsi_header);
50968 memcpy(&packet.data, buf, count);
50969
50970@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50971 struct hvsi_control packet __ALIGNED__;
50972
50973 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50974- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50975+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50976 packet.hdr.len = 6;
50977 packet.verb = VSV_CLOSE_PROTOCOL;
50978
50979@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50980
50981 tty_port_tty_set(&hp->port, tty);
50982 spin_lock_irqsave(&hp->lock, flags);
50983- hp->port.count++;
50984+ atomic_inc(&hp->port.count);
50985 atomic_set(&hp->seqno, 0);
50986 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50987 spin_unlock_irqrestore(&hp->lock, flags);
50988@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50989
50990 spin_lock_irqsave(&hp->lock, flags);
50991
50992- if (--hp->port.count == 0) {
50993+ if (atomic_dec_return(&hp->port.count) == 0) {
50994 tty_port_tty_set(&hp->port, NULL);
50995 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50996
50997@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50998
50999 spin_lock_irqsave(&hp->lock, flags);
51000 }
51001- } else if (hp->port.count < 0)
51002+ } else if (atomic_read(&hp->port.count) < 0)
51003 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
51004- hp - hvsi_ports, hp->port.count);
51005+ hp - hvsi_ports, atomic_read(&hp->port.count));
51006
51007 spin_unlock_irqrestore(&hp->lock, flags);
51008 }
51009@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
51010 tty_port_tty_set(&hp->port, NULL);
51011
51012 spin_lock_irqsave(&hp->lock, flags);
51013- hp->port.count = 0;
51014+ atomic_set(&hp->port.count, 0);
51015 hp->n_outbuf = 0;
51016 spin_unlock_irqrestore(&hp->lock, flags);
51017 }
51018diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
51019index 7ae6c29..05c6dba 100644
51020--- a/drivers/tty/hvc/hvsi_lib.c
51021+++ b/drivers/tty/hvc/hvsi_lib.c
51022@@ -8,7 +8,7 @@
51023
51024 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
51025 {
51026- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51027+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51028
51029 /* Assumes that always succeeds, works in practice */
51030 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51031@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51032
51033 /* Reset state */
51034 pv->established = 0;
51035- atomic_set(&pv->seqno, 0);
51036+ atomic_set_unchecked(&pv->seqno, 0);
51037
51038 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51039
51040diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51041index 17ee3bf..8d2520d 100644
51042--- a/drivers/tty/ipwireless/tty.c
51043+++ b/drivers/tty/ipwireless/tty.c
51044@@ -28,6 +28,7 @@
51045 #include <linux/tty_driver.h>
51046 #include <linux/tty_flip.h>
51047 #include <linux/uaccess.h>
51048+#include <asm/local.h>
51049
51050 #include "tty.h"
51051 #include "network.h"
51052@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51053 mutex_unlock(&tty->ipw_tty_mutex);
51054 return -ENODEV;
51055 }
51056- if (tty->port.count == 0)
51057+ if (atomic_read(&tty->port.count) == 0)
51058 tty->tx_bytes_queued = 0;
51059
51060- tty->port.count++;
51061+ atomic_inc(&tty->port.count);
51062
51063 tty->port.tty = linux_tty;
51064 linux_tty->driver_data = tty;
51065@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51066
51067 static void do_ipw_close(struct ipw_tty *tty)
51068 {
51069- tty->port.count--;
51070-
51071- if (tty->port.count == 0) {
51072+ if (atomic_dec_return(&tty->port.count) == 0) {
51073 struct tty_struct *linux_tty = tty->port.tty;
51074
51075 if (linux_tty != NULL) {
51076@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51077 return;
51078
51079 mutex_lock(&tty->ipw_tty_mutex);
51080- if (tty->port.count == 0) {
51081+ if (atomic_read(&tty->port.count) == 0) {
51082 mutex_unlock(&tty->ipw_tty_mutex);
51083 return;
51084 }
51085@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51086
51087 mutex_lock(&tty->ipw_tty_mutex);
51088
51089- if (!tty->port.count) {
51090+ if (!atomic_read(&tty->port.count)) {
51091 mutex_unlock(&tty->ipw_tty_mutex);
51092 return;
51093 }
51094@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51095 return -ENODEV;
51096
51097 mutex_lock(&tty->ipw_tty_mutex);
51098- if (!tty->port.count) {
51099+ if (!atomic_read(&tty->port.count)) {
51100 mutex_unlock(&tty->ipw_tty_mutex);
51101 return -EINVAL;
51102 }
51103@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51104 if (!tty)
51105 return -ENODEV;
51106
51107- if (!tty->port.count)
51108+ if (!atomic_read(&tty->port.count))
51109 return -EINVAL;
51110
51111 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51112@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51113 if (!tty)
51114 return 0;
51115
51116- if (!tty->port.count)
51117+ if (!atomic_read(&tty->port.count))
51118 return 0;
51119
51120 return tty->tx_bytes_queued;
51121@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51122 if (!tty)
51123 return -ENODEV;
51124
51125- if (!tty->port.count)
51126+ if (!atomic_read(&tty->port.count))
51127 return -EINVAL;
51128
51129 return get_control_lines(tty);
51130@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51131 if (!tty)
51132 return -ENODEV;
51133
51134- if (!tty->port.count)
51135+ if (!atomic_read(&tty->port.count))
51136 return -EINVAL;
51137
51138 return set_control_lines(tty, set, clear);
51139@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51140 if (!tty)
51141 return -ENODEV;
51142
51143- if (!tty->port.count)
51144+ if (!atomic_read(&tty->port.count))
51145 return -EINVAL;
51146
51147 /* FIXME: Exactly how is the tty object locked here .. */
51148@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51149 * are gone */
51150 mutex_lock(&ttyj->ipw_tty_mutex);
51151 }
51152- while (ttyj->port.count)
51153+ while (atomic_read(&ttyj->port.count))
51154 do_ipw_close(ttyj);
51155 ipwireless_disassociate_network_ttys(network,
51156 ttyj->channel_idx);
51157diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51158index 1deaca4..c8582d4 100644
51159--- a/drivers/tty/moxa.c
51160+++ b/drivers/tty/moxa.c
51161@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51162 }
51163
51164 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51165- ch->port.count++;
51166+ atomic_inc(&ch->port.count);
51167 tty->driver_data = ch;
51168 tty_port_tty_set(&ch->port, tty);
51169 mutex_lock(&ch->port.mutex);
51170diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51171index 2ebe47b..3205833 100644
51172--- a/drivers/tty/n_gsm.c
51173+++ b/drivers/tty/n_gsm.c
51174@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51175 spin_lock_init(&dlci->lock);
51176 mutex_init(&dlci->mutex);
51177 dlci->fifo = &dlci->_fifo;
51178- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51179+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51180 kfree(dlci);
51181 return NULL;
51182 }
51183@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51184 struct gsm_dlci *dlci = tty->driver_data;
51185 struct tty_port *port = &dlci->port;
51186
51187- port->count++;
51188+ atomic_inc(&port->count);
51189 tty_port_tty_set(port, tty);
51190
51191 dlci->modem_rx = 0;
51192diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51193index 0391f17..31fa586 100644
51194--- a/drivers/tty/n_tty.c
51195+++ b/drivers/tty/n_tty.c
51196@@ -115,7 +115,7 @@ struct n_tty_data {
51197 int minimum_to_wake;
51198
51199 /* consumer-published */
51200- size_t read_tail;
51201+ size_t read_tail __intentional_overflow(-1);
51202 size_t line_start;
51203
51204 /* protected by output lock */
51205@@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51206 {
51207 *ops = tty_ldisc_N_TTY;
51208 ops->owner = NULL;
51209- ops->refcount = ops->flags = 0;
51210+ atomic_set(&ops->refcount, 0);
51211+ ops->flags = 0;
51212 }
51213 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51214diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51215index 25c9bc7..24077b7 100644
51216--- a/drivers/tty/pty.c
51217+++ b/drivers/tty/pty.c
51218@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51219 panic("Couldn't register Unix98 pts driver");
51220
51221 /* Now create the /dev/ptmx special device */
51222+ pax_open_kernel();
51223 tty_default_fops(&ptmx_fops);
51224- ptmx_fops.open = ptmx_open;
51225+ *(void **)&ptmx_fops.open = ptmx_open;
51226+ pax_close_kernel();
51227
51228 cdev_init(&ptmx_cdev, &ptmx_fops);
51229 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51230diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51231index 383c4c7..d408e21 100644
51232--- a/drivers/tty/rocket.c
51233+++ b/drivers/tty/rocket.c
51234@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51235 tty->driver_data = info;
51236 tty_port_tty_set(port, tty);
51237
51238- if (port->count++ == 0) {
51239+ if (atomic_inc_return(&port->count) == 1) {
51240 atomic_inc(&rp_num_ports_open);
51241
51242 #ifdef ROCKET_DEBUG_OPEN
51243@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51244 #endif
51245 }
51246 #ifdef ROCKET_DEBUG_OPEN
51247- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51248+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51249 #endif
51250
51251 /*
51252@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51253 spin_unlock_irqrestore(&info->port.lock, flags);
51254 return;
51255 }
51256- if (info->port.count)
51257+ if (atomic_read(&info->port.count))
51258 atomic_dec(&rp_num_ports_open);
51259 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51260 spin_unlock_irqrestore(&info->port.lock, flags);
51261diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51262index 1274499..f541382 100644
51263--- a/drivers/tty/serial/ioc4_serial.c
51264+++ b/drivers/tty/serial/ioc4_serial.c
51265@@ -437,7 +437,7 @@ struct ioc4_soft {
51266 } is_intr_info[MAX_IOC4_INTR_ENTS];
51267
51268 /* Number of entries active in the above array */
51269- atomic_t is_num_intrs;
51270+ atomic_unchecked_t is_num_intrs;
51271 } is_intr_type[IOC4_NUM_INTR_TYPES];
51272
51273 /* is_ir_lock must be held while
51274@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51275 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51276 || (type == IOC4_OTHER_INTR_TYPE)));
51277
51278- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51279+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51280 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51281
51282 /* Save off the lower level interrupt handler */
51283@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51284
51285 soft = arg;
51286 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51287- num_intrs = (int)atomic_read(
51288+ num_intrs = (int)atomic_read_unchecked(
51289 &soft->is_intr_type[intr_type].is_num_intrs);
51290
51291 this_mir = this_ir = pending_intrs(soft, intr_type);
51292diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51293index a260cde..6b2b5ce 100644
51294--- a/drivers/tty/serial/kgdboc.c
51295+++ b/drivers/tty/serial/kgdboc.c
51296@@ -24,8 +24,9 @@
51297 #define MAX_CONFIG_LEN 40
51298
51299 static struct kgdb_io kgdboc_io_ops;
51300+static struct kgdb_io kgdboc_io_ops_console;
51301
51302-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51303+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51304 static int configured = -1;
51305
51306 static char config[MAX_CONFIG_LEN];
51307@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51308 kgdboc_unregister_kbd();
51309 if (configured == 1)
51310 kgdb_unregister_io_module(&kgdboc_io_ops);
51311+ else if (configured == 2)
51312+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
51313 }
51314
51315 static int configure_kgdboc(void)
51316@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51317 int err;
51318 char *cptr = config;
51319 struct console *cons;
51320+ int is_console = 0;
51321
51322 err = kgdboc_option_setup(config);
51323 if (err || !strlen(config) || isspace(config[0]))
51324 goto noconfig;
51325
51326 err = -ENODEV;
51327- kgdboc_io_ops.is_console = 0;
51328 kgdb_tty_driver = NULL;
51329
51330 kgdboc_use_kms = 0;
51331@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51332 int idx;
51333 if (cons->device && cons->device(cons, &idx) == p &&
51334 idx == tty_line) {
51335- kgdboc_io_ops.is_console = 1;
51336+ is_console = 1;
51337 break;
51338 }
51339 cons = cons->next;
51340@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51341 kgdb_tty_line = tty_line;
51342
51343 do_register:
51344- err = kgdb_register_io_module(&kgdboc_io_ops);
51345+ if (is_console) {
51346+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
51347+ configured = 2;
51348+ } else {
51349+ err = kgdb_register_io_module(&kgdboc_io_ops);
51350+ configured = 1;
51351+ }
51352 if (err)
51353 goto noconfig;
51354
51355@@ -205,8 +214,6 @@ do_register:
51356 if (err)
51357 goto nmi_con_failed;
51358
51359- configured = 1;
51360-
51361 return 0;
51362
51363 nmi_con_failed:
51364@@ -223,7 +230,7 @@ noconfig:
51365 static int __init init_kgdboc(void)
51366 {
51367 /* Already configured? */
51368- if (configured == 1)
51369+ if (configured >= 1)
51370 return 0;
51371
51372 return configure_kgdboc();
51373@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51374 if (config[len - 1] == '\n')
51375 config[len - 1] = '\0';
51376
51377- if (configured == 1)
51378+ if (configured >= 1)
51379 cleanup_kgdboc();
51380
51381 /* Go and configure with the new params. */
51382@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51383 .post_exception = kgdboc_post_exp_handler,
51384 };
51385
51386+static struct kgdb_io kgdboc_io_ops_console = {
51387+ .name = "kgdboc",
51388+ .read_char = kgdboc_get_char,
51389+ .write_char = kgdboc_put_char,
51390+ .pre_exception = kgdboc_pre_exp_handler,
51391+ .post_exception = kgdboc_post_exp_handler,
51392+ .is_console = 1
51393+};
51394+
51395 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51396 /* This is only available if kgdboc is a built in for early debugging */
51397 static int __init kgdboc_early_init(char *opt)
51398diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51399index 7307dc4..ce4fe90 100644
51400--- a/drivers/tty/serial/msm_serial.c
51401+++ b/drivers/tty/serial/msm_serial.c
51402@@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
51403 .cons = MSM_CONSOLE,
51404 };
51405
51406-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51407+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51408
51409 static const struct of_device_id msm_uartdm_table[] = {
51410 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
51411@@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51412 int irq;
51413
51414 if (pdev->id == -1)
51415- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51416+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51417
51418 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51419 return -ENXIO;
51420diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51421index 1f5505e..a1a767d 100644
51422--- a/drivers/tty/serial/samsung.c
51423+++ b/drivers/tty/serial/samsung.c
51424@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51425 }
51426 }
51427
51428+static int s3c64xx_serial_startup(struct uart_port *port);
51429 static int s3c24xx_serial_startup(struct uart_port *port)
51430 {
51431 struct s3c24xx_uart_port *ourport = to_ourport(port);
51432 int ret;
51433
51434+ /* Startup sequence is different for s3c64xx and higher SoC's */
51435+ if (s3c24xx_serial_has_interrupt_mask(port))
51436+ return s3c64xx_serial_startup(port);
51437+
51438 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51439 port->mapbase, port->membase);
51440
51441@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51442 /* setup info for port */
51443 port->dev = &platdev->dev;
51444
51445- /* Startup sequence is different for s3c64xx and higher SoC's */
51446- if (s3c24xx_serial_has_interrupt_mask(port))
51447- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51448-
51449 port->uartclk = 1;
51450
51451 if (cfg->uart_flags & UPF_CONS_FLOW) {
51452diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51453index b68550d..a62d7f8 100644
51454--- a/drivers/tty/serial/serial_core.c
51455+++ b/drivers/tty/serial/serial_core.c
51456@@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
51457
51458 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
51459
51460- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
51461+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
51462 return;
51463
51464 /*
51465@@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51466 uart_flush_buffer(tty);
51467 uart_shutdown(tty, state);
51468 spin_lock_irqsave(&port->lock, flags);
51469- port->count = 0;
51470+ atomic_set(&port->count, 0);
51471 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51472 spin_unlock_irqrestore(&port->lock, flags);
51473 tty_port_tty_set(port, NULL);
51474@@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51475 goto end;
51476 }
51477
51478- port->count++;
51479+ atomic_inc(&port->count);
51480 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51481 retval = -ENXIO;
51482 goto err_dec_count;
51483@@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51484 end:
51485 return retval;
51486 err_dec_count:
51487- port->count--;
51488+ atomic_inc(&port->count);
51489 mutex_unlock(&port->mutex);
51490 goto end;
51491 }
51492diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51493index d48e040..0f52764 100644
51494--- a/drivers/tty/synclink.c
51495+++ b/drivers/tty/synclink.c
51496@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51497
51498 if (debug_level >= DEBUG_LEVEL_INFO)
51499 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51500- __FILE__,__LINE__, info->device_name, info->port.count);
51501+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51502
51503 if (tty_port_close_start(&info->port, tty, filp) == 0)
51504 goto cleanup;
51505@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51506 cleanup:
51507 if (debug_level >= DEBUG_LEVEL_INFO)
51508 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51509- tty->driver->name, info->port.count);
51510+ tty->driver->name, atomic_read(&info->port.count));
51511
51512 } /* end of mgsl_close() */
51513
51514@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51515
51516 mgsl_flush_buffer(tty);
51517 shutdown(info);
51518-
51519- info->port.count = 0;
51520+
51521+ atomic_set(&info->port.count, 0);
51522 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51523 info->port.tty = NULL;
51524
51525@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51526
51527 if (debug_level >= DEBUG_LEVEL_INFO)
51528 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51529- __FILE__,__LINE__, tty->driver->name, port->count );
51530+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51531
51532 spin_lock_irqsave(&info->irq_spinlock, flags);
51533 if (!tty_hung_up_p(filp)) {
51534 extra_count = true;
51535- port->count--;
51536+ atomic_dec(&port->count);
51537 }
51538 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51539 port->blocked_open++;
51540@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51541
51542 if (debug_level >= DEBUG_LEVEL_INFO)
51543 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51544- __FILE__,__LINE__, tty->driver->name, port->count );
51545+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51546
51547 tty_unlock(tty);
51548 schedule();
51549@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51550
51551 /* FIXME: Racy on hangup during close wait */
51552 if (extra_count)
51553- port->count++;
51554+ atomic_inc(&port->count);
51555 port->blocked_open--;
51556
51557 if (debug_level >= DEBUG_LEVEL_INFO)
51558 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51559- __FILE__,__LINE__, tty->driver->name, port->count );
51560+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51561
51562 if (!retval)
51563 port->flags |= ASYNC_NORMAL_ACTIVE;
51564@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51565
51566 if (debug_level >= DEBUG_LEVEL_INFO)
51567 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51568- __FILE__,__LINE__,tty->driver->name, info->port.count);
51569+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51570
51571 /* If port is closing, signal caller to try again */
51572 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51573@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51574 spin_unlock_irqrestore(&info->netlock, flags);
51575 goto cleanup;
51576 }
51577- info->port.count++;
51578+ atomic_inc(&info->port.count);
51579 spin_unlock_irqrestore(&info->netlock, flags);
51580
51581- if (info->port.count == 1) {
51582+ if (atomic_read(&info->port.count) == 1) {
51583 /* 1st open on this device, init hardware */
51584 retval = startup(info);
51585 if (retval < 0)
51586@@ -3446,8 +3446,8 @@ cleanup:
51587 if (retval) {
51588 if (tty->count == 1)
51589 info->port.tty = NULL; /* tty layer will release tty struct */
51590- if(info->port.count)
51591- info->port.count--;
51592+ if (atomic_read(&info->port.count))
51593+ atomic_dec(&info->port.count);
51594 }
51595
51596 return retval;
51597@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51598 unsigned short new_crctype;
51599
51600 /* return error if TTY interface open */
51601- if (info->port.count)
51602+ if (atomic_read(&info->port.count))
51603 return -EBUSY;
51604
51605 switch (encoding)
51606@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51607
51608 /* arbitrate between network and tty opens */
51609 spin_lock_irqsave(&info->netlock, flags);
51610- if (info->port.count != 0 || info->netcount != 0) {
51611+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51612 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51613 spin_unlock_irqrestore(&info->netlock, flags);
51614 return -EBUSY;
51615@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51616 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51617
51618 /* return error if TTY interface open */
51619- if (info->port.count)
51620+ if (atomic_read(&info->port.count))
51621 return -EBUSY;
51622
51623 if (cmd != SIOCWANDEV)
51624diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51625index c359a91..959fc26 100644
51626--- a/drivers/tty/synclink_gt.c
51627+++ b/drivers/tty/synclink_gt.c
51628@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51629 tty->driver_data = info;
51630 info->port.tty = tty;
51631
51632- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51633+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51634
51635 /* If port is closing, signal caller to try again */
51636 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51637@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51638 mutex_unlock(&info->port.mutex);
51639 goto cleanup;
51640 }
51641- info->port.count++;
51642+ atomic_inc(&info->port.count);
51643 spin_unlock_irqrestore(&info->netlock, flags);
51644
51645- if (info->port.count == 1) {
51646+ if (atomic_read(&info->port.count) == 1) {
51647 /* 1st open on this device, init hardware */
51648 retval = startup(info);
51649 if (retval < 0) {
51650@@ -715,8 +715,8 @@ cleanup:
51651 if (retval) {
51652 if (tty->count == 1)
51653 info->port.tty = NULL; /* tty layer will release tty struct */
51654- if(info->port.count)
51655- info->port.count--;
51656+ if(atomic_read(&info->port.count))
51657+ atomic_dec(&info->port.count);
51658 }
51659
51660 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51661@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51662
51663 if (sanity_check(info, tty->name, "close"))
51664 return;
51665- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51666+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51667
51668 if (tty_port_close_start(&info->port, tty, filp) == 0)
51669 goto cleanup;
51670@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51671 tty_port_close_end(&info->port, tty);
51672 info->port.tty = NULL;
51673 cleanup:
51674- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51675+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51676 }
51677
51678 static void hangup(struct tty_struct *tty)
51679@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51680 shutdown(info);
51681
51682 spin_lock_irqsave(&info->port.lock, flags);
51683- info->port.count = 0;
51684+ atomic_set(&info->port.count, 0);
51685 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51686 info->port.tty = NULL;
51687 spin_unlock_irqrestore(&info->port.lock, flags);
51688@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51689 unsigned short new_crctype;
51690
51691 /* return error if TTY interface open */
51692- if (info->port.count)
51693+ if (atomic_read(&info->port.count))
51694 return -EBUSY;
51695
51696 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51697@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51698
51699 /* arbitrate between network and tty opens */
51700 spin_lock_irqsave(&info->netlock, flags);
51701- if (info->port.count != 0 || info->netcount != 0) {
51702+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51703 DBGINFO(("%s hdlc_open busy\n", dev->name));
51704 spin_unlock_irqrestore(&info->netlock, flags);
51705 return -EBUSY;
51706@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51707 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51708
51709 /* return error if TTY interface open */
51710- if (info->port.count)
51711+ if (atomic_read(&info->port.count))
51712 return -EBUSY;
51713
51714 if (cmd != SIOCWANDEV)
51715@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51716 if (port == NULL)
51717 continue;
51718 spin_lock(&port->lock);
51719- if ((port->port.count || port->netcount) &&
51720+ if ((atomic_read(&port->port.count) || port->netcount) &&
51721 port->pending_bh && !port->bh_running &&
51722 !port->bh_requested) {
51723 DBGISR(("%s bh queued\n", port->device_name));
51724@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51725 spin_lock_irqsave(&info->lock, flags);
51726 if (!tty_hung_up_p(filp)) {
51727 extra_count = true;
51728- port->count--;
51729+ atomic_dec(&port->count);
51730 }
51731 spin_unlock_irqrestore(&info->lock, flags);
51732 port->blocked_open++;
51733@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51734 remove_wait_queue(&port->open_wait, &wait);
51735
51736 if (extra_count)
51737- port->count++;
51738+ atomic_inc(&port->count);
51739 port->blocked_open--;
51740
51741 if (!retval)
51742diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51743index 53ba853..3c30f6d 100644
51744--- a/drivers/tty/synclinkmp.c
51745+++ b/drivers/tty/synclinkmp.c
51746@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51747
51748 if (debug_level >= DEBUG_LEVEL_INFO)
51749 printk("%s(%d):%s open(), old ref count = %d\n",
51750- __FILE__,__LINE__,tty->driver->name, info->port.count);
51751+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51752
51753 /* If port is closing, signal caller to try again */
51754 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51755@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51756 spin_unlock_irqrestore(&info->netlock, flags);
51757 goto cleanup;
51758 }
51759- info->port.count++;
51760+ atomic_inc(&info->port.count);
51761 spin_unlock_irqrestore(&info->netlock, flags);
51762
51763- if (info->port.count == 1) {
51764+ if (atomic_read(&info->port.count) == 1) {
51765 /* 1st open on this device, init hardware */
51766 retval = startup(info);
51767 if (retval < 0)
51768@@ -796,8 +796,8 @@ cleanup:
51769 if (retval) {
51770 if (tty->count == 1)
51771 info->port.tty = NULL; /* tty layer will release tty struct */
51772- if(info->port.count)
51773- info->port.count--;
51774+ if(atomic_read(&info->port.count))
51775+ atomic_dec(&info->port.count);
51776 }
51777
51778 return retval;
51779@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51780
51781 if (debug_level >= DEBUG_LEVEL_INFO)
51782 printk("%s(%d):%s close() entry, count=%d\n",
51783- __FILE__,__LINE__, info->device_name, info->port.count);
51784+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51785
51786 if (tty_port_close_start(&info->port, tty, filp) == 0)
51787 goto cleanup;
51788@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51789 cleanup:
51790 if (debug_level >= DEBUG_LEVEL_INFO)
51791 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51792- tty->driver->name, info->port.count);
51793+ tty->driver->name, atomic_read(&info->port.count));
51794 }
51795
51796 /* Called by tty_hangup() when a hangup is signaled.
51797@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51798 shutdown(info);
51799
51800 spin_lock_irqsave(&info->port.lock, flags);
51801- info->port.count = 0;
51802+ atomic_set(&info->port.count, 0);
51803 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51804 info->port.tty = NULL;
51805 spin_unlock_irqrestore(&info->port.lock, flags);
51806@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51807 unsigned short new_crctype;
51808
51809 /* return error if TTY interface open */
51810- if (info->port.count)
51811+ if (atomic_read(&info->port.count))
51812 return -EBUSY;
51813
51814 switch (encoding)
51815@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51816
51817 /* arbitrate between network and tty opens */
51818 spin_lock_irqsave(&info->netlock, flags);
51819- if (info->port.count != 0 || info->netcount != 0) {
51820+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51821 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51822 spin_unlock_irqrestore(&info->netlock, flags);
51823 return -EBUSY;
51824@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51825 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51826
51827 /* return error if TTY interface open */
51828- if (info->port.count)
51829+ if (atomic_read(&info->port.count))
51830 return -EBUSY;
51831
51832 if (cmd != SIOCWANDEV)
51833@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51834 * do not request bottom half processing if the
51835 * device is not open in a normal mode.
51836 */
51837- if ( port && (port->port.count || port->netcount) &&
51838+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51839 port->pending_bh && !port->bh_running &&
51840 !port->bh_requested ) {
51841 if ( debug_level >= DEBUG_LEVEL_ISR )
51842@@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51843
51844 if (debug_level >= DEBUG_LEVEL_INFO)
51845 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51846- __FILE__,__LINE__, tty->driver->name, port->count );
51847+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51848
51849 spin_lock_irqsave(&info->lock, flags);
51850 if (!tty_hung_up_p(filp)) {
51851 extra_count = true;
51852- port->count--;
51853+ atomic_dec(&port->count);
51854 }
51855 spin_unlock_irqrestore(&info->lock, flags);
51856 port->blocked_open++;
51857@@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51858
51859 if (debug_level >= DEBUG_LEVEL_INFO)
51860 printk("%s(%d):%s block_til_ready() count=%d\n",
51861- __FILE__,__LINE__, tty->driver->name, port->count );
51862+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51863
51864 tty_unlock(tty);
51865 schedule();
51866@@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51867 remove_wait_queue(&port->open_wait, &wait);
51868
51869 if (extra_count)
51870- port->count++;
51871+ atomic_inc(&port->count);
51872 port->blocked_open--;
51873
51874 if (debug_level >= DEBUG_LEVEL_INFO)
51875 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51876- __FILE__,__LINE__, tty->driver->name, port->count );
51877+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51878
51879 if (!retval)
51880 port->flags |= ASYNC_NORMAL_ACTIVE;
51881diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51882index ce396ec..04a37be 100644
51883--- a/drivers/tty/sysrq.c
51884+++ b/drivers/tty/sysrq.c
51885@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51886 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51887 size_t count, loff_t *ppos)
51888 {
51889- if (count) {
51890+ if (count && capable(CAP_SYS_ADMIN)) {
51891 char c;
51892
51893 if (get_user(c, buf))
51894diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51895index 3411071..86f2cf2 100644
51896--- a/drivers/tty/tty_io.c
51897+++ b/drivers/tty/tty_io.c
51898@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51899
51900 void tty_default_fops(struct file_operations *fops)
51901 {
51902- *fops = tty_fops;
51903+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51904 }
51905
51906 /*
51907diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51908index 2d822aa..a566234 100644
51909--- a/drivers/tty/tty_ldisc.c
51910+++ b/drivers/tty/tty_ldisc.c
51911@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51912 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51913 tty_ldiscs[disc] = new_ldisc;
51914 new_ldisc->num = disc;
51915- new_ldisc->refcount = 0;
51916+ atomic_set(&new_ldisc->refcount, 0);
51917 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51918
51919 return ret;
51920@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51921 return -EINVAL;
51922
51923 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51924- if (tty_ldiscs[disc]->refcount)
51925+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51926 ret = -EBUSY;
51927 else
51928 tty_ldiscs[disc] = NULL;
51929@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51930 if (ldops) {
51931 ret = ERR_PTR(-EAGAIN);
51932 if (try_module_get(ldops->owner)) {
51933- ldops->refcount++;
51934+ atomic_inc(&ldops->refcount);
51935 ret = ldops;
51936 }
51937 }
51938@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51939 unsigned long flags;
51940
51941 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51942- ldops->refcount--;
51943+ atomic_dec(&ldops->refcount);
51944 module_put(ldops->owner);
51945 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51946 }
51947diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51948index 3f746c8..2f2fcaa 100644
51949--- a/drivers/tty/tty_port.c
51950+++ b/drivers/tty/tty_port.c
51951@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51952 unsigned long flags;
51953
51954 spin_lock_irqsave(&port->lock, flags);
51955- port->count = 0;
51956+ atomic_set(&port->count, 0);
51957 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51958 tty = port->tty;
51959 if (tty)
51960@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51961 /* The port lock protects the port counts */
51962 spin_lock_irqsave(&port->lock, flags);
51963 if (!tty_hung_up_p(filp))
51964- port->count--;
51965+ atomic_dec(&port->count);
51966 port->blocked_open++;
51967 spin_unlock_irqrestore(&port->lock, flags);
51968
51969@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51970 we must not mess that up further */
51971 spin_lock_irqsave(&port->lock, flags);
51972 if (!tty_hung_up_p(filp))
51973- port->count++;
51974+ atomic_inc(&port->count);
51975 port->blocked_open--;
51976 if (retval == 0)
51977 port->flags |= ASYNC_NORMAL_ACTIVE;
51978@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51979 return 0;
51980 }
51981
51982- if (tty->count == 1 && port->count != 1) {
51983+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51984 printk(KERN_WARNING
51985 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51986- port->count);
51987- port->count = 1;
51988+ atomic_read(&port->count));
51989+ atomic_set(&port->count, 1);
51990 }
51991- if (--port->count < 0) {
51992+ if (atomic_dec_return(&port->count) < 0) {
51993 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51994- port->count);
51995- port->count = 0;
51996+ atomic_read(&port->count));
51997+ atomic_set(&port->count, 0);
51998 }
51999
52000- if (port->count) {
52001+ if (atomic_read(&port->count)) {
52002 spin_unlock_irqrestore(&port->lock, flags);
52003 return 0;
52004 }
52005@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
52006 {
52007 spin_lock_irq(&port->lock);
52008 if (!tty_hung_up_p(filp))
52009- ++port->count;
52010+ atomic_inc(&port->count);
52011 spin_unlock_irq(&port->lock);
52012 tty_port_tty_set(port, tty);
52013
52014diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
52015index d0e3a44..5f8b754 100644
52016--- a/drivers/tty/vt/keyboard.c
52017+++ b/drivers/tty/vt/keyboard.c
52018@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
52019 kbd->kbdmode == VC_OFF) &&
52020 value != KVAL(K_SAK))
52021 return; /* SAK is allowed even in raw mode */
52022+
52023+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52024+ {
52025+ void *func = fn_handler[value];
52026+ if (func == fn_show_state || func == fn_show_ptregs ||
52027+ func == fn_show_mem)
52028+ return;
52029+ }
52030+#endif
52031+
52032 fn_handler[value](vc);
52033 }
52034
52035@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52036 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52037 return -EFAULT;
52038
52039- if (!capable(CAP_SYS_TTY_CONFIG))
52040- perm = 0;
52041-
52042 switch (cmd) {
52043 case KDGKBENT:
52044 /* Ensure another thread doesn't free it under us */
52045@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52046 spin_unlock_irqrestore(&kbd_event_lock, flags);
52047 return put_user(val, &user_kbe->kb_value);
52048 case KDSKBENT:
52049+ if (!capable(CAP_SYS_TTY_CONFIG))
52050+ perm = 0;
52051+
52052 if (!perm)
52053 return -EPERM;
52054 if (!i && v == K_NOSUCHMAP) {
52055@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52056 int i, j, k;
52057 int ret;
52058
52059- if (!capable(CAP_SYS_TTY_CONFIG))
52060- perm = 0;
52061-
52062 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52063 if (!kbs) {
52064 ret = -ENOMEM;
52065@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52066 kfree(kbs);
52067 return ((p && *p) ? -EOVERFLOW : 0);
52068 case KDSKBSENT:
52069+ if (!capable(CAP_SYS_TTY_CONFIG))
52070+ perm = 0;
52071+
52072 if (!perm) {
52073 ret = -EPERM;
52074 goto reterr;
52075diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52076index a673e5b..36e5d32 100644
52077--- a/drivers/uio/uio.c
52078+++ b/drivers/uio/uio.c
52079@@ -25,6 +25,7 @@
52080 #include <linux/kobject.h>
52081 #include <linux/cdev.h>
52082 #include <linux/uio_driver.h>
52083+#include <asm/local.h>
52084
52085 #define UIO_MAX_DEVICES (1U << MINORBITS)
52086
52087@@ -32,7 +33,7 @@ struct uio_device {
52088 struct module *owner;
52089 struct device *dev;
52090 int minor;
52091- atomic_t event;
52092+ atomic_unchecked_t event;
52093 struct fasync_struct *async_queue;
52094 wait_queue_head_t wait;
52095 struct uio_info *info;
52096@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52097 struct device_attribute *attr, char *buf)
52098 {
52099 struct uio_device *idev = dev_get_drvdata(dev);
52100- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52101+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52102 }
52103 static DEVICE_ATTR_RO(event);
52104
52105@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52106 {
52107 struct uio_device *idev = info->uio_dev;
52108
52109- atomic_inc(&idev->event);
52110+ atomic_inc_unchecked(&idev->event);
52111 wake_up_interruptible(&idev->wait);
52112 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52113 }
52114@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52115 }
52116
52117 listener->dev = idev;
52118- listener->event_count = atomic_read(&idev->event);
52119+ listener->event_count = atomic_read_unchecked(&idev->event);
52120 filep->private_data = listener;
52121
52122 if (idev->info->open) {
52123@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52124 return -EIO;
52125
52126 poll_wait(filep, &idev->wait, wait);
52127- if (listener->event_count != atomic_read(&idev->event))
52128+ if (listener->event_count != atomic_read_unchecked(&idev->event))
52129 return POLLIN | POLLRDNORM;
52130 return 0;
52131 }
52132@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52133 do {
52134 set_current_state(TASK_INTERRUPTIBLE);
52135
52136- event_count = atomic_read(&idev->event);
52137+ event_count = atomic_read_unchecked(&idev->event);
52138 if (event_count != listener->event_count) {
52139 if (copy_to_user(buf, &event_count, count))
52140 retval = -EFAULT;
52141@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52142 static int uio_find_mem_index(struct vm_area_struct *vma)
52143 {
52144 struct uio_device *idev = vma->vm_private_data;
52145+ unsigned long size;
52146
52147 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52148- if (idev->info->mem[vma->vm_pgoff].size == 0)
52149+ size = idev->info->mem[vma->vm_pgoff].size;
52150+ if (size == 0)
52151+ return -1;
52152+ if (vma->vm_end - vma->vm_start > size)
52153 return -1;
52154 return (int)vma->vm_pgoff;
52155 }
52156@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52157 idev->owner = owner;
52158 idev->info = info;
52159 init_waitqueue_head(&idev->wait);
52160- atomic_set(&idev->event, 0);
52161+ atomic_set_unchecked(&idev->event, 0);
52162
52163 ret = uio_get_minor(idev);
52164 if (ret)
52165diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52166index 813d4d3..a71934f 100644
52167--- a/drivers/usb/atm/cxacru.c
52168+++ b/drivers/usb/atm/cxacru.c
52169@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52170 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52171 if (ret < 2)
52172 return -EINVAL;
52173- if (index < 0 || index > 0x7f)
52174+ if (index > 0x7f)
52175 return -EINVAL;
52176 pos += tmp;
52177
52178diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52179index dada014..1d0d517 100644
52180--- a/drivers/usb/atm/usbatm.c
52181+++ b/drivers/usb/atm/usbatm.c
52182@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52183 if (printk_ratelimit())
52184 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52185 __func__, vpi, vci);
52186- atomic_inc(&vcc->stats->rx_err);
52187+ atomic_inc_unchecked(&vcc->stats->rx_err);
52188 return;
52189 }
52190
52191@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52192 if (length > ATM_MAX_AAL5_PDU) {
52193 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52194 __func__, length, vcc);
52195- atomic_inc(&vcc->stats->rx_err);
52196+ atomic_inc_unchecked(&vcc->stats->rx_err);
52197 goto out;
52198 }
52199
52200@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52201 if (sarb->len < pdu_length) {
52202 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52203 __func__, pdu_length, sarb->len, vcc);
52204- atomic_inc(&vcc->stats->rx_err);
52205+ atomic_inc_unchecked(&vcc->stats->rx_err);
52206 goto out;
52207 }
52208
52209 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52210 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52211 __func__, vcc);
52212- atomic_inc(&vcc->stats->rx_err);
52213+ atomic_inc_unchecked(&vcc->stats->rx_err);
52214 goto out;
52215 }
52216
52217@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52218 if (printk_ratelimit())
52219 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52220 __func__, length);
52221- atomic_inc(&vcc->stats->rx_drop);
52222+ atomic_inc_unchecked(&vcc->stats->rx_drop);
52223 goto out;
52224 }
52225
52226@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52227
52228 vcc->push(vcc, skb);
52229
52230- atomic_inc(&vcc->stats->rx);
52231+ atomic_inc_unchecked(&vcc->stats->rx);
52232 out:
52233 skb_trim(sarb, 0);
52234 }
52235@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52236 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52237
52238 usbatm_pop(vcc, skb);
52239- atomic_inc(&vcc->stats->tx);
52240+ atomic_inc_unchecked(&vcc->stats->tx);
52241
52242 skb = skb_dequeue(&instance->sndqueue);
52243 }
52244@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52245 if (!left--)
52246 return sprintf(page,
52247 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52248- atomic_read(&atm_dev->stats.aal5.tx),
52249- atomic_read(&atm_dev->stats.aal5.tx_err),
52250- atomic_read(&atm_dev->stats.aal5.rx),
52251- atomic_read(&atm_dev->stats.aal5.rx_err),
52252- atomic_read(&atm_dev->stats.aal5.rx_drop));
52253+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52254+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52255+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52256+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52257+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52258
52259 if (!left--) {
52260 if (instance->disconnected)
52261diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52262index 2a3bbdf..91d72cf 100644
52263--- a/drivers/usb/core/devices.c
52264+++ b/drivers/usb/core/devices.c
52265@@ -126,7 +126,7 @@ static const char format_endpt[] =
52266 * time it gets called.
52267 */
52268 static struct device_connect_event {
52269- atomic_t count;
52270+ atomic_unchecked_t count;
52271 wait_queue_head_t wait;
52272 } device_event = {
52273 .count = ATOMIC_INIT(1),
52274@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52275
52276 void usbfs_conn_disc_event(void)
52277 {
52278- atomic_add(2, &device_event.count);
52279+ atomic_add_unchecked(2, &device_event.count);
52280 wake_up(&device_event.wait);
52281 }
52282
52283@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52284
52285 poll_wait(file, &device_event.wait, wait);
52286
52287- event_count = atomic_read(&device_event.count);
52288+ event_count = atomic_read_unchecked(&device_event.count);
52289 if (file->f_version != event_count) {
52290 file->f_version = event_count;
52291 return POLLIN | POLLRDNORM;
52292diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52293index 257876e..4304364 100644
52294--- a/drivers/usb/core/devio.c
52295+++ b/drivers/usb/core/devio.c
52296@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52297 struct usb_dev_state *ps = file->private_data;
52298 struct usb_device *dev = ps->dev;
52299 ssize_t ret = 0;
52300- unsigned len;
52301+ size_t len;
52302 loff_t pos;
52303 int i;
52304
52305@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52306 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52307 struct usb_config_descriptor *config =
52308 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52309- unsigned int length = le16_to_cpu(config->wTotalLength);
52310+ size_t length = le16_to_cpu(config->wTotalLength);
52311
52312 if (*ppos < pos + length) {
52313
52314 /* The descriptor may claim to be longer than it
52315 * really is. Here is the actual allocated length. */
52316- unsigned alloclen =
52317+ size_t alloclen =
52318 le16_to_cpu(dev->config[i].desc.wTotalLength);
52319
52320- len = length - (*ppos - pos);
52321+ len = length + pos - *ppos;
52322 if (len > nbytes)
52323 len = nbytes;
52324
52325 /* Simply don't write (skip over) unallocated parts */
52326 if (alloclen > (*ppos - pos)) {
52327- alloclen -= (*ppos - pos);
52328+ alloclen = alloclen + pos - *ppos;
52329 if (copy_to_user(buf,
52330 dev->rawdescriptors[i] + (*ppos - pos),
52331 min(len, alloclen))) {
52332diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52333index 9c4e292..b89877f 100644
52334--- a/drivers/usb/core/hcd.c
52335+++ b/drivers/usb/core/hcd.c
52336@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52337 */
52338 usb_get_urb(urb);
52339 atomic_inc(&urb->use_count);
52340- atomic_inc(&urb->dev->urbnum);
52341+ atomic_inc_unchecked(&urb->dev->urbnum);
52342 usbmon_urb_submit(&hcd->self, urb);
52343
52344 /* NOTE requirements on root-hub callers (usbfs and the hub
52345@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52346 urb->hcpriv = NULL;
52347 INIT_LIST_HEAD(&urb->urb_list);
52348 atomic_dec(&urb->use_count);
52349- atomic_dec(&urb->dev->urbnum);
52350+ atomic_dec_unchecked(&urb->dev->urbnum);
52351 if (atomic_read(&urb->reject))
52352 wake_up(&usb_kill_urb_queue);
52353 usb_put_urb(urb);
52354diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52355index 00c4b96..b4498c8 100644
52356--- a/drivers/usb/core/hub.c
52357+++ b/drivers/usb/core/hub.c
52358@@ -27,6 +27,7 @@
52359 #include <linux/freezer.h>
52360 #include <linux/random.h>
52361 #include <linux/pm_qos.h>
52362+#include <linux/grsecurity.h>
52363
52364 #include <asm/uaccess.h>
52365 #include <asm/byteorder.h>
52366@@ -4531,6 +4532,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52367 goto done;
52368 return;
52369 }
52370+
52371+ if (gr_handle_new_usb())
52372+ goto done;
52373+
52374 if (hub_is_superspeed(hub->hdev))
52375 unit_load = 150;
52376 else
52377diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52378index 0c8a7fc..c45b40a 100644
52379--- a/drivers/usb/core/message.c
52380+++ b/drivers/usb/core/message.c
52381@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52382 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52383 * error number.
52384 */
52385-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52386+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52387 __u8 requesttype, __u16 value, __u16 index, void *data,
52388 __u16 size, int timeout)
52389 {
52390@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52391 * If successful, 0. Otherwise a negative error number. The number of actual
52392 * bytes transferred will be stored in the @actual_length parameter.
52393 */
52394-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52395+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52396 void *data, int len, int *actual_length, int timeout)
52397 {
52398 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52399@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52400 * bytes transferred will be stored in the @actual_length parameter.
52401 *
52402 */
52403-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52404+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52405 void *data, int len, int *actual_length, int timeout)
52406 {
52407 struct urb *urb;
52408diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52409index 1236c60..d47a51c 100644
52410--- a/drivers/usb/core/sysfs.c
52411+++ b/drivers/usb/core/sysfs.c
52412@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52413 struct usb_device *udev;
52414
52415 udev = to_usb_device(dev);
52416- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52417+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52418 }
52419 static DEVICE_ATTR_RO(urbnum);
52420
52421diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52422index 4d11449..f4ccabf 100644
52423--- a/drivers/usb/core/usb.c
52424+++ b/drivers/usb/core/usb.c
52425@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52426 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52427 dev->state = USB_STATE_ATTACHED;
52428 dev->lpm_disable_count = 1;
52429- atomic_set(&dev->urbnum, 0);
52430+ atomic_set_unchecked(&dev->urbnum, 0);
52431
52432 INIT_LIST_HEAD(&dev->ep0.urb_list);
52433 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52434diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52435index 85f398d..d375bbe 100644
52436--- a/drivers/usb/dwc3/gadget.c
52437+++ b/drivers/usb/dwc3/gadget.c
52438@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52439 if (!usb_endpoint_xfer_isoc(desc))
52440 return 0;
52441
52442- memset(&trb_link, 0, sizeof(trb_link));
52443-
52444 /* Link TRB for ISOC. The HWO bit is never reset */
52445 trb_st_hw = &dep->trb_pool[0];
52446
52447diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52448index 8cfc319..4868255 100644
52449--- a/drivers/usb/early/ehci-dbgp.c
52450+++ b/drivers/usb/early/ehci-dbgp.c
52451@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52452
52453 #ifdef CONFIG_KGDB
52454 static struct kgdb_io kgdbdbgp_io_ops;
52455-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52456+static struct kgdb_io kgdbdbgp_io_ops_console;
52457+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52458 #else
52459 #define dbgp_kgdb_mode (0)
52460 #endif
52461@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52462 .write_char = kgdbdbgp_write_char,
52463 };
52464
52465+static struct kgdb_io kgdbdbgp_io_ops_console = {
52466+ .name = "kgdbdbgp",
52467+ .read_char = kgdbdbgp_read_char,
52468+ .write_char = kgdbdbgp_write_char,
52469+ .is_console = 1
52470+};
52471+
52472 static int kgdbdbgp_wait_time;
52473
52474 static int __init kgdbdbgp_parse_config(char *str)
52475@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52476 ptr++;
52477 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52478 }
52479- kgdb_register_io_module(&kgdbdbgp_io_ops);
52480- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52481+ if (early_dbgp_console.index != -1)
52482+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52483+ else
52484+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52485
52486 return 0;
52487 }
52488diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52489index 2b4c82d..06a8ee6 100644
52490--- a/drivers/usb/gadget/f_uac1.c
52491+++ b/drivers/usb/gadget/f_uac1.c
52492@@ -13,6 +13,7 @@
52493 #include <linux/kernel.h>
52494 #include <linux/device.h>
52495 #include <linux/atomic.h>
52496+#include <linux/module.h>
52497
52498 #include "u_uac1.h"
52499
52500diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52501index ad0aca8..8ff84865 100644
52502--- a/drivers/usb/gadget/u_serial.c
52503+++ b/drivers/usb/gadget/u_serial.c
52504@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52505 spin_lock_irq(&port->port_lock);
52506
52507 /* already open? Great. */
52508- if (port->port.count) {
52509+ if (atomic_read(&port->port.count)) {
52510 status = 0;
52511- port->port.count++;
52512+ atomic_inc(&port->port.count);
52513
52514 /* currently opening/closing? wait ... */
52515 } else if (port->openclose) {
52516@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52517 tty->driver_data = port;
52518 port->port.tty = tty;
52519
52520- port->port.count = 1;
52521+ atomic_set(&port->port.count, 1);
52522 port->openclose = false;
52523
52524 /* if connected, start the I/O stream */
52525@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52526
52527 spin_lock_irq(&port->port_lock);
52528
52529- if (port->port.count != 1) {
52530- if (port->port.count == 0)
52531+ if (atomic_read(&port->port.count) != 1) {
52532+ if (atomic_read(&port->port.count) == 0)
52533 WARN_ON(1);
52534 else
52535- --port->port.count;
52536+ atomic_dec(&port->port.count);
52537 goto exit;
52538 }
52539
52540@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52541 * and sleep if necessary
52542 */
52543 port->openclose = true;
52544- port->port.count = 0;
52545+ atomic_set(&port->port.count, 0);
52546
52547 gser = port->port_usb;
52548 if (gser && gser->disconnect)
52549@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52550 int cond;
52551
52552 spin_lock_irq(&port->port_lock);
52553- cond = (port->port.count == 0) && !port->openclose;
52554+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52555 spin_unlock_irq(&port->port_lock);
52556 return cond;
52557 }
52558@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52559 /* if it's already open, start I/O ... and notify the serial
52560 * protocol about open/close status (connect/disconnect).
52561 */
52562- if (port->port.count) {
52563+ if (atomic_read(&port->port.count)) {
52564 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52565 gs_start_io(port);
52566 if (gser->connect)
52567@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52568
52569 port->port_usb = NULL;
52570 gser->ioport = NULL;
52571- if (port->port.count > 0 || port->openclose) {
52572+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52573 wake_up_interruptible(&port->drain_wait);
52574 if (port->port.tty)
52575 tty_hangup(port->port.tty);
52576@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52577
52578 /* finally, free any unused/unusable I/O buffers */
52579 spin_lock_irqsave(&port->port_lock, flags);
52580- if (port->port.count == 0 && !port->openclose)
52581+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52582 gs_buf_free(&port->port_write_buf);
52583 gs_free_requests(gser->out, &port->read_pool, NULL);
52584 gs_free_requests(gser->out, &port->read_queue, NULL);
52585diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52586index 7a55fea..cc0ed4f 100644
52587--- a/drivers/usb/gadget/u_uac1.c
52588+++ b/drivers/usb/gadget/u_uac1.c
52589@@ -16,6 +16,7 @@
52590 #include <linux/ctype.h>
52591 #include <linux/random.h>
52592 #include <linux/syscalls.h>
52593+#include <linux/module.h>
52594
52595 #include "u_uac1.h"
52596
52597diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52598index 7ae0c4d..35521b7 100644
52599--- a/drivers/usb/host/ehci-hub.c
52600+++ b/drivers/usb/host/ehci-hub.c
52601@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52602 urb->transfer_flags = URB_DIR_IN;
52603 usb_get_urb(urb);
52604 atomic_inc(&urb->use_count);
52605- atomic_inc(&urb->dev->urbnum);
52606+ atomic_inc_unchecked(&urb->dev->urbnum);
52607 urb->setup_dma = dma_map_single(
52608 hcd->self.controller,
52609 urb->setup_packet,
52610@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52611 urb->status = -EINPROGRESS;
52612 usb_get_urb(urb);
52613 atomic_inc(&urb->use_count);
52614- atomic_inc(&urb->dev->urbnum);
52615+ atomic_inc_unchecked(&urb->dev->urbnum);
52616 retval = submit_single_step_set_feature(hcd, urb, 0);
52617 if (!retval && !wait_for_completion_timeout(&done,
52618 msecs_to_jiffies(2000))) {
52619diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
52620index d0d8fad..668ef7b 100644
52621--- a/drivers/usb/host/hwa-hc.c
52622+++ b/drivers/usb/host/hwa-hc.c
52623@@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52624 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
52625 struct wahc *wa = &hwahc->wa;
52626 struct device *dev = &wa->usb_iface->dev;
52627- u8 mas_le[UWB_NUM_MAS/8];
52628+ u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
52629+
52630+ if (mas_le == NULL)
52631+ return -ENOMEM;
52632
52633 /* Set the stream index */
52634 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
52635@@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52636 WUSB_REQ_SET_WUSB_MAS,
52637 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
52638 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
52639- mas_le, 32, USB_CTRL_SET_TIMEOUT);
52640+ mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
52641 if (result < 0)
52642 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
52643 out:
52644+ kfree(mas_le);
52645+
52646 return result;
52647 }
52648
52649diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52650index ba6a5d6..f88f7f3 100644
52651--- a/drivers/usb/misc/appledisplay.c
52652+++ b/drivers/usb/misc/appledisplay.c
52653@@ -83,7 +83,7 @@ struct appledisplay {
52654 spinlock_t lock;
52655 };
52656
52657-static atomic_t count_displays = ATOMIC_INIT(0);
52658+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52659 static struct workqueue_struct *wq;
52660
52661 static void appledisplay_complete(struct urb *urb)
52662@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52663
52664 /* Register backlight device */
52665 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52666- atomic_inc_return(&count_displays) - 1);
52667+ atomic_inc_return_unchecked(&count_displays) - 1);
52668 memset(&props, 0, sizeof(struct backlight_properties));
52669 props.type = BACKLIGHT_RAW;
52670 props.max_brightness = 0xff;
52671diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52672index 8d7fc48..01c4986 100644
52673--- a/drivers/usb/serial/console.c
52674+++ b/drivers/usb/serial/console.c
52675@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52676
52677 info->port = port;
52678
52679- ++port->port.count;
52680+ atomic_inc(&port->port.count);
52681 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52682 if (serial->type->set_termios) {
52683 /*
52684@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52685 }
52686 /* Now that any required fake tty operations are completed restore
52687 * the tty port count */
52688- --port->port.count;
52689+ atomic_dec(&port->port.count);
52690 /* The console is special in terms of closing the device so
52691 * indicate this port is now acting as a system console. */
52692 port->port.console = 1;
52693@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52694 free_tty:
52695 kfree(tty);
52696 reset_open_count:
52697- port->port.count = 0;
52698+ atomic_set(&port->port.count, 0);
52699 usb_autopm_put_interface(serial->interface);
52700 error_get_interface:
52701 usb_serial_put(serial);
52702@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52703 static void usb_console_write(struct console *co,
52704 const char *buf, unsigned count)
52705 {
52706- static struct usbcons_info *info = &usbcons_info;
52707+ struct usbcons_info *info = &usbcons_info;
52708 struct usb_serial_port *port = info->port;
52709 struct usb_serial *serial;
52710 int retval = -ENODEV;
52711diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52712index 307e339..6aa97cb 100644
52713--- a/drivers/usb/storage/usb.h
52714+++ b/drivers/usb/storage/usb.h
52715@@ -63,7 +63,7 @@ struct us_unusual_dev {
52716 __u8 useProtocol;
52717 __u8 useTransport;
52718 int (*initFunction)(struct us_data *);
52719-};
52720+} __do_const;
52721
52722
52723 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52724diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52725index f2a8d29..7bc3fe7 100644
52726--- a/drivers/usb/wusbcore/wa-hc.h
52727+++ b/drivers/usb/wusbcore/wa-hc.h
52728@@ -240,7 +240,7 @@ struct wahc {
52729 spinlock_t xfer_list_lock;
52730 struct work_struct xfer_enqueue_work;
52731 struct work_struct xfer_error_work;
52732- atomic_t xfer_id_count;
52733+ atomic_unchecked_t xfer_id_count;
52734
52735 kernel_ulong_t quirks;
52736 };
52737@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52738 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52739 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52740 wa->dto_in_use = 0;
52741- atomic_set(&wa->xfer_id_count, 1);
52742+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52743 /* init the buf in URBs */
52744 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52745 usb_init_urb(&(wa->buf_in_urbs[index]));
52746diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52747index 3e2e4ed..060c9b8 100644
52748--- a/drivers/usb/wusbcore/wa-xfer.c
52749+++ b/drivers/usb/wusbcore/wa-xfer.c
52750@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52751 */
52752 static void wa_xfer_id_init(struct wa_xfer *xfer)
52753 {
52754- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52755+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52756 }
52757
52758 /* Return the xfer's ID. */
52759diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52760index 512f479..7e041d0 100644
52761--- a/drivers/vfio/vfio.c
52762+++ b/drivers/vfio/vfio.c
52763@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52764 return 0;
52765
52766 /* TODO Prevent device auto probing */
52767- WARN("Device %s added to live group %d!\n", dev_name(dev),
52768+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52769 iommu_group_id(group->iommu_group));
52770
52771 return 0;
52772diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52773index 5174eba..451e6bc 100644
52774--- a/drivers/vhost/vringh.c
52775+++ b/drivers/vhost/vringh.c
52776@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52777 /* Userspace access helpers: in this case, addresses are really userspace. */
52778 static inline int getu16_user(u16 *val, const u16 *p)
52779 {
52780- return get_user(*val, (__force u16 __user *)p);
52781+ return get_user(*val, (u16 __force_user *)p);
52782 }
52783
52784 static inline int putu16_user(u16 *p, u16 val)
52785 {
52786- return put_user(val, (__force u16 __user *)p);
52787+ return put_user(val, (u16 __force_user *)p);
52788 }
52789
52790 static inline int copydesc_user(void *dst, const void *src, size_t len)
52791 {
52792- return copy_from_user(dst, (__force void __user *)src, len) ?
52793+ return copy_from_user(dst, (void __force_user *)src, len) ?
52794 -EFAULT : 0;
52795 }
52796
52797@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52798 const struct vring_used_elem *src,
52799 unsigned int num)
52800 {
52801- return copy_to_user((__force void __user *)dst, src,
52802+ return copy_to_user((void __force_user *)dst, src,
52803 sizeof(*dst) * num) ? -EFAULT : 0;
52804 }
52805
52806 static inline int xfer_from_user(void *src, void *dst, size_t len)
52807 {
52808- return copy_from_user(dst, (__force void __user *)src, len) ?
52809+ return copy_from_user(dst, (void __force_user *)src, len) ?
52810 -EFAULT : 0;
52811 }
52812
52813 static inline int xfer_to_user(void *dst, void *src, size_t len)
52814 {
52815- return copy_to_user((__force void __user *)dst, src, len) ?
52816+ return copy_to_user((void __force_user *)dst, src, len) ?
52817 -EFAULT : 0;
52818 }
52819
52820@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52821 vrh->last_used_idx = 0;
52822 vrh->vring.num = num;
52823 /* vring expects kernel addresses, but only used via accessors. */
52824- vrh->vring.desc = (__force struct vring_desc *)desc;
52825- vrh->vring.avail = (__force struct vring_avail *)avail;
52826- vrh->vring.used = (__force struct vring_used *)used;
52827+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52828+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52829+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52830 return 0;
52831 }
52832 EXPORT_SYMBOL(vringh_init_user);
52833@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52834
52835 static inline int putu16_kern(u16 *p, u16 val)
52836 {
52837- ACCESS_ONCE(*p) = val;
52838+ ACCESS_ONCE_RW(*p) = val;
52839 return 0;
52840 }
52841
52842diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52843index 84a110a..96312c3 100644
52844--- a/drivers/video/backlight/kb3886_bl.c
52845+++ b/drivers/video/backlight/kb3886_bl.c
52846@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52847 static unsigned long kb3886bl_flags;
52848 #define KB3886BL_SUSPENDED 0x01
52849
52850-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52851+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52852 {
52853 .ident = "Sahara Touch-iT",
52854 .matches = {
52855diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52856index 1b0b233..6f34c2c 100644
52857--- a/drivers/video/fbdev/arcfb.c
52858+++ b/drivers/video/fbdev/arcfb.c
52859@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52860 return -ENOSPC;
52861
52862 err = 0;
52863- if ((count + p) > fbmemlength) {
52864+ if (count > (fbmemlength - p)) {
52865 count = fbmemlength - p;
52866 err = -ENOSPC;
52867 }
52868diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52869index 52108be..c7c110d 100644
52870--- a/drivers/video/fbdev/aty/aty128fb.c
52871+++ b/drivers/video/fbdev/aty/aty128fb.c
52872@@ -149,7 +149,7 @@ enum {
52873 };
52874
52875 /* Must match above enum */
52876-static char * const r128_family[] = {
52877+static const char * const r128_family[] = {
52878 "AGP",
52879 "PCI",
52880 "PRO AGP",
52881diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52882index c3d0074..0b9077e 100644
52883--- a/drivers/video/fbdev/aty/atyfb_base.c
52884+++ b/drivers/video/fbdev/aty/atyfb_base.c
52885@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52886 par->accel_flags = var->accel_flags; /* hack */
52887
52888 if (var->accel_flags) {
52889- info->fbops->fb_sync = atyfb_sync;
52890+ pax_open_kernel();
52891+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52892+ pax_close_kernel();
52893 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52894 } else {
52895- info->fbops->fb_sync = NULL;
52896+ pax_open_kernel();
52897+ *(void **)&info->fbops->fb_sync = NULL;
52898+ pax_close_kernel();
52899 info->flags |= FBINFO_HWACCEL_DISABLED;
52900 }
52901
52902diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52903index 2fa0317..4983f2a 100644
52904--- a/drivers/video/fbdev/aty/mach64_cursor.c
52905+++ b/drivers/video/fbdev/aty/mach64_cursor.c
52906@@ -8,6 +8,7 @@
52907 #include "../core/fb_draw.h"
52908
52909 #include <asm/io.h>
52910+#include <asm/pgtable.h>
52911
52912 #ifdef __sparc__
52913 #include <asm/fbio.h>
52914@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52915 info->sprite.buf_align = 16; /* and 64 lines tall. */
52916 info->sprite.flags = FB_PIXMAP_IO;
52917
52918- info->fbops->fb_cursor = atyfb_cursor;
52919+ pax_open_kernel();
52920+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52921+ pax_close_kernel();
52922
52923 return 0;
52924 }
52925diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
52926index 900aa4e..6d49418 100644
52927--- a/drivers/video/fbdev/core/fb_defio.c
52928+++ b/drivers/video/fbdev/core/fb_defio.c
52929@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52930
52931 BUG_ON(!fbdefio);
52932 mutex_init(&fbdefio->lock);
52933- info->fbops->fb_mmap = fb_deferred_io_mmap;
52934+ pax_open_kernel();
52935+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52936+ pax_close_kernel();
52937 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52938 INIT_LIST_HEAD(&fbdefio->pagelist);
52939 if (fbdefio->delay == 0) /* set a default of 1 s */
52940@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52941 page->mapping = NULL;
52942 }
52943
52944- info->fbops->fb_mmap = NULL;
52945+ *(void **)&info->fbops->fb_mmap = NULL;
52946 mutex_destroy(&fbdefio->lock);
52947 }
52948 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52949diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
52950index b6d5008..5bca7bf 100644
52951--- a/drivers/video/fbdev/core/fbmem.c
52952+++ b/drivers/video/fbdev/core/fbmem.c
52953@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52954 image->dx += image->width + 8;
52955 }
52956 } else if (rotate == FB_ROTATE_UD) {
52957- for (x = 0; x < num && image->dx >= 0; x++) {
52958+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52959 info->fbops->fb_imageblit(info, image);
52960 image->dx -= image->width + 8;
52961 }
52962@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52963 image->dy += image->height + 8;
52964 }
52965 } else if (rotate == FB_ROTATE_CCW) {
52966- for (x = 0; x < num && image->dy >= 0; x++) {
52967+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52968 info->fbops->fb_imageblit(info, image);
52969 image->dy -= image->height + 8;
52970 }
52971@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52972 return -EFAULT;
52973 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52974 return -EINVAL;
52975- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52976+ if (con2fb.framebuffer >= FB_MAX)
52977 return -EINVAL;
52978 if (!registered_fb[con2fb.framebuffer])
52979 request_module("fb%d", con2fb.framebuffer);
52980@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52981 __u32 data;
52982 int err;
52983
52984- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52985+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52986
52987 data = (__u32) (unsigned long) fix->smem_start;
52988 err |= put_user(data, &fix32->smem_start);
52989diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
52990index e23392e..8a77540 100644
52991--- a/drivers/video/fbdev/hyperv_fb.c
52992+++ b/drivers/video/fbdev/hyperv_fb.c
52993@@ -235,7 +235,7 @@ static uint screen_fb_size;
52994 static inline int synthvid_send(struct hv_device *hdev,
52995 struct synthvid_msg *msg)
52996 {
52997- static atomic64_t request_id = ATOMIC64_INIT(0);
52998+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52999 int ret;
53000
53001 msg->pipe_hdr.type = PIPE_MSG_DATA;
53002@@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
53003
53004 ret = vmbus_sendpacket(hdev->channel, msg,
53005 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
53006- atomic64_inc_return(&request_id),
53007+ atomic64_inc_return_unchecked(&request_id),
53008 VM_PKT_DATA_INBAND, 0);
53009
53010 if (ret)
53011diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
53012index 7672d2e..b56437f 100644
53013--- a/drivers/video/fbdev/i810/i810_accel.c
53014+++ b/drivers/video/fbdev/i810/i810_accel.c
53015@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
53016 }
53017 }
53018 printk("ringbuffer lockup!!!\n");
53019+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
53020 i810_report_error(mmio);
53021 par->dev_flags |= LOCKUP;
53022 info->pixmap.scan_align = 1;
53023diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53024index a01147f..5d896f8 100644
53025--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53026+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53027@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
53028
53029 #ifdef CONFIG_FB_MATROX_MYSTIQUE
53030 struct matrox_switch matrox_mystique = {
53031- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
53032+ .preinit = MGA1064_preinit,
53033+ .reset = MGA1064_reset,
53034+ .init = MGA1064_init,
53035+ .restore = MGA1064_restore,
53036 };
53037 EXPORT_SYMBOL(matrox_mystique);
53038 #endif
53039
53040 #ifdef CONFIG_FB_MATROX_G
53041 struct matrox_switch matrox_G100 = {
53042- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
53043+ .preinit = MGAG100_preinit,
53044+ .reset = MGAG100_reset,
53045+ .init = MGAG100_init,
53046+ .restore = MGAG100_restore,
53047 };
53048 EXPORT_SYMBOL(matrox_G100);
53049 #endif
53050diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53051index 195ad7c..09743fc 100644
53052--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53053+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53054@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
53055 }
53056
53057 struct matrox_switch matrox_millennium = {
53058- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
53059+ .preinit = Ti3026_preinit,
53060+ .reset = Ti3026_reset,
53061+ .init = Ti3026_init,
53062+ .restore = Ti3026_restore
53063 };
53064 EXPORT_SYMBOL(matrox_millennium);
53065 #endif
53066diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53067index fe92eed..106e085 100644
53068--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53069+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53070@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
53071 struct mb862xxfb_par *par = info->par;
53072
53073 if (info->var.bits_per_pixel == 32) {
53074- info->fbops->fb_fillrect = cfb_fillrect;
53075- info->fbops->fb_copyarea = cfb_copyarea;
53076- info->fbops->fb_imageblit = cfb_imageblit;
53077+ pax_open_kernel();
53078+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53079+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53080+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53081+ pax_close_kernel();
53082 } else {
53083 outreg(disp, GC_L0EM, 3);
53084- info->fbops->fb_fillrect = mb86290fb_fillrect;
53085- info->fbops->fb_copyarea = mb86290fb_copyarea;
53086- info->fbops->fb_imageblit = mb86290fb_imageblit;
53087+ pax_open_kernel();
53088+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
53089+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
53090+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
53091+ pax_close_kernel();
53092 }
53093 outreg(draw, GDC_REG_DRAW_BASE, 0);
53094 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
53095diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
53096index def0412..fed6529 100644
53097--- a/drivers/video/fbdev/nvidia/nvidia.c
53098+++ b/drivers/video/fbdev/nvidia/nvidia.c
53099@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
53100 info->fix.line_length = (info->var.xres_virtual *
53101 info->var.bits_per_pixel) >> 3;
53102 if (info->var.accel_flags) {
53103- info->fbops->fb_imageblit = nvidiafb_imageblit;
53104- info->fbops->fb_fillrect = nvidiafb_fillrect;
53105- info->fbops->fb_copyarea = nvidiafb_copyarea;
53106- info->fbops->fb_sync = nvidiafb_sync;
53107+ pax_open_kernel();
53108+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
53109+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
53110+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
53111+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
53112+ pax_close_kernel();
53113 info->pixmap.scan_align = 4;
53114 info->flags &= ~FBINFO_HWACCEL_DISABLED;
53115 info->flags |= FBINFO_READS_FAST;
53116 NVResetGraphics(info);
53117 } else {
53118- info->fbops->fb_imageblit = cfb_imageblit;
53119- info->fbops->fb_fillrect = cfb_fillrect;
53120- info->fbops->fb_copyarea = cfb_copyarea;
53121- info->fbops->fb_sync = NULL;
53122+ pax_open_kernel();
53123+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53124+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53125+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53126+ *(void **)&info->fbops->fb_sync = NULL;
53127+ pax_close_kernel();
53128 info->pixmap.scan_align = 1;
53129 info->flags |= FBINFO_HWACCEL_DISABLED;
53130 info->flags &= ~FBINFO_READS_FAST;
53131@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
53132 info->pixmap.size = 8 * 1024;
53133 info->pixmap.flags = FB_PIXMAP_SYSTEM;
53134
53135- if (!hwcur)
53136- info->fbops->fb_cursor = NULL;
53137+ if (!hwcur) {
53138+ pax_open_kernel();
53139+ *(void **)&info->fbops->fb_cursor = NULL;
53140+ pax_close_kernel();
53141+ }
53142
53143 info->var.accel_flags = (!noaccel);
53144
53145diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
53146index 2412a0d..294215b 100644
53147--- a/drivers/video/fbdev/omap2/dss/display.c
53148+++ b/drivers/video/fbdev/omap2/dss/display.c
53149@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
53150 if (dssdev->name == NULL)
53151 dssdev->name = dssdev->alias;
53152
53153+ pax_open_kernel();
53154 if (drv && drv->get_resolution == NULL)
53155- drv->get_resolution = omapdss_default_get_resolution;
53156+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
53157 if (drv && drv->get_recommended_bpp == NULL)
53158- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53159+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53160 if (drv && drv->get_timings == NULL)
53161- drv->get_timings = omapdss_default_get_timings;
53162+ *(void **)&drv->get_timings = omapdss_default_get_timings;
53163+ pax_close_kernel();
53164
53165 mutex_lock(&panel_list_mutex);
53166 list_add_tail(&dssdev->panel_list, &panel_list);
53167diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
53168index 83433cb..71e9b98 100644
53169--- a/drivers/video/fbdev/s1d13xxxfb.c
53170+++ b/drivers/video/fbdev/s1d13xxxfb.c
53171@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
53172
53173 switch(prod_id) {
53174 case S1D13506_PROD_ID: /* activate acceleration */
53175- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53176- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53177+ pax_open_kernel();
53178+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53179+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53180+ pax_close_kernel();
53181 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
53182 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
53183 break;
53184diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53185index 2bcc84a..29dd1ea 100644
53186--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
53187+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53188@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
53189 }
53190
53191 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
53192- lcdc_sys_write_index,
53193- lcdc_sys_write_data,
53194- lcdc_sys_read_data,
53195+ .write_index = lcdc_sys_write_index,
53196+ .write_data = lcdc_sys_write_data,
53197+ .read_data = lcdc_sys_read_data,
53198 };
53199
53200 static int sh_mobile_lcdc_sginit(struct fb_info *info,
53201diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
53202index d513ed6..90b0de9 100644
53203--- a/drivers/video/fbdev/smscufx.c
53204+++ b/drivers/video/fbdev/smscufx.c
53205@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
53206 fb_deferred_io_cleanup(info);
53207 kfree(info->fbdefio);
53208 info->fbdefio = NULL;
53209- info->fbops->fb_mmap = ufx_ops_mmap;
53210+ pax_open_kernel();
53211+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
53212+ pax_close_kernel();
53213 }
53214
53215 pr_debug("released /dev/fb%d user=%d count=%d",
53216diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
53217index 77b890e..458e666 100644
53218--- a/drivers/video/fbdev/udlfb.c
53219+++ b/drivers/video/fbdev/udlfb.c
53220@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
53221 dlfb_urb_completion(urb);
53222
53223 error:
53224- atomic_add(bytes_sent, &dev->bytes_sent);
53225- atomic_add(bytes_identical, &dev->bytes_identical);
53226- atomic_add(width*height*2, &dev->bytes_rendered);
53227+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53228+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53229+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
53230 end_cycles = get_cycles();
53231- atomic_add(((unsigned int) ((end_cycles - start_cycles)
53232+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53233 >> 10)), /* Kcycles */
53234 &dev->cpu_kcycles_used);
53235
53236@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
53237 dlfb_urb_completion(urb);
53238
53239 error:
53240- atomic_add(bytes_sent, &dev->bytes_sent);
53241- atomic_add(bytes_identical, &dev->bytes_identical);
53242- atomic_add(bytes_rendered, &dev->bytes_rendered);
53243+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53244+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53245+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
53246 end_cycles = get_cycles();
53247- atomic_add(((unsigned int) ((end_cycles - start_cycles)
53248+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53249 >> 10)), /* Kcycles */
53250 &dev->cpu_kcycles_used);
53251 }
53252@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
53253 fb_deferred_io_cleanup(info);
53254 kfree(info->fbdefio);
53255 info->fbdefio = NULL;
53256- info->fbops->fb_mmap = dlfb_ops_mmap;
53257+ pax_open_kernel();
53258+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
53259+ pax_close_kernel();
53260 }
53261
53262 pr_warn("released /dev/fb%d user=%d count=%d\n",
53263@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
53264 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53265 struct dlfb_data *dev = fb_info->par;
53266 return snprintf(buf, PAGE_SIZE, "%u\n",
53267- atomic_read(&dev->bytes_rendered));
53268+ atomic_read_unchecked(&dev->bytes_rendered));
53269 }
53270
53271 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53272@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53273 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53274 struct dlfb_data *dev = fb_info->par;
53275 return snprintf(buf, PAGE_SIZE, "%u\n",
53276- atomic_read(&dev->bytes_identical));
53277+ atomic_read_unchecked(&dev->bytes_identical));
53278 }
53279
53280 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53281@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53282 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53283 struct dlfb_data *dev = fb_info->par;
53284 return snprintf(buf, PAGE_SIZE, "%u\n",
53285- atomic_read(&dev->bytes_sent));
53286+ atomic_read_unchecked(&dev->bytes_sent));
53287 }
53288
53289 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53290@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53291 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53292 struct dlfb_data *dev = fb_info->par;
53293 return snprintf(buf, PAGE_SIZE, "%u\n",
53294- atomic_read(&dev->cpu_kcycles_used));
53295+ atomic_read_unchecked(&dev->cpu_kcycles_used));
53296 }
53297
53298 static ssize_t edid_show(
53299@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
53300 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53301 struct dlfb_data *dev = fb_info->par;
53302
53303- atomic_set(&dev->bytes_rendered, 0);
53304- atomic_set(&dev->bytes_identical, 0);
53305- atomic_set(&dev->bytes_sent, 0);
53306- atomic_set(&dev->cpu_kcycles_used, 0);
53307+ atomic_set_unchecked(&dev->bytes_rendered, 0);
53308+ atomic_set_unchecked(&dev->bytes_identical, 0);
53309+ atomic_set_unchecked(&dev->bytes_sent, 0);
53310+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
53311
53312 return count;
53313 }
53314diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
53315index 509d452..7c9d2de 100644
53316--- a/drivers/video/fbdev/uvesafb.c
53317+++ b/drivers/video/fbdev/uvesafb.c
53318@@ -19,6 +19,7 @@
53319 #include <linux/io.h>
53320 #include <linux/mutex.h>
53321 #include <linux/slab.h>
53322+#include <linux/moduleloader.h>
53323 #include <video/edid.h>
53324 #include <video/uvesafb.h>
53325 #ifdef CONFIG_X86
53326@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
53327 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
53328 par->pmi_setpal = par->ypan = 0;
53329 } else {
53330+
53331+#ifdef CONFIG_PAX_KERNEXEC
53332+#ifdef CONFIG_MODULES
53333+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
53334+#endif
53335+ if (!par->pmi_code) {
53336+ par->pmi_setpal = par->ypan = 0;
53337+ return 0;
53338+ }
53339+#endif
53340+
53341 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
53342 + task->t.regs.edi);
53343+
53344+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53345+ pax_open_kernel();
53346+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
53347+ pax_close_kernel();
53348+
53349+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
53350+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
53351+#else
53352 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
53353 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
53354+#endif
53355+
53356 printk(KERN_INFO "uvesafb: protected mode interface info at "
53357 "%04x:%04x\n",
53358 (u16)task->t.regs.es, (u16)task->t.regs.edi);
53359@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
53360 par->ypan = ypan;
53361
53362 if (par->pmi_setpal || par->ypan) {
53363+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
53364 if (__supported_pte_mask & _PAGE_NX) {
53365 par->pmi_setpal = par->ypan = 0;
53366 printk(KERN_WARNING "uvesafb: NX protection is active, "
53367 "better not use the PMI.\n");
53368- } else {
53369+ } else
53370+#endif
53371 uvesafb_vbe_getpmi(task, par);
53372- }
53373 }
53374 #else
53375 /* The protected mode interface is not available on non-x86. */
53376@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53377 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
53378
53379 /* Disable blanking if the user requested so. */
53380- if (!blank)
53381- info->fbops->fb_blank = NULL;
53382+ if (!blank) {
53383+ pax_open_kernel();
53384+ *(void **)&info->fbops->fb_blank = NULL;
53385+ pax_close_kernel();
53386+ }
53387
53388 /*
53389 * Find out how much IO memory is required for the mode with
53390@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53391 info->flags = FBINFO_FLAG_DEFAULT |
53392 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
53393
53394- if (!par->ypan)
53395- info->fbops->fb_pan_display = NULL;
53396+ if (!par->ypan) {
53397+ pax_open_kernel();
53398+ *(void **)&info->fbops->fb_pan_display = NULL;
53399+ pax_close_kernel();
53400+ }
53401 }
53402
53403 static void uvesafb_init_mtrr(struct fb_info *info)
53404@@ -1787,6 +1817,11 @@ out_mode:
53405 out:
53406 kfree(par->vbe_modes);
53407
53408+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53409+ if (par->pmi_code)
53410+ module_free_exec(NULL, par->pmi_code);
53411+#endif
53412+
53413 framebuffer_release(info);
53414 return err;
53415 }
53416@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
53417 kfree(par->vbe_state_orig);
53418 kfree(par->vbe_state_saved);
53419
53420+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53421+ if (par->pmi_code)
53422+ module_free_exec(NULL, par->pmi_code);
53423+#endif
53424+
53425 framebuffer_release(info);
53426 }
53427 return 0;
53428diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
53429index 6170e7f..dd63031 100644
53430--- a/drivers/video/fbdev/vesafb.c
53431+++ b/drivers/video/fbdev/vesafb.c
53432@@ -9,6 +9,7 @@
53433 */
53434
53435 #include <linux/module.h>
53436+#include <linux/moduleloader.h>
53437 #include <linux/kernel.h>
53438 #include <linux/errno.h>
53439 #include <linux/string.h>
53440@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53441 static int vram_total; /* Set total amount of memory */
53442 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53443 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53444-static void (*pmi_start)(void) __read_mostly;
53445-static void (*pmi_pal) (void) __read_mostly;
53446+static void (*pmi_start)(void) __read_only;
53447+static void (*pmi_pal) (void) __read_only;
53448 static int depth __read_mostly;
53449 static int vga_compat __read_mostly;
53450 /* --------------------------------------------------------------------- */
53451@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
53452 unsigned int size_remap;
53453 unsigned int size_total;
53454 char *option = NULL;
53455+ void *pmi_code = NULL;
53456
53457 /* ignore error return of fb_get_options */
53458 fb_get_options("vesafb", &option);
53459@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
53460 size_remap = size_total;
53461 vesafb_fix.smem_len = size_remap;
53462
53463-#ifndef __i386__
53464- screen_info.vesapm_seg = 0;
53465-#endif
53466-
53467 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53468 printk(KERN_WARNING
53469 "vesafb: cannot reserve video memory at 0x%lx\n",
53470@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53471 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53472 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53473
53474+#ifdef __i386__
53475+
53476+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53477+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
53478+ if (!pmi_code)
53479+#elif !defined(CONFIG_PAX_KERNEXEC)
53480+ if (0)
53481+#endif
53482+
53483+#endif
53484+ screen_info.vesapm_seg = 0;
53485+
53486 if (screen_info.vesapm_seg) {
53487- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53488- screen_info.vesapm_seg,screen_info.vesapm_off);
53489+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53490+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53491 }
53492
53493 if (screen_info.vesapm_seg < 0xc000)
53494@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53495
53496 if (ypan || pmi_setpal) {
53497 unsigned short *pmi_base;
53498+
53499 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53500- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53501- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53502+
53503+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53504+ pax_open_kernel();
53505+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53506+#else
53507+ pmi_code = pmi_base;
53508+#endif
53509+
53510+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53511+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53512+
53513+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53514+ pmi_start = ktva_ktla(pmi_start);
53515+ pmi_pal = ktva_ktla(pmi_pal);
53516+ pax_close_kernel();
53517+#endif
53518+
53519 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53520 if (pmi_base[3]) {
53521 printk(KERN_INFO "vesafb: pmi: ports = ");
53522@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53523 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53524 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53525
53526- if (!ypan)
53527- info->fbops->fb_pan_display = NULL;
53528+ if (!ypan) {
53529+ pax_open_kernel();
53530+ *(void **)&info->fbops->fb_pan_display = NULL;
53531+ pax_close_kernel();
53532+ }
53533
53534 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53535 err = -ENOMEM;
53536@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53537 fb_info(info, "%s frame buffer device\n", info->fix.id);
53538 return 0;
53539 err:
53540+
53541+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53542+ module_free_exec(NULL, pmi_code);
53543+#endif
53544+
53545 if (info->screen_base)
53546 iounmap(info->screen_base);
53547 framebuffer_release(info);
53548diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53549index 88714ae..16c2e11 100644
53550--- a/drivers/video/fbdev/via/via_clock.h
53551+++ b/drivers/video/fbdev/via/via_clock.h
53552@@ -56,7 +56,7 @@ struct via_clock {
53553
53554 void (*set_engine_pll_state)(u8 state);
53555 void (*set_engine_pll)(struct via_pll_config config);
53556-};
53557+} __no_const;
53558
53559
53560 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53561diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53562index 3c14e43..2630570 100644
53563--- a/drivers/video/logo/logo_linux_clut224.ppm
53564+++ b/drivers/video/logo/logo_linux_clut224.ppm
53565@@ -2,1603 +2,1123 @@ P3
53566 # Standard 224-color Linux logo
53567 80 80
53568 255
53569- 0 0 0 0 0 0 0 0 0 0 0 0
53570- 0 0 0 0 0 0 0 0 0 0 0 0
53571- 0 0 0 0 0 0 0 0 0 0 0 0
53572- 0 0 0 0 0 0 0 0 0 0 0 0
53573- 0 0 0 0 0 0 0 0 0 0 0 0
53574- 0 0 0 0 0 0 0 0 0 0 0 0
53575- 0 0 0 0 0 0 0 0 0 0 0 0
53576- 0 0 0 0 0 0 0 0 0 0 0 0
53577- 0 0 0 0 0 0 0 0 0 0 0 0
53578- 6 6 6 6 6 6 10 10 10 10 10 10
53579- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0
53585- 0 0 0 0 0 0 0 0 0 0 0 0
53586- 0 0 0 0 0 0 0 0 0 0 0 0
53587- 0 0 0 0 0 0 0 0 0 0 0 0
53588- 0 0 0 0 0 0 0 0 0 0 0 0
53589- 0 0 0 0 0 0 0 0 0 0 0 0
53590- 0 0 0 0 0 0 0 0 0 0 0 0
53591- 0 0 0 0 0 0 0 0 0 0 0 0
53592- 0 0 0 0 0 0 0 0 0 0 0 0
53593- 0 0 0 0 0 0 0 0 0 0 0 0
53594- 0 0 0 0 0 0 0 0 0 0 0 0
53595- 0 0 0 0 0 0 0 0 0 0 0 0
53596- 0 0 0 0 0 0 0 0 0 0 0 0
53597- 0 0 0 6 6 6 10 10 10 14 14 14
53598- 22 22 22 26 26 26 30 30 30 34 34 34
53599- 30 30 30 30 30 30 26 26 26 18 18 18
53600- 14 14 14 10 10 10 6 6 6 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 0 0 0
53605- 0 0 0 0 0 0 0 0 0 0 0 0
53606- 0 0 0 0 0 0 0 0 0 0 0 0
53607- 0 0 0 0 0 0 0 0 0 0 0 0
53608- 0 0 0 0 0 0 0 0 0 0 0 0
53609- 0 0 0 0 0 0 0 0 0 0 0 0
53610- 0 0 0 0 0 1 0 0 1 0 0 0
53611- 0 0 0 0 0 0 0 0 0 0 0 0
53612- 0 0 0 0 0 0 0 0 0 0 0 0
53613- 0 0 0 0 0 0 0 0 0 0 0 0
53614- 0 0 0 0 0 0 0 0 0 0 0 0
53615- 0 0 0 0 0 0 0 0 0 0 0 0
53616- 0 0 0 0 0 0 0 0 0 0 0 0
53617- 6 6 6 14 14 14 26 26 26 42 42 42
53618- 54 54 54 66 66 66 78 78 78 78 78 78
53619- 78 78 78 74 74 74 66 66 66 54 54 54
53620- 42 42 42 26 26 26 18 18 18 10 10 10
53621- 6 6 6 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 0 0 0
53625- 0 0 0 0 0 0 0 0 0 0 0 0
53626- 0 0 0 0 0 0 0 0 0 0 0 0
53627- 0 0 0 0 0 0 0 0 0 0 0 0
53628- 0 0 0 0 0 0 0 0 0 0 0 0
53629- 0 0 0 0 0 0 0 0 0 0 0 0
53630- 0 0 1 0 0 0 0 0 0 0 0 0
53631- 0 0 0 0 0 0 0 0 0 0 0 0
53632- 0 0 0 0 0 0 0 0 0 0 0 0
53633- 0 0 0 0 0 0 0 0 0 0 0 0
53634- 0 0 0 0 0 0 0 0 0 0 0 0
53635- 0 0 0 0 0 0 0 0 0 0 0 0
53636- 0 0 0 0 0 0 0 0 0 10 10 10
53637- 22 22 22 42 42 42 66 66 66 86 86 86
53638- 66 66 66 38 38 38 38 38 38 22 22 22
53639- 26 26 26 34 34 34 54 54 54 66 66 66
53640- 86 86 86 70 70 70 46 46 46 26 26 26
53641- 14 14 14 6 6 6 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 0 0 0
53645- 0 0 0 0 0 0 0 0 0 0 0 0
53646- 0 0 0 0 0 0 0 0 0 0 0 0
53647- 0 0 0 0 0 0 0 0 0 0 0 0
53648- 0 0 0 0 0 0 0 0 0 0 0 0
53649- 0 0 0 0 0 0 0 0 0 0 0 0
53650- 0 0 1 0 0 1 0 0 1 0 0 0
53651- 0 0 0 0 0 0 0 0 0 0 0 0
53652- 0 0 0 0 0 0 0 0 0 0 0 0
53653- 0 0 0 0 0 0 0 0 0 0 0 0
53654- 0 0 0 0 0 0 0 0 0 0 0 0
53655- 0 0 0 0 0 0 0 0 0 0 0 0
53656- 0 0 0 0 0 0 10 10 10 26 26 26
53657- 50 50 50 82 82 82 58 58 58 6 6 6
53658- 2 2 6 2 2 6 2 2 6 2 2 6
53659- 2 2 6 2 2 6 2 2 6 2 2 6
53660- 6 6 6 54 54 54 86 86 86 66 66 66
53661- 38 38 38 18 18 18 6 6 6 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 0 0 0
53665- 0 0 0 0 0 0 0 0 0 0 0 0
53666- 0 0 0 0 0 0 0 0 0 0 0 0
53667- 0 0 0 0 0 0 0 0 0 0 0 0
53668- 0 0 0 0 0 0 0 0 0 0 0 0
53669- 0 0 0 0 0 0 0 0 0 0 0 0
53670- 0 0 0 0 0 0 0 0 0 0 0 0
53671- 0 0 0 0 0 0 0 0 0 0 0 0
53672- 0 0 0 0 0 0 0 0 0 0 0 0
53673- 0 0 0 0 0 0 0 0 0 0 0 0
53674- 0 0 0 0 0 0 0 0 0 0 0 0
53675- 0 0 0 0 0 0 0 0 0 0 0 0
53676- 0 0 0 6 6 6 22 22 22 50 50 50
53677- 78 78 78 34 34 34 2 2 6 2 2 6
53678- 2 2 6 2 2 6 2 2 6 2 2 6
53679- 2 2 6 2 2 6 2 2 6 2 2 6
53680- 2 2 6 2 2 6 6 6 6 70 70 70
53681- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
53685- 0 0 0 0 0 0 0 0 0 0 0 0
53686- 0 0 0 0 0 0 0 0 0 0 0 0
53687- 0 0 0 0 0 0 0 0 0 0 0 0
53688- 0 0 0 0 0 0 0 0 0 0 0 0
53689- 0 0 0 0 0 0 0 0 0 0 0 0
53690- 0 0 1 0 0 1 0 0 1 0 0 0
53691- 0 0 0 0 0 0 0 0 0 0 0 0
53692- 0 0 0 0 0 0 0 0 0 0 0 0
53693- 0 0 0 0 0 0 0 0 0 0 0 0
53694- 0 0 0 0 0 0 0 0 0 0 0 0
53695- 0 0 0 0 0 0 0 0 0 0 0 0
53696- 6 6 6 18 18 18 42 42 42 82 82 82
53697- 26 26 26 2 2 6 2 2 6 2 2 6
53698- 2 2 6 2 2 6 2 2 6 2 2 6
53699- 2 2 6 2 2 6 2 2 6 14 14 14
53700- 46 46 46 34 34 34 6 6 6 2 2 6
53701- 42 42 42 78 78 78 42 42 42 18 18 18
53702- 6 6 6 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 0 0 0
53705- 0 0 0 0 0 0 0 0 0 0 0 0
53706- 0 0 0 0 0 0 0 0 0 0 0 0
53707- 0 0 0 0 0 0 0 0 0 0 0 0
53708- 0 0 0 0 0 0 0 0 0 0 0 0
53709- 0 0 0 0 0 0 0 0 0 0 0 0
53710- 0 0 1 0 0 0 0 0 1 0 0 0
53711- 0 0 0 0 0 0 0 0 0 0 0 0
53712- 0 0 0 0 0 0 0 0 0 0 0 0
53713- 0 0 0 0 0 0 0 0 0 0 0 0
53714- 0 0 0 0 0 0 0 0 0 0 0 0
53715- 0 0 0 0 0 0 0 0 0 0 0 0
53716- 10 10 10 30 30 30 66 66 66 58 58 58
53717- 2 2 6 2 2 6 2 2 6 2 2 6
53718- 2 2 6 2 2 6 2 2 6 2 2 6
53719- 2 2 6 2 2 6 2 2 6 26 26 26
53720- 86 86 86 101 101 101 46 46 46 10 10 10
53721- 2 2 6 58 58 58 70 70 70 34 34 34
53722- 10 10 10 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 0 0 0 0 0 0
53725- 0 0 0 0 0 0 0 0 0 0 0 0
53726- 0 0 0 0 0 0 0 0 0 0 0 0
53727- 0 0 0 0 0 0 0 0 0 0 0 0
53728- 0 0 0 0 0 0 0 0 0 0 0 0
53729- 0 0 0 0 0 0 0 0 0 0 0 0
53730- 0 0 1 0 0 1 0 0 1 0 0 0
53731- 0 0 0 0 0 0 0 0 0 0 0 0
53732- 0 0 0 0 0 0 0 0 0 0 0 0
53733- 0 0 0 0 0 0 0 0 0 0 0 0
53734- 0 0 0 0 0 0 0 0 0 0 0 0
53735- 0 0 0 0 0 0 0 0 0 0 0 0
53736- 14 14 14 42 42 42 86 86 86 10 10 10
53737- 2 2 6 2 2 6 2 2 6 2 2 6
53738- 2 2 6 2 2 6 2 2 6 2 2 6
53739- 2 2 6 2 2 6 2 2 6 30 30 30
53740- 94 94 94 94 94 94 58 58 58 26 26 26
53741- 2 2 6 6 6 6 78 78 78 54 54 54
53742- 22 22 22 6 6 6 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 0 0 0 0 0 0
53745- 0 0 0 0 0 0 0 0 0 0 0 0
53746- 0 0 0 0 0 0 0 0 0 0 0 0
53747- 0 0 0 0 0 0 0 0 0 0 0 0
53748- 0 0 0 0 0 0 0 0 0 0 0 0
53749- 0 0 0 0 0 0 0 0 0 0 0 0
53750- 0 0 0 0 0 0 0 0 0 0 0 0
53751- 0 0 0 0 0 0 0 0 0 0 0 0
53752- 0 0 0 0 0 0 0 0 0 0 0 0
53753- 0 0 0 0 0 0 0 0 0 0 0 0
53754- 0 0 0 0 0 0 0 0 0 0 0 0
53755- 0 0 0 0 0 0 0 0 0 6 6 6
53756- 22 22 22 62 62 62 62 62 62 2 2 6
53757- 2 2 6 2 2 6 2 2 6 2 2 6
53758- 2 2 6 2 2 6 2 2 6 2 2 6
53759- 2 2 6 2 2 6 2 2 6 26 26 26
53760- 54 54 54 38 38 38 18 18 18 10 10 10
53761- 2 2 6 2 2 6 34 34 34 82 82 82
53762- 38 38 38 14 14 14 0 0 0 0 0 0
53763- 0 0 0 0 0 0 0 0 0 0 0 0
53764- 0 0 0 0 0 0 0 0 0 0 0 0
53765- 0 0 0 0 0 0 0 0 0 0 0 0
53766- 0 0 0 0 0 0 0 0 0 0 0 0
53767- 0 0 0 0 0 0 0 0 0 0 0 0
53768- 0 0 0 0 0 0 0 0 0 0 0 0
53769- 0 0 0 0 0 0 0 0 0 0 0 0
53770- 0 0 0 0 0 1 0 0 1 0 0 0
53771- 0 0 0 0 0 0 0 0 0 0 0 0
53772- 0 0 0 0 0 0 0 0 0 0 0 0
53773- 0 0 0 0 0 0 0 0 0 0 0 0
53774- 0 0 0 0 0 0 0 0 0 0 0 0
53775- 0 0 0 0 0 0 0 0 0 6 6 6
53776- 30 30 30 78 78 78 30 30 30 2 2 6
53777- 2 2 6 2 2 6 2 2 6 2 2 6
53778- 2 2 6 2 2 6 2 2 6 2 2 6
53779- 2 2 6 2 2 6 2 2 6 10 10 10
53780- 10 10 10 2 2 6 2 2 6 2 2 6
53781- 2 2 6 2 2 6 2 2 6 78 78 78
53782- 50 50 50 18 18 18 6 6 6 0 0 0
53783- 0 0 0 0 0 0 0 0 0 0 0 0
53784- 0 0 0 0 0 0 0 0 0 0 0 0
53785- 0 0 0 0 0 0 0 0 0 0 0 0
53786- 0 0 0 0 0 0 0 0 0 0 0 0
53787- 0 0 0 0 0 0 0 0 0 0 0 0
53788- 0 0 0 0 0 0 0 0 0 0 0 0
53789- 0 0 0 0 0 0 0 0 0 0 0 0
53790- 0 0 1 0 0 0 0 0 0 0 0 0
53791- 0 0 0 0 0 0 0 0 0 0 0 0
53792- 0 0 0 0 0 0 0 0 0 0 0 0
53793- 0 0 0 0 0 0 0 0 0 0 0 0
53794- 0 0 0 0 0 0 0 0 0 0 0 0
53795- 0 0 0 0 0 0 0 0 0 10 10 10
53796- 38 38 38 86 86 86 14 14 14 2 2 6
53797- 2 2 6 2 2 6 2 2 6 2 2 6
53798- 2 2 6 2 2 6 2 2 6 2 2 6
53799- 2 2 6 2 2 6 2 2 6 2 2 6
53800- 2 2 6 2 2 6 2 2 6 2 2 6
53801- 2 2 6 2 2 6 2 2 6 54 54 54
53802- 66 66 66 26 26 26 6 6 6 0 0 0
53803- 0 0 0 0 0 0 0 0 0 0 0 0
53804- 0 0 0 0 0 0 0 0 0 0 0 0
53805- 0 0 0 0 0 0 0 0 0 0 0 0
53806- 0 0 0 0 0 0 0 0 0 0 0 0
53807- 0 0 0 0 0 0 0 0 0 0 0 0
53808- 0 0 0 0 0 0 0 0 0 0 0 0
53809- 0 0 0 0 0 0 0 0 0 0 0 0
53810- 0 0 0 0 0 1 0 0 1 0 0 0
53811- 0 0 0 0 0 0 0 0 0 0 0 0
53812- 0 0 0 0 0 0 0 0 0 0 0 0
53813- 0 0 0 0 0 0 0 0 0 0 0 0
53814- 0 0 0 0 0 0 0 0 0 0 0 0
53815- 0 0 0 0 0 0 0 0 0 14 14 14
53816- 42 42 42 82 82 82 2 2 6 2 2 6
53817- 2 2 6 6 6 6 10 10 10 2 2 6
53818- 2 2 6 2 2 6 2 2 6 2 2 6
53819- 2 2 6 2 2 6 2 2 6 6 6 6
53820- 14 14 14 10 10 10 2 2 6 2 2 6
53821- 2 2 6 2 2 6 2 2 6 18 18 18
53822- 82 82 82 34 34 34 10 10 10 0 0 0
53823- 0 0 0 0 0 0 0 0 0 0 0 0
53824- 0 0 0 0 0 0 0 0 0 0 0 0
53825- 0 0 0 0 0 0 0 0 0 0 0 0
53826- 0 0 0 0 0 0 0 0 0 0 0 0
53827- 0 0 0 0 0 0 0 0 0 0 0 0
53828- 0 0 0 0 0 0 0 0 0 0 0 0
53829- 0 0 0 0 0 0 0 0 0 0 0 0
53830- 0 0 1 0 0 0 0 0 0 0 0 0
53831- 0 0 0 0 0 0 0 0 0 0 0 0
53832- 0 0 0 0 0 0 0 0 0 0 0 0
53833- 0 0 0 0 0 0 0 0 0 0 0 0
53834- 0 0 0 0 0 0 0 0 0 0 0 0
53835- 0 0 0 0 0 0 0 0 0 14 14 14
53836- 46 46 46 86 86 86 2 2 6 2 2 6
53837- 6 6 6 6 6 6 22 22 22 34 34 34
53838- 6 6 6 2 2 6 2 2 6 2 2 6
53839- 2 2 6 2 2 6 18 18 18 34 34 34
53840- 10 10 10 50 50 50 22 22 22 2 2 6
53841- 2 2 6 2 2 6 2 2 6 10 10 10
53842- 86 86 86 42 42 42 14 14 14 0 0 0
53843- 0 0 0 0 0 0 0 0 0 0 0 0
53844- 0 0 0 0 0 0 0 0 0 0 0 0
53845- 0 0 0 0 0 0 0 0 0 0 0 0
53846- 0 0 0 0 0 0 0 0 0 0 0 0
53847- 0 0 0 0 0 0 0 0 0 0 0 0
53848- 0 0 0 0 0 0 0 0 0 0 0 0
53849- 0 0 0 0 0 0 0 0 0 0 0 0
53850- 0 0 1 0 0 1 0 0 1 0 0 0
53851- 0 0 0 0 0 0 0 0 0 0 0 0
53852- 0 0 0 0 0 0 0 0 0 0 0 0
53853- 0 0 0 0 0 0 0 0 0 0 0 0
53854- 0 0 0 0 0 0 0 0 0 0 0 0
53855- 0 0 0 0 0 0 0 0 0 14 14 14
53856- 46 46 46 86 86 86 2 2 6 2 2 6
53857- 38 38 38 116 116 116 94 94 94 22 22 22
53858- 22 22 22 2 2 6 2 2 6 2 2 6
53859- 14 14 14 86 86 86 138 138 138 162 162 162
53860-154 154 154 38 38 38 26 26 26 6 6 6
53861- 2 2 6 2 2 6 2 2 6 2 2 6
53862- 86 86 86 46 46 46 14 14 14 0 0 0
53863- 0 0 0 0 0 0 0 0 0 0 0 0
53864- 0 0 0 0 0 0 0 0 0 0 0 0
53865- 0 0 0 0 0 0 0 0 0 0 0 0
53866- 0 0 0 0 0 0 0 0 0 0 0 0
53867- 0 0 0 0 0 0 0 0 0 0 0 0
53868- 0 0 0 0 0 0 0 0 0 0 0 0
53869- 0 0 0 0 0 0 0 0 0 0 0 0
53870- 0 0 0 0 0 0 0 0 0 0 0 0
53871- 0 0 0 0 0 0 0 0 0 0 0 0
53872- 0 0 0 0 0 0 0 0 0 0 0 0
53873- 0 0 0 0 0 0 0 0 0 0 0 0
53874- 0 0 0 0 0 0 0 0 0 0 0 0
53875- 0 0 0 0 0 0 0 0 0 14 14 14
53876- 46 46 46 86 86 86 2 2 6 14 14 14
53877-134 134 134 198 198 198 195 195 195 116 116 116
53878- 10 10 10 2 2 6 2 2 6 6 6 6
53879-101 98 89 187 187 187 210 210 210 218 218 218
53880-214 214 214 134 134 134 14 14 14 6 6 6
53881- 2 2 6 2 2 6 2 2 6 2 2 6
53882- 86 86 86 50 50 50 18 18 18 6 6 6
53883- 0 0 0 0 0 0 0 0 0 0 0 0
53884- 0 0 0 0 0 0 0 0 0 0 0 0
53885- 0 0 0 0 0 0 0 0 0 0 0 0
53886- 0 0 0 0 0 0 0 0 0 0 0 0
53887- 0 0 0 0 0 0 0 0 0 0 0 0
53888- 0 0 0 0 0 0 0 0 0 0 0 0
53889- 0 0 0 0 0 0 0 0 1 0 0 0
53890- 0 0 1 0 0 1 0 0 1 0 0 0
53891- 0 0 0 0 0 0 0 0 0 0 0 0
53892- 0 0 0 0 0 0 0 0 0 0 0 0
53893- 0 0 0 0 0 0 0 0 0 0 0 0
53894- 0 0 0 0 0 0 0 0 0 0 0 0
53895- 0 0 0 0 0 0 0 0 0 14 14 14
53896- 46 46 46 86 86 86 2 2 6 54 54 54
53897-218 218 218 195 195 195 226 226 226 246 246 246
53898- 58 58 58 2 2 6 2 2 6 30 30 30
53899-210 210 210 253 253 253 174 174 174 123 123 123
53900-221 221 221 234 234 234 74 74 74 2 2 6
53901- 2 2 6 2 2 6 2 2 6 2 2 6
53902- 70 70 70 58 58 58 22 22 22 6 6 6
53903- 0 0 0 0 0 0 0 0 0 0 0 0
53904- 0 0 0 0 0 0 0 0 0 0 0 0
53905- 0 0 0 0 0 0 0 0 0 0 0 0
53906- 0 0 0 0 0 0 0 0 0 0 0 0
53907- 0 0 0 0 0 0 0 0 0 0 0 0
53908- 0 0 0 0 0 0 0 0 0 0 0 0
53909- 0 0 0 0 0 0 0 0 0 0 0 0
53910- 0 0 0 0 0 0 0 0 0 0 0 0
53911- 0 0 0 0 0 0 0 0 0 0 0 0
53912- 0 0 0 0 0 0 0 0 0 0 0 0
53913- 0 0 0 0 0 0 0 0 0 0 0 0
53914- 0 0 0 0 0 0 0 0 0 0 0 0
53915- 0 0 0 0 0 0 0 0 0 14 14 14
53916- 46 46 46 82 82 82 2 2 6 106 106 106
53917-170 170 170 26 26 26 86 86 86 226 226 226
53918-123 123 123 10 10 10 14 14 14 46 46 46
53919-231 231 231 190 190 190 6 6 6 70 70 70
53920- 90 90 90 238 238 238 158 158 158 2 2 6
53921- 2 2 6 2 2 6 2 2 6 2 2 6
53922- 70 70 70 58 58 58 22 22 22 6 6 6
53923- 0 0 0 0 0 0 0 0 0 0 0 0
53924- 0 0 0 0 0 0 0 0 0 0 0 0
53925- 0 0 0 0 0 0 0 0 0 0 0 0
53926- 0 0 0 0 0 0 0 0 0 0 0 0
53927- 0 0 0 0 0 0 0 0 0 0 0 0
53928- 0 0 0 0 0 0 0 0 0 0 0 0
53929- 0 0 0 0 0 0 0 0 1 0 0 0
53930- 0 0 1 0 0 1 0 0 1 0 0 0
53931- 0 0 0 0 0 0 0 0 0 0 0 0
53932- 0 0 0 0 0 0 0 0 0 0 0 0
53933- 0 0 0 0 0 0 0 0 0 0 0 0
53934- 0 0 0 0 0 0 0 0 0 0 0 0
53935- 0 0 0 0 0 0 0 0 0 14 14 14
53936- 42 42 42 86 86 86 6 6 6 116 116 116
53937-106 106 106 6 6 6 70 70 70 149 149 149
53938-128 128 128 18 18 18 38 38 38 54 54 54
53939-221 221 221 106 106 106 2 2 6 14 14 14
53940- 46 46 46 190 190 190 198 198 198 2 2 6
53941- 2 2 6 2 2 6 2 2 6 2 2 6
53942- 74 74 74 62 62 62 22 22 22 6 6 6
53943- 0 0 0 0 0 0 0 0 0 0 0 0
53944- 0 0 0 0 0 0 0 0 0 0 0 0
53945- 0 0 0 0 0 0 0 0 0 0 0 0
53946- 0 0 0 0 0 0 0 0 0 0 0 0
53947- 0 0 0 0 0 0 0 0 0 0 0 0
53948- 0 0 0 0 0 0 0 0 0 0 0 0
53949- 0 0 0 0 0 0 0 0 1 0 0 0
53950- 0 0 1 0 0 0 0 0 1 0 0 0
53951- 0 0 0 0 0 0 0 0 0 0 0 0
53952- 0 0 0 0 0 0 0 0 0 0 0 0
53953- 0 0 0 0 0 0 0 0 0 0 0 0
53954- 0 0 0 0 0 0 0 0 0 0 0 0
53955- 0 0 0 0 0 0 0 0 0 14 14 14
53956- 42 42 42 94 94 94 14 14 14 101 101 101
53957-128 128 128 2 2 6 18 18 18 116 116 116
53958-118 98 46 121 92 8 121 92 8 98 78 10
53959-162 162 162 106 106 106 2 2 6 2 2 6
53960- 2 2 6 195 195 195 195 195 195 6 6 6
53961- 2 2 6 2 2 6 2 2 6 2 2 6
53962- 74 74 74 62 62 62 22 22 22 6 6 6
53963- 0 0 0 0 0 0 0 0 0 0 0 0
53964- 0 0 0 0 0 0 0 0 0 0 0 0
53965- 0 0 0 0 0 0 0 0 0 0 0 0
53966- 0 0 0 0 0 0 0 0 0 0 0 0
53967- 0 0 0 0 0 0 0 0 0 0 0 0
53968- 0 0 0 0 0 0 0 0 0 0 0 0
53969- 0 0 0 0 0 0 0 0 1 0 0 1
53970- 0 0 1 0 0 0 0 0 1 0 0 0
53971- 0 0 0 0 0 0 0 0 0 0 0 0
53972- 0 0 0 0 0 0 0 0 0 0 0 0
53973- 0 0 0 0 0 0 0 0 0 0 0 0
53974- 0 0 0 0 0 0 0 0 0 0 0 0
53975- 0 0 0 0 0 0 0 0 0 10 10 10
53976- 38 38 38 90 90 90 14 14 14 58 58 58
53977-210 210 210 26 26 26 54 38 6 154 114 10
53978-226 170 11 236 186 11 225 175 15 184 144 12
53979-215 174 15 175 146 61 37 26 9 2 2 6
53980- 70 70 70 246 246 246 138 138 138 2 2 6
53981- 2 2 6 2 2 6 2 2 6 2 2 6
53982- 70 70 70 66 66 66 26 26 26 6 6 6
53983- 0 0 0 0 0 0 0 0 0 0 0 0
53984- 0 0 0 0 0 0 0 0 0 0 0 0
53985- 0 0 0 0 0 0 0 0 0 0 0 0
53986- 0 0 0 0 0 0 0 0 0 0 0 0
53987- 0 0 0 0 0 0 0 0 0 0 0 0
53988- 0 0 0 0 0 0 0 0 0 0 0 0
53989- 0 0 0 0 0 0 0 0 0 0 0 0
53990- 0 0 0 0 0 0 0 0 0 0 0 0
53991- 0 0 0 0 0 0 0 0 0 0 0 0
53992- 0 0 0 0 0 0 0 0 0 0 0 0
53993- 0 0 0 0 0 0 0 0 0 0 0 0
53994- 0 0 0 0 0 0 0 0 0 0 0 0
53995- 0 0 0 0 0 0 0 0 0 10 10 10
53996- 38 38 38 86 86 86 14 14 14 10 10 10
53997-195 195 195 188 164 115 192 133 9 225 175 15
53998-239 182 13 234 190 10 232 195 16 232 200 30
53999-245 207 45 241 208 19 232 195 16 184 144 12
54000-218 194 134 211 206 186 42 42 42 2 2 6
54001- 2 2 6 2 2 6 2 2 6 2 2 6
54002- 50 50 50 74 74 74 30 30 30 6 6 6
54003- 0 0 0 0 0 0 0 0 0 0 0 0
54004- 0 0 0 0 0 0 0 0 0 0 0 0
54005- 0 0 0 0 0 0 0 0 0 0 0 0
54006- 0 0 0 0 0 0 0 0 0 0 0 0
54007- 0 0 0 0 0 0 0 0 0 0 0 0
54008- 0 0 0 0 0 0 0 0 0 0 0 0
54009- 0 0 0 0 0 0 0 0 0 0 0 0
54010- 0 0 0 0 0 0 0 0 0 0 0 0
54011- 0 0 0 0 0 0 0 0 0 0 0 0
54012- 0 0 0 0 0 0 0 0 0 0 0 0
54013- 0 0 0 0 0 0 0 0 0 0 0 0
54014- 0 0 0 0 0 0 0 0 0 0 0 0
54015- 0 0 0 0 0 0 0 0 0 10 10 10
54016- 34 34 34 86 86 86 14 14 14 2 2 6
54017-121 87 25 192 133 9 219 162 10 239 182 13
54018-236 186 11 232 195 16 241 208 19 244 214 54
54019-246 218 60 246 218 38 246 215 20 241 208 19
54020-241 208 19 226 184 13 121 87 25 2 2 6
54021- 2 2 6 2 2 6 2 2 6 2 2 6
54022- 50 50 50 82 82 82 34 34 34 10 10 10
54023- 0 0 0 0 0 0 0 0 0 0 0 0
54024- 0 0 0 0 0 0 0 0 0 0 0 0
54025- 0 0 0 0 0 0 0 0 0 0 0 0
54026- 0 0 0 0 0 0 0 0 0 0 0 0
54027- 0 0 0 0 0 0 0 0 0 0 0 0
54028- 0 0 0 0 0 0 0 0 0 0 0 0
54029- 0 0 0 0 0 0 0 0 0 0 0 0
54030- 0 0 0 0 0 0 0 0 0 0 0 0
54031- 0 0 0 0 0 0 0 0 0 0 0 0
54032- 0 0 0 0 0 0 0 0 0 0 0 0
54033- 0 0 0 0 0 0 0 0 0 0 0 0
54034- 0 0 0 0 0 0 0 0 0 0 0 0
54035- 0 0 0 0 0 0 0 0 0 10 10 10
54036- 34 34 34 82 82 82 30 30 30 61 42 6
54037-180 123 7 206 145 10 230 174 11 239 182 13
54038-234 190 10 238 202 15 241 208 19 246 218 74
54039-246 218 38 246 215 20 246 215 20 246 215 20
54040-226 184 13 215 174 15 184 144 12 6 6 6
54041- 2 2 6 2 2 6 2 2 6 2 2 6
54042- 26 26 26 94 94 94 42 42 42 14 14 14
54043- 0 0 0 0 0 0 0 0 0 0 0 0
54044- 0 0 0 0 0 0 0 0 0 0 0 0
54045- 0 0 0 0 0 0 0 0 0 0 0 0
54046- 0 0 0 0 0 0 0 0 0 0 0 0
54047- 0 0 0 0 0 0 0 0 0 0 0 0
54048- 0 0 0 0 0 0 0 0 0 0 0 0
54049- 0 0 0 0 0 0 0 0 0 0 0 0
54050- 0 0 0 0 0 0 0 0 0 0 0 0
54051- 0 0 0 0 0 0 0 0 0 0 0 0
54052- 0 0 0 0 0 0 0 0 0 0 0 0
54053- 0 0 0 0 0 0 0 0 0 0 0 0
54054- 0 0 0 0 0 0 0 0 0 0 0 0
54055- 0 0 0 0 0 0 0 0 0 10 10 10
54056- 30 30 30 78 78 78 50 50 50 104 69 6
54057-192 133 9 216 158 10 236 178 12 236 186 11
54058-232 195 16 241 208 19 244 214 54 245 215 43
54059-246 215 20 246 215 20 241 208 19 198 155 10
54060-200 144 11 216 158 10 156 118 10 2 2 6
54061- 2 2 6 2 2 6 2 2 6 2 2 6
54062- 6 6 6 90 90 90 54 54 54 18 18 18
54063- 6 6 6 0 0 0 0 0 0 0 0 0
54064- 0 0 0 0 0 0 0 0 0 0 0 0
54065- 0 0 0 0 0 0 0 0 0 0 0 0
54066- 0 0 0 0 0 0 0 0 0 0 0 0
54067- 0 0 0 0 0 0 0 0 0 0 0 0
54068- 0 0 0 0 0 0 0 0 0 0 0 0
54069- 0 0 0 0 0 0 0 0 0 0 0 0
54070- 0 0 0 0 0 0 0 0 0 0 0 0
54071- 0 0 0 0 0 0 0 0 0 0 0 0
54072- 0 0 0 0 0 0 0 0 0 0 0 0
54073- 0 0 0 0 0 0 0 0 0 0 0 0
54074- 0 0 0 0 0 0 0 0 0 0 0 0
54075- 0 0 0 0 0 0 0 0 0 10 10 10
54076- 30 30 30 78 78 78 46 46 46 22 22 22
54077-137 92 6 210 162 10 239 182 13 238 190 10
54078-238 202 15 241 208 19 246 215 20 246 215 20
54079-241 208 19 203 166 17 185 133 11 210 150 10
54080-216 158 10 210 150 10 102 78 10 2 2 6
54081- 6 6 6 54 54 54 14 14 14 2 2 6
54082- 2 2 6 62 62 62 74 74 74 30 30 30
54083- 10 10 10 0 0 0 0 0 0 0 0 0
54084- 0 0 0 0 0 0 0 0 0 0 0 0
54085- 0 0 0 0 0 0 0 0 0 0 0 0
54086- 0 0 0 0 0 0 0 0 0 0 0 0
54087- 0 0 0 0 0 0 0 0 0 0 0 0
54088- 0 0 0 0 0 0 0 0 0 0 0 0
54089- 0 0 0 0 0 0 0 0 0 0 0 0
54090- 0 0 0 0 0 0 0 0 0 0 0 0
54091- 0 0 0 0 0 0 0 0 0 0 0 0
54092- 0 0 0 0 0 0 0 0 0 0 0 0
54093- 0 0 0 0 0 0 0 0 0 0 0 0
54094- 0 0 0 0 0 0 0 0 0 0 0 0
54095- 0 0 0 0 0 0 0 0 0 10 10 10
54096- 34 34 34 78 78 78 50 50 50 6 6 6
54097- 94 70 30 139 102 15 190 146 13 226 184 13
54098-232 200 30 232 195 16 215 174 15 190 146 13
54099-168 122 10 192 133 9 210 150 10 213 154 11
54100-202 150 34 182 157 106 101 98 89 2 2 6
54101- 2 2 6 78 78 78 116 116 116 58 58 58
54102- 2 2 6 22 22 22 90 90 90 46 46 46
54103- 18 18 18 6 6 6 0 0 0 0 0 0
54104- 0 0 0 0 0 0 0 0 0 0 0 0
54105- 0 0 0 0 0 0 0 0 0 0 0 0
54106- 0 0 0 0 0 0 0 0 0 0 0 0
54107- 0 0 0 0 0 0 0 0 0 0 0 0
54108- 0 0 0 0 0 0 0 0 0 0 0 0
54109- 0 0 0 0 0 0 0 0 0 0 0 0
54110- 0 0 0 0 0 0 0 0 0 0 0 0
54111- 0 0 0 0 0 0 0 0 0 0 0 0
54112- 0 0 0 0 0 0 0 0 0 0 0 0
54113- 0 0 0 0 0 0 0 0 0 0 0 0
54114- 0 0 0 0 0 0 0 0 0 0 0 0
54115- 0 0 0 0 0 0 0 0 0 10 10 10
54116- 38 38 38 86 86 86 50 50 50 6 6 6
54117-128 128 128 174 154 114 156 107 11 168 122 10
54118-198 155 10 184 144 12 197 138 11 200 144 11
54119-206 145 10 206 145 10 197 138 11 188 164 115
54120-195 195 195 198 198 198 174 174 174 14 14 14
54121- 2 2 6 22 22 22 116 116 116 116 116 116
54122- 22 22 22 2 2 6 74 74 74 70 70 70
54123- 30 30 30 10 10 10 0 0 0 0 0 0
54124- 0 0 0 0 0 0 0 0 0 0 0 0
54125- 0 0 0 0 0 0 0 0 0 0 0 0
54126- 0 0 0 0 0 0 0 0 0 0 0 0
54127- 0 0 0 0 0 0 0 0 0 0 0 0
54128- 0 0 0 0 0 0 0 0 0 0 0 0
54129- 0 0 0 0 0 0 0 0 0 0 0 0
54130- 0 0 0 0 0 0 0 0 0 0 0 0
54131- 0 0 0 0 0 0 0 0 0 0 0 0
54132- 0 0 0 0 0 0 0 0 0 0 0 0
54133- 0 0 0 0 0 0 0 0 0 0 0 0
54134- 0 0 0 0 0 0 0 0 0 0 0 0
54135- 0 0 0 0 0 0 6 6 6 18 18 18
54136- 50 50 50 101 101 101 26 26 26 10 10 10
54137-138 138 138 190 190 190 174 154 114 156 107 11
54138-197 138 11 200 144 11 197 138 11 192 133 9
54139-180 123 7 190 142 34 190 178 144 187 187 187
54140-202 202 202 221 221 221 214 214 214 66 66 66
54141- 2 2 6 2 2 6 50 50 50 62 62 62
54142- 6 6 6 2 2 6 10 10 10 90 90 90
54143- 50 50 50 18 18 18 6 6 6 0 0 0
54144- 0 0 0 0 0 0 0 0 0 0 0 0
54145- 0 0 0 0 0 0 0 0 0 0 0 0
54146- 0 0 0 0 0 0 0 0 0 0 0 0
54147- 0 0 0 0 0 0 0 0 0 0 0 0
54148- 0 0 0 0 0 0 0 0 0 0 0 0
54149- 0 0 0 0 0 0 0 0 0 0 0 0
54150- 0 0 0 0 0 0 0 0 0 0 0 0
54151- 0 0 0 0 0 0 0 0 0 0 0 0
54152- 0 0 0 0 0 0 0 0 0 0 0 0
54153- 0 0 0 0 0 0 0 0 0 0 0 0
54154- 0 0 0 0 0 0 0 0 0 0 0 0
54155- 0 0 0 0 0 0 10 10 10 34 34 34
54156- 74 74 74 74 74 74 2 2 6 6 6 6
54157-144 144 144 198 198 198 190 190 190 178 166 146
54158-154 121 60 156 107 11 156 107 11 168 124 44
54159-174 154 114 187 187 187 190 190 190 210 210 210
54160-246 246 246 253 253 253 253 253 253 182 182 182
54161- 6 6 6 2 2 6 2 2 6 2 2 6
54162- 2 2 6 2 2 6 2 2 6 62 62 62
54163- 74 74 74 34 34 34 14 14 14 0 0 0
54164- 0 0 0 0 0 0 0 0 0 0 0 0
54165- 0 0 0 0 0 0 0 0 0 0 0 0
54166- 0 0 0 0 0 0 0 0 0 0 0 0
54167- 0 0 0 0 0 0 0 0 0 0 0 0
54168- 0 0 0 0 0 0 0 0 0 0 0 0
54169- 0 0 0 0 0 0 0 0 0 0 0 0
54170- 0 0 0 0 0 0 0 0 0 0 0 0
54171- 0 0 0 0 0 0 0 0 0 0 0 0
54172- 0 0 0 0 0 0 0 0 0 0 0 0
54173- 0 0 0 0 0 0 0 0 0 0 0 0
54174- 0 0 0 0 0 0 0 0 0 0 0 0
54175- 0 0 0 10 10 10 22 22 22 54 54 54
54176- 94 94 94 18 18 18 2 2 6 46 46 46
54177-234 234 234 221 221 221 190 190 190 190 190 190
54178-190 190 190 187 187 187 187 187 187 190 190 190
54179-190 190 190 195 195 195 214 214 214 242 242 242
54180-253 253 253 253 253 253 253 253 253 253 253 253
54181- 82 82 82 2 2 6 2 2 6 2 2 6
54182- 2 2 6 2 2 6 2 2 6 14 14 14
54183- 86 86 86 54 54 54 22 22 22 6 6 6
54184- 0 0 0 0 0 0 0 0 0 0 0 0
54185- 0 0 0 0 0 0 0 0 0 0 0 0
54186- 0 0 0 0 0 0 0 0 0 0 0 0
54187- 0 0 0 0 0 0 0 0 0 0 0 0
54188- 0 0 0 0 0 0 0 0 0 0 0 0
54189- 0 0 0 0 0 0 0 0 0 0 0 0
54190- 0 0 0 0 0 0 0 0 0 0 0 0
54191- 0 0 0 0 0 0 0 0 0 0 0 0
54192- 0 0 0 0 0 0 0 0 0 0 0 0
54193- 0 0 0 0 0 0 0 0 0 0 0 0
54194- 0 0 0 0 0 0 0 0 0 0 0 0
54195- 6 6 6 18 18 18 46 46 46 90 90 90
54196- 46 46 46 18 18 18 6 6 6 182 182 182
54197-253 253 253 246 246 246 206 206 206 190 190 190
54198-190 190 190 190 190 190 190 190 190 190 190 190
54199-206 206 206 231 231 231 250 250 250 253 253 253
54200-253 253 253 253 253 253 253 253 253 253 253 253
54201-202 202 202 14 14 14 2 2 6 2 2 6
54202- 2 2 6 2 2 6 2 2 6 2 2 6
54203- 42 42 42 86 86 86 42 42 42 18 18 18
54204- 6 6 6 0 0 0 0 0 0 0 0 0
54205- 0 0 0 0 0 0 0 0 0 0 0 0
54206- 0 0 0 0 0 0 0 0 0 0 0 0
54207- 0 0 0 0 0 0 0 0 0 0 0 0
54208- 0 0 0 0 0 0 0 0 0 0 0 0
54209- 0 0 0 0 0 0 0 0 0 0 0 0
54210- 0 0 0 0 0 0 0 0 0 0 0 0
54211- 0 0 0 0 0 0 0 0 0 0 0 0
54212- 0 0 0 0 0 0 0 0 0 0 0 0
54213- 0 0 0 0 0 0 0 0 0 0 0 0
54214- 0 0 0 0 0 0 0 0 0 6 6 6
54215- 14 14 14 38 38 38 74 74 74 66 66 66
54216- 2 2 6 6 6 6 90 90 90 250 250 250
54217-253 253 253 253 253 253 238 238 238 198 198 198
54218-190 190 190 190 190 190 195 195 195 221 221 221
54219-246 246 246 253 253 253 253 253 253 253 253 253
54220-253 253 253 253 253 253 253 253 253 253 253 253
54221-253 253 253 82 82 82 2 2 6 2 2 6
54222- 2 2 6 2 2 6 2 2 6 2 2 6
54223- 2 2 6 78 78 78 70 70 70 34 34 34
54224- 14 14 14 6 6 6 0 0 0 0 0 0
54225- 0 0 0 0 0 0 0 0 0 0 0 0
54226- 0 0 0 0 0 0 0 0 0 0 0 0
54227- 0 0 0 0 0 0 0 0 0 0 0 0
54228- 0 0 0 0 0 0 0 0 0 0 0 0
54229- 0 0 0 0 0 0 0 0 0 0 0 0
54230- 0 0 0 0 0 0 0 0 0 0 0 0
54231- 0 0 0 0 0 0 0 0 0 0 0 0
54232- 0 0 0 0 0 0 0 0 0 0 0 0
54233- 0 0 0 0 0 0 0 0 0 0 0 0
54234- 0 0 0 0 0 0 0 0 0 14 14 14
54235- 34 34 34 66 66 66 78 78 78 6 6 6
54236- 2 2 6 18 18 18 218 218 218 253 253 253
54237-253 253 253 253 253 253 253 253 253 246 246 246
54238-226 226 226 231 231 231 246 246 246 253 253 253
54239-253 253 253 253 253 253 253 253 253 253 253 253
54240-253 253 253 253 253 253 253 253 253 253 253 253
54241-253 253 253 178 178 178 2 2 6 2 2 6
54242- 2 2 6 2 2 6 2 2 6 2 2 6
54243- 2 2 6 18 18 18 90 90 90 62 62 62
54244- 30 30 30 10 10 10 0 0 0 0 0 0
54245- 0 0 0 0 0 0 0 0 0 0 0 0
54246- 0 0 0 0 0 0 0 0 0 0 0 0
54247- 0 0 0 0 0 0 0 0 0 0 0 0
54248- 0 0 0 0 0 0 0 0 0 0 0 0
54249- 0 0 0 0 0 0 0 0 0 0 0 0
54250- 0 0 0 0 0 0 0 0 0 0 0 0
54251- 0 0 0 0 0 0 0 0 0 0 0 0
54252- 0 0 0 0 0 0 0 0 0 0 0 0
54253- 0 0 0 0 0 0 0 0 0 0 0 0
54254- 0 0 0 0 0 0 10 10 10 26 26 26
54255- 58 58 58 90 90 90 18 18 18 2 2 6
54256- 2 2 6 110 110 110 253 253 253 253 253 253
54257-253 253 253 253 253 253 253 253 253 253 253 253
54258-250 250 250 253 253 253 253 253 253 253 253 253
54259-253 253 253 253 253 253 253 253 253 253 253 253
54260-253 253 253 253 253 253 253 253 253 253 253 253
54261-253 253 253 231 231 231 18 18 18 2 2 6
54262- 2 2 6 2 2 6 2 2 6 2 2 6
54263- 2 2 6 2 2 6 18 18 18 94 94 94
54264- 54 54 54 26 26 26 10 10 10 0 0 0
54265- 0 0 0 0 0 0 0 0 0 0 0 0
54266- 0 0 0 0 0 0 0 0 0 0 0 0
54267- 0 0 0 0 0 0 0 0 0 0 0 0
54268- 0 0 0 0 0 0 0 0 0 0 0 0
54269- 0 0 0 0 0 0 0 0 0 0 0 0
54270- 0 0 0 0 0 0 0 0 0 0 0 0
54271- 0 0 0 0 0 0 0 0 0 0 0 0
54272- 0 0 0 0 0 0 0 0 0 0 0 0
54273- 0 0 0 0 0 0 0 0 0 0 0 0
54274- 0 0 0 6 6 6 22 22 22 50 50 50
54275- 90 90 90 26 26 26 2 2 6 2 2 6
54276- 14 14 14 195 195 195 250 250 250 253 253 253
54277-253 253 253 253 253 253 253 253 253 253 253 253
54278-253 253 253 253 253 253 253 253 253 253 253 253
54279-253 253 253 253 253 253 253 253 253 253 253 253
54280-253 253 253 253 253 253 253 253 253 253 253 253
54281-250 250 250 242 242 242 54 54 54 2 2 6
54282- 2 2 6 2 2 6 2 2 6 2 2 6
54283- 2 2 6 2 2 6 2 2 6 38 38 38
54284- 86 86 86 50 50 50 22 22 22 6 6 6
54285- 0 0 0 0 0 0 0 0 0 0 0 0
54286- 0 0 0 0 0 0 0 0 0 0 0 0
54287- 0 0 0 0 0 0 0 0 0 0 0 0
54288- 0 0 0 0 0 0 0 0 0 0 0 0
54289- 0 0 0 0 0 0 0 0 0 0 0 0
54290- 0 0 0 0 0 0 0 0 0 0 0 0
54291- 0 0 0 0 0 0 0 0 0 0 0 0
54292- 0 0 0 0 0 0 0 0 0 0 0 0
54293- 0 0 0 0 0 0 0 0 0 0 0 0
54294- 6 6 6 14 14 14 38 38 38 82 82 82
54295- 34 34 34 2 2 6 2 2 6 2 2 6
54296- 42 42 42 195 195 195 246 246 246 253 253 253
54297-253 253 253 253 253 253 253 253 253 250 250 250
54298-242 242 242 242 242 242 250 250 250 253 253 253
54299-253 253 253 253 253 253 253 253 253 253 253 253
54300-253 253 253 250 250 250 246 246 246 238 238 238
54301-226 226 226 231 231 231 101 101 101 6 6 6
54302- 2 2 6 2 2 6 2 2 6 2 2 6
54303- 2 2 6 2 2 6 2 2 6 2 2 6
54304- 38 38 38 82 82 82 42 42 42 14 14 14
54305- 6 6 6 0 0 0 0 0 0 0 0 0
54306- 0 0 0 0 0 0 0 0 0 0 0 0
54307- 0 0 0 0 0 0 0 0 0 0 0 0
54308- 0 0 0 0 0 0 0 0 0 0 0 0
54309- 0 0 0 0 0 0 0 0 0 0 0 0
54310- 0 0 0 0 0 0 0 0 0 0 0 0
54311- 0 0 0 0 0 0 0 0 0 0 0 0
54312- 0 0 0 0 0 0 0 0 0 0 0 0
54313- 0 0 0 0 0 0 0 0 0 0 0 0
54314- 10 10 10 26 26 26 62 62 62 66 66 66
54315- 2 2 6 2 2 6 2 2 6 6 6 6
54316- 70 70 70 170 170 170 206 206 206 234 234 234
54317-246 246 246 250 250 250 250 250 250 238 238 238
54318-226 226 226 231 231 231 238 238 238 250 250 250
54319-250 250 250 250 250 250 246 246 246 231 231 231
54320-214 214 214 206 206 206 202 202 202 202 202 202
54321-198 198 198 202 202 202 182 182 182 18 18 18
54322- 2 2 6 2 2 6 2 2 6 2 2 6
54323- 2 2 6 2 2 6 2 2 6 2 2 6
54324- 2 2 6 62 62 62 66 66 66 30 30 30
54325- 10 10 10 0 0 0 0 0 0 0 0 0
54326- 0 0 0 0 0 0 0 0 0 0 0 0
54327- 0 0 0 0 0 0 0 0 0 0 0 0
54328- 0 0 0 0 0 0 0 0 0 0 0 0
54329- 0 0 0 0 0 0 0 0 0 0 0 0
54330- 0 0 0 0 0 0 0 0 0 0 0 0
54331- 0 0 0 0 0 0 0 0 0 0 0 0
54332- 0 0 0 0 0 0 0 0 0 0 0 0
54333- 0 0 0 0 0 0 0 0 0 0 0 0
54334- 14 14 14 42 42 42 82 82 82 18 18 18
54335- 2 2 6 2 2 6 2 2 6 10 10 10
54336- 94 94 94 182 182 182 218 218 218 242 242 242
54337-250 250 250 253 253 253 253 253 253 250 250 250
54338-234 234 234 253 253 253 253 253 253 253 253 253
54339-253 253 253 253 253 253 253 253 253 246 246 246
54340-238 238 238 226 226 226 210 210 210 202 202 202
54341-195 195 195 195 195 195 210 210 210 158 158 158
54342- 6 6 6 14 14 14 50 50 50 14 14 14
54343- 2 2 6 2 2 6 2 2 6 2 2 6
54344- 2 2 6 6 6 6 86 86 86 46 46 46
54345- 18 18 18 6 6 6 0 0 0 0 0 0
54346- 0 0 0 0 0 0 0 0 0 0 0 0
54347- 0 0 0 0 0 0 0 0 0 0 0 0
54348- 0 0 0 0 0 0 0 0 0 0 0 0
54349- 0 0 0 0 0 0 0 0 0 0 0 0
54350- 0 0 0 0 0 0 0 0 0 0 0 0
54351- 0 0 0 0 0 0 0 0 0 0 0 0
54352- 0 0 0 0 0 0 0 0 0 0 0 0
54353- 0 0 0 0 0 0 0 0 0 6 6 6
54354- 22 22 22 54 54 54 70 70 70 2 2 6
54355- 2 2 6 10 10 10 2 2 6 22 22 22
54356-166 166 166 231 231 231 250 250 250 253 253 253
54357-253 253 253 253 253 253 253 253 253 250 250 250
54358-242 242 242 253 253 253 253 253 253 253 253 253
54359-253 253 253 253 253 253 253 253 253 253 253 253
54360-253 253 253 253 253 253 253 253 253 246 246 246
54361-231 231 231 206 206 206 198 198 198 226 226 226
54362- 94 94 94 2 2 6 6 6 6 38 38 38
54363- 30 30 30 2 2 6 2 2 6 2 2 6
54364- 2 2 6 2 2 6 62 62 62 66 66 66
54365- 26 26 26 10 10 10 0 0 0 0 0 0
54366- 0 0 0 0 0 0 0 0 0 0 0 0
54367- 0 0 0 0 0 0 0 0 0 0 0 0
54368- 0 0 0 0 0 0 0 0 0 0 0 0
54369- 0 0 0 0 0 0 0 0 0 0 0 0
54370- 0 0 0 0 0 0 0 0 0 0 0 0
54371- 0 0 0 0 0 0 0 0 0 0 0 0
54372- 0 0 0 0 0 0 0 0 0 0 0 0
54373- 0 0 0 0 0 0 0 0 0 10 10 10
54374- 30 30 30 74 74 74 50 50 50 2 2 6
54375- 26 26 26 26 26 26 2 2 6 106 106 106
54376-238 238 238 253 253 253 253 253 253 253 253 253
54377-253 253 253 253 253 253 253 253 253 253 253 253
54378-253 253 253 253 253 253 253 253 253 253 253 253
54379-253 253 253 253 253 253 253 253 253 253 253 253
54380-253 253 253 253 253 253 253 253 253 253 253 253
54381-253 253 253 246 246 246 218 218 218 202 202 202
54382-210 210 210 14 14 14 2 2 6 2 2 6
54383- 30 30 30 22 22 22 2 2 6 2 2 6
54384- 2 2 6 2 2 6 18 18 18 86 86 86
54385- 42 42 42 14 14 14 0 0 0 0 0 0
54386- 0 0 0 0 0 0 0 0 0 0 0 0
54387- 0 0 0 0 0 0 0 0 0 0 0 0
54388- 0 0 0 0 0 0 0 0 0 0 0 0
54389- 0 0 0 0 0 0 0 0 0 0 0 0
54390- 0 0 0 0 0 0 0 0 0 0 0 0
54391- 0 0 0 0 0 0 0 0 0 0 0 0
54392- 0 0 0 0 0 0 0 0 0 0 0 0
54393- 0 0 0 0 0 0 0 0 0 14 14 14
54394- 42 42 42 90 90 90 22 22 22 2 2 6
54395- 42 42 42 2 2 6 18 18 18 218 218 218
54396-253 253 253 253 253 253 253 253 253 253 253 253
54397-253 253 253 253 253 253 253 253 253 253 253 253
54398-253 253 253 253 253 253 253 253 253 253 253 253
54399-253 253 253 253 253 253 253 253 253 253 253 253
54400-253 253 253 253 253 253 253 253 253 253 253 253
54401-253 253 253 253 253 253 250 250 250 221 221 221
54402-218 218 218 101 101 101 2 2 6 14 14 14
54403- 18 18 18 38 38 38 10 10 10 2 2 6
54404- 2 2 6 2 2 6 2 2 6 78 78 78
54405- 58 58 58 22 22 22 6 6 6 0 0 0
54406- 0 0 0 0 0 0 0 0 0 0 0 0
54407- 0 0 0 0 0 0 0 0 0 0 0 0
54408- 0 0 0 0 0 0 0 0 0 0 0 0
54409- 0 0 0 0 0 0 0 0 0 0 0 0
54410- 0 0 0 0 0 0 0 0 0 0 0 0
54411- 0 0 0 0 0 0 0 0 0 0 0 0
54412- 0 0 0 0 0 0 0 0 0 0 0 0
54413- 0 0 0 0 0 0 6 6 6 18 18 18
54414- 54 54 54 82 82 82 2 2 6 26 26 26
54415- 22 22 22 2 2 6 123 123 123 253 253 253
54416-253 253 253 253 253 253 253 253 253 253 253 253
54417-253 253 253 253 253 253 253 253 253 253 253 253
54418-253 253 253 253 253 253 253 253 253 253 253 253
54419-253 253 253 253 253 253 253 253 253 253 253 253
54420-253 253 253 253 253 253 253 253 253 253 253 253
54421-253 253 253 253 253 253 253 253 253 250 250 250
54422-238 238 238 198 198 198 6 6 6 38 38 38
54423- 58 58 58 26 26 26 38 38 38 2 2 6
54424- 2 2 6 2 2 6 2 2 6 46 46 46
54425- 78 78 78 30 30 30 10 10 10 0 0 0
54426- 0 0 0 0 0 0 0 0 0 0 0 0
54427- 0 0 0 0 0 0 0 0 0 0 0 0
54428- 0 0 0 0 0 0 0 0 0 0 0 0
54429- 0 0 0 0 0 0 0 0 0 0 0 0
54430- 0 0 0 0 0 0 0 0 0 0 0 0
54431- 0 0 0 0 0 0 0 0 0 0 0 0
54432- 0 0 0 0 0 0 0 0 0 0 0 0
54433- 0 0 0 0 0 0 10 10 10 30 30 30
54434- 74 74 74 58 58 58 2 2 6 42 42 42
54435- 2 2 6 22 22 22 231 231 231 253 253 253
54436-253 253 253 253 253 253 253 253 253 253 253 253
54437-253 253 253 253 253 253 253 253 253 250 250 250
54438-253 253 253 253 253 253 253 253 253 253 253 253
54439-253 253 253 253 253 253 253 253 253 253 253 253
54440-253 253 253 253 253 253 253 253 253 253 253 253
54441-253 253 253 253 253 253 253 253 253 253 253 253
54442-253 253 253 246 246 246 46 46 46 38 38 38
54443- 42 42 42 14 14 14 38 38 38 14 14 14
54444- 2 2 6 2 2 6 2 2 6 6 6 6
54445- 86 86 86 46 46 46 14 14 14 0 0 0
54446- 0 0 0 0 0 0 0 0 0 0 0 0
54447- 0 0 0 0 0 0 0 0 0 0 0 0
54448- 0 0 0 0 0 0 0 0 0 0 0 0
54449- 0 0 0 0 0 0 0 0 0 0 0 0
54450- 0 0 0 0 0 0 0 0 0 0 0 0
54451- 0 0 0 0 0 0 0 0 0 0 0 0
54452- 0 0 0 0 0 0 0 0 0 0 0 0
54453- 0 0 0 6 6 6 14 14 14 42 42 42
54454- 90 90 90 18 18 18 18 18 18 26 26 26
54455- 2 2 6 116 116 116 253 253 253 253 253 253
54456-253 253 253 253 253 253 253 253 253 253 253 253
54457-253 253 253 253 253 253 250 250 250 238 238 238
54458-253 253 253 253 253 253 253 253 253 253 253 253
54459-253 253 253 253 253 253 253 253 253 253 253 253
54460-253 253 253 253 253 253 253 253 253 253 253 253
54461-253 253 253 253 253 253 253 253 253 253 253 253
54462-253 253 253 253 253 253 94 94 94 6 6 6
54463- 2 2 6 2 2 6 10 10 10 34 34 34
54464- 2 2 6 2 2 6 2 2 6 2 2 6
54465- 74 74 74 58 58 58 22 22 22 6 6 6
54466- 0 0 0 0 0 0 0 0 0 0 0 0
54467- 0 0 0 0 0 0 0 0 0 0 0 0
54468- 0 0 0 0 0 0 0 0 0 0 0 0
54469- 0 0 0 0 0 0 0 0 0 0 0 0
54470- 0 0 0 0 0 0 0 0 0 0 0 0
54471- 0 0 0 0 0 0 0 0 0 0 0 0
54472- 0 0 0 0 0 0 0 0 0 0 0 0
54473- 0 0 0 10 10 10 26 26 26 66 66 66
54474- 82 82 82 2 2 6 38 38 38 6 6 6
54475- 14 14 14 210 210 210 253 253 253 253 253 253
54476-253 253 253 253 253 253 253 253 253 253 253 253
54477-253 253 253 253 253 253 246 246 246 242 242 242
54478-253 253 253 253 253 253 253 253 253 253 253 253
54479-253 253 253 253 253 253 253 253 253 253 253 253
54480-253 253 253 253 253 253 253 253 253 253 253 253
54481-253 253 253 253 253 253 253 253 253 253 253 253
54482-253 253 253 253 253 253 144 144 144 2 2 6
54483- 2 2 6 2 2 6 2 2 6 46 46 46
54484- 2 2 6 2 2 6 2 2 6 2 2 6
54485- 42 42 42 74 74 74 30 30 30 10 10 10
54486- 0 0 0 0 0 0 0 0 0 0 0 0
54487- 0 0 0 0 0 0 0 0 0 0 0 0
54488- 0 0 0 0 0 0 0 0 0 0 0 0
54489- 0 0 0 0 0 0 0 0 0 0 0 0
54490- 0 0 0 0 0 0 0 0 0 0 0 0
54491- 0 0 0 0 0 0 0 0 0 0 0 0
54492- 0 0 0 0 0 0 0 0 0 0 0 0
54493- 6 6 6 14 14 14 42 42 42 90 90 90
54494- 26 26 26 6 6 6 42 42 42 2 2 6
54495- 74 74 74 250 250 250 253 253 253 253 253 253
54496-253 253 253 253 253 253 253 253 253 253 253 253
54497-253 253 253 253 253 253 242 242 242 242 242 242
54498-253 253 253 253 253 253 253 253 253 253 253 253
54499-253 253 253 253 253 253 253 253 253 253 253 253
54500-253 253 253 253 253 253 253 253 253 253 253 253
54501-253 253 253 253 253 253 253 253 253 253 253 253
54502-253 253 253 253 253 253 182 182 182 2 2 6
54503- 2 2 6 2 2 6 2 2 6 46 46 46
54504- 2 2 6 2 2 6 2 2 6 2 2 6
54505- 10 10 10 86 86 86 38 38 38 10 10 10
54506- 0 0 0 0 0 0 0 0 0 0 0 0
54507- 0 0 0 0 0 0 0 0 0 0 0 0
54508- 0 0 0 0 0 0 0 0 0 0 0 0
54509- 0 0 0 0 0 0 0 0 0 0 0 0
54510- 0 0 0 0 0 0 0 0 0 0 0 0
54511- 0 0 0 0 0 0 0 0 0 0 0 0
54512- 0 0 0 0 0 0 0 0 0 0 0 0
54513- 10 10 10 26 26 26 66 66 66 82 82 82
54514- 2 2 6 22 22 22 18 18 18 2 2 6
54515-149 149 149 253 253 253 253 253 253 253 253 253
54516-253 253 253 253 253 253 253 253 253 253 253 253
54517-253 253 253 253 253 253 234 234 234 242 242 242
54518-253 253 253 253 253 253 253 253 253 253 253 253
54519-253 253 253 253 253 253 253 253 253 253 253 253
54520-253 253 253 253 253 253 253 253 253 253 253 253
54521-253 253 253 253 253 253 253 253 253 253 253 253
54522-253 253 253 253 253 253 206 206 206 2 2 6
54523- 2 2 6 2 2 6 2 2 6 38 38 38
54524- 2 2 6 2 2 6 2 2 6 2 2 6
54525- 6 6 6 86 86 86 46 46 46 14 14 14
54526- 0 0 0 0 0 0 0 0 0 0 0 0
54527- 0 0 0 0 0 0 0 0 0 0 0 0
54528- 0 0 0 0 0 0 0 0 0 0 0 0
54529- 0 0 0 0 0 0 0 0 0 0 0 0
54530- 0 0 0 0 0 0 0 0 0 0 0 0
54531- 0 0 0 0 0 0 0 0 0 0 0 0
54532- 0 0 0 0 0 0 0 0 0 6 6 6
54533- 18 18 18 46 46 46 86 86 86 18 18 18
54534- 2 2 6 34 34 34 10 10 10 6 6 6
54535-210 210 210 253 253 253 253 253 253 253 253 253
54536-253 253 253 253 253 253 253 253 253 253 253 253
54537-253 253 253 253 253 253 234 234 234 242 242 242
54538-253 253 253 253 253 253 253 253 253 253 253 253
54539-253 253 253 253 253 253 253 253 253 253 253 253
54540-253 253 253 253 253 253 253 253 253 253 253 253
54541-253 253 253 253 253 253 253 253 253 253 253 253
54542-253 253 253 253 253 253 221 221 221 6 6 6
54543- 2 2 6 2 2 6 6 6 6 30 30 30
54544- 2 2 6 2 2 6 2 2 6 2 2 6
54545- 2 2 6 82 82 82 54 54 54 18 18 18
54546- 6 6 6 0 0 0 0 0 0 0 0 0
54547- 0 0 0 0 0 0 0 0 0 0 0 0
54548- 0 0 0 0 0 0 0 0 0 0 0 0
54549- 0 0 0 0 0 0 0 0 0 0 0 0
54550- 0 0 0 0 0 0 0 0 0 0 0 0
54551- 0 0 0 0 0 0 0 0 0 0 0 0
54552- 0 0 0 0 0 0 0 0 0 10 10 10
54553- 26 26 26 66 66 66 62 62 62 2 2 6
54554- 2 2 6 38 38 38 10 10 10 26 26 26
54555-238 238 238 253 253 253 253 253 253 253 253 253
54556-253 253 253 253 253 253 253 253 253 253 253 253
54557-253 253 253 253 253 253 231 231 231 238 238 238
54558-253 253 253 253 253 253 253 253 253 253 253 253
54559-253 253 253 253 253 253 253 253 253 253 253 253
54560-253 253 253 253 253 253 253 253 253 253 253 253
54561-253 253 253 253 253 253 253 253 253 253 253 253
54562-253 253 253 253 253 253 231 231 231 6 6 6
54563- 2 2 6 2 2 6 10 10 10 30 30 30
54564- 2 2 6 2 2 6 2 2 6 2 2 6
54565- 2 2 6 66 66 66 58 58 58 22 22 22
54566- 6 6 6 0 0 0 0 0 0 0 0 0
54567- 0 0 0 0 0 0 0 0 0 0 0 0
54568- 0 0 0 0 0 0 0 0 0 0 0 0
54569- 0 0 0 0 0 0 0 0 0 0 0 0
54570- 0 0 0 0 0 0 0 0 0 0 0 0
54571- 0 0 0 0 0 0 0 0 0 0 0 0
54572- 0 0 0 0 0 0 0 0 0 10 10 10
54573- 38 38 38 78 78 78 6 6 6 2 2 6
54574- 2 2 6 46 46 46 14 14 14 42 42 42
54575-246 246 246 253 253 253 253 253 253 253 253 253
54576-253 253 253 253 253 253 253 253 253 253 253 253
54577-253 253 253 253 253 253 231 231 231 242 242 242
54578-253 253 253 253 253 253 253 253 253 253 253 253
54579-253 253 253 253 253 253 253 253 253 253 253 253
54580-253 253 253 253 253 253 253 253 253 253 253 253
54581-253 253 253 253 253 253 253 253 253 253 253 253
54582-253 253 253 253 253 253 234 234 234 10 10 10
54583- 2 2 6 2 2 6 22 22 22 14 14 14
54584- 2 2 6 2 2 6 2 2 6 2 2 6
54585- 2 2 6 66 66 66 62 62 62 22 22 22
54586- 6 6 6 0 0 0 0 0 0 0 0 0
54587- 0 0 0 0 0 0 0 0 0 0 0 0
54588- 0 0 0 0 0 0 0 0 0 0 0 0
54589- 0 0 0 0 0 0 0 0 0 0 0 0
54590- 0 0 0 0 0 0 0 0 0 0 0 0
54591- 0 0 0 0 0 0 0 0 0 0 0 0
54592- 0 0 0 0 0 0 6 6 6 18 18 18
54593- 50 50 50 74 74 74 2 2 6 2 2 6
54594- 14 14 14 70 70 70 34 34 34 62 62 62
54595-250 250 250 253 253 253 253 253 253 253 253 253
54596-253 253 253 253 253 253 253 253 253 253 253 253
54597-253 253 253 253 253 253 231 231 231 246 246 246
54598-253 253 253 253 253 253 253 253 253 253 253 253
54599-253 253 253 253 253 253 253 253 253 253 253 253
54600-253 253 253 253 253 253 253 253 253 253 253 253
54601-253 253 253 253 253 253 253 253 253 253 253 253
54602-253 253 253 253 253 253 234 234 234 14 14 14
54603- 2 2 6 2 2 6 30 30 30 2 2 6
54604- 2 2 6 2 2 6 2 2 6 2 2 6
54605- 2 2 6 66 66 66 62 62 62 22 22 22
54606- 6 6 6 0 0 0 0 0 0 0 0 0
54607- 0 0 0 0 0 0 0 0 0 0 0 0
54608- 0 0 0 0 0 0 0 0 0 0 0 0
54609- 0 0 0 0 0 0 0 0 0 0 0 0
54610- 0 0 0 0 0 0 0 0 0 0 0 0
54611- 0 0 0 0 0 0 0 0 0 0 0 0
54612- 0 0 0 0 0 0 6 6 6 18 18 18
54613- 54 54 54 62 62 62 2 2 6 2 2 6
54614- 2 2 6 30 30 30 46 46 46 70 70 70
54615-250 250 250 253 253 253 253 253 253 253 253 253
54616-253 253 253 253 253 253 253 253 253 253 253 253
54617-253 253 253 253 253 253 231 231 231 246 246 246
54618-253 253 253 253 253 253 253 253 253 253 253 253
54619-253 253 253 253 253 253 253 253 253 253 253 253
54620-253 253 253 253 253 253 253 253 253 253 253 253
54621-253 253 253 253 253 253 253 253 253 253 253 253
54622-253 253 253 253 253 253 226 226 226 10 10 10
54623- 2 2 6 6 6 6 30 30 30 2 2 6
54624- 2 2 6 2 2 6 2 2 6 2 2 6
54625- 2 2 6 66 66 66 58 58 58 22 22 22
54626- 6 6 6 0 0 0 0 0 0 0 0 0
54627- 0 0 0 0 0 0 0 0 0 0 0 0
54628- 0 0 0 0 0 0 0 0 0 0 0 0
54629- 0 0 0 0 0 0 0 0 0 0 0 0
54630- 0 0 0 0 0 0 0 0 0 0 0 0
54631- 0 0 0 0 0 0 0 0 0 0 0 0
54632- 0 0 0 0 0 0 6 6 6 22 22 22
54633- 58 58 58 62 62 62 2 2 6 2 2 6
54634- 2 2 6 2 2 6 30 30 30 78 78 78
54635-250 250 250 253 253 253 253 253 253 253 253 253
54636-253 253 253 253 253 253 253 253 253 253 253 253
54637-253 253 253 253 253 253 231 231 231 246 246 246
54638-253 253 253 253 253 253 253 253 253 253 253 253
54639-253 253 253 253 253 253 253 253 253 253 253 253
54640-253 253 253 253 253 253 253 253 253 253 253 253
54641-253 253 253 253 253 253 253 253 253 253 253 253
54642-253 253 253 253 253 253 206 206 206 2 2 6
54643- 22 22 22 34 34 34 18 14 6 22 22 22
54644- 26 26 26 18 18 18 6 6 6 2 2 6
54645- 2 2 6 82 82 82 54 54 54 18 18 18
54646- 6 6 6 0 0 0 0 0 0 0 0 0
54647- 0 0 0 0 0 0 0 0 0 0 0 0
54648- 0 0 0 0 0 0 0 0 0 0 0 0
54649- 0 0 0 0 0 0 0 0 0 0 0 0
54650- 0 0 0 0 0 0 0 0 0 0 0 0
54651- 0 0 0 0 0 0 0 0 0 0 0 0
54652- 0 0 0 0 0 0 6 6 6 26 26 26
54653- 62 62 62 106 106 106 74 54 14 185 133 11
54654-210 162 10 121 92 8 6 6 6 62 62 62
54655-238 238 238 253 253 253 253 253 253 253 253 253
54656-253 253 253 253 253 253 253 253 253 253 253 253
54657-253 253 253 253 253 253 231 231 231 246 246 246
54658-253 253 253 253 253 253 253 253 253 253 253 253
54659-253 253 253 253 253 253 253 253 253 253 253 253
54660-253 253 253 253 253 253 253 253 253 253 253 253
54661-253 253 253 253 253 253 253 253 253 253 253 253
54662-253 253 253 253 253 253 158 158 158 18 18 18
54663- 14 14 14 2 2 6 2 2 6 2 2 6
54664- 6 6 6 18 18 18 66 66 66 38 38 38
54665- 6 6 6 94 94 94 50 50 50 18 18 18
54666- 6 6 6 0 0 0 0 0 0 0 0 0
54667- 0 0 0 0 0 0 0 0 0 0 0 0
54668- 0 0 0 0 0 0 0 0 0 0 0 0
54669- 0 0 0 0 0 0 0 0 0 0 0 0
54670- 0 0 0 0 0 0 0 0 0 0 0 0
54671- 0 0 0 0 0 0 0 0 0 6 6 6
54672- 10 10 10 10 10 10 18 18 18 38 38 38
54673- 78 78 78 142 134 106 216 158 10 242 186 14
54674-246 190 14 246 190 14 156 118 10 10 10 10
54675- 90 90 90 238 238 238 253 253 253 253 253 253
54676-253 253 253 253 253 253 253 253 253 253 253 253
54677-253 253 253 253 253 253 231 231 231 250 250 250
54678-253 253 253 253 253 253 253 253 253 253 253 253
54679-253 253 253 253 253 253 253 253 253 253 253 253
54680-253 253 253 253 253 253 253 253 253 253 253 253
54681-253 253 253 253 253 253 253 253 253 246 230 190
54682-238 204 91 238 204 91 181 142 44 37 26 9
54683- 2 2 6 2 2 6 2 2 6 2 2 6
54684- 2 2 6 2 2 6 38 38 38 46 46 46
54685- 26 26 26 106 106 106 54 54 54 18 18 18
54686- 6 6 6 0 0 0 0 0 0 0 0 0
54687- 0 0 0 0 0 0 0 0 0 0 0 0
54688- 0 0 0 0 0 0 0 0 0 0 0 0
54689- 0 0 0 0 0 0 0 0 0 0 0 0
54690- 0 0 0 0 0 0 0 0 0 0 0 0
54691- 0 0 0 6 6 6 14 14 14 22 22 22
54692- 30 30 30 38 38 38 50 50 50 70 70 70
54693-106 106 106 190 142 34 226 170 11 242 186 14
54694-246 190 14 246 190 14 246 190 14 154 114 10
54695- 6 6 6 74 74 74 226 226 226 253 253 253
54696-253 253 253 253 253 253 253 253 253 253 253 253
54697-253 253 253 253 253 253 231 231 231 250 250 250
54698-253 253 253 253 253 253 253 253 253 253 253 253
54699-253 253 253 253 253 253 253 253 253 253 253 253
54700-253 253 253 253 253 253 253 253 253 253 253 253
54701-253 253 253 253 253 253 253 253 253 228 184 62
54702-241 196 14 241 208 19 232 195 16 38 30 10
54703- 2 2 6 2 2 6 2 2 6 2 2 6
54704- 2 2 6 6 6 6 30 30 30 26 26 26
54705-203 166 17 154 142 90 66 66 66 26 26 26
54706- 6 6 6 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
54711- 6 6 6 18 18 18 38 38 38 58 58 58
54712- 78 78 78 86 86 86 101 101 101 123 123 123
54713-175 146 61 210 150 10 234 174 13 246 186 14
54714-246 190 14 246 190 14 246 190 14 238 190 10
54715-102 78 10 2 2 6 46 46 46 198 198 198
54716-253 253 253 253 253 253 253 253 253 253 253 253
54717-253 253 253 253 253 253 234 234 234 242 242 242
54718-253 253 253 253 253 253 253 253 253 253 253 253
54719-253 253 253 253 253 253 253 253 253 253 253 253
54720-253 253 253 253 253 253 253 253 253 253 253 253
54721-253 253 253 253 253 253 253 253 253 224 178 62
54722-242 186 14 241 196 14 210 166 10 22 18 6
54723- 2 2 6 2 2 6 2 2 6 2 2 6
54724- 2 2 6 2 2 6 6 6 6 121 92 8
54725-238 202 15 232 195 16 82 82 82 34 34 34
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 0 0 0 0 0 0 0 0 0
54731- 14 14 14 38 38 38 70 70 70 154 122 46
54732-190 142 34 200 144 11 197 138 11 197 138 11
54733-213 154 11 226 170 11 242 186 14 246 190 14
54734-246 190 14 246 190 14 246 190 14 246 190 14
54735-225 175 15 46 32 6 2 2 6 22 22 22
54736-158 158 158 250 250 250 253 253 253 253 253 253
54737-253 253 253 253 253 253 253 253 253 253 253 253
54738-253 253 253 253 253 253 253 253 253 253 253 253
54739-253 253 253 253 253 253 253 253 253 253 253 253
54740-253 253 253 253 253 253 253 253 253 253 253 253
54741-253 253 253 250 250 250 242 242 242 224 178 62
54742-239 182 13 236 186 11 213 154 11 46 32 6
54743- 2 2 6 2 2 6 2 2 6 2 2 6
54744- 2 2 6 2 2 6 61 42 6 225 175 15
54745-238 190 10 236 186 11 112 100 78 42 42 42
54746- 14 14 14 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- 22 22 22 54 54 54 154 122 46 213 154 11
54752-226 170 11 230 174 11 226 170 11 226 170 11
54753-236 178 12 242 186 14 246 190 14 246 190 14
54754-246 190 14 246 190 14 246 190 14 246 190 14
54755-241 196 14 184 144 12 10 10 10 2 2 6
54756- 6 6 6 116 116 116 242 242 242 253 253 253
54757-253 253 253 253 253 253 253 253 253 253 253 253
54758-253 253 253 253 253 253 253 253 253 253 253 253
54759-253 253 253 253 253 253 253 253 253 253 253 253
54760-253 253 253 253 253 253 253 253 253 253 253 253
54761-253 253 253 231 231 231 198 198 198 214 170 54
54762-236 178 12 236 178 12 210 150 10 137 92 6
54763- 18 14 6 2 2 6 2 2 6 2 2 6
54764- 6 6 6 70 47 6 200 144 11 236 178 12
54765-239 182 13 239 182 13 124 112 88 58 58 58
54766- 22 22 22 6 6 6 0 0 0 0 0 0
54767- 0 0 0 0 0 0 0 0 0 0 0 0
54768- 0 0 0 0 0 0 0 0 0 0 0 0
54769- 0 0 0 0 0 0 0 0 0 0 0 0
54770- 0 0 0 0 0 0 0 0 0 10 10 10
54771- 30 30 30 70 70 70 180 133 36 226 170 11
54772-239 182 13 242 186 14 242 186 14 246 186 14
54773-246 190 14 246 190 14 246 190 14 246 190 14
54774-246 190 14 246 190 14 246 190 14 246 190 14
54775-246 190 14 232 195 16 98 70 6 2 2 6
54776- 2 2 6 2 2 6 66 66 66 221 221 221
54777-253 253 253 253 253 253 253 253 253 253 253 253
54778-253 253 253 253 253 253 253 253 253 253 253 253
54779-253 253 253 253 253 253 253 253 253 253 253 253
54780-253 253 253 253 253 253 253 253 253 253 253 253
54781-253 253 253 206 206 206 198 198 198 214 166 58
54782-230 174 11 230 174 11 216 158 10 192 133 9
54783-163 110 8 116 81 8 102 78 10 116 81 8
54784-167 114 7 197 138 11 226 170 11 239 182 13
54785-242 186 14 242 186 14 162 146 94 78 78 78
54786- 34 34 34 14 14 14 6 6 6 0 0 0
54787- 0 0 0 0 0 0 0 0 0 0 0 0
54788- 0 0 0 0 0 0 0 0 0 0 0 0
54789- 0 0 0 0 0 0 0 0 0 0 0 0
54790- 0 0 0 0 0 0 0 0 0 6 6 6
54791- 30 30 30 78 78 78 190 142 34 226 170 11
54792-239 182 13 246 190 14 246 190 14 246 190 14
54793-246 190 14 246 190 14 246 190 14 246 190 14
54794-246 190 14 246 190 14 246 190 14 246 190 14
54795-246 190 14 241 196 14 203 166 17 22 18 6
54796- 2 2 6 2 2 6 2 2 6 38 38 38
54797-218 218 218 253 253 253 253 253 253 253 253 253
54798-253 253 253 253 253 253 253 253 253 253 253 253
54799-253 253 253 253 253 253 253 253 253 253 253 253
54800-253 253 253 253 253 253 253 253 253 253 253 253
54801-250 250 250 206 206 206 198 198 198 202 162 69
54802-226 170 11 236 178 12 224 166 10 210 150 10
54803-200 144 11 197 138 11 192 133 9 197 138 11
54804-210 150 10 226 170 11 242 186 14 246 190 14
54805-246 190 14 246 186 14 225 175 15 124 112 88
54806- 62 62 62 30 30 30 14 14 14 6 6 6
54807- 0 0 0 0 0 0 0 0 0 0 0 0
54808- 0 0 0 0 0 0 0 0 0 0 0 0
54809- 0 0 0 0 0 0 0 0 0 0 0 0
54810- 0 0 0 0 0 0 0 0 0 10 10 10
54811- 30 30 30 78 78 78 174 135 50 224 166 10
54812-239 182 13 246 190 14 246 190 14 246 190 14
54813-246 190 14 246 190 14 246 190 14 246 190 14
54814-246 190 14 246 190 14 246 190 14 246 190 14
54815-246 190 14 246 190 14 241 196 14 139 102 15
54816- 2 2 6 2 2 6 2 2 6 2 2 6
54817- 78 78 78 250 250 250 253 253 253 253 253 253
54818-253 253 253 253 253 253 253 253 253 253 253 253
54819-253 253 253 253 253 253 253 253 253 253 253 253
54820-253 253 253 253 253 253 253 253 253 253 253 253
54821-250 250 250 214 214 214 198 198 198 190 150 46
54822-219 162 10 236 178 12 234 174 13 224 166 10
54823-216 158 10 213 154 11 213 154 11 216 158 10
54824-226 170 11 239 182 13 246 190 14 246 190 14
54825-246 190 14 246 190 14 242 186 14 206 162 42
54826-101 101 101 58 58 58 30 30 30 14 14 14
54827- 6 6 6 0 0 0 0 0 0 0 0 0
54828- 0 0 0 0 0 0 0 0 0 0 0 0
54829- 0 0 0 0 0 0 0 0 0 0 0 0
54830- 0 0 0 0 0 0 0 0 0 10 10 10
54831- 30 30 30 74 74 74 174 135 50 216 158 10
54832-236 178 12 246 190 14 246 190 14 246 190 14
54833-246 190 14 246 190 14 246 190 14 246 190 14
54834-246 190 14 246 190 14 246 190 14 246 190 14
54835-246 190 14 246 190 14 241 196 14 226 184 13
54836- 61 42 6 2 2 6 2 2 6 2 2 6
54837- 22 22 22 238 238 238 253 253 253 253 253 253
54838-253 253 253 253 253 253 253 253 253 253 253 253
54839-253 253 253 253 253 253 253 253 253 253 253 253
54840-253 253 253 253 253 253 253 253 253 253 253 253
54841-253 253 253 226 226 226 187 187 187 180 133 36
54842-216 158 10 236 178 12 239 182 13 236 178 12
54843-230 174 11 226 170 11 226 170 11 230 174 11
54844-236 178 12 242 186 14 246 190 14 246 190 14
54845-246 190 14 246 190 14 246 186 14 239 182 13
54846-206 162 42 106 106 106 66 66 66 34 34 34
54847- 14 14 14 6 6 6 0 0 0 0 0 0
54848- 0 0 0 0 0 0 0 0 0 0 0 0
54849- 0 0 0 0 0 0 0 0 0 0 0 0
54850- 0 0 0 0 0 0 0 0 0 6 6 6
54851- 26 26 26 70 70 70 163 133 67 213 154 11
54852-236 178 12 246 190 14 246 190 14 246 190 14
54853-246 190 14 246 190 14 246 190 14 246 190 14
54854-246 190 14 246 190 14 246 190 14 246 190 14
54855-246 190 14 246 190 14 246 190 14 241 196 14
54856-190 146 13 18 14 6 2 2 6 2 2 6
54857- 46 46 46 246 246 246 253 253 253 253 253 253
54858-253 253 253 253 253 253 253 253 253 253 253 253
54859-253 253 253 253 253 253 253 253 253 253 253 253
54860-253 253 253 253 253 253 253 253 253 253 253 253
54861-253 253 253 221 221 221 86 86 86 156 107 11
54862-216 158 10 236 178 12 242 186 14 246 186 14
54863-242 186 14 239 182 13 239 182 13 242 186 14
54864-242 186 14 246 186 14 246 190 14 246 190 14
54865-246 190 14 246 190 14 246 190 14 246 190 14
54866-242 186 14 225 175 15 142 122 72 66 66 66
54867- 30 30 30 10 10 10 0 0 0 0 0 0
54868- 0 0 0 0 0 0 0 0 0 0 0 0
54869- 0 0 0 0 0 0 0 0 0 0 0 0
54870- 0 0 0 0 0 0 0 0 0 6 6 6
54871- 26 26 26 70 70 70 163 133 67 210 150 10
54872-236 178 12 246 190 14 246 190 14 246 190 14
54873-246 190 14 246 190 14 246 190 14 246 190 14
54874-246 190 14 246 190 14 246 190 14 246 190 14
54875-246 190 14 246 190 14 246 190 14 246 190 14
54876-232 195 16 121 92 8 34 34 34 106 106 106
54877-221 221 221 253 253 253 253 253 253 253 253 253
54878-253 253 253 253 253 253 253 253 253 253 253 253
54879-253 253 253 253 253 253 253 253 253 253 253 253
54880-253 253 253 253 253 253 253 253 253 253 253 253
54881-242 242 242 82 82 82 18 14 6 163 110 8
54882-216 158 10 236 178 12 242 186 14 246 190 14
54883-246 190 14 246 190 14 246 190 14 246 190 14
54884-246 190 14 246 190 14 246 190 14 246 190 14
54885-246 190 14 246 190 14 246 190 14 246 190 14
54886-246 190 14 246 190 14 242 186 14 163 133 67
54887- 46 46 46 18 18 18 6 6 6 0 0 0
54888- 0 0 0 0 0 0 0 0 0 0 0 0
54889- 0 0 0 0 0 0 0 0 0 0 0 0
54890- 0 0 0 0 0 0 0 0 0 10 10 10
54891- 30 30 30 78 78 78 163 133 67 210 150 10
54892-236 178 12 246 186 14 246 190 14 246 190 14
54893-246 190 14 246 190 14 246 190 14 246 190 14
54894-246 190 14 246 190 14 246 190 14 246 190 14
54895-246 190 14 246 190 14 246 190 14 246 190 14
54896-241 196 14 215 174 15 190 178 144 253 253 253
54897-253 253 253 253 253 253 253 253 253 253 253 253
54898-253 253 253 253 253 253 253 253 253 253 253 253
54899-253 253 253 253 253 253 253 253 253 253 253 253
54900-253 253 253 253 253 253 253 253 253 218 218 218
54901- 58 58 58 2 2 6 22 18 6 167 114 7
54902-216 158 10 236 178 12 246 186 14 246 190 14
54903-246 190 14 246 190 14 246 190 14 246 190 14
54904-246 190 14 246 190 14 246 190 14 246 190 14
54905-246 190 14 246 190 14 246 190 14 246 190 14
54906-246 190 14 246 186 14 242 186 14 190 150 46
54907- 54 54 54 22 22 22 6 6 6 0 0 0
54908- 0 0 0 0 0 0 0 0 0 0 0 0
54909- 0 0 0 0 0 0 0 0 0 0 0 0
54910- 0 0 0 0 0 0 0 0 0 14 14 14
54911- 38 38 38 86 86 86 180 133 36 213 154 11
54912-236 178 12 246 186 14 246 190 14 246 190 14
54913-246 190 14 246 190 14 246 190 14 246 190 14
54914-246 190 14 246 190 14 246 190 14 246 190 14
54915-246 190 14 246 190 14 246 190 14 246 190 14
54916-246 190 14 232 195 16 190 146 13 214 214 214
54917-253 253 253 253 253 253 253 253 253 253 253 253
54918-253 253 253 253 253 253 253 253 253 253 253 253
54919-253 253 253 253 253 253 253 253 253 253 253 253
54920-253 253 253 250 250 250 170 170 170 26 26 26
54921- 2 2 6 2 2 6 37 26 9 163 110 8
54922-219 162 10 239 182 13 246 186 14 246 190 14
54923-246 190 14 246 190 14 246 190 14 246 190 14
54924-246 190 14 246 190 14 246 190 14 246 190 14
54925-246 190 14 246 190 14 246 190 14 246 190 14
54926-246 186 14 236 178 12 224 166 10 142 122 72
54927- 46 46 46 18 18 18 6 6 6 0 0 0
54928- 0 0 0 0 0 0 0 0 0 0 0 0
54929- 0 0 0 0 0 0 0 0 0 0 0 0
54930- 0 0 0 0 0 0 6 6 6 18 18 18
54931- 50 50 50 109 106 95 192 133 9 224 166 10
54932-242 186 14 246 190 14 246 190 14 246 190 14
54933-246 190 14 246 190 14 246 190 14 246 190 14
54934-246 190 14 246 190 14 246 190 14 246 190 14
54935-246 190 14 246 190 14 246 190 14 246 190 14
54936-242 186 14 226 184 13 210 162 10 142 110 46
54937-226 226 226 253 253 253 253 253 253 253 253 253
54938-253 253 253 253 253 253 253 253 253 253 253 253
54939-253 253 253 253 253 253 253 253 253 253 253 253
54940-198 198 198 66 66 66 2 2 6 2 2 6
54941- 2 2 6 2 2 6 50 34 6 156 107 11
54942-219 162 10 239 182 13 246 186 14 246 190 14
54943-246 190 14 246 190 14 246 190 14 246 190 14
54944-246 190 14 246 190 14 246 190 14 246 190 14
54945-246 190 14 246 190 14 246 190 14 242 186 14
54946-234 174 13 213 154 11 154 122 46 66 66 66
54947- 30 30 30 10 10 10 0 0 0 0 0 0
54948- 0 0 0 0 0 0 0 0 0 0 0 0
54949- 0 0 0 0 0 0 0 0 0 0 0 0
54950- 0 0 0 0 0 0 6 6 6 22 22 22
54951- 58 58 58 154 121 60 206 145 10 234 174 13
54952-242 186 14 246 186 14 246 190 14 246 190 14
54953-246 190 14 246 190 14 246 190 14 246 190 14
54954-246 190 14 246 190 14 246 190 14 246 190 14
54955-246 190 14 246 190 14 246 190 14 246 190 14
54956-246 186 14 236 178 12 210 162 10 163 110 8
54957- 61 42 6 138 138 138 218 218 218 250 250 250
54958-253 253 253 253 253 253 253 253 253 250 250 250
54959-242 242 242 210 210 210 144 144 144 66 66 66
54960- 6 6 6 2 2 6 2 2 6 2 2 6
54961- 2 2 6 2 2 6 61 42 6 163 110 8
54962-216 158 10 236 178 12 246 190 14 246 190 14
54963-246 190 14 246 190 14 246 190 14 246 190 14
54964-246 190 14 246 190 14 246 190 14 246 190 14
54965-246 190 14 239 182 13 230 174 11 216 158 10
54966-190 142 34 124 112 88 70 70 70 38 38 38
54967- 18 18 18 6 6 6 0 0 0 0 0 0
54968- 0 0 0 0 0 0 0 0 0 0 0 0
54969- 0 0 0 0 0 0 0 0 0 0 0 0
54970- 0 0 0 0 0 0 6 6 6 22 22 22
54971- 62 62 62 168 124 44 206 145 10 224 166 10
54972-236 178 12 239 182 13 242 186 14 242 186 14
54973-246 186 14 246 190 14 246 190 14 246 190 14
54974-246 190 14 246 190 14 246 190 14 246 190 14
54975-246 190 14 246 190 14 246 190 14 246 190 14
54976-246 190 14 236 178 12 216 158 10 175 118 6
54977- 80 54 7 2 2 6 6 6 6 30 30 30
54978- 54 54 54 62 62 62 50 50 50 38 38 38
54979- 14 14 14 2 2 6 2 2 6 2 2 6
54980- 2 2 6 2 2 6 2 2 6 2 2 6
54981- 2 2 6 6 6 6 80 54 7 167 114 7
54982-213 154 11 236 178 12 246 190 14 246 190 14
54983-246 190 14 246 190 14 246 190 14 246 190 14
54984-246 190 14 242 186 14 239 182 13 239 182 13
54985-230 174 11 210 150 10 174 135 50 124 112 88
54986- 82 82 82 54 54 54 34 34 34 18 18 18
54987- 6 6 6 0 0 0 0 0 0 0 0 0
54988- 0 0 0 0 0 0 0 0 0 0 0 0
54989- 0 0 0 0 0 0 0 0 0 0 0 0
54990- 0 0 0 0 0 0 6 6 6 18 18 18
54991- 50 50 50 158 118 36 192 133 9 200 144 11
54992-216 158 10 219 162 10 224 166 10 226 170 11
54993-230 174 11 236 178 12 239 182 13 239 182 13
54994-242 186 14 246 186 14 246 190 14 246 190 14
54995-246 190 14 246 190 14 246 190 14 246 190 14
54996-246 186 14 230 174 11 210 150 10 163 110 8
54997-104 69 6 10 10 10 2 2 6 2 2 6
54998- 2 2 6 2 2 6 2 2 6 2 2 6
54999- 2 2 6 2 2 6 2 2 6 2 2 6
55000- 2 2 6 2 2 6 2 2 6 2 2 6
55001- 2 2 6 6 6 6 91 60 6 167 114 7
55002-206 145 10 230 174 11 242 186 14 246 190 14
55003-246 190 14 246 190 14 246 186 14 242 186 14
55004-239 182 13 230 174 11 224 166 10 213 154 11
55005-180 133 36 124 112 88 86 86 86 58 58 58
55006- 38 38 38 22 22 22 10 10 10 6 6 6
55007- 0 0 0 0 0 0 0 0 0 0 0 0
55008- 0 0 0 0 0 0 0 0 0 0 0 0
55009- 0 0 0 0 0 0 0 0 0 0 0 0
55010- 0 0 0 0 0 0 0 0 0 14 14 14
55011- 34 34 34 70 70 70 138 110 50 158 118 36
55012-167 114 7 180 123 7 192 133 9 197 138 11
55013-200 144 11 206 145 10 213 154 11 219 162 10
55014-224 166 10 230 174 11 239 182 13 242 186 14
55015-246 186 14 246 186 14 246 186 14 246 186 14
55016-239 182 13 216 158 10 185 133 11 152 99 6
55017-104 69 6 18 14 6 2 2 6 2 2 6
55018- 2 2 6 2 2 6 2 2 6 2 2 6
55019- 2 2 6 2 2 6 2 2 6 2 2 6
55020- 2 2 6 2 2 6 2 2 6 2 2 6
55021- 2 2 6 6 6 6 80 54 7 152 99 6
55022-192 133 9 219 162 10 236 178 12 239 182 13
55023-246 186 14 242 186 14 239 182 13 236 178 12
55024-224 166 10 206 145 10 192 133 9 154 121 60
55025- 94 94 94 62 62 62 42 42 42 22 22 22
55026- 14 14 14 6 6 6 0 0 0 0 0 0
55027- 0 0 0 0 0 0 0 0 0 0 0 0
55028- 0 0 0 0 0 0 0 0 0 0 0 0
55029- 0 0 0 0 0 0 0 0 0 0 0 0
55030- 0 0 0 0 0 0 0 0 0 6 6 6
55031- 18 18 18 34 34 34 58 58 58 78 78 78
55032-101 98 89 124 112 88 142 110 46 156 107 11
55033-163 110 8 167 114 7 175 118 6 180 123 7
55034-185 133 11 197 138 11 210 150 10 219 162 10
55035-226 170 11 236 178 12 236 178 12 234 174 13
55036-219 162 10 197 138 11 163 110 8 130 83 6
55037- 91 60 6 10 10 10 2 2 6 2 2 6
55038- 18 18 18 38 38 38 38 38 38 38 38 38
55039- 38 38 38 38 38 38 38 38 38 38 38 38
55040- 38 38 38 38 38 38 26 26 26 2 2 6
55041- 2 2 6 6 6 6 70 47 6 137 92 6
55042-175 118 6 200 144 11 219 162 10 230 174 11
55043-234 174 13 230 174 11 219 162 10 210 150 10
55044-192 133 9 163 110 8 124 112 88 82 82 82
55045- 50 50 50 30 30 30 14 14 14 6 6 6
55046- 0 0 0 0 0 0 0 0 0 0 0 0
55047- 0 0 0 0 0 0 0 0 0 0 0 0
55048- 0 0 0 0 0 0 0 0 0 0 0 0
55049- 0 0 0 0 0 0 0 0 0 0 0 0
55050- 0 0 0 0 0 0 0 0 0 0 0 0
55051- 6 6 6 14 14 14 22 22 22 34 34 34
55052- 42 42 42 58 58 58 74 74 74 86 86 86
55053-101 98 89 122 102 70 130 98 46 121 87 25
55054-137 92 6 152 99 6 163 110 8 180 123 7
55055-185 133 11 197 138 11 206 145 10 200 144 11
55056-180 123 7 156 107 11 130 83 6 104 69 6
55057- 50 34 6 54 54 54 110 110 110 101 98 89
55058- 86 86 86 82 82 82 78 78 78 78 78 78
55059- 78 78 78 78 78 78 78 78 78 78 78 78
55060- 78 78 78 82 82 82 86 86 86 94 94 94
55061-106 106 106 101 101 101 86 66 34 124 80 6
55062-156 107 11 180 123 7 192 133 9 200 144 11
55063-206 145 10 200 144 11 192 133 9 175 118 6
55064-139 102 15 109 106 95 70 70 70 42 42 42
55065- 22 22 22 10 10 10 0 0 0 0 0 0
55066- 0 0 0 0 0 0 0 0 0 0 0 0
55067- 0 0 0 0 0 0 0 0 0 0 0 0
55068- 0 0 0 0 0 0 0 0 0 0 0 0
55069- 0 0 0 0 0 0 0 0 0 0 0 0
55070- 0 0 0 0 0 0 0 0 0 0 0 0
55071- 0 0 0 0 0 0 6 6 6 10 10 10
55072- 14 14 14 22 22 22 30 30 30 38 38 38
55073- 50 50 50 62 62 62 74 74 74 90 90 90
55074-101 98 89 112 100 78 121 87 25 124 80 6
55075-137 92 6 152 99 6 152 99 6 152 99 6
55076-138 86 6 124 80 6 98 70 6 86 66 30
55077-101 98 89 82 82 82 58 58 58 46 46 46
55078- 38 38 38 34 34 34 34 34 34 34 34 34
55079- 34 34 34 34 34 34 34 34 34 34 34 34
55080- 34 34 34 34 34 34 38 38 38 42 42 42
55081- 54 54 54 82 82 82 94 86 76 91 60 6
55082-134 86 6 156 107 11 167 114 7 175 118 6
55083-175 118 6 167 114 7 152 99 6 121 87 25
55084-101 98 89 62 62 62 34 34 34 18 18 18
55085- 6 6 6 0 0 0 0 0 0 0 0 0
55086- 0 0 0 0 0 0 0 0 0 0 0 0
55087- 0 0 0 0 0 0 0 0 0 0 0 0
55088- 0 0 0 0 0 0 0 0 0 0 0 0
55089- 0 0 0 0 0 0 0 0 0 0 0 0
55090- 0 0 0 0 0 0 0 0 0 0 0 0
55091- 0 0 0 0 0 0 0 0 0 0 0 0
55092- 0 0 0 6 6 6 6 6 6 10 10 10
55093- 18 18 18 22 22 22 30 30 30 42 42 42
55094- 50 50 50 66 66 66 86 86 86 101 98 89
55095-106 86 58 98 70 6 104 69 6 104 69 6
55096-104 69 6 91 60 6 82 62 34 90 90 90
55097- 62 62 62 38 38 38 22 22 22 14 14 14
55098- 10 10 10 10 10 10 10 10 10 10 10 10
55099- 10 10 10 10 10 10 6 6 6 10 10 10
55100- 10 10 10 10 10 10 10 10 10 14 14 14
55101- 22 22 22 42 42 42 70 70 70 89 81 66
55102- 80 54 7 104 69 6 124 80 6 137 92 6
55103-134 86 6 116 81 8 100 82 52 86 86 86
55104- 58 58 58 30 30 30 14 14 14 6 6 6
55105- 0 0 0 0 0 0 0 0 0 0 0 0
55106- 0 0 0 0 0 0 0 0 0 0 0 0
55107- 0 0 0 0 0 0 0 0 0 0 0 0
55108- 0 0 0 0 0 0 0 0 0 0 0 0
55109- 0 0 0 0 0 0 0 0 0 0 0 0
55110- 0 0 0 0 0 0 0 0 0 0 0 0
55111- 0 0 0 0 0 0 0 0 0 0 0 0
55112- 0 0 0 0 0 0 0 0 0 0 0 0
55113- 0 0 0 6 6 6 10 10 10 14 14 14
55114- 18 18 18 26 26 26 38 38 38 54 54 54
55115- 70 70 70 86 86 86 94 86 76 89 81 66
55116- 89 81 66 86 86 86 74 74 74 50 50 50
55117- 30 30 30 14 14 14 6 6 6 0 0 0
55118- 0 0 0 0 0 0 0 0 0 0 0 0
55119- 0 0 0 0 0 0 0 0 0 0 0 0
55120- 0 0 0 0 0 0 0 0 0 0 0 0
55121- 6 6 6 18 18 18 34 34 34 58 58 58
55122- 82 82 82 89 81 66 89 81 66 89 81 66
55123- 94 86 66 94 86 76 74 74 74 50 50 50
55124- 26 26 26 14 14 14 6 6 6 0 0 0
55125- 0 0 0 0 0 0 0 0 0 0 0 0
55126- 0 0 0 0 0 0 0 0 0 0 0 0
55127- 0 0 0 0 0 0 0 0 0 0 0 0
55128- 0 0 0 0 0 0 0 0 0 0 0 0
55129- 0 0 0 0 0 0 0 0 0 0 0 0
55130- 0 0 0 0 0 0 0 0 0 0 0 0
55131- 0 0 0 0 0 0 0 0 0 0 0 0
55132- 0 0 0 0 0 0 0 0 0 0 0 0
55133- 0 0 0 0 0 0 0 0 0 0 0 0
55134- 6 6 6 6 6 6 14 14 14 18 18 18
55135- 30 30 30 38 38 38 46 46 46 54 54 54
55136- 50 50 50 42 42 42 30 30 30 18 18 18
55137- 10 10 10 0 0 0 0 0 0 0 0 0
55138- 0 0 0 0 0 0 0 0 0 0 0 0
55139- 0 0 0 0 0 0 0 0 0 0 0 0
55140- 0 0 0 0 0 0 0 0 0 0 0 0
55141- 0 0 0 6 6 6 14 14 14 26 26 26
55142- 38 38 38 50 50 50 58 58 58 58 58 58
55143- 54 54 54 42 42 42 30 30 30 18 18 18
55144- 10 10 10 0 0 0 0 0 0 0 0 0
55145- 0 0 0 0 0 0 0 0 0 0 0 0
55146- 0 0 0 0 0 0 0 0 0 0 0 0
55147- 0 0 0 0 0 0 0 0 0 0 0 0
55148- 0 0 0 0 0 0 0 0 0 0 0 0
55149- 0 0 0 0 0 0 0 0 0 0 0 0
55150- 0 0 0 0 0 0 0 0 0 0 0 0
55151- 0 0 0 0 0 0 0 0 0 0 0 0
55152- 0 0 0 0 0 0 0 0 0 0 0 0
55153- 0 0 0 0 0 0 0 0 0 0 0 0
55154- 0 0 0 0 0 0 0 0 0 6 6 6
55155- 6 6 6 10 10 10 14 14 14 18 18 18
55156- 18 18 18 14 14 14 10 10 10 6 6 6
55157- 0 0 0 0 0 0 0 0 0 0 0 0
55158- 0 0 0 0 0 0 0 0 0 0 0 0
55159- 0 0 0 0 0 0 0 0 0 0 0 0
55160- 0 0 0 0 0 0 0 0 0 0 0 0
55161- 0 0 0 0 0 0 0 0 0 6 6 6
55162- 14 14 14 18 18 18 22 22 22 22 22 22
55163- 18 18 18 14 14 14 10 10 10 6 6 6
55164- 0 0 0 0 0 0 0 0 0 0 0 0
55165- 0 0 0 0 0 0 0 0 0 0 0 0
55166- 0 0 0 0 0 0 0 0 0 0 0 0
55167- 0 0 0 0 0 0 0 0 0 0 0 0
55168- 0 0 0 0 0 0 0 0 0 0 0 0
55169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55182+4 4 4 4 4 4
55183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55196+4 4 4 4 4 4
55197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55210+4 4 4 4 4 4
55211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55224+4 4 4 4 4 4
55225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55238+4 4 4 4 4 4
55239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55252+4 4 4 4 4 4
55253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55257+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
55258+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
55262+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
55263+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55264+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
55265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55266+4 4 4 4 4 4
55267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55271+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
55272+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
55273+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55276+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
55277+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
55278+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
55279+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55280+4 4 4 4 4 4
55281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55285+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
55286+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
55287+0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
55290+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
55291+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
55292+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
55293+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
55294+4 4 4 4 4 4
55295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55298+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
55299+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
55300+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
55301+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 5 5 5 5 5 5
55304+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
55305+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
55306+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
55307+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
55308+4 4 4 4 4 4
55309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55312+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
55313+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
55314+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
55315+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
55316+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55317+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
55318+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
55319+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
55320+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
55321+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
55322+4 4 4 4 4 4
55323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55326+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
55327+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
55328+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
55329+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
55330+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55331+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
55332+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
55333+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
55334+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
55335+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
55336+4 4 4 4 4 4
55337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55339+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
55340+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
55341+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
55342+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
55343+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
55344+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
55345+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
55346+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
55347+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
55348+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
55349+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
55350+4 4 4 4 4 4
55351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55353+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
55354+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
55355+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
55356+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
55357+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
55358+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
55359+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
55360+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
55361+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
55362+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
55363+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
55364+4 4 4 4 4 4
55365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55367+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
55368+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
55369+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
55370+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
55371+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
55372+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
55373+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
55374+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
55375+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
55376+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
55377+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55378+4 4 4 4 4 4
55379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55381+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
55382+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
55383+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
55384+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
55385+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
55386+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
55387+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
55388+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
55389+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
55390+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
55391+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
55392+4 4 4 4 4 4
55393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55394+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
55395+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
55396+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
55397+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
55398+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
55399+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
55400+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
55401+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
55402+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
55403+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
55404+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
55405+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
55406+4 4 4 4 4 4
55407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55408+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
55409+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
55410+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
55411+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55412+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
55413+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
55414+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
55415+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
55416+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
55417+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
55418+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
55419+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
55420+0 0 0 4 4 4
55421+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55422+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
55423+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
55424+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
55425+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
55426+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
55427+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
55428+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
55429+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
55430+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
55431+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
55432+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
55433+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
55434+2 0 0 0 0 0
55435+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
55436+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
55437+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
55438+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
55439+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
55440+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
55441+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
55442+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
55443+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
55444+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
55445+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
55446+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
55447+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
55448+37 38 37 0 0 0
55449+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55450+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
55451+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
55452+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
55453+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
55454+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
55455+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55456+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55457+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55458+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55459+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55460+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55461+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55462+85 115 134 4 0 0
55463+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55464+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55465+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55466+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55467+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55468+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55469+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55470+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55471+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55472+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55473+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55474+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55475+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55476+60 73 81 4 0 0
55477+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55478+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55479+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55480+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55481+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55482+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55483+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55484+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55485+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55486+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55487+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55488+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55489+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55490+16 19 21 4 0 0
55491+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55492+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55493+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55494+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55495+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55496+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55497+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55498+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55499+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55500+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55501+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55502+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55503+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55504+4 0 0 4 3 3
55505+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55506+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55507+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55509+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55510+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55511+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55512+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55513+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55514+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55515+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55516+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55517+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55518+3 2 2 4 4 4
55519+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55520+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55521+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55522+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55523+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55524+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55525+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55526+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55527+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55528+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55529+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55530+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55531+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55532+4 4 4 4 4 4
55533+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55534+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55535+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55536+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55537+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55538+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55539+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55540+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55541+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55542+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55543+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55544+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55545+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55546+4 4 4 4 4 4
55547+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55548+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55549+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55550+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55551+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55552+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55553+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55554+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55555+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55556+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55557+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55558+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55559+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55560+5 5 5 5 5 5
55561+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55562+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55563+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55564+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55565+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55566+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55567+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55568+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55569+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55570+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55571+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55572+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55573+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55574+5 5 5 4 4 4
55575+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55576+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55577+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55578+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55579+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55580+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55581+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55582+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55583+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55584+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55585+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55586+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55588+4 4 4 4 4 4
55589+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55590+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55591+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55592+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55593+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55594+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55595+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55596+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55597+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55598+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55599+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55600+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55602+4 4 4 4 4 4
55603+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55604+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55605+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55606+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55607+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55608+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55609+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55610+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55611+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55612+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55613+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55616+4 4 4 4 4 4
55617+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55618+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55619+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55620+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55621+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55622+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55623+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55624+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55625+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55626+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55627+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55630+4 4 4 4 4 4
55631+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55632+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55633+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55634+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55635+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55636+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55637+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55638+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55639+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55640+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55641+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55644+4 4 4 4 4 4
55645+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55646+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55647+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55648+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55649+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55650+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55651+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55652+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55653+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55654+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55655+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55658+4 4 4 4 4 4
55659+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55660+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55661+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55662+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55663+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55664+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55665+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55666+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55667+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55668+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55669+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55672+4 4 4 4 4 4
55673+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55674+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55675+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55676+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55677+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55678+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55679+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55680+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55681+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55682+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55683+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55686+4 4 4 4 4 4
55687+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55688+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55689+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55690+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55691+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55692+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55693+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55694+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55695+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55696+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55697+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55700+4 4 4 4 4 4
55701+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55702+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55703+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55704+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55705+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55706+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55707+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55708+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55709+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55710+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55711+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55714+4 4 4 4 4 4
55715+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55716+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55717+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55718+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55719+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55720+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55721+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55722+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55723+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55724+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55725+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55728+4 4 4 4 4 4
55729+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55730+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55731+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55732+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55733+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55734+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55735+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55736+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55737+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55738+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55739+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55742+4 4 4 4 4 4
55743+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55744+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55745+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55746+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55747+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55748+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55749+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55750+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55751+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55752+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55753+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55756+4 4 4 4 4 4
55757+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55758+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55759+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55760+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55761+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55762+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55763+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55764+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55765+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55766+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55767+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55770+4 4 4 4 4 4
55771+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55772+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55773+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55774+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55775+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55776+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55777+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55778+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55779+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55780+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55781+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55784+4 4 4 4 4 4
55785+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55786+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55787+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55788+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55789+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55790+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55791+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55792+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55793+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55794+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55795+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
55798+4 4 4 4 4 4
55799+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55800+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55801+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55802+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55803+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55804+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55805+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55806+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55807+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55808+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55809+0 0 0 3 3 3 5 5 5 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 4 4 4
55812+4 4 4 4 4 4
55813+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55814+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55815+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55816+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55817+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55818+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55819+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55820+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55821+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55822+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55823+0 0 0 3 3 3 5 5 5 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 4 4 4
55827+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55828+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55829+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55830+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55831+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55832+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55833+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55834+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55835+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55836+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55837+0 0 0 3 3 3 5 5 5 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 4 4 4
55841+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55842+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55843+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55844+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55845+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55846+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55847+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55848+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55849+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55850+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55851+0 0 0 3 3 3 5 5 5 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
55855+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55856+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55857+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55858+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55859+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55860+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55861+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55862+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55863+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55864+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55865+0 0 0 3 3 3 5 5 5 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
55869+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55870+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55871+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55872+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55873+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55874+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55875+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55876+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55877+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55878+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55879+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55882+4 4 4 4 4 4
55883+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55884+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55885+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55886+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55887+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55888+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55889+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55890+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55891+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55892+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55893+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55896+4 4 4 4 4 4
55897+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55898+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55899+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55900+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55901+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55902+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55903+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55904+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55905+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55906+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55907+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55910+4 4 4 4 4 4
55911+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55912+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55913+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55914+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55915+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55916+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55917+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55918+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55919+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55920+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55921+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55924+4 4 4 4 4 4
55925+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55926+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55927+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55928+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55929+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55930+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55931+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55932+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55933+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55934+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55935+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55938+4 4 4 4 4 4
55939+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55940+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55941+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55942+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55943+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55944+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55945+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55946+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55947+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55948+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55949+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55952+4 4 4 4 4 4
55953+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55954+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55955+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55956+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55957+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55958+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55959+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55960+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55961+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55962+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55963+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55966+4 4 4 4 4 4
55967+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55968+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55969+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55970+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55971+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55972+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55973+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55974+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55975+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55976+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55977+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55980+4 4 4 4 4 4
55981+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55982+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55983+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55984+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55985+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55986+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55987+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55988+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55989+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55990+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55994+4 4 4 4 4 4
55995+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55996+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55997+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55998+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55999+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
56000+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
56001+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
56002+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
56003+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
56004+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
56005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56008+4 4 4 4 4 4
56009+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
56010+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
56011+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
56012+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
56013+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
56014+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
56015+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
56016+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
56017+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
56018+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
56019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56022+4 4 4 4 4 4
56023+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
56024+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
56025+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
56026+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
56027+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
56028+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
56029+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
56030+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
56031+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
56032+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
56033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56036+4 4 4 4 4 4
56037+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
56038+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56039+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
56040+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
56041+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
56042+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
56043+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
56044+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
56045+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
56046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56050+4 4 4 4 4 4
56051+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
56052+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
56053+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
56054+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
56055+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
56056+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
56057+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
56058+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
56059+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
56060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56064+4 4 4 4 4 4
56065+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
56066+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
56067+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
56068+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
56069+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
56070+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
56071+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
56072+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
56073+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56078+4 4 4 4 4 4
56079+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
56080+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
56081+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56082+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
56083+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
56084+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
56085+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
56086+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
56087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56092+4 4 4 4 4 4
56093+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56094+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
56095+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
56096+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
56097+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
56098+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
56099+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
56100+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
56101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56106+4 4 4 4 4 4
56107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56108+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
56109+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56110+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
56111+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
56112+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
56113+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
56114+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
56115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56120+4 4 4 4 4 4
56121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56122+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
56123+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
56124+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
56125+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
56126+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
56127+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
56128+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
56129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56134+4 4 4 4 4 4
56135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56136+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
56137+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
56138+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56139+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
56140+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
56141+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
56142+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
56143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56148+4 4 4 4 4 4
56149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56151+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56152+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
56153+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
56154+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
56155+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
56156+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
56157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56162+4 4 4 4 4 4
56163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56166+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56167+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
56168+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
56169+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
56170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56176+4 4 4 4 4 4
56177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56180+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56181+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56182+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
56183+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
56184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56190+4 4 4 4 4 4
56191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56194+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
56195+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56196+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56197+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
56198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56204+4 4 4 4 4 4
56205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56208+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
56209+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
56210+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
56211+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
56212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56218+4 4 4 4 4 4
56219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56223+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
56224+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56225+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
56226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56232+4 4 4 4 4 4
56233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56237+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
56238+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
56239+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
56240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56246+4 4 4 4 4 4
56247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56251+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
56252+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
56253+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56260+4 4 4 4 4 4
56261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56265+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
56266+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
56267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56274+4 4 4 4 4 4
56275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56279+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56280+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
56281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56288+4 4 4 4 4 4
56289diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56290index fef20db..d28b1ab 100644
56291--- a/drivers/xen/xenfs/xenstored.c
56292+++ b/drivers/xen/xenfs/xenstored.c
56293@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56294 static int xsd_kva_open(struct inode *inode, struct file *file)
56295 {
56296 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56297+#ifdef CONFIG_GRKERNSEC_HIDESYM
56298+ NULL);
56299+#else
56300 xen_store_interface);
56301+#endif
56302+
56303 if (!file->private_data)
56304 return -ENOMEM;
56305 return 0;
56306diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56307index c71e886..61d3d44b 100644
56308--- a/fs/9p/vfs_addr.c
56309+++ b/fs/9p/vfs_addr.c
56310@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56311
56312 retval = v9fs_file_write_internal(inode,
56313 v9inode->writeback_fid,
56314- (__force const char __user *)buffer,
56315+ (const char __force_user *)buffer,
56316 len, &offset, 0);
56317 if (retval > 0)
56318 retval = 0;
56319diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56320index 53161ec..e261d8a 100644
56321--- a/fs/9p/vfs_inode.c
56322+++ b/fs/9p/vfs_inode.c
56323@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56324 void
56325 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56326 {
56327- char *s = nd_get_link(nd);
56328+ const char *s = nd_get_link(nd);
56329
56330 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56331 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56332diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56333index 370b24c..ff0be7b 100644
56334--- a/fs/Kconfig.binfmt
56335+++ b/fs/Kconfig.binfmt
56336@@ -103,7 +103,7 @@ config HAVE_AOUT
56337
56338 config BINFMT_AOUT
56339 tristate "Kernel support for a.out and ECOFF binaries"
56340- depends on HAVE_AOUT
56341+ depends on HAVE_AOUT && BROKEN
56342 ---help---
56343 A.out (Assembler.OUTput) is a set of formats for libraries and
56344 executables used in the earliest versions of UNIX. Linux used
56345diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56346index 2946712..f737435 100644
56347--- a/fs/afs/inode.c
56348+++ b/fs/afs/inode.c
56349@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56350 struct afs_vnode *vnode;
56351 struct super_block *sb;
56352 struct inode *inode;
56353- static atomic_t afs_autocell_ino;
56354+ static atomic_unchecked_t afs_autocell_ino;
56355
56356 _enter("{%x:%u},%*.*s,",
56357 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56358@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56359 data.fid.unique = 0;
56360 data.fid.vnode = 0;
56361
56362- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56363+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56364 afs_iget5_autocell_test, afs_iget5_set,
56365 &data);
56366 if (!inode) {
56367diff --git a/fs/aio.c b/fs/aio.c
56368index 6d68e01..573d8dc 100644
56369--- a/fs/aio.c
56370+++ b/fs/aio.c
56371@@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56372 size += sizeof(struct io_event) * nr_events;
56373
56374 nr_pages = PFN_UP(size);
56375- if (nr_pages < 0)
56376+ if (nr_pages <= 0)
56377 return -EINVAL;
56378
56379 file = aio_private_file(ctx, nr_pages);
56380diff --git a/fs/attr.c b/fs/attr.c
56381index 6530ced..4a827e2 100644
56382--- a/fs/attr.c
56383+++ b/fs/attr.c
56384@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56385 unsigned long limit;
56386
56387 limit = rlimit(RLIMIT_FSIZE);
56388+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56389 if (limit != RLIM_INFINITY && offset > limit)
56390 goto out_sig;
56391 if (offset > inode->i_sb->s_maxbytes)
56392diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56393index 116fd38..c04182da 100644
56394--- a/fs/autofs4/waitq.c
56395+++ b/fs/autofs4/waitq.c
56396@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56397 {
56398 unsigned long sigpipe, flags;
56399 mm_segment_t fs;
56400- const char *data = (const char *)addr;
56401+ const char __user *data = (const char __force_user *)addr;
56402 ssize_t wr = 0;
56403
56404 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56405@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56406 return 1;
56407 }
56408
56409+#ifdef CONFIG_GRKERNSEC_HIDESYM
56410+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56411+#endif
56412+
56413 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56414 enum autofs_notify notify)
56415 {
56416@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56417
56418 /* If this is a direct mount request create a dummy name */
56419 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56420+#ifdef CONFIG_GRKERNSEC_HIDESYM
56421+ /* this name does get written to userland via autofs4_write() */
56422+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56423+#else
56424 qstr.len = sprintf(name, "%p", dentry);
56425+#endif
56426 else {
56427 qstr.len = autofs4_getpath(sbi, dentry, &name);
56428 if (!qstr.len) {
56429diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56430index 2722387..56059b5 100644
56431--- a/fs/befs/endian.h
56432+++ b/fs/befs/endian.h
56433@@ -11,7 +11,7 @@
56434
56435 #include <asm/byteorder.h>
56436
56437-static inline u64
56438+static inline u64 __intentional_overflow(-1)
56439 fs64_to_cpu(const struct super_block *sb, fs64 n)
56440 {
56441 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56442@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56443 return (__force fs64)cpu_to_be64(n);
56444 }
56445
56446-static inline u32
56447+static inline u32 __intentional_overflow(-1)
56448 fs32_to_cpu(const struct super_block *sb, fs32 n)
56449 {
56450 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56451@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56452 return (__force fs32)cpu_to_be32(n);
56453 }
56454
56455-static inline u16
56456+static inline u16 __intentional_overflow(-1)
56457 fs16_to_cpu(const struct super_block *sb, fs16 n)
56458 {
56459 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56460diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56461index ca0ba15..0fa3257 100644
56462--- a/fs/binfmt_aout.c
56463+++ b/fs/binfmt_aout.c
56464@@ -16,6 +16,7 @@
56465 #include <linux/string.h>
56466 #include <linux/fs.h>
56467 #include <linux/file.h>
56468+#include <linux/security.h>
56469 #include <linux/stat.h>
56470 #include <linux/fcntl.h>
56471 #include <linux/ptrace.h>
56472@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56473 #endif
56474 # define START_STACK(u) ((void __user *)u.start_stack)
56475
56476+ memset(&dump, 0, sizeof(dump));
56477+
56478 fs = get_fs();
56479 set_fs(KERNEL_DS);
56480 has_dumped = 1;
56481@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56482
56483 /* If the size of the dump file exceeds the rlimit, then see what would happen
56484 if we wrote the stack, but not the data area. */
56485+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56486 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56487 dump.u_dsize = 0;
56488
56489 /* Make sure we have enough room to write the stack and data areas. */
56490+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56491 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56492 dump.u_ssize = 0;
56493
56494@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56495 rlim = rlimit(RLIMIT_DATA);
56496 if (rlim >= RLIM_INFINITY)
56497 rlim = ~0;
56498+
56499+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56500 if (ex.a_data + ex.a_bss > rlim)
56501 return -ENOMEM;
56502
56503@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56504
56505 install_exec_creds(bprm);
56506
56507+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56508+ current->mm->pax_flags = 0UL;
56509+#endif
56510+
56511+#ifdef CONFIG_PAX_PAGEEXEC
56512+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56513+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56514+
56515+#ifdef CONFIG_PAX_EMUTRAMP
56516+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56517+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56518+#endif
56519+
56520+#ifdef CONFIG_PAX_MPROTECT
56521+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56522+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56523+#endif
56524+
56525+ }
56526+#endif
56527+
56528 if (N_MAGIC(ex) == OMAGIC) {
56529 unsigned long text_addr, map_size;
56530 loff_t pos;
56531@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56532 }
56533
56534 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56535- PROT_READ | PROT_WRITE | PROT_EXEC,
56536+ PROT_READ | PROT_WRITE,
56537 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56538 fd_offset + ex.a_text);
56539 if (error != N_DATADDR(ex)) {
56540diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56541index aa3cb62..bc53934 100644
56542--- a/fs/binfmt_elf.c
56543+++ b/fs/binfmt_elf.c
56544@@ -34,6 +34,7 @@
56545 #include <linux/utsname.h>
56546 #include <linux/coredump.h>
56547 #include <linux/sched.h>
56548+#include <linux/xattr.h>
56549 #include <asm/uaccess.h>
56550 #include <asm/param.h>
56551 #include <asm/page.h>
56552@@ -47,7 +48,7 @@
56553
56554 static int load_elf_binary(struct linux_binprm *bprm);
56555 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56556- int, int, unsigned long);
56557+ int, int, unsigned long) __intentional_overflow(-1);
56558
56559 #ifdef CONFIG_USELIB
56560 static int load_elf_library(struct file *);
56561@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56562 #define elf_core_dump NULL
56563 #endif
56564
56565+#ifdef CONFIG_PAX_MPROTECT
56566+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56567+#endif
56568+
56569+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56570+static void elf_handle_mmap(struct file *file);
56571+#endif
56572+
56573 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56574 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56575 #else
56576@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56577 .load_binary = load_elf_binary,
56578 .load_shlib = load_elf_library,
56579 .core_dump = elf_core_dump,
56580+
56581+#ifdef CONFIG_PAX_MPROTECT
56582+ .handle_mprotect= elf_handle_mprotect,
56583+#endif
56584+
56585+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56586+ .handle_mmap = elf_handle_mmap,
56587+#endif
56588+
56589 .min_coredump = ELF_EXEC_PAGESIZE,
56590 };
56591
56592@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56593
56594 static int set_brk(unsigned long start, unsigned long end)
56595 {
56596+ unsigned long e = end;
56597+
56598 start = ELF_PAGEALIGN(start);
56599 end = ELF_PAGEALIGN(end);
56600 if (end > start) {
56601@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56602 if (BAD_ADDR(addr))
56603 return addr;
56604 }
56605- current->mm->start_brk = current->mm->brk = end;
56606+ current->mm->start_brk = current->mm->brk = e;
56607 return 0;
56608 }
56609
56610@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56611 elf_addr_t __user *u_rand_bytes;
56612 const char *k_platform = ELF_PLATFORM;
56613 const char *k_base_platform = ELF_BASE_PLATFORM;
56614- unsigned char k_rand_bytes[16];
56615+ u32 k_rand_bytes[4];
56616 int items;
56617 elf_addr_t *elf_info;
56618 int ei_index = 0;
56619 const struct cred *cred = current_cred();
56620 struct vm_area_struct *vma;
56621+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56622
56623 /*
56624 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56625@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56626 * Generate 16 random bytes for userspace PRNG seeding.
56627 */
56628 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56629- u_rand_bytes = (elf_addr_t __user *)
56630- STACK_ALLOC(p, sizeof(k_rand_bytes));
56631+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56632+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56633+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56634+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56635+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56636+ u_rand_bytes = (elf_addr_t __user *) p;
56637 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56638 return -EFAULT;
56639
56640@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56641 return -EFAULT;
56642 current->mm->env_end = p;
56643
56644+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56645+
56646 /* Put the elf_info on the stack in the right place. */
56647 sp = (elf_addr_t __user *)envp + 1;
56648- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56649+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56650 return -EFAULT;
56651 return 0;
56652 }
56653@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56654 an ELF header */
56655
56656 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56657- struct file *interpreter, unsigned long *interp_map_addr,
56658- unsigned long no_base)
56659+ struct file *interpreter, unsigned long no_base)
56660 {
56661 struct elf_phdr *elf_phdata;
56662 struct elf_phdr *eppnt;
56663- unsigned long load_addr = 0;
56664+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56665 int load_addr_set = 0;
56666 unsigned long last_bss = 0, elf_bss = 0;
56667- unsigned long error = ~0UL;
56668+ unsigned long error = -EINVAL;
56669 unsigned long total_size;
56670 int retval, i, size;
56671
56672@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56673 goto out_close;
56674 }
56675
56676+#ifdef CONFIG_PAX_SEGMEXEC
56677+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56678+ pax_task_size = SEGMEXEC_TASK_SIZE;
56679+#endif
56680+
56681 eppnt = elf_phdata;
56682 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56683 if (eppnt->p_type == PT_LOAD) {
56684@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56685 map_addr = elf_map(interpreter, load_addr + vaddr,
56686 eppnt, elf_prot, elf_type, total_size);
56687 total_size = 0;
56688- if (!*interp_map_addr)
56689- *interp_map_addr = map_addr;
56690 error = map_addr;
56691 if (BAD_ADDR(map_addr))
56692 goto out_close;
56693@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56694 k = load_addr + eppnt->p_vaddr;
56695 if (BAD_ADDR(k) ||
56696 eppnt->p_filesz > eppnt->p_memsz ||
56697- eppnt->p_memsz > TASK_SIZE ||
56698- TASK_SIZE - eppnt->p_memsz < k) {
56699+ eppnt->p_memsz > pax_task_size ||
56700+ pax_task_size - eppnt->p_memsz < k) {
56701 error = -ENOMEM;
56702 goto out_close;
56703 }
56704@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56705 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56706
56707 /* Map the last of the bss segment */
56708- error = vm_brk(elf_bss, last_bss - elf_bss);
56709- if (BAD_ADDR(error))
56710- goto out_close;
56711+ if (last_bss > elf_bss) {
56712+ error = vm_brk(elf_bss, last_bss - elf_bss);
56713+ if (BAD_ADDR(error))
56714+ goto out_close;
56715+ }
56716 }
56717
56718 error = load_addr;
56719@@ -543,6 +574,336 @@ out:
56720 return error;
56721 }
56722
56723+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56724+#ifdef CONFIG_PAX_SOFTMODE
56725+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56726+{
56727+ unsigned long pax_flags = 0UL;
56728+
56729+#ifdef CONFIG_PAX_PAGEEXEC
56730+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56731+ pax_flags |= MF_PAX_PAGEEXEC;
56732+#endif
56733+
56734+#ifdef CONFIG_PAX_SEGMEXEC
56735+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56736+ pax_flags |= MF_PAX_SEGMEXEC;
56737+#endif
56738+
56739+#ifdef CONFIG_PAX_EMUTRAMP
56740+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56741+ pax_flags |= MF_PAX_EMUTRAMP;
56742+#endif
56743+
56744+#ifdef CONFIG_PAX_MPROTECT
56745+ if (elf_phdata->p_flags & PF_MPROTECT)
56746+ pax_flags |= MF_PAX_MPROTECT;
56747+#endif
56748+
56749+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56750+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56751+ pax_flags |= MF_PAX_RANDMMAP;
56752+#endif
56753+
56754+ return pax_flags;
56755+}
56756+#endif
56757+
56758+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56759+{
56760+ unsigned long pax_flags = 0UL;
56761+
56762+#ifdef CONFIG_PAX_PAGEEXEC
56763+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56764+ pax_flags |= MF_PAX_PAGEEXEC;
56765+#endif
56766+
56767+#ifdef CONFIG_PAX_SEGMEXEC
56768+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56769+ pax_flags |= MF_PAX_SEGMEXEC;
56770+#endif
56771+
56772+#ifdef CONFIG_PAX_EMUTRAMP
56773+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56774+ pax_flags |= MF_PAX_EMUTRAMP;
56775+#endif
56776+
56777+#ifdef CONFIG_PAX_MPROTECT
56778+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56779+ pax_flags |= MF_PAX_MPROTECT;
56780+#endif
56781+
56782+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56783+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56784+ pax_flags |= MF_PAX_RANDMMAP;
56785+#endif
56786+
56787+ return pax_flags;
56788+}
56789+#endif
56790+
56791+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56792+#ifdef CONFIG_PAX_SOFTMODE
56793+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56794+{
56795+ unsigned long pax_flags = 0UL;
56796+
56797+#ifdef CONFIG_PAX_PAGEEXEC
56798+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56799+ pax_flags |= MF_PAX_PAGEEXEC;
56800+#endif
56801+
56802+#ifdef CONFIG_PAX_SEGMEXEC
56803+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56804+ pax_flags |= MF_PAX_SEGMEXEC;
56805+#endif
56806+
56807+#ifdef CONFIG_PAX_EMUTRAMP
56808+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56809+ pax_flags |= MF_PAX_EMUTRAMP;
56810+#endif
56811+
56812+#ifdef CONFIG_PAX_MPROTECT
56813+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56814+ pax_flags |= MF_PAX_MPROTECT;
56815+#endif
56816+
56817+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56818+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56819+ pax_flags |= MF_PAX_RANDMMAP;
56820+#endif
56821+
56822+ return pax_flags;
56823+}
56824+#endif
56825+
56826+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56827+{
56828+ unsigned long pax_flags = 0UL;
56829+
56830+#ifdef CONFIG_PAX_PAGEEXEC
56831+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56832+ pax_flags |= MF_PAX_PAGEEXEC;
56833+#endif
56834+
56835+#ifdef CONFIG_PAX_SEGMEXEC
56836+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56837+ pax_flags |= MF_PAX_SEGMEXEC;
56838+#endif
56839+
56840+#ifdef CONFIG_PAX_EMUTRAMP
56841+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56842+ pax_flags |= MF_PAX_EMUTRAMP;
56843+#endif
56844+
56845+#ifdef CONFIG_PAX_MPROTECT
56846+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56847+ pax_flags |= MF_PAX_MPROTECT;
56848+#endif
56849+
56850+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56851+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56852+ pax_flags |= MF_PAX_RANDMMAP;
56853+#endif
56854+
56855+ return pax_flags;
56856+}
56857+#endif
56858+
56859+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56860+static unsigned long pax_parse_defaults(void)
56861+{
56862+ unsigned long pax_flags = 0UL;
56863+
56864+#ifdef CONFIG_PAX_SOFTMODE
56865+ if (pax_softmode)
56866+ return pax_flags;
56867+#endif
56868+
56869+#ifdef CONFIG_PAX_PAGEEXEC
56870+ pax_flags |= MF_PAX_PAGEEXEC;
56871+#endif
56872+
56873+#ifdef CONFIG_PAX_SEGMEXEC
56874+ pax_flags |= MF_PAX_SEGMEXEC;
56875+#endif
56876+
56877+#ifdef CONFIG_PAX_MPROTECT
56878+ pax_flags |= MF_PAX_MPROTECT;
56879+#endif
56880+
56881+#ifdef CONFIG_PAX_RANDMMAP
56882+ if (randomize_va_space)
56883+ pax_flags |= MF_PAX_RANDMMAP;
56884+#endif
56885+
56886+ return pax_flags;
56887+}
56888+
56889+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56890+{
56891+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56892+
56893+#ifdef CONFIG_PAX_EI_PAX
56894+
56895+#ifdef CONFIG_PAX_SOFTMODE
56896+ if (pax_softmode)
56897+ return pax_flags;
56898+#endif
56899+
56900+ pax_flags = 0UL;
56901+
56902+#ifdef CONFIG_PAX_PAGEEXEC
56903+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56904+ pax_flags |= MF_PAX_PAGEEXEC;
56905+#endif
56906+
56907+#ifdef CONFIG_PAX_SEGMEXEC
56908+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56909+ pax_flags |= MF_PAX_SEGMEXEC;
56910+#endif
56911+
56912+#ifdef CONFIG_PAX_EMUTRAMP
56913+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56914+ pax_flags |= MF_PAX_EMUTRAMP;
56915+#endif
56916+
56917+#ifdef CONFIG_PAX_MPROTECT
56918+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56919+ pax_flags |= MF_PAX_MPROTECT;
56920+#endif
56921+
56922+#ifdef CONFIG_PAX_ASLR
56923+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56924+ pax_flags |= MF_PAX_RANDMMAP;
56925+#endif
56926+
56927+#endif
56928+
56929+ return pax_flags;
56930+
56931+}
56932+
56933+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56934+{
56935+
56936+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56937+ unsigned long i;
56938+
56939+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56940+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56941+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56942+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56943+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56944+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56945+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56946+ return PAX_PARSE_FLAGS_FALLBACK;
56947+
56948+#ifdef CONFIG_PAX_SOFTMODE
56949+ if (pax_softmode)
56950+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56951+ else
56952+#endif
56953+
56954+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56955+ break;
56956+ }
56957+#endif
56958+
56959+ return PAX_PARSE_FLAGS_FALLBACK;
56960+}
56961+
56962+static unsigned long pax_parse_xattr_pax(struct file * const file)
56963+{
56964+
56965+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56966+ ssize_t xattr_size, i;
56967+ unsigned char xattr_value[sizeof("pemrs") - 1];
56968+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56969+
56970+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56971+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56972+ return PAX_PARSE_FLAGS_FALLBACK;
56973+
56974+ for (i = 0; i < xattr_size; i++)
56975+ switch (xattr_value[i]) {
56976+ default:
56977+ return PAX_PARSE_FLAGS_FALLBACK;
56978+
56979+#define parse_flag(option1, option2, flag) \
56980+ case option1: \
56981+ if (pax_flags_hardmode & MF_PAX_##flag) \
56982+ return PAX_PARSE_FLAGS_FALLBACK;\
56983+ pax_flags_hardmode |= MF_PAX_##flag; \
56984+ break; \
56985+ case option2: \
56986+ if (pax_flags_softmode & MF_PAX_##flag) \
56987+ return PAX_PARSE_FLAGS_FALLBACK;\
56988+ pax_flags_softmode |= MF_PAX_##flag; \
56989+ break;
56990+
56991+ parse_flag('p', 'P', PAGEEXEC);
56992+ parse_flag('e', 'E', EMUTRAMP);
56993+ parse_flag('m', 'M', MPROTECT);
56994+ parse_flag('r', 'R', RANDMMAP);
56995+ parse_flag('s', 'S', SEGMEXEC);
56996+
56997+#undef parse_flag
56998+ }
56999+
57000+ if (pax_flags_hardmode & pax_flags_softmode)
57001+ return PAX_PARSE_FLAGS_FALLBACK;
57002+
57003+#ifdef CONFIG_PAX_SOFTMODE
57004+ if (pax_softmode)
57005+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
57006+ else
57007+#endif
57008+
57009+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
57010+#else
57011+ return PAX_PARSE_FLAGS_FALLBACK;
57012+#endif
57013+
57014+}
57015+
57016+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
57017+{
57018+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
57019+
57020+ pax_flags = pax_parse_defaults();
57021+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
57022+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
57023+ xattr_pax_flags = pax_parse_xattr_pax(file);
57024+
57025+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57026+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57027+ pt_pax_flags != xattr_pax_flags)
57028+ return -EINVAL;
57029+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57030+ pax_flags = xattr_pax_flags;
57031+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57032+ pax_flags = pt_pax_flags;
57033+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57034+ pax_flags = ei_pax_flags;
57035+
57036+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57037+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57038+ if ((__supported_pte_mask & _PAGE_NX))
57039+ pax_flags &= ~MF_PAX_SEGMEXEC;
57040+ else
57041+ pax_flags &= ~MF_PAX_PAGEEXEC;
57042+ }
57043+#endif
57044+
57045+ if (0 > pax_check_flags(&pax_flags))
57046+ return -EINVAL;
57047+
57048+ current->mm->pax_flags = pax_flags;
57049+ return 0;
57050+}
57051+#endif
57052+
57053 /*
57054 * These are the functions used to load ELF style executables and shared
57055 * libraries. There is no binary dependent code anywhere else.
57056@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57057 {
57058 unsigned int random_variable = 0;
57059
57060+#ifdef CONFIG_PAX_RANDUSTACK
57061+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57062+ return stack_top - current->mm->delta_stack;
57063+#endif
57064+
57065 if ((current->flags & PF_RANDOMIZE) &&
57066 !(current->personality & ADDR_NO_RANDOMIZE)) {
57067 random_variable = get_random_int() & STACK_RND_MASK;
57068@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57069 unsigned long load_addr = 0, load_bias = 0;
57070 int load_addr_set = 0;
57071 char * elf_interpreter = NULL;
57072- unsigned long error;
57073+ unsigned long error = 0;
57074 struct elf_phdr *elf_ppnt, *elf_phdata;
57075 unsigned long elf_bss, elf_brk;
57076 int retval, i;
57077@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57078 struct elfhdr elf_ex;
57079 struct elfhdr interp_elf_ex;
57080 } *loc;
57081+ unsigned long pax_task_size;
57082
57083 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57084 if (!loc) {
57085@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
57086 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57087 may depend on the personality. */
57088 SET_PERSONALITY(loc->elf_ex);
57089+
57090+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57091+ current->mm->pax_flags = 0UL;
57092+#endif
57093+
57094+#ifdef CONFIG_PAX_DLRESOLVE
57095+ current->mm->call_dl_resolve = 0UL;
57096+#endif
57097+
57098+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57099+ current->mm->call_syscall = 0UL;
57100+#endif
57101+
57102+#ifdef CONFIG_PAX_ASLR
57103+ current->mm->delta_mmap = 0UL;
57104+ current->mm->delta_stack = 0UL;
57105+#endif
57106+
57107+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57108+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57109+ send_sig(SIGKILL, current, 0);
57110+ goto out_free_dentry;
57111+ }
57112+#endif
57113+
57114+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57115+ pax_set_initial_flags(bprm);
57116+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57117+ if (pax_set_initial_flags_func)
57118+ (pax_set_initial_flags_func)(bprm);
57119+#endif
57120+
57121+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57122+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57123+ current->mm->context.user_cs_limit = PAGE_SIZE;
57124+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57125+ }
57126+#endif
57127+
57128+#ifdef CONFIG_PAX_SEGMEXEC
57129+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57130+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57131+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57132+ pax_task_size = SEGMEXEC_TASK_SIZE;
57133+ current->mm->def_flags |= VM_NOHUGEPAGE;
57134+ } else
57135+#endif
57136+
57137+ pax_task_size = TASK_SIZE;
57138+
57139+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57140+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57141+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57142+ put_cpu();
57143+ }
57144+#endif
57145+
57146+#ifdef CONFIG_PAX_ASLR
57147+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57148+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57149+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57150+ }
57151+#endif
57152+
57153+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57154+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57155+ executable_stack = EXSTACK_DISABLE_X;
57156+ current->personality &= ~READ_IMPLIES_EXEC;
57157+ } else
57158+#endif
57159+
57160 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57161 current->personality |= READ_IMPLIES_EXEC;
57162
57163@@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57164 #else
57165 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57166 #endif
57167+
57168+#ifdef CONFIG_PAX_RANDMMAP
57169+ /* PaX: randomize base address at the default exe base if requested */
57170+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57171+#ifdef CONFIG_SPARC64
57172+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57173+#else
57174+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57175+#endif
57176+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57177+ elf_flags |= MAP_FIXED;
57178+ }
57179+#endif
57180+
57181 }
57182
57183 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57184@@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57185 * allowed task size. Note that p_filesz must always be
57186 * <= p_memsz so it is only necessary to check p_memsz.
57187 */
57188- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57189- elf_ppnt->p_memsz > TASK_SIZE ||
57190- TASK_SIZE - elf_ppnt->p_memsz < k) {
57191+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57192+ elf_ppnt->p_memsz > pax_task_size ||
57193+ pax_task_size - elf_ppnt->p_memsz < k) {
57194 /* set_brk can never work. Avoid overflows. */
57195 send_sig(SIGKILL, current, 0);
57196 retval = -EINVAL;
57197@@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57198 goto out_free_dentry;
57199 }
57200 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57201- send_sig(SIGSEGV, current, 0);
57202- retval = -EFAULT; /* Nobody gets to see this, but.. */
57203- goto out_free_dentry;
57204+ /*
57205+ * This bss-zeroing can fail if the ELF
57206+ * file specifies odd protections. So
57207+ * we don't check the return value
57208+ */
57209 }
57210
57211+#ifdef CONFIG_PAX_RANDMMAP
57212+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57213+ unsigned long start, size, flags;
57214+ vm_flags_t vm_flags;
57215+
57216+ start = ELF_PAGEALIGN(elf_brk);
57217+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57218+ flags = MAP_FIXED | MAP_PRIVATE;
57219+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57220+
57221+ down_write(&current->mm->mmap_sem);
57222+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57223+ retval = -ENOMEM;
57224+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57225+// if (current->personality & ADDR_NO_RANDOMIZE)
57226+// vm_flags |= VM_READ | VM_MAYREAD;
57227+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57228+ retval = IS_ERR_VALUE(start) ? start : 0;
57229+ }
57230+ up_write(&current->mm->mmap_sem);
57231+ if (retval == 0)
57232+ retval = set_brk(start + size, start + size + PAGE_SIZE);
57233+ if (retval < 0) {
57234+ send_sig(SIGKILL, current, 0);
57235+ goto out_free_dentry;
57236+ }
57237+ }
57238+#endif
57239+
57240 if (elf_interpreter) {
57241- unsigned long interp_map_addr = 0;
57242-
57243 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57244 interpreter,
57245- &interp_map_addr,
57246 load_bias);
57247 if (!IS_ERR((void *)elf_entry)) {
57248 /*
57249@@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57250 * Decide what to dump of a segment, part, all or none.
57251 */
57252 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57253- unsigned long mm_flags)
57254+ unsigned long mm_flags, long signr)
57255 {
57256 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57257
57258@@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57259 if (vma->vm_file == NULL)
57260 return 0;
57261
57262- if (FILTER(MAPPED_PRIVATE))
57263+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57264 goto whole;
57265
57266 /*
57267@@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57268 {
57269 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57270 int i = 0;
57271- do
57272+ do {
57273 i += 2;
57274- while (auxv[i - 2] != AT_NULL);
57275+ } while (auxv[i - 2] != AT_NULL);
57276 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57277 }
57278
57279@@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57280 {
57281 mm_segment_t old_fs = get_fs();
57282 set_fs(KERNEL_DS);
57283- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57284+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57285 set_fs(old_fs);
57286 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57287 }
57288@@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57289 }
57290
57291 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57292- unsigned long mm_flags)
57293+ struct coredump_params *cprm)
57294 {
57295 struct vm_area_struct *vma;
57296 size_t size = 0;
57297
57298 for (vma = first_vma(current, gate_vma); vma != NULL;
57299 vma = next_vma(vma, gate_vma))
57300- size += vma_dump_size(vma, mm_flags);
57301+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57302 return size;
57303 }
57304
57305@@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57306
57307 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57308
57309- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57310+ offset += elf_core_vma_data_size(gate_vma, cprm);
57311 offset += elf_core_extra_data_size();
57312 e_shoff = offset;
57313
57314@@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57315 phdr.p_offset = offset;
57316 phdr.p_vaddr = vma->vm_start;
57317 phdr.p_paddr = 0;
57318- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57319+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57320 phdr.p_memsz = vma->vm_end - vma->vm_start;
57321 offset += phdr.p_filesz;
57322 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57323@@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57324 unsigned long addr;
57325 unsigned long end;
57326
57327- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57328+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57329
57330 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57331 struct page *page;
57332@@ -2202,6 +2682,167 @@ out:
57333
57334 #endif /* CONFIG_ELF_CORE */
57335
57336+#ifdef CONFIG_PAX_MPROTECT
57337+/* PaX: non-PIC ELF libraries need relocations on their executable segments
57338+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57339+ * we'll remove VM_MAYWRITE for good on RELRO segments.
57340+ *
57341+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57342+ * basis because we want to allow the common case and not the special ones.
57343+ */
57344+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57345+{
57346+ struct elfhdr elf_h;
57347+ struct elf_phdr elf_p;
57348+ unsigned long i;
57349+ unsigned long oldflags;
57350+ bool is_textrel_rw, is_textrel_rx, is_relro;
57351+
57352+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57353+ return;
57354+
57355+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57356+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57357+
57358+#ifdef CONFIG_PAX_ELFRELOCS
57359+ /* possible TEXTREL */
57360+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57361+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57362+#else
57363+ is_textrel_rw = false;
57364+ is_textrel_rx = false;
57365+#endif
57366+
57367+ /* possible RELRO */
57368+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57369+
57370+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57371+ return;
57372+
57373+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57374+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57375+
57376+#ifdef CONFIG_PAX_ETEXECRELOCS
57377+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57378+#else
57379+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57380+#endif
57381+
57382+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57383+ !elf_check_arch(&elf_h) ||
57384+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57385+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57386+ return;
57387+
57388+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57389+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57390+ return;
57391+ switch (elf_p.p_type) {
57392+ case PT_DYNAMIC:
57393+ if (!is_textrel_rw && !is_textrel_rx)
57394+ continue;
57395+ i = 0UL;
57396+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57397+ elf_dyn dyn;
57398+
57399+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57400+ break;
57401+ if (dyn.d_tag == DT_NULL)
57402+ break;
57403+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57404+ gr_log_textrel(vma);
57405+ if (is_textrel_rw)
57406+ vma->vm_flags |= VM_MAYWRITE;
57407+ else
57408+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57409+ vma->vm_flags &= ~VM_MAYWRITE;
57410+ break;
57411+ }
57412+ i++;
57413+ }
57414+ is_textrel_rw = false;
57415+ is_textrel_rx = false;
57416+ continue;
57417+
57418+ case PT_GNU_RELRO:
57419+ if (!is_relro)
57420+ continue;
57421+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57422+ vma->vm_flags &= ~VM_MAYWRITE;
57423+ is_relro = false;
57424+ continue;
57425+
57426+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57427+ case PT_PAX_FLAGS: {
57428+ const char *msg_mprotect = "", *msg_emutramp = "";
57429+ char *buffer_lib, *buffer_exe;
57430+
57431+ if (elf_p.p_flags & PF_NOMPROTECT)
57432+ msg_mprotect = "MPROTECT disabled";
57433+
57434+#ifdef CONFIG_PAX_EMUTRAMP
57435+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57436+ msg_emutramp = "EMUTRAMP enabled";
57437+#endif
57438+
57439+ if (!msg_mprotect[0] && !msg_emutramp[0])
57440+ continue;
57441+
57442+ if (!printk_ratelimit())
57443+ continue;
57444+
57445+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57446+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57447+ if (buffer_lib && buffer_exe) {
57448+ char *path_lib, *path_exe;
57449+
57450+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57451+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57452+
57453+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57454+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57455+
57456+ }
57457+ free_page((unsigned long)buffer_exe);
57458+ free_page((unsigned long)buffer_lib);
57459+ continue;
57460+ }
57461+#endif
57462+
57463+ }
57464+ }
57465+}
57466+#endif
57467+
57468+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57469+
57470+extern int grsec_enable_log_rwxmaps;
57471+
57472+static void elf_handle_mmap(struct file *file)
57473+{
57474+ struct elfhdr elf_h;
57475+ struct elf_phdr elf_p;
57476+ unsigned long i;
57477+
57478+ if (!grsec_enable_log_rwxmaps)
57479+ return;
57480+
57481+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57482+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57483+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57484+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57485+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57486+ return;
57487+
57488+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57489+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57490+ return;
57491+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57492+ gr_log_ptgnustack(file);
57493+ }
57494+}
57495+#endif
57496+
57497 static int __init init_elf_binfmt(void)
57498 {
57499 register_binfmt(&elf_format);
57500diff --git a/fs/bio.c b/fs/bio.c
57501index 6f0362b..26a7496 100644
57502--- a/fs/bio.c
57503+++ b/fs/bio.c
57504@@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57505 /*
57506 * Overflow, abort
57507 */
57508- if (end < start)
57509+ if (end < start || end - start > INT_MAX - nr_pages)
57510 return ERR_PTR(-EINVAL);
57511
57512 nr_pages += end - start;
57513@@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57514 /*
57515 * Overflow, abort
57516 */
57517- if (end < start)
57518+ if (end < start || end - start > INT_MAX - nr_pages)
57519 return ERR_PTR(-EINVAL);
57520
57521 nr_pages += end - start;
57522@@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57523 const int read = bio_data_dir(bio) == READ;
57524 struct bio_map_data *bmd = bio->bi_private;
57525 int i;
57526- char *p = bmd->sgvecs[0].iov_base;
57527+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57528
57529 bio_for_each_segment_all(bvec, bio, i) {
57530 char *addr = page_address(bvec->bv_page);
57531diff --git a/fs/block_dev.c b/fs/block_dev.c
57532index 552a8d1..d51ccf3 100644
57533--- a/fs/block_dev.c
57534+++ b/fs/block_dev.c
57535@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57536 else if (bdev->bd_contains == bdev)
57537 return true; /* is a whole device which isn't held */
57538
57539- else if (whole->bd_holder == bd_may_claim)
57540+ else if (whole->bd_holder == (void *)bd_may_claim)
57541 return true; /* is a partition of a device that is being partitioned */
57542 else if (whole->bd_holder != NULL)
57543 return false; /* is a partition of a held device */
57544diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57545index 1bcfcdb..e942132 100644
57546--- a/fs/btrfs/ctree.c
57547+++ b/fs/btrfs/ctree.c
57548@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57549 free_extent_buffer(buf);
57550 add_root_to_dirty_list(root);
57551 } else {
57552- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57553- parent_start = parent->start;
57554- else
57555+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57556+ if (parent)
57557+ parent_start = parent->start;
57558+ else
57559+ parent_start = 0;
57560+ } else
57561 parent_start = 0;
57562
57563 WARN_ON(trans->transid != btrfs_header_generation(parent));
57564diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57565index 33e561a..16df7ae 100644
57566--- a/fs/btrfs/delayed-inode.c
57567+++ b/fs/btrfs/delayed-inode.c
57568@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57569
57570 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57571 {
57572- int seq = atomic_inc_return(&delayed_root->items_seq);
57573+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57574 if ((atomic_dec_return(&delayed_root->items) <
57575 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57576 waitqueue_active(&delayed_root->wait))
57577@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57578
57579 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57580 {
57581- int val = atomic_read(&delayed_root->items_seq);
57582+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57583
57584 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57585 return 1;
57586@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57587 int seq;
57588 int ret;
57589
57590- seq = atomic_read(&delayed_root->items_seq);
57591+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57592
57593 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57594 if (ret)
57595diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57596index f70119f..ab5894d 100644
57597--- a/fs/btrfs/delayed-inode.h
57598+++ b/fs/btrfs/delayed-inode.h
57599@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57600 */
57601 struct list_head prepare_list;
57602 atomic_t items; /* for delayed items */
57603- atomic_t items_seq; /* for delayed items */
57604+ atomic_unchecked_t items_seq; /* for delayed items */
57605 int nodes; /* for delayed nodes */
57606 wait_queue_head_t wait;
57607 };
57608@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57609 struct btrfs_delayed_root *delayed_root)
57610 {
57611 atomic_set(&delayed_root->items, 0);
57612- atomic_set(&delayed_root->items_seq, 0);
57613+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57614 delayed_root->nodes = 0;
57615 spin_lock_init(&delayed_root->lock);
57616 init_waitqueue_head(&delayed_root->wait);
57617diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57618index 2f6d7b1..f186382 100644
57619--- a/fs/btrfs/ioctl.c
57620+++ b/fs/btrfs/ioctl.c
57621@@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57622 for (i = 0; i < num_types; i++) {
57623 struct btrfs_space_info *tmp;
57624
57625+ /* Don't copy in more than we allocated */
57626 if (!slot_count)
57627 break;
57628
57629+ slot_count--;
57630+
57631 info = NULL;
57632 rcu_read_lock();
57633 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57634@@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57635 memcpy(dest, &space, sizeof(space));
57636 dest++;
57637 space_args.total_spaces++;
57638- slot_count--;
57639 }
57640- if (!slot_count)
57641- break;
57642 }
57643 up_read(&info->groups_sem);
57644 }
57645diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57646index 9601d25..2896d6c 100644
57647--- a/fs/btrfs/super.c
57648+++ b/fs/btrfs/super.c
57649@@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57650 function, line, errstr);
57651 return;
57652 }
57653- ACCESS_ONCE(trans->transaction->aborted) = errno;
57654+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57655 /* Wake up anybody who may be waiting on this transaction */
57656 wake_up(&root->fs_info->transaction_wait);
57657 wake_up(&root->fs_info->transaction_blocked_wait);
57658diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57659index 4825cd2..b2fe768 100644
57660--- a/fs/btrfs/sysfs.c
57661+++ b/fs/btrfs/sysfs.c
57662@@ -438,7 +438,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57663 for (set = 0; set < FEAT_MAX; set++) {
57664 int i;
57665 struct attribute *attrs[2];
57666- struct attribute_group agroup = {
57667+ attribute_group_no_const agroup = {
57668 .name = "features",
57669 .attrs = attrs,
57670 };
57671diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57672index e2f45fc..b036909 100644
57673--- a/fs/btrfs/tree-log.c
57674+++ b/fs/btrfs/tree-log.c
57675@@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57676 blk_finish_plug(&plug);
57677 btrfs_abort_transaction(trans, root, ret);
57678 btrfs_free_logged_extents(log, log_transid);
57679- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57680+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57681 trans->transid;
57682 mutex_unlock(&root->log_mutex);
57683 goto out;
57684@@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57685 list_del_init(&root_log_ctx.list);
57686
57687 blk_finish_plug(&plug);
57688- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57689+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57690 trans->transid;
57691 if (ret != -ENOSPC) {
57692 btrfs_abort_transaction(trans, root, ret);
57693@@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57694 * now that we've moved on to the tree of log tree roots,
57695 * check the full commit flag again
57696 */
57697- if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57698+ if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57699 trans->transid) {
57700 blk_finish_plug(&plug);
57701 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57702@@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57703 EXTENT_DIRTY | EXTENT_NEW);
57704 blk_finish_plug(&plug);
57705 if (ret) {
57706- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57707+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57708 trans->transid;
57709 btrfs_abort_transaction(trans, root, ret);
57710 btrfs_free_logged_extents(log, log_transid);
57711@@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57712 */
57713 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57714 if (ret) {
57715- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57716+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57717 trans->transid;
57718 btrfs_abort_transaction(trans, root, ret);
57719 goto out_wake_log_root;
57720diff --git a/fs/buffer.c b/fs/buffer.c
57721index 9ddb9fc..7aa2487 100644
57722--- a/fs/buffer.c
57723+++ b/fs/buffer.c
57724@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57725 bh_cachep = kmem_cache_create("buffer_head",
57726 sizeof(struct buffer_head), 0,
57727 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57728- SLAB_MEM_SPREAD),
57729+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57730 NULL);
57731
57732 /*
57733diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57734index 5b99baf..47fffb5 100644
57735--- a/fs/cachefiles/bind.c
57736+++ b/fs/cachefiles/bind.c
57737@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57738 args);
57739
57740 /* start by checking things over */
57741- ASSERT(cache->fstop_percent >= 0 &&
57742- cache->fstop_percent < cache->fcull_percent &&
57743+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57744 cache->fcull_percent < cache->frun_percent &&
57745 cache->frun_percent < 100);
57746
57747- ASSERT(cache->bstop_percent >= 0 &&
57748- cache->bstop_percent < cache->bcull_percent &&
57749+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57750 cache->bcull_percent < cache->brun_percent &&
57751 cache->brun_percent < 100);
57752
57753diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57754index 0a1467b..6a53245 100644
57755--- a/fs/cachefiles/daemon.c
57756+++ b/fs/cachefiles/daemon.c
57757@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57758 if (n > buflen)
57759 return -EMSGSIZE;
57760
57761- if (copy_to_user(_buffer, buffer, n) != 0)
57762+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57763 return -EFAULT;
57764
57765 return n;
57766@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57767 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57768 return -EIO;
57769
57770- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57771+ if (datalen > PAGE_SIZE - 1)
57772 return -EOPNOTSUPP;
57773
57774 /* drag the command string into the kernel so we can parse it */
57775@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57776 if (args[0] != '%' || args[1] != '\0')
57777 return -EINVAL;
57778
57779- if (fstop < 0 || fstop >= cache->fcull_percent)
57780+ if (fstop >= cache->fcull_percent)
57781 return cachefiles_daemon_range_error(cache, args);
57782
57783 cache->fstop_percent = fstop;
57784@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57785 if (args[0] != '%' || args[1] != '\0')
57786 return -EINVAL;
57787
57788- if (bstop < 0 || bstop >= cache->bcull_percent)
57789+ if (bstop >= cache->bcull_percent)
57790 return cachefiles_daemon_range_error(cache, args);
57791
57792 cache->bstop_percent = bstop;
57793diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57794index 5349473..d6c0b93 100644
57795--- a/fs/cachefiles/internal.h
57796+++ b/fs/cachefiles/internal.h
57797@@ -59,7 +59,7 @@ struct cachefiles_cache {
57798 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57799 struct rb_root active_nodes; /* active nodes (can't be culled) */
57800 rwlock_t active_lock; /* lock for active_nodes */
57801- atomic_t gravecounter; /* graveyard uniquifier */
57802+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57803 unsigned frun_percent; /* when to stop culling (% files) */
57804 unsigned fcull_percent; /* when to start culling (% files) */
57805 unsigned fstop_percent; /* when to stop allocating (% files) */
57806@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57807 * proc.c
57808 */
57809 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57810-extern atomic_t cachefiles_lookup_histogram[HZ];
57811-extern atomic_t cachefiles_mkdir_histogram[HZ];
57812-extern atomic_t cachefiles_create_histogram[HZ];
57813+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57814+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57815+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57816
57817 extern int __init cachefiles_proc_init(void);
57818 extern void cachefiles_proc_cleanup(void);
57819 static inline
57820-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57821+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57822 {
57823 unsigned long jif = jiffies - start_jif;
57824 if (jif >= HZ)
57825 jif = HZ - 1;
57826- atomic_inc(&histogram[jif]);
57827+ atomic_inc_unchecked(&histogram[jif]);
57828 }
57829
57830 #else
57831diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57832index c0a6817..ea811166 100644
57833--- a/fs/cachefiles/namei.c
57834+++ b/fs/cachefiles/namei.c
57835@@ -317,7 +317,7 @@ try_again:
57836 /* first step is to make up a grave dentry in the graveyard */
57837 sprintf(nbuffer, "%08x%08x",
57838 (uint32_t) get_seconds(),
57839- (uint32_t) atomic_inc_return(&cache->gravecounter));
57840+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57841
57842 /* do the multiway lock magic */
57843 trap = lock_rename(cache->graveyard, dir);
57844diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57845index eccd339..4c1d995 100644
57846--- a/fs/cachefiles/proc.c
57847+++ b/fs/cachefiles/proc.c
57848@@ -14,9 +14,9 @@
57849 #include <linux/seq_file.h>
57850 #include "internal.h"
57851
57852-atomic_t cachefiles_lookup_histogram[HZ];
57853-atomic_t cachefiles_mkdir_histogram[HZ];
57854-atomic_t cachefiles_create_histogram[HZ];
57855+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57856+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57857+atomic_unchecked_t cachefiles_create_histogram[HZ];
57858
57859 /*
57860 * display the latency histogram
57861@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57862 return 0;
57863 default:
57864 index = (unsigned long) v - 3;
57865- x = atomic_read(&cachefiles_lookup_histogram[index]);
57866- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57867- z = atomic_read(&cachefiles_create_histogram[index]);
57868+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57869+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57870+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57871 if (x == 0 && y == 0 && z == 0)
57872 return 0;
57873
57874diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57875index 4b1fb5c..0d2a699 100644
57876--- a/fs/cachefiles/rdwr.c
57877+++ b/fs/cachefiles/rdwr.c
57878@@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57879 old_fs = get_fs();
57880 set_fs(KERNEL_DS);
57881 ret = file->f_op->write(
57882- file, (const void __user *) data, len, &pos);
57883+ file, (const void __force_user *) data, len, &pos);
57884 set_fs(old_fs);
57885 kunmap(page);
57886 file_end_write(file);
57887diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57888index c29d6ae..a56c4ae 100644
57889--- a/fs/ceph/dir.c
57890+++ b/fs/ceph/dir.c
57891@@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57892 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57893 struct ceph_mds_client *mdsc = fsc->mdsc;
57894 unsigned frag = fpos_frag(ctx->pos);
57895- int off = fpos_off(ctx->pos);
57896+ unsigned int off = fpos_off(ctx->pos);
57897 int err;
57898 u32 ftype;
57899 struct ceph_mds_reply_info_parsed *rinfo;
57900diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57901index 06150fd..192061b 100644
57902--- a/fs/ceph/super.c
57903+++ b/fs/ceph/super.c
57904@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57905 /*
57906 * construct our own bdi so we can control readahead, etc.
57907 */
57908-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57909+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57910
57911 static int ceph_register_bdi(struct super_block *sb,
57912 struct ceph_fs_client *fsc)
57913@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57914 default_backing_dev_info.ra_pages;
57915
57916 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57917- atomic_long_inc_return(&bdi_seq));
57918+ atomic_long_inc_return_unchecked(&bdi_seq));
57919 if (!err)
57920 sb->s_bdi = &fsc->backing_dev_info;
57921 return err;
57922diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57923index f3ac415..3d2420c 100644
57924--- a/fs/cifs/cifs_debug.c
57925+++ b/fs/cifs/cifs_debug.c
57926@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57927
57928 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57929 #ifdef CONFIG_CIFS_STATS2
57930- atomic_set(&totBufAllocCount, 0);
57931- atomic_set(&totSmBufAllocCount, 0);
57932+ atomic_set_unchecked(&totBufAllocCount, 0);
57933+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57934 #endif /* CONFIG_CIFS_STATS2 */
57935 spin_lock(&cifs_tcp_ses_lock);
57936 list_for_each(tmp1, &cifs_tcp_ses_list) {
57937@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57938 tcon = list_entry(tmp3,
57939 struct cifs_tcon,
57940 tcon_list);
57941- atomic_set(&tcon->num_smbs_sent, 0);
57942+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57943 if (server->ops->clear_stats)
57944 server->ops->clear_stats(tcon);
57945 }
57946@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57947 smBufAllocCount.counter, cifs_min_small);
57948 #ifdef CONFIG_CIFS_STATS2
57949 seq_printf(m, "Total Large %d Small %d Allocations\n",
57950- atomic_read(&totBufAllocCount),
57951- atomic_read(&totSmBufAllocCount));
57952+ atomic_read_unchecked(&totBufAllocCount),
57953+ atomic_read_unchecked(&totSmBufAllocCount));
57954 #endif /* CONFIG_CIFS_STATS2 */
57955
57956 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57957@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57958 if (tcon->need_reconnect)
57959 seq_puts(m, "\tDISCONNECTED ");
57960 seq_printf(m, "\nSMBs: %d",
57961- atomic_read(&tcon->num_smbs_sent));
57962+ atomic_read_unchecked(&tcon->num_smbs_sent));
57963 if (server->ops->print_stats)
57964 server->ops->print_stats(m, tcon);
57965 }
57966diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57967index 5be1f997..fa1015a1 100644
57968--- a/fs/cifs/cifsfs.c
57969+++ b/fs/cifs/cifsfs.c
57970@@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
57971 */
57972 cifs_req_cachep = kmem_cache_create("cifs_request",
57973 CIFSMaxBufSize + max_hdr_size, 0,
57974- SLAB_HWCACHE_ALIGN, NULL);
57975+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57976 if (cifs_req_cachep == NULL)
57977 return -ENOMEM;
57978
57979@@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
57980 efficient to alloc 1 per page off the slab compared to 17K (5page)
57981 alloc of large cifs buffers even when page debugging is on */
57982 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57983- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57984+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57985 NULL);
57986 if (cifs_sm_req_cachep == NULL) {
57987 mempool_destroy(cifs_req_poolp);
57988@@ -1180,8 +1180,8 @@ init_cifs(void)
57989 atomic_set(&bufAllocCount, 0);
57990 atomic_set(&smBufAllocCount, 0);
57991 #ifdef CONFIG_CIFS_STATS2
57992- atomic_set(&totBufAllocCount, 0);
57993- atomic_set(&totSmBufAllocCount, 0);
57994+ atomic_set_unchecked(&totBufAllocCount, 0);
57995+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57996 #endif /* CONFIG_CIFS_STATS2 */
57997
57998 atomic_set(&midCount, 0);
57999diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
58000index 30f6e92..e915ba5 100644
58001--- a/fs/cifs/cifsglob.h
58002+++ b/fs/cifs/cifsglob.h
58003@@ -806,35 +806,35 @@ struct cifs_tcon {
58004 __u16 Flags; /* optional support bits */
58005 enum statusEnum tidStatus;
58006 #ifdef CONFIG_CIFS_STATS
58007- atomic_t num_smbs_sent;
58008+ atomic_unchecked_t num_smbs_sent;
58009 union {
58010 struct {
58011- atomic_t num_writes;
58012- atomic_t num_reads;
58013- atomic_t num_flushes;
58014- atomic_t num_oplock_brks;
58015- atomic_t num_opens;
58016- atomic_t num_closes;
58017- atomic_t num_deletes;
58018- atomic_t num_mkdirs;
58019- atomic_t num_posixopens;
58020- atomic_t num_posixmkdirs;
58021- atomic_t num_rmdirs;
58022- atomic_t num_renames;
58023- atomic_t num_t2renames;
58024- atomic_t num_ffirst;
58025- atomic_t num_fnext;
58026- atomic_t num_fclose;
58027- atomic_t num_hardlinks;
58028- atomic_t num_symlinks;
58029- atomic_t num_locks;
58030- atomic_t num_acl_get;
58031- atomic_t num_acl_set;
58032+ atomic_unchecked_t num_writes;
58033+ atomic_unchecked_t num_reads;
58034+ atomic_unchecked_t num_flushes;
58035+ atomic_unchecked_t num_oplock_brks;
58036+ atomic_unchecked_t num_opens;
58037+ atomic_unchecked_t num_closes;
58038+ atomic_unchecked_t num_deletes;
58039+ atomic_unchecked_t num_mkdirs;
58040+ atomic_unchecked_t num_posixopens;
58041+ atomic_unchecked_t num_posixmkdirs;
58042+ atomic_unchecked_t num_rmdirs;
58043+ atomic_unchecked_t num_renames;
58044+ atomic_unchecked_t num_t2renames;
58045+ atomic_unchecked_t num_ffirst;
58046+ atomic_unchecked_t num_fnext;
58047+ atomic_unchecked_t num_fclose;
58048+ atomic_unchecked_t num_hardlinks;
58049+ atomic_unchecked_t num_symlinks;
58050+ atomic_unchecked_t num_locks;
58051+ atomic_unchecked_t num_acl_get;
58052+ atomic_unchecked_t num_acl_set;
58053 } cifs_stats;
58054 #ifdef CONFIG_CIFS_SMB2
58055 struct {
58056- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58057- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58058+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58059+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58060 } smb2_stats;
58061 #endif /* CONFIG_CIFS_SMB2 */
58062 } stats;
58063@@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
58064 }
58065
58066 #ifdef CONFIG_CIFS_STATS
58067-#define cifs_stats_inc atomic_inc
58068+#define cifs_stats_inc atomic_inc_unchecked
58069
58070 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58071 unsigned int bytes)
58072@@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58073 /* Various Debug counters */
58074 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58075 #ifdef CONFIG_CIFS_STATS2
58076-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58077-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58078+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58079+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58080 #endif
58081 GLOBAL_EXTERN atomic_t smBufAllocCount;
58082 GLOBAL_EXTERN atomic_t midCount;
58083diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58084index 5ed03e0..e9a3a6c 100644
58085--- a/fs/cifs/file.c
58086+++ b/fs/cifs/file.c
58087@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58088 index = mapping->writeback_index; /* Start from prev offset */
58089 end = -1;
58090 } else {
58091- index = wbc->range_start >> PAGE_CACHE_SHIFT;
58092- end = wbc->range_end >> PAGE_CACHE_SHIFT;
58093- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58094+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58095 range_whole = true;
58096+ index = 0;
58097+ end = ULONG_MAX;
58098+ } else {
58099+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
58100+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
58101+ }
58102 scanned = true;
58103 }
58104 retry:
58105diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58106index 3b0c62e..f7d090c 100644
58107--- a/fs/cifs/misc.c
58108+++ b/fs/cifs/misc.c
58109@@ -170,7 +170,7 @@ cifs_buf_get(void)
58110 memset(ret_buf, 0, buf_size + 3);
58111 atomic_inc(&bufAllocCount);
58112 #ifdef CONFIG_CIFS_STATS2
58113- atomic_inc(&totBufAllocCount);
58114+ atomic_inc_unchecked(&totBufAllocCount);
58115 #endif /* CONFIG_CIFS_STATS2 */
58116 }
58117
58118@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58119 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58120 atomic_inc(&smBufAllocCount);
58121 #ifdef CONFIG_CIFS_STATS2
58122- atomic_inc(&totSmBufAllocCount);
58123+ atomic_inc_unchecked(&totSmBufAllocCount);
58124 #endif /* CONFIG_CIFS_STATS2 */
58125
58126 }
58127diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58128index d1fdfa8..94558f8 100644
58129--- a/fs/cifs/smb1ops.c
58130+++ b/fs/cifs/smb1ops.c
58131@@ -626,27 +626,27 @@ static void
58132 cifs_clear_stats(struct cifs_tcon *tcon)
58133 {
58134 #ifdef CONFIG_CIFS_STATS
58135- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58136- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58137- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58138- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58139- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58140- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58141- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58142- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58143- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58144- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58145- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58146- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58147- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58148- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58149- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58150- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58151- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58152- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58153- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58154- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58155- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58156+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58157+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58158+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58159+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58160+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58161+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58162+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58163+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58164+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58165+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58166+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58167+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58168+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58169+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58170+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58171+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58172+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58173+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58174+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58175+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58176+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58177 #endif
58178 }
58179
58180@@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58181 {
58182 #ifdef CONFIG_CIFS_STATS
58183 seq_printf(m, " Oplocks breaks: %d",
58184- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58185+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58186 seq_printf(m, "\nReads: %d Bytes: %llu",
58187- atomic_read(&tcon->stats.cifs_stats.num_reads),
58188+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58189 (long long)(tcon->bytes_read));
58190 seq_printf(m, "\nWrites: %d Bytes: %llu",
58191- atomic_read(&tcon->stats.cifs_stats.num_writes),
58192+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58193 (long long)(tcon->bytes_written));
58194 seq_printf(m, "\nFlushes: %d",
58195- atomic_read(&tcon->stats.cifs_stats.num_flushes));
58196+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58197 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58198- atomic_read(&tcon->stats.cifs_stats.num_locks),
58199- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58200- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58201+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58202+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58203+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58204 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58205- atomic_read(&tcon->stats.cifs_stats.num_opens),
58206- atomic_read(&tcon->stats.cifs_stats.num_closes),
58207- atomic_read(&tcon->stats.cifs_stats.num_deletes));
58208+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58209+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58210+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58211 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58212- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58213- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58214+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58215+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58216 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58217- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58218- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58219+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58220+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58221 seq_printf(m, "\nRenames: %d T2 Renames %d",
58222- atomic_read(&tcon->stats.cifs_stats.num_renames),
58223- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58224+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58225+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58226 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58227- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58228- atomic_read(&tcon->stats.cifs_stats.num_fnext),
58229- atomic_read(&tcon->stats.cifs_stats.num_fclose));
58230+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58231+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58232+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58233 #endif
58234 }
58235
58236diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58237index 35ddc3e..563e809 100644
58238--- a/fs/cifs/smb2ops.c
58239+++ b/fs/cifs/smb2ops.c
58240@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58241 #ifdef CONFIG_CIFS_STATS
58242 int i;
58243 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58244- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58245- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58246+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58247+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58248 }
58249 #endif
58250 }
58251@@ -405,65 +405,65 @@ static void
58252 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58253 {
58254 #ifdef CONFIG_CIFS_STATS
58255- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58256- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58257+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58258+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58259 seq_printf(m, "\nNegotiates: %d sent %d failed",
58260- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58261- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58262+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58263+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58264 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58265- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58266- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58267+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58268+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58269 seq_printf(m, "\nLogoffs: %d sent %d failed",
58270- atomic_read(&sent[SMB2_LOGOFF_HE]),
58271- atomic_read(&failed[SMB2_LOGOFF_HE]));
58272+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58273+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58274 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58275- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58276- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58277+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58278+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58279 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58280- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58281- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58282+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58283+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58284 seq_printf(m, "\nCreates: %d sent %d failed",
58285- atomic_read(&sent[SMB2_CREATE_HE]),
58286- atomic_read(&failed[SMB2_CREATE_HE]));
58287+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58288+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58289 seq_printf(m, "\nCloses: %d sent %d failed",
58290- atomic_read(&sent[SMB2_CLOSE_HE]),
58291- atomic_read(&failed[SMB2_CLOSE_HE]));
58292+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58293+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58294 seq_printf(m, "\nFlushes: %d sent %d failed",
58295- atomic_read(&sent[SMB2_FLUSH_HE]),
58296- atomic_read(&failed[SMB2_FLUSH_HE]));
58297+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58298+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58299 seq_printf(m, "\nReads: %d sent %d failed",
58300- atomic_read(&sent[SMB2_READ_HE]),
58301- atomic_read(&failed[SMB2_READ_HE]));
58302+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
58303+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
58304 seq_printf(m, "\nWrites: %d sent %d failed",
58305- atomic_read(&sent[SMB2_WRITE_HE]),
58306- atomic_read(&failed[SMB2_WRITE_HE]));
58307+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58308+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58309 seq_printf(m, "\nLocks: %d sent %d failed",
58310- atomic_read(&sent[SMB2_LOCK_HE]),
58311- atomic_read(&failed[SMB2_LOCK_HE]));
58312+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58313+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58314 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58315- atomic_read(&sent[SMB2_IOCTL_HE]),
58316- atomic_read(&failed[SMB2_IOCTL_HE]));
58317+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58318+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58319 seq_printf(m, "\nCancels: %d sent %d failed",
58320- atomic_read(&sent[SMB2_CANCEL_HE]),
58321- atomic_read(&failed[SMB2_CANCEL_HE]));
58322+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58323+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58324 seq_printf(m, "\nEchos: %d sent %d failed",
58325- atomic_read(&sent[SMB2_ECHO_HE]),
58326- atomic_read(&failed[SMB2_ECHO_HE]));
58327+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58328+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58329 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58330- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58331- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58332+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58333+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58334 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58335- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58336- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58337+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58338+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58339 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58340- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58341- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58342+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58343+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58344 seq_printf(m, "\nSetInfos: %d sent %d failed",
58345- atomic_read(&sent[SMB2_SET_INFO_HE]),
58346- atomic_read(&failed[SMB2_SET_INFO_HE]));
58347+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58348+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58349 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58350- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58351- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58352+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58353+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58354 #endif
58355 }
58356
58357diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58358index 1fb6ad2..758e171 100644
58359--- a/fs/cifs/smb2pdu.c
58360+++ b/fs/cifs/smb2pdu.c
58361@@ -2097,8 +2097,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58362 default:
58363 cifs_dbg(VFS, "info level %u isn't supported\n",
58364 srch_inf->info_level);
58365- rc = -EINVAL;
58366- goto qdir_exit;
58367+ return -EINVAL;
58368 }
58369
58370 req->FileIndex = cpu_to_le32(index);
58371diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58372index 1da168c..8bc7ff6 100644
58373--- a/fs/coda/cache.c
58374+++ b/fs/coda/cache.c
58375@@ -24,7 +24,7 @@
58376 #include "coda_linux.h"
58377 #include "coda_cache.h"
58378
58379-static atomic_t permission_epoch = ATOMIC_INIT(0);
58380+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58381
58382 /* replace or extend an acl cache hit */
58383 void coda_cache_enter(struct inode *inode, int mask)
58384@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58385 struct coda_inode_info *cii = ITOC(inode);
58386
58387 spin_lock(&cii->c_lock);
58388- cii->c_cached_epoch = atomic_read(&permission_epoch);
58389+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58390 if (!uid_eq(cii->c_uid, current_fsuid())) {
58391 cii->c_uid = current_fsuid();
58392 cii->c_cached_perm = mask;
58393@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58394 {
58395 struct coda_inode_info *cii = ITOC(inode);
58396 spin_lock(&cii->c_lock);
58397- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58398+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58399 spin_unlock(&cii->c_lock);
58400 }
58401
58402 /* remove all acl caches */
58403 void coda_cache_clear_all(struct super_block *sb)
58404 {
58405- atomic_inc(&permission_epoch);
58406+ atomic_inc_unchecked(&permission_epoch);
58407 }
58408
58409
58410@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58411 spin_lock(&cii->c_lock);
58412 hit = (mask & cii->c_cached_perm) == mask &&
58413 uid_eq(cii->c_uid, current_fsuid()) &&
58414- cii->c_cached_epoch == atomic_read(&permission_epoch);
58415+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58416 spin_unlock(&cii->c_lock);
58417
58418 return hit;
58419diff --git a/fs/compat.c b/fs/compat.c
58420index 66d3d3c..9c10175 100644
58421--- a/fs/compat.c
58422+++ b/fs/compat.c
58423@@ -54,7 +54,7 @@
58424 #include <asm/ioctls.h>
58425 #include "internal.h"
58426
58427-int compat_log = 1;
58428+int compat_log = 0;
58429
58430 int compat_printk(const char *fmt, ...)
58431 {
58432@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
58433
58434 set_fs(KERNEL_DS);
58435 /* The __user pointer cast is valid because of the set_fs() */
58436- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58437+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58438 set_fs(oldfs);
58439 /* truncating is ok because it's a user address */
58440 if (!ret)
58441@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58442 goto out;
58443
58444 ret = -EINVAL;
58445- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58446+ if (nr_segs > UIO_MAXIOV)
58447 goto out;
58448 if (nr_segs > fast_segs) {
58449 ret = -ENOMEM;
58450@@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
58451 struct compat_readdir_callback {
58452 struct dir_context ctx;
58453 struct compat_old_linux_dirent __user *dirent;
58454+ struct file * file;
58455 int result;
58456 };
58457
58458@@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58459 buf->result = -EOVERFLOW;
58460 return -EOVERFLOW;
58461 }
58462+
58463+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58464+ return 0;
58465+
58466 buf->result++;
58467 dirent = buf->dirent;
58468 if (!access_ok(VERIFY_WRITE, dirent,
58469@@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58470 if (!f.file)
58471 return -EBADF;
58472
58473+ buf.file = f.file;
58474 error = iterate_dir(f.file, &buf.ctx);
58475 if (buf.result)
58476 error = buf.result;
58477@@ -917,6 +923,7 @@ struct compat_getdents_callback {
58478 struct dir_context ctx;
58479 struct compat_linux_dirent __user *current_dir;
58480 struct compat_linux_dirent __user *previous;
58481+ struct file * file;
58482 int count;
58483 int error;
58484 };
58485@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58486 buf->error = -EOVERFLOW;
58487 return -EOVERFLOW;
58488 }
58489+
58490+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58491+ return 0;
58492+
58493 dirent = buf->previous;
58494 if (dirent) {
58495 if (__put_user(offset, &dirent->d_off))
58496@@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58497 if (!f.file)
58498 return -EBADF;
58499
58500+ buf.file = f.file;
58501 error = iterate_dir(f.file, &buf.ctx);
58502 if (error >= 0)
58503 error = buf.error;
58504@@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58505 struct dir_context ctx;
58506 struct linux_dirent64 __user *current_dir;
58507 struct linux_dirent64 __user *previous;
58508+ struct file * file;
58509 int count;
58510 int error;
58511 };
58512@@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58513 buf->error = -EINVAL; /* only used if we fail.. */
58514 if (reclen > buf->count)
58515 return -EINVAL;
58516+
58517+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58518+ return 0;
58519+
58520 dirent = buf->previous;
58521
58522 if (dirent) {
58523@@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58524 if (!f.file)
58525 return -EBADF;
58526
58527+ buf.file = f.file;
58528 error = iterate_dir(f.file, &buf.ctx);
58529 if (error >= 0)
58530 error = buf.error;
58531diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58532index 4d24d17..4f8c09e 100644
58533--- a/fs/compat_binfmt_elf.c
58534+++ b/fs/compat_binfmt_elf.c
58535@@ -30,11 +30,13 @@
58536 #undef elf_phdr
58537 #undef elf_shdr
58538 #undef elf_note
58539+#undef elf_dyn
58540 #undef elf_addr_t
58541 #define elfhdr elf32_hdr
58542 #define elf_phdr elf32_phdr
58543 #define elf_shdr elf32_shdr
58544 #define elf_note elf32_note
58545+#define elf_dyn Elf32_Dyn
58546 #define elf_addr_t Elf32_Addr
58547
58548 /*
58549diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58550index e822890..fed89d9 100644
58551--- a/fs/compat_ioctl.c
58552+++ b/fs/compat_ioctl.c
58553@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58554 return -EFAULT;
58555 if (__get_user(udata, &ss32->iomem_base))
58556 return -EFAULT;
58557- ss.iomem_base = compat_ptr(udata);
58558+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58559 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58560 __get_user(ss.port_high, &ss32->port_high))
58561 return -EFAULT;
58562@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58563 for (i = 0; i < nmsgs; i++) {
58564 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58565 return -EFAULT;
58566- if (get_user(datap, &umsgs[i].buf) ||
58567- put_user(compat_ptr(datap), &tmsgs[i].buf))
58568+ if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
58569+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58570 return -EFAULT;
58571 }
58572 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58573@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58574 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58575 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58576 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58577- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58578+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58579 return -EFAULT;
58580
58581 return ioctl_preallocate(file, p);
58582@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58583 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58584 {
58585 unsigned int a, b;
58586- a = *(unsigned int *)p;
58587- b = *(unsigned int *)q;
58588+ a = *(const unsigned int *)p;
58589+ b = *(const unsigned int *)q;
58590 if (a > b)
58591 return 1;
58592 if (a < b)
58593diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58594index e081acb..911df21 100644
58595--- a/fs/configfs/dir.c
58596+++ b/fs/configfs/dir.c
58597@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58598 }
58599 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58600 struct configfs_dirent *next;
58601- const char *name;
58602+ const unsigned char * name;
58603+ char d_name[sizeof(next->s_dentry->d_iname)];
58604 int len;
58605 struct inode *inode = NULL;
58606
58607@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58608 continue;
58609
58610 name = configfs_get_name(next);
58611- len = strlen(name);
58612+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58613+ len = next->s_dentry->d_name.len;
58614+ memcpy(d_name, name, len);
58615+ name = d_name;
58616+ } else
58617+ len = strlen(name);
58618
58619 /*
58620 * We'll have a dentry and an inode for
58621diff --git a/fs/coredump.c b/fs/coredump.c
58622index a93f7e6..d58bcbe 100644
58623--- a/fs/coredump.c
58624+++ b/fs/coredump.c
58625@@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58626 struct pipe_inode_info *pipe = file->private_data;
58627
58628 pipe_lock(pipe);
58629- pipe->readers++;
58630- pipe->writers--;
58631+ atomic_inc(&pipe->readers);
58632+ atomic_dec(&pipe->writers);
58633 wake_up_interruptible_sync(&pipe->wait);
58634 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58635 pipe_unlock(pipe);
58636@@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58637 * We actually want wait_event_freezable() but then we need
58638 * to clear TIF_SIGPENDING and improve dump_interrupted().
58639 */
58640- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58641+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58642
58643 pipe_lock(pipe);
58644- pipe->readers--;
58645- pipe->writers++;
58646+ atomic_dec(&pipe->readers);
58647+ atomic_inc(&pipe->writers);
58648 pipe_unlock(pipe);
58649 }
58650
58651@@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58652 struct files_struct *displaced;
58653 bool need_nonrelative = false;
58654 bool core_dumped = false;
58655- static atomic_t core_dump_count = ATOMIC_INIT(0);
58656+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58657+ long signr = siginfo->si_signo;
58658+ int dumpable;
58659 struct coredump_params cprm = {
58660 .siginfo = siginfo,
58661 .regs = signal_pt_regs(),
58662@@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58663 .mm_flags = mm->flags,
58664 };
58665
58666- audit_core_dumps(siginfo->si_signo);
58667+ audit_core_dumps(signr);
58668+
58669+ dumpable = __get_dumpable(cprm.mm_flags);
58670+
58671+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58672+ gr_handle_brute_attach(dumpable);
58673
58674 binfmt = mm->binfmt;
58675 if (!binfmt || !binfmt->core_dump)
58676 goto fail;
58677- if (!__get_dumpable(cprm.mm_flags))
58678+ if (!dumpable)
58679 goto fail;
58680
58681 cred = prepare_creds();
58682@@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58683 need_nonrelative = true;
58684 }
58685
58686- retval = coredump_wait(siginfo->si_signo, &core_state);
58687+ retval = coredump_wait(signr, &core_state);
58688 if (retval < 0)
58689 goto fail_creds;
58690
58691@@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58692 }
58693 cprm.limit = RLIM_INFINITY;
58694
58695- dump_count = atomic_inc_return(&core_dump_count);
58696+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58697 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58698 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58699 task_tgid_vnr(current), current->comm);
58700@@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58701 } else {
58702 struct inode *inode;
58703
58704+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58705+
58706 if (cprm.limit < binfmt->min_coredump)
58707 goto fail_unlock;
58708
58709@@ -673,7 +682,7 @@ close_fail:
58710 filp_close(cprm.file, NULL);
58711 fail_dropcount:
58712 if (ispipe)
58713- atomic_dec(&core_dump_count);
58714+ atomic_dec_unchecked(&core_dump_count);
58715 fail_unlock:
58716 kfree(cn.corename);
58717 coredump_finish(mm, core_dumped);
58718@@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58719 struct file *file = cprm->file;
58720 loff_t pos = file->f_pos;
58721 ssize_t n;
58722+
58723+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58724 if (cprm->written + nr > cprm->limit)
58725 return 0;
58726 while (nr) {
58727diff --git a/fs/dcache.c b/fs/dcache.c
58728index e99c6f5..2838bf58 100644
58729--- a/fs/dcache.c
58730+++ b/fs/dcache.c
58731@@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58732 */
58733 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58734 if (name->len > DNAME_INLINE_LEN-1) {
58735- dname = kmalloc(name->len + 1, GFP_KERNEL);
58736+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58737 if (!dname) {
58738 kmem_cache_free(dentry_cache, dentry);
58739 return NULL;
58740@@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58741 mempages -= reserve;
58742
58743 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58744- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58745+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58746+ SLAB_NO_SANITIZE, NULL);
58747
58748 dcache_init();
58749 inode_init();
58750diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58751index 8c41b52..145b1b9 100644
58752--- a/fs/debugfs/inode.c
58753+++ b/fs/debugfs/inode.c
58754@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58755 */
58756 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58757 {
58758+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58759+ return __create_file(name, S_IFDIR | S_IRWXU,
58760+#else
58761 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58762+#endif
58763 parent, NULL, NULL);
58764 }
58765 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58766diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58767index d4a9431..77f9b2e 100644
58768--- a/fs/ecryptfs/inode.c
58769+++ b/fs/ecryptfs/inode.c
58770@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58771 old_fs = get_fs();
58772 set_fs(get_ds());
58773 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58774- (char __user *)lower_buf,
58775+ (char __force_user *)lower_buf,
58776 PATH_MAX);
58777 set_fs(old_fs);
58778 if (rc < 0)
58779diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58780index e4141f2..d8263e8 100644
58781--- a/fs/ecryptfs/miscdev.c
58782+++ b/fs/ecryptfs/miscdev.c
58783@@ -304,7 +304,7 @@ check_list:
58784 goto out_unlock_msg_ctx;
58785 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58786 if (msg_ctx->msg) {
58787- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58788+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58789 goto out_unlock_msg_ctx;
58790 i += packet_length_size;
58791 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58792diff --git a/fs/exec.c b/fs/exec.c
58793index 238b7aa..a421d91 100644
58794--- a/fs/exec.c
58795+++ b/fs/exec.c
58796@@ -56,8 +56,20 @@
58797 #include <linux/pipe_fs_i.h>
58798 #include <linux/oom.h>
58799 #include <linux/compat.h>
58800+#include <linux/random.h>
58801+#include <linux/seq_file.h>
58802+#include <linux/coredump.h>
58803+#include <linux/mman.h>
58804+
58805+#ifdef CONFIG_PAX_REFCOUNT
58806+#include <linux/kallsyms.h>
58807+#include <linux/kdebug.h>
58808+#endif
58809+
58810+#include <trace/events/fs.h>
58811
58812 #include <asm/uaccess.h>
58813+#include <asm/sections.h>
58814 #include <asm/mmu_context.h>
58815 #include <asm/tlb.h>
58816
58817@@ -66,19 +78,34 @@
58818
58819 #include <trace/events/sched.h>
58820
58821+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58822+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58823+{
58824+ 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");
58825+}
58826+#endif
58827+
58828+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58829+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58830+EXPORT_SYMBOL(pax_set_initial_flags_func);
58831+#endif
58832+
58833 int suid_dumpable = 0;
58834
58835 static LIST_HEAD(formats);
58836 static DEFINE_RWLOCK(binfmt_lock);
58837
58838+extern int gr_process_kernel_exec_ban(void);
58839+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58840+
58841 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58842 {
58843 BUG_ON(!fmt);
58844 if (WARN_ON(!fmt->load_binary))
58845 return;
58846 write_lock(&binfmt_lock);
58847- insert ? list_add(&fmt->lh, &formats) :
58848- list_add_tail(&fmt->lh, &formats);
58849+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58850+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58851 write_unlock(&binfmt_lock);
58852 }
58853
58854@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58855 void unregister_binfmt(struct linux_binfmt * fmt)
58856 {
58857 write_lock(&binfmt_lock);
58858- list_del(&fmt->lh);
58859+ pax_list_del((struct list_head *)&fmt->lh);
58860 write_unlock(&binfmt_lock);
58861 }
58862
58863@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58864 int write)
58865 {
58866 struct page *page;
58867- int ret;
58868
58869-#ifdef CONFIG_STACK_GROWSUP
58870- if (write) {
58871- ret = expand_downwards(bprm->vma, pos);
58872- if (ret < 0)
58873- return NULL;
58874- }
58875-#endif
58876- ret = get_user_pages(current, bprm->mm, pos,
58877- 1, write, 1, &page, NULL);
58878- if (ret <= 0)
58879+ if (0 > expand_downwards(bprm->vma, pos))
58880+ return NULL;
58881+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58882 return NULL;
58883
58884 if (write) {
58885@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58886 if (size <= ARG_MAX)
58887 return page;
58888
58889+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58890+ // only allow 512KB for argv+env on suid/sgid binaries
58891+ // to prevent easy ASLR exhaustion
58892+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58893+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58894+ (size > (512 * 1024))) {
58895+ put_page(page);
58896+ return NULL;
58897+ }
58898+#endif
58899+
58900 /*
58901 * Limit to 1/4-th the stack size for the argv+env strings.
58902 * This ensures that:
58903@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58904 vma->vm_end = STACK_TOP_MAX;
58905 vma->vm_start = vma->vm_end - PAGE_SIZE;
58906 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58907+
58908+#ifdef CONFIG_PAX_SEGMEXEC
58909+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58910+#endif
58911+
58912 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58913 INIT_LIST_HEAD(&vma->anon_vma_chain);
58914
58915@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58916 mm->stack_vm = mm->total_vm = 1;
58917 up_write(&mm->mmap_sem);
58918 bprm->p = vma->vm_end - sizeof(void *);
58919+
58920+#ifdef CONFIG_PAX_RANDUSTACK
58921+ if (randomize_va_space)
58922+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58923+#endif
58924+
58925 return 0;
58926 err:
58927 up_write(&mm->mmap_sem);
58928@@ -399,7 +440,7 @@ struct user_arg_ptr {
58929 } ptr;
58930 };
58931
58932-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58933+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58934 {
58935 const char __user *native;
58936
58937@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58938 compat_uptr_t compat;
58939
58940 if (get_user(compat, argv.ptr.compat + nr))
58941- return ERR_PTR(-EFAULT);
58942+ return (const char __force_user *)ERR_PTR(-EFAULT);
58943
58944 return compat_ptr(compat);
58945 }
58946 #endif
58947
58948 if (get_user(native, argv.ptr.native + nr))
58949- return ERR_PTR(-EFAULT);
58950+ return (const char __force_user *)ERR_PTR(-EFAULT);
58951
58952 return native;
58953 }
58954@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
58955 if (!p)
58956 break;
58957
58958- if (IS_ERR(p))
58959+ if (IS_ERR((const char __force_kernel *)p))
58960 return -EFAULT;
58961
58962 if (i >= max)
58963@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58964
58965 ret = -EFAULT;
58966 str = get_user_arg_ptr(argv, argc);
58967- if (IS_ERR(str))
58968+ if (IS_ERR((const char __force_kernel *)str))
58969 goto out;
58970
58971 len = strnlen_user(str, MAX_ARG_STRLEN);
58972@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58973 int r;
58974 mm_segment_t oldfs = get_fs();
58975 struct user_arg_ptr argv = {
58976- .ptr.native = (const char __user *const __user *)__argv,
58977+ .ptr.native = (const char __user * const __force_user *)__argv,
58978 };
58979
58980 set_fs(KERNEL_DS);
58981@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58982 unsigned long new_end = old_end - shift;
58983 struct mmu_gather tlb;
58984
58985- BUG_ON(new_start > new_end);
58986+ if (new_start >= new_end || new_start < mmap_min_addr)
58987+ return -ENOMEM;
58988
58989 /*
58990 * ensure there are no vmas between where we want to go
58991@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58992 if (vma != find_vma(mm, new_start))
58993 return -EFAULT;
58994
58995+#ifdef CONFIG_PAX_SEGMEXEC
58996+ BUG_ON(pax_find_mirror_vma(vma));
58997+#endif
58998+
58999 /*
59000 * cover the whole range: [new_start, old_end)
59001 */
59002@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59003 stack_top = arch_align_stack(stack_top);
59004 stack_top = PAGE_ALIGN(stack_top);
59005
59006- if (unlikely(stack_top < mmap_min_addr) ||
59007- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
59008- return -ENOMEM;
59009-
59010 stack_shift = vma->vm_end - stack_top;
59011
59012 bprm->p -= stack_shift;
59013@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
59014 bprm->exec -= stack_shift;
59015
59016 down_write(&mm->mmap_sem);
59017+
59018+ /* Move stack pages down in memory. */
59019+ if (stack_shift) {
59020+ ret = shift_arg_pages(vma, stack_shift);
59021+ if (ret)
59022+ goto out_unlock;
59023+ }
59024+
59025 vm_flags = VM_STACK_FLAGS;
59026
59027+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59028+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59029+ vm_flags &= ~VM_EXEC;
59030+
59031+#ifdef CONFIG_PAX_MPROTECT
59032+ if (mm->pax_flags & MF_PAX_MPROTECT)
59033+ vm_flags &= ~VM_MAYEXEC;
59034+#endif
59035+
59036+ }
59037+#endif
59038+
59039 /*
59040 * Adjust stack execute permissions; explicitly enable for
59041 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59042@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59043 goto out_unlock;
59044 BUG_ON(prev != vma);
59045
59046- /* Move stack pages down in memory. */
59047- if (stack_shift) {
59048- ret = shift_arg_pages(vma, stack_shift);
59049- if (ret)
59050- goto out_unlock;
59051- }
59052-
59053 /* mprotect_fixup is overkill to remove the temporary stack flags */
59054 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59055
59056@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59057 #endif
59058 current->mm->start_stack = bprm->p;
59059 ret = expand_stack(vma, stack_base);
59060+
59061+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59062+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59063+ unsigned long size;
59064+ vm_flags_t vm_flags;
59065+
59066+ size = STACK_TOP - vma->vm_end;
59067+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59068+
59069+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59070+
59071+#ifdef CONFIG_X86
59072+ if (!ret) {
59073+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59074+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59075+ }
59076+#endif
59077+
59078+ }
59079+#endif
59080+
59081 if (ret)
59082 ret = -EFAULT;
59083
59084@@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
59085
59086 fsnotify_open(file);
59087
59088+ trace_open_exec(name->name);
59089+
59090 err = deny_write_access(file);
59091 if (err)
59092 goto exit;
59093@@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
59094 old_fs = get_fs();
59095 set_fs(get_ds());
59096 /* The cast to a user pointer is valid due to the set_fs() */
59097- result = vfs_read(file, (void __user *)addr, count, &pos);
59098+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
59099 set_fs(old_fs);
59100 return result;
59101 }
59102@@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
59103 tsk->mm = mm;
59104 tsk->active_mm = mm;
59105 activate_mm(active_mm, mm);
59106+ populate_stack();
59107 tsk->mm->vmacache_seqnum = 0;
59108 vmacache_flush(tsk);
59109 task_unlock(tsk);
59110@@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59111 }
59112 rcu_read_unlock();
59113
59114- if (p->fs->users > n_fs)
59115+ if (atomic_read(&p->fs->users) > n_fs)
59116 bprm->unsafe |= LSM_UNSAFE_SHARE;
59117 else
59118 p->fs->in_exec = 1;
59119@@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59120 return ret;
59121 }
59122
59123+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59124+static DEFINE_PER_CPU(u64, exec_counter);
59125+static int __init init_exec_counters(void)
59126+{
59127+ unsigned int cpu;
59128+
59129+ for_each_possible_cpu(cpu) {
59130+ per_cpu(exec_counter, cpu) = (u64)cpu;
59131+ }
59132+
59133+ return 0;
59134+}
59135+early_initcall(init_exec_counters);
59136+static inline void increment_exec_counter(void)
59137+{
59138+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
59139+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59140+}
59141+#else
59142+static inline void increment_exec_counter(void) {}
59143+#endif
59144+
59145+extern void gr_handle_exec_args(struct linux_binprm *bprm,
59146+ struct user_arg_ptr argv);
59147+
59148 /*
59149 * sys_execve() executes a new program.
59150 */
59151@@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
59152 struct user_arg_ptr argv,
59153 struct user_arg_ptr envp)
59154 {
59155+#ifdef CONFIG_GRKERNSEC
59156+ struct file *old_exec_file;
59157+ struct acl_subject_label *old_acl;
59158+ struct rlimit old_rlim[RLIM_NLIMITS];
59159+#endif
59160 struct linux_binprm *bprm;
59161 struct file *file;
59162 struct files_struct *displaced;
59163@@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
59164 if (IS_ERR(filename))
59165 return PTR_ERR(filename);
59166
59167+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59168+
59169 /*
59170 * We move the actual failure in case of RLIMIT_NPROC excess from
59171 * set*uid() to execve() because too many poorly written programs
59172@@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
59173 if (IS_ERR(file))
59174 goto out_unmark;
59175
59176+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
59177+ retval = -EPERM;
59178+ goto out_unmark;
59179+ }
59180+
59181 sched_exec();
59182
59183 bprm->file = file;
59184 bprm->filename = bprm->interp = filename->name;
59185
59186+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59187+ retval = -EACCES;
59188+ goto out_unmark;
59189+ }
59190+
59191 retval = bprm_mm_init(bprm);
59192 if (retval)
59193 goto out_unmark;
59194@@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
59195 if (retval < 0)
59196 goto out;
59197
59198+#ifdef CONFIG_GRKERNSEC
59199+ old_acl = current->acl;
59200+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59201+ old_exec_file = current->exec_file;
59202+ get_file(file);
59203+ current->exec_file = file;
59204+#endif
59205+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59206+ /* limit suid stack to 8MB
59207+ * we saved the old limits above and will restore them if this exec fails
59208+ */
59209+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59210+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59211+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59212+#endif
59213+
59214+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59215+ retval = -EPERM;
59216+ goto out_fail;
59217+ }
59218+
59219+ if (!gr_tpe_allow(file)) {
59220+ retval = -EACCES;
59221+ goto out_fail;
59222+ }
59223+
59224+ if (gr_check_crash_exec(file)) {
59225+ retval = -EACCES;
59226+ goto out_fail;
59227+ }
59228+
59229+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59230+ bprm->unsafe);
59231+ if (retval < 0)
59232+ goto out_fail;
59233+
59234 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59235 if (retval < 0)
59236- goto out;
59237+ goto out_fail;
59238
59239 bprm->exec = bprm->p;
59240 retval = copy_strings(bprm->envc, envp, bprm);
59241 if (retval < 0)
59242- goto out;
59243+ goto out_fail;
59244
59245 retval = copy_strings(bprm->argc, argv, bprm);
59246 if (retval < 0)
59247- goto out;
59248+ goto out_fail;
59249+
59250+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59251+
59252+ gr_handle_exec_args(bprm, argv);
59253
59254 retval = exec_binprm(bprm);
59255 if (retval < 0)
59256- goto out;
59257+ goto out_fail;
59258+#ifdef CONFIG_GRKERNSEC
59259+ if (old_exec_file)
59260+ fput(old_exec_file);
59261+#endif
59262
59263 /* execve succeeded */
59264+
59265+ increment_exec_counter();
59266 current->fs->in_exec = 0;
59267 current->in_execve = 0;
59268 acct_update_integrals(current);
59269@@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
59270 put_files_struct(displaced);
59271 return retval;
59272
59273+out_fail:
59274+#ifdef CONFIG_GRKERNSEC
59275+ current->acl = old_acl;
59276+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59277+ fput(current->exec_file);
59278+ current->exec_file = old_exec_file;
59279+#endif
59280+
59281 out:
59282 if (bprm->mm) {
59283 acct_arg_size(bprm, 0);
59284@@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
59285 return compat_do_execve(getname(filename), argv, envp);
59286 }
59287 #endif
59288+
59289+int pax_check_flags(unsigned long *flags)
59290+{
59291+ int retval = 0;
59292+
59293+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59294+ if (*flags & MF_PAX_SEGMEXEC)
59295+ {
59296+ *flags &= ~MF_PAX_SEGMEXEC;
59297+ retval = -EINVAL;
59298+ }
59299+#endif
59300+
59301+ if ((*flags & MF_PAX_PAGEEXEC)
59302+
59303+#ifdef CONFIG_PAX_PAGEEXEC
59304+ && (*flags & MF_PAX_SEGMEXEC)
59305+#endif
59306+
59307+ )
59308+ {
59309+ *flags &= ~MF_PAX_PAGEEXEC;
59310+ retval = -EINVAL;
59311+ }
59312+
59313+ if ((*flags & MF_PAX_MPROTECT)
59314+
59315+#ifdef CONFIG_PAX_MPROTECT
59316+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59317+#endif
59318+
59319+ )
59320+ {
59321+ *flags &= ~MF_PAX_MPROTECT;
59322+ retval = -EINVAL;
59323+ }
59324+
59325+ if ((*flags & MF_PAX_EMUTRAMP)
59326+
59327+#ifdef CONFIG_PAX_EMUTRAMP
59328+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59329+#endif
59330+
59331+ )
59332+ {
59333+ *flags &= ~MF_PAX_EMUTRAMP;
59334+ retval = -EINVAL;
59335+ }
59336+
59337+ return retval;
59338+}
59339+
59340+EXPORT_SYMBOL(pax_check_flags);
59341+
59342+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59343+char *pax_get_path(const struct path *path, char *buf, int buflen)
59344+{
59345+ char *pathname = d_path(path, buf, buflen);
59346+
59347+ if (IS_ERR(pathname))
59348+ goto toolong;
59349+
59350+ pathname = mangle_path(buf, pathname, "\t\n\\");
59351+ if (!pathname)
59352+ goto toolong;
59353+
59354+ *pathname = 0;
59355+ return buf;
59356+
59357+toolong:
59358+ return "<path too long>";
59359+}
59360+EXPORT_SYMBOL(pax_get_path);
59361+
59362+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59363+{
59364+ struct task_struct *tsk = current;
59365+ struct mm_struct *mm = current->mm;
59366+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59367+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59368+ char *path_exec = NULL;
59369+ char *path_fault = NULL;
59370+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
59371+ siginfo_t info = { };
59372+
59373+ if (buffer_exec && buffer_fault) {
59374+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59375+
59376+ down_read(&mm->mmap_sem);
59377+ vma = mm->mmap;
59378+ while (vma && (!vma_exec || !vma_fault)) {
59379+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59380+ vma_exec = vma;
59381+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59382+ vma_fault = vma;
59383+ vma = vma->vm_next;
59384+ }
59385+ if (vma_exec)
59386+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59387+ if (vma_fault) {
59388+ start = vma_fault->vm_start;
59389+ end = vma_fault->vm_end;
59390+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59391+ if (vma_fault->vm_file)
59392+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59393+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59394+ path_fault = "<heap>";
59395+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59396+ path_fault = "<stack>";
59397+ else
59398+ path_fault = "<anonymous mapping>";
59399+ }
59400+ up_read(&mm->mmap_sem);
59401+ }
59402+ if (tsk->signal->curr_ip)
59403+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59404+ else
59405+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59406+ 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),
59407+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59408+ free_page((unsigned long)buffer_exec);
59409+ free_page((unsigned long)buffer_fault);
59410+ pax_report_insns(regs, pc, sp);
59411+ info.si_signo = SIGKILL;
59412+ info.si_errno = 0;
59413+ info.si_code = SI_KERNEL;
59414+ info.si_pid = 0;
59415+ info.si_uid = 0;
59416+ do_coredump(&info);
59417+}
59418+#endif
59419+
59420+#ifdef CONFIG_PAX_REFCOUNT
59421+void pax_report_refcount_overflow(struct pt_regs *regs)
59422+{
59423+ if (current->signal->curr_ip)
59424+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59425+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59426+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59427+ else
59428+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59429+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59430+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59431+ preempt_disable();
59432+ show_regs(regs);
59433+ preempt_enable();
59434+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59435+}
59436+#endif
59437+
59438+#ifdef CONFIG_PAX_USERCOPY
59439+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59440+static noinline int check_stack_object(const void *obj, unsigned long len)
59441+{
59442+ const void * const stack = task_stack_page(current);
59443+ const void * const stackend = stack + THREAD_SIZE;
59444+
59445+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59446+ const void *frame = NULL;
59447+ const void *oldframe;
59448+#endif
59449+
59450+ if (obj + len < obj)
59451+ return -1;
59452+
59453+ if (obj + len <= stack || stackend <= obj)
59454+ return 0;
59455+
59456+ if (obj < stack || stackend < obj + len)
59457+ return -1;
59458+
59459+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59460+ oldframe = __builtin_frame_address(1);
59461+ if (oldframe)
59462+ frame = __builtin_frame_address(2);
59463+ /*
59464+ low ----------------------------------------------> high
59465+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59466+ ^----------------^
59467+ allow copies only within here
59468+ */
59469+ while (stack <= frame && frame < stackend) {
59470+ /* if obj + len extends past the last frame, this
59471+ check won't pass and the next frame will be 0,
59472+ causing us to bail out and correctly report
59473+ the copy as invalid
59474+ */
59475+ if (obj + len <= frame)
59476+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59477+ oldframe = frame;
59478+ frame = *(const void * const *)frame;
59479+ }
59480+ return -1;
59481+#else
59482+ return 1;
59483+#endif
59484+}
59485+
59486+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59487+{
59488+ if (current->signal->curr_ip)
59489+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59490+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59491+ else
59492+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59493+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59494+ dump_stack();
59495+ gr_handle_kernel_exploit();
59496+ do_group_exit(SIGKILL);
59497+}
59498+#endif
59499+
59500+#ifdef CONFIG_PAX_USERCOPY
59501+
59502+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59503+{
59504+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59505+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59506+#ifdef CONFIG_MODULES
59507+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59508+#else
59509+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59510+#endif
59511+
59512+#else
59513+ unsigned long textlow = (unsigned long)_stext;
59514+ unsigned long texthigh = (unsigned long)_etext;
59515+
59516+#ifdef CONFIG_X86_64
59517+ /* check against linear mapping as well */
59518+ if (high > (unsigned long)__va(__pa(textlow)) &&
59519+ low < (unsigned long)__va(__pa(texthigh)))
59520+ return true;
59521+#endif
59522+
59523+#endif
59524+
59525+ if (high <= textlow || low >= texthigh)
59526+ return false;
59527+ else
59528+ return true;
59529+}
59530+#endif
59531+
59532+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59533+{
59534+#ifdef CONFIG_PAX_USERCOPY
59535+ const char *type;
59536+#endif
59537+
59538+#ifndef CONFIG_STACK_GROWSUP
59539+ unsigned long stackstart = (unsigned long)task_stack_page(current);
59540+ unsigned long currentsp = (unsigned long)&stackstart;
59541+ if (unlikely((currentsp < stackstart + 512 ||
59542+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59543+ BUG();
59544+#endif
59545+
59546+#ifndef CONFIG_PAX_USERCOPY_DEBUG
59547+ if (const_size)
59548+ return;
59549+#endif
59550+
59551+#ifdef CONFIG_PAX_USERCOPY
59552+ if (!n)
59553+ return;
59554+
59555+ type = check_heap_object(ptr, n);
59556+ if (!type) {
59557+ int ret = check_stack_object(ptr, n);
59558+ if (ret == 1 || ret == 2)
59559+ return;
59560+ if (ret == 0) {
59561+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59562+ type = "<kernel text>";
59563+ else
59564+ return;
59565+ } else
59566+ type = "<process stack>";
59567+ }
59568+
59569+ pax_report_usercopy(ptr, n, to_user, type);
59570+#endif
59571+
59572+}
59573+EXPORT_SYMBOL(__check_object_size);
59574+
59575+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59576+void pax_track_stack(void)
59577+{
59578+ unsigned long sp = (unsigned long)&sp;
59579+ if (sp < current_thread_info()->lowest_stack &&
59580+ sp > (unsigned long)task_stack_page(current))
59581+ current_thread_info()->lowest_stack = sp;
59582+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59583+ BUG();
59584+}
59585+EXPORT_SYMBOL(pax_track_stack);
59586+#endif
59587+
59588+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59589+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59590+{
59591+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59592+ dump_stack();
59593+ do_group_exit(SIGKILL);
59594+}
59595+EXPORT_SYMBOL(report_size_overflow);
59596+#endif
59597diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59598index 9f9992b..8b59411 100644
59599--- a/fs/ext2/balloc.c
59600+++ b/fs/ext2/balloc.c
59601@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59602
59603 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59604 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59605- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59606+ if (free_blocks < root_blocks + 1 &&
59607 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59608 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59609- !in_group_p (sbi->s_resgid))) {
59610+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59611 return 0;
59612 }
59613 return 1;
59614diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59615index 9142614..97484fa 100644
59616--- a/fs/ext2/xattr.c
59617+++ b/fs/ext2/xattr.c
59618@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59619 struct buffer_head *bh = NULL;
59620 struct ext2_xattr_entry *entry;
59621 char *end;
59622- size_t rest = buffer_size;
59623+ size_t rest = buffer_size, total_size = 0;
59624 int error;
59625
59626 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59627@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59628 buffer += size;
59629 }
59630 rest -= size;
59631+ total_size += size;
59632 }
59633 }
59634- error = buffer_size - rest; /* total size */
59635+ error = total_size;
59636
59637 cleanup:
59638 brelse(bh);
59639diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59640index 158b5d4..2432610 100644
59641--- a/fs/ext3/balloc.c
59642+++ b/fs/ext3/balloc.c
59643@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59644
59645 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59646 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59647- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59648+ if (free_blocks < root_blocks + 1 &&
59649 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59650 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59651- !in_group_p (sbi->s_resgid))) {
59652+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59653 return 0;
59654 }
59655 return 1;
59656diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59657index c6874be..f8a6ae8 100644
59658--- a/fs/ext3/xattr.c
59659+++ b/fs/ext3/xattr.c
59660@@ -330,7 +330,7 @@ static int
59661 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59662 char *buffer, size_t buffer_size)
59663 {
59664- size_t rest = buffer_size;
59665+ size_t rest = buffer_size, total_size = 0;
59666
59667 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59668 const struct xattr_handler *handler =
59669@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59670 buffer += size;
59671 }
59672 rest -= size;
59673+ total_size += size;
59674 }
59675 }
59676- return buffer_size - rest;
59677+ return total_size;
59678 }
59679
59680 static int
59681diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59682index 5c56785..77698a2 100644
59683--- a/fs/ext4/balloc.c
59684+++ b/fs/ext4/balloc.c
59685@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59686 /* Hm, nope. Are (enough) root reserved clusters available? */
59687 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59688 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59689- capable(CAP_SYS_RESOURCE) ||
59690- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59691+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59692+ capable_nolog(CAP_SYS_RESOURCE)) {
59693
59694 if (free_clusters >= (nclusters + dirty_clusters +
59695 resv_clusters))
59696diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59697index f542e48..c0275f5 100644
59698--- a/fs/ext4/ext4.h
59699+++ b/fs/ext4/ext4.h
59700@@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59701 unsigned long s_mb_last_start;
59702
59703 /* stats for buddy allocator */
59704- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59705- atomic_t s_bal_success; /* we found long enough chunks */
59706- atomic_t s_bal_allocated; /* in blocks */
59707- atomic_t s_bal_ex_scanned; /* total extents scanned */
59708- atomic_t s_bal_goals; /* goal hits */
59709- atomic_t s_bal_breaks; /* too long searches */
59710- atomic_t s_bal_2orders; /* 2^order hits */
59711+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59712+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59713+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59714+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59715+ atomic_unchecked_t s_bal_goals; /* goal hits */
59716+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59717+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59718 spinlock_t s_bal_lock;
59719 unsigned long s_mb_buddies_generated;
59720 unsigned long long s_mb_generation_time;
59721- atomic_t s_mb_lost_chunks;
59722- atomic_t s_mb_preallocated;
59723- atomic_t s_mb_discarded;
59724+ atomic_unchecked_t s_mb_lost_chunks;
59725+ atomic_unchecked_t s_mb_preallocated;
59726+ atomic_unchecked_t s_mb_discarded;
59727 atomic_t s_lock_busy;
59728
59729 /* locality groups */
59730diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
59731index e6574d7..c30cbe2 100644
59732--- a/fs/ext4/indirect.c
59733+++ b/fs/ext4/indirect.c
59734@@ -1345,8 +1345,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59735 if (level == 0 ||
59736 (bh && all_zeroes((__le32 *)bh->b_data,
59737 (__le32 *)bh->b_data + addr_per_block))) {
59738- ext4_free_data(handle, inode, parent_bh, &blk, &blk+1);
59739- *i_data = 0;
59740+ ext4_free_data(handle, inode, parent_bh,
59741+ i_data, i_data + 1);
59742 }
59743 brelse(bh);
59744 bh = NULL;
59745diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59746index 2735a72..d083044 100644
59747--- a/fs/ext4/mballoc.c
59748+++ b/fs/ext4/mballoc.c
59749@@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59750 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59751
59752 if (EXT4_SB(sb)->s_mb_stats)
59753- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59754+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59755
59756 break;
59757 }
59758@@ -2199,7 +2199,7 @@ repeat:
59759 ac->ac_status = AC_STATUS_CONTINUE;
59760 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59761 cr = 3;
59762- atomic_inc(&sbi->s_mb_lost_chunks);
59763+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59764 goto repeat;
59765 }
59766 }
59767@@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59768 if (sbi->s_mb_stats) {
59769 ext4_msg(sb, KERN_INFO,
59770 "mballoc: %u blocks %u reqs (%u success)",
59771- atomic_read(&sbi->s_bal_allocated),
59772- atomic_read(&sbi->s_bal_reqs),
59773- atomic_read(&sbi->s_bal_success));
59774+ atomic_read_unchecked(&sbi->s_bal_allocated),
59775+ atomic_read_unchecked(&sbi->s_bal_reqs),
59776+ atomic_read_unchecked(&sbi->s_bal_success));
59777 ext4_msg(sb, KERN_INFO,
59778 "mballoc: %u extents scanned, %u goal hits, "
59779 "%u 2^N hits, %u breaks, %u lost",
59780- atomic_read(&sbi->s_bal_ex_scanned),
59781- atomic_read(&sbi->s_bal_goals),
59782- atomic_read(&sbi->s_bal_2orders),
59783- atomic_read(&sbi->s_bal_breaks),
59784- atomic_read(&sbi->s_mb_lost_chunks));
59785+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59786+ atomic_read_unchecked(&sbi->s_bal_goals),
59787+ atomic_read_unchecked(&sbi->s_bal_2orders),
59788+ atomic_read_unchecked(&sbi->s_bal_breaks),
59789+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59790 ext4_msg(sb, KERN_INFO,
59791 "mballoc: %lu generated and it took %Lu",
59792 sbi->s_mb_buddies_generated,
59793 sbi->s_mb_generation_time);
59794 ext4_msg(sb, KERN_INFO,
59795 "mballoc: %u preallocated, %u discarded",
59796- atomic_read(&sbi->s_mb_preallocated),
59797- atomic_read(&sbi->s_mb_discarded));
59798+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59799+ atomic_read_unchecked(&sbi->s_mb_discarded));
59800 }
59801
59802 free_percpu(sbi->s_locality_groups);
59803@@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59804 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59805
59806 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59807- atomic_inc(&sbi->s_bal_reqs);
59808- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59809+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59810+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59811 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59812- atomic_inc(&sbi->s_bal_success);
59813- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59814+ atomic_inc_unchecked(&sbi->s_bal_success);
59815+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59816 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59817 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59818- atomic_inc(&sbi->s_bal_goals);
59819+ atomic_inc_unchecked(&sbi->s_bal_goals);
59820 if (ac->ac_found > sbi->s_mb_max_to_scan)
59821- atomic_inc(&sbi->s_bal_breaks);
59822+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59823 }
59824
59825 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59826@@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59827 trace_ext4_mb_new_inode_pa(ac, pa);
59828
59829 ext4_mb_use_inode_pa(ac, pa);
59830- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59831+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59832
59833 ei = EXT4_I(ac->ac_inode);
59834 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59835@@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59836 trace_ext4_mb_new_group_pa(ac, pa);
59837
59838 ext4_mb_use_group_pa(ac, pa);
59839- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59840+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59841
59842 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59843 lg = ac->ac_lg;
59844@@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59845 * from the bitmap and continue.
59846 */
59847 }
59848- atomic_add(free, &sbi->s_mb_discarded);
59849+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59850
59851 return err;
59852 }
59853@@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59854 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59855 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59856 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59857- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59858+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59859 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59860
59861 return 0;
59862diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59863index 04434ad..6404663 100644
59864--- a/fs/ext4/mmp.c
59865+++ b/fs/ext4/mmp.c
59866@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59867 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59868 const char *function, unsigned int line, const char *msg)
59869 {
59870- __ext4_warning(sb, function, line, msg);
59871+ __ext4_warning(sb, function, line, "%s", msg);
59872 __ext4_warning(sb, function, line,
59873 "MMP failure info: last update time: %llu, last update "
59874 "node: %s, last update device: %s\n",
59875diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59876index 29a403c..f58dbdb 100644
59877--- a/fs/ext4/super.c
59878+++ b/fs/ext4/super.c
59879@@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59880 }
59881
59882 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59883-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59884+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59885 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59886
59887 #ifdef CONFIG_QUOTA
59888@@ -2453,7 +2453,7 @@ struct ext4_attr {
59889 int offset;
59890 int deprecated_val;
59891 } u;
59892-};
59893+} __do_const;
59894
59895 static int parse_strtoull(const char *buf,
59896 unsigned long long max, unsigned long long *value)
59897diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59898index 4eec399..1d9444c 100644
59899--- a/fs/ext4/xattr.c
59900+++ b/fs/ext4/xattr.c
59901@@ -383,7 +383,7 @@ static int
59902 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59903 char *buffer, size_t buffer_size)
59904 {
59905- size_t rest = buffer_size;
59906+ size_t rest = buffer_size, total_size = 0;
59907
59908 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59909 const struct xattr_handler *handler =
59910@@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59911 buffer += size;
59912 }
59913 rest -= size;
59914+ total_size += size;
59915 }
59916 }
59917- return buffer_size - rest;
59918+ return total_size;
59919 }
59920
59921 static int
59922diff --git a/fs/fcntl.c b/fs/fcntl.c
59923index 72c82f6..a18b263 100644
59924--- a/fs/fcntl.c
59925+++ b/fs/fcntl.c
59926@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59927 if (err)
59928 return err;
59929
59930+ if (gr_handle_chroot_fowner(pid, type))
59931+ return -ENOENT;
59932+ if (gr_check_protected_task_fowner(pid, type))
59933+ return -EACCES;
59934+
59935 f_modown(filp, pid, type, force);
59936 return 0;
59937 }
59938diff --git a/fs/fhandle.c b/fs/fhandle.c
59939index 999ff5c..ac037c9 100644
59940--- a/fs/fhandle.c
59941+++ b/fs/fhandle.c
59942@@ -8,6 +8,7 @@
59943 #include <linux/fs_struct.h>
59944 #include <linux/fsnotify.h>
59945 #include <linux/personality.h>
59946+#include <linux/grsecurity.h>
59947 #include <asm/uaccess.h>
59948 #include "internal.h"
59949 #include "mount.h"
59950@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
59951 } else
59952 retval = 0;
59953 /* copy the mount id */
59954- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59955- sizeof(*mnt_id)) ||
59956+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59957 copy_to_user(ufh, handle,
59958 sizeof(struct file_handle) + handle_bytes))
59959 retval = -EFAULT;
59960@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
59961 * the directory. Ideally we would like CAP_DAC_SEARCH.
59962 * But we don't have that
59963 */
59964- if (!capable(CAP_DAC_READ_SEARCH)) {
59965+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
59966 retval = -EPERM;
59967 goto out_err;
59968 }
59969diff --git a/fs/file.c b/fs/file.c
59970index 8f294cf..d0f3872 100644
59971--- a/fs/file.c
59972+++ b/fs/file.c
59973@@ -16,6 +16,7 @@
59974 #include <linux/slab.h>
59975 #include <linux/vmalloc.h>
59976 #include <linux/file.h>
59977+#include <linux/security.h>
59978 #include <linux/fdtable.h>
59979 #include <linux/bitops.h>
59980 #include <linux/interrupt.h>
59981@@ -144,7 +145,7 @@ out:
59982 * Return <0 error code on error; 1 on successful completion.
59983 * The files->file_lock should be held on entry, and will be held on exit.
59984 */
59985-static int expand_fdtable(struct files_struct *files, int nr)
59986+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59987 __releases(files->file_lock)
59988 __acquires(files->file_lock)
59989 {
59990@@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59991 * expanded and execution may have blocked.
59992 * The files->file_lock should be held on entry, and will be held on exit.
59993 */
59994-static int expand_files(struct files_struct *files, int nr)
59995+static int expand_files(struct files_struct *files, unsigned int nr)
59996 {
59997 struct fdtable *fdt;
59998
59999@@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
60000 if (!file)
60001 return __close_fd(files, fd);
60002
60003+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
60004 if (fd >= rlimit(RLIMIT_NOFILE))
60005 return -EBADF;
60006
60007@@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
60008 if (unlikely(oldfd == newfd))
60009 return -EINVAL;
60010
60011+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
60012 if (newfd >= rlimit(RLIMIT_NOFILE))
60013 return -EBADF;
60014
60015@@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
60016 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
60017 {
60018 int err;
60019+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
60020 if (from >= rlimit(RLIMIT_NOFILE))
60021 return -EINVAL;
60022 err = alloc_fd(from, flags);
60023diff --git a/fs/filesystems.c b/fs/filesystems.c
60024index 5797d45..7d7d79a 100644
60025--- a/fs/filesystems.c
60026+++ b/fs/filesystems.c
60027@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
60028 int len = dot ? dot - name : strlen(name);
60029
60030 fs = __get_fs_type(name, len);
60031+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60032+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
60033+#else
60034 if (!fs && (request_module("fs-%.*s", len, name) == 0))
60035+#endif
60036 fs = __get_fs_type(name, len);
60037
60038 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
60039diff --git a/fs/fs_struct.c b/fs/fs_struct.c
60040index 7dca743..543d620 100644
60041--- a/fs/fs_struct.c
60042+++ b/fs/fs_struct.c
60043@@ -4,6 +4,7 @@
60044 #include <linux/path.h>
60045 #include <linux/slab.h>
60046 #include <linux/fs_struct.h>
60047+#include <linux/grsecurity.h>
60048 #include "internal.h"
60049
60050 /*
60051@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
60052 write_seqcount_begin(&fs->seq);
60053 old_root = fs->root;
60054 fs->root = *path;
60055+ gr_set_chroot_entries(current, path);
60056 write_seqcount_end(&fs->seq);
60057 spin_unlock(&fs->lock);
60058 if (old_root.dentry)
60059@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
60060 int hits = 0;
60061 spin_lock(&fs->lock);
60062 write_seqcount_begin(&fs->seq);
60063+ /* this root replacement is only done by pivot_root,
60064+ leave grsec's chroot tagging alone for this task
60065+ so that a pivoted root isn't treated as a chroot
60066+ */
60067 hits += replace_path(&fs->root, old_root, new_root);
60068 hits += replace_path(&fs->pwd, old_root, new_root);
60069 write_seqcount_end(&fs->seq);
60070@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
60071 task_lock(tsk);
60072 spin_lock(&fs->lock);
60073 tsk->fs = NULL;
60074- kill = !--fs->users;
60075+ gr_clear_chroot_entries(tsk);
60076+ kill = !atomic_dec_return(&fs->users);
60077 spin_unlock(&fs->lock);
60078 task_unlock(tsk);
60079 if (kill)
60080@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60081 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60082 /* We don't need to lock fs - think why ;-) */
60083 if (fs) {
60084- fs->users = 1;
60085+ atomic_set(&fs->users, 1);
60086 fs->in_exec = 0;
60087 spin_lock_init(&fs->lock);
60088 seqcount_init(&fs->seq);
60089@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60090 spin_lock(&old->lock);
60091 fs->root = old->root;
60092 path_get(&fs->root);
60093+ /* instead of calling gr_set_chroot_entries here,
60094+ we call it from every caller of this function
60095+ */
60096 fs->pwd = old->pwd;
60097 path_get(&fs->pwd);
60098 spin_unlock(&old->lock);
60099@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60100
60101 task_lock(current);
60102 spin_lock(&fs->lock);
60103- kill = !--fs->users;
60104+ kill = !atomic_dec_return(&fs->users);
60105 current->fs = new_fs;
60106+ gr_set_chroot_entries(current, &new_fs->root);
60107 spin_unlock(&fs->lock);
60108 task_unlock(current);
60109
60110@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60111
60112 int current_umask(void)
60113 {
60114- return current->fs->umask;
60115+ return current->fs->umask | gr_acl_umask();
60116 }
60117 EXPORT_SYMBOL(current_umask);
60118
60119 /* to be mentioned only in INIT_TASK */
60120 struct fs_struct init_fs = {
60121- .users = 1,
60122+ .users = ATOMIC_INIT(1),
60123 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60124 .seq = SEQCNT_ZERO(init_fs.seq),
60125 .umask = 0022,
60126diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60127index 29d7feb..303644d 100644
60128--- a/fs/fscache/cookie.c
60129+++ b/fs/fscache/cookie.c
60130@@ -19,7 +19,7 @@
60131
60132 struct kmem_cache *fscache_cookie_jar;
60133
60134-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60135+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60136
60137 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60138 static int fscache_alloc_object(struct fscache_cache *cache,
60139@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60140 parent ? (char *) parent->def->name : "<no-parent>",
60141 def->name, netfs_data, enable);
60142
60143- fscache_stat(&fscache_n_acquires);
60144+ fscache_stat_unchecked(&fscache_n_acquires);
60145
60146 /* if there's no parent cookie, then we don't create one here either */
60147 if (!parent) {
60148- fscache_stat(&fscache_n_acquires_null);
60149+ fscache_stat_unchecked(&fscache_n_acquires_null);
60150 _leave(" [no parent]");
60151 return NULL;
60152 }
60153@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60154 /* allocate and initialise a cookie */
60155 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60156 if (!cookie) {
60157- fscache_stat(&fscache_n_acquires_oom);
60158+ fscache_stat_unchecked(&fscache_n_acquires_oom);
60159 _leave(" [ENOMEM]");
60160 return NULL;
60161 }
60162@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60163
60164 switch (cookie->def->type) {
60165 case FSCACHE_COOKIE_TYPE_INDEX:
60166- fscache_stat(&fscache_n_cookie_index);
60167+ fscache_stat_unchecked(&fscache_n_cookie_index);
60168 break;
60169 case FSCACHE_COOKIE_TYPE_DATAFILE:
60170- fscache_stat(&fscache_n_cookie_data);
60171+ fscache_stat_unchecked(&fscache_n_cookie_data);
60172 break;
60173 default:
60174- fscache_stat(&fscache_n_cookie_special);
60175+ fscache_stat_unchecked(&fscache_n_cookie_special);
60176 break;
60177 }
60178
60179@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60180 } else {
60181 atomic_dec(&parent->n_children);
60182 __fscache_cookie_put(cookie);
60183- fscache_stat(&fscache_n_acquires_nobufs);
60184+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60185 _leave(" = NULL");
60186 return NULL;
60187 }
60188@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60189 }
60190 }
60191
60192- fscache_stat(&fscache_n_acquires_ok);
60193+ fscache_stat_unchecked(&fscache_n_acquires_ok);
60194 _leave(" = %p", cookie);
60195 return cookie;
60196 }
60197@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60198 cache = fscache_select_cache_for_object(cookie->parent);
60199 if (!cache) {
60200 up_read(&fscache_addremove_sem);
60201- fscache_stat(&fscache_n_acquires_no_cache);
60202+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60203 _leave(" = -ENOMEDIUM [no cache]");
60204 return -ENOMEDIUM;
60205 }
60206@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60207 object = cache->ops->alloc_object(cache, cookie);
60208 fscache_stat_d(&fscache_n_cop_alloc_object);
60209 if (IS_ERR(object)) {
60210- fscache_stat(&fscache_n_object_no_alloc);
60211+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
60212 ret = PTR_ERR(object);
60213 goto error;
60214 }
60215
60216- fscache_stat(&fscache_n_object_alloc);
60217+ fscache_stat_unchecked(&fscache_n_object_alloc);
60218
60219- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60220+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60221
60222 _debug("ALLOC OBJ%x: %s {%lx}",
60223 object->debug_id, cookie->def->name, object->events);
60224@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60225
60226 _enter("{%s}", cookie->def->name);
60227
60228- fscache_stat(&fscache_n_invalidates);
60229+ fscache_stat_unchecked(&fscache_n_invalidates);
60230
60231 /* Only permit invalidation of data files. Invalidating an index will
60232 * require the caller to release all its attachments to the tree rooted
60233@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60234 {
60235 struct fscache_object *object;
60236
60237- fscache_stat(&fscache_n_updates);
60238+ fscache_stat_unchecked(&fscache_n_updates);
60239
60240 if (!cookie) {
60241- fscache_stat(&fscache_n_updates_null);
60242+ fscache_stat_unchecked(&fscache_n_updates_null);
60243 _leave(" [no cookie]");
60244 return;
60245 }
60246@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60247 */
60248 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60249 {
60250- fscache_stat(&fscache_n_relinquishes);
60251+ fscache_stat_unchecked(&fscache_n_relinquishes);
60252 if (retire)
60253- fscache_stat(&fscache_n_relinquishes_retire);
60254+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60255
60256 if (!cookie) {
60257- fscache_stat(&fscache_n_relinquishes_null);
60258+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
60259 _leave(" [no cookie]");
60260 return;
60261 }
60262@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60263 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60264 goto inconsistent;
60265
60266- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60267+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60268
60269 __fscache_use_cookie(cookie);
60270 if (fscache_submit_op(object, op) < 0)
60271diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60272index 4226f66..0fb3f45 100644
60273--- a/fs/fscache/internal.h
60274+++ b/fs/fscache/internal.h
60275@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60276 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60277 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60278 struct fscache_operation *,
60279- atomic_t *,
60280- atomic_t *,
60281+ atomic_unchecked_t *,
60282+ atomic_unchecked_t *,
60283 void (*)(struct fscache_operation *));
60284 extern void fscache_invalidate_writes(struct fscache_cookie *);
60285
60286@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60287 * stats.c
60288 */
60289 #ifdef CONFIG_FSCACHE_STATS
60290-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60291-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60292+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60293+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60294
60295-extern atomic_t fscache_n_op_pend;
60296-extern atomic_t fscache_n_op_run;
60297-extern atomic_t fscache_n_op_enqueue;
60298-extern atomic_t fscache_n_op_deferred_release;
60299-extern atomic_t fscache_n_op_release;
60300-extern atomic_t fscache_n_op_gc;
60301-extern atomic_t fscache_n_op_cancelled;
60302-extern atomic_t fscache_n_op_rejected;
60303+extern atomic_unchecked_t fscache_n_op_pend;
60304+extern atomic_unchecked_t fscache_n_op_run;
60305+extern atomic_unchecked_t fscache_n_op_enqueue;
60306+extern atomic_unchecked_t fscache_n_op_deferred_release;
60307+extern atomic_unchecked_t fscache_n_op_release;
60308+extern atomic_unchecked_t fscache_n_op_gc;
60309+extern atomic_unchecked_t fscache_n_op_cancelled;
60310+extern atomic_unchecked_t fscache_n_op_rejected;
60311
60312-extern atomic_t fscache_n_attr_changed;
60313-extern atomic_t fscache_n_attr_changed_ok;
60314-extern atomic_t fscache_n_attr_changed_nobufs;
60315-extern atomic_t fscache_n_attr_changed_nomem;
60316-extern atomic_t fscache_n_attr_changed_calls;
60317+extern atomic_unchecked_t fscache_n_attr_changed;
60318+extern atomic_unchecked_t fscache_n_attr_changed_ok;
60319+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60320+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60321+extern atomic_unchecked_t fscache_n_attr_changed_calls;
60322
60323-extern atomic_t fscache_n_allocs;
60324-extern atomic_t fscache_n_allocs_ok;
60325-extern atomic_t fscache_n_allocs_wait;
60326-extern atomic_t fscache_n_allocs_nobufs;
60327-extern atomic_t fscache_n_allocs_intr;
60328-extern atomic_t fscache_n_allocs_object_dead;
60329-extern atomic_t fscache_n_alloc_ops;
60330-extern atomic_t fscache_n_alloc_op_waits;
60331+extern atomic_unchecked_t fscache_n_allocs;
60332+extern atomic_unchecked_t fscache_n_allocs_ok;
60333+extern atomic_unchecked_t fscache_n_allocs_wait;
60334+extern atomic_unchecked_t fscache_n_allocs_nobufs;
60335+extern atomic_unchecked_t fscache_n_allocs_intr;
60336+extern atomic_unchecked_t fscache_n_allocs_object_dead;
60337+extern atomic_unchecked_t fscache_n_alloc_ops;
60338+extern atomic_unchecked_t fscache_n_alloc_op_waits;
60339
60340-extern atomic_t fscache_n_retrievals;
60341-extern atomic_t fscache_n_retrievals_ok;
60342-extern atomic_t fscache_n_retrievals_wait;
60343-extern atomic_t fscache_n_retrievals_nodata;
60344-extern atomic_t fscache_n_retrievals_nobufs;
60345-extern atomic_t fscache_n_retrievals_intr;
60346-extern atomic_t fscache_n_retrievals_nomem;
60347-extern atomic_t fscache_n_retrievals_object_dead;
60348-extern atomic_t fscache_n_retrieval_ops;
60349-extern atomic_t fscache_n_retrieval_op_waits;
60350+extern atomic_unchecked_t fscache_n_retrievals;
60351+extern atomic_unchecked_t fscache_n_retrievals_ok;
60352+extern atomic_unchecked_t fscache_n_retrievals_wait;
60353+extern atomic_unchecked_t fscache_n_retrievals_nodata;
60354+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60355+extern atomic_unchecked_t fscache_n_retrievals_intr;
60356+extern atomic_unchecked_t fscache_n_retrievals_nomem;
60357+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60358+extern atomic_unchecked_t fscache_n_retrieval_ops;
60359+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60360
60361-extern atomic_t fscache_n_stores;
60362-extern atomic_t fscache_n_stores_ok;
60363-extern atomic_t fscache_n_stores_again;
60364-extern atomic_t fscache_n_stores_nobufs;
60365-extern atomic_t fscache_n_stores_oom;
60366-extern atomic_t fscache_n_store_ops;
60367-extern atomic_t fscache_n_store_calls;
60368-extern atomic_t fscache_n_store_pages;
60369-extern atomic_t fscache_n_store_radix_deletes;
60370-extern atomic_t fscache_n_store_pages_over_limit;
60371+extern atomic_unchecked_t fscache_n_stores;
60372+extern atomic_unchecked_t fscache_n_stores_ok;
60373+extern atomic_unchecked_t fscache_n_stores_again;
60374+extern atomic_unchecked_t fscache_n_stores_nobufs;
60375+extern atomic_unchecked_t fscache_n_stores_oom;
60376+extern atomic_unchecked_t fscache_n_store_ops;
60377+extern atomic_unchecked_t fscache_n_store_calls;
60378+extern atomic_unchecked_t fscache_n_store_pages;
60379+extern atomic_unchecked_t fscache_n_store_radix_deletes;
60380+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60381
60382-extern atomic_t fscache_n_store_vmscan_not_storing;
60383-extern atomic_t fscache_n_store_vmscan_gone;
60384-extern atomic_t fscache_n_store_vmscan_busy;
60385-extern atomic_t fscache_n_store_vmscan_cancelled;
60386-extern atomic_t fscache_n_store_vmscan_wait;
60387+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60388+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60389+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60390+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60391+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60392
60393-extern atomic_t fscache_n_marks;
60394-extern atomic_t fscache_n_uncaches;
60395+extern atomic_unchecked_t fscache_n_marks;
60396+extern atomic_unchecked_t fscache_n_uncaches;
60397
60398-extern atomic_t fscache_n_acquires;
60399-extern atomic_t fscache_n_acquires_null;
60400-extern atomic_t fscache_n_acquires_no_cache;
60401-extern atomic_t fscache_n_acquires_ok;
60402-extern atomic_t fscache_n_acquires_nobufs;
60403-extern atomic_t fscache_n_acquires_oom;
60404+extern atomic_unchecked_t fscache_n_acquires;
60405+extern atomic_unchecked_t fscache_n_acquires_null;
60406+extern atomic_unchecked_t fscache_n_acquires_no_cache;
60407+extern atomic_unchecked_t fscache_n_acquires_ok;
60408+extern atomic_unchecked_t fscache_n_acquires_nobufs;
60409+extern atomic_unchecked_t fscache_n_acquires_oom;
60410
60411-extern atomic_t fscache_n_invalidates;
60412-extern atomic_t fscache_n_invalidates_run;
60413+extern atomic_unchecked_t fscache_n_invalidates;
60414+extern atomic_unchecked_t fscache_n_invalidates_run;
60415
60416-extern atomic_t fscache_n_updates;
60417-extern atomic_t fscache_n_updates_null;
60418-extern atomic_t fscache_n_updates_run;
60419+extern atomic_unchecked_t fscache_n_updates;
60420+extern atomic_unchecked_t fscache_n_updates_null;
60421+extern atomic_unchecked_t fscache_n_updates_run;
60422
60423-extern atomic_t fscache_n_relinquishes;
60424-extern atomic_t fscache_n_relinquishes_null;
60425-extern atomic_t fscache_n_relinquishes_waitcrt;
60426-extern atomic_t fscache_n_relinquishes_retire;
60427+extern atomic_unchecked_t fscache_n_relinquishes;
60428+extern atomic_unchecked_t fscache_n_relinquishes_null;
60429+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60430+extern atomic_unchecked_t fscache_n_relinquishes_retire;
60431
60432-extern atomic_t fscache_n_cookie_index;
60433-extern atomic_t fscache_n_cookie_data;
60434-extern atomic_t fscache_n_cookie_special;
60435+extern atomic_unchecked_t fscache_n_cookie_index;
60436+extern atomic_unchecked_t fscache_n_cookie_data;
60437+extern atomic_unchecked_t fscache_n_cookie_special;
60438
60439-extern atomic_t fscache_n_object_alloc;
60440-extern atomic_t fscache_n_object_no_alloc;
60441-extern atomic_t fscache_n_object_lookups;
60442-extern atomic_t fscache_n_object_lookups_negative;
60443-extern atomic_t fscache_n_object_lookups_positive;
60444-extern atomic_t fscache_n_object_lookups_timed_out;
60445-extern atomic_t fscache_n_object_created;
60446-extern atomic_t fscache_n_object_avail;
60447-extern atomic_t fscache_n_object_dead;
60448+extern atomic_unchecked_t fscache_n_object_alloc;
60449+extern atomic_unchecked_t fscache_n_object_no_alloc;
60450+extern atomic_unchecked_t fscache_n_object_lookups;
60451+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60452+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60453+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60454+extern atomic_unchecked_t fscache_n_object_created;
60455+extern atomic_unchecked_t fscache_n_object_avail;
60456+extern atomic_unchecked_t fscache_n_object_dead;
60457
60458-extern atomic_t fscache_n_checkaux_none;
60459-extern atomic_t fscache_n_checkaux_okay;
60460-extern atomic_t fscache_n_checkaux_update;
60461-extern atomic_t fscache_n_checkaux_obsolete;
60462+extern atomic_unchecked_t fscache_n_checkaux_none;
60463+extern atomic_unchecked_t fscache_n_checkaux_okay;
60464+extern atomic_unchecked_t fscache_n_checkaux_update;
60465+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60466
60467 extern atomic_t fscache_n_cop_alloc_object;
60468 extern atomic_t fscache_n_cop_lookup_object;
60469@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60470 atomic_inc(stat);
60471 }
60472
60473+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60474+{
60475+ atomic_inc_unchecked(stat);
60476+}
60477+
60478 static inline void fscache_stat_d(atomic_t *stat)
60479 {
60480 atomic_dec(stat);
60481@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60482
60483 #define __fscache_stat(stat) (NULL)
60484 #define fscache_stat(stat) do {} while (0)
60485+#define fscache_stat_unchecked(stat) do {} while (0)
60486 #define fscache_stat_d(stat) do {} while (0)
60487 #endif
60488
60489diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60490index d3b4539..ed0c659 100644
60491--- a/fs/fscache/object.c
60492+++ b/fs/fscache/object.c
60493@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60494 _debug("LOOKUP \"%s\" in \"%s\"",
60495 cookie->def->name, object->cache->tag->name);
60496
60497- fscache_stat(&fscache_n_object_lookups);
60498+ fscache_stat_unchecked(&fscache_n_object_lookups);
60499 fscache_stat(&fscache_n_cop_lookup_object);
60500 ret = object->cache->ops->lookup_object(object);
60501 fscache_stat_d(&fscache_n_cop_lookup_object);
60502@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60503 if (ret == -ETIMEDOUT) {
60504 /* probably stuck behind another object, so move this one to
60505 * the back of the queue */
60506- fscache_stat(&fscache_n_object_lookups_timed_out);
60507+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60508 _leave(" [timeout]");
60509 return NO_TRANSIT;
60510 }
60511@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60512 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60513
60514 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60515- fscache_stat(&fscache_n_object_lookups_negative);
60516+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60517
60518 /* Allow write requests to begin stacking up and read requests to begin
60519 * returning ENODATA.
60520@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60521 /* if we were still looking up, then we must have a positive lookup
60522 * result, in which case there may be data available */
60523 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60524- fscache_stat(&fscache_n_object_lookups_positive);
60525+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60526
60527 /* We do (presumably) have data */
60528 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60529@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60530 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60531 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60532 } else {
60533- fscache_stat(&fscache_n_object_created);
60534+ fscache_stat_unchecked(&fscache_n_object_created);
60535 }
60536
60537 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60538@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60539 fscache_stat_d(&fscache_n_cop_lookup_complete);
60540
60541 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60542- fscache_stat(&fscache_n_object_avail);
60543+ fscache_stat_unchecked(&fscache_n_object_avail);
60544
60545 _leave("");
60546 return transit_to(JUMPSTART_DEPS);
60547@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60548
60549 /* this just shifts the object release to the work processor */
60550 fscache_put_object(object);
60551- fscache_stat(&fscache_n_object_dead);
60552+ fscache_stat_unchecked(&fscache_n_object_dead);
60553
60554 _leave("");
60555 return transit_to(OBJECT_DEAD);
60556@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60557 enum fscache_checkaux result;
60558
60559 if (!object->cookie->def->check_aux) {
60560- fscache_stat(&fscache_n_checkaux_none);
60561+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60562 return FSCACHE_CHECKAUX_OKAY;
60563 }
60564
60565@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60566 switch (result) {
60567 /* entry okay as is */
60568 case FSCACHE_CHECKAUX_OKAY:
60569- fscache_stat(&fscache_n_checkaux_okay);
60570+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60571 break;
60572
60573 /* entry requires update */
60574 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60575- fscache_stat(&fscache_n_checkaux_update);
60576+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60577 break;
60578
60579 /* entry requires deletion */
60580 case FSCACHE_CHECKAUX_OBSOLETE:
60581- fscache_stat(&fscache_n_checkaux_obsolete);
60582+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60583 break;
60584
60585 default:
60586@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60587 {
60588 const struct fscache_state *s;
60589
60590- fscache_stat(&fscache_n_invalidates_run);
60591+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60592 fscache_stat(&fscache_n_cop_invalidate_object);
60593 s = _fscache_invalidate_object(object, event);
60594 fscache_stat_d(&fscache_n_cop_invalidate_object);
60595@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60596 {
60597 _enter("{OBJ%x},%d", object->debug_id, event);
60598
60599- fscache_stat(&fscache_n_updates_run);
60600+ fscache_stat_unchecked(&fscache_n_updates_run);
60601 fscache_stat(&fscache_n_cop_update_object);
60602 object->cache->ops->update_object(object);
60603 fscache_stat_d(&fscache_n_cop_update_object);
60604diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60605index 318071a..379938b 100644
60606--- a/fs/fscache/operation.c
60607+++ b/fs/fscache/operation.c
60608@@ -17,7 +17,7 @@
60609 #include <linux/slab.h>
60610 #include "internal.h"
60611
60612-atomic_t fscache_op_debug_id;
60613+atomic_unchecked_t fscache_op_debug_id;
60614 EXPORT_SYMBOL(fscache_op_debug_id);
60615
60616 /**
60617@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60618 ASSERTCMP(atomic_read(&op->usage), >, 0);
60619 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60620
60621- fscache_stat(&fscache_n_op_enqueue);
60622+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60623 switch (op->flags & FSCACHE_OP_TYPE) {
60624 case FSCACHE_OP_ASYNC:
60625 _debug("queue async");
60626@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60627 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60628 if (op->processor)
60629 fscache_enqueue_operation(op);
60630- fscache_stat(&fscache_n_op_run);
60631+ fscache_stat_unchecked(&fscache_n_op_run);
60632 }
60633
60634 /*
60635@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60636 if (object->n_in_progress > 0) {
60637 atomic_inc(&op->usage);
60638 list_add_tail(&op->pend_link, &object->pending_ops);
60639- fscache_stat(&fscache_n_op_pend);
60640+ fscache_stat_unchecked(&fscache_n_op_pend);
60641 } else if (!list_empty(&object->pending_ops)) {
60642 atomic_inc(&op->usage);
60643 list_add_tail(&op->pend_link, &object->pending_ops);
60644- fscache_stat(&fscache_n_op_pend);
60645+ fscache_stat_unchecked(&fscache_n_op_pend);
60646 fscache_start_operations(object);
60647 } else {
60648 ASSERTCMP(object->n_in_progress, ==, 0);
60649@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60650 object->n_exclusive++; /* reads and writes must wait */
60651 atomic_inc(&op->usage);
60652 list_add_tail(&op->pend_link, &object->pending_ops);
60653- fscache_stat(&fscache_n_op_pend);
60654+ fscache_stat_unchecked(&fscache_n_op_pend);
60655 ret = 0;
60656 } else {
60657 /* If we're in any other state, there must have been an I/O
60658@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60659 if (object->n_exclusive > 0) {
60660 atomic_inc(&op->usage);
60661 list_add_tail(&op->pend_link, &object->pending_ops);
60662- fscache_stat(&fscache_n_op_pend);
60663+ fscache_stat_unchecked(&fscache_n_op_pend);
60664 } else if (!list_empty(&object->pending_ops)) {
60665 atomic_inc(&op->usage);
60666 list_add_tail(&op->pend_link, &object->pending_ops);
60667- fscache_stat(&fscache_n_op_pend);
60668+ fscache_stat_unchecked(&fscache_n_op_pend);
60669 fscache_start_operations(object);
60670 } else {
60671 ASSERTCMP(object->n_exclusive, ==, 0);
60672@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60673 object->n_ops++;
60674 atomic_inc(&op->usage);
60675 list_add_tail(&op->pend_link, &object->pending_ops);
60676- fscache_stat(&fscache_n_op_pend);
60677+ fscache_stat_unchecked(&fscache_n_op_pend);
60678 ret = 0;
60679 } else if (fscache_object_is_dying(object)) {
60680- fscache_stat(&fscache_n_op_rejected);
60681+ fscache_stat_unchecked(&fscache_n_op_rejected);
60682 op->state = FSCACHE_OP_ST_CANCELLED;
60683 ret = -ENOBUFS;
60684 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60685@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60686 ret = -EBUSY;
60687 if (op->state == FSCACHE_OP_ST_PENDING) {
60688 ASSERT(!list_empty(&op->pend_link));
60689- fscache_stat(&fscache_n_op_cancelled);
60690+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60691 list_del_init(&op->pend_link);
60692 if (do_cancel)
60693 do_cancel(op);
60694@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60695 while (!list_empty(&object->pending_ops)) {
60696 op = list_entry(object->pending_ops.next,
60697 struct fscache_operation, pend_link);
60698- fscache_stat(&fscache_n_op_cancelled);
60699+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60700 list_del_init(&op->pend_link);
60701
60702 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60703@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60704 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60705 op->state = FSCACHE_OP_ST_DEAD;
60706
60707- fscache_stat(&fscache_n_op_release);
60708+ fscache_stat_unchecked(&fscache_n_op_release);
60709
60710 if (op->release) {
60711 op->release(op);
60712@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60713 * lock, and defer it otherwise */
60714 if (!spin_trylock(&object->lock)) {
60715 _debug("defer put");
60716- fscache_stat(&fscache_n_op_deferred_release);
60717+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60718
60719 cache = object->cache;
60720 spin_lock(&cache->op_gc_list_lock);
60721@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60722
60723 _debug("GC DEFERRED REL OBJ%x OP%x",
60724 object->debug_id, op->debug_id);
60725- fscache_stat(&fscache_n_op_gc);
60726+ fscache_stat_unchecked(&fscache_n_op_gc);
60727
60728 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60729 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60730diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60731index 7f5c658..6c1e164 100644
60732--- a/fs/fscache/page.c
60733+++ b/fs/fscache/page.c
60734@@ -61,7 +61,7 @@ try_again:
60735 val = radix_tree_lookup(&cookie->stores, page->index);
60736 if (!val) {
60737 rcu_read_unlock();
60738- fscache_stat(&fscache_n_store_vmscan_not_storing);
60739+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60740 __fscache_uncache_page(cookie, page);
60741 return true;
60742 }
60743@@ -91,11 +91,11 @@ try_again:
60744 spin_unlock(&cookie->stores_lock);
60745
60746 if (xpage) {
60747- fscache_stat(&fscache_n_store_vmscan_cancelled);
60748- fscache_stat(&fscache_n_store_radix_deletes);
60749+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60750+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60751 ASSERTCMP(xpage, ==, page);
60752 } else {
60753- fscache_stat(&fscache_n_store_vmscan_gone);
60754+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60755 }
60756
60757 wake_up_bit(&cookie->flags, 0);
60758@@ -110,11 +110,11 @@ page_busy:
60759 * sleeping on memory allocation, so we may need to impose a timeout
60760 * too. */
60761 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60762- fscache_stat(&fscache_n_store_vmscan_busy);
60763+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60764 return false;
60765 }
60766
60767- fscache_stat(&fscache_n_store_vmscan_wait);
60768+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60769 __fscache_wait_on_page_write(cookie, page);
60770 gfp &= ~__GFP_WAIT;
60771 goto try_again;
60772@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60773 FSCACHE_COOKIE_STORING_TAG);
60774 if (!radix_tree_tag_get(&cookie->stores, page->index,
60775 FSCACHE_COOKIE_PENDING_TAG)) {
60776- fscache_stat(&fscache_n_store_radix_deletes);
60777+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60778 xpage = radix_tree_delete(&cookie->stores, page->index);
60779 }
60780 spin_unlock(&cookie->stores_lock);
60781@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60782
60783 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60784
60785- fscache_stat(&fscache_n_attr_changed_calls);
60786+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60787
60788 if (fscache_object_is_active(object)) {
60789 fscache_stat(&fscache_n_cop_attr_changed);
60790@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60791
60792 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60793
60794- fscache_stat(&fscache_n_attr_changed);
60795+ fscache_stat_unchecked(&fscache_n_attr_changed);
60796
60797 op = kzalloc(sizeof(*op), GFP_KERNEL);
60798 if (!op) {
60799- fscache_stat(&fscache_n_attr_changed_nomem);
60800+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60801 _leave(" = -ENOMEM");
60802 return -ENOMEM;
60803 }
60804@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60805 if (fscache_submit_exclusive_op(object, op) < 0)
60806 goto nobufs;
60807 spin_unlock(&cookie->lock);
60808- fscache_stat(&fscache_n_attr_changed_ok);
60809+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60810 fscache_put_operation(op);
60811 _leave(" = 0");
60812 return 0;
60813@@ -225,7 +225,7 @@ nobufs:
60814 kfree(op);
60815 if (wake_cookie)
60816 __fscache_wake_unused_cookie(cookie);
60817- fscache_stat(&fscache_n_attr_changed_nobufs);
60818+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60819 _leave(" = %d", -ENOBUFS);
60820 return -ENOBUFS;
60821 }
60822@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60823 /* allocate a retrieval operation and attempt to submit it */
60824 op = kzalloc(sizeof(*op), GFP_NOIO);
60825 if (!op) {
60826- fscache_stat(&fscache_n_retrievals_nomem);
60827+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60828 return NULL;
60829 }
60830
60831@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60832 return 0;
60833 }
60834
60835- fscache_stat(&fscache_n_retrievals_wait);
60836+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60837
60838 jif = jiffies;
60839 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60840 fscache_wait_bit_interruptible,
60841 TASK_INTERRUPTIBLE) != 0) {
60842- fscache_stat(&fscache_n_retrievals_intr);
60843+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60844 _leave(" = -ERESTARTSYS");
60845 return -ERESTARTSYS;
60846 }
60847@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60848 */
60849 int fscache_wait_for_operation_activation(struct fscache_object *object,
60850 struct fscache_operation *op,
60851- atomic_t *stat_op_waits,
60852- atomic_t *stat_object_dead,
60853+ atomic_unchecked_t *stat_op_waits,
60854+ atomic_unchecked_t *stat_object_dead,
60855 void (*do_cancel)(struct fscache_operation *))
60856 {
60857 int ret;
60858@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60859
60860 _debug(">>> WT");
60861 if (stat_op_waits)
60862- fscache_stat(stat_op_waits);
60863+ fscache_stat_unchecked(stat_op_waits);
60864 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60865 fscache_wait_bit_interruptible,
60866 TASK_INTERRUPTIBLE) != 0) {
60867@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60868 check_if_dead:
60869 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60870 if (stat_object_dead)
60871- fscache_stat(stat_object_dead);
60872+ fscache_stat_unchecked(stat_object_dead);
60873 _leave(" = -ENOBUFS [cancelled]");
60874 return -ENOBUFS;
60875 }
60876@@ -366,7 +366,7 @@ check_if_dead:
60877 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60878 fscache_cancel_op(op, do_cancel);
60879 if (stat_object_dead)
60880- fscache_stat(stat_object_dead);
60881+ fscache_stat_unchecked(stat_object_dead);
60882 return -ENOBUFS;
60883 }
60884 return 0;
60885@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60886
60887 _enter("%p,%p,,,", cookie, page);
60888
60889- fscache_stat(&fscache_n_retrievals);
60890+ fscache_stat_unchecked(&fscache_n_retrievals);
60891
60892 if (hlist_empty(&cookie->backing_objects))
60893 goto nobufs;
60894@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60895 goto nobufs_unlock_dec;
60896 spin_unlock(&cookie->lock);
60897
60898- fscache_stat(&fscache_n_retrieval_ops);
60899+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60900
60901 /* pin the netfs read context in case we need to do the actual netfs
60902 * read because we've encountered a cache read failure */
60903@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60904
60905 error:
60906 if (ret == -ENOMEM)
60907- fscache_stat(&fscache_n_retrievals_nomem);
60908+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60909 else if (ret == -ERESTARTSYS)
60910- fscache_stat(&fscache_n_retrievals_intr);
60911+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60912 else if (ret == -ENODATA)
60913- fscache_stat(&fscache_n_retrievals_nodata);
60914+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60915 else if (ret < 0)
60916- fscache_stat(&fscache_n_retrievals_nobufs);
60917+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60918 else
60919- fscache_stat(&fscache_n_retrievals_ok);
60920+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60921
60922 fscache_put_retrieval(op);
60923 _leave(" = %d", ret);
60924@@ -490,7 +490,7 @@ nobufs_unlock:
60925 __fscache_wake_unused_cookie(cookie);
60926 kfree(op);
60927 nobufs:
60928- fscache_stat(&fscache_n_retrievals_nobufs);
60929+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60930 _leave(" = -ENOBUFS");
60931 return -ENOBUFS;
60932 }
60933@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60934
60935 _enter("%p,,%d,,,", cookie, *nr_pages);
60936
60937- fscache_stat(&fscache_n_retrievals);
60938+ fscache_stat_unchecked(&fscache_n_retrievals);
60939
60940 if (hlist_empty(&cookie->backing_objects))
60941 goto nobufs;
60942@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60943 goto nobufs_unlock_dec;
60944 spin_unlock(&cookie->lock);
60945
60946- fscache_stat(&fscache_n_retrieval_ops);
60947+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60948
60949 /* pin the netfs read context in case we need to do the actual netfs
60950 * read because we've encountered a cache read failure */
60951@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60952
60953 error:
60954 if (ret == -ENOMEM)
60955- fscache_stat(&fscache_n_retrievals_nomem);
60956+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60957 else if (ret == -ERESTARTSYS)
60958- fscache_stat(&fscache_n_retrievals_intr);
60959+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60960 else if (ret == -ENODATA)
60961- fscache_stat(&fscache_n_retrievals_nodata);
60962+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60963 else if (ret < 0)
60964- fscache_stat(&fscache_n_retrievals_nobufs);
60965+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60966 else
60967- fscache_stat(&fscache_n_retrievals_ok);
60968+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60969
60970 fscache_put_retrieval(op);
60971 _leave(" = %d", ret);
60972@@ -621,7 +621,7 @@ nobufs_unlock:
60973 if (wake_cookie)
60974 __fscache_wake_unused_cookie(cookie);
60975 nobufs:
60976- fscache_stat(&fscache_n_retrievals_nobufs);
60977+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60978 _leave(" = -ENOBUFS");
60979 return -ENOBUFS;
60980 }
60981@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60982
60983 _enter("%p,%p,,,", cookie, page);
60984
60985- fscache_stat(&fscache_n_allocs);
60986+ fscache_stat_unchecked(&fscache_n_allocs);
60987
60988 if (hlist_empty(&cookie->backing_objects))
60989 goto nobufs;
60990@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60991 goto nobufs_unlock_dec;
60992 spin_unlock(&cookie->lock);
60993
60994- fscache_stat(&fscache_n_alloc_ops);
60995+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60996
60997 ret = fscache_wait_for_operation_activation(
60998 object, &op->op,
60999@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61000
61001 error:
61002 if (ret == -ERESTARTSYS)
61003- fscache_stat(&fscache_n_allocs_intr);
61004+ fscache_stat_unchecked(&fscache_n_allocs_intr);
61005 else if (ret < 0)
61006- fscache_stat(&fscache_n_allocs_nobufs);
61007+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61008 else
61009- fscache_stat(&fscache_n_allocs_ok);
61010+ fscache_stat_unchecked(&fscache_n_allocs_ok);
61011
61012 fscache_put_retrieval(op);
61013 _leave(" = %d", ret);
61014@@ -715,7 +715,7 @@ nobufs_unlock:
61015 if (wake_cookie)
61016 __fscache_wake_unused_cookie(cookie);
61017 nobufs:
61018- fscache_stat(&fscache_n_allocs_nobufs);
61019+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61020 _leave(" = -ENOBUFS");
61021 return -ENOBUFS;
61022 }
61023@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61024
61025 spin_lock(&cookie->stores_lock);
61026
61027- fscache_stat(&fscache_n_store_calls);
61028+ fscache_stat_unchecked(&fscache_n_store_calls);
61029
61030 /* find a page to store */
61031 page = NULL;
61032@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61033 page = results[0];
61034 _debug("gang %d [%lx]", n, page->index);
61035 if (page->index > op->store_limit) {
61036- fscache_stat(&fscache_n_store_pages_over_limit);
61037+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
61038 goto superseded;
61039 }
61040
61041@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61042 spin_unlock(&cookie->stores_lock);
61043 spin_unlock(&object->lock);
61044
61045- fscache_stat(&fscache_n_store_pages);
61046+ fscache_stat_unchecked(&fscache_n_store_pages);
61047 fscache_stat(&fscache_n_cop_write_page);
61048 ret = object->cache->ops->write_page(op, page);
61049 fscache_stat_d(&fscache_n_cop_write_page);
61050@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61051 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61052 ASSERT(PageFsCache(page));
61053
61054- fscache_stat(&fscache_n_stores);
61055+ fscache_stat_unchecked(&fscache_n_stores);
61056
61057 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
61058 _leave(" = -ENOBUFS [invalidating]");
61059@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61060 spin_unlock(&cookie->stores_lock);
61061 spin_unlock(&object->lock);
61062
61063- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
61064+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61065 op->store_limit = object->store_limit;
61066
61067 __fscache_use_cookie(cookie);
61068@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61069
61070 spin_unlock(&cookie->lock);
61071 radix_tree_preload_end();
61072- fscache_stat(&fscache_n_store_ops);
61073- fscache_stat(&fscache_n_stores_ok);
61074+ fscache_stat_unchecked(&fscache_n_store_ops);
61075+ fscache_stat_unchecked(&fscache_n_stores_ok);
61076
61077 /* the work queue now carries its own ref on the object */
61078 fscache_put_operation(&op->op);
61079@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61080 return 0;
61081
61082 already_queued:
61083- fscache_stat(&fscache_n_stores_again);
61084+ fscache_stat_unchecked(&fscache_n_stores_again);
61085 already_pending:
61086 spin_unlock(&cookie->stores_lock);
61087 spin_unlock(&object->lock);
61088 spin_unlock(&cookie->lock);
61089 radix_tree_preload_end();
61090 kfree(op);
61091- fscache_stat(&fscache_n_stores_ok);
61092+ fscache_stat_unchecked(&fscache_n_stores_ok);
61093 _leave(" = 0");
61094 return 0;
61095
61096@@ -1024,14 +1024,14 @@ nobufs:
61097 kfree(op);
61098 if (wake_cookie)
61099 __fscache_wake_unused_cookie(cookie);
61100- fscache_stat(&fscache_n_stores_nobufs);
61101+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
61102 _leave(" = -ENOBUFS");
61103 return -ENOBUFS;
61104
61105 nomem_free:
61106 kfree(op);
61107 nomem:
61108- fscache_stat(&fscache_n_stores_oom);
61109+ fscache_stat_unchecked(&fscache_n_stores_oom);
61110 _leave(" = -ENOMEM");
61111 return -ENOMEM;
61112 }
61113@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61114 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61115 ASSERTCMP(page, !=, NULL);
61116
61117- fscache_stat(&fscache_n_uncaches);
61118+ fscache_stat_unchecked(&fscache_n_uncaches);
61119
61120 /* cache withdrawal may beat us to it */
61121 if (!PageFsCache(page))
61122@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61123 struct fscache_cookie *cookie = op->op.object->cookie;
61124
61125 #ifdef CONFIG_FSCACHE_STATS
61126- atomic_inc(&fscache_n_marks);
61127+ atomic_inc_unchecked(&fscache_n_marks);
61128 #endif
61129
61130 _debug("- mark %p{%lx}", page, page->index);
61131diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61132index 40d13c7..ddf52b9 100644
61133--- a/fs/fscache/stats.c
61134+++ b/fs/fscache/stats.c
61135@@ -18,99 +18,99 @@
61136 /*
61137 * operation counters
61138 */
61139-atomic_t fscache_n_op_pend;
61140-atomic_t fscache_n_op_run;
61141-atomic_t fscache_n_op_enqueue;
61142-atomic_t fscache_n_op_requeue;
61143-atomic_t fscache_n_op_deferred_release;
61144-atomic_t fscache_n_op_release;
61145-atomic_t fscache_n_op_gc;
61146-atomic_t fscache_n_op_cancelled;
61147-atomic_t fscache_n_op_rejected;
61148+atomic_unchecked_t fscache_n_op_pend;
61149+atomic_unchecked_t fscache_n_op_run;
61150+atomic_unchecked_t fscache_n_op_enqueue;
61151+atomic_unchecked_t fscache_n_op_requeue;
61152+atomic_unchecked_t fscache_n_op_deferred_release;
61153+atomic_unchecked_t fscache_n_op_release;
61154+atomic_unchecked_t fscache_n_op_gc;
61155+atomic_unchecked_t fscache_n_op_cancelled;
61156+atomic_unchecked_t fscache_n_op_rejected;
61157
61158-atomic_t fscache_n_attr_changed;
61159-atomic_t fscache_n_attr_changed_ok;
61160-atomic_t fscache_n_attr_changed_nobufs;
61161-atomic_t fscache_n_attr_changed_nomem;
61162-atomic_t fscache_n_attr_changed_calls;
61163+atomic_unchecked_t fscache_n_attr_changed;
61164+atomic_unchecked_t fscache_n_attr_changed_ok;
61165+atomic_unchecked_t fscache_n_attr_changed_nobufs;
61166+atomic_unchecked_t fscache_n_attr_changed_nomem;
61167+atomic_unchecked_t fscache_n_attr_changed_calls;
61168
61169-atomic_t fscache_n_allocs;
61170-atomic_t fscache_n_allocs_ok;
61171-atomic_t fscache_n_allocs_wait;
61172-atomic_t fscache_n_allocs_nobufs;
61173-atomic_t fscache_n_allocs_intr;
61174-atomic_t fscache_n_allocs_object_dead;
61175-atomic_t fscache_n_alloc_ops;
61176-atomic_t fscache_n_alloc_op_waits;
61177+atomic_unchecked_t fscache_n_allocs;
61178+atomic_unchecked_t fscache_n_allocs_ok;
61179+atomic_unchecked_t fscache_n_allocs_wait;
61180+atomic_unchecked_t fscache_n_allocs_nobufs;
61181+atomic_unchecked_t fscache_n_allocs_intr;
61182+atomic_unchecked_t fscache_n_allocs_object_dead;
61183+atomic_unchecked_t fscache_n_alloc_ops;
61184+atomic_unchecked_t fscache_n_alloc_op_waits;
61185
61186-atomic_t fscache_n_retrievals;
61187-atomic_t fscache_n_retrievals_ok;
61188-atomic_t fscache_n_retrievals_wait;
61189-atomic_t fscache_n_retrievals_nodata;
61190-atomic_t fscache_n_retrievals_nobufs;
61191-atomic_t fscache_n_retrievals_intr;
61192-atomic_t fscache_n_retrievals_nomem;
61193-atomic_t fscache_n_retrievals_object_dead;
61194-atomic_t fscache_n_retrieval_ops;
61195-atomic_t fscache_n_retrieval_op_waits;
61196+atomic_unchecked_t fscache_n_retrievals;
61197+atomic_unchecked_t fscache_n_retrievals_ok;
61198+atomic_unchecked_t fscache_n_retrievals_wait;
61199+atomic_unchecked_t fscache_n_retrievals_nodata;
61200+atomic_unchecked_t fscache_n_retrievals_nobufs;
61201+atomic_unchecked_t fscache_n_retrievals_intr;
61202+atomic_unchecked_t fscache_n_retrievals_nomem;
61203+atomic_unchecked_t fscache_n_retrievals_object_dead;
61204+atomic_unchecked_t fscache_n_retrieval_ops;
61205+atomic_unchecked_t fscache_n_retrieval_op_waits;
61206
61207-atomic_t fscache_n_stores;
61208-atomic_t fscache_n_stores_ok;
61209-atomic_t fscache_n_stores_again;
61210-atomic_t fscache_n_stores_nobufs;
61211-atomic_t fscache_n_stores_oom;
61212-atomic_t fscache_n_store_ops;
61213-atomic_t fscache_n_store_calls;
61214-atomic_t fscache_n_store_pages;
61215-atomic_t fscache_n_store_radix_deletes;
61216-atomic_t fscache_n_store_pages_over_limit;
61217+atomic_unchecked_t fscache_n_stores;
61218+atomic_unchecked_t fscache_n_stores_ok;
61219+atomic_unchecked_t fscache_n_stores_again;
61220+atomic_unchecked_t fscache_n_stores_nobufs;
61221+atomic_unchecked_t fscache_n_stores_oom;
61222+atomic_unchecked_t fscache_n_store_ops;
61223+atomic_unchecked_t fscache_n_store_calls;
61224+atomic_unchecked_t fscache_n_store_pages;
61225+atomic_unchecked_t fscache_n_store_radix_deletes;
61226+atomic_unchecked_t fscache_n_store_pages_over_limit;
61227
61228-atomic_t fscache_n_store_vmscan_not_storing;
61229-atomic_t fscache_n_store_vmscan_gone;
61230-atomic_t fscache_n_store_vmscan_busy;
61231-atomic_t fscache_n_store_vmscan_cancelled;
61232-atomic_t fscache_n_store_vmscan_wait;
61233+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61234+atomic_unchecked_t fscache_n_store_vmscan_gone;
61235+atomic_unchecked_t fscache_n_store_vmscan_busy;
61236+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61237+atomic_unchecked_t fscache_n_store_vmscan_wait;
61238
61239-atomic_t fscache_n_marks;
61240-atomic_t fscache_n_uncaches;
61241+atomic_unchecked_t fscache_n_marks;
61242+atomic_unchecked_t fscache_n_uncaches;
61243
61244-atomic_t fscache_n_acquires;
61245-atomic_t fscache_n_acquires_null;
61246-atomic_t fscache_n_acquires_no_cache;
61247-atomic_t fscache_n_acquires_ok;
61248-atomic_t fscache_n_acquires_nobufs;
61249-atomic_t fscache_n_acquires_oom;
61250+atomic_unchecked_t fscache_n_acquires;
61251+atomic_unchecked_t fscache_n_acquires_null;
61252+atomic_unchecked_t fscache_n_acquires_no_cache;
61253+atomic_unchecked_t fscache_n_acquires_ok;
61254+atomic_unchecked_t fscache_n_acquires_nobufs;
61255+atomic_unchecked_t fscache_n_acquires_oom;
61256
61257-atomic_t fscache_n_invalidates;
61258-atomic_t fscache_n_invalidates_run;
61259+atomic_unchecked_t fscache_n_invalidates;
61260+atomic_unchecked_t fscache_n_invalidates_run;
61261
61262-atomic_t fscache_n_updates;
61263-atomic_t fscache_n_updates_null;
61264-atomic_t fscache_n_updates_run;
61265+atomic_unchecked_t fscache_n_updates;
61266+atomic_unchecked_t fscache_n_updates_null;
61267+atomic_unchecked_t fscache_n_updates_run;
61268
61269-atomic_t fscache_n_relinquishes;
61270-atomic_t fscache_n_relinquishes_null;
61271-atomic_t fscache_n_relinquishes_waitcrt;
61272-atomic_t fscache_n_relinquishes_retire;
61273+atomic_unchecked_t fscache_n_relinquishes;
61274+atomic_unchecked_t fscache_n_relinquishes_null;
61275+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61276+atomic_unchecked_t fscache_n_relinquishes_retire;
61277
61278-atomic_t fscache_n_cookie_index;
61279-atomic_t fscache_n_cookie_data;
61280-atomic_t fscache_n_cookie_special;
61281+atomic_unchecked_t fscache_n_cookie_index;
61282+atomic_unchecked_t fscache_n_cookie_data;
61283+atomic_unchecked_t fscache_n_cookie_special;
61284
61285-atomic_t fscache_n_object_alloc;
61286-atomic_t fscache_n_object_no_alloc;
61287-atomic_t fscache_n_object_lookups;
61288-atomic_t fscache_n_object_lookups_negative;
61289-atomic_t fscache_n_object_lookups_positive;
61290-atomic_t fscache_n_object_lookups_timed_out;
61291-atomic_t fscache_n_object_created;
61292-atomic_t fscache_n_object_avail;
61293-atomic_t fscache_n_object_dead;
61294+atomic_unchecked_t fscache_n_object_alloc;
61295+atomic_unchecked_t fscache_n_object_no_alloc;
61296+atomic_unchecked_t fscache_n_object_lookups;
61297+atomic_unchecked_t fscache_n_object_lookups_negative;
61298+atomic_unchecked_t fscache_n_object_lookups_positive;
61299+atomic_unchecked_t fscache_n_object_lookups_timed_out;
61300+atomic_unchecked_t fscache_n_object_created;
61301+atomic_unchecked_t fscache_n_object_avail;
61302+atomic_unchecked_t fscache_n_object_dead;
61303
61304-atomic_t fscache_n_checkaux_none;
61305-atomic_t fscache_n_checkaux_okay;
61306-atomic_t fscache_n_checkaux_update;
61307-atomic_t fscache_n_checkaux_obsolete;
61308+atomic_unchecked_t fscache_n_checkaux_none;
61309+atomic_unchecked_t fscache_n_checkaux_okay;
61310+atomic_unchecked_t fscache_n_checkaux_update;
61311+atomic_unchecked_t fscache_n_checkaux_obsolete;
61312
61313 atomic_t fscache_n_cop_alloc_object;
61314 atomic_t fscache_n_cop_lookup_object;
61315@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61316 seq_puts(m, "FS-Cache statistics\n");
61317
61318 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61319- atomic_read(&fscache_n_cookie_index),
61320- atomic_read(&fscache_n_cookie_data),
61321- atomic_read(&fscache_n_cookie_special));
61322+ atomic_read_unchecked(&fscache_n_cookie_index),
61323+ atomic_read_unchecked(&fscache_n_cookie_data),
61324+ atomic_read_unchecked(&fscache_n_cookie_special));
61325
61326 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61327- atomic_read(&fscache_n_object_alloc),
61328- atomic_read(&fscache_n_object_no_alloc),
61329- atomic_read(&fscache_n_object_avail),
61330- atomic_read(&fscache_n_object_dead));
61331+ atomic_read_unchecked(&fscache_n_object_alloc),
61332+ atomic_read_unchecked(&fscache_n_object_no_alloc),
61333+ atomic_read_unchecked(&fscache_n_object_avail),
61334+ atomic_read_unchecked(&fscache_n_object_dead));
61335 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61336- atomic_read(&fscache_n_checkaux_none),
61337- atomic_read(&fscache_n_checkaux_okay),
61338- atomic_read(&fscache_n_checkaux_update),
61339- atomic_read(&fscache_n_checkaux_obsolete));
61340+ atomic_read_unchecked(&fscache_n_checkaux_none),
61341+ atomic_read_unchecked(&fscache_n_checkaux_okay),
61342+ atomic_read_unchecked(&fscache_n_checkaux_update),
61343+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61344
61345 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61346- atomic_read(&fscache_n_marks),
61347- atomic_read(&fscache_n_uncaches));
61348+ atomic_read_unchecked(&fscache_n_marks),
61349+ atomic_read_unchecked(&fscache_n_uncaches));
61350
61351 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61352 " oom=%u\n",
61353- atomic_read(&fscache_n_acquires),
61354- atomic_read(&fscache_n_acquires_null),
61355- atomic_read(&fscache_n_acquires_no_cache),
61356- atomic_read(&fscache_n_acquires_ok),
61357- atomic_read(&fscache_n_acquires_nobufs),
61358- atomic_read(&fscache_n_acquires_oom));
61359+ atomic_read_unchecked(&fscache_n_acquires),
61360+ atomic_read_unchecked(&fscache_n_acquires_null),
61361+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
61362+ atomic_read_unchecked(&fscache_n_acquires_ok),
61363+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
61364+ atomic_read_unchecked(&fscache_n_acquires_oom));
61365
61366 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61367- atomic_read(&fscache_n_object_lookups),
61368- atomic_read(&fscache_n_object_lookups_negative),
61369- atomic_read(&fscache_n_object_lookups_positive),
61370- atomic_read(&fscache_n_object_created),
61371- atomic_read(&fscache_n_object_lookups_timed_out));
61372+ atomic_read_unchecked(&fscache_n_object_lookups),
61373+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
61374+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
61375+ atomic_read_unchecked(&fscache_n_object_created),
61376+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61377
61378 seq_printf(m, "Invals : n=%u run=%u\n",
61379- atomic_read(&fscache_n_invalidates),
61380- atomic_read(&fscache_n_invalidates_run));
61381+ atomic_read_unchecked(&fscache_n_invalidates),
61382+ atomic_read_unchecked(&fscache_n_invalidates_run));
61383
61384 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61385- atomic_read(&fscache_n_updates),
61386- atomic_read(&fscache_n_updates_null),
61387- atomic_read(&fscache_n_updates_run));
61388+ atomic_read_unchecked(&fscache_n_updates),
61389+ atomic_read_unchecked(&fscache_n_updates_null),
61390+ atomic_read_unchecked(&fscache_n_updates_run));
61391
61392 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61393- atomic_read(&fscache_n_relinquishes),
61394- atomic_read(&fscache_n_relinquishes_null),
61395- atomic_read(&fscache_n_relinquishes_waitcrt),
61396- atomic_read(&fscache_n_relinquishes_retire));
61397+ atomic_read_unchecked(&fscache_n_relinquishes),
61398+ atomic_read_unchecked(&fscache_n_relinquishes_null),
61399+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61400+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
61401
61402 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61403- atomic_read(&fscache_n_attr_changed),
61404- atomic_read(&fscache_n_attr_changed_ok),
61405- atomic_read(&fscache_n_attr_changed_nobufs),
61406- atomic_read(&fscache_n_attr_changed_nomem),
61407- atomic_read(&fscache_n_attr_changed_calls));
61408+ atomic_read_unchecked(&fscache_n_attr_changed),
61409+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
61410+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61411+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61412+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
61413
61414 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61415- atomic_read(&fscache_n_allocs),
61416- atomic_read(&fscache_n_allocs_ok),
61417- atomic_read(&fscache_n_allocs_wait),
61418- atomic_read(&fscache_n_allocs_nobufs),
61419- atomic_read(&fscache_n_allocs_intr));
61420+ atomic_read_unchecked(&fscache_n_allocs),
61421+ atomic_read_unchecked(&fscache_n_allocs_ok),
61422+ atomic_read_unchecked(&fscache_n_allocs_wait),
61423+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
61424+ atomic_read_unchecked(&fscache_n_allocs_intr));
61425 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61426- atomic_read(&fscache_n_alloc_ops),
61427- atomic_read(&fscache_n_alloc_op_waits),
61428- atomic_read(&fscache_n_allocs_object_dead));
61429+ atomic_read_unchecked(&fscache_n_alloc_ops),
61430+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
61431+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
61432
61433 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61434 " int=%u oom=%u\n",
61435- atomic_read(&fscache_n_retrievals),
61436- atomic_read(&fscache_n_retrievals_ok),
61437- atomic_read(&fscache_n_retrievals_wait),
61438- atomic_read(&fscache_n_retrievals_nodata),
61439- atomic_read(&fscache_n_retrievals_nobufs),
61440- atomic_read(&fscache_n_retrievals_intr),
61441- atomic_read(&fscache_n_retrievals_nomem));
61442+ atomic_read_unchecked(&fscache_n_retrievals),
61443+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61444+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61445+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61446+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61447+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61448+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61449 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61450- atomic_read(&fscache_n_retrieval_ops),
61451- atomic_read(&fscache_n_retrieval_op_waits),
61452- atomic_read(&fscache_n_retrievals_object_dead));
61453+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61454+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61455+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61456
61457 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61458- atomic_read(&fscache_n_stores),
61459- atomic_read(&fscache_n_stores_ok),
61460- atomic_read(&fscache_n_stores_again),
61461- atomic_read(&fscache_n_stores_nobufs),
61462- atomic_read(&fscache_n_stores_oom));
61463+ atomic_read_unchecked(&fscache_n_stores),
61464+ atomic_read_unchecked(&fscache_n_stores_ok),
61465+ atomic_read_unchecked(&fscache_n_stores_again),
61466+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61467+ atomic_read_unchecked(&fscache_n_stores_oom));
61468 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61469- atomic_read(&fscache_n_store_ops),
61470- atomic_read(&fscache_n_store_calls),
61471- atomic_read(&fscache_n_store_pages),
61472- atomic_read(&fscache_n_store_radix_deletes),
61473- atomic_read(&fscache_n_store_pages_over_limit));
61474+ atomic_read_unchecked(&fscache_n_store_ops),
61475+ atomic_read_unchecked(&fscache_n_store_calls),
61476+ atomic_read_unchecked(&fscache_n_store_pages),
61477+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61478+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61479
61480 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61481- atomic_read(&fscache_n_store_vmscan_not_storing),
61482- atomic_read(&fscache_n_store_vmscan_gone),
61483- atomic_read(&fscache_n_store_vmscan_busy),
61484- atomic_read(&fscache_n_store_vmscan_cancelled),
61485- atomic_read(&fscache_n_store_vmscan_wait));
61486+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61487+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61488+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61489+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61490+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61491
61492 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61493- atomic_read(&fscache_n_op_pend),
61494- atomic_read(&fscache_n_op_run),
61495- atomic_read(&fscache_n_op_enqueue),
61496- atomic_read(&fscache_n_op_cancelled),
61497- atomic_read(&fscache_n_op_rejected));
61498+ atomic_read_unchecked(&fscache_n_op_pend),
61499+ atomic_read_unchecked(&fscache_n_op_run),
61500+ atomic_read_unchecked(&fscache_n_op_enqueue),
61501+ atomic_read_unchecked(&fscache_n_op_cancelled),
61502+ atomic_read_unchecked(&fscache_n_op_rejected));
61503 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61504- atomic_read(&fscache_n_op_deferred_release),
61505- atomic_read(&fscache_n_op_release),
61506- atomic_read(&fscache_n_op_gc));
61507+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61508+ atomic_read_unchecked(&fscache_n_op_release),
61509+ atomic_read_unchecked(&fscache_n_op_gc));
61510
61511 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61512 atomic_read(&fscache_n_cop_alloc_object),
61513diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61514index 13b691a..1ffca5ae 100644
61515--- a/fs/fuse/cuse.c
61516+++ b/fs/fuse/cuse.c
61517@@ -607,10 +607,12 @@ static int __init cuse_init(void)
61518 INIT_LIST_HEAD(&cuse_conntbl[i]);
61519
61520 /* inherit and extend fuse_dev_operations */
61521- cuse_channel_fops = fuse_dev_operations;
61522- cuse_channel_fops.owner = THIS_MODULE;
61523- cuse_channel_fops.open = cuse_channel_open;
61524- cuse_channel_fops.release = cuse_channel_release;
61525+ pax_open_kernel();
61526+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61527+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61528+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61529+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61530+ pax_close_kernel();
61531
61532 cuse_class = class_create(THIS_MODULE, "cuse");
61533 if (IS_ERR(cuse_class))
61534diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61535index 75fa055..73b76d8 100644
61536--- a/fs/fuse/dev.c
61537+++ b/fs/fuse/dev.c
61538@@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61539 ret = 0;
61540 pipe_lock(pipe);
61541
61542- if (!pipe->readers) {
61543+ if (!atomic_read(&pipe->readers)) {
61544 send_sig(SIGPIPE, current, 0);
61545 if (!ret)
61546 ret = -EPIPE;
61547@@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61548 page_nr++;
61549 ret += buf->len;
61550
61551- if (pipe->files)
61552+ if (atomic_read(&pipe->files))
61553 do_wakeup = 1;
61554 }
61555
61556diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61557index 202a972..c4836eb 100644
61558--- a/fs/fuse/dir.c
61559+++ b/fs/fuse/dir.c
61560@@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
61561 return link;
61562 }
61563
61564-static void free_link(char *link)
61565+static void free_link(const char *link)
61566 {
61567 if (!IS_ERR(link))
61568 free_page((unsigned long) link);
61569diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61570index 9c470fd..aae410e 100644
61571--- a/fs/hostfs/hostfs_kern.c
61572+++ b/fs/hostfs/hostfs_kern.c
61573@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61574
61575 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61576 {
61577- char *s = nd_get_link(nd);
61578+ const char *s = nd_get_link(nd);
61579 if (!IS_ERR(s))
61580 __putname(s);
61581 }
61582diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61583index e19d4c0..8a357a9 100644
61584--- a/fs/hugetlbfs/inode.c
61585+++ b/fs/hugetlbfs/inode.c
61586@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61587 struct mm_struct *mm = current->mm;
61588 struct vm_area_struct *vma;
61589 struct hstate *h = hstate_file(file);
61590+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61591 struct vm_unmapped_area_info info;
61592
61593 if (len & ~huge_page_mask(h))
61594@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61595 return addr;
61596 }
61597
61598+#ifdef CONFIG_PAX_RANDMMAP
61599+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61600+#endif
61601+
61602 if (addr) {
61603 addr = ALIGN(addr, huge_page_size(h));
61604 vma = find_vma(mm, addr);
61605- if (TASK_SIZE - len >= addr &&
61606- (!vma || addr + len <= vma->vm_start))
61607+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61608 return addr;
61609 }
61610
61611 info.flags = 0;
61612 info.length = len;
61613 info.low_limit = TASK_UNMAPPED_BASE;
61614+
61615+#ifdef CONFIG_PAX_RANDMMAP
61616+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61617+ info.low_limit += mm->delta_mmap;
61618+#endif
61619+
61620 info.high_limit = TASK_SIZE;
61621 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61622 info.align_offset = 0;
61623@@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61624 };
61625 MODULE_ALIAS_FS("hugetlbfs");
61626
61627-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61628+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61629
61630 static int can_do_hugetlb_shm(void)
61631 {
61632diff --git a/fs/inode.c b/fs/inode.c
61633index d2fb2f2..a6444b0 100644
61634--- a/fs/inode.c
61635+++ b/fs/inode.c
61636@@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61637 unsigned int *p = &get_cpu_var(last_ino);
61638 unsigned int res = *p;
61639
61640+start:
61641+
61642 #ifdef CONFIG_SMP
61643 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61644- static atomic_t shared_last_ino;
61645- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61646+ static atomic_unchecked_t shared_last_ino;
61647+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61648
61649 res = next - LAST_INO_BATCH;
61650 }
61651 #endif
61652
61653- *p = ++res;
61654+ if (unlikely(!++res))
61655+ goto start; /* never zero */
61656+ *p = res;
61657 put_cpu_var(last_ino);
61658 return res;
61659 }
61660diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61661index 4a6cf28..d3a29d3 100644
61662--- a/fs/jffs2/erase.c
61663+++ b/fs/jffs2/erase.c
61664@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61665 struct jffs2_unknown_node marker = {
61666 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61667 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61668- .totlen = cpu_to_je32(c->cleanmarker_size)
61669+ .totlen = cpu_to_je32(c->cleanmarker_size),
61670+ .hdr_crc = cpu_to_je32(0)
61671 };
61672
61673 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61674diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61675index a6597d6..41b30ec 100644
61676--- a/fs/jffs2/wbuf.c
61677+++ b/fs/jffs2/wbuf.c
61678@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61679 {
61680 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61681 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61682- .totlen = constant_cpu_to_je32(8)
61683+ .totlen = constant_cpu_to_je32(8),
61684+ .hdr_crc = constant_cpu_to_je32(0)
61685 };
61686
61687 /*
61688diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61689index 97f7fda..09bd33d 100644
61690--- a/fs/jfs/super.c
61691+++ b/fs/jfs/super.c
61692@@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61693
61694 jfs_inode_cachep =
61695 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61696- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61697+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61698 init_once);
61699 if (jfs_inode_cachep == NULL)
61700 return -ENOMEM;
61701diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61702index a693f5b..82276a1 100644
61703--- a/fs/kernfs/dir.c
61704+++ b/fs/kernfs/dir.c
61705@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61706 *
61707 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61708 */
61709-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61710+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61711 {
61712 unsigned long hash = init_name_hash();
61713 unsigned int len = strlen(name);
61714diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61715index 5e9a80c..3853a24 100644
61716--- a/fs/kernfs/file.c
61717+++ b/fs/kernfs/file.c
61718@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61719
61720 struct kernfs_open_node {
61721 atomic_t refcnt;
61722- atomic_t event;
61723+ atomic_unchecked_t event;
61724 wait_queue_head_t poll;
61725 struct list_head files; /* goes through kernfs_open_file.list */
61726 };
61727@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61728 {
61729 struct kernfs_open_file *of = sf->private;
61730
61731- of->event = atomic_read(&of->kn->attr.open->event);
61732+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61733
61734 return of->kn->attr.ops->seq_show(sf, v);
61735 }
61736@@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61737 return ret;
61738 }
61739
61740-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61741- void *buf, int len, int write)
61742+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61743+ void *buf, size_t len, int write)
61744 {
61745 struct file *file = vma->vm_file;
61746 struct kernfs_open_file *of = kernfs_of(file);
61747- int ret;
61748+ ssize_t ret;
61749
61750 if (!of->vm_ops)
61751 return -EINVAL;
61752@@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61753 return -ENOMEM;
61754
61755 atomic_set(&new_on->refcnt, 0);
61756- atomic_set(&new_on->event, 1);
61757+ atomic_set_unchecked(&new_on->event, 1);
61758 init_waitqueue_head(&new_on->poll);
61759 INIT_LIST_HEAD(&new_on->files);
61760 goto retry;
61761@@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61762
61763 kernfs_put_active(kn);
61764
61765- if (of->event != atomic_read(&on->event))
61766+ if (of->event != atomic_read_unchecked(&on->event))
61767 goto trigger;
61768
61769 return DEFAULT_POLLMASK;
61770@@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
61771 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61772 on = kn->attr.open;
61773 if (on) {
61774- atomic_inc(&on->event);
61775+ atomic_inc_unchecked(&on->event);
61776 wake_up_interruptible(&on->poll);
61777 }
61778 }
61779diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61780index 8a19889..4c3069a 100644
61781--- a/fs/kernfs/symlink.c
61782+++ b/fs/kernfs/symlink.c
61783@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61784 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61785 void *cookie)
61786 {
61787- char *page = nd_get_link(nd);
61788+ const char *page = nd_get_link(nd);
61789 if (!IS_ERR(page))
61790 free_page((unsigned long)page);
61791 }
61792diff --git a/fs/libfs.c b/fs/libfs.c
61793index a184424..944ddce 100644
61794--- a/fs/libfs.c
61795+++ b/fs/libfs.c
61796@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61797
61798 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61799 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61800+ char d_name[sizeof(next->d_iname)];
61801+ const unsigned char *name;
61802+
61803 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61804 if (!simple_positive(next)) {
61805 spin_unlock(&next->d_lock);
61806@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61807
61808 spin_unlock(&next->d_lock);
61809 spin_unlock(&dentry->d_lock);
61810- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61811+ name = next->d_name.name;
61812+ if (name == next->d_iname) {
61813+ memcpy(d_name, name, next->d_name.len);
61814+ name = d_name;
61815+ }
61816+ if (!dir_emit(ctx, name, next->d_name.len,
61817 next->d_inode->i_ino, dt_type(next->d_inode)))
61818 return 0;
61819 spin_lock(&dentry->d_lock);
61820@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61821 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61822 void *cookie)
61823 {
61824- char *s = nd_get_link(nd);
61825+ const char *s = nd_get_link(nd);
61826 if (!IS_ERR(s))
61827 kfree(s);
61828 }
61829diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61830index acd3947..1f896e2 100644
61831--- a/fs/lockd/clntproc.c
61832+++ b/fs/lockd/clntproc.c
61833@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61834 /*
61835 * Cookie counter for NLM requests
61836 */
61837-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61838+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61839
61840 void nlmclnt_next_cookie(struct nlm_cookie *c)
61841 {
61842- u32 cookie = atomic_inc_return(&nlm_cookie);
61843+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61844
61845 memcpy(c->data, &cookie, 4);
61846 c->len=4;
61847diff --git a/fs/locks.c b/fs/locks.c
61848index e390bd9..c79870e 100644
61849--- a/fs/locks.c
61850+++ b/fs/locks.c
61851@@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
61852 locks_remove_posix(filp, (fl_owner_t)filp);
61853
61854 if (filp->f_op->flock) {
61855- struct file_lock fl = {
61856+ struct file_lock flock = {
61857 .fl_pid = current->tgid,
61858 .fl_file = filp,
61859 .fl_flags = FL_FLOCK,
61860 .fl_type = F_UNLCK,
61861 .fl_end = OFFSET_MAX,
61862 };
61863- filp->f_op->flock(filp, F_SETLKW, &fl);
61864- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61865- fl.fl_ops->fl_release_private(&fl);
61866+ filp->f_op->flock(filp, F_SETLKW, &flock);
61867+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61868+ flock.fl_ops->fl_release_private(&flock);
61869 }
61870
61871 spin_lock(&inode->i_lock);
61872diff --git a/fs/mount.h b/fs/mount.h
61873index d55297f..f5b28c5 100644
61874--- a/fs/mount.h
61875+++ b/fs/mount.h
61876@@ -11,7 +11,7 @@ struct mnt_namespace {
61877 u64 seq; /* Sequence number to prevent loops */
61878 wait_queue_head_t poll;
61879 u64 event;
61880-};
61881+} __randomize_layout;
61882
61883 struct mnt_pcp {
61884 int mnt_count;
61885@@ -57,7 +57,7 @@ struct mount {
61886 int mnt_expiry_mark; /* true if marked for expiry */
61887 int mnt_pinned;
61888 struct path mnt_ex_mountpoint;
61889-};
61890+} __randomize_layout;
61891
61892 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61893
61894diff --git a/fs/namei.c b/fs/namei.c
61895index 9eb787e..5f520b67 100644
61896--- a/fs/namei.c
61897+++ b/fs/namei.c
61898@@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61899 if (ret != -EACCES)
61900 return ret;
61901
61902+#ifdef CONFIG_GRKERNSEC
61903+ /* we'll block if we have to log due to a denied capability use */
61904+ if (mask & MAY_NOT_BLOCK)
61905+ return -ECHILD;
61906+#endif
61907+
61908 if (S_ISDIR(inode->i_mode)) {
61909 /* DACs are overridable for directories */
61910- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61911- return 0;
61912 if (!(mask & MAY_WRITE))
61913- if (capable_wrt_inode_uidgid(inode,
61914- CAP_DAC_READ_SEARCH))
61915+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61916+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61917 return 0;
61918+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61919+ return 0;
61920 return -EACCES;
61921 }
61922 /*
61923+ * Searching includes executable on directories, else just read.
61924+ */
61925+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61926+ if (mask == MAY_READ)
61927+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61928+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61929+ return 0;
61930+
61931+ /*
61932 * Read/write DACs are always overridable.
61933 * Executable DACs are overridable when there is
61934 * at least one exec bit set.
61935@@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61936 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61937 return 0;
61938
61939- /*
61940- * Searching includes executable on directories, else just read.
61941- */
61942- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61943- if (mask == MAY_READ)
61944- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61945- return 0;
61946-
61947 return -EACCES;
61948 }
61949 EXPORT_SYMBOL(generic_permission);
61950@@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61951 {
61952 struct dentry *dentry = link->dentry;
61953 int error;
61954- char *s;
61955+ const char *s;
61956
61957 BUG_ON(nd->flags & LOOKUP_RCU);
61958
61959@@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61960 if (error)
61961 goto out_put_nd_path;
61962
61963+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61964+ dentry->d_inode, dentry, nd->path.mnt)) {
61965+ error = -EACCES;
61966+ goto out_put_nd_path;
61967+ }
61968+
61969 nd->last_type = LAST_BIND;
61970 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61971 error = PTR_ERR(*p);
61972@@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61973 if (res)
61974 break;
61975 res = walk_component(nd, path, LOOKUP_FOLLOW);
61976+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61977+ res = -EACCES;
61978 put_link(nd, &link, cookie);
61979 } while (res > 0);
61980
61981@@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
61982 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61983 {
61984 unsigned long a, b, adata, bdata, mask, hash, len;
61985- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61986+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61987
61988 hash = a = 0;
61989 len = -sizeof(unsigned long);
61990@@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
61991 if (err)
61992 break;
61993 err = lookup_last(nd, &path);
61994+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61995+ err = -EACCES;
61996 put_link(nd, &link, cookie);
61997 }
61998 }
61999@@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
62000 if (!err)
62001 err = complete_walk(nd);
62002
62003+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
62004+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62005+ path_put(&nd->path);
62006+ err = -ENOENT;
62007+ }
62008+ }
62009+
62010 if (!err && nd->flags & LOOKUP_DIRECTORY) {
62011 if (!d_can_lookup(nd->path.dentry)) {
62012 path_put(&nd->path);
62013@@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
62014 retval = path_lookupat(dfd, name->name,
62015 flags | LOOKUP_REVAL, nd);
62016
62017- if (likely(!retval))
62018+ if (likely(!retval)) {
62019 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
62020+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
62021+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
62022+ path_put(&nd->path);
62023+ return -ENOENT;
62024+ }
62025+ }
62026+ }
62027 return retval;
62028 }
62029
62030@@ -2570,6 +2601,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
62031 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
62032 return -EPERM;
62033
62034+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
62035+ return -EPERM;
62036+ if (gr_handle_rawio(inode))
62037+ return -EPERM;
62038+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
62039+ return -EACCES;
62040+
62041 return 0;
62042 }
62043
62044@@ -2801,7 +2839,7 @@ looked_up:
62045 * cleared otherwise prior to returning.
62046 */
62047 static int lookup_open(struct nameidata *nd, struct path *path,
62048- struct file *file,
62049+ struct path *link, struct file *file,
62050 const struct open_flags *op,
62051 bool got_write, int *opened)
62052 {
62053@@ -2836,6 +2874,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62054 /* Negative dentry, just create the file */
62055 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
62056 umode_t mode = op->mode;
62057+
62058+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
62059+ error = -EACCES;
62060+ goto out_dput;
62061+ }
62062+
62063+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
62064+ error = -EACCES;
62065+ goto out_dput;
62066+ }
62067+
62068 if (!IS_POSIXACL(dir->d_inode))
62069 mode &= ~current_umask();
62070 /*
62071@@ -2857,6 +2906,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62072 nd->flags & LOOKUP_EXCL);
62073 if (error)
62074 goto out_dput;
62075+ else
62076+ gr_handle_create(dentry, nd->path.mnt);
62077 }
62078 out_no_open:
62079 path->dentry = dentry;
62080@@ -2871,7 +2922,7 @@ out_dput:
62081 /*
62082 * Handle the last step of open()
62083 */
62084-static int do_last(struct nameidata *nd, struct path *path,
62085+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62086 struct file *file, const struct open_flags *op,
62087 int *opened, struct filename *name)
62088 {
62089@@ -2921,6 +2972,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62090 if (error)
62091 return error;
62092
62093+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62094+ error = -ENOENT;
62095+ goto out;
62096+ }
62097+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62098+ error = -EACCES;
62099+ goto out;
62100+ }
62101+
62102 audit_inode(name, dir, LOOKUP_PARENT);
62103 error = -EISDIR;
62104 /* trailing slashes? */
62105@@ -2940,7 +3000,7 @@ retry_lookup:
62106 */
62107 }
62108 mutex_lock(&dir->d_inode->i_mutex);
62109- error = lookup_open(nd, path, file, op, got_write, opened);
62110+ error = lookup_open(nd, path, link, file, op, got_write, opened);
62111 mutex_unlock(&dir->d_inode->i_mutex);
62112
62113 if (error <= 0) {
62114@@ -2964,11 +3024,28 @@ retry_lookup:
62115 goto finish_open_created;
62116 }
62117
62118+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62119+ error = -ENOENT;
62120+ goto exit_dput;
62121+ }
62122+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62123+ error = -EACCES;
62124+ goto exit_dput;
62125+ }
62126+
62127 /*
62128 * create/update audit record if it already exists.
62129 */
62130- if (d_is_positive(path->dentry))
62131+ if (d_is_positive(path->dentry)) {
62132+ /* only check if O_CREAT is specified, all other checks need to go
62133+ into may_open */
62134+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62135+ error = -EACCES;
62136+ goto exit_dput;
62137+ }
62138+
62139 audit_inode(name, path->dentry, 0);
62140+ }
62141
62142 /*
62143 * If atomic_open() acquired write access it is dropped now due to
62144@@ -3009,6 +3086,11 @@ finish_lookup:
62145 }
62146 }
62147 BUG_ON(inode != path->dentry->d_inode);
62148+ /* if we're resolving a symlink to another symlink */
62149+ if (link && gr_handle_symlink_owner(link, inode)) {
62150+ error = -EACCES;
62151+ goto out;
62152+ }
62153 return 1;
62154 }
62155
62156@@ -3018,7 +3100,6 @@ finish_lookup:
62157 save_parent.dentry = nd->path.dentry;
62158 save_parent.mnt = mntget(path->mnt);
62159 nd->path.dentry = path->dentry;
62160-
62161 }
62162 nd->inode = inode;
62163 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62164@@ -3028,7 +3109,18 @@ finish_open:
62165 path_put(&save_parent);
62166 return error;
62167 }
62168+
62169+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62170+ error = -ENOENT;
62171+ goto out;
62172+ }
62173+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62174+ error = -EACCES;
62175+ goto out;
62176+ }
62177+
62178 audit_inode(name, nd->path.dentry, 0);
62179+
62180 error = -EISDIR;
62181 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
62182 goto out;
62183@@ -3191,7 +3283,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62184 if (unlikely(error))
62185 goto out;
62186
62187- error = do_last(nd, &path, file, op, &opened, pathname);
62188+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62189 while (unlikely(error > 0)) { /* trailing symlink */
62190 struct path link = path;
62191 void *cookie;
62192@@ -3209,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62193 error = follow_link(&link, nd, &cookie);
62194 if (unlikely(error))
62195 break;
62196- error = do_last(nd, &path, file, op, &opened, pathname);
62197+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
62198 put_link(nd, &link, cookie);
62199 }
62200 out:
62201@@ -3309,9 +3401,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62202 goto unlock;
62203
62204 error = -EEXIST;
62205- if (d_is_positive(dentry))
62206+ if (d_is_positive(dentry)) {
62207+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62208+ error = -ENOENT;
62209 goto fail;
62210-
62211+ }
62212 /*
62213 * Special case - lookup gave negative, but... we had foo/bar/
62214 * From the vfs_mknod() POV we just have a negative dentry -
62215@@ -3363,6 +3457,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62216 }
62217 EXPORT_SYMBOL(user_path_create);
62218
62219+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62220+{
62221+ struct filename *tmp = getname(pathname);
62222+ struct dentry *res;
62223+ if (IS_ERR(tmp))
62224+ return ERR_CAST(tmp);
62225+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62226+ if (IS_ERR(res))
62227+ putname(tmp);
62228+ else
62229+ *to = tmp;
62230+ return res;
62231+}
62232+
62233 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62234 {
62235 int error = may_create(dir, dentry);
62236@@ -3426,6 +3534,17 @@ retry:
62237
62238 if (!IS_POSIXACL(path.dentry->d_inode))
62239 mode &= ~current_umask();
62240+
62241+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62242+ error = -EPERM;
62243+ goto out;
62244+ }
62245+
62246+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62247+ error = -EACCES;
62248+ goto out;
62249+ }
62250+
62251 error = security_path_mknod(&path, dentry, mode, dev);
62252 if (error)
62253 goto out;
62254@@ -3442,6 +3561,8 @@ retry:
62255 break;
62256 }
62257 out:
62258+ if (!error)
62259+ gr_handle_create(dentry, path.mnt);
62260 done_path_create(&path, dentry);
62261 if (retry_estale(error, lookup_flags)) {
62262 lookup_flags |= LOOKUP_REVAL;
62263@@ -3495,9 +3616,16 @@ retry:
62264
62265 if (!IS_POSIXACL(path.dentry->d_inode))
62266 mode &= ~current_umask();
62267+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62268+ error = -EACCES;
62269+ goto out;
62270+ }
62271 error = security_path_mkdir(&path, dentry, mode);
62272 if (!error)
62273 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62274+ if (!error)
62275+ gr_handle_create(dentry, path.mnt);
62276+out:
62277 done_path_create(&path, dentry);
62278 if (retry_estale(error, lookup_flags)) {
62279 lookup_flags |= LOOKUP_REVAL;
62280@@ -3580,6 +3708,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62281 struct filename *name;
62282 struct dentry *dentry;
62283 struct nameidata nd;
62284+ ino_t saved_ino = 0;
62285+ dev_t saved_dev = 0;
62286 unsigned int lookup_flags = 0;
62287 retry:
62288 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62289@@ -3612,10 +3742,21 @@ retry:
62290 error = -ENOENT;
62291 goto exit3;
62292 }
62293+
62294+ saved_ino = dentry->d_inode->i_ino;
62295+ saved_dev = gr_get_dev_from_dentry(dentry);
62296+
62297+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62298+ error = -EACCES;
62299+ goto exit3;
62300+ }
62301+
62302 error = security_path_rmdir(&nd.path, dentry);
62303 if (error)
62304 goto exit3;
62305 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62306+ if (!error && (saved_dev || saved_ino))
62307+ gr_handle_delete(saved_ino, saved_dev);
62308 exit3:
62309 dput(dentry);
62310 exit2:
62311@@ -3706,6 +3847,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62312 struct nameidata nd;
62313 struct inode *inode = NULL;
62314 struct inode *delegated_inode = NULL;
62315+ ino_t saved_ino = 0;
62316+ dev_t saved_dev = 0;
62317 unsigned int lookup_flags = 0;
62318 retry:
62319 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62320@@ -3732,10 +3875,22 @@ retry_deleg:
62321 if (d_is_negative(dentry))
62322 goto slashes;
62323 ihold(inode);
62324+
62325+ if (inode->i_nlink <= 1) {
62326+ saved_ino = inode->i_ino;
62327+ saved_dev = gr_get_dev_from_dentry(dentry);
62328+ }
62329+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62330+ error = -EACCES;
62331+ goto exit2;
62332+ }
62333+
62334 error = security_path_unlink(&nd.path, dentry);
62335 if (error)
62336 goto exit2;
62337 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62338+ if (!error && (saved_ino || saved_dev))
62339+ gr_handle_delete(saved_ino, saved_dev);
62340 exit2:
62341 dput(dentry);
62342 }
62343@@ -3824,9 +3979,17 @@ retry:
62344 if (IS_ERR(dentry))
62345 goto out_putname;
62346
62347+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62348+ error = -EACCES;
62349+ goto out;
62350+ }
62351+
62352 error = security_path_symlink(&path, dentry, from->name);
62353 if (!error)
62354 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62355+ if (!error)
62356+ gr_handle_create(dentry, path.mnt);
62357+out:
62358 done_path_create(&path, dentry);
62359 if (retry_estale(error, lookup_flags)) {
62360 lookup_flags |= LOOKUP_REVAL;
62361@@ -3930,6 +4093,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62362 struct dentry *new_dentry;
62363 struct path old_path, new_path;
62364 struct inode *delegated_inode = NULL;
62365+ struct filename *to = NULL;
62366 int how = 0;
62367 int error;
62368
62369@@ -3953,7 +4117,7 @@ retry:
62370 if (error)
62371 return error;
62372
62373- new_dentry = user_path_create(newdfd, newname, &new_path,
62374+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62375 (how & LOOKUP_REVAL));
62376 error = PTR_ERR(new_dentry);
62377 if (IS_ERR(new_dentry))
62378@@ -3965,11 +4129,28 @@ retry:
62379 error = may_linkat(&old_path);
62380 if (unlikely(error))
62381 goto out_dput;
62382+
62383+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62384+ old_path.dentry->d_inode,
62385+ old_path.dentry->d_inode->i_mode, to)) {
62386+ error = -EACCES;
62387+ goto out_dput;
62388+ }
62389+
62390+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62391+ old_path.dentry, old_path.mnt, to)) {
62392+ error = -EACCES;
62393+ goto out_dput;
62394+ }
62395+
62396 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62397 if (error)
62398 goto out_dput;
62399 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62400+ if (!error)
62401+ gr_handle_create(new_dentry, new_path.mnt);
62402 out_dput:
62403+ putname(to);
62404 done_path_create(&new_path, new_dentry);
62405 if (delegated_inode) {
62406 error = break_deleg_wait(&delegated_inode);
62407@@ -4279,6 +4460,12 @@ retry_deleg:
62408 if (new_dentry == trap)
62409 goto exit5;
62410
62411+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62412+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
62413+ to, flags);
62414+ if (error)
62415+ goto exit5;
62416+
62417 error = security_path_rename(&oldnd.path, old_dentry,
62418 &newnd.path, new_dentry, flags);
62419 if (error)
62420@@ -4286,6 +4473,9 @@ retry_deleg:
62421 error = vfs_rename(old_dir->d_inode, old_dentry,
62422 new_dir->d_inode, new_dentry,
62423 &delegated_inode, flags);
62424+ if (!error)
62425+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62426+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
62427 exit5:
62428 dput(new_dentry);
62429 exit4:
62430@@ -4328,14 +4518,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62431
62432 int readlink_copy(char __user *buffer, int buflen, const char *link)
62433 {
62434+ char tmpbuf[64];
62435+ const char *newlink;
62436 int len = PTR_ERR(link);
62437+
62438 if (IS_ERR(link))
62439 goto out;
62440
62441 len = strlen(link);
62442 if (len > (unsigned) buflen)
62443 len = buflen;
62444- if (copy_to_user(buffer, link, len))
62445+
62446+ if (len < sizeof(tmpbuf)) {
62447+ memcpy(tmpbuf, link, len);
62448+ newlink = tmpbuf;
62449+ } else
62450+ newlink = link;
62451+
62452+ if (copy_to_user(buffer, newlink, len))
62453 len = -EFAULT;
62454 out:
62455 return len;
62456diff --git a/fs/namespace.c b/fs/namespace.c
62457index 182bc41..72e3cf1 100644
62458--- a/fs/namespace.c
62459+++ b/fs/namespace.c
62460@@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
62461 if (!(sb->s_flags & MS_RDONLY))
62462 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62463 up_write(&sb->s_umount);
62464+
62465+ gr_log_remount(mnt->mnt_devname, retval);
62466+
62467 return retval;
62468 }
62469
62470@@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
62471 }
62472 unlock_mount_hash();
62473 namespace_unlock();
62474+
62475+ gr_log_unmount(mnt->mnt_devname, retval);
62476+
62477 return retval;
62478 }
62479
62480@@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
62481 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62482 */
62483
62484-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62485+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62486 {
62487 struct path path;
62488 struct mount *mnt;
62489@@ -1431,7 +1437,7 @@ out:
62490 /*
62491 * The 2.0 compatible umount. No flags.
62492 */
62493-SYSCALL_DEFINE1(oldumount, char __user *, name)
62494+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62495 {
62496 return sys_umount(name, 0);
62497 }
62498@@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62499 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62500 MS_STRICTATIME);
62501
62502+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62503+ retval = -EPERM;
62504+ goto dput_out;
62505+ }
62506+
62507+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62508+ retval = -EPERM;
62509+ goto dput_out;
62510+ }
62511+
62512 if (flags & MS_REMOUNT)
62513 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62514 data_page);
62515@@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62516 dev_name, data_page);
62517 dput_out:
62518 path_put(&path);
62519+
62520+ gr_log_mount(dev_name, dir_name, retval);
62521+
62522 return retval;
62523 }
62524
62525@@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62526 * number incrementing at 10Ghz will take 12,427 years to wrap which
62527 * is effectively never, so we can ignore the possibility.
62528 */
62529-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62530+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62531
62532 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62533 {
62534@@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62535 kfree(new_ns);
62536 return ERR_PTR(ret);
62537 }
62538- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62539+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62540 atomic_set(&new_ns->count, 1);
62541 new_ns->root = NULL;
62542 INIT_LIST_HEAD(&new_ns->list);
62543@@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62544 return new_ns;
62545 }
62546
62547-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62548+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62549 struct user_namespace *user_ns, struct fs_struct *new_fs)
62550 {
62551 struct mnt_namespace *new_ns;
62552@@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62553 }
62554 EXPORT_SYMBOL(mount_subtree);
62555
62556-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62557- char __user *, type, unsigned long, flags, void __user *, data)
62558+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62559+ const char __user *, type, unsigned long, flags, void __user *, data)
62560 {
62561 int ret;
62562 char *kernel_type;
62563@@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62564 if (error)
62565 goto out2;
62566
62567+ if (gr_handle_chroot_pivot()) {
62568+ error = -EPERM;
62569+ goto out2;
62570+ }
62571+
62572 get_fs_root(current->fs, &root);
62573 old_mp = lock_mount(&old);
62574 error = PTR_ERR(old_mp);
62575@@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62576 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62577 return -EPERM;
62578
62579- if (fs->users != 1)
62580+ if (atomic_read(&fs->users) != 1)
62581 return -EINVAL;
62582
62583 get_mnt_ns(mnt_ns);
62584diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62585index f4ccfe6..a5cf064 100644
62586--- a/fs/nfs/callback_xdr.c
62587+++ b/fs/nfs/callback_xdr.c
62588@@ -51,7 +51,7 @@ struct callback_op {
62589 callback_decode_arg_t decode_args;
62590 callback_encode_res_t encode_res;
62591 long res_maxsize;
62592-};
62593+} __do_const;
62594
62595 static struct callback_op callback_ops[];
62596
62597diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62598index c79f3e7..d61d671 100644
62599--- a/fs/nfs/inode.c
62600+++ b/fs/nfs/inode.c
62601@@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62602 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62603 }
62604
62605-static atomic_long_t nfs_attr_generation_counter;
62606+static atomic_long_unchecked_t nfs_attr_generation_counter;
62607
62608 static unsigned long nfs_read_attr_generation_counter(void)
62609 {
62610- return atomic_long_read(&nfs_attr_generation_counter);
62611+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62612 }
62613
62614 unsigned long nfs_inc_attr_generation_counter(void)
62615 {
62616- return atomic_long_inc_return(&nfs_attr_generation_counter);
62617+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62618 }
62619
62620 void nfs_fattr_init(struct nfs_fattr *fattr)
62621diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
62622index 8f854dd..d0fec26 100644
62623--- a/fs/nfs/nfs3acl.c
62624+++ b/fs/nfs/nfs3acl.c
62625@@ -256,7 +256,7 @@ nfs3_list_one_acl(struct inode *inode, int type, const char *name, void *data,
62626 char *p = data + *result;
62627
62628 acl = get_acl(inode, type);
62629- if (!acl)
62630+ if (IS_ERR_OR_NULL(acl))
62631 return 0;
62632
62633 posix_acl_release(acl);
62634diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62635index 95e3720..46c23fa 100644
62636--- a/fs/nfsd/nfs4proc.c
62637+++ b/fs/nfsd/nfs4proc.c
62638@@ -1169,7 +1169,7 @@ struct nfsd4_operation {
62639 nfsd4op_rsize op_rsize_bop;
62640 stateid_getter op_get_currentstateid;
62641 stateid_setter op_set_currentstateid;
62642-};
62643+} __do_const;
62644
62645 static struct nfsd4_operation nfsd4_ops[];
62646
62647diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62648index 3297158..7bb8436 100644
62649--- a/fs/nfsd/nfs4xdr.c
62650+++ b/fs/nfsd/nfs4xdr.c
62651@@ -1541,7 +1541,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62652
62653 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62654
62655-static nfsd4_dec nfsd4_dec_ops[] = {
62656+static const nfsd4_dec nfsd4_dec_ops[] = {
62657 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62658 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62659 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62660diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62661index f8f060f..c4ba09a 100644
62662--- a/fs/nfsd/nfscache.c
62663+++ b/fs/nfsd/nfscache.c
62664@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62665 {
62666 struct svc_cacherep *rp = rqstp->rq_cacherep;
62667 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62668- int len;
62669+ long len;
62670 size_t bufsize = 0;
62671
62672 if (!rp)
62673 return;
62674
62675- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62676- len >>= 2;
62677+ if (statp) {
62678+ len = (char*)statp - (char*)resv->iov_base;
62679+ len = resv->iov_len - len;
62680+ len >>= 2;
62681+ }
62682
62683 /* Don't cache excessive amounts of data and XDR failures */
62684 if (!statp || len > (256 >> 2)) {
62685diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62686index 16f0673..1c2c30ab 100644
62687--- a/fs/nfsd/vfs.c
62688+++ b/fs/nfsd/vfs.c
62689@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62690 } else {
62691 oldfs = get_fs();
62692 set_fs(KERNEL_DS);
62693- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62694+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62695 set_fs(oldfs);
62696 }
62697
62698@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62699
62700 /* Write the data. */
62701 oldfs = get_fs(); set_fs(KERNEL_DS);
62702- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62703+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62704 set_fs(oldfs);
62705 if (host_err < 0)
62706 goto out_nfserr;
62707@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62708 */
62709
62710 oldfs = get_fs(); set_fs(KERNEL_DS);
62711- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62712+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62713 set_fs(oldfs);
62714
62715 if (host_err < 0)
62716diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62717index 52ccd34..43a53b1 100644
62718--- a/fs/nls/nls_base.c
62719+++ b/fs/nls/nls_base.c
62720@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62721
62722 int __register_nls(struct nls_table *nls, struct module *owner)
62723 {
62724- struct nls_table ** tmp = &tables;
62725+ struct nls_table *tmp = tables;
62726
62727 if (nls->next)
62728 return -EBUSY;
62729
62730- nls->owner = owner;
62731+ pax_open_kernel();
62732+ *(void **)&nls->owner = owner;
62733+ pax_close_kernel();
62734 spin_lock(&nls_lock);
62735- while (*tmp) {
62736- if (nls == *tmp) {
62737+ while (tmp) {
62738+ if (nls == tmp) {
62739 spin_unlock(&nls_lock);
62740 return -EBUSY;
62741 }
62742- tmp = &(*tmp)->next;
62743+ tmp = tmp->next;
62744 }
62745- nls->next = tables;
62746+ pax_open_kernel();
62747+ *(struct nls_table **)&nls->next = tables;
62748+ pax_close_kernel();
62749 tables = nls;
62750 spin_unlock(&nls_lock);
62751 return 0;
62752@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62753
62754 int unregister_nls(struct nls_table * nls)
62755 {
62756- struct nls_table ** tmp = &tables;
62757+ struct nls_table * const * tmp = &tables;
62758
62759 spin_lock(&nls_lock);
62760 while (*tmp) {
62761 if (nls == *tmp) {
62762- *tmp = nls->next;
62763+ pax_open_kernel();
62764+ *(struct nls_table **)tmp = nls->next;
62765+ pax_close_kernel();
62766 spin_unlock(&nls_lock);
62767 return 0;
62768 }
62769diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62770index 162b3f1..6076a7c 100644
62771--- a/fs/nls/nls_euc-jp.c
62772+++ b/fs/nls/nls_euc-jp.c
62773@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62774 p_nls = load_nls("cp932");
62775
62776 if (p_nls) {
62777- table.charset2upper = p_nls->charset2upper;
62778- table.charset2lower = p_nls->charset2lower;
62779+ pax_open_kernel();
62780+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62781+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62782+ pax_close_kernel();
62783 return register_nls(&table);
62784 }
62785
62786diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62787index a80a741..7b96e1b 100644
62788--- a/fs/nls/nls_koi8-ru.c
62789+++ b/fs/nls/nls_koi8-ru.c
62790@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62791 p_nls = load_nls("koi8-u");
62792
62793 if (p_nls) {
62794- table.charset2upper = p_nls->charset2upper;
62795- table.charset2lower = p_nls->charset2lower;
62796+ pax_open_kernel();
62797+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62798+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62799+ pax_close_kernel();
62800 return register_nls(&table);
62801 }
62802
62803diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62804index 732648b..d3b017f 100644
62805--- a/fs/notify/fanotify/fanotify_user.c
62806+++ b/fs/notify/fanotify/fanotify_user.c
62807@@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62808
62809 fd = fanotify_event_metadata.fd;
62810 ret = -EFAULT;
62811- if (copy_to_user(buf, &fanotify_event_metadata,
62812- fanotify_event_metadata.event_len))
62813+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62814+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62815 goto out_close_fd;
62816
62817 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62818diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62819index 1e58402..bb2d6f4 100644
62820--- a/fs/notify/notification.c
62821+++ b/fs/notify/notification.c
62822@@ -48,7 +48,7 @@
62823 #include <linux/fsnotify_backend.h>
62824 #include "fsnotify.h"
62825
62826-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62827+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62828
62829 /**
62830 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62831@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62832 */
62833 u32 fsnotify_get_cookie(void)
62834 {
62835- return atomic_inc_return(&fsnotify_sync_cookie);
62836+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62837 }
62838 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62839
62840diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62841index 9e38daf..5727cae 100644
62842--- a/fs/ntfs/dir.c
62843+++ b/fs/ntfs/dir.c
62844@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62845 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62846 ~(s64)(ndir->itype.index.block_size - 1)));
62847 /* Bounds checks. */
62848- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62849+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62850 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62851 "inode 0x%lx or driver bug.", vdir->i_ino);
62852 goto err_out;
62853diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62854index db9bd8a..8338fb6 100644
62855--- a/fs/ntfs/file.c
62856+++ b/fs/ntfs/file.c
62857@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62858 char *addr;
62859 size_t total = 0;
62860 unsigned len;
62861- int left;
62862+ unsigned left;
62863
62864 do {
62865 len = PAGE_CACHE_SIZE - ofs;
62866diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62867index 9de2491..3306095 100644
62868--- a/fs/ntfs/super.c
62869+++ b/fs/ntfs/super.c
62870@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62871 if (!silent)
62872 ntfs_error(sb, "Primary boot sector is invalid.");
62873 } else if (!silent)
62874- ntfs_error(sb, read_err_str, "primary");
62875+ ntfs_error(sb, read_err_str, "%s", "primary");
62876 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62877 if (bh_primary)
62878 brelse(bh_primary);
62879@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62880 goto hotfix_primary_boot_sector;
62881 brelse(bh_backup);
62882 } else if (!silent)
62883- ntfs_error(sb, read_err_str, "backup");
62884+ ntfs_error(sb, read_err_str, "%s", "backup");
62885 /* Try to read NT3.51- backup boot sector. */
62886 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62887 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62888@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62889 "sector.");
62890 brelse(bh_backup);
62891 } else if (!silent)
62892- ntfs_error(sb, read_err_str, "backup");
62893+ ntfs_error(sb, read_err_str, "%s", "backup");
62894 /* We failed. Cleanup and return. */
62895 if (bh_primary)
62896 brelse(bh_primary);
62897diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62898index 0440134..d52c93a 100644
62899--- a/fs/ocfs2/localalloc.c
62900+++ b/fs/ocfs2/localalloc.c
62901@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62902 goto bail;
62903 }
62904
62905- atomic_inc(&osb->alloc_stats.moves);
62906+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62907
62908 bail:
62909 if (handle)
62910diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62911index 8d64a97..c37665d 100644
62912--- a/fs/ocfs2/ocfs2.h
62913+++ b/fs/ocfs2/ocfs2.h
62914@@ -236,11 +236,11 @@ enum ocfs2_vol_state
62915
62916 struct ocfs2_alloc_stats
62917 {
62918- atomic_t moves;
62919- atomic_t local_data;
62920- atomic_t bitmap_data;
62921- atomic_t bg_allocs;
62922- atomic_t bg_extends;
62923+ atomic_unchecked_t moves;
62924+ atomic_unchecked_t local_data;
62925+ atomic_unchecked_t bitmap_data;
62926+ atomic_unchecked_t bg_allocs;
62927+ atomic_unchecked_t bg_extends;
62928 };
62929
62930 enum ocfs2_local_alloc_state
62931diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62932index 0cb889a..6a26b24 100644
62933--- a/fs/ocfs2/suballoc.c
62934+++ b/fs/ocfs2/suballoc.c
62935@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62936 mlog_errno(status);
62937 goto bail;
62938 }
62939- atomic_inc(&osb->alloc_stats.bg_extends);
62940+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62941
62942 /* You should never ask for this much metadata */
62943 BUG_ON(bits_wanted >
62944@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62945 mlog_errno(status);
62946 goto bail;
62947 }
62948- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62949+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62950
62951 *suballoc_loc = res.sr_bg_blkno;
62952 *suballoc_bit_start = res.sr_bit_offset;
62953@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62954 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62955 res->sr_bits);
62956
62957- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62958+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62959
62960 BUG_ON(res->sr_bits != 1);
62961
62962@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62963 mlog_errno(status);
62964 goto bail;
62965 }
62966- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62967+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62968
62969 BUG_ON(res.sr_bits != 1);
62970
62971@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62972 cluster_start,
62973 num_clusters);
62974 if (!status)
62975- atomic_inc(&osb->alloc_stats.local_data);
62976+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62977 } else {
62978 if (min_clusters > (osb->bitmap_cpg - 1)) {
62979 /* The only paths asking for contiguousness
62980@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62981 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62982 res.sr_bg_blkno,
62983 res.sr_bit_offset);
62984- atomic_inc(&osb->alloc_stats.bitmap_data);
62985+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62986 *num_clusters = res.sr_bits;
62987 }
62988 }
62989diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62990index a7cdd56..c583144 100644
62991--- a/fs/ocfs2/super.c
62992+++ b/fs/ocfs2/super.c
62993@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62994 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62995 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62996 "Stats",
62997- atomic_read(&osb->alloc_stats.bitmap_data),
62998- atomic_read(&osb->alloc_stats.local_data),
62999- atomic_read(&osb->alloc_stats.bg_allocs),
63000- atomic_read(&osb->alloc_stats.moves),
63001- atomic_read(&osb->alloc_stats.bg_extends));
63002+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
63003+ atomic_read_unchecked(&osb->alloc_stats.local_data),
63004+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
63005+ atomic_read_unchecked(&osb->alloc_stats.moves),
63006+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
63007
63008 out += snprintf(buf + out, len - out,
63009 "%10s => State: %u Descriptor: %llu Size: %u bits "
63010@@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
63011
63012 mutex_init(&osb->system_file_mutex);
63013
63014- atomic_set(&osb->alloc_stats.moves, 0);
63015- atomic_set(&osb->alloc_stats.local_data, 0);
63016- atomic_set(&osb->alloc_stats.bitmap_data, 0);
63017- atomic_set(&osb->alloc_stats.bg_allocs, 0);
63018- atomic_set(&osb->alloc_stats.bg_extends, 0);
63019+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
63020+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
63021+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
63022+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
63023+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
63024
63025 /* Copy the blockcheck stats from the superblock probe */
63026 osb->osb_ecc_stats = *stats;
63027diff --git a/fs/open.c b/fs/open.c
63028index dd24f21..c1f4b3a 100644
63029--- a/fs/open.c
63030+++ b/fs/open.c
63031@@ -32,6 +32,8 @@
63032 #include <linux/dnotify.h>
63033 #include <linux/compat.h>
63034
63035+#define CREATE_TRACE_POINTS
63036+#include <trace/events/fs.h>
63037 #include "internal.h"
63038
63039 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
63040@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
63041 error = locks_verify_truncate(inode, NULL, length);
63042 if (!error)
63043 error = security_path_truncate(path);
63044+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
63045+ error = -EACCES;
63046 if (!error)
63047 error = do_truncate(path->dentry, length, 0, NULL);
63048
63049@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
63050 error = locks_verify_truncate(inode, f.file, length);
63051 if (!error)
63052 error = security_path_truncate(&f.file->f_path);
63053+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
63054+ error = -EACCES;
63055 if (!error)
63056 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
63057 sb_end_write(inode->i_sb);
63058@@ -380,6 +386,9 @@ retry:
63059 if (__mnt_is_readonly(path.mnt))
63060 res = -EROFS;
63061
63062+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
63063+ res = -EACCES;
63064+
63065 out_path_release:
63066 path_put(&path);
63067 if (retry_estale(res, lookup_flags)) {
63068@@ -411,6 +420,8 @@ retry:
63069 if (error)
63070 goto dput_and_out;
63071
63072+ gr_log_chdir(path.dentry, path.mnt);
63073+
63074 set_fs_pwd(current->fs, &path);
63075
63076 dput_and_out:
63077@@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
63078 goto out_putf;
63079
63080 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
63081+
63082+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
63083+ error = -EPERM;
63084+
63085+ if (!error)
63086+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63087+
63088 if (!error)
63089 set_fs_pwd(current->fs, &f.file->f_path);
63090 out_putf:
63091@@ -469,7 +487,13 @@ retry:
63092 if (error)
63093 goto dput_and_out;
63094
63095+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63096+ goto dput_and_out;
63097+
63098 set_fs_root(current->fs, &path);
63099+
63100+ gr_handle_chroot_chdir(&path);
63101+
63102 error = 0;
63103 dput_and_out:
63104 path_put(&path);
63105@@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
63106 return error;
63107 retry_deleg:
63108 mutex_lock(&inode->i_mutex);
63109+
63110+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63111+ error = -EACCES;
63112+ goto out_unlock;
63113+ }
63114+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63115+ error = -EACCES;
63116+ goto out_unlock;
63117+ }
63118+
63119 error = security_path_chmod(path, mode);
63120 if (error)
63121 goto out_unlock;
63122@@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63123 uid = make_kuid(current_user_ns(), user);
63124 gid = make_kgid(current_user_ns(), group);
63125
63126+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
63127+ return -EACCES;
63128+
63129 newattrs.ia_valid = ATTR_CTIME;
63130 if (user != (uid_t) -1) {
63131 if (!uid_valid(uid))
63132@@ -977,6 +1014,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63133 } else {
63134 fsnotify_open(f);
63135 fd_install(fd, f);
63136+ trace_do_sys_open(tmp->name, flags, mode);
63137 }
63138 }
63139 putname(tmp);
63140diff --git a/fs/pipe.c b/fs/pipe.c
63141index 034bffa..6c6b522 100644
63142--- a/fs/pipe.c
63143+++ b/fs/pipe.c
63144@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63145
63146 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63147 {
63148- if (pipe->files)
63149+ if (atomic_read(&pipe->files))
63150 mutex_lock_nested(&pipe->mutex, subclass);
63151 }
63152
63153@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63154
63155 void pipe_unlock(struct pipe_inode_info *pipe)
63156 {
63157- if (pipe->files)
63158+ if (atomic_read(&pipe->files))
63159 mutex_unlock(&pipe->mutex);
63160 }
63161 EXPORT_SYMBOL(pipe_unlock);
63162@@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
63163 }
63164 if (bufs) /* More to do? */
63165 continue;
63166- if (!pipe->writers)
63167+ if (!atomic_read(&pipe->writers))
63168 break;
63169- if (!pipe->waiting_writers) {
63170+ if (!atomic_read(&pipe->waiting_writers)) {
63171 /* syscall merging: Usually we must not sleep
63172 * if O_NONBLOCK is set, or if we got some data.
63173 * But if a writer sleeps in kernel space, then
63174@@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63175 ret = 0;
63176 __pipe_lock(pipe);
63177
63178- if (!pipe->readers) {
63179+ if (!atomic_read(&pipe->readers)) {
63180 send_sig(SIGPIPE, current, 0);
63181 ret = -EPIPE;
63182 goto out;
63183@@ -461,7 +461,7 @@ redo1:
63184 for (;;) {
63185 int bufs;
63186
63187- if (!pipe->readers) {
63188+ if (!atomic_read(&pipe->readers)) {
63189 send_sig(SIGPIPE, current, 0);
63190 if (!ret)
63191 ret = -EPIPE;
63192@@ -552,9 +552,9 @@ redo2:
63193 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63194 do_wakeup = 0;
63195 }
63196- pipe->waiting_writers++;
63197+ atomic_inc(&pipe->waiting_writers);
63198 pipe_wait(pipe);
63199- pipe->waiting_writers--;
63200+ atomic_dec(&pipe->waiting_writers);
63201 }
63202 out:
63203 __pipe_unlock(pipe);
63204@@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63205 mask = 0;
63206 if (filp->f_mode & FMODE_READ) {
63207 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63208- if (!pipe->writers && filp->f_version != pipe->w_counter)
63209+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63210 mask |= POLLHUP;
63211 }
63212
63213@@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63214 * Most Unices do not set POLLERR for FIFOs but on Linux they
63215 * behave exactly like pipes for poll().
63216 */
63217- if (!pipe->readers)
63218+ if (!atomic_read(&pipe->readers))
63219 mask |= POLLERR;
63220 }
63221
63222@@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63223 int kill = 0;
63224
63225 spin_lock(&inode->i_lock);
63226- if (!--pipe->files) {
63227+ if (atomic_dec_and_test(&pipe->files)) {
63228 inode->i_pipe = NULL;
63229 kill = 1;
63230 }
63231@@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
63232
63233 __pipe_lock(pipe);
63234 if (file->f_mode & FMODE_READ)
63235- pipe->readers--;
63236+ atomic_dec(&pipe->readers);
63237 if (file->f_mode & FMODE_WRITE)
63238- pipe->writers--;
63239+ atomic_dec(&pipe->writers);
63240
63241- if (pipe->readers || pipe->writers) {
63242+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63243 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63244 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63245 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63246@@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63247 kfree(pipe);
63248 }
63249
63250-static struct vfsmount *pipe_mnt __read_mostly;
63251+struct vfsmount *pipe_mnt __read_mostly;
63252
63253 /*
63254 * pipefs_dname() is called from d_path().
63255@@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
63256 goto fail_iput;
63257
63258 inode->i_pipe = pipe;
63259- pipe->files = 2;
63260- pipe->readers = pipe->writers = 1;
63261+ atomic_set(&pipe->files, 2);
63262+ atomic_set(&pipe->readers, 1);
63263+ atomic_set(&pipe->writers, 1);
63264 inode->i_fop = &pipefifo_fops;
63265
63266 /*
63267@@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63268 spin_lock(&inode->i_lock);
63269 if (inode->i_pipe) {
63270 pipe = inode->i_pipe;
63271- pipe->files++;
63272+ atomic_inc(&pipe->files);
63273 spin_unlock(&inode->i_lock);
63274 } else {
63275 spin_unlock(&inode->i_lock);
63276 pipe = alloc_pipe_info();
63277 if (!pipe)
63278 return -ENOMEM;
63279- pipe->files = 1;
63280+ atomic_set(&pipe->files, 1);
63281 spin_lock(&inode->i_lock);
63282 if (unlikely(inode->i_pipe)) {
63283- inode->i_pipe->files++;
63284+ atomic_inc(&inode->i_pipe->files);
63285 spin_unlock(&inode->i_lock);
63286 free_pipe_info(pipe);
63287 pipe = inode->i_pipe;
63288@@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63289 * opened, even when there is no process writing the FIFO.
63290 */
63291 pipe->r_counter++;
63292- if (pipe->readers++ == 0)
63293+ if (atomic_inc_return(&pipe->readers) == 1)
63294 wake_up_partner(pipe);
63295
63296- if (!is_pipe && !pipe->writers) {
63297+ if (!is_pipe && !atomic_read(&pipe->writers)) {
63298 if ((filp->f_flags & O_NONBLOCK)) {
63299 /* suppress POLLHUP until we have
63300 * seen a writer */
63301@@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63302 * errno=ENXIO when there is no process reading the FIFO.
63303 */
63304 ret = -ENXIO;
63305- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63306+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63307 goto err;
63308
63309 pipe->w_counter++;
63310- if (!pipe->writers++)
63311+ if (atomic_inc_return(&pipe->writers) == 1)
63312 wake_up_partner(pipe);
63313
63314- if (!is_pipe && !pipe->readers) {
63315+ if (!is_pipe && !atomic_read(&pipe->readers)) {
63316 if (wait_for_partner(pipe, &pipe->r_counter))
63317 goto err_wr;
63318 }
63319@@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63320 * the process can at least talk to itself.
63321 */
63322
63323- pipe->readers++;
63324- pipe->writers++;
63325+ atomic_inc(&pipe->readers);
63326+ atomic_inc(&pipe->writers);
63327 pipe->r_counter++;
63328 pipe->w_counter++;
63329- if (pipe->readers == 1 || pipe->writers == 1)
63330+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63331 wake_up_partner(pipe);
63332 break;
63333
63334@@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63335 return 0;
63336
63337 err_rd:
63338- if (!--pipe->readers)
63339+ if (atomic_dec_and_test(&pipe->readers))
63340 wake_up_interruptible(&pipe->wait);
63341 ret = -ERESTARTSYS;
63342 goto err;
63343
63344 err_wr:
63345- if (!--pipe->writers)
63346+ if (atomic_dec_and_test(&pipe->writers))
63347 wake_up_interruptible(&pipe->wait);
63348 ret = -ERESTARTSYS;
63349 goto err;
63350diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63351index 0855f77..6787d50 100644
63352--- a/fs/posix_acl.c
63353+++ b/fs/posix_acl.c
63354@@ -20,6 +20,7 @@
63355 #include <linux/xattr.h>
63356 #include <linux/export.h>
63357 #include <linux/user_namespace.h>
63358+#include <linux/grsecurity.h>
63359
63360 struct posix_acl **acl_by_type(struct inode *inode, int type)
63361 {
63362@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63363 }
63364 }
63365 if (mode_p)
63366- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63367+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63368 return not_equiv;
63369 }
63370 EXPORT_SYMBOL(posix_acl_equiv_mode);
63371@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63372 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63373 }
63374
63375- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63376+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63377 return not_equiv;
63378 }
63379
63380@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63381 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63382 int err = -ENOMEM;
63383 if (clone) {
63384+ *mode_p &= ~gr_acl_umask();
63385+
63386 err = posix_acl_create_masq(clone, mode_p);
63387 if (err < 0) {
63388 posix_acl_release(clone);
63389@@ -659,11 +662,12 @@ struct posix_acl *
63390 posix_acl_from_xattr(struct user_namespace *user_ns,
63391 const void *value, size_t size)
63392 {
63393- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63394- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63395+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63396+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63397 int count;
63398 struct posix_acl *acl;
63399 struct posix_acl_entry *acl_e;
63400+ umode_t umask = gr_acl_umask();
63401
63402 if (!value)
63403 return NULL;
63404@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63405
63406 switch(acl_e->e_tag) {
63407 case ACL_USER_OBJ:
63408+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63409+ break;
63410 case ACL_GROUP_OBJ:
63411 case ACL_MASK:
63412+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63413+ break;
63414 case ACL_OTHER:
63415+ acl_e->e_perm &= ~(umask & S_IRWXO);
63416 break;
63417
63418 case ACL_USER:
63419+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63420 acl_e->e_uid =
63421 make_kuid(user_ns,
63422 le32_to_cpu(entry->e_id));
63423@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63424 goto fail;
63425 break;
63426 case ACL_GROUP:
63427+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63428 acl_e->e_gid =
63429 make_kgid(user_ns,
63430 le32_to_cpu(entry->e_id));
63431diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63432index 2183fcf..3c32a98 100644
63433--- a/fs/proc/Kconfig
63434+++ b/fs/proc/Kconfig
63435@@ -30,7 +30,7 @@ config PROC_FS
63436
63437 config PROC_KCORE
63438 bool "/proc/kcore support" if !ARM
63439- depends on PROC_FS && MMU
63440+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63441 help
63442 Provides a virtual ELF core file of the live kernel. This can
63443 be read with gdb and other ELF tools. No modifications can be
63444@@ -38,8 +38,8 @@ config PROC_KCORE
63445
63446 config PROC_VMCORE
63447 bool "/proc/vmcore support"
63448- depends on PROC_FS && CRASH_DUMP
63449- default y
63450+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63451+ default n
63452 help
63453 Exports the dump image of crashed kernel in ELF format.
63454
63455@@ -63,8 +63,8 @@ config PROC_SYSCTL
63456 limited in memory.
63457
63458 config PROC_PAGE_MONITOR
63459- default y
63460- depends on PROC_FS && MMU
63461+ default n
63462+ depends on PROC_FS && MMU && !GRKERNSEC
63463 bool "Enable /proc page monitoring" if EXPERT
63464 help
63465 Various /proc files exist to monitor process memory utilization:
63466diff --git a/fs/proc/array.c b/fs/proc/array.c
63467index 64db2bc..a8185d6 100644
63468--- a/fs/proc/array.c
63469+++ b/fs/proc/array.c
63470@@ -60,6 +60,7 @@
63471 #include <linux/tty.h>
63472 #include <linux/string.h>
63473 #include <linux/mman.h>
63474+#include <linux/grsecurity.h>
63475 #include <linux/proc_fs.h>
63476 #include <linux/ioport.h>
63477 #include <linux/uaccess.h>
63478@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63479 seq_putc(m, '\n');
63480 }
63481
63482+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63483+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63484+{
63485+ if (p->mm)
63486+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63487+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63488+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63489+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63490+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63491+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63492+ else
63493+ seq_printf(m, "PaX:\t-----\n");
63494+}
63495+#endif
63496+
63497 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63498 struct pid *pid, struct task_struct *task)
63499 {
63500@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63501 task_cpus_allowed(m, task);
63502 cpuset_task_status_allowed(m, task);
63503 task_context_switch_counts(m, task);
63504+
63505+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63506+ task_pax(m, task);
63507+#endif
63508+
63509+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63510+ task_grsec_rbac(m, task);
63511+#endif
63512+
63513 return 0;
63514 }
63515
63516+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63517+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63518+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63519+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63520+#endif
63521+
63522 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63523 struct pid *pid, struct task_struct *task, int whole)
63524 {
63525@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63526 char tcomm[sizeof(task->comm)];
63527 unsigned long flags;
63528
63529+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63530+ if (current->exec_id != m->exec_id) {
63531+ gr_log_badprocpid("stat");
63532+ return 0;
63533+ }
63534+#endif
63535+
63536 state = *get_task_state(task);
63537 vsize = eip = esp = 0;
63538 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63539@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63540 gtime = task_gtime(task);
63541 }
63542
63543+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63544+ if (PAX_RAND_FLAGS(mm)) {
63545+ eip = 0;
63546+ esp = 0;
63547+ wchan = 0;
63548+ }
63549+#endif
63550+#ifdef CONFIG_GRKERNSEC_HIDESYM
63551+ wchan = 0;
63552+ eip =0;
63553+ esp =0;
63554+#endif
63555+
63556 /* scale priority and nice values from timeslices to -20..20 */
63557 /* to make it look like a "normal" Unix priority/nice value */
63558 priority = task_prio(task);
63559@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63560 seq_put_decimal_ull(m, ' ', vsize);
63561 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63562 seq_put_decimal_ull(m, ' ', rsslim);
63563+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63564+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63565+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63566+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63567+#else
63568 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63569 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63570 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63571+#endif
63572 seq_put_decimal_ull(m, ' ', esp);
63573 seq_put_decimal_ull(m, ' ', eip);
63574 /* The signal information here is obsolete.
63575@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63576 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63577 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63578
63579- if (mm && permitted) {
63580+ if (mm && permitted
63581+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63582+ && !PAX_RAND_FLAGS(mm)
63583+#endif
63584+ ) {
63585 seq_put_decimal_ull(m, ' ', mm->start_data);
63586 seq_put_decimal_ull(m, ' ', mm->end_data);
63587 seq_put_decimal_ull(m, ' ', mm->start_brk);
63588@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63589 struct pid *pid, struct task_struct *task)
63590 {
63591 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63592- struct mm_struct *mm = get_task_mm(task);
63593+ struct mm_struct *mm;
63594
63595+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63596+ if (current->exec_id != m->exec_id) {
63597+ gr_log_badprocpid("statm");
63598+ return 0;
63599+ }
63600+#endif
63601+ mm = get_task_mm(task);
63602 if (mm) {
63603 size = task_statm(mm, &shared, &text, &data, &resident);
63604 mmput(mm);
63605@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63606 return 0;
63607 }
63608
63609+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63610+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63611+{
63612+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63613+}
63614+#endif
63615+
63616 #ifdef CONFIG_CHECKPOINT_RESTORE
63617 static struct pid *
63618 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63619diff --git a/fs/proc/base.c b/fs/proc/base.c
63620index 2d696b0..b9da447 100644
63621--- a/fs/proc/base.c
63622+++ b/fs/proc/base.c
63623@@ -113,6 +113,14 @@ struct pid_entry {
63624 union proc_op op;
63625 };
63626
63627+struct getdents_callback {
63628+ struct linux_dirent __user * current_dir;
63629+ struct linux_dirent __user * previous;
63630+ struct file * file;
63631+ int count;
63632+ int error;
63633+};
63634+
63635 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63636 .name = (NAME), \
63637 .len = sizeof(NAME) - 1, \
63638@@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63639 return get_cmdline(task, buffer, PAGE_SIZE);
63640 }
63641
63642+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63643+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63644+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63645+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63646+#endif
63647+
63648 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63649 {
63650 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63651 int res = PTR_ERR(mm);
63652 if (mm && !IS_ERR(mm)) {
63653 unsigned int nwords = 0;
63654+
63655+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63656+ /* allow if we're currently ptracing this task */
63657+ if (PAX_RAND_FLAGS(mm) &&
63658+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63659+ mmput(mm);
63660+ return 0;
63661+ }
63662+#endif
63663+
63664 do {
63665 nwords += 2;
63666 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63667@@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63668 }
63669
63670
63671-#ifdef CONFIG_KALLSYMS
63672+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63673 /*
63674 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63675 * Returns the resolved symbol. If that fails, simply return the address.
63676@@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63677 mutex_unlock(&task->signal->cred_guard_mutex);
63678 }
63679
63680-#ifdef CONFIG_STACKTRACE
63681+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63682
63683 #define MAX_STACK_TRACE_DEPTH 64
63684
63685@@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63686 return count;
63687 }
63688
63689-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63690+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63691 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63692 {
63693 long nr;
63694@@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63695 /************************************************************************/
63696
63697 /* permission checks */
63698-static int proc_fd_access_allowed(struct inode *inode)
63699+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63700 {
63701 struct task_struct *task;
63702 int allowed = 0;
63703@@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63704 */
63705 task = get_proc_task(inode);
63706 if (task) {
63707- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63708+ if (log)
63709+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63710+ else
63711+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63712 put_task_struct(task);
63713 }
63714 return allowed;
63715@@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63716 struct task_struct *task,
63717 int hide_pid_min)
63718 {
63719+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63720+ return false;
63721+
63722+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63723+ rcu_read_lock();
63724+ {
63725+ const struct cred *tmpcred = current_cred();
63726+ const struct cred *cred = __task_cred(task);
63727+
63728+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63729+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63730+ || in_group_p(grsec_proc_gid)
63731+#endif
63732+ ) {
63733+ rcu_read_unlock();
63734+ return true;
63735+ }
63736+ }
63737+ rcu_read_unlock();
63738+
63739+ if (!pid->hide_pid)
63740+ return false;
63741+#endif
63742+
63743 if (pid->hide_pid < hide_pid_min)
63744 return true;
63745 if (in_group_p(pid->pid_gid))
63746 return true;
63747+
63748 return ptrace_may_access(task, PTRACE_MODE_READ);
63749 }
63750
63751@@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63752 put_task_struct(task);
63753
63754 if (!has_perms) {
63755+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63756+ {
63757+#else
63758 if (pid->hide_pid == 2) {
63759+#endif
63760 /*
63761 * Let's make getdents(), stat(), and open()
63762 * consistent with each other. If a process
63763@@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63764 if (!task)
63765 return -ESRCH;
63766
63767+ if (gr_acl_handle_procpidmem(task)) {
63768+ put_task_struct(task);
63769+ return -EPERM;
63770+ }
63771+
63772 mm = mm_access(task, mode);
63773 put_task_struct(task);
63774
63775@@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63776
63777 file->private_data = mm;
63778
63779+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63780+ file->f_version = current->exec_id;
63781+#endif
63782+
63783 return 0;
63784 }
63785
63786@@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63787 ssize_t copied;
63788 char *page;
63789
63790+#ifdef CONFIG_GRKERNSEC
63791+ if (write)
63792+ return -EPERM;
63793+#endif
63794+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63795+ if (file->f_version != current->exec_id) {
63796+ gr_log_badprocpid("mem");
63797+ return 0;
63798+ }
63799+#endif
63800+
63801 if (!mm)
63802 return 0;
63803
63804@@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63805 goto free;
63806
63807 while (count > 0) {
63808- int this_len = min_t(int, count, PAGE_SIZE);
63809+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63810
63811 if (write && copy_from_user(page, buf, this_len)) {
63812 copied = -EFAULT;
63813@@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63814 if (!mm)
63815 return 0;
63816
63817+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63818+ if (file->f_version != current->exec_id) {
63819+ gr_log_badprocpid("environ");
63820+ return 0;
63821+ }
63822+#endif
63823+
63824 page = (char *)__get_free_page(GFP_TEMPORARY);
63825 if (!page)
63826 return -ENOMEM;
63827@@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63828 goto free;
63829 while (count > 0) {
63830 size_t this_len, max_len;
63831- int retval;
63832+ ssize_t retval;
63833
63834 if (src >= (mm->env_end - mm->env_start))
63835 break;
63836@@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63837 int error = -EACCES;
63838
63839 /* Are we allowed to snoop on the tasks file descriptors? */
63840- if (!proc_fd_access_allowed(inode))
63841+ if (!proc_fd_access_allowed(inode, 0))
63842 goto out;
63843
63844 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63845@@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63846 struct path path;
63847
63848 /* Are we allowed to snoop on the tasks file descriptors? */
63849- if (!proc_fd_access_allowed(inode))
63850- goto out;
63851+ /* logging this is needed for learning on chromium to work properly,
63852+ but we don't want to flood the logs from 'ps' which does a readlink
63853+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63854+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63855+ */
63856+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63857+ if (!proc_fd_access_allowed(inode,0))
63858+ goto out;
63859+ } else {
63860+ if (!proc_fd_access_allowed(inode,1))
63861+ goto out;
63862+ }
63863
63864 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63865 if (error)
63866@@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63867 rcu_read_lock();
63868 cred = __task_cred(task);
63869 inode->i_uid = cred->euid;
63870+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63871+ inode->i_gid = grsec_proc_gid;
63872+#else
63873 inode->i_gid = cred->egid;
63874+#endif
63875 rcu_read_unlock();
63876 }
63877 security_task_to_inode(task, inode);
63878@@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63879 return -ENOENT;
63880 }
63881 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63882+#ifdef CONFIG_GRKERNSEC_PROC_USER
63883+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63884+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63885+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63886+#endif
63887 task_dumpable(task)) {
63888 cred = __task_cred(task);
63889 stat->uid = cred->euid;
63890+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63891+ stat->gid = grsec_proc_gid;
63892+#else
63893 stat->gid = cred->egid;
63894+#endif
63895 }
63896 }
63897 rcu_read_unlock();
63898@@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63899
63900 if (task) {
63901 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63902+#ifdef CONFIG_GRKERNSEC_PROC_USER
63903+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63904+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63905+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63906+#endif
63907 task_dumpable(task)) {
63908 rcu_read_lock();
63909 cred = __task_cred(task);
63910 inode->i_uid = cred->euid;
63911+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63912+ inode->i_gid = grsec_proc_gid;
63913+#else
63914 inode->i_gid = cred->egid;
63915+#endif
63916 rcu_read_unlock();
63917 } else {
63918 inode->i_uid = GLOBAL_ROOT_UID;
63919@@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63920 if (!task)
63921 goto out_no_task;
63922
63923+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63924+ goto out;
63925+
63926 /*
63927 * Yes, it does not scale. And it should not. Don't add
63928 * new entries into /proc/<tgid>/ without very good reasons.
63929@@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63930 if (!task)
63931 return -ENOENT;
63932
63933+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63934+ goto out;
63935+
63936 if (!dir_emit_dots(file, ctx))
63937 goto out;
63938
63939@@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63940 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63941 #endif
63942 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63943-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63944+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63945 INF("syscall", S_IRUSR, proc_pid_syscall),
63946 #endif
63947 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63948@@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63949 #ifdef CONFIG_SECURITY
63950 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63951 #endif
63952-#ifdef CONFIG_KALLSYMS
63953+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63954 INF("wchan", S_IRUGO, proc_pid_wchan),
63955 #endif
63956-#ifdef CONFIG_STACKTRACE
63957+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63958 ONE("stack", S_IRUSR, proc_pid_stack),
63959 #endif
63960 #ifdef CONFIG_SCHEDSTATS
63961@@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63962 #ifdef CONFIG_HARDWALL
63963 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63964 #endif
63965+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63966+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63967+#endif
63968 #ifdef CONFIG_USER_NS
63969 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63970 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63971@@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
63972 if (!inode)
63973 goto out;
63974
63975+#ifdef CONFIG_GRKERNSEC_PROC_USER
63976+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63977+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63978+ inode->i_gid = grsec_proc_gid;
63979+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63980+#else
63981 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63982+#endif
63983 inode->i_op = &proc_tgid_base_inode_operations;
63984 inode->i_fop = &proc_tgid_base_operations;
63985 inode->i_flags|=S_IMMUTABLE;
63986@@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63987 if (!task)
63988 goto out;
63989
63990+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63991+ goto out_put_task;
63992+
63993 result = proc_pid_instantiate(dir, dentry, task, NULL);
63994+out_put_task:
63995 put_task_struct(task);
63996 out:
63997 return ERR_PTR(result);
63998@@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
63999 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
64000 #endif
64001 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
64002-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
64003+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
64004 INF("syscall", S_IRUSR, proc_pid_syscall),
64005 #endif
64006 INF("cmdline", S_IRUGO, proc_pid_cmdline),
64007@@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
64008 #ifdef CONFIG_SECURITY
64009 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
64010 #endif
64011-#ifdef CONFIG_KALLSYMS
64012+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64013 INF("wchan", S_IRUGO, proc_pid_wchan),
64014 #endif
64015-#ifdef CONFIG_STACKTRACE
64016+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64017 ONE("stack", S_IRUSR, proc_pid_stack),
64018 #endif
64019 #ifdef CONFIG_SCHEDSTATS
64020diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
64021index cbd82df..c0407d2 100644
64022--- a/fs/proc/cmdline.c
64023+++ b/fs/proc/cmdline.c
64024@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
64025
64026 static int __init proc_cmdline_init(void)
64027 {
64028+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64029+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
64030+#else
64031 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
64032+#endif
64033 return 0;
64034 }
64035 fs_initcall(proc_cmdline_init);
64036diff --git a/fs/proc/devices.c b/fs/proc/devices.c
64037index 50493ed..248166b 100644
64038--- a/fs/proc/devices.c
64039+++ b/fs/proc/devices.c
64040@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
64041
64042 static int __init proc_devices_init(void)
64043 {
64044+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64045+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
64046+#else
64047 proc_create("devices", 0, NULL, &proc_devinfo_operations);
64048+#endif
64049 return 0;
64050 }
64051 fs_initcall(proc_devices_init);
64052diff --git a/fs/proc/fd.c b/fs/proc/fd.c
64053index 0788d09..9cc1385 100644
64054--- a/fs/proc/fd.c
64055+++ b/fs/proc/fd.c
64056@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
64057 if (!task)
64058 return -ENOENT;
64059
64060- files = get_files_struct(task);
64061+ if (!gr_acl_handle_procpidmem(task))
64062+ files = get_files_struct(task);
64063 put_task_struct(task);
64064
64065 if (files) {
64066@@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
64067 */
64068 int proc_fd_permission(struct inode *inode, int mask)
64069 {
64070+ struct task_struct *task;
64071 int rv = generic_permission(inode, mask);
64072- if (rv == 0)
64073- return 0;
64074+
64075 if (task_tgid(current) == proc_pid(inode))
64076 rv = 0;
64077+
64078+ task = get_proc_task(inode);
64079+ if (task == NULL)
64080+ return rv;
64081+
64082+ if (gr_acl_handle_procpidmem(task))
64083+ rv = -EACCES;
64084+
64085+ put_task_struct(task);
64086+
64087 return rv;
64088 }
64089
64090diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64091index b7f268e..3bea6b7 100644
64092--- a/fs/proc/generic.c
64093+++ b/fs/proc/generic.c
64094@@ -23,6 +23,7 @@
64095 #include <linux/bitops.h>
64096 #include <linux/spinlock.h>
64097 #include <linux/completion.h>
64098+#include <linux/grsecurity.h>
64099 #include <asm/uaccess.h>
64100
64101 #include "internal.h"
64102@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64103 return proc_lookup_de(PDE(dir), dir, dentry);
64104 }
64105
64106+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64107+ unsigned int flags)
64108+{
64109+ if (gr_proc_is_restricted())
64110+ return ERR_PTR(-EACCES);
64111+
64112+ return proc_lookup_de(PDE(dir), dir, dentry);
64113+}
64114+
64115 /*
64116 * This returns non-zero if at EOF, so that the /proc
64117 * root directory can use this and check if it should
64118@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64119 return proc_readdir_de(PDE(inode), file, ctx);
64120 }
64121
64122+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64123+{
64124+ struct inode *inode = file_inode(file);
64125+
64126+ if (gr_proc_is_restricted())
64127+ return -EACCES;
64128+
64129+ return proc_readdir_de(PDE(inode), file, ctx);
64130+}
64131+
64132 /*
64133 * These are the generic /proc directory operations. They
64134 * use the in-memory "struct proc_dir_entry" tree to parse
64135@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64136 .iterate = proc_readdir,
64137 };
64138
64139+static const struct file_operations proc_dir_restricted_operations = {
64140+ .llseek = generic_file_llseek,
64141+ .read = generic_read_dir,
64142+ .iterate = proc_readdir_restrict,
64143+};
64144+
64145 /*
64146 * proc directories can do almost nothing..
64147 */
64148@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64149 .setattr = proc_notify_change,
64150 };
64151
64152+static const struct inode_operations proc_dir_restricted_inode_operations = {
64153+ .lookup = proc_lookup_restrict,
64154+ .getattr = proc_getattr,
64155+ .setattr = proc_notify_change,
64156+};
64157+
64158 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64159 {
64160 struct proc_dir_entry *tmp;
64161@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64162 return ret;
64163
64164 if (S_ISDIR(dp->mode)) {
64165- dp->proc_fops = &proc_dir_operations;
64166- dp->proc_iops = &proc_dir_inode_operations;
64167+ if (dp->restricted) {
64168+ dp->proc_fops = &proc_dir_restricted_operations;
64169+ dp->proc_iops = &proc_dir_restricted_inode_operations;
64170+ } else {
64171+ dp->proc_fops = &proc_dir_operations;
64172+ dp->proc_iops = &proc_dir_inode_operations;
64173+ }
64174 dir->nlink++;
64175 } else if (S_ISLNK(dp->mode)) {
64176 dp->proc_iops = &proc_link_inode_operations;
64177@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64178 }
64179 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64180
64181+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64182+ struct proc_dir_entry *parent, void *data)
64183+{
64184+ struct proc_dir_entry *ent;
64185+
64186+ if (mode == 0)
64187+ mode = S_IRUGO | S_IXUGO;
64188+
64189+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64190+ if (ent) {
64191+ ent->data = data;
64192+ ent->restricted = 1;
64193+ if (proc_register(parent, ent) < 0) {
64194+ kfree(ent);
64195+ ent = NULL;
64196+ }
64197+ }
64198+ return ent;
64199+}
64200+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64201+
64202 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64203 struct proc_dir_entry *parent)
64204 {
64205@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64206 }
64207 EXPORT_SYMBOL(proc_mkdir);
64208
64209+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64210+ struct proc_dir_entry *parent)
64211+{
64212+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
64213+}
64214+EXPORT_SYMBOL(proc_mkdir_restrict);
64215+
64216 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64217 struct proc_dir_entry *parent,
64218 const struct file_operations *proc_fops,
64219diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64220index 0adbc02..bee4d0b 100644
64221--- a/fs/proc/inode.c
64222+++ b/fs/proc/inode.c
64223@@ -23,11 +23,17 @@
64224 #include <linux/slab.h>
64225 #include <linux/mount.h>
64226 #include <linux/magic.h>
64227+#include <linux/grsecurity.h>
64228
64229 #include <asm/uaccess.h>
64230
64231 #include "internal.h"
64232
64233+#ifdef CONFIG_PROC_SYSCTL
64234+extern const struct inode_operations proc_sys_inode_operations;
64235+extern const struct inode_operations proc_sys_dir_operations;
64236+#endif
64237+
64238 static void proc_evict_inode(struct inode *inode)
64239 {
64240 struct proc_dir_entry *de;
64241@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64242 ns = PROC_I(inode)->ns.ns;
64243 if (ns_ops && ns)
64244 ns_ops->put(ns);
64245+
64246+#ifdef CONFIG_PROC_SYSCTL
64247+ if (inode->i_op == &proc_sys_inode_operations ||
64248+ inode->i_op == &proc_sys_dir_operations)
64249+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64250+#endif
64251+
64252 }
64253
64254 static struct kmem_cache * proc_inode_cachep;
64255@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64256 if (de->mode) {
64257 inode->i_mode = de->mode;
64258 inode->i_uid = de->uid;
64259+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64260+ inode->i_gid = grsec_proc_gid;
64261+#else
64262 inode->i_gid = de->gid;
64263+#endif
64264 }
64265 if (de->size)
64266 inode->i_size = de->size;
64267diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64268index 3ab6d14..b26174e 100644
64269--- a/fs/proc/internal.h
64270+++ b/fs/proc/internal.h
64271@@ -46,9 +46,10 @@ struct proc_dir_entry {
64272 struct completion *pde_unload_completion;
64273 struct list_head pde_openers; /* who did ->open, but not ->release */
64274 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64275+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64276 u8 namelen;
64277 char name[];
64278-};
64279+} __randomize_layout;
64280
64281 union proc_op {
64282 int (*proc_get_link)(struct dentry *, struct path *);
64283@@ -67,7 +68,7 @@ struct proc_inode {
64284 struct ctl_table *sysctl_entry;
64285 struct proc_ns ns;
64286 struct inode vfs_inode;
64287-};
64288+} __randomize_layout;
64289
64290 /*
64291 * General functions
64292@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64293 struct pid *, struct task_struct *);
64294 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64295 struct pid *, struct task_struct *);
64296+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64297+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64298+#endif
64299
64300 /*
64301 * base.c
64302@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64303 extern spinlock_t proc_subdir_lock;
64304
64305 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64306+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64307 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64308 struct dentry *);
64309 extern int proc_readdir(struct file *, struct dir_context *);
64310+extern int proc_readdir_restrict(struct file *, struct dir_context *);
64311 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64312
64313 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64314diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64315index a352d57..cb94a5c 100644
64316--- a/fs/proc/interrupts.c
64317+++ b/fs/proc/interrupts.c
64318@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64319
64320 static int __init proc_interrupts_init(void)
64321 {
64322+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64323+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64324+#else
64325 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64326+#endif
64327 return 0;
64328 }
64329 fs_initcall(proc_interrupts_init);
64330diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64331index 39e6ef3..2f9cb5e 100644
64332--- a/fs/proc/kcore.c
64333+++ b/fs/proc/kcore.c
64334@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64335 * the addresses in the elf_phdr on our list.
64336 */
64337 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64338- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64339+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64340+ if (tsz > buflen)
64341 tsz = buflen;
64342-
64343+
64344 while (buflen) {
64345 struct kcore_list *m;
64346
64347@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64348 kfree(elf_buf);
64349 } else {
64350 if (kern_addr_valid(start)) {
64351- unsigned long n;
64352+ char *elf_buf;
64353+ mm_segment_t oldfs;
64354
64355- n = copy_to_user(buffer, (char *)start, tsz);
64356- /*
64357- * We cannot distinguish between fault on source
64358- * and fault on destination. When this happens
64359- * we clear too and hope it will trigger the
64360- * EFAULT again.
64361- */
64362- if (n) {
64363- if (clear_user(buffer + tsz - n,
64364- n))
64365+ elf_buf = kmalloc(tsz, GFP_KERNEL);
64366+ if (!elf_buf)
64367+ return -ENOMEM;
64368+ oldfs = get_fs();
64369+ set_fs(KERNEL_DS);
64370+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64371+ set_fs(oldfs);
64372+ if (copy_to_user(buffer, elf_buf, tsz)) {
64373+ kfree(elf_buf);
64374 return -EFAULT;
64375+ }
64376 }
64377+ set_fs(oldfs);
64378+ kfree(elf_buf);
64379 } else {
64380 if (clear_user(buffer, tsz))
64381 return -EFAULT;
64382@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64383
64384 static int open_kcore(struct inode *inode, struct file *filp)
64385 {
64386+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64387+ return -EPERM;
64388+#endif
64389 if (!capable(CAP_SYS_RAWIO))
64390 return -EPERM;
64391 if (kcore_need_update)
64392diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64393index 7445af0..7c5113c 100644
64394--- a/fs/proc/meminfo.c
64395+++ b/fs/proc/meminfo.c
64396@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64397 vmi.used >> 10,
64398 vmi.largest_chunk >> 10
64399 #ifdef CONFIG_MEMORY_FAILURE
64400- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64401+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64402 #endif
64403 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64404 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64405diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64406index d4a3574..b421ce9 100644
64407--- a/fs/proc/nommu.c
64408+++ b/fs/proc/nommu.c
64409@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64410
64411 if (file) {
64412 seq_pad(m, ' ');
64413- seq_path(m, &file->f_path, "");
64414+ seq_path(m, &file->f_path, "\n\\");
64415 }
64416
64417 seq_putc(m, '\n');
64418diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64419index 4677bb7..dad3045 100644
64420--- a/fs/proc/proc_net.c
64421+++ b/fs/proc/proc_net.c
64422@@ -23,9 +23,27 @@
64423 #include <linux/nsproxy.h>
64424 #include <net/net_namespace.h>
64425 #include <linux/seq_file.h>
64426+#include <linux/grsecurity.h>
64427
64428 #include "internal.h"
64429
64430+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64431+static struct seq_operations *ipv6_seq_ops_addr;
64432+
64433+void register_ipv6_seq_ops_addr(struct seq_operations *addr)
64434+{
64435+ ipv6_seq_ops_addr = addr;
64436+}
64437+
64438+void unregister_ipv6_seq_ops_addr(void)
64439+{
64440+ ipv6_seq_ops_addr = NULL;
64441+}
64442+
64443+EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
64444+EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
64445+#endif
64446+
64447 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
64448 {
64449 return pde->parent->data;
64450@@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
64451 return maybe_get_net(PDE_NET(PDE(inode)));
64452 }
64453
64454+extern const struct seq_operations dev_seq_ops;
64455+
64456 int seq_open_net(struct inode *ino, struct file *f,
64457 const struct seq_operations *ops, int size)
64458 {
64459@@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
64460
64461 BUG_ON(size < sizeof(*p));
64462
64463+ /* only permit access to /proc/net/dev */
64464+ if (
64465+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64466+ ops != ipv6_seq_ops_addr &&
64467+#endif
64468+ ops != &dev_seq_ops && gr_proc_is_restricted())
64469+ return -EACCES;
64470+
64471 net = get_proc_net(ino);
64472 if (net == NULL)
64473 return -ENXIO;
64474@@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
64475 int err;
64476 struct net *net;
64477
64478+ if (gr_proc_is_restricted())
64479+ return -EACCES;
64480+
64481 err = -ENXIO;
64482 net = get_proc_net(inode);
64483 if (net == NULL)
64484diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64485index 7129046..6914844 100644
64486--- a/fs/proc/proc_sysctl.c
64487+++ b/fs/proc/proc_sysctl.c
64488@@ -11,13 +11,21 @@
64489 #include <linux/namei.h>
64490 #include <linux/mm.h>
64491 #include <linux/module.h>
64492+#include <linux/nsproxy.h>
64493+#ifdef CONFIG_GRKERNSEC
64494+#include <net/net_namespace.h>
64495+#endif
64496 #include "internal.h"
64497
64498+extern int gr_handle_chroot_sysctl(const int op);
64499+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64500+ const int op);
64501+
64502 static const struct dentry_operations proc_sys_dentry_operations;
64503 static const struct file_operations proc_sys_file_operations;
64504-static const struct inode_operations proc_sys_inode_operations;
64505+const struct inode_operations proc_sys_inode_operations;
64506 static const struct file_operations proc_sys_dir_file_operations;
64507-static const struct inode_operations proc_sys_dir_operations;
64508+const struct inode_operations proc_sys_dir_operations;
64509
64510 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64511 {
64512@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64513
64514 err = NULL;
64515 d_set_d_op(dentry, &proc_sys_dentry_operations);
64516+
64517+ gr_handle_proc_create(dentry, inode);
64518+
64519 d_add(dentry, inode);
64520
64521 out:
64522@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64523 struct inode *inode = file_inode(filp);
64524 struct ctl_table_header *head = grab_header(inode);
64525 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64526+ int op = write ? MAY_WRITE : MAY_READ;
64527 ssize_t error;
64528 size_t res;
64529
64530@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64531 * and won't be until we finish.
64532 */
64533 error = -EPERM;
64534- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64535+ if (sysctl_perm(head, table, op))
64536 goto out;
64537
64538 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64539@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64540 if (!table->proc_handler)
64541 goto out;
64542
64543+#ifdef CONFIG_GRKERNSEC
64544+ error = -EPERM;
64545+ if (gr_handle_chroot_sysctl(op))
64546+ goto out;
64547+ dget(filp->f_path.dentry);
64548+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64549+ dput(filp->f_path.dentry);
64550+ goto out;
64551+ }
64552+ dput(filp->f_path.dentry);
64553+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64554+ goto out;
64555+ if (write) {
64556+ if (current->nsproxy->net_ns != table->extra2) {
64557+ if (!capable(CAP_SYS_ADMIN))
64558+ goto out;
64559+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64560+ goto out;
64561+ }
64562+#endif
64563+
64564 /* careful: calling conventions are nasty here */
64565 res = count;
64566 error = table->proc_handler(table, write, buf, &res, ppos);
64567@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64568 return false;
64569 } else {
64570 d_set_d_op(child, &proc_sys_dentry_operations);
64571+
64572+ gr_handle_proc_create(child, inode);
64573+
64574 d_add(child, inode);
64575 }
64576 } else {
64577@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64578 if ((*pos)++ < ctx->pos)
64579 return true;
64580
64581+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64582+ return 0;
64583+
64584 if (unlikely(S_ISLNK(table->mode)))
64585 res = proc_sys_link_fill_cache(file, ctx, head, table);
64586 else
64587@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64588 if (IS_ERR(head))
64589 return PTR_ERR(head);
64590
64591+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64592+ return -ENOENT;
64593+
64594 generic_fillattr(inode, stat);
64595 if (table)
64596 stat->mode = (stat->mode & S_IFMT) | table->mode;
64597@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64598 .llseek = generic_file_llseek,
64599 };
64600
64601-static const struct inode_operations proc_sys_inode_operations = {
64602+const struct inode_operations proc_sys_inode_operations = {
64603 .permission = proc_sys_permission,
64604 .setattr = proc_sys_setattr,
64605 .getattr = proc_sys_getattr,
64606 };
64607
64608-static const struct inode_operations proc_sys_dir_operations = {
64609+const struct inode_operations proc_sys_dir_operations = {
64610 .lookup = proc_sys_lookup,
64611 .permission = proc_sys_permission,
64612 .setattr = proc_sys_setattr,
64613@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64614 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64615 const char *name, int namelen)
64616 {
64617- struct ctl_table *table;
64618+ ctl_table_no_const *table;
64619 struct ctl_dir *new;
64620 struct ctl_node *node;
64621 char *new_name;
64622@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64623 return NULL;
64624
64625 node = (struct ctl_node *)(new + 1);
64626- table = (struct ctl_table *)(node + 1);
64627+ table = (ctl_table_no_const *)(node + 1);
64628 new_name = (char *)(table + 2);
64629 memcpy(new_name, name, namelen);
64630 new_name[namelen] = '\0';
64631@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64632 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64633 struct ctl_table_root *link_root)
64634 {
64635- struct ctl_table *link_table, *entry, *link;
64636+ ctl_table_no_const *link_table, *link;
64637+ struct ctl_table *entry;
64638 struct ctl_table_header *links;
64639 struct ctl_node *node;
64640 char *link_name;
64641@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64642 return NULL;
64643
64644 node = (struct ctl_node *)(links + 1);
64645- link_table = (struct ctl_table *)(node + nr_entries);
64646+ link_table = (ctl_table_no_const *)(node + nr_entries);
64647 link_name = (char *)&link_table[nr_entries + 1];
64648
64649 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64650@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64651 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64652 struct ctl_table *table)
64653 {
64654- struct ctl_table *ctl_table_arg = NULL;
64655- struct ctl_table *entry, *files;
64656+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64657+ struct ctl_table *entry;
64658 int nr_files = 0;
64659 int nr_dirs = 0;
64660 int err = -ENOMEM;
64661@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64662 nr_files++;
64663 }
64664
64665- files = table;
64666 /* If there are mixed files and directories we need a new table */
64667 if (nr_dirs && nr_files) {
64668- struct ctl_table *new;
64669+ ctl_table_no_const *new;
64670 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64671 GFP_KERNEL);
64672 if (!files)
64673@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64674 /* Register everything except a directory full of subdirectories */
64675 if (nr_files || !nr_dirs) {
64676 struct ctl_table_header *header;
64677- header = __register_sysctl_table(set, path, files);
64678+ header = __register_sysctl_table(set, path, files ? files : table);
64679 if (!header) {
64680 kfree(ctl_table_arg);
64681 goto out;
64682diff --git a/fs/proc/root.c b/fs/proc/root.c
64683index 5dbadec..473af2f 100644
64684--- a/fs/proc/root.c
64685+++ b/fs/proc/root.c
64686@@ -185,7 +185,15 @@ void __init proc_root_init(void)
64687 proc_mkdir("openprom", NULL);
64688 #endif
64689 proc_tty_init();
64690+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64691+#ifdef CONFIG_GRKERNSEC_PROC_USER
64692+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64693+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64694+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64695+#endif
64696+#else
64697 proc_mkdir("bus", NULL);
64698+#endif
64699 proc_sys_init();
64700 }
64701
64702diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64703index 9d231e9..2e1b51a 100644
64704--- a/fs/proc/stat.c
64705+++ b/fs/proc/stat.c
64706@@ -11,6 +11,7 @@
64707 #include <linux/irqnr.h>
64708 #include <linux/cputime.h>
64709 #include <linux/tick.h>
64710+#include <linux/grsecurity.h>
64711
64712 #ifndef arch_irq_stat_cpu
64713 #define arch_irq_stat_cpu(cpu) 0
64714@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64715 u64 sum_softirq = 0;
64716 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64717 struct timespec boottime;
64718+ int unrestricted = 1;
64719+
64720+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64721+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64722+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64723+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64724+ && !in_group_p(grsec_proc_gid)
64725+#endif
64726+ )
64727+ unrestricted = 0;
64728+#endif
64729+#endif
64730
64731 user = nice = system = idle = iowait =
64732 irq = softirq = steal = 0;
64733@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64734 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64735 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64736 idle += get_idle_time(i);
64737- iowait += get_iowait_time(i);
64738- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64739- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64740- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64741- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64742- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64743- sum += kstat_cpu_irqs_sum(i);
64744- sum += arch_irq_stat_cpu(i);
64745+ if (unrestricted) {
64746+ iowait += get_iowait_time(i);
64747+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64748+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64749+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64750+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64751+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64752+ sum += kstat_cpu_irqs_sum(i);
64753+ sum += arch_irq_stat_cpu(i);
64754+ for (j = 0; j < NR_SOFTIRQS; j++) {
64755+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64756
64757- for (j = 0; j < NR_SOFTIRQS; j++) {
64758- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64759-
64760- per_softirq_sums[j] += softirq_stat;
64761- sum_softirq += softirq_stat;
64762+ per_softirq_sums[j] += softirq_stat;
64763+ sum_softirq += softirq_stat;
64764+ }
64765 }
64766 }
64767- sum += arch_irq_stat();
64768+ if (unrestricted)
64769+ sum += arch_irq_stat();
64770
64771 seq_puts(p, "cpu ");
64772 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64773@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64774 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64775 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64776 idle = get_idle_time(i);
64777- iowait = get_iowait_time(i);
64778- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64779- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64780- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64781- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64782- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64783+ if (unrestricted) {
64784+ iowait = get_iowait_time(i);
64785+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64786+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64787+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64788+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64789+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64790+ }
64791 seq_printf(p, "cpu%d", i);
64792 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64793 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64794@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64795
64796 /* sum again ? it could be updated? */
64797 for_each_irq_nr(j)
64798- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64799+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64800
64801 seq_printf(p,
64802 "\nctxt %llu\n"
64803@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64804 "processes %lu\n"
64805 "procs_running %lu\n"
64806 "procs_blocked %lu\n",
64807- nr_context_switches(),
64808+ unrestricted ? nr_context_switches() : 0ULL,
64809 (unsigned long)jif,
64810- total_forks,
64811- nr_running(),
64812- nr_iowait());
64813+ unrestricted ? total_forks : 0UL,
64814+ unrestricted ? nr_running() : 0UL,
64815+ unrestricted ? nr_iowait() : 0UL);
64816
64817 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64818
64819diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64820index c4b2646..84f0d7b 100644
64821--- a/fs/proc/task_mmu.c
64822+++ b/fs/proc/task_mmu.c
64823@@ -13,12 +13,19 @@
64824 #include <linux/swap.h>
64825 #include <linux/swapops.h>
64826 #include <linux/mmu_notifier.h>
64827+#include <linux/grsecurity.h>
64828
64829 #include <asm/elf.h>
64830 #include <asm/uaccess.h>
64831 #include <asm/tlbflush.h>
64832 #include "internal.h"
64833
64834+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64835+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64836+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64837+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64838+#endif
64839+
64840 void task_mem(struct seq_file *m, struct mm_struct *mm)
64841 {
64842 unsigned long data, text, lib, swap;
64843@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64844 "VmExe:\t%8lu kB\n"
64845 "VmLib:\t%8lu kB\n"
64846 "VmPTE:\t%8lu kB\n"
64847- "VmSwap:\t%8lu kB\n",
64848- hiwater_vm << (PAGE_SHIFT-10),
64849+ "VmSwap:\t%8lu kB\n"
64850+
64851+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64852+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64853+#endif
64854+
64855+ ,hiwater_vm << (PAGE_SHIFT-10),
64856 total_vm << (PAGE_SHIFT-10),
64857 mm->locked_vm << (PAGE_SHIFT-10),
64858 mm->pinned_vm << (PAGE_SHIFT-10),
64859@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64860 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64861 (PTRS_PER_PTE * sizeof(pte_t) *
64862 atomic_long_read(&mm->nr_ptes)) >> 10,
64863- swap << (PAGE_SHIFT-10));
64864+ swap << (PAGE_SHIFT-10)
64865+
64866+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64867+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64868+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64869+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64870+#else
64871+ , mm->context.user_cs_base
64872+ , mm->context.user_cs_limit
64873+#endif
64874+#endif
64875+
64876+ );
64877 }
64878
64879 unsigned long task_vsize(struct mm_struct *mm)
64880@@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64881 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64882 }
64883
64884- /* We don't show the stack guard page in /proc/maps */
64885+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64886+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64887+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64888+#else
64889 start = vma->vm_start;
64890- if (stack_guard_page_start(vma, start))
64891- start += PAGE_SIZE;
64892 end = vma->vm_end;
64893- if (stack_guard_page_end(vma, end))
64894- end -= PAGE_SIZE;
64895+#endif
64896
64897 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64898 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64899@@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64900 flags & VM_WRITE ? 'w' : '-',
64901 flags & VM_EXEC ? 'x' : '-',
64902 flags & VM_MAYSHARE ? 's' : 'p',
64903+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64904+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64905+#else
64906 pgoff,
64907+#endif
64908 MAJOR(dev), MINOR(dev), ino);
64909
64910 /*
64911@@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64912 */
64913 if (file) {
64914 seq_pad(m, ' ');
64915- seq_path(m, &file->f_path, "\n");
64916+ seq_path(m, &file->f_path, "\n\\");
64917 goto done;
64918 }
64919
64920@@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64921 * Thread stack in /proc/PID/task/TID/maps or
64922 * the main process stack.
64923 */
64924- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64925- vma->vm_end >= mm->start_stack)) {
64926+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64927+ (vma->vm_start <= mm->start_stack &&
64928+ vma->vm_end >= mm->start_stack)) {
64929 name = "[stack]";
64930 } else {
64931 /* Thread stack in /proc/PID/maps */
64932@@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64933 struct proc_maps_private *priv = m->private;
64934 struct task_struct *task = priv->task;
64935
64936+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64937+ if (current->exec_id != m->exec_id) {
64938+ gr_log_badprocpid("maps");
64939+ return 0;
64940+ }
64941+#endif
64942+
64943 show_map_vma(m, vma, is_pid);
64944
64945 if (m->count < m->size) /* vma is copied successfully */
64946@@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64947 .private = &mss,
64948 };
64949
64950+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64951+ if (current->exec_id != m->exec_id) {
64952+ gr_log_badprocpid("smaps");
64953+ return 0;
64954+ }
64955+#endif
64956 memset(&mss, 0, sizeof mss);
64957- mss.vma = vma;
64958- /* mmap_sem is held in m_start */
64959- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64960- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64961-
64962+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64963+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64964+#endif
64965+ mss.vma = vma;
64966+ /* mmap_sem is held in m_start */
64967+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64968+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64969+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64970+ }
64971+#endif
64972 show_map_vma(m, vma, is_pid);
64973
64974 seq_printf(m,
64975@@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64976 "KernelPageSize: %8lu kB\n"
64977 "MMUPageSize: %8lu kB\n"
64978 "Locked: %8lu kB\n",
64979+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64980+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64981+#else
64982 (vma->vm_end - vma->vm_start) >> 10,
64983+#endif
64984 mss.resident >> 10,
64985 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64986 mss.shared_clean >> 10,
64987@@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64988 char buffer[64];
64989 int nid;
64990
64991+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64992+ if (current->exec_id != m->exec_id) {
64993+ gr_log_badprocpid("numa_maps");
64994+ return 0;
64995+ }
64996+#endif
64997+
64998 if (!mm)
64999 return 0;
65000
65001@@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
65002 mpol_to_str(buffer, sizeof(buffer), pol);
65003 mpol_cond_put(pol);
65004
65005+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65006+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
65007+#else
65008 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
65009+#endif
65010
65011 if (file) {
65012 seq_printf(m, " file=");
65013- seq_path(m, &file->f_path, "\n\t= ");
65014+ seq_path(m, &file->f_path, "\n\t\\= ");
65015 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
65016 seq_printf(m, " heap");
65017 } else {
65018diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
65019index 678455d..ebd3245 100644
65020--- a/fs/proc/task_nommu.c
65021+++ b/fs/proc/task_nommu.c
65022@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
65023 else
65024 bytes += kobjsize(mm);
65025
65026- if (current->fs && current->fs->users > 1)
65027+ if (current->fs && atomic_read(&current->fs->users) > 1)
65028 sbytes += kobjsize(current->fs);
65029 else
65030 bytes += kobjsize(current->fs);
65031@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
65032
65033 if (file) {
65034 seq_pad(m, ' ');
65035- seq_path(m, &file->f_path, "");
65036+ seq_path(m, &file->f_path, "\n\\");
65037 } else if (mm) {
65038 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
65039
65040diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
65041index 6a8e785..41f2a6c 100644
65042--- a/fs/proc/vmcore.c
65043+++ b/fs/proc/vmcore.c
65044@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
65045 nr_bytes = count;
65046
65047 /* If pfn is not ram, return zeros for sparse dump files */
65048- if (pfn_is_ram(pfn) == 0)
65049- memset(buf, 0, nr_bytes);
65050- else {
65051+ if (pfn_is_ram(pfn) == 0) {
65052+ if (userbuf) {
65053+ if (clear_user((char __force_user *)buf, nr_bytes))
65054+ return -EFAULT;
65055+ } else
65056+ memset(buf, 0, nr_bytes);
65057+ } else {
65058 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
65059 offset, userbuf);
65060 if (tmp < 0)
65061@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
65062 static int copy_to(void *target, void *src, size_t size, int userbuf)
65063 {
65064 if (userbuf) {
65065- if (copy_to_user((char __user *) target, src, size))
65066+ if (copy_to_user((char __force_user *) target, src, size))
65067 return -EFAULT;
65068 } else {
65069 memcpy(target, src, size);
65070@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65071 if (*fpos < m->offset + m->size) {
65072 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
65073 start = m->paddr + *fpos - m->offset;
65074- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
65075+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
65076 if (tmp < 0)
65077 return tmp;
65078 buflen -= tsz;
65079@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65080 static ssize_t read_vmcore(struct file *file, char __user *buffer,
65081 size_t buflen, loff_t *fpos)
65082 {
65083- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
65084+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
65085 }
65086
65087 /*
65088diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
65089index b00fcc9..e0c6381 100644
65090--- a/fs/qnx6/qnx6.h
65091+++ b/fs/qnx6/qnx6.h
65092@@ -74,7 +74,7 @@ enum {
65093 BYTESEX_BE,
65094 };
65095
65096-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65097+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65098 {
65099 if (sbi->s_bytesex == BYTESEX_LE)
65100 return le64_to_cpu((__force __le64)n);
65101@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65102 return (__force __fs64)cpu_to_be64(n);
65103 }
65104
65105-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65106+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65107 {
65108 if (sbi->s_bytesex == BYTESEX_LE)
65109 return le32_to_cpu((__force __le32)n);
65110diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65111index 72d2917..c917c12 100644
65112--- a/fs/quota/netlink.c
65113+++ b/fs/quota/netlink.c
65114@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65115 void quota_send_warning(struct kqid qid, dev_t dev,
65116 const char warntype)
65117 {
65118- static atomic_t seq;
65119+ static atomic_unchecked_t seq;
65120 struct sk_buff *skb;
65121 void *msg_head;
65122 int ret;
65123@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65124 "VFS: Not enough memory to send quota warning.\n");
65125 return;
65126 }
65127- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65128+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65129 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65130 if (!msg_head) {
65131 printk(KERN_ERR
65132diff --git a/fs/read_write.c b/fs/read_write.c
65133index 31c6efa..a068805 100644
65134--- a/fs/read_write.c
65135+++ b/fs/read_write.c
65136@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65137
65138 old_fs = get_fs();
65139 set_fs(get_ds());
65140- p = (__force const char __user *)buf;
65141+ p = (const char __force_user *)buf;
65142 if (count > MAX_RW_COUNT)
65143 count = MAX_RW_COUNT;
65144 if (file->f_op->write)
65145diff --git a/fs/readdir.c b/fs/readdir.c
65146index 5b53d99..a6c3049 100644
65147--- a/fs/readdir.c
65148+++ b/fs/readdir.c
65149@@ -17,6 +17,7 @@
65150 #include <linux/security.h>
65151 #include <linux/syscalls.h>
65152 #include <linux/unistd.h>
65153+#include <linux/namei.h>
65154
65155 #include <asm/uaccess.h>
65156
65157@@ -69,6 +70,7 @@ struct old_linux_dirent {
65158 struct readdir_callback {
65159 struct dir_context ctx;
65160 struct old_linux_dirent __user * dirent;
65161+ struct file * file;
65162 int result;
65163 };
65164
65165@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65166 buf->result = -EOVERFLOW;
65167 return -EOVERFLOW;
65168 }
65169+
65170+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65171+ return 0;
65172+
65173 buf->result++;
65174 dirent = buf->dirent;
65175 if (!access_ok(VERIFY_WRITE, dirent,
65176@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65177 if (!f.file)
65178 return -EBADF;
65179
65180+ buf.file = f.file;
65181 error = iterate_dir(f.file, &buf.ctx);
65182 if (buf.result)
65183 error = buf.result;
65184@@ -142,6 +149,7 @@ struct getdents_callback {
65185 struct dir_context ctx;
65186 struct linux_dirent __user * current_dir;
65187 struct linux_dirent __user * previous;
65188+ struct file * file;
65189 int count;
65190 int error;
65191 };
65192@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65193 buf->error = -EOVERFLOW;
65194 return -EOVERFLOW;
65195 }
65196+
65197+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65198+ return 0;
65199+
65200 dirent = buf->previous;
65201 if (dirent) {
65202 if (__put_user(offset, &dirent->d_off))
65203@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65204 if (!f.file)
65205 return -EBADF;
65206
65207+ buf.file = f.file;
65208 error = iterate_dir(f.file, &buf.ctx);
65209 if (error >= 0)
65210 error = buf.error;
65211@@ -226,6 +239,7 @@ struct getdents_callback64 {
65212 struct dir_context ctx;
65213 struct linux_dirent64 __user * current_dir;
65214 struct linux_dirent64 __user * previous;
65215+ struct file *file;
65216 int count;
65217 int error;
65218 };
65219@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65220 buf->error = -EINVAL; /* only used if we fail.. */
65221 if (reclen > buf->count)
65222 return -EINVAL;
65223+
65224+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65225+ return 0;
65226+
65227 dirent = buf->previous;
65228 if (dirent) {
65229 if (__put_user(offset, &dirent->d_off))
65230@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65231 if (!f.file)
65232 return -EBADF;
65233
65234+ buf.file = f.file;
65235 error = iterate_dir(f.file, &buf.ctx);
65236 if (error >= 0)
65237 error = buf.error;
65238diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65239index 9a3c68c..767933e 100644
65240--- a/fs/reiserfs/do_balan.c
65241+++ b/fs/reiserfs/do_balan.c
65242@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65243 return;
65244 }
65245
65246- atomic_inc(&(fs_generation(tb->tb_sb)));
65247+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65248 do_balance_starts(tb);
65249
65250 /* balance leaf returns 0 except if combining L R and S into
65251diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65252index ee382ef..f4eb6eb5 100644
65253--- a/fs/reiserfs/item_ops.c
65254+++ b/fs/reiserfs/item_ops.c
65255@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65256 }
65257
65258 static struct item_operations errcatch_ops = {
65259- errcatch_bytes_number,
65260- errcatch_decrement_key,
65261- errcatch_is_left_mergeable,
65262- errcatch_print_item,
65263- errcatch_check_item,
65264+ .bytes_number = errcatch_bytes_number,
65265+ .decrement_key = errcatch_decrement_key,
65266+ .is_left_mergeable = errcatch_is_left_mergeable,
65267+ .print_item = errcatch_print_item,
65268+ .check_item = errcatch_check_item,
65269
65270- errcatch_create_vi,
65271- errcatch_check_left,
65272- errcatch_check_right,
65273- errcatch_part_size,
65274- errcatch_unit_num,
65275- errcatch_print_vi
65276+ .create_vi = errcatch_create_vi,
65277+ .check_left = errcatch_check_left,
65278+ .check_right = errcatch_check_right,
65279+ .part_size = errcatch_part_size,
65280+ .unit_num = errcatch_unit_num,
65281+ .print_vi = errcatch_print_vi
65282 };
65283
65284 //////////////////////////////////////////////////////////////////////////////
65285diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65286index 02b0b7d..c85018b 100644
65287--- a/fs/reiserfs/procfs.c
65288+++ b/fs/reiserfs/procfs.c
65289@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65290 "SMALL_TAILS " : "NO_TAILS ",
65291 replay_only(sb) ? "REPLAY_ONLY " : "",
65292 convert_reiserfs(sb) ? "CONV " : "",
65293- atomic_read(&r->s_generation_counter),
65294+ atomic_read_unchecked(&r->s_generation_counter),
65295 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65296 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65297 SF(s_good_search_by_key_reada), SF(s_bmaps),
65298diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65299index 83d4eac..04e39a7 100644
65300--- a/fs/reiserfs/reiserfs.h
65301+++ b/fs/reiserfs/reiserfs.h
65302@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65303 /* Comment? -Hans */
65304 wait_queue_head_t s_wait;
65305 /* To be obsoleted soon by per buffer seals.. -Hans */
65306- atomic_t s_generation_counter; // increased by one every time the
65307+ atomic_unchecked_t s_generation_counter; // increased by one every time the
65308 // tree gets re-balanced
65309 unsigned long s_properties; /* File system properties. Currently holds
65310 on-disk FS format */
65311@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65312 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65313
65314 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65315-#define get_generation(s) atomic_read (&fs_generation(s))
65316+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65317 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65318 #define __fs_changed(gen,s) (gen != get_generation (s))
65319 #define fs_changed(gen,s) \
65320diff --git a/fs/select.c b/fs/select.c
65321index 467bb1c..cf9d65a 100644
65322--- a/fs/select.c
65323+++ b/fs/select.c
65324@@ -20,6 +20,7 @@
65325 #include <linux/export.h>
65326 #include <linux/slab.h>
65327 #include <linux/poll.h>
65328+#include <linux/security.h>
65329 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65330 #include <linux/file.h>
65331 #include <linux/fdtable.h>
65332@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65333 struct poll_list *walk = head;
65334 unsigned long todo = nfds;
65335
65336+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65337 if (nfds > rlimit(RLIMIT_NOFILE))
65338 return -EINVAL;
65339
65340diff --git a/fs/seq_file.c b/fs/seq_file.c
65341index 1d641bb..c2f4743 100644
65342--- a/fs/seq_file.c
65343+++ b/fs/seq_file.c
65344@@ -10,6 +10,8 @@
65345 #include <linux/seq_file.h>
65346 #include <linux/slab.h>
65347 #include <linux/cred.h>
65348+#include <linux/sched.h>
65349+#include <linux/grsecurity.h>
65350
65351 #include <asm/uaccess.h>
65352 #include <asm/page.h>
65353@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65354 #ifdef CONFIG_USER_NS
65355 p->user_ns = file->f_cred->user_ns;
65356 #endif
65357+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65358+ p->exec_id = current->exec_id;
65359+#endif
65360
65361 /*
65362 * Wrappers around seq_open(e.g. swaps_open) need to be
65363@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65364 }
65365 EXPORT_SYMBOL(seq_open);
65366
65367+
65368+int seq_open_restrict(struct file *file, const struct seq_operations *op)
65369+{
65370+ if (gr_proc_is_restricted())
65371+ return -EACCES;
65372+
65373+ return seq_open(file, op);
65374+}
65375+EXPORT_SYMBOL(seq_open_restrict);
65376+
65377 static int traverse(struct seq_file *m, loff_t offset)
65378 {
65379 loff_t pos = 0, index;
65380@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65381 return 0;
65382 }
65383 if (!m->buf) {
65384- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65385+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65386 if (!m->buf)
65387 return -ENOMEM;
65388 }
65389@@ -137,7 +152,7 @@ Eoverflow:
65390 m->op->stop(m, p);
65391 kfree(m->buf);
65392 m->count = 0;
65393- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65394+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65395 return !m->buf ? -ENOMEM : -EAGAIN;
65396 }
65397
65398@@ -153,7 +168,7 @@ Eoverflow:
65399 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65400 {
65401 struct seq_file *m = file->private_data;
65402- size_t copied = 0;
65403+ ssize_t copied = 0;
65404 loff_t pos;
65405 size_t n;
65406 void *p;
65407@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65408
65409 /* grab buffer if we didn't have one */
65410 if (!m->buf) {
65411- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65412+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65413 if (!m->buf)
65414 goto Enomem;
65415 }
65416@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65417 m->op->stop(m, p);
65418 kfree(m->buf);
65419 m->count = 0;
65420- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65421+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65422 if (!m->buf)
65423 goto Enomem;
65424 m->version = 0;
65425@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65426 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65427 void *data)
65428 {
65429- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65430+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65431 int res = -ENOMEM;
65432
65433 if (op) {
65434@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65435 }
65436 EXPORT_SYMBOL(single_open_size);
65437
65438+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65439+ void *data)
65440+{
65441+ if (gr_proc_is_restricted())
65442+ return -EACCES;
65443+
65444+ return single_open(file, show, data);
65445+}
65446+EXPORT_SYMBOL(single_open_restrict);
65447+
65448+
65449 int single_release(struct inode *inode, struct file *file)
65450 {
65451 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65452diff --git a/fs/splice.c b/fs/splice.c
65453index e246954..bd4f5b5 100644
65454--- a/fs/splice.c
65455+++ b/fs/splice.c
65456@@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65457 pipe_lock(pipe);
65458
65459 for (;;) {
65460- if (!pipe->readers) {
65461+ if (!atomic_read(&pipe->readers)) {
65462 send_sig(SIGPIPE, current, 0);
65463 if (!ret)
65464 ret = -EPIPE;
65465@@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65466 page_nr++;
65467 ret += buf->len;
65468
65469- if (pipe->files)
65470+ if (atomic_read(&pipe->files))
65471 do_wakeup = 1;
65472
65473 if (!--spd->nr_pages)
65474@@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65475 do_wakeup = 0;
65476 }
65477
65478- pipe->waiting_writers++;
65479+ atomic_inc(&pipe->waiting_writers);
65480 pipe_wait(pipe);
65481- pipe->waiting_writers--;
65482+ atomic_dec(&pipe->waiting_writers);
65483 }
65484
65485 pipe_unlock(pipe);
65486@@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65487 old_fs = get_fs();
65488 set_fs(get_ds());
65489 /* The cast to a user pointer is valid due to the set_fs() */
65490- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65491+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65492 set_fs(old_fs);
65493
65494 return res;
65495@@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65496 old_fs = get_fs();
65497 set_fs(get_ds());
65498 /* The cast to a user pointer is valid due to the set_fs() */
65499- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65500+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65501 set_fs(old_fs);
65502
65503 return res;
65504@@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65505 goto err;
65506
65507 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65508- vec[i].iov_base = (void __user *) page_address(page);
65509+ vec[i].iov_base = (void __force_user *) page_address(page);
65510 vec[i].iov_len = this_len;
65511 spd.pages[i] = page;
65512 spd.nr_pages++;
65513@@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65514 ops->release(pipe, buf);
65515 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65516 pipe->nrbufs--;
65517- if (pipe->files)
65518+ if (atomic_read(&pipe->files))
65519 sd->need_wakeup = true;
65520 }
65521
65522@@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65523 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65524 {
65525 while (!pipe->nrbufs) {
65526- if (!pipe->writers)
65527+ if (!atomic_read(&pipe->writers))
65528 return 0;
65529
65530- if (!pipe->waiting_writers && sd->num_spliced)
65531+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65532 return 0;
65533
65534 if (sd->flags & SPLICE_F_NONBLOCK)
65535@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65536 * out of the pipe right after the splice_to_pipe(). So set
65537 * PIPE_READERS appropriately.
65538 */
65539- pipe->readers = 1;
65540+ atomic_set(&pipe->readers, 1);
65541
65542 current->splice_pipe = pipe;
65543 }
65544@@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65545
65546 partial[buffers].offset = off;
65547 partial[buffers].len = plen;
65548+ partial[buffers].private = 0;
65549
65550 off = 0;
65551 len -= plen;
65552@@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65553 ret = -ERESTARTSYS;
65554 break;
65555 }
65556- if (!pipe->writers)
65557+ if (!atomic_read(&pipe->writers))
65558 break;
65559- if (!pipe->waiting_writers) {
65560+ if (!atomic_read(&pipe->waiting_writers)) {
65561 if (flags & SPLICE_F_NONBLOCK) {
65562 ret = -EAGAIN;
65563 break;
65564@@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65565 pipe_lock(pipe);
65566
65567 while (pipe->nrbufs >= pipe->buffers) {
65568- if (!pipe->readers) {
65569+ if (!atomic_read(&pipe->readers)) {
65570 send_sig(SIGPIPE, current, 0);
65571 ret = -EPIPE;
65572 break;
65573@@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65574 ret = -ERESTARTSYS;
65575 break;
65576 }
65577- pipe->waiting_writers++;
65578+ atomic_inc(&pipe->waiting_writers);
65579 pipe_wait(pipe);
65580- pipe->waiting_writers--;
65581+ atomic_dec(&pipe->waiting_writers);
65582 }
65583
65584 pipe_unlock(pipe);
65585@@ -1806,14 +1807,14 @@ retry:
65586 pipe_double_lock(ipipe, opipe);
65587
65588 do {
65589- if (!opipe->readers) {
65590+ if (!atomic_read(&opipe->readers)) {
65591 send_sig(SIGPIPE, current, 0);
65592 if (!ret)
65593 ret = -EPIPE;
65594 break;
65595 }
65596
65597- if (!ipipe->nrbufs && !ipipe->writers)
65598+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65599 break;
65600
65601 /*
65602@@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65603 pipe_double_lock(ipipe, opipe);
65604
65605 do {
65606- if (!opipe->readers) {
65607+ if (!atomic_read(&opipe->readers)) {
65608 send_sig(SIGPIPE, current, 0);
65609 if (!ret)
65610 ret = -EPIPE;
65611@@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65612 * return EAGAIN if we have the potential of some data in the
65613 * future, otherwise just return 0
65614 */
65615- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65616+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65617 ret = -EAGAIN;
65618
65619 pipe_unlock(ipipe);
65620diff --git a/fs/stat.c b/fs/stat.c
65621index ae0c3ce..9ee641c 100644
65622--- a/fs/stat.c
65623+++ b/fs/stat.c
65624@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65625 stat->gid = inode->i_gid;
65626 stat->rdev = inode->i_rdev;
65627 stat->size = i_size_read(inode);
65628- stat->atime = inode->i_atime;
65629- stat->mtime = inode->i_mtime;
65630+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65631+ stat->atime = inode->i_ctime;
65632+ stat->mtime = inode->i_ctime;
65633+ } else {
65634+ stat->atime = inode->i_atime;
65635+ stat->mtime = inode->i_mtime;
65636+ }
65637 stat->ctime = inode->i_ctime;
65638 stat->blksize = (1 << inode->i_blkbits);
65639 stat->blocks = inode->i_blocks;
65640@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65641 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65642 {
65643 struct inode *inode = path->dentry->d_inode;
65644+ int retval;
65645
65646- if (inode->i_op->getattr)
65647- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65648+ if (inode->i_op->getattr) {
65649+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65650+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65651+ stat->atime = stat->ctime;
65652+ stat->mtime = stat->ctime;
65653+ }
65654+ return retval;
65655+ }
65656
65657 generic_fillattr(inode, stat);
65658 return 0;
65659diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65660index 0b45ff4..847de5b 100644
65661--- a/fs/sysfs/dir.c
65662+++ b/fs/sysfs/dir.c
65663@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65664 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65665 {
65666 struct kernfs_node *parent, *kn;
65667+ const char *name;
65668+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65669+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65670+ const char *parent_name;
65671+#endif
65672
65673 BUG_ON(!kobj);
65674
65675+ name = kobject_name(kobj);
65676+
65677 if (kobj->parent)
65678 parent = kobj->parent->sd;
65679 else
65680@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65681 if (!parent)
65682 return -ENOENT;
65683
65684- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65685- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65686+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65687+ parent_name = parent->name;
65688+ mode = S_IRWXU;
65689+
65690+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65691+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65692+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65693+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65694+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65695+#endif
65696+
65697+ kn = kernfs_create_dir_ns(parent, name,
65698+ mode, kobj, ns);
65699 if (IS_ERR(kn)) {
65700 if (PTR_ERR(kn) == -EEXIST)
65701- sysfs_warn_dup(parent, kobject_name(kobj));
65702+ sysfs_warn_dup(parent, name);
65703 return PTR_ERR(kn);
65704 }
65705
65706diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65707index 69d4889..a810bd4 100644
65708--- a/fs/sysv/sysv.h
65709+++ b/fs/sysv/sysv.h
65710@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65711 #endif
65712 }
65713
65714-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65715+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65716 {
65717 if (sbi->s_bytesex == BYTESEX_PDP)
65718 return PDP_swab((__force __u32)n);
65719diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65720index e18b988..f1d4ad0f 100644
65721--- a/fs/ubifs/io.c
65722+++ b/fs/ubifs/io.c
65723@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65724 return err;
65725 }
65726
65727-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65728+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65729 {
65730 int err;
65731
65732diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65733index c175b4d..8f36a16 100644
65734--- a/fs/udf/misc.c
65735+++ b/fs/udf/misc.c
65736@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65737
65738 u8 udf_tag_checksum(const struct tag *t)
65739 {
65740- u8 *data = (u8 *)t;
65741+ const u8 *data = (const u8 *)t;
65742 u8 checksum = 0;
65743 int i;
65744 for (i = 0; i < sizeof(struct tag); ++i)
65745diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65746index 8d974c4..b82f6ec 100644
65747--- a/fs/ufs/swab.h
65748+++ b/fs/ufs/swab.h
65749@@ -22,7 +22,7 @@ enum {
65750 BYTESEX_BE
65751 };
65752
65753-static inline u64
65754+static inline u64 __intentional_overflow(-1)
65755 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65756 {
65757 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65758@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65759 return (__force __fs64)cpu_to_be64(n);
65760 }
65761
65762-static inline u32
65763+static inline u32 __intentional_overflow(-1)
65764 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65765 {
65766 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65767diff --git a/fs/utimes.c b/fs/utimes.c
65768index aa138d6..5f3a811 100644
65769--- a/fs/utimes.c
65770+++ b/fs/utimes.c
65771@@ -1,6 +1,7 @@
65772 #include <linux/compiler.h>
65773 #include <linux/file.h>
65774 #include <linux/fs.h>
65775+#include <linux/security.h>
65776 #include <linux/linkage.h>
65777 #include <linux/mount.h>
65778 #include <linux/namei.h>
65779@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65780 }
65781 }
65782 retry_deleg:
65783+
65784+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65785+ error = -EACCES;
65786+ goto mnt_drop_write_and_out;
65787+ }
65788+
65789 mutex_lock(&inode->i_mutex);
65790 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65791 mutex_unlock(&inode->i_mutex);
65792diff --git a/fs/xattr.c b/fs/xattr.c
65793index 3377dff..f394815 100644
65794--- a/fs/xattr.c
65795+++ b/fs/xattr.c
65796@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65797 return rc;
65798 }
65799
65800+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65801+ssize_t
65802+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65803+{
65804+ struct inode *inode = dentry->d_inode;
65805+ ssize_t error;
65806+
65807+ error = inode_permission(inode, MAY_EXEC);
65808+ if (error)
65809+ return error;
65810+
65811+ if (inode->i_op->getxattr)
65812+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65813+ else
65814+ error = -EOPNOTSUPP;
65815+
65816+ return error;
65817+}
65818+EXPORT_SYMBOL(pax_getxattr);
65819+#endif
65820+
65821 ssize_t
65822 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65823 {
65824@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65825 * Extended attribute SET operations
65826 */
65827 static long
65828-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65829+setxattr(struct path *path, const char __user *name, const void __user *value,
65830 size_t size, int flags)
65831 {
65832 int error;
65833@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65834 posix_acl_fix_xattr_from_user(kvalue, size);
65835 }
65836
65837- error = vfs_setxattr(d, kname, kvalue, size, flags);
65838+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65839+ error = -EACCES;
65840+ goto out;
65841+ }
65842+
65843+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65844 out:
65845 if (vvalue)
65846 vfree(vvalue);
65847@@ -377,7 +403,7 @@ retry:
65848 return error;
65849 error = mnt_want_write(path.mnt);
65850 if (!error) {
65851- error = setxattr(path.dentry, name, value, size, flags);
65852+ error = setxattr(&path, name, value, size, flags);
65853 mnt_drop_write(path.mnt);
65854 }
65855 path_put(&path);
65856@@ -401,7 +427,7 @@ retry:
65857 return error;
65858 error = mnt_want_write(path.mnt);
65859 if (!error) {
65860- error = setxattr(path.dentry, name, value, size, flags);
65861+ error = setxattr(&path, name, value, size, flags);
65862 mnt_drop_write(path.mnt);
65863 }
65864 path_put(&path);
65865@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65866 const void __user *,value, size_t, size, int, flags)
65867 {
65868 struct fd f = fdget(fd);
65869- struct dentry *dentry;
65870 int error = -EBADF;
65871
65872 if (!f.file)
65873 return error;
65874- dentry = f.file->f_path.dentry;
65875- audit_inode(NULL, dentry, 0);
65876+ audit_inode(NULL, f.file->f_path.dentry, 0);
65877 error = mnt_want_write_file(f.file);
65878 if (!error) {
65879- error = setxattr(dentry, name, value, size, flags);
65880+ error = setxattr(&f.file->f_path, name, value, size, flags);
65881 mnt_drop_write_file(f.file);
65882 }
65883 fdput(f);
65884@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65885 * Extended attribute REMOVE operations
65886 */
65887 static long
65888-removexattr(struct dentry *d, const char __user *name)
65889+removexattr(struct path *path, const char __user *name)
65890 {
65891 int error;
65892 char kname[XATTR_NAME_MAX + 1];
65893@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65894 if (error < 0)
65895 return error;
65896
65897- return vfs_removexattr(d, kname);
65898+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65899+ return -EACCES;
65900+
65901+ return vfs_removexattr(path->dentry, kname);
65902 }
65903
65904 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65905@@ -652,7 +679,7 @@ retry:
65906 return error;
65907 error = mnt_want_write(path.mnt);
65908 if (!error) {
65909- error = removexattr(path.dentry, name);
65910+ error = removexattr(&path, name);
65911 mnt_drop_write(path.mnt);
65912 }
65913 path_put(&path);
65914@@ -675,7 +702,7 @@ retry:
65915 return error;
65916 error = mnt_want_write(path.mnt);
65917 if (!error) {
65918- error = removexattr(path.dentry, name);
65919+ error = removexattr(&path, name);
65920 mnt_drop_write(path.mnt);
65921 }
65922 path_put(&path);
65923@@ -689,16 +716,16 @@ retry:
65924 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65925 {
65926 struct fd f = fdget(fd);
65927- struct dentry *dentry;
65928+ struct path *path;
65929 int error = -EBADF;
65930
65931 if (!f.file)
65932 return error;
65933- dentry = f.file->f_path.dentry;
65934- audit_inode(NULL, dentry, 0);
65935+ path = &f.file->f_path;
65936+ audit_inode(NULL, path->dentry, 0);
65937 error = mnt_want_write_file(f.file);
65938 if (!error) {
65939- error = removexattr(dentry, name);
65940+ error = removexattr(path, name);
65941 mnt_drop_write_file(f.file);
65942 }
65943 fdput(f);
65944diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65945index f0efc7e..ba72910 100644
65946--- a/fs/xfs/xfs_bmap.c
65947+++ b/fs/xfs/xfs_bmap.c
65948@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65949
65950 #else
65951 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65952-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65953+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65954 #endif /* DEBUG */
65955
65956 /*
65957diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65958index aead369..0dfecfd 100644
65959--- a/fs/xfs/xfs_dir2_readdir.c
65960+++ b/fs/xfs/xfs_dir2_readdir.c
65961@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65962 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65963 filetype = dp->d_ops->sf_get_ftype(sfep);
65964 ctx->pos = off & 0x7fffffff;
65965- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65966+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65967+ char name[sfep->namelen];
65968+ memcpy(name, sfep->name, sfep->namelen);
65969+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65970+ return 0;
65971+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65972 xfs_dir3_get_dtype(mp, filetype)))
65973 return 0;
65974 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65975diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65976index 6152cbe..f0f9eaa 100644
65977--- a/fs/xfs/xfs_ioctl.c
65978+++ b/fs/xfs/xfs_ioctl.c
65979@@ -122,7 +122,7 @@ xfs_find_handle(
65980 }
65981
65982 error = -EFAULT;
65983- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65984+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65985 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65986 goto out_put;
65987
65988diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65989new file mode 100644
65990index 0000000..bfd482c
65991--- /dev/null
65992+++ b/grsecurity/Kconfig
65993@@ -0,0 +1,1176 @@
65994+#
65995+# grecurity configuration
65996+#
65997+menu "Memory Protections"
65998+depends on GRKERNSEC
65999+
66000+config GRKERNSEC_KMEM
66001+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
66002+ default y if GRKERNSEC_CONFIG_AUTO
66003+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
66004+ help
66005+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
66006+ be written to or read from to modify or leak the contents of the running
66007+ kernel. /dev/port will also not be allowed to be opened, writing to
66008+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
66009+ If you have module support disabled, enabling this will close up several
66010+ ways that are currently used to insert malicious code into the running
66011+ kernel.
66012+
66013+ Even with this feature enabled, we still highly recommend that
66014+ you use the RBAC system, as it is still possible for an attacker to
66015+ modify the running kernel through other more obscure methods.
66016+
66017+ It is highly recommended that you say Y here if you meet all the
66018+ conditions above.
66019+
66020+config GRKERNSEC_VM86
66021+ bool "Restrict VM86 mode"
66022+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66023+ depends on X86_32
66024+
66025+ help
66026+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
66027+ make use of a special execution mode on 32bit x86 processors called
66028+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
66029+ video cards and will still work with this option enabled. The purpose
66030+ of the option is to prevent exploitation of emulation errors in
66031+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
66032+ Nearly all users should be able to enable this option.
66033+
66034+config GRKERNSEC_IO
66035+ bool "Disable privileged I/O"
66036+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66037+ depends on X86
66038+ select RTC_CLASS
66039+ select RTC_INTF_DEV
66040+ select RTC_DRV_CMOS
66041+
66042+ help
66043+ If you say Y here, all ioperm and iopl calls will return an error.
66044+ Ioperm and iopl can be used to modify the running kernel.
66045+ Unfortunately, some programs need this access to operate properly,
66046+ the most notable of which are XFree86 and hwclock. hwclock can be
66047+ remedied by having RTC support in the kernel, so real-time
66048+ clock support is enabled if this option is enabled, to ensure
66049+ that hwclock operates correctly. If hwclock still does not work,
66050+ either update udev or symlink /dev/rtc to /dev/rtc0.
66051+
66052+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
66053+ you may not be able to boot into a graphical environment with this
66054+ option enabled. In this case, you should use the RBAC system instead.
66055+
66056+config GRKERNSEC_JIT_HARDEN
66057+ bool "Harden BPF JIT against spray attacks"
66058+ default y if GRKERNSEC_CONFIG_AUTO
66059+ depends on BPF_JIT && X86
66060+ help
66061+ If you say Y here, the native code generated by the kernel's Berkeley
66062+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
66063+ attacks that attempt to fit attacker-beneficial instructions in
66064+ 32bit immediate fields of JIT-generated native instructions. The
66065+ attacker will generally aim to cause an unintended instruction sequence
66066+ of JIT-generated native code to execute by jumping into the middle of
66067+ a generated instruction. This feature effectively randomizes the 32bit
66068+ immediate constants present in the generated code to thwart such attacks.
66069+
66070+ If you're using KERNEXEC, it's recommended that you enable this option
66071+ to supplement the hardening of the kernel.
66072+
66073+config GRKERNSEC_PERF_HARDEN
66074+ bool "Disable unprivileged PERF_EVENTS usage by default"
66075+ default y if GRKERNSEC_CONFIG_AUTO
66076+ depends on PERF_EVENTS
66077+ help
66078+ If you say Y here, the range of acceptable values for the
66079+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
66080+ default to a new value: 3. When the sysctl is set to this value, no
66081+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
66082+
66083+ Though PERF_EVENTS can be used legitimately for performance monitoring
66084+ and low-level application profiling, it is forced on regardless of
66085+ configuration, has been at fault for several vulnerabilities, and
66086+ creates new opportunities for side channels and other information leaks.
66087+
66088+ This feature puts PERF_EVENTS into a secure default state and permits
66089+ the administrator to change out of it temporarily if unprivileged
66090+ application profiling is needed.
66091+
66092+config GRKERNSEC_RAND_THREADSTACK
66093+ bool "Insert random gaps between thread stacks"
66094+ default y if GRKERNSEC_CONFIG_AUTO
66095+ depends on PAX_RANDMMAP && !PPC
66096+ help
66097+ If you say Y here, a random-sized gap will be enforced between allocated
66098+ thread stacks. Glibc's NPTL and other threading libraries that
66099+ pass MAP_STACK to the kernel for thread stack allocation are supported.
66100+ The implementation currently provides 8 bits of entropy for the gap.
66101+
66102+ Many distributions do not compile threaded remote services with the
66103+ -fstack-check argument to GCC, causing the variable-sized stack-based
66104+ allocator, alloca(), to not probe the stack on allocation. This
66105+ permits an unbounded alloca() to skip over any guard page and potentially
66106+ modify another thread's stack reliably. An enforced random gap
66107+ reduces the reliability of such an attack and increases the chance
66108+ that such a read/write to another thread's stack instead lands in
66109+ an unmapped area, causing a crash and triggering grsecurity's
66110+ anti-bruteforcing logic.
66111+
66112+config GRKERNSEC_PROC_MEMMAP
66113+ bool "Harden ASLR against information leaks and entropy reduction"
66114+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66115+ depends on PAX_NOEXEC || PAX_ASLR
66116+ help
66117+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66118+ give no information about the addresses of its mappings if
66119+ PaX features that rely on random addresses are enabled on the task.
66120+ In addition to sanitizing this information and disabling other
66121+ dangerous sources of information, this option causes reads of sensitive
66122+ /proc/<pid> entries where the file descriptor was opened in a different
66123+ task than the one performing the read. Such attempts are logged.
66124+ This option also limits argv/env strings for suid/sgid binaries
66125+ to 512KB to prevent a complete exhaustion of the stack entropy provided
66126+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66127+ binaries to prevent alternative mmap layouts from being abused.
66128+
66129+ If you use PaX it is essential that you say Y here as it closes up
66130+ several holes that make full ASLR useless locally.
66131+
66132+
66133+config GRKERNSEC_KSTACKOVERFLOW
66134+ bool "Prevent kernel stack overflows"
66135+ default y if GRKERNSEC_CONFIG_AUTO
66136+ depends on !IA64 && 64BIT
66137+ help
66138+ If you say Y here, the kernel's process stacks will be allocated
66139+ with vmalloc instead of the kernel's default allocator. This
66140+ introduces guard pages that in combination with the alloca checking
66141+ of the STACKLEAK feature prevents all forms of kernel process stack
66142+ overflow abuse. Note that this is different from kernel stack
66143+ buffer overflows.
66144+
66145+config GRKERNSEC_BRUTE
66146+ bool "Deter exploit bruteforcing"
66147+ default y if GRKERNSEC_CONFIG_AUTO
66148+ help
66149+ If you say Y here, attempts to bruteforce exploits against forking
66150+ daemons such as apache or sshd, as well as against suid/sgid binaries
66151+ will be deterred. When a child of a forking daemon is killed by PaX
66152+ or crashes due to an illegal instruction or other suspicious signal,
66153+ the parent process will be delayed 30 seconds upon every subsequent
66154+ fork until the administrator is able to assess the situation and
66155+ restart the daemon.
66156+ In the suid/sgid case, the attempt is logged, the user has all their
66157+ existing instances of the suid/sgid binary terminated and will
66158+ be unable to execute any suid/sgid binaries for 15 minutes.
66159+
66160+ It is recommended that you also enable signal logging in the auditing
66161+ section so that logs are generated when a process triggers a suspicious
66162+ signal.
66163+ If the sysctl option is enabled, a sysctl option with name
66164+ "deter_bruteforce" is created.
66165+
66166+config GRKERNSEC_MODHARDEN
66167+ bool "Harden module auto-loading"
66168+ default y if GRKERNSEC_CONFIG_AUTO
66169+ depends on MODULES
66170+ help
66171+ If you say Y here, module auto-loading in response to use of some
66172+ feature implemented by an unloaded module will be restricted to
66173+ root users. Enabling this option helps defend against attacks
66174+ by unprivileged users who abuse the auto-loading behavior to
66175+ cause a vulnerable module to load that is then exploited.
66176+
66177+ If this option prevents a legitimate use of auto-loading for a
66178+ non-root user, the administrator can execute modprobe manually
66179+ with the exact name of the module mentioned in the alert log.
66180+ Alternatively, the administrator can add the module to the list
66181+ of modules loaded at boot by modifying init scripts.
66182+
66183+ Modification of init scripts will most likely be needed on
66184+ Ubuntu servers with encrypted home directory support enabled,
66185+ as the first non-root user logging in will cause the ecb(aes),
66186+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66187+
66188+config GRKERNSEC_HIDESYM
66189+ bool "Hide kernel symbols"
66190+ default y if GRKERNSEC_CONFIG_AUTO
66191+ select PAX_USERCOPY_SLABS
66192+ help
66193+ If you say Y here, getting information on loaded modules, and
66194+ displaying all kernel symbols through a syscall will be restricted
66195+ to users with CAP_SYS_MODULE. For software compatibility reasons,
66196+ /proc/kallsyms will be restricted to the root user. The RBAC
66197+ system can hide that entry even from root.
66198+
66199+ This option also prevents leaking of kernel addresses through
66200+ several /proc entries.
66201+
66202+ Note that this option is only effective provided the following
66203+ conditions are met:
66204+ 1) The kernel using grsecurity is not precompiled by some distribution
66205+ 2) You have also enabled GRKERNSEC_DMESG
66206+ 3) You are using the RBAC system and hiding other files such as your
66207+ kernel image and System.map. Alternatively, enabling this option
66208+ causes the permissions on /boot, /lib/modules, and the kernel
66209+ source directory to change at compile time to prevent
66210+ reading by non-root users.
66211+ If the above conditions are met, this option will aid in providing a
66212+ useful protection against local kernel exploitation of overflows
66213+ and arbitrary read/write vulnerabilities.
66214+
66215+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66216+ in addition to this feature.
66217+
66218+config GRKERNSEC_RANDSTRUCT
66219+ bool "Randomize layout of sensitive kernel structures"
66220+ default y if GRKERNSEC_CONFIG_AUTO
66221+ select GRKERNSEC_HIDESYM
66222+ select MODVERSIONS if MODULES
66223+ help
66224+ If you say Y here, the layouts of a number of sensitive kernel
66225+ structures (task, fs, cred, etc) and all structures composed entirely
66226+ of function pointers (aka "ops" structs) will be randomized at compile-time.
66227+ This can introduce the requirement of an additional infoleak
66228+ vulnerability for exploits targeting these structure types.
66229+
66230+ Enabling this feature will introduce some performance impact, slightly
66231+ increase memory usage, and prevent the use of forensic tools like
66232+ Volatility against the system (unless the kernel source tree isn't
66233+ cleaned after kernel installation).
66234+
66235+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66236+ It remains after a make clean to allow for external modules to be compiled
66237+ with the existing seed and will be removed by a make mrproper or
66238+ make distclean.
66239+
66240+ Note that the implementation requires gcc 4.6.4. or newer. You may need
66241+ to install the supporting headers explicitly in addition to the normal
66242+ gcc package.
66243+
66244+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66245+ bool "Use cacheline-aware structure randomization"
66246+ depends on GRKERNSEC_RANDSTRUCT
66247+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66248+ help
66249+ If you say Y here, the RANDSTRUCT randomization will make a best effort
66250+ at restricting randomization to cacheline-sized groups of elements. It
66251+ will further not randomize bitfields in structures. This reduces the
66252+ performance hit of RANDSTRUCT at the cost of weakened randomization.
66253+
66254+config GRKERNSEC_KERN_LOCKOUT
66255+ bool "Active kernel exploit response"
66256+ default y if GRKERNSEC_CONFIG_AUTO
66257+ depends on X86 || ARM || PPC || SPARC
66258+ help
66259+ If you say Y here, when a PaX alert is triggered due to suspicious
66260+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66261+ or an OOPS occurs due to bad memory accesses, instead of just
66262+ terminating the offending process (and potentially allowing
66263+ a subsequent exploit from the same user), we will take one of two
66264+ actions:
66265+ If the user was root, we will panic the system
66266+ If the user was non-root, we will log the attempt, terminate
66267+ all processes owned by the user, then prevent them from creating
66268+ any new processes until the system is restarted
66269+ This deters repeated kernel exploitation/bruteforcing attempts
66270+ and is useful for later forensics.
66271+
66272+config GRKERNSEC_OLD_ARM_USERLAND
66273+ bool "Old ARM userland compatibility"
66274+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66275+ help
66276+ If you say Y here, stubs of executable code to perform such operations
66277+ as "compare-exchange" will be placed at fixed locations in the ARM vector
66278+ table. This is unfortunately needed for old ARM userland meant to run
66279+ across a wide range of processors. Without this option enabled,
66280+ the get_tls and data memory barrier stubs will be emulated by the kernel,
66281+ which is enough for Linaro userlands or other userlands designed for v6
66282+ and newer ARM CPUs. It's recommended that you try without this option enabled
66283+ first, and only enable it if your userland does not boot (it will likely fail
66284+ at init time).
66285+
66286+endmenu
66287+menu "Role Based Access Control Options"
66288+depends on GRKERNSEC
66289+
66290+config GRKERNSEC_RBAC_DEBUG
66291+ bool
66292+
66293+config GRKERNSEC_NO_RBAC
66294+ bool "Disable RBAC system"
66295+ help
66296+ If you say Y here, the /dev/grsec device will be removed from the kernel,
66297+ preventing the RBAC system from being enabled. You should only say Y
66298+ here if you have no intention of using the RBAC system, so as to prevent
66299+ an attacker with root access from misusing the RBAC system to hide files
66300+ and processes when loadable module support and /dev/[k]mem have been
66301+ locked down.
66302+
66303+config GRKERNSEC_ACL_HIDEKERN
66304+ bool "Hide kernel processes"
66305+ help
66306+ If you say Y here, all kernel threads will be hidden to all
66307+ processes but those whose subject has the "view hidden processes"
66308+ flag.
66309+
66310+config GRKERNSEC_ACL_MAXTRIES
66311+ int "Maximum tries before password lockout"
66312+ default 3
66313+ help
66314+ This option enforces the maximum number of times a user can attempt
66315+ to authorize themselves with the grsecurity RBAC system before being
66316+ denied the ability to attempt authorization again for a specified time.
66317+ The lower the number, the harder it will be to brute-force a password.
66318+
66319+config GRKERNSEC_ACL_TIMEOUT
66320+ int "Time to wait after max password tries, in seconds"
66321+ default 30
66322+ help
66323+ This option specifies the time the user must wait after attempting to
66324+ authorize to the RBAC system with the maximum number of invalid
66325+ passwords. The higher the number, the harder it will be to brute-force
66326+ a password.
66327+
66328+endmenu
66329+menu "Filesystem Protections"
66330+depends on GRKERNSEC
66331+
66332+config GRKERNSEC_PROC
66333+ bool "Proc restrictions"
66334+ default y if GRKERNSEC_CONFIG_AUTO
66335+ help
66336+ If you say Y here, the permissions of the /proc filesystem
66337+ will be altered to enhance system security and privacy. You MUST
66338+ choose either a user only restriction or a user and group restriction.
66339+ Depending upon the option you choose, you can either restrict users to
66340+ see only the processes they themselves run, or choose a group that can
66341+ view all processes and files normally restricted to root if you choose
66342+ the "restrict to user only" option. NOTE: If you're running identd or
66343+ ntpd as a non-root user, you will have to run it as the group you
66344+ specify here.
66345+
66346+config GRKERNSEC_PROC_USER
66347+ bool "Restrict /proc to user only"
66348+ depends on GRKERNSEC_PROC
66349+ help
66350+ If you say Y here, non-root users will only be able to view their own
66351+ processes, and restricts them from viewing network-related information,
66352+ and viewing kernel symbol and module information.
66353+
66354+config GRKERNSEC_PROC_USERGROUP
66355+ bool "Allow special group"
66356+ default y if GRKERNSEC_CONFIG_AUTO
66357+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66358+ help
66359+ If you say Y here, you will be able to select a group that will be
66360+ able to view all processes and network-related information. If you've
66361+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66362+ remain hidden. This option is useful if you want to run identd as
66363+ a non-root user. The group you select may also be chosen at boot time
66364+ via "grsec_proc_gid=" on the kernel commandline.
66365+
66366+config GRKERNSEC_PROC_GID
66367+ int "GID for special group"
66368+ depends on GRKERNSEC_PROC_USERGROUP
66369+ default 1001
66370+
66371+config GRKERNSEC_PROC_ADD
66372+ bool "Additional restrictions"
66373+ default y if GRKERNSEC_CONFIG_AUTO
66374+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66375+ help
66376+ If you say Y here, additional restrictions will be placed on
66377+ /proc that keep normal users from viewing device information and
66378+ slabinfo information that could be useful for exploits.
66379+
66380+config GRKERNSEC_LINK
66381+ bool "Linking restrictions"
66382+ default y if GRKERNSEC_CONFIG_AUTO
66383+ help
66384+ If you say Y here, /tmp race exploits will be prevented, since users
66385+ will no longer be able to follow symlinks owned by other users in
66386+ world-writable +t directories (e.g. /tmp), unless the owner of the
66387+ symlink is the owner of the directory. users will also not be
66388+ able to hardlink to files they do not own. If the sysctl option is
66389+ enabled, a sysctl option with name "linking_restrictions" is created.
66390+
66391+config GRKERNSEC_SYMLINKOWN
66392+ bool "Kernel-enforced SymlinksIfOwnerMatch"
66393+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66394+ help
66395+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
66396+ that prevents it from being used as a security feature. As Apache
66397+ verifies the symlink by performing a stat() against the target of
66398+ the symlink before it is followed, an attacker can setup a symlink
66399+ to point to a same-owned file, then replace the symlink with one
66400+ that targets another user's file just after Apache "validates" the
66401+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
66402+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66403+ will be in place for the group you specify. If the sysctl option
66404+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
66405+ created.
66406+
66407+config GRKERNSEC_SYMLINKOWN_GID
66408+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66409+ depends on GRKERNSEC_SYMLINKOWN
66410+ default 1006
66411+ help
66412+ Setting this GID determines what group kernel-enforced
66413+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66414+ is enabled, a sysctl option with name "symlinkown_gid" is created.
66415+
66416+config GRKERNSEC_FIFO
66417+ bool "FIFO restrictions"
66418+ default y if GRKERNSEC_CONFIG_AUTO
66419+ help
66420+ If you say Y here, users will not be able to write to FIFOs they don't
66421+ own in world-writable +t directories (e.g. /tmp), unless the owner of
66422+ the FIFO is the same owner of the directory it's held in. If the sysctl
66423+ option is enabled, a sysctl option with name "fifo_restrictions" is
66424+ created.
66425+
66426+config GRKERNSEC_SYSFS_RESTRICT
66427+ bool "Sysfs/debugfs restriction"
66428+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66429+ depends on SYSFS
66430+ help
66431+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66432+ any filesystem normally mounted under it (e.g. debugfs) will be
66433+ mostly accessible only by root. These filesystems generally provide access
66434+ to hardware and debug information that isn't appropriate for unprivileged
66435+ users of the system. Sysfs and debugfs have also become a large source
66436+ of new vulnerabilities, ranging from infoleaks to local compromise.
66437+ There has been very little oversight with an eye toward security involved
66438+ in adding new exporters of information to these filesystems, so their
66439+ use is discouraged.
66440+ For reasons of compatibility, a few directories have been whitelisted
66441+ for access by non-root users:
66442+ /sys/fs/selinux
66443+ /sys/fs/fuse
66444+ /sys/devices/system/cpu
66445+
66446+config GRKERNSEC_ROFS
66447+ bool "Runtime read-only mount protection"
66448+ depends on SYSCTL
66449+ help
66450+ If you say Y here, a sysctl option with name "romount_protect" will
66451+ be created. By setting this option to 1 at runtime, filesystems
66452+ will be protected in the following ways:
66453+ * No new writable mounts will be allowed
66454+ * Existing read-only mounts won't be able to be remounted read/write
66455+ * Write operations will be denied on all block devices
66456+ This option acts independently of grsec_lock: once it is set to 1,
66457+ it cannot be turned off. Therefore, please be mindful of the resulting
66458+ behavior if this option is enabled in an init script on a read-only
66459+ filesystem.
66460+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66461+ and GRKERNSEC_IO should be enabled and module loading disabled via
66462+ config or at runtime.
66463+ This feature is mainly intended for secure embedded systems.
66464+
66465+
66466+config GRKERNSEC_DEVICE_SIDECHANNEL
66467+ bool "Eliminate stat/notify-based device sidechannels"
66468+ default y if GRKERNSEC_CONFIG_AUTO
66469+ help
66470+ If you say Y here, timing analyses on block or character
66471+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66472+ will be thwarted for unprivileged users. If a process without
66473+ CAP_MKNOD stats such a device, the last access and last modify times
66474+ will match the device's create time. No access or modify events
66475+ will be triggered through inotify/dnotify/fanotify for such devices.
66476+ This feature will prevent attacks that may at a minimum
66477+ allow an attacker to determine the administrator's password length.
66478+
66479+config GRKERNSEC_CHROOT
66480+ bool "Chroot jail restrictions"
66481+ default y if GRKERNSEC_CONFIG_AUTO
66482+ help
66483+ If you say Y here, you will be able to choose several options that will
66484+ make breaking out of a chrooted jail much more difficult. If you
66485+ encounter no software incompatibilities with the following options, it
66486+ is recommended that you enable each one.
66487+
66488+ Note that the chroot restrictions are not intended to apply to "chroots"
66489+ to directories that are simple bind mounts of the global root filesystem.
66490+ For several other reasons, a user shouldn't expect any significant
66491+ security by performing such a chroot.
66492+
66493+config GRKERNSEC_CHROOT_MOUNT
66494+ bool "Deny mounts"
66495+ default y if GRKERNSEC_CONFIG_AUTO
66496+ depends on GRKERNSEC_CHROOT
66497+ help
66498+ If you say Y here, processes inside a chroot will not be able to
66499+ mount or remount filesystems. If the sysctl option is enabled, a
66500+ sysctl option with name "chroot_deny_mount" is created.
66501+
66502+config GRKERNSEC_CHROOT_DOUBLE
66503+ bool "Deny double-chroots"
66504+ default y if GRKERNSEC_CONFIG_AUTO
66505+ depends on GRKERNSEC_CHROOT
66506+ help
66507+ If you say Y here, processes inside a chroot will not be able to chroot
66508+ again outside the chroot. This is a widely used method of breaking
66509+ out of a chroot jail and should not be allowed. If the sysctl
66510+ option is enabled, a sysctl option with name
66511+ "chroot_deny_chroot" is created.
66512+
66513+config GRKERNSEC_CHROOT_PIVOT
66514+ bool "Deny pivot_root in chroot"
66515+ default y if GRKERNSEC_CONFIG_AUTO
66516+ depends on GRKERNSEC_CHROOT
66517+ help
66518+ If you say Y here, processes inside a chroot will not be able to use
66519+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66520+ works similar to chroot in that it changes the root filesystem. This
66521+ function could be misused in a chrooted process to attempt to break out
66522+ of the chroot, and therefore should not be allowed. If the sysctl
66523+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66524+ created.
66525+
66526+config GRKERNSEC_CHROOT_CHDIR
66527+ bool "Enforce chdir(\"/\") on all chroots"
66528+ default y if GRKERNSEC_CONFIG_AUTO
66529+ depends on GRKERNSEC_CHROOT
66530+ help
66531+ If you say Y here, the current working directory of all newly-chrooted
66532+ applications will be set to the the root directory of the chroot.
66533+ The man page on chroot(2) states:
66534+ Note that this call does not change the current working
66535+ directory, so that `.' can be outside the tree rooted at
66536+ `/'. In particular, the super-user can escape from a
66537+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66538+
66539+ It is recommended that you say Y here, since it's not known to break
66540+ any software. If the sysctl option is enabled, a sysctl option with
66541+ name "chroot_enforce_chdir" is created.
66542+
66543+config GRKERNSEC_CHROOT_CHMOD
66544+ bool "Deny (f)chmod +s"
66545+ default y if GRKERNSEC_CONFIG_AUTO
66546+ depends on GRKERNSEC_CHROOT
66547+ help
66548+ If you say Y here, processes inside a chroot will not be able to chmod
66549+ or fchmod files to make them have suid or sgid bits. This protects
66550+ against another published method of breaking a chroot. If the sysctl
66551+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66552+ created.
66553+
66554+config GRKERNSEC_CHROOT_FCHDIR
66555+ bool "Deny fchdir and fhandle out of chroot"
66556+ default y if GRKERNSEC_CONFIG_AUTO
66557+ depends on GRKERNSEC_CHROOT
66558+ help
66559+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66560+ to a file descriptor of the chrooting process that points to a directory
66561+ outside the filesystem will be stopped. Additionally, this option prevents
66562+ use of the recently-created syscall for opening files by a guessable "file
66563+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66564+ with name "chroot_deny_fchdir" is created.
66565+
66566+config GRKERNSEC_CHROOT_MKNOD
66567+ bool "Deny mknod"
66568+ default y if GRKERNSEC_CONFIG_AUTO
66569+ depends on GRKERNSEC_CHROOT
66570+ help
66571+ If you say Y here, processes inside a chroot will not be allowed to
66572+ mknod. The problem with using mknod inside a chroot is that it
66573+ would allow an attacker to create a device entry that is the same
66574+ as one on the physical root of your system, which could range from
66575+ anything from the console device to a device for your harddrive (which
66576+ they could then use to wipe the drive or steal data). It is recommended
66577+ that you say Y here, unless you run into software incompatibilities.
66578+ If the sysctl option is enabled, a sysctl option with name
66579+ "chroot_deny_mknod" is created.
66580+
66581+config GRKERNSEC_CHROOT_SHMAT
66582+ bool "Deny shmat() out of chroot"
66583+ default y if GRKERNSEC_CONFIG_AUTO
66584+ depends on GRKERNSEC_CHROOT
66585+ help
66586+ If you say Y here, processes inside a chroot will not be able to attach
66587+ to shared memory segments that were created outside of the chroot jail.
66588+ It is recommended that you say Y here. If the sysctl option is enabled,
66589+ a sysctl option with name "chroot_deny_shmat" is created.
66590+
66591+config GRKERNSEC_CHROOT_UNIX
66592+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66593+ default y if GRKERNSEC_CONFIG_AUTO
66594+ depends on GRKERNSEC_CHROOT
66595+ help
66596+ If you say Y here, processes inside a chroot will not be able to
66597+ connect to abstract (meaning not belonging to a filesystem) Unix
66598+ domain sockets that were bound outside of a chroot. It is recommended
66599+ that you say Y here. If the sysctl option is enabled, a sysctl option
66600+ with name "chroot_deny_unix" is created.
66601+
66602+config GRKERNSEC_CHROOT_FINDTASK
66603+ bool "Protect outside processes"
66604+ default y if GRKERNSEC_CONFIG_AUTO
66605+ depends on GRKERNSEC_CHROOT
66606+ help
66607+ If you say Y here, processes inside a chroot will not be able to
66608+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66609+ getsid, or view any process outside of the chroot. If the sysctl
66610+ option is enabled, a sysctl option with name "chroot_findtask" is
66611+ created.
66612+
66613+config GRKERNSEC_CHROOT_NICE
66614+ bool "Restrict priority changes"
66615+ default y if GRKERNSEC_CONFIG_AUTO
66616+ depends on GRKERNSEC_CHROOT
66617+ help
66618+ If you say Y here, processes inside a chroot will not be able to raise
66619+ the priority of processes in the chroot, or alter the priority of
66620+ processes outside the chroot. This provides more security than simply
66621+ removing CAP_SYS_NICE from the process' capability set. If the
66622+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66623+ is created.
66624+
66625+config GRKERNSEC_CHROOT_SYSCTL
66626+ bool "Deny sysctl writes"
66627+ default y if GRKERNSEC_CONFIG_AUTO
66628+ depends on GRKERNSEC_CHROOT
66629+ help
66630+ If you say Y here, an attacker in a chroot will not be able to
66631+ write to sysctl entries, either by sysctl(2) or through a /proc
66632+ interface. It is strongly recommended that you say Y here. If the
66633+ sysctl option is enabled, a sysctl option with name
66634+ "chroot_deny_sysctl" is created.
66635+
66636+config GRKERNSEC_CHROOT_CAPS
66637+ bool "Capability restrictions"
66638+ default y if GRKERNSEC_CONFIG_AUTO
66639+ depends on GRKERNSEC_CHROOT
66640+ help
66641+ If you say Y here, the capabilities on all processes within a
66642+ chroot jail will be lowered to stop module insertion, raw i/o,
66643+ system and net admin tasks, rebooting the system, modifying immutable
66644+ files, modifying IPC owned by another, and changing the system time.
66645+ This is left an option because it can break some apps. Disable this
66646+ if your chrooted apps are having problems performing those kinds of
66647+ tasks. If the sysctl option is enabled, a sysctl option with
66648+ name "chroot_caps" is created.
66649+
66650+config GRKERNSEC_CHROOT_INITRD
66651+ bool "Exempt initrd tasks from restrictions"
66652+ default y if GRKERNSEC_CONFIG_AUTO
66653+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66654+ help
66655+ If you say Y here, tasks started prior to init will be exempted from
66656+ grsecurity's chroot restrictions. This option is mainly meant to
66657+ resolve Plymouth's performing privileged operations unnecessarily
66658+ in a chroot.
66659+
66660+endmenu
66661+menu "Kernel Auditing"
66662+depends on GRKERNSEC
66663+
66664+config GRKERNSEC_AUDIT_GROUP
66665+ bool "Single group for auditing"
66666+ help
66667+ If you say Y here, the exec and chdir logging features will only operate
66668+ on a group you specify. This option is recommended if you only want to
66669+ watch certain users instead of having a large amount of logs from the
66670+ entire system. If the sysctl option is enabled, a sysctl option with
66671+ name "audit_group" is created.
66672+
66673+config GRKERNSEC_AUDIT_GID
66674+ int "GID for auditing"
66675+ depends on GRKERNSEC_AUDIT_GROUP
66676+ default 1007
66677+
66678+config GRKERNSEC_EXECLOG
66679+ bool "Exec logging"
66680+ help
66681+ If you say Y here, all execve() calls will be logged (since the
66682+ other exec*() calls are frontends to execve(), all execution
66683+ will be logged). Useful for shell-servers that like to keep track
66684+ of their users. If the sysctl option is enabled, a sysctl option with
66685+ name "exec_logging" is created.
66686+ WARNING: This option when enabled will produce a LOT of logs, especially
66687+ on an active system.
66688+
66689+config GRKERNSEC_RESLOG
66690+ bool "Resource logging"
66691+ default y if GRKERNSEC_CONFIG_AUTO
66692+ help
66693+ If you say Y here, all attempts to overstep resource limits will
66694+ be logged with the resource name, the requested size, and the current
66695+ limit. It is highly recommended that you say Y here. If the sysctl
66696+ option is enabled, a sysctl option with name "resource_logging" is
66697+ created. If the RBAC system is enabled, the sysctl value is ignored.
66698+
66699+config GRKERNSEC_CHROOT_EXECLOG
66700+ bool "Log execs within chroot"
66701+ help
66702+ If you say Y here, all executions inside a chroot jail will be logged
66703+ to syslog. This can cause a large amount of logs if certain
66704+ applications (eg. djb's daemontools) are installed on the system, and
66705+ is therefore left as an option. If the sysctl option is enabled, a
66706+ sysctl option with name "chroot_execlog" is created.
66707+
66708+config GRKERNSEC_AUDIT_PTRACE
66709+ bool "Ptrace logging"
66710+ help
66711+ If you say Y here, all attempts to attach to a process via ptrace
66712+ will be logged. If the sysctl option is enabled, a sysctl option
66713+ with name "audit_ptrace" is created.
66714+
66715+config GRKERNSEC_AUDIT_CHDIR
66716+ bool "Chdir logging"
66717+ help
66718+ If you say Y here, all chdir() calls will be logged. If the sysctl
66719+ option is enabled, a sysctl option with name "audit_chdir" is created.
66720+
66721+config GRKERNSEC_AUDIT_MOUNT
66722+ bool "(Un)Mount logging"
66723+ help
66724+ If you say Y here, all mounts and unmounts will be logged. If the
66725+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66726+ created.
66727+
66728+config GRKERNSEC_SIGNAL
66729+ bool "Signal logging"
66730+ default y if GRKERNSEC_CONFIG_AUTO
66731+ help
66732+ If you say Y here, certain important signals will be logged, such as
66733+ SIGSEGV, which will as a result inform you of when a error in a program
66734+ occurred, which in some cases could mean a possible exploit attempt.
66735+ If the sysctl option is enabled, a sysctl option with name
66736+ "signal_logging" is created.
66737+
66738+config GRKERNSEC_FORKFAIL
66739+ bool "Fork failure logging"
66740+ help
66741+ If you say Y here, all failed fork() attempts will be logged.
66742+ This could suggest a fork bomb, or someone attempting to overstep
66743+ their process limit. If the sysctl option is enabled, a sysctl option
66744+ with name "forkfail_logging" is created.
66745+
66746+config GRKERNSEC_TIME
66747+ bool "Time change logging"
66748+ default y if GRKERNSEC_CONFIG_AUTO
66749+ help
66750+ If you say Y here, any changes of the system clock will be logged.
66751+ If the sysctl option is enabled, a sysctl option with name
66752+ "timechange_logging" is created.
66753+
66754+config GRKERNSEC_PROC_IPADDR
66755+ bool "/proc/<pid>/ipaddr support"
66756+ default y if GRKERNSEC_CONFIG_AUTO
66757+ help
66758+ If you say Y here, a new entry will be added to each /proc/<pid>
66759+ directory that contains the IP address of the person using the task.
66760+ The IP is carried across local TCP and AF_UNIX stream sockets.
66761+ This information can be useful for IDS/IPSes to perform remote response
66762+ to a local attack. The entry is readable by only the owner of the
66763+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66764+ the RBAC system), and thus does not create privacy concerns.
66765+
66766+config GRKERNSEC_RWXMAP_LOG
66767+ bool 'Denied RWX mmap/mprotect logging'
66768+ default y if GRKERNSEC_CONFIG_AUTO
66769+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66770+ help
66771+ If you say Y here, calls to mmap() and mprotect() with explicit
66772+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66773+ denied by the PAX_MPROTECT feature. This feature will also
66774+ log other problematic scenarios that can occur when PAX_MPROTECT
66775+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66776+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66777+ is created.
66778+
66779+endmenu
66780+
66781+menu "Executable Protections"
66782+depends on GRKERNSEC
66783+
66784+config GRKERNSEC_DMESG
66785+ bool "Dmesg(8) restriction"
66786+ default y if GRKERNSEC_CONFIG_AUTO
66787+ help
66788+ If you say Y here, non-root users will not be able to use dmesg(8)
66789+ to view the contents of the kernel's circular log buffer.
66790+ The kernel's log buffer often contains kernel addresses and other
66791+ identifying information useful to an attacker in fingerprinting a
66792+ system for a targeted exploit.
66793+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66794+ created.
66795+
66796+config GRKERNSEC_HARDEN_PTRACE
66797+ bool "Deter ptrace-based process snooping"
66798+ default y if GRKERNSEC_CONFIG_AUTO
66799+ help
66800+ If you say Y here, TTY sniffers and other malicious monitoring
66801+ programs implemented through ptrace will be defeated. If you
66802+ have been using the RBAC system, this option has already been
66803+ enabled for several years for all users, with the ability to make
66804+ fine-grained exceptions.
66805+
66806+ This option only affects the ability of non-root users to ptrace
66807+ processes that are not a descendent of the ptracing process.
66808+ This means that strace ./binary and gdb ./binary will still work,
66809+ but attaching to arbitrary processes will not. If the sysctl
66810+ option is enabled, a sysctl option with name "harden_ptrace" is
66811+ created.
66812+
66813+config GRKERNSEC_PTRACE_READEXEC
66814+ bool "Require read access to ptrace sensitive binaries"
66815+ default y if GRKERNSEC_CONFIG_AUTO
66816+ help
66817+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66818+ binaries. This option is useful in environments that
66819+ remove the read bits (e.g. file mode 4711) from suid binaries to
66820+ prevent infoleaking of their contents. This option adds
66821+ consistency to the use of that file mode, as the binary could normally
66822+ be read out when run without privileges while ptracing.
66823+
66824+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66825+ is created.
66826+
66827+config GRKERNSEC_SETXID
66828+ bool "Enforce consistent multithreaded privileges"
66829+ default y if GRKERNSEC_CONFIG_AUTO
66830+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66831+ help
66832+ If you say Y here, a change from a root uid to a non-root uid
66833+ in a multithreaded application will cause the resulting uids,
66834+ gids, supplementary groups, and capabilities in that thread
66835+ to be propagated to the other threads of the process. In most
66836+ cases this is unnecessary, as glibc will emulate this behavior
66837+ on behalf of the application. Other libcs do not act in the
66838+ same way, allowing the other threads of the process to continue
66839+ running with root privileges. If the sysctl option is enabled,
66840+ a sysctl option with name "consistent_setxid" is created.
66841+
66842+config GRKERNSEC_HARDEN_IPC
66843+ bool "Disallow access to overly-permissive IPC objects"
66844+ default y if GRKERNSEC_CONFIG_AUTO
66845+ depends on SYSVIPC
66846+ help
66847+ If you say Y here, access to overly-permissive IPC objects (shared
66848+ memory, message queues, and semaphores) will be denied for processes
66849+ given the following criteria beyond normal permission checks:
66850+ 1) If the IPC object is world-accessible and the euid doesn't match
66851+ that of the creator or current uid for the IPC object
66852+ 2) If the IPC object is group-accessible and the egid doesn't
66853+ match that of the creator or current gid for the IPC object
66854+ It's a common error to grant too much permission to these objects,
66855+ with impact ranging from denial of service and information leaking to
66856+ privilege escalation. This feature was developed in response to
66857+ research by Tim Brown:
66858+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66859+ who found hundreds of such insecure usages. Processes with
66860+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66861+ If the sysctl option is enabled, a sysctl option with name
66862+ "harden_ipc" is created.
66863+
66864+config GRKERNSEC_TPE
66865+ bool "Trusted Path Execution (TPE)"
66866+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66867+ help
66868+ If you say Y here, you will be able to choose a gid to add to the
66869+ supplementary groups of users you want to mark as "untrusted."
66870+ These users will not be able to execute any files that are not in
66871+ root-owned directories writable only by root. If the sysctl option
66872+ is enabled, a sysctl option with name "tpe" is created.
66873+
66874+config GRKERNSEC_TPE_ALL
66875+ bool "Partially restrict all non-root users"
66876+ depends on GRKERNSEC_TPE
66877+ help
66878+ If you say Y here, all non-root users will be covered under
66879+ a weaker TPE restriction. This is separate from, and in addition to,
66880+ the main TPE options that you have selected elsewhere. Thus, if a
66881+ "trusted" GID is chosen, this restriction applies to even that GID.
66882+ Under this restriction, all non-root users will only be allowed to
66883+ execute files in directories they own that are not group or
66884+ world-writable, or in directories owned by root and writable only by
66885+ root. If the sysctl option is enabled, a sysctl option with name
66886+ "tpe_restrict_all" is created.
66887+
66888+config GRKERNSEC_TPE_INVERT
66889+ bool "Invert GID option"
66890+ depends on GRKERNSEC_TPE
66891+ help
66892+ If you say Y here, the group you specify in the TPE configuration will
66893+ decide what group TPE restrictions will be *disabled* for. This
66894+ option is useful if you want TPE restrictions to be applied to most
66895+ users on the system. If the sysctl option is enabled, a sysctl option
66896+ with name "tpe_invert" is created. Unlike other sysctl options, this
66897+ entry will default to on for backward-compatibility.
66898+
66899+config GRKERNSEC_TPE_GID
66900+ int
66901+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66902+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66903+
66904+config GRKERNSEC_TPE_UNTRUSTED_GID
66905+ int "GID for TPE-untrusted users"
66906+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66907+ default 1005
66908+ help
66909+ Setting this GID determines what group TPE restrictions will be
66910+ *enabled* for. If the sysctl option is enabled, a sysctl option
66911+ with name "tpe_gid" is created.
66912+
66913+config GRKERNSEC_TPE_TRUSTED_GID
66914+ int "GID for TPE-trusted users"
66915+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66916+ default 1005
66917+ help
66918+ Setting this GID determines what group TPE restrictions will be
66919+ *disabled* for. If the sysctl option is enabled, a sysctl option
66920+ with name "tpe_gid" is created.
66921+
66922+endmenu
66923+menu "Network Protections"
66924+depends on GRKERNSEC
66925+
66926+config GRKERNSEC_RANDNET
66927+ bool "Larger entropy pools"
66928+ default y if GRKERNSEC_CONFIG_AUTO
66929+ help
66930+ If you say Y here, the entropy pools used for many features of Linux
66931+ and grsecurity will be doubled in size. Since several grsecurity
66932+ features use additional randomness, it is recommended that you say Y
66933+ here. Saying Y here has a similar effect as modifying
66934+ /proc/sys/kernel/random/poolsize.
66935+
66936+config GRKERNSEC_BLACKHOLE
66937+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66938+ default y if GRKERNSEC_CONFIG_AUTO
66939+ depends on NET
66940+ help
66941+ If you say Y here, neither TCP resets nor ICMP
66942+ destination-unreachable packets will be sent in response to packets
66943+ sent to ports for which no associated listening process exists.
66944+ This feature supports both IPV4 and IPV6 and exempts the
66945+ loopback interface from blackholing. Enabling this feature
66946+ makes a host more resilient to DoS attacks and reduces network
66947+ visibility against scanners.
66948+
66949+ The blackhole feature as-implemented is equivalent to the FreeBSD
66950+ blackhole feature, as it prevents RST responses to all packets, not
66951+ just SYNs. Under most application behavior this causes no
66952+ problems, but applications (like haproxy) may not close certain
66953+ connections in a way that cleanly terminates them on the remote
66954+ end, leaving the remote host in LAST_ACK state. Because of this
66955+ side-effect and to prevent intentional LAST_ACK DoSes, this
66956+ feature also adds automatic mitigation against such attacks.
66957+ The mitigation drastically reduces the amount of time a socket
66958+ can spend in LAST_ACK state. If you're using haproxy and not
66959+ all servers it connects to have this option enabled, consider
66960+ disabling this feature on the haproxy host.
66961+
66962+ If the sysctl option is enabled, two sysctl options with names
66963+ "ip_blackhole" and "lastack_retries" will be created.
66964+ While "ip_blackhole" takes the standard zero/non-zero on/off
66965+ toggle, "lastack_retries" uses the same kinds of values as
66966+ "tcp_retries1" and "tcp_retries2". The default value of 4
66967+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66968+ state.
66969+
66970+config GRKERNSEC_NO_SIMULT_CONNECT
66971+ bool "Disable TCP Simultaneous Connect"
66972+ default y if GRKERNSEC_CONFIG_AUTO
66973+ depends on NET
66974+ help
66975+ If you say Y here, a feature by Willy Tarreau will be enabled that
66976+ removes a weakness in Linux's strict implementation of TCP that
66977+ allows two clients to connect to each other without either entering
66978+ a listening state. The weakness allows an attacker to easily prevent
66979+ a client from connecting to a known server provided the source port
66980+ for the connection is guessed correctly.
66981+
66982+ As the weakness could be used to prevent an antivirus or IPS from
66983+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66984+ it should be eliminated by enabling this option. Though Linux is
66985+ one of few operating systems supporting simultaneous connect, it
66986+ has no legitimate use in practice and is rarely supported by firewalls.
66987+
66988+config GRKERNSEC_SOCKET
66989+ bool "Socket restrictions"
66990+ depends on NET
66991+ help
66992+ If you say Y here, you will be able to choose from several options.
66993+ If you assign a GID on your system and add it to the supplementary
66994+ groups of users you want to restrict socket access to, this patch
66995+ will perform up to three things, based on the option(s) you choose.
66996+
66997+config GRKERNSEC_SOCKET_ALL
66998+ bool "Deny any sockets to group"
66999+ depends on GRKERNSEC_SOCKET
67000+ help
67001+ If you say Y here, you will be able to choose a GID of whose users will
67002+ be unable to connect to other hosts from your machine or run server
67003+ applications from your machine. If the sysctl option is enabled, a
67004+ sysctl option with name "socket_all" is created.
67005+
67006+config GRKERNSEC_SOCKET_ALL_GID
67007+ int "GID to deny all sockets for"
67008+ depends on GRKERNSEC_SOCKET_ALL
67009+ default 1004
67010+ help
67011+ Here you can choose the GID to disable socket access for. Remember to
67012+ add the users you want socket access disabled for to the GID
67013+ specified here. If the sysctl option is enabled, a sysctl option
67014+ with name "socket_all_gid" is created.
67015+
67016+config GRKERNSEC_SOCKET_CLIENT
67017+ bool "Deny client sockets to group"
67018+ depends on GRKERNSEC_SOCKET
67019+ help
67020+ If you say Y here, you will be able to choose a GID of whose users will
67021+ be unable to connect to other hosts from your machine, but will be
67022+ able to run servers. If this option is enabled, all users in the group
67023+ you specify will have to use passive mode when initiating ftp transfers
67024+ from the shell on your machine. If the sysctl option is enabled, a
67025+ sysctl option with name "socket_client" is created.
67026+
67027+config GRKERNSEC_SOCKET_CLIENT_GID
67028+ int "GID to deny client sockets for"
67029+ depends on GRKERNSEC_SOCKET_CLIENT
67030+ default 1003
67031+ help
67032+ Here you can choose the GID to disable client socket access for.
67033+ Remember to add the users you want client socket access disabled for to
67034+ the GID specified here. If the sysctl option is enabled, a sysctl
67035+ option with name "socket_client_gid" is created.
67036+
67037+config GRKERNSEC_SOCKET_SERVER
67038+ bool "Deny server sockets to group"
67039+ depends on GRKERNSEC_SOCKET
67040+ help
67041+ If you say Y here, you will be able to choose a GID of whose users will
67042+ be unable to run server applications from your machine. If the sysctl
67043+ option is enabled, a sysctl option with name "socket_server" is created.
67044+
67045+config GRKERNSEC_SOCKET_SERVER_GID
67046+ int "GID to deny server sockets for"
67047+ depends on GRKERNSEC_SOCKET_SERVER
67048+ default 1002
67049+ help
67050+ Here you can choose the GID to disable server socket access for.
67051+ Remember to add the users you want server socket access disabled for to
67052+ the GID specified here. If the sysctl option is enabled, a sysctl
67053+ option with name "socket_server_gid" is created.
67054+
67055+endmenu
67056+
67057+menu "Physical Protections"
67058+depends on GRKERNSEC
67059+
67060+config GRKERNSEC_DENYUSB
67061+ bool "Deny new USB connections after toggle"
67062+ default y if GRKERNSEC_CONFIG_AUTO
67063+ depends on SYSCTL && USB_SUPPORT
67064+ help
67065+ If you say Y here, a new sysctl option with name "deny_new_usb"
67066+ will be created. Setting its value to 1 will prevent any new
67067+ USB devices from being recognized by the OS. Any attempted USB
67068+ device insertion will be logged. This option is intended to be
67069+ used against custom USB devices designed to exploit vulnerabilities
67070+ in various USB device drivers.
67071+
67072+ For greatest effectiveness, this sysctl should be set after any
67073+ relevant init scripts. This option is safe to enable in distros
67074+ as each user can choose whether or not to toggle the sysctl.
67075+
67076+config GRKERNSEC_DENYUSB_FORCE
67077+ bool "Reject all USB devices not connected at boot"
67078+ select USB
67079+ depends on GRKERNSEC_DENYUSB
67080+ help
67081+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
67082+ that doesn't involve a sysctl entry. This option should only be
67083+ enabled if you're sure you want to deny all new USB connections
67084+ at runtime and don't want to modify init scripts. This should not
67085+ be enabled by distros. It forces the core USB code to be built
67086+ into the kernel image so that all devices connected at boot time
67087+ can be recognized and new USB device connections can be prevented
67088+ prior to init running.
67089+
67090+endmenu
67091+
67092+menu "Sysctl Support"
67093+depends on GRKERNSEC && SYSCTL
67094+
67095+config GRKERNSEC_SYSCTL
67096+ bool "Sysctl support"
67097+ default y if GRKERNSEC_CONFIG_AUTO
67098+ help
67099+ If you say Y here, you will be able to change the options that
67100+ grsecurity runs with at bootup, without having to recompile your
67101+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
67102+ to enable (1) or disable (0) various features. All the sysctl entries
67103+ are mutable until the "grsec_lock" entry is set to a non-zero value.
67104+ All features enabled in the kernel configuration are disabled at boot
67105+ if you do not say Y to the "Turn on features by default" option.
67106+ All options should be set at startup, and the grsec_lock entry should
67107+ be set to a non-zero value after all the options are set.
67108+ *THIS IS EXTREMELY IMPORTANT*
67109+
67110+config GRKERNSEC_SYSCTL_DISTRO
67111+ bool "Extra sysctl support for distro makers (READ HELP)"
67112+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
67113+ help
67114+ If you say Y here, additional sysctl options will be created
67115+ for features that affect processes running as root. Therefore,
67116+ it is critical when using this option that the grsec_lock entry be
67117+ enabled after boot. Only distros with prebuilt kernel packages
67118+ with this option enabled that can ensure grsec_lock is enabled
67119+ after boot should use this option.
67120+ *Failure to set grsec_lock after boot makes all grsec features
67121+ this option covers useless*
67122+
67123+ Currently this option creates the following sysctl entries:
67124+ "Disable Privileged I/O": "disable_priv_io"
67125+
67126+config GRKERNSEC_SYSCTL_ON
67127+ bool "Turn on features by default"
67128+ default y if GRKERNSEC_CONFIG_AUTO
67129+ depends on GRKERNSEC_SYSCTL
67130+ help
67131+ If you say Y here, instead of having all features enabled in the
67132+ kernel configuration disabled at boot time, the features will be
67133+ enabled at boot time. It is recommended you say Y here unless
67134+ there is some reason you would want all sysctl-tunable features to
67135+ be disabled by default. As mentioned elsewhere, it is important
67136+ to enable the grsec_lock entry once you have finished modifying
67137+ the sysctl entries.
67138+
67139+endmenu
67140+menu "Logging Options"
67141+depends on GRKERNSEC
67142+
67143+config GRKERNSEC_FLOODTIME
67144+ int "Seconds in between log messages (minimum)"
67145+ default 10
67146+ help
67147+ This option allows you to enforce the number of seconds between
67148+ grsecurity log messages. The default should be suitable for most
67149+ people, however, if you choose to change it, choose a value small enough
67150+ to allow informative logs to be produced, but large enough to
67151+ prevent flooding.
67152+
67153+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67154+ any rate limiting on grsecurity log messages.
67155+
67156+config GRKERNSEC_FLOODBURST
67157+ int "Number of messages in a burst (maximum)"
67158+ default 6
67159+ help
67160+ This option allows you to choose the maximum number of messages allowed
67161+ within the flood time interval you chose in a separate option. The
67162+ default should be suitable for most people, however if you find that
67163+ many of your logs are being interpreted as flooding, you may want to
67164+ raise this value.
67165+
67166+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67167+ any rate limiting on grsecurity log messages.
67168+
67169+endmenu
67170diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67171new file mode 100644
67172index 0000000..30ababb
67173--- /dev/null
67174+++ b/grsecurity/Makefile
67175@@ -0,0 +1,54 @@
67176+# grsecurity – access control and security hardening for Linux
67177+# All code in this directory and various hooks located throughout the Linux kernel are
67178+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67179+# http://www.grsecurity.net spender@grsecurity.net
67180+#
67181+# This program is free software; you can redistribute it and/or
67182+# modify it under the terms of the GNU General Public License version 2
67183+# as published by the Free Software Foundation.
67184+#
67185+# This program is distributed in the hope that it will be useful,
67186+# but WITHOUT ANY WARRANTY; without even the implied warranty of
67187+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67188+# GNU General Public License for more details.
67189+#
67190+# You should have received a copy of the GNU General Public License
67191+# along with this program; if not, write to the Free Software
67192+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67193+
67194+KBUILD_CFLAGS += -Werror
67195+
67196+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67197+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
67198+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67199+ grsec_usb.o grsec_ipc.o grsec_proc.o
67200+
67201+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67202+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67203+ gracl_learn.o grsec_log.o gracl_policy.o
67204+ifdef CONFIG_COMPAT
67205+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67206+endif
67207+
67208+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67209+
67210+ifdef CONFIG_NET
67211+obj-y += grsec_sock.o
67212+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67213+endif
67214+
67215+ifndef CONFIG_GRKERNSEC
67216+obj-y += grsec_disabled.o
67217+endif
67218+
67219+ifdef CONFIG_GRKERNSEC_HIDESYM
67220+extra-y := grsec_hidesym.o
67221+$(obj)/grsec_hidesym.o:
67222+ @-chmod -f 500 /boot
67223+ @-chmod -f 500 /lib/modules
67224+ @-chmod -f 500 /lib64/modules
67225+ @-chmod -f 500 /lib32/modules
67226+ @-chmod -f 700 .
67227+ @-chmod -f 700 $(objtree)
67228+ @echo ' grsec: protected kernel image paths'
67229+endif
67230diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67231new file mode 100644
67232index 0000000..58223f6
67233--- /dev/null
67234+++ b/grsecurity/gracl.c
67235@@ -0,0 +1,2702 @@
67236+#include <linux/kernel.h>
67237+#include <linux/module.h>
67238+#include <linux/sched.h>
67239+#include <linux/mm.h>
67240+#include <linux/file.h>
67241+#include <linux/fs.h>
67242+#include <linux/namei.h>
67243+#include <linux/mount.h>
67244+#include <linux/tty.h>
67245+#include <linux/proc_fs.h>
67246+#include <linux/lglock.h>
67247+#include <linux/slab.h>
67248+#include <linux/vmalloc.h>
67249+#include <linux/types.h>
67250+#include <linux/sysctl.h>
67251+#include <linux/netdevice.h>
67252+#include <linux/ptrace.h>
67253+#include <linux/gracl.h>
67254+#include <linux/gralloc.h>
67255+#include <linux/security.h>
67256+#include <linux/grinternal.h>
67257+#include <linux/pid_namespace.h>
67258+#include <linux/stop_machine.h>
67259+#include <linux/fdtable.h>
67260+#include <linux/percpu.h>
67261+#include <linux/lglock.h>
67262+#include <linux/hugetlb.h>
67263+#include <linux/posix-timers.h>
67264+#include <linux/prefetch.h>
67265+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67266+#include <linux/magic.h>
67267+#include <linux/pagemap.h>
67268+#include "../fs/btrfs/async-thread.h"
67269+#include "../fs/btrfs/ctree.h"
67270+#include "../fs/btrfs/btrfs_inode.h"
67271+#endif
67272+#include "../fs/mount.h"
67273+
67274+#include <asm/uaccess.h>
67275+#include <asm/errno.h>
67276+#include <asm/mman.h>
67277+
67278+#define FOR_EACH_ROLE_START(role) \
67279+ role = running_polstate.role_list; \
67280+ while (role) {
67281+
67282+#define FOR_EACH_ROLE_END(role) \
67283+ role = role->prev; \
67284+ }
67285+
67286+extern struct path gr_real_root;
67287+
67288+static struct gr_policy_state running_polstate;
67289+struct gr_policy_state *polstate = &running_polstate;
67290+extern struct gr_alloc_state *current_alloc_state;
67291+
67292+extern char *gr_shared_page[4];
67293+DEFINE_RWLOCK(gr_inode_lock);
67294+
67295+static unsigned int gr_status __read_only = GR_STATUS_INIT;
67296+
67297+#ifdef CONFIG_NET
67298+extern struct vfsmount *sock_mnt;
67299+#endif
67300+
67301+extern struct vfsmount *pipe_mnt;
67302+extern struct vfsmount *shm_mnt;
67303+
67304+#ifdef CONFIG_HUGETLBFS
67305+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67306+#endif
67307+
67308+extern u16 acl_sp_role_value;
67309+extern struct acl_object_label *fakefs_obj_rw;
67310+extern struct acl_object_label *fakefs_obj_rwx;
67311+
67312+int gr_acl_is_enabled(void)
67313+{
67314+ return (gr_status & GR_READY);
67315+}
67316+
67317+void gr_enable_rbac_system(void)
67318+{
67319+ pax_open_kernel();
67320+ gr_status |= GR_READY;
67321+ pax_close_kernel();
67322+}
67323+
67324+int gr_rbac_disable(void *unused)
67325+{
67326+ pax_open_kernel();
67327+ gr_status &= ~GR_READY;
67328+ pax_close_kernel();
67329+
67330+ return 0;
67331+}
67332+
67333+static inline dev_t __get_dev(const struct dentry *dentry)
67334+{
67335+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67336+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67337+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67338+ else
67339+#endif
67340+ return dentry->d_sb->s_dev;
67341+}
67342+
67343+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67344+{
67345+ return __get_dev(dentry);
67346+}
67347+
67348+static char gr_task_roletype_to_char(struct task_struct *task)
67349+{
67350+ switch (task->role->roletype &
67351+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67352+ GR_ROLE_SPECIAL)) {
67353+ case GR_ROLE_DEFAULT:
67354+ return 'D';
67355+ case GR_ROLE_USER:
67356+ return 'U';
67357+ case GR_ROLE_GROUP:
67358+ return 'G';
67359+ case GR_ROLE_SPECIAL:
67360+ return 'S';
67361+ }
67362+
67363+ return 'X';
67364+}
67365+
67366+char gr_roletype_to_char(void)
67367+{
67368+ return gr_task_roletype_to_char(current);
67369+}
67370+
67371+__inline__ int
67372+gr_acl_tpe_check(void)
67373+{
67374+ if (unlikely(!(gr_status & GR_READY)))
67375+ return 0;
67376+ if (current->role->roletype & GR_ROLE_TPE)
67377+ return 1;
67378+ else
67379+ return 0;
67380+}
67381+
67382+int
67383+gr_handle_rawio(const struct inode *inode)
67384+{
67385+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67386+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67387+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67388+ !capable(CAP_SYS_RAWIO))
67389+ return 1;
67390+#endif
67391+ return 0;
67392+}
67393+
67394+int
67395+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67396+{
67397+ if (likely(lena != lenb))
67398+ return 0;
67399+
67400+ return !memcmp(a, b, lena);
67401+}
67402+
67403+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67404+{
67405+ *buflen -= namelen;
67406+ if (*buflen < 0)
67407+ return -ENAMETOOLONG;
67408+ *buffer -= namelen;
67409+ memcpy(*buffer, str, namelen);
67410+ return 0;
67411+}
67412+
67413+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67414+{
67415+ return prepend(buffer, buflen, name->name, name->len);
67416+}
67417+
67418+static int prepend_path(const struct path *path, struct path *root,
67419+ char **buffer, int *buflen)
67420+{
67421+ struct dentry *dentry = path->dentry;
67422+ struct vfsmount *vfsmnt = path->mnt;
67423+ struct mount *mnt = real_mount(vfsmnt);
67424+ bool slash = false;
67425+ int error = 0;
67426+
67427+ while (dentry != root->dentry || vfsmnt != root->mnt) {
67428+ struct dentry * parent;
67429+
67430+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67431+ /* Global root? */
67432+ if (!mnt_has_parent(mnt)) {
67433+ goto out;
67434+ }
67435+ dentry = mnt->mnt_mountpoint;
67436+ mnt = mnt->mnt_parent;
67437+ vfsmnt = &mnt->mnt;
67438+ continue;
67439+ }
67440+ parent = dentry->d_parent;
67441+ prefetch(parent);
67442+ spin_lock(&dentry->d_lock);
67443+ error = prepend_name(buffer, buflen, &dentry->d_name);
67444+ spin_unlock(&dentry->d_lock);
67445+ if (!error)
67446+ error = prepend(buffer, buflen, "/", 1);
67447+ if (error)
67448+ break;
67449+
67450+ slash = true;
67451+ dentry = parent;
67452+ }
67453+
67454+out:
67455+ if (!error && !slash)
67456+ error = prepend(buffer, buflen, "/", 1);
67457+
67458+ return error;
67459+}
67460+
67461+/* this must be called with mount_lock and rename_lock held */
67462+
67463+static char *__our_d_path(const struct path *path, struct path *root,
67464+ char *buf, int buflen)
67465+{
67466+ char *res = buf + buflen;
67467+ int error;
67468+
67469+ prepend(&res, &buflen, "\0", 1);
67470+ error = prepend_path(path, root, &res, &buflen);
67471+ if (error)
67472+ return ERR_PTR(error);
67473+
67474+ return res;
67475+}
67476+
67477+static char *
67478+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67479+{
67480+ char *retval;
67481+
67482+ retval = __our_d_path(path, root, buf, buflen);
67483+ if (unlikely(IS_ERR(retval)))
67484+ retval = strcpy(buf, "<path too long>");
67485+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67486+ retval[1] = '\0';
67487+
67488+ return retval;
67489+}
67490+
67491+static char *
67492+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67493+ char *buf, int buflen)
67494+{
67495+ struct path path;
67496+ char *res;
67497+
67498+ path.dentry = (struct dentry *)dentry;
67499+ path.mnt = (struct vfsmount *)vfsmnt;
67500+
67501+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67502+ by the RBAC system */
67503+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67504+
67505+ return res;
67506+}
67507+
67508+static char *
67509+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67510+ char *buf, int buflen)
67511+{
67512+ char *res;
67513+ struct path path;
67514+ struct path root;
67515+ struct task_struct *reaper = init_pid_ns.child_reaper;
67516+
67517+ path.dentry = (struct dentry *)dentry;
67518+ path.mnt = (struct vfsmount *)vfsmnt;
67519+
67520+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67521+ get_fs_root(reaper->fs, &root);
67522+
67523+ read_seqlock_excl(&mount_lock);
67524+ write_seqlock(&rename_lock);
67525+ res = gen_full_path(&path, &root, buf, buflen);
67526+ write_sequnlock(&rename_lock);
67527+ read_sequnlock_excl(&mount_lock);
67528+
67529+ path_put(&root);
67530+ return res;
67531+}
67532+
67533+char *
67534+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67535+{
67536+ char *ret;
67537+ read_seqlock_excl(&mount_lock);
67538+ write_seqlock(&rename_lock);
67539+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67540+ PAGE_SIZE);
67541+ write_sequnlock(&rename_lock);
67542+ read_sequnlock_excl(&mount_lock);
67543+ return ret;
67544+}
67545+
67546+static char *
67547+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67548+{
67549+ char *ret;
67550+ char *buf;
67551+ int buflen;
67552+
67553+ read_seqlock_excl(&mount_lock);
67554+ write_seqlock(&rename_lock);
67555+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67556+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67557+ buflen = (int)(ret - buf);
67558+ if (buflen >= 5)
67559+ prepend(&ret, &buflen, "/proc", 5);
67560+ else
67561+ ret = strcpy(buf, "<path too long>");
67562+ write_sequnlock(&rename_lock);
67563+ read_sequnlock_excl(&mount_lock);
67564+ return ret;
67565+}
67566+
67567+char *
67568+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67569+{
67570+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67571+ PAGE_SIZE);
67572+}
67573+
67574+char *
67575+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67576+{
67577+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67578+ PAGE_SIZE);
67579+}
67580+
67581+char *
67582+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67583+{
67584+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67585+ PAGE_SIZE);
67586+}
67587+
67588+char *
67589+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67590+{
67591+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67592+ PAGE_SIZE);
67593+}
67594+
67595+char *
67596+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67597+{
67598+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67599+ PAGE_SIZE);
67600+}
67601+
67602+__inline__ __u32
67603+to_gr_audit(const __u32 reqmode)
67604+{
67605+ /* masks off auditable permission flags, then shifts them to create
67606+ auditing flags, and adds the special case of append auditing if
67607+ we're requesting write */
67608+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67609+}
67610+
67611+struct acl_role_label *
67612+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67613+ const gid_t gid)
67614+{
67615+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67616+ struct acl_role_label *match;
67617+ struct role_allowed_ip *ipp;
67618+ unsigned int x;
67619+ u32 curr_ip = task->signal->saved_ip;
67620+
67621+ match = state->acl_role_set.r_hash[index];
67622+
67623+ while (match) {
67624+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67625+ for (x = 0; x < match->domain_child_num; x++) {
67626+ if (match->domain_children[x] == uid)
67627+ goto found;
67628+ }
67629+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67630+ break;
67631+ match = match->next;
67632+ }
67633+found:
67634+ if (match == NULL) {
67635+ try_group:
67636+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67637+ match = state->acl_role_set.r_hash[index];
67638+
67639+ while (match) {
67640+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67641+ for (x = 0; x < match->domain_child_num; x++) {
67642+ if (match->domain_children[x] == gid)
67643+ goto found2;
67644+ }
67645+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67646+ break;
67647+ match = match->next;
67648+ }
67649+found2:
67650+ if (match == NULL)
67651+ match = state->default_role;
67652+ if (match->allowed_ips == NULL)
67653+ return match;
67654+ else {
67655+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67656+ if (likely
67657+ ((ntohl(curr_ip) & ipp->netmask) ==
67658+ (ntohl(ipp->addr) & ipp->netmask)))
67659+ return match;
67660+ }
67661+ match = state->default_role;
67662+ }
67663+ } else if (match->allowed_ips == NULL) {
67664+ return match;
67665+ } else {
67666+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67667+ if (likely
67668+ ((ntohl(curr_ip) & ipp->netmask) ==
67669+ (ntohl(ipp->addr) & ipp->netmask)))
67670+ return match;
67671+ }
67672+ goto try_group;
67673+ }
67674+
67675+ return match;
67676+}
67677+
67678+static struct acl_role_label *
67679+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67680+ const gid_t gid)
67681+{
67682+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67683+}
67684+
67685+struct acl_subject_label *
67686+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67687+ const struct acl_role_label *role)
67688+{
67689+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67690+ struct acl_subject_label *match;
67691+
67692+ match = role->subj_hash[index];
67693+
67694+ while (match && (match->inode != ino || match->device != dev ||
67695+ (match->mode & GR_DELETED))) {
67696+ match = match->next;
67697+ }
67698+
67699+ if (match && !(match->mode & GR_DELETED))
67700+ return match;
67701+ else
67702+ return NULL;
67703+}
67704+
67705+struct acl_subject_label *
67706+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67707+ const struct acl_role_label *role)
67708+{
67709+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67710+ struct acl_subject_label *match;
67711+
67712+ match = role->subj_hash[index];
67713+
67714+ while (match && (match->inode != ino || match->device != dev ||
67715+ !(match->mode & GR_DELETED))) {
67716+ match = match->next;
67717+ }
67718+
67719+ if (match && (match->mode & GR_DELETED))
67720+ return match;
67721+ else
67722+ return NULL;
67723+}
67724+
67725+static struct acl_object_label *
67726+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67727+ const struct acl_subject_label *subj)
67728+{
67729+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67730+ struct acl_object_label *match;
67731+
67732+ match = subj->obj_hash[index];
67733+
67734+ while (match && (match->inode != ino || match->device != dev ||
67735+ (match->mode & GR_DELETED))) {
67736+ match = match->next;
67737+ }
67738+
67739+ if (match && !(match->mode & GR_DELETED))
67740+ return match;
67741+ else
67742+ return NULL;
67743+}
67744+
67745+static struct acl_object_label *
67746+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67747+ const struct acl_subject_label *subj)
67748+{
67749+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67750+ struct acl_object_label *match;
67751+
67752+ match = subj->obj_hash[index];
67753+
67754+ while (match && (match->inode != ino || match->device != dev ||
67755+ !(match->mode & GR_DELETED))) {
67756+ match = match->next;
67757+ }
67758+
67759+ if (match && (match->mode & GR_DELETED))
67760+ return match;
67761+
67762+ match = subj->obj_hash[index];
67763+
67764+ while (match && (match->inode != ino || match->device != dev ||
67765+ (match->mode & GR_DELETED))) {
67766+ match = match->next;
67767+ }
67768+
67769+ if (match && !(match->mode & GR_DELETED))
67770+ return match;
67771+ else
67772+ return NULL;
67773+}
67774+
67775+struct name_entry *
67776+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67777+{
67778+ unsigned int len = strlen(name);
67779+ unsigned int key = full_name_hash(name, len);
67780+ unsigned int index = key % state->name_set.n_size;
67781+ struct name_entry *match;
67782+
67783+ match = state->name_set.n_hash[index];
67784+
67785+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67786+ match = match->next;
67787+
67788+ return match;
67789+}
67790+
67791+static struct name_entry *
67792+lookup_name_entry(const char *name)
67793+{
67794+ return __lookup_name_entry(&running_polstate, name);
67795+}
67796+
67797+static struct name_entry *
67798+lookup_name_entry_create(const char *name)
67799+{
67800+ unsigned int len = strlen(name);
67801+ unsigned int key = full_name_hash(name, len);
67802+ unsigned int index = key % running_polstate.name_set.n_size;
67803+ struct name_entry *match;
67804+
67805+ match = running_polstate.name_set.n_hash[index];
67806+
67807+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67808+ !match->deleted))
67809+ match = match->next;
67810+
67811+ if (match && match->deleted)
67812+ return match;
67813+
67814+ match = running_polstate.name_set.n_hash[index];
67815+
67816+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67817+ match->deleted))
67818+ match = match->next;
67819+
67820+ if (match && !match->deleted)
67821+ return match;
67822+ else
67823+ return NULL;
67824+}
67825+
67826+static struct inodev_entry *
67827+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67828+{
67829+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67830+ struct inodev_entry *match;
67831+
67832+ match = running_polstate.inodev_set.i_hash[index];
67833+
67834+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67835+ match = match->next;
67836+
67837+ return match;
67838+}
67839+
67840+void
67841+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67842+{
67843+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67844+ state->inodev_set.i_size);
67845+ struct inodev_entry **curr;
67846+
67847+ entry->prev = NULL;
67848+
67849+ curr = &state->inodev_set.i_hash[index];
67850+ if (*curr != NULL)
67851+ (*curr)->prev = entry;
67852+
67853+ entry->next = *curr;
67854+ *curr = entry;
67855+
67856+ return;
67857+}
67858+
67859+static void
67860+insert_inodev_entry(struct inodev_entry *entry)
67861+{
67862+ __insert_inodev_entry(&running_polstate, entry);
67863+}
67864+
67865+void
67866+insert_acl_obj_label(struct acl_object_label *obj,
67867+ struct acl_subject_label *subj)
67868+{
67869+ unsigned int index =
67870+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67871+ struct acl_object_label **curr;
67872+
67873+ obj->prev = NULL;
67874+
67875+ curr = &subj->obj_hash[index];
67876+ if (*curr != NULL)
67877+ (*curr)->prev = obj;
67878+
67879+ obj->next = *curr;
67880+ *curr = obj;
67881+
67882+ return;
67883+}
67884+
67885+void
67886+insert_acl_subj_label(struct acl_subject_label *obj,
67887+ struct acl_role_label *role)
67888+{
67889+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67890+ struct acl_subject_label **curr;
67891+
67892+ obj->prev = NULL;
67893+
67894+ curr = &role->subj_hash[index];
67895+ if (*curr != NULL)
67896+ (*curr)->prev = obj;
67897+
67898+ obj->next = *curr;
67899+ *curr = obj;
67900+
67901+ return;
67902+}
67903+
67904+/* derived from glibc fnmatch() 0: match, 1: no match*/
67905+
67906+static int
67907+glob_match(const char *p, const char *n)
67908+{
67909+ char c;
67910+
67911+ while ((c = *p++) != '\0') {
67912+ switch (c) {
67913+ case '?':
67914+ if (*n == '\0')
67915+ return 1;
67916+ else if (*n == '/')
67917+ return 1;
67918+ break;
67919+ case '\\':
67920+ if (*n != c)
67921+ return 1;
67922+ break;
67923+ case '*':
67924+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67925+ if (*n == '/')
67926+ return 1;
67927+ else if (c == '?') {
67928+ if (*n == '\0')
67929+ return 1;
67930+ else
67931+ ++n;
67932+ }
67933+ }
67934+ if (c == '\0') {
67935+ return 0;
67936+ } else {
67937+ const char *endp;
67938+
67939+ if ((endp = strchr(n, '/')) == NULL)
67940+ endp = n + strlen(n);
67941+
67942+ if (c == '[') {
67943+ for (--p; n < endp; ++n)
67944+ if (!glob_match(p, n))
67945+ return 0;
67946+ } else if (c == '/') {
67947+ while (*n != '\0' && *n != '/')
67948+ ++n;
67949+ if (*n == '/' && !glob_match(p, n + 1))
67950+ return 0;
67951+ } else {
67952+ for (--p; n < endp; ++n)
67953+ if (*n == c && !glob_match(p, n))
67954+ return 0;
67955+ }
67956+
67957+ return 1;
67958+ }
67959+ case '[':
67960+ {
67961+ int not;
67962+ char cold;
67963+
67964+ if (*n == '\0' || *n == '/')
67965+ return 1;
67966+
67967+ not = (*p == '!' || *p == '^');
67968+ if (not)
67969+ ++p;
67970+
67971+ c = *p++;
67972+ for (;;) {
67973+ unsigned char fn = (unsigned char)*n;
67974+
67975+ if (c == '\0')
67976+ return 1;
67977+ else {
67978+ if (c == fn)
67979+ goto matched;
67980+ cold = c;
67981+ c = *p++;
67982+
67983+ if (c == '-' && *p != ']') {
67984+ unsigned char cend = *p++;
67985+
67986+ if (cend == '\0')
67987+ return 1;
67988+
67989+ if (cold <= fn && fn <= cend)
67990+ goto matched;
67991+
67992+ c = *p++;
67993+ }
67994+ }
67995+
67996+ if (c == ']')
67997+ break;
67998+ }
67999+ if (!not)
68000+ return 1;
68001+ break;
68002+ matched:
68003+ while (c != ']') {
68004+ if (c == '\0')
68005+ return 1;
68006+
68007+ c = *p++;
68008+ }
68009+ if (not)
68010+ return 1;
68011+ }
68012+ break;
68013+ default:
68014+ if (c != *n)
68015+ return 1;
68016+ }
68017+
68018+ ++n;
68019+ }
68020+
68021+ if (*n == '\0')
68022+ return 0;
68023+
68024+ if (*n == '/')
68025+ return 0;
68026+
68027+ return 1;
68028+}
68029+
68030+static struct acl_object_label *
68031+chk_glob_label(struct acl_object_label *globbed,
68032+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
68033+{
68034+ struct acl_object_label *tmp;
68035+
68036+ if (*path == NULL)
68037+ *path = gr_to_filename_nolock(dentry, mnt);
68038+
68039+ tmp = globbed;
68040+
68041+ while (tmp) {
68042+ if (!glob_match(tmp->filename, *path))
68043+ return tmp;
68044+ tmp = tmp->next;
68045+ }
68046+
68047+ return NULL;
68048+}
68049+
68050+static struct acl_object_label *
68051+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68052+ const ino_t curr_ino, const dev_t curr_dev,
68053+ const struct acl_subject_label *subj, char **path, const int checkglob)
68054+{
68055+ struct acl_subject_label *tmpsubj;
68056+ struct acl_object_label *retval;
68057+ struct acl_object_label *retval2;
68058+
68059+ tmpsubj = (struct acl_subject_label *) subj;
68060+ read_lock(&gr_inode_lock);
68061+ do {
68062+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
68063+ if (retval) {
68064+ if (checkglob && retval->globbed) {
68065+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
68066+ if (retval2)
68067+ retval = retval2;
68068+ }
68069+ break;
68070+ }
68071+ } while ((tmpsubj = tmpsubj->parent_subject));
68072+ read_unlock(&gr_inode_lock);
68073+
68074+ return retval;
68075+}
68076+
68077+static __inline__ struct acl_object_label *
68078+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68079+ struct dentry *curr_dentry,
68080+ const struct acl_subject_label *subj, char **path, const int checkglob)
68081+{
68082+ int newglob = checkglob;
68083+ ino_t inode;
68084+ dev_t device;
68085+
68086+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
68087+ as we don't want a / * rule to match instead of the / object
68088+ don't do this for create lookups that call this function though, since they're looking up
68089+ on the parent and thus need globbing checks on all paths
68090+ */
68091+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
68092+ newglob = GR_NO_GLOB;
68093+
68094+ spin_lock(&curr_dentry->d_lock);
68095+ inode = curr_dentry->d_inode->i_ino;
68096+ device = __get_dev(curr_dentry);
68097+ spin_unlock(&curr_dentry->d_lock);
68098+
68099+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
68100+}
68101+
68102+#ifdef CONFIG_HUGETLBFS
68103+static inline bool
68104+is_hugetlbfs_mnt(const struct vfsmount *mnt)
68105+{
68106+ int i;
68107+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
68108+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
68109+ return true;
68110+ }
68111+
68112+ return false;
68113+}
68114+#endif
68115+
68116+static struct acl_object_label *
68117+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68118+ const struct acl_subject_label *subj, char *path, const int checkglob)
68119+{
68120+ struct dentry *dentry = (struct dentry *) l_dentry;
68121+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68122+ struct mount *real_mnt = real_mount(mnt);
68123+ struct acl_object_label *retval;
68124+ struct dentry *parent;
68125+
68126+ read_seqlock_excl(&mount_lock);
68127+ write_seqlock(&rename_lock);
68128+
68129+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68130+#ifdef CONFIG_NET
68131+ mnt == sock_mnt ||
68132+#endif
68133+#ifdef CONFIG_HUGETLBFS
68134+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68135+#endif
68136+ /* ignore Eric Biederman */
68137+ IS_PRIVATE(l_dentry->d_inode))) {
68138+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68139+ goto out;
68140+ }
68141+
68142+ for (;;) {
68143+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68144+ break;
68145+
68146+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68147+ if (!mnt_has_parent(real_mnt))
68148+ break;
68149+
68150+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68151+ if (retval != NULL)
68152+ goto out;
68153+
68154+ dentry = real_mnt->mnt_mountpoint;
68155+ real_mnt = real_mnt->mnt_parent;
68156+ mnt = &real_mnt->mnt;
68157+ continue;
68158+ }
68159+
68160+ parent = dentry->d_parent;
68161+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68162+ if (retval != NULL)
68163+ goto out;
68164+
68165+ dentry = parent;
68166+ }
68167+
68168+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68169+
68170+ /* gr_real_root is pinned so we don't have to hold a reference */
68171+ if (retval == NULL)
68172+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68173+out:
68174+ write_sequnlock(&rename_lock);
68175+ read_sequnlock_excl(&mount_lock);
68176+
68177+ BUG_ON(retval == NULL);
68178+
68179+ return retval;
68180+}
68181+
68182+static __inline__ struct acl_object_label *
68183+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68184+ const struct acl_subject_label *subj)
68185+{
68186+ char *path = NULL;
68187+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68188+}
68189+
68190+static __inline__ struct acl_object_label *
68191+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68192+ const struct acl_subject_label *subj)
68193+{
68194+ char *path = NULL;
68195+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68196+}
68197+
68198+static __inline__ struct acl_object_label *
68199+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68200+ const struct acl_subject_label *subj, char *path)
68201+{
68202+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68203+}
68204+
68205+struct acl_subject_label *
68206+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68207+ const struct acl_role_label *role)
68208+{
68209+ struct dentry *dentry = (struct dentry *) l_dentry;
68210+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68211+ struct mount *real_mnt = real_mount(mnt);
68212+ struct acl_subject_label *retval;
68213+ struct dentry *parent;
68214+
68215+ read_seqlock_excl(&mount_lock);
68216+ write_seqlock(&rename_lock);
68217+
68218+ for (;;) {
68219+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68220+ break;
68221+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68222+ if (!mnt_has_parent(real_mnt))
68223+ break;
68224+
68225+ spin_lock(&dentry->d_lock);
68226+ read_lock(&gr_inode_lock);
68227+ retval =
68228+ lookup_acl_subj_label(dentry->d_inode->i_ino,
68229+ __get_dev(dentry), role);
68230+ read_unlock(&gr_inode_lock);
68231+ spin_unlock(&dentry->d_lock);
68232+ if (retval != NULL)
68233+ goto out;
68234+
68235+ dentry = real_mnt->mnt_mountpoint;
68236+ real_mnt = real_mnt->mnt_parent;
68237+ mnt = &real_mnt->mnt;
68238+ continue;
68239+ }
68240+
68241+ spin_lock(&dentry->d_lock);
68242+ read_lock(&gr_inode_lock);
68243+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68244+ __get_dev(dentry), role);
68245+ read_unlock(&gr_inode_lock);
68246+ parent = dentry->d_parent;
68247+ spin_unlock(&dentry->d_lock);
68248+
68249+ if (retval != NULL)
68250+ goto out;
68251+
68252+ dentry = parent;
68253+ }
68254+
68255+ spin_lock(&dentry->d_lock);
68256+ read_lock(&gr_inode_lock);
68257+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68258+ __get_dev(dentry), role);
68259+ read_unlock(&gr_inode_lock);
68260+ spin_unlock(&dentry->d_lock);
68261+
68262+ if (unlikely(retval == NULL)) {
68263+ /* gr_real_root is pinned, we don't need to hold a reference */
68264+ read_lock(&gr_inode_lock);
68265+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68266+ __get_dev(gr_real_root.dentry), role);
68267+ read_unlock(&gr_inode_lock);
68268+ }
68269+out:
68270+ write_sequnlock(&rename_lock);
68271+ read_sequnlock_excl(&mount_lock);
68272+
68273+ BUG_ON(retval == NULL);
68274+
68275+ return retval;
68276+}
68277+
68278+void
68279+assign_special_role(const char *rolename)
68280+{
68281+ struct acl_object_label *obj;
68282+ struct acl_role_label *r;
68283+ struct acl_role_label *assigned = NULL;
68284+ struct task_struct *tsk;
68285+ struct file *filp;
68286+
68287+ FOR_EACH_ROLE_START(r)
68288+ if (!strcmp(rolename, r->rolename) &&
68289+ (r->roletype & GR_ROLE_SPECIAL)) {
68290+ assigned = r;
68291+ break;
68292+ }
68293+ FOR_EACH_ROLE_END(r)
68294+
68295+ if (!assigned)
68296+ return;
68297+
68298+ read_lock(&tasklist_lock);
68299+ read_lock(&grsec_exec_file_lock);
68300+
68301+ tsk = current->real_parent;
68302+ if (tsk == NULL)
68303+ goto out_unlock;
68304+
68305+ filp = tsk->exec_file;
68306+ if (filp == NULL)
68307+ goto out_unlock;
68308+
68309+ tsk->is_writable = 0;
68310+ tsk->inherited = 0;
68311+
68312+ tsk->acl_sp_role = 1;
68313+ tsk->acl_role_id = ++acl_sp_role_value;
68314+ tsk->role = assigned;
68315+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68316+
68317+ /* ignore additional mmap checks for processes that are writable
68318+ by the default ACL */
68319+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68320+ if (unlikely(obj->mode & GR_WRITE))
68321+ tsk->is_writable = 1;
68322+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68323+ if (unlikely(obj->mode & GR_WRITE))
68324+ tsk->is_writable = 1;
68325+
68326+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68327+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68328+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68329+#endif
68330+
68331+out_unlock:
68332+ read_unlock(&grsec_exec_file_lock);
68333+ read_unlock(&tasklist_lock);
68334+ return;
68335+}
68336+
68337+
68338+static void
68339+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68340+{
68341+ struct task_struct *task = current;
68342+ const struct cred *cred = current_cred();
68343+
68344+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68345+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68346+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68347+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68348+
68349+ return;
68350+}
68351+
68352+static void
68353+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68354+{
68355+ struct task_struct *task = current;
68356+ const struct cred *cred = current_cred();
68357+
68358+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68359+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68360+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68361+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68362+
68363+ return;
68364+}
68365+
68366+static void
68367+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68368+{
68369+ struct task_struct *task = current;
68370+ const struct cred *cred = current_cred();
68371+
68372+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68373+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68374+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68375+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68376+
68377+ return;
68378+}
68379+
68380+static void
68381+gr_set_proc_res(struct task_struct *task)
68382+{
68383+ struct acl_subject_label *proc;
68384+ unsigned short i;
68385+
68386+ proc = task->acl;
68387+
68388+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68389+ return;
68390+
68391+ for (i = 0; i < RLIM_NLIMITS; i++) {
68392+ if (!(proc->resmask & (1U << i)))
68393+ continue;
68394+
68395+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68396+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68397+
68398+ if (i == RLIMIT_CPU)
68399+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
68400+ }
68401+
68402+ return;
68403+}
68404+
68405+/* both of the below must be called with
68406+ rcu_read_lock();
68407+ read_lock(&tasklist_lock);
68408+ read_lock(&grsec_exec_file_lock);
68409+*/
68410+
68411+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68412+{
68413+ char *tmpname;
68414+ struct acl_subject_label *tmpsubj;
68415+ struct file *filp;
68416+ struct name_entry *nmatch;
68417+
68418+ filp = task->exec_file;
68419+ if (filp == NULL)
68420+ return NULL;
68421+
68422+ /* the following is to apply the correct subject
68423+ on binaries running when the RBAC system
68424+ is enabled, when the binaries have been
68425+ replaced or deleted since their execution
68426+ -----
68427+ when the RBAC system starts, the inode/dev
68428+ from exec_file will be one the RBAC system
68429+ is unaware of. It only knows the inode/dev
68430+ of the present file on disk, or the absence
68431+ of it.
68432+ */
68433+
68434+ if (filename)
68435+ nmatch = __lookup_name_entry(state, filename);
68436+ else {
68437+ preempt_disable();
68438+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68439+
68440+ nmatch = __lookup_name_entry(state, tmpname);
68441+ preempt_enable();
68442+ }
68443+ tmpsubj = NULL;
68444+ if (nmatch) {
68445+ if (nmatch->deleted)
68446+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68447+ else
68448+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68449+ }
68450+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68451+ then we fall back to a normal lookup based on the binary's ino/dev
68452+ */
68453+ if (tmpsubj == NULL)
68454+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68455+
68456+ return tmpsubj;
68457+}
68458+
68459+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68460+{
68461+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68462+}
68463+
68464+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68465+{
68466+ struct acl_object_label *obj;
68467+ struct file *filp;
68468+
68469+ filp = task->exec_file;
68470+
68471+ task->acl = subj;
68472+ task->is_writable = 0;
68473+ /* ignore additional mmap checks for processes that are writable
68474+ by the default ACL */
68475+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68476+ if (unlikely(obj->mode & GR_WRITE))
68477+ task->is_writable = 1;
68478+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68479+ if (unlikely(obj->mode & GR_WRITE))
68480+ task->is_writable = 1;
68481+
68482+ gr_set_proc_res(task);
68483+
68484+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68485+ 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);
68486+#endif
68487+}
68488+
68489+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68490+{
68491+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68492+}
68493+
68494+__u32
68495+gr_search_file(const struct dentry * dentry, const __u32 mode,
68496+ const struct vfsmount * mnt)
68497+{
68498+ __u32 retval = mode;
68499+ struct acl_subject_label *curracl;
68500+ struct acl_object_label *currobj;
68501+
68502+ if (unlikely(!(gr_status & GR_READY)))
68503+ return (mode & ~GR_AUDITS);
68504+
68505+ curracl = current->acl;
68506+
68507+ currobj = chk_obj_label(dentry, mnt, curracl);
68508+ retval = currobj->mode & mode;
68509+
68510+ /* if we're opening a specified transfer file for writing
68511+ (e.g. /dev/initctl), then transfer our role to init
68512+ */
68513+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68514+ current->role->roletype & GR_ROLE_PERSIST)) {
68515+ struct task_struct *task = init_pid_ns.child_reaper;
68516+
68517+ if (task->role != current->role) {
68518+ struct acl_subject_label *subj;
68519+
68520+ task->acl_sp_role = 0;
68521+ task->acl_role_id = current->acl_role_id;
68522+ task->role = current->role;
68523+ rcu_read_lock();
68524+ read_lock(&grsec_exec_file_lock);
68525+ subj = gr_get_subject_for_task(task, NULL);
68526+ gr_apply_subject_to_task(task, subj);
68527+ read_unlock(&grsec_exec_file_lock);
68528+ rcu_read_unlock();
68529+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68530+ }
68531+ }
68532+
68533+ if (unlikely
68534+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68535+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68536+ __u32 new_mode = mode;
68537+
68538+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68539+
68540+ retval = new_mode;
68541+
68542+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68543+ new_mode |= GR_INHERIT;
68544+
68545+ if (!(mode & GR_NOLEARN))
68546+ gr_log_learn(dentry, mnt, new_mode);
68547+ }
68548+
68549+ return retval;
68550+}
68551+
68552+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68553+ const struct dentry *parent,
68554+ const struct vfsmount *mnt)
68555+{
68556+ struct name_entry *match;
68557+ struct acl_object_label *matchpo;
68558+ struct acl_subject_label *curracl;
68559+ char *path;
68560+
68561+ if (unlikely(!(gr_status & GR_READY)))
68562+ return NULL;
68563+
68564+ preempt_disable();
68565+ path = gr_to_filename_rbac(new_dentry, mnt);
68566+ match = lookup_name_entry_create(path);
68567+
68568+ curracl = current->acl;
68569+
68570+ if (match) {
68571+ read_lock(&gr_inode_lock);
68572+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68573+ read_unlock(&gr_inode_lock);
68574+
68575+ if (matchpo) {
68576+ preempt_enable();
68577+ return matchpo;
68578+ }
68579+ }
68580+
68581+ // lookup parent
68582+
68583+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68584+
68585+ preempt_enable();
68586+ return matchpo;
68587+}
68588+
68589+__u32
68590+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68591+ const struct vfsmount * mnt, const __u32 mode)
68592+{
68593+ struct acl_object_label *matchpo;
68594+ __u32 retval;
68595+
68596+ if (unlikely(!(gr_status & GR_READY)))
68597+ return (mode & ~GR_AUDITS);
68598+
68599+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68600+
68601+ retval = matchpo->mode & mode;
68602+
68603+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68604+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68605+ __u32 new_mode = mode;
68606+
68607+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68608+
68609+ gr_log_learn(new_dentry, mnt, new_mode);
68610+ return new_mode;
68611+ }
68612+
68613+ return retval;
68614+}
68615+
68616+__u32
68617+gr_check_link(const struct dentry * new_dentry,
68618+ const struct dentry * parent_dentry,
68619+ const struct vfsmount * parent_mnt,
68620+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68621+{
68622+ struct acl_object_label *obj;
68623+ __u32 oldmode, newmode;
68624+ __u32 needmode;
68625+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68626+ GR_DELETE | GR_INHERIT;
68627+
68628+ if (unlikely(!(gr_status & GR_READY)))
68629+ return (GR_CREATE | GR_LINK);
68630+
68631+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68632+ oldmode = obj->mode;
68633+
68634+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68635+ newmode = obj->mode;
68636+
68637+ needmode = newmode & checkmodes;
68638+
68639+ // old name for hardlink must have at least the permissions of the new name
68640+ if ((oldmode & needmode) != needmode)
68641+ goto bad;
68642+
68643+ // if old name had restrictions/auditing, make sure the new name does as well
68644+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68645+
68646+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68647+ if (is_privileged_binary(old_dentry))
68648+ needmode |= GR_SETID;
68649+
68650+ if ((newmode & needmode) != needmode)
68651+ goto bad;
68652+
68653+ // enforce minimum permissions
68654+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68655+ return newmode;
68656+bad:
68657+ needmode = oldmode;
68658+ if (is_privileged_binary(old_dentry))
68659+ needmode |= GR_SETID;
68660+
68661+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68662+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68663+ return (GR_CREATE | GR_LINK);
68664+ } else if (newmode & GR_SUPPRESS)
68665+ return GR_SUPPRESS;
68666+ else
68667+ return 0;
68668+}
68669+
68670+int
68671+gr_check_hidden_task(const struct task_struct *task)
68672+{
68673+ if (unlikely(!(gr_status & GR_READY)))
68674+ return 0;
68675+
68676+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68677+ return 1;
68678+
68679+ return 0;
68680+}
68681+
68682+int
68683+gr_check_protected_task(const struct task_struct *task)
68684+{
68685+ if (unlikely(!(gr_status & GR_READY) || !task))
68686+ return 0;
68687+
68688+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68689+ task->acl != current->acl)
68690+ return 1;
68691+
68692+ return 0;
68693+}
68694+
68695+int
68696+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68697+{
68698+ struct task_struct *p;
68699+ int ret = 0;
68700+
68701+ if (unlikely(!(gr_status & GR_READY) || !pid))
68702+ return ret;
68703+
68704+ read_lock(&tasklist_lock);
68705+ do_each_pid_task(pid, type, p) {
68706+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68707+ p->acl != current->acl) {
68708+ ret = 1;
68709+ goto out;
68710+ }
68711+ } while_each_pid_task(pid, type, p);
68712+out:
68713+ read_unlock(&tasklist_lock);
68714+
68715+ return ret;
68716+}
68717+
68718+void
68719+gr_copy_label(struct task_struct *tsk)
68720+{
68721+ struct task_struct *p = current;
68722+
68723+ tsk->inherited = p->inherited;
68724+ tsk->acl_sp_role = 0;
68725+ tsk->acl_role_id = p->acl_role_id;
68726+ tsk->acl = p->acl;
68727+ tsk->role = p->role;
68728+ tsk->signal->used_accept = 0;
68729+ tsk->signal->curr_ip = p->signal->curr_ip;
68730+ tsk->signal->saved_ip = p->signal->saved_ip;
68731+ if (p->exec_file)
68732+ get_file(p->exec_file);
68733+ tsk->exec_file = p->exec_file;
68734+ tsk->is_writable = p->is_writable;
68735+ if (unlikely(p->signal->used_accept)) {
68736+ p->signal->curr_ip = 0;
68737+ p->signal->saved_ip = 0;
68738+ }
68739+
68740+ return;
68741+}
68742+
68743+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68744+
68745+int
68746+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68747+{
68748+ unsigned int i;
68749+ __u16 num;
68750+ uid_t *uidlist;
68751+ uid_t curuid;
68752+ int realok = 0;
68753+ int effectiveok = 0;
68754+ int fsok = 0;
68755+ uid_t globalreal, globaleffective, globalfs;
68756+
68757+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68758+ struct user_struct *user;
68759+
68760+ if (!uid_valid(real))
68761+ goto skipit;
68762+
68763+ /* find user based on global namespace */
68764+
68765+ globalreal = GR_GLOBAL_UID(real);
68766+
68767+ user = find_user(make_kuid(&init_user_ns, globalreal));
68768+ if (user == NULL)
68769+ goto skipit;
68770+
68771+ if (gr_process_kernel_setuid_ban(user)) {
68772+ /* for find_user */
68773+ free_uid(user);
68774+ return 1;
68775+ }
68776+
68777+ /* for find_user */
68778+ free_uid(user);
68779+
68780+skipit:
68781+#endif
68782+
68783+ if (unlikely(!(gr_status & GR_READY)))
68784+ return 0;
68785+
68786+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68787+ gr_log_learn_uid_change(real, effective, fs);
68788+
68789+ num = current->acl->user_trans_num;
68790+ uidlist = current->acl->user_transitions;
68791+
68792+ if (uidlist == NULL)
68793+ return 0;
68794+
68795+ if (!uid_valid(real)) {
68796+ realok = 1;
68797+ globalreal = (uid_t)-1;
68798+ } else {
68799+ globalreal = GR_GLOBAL_UID(real);
68800+ }
68801+ if (!uid_valid(effective)) {
68802+ effectiveok = 1;
68803+ globaleffective = (uid_t)-1;
68804+ } else {
68805+ globaleffective = GR_GLOBAL_UID(effective);
68806+ }
68807+ if (!uid_valid(fs)) {
68808+ fsok = 1;
68809+ globalfs = (uid_t)-1;
68810+ } else {
68811+ globalfs = GR_GLOBAL_UID(fs);
68812+ }
68813+
68814+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68815+ for (i = 0; i < num; i++) {
68816+ curuid = uidlist[i];
68817+ if (globalreal == curuid)
68818+ realok = 1;
68819+ if (globaleffective == curuid)
68820+ effectiveok = 1;
68821+ if (globalfs == curuid)
68822+ fsok = 1;
68823+ }
68824+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68825+ for (i = 0; i < num; i++) {
68826+ curuid = uidlist[i];
68827+ if (globalreal == curuid)
68828+ break;
68829+ if (globaleffective == curuid)
68830+ break;
68831+ if (globalfs == curuid)
68832+ break;
68833+ }
68834+ /* not in deny list */
68835+ if (i == num) {
68836+ realok = 1;
68837+ effectiveok = 1;
68838+ fsok = 1;
68839+ }
68840+ }
68841+
68842+ if (realok && effectiveok && fsok)
68843+ return 0;
68844+ else {
68845+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68846+ return 1;
68847+ }
68848+}
68849+
68850+int
68851+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68852+{
68853+ unsigned int i;
68854+ __u16 num;
68855+ gid_t *gidlist;
68856+ gid_t curgid;
68857+ int realok = 0;
68858+ int effectiveok = 0;
68859+ int fsok = 0;
68860+ gid_t globalreal, globaleffective, globalfs;
68861+
68862+ if (unlikely(!(gr_status & GR_READY)))
68863+ return 0;
68864+
68865+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68866+ gr_log_learn_gid_change(real, effective, fs);
68867+
68868+ num = current->acl->group_trans_num;
68869+ gidlist = current->acl->group_transitions;
68870+
68871+ if (gidlist == NULL)
68872+ return 0;
68873+
68874+ if (!gid_valid(real)) {
68875+ realok = 1;
68876+ globalreal = (gid_t)-1;
68877+ } else {
68878+ globalreal = GR_GLOBAL_GID(real);
68879+ }
68880+ if (!gid_valid(effective)) {
68881+ effectiveok = 1;
68882+ globaleffective = (gid_t)-1;
68883+ } else {
68884+ globaleffective = GR_GLOBAL_GID(effective);
68885+ }
68886+ if (!gid_valid(fs)) {
68887+ fsok = 1;
68888+ globalfs = (gid_t)-1;
68889+ } else {
68890+ globalfs = GR_GLOBAL_GID(fs);
68891+ }
68892+
68893+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68894+ for (i = 0; i < num; i++) {
68895+ curgid = gidlist[i];
68896+ if (globalreal == curgid)
68897+ realok = 1;
68898+ if (globaleffective == curgid)
68899+ effectiveok = 1;
68900+ if (globalfs == curgid)
68901+ fsok = 1;
68902+ }
68903+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68904+ for (i = 0; i < num; i++) {
68905+ curgid = gidlist[i];
68906+ if (globalreal == curgid)
68907+ break;
68908+ if (globaleffective == curgid)
68909+ break;
68910+ if (globalfs == curgid)
68911+ break;
68912+ }
68913+ /* not in deny list */
68914+ if (i == num) {
68915+ realok = 1;
68916+ effectiveok = 1;
68917+ fsok = 1;
68918+ }
68919+ }
68920+
68921+ if (realok && effectiveok && fsok)
68922+ return 0;
68923+ else {
68924+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68925+ return 1;
68926+ }
68927+}
68928+
68929+extern int gr_acl_is_capable(const int cap);
68930+
68931+void
68932+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68933+{
68934+ struct acl_role_label *role = task->role;
68935+ struct acl_subject_label *subj = NULL;
68936+ struct acl_object_label *obj;
68937+ struct file *filp;
68938+ uid_t uid;
68939+ gid_t gid;
68940+
68941+ if (unlikely(!(gr_status & GR_READY)))
68942+ return;
68943+
68944+ uid = GR_GLOBAL_UID(kuid);
68945+ gid = GR_GLOBAL_GID(kgid);
68946+
68947+ filp = task->exec_file;
68948+
68949+ /* kernel process, we'll give them the kernel role */
68950+ if (unlikely(!filp)) {
68951+ task->role = running_polstate.kernel_role;
68952+ task->acl = running_polstate.kernel_role->root_label;
68953+ return;
68954+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68955+ /* save the current ip at time of role lookup so that the proper
68956+ IP will be learned for role_allowed_ip */
68957+ task->signal->saved_ip = task->signal->curr_ip;
68958+ role = lookup_acl_role_label(task, uid, gid);
68959+ }
68960+
68961+ /* don't change the role if we're not a privileged process */
68962+ if (role && task->role != role &&
68963+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68964+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68965+ return;
68966+
68967+ /* perform subject lookup in possibly new role
68968+ we can use this result below in the case where role == task->role
68969+ */
68970+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68971+
68972+ /* if we changed uid/gid, but result in the same role
68973+ and are using inheritance, don't lose the inherited subject
68974+ if current subject is other than what normal lookup
68975+ would result in, we arrived via inheritance, don't
68976+ lose subject
68977+ */
68978+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68979+ (subj == task->acl)))
68980+ task->acl = subj;
68981+
68982+ /* leave task->inherited unaffected */
68983+
68984+ task->role = role;
68985+
68986+ task->is_writable = 0;
68987+
68988+ /* ignore additional mmap checks for processes that are writable
68989+ by the default ACL */
68990+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68991+ if (unlikely(obj->mode & GR_WRITE))
68992+ task->is_writable = 1;
68993+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68994+ if (unlikely(obj->mode & GR_WRITE))
68995+ task->is_writable = 1;
68996+
68997+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68998+ 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);
68999+#endif
69000+
69001+ gr_set_proc_res(task);
69002+
69003+ return;
69004+}
69005+
69006+int
69007+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
69008+ const int unsafe_flags)
69009+{
69010+ struct task_struct *task = current;
69011+ struct acl_subject_label *newacl;
69012+ struct acl_object_label *obj;
69013+ __u32 retmode;
69014+
69015+ if (unlikely(!(gr_status & GR_READY)))
69016+ return 0;
69017+
69018+ newacl = chk_subj_label(dentry, mnt, task->role);
69019+
69020+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
69021+ did an exec
69022+ */
69023+ rcu_read_lock();
69024+ read_lock(&tasklist_lock);
69025+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
69026+ (task->parent->acl->mode & GR_POVERRIDE))) {
69027+ read_unlock(&tasklist_lock);
69028+ rcu_read_unlock();
69029+ goto skip_check;
69030+ }
69031+ read_unlock(&tasklist_lock);
69032+ rcu_read_unlock();
69033+
69034+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
69035+ !(task->role->roletype & GR_ROLE_GOD) &&
69036+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
69037+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
69038+ if (unsafe_flags & LSM_UNSAFE_SHARE)
69039+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
69040+ else
69041+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
69042+ return -EACCES;
69043+ }
69044+
69045+skip_check:
69046+
69047+ obj = chk_obj_label(dentry, mnt, task->acl);
69048+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
69049+
69050+ if (!(task->acl->mode & GR_INHERITLEARN) &&
69051+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
69052+ if (obj->nested)
69053+ task->acl = obj->nested;
69054+ else
69055+ task->acl = newacl;
69056+ task->inherited = 0;
69057+ } else {
69058+ task->inherited = 1;
69059+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
69060+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
69061+ }
69062+
69063+ task->is_writable = 0;
69064+
69065+ /* ignore additional mmap checks for processes that are writable
69066+ by the default ACL */
69067+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
69068+ if (unlikely(obj->mode & GR_WRITE))
69069+ task->is_writable = 1;
69070+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
69071+ if (unlikely(obj->mode & GR_WRITE))
69072+ task->is_writable = 1;
69073+
69074+ gr_set_proc_res(task);
69075+
69076+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69077+ 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);
69078+#endif
69079+ return 0;
69080+}
69081+
69082+/* always called with valid inodev ptr */
69083+static void
69084+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
69085+{
69086+ struct acl_object_label *matchpo;
69087+ struct acl_subject_label *matchps;
69088+ struct acl_subject_label *subj;
69089+ struct acl_role_label *role;
69090+ unsigned int x;
69091+
69092+ FOR_EACH_ROLE_START(role)
69093+ FOR_EACH_SUBJECT_START(role, subj, x)
69094+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69095+ matchpo->mode |= GR_DELETED;
69096+ FOR_EACH_SUBJECT_END(subj,x)
69097+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69098+ /* nested subjects aren't in the role's subj_hash table */
69099+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69100+ matchpo->mode |= GR_DELETED;
69101+ FOR_EACH_NESTED_SUBJECT_END(subj)
69102+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
69103+ matchps->mode |= GR_DELETED;
69104+ FOR_EACH_ROLE_END(role)
69105+
69106+ inodev->nentry->deleted = 1;
69107+
69108+ return;
69109+}
69110+
69111+void
69112+gr_handle_delete(const ino_t ino, const dev_t dev)
69113+{
69114+ struct inodev_entry *inodev;
69115+
69116+ if (unlikely(!(gr_status & GR_READY)))
69117+ return;
69118+
69119+ write_lock(&gr_inode_lock);
69120+ inodev = lookup_inodev_entry(ino, dev);
69121+ if (inodev != NULL)
69122+ do_handle_delete(inodev, ino, dev);
69123+ write_unlock(&gr_inode_lock);
69124+
69125+ return;
69126+}
69127+
69128+static void
69129+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69130+ const ino_t newinode, const dev_t newdevice,
69131+ struct acl_subject_label *subj)
69132+{
69133+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69134+ struct acl_object_label *match;
69135+
69136+ match = subj->obj_hash[index];
69137+
69138+ while (match && (match->inode != oldinode ||
69139+ match->device != olddevice ||
69140+ !(match->mode & GR_DELETED)))
69141+ match = match->next;
69142+
69143+ if (match && (match->inode == oldinode)
69144+ && (match->device == olddevice)
69145+ && (match->mode & GR_DELETED)) {
69146+ if (match->prev == NULL) {
69147+ subj->obj_hash[index] = match->next;
69148+ if (match->next != NULL)
69149+ match->next->prev = NULL;
69150+ } else {
69151+ match->prev->next = match->next;
69152+ if (match->next != NULL)
69153+ match->next->prev = match->prev;
69154+ }
69155+ match->prev = NULL;
69156+ match->next = NULL;
69157+ match->inode = newinode;
69158+ match->device = newdevice;
69159+ match->mode &= ~GR_DELETED;
69160+
69161+ insert_acl_obj_label(match, subj);
69162+ }
69163+
69164+ return;
69165+}
69166+
69167+static void
69168+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69169+ const ino_t newinode, const dev_t newdevice,
69170+ struct acl_role_label *role)
69171+{
69172+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69173+ struct acl_subject_label *match;
69174+
69175+ match = role->subj_hash[index];
69176+
69177+ while (match && (match->inode != oldinode ||
69178+ match->device != olddevice ||
69179+ !(match->mode & GR_DELETED)))
69180+ match = match->next;
69181+
69182+ if (match && (match->inode == oldinode)
69183+ && (match->device == olddevice)
69184+ && (match->mode & GR_DELETED)) {
69185+ if (match->prev == NULL) {
69186+ role->subj_hash[index] = match->next;
69187+ if (match->next != NULL)
69188+ match->next->prev = NULL;
69189+ } else {
69190+ match->prev->next = match->next;
69191+ if (match->next != NULL)
69192+ match->next->prev = match->prev;
69193+ }
69194+ match->prev = NULL;
69195+ match->next = NULL;
69196+ match->inode = newinode;
69197+ match->device = newdevice;
69198+ match->mode &= ~GR_DELETED;
69199+
69200+ insert_acl_subj_label(match, role);
69201+ }
69202+
69203+ return;
69204+}
69205+
69206+static void
69207+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69208+ const ino_t newinode, const dev_t newdevice)
69209+{
69210+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69211+ struct inodev_entry *match;
69212+
69213+ match = running_polstate.inodev_set.i_hash[index];
69214+
69215+ while (match && (match->nentry->inode != oldinode ||
69216+ match->nentry->device != olddevice || !match->nentry->deleted))
69217+ match = match->next;
69218+
69219+ if (match && (match->nentry->inode == oldinode)
69220+ && (match->nentry->device == olddevice) &&
69221+ match->nentry->deleted) {
69222+ if (match->prev == NULL) {
69223+ running_polstate.inodev_set.i_hash[index] = match->next;
69224+ if (match->next != NULL)
69225+ match->next->prev = NULL;
69226+ } else {
69227+ match->prev->next = match->next;
69228+ if (match->next != NULL)
69229+ match->next->prev = match->prev;
69230+ }
69231+ match->prev = NULL;
69232+ match->next = NULL;
69233+ match->nentry->inode = newinode;
69234+ match->nentry->device = newdevice;
69235+ match->nentry->deleted = 0;
69236+
69237+ insert_inodev_entry(match);
69238+ }
69239+
69240+ return;
69241+}
69242+
69243+static void
69244+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69245+{
69246+ struct acl_subject_label *subj;
69247+ struct acl_role_label *role;
69248+ unsigned int x;
69249+
69250+ FOR_EACH_ROLE_START(role)
69251+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69252+
69253+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69254+ if ((subj->inode == ino) && (subj->device == dev)) {
69255+ subj->inode = ino;
69256+ subj->device = dev;
69257+ }
69258+ /* nested subjects aren't in the role's subj_hash table */
69259+ update_acl_obj_label(matchn->inode, matchn->device,
69260+ ino, dev, subj);
69261+ FOR_EACH_NESTED_SUBJECT_END(subj)
69262+ FOR_EACH_SUBJECT_START(role, subj, x)
69263+ update_acl_obj_label(matchn->inode, matchn->device,
69264+ ino, dev, subj);
69265+ FOR_EACH_SUBJECT_END(subj,x)
69266+ FOR_EACH_ROLE_END(role)
69267+
69268+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69269+
69270+ return;
69271+}
69272+
69273+static void
69274+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69275+ const struct vfsmount *mnt)
69276+{
69277+ ino_t ino = dentry->d_inode->i_ino;
69278+ dev_t dev = __get_dev(dentry);
69279+
69280+ __do_handle_create(matchn, ino, dev);
69281+
69282+ return;
69283+}
69284+
69285+void
69286+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69287+{
69288+ struct name_entry *matchn;
69289+
69290+ if (unlikely(!(gr_status & GR_READY)))
69291+ return;
69292+
69293+ preempt_disable();
69294+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69295+
69296+ if (unlikely((unsigned long)matchn)) {
69297+ write_lock(&gr_inode_lock);
69298+ do_handle_create(matchn, dentry, mnt);
69299+ write_unlock(&gr_inode_lock);
69300+ }
69301+ preempt_enable();
69302+
69303+ return;
69304+}
69305+
69306+void
69307+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69308+{
69309+ struct name_entry *matchn;
69310+
69311+ if (unlikely(!(gr_status & GR_READY)))
69312+ return;
69313+
69314+ preempt_disable();
69315+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69316+
69317+ if (unlikely((unsigned long)matchn)) {
69318+ write_lock(&gr_inode_lock);
69319+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69320+ write_unlock(&gr_inode_lock);
69321+ }
69322+ preempt_enable();
69323+
69324+ return;
69325+}
69326+
69327+void
69328+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69329+ struct dentry *old_dentry,
69330+ struct dentry *new_dentry,
69331+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
69332+{
69333+ struct name_entry *matchn;
69334+ struct name_entry *matchn2 = NULL;
69335+ struct inodev_entry *inodev;
69336+ struct inode *inode = new_dentry->d_inode;
69337+ ino_t old_ino = old_dentry->d_inode->i_ino;
69338+ dev_t old_dev = __get_dev(old_dentry);
69339+ unsigned int exchange = flags & RENAME_EXCHANGE;
69340+
69341+ /* vfs_rename swaps the name and parent link for old_dentry and
69342+ new_dentry
69343+ at this point, old_dentry has the new name, parent link, and inode
69344+ for the renamed file
69345+ if a file is being replaced by a rename, new_dentry has the inode
69346+ and name for the replaced file
69347+ */
69348+
69349+ if (unlikely(!(gr_status & GR_READY)))
69350+ return;
69351+
69352+ preempt_disable();
69353+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69354+
69355+ /* exchange cases:
69356+ a filename exists for the source, but not dest
69357+ do a recreate on source
69358+ a filename exists for the dest, but not source
69359+ do a recreate on dest
69360+ a filename exists for both source and dest
69361+ delete source and dest, then create source and dest
69362+ a filename exists for neither source nor dest
69363+ no updates needed
69364+
69365+ the name entry lookups get us the old inode/dev associated with
69366+ each name, so do the deletes first (if possible) so that when
69367+ we do the create, we pick up on the right entries
69368+ */
69369+
69370+ if (exchange)
69371+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
69372+
69373+ /* we wouldn't have to check d_inode if it weren't for
69374+ NFS silly-renaming
69375+ */
69376+
69377+ write_lock(&gr_inode_lock);
69378+ if (unlikely((replace || exchange) && inode)) {
69379+ ino_t new_ino = inode->i_ino;
69380+ dev_t new_dev = __get_dev(new_dentry);
69381+
69382+ inodev = lookup_inodev_entry(new_ino, new_dev);
69383+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69384+ do_handle_delete(inodev, new_ino, new_dev);
69385+ }
69386+
69387+ inodev = lookup_inodev_entry(old_ino, old_dev);
69388+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69389+ do_handle_delete(inodev, old_ino, old_dev);
69390+
69391+ if (unlikely(matchn != NULL))
69392+ do_handle_create(matchn, old_dentry, mnt);
69393+
69394+ if (unlikely(matchn2 != NULL))
69395+ do_handle_create(matchn2, new_dentry, mnt);
69396+
69397+ write_unlock(&gr_inode_lock);
69398+ preempt_enable();
69399+
69400+ return;
69401+}
69402+
69403+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69404+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69405+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69406+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69407+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69408+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69409+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69410+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69411+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69412+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69413+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69414+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69415+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69416+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69417+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69418+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69419+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69420+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69421+};
69422+
69423+void
69424+gr_learn_resource(const struct task_struct *task,
69425+ const int res, const unsigned long wanted, const int gt)
69426+{
69427+ struct acl_subject_label *acl;
69428+ const struct cred *cred;
69429+
69430+ if (unlikely((gr_status & GR_READY) &&
69431+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69432+ goto skip_reslog;
69433+
69434+ gr_log_resource(task, res, wanted, gt);
69435+skip_reslog:
69436+
69437+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69438+ return;
69439+
69440+ acl = task->acl;
69441+
69442+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69443+ !(acl->resmask & (1U << (unsigned short) res))))
69444+ return;
69445+
69446+ if (wanted >= acl->res[res].rlim_cur) {
69447+ unsigned long res_add;
69448+
69449+ res_add = wanted + res_learn_bumps[res];
69450+
69451+ acl->res[res].rlim_cur = res_add;
69452+
69453+ if (wanted > acl->res[res].rlim_max)
69454+ acl->res[res].rlim_max = res_add;
69455+
69456+ /* only log the subject filename, since resource logging is supported for
69457+ single-subject learning only */
69458+ rcu_read_lock();
69459+ cred = __task_cred(task);
69460+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69461+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69462+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69463+ "", (unsigned long) res, &task->signal->saved_ip);
69464+ rcu_read_unlock();
69465+ }
69466+
69467+ return;
69468+}
69469+EXPORT_SYMBOL_GPL(gr_learn_resource);
69470+#endif
69471+
69472+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69473+void
69474+pax_set_initial_flags(struct linux_binprm *bprm)
69475+{
69476+ struct task_struct *task = current;
69477+ struct acl_subject_label *proc;
69478+ unsigned long flags;
69479+
69480+ if (unlikely(!(gr_status & GR_READY)))
69481+ return;
69482+
69483+ flags = pax_get_flags(task);
69484+
69485+ proc = task->acl;
69486+
69487+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69488+ flags &= ~MF_PAX_PAGEEXEC;
69489+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69490+ flags &= ~MF_PAX_SEGMEXEC;
69491+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69492+ flags &= ~MF_PAX_RANDMMAP;
69493+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69494+ flags &= ~MF_PAX_EMUTRAMP;
69495+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69496+ flags &= ~MF_PAX_MPROTECT;
69497+
69498+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69499+ flags |= MF_PAX_PAGEEXEC;
69500+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69501+ flags |= MF_PAX_SEGMEXEC;
69502+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69503+ flags |= MF_PAX_RANDMMAP;
69504+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69505+ flags |= MF_PAX_EMUTRAMP;
69506+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69507+ flags |= MF_PAX_MPROTECT;
69508+
69509+ pax_set_flags(task, flags);
69510+
69511+ return;
69512+}
69513+#endif
69514+
69515+int
69516+gr_handle_proc_ptrace(struct task_struct *task)
69517+{
69518+ struct file *filp;
69519+ struct task_struct *tmp = task;
69520+ struct task_struct *curtemp = current;
69521+ __u32 retmode;
69522+
69523+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69524+ if (unlikely(!(gr_status & GR_READY)))
69525+ return 0;
69526+#endif
69527+
69528+ read_lock(&tasklist_lock);
69529+ read_lock(&grsec_exec_file_lock);
69530+ filp = task->exec_file;
69531+
69532+ while (task_pid_nr(tmp) > 0) {
69533+ if (tmp == curtemp)
69534+ break;
69535+ tmp = tmp->real_parent;
69536+ }
69537+
69538+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69539+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69540+ read_unlock(&grsec_exec_file_lock);
69541+ read_unlock(&tasklist_lock);
69542+ return 1;
69543+ }
69544+
69545+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69546+ if (!(gr_status & GR_READY)) {
69547+ read_unlock(&grsec_exec_file_lock);
69548+ read_unlock(&tasklist_lock);
69549+ return 0;
69550+ }
69551+#endif
69552+
69553+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69554+ read_unlock(&grsec_exec_file_lock);
69555+ read_unlock(&tasklist_lock);
69556+
69557+ if (retmode & GR_NOPTRACE)
69558+ return 1;
69559+
69560+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69561+ && (current->acl != task->acl || (current->acl != current->role->root_label
69562+ && task_pid_nr(current) != task_pid_nr(task))))
69563+ return 1;
69564+
69565+ return 0;
69566+}
69567+
69568+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69569+{
69570+ if (unlikely(!(gr_status & GR_READY)))
69571+ return;
69572+
69573+ if (!(current->role->roletype & GR_ROLE_GOD))
69574+ return;
69575+
69576+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69577+ p->role->rolename, gr_task_roletype_to_char(p),
69578+ p->acl->filename);
69579+}
69580+
69581+int
69582+gr_handle_ptrace(struct task_struct *task, const long request)
69583+{
69584+ struct task_struct *tmp = task;
69585+ struct task_struct *curtemp = current;
69586+ __u32 retmode;
69587+
69588+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69589+ if (unlikely(!(gr_status & GR_READY)))
69590+ return 0;
69591+#endif
69592+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69593+ read_lock(&tasklist_lock);
69594+ while (task_pid_nr(tmp) > 0) {
69595+ if (tmp == curtemp)
69596+ break;
69597+ tmp = tmp->real_parent;
69598+ }
69599+
69600+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69601+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69602+ read_unlock(&tasklist_lock);
69603+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69604+ return 1;
69605+ }
69606+ read_unlock(&tasklist_lock);
69607+ }
69608+
69609+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69610+ if (!(gr_status & GR_READY))
69611+ return 0;
69612+#endif
69613+
69614+ read_lock(&grsec_exec_file_lock);
69615+ if (unlikely(!task->exec_file)) {
69616+ read_unlock(&grsec_exec_file_lock);
69617+ return 0;
69618+ }
69619+
69620+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69621+ read_unlock(&grsec_exec_file_lock);
69622+
69623+ if (retmode & GR_NOPTRACE) {
69624+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69625+ return 1;
69626+ }
69627+
69628+ if (retmode & GR_PTRACERD) {
69629+ switch (request) {
69630+ case PTRACE_SEIZE:
69631+ case PTRACE_POKETEXT:
69632+ case PTRACE_POKEDATA:
69633+ case PTRACE_POKEUSR:
69634+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69635+ case PTRACE_SETREGS:
69636+ case PTRACE_SETFPREGS:
69637+#endif
69638+#ifdef CONFIG_X86
69639+ case PTRACE_SETFPXREGS:
69640+#endif
69641+#ifdef CONFIG_ALTIVEC
69642+ case PTRACE_SETVRREGS:
69643+#endif
69644+ return 1;
69645+ default:
69646+ return 0;
69647+ }
69648+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69649+ !(current->role->roletype & GR_ROLE_GOD) &&
69650+ (current->acl != task->acl)) {
69651+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69652+ return 1;
69653+ }
69654+
69655+ return 0;
69656+}
69657+
69658+static int is_writable_mmap(const struct file *filp)
69659+{
69660+ struct task_struct *task = current;
69661+ struct acl_object_label *obj, *obj2;
69662+
69663+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69664+ !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))) {
69665+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69666+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69667+ task->role->root_label);
69668+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69669+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69670+ return 1;
69671+ }
69672+ }
69673+ return 0;
69674+}
69675+
69676+int
69677+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69678+{
69679+ __u32 mode;
69680+
69681+ if (unlikely(!file || !(prot & PROT_EXEC)))
69682+ return 1;
69683+
69684+ if (is_writable_mmap(file))
69685+ return 0;
69686+
69687+ mode =
69688+ gr_search_file(file->f_path.dentry,
69689+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69690+ file->f_path.mnt);
69691+
69692+ if (!gr_tpe_allow(file))
69693+ return 0;
69694+
69695+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69696+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69697+ return 0;
69698+ } else if (unlikely(!(mode & GR_EXEC))) {
69699+ return 0;
69700+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69701+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69702+ return 1;
69703+ }
69704+
69705+ return 1;
69706+}
69707+
69708+int
69709+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69710+{
69711+ __u32 mode;
69712+
69713+ if (unlikely(!file || !(prot & PROT_EXEC)))
69714+ return 1;
69715+
69716+ if (is_writable_mmap(file))
69717+ return 0;
69718+
69719+ mode =
69720+ gr_search_file(file->f_path.dentry,
69721+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69722+ file->f_path.mnt);
69723+
69724+ if (!gr_tpe_allow(file))
69725+ return 0;
69726+
69727+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69728+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69729+ return 0;
69730+ } else if (unlikely(!(mode & GR_EXEC))) {
69731+ return 0;
69732+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69733+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69734+ return 1;
69735+ }
69736+
69737+ return 1;
69738+}
69739+
69740+void
69741+gr_acl_handle_psacct(struct task_struct *task, const long code)
69742+{
69743+ unsigned long runtime, cputime;
69744+ cputime_t utime, stime;
69745+ unsigned int wday, cday;
69746+ __u8 whr, chr;
69747+ __u8 wmin, cmin;
69748+ __u8 wsec, csec;
69749+ struct timespec timeval;
69750+
69751+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69752+ !(task->acl->mode & GR_PROCACCT)))
69753+ return;
69754+
69755+ do_posix_clock_monotonic_gettime(&timeval);
69756+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69757+ wday = runtime / (60 * 60 * 24);
69758+ runtime -= wday * (60 * 60 * 24);
69759+ whr = runtime / (60 * 60);
69760+ runtime -= whr * (60 * 60);
69761+ wmin = runtime / 60;
69762+ runtime -= wmin * 60;
69763+ wsec = runtime;
69764+
69765+ task_cputime(task, &utime, &stime);
69766+ cputime = cputime_to_secs(utime + stime);
69767+ cday = cputime / (60 * 60 * 24);
69768+ cputime -= cday * (60 * 60 * 24);
69769+ chr = cputime / (60 * 60);
69770+ cputime -= chr * (60 * 60);
69771+ cmin = cputime / 60;
69772+ cputime -= cmin * 60;
69773+ csec = cputime;
69774+
69775+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69776+
69777+ return;
69778+}
69779+
69780+#ifdef CONFIG_TASKSTATS
69781+int gr_is_taskstats_denied(int pid)
69782+{
69783+ struct task_struct *task;
69784+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69785+ const struct cred *cred;
69786+#endif
69787+ int ret = 0;
69788+
69789+ /* restrict taskstats viewing to un-chrooted root users
69790+ who have the 'view' subject flag if the RBAC system is enabled
69791+ */
69792+
69793+ rcu_read_lock();
69794+ read_lock(&tasklist_lock);
69795+ task = find_task_by_vpid(pid);
69796+ if (task) {
69797+#ifdef CONFIG_GRKERNSEC_CHROOT
69798+ if (proc_is_chrooted(task))
69799+ ret = -EACCES;
69800+#endif
69801+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69802+ cred = __task_cred(task);
69803+#ifdef CONFIG_GRKERNSEC_PROC_USER
69804+ if (gr_is_global_nonroot(cred->uid))
69805+ ret = -EACCES;
69806+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69807+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69808+ ret = -EACCES;
69809+#endif
69810+#endif
69811+ if (gr_status & GR_READY) {
69812+ if (!(task->acl->mode & GR_VIEW))
69813+ ret = -EACCES;
69814+ }
69815+ } else
69816+ ret = -ENOENT;
69817+
69818+ read_unlock(&tasklist_lock);
69819+ rcu_read_unlock();
69820+
69821+ return ret;
69822+}
69823+#endif
69824+
69825+/* AUXV entries are filled via a descendant of search_binary_handler
69826+ after we've already applied the subject for the target
69827+*/
69828+int gr_acl_enable_at_secure(void)
69829+{
69830+ if (unlikely(!(gr_status & GR_READY)))
69831+ return 0;
69832+
69833+ if (current->acl->mode & GR_ATSECURE)
69834+ return 1;
69835+
69836+ return 0;
69837+}
69838+
69839+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69840+{
69841+ struct task_struct *task = current;
69842+ struct dentry *dentry = file->f_path.dentry;
69843+ struct vfsmount *mnt = file->f_path.mnt;
69844+ struct acl_object_label *obj, *tmp;
69845+ struct acl_subject_label *subj;
69846+ unsigned int bufsize;
69847+ int is_not_root;
69848+ char *path;
69849+ dev_t dev = __get_dev(dentry);
69850+
69851+ if (unlikely(!(gr_status & GR_READY)))
69852+ return 1;
69853+
69854+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69855+ return 1;
69856+
69857+ /* ignore Eric Biederman */
69858+ if (IS_PRIVATE(dentry->d_inode))
69859+ return 1;
69860+
69861+ subj = task->acl;
69862+ read_lock(&gr_inode_lock);
69863+ do {
69864+ obj = lookup_acl_obj_label(ino, dev, subj);
69865+ if (obj != NULL) {
69866+ read_unlock(&gr_inode_lock);
69867+ return (obj->mode & GR_FIND) ? 1 : 0;
69868+ }
69869+ } while ((subj = subj->parent_subject));
69870+ read_unlock(&gr_inode_lock);
69871+
69872+ /* this is purely an optimization since we're looking for an object
69873+ for the directory we're doing a readdir on
69874+ if it's possible for any globbed object to match the entry we're
69875+ filling into the directory, then the object we find here will be
69876+ an anchor point with attached globbed objects
69877+ */
69878+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69879+ if (obj->globbed == NULL)
69880+ return (obj->mode & GR_FIND) ? 1 : 0;
69881+
69882+ is_not_root = ((obj->filename[0] == '/') &&
69883+ (obj->filename[1] == '\0')) ? 0 : 1;
69884+ bufsize = PAGE_SIZE - namelen - is_not_root;
69885+
69886+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69887+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69888+ return 1;
69889+
69890+ preempt_disable();
69891+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69892+ bufsize);
69893+
69894+ bufsize = strlen(path);
69895+
69896+ /* if base is "/", don't append an additional slash */
69897+ if (is_not_root)
69898+ *(path + bufsize) = '/';
69899+ memcpy(path + bufsize + is_not_root, name, namelen);
69900+ *(path + bufsize + namelen + is_not_root) = '\0';
69901+
69902+ tmp = obj->globbed;
69903+ while (tmp) {
69904+ if (!glob_match(tmp->filename, path)) {
69905+ preempt_enable();
69906+ return (tmp->mode & GR_FIND) ? 1 : 0;
69907+ }
69908+ tmp = tmp->next;
69909+ }
69910+ preempt_enable();
69911+ return (obj->mode & GR_FIND) ? 1 : 0;
69912+}
69913+
69914+void gr_put_exec_file(struct task_struct *task)
69915+{
69916+ struct file *filp;
69917+
69918+ write_lock(&grsec_exec_file_lock);
69919+ filp = task->exec_file;
69920+ task->exec_file = NULL;
69921+ write_unlock(&grsec_exec_file_lock);
69922+
69923+ if (filp)
69924+ fput(filp);
69925+
69926+ return;
69927+}
69928+
69929+
69930+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69931+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69932+#endif
69933+#ifdef CONFIG_SECURITY
69934+EXPORT_SYMBOL_GPL(gr_check_user_change);
69935+EXPORT_SYMBOL_GPL(gr_check_group_change);
69936+#endif
69937+
69938diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69939new file mode 100644
69940index 0000000..18ffbbd
69941--- /dev/null
69942+++ b/grsecurity/gracl_alloc.c
69943@@ -0,0 +1,105 @@
69944+#include <linux/kernel.h>
69945+#include <linux/mm.h>
69946+#include <linux/slab.h>
69947+#include <linux/vmalloc.h>
69948+#include <linux/gracl.h>
69949+#include <linux/grsecurity.h>
69950+
69951+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69952+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69953+
69954+static __inline__ int
69955+alloc_pop(void)
69956+{
69957+ if (current_alloc_state->alloc_stack_next == 1)
69958+ return 0;
69959+
69960+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69961+
69962+ current_alloc_state->alloc_stack_next--;
69963+
69964+ return 1;
69965+}
69966+
69967+static __inline__ int
69968+alloc_push(void *buf)
69969+{
69970+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69971+ return 1;
69972+
69973+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69974+
69975+ current_alloc_state->alloc_stack_next++;
69976+
69977+ return 0;
69978+}
69979+
69980+void *
69981+acl_alloc(unsigned long len)
69982+{
69983+ void *ret = NULL;
69984+
69985+ if (!len || len > PAGE_SIZE)
69986+ goto out;
69987+
69988+ ret = kmalloc(len, GFP_KERNEL);
69989+
69990+ if (ret) {
69991+ if (alloc_push(ret)) {
69992+ kfree(ret);
69993+ ret = NULL;
69994+ }
69995+ }
69996+
69997+out:
69998+ return ret;
69999+}
70000+
70001+void *
70002+acl_alloc_num(unsigned long num, unsigned long len)
70003+{
70004+ if (!len || (num > (PAGE_SIZE / len)))
70005+ return NULL;
70006+
70007+ return acl_alloc(num * len);
70008+}
70009+
70010+void
70011+acl_free_all(void)
70012+{
70013+ if (!current_alloc_state->alloc_stack)
70014+ return;
70015+
70016+ while (alloc_pop()) ;
70017+
70018+ if (current_alloc_state->alloc_stack) {
70019+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
70020+ kfree(current_alloc_state->alloc_stack);
70021+ else
70022+ vfree(current_alloc_state->alloc_stack);
70023+ }
70024+
70025+ current_alloc_state->alloc_stack = NULL;
70026+ current_alloc_state->alloc_stack_size = 1;
70027+ current_alloc_state->alloc_stack_next = 1;
70028+
70029+ return;
70030+}
70031+
70032+int
70033+acl_alloc_stack_init(unsigned long size)
70034+{
70035+ if ((size * sizeof (void *)) <= PAGE_SIZE)
70036+ current_alloc_state->alloc_stack =
70037+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
70038+ else
70039+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
70040+
70041+ current_alloc_state->alloc_stack_size = size;
70042+ current_alloc_state->alloc_stack_next = 1;
70043+
70044+ if (!current_alloc_state->alloc_stack)
70045+ return 0;
70046+ else
70047+ return 1;
70048+}
70049diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
70050new file mode 100644
70051index 0000000..bdd51ea
70052--- /dev/null
70053+++ b/grsecurity/gracl_cap.c
70054@@ -0,0 +1,110 @@
70055+#include <linux/kernel.h>
70056+#include <linux/module.h>
70057+#include <linux/sched.h>
70058+#include <linux/gracl.h>
70059+#include <linux/grsecurity.h>
70060+#include <linux/grinternal.h>
70061+
70062+extern const char *captab_log[];
70063+extern int captab_log_entries;
70064+
70065+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70066+{
70067+ struct acl_subject_label *curracl;
70068+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70069+ kernel_cap_t cap_audit = __cap_empty_set;
70070+
70071+ if (!gr_acl_is_enabled())
70072+ return 1;
70073+
70074+ curracl = task->acl;
70075+
70076+ cap_drop = curracl->cap_lower;
70077+ cap_mask = curracl->cap_mask;
70078+ cap_audit = curracl->cap_invert_audit;
70079+
70080+ while ((curracl = curracl->parent_subject)) {
70081+ /* if the cap isn't specified in the current computed mask but is specified in the
70082+ current level subject, and is lowered in the current level subject, then add
70083+ it to the set of dropped capabilities
70084+ otherwise, add the current level subject's mask to the current computed mask
70085+ */
70086+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70087+ cap_raise(cap_mask, cap);
70088+ if (cap_raised(curracl->cap_lower, cap))
70089+ cap_raise(cap_drop, cap);
70090+ if (cap_raised(curracl->cap_invert_audit, cap))
70091+ cap_raise(cap_audit, cap);
70092+ }
70093+ }
70094+
70095+ if (!cap_raised(cap_drop, cap)) {
70096+ if (cap_raised(cap_audit, cap))
70097+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
70098+ return 1;
70099+ }
70100+
70101+ curracl = task->acl;
70102+
70103+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
70104+ && cap_raised(cred->cap_effective, cap)) {
70105+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
70106+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
70107+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
70108+ gr_to_filename(task->exec_file->f_path.dentry,
70109+ task->exec_file->f_path.mnt) : curracl->filename,
70110+ curracl->filename, 0UL,
70111+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
70112+ return 1;
70113+ }
70114+
70115+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
70116+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
70117+
70118+ return 0;
70119+}
70120+
70121+int
70122+gr_acl_is_capable(const int cap)
70123+{
70124+ return gr_task_acl_is_capable(current, current_cred(), cap);
70125+}
70126+
70127+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
70128+{
70129+ struct acl_subject_label *curracl;
70130+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70131+
70132+ if (!gr_acl_is_enabled())
70133+ return 1;
70134+
70135+ curracl = task->acl;
70136+
70137+ cap_drop = curracl->cap_lower;
70138+ cap_mask = curracl->cap_mask;
70139+
70140+ while ((curracl = curracl->parent_subject)) {
70141+ /* if the cap isn't specified in the current computed mask but is specified in the
70142+ current level subject, and is lowered in the current level subject, then add
70143+ it to the set of dropped capabilities
70144+ otherwise, add the current level subject's mask to the current computed mask
70145+ */
70146+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70147+ cap_raise(cap_mask, cap);
70148+ if (cap_raised(curracl->cap_lower, cap))
70149+ cap_raise(cap_drop, cap);
70150+ }
70151+ }
70152+
70153+ if (!cap_raised(cap_drop, cap))
70154+ return 1;
70155+
70156+ return 0;
70157+}
70158+
70159+int
70160+gr_acl_is_capable_nolog(const int cap)
70161+{
70162+ return gr_task_acl_is_capable_nolog(current, cap);
70163+}
70164+
70165diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70166new file mode 100644
70167index 0000000..ca25605
70168--- /dev/null
70169+++ b/grsecurity/gracl_compat.c
70170@@ -0,0 +1,270 @@
70171+#include <linux/kernel.h>
70172+#include <linux/gracl.h>
70173+#include <linux/compat.h>
70174+#include <linux/gracl_compat.h>
70175+
70176+#include <asm/uaccess.h>
70177+
70178+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70179+{
70180+ struct gr_arg_wrapper_compat uwrapcompat;
70181+
70182+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70183+ return -EFAULT;
70184+
70185+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70186+ (uwrapcompat.version != 0x2901)) ||
70187+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70188+ return -EINVAL;
70189+
70190+ uwrap->arg = compat_ptr(uwrapcompat.arg);
70191+ uwrap->version = uwrapcompat.version;
70192+ uwrap->size = sizeof(struct gr_arg);
70193+
70194+ return 0;
70195+}
70196+
70197+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70198+{
70199+ struct gr_arg_compat argcompat;
70200+
70201+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70202+ return -EFAULT;
70203+
70204+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70205+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70206+ arg->role_db.num_roles = argcompat.role_db.num_roles;
70207+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70208+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70209+ arg->role_db.num_objects = argcompat.role_db.num_objects;
70210+
70211+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70212+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70213+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70214+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70215+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70216+ arg->segv_device = argcompat.segv_device;
70217+ arg->segv_inode = argcompat.segv_inode;
70218+ arg->segv_uid = argcompat.segv_uid;
70219+ arg->num_sprole_pws = argcompat.num_sprole_pws;
70220+ arg->mode = argcompat.mode;
70221+
70222+ return 0;
70223+}
70224+
70225+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70226+{
70227+ struct acl_object_label_compat objcompat;
70228+
70229+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70230+ return -EFAULT;
70231+
70232+ obj->filename = compat_ptr(objcompat.filename);
70233+ obj->inode = objcompat.inode;
70234+ obj->device = objcompat.device;
70235+ obj->mode = objcompat.mode;
70236+
70237+ obj->nested = compat_ptr(objcompat.nested);
70238+ obj->globbed = compat_ptr(objcompat.globbed);
70239+
70240+ obj->prev = compat_ptr(objcompat.prev);
70241+ obj->next = compat_ptr(objcompat.next);
70242+
70243+ return 0;
70244+}
70245+
70246+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70247+{
70248+ unsigned int i;
70249+ struct acl_subject_label_compat subjcompat;
70250+
70251+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70252+ return -EFAULT;
70253+
70254+ subj->filename = compat_ptr(subjcompat.filename);
70255+ subj->inode = subjcompat.inode;
70256+ subj->device = subjcompat.device;
70257+ subj->mode = subjcompat.mode;
70258+ subj->cap_mask = subjcompat.cap_mask;
70259+ subj->cap_lower = subjcompat.cap_lower;
70260+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
70261+
70262+ for (i = 0; i < GR_NLIMITS; i++) {
70263+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70264+ subj->res[i].rlim_cur = RLIM_INFINITY;
70265+ else
70266+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70267+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70268+ subj->res[i].rlim_max = RLIM_INFINITY;
70269+ else
70270+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70271+ }
70272+ subj->resmask = subjcompat.resmask;
70273+
70274+ subj->user_trans_type = subjcompat.user_trans_type;
70275+ subj->group_trans_type = subjcompat.group_trans_type;
70276+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70277+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70278+ subj->user_trans_num = subjcompat.user_trans_num;
70279+ subj->group_trans_num = subjcompat.group_trans_num;
70280+
70281+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70282+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70283+ subj->ip_type = subjcompat.ip_type;
70284+ subj->ips = compat_ptr(subjcompat.ips);
70285+ subj->ip_num = subjcompat.ip_num;
70286+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
70287+
70288+ subj->crashes = subjcompat.crashes;
70289+ subj->expires = subjcompat.expires;
70290+
70291+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70292+ subj->hash = compat_ptr(subjcompat.hash);
70293+ subj->prev = compat_ptr(subjcompat.prev);
70294+ subj->next = compat_ptr(subjcompat.next);
70295+
70296+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70297+ subj->obj_hash_size = subjcompat.obj_hash_size;
70298+ subj->pax_flags = subjcompat.pax_flags;
70299+
70300+ return 0;
70301+}
70302+
70303+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70304+{
70305+ struct acl_role_label_compat rolecompat;
70306+
70307+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70308+ return -EFAULT;
70309+
70310+ role->rolename = compat_ptr(rolecompat.rolename);
70311+ role->uidgid = rolecompat.uidgid;
70312+ role->roletype = rolecompat.roletype;
70313+
70314+ role->auth_attempts = rolecompat.auth_attempts;
70315+ role->expires = rolecompat.expires;
70316+
70317+ role->root_label = compat_ptr(rolecompat.root_label);
70318+ role->hash = compat_ptr(rolecompat.hash);
70319+
70320+ role->prev = compat_ptr(rolecompat.prev);
70321+ role->next = compat_ptr(rolecompat.next);
70322+
70323+ role->transitions = compat_ptr(rolecompat.transitions);
70324+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70325+ role->domain_children = compat_ptr(rolecompat.domain_children);
70326+ role->domain_child_num = rolecompat.domain_child_num;
70327+
70328+ role->umask = rolecompat.umask;
70329+
70330+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
70331+ role->subj_hash_size = rolecompat.subj_hash_size;
70332+
70333+ return 0;
70334+}
70335+
70336+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70337+{
70338+ struct role_allowed_ip_compat roleip_compat;
70339+
70340+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70341+ return -EFAULT;
70342+
70343+ roleip->addr = roleip_compat.addr;
70344+ roleip->netmask = roleip_compat.netmask;
70345+
70346+ roleip->prev = compat_ptr(roleip_compat.prev);
70347+ roleip->next = compat_ptr(roleip_compat.next);
70348+
70349+ return 0;
70350+}
70351+
70352+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70353+{
70354+ struct role_transition_compat trans_compat;
70355+
70356+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70357+ return -EFAULT;
70358+
70359+ trans->rolename = compat_ptr(trans_compat.rolename);
70360+
70361+ trans->prev = compat_ptr(trans_compat.prev);
70362+ trans->next = compat_ptr(trans_compat.next);
70363+
70364+ return 0;
70365+
70366+}
70367+
70368+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70369+{
70370+ struct gr_hash_struct_compat hash_compat;
70371+
70372+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70373+ return -EFAULT;
70374+
70375+ hash->table = compat_ptr(hash_compat.table);
70376+ hash->nametable = compat_ptr(hash_compat.nametable);
70377+ hash->first = compat_ptr(hash_compat.first);
70378+
70379+ hash->table_size = hash_compat.table_size;
70380+ hash->used_size = hash_compat.used_size;
70381+
70382+ hash->type = hash_compat.type;
70383+
70384+ return 0;
70385+}
70386+
70387+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70388+{
70389+ compat_uptr_t ptrcompat;
70390+
70391+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70392+ return -EFAULT;
70393+
70394+ *(void **)ptr = compat_ptr(ptrcompat);
70395+
70396+ return 0;
70397+}
70398+
70399+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70400+{
70401+ struct acl_ip_label_compat ip_compat;
70402+
70403+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70404+ return -EFAULT;
70405+
70406+ ip->iface = compat_ptr(ip_compat.iface);
70407+ ip->addr = ip_compat.addr;
70408+ ip->netmask = ip_compat.netmask;
70409+ ip->low = ip_compat.low;
70410+ ip->high = ip_compat.high;
70411+ ip->mode = ip_compat.mode;
70412+ ip->type = ip_compat.type;
70413+
70414+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70415+
70416+ ip->prev = compat_ptr(ip_compat.prev);
70417+ ip->next = compat_ptr(ip_compat.next);
70418+
70419+ return 0;
70420+}
70421+
70422+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70423+{
70424+ struct sprole_pw_compat pw_compat;
70425+
70426+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70427+ return -EFAULT;
70428+
70429+ pw->rolename = compat_ptr(pw_compat.rolename);
70430+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70431+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70432+
70433+ return 0;
70434+}
70435+
70436+size_t get_gr_arg_wrapper_size_compat(void)
70437+{
70438+ return sizeof(struct gr_arg_wrapper_compat);
70439+}
70440+
70441diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70442new file mode 100644
70443index 0000000..4008fdc
70444--- /dev/null
70445+++ b/grsecurity/gracl_fs.c
70446@@ -0,0 +1,445 @@
70447+#include <linux/kernel.h>
70448+#include <linux/sched.h>
70449+#include <linux/types.h>
70450+#include <linux/fs.h>
70451+#include <linux/file.h>
70452+#include <linux/stat.h>
70453+#include <linux/grsecurity.h>
70454+#include <linux/grinternal.h>
70455+#include <linux/gracl.h>
70456+
70457+umode_t
70458+gr_acl_umask(void)
70459+{
70460+ if (unlikely(!gr_acl_is_enabled()))
70461+ return 0;
70462+
70463+ return current->role->umask;
70464+}
70465+
70466+__u32
70467+gr_acl_handle_hidden_file(const struct dentry * dentry,
70468+ const struct vfsmount * mnt)
70469+{
70470+ __u32 mode;
70471+
70472+ if (unlikely(d_is_negative(dentry)))
70473+ return GR_FIND;
70474+
70475+ mode =
70476+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70477+
70478+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70479+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70480+ return mode;
70481+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70482+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70483+ return 0;
70484+ } else if (unlikely(!(mode & GR_FIND)))
70485+ return 0;
70486+
70487+ return GR_FIND;
70488+}
70489+
70490+__u32
70491+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70492+ int acc_mode)
70493+{
70494+ __u32 reqmode = GR_FIND;
70495+ __u32 mode;
70496+
70497+ if (unlikely(d_is_negative(dentry)))
70498+ return reqmode;
70499+
70500+ if (acc_mode & MAY_APPEND)
70501+ reqmode |= GR_APPEND;
70502+ else if (acc_mode & MAY_WRITE)
70503+ reqmode |= GR_WRITE;
70504+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70505+ reqmode |= GR_READ;
70506+
70507+ mode =
70508+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70509+ mnt);
70510+
70511+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70512+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70513+ reqmode & GR_READ ? " reading" : "",
70514+ reqmode & GR_WRITE ? " writing" : reqmode &
70515+ GR_APPEND ? " appending" : "");
70516+ return reqmode;
70517+ } else
70518+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70519+ {
70520+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70521+ reqmode & GR_READ ? " reading" : "",
70522+ reqmode & GR_WRITE ? " writing" : reqmode &
70523+ GR_APPEND ? " appending" : "");
70524+ return 0;
70525+ } else if (unlikely((mode & reqmode) != reqmode))
70526+ return 0;
70527+
70528+ return reqmode;
70529+}
70530+
70531+__u32
70532+gr_acl_handle_creat(const struct dentry * dentry,
70533+ const struct dentry * p_dentry,
70534+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70535+ const int imode)
70536+{
70537+ __u32 reqmode = GR_WRITE | GR_CREATE;
70538+ __u32 mode;
70539+
70540+ if (acc_mode & MAY_APPEND)
70541+ reqmode |= GR_APPEND;
70542+ // if a directory was required or the directory already exists, then
70543+ // don't count this open as a read
70544+ if ((acc_mode & MAY_READ) &&
70545+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70546+ reqmode |= GR_READ;
70547+ if ((open_flags & O_CREAT) &&
70548+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70549+ reqmode |= GR_SETID;
70550+
70551+ mode =
70552+ gr_check_create(dentry, p_dentry, p_mnt,
70553+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70554+
70555+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70556+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70557+ reqmode & GR_READ ? " reading" : "",
70558+ reqmode & GR_WRITE ? " writing" : reqmode &
70559+ GR_APPEND ? " appending" : "");
70560+ return reqmode;
70561+ } else
70562+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70563+ {
70564+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70565+ reqmode & GR_READ ? " reading" : "",
70566+ reqmode & GR_WRITE ? " writing" : reqmode &
70567+ GR_APPEND ? " appending" : "");
70568+ return 0;
70569+ } else if (unlikely((mode & reqmode) != reqmode))
70570+ return 0;
70571+
70572+ return reqmode;
70573+}
70574+
70575+__u32
70576+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70577+ const int fmode)
70578+{
70579+ __u32 mode, reqmode = GR_FIND;
70580+
70581+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70582+ reqmode |= GR_EXEC;
70583+ if (fmode & S_IWOTH)
70584+ reqmode |= GR_WRITE;
70585+ if (fmode & S_IROTH)
70586+ reqmode |= GR_READ;
70587+
70588+ mode =
70589+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70590+ mnt);
70591+
70592+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70593+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70594+ reqmode & GR_READ ? " reading" : "",
70595+ reqmode & GR_WRITE ? " writing" : "",
70596+ reqmode & GR_EXEC ? " executing" : "");
70597+ return reqmode;
70598+ } else
70599+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70600+ {
70601+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70602+ reqmode & GR_READ ? " reading" : "",
70603+ reqmode & GR_WRITE ? " writing" : "",
70604+ reqmode & GR_EXEC ? " executing" : "");
70605+ return 0;
70606+ } else if (unlikely((mode & reqmode) != reqmode))
70607+ return 0;
70608+
70609+ return reqmode;
70610+}
70611+
70612+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70613+{
70614+ __u32 mode;
70615+
70616+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70617+
70618+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70619+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70620+ return mode;
70621+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70622+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70623+ return 0;
70624+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70625+ return 0;
70626+
70627+ return (reqmode);
70628+}
70629+
70630+__u32
70631+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70632+{
70633+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70634+}
70635+
70636+__u32
70637+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70638+{
70639+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70640+}
70641+
70642+__u32
70643+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70644+{
70645+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70646+}
70647+
70648+__u32
70649+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70650+{
70651+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70652+}
70653+
70654+__u32
70655+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70656+ umode_t *modeptr)
70657+{
70658+ umode_t mode;
70659+
70660+ *modeptr &= ~gr_acl_umask();
70661+ mode = *modeptr;
70662+
70663+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70664+ return 1;
70665+
70666+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70667+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70668+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70669+ GR_CHMOD_ACL_MSG);
70670+ } else {
70671+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70672+ }
70673+}
70674+
70675+__u32
70676+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70677+{
70678+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70679+}
70680+
70681+__u32
70682+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70683+{
70684+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70685+}
70686+
70687+__u32
70688+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70689+{
70690+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70691+}
70692+
70693+__u32
70694+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70695+{
70696+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70697+}
70698+
70699+__u32
70700+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70701+{
70702+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70703+ GR_UNIXCONNECT_ACL_MSG);
70704+}
70705+
70706+/* hardlinks require at minimum create and link permission,
70707+ any additional privilege required is based on the
70708+ privilege of the file being linked to
70709+*/
70710+__u32
70711+gr_acl_handle_link(const struct dentry * new_dentry,
70712+ const struct dentry * parent_dentry,
70713+ const struct vfsmount * parent_mnt,
70714+ const struct dentry * old_dentry,
70715+ const struct vfsmount * old_mnt, const struct filename *to)
70716+{
70717+ __u32 mode;
70718+ __u32 needmode = GR_CREATE | GR_LINK;
70719+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70720+
70721+ mode =
70722+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70723+ old_mnt);
70724+
70725+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70726+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70727+ return mode;
70728+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70729+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70730+ return 0;
70731+ } else if (unlikely((mode & needmode) != needmode))
70732+ return 0;
70733+
70734+ return 1;
70735+}
70736+
70737+__u32
70738+gr_acl_handle_symlink(const struct dentry * new_dentry,
70739+ const struct dentry * parent_dentry,
70740+ const struct vfsmount * parent_mnt, const struct filename *from)
70741+{
70742+ __u32 needmode = GR_WRITE | GR_CREATE;
70743+ __u32 mode;
70744+
70745+ mode =
70746+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70747+ GR_CREATE | GR_AUDIT_CREATE |
70748+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70749+
70750+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70751+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70752+ return mode;
70753+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70754+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70755+ return 0;
70756+ } else if (unlikely((mode & needmode) != needmode))
70757+ return 0;
70758+
70759+ return (GR_WRITE | GR_CREATE);
70760+}
70761+
70762+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)
70763+{
70764+ __u32 mode;
70765+
70766+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70767+
70768+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70769+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70770+ return mode;
70771+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70772+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70773+ return 0;
70774+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70775+ return 0;
70776+
70777+ return (reqmode);
70778+}
70779+
70780+__u32
70781+gr_acl_handle_mknod(const struct dentry * new_dentry,
70782+ const struct dentry * parent_dentry,
70783+ const struct vfsmount * parent_mnt,
70784+ const int mode)
70785+{
70786+ __u32 reqmode = GR_WRITE | GR_CREATE;
70787+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70788+ reqmode |= GR_SETID;
70789+
70790+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70791+ reqmode, GR_MKNOD_ACL_MSG);
70792+}
70793+
70794+__u32
70795+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70796+ const struct dentry *parent_dentry,
70797+ const struct vfsmount *parent_mnt)
70798+{
70799+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70800+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70801+}
70802+
70803+#define RENAME_CHECK_SUCCESS(old, new) \
70804+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70805+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70806+
70807+int
70808+gr_acl_handle_rename(struct dentry *new_dentry,
70809+ struct dentry *parent_dentry,
70810+ const struct vfsmount *parent_mnt,
70811+ struct dentry *old_dentry,
70812+ struct inode *old_parent_inode,
70813+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
70814+{
70815+ __u32 comp1, comp2;
70816+ int error = 0;
70817+
70818+ if (unlikely(!gr_acl_is_enabled()))
70819+ return 0;
70820+
70821+ if (flags & RENAME_EXCHANGE) {
70822+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70823+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70824+ GR_SUPPRESS, parent_mnt);
70825+ comp2 =
70826+ gr_search_file(old_dentry,
70827+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70828+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70829+ } else if (d_is_negative(new_dentry)) {
70830+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70831+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70832+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70833+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70834+ GR_DELETE | GR_AUDIT_DELETE |
70835+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70836+ GR_SUPPRESS, old_mnt);
70837+ } else {
70838+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70839+ GR_CREATE | GR_DELETE |
70840+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70841+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70842+ GR_SUPPRESS, parent_mnt);
70843+ comp2 =
70844+ gr_search_file(old_dentry,
70845+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70846+ GR_DELETE | GR_AUDIT_DELETE |
70847+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70848+ }
70849+
70850+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70851+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70852+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70853+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70854+ && !(comp2 & GR_SUPPRESS)) {
70855+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70856+ error = -EACCES;
70857+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70858+ error = -EACCES;
70859+
70860+ return error;
70861+}
70862+
70863+void
70864+gr_acl_handle_exit(void)
70865+{
70866+ u16 id;
70867+ char *rolename;
70868+
70869+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70870+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70871+ id = current->acl_role_id;
70872+ rolename = current->role->rolename;
70873+ gr_set_acls(1);
70874+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70875+ }
70876+
70877+ gr_put_exec_file(current);
70878+ return;
70879+}
70880+
70881+int
70882+gr_acl_handle_procpidmem(const struct task_struct *task)
70883+{
70884+ if (unlikely(!gr_acl_is_enabled()))
70885+ return 0;
70886+
70887+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70888+ return -EACCES;
70889+
70890+ return 0;
70891+}
70892diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70893new file mode 100644
70894index 0000000..f056b81
70895--- /dev/null
70896+++ b/grsecurity/gracl_ip.c
70897@@ -0,0 +1,386 @@
70898+#include <linux/kernel.h>
70899+#include <asm/uaccess.h>
70900+#include <asm/errno.h>
70901+#include <net/sock.h>
70902+#include <linux/file.h>
70903+#include <linux/fs.h>
70904+#include <linux/net.h>
70905+#include <linux/in.h>
70906+#include <linux/skbuff.h>
70907+#include <linux/ip.h>
70908+#include <linux/udp.h>
70909+#include <linux/types.h>
70910+#include <linux/sched.h>
70911+#include <linux/netdevice.h>
70912+#include <linux/inetdevice.h>
70913+#include <linux/gracl.h>
70914+#include <linux/grsecurity.h>
70915+#include <linux/grinternal.h>
70916+
70917+#define GR_BIND 0x01
70918+#define GR_CONNECT 0x02
70919+#define GR_INVERT 0x04
70920+#define GR_BINDOVERRIDE 0x08
70921+#define GR_CONNECTOVERRIDE 0x10
70922+#define GR_SOCK_FAMILY 0x20
70923+
70924+static const char * gr_protocols[IPPROTO_MAX] = {
70925+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70926+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70927+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70928+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70929+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70930+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70931+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70932+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70933+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70934+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70935+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70936+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70937+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70938+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70939+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70940+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70941+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70942+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70943+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70944+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70945+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70946+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70947+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70948+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70949+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70950+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70951+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70952+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70953+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70954+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70955+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70956+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70957+ };
70958+
70959+static const char * gr_socktypes[SOCK_MAX] = {
70960+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70961+ "unknown:7", "unknown:8", "unknown:9", "packet"
70962+ };
70963+
70964+static const char * gr_sockfamilies[AF_MAX+1] = {
70965+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70966+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70967+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70968+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70969+ };
70970+
70971+const char *
70972+gr_proto_to_name(unsigned char proto)
70973+{
70974+ return gr_protocols[proto];
70975+}
70976+
70977+const char *
70978+gr_socktype_to_name(unsigned char type)
70979+{
70980+ return gr_socktypes[type];
70981+}
70982+
70983+const char *
70984+gr_sockfamily_to_name(unsigned char family)
70985+{
70986+ return gr_sockfamilies[family];
70987+}
70988+
70989+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70990+
70991+int
70992+gr_search_socket(const int domain, const int type, const int protocol)
70993+{
70994+ struct acl_subject_label *curr;
70995+ const struct cred *cred = current_cred();
70996+
70997+ if (unlikely(!gr_acl_is_enabled()))
70998+ goto exit;
70999+
71000+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
71001+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
71002+ goto exit; // let the kernel handle it
71003+
71004+ curr = current->acl;
71005+
71006+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
71007+ /* the family is allowed, if this is PF_INET allow it only if
71008+ the extra sock type/protocol checks pass */
71009+ if (domain == PF_INET)
71010+ goto inet_check;
71011+ goto exit;
71012+ } else {
71013+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71014+ __u32 fakeip = 0;
71015+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71016+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71017+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71018+ gr_to_filename(current->exec_file->f_path.dentry,
71019+ current->exec_file->f_path.mnt) :
71020+ curr->filename, curr->filename,
71021+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
71022+ &current->signal->saved_ip);
71023+ goto exit;
71024+ }
71025+ goto exit_fail;
71026+ }
71027+
71028+inet_check:
71029+ /* the rest of this checking is for IPv4 only */
71030+ if (!curr->ips)
71031+ goto exit;
71032+
71033+ if ((curr->ip_type & (1U << type)) &&
71034+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
71035+ goto exit;
71036+
71037+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71038+ /* we don't place acls on raw sockets , and sometimes
71039+ dgram/ip sockets are opened for ioctl and not
71040+ bind/connect, so we'll fake a bind learn log */
71041+ if (type == SOCK_RAW || type == SOCK_PACKET) {
71042+ __u32 fakeip = 0;
71043+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71044+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71045+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71046+ gr_to_filename(current->exec_file->f_path.dentry,
71047+ current->exec_file->f_path.mnt) :
71048+ curr->filename, curr->filename,
71049+ &fakeip, 0, type,
71050+ protocol, GR_CONNECT, &current->signal->saved_ip);
71051+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
71052+ __u32 fakeip = 0;
71053+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71054+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71055+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71056+ gr_to_filename(current->exec_file->f_path.dentry,
71057+ current->exec_file->f_path.mnt) :
71058+ curr->filename, curr->filename,
71059+ &fakeip, 0, type,
71060+ protocol, GR_BIND, &current->signal->saved_ip);
71061+ }
71062+ /* we'll log when they use connect or bind */
71063+ goto exit;
71064+ }
71065+
71066+exit_fail:
71067+ if (domain == PF_INET)
71068+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
71069+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
71070+ else if (rcu_access_pointer(net_families[domain]) != NULL)
71071+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
71072+ gr_socktype_to_name(type), protocol);
71073+
71074+ return 0;
71075+exit:
71076+ return 1;
71077+}
71078+
71079+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)
71080+{
71081+ if ((ip->mode & mode) &&
71082+ (ip_port >= ip->low) &&
71083+ (ip_port <= ip->high) &&
71084+ ((ntohl(ip_addr) & our_netmask) ==
71085+ (ntohl(our_addr) & our_netmask))
71086+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
71087+ && (ip->type & (1U << type))) {
71088+ if (ip->mode & GR_INVERT)
71089+ return 2; // specifically denied
71090+ else
71091+ return 1; // allowed
71092+ }
71093+
71094+ return 0; // not specifically allowed, may continue parsing
71095+}
71096+
71097+static int
71098+gr_search_connectbind(const int full_mode, struct sock *sk,
71099+ struct sockaddr_in *addr, const int type)
71100+{
71101+ char iface[IFNAMSIZ] = {0};
71102+ struct acl_subject_label *curr;
71103+ struct acl_ip_label *ip;
71104+ struct inet_sock *isk;
71105+ struct net_device *dev;
71106+ struct in_device *idev;
71107+ unsigned long i;
71108+ int ret;
71109+ int mode = full_mode & (GR_BIND | GR_CONNECT);
71110+ __u32 ip_addr = 0;
71111+ __u32 our_addr;
71112+ __u32 our_netmask;
71113+ char *p;
71114+ __u16 ip_port = 0;
71115+ const struct cred *cred = current_cred();
71116+
71117+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
71118+ return 0;
71119+
71120+ curr = current->acl;
71121+ isk = inet_sk(sk);
71122+
71123+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
71124+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
71125+ addr->sin_addr.s_addr = curr->inaddr_any_override;
71126+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
71127+ struct sockaddr_in saddr;
71128+ int err;
71129+
71130+ saddr.sin_family = AF_INET;
71131+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
71132+ saddr.sin_port = isk->inet_sport;
71133+
71134+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71135+ if (err)
71136+ return err;
71137+
71138+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71139+ if (err)
71140+ return err;
71141+ }
71142+
71143+ if (!curr->ips)
71144+ return 0;
71145+
71146+ ip_addr = addr->sin_addr.s_addr;
71147+ ip_port = ntohs(addr->sin_port);
71148+
71149+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71150+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71151+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71152+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71153+ gr_to_filename(current->exec_file->f_path.dentry,
71154+ current->exec_file->f_path.mnt) :
71155+ curr->filename, curr->filename,
71156+ &ip_addr, ip_port, type,
71157+ sk->sk_protocol, mode, &current->signal->saved_ip);
71158+ return 0;
71159+ }
71160+
71161+ for (i = 0; i < curr->ip_num; i++) {
71162+ ip = *(curr->ips + i);
71163+ if (ip->iface != NULL) {
71164+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
71165+ p = strchr(iface, ':');
71166+ if (p != NULL)
71167+ *p = '\0';
71168+ dev = dev_get_by_name(sock_net(sk), iface);
71169+ if (dev == NULL)
71170+ continue;
71171+ idev = in_dev_get(dev);
71172+ if (idev == NULL) {
71173+ dev_put(dev);
71174+ continue;
71175+ }
71176+ rcu_read_lock();
71177+ for_ifa(idev) {
71178+ if (!strcmp(ip->iface, ifa->ifa_label)) {
71179+ our_addr = ifa->ifa_address;
71180+ our_netmask = 0xffffffff;
71181+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71182+ if (ret == 1) {
71183+ rcu_read_unlock();
71184+ in_dev_put(idev);
71185+ dev_put(dev);
71186+ return 0;
71187+ } else if (ret == 2) {
71188+ rcu_read_unlock();
71189+ in_dev_put(idev);
71190+ dev_put(dev);
71191+ goto denied;
71192+ }
71193+ }
71194+ } endfor_ifa(idev);
71195+ rcu_read_unlock();
71196+ in_dev_put(idev);
71197+ dev_put(dev);
71198+ } else {
71199+ our_addr = ip->addr;
71200+ our_netmask = ip->netmask;
71201+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71202+ if (ret == 1)
71203+ return 0;
71204+ else if (ret == 2)
71205+ goto denied;
71206+ }
71207+ }
71208+
71209+denied:
71210+ if (mode == GR_BIND)
71211+ 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));
71212+ else if (mode == GR_CONNECT)
71213+ 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));
71214+
71215+ return -EACCES;
71216+}
71217+
71218+int
71219+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71220+{
71221+ /* always allow disconnection of dgram sockets with connect */
71222+ if (addr->sin_family == AF_UNSPEC)
71223+ return 0;
71224+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71225+}
71226+
71227+int
71228+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71229+{
71230+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71231+}
71232+
71233+int gr_search_listen(struct socket *sock)
71234+{
71235+ struct sock *sk = sock->sk;
71236+ struct sockaddr_in addr;
71237+
71238+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71239+ addr.sin_port = inet_sk(sk)->inet_sport;
71240+
71241+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71242+}
71243+
71244+int gr_search_accept(struct socket *sock)
71245+{
71246+ struct sock *sk = sock->sk;
71247+ struct sockaddr_in addr;
71248+
71249+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71250+ addr.sin_port = inet_sk(sk)->inet_sport;
71251+
71252+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71253+}
71254+
71255+int
71256+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71257+{
71258+ if (addr)
71259+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71260+ else {
71261+ struct sockaddr_in sin;
71262+ const struct inet_sock *inet = inet_sk(sk);
71263+
71264+ sin.sin_addr.s_addr = inet->inet_daddr;
71265+ sin.sin_port = inet->inet_dport;
71266+
71267+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71268+ }
71269+}
71270+
71271+int
71272+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71273+{
71274+ struct sockaddr_in sin;
71275+
71276+ if (unlikely(skb->len < sizeof (struct udphdr)))
71277+ return 0; // skip this packet
71278+
71279+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71280+ sin.sin_port = udp_hdr(skb)->source;
71281+
71282+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71283+}
71284diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71285new file mode 100644
71286index 0000000..25f54ef
71287--- /dev/null
71288+++ b/grsecurity/gracl_learn.c
71289@@ -0,0 +1,207 @@
71290+#include <linux/kernel.h>
71291+#include <linux/mm.h>
71292+#include <linux/sched.h>
71293+#include <linux/poll.h>
71294+#include <linux/string.h>
71295+#include <linux/file.h>
71296+#include <linux/types.h>
71297+#include <linux/vmalloc.h>
71298+#include <linux/grinternal.h>
71299+
71300+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71301+ size_t count, loff_t *ppos);
71302+extern int gr_acl_is_enabled(void);
71303+
71304+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71305+static int gr_learn_attached;
71306+
71307+/* use a 512k buffer */
71308+#define LEARN_BUFFER_SIZE (512 * 1024)
71309+
71310+static DEFINE_SPINLOCK(gr_learn_lock);
71311+static DEFINE_MUTEX(gr_learn_user_mutex);
71312+
71313+/* we need to maintain two buffers, so that the kernel context of grlearn
71314+ uses a semaphore around the userspace copying, and the other kernel contexts
71315+ use a spinlock when copying into the buffer, since they cannot sleep
71316+*/
71317+static char *learn_buffer;
71318+static char *learn_buffer_user;
71319+static int learn_buffer_len;
71320+static int learn_buffer_user_len;
71321+
71322+static ssize_t
71323+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71324+{
71325+ DECLARE_WAITQUEUE(wait, current);
71326+ ssize_t retval = 0;
71327+
71328+ add_wait_queue(&learn_wait, &wait);
71329+ set_current_state(TASK_INTERRUPTIBLE);
71330+ do {
71331+ mutex_lock(&gr_learn_user_mutex);
71332+ spin_lock(&gr_learn_lock);
71333+ if (learn_buffer_len)
71334+ break;
71335+ spin_unlock(&gr_learn_lock);
71336+ mutex_unlock(&gr_learn_user_mutex);
71337+ if (file->f_flags & O_NONBLOCK) {
71338+ retval = -EAGAIN;
71339+ goto out;
71340+ }
71341+ if (signal_pending(current)) {
71342+ retval = -ERESTARTSYS;
71343+ goto out;
71344+ }
71345+
71346+ schedule();
71347+ } while (1);
71348+
71349+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71350+ learn_buffer_user_len = learn_buffer_len;
71351+ retval = learn_buffer_len;
71352+ learn_buffer_len = 0;
71353+
71354+ spin_unlock(&gr_learn_lock);
71355+
71356+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71357+ retval = -EFAULT;
71358+
71359+ mutex_unlock(&gr_learn_user_mutex);
71360+out:
71361+ set_current_state(TASK_RUNNING);
71362+ remove_wait_queue(&learn_wait, &wait);
71363+ return retval;
71364+}
71365+
71366+static unsigned int
71367+poll_learn(struct file * file, poll_table * wait)
71368+{
71369+ poll_wait(file, &learn_wait, wait);
71370+
71371+ if (learn_buffer_len)
71372+ return (POLLIN | POLLRDNORM);
71373+
71374+ return 0;
71375+}
71376+
71377+void
71378+gr_clear_learn_entries(void)
71379+{
71380+ char *tmp;
71381+
71382+ mutex_lock(&gr_learn_user_mutex);
71383+ spin_lock(&gr_learn_lock);
71384+ tmp = learn_buffer;
71385+ learn_buffer = NULL;
71386+ spin_unlock(&gr_learn_lock);
71387+ if (tmp)
71388+ vfree(tmp);
71389+ if (learn_buffer_user != NULL) {
71390+ vfree(learn_buffer_user);
71391+ learn_buffer_user = NULL;
71392+ }
71393+ learn_buffer_len = 0;
71394+ mutex_unlock(&gr_learn_user_mutex);
71395+
71396+ return;
71397+}
71398+
71399+void
71400+gr_add_learn_entry(const char *fmt, ...)
71401+{
71402+ va_list args;
71403+ unsigned int len;
71404+
71405+ if (!gr_learn_attached)
71406+ return;
71407+
71408+ spin_lock(&gr_learn_lock);
71409+
71410+ /* leave a gap at the end so we know when it's "full" but don't have to
71411+ compute the exact length of the string we're trying to append
71412+ */
71413+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71414+ spin_unlock(&gr_learn_lock);
71415+ wake_up_interruptible(&learn_wait);
71416+ return;
71417+ }
71418+ if (learn_buffer == NULL) {
71419+ spin_unlock(&gr_learn_lock);
71420+ return;
71421+ }
71422+
71423+ va_start(args, fmt);
71424+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71425+ va_end(args);
71426+
71427+ learn_buffer_len += len + 1;
71428+
71429+ spin_unlock(&gr_learn_lock);
71430+ wake_up_interruptible(&learn_wait);
71431+
71432+ return;
71433+}
71434+
71435+static int
71436+open_learn(struct inode *inode, struct file *file)
71437+{
71438+ if (file->f_mode & FMODE_READ && gr_learn_attached)
71439+ return -EBUSY;
71440+ if (file->f_mode & FMODE_READ) {
71441+ int retval = 0;
71442+ mutex_lock(&gr_learn_user_mutex);
71443+ if (learn_buffer == NULL)
71444+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71445+ if (learn_buffer_user == NULL)
71446+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71447+ if (learn_buffer == NULL) {
71448+ retval = -ENOMEM;
71449+ goto out_error;
71450+ }
71451+ if (learn_buffer_user == NULL) {
71452+ retval = -ENOMEM;
71453+ goto out_error;
71454+ }
71455+ learn_buffer_len = 0;
71456+ learn_buffer_user_len = 0;
71457+ gr_learn_attached = 1;
71458+out_error:
71459+ mutex_unlock(&gr_learn_user_mutex);
71460+ return retval;
71461+ }
71462+ return 0;
71463+}
71464+
71465+static int
71466+close_learn(struct inode *inode, struct file *file)
71467+{
71468+ if (file->f_mode & FMODE_READ) {
71469+ char *tmp = NULL;
71470+ mutex_lock(&gr_learn_user_mutex);
71471+ spin_lock(&gr_learn_lock);
71472+ tmp = learn_buffer;
71473+ learn_buffer = NULL;
71474+ spin_unlock(&gr_learn_lock);
71475+ if (tmp)
71476+ vfree(tmp);
71477+ if (learn_buffer_user != NULL) {
71478+ vfree(learn_buffer_user);
71479+ learn_buffer_user = NULL;
71480+ }
71481+ learn_buffer_len = 0;
71482+ learn_buffer_user_len = 0;
71483+ gr_learn_attached = 0;
71484+ mutex_unlock(&gr_learn_user_mutex);
71485+ }
71486+
71487+ return 0;
71488+}
71489+
71490+const struct file_operations grsec_fops = {
71491+ .read = read_learn,
71492+ .write = write_grsec_handler,
71493+ .open = open_learn,
71494+ .release = close_learn,
71495+ .poll = poll_learn,
71496+};
71497diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71498new file mode 100644
71499index 0000000..3f8ade0
71500--- /dev/null
71501+++ b/grsecurity/gracl_policy.c
71502@@ -0,0 +1,1782 @@
71503+#include <linux/kernel.h>
71504+#include <linux/module.h>
71505+#include <linux/sched.h>
71506+#include <linux/mm.h>
71507+#include <linux/file.h>
71508+#include <linux/fs.h>
71509+#include <linux/namei.h>
71510+#include <linux/mount.h>
71511+#include <linux/tty.h>
71512+#include <linux/proc_fs.h>
71513+#include <linux/lglock.h>
71514+#include <linux/slab.h>
71515+#include <linux/vmalloc.h>
71516+#include <linux/types.h>
71517+#include <linux/sysctl.h>
71518+#include <linux/netdevice.h>
71519+#include <linux/ptrace.h>
71520+#include <linux/gracl.h>
71521+#include <linux/gralloc.h>
71522+#include <linux/security.h>
71523+#include <linux/grinternal.h>
71524+#include <linux/pid_namespace.h>
71525+#include <linux/stop_machine.h>
71526+#include <linux/fdtable.h>
71527+#include <linux/percpu.h>
71528+#include <linux/lglock.h>
71529+#include <linux/hugetlb.h>
71530+#include <linux/posix-timers.h>
71531+#include "../fs/mount.h"
71532+
71533+#include <asm/uaccess.h>
71534+#include <asm/errno.h>
71535+#include <asm/mman.h>
71536+
71537+extern struct gr_policy_state *polstate;
71538+
71539+#define FOR_EACH_ROLE_START(role) \
71540+ role = polstate->role_list; \
71541+ while (role) {
71542+
71543+#define FOR_EACH_ROLE_END(role) \
71544+ role = role->prev; \
71545+ }
71546+
71547+struct path gr_real_root;
71548+
71549+extern struct gr_alloc_state *current_alloc_state;
71550+
71551+u16 acl_sp_role_value;
71552+
71553+static DEFINE_MUTEX(gr_dev_mutex);
71554+
71555+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71556+extern void gr_clear_learn_entries(void);
71557+
71558+struct gr_arg *gr_usermode __read_only;
71559+unsigned char *gr_system_salt __read_only;
71560+unsigned char *gr_system_sum __read_only;
71561+
71562+static unsigned int gr_auth_attempts = 0;
71563+static unsigned long gr_auth_expires = 0UL;
71564+
71565+struct acl_object_label *fakefs_obj_rw;
71566+struct acl_object_label *fakefs_obj_rwx;
71567+
71568+extern int gr_init_uidset(void);
71569+extern void gr_free_uidset(void);
71570+extern void gr_remove_uid(uid_t uid);
71571+extern int gr_find_uid(uid_t uid);
71572+
71573+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71574+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71575+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71576+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71577+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);
71578+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71579+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71580+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71581+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71582+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71583+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71584+extern void assign_special_role(const char *rolename);
71585+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71586+extern int gr_rbac_disable(void *unused);
71587+extern void gr_enable_rbac_system(void);
71588+
71589+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71590+{
71591+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71592+ return -EFAULT;
71593+
71594+ return 0;
71595+}
71596+
71597+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71598+{
71599+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71600+ return -EFAULT;
71601+
71602+ return 0;
71603+}
71604+
71605+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71606+{
71607+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71608+ return -EFAULT;
71609+
71610+ return 0;
71611+}
71612+
71613+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71614+{
71615+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71616+ return -EFAULT;
71617+
71618+ return 0;
71619+}
71620+
71621+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71622+{
71623+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71624+ return -EFAULT;
71625+
71626+ return 0;
71627+}
71628+
71629+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71630+{
71631+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71632+ return -EFAULT;
71633+
71634+ return 0;
71635+}
71636+
71637+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71638+{
71639+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71640+ return -EFAULT;
71641+
71642+ return 0;
71643+}
71644+
71645+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71646+{
71647+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71648+ return -EFAULT;
71649+
71650+ return 0;
71651+}
71652+
71653+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71654+{
71655+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71656+ return -EFAULT;
71657+
71658+ return 0;
71659+}
71660+
71661+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71662+{
71663+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71664+ return -EFAULT;
71665+
71666+ if (((uwrap->version != GRSECURITY_VERSION) &&
71667+ (uwrap->version != 0x2901)) ||
71668+ (uwrap->size != sizeof(struct gr_arg)))
71669+ return -EINVAL;
71670+
71671+ return 0;
71672+}
71673+
71674+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71675+{
71676+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71677+ return -EFAULT;
71678+
71679+ return 0;
71680+}
71681+
71682+static size_t get_gr_arg_wrapper_size_normal(void)
71683+{
71684+ return sizeof(struct gr_arg_wrapper);
71685+}
71686+
71687+#ifdef CONFIG_COMPAT
71688+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71689+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71690+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71691+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71692+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71693+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71694+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71695+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71696+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71697+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71698+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71699+extern size_t get_gr_arg_wrapper_size_compat(void);
71700+
71701+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71702+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71703+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71704+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71705+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71706+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71707+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71708+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71709+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71710+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71711+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71712+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71713+
71714+#else
71715+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71716+#define copy_gr_arg copy_gr_arg_normal
71717+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71718+#define copy_acl_object_label copy_acl_object_label_normal
71719+#define copy_acl_subject_label copy_acl_subject_label_normal
71720+#define copy_acl_role_label copy_acl_role_label_normal
71721+#define copy_acl_ip_label copy_acl_ip_label_normal
71722+#define copy_pointer_from_array copy_pointer_from_array_normal
71723+#define copy_sprole_pw copy_sprole_pw_normal
71724+#define copy_role_transition copy_role_transition_normal
71725+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71726+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71727+#endif
71728+
71729+static struct acl_subject_label *
71730+lookup_subject_map(const struct acl_subject_label *userp)
71731+{
71732+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71733+ struct subject_map *match;
71734+
71735+ match = polstate->subj_map_set.s_hash[index];
71736+
71737+ while (match && match->user != userp)
71738+ match = match->next;
71739+
71740+ if (match != NULL)
71741+ return match->kernel;
71742+ else
71743+ return NULL;
71744+}
71745+
71746+static void
71747+insert_subj_map_entry(struct subject_map *subjmap)
71748+{
71749+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71750+ struct subject_map **curr;
71751+
71752+ subjmap->prev = NULL;
71753+
71754+ curr = &polstate->subj_map_set.s_hash[index];
71755+ if (*curr != NULL)
71756+ (*curr)->prev = subjmap;
71757+
71758+ subjmap->next = *curr;
71759+ *curr = subjmap;
71760+
71761+ return;
71762+}
71763+
71764+static void
71765+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71766+{
71767+ unsigned int index =
71768+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71769+ struct acl_role_label **curr;
71770+ struct acl_role_label *tmp, *tmp2;
71771+
71772+ curr = &polstate->acl_role_set.r_hash[index];
71773+
71774+ /* simple case, slot is empty, just set it to our role */
71775+ if (*curr == NULL) {
71776+ *curr = role;
71777+ } else {
71778+ /* example:
71779+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71780+ 2 -> 3
71781+ */
71782+ /* first check to see if we can already be reached via this slot */
71783+ tmp = *curr;
71784+ while (tmp && tmp != role)
71785+ tmp = tmp->next;
71786+ if (tmp == role) {
71787+ /* we don't need to add ourselves to this slot's chain */
71788+ return;
71789+ }
71790+ /* we need to add ourselves to this chain, two cases */
71791+ if (role->next == NULL) {
71792+ /* simple case, append the current chain to our role */
71793+ role->next = *curr;
71794+ *curr = role;
71795+ } else {
71796+ /* 1 -> 2 -> 3 -> 4
71797+ 2 -> 3 -> 4
71798+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71799+ */
71800+ /* trickier case: walk our role's chain until we find
71801+ the role for the start of the current slot's chain */
71802+ tmp = role;
71803+ tmp2 = *curr;
71804+ while (tmp->next && tmp->next != tmp2)
71805+ tmp = tmp->next;
71806+ if (tmp->next == tmp2) {
71807+ /* from example above, we found 3, so just
71808+ replace this slot's chain with ours */
71809+ *curr = role;
71810+ } else {
71811+ /* we didn't find a subset of our role's chain
71812+ in the current slot's chain, so append their
71813+ chain to ours, and set us as the first role in
71814+ the slot's chain
71815+
71816+ we could fold this case with the case above,
71817+ but making it explicit for clarity
71818+ */
71819+ tmp->next = tmp2;
71820+ *curr = role;
71821+ }
71822+ }
71823+ }
71824+
71825+ return;
71826+}
71827+
71828+static void
71829+insert_acl_role_label(struct acl_role_label *role)
71830+{
71831+ int i;
71832+
71833+ if (polstate->role_list == NULL) {
71834+ polstate->role_list = role;
71835+ role->prev = NULL;
71836+ } else {
71837+ role->prev = polstate->role_list;
71838+ polstate->role_list = role;
71839+ }
71840+
71841+ /* used for hash chains */
71842+ role->next = NULL;
71843+
71844+ if (role->roletype & GR_ROLE_DOMAIN) {
71845+ for (i = 0; i < role->domain_child_num; i++)
71846+ __insert_acl_role_label(role, role->domain_children[i]);
71847+ } else
71848+ __insert_acl_role_label(role, role->uidgid);
71849+}
71850+
71851+static int
71852+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71853+{
71854+ struct name_entry **curr, *nentry;
71855+ struct inodev_entry *ientry;
71856+ unsigned int len = strlen(name);
71857+ unsigned int key = full_name_hash(name, len);
71858+ unsigned int index = key % polstate->name_set.n_size;
71859+
71860+ curr = &polstate->name_set.n_hash[index];
71861+
71862+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71863+ curr = &((*curr)->next);
71864+
71865+ if (*curr != NULL)
71866+ return 1;
71867+
71868+ nentry = acl_alloc(sizeof (struct name_entry));
71869+ if (nentry == NULL)
71870+ return 0;
71871+ ientry = acl_alloc(sizeof (struct inodev_entry));
71872+ if (ientry == NULL)
71873+ return 0;
71874+ ientry->nentry = nentry;
71875+
71876+ nentry->key = key;
71877+ nentry->name = name;
71878+ nentry->inode = inode;
71879+ nentry->device = device;
71880+ nentry->len = len;
71881+ nentry->deleted = deleted;
71882+
71883+ nentry->prev = NULL;
71884+ curr = &polstate->name_set.n_hash[index];
71885+ if (*curr != NULL)
71886+ (*curr)->prev = nentry;
71887+ nentry->next = *curr;
71888+ *curr = nentry;
71889+
71890+ /* insert us into the table searchable by inode/dev */
71891+ __insert_inodev_entry(polstate, ientry);
71892+
71893+ return 1;
71894+}
71895+
71896+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71897+
71898+static void *
71899+create_table(__u32 * len, int elementsize)
71900+{
71901+ unsigned int table_sizes[] = {
71902+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71903+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71904+ 4194301, 8388593, 16777213, 33554393, 67108859
71905+ };
71906+ void *newtable = NULL;
71907+ unsigned int pwr = 0;
71908+
71909+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71910+ table_sizes[pwr] <= *len)
71911+ pwr++;
71912+
71913+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71914+ return newtable;
71915+
71916+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71917+ newtable =
71918+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71919+ else
71920+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71921+
71922+ *len = table_sizes[pwr];
71923+
71924+ return newtable;
71925+}
71926+
71927+static int
71928+init_variables(const struct gr_arg *arg, bool reload)
71929+{
71930+ struct task_struct *reaper = init_pid_ns.child_reaper;
71931+ unsigned int stacksize;
71932+
71933+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71934+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71935+ polstate->name_set.n_size = arg->role_db.num_objects;
71936+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71937+
71938+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71939+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71940+ return 1;
71941+
71942+ if (!reload) {
71943+ if (!gr_init_uidset())
71944+ return 1;
71945+ }
71946+
71947+ /* set up the stack that holds allocation info */
71948+
71949+ stacksize = arg->role_db.num_pointers + 5;
71950+
71951+ if (!acl_alloc_stack_init(stacksize))
71952+ return 1;
71953+
71954+ if (!reload) {
71955+ /* grab reference for the real root dentry and vfsmount */
71956+ get_fs_root(reaper->fs, &gr_real_root);
71957+
71958+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71959+ 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);
71960+#endif
71961+
71962+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71963+ if (fakefs_obj_rw == NULL)
71964+ return 1;
71965+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71966+
71967+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71968+ if (fakefs_obj_rwx == NULL)
71969+ return 1;
71970+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71971+ }
71972+
71973+ polstate->subj_map_set.s_hash =
71974+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71975+ polstate->acl_role_set.r_hash =
71976+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71977+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71978+ polstate->inodev_set.i_hash =
71979+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71980+
71981+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71982+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71983+ return 1;
71984+
71985+ memset(polstate->subj_map_set.s_hash, 0,
71986+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71987+ memset(polstate->acl_role_set.r_hash, 0,
71988+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71989+ memset(polstate->name_set.n_hash, 0,
71990+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71991+ memset(polstate->inodev_set.i_hash, 0,
71992+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71993+
71994+ return 0;
71995+}
71996+
71997+/* free information not needed after startup
71998+ currently contains user->kernel pointer mappings for subjects
71999+*/
72000+
72001+static void
72002+free_init_variables(void)
72003+{
72004+ __u32 i;
72005+
72006+ if (polstate->subj_map_set.s_hash) {
72007+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
72008+ if (polstate->subj_map_set.s_hash[i]) {
72009+ kfree(polstate->subj_map_set.s_hash[i]);
72010+ polstate->subj_map_set.s_hash[i] = NULL;
72011+ }
72012+ }
72013+
72014+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
72015+ PAGE_SIZE)
72016+ kfree(polstate->subj_map_set.s_hash);
72017+ else
72018+ vfree(polstate->subj_map_set.s_hash);
72019+ }
72020+
72021+ return;
72022+}
72023+
72024+static void
72025+free_variables(bool reload)
72026+{
72027+ struct acl_subject_label *s;
72028+ struct acl_role_label *r;
72029+ struct task_struct *task, *task2;
72030+ unsigned int x;
72031+
72032+ if (!reload) {
72033+ gr_clear_learn_entries();
72034+
72035+ read_lock(&tasklist_lock);
72036+ do_each_thread(task2, task) {
72037+ task->acl_sp_role = 0;
72038+ task->acl_role_id = 0;
72039+ task->inherited = 0;
72040+ task->acl = NULL;
72041+ task->role = NULL;
72042+ } while_each_thread(task2, task);
72043+ read_unlock(&tasklist_lock);
72044+
72045+ kfree(fakefs_obj_rw);
72046+ fakefs_obj_rw = NULL;
72047+ kfree(fakefs_obj_rwx);
72048+ fakefs_obj_rwx = NULL;
72049+
72050+ /* release the reference to the real root dentry and vfsmount */
72051+ path_put(&gr_real_root);
72052+ memset(&gr_real_root, 0, sizeof(gr_real_root));
72053+ }
72054+
72055+ /* free all object hash tables */
72056+
72057+ FOR_EACH_ROLE_START(r)
72058+ if (r->subj_hash == NULL)
72059+ goto next_role;
72060+ FOR_EACH_SUBJECT_START(r, s, x)
72061+ if (s->obj_hash == NULL)
72062+ break;
72063+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72064+ kfree(s->obj_hash);
72065+ else
72066+ vfree(s->obj_hash);
72067+ FOR_EACH_SUBJECT_END(s, x)
72068+ FOR_EACH_NESTED_SUBJECT_START(r, s)
72069+ if (s->obj_hash == NULL)
72070+ break;
72071+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72072+ kfree(s->obj_hash);
72073+ else
72074+ vfree(s->obj_hash);
72075+ FOR_EACH_NESTED_SUBJECT_END(s)
72076+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
72077+ kfree(r->subj_hash);
72078+ else
72079+ vfree(r->subj_hash);
72080+ r->subj_hash = NULL;
72081+next_role:
72082+ FOR_EACH_ROLE_END(r)
72083+
72084+ acl_free_all();
72085+
72086+ if (polstate->acl_role_set.r_hash) {
72087+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
72088+ PAGE_SIZE)
72089+ kfree(polstate->acl_role_set.r_hash);
72090+ else
72091+ vfree(polstate->acl_role_set.r_hash);
72092+ }
72093+ if (polstate->name_set.n_hash) {
72094+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
72095+ PAGE_SIZE)
72096+ kfree(polstate->name_set.n_hash);
72097+ else
72098+ vfree(polstate->name_set.n_hash);
72099+ }
72100+
72101+ if (polstate->inodev_set.i_hash) {
72102+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
72103+ PAGE_SIZE)
72104+ kfree(polstate->inodev_set.i_hash);
72105+ else
72106+ vfree(polstate->inodev_set.i_hash);
72107+ }
72108+
72109+ if (!reload)
72110+ gr_free_uidset();
72111+
72112+ memset(&polstate->name_set, 0, sizeof (struct name_db));
72113+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
72114+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
72115+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
72116+
72117+ polstate->default_role = NULL;
72118+ polstate->kernel_role = NULL;
72119+ polstate->role_list = NULL;
72120+
72121+ return;
72122+}
72123+
72124+static struct acl_subject_label *
72125+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
72126+
72127+static int alloc_and_copy_string(char **name, unsigned int maxlen)
72128+{
72129+ unsigned int len = strnlen_user(*name, maxlen);
72130+ char *tmp;
72131+
72132+ if (!len || len >= maxlen)
72133+ return -EINVAL;
72134+
72135+ if ((tmp = (char *) acl_alloc(len)) == NULL)
72136+ return -ENOMEM;
72137+
72138+ if (copy_from_user(tmp, *name, len))
72139+ return -EFAULT;
72140+
72141+ tmp[len-1] = '\0';
72142+ *name = tmp;
72143+
72144+ return 0;
72145+}
72146+
72147+static int
72148+copy_user_glob(struct acl_object_label *obj)
72149+{
72150+ struct acl_object_label *g_tmp, **guser;
72151+ int error;
72152+
72153+ if (obj->globbed == NULL)
72154+ return 0;
72155+
72156+ guser = &obj->globbed;
72157+ while (*guser) {
72158+ g_tmp = (struct acl_object_label *)
72159+ acl_alloc(sizeof (struct acl_object_label));
72160+ if (g_tmp == NULL)
72161+ return -ENOMEM;
72162+
72163+ if (copy_acl_object_label(g_tmp, *guser))
72164+ return -EFAULT;
72165+
72166+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72167+ if (error)
72168+ return error;
72169+
72170+ *guser = g_tmp;
72171+ guser = &(g_tmp->next);
72172+ }
72173+
72174+ return 0;
72175+}
72176+
72177+static int
72178+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72179+ struct acl_role_label *role)
72180+{
72181+ struct acl_object_label *o_tmp;
72182+ int ret;
72183+
72184+ while (userp) {
72185+ if ((o_tmp = (struct acl_object_label *)
72186+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
72187+ return -ENOMEM;
72188+
72189+ if (copy_acl_object_label(o_tmp, userp))
72190+ return -EFAULT;
72191+
72192+ userp = o_tmp->prev;
72193+
72194+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72195+ if (ret)
72196+ return ret;
72197+
72198+ insert_acl_obj_label(o_tmp, subj);
72199+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72200+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72201+ return -ENOMEM;
72202+
72203+ ret = copy_user_glob(o_tmp);
72204+ if (ret)
72205+ return ret;
72206+
72207+ if (o_tmp->nested) {
72208+ int already_copied;
72209+
72210+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72211+ if (IS_ERR(o_tmp->nested))
72212+ return PTR_ERR(o_tmp->nested);
72213+
72214+ /* insert into nested subject list if we haven't copied this one yet
72215+ to prevent duplicate entries */
72216+ if (!already_copied) {
72217+ o_tmp->nested->next = role->hash->first;
72218+ role->hash->first = o_tmp->nested;
72219+ }
72220+ }
72221+ }
72222+
72223+ return 0;
72224+}
72225+
72226+static __u32
72227+count_user_subjs(struct acl_subject_label *userp)
72228+{
72229+ struct acl_subject_label s_tmp;
72230+ __u32 num = 0;
72231+
72232+ while (userp) {
72233+ if (copy_acl_subject_label(&s_tmp, userp))
72234+ break;
72235+
72236+ userp = s_tmp.prev;
72237+ }
72238+
72239+ return num;
72240+}
72241+
72242+static int
72243+copy_user_allowedips(struct acl_role_label *rolep)
72244+{
72245+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72246+
72247+ ruserip = rolep->allowed_ips;
72248+
72249+ while (ruserip) {
72250+ rlast = rtmp;
72251+
72252+ if ((rtmp = (struct role_allowed_ip *)
72253+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72254+ return -ENOMEM;
72255+
72256+ if (copy_role_allowed_ip(rtmp, ruserip))
72257+ return -EFAULT;
72258+
72259+ ruserip = rtmp->prev;
72260+
72261+ if (!rlast) {
72262+ rtmp->prev = NULL;
72263+ rolep->allowed_ips = rtmp;
72264+ } else {
72265+ rlast->next = rtmp;
72266+ rtmp->prev = rlast;
72267+ }
72268+
72269+ if (!ruserip)
72270+ rtmp->next = NULL;
72271+ }
72272+
72273+ return 0;
72274+}
72275+
72276+static int
72277+copy_user_transitions(struct acl_role_label *rolep)
72278+{
72279+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
72280+ int error;
72281+
72282+ rusertp = rolep->transitions;
72283+
72284+ while (rusertp) {
72285+ rlast = rtmp;
72286+
72287+ if ((rtmp = (struct role_transition *)
72288+ acl_alloc(sizeof (struct role_transition))) == NULL)
72289+ return -ENOMEM;
72290+
72291+ if (copy_role_transition(rtmp, rusertp))
72292+ return -EFAULT;
72293+
72294+ rusertp = rtmp->prev;
72295+
72296+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72297+ if (error)
72298+ return error;
72299+
72300+ if (!rlast) {
72301+ rtmp->prev = NULL;
72302+ rolep->transitions = rtmp;
72303+ } else {
72304+ rlast->next = rtmp;
72305+ rtmp->prev = rlast;
72306+ }
72307+
72308+ if (!rusertp)
72309+ rtmp->next = NULL;
72310+ }
72311+
72312+ return 0;
72313+}
72314+
72315+static __u32 count_user_objs(const struct acl_object_label __user *userp)
72316+{
72317+ struct acl_object_label o_tmp;
72318+ __u32 num = 0;
72319+
72320+ while (userp) {
72321+ if (copy_acl_object_label(&o_tmp, userp))
72322+ break;
72323+
72324+ userp = o_tmp.prev;
72325+ num++;
72326+ }
72327+
72328+ return num;
72329+}
72330+
72331+static struct acl_subject_label *
72332+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72333+{
72334+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72335+ __u32 num_objs;
72336+ struct acl_ip_label **i_tmp, *i_utmp2;
72337+ struct gr_hash_struct ghash;
72338+ struct subject_map *subjmap;
72339+ unsigned int i_num;
72340+ int err;
72341+
72342+ if (already_copied != NULL)
72343+ *already_copied = 0;
72344+
72345+ s_tmp = lookup_subject_map(userp);
72346+
72347+ /* we've already copied this subject into the kernel, just return
72348+ the reference to it, and don't copy it over again
72349+ */
72350+ if (s_tmp) {
72351+ if (already_copied != NULL)
72352+ *already_copied = 1;
72353+ return(s_tmp);
72354+ }
72355+
72356+ if ((s_tmp = (struct acl_subject_label *)
72357+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72358+ return ERR_PTR(-ENOMEM);
72359+
72360+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72361+ if (subjmap == NULL)
72362+ return ERR_PTR(-ENOMEM);
72363+
72364+ subjmap->user = userp;
72365+ subjmap->kernel = s_tmp;
72366+ insert_subj_map_entry(subjmap);
72367+
72368+ if (copy_acl_subject_label(s_tmp, userp))
72369+ return ERR_PTR(-EFAULT);
72370+
72371+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72372+ if (err)
72373+ return ERR_PTR(err);
72374+
72375+ if (!strcmp(s_tmp->filename, "/"))
72376+ role->root_label = s_tmp;
72377+
72378+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72379+ return ERR_PTR(-EFAULT);
72380+
72381+ /* copy user and group transition tables */
72382+
72383+ if (s_tmp->user_trans_num) {
72384+ uid_t *uidlist;
72385+
72386+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72387+ if (uidlist == NULL)
72388+ return ERR_PTR(-ENOMEM);
72389+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72390+ return ERR_PTR(-EFAULT);
72391+
72392+ s_tmp->user_transitions = uidlist;
72393+ }
72394+
72395+ if (s_tmp->group_trans_num) {
72396+ gid_t *gidlist;
72397+
72398+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72399+ if (gidlist == NULL)
72400+ return ERR_PTR(-ENOMEM);
72401+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72402+ return ERR_PTR(-EFAULT);
72403+
72404+ s_tmp->group_transitions = gidlist;
72405+ }
72406+
72407+ /* set up object hash table */
72408+ num_objs = count_user_objs(ghash.first);
72409+
72410+ s_tmp->obj_hash_size = num_objs;
72411+ s_tmp->obj_hash =
72412+ (struct acl_object_label **)
72413+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72414+
72415+ if (!s_tmp->obj_hash)
72416+ return ERR_PTR(-ENOMEM);
72417+
72418+ memset(s_tmp->obj_hash, 0,
72419+ s_tmp->obj_hash_size *
72420+ sizeof (struct acl_object_label *));
72421+
72422+ /* add in objects */
72423+ err = copy_user_objs(ghash.first, s_tmp, role);
72424+
72425+ if (err)
72426+ return ERR_PTR(err);
72427+
72428+ /* set pointer for parent subject */
72429+ if (s_tmp->parent_subject) {
72430+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72431+
72432+ if (IS_ERR(s_tmp2))
72433+ return s_tmp2;
72434+
72435+ s_tmp->parent_subject = s_tmp2;
72436+ }
72437+
72438+ /* add in ip acls */
72439+
72440+ if (!s_tmp->ip_num) {
72441+ s_tmp->ips = NULL;
72442+ goto insert;
72443+ }
72444+
72445+ i_tmp =
72446+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72447+ sizeof (struct acl_ip_label *));
72448+
72449+ if (!i_tmp)
72450+ return ERR_PTR(-ENOMEM);
72451+
72452+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72453+ *(i_tmp + i_num) =
72454+ (struct acl_ip_label *)
72455+ acl_alloc(sizeof (struct acl_ip_label));
72456+ if (!*(i_tmp + i_num))
72457+ return ERR_PTR(-ENOMEM);
72458+
72459+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72460+ return ERR_PTR(-EFAULT);
72461+
72462+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72463+ return ERR_PTR(-EFAULT);
72464+
72465+ if ((*(i_tmp + i_num))->iface == NULL)
72466+ continue;
72467+
72468+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72469+ if (err)
72470+ return ERR_PTR(err);
72471+ }
72472+
72473+ s_tmp->ips = i_tmp;
72474+
72475+insert:
72476+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72477+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72478+ return ERR_PTR(-ENOMEM);
72479+
72480+ return s_tmp;
72481+}
72482+
72483+static int
72484+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72485+{
72486+ struct acl_subject_label s_pre;
72487+ struct acl_subject_label * ret;
72488+ int err;
72489+
72490+ while (userp) {
72491+ if (copy_acl_subject_label(&s_pre, userp))
72492+ return -EFAULT;
72493+
72494+ ret = do_copy_user_subj(userp, role, NULL);
72495+
72496+ err = PTR_ERR(ret);
72497+ if (IS_ERR(ret))
72498+ return err;
72499+
72500+ insert_acl_subj_label(ret, role);
72501+
72502+ userp = s_pre.prev;
72503+ }
72504+
72505+ return 0;
72506+}
72507+
72508+static int
72509+copy_user_acl(struct gr_arg *arg)
72510+{
72511+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72512+ struct acl_subject_label *subj_list;
72513+ struct sprole_pw *sptmp;
72514+ struct gr_hash_struct *ghash;
72515+ uid_t *domainlist;
72516+ unsigned int r_num;
72517+ int err = 0;
72518+ __u16 i;
72519+ __u32 num_subjs;
72520+
72521+ /* we need a default and kernel role */
72522+ if (arg->role_db.num_roles < 2)
72523+ return -EINVAL;
72524+
72525+ /* copy special role authentication info from userspace */
72526+
72527+ polstate->num_sprole_pws = arg->num_sprole_pws;
72528+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72529+
72530+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72531+ return -ENOMEM;
72532+
72533+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72534+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72535+ if (!sptmp)
72536+ return -ENOMEM;
72537+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72538+ return -EFAULT;
72539+
72540+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72541+ if (err)
72542+ return err;
72543+
72544+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72545+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72546+#endif
72547+
72548+ polstate->acl_special_roles[i] = sptmp;
72549+ }
72550+
72551+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72552+
72553+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72554+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72555+
72556+ if (!r_tmp)
72557+ return -ENOMEM;
72558+
72559+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72560+ return -EFAULT;
72561+
72562+ if (copy_acl_role_label(r_tmp, r_utmp2))
72563+ return -EFAULT;
72564+
72565+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72566+ if (err)
72567+ return err;
72568+
72569+ if (!strcmp(r_tmp->rolename, "default")
72570+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72571+ polstate->default_role = r_tmp;
72572+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72573+ polstate->kernel_role = r_tmp;
72574+ }
72575+
72576+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72577+ return -ENOMEM;
72578+
72579+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72580+ return -EFAULT;
72581+
72582+ r_tmp->hash = ghash;
72583+
72584+ num_subjs = count_user_subjs(r_tmp->hash->first);
72585+
72586+ r_tmp->subj_hash_size = num_subjs;
72587+ r_tmp->subj_hash =
72588+ (struct acl_subject_label **)
72589+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72590+
72591+ if (!r_tmp->subj_hash)
72592+ return -ENOMEM;
72593+
72594+ err = copy_user_allowedips(r_tmp);
72595+ if (err)
72596+ return err;
72597+
72598+ /* copy domain info */
72599+ if (r_tmp->domain_children != NULL) {
72600+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72601+ if (domainlist == NULL)
72602+ return -ENOMEM;
72603+
72604+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72605+ return -EFAULT;
72606+
72607+ r_tmp->domain_children = domainlist;
72608+ }
72609+
72610+ err = copy_user_transitions(r_tmp);
72611+ if (err)
72612+ return err;
72613+
72614+ memset(r_tmp->subj_hash, 0,
72615+ r_tmp->subj_hash_size *
72616+ sizeof (struct acl_subject_label *));
72617+
72618+ /* acquire the list of subjects, then NULL out
72619+ the list prior to parsing the subjects for this role,
72620+ as during this parsing the list is replaced with a list
72621+ of *nested* subjects for the role
72622+ */
72623+ subj_list = r_tmp->hash->first;
72624+
72625+ /* set nested subject list to null */
72626+ r_tmp->hash->first = NULL;
72627+
72628+ err = copy_user_subjs(subj_list, r_tmp);
72629+
72630+ if (err)
72631+ return err;
72632+
72633+ insert_acl_role_label(r_tmp);
72634+ }
72635+
72636+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72637+ return -EINVAL;
72638+
72639+ return err;
72640+}
72641+
72642+static int gracl_reload_apply_policies(void *reload)
72643+{
72644+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72645+ struct task_struct *task, *task2;
72646+ struct acl_role_label *role, *rtmp;
72647+ struct acl_subject_label *subj;
72648+ const struct cred *cred;
72649+ int role_applied;
72650+ int ret = 0;
72651+
72652+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72653+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72654+
72655+ /* first make sure we'll be able to apply the new policy cleanly */
72656+ do_each_thread(task2, task) {
72657+ if (task->exec_file == NULL)
72658+ continue;
72659+ role_applied = 0;
72660+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72661+ /* preserve special roles */
72662+ FOR_EACH_ROLE_START(role)
72663+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72664+ rtmp = task->role;
72665+ task->role = role;
72666+ role_applied = 1;
72667+ break;
72668+ }
72669+ FOR_EACH_ROLE_END(role)
72670+ }
72671+ if (!role_applied) {
72672+ cred = __task_cred(task);
72673+ rtmp = task->role;
72674+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72675+ }
72676+ /* this handles non-nested inherited subjects, nested subjects will still
72677+ be dropped currently */
72678+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72679+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72680+ /* change the role back so that we've made no modifications to the policy */
72681+ task->role = rtmp;
72682+
72683+ if (subj == NULL || task->tmpacl == NULL) {
72684+ ret = -EINVAL;
72685+ goto out;
72686+ }
72687+ } while_each_thread(task2, task);
72688+
72689+ /* now actually apply the policy */
72690+
72691+ do_each_thread(task2, task) {
72692+ if (task->exec_file) {
72693+ role_applied = 0;
72694+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72695+ /* preserve special roles */
72696+ FOR_EACH_ROLE_START(role)
72697+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72698+ task->role = role;
72699+ role_applied = 1;
72700+ break;
72701+ }
72702+ FOR_EACH_ROLE_END(role)
72703+ }
72704+ if (!role_applied) {
72705+ cred = __task_cred(task);
72706+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72707+ }
72708+ /* this handles non-nested inherited subjects, nested subjects will still
72709+ be dropped currently */
72710+ if (!reload_state->oldmode && task->inherited)
72711+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72712+ else {
72713+ /* looked up and tagged to the task previously */
72714+ subj = task->tmpacl;
72715+ }
72716+ /* subj will be non-null */
72717+ __gr_apply_subject_to_task(polstate, task, subj);
72718+ if (reload_state->oldmode) {
72719+ task->acl_role_id = 0;
72720+ task->acl_sp_role = 0;
72721+ task->inherited = 0;
72722+ }
72723+ } else {
72724+ // it's a kernel process
72725+ task->role = polstate->kernel_role;
72726+ task->acl = polstate->kernel_role->root_label;
72727+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72728+ task->acl->mode &= ~GR_PROCFIND;
72729+#endif
72730+ }
72731+ } while_each_thread(task2, task);
72732+
72733+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72734+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72735+
72736+out:
72737+
72738+ return ret;
72739+}
72740+
72741+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72742+{
72743+ struct gr_reload_state new_reload_state = { };
72744+ int err;
72745+
72746+ new_reload_state.oldpolicy_ptr = polstate;
72747+ new_reload_state.oldalloc_ptr = current_alloc_state;
72748+ new_reload_state.oldmode = oldmode;
72749+
72750+ current_alloc_state = &new_reload_state.newalloc;
72751+ polstate = &new_reload_state.newpolicy;
72752+
72753+ /* everything relevant is now saved off, copy in the new policy */
72754+ if (init_variables(args, true)) {
72755+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72756+ err = -ENOMEM;
72757+ goto error;
72758+ }
72759+
72760+ err = copy_user_acl(args);
72761+ free_init_variables();
72762+ if (err)
72763+ goto error;
72764+ /* the new policy is copied in, with the old policy available via saved_state
72765+ first go through applying roles, making sure to preserve special roles
72766+ then apply new subjects, making sure to preserve inherited and nested subjects,
72767+ though currently only inherited subjects will be preserved
72768+ */
72769+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72770+ if (err)
72771+ goto error;
72772+
72773+ /* we've now applied the new policy, so restore the old policy state to free it */
72774+ polstate = &new_reload_state.oldpolicy;
72775+ current_alloc_state = &new_reload_state.oldalloc;
72776+ free_variables(true);
72777+
72778+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72779+ to running_polstate/current_alloc_state inside stop_machine
72780+ */
72781+ err = 0;
72782+ goto out;
72783+error:
72784+ /* on error of loading the new policy, we'll just keep the previous
72785+ policy set around
72786+ */
72787+ free_variables(true);
72788+
72789+ /* doesn't affect runtime, but maintains consistent state */
72790+out:
72791+ polstate = new_reload_state.oldpolicy_ptr;
72792+ current_alloc_state = new_reload_state.oldalloc_ptr;
72793+
72794+ return err;
72795+}
72796+
72797+static int
72798+gracl_init(struct gr_arg *args)
72799+{
72800+ int error = 0;
72801+
72802+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
72803+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
72804+
72805+ if (init_variables(args, false)) {
72806+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72807+ error = -ENOMEM;
72808+ goto out;
72809+ }
72810+
72811+ error = copy_user_acl(args);
72812+ free_init_variables();
72813+ if (error)
72814+ goto out;
72815+
72816+ error = gr_set_acls(0);
72817+ if (error)
72818+ goto out;
72819+
72820+ gr_enable_rbac_system();
72821+
72822+ return 0;
72823+
72824+out:
72825+ free_variables(false);
72826+ return error;
72827+}
72828+
72829+static int
72830+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72831+ unsigned char **sum)
72832+{
72833+ struct acl_role_label *r;
72834+ struct role_allowed_ip *ipp;
72835+ struct role_transition *trans;
72836+ unsigned int i;
72837+ int found = 0;
72838+ u32 curr_ip = current->signal->curr_ip;
72839+
72840+ current->signal->saved_ip = curr_ip;
72841+
72842+ /* check transition table */
72843+
72844+ for (trans = current->role->transitions; trans; trans = trans->next) {
72845+ if (!strcmp(rolename, trans->rolename)) {
72846+ found = 1;
72847+ break;
72848+ }
72849+ }
72850+
72851+ if (!found)
72852+ return 0;
72853+
72854+ /* handle special roles that do not require authentication
72855+ and check ip */
72856+
72857+ FOR_EACH_ROLE_START(r)
72858+ if (!strcmp(rolename, r->rolename) &&
72859+ (r->roletype & GR_ROLE_SPECIAL)) {
72860+ found = 0;
72861+ if (r->allowed_ips != NULL) {
72862+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72863+ if ((ntohl(curr_ip) & ipp->netmask) ==
72864+ (ntohl(ipp->addr) & ipp->netmask))
72865+ found = 1;
72866+ }
72867+ } else
72868+ found = 2;
72869+ if (!found)
72870+ return 0;
72871+
72872+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72873+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72874+ *salt = NULL;
72875+ *sum = NULL;
72876+ return 1;
72877+ }
72878+ }
72879+ FOR_EACH_ROLE_END(r)
72880+
72881+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72882+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72883+ *salt = polstate->acl_special_roles[i]->salt;
72884+ *sum = polstate->acl_special_roles[i]->sum;
72885+ return 1;
72886+ }
72887+ }
72888+
72889+ return 0;
72890+}
72891+
72892+int gr_check_secure_terminal(struct task_struct *task)
72893+{
72894+ struct task_struct *p, *p2, *p3;
72895+ struct files_struct *files;
72896+ struct fdtable *fdt;
72897+ struct file *our_file = NULL, *file;
72898+ int i;
72899+
72900+ if (task->signal->tty == NULL)
72901+ return 1;
72902+
72903+ files = get_files_struct(task);
72904+ if (files != NULL) {
72905+ rcu_read_lock();
72906+ fdt = files_fdtable(files);
72907+ for (i=0; i < fdt->max_fds; i++) {
72908+ file = fcheck_files(files, i);
72909+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72910+ get_file(file);
72911+ our_file = file;
72912+ }
72913+ }
72914+ rcu_read_unlock();
72915+ put_files_struct(files);
72916+ }
72917+
72918+ if (our_file == NULL)
72919+ return 1;
72920+
72921+ read_lock(&tasklist_lock);
72922+ do_each_thread(p2, p) {
72923+ files = get_files_struct(p);
72924+ if (files == NULL ||
72925+ (p->signal && p->signal->tty == task->signal->tty)) {
72926+ if (files != NULL)
72927+ put_files_struct(files);
72928+ continue;
72929+ }
72930+ rcu_read_lock();
72931+ fdt = files_fdtable(files);
72932+ for (i=0; i < fdt->max_fds; i++) {
72933+ file = fcheck_files(files, i);
72934+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72935+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72936+ p3 = task;
72937+ while (task_pid_nr(p3) > 0) {
72938+ if (p3 == p)
72939+ break;
72940+ p3 = p3->real_parent;
72941+ }
72942+ if (p3 == p)
72943+ break;
72944+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72945+ gr_handle_alertkill(p);
72946+ rcu_read_unlock();
72947+ put_files_struct(files);
72948+ read_unlock(&tasklist_lock);
72949+ fput(our_file);
72950+ return 0;
72951+ }
72952+ }
72953+ rcu_read_unlock();
72954+ put_files_struct(files);
72955+ } while_each_thread(p2, p);
72956+ read_unlock(&tasklist_lock);
72957+
72958+ fput(our_file);
72959+ return 1;
72960+}
72961+
72962+ssize_t
72963+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72964+{
72965+ struct gr_arg_wrapper uwrap;
72966+ unsigned char *sprole_salt = NULL;
72967+ unsigned char *sprole_sum = NULL;
72968+ int error = 0;
72969+ int error2 = 0;
72970+ size_t req_count = 0;
72971+ unsigned char oldmode = 0;
72972+
72973+ mutex_lock(&gr_dev_mutex);
72974+
72975+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72976+ error = -EPERM;
72977+ goto out;
72978+ }
72979+
72980+#ifdef CONFIG_COMPAT
72981+ pax_open_kernel();
72982+ if (is_compat_task()) {
72983+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72984+ copy_gr_arg = &copy_gr_arg_compat;
72985+ copy_acl_object_label = &copy_acl_object_label_compat;
72986+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72987+ copy_acl_role_label = &copy_acl_role_label_compat;
72988+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72989+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72990+ copy_role_transition = &copy_role_transition_compat;
72991+ copy_sprole_pw = &copy_sprole_pw_compat;
72992+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72993+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72994+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72995+ } else {
72996+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72997+ copy_gr_arg = &copy_gr_arg_normal;
72998+ copy_acl_object_label = &copy_acl_object_label_normal;
72999+ copy_acl_subject_label = &copy_acl_subject_label_normal;
73000+ copy_acl_role_label = &copy_acl_role_label_normal;
73001+ copy_acl_ip_label = &copy_acl_ip_label_normal;
73002+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
73003+ copy_role_transition = &copy_role_transition_normal;
73004+ copy_sprole_pw = &copy_sprole_pw_normal;
73005+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
73006+ copy_pointer_from_array = &copy_pointer_from_array_normal;
73007+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
73008+ }
73009+ pax_close_kernel();
73010+#endif
73011+
73012+ req_count = get_gr_arg_wrapper_size();
73013+
73014+ if (count != req_count) {
73015+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
73016+ error = -EINVAL;
73017+ goto out;
73018+ }
73019+
73020+
73021+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
73022+ gr_auth_expires = 0;
73023+ gr_auth_attempts = 0;
73024+ }
73025+
73026+ error = copy_gr_arg_wrapper(buf, &uwrap);
73027+ if (error)
73028+ goto out;
73029+
73030+ error = copy_gr_arg(uwrap.arg, gr_usermode);
73031+ if (error)
73032+ goto out;
73033+
73034+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
73035+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73036+ time_after(gr_auth_expires, get_seconds())) {
73037+ error = -EBUSY;
73038+ goto out;
73039+ }
73040+
73041+ /* if non-root trying to do anything other than use a special role,
73042+ do not attempt authentication, do not count towards authentication
73043+ locking
73044+ */
73045+
73046+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
73047+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
73048+ gr_is_global_nonroot(current_uid())) {
73049+ error = -EPERM;
73050+ goto out;
73051+ }
73052+
73053+ /* ensure pw and special role name are null terminated */
73054+
73055+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
73056+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
73057+
73058+ /* Okay.
73059+ * We have our enough of the argument structure..(we have yet
73060+ * to copy_from_user the tables themselves) . Copy the tables
73061+ * only if we need them, i.e. for loading operations. */
73062+
73063+ switch (gr_usermode->mode) {
73064+ case GR_STATUS:
73065+ if (gr_acl_is_enabled()) {
73066+ error = 1;
73067+ if (!gr_check_secure_terminal(current))
73068+ error = 3;
73069+ } else
73070+ error = 2;
73071+ goto out;
73072+ case GR_SHUTDOWN:
73073+ if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73074+ stop_machine(gr_rbac_disable, NULL, NULL);
73075+ free_variables(false);
73076+ memset(gr_usermode, 0, sizeof(struct gr_arg));
73077+ memset(gr_system_salt, 0, GR_SALT_LEN);
73078+ memset(gr_system_sum, 0, GR_SHA_LEN);
73079+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
73080+ } else if (gr_acl_is_enabled()) {
73081+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
73082+ error = -EPERM;
73083+ } else {
73084+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
73085+ error = -EAGAIN;
73086+ }
73087+ break;
73088+ case GR_ENABLE:
73089+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
73090+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
73091+ else {
73092+ if (gr_acl_is_enabled())
73093+ error = -EAGAIN;
73094+ else
73095+ error = error2;
73096+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
73097+ }
73098+ break;
73099+ case GR_OLDRELOAD:
73100+ oldmode = 1;
73101+ case GR_RELOAD:
73102+ if (!gr_acl_is_enabled()) {
73103+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
73104+ error = -EAGAIN;
73105+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73106+ error2 = gracl_reload(gr_usermode, oldmode);
73107+ if (!error2)
73108+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
73109+ else {
73110+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73111+ error = error2;
73112+ }
73113+ } else {
73114+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73115+ error = -EPERM;
73116+ }
73117+ break;
73118+ case GR_SEGVMOD:
73119+ if (unlikely(!gr_acl_is_enabled())) {
73120+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
73121+ error = -EAGAIN;
73122+ break;
73123+ }
73124+
73125+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73126+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
73127+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
73128+ struct acl_subject_label *segvacl;
73129+ segvacl =
73130+ lookup_acl_subj_label(gr_usermode->segv_inode,
73131+ gr_usermode->segv_device,
73132+ current->role);
73133+ if (segvacl) {
73134+ segvacl->crashes = 0;
73135+ segvacl->expires = 0;
73136+ }
73137+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
73138+ gr_remove_uid(gr_usermode->segv_uid);
73139+ }
73140+ } else {
73141+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
73142+ error = -EPERM;
73143+ }
73144+ break;
73145+ case GR_SPROLE:
73146+ case GR_SPROLEPAM:
73147+ if (unlikely(!gr_acl_is_enabled())) {
73148+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73149+ error = -EAGAIN;
73150+ break;
73151+ }
73152+
73153+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73154+ current->role->expires = 0;
73155+ current->role->auth_attempts = 0;
73156+ }
73157+
73158+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73159+ time_after(current->role->expires, get_seconds())) {
73160+ error = -EBUSY;
73161+ goto out;
73162+ }
73163+
73164+ if (lookup_special_role_auth
73165+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
73166+ && ((!sprole_salt && !sprole_sum)
73167+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
73168+ char *p = "";
73169+ assign_special_role(gr_usermode->sp_role);
73170+ read_lock(&tasklist_lock);
73171+ if (current->real_parent)
73172+ p = current->real_parent->role->rolename;
73173+ read_unlock(&tasklist_lock);
73174+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73175+ p, acl_sp_role_value);
73176+ } else {
73177+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
73178+ error = -EPERM;
73179+ if(!(current->role->auth_attempts++))
73180+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73181+
73182+ goto out;
73183+ }
73184+ break;
73185+ case GR_UNSPROLE:
73186+ if (unlikely(!gr_acl_is_enabled())) {
73187+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73188+ error = -EAGAIN;
73189+ break;
73190+ }
73191+
73192+ if (current->role->roletype & GR_ROLE_SPECIAL) {
73193+ char *p = "";
73194+ int i = 0;
73195+
73196+ read_lock(&tasklist_lock);
73197+ if (current->real_parent) {
73198+ p = current->real_parent->role->rolename;
73199+ i = current->real_parent->acl_role_id;
73200+ }
73201+ read_unlock(&tasklist_lock);
73202+
73203+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73204+ gr_set_acls(1);
73205+ } else {
73206+ error = -EPERM;
73207+ goto out;
73208+ }
73209+ break;
73210+ default:
73211+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
73212+ error = -EINVAL;
73213+ break;
73214+ }
73215+
73216+ if (error != -EPERM)
73217+ goto out;
73218+
73219+ if(!(gr_auth_attempts++))
73220+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73221+
73222+ out:
73223+ mutex_unlock(&gr_dev_mutex);
73224+
73225+ if (!error)
73226+ error = req_count;
73227+
73228+ return error;
73229+}
73230+
73231+int
73232+gr_set_acls(const int type)
73233+{
73234+ struct task_struct *task, *task2;
73235+ struct acl_role_label *role = current->role;
73236+ struct acl_subject_label *subj;
73237+ __u16 acl_role_id = current->acl_role_id;
73238+ const struct cred *cred;
73239+ int ret;
73240+
73241+ rcu_read_lock();
73242+ read_lock(&tasklist_lock);
73243+ read_lock(&grsec_exec_file_lock);
73244+ do_each_thread(task2, task) {
73245+ /* check to see if we're called from the exit handler,
73246+ if so, only replace ACLs that have inherited the admin
73247+ ACL */
73248+
73249+ if (type && (task->role != role ||
73250+ task->acl_role_id != acl_role_id))
73251+ continue;
73252+
73253+ task->acl_role_id = 0;
73254+ task->acl_sp_role = 0;
73255+ task->inherited = 0;
73256+
73257+ if (task->exec_file) {
73258+ cred = __task_cred(task);
73259+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73260+ subj = __gr_get_subject_for_task(polstate, task, NULL);
73261+ if (subj == NULL) {
73262+ ret = -EINVAL;
73263+ read_unlock(&grsec_exec_file_lock);
73264+ read_unlock(&tasklist_lock);
73265+ rcu_read_unlock();
73266+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73267+ return ret;
73268+ }
73269+ __gr_apply_subject_to_task(polstate, task, subj);
73270+ } else {
73271+ // it's a kernel process
73272+ task->role = polstate->kernel_role;
73273+ task->acl = polstate->kernel_role->root_label;
73274+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73275+ task->acl->mode &= ~GR_PROCFIND;
73276+#endif
73277+ }
73278+ } while_each_thread(task2, task);
73279+ read_unlock(&grsec_exec_file_lock);
73280+ read_unlock(&tasklist_lock);
73281+ rcu_read_unlock();
73282+
73283+ return 0;
73284+}
73285diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73286new file mode 100644
73287index 0000000..39645c9
73288--- /dev/null
73289+++ b/grsecurity/gracl_res.c
73290@@ -0,0 +1,68 @@
73291+#include <linux/kernel.h>
73292+#include <linux/sched.h>
73293+#include <linux/gracl.h>
73294+#include <linux/grinternal.h>
73295+
73296+static const char *restab_log[] = {
73297+ [RLIMIT_CPU] = "RLIMIT_CPU",
73298+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73299+ [RLIMIT_DATA] = "RLIMIT_DATA",
73300+ [RLIMIT_STACK] = "RLIMIT_STACK",
73301+ [RLIMIT_CORE] = "RLIMIT_CORE",
73302+ [RLIMIT_RSS] = "RLIMIT_RSS",
73303+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
73304+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73305+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73306+ [RLIMIT_AS] = "RLIMIT_AS",
73307+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73308+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73309+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73310+ [RLIMIT_NICE] = "RLIMIT_NICE",
73311+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73312+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73313+ [GR_CRASH_RES] = "RLIMIT_CRASH"
73314+};
73315+
73316+void
73317+gr_log_resource(const struct task_struct *task,
73318+ const int res, const unsigned long wanted, const int gt)
73319+{
73320+ const struct cred *cred;
73321+ unsigned long rlim;
73322+
73323+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
73324+ return;
73325+
73326+ // not yet supported resource
73327+ if (unlikely(!restab_log[res]))
73328+ return;
73329+
73330+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73331+ rlim = task_rlimit_max(task, res);
73332+ else
73333+ rlim = task_rlimit(task, res);
73334+
73335+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73336+ return;
73337+
73338+ rcu_read_lock();
73339+ cred = __task_cred(task);
73340+
73341+ if (res == RLIMIT_NPROC &&
73342+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73343+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73344+ goto out_rcu_unlock;
73345+ else if (res == RLIMIT_MEMLOCK &&
73346+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73347+ goto out_rcu_unlock;
73348+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73349+ goto out_rcu_unlock;
73350+ rcu_read_unlock();
73351+
73352+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73353+
73354+ return;
73355+out_rcu_unlock:
73356+ rcu_read_unlock();
73357+ return;
73358+}
73359diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73360new file mode 100644
73361index 0000000..2040e61
73362--- /dev/null
73363+++ b/grsecurity/gracl_segv.c
73364@@ -0,0 +1,313 @@
73365+#include <linux/kernel.h>
73366+#include <linux/mm.h>
73367+#include <asm/uaccess.h>
73368+#include <asm/errno.h>
73369+#include <asm/mman.h>
73370+#include <net/sock.h>
73371+#include <linux/file.h>
73372+#include <linux/fs.h>
73373+#include <linux/net.h>
73374+#include <linux/in.h>
73375+#include <linux/slab.h>
73376+#include <linux/types.h>
73377+#include <linux/sched.h>
73378+#include <linux/timer.h>
73379+#include <linux/gracl.h>
73380+#include <linux/grsecurity.h>
73381+#include <linux/grinternal.h>
73382+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73383+#include <linux/magic.h>
73384+#include <linux/pagemap.h>
73385+#include "../fs/btrfs/async-thread.h"
73386+#include "../fs/btrfs/ctree.h"
73387+#include "../fs/btrfs/btrfs_inode.h"
73388+#endif
73389+
73390+static struct crash_uid *uid_set;
73391+static unsigned short uid_used;
73392+static DEFINE_SPINLOCK(gr_uid_lock);
73393+extern rwlock_t gr_inode_lock;
73394+extern struct acl_subject_label *
73395+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73396+ struct acl_role_label *role);
73397+
73398+static inline dev_t __get_dev(const struct dentry *dentry)
73399+{
73400+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73401+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73402+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
73403+ else
73404+#endif
73405+ return dentry->d_sb->s_dev;
73406+}
73407+
73408+int
73409+gr_init_uidset(void)
73410+{
73411+ uid_set =
73412+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73413+ uid_used = 0;
73414+
73415+ return uid_set ? 1 : 0;
73416+}
73417+
73418+void
73419+gr_free_uidset(void)
73420+{
73421+ if (uid_set) {
73422+ struct crash_uid *tmpset;
73423+ spin_lock(&gr_uid_lock);
73424+ tmpset = uid_set;
73425+ uid_set = NULL;
73426+ uid_used = 0;
73427+ spin_unlock(&gr_uid_lock);
73428+ if (tmpset)
73429+ kfree(tmpset);
73430+ }
73431+
73432+ return;
73433+}
73434+
73435+int
73436+gr_find_uid(const uid_t uid)
73437+{
73438+ struct crash_uid *tmp = uid_set;
73439+ uid_t buid;
73440+ int low = 0, high = uid_used - 1, mid;
73441+
73442+ while (high >= low) {
73443+ mid = (low + high) >> 1;
73444+ buid = tmp[mid].uid;
73445+ if (buid == uid)
73446+ return mid;
73447+ if (buid > uid)
73448+ high = mid - 1;
73449+ if (buid < uid)
73450+ low = mid + 1;
73451+ }
73452+
73453+ return -1;
73454+}
73455+
73456+static __inline__ void
73457+gr_insertsort(void)
73458+{
73459+ unsigned short i, j;
73460+ struct crash_uid index;
73461+
73462+ for (i = 1; i < uid_used; i++) {
73463+ index = uid_set[i];
73464+ j = i;
73465+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73466+ uid_set[j] = uid_set[j - 1];
73467+ j--;
73468+ }
73469+ uid_set[j] = index;
73470+ }
73471+
73472+ return;
73473+}
73474+
73475+static __inline__ void
73476+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73477+{
73478+ int loc;
73479+ uid_t uid = GR_GLOBAL_UID(kuid);
73480+
73481+ if (uid_used == GR_UIDTABLE_MAX)
73482+ return;
73483+
73484+ loc = gr_find_uid(uid);
73485+
73486+ if (loc >= 0) {
73487+ uid_set[loc].expires = expires;
73488+ return;
73489+ }
73490+
73491+ uid_set[uid_used].uid = uid;
73492+ uid_set[uid_used].expires = expires;
73493+ uid_used++;
73494+
73495+ gr_insertsort();
73496+
73497+ return;
73498+}
73499+
73500+void
73501+gr_remove_uid(const unsigned short loc)
73502+{
73503+ unsigned short i;
73504+
73505+ for (i = loc + 1; i < uid_used; i++)
73506+ uid_set[i - 1] = uid_set[i];
73507+
73508+ uid_used--;
73509+
73510+ return;
73511+}
73512+
73513+int
73514+gr_check_crash_uid(const kuid_t kuid)
73515+{
73516+ int loc;
73517+ int ret = 0;
73518+ uid_t uid;
73519+
73520+ if (unlikely(!gr_acl_is_enabled()))
73521+ return 0;
73522+
73523+ uid = GR_GLOBAL_UID(kuid);
73524+
73525+ spin_lock(&gr_uid_lock);
73526+ loc = gr_find_uid(uid);
73527+
73528+ if (loc < 0)
73529+ goto out_unlock;
73530+
73531+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73532+ gr_remove_uid(loc);
73533+ else
73534+ ret = 1;
73535+
73536+out_unlock:
73537+ spin_unlock(&gr_uid_lock);
73538+ return ret;
73539+}
73540+
73541+static __inline__ int
73542+proc_is_setxid(const struct cred *cred)
73543+{
73544+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73545+ !uid_eq(cred->uid, cred->fsuid))
73546+ return 1;
73547+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73548+ !gid_eq(cred->gid, cred->fsgid))
73549+ return 1;
73550+
73551+ return 0;
73552+}
73553+
73554+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73555+
73556+void
73557+gr_handle_crash(struct task_struct *task, const int sig)
73558+{
73559+ struct acl_subject_label *curr;
73560+ struct task_struct *tsk, *tsk2;
73561+ const struct cred *cred;
73562+ const struct cred *cred2;
73563+
73564+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73565+ return;
73566+
73567+ if (unlikely(!gr_acl_is_enabled()))
73568+ return;
73569+
73570+ curr = task->acl;
73571+
73572+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73573+ return;
73574+
73575+ if (time_before_eq(curr->expires, get_seconds())) {
73576+ curr->expires = 0;
73577+ curr->crashes = 0;
73578+ }
73579+
73580+ curr->crashes++;
73581+
73582+ if (!curr->expires)
73583+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73584+
73585+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73586+ time_after(curr->expires, get_seconds())) {
73587+ rcu_read_lock();
73588+ cred = __task_cred(task);
73589+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73590+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73591+ spin_lock(&gr_uid_lock);
73592+ gr_insert_uid(cred->uid, curr->expires);
73593+ spin_unlock(&gr_uid_lock);
73594+ curr->expires = 0;
73595+ curr->crashes = 0;
73596+ read_lock(&tasklist_lock);
73597+ do_each_thread(tsk2, tsk) {
73598+ cred2 = __task_cred(tsk);
73599+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73600+ gr_fake_force_sig(SIGKILL, tsk);
73601+ } while_each_thread(tsk2, tsk);
73602+ read_unlock(&tasklist_lock);
73603+ } else {
73604+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73605+ read_lock(&tasklist_lock);
73606+ read_lock(&grsec_exec_file_lock);
73607+ do_each_thread(tsk2, tsk) {
73608+ if (likely(tsk != task)) {
73609+ // if this thread has the same subject as the one that triggered
73610+ // RES_CRASH and it's the same binary, kill it
73611+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73612+ gr_fake_force_sig(SIGKILL, tsk);
73613+ }
73614+ } while_each_thread(tsk2, tsk);
73615+ read_unlock(&grsec_exec_file_lock);
73616+ read_unlock(&tasklist_lock);
73617+ }
73618+ rcu_read_unlock();
73619+ }
73620+
73621+ return;
73622+}
73623+
73624+int
73625+gr_check_crash_exec(const struct file *filp)
73626+{
73627+ struct acl_subject_label *curr;
73628+
73629+ if (unlikely(!gr_acl_is_enabled()))
73630+ return 0;
73631+
73632+ read_lock(&gr_inode_lock);
73633+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73634+ __get_dev(filp->f_path.dentry),
73635+ current->role);
73636+ read_unlock(&gr_inode_lock);
73637+
73638+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73639+ (!curr->crashes && !curr->expires))
73640+ return 0;
73641+
73642+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73643+ time_after(curr->expires, get_seconds()))
73644+ return 1;
73645+ else if (time_before_eq(curr->expires, get_seconds())) {
73646+ curr->crashes = 0;
73647+ curr->expires = 0;
73648+ }
73649+
73650+ return 0;
73651+}
73652+
73653+void
73654+gr_handle_alertkill(struct task_struct *task)
73655+{
73656+ struct acl_subject_label *curracl;
73657+ __u32 curr_ip;
73658+ struct task_struct *p, *p2;
73659+
73660+ if (unlikely(!gr_acl_is_enabled()))
73661+ return;
73662+
73663+ curracl = task->acl;
73664+ curr_ip = task->signal->curr_ip;
73665+
73666+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73667+ read_lock(&tasklist_lock);
73668+ do_each_thread(p2, p) {
73669+ if (p->signal->curr_ip == curr_ip)
73670+ gr_fake_force_sig(SIGKILL, p);
73671+ } while_each_thread(p2, p);
73672+ read_unlock(&tasklist_lock);
73673+ } else if (curracl->mode & GR_KILLPROC)
73674+ gr_fake_force_sig(SIGKILL, task);
73675+
73676+ return;
73677+}
73678diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73679new file mode 100644
73680index 0000000..98011b0
73681--- /dev/null
73682+++ b/grsecurity/gracl_shm.c
73683@@ -0,0 +1,40 @@
73684+#include <linux/kernel.h>
73685+#include <linux/mm.h>
73686+#include <linux/sched.h>
73687+#include <linux/file.h>
73688+#include <linux/ipc.h>
73689+#include <linux/gracl.h>
73690+#include <linux/grsecurity.h>
73691+#include <linux/grinternal.h>
73692+
73693+int
73694+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73695+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73696+{
73697+ struct task_struct *task;
73698+
73699+ if (!gr_acl_is_enabled())
73700+ return 1;
73701+
73702+ rcu_read_lock();
73703+ read_lock(&tasklist_lock);
73704+
73705+ task = find_task_by_vpid(shm_cprid);
73706+
73707+ if (unlikely(!task))
73708+ task = find_task_by_vpid(shm_lapid);
73709+
73710+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73711+ (task_pid_nr(task) == shm_lapid)) &&
73712+ (task->acl->mode & GR_PROTSHM) &&
73713+ (task->acl != current->acl))) {
73714+ read_unlock(&tasklist_lock);
73715+ rcu_read_unlock();
73716+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73717+ return 0;
73718+ }
73719+ read_unlock(&tasklist_lock);
73720+ rcu_read_unlock();
73721+
73722+ return 1;
73723+}
73724diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73725new file mode 100644
73726index 0000000..bc0be01
73727--- /dev/null
73728+++ b/grsecurity/grsec_chdir.c
73729@@ -0,0 +1,19 @@
73730+#include <linux/kernel.h>
73731+#include <linux/sched.h>
73732+#include <linux/fs.h>
73733+#include <linux/file.h>
73734+#include <linux/grsecurity.h>
73735+#include <linux/grinternal.h>
73736+
73737+void
73738+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73739+{
73740+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73741+ if ((grsec_enable_chdir && grsec_enable_group &&
73742+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73743+ !grsec_enable_group)) {
73744+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73745+ }
73746+#endif
73747+ return;
73748+}
73749diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73750new file mode 100644
73751index 0000000..baa635c
73752--- /dev/null
73753+++ b/grsecurity/grsec_chroot.c
73754@@ -0,0 +1,387 @@
73755+#include <linux/kernel.h>
73756+#include <linux/module.h>
73757+#include <linux/sched.h>
73758+#include <linux/file.h>
73759+#include <linux/fs.h>
73760+#include <linux/mount.h>
73761+#include <linux/types.h>
73762+#include "../fs/mount.h"
73763+#include <linux/grsecurity.h>
73764+#include <linux/grinternal.h>
73765+
73766+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73767+int gr_init_ran;
73768+#endif
73769+
73770+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73771+{
73772+#ifdef CONFIG_GRKERNSEC
73773+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73774+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73775+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73776+ && gr_init_ran
73777+#endif
73778+ )
73779+ task->gr_is_chrooted = 1;
73780+ else {
73781+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73782+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73783+ gr_init_ran = 1;
73784+#endif
73785+ task->gr_is_chrooted = 0;
73786+ }
73787+
73788+ task->gr_chroot_dentry = path->dentry;
73789+#endif
73790+ return;
73791+}
73792+
73793+void gr_clear_chroot_entries(struct task_struct *task)
73794+{
73795+#ifdef CONFIG_GRKERNSEC
73796+ task->gr_is_chrooted = 0;
73797+ task->gr_chroot_dentry = NULL;
73798+#endif
73799+ return;
73800+}
73801+
73802+int
73803+gr_handle_chroot_unix(const pid_t pid)
73804+{
73805+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73806+ struct task_struct *p;
73807+
73808+ if (unlikely(!grsec_enable_chroot_unix))
73809+ return 1;
73810+
73811+ if (likely(!proc_is_chrooted(current)))
73812+ return 1;
73813+
73814+ rcu_read_lock();
73815+ read_lock(&tasklist_lock);
73816+ p = find_task_by_vpid_unrestricted(pid);
73817+ if (unlikely(p && !have_same_root(current, p))) {
73818+ read_unlock(&tasklist_lock);
73819+ rcu_read_unlock();
73820+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73821+ return 0;
73822+ }
73823+ read_unlock(&tasklist_lock);
73824+ rcu_read_unlock();
73825+#endif
73826+ return 1;
73827+}
73828+
73829+int
73830+gr_handle_chroot_nice(void)
73831+{
73832+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73833+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73834+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73835+ return -EPERM;
73836+ }
73837+#endif
73838+ return 0;
73839+}
73840+
73841+int
73842+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73843+{
73844+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73845+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73846+ && proc_is_chrooted(current)) {
73847+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73848+ return -EACCES;
73849+ }
73850+#endif
73851+ return 0;
73852+}
73853+
73854+int
73855+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73856+{
73857+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73858+ struct task_struct *p;
73859+ int ret = 0;
73860+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73861+ return ret;
73862+
73863+ read_lock(&tasklist_lock);
73864+ do_each_pid_task(pid, type, p) {
73865+ if (!have_same_root(current, p)) {
73866+ ret = 1;
73867+ goto out;
73868+ }
73869+ } while_each_pid_task(pid, type, p);
73870+out:
73871+ read_unlock(&tasklist_lock);
73872+ return ret;
73873+#endif
73874+ return 0;
73875+}
73876+
73877+int
73878+gr_pid_is_chrooted(struct task_struct *p)
73879+{
73880+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73881+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73882+ return 0;
73883+
73884+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73885+ !have_same_root(current, p)) {
73886+ return 1;
73887+ }
73888+#endif
73889+ return 0;
73890+}
73891+
73892+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73893+
73894+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73895+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73896+{
73897+ struct path path, currentroot;
73898+ int ret = 0;
73899+
73900+ path.dentry = (struct dentry *)u_dentry;
73901+ path.mnt = (struct vfsmount *)u_mnt;
73902+ get_fs_root(current->fs, &currentroot);
73903+ if (path_is_under(&path, &currentroot))
73904+ ret = 1;
73905+ path_put(&currentroot);
73906+
73907+ return ret;
73908+}
73909+#endif
73910+
73911+int
73912+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73913+{
73914+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73915+ if (!grsec_enable_chroot_fchdir)
73916+ return 1;
73917+
73918+ if (!proc_is_chrooted(current))
73919+ return 1;
73920+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73921+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73922+ return 0;
73923+ }
73924+#endif
73925+ return 1;
73926+}
73927+
73928+int
73929+gr_chroot_fhandle(void)
73930+{
73931+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73932+ if (!grsec_enable_chroot_fchdir)
73933+ return 1;
73934+
73935+ if (!proc_is_chrooted(current))
73936+ return 1;
73937+ else {
73938+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
73939+ return 0;
73940+ }
73941+#endif
73942+ return 1;
73943+}
73944+
73945+int
73946+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73947+ const time_t shm_createtime)
73948+{
73949+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73950+ struct task_struct *p;
73951+ time_t starttime;
73952+
73953+ if (unlikely(!grsec_enable_chroot_shmat))
73954+ return 1;
73955+
73956+ if (likely(!proc_is_chrooted(current)))
73957+ return 1;
73958+
73959+ rcu_read_lock();
73960+ read_lock(&tasklist_lock);
73961+
73962+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73963+ starttime = p->start_time.tv_sec;
73964+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73965+ if (have_same_root(current, p)) {
73966+ goto allow;
73967+ } else {
73968+ read_unlock(&tasklist_lock);
73969+ rcu_read_unlock();
73970+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73971+ return 0;
73972+ }
73973+ }
73974+ /* creator exited, pid reuse, fall through to next check */
73975+ }
73976+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73977+ if (unlikely(!have_same_root(current, p))) {
73978+ read_unlock(&tasklist_lock);
73979+ rcu_read_unlock();
73980+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73981+ return 0;
73982+ }
73983+ }
73984+
73985+allow:
73986+ read_unlock(&tasklist_lock);
73987+ rcu_read_unlock();
73988+#endif
73989+ return 1;
73990+}
73991+
73992+void
73993+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73994+{
73995+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73996+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73997+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73998+#endif
73999+ return;
74000+}
74001+
74002+int
74003+gr_handle_chroot_mknod(const struct dentry *dentry,
74004+ const struct vfsmount *mnt, const int mode)
74005+{
74006+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74007+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
74008+ proc_is_chrooted(current)) {
74009+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
74010+ return -EPERM;
74011+ }
74012+#endif
74013+ return 0;
74014+}
74015+
74016+int
74017+gr_handle_chroot_mount(const struct dentry *dentry,
74018+ const struct vfsmount *mnt, const char *dev_name)
74019+{
74020+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74021+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
74022+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
74023+ return -EPERM;
74024+ }
74025+#endif
74026+ return 0;
74027+}
74028+
74029+int
74030+gr_handle_chroot_pivot(void)
74031+{
74032+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74033+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
74034+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
74035+ return -EPERM;
74036+ }
74037+#endif
74038+ return 0;
74039+}
74040+
74041+int
74042+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
74043+{
74044+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74045+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
74046+ !gr_is_outside_chroot(dentry, mnt)) {
74047+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
74048+ return -EPERM;
74049+ }
74050+#endif
74051+ return 0;
74052+}
74053+
74054+extern const char *captab_log[];
74055+extern int captab_log_entries;
74056+
74057+int
74058+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74059+{
74060+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74061+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74062+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74063+ if (cap_raised(chroot_caps, cap)) {
74064+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
74065+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
74066+ }
74067+ return 0;
74068+ }
74069+ }
74070+#endif
74071+ return 1;
74072+}
74073+
74074+int
74075+gr_chroot_is_capable(const int cap)
74076+{
74077+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74078+ return gr_task_chroot_is_capable(current, current_cred(), cap);
74079+#endif
74080+ return 1;
74081+}
74082+
74083+int
74084+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
74085+{
74086+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74087+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74088+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74089+ if (cap_raised(chroot_caps, cap)) {
74090+ return 0;
74091+ }
74092+ }
74093+#endif
74094+ return 1;
74095+}
74096+
74097+int
74098+gr_chroot_is_capable_nolog(const int cap)
74099+{
74100+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74101+ return gr_task_chroot_is_capable_nolog(current, cap);
74102+#endif
74103+ return 1;
74104+}
74105+
74106+int
74107+gr_handle_chroot_sysctl(const int op)
74108+{
74109+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74110+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
74111+ proc_is_chrooted(current))
74112+ return -EACCES;
74113+#endif
74114+ return 0;
74115+}
74116+
74117+void
74118+gr_handle_chroot_chdir(const struct path *path)
74119+{
74120+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74121+ if (grsec_enable_chroot_chdir)
74122+ set_fs_pwd(current->fs, path);
74123+#endif
74124+ return;
74125+}
74126+
74127+int
74128+gr_handle_chroot_chmod(const struct dentry *dentry,
74129+ const struct vfsmount *mnt, const int mode)
74130+{
74131+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74132+ /* allow chmod +s on directories, but not files */
74133+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
74134+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
74135+ proc_is_chrooted(current)) {
74136+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
74137+ return -EPERM;
74138+ }
74139+#endif
74140+ return 0;
74141+}
74142diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
74143new file mode 100644
74144index 0000000..de31e65
74145--- /dev/null
74146+++ b/grsecurity/grsec_disabled.c
74147@@ -0,0 +1,434 @@
74148+#include <linux/kernel.h>
74149+#include <linux/module.h>
74150+#include <linux/sched.h>
74151+#include <linux/file.h>
74152+#include <linux/fs.h>
74153+#include <linux/kdev_t.h>
74154+#include <linux/net.h>
74155+#include <linux/in.h>
74156+#include <linux/ip.h>
74157+#include <linux/skbuff.h>
74158+#include <linux/sysctl.h>
74159+
74160+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74161+void
74162+pax_set_initial_flags(struct linux_binprm *bprm)
74163+{
74164+ return;
74165+}
74166+#endif
74167+
74168+#ifdef CONFIG_SYSCTL
74169+__u32
74170+gr_handle_sysctl(const struct ctl_table * table, const int op)
74171+{
74172+ return 0;
74173+}
74174+#endif
74175+
74176+#ifdef CONFIG_TASKSTATS
74177+int gr_is_taskstats_denied(int pid)
74178+{
74179+ return 0;
74180+}
74181+#endif
74182+
74183+int
74184+gr_acl_is_enabled(void)
74185+{
74186+ return 0;
74187+}
74188+
74189+void
74190+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74191+{
74192+ return;
74193+}
74194+
74195+int
74196+gr_handle_rawio(const struct inode *inode)
74197+{
74198+ return 0;
74199+}
74200+
74201+void
74202+gr_acl_handle_psacct(struct task_struct *task, const long code)
74203+{
74204+ return;
74205+}
74206+
74207+int
74208+gr_handle_ptrace(struct task_struct *task, const long request)
74209+{
74210+ return 0;
74211+}
74212+
74213+int
74214+gr_handle_proc_ptrace(struct task_struct *task)
74215+{
74216+ return 0;
74217+}
74218+
74219+int
74220+gr_set_acls(const int type)
74221+{
74222+ return 0;
74223+}
74224+
74225+int
74226+gr_check_hidden_task(const struct task_struct *tsk)
74227+{
74228+ return 0;
74229+}
74230+
74231+int
74232+gr_check_protected_task(const struct task_struct *task)
74233+{
74234+ return 0;
74235+}
74236+
74237+int
74238+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74239+{
74240+ return 0;
74241+}
74242+
74243+void
74244+gr_copy_label(struct task_struct *tsk)
74245+{
74246+ return;
74247+}
74248+
74249+void
74250+gr_set_pax_flags(struct task_struct *task)
74251+{
74252+ return;
74253+}
74254+
74255+int
74256+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74257+ const int unsafe_share)
74258+{
74259+ return 0;
74260+}
74261+
74262+void
74263+gr_handle_delete(const ino_t ino, const dev_t dev)
74264+{
74265+ return;
74266+}
74267+
74268+void
74269+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74270+{
74271+ return;
74272+}
74273+
74274+void
74275+gr_handle_crash(struct task_struct *task, const int sig)
74276+{
74277+ return;
74278+}
74279+
74280+int
74281+gr_check_crash_exec(const struct file *filp)
74282+{
74283+ return 0;
74284+}
74285+
74286+int
74287+gr_check_crash_uid(const kuid_t uid)
74288+{
74289+ return 0;
74290+}
74291+
74292+void
74293+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74294+ struct dentry *old_dentry,
74295+ struct dentry *new_dentry,
74296+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
74297+{
74298+ return;
74299+}
74300+
74301+int
74302+gr_search_socket(const int family, const int type, const int protocol)
74303+{
74304+ return 1;
74305+}
74306+
74307+int
74308+gr_search_connectbind(const int mode, const struct socket *sock,
74309+ const struct sockaddr_in *addr)
74310+{
74311+ return 0;
74312+}
74313+
74314+void
74315+gr_handle_alertkill(struct task_struct *task)
74316+{
74317+ return;
74318+}
74319+
74320+__u32
74321+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74322+{
74323+ return 1;
74324+}
74325+
74326+__u32
74327+gr_acl_handle_hidden_file(const struct dentry * dentry,
74328+ const struct vfsmount * mnt)
74329+{
74330+ return 1;
74331+}
74332+
74333+__u32
74334+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74335+ int acc_mode)
74336+{
74337+ return 1;
74338+}
74339+
74340+__u32
74341+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74342+{
74343+ return 1;
74344+}
74345+
74346+__u32
74347+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74348+{
74349+ return 1;
74350+}
74351+
74352+int
74353+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74354+ unsigned int *vm_flags)
74355+{
74356+ return 1;
74357+}
74358+
74359+__u32
74360+gr_acl_handle_truncate(const struct dentry * dentry,
74361+ const struct vfsmount * mnt)
74362+{
74363+ return 1;
74364+}
74365+
74366+__u32
74367+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74368+{
74369+ return 1;
74370+}
74371+
74372+__u32
74373+gr_acl_handle_access(const struct dentry * dentry,
74374+ const struct vfsmount * mnt, const int fmode)
74375+{
74376+ return 1;
74377+}
74378+
74379+__u32
74380+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74381+ umode_t *mode)
74382+{
74383+ return 1;
74384+}
74385+
74386+__u32
74387+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74388+{
74389+ return 1;
74390+}
74391+
74392+__u32
74393+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74394+{
74395+ return 1;
74396+}
74397+
74398+__u32
74399+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74400+{
74401+ return 1;
74402+}
74403+
74404+void
74405+grsecurity_init(void)
74406+{
74407+ return;
74408+}
74409+
74410+umode_t gr_acl_umask(void)
74411+{
74412+ return 0;
74413+}
74414+
74415+__u32
74416+gr_acl_handle_mknod(const struct dentry * new_dentry,
74417+ const struct dentry * parent_dentry,
74418+ const struct vfsmount * parent_mnt,
74419+ const int mode)
74420+{
74421+ return 1;
74422+}
74423+
74424+__u32
74425+gr_acl_handle_mkdir(const struct dentry * new_dentry,
74426+ const struct dentry * parent_dentry,
74427+ const struct vfsmount * parent_mnt)
74428+{
74429+ return 1;
74430+}
74431+
74432+__u32
74433+gr_acl_handle_symlink(const struct dentry * new_dentry,
74434+ const struct dentry * parent_dentry,
74435+ const struct vfsmount * parent_mnt, const struct filename *from)
74436+{
74437+ return 1;
74438+}
74439+
74440+__u32
74441+gr_acl_handle_link(const struct dentry * new_dentry,
74442+ const struct dentry * parent_dentry,
74443+ const struct vfsmount * parent_mnt,
74444+ const struct dentry * old_dentry,
74445+ const struct vfsmount * old_mnt, const struct filename *to)
74446+{
74447+ return 1;
74448+}
74449+
74450+int
74451+gr_acl_handle_rename(const struct dentry *new_dentry,
74452+ const struct dentry *parent_dentry,
74453+ const struct vfsmount *parent_mnt,
74454+ const struct dentry *old_dentry,
74455+ const struct inode *old_parent_inode,
74456+ const struct vfsmount *old_mnt, const struct filename *newname,
74457+ unsigned int flags)
74458+{
74459+ return 0;
74460+}
74461+
74462+int
74463+gr_acl_handle_filldir(const struct file *file, const char *name,
74464+ const int namelen, const ino_t ino)
74465+{
74466+ return 1;
74467+}
74468+
74469+int
74470+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74471+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74472+{
74473+ return 1;
74474+}
74475+
74476+int
74477+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74478+{
74479+ return 0;
74480+}
74481+
74482+int
74483+gr_search_accept(const struct socket *sock)
74484+{
74485+ return 0;
74486+}
74487+
74488+int
74489+gr_search_listen(const struct socket *sock)
74490+{
74491+ return 0;
74492+}
74493+
74494+int
74495+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74496+{
74497+ return 0;
74498+}
74499+
74500+__u32
74501+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74502+{
74503+ return 1;
74504+}
74505+
74506+__u32
74507+gr_acl_handle_creat(const struct dentry * dentry,
74508+ const struct dentry * p_dentry,
74509+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74510+ const int imode)
74511+{
74512+ return 1;
74513+}
74514+
74515+void
74516+gr_acl_handle_exit(void)
74517+{
74518+ return;
74519+}
74520+
74521+int
74522+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74523+{
74524+ return 1;
74525+}
74526+
74527+void
74528+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74529+{
74530+ return;
74531+}
74532+
74533+int
74534+gr_acl_handle_procpidmem(const struct task_struct *task)
74535+{
74536+ return 0;
74537+}
74538+
74539+int
74540+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74541+{
74542+ return 0;
74543+}
74544+
74545+int
74546+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74547+{
74548+ return 0;
74549+}
74550+
74551+int
74552+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74553+{
74554+ return 0;
74555+}
74556+
74557+int
74558+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74559+{
74560+ return 0;
74561+}
74562+
74563+int gr_acl_enable_at_secure(void)
74564+{
74565+ return 0;
74566+}
74567+
74568+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74569+{
74570+ return dentry->d_sb->s_dev;
74571+}
74572+
74573+void gr_put_exec_file(struct task_struct *task)
74574+{
74575+ return;
74576+}
74577+
74578+#ifdef CONFIG_SECURITY
74579+EXPORT_SYMBOL_GPL(gr_check_user_change);
74580+EXPORT_SYMBOL_GPL(gr_check_group_change);
74581+#endif
74582diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74583new file mode 100644
74584index 0000000..14638ff
74585--- /dev/null
74586+++ b/grsecurity/grsec_exec.c
74587@@ -0,0 +1,188 @@
74588+#include <linux/kernel.h>
74589+#include <linux/sched.h>
74590+#include <linux/file.h>
74591+#include <linux/binfmts.h>
74592+#include <linux/fs.h>
74593+#include <linux/types.h>
74594+#include <linux/grdefs.h>
74595+#include <linux/grsecurity.h>
74596+#include <linux/grinternal.h>
74597+#include <linux/capability.h>
74598+#include <linux/module.h>
74599+#include <linux/compat.h>
74600+
74601+#include <asm/uaccess.h>
74602+
74603+#ifdef CONFIG_GRKERNSEC_EXECLOG
74604+static char gr_exec_arg_buf[132];
74605+static DEFINE_MUTEX(gr_exec_arg_mutex);
74606+#endif
74607+
74608+struct user_arg_ptr {
74609+#ifdef CONFIG_COMPAT
74610+ bool is_compat;
74611+#endif
74612+ union {
74613+ const char __user *const __user *native;
74614+#ifdef CONFIG_COMPAT
74615+ const compat_uptr_t __user *compat;
74616+#endif
74617+ } ptr;
74618+};
74619+
74620+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74621+
74622+void
74623+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74624+{
74625+#ifdef CONFIG_GRKERNSEC_EXECLOG
74626+ char *grarg = gr_exec_arg_buf;
74627+ unsigned int i, x, execlen = 0;
74628+ char c;
74629+
74630+ if (!((grsec_enable_execlog && grsec_enable_group &&
74631+ in_group_p(grsec_audit_gid))
74632+ || (grsec_enable_execlog && !grsec_enable_group)))
74633+ return;
74634+
74635+ mutex_lock(&gr_exec_arg_mutex);
74636+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74637+
74638+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74639+ const char __user *p;
74640+ unsigned int len;
74641+
74642+ p = get_user_arg_ptr(argv, i);
74643+ if (IS_ERR(p))
74644+ goto log;
74645+
74646+ len = strnlen_user(p, 128 - execlen);
74647+ if (len > 128 - execlen)
74648+ len = 128 - execlen;
74649+ else if (len > 0)
74650+ len--;
74651+ if (copy_from_user(grarg + execlen, p, len))
74652+ goto log;
74653+
74654+ /* rewrite unprintable characters */
74655+ for (x = 0; x < len; x++) {
74656+ c = *(grarg + execlen + x);
74657+ if (c < 32 || c > 126)
74658+ *(grarg + execlen + x) = ' ';
74659+ }
74660+
74661+ execlen += len;
74662+ *(grarg + execlen) = ' ';
74663+ *(grarg + execlen + 1) = '\0';
74664+ execlen++;
74665+ }
74666+
74667+ log:
74668+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74669+ bprm->file->f_path.mnt, grarg);
74670+ mutex_unlock(&gr_exec_arg_mutex);
74671+#endif
74672+ return;
74673+}
74674+
74675+#ifdef CONFIG_GRKERNSEC
74676+extern int gr_acl_is_capable(const int cap);
74677+extern int gr_acl_is_capable_nolog(const int cap);
74678+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74679+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74680+extern int gr_chroot_is_capable(const int cap);
74681+extern int gr_chroot_is_capable_nolog(const int cap);
74682+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74683+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74684+#endif
74685+
74686+const char *captab_log[] = {
74687+ "CAP_CHOWN",
74688+ "CAP_DAC_OVERRIDE",
74689+ "CAP_DAC_READ_SEARCH",
74690+ "CAP_FOWNER",
74691+ "CAP_FSETID",
74692+ "CAP_KILL",
74693+ "CAP_SETGID",
74694+ "CAP_SETUID",
74695+ "CAP_SETPCAP",
74696+ "CAP_LINUX_IMMUTABLE",
74697+ "CAP_NET_BIND_SERVICE",
74698+ "CAP_NET_BROADCAST",
74699+ "CAP_NET_ADMIN",
74700+ "CAP_NET_RAW",
74701+ "CAP_IPC_LOCK",
74702+ "CAP_IPC_OWNER",
74703+ "CAP_SYS_MODULE",
74704+ "CAP_SYS_RAWIO",
74705+ "CAP_SYS_CHROOT",
74706+ "CAP_SYS_PTRACE",
74707+ "CAP_SYS_PACCT",
74708+ "CAP_SYS_ADMIN",
74709+ "CAP_SYS_BOOT",
74710+ "CAP_SYS_NICE",
74711+ "CAP_SYS_RESOURCE",
74712+ "CAP_SYS_TIME",
74713+ "CAP_SYS_TTY_CONFIG",
74714+ "CAP_MKNOD",
74715+ "CAP_LEASE",
74716+ "CAP_AUDIT_WRITE",
74717+ "CAP_AUDIT_CONTROL",
74718+ "CAP_SETFCAP",
74719+ "CAP_MAC_OVERRIDE",
74720+ "CAP_MAC_ADMIN",
74721+ "CAP_SYSLOG",
74722+ "CAP_WAKE_ALARM",
74723+ "CAP_BLOCK_SUSPEND"
74724+};
74725+
74726+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74727+
74728+int gr_is_capable(const int cap)
74729+{
74730+#ifdef CONFIG_GRKERNSEC
74731+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74732+ return 1;
74733+ return 0;
74734+#else
74735+ return 1;
74736+#endif
74737+}
74738+
74739+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74740+{
74741+#ifdef CONFIG_GRKERNSEC
74742+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74743+ return 1;
74744+ return 0;
74745+#else
74746+ return 1;
74747+#endif
74748+}
74749+
74750+int gr_is_capable_nolog(const int cap)
74751+{
74752+#ifdef CONFIG_GRKERNSEC
74753+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74754+ return 1;
74755+ return 0;
74756+#else
74757+ return 1;
74758+#endif
74759+}
74760+
74761+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74762+{
74763+#ifdef CONFIG_GRKERNSEC
74764+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74765+ return 1;
74766+ return 0;
74767+#else
74768+ return 1;
74769+#endif
74770+}
74771+
74772+EXPORT_SYMBOL_GPL(gr_is_capable);
74773+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74774+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74775+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74776diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74777new file mode 100644
74778index 0000000..06cc6ea
74779--- /dev/null
74780+++ b/grsecurity/grsec_fifo.c
74781@@ -0,0 +1,24 @@
74782+#include <linux/kernel.h>
74783+#include <linux/sched.h>
74784+#include <linux/fs.h>
74785+#include <linux/file.h>
74786+#include <linux/grinternal.h>
74787+
74788+int
74789+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74790+ const struct dentry *dir, const int flag, const int acc_mode)
74791+{
74792+#ifdef CONFIG_GRKERNSEC_FIFO
74793+ const struct cred *cred = current_cred();
74794+
74795+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74796+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74797+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74798+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74799+ if (!inode_permission(dentry->d_inode, acc_mode))
74800+ 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));
74801+ return -EACCES;
74802+ }
74803+#endif
74804+ return 0;
74805+}
74806diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74807new file mode 100644
74808index 0000000..8ca18bf
74809--- /dev/null
74810+++ b/grsecurity/grsec_fork.c
74811@@ -0,0 +1,23 @@
74812+#include <linux/kernel.h>
74813+#include <linux/sched.h>
74814+#include <linux/grsecurity.h>
74815+#include <linux/grinternal.h>
74816+#include <linux/errno.h>
74817+
74818+void
74819+gr_log_forkfail(const int retval)
74820+{
74821+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74822+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74823+ switch (retval) {
74824+ case -EAGAIN:
74825+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74826+ break;
74827+ case -ENOMEM:
74828+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74829+ break;
74830+ }
74831+ }
74832+#endif
74833+ return;
74834+}
74835diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74836new file mode 100644
74837index 0000000..b7cb191
74838--- /dev/null
74839+++ b/grsecurity/grsec_init.c
74840@@ -0,0 +1,286 @@
74841+#include <linux/kernel.h>
74842+#include <linux/sched.h>
74843+#include <linux/mm.h>
74844+#include <linux/gracl.h>
74845+#include <linux/slab.h>
74846+#include <linux/vmalloc.h>
74847+#include <linux/percpu.h>
74848+#include <linux/module.h>
74849+
74850+int grsec_enable_ptrace_readexec;
74851+int grsec_enable_setxid;
74852+int grsec_enable_symlinkown;
74853+kgid_t grsec_symlinkown_gid;
74854+int grsec_enable_brute;
74855+int grsec_enable_link;
74856+int grsec_enable_dmesg;
74857+int grsec_enable_harden_ptrace;
74858+int grsec_enable_harden_ipc;
74859+int grsec_enable_fifo;
74860+int grsec_enable_execlog;
74861+int grsec_enable_signal;
74862+int grsec_enable_forkfail;
74863+int grsec_enable_audit_ptrace;
74864+int grsec_enable_time;
74865+int grsec_enable_group;
74866+kgid_t grsec_audit_gid;
74867+int grsec_enable_chdir;
74868+int grsec_enable_mount;
74869+int grsec_enable_rofs;
74870+int grsec_deny_new_usb;
74871+int grsec_enable_chroot_findtask;
74872+int grsec_enable_chroot_mount;
74873+int grsec_enable_chroot_shmat;
74874+int grsec_enable_chroot_fchdir;
74875+int grsec_enable_chroot_double;
74876+int grsec_enable_chroot_pivot;
74877+int grsec_enable_chroot_chdir;
74878+int grsec_enable_chroot_chmod;
74879+int grsec_enable_chroot_mknod;
74880+int grsec_enable_chroot_nice;
74881+int grsec_enable_chroot_execlog;
74882+int grsec_enable_chroot_caps;
74883+int grsec_enable_chroot_sysctl;
74884+int grsec_enable_chroot_unix;
74885+int grsec_enable_tpe;
74886+kgid_t grsec_tpe_gid;
74887+int grsec_enable_blackhole;
74888+#ifdef CONFIG_IPV6_MODULE
74889+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74890+#endif
74891+int grsec_lastack_retries;
74892+int grsec_enable_tpe_all;
74893+int grsec_enable_tpe_invert;
74894+int grsec_enable_socket_all;
74895+kgid_t grsec_socket_all_gid;
74896+int grsec_enable_socket_client;
74897+kgid_t grsec_socket_client_gid;
74898+int grsec_enable_socket_server;
74899+kgid_t grsec_socket_server_gid;
74900+int grsec_resource_logging;
74901+int grsec_disable_privio;
74902+int grsec_enable_log_rwxmaps;
74903+int grsec_lock;
74904+
74905+DEFINE_SPINLOCK(grsec_alert_lock);
74906+unsigned long grsec_alert_wtime = 0;
74907+unsigned long grsec_alert_fyet = 0;
74908+
74909+DEFINE_SPINLOCK(grsec_audit_lock);
74910+
74911+DEFINE_RWLOCK(grsec_exec_file_lock);
74912+
74913+char *gr_shared_page[4];
74914+
74915+char *gr_alert_log_fmt;
74916+char *gr_audit_log_fmt;
74917+char *gr_alert_log_buf;
74918+char *gr_audit_log_buf;
74919+
74920+extern struct gr_arg *gr_usermode;
74921+extern unsigned char *gr_system_salt;
74922+extern unsigned char *gr_system_sum;
74923+
74924+void __init
74925+grsecurity_init(void)
74926+{
74927+ int j;
74928+ /* create the per-cpu shared pages */
74929+
74930+#ifdef CONFIG_X86
74931+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74932+#endif
74933+
74934+ for (j = 0; j < 4; j++) {
74935+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74936+ if (gr_shared_page[j] == NULL) {
74937+ panic("Unable to allocate grsecurity shared page");
74938+ return;
74939+ }
74940+ }
74941+
74942+ /* allocate log buffers */
74943+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74944+ if (!gr_alert_log_fmt) {
74945+ panic("Unable to allocate grsecurity alert log format buffer");
74946+ return;
74947+ }
74948+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74949+ if (!gr_audit_log_fmt) {
74950+ panic("Unable to allocate grsecurity audit log format buffer");
74951+ return;
74952+ }
74953+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74954+ if (!gr_alert_log_buf) {
74955+ panic("Unable to allocate grsecurity alert log buffer");
74956+ return;
74957+ }
74958+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74959+ if (!gr_audit_log_buf) {
74960+ panic("Unable to allocate grsecurity audit log buffer");
74961+ return;
74962+ }
74963+
74964+ /* allocate memory for authentication structure */
74965+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
74966+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
74967+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
74968+
74969+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
74970+ panic("Unable to allocate grsecurity authentication structure");
74971+ return;
74972+ }
74973+
74974+#ifdef CONFIG_GRKERNSEC_IO
74975+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74976+ grsec_disable_privio = 1;
74977+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74978+ grsec_disable_privio = 1;
74979+#else
74980+ grsec_disable_privio = 0;
74981+#endif
74982+#endif
74983+
74984+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74985+ /* for backward compatibility, tpe_invert always defaults to on if
74986+ enabled in the kernel
74987+ */
74988+ grsec_enable_tpe_invert = 1;
74989+#endif
74990+
74991+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74992+#ifndef CONFIG_GRKERNSEC_SYSCTL
74993+ grsec_lock = 1;
74994+#endif
74995+
74996+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74997+ grsec_enable_log_rwxmaps = 1;
74998+#endif
74999+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75000+ grsec_enable_group = 1;
75001+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
75002+#endif
75003+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75004+ grsec_enable_ptrace_readexec = 1;
75005+#endif
75006+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75007+ grsec_enable_chdir = 1;
75008+#endif
75009+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75010+ grsec_enable_harden_ptrace = 1;
75011+#endif
75012+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75013+ grsec_enable_harden_ipc = 1;
75014+#endif
75015+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75016+ grsec_enable_mount = 1;
75017+#endif
75018+#ifdef CONFIG_GRKERNSEC_LINK
75019+ grsec_enable_link = 1;
75020+#endif
75021+#ifdef CONFIG_GRKERNSEC_BRUTE
75022+ grsec_enable_brute = 1;
75023+#endif
75024+#ifdef CONFIG_GRKERNSEC_DMESG
75025+ grsec_enable_dmesg = 1;
75026+#endif
75027+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75028+ grsec_enable_blackhole = 1;
75029+ grsec_lastack_retries = 4;
75030+#endif
75031+#ifdef CONFIG_GRKERNSEC_FIFO
75032+ grsec_enable_fifo = 1;
75033+#endif
75034+#ifdef CONFIG_GRKERNSEC_EXECLOG
75035+ grsec_enable_execlog = 1;
75036+#endif
75037+#ifdef CONFIG_GRKERNSEC_SETXID
75038+ grsec_enable_setxid = 1;
75039+#endif
75040+#ifdef CONFIG_GRKERNSEC_SIGNAL
75041+ grsec_enable_signal = 1;
75042+#endif
75043+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75044+ grsec_enable_forkfail = 1;
75045+#endif
75046+#ifdef CONFIG_GRKERNSEC_TIME
75047+ grsec_enable_time = 1;
75048+#endif
75049+#ifdef CONFIG_GRKERNSEC_RESLOG
75050+ grsec_resource_logging = 1;
75051+#endif
75052+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75053+ grsec_enable_chroot_findtask = 1;
75054+#endif
75055+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75056+ grsec_enable_chroot_unix = 1;
75057+#endif
75058+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75059+ grsec_enable_chroot_mount = 1;
75060+#endif
75061+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75062+ grsec_enable_chroot_fchdir = 1;
75063+#endif
75064+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75065+ grsec_enable_chroot_shmat = 1;
75066+#endif
75067+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75068+ grsec_enable_audit_ptrace = 1;
75069+#endif
75070+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75071+ grsec_enable_chroot_double = 1;
75072+#endif
75073+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75074+ grsec_enable_chroot_pivot = 1;
75075+#endif
75076+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75077+ grsec_enable_chroot_chdir = 1;
75078+#endif
75079+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75080+ grsec_enable_chroot_chmod = 1;
75081+#endif
75082+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75083+ grsec_enable_chroot_mknod = 1;
75084+#endif
75085+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75086+ grsec_enable_chroot_nice = 1;
75087+#endif
75088+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75089+ grsec_enable_chroot_execlog = 1;
75090+#endif
75091+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75092+ grsec_enable_chroot_caps = 1;
75093+#endif
75094+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75095+ grsec_enable_chroot_sysctl = 1;
75096+#endif
75097+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75098+ grsec_enable_symlinkown = 1;
75099+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
75100+#endif
75101+#ifdef CONFIG_GRKERNSEC_TPE
75102+ grsec_enable_tpe = 1;
75103+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
75104+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75105+ grsec_enable_tpe_all = 1;
75106+#endif
75107+#endif
75108+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75109+ grsec_enable_socket_all = 1;
75110+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
75111+#endif
75112+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75113+ grsec_enable_socket_client = 1;
75114+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
75115+#endif
75116+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75117+ grsec_enable_socket_server = 1;
75118+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
75119+#endif
75120+#endif
75121+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
75122+ grsec_deny_new_usb = 1;
75123+#endif
75124+
75125+ return;
75126+}
75127diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
75128new file mode 100644
75129index 0000000..1773300
75130--- /dev/null
75131+++ b/grsecurity/grsec_ipc.c
75132@@ -0,0 +1,48 @@
75133+#include <linux/kernel.h>
75134+#include <linux/mm.h>
75135+#include <linux/sched.h>
75136+#include <linux/file.h>
75137+#include <linux/ipc.h>
75138+#include <linux/ipc_namespace.h>
75139+#include <linux/grsecurity.h>
75140+#include <linux/grinternal.h>
75141+
75142+int
75143+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
75144+{
75145+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75146+ int write;
75147+ int orig_granted_mode;
75148+ kuid_t euid;
75149+ kgid_t egid;
75150+
75151+ if (!grsec_enable_harden_ipc)
75152+ return 1;
75153+
75154+ euid = current_euid();
75155+ egid = current_egid();
75156+
75157+ write = requested_mode & 00002;
75158+ orig_granted_mode = ipcp->mode;
75159+
75160+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
75161+ orig_granted_mode >>= 6;
75162+ else {
75163+ /* if likely wrong permissions, lock to user */
75164+ if (orig_granted_mode & 0007)
75165+ orig_granted_mode = 0;
75166+ /* otherwise do a egid-only check */
75167+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
75168+ orig_granted_mode >>= 3;
75169+ /* otherwise, no access */
75170+ else
75171+ orig_granted_mode = 0;
75172+ }
75173+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
75174+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
75175+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
75176+ return 0;
75177+ }
75178+#endif
75179+ return 1;
75180+}
75181diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75182new file mode 100644
75183index 0000000..5e05e20
75184--- /dev/null
75185+++ b/grsecurity/grsec_link.c
75186@@ -0,0 +1,58 @@
75187+#include <linux/kernel.h>
75188+#include <linux/sched.h>
75189+#include <linux/fs.h>
75190+#include <linux/file.h>
75191+#include <linux/grinternal.h>
75192+
75193+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75194+{
75195+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75196+ const struct inode *link_inode = link->dentry->d_inode;
75197+
75198+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75199+ /* ignore root-owned links, e.g. /proc/self */
75200+ gr_is_global_nonroot(link_inode->i_uid) && target &&
75201+ !uid_eq(link_inode->i_uid, target->i_uid)) {
75202+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75203+ return 1;
75204+ }
75205+#endif
75206+ return 0;
75207+}
75208+
75209+int
75210+gr_handle_follow_link(const struct inode *parent,
75211+ const struct inode *inode,
75212+ const struct dentry *dentry, const struct vfsmount *mnt)
75213+{
75214+#ifdef CONFIG_GRKERNSEC_LINK
75215+ const struct cred *cred = current_cred();
75216+
75217+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75218+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75219+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75220+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75221+ return -EACCES;
75222+ }
75223+#endif
75224+ return 0;
75225+}
75226+
75227+int
75228+gr_handle_hardlink(const struct dentry *dentry,
75229+ const struct vfsmount *mnt,
75230+ struct inode *inode, const int mode, const struct filename *to)
75231+{
75232+#ifdef CONFIG_GRKERNSEC_LINK
75233+ const struct cred *cred = current_cred();
75234+
75235+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75236+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75237+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75238+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75239+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75240+ return -EPERM;
75241+ }
75242+#endif
75243+ return 0;
75244+}
75245diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75246new file mode 100644
75247index 0000000..dbe0a6b
75248--- /dev/null
75249+++ b/grsecurity/grsec_log.c
75250@@ -0,0 +1,341 @@
75251+#include <linux/kernel.h>
75252+#include <linux/sched.h>
75253+#include <linux/file.h>
75254+#include <linux/tty.h>
75255+#include <linux/fs.h>
75256+#include <linux/mm.h>
75257+#include <linux/grinternal.h>
75258+
75259+#ifdef CONFIG_TREE_PREEMPT_RCU
75260+#define DISABLE_PREEMPT() preempt_disable()
75261+#define ENABLE_PREEMPT() preempt_enable()
75262+#else
75263+#define DISABLE_PREEMPT()
75264+#define ENABLE_PREEMPT()
75265+#endif
75266+
75267+#define BEGIN_LOCKS(x) \
75268+ DISABLE_PREEMPT(); \
75269+ rcu_read_lock(); \
75270+ read_lock(&tasklist_lock); \
75271+ read_lock(&grsec_exec_file_lock); \
75272+ if (x != GR_DO_AUDIT) \
75273+ spin_lock(&grsec_alert_lock); \
75274+ else \
75275+ spin_lock(&grsec_audit_lock)
75276+
75277+#define END_LOCKS(x) \
75278+ if (x != GR_DO_AUDIT) \
75279+ spin_unlock(&grsec_alert_lock); \
75280+ else \
75281+ spin_unlock(&grsec_audit_lock); \
75282+ read_unlock(&grsec_exec_file_lock); \
75283+ read_unlock(&tasklist_lock); \
75284+ rcu_read_unlock(); \
75285+ ENABLE_PREEMPT(); \
75286+ if (x == GR_DONT_AUDIT) \
75287+ gr_handle_alertkill(current)
75288+
75289+enum {
75290+ FLOODING,
75291+ NO_FLOODING
75292+};
75293+
75294+extern char *gr_alert_log_fmt;
75295+extern char *gr_audit_log_fmt;
75296+extern char *gr_alert_log_buf;
75297+extern char *gr_audit_log_buf;
75298+
75299+static int gr_log_start(int audit)
75300+{
75301+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75302+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75303+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75304+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75305+ unsigned long curr_secs = get_seconds();
75306+
75307+ if (audit == GR_DO_AUDIT)
75308+ goto set_fmt;
75309+
75310+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75311+ grsec_alert_wtime = curr_secs;
75312+ grsec_alert_fyet = 0;
75313+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75314+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75315+ grsec_alert_fyet++;
75316+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75317+ grsec_alert_wtime = curr_secs;
75318+ grsec_alert_fyet++;
75319+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75320+ return FLOODING;
75321+ }
75322+ else return FLOODING;
75323+
75324+set_fmt:
75325+#endif
75326+ memset(buf, 0, PAGE_SIZE);
75327+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
75328+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75329+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75330+ } else if (current->signal->curr_ip) {
75331+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75332+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75333+ } else if (gr_acl_is_enabled()) {
75334+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75335+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75336+ } else {
75337+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
75338+ strcpy(buf, fmt);
75339+ }
75340+
75341+ return NO_FLOODING;
75342+}
75343+
75344+static void gr_log_middle(int audit, const char *msg, va_list ap)
75345+ __attribute__ ((format (printf, 2, 0)));
75346+
75347+static void gr_log_middle(int audit, const char *msg, va_list ap)
75348+{
75349+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75350+ unsigned int len = strlen(buf);
75351+
75352+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75353+
75354+ return;
75355+}
75356+
75357+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75358+ __attribute__ ((format (printf, 2, 3)));
75359+
75360+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75361+{
75362+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75363+ unsigned int len = strlen(buf);
75364+ va_list ap;
75365+
75366+ va_start(ap, msg);
75367+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75368+ va_end(ap);
75369+
75370+ return;
75371+}
75372+
75373+static void gr_log_end(int audit, int append_default)
75374+{
75375+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75376+ if (append_default) {
75377+ struct task_struct *task = current;
75378+ struct task_struct *parent = task->real_parent;
75379+ const struct cred *cred = __task_cred(task);
75380+ const struct cred *pcred = __task_cred(parent);
75381+ unsigned int len = strlen(buf);
75382+
75383+ 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));
75384+ }
75385+
75386+ printk("%s\n", buf);
75387+
75388+ return;
75389+}
75390+
75391+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75392+{
75393+ int logtype;
75394+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75395+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75396+ void *voidptr = NULL;
75397+ int num1 = 0, num2 = 0;
75398+ unsigned long ulong1 = 0, ulong2 = 0;
75399+ struct dentry *dentry = NULL;
75400+ struct vfsmount *mnt = NULL;
75401+ struct file *file = NULL;
75402+ struct task_struct *task = NULL;
75403+ struct vm_area_struct *vma = NULL;
75404+ const struct cred *cred, *pcred;
75405+ va_list ap;
75406+
75407+ BEGIN_LOCKS(audit);
75408+ logtype = gr_log_start(audit);
75409+ if (logtype == FLOODING) {
75410+ END_LOCKS(audit);
75411+ return;
75412+ }
75413+ va_start(ap, argtypes);
75414+ switch (argtypes) {
75415+ case GR_TTYSNIFF:
75416+ task = va_arg(ap, struct task_struct *);
75417+ 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));
75418+ break;
75419+ case GR_SYSCTL_HIDDEN:
75420+ str1 = va_arg(ap, char *);
75421+ gr_log_middle_varargs(audit, msg, result, str1);
75422+ break;
75423+ case GR_RBAC:
75424+ dentry = va_arg(ap, struct dentry *);
75425+ mnt = va_arg(ap, struct vfsmount *);
75426+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75427+ break;
75428+ case GR_RBAC_STR:
75429+ dentry = va_arg(ap, struct dentry *);
75430+ mnt = va_arg(ap, struct vfsmount *);
75431+ str1 = va_arg(ap, char *);
75432+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75433+ break;
75434+ case GR_STR_RBAC:
75435+ str1 = va_arg(ap, char *);
75436+ dentry = va_arg(ap, struct dentry *);
75437+ mnt = va_arg(ap, struct vfsmount *);
75438+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75439+ break;
75440+ case GR_RBAC_MODE2:
75441+ dentry = va_arg(ap, struct dentry *);
75442+ mnt = va_arg(ap, struct vfsmount *);
75443+ str1 = va_arg(ap, char *);
75444+ str2 = va_arg(ap, char *);
75445+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75446+ break;
75447+ case GR_RBAC_MODE3:
75448+ dentry = va_arg(ap, struct dentry *);
75449+ mnt = va_arg(ap, struct vfsmount *);
75450+ str1 = va_arg(ap, char *);
75451+ str2 = va_arg(ap, char *);
75452+ str3 = va_arg(ap, char *);
75453+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75454+ break;
75455+ case GR_FILENAME:
75456+ dentry = va_arg(ap, struct dentry *);
75457+ mnt = va_arg(ap, struct vfsmount *);
75458+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75459+ break;
75460+ case GR_STR_FILENAME:
75461+ str1 = va_arg(ap, char *);
75462+ dentry = va_arg(ap, struct dentry *);
75463+ mnt = va_arg(ap, struct vfsmount *);
75464+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75465+ break;
75466+ case GR_FILENAME_STR:
75467+ dentry = va_arg(ap, struct dentry *);
75468+ mnt = va_arg(ap, struct vfsmount *);
75469+ str1 = va_arg(ap, char *);
75470+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75471+ break;
75472+ case GR_FILENAME_TWO_INT:
75473+ dentry = va_arg(ap, struct dentry *);
75474+ mnt = va_arg(ap, struct vfsmount *);
75475+ num1 = va_arg(ap, int);
75476+ num2 = va_arg(ap, int);
75477+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75478+ break;
75479+ case GR_FILENAME_TWO_INT_STR:
75480+ dentry = va_arg(ap, struct dentry *);
75481+ mnt = va_arg(ap, struct vfsmount *);
75482+ num1 = va_arg(ap, int);
75483+ num2 = va_arg(ap, int);
75484+ str1 = va_arg(ap, char *);
75485+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75486+ break;
75487+ case GR_TEXTREL:
75488+ file = va_arg(ap, struct file *);
75489+ ulong1 = va_arg(ap, unsigned long);
75490+ ulong2 = va_arg(ap, unsigned long);
75491+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75492+ break;
75493+ case GR_PTRACE:
75494+ task = va_arg(ap, struct task_struct *);
75495+ 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));
75496+ break;
75497+ case GR_RESOURCE:
75498+ task = va_arg(ap, struct task_struct *);
75499+ cred = __task_cred(task);
75500+ pcred = __task_cred(task->real_parent);
75501+ ulong1 = va_arg(ap, unsigned long);
75502+ str1 = va_arg(ap, char *);
75503+ ulong2 = va_arg(ap, unsigned long);
75504+ 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));
75505+ break;
75506+ case GR_CAP:
75507+ task = va_arg(ap, struct task_struct *);
75508+ cred = __task_cred(task);
75509+ pcred = __task_cred(task->real_parent);
75510+ str1 = va_arg(ap, char *);
75511+ 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));
75512+ break;
75513+ case GR_SIG:
75514+ str1 = va_arg(ap, char *);
75515+ voidptr = va_arg(ap, void *);
75516+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75517+ break;
75518+ case GR_SIG2:
75519+ task = va_arg(ap, struct task_struct *);
75520+ cred = __task_cred(task);
75521+ pcred = __task_cred(task->real_parent);
75522+ num1 = va_arg(ap, int);
75523+ 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));
75524+ break;
75525+ case GR_CRASH1:
75526+ task = va_arg(ap, struct task_struct *);
75527+ cred = __task_cred(task);
75528+ pcred = __task_cred(task->real_parent);
75529+ ulong1 = va_arg(ap, unsigned long);
75530+ 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);
75531+ break;
75532+ case GR_CRASH2:
75533+ task = va_arg(ap, struct task_struct *);
75534+ cred = __task_cred(task);
75535+ pcred = __task_cred(task->real_parent);
75536+ ulong1 = va_arg(ap, unsigned long);
75537+ 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);
75538+ break;
75539+ case GR_RWXMAP:
75540+ file = va_arg(ap, struct file *);
75541+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75542+ break;
75543+ case GR_RWXMAPVMA:
75544+ vma = va_arg(ap, struct vm_area_struct *);
75545+ if (vma->vm_file)
75546+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75547+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75548+ str1 = "<stack>";
75549+ else if (vma->vm_start <= current->mm->brk &&
75550+ vma->vm_end >= current->mm->start_brk)
75551+ str1 = "<heap>";
75552+ else
75553+ str1 = "<anonymous mapping>";
75554+ gr_log_middle_varargs(audit, msg, str1);
75555+ break;
75556+ case GR_PSACCT:
75557+ {
75558+ unsigned int wday, cday;
75559+ __u8 whr, chr;
75560+ __u8 wmin, cmin;
75561+ __u8 wsec, csec;
75562+ char cur_tty[64] = { 0 };
75563+ char parent_tty[64] = { 0 };
75564+
75565+ task = va_arg(ap, struct task_struct *);
75566+ wday = va_arg(ap, unsigned int);
75567+ cday = va_arg(ap, unsigned int);
75568+ whr = va_arg(ap, int);
75569+ chr = va_arg(ap, int);
75570+ wmin = va_arg(ap, int);
75571+ cmin = va_arg(ap, int);
75572+ wsec = va_arg(ap, int);
75573+ csec = va_arg(ap, int);
75574+ ulong1 = va_arg(ap, unsigned long);
75575+ cred = __task_cred(task);
75576+ pcred = __task_cred(task->real_parent);
75577+
75578+ 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));
75579+ }
75580+ break;
75581+ default:
75582+ gr_log_middle(audit, msg, ap);
75583+ }
75584+ va_end(ap);
75585+ // these don't need DEFAULTSECARGS printed on the end
75586+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75587+ gr_log_end(audit, 0);
75588+ else
75589+ gr_log_end(audit, 1);
75590+ END_LOCKS(audit);
75591+}
75592diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75593new file mode 100644
75594index 0000000..0e39d8c
75595--- /dev/null
75596+++ b/grsecurity/grsec_mem.c
75597@@ -0,0 +1,48 @@
75598+#include <linux/kernel.h>
75599+#include <linux/sched.h>
75600+#include <linux/mm.h>
75601+#include <linux/mman.h>
75602+#include <linux/module.h>
75603+#include <linux/grinternal.h>
75604+
75605+void gr_handle_msr_write(void)
75606+{
75607+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75608+ return;
75609+}
75610+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75611+
75612+void
75613+gr_handle_ioperm(void)
75614+{
75615+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75616+ return;
75617+}
75618+
75619+void
75620+gr_handle_iopl(void)
75621+{
75622+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75623+ return;
75624+}
75625+
75626+void
75627+gr_handle_mem_readwrite(u64 from, u64 to)
75628+{
75629+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75630+ return;
75631+}
75632+
75633+void
75634+gr_handle_vm86(void)
75635+{
75636+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75637+ return;
75638+}
75639+
75640+void
75641+gr_log_badprocpid(const char *entry)
75642+{
75643+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75644+ return;
75645+}
75646diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75647new file mode 100644
75648index 0000000..cd9e124
75649--- /dev/null
75650+++ b/grsecurity/grsec_mount.c
75651@@ -0,0 +1,65 @@
75652+#include <linux/kernel.h>
75653+#include <linux/sched.h>
75654+#include <linux/mount.h>
75655+#include <linux/major.h>
75656+#include <linux/grsecurity.h>
75657+#include <linux/grinternal.h>
75658+
75659+void
75660+gr_log_remount(const char *devname, const int retval)
75661+{
75662+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75663+ if (grsec_enable_mount && (retval >= 0))
75664+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75665+#endif
75666+ return;
75667+}
75668+
75669+void
75670+gr_log_unmount(const char *devname, const int retval)
75671+{
75672+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75673+ if (grsec_enable_mount && (retval >= 0))
75674+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75675+#endif
75676+ return;
75677+}
75678+
75679+void
75680+gr_log_mount(const char *from, const char *to, const int retval)
75681+{
75682+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75683+ if (grsec_enable_mount && (retval >= 0))
75684+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75685+#endif
75686+ return;
75687+}
75688+
75689+int
75690+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75691+{
75692+#ifdef CONFIG_GRKERNSEC_ROFS
75693+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75694+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75695+ return -EPERM;
75696+ } else
75697+ return 0;
75698+#endif
75699+ return 0;
75700+}
75701+
75702+int
75703+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75704+{
75705+#ifdef CONFIG_GRKERNSEC_ROFS
75706+ struct inode *inode = dentry->d_inode;
75707+
75708+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75709+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75710+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75711+ return -EPERM;
75712+ } else
75713+ return 0;
75714+#endif
75715+ return 0;
75716+}
75717diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75718new file mode 100644
75719index 0000000..6ee9d50
75720--- /dev/null
75721+++ b/grsecurity/grsec_pax.c
75722@@ -0,0 +1,45 @@
75723+#include <linux/kernel.h>
75724+#include <linux/sched.h>
75725+#include <linux/mm.h>
75726+#include <linux/file.h>
75727+#include <linux/grinternal.h>
75728+#include <linux/grsecurity.h>
75729+
75730+void
75731+gr_log_textrel(struct vm_area_struct * vma)
75732+{
75733+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75734+ if (grsec_enable_log_rwxmaps)
75735+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75736+#endif
75737+ return;
75738+}
75739+
75740+void gr_log_ptgnustack(struct file *file)
75741+{
75742+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75743+ if (grsec_enable_log_rwxmaps)
75744+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75745+#endif
75746+ return;
75747+}
75748+
75749+void
75750+gr_log_rwxmmap(struct file *file)
75751+{
75752+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75753+ if (grsec_enable_log_rwxmaps)
75754+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75755+#endif
75756+ return;
75757+}
75758+
75759+void
75760+gr_log_rwxmprotect(struct vm_area_struct *vma)
75761+{
75762+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75763+ if (grsec_enable_log_rwxmaps)
75764+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75765+#endif
75766+ return;
75767+}
75768diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75769new file mode 100644
75770index 0000000..2005a3a
75771--- /dev/null
75772+++ b/grsecurity/grsec_proc.c
75773@@ -0,0 +1,20 @@
75774+#include <linux/kernel.h>
75775+#include <linux/sched.h>
75776+#include <linux/grsecurity.h>
75777+#include <linux/grinternal.h>
75778+
75779+int gr_proc_is_restricted(void)
75780+{
75781+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75782+ const struct cred *cred = current_cred();
75783+#endif
75784+
75785+#ifdef CONFIG_GRKERNSEC_PROC_USER
75786+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75787+ return -EACCES;
75788+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75789+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75790+ return -EACCES;
75791+#endif
75792+ return 0;
75793+}
75794diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75795new file mode 100644
75796index 0000000..f7f29aa
75797--- /dev/null
75798+++ b/grsecurity/grsec_ptrace.c
75799@@ -0,0 +1,30 @@
75800+#include <linux/kernel.h>
75801+#include <linux/sched.h>
75802+#include <linux/grinternal.h>
75803+#include <linux/security.h>
75804+
75805+void
75806+gr_audit_ptrace(struct task_struct *task)
75807+{
75808+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75809+ if (grsec_enable_audit_ptrace)
75810+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75811+#endif
75812+ return;
75813+}
75814+
75815+int
75816+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75817+{
75818+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75819+ const struct dentry *dentry = file->f_path.dentry;
75820+ const struct vfsmount *mnt = file->f_path.mnt;
75821+
75822+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75823+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75824+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75825+ return -EACCES;
75826+ }
75827+#endif
75828+ return 0;
75829+}
75830diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75831new file mode 100644
75832index 0000000..3860c7e
75833--- /dev/null
75834+++ b/grsecurity/grsec_sig.c
75835@@ -0,0 +1,236 @@
75836+#include <linux/kernel.h>
75837+#include <linux/sched.h>
75838+#include <linux/fs.h>
75839+#include <linux/delay.h>
75840+#include <linux/grsecurity.h>
75841+#include <linux/grinternal.h>
75842+#include <linux/hardirq.h>
75843+
75844+char *signames[] = {
75845+ [SIGSEGV] = "Segmentation fault",
75846+ [SIGILL] = "Illegal instruction",
75847+ [SIGABRT] = "Abort",
75848+ [SIGBUS] = "Invalid alignment/Bus error"
75849+};
75850+
75851+void
75852+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75853+{
75854+#ifdef CONFIG_GRKERNSEC_SIGNAL
75855+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75856+ (sig == SIGABRT) || (sig == SIGBUS))) {
75857+ if (task_pid_nr(t) == task_pid_nr(current)) {
75858+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75859+ } else {
75860+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75861+ }
75862+ }
75863+#endif
75864+ return;
75865+}
75866+
75867+int
75868+gr_handle_signal(const struct task_struct *p, const int sig)
75869+{
75870+#ifdef CONFIG_GRKERNSEC
75871+ /* ignore the 0 signal for protected task checks */
75872+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75873+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75874+ return -EPERM;
75875+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75876+ return -EPERM;
75877+ }
75878+#endif
75879+ return 0;
75880+}
75881+
75882+#ifdef CONFIG_GRKERNSEC
75883+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75884+
75885+int gr_fake_force_sig(int sig, struct task_struct *t)
75886+{
75887+ unsigned long int flags;
75888+ int ret, blocked, ignored;
75889+ struct k_sigaction *action;
75890+
75891+ spin_lock_irqsave(&t->sighand->siglock, flags);
75892+ action = &t->sighand->action[sig-1];
75893+ ignored = action->sa.sa_handler == SIG_IGN;
75894+ blocked = sigismember(&t->blocked, sig);
75895+ if (blocked || ignored) {
75896+ action->sa.sa_handler = SIG_DFL;
75897+ if (blocked) {
75898+ sigdelset(&t->blocked, sig);
75899+ recalc_sigpending_and_wake(t);
75900+ }
75901+ }
75902+ if (action->sa.sa_handler == SIG_DFL)
75903+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75904+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75905+
75906+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75907+
75908+ return ret;
75909+}
75910+#endif
75911+
75912+#define GR_USER_BAN_TIME (15 * 60)
75913+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75914+
75915+void gr_handle_brute_attach(int dumpable)
75916+{
75917+#ifdef CONFIG_GRKERNSEC_BRUTE
75918+ struct task_struct *p = current;
75919+ kuid_t uid = GLOBAL_ROOT_UID;
75920+ int daemon = 0;
75921+
75922+ if (!grsec_enable_brute)
75923+ return;
75924+
75925+ rcu_read_lock();
75926+ read_lock(&tasklist_lock);
75927+ read_lock(&grsec_exec_file_lock);
75928+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75929+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75930+ p->real_parent->brute = 1;
75931+ daemon = 1;
75932+ } else {
75933+ const struct cred *cred = __task_cred(p), *cred2;
75934+ struct task_struct *tsk, *tsk2;
75935+
75936+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75937+ struct user_struct *user;
75938+
75939+ uid = cred->uid;
75940+
75941+ /* this is put upon execution past expiration */
75942+ user = find_user(uid);
75943+ if (user == NULL)
75944+ goto unlock;
75945+ user->suid_banned = 1;
75946+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75947+ if (user->suid_ban_expires == ~0UL)
75948+ user->suid_ban_expires--;
75949+
75950+ /* only kill other threads of the same binary, from the same user */
75951+ do_each_thread(tsk2, tsk) {
75952+ cred2 = __task_cred(tsk);
75953+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75954+ gr_fake_force_sig(SIGKILL, tsk);
75955+ } while_each_thread(tsk2, tsk);
75956+ }
75957+ }
75958+unlock:
75959+ read_unlock(&grsec_exec_file_lock);
75960+ read_unlock(&tasklist_lock);
75961+ rcu_read_unlock();
75962+
75963+ if (gr_is_global_nonroot(uid))
75964+ 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);
75965+ else if (daemon)
75966+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75967+
75968+#endif
75969+ return;
75970+}
75971+
75972+void gr_handle_brute_check(void)
75973+{
75974+#ifdef CONFIG_GRKERNSEC_BRUTE
75975+ struct task_struct *p = current;
75976+
75977+ if (unlikely(p->brute)) {
75978+ if (!grsec_enable_brute)
75979+ p->brute = 0;
75980+ else if (time_before(get_seconds(), p->brute_expires))
75981+ msleep(30 * 1000);
75982+ }
75983+#endif
75984+ return;
75985+}
75986+
75987+void gr_handle_kernel_exploit(void)
75988+{
75989+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75990+ const struct cred *cred;
75991+ struct task_struct *tsk, *tsk2;
75992+ struct user_struct *user;
75993+ kuid_t uid;
75994+
75995+ if (in_irq() || in_serving_softirq() || in_nmi())
75996+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75997+
75998+ uid = current_uid();
75999+
76000+ if (gr_is_global_root(uid))
76001+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
76002+ else {
76003+ /* kill all the processes of this user, hold a reference
76004+ to their creds struct, and prevent them from creating
76005+ another process until system reset
76006+ */
76007+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
76008+ GR_GLOBAL_UID(uid));
76009+ /* we intentionally leak this ref */
76010+ user = get_uid(current->cred->user);
76011+ if (user)
76012+ user->kernel_banned = 1;
76013+
76014+ /* kill all processes of this user */
76015+ read_lock(&tasklist_lock);
76016+ do_each_thread(tsk2, tsk) {
76017+ cred = __task_cred(tsk);
76018+ if (uid_eq(cred->uid, uid))
76019+ gr_fake_force_sig(SIGKILL, tsk);
76020+ } while_each_thread(tsk2, tsk);
76021+ read_unlock(&tasklist_lock);
76022+ }
76023+#endif
76024+}
76025+
76026+#ifdef CONFIG_GRKERNSEC_BRUTE
76027+static bool suid_ban_expired(struct user_struct *user)
76028+{
76029+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
76030+ user->suid_banned = 0;
76031+ user->suid_ban_expires = 0;
76032+ free_uid(user);
76033+ return true;
76034+ }
76035+
76036+ return false;
76037+}
76038+#endif
76039+
76040+int gr_process_kernel_exec_ban(void)
76041+{
76042+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76043+ if (unlikely(current->cred->user->kernel_banned))
76044+ return -EPERM;
76045+#endif
76046+ return 0;
76047+}
76048+
76049+int gr_process_kernel_setuid_ban(struct user_struct *user)
76050+{
76051+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76052+ if (unlikely(user->kernel_banned))
76053+ gr_fake_force_sig(SIGKILL, current);
76054+#endif
76055+ return 0;
76056+}
76057+
76058+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
76059+{
76060+#ifdef CONFIG_GRKERNSEC_BRUTE
76061+ struct user_struct *user = current->cred->user;
76062+ if (unlikely(user->suid_banned)) {
76063+ if (suid_ban_expired(user))
76064+ return 0;
76065+ /* disallow execution of suid binaries only */
76066+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
76067+ return -EPERM;
76068+ }
76069+#endif
76070+ return 0;
76071+}
76072diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
76073new file mode 100644
76074index 0000000..c0aef3a
76075--- /dev/null
76076+++ b/grsecurity/grsec_sock.c
76077@@ -0,0 +1,244 @@
76078+#include <linux/kernel.h>
76079+#include <linux/module.h>
76080+#include <linux/sched.h>
76081+#include <linux/file.h>
76082+#include <linux/net.h>
76083+#include <linux/in.h>
76084+#include <linux/ip.h>
76085+#include <net/sock.h>
76086+#include <net/inet_sock.h>
76087+#include <linux/grsecurity.h>
76088+#include <linux/grinternal.h>
76089+#include <linux/gracl.h>
76090+
76091+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
76092+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
76093+
76094+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
76095+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
76096+
76097+#ifdef CONFIG_UNIX_MODULE
76098+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
76099+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
76100+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
76101+EXPORT_SYMBOL_GPL(gr_handle_create);
76102+#endif
76103+
76104+#ifdef CONFIG_GRKERNSEC
76105+#define gr_conn_table_size 32749
76106+struct conn_table_entry {
76107+ struct conn_table_entry *next;
76108+ struct signal_struct *sig;
76109+};
76110+
76111+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
76112+DEFINE_SPINLOCK(gr_conn_table_lock);
76113+
76114+extern const char * gr_socktype_to_name(unsigned char type);
76115+extern const char * gr_proto_to_name(unsigned char proto);
76116+extern const char * gr_sockfamily_to_name(unsigned char family);
76117+
76118+static __inline__ int
76119+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
76120+{
76121+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
76122+}
76123+
76124+static __inline__ int
76125+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
76126+ __u16 sport, __u16 dport)
76127+{
76128+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
76129+ sig->gr_sport == sport && sig->gr_dport == dport))
76130+ return 1;
76131+ else
76132+ return 0;
76133+}
76134+
76135+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
76136+{
76137+ struct conn_table_entry **match;
76138+ unsigned int index;
76139+
76140+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76141+ sig->gr_sport, sig->gr_dport,
76142+ gr_conn_table_size);
76143+
76144+ newent->sig = sig;
76145+
76146+ match = &gr_conn_table[index];
76147+ newent->next = *match;
76148+ *match = newent;
76149+
76150+ return;
76151+}
76152+
76153+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
76154+{
76155+ struct conn_table_entry *match, *last = NULL;
76156+ unsigned int index;
76157+
76158+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76159+ sig->gr_sport, sig->gr_dport,
76160+ gr_conn_table_size);
76161+
76162+ match = gr_conn_table[index];
76163+ while (match && !conn_match(match->sig,
76164+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
76165+ sig->gr_dport)) {
76166+ last = match;
76167+ match = match->next;
76168+ }
76169+
76170+ if (match) {
76171+ if (last)
76172+ last->next = match->next;
76173+ else
76174+ gr_conn_table[index] = NULL;
76175+ kfree(match);
76176+ }
76177+
76178+ return;
76179+}
76180+
76181+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76182+ __u16 sport, __u16 dport)
76183+{
76184+ struct conn_table_entry *match;
76185+ unsigned int index;
76186+
76187+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76188+
76189+ match = gr_conn_table[index];
76190+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76191+ match = match->next;
76192+
76193+ if (match)
76194+ return match->sig;
76195+ else
76196+ return NULL;
76197+}
76198+
76199+#endif
76200+
76201+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76202+{
76203+#ifdef CONFIG_GRKERNSEC
76204+ struct signal_struct *sig = task->signal;
76205+ struct conn_table_entry *newent;
76206+
76207+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76208+ if (newent == NULL)
76209+ return;
76210+ /* no bh lock needed since we are called with bh disabled */
76211+ spin_lock(&gr_conn_table_lock);
76212+ gr_del_task_from_ip_table_nolock(sig);
76213+ sig->gr_saddr = inet->inet_rcv_saddr;
76214+ sig->gr_daddr = inet->inet_daddr;
76215+ sig->gr_sport = inet->inet_sport;
76216+ sig->gr_dport = inet->inet_dport;
76217+ gr_add_to_task_ip_table_nolock(sig, newent);
76218+ spin_unlock(&gr_conn_table_lock);
76219+#endif
76220+ return;
76221+}
76222+
76223+void gr_del_task_from_ip_table(struct task_struct *task)
76224+{
76225+#ifdef CONFIG_GRKERNSEC
76226+ spin_lock_bh(&gr_conn_table_lock);
76227+ gr_del_task_from_ip_table_nolock(task->signal);
76228+ spin_unlock_bh(&gr_conn_table_lock);
76229+#endif
76230+ return;
76231+}
76232+
76233+void
76234+gr_attach_curr_ip(const struct sock *sk)
76235+{
76236+#ifdef CONFIG_GRKERNSEC
76237+ struct signal_struct *p, *set;
76238+ const struct inet_sock *inet = inet_sk(sk);
76239+
76240+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76241+ return;
76242+
76243+ set = current->signal;
76244+
76245+ spin_lock_bh(&gr_conn_table_lock);
76246+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76247+ inet->inet_dport, inet->inet_sport);
76248+ if (unlikely(p != NULL)) {
76249+ set->curr_ip = p->curr_ip;
76250+ set->used_accept = 1;
76251+ gr_del_task_from_ip_table_nolock(p);
76252+ spin_unlock_bh(&gr_conn_table_lock);
76253+ return;
76254+ }
76255+ spin_unlock_bh(&gr_conn_table_lock);
76256+
76257+ set->curr_ip = inet->inet_daddr;
76258+ set->used_accept = 1;
76259+#endif
76260+ return;
76261+}
76262+
76263+int
76264+gr_handle_sock_all(const int family, const int type, const int protocol)
76265+{
76266+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76267+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76268+ (family != AF_UNIX)) {
76269+ if (family == AF_INET)
76270+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76271+ else
76272+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76273+ return -EACCES;
76274+ }
76275+#endif
76276+ return 0;
76277+}
76278+
76279+int
76280+gr_handle_sock_server(const struct sockaddr *sck)
76281+{
76282+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76283+ if (grsec_enable_socket_server &&
76284+ in_group_p(grsec_socket_server_gid) &&
76285+ sck && (sck->sa_family != AF_UNIX) &&
76286+ (sck->sa_family != AF_LOCAL)) {
76287+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76288+ return -EACCES;
76289+ }
76290+#endif
76291+ return 0;
76292+}
76293+
76294+int
76295+gr_handle_sock_server_other(const struct sock *sck)
76296+{
76297+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76298+ if (grsec_enable_socket_server &&
76299+ in_group_p(grsec_socket_server_gid) &&
76300+ sck && (sck->sk_family != AF_UNIX) &&
76301+ (sck->sk_family != AF_LOCAL)) {
76302+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76303+ return -EACCES;
76304+ }
76305+#endif
76306+ return 0;
76307+}
76308+
76309+int
76310+gr_handle_sock_client(const struct sockaddr *sck)
76311+{
76312+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76313+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76314+ sck && (sck->sa_family != AF_UNIX) &&
76315+ (sck->sa_family != AF_LOCAL)) {
76316+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76317+ return -EACCES;
76318+ }
76319+#endif
76320+ return 0;
76321+}
76322diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76323new file mode 100644
76324index 0000000..8159888
76325--- /dev/null
76326+++ b/grsecurity/grsec_sysctl.c
76327@@ -0,0 +1,479 @@
76328+#include <linux/kernel.h>
76329+#include <linux/sched.h>
76330+#include <linux/sysctl.h>
76331+#include <linux/grsecurity.h>
76332+#include <linux/grinternal.h>
76333+
76334+int
76335+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76336+{
76337+#ifdef CONFIG_GRKERNSEC_SYSCTL
76338+ if (dirname == NULL || name == NULL)
76339+ return 0;
76340+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76341+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76342+ return -EACCES;
76343+ }
76344+#endif
76345+ return 0;
76346+}
76347+
76348+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76349+static int __maybe_unused __read_only one = 1;
76350+#endif
76351+
76352+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76353+ defined(CONFIG_GRKERNSEC_DENYUSB)
76354+struct ctl_table grsecurity_table[] = {
76355+#ifdef CONFIG_GRKERNSEC_SYSCTL
76356+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76357+#ifdef CONFIG_GRKERNSEC_IO
76358+ {
76359+ .procname = "disable_priv_io",
76360+ .data = &grsec_disable_privio,
76361+ .maxlen = sizeof(int),
76362+ .mode = 0600,
76363+ .proc_handler = &proc_dointvec,
76364+ },
76365+#endif
76366+#endif
76367+#ifdef CONFIG_GRKERNSEC_LINK
76368+ {
76369+ .procname = "linking_restrictions",
76370+ .data = &grsec_enable_link,
76371+ .maxlen = sizeof(int),
76372+ .mode = 0600,
76373+ .proc_handler = &proc_dointvec,
76374+ },
76375+#endif
76376+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76377+ {
76378+ .procname = "enforce_symlinksifowner",
76379+ .data = &grsec_enable_symlinkown,
76380+ .maxlen = sizeof(int),
76381+ .mode = 0600,
76382+ .proc_handler = &proc_dointvec,
76383+ },
76384+ {
76385+ .procname = "symlinkown_gid",
76386+ .data = &grsec_symlinkown_gid,
76387+ .maxlen = sizeof(int),
76388+ .mode = 0600,
76389+ .proc_handler = &proc_dointvec,
76390+ },
76391+#endif
76392+#ifdef CONFIG_GRKERNSEC_BRUTE
76393+ {
76394+ .procname = "deter_bruteforce",
76395+ .data = &grsec_enable_brute,
76396+ .maxlen = sizeof(int),
76397+ .mode = 0600,
76398+ .proc_handler = &proc_dointvec,
76399+ },
76400+#endif
76401+#ifdef CONFIG_GRKERNSEC_FIFO
76402+ {
76403+ .procname = "fifo_restrictions",
76404+ .data = &grsec_enable_fifo,
76405+ .maxlen = sizeof(int),
76406+ .mode = 0600,
76407+ .proc_handler = &proc_dointvec,
76408+ },
76409+#endif
76410+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76411+ {
76412+ .procname = "ptrace_readexec",
76413+ .data = &grsec_enable_ptrace_readexec,
76414+ .maxlen = sizeof(int),
76415+ .mode = 0600,
76416+ .proc_handler = &proc_dointvec,
76417+ },
76418+#endif
76419+#ifdef CONFIG_GRKERNSEC_SETXID
76420+ {
76421+ .procname = "consistent_setxid",
76422+ .data = &grsec_enable_setxid,
76423+ .maxlen = sizeof(int),
76424+ .mode = 0600,
76425+ .proc_handler = &proc_dointvec,
76426+ },
76427+#endif
76428+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76429+ {
76430+ .procname = "ip_blackhole",
76431+ .data = &grsec_enable_blackhole,
76432+ .maxlen = sizeof(int),
76433+ .mode = 0600,
76434+ .proc_handler = &proc_dointvec,
76435+ },
76436+ {
76437+ .procname = "lastack_retries",
76438+ .data = &grsec_lastack_retries,
76439+ .maxlen = sizeof(int),
76440+ .mode = 0600,
76441+ .proc_handler = &proc_dointvec,
76442+ },
76443+#endif
76444+#ifdef CONFIG_GRKERNSEC_EXECLOG
76445+ {
76446+ .procname = "exec_logging",
76447+ .data = &grsec_enable_execlog,
76448+ .maxlen = sizeof(int),
76449+ .mode = 0600,
76450+ .proc_handler = &proc_dointvec,
76451+ },
76452+#endif
76453+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76454+ {
76455+ .procname = "rwxmap_logging",
76456+ .data = &grsec_enable_log_rwxmaps,
76457+ .maxlen = sizeof(int),
76458+ .mode = 0600,
76459+ .proc_handler = &proc_dointvec,
76460+ },
76461+#endif
76462+#ifdef CONFIG_GRKERNSEC_SIGNAL
76463+ {
76464+ .procname = "signal_logging",
76465+ .data = &grsec_enable_signal,
76466+ .maxlen = sizeof(int),
76467+ .mode = 0600,
76468+ .proc_handler = &proc_dointvec,
76469+ },
76470+#endif
76471+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76472+ {
76473+ .procname = "forkfail_logging",
76474+ .data = &grsec_enable_forkfail,
76475+ .maxlen = sizeof(int),
76476+ .mode = 0600,
76477+ .proc_handler = &proc_dointvec,
76478+ },
76479+#endif
76480+#ifdef CONFIG_GRKERNSEC_TIME
76481+ {
76482+ .procname = "timechange_logging",
76483+ .data = &grsec_enable_time,
76484+ .maxlen = sizeof(int),
76485+ .mode = 0600,
76486+ .proc_handler = &proc_dointvec,
76487+ },
76488+#endif
76489+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76490+ {
76491+ .procname = "chroot_deny_shmat",
76492+ .data = &grsec_enable_chroot_shmat,
76493+ .maxlen = sizeof(int),
76494+ .mode = 0600,
76495+ .proc_handler = &proc_dointvec,
76496+ },
76497+#endif
76498+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76499+ {
76500+ .procname = "chroot_deny_unix",
76501+ .data = &grsec_enable_chroot_unix,
76502+ .maxlen = sizeof(int),
76503+ .mode = 0600,
76504+ .proc_handler = &proc_dointvec,
76505+ },
76506+#endif
76507+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76508+ {
76509+ .procname = "chroot_deny_mount",
76510+ .data = &grsec_enable_chroot_mount,
76511+ .maxlen = sizeof(int),
76512+ .mode = 0600,
76513+ .proc_handler = &proc_dointvec,
76514+ },
76515+#endif
76516+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76517+ {
76518+ .procname = "chroot_deny_fchdir",
76519+ .data = &grsec_enable_chroot_fchdir,
76520+ .maxlen = sizeof(int),
76521+ .mode = 0600,
76522+ .proc_handler = &proc_dointvec,
76523+ },
76524+#endif
76525+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76526+ {
76527+ .procname = "chroot_deny_chroot",
76528+ .data = &grsec_enable_chroot_double,
76529+ .maxlen = sizeof(int),
76530+ .mode = 0600,
76531+ .proc_handler = &proc_dointvec,
76532+ },
76533+#endif
76534+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76535+ {
76536+ .procname = "chroot_deny_pivot",
76537+ .data = &grsec_enable_chroot_pivot,
76538+ .maxlen = sizeof(int),
76539+ .mode = 0600,
76540+ .proc_handler = &proc_dointvec,
76541+ },
76542+#endif
76543+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76544+ {
76545+ .procname = "chroot_enforce_chdir",
76546+ .data = &grsec_enable_chroot_chdir,
76547+ .maxlen = sizeof(int),
76548+ .mode = 0600,
76549+ .proc_handler = &proc_dointvec,
76550+ },
76551+#endif
76552+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76553+ {
76554+ .procname = "chroot_deny_chmod",
76555+ .data = &grsec_enable_chroot_chmod,
76556+ .maxlen = sizeof(int),
76557+ .mode = 0600,
76558+ .proc_handler = &proc_dointvec,
76559+ },
76560+#endif
76561+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76562+ {
76563+ .procname = "chroot_deny_mknod",
76564+ .data = &grsec_enable_chroot_mknod,
76565+ .maxlen = sizeof(int),
76566+ .mode = 0600,
76567+ .proc_handler = &proc_dointvec,
76568+ },
76569+#endif
76570+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76571+ {
76572+ .procname = "chroot_restrict_nice",
76573+ .data = &grsec_enable_chroot_nice,
76574+ .maxlen = sizeof(int),
76575+ .mode = 0600,
76576+ .proc_handler = &proc_dointvec,
76577+ },
76578+#endif
76579+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76580+ {
76581+ .procname = "chroot_execlog",
76582+ .data = &grsec_enable_chroot_execlog,
76583+ .maxlen = sizeof(int),
76584+ .mode = 0600,
76585+ .proc_handler = &proc_dointvec,
76586+ },
76587+#endif
76588+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76589+ {
76590+ .procname = "chroot_caps",
76591+ .data = &grsec_enable_chroot_caps,
76592+ .maxlen = sizeof(int),
76593+ .mode = 0600,
76594+ .proc_handler = &proc_dointvec,
76595+ },
76596+#endif
76597+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76598+ {
76599+ .procname = "chroot_deny_sysctl",
76600+ .data = &grsec_enable_chroot_sysctl,
76601+ .maxlen = sizeof(int),
76602+ .mode = 0600,
76603+ .proc_handler = &proc_dointvec,
76604+ },
76605+#endif
76606+#ifdef CONFIG_GRKERNSEC_TPE
76607+ {
76608+ .procname = "tpe",
76609+ .data = &grsec_enable_tpe,
76610+ .maxlen = sizeof(int),
76611+ .mode = 0600,
76612+ .proc_handler = &proc_dointvec,
76613+ },
76614+ {
76615+ .procname = "tpe_gid",
76616+ .data = &grsec_tpe_gid,
76617+ .maxlen = sizeof(int),
76618+ .mode = 0600,
76619+ .proc_handler = &proc_dointvec,
76620+ },
76621+#endif
76622+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76623+ {
76624+ .procname = "tpe_invert",
76625+ .data = &grsec_enable_tpe_invert,
76626+ .maxlen = sizeof(int),
76627+ .mode = 0600,
76628+ .proc_handler = &proc_dointvec,
76629+ },
76630+#endif
76631+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76632+ {
76633+ .procname = "tpe_restrict_all",
76634+ .data = &grsec_enable_tpe_all,
76635+ .maxlen = sizeof(int),
76636+ .mode = 0600,
76637+ .proc_handler = &proc_dointvec,
76638+ },
76639+#endif
76640+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76641+ {
76642+ .procname = "socket_all",
76643+ .data = &grsec_enable_socket_all,
76644+ .maxlen = sizeof(int),
76645+ .mode = 0600,
76646+ .proc_handler = &proc_dointvec,
76647+ },
76648+ {
76649+ .procname = "socket_all_gid",
76650+ .data = &grsec_socket_all_gid,
76651+ .maxlen = sizeof(int),
76652+ .mode = 0600,
76653+ .proc_handler = &proc_dointvec,
76654+ },
76655+#endif
76656+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76657+ {
76658+ .procname = "socket_client",
76659+ .data = &grsec_enable_socket_client,
76660+ .maxlen = sizeof(int),
76661+ .mode = 0600,
76662+ .proc_handler = &proc_dointvec,
76663+ },
76664+ {
76665+ .procname = "socket_client_gid",
76666+ .data = &grsec_socket_client_gid,
76667+ .maxlen = sizeof(int),
76668+ .mode = 0600,
76669+ .proc_handler = &proc_dointvec,
76670+ },
76671+#endif
76672+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76673+ {
76674+ .procname = "socket_server",
76675+ .data = &grsec_enable_socket_server,
76676+ .maxlen = sizeof(int),
76677+ .mode = 0600,
76678+ .proc_handler = &proc_dointvec,
76679+ },
76680+ {
76681+ .procname = "socket_server_gid",
76682+ .data = &grsec_socket_server_gid,
76683+ .maxlen = sizeof(int),
76684+ .mode = 0600,
76685+ .proc_handler = &proc_dointvec,
76686+ },
76687+#endif
76688+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76689+ {
76690+ .procname = "audit_group",
76691+ .data = &grsec_enable_group,
76692+ .maxlen = sizeof(int),
76693+ .mode = 0600,
76694+ .proc_handler = &proc_dointvec,
76695+ },
76696+ {
76697+ .procname = "audit_gid",
76698+ .data = &grsec_audit_gid,
76699+ .maxlen = sizeof(int),
76700+ .mode = 0600,
76701+ .proc_handler = &proc_dointvec,
76702+ },
76703+#endif
76704+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76705+ {
76706+ .procname = "audit_chdir",
76707+ .data = &grsec_enable_chdir,
76708+ .maxlen = sizeof(int),
76709+ .mode = 0600,
76710+ .proc_handler = &proc_dointvec,
76711+ },
76712+#endif
76713+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76714+ {
76715+ .procname = "audit_mount",
76716+ .data = &grsec_enable_mount,
76717+ .maxlen = sizeof(int),
76718+ .mode = 0600,
76719+ .proc_handler = &proc_dointvec,
76720+ },
76721+#endif
76722+#ifdef CONFIG_GRKERNSEC_DMESG
76723+ {
76724+ .procname = "dmesg",
76725+ .data = &grsec_enable_dmesg,
76726+ .maxlen = sizeof(int),
76727+ .mode = 0600,
76728+ .proc_handler = &proc_dointvec,
76729+ },
76730+#endif
76731+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76732+ {
76733+ .procname = "chroot_findtask",
76734+ .data = &grsec_enable_chroot_findtask,
76735+ .maxlen = sizeof(int),
76736+ .mode = 0600,
76737+ .proc_handler = &proc_dointvec,
76738+ },
76739+#endif
76740+#ifdef CONFIG_GRKERNSEC_RESLOG
76741+ {
76742+ .procname = "resource_logging",
76743+ .data = &grsec_resource_logging,
76744+ .maxlen = sizeof(int),
76745+ .mode = 0600,
76746+ .proc_handler = &proc_dointvec,
76747+ },
76748+#endif
76749+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76750+ {
76751+ .procname = "audit_ptrace",
76752+ .data = &grsec_enable_audit_ptrace,
76753+ .maxlen = sizeof(int),
76754+ .mode = 0600,
76755+ .proc_handler = &proc_dointvec,
76756+ },
76757+#endif
76758+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76759+ {
76760+ .procname = "harden_ptrace",
76761+ .data = &grsec_enable_harden_ptrace,
76762+ .maxlen = sizeof(int),
76763+ .mode = 0600,
76764+ .proc_handler = &proc_dointvec,
76765+ },
76766+#endif
76767+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76768+ {
76769+ .procname = "harden_ipc",
76770+ .data = &grsec_enable_harden_ipc,
76771+ .maxlen = sizeof(int),
76772+ .mode = 0600,
76773+ .proc_handler = &proc_dointvec,
76774+ },
76775+#endif
76776+ {
76777+ .procname = "grsec_lock",
76778+ .data = &grsec_lock,
76779+ .maxlen = sizeof(int),
76780+ .mode = 0600,
76781+ .proc_handler = &proc_dointvec,
76782+ },
76783+#endif
76784+#ifdef CONFIG_GRKERNSEC_ROFS
76785+ {
76786+ .procname = "romount_protect",
76787+ .data = &grsec_enable_rofs,
76788+ .maxlen = sizeof(int),
76789+ .mode = 0600,
76790+ .proc_handler = &proc_dointvec_minmax,
76791+ .extra1 = &one,
76792+ .extra2 = &one,
76793+ },
76794+#endif
76795+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76796+ {
76797+ .procname = "deny_new_usb",
76798+ .data = &grsec_deny_new_usb,
76799+ .maxlen = sizeof(int),
76800+ .mode = 0600,
76801+ .proc_handler = &proc_dointvec,
76802+ },
76803+#endif
76804+ { }
76805+};
76806+#endif
76807diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76808new file mode 100644
76809index 0000000..61b514e
76810--- /dev/null
76811+++ b/grsecurity/grsec_time.c
76812@@ -0,0 +1,16 @@
76813+#include <linux/kernel.h>
76814+#include <linux/sched.h>
76815+#include <linux/grinternal.h>
76816+#include <linux/module.h>
76817+
76818+void
76819+gr_log_timechange(void)
76820+{
76821+#ifdef CONFIG_GRKERNSEC_TIME
76822+ if (grsec_enable_time)
76823+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76824+#endif
76825+ return;
76826+}
76827+
76828+EXPORT_SYMBOL_GPL(gr_log_timechange);
76829diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76830new file mode 100644
76831index 0000000..d1953de
76832--- /dev/null
76833+++ b/grsecurity/grsec_tpe.c
76834@@ -0,0 +1,78 @@
76835+#include <linux/kernel.h>
76836+#include <linux/sched.h>
76837+#include <linux/file.h>
76838+#include <linux/fs.h>
76839+#include <linux/grinternal.h>
76840+
76841+extern int gr_acl_tpe_check(void);
76842+
76843+int
76844+gr_tpe_allow(const struct file *file)
76845+{
76846+#ifdef CONFIG_GRKERNSEC
76847+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76848+ struct inode *file_inode = file->f_path.dentry->d_inode;
76849+ const struct cred *cred = current_cred();
76850+ char *msg = NULL;
76851+ char *msg2 = NULL;
76852+
76853+ // never restrict root
76854+ if (gr_is_global_root(cred->uid))
76855+ return 1;
76856+
76857+ if (grsec_enable_tpe) {
76858+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76859+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76860+ msg = "not being in trusted group";
76861+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76862+ msg = "being in untrusted group";
76863+#else
76864+ if (in_group_p(grsec_tpe_gid))
76865+ msg = "being in untrusted group";
76866+#endif
76867+ }
76868+ if (!msg && gr_acl_tpe_check())
76869+ msg = "being in untrusted role";
76870+
76871+ // not in any affected group/role
76872+ if (!msg)
76873+ goto next_check;
76874+
76875+ if (gr_is_global_nonroot(inode->i_uid))
76876+ msg2 = "file in non-root-owned directory";
76877+ else if (inode->i_mode & S_IWOTH)
76878+ msg2 = "file in world-writable directory";
76879+ else if (inode->i_mode & S_IWGRP)
76880+ msg2 = "file in group-writable directory";
76881+ else if (file_inode->i_mode & S_IWOTH)
76882+ msg2 = "file is world-writable";
76883+
76884+ if (msg && msg2) {
76885+ char fullmsg[70] = {0};
76886+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76887+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76888+ return 0;
76889+ }
76890+ msg = NULL;
76891+next_check:
76892+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76893+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76894+ return 1;
76895+
76896+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76897+ msg = "directory not owned by user";
76898+ else if (inode->i_mode & S_IWOTH)
76899+ msg = "file in world-writable directory";
76900+ else if (inode->i_mode & S_IWGRP)
76901+ msg = "file in group-writable directory";
76902+ else if (file_inode->i_mode & S_IWOTH)
76903+ msg = "file is world-writable";
76904+
76905+ if (msg) {
76906+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76907+ return 0;
76908+ }
76909+#endif
76910+#endif
76911+ return 1;
76912+}
76913diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76914new file mode 100644
76915index 0000000..ae02d8e
76916--- /dev/null
76917+++ b/grsecurity/grsec_usb.c
76918@@ -0,0 +1,15 @@
76919+#include <linux/kernel.h>
76920+#include <linux/grinternal.h>
76921+#include <linux/module.h>
76922+
76923+int gr_handle_new_usb(void)
76924+{
76925+#ifdef CONFIG_GRKERNSEC_DENYUSB
76926+ if (grsec_deny_new_usb) {
76927+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76928+ return 1;
76929+ }
76930+#endif
76931+ return 0;
76932+}
76933+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76934diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76935new file mode 100644
76936index 0000000..158b330
76937--- /dev/null
76938+++ b/grsecurity/grsum.c
76939@@ -0,0 +1,64 @@
76940+#include <linux/err.h>
76941+#include <linux/kernel.h>
76942+#include <linux/sched.h>
76943+#include <linux/mm.h>
76944+#include <linux/scatterlist.h>
76945+#include <linux/crypto.h>
76946+#include <linux/gracl.h>
76947+
76948+
76949+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76950+#error "crypto and sha256 must be built into the kernel"
76951+#endif
76952+
76953+int
76954+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76955+{
76956+ struct crypto_hash *tfm;
76957+ struct hash_desc desc;
76958+ struct scatterlist sg[2];
76959+ unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
76960+ unsigned long *tmpsumptr = (unsigned long *)temp_sum;
76961+ unsigned long *sumptr = (unsigned long *)sum;
76962+ int cryptres;
76963+ int retval = 1;
76964+ volatile int mismatched = 0;
76965+ volatile int dummy = 0;
76966+ unsigned int i;
76967+
76968+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76969+ if (IS_ERR(tfm)) {
76970+ /* should never happen, since sha256 should be built in */
76971+ memset(entry->pw, 0, GR_PW_LEN);
76972+ return 1;
76973+ }
76974+
76975+ sg_init_table(sg, 2);
76976+ sg_set_buf(&sg[0], salt, GR_SALT_LEN);
76977+ sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
76978+
76979+ desc.tfm = tfm;
76980+ desc.flags = 0;
76981+
76982+ cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
76983+ temp_sum);
76984+
76985+ memset(entry->pw, 0, GR_PW_LEN);
76986+
76987+ if (cryptres)
76988+ goto out;
76989+
76990+ for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
76991+ if (sumptr[i] != tmpsumptr[i])
76992+ mismatched = 1;
76993+ else
76994+ dummy = 1; // waste a cycle
76995+
76996+ if (!mismatched)
76997+ retval = dummy - 1;
76998+
76999+out:
77000+ crypto_free_hash(tfm);
77001+
77002+ return retval;
77003+}
77004diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
77005index 77ff547..181834f 100644
77006--- a/include/asm-generic/4level-fixup.h
77007+++ b/include/asm-generic/4level-fixup.h
77008@@ -13,8 +13,10 @@
77009 #define pmd_alloc(mm, pud, address) \
77010 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
77011 NULL: pmd_offset(pud, address))
77012+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
77013
77014 #define pud_alloc(mm, pgd, address) (pgd)
77015+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
77016 #define pud_offset(pgd, start) (pgd)
77017 #define pud_none(pud) 0
77018 #define pud_bad(pud) 0
77019diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
77020index b7babf0..97f4c4f 100644
77021--- a/include/asm-generic/atomic-long.h
77022+++ b/include/asm-generic/atomic-long.h
77023@@ -22,6 +22,12 @@
77024
77025 typedef atomic64_t atomic_long_t;
77026
77027+#ifdef CONFIG_PAX_REFCOUNT
77028+typedef atomic64_unchecked_t atomic_long_unchecked_t;
77029+#else
77030+typedef atomic64_t atomic_long_unchecked_t;
77031+#endif
77032+
77033 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
77034
77035 static inline long atomic_long_read(atomic_long_t *l)
77036@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77037 return (long)atomic64_read(v);
77038 }
77039
77040+#ifdef CONFIG_PAX_REFCOUNT
77041+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77042+{
77043+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77044+
77045+ return (long)atomic64_read_unchecked(v);
77046+}
77047+#endif
77048+
77049 static inline void atomic_long_set(atomic_long_t *l, long i)
77050 {
77051 atomic64_t *v = (atomic64_t *)l;
77052@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77053 atomic64_set(v, i);
77054 }
77055
77056+#ifdef CONFIG_PAX_REFCOUNT
77057+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77058+{
77059+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77060+
77061+ atomic64_set_unchecked(v, i);
77062+}
77063+#endif
77064+
77065 static inline void atomic_long_inc(atomic_long_t *l)
77066 {
77067 atomic64_t *v = (atomic64_t *)l;
77068@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77069 atomic64_inc(v);
77070 }
77071
77072+#ifdef CONFIG_PAX_REFCOUNT
77073+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77074+{
77075+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77076+
77077+ atomic64_inc_unchecked(v);
77078+}
77079+#endif
77080+
77081 static inline void atomic_long_dec(atomic_long_t *l)
77082 {
77083 atomic64_t *v = (atomic64_t *)l;
77084@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77085 atomic64_dec(v);
77086 }
77087
77088+#ifdef CONFIG_PAX_REFCOUNT
77089+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77090+{
77091+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77092+
77093+ atomic64_dec_unchecked(v);
77094+}
77095+#endif
77096+
77097 static inline void atomic_long_add(long i, atomic_long_t *l)
77098 {
77099 atomic64_t *v = (atomic64_t *)l;
77100@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77101 atomic64_add(i, v);
77102 }
77103
77104+#ifdef CONFIG_PAX_REFCOUNT
77105+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77106+{
77107+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77108+
77109+ atomic64_add_unchecked(i, v);
77110+}
77111+#endif
77112+
77113 static inline void atomic_long_sub(long i, atomic_long_t *l)
77114 {
77115 atomic64_t *v = (atomic64_t *)l;
77116@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77117 atomic64_sub(i, v);
77118 }
77119
77120+#ifdef CONFIG_PAX_REFCOUNT
77121+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77122+{
77123+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77124+
77125+ atomic64_sub_unchecked(i, v);
77126+}
77127+#endif
77128+
77129 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77130 {
77131 atomic64_t *v = (atomic64_t *)l;
77132@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
77133 return atomic64_add_negative(i, v);
77134 }
77135
77136-static inline long atomic_long_add_return(long i, atomic_long_t *l)
77137+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
77138 {
77139 atomic64_t *v = (atomic64_t *)l;
77140
77141 return (long)atomic64_add_return(i, v);
77142 }
77143
77144+#ifdef CONFIG_PAX_REFCOUNT
77145+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77146+{
77147+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77148+
77149+ return (long)atomic64_add_return_unchecked(i, v);
77150+}
77151+#endif
77152+
77153 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77154 {
77155 atomic64_t *v = (atomic64_t *)l;
77156@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77157 return (long)atomic64_inc_return(v);
77158 }
77159
77160+#ifdef CONFIG_PAX_REFCOUNT
77161+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77162+{
77163+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77164+
77165+ return (long)atomic64_inc_return_unchecked(v);
77166+}
77167+#endif
77168+
77169 static inline long atomic_long_dec_return(atomic_long_t *l)
77170 {
77171 atomic64_t *v = (atomic64_t *)l;
77172@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77173
77174 typedef atomic_t atomic_long_t;
77175
77176+#ifdef CONFIG_PAX_REFCOUNT
77177+typedef atomic_unchecked_t atomic_long_unchecked_t;
77178+#else
77179+typedef atomic_t atomic_long_unchecked_t;
77180+#endif
77181+
77182 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
77183 static inline long atomic_long_read(atomic_long_t *l)
77184 {
77185@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77186 return (long)atomic_read(v);
77187 }
77188
77189+#ifdef CONFIG_PAX_REFCOUNT
77190+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77191+{
77192+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77193+
77194+ return (long)atomic_read_unchecked(v);
77195+}
77196+#endif
77197+
77198 static inline void atomic_long_set(atomic_long_t *l, long i)
77199 {
77200 atomic_t *v = (atomic_t *)l;
77201@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77202 atomic_set(v, i);
77203 }
77204
77205+#ifdef CONFIG_PAX_REFCOUNT
77206+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77207+{
77208+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77209+
77210+ atomic_set_unchecked(v, i);
77211+}
77212+#endif
77213+
77214 static inline void atomic_long_inc(atomic_long_t *l)
77215 {
77216 atomic_t *v = (atomic_t *)l;
77217@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77218 atomic_inc(v);
77219 }
77220
77221+#ifdef CONFIG_PAX_REFCOUNT
77222+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77223+{
77224+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77225+
77226+ atomic_inc_unchecked(v);
77227+}
77228+#endif
77229+
77230 static inline void atomic_long_dec(atomic_long_t *l)
77231 {
77232 atomic_t *v = (atomic_t *)l;
77233@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77234 atomic_dec(v);
77235 }
77236
77237+#ifdef CONFIG_PAX_REFCOUNT
77238+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77239+{
77240+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77241+
77242+ atomic_dec_unchecked(v);
77243+}
77244+#endif
77245+
77246 static inline void atomic_long_add(long i, atomic_long_t *l)
77247 {
77248 atomic_t *v = (atomic_t *)l;
77249@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77250 atomic_add(i, v);
77251 }
77252
77253+#ifdef CONFIG_PAX_REFCOUNT
77254+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77255+{
77256+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77257+
77258+ atomic_add_unchecked(i, v);
77259+}
77260+#endif
77261+
77262 static inline void atomic_long_sub(long i, atomic_long_t *l)
77263 {
77264 atomic_t *v = (atomic_t *)l;
77265@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77266 atomic_sub(i, v);
77267 }
77268
77269+#ifdef CONFIG_PAX_REFCOUNT
77270+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77271+{
77272+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77273+
77274+ atomic_sub_unchecked(i, v);
77275+}
77276+#endif
77277+
77278 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77279 {
77280 atomic_t *v = (atomic_t *)l;
77281@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77282 return (long)atomic_add_return(i, v);
77283 }
77284
77285+#ifdef CONFIG_PAX_REFCOUNT
77286+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77287+{
77288+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77289+
77290+ return (long)atomic_add_return_unchecked(i, v);
77291+}
77292+
77293+#endif
77294+
77295 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77296 {
77297 atomic_t *v = (atomic_t *)l;
77298@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77299 return (long)atomic_inc_return(v);
77300 }
77301
77302+#ifdef CONFIG_PAX_REFCOUNT
77303+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77304+{
77305+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77306+
77307+ return (long)atomic_inc_return_unchecked(v);
77308+}
77309+#endif
77310+
77311 static inline long atomic_long_dec_return(atomic_long_t *l)
77312 {
77313 atomic_t *v = (atomic_t *)l;
77314@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77315
77316 #endif /* BITS_PER_LONG == 64 */
77317
77318+#ifdef CONFIG_PAX_REFCOUNT
77319+static inline void pax_refcount_needs_these_functions(void)
77320+{
77321+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
77322+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77323+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77324+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77325+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77326+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77327+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77328+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77329+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77330+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77331+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77332+#ifdef CONFIG_X86
77333+ atomic_clear_mask_unchecked(0, NULL);
77334+ atomic_set_mask_unchecked(0, NULL);
77335+#endif
77336+
77337+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77338+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77339+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77340+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77341+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77342+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77343+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77344+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77345+}
77346+#else
77347+#define atomic_read_unchecked(v) atomic_read(v)
77348+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77349+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77350+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77351+#define atomic_inc_unchecked(v) atomic_inc(v)
77352+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77353+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77354+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77355+#define atomic_dec_unchecked(v) atomic_dec(v)
77356+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77357+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77358+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77359+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77360+
77361+#define atomic_long_read_unchecked(v) atomic_long_read(v)
77362+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77363+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77364+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77365+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77366+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77367+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77368+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77369+#endif
77370+
77371 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77372diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77373index 33bd2de..f31bff97 100644
77374--- a/include/asm-generic/atomic.h
77375+++ b/include/asm-generic/atomic.h
77376@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77377 * Atomically clears the bits set in @mask from @v
77378 */
77379 #ifndef atomic_clear_mask
77380-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77381+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77382 {
77383 unsigned long flags;
77384
77385diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77386index b18ce4f..2ee2843 100644
77387--- a/include/asm-generic/atomic64.h
77388+++ b/include/asm-generic/atomic64.h
77389@@ -16,6 +16,8 @@ typedef struct {
77390 long long counter;
77391 } atomic64_t;
77392
77393+typedef atomic64_t atomic64_unchecked_t;
77394+
77395 #define ATOMIC64_INIT(i) { (i) }
77396
77397 extern long long atomic64_read(const atomic64_t *v);
77398@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77399 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77400 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77401
77402+#define atomic64_read_unchecked(v) atomic64_read(v)
77403+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77404+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77405+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77406+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77407+#define atomic64_inc_unchecked(v) atomic64_inc(v)
77408+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77409+#define atomic64_dec_unchecked(v) atomic64_dec(v)
77410+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77411+
77412 #endif /* _ASM_GENERIC_ATOMIC64_H */
77413diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
77414index 6f692f8..2ad9dd2 100644
77415--- a/include/asm-generic/barrier.h
77416+++ b/include/asm-generic/barrier.h
77417@@ -66,7 +66,7 @@
77418 do { \
77419 compiletime_assert_atomic_type(*p); \
77420 smp_mb(); \
77421- ACCESS_ONCE(*p) = (v); \
77422+ ACCESS_ONCE_RW(*p) = (v); \
77423 } while (0)
77424
77425 #define smp_load_acquire(p) \
77426diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77427index a60a7cc..0fe12f2 100644
77428--- a/include/asm-generic/bitops/__fls.h
77429+++ b/include/asm-generic/bitops/__fls.h
77430@@ -9,7 +9,7 @@
77431 *
77432 * Undefined if no set bit exists, so code should check against 0 first.
77433 */
77434-static __always_inline unsigned long __fls(unsigned long word)
77435+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77436 {
77437 int num = BITS_PER_LONG - 1;
77438
77439diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77440index 0576d1f..dad6c71 100644
77441--- a/include/asm-generic/bitops/fls.h
77442+++ b/include/asm-generic/bitops/fls.h
77443@@ -9,7 +9,7 @@
77444 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77445 */
77446
77447-static __always_inline int fls(int x)
77448+static __always_inline int __intentional_overflow(-1) fls(int x)
77449 {
77450 int r = 32;
77451
77452diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77453index b097cf8..3d40e14 100644
77454--- a/include/asm-generic/bitops/fls64.h
77455+++ b/include/asm-generic/bitops/fls64.h
77456@@ -15,7 +15,7 @@
77457 * at position 64.
77458 */
77459 #if BITS_PER_LONG == 32
77460-static __always_inline int fls64(__u64 x)
77461+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77462 {
77463 __u32 h = x >> 32;
77464 if (h)
77465@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77466 return fls(x);
77467 }
77468 #elif BITS_PER_LONG == 64
77469-static __always_inline int fls64(__u64 x)
77470+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77471 {
77472 if (x == 0)
77473 return 0;
77474diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77475index 1bfcfe5..e04c5c9 100644
77476--- a/include/asm-generic/cache.h
77477+++ b/include/asm-generic/cache.h
77478@@ -6,7 +6,7 @@
77479 * cache lines need to provide their own cache.h.
77480 */
77481
77482-#define L1_CACHE_SHIFT 5
77483-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77484+#define L1_CACHE_SHIFT 5UL
77485+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77486
77487 #endif /* __ASM_GENERIC_CACHE_H */
77488diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77489index 0d68a1e..b74a761 100644
77490--- a/include/asm-generic/emergency-restart.h
77491+++ b/include/asm-generic/emergency-restart.h
77492@@ -1,7 +1,7 @@
77493 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77494 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77495
77496-static inline void machine_emergency_restart(void)
77497+static inline __noreturn void machine_emergency_restart(void)
77498 {
77499 machine_restart(NULL);
77500 }
77501diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
77502index 975e1cc..0b8a083 100644
77503--- a/include/asm-generic/io.h
77504+++ b/include/asm-generic/io.h
77505@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
77506 * These are pretty trivial
77507 */
77508 #ifndef virt_to_phys
77509-static inline unsigned long virt_to_phys(volatile void *address)
77510+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
77511 {
77512 return __pa((unsigned long)address);
77513 }
77514diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77515index 90f99c7..00ce236 100644
77516--- a/include/asm-generic/kmap_types.h
77517+++ b/include/asm-generic/kmap_types.h
77518@@ -2,9 +2,9 @@
77519 #define _ASM_GENERIC_KMAP_TYPES_H
77520
77521 #ifdef __WITH_KM_FENCE
77522-# define KM_TYPE_NR 41
77523+# define KM_TYPE_NR 42
77524 #else
77525-# define KM_TYPE_NR 20
77526+# define KM_TYPE_NR 21
77527 #endif
77528
77529 #endif
77530diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77531index 9ceb03b..62b0b8f 100644
77532--- a/include/asm-generic/local.h
77533+++ b/include/asm-generic/local.h
77534@@ -23,24 +23,37 @@ typedef struct
77535 atomic_long_t a;
77536 } local_t;
77537
77538+typedef struct {
77539+ atomic_long_unchecked_t a;
77540+} local_unchecked_t;
77541+
77542 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77543
77544 #define local_read(l) atomic_long_read(&(l)->a)
77545+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77546 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77547+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77548 #define local_inc(l) atomic_long_inc(&(l)->a)
77549+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77550 #define local_dec(l) atomic_long_dec(&(l)->a)
77551+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77552 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77553+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77554 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77555+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77556
77557 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77558 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77559 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77560 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77561 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77562+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77563 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77564 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77565+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77566
77567 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77568+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77569 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77570 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77571 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77572diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77573index 725612b..9cc513a 100644
77574--- a/include/asm-generic/pgtable-nopmd.h
77575+++ b/include/asm-generic/pgtable-nopmd.h
77576@@ -1,14 +1,19 @@
77577 #ifndef _PGTABLE_NOPMD_H
77578 #define _PGTABLE_NOPMD_H
77579
77580-#ifndef __ASSEMBLY__
77581-
77582 #include <asm-generic/pgtable-nopud.h>
77583
77584-struct mm_struct;
77585-
77586 #define __PAGETABLE_PMD_FOLDED
77587
77588+#define PMD_SHIFT PUD_SHIFT
77589+#define PTRS_PER_PMD 1
77590+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77591+#define PMD_MASK (~(PMD_SIZE-1))
77592+
77593+#ifndef __ASSEMBLY__
77594+
77595+struct mm_struct;
77596+
77597 /*
77598 * Having the pmd type consist of a pud gets the size right, and allows
77599 * us to conceptually access the pud entry that this pmd is folded into
77600@@ -16,11 +21,6 @@ struct mm_struct;
77601 */
77602 typedef struct { pud_t pud; } pmd_t;
77603
77604-#define PMD_SHIFT PUD_SHIFT
77605-#define PTRS_PER_PMD 1
77606-#define PMD_SIZE (1UL << PMD_SHIFT)
77607-#define PMD_MASK (~(PMD_SIZE-1))
77608-
77609 /*
77610 * The "pud_xxx()" functions here are trivial for a folded two-level
77611 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77612diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77613index 810431d..0ec4804f 100644
77614--- a/include/asm-generic/pgtable-nopud.h
77615+++ b/include/asm-generic/pgtable-nopud.h
77616@@ -1,10 +1,15 @@
77617 #ifndef _PGTABLE_NOPUD_H
77618 #define _PGTABLE_NOPUD_H
77619
77620-#ifndef __ASSEMBLY__
77621-
77622 #define __PAGETABLE_PUD_FOLDED
77623
77624+#define PUD_SHIFT PGDIR_SHIFT
77625+#define PTRS_PER_PUD 1
77626+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77627+#define PUD_MASK (~(PUD_SIZE-1))
77628+
77629+#ifndef __ASSEMBLY__
77630+
77631 /*
77632 * Having the pud type consist of a pgd gets the size right, and allows
77633 * us to conceptually access the pgd entry that this pud is folded into
77634@@ -12,11 +17,6 @@
77635 */
77636 typedef struct { pgd_t pgd; } pud_t;
77637
77638-#define PUD_SHIFT PGDIR_SHIFT
77639-#define PTRS_PER_PUD 1
77640-#define PUD_SIZE (1UL << PUD_SHIFT)
77641-#define PUD_MASK (~(PUD_SIZE-1))
77642-
77643 /*
77644 * The "pgd_xxx()" functions here are trivial for a folded two-level
77645 * setup: the pud is never bad, and a pud always exists (as it's folded
77646@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77647 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77648
77649 #define pgd_populate(mm, pgd, pud) do { } while (0)
77650+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77651 /*
77652 * (puds are folded into pgds so this doesn't get actually called,
77653 * but the define is needed for a generic inline function.)
77654diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77655index a8015a7..7a4407b 100644
77656--- a/include/asm-generic/pgtable.h
77657+++ b/include/asm-generic/pgtable.h
77658@@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77659 }
77660 #endif /* CONFIG_NUMA_BALANCING */
77661
77662+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77663+#ifdef CONFIG_PAX_KERNEXEC
77664+#error KERNEXEC requires pax_open_kernel
77665+#else
77666+static inline unsigned long pax_open_kernel(void) { return 0; }
77667+#endif
77668+#endif
77669+
77670+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77671+#ifdef CONFIG_PAX_KERNEXEC
77672+#error KERNEXEC requires pax_close_kernel
77673+#else
77674+static inline unsigned long pax_close_kernel(void) { return 0; }
77675+#endif
77676+#endif
77677+
77678 #endif /* CONFIG_MMU */
77679
77680 #endif /* !__ASSEMBLY__ */
77681diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77682index 72d8803..cb9749c 100644
77683--- a/include/asm-generic/uaccess.h
77684+++ b/include/asm-generic/uaccess.h
77685@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77686 return __clear_user(to, n);
77687 }
77688
77689+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77690+#ifdef CONFIG_PAX_MEMORY_UDEREF
77691+#error UDEREF requires pax_open_userland
77692+#else
77693+static inline unsigned long pax_open_userland(void) { return 0; }
77694+#endif
77695+#endif
77696+
77697+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77698+#ifdef CONFIG_PAX_MEMORY_UDEREF
77699+#error UDEREF requires pax_close_userland
77700+#else
77701+static inline unsigned long pax_close_userland(void) { return 0; }
77702+#endif
77703+#endif
77704+
77705 #endif /* __ASM_GENERIC_UACCESS_H */
77706diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77707index 146e4ff..f4f9609 100644
77708--- a/include/asm-generic/vmlinux.lds.h
77709+++ b/include/asm-generic/vmlinux.lds.h
77710@@ -251,6 +251,7 @@
77711 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77712 VMLINUX_SYMBOL(__start_rodata) = .; \
77713 *(.rodata) *(.rodata.*) \
77714+ *(.data..read_only) \
77715 *(__vermagic) /* Kernel version magic */ \
77716 . = ALIGN(8); \
77717 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77718@@ -737,17 +738,18 @@
77719 * section in the linker script will go there too. @phdr should have
77720 * a leading colon.
77721 *
77722- * Note that this macros defines __per_cpu_load as an absolute symbol.
77723+ * Note that this macros defines per_cpu_load as an absolute symbol.
77724 * If there is no need to put the percpu section at a predetermined
77725 * address, use PERCPU_SECTION.
77726 */
77727 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77728- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77729- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77730+ per_cpu_load = .; \
77731+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77732 - LOAD_OFFSET) { \
77733+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77734 PERCPU_INPUT(cacheline) \
77735 } phdr \
77736- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77737+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77738
77739 /**
77740 * PERCPU_SECTION - define output section for percpu area, simple version
77741diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77742index 016c2f1..c4baa98 100644
77743--- a/include/crypto/algapi.h
77744+++ b/include/crypto/algapi.h
77745@@ -34,7 +34,7 @@ struct crypto_type {
77746 unsigned int maskclear;
77747 unsigned int maskset;
77748 unsigned int tfmsize;
77749-};
77750+} __do_const;
77751
77752 struct crypto_instance {
77753 struct crypto_alg alg;
77754diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77755index a7c2a86..078f1b6 100644
77756--- a/include/drm/drmP.h
77757+++ b/include/drm/drmP.h
77758@@ -68,6 +68,7 @@
77759 #include <linux/workqueue.h>
77760 #include <linux/poll.h>
77761 #include <asm/pgalloc.h>
77762+#include <asm/local.h>
77763 #include <drm/drm.h>
77764 #include <drm/drm_sarea.h>
77765 #include <drm/drm_vma_manager.h>
77766@@ -268,10 +269,12 @@ do { \
77767 * \param cmd command.
77768 * \param arg argument.
77769 */
77770-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77771+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77772+ struct drm_file *file_priv);
77773+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77774 struct drm_file *file_priv);
77775
77776-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77777+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77778 unsigned long arg);
77779
77780 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77781@@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77782 struct drm_ioctl_desc {
77783 unsigned int cmd;
77784 int flags;
77785- drm_ioctl_t *func;
77786+ drm_ioctl_t func;
77787 unsigned int cmd_drv;
77788 const char *name;
77789-};
77790+} __do_const;
77791
77792 /**
77793 * Creates a driver or general drm_ioctl_desc array entry for the given
77794@@ -1001,7 +1004,8 @@ struct drm_info_list {
77795 int (*show)(struct seq_file*, void*); /** show callback */
77796 u32 driver_features; /**< Required driver features for this entry */
77797 void *data;
77798-};
77799+} __do_const;
77800+typedef struct drm_info_list __no_const drm_info_list_no_const;
77801
77802 /**
77803 * debugfs node structure. This structure represents a debugfs file.
77804@@ -1083,7 +1087,7 @@ struct drm_device {
77805
77806 /** \name Usage Counters */
77807 /*@{ */
77808- int open_count; /**< Outstanding files open */
77809+ local_t open_count; /**< Outstanding files open */
77810 int buf_use; /**< Buffers in use -- cannot alloc */
77811 atomic_t buf_alloc; /**< Buffer allocation in progress */
77812 /*@} */
77813diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77814index 36a5feb..d9f01aa 100644
77815--- a/include/drm/drm_crtc_helper.h
77816+++ b/include/drm/drm_crtc_helper.h
77817@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77818 struct drm_connector *connector);
77819 /* disable encoder when not in use - more explicit than dpms off */
77820 void (*disable)(struct drm_encoder *encoder);
77821-};
77822+} __no_const;
77823
77824 /**
77825 * drm_connector_helper_funcs - helper operations for connectors
77826diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77827index 012d58f..d0a0642 100644
77828--- a/include/drm/i915_pciids.h
77829+++ b/include/drm/i915_pciids.h
77830@@ -37,7 +37,7 @@
77831 */
77832 #define INTEL_VGA_DEVICE(id, info) { \
77833 0x8086, id, \
77834- ~0, ~0, \
77835+ PCI_ANY_ID, PCI_ANY_ID, \
77836 0x030000, 0xff0000, \
77837 (unsigned long) info }
77838
77839diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77840index 72dcbe8..8db58d7 100644
77841--- a/include/drm/ttm/ttm_memory.h
77842+++ b/include/drm/ttm/ttm_memory.h
77843@@ -48,7 +48,7 @@
77844
77845 struct ttm_mem_shrink {
77846 int (*do_shrink) (struct ttm_mem_shrink *);
77847-};
77848+} __no_const;
77849
77850 /**
77851 * struct ttm_mem_global - Global memory accounting structure.
77852diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77853index 49a8284..9643967 100644
77854--- a/include/drm/ttm/ttm_page_alloc.h
77855+++ b/include/drm/ttm/ttm_page_alloc.h
77856@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77857 */
77858 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77859
77860+struct device;
77861 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77862 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77863
77864diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77865index 4b840e8..155d235 100644
77866--- a/include/keys/asymmetric-subtype.h
77867+++ b/include/keys/asymmetric-subtype.h
77868@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77869 /* Verify the signature on a key of this subtype (optional) */
77870 int (*verify_signature)(const struct key *key,
77871 const struct public_key_signature *sig);
77872-};
77873+} __do_const;
77874
77875 /**
77876 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77877diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77878index c1da539..1dcec55 100644
77879--- a/include/linux/atmdev.h
77880+++ b/include/linux/atmdev.h
77881@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77882 #endif
77883
77884 struct k_atm_aal_stats {
77885-#define __HANDLE_ITEM(i) atomic_t i
77886+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77887 __AAL_STAT_ITEMS
77888 #undef __HANDLE_ITEM
77889 };
77890@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77891 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77892 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77893 struct module *owner;
77894-};
77895+} __do_const ;
77896
77897 struct atmphy_ops {
77898 int (*start)(struct atm_dev *dev);
77899diff --git a/include/linux/audit.h b/include/linux/audit.h
77900index 22cfddb..ab759e8 100644
77901--- a/include/linux/audit.h
77902+++ b/include/linux/audit.h
77903@@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
77904 extern unsigned int audit_serial(void);
77905 extern int auditsc_get_stamp(struct audit_context *ctx,
77906 struct timespec *t, unsigned int *serial);
77907-extern int audit_set_loginuid(kuid_t loginuid);
77908+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77909
77910 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77911 {
77912diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77913index 61f29e5..e67c658 100644
77914--- a/include/linux/binfmts.h
77915+++ b/include/linux/binfmts.h
77916@@ -44,7 +44,7 @@ struct linux_binprm {
77917 unsigned interp_flags;
77918 unsigned interp_data;
77919 unsigned long loader, exec;
77920-};
77921+} __randomize_layout;
77922
77923 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77924 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77925@@ -73,8 +73,10 @@ struct linux_binfmt {
77926 int (*load_binary)(struct linux_binprm *);
77927 int (*load_shlib)(struct file *);
77928 int (*core_dump)(struct coredump_params *cprm);
77929+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77930+ void (*handle_mmap)(struct file *);
77931 unsigned long min_coredump; /* minimal dump size */
77932-};
77933+} __do_const __randomize_layout;
77934
77935 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77936
77937diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77938index be5fd38..d71192a 100644
77939--- a/include/linux/bitops.h
77940+++ b/include/linux/bitops.h
77941@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77942 * @word: value to rotate
77943 * @shift: bits to roll
77944 */
77945-static inline __u32 rol32(__u32 word, unsigned int shift)
77946+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77947 {
77948 return (word << shift) | (word >> (32 - shift));
77949 }
77950@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77951 * @word: value to rotate
77952 * @shift: bits to roll
77953 */
77954-static inline __u32 ror32(__u32 word, unsigned int shift)
77955+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77956 {
77957 return (word >> shift) | (word << (32 - shift));
77958 }
77959@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77960 return (__s32)(value << shift) >> shift;
77961 }
77962
77963-static inline unsigned fls_long(unsigned long l)
77964+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77965 {
77966 if (sizeof(l) == 4)
77967 return fls(l);
77968diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77969index 0d84981..bb741c0 100644
77970--- a/include/linux/blkdev.h
77971+++ b/include/linux/blkdev.h
77972@@ -1584,7 +1584,7 @@ struct block_device_operations {
77973 /* this callback is with swap_lock and sometimes page table lock held */
77974 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77975 struct module *owner;
77976-};
77977+} __do_const;
77978
77979 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77980 unsigned long);
77981diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77982index afc1343..9735539 100644
77983--- a/include/linux/blktrace_api.h
77984+++ b/include/linux/blktrace_api.h
77985@@ -25,7 +25,7 @@ struct blk_trace {
77986 struct dentry *dropped_file;
77987 struct dentry *msg_file;
77988 struct list_head running_list;
77989- atomic_t dropped;
77990+ atomic_unchecked_t dropped;
77991 };
77992
77993 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77994diff --git a/include/linux/cache.h b/include/linux/cache.h
77995index 17e7e82..1d7da26 100644
77996--- a/include/linux/cache.h
77997+++ b/include/linux/cache.h
77998@@ -16,6 +16,14 @@
77999 #define __read_mostly
78000 #endif
78001
78002+#ifndef __read_only
78003+#ifdef CONFIG_PAX_KERNEXEC
78004+#error KERNEXEC requires __read_only
78005+#else
78006+#define __read_only __read_mostly
78007+#endif
78008+#endif
78009+
78010 #ifndef ____cacheline_aligned
78011 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
78012 #endif
78013diff --git a/include/linux/capability.h b/include/linux/capability.h
78014index 84b13ad..172cdee 100644
78015--- a/include/linux/capability.h
78016+++ b/include/linux/capability.h
78017@@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
78018 extern bool capable(int cap);
78019 extern bool ns_capable(struct user_namespace *ns, int cap);
78020 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
78021+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
78022 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
78023+extern bool capable_nolog(int cap);
78024+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
78025
78026 /* audit system wants to get cap info from files as well */
78027 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
78028
78029+extern int is_privileged_binary(const struct dentry *dentry);
78030+
78031 #endif /* !_LINUX_CAPABILITY_H */
78032diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
78033index 8609d57..86e4d79 100644
78034--- a/include/linux/cdrom.h
78035+++ b/include/linux/cdrom.h
78036@@ -87,7 +87,6 @@ struct cdrom_device_ops {
78037
78038 /* driver specifications */
78039 const int capability; /* capability flags */
78040- int n_minors; /* number of active minor devices */
78041 /* handle uniform packets for scsi type devices (scsi,atapi) */
78042 int (*generic_packet) (struct cdrom_device_info *,
78043 struct packet_command *);
78044diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
78045index 4ce9056..86caac6 100644
78046--- a/include/linux/cleancache.h
78047+++ b/include/linux/cleancache.h
78048@@ -31,7 +31,7 @@ struct cleancache_ops {
78049 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
78050 void (*invalidate_inode)(int, struct cleancache_filekey);
78051 void (*invalidate_fs)(int);
78052-};
78053+} __no_const;
78054
78055 extern struct cleancache_ops *
78056 cleancache_register_ops(struct cleancache_ops *ops);
78057diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
78058index 5119174..8e264f8 100644
78059--- a/include/linux/clk-provider.h
78060+++ b/include/linux/clk-provider.h
78061@@ -174,6 +174,7 @@ struct clk_ops {
78062 void (*init)(struct clk_hw *hw);
78063 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
78064 };
78065+typedef struct clk_ops __no_const clk_ops_no_const;
78066
78067 /**
78068 * struct clk_init_data - holds init data that's common to all clocks and is
78069diff --git a/include/linux/compat.h b/include/linux/compat.h
78070index e649426..a74047b 100644
78071--- a/include/linux/compat.h
78072+++ b/include/linux/compat.h
78073@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
78074 compat_size_t __user *len_ptr);
78075
78076 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
78077-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
78078+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
78079 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
78080 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
78081 compat_ssize_t msgsz, int msgflg);
78082@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
78083 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
78084 compat_ulong_t addr, compat_ulong_t data);
78085 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
78086- compat_long_t addr, compat_long_t data);
78087+ compat_ulong_t addr, compat_ulong_t data);
78088
78089 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
78090 /*
78091diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
78092index 2507fd2..55203f8 100644
78093--- a/include/linux/compiler-gcc4.h
78094+++ b/include/linux/compiler-gcc4.h
78095@@ -39,9 +39,34 @@
78096 # define __compiletime_warning(message) __attribute__((warning(message)))
78097 # define __compiletime_error(message) __attribute__((error(message)))
78098 #endif /* __CHECKER__ */
78099+
78100+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
78101+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
78102+#define __bos0(ptr) __bos((ptr), 0)
78103+#define __bos1(ptr) __bos((ptr), 1)
78104 #endif /* GCC_VERSION >= 40300 */
78105
78106 #if GCC_VERSION >= 40500
78107+
78108+#ifdef RANDSTRUCT_PLUGIN
78109+#define __randomize_layout __attribute__((randomize_layout))
78110+#define __no_randomize_layout __attribute__((no_randomize_layout))
78111+#endif
78112+
78113+#ifdef CONSTIFY_PLUGIN
78114+#define __no_const __attribute__((no_const))
78115+#define __do_const __attribute__((do_const))
78116+#endif
78117+
78118+#ifdef SIZE_OVERFLOW_PLUGIN
78119+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
78120+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
78121+#endif
78122+
78123+#ifdef LATENT_ENTROPY_PLUGIN
78124+#define __latent_entropy __attribute__((latent_entropy))
78125+#endif
78126+
78127 /*
78128 * Mark a position in code as unreachable. This can be used to
78129 * suppress control flow warnings after asm blocks that transfer
78130diff --git a/include/linux/compiler.h b/include/linux/compiler.h
78131index ee7239e..7c11769 100644
78132--- a/include/linux/compiler.h
78133+++ b/include/linux/compiler.h
78134@@ -5,11 +5,14 @@
78135
78136 #ifdef __CHECKER__
78137 # define __user __attribute__((noderef, address_space(1)))
78138+# define __force_user __force __user
78139 # define __kernel __attribute__((address_space(0)))
78140+# define __force_kernel __force __kernel
78141 # define __safe __attribute__((safe))
78142 # define __force __attribute__((force))
78143 # define __nocast __attribute__((nocast))
78144 # define __iomem __attribute__((noderef, address_space(2)))
78145+# define __force_iomem __force __iomem
78146 # define __must_hold(x) __attribute__((context(x,1,1)))
78147 # define __acquires(x) __attribute__((context(x,0,1)))
78148 # define __releases(x) __attribute__((context(x,1,0)))
78149@@ -17,20 +20,37 @@
78150 # define __release(x) __context__(x,-1)
78151 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
78152 # define __percpu __attribute__((noderef, address_space(3)))
78153+# define __force_percpu __force __percpu
78154 #ifdef CONFIG_SPARSE_RCU_POINTER
78155 # define __rcu __attribute__((noderef, address_space(4)))
78156+# define __force_rcu __force __rcu
78157 #else
78158 # define __rcu
78159+# define __force_rcu
78160 #endif
78161 extern void __chk_user_ptr(const volatile void __user *);
78162 extern void __chk_io_ptr(const volatile void __iomem *);
78163 #else
78164-# define __user
78165-# define __kernel
78166+# ifdef CHECKER_PLUGIN
78167+//# define __user
78168+//# define __force_user
78169+//# define __kernel
78170+//# define __force_kernel
78171+# else
78172+# ifdef STRUCTLEAK_PLUGIN
78173+# define __user __attribute__((user))
78174+# else
78175+# define __user
78176+# endif
78177+# define __force_user
78178+# define __kernel
78179+# define __force_kernel
78180+# endif
78181 # define __safe
78182 # define __force
78183 # define __nocast
78184 # define __iomem
78185+# define __force_iomem
78186 # define __chk_user_ptr(x) (void)0
78187 # define __chk_io_ptr(x) (void)0
78188 # define __builtin_warning(x, y...) (1)
78189@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
78190 # define __release(x) (void)0
78191 # define __cond_lock(x,c) (c)
78192 # define __percpu
78193+# define __force_percpu
78194 # define __rcu
78195+# define __force_rcu
78196 #endif
78197
78198 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
78199@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78200 # define __attribute_const__ /* unimplemented */
78201 #endif
78202
78203+#ifndef __randomize_layout
78204+# define __randomize_layout
78205+#endif
78206+
78207+#ifndef __no_randomize_layout
78208+# define __no_randomize_layout
78209+#endif
78210+
78211+#ifndef __no_const
78212+# define __no_const
78213+#endif
78214+
78215+#ifndef __do_const
78216+# define __do_const
78217+#endif
78218+
78219+#ifndef __size_overflow
78220+# define __size_overflow(...)
78221+#endif
78222+
78223+#ifndef __intentional_overflow
78224+# define __intentional_overflow(...)
78225+#endif
78226+
78227+#ifndef __latent_entropy
78228+# define __latent_entropy
78229+#endif
78230+
78231 /*
78232 * Tell gcc if a function is cold. The compiler will assume any path
78233 * directly leading to the call is unlikely.
78234@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78235 #define __cold
78236 #endif
78237
78238+#ifndef __alloc_size
78239+#define __alloc_size(...)
78240+#endif
78241+
78242+#ifndef __bos
78243+#define __bos(ptr, arg)
78244+#endif
78245+
78246+#ifndef __bos0
78247+#define __bos0(ptr)
78248+#endif
78249+
78250+#ifndef __bos1
78251+#define __bos1(ptr)
78252+#endif
78253+
78254 /* Simple shorthand for a section definition */
78255 #ifndef __section
78256 # define __section(S) __attribute__ ((__section__(#S)))
78257@@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78258 * use is to mediate communication between process-level code and irq/NMI
78259 * handlers, all running on the same CPU.
78260 */
78261-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78262+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78263+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78264
78265 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78266 #ifdef CONFIG_KPROBES
78267diff --git a/include/linux/completion.h b/include/linux/completion.h
78268index 5d5aaae..0ea9b84 100644
78269--- a/include/linux/completion.h
78270+++ b/include/linux/completion.h
78271@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78272
78273 extern void wait_for_completion(struct completion *);
78274 extern void wait_for_completion_io(struct completion *);
78275-extern int wait_for_completion_interruptible(struct completion *x);
78276-extern int wait_for_completion_killable(struct completion *x);
78277+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78278+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78279 extern unsigned long wait_for_completion_timeout(struct completion *x,
78280- unsigned long timeout);
78281+ unsigned long timeout) __intentional_overflow(-1);
78282 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78283- unsigned long timeout);
78284+ unsigned long timeout) __intentional_overflow(-1);
78285 extern long wait_for_completion_interruptible_timeout(
78286- struct completion *x, unsigned long timeout);
78287+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78288 extern long wait_for_completion_killable_timeout(
78289- struct completion *x, unsigned long timeout);
78290+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78291 extern bool try_wait_for_completion(struct completion *x);
78292 extern bool completion_done(struct completion *x);
78293
78294diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78295index 34025df..d94bbbc 100644
78296--- a/include/linux/configfs.h
78297+++ b/include/linux/configfs.h
78298@@ -125,7 +125,7 @@ struct configfs_attribute {
78299 const char *ca_name;
78300 struct module *ca_owner;
78301 umode_t ca_mode;
78302-};
78303+} __do_const;
78304
78305 /*
78306 * Users often need to create attribute structures for their configurable
78307diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78308index 5ae5100..b809662 100644
78309--- a/include/linux/cpufreq.h
78310+++ b/include/linux/cpufreq.h
78311@@ -200,6 +200,7 @@ struct global_attr {
78312 ssize_t (*store)(struct kobject *a, struct attribute *b,
78313 const char *c, size_t count);
78314 };
78315+typedef struct global_attr __no_const global_attr_no_const;
78316
78317 #define define_one_global_ro(_name) \
78318 static struct global_attr _name = \
78319@@ -242,7 +243,7 @@ struct cpufreq_driver {
78320 bool boost_supported;
78321 bool boost_enabled;
78322 int (*set_boost) (int state);
78323-};
78324+} __do_const;
78325
78326 /* flags */
78327 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78328diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78329index b0238cb..db89e1e 100644
78330--- a/include/linux/cpuidle.h
78331+++ b/include/linux/cpuidle.h
78332@@ -50,7 +50,8 @@ struct cpuidle_state {
78333 int index);
78334
78335 int (*enter_dead) (struct cpuidle_device *dev, int index);
78336-};
78337+} __do_const;
78338+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78339
78340 /* Idle State Flags */
78341 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78342@@ -211,7 +212,7 @@ struct cpuidle_governor {
78343 void (*reflect) (struct cpuidle_device *dev, int index);
78344
78345 struct module *owner;
78346-};
78347+} __do_const;
78348
78349 #ifdef CONFIG_CPU_IDLE
78350 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78351diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78352index d08e4d2..95fad61 100644
78353--- a/include/linux/cpumask.h
78354+++ b/include/linux/cpumask.h
78355@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78356 }
78357
78358 /* Valid inputs for n are -1 and 0. */
78359-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78360+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78361 {
78362 return n+1;
78363 }
78364
78365-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78366+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78367 {
78368 return n+1;
78369 }
78370
78371-static inline unsigned int cpumask_next_and(int n,
78372+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78373 const struct cpumask *srcp,
78374 const struct cpumask *andp)
78375 {
78376@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78377 *
78378 * Returns >= nr_cpu_ids if no further cpus set.
78379 */
78380-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78381+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78382 {
78383 /* -1 is a legal arg here. */
78384 if (n != -1)
78385@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78386 *
78387 * Returns >= nr_cpu_ids if no further cpus unset.
78388 */
78389-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78390+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78391 {
78392 /* -1 is a legal arg here. */
78393 if (n != -1)
78394@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78395 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78396 }
78397
78398-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78399+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78400 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78401
78402 /**
78403diff --git a/include/linux/cred.h b/include/linux/cred.h
78404index f61d6c8..d372d95 100644
78405--- a/include/linux/cred.h
78406+++ b/include/linux/cred.h
78407@@ -35,7 +35,7 @@ struct group_info {
78408 int nblocks;
78409 kgid_t small_block[NGROUPS_SMALL];
78410 kgid_t *blocks[0];
78411-};
78412+} __randomize_layout;
78413
78414 /**
78415 * get_group_info - Get a reference to a group info structure
78416@@ -136,7 +136,7 @@ struct cred {
78417 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78418 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78419 struct rcu_head rcu; /* RCU deletion hook */
78420-};
78421+} __randomize_layout;
78422
78423 extern void __put_cred(struct cred *);
78424 extern void exit_creds(struct task_struct *);
78425@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78426 static inline void validate_process_creds(void)
78427 {
78428 }
78429+static inline void validate_task_creds(struct task_struct *task)
78430+{
78431+}
78432 #endif
78433
78434 /**
78435@@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
78436
78437 #define task_uid(task) (task_cred_xxx((task), uid))
78438 #define task_euid(task) (task_cred_xxx((task), euid))
78439+#define task_securebits(task) (task_cred_xxx((task), securebits))
78440
78441 #define current_cred_xxx(xxx) \
78442 ({ \
78443diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78444index b92eadf..b4ecdc1 100644
78445--- a/include/linux/crypto.h
78446+++ b/include/linux/crypto.h
78447@@ -373,7 +373,7 @@ struct cipher_tfm {
78448 const u8 *key, unsigned int keylen);
78449 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78450 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78451-};
78452+} __no_const;
78453
78454 struct hash_tfm {
78455 int (*init)(struct hash_desc *desc);
78456@@ -394,13 +394,13 @@ struct compress_tfm {
78457 int (*cot_decompress)(struct crypto_tfm *tfm,
78458 const u8 *src, unsigned int slen,
78459 u8 *dst, unsigned int *dlen);
78460-};
78461+} __no_const;
78462
78463 struct rng_tfm {
78464 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78465 unsigned int dlen);
78466 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78467-};
78468+} __no_const;
78469
78470 #define crt_ablkcipher crt_u.ablkcipher
78471 #define crt_aead crt_u.aead
78472diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78473index 653589e..4ef254a 100644
78474--- a/include/linux/ctype.h
78475+++ b/include/linux/ctype.h
78476@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78477 * Fast implementation of tolower() for internal usage. Do not use in your
78478 * code.
78479 */
78480-static inline char _tolower(const char c)
78481+static inline unsigned char _tolower(const unsigned char c)
78482 {
78483 return c | 0x20;
78484 }
78485diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78486index 3c7ec32..4ca97cc 100644
78487--- a/include/linux/dcache.h
78488+++ b/include/linux/dcache.h
78489@@ -133,7 +133,7 @@ struct dentry {
78490 } d_u;
78491 struct list_head d_subdirs; /* our children */
78492 struct hlist_node d_alias; /* inode alias list */
78493-};
78494+} __randomize_layout;
78495
78496 /*
78497 * dentry->d_lock spinlock nesting subclasses:
78498diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78499index 7925bf0..d5143d2 100644
78500--- a/include/linux/decompress/mm.h
78501+++ b/include/linux/decompress/mm.h
78502@@ -77,7 +77,7 @@ static void free(void *where)
78503 * warnings when not needed (indeed large_malloc / large_free are not
78504 * needed by inflate */
78505
78506-#define malloc(a) kmalloc(a, GFP_KERNEL)
78507+#define malloc(a) kmalloc((a), GFP_KERNEL)
78508 #define free(a) kfree(a)
78509
78510 #define large_malloc(a) vmalloc(a)
78511diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78512index d48dc00..211ee54 100644
78513--- a/include/linux/devfreq.h
78514+++ b/include/linux/devfreq.h
78515@@ -114,7 +114,7 @@ struct devfreq_governor {
78516 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78517 int (*event_handler)(struct devfreq *devfreq,
78518 unsigned int event, void *data);
78519-};
78520+} __do_const;
78521
78522 /**
78523 * struct devfreq - Device devfreq structure
78524diff --git a/include/linux/device.h b/include/linux/device.h
78525index d1d1c05..a90fdb0 100644
78526--- a/include/linux/device.h
78527+++ b/include/linux/device.h
78528@@ -310,7 +310,7 @@ struct subsys_interface {
78529 struct list_head node;
78530 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78531 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78532-};
78533+} __do_const;
78534
78535 int subsys_interface_register(struct subsys_interface *sif);
78536 void subsys_interface_unregister(struct subsys_interface *sif);
78537@@ -506,7 +506,7 @@ struct device_type {
78538 void (*release)(struct device *dev);
78539
78540 const struct dev_pm_ops *pm;
78541-};
78542+} __do_const;
78543
78544 /* interface for exporting device attributes */
78545 struct device_attribute {
78546@@ -516,11 +516,12 @@ struct device_attribute {
78547 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78548 const char *buf, size_t count);
78549 };
78550+typedef struct device_attribute __no_const device_attribute_no_const;
78551
78552 struct dev_ext_attribute {
78553 struct device_attribute attr;
78554 void *var;
78555-};
78556+} __do_const;
78557
78558 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78559 char *buf);
78560diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78561index fd4aee2..1f28db9 100644
78562--- a/include/linux/dma-mapping.h
78563+++ b/include/linux/dma-mapping.h
78564@@ -54,7 +54,7 @@ struct dma_map_ops {
78565 u64 (*get_required_mask)(struct device *dev);
78566 #endif
78567 int is_phys;
78568-};
78569+} __do_const;
78570
78571 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78572
78573diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78574index 72cb0dd..7fe9a4b 100644
78575--- a/include/linux/dmaengine.h
78576+++ b/include/linux/dmaengine.h
78577@@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78578 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78579 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78580
78581-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78582+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78583 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78584-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78585+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78586 struct dma_pinned_list *pinned_list, struct page *page,
78587 unsigned int offset, size_t len);
78588
78589diff --git a/include/linux/efi.h b/include/linux/efi.h
78590index 6c100ff..e3289b4 100644
78591--- a/include/linux/efi.h
78592+++ b/include/linux/efi.h
78593@@ -1009,6 +1009,7 @@ struct efivar_operations {
78594 efi_set_variable_t *set_variable;
78595 efi_query_variable_store_t *query_variable_store;
78596 };
78597+typedef struct efivar_operations __no_const efivar_operations_no_const;
78598
78599 struct efivars {
78600 /*
78601diff --git a/include/linux/elf.h b/include/linux/elf.h
78602index 67a5fa7..b817372 100644
78603--- a/include/linux/elf.h
78604+++ b/include/linux/elf.h
78605@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78606 #define elf_note elf32_note
78607 #define elf_addr_t Elf32_Off
78608 #define Elf_Half Elf32_Half
78609+#define elf_dyn Elf32_Dyn
78610
78611 #else
78612
78613@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78614 #define elf_note elf64_note
78615 #define elf_addr_t Elf64_Off
78616 #define Elf_Half Elf64_Half
78617+#define elf_dyn Elf64_Dyn
78618
78619 #endif
78620
78621diff --git a/include/linux/err.h b/include/linux/err.h
78622index a729120..6ede2c9 100644
78623--- a/include/linux/err.h
78624+++ b/include/linux/err.h
78625@@ -20,12 +20,12 @@
78626
78627 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78628
78629-static inline void * __must_check ERR_PTR(long error)
78630+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78631 {
78632 return (void *) error;
78633 }
78634
78635-static inline long __must_check PTR_ERR(__force const void *ptr)
78636+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78637 {
78638 return (long) ptr;
78639 }
78640diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78641index f488145..3b6b04e 100644
78642--- a/include/linux/extcon.h
78643+++ b/include/linux/extcon.h
78644@@ -135,7 +135,7 @@ struct extcon_dev {
78645 /* /sys/class/extcon/.../mutually_exclusive/... */
78646 struct attribute_group attr_g_muex;
78647 struct attribute **attrs_muex;
78648- struct device_attribute *d_attrs_muex;
78649+ device_attribute_no_const *d_attrs_muex;
78650 };
78651
78652 /**
78653diff --git a/include/linux/fb.h b/include/linux/fb.h
78654index fe6ac95..898d41d 100644
78655--- a/include/linux/fb.h
78656+++ b/include/linux/fb.h
78657@@ -304,7 +304,7 @@ struct fb_ops {
78658 /* called at KDB enter and leave time to prepare the console */
78659 int (*fb_debug_enter)(struct fb_info *info);
78660 int (*fb_debug_leave)(struct fb_info *info);
78661-};
78662+} __do_const;
78663
78664 #ifdef CONFIG_FB_TILEBLITTING
78665 #define FB_TILE_CURSOR_NONE 0
78666diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78667index 230f87b..1fd0485 100644
78668--- a/include/linux/fdtable.h
78669+++ b/include/linux/fdtable.h
78670@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78671 void put_files_struct(struct files_struct *fs);
78672 void reset_files_struct(struct files_struct *);
78673 int unshare_files(struct files_struct **);
78674-struct files_struct *dup_fd(struct files_struct *, int *);
78675+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78676 void do_close_on_exec(struct files_struct *);
78677 int iterate_fd(struct files_struct *, unsigned,
78678 int (*)(const void *, struct file *, unsigned),
78679diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78680index 8293262..2b3b8bd 100644
78681--- a/include/linux/frontswap.h
78682+++ b/include/linux/frontswap.h
78683@@ -11,7 +11,7 @@ struct frontswap_ops {
78684 int (*load)(unsigned, pgoff_t, struct page *);
78685 void (*invalidate_page)(unsigned, pgoff_t);
78686 void (*invalidate_area)(unsigned);
78687-};
78688+} __no_const;
78689
78690 extern bool frontswap_enabled;
78691 extern struct frontswap_ops *
78692diff --git a/include/linux/fs.h b/include/linux/fs.h
78693index 8780312..425cc22 100644
78694--- a/include/linux/fs.h
78695+++ b/include/linux/fs.h
78696@@ -398,7 +398,7 @@ struct address_space {
78697 spinlock_t private_lock; /* for use by the address_space */
78698 struct list_head private_list; /* ditto */
78699 void *private_data; /* ditto */
78700-} __attribute__((aligned(sizeof(long))));
78701+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78702 /*
78703 * On most architectures that alignment is already the case; but
78704 * must be enforced here for CRIS, to let the least significant bit
78705@@ -441,7 +441,7 @@ struct block_device {
78706 int bd_fsfreeze_count;
78707 /* Mutex for freeze */
78708 struct mutex bd_fsfreeze_mutex;
78709-};
78710+} __randomize_layout;
78711
78712 /*
78713 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78714@@ -585,7 +585,7 @@ struct inode {
78715 #endif
78716
78717 void *i_private; /* fs or device private pointer */
78718-};
78719+} __randomize_layout;
78720
78721 static inline int inode_unhashed(struct inode *inode)
78722 {
78723@@ -778,7 +778,7 @@ struct file {
78724 struct list_head f_tfile_llink;
78725 #endif /* #ifdef CONFIG_EPOLL */
78726 struct address_space *f_mapping;
78727-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78728+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78729
78730 struct file_handle {
78731 __u32 handle_bytes;
78732@@ -906,7 +906,7 @@ struct file_lock {
78733 int state; /* state of grant or error if -ve */
78734 } afs;
78735 } fl_u;
78736-};
78737+} __randomize_layout;
78738
78739 /* The following constant reflects the upper bound of the file/locking space */
78740 #ifndef OFFSET_MAX
78741@@ -1255,7 +1255,7 @@ struct super_block {
78742 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78743 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78744 struct rcu_head rcu;
78745-};
78746+} __randomize_layout;
78747
78748 extern struct timespec current_fs_time(struct super_block *sb);
78749
78750@@ -1477,7 +1477,8 @@ struct file_operations {
78751 long (*fallocate)(struct file *file, int mode, loff_t offset,
78752 loff_t len);
78753 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78754-};
78755+} __do_const __randomize_layout;
78756+typedef struct file_operations __no_const file_operations_no_const;
78757
78758 struct inode_operations {
78759 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78760@@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
78761 return !IS_DEADDIR(inode);
78762 }
78763
78764+static inline bool is_sidechannel_device(const struct inode *inode)
78765+{
78766+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78767+ umode_t mode = inode->i_mode;
78768+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78769+#else
78770+ return false;
78771+#endif
78772+}
78773+
78774 #endif /* _LINUX_FS_H */
78775diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78776index 0efc3e6..fd23610 100644
78777--- a/include/linux/fs_struct.h
78778+++ b/include/linux/fs_struct.h
78779@@ -6,13 +6,13 @@
78780 #include <linux/seqlock.h>
78781
78782 struct fs_struct {
78783- int users;
78784+ atomic_t users;
78785 spinlock_t lock;
78786 seqcount_t seq;
78787 int umask;
78788 int in_exec;
78789 struct path root, pwd;
78790-};
78791+} __randomize_layout;
78792
78793 extern struct kmem_cache *fs_cachep;
78794
78795diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78796index 7714849..a4a5c7a 100644
78797--- a/include/linux/fscache-cache.h
78798+++ b/include/linux/fscache-cache.h
78799@@ -113,7 +113,7 @@ struct fscache_operation {
78800 fscache_operation_release_t release;
78801 };
78802
78803-extern atomic_t fscache_op_debug_id;
78804+extern atomic_unchecked_t fscache_op_debug_id;
78805 extern void fscache_op_work_func(struct work_struct *work);
78806
78807 extern void fscache_enqueue_operation(struct fscache_operation *);
78808@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78809 INIT_WORK(&op->work, fscache_op_work_func);
78810 atomic_set(&op->usage, 1);
78811 op->state = FSCACHE_OP_ST_INITIALISED;
78812- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78813+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78814 op->processor = processor;
78815 op->release = release;
78816 INIT_LIST_HEAD(&op->pend_link);
78817diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78818index 115bb81..e7b812b 100644
78819--- a/include/linux/fscache.h
78820+++ b/include/linux/fscache.h
78821@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78822 * - this is mandatory for any object that may have data
78823 */
78824 void (*now_uncached)(void *cookie_netfs_data);
78825-};
78826+} __do_const;
78827
78828 /*
78829 * fscache cached network filesystem type
78830diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78831index 1c804b0..1432c2b 100644
78832--- a/include/linux/fsnotify.h
78833+++ b/include/linux/fsnotify.h
78834@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78835 struct inode *inode = file_inode(file);
78836 __u32 mask = FS_ACCESS;
78837
78838+ if (is_sidechannel_device(inode))
78839+ return;
78840+
78841 if (S_ISDIR(inode->i_mode))
78842 mask |= FS_ISDIR;
78843
78844@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78845 struct inode *inode = file_inode(file);
78846 __u32 mask = FS_MODIFY;
78847
78848+ if (is_sidechannel_device(inode))
78849+ return;
78850+
78851 if (S_ISDIR(inode->i_mode))
78852 mask |= FS_ISDIR;
78853
78854@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78855 */
78856 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78857 {
78858- return kstrdup(name, GFP_KERNEL);
78859+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78860 }
78861
78862 /*
78863diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78864index 9f3c275..8bdff5d 100644
78865--- a/include/linux/genhd.h
78866+++ b/include/linux/genhd.h
78867@@ -194,7 +194,7 @@ struct gendisk {
78868 struct kobject *slave_dir;
78869
78870 struct timer_rand_state *random;
78871- atomic_t sync_io; /* RAID */
78872+ atomic_unchecked_t sync_io; /* RAID */
78873 struct disk_events *ev;
78874 #ifdef CONFIG_BLK_DEV_INTEGRITY
78875 struct blk_integrity *integrity;
78876@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78877 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78878
78879 /* drivers/char/random.c */
78880-extern void add_disk_randomness(struct gendisk *disk);
78881+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78882 extern void rand_initialize_disk(struct gendisk *disk);
78883
78884 static inline sector_t get_start_sect(struct block_device *bdev)
78885diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78886index c0894dd..2fbf10c 100644
78887--- a/include/linux/genl_magic_func.h
78888+++ b/include/linux/genl_magic_func.h
78889@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78890 },
78891
78892 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78893-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78894+static struct genl_ops ZZZ_genl_ops[] = {
78895 #include GENL_MAGIC_INCLUDE_FILE
78896 };
78897
78898diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78899index 39b81dc..819dc51 100644
78900--- a/include/linux/gfp.h
78901+++ b/include/linux/gfp.h
78902@@ -36,6 +36,13 @@ struct vm_area_struct;
78903 #define ___GFP_NO_KSWAPD 0x400000u
78904 #define ___GFP_OTHER_NODE 0x800000u
78905 #define ___GFP_WRITE 0x1000000u
78906+
78907+#ifdef CONFIG_PAX_USERCOPY_SLABS
78908+#define ___GFP_USERCOPY 0x2000000u
78909+#else
78910+#define ___GFP_USERCOPY 0
78911+#endif
78912+
78913 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78914
78915 /*
78916@@ -93,6 +100,7 @@ struct vm_area_struct;
78917 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78918 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78919 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78920+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78921
78922 /*
78923 * This may seem redundant, but it's a way of annotating false positives vs.
78924@@ -100,7 +108,7 @@ struct vm_area_struct;
78925 */
78926 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78927
78928-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78929+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78930 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78931
78932 /* This equals 0, but use constants in case they ever change */
78933@@ -158,6 +166,8 @@ struct vm_area_struct;
78934 /* 4GB DMA on some platforms */
78935 #define GFP_DMA32 __GFP_DMA32
78936
78937+#define GFP_USERCOPY __GFP_USERCOPY
78938+
78939 /* Convert GFP flags to their corresponding migrate type */
78940 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78941 {
78942diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78943new file mode 100644
78944index 0000000..edb2cb6
78945--- /dev/null
78946+++ b/include/linux/gracl.h
78947@@ -0,0 +1,340 @@
78948+#ifndef GR_ACL_H
78949+#define GR_ACL_H
78950+
78951+#include <linux/grdefs.h>
78952+#include <linux/resource.h>
78953+#include <linux/capability.h>
78954+#include <linux/dcache.h>
78955+#include <asm/resource.h>
78956+
78957+/* Major status information */
78958+
78959+#define GR_VERSION "grsecurity 3.0"
78960+#define GRSECURITY_VERSION 0x3000
78961+
78962+enum {
78963+ GR_SHUTDOWN = 0,
78964+ GR_ENABLE = 1,
78965+ GR_SPROLE = 2,
78966+ GR_OLDRELOAD = 3,
78967+ GR_SEGVMOD = 4,
78968+ GR_STATUS = 5,
78969+ GR_UNSPROLE = 6,
78970+ GR_PASSSET = 7,
78971+ GR_SPROLEPAM = 8,
78972+ GR_RELOAD = 9,
78973+};
78974+
78975+/* Password setup definitions
78976+ * kernel/grhash.c */
78977+enum {
78978+ GR_PW_LEN = 128,
78979+ GR_SALT_LEN = 16,
78980+ GR_SHA_LEN = 32,
78981+};
78982+
78983+enum {
78984+ GR_SPROLE_LEN = 64,
78985+};
78986+
78987+enum {
78988+ GR_NO_GLOB = 0,
78989+ GR_REG_GLOB,
78990+ GR_CREATE_GLOB
78991+};
78992+
78993+#define GR_NLIMITS 32
78994+
78995+/* Begin Data Structures */
78996+
78997+struct sprole_pw {
78998+ unsigned char *rolename;
78999+ unsigned char salt[GR_SALT_LEN];
79000+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
79001+};
79002+
79003+struct name_entry {
79004+ __u32 key;
79005+ ino_t inode;
79006+ dev_t device;
79007+ char *name;
79008+ __u16 len;
79009+ __u8 deleted;
79010+ struct name_entry *prev;
79011+ struct name_entry *next;
79012+};
79013+
79014+struct inodev_entry {
79015+ struct name_entry *nentry;
79016+ struct inodev_entry *prev;
79017+ struct inodev_entry *next;
79018+};
79019+
79020+struct acl_role_db {
79021+ struct acl_role_label **r_hash;
79022+ __u32 r_size;
79023+};
79024+
79025+struct inodev_db {
79026+ struct inodev_entry **i_hash;
79027+ __u32 i_size;
79028+};
79029+
79030+struct name_db {
79031+ struct name_entry **n_hash;
79032+ __u32 n_size;
79033+};
79034+
79035+struct crash_uid {
79036+ uid_t uid;
79037+ unsigned long expires;
79038+};
79039+
79040+struct gr_hash_struct {
79041+ void **table;
79042+ void **nametable;
79043+ void *first;
79044+ __u32 table_size;
79045+ __u32 used_size;
79046+ int type;
79047+};
79048+
79049+/* Userspace Grsecurity ACL data structures */
79050+
79051+struct acl_subject_label {
79052+ char *filename;
79053+ ino_t inode;
79054+ dev_t device;
79055+ __u32 mode;
79056+ kernel_cap_t cap_mask;
79057+ kernel_cap_t cap_lower;
79058+ kernel_cap_t cap_invert_audit;
79059+
79060+ struct rlimit res[GR_NLIMITS];
79061+ __u32 resmask;
79062+
79063+ __u8 user_trans_type;
79064+ __u8 group_trans_type;
79065+ uid_t *user_transitions;
79066+ gid_t *group_transitions;
79067+ __u16 user_trans_num;
79068+ __u16 group_trans_num;
79069+
79070+ __u32 sock_families[2];
79071+ __u32 ip_proto[8];
79072+ __u32 ip_type;
79073+ struct acl_ip_label **ips;
79074+ __u32 ip_num;
79075+ __u32 inaddr_any_override;
79076+
79077+ __u32 crashes;
79078+ unsigned long expires;
79079+
79080+ struct acl_subject_label *parent_subject;
79081+ struct gr_hash_struct *hash;
79082+ struct acl_subject_label *prev;
79083+ struct acl_subject_label *next;
79084+
79085+ struct acl_object_label **obj_hash;
79086+ __u32 obj_hash_size;
79087+ __u16 pax_flags;
79088+};
79089+
79090+struct role_allowed_ip {
79091+ __u32 addr;
79092+ __u32 netmask;
79093+
79094+ struct role_allowed_ip *prev;
79095+ struct role_allowed_ip *next;
79096+};
79097+
79098+struct role_transition {
79099+ char *rolename;
79100+
79101+ struct role_transition *prev;
79102+ struct role_transition *next;
79103+};
79104+
79105+struct acl_role_label {
79106+ char *rolename;
79107+ uid_t uidgid;
79108+ __u16 roletype;
79109+
79110+ __u16 auth_attempts;
79111+ unsigned long expires;
79112+
79113+ struct acl_subject_label *root_label;
79114+ struct gr_hash_struct *hash;
79115+
79116+ struct acl_role_label *prev;
79117+ struct acl_role_label *next;
79118+
79119+ struct role_transition *transitions;
79120+ struct role_allowed_ip *allowed_ips;
79121+ uid_t *domain_children;
79122+ __u16 domain_child_num;
79123+
79124+ umode_t umask;
79125+
79126+ struct acl_subject_label **subj_hash;
79127+ __u32 subj_hash_size;
79128+};
79129+
79130+struct user_acl_role_db {
79131+ struct acl_role_label **r_table;
79132+ __u32 num_pointers; /* Number of allocations to track */
79133+ __u32 num_roles; /* Number of roles */
79134+ __u32 num_domain_children; /* Number of domain children */
79135+ __u32 num_subjects; /* Number of subjects */
79136+ __u32 num_objects; /* Number of objects */
79137+};
79138+
79139+struct acl_object_label {
79140+ char *filename;
79141+ ino_t inode;
79142+ dev_t device;
79143+ __u32 mode;
79144+
79145+ struct acl_subject_label *nested;
79146+ struct acl_object_label *globbed;
79147+
79148+ /* next two structures not used */
79149+
79150+ struct acl_object_label *prev;
79151+ struct acl_object_label *next;
79152+};
79153+
79154+struct acl_ip_label {
79155+ char *iface;
79156+ __u32 addr;
79157+ __u32 netmask;
79158+ __u16 low, high;
79159+ __u8 mode;
79160+ __u32 type;
79161+ __u32 proto[8];
79162+
79163+ /* next two structures not used */
79164+
79165+ struct acl_ip_label *prev;
79166+ struct acl_ip_label *next;
79167+};
79168+
79169+struct gr_arg {
79170+ struct user_acl_role_db role_db;
79171+ unsigned char pw[GR_PW_LEN];
79172+ unsigned char salt[GR_SALT_LEN];
79173+ unsigned char sum[GR_SHA_LEN];
79174+ unsigned char sp_role[GR_SPROLE_LEN];
79175+ struct sprole_pw *sprole_pws;
79176+ dev_t segv_device;
79177+ ino_t segv_inode;
79178+ uid_t segv_uid;
79179+ __u16 num_sprole_pws;
79180+ __u16 mode;
79181+};
79182+
79183+struct gr_arg_wrapper {
79184+ struct gr_arg *arg;
79185+ __u32 version;
79186+ __u32 size;
79187+};
79188+
79189+struct subject_map {
79190+ struct acl_subject_label *user;
79191+ struct acl_subject_label *kernel;
79192+ struct subject_map *prev;
79193+ struct subject_map *next;
79194+};
79195+
79196+struct acl_subj_map_db {
79197+ struct subject_map **s_hash;
79198+ __u32 s_size;
79199+};
79200+
79201+struct gr_policy_state {
79202+ struct sprole_pw **acl_special_roles;
79203+ __u16 num_sprole_pws;
79204+ struct acl_role_label *kernel_role;
79205+ struct acl_role_label *role_list;
79206+ struct acl_role_label *default_role;
79207+ struct acl_role_db acl_role_set;
79208+ struct acl_subj_map_db subj_map_set;
79209+ struct name_db name_set;
79210+ struct inodev_db inodev_set;
79211+};
79212+
79213+struct gr_alloc_state {
79214+ unsigned long alloc_stack_next;
79215+ unsigned long alloc_stack_size;
79216+ void **alloc_stack;
79217+};
79218+
79219+struct gr_reload_state {
79220+ struct gr_policy_state oldpolicy;
79221+ struct gr_alloc_state oldalloc;
79222+ struct gr_policy_state newpolicy;
79223+ struct gr_alloc_state newalloc;
79224+ struct gr_policy_state *oldpolicy_ptr;
79225+ struct gr_alloc_state *oldalloc_ptr;
79226+ unsigned char oldmode;
79227+};
79228+
79229+/* End Data Structures Section */
79230+
79231+/* Hash functions generated by empirical testing by Brad Spengler
79232+ Makes good use of the low bits of the inode. Generally 0-1 times
79233+ in loop for successful match. 0-3 for unsuccessful match.
79234+ Shift/add algorithm with modulus of table size and an XOR*/
79235+
79236+static __inline__ unsigned int
79237+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79238+{
79239+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
79240+}
79241+
79242+ static __inline__ unsigned int
79243+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79244+{
79245+ return ((const unsigned long)userp % sz);
79246+}
79247+
79248+static __inline__ unsigned int
79249+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79250+{
79251+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79252+}
79253+
79254+static __inline__ unsigned int
79255+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79256+{
79257+ return full_name_hash((const unsigned char *)name, len) % sz;
79258+}
79259+
79260+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79261+ subj = NULL; \
79262+ iter = 0; \
79263+ while (iter < role->subj_hash_size) { \
79264+ if (subj == NULL) \
79265+ subj = role->subj_hash[iter]; \
79266+ if (subj == NULL) { \
79267+ iter++; \
79268+ continue; \
79269+ }
79270+
79271+#define FOR_EACH_SUBJECT_END(subj,iter) \
79272+ subj = subj->next; \
79273+ if (subj == NULL) \
79274+ iter++; \
79275+ }
79276+
79277+
79278+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79279+ subj = role->hash->first; \
79280+ while (subj != NULL) {
79281+
79282+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79283+ subj = subj->next; \
79284+ }
79285+
79286+#endif
79287+
79288diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79289new file mode 100644
79290index 0000000..33ebd1f
79291--- /dev/null
79292+++ b/include/linux/gracl_compat.h
79293@@ -0,0 +1,156 @@
79294+#ifndef GR_ACL_COMPAT_H
79295+#define GR_ACL_COMPAT_H
79296+
79297+#include <linux/resource.h>
79298+#include <asm/resource.h>
79299+
79300+struct sprole_pw_compat {
79301+ compat_uptr_t rolename;
79302+ unsigned char salt[GR_SALT_LEN];
79303+ unsigned char sum[GR_SHA_LEN];
79304+};
79305+
79306+struct gr_hash_struct_compat {
79307+ compat_uptr_t table;
79308+ compat_uptr_t nametable;
79309+ compat_uptr_t first;
79310+ __u32 table_size;
79311+ __u32 used_size;
79312+ int type;
79313+};
79314+
79315+struct acl_subject_label_compat {
79316+ compat_uptr_t filename;
79317+ compat_ino_t inode;
79318+ __u32 device;
79319+ __u32 mode;
79320+ kernel_cap_t cap_mask;
79321+ kernel_cap_t cap_lower;
79322+ kernel_cap_t cap_invert_audit;
79323+
79324+ struct compat_rlimit res[GR_NLIMITS];
79325+ __u32 resmask;
79326+
79327+ __u8 user_trans_type;
79328+ __u8 group_trans_type;
79329+ compat_uptr_t user_transitions;
79330+ compat_uptr_t group_transitions;
79331+ __u16 user_trans_num;
79332+ __u16 group_trans_num;
79333+
79334+ __u32 sock_families[2];
79335+ __u32 ip_proto[8];
79336+ __u32 ip_type;
79337+ compat_uptr_t ips;
79338+ __u32 ip_num;
79339+ __u32 inaddr_any_override;
79340+
79341+ __u32 crashes;
79342+ compat_ulong_t expires;
79343+
79344+ compat_uptr_t parent_subject;
79345+ compat_uptr_t hash;
79346+ compat_uptr_t prev;
79347+ compat_uptr_t next;
79348+
79349+ compat_uptr_t obj_hash;
79350+ __u32 obj_hash_size;
79351+ __u16 pax_flags;
79352+};
79353+
79354+struct role_allowed_ip_compat {
79355+ __u32 addr;
79356+ __u32 netmask;
79357+
79358+ compat_uptr_t prev;
79359+ compat_uptr_t next;
79360+};
79361+
79362+struct role_transition_compat {
79363+ compat_uptr_t rolename;
79364+
79365+ compat_uptr_t prev;
79366+ compat_uptr_t next;
79367+};
79368+
79369+struct acl_role_label_compat {
79370+ compat_uptr_t rolename;
79371+ uid_t uidgid;
79372+ __u16 roletype;
79373+
79374+ __u16 auth_attempts;
79375+ compat_ulong_t expires;
79376+
79377+ compat_uptr_t root_label;
79378+ compat_uptr_t hash;
79379+
79380+ compat_uptr_t prev;
79381+ compat_uptr_t next;
79382+
79383+ compat_uptr_t transitions;
79384+ compat_uptr_t allowed_ips;
79385+ compat_uptr_t domain_children;
79386+ __u16 domain_child_num;
79387+
79388+ umode_t umask;
79389+
79390+ compat_uptr_t subj_hash;
79391+ __u32 subj_hash_size;
79392+};
79393+
79394+struct user_acl_role_db_compat {
79395+ compat_uptr_t r_table;
79396+ __u32 num_pointers;
79397+ __u32 num_roles;
79398+ __u32 num_domain_children;
79399+ __u32 num_subjects;
79400+ __u32 num_objects;
79401+};
79402+
79403+struct acl_object_label_compat {
79404+ compat_uptr_t filename;
79405+ compat_ino_t inode;
79406+ __u32 device;
79407+ __u32 mode;
79408+
79409+ compat_uptr_t nested;
79410+ compat_uptr_t globbed;
79411+
79412+ compat_uptr_t prev;
79413+ compat_uptr_t next;
79414+};
79415+
79416+struct acl_ip_label_compat {
79417+ compat_uptr_t iface;
79418+ __u32 addr;
79419+ __u32 netmask;
79420+ __u16 low, high;
79421+ __u8 mode;
79422+ __u32 type;
79423+ __u32 proto[8];
79424+
79425+ compat_uptr_t prev;
79426+ compat_uptr_t next;
79427+};
79428+
79429+struct gr_arg_compat {
79430+ struct user_acl_role_db_compat role_db;
79431+ unsigned char pw[GR_PW_LEN];
79432+ unsigned char salt[GR_SALT_LEN];
79433+ unsigned char sum[GR_SHA_LEN];
79434+ unsigned char sp_role[GR_SPROLE_LEN];
79435+ compat_uptr_t sprole_pws;
79436+ __u32 segv_device;
79437+ compat_ino_t segv_inode;
79438+ uid_t segv_uid;
79439+ __u16 num_sprole_pws;
79440+ __u16 mode;
79441+};
79442+
79443+struct gr_arg_wrapper_compat {
79444+ compat_uptr_t arg;
79445+ __u32 version;
79446+ __u32 size;
79447+};
79448+
79449+#endif
79450diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79451new file mode 100644
79452index 0000000..323ecf2
79453--- /dev/null
79454+++ b/include/linux/gralloc.h
79455@@ -0,0 +1,9 @@
79456+#ifndef __GRALLOC_H
79457+#define __GRALLOC_H
79458+
79459+void acl_free_all(void);
79460+int acl_alloc_stack_init(unsigned long size);
79461+void *acl_alloc(unsigned long len);
79462+void *acl_alloc_num(unsigned long num, unsigned long len);
79463+
79464+#endif
79465diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79466new file mode 100644
79467index 0000000..be66033
79468--- /dev/null
79469+++ b/include/linux/grdefs.h
79470@@ -0,0 +1,140 @@
79471+#ifndef GRDEFS_H
79472+#define GRDEFS_H
79473+
79474+/* Begin grsecurity status declarations */
79475+
79476+enum {
79477+ GR_READY = 0x01,
79478+ GR_STATUS_INIT = 0x00 // disabled state
79479+};
79480+
79481+/* Begin ACL declarations */
79482+
79483+/* Role flags */
79484+
79485+enum {
79486+ GR_ROLE_USER = 0x0001,
79487+ GR_ROLE_GROUP = 0x0002,
79488+ GR_ROLE_DEFAULT = 0x0004,
79489+ GR_ROLE_SPECIAL = 0x0008,
79490+ GR_ROLE_AUTH = 0x0010,
79491+ GR_ROLE_NOPW = 0x0020,
79492+ GR_ROLE_GOD = 0x0040,
79493+ GR_ROLE_LEARN = 0x0080,
79494+ GR_ROLE_TPE = 0x0100,
79495+ GR_ROLE_DOMAIN = 0x0200,
79496+ GR_ROLE_PAM = 0x0400,
79497+ GR_ROLE_PERSIST = 0x0800
79498+};
79499+
79500+/* ACL Subject and Object mode flags */
79501+enum {
79502+ GR_DELETED = 0x80000000
79503+};
79504+
79505+/* ACL Object-only mode flags */
79506+enum {
79507+ GR_READ = 0x00000001,
79508+ GR_APPEND = 0x00000002,
79509+ GR_WRITE = 0x00000004,
79510+ GR_EXEC = 0x00000008,
79511+ GR_FIND = 0x00000010,
79512+ GR_INHERIT = 0x00000020,
79513+ GR_SETID = 0x00000040,
79514+ GR_CREATE = 0x00000080,
79515+ GR_DELETE = 0x00000100,
79516+ GR_LINK = 0x00000200,
79517+ GR_AUDIT_READ = 0x00000400,
79518+ GR_AUDIT_APPEND = 0x00000800,
79519+ GR_AUDIT_WRITE = 0x00001000,
79520+ GR_AUDIT_EXEC = 0x00002000,
79521+ GR_AUDIT_FIND = 0x00004000,
79522+ GR_AUDIT_INHERIT= 0x00008000,
79523+ GR_AUDIT_SETID = 0x00010000,
79524+ GR_AUDIT_CREATE = 0x00020000,
79525+ GR_AUDIT_DELETE = 0x00040000,
79526+ GR_AUDIT_LINK = 0x00080000,
79527+ GR_PTRACERD = 0x00100000,
79528+ GR_NOPTRACE = 0x00200000,
79529+ GR_SUPPRESS = 0x00400000,
79530+ GR_NOLEARN = 0x00800000,
79531+ GR_INIT_TRANSFER= 0x01000000
79532+};
79533+
79534+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79535+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79536+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79537+
79538+/* ACL subject-only mode flags */
79539+enum {
79540+ GR_KILL = 0x00000001,
79541+ GR_VIEW = 0x00000002,
79542+ GR_PROTECTED = 0x00000004,
79543+ GR_LEARN = 0x00000008,
79544+ GR_OVERRIDE = 0x00000010,
79545+ /* just a placeholder, this mode is only used in userspace */
79546+ GR_DUMMY = 0x00000020,
79547+ GR_PROTSHM = 0x00000040,
79548+ GR_KILLPROC = 0x00000080,
79549+ GR_KILLIPPROC = 0x00000100,
79550+ /* just a placeholder, this mode is only used in userspace */
79551+ GR_NOTROJAN = 0x00000200,
79552+ GR_PROTPROCFD = 0x00000400,
79553+ GR_PROCACCT = 0x00000800,
79554+ GR_RELAXPTRACE = 0x00001000,
79555+ //GR_NESTED = 0x00002000,
79556+ GR_INHERITLEARN = 0x00004000,
79557+ GR_PROCFIND = 0x00008000,
79558+ GR_POVERRIDE = 0x00010000,
79559+ GR_KERNELAUTH = 0x00020000,
79560+ GR_ATSECURE = 0x00040000,
79561+ GR_SHMEXEC = 0x00080000
79562+};
79563+
79564+enum {
79565+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79566+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79567+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79568+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79569+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79570+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79571+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79572+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79573+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79574+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79575+};
79576+
79577+enum {
79578+ GR_ID_USER = 0x01,
79579+ GR_ID_GROUP = 0x02,
79580+};
79581+
79582+enum {
79583+ GR_ID_ALLOW = 0x01,
79584+ GR_ID_DENY = 0x02,
79585+};
79586+
79587+#define GR_CRASH_RES 31
79588+#define GR_UIDTABLE_MAX 500
79589+
79590+/* begin resource learning section */
79591+enum {
79592+ GR_RLIM_CPU_BUMP = 60,
79593+ GR_RLIM_FSIZE_BUMP = 50000,
79594+ GR_RLIM_DATA_BUMP = 10000,
79595+ GR_RLIM_STACK_BUMP = 1000,
79596+ GR_RLIM_CORE_BUMP = 10000,
79597+ GR_RLIM_RSS_BUMP = 500000,
79598+ GR_RLIM_NPROC_BUMP = 1,
79599+ GR_RLIM_NOFILE_BUMP = 5,
79600+ GR_RLIM_MEMLOCK_BUMP = 50000,
79601+ GR_RLIM_AS_BUMP = 500000,
79602+ GR_RLIM_LOCKS_BUMP = 2,
79603+ GR_RLIM_SIGPENDING_BUMP = 5,
79604+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79605+ GR_RLIM_NICE_BUMP = 1,
79606+ GR_RLIM_RTPRIO_BUMP = 1,
79607+ GR_RLIM_RTTIME_BUMP = 1000000
79608+};
79609+
79610+#endif
79611diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79612new file mode 100644
79613index 0000000..d25522e
79614--- /dev/null
79615+++ b/include/linux/grinternal.h
79616@@ -0,0 +1,229 @@
79617+#ifndef __GRINTERNAL_H
79618+#define __GRINTERNAL_H
79619+
79620+#ifdef CONFIG_GRKERNSEC
79621+
79622+#include <linux/fs.h>
79623+#include <linux/mnt_namespace.h>
79624+#include <linux/nsproxy.h>
79625+#include <linux/gracl.h>
79626+#include <linux/grdefs.h>
79627+#include <linux/grmsg.h>
79628+
79629+void gr_add_learn_entry(const char *fmt, ...)
79630+ __attribute__ ((format (printf, 1, 2)));
79631+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79632+ const struct vfsmount *mnt);
79633+__u32 gr_check_create(const struct dentry *new_dentry,
79634+ const struct dentry *parent,
79635+ const struct vfsmount *mnt, const __u32 mode);
79636+int gr_check_protected_task(const struct task_struct *task);
79637+__u32 to_gr_audit(const __u32 reqmode);
79638+int gr_set_acls(const int type);
79639+int gr_acl_is_enabled(void);
79640+char gr_roletype_to_char(void);
79641+
79642+void gr_handle_alertkill(struct task_struct *task);
79643+char *gr_to_filename(const struct dentry *dentry,
79644+ const struct vfsmount *mnt);
79645+char *gr_to_filename1(const struct dentry *dentry,
79646+ const struct vfsmount *mnt);
79647+char *gr_to_filename2(const struct dentry *dentry,
79648+ const struct vfsmount *mnt);
79649+char *gr_to_filename3(const struct dentry *dentry,
79650+ const struct vfsmount *mnt);
79651+
79652+extern int grsec_enable_ptrace_readexec;
79653+extern int grsec_enable_harden_ptrace;
79654+extern int grsec_enable_link;
79655+extern int grsec_enable_fifo;
79656+extern int grsec_enable_execve;
79657+extern int grsec_enable_shm;
79658+extern int grsec_enable_execlog;
79659+extern int grsec_enable_signal;
79660+extern int grsec_enable_audit_ptrace;
79661+extern int grsec_enable_forkfail;
79662+extern int grsec_enable_time;
79663+extern int grsec_enable_rofs;
79664+extern int grsec_deny_new_usb;
79665+extern int grsec_enable_chroot_shmat;
79666+extern int grsec_enable_chroot_mount;
79667+extern int grsec_enable_chroot_double;
79668+extern int grsec_enable_chroot_pivot;
79669+extern int grsec_enable_chroot_chdir;
79670+extern int grsec_enable_chroot_chmod;
79671+extern int grsec_enable_chroot_mknod;
79672+extern int grsec_enable_chroot_fchdir;
79673+extern int grsec_enable_chroot_nice;
79674+extern int grsec_enable_chroot_execlog;
79675+extern int grsec_enable_chroot_caps;
79676+extern int grsec_enable_chroot_sysctl;
79677+extern int grsec_enable_chroot_unix;
79678+extern int grsec_enable_symlinkown;
79679+extern kgid_t grsec_symlinkown_gid;
79680+extern int grsec_enable_tpe;
79681+extern kgid_t grsec_tpe_gid;
79682+extern int grsec_enable_tpe_all;
79683+extern int grsec_enable_tpe_invert;
79684+extern int grsec_enable_socket_all;
79685+extern kgid_t grsec_socket_all_gid;
79686+extern int grsec_enable_socket_client;
79687+extern kgid_t grsec_socket_client_gid;
79688+extern int grsec_enable_socket_server;
79689+extern kgid_t grsec_socket_server_gid;
79690+extern kgid_t grsec_audit_gid;
79691+extern int grsec_enable_group;
79692+extern int grsec_enable_log_rwxmaps;
79693+extern int grsec_enable_mount;
79694+extern int grsec_enable_chdir;
79695+extern int grsec_resource_logging;
79696+extern int grsec_enable_blackhole;
79697+extern int grsec_lastack_retries;
79698+extern int grsec_enable_brute;
79699+extern int grsec_enable_harden_ipc;
79700+extern int grsec_lock;
79701+
79702+extern spinlock_t grsec_alert_lock;
79703+extern unsigned long grsec_alert_wtime;
79704+extern unsigned long grsec_alert_fyet;
79705+
79706+extern spinlock_t grsec_audit_lock;
79707+
79708+extern rwlock_t grsec_exec_file_lock;
79709+
79710+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79711+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79712+ (tsk)->exec_file->f_path.mnt) : "/")
79713+
79714+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79715+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79716+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79717+
79718+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79719+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79720+ (tsk)->exec_file->f_path.mnt) : "/")
79721+
79722+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79723+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79724+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79725+
79726+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79727+
79728+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79729+
79730+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79731+{
79732+ if (file1 && file2) {
79733+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79734+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79735+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79736+ return true;
79737+ }
79738+
79739+ return false;
79740+}
79741+
79742+#define GR_CHROOT_CAPS {{ \
79743+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79744+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79745+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79746+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79747+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79748+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79749+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79750+
79751+#define security_learn(normal_msg,args...) \
79752+({ \
79753+ read_lock(&grsec_exec_file_lock); \
79754+ gr_add_learn_entry(normal_msg "\n", ## args); \
79755+ read_unlock(&grsec_exec_file_lock); \
79756+})
79757+
79758+enum {
79759+ GR_DO_AUDIT,
79760+ GR_DONT_AUDIT,
79761+ /* used for non-audit messages that we shouldn't kill the task on */
79762+ GR_DONT_AUDIT_GOOD
79763+};
79764+
79765+enum {
79766+ GR_TTYSNIFF,
79767+ GR_RBAC,
79768+ GR_RBAC_STR,
79769+ GR_STR_RBAC,
79770+ GR_RBAC_MODE2,
79771+ GR_RBAC_MODE3,
79772+ GR_FILENAME,
79773+ GR_SYSCTL_HIDDEN,
79774+ GR_NOARGS,
79775+ GR_ONE_INT,
79776+ GR_ONE_INT_TWO_STR,
79777+ GR_ONE_STR,
79778+ GR_STR_INT,
79779+ GR_TWO_STR_INT,
79780+ GR_TWO_INT,
79781+ GR_TWO_U64,
79782+ GR_THREE_INT,
79783+ GR_FIVE_INT_TWO_STR,
79784+ GR_TWO_STR,
79785+ GR_THREE_STR,
79786+ GR_FOUR_STR,
79787+ GR_STR_FILENAME,
79788+ GR_FILENAME_STR,
79789+ GR_FILENAME_TWO_INT,
79790+ GR_FILENAME_TWO_INT_STR,
79791+ GR_TEXTREL,
79792+ GR_PTRACE,
79793+ GR_RESOURCE,
79794+ GR_CAP,
79795+ GR_SIG,
79796+ GR_SIG2,
79797+ GR_CRASH1,
79798+ GR_CRASH2,
79799+ GR_PSACCT,
79800+ GR_RWXMAP,
79801+ GR_RWXMAPVMA
79802+};
79803+
79804+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79805+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79806+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79807+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79808+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79809+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79810+#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)
79811+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79812+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79813+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79814+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79815+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79816+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79817+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79818+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79819+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79820+#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)
79821+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79822+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79823+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79824+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79825+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79826+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79827+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79828+#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)
79829+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79830+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79831+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79832+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79833+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79834+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79835+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79836+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79837+#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)
79838+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79839+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79840+
79841+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79842+
79843+#endif
79844+
79845+#endif
79846diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79847new file mode 100644
79848index 0000000..b02ba9d
79849--- /dev/null
79850+++ b/include/linux/grmsg.h
79851@@ -0,0 +1,117 @@
79852+#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"
79853+#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"
79854+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79855+#define GR_STOPMOD_MSG "denied modification of module state by "
79856+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79857+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79858+#define GR_IOPERM_MSG "denied use of ioperm() by "
79859+#define GR_IOPL_MSG "denied use of iopl() by "
79860+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79861+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79862+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79863+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79864+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79865+#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"
79866+#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"
79867+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79868+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79869+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79870+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79871+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79872+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79873+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79874+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79875+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79876+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79877+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79878+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79879+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79880+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79881+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79882+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79883+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79884+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79885+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79886+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79887+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79888+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79889+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79890+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79891+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79892+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79893+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79894+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79895+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79896+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79897+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79898+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
79899+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79900+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79901+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79902+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79903+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79904+#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"
79905+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79906+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79907+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79908+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79909+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79910+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79911+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79912+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79913+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79914+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79915+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79916+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79917+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79918+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79919+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79920+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79921+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79922+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79923+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79924+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79925+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79926+#define GR_NICE_CHROOT_MSG "denied priority change by "
79927+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79928+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79929+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79930+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79931+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79932+#define GR_TIME_MSG "time set by "
79933+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79934+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79935+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79936+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79937+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79938+#define GR_BIND_MSG "denied bind() by "
79939+#define GR_CONNECT_MSG "denied connect() by "
79940+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79941+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79942+#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"
79943+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79944+#define GR_CAP_ACL_MSG "use of %s denied for "
79945+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79946+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79947+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79948+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79949+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79950+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79951+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79952+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79953+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79954+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79955+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79956+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79957+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79958+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79959+#define GR_VM86_MSG "denied use of vm86 by "
79960+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79961+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79962+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79963+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79964+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79965+#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 "
79966+#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 "
79967+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79968+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79969diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79970new file mode 100644
79971index 0000000..e6d120f
79972--- /dev/null
79973+++ b/include/linux/grsecurity.h
79974@@ -0,0 +1,252 @@
79975+#ifndef GR_SECURITY_H
79976+#define GR_SECURITY_H
79977+#include <linux/fs.h>
79978+#include <linux/fs_struct.h>
79979+#include <linux/binfmts.h>
79980+#include <linux/gracl.h>
79981+
79982+/* notify of brain-dead configs */
79983+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79984+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79985+#endif
79986+#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79987+#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
79988+#endif
79989+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79990+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79991+#endif
79992+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79993+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79994+#endif
79995+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79996+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79997+#endif
79998+
79999+int gr_handle_new_usb(void);
80000+
80001+void gr_handle_brute_attach(int dumpable);
80002+void gr_handle_brute_check(void);
80003+void gr_handle_kernel_exploit(void);
80004+
80005+char gr_roletype_to_char(void);
80006+
80007+int gr_proc_is_restricted(void);
80008+
80009+int gr_acl_enable_at_secure(void);
80010+
80011+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
80012+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
80013+
80014+void gr_del_task_from_ip_table(struct task_struct *p);
80015+
80016+int gr_pid_is_chrooted(struct task_struct *p);
80017+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
80018+int gr_handle_chroot_nice(void);
80019+int gr_handle_chroot_sysctl(const int op);
80020+int gr_handle_chroot_setpriority(struct task_struct *p,
80021+ const int niceval);
80022+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
80023+int gr_chroot_fhandle(void);
80024+int gr_handle_chroot_chroot(const struct dentry *dentry,
80025+ const struct vfsmount *mnt);
80026+void gr_handle_chroot_chdir(const struct path *path);
80027+int gr_handle_chroot_chmod(const struct dentry *dentry,
80028+ const struct vfsmount *mnt, const int mode);
80029+int gr_handle_chroot_mknod(const struct dentry *dentry,
80030+ const struct vfsmount *mnt, const int mode);
80031+int gr_handle_chroot_mount(const struct dentry *dentry,
80032+ const struct vfsmount *mnt,
80033+ const char *dev_name);
80034+int gr_handle_chroot_pivot(void);
80035+int gr_handle_chroot_unix(const pid_t pid);
80036+
80037+int gr_handle_rawio(const struct inode *inode);
80038+
80039+void gr_handle_ioperm(void);
80040+void gr_handle_iopl(void);
80041+void gr_handle_msr_write(void);
80042+
80043+umode_t gr_acl_umask(void);
80044+
80045+int gr_tpe_allow(const struct file *file);
80046+
80047+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
80048+void gr_clear_chroot_entries(struct task_struct *task);
80049+
80050+void gr_log_forkfail(const int retval);
80051+void gr_log_timechange(void);
80052+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
80053+void gr_log_chdir(const struct dentry *dentry,
80054+ const struct vfsmount *mnt);
80055+void gr_log_chroot_exec(const struct dentry *dentry,
80056+ const struct vfsmount *mnt);
80057+void gr_log_remount(const char *devname, const int retval);
80058+void gr_log_unmount(const char *devname, const int retval);
80059+void gr_log_mount(const char *from, const char *to, const int retval);
80060+void gr_log_textrel(struct vm_area_struct *vma);
80061+void gr_log_ptgnustack(struct file *file);
80062+void gr_log_rwxmmap(struct file *file);
80063+void gr_log_rwxmprotect(struct vm_area_struct *vma);
80064+
80065+int gr_handle_follow_link(const struct inode *parent,
80066+ const struct inode *inode,
80067+ const struct dentry *dentry,
80068+ const struct vfsmount *mnt);
80069+int gr_handle_fifo(const struct dentry *dentry,
80070+ const struct vfsmount *mnt,
80071+ const struct dentry *dir, const int flag,
80072+ const int acc_mode);
80073+int gr_handle_hardlink(const struct dentry *dentry,
80074+ const struct vfsmount *mnt,
80075+ struct inode *inode,
80076+ const int mode, const struct filename *to);
80077+
80078+int gr_is_capable(const int cap);
80079+int gr_is_capable_nolog(const int cap);
80080+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
80081+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
80082+
80083+void gr_copy_label(struct task_struct *tsk);
80084+void gr_handle_crash(struct task_struct *task, const int sig);
80085+int gr_handle_signal(const struct task_struct *p, const int sig);
80086+int gr_check_crash_uid(const kuid_t uid);
80087+int gr_check_protected_task(const struct task_struct *task);
80088+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
80089+int gr_acl_handle_mmap(const struct file *file,
80090+ const unsigned long prot);
80091+int gr_acl_handle_mprotect(const struct file *file,
80092+ const unsigned long prot);
80093+int gr_check_hidden_task(const struct task_struct *tsk);
80094+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
80095+ const struct vfsmount *mnt);
80096+__u32 gr_acl_handle_utime(const struct dentry *dentry,
80097+ const struct vfsmount *mnt);
80098+__u32 gr_acl_handle_access(const struct dentry *dentry,
80099+ const struct vfsmount *mnt, const int fmode);
80100+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
80101+ const struct vfsmount *mnt, umode_t *mode);
80102+__u32 gr_acl_handle_chown(const struct dentry *dentry,
80103+ const struct vfsmount *mnt);
80104+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
80105+ const struct vfsmount *mnt);
80106+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
80107+ const struct vfsmount *mnt);
80108+int gr_handle_ptrace(struct task_struct *task, const long request);
80109+int gr_handle_proc_ptrace(struct task_struct *task);
80110+__u32 gr_acl_handle_execve(const struct dentry *dentry,
80111+ const struct vfsmount *mnt);
80112+int gr_check_crash_exec(const struct file *filp);
80113+int gr_acl_is_enabled(void);
80114+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
80115+ const kgid_t gid);
80116+int gr_set_proc_label(const struct dentry *dentry,
80117+ const struct vfsmount *mnt,
80118+ const int unsafe_flags);
80119+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
80120+ const struct vfsmount *mnt);
80121+__u32 gr_acl_handle_open(const struct dentry *dentry,
80122+ const struct vfsmount *mnt, int acc_mode);
80123+__u32 gr_acl_handle_creat(const struct dentry *dentry,
80124+ const struct dentry *p_dentry,
80125+ const struct vfsmount *p_mnt,
80126+ int open_flags, int acc_mode, const int imode);
80127+void gr_handle_create(const struct dentry *dentry,
80128+ const struct vfsmount *mnt);
80129+void gr_handle_proc_create(const struct dentry *dentry,
80130+ const struct inode *inode);
80131+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
80132+ const struct dentry *parent_dentry,
80133+ const struct vfsmount *parent_mnt,
80134+ const int mode);
80135+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
80136+ const struct dentry *parent_dentry,
80137+ const struct vfsmount *parent_mnt);
80138+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
80139+ const struct vfsmount *mnt);
80140+void gr_handle_delete(const ino_t ino, const dev_t dev);
80141+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
80142+ const struct vfsmount *mnt);
80143+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
80144+ const struct dentry *parent_dentry,
80145+ const struct vfsmount *parent_mnt,
80146+ const struct filename *from);
80147+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
80148+ const struct dentry *parent_dentry,
80149+ const struct vfsmount *parent_mnt,
80150+ const struct dentry *old_dentry,
80151+ const struct vfsmount *old_mnt, const struct filename *to);
80152+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
80153+int gr_acl_handle_rename(struct dentry *new_dentry,
80154+ struct dentry *parent_dentry,
80155+ const struct vfsmount *parent_mnt,
80156+ struct dentry *old_dentry,
80157+ struct inode *old_parent_inode,
80158+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
80159+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
80160+ struct dentry *old_dentry,
80161+ struct dentry *new_dentry,
80162+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
80163+__u32 gr_check_link(const struct dentry *new_dentry,
80164+ const struct dentry *parent_dentry,
80165+ const struct vfsmount *parent_mnt,
80166+ const struct dentry *old_dentry,
80167+ const struct vfsmount *old_mnt);
80168+int gr_acl_handle_filldir(const struct file *file, const char *name,
80169+ const unsigned int namelen, const ino_t ino);
80170+
80171+__u32 gr_acl_handle_unix(const struct dentry *dentry,
80172+ const struct vfsmount *mnt);
80173+void gr_acl_handle_exit(void);
80174+void gr_acl_handle_psacct(struct task_struct *task, const long code);
80175+int gr_acl_handle_procpidmem(const struct task_struct *task);
80176+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
80177+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
80178+void gr_audit_ptrace(struct task_struct *task);
80179+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
80180+void gr_put_exec_file(struct task_struct *task);
80181+
80182+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
80183+
80184+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
80185+extern void gr_learn_resource(const struct task_struct *task, const int res,
80186+ const unsigned long wanted, const int gt);
80187+#else
80188+static inline void gr_learn_resource(const struct task_struct *task, const int res,
80189+ const unsigned long wanted, const int gt)
80190+{
80191+}
80192+#endif
80193+
80194+#ifdef CONFIG_GRKERNSEC_RESLOG
80195+extern void gr_log_resource(const struct task_struct *task, const int res,
80196+ const unsigned long wanted, const int gt);
80197+#else
80198+static inline void gr_log_resource(const struct task_struct *task, const int res,
80199+ const unsigned long wanted, const int gt)
80200+{
80201+}
80202+#endif
80203+
80204+#ifdef CONFIG_GRKERNSEC
80205+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
80206+void gr_handle_vm86(void);
80207+void gr_handle_mem_readwrite(u64 from, u64 to);
80208+
80209+void gr_log_badprocpid(const char *entry);
80210+
80211+extern int grsec_enable_dmesg;
80212+extern int grsec_disable_privio;
80213+
80214+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80215+extern kgid_t grsec_proc_gid;
80216+#endif
80217+
80218+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80219+extern int grsec_enable_chroot_findtask;
80220+#endif
80221+#ifdef CONFIG_GRKERNSEC_SETXID
80222+extern int grsec_enable_setxid;
80223+#endif
80224+#endif
80225+
80226+#endif
80227diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80228new file mode 100644
80229index 0000000..e7ffaaf
80230--- /dev/null
80231+++ b/include/linux/grsock.h
80232@@ -0,0 +1,19 @@
80233+#ifndef __GRSOCK_H
80234+#define __GRSOCK_H
80235+
80236+extern void gr_attach_curr_ip(const struct sock *sk);
80237+extern int gr_handle_sock_all(const int family, const int type,
80238+ const int protocol);
80239+extern int gr_handle_sock_server(const struct sockaddr *sck);
80240+extern int gr_handle_sock_server_other(const struct sock *sck);
80241+extern int gr_handle_sock_client(const struct sockaddr *sck);
80242+extern int gr_search_connect(struct socket * sock,
80243+ struct sockaddr_in * addr);
80244+extern int gr_search_bind(struct socket * sock,
80245+ struct sockaddr_in * addr);
80246+extern int gr_search_listen(struct socket * sock);
80247+extern int gr_search_accept(struct socket * sock);
80248+extern int gr_search_socket(const int domain, const int type,
80249+ const int protocol);
80250+
80251+#endif
80252diff --git a/include/linux/hash.h b/include/linux/hash.h
80253index bd1754c..8240892 100644
80254--- a/include/linux/hash.h
80255+++ b/include/linux/hash.h
80256@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80257 struct fast_hash_ops {
80258 u32 (*hash)(const void *data, u32 len, u32 seed);
80259 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80260-};
80261+} __no_const;
80262
80263 /**
80264 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80265diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80266index 7fb31da..08b5114 100644
80267--- a/include/linux/highmem.h
80268+++ b/include/linux/highmem.h
80269@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80270 kunmap_atomic(kaddr);
80271 }
80272
80273+static inline void sanitize_highpage(struct page *page)
80274+{
80275+ void *kaddr;
80276+ unsigned long flags;
80277+
80278+ local_irq_save(flags);
80279+ kaddr = kmap_atomic(page);
80280+ clear_page(kaddr);
80281+ kunmap_atomic(kaddr);
80282+ local_irq_restore(flags);
80283+}
80284+
80285 static inline void zero_user_segments(struct page *page,
80286 unsigned start1, unsigned end1,
80287 unsigned start2, unsigned end2)
80288diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80289index 1c7b89a..7dda400 100644
80290--- a/include/linux/hwmon-sysfs.h
80291+++ b/include/linux/hwmon-sysfs.h
80292@@ -25,7 +25,8 @@
80293 struct sensor_device_attribute{
80294 struct device_attribute dev_attr;
80295 int index;
80296-};
80297+} __do_const;
80298+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80299 #define to_sensor_dev_attr(_dev_attr) \
80300 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80301
80302@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80303 struct device_attribute dev_attr;
80304 u8 index;
80305 u8 nr;
80306-};
80307+} __do_const;
80308+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80309 #define to_sensor_dev_attr_2(_dev_attr) \
80310 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80311
80312diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80313index b556e0a..c10a515 100644
80314--- a/include/linux/i2c.h
80315+++ b/include/linux/i2c.h
80316@@ -378,6 +378,7 @@ struct i2c_algorithm {
80317 /* To determine what the adapter supports */
80318 u32 (*functionality) (struct i2c_adapter *);
80319 };
80320+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80321
80322 /**
80323 * struct i2c_bus_recovery_info - I2C bus recovery information
80324diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80325index d23c3c2..eb63c81 100644
80326--- a/include/linux/i2o.h
80327+++ b/include/linux/i2o.h
80328@@ -565,7 +565,7 @@ struct i2o_controller {
80329 struct i2o_device *exec; /* Executive */
80330 #if BITS_PER_LONG == 64
80331 spinlock_t context_list_lock; /* lock for context_list */
80332- atomic_t context_list_counter; /* needed for unique contexts */
80333+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80334 struct list_head context_list; /* list of context id's
80335 and pointers */
80336 #endif
80337diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80338index aff7ad8..3942bbd 100644
80339--- a/include/linux/if_pppox.h
80340+++ b/include/linux/if_pppox.h
80341@@ -76,7 +76,7 @@ struct pppox_proto {
80342 int (*ioctl)(struct socket *sock, unsigned int cmd,
80343 unsigned long arg);
80344 struct module *owner;
80345-};
80346+} __do_const;
80347
80348 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80349 extern void unregister_pppox_proto(int proto_num);
80350diff --git a/include/linux/init.h b/include/linux/init.h
80351index a3ba270..a1b6604 100644
80352--- a/include/linux/init.h
80353+++ b/include/linux/init.h
80354@@ -37,9 +37,17 @@
80355 * section.
80356 */
80357
80358+#define add_init_latent_entropy __latent_entropy
80359+
80360+#ifdef CONFIG_MEMORY_HOTPLUG
80361+#define add_meminit_latent_entropy
80362+#else
80363+#define add_meminit_latent_entropy __latent_entropy
80364+#endif
80365+
80366 /* These are for everybody (although not all archs will actually
80367 discard it in modules) */
80368-#define __init __section(.init.text) __cold notrace
80369+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80370 #define __initdata __section(.init.data)
80371 #define __initconst __constsection(.init.rodata)
80372 #define __exitdata __section(.exit.data)
80373@@ -100,7 +108,7 @@
80374 #define __cpuexitconst
80375
80376 /* Used for MEMORY_HOTPLUG */
80377-#define __meminit __section(.meminit.text) __cold notrace
80378+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80379 #define __meminitdata __section(.meminit.data)
80380 #define __meminitconst __constsection(.meminit.rodata)
80381 #define __memexit __section(.memexit.text) __exitused __cold notrace
80382diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80383index 6df7f9f..d0bf699 100644
80384--- a/include/linux/init_task.h
80385+++ b/include/linux/init_task.h
80386@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80387
80388 #define INIT_TASK_COMM "swapper"
80389
80390+#ifdef CONFIG_X86
80391+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80392+#else
80393+#define INIT_TASK_THREAD_INFO
80394+#endif
80395+
80396 #ifdef CONFIG_RT_MUTEXES
80397 # define INIT_RT_MUTEXES(tsk) \
80398 .pi_waiters = RB_ROOT, \
80399@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80400 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80401 .comm = INIT_TASK_COMM, \
80402 .thread = INIT_THREAD, \
80403+ INIT_TASK_THREAD_INFO \
80404 .fs = &init_fs, \
80405 .files = &init_files, \
80406 .signal = &init_signals, \
80407diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80408index 051c850..431f83a 100644
80409--- a/include/linux/interrupt.h
80410+++ b/include/linux/interrupt.h
80411@@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80412
80413 struct softirq_action
80414 {
80415- void (*action)(struct softirq_action *);
80416-};
80417+ void (*action)(void);
80418+} __no_const;
80419
80420 asmlinkage void do_softirq(void);
80421 asmlinkage void __do_softirq(void);
80422@@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
80423 }
80424 #endif
80425
80426-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80427+extern void open_softirq(int nr, void (*action)(void));
80428 extern void softirq_init(void);
80429 extern void __raise_softirq_irqoff(unsigned int nr);
80430
80431diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80432index b96a5b2..2732d1c 100644
80433--- a/include/linux/iommu.h
80434+++ b/include/linux/iommu.h
80435@@ -131,7 +131,7 @@ struct iommu_ops {
80436 u32 (*domain_get_windows)(struct iommu_domain *domain);
80437
80438 unsigned long pgsize_bitmap;
80439-};
80440+} __do_const;
80441
80442 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80443 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80444diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80445index 5e3a906..3131d0f 100644
80446--- a/include/linux/ioport.h
80447+++ b/include/linux/ioport.h
80448@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80449 int adjust_resource(struct resource *res, resource_size_t start,
80450 resource_size_t size);
80451 resource_size_t resource_alignment(struct resource *res);
80452-static inline resource_size_t resource_size(const struct resource *res)
80453+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80454 {
80455 return res->end - res->start + 1;
80456 }
80457diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80458index 35e7eca..6afb7ad 100644
80459--- a/include/linux/ipc_namespace.h
80460+++ b/include/linux/ipc_namespace.h
80461@@ -69,7 +69,7 @@ struct ipc_namespace {
80462 struct user_namespace *user_ns;
80463
80464 unsigned int proc_inum;
80465-};
80466+} __randomize_layout;
80467
80468 extern struct ipc_namespace init_ipc_ns;
80469 extern atomic_t nr_ipc_ns;
80470diff --git a/include/linux/irq.h b/include/linux/irq.h
80471index 5c57efb..965a62b 100644
80472--- a/include/linux/irq.h
80473+++ b/include/linux/irq.h
80474@@ -344,7 +344,8 @@ struct irq_chip {
80475 void (*irq_release_resources)(struct irq_data *data);
80476
80477 unsigned long flags;
80478-};
80479+} __do_const;
80480+typedef struct irq_chip __no_const irq_chip_no_const;
80481
80482 /*
80483 * irq_chip specific flags
80484diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80485index 7ed92d0..589abf5 100644
80486--- a/include/linux/irqchip/arm-gic.h
80487+++ b/include/linux/irqchip/arm-gic.h
80488@@ -73,9 +73,11 @@
80489
80490 #ifndef __ASSEMBLY__
80491
80492+#include <linux/irq.h>
80493+
80494 struct device_node;
80495
80496-extern struct irq_chip gic_arch_extn;
80497+extern irq_chip_no_const gic_arch_extn;
80498
80499 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80500 u32 offset, struct device_node *);
80501diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80502index 1f44466..b481806 100644
80503--- a/include/linux/jiffies.h
80504+++ b/include/linux/jiffies.h
80505@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80506 /*
80507 * Convert various time units to each other:
80508 */
80509-extern unsigned int jiffies_to_msecs(const unsigned long j);
80510-extern unsigned int jiffies_to_usecs(const unsigned long j);
80511+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80512+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80513
80514-static inline u64 jiffies_to_nsecs(const unsigned long j)
80515+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80516 {
80517 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80518 }
80519
80520-extern unsigned long msecs_to_jiffies(const unsigned int m);
80521-extern unsigned long usecs_to_jiffies(const unsigned int u);
80522+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80523+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80524 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80525 extern void jiffies_to_timespec(const unsigned long jiffies,
80526- struct timespec *value);
80527-extern unsigned long timeval_to_jiffies(const struct timeval *value);
80528+ struct timespec *value) __intentional_overflow(-1);
80529+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80530 extern void jiffies_to_timeval(const unsigned long jiffies,
80531 struct timeval *value);
80532
80533diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80534index 6883e19..e854fcb 100644
80535--- a/include/linux/kallsyms.h
80536+++ b/include/linux/kallsyms.h
80537@@ -15,7 +15,8 @@
80538
80539 struct module;
80540
80541-#ifdef CONFIG_KALLSYMS
80542+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80543+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80544 /* Lookup the address for a symbol. Returns 0 if not found. */
80545 unsigned long kallsyms_lookup_name(const char *name);
80546
80547@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80548 /* Stupid that this does nothing, but I didn't create this mess. */
80549 #define __print_symbol(fmt, addr)
80550 #endif /*CONFIG_KALLSYMS*/
80551+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80552+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80553+extern unsigned long kallsyms_lookup_name(const char *name);
80554+extern void __print_symbol(const char *fmt, unsigned long address);
80555+extern int sprint_backtrace(char *buffer, unsigned long address);
80556+extern int sprint_symbol(char *buffer, unsigned long address);
80557+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80558+const char *kallsyms_lookup(unsigned long addr,
80559+ unsigned long *symbolsize,
80560+ unsigned long *offset,
80561+ char **modname, char *namebuf);
80562+extern int kallsyms_lookup_size_offset(unsigned long addr,
80563+ unsigned long *symbolsize,
80564+ unsigned long *offset);
80565+#endif
80566
80567 /* This macro allows us to keep printk typechecking */
80568 static __printf(1, 2)
80569diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80570index a74c3a8..28d3f21 100644
80571--- a/include/linux/key-type.h
80572+++ b/include/linux/key-type.h
80573@@ -131,7 +131,7 @@ struct key_type {
80574 /* internal fields */
80575 struct list_head link; /* link in types list */
80576 struct lock_class_key lock_class; /* key->sem lock class */
80577-};
80578+} __do_const;
80579
80580 extern struct key_type key_type_keyring;
80581
80582diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80583index 6b06d37..c134867 100644
80584--- a/include/linux/kgdb.h
80585+++ b/include/linux/kgdb.h
80586@@ -52,7 +52,7 @@ extern int kgdb_connected;
80587 extern int kgdb_io_module_registered;
80588
80589 extern atomic_t kgdb_setting_breakpoint;
80590-extern atomic_t kgdb_cpu_doing_single_step;
80591+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80592
80593 extern struct task_struct *kgdb_usethread;
80594 extern struct task_struct *kgdb_contthread;
80595@@ -254,7 +254,7 @@ struct kgdb_arch {
80596 void (*correct_hw_break)(void);
80597
80598 void (*enable_nmi)(bool on);
80599-};
80600+} __do_const;
80601
80602 /**
80603 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80604@@ -279,7 +279,7 @@ struct kgdb_io {
80605 void (*pre_exception) (void);
80606 void (*post_exception) (void);
80607 int is_console;
80608-};
80609+} __do_const;
80610
80611 extern struct kgdb_arch arch_kgdb_ops;
80612
80613diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80614index 0555cc6..40116ce 100644
80615--- a/include/linux/kmod.h
80616+++ b/include/linux/kmod.h
80617@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80618 * usually useless though. */
80619 extern __printf(2, 3)
80620 int __request_module(bool wait, const char *name, ...);
80621+extern __printf(3, 4)
80622+int ___request_module(bool wait, char *param_name, const char *name, ...);
80623 #define request_module(mod...) __request_module(true, mod)
80624 #define request_module_nowait(mod...) __request_module(false, mod)
80625 #define try_then_request_module(x, mod...) \
80626@@ -57,6 +59,9 @@ struct subprocess_info {
80627 struct work_struct work;
80628 struct completion *complete;
80629 char *path;
80630+#ifdef CONFIG_GRKERNSEC
80631+ char *origpath;
80632+#endif
80633 char **argv;
80634 char **envp;
80635 int wait;
80636diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80637index f896a33..f2eb10f 100644
80638--- a/include/linux/kobject.h
80639+++ b/include/linux/kobject.h
80640@@ -116,7 +116,7 @@ struct kobj_type {
80641 struct attribute **default_attrs;
80642 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80643 const void *(*namespace)(struct kobject *kobj);
80644-};
80645+} __do_const;
80646
80647 struct kobj_uevent_env {
80648 char *argv[3];
80649@@ -140,6 +140,7 @@ struct kobj_attribute {
80650 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80651 const char *buf, size_t count);
80652 };
80653+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80654
80655 extern const struct sysfs_ops kobj_sysfs_ops;
80656
80657@@ -167,7 +168,7 @@ struct kset {
80658 spinlock_t list_lock;
80659 struct kobject kobj;
80660 const struct kset_uevent_ops *uevent_ops;
80661-};
80662+} __randomize_layout;
80663
80664 extern void kset_init(struct kset *kset);
80665 extern int __must_check kset_register(struct kset *kset);
80666diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80667index df32d25..fb52e27 100644
80668--- a/include/linux/kobject_ns.h
80669+++ b/include/linux/kobject_ns.h
80670@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80671 const void *(*netlink_ns)(struct sock *sk);
80672 const void *(*initial_ns)(void);
80673 void (*drop_ns)(void *);
80674-};
80675+} __do_const;
80676
80677 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80678 int kobj_ns_type_registered(enum kobj_ns_type type);
80679diff --git a/include/linux/kref.h b/include/linux/kref.h
80680index 484604d..0f6c5b6 100644
80681--- a/include/linux/kref.h
80682+++ b/include/linux/kref.h
80683@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80684 static inline int kref_sub(struct kref *kref, unsigned int count,
80685 void (*release)(struct kref *kref))
80686 {
80687- WARN_ON(release == NULL);
80688+ BUG_ON(release == NULL);
80689
80690 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80691 release(kref);
80692diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80693index 7d21cf9..bc0c81f 100644
80694--- a/include/linux/kvm_host.h
80695+++ b/include/linux/kvm_host.h
80696@@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80697 {
80698 }
80699 #endif
80700-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80701+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80702 struct module *module);
80703 void kvm_exit(void);
80704
80705@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80706 struct kvm_guest_debug *dbg);
80707 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80708
80709-int kvm_arch_init(void *opaque);
80710+int kvm_arch_init(const void *opaque);
80711 void kvm_arch_exit(void);
80712
80713 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80714diff --git a/include/linux/libata.h b/include/linux/libata.h
80715index 92abb49..e7fff2a 100644
80716--- a/include/linux/libata.h
80717+++ b/include/linux/libata.h
80718@@ -976,7 +976,7 @@ struct ata_port_operations {
80719 * fields must be pointers.
80720 */
80721 const struct ata_port_operations *inherits;
80722-};
80723+} __do_const;
80724
80725 struct ata_port_info {
80726 unsigned long flags;
80727diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80728index a6a42dd..6c5ebce 100644
80729--- a/include/linux/linkage.h
80730+++ b/include/linux/linkage.h
80731@@ -36,6 +36,7 @@
80732 #endif
80733
80734 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80735+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80736 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80737
80738 /*
80739diff --git a/include/linux/list.h b/include/linux/list.h
80740index ef95941..82db65a 100644
80741--- a/include/linux/list.h
80742+++ b/include/linux/list.h
80743@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80744 extern void list_del(struct list_head *entry);
80745 #endif
80746
80747+extern void __pax_list_add(struct list_head *new,
80748+ struct list_head *prev,
80749+ struct list_head *next);
80750+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80751+{
80752+ __pax_list_add(new, head, head->next);
80753+}
80754+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80755+{
80756+ __pax_list_add(new, head->prev, head);
80757+}
80758+extern void pax_list_del(struct list_head *entry);
80759+
80760 /**
80761 * list_replace - replace old entry by new one
80762 * @old : the element to be replaced
80763@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80764 INIT_LIST_HEAD(entry);
80765 }
80766
80767+extern void pax_list_del_init(struct list_head *entry);
80768+
80769 /**
80770 * list_move - delete from one list and add as another's head
80771 * @list: the entry to move
80772diff --git a/include/linux/math64.h b/include/linux/math64.h
80773index c45c089..298841c 100644
80774--- a/include/linux/math64.h
80775+++ b/include/linux/math64.h
80776@@ -15,7 +15,7 @@
80777 * This is commonly provided by 32bit archs to provide an optimized 64bit
80778 * divide.
80779 */
80780-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80781+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80782 {
80783 *remainder = dividend % divisor;
80784 return dividend / divisor;
80785@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80786 /**
80787 * div64_u64 - unsigned 64bit divide with 64bit divisor
80788 */
80789-static inline u64 div64_u64(u64 dividend, u64 divisor)
80790+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80791 {
80792 return dividend / divisor;
80793 }
80794@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80795 #define div64_ul(x, y) div_u64((x), (y))
80796
80797 #ifndef div_u64_rem
80798-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80799+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80800 {
80801 *remainder = do_div(dividend, divisor);
80802 return dividend;
80803@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80804 #endif
80805
80806 #ifndef div64_u64
80807-extern u64 div64_u64(u64 dividend, u64 divisor);
80808+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80809 #endif
80810
80811 #ifndef div64_s64
80812@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80813 * divide.
80814 */
80815 #ifndef div_u64
80816-static inline u64 div_u64(u64 dividend, u32 divisor)
80817+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80818 {
80819 u32 remainder;
80820 return div_u64_rem(dividend, divisor, &remainder);
80821diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80822index f230a97..714c006 100644
80823--- a/include/linux/mempolicy.h
80824+++ b/include/linux/mempolicy.h
80825@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80826 }
80827
80828 #define vma_policy(vma) ((vma)->vm_policy)
80829+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80830+{
80831+ vma->vm_policy = pol;
80832+}
80833
80834 static inline void mpol_get(struct mempolicy *pol)
80835 {
80836@@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80837 }
80838
80839 #define vma_policy(vma) NULL
80840+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80841+{
80842+}
80843
80844 static inline int
80845 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80846diff --git a/include/linux/mm.h b/include/linux/mm.h
80847index d677706..673408c 100644
80848--- a/include/linux/mm.h
80849+++ b/include/linux/mm.h
80850@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80851 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80852 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80853 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80854+
80855+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80856+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80857+#endif
80858+
80859 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80860
80861 #ifdef CONFIG_MEM_SOFT_DIRTY
80862@@ -237,8 +242,8 @@ struct vm_operations_struct {
80863 /* called by access_process_vm when get_user_pages() fails, typically
80864 * for use by special VMAs that can switch between memory and hardware
80865 */
80866- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80867- void *buf, int len, int write);
80868+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80869+ void *buf, size_t len, int write);
80870 #ifdef CONFIG_NUMA
80871 /*
80872 * set_policy() op must add a reference to any non-NULL @new mempolicy
80873@@ -268,6 +273,7 @@ struct vm_operations_struct {
80874 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80875 unsigned long size, pgoff_t pgoff);
80876 };
80877+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80878
80879 struct mmu_gather;
80880 struct inode;
80881@@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80882 unsigned long *pfn);
80883 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80884 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80885-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80886- void *buf, int len, int write);
80887+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80888+ void *buf, size_t len, int write);
80889
80890 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80891 loff_t const holebegin, loff_t const holelen)
80892@@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80893 }
80894 #endif
80895
80896-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80897-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80898- void *buf, int len, int write);
80899+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80900+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80901+ void *buf, size_t len, int write);
80902
80903 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80904 unsigned long start, unsigned long nr_pages,
80905@@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
80906 int clear_page_dirty_for_io(struct page *page);
80907 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
80908
80909-/* Is the vma a continuation of the stack vma above it? */
80910-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80911-{
80912- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80913-}
80914-
80915-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80916- unsigned long addr)
80917-{
80918- return (vma->vm_flags & VM_GROWSDOWN) &&
80919- (vma->vm_start == addr) &&
80920- !vma_growsdown(vma->vm_prev, addr);
80921-}
80922-
80923-/* Is the vma a continuation of the stack vma below it? */
80924-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80925-{
80926- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80927-}
80928-
80929-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80930- unsigned long addr)
80931-{
80932- return (vma->vm_flags & VM_GROWSUP) &&
80933- (vma->vm_end == addr) &&
80934- !vma_growsup(vma->vm_next, addr);
80935-}
80936-
80937 extern pid_t
80938 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80939
80940@@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80941 }
80942 #endif
80943
80944+#ifdef CONFIG_MMU
80945+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80946+#else
80947+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80948+{
80949+ return __pgprot(0);
80950+}
80951+#endif
80952+
80953 int vma_wants_writenotify(struct vm_area_struct *vma);
80954
80955 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80956@@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80957 {
80958 return 0;
80959 }
80960+
80961+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80962+ unsigned long address)
80963+{
80964+ return 0;
80965+}
80966 #else
80967 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80968+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80969 #endif
80970
80971 #ifdef __PAGETABLE_PMD_FOLDED
80972@@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80973 {
80974 return 0;
80975 }
80976+
80977+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80978+ unsigned long address)
80979+{
80980+ return 0;
80981+}
80982 #else
80983 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80984+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80985 #endif
80986
80987 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80988@@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80989 NULL: pud_offset(pgd, address);
80990 }
80991
80992+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80993+{
80994+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80995+ NULL: pud_offset(pgd, address);
80996+}
80997+
80998 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80999 {
81000 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
81001 NULL: pmd_offset(pud, address);
81002 }
81003+
81004+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
81005+{
81006+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
81007+ NULL: pmd_offset(pud, address);
81008+}
81009 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
81010
81011 #if USE_SPLIT_PTE_PTLOCKS
81012@@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
81013 unsigned long addr, unsigned long len,
81014 unsigned long flags, struct page **pages);
81015
81016-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
81017+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
81018
81019 extern unsigned long mmap_region(struct file *file, unsigned long addr,
81020 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
81021@@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81022 unsigned long len, unsigned long prot, unsigned long flags,
81023 unsigned long pgoff, unsigned long *populate);
81024 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
81025+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
81026
81027 #ifdef CONFIG_MMU
81028 extern int __mm_populate(unsigned long addr, unsigned long len,
81029@@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
81030 unsigned long high_limit;
81031 unsigned long align_mask;
81032 unsigned long align_offset;
81033+ unsigned long threadstack_offset;
81034 };
81035
81036-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
81037-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81038+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
81039+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
81040
81041 /*
81042 * Search for an unmapped address range.
81043@@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81044 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
81045 */
81046 static inline unsigned long
81047-vm_unmapped_area(struct vm_unmapped_area_info *info)
81048+vm_unmapped_area(const struct vm_unmapped_area_info *info)
81049 {
81050 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
81051 return unmapped_area(info);
81052@@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
81053 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
81054 struct vm_area_struct **pprev);
81055
81056+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
81057+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
81058+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
81059+
81060 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
81061 NULL if none. Assume start_addr < end_addr. */
81062 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
81063@@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
81064 return vma;
81065 }
81066
81067-#ifdef CONFIG_MMU
81068-pgprot_t vm_get_page_prot(unsigned long vm_flags);
81069-#else
81070-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
81071-{
81072- return __pgprot(0);
81073-}
81074-#endif
81075-
81076 #ifdef CONFIG_NUMA_BALANCING
81077 unsigned long change_prot_numa(struct vm_area_struct *vma,
81078 unsigned long start, unsigned long end);
81079@@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
81080 static inline void vm_stat_account(struct mm_struct *mm,
81081 unsigned long flags, struct file *file, long pages)
81082 {
81083+
81084+#ifdef CONFIG_PAX_RANDMMAP
81085+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81086+#endif
81087+
81088 mm->total_vm += pages;
81089 }
81090 #endif /* CONFIG_PROC_FS */
81091@@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
81092 extern int sysctl_memory_failure_early_kill;
81093 extern int sysctl_memory_failure_recovery;
81094 extern void shake_page(struct page *p, int access);
81095-extern atomic_long_t num_poisoned_pages;
81096+extern atomic_long_unchecked_t num_poisoned_pages;
81097 extern int soft_offline_page(struct page *page, int flags);
81098
81099 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
81100@@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
81101 static inline void setup_nr_node_ids(void) {}
81102 #endif
81103
81104+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81105+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
81106+#else
81107+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
81108+#endif
81109+
81110 #endif /* __KERNEL__ */
81111 #endif /* _LINUX_MM_H */
81112diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
81113index 8967e20..61f7900 100644
81114--- a/include/linux/mm_types.h
81115+++ b/include/linux/mm_types.h
81116@@ -308,7 +308,9 @@ struct vm_area_struct {
81117 #ifdef CONFIG_NUMA
81118 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
81119 #endif
81120-};
81121+
81122+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
81123+} __randomize_layout;
81124
81125 struct core_thread {
81126 struct task_struct *task;
81127@@ -454,7 +456,25 @@ struct mm_struct {
81128 bool tlb_flush_pending;
81129 #endif
81130 struct uprobes_state uprobes_state;
81131-};
81132+
81133+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81134+ unsigned long pax_flags;
81135+#endif
81136+
81137+#ifdef CONFIG_PAX_DLRESOLVE
81138+ unsigned long call_dl_resolve;
81139+#endif
81140+
81141+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
81142+ unsigned long call_syscall;
81143+#endif
81144+
81145+#ifdef CONFIG_PAX_ASLR
81146+ unsigned long delta_mmap; /* randomized offset */
81147+ unsigned long delta_stack; /* randomized offset */
81148+#endif
81149+
81150+} __randomize_layout;
81151
81152 static inline void mm_init_cpumask(struct mm_struct *mm)
81153 {
81154diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
81155index c5d5278..f0b68c8 100644
81156--- a/include/linux/mmiotrace.h
81157+++ b/include/linux/mmiotrace.h
81158@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
81159 /* Called from ioremap.c */
81160 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
81161 void __iomem *addr);
81162-extern void mmiotrace_iounmap(volatile void __iomem *addr);
81163+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
81164
81165 /* For anyone to insert markers. Remember trailing newline. */
81166 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
81167@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
81168 {
81169 }
81170
81171-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
81172+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
81173 {
81174 }
81175
81176diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
81177index 835aa3d..676b387 100644
81178--- a/include/linux/mmzone.h
81179+++ b/include/linux/mmzone.h
81180@@ -406,7 +406,7 @@ struct zone {
81181 unsigned long flags; /* zone flags, see below */
81182
81183 /* Zone statistics */
81184- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81185+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81186
81187 /*
81188 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
81189diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
81190index 44eeef0..a92d3f9 100644
81191--- a/include/linux/mod_devicetable.h
81192+++ b/include/linux/mod_devicetable.h
81193@@ -139,7 +139,7 @@ struct usb_device_id {
81194 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
81195 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
81196
81197-#define HID_ANY_ID (~0)
81198+#define HID_ANY_ID (~0U)
81199 #define HID_BUS_ANY 0xffff
81200 #define HID_GROUP_ANY 0x0000
81201
81202@@ -475,7 +475,7 @@ struct dmi_system_id {
81203 const char *ident;
81204 struct dmi_strmatch matches[4];
81205 void *driver_data;
81206-};
81207+} __do_const;
81208 /*
81209 * struct dmi_device_id appears during expansion of
81210 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
81211diff --git a/include/linux/module.h b/include/linux/module.h
81212index f520a76..5f898ef 100644
81213--- a/include/linux/module.h
81214+++ b/include/linux/module.h
81215@@ -17,9 +17,11 @@
81216 #include <linux/moduleparam.h>
81217 #include <linux/jump_label.h>
81218 #include <linux/export.h>
81219+#include <linux/fs.h>
81220
81221 #include <linux/percpu.h>
81222 #include <asm/module.h>
81223+#include <asm/pgtable.h>
81224
81225 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81226 #define MODULE_SIG_STRING "~Module signature appended~\n"
81227@@ -42,7 +44,7 @@ struct module_kobject {
81228 struct kobject *drivers_dir;
81229 struct module_param_attrs *mp;
81230 struct completion *kobj_completion;
81231-};
81232+} __randomize_layout;
81233
81234 struct module_attribute {
81235 struct attribute attr;
81236@@ -54,12 +56,13 @@ struct module_attribute {
81237 int (*test)(struct module *);
81238 void (*free)(struct module *);
81239 };
81240+typedef struct module_attribute __no_const module_attribute_no_const;
81241
81242 struct module_version_attribute {
81243 struct module_attribute mattr;
81244 const char *module_name;
81245 const char *version;
81246-} __attribute__ ((__aligned__(sizeof(void *))));
81247+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81248
81249 extern ssize_t __modver_version_show(struct module_attribute *,
81250 struct module_kobject *, char *);
81251@@ -235,7 +238,7 @@ struct module {
81252
81253 /* Sysfs stuff. */
81254 struct module_kobject mkobj;
81255- struct module_attribute *modinfo_attrs;
81256+ module_attribute_no_const *modinfo_attrs;
81257 const char *version;
81258 const char *srcversion;
81259 struct kobject *holders_dir;
81260@@ -284,19 +287,16 @@ struct module {
81261 int (*init)(void);
81262
81263 /* If this is non-NULL, vfree after init() returns */
81264- void *module_init;
81265+ void *module_init_rx, *module_init_rw;
81266
81267 /* Here is the actual code + data, vfree'd on unload. */
81268- void *module_core;
81269+ void *module_core_rx, *module_core_rw;
81270
81271 /* Here are the sizes of the init and core sections */
81272- unsigned int init_size, core_size;
81273+ unsigned int init_size_rw, core_size_rw;
81274
81275 /* The size of the executable code in each section. */
81276- unsigned int init_text_size, core_text_size;
81277-
81278- /* Size of RO sections of the module (text+rodata) */
81279- unsigned int init_ro_size, core_ro_size;
81280+ unsigned int init_size_rx, core_size_rx;
81281
81282 /* Arch-specific module values */
81283 struct mod_arch_specific arch;
81284@@ -352,6 +352,10 @@ struct module {
81285 #ifdef CONFIG_EVENT_TRACING
81286 struct ftrace_event_call **trace_events;
81287 unsigned int num_trace_events;
81288+ struct file_operations trace_id;
81289+ struct file_operations trace_enable;
81290+ struct file_operations trace_format;
81291+ struct file_operations trace_filter;
81292 #endif
81293 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81294 unsigned int num_ftrace_callsites;
81295@@ -375,7 +379,7 @@ struct module {
81296 ctor_fn_t *ctors;
81297 unsigned int num_ctors;
81298 #endif
81299-};
81300+} __randomize_layout;
81301 #ifndef MODULE_ARCH_INIT
81302 #define MODULE_ARCH_INIT {}
81303 #endif
81304@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
81305 bool is_module_percpu_address(unsigned long addr);
81306 bool is_module_text_address(unsigned long addr);
81307
81308+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81309+{
81310+
81311+#ifdef CONFIG_PAX_KERNEXEC
81312+ if (ktla_ktva(addr) >= (unsigned long)start &&
81313+ ktla_ktva(addr) < (unsigned long)start + size)
81314+ return 1;
81315+#endif
81316+
81317+ return ((void *)addr >= start && (void *)addr < start + size);
81318+}
81319+
81320+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81321+{
81322+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81323+}
81324+
81325+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81326+{
81327+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81328+}
81329+
81330+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81331+{
81332+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81333+}
81334+
81335+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81336+{
81337+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81338+}
81339+
81340 static inline int within_module_core(unsigned long addr, const struct module *mod)
81341 {
81342- return (unsigned long)mod->module_core <= addr &&
81343- addr < (unsigned long)mod->module_core + mod->core_size;
81344+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81345 }
81346
81347 static inline int within_module_init(unsigned long addr, const struct module *mod)
81348 {
81349- return (unsigned long)mod->module_init <= addr &&
81350- addr < (unsigned long)mod->module_init + mod->init_size;
81351+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81352 }
81353
81354 /* Search for module by name: must hold module_mutex. */
81355diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81356index 560ca53..ef621ef 100644
81357--- a/include/linux/moduleloader.h
81358+++ b/include/linux/moduleloader.h
81359@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81360 sections. Returns NULL on failure. */
81361 void *module_alloc(unsigned long size);
81362
81363+#ifdef CONFIG_PAX_KERNEXEC
81364+void *module_alloc_exec(unsigned long size);
81365+#else
81366+#define module_alloc_exec(x) module_alloc(x)
81367+#endif
81368+
81369 /* Free memory returned from module_alloc. */
81370 void module_free(struct module *mod, void *module_region);
81371
81372+#ifdef CONFIG_PAX_KERNEXEC
81373+void module_free_exec(struct module *mod, void *module_region);
81374+#else
81375+#define module_free_exec(x, y) module_free((x), (y))
81376+#endif
81377+
81378 /*
81379 * Apply the given relocation to the (simplified) ELF. Return -error
81380 * or 0.
81381@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81382 unsigned int relsec,
81383 struct module *me)
81384 {
81385+#ifdef CONFIG_MODULES
81386 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81387+#endif
81388 return -ENOEXEC;
81389 }
81390 #endif
81391@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81392 unsigned int relsec,
81393 struct module *me)
81394 {
81395+#ifdef CONFIG_MODULES
81396 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81397+#endif
81398 return -ENOEXEC;
81399 }
81400 #endif
81401diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81402index 204a677..e9b486a 100644
81403--- a/include/linux/moduleparam.h
81404+++ b/include/linux/moduleparam.h
81405@@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
81406 * @len is usually just sizeof(string).
81407 */
81408 #define module_param_string(name, string, len, perm) \
81409- static const struct kparam_string __param_string_##name \
81410+ static const struct kparam_string __param_string_##name __used \
81411 = { len, string }; \
81412 __module_param_call(MODULE_PARAM_PREFIX, name, \
81413 &param_ops_string, \
81414@@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81415 */
81416 #define module_param_array_named(name, array, type, nump, perm) \
81417 param_check_##type(name, &(array)[0]); \
81418- static const struct kparam_array __param_arr_##name \
81419+ static const struct kparam_array __param_arr_##name __used \
81420 = { .max = ARRAY_SIZE(array), .num = nump, \
81421 .ops = &param_ops_##type, \
81422 .elemsize = sizeof(array[0]), .elem = array }; \
81423diff --git a/include/linux/mount.h b/include/linux/mount.h
81424index 839bac2..a96b37c 100644
81425--- a/include/linux/mount.h
81426+++ b/include/linux/mount.h
81427@@ -59,7 +59,7 @@ struct vfsmount {
81428 struct dentry *mnt_root; /* root of the mounted tree */
81429 struct super_block *mnt_sb; /* pointer to superblock */
81430 int mnt_flags;
81431-};
81432+} __randomize_layout;
81433
81434 struct file; /* forward dec */
81435
81436diff --git a/include/linux/namei.h b/include/linux/namei.h
81437index 492de72..1bddcd4 100644
81438--- a/include/linux/namei.h
81439+++ b/include/linux/namei.h
81440@@ -19,7 +19,7 @@ struct nameidata {
81441 unsigned seq, m_seq;
81442 int last_type;
81443 unsigned depth;
81444- char *saved_names[MAX_NESTED_LINKS + 1];
81445+ const char *saved_names[MAX_NESTED_LINKS + 1];
81446 };
81447
81448 /*
81449@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81450
81451 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81452
81453-static inline void nd_set_link(struct nameidata *nd, char *path)
81454+static inline void nd_set_link(struct nameidata *nd, const char *path)
81455 {
81456 nd->saved_names[nd->depth] = path;
81457 }
81458
81459-static inline char *nd_get_link(struct nameidata *nd)
81460+static inline const char *nd_get_link(const struct nameidata *nd)
81461 {
81462 return nd->saved_names[nd->depth];
81463 }
81464diff --git a/include/linux/net.h b/include/linux/net.h
81465index 17d8339..81656c0 100644
81466--- a/include/linux/net.h
81467+++ b/include/linux/net.h
81468@@ -192,7 +192,7 @@ struct net_proto_family {
81469 int (*create)(struct net *net, struct socket *sock,
81470 int protocol, int kern);
81471 struct module *owner;
81472-};
81473+} __do_const;
81474
81475 struct iovec;
81476 struct kvec;
81477diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81478index b42d07b..7f45ae2 100644
81479--- a/include/linux/netdevice.h
81480+++ b/include/linux/netdevice.h
81481@@ -1146,6 +1146,7 @@ struct net_device_ops {
81482 void *priv);
81483 int (*ndo_get_lock_subclass)(struct net_device *dev);
81484 };
81485+typedef struct net_device_ops __no_const net_device_ops_no_const;
81486
81487 /**
81488 * enum net_device_priv_flags - &struct net_device priv_flags
81489@@ -1313,11 +1314,11 @@ struct net_device {
81490 struct net_device_stats stats;
81491
81492 /* dropped packets by core network, Do not use this in drivers */
81493- atomic_long_t rx_dropped;
81494- atomic_long_t tx_dropped;
81495+ atomic_long_unchecked_t rx_dropped;
81496+ atomic_long_unchecked_t tx_dropped;
81497
81498 /* Stats to monitor carrier on<->off transitions */
81499- atomic_t carrier_changes;
81500+ atomic_unchecked_t carrier_changes;
81501
81502 #ifdef CONFIG_WIRELESS_EXT
81503 /* List of functions to handle Wireless Extensions (instead of ioctl).
81504diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81505index 2077489..a15e561 100644
81506--- a/include/linux/netfilter.h
81507+++ b/include/linux/netfilter.h
81508@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81509 #endif
81510 /* Use the module struct to lock set/get code in place */
81511 struct module *owner;
81512-};
81513+} __do_const;
81514
81515 /* Function to register/unregister hook points. */
81516 int nf_register_hook(struct nf_hook_ops *reg);
81517diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81518index e955d47..04a5338 100644
81519--- a/include/linux/netfilter/nfnetlink.h
81520+++ b/include/linux/netfilter/nfnetlink.h
81521@@ -19,7 +19,7 @@ struct nfnl_callback {
81522 const struct nlattr * const cda[]);
81523 const struct nla_policy *policy; /* netlink attribute policy */
81524 const u_int16_t attr_count; /* number of nlattr's */
81525-};
81526+} __do_const;
81527
81528 struct nfnetlink_subsystem {
81529 const char *name;
81530diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81531new file mode 100644
81532index 0000000..33f4af8
81533--- /dev/null
81534+++ b/include/linux/netfilter/xt_gradm.h
81535@@ -0,0 +1,9 @@
81536+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81537+#define _LINUX_NETFILTER_XT_GRADM_H 1
81538+
81539+struct xt_gradm_mtinfo {
81540+ __u16 flags;
81541+ __u16 invflags;
81542+};
81543+
81544+#endif
81545diff --git a/include/linux/nls.h b/include/linux/nls.h
81546index 520681b..1d67ed2 100644
81547--- a/include/linux/nls.h
81548+++ b/include/linux/nls.h
81549@@ -31,7 +31,7 @@ struct nls_table {
81550 const unsigned char *charset2upper;
81551 struct module *owner;
81552 struct nls_table *next;
81553-};
81554+} __do_const;
81555
81556 /* this value hold the maximum octet of charset */
81557 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81558diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81559index d14a4c3..a078786 100644
81560--- a/include/linux/notifier.h
81561+++ b/include/linux/notifier.h
81562@@ -54,7 +54,8 @@ struct notifier_block {
81563 notifier_fn_t notifier_call;
81564 struct notifier_block __rcu *next;
81565 int priority;
81566-};
81567+} __do_const;
81568+typedef struct notifier_block __no_const notifier_block_no_const;
81569
81570 struct atomic_notifier_head {
81571 spinlock_t lock;
81572diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81573index b2a0f15..4d7da32 100644
81574--- a/include/linux/oprofile.h
81575+++ b/include/linux/oprofile.h
81576@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81577 int oprofilefs_create_ro_ulong(struct dentry * root,
81578 char const * name, ulong * val);
81579
81580-/** Create a file for read-only access to an atomic_t. */
81581+/** Create a file for read-only access to an atomic_unchecked_t. */
81582 int oprofilefs_create_ro_atomic(struct dentry * root,
81583- char const * name, atomic_t * val);
81584+ char const * name, atomic_unchecked_t * val);
81585
81586 /** create a directory */
81587 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81588diff --git a/include/linux/padata.h b/include/linux/padata.h
81589index 4386946..f50c615 100644
81590--- a/include/linux/padata.h
81591+++ b/include/linux/padata.h
81592@@ -129,7 +129,7 @@ struct parallel_data {
81593 struct padata_serial_queue __percpu *squeue;
81594 atomic_t reorder_objects;
81595 atomic_t refcnt;
81596- atomic_t seq_nr;
81597+ atomic_unchecked_t seq_nr;
81598 struct padata_cpumask cpumask;
81599 spinlock_t lock ____cacheline_aligned;
81600 unsigned int processed;
81601diff --git a/include/linux/path.h b/include/linux/path.h
81602index d137218..be0c176 100644
81603--- a/include/linux/path.h
81604+++ b/include/linux/path.h
81605@@ -1,13 +1,15 @@
81606 #ifndef _LINUX_PATH_H
81607 #define _LINUX_PATH_H
81608
81609+#include <linux/compiler.h>
81610+
81611 struct dentry;
81612 struct vfsmount;
81613
81614 struct path {
81615 struct vfsmount *mnt;
81616 struct dentry *dentry;
81617-};
81618+} __randomize_layout;
81619
81620 extern void path_get(const struct path *);
81621 extern void path_put(const struct path *);
81622diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81623index 5f2e559..7d59314 100644
81624--- a/include/linux/pci_hotplug.h
81625+++ b/include/linux/pci_hotplug.h
81626@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81627 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81628 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81629 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81630-};
81631+} __do_const;
81632+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81633
81634 /**
81635 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81636diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81637index 3ef6ea1..ed1a248 100644
81638--- a/include/linux/perf_event.h
81639+++ b/include/linux/perf_event.h
81640@@ -328,8 +328,8 @@ struct perf_event {
81641
81642 enum perf_event_active_state state;
81643 unsigned int attach_state;
81644- local64_t count;
81645- atomic64_t child_count;
81646+ local64_t count; /* PaX: fix it one day */
81647+ atomic64_unchecked_t child_count;
81648
81649 /*
81650 * These are the total time in nanoseconds that the event
81651@@ -380,8 +380,8 @@ struct perf_event {
81652 * These accumulate total time (in nanoseconds) that children
81653 * events have been enabled and running, respectively.
81654 */
81655- atomic64_t child_total_time_enabled;
81656- atomic64_t child_total_time_running;
81657+ atomic64_unchecked_t child_total_time_enabled;
81658+ atomic64_unchecked_t child_total_time_running;
81659
81660 /*
81661 * Protect attach/detach and child_list:
81662@@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81663 entry->ip[entry->nr++] = ip;
81664 }
81665
81666-extern int sysctl_perf_event_paranoid;
81667+extern int sysctl_perf_event_legitimately_concerned;
81668 extern int sysctl_perf_event_mlock;
81669 extern int sysctl_perf_event_sample_rate;
81670 extern int sysctl_perf_cpu_time_max_percent;
81671@@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81672 loff_t *ppos);
81673
81674
81675+static inline bool perf_paranoid_any(void)
81676+{
81677+ return sysctl_perf_event_legitimately_concerned > 2;
81678+}
81679+
81680 static inline bool perf_paranoid_tracepoint_raw(void)
81681 {
81682- return sysctl_perf_event_paranoid > -1;
81683+ return sysctl_perf_event_legitimately_concerned > -1;
81684 }
81685
81686 static inline bool perf_paranoid_cpu(void)
81687 {
81688- return sysctl_perf_event_paranoid > 0;
81689+ return sysctl_perf_event_legitimately_concerned > 0;
81690 }
81691
81692 static inline bool perf_paranoid_kernel(void)
81693 {
81694- return sysctl_perf_event_paranoid > 1;
81695+ return sysctl_perf_event_legitimately_concerned > 1;
81696 }
81697
81698 extern void perf_event_init(void);
81699@@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81700 struct device_attribute attr;
81701 u64 id;
81702 const char *event_str;
81703-};
81704+} __do_const;
81705
81706 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81707 static struct perf_pmu_events_attr _var = { \
81708diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81709index 7246ef3..1539ea4 100644
81710--- a/include/linux/pid_namespace.h
81711+++ b/include/linux/pid_namespace.h
81712@@ -43,7 +43,7 @@ struct pid_namespace {
81713 int hide_pid;
81714 int reboot; /* group exit code if this pidns was rebooted */
81715 unsigned int proc_inum;
81716-};
81717+} __randomize_layout;
81718
81719 extern struct pid_namespace init_pid_ns;
81720
81721diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81722index eb8b8ac..62649e1 100644
81723--- a/include/linux/pipe_fs_i.h
81724+++ b/include/linux/pipe_fs_i.h
81725@@ -47,10 +47,10 @@ struct pipe_inode_info {
81726 struct mutex mutex;
81727 wait_queue_head_t wait;
81728 unsigned int nrbufs, curbuf, buffers;
81729- unsigned int readers;
81730- unsigned int writers;
81731- unsigned int files;
81732- unsigned int waiting_writers;
81733+ atomic_t readers;
81734+ atomic_t writers;
81735+ atomic_t files;
81736+ atomic_t waiting_writers;
81737 unsigned int r_counter;
81738 unsigned int w_counter;
81739 struct page *tmp_page;
81740diff --git a/include/linux/pm.h b/include/linux/pm.h
81741index d915d03..0531037 100644
81742--- a/include/linux/pm.h
81743+++ b/include/linux/pm.h
81744@@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81745 struct dev_pm_domain {
81746 struct dev_pm_ops ops;
81747 };
81748+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81749
81750 /*
81751 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81752diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81753index 7c1d252..0e7061d 100644
81754--- a/include/linux/pm_domain.h
81755+++ b/include/linux/pm_domain.h
81756@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81757 int (*thaw_early)(struct device *dev);
81758 int (*thaw)(struct device *dev);
81759 bool (*active_wakeup)(struct device *dev);
81760-};
81761+} __no_const;
81762
81763 struct gpd_cpu_data {
81764 unsigned int saved_exit_latency;
81765- struct cpuidle_state *idle_state;
81766+ cpuidle_state_no_const *idle_state;
81767 };
81768
81769 struct generic_pm_domain {
81770diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81771index 2a5897a..4f9af63 100644
81772--- a/include/linux/pm_runtime.h
81773+++ b/include/linux/pm_runtime.h
81774@@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81775
81776 static inline void pm_runtime_mark_last_busy(struct device *dev)
81777 {
81778- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81779+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81780 }
81781
81782 #else /* !CONFIG_PM_RUNTIME */
81783diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81784index 195aafc..49a7bc2 100644
81785--- a/include/linux/pnp.h
81786+++ b/include/linux/pnp.h
81787@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81788 struct pnp_fixup {
81789 char id[7];
81790 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81791-};
81792+} __do_const;
81793
81794 /* config parameters */
81795 #define PNP_CONFIG_NORMAL 0x0001
81796diff --git a/include/linux/poison.h b/include/linux/poison.h
81797index 2110a81..13a11bb 100644
81798--- a/include/linux/poison.h
81799+++ b/include/linux/poison.h
81800@@ -19,8 +19,8 @@
81801 * under normal circumstances, used to verify that nobody uses
81802 * non-initialized list entries.
81803 */
81804-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81805-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81806+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81807+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81808
81809 /********** include/linux/timer.h **********/
81810 /*
81811diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81812index d8b187c3..9a9257a 100644
81813--- a/include/linux/power/smartreflex.h
81814+++ b/include/linux/power/smartreflex.h
81815@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81816 int (*notify)(struct omap_sr *sr, u32 status);
81817 u8 notify_flags;
81818 u8 class_type;
81819-};
81820+} __do_const;
81821
81822 /**
81823 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81824diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81825index 4ea1d37..80f4b33 100644
81826--- a/include/linux/ppp-comp.h
81827+++ b/include/linux/ppp-comp.h
81828@@ -84,7 +84,7 @@ struct compressor {
81829 struct module *owner;
81830 /* Extra skb space needed by the compressor algorithm */
81831 unsigned int comp_extra;
81832-};
81833+} __do_const;
81834
81835 /*
81836 * The return value from decompress routine is the length of the
81837diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81838index de83b4e..c4b997d 100644
81839--- a/include/linux/preempt.h
81840+++ b/include/linux/preempt.h
81841@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81842 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81843 #endif
81844
81845+#define raw_preempt_count_add(val) __preempt_count_add(val)
81846+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81847+
81848 #define __preempt_count_inc() __preempt_count_add(1)
81849 #define __preempt_count_dec() __preempt_count_sub(1)
81850
81851 #define preempt_count_inc() preempt_count_add(1)
81852+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81853 #define preempt_count_dec() preempt_count_sub(1)
81854+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81855
81856 #ifdef CONFIG_PREEMPT_COUNT
81857
81858@@ -41,6 +46,12 @@ do { \
81859 barrier(); \
81860 } while (0)
81861
81862+#define raw_preempt_disable() \
81863+do { \
81864+ raw_preempt_count_inc(); \
81865+ barrier(); \
81866+} while (0)
81867+
81868 #define sched_preempt_enable_no_resched() \
81869 do { \
81870 barrier(); \
81871@@ -49,6 +60,12 @@ do { \
81872
81873 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81874
81875+#define raw_preempt_enable_no_resched() \
81876+do { \
81877+ barrier(); \
81878+ raw_preempt_count_dec(); \
81879+} while (0)
81880+
81881 #ifdef CONFIG_PREEMPT
81882 #define preempt_enable() \
81883 do { \
81884@@ -113,8 +130,10 @@ do { \
81885 * region.
81886 */
81887 #define preempt_disable() barrier()
81888+#define raw_preempt_disable() barrier()
81889 #define sched_preempt_enable_no_resched() barrier()
81890 #define preempt_enable_no_resched() barrier()
81891+#define raw_preempt_enable_no_resched() barrier()
81892 #define preempt_enable() barrier()
81893 #define preempt_check_resched() do { } while (0)
81894
81895@@ -128,11 +147,13 @@ do { \
81896 /*
81897 * Modules have no business playing preemption tricks.
81898 */
81899+#ifndef CONFIG_PAX_KERNEXEC
81900 #undef sched_preempt_enable_no_resched
81901 #undef preempt_enable_no_resched
81902 #undef preempt_enable_no_resched_notrace
81903 #undef preempt_check_resched
81904 #endif
81905+#endif
81906
81907 #define preempt_set_need_resched() \
81908 do { \
81909diff --git a/include/linux/printk.h b/include/linux/printk.h
81910index 7847301..29cd406 100644
81911--- a/include/linux/printk.h
81912+++ b/include/linux/printk.h
81913@@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
81914 void early_printk(const char *s, ...) { }
81915 #endif
81916
81917+extern int kptr_restrict;
81918+
81919 #ifdef CONFIG_PRINTK
81920 asmlinkage __printf(5, 0)
81921 int vprintk_emit(int facility, int level,
81922@@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81923
81924 extern int printk_delay_msec;
81925 extern int dmesg_restrict;
81926-extern int kptr_restrict;
81927
81928 extern void wake_up_klogd(void);
81929
81930diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81931index 608e60a..79cfb18 100644
81932--- a/include/linux/proc_fs.h
81933+++ b/include/linux/proc_fs.h
81934@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81935 extern struct proc_dir_entry *proc_symlink(const char *,
81936 struct proc_dir_entry *, const char *);
81937 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81938+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81939 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81940 struct proc_dir_entry *, void *);
81941+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81942+ struct proc_dir_entry *, void *);
81943 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81944 struct proc_dir_entry *);
81945
81946@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81947 return proc_create_data(name, mode, parent, proc_fops, NULL);
81948 }
81949
81950+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81951+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81952+{
81953+#ifdef CONFIG_GRKERNSEC_PROC_USER
81954+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81955+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81956+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81957+#else
81958+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81959+#endif
81960+}
81961+
81962+
81963 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81964 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81965 extern void *PDE_DATA(const struct inode *);
81966@@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
81967 struct proc_dir_entry *parent,const char *dest) { return NULL;}
81968 static inline struct proc_dir_entry *proc_mkdir(const char *name,
81969 struct proc_dir_entry *parent) {return NULL;}
81970+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
81971+ struct proc_dir_entry *parent) { return NULL; }
81972 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
81973 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81974+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
81975+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81976 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
81977 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
81978 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
81979@@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81980 static inline struct proc_dir_entry *proc_net_mkdir(
81981 struct net *net, const char *name, struct proc_dir_entry *parent)
81982 {
81983- return proc_mkdir_data(name, 0, parent, net);
81984+ return proc_mkdir_data_restrict(name, 0, parent, net);
81985 }
81986
81987 #endif /* _LINUX_PROC_FS_H */
81988diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81989index 34a1e10..70f6bde 100644
81990--- a/include/linux/proc_ns.h
81991+++ b/include/linux/proc_ns.h
81992@@ -14,7 +14,7 @@ struct proc_ns_operations {
81993 void (*put)(void *ns);
81994 int (*install)(struct nsproxy *nsproxy, void *ns);
81995 unsigned int (*inum)(void *ns);
81996-};
81997+} __do_const __randomize_layout;
81998
81999 struct proc_ns {
82000 void *ns;
82001diff --git a/include/linux/quota.h b/include/linux/quota.h
82002index cc7494a..1e27036 100644
82003--- a/include/linux/quota.h
82004+++ b/include/linux/quota.h
82005@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
82006
82007 extern bool qid_eq(struct kqid left, struct kqid right);
82008 extern bool qid_lt(struct kqid left, struct kqid right);
82009-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
82010+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
82011 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
82012 extern bool qid_valid(struct kqid qid);
82013
82014diff --git a/include/linux/random.h b/include/linux/random.h
82015index 57fbbff..2170304 100644
82016--- a/include/linux/random.h
82017+++ b/include/linux/random.h
82018@@ -9,9 +9,19 @@
82019 #include <uapi/linux/random.h>
82020
82021 extern void add_device_randomness(const void *, unsigned int);
82022+
82023+static inline void add_latent_entropy(void)
82024+{
82025+
82026+#ifdef LATENT_ENTROPY_PLUGIN
82027+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82028+#endif
82029+
82030+}
82031+
82032 extern void add_input_randomness(unsigned int type, unsigned int code,
82033- unsigned int value);
82034-extern void add_interrupt_randomness(int irq, int irq_flags);
82035+ unsigned int value) __latent_entropy;
82036+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
82037
82038 extern void get_random_bytes(void *buf, int nbytes);
82039 extern void get_random_bytes_arch(void *buf, int nbytes);
82040@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
82041 extern const struct file_operations random_fops, urandom_fops;
82042 #endif
82043
82044-unsigned int get_random_int(void);
82045+unsigned int __intentional_overflow(-1) get_random_int(void);
82046 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
82047
82048-u32 prandom_u32(void);
82049+u32 prandom_u32(void) __intentional_overflow(-1);
82050 void prandom_bytes(void *buf, int nbytes);
82051 void prandom_seed(u32 seed);
82052 void prandom_reseed_late(void);
82053@@ -37,6 +47,11 @@ struct rnd_state {
82054 u32 prandom_u32_state(struct rnd_state *state);
82055 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
82056
82057+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
82058+{
82059+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
82060+}
82061+
82062 /**
82063 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
82064 * @ep_ro: right open interval endpoint
82065@@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
82066 *
82067 * Returns: pseudo-random number in interval [0, ep_ro)
82068 */
82069-static inline u32 prandom_u32_max(u32 ep_ro)
82070+static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
82071 {
82072 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
82073 }
82074diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
82075index fea49b5..2ac22bb 100644
82076--- a/include/linux/rbtree_augmented.h
82077+++ b/include/linux/rbtree_augmented.h
82078@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
82079 old->rbaugmented = rbcompute(old); \
82080 } \
82081 rbstatic const struct rb_augment_callbacks rbname = { \
82082- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
82083+ .propagate = rbname ## _propagate, \
82084+ .copy = rbname ## _copy, \
82085+ .rotate = rbname ## _rotate \
82086 };
82087
82088
82089diff --git a/include/linux/rculist.h b/include/linux/rculist.h
82090index 8183b46..a388711 100644
82091--- a/include/linux/rculist.h
82092+++ b/include/linux/rculist.h
82093@@ -29,8 +29,8 @@
82094 */
82095 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
82096 {
82097- ACCESS_ONCE(list->next) = list;
82098- ACCESS_ONCE(list->prev) = list;
82099+ ACCESS_ONCE_RW(list->next) = list;
82100+ ACCESS_ONCE_RW(list->prev) = list;
82101 }
82102
82103 /*
82104@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
82105 struct list_head *prev, struct list_head *next);
82106 #endif
82107
82108+void __pax_list_add_rcu(struct list_head *new,
82109+ struct list_head *prev, struct list_head *next);
82110+
82111 /**
82112 * list_add_rcu - add a new entry to rcu-protected list
82113 * @new: new entry to be added
82114@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
82115 __list_add_rcu(new, head, head->next);
82116 }
82117
82118+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
82119+{
82120+ __pax_list_add_rcu(new, head, head->next);
82121+}
82122+
82123 /**
82124 * list_add_tail_rcu - add a new entry to rcu-protected list
82125 * @new: new entry to be added
82126@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
82127 __list_add_rcu(new, head->prev, head);
82128 }
82129
82130+static inline void pax_list_add_tail_rcu(struct list_head *new,
82131+ struct list_head *head)
82132+{
82133+ __pax_list_add_rcu(new, head->prev, head);
82134+}
82135+
82136 /**
82137 * list_del_rcu - deletes entry from list without re-initialization
82138 * @entry: the element to delete from the list.
82139@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
82140 entry->prev = LIST_POISON2;
82141 }
82142
82143+extern void pax_list_del_rcu(struct list_head *entry);
82144+
82145 /**
82146 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
82147 * @n: the element to delete from the hash list.
82148diff --git a/include/linux/reboot.h b/include/linux/reboot.h
82149index 48bf152..d38b785 100644
82150--- a/include/linux/reboot.h
82151+++ b/include/linux/reboot.h
82152@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
82153 */
82154
82155 extern void migrate_to_reboot_cpu(void);
82156-extern void machine_restart(char *cmd);
82157-extern void machine_halt(void);
82158-extern void machine_power_off(void);
82159+extern void machine_restart(char *cmd) __noreturn;
82160+extern void machine_halt(void) __noreturn;
82161+extern void machine_power_off(void) __noreturn;
82162
82163 extern void machine_shutdown(void);
82164 struct pt_regs;
82165@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
82166 */
82167
82168 extern void kernel_restart_prepare(char *cmd);
82169-extern void kernel_restart(char *cmd);
82170-extern void kernel_halt(void);
82171-extern void kernel_power_off(void);
82172+extern void kernel_restart(char *cmd) __noreturn;
82173+extern void kernel_halt(void) __noreturn;
82174+extern void kernel_power_off(void) __noreturn;
82175
82176 extern int C_A_D; /* for sysctl */
82177 void ctrl_alt_del(void);
82178@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
82179 * Emergency restart, callable from an interrupt handler.
82180 */
82181
82182-extern void emergency_restart(void);
82183+extern void emergency_restart(void) __noreturn;
82184 #include <asm/emergency-restart.h>
82185
82186 #endif /* _LINUX_REBOOT_H */
82187diff --git a/include/linux/regset.h b/include/linux/regset.h
82188index 8e0c9fe..ac4d221 100644
82189--- a/include/linux/regset.h
82190+++ b/include/linux/regset.h
82191@@ -161,7 +161,8 @@ struct user_regset {
82192 unsigned int align;
82193 unsigned int bias;
82194 unsigned int core_note_type;
82195-};
82196+} __do_const;
82197+typedef struct user_regset __no_const user_regset_no_const;
82198
82199 /**
82200 * struct user_regset_view - available regsets
82201diff --git a/include/linux/relay.h b/include/linux/relay.h
82202index d7c8359..818daf5 100644
82203--- a/include/linux/relay.h
82204+++ b/include/linux/relay.h
82205@@ -157,7 +157,7 @@ struct rchan_callbacks
82206 * The callback should return 0 if successful, negative if not.
82207 */
82208 int (*remove_buf_file)(struct dentry *dentry);
82209-};
82210+} __no_const;
82211
82212 /*
82213 * CONFIG_RELAY kernel API, kernel/relay.c
82214diff --git a/include/linux/rio.h b/include/linux/rio.h
82215index 6bda06f..bf39a9b 100644
82216--- a/include/linux/rio.h
82217+++ b/include/linux/rio.h
82218@@ -358,7 +358,7 @@ struct rio_ops {
82219 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
82220 u64 rstart, u32 size, u32 flags);
82221 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
82222-};
82223+} __no_const;
82224
82225 #define RIO_RESOURCE_MEM 0x00000100
82226 #define RIO_RESOURCE_DOORBELL 0x00000200
82227diff --git a/include/linux/rmap.h b/include/linux/rmap.h
82228index b66c211..13d2915 100644
82229--- a/include/linux/rmap.h
82230+++ b/include/linux/rmap.h
82231@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
82232 void anon_vma_init(void); /* create anon_vma_cachep */
82233 int anon_vma_prepare(struct vm_area_struct *);
82234 void unlink_anon_vmas(struct vm_area_struct *);
82235-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82236-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82237+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82238+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82239
82240 static inline void anon_vma_merge(struct vm_area_struct *vma,
82241 struct vm_area_struct *next)
82242diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
82243index a964f72..b475afb 100644
82244--- a/include/linux/scatterlist.h
82245+++ b/include/linux/scatterlist.h
82246@@ -1,6 +1,7 @@
82247 #ifndef _LINUX_SCATTERLIST_H
82248 #define _LINUX_SCATTERLIST_H
82249
82250+#include <linux/sched.h>
82251 #include <linux/string.h>
82252 #include <linux/bug.h>
82253 #include <linux/mm.h>
82254@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
82255 #ifdef CONFIG_DEBUG_SG
82256 BUG_ON(!virt_addr_valid(buf));
82257 #endif
82258+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82259+ if (object_starts_on_stack(buf)) {
82260+ void *adjbuf = buf - current->stack + current->lowmem_stack;
82261+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
82262+ } else
82263+#endif
82264 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
82265 }
82266
82267diff --git a/include/linux/sched.h b/include/linux/sched.h
82268index 221b2bd..e2e5f82 100644
82269--- a/include/linux/sched.h
82270+++ b/include/linux/sched.h
82271@@ -131,6 +131,7 @@ struct fs_struct;
82272 struct perf_event_context;
82273 struct blk_plug;
82274 struct filename;
82275+struct linux_binprm;
82276
82277 #define VMACACHE_BITS 2
82278 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
82279@@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
82280 extern int in_sched_functions(unsigned long addr);
82281
82282 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82283-extern signed long schedule_timeout(signed long timeout);
82284+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82285 extern signed long schedule_timeout_interruptible(signed long timeout);
82286 extern signed long schedule_timeout_killable(signed long timeout);
82287 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82288@@ -391,6 +392,19 @@ struct nsproxy;
82289 struct user_namespace;
82290
82291 #ifdef CONFIG_MMU
82292+
82293+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82294+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82295+#else
82296+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82297+{
82298+ return 0;
82299+}
82300+#endif
82301+
82302+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82303+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82304+
82305 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82306 extern unsigned long
82307 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82308@@ -688,6 +702,17 @@ struct signal_struct {
82309 #ifdef CONFIG_TASKSTATS
82310 struct taskstats *stats;
82311 #endif
82312+
82313+#ifdef CONFIG_GRKERNSEC
82314+ u32 curr_ip;
82315+ u32 saved_ip;
82316+ u32 gr_saddr;
82317+ u32 gr_daddr;
82318+ u16 gr_sport;
82319+ u16 gr_dport;
82320+ u8 used_accept:1;
82321+#endif
82322+
82323 #ifdef CONFIG_AUDIT
82324 unsigned audit_tty;
82325 unsigned audit_tty_log_passwd;
82326@@ -714,7 +739,7 @@ struct signal_struct {
82327 struct mutex cred_guard_mutex; /* guard against foreign influences on
82328 * credential calculations
82329 * (notably. ptrace) */
82330-};
82331+} __randomize_layout;
82332
82333 /*
82334 * Bits in flags field of signal_struct.
82335@@ -768,6 +793,14 @@ struct user_struct {
82336 struct key *session_keyring; /* UID's default session keyring */
82337 #endif
82338
82339+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82340+ unsigned char kernel_banned;
82341+#endif
82342+#ifdef CONFIG_GRKERNSEC_BRUTE
82343+ unsigned char suid_banned;
82344+ unsigned long suid_ban_expires;
82345+#endif
82346+
82347 /* Hash table maintenance information */
82348 struct hlist_node uidhash_node;
82349 kuid_t uid;
82350@@ -775,7 +808,7 @@ struct user_struct {
82351 #ifdef CONFIG_PERF_EVENTS
82352 atomic_long_t locked_vm;
82353 #endif
82354-};
82355+} __randomize_layout;
82356
82357 extern int uids_sysfs_init(void);
82358
82359@@ -1179,6 +1212,9 @@ enum perf_event_task_context {
82360 struct task_struct {
82361 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
82362 void *stack;
82363+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82364+ void *lowmem_stack;
82365+#endif
82366 atomic_t usage;
82367 unsigned int flags; /* per process flags, defined below */
82368 unsigned int ptrace;
82369@@ -1304,8 +1340,8 @@ struct task_struct {
82370 struct list_head thread_node;
82371
82372 struct completion *vfork_done; /* for vfork() */
82373- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82374- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82375+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82376+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82377
82378 cputime_t utime, stime, utimescaled, stimescaled;
82379 cputime_t gtime;
82380@@ -1330,11 +1366,6 @@ struct task_struct {
82381 struct task_cputime cputime_expires;
82382 struct list_head cpu_timers[3];
82383
82384-/* process credentials */
82385- const struct cred __rcu *real_cred; /* objective and real subjective task
82386- * credentials (COW) */
82387- const struct cred __rcu *cred; /* effective (overridable) subjective task
82388- * credentials (COW) */
82389 char comm[TASK_COMM_LEN]; /* executable name excluding path
82390 - access with [gs]et_task_comm (which lock
82391 it with task_lock())
82392@@ -1351,6 +1382,10 @@ struct task_struct {
82393 #endif
82394 /* CPU-specific state of this task */
82395 struct thread_struct thread;
82396+/* thread_info moved to task_struct */
82397+#ifdef CONFIG_X86
82398+ struct thread_info tinfo;
82399+#endif
82400 /* filesystem information */
82401 struct fs_struct *fs;
82402 /* open file information */
82403@@ -1427,6 +1462,10 @@ struct task_struct {
82404 gfp_t lockdep_reclaim_gfp;
82405 #endif
82406
82407+/* process credentials */
82408+ const struct cred __rcu *real_cred; /* objective and real subjective task
82409+ * credentials (COW) */
82410+
82411 /* journalling filesystem info */
82412 void *journal_info;
82413
82414@@ -1465,6 +1504,10 @@ struct task_struct {
82415 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82416 struct list_head cg_list;
82417 #endif
82418+
82419+ const struct cred __rcu *cred; /* effective (overridable) subjective task
82420+ * credentials (COW) */
82421+
82422 #ifdef CONFIG_FUTEX
82423 struct robust_list_head __user *robust_list;
82424 #ifdef CONFIG_COMPAT
82425@@ -1610,7 +1653,78 @@ struct task_struct {
82426 unsigned int sequential_io;
82427 unsigned int sequential_io_avg;
82428 #endif
82429-};
82430+
82431+#ifdef CONFIG_GRKERNSEC
82432+ /* grsecurity */
82433+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82434+ u64 exec_id;
82435+#endif
82436+#ifdef CONFIG_GRKERNSEC_SETXID
82437+ const struct cred *delayed_cred;
82438+#endif
82439+ struct dentry *gr_chroot_dentry;
82440+ struct acl_subject_label *acl;
82441+ struct acl_subject_label *tmpacl;
82442+ struct acl_role_label *role;
82443+ struct file *exec_file;
82444+ unsigned long brute_expires;
82445+ u16 acl_role_id;
82446+ u8 inherited;
82447+ /* is this the task that authenticated to the special role */
82448+ u8 acl_sp_role;
82449+ u8 is_writable;
82450+ u8 brute;
82451+ u8 gr_is_chrooted;
82452+#endif
82453+
82454+} __randomize_layout;
82455+
82456+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82457+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82458+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82459+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82460+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82461+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82462+
82463+#ifdef CONFIG_PAX_SOFTMODE
82464+extern int pax_softmode;
82465+#endif
82466+
82467+extern int pax_check_flags(unsigned long *);
82468+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82469+
82470+/* if tsk != current then task_lock must be held on it */
82471+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82472+static inline unsigned long pax_get_flags(struct task_struct *tsk)
82473+{
82474+ if (likely(tsk->mm))
82475+ return tsk->mm->pax_flags;
82476+ else
82477+ return 0UL;
82478+}
82479+
82480+/* if tsk != current then task_lock must be held on it */
82481+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82482+{
82483+ if (likely(tsk->mm)) {
82484+ tsk->mm->pax_flags = flags;
82485+ return 0;
82486+ }
82487+ return -EINVAL;
82488+}
82489+#endif
82490+
82491+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82492+extern void pax_set_initial_flags(struct linux_binprm *bprm);
82493+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82494+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82495+#endif
82496+
82497+struct path;
82498+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82499+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82500+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82501+extern void pax_report_refcount_overflow(struct pt_regs *regs);
82502
82503 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82504 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82505@@ -1692,7 +1806,7 @@ struct pid_namespace;
82506 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82507 struct pid_namespace *ns);
82508
82509-static inline pid_t task_pid_nr(struct task_struct *tsk)
82510+static inline pid_t task_pid_nr(const struct task_struct *tsk)
82511 {
82512 return tsk->pid;
82513 }
82514@@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
82515
82516 extern void sched_clock_init(void);
82517
82518+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82519+static inline void populate_stack(void)
82520+{
82521+ struct task_struct *curtask = current;
82522+ int c;
82523+ int *ptr = curtask->stack;
82524+ int *end = curtask->stack + THREAD_SIZE;
82525+
82526+ while (ptr < end) {
82527+ c = *(volatile int *)ptr;
82528+ ptr += PAGE_SIZE/sizeof(int);
82529+ }
82530+}
82531+#else
82532+static inline void populate_stack(void)
82533+{
82534+}
82535+#endif
82536+
82537 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82538 static inline void sched_clock_tick(void)
82539 {
82540@@ -2172,7 +2305,9 @@ void yield(void);
82541 extern struct exec_domain default_exec_domain;
82542
82543 union thread_union {
82544+#ifndef CONFIG_X86
82545 struct thread_info thread_info;
82546+#endif
82547 unsigned long stack[THREAD_SIZE/sizeof(long)];
82548 };
82549
82550@@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82551 */
82552
82553 extern struct task_struct *find_task_by_vpid(pid_t nr);
82554+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82555 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82556 struct pid_namespace *ns);
82557
82558@@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82559 extern void exit_itimers(struct signal_struct *);
82560 extern void flush_itimer_signals(void);
82561
82562-extern void do_group_exit(int);
82563+extern __noreturn void do_group_exit(int);
82564
82565 extern int allow_signal(int);
82566 extern int disallow_signal(int);
82567@@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82568
82569 #endif
82570
82571-static inline int object_is_on_stack(void *obj)
82572+static inline int object_starts_on_stack(const void *obj)
82573 {
82574- void *stack = task_stack_page(current);
82575+ const void *stack = task_stack_page(current);
82576
82577 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82578 }
82579diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82580index 8045a55..c959cd5 100644
82581--- a/include/linux/sched/sysctl.h
82582+++ b/include/linux/sched/sysctl.h
82583@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82584 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82585
82586 extern int sysctl_max_map_count;
82587+extern unsigned long sysctl_heap_stack_gap;
82588
82589 extern unsigned int sysctl_sched_latency;
82590 extern unsigned int sysctl_sched_min_granularity;
82591diff --git a/include/linux/security.h b/include/linux/security.h
82592index 6478ce3..5e6ad6e 100644
82593--- a/include/linux/security.h
82594+++ b/include/linux/security.h
82595@@ -27,6 +27,7 @@
82596 #include <linux/slab.h>
82597 #include <linux/err.h>
82598 #include <linux/string.h>
82599+#include <linux/grsecurity.h>
82600
82601 struct linux_binprm;
82602 struct cred;
82603@@ -116,8 +117,6 @@ struct seq_file;
82604
82605 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82606
82607-void reset_security_ops(void);
82608-
82609 #ifdef CONFIG_MMU
82610 extern unsigned long mmap_min_addr;
82611 extern unsigned long dac_mmap_min_addr;
82612@@ -1719,7 +1718,7 @@ struct security_operations {
82613 struct audit_context *actx);
82614 void (*audit_rule_free) (void *lsmrule);
82615 #endif /* CONFIG_AUDIT */
82616-};
82617+} __randomize_layout;
82618
82619 /* prototypes */
82620 extern int security_init(void);
82621diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82622index dc368b8..e895209 100644
82623--- a/include/linux/semaphore.h
82624+++ b/include/linux/semaphore.h
82625@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82626 }
82627
82628 extern void down(struct semaphore *sem);
82629-extern int __must_check down_interruptible(struct semaphore *sem);
82630+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82631 extern int __must_check down_killable(struct semaphore *sem);
82632 extern int __must_check down_trylock(struct semaphore *sem);
82633 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82634diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82635index 52e0097..383f21d 100644
82636--- a/include/linux/seq_file.h
82637+++ b/include/linux/seq_file.h
82638@@ -27,6 +27,9 @@ struct seq_file {
82639 struct mutex lock;
82640 const struct seq_operations *op;
82641 int poll_event;
82642+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82643+ u64 exec_id;
82644+#endif
82645 #ifdef CONFIG_USER_NS
82646 struct user_namespace *user_ns;
82647 #endif
82648@@ -39,6 +42,7 @@ struct seq_operations {
82649 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82650 int (*show) (struct seq_file *m, void *v);
82651 };
82652+typedef struct seq_operations __no_const seq_operations_no_const;
82653
82654 #define SEQ_SKIP 1
82655
82656@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82657
82658 char *mangle_path(char *s, const char *p, const char *esc);
82659 int seq_open(struct file *, const struct seq_operations *);
82660+int seq_open_restrict(struct file *, const struct seq_operations *);
82661 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82662 loff_t seq_lseek(struct file *, loff_t, int);
82663 int seq_release(struct inode *, struct file *);
82664@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82665 }
82666
82667 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82668+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82669 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82670 int single_release(struct inode *, struct file *);
82671 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82672diff --git a/include/linux/shm.h b/include/linux/shm.h
82673index 1e2cd2e..0288750 100644
82674--- a/include/linux/shm.h
82675+++ b/include/linux/shm.h
82676@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82677
82678 /* The task created the shm object. NULL if the task is dead. */
82679 struct task_struct *shm_creator;
82680+#ifdef CONFIG_GRKERNSEC
82681+ time_t shm_createtime;
82682+ pid_t shm_lapid;
82683+#endif
82684 };
82685
82686 /* shm_mode upper byte flags */
82687diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82688index 08074a8..e2ae280 100644
82689--- a/include/linux/skbuff.h
82690+++ b/include/linux/skbuff.h
82691@@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82692 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82693 int node);
82694 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82695-static inline struct sk_buff *alloc_skb(unsigned int size,
82696+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82697 gfp_t priority)
82698 {
82699 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82700@@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82701 return skb->inner_transport_header - skb->inner_network_header;
82702 }
82703
82704-static inline int skb_network_offset(const struct sk_buff *skb)
82705+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82706 {
82707 return skb_network_header(skb) - skb->data;
82708 }
82709@@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82710 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82711 */
82712 #ifndef NET_SKB_PAD
82713-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82714+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82715 #endif
82716
82717 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82718@@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82719 int *err);
82720 unsigned int datagram_poll(struct file *file, struct socket *sock,
82721 struct poll_table_struct *wait);
82722-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82723+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82724 struct iovec *to, int size);
82725 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82726 struct iovec *iov);
82727@@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82728 nf_bridge_put(skb->nf_bridge);
82729 skb->nf_bridge = NULL;
82730 #endif
82731+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82732+ skb->nf_trace = 0;
82733+#endif
82734 }
82735
82736 static inline void nf_reset_trace(struct sk_buff *skb)
82737diff --git a/include/linux/slab.h b/include/linux/slab.h
82738index 307bfbe..a999cf3 100644
82739--- a/include/linux/slab.h
82740+++ b/include/linux/slab.h
82741@@ -14,15 +14,29 @@
82742 #include <linux/gfp.h>
82743 #include <linux/types.h>
82744 #include <linux/workqueue.h>
82745-
82746+#include <linux/err.h>
82747
82748 /*
82749 * Flags to pass to kmem_cache_create().
82750 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82751 */
82752 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82753+
82754+#ifdef CONFIG_PAX_USERCOPY_SLABS
82755+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82756+#else
82757+#define SLAB_USERCOPY 0x00000000UL
82758+#endif
82759+
82760 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82761 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82762+
82763+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82764+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82765+#else
82766+#define SLAB_NO_SANITIZE 0x00000000UL
82767+#endif
82768+
82769 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82770 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82771 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82772@@ -98,10 +112,13 @@
82773 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82774 * Both make kfree a no-op.
82775 */
82776-#define ZERO_SIZE_PTR ((void *)16)
82777+#define ZERO_SIZE_PTR \
82778+({ \
82779+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82780+ (void *)(-MAX_ERRNO-1L); \
82781+})
82782
82783-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82784- (unsigned long)ZERO_SIZE_PTR)
82785+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82786
82787 #include <linux/kmemleak.h>
82788
82789@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82790 void kfree(const void *);
82791 void kzfree(const void *);
82792 size_t ksize(const void *);
82793+const char *check_heap_object(const void *ptr, unsigned long n);
82794+bool is_usercopy_object(const void *ptr);
82795
82796 /*
82797 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82798@@ -174,7 +193,7 @@ struct kmem_cache {
82799 unsigned int align; /* Alignment as calculated */
82800 unsigned long flags; /* Active flags on the slab */
82801 const char *name; /* Slab name for sysfs */
82802- int refcount; /* Use counter */
82803+ atomic_t refcount; /* Use counter */
82804 void (*ctor)(void *); /* Called on object slot creation */
82805 struct list_head list; /* List of all slab caches on the system */
82806 };
82807@@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82808 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82809 #endif
82810
82811+#ifdef CONFIG_PAX_USERCOPY_SLABS
82812+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82813+#endif
82814+
82815 /*
82816 * Figure out which kmalloc slab an allocation of a certain size
82817 * belongs to.
82818@@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82819 * 2 = 120 .. 192 bytes
82820 * n = 2^(n-1) .. 2^n -1
82821 */
82822-static __always_inline int kmalloc_index(size_t size)
82823+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82824 {
82825 if (!size)
82826 return 0;
82827@@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
82828 }
82829 #endif /* !CONFIG_SLOB */
82830
82831-void *__kmalloc(size_t size, gfp_t flags);
82832+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82833 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82834
82835 #ifdef CONFIG_NUMA
82836-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82837+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82838 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82839 #else
82840 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82841diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82842index 8235dfb..47ce586 100644
82843--- a/include/linux/slab_def.h
82844+++ b/include/linux/slab_def.h
82845@@ -38,7 +38,7 @@ struct kmem_cache {
82846 /* 4) cache creation/removal */
82847 const char *name;
82848 struct list_head list;
82849- int refcount;
82850+ atomic_t refcount;
82851 int object_size;
82852 int align;
82853
82854@@ -54,10 +54,14 @@ struct kmem_cache {
82855 unsigned long node_allocs;
82856 unsigned long node_frees;
82857 unsigned long node_overflow;
82858- atomic_t allochit;
82859- atomic_t allocmiss;
82860- atomic_t freehit;
82861- atomic_t freemiss;
82862+ atomic_unchecked_t allochit;
82863+ atomic_unchecked_t allocmiss;
82864+ atomic_unchecked_t freehit;
82865+ atomic_unchecked_t freemiss;
82866+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82867+ atomic_unchecked_t sanitized;
82868+ atomic_unchecked_t not_sanitized;
82869+#endif
82870
82871 /*
82872 * If debugging is enabled, then the allocator can add additional
82873diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82874index d82abd4..408c3a0 100644
82875--- a/include/linux/slub_def.h
82876+++ b/include/linux/slub_def.h
82877@@ -74,7 +74,7 @@ struct kmem_cache {
82878 struct kmem_cache_order_objects max;
82879 struct kmem_cache_order_objects min;
82880 gfp_t allocflags; /* gfp flags to use on each alloc */
82881- int refcount; /* Refcount for slab cache destroy */
82882+ atomic_t refcount; /* Refcount for slab cache destroy */
82883 void (*ctor)(void *);
82884 int inuse; /* Offset to metadata */
82885 int align; /* Alignment */
82886diff --git a/include/linux/smp.h b/include/linux/smp.h
82887index 633f5ed..6c3dc3f 100644
82888--- a/include/linux/smp.h
82889+++ b/include/linux/smp.h
82890@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
82891 #endif
82892
82893 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82894+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82895 #define put_cpu() preempt_enable()
82896+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82897
82898 /*
82899 * Callback to arch code if there's nosmp or maxcpus=0 on the
82900diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82901index 46cca4c..3323536 100644
82902--- a/include/linux/sock_diag.h
82903+++ b/include/linux/sock_diag.h
82904@@ -11,7 +11,7 @@ struct sock;
82905 struct sock_diag_handler {
82906 __u8 family;
82907 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82908-};
82909+} __do_const;
82910
82911 int sock_diag_register(const struct sock_diag_handler *h);
82912 void sock_diag_unregister(const struct sock_diag_handler *h);
82913diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82914index 680f9a3..f13aeb0 100644
82915--- a/include/linux/sonet.h
82916+++ b/include/linux/sonet.h
82917@@ -7,7 +7,7 @@
82918 #include <uapi/linux/sonet.h>
82919
82920 struct k_sonet_stats {
82921-#define __HANDLE_ITEM(i) atomic_t i
82922+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82923 __SONET_ITEMS
82924 #undef __HANDLE_ITEM
82925 };
82926diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82927index 07d8e53..dc934c9 100644
82928--- a/include/linux/sunrpc/addr.h
82929+++ b/include/linux/sunrpc/addr.h
82930@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82931 {
82932 switch (sap->sa_family) {
82933 case AF_INET:
82934- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82935+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82936 case AF_INET6:
82937- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82938+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82939 }
82940 return 0;
82941 }
82942@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82943 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82944 const struct sockaddr *src)
82945 {
82946- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82947+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82948 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82949
82950 dsin->sin_family = ssin->sin_family;
82951@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82952 if (sa->sa_family != AF_INET6)
82953 return 0;
82954
82955- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82956+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82957 }
82958
82959 #endif /* _LINUX_SUNRPC_ADDR_H */
82960diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82961index 70736b9..37f33db 100644
82962--- a/include/linux/sunrpc/clnt.h
82963+++ b/include/linux/sunrpc/clnt.h
82964@@ -97,7 +97,7 @@ struct rpc_procinfo {
82965 unsigned int p_timer; /* Which RTT timer to use */
82966 u32 p_statidx; /* Which procedure to account */
82967 const char * p_name; /* name of procedure */
82968-};
82969+} __do_const;
82970
82971 #ifdef __KERNEL__
82972
82973diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82974index 04e7632..2e2a8a3 100644
82975--- a/include/linux/sunrpc/svc.h
82976+++ b/include/linux/sunrpc/svc.h
82977@@ -412,7 +412,7 @@ struct svc_procedure {
82978 unsigned int pc_count; /* call count */
82979 unsigned int pc_cachetype; /* cache info (NFS) */
82980 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82981-};
82982+} __do_const;
82983
82984 /*
82985 * Function prototypes.
82986diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82987index 0b8e3e6..33e0a01 100644
82988--- a/include/linux/sunrpc/svc_rdma.h
82989+++ b/include/linux/sunrpc/svc_rdma.h
82990@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82991 extern unsigned int svcrdma_max_requests;
82992 extern unsigned int svcrdma_max_req_size;
82993
82994-extern atomic_t rdma_stat_recv;
82995-extern atomic_t rdma_stat_read;
82996-extern atomic_t rdma_stat_write;
82997-extern atomic_t rdma_stat_sq_starve;
82998-extern atomic_t rdma_stat_rq_starve;
82999-extern atomic_t rdma_stat_rq_poll;
83000-extern atomic_t rdma_stat_rq_prod;
83001-extern atomic_t rdma_stat_sq_poll;
83002-extern atomic_t rdma_stat_sq_prod;
83003+extern atomic_unchecked_t rdma_stat_recv;
83004+extern atomic_unchecked_t rdma_stat_read;
83005+extern atomic_unchecked_t rdma_stat_write;
83006+extern atomic_unchecked_t rdma_stat_sq_starve;
83007+extern atomic_unchecked_t rdma_stat_rq_starve;
83008+extern atomic_unchecked_t rdma_stat_rq_poll;
83009+extern atomic_unchecked_t rdma_stat_rq_prod;
83010+extern atomic_unchecked_t rdma_stat_sq_poll;
83011+extern atomic_unchecked_t rdma_stat_sq_prod;
83012
83013 #define RPCRDMA_VERSION 1
83014
83015diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
83016index 8d71d65..f79586e 100644
83017--- a/include/linux/sunrpc/svcauth.h
83018+++ b/include/linux/sunrpc/svcauth.h
83019@@ -120,7 +120,7 @@ struct auth_ops {
83020 int (*release)(struct svc_rqst *rq);
83021 void (*domain_release)(struct auth_domain *);
83022 int (*set_client)(struct svc_rqst *rq);
83023-};
83024+} __do_const;
83025
83026 #define SVC_GARBAGE 1
83027 #define SVC_SYSERR 2
83028diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
83029index a5ffd32..0935dea 100644
83030--- a/include/linux/swiotlb.h
83031+++ b/include/linux/swiotlb.h
83032@@ -60,7 +60,8 @@ extern void
83033
83034 extern void
83035 swiotlb_free_coherent(struct device *hwdev, size_t size,
83036- void *vaddr, dma_addr_t dma_handle);
83037+ void *vaddr, dma_addr_t dma_handle,
83038+ struct dma_attrs *attrs);
83039
83040 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
83041 unsigned long offset, size_t size,
83042diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
83043index a4a0588..752870e 100644
83044--- a/include/linux/syscalls.h
83045+++ b/include/linux/syscalls.h
83046@@ -98,10 +98,16 @@ struct sigaltstack;
83047 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
83048
83049 #define __SC_DECL(t, a) t a
83050+#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))
83051 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
83052 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
83053 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
83054-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
83055+#define __SC_LONG(t, a) __typeof( \
83056+ __builtin_choose_expr( \
83057+ sizeof(t) > sizeof(int), \
83058+ (t) 0, \
83059+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
83060+ )) a
83061 #define __SC_CAST(t, a) (t) a
83062 #define __SC_ARGS(t, a) a
83063 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
83064@@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
83065 asmlinkage long sys_fsync(unsigned int fd);
83066 asmlinkage long sys_fdatasync(unsigned int fd);
83067 asmlinkage long sys_bdflush(int func, long data);
83068-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
83069- char __user *type, unsigned long flags,
83070+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
83071+ const char __user *type, unsigned long flags,
83072 void __user *data);
83073-asmlinkage long sys_umount(char __user *name, int flags);
83074-asmlinkage long sys_oldumount(char __user *name);
83075+asmlinkage long sys_umount(const char __user *name, int flags);
83076+asmlinkage long sys_oldumount(const char __user *name);
83077 asmlinkage long sys_truncate(const char __user *path, long length);
83078 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
83079 asmlinkage long sys_stat(const char __user *filename,
83080@@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
83081 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
83082 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
83083 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
83084- struct sockaddr __user *, int);
83085+ struct sockaddr __user *, int) __intentional_overflow(0);
83086 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
83087 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
83088 unsigned int vlen, unsigned flags);
83089diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
83090index 27b3b0b..e093dd9 100644
83091--- a/include/linux/syscore_ops.h
83092+++ b/include/linux/syscore_ops.h
83093@@ -16,7 +16,7 @@ struct syscore_ops {
83094 int (*suspend)(void);
83095 void (*resume)(void);
83096 void (*shutdown)(void);
83097-};
83098+} __do_const;
83099
83100 extern void register_syscore_ops(struct syscore_ops *ops);
83101 extern void unregister_syscore_ops(struct syscore_ops *ops);
83102diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
83103index 14a8ff2..fa95f3a 100644
83104--- a/include/linux/sysctl.h
83105+++ b/include/linux/sysctl.h
83106@@ -34,13 +34,13 @@ struct ctl_table_root;
83107 struct ctl_table_header;
83108 struct ctl_dir;
83109
83110-typedef struct ctl_table ctl_table;
83111-
83112 typedef int proc_handler (struct ctl_table *ctl, int write,
83113 void __user *buffer, size_t *lenp, loff_t *ppos);
83114
83115 extern int proc_dostring(struct ctl_table *, int,
83116 void __user *, size_t *, loff_t *);
83117+extern int proc_dostring_modpriv(struct ctl_table *, int,
83118+ void __user *, size_t *, loff_t *);
83119 extern int proc_dointvec(struct ctl_table *, int,
83120 void __user *, size_t *, loff_t *);
83121 extern int proc_dointvec_minmax(struct ctl_table *, int,
83122@@ -115,7 +115,9 @@ struct ctl_table
83123 struct ctl_table_poll *poll;
83124 void *extra1;
83125 void *extra2;
83126-};
83127+} __do_const __randomize_layout;
83128+typedef struct ctl_table __no_const ctl_table_no_const;
83129+typedef struct ctl_table ctl_table;
83130
83131 struct ctl_node {
83132 struct rb_node node;
83133diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
83134index 5ffaa34..fe3e31c 100644
83135--- a/include/linux/sysfs.h
83136+++ b/include/linux/sysfs.h
83137@@ -34,7 +34,8 @@ struct attribute {
83138 struct lock_class_key *key;
83139 struct lock_class_key skey;
83140 #endif
83141-};
83142+} __do_const;
83143+typedef struct attribute __no_const attribute_no_const;
83144
83145 /**
83146 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
83147@@ -63,7 +64,8 @@ struct attribute_group {
83148 struct attribute *, int);
83149 struct attribute **attrs;
83150 struct bin_attribute **bin_attrs;
83151-};
83152+} __do_const;
83153+typedef struct attribute_group __no_const attribute_group_no_const;
83154
83155 /**
83156 * Use these macros to make defining attributes easier. See include/linux/device.h
83157@@ -128,7 +130,8 @@ struct bin_attribute {
83158 char *, loff_t, size_t);
83159 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
83160 struct vm_area_struct *vma);
83161-};
83162+} __do_const;
83163+typedef struct bin_attribute __no_const bin_attribute_no_const;
83164
83165 /**
83166 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
83167diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
83168index 387fa7d..3fcde6b 100644
83169--- a/include/linux/sysrq.h
83170+++ b/include/linux/sysrq.h
83171@@ -16,6 +16,7 @@
83172
83173 #include <linux/errno.h>
83174 #include <linux/types.h>
83175+#include <linux/compiler.h>
83176
83177 /* Possible values of bitmask for enabling sysrq functions */
83178 /* 0x0001 is reserved for enable everything */
83179@@ -33,7 +34,7 @@ struct sysrq_key_op {
83180 char *help_msg;
83181 char *action_msg;
83182 int enable_mask;
83183-};
83184+} __do_const;
83185
83186 #ifdef CONFIG_MAGIC_SYSRQ
83187
83188diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
83189index fddbe20..a0e76ab 100644
83190--- a/include/linux/thread_info.h
83191+++ b/include/linux/thread_info.h
83192@@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
83193 #error "no set_restore_sigmask() provided and default one won't work"
83194 #endif
83195
83196+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
83197+
83198+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
83199+{
83200+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
83201+}
83202+
83203 #endif /* __KERNEL__ */
83204
83205 #endif /* _LINUX_THREAD_INFO_H */
83206diff --git a/include/linux/tty.h b/include/linux/tty.h
83207index 1c3316a..ae83b9f 100644
83208--- a/include/linux/tty.h
83209+++ b/include/linux/tty.h
83210@@ -202,7 +202,7 @@ struct tty_port {
83211 const struct tty_port_operations *ops; /* Port operations */
83212 spinlock_t lock; /* Lock protecting tty field */
83213 int blocked_open; /* Waiting to open */
83214- int count; /* Usage count */
83215+ atomic_t count; /* Usage count */
83216 wait_queue_head_t open_wait; /* Open waiters */
83217 wait_queue_head_t close_wait; /* Close waiters */
83218 wait_queue_head_t delta_msr_wait; /* Modem status change */
83219@@ -284,7 +284,7 @@ struct tty_struct {
83220 /* If the tty has a pending do_SAK, queue it here - akpm */
83221 struct work_struct SAK_work;
83222 struct tty_port *port;
83223-};
83224+} __randomize_layout;
83225
83226 /* Each of a tty's open files has private_data pointing to tty_file_private */
83227 struct tty_file_private {
83228@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
83229 struct tty_struct *tty, struct file *filp);
83230 static inline int tty_port_users(struct tty_port *port)
83231 {
83232- return port->count + port->blocked_open;
83233+ return atomic_read(&port->count) + port->blocked_open;
83234 }
83235
83236 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
83237diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
83238index 756a609..89db85e 100644
83239--- a/include/linux/tty_driver.h
83240+++ b/include/linux/tty_driver.h
83241@@ -285,7 +285,7 @@ struct tty_operations {
83242 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
83243 #endif
83244 const struct file_operations *proc_fops;
83245-};
83246+} __do_const __randomize_layout;
83247
83248 struct tty_driver {
83249 int magic; /* magic number for this structure */
83250@@ -319,7 +319,7 @@ struct tty_driver {
83251
83252 const struct tty_operations *ops;
83253 struct list_head tty_drivers;
83254-};
83255+} __randomize_layout;
83256
83257 extern struct list_head tty_drivers;
83258
83259diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
83260index add26da..22c00bef 100644
83261--- a/include/linux/tty_ldisc.h
83262+++ b/include/linux/tty_ldisc.h
83263@@ -212,7 +212,7 @@ struct tty_ldisc_ops {
83264
83265 struct module *owner;
83266
83267- int refcount;
83268+ atomic_t refcount;
83269 };
83270
83271 struct tty_ldisc {
83272diff --git a/include/linux/types.h b/include/linux/types.h
83273index 4d118ba..c3ee9bf 100644
83274--- a/include/linux/types.h
83275+++ b/include/linux/types.h
83276@@ -176,10 +176,26 @@ typedef struct {
83277 int counter;
83278 } atomic_t;
83279
83280+#ifdef CONFIG_PAX_REFCOUNT
83281+typedef struct {
83282+ int counter;
83283+} atomic_unchecked_t;
83284+#else
83285+typedef atomic_t atomic_unchecked_t;
83286+#endif
83287+
83288 #ifdef CONFIG_64BIT
83289 typedef struct {
83290 long counter;
83291 } atomic64_t;
83292+
83293+#ifdef CONFIG_PAX_REFCOUNT
83294+typedef struct {
83295+ long counter;
83296+} atomic64_unchecked_t;
83297+#else
83298+typedef atomic64_t atomic64_unchecked_t;
83299+#endif
83300 #endif
83301
83302 struct list_head {
83303diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83304index ecd3319..8a36ded 100644
83305--- a/include/linux/uaccess.h
83306+++ b/include/linux/uaccess.h
83307@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83308 long ret; \
83309 mm_segment_t old_fs = get_fs(); \
83310 \
83311- set_fs(KERNEL_DS); \
83312 pagefault_disable(); \
83313- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83314- pagefault_enable(); \
83315+ set_fs(KERNEL_DS); \
83316+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83317 set_fs(old_fs); \
83318+ pagefault_enable(); \
83319 ret; \
83320 })
83321
83322diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83323index 2d1f9b6..d7a9fce 100644
83324--- a/include/linux/uidgid.h
83325+++ b/include/linux/uidgid.h
83326@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83327
83328 #endif /* CONFIG_USER_NS */
83329
83330+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83331+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83332+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83333+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83334+
83335 #endif /* _LINUX_UIDGID_H */
83336diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83337index 99c1b4d..562e6f3 100644
83338--- a/include/linux/unaligned/access_ok.h
83339+++ b/include/linux/unaligned/access_ok.h
83340@@ -4,34 +4,34 @@
83341 #include <linux/kernel.h>
83342 #include <asm/byteorder.h>
83343
83344-static inline u16 get_unaligned_le16(const void *p)
83345+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83346 {
83347- return le16_to_cpup((__le16 *)p);
83348+ return le16_to_cpup((const __le16 *)p);
83349 }
83350
83351-static inline u32 get_unaligned_le32(const void *p)
83352+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83353 {
83354- return le32_to_cpup((__le32 *)p);
83355+ return le32_to_cpup((const __le32 *)p);
83356 }
83357
83358-static inline u64 get_unaligned_le64(const void *p)
83359+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83360 {
83361- return le64_to_cpup((__le64 *)p);
83362+ return le64_to_cpup((const __le64 *)p);
83363 }
83364
83365-static inline u16 get_unaligned_be16(const void *p)
83366+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83367 {
83368- return be16_to_cpup((__be16 *)p);
83369+ return be16_to_cpup((const __be16 *)p);
83370 }
83371
83372-static inline u32 get_unaligned_be32(const void *p)
83373+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83374 {
83375- return be32_to_cpup((__be32 *)p);
83376+ return be32_to_cpup((const __be32 *)p);
83377 }
83378
83379-static inline u64 get_unaligned_be64(const void *p)
83380+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83381 {
83382- return be64_to_cpup((__be64 *)p);
83383+ return be64_to_cpup((const __be64 *)p);
83384 }
83385
83386 static inline void put_unaligned_le16(u16 val, void *p)
83387diff --git a/include/linux/usb.h b/include/linux/usb.h
83388index 6b7ec37..4428419 100644
83389--- a/include/linux/usb.h
83390+++ b/include/linux/usb.h
83391@@ -569,7 +569,7 @@ struct usb_device {
83392 int maxchild;
83393
83394 u32 quirks;
83395- atomic_t urbnum;
83396+ atomic_unchecked_t urbnum;
83397
83398 unsigned long active_duration;
83399
83400@@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83401
83402 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83403 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83404- void *data, __u16 size, int timeout);
83405+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
83406 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83407 void *data, int len, int *actual_length, int timeout);
83408 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83409diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83410index e452ba6..78f8e80 100644
83411--- a/include/linux/usb/renesas_usbhs.h
83412+++ b/include/linux/usb/renesas_usbhs.h
83413@@ -39,7 +39,7 @@ enum {
83414 */
83415 struct renesas_usbhs_driver_callback {
83416 int (*notify_hotplug)(struct platform_device *pdev);
83417-};
83418+} __no_const;
83419
83420 /*
83421 * callback functions for platform
83422diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83423index 4836ba3..603f6ee 100644
83424--- a/include/linux/user_namespace.h
83425+++ b/include/linux/user_namespace.h
83426@@ -33,7 +33,7 @@ struct user_namespace {
83427 struct key *persistent_keyring_register;
83428 struct rw_semaphore persistent_keyring_register_sem;
83429 #endif
83430-};
83431+} __randomize_layout;
83432
83433 extern struct user_namespace init_user_ns;
83434
83435diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83436index 239e277..22a5cf5 100644
83437--- a/include/linux/utsname.h
83438+++ b/include/linux/utsname.h
83439@@ -24,7 +24,7 @@ struct uts_namespace {
83440 struct new_utsname name;
83441 struct user_namespace *user_ns;
83442 unsigned int proc_inum;
83443-};
83444+} __randomize_layout;
83445 extern struct uts_namespace init_uts_ns;
83446
83447 #ifdef CONFIG_UTS_NS
83448diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83449index 6f8fbcf..4efc177 100644
83450--- a/include/linux/vermagic.h
83451+++ b/include/linux/vermagic.h
83452@@ -25,9 +25,42 @@
83453 #define MODULE_ARCH_VERMAGIC ""
83454 #endif
83455
83456+#ifdef CONFIG_PAX_REFCOUNT
83457+#define MODULE_PAX_REFCOUNT "REFCOUNT "
83458+#else
83459+#define MODULE_PAX_REFCOUNT ""
83460+#endif
83461+
83462+#ifdef CONSTIFY_PLUGIN
83463+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83464+#else
83465+#define MODULE_CONSTIFY_PLUGIN ""
83466+#endif
83467+
83468+#ifdef STACKLEAK_PLUGIN
83469+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83470+#else
83471+#define MODULE_STACKLEAK_PLUGIN ""
83472+#endif
83473+
83474+#ifdef RANDSTRUCT_PLUGIN
83475+#include <generated/randomize_layout_hash.h>
83476+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83477+#else
83478+#define MODULE_RANDSTRUCT_PLUGIN
83479+#endif
83480+
83481+#ifdef CONFIG_GRKERNSEC
83482+#define MODULE_GRSEC "GRSEC "
83483+#else
83484+#define MODULE_GRSEC ""
83485+#endif
83486+
83487 #define VERMAGIC_STRING \
83488 UTS_RELEASE " " \
83489 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83490 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83491- MODULE_ARCH_VERMAGIC
83492+ MODULE_ARCH_VERMAGIC \
83493+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83494+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83495
83496diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83497index 502073a..a7de024 100644
83498--- a/include/linux/vga_switcheroo.h
83499+++ b/include/linux/vga_switcheroo.h
83500@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83501
83502 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83503
83504-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83505-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83506+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83507+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83508 #else
83509
83510 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83511@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83512
83513 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83514
83515-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83516-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83517+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83518+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83519
83520 #endif
83521 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83522diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83523index 4b8a891..e9a2863 100644
83524--- a/include/linux/vmalloc.h
83525+++ b/include/linux/vmalloc.h
83526@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83527 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83528 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83529 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83530+
83531+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83532+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83533+#endif
83534+
83535 /* bits [20..32] reserved for arch specific ioremap internals */
83536
83537 /*
83538@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
83539 unsigned long flags, pgprot_t prot);
83540 extern void vunmap(const void *addr);
83541
83542+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83543+extern void unmap_process_stacks(struct task_struct *task);
83544+#endif
83545+
83546 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83547 unsigned long uaddr, void *kaddr,
83548 unsigned long size);
83549@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83550
83551 /* for /dev/kmem */
83552 extern long vread(char *buf, char *addr, unsigned long count);
83553-extern long vwrite(char *buf, char *addr, unsigned long count);
83554+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83555
83556 /*
83557 * Internals. Dont't use..
83558diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83559index 45c9cd1..20bd0bf 100644
83560--- a/include/linux/vmstat.h
83561+++ b/include/linux/vmstat.h
83562@@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83563 /*
83564 * Zone based page accounting with per cpu differentials.
83565 */
83566-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83567+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83568
83569 static inline void zone_page_state_add(long x, struct zone *zone,
83570 enum zone_stat_item item)
83571 {
83572- atomic_long_add(x, &zone->vm_stat[item]);
83573- atomic_long_add(x, &vm_stat[item]);
83574+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83575+ atomic_long_add_unchecked(x, &vm_stat[item]);
83576 }
83577
83578-static inline unsigned long global_page_state(enum zone_stat_item item)
83579+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83580 {
83581- long x = atomic_long_read(&vm_stat[item]);
83582+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83583 #ifdef CONFIG_SMP
83584 if (x < 0)
83585 x = 0;
83586@@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83587 return x;
83588 }
83589
83590-static inline unsigned long zone_page_state(struct zone *zone,
83591+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83592 enum zone_stat_item item)
83593 {
83594- long x = atomic_long_read(&zone->vm_stat[item]);
83595+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83596 #ifdef CONFIG_SMP
83597 if (x < 0)
83598 x = 0;
83599@@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83600 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83601 enum zone_stat_item item)
83602 {
83603- long x = atomic_long_read(&zone->vm_stat[item]);
83604+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83605
83606 #ifdef CONFIG_SMP
83607 int cpu;
83608@@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83609
83610 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83611 {
83612- atomic_long_inc(&zone->vm_stat[item]);
83613- atomic_long_inc(&vm_stat[item]);
83614+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83615+ atomic_long_inc_unchecked(&vm_stat[item]);
83616 }
83617
83618 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83619 {
83620- atomic_long_dec(&zone->vm_stat[item]);
83621- atomic_long_dec(&vm_stat[item]);
83622+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83623+ atomic_long_dec_unchecked(&vm_stat[item]);
83624 }
83625
83626 static inline void __inc_zone_page_state(struct page *page,
83627diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83628index 91b0a68..0e9adf6 100644
83629--- a/include/linux/xattr.h
83630+++ b/include/linux/xattr.h
83631@@ -28,7 +28,7 @@ struct xattr_handler {
83632 size_t size, int handler_flags);
83633 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83634 size_t size, int flags, int handler_flags);
83635-};
83636+} __do_const;
83637
83638 struct xattr {
83639 const char *name;
83640@@ -37,6 +37,9 @@ struct xattr {
83641 };
83642
83643 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83644+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83645+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83646+#endif
83647 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83648 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83649 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83650diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83651index 9c5a6b4..09c9438 100644
83652--- a/include/linux/zlib.h
83653+++ b/include/linux/zlib.h
83654@@ -31,6 +31,7 @@
83655 #define _ZLIB_H
83656
83657 #include <linux/zconf.h>
83658+#include <linux/compiler.h>
83659
83660 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83661 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83662@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83663
83664 /* basic functions */
83665
83666-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83667+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83668 /*
83669 Returns the number of bytes that needs to be allocated for a per-
83670 stream workspace with the specified parameters. A pointer to this
83671diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83672index eec6e46..82d5641 100644
83673--- a/include/media/v4l2-dev.h
83674+++ b/include/media/v4l2-dev.h
83675@@ -77,7 +77,7 @@ struct v4l2_file_operations {
83676 int (*mmap) (struct file *, struct vm_area_struct *);
83677 int (*open) (struct file *);
83678 int (*release) (struct file *);
83679-};
83680+} __do_const;
83681
83682 /*
83683 * Newer version of video_device, handled by videodev2.c
83684diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83685index c9b1593..a572459 100644
83686--- a/include/media/v4l2-device.h
83687+++ b/include/media/v4l2-device.h
83688@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83689 this function returns 0. If the name ends with a digit (e.g. cx18),
83690 then the name will be set to cx18-0 since cx180 looks really odd. */
83691 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83692- atomic_t *instance);
83693+ atomic_unchecked_t *instance);
83694
83695 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83696 Since the parent disappears this ensures that v4l2_dev doesn't have an
83697diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83698index d9fa68f..45c88d1 100644
83699--- a/include/net/9p/transport.h
83700+++ b/include/net/9p/transport.h
83701@@ -63,7 +63,7 @@ struct p9_trans_module {
83702 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83703 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83704 char *, char *, int , int, int, int);
83705-};
83706+} __do_const;
83707
83708 void v9fs_register_trans(struct p9_trans_module *m);
83709 void v9fs_unregister_trans(struct p9_trans_module *m);
83710diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83711index a175ba4..196eb82 100644
83712--- a/include/net/af_unix.h
83713+++ b/include/net/af_unix.h
83714@@ -36,7 +36,7 @@ struct unix_skb_parms {
83715 u32 secid; /* Security ID */
83716 #endif
83717 u32 consumed;
83718-};
83719+} __randomize_layout;
83720
83721 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83722 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83723diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83724index 4abdcb2..945c5cc 100644
83725--- a/include/net/bluetooth/l2cap.h
83726+++ b/include/net/bluetooth/l2cap.h
83727@@ -601,7 +601,7 @@ struct l2cap_ops {
83728 long (*get_sndtimeo) (struct l2cap_chan *chan);
83729 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83730 unsigned long len, int nb);
83731-};
83732+} __do_const;
83733
83734 struct l2cap_conn {
83735 struct hci_conn *hcon;
83736diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83737index f2ae33d..c457cf0 100644
83738--- a/include/net/caif/cfctrl.h
83739+++ b/include/net/caif/cfctrl.h
83740@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83741 void (*radioset_rsp)(void);
83742 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83743 struct cflayer *client_layer);
83744-};
83745+} __no_const;
83746
83747 /* Link Setup Parameters for CAIF-Links. */
83748 struct cfctrl_link_param {
83749@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83750 struct cfctrl {
83751 struct cfsrvl serv;
83752 struct cfctrl_rsp res;
83753- atomic_t req_seq_no;
83754- atomic_t rsp_seq_no;
83755+ atomic_unchecked_t req_seq_no;
83756+ atomic_unchecked_t rsp_seq_no;
83757 struct list_head list;
83758 /* Protects from simultaneous access to first_req list */
83759 spinlock_t info_list_lock;
83760diff --git a/include/net/flow.h b/include/net/flow.h
83761index 8109a15..504466d 100644
83762--- a/include/net/flow.h
83763+++ b/include/net/flow.h
83764@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
83765
83766 void flow_cache_flush(struct net *net);
83767 void flow_cache_flush_deferred(struct net *net);
83768-extern atomic_t flow_cache_genid;
83769+extern atomic_unchecked_t flow_cache_genid;
83770
83771 #endif
83772diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83773index 93695f0..766d71c 100644
83774--- a/include/net/genetlink.h
83775+++ b/include/net/genetlink.h
83776@@ -120,7 +120,7 @@ struct genl_ops {
83777 u8 cmd;
83778 u8 internal_flags;
83779 u8 flags;
83780-};
83781+} __do_const;
83782
83783 int __genl_register_family(struct genl_family *family);
83784
83785diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83786index 734d9b5..48a9a4b 100644
83787--- a/include/net/gro_cells.h
83788+++ b/include/net/gro_cells.h
83789@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83790 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83791
83792 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83793- atomic_long_inc(&dev->rx_dropped);
83794+ atomic_long_inc_unchecked(&dev->rx_dropped);
83795 kfree_skb(skb);
83796 return;
83797 }
83798diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83799index 7a43138..bc76865 100644
83800--- a/include/net/inet_connection_sock.h
83801+++ b/include/net/inet_connection_sock.h
83802@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83803 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83804 int (*bind_conflict)(const struct sock *sk,
83805 const struct inet_bind_bucket *tb, bool relax);
83806-};
83807+} __do_const;
83808
83809 /** inet_connection_sock - INET connection oriented sock
83810 *
83811diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83812index 823ec7b..1af4453 100644
83813--- a/include/net/inetpeer.h
83814+++ b/include/net/inetpeer.h
83815@@ -47,7 +47,7 @@ struct inet_peer {
83816 */
83817 union {
83818 struct {
83819- atomic_t rid; /* Frag reception counter */
83820+ atomic_unchecked_t rid; /* Frag reception counter */
83821 };
83822 struct rcu_head rcu;
83823 struct inet_peer *gc_next;
83824diff --git a/include/net/ip.h b/include/net/ip.h
83825index 54de029..6a28064 100644
83826--- a/include/net/ip.h
83827+++ b/include/net/ip.h
83828@@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83829
83830 void inet_get_local_port_range(struct net *net, int *low, int *high);
83831
83832-extern unsigned long *sysctl_local_reserved_ports;
83833+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83834 static inline int inet_is_reserved_local_port(int port)
83835 {
83836 return test_bit(port, sysctl_local_reserved_ports);
83837@@ -310,7 +310,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
83838 }
83839 }
83840
83841-u32 ip_idents_reserve(u32 hash, int segs);
83842+u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
83843 void __ip_select_ident(struct iphdr *iph, int segs);
83844
83845 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
83846diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83847index 9922093..a1755d6 100644
83848--- a/include/net/ip_fib.h
83849+++ b/include/net/ip_fib.h
83850@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83851
83852 #define FIB_RES_SADDR(net, res) \
83853 ((FIB_RES_NH(res).nh_saddr_genid == \
83854- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83855+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83856 FIB_RES_NH(res).nh_saddr : \
83857 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83858 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83859diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83860index 5679d92..2e7a690 100644
83861--- a/include/net/ip_vs.h
83862+++ b/include/net/ip_vs.h
83863@@ -558,7 +558,7 @@ struct ip_vs_conn {
83864 struct ip_vs_conn *control; /* Master control connection */
83865 atomic_t n_control; /* Number of controlled ones */
83866 struct ip_vs_dest *dest; /* real server */
83867- atomic_t in_pkts; /* incoming packet counter */
83868+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83869
83870 /* packet transmitter for different forwarding methods. If it
83871 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83872@@ -705,7 +705,7 @@ struct ip_vs_dest {
83873 __be16 port; /* port number of the server */
83874 union nf_inet_addr addr; /* IP address of the server */
83875 volatile unsigned int flags; /* dest status flags */
83876- atomic_t conn_flags; /* flags to copy to conn */
83877+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83878 atomic_t weight; /* server weight */
83879
83880 atomic_t refcnt; /* reference counter */
83881@@ -960,11 +960,11 @@ struct netns_ipvs {
83882 /* ip_vs_lblc */
83883 int sysctl_lblc_expiration;
83884 struct ctl_table_header *lblc_ctl_header;
83885- struct ctl_table *lblc_ctl_table;
83886+ ctl_table_no_const *lblc_ctl_table;
83887 /* ip_vs_lblcr */
83888 int sysctl_lblcr_expiration;
83889 struct ctl_table_header *lblcr_ctl_header;
83890- struct ctl_table *lblcr_ctl_table;
83891+ ctl_table_no_const *lblcr_ctl_table;
83892 /* ip_vs_est */
83893 struct list_head est_list; /* estimator list */
83894 spinlock_t est_lock;
83895diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83896index 8d4f588..2e37ad2 100644
83897--- a/include/net/irda/ircomm_tty.h
83898+++ b/include/net/irda/ircomm_tty.h
83899@@ -33,6 +33,7 @@
83900 #include <linux/termios.h>
83901 #include <linux/timer.h>
83902 #include <linux/tty.h> /* struct tty_struct */
83903+#include <asm/local.h>
83904
83905 #include <net/irda/irias_object.h>
83906 #include <net/irda/ircomm_core.h>
83907diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83908index 714cc9a..ea05f3e 100644
83909--- a/include/net/iucv/af_iucv.h
83910+++ b/include/net/iucv/af_iucv.h
83911@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83912 struct iucv_sock_list {
83913 struct hlist_head head;
83914 rwlock_t lock;
83915- atomic_t autobind_name;
83916+ atomic_unchecked_t autobind_name;
83917 };
83918
83919 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83920diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83921index f3be818..bf46196 100644
83922--- a/include/net/llc_c_ac.h
83923+++ b/include/net/llc_c_ac.h
83924@@ -87,7 +87,7 @@
83925 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83926 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83927
83928-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83929+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83930
83931 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83932 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83933diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83934index 3948cf1..83b28c4 100644
83935--- a/include/net/llc_c_ev.h
83936+++ b/include/net/llc_c_ev.h
83937@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83938 return (struct llc_conn_state_ev *)skb->cb;
83939 }
83940
83941-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83942-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83943+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83944+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83945
83946 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83947 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83948diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83949index 0e79cfb..f46db31 100644
83950--- a/include/net/llc_c_st.h
83951+++ b/include/net/llc_c_st.h
83952@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83953 u8 next_state;
83954 llc_conn_ev_qfyr_t *ev_qualifiers;
83955 llc_conn_action_t *ev_actions;
83956-};
83957+} __do_const;
83958
83959 struct llc_conn_state {
83960 u8 current_state;
83961diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83962index a61b98c..aade1eb 100644
83963--- a/include/net/llc_s_ac.h
83964+++ b/include/net/llc_s_ac.h
83965@@ -23,7 +23,7 @@
83966 #define SAP_ACT_TEST_IND 9
83967
83968 /* All action functions must look like this */
83969-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83970+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83971
83972 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83973 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83974diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83975index 567c681..cd73ac02 100644
83976--- a/include/net/llc_s_st.h
83977+++ b/include/net/llc_s_st.h
83978@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83979 llc_sap_ev_t ev;
83980 u8 next_state;
83981 llc_sap_action_t *ev_actions;
83982-};
83983+} __do_const;
83984
83985 struct llc_sap_state {
83986 u8 curr_state;
83987diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83988index 8248e39..7610eec 100644
83989--- a/include/net/mac80211.h
83990+++ b/include/net/mac80211.h
83991@@ -4467,7 +4467,7 @@ struct rate_control_ops {
83992 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83993 struct dentry *dir);
83994 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83995-};
83996+} __do_const;
83997
83998 static inline int rate_supported(struct ieee80211_sta *sta,
83999 enum ieee80211_band band,
84000diff --git a/include/net/neighbour.h b/include/net/neighbour.h
84001index 7277caf..fd095bc 100644
84002--- a/include/net/neighbour.h
84003+++ b/include/net/neighbour.h
84004@@ -163,7 +163,7 @@ struct neigh_ops {
84005 void (*error_report)(struct neighbour *, struct sk_buff *);
84006 int (*output)(struct neighbour *, struct sk_buff *);
84007 int (*connected_output)(struct neighbour *, struct sk_buff *);
84008-};
84009+} __do_const;
84010
84011 struct pneigh_entry {
84012 struct pneigh_entry *next;
84013@@ -203,7 +203,6 @@ struct neigh_table {
84014 void (*proxy_redo)(struct sk_buff *skb);
84015 char *id;
84016 struct neigh_parms parms;
84017- /* HACK. gc_* should follow parms without a gap! */
84018 int gc_interval;
84019 int gc_thresh1;
84020 int gc_thresh2;
84021@@ -218,7 +217,7 @@ struct neigh_table {
84022 struct neigh_statistics __percpu *stats;
84023 struct neigh_hash_table __rcu *nht;
84024 struct pneigh_entry **phash_buckets;
84025-};
84026+} __randomize_layout;
84027
84028 static inline int neigh_parms_family(struct neigh_parms *p)
84029 {
84030diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
84031index 5f9eb26..85699c4 100644
84032--- a/include/net/net_namespace.h
84033+++ b/include/net/net_namespace.h
84034@@ -129,8 +129,8 @@ struct net {
84035 struct netns_ipvs *ipvs;
84036 #endif
84037 struct sock *diag_nlsk;
84038- atomic_t fnhe_genid;
84039-};
84040+ atomic_unchecked_t fnhe_genid;
84041+} __randomize_layout;
84042
84043 #include <linux/seq_file_net.h>
84044
84045@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
84046 #define __net_init __init
84047 #define __net_exit __exit_refok
84048 #define __net_initdata __initdata
84049+#ifdef CONSTIFY_PLUGIN
84050 #define __net_initconst __initconst
84051+#else
84052+#define __net_initconst __initdata
84053+#endif
84054 #endif
84055
84056 struct pernet_operations {
84057@@ -296,7 +300,7 @@ struct pernet_operations {
84058 void (*exit_batch)(struct list_head *net_exit_list);
84059 int *id;
84060 size_t size;
84061-};
84062+} __do_const;
84063
84064 /*
84065 * Use these carefully. If you implement a network device and it
84066@@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
84067
84068 static inline int rt_genid_ipv4(struct net *net)
84069 {
84070- return atomic_read(&net->ipv4.rt_genid);
84071+ return atomic_read_unchecked(&net->ipv4.rt_genid);
84072 }
84073
84074 static inline void rt_genid_bump_ipv4(struct net *net)
84075 {
84076- atomic_inc(&net->ipv4.rt_genid);
84077+ atomic_inc_unchecked(&net->ipv4.rt_genid);
84078 }
84079
84080 #if IS_ENABLED(CONFIG_IPV6)
84081 static inline int rt_genid_ipv6(struct net *net)
84082 {
84083- return atomic_read(&net->ipv6.rt_genid);
84084+ return atomic_read_unchecked(&net->ipv6.rt_genid);
84085 }
84086
84087 static inline void rt_genid_bump_ipv6(struct net *net)
84088 {
84089- atomic_inc(&net->ipv6.rt_genid);
84090+ atomic_inc_unchecked(&net->ipv6.rt_genid);
84091 }
84092 #else
84093 static inline int rt_genid_ipv6(struct net *net)
84094@@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
84095
84096 static inline int fnhe_genid(struct net *net)
84097 {
84098- return atomic_read(&net->fnhe_genid);
84099+ return atomic_read_unchecked(&net->fnhe_genid);
84100 }
84101
84102 static inline void fnhe_genid_bump(struct net *net)
84103 {
84104- atomic_inc(&net->fnhe_genid);
84105+ atomic_inc_unchecked(&net->fnhe_genid);
84106 }
84107
84108 #endif /* __NET_NET_NAMESPACE_H */
84109diff --git a/include/net/netdma.h b/include/net/netdma.h
84110index 8ba8ce2..99b7fff 100644
84111--- a/include/net/netdma.h
84112+++ b/include/net/netdma.h
84113@@ -24,7 +24,7 @@
84114 #include <linux/dmaengine.h>
84115 #include <linux/skbuff.h>
84116
84117-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84118+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84119 struct sk_buff *skb, int offset, struct iovec *to,
84120 size_t len, struct dma_pinned_list *pinned_list);
84121
84122diff --git a/include/net/netlink.h b/include/net/netlink.h
84123index 2b47eaa..6d5bcc2 100644
84124--- a/include/net/netlink.h
84125+++ b/include/net/netlink.h
84126@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
84127 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
84128 {
84129 if (mark)
84130- skb_trim(skb, (unsigned char *) mark - skb->data);
84131+ skb_trim(skb, (const unsigned char *) mark - skb->data);
84132 }
84133
84134 /**
84135diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
84136index 773cce3..6a11852 100644
84137--- a/include/net/netns/conntrack.h
84138+++ b/include/net/netns/conntrack.h
84139@@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
84140 struct nf_proto_net {
84141 #ifdef CONFIG_SYSCTL
84142 struct ctl_table_header *ctl_table_header;
84143- struct ctl_table *ctl_table;
84144+ ctl_table_no_const *ctl_table;
84145 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
84146 struct ctl_table_header *ctl_compat_header;
84147- struct ctl_table *ctl_compat_table;
84148+ ctl_table_no_const *ctl_compat_table;
84149 #endif
84150 #endif
84151 unsigned int users;
84152@@ -59,7 +59,7 @@ struct nf_ip_net {
84153 struct nf_icmp_net icmpv6;
84154 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
84155 struct ctl_table_header *ctl_table_header;
84156- struct ctl_table *ctl_table;
84157+ ctl_table_no_const *ctl_table;
84158 #endif
84159 };
84160
84161diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
84162index b2704fd0..421d717 100644
84163--- a/include/net/netns/ipv4.h
84164+++ b/include/net/netns/ipv4.h
84165@@ -79,7 +79,7 @@ struct netns_ipv4 {
84166
84167 struct ping_group_range ping_group_range;
84168
84169- atomic_t dev_addr_genid;
84170+ atomic_unchecked_t dev_addr_genid;
84171
84172 #ifdef CONFIG_IP_MROUTE
84173 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
84174@@ -89,6 +89,6 @@ struct netns_ipv4 {
84175 struct fib_rules_ops *mr_rules_ops;
84176 #endif
84177 #endif
84178- atomic_t rt_genid;
84179+ atomic_unchecked_t rt_genid;
84180 };
84181 #endif
84182diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
84183index 21edaf1..4c5faae 100644
84184--- a/include/net/netns/ipv6.h
84185+++ b/include/net/netns/ipv6.h
84186@@ -73,8 +73,8 @@ struct netns_ipv6 {
84187 struct fib_rules_ops *mr6_rules_ops;
84188 #endif
84189 #endif
84190- atomic_t dev_addr_genid;
84191- atomic_t rt_genid;
84192+ atomic_unchecked_t dev_addr_genid;
84193+ atomic_unchecked_t rt_genid;
84194 };
84195
84196 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
84197diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
84198index 3492434..209f58c 100644
84199--- a/include/net/netns/xfrm.h
84200+++ b/include/net/netns/xfrm.h
84201@@ -64,7 +64,7 @@ struct netns_xfrm {
84202
84203 /* flow cache part */
84204 struct flow_cache flow_cache_global;
84205- atomic_t flow_cache_genid;
84206+ atomic_unchecked_t flow_cache_genid;
84207 struct list_head flow_cache_gc_list;
84208 spinlock_t flow_cache_gc_lock;
84209 struct work_struct flow_cache_gc_work;
84210diff --git a/include/net/ping.h b/include/net/ping.h
84211index 026479b..d9b2829 100644
84212--- a/include/net/ping.h
84213+++ b/include/net/ping.h
84214@@ -54,7 +54,7 @@ struct ping_iter_state {
84215
84216 extern struct proto ping_prot;
84217 #if IS_ENABLED(CONFIG_IPV6)
84218-extern struct pingv6_ops pingv6_ops;
84219+extern struct pingv6_ops *pingv6_ops;
84220 #endif
84221
84222 struct pingfakehdr {
84223diff --git a/include/net/protocol.h b/include/net/protocol.h
84224index a7e986b..dc67bce 100644
84225--- a/include/net/protocol.h
84226+++ b/include/net/protocol.h
84227@@ -49,7 +49,7 @@ struct net_protocol {
84228 * socket lookup?
84229 */
84230 icmp_strict_tag_validation:1;
84231-};
84232+} __do_const;
84233
84234 #if IS_ENABLED(CONFIG_IPV6)
84235 struct inet6_protocol {
84236@@ -62,7 +62,7 @@ struct inet6_protocol {
84237 u8 type, u8 code, int offset,
84238 __be32 info);
84239 unsigned int flags; /* INET6_PROTO_xxx */
84240-};
84241+} __do_const;
84242
84243 #define INET6_PROTO_NOPOLICY 0x1
84244 #define INET6_PROTO_FINAL 0x2
84245diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
84246index 72240e5..8c14bef 100644
84247--- a/include/net/rtnetlink.h
84248+++ b/include/net/rtnetlink.h
84249@@ -93,7 +93,7 @@ struct rtnl_link_ops {
84250 int (*fill_slave_info)(struct sk_buff *skb,
84251 const struct net_device *dev,
84252 const struct net_device *slave_dev);
84253-};
84254+} __do_const;
84255
84256 int __rtnl_link_register(struct rtnl_link_ops *ops);
84257 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
84258diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
84259index 4a5b9a3..ca27d73 100644
84260--- a/include/net/sctp/checksum.h
84261+++ b/include/net/sctp/checksum.h
84262@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
84263 unsigned int offset)
84264 {
84265 struct sctphdr *sh = sctp_hdr(skb);
84266- __le32 ret, old = sh->checksum;
84267- const struct skb_checksum_ops ops = {
84268+ __le32 ret, old = sh->checksum;
84269+ static const struct skb_checksum_ops ops = {
84270 .update = sctp_csum_update,
84271 .combine = sctp_csum_combine,
84272 };
84273diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
84274index 7f4eeb3..37e8fe1 100644
84275--- a/include/net/sctp/sm.h
84276+++ b/include/net/sctp/sm.h
84277@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84278 typedef struct {
84279 sctp_state_fn_t *fn;
84280 const char *name;
84281-} sctp_sm_table_entry_t;
84282+} __do_const sctp_sm_table_entry_t;
84283
84284 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84285 * currently in use.
84286@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84287 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84288
84289 /* Extern declarations for major data structures. */
84290-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84291+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84292
84293
84294 /* Get the size of a DATA chunk payload. */
84295diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84296index 0dfcc92..7967849 100644
84297--- a/include/net/sctp/structs.h
84298+++ b/include/net/sctp/structs.h
84299@@ -507,7 +507,7 @@ struct sctp_pf {
84300 struct sctp_association *asoc);
84301 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84302 struct sctp_af *af;
84303-};
84304+} __do_const;
84305
84306
84307 /* Structure to track chunk fragments that have been acked, but peer
84308diff --git a/include/net/sock.h b/include/net/sock.h
84309index f5a7e22..043b85f 100644
84310--- a/include/net/sock.h
84311+++ b/include/net/sock.h
84312@@ -348,7 +348,7 @@ struct sock {
84313 unsigned int sk_napi_id;
84314 unsigned int sk_ll_usec;
84315 #endif
84316- atomic_t sk_drops;
84317+ atomic_unchecked_t sk_drops;
84318 int sk_rcvbuf;
84319
84320 struct sk_filter __rcu *sk_filter;
84321@@ -1036,7 +1036,7 @@ struct proto {
84322 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84323 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84324 #endif
84325-};
84326+} __randomize_layout;
84327
84328 /*
84329 * Bits in struct cg_proto.flags
84330@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84331 return ret >> PAGE_SHIFT;
84332 }
84333
84334-static inline long
84335+static inline long __intentional_overflow(-1)
84336 sk_memory_allocated(const struct sock *sk)
84337 {
84338 struct proto *prot = sk->sk_prot;
84339@@ -1368,7 +1368,7 @@ struct sock_iocb {
84340 struct scm_cookie *scm;
84341 struct msghdr *msg, async_msg;
84342 struct kiocb *kiocb;
84343-};
84344+} __randomize_layout;
84345
84346 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84347 {
84348@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84349 }
84350
84351 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84352- char __user *from, char *to,
84353+ char __user *from, unsigned char *to,
84354 int copy, int offset)
84355 {
84356 if (skb->ip_summed == CHECKSUM_NONE) {
84357@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84358 }
84359 }
84360
84361-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84362+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84363
84364 /**
84365 * sk_page_frag - return an appropriate page_frag
84366diff --git a/include/net/tcp.h b/include/net/tcp.h
84367index 87d8774..cf214f8 100644
84368--- a/include/net/tcp.h
84369+++ b/include/net/tcp.h
84370@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84371 void tcp_xmit_retransmit_queue(struct sock *);
84372 void tcp_simple_retransmit(struct sock *);
84373 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84374-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84375+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84376
84377 void tcp_send_probe0(struct sock *);
84378 void tcp_send_partial(struct sock *);
84379@@ -715,8 +715,8 @@ struct tcp_skb_cb {
84380 struct inet6_skb_parm h6;
84381 #endif
84382 } header; /* For incoming frames */
84383- __u32 seq; /* Starting sequence number */
84384- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84385+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
84386+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84387 __u32 when; /* used to compute rtt's */
84388 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84389
84390@@ -730,7 +730,7 @@ struct tcp_skb_cb {
84391
84392 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84393 /* 1 byte hole */
84394- __u32 ack_seq; /* Sequence number ACK'd */
84395+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84396 };
84397
84398 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84399diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84400index 116e9c7..3070537 100644
84401--- a/include/net/xfrm.h
84402+++ b/include/net/xfrm.h
84403@@ -285,7 +285,6 @@ struct xfrm_dst;
84404 struct xfrm_policy_afinfo {
84405 unsigned short family;
84406 struct dst_ops *dst_ops;
84407- void (*garbage_collect)(struct net *net);
84408 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84409 const xfrm_address_t *saddr,
84410 const xfrm_address_t *daddr);
84411@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
84412 struct net_device *dev,
84413 const struct flowi *fl);
84414 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84415-};
84416+} __do_const;
84417
84418 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84419 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84420@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
84421 int (*transport_finish)(struct sk_buff *skb,
84422 int async);
84423 void (*local_error)(struct sk_buff *skb, u32 mtu);
84424-};
84425+} __do_const;
84426
84427 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84428 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84429@@ -437,7 +436,7 @@ struct xfrm_mode {
84430 struct module *owner;
84431 unsigned int encap;
84432 int flags;
84433-};
84434+} __do_const;
84435
84436 /* Flags for xfrm_mode. */
84437 enum {
84438@@ -534,7 +533,7 @@ struct xfrm_policy {
84439 struct timer_list timer;
84440
84441 struct flow_cache_object flo;
84442- atomic_t genid;
84443+ atomic_unchecked_t genid;
84444 u32 priority;
84445 u32 index;
84446 struct xfrm_mark mark;
84447@@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84448 }
84449
84450 void xfrm_garbage_collect(struct net *net);
84451+void xfrm_garbage_collect_deferred(struct net *net);
84452
84453 #else
84454
84455@@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84456 static inline void xfrm_garbage_collect(struct net *net)
84457 {
84458 }
84459+static inline void xfrm_garbage_collect_deferred(struct net *net)
84460+{
84461+}
84462 #endif
84463
84464 static __inline__
84465diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84466index 1017e0b..227aa4d 100644
84467--- a/include/rdma/iw_cm.h
84468+++ b/include/rdma/iw_cm.h
84469@@ -122,7 +122,7 @@ struct iw_cm_verbs {
84470 int backlog);
84471
84472 int (*destroy_listen)(struct iw_cm_id *cm_id);
84473-};
84474+} __no_const;
84475
84476 /**
84477 * iw_create_cm_id - Create an IW CM identifier.
84478diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84479index 52beadf..598734c 100644
84480--- a/include/scsi/libfc.h
84481+++ b/include/scsi/libfc.h
84482@@ -771,6 +771,7 @@ struct libfc_function_template {
84483 */
84484 void (*disc_stop_final) (struct fc_lport *);
84485 };
84486+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84487
84488 /**
84489 * struct fc_disc - Discovery context
84490@@ -875,7 +876,7 @@ struct fc_lport {
84491 struct fc_vport *vport;
84492
84493 /* Operational Information */
84494- struct libfc_function_template tt;
84495+ libfc_function_template_no_const tt;
84496 u8 link_up;
84497 u8 qfull;
84498 enum fc_lport_state state;
84499diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84500index 27ab310..60dc245 100644
84501--- a/include/scsi/scsi_device.h
84502+++ b/include/scsi/scsi_device.h
84503@@ -187,9 +187,9 @@ struct scsi_device {
84504 unsigned int max_device_blocked; /* what device_blocked counts down from */
84505 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84506
84507- atomic_t iorequest_cnt;
84508- atomic_t iodone_cnt;
84509- atomic_t ioerr_cnt;
84510+ atomic_unchecked_t iorequest_cnt;
84511+ atomic_unchecked_t iodone_cnt;
84512+ atomic_unchecked_t ioerr_cnt;
84513
84514 struct device sdev_gendev,
84515 sdev_dev;
84516diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84517index 8c79980..723f6f9 100644
84518--- a/include/scsi/scsi_transport_fc.h
84519+++ b/include/scsi/scsi_transport_fc.h
84520@@ -752,7 +752,8 @@ struct fc_function_template {
84521 unsigned long show_host_system_hostname:1;
84522
84523 unsigned long disable_target_scan:1;
84524-};
84525+} __do_const;
84526+typedef struct fc_function_template __no_const fc_function_template_no_const;
84527
84528
84529 /**
84530diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84531index ae6c3b8..fd748ac 100644
84532--- a/include/sound/compress_driver.h
84533+++ b/include/sound/compress_driver.h
84534@@ -128,7 +128,7 @@ struct snd_compr_ops {
84535 struct snd_compr_caps *caps);
84536 int (*get_codec_caps) (struct snd_compr_stream *stream,
84537 struct snd_compr_codec_caps *codec);
84538-};
84539+} __no_const;
84540
84541 /**
84542 * struct snd_compr: Compressed device
84543diff --git a/include/sound/soc.h b/include/sound/soc.h
84544index 0b83168..d67280a 100644
84545--- a/include/sound/soc.h
84546+++ b/include/sound/soc.h
84547@@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84548 /* probe ordering - for components with runtime dependencies */
84549 int probe_order;
84550 int remove_order;
84551-};
84552+} __do_const;
84553
84554 /* SoC platform interface */
84555 struct snd_soc_platform_driver {
84556@@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84557 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84558 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84559 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84560-};
84561+} __do_const;
84562
84563 struct snd_soc_platform {
84564 const char *name;
84565diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84566index 9ec9864..e2ee1ee 100644
84567--- a/include/target/target_core_base.h
84568+++ b/include/target/target_core_base.h
84569@@ -761,7 +761,7 @@ struct se_device {
84570 atomic_long_t write_bytes;
84571 /* Active commands on this virtual SE device */
84572 atomic_t simple_cmds;
84573- atomic_t dev_ordered_id;
84574+ atomic_unchecked_t dev_ordered_id;
84575 atomic_t dev_ordered_sync;
84576 atomic_t dev_qf_count;
84577 int export_count;
84578diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84579new file mode 100644
84580index 0000000..fb634b7
84581--- /dev/null
84582+++ b/include/trace/events/fs.h
84583@@ -0,0 +1,53 @@
84584+#undef TRACE_SYSTEM
84585+#define TRACE_SYSTEM fs
84586+
84587+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84588+#define _TRACE_FS_H
84589+
84590+#include <linux/fs.h>
84591+#include <linux/tracepoint.h>
84592+
84593+TRACE_EVENT(do_sys_open,
84594+
84595+ TP_PROTO(const char *filename, int flags, int mode),
84596+
84597+ TP_ARGS(filename, flags, mode),
84598+
84599+ TP_STRUCT__entry(
84600+ __string( filename, filename )
84601+ __field( int, flags )
84602+ __field( int, mode )
84603+ ),
84604+
84605+ TP_fast_assign(
84606+ __assign_str(filename, filename);
84607+ __entry->flags = flags;
84608+ __entry->mode = mode;
84609+ ),
84610+
84611+ TP_printk("\"%s\" %x %o",
84612+ __get_str(filename), __entry->flags, __entry->mode)
84613+);
84614+
84615+TRACE_EVENT(open_exec,
84616+
84617+ TP_PROTO(const char *filename),
84618+
84619+ TP_ARGS(filename),
84620+
84621+ TP_STRUCT__entry(
84622+ __string( filename, filename )
84623+ ),
84624+
84625+ TP_fast_assign(
84626+ __assign_str(filename, filename);
84627+ ),
84628+
84629+ TP_printk("\"%s\"",
84630+ __get_str(filename))
84631+);
84632+
84633+#endif /* _TRACE_FS_H */
84634+
84635+/* This part must be outside protection */
84636+#include <trace/define_trace.h>
84637diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84638index 1c09820..7f5ec79 100644
84639--- a/include/trace/events/irq.h
84640+++ b/include/trace/events/irq.h
84641@@ -36,7 +36,7 @@ struct softirq_action;
84642 */
84643 TRACE_EVENT(irq_handler_entry,
84644
84645- TP_PROTO(int irq, struct irqaction *action),
84646+ TP_PROTO(int irq, const struct irqaction *action),
84647
84648 TP_ARGS(irq, action),
84649
84650@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84651 */
84652 TRACE_EVENT(irq_handler_exit,
84653
84654- TP_PROTO(int irq, struct irqaction *action, int ret),
84655+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84656
84657 TP_ARGS(irq, action, ret),
84658
84659diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84660index 7caf44c..23c6f27 100644
84661--- a/include/uapi/linux/a.out.h
84662+++ b/include/uapi/linux/a.out.h
84663@@ -39,6 +39,14 @@ enum machine_type {
84664 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84665 };
84666
84667+/* Constants for the N_FLAGS field */
84668+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84669+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84670+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84671+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84672+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84673+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84674+
84675 #if !defined (N_MAGIC)
84676 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84677 #endif
84678diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84679index 22b6ad3..aeba37e 100644
84680--- a/include/uapi/linux/bcache.h
84681+++ b/include/uapi/linux/bcache.h
84682@@ -5,6 +5,7 @@
84683 * Bcache on disk data structures
84684 */
84685
84686+#include <linux/compiler.h>
84687 #include <asm/types.h>
84688
84689 #define BITMASK(name, type, field, offset, size) \
84690@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84691 /* Btree keys - all units are in sectors */
84692
84693 struct bkey {
84694- __u64 high;
84695- __u64 low;
84696+ __u64 high __intentional_overflow(-1);
84697+ __u64 low __intentional_overflow(-1);
84698 __u64 ptr[];
84699 };
84700
84701diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84702index d876736..ccce5c0 100644
84703--- a/include/uapi/linux/byteorder/little_endian.h
84704+++ b/include/uapi/linux/byteorder/little_endian.h
84705@@ -42,51 +42,51 @@
84706
84707 static inline __le64 __cpu_to_le64p(const __u64 *p)
84708 {
84709- return (__force __le64)*p;
84710+ return (__force const __le64)*p;
84711 }
84712-static inline __u64 __le64_to_cpup(const __le64 *p)
84713+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84714 {
84715- return (__force __u64)*p;
84716+ return (__force const __u64)*p;
84717 }
84718 static inline __le32 __cpu_to_le32p(const __u32 *p)
84719 {
84720- return (__force __le32)*p;
84721+ return (__force const __le32)*p;
84722 }
84723 static inline __u32 __le32_to_cpup(const __le32 *p)
84724 {
84725- return (__force __u32)*p;
84726+ return (__force const __u32)*p;
84727 }
84728 static inline __le16 __cpu_to_le16p(const __u16 *p)
84729 {
84730- return (__force __le16)*p;
84731+ return (__force const __le16)*p;
84732 }
84733 static inline __u16 __le16_to_cpup(const __le16 *p)
84734 {
84735- return (__force __u16)*p;
84736+ return (__force const __u16)*p;
84737 }
84738 static inline __be64 __cpu_to_be64p(const __u64 *p)
84739 {
84740- return (__force __be64)__swab64p(p);
84741+ return (__force const __be64)__swab64p(p);
84742 }
84743 static inline __u64 __be64_to_cpup(const __be64 *p)
84744 {
84745- return __swab64p((__u64 *)p);
84746+ return __swab64p((const __u64 *)p);
84747 }
84748 static inline __be32 __cpu_to_be32p(const __u32 *p)
84749 {
84750- return (__force __be32)__swab32p(p);
84751+ return (__force const __be32)__swab32p(p);
84752 }
84753-static inline __u32 __be32_to_cpup(const __be32 *p)
84754+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84755 {
84756- return __swab32p((__u32 *)p);
84757+ return __swab32p((const __u32 *)p);
84758 }
84759 static inline __be16 __cpu_to_be16p(const __u16 *p)
84760 {
84761- return (__force __be16)__swab16p(p);
84762+ return (__force const __be16)__swab16p(p);
84763 }
84764 static inline __u16 __be16_to_cpup(const __be16 *p)
84765 {
84766- return __swab16p((__u16 *)p);
84767+ return __swab16p((const __u16 *)p);
84768 }
84769 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84770 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84771diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84772index ef6103b..d4e65dd 100644
84773--- a/include/uapi/linux/elf.h
84774+++ b/include/uapi/linux/elf.h
84775@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84776 #define PT_GNU_EH_FRAME 0x6474e550
84777
84778 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84779+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84780+
84781+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84782+
84783+/* Constants for the e_flags field */
84784+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84785+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84786+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84787+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84788+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84789+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84790
84791 /*
84792 * Extended Numbering
84793@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84794 #define DT_DEBUG 21
84795 #define DT_TEXTREL 22
84796 #define DT_JMPREL 23
84797+#define DT_FLAGS 30
84798+ #define DF_TEXTREL 0x00000004
84799 #define DT_ENCODING 32
84800 #define OLD_DT_LOOS 0x60000000
84801 #define DT_LOOS 0x6000000d
84802@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84803 #define PF_W 0x2
84804 #define PF_X 0x1
84805
84806+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84807+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84808+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84809+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84810+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84811+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84812+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84813+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84814+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84815+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84816+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84817+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84818+
84819 typedef struct elf32_phdr{
84820 Elf32_Word p_type;
84821 Elf32_Off p_offset;
84822@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84823 #define EI_OSABI 7
84824 #define EI_PAD 8
84825
84826+#define EI_PAX 14
84827+
84828 #define ELFMAG0 0x7f /* EI_MAG */
84829 #define ELFMAG1 'E'
84830 #define ELFMAG2 'L'
84831diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84832index aa169c4..6a2771d 100644
84833--- a/include/uapi/linux/personality.h
84834+++ b/include/uapi/linux/personality.h
84835@@ -30,6 +30,7 @@ enum {
84836 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84837 ADDR_NO_RANDOMIZE | \
84838 ADDR_COMPAT_LAYOUT | \
84839+ ADDR_LIMIT_3GB | \
84840 MMAP_PAGE_ZERO)
84841
84842 /*
84843diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84844index 7530e74..e714828 100644
84845--- a/include/uapi/linux/screen_info.h
84846+++ b/include/uapi/linux/screen_info.h
84847@@ -43,7 +43,8 @@ struct screen_info {
84848 __u16 pages; /* 0x32 */
84849 __u16 vesa_attributes; /* 0x34 */
84850 __u32 capabilities; /* 0x36 */
84851- __u8 _reserved[6]; /* 0x3a */
84852+ __u16 vesapm_size; /* 0x3a */
84853+ __u8 _reserved[4]; /* 0x3c */
84854 } __attribute__((packed));
84855
84856 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84857diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84858index 0e011eb..82681b1 100644
84859--- a/include/uapi/linux/swab.h
84860+++ b/include/uapi/linux/swab.h
84861@@ -43,7 +43,7 @@
84862 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84863 */
84864
84865-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84866+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84867 {
84868 #ifdef __HAVE_BUILTIN_BSWAP16__
84869 return __builtin_bswap16(val);
84870@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84871 #endif
84872 }
84873
84874-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84875+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84876 {
84877 #ifdef __HAVE_BUILTIN_BSWAP32__
84878 return __builtin_bswap32(val);
84879@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84880 #endif
84881 }
84882
84883-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84884+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84885 {
84886 #ifdef __HAVE_BUILTIN_BSWAP64__
84887 return __builtin_bswap64(val);
84888diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84889index 6d67213..552fdd9 100644
84890--- a/include/uapi/linux/sysctl.h
84891+++ b/include/uapi/linux/sysctl.h
84892@@ -155,8 +155,6 @@ enum
84893 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84894 };
84895
84896-
84897-
84898 /* CTL_VM names: */
84899 enum
84900 {
84901diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84902index ea468ee..4d367a5 100644
84903--- a/include/uapi/linux/videodev2.h
84904+++ b/include/uapi/linux/videodev2.h
84905@@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
84906 union {
84907 __s32 value;
84908 __s64 value64;
84909- char *string;
84910+ char __user *string;
84911 };
84912 } __attribute__ ((packed));
84913
84914diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84915index c38355c..17a57bc 100644
84916--- a/include/uapi/linux/xattr.h
84917+++ b/include/uapi/linux/xattr.h
84918@@ -73,5 +73,9 @@
84919 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84920 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84921
84922+/* User namespace */
84923+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84924+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84925+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84926
84927 #endif /* _UAPI_LINUX_XATTR_H */
84928diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84929index f9466fa..f4e2b81 100644
84930--- a/include/video/udlfb.h
84931+++ b/include/video/udlfb.h
84932@@ -53,10 +53,10 @@ struct dlfb_data {
84933 u32 pseudo_palette[256];
84934 int blank_mode; /*one of FB_BLANK_ */
84935 /* blit-only rendering path metrics, exposed through sysfs */
84936- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84937- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84938- atomic_t bytes_sent; /* to usb, after compression including overhead */
84939- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84940+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84941+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84942+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84943+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84944 };
84945
84946 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84947diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84948index 30f5362..8ed8ac9 100644
84949--- a/include/video/uvesafb.h
84950+++ b/include/video/uvesafb.h
84951@@ -122,6 +122,7 @@ struct uvesafb_par {
84952 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84953 u8 pmi_setpal; /* PMI for palette changes */
84954 u16 *pmi_base; /* protected mode interface location */
84955+ u8 *pmi_code; /* protected mode code location */
84956 void *pmi_start;
84957 void *pmi_pal;
84958 u8 *vbe_state_orig; /*
84959diff --git a/init/Kconfig b/init/Kconfig
84960index 9d3585b..ad45d34 100644
84961--- a/init/Kconfig
84962+++ b/init/Kconfig
84963@@ -1093,6 +1093,7 @@ endif # CGROUPS
84964
84965 config CHECKPOINT_RESTORE
84966 bool "Checkpoint/restore support" if EXPERT
84967+ depends on !GRKERNSEC
84968 default n
84969 help
84970 Enables additional kernel features in a sake of checkpoint/restore.
84971@@ -1570,7 +1571,7 @@ config SLUB_DEBUG
84972
84973 config COMPAT_BRK
84974 bool "Disable heap randomization"
84975- default y
84976+ default n
84977 help
84978 Randomizing heap placement makes heap exploits harder, but it
84979 also breaks ancient binaries (including anything libc5 based).
84980@@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
84981 config STOP_MACHINE
84982 bool
84983 default y
84984- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84985+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84986 help
84987 Need stop_machine() primitive.
84988
84989diff --git a/init/Makefile b/init/Makefile
84990index 7bc47ee..6da2dc7 100644
84991--- a/init/Makefile
84992+++ b/init/Makefile
84993@@ -2,6 +2,9 @@
84994 # Makefile for the linux kernel.
84995 #
84996
84997+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84998+asflags-y := $(GCC_PLUGINS_AFLAGS)
84999+
85000 obj-y := main.o version.o mounts.o
85001 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
85002 obj-y += noinitramfs.o
85003diff --git a/init/do_mounts.c b/init/do_mounts.c
85004index 82f2288..ea1430a 100644
85005--- a/init/do_mounts.c
85006+++ b/init/do_mounts.c
85007@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
85008 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
85009 {
85010 struct super_block *s;
85011- int err = sys_mount(name, "/root", fs, flags, data);
85012+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
85013 if (err)
85014 return err;
85015
85016- sys_chdir("/root");
85017+ sys_chdir((const char __force_user *)"/root");
85018 s = current->fs->pwd.dentry->d_sb;
85019 ROOT_DEV = s->s_dev;
85020 printk(KERN_INFO
85021@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
85022 va_start(args, fmt);
85023 vsprintf(buf, fmt, args);
85024 va_end(args);
85025- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
85026+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
85027 if (fd >= 0) {
85028 sys_ioctl(fd, FDEJECT, 0);
85029 sys_close(fd);
85030 }
85031 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
85032- fd = sys_open("/dev/console", O_RDWR, 0);
85033+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
85034 if (fd >= 0) {
85035 sys_ioctl(fd, TCGETS, (long)&termios);
85036 termios.c_lflag &= ~ICANON;
85037 sys_ioctl(fd, TCSETSF, (long)&termios);
85038- sys_read(fd, &c, 1);
85039+ sys_read(fd, (char __user *)&c, 1);
85040 termios.c_lflag |= ICANON;
85041 sys_ioctl(fd, TCSETSF, (long)&termios);
85042 sys_close(fd);
85043@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
85044 mount_root();
85045 out:
85046 devtmpfs_mount("dev");
85047- sys_mount(".", "/", NULL, MS_MOVE, NULL);
85048- sys_chroot(".");
85049+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85050+ sys_chroot((const char __force_user *)".");
85051 }
85052
85053 static bool is_tmpfs;
85054diff --git a/init/do_mounts.h b/init/do_mounts.h
85055index f5b978a..69dbfe8 100644
85056--- a/init/do_mounts.h
85057+++ b/init/do_mounts.h
85058@@ -15,15 +15,15 @@ extern int root_mountflags;
85059
85060 static inline int create_dev(char *name, dev_t dev)
85061 {
85062- sys_unlink(name);
85063- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
85064+ sys_unlink((char __force_user *)name);
85065+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
85066 }
85067
85068 #if BITS_PER_LONG == 32
85069 static inline u32 bstat(char *name)
85070 {
85071 struct stat64 stat;
85072- if (sys_stat64(name, &stat) != 0)
85073+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
85074 return 0;
85075 if (!S_ISBLK(stat.st_mode))
85076 return 0;
85077@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
85078 static inline u32 bstat(char *name)
85079 {
85080 struct stat stat;
85081- if (sys_newstat(name, &stat) != 0)
85082+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
85083 return 0;
85084 if (!S_ISBLK(stat.st_mode))
85085 return 0;
85086diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
85087index 3e0878e..8a9d7a0 100644
85088--- a/init/do_mounts_initrd.c
85089+++ b/init/do_mounts_initrd.c
85090@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
85091 {
85092 sys_unshare(CLONE_FS | CLONE_FILES);
85093 /* stdin/stdout/stderr for /linuxrc */
85094- sys_open("/dev/console", O_RDWR, 0);
85095+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
85096 sys_dup(0);
85097 sys_dup(0);
85098 /* move initrd over / and chdir/chroot in initrd root */
85099- sys_chdir("/root");
85100- sys_mount(".", "/", NULL, MS_MOVE, NULL);
85101- sys_chroot(".");
85102+ sys_chdir((const char __force_user *)"/root");
85103+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85104+ sys_chroot((const char __force_user *)".");
85105 sys_setsid();
85106 return 0;
85107 }
85108@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
85109 create_dev("/dev/root.old", Root_RAM0);
85110 /* mount initrd on rootfs' /root */
85111 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
85112- sys_mkdir("/old", 0700);
85113- sys_chdir("/old");
85114+ sys_mkdir((const char __force_user *)"/old", 0700);
85115+ sys_chdir((const char __force_user *)"/old");
85116
85117 /* try loading default modules from initrd */
85118 load_default_modules();
85119@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
85120 current->flags &= ~PF_FREEZER_SKIP;
85121
85122 /* move initrd to rootfs' /old */
85123- sys_mount("..", ".", NULL, MS_MOVE, NULL);
85124+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
85125 /* switch root and cwd back to / of rootfs */
85126- sys_chroot("..");
85127+ sys_chroot((const char __force_user *)"..");
85128
85129 if (new_decode_dev(real_root_dev) == Root_RAM0) {
85130- sys_chdir("/old");
85131+ sys_chdir((const char __force_user *)"/old");
85132 return;
85133 }
85134
85135- sys_chdir("/");
85136+ sys_chdir((const char __force_user *)"/");
85137 ROOT_DEV = new_decode_dev(real_root_dev);
85138 mount_root();
85139
85140 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
85141- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
85142+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
85143 if (!error)
85144 printk("okay\n");
85145 else {
85146- int fd = sys_open("/dev/root.old", O_RDWR, 0);
85147+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
85148 if (error == -ENOENT)
85149 printk("/initrd does not exist. Ignored.\n");
85150 else
85151 printk("failed\n");
85152 printk(KERN_NOTICE "Unmounting old root\n");
85153- sys_umount("/old", MNT_DETACH);
85154+ sys_umount((char __force_user *)"/old", MNT_DETACH);
85155 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
85156 if (fd < 0) {
85157 error = fd;
85158@@ -127,11 +127,11 @@ int __init initrd_load(void)
85159 * mounted in the normal path.
85160 */
85161 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
85162- sys_unlink("/initrd.image");
85163+ sys_unlink((const char __force_user *)"/initrd.image");
85164 handle_initrd();
85165 return 1;
85166 }
85167 }
85168- sys_unlink("/initrd.image");
85169+ sys_unlink((const char __force_user *)"/initrd.image");
85170 return 0;
85171 }
85172diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
85173index 8cb6db5..d729f50 100644
85174--- a/init/do_mounts_md.c
85175+++ b/init/do_mounts_md.c
85176@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
85177 partitioned ? "_d" : "", minor,
85178 md_setup_args[ent].device_names);
85179
85180- fd = sys_open(name, 0, 0);
85181+ fd = sys_open((char __force_user *)name, 0, 0);
85182 if (fd < 0) {
85183 printk(KERN_ERR "md: open failed - cannot start "
85184 "array %s\n", name);
85185@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
85186 * array without it
85187 */
85188 sys_close(fd);
85189- fd = sys_open(name, 0, 0);
85190+ fd = sys_open((char __force_user *)name, 0, 0);
85191 sys_ioctl(fd, BLKRRPART, 0);
85192 }
85193 sys_close(fd);
85194@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
85195
85196 wait_for_device_probe();
85197
85198- fd = sys_open("/dev/md0", 0, 0);
85199+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
85200 if (fd >= 0) {
85201 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
85202 sys_close(fd);
85203diff --git a/init/init_task.c b/init/init_task.c
85204index ba0a7f36..2bcf1d5 100644
85205--- a/init/init_task.c
85206+++ b/init/init_task.c
85207@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
85208 * Initial thread structure. Alignment of this is handled by a special
85209 * linker map entry.
85210 */
85211+#ifdef CONFIG_X86
85212+union thread_union init_thread_union __init_task_data;
85213+#else
85214 union thread_union init_thread_union __init_task_data =
85215 { INIT_THREAD_INFO(init_task) };
85216+#endif
85217diff --git a/init/initramfs.c b/init/initramfs.c
85218index a8497fa..35b3c90 100644
85219--- a/init/initramfs.c
85220+++ b/init/initramfs.c
85221@@ -84,7 +84,7 @@ static void __init free_hash(void)
85222 }
85223 }
85224
85225-static long __init do_utime(char *filename, time_t mtime)
85226+static long __init do_utime(char __force_user *filename, time_t mtime)
85227 {
85228 struct timespec t[2];
85229
85230@@ -119,7 +119,7 @@ static void __init dir_utime(void)
85231 struct dir_entry *de, *tmp;
85232 list_for_each_entry_safe(de, tmp, &dir_list, list) {
85233 list_del(&de->list);
85234- do_utime(de->name, de->mtime);
85235+ do_utime((char __force_user *)de->name, de->mtime);
85236 kfree(de->name);
85237 kfree(de);
85238 }
85239@@ -281,7 +281,7 @@ static int __init maybe_link(void)
85240 if (nlink >= 2) {
85241 char *old = find_link(major, minor, ino, mode, collected);
85242 if (old)
85243- return (sys_link(old, collected) < 0) ? -1 : 1;
85244+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
85245 }
85246 return 0;
85247 }
85248@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
85249 {
85250 struct stat st;
85251
85252- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
85253+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
85254 if (S_ISDIR(st.st_mode))
85255- sys_rmdir(path);
85256+ sys_rmdir((char __force_user *)path);
85257 else
85258- sys_unlink(path);
85259+ sys_unlink((char __force_user *)path);
85260 }
85261 }
85262
85263@@ -315,7 +315,7 @@ static int __init do_name(void)
85264 int openflags = O_WRONLY|O_CREAT;
85265 if (ml != 1)
85266 openflags |= O_TRUNC;
85267- wfd = sys_open(collected, openflags, mode);
85268+ wfd = sys_open((char __force_user *)collected, openflags, mode);
85269
85270 if (wfd >= 0) {
85271 sys_fchown(wfd, uid, gid);
85272@@ -327,17 +327,17 @@ static int __init do_name(void)
85273 }
85274 }
85275 } else if (S_ISDIR(mode)) {
85276- sys_mkdir(collected, mode);
85277- sys_chown(collected, uid, gid);
85278- sys_chmod(collected, mode);
85279+ sys_mkdir((char __force_user *)collected, mode);
85280+ sys_chown((char __force_user *)collected, uid, gid);
85281+ sys_chmod((char __force_user *)collected, mode);
85282 dir_add(collected, mtime);
85283 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85284 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85285 if (maybe_link() == 0) {
85286- sys_mknod(collected, mode, rdev);
85287- sys_chown(collected, uid, gid);
85288- sys_chmod(collected, mode);
85289- do_utime(collected, mtime);
85290+ sys_mknod((char __force_user *)collected, mode, rdev);
85291+ sys_chown((char __force_user *)collected, uid, gid);
85292+ sys_chmod((char __force_user *)collected, mode);
85293+ do_utime((char __force_user *)collected, mtime);
85294 }
85295 }
85296 return 0;
85297@@ -346,15 +346,15 @@ static int __init do_name(void)
85298 static int __init do_copy(void)
85299 {
85300 if (count >= body_len) {
85301- sys_write(wfd, victim, body_len);
85302+ sys_write(wfd, (char __force_user *)victim, body_len);
85303 sys_close(wfd);
85304- do_utime(vcollected, mtime);
85305+ do_utime((char __force_user *)vcollected, mtime);
85306 kfree(vcollected);
85307 eat(body_len);
85308 state = SkipIt;
85309 return 0;
85310 } else {
85311- sys_write(wfd, victim, count);
85312+ sys_write(wfd, (char __force_user *)victim, count);
85313 body_len -= count;
85314 eat(count);
85315 return 1;
85316@@ -365,9 +365,9 @@ static int __init do_symlink(void)
85317 {
85318 collected[N_ALIGN(name_len) + body_len] = '\0';
85319 clean_path(collected, 0);
85320- sys_symlink(collected + N_ALIGN(name_len), collected);
85321- sys_lchown(collected, uid, gid);
85322- do_utime(collected, mtime);
85323+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85324+ sys_lchown((char __force_user *)collected, uid, gid);
85325+ do_utime((char __force_user *)collected, mtime);
85326 state = SkipIt;
85327 next_state = Reset;
85328 return 0;
85329diff --git a/init/main.c b/init/main.c
85330index eb0ea86..b91cd60 100644
85331--- a/init/main.c
85332+++ b/init/main.c
85333@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85334 static inline void mark_rodata_ro(void) { }
85335 #endif
85336
85337+extern void grsecurity_init(void);
85338+
85339 /*
85340 * Debug helper: via this flag we know that we are in 'early bootup code'
85341 * where only the boot processor is running with IRQ disabled. This means
85342@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85343
85344 __setup("reset_devices", set_reset_devices);
85345
85346+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85347+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85348+static int __init setup_grsec_proc_gid(char *str)
85349+{
85350+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85351+ return 1;
85352+}
85353+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85354+#endif
85355+
85356+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85357+unsigned long pax_user_shadow_base __read_only;
85358+EXPORT_SYMBOL(pax_user_shadow_base);
85359+extern char pax_enter_kernel_user[];
85360+extern char pax_exit_kernel_user[];
85361+#endif
85362+
85363+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85364+static int __init setup_pax_nouderef(char *str)
85365+{
85366+#ifdef CONFIG_X86_32
85367+ unsigned int cpu;
85368+ struct desc_struct *gdt;
85369+
85370+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85371+ gdt = get_cpu_gdt_table(cpu);
85372+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85373+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85374+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85375+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85376+ }
85377+ loadsegment(ds, __KERNEL_DS);
85378+ loadsegment(es, __KERNEL_DS);
85379+ loadsegment(ss, __KERNEL_DS);
85380+#else
85381+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85382+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85383+ clone_pgd_mask = ~(pgdval_t)0UL;
85384+ pax_user_shadow_base = 0UL;
85385+ setup_clear_cpu_cap(X86_FEATURE_PCID);
85386+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85387+#endif
85388+
85389+ return 0;
85390+}
85391+early_param("pax_nouderef", setup_pax_nouderef);
85392+
85393+#ifdef CONFIG_X86_64
85394+static int __init setup_pax_weakuderef(char *str)
85395+{
85396+ if (clone_pgd_mask != ~(pgdval_t)0UL)
85397+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85398+ return 1;
85399+}
85400+__setup("pax_weakuderef", setup_pax_weakuderef);
85401+#endif
85402+#endif
85403+
85404+#ifdef CONFIG_PAX_SOFTMODE
85405+int pax_softmode;
85406+
85407+static int __init setup_pax_softmode(char *str)
85408+{
85409+ get_option(&str, &pax_softmode);
85410+ return 1;
85411+}
85412+__setup("pax_softmode=", setup_pax_softmode);
85413+#endif
85414+
85415 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85416 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85417 static const char *panic_later, *panic_param;
85418@@ -692,25 +763,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85419 {
85420 int count = preempt_count();
85421 int ret;
85422- char msgbuf[64];
85423+ const char *msg1 = "", *msg2 = "";
85424
85425 if (initcall_debug)
85426 ret = do_one_initcall_debug(fn);
85427 else
85428 ret = fn();
85429
85430- msgbuf[0] = 0;
85431-
85432 if (preempt_count() != count) {
85433- sprintf(msgbuf, "preemption imbalance ");
85434+ msg1 = " preemption imbalance";
85435 preempt_count_set(count);
85436 }
85437 if (irqs_disabled()) {
85438- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85439+ msg2 = " disabled interrupts";
85440 local_irq_enable();
85441 }
85442- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85443+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85444
85445+ add_latent_entropy();
85446 return ret;
85447 }
85448
85449@@ -817,8 +887,8 @@ static int run_init_process(const char *init_filename)
85450 {
85451 argv_init[0] = init_filename;
85452 return do_execve(getname_kernel(init_filename),
85453- (const char __user *const __user *)argv_init,
85454- (const char __user *const __user *)envp_init);
85455+ (const char __user *const __force_user *)argv_init,
85456+ (const char __user *const __force_user *)envp_init);
85457 }
85458
85459 static int try_to_run_init_process(const char *init_filename)
85460@@ -835,6 +905,10 @@ static int try_to_run_init_process(const char *init_filename)
85461 return ret;
85462 }
85463
85464+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85465+extern int gr_init_ran;
85466+#endif
85467+
85468 static noinline void __init kernel_init_freeable(void);
85469
85470 static int __ref kernel_init(void *unused)
85471@@ -859,6 +933,11 @@ static int __ref kernel_init(void *unused)
85472 ramdisk_execute_command, ret);
85473 }
85474
85475+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85476+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
85477+ gr_init_ran = 1;
85478+#endif
85479+
85480 /*
85481 * We try each of these until one succeeds.
85482 *
85483@@ -914,7 +993,7 @@ static noinline void __init kernel_init_freeable(void)
85484 do_basic_setup();
85485
85486 /* Open the /dev/console on the rootfs, this should never fail */
85487- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85488+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85489 pr_err("Warning: unable to open an initial console.\n");
85490
85491 (void) sys_dup(0);
85492@@ -927,11 +1006,13 @@ static noinline void __init kernel_init_freeable(void)
85493 if (!ramdisk_execute_command)
85494 ramdisk_execute_command = "/init";
85495
85496- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85497+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85498 ramdisk_execute_command = NULL;
85499 prepare_namespace();
85500 }
85501
85502+ grsecurity_init();
85503+
85504 /*
85505 * Ok, we have completed the initial bootup, and
85506 * we're essentially up and running. Get rid of the
85507diff --git a/ipc/compat.c b/ipc/compat.c
85508index 45d035d..e4a7f99 100644
85509--- a/ipc/compat.c
85510+++ b/ipc/compat.c
85511@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85512 COMPAT_SHMLBA);
85513 if (err < 0)
85514 return err;
85515- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85516+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85517 }
85518 case SHMDT:
85519 return sys_shmdt(compat_ptr(ptr));
85520diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85521index 998d31b..30c24df 100644
85522--- a/ipc/ipc_sysctl.c
85523+++ b/ipc/ipc_sysctl.c
85524@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85525 static int proc_ipc_dointvec(ctl_table *table, int write,
85526 void __user *buffer, size_t *lenp, loff_t *ppos)
85527 {
85528- struct ctl_table ipc_table;
85529+ ctl_table_no_const ipc_table;
85530
85531 memcpy(&ipc_table, table, sizeof(ipc_table));
85532 ipc_table.data = get_ipc(table);
85533@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85534 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85535 void __user *buffer, size_t *lenp, loff_t *ppos)
85536 {
85537- struct ctl_table ipc_table;
85538+ ctl_table_no_const ipc_table;
85539
85540 memcpy(&ipc_table, table, sizeof(ipc_table));
85541 ipc_table.data = get_ipc(table);
85542@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85543 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85544 void __user *buffer, size_t *lenp, loff_t *ppos)
85545 {
85546- struct ctl_table ipc_table;
85547+ ctl_table_no_const ipc_table;
85548 size_t lenp_bef = *lenp;
85549 int rc;
85550
85551@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85552 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85553 void __user *buffer, size_t *lenp, loff_t *ppos)
85554 {
85555- struct ctl_table ipc_table;
85556+ ctl_table_no_const ipc_table;
85557 memcpy(&ipc_table, table, sizeof(ipc_table));
85558 ipc_table.data = get_ipc(table);
85559
85560@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85561 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85562 void __user *buffer, size_t *lenp, loff_t *ppos)
85563 {
85564- struct ctl_table ipc_table;
85565+ ctl_table_no_const ipc_table;
85566 size_t lenp_bef = *lenp;
85567 int oldval;
85568 int rc;
85569diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85570index 5bb8bfe..a38ec05 100644
85571--- a/ipc/mq_sysctl.c
85572+++ b/ipc/mq_sysctl.c
85573@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85574 static int proc_mq_dointvec(ctl_table *table, int write,
85575 void __user *buffer, size_t *lenp, loff_t *ppos)
85576 {
85577- struct ctl_table mq_table;
85578+ ctl_table_no_const mq_table;
85579 memcpy(&mq_table, table, sizeof(mq_table));
85580 mq_table.data = get_mq(table);
85581
85582@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85583 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85584 void __user *buffer, size_t *lenp, loff_t *ppos)
85585 {
85586- struct ctl_table mq_table;
85587+ ctl_table_no_const mq_table;
85588 memcpy(&mq_table, table, sizeof(mq_table));
85589 mq_table.data = get_mq(table);
85590
85591diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85592index 4fcf39a..d3cc2ec 100644
85593--- a/ipc/mqueue.c
85594+++ b/ipc/mqueue.c
85595@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85596 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85597 info->attr.mq_msgsize);
85598
85599+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85600 spin_lock(&mq_lock);
85601 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85602 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85603diff --git a/ipc/msg.c b/ipc/msg.c
85604index 6498531..b0ff3c8 100644
85605--- a/ipc/msg.c
85606+++ b/ipc/msg.c
85607@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85608 return security_msg_queue_associate(msq, msgflg);
85609 }
85610
85611+static struct ipc_ops msg_ops = {
85612+ .getnew = newque,
85613+ .associate = msg_security,
85614+ .more_checks = NULL
85615+};
85616+
85617 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85618 {
85619 struct ipc_namespace *ns;
85620- struct ipc_ops msg_ops;
85621 struct ipc_params msg_params;
85622
85623 ns = current->nsproxy->ipc_ns;
85624
85625- msg_ops.getnew = newque;
85626- msg_ops.associate = msg_security;
85627- msg_ops.more_checks = NULL;
85628-
85629 msg_params.key = key;
85630 msg_params.flg = msgflg;
85631
85632diff --git a/ipc/sem.c b/ipc/sem.c
85633index bee5554..e9af81dd 100644
85634--- a/ipc/sem.c
85635+++ b/ipc/sem.c
85636@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85637 return 0;
85638 }
85639
85640+static struct ipc_ops sem_ops = {
85641+ .getnew = newary,
85642+ .associate = sem_security,
85643+ .more_checks = sem_more_checks
85644+};
85645+
85646 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85647 {
85648 struct ipc_namespace *ns;
85649- struct ipc_ops sem_ops;
85650 struct ipc_params sem_params;
85651
85652 ns = current->nsproxy->ipc_ns;
85653@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85654 if (nsems < 0 || nsems > ns->sc_semmsl)
85655 return -EINVAL;
85656
85657- sem_ops.getnew = newary;
85658- sem_ops.associate = sem_security;
85659- sem_ops.more_checks = sem_more_checks;
85660-
85661 sem_params.key = key;
85662 sem_params.flg = semflg;
85663 sem_params.u.nsems = nsems;
85664diff --git a/ipc/shm.c b/ipc/shm.c
85665index 7645961..afc7f02 100644
85666--- a/ipc/shm.c
85667+++ b/ipc/shm.c
85668@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85669 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85670 #endif
85671
85672+#ifdef CONFIG_GRKERNSEC
85673+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85674+ const time_t shm_createtime, const kuid_t cuid,
85675+ const int shmid);
85676+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85677+ const time_t shm_createtime);
85678+#endif
85679+
85680 void shm_init_ns(struct ipc_namespace *ns)
85681 {
85682 ns->shm_ctlmax = SHMMAX;
85683@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85684 shp->shm_lprid = 0;
85685 shp->shm_atim = shp->shm_dtim = 0;
85686 shp->shm_ctim = get_seconds();
85687+#ifdef CONFIG_GRKERNSEC
85688+ {
85689+ struct timespec timeval;
85690+ do_posix_clock_monotonic_gettime(&timeval);
85691+
85692+ shp->shm_createtime = timeval.tv_sec;
85693+ }
85694+#endif
85695 shp->shm_segsz = size;
85696 shp->shm_nattch = 0;
85697 shp->shm_file = file;
85698@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85699 return 0;
85700 }
85701
85702+static struct ipc_ops shm_ops = {
85703+ .getnew = newseg,
85704+ .associate = shm_security,
85705+ .more_checks = shm_more_checks
85706+};
85707+
85708 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85709 {
85710 struct ipc_namespace *ns;
85711- struct ipc_ops shm_ops;
85712 struct ipc_params shm_params;
85713
85714 ns = current->nsproxy->ipc_ns;
85715
85716- shm_ops.getnew = newseg;
85717- shm_ops.associate = shm_security;
85718- shm_ops.more_checks = shm_more_checks;
85719-
85720 shm_params.key = key;
85721 shm_params.flg = shmflg;
85722 shm_params.u.size = size;
85723@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85724 f_mode = FMODE_READ | FMODE_WRITE;
85725 }
85726 if (shmflg & SHM_EXEC) {
85727+
85728+#ifdef CONFIG_PAX_MPROTECT
85729+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85730+ goto out;
85731+#endif
85732+
85733 prot |= PROT_EXEC;
85734 acc_mode |= S_IXUGO;
85735 }
85736@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85737 if (err)
85738 goto out_unlock;
85739
85740+#ifdef CONFIG_GRKERNSEC
85741+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85742+ shp->shm_perm.cuid, shmid) ||
85743+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85744+ err = -EACCES;
85745+ goto out_unlock;
85746+ }
85747+#endif
85748+
85749 ipc_lock_object(&shp->shm_perm);
85750
85751 /* check if shm_destroy() is tearing down shp */
85752@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85753 path = shp->shm_file->f_path;
85754 path_get(&path);
85755 shp->shm_nattch++;
85756+#ifdef CONFIG_GRKERNSEC
85757+ shp->shm_lapid = current->pid;
85758+#endif
85759 size = i_size_read(path.dentry->d_inode);
85760 ipc_unlock_object(&shp->shm_perm);
85761 rcu_read_unlock();
85762diff --git a/ipc/util.c b/ipc/util.c
85763index 2eb0d1e..0308564 100644
85764--- a/ipc/util.c
85765+++ b/ipc/util.c
85766@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85767 int (*show)(struct seq_file *, void *);
85768 };
85769
85770+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85771+
85772 static void ipc_memory_notifier(struct work_struct *work)
85773 {
85774 ipcns_notify(IPCNS_MEMCHANGED);
85775@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85776 granted_mode >>= 6;
85777 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85778 granted_mode >>= 3;
85779+
85780+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85781+ return -1;
85782+
85783 /* is there some bit set in requested_mode but not in granted_mode? */
85784 if ((requested_mode & ~granted_mode & 0007) &&
85785 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85786diff --git a/kernel/acct.c b/kernel/acct.c
85787index 8d6e145..33e0b1e 100644
85788--- a/kernel/acct.c
85789+++ b/kernel/acct.c
85790@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85791 */
85792 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85793 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85794- file->f_op->write(file, (char *)&ac,
85795+ file->f_op->write(file, (char __force_user *)&ac,
85796 sizeof(acct_t), &file->f_pos);
85797 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85798 set_fs(fs);
85799diff --git a/kernel/audit.c b/kernel/audit.c
85800index 47845c5..bd9dd5b 100644
85801--- a/kernel/audit.c
85802+++ b/kernel/audit.c
85803@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85804 3) suppressed due to audit_rate_limit
85805 4) suppressed due to audit_backlog_limit
85806 */
85807-static atomic_t audit_lost = ATOMIC_INIT(0);
85808+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85809
85810 /* The netlink socket. */
85811 static struct sock *audit_sock;
85812@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85813 unsigned long now;
85814 int print;
85815
85816- atomic_inc(&audit_lost);
85817+ atomic_inc_unchecked(&audit_lost);
85818
85819 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85820
85821@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85822 if (print) {
85823 if (printk_ratelimit())
85824 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85825- atomic_read(&audit_lost),
85826+ atomic_read_unchecked(&audit_lost),
85827 audit_rate_limit,
85828 audit_backlog_limit);
85829 audit_panic(message);
85830@@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85831 s.pid = audit_pid;
85832 s.rate_limit = audit_rate_limit;
85833 s.backlog_limit = audit_backlog_limit;
85834- s.lost = atomic_read(&audit_lost);
85835+ s.lost = atomic_read_unchecked(&audit_lost);
85836 s.backlog = skb_queue_len(&audit_skb_queue);
85837 s.version = AUDIT_VERSION_LATEST;
85838 s.backlog_wait_time = audit_backlog_wait_time;
85839diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85840index 21eae3c..66db239 100644
85841--- a/kernel/auditsc.c
85842+++ b/kernel/auditsc.c
85843@@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85844 }
85845
85846 /* global counter which is incremented every time something logs in */
85847-static atomic_t session_id = ATOMIC_INIT(0);
85848+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85849
85850 static int audit_set_loginuid_perm(kuid_t loginuid)
85851 {
85852@@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
85853
85854 /* are we setting or clearing? */
85855 if (uid_valid(loginuid))
85856- sessionid = (unsigned int)atomic_inc_return(&session_id);
85857+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85858
85859 task->sessionid = sessionid;
85860 task->loginuid = loginuid;
85861diff --git a/kernel/capability.c b/kernel/capability.c
85862index 24663b3..b926ae1 100644
85863--- a/kernel/capability.c
85864+++ b/kernel/capability.c
85865@@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85866 * before modification is attempted and the application
85867 * fails.
85868 */
85869+ if (tocopy > ARRAY_SIZE(kdata))
85870+ return -EFAULT;
85871+
85872 if (copy_to_user(dataptr, kdata, tocopy
85873 * sizeof(struct __user_cap_data_struct))) {
85874 return -EFAULT;
85875@@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
85876 int ret;
85877
85878 rcu_read_lock();
85879- ret = security_capable(__task_cred(t), ns, cap);
85880+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85881+ gr_task_is_capable(t, __task_cred(t), cap);
85882 rcu_read_unlock();
85883
85884- return (ret == 0);
85885+ return ret;
85886 }
85887
85888 /**
85889@@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85890 int ret;
85891
85892 rcu_read_lock();
85893- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85894+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85895 rcu_read_unlock();
85896
85897- return (ret == 0);
85898+ return ret;
85899 }
85900
85901 /**
85902@@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85903 BUG();
85904 }
85905
85906- if (security_capable(current_cred(), ns, cap) == 0) {
85907+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85908 current->flags |= PF_SUPERPRIV;
85909 return true;
85910 }
85911@@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85912 }
85913 EXPORT_SYMBOL(ns_capable);
85914
85915+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85916+{
85917+ if (unlikely(!cap_valid(cap))) {
85918+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85919+ BUG();
85920+ }
85921+
85922+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85923+ current->flags |= PF_SUPERPRIV;
85924+ return true;
85925+ }
85926+ return false;
85927+}
85928+EXPORT_SYMBOL(ns_capable_nolog);
85929+
85930 /**
85931 * file_ns_capable - Determine if the file's opener had a capability in effect
85932 * @file: The file we want to check
85933@@ -423,6 +442,12 @@ bool capable(int cap)
85934 }
85935 EXPORT_SYMBOL(capable);
85936
85937+bool capable_nolog(int cap)
85938+{
85939+ return ns_capable_nolog(&init_user_ns, cap);
85940+}
85941+EXPORT_SYMBOL(capable_nolog);
85942+
85943 /**
85944 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
85945 * @inode: The inode in question
85946@@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
85947 kgid_has_mapping(ns, inode->i_gid);
85948 }
85949 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
85950+
85951+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
85952+{
85953+ struct user_namespace *ns = current_user_ns();
85954+
85955+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
85956+ kgid_has_mapping(ns, inode->i_gid);
85957+}
85958+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
85959diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85960index 073226b..969c746 100644
85961--- a/kernel/cgroup.c
85962+++ b/kernel/cgroup.c
85963@@ -4808,7 +4808,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85964 struct task_struct *task;
85965 int count = 0;
85966
85967- seq_printf(seq, "css_set %p\n", cset);
85968+ seq_printf(seq, "css_set %pK\n", cset);
85969
85970 list_for_each_entry(task, &cset->tasks, cg_list) {
85971 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
85972diff --git a/kernel/compat.c b/kernel/compat.c
85973index e40b043..3da8f51 100644
85974--- a/kernel/compat.c
85975+++ b/kernel/compat.c
85976@@ -13,6 +13,7 @@
85977
85978 #include <linux/linkage.h>
85979 #include <linux/compat.h>
85980+#include <linux/module.h>
85981 #include <linux/errno.h>
85982 #include <linux/time.h>
85983 #include <linux/signal.h>
85984@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85985 mm_segment_t oldfs;
85986 long ret;
85987
85988- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85989+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85990 oldfs = get_fs();
85991 set_fs(KERNEL_DS);
85992 ret = hrtimer_nanosleep_restart(restart);
85993@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
85994 oldfs = get_fs();
85995 set_fs(KERNEL_DS);
85996 ret = hrtimer_nanosleep(&tu,
85997- rmtp ? (struct timespec __user *)&rmt : NULL,
85998+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85999 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
86000 set_fs(oldfs);
86001
86002@@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
86003 mm_segment_t old_fs = get_fs();
86004
86005 set_fs(KERNEL_DS);
86006- ret = sys_sigpending((old_sigset_t __user *) &s);
86007+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
86008 set_fs(old_fs);
86009 if (ret == 0)
86010 ret = put_user(s, set);
86011@@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
86012 mm_segment_t old_fs = get_fs();
86013
86014 set_fs(KERNEL_DS);
86015- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
86016+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
86017 set_fs(old_fs);
86018
86019 if (!ret) {
86020@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
86021 set_fs (KERNEL_DS);
86022 ret = sys_wait4(pid,
86023 (stat_addr ?
86024- (unsigned int __user *) &status : NULL),
86025- options, (struct rusage __user *) &r);
86026+ (unsigned int __force_user *) &status : NULL),
86027+ options, (struct rusage __force_user *) &r);
86028 set_fs (old_fs);
86029
86030 if (ret > 0) {
86031@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
86032 memset(&info, 0, sizeof(info));
86033
86034 set_fs(KERNEL_DS);
86035- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
86036- uru ? (struct rusage __user *)&ru : NULL);
86037+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
86038+ uru ? (struct rusage __force_user *)&ru : NULL);
86039 set_fs(old_fs);
86040
86041 if ((ret < 0) || (info.si_signo == 0))
86042@@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
86043 oldfs = get_fs();
86044 set_fs(KERNEL_DS);
86045 err = sys_timer_settime(timer_id, flags,
86046- (struct itimerspec __user *) &newts,
86047- (struct itimerspec __user *) &oldts);
86048+ (struct itimerspec __force_user *) &newts,
86049+ (struct itimerspec __force_user *) &oldts);
86050 set_fs(oldfs);
86051 if (!err && old && put_compat_itimerspec(old, &oldts))
86052 return -EFAULT;
86053@@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
86054 oldfs = get_fs();
86055 set_fs(KERNEL_DS);
86056 err = sys_timer_gettime(timer_id,
86057- (struct itimerspec __user *) &ts);
86058+ (struct itimerspec __force_user *) &ts);
86059 set_fs(oldfs);
86060 if (!err && put_compat_itimerspec(setting, &ts))
86061 return -EFAULT;
86062@@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
86063 oldfs = get_fs();
86064 set_fs(KERNEL_DS);
86065 err = sys_clock_settime(which_clock,
86066- (struct timespec __user *) &ts);
86067+ (struct timespec __force_user *) &ts);
86068 set_fs(oldfs);
86069 return err;
86070 }
86071@@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
86072 oldfs = get_fs();
86073 set_fs(KERNEL_DS);
86074 err = sys_clock_gettime(which_clock,
86075- (struct timespec __user *) &ts);
86076+ (struct timespec __force_user *) &ts);
86077 set_fs(oldfs);
86078 if (!err && compat_put_timespec(&ts, tp))
86079 return -EFAULT;
86080@@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
86081
86082 oldfs = get_fs();
86083 set_fs(KERNEL_DS);
86084- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
86085+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
86086 set_fs(oldfs);
86087
86088 err = compat_put_timex(utp, &txc);
86089@@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
86090 oldfs = get_fs();
86091 set_fs(KERNEL_DS);
86092 err = sys_clock_getres(which_clock,
86093- (struct timespec __user *) &ts);
86094+ (struct timespec __force_user *) &ts);
86095 set_fs(oldfs);
86096 if (!err && tp && compat_put_timespec(&ts, tp))
86097 return -EFAULT;
86098@@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
86099 struct timespec tu;
86100 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
86101
86102- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
86103+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
86104 oldfs = get_fs();
86105 set_fs(KERNEL_DS);
86106 err = clock_nanosleep_restart(restart);
86107@@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
86108 oldfs = get_fs();
86109 set_fs(KERNEL_DS);
86110 err = sys_clock_nanosleep(which_clock, flags,
86111- (struct timespec __user *) &in,
86112- (struct timespec __user *) &out);
86113+ (struct timespec __force_user *) &in,
86114+ (struct timespec __force_user *) &out);
86115 set_fs(oldfs);
86116
86117 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
86118@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
86119 mm_segment_t old_fs = get_fs();
86120
86121 set_fs(KERNEL_DS);
86122- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
86123+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
86124 set_fs(old_fs);
86125 if (compat_put_timespec(&t, interval))
86126 return -EFAULT;
86127diff --git a/kernel/configs.c b/kernel/configs.c
86128index c18b1f1..b9a0132 100644
86129--- a/kernel/configs.c
86130+++ b/kernel/configs.c
86131@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
86132 struct proc_dir_entry *entry;
86133
86134 /* create the current config file */
86135+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
86136+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
86137+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
86138+ &ikconfig_file_ops);
86139+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86140+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
86141+ &ikconfig_file_ops);
86142+#endif
86143+#else
86144 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
86145 &ikconfig_file_ops);
86146+#endif
86147+
86148 if (!entry)
86149 return -ENOMEM;
86150
86151diff --git a/kernel/cred.c b/kernel/cred.c
86152index e0573a4..26c0fd3 100644
86153--- a/kernel/cred.c
86154+++ b/kernel/cred.c
86155@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
86156 validate_creds(cred);
86157 alter_cred_subscribers(cred, -1);
86158 put_cred(cred);
86159+
86160+#ifdef CONFIG_GRKERNSEC_SETXID
86161+ cred = (struct cred *) tsk->delayed_cred;
86162+ if (cred != NULL) {
86163+ tsk->delayed_cred = NULL;
86164+ validate_creds(cred);
86165+ alter_cred_subscribers(cred, -1);
86166+ put_cred(cred);
86167+ }
86168+#endif
86169 }
86170
86171 /**
86172@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
86173 * Always returns 0 thus allowing this function to be tail-called at the end
86174 * of, say, sys_setgid().
86175 */
86176-int commit_creds(struct cred *new)
86177+static int __commit_creds(struct cred *new)
86178 {
86179 struct task_struct *task = current;
86180 const struct cred *old = task->real_cred;
86181@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
86182
86183 get_cred(new); /* we will require a ref for the subj creds too */
86184
86185+ gr_set_role_label(task, new->uid, new->gid);
86186+
86187 /* dumpability changes */
86188 if (!uid_eq(old->euid, new->euid) ||
86189 !gid_eq(old->egid, new->egid) ||
86190@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
86191 put_cred(old);
86192 return 0;
86193 }
86194+#ifdef CONFIG_GRKERNSEC_SETXID
86195+extern int set_user(struct cred *new);
86196+
86197+void gr_delayed_cred_worker(void)
86198+{
86199+ const struct cred *new = current->delayed_cred;
86200+ struct cred *ncred;
86201+
86202+ current->delayed_cred = NULL;
86203+
86204+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
86205+ // from doing get_cred on it when queueing this
86206+ put_cred(new);
86207+ return;
86208+ } else if (new == NULL)
86209+ return;
86210+
86211+ ncred = prepare_creds();
86212+ if (!ncred)
86213+ goto die;
86214+ // uids
86215+ ncred->uid = new->uid;
86216+ ncred->euid = new->euid;
86217+ ncred->suid = new->suid;
86218+ ncred->fsuid = new->fsuid;
86219+ // gids
86220+ ncred->gid = new->gid;
86221+ ncred->egid = new->egid;
86222+ ncred->sgid = new->sgid;
86223+ ncred->fsgid = new->fsgid;
86224+ // groups
86225+ set_groups(ncred, new->group_info);
86226+ // caps
86227+ ncred->securebits = new->securebits;
86228+ ncred->cap_inheritable = new->cap_inheritable;
86229+ ncred->cap_permitted = new->cap_permitted;
86230+ ncred->cap_effective = new->cap_effective;
86231+ ncred->cap_bset = new->cap_bset;
86232+
86233+ if (set_user(ncred)) {
86234+ abort_creds(ncred);
86235+ goto die;
86236+ }
86237+
86238+ // from doing get_cred on it when queueing this
86239+ put_cred(new);
86240+
86241+ __commit_creds(ncred);
86242+ return;
86243+die:
86244+ // from doing get_cred on it when queueing this
86245+ put_cred(new);
86246+ do_group_exit(SIGKILL);
86247+}
86248+#endif
86249+
86250+int commit_creds(struct cred *new)
86251+{
86252+#ifdef CONFIG_GRKERNSEC_SETXID
86253+ int ret;
86254+ int schedule_it = 0;
86255+ struct task_struct *t;
86256+ unsigned oldsecurebits = current_cred()->securebits;
86257+
86258+ /* we won't get called with tasklist_lock held for writing
86259+ and interrupts disabled as the cred struct in that case is
86260+ init_cred
86261+ */
86262+ if (grsec_enable_setxid && !current_is_single_threaded() &&
86263+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
86264+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
86265+ schedule_it = 1;
86266+ }
86267+ ret = __commit_creds(new);
86268+ if (schedule_it) {
86269+ rcu_read_lock();
86270+ read_lock(&tasklist_lock);
86271+ for (t = next_thread(current); t != current;
86272+ t = next_thread(t)) {
86273+ /* we'll check if the thread has uid 0 in
86274+ * the delayed worker routine
86275+ */
86276+ if (task_securebits(t) == oldsecurebits &&
86277+ t->delayed_cred == NULL) {
86278+ t->delayed_cred = get_cred(new);
86279+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86280+ set_tsk_need_resched(t);
86281+ }
86282+ }
86283+ read_unlock(&tasklist_lock);
86284+ rcu_read_unlock();
86285+ }
86286+
86287+ return ret;
86288+#else
86289+ return __commit_creds(new);
86290+#endif
86291+}
86292+
86293 EXPORT_SYMBOL(commit_creds);
86294
86295 /**
86296diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86297index 2956c8d..cfe1e2e 100644
86298--- a/kernel/debug/debug_core.c
86299+++ b/kernel/debug/debug_core.c
86300@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86301 */
86302 static atomic_t masters_in_kgdb;
86303 static atomic_t slaves_in_kgdb;
86304-static atomic_t kgdb_break_tasklet_var;
86305+static atomic_unchecked_t kgdb_break_tasklet_var;
86306 atomic_t kgdb_setting_breakpoint;
86307
86308 struct task_struct *kgdb_usethread;
86309@@ -134,7 +134,7 @@ int kgdb_single_step;
86310 static pid_t kgdb_sstep_pid;
86311
86312 /* to keep track of the CPU which is doing the single stepping*/
86313-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86314+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86315
86316 /*
86317 * If you are debugging a problem where roundup (the collection of
86318@@ -549,7 +549,7 @@ return_normal:
86319 * kernel will only try for the value of sstep_tries before
86320 * giving up and continuing on.
86321 */
86322- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86323+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86324 (kgdb_info[cpu].task &&
86325 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86326 atomic_set(&kgdb_active, -1);
86327@@ -647,8 +647,8 @@ cpu_master_loop:
86328 }
86329
86330 kgdb_restore:
86331- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86332- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86333+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86334+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86335 if (kgdb_info[sstep_cpu].task)
86336 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86337 else
86338@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
86339 static void kgdb_tasklet_bpt(unsigned long ing)
86340 {
86341 kgdb_breakpoint();
86342- atomic_set(&kgdb_break_tasklet_var, 0);
86343+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86344 }
86345
86346 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86347
86348 void kgdb_schedule_breakpoint(void)
86349 {
86350- if (atomic_read(&kgdb_break_tasklet_var) ||
86351+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86352 atomic_read(&kgdb_active) != -1 ||
86353 atomic_read(&kgdb_setting_breakpoint))
86354 return;
86355- atomic_inc(&kgdb_break_tasklet_var);
86356+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
86357 tasklet_schedule(&kgdb_tasklet_breakpoint);
86358 }
86359 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86360diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86361index 0b097c8..11dd5c5 100644
86362--- a/kernel/debug/kdb/kdb_main.c
86363+++ b/kernel/debug/kdb/kdb_main.c
86364@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86365 continue;
86366
86367 kdb_printf("%-20s%8u 0x%p ", mod->name,
86368- mod->core_size, (void *)mod);
86369+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
86370 #ifdef CONFIG_MODULE_UNLOAD
86371 kdb_printf("%4ld ", module_refcount(mod));
86372 #endif
86373@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86374 kdb_printf(" (Loading)");
86375 else
86376 kdb_printf(" (Live)");
86377- kdb_printf(" 0x%p", mod->module_core);
86378+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86379
86380 #ifdef CONFIG_MODULE_UNLOAD
86381 {
86382diff --git a/kernel/events/core.c b/kernel/events/core.c
86383index 935271c..8888f93 100644
86384--- a/kernel/events/core.c
86385+++ b/kernel/events/core.c
86386@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86387 * 0 - disallow raw tracepoint access for unpriv
86388 * 1 - disallow cpu events for unpriv
86389 * 2 - disallow kernel profiling for unpriv
86390+ * 3 - disallow all unpriv perf event use
86391 */
86392-int sysctl_perf_event_paranoid __read_mostly = 1;
86393+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86394+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86395+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86396+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86397+#else
86398+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86399+#endif
86400
86401 /* Minimum for 512 kiB + 1 user control page */
86402 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86403@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86404
86405 tmp *= sysctl_perf_cpu_time_max_percent;
86406 do_div(tmp, 100);
86407- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86408+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86409 }
86410
86411 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86412@@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86413 }
86414 }
86415
86416-static atomic64_t perf_event_id;
86417+static atomic64_unchecked_t perf_event_id;
86418
86419 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86420 enum event_type_t event_type);
86421@@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
86422
86423 static inline u64 perf_event_count(struct perf_event *event)
86424 {
86425- return local64_read(&event->count) + atomic64_read(&event->child_count);
86426+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86427 }
86428
86429 static u64 perf_event_read(struct perf_event *event)
86430@@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86431 mutex_lock(&event->child_mutex);
86432 total += perf_event_read(event);
86433 *enabled += event->total_time_enabled +
86434- atomic64_read(&event->child_total_time_enabled);
86435+ atomic64_read_unchecked(&event->child_total_time_enabled);
86436 *running += event->total_time_running +
86437- atomic64_read(&event->child_total_time_running);
86438+ atomic64_read_unchecked(&event->child_total_time_running);
86439
86440 list_for_each_entry(child, &event->child_list, child_list) {
86441 total += perf_event_read(child);
86442@@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
86443 userpg->offset -= local64_read(&event->hw.prev_count);
86444
86445 userpg->time_enabled = enabled +
86446- atomic64_read(&event->child_total_time_enabled);
86447+ atomic64_read_unchecked(&event->child_total_time_enabled);
86448
86449 userpg->time_running = running +
86450- atomic64_read(&event->child_total_time_running);
86451+ atomic64_read_unchecked(&event->child_total_time_running);
86452
86453 arch_perf_update_userpage(userpg, now);
86454
86455@@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86456
86457 /* Data. */
86458 sp = perf_user_stack_pointer(regs);
86459- rem = __output_copy_user(handle, (void *) sp, dump_size);
86460+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86461 dyn_size = dump_size - rem;
86462
86463 perf_output_skip(handle, rem);
86464@@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86465 values[n++] = perf_event_count(event);
86466 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86467 values[n++] = enabled +
86468- atomic64_read(&event->child_total_time_enabled);
86469+ atomic64_read_unchecked(&event->child_total_time_enabled);
86470 }
86471 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86472 values[n++] = running +
86473- atomic64_read(&event->child_total_time_running);
86474+ atomic64_read_unchecked(&event->child_total_time_running);
86475 }
86476 if (read_format & PERF_FORMAT_ID)
86477 values[n++] = primary_event_id(event);
86478@@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86479 event->parent = parent_event;
86480
86481 event->ns = get_pid_ns(task_active_pid_ns(current));
86482- event->id = atomic64_inc_return(&perf_event_id);
86483+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
86484
86485 event->state = PERF_EVENT_STATE_INACTIVE;
86486
86487@@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
86488 if (flags & ~PERF_FLAG_ALL)
86489 return -EINVAL;
86490
86491+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86492+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86493+ return -EACCES;
86494+#endif
86495+
86496 err = perf_copy_attr(attr_uptr, &attr);
86497 if (err)
86498 return err;
86499@@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
86500 /*
86501 * Add back the child's count to the parent's count:
86502 */
86503- atomic64_add(child_val, &parent_event->child_count);
86504- atomic64_add(child_event->total_time_enabled,
86505+ atomic64_add_unchecked(child_val, &parent_event->child_count);
86506+ atomic64_add_unchecked(child_event->total_time_enabled,
86507 &parent_event->child_total_time_enabled);
86508- atomic64_add(child_event->total_time_running,
86509+ atomic64_add_unchecked(child_event->total_time_running,
86510 &parent_event->child_total_time_running);
86511
86512 /*
86513diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86514index 569b2187..19940d9 100644
86515--- a/kernel/events/internal.h
86516+++ b/kernel/events/internal.h
86517@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86518 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86519 }
86520
86521-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86522+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86523 static inline unsigned long \
86524 func_name(struct perf_output_handle *handle, \
86525- const void *buf, unsigned long len) \
86526+ const void user *buf, unsigned long len) \
86527 { \
86528 unsigned long size, written; \
86529 \
86530@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86531 return 0;
86532 }
86533
86534-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86535+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86536
86537 static inline unsigned long
86538 memcpy_skip(void *dst, const void *src, unsigned long n)
86539@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86540 return 0;
86541 }
86542
86543-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86544+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86545
86546 #ifndef arch_perf_out_copy_user
86547 #define arch_perf_out_copy_user arch_perf_out_copy_user
86548@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86549 }
86550 #endif
86551
86552-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86553+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86554
86555 /* Callchain handling */
86556 extern struct perf_callchain_entry *
86557diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86558index 04709b6..d330828 100644
86559--- a/kernel/events/uprobes.c
86560+++ b/kernel/events/uprobes.c
86561@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86562 {
86563 struct page *page;
86564 uprobe_opcode_t opcode;
86565- int result;
86566+ long result;
86567
86568 pagefault_disable();
86569 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86570diff --git a/kernel/exit.c b/kernel/exit.c
86571index 6ed6a1d..edecb0e 100644
86572--- a/kernel/exit.c
86573+++ b/kernel/exit.c
86574@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86575 struct task_struct *leader;
86576 int zap_leader;
86577 repeat:
86578+#ifdef CONFIG_NET
86579+ gr_del_task_from_ip_table(p);
86580+#endif
86581+
86582 /* don't need to get the RCU readlock here - the process is dead and
86583 * can't be modifying its own credentials. But shut RCU-lockdep up */
86584 rcu_read_lock();
86585@@ -330,7 +334,7 @@ int allow_signal(int sig)
86586 * know it'll be handled, so that they don't get converted to
86587 * SIGKILL or just silently dropped.
86588 */
86589- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86590+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86591 recalc_sigpending();
86592 spin_unlock_irq(&current->sighand->siglock);
86593 return 0;
86594@@ -699,6 +703,8 @@ void do_exit(long code)
86595 struct task_struct *tsk = current;
86596 int group_dead;
86597
86598+ set_fs(USER_DS);
86599+
86600 profile_task_exit(tsk);
86601
86602 WARN_ON(blk_needs_flush_plug(tsk));
86603@@ -715,7 +721,6 @@ void do_exit(long code)
86604 * mm_release()->clear_child_tid() from writing to a user-controlled
86605 * kernel address.
86606 */
86607- set_fs(USER_DS);
86608
86609 ptrace_event(PTRACE_EVENT_EXIT, code);
86610
86611@@ -774,6 +779,9 @@ void do_exit(long code)
86612 tsk->exit_code = code;
86613 taskstats_exit(tsk, group_dead);
86614
86615+ gr_acl_handle_psacct(tsk, code);
86616+ gr_acl_handle_exit();
86617+
86618 exit_mm(tsk);
86619
86620 if (group_dead)
86621@@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86622 * Take down every thread in the group. This is called by fatal signals
86623 * as well as by sys_exit_group (below).
86624 */
86625-void
86626+__noreturn void
86627 do_group_exit(int exit_code)
86628 {
86629 struct signal_struct *sig = current->signal;
86630diff --git a/kernel/fork.c b/kernel/fork.c
86631index 68b9226..0700bf6 100644
86632--- a/kernel/fork.c
86633+++ b/kernel/fork.c
86634@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86635 # endif
86636 #endif
86637
86638+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86639+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86640+ int node, void **lowmem_stack)
86641+{
86642+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
86643+ void *ret = NULL;
86644+ unsigned int i;
86645+
86646+ *lowmem_stack = alloc_thread_info_node(tsk, node);
86647+ if (*lowmem_stack == NULL)
86648+ goto out;
86649+
86650+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86651+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86652+
86653+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86654+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86655+ if (ret == NULL) {
86656+ free_thread_info(*lowmem_stack);
86657+ *lowmem_stack = NULL;
86658+ }
86659+
86660+out:
86661+ return ret;
86662+}
86663+
86664+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86665+{
86666+ unmap_process_stacks(tsk);
86667+}
86668+#else
86669+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86670+ int node, void **lowmem_stack)
86671+{
86672+ return alloc_thread_info_node(tsk, node);
86673+}
86674+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86675+{
86676+ free_thread_info(ti);
86677+}
86678+#endif
86679+
86680 /* SLAB cache for signal_struct structures (tsk->signal) */
86681 static struct kmem_cache *signal_cachep;
86682
86683@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86684 /* SLAB cache for mm_struct structures (tsk->mm) */
86685 static struct kmem_cache *mm_cachep;
86686
86687-static void account_kernel_stack(struct thread_info *ti, int account)
86688+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86689 {
86690+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86691+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86692+#else
86693 struct zone *zone = page_zone(virt_to_page(ti));
86694+#endif
86695
86696 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86697 }
86698
86699 void free_task(struct task_struct *tsk)
86700 {
86701- account_kernel_stack(tsk->stack, -1);
86702+ account_kernel_stack(tsk, tsk->stack, -1);
86703 arch_release_thread_info(tsk->stack);
86704- free_thread_info(tsk->stack);
86705+ gr_free_thread_info(tsk, tsk->stack);
86706 rt_mutex_debug_task_free(tsk);
86707 ftrace_graph_exit_task(tsk);
86708 put_seccomp_filter(tsk);
86709@@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86710 struct task_struct *tsk;
86711 struct thread_info *ti;
86712 unsigned long *stackend;
86713+ void *lowmem_stack;
86714 int node = tsk_fork_get_node(orig);
86715 int err;
86716
86717@@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86718 if (!tsk)
86719 return NULL;
86720
86721- ti = alloc_thread_info_node(tsk, node);
86722+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86723 if (!ti)
86724 goto free_tsk;
86725
86726@@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86727 goto free_ti;
86728
86729 tsk->stack = ti;
86730+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86731+ tsk->lowmem_stack = lowmem_stack;
86732+#endif
86733
86734 setup_thread_stack(tsk, orig);
86735 clear_user_return_notifier(tsk);
86736@@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86737 *stackend = STACK_END_MAGIC; /* for overflow detection */
86738
86739 #ifdef CONFIG_CC_STACKPROTECTOR
86740- tsk->stack_canary = get_random_int();
86741+ tsk->stack_canary = pax_get_random_long();
86742 #endif
86743
86744 /*
86745@@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86746 tsk->splice_pipe = NULL;
86747 tsk->task_frag.page = NULL;
86748
86749- account_kernel_stack(ti, 1);
86750+ account_kernel_stack(tsk, ti, 1);
86751
86752 return tsk;
86753
86754 free_ti:
86755- free_thread_info(ti);
86756+ gr_free_thread_info(tsk, ti);
86757 free_tsk:
86758 free_task_struct(tsk);
86759 return NULL;
86760 }
86761
86762 #ifdef CONFIG_MMU
86763-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86764+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86765+{
86766+ struct vm_area_struct *tmp;
86767+ unsigned long charge;
86768+ struct file *file;
86769+ int retval;
86770+
86771+ charge = 0;
86772+ if (mpnt->vm_flags & VM_ACCOUNT) {
86773+ unsigned long len = vma_pages(mpnt);
86774+
86775+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86776+ goto fail_nomem;
86777+ charge = len;
86778+ }
86779+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86780+ if (!tmp)
86781+ goto fail_nomem;
86782+ *tmp = *mpnt;
86783+ tmp->vm_mm = mm;
86784+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86785+ retval = vma_dup_policy(mpnt, tmp);
86786+ if (retval)
86787+ goto fail_nomem_policy;
86788+ if (anon_vma_fork(tmp, mpnt))
86789+ goto fail_nomem_anon_vma_fork;
86790+ tmp->vm_flags &= ~VM_LOCKED;
86791+ tmp->vm_next = tmp->vm_prev = NULL;
86792+ tmp->vm_mirror = NULL;
86793+ file = tmp->vm_file;
86794+ if (file) {
86795+ struct inode *inode = file_inode(file);
86796+ struct address_space *mapping = file->f_mapping;
86797+
86798+ get_file(file);
86799+ if (tmp->vm_flags & VM_DENYWRITE)
86800+ atomic_dec(&inode->i_writecount);
86801+ mutex_lock(&mapping->i_mmap_mutex);
86802+ if (tmp->vm_flags & VM_SHARED)
86803+ mapping->i_mmap_writable++;
86804+ flush_dcache_mmap_lock(mapping);
86805+ /* insert tmp into the share list, just after mpnt */
86806+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86807+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86808+ else
86809+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86810+ flush_dcache_mmap_unlock(mapping);
86811+ mutex_unlock(&mapping->i_mmap_mutex);
86812+ }
86813+
86814+ /*
86815+ * Clear hugetlb-related page reserves for children. This only
86816+ * affects MAP_PRIVATE mappings. Faults generated by the child
86817+ * are not guaranteed to succeed, even if read-only
86818+ */
86819+ if (is_vm_hugetlb_page(tmp))
86820+ reset_vma_resv_huge_pages(tmp);
86821+
86822+ return tmp;
86823+
86824+fail_nomem_anon_vma_fork:
86825+ mpol_put(vma_policy(tmp));
86826+fail_nomem_policy:
86827+ kmem_cache_free(vm_area_cachep, tmp);
86828+fail_nomem:
86829+ vm_unacct_memory(charge);
86830+ return NULL;
86831+}
86832+
86833+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86834 {
86835 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86836 struct rb_node **rb_link, *rb_parent;
86837 int retval;
86838- unsigned long charge;
86839
86840 uprobe_start_dup_mmap();
86841 down_write(&oldmm->mmap_sem);
86842@@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86843
86844 prev = NULL;
86845 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86846- struct file *file;
86847-
86848 if (mpnt->vm_flags & VM_DONTCOPY) {
86849 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86850 -vma_pages(mpnt));
86851 continue;
86852 }
86853- charge = 0;
86854- if (mpnt->vm_flags & VM_ACCOUNT) {
86855- unsigned long len = vma_pages(mpnt);
86856-
86857- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86858- goto fail_nomem;
86859- charge = len;
86860- }
86861- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86862- if (!tmp)
86863- goto fail_nomem;
86864- *tmp = *mpnt;
86865- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86866- retval = vma_dup_policy(mpnt, tmp);
86867- if (retval)
86868- goto fail_nomem_policy;
86869- tmp->vm_mm = mm;
86870- if (anon_vma_fork(tmp, mpnt))
86871- goto fail_nomem_anon_vma_fork;
86872- tmp->vm_flags &= ~VM_LOCKED;
86873- tmp->vm_next = tmp->vm_prev = NULL;
86874- file = tmp->vm_file;
86875- if (file) {
86876- struct inode *inode = file_inode(file);
86877- struct address_space *mapping = file->f_mapping;
86878-
86879- get_file(file);
86880- if (tmp->vm_flags & VM_DENYWRITE)
86881- atomic_dec(&inode->i_writecount);
86882- mutex_lock(&mapping->i_mmap_mutex);
86883- if (tmp->vm_flags & VM_SHARED)
86884- mapping->i_mmap_writable++;
86885- flush_dcache_mmap_lock(mapping);
86886- /* insert tmp into the share list, just after mpnt */
86887- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86888- vma_nonlinear_insert(tmp,
86889- &mapping->i_mmap_nonlinear);
86890- else
86891- vma_interval_tree_insert_after(tmp, mpnt,
86892- &mapping->i_mmap);
86893- flush_dcache_mmap_unlock(mapping);
86894- mutex_unlock(&mapping->i_mmap_mutex);
86895+ tmp = dup_vma(mm, oldmm, mpnt);
86896+ if (!tmp) {
86897+ retval = -ENOMEM;
86898+ goto out;
86899 }
86900
86901 /*
86902@@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86903 if (retval)
86904 goto out;
86905 }
86906+
86907+#ifdef CONFIG_PAX_SEGMEXEC
86908+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86909+ struct vm_area_struct *mpnt_m;
86910+
86911+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86912+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86913+
86914+ if (!mpnt->vm_mirror)
86915+ continue;
86916+
86917+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86918+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86919+ mpnt->vm_mirror = mpnt_m;
86920+ } else {
86921+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86922+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86923+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86924+ mpnt->vm_mirror->vm_mirror = mpnt;
86925+ }
86926+ }
86927+ BUG_ON(mpnt_m);
86928+ }
86929+#endif
86930+
86931 /* a new mm has just been created */
86932 arch_dup_mmap(oldmm, mm);
86933 retval = 0;
86934@@ -472,14 +575,6 @@ out:
86935 up_write(&oldmm->mmap_sem);
86936 uprobe_end_dup_mmap();
86937 return retval;
86938-fail_nomem_anon_vma_fork:
86939- mpol_put(vma_policy(tmp));
86940-fail_nomem_policy:
86941- kmem_cache_free(vm_area_cachep, tmp);
86942-fail_nomem:
86943- retval = -ENOMEM;
86944- vm_unacct_memory(charge);
86945- goto out;
86946 }
86947
86948 static inline int mm_alloc_pgd(struct mm_struct *mm)
86949@@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86950 return ERR_PTR(err);
86951
86952 mm = get_task_mm(task);
86953- if (mm && mm != current->mm &&
86954- !ptrace_may_access(task, mode)) {
86955+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86956+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86957 mmput(mm);
86958 mm = ERR_PTR(-EACCES);
86959 }
86960@@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86961 spin_unlock(&fs->lock);
86962 return -EAGAIN;
86963 }
86964- fs->users++;
86965+ atomic_inc(&fs->users);
86966 spin_unlock(&fs->lock);
86967 return 0;
86968 }
86969 tsk->fs = copy_fs_struct(fs);
86970 if (!tsk->fs)
86971 return -ENOMEM;
86972+ /* Carry through gr_chroot_dentry and is_chrooted instead
86973+ of recomputing it here. Already copied when the task struct
86974+ is duplicated. This allows pivot_root to not be treated as
86975+ a chroot
86976+ */
86977+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86978+
86979 return 0;
86980 }
86981
86982@@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86983 * parts of the process environment (as per the clone
86984 * flags). The actual kick-off is left to the caller.
86985 */
86986-static struct task_struct *copy_process(unsigned long clone_flags,
86987+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86988 unsigned long stack_start,
86989 unsigned long stack_size,
86990 int __user *child_tidptr,
86991@@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86992 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86993 #endif
86994 retval = -EAGAIN;
86995+
86996+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86997+
86998 if (atomic_read(&p->real_cred->user->processes) >=
86999 task_rlimit(p, RLIMIT_NPROC)) {
87000 if (p->real_cred->user != INIT_USER &&
87001@@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
87002 goto bad_fork_free_pid;
87003 }
87004
87005+ /* synchronizes with gr_set_acls()
87006+ we need to call this past the point of no return for fork()
87007+ */
87008+ gr_copy_label(p);
87009+
87010 if (likely(p->pid)) {
87011 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
87012
87013@@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
87014 bad_fork_free:
87015 free_task(p);
87016 fork_out:
87017+ gr_log_forkfail(retval);
87018+
87019 return ERR_PTR(retval);
87020 }
87021
87022@@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
87023
87024 p = copy_process(clone_flags, stack_start, stack_size,
87025 child_tidptr, NULL, trace);
87026+ add_latent_entropy();
87027 /*
87028 * Do this prior waking up the new thread - the thread pointer
87029 * might get invalid after that point, if the thread exits quickly.
87030@@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
87031 if (clone_flags & CLONE_PARENT_SETTID)
87032 put_user(nr, parent_tidptr);
87033
87034+ gr_handle_brute_check();
87035+
87036 if (clone_flags & CLONE_VFORK) {
87037 p->vfork_done = &vfork;
87038 init_completion(&vfork);
87039@@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
87040 mm_cachep = kmem_cache_create("mm_struct",
87041 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
87042 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
87043- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
87044+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
87045 mmap_init();
87046 nsproxy_cache_init();
87047 }
87048@@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
87049 return 0;
87050
87051 /* don't need lock here; in the worst case we'll do useless copy */
87052- if (fs->users == 1)
87053+ if (atomic_read(&fs->users) == 1)
87054 return 0;
87055
87056 *new_fsp = copy_fs_struct(fs);
87057@@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
87058 fs = current->fs;
87059 spin_lock(&fs->lock);
87060 current->fs = new_fs;
87061- if (--fs->users)
87062+ gr_set_chroot_entries(current, &current->fs->root);
87063+ if (atomic_dec_return(&fs->users))
87064 new_fs = NULL;
87065 else
87066 new_fs = fs;
87067diff --git a/kernel/futex.c b/kernel/futex.c
87068index de938d2..c566038 100644
87069--- a/kernel/futex.c
87070+++ b/kernel/futex.c
87071@@ -202,7 +202,7 @@ struct futex_pi_state {
87072 atomic_t refcount;
87073
87074 union futex_key key;
87075-};
87076+} __randomize_layout;
87077
87078 /**
87079 * struct futex_q - The hashed futex queue entry, one per waiting task
87080@@ -236,7 +236,7 @@ struct futex_q {
87081 struct rt_mutex_waiter *rt_waiter;
87082 union futex_key *requeue_pi_key;
87083 u32 bitset;
87084-};
87085+} __randomize_layout;
87086
87087 static const struct futex_q futex_q_init = {
87088 /* list gets initialized in queue_me()*/
87089@@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
87090 struct page *page, *page_head;
87091 int err, ro = 0;
87092
87093+#ifdef CONFIG_PAX_SEGMEXEC
87094+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
87095+ return -EFAULT;
87096+#endif
87097+
87098 /*
87099 * The futex address must be "naturally" aligned.
87100 */
87101@@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
87102
87103 static int get_futex_value_locked(u32 *dest, u32 __user *from)
87104 {
87105- int ret;
87106+ unsigned long ret;
87107
87108 pagefault_disable();
87109 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
87110@@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
87111 {
87112 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
87113 u32 curval;
87114+ mm_segment_t oldfs;
87115
87116 /*
87117 * This will fail and we want it. Some arch implementations do
87118@@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
87119 * implementation, the non-functional ones will return
87120 * -ENOSYS.
87121 */
87122+ oldfs = get_fs();
87123+ set_fs(USER_DS);
87124 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
87125 futex_cmpxchg_enabled = 1;
87126+ set_fs(oldfs);
87127 #endif
87128 }
87129
87130diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
87131index 55c8c93..9ba7ad6 100644
87132--- a/kernel/futex_compat.c
87133+++ b/kernel/futex_compat.c
87134@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
87135 return 0;
87136 }
87137
87138-static void __user *futex_uaddr(struct robust_list __user *entry,
87139+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
87140 compat_long_t futex_offset)
87141 {
87142 compat_uptr_t base = ptr_to_compat(entry);
87143diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
87144index f45b75b..bfac6d5 100644
87145--- a/kernel/gcov/base.c
87146+++ b/kernel/gcov/base.c
87147@@ -108,11 +108,6 @@ void gcov_enable_events(void)
87148 }
87149
87150 #ifdef CONFIG_MODULES
87151-static inline int within(void *addr, void *start, unsigned long size)
87152-{
87153- return ((addr >= start) && (addr < start + size));
87154-}
87155-
87156 /* Update list and generate events when modules are unloaded. */
87157 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87158 void *data)
87159@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87160
87161 /* Remove entries located in module from linked list. */
87162 while ((info = gcov_info_next(info))) {
87163- if (within(info, mod->module_core, mod->core_size)) {
87164+ if (within_module_core_rw((unsigned long)info, mod)) {
87165 gcov_info_unlink(prev, info);
87166 if (gcov_events_enabled)
87167 gcov_event(GCOV_REMOVE, info);
87168diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
87169index e0501fe..312edd6 100644
87170--- a/kernel/hrtimer.c
87171+++ b/kernel/hrtimer.c
87172@@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
87173 local_irq_restore(flags);
87174 }
87175
87176-static void run_hrtimer_softirq(struct softirq_action *h)
87177+static __latent_entropy void run_hrtimer_softirq(void)
87178 {
87179 hrtimer_peek_ahead_timers();
87180 }
87181diff --git a/kernel/irq_work.c b/kernel/irq_work.c
87182index a82170e..5b01e7f 100644
87183--- a/kernel/irq_work.c
87184+++ b/kernel/irq_work.c
87185@@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
87186 return NOTIFY_OK;
87187 }
87188
87189-static struct notifier_block cpu_notify;
87190+static struct notifier_block cpu_notify = {
87191+ .notifier_call = irq_work_cpu_notify,
87192+ .priority = 0,
87193+};
87194
87195 static __init int irq_work_init_cpu_notifier(void)
87196 {
87197- cpu_notify.notifier_call = irq_work_cpu_notify;
87198- cpu_notify.priority = 0;
87199 register_cpu_notifier(&cpu_notify);
87200 return 0;
87201 }
87202diff --git a/kernel/jump_label.c b/kernel/jump_label.c
87203index 9019f15..9a3c42e 100644
87204--- a/kernel/jump_label.c
87205+++ b/kernel/jump_label.c
87206@@ -14,6 +14,7 @@
87207 #include <linux/err.h>
87208 #include <linux/static_key.h>
87209 #include <linux/jump_label_ratelimit.h>
87210+#include <linux/mm.h>
87211
87212 #ifdef HAVE_JUMP_LABEL
87213
87214@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
87215
87216 size = (((unsigned long)stop - (unsigned long)start)
87217 / sizeof(struct jump_entry));
87218+ pax_open_kernel();
87219 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
87220+ pax_close_kernel();
87221 }
87222
87223 static void jump_label_update(struct static_key *key, int enable);
87224@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
87225 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
87226 struct jump_entry *iter;
87227
87228+ pax_open_kernel();
87229 for (iter = iter_start; iter < iter_stop; iter++) {
87230 if (within_module_init(iter->code, mod))
87231 iter->code = 0;
87232 }
87233+ pax_close_kernel();
87234 }
87235
87236 static int
87237diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
87238index cb0cf37..b69e161 100644
87239--- a/kernel/kallsyms.c
87240+++ b/kernel/kallsyms.c
87241@@ -11,6 +11,9 @@
87242 * Changed the compression method from stem compression to "table lookup"
87243 * compression (see scripts/kallsyms.c for a more complete description)
87244 */
87245+#ifdef CONFIG_GRKERNSEC_HIDESYM
87246+#define __INCLUDED_BY_HIDESYM 1
87247+#endif
87248 #include <linux/kallsyms.h>
87249 #include <linux/module.h>
87250 #include <linux/init.h>
87251@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
87252
87253 static inline int is_kernel_inittext(unsigned long addr)
87254 {
87255+ if (system_state != SYSTEM_BOOTING)
87256+ return 0;
87257+
87258 if (addr >= (unsigned long)_sinittext
87259 && addr <= (unsigned long)_einittext)
87260 return 1;
87261 return 0;
87262 }
87263
87264+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87265+#ifdef CONFIG_MODULES
87266+static inline int is_module_text(unsigned long addr)
87267+{
87268+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
87269+ return 1;
87270+
87271+ addr = ktla_ktva(addr);
87272+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
87273+}
87274+#else
87275+static inline int is_module_text(unsigned long addr)
87276+{
87277+ return 0;
87278+}
87279+#endif
87280+#endif
87281+
87282 static inline int is_kernel_text(unsigned long addr)
87283 {
87284 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
87285@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
87286
87287 static inline int is_kernel(unsigned long addr)
87288 {
87289+
87290+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87291+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
87292+ return 1;
87293+
87294+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
87295+#else
87296 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
87297+#endif
87298+
87299 return 1;
87300 return in_gate_area_no_mm(addr);
87301 }
87302
87303 static int is_ksym_addr(unsigned long addr)
87304 {
87305+
87306+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87307+ if (is_module_text(addr))
87308+ return 0;
87309+#endif
87310+
87311 if (all_var)
87312 return is_kernel(addr);
87313
87314@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
87315
87316 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
87317 {
87318- iter->name[0] = '\0';
87319 iter->nameoff = get_symbol_offset(new_pos);
87320 iter->pos = new_pos;
87321 }
87322@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
87323 {
87324 struct kallsym_iter *iter = m->private;
87325
87326+#ifdef CONFIG_GRKERNSEC_HIDESYM
87327+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
87328+ return 0;
87329+#endif
87330+
87331 /* Some debugging symbols have no name. Ignore them. */
87332 if (!iter->name[0])
87333 return 0;
87334@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
87335 */
87336 type = iter->exported ? toupper(iter->type) :
87337 tolower(iter->type);
87338+
87339 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87340 type, iter->name, iter->module_name);
87341 } else
87342@@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87343 struct kallsym_iter *iter;
87344 int ret;
87345
87346- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87347+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87348 if (!iter)
87349 return -ENOMEM;
87350 reset_iter(iter, 0);
87351diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87352index e30ac0f..3528cac 100644
87353--- a/kernel/kcmp.c
87354+++ b/kernel/kcmp.c
87355@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87356 struct task_struct *task1, *task2;
87357 int ret;
87358
87359+#ifdef CONFIG_GRKERNSEC
87360+ return -ENOSYS;
87361+#endif
87362+
87363 rcu_read_lock();
87364
87365 /*
87366diff --git a/kernel/kexec.c b/kernel/kexec.c
87367index 28c5706..bfc8388 100644
87368--- a/kernel/kexec.c
87369+++ b/kernel/kexec.c
87370@@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
87371 compat_ulong_t, flags)
87372 {
87373 struct compat_kexec_segment in;
87374- struct kexec_segment out, __user *ksegments;
87375+ struct kexec_segment out;
87376+ struct kexec_segment __user *ksegments;
87377 unsigned long i, result;
87378
87379 /* Don't allow clients that don't understand the native
87380diff --git a/kernel/kmod.c b/kernel/kmod.c
87381index 6b375af..eaff670 100644
87382--- a/kernel/kmod.c
87383+++ b/kernel/kmod.c
87384@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87385 kfree(info->argv);
87386 }
87387
87388-static int call_modprobe(char *module_name, int wait)
87389+static int call_modprobe(char *module_name, char *module_param, int wait)
87390 {
87391 struct subprocess_info *info;
87392 static char *envp[] = {
87393@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87394 NULL
87395 };
87396
87397- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87398+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87399 if (!argv)
87400 goto out;
87401
87402@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87403 argv[1] = "-q";
87404 argv[2] = "--";
87405 argv[3] = module_name; /* check free_modprobe_argv() */
87406- argv[4] = NULL;
87407+ argv[4] = module_param;
87408+ argv[5] = NULL;
87409
87410 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87411 NULL, free_modprobe_argv, NULL);
87412@@ -129,9 +130,8 @@ out:
87413 * If module auto-loading support is disabled then this function
87414 * becomes a no-operation.
87415 */
87416-int __request_module(bool wait, const char *fmt, ...)
87417+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87418 {
87419- va_list args;
87420 char module_name[MODULE_NAME_LEN];
87421 unsigned int max_modprobes;
87422 int ret;
87423@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87424 if (!modprobe_path[0])
87425 return 0;
87426
87427- va_start(args, fmt);
87428- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87429- va_end(args);
87430+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87431 if (ret >= MODULE_NAME_LEN)
87432 return -ENAMETOOLONG;
87433
87434@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87435 if (ret)
87436 return ret;
87437
87438+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87439+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87440+ /* hack to workaround consolekit/udisks stupidity */
87441+ read_lock(&tasklist_lock);
87442+ if (!strcmp(current->comm, "mount") &&
87443+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87444+ read_unlock(&tasklist_lock);
87445+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87446+ return -EPERM;
87447+ }
87448+ read_unlock(&tasklist_lock);
87449+ }
87450+#endif
87451+
87452 /* If modprobe needs a service that is in a module, we get a recursive
87453 * loop. Limit the number of running kmod threads to max_threads/2 or
87454 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87455@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87456
87457 trace_module_request(module_name, wait, _RET_IP_);
87458
87459- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87460+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87461
87462 atomic_dec(&kmod_concurrent);
87463 return ret;
87464 }
87465+
87466+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87467+{
87468+ va_list args;
87469+ int ret;
87470+
87471+ va_start(args, fmt);
87472+ ret = ____request_module(wait, module_param, fmt, args);
87473+ va_end(args);
87474+
87475+ return ret;
87476+}
87477+
87478+int __request_module(bool wait, const char *fmt, ...)
87479+{
87480+ va_list args;
87481+ int ret;
87482+
87483+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87484+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87485+ char module_param[MODULE_NAME_LEN];
87486+
87487+ memset(module_param, 0, sizeof(module_param));
87488+
87489+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87490+
87491+ va_start(args, fmt);
87492+ ret = ____request_module(wait, module_param, fmt, args);
87493+ va_end(args);
87494+
87495+ return ret;
87496+ }
87497+#endif
87498+
87499+ va_start(args, fmt);
87500+ ret = ____request_module(wait, NULL, fmt, args);
87501+ va_end(args);
87502+
87503+ return ret;
87504+}
87505+
87506 EXPORT_SYMBOL(__request_module);
87507 #endif /* CONFIG_MODULES */
87508
87509@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87510 */
87511 set_user_nice(current, 0);
87512
87513+#ifdef CONFIG_GRKERNSEC
87514+ /* this is race-free as far as userland is concerned as we copied
87515+ out the path to be used prior to this point and are now operating
87516+ on that copy
87517+ */
87518+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87519+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87520+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87521+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87522+ retval = -EPERM;
87523+ goto fail;
87524+ }
87525+#endif
87526+
87527 retval = -ENOMEM;
87528 new = prepare_kernel_cred(current);
87529 if (!new)
87530@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87531 commit_creds(new);
87532
87533 retval = do_execve(getname_kernel(sub_info->path),
87534- (const char __user *const __user *)sub_info->argv,
87535- (const char __user *const __user *)sub_info->envp);
87536+ (const char __user *const __force_user *)sub_info->argv,
87537+ (const char __user *const __force_user *)sub_info->envp);
87538 if (!retval)
87539 return 0;
87540
87541@@ -260,6 +327,10 @@ static int call_helper(void *data)
87542
87543 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87544 {
87545+#ifdef CONFIG_GRKERNSEC
87546+ kfree(info->path);
87547+ info->path = info->origpath;
87548+#endif
87549 if (info->cleanup)
87550 (*info->cleanup)(info);
87551 kfree(info);
87552@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87553 *
87554 * Thus the __user pointer cast is valid here.
87555 */
87556- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87557+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87558
87559 /*
87560 * If ret is 0, either ____call_usermodehelper failed and the
87561@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87562 goto out;
87563
87564 INIT_WORK(&sub_info->work, __call_usermodehelper);
87565+#ifdef CONFIG_GRKERNSEC
87566+ sub_info->origpath = path;
87567+ sub_info->path = kstrdup(path, gfp_mask);
87568+#else
87569 sub_info->path = path;
87570+#endif
87571 sub_info->argv = argv;
87572 sub_info->envp = envp;
87573
87574@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87575 static int proc_cap_handler(struct ctl_table *table, int write,
87576 void __user *buffer, size_t *lenp, loff_t *ppos)
87577 {
87578- struct ctl_table t;
87579+ ctl_table_no_const t;
87580 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87581 kernel_cap_t new_cap;
87582 int err, i;
87583diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87584index ceeadfc..11c18b6 100644
87585--- a/kernel/kprobes.c
87586+++ b/kernel/kprobes.c
87587@@ -31,6 +31,9 @@
87588 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87589 * <prasanna@in.ibm.com> added function-return probes.
87590 */
87591+#ifdef CONFIG_GRKERNSEC_HIDESYM
87592+#define __INCLUDED_BY_HIDESYM 1
87593+#endif
87594 #include <linux/kprobes.h>
87595 #include <linux/hash.h>
87596 #include <linux/init.h>
87597@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87598
87599 static void *alloc_insn_page(void)
87600 {
87601- return module_alloc(PAGE_SIZE);
87602+ return module_alloc_exec(PAGE_SIZE);
87603 }
87604
87605 static void free_insn_page(void *page)
87606 {
87607- module_free(NULL, page);
87608+ module_free_exec(NULL, page);
87609 }
87610
87611 struct kprobe_insn_cache kprobe_insn_slots = {
87612@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87613 kprobe_type = "k";
87614
87615 if (sym)
87616- seq_printf(pi, "%p %s %s+0x%x %s ",
87617+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87618 p->addr, kprobe_type, sym, offset,
87619 (modname ? modname : " "));
87620 else
87621- seq_printf(pi, "%p %s %p ",
87622+ seq_printf(pi, "%pK %s %pK ",
87623 p->addr, kprobe_type, p->addr);
87624
87625 if (!pp)
87626diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87627index 2495a9b..071b906 100644
87628--- a/kernel/ksysfs.c
87629+++ b/kernel/ksysfs.c
87630@@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87631 {
87632 if (count+1 > UEVENT_HELPER_PATH_LEN)
87633 return -ENOENT;
87634+ if (!capable(CAP_SYS_ADMIN))
87635+ return -EPERM;
87636 memcpy(uevent_helper, buf, count);
87637 uevent_helper[count] = '\0';
87638 if (count && uevent_helper[count-1] == '\n')
87639@@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87640 return count;
87641 }
87642
87643-static struct bin_attribute notes_attr = {
87644+static bin_attribute_no_const notes_attr __read_only = {
87645 .attr = {
87646 .name = "notes",
87647 .mode = S_IRUGO,
87648diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87649index d24e433..fa04fb8 100644
87650--- a/kernel/locking/lockdep.c
87651+++ b/kernel/locking/lockdep.c
87652@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87653 end = (unsigned long) &_end,
87654 addr = (unsigned long) obj;
87655
87656+#ifdef CONFIG_PAX_KERNEXEC
87657+ start = ktla_ktva(start);
87658+#endif
87659+
87660 /*
87661 * static variable?
87662 */
87663@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87664 if (!static_obj(lock->key)) {
87665 debug_locks_off();
87666 printk("INFO: trying to register non-static key.\n");
87667+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87668 printk("the code is fine but needs lockdep annotation.\n");
87669 printk("turning off the locking correctness validator.\n");
87670 dump_stack();
87671@@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87672 if (!class)
87673 return 0;
87674 }
87675- atomic_inc((atomic_t *)&class->ops);
87676+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87677 if (very_verbose(class)) {
87678 printk("\nacquire class [%p] %s", class->key, class->name);
87679 if (class->name_version > 1)
87680diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87681index ef43ac4..2720dfa 100644
87682--- a/kernel/locking/lockdep_proc.c
87683+++ b/kernel/locking/lockdep_proc.c
87684@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87685 return 0;
87686 }
87687
87688- seq_printf(m, "%p", class->key);
87689+ seq_printf(m, "%pK", class->key);
87690 #ifdef CONFIG_DEBUG_LOCKDEP
87691 seq_printf(m, " OPS:%8ld", class->ops);
87692 #endif
87693@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87694
87695 list_for_each_entry(entry, &class->locks_after, entry) {
87696 if (entry->distance == 1) {
87697- seq_printf(m, " -> [%p] ", entry->class->key);
87698+ seq_printf(m, " -> [%pK] ", entry->class->key);
87699 print_name(m, entry->class);
87700 seq_puts(m, "\n");
87701 }
87702@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87703 if (!class->key)
87704 continue;
87705
87706- seq_printf(m, "[%p] ", class->key);
87707+ seq_printf(m, "[%pK] ", class->key);
87708 print_name(m, class);
87709 seq_puts(m, "\n");
87710 }
87711@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87712 if (!i)
87713 seq_line(m, '-', 40-namelen, namelen);
87714
87715- snprintf(ip, sizeof(ip), "[<%p>]",
87716+ snprintf(ip, sizeof(ip), "[<%pK>]",
87717 (void *)class->contention_point[i]);
87718 seq_printf(m, "%40s %14lu %29s %pS\n",
87719 name, stats->contention_point[i],
87720@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87721 if (!i)
87722 seq_line(m, '-', 40-namelen, namelen);
87723
87724- snprintf(ip, sizeof(ip), "[<%p>]",
87725+ snprintf(ip, sizeof(ip), "[<%pK>]",
87726 (void *)class->contending_point[i]);
87727 seq_printf(m, "%40s %14lu %29s %pS\n",
87728 name, stats->contending_point[i],
87729diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87730index 838dc9e..760e158 100644
87731--- a/kernel/locking/mcs_spinlock.c
87732+++ b/kernel/locking/mcs_spinlock.c
87733@@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87734 if (likely(prev == NULL))
87735 return true;
87736
87737- ACCESS_ONCE(prev->next) = node;
87738+ ACCESS_ONCE_RW(prev->next) = node;
87739
87740 /*
87741 * Normally @prev is untouchable after the above store; because at that
87742@@ -143,8 +143,8 @@ unqueue:
87743 * it will wait in Step-A.
87744 */
87745
87746- ACCESS_ONCE(next->prev) = prev;
87747- ACCESS_ONCE(prev->next) = next;
87748+ ACCESS_ONCE_RW(next->prev) = prev;
87749+ ACCESS_ONCE_RW(prev->next) = next;
87750
87751 return false;
87752 }
87753@@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
87754 */
87755 next = xchg(&node->next, NULL);
87756 if (next) {
87757- ACCESS_ONCE(next->locked) = 1;
87758+ ACCESS_ONCE_RW(next->locked) = 1;
87759 return;
87760 }
87761
87762 next = osq_wait_next(lock, node, NULL);
87763 if (next)
87764- ACCESS_ONCE(next->locked) = 1;
87765+ ACCESS_ONCE_RW(next->locked) = 1;
87766 }
87767
87768 #endif
87769diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
87770index a2dbac4..e02a34a 100644
87771--- a/kernel/locking/mcs_spinlock.h
87772+++ b/kernel/locking/mcs_spinlock.h
87773@@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
87774 */
87775 return;
87776 }
87777- ACCESS_ONCE(prev->next) = node;
87778+ ACCESS_ONCE_RW(prev->next) = node;
87779
87780 /* Wait until the lock holder passes the lock down. */
87781 arch_mcs_spin_lock_contended(&node->locked);
87782diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87783index 5cf6731..ce3bc5a 100644
87784--- a/kernel/locking/mutex-debug.c
87785+++ b/kernel/locking/mutex-debug.c
87786@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87787 }
87788
87789 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87790- struct thread_info *ti)
87791+ struct task_struct *task)
87792 {
87793 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87794
87795 /* Mark the current thread as blocked on the lock: */
87796- ti->task->blocked_on = waiter;
87797+ task->blocked_on = waiter;
87798 }
87799
87800 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87801- struct thread_info *ti)
87802+ struct task_struct *task)
87803 {
87804 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87805- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87806- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87807- ti->task->blocked_on = NULL;
87808+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87809+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87810+ task->blocked_on = NULL;
87811
87812 list_del_init(&waiter->list);
87813 waiter->task = NULL;
87814diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87815index 0799fd3..d06ae3b 100644
87816--- a/kernel/locking/mutex-debug.h
87817+++ b/kernel/locking/mutex-debug.h
87818@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87819 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87820 extern void debug_mutex_add_waiter(struct mutex *lock,
87821 struct mutex_waiter *waiter,
87822- struct thread_info *ti);
87823+ struct task_struct *task);
87824 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87825- struct thread_info *ti);
87826+ struct task_struct *task);
87827 extern void debug_mutex_unlock(struct mutex *lock);
87828 extern void debug_mutex_init(struct mutex *lock, const char *name,
87829 struct lock_class_key *key);
87830diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87831index bc73d33..6f308aa 100644
87832--- a/kernel/locking/mutex.c
87833+++ b/kernel/locking/mutex.c
87834@@ -490,7 +490,7 @@ slowpath:
87835 goto skip_wait;
87836
87837 debug_mutex_lock_common(lock, &waiter);
87838- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87839+ debug_mutex_add_waiter(lock, &waiter, task);
87840
87841 /* add waiting tasks to the end of the waitqueue (FIFO): */
87842 list_add_tail(&waiter.list, &lock->wait_list);
87843@@ -534,7 +534,7 @@ slowpath:
87844 schedule_preempt_disabled();
87845 spin_lock_mutex(&lock->wait_lock, flags);
87846 }
87847- mutex_remove_waiter(lock, &waiter, current_thread_info());
87848+ mutex_remove_waiter(lock, &waiter, task);
87849 /* set it to 0 if there are no waiters left: */
87850 if (likely(list_empty(&lock->wait_list)))
87851 atomic_set(&lock->count, 0);
87852@@ -571,7 +571,7 @@ skip_wait:
87853 return 0;
87854
87855 err:
87856- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87857+ mutex_remove_waiter(lock, &waiter, task);
87858 spin_unlock_mutex(&lock->wait_lock, flags);
87859 debug_mutex_free_waiter(&waiter);
87860 mutex_release(&lock->dep_map, 1, ip);
87861diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87862index 1d96dd0..994ff19 100644
87863--- a/kernel/locking/rtmutex-tester.c
87864+++ b/kernel/locking/rtmutex-tester.c
87865@@ -22,7 +22,7 @@
87866 #define MAX_RT_TEST_MUTEXES 8
87867
87868 static spinlock_t rttest_lock;
87869-static atomic_t rttest_event;
87870+static atomic_unchecked_t rttest_event;
87871
87872 struct test_thread_data {
87873 int opcode;
87874@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87875
87876 case RTTEST_LOCKCONT:
87877 td->mutexes[td->opdata] = 1;
87878- td->event = atomic_add_return(1, &rttest_event);
87879+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87880 return 0;
87881
87882 case RTTEST_RESET:
87883@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87884 return 0;
87885
87886 case RTTEST_RESETEVENT:
87887- atomic_set(&rttest_event, 0);
87888+ atomic_set_unchecked(&rttest_event, 0);
87889 return 0;
87890
87891 default:
87892@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87893 return ret;
87894
87895 td->mutexes[id] = 1;
87896- td->event = atomic_add_return(1, &rttest_event);
87897+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87898 rt_mutex_lock(&mutexes[id]);
87899- td->event = atomic_add_return(1, &rttest_event);
87900+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87901 td->mutexes[id] = 4;
87902 return 0;
87903
87904@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87905 return ret;
87906
87907 td->mutexes[id] = 1;
87908- td->event = atomic_add_return(1, &rttest_event);
87909+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87910 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87911- td->event = atomic_add_return(1, &rttest_event);
87912+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87913 td->mutexes[id] = ret ? 0 : 4;
87914 return ret ? -EINTR : 0;
87915
87916@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87917 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87918 return ret;
87919
87920- td->event = atomic_add_return(1, &rttest_event);
87921+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87922 rt_mutex_unlock(&mutexes[id]);
87923- td->event = atomic_add_return(1, &rttest_event);
87924+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87925 td->mutexes[id] = 0;
87926 return 0;
87927
87928@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87929 break;
87930
87931 td->mutexes[dat] = 2;
87932- td->event = atomic_add_return(1, &rttest_event);
87933+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87934 break;
87935
87936 default:
87937@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87938 return;
87939
87940 td->mutexes[dat] = 3;
87941- td->event = atomic_add_return(1, &rttest_event);
87942+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87943 break;
87944
87945 case RTTEST_LOCKNOWAIT:
87946@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87947 return;
87948
87949 td->mutexes[dat] = 1;
87950- td->event = atomic_add_return(1, &rttest_event);
87951+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87952 return;
87953
87954 default:
87955diff --git a/kernel/module.c b/kernel/module.c
87956index 079c461..741f79c 100644
87957--- a/kernel/module.c
87958+++ b/kernel/module.c
87959@@ -61,6 +61,7 @@
87960 #include <linux/pfn.h>
87961 #include <linux/bsearch.h>
87962 #include <linux/fips.h>
87963+#include <linux/grsecurity.h>
87964 #include <uapi/linux/module.h>
87965 #include "module-internal.h"
87966
87967@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87968
87969 /* Bounds of module allocation, for speeding __module_address.
87970 * Protected by module_mutex. */
87971-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87972+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87973+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87974
87975 int register_module_notifier(struct notifier_block * nb)
87976 {
87977@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87978 return true;
87979
87980 list_for_each_entry_rcu(mod, &modules, list) {
87981- struct symsearch arr[] = {
87982+ struct symsearch modarr[] = {
87983 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87984 NOT_GPL_ONLY, false },
87985 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87986@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87987 if (mod->state == MODULE_STATE_UNFORMED)
87988 continue;
87989
87990- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87991+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87992 return true;
87993 }
87994 return false;
87995@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87996 if (!pcpusec->sh_size)
87997 return 0;
87998
87999- if (align > PAGE_SIZE) {
88000+ if (align-1 >= PAGE_SIZE) {
88001 pr_warn("%s: per-cpu alignment %li > %li\n",
88002 mod->name, align, PAGE_SIZE);
88003 align = PAGE_SIZE;
88004@@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
88005 static ssize_t show_coresize(struct module_attribute *mattr,
88006 struct module_kobject *mk, char *buffer)
88007 {
88008- return sprintf(buffer, "%u\n", mk->mod->core_size);
88009+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
88010 }
88011
88012 static struct module_attribute modinfo_coresize =
88013@@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
88014 static ssize_t show_initsize(struct module_attribute *mattr,
88015 struct module_kobject *mk, char *buffer)
88016 {
88017- return sprintf(buffer, "%u\n", mk->mod->init_size);
88018+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
88019 }
88020
88021 static struct module_attribute modinfo_initsize =
88022@@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
88023 goto bad_version;
88024 }
88025
88026+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88027+ /*
88028+ * avoid potentially printing jibberish on attempted load
88029+ * of a module randomized with a different seed
88030+ */
88031+ pr_warn("no symbol version for %s\n", symname);
88032+#else
88033 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
88034+#endif
88035 return 0;
88036
88037 bad_version:
88038+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88039+ /*
88040+ * avoid potentially printing jibberish on attempted load
88041+ * of a module randomized with a different seed
88042+ */
88043+ printk("attempted module disagrees about version of symbol %s\n",
88044+ symname);
88045+#else
88046 printk("%s: disagrees about version of symbol %s\n",
88047 mod->name, symname);
88048+#endif
88049 return 0;
88050 }
88051
88052@@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
88053 */
88054 #ifdef CONFIG_SYSFS
88055
88056-#ifdef CONFIG_KALLSYMS
88057+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
88058 static inline bool sect_empty(const Elf_Shdr *sect)
88059 {
88060 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
88061@@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
88062 {
88063 unsigned int notes, loaded, i;
88064 struct module_notes_attrs *notes_attrs;
88065- struct bin_attribute *nattr;
88066+ bin_attribute_no_const *nattr;
88067
88068 /* failed to create section attributes, so can't create notes */
88069 if (!mod->sect_attrs)
88070@@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
88071 static int module_add_modinfo_attrs(struct module *mod)
88072 {
88073 struct module_attribute *attr;
88074- struct module_attribute *temp_attr;
88075+ module_attribute_no_const *temp_attr;
88076 int error = 0;
88077 int i;
88078
88079@@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
88080
88081 static void unset_module_core_ro_nx(struct module *mod)
88082 {
88083- set_page_attributes(mod->module_core + mod->core_text_size,
88084- mod->module_core + mod->core_size,
88085+ set_page_attributes(mod->module_core_rw,
88086+ mod->module_core_rw + mod->core_size_rw,
88087 set_memory_x);
88088- set_page_attributes(mod->module_core,
88089- mod->module_core + mod->core_ro_size,
88090+ set_page_attributes(mod->module_core_rx,
88091+ mod->module_core_rx + mod->core_size_rx,
88092 set_memory_rw);
88093 }
88094
88095 static void unset_module_init_ro_nx(struct module *mod)
88096 {
88097- set_page_attributes(mod->module_init + mod->init_text_size,
88098- mod->module_init + mod->init_size,
88099+ set_page_attributes(mod->module_init_rw,
88100+ mod->module_init_rw + mod->init_size_rw,
88101 set_memory_x);
88102- set_page_attributes(mod->module_init,
88103- mod->module_init + mod->init_ro_size,
88104+ set_page_attributes(mod->module_init_rx,
88105+ mod->module_init_rx + mod->init_size_rx,
88106 set_memory_rw);
88107 }
88108
88109@@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
88110 list_for_each_entry_rcu(mod, &modules, list) {
88111 if (mod->state == MODULE_STATE_UNFORMED)
88112 continue;
88113- if ((mod->module_core) && (mod->core_text_size)) {
88114- set_page_attributes(mod->module_core,
88115- mod->module_core + mod->core_text_size,
88116+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
88117+ set_page_attributes(mod->module_core_rx,
88118+ mod->module_core_rx + mod->core_size_rx,
88119 set_memory_rw);
88120 }
88121- if ((mod->module_init) && (mod->init_text_size)) {
88122- set_page_attributes(mod->module_init,
88123- mod->module_init + mod->init_text_size,
88124+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
88125+ set_page_attributes(mod->module_init_rx,
88126+ mod->module_init_rx + mod->init_size_rx,
88127 set_memory_rw);
88128 }
88129 }
88130@@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
88131 list_for_each_entry_rcu(mod, &modules, list) {
88132 if (mod->state == MODULE_STATE_UNFORMED)
88133 continue;
88134- if ((mod->module_core) && (mod->core_text_size)) {
88135- set_page_attributes(mod->module_core,
88136- mod->module_core + mod->core_text_size,
88137+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
88138+ set_page_attributes(mod->module_core_rx,
88139+ mod->module_core_rx + mod->core_size_rx,
88140 set_memory_ro);
88141 }
88142- if ((mod->module_init) && (mod->init_text_size)) {
88143- set_page_attributes(mod->module_init,
88144- mod->module_init + mod->init_text_size,
88145+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
88146+ set_page_attributes(mod->module_init_rx,
88147+ mod->module_init_rx + mod->init_size_rx,
88148 set_memory_ro);
88149 }
88150 }
88151@@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
88152
88153 /* This may be NULL, but that's OK */
88154 unset_module_init_ro_nx(mod);
88155- module_free(mod, mod->module_init);
88156+ module_free(mod, mod->module_init_rw);
88157+ module_free_exec(mod, mod->module_init_rx);
88158 kfree(mod->args);
88159 percpu_modfree(mod);
88160
88161 /* Free lock-classes: */
88162- lockdep_free_key_range(mod->module_core, mod->core_size);
88163+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
88164+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
88165
88166 /* Finally, free the core (containing the module structure) */
88167 unset_module_core_ro_nx(mod);
88168- module_free(mod, mod->module_core);
88169+ module_free_exec(mod, mod->module_core_rx);
88170+ module_free(mod, mod->module_core_rw);
88171
88172 #ifdef CONFIG_MPU
88173 update_protections(current->mm);
88174@@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88175 int ret = 0;
88176 const struct kernel_symbol *ksym;
88177
88178+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88179+ int is_fs_load = 0;
88180+ int register_filesystem_found = 0;
88181+ char *p;
88182+
88183+ p = strstr(mod->args, "grsec_modharden_fs");
88184+ if (p) {
88185+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
88186+ /* copy \0 as well */
88187+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
88188+ is_fs_load = 1;
88189+ }
88190+#endif
88191+
88192 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
88193 const char *name = info->strtab + sym[i].st_name;
88194
88195+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88196+ /* it's a real shame this will never get ripped and copied
88197+ upstream! ;(
88198+ */
88199+ if (is_fs_load && !strcmp(name, "register_filesystem"))
88200+ register_filesystem_found = 1;
88201+#endif
88202+
88203 switch (sym[i].st_shndx) {
88204 case SHN_COMMON:
88205 /* Ignore common symbols */
88206@@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88207 ksym = resolve_symbol_wait(mod, info, name);
88208 /* Ok if resolved. */
88209 if (ksym && !IS_ERR(ksym)) {
88210+ pax_open_kernel();
88211 sym[i].st_value = ksym->value;
88212+ pax_close_kernel();
88213 break;
88214 }
88215
88216@@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88217 secbase = (unsigned long)mod_percpu(mod);
88218 else
88219 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
88220+ pax_open_kernel();
88221 sym[i].st_value += secbase;
88222+ pax_close_kernel();
88223 break;
88224 }
88225 }
88226
88227+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88228+ if (is_fs_load && !register_filesystem_found) {
88229+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
88230+ ret = -EPERM;
88231+ }
88232+#endif
88233+
88234 return ret;
88235 }
88236
88237@@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
88238 || s->sh_entsize != ~0UL
88239 || strstarts(sname, ".init"))
88240 continue;
88241- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
88242+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88243+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
88244+ else
88245+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
88246 pr_debug("\t%s\n", sname);
88247 }
88248- switch (m) {
88249- case 0: /* executable */
88250- mod->core_size = debug_align(mod->core_size);
88251- mod->core_text_size = mod->core_size;
88252- break;
88253- case 1: /* RO: text and ro-data */
88254- mod->core_size = debug_align(mod->core_size);
88255- mod->core_ro_size = mod->core_size;
88256- break;
88257- case 3: /* whole core */
88258- mod->core_size = debug_align(mod->core_size);
88259- break;
88260- }
88261 }
88262
88263 pr_debug("Init section allocation order:\n");
88264@@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
88265 || s->sh_entsize != ~0UL
88266 || !strstarts(sname, ".init"))
88267 continue;
88268- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
88269- | INIT_OFFSET_MASK);
88270+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88271+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
88272+ else
88273+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
88274+ s->sh_entsize |= INIT_OFFSET_MASK;
88275 pr_debug("\t%s\n", sname);
88276 }
88277- switch (m) {
88278- case 0: /* executable */
88279- mod->init_size = debug_align(mod->init_size);
88280- mod->init_text_size = mod->init_size;
88281- break;
88282- case 1: /* RO: text and ro-data */
88283- mod->init_size = debug_align(mod->init_size);
88284- mod->init_ro_size = mod->init_size;
88285- break;
88286- case 3: /* whole init */
88287- mod->init_size = debug_align(mod->init_size);
88288- break;
88289- }
88290 }
88291 }
88292
88293@@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88294
88295 /* Put symbol section at end of init part of module. */
88296 symsect->sh_flags |= SHF_ALLOC;
88297- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
88298+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
88299 info->index.sym) | INIT_OFFSET_MASK;
88300 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
88301
88302@@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88303 }
88304
88305 /* Append room for core symbols at end of core part. */
88306- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
88307- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
88308- mod->core_size += strtab_size;
88309+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
88310+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
88311+ mod->core_size_rx += strtab_size;
88312
88313 /* Put string table section at end of init part of module. */
88314 strsect->sh_flags |= SHF_ALLOC;
88315- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
88316+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
88317 info->index.str) | INIT_OFFSET_MASK;
88318 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
88319 }
88320@@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88321 /* Make sure we get permanent strtab: don't use info->strtab. */
88322 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
88323
88324+ pax_open_kernel();
88325+
88326 /* Set types up while we still have access to sections. */
88327 for (i = 0; i < mod->num_symtab; i++)
88328 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
88329
88330- mod->core_symtab = dst = mod->module_core + info->symoffs;
88331- mod->core_strtab = s = mod->module_core + info->stroffs;
88332+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
88333+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
88334 src = mod->symtab;
88335 for (ndst = i = 0; i < mod->num_symtab; i++) {
88336 if (i == 0 ||
88337@@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88338 }
88339 }
88340 mod->core_num_syms = ndst;
88341+
88342+ pax_close_kernel();
88343 }
88344 #else
88345 static inline void layout_symtab(struct module *mod, struct load_info *info)
88346@@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
88347 return vmalloc_exec(size);
88348 }
88349
88350-static void *module_alloc_update_bounds(unsigned long size)
88351+static void *module_alloc_update_bounds_rw(unsigned long size)
88352 {
88353 void *ret = module_alloc(size);
88354
88355 if (ret) {
88356 mutex_lock(&module_mutex);
88357 /* Update module bounds. */
88358- if ((unsigned long)ret < module_addr_min)
88359- module_addr_min = (unsigned long)ret;
88360- if ((unsigned long)ret + size > module_addr_max)
88361- module_addr_max = (unsigned long)ret + size;
88362+ if ((unsigned long)ret < module_addr_min_rw)
88363+ module_addr_min_rw = (unsigned long)ret;
88364+ if ((unsigned long)ret + size > module_addr_max_rw)
88365+ module_addr_max_rw = (unsigned long)ret + size;
88366+ mutex_unlock(&module_mutex);
88367+ }
88368+ return ret;
88369+}
88370+
88371+static void *module_alloc_update_bounds_rx(unsigned long size)
88372+{
88373+ void *ret = module_alloc_exec(size);
88374+
88375+ if (ret) {
88376+ mutex_lock(&module_mutex);
88377+ /* Update module bounds. */
88378+ if ((unsigned long)ret < module_addr_min_rx)
88379+ module_addr_min_rx = (unsigned long)ret;
88380+ if ((unsigned long)ret + size > module_addr_max_rx)
88381+ module_addr_max_rx = (unsigned long)ret + size;
88382 mutex_unlock(&module_mutex);
88383 }
88384 return ret;
88385@@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88386 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88387
88388 if (info->index.sym == 0) {
88389+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88390+ /*
88391+ * avoid potentially printing jibberish on attempted load
88392+ * of a module randomized with a different seed
88393+ */
88394+ pr_warn("module has no symbols (stripped?)\n");
88395+#else
88396 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88397+#endif
88398 return ERR_PTR(-ENOEXEC);
88399 }
88400
88401@@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88402 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88403 {
88404 const char *modmagic = get_modinfo(info, "vermagic");
88405+ const char *license = get_modinfo(info, "license");
88406 int err;
88407
88408+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88409+ if (!license || !license_is_gpl_compatible(license))
88410+ return -ENOEXEC;
88411+#endif
88412+
88413 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88414 modmagic = NULL;
88415
88416@@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88417 }
88418
88419 /* Set up license info based on the info section */
88420- set_license(mod, get_modinfo(info, "license"));
88421+ set_license(mod, license);
88422
88423 return 0;
88424 }
88425@@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
88426 void *ptr;
88427
88428 /* Do the allocs. */
88429- ptr = module_alloc_update_bounds(mod->core_size);
88430+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88431 /*
88432 * The pointer to this block is stored in the module structure
88433 * which is inside the block. Just mark it as not being a
88434@@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
88435 if (!ptr)
88436 return -ENOMEM;
88437
88438- memset(ptr, 0, mod->core_size);
88439- mod->module_core = ptr;
88440+ memset(ptr, 0, mod->core_size_rw);
88441+ mod->module_core_rw = ptr;
88442
88443- if (mod->init_size) {
88444- ptr = module_alloc_update_bounds(mod->init_size);
88445+ if (mod->init_size_rw) {
88446+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88447 /*
88448 * The pointer to this block is stored in the module structure
88449 * which is inside the block. This block doesn't need to be
88450@@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
88451 */
88452 kmemleak_ignore(ptr);
88453 if (!ptr) {
88454- module_free(mod, mod->module_core);
88455+ module_free(mod, mod->module_core_rw);
88456 return -ENOMEM;
88457 }
88458- memset(ptr, 0, mod->init_size);
88459- mod->module_init = ptr;
88460+ memset(ptr, 0, mod->init_size_rw);
88461+ mod->module_init_rw = ptr;
88462 } else
88463- mod->module_init = NULL;
88464+ mod->module_init_rw = NULL;
88465+
88466+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88467+ kmemleak_not_leak(ptr);
88468+ if (!ptr) {
88469+ if (mod->module_init_rw)
88470+ module_free(mod, mod->module_init_rw);
88471+ module_free(mod, mod->module_core_rw);
88472+ return -ENOMEM;
88473+ }
88474+
88475+ pax_open_kernel();
88476+ memset(ptr, 0, mod->core_size_rx);
88477+ pax_close_kernel();
88478+ mod->module_core_rx = ptr;
88479+
88480+ if (mod->init_size_rx) {
88481+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88482+ kmemleak_ignore(ptr);
88483+ if (!ptr && mod->init_size_rx) {
88484+ module_free_exec(mod, mod->module_core_rx);
88485+ if (mod->module_init_rw)
88486+ module_free(mod, mod->module_init_rw);
88487+ module_free(mod, mod->module_core_rw);
88488+ return -ENOMEM;
88489+ }
88490+
88491+ pax_open_kernel();
88492+ memset(ptr, 0, mod->init_size_rx);
88493+ pax_close_kernel();
88494+ mod->module_init_rx = ptr;
88495+ } else
88496+ mod->module_init_rx = NULL;
88497
88498 /* Transfer each section which specifies SHF_ALLOC */
88499 pr_debug("final section addresses:\n");
88500@@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
88501 if (!(shdr->sh_flags & SHF_ALLOC))
88502 continue;
88503
88504- if (shdr->sh_entsize & INIT_OFFSET_MASK)
88505- dest = mod->module_init
88506- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88507- else
88508- dest = mod->module_core + shdr->sh_entsize;
88509+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88510+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88511+ dest = mod->module_init_rw
88512+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88513+ else
88514+ dest = mod->module_init_rx
88515+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88516+ } else {
88517+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88518+ dest = mod->module_core_rw + shdr->sh_entsize;
88519+ else
88520+ dest = mod->module_core_rx + shdr->sh_entsize;
88521+ }
88522+
88523+ if (shdr->sh_type != SHT_NOBITS) {
88524+
88525+#ifdef CONFIG_PAX_KERNEXEC
88526+#ifdef CONFIG_X86_64
88527+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88528+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88529+#endif
88530+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88531+ pax_open_kernel();
88532+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88533+ pax_close_kernel();
88534+ } else
88535+#endif
88536
88537- if (shdr->sh_type != SHT_NOBITS)
88538 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88539+ }
88540 /* Update sh_addr to point to copy in image. */
88541- shdr->sh_addr = (unsigned long)dest;
88542+
88543+#ifdef CONFIG_PAX_KERNEXEC
88544+ if (shdr->sh_flags & SHF_EXECINSTR)
88545+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88546+ else
88547+#endif
88548+
88549+ shdr->sh_addr = (unsigned long)dest;
88550 pr_debug("\t0x%lx %s\n",
88551 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88552 }
88553@@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88554 * Do it before processing of module parameters, so the module
88555 * can provide parameter accessor functions of its own.
88556 */
88557- if (mod->module_init)
88558- flush_icache_range((unsigned long)mod->module_init,
88559- (unsigned long)mod->module_init
88560- + mod->init_size);
88561- flush_icache_range((unsigned long)mod->module_core,
88562- (unsigned long)mod->module_core + mod->core_size);
88563+ if (mod->module_init_rx)
88564+ flush_icache_range((unsigned long)mod->module_init_rx,
88565+ (unsigned long)mod->module_init_rx
88566+ + mod->init_size_rx);
88567+ flush_icache_range((unsigned long)mod->module_core_rx,
88568+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88569
88570 set_fs(old_fs);
88571 }
88572@@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88573 static void module_deallocate(struct module *mod, struct load_info *info)
88574 {
88575 percpu_modfree(mod);
88576- module_free(mod, mod->module_init);
88577- module_free(mod, mod->module_core);
88578+ module_free_exec(mod, mod->module_init_rx);
88579+ module_free_exec(mod, mod->module_core_rx);
88580+ module_free(mod, mod->module_init_rw);
88581+ module_free(mod, mod->module_core_rw);
88582 }
88583
88584 int __weak module_finalize(const Elf_Ehdr *hdr,
88585@@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88586 static int post_relocation(struct module *mod, const struct load_info *info)
88587 {
88588 /* Sort exception table now relocations are done. */
88589+ pax_open_kernel();
88590 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88591+ pax_close_kernel();
88592
88593 /* Copy relocated percpu area over. */
88594 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88595@@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88596 MODULE_STATE_COMING, mod);
88597
88598 /* Set RO and NX regions for core */
88599- set_section_ro_nx(mod->module_core,
88600- mod->core_text_size,
88601- mod->core_ro_size,
88602- mod->core_size);
88603+ set_section_ro_nx(mod->module_core_rx,
88604+ mod->core_size_rx,
88605+ mod->core_size_rx,
88606+ mod->core_size_rx);
88607
88608 /* Set RO and NX regions for init */
88609- set_section_ro_nx(mod->module_init,
88610- mod->init_text_size,
88611- mod->init_ro_size,
88612- mod->init_size);
88613+ set_section_ro_nx(mod->module_init_rx,
88614+ mod->init_size_rx,
88615+ mod->init_size_rx,
88616+ mod->init_size_rx);
88617
88618 do_mod_ctors(mod);
88619 /* Start the module */
88620@@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88621 mod->strtab = mod->core_strtab;
88622 #endif
88623 unset_module_init_ro_nx(mod);
88624- module_free(mod, mod->module_init);
88625- mod->module_init = NULL;
88626- mod->init_size = 0;
88627- mod->init_ro_size = 0;
88628- mod->init_text_size = 0;
88629+ module_free(mod, mod->module_init_rw);
88630+ module_free_exec(mod, mod->module_init_rx);
88631+ mod->module_init_rw = NULL;
88632+ mod->module_init_rx = NULL;
88633+ mod->init_size_rw = 0;
88634+ mod->init_size_rx = 0;
88635 mutex_unlock(&module_mutex);
88636 wake_up_all(&module_wq);
88637
88638@@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88639 if (err)
88640 goto free_unload;
88641
88642+ /* Now copy in args */
88643+ mod->args = strndup_user(uargs, ~0UL >> 1);
88644+ if (IS_ERR(mod->args)) {
88645+ err = PTR_ERR(mod->args);
88646+ goto free_unload;
88647+ }
88648+
88649 /* Set up MODINFO_ATTR fields */
88650 setup_modinfo(mod, info);
88651
88652+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88653+ {
88654+ char *p, *p2;
88655+
88656+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88657+ 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);
88658+ err = -EPERM;
88659+ goto free_modinfo;
88660+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88661+ p += sizeof("grsec_modharden_normal") - 1;
88662+ p2 = strstr(p, "_");
88663+ if (p2) {
88664+ *p2 = '\0';
88665+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88666+ *p2 = '_';
88667+ }
88668+ err = -EPERM;
88669+ goto free_modinfo;
88670+ }
88671+ }
88672+#endif
88673+
88674 /* Fix up syms, so that st_value is a pointer to location. */
88675 err = simplify_symbols(mod, info);
88676 if (err < 0)
88677@@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88678
88679 flush_module_icache(mod);
88680
88681- /* Now copy in args */
88682- mod->args = strndup_user(uargs, ~0UL >> 1);
88683- if (IS_ERR(mod->args)) {
88684- err = PTR_ERR(mod->args);
88685- goto free_arch_cleanup;
88686- }
88687-
88688 dynamic_debug_setup(info->debug, info->num_debug);
88689
88690 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88691@@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88692 ddebug_cleanup:
88693 dynamic_debug_remove(info->debug);
88694 synchronize_sched();
88695- kfree(mod->args);
88696- free_arch_cleanup:
88697 module_arch_cleanup(mod);
88698 free_modinfo:
88699 free_modinfo(mod);
88700+ kfree(mod->args);
88701 free_unload:
88702 module_unload_free(mod);
88703 unlink_mod:
88704@@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88705 unsigned long nextval;
88706
88707 /* At worse, next value is at end of module */
88708- if (within_module_init(addr, mod))
88709- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88710+ if (within_module_init_rx(addr, mod))
88711+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88712+ else if (within_module_init_rw(addr, mod))
88713+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88714+ else if (within_module_core_rx(addr, mod))
88715+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88716+ else if (within_module_core_rw(addr, mod))
88717+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88718 else
88719- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88720+ return NULL;
88721
88722 /* Scan for closest preceding symbol, and next symbol. (ELF
88723 starts real symbols at 1). */
88724@@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88725 return 0;
88726
88727 seq_printf(m, "%s %u",
88728- mod->name, mod->init_size + mod->core_size);
88729+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88730 print_unload_info(m, mod);
88731
88732 /* Informative for users. */
88733@@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88734 mod->state == MODULE_STATE_COMING ? "Loading":
88735 "Live");
88736 /* Used by oprofile and other similar tools. */
88737- seq_printf(m, " 0x%pK", mod->module_core);
88738+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88739
88740 /* Taints info */
88741 if (mod->taints)
88742@@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
88743
88744 static int __init proc_modules_init(void)
88745 {
88746+#ifndef CONFIG_GRKERNSEC_HIDESYM
88747+#ifdef CONFIG_GRKERNSEC_PROC_USER
88748+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88749+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88750+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88751+#else
88752 proc_create("modules", 0, NULL, &proc_modules_operations);
88753+#endif
88754+#else
88755+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88756+#endif
88757 return 0;
88758 }
88759 module_init(proc_modules_init);
88760@@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
88761 {
88762 struct module *mod;
88763
88764- if (addr < module_addr_min || addr > module_addr_max)
88765+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88766+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88767 return NULL;
88768
88769 list_for_each_entry_rcu(mod, &modules, list) {
88770 if (mod->state == MODULE_STATE_UNFORMED)
88771 continue;
88772- if (within_module_core(addr, mod)
88773- || within_module_init(addr, mod))
88774+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88775 return mod;
88776 }
88777 return NULL;
88778@@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
88779 */
88780 struct module *__module_text_address(unsigned long addr)
88781 {
88782- struct module *mod = __module_address(addr);
88783+ struct module *mod;
88784+
88785+#ifdef CONFIG_X86_32
88786+ addr = ktla_ktva(addr);
88787+#endif
88788+
88789+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88790+ return NULL;
88791+
88792+ mod = __module_address(addr);
88793+
88794 if (mod) {
88795 /* Make sure it's within the text section. */
88796- if (!within(addr, mod->module_init, mod->init_text_size)
88797- && !within(addr, mod->module_core, mod->core_text_size))
88798+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88799 mod = NULL;
88800 }
88801 return mod;
88802diff --git a/kernel/notifier.c b/kernel/notifier.c
88803index db4c8b0..ad011c5 100644
88804--- a/kernel/notifier.c
88805+++ b/kernel/notifier.c
88806@@ -5,6 +5,7 @@
88807 #include <linux/rcupdate.h>
88808 #include <linux/vmalloc.h>
88809 #include <linux/reboot.h>
88810+#include <linux/mm.h>
88811
88812 /*
88813 * Notifier list for kernel code which wants to be called
88814@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88815 while ((*nl) != NULL) {
88816 if (n->priority > (*nl)->priority)
88817 break;
88818- nl = &((*nl)->next);
88819+ nl = (struct notifier_block **)&((*nl)->next);
88820 }
88821- n->next = *nl;
88822+ pax_open_kernel();
88823+ *(const void **)&n->next = *nl;
88824 rcu_assign_pointer(*nl, n);
88825+ pax_close_kernel();
88826 return 0;
88827 }
88828
88829@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88830 return 0;
88831 if (n->priority > (*nl)->priority)
88832 break;
88833- nl = &((*nl)->next);
88834+ nl = (struct notifier_block **)&((*nl)->next);
88835 }
88836- n->next = *nl;
88837+ pax_open_kernel();
88838+ *(const void **)&n->next = *nl;
88839 rcu_assign_pointer(*nl, n);
88840+ pax_close_kernel();
88841 return 0;
88842 }
88843
88844@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88845 {
88846 while ((*nl) != NULL) {
88847 if ((*nl) == n) {
88848+ pax_open_kernel();
88849 rcu_assign_pointer(*nl, n->next);
88850+ pax_close_kernel();
88851 return 0;
88852 }
88853- nl = &((*nl)->next);
88854+ nl = (struct notifier_block **)&((*nl)->next);
88855 }
88856 return -ENOENT;
88857 }
88858diff --git a/kernel/padata.c b/kernel/padata.c
88859index 161402f..598814c 100644
88860--- a/kernel/padata.c
88861+++ b/kernel/padata.c
88862@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88863 * seq_nr mod. number of cpus in use.
88864 */
88865
88866- seq_nr = atomic_inc_return(&pd->seq_nr);
88867+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88868 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88869
88870 return padata_index_to_cpu(pd, cpu_index);
88871@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88872 padata_init_pqueues(pd);
88873 padata_init_squeues(pd);
88874 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88875- atomic_set(&pd->seq_nr, -1);
88876+ atomic_set_unchecked(&pd->seq_nr, -1);
88877 atomic_set(&pd->reorder_objects, 0);
88878 atomic_set(&pd->refcnt, 0);
88879 pd->pinst = pinst;
88880diff --git a/kernel/panic.c b/kernel/panic.c
88881index d02fa9f..9faec0a 100644
88882--- a/kernel/panic.c
88883+++ b/kernel/panic.c
88884@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88885 /*
88886 * Stop ourself in panic -- architecture code may override this
88887 */
88888-void __weak panic_smp_self_stop(void)
88889+void __weak __noreturn panic_smp_self_stop(void)
88890 {
88891 while (1)
88892 cpu_relax();
88893@@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88894 disable_trace_on_warning();
88895
88896 pr_warn("------------[ cut here ]------------\n");
88897- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88898+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88899 raw_smp_processor_id(), current->pid, file, line, caller);
88900
88901 if (args)
88902@@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88903 */
88904 __visible void __stack_chk_fail(void)
88905 {
88906- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88907+ dump_stack();
88908+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88909 __builtin_return_address(0));
88910 }
88911 EXPORT_SYMBOL(__stack_chk_fail);
88912diff --git a/kernel/pid.c b/kernel/pid.c
88913index 9b9a266..c20ef80 100644
88914--- a/kernel/pid.c
88915+++ b/kernel/pid.c
88916@@ -33,6 +33,7 @@
88917 #include <linux/rculist.h>
88918 #include <linux/bootmem.h>
88919 #include <linux/hash.h>
88920+#include <linux/security.h>
88921 #include <linux/pid_namespace.h>
88922 #include <linux/init_task.h>
88923 #include <linux/syscalls.h>
88924@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88925
88926 int pid_max = PID_MAX_DEFAULT;
88927
88928-#define RESERVED_PIDS 300
88929+#define RESERVED_PIDS 500
88930
88931 int pid_max_min = RESERVED_PIDS + 1;
88932 int pid_max_max = PID_MAX_LIMIT;
88933@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88934 */
88935 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88936 {
88937+ struct task_struct *task;
88938+
88939 rcu_lockdep_assert(rcu_read_lock_held(),
88940 "find_task_by_pid_ns() needs rcu_read_lock()"
88941 " protection");
88942- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88943+
88944+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88945+
88946+ if (gr_pid_is_chrooted(task))
88947+ return NULL;
88948+
88949+ return task;
88950 }
88951
88952 struct task_struct *find_task_by_vpid(pid_t vnr)
88953@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88954 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88955 }
88956
88957+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88958+{
88959+ rcu_lockdep_assert(rcu_read_lock_held(),
88960+ "find_task_by_pid_ns() needs rcu_read_lock()"
88961+ " protection");
88962+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88963+}
88964+
88965 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88966 {
88967 struct pid *pid;
88968diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88969index db95d8e..a0ca23f 100644
88970--- a/kernel/pid_namespace.c
88971+++ b/kernel/pid_namespace.c
88972@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88973 void __user *buffer, size_t *lenp, loff_t *ppos)
88974 {
88975 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88976- struct ctl_table tmp = *table;
88977+ ctl_table_no_const tmp = *table;
88978
88979 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88980 return -EPERM;
88981diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88982index 3b89464..5e38379 100644
88983--- a/kernel/posix-cpu-timers.c
88984+++ b/kernel/posix-cpu-timers.c
88985@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88986
88987 static __init int init_posix_cpu_timers(void)
88988 {
88989- struct k_clock process = {
88990+ static struct k_clock process = {
88991 .clock_getres = process_cpu_clock_getres,
88992 .clock_get = process_cpu_clock_get,
88993 .timer_create = process_cpu_timer_create,
88994 .nsleep = process_cpu_nsleep,
88995 .nsleep_restart = process_cpu_nsleep_restart,
88996 };
88997- struct k_clock thread = {
88998+ static struct k_clock thread = {
88999 .clock_getres = thread_cpu_clock_getres,
89000 .clock_get = thread_cpu_clock_get,
89001 .timer_create = thread_cpu_timer_create,
89002diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
89003index 424c2d4..679242f 100644
89004--- a/kernel/posix-timers.c
89005+++ b/kernel/posix-timers.c
89006@@ -43,6 +43,7 @@
89007 #include <linux/hash.h>
89008 #include <linux/posix-clock.h>
89009 #include <linux/posix-timers.h>
89010+#include <linux/grsecurity.h>
89011 #include <linux/syscalls.h>
89012 #include <linux/wait.h>
89013 #include <linux/workqueue.h>
89014@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
89015 * which we beg off on and pass to do_sys_settimeofday().
89016 */
89017
89018-static struct k_clock posix_clocks[MAX_CLOCKS];
89019+static struct k_clock *posix_clocks[MAX_CLOCKS];
89020
89021 /*
89022 * These ones are defined below.
89023@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
89024 */
89025 static __init int init_posix_timers(void)
89026 {
89027- struct k_clock clock_realtime = {
89028+ static struct k_clock clock_realtime = {
89029 .clock_getres = hrtimer_get_res,
89030 .clock_get = posix_clock_realtime_get,
89031 .clock_set = posix_clock_realtime_set,
89032@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
89033 .timer_get = common_timer_get,
89034 .timer_del = common_timer_del,
89035 };
89036- struct k_clock clock_monotonic = {
89037+ static struct k_clock clock_monotonic = {
89038 .clock_getres = hrtimer_get_res,
89039 .clock_get = posix_ktime_get_ts,
89040 .nsleep = common_nsleep,
89041@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
89042 .timer_get = common_timer_get,
89043 .timer_del = common_timer_del,
89044 };
89045- struct k_clock clock_monotonic_raw = {
89046+ static struct k_clock clock_monotonic_raw = {
89047 .clock_getres = hrtimer_get_res,
89048 .clock_get = posix_get_monotonic_raw,
89049 };
89050- struct k_clock clock_realtime_coarse = {
89051+ static struct k_clock clock_realtime_coarse = {
89052 .clock_getres = posix_get_coarse_res,
89053 .clock_get = posix_get_realtime_coarse,
89054 };
89055- struct k_clock clock_monotonic_coarse = {
89056+ static struct k_clock clock_monotonic_coarse = {
89057 .clock_getres = posix_get_coarse_res,
89058 .clock_get = posix_get_monotonic_coarse,
89059 };
89060- struct k_clock clock_tai = {
89061+ static struct k_clock clock_tai = {
89062 .clock_getres = hrtimer_get_res,
89063 .clock_get = posix_get_tai,
89064 .nsleep = common_nsleep,
89065@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
89066 .timer_get = common_timer_get,
89067 .timer_del = common_timer_del,
89068 };
89069- struct k_clock clock_boottime = {
89070+ static struct k_clock clock_boottime = {
89071 .clock_getres = hrtimer_get_res,
89072 .clock_get = posix_get_boottime,
89073 .nsleep = common_nsleep,
89074@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
89075 return;
89076 }
89077
89078- posix_clocks[clock_id] = *new_clock;
89079+ posix_clocks[clock_id] = new_clock;
89080 }
89081 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
89082
89083@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
89084 return (id & CLOCKFD_MASK) == CLOCKFD ?
89085 &clock_posix_dynamic : &clock_posix_cpu;
89086
89087- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
89088+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
89089 return NULL;
89090- return &posix_clocks[id];
89091+ return posix_clocks[id];
89092 }
89093
89094 static int common_timer_create(struct k_itimer *new_timer)
89095@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
89096 struct k_clock *kc = clockid_to_kclock(which_clock);
89097 struct k_itimer *new_timer;
89098 int error, new_timer_id;
89099- sigevent_t event;
89100+ sigevent_t event = { };
89101 int it_id_set = IT_ID_NOT_SET;
89102
89103 if (!kc)
89104@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
89105 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
89106 return -EFAULT;
89107
89108+ /* only the CLOCK_REALTIME clock can be set, all other clocks
89109+ have their clock_set fptr set to a nosettime dummy function
89110+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
89111+ call common_clock_set, which calls do_sys_settimeofday, which
89112+ we hook
89113+ */
89114+
89115 return kc->clock_set(which_clock, &new_tp);
89116 }
89117
89118diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
89119index 2fac9cc..56fef29 100644
89120--- a/kernel/power/Kconfig
89121+++ b/kernel/power/Kconfig
89122@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
89123 config HIBERNATION
89124 bool "Hibernation (aka 'suspend to disk')"
89125 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
89126+ depends on !GRKERNSEC_KMEM
89127+ depends on !PAX_MEMORY_SANITIZE
89128 select HIBERNATE_CALLBACKS
89129 select LZO_COMPRESS
89130 select LZO_DECOMPRESS
89131diff --git a/kernel/power/process.c b/kernel/power/process.c
89132index 14f9a8d..98ee610 100644
89133--- a/kernel/power/process.c
89134+++ b/kernel/power/process.c
89135@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
89136 unsigned int elapsed_msecs;
89137 bool wakeup = false;
89138 int sleep_usecs = USEC_PER_MSEC;
89139+ bool timedout = false;
89140
89141 do_gettimeofday(&start);
89142
89143@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
89144
89145 while (true) {
89146 todo = 0;
89147+ if (time_after(jiffies, end_time))
89148+ timedout = true;
89149 read_lock(&tasklist_lock);
89150 do_each_thread(g, p) {
89151 if (p == current || !freeze_task(p))
89152 continue;
89153
89154- if (!freezer_should_skip(p))
89155+ if (!freezer_should_skip(p)) {
89156 todo++;
89157+ if (timedout) {
89158+ printk(KERN_ERR "Task refusing to freeze:\n");
89159+ sched_show_task(p);
89160+ }
89161+ }
89162 } while_each_thread(g, p);
89163 read_unlock(&tasklist_lock);
89164
89165@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
89166 todo += wq_busy;
89167 }
89168
89169- if (!todo || time_after(jiffies, end_time))
89170+ if (!todo || timedout)
89171 break;
89172
89173 if (pm_wakeup_pending()) {
89174diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
89175index 63594be..8444e0f 100644
89176--- a/kernel/printk/printk.c
89177+++ b/kernel/printk/printk.c
89178@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
89179 if (from_file && type != SYSLOG_ACTION_OPEN)
89180 return 0;
89181
89182+#ifdef CONFIG_GRKERNSEC_DMESG
89183+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
89184+ return -EPERM;
89185+#endif
89186+
89187 if (syslog_action_restricted(type)) {
89188 if (capable(CAP_SYSLOG))
89189 return 0;
89190diff --git a/kernel/profile.c b/kernel/profile.c
89191index cb980f0..ccd8782 100644
89192--- a/kernel/profile.c
89193+++ b/kernel/profile.c
89194@@ -37,7 +37,7 @@ struct profile_hit {
89195 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
89196 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
89197
89198-static atomic_t *prof_buffer;
89199+static atomic_unchecked_t *prof_buffer;
89200 static unsigned long prof_len, prof_shift;
89201
89202 int prof_on __read_mostly;
89203@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
89204 hits[i].pc = 0;
89205 continue;
89206 }
89207- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89208+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89209 hits[i].hits = hits[i].pc = 0;
89210 }
89211 }
89212@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89213 * Add the current hit(s) and flush the write-queue out
89214 * to the global buffer:
89215 */
89216- atomic_add(nr_hits, &prof_buffer[pc]);
89217+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
89218 for (i = 0; i < NR_PROFILE_HIT; ++i) {
89219- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89220+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89221 hits[i].pc = hits[i].hits = 0;
89222 }
89223 out:
89224@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89225 {
89226 unsigned long pc;
89227 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
89228- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89229+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89230 }
89231 #endif /* !CONFIG_SMP */
89232
89233@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
89234 return -EFAULT;
89235 buf++; p++; count--; read++;
89236 }
89237- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
89238+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
89239 if (copy_to_user(buf, (void *)pnt, count))
89240 return -EFAULT;
89241 read += count;
89242@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
89243 }
89244 #endif
89245 profile_discard_flip_buffers();
89246- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
89247+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
89248 return count;
89249 }
89250
89251diff --git a/kernel/ptrace.c b/kernel/ptrace.c
89252index adf9862..9d86345 100644
89253--- a/kernel/ptrace.c
89254+++ b/kernel/ptrace.c
89255@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
89256 if (seize)
89257 flags |= PT_SEIZED;
89258 rcu_read_lock();
89259- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89260+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89261 flags |= PT_PTRACE_CAP;
89262 rcu_read_unlock();
89263 task->ptrace = flags;
89264@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
89265 break;
89266 return -EIO;
89267 }
89268- if (copy_to_user(dst, buf, retval))
89269+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
89270 return -EFAULT;
89271 copied += retval;
89272 src += retval;
89273@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
89274 bool seized = child->ptrace & PT_SEIZED;
89275 int ret = -EIO;
89276 siginfo_t siginfo, *si;
89277- void __user *datavp = (void __user *) data;
89278+ void __user *datavp = (__force void __user *) data;
89279 unsigned long __user *datalp = datavp;
89280 unsigned long flags;
89281
89282@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
89283 goto out;
89284 }
89285
89286+ if (gr_handle_ptrace(child, request)) {
89287+ ret = -EPERM;
89288+ goto out_put_task_struct;
89289+ }
89290+
89291 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89292 ret = ptrace_attach(child, request, addr, data);
89293 /*
89294 * Some architectures need to do book-keeping after
89295 * a ptrace attach.
89296 */
89297- if (!ret)
89298+ if (!ret) {
89299 arch_ptrace_attach(child);
89300+ gr_audit_ptrace(child);
89301+ }
89302 goto out_put_task_struct;
89303 }
89304
89305@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
89306 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
89307 if (copied != sizeof(tmp))
89308 return -EIO;
89309- return put_user(tmp, (unsigned long __user *)data);
89310+ return put_user(tmp, (__force unsigned long __user *)data);
89311 }
89312
89313 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
89314@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
89315 }
89316
89317 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89318- compat_long_t, addr, compat_long_t, data)
89319+ compat_ulong_t, addr, compat_ulong_t, data)
89320 {
89321 struct task_struct *child;
89322 long ret;
89323@@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89324 goto out;
89325 }
89326
89327+ if (gr_handle_ptrace(child, request)) {
89328+ ret = -EPERM;
89329+ goto out_put_task_struct;
89330+ }
89331+
89332 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89333 ret = ptrace_attach(child, request, addr, data);
89334 /*
89335 * Some architectures need to do book-keeping after
89336 * a ptrace attach.
89337 */
89338- if (!ret)
89339+ if (!ret) {
89340 arch_ptrace_attach(child);
89341+ gr_audit_ptrace(child);
89342+ }
89343 goto out_put_task_struct;
89344 }
89345
89346diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
89347index bd30bc6..dce23da 100644
89348--- a/kernel/rcu/rcutorture.c
89349+++ b/kernel/rcu/rcutorture.c
89350@@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89351 rcu_torture_count) = { 0 };
89352 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89353 rcu_torture_batch) = { 0 };
89354-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89355-static atomic_t n_rcu_torture_alloc;
89356-static atomic_t n_rcu_torture_alloc_fail;
89357-static atomic_t n_rcu_torture_free;
89358-static atomic_t n_rcu_torture_mberror;
89359-static atomic_t n_rcu_torture_error;
89360+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89361+static atomic_unchecked_t n_rcu_torture_alloc;
89362+static atomic_unchecked_t n_rcu_torture_alloc_fail;
89363+static atomic_unchecked_t n_rcu_torture_free;
89364+static atomic_unchecked_t n_rcu_torture_mberror;
89365+static atomic_unchecked_t n_rcu_torture_error;
89366 static long n_rcu_torture_barrier_error;
89367 static long n_rcu_torture_boost_ktrerror;
89368 static long n_rcu_torture_boost_rterror;
89369@@ -186,11 +186,11 @@ rcu_torture_alloc(void)
89370
89371 spin_lock_bh(&rcu_torture_lock);
89372 if (list_empty(&rcu_torture_freelist)) {
89373- atomic_inc(&n_rcu_torture_alloc_fail);
89374+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89375 spin_unlock_bh(&rcu_torture_lock);
89376 return NULL;
89377 }
89378- atomic_inc(&n_rcu_torture_alloc);
89379+ atomic_inc_unchecked(&n_rcu_torture_alloc);
89380 p = rcu_torture_freelist.next;
89381 list_del_init(p);
89382 spin_unlock_bh(&rcu_torture_lock);
89383@@ -203,7 +203,7 @@ rcu_torture_alloc(void)
89384 static void
89385 rcu_torture_free(struct rcu_torture *p)
89386 {
89387- atomic_inc(&n_rcu_torture_free);
89388+ atomic_inc_unchecked(&n_rcu_torture_free);
89389 spin_lock_bh(&rcu_torture_lock);
89390 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89391 spin_unlock_bh(&rcu_torture_lock);
89392@@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
89393 i = rp->rtort_pipe_count;
89394 if (i > RCU_TORTURE_PIPE_LEN)
89395 i = RCU_TORTURE_PIPE_LEN;
89396- atomic_inc(&rcu_torture_wcount[i]);
89397+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89398 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89399 rp->rtort_mbtest = 0;
89400 rcu_torture_free(rp);
89401@@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
89402 i = old_rp->rtort_pipe_count;
89403 if (i > RCU_TORTURE_PIPE_LEN)
89404 i = RCU_TORTURE_PIPE_LEN;
89405- atomic_inc(&rcu_torture_wcount[i]);
89406+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89407 old_rp->rtort_pipe_count++;
89408 if (gp_normal == gp_exp)
89409 exp = !!(torture_random(&rand) & 0x80);
89410@@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
89411 i = rp->rtort_pipe_count;
89412 if (i > RCU_TORTURE_PIPE_LEN)
89413 i = RCU_TORTURE_PIPE_LEN;
89414- atomic_inc(&rcu_torture_wcount[i]);
89415+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89416 if (++rp->rtort_pipe_count >=
89417 RCU_TORTURE_PIPE_LEN) {
89418 rp->rtort_mbtest = 0;
89419@@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
89420 return;
89421 }
89422 if (p->rtort_mbtest == 0)
89423- atomic_inc(&n_rcu_torture_mberror);
89424+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89425 spin_lock(&rand_lock);
89426 cur_ops->read_delay(&rand);
89427 n_rcu_torture_timers++;
89428@@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
89429 continue;
89430 }
89431 if (p->rtort_mbtest == 0)
89432- atomic_inc(&n_rcu_torture_mberror);
89433+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89434 cur_ops->read_delay(&rand);
89435 preempt_disable();
89436 pipe_count = p->rtort_pipe_count;
89437@@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
89438 }
89439 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89440 page += sprintf(page,
89441- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89442+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89443 rcu_torture_current,
89444 rcu_torture_current_version,
89445 list_empty(&rcu_torture_freelist),
89446- atomic_read(&n_rcu_torture_alloc),
89447- atomic_read(&n_rcu_torture_alloc_fail),
89448- atomic_read(&n_rcu_torture_free));
89449+ atomic_read_unchecked(&n_rcu_torture_alloc),
89450+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89451+ atomic_read_unchecked(&n_rcu_torture_free));
89452 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89453- atomic_read(&n_rcu_torture_mberror),
89454+ atomic_read_unchecked(&n_rcu_torture_mberror),
89455 n_rcu_torture_boost_ktrerror,
89456 n_rcu_torture_boost_rterror);
89457 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89458@@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
89459 n_barrier_attempts,
89460 n_rcu_torture_barrier_error);
89461 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89462- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89463+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89464 n_rcu_torture_barrier_error != 0 ||
89465 n_rcu_torture_boost_ktrerror != 0 ||
89466 n_rcu_torture_boost_rterror != 0 ||
89467 n_rcu_torture_boost_failure != 0 ||
89468 i > 1) {
89469 page += sprintf(page, "!!! ");
89470- atomic_inc(&n_rcu_torture_error);
89471+ atomic_inc_unchecked(&n_rcu_torture_error);
89472 WARN_ON_ONCE(1);
89473 }
89474 page += sprintf(page, "Reader Pipe: ");
89475@@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
89476 page += sprintf(page, "Free-Block Circulation: ");
89477 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89478 page += sprintf(page, " %d",
89479- atomic_read(&rcu_torture_wcount[i]));
89480+ atomic_read_unchecked(&rcu_torture_wcount[i]));
89481 }
89482 page += sprintf(page, "\n");
89483 if (cur_ops->stats)
89484@@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
89485
89486 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89487
89488- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89489+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89490 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89491 else if (torture_onoff_failures())
89492 rcu_torture_print_module_parms(cur_ops,
89493@@ -1460,18 +1460,18 @@ rcu_torture_init(void)
89494
89495 rcu_torture_current = NULL;
89496 rcu_torture_current_version = 0;
89497- atomic_set(&n_rcu_torture_alloc, 0);
89498- atomic_set(&n_rcu_torture_alloc_fail, 0);
89499- atomic_set(&n_rcu_torture_free, 0);
89500- atomic_set(&n_rcu_torture_mberror, 0);
89501- atomic_set(&n_rcu_torture_error, 0);
89502+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89503+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89504+ atomic_set_unchecked(&n_rcu_torture_free, 0);
89505+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89506+ atomic_set_unchecked(&n_rcu_torture_error, 0);
89507 n_rcu_torture_barrier_error = 0;
89508 n_rcu_torture_boost_ktrerror = 0;
89509 n_rcu_torture_boost_rterror = 0;
89510 n_rcu_torture_boost_failure = 0;
89511 n_rcu_torture_boosts = 0;
89512 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89513- atomic_set(&rcu_torture_wcount[i], 0);
89514+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89515 for_each_possible_cpu(cpu) {
89516 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89517 per_cpu(rcu_torture_count, cpu)[i] = 0;
89518diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89519index c639556..cf0a0d5 100644
89520--- a/kernel/rcu/srcu.c
89521+++ b/kernel/rcu/srcu.c
89522@@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89523
89524 idx = ACCESS_ONCE(sp->completed) & 0x1;
89525 preempt_disable();
89526- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89527+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89528 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89529- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89530+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89531 preempt_enable();
89532 return idx;
89533 }
89534diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89535index d9efcc1..ea543e9 100644
89536--- a/kernel/rcu/tiny.c
89537+++ b/kernel/rcu/tiny.c
89538@@ -42,7 +42,7 @@
89539 /* Forward declarations for tiny_plugin.h. */
89540 struct rcu_ctrlblk;
89541 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89542-static void rcu_process_callbacks(struct softirq_action *unused);
89543+static void rcu_process_callbacks(void);
89544 static void __call_rcu(struct rcu_head *head,
89545 void (*func)(struct rcu_head *rcu),
89546 struct rcu_ctrlblk *rcp);
89547@@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89548 false));
89549 }
89550
89551-static void rcu_process_callbacks(struct softirq_action *unused)
89552+static __latent_entropy void rcu_process_callbacks(void)
89553 {
89554 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89555 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89556diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89557index 0c47e30..a084591 100644
89558--- a/kernel/rcu/tree.c
89559+++ b/kernel/rcu/tree.c
89560@@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89561 rcu_prepare_for_idle(smp_processor_id());
89562 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89563 smp_mb__before_atomic_inc(); /* See above. */
89564- atomic_inc(&rdtp->dynticks);
89565+ atomic_inc_unchecked(&rdtp->dynticks);
89566 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89567- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89568+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89569
89570 /*
89571 * It is illegal to enter an extended quiescent state while
89572@@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89573 int user)
89574 {
89575 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89576- atomic_inc(&rdtp->dynticks);
89577+ atomic_inc_unchecked(&rdtp->dynticks);
89578 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89579 smp_mb__after_atomic_inc(); /* See above. */
89580- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89581+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89582 rcu_cleanup_after_idle(smp_processor_id());
89583 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89584 if (!user && !is_idle_task(current)) {
89585@@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89586 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89587
89588 if (rdtp->dynticks_nmi_nesting == 0 &&
89589- (atomic_read(&rdtp->dynticks) & 0x1))
89590+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89591 return;
89592 rdtp->dynticks_nmi_nesting++;
89593 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89594- atomic_inc(&rdtp->dynticks);
89595+ atomic_inc_unchecked(&rdtp->dynticks);
89596 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89597 smp_mb__after_atomic_inc(); /* See above. */
89598- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89599+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89600 }
89601
89602 /**
89603@@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89604 return;
89605 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89606 smp_mb__before_atomic_inc(); /* See above. */
89607- atomic_inc(&rdtp->dynticks);
89608+ atomic_inc_unchecked(&rdtp->dynticks);
89609 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89610- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89611+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89612 }
89613
89614 /**
89615@@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89616 */
89617 bool notrace __rcu_is_watching(void)
89618 {
89619- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89620+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89621 }
89622
89623 /**
89624@@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89625 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89626 bool *isidle, unsigned long *maxj)
89627 {
89628- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89629+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89630 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89631 return (rdp->dynticks_snap & 0x1) == 0;
89632 }
89633@@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89634 unsigned int curr;
89635 unsigned int snap;
89636
89637- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89638+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89639 snap = (unsigned int)rdp->dynticks_snap;
89640
89641 /*
89642@@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89643 rdp = this_cpu_ptr(rsp->rda);
89644 rcu_preempt_check_blocked_tasks(rnp);
89645 rnp->qsmask = rnp->qsmaskinit;
89646- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89647+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89648 WARN_ON_ONCE(rnp->completed != rsp->completed);
89649- ACCESS_ONCE(rnp->completed) = rsp->completed;
89650+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89651 if (rnp == rdp->mynode)
89652 __note_gp_changes(rsp, rnp, rdp);
89653 rcu_preempt_boost_start_gp(rnp);
89654@@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89655 rcu_for_each_node_breadth_first(rsp, rnp) {
89656 raw_spin_lock_irq(&rnp->lock);
89657 smp_mb__after_unlock_lock();
89658- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89659+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89660 rdp = this_cpu_ptr(rsp->rda);
89661 if (rnp == rdp->mynode)
89662 __note_gp_changes(rsp, rnp, rdp);
89663@@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89664 rcu_nocb_gp_set(rnp, nocb);
89665
89666 /* Declare grace period done. */
89667- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89668+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89669 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89670 rsp->fqs_state = RCU_GP_IDLE;
89671 rdp = this_cpu_ptr(rsp->rda);
89672@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89673 rsp->qlen += rdp->qlen;
89674 rdp->n_cbs_orphaned += rdp->qlen;
89675 rdp->qlen_lazy = 0;
89676- ACCESS_ONCE(rdp->qlen) = 0;
89677+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89678 }
89679
89680 /*
89681@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89682 }
89683 smp_mb(); /* List handling before counting for rcu_barrier(). */
89684 rdp->qlen_lazy -= count_lazy;
89685- ACCESS_ONCE(rdp->qlen) -= count;
89686+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89687 rdp->n_cbs_invoked += count;
89688
89689 /* Reinstate batch limit if we have worked down the excess. */
89690@@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89691 if (rnp_old != NULL)
89692 raw_spin_unlock(&rnp_old->fqslock);
89693 if (ret) {
89694- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89695+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89696 return;
89697 }
89698 rnp_old = rnp;
89699@@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89700 smp_mb__after_unlock_lock();
89701 raw_spin_unlock(&rnp_old->fqslock);
89702 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89703- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89704+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89705 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89706 return; /* Someone beat us to it. */
89707 }
89708@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89709 /*
89710 * Do RCU core processing for the current CPU.
89711 */
89712-static void rcu_process_callbacks(struct softirq_action *unused)
89713+static void rcu_process_callbacks(void)
89714 {
89715 struct rcu_state *rsp;
89716
89717@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89718 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89719 if (debug_rcu_head_queue(head)) {
89720 /* Probable double call_rcu(), so leak the callback. */
89721- ACCESS_ONCE(head->func) = rcu_leak_callback;
89722+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89723 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89724 return;
89725 }
89726@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89727 local_irq_restore(flags);
89728 return;
89729 }
89730- ACCESS_ONCE(rdp->qlen)++;
89731+ ACCESS_ONCE_RW(rdp->qlen)++;
89732 if (lazy)
89733 rdp->qlen_lazy++;
89734 else
89735@@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89736 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89737 * course be required on a 64-bit system.
89738 */
89739- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89740+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89741 (ulong)atomic_long_read(&rsp->expedited_done) +
89742 ULONG_MAX / 8)) {
89743 synchronize_sched();
89744- atomic_long_inc(&rsp->expedited_wrap);
89745+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
89746 return;
89747 }
89748
89749@@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
89750 * Take a ticket. Note that atomic_inc_return() implies a
89751 * full memory barrier.
89752 */
89753- snap = atomic_long_inc_return(&rsp->expedited_start);
89754+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89755 firstsnap = snap;
89756 get_online_cpus();
89757 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89758@@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
89759 synchronize_sched_expedited_cpu_stop,
89760 NULL) == -EAGAIN) {
89761 put_online_cpus();
89762- atomic_long_inc(&rsp->expedited_tryfail);
89763+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89764
89765 /* Check to see if someone else did our work for us. */
89766 s = atomic_long_read(&rsp->expedited_done);
89767 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89768 /* ensure test happens before caller kfree */
89769 smp_mb__before_atomic_inc(); /* ^^^ */
89770- atomic_long_inc(&rsp->expedited_workdone1);
89771+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89772 return;
89773 }
89774
89775@@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
89776 udelay(trycount * num_online_cpus());
89777 } else {
89778 wait_rcu_gp(call_rcu_sched);
89779- atomic_long_inc(&rsp->expedited_normal);
89780+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89781 return;
89782 }
89783
89784@@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
89785 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89786 /* ensure test happens before caller kfree */
89787 smp_mb__before_atomic_inc(); /* ^^^ */
89788- atomic_long_inc(&rsp->expedited_workdone2);
89789+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89790 return;
89791 }
89792
89793@@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
89794 * period works for us.
89795 */
89796 get_online_cpus();
89797- snap = atomic_long_read(&rsp->expedited_start);
89798+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89799 smp_mb(); /* ensure read is before try_stop_cpus(). */
89800 }
89801- atomic_long_inc(&rsp->expedited_stoppedcpus);
89802+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89803
89804 /*
89805 * Everyone up to our most recent fetch is covered by our grace
89806@@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
89807 * than we did already did their update.
89808 */
89809 do {
89810- atomic_long_inc(&rsp->expedited_done_tries);
89811+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89812 s = atomic_long_read(&rsp->expedited_done);
89813 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89814 /* ensure test happens before caller kfree */
89815 smp_mb__before_atomic_inc(); /* ^^^ */
89816- atomic_long_inc(&rsp->expedited_done_lost);
89817+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89818 break;
89819 }
89820 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89821- atomic_long_inc(&rsp->expedited_done_exit);
89822+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89823
89824 put_online_cpus();
89825 }
89826@@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89827 * ACCESS_ONCE() to prevent the compiler from speculating
89828 * the increment to precede the early-exit check.
89829 */
89830- ACCESS_ONCE(rsp->n_barrier_done)++;
89831+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89832 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89833 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89834 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89835@@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89836
89837 /* Increment ->n_barrier_done to prevent duplicate work. */
89838 smp_mb(); /* Keep increment after above mechanism. */
89839- ACCESS_ONCE(rsp->n_barrier_done)++;
89840+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89841 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89842 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89843 smp_mb(); /* Keep increment before caller's subsequent code. */
89844@@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89845 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89846 init_callback_list(rdp);
89847 rdp->qlen_lazy = 0;
89848- ACCESS_ONCE(rdp->qlen) = 0;
89849+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89850 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89851 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89852- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89853+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89854 rdp->cpu = cpu;
89855 rdp->rsp = rsp;
89856 rcu_boot_init_nocb_percpu_data(rdp);
89857@@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89858 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89859 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89860 rcu_sysidle_init_percpu_data(rdp->dynticks);
89861- atomic_set(&rdp->dynticks->dynticks,
89862- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89863+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89864+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89865 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89866
89867 /* Add CPU to rcu_node bitmasks. */
89868diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89869index 75dc3c3..b95d624 100644
89870--- a/kernel/rcu/tree.h
89871+++ b/kernel/rcu/tree.h
89872@@ -87,11 +87,11 @@ struct rcu_dynticks {
89873 long long dynticks_nesting; /* Track irq/process nesting level. */
89874 /* Process level is worth LLONG_MAX/2. */
89875 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89876- atomic_t dynticks; /* Even value for idle, else odd. */
89877+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89878 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89879 long long dynticks_idle_nesting;
89880 /* irq/process nesting level from idle. */
89881- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89882+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89883 /* "Idle" excludes userspace execution. */
89884 unsigned long dynticks_idle_jiffies;
89885 /* End of last non-NMI non-idle period. */
89886@@ -431,17 +431,17 @@ struct rcu_state {
89887 /* _rcu_barrier(). */
89888 /* End of fields guarded by barrier_mutex. */
89889
89890- atomic_long_t expedited_start; /* Starting ticket. */
89891- atomic_long_t expedited_done; /* Done ticket. */
89892- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89893- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89894- atomic_long_t expedited_workdone1; /* # done by others #1. */
89895- atomic_long_t expedited_workdone2; /* # done by others #2. */
89896- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89897- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89898- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89899- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89900- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89901+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89902+ atomic_long_t expedited_done; /* Done ticket. */
89903+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89904+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89905+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89906+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89907+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89908+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89909+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89910+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89911+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89912
89913 unsigned long jiffies_force_qs; /* Time at which to invoke */
89914 /* force_quiescent_state(). */
89915diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89916index 962d1d5..c6c62d12d 100644
89917--- a/kernel/rcu/tree_plugin.h
89918+++ b/kernel/rcu/tree_plugin.h
89919@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89920 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89921 {
89922 return !rcu_preempted_readers_exp(rnp) &&
89923- ACCESS_ONCE(rnp->expmask) == 0;
89924+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89925 }
89926
89927 /*
89928@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89929
89930 /* Clean up and exit. */
89931 smp_mb(); /* ensure expedited GP seen before counter increment. */
89932- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89933+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89934 unlock_mb_ret:
89935 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89936 mb_ret:
89937@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89938 free_cpumask_var(cm);
89939 }
89940
89941-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89942+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89943 .store = &rcu_cpu_kthread_task,
89944 .thread_should_run = rcu_cpu_kthread_should_run,
89945 .thread_fn = rcu_cpu_kthread,
89946@@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89947 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89948 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89949 cpu, ticks_value, ticks_title,
89950- atomic_read(&rdtp->dynticks) & 0xfff,
89951+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89952 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89953 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89954 fast_no_hz);
89955@@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89956
89957 /* Enqueue the callback on the nocb list and update counts. */
89958 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89959- ACCESS_ONCE(*old_rhpp) = rhp;
89960+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89961 atomic_long_add(rhcount, &rdp->nocb_q_count);
89962 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89963
89964@@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
89965 * Extract queued callbacks, update counts, and wait
89966 * for a grace period to elapse.
89967 */
89968- ACCESS_ONCE(rdp->nocb_head) = NULL;
89969+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89970 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89971 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89972 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89973- ACCESS_ONCE(rdp->nocb_p_count) += c;
89974- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89975+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89976+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89977 rcu_nocb_wait_gp(rdp);
89978
89979 /* Each pass through the following loop invokes a callback. */
89980@@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
89981 list = next;
89982 }
89983 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89984- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89985- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89986+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89987+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89988 rdp->n_nocbs_invoked += c;
89989 }
89990 return 0;
89991@@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89992 {
89993 if (!rcu_nocb_need_deferred_wakeup(rdp))
89994 return;
89995- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89996+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89997 wake_up(&rdp->nocb_wq);
89998 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89999 }
90000@@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
90001 t = kthread_run(rcu_nocb_kthread, rdp,
90002 "rcuo%c/%d", rsp->abbr, cpu);
90003 BUG_ON(IS_ERR(t));
90004- ACCESS_ONCE(rdp->nocb_kthread) = t;
90005+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
90006 }
90007 }
90008
90009@@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
90010
90011 /* Record start of fully idle period. */
90012 j = jiffies;
90013- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
90014+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
90015 smp_mb__before_atomic_inc();
90016- atomic_inc(&rdtp->dynticks_idle);
90017+ atomic_inc_unchecked(&rdtp->dynticks_idle);
90018 smp_mb__after_atomic_inc();
90019- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
90020+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
90021 }
90022
90023 /*
90024@@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
90025
90026 /* Record end of idle period. */
90027 smp_mb__before_atomic_inc();
90028- atomic_inc(&rdtp->dynticks_idle);
90029+ atomic_inc_unchecked(&rdtp->dynticks_idle);
90030 smp_mb__after_atomic_inc();
90031- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
90032+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
90033
90034 /*
90035 * If we are the timekeeping CPU, we are permitted to be non-idle
90036@@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
90037 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
90038
90039 /* Pick up current idle and NMI-nesting counter and check. */
90040- cur = atomic_read(&rdtp->dynticks_idle);
90041+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
90042 if (cur & 0x1) {
90043 *isidle = false; /* We are not idle! */
90044 return;
90045@@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
90046 case RCU_SYSIDLE_NOT:
90047
90048 /* First time all are idle, so note a short idle period. */
90049- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
90050+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
90051 break;
90052
90053 case RCU_SYSIDLE_SHORT:
90054@@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
90055 static void rcu_sysidle_cancel(void)
90056 {
90057 smp_mb();
90058- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
90059+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
90060 }
90061
90062 /*
90063@@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
90064 smp_mb(); /* grace period precedes setting inuse. */
90065
90066 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
90067- ACCESS_ONCE(rshp->inuse) = 0;
90068+ ACCESS_ONCE_RW(rshp->inuse) = 0;
90069 }
90070
90071 /*
90072diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
90073index 5cdc62e..cc52e88 100644
90074--- a/kernel/rcu/tree_trace.c
90075+++ b/kernel/rcu/tree_trace.c
90076@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
90077 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
90078 rdp->passed_quiesce, rdp->qs_pending);
90079 seq_printf(m, " dt=%d/%llx/%d df=%lu",
90080- atomic_read(&rdp->dynticks->dynticks),
90081+ atomic_read_unchecked(&rdp->dynticks->dynticks),
90082 rdp->dynticks->dynticks_nesting,
90083 rdp->dynticks->dynticks_nmi_nesting,
90084 rdp->dynticks_fqs);
90085@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
90086 struct rcu_state *rsp = (struct rcu_state *)m->private;
90087
90088 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",
90089- atomic_long_read(&rsp->expedited_start),
90090+ atomic_long_read_unchecked(&rsp->expedited_start),
90091 atomic_long_read(&rsp->expedited_done),
90092- atomic_long_read(&rsp->expedited_wrap),
90093- atomic_long_read(&rsp->expedited_tryfail),
90094- atomic_long_read(&rsp->expedited_workdone1),
90095- atomic_long_read(&rsp->expedited_workdone2),
90096- atomic_long_read(&rsp->expedited_normal),
90097- atomic_long_read(&rsp->expedited_stoppedcpus),
90098- atomic_long_read(&rsp->expedited_done_tries),
90099- atomic_long_read(&rsp->expedited_done_lost),
90100- atomic_long_read(&rsp->expedited_done_exit));
90101+ atomic_long_read_unchecked(&rsp->expedited_wrap),
90102+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
90103+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
90104+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
90105+ atomic_long_read_unchecked(&rsp->expedited_normal),
90106+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
90107+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
90108+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
90109+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
90110 return 0;
90111 }
90112
90113diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
90114index 4c0a9b0..7e81362 100644
90115--- a/kernel/rcu/update.c
90116+++ b/kernel/rcu/update.c
90117@@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
90118 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
90119 */
90120 if (till_stall_check < 3) {
90121- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
90122+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
90123 till_stall_check = 3;
90124 } else if (till_stall_check > 300) {
90125- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
90126+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
90127 till_stall_check = 300;
90128 }
90129 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
90130diff --git a/kernel/resource.c b/kernel/resource.c
90131index 8957d68..770cbe4 100644
90132--- a/kernel/resource.c
90133+++ b/kernel/resource.c
90134@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
90135
90136 static int __init ioresources_init(void)
90137 {
90138+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90139+#ifdef CONFIG_GRKERNSEC_PROC_USER
90140+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
90141+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
90142+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90143+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
90144+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
90145+#endif
90146+#else
90147 proc_create("ioports", 0, NULL, &proc_ioports_operations);
90148 proc_create("iomem", 0, NULL, &proc_iomem_operations);
90149+#endif
90150 return 0;
90151 }
90152 __initcall(ioresources_init);
90153diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
90154index e73efba..c9bfbd4 100644
90155--- a/kernel/sched/auto_group.c
90156+++ b/kernel/sched/auto_group.c
90157@@ -11,7 +11,7 @@
90158
90159 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
90160 static struct autogroup autogroup_default;
90161-static atomic_t autogroup_seq_nr;
90162+static atomic_unchecked_t autogroup_seq_nr;
90163
90164 void __init autogroup_init(struct task_struct *init_task)
90165 {
90166@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
90167
90168 kref_init(&ag->kref);
90169 init_rwsem(&ag->lock);
90170- ag->id = atomic_inc_return(&autogroup_seq_nr);
90171+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
90172 ag->tg = tg;
90173 #ifdef CONFIG_RT_GROUP_SCHED
90174 /*
90175diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
90176index a63f4dc..349bbb0 100644
90177--- a/kernel/sched/completion.c
90178+++ b/kernel/sched/completion.c
90179@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
90180 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90181 * or number of jiffies left till timeout) if completed.
90182 */
90183-long __sched
90184+long __sched __intentional_overflow(-1)
90185 wait_for_completion_interruptible_timeout(struct completion *x,
90186 unsigned long timeout)
90187 {
90188@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
90189 *
90190 * Return: -ERESTARTSYS if interrupted, 0 if completed.
90191 */
90192-int __sched wait_for_completion_killable(struct completion *x)
90193+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
90194 {
90195 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
90196 if (t == -ERESTARTSYS)
90197@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
90198 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90199 * or number of jiffies left till timeout) if completed.
90200 */
90201-long __sched
90202+long __sched __intentional_overflow(-1)
90203 wait_for_completion_killable_timeout(struct completion *x,
90204 unsigned long timeout)
90205 {
90206diff --git a/kernel/sched/core.c b/kernel/sched/core.c
90207index 8da7e49..ef10a02 100644
90208--- a/kernel/sched/core.c
90209+++ b/kernel/sched/core.c
90210@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
90211 int sysctl_numa_balancing(struct ctl_table *table, int write,
90212 void __user *buffer, size_t *lenp, loff_t *ppos)
90213 {
90214- struct ctl_table t;
90215+ ctl_table_no_const t;
90216 int err;
90217 int state = numabalancing_enabled;
90218
90219@@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
90220 next->active_mm = oldmm;
90221 atomic_inc(&oldmm->mm_count);
90222 enter_lazy_tlb(oldmm, next);
90223- } else
90224+ } else {
90225 switch_mm(oldmm, mm, next);
90226+ populate_stack();
90227+ }
90228
90229 if (!prev->mm) {
90230 prev->active_mm = NULL;
90231@@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
90232 /* convert nice value [19,-20] to rlimit style value [1,40] */
90233 int nice_rlim = 20 - nice;
90234
90235+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
90236+
90237 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
90238 capable(CAP_SYS_NICE));
90239 }
90240@@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
90241 if (nice > MAX_NICE)
90242 nice = MAX_NICE;
90243
90244- if (increment < 0 && !can_nice(current, nice))
90245+ if (increment < 0 && (!can_nice(current, nice) ||
90246+ gr_handle_chroot_nice()))
90247 return -EPERM;
90248
90249 retval = security_task_setnice(current, nice);
90250@@ -3310,6 +3315,7 @@ recheck:
90251 if (policy != p->policy && !rlim_rtprio)
90252 return -EPERM;
90253
90254+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
90255 /* can't increase priority */
90256 if (attr->sched_priority > p->rt_priority &&
90257 attr->sched_priority > rlim_rtprio)
90258@@ -4708,6 +4714,7 @@ void idle_task_exit(void)
90259
90260 if (mm != &init_mm) {
90261 switch_mm(mm, &init_mm, current);
90262+ populate_stack();
90263 finish_arch_post_lock_switch();
90264 }
90265 mmdrop(mm);
90266@@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
90267
90268 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
90269
90270-static struct ctl_table sd_ctl_dir[] = {
90271+static ctl_table_no_const sd_ctl_dir[] __read_only = {
90272 {
90273 .procname = "sched_domain",
90274 .mode = 0555,
90275@@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
90276 {}
90277 };
90278
90279-static struct ctl_table *sd_alloc_ctl_entry(int n)
90280+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
90281 {
90282- struct ctl_table *entry =
90283+ ctl_table_no_const *entry =
90284 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
90285
90286 return entry;
90287 }
90288
90289-static void sd_free_ctl_entry(struct ctl_table **tablep)
90290+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
90291 {
90292- struct ctl_table *entry;
90293+ ctl_table_no_const *entry;
90294
90295 /*
90296 * In the intermediate directories, both the child directory and
90297@@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
90298 * will always be set. In the lowest directory the names are
90299 * static strings and all have proc handlers.
90300 */
90301- for (entry = *tablep; entry->mode; entry++) {
90302- if (entry->child)
90303- sd_free_ctl_entry(&entry->child);
90304+ for (entry = tablep; entry->mode; entry++) {
90305+ if (entry->child) {
90306+ sd_free_ctl_entry(entry->child);
90307+ pax_open_kernel();
90308+ entry->child = NULL;
90309+ pax_close_kernel();
90310+ }
90311 if (entry->proc_handler == NULL)
90312 kfree(entry->procname);
90313 }
90314
90315- kfree(*tablep);
90316- *tablep = NULL;
90317+ kfree(tablep);
90318 }
90319
90320 static int min_load_idx = 0;
90321 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
90322
90323 static void
90324-set_table_entry(struct ctl_table *entry,
90325+set_table_entry(ctl_table_no_const *entry,
90326 const char *procname, void *data, int maxlen,
90327 umode_t mode, proc_handler *proc_handler,
90328 bool load_idx)
90329@@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
90330 static struct ctl_table *
90331 sd_alloc_ctl_domain_table(struct sched_domain *sd)
90332 {
90333- struct ctl_table *table = sd_alloc_ctl_entry(14);
90334+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
90335
90336 if (table == NULL)
90337 return NULL;
90338@@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
90339 return table;
90340 }
90341
90342-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
90343+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
90344 {
90345- struct ctl_table *entry, *table;
90346+ ctl_table_no_const *entry, *table;
90347 struct sched_domain *sd;
90348 int domain_num = 0, i;
90349 char buf[32];
90350@@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
90351 static void register_sched_domain_sysctl(void)
90352 {
90353 int i, cpu_num = num_possible_cpus();
90354- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
90355+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
90356 char buf[32];
90357
90358 WARN_ON(sd_ctl_dir[0].child);
90359+ pax_open_kernel();
90360 sd_ctl_dir[0].child = entry;
90361+ pax_close_kernel();
90362
90363 if (entry == NULL)
90364 return;
90365@@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
90366 if (sd_sysctl_header)
90367 unregister_sysctl_table(sd_sysctl_header);
90368 sd_sysctl_header = NULL;
90369- if (sd_ctl_dir[0].child)
90370- sd_free_ctl_entry(&sd_ctl_dir[0].child);
90371+ if (sd_ctl_dir[0].child) {
90372+ sd_free_ctl_entry(sd_ctl_dir[0].child);
90373+ pax_open_kernel();
90374+ sd_ctl_dir[0].child = NULL;
90375+ pax_close_kernel();
90376+ }
90377 }
90378 #else
90379 static void register_sched_domain_sysctl(void)
90380diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
90381index 8cbe2d2..61f20a1 100644
90382--- a/kernel/sched/fair.c
90383+++ b/kernel/sched/fair.c
90384@@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
90385
90386 static void reset_ptenuma_scan(struct task_struct *p)
90387 {
90388- ACCESS_ONCE(p->mm->numa_scan_seq)++;
90389+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
90390 p->mm->numa_scan_offset = 0;
90391 }
90392
90393@@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
90394 * run_rebalance_domains is triggered when needed from the scheduler tick.
90395 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
90396 */
90397-static void run_rebalance_domains(struct softirq_action *h)
90398+static __latent_entropy void run_rebalance_domains(void)
90399 {
90400 struct rq *this_rq = this_rq();
90401 enum cpu_idle_type idle = this_rq->idle_balance ?
90402diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
90403index 369b4d6..fa4eb3b 100644
90404--- a/kernel/sched/sched.h
90405+++ b/kernel/sched/sched.h
90406@@ -1157,7 +1157,7 @@ struct sched_class {
90407 #ifdef CONFIG_FAIR_GROUP_SCHED
90408 void (*task_move_group) (struct task_struct *p, int on_rq);
90409 #endif
90410-};
90411+} __do_const;
90412
90413 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
90414 {
90415diff --git a/kernel/signal.c b/kernel/signal.c
90416index 6ea13c0..31e3b25 100644
90417--- a/kernel/signal.c
90418+++ b/kernel/signal.c
90419@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
90420
90421 int print_fatal_signals __read_mostly;
90422
90423-static void __user *sig_handler(struct task_struct *t, int sig)
90424+static __sighandler_t sig_handler(struct task_struct *t, int sig)
90425 {
90426 return t->sighand->action[sig - 1].sa.sa_handler;
90427 }
90428
90429-static int sig_handler_ignored(void __user *handler, int sig)
90430+static int sig_handler_ignored(__sighandler_t handler, int sig)
90431 {
90432 /* Is it explicitly or implicitly ignored? */
90433 return handler == SIG_IGN ||
90434@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90435
90436 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90437 {
90438- void __user *handler;
90439+ __sighandler_t handler;
90440
90441 handler = sig_handler(t, sig);
90442
90443@@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90444 atomic_inc(&user->sigpending);
90445 rcu_read_unlock();
90446
90447+ if (!override_rlimit)
90448+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90449+
90450 if (override_rlimit ||
90451 atomic_read(&user->sigpending) <=
90452 task_rlimit(t, RLIMIT_SIGPENDING)) {
90453@@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90454
90455 int unhandled_signal(struct task_struct *tsk, int sig)
90456 {
90457- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90458+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90459 if (is_global_init(tsk))
90460 return 1;
90461 if (handler != SIG_IGN && handler != SIG_DFL)
90462@@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90463 }
90464 }
90465
90466+ /* allow glibc communication via tgkill to other threads in our
90467+ thread group */
90468+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90469+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90470+ && gr_handle_signal(t, sig))
90471+ return -EPERM;
90472+
90473 return security_task_kill(t, info, sig, 0);
90474 }
90475
90476@@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90477 return send_signal(sig, info, p, 1);
90478 }
90479
90480-static int
90481+int
90482 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90483 {
90484 return send_signal(sig, info, t, 0);
90485@@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90486 unsigned long int flags;
90487 int ret, blocked, ignored;
90488 struct k_sigaction *action;
90489+ int is_unhandled = 0;
90490
90491 spin_lock_irqsave(&t->sighand->siglock, flags);
90492 action = &t->sighand->action[sig-1];
90493@@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90494 }
90495 if (action->sa.sa_handler == SIG_DFL)
90496 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90497+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90498+ is_unhandled = 1;
90499 ret = specific_send_sig_info(sig, info, t);
90500 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90501
90502+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
90503+ normal operation */
90504+ if (is_unhandled) {
90505+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90506+ gr_handle_crash(t, sig);
90507+ }
90508+
90509 return ret;
90510 }
90511
90512@@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90513 ret = check_kill_permission(sig, info, p);
90514 rcu_read_unlock();
90515
90516- if (!ret && sig)
90517+ if (!ret && sig) {
90518 ret = do_send_sig_info(sig, info, p, true);
90519+ if (!ret)
90520+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90521+ }
90522
90523 return ret;
90524 }
90525@@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90526 int error = -ESRCH;
90527
90528 rcu_read_lock();
90529- p = find_task_by_vpid(pid);
90530+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90531+ /* allow glibc communication via tgkill to other threads in our
90532+ thread group */
90533+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90534+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90535+ p = find_task_by_vpid_unrestricted(pid);
90536+ else
90537+#endif
90538+ p = find_task_by_vpid(pid);
90539 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90540 error = check_kill_permission(sig, info, p);
90541 /*
90542@@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90543 }
90544 seg = get_fs();
90545 set_fs(KERNEL_DS);
90546- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90547- (stack_t __force __user *) &uoss,
90548+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90549+ (stack_t __force_user *) &uoss,
90550 compat_user_stack_pointer());
90551 set_fs(seg);
90552 if (ret >= 0 && uoss_ptr) {
90553diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90554index eb89e18..a4e6792 100644
90555--- a/kernel/smpboot.c
90556+++ b/kernel/smpboot.c
90557@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90558 }
90559 smpboot_unpark_thread(plug_thread, cpu);
90560 }
90561- list_add(&plug_thread->list, &hotplug_threads);
90562+ pax_list_add(&plug_thread->list, &hotplug_threads);
90563 out:
90564 mutex_unlock(&smpboot_threads_lock);
90565 return ret;
90566@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90567 {
90568 get_online_cpus();
90569 mutex_lock(&smpboot_threads_lock);
90570- list_del(&plug_thread->list);
90571+ pax_list_del(&plug_thread->list);
90572 smpboot_destroy_threads(plug_thread);
90573 mutex_unlock(&smpboot_threads_lock);
90574 put_online_cpus();
90575diff --git a/kernel/softirq.c b/kernel/softirq.c
90576index 92f24f5..db41501 100644
90577--- a/kernel/softirq.c
90578+++ b/kernel/softirq.c
90579@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90580 EXPORT_SYMBOL(irq_stat);
90581 #endif
90582
90583-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90584+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90585
90586 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90587
90588@@ -268,7 +268,7 @@ restart:
90589 kstat_incr_softirqs_this_cpu(vec_nr);
90590
90591 trace_softirq_entry(vec_nr);
90592- h->action(h);
90593+ h->action();
90594 trace_softirq_exit(vec_nr);
90595 if (unlikely(prev_count != preempt_count())) {
90596 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90597@@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90598 or_softirq_pending(1UL << nr);
90599 }
90600
90601-void open_softirq(int nr, void (*action)(struct softirq_action *))
90602+void __init open_softirq(int nr, void (*action)(void))
90603 {
90604 softirq_vec[nr].action = action;
90605 }
90606@@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90607 }
90608 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90609
90610-static void tasklet_action(struct softirq_action *a)
90611+static void tasklet_action(void)
90612 {
90613 struct tasklet_struct *list;
90614
90615@@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90616 }
90617 }
90618
90619-static void tasklet_hi_action(struct softirq_action *a)
90620+static __latent_entropy void tasklet_hi_action(void)
90621 {
90622 struct tasklet_struct *list;
90623
90624@@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90625 .notifier_call = cpu_callback
90626 };
90627
90628-static struct smp_hotplug_thread softirq_threads = {
90629+static struct smp_hotplug_thread softirq_threads __read_only = {
90630 .store = &ksoftirqd,
90631 .thread_should_run = ksoftirqd_should_run,
90632 .thread_fn = run_ksoftirqd,
90633diff --git a/kernel/sys.c b/kernel/sys.c
90634index fba0f29..84400e2 100644
90635--- a/kernel/sys.c
90636+++ b/kernel/sys.c
90637@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90638 error = -EACCES;
90639 goto out;
90640 }
90641+
90642+ if (gr_handle_chroot_setpriority(p, niceval)) {
90643+ error = -EACCES;
90644+ goto out;
90645+ }
90646+
90647 no_nice = security_task_setnice(p, niceval);
90648 if (no_nice) {
90649 error = no_nice;
90650@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90651 goto error;
90652 }
90653
90654+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90655+ goto error;
90656+
90657 if (rgid != (gid_t) -1 ||
90658 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90659 new->sgid = new->egid;
90660@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90661 old = current_cred();
90662
90663 retval = -EPERM;
90664+
90665+ if (gr_check_group_change(kgid, kgid, kgid))
90666+ goto error;
90667+
90668 if (ns_capable(old->user_ns, CAP_SETGID))
90669 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90670 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90671@@ -403,7 +416,7 @@ error:
90672 /*
90673 * change the user struct in a credentials set to match the new UID
90674 */
90675-static int set_user(struct cred *new)
90676+int set_user(struct cred *new)
90677 {
90678 struct user_struct *new_user;
90679
90680@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90681 goto error;
90682 }
90683
90684+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90685+ goto error;
90686+
90687 if (!uid_eq(new->uid, old->uid)) {
90688 retval = set_user(new);
90689 if (retval < 0)
90690@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90691 old = current_cred();
90692
90693 retval = -EPERM;
90694+
90695+ if (gr_check_crash_uid(kuid))
90696+ goto error;
90697+ if (gr_check_user_change(kuid, kuid, kuid))
90698+ goto error;
90699+
90700 if (ns_capable(old->user_ns, CAP_SETUID)) {
90701 new->suid = new->uid = kuid;
90702 if (!uid_eq(kuid, old->uid)) {
90703@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90704 goto error;
90705 }
90706
90707+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90708+ goto error;
90709+
90710 if (ruid != (uid_t) -1) {
90711 new->uid = kruid;
90712 if (!uid_eq(kruid, old->uid)) {
90713@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90714 goto error;
90715 }
90716
90717+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90718+ goto error;
90719+
90720 if (rgid != (gid_t) -1)
90721 new->gid = krgid;
90722 if (egid != (gid_t) -1)
90723@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90724 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90725 ns_capable(old->user_ns, CAP_SETUID)) {
90726 if (!uid_eq(kuid, old->fsuid)) {
90727+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90728+ goto error;
90729+
90730 new->fsuid = kuid;
90731 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90732 goto change_okay;
90733 }
90734 }
90735
90736+error:
90737 abort_creds(new);
90738 return old_fsuid;
90739
90740@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90741 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90742 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90743 ns_capable(old->user_ns, CAP_SETGID)) {
90744+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90745+ goto error;
90746+
90747 if (!gid_eq(kgid, old->fsgid)) {
90748 new->fsgid = kgid;
90749 goto change_okay;
90750 }
90751 }
90752
90753+error:
90754 abort_creds(new);
90755 return old_fsgid;
90756
90757@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90758 return -EFAULT;
90759
90760 down_read(&uts_sem);
90761- error = __copy_to_user(&name->sysname, &utsname()->sysname,
90762+ error = __copy_to_user(name->sysname, &utsname()->sysname,
90763 __OLD_UTS_LEN);
90764 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90765- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90766+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
90767 __OLD_UTS_LEN);
90768 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90769- error |= __copy_to_user(&name->release, &utsname()->release,
90770+ error |= __copy_to_user(name->release, &utsname()->release,
90771 __OLD_UTS_LEN);
90772 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90773- error |= __copy_to_user(&name->version, &utsname()->version,
90774+ error |= __copy_to_user(name->version, &utsname()->version,
90775 __OLD_UTS_LEN);
90776 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90777- error |= __copy_to_user(&name->machine, &utsname()->machine,
90778+ error |= __copy_to_user(name->machine, &utsname()->machine,
90779 __OLD_UTS_LEN);
90780 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90781 up_read(&uts_sem);
90782@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90783 */
90784 new_rlim->rlim_cur = 1;
90785 }
90786+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90787+ is changed to a lower value. Since tasks can be created by the same
90788+ user in between this limit change and an execve by this task, force
90789+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90790+ */
90791+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90792+ tsk->flags |= PF_NPROC_EXCEEDED;
90793 }
90794 if (!retval) {
90795 if (old_rlim)
90796diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90797index 0e0373f..69f5181 100644
90798--- a/kernel/sysctl.c
90799+++ b/kernel/sysctl.c
90800@@ -94,7 +94,6 @@
90801
90802
90803 #if defined(CONFIG_SYSCTL)
90804-
90805 /* External variables not in a header file. */
90806 extern int max_threads;
90807 extern int suid_dumpable;
90808@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
90809
90810 /* Constants used for minimum and maximum */
90811 #ifdef CONFIG_LOCKUP_DETECTOR
90812-static int sixty = 60;
90813+static int sixty __read_only = 60;
90814 #endif
90815
90816-static int __maybe_unused neg_one = -1;
90817+static int __maybe_unused neg_one __read_only = -1;
90818
90819-static int zero;
90820-static int __maybe_unused one = 1;
90821-static int __maybe_unused two = 2;
90822-static int __maybe_unused four = 4;
90823-static unsigned long one_ul = 1;
90824-static int one_hundred = 100;
90825+static int zero __read_only = 0;
90826+static int __maybe_unused one __read_only = 1;
90827+static int __maybe_unused two __read_only = 2;
90828+static int __maybe_unused three __read_only = 3;
90829+static int __maybe_unused four __read_only = 4;
90830+static unsigned long one_ul __read_only = 1;
90831+static int one_hundred __read_only = 100;
90832 #ifdef CONFIG_PRINTK
90833-static int ten_thousand = 10000;
90834+static int ten_thousand __read_only = 10000;
90835 #endif
90836
90837 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90838@@ -178,10 +178,8 @@ static int proc_taint(struct ctl_table *table, int write,
90839 void __user *buffer, size_t *lenp, loff_t *ppos);
90840 #endif
90841
90842-#ifdef CONFIG_PRINTK
90843 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90844 void __user *buffer, size_t *lenp, loff_t *ppos);
90845-#endif
90846
90847 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90848 void __user *buffer, size_t *lenp, loff_t *ppos);
90849@@ -212,6 +210,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90850
90851 #endif
90852
90853+extern struct ctl_table grsecurity_table[];
90854+
90855 static struct ctl_table kern_table[];
90856 static struct ctl_table vm_table[];
90857 static struct ctl_table fs_table[];
90858@@ -226,6 +226,20 @@ extern struct ctl_table epoll_table[];
90859 int sysctl_legacy_va_layout;
90860 #endif
90861
90862+#ifdef CONFIG_PAX_SOFTMODE
90863+static ctl_table pax_table[] = {
90864+ {
90865+ .procname = "softmode",
90866+ .data = &pax_softmode,
90867+ .maxlen = sizeof(unsigned int),
90868+ .mode = 0600,
90869+ .proc_handler = &proc_dointvec,
90870+ },
90871+
90872+ { }
90873+};
90874+#endif
90875+
90876 /* The default sysctl tables: */
90877
90878 static struct ctl_table sysctl_base_table[] = {
90879@@ -274,6 +288,22 @@ static int max_extfrag_threshold = 1000;
90880 #endif
90881
90882 static struct ctl_table kern_table[] = {
90883+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90884+ {
90885+ .procname = "grsecurity",
90886+ .mode = 0500,
90887+ .child = grsecurity_table,
90888+ },
90889+#endif
90890+
90891+#ifdef CONFIG_PAX_SOFTMODE
90892+ {
90893+ .procname = "pax",
90894+ .mode = 0500,
90895+ .child = pax_table,
90896+ },
90897+#endif
90898+
90899 {
90900 .procname = "sched_child_runs_first",
90901 .data = &sysctl_sched_child_runs_first,
90902@@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
90903 .data = &modprobe_path,
90904 .maxlen = KMOD_PATH_LEN,
90905 .mode = 0644,
90906- .proc_handler = proc_dostring,
90907+ .proc_handler = proc_dostring_modpriv,
90908 },
90909 {
90910 .procname = "modules_disabled",
90911@@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
90912 .extra1 = &zero,
90913 .extra2 = &one,
90914 },
90915+#endif
90916 {
90917 .procname = "kptr_restrict",
90918 .data = &kptr_restrict,
90919 .maxlen = sizeof(int),
90920 .mode = 0644,
90921 .proc_handler = proc_dointvec_minmax_sysadmin,
90922+#ifdef CONFIG_GRKERNSEC_HIDESYM
90923+ .extra1 = &two,
90924+#else
90925 .extra1 = &zero,
90926+#endif
90927 .extra2 = &two,
90928 },
90929-#endif
90930 {
90931 .procname = "ngroups_max",
90932 .data = &ngroups_max,
90933@@ -1050,10 +1084,17 @@ static struct ctl_table kern_table[] = {
90934 */
90935 {
90936 .procname = "perf_event_paranoid",
90937- .data = &sysctl_perf_event_paranoid,
90938- .maxlen = sizeof(sysctl_perf_event_paranoid),
90939+ .data = &sysctl_perf_event_legitimately_concerned,
90940+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90941 .mode = 0644,
90942- .proc_handler = proc_dointvec,
90943+ /* go ahead, be a hero */
90944+ .proc_handler = proc_dointvec_minmax_sysadmin,
90945+ .extra1 = &neg_one,
90946+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90947+ .extra2 = &three,
90948+#else
90949+ .extra2 = &two,
90950+#endif
90951 },
90952 {
90953 .procname = "perf_event_mlock_kb",
90954@@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
90955 .proc_handler = proc_dointvec_minmax,
90956 .extra1 = &zero,
90957 },
90958+ {
90959+ .procname = "heap_stack_gap",
90960+ .data = &sysctl_heap_stack_gap,
90961+ .maxlen = sizeof(sysctl_heap_stack_gap),
90962+ .mode = 0644,
90963+ .proc_handler = proc_doulongvec_minmax,
90964+ },
90965 #else
90966 {
90967 .procname = "nr_trim_pages",
90968@@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
90969 buffer, lenp, ppos);
90970 }
90971
90972+int proc_dostring_modpriv(struct ctl_table *table, int write,
90973+ void __user *buffer, size_t *lenp, loff_t *ppos)
90974+{
90975+ if (write && !capable(CAP_SYS_MODULE))
90976+ return -EPERM;
90977+
90978+ return _proc_do_string(table->data, table->maxlen, write,
90979+ buffer, lenp, ppos);
90980+}
90981+
90982 static size_t proc_skip_spaces(char **buf)
90983 {
90984 size_t ret;
90985@@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90986 len = strlen(tmp);
90987 if (len > *size)
90988 len = *size;
90989+ if (len > sizeof(tmp))
90990+ len = sizeof(tmp);
90991 if (copy_to_user(*buf, tmp, len))
90992 return -EFAULT;
90993 *size -= len;
90994@@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90995 static int proc_taint(struct ctl_table *table, int write,
90996 void __user *buffer, size_t *lenp, loff_t *ppos)
90997 {
90998- struct ctl_table t;
90999+ ctl_table_no_const t;
91000 unsigned long tmptaint = get_taint();
91001 int err;
91002
91003@@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
91004 return err;
91005 }
91006
91007-#ifdef CONFIG_PRINTK
91008 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
91009 void __user *buffer, size_t *lenp, loff_t *ppos)
91010 {
91011@@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
91012
91013 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
91014 }
91015-#endif
91016
91017 struct do_proc_dointvec_minmax_conv_param {
91018 int *min;
91019@@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
91020 return -ENOSYS;
91021 }
91022
91023+int proc_dostring_modpriv(struct ctl_table *table, int write,
91024+ void __user *buffer, size_t *lenp, loff_t *ppos)
91025+{
91026+ return -ENOSYS;
91027+}
91028+
91029 int proc_dointvec(struct ctl_table *table, int write,
91030 void __user *buffer, size_t *lenp, loff_t *ppos)
91031 {
91032@@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
91033 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
91034 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
91035 EXPORT_SYMBOL(proc_dostring);
91036+EXPORT_SYMBOL(proc_dostring_modpriv);
91037 EXPORT_SYMBOL(proc_doulongvec_minmax);
91038 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
91039diff --git a/kernel/taskstats.c b/kernel/taskstats.c
91040index 13d2f7c..c93d0b0 100644
91041--- a/kernel/taskstats.c
91042+++ b/kernel/taskstats.c
91043@@ -28,9 +28,12 @@
91044 #include <linux/fs.h>
91045 #include <linux/file.h>
91046 #include <linux/pid_namespace.h>
91047+#include <linux/grsecurity.h>
91048 #include <net/genetlink.h>
91049 #include <linux/atomic.h>
91050
91051+extern int gr_is_taskstats_denied(int pid);
91052+
91053 /*
91054 * Maximum length of a cpumask that can be specified in
91055 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
91056@@ -576,6 +579,9 @@ err:
91057
91058 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
91059 {
91060+ if (gr_is_taskstats_denied(current->pid))
91061+ return -EACCES;
91062+
91063 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
91064 return cmd_attr_register_cpumask(info);
91065 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
91066diff --git a/kernel/time.c b/kernel/time.c
91067index 7c7964c..2a0d412 100644
91068--- a/kernel/time.c
91069+++ b/kernel/time.c
91070@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
91071 return error;
91072
91073 if (tz) {
91074+ /* we log in do_settimeofday called below, so don't log twice
91075+ */
91076+ if (!tv)
91077+ gr_log_timechange();
91078+
91079 sys_tz = *tz;
91080 update_vsyscall_tz();
91081 if (firsttime) {
91082diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
91083index fe75444..190c528 100644
91084--- a/kernel/time/alarmtimer.c
91085+++ b/kernel/time/alarmtimer.c
91086@@ -811,7 +811,7 @@ static int __init alarmtimer_init(void)
91087 struct platform_device *pdev;
91088 int error = 0;
91089 int i;
91090- struct k_clock alarm_clock = {
91091+ static struct k_clock alarm_clock = {
91092 .clock_getres = alarm_clock_getres,
91093 .clock_get = alarm_clock_get,
91094 .timer_create = alarm_timer_create,
91095diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
91096index f7df8ea..0810193 100644
91097--- a/kernel/time/timekeeping.c
91098+++ b/kernel/time/timekeeping.c
91099@@ -15,6 +15,7 @@
91100 #include <linux/init.h>
91101 #include <linux/mm.h>
91102 #include <linux/sched.h>
91103+#include <linux/grsecurity.h>
91104 #include <linux/syscore_ops.h>
91105 #include <linux/clocksource.h>
91106 #include <linux/jiffies.h>
91107@@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
91108 if (!timespec_valid_strict(tv))
91109 return -EINVAL;
91110
91111+ gr_log_timechange();
91112+
91113 raw_spin_lock_irqsave(&timekeeper_lock, flags);
91114 write_seqcount_begin(&timekeeper_seq);
91115
91116diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
91117index 61ed862..3b52c65 100644
91118--- a/kernel/time/timer_list.c
91119+++ b/kernel/time/timer_list.c
91120@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
91121
91122 static void print_name_offset(struct seq_file *m, void *sym)
91123 {
91124+#ifdef CONFIG_GRKERNSEC_HIDESYM
91125+ SEQ_printf(m, "<%p>", NULL);
91126+#else
91127 char symname[KSYM_NAME_LEN];
91128
91129 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
91130 SEQ_printf(m, "<%pK>", sym);
91131 else
91132 SEQ_printf(m, "%s", symname);
91133+#endif
91134 }
91135
91136 static void
91137@@ -119,7 +123,11 @@ next_one:
91138 static void
91139 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
91140 {
91141+#ifdef CONFIG_GRKERNSEC_HIDESYM
91142+ SEQ_printf(m, " .base: %p\n", NULL);
91143+#else
91144 SEQ_printf(m, " .base: %pK\n", base);
91145+#endif
91146 SEQ_printf(m, " .index: %d\n",
91147 base->index);
91148 SEQ_printf(m, " .resolution: %Lu nsecs\n",
91149@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
91150 {
91151 struct proc_dir_entry *pe;
91152
91153+#ifdef CONFIG_GRKERNSEC_PROC_ADD
91154+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
91155+#else
91156 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
91157+#endif
91158 if (!pe)
91159 return -ENOMEM;
91160 return 0;
91161diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
91162index 1fb08f2..ca4bb1e 100644
91163--- a/kernel/time/timer_stats.c
91164+++ b/kernel/time/timer_stats.c
91165@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
91166 static unsigned long nr_entries;
91167 static struct entry entries[MAX_ENTRIES];
91168
91169-static atomic_t overflow_count;
91170+static atomic_unchecked_t overflow_count;
91171
91172 /*
91173 * The entries are in a hash-table, for fast lookup:
91174@@ -140,7 +140,7 @@ static void reset_entries(void)
91175 nr_entries = 0;
91176 memset(entries, 0, sizeof(entries));
91177 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
91178- atomic_set(&overflow_count, 0);
91179+ atomic_set_unchecked(&overflow_count, 0);
91180 }
91181
91182 static struct entry *alloc_entry(void)
91183@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91184 if (likely(entry))
91185 entry->count++;
91186 else
91187- atomic_inc(&overflow_count);
91188+ atomic_inc_unchecked(&overflow_count);
91189
91190 out_unlock:
91191 raw_spin_unlock_irqrestore(lock, flags);
91192@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91193
91194 static void print_name_offset(struct seq_file *m, unsigned long addr)
91195 {
91196+#ifdef CONFIG_GRKERNSEC_HIDESYM
91197+ seq_printf(m, "<%p>", NULL);
91198+#else
91199 char symname[KSYM_NAME_LEN];
91200
91201 if (lookup_symbol_name(addr, symname) < 0)
91202- seq_printf(m, "<%p>", (void *)addr);
91203+ seq_printf(m, "<%pK>", (void *)addr);
91204 else
91205 seq_printf(m, "%s", symname);
91206+#endif
91207 }
91208
91209 static int tstats_show(struct seq_file *m, void *v)
91210@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
91211
91212 seq_puts(m, "Timer Stats Version: v0.3\n");
91213 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
91214- if (atomic_read(&overflow_count))
91215- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
91216+ if (atomic_read_unchecked(&overflow_count))
91217+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
91218 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
91219
91220 for (i = 0; i < nr_entries; i++) {
91221@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
91222 {
91223 struct proc_dir_entry *pe;
91224
91225+#ifdef CONFIG_GRKERNSEC_PROC_ADD
91226+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
91227+#else
91228 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
91229+#endif
91230 if (!pe)
91231 return -ENOMEM;
91232 return 0;
91233diff --git a/kernel/timer.c b/kernel/timer.c
91234index 3bb01a3..0e7760e 100644
91235--- a/kernel/timer.c
91236+++ b/kernel/timer.c
91237@@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
91238 /*
91239 * This function runs timers and the timer-tq in bottom half context.
91240 */
91241-static void run_timer_softirq(struct softirq_action *h)
91242+static __latent_entropy void run_timer_softirq(void)
91243 {
91244 struct tvec_base *base = __this_cpu_read(tvec_bases);
91245
91246@@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
91247 *
91248 * In all cases the return value is guaranteed to be non-negative.
91249 */
91250-signed long __sched schedule_timeout(signed long timeout)
91251+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
91252 {
91253 struct timer_list timer;
91254 unsigned long expire;
91255diff --git a/kernel/torture.c b/kernel/torture.c
91256index acc9afc..4f9eb49 100644
91257--- a/kernel/torture.c
91258+++ b/kernel/torture.c
91259@@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
91260 mutex_lock(&fullstop_mutex);
91261 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
91262 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
91263- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
91264+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
91265 } else {
91266 pr_warn("Concurrent rmmod and shutdown illegal!\n");
91267 }
91268@@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
91269 do {
91270 if (!torture_must_stop()) {
91271 schedule_timeout_interruptible(stutter);
91272- ACCESS_ONCE(stutter_pause_test) = 1;
91273+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
91274 }
91275 if (!torture_must_stop())
91276 schedule_timeout_interruptible(stutter);
91277- ACCESS_ONCE(stutter_pause_test) = 0;
91278+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
91279 torture_shutdown_absorb("torture_stutter");
91280 } while (!torture_must_stop());
91281 torture_kthread_stopping("torture_stutter");
91282@@ -636,7 +636,7 @@ bool torture_cleanup(void)
91283 schedule_timeout_uninterruptible(10);
91284 return true;
91285 }
91286- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
91287+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
91288 mutex_unlock(&fullstop_mutex);
91289 torture_shutdown_cleanup();
91290 torture_shuffle_cleanup();
91291diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
91292index c1bd4ad..4b861dc 100644
91293--- a/kernel/trace/blktrace.c
91294+++ b/kernel/trace/blktrace.c
91295@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
91296 struct blk_trace *bt = filp->private_data;
91297 char buf[16];
91298
91299- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
91300+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
91301
91302 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
91303 }
91304@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
91305 return 1;
91306
91307 bt = buf->chan->private_data;
91308- atomic_inc(&bt->dropped);
91309+ atomic_inc_unchecked(&bt->dropped);
91310 return 0;
91311 }
91312
91313@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
91314
91315 bt->dir = dir;
91316 bt->dev = dev;
91317- atomic_set(&bt->dropped, 0);
91318+ atomic_set_unchecked(&bt->dropped, 0);
91319 INIT_LIST_HEAD(&bt->running_list);
91320
91321 ret = -EIO;
91322diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
91323index 5aeac53..863ed29 100644
91324--- a/kernel/trace/ftrace.c
91325+++ b/kernel/trace/ftrace.c
91326@@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
91327 if (unlikely(ftrace_disabled))
91328 return 0;
91329
91330+ ret = ftrace_arch_code_modify_prepare();
91331+ FTRACE_WARN_ON(ret);
91332+ if (ret)
91333+ return 0;
91334+
91335 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
91336+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
91337 if (ret) {
91338 ftrace_bug(ret, ip);
91339- return 0;
91340 }
91341- return 1;
91342+ return ret ? 0 : 1;
91343 }
91344
91345 /*
91346@@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
91347 if (!count)
91348 return 0;
91349
91350+ pax_open_kernel();
91351 sort(start, count, sizeof(*start),
91352 ftrace_cmp_ips, ftrace_swap_ips);
91353+ pax_close_kernel();
91354
91355 start_pg = ftrace_allocate_pages(count);
91356 if (!start_pg)
91357@@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
91358 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
91359
91360 static int ftrace_graph_active;
91361-static struct notifier_block ftrace_suspend_notifier;
91362-
91363 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
91364 {
91365 return 0;
91366@@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
91367 ftrace_graph_entry = ftrace_graph_entry_test;
91368 }
91369
91370+static struct notifier_block ftrace_suspend_notifier = {
91371+ .notifier_call = ftrace_suspend_notifier_call
91372+};
91373+
91374 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91375 trace_func_graph_ent_t entryfunc)
91376 {
91377@@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91378 goto out;
91379 }
91380
91381- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
91382 register_pm_notifier(&ftrace_suspend_notifier);
91383
91384 ftrace_graph_active++;
91385diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
91386index ff70271..e1e8cf1 100644
91387--- a/kernel/trace/ring_buffer.c
91388+++ b/kernel/trace/ring_buffer.c
91389@@ -352,9 +352,9 @@ struct buffer_data_page {
91390 */
91391 struct buffer_page {
91392 struct list_head list; /* list of buffer pages */
91393- local_t write; /* index for next write */
91394+ local_unchecked_t write; /* index for next write */
91395 unsigned read; /* index for next read */
91396- local_t entries; /* entries on this page */
91397+ local_unchecked_t entries; /* entries on this page */
91398 unsigned long real_end; /* real end of data */
91399 struct buffer_data_page *page; /* Actual data page */
91400 };
91401@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
91402 unsigned long last_overrun;
91403 local_t entries_bytes;
91404 local_t entries;
91405- local_t overrun;
91406- local_t commit_overrun;
91407+ local_unchecked_t overrun;
91408+ local_unchecked_t commit_overrun;
91409 local_t dropped_events;
91410 local_t committing;
91411 local_t commits;
91412@@ -991,8 +991,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91413 *
91414 * We add a counter to the write field to denote this.
91415 */
91416- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
91417- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
91418+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
91419+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
91420
91421 /*
91422 * Just make sure we have seen our old_write and synchronize
91423@@ -1020,8 +1020,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91424 * cmpxchg to only update if an interrupt did not already
91425 * do it for us. If the cmpxchg fails, we don't care.
91426 */
91427- (void)local_cmpxchg(&next_page->write, old_write, val);
91428- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
91429+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
91430+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
91431
91432 /*
91433 * No need to worry about races with clearing out the commit.
91434@@ -1388,12 +1388,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
91435
91436 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
91437 {
91438- return local_read(&bpage->entries) & RB_WRITE_MASK;
91439+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
91440 }
91441
91442 static inline unsigned long rb_page_write(struct buffer_page *bpage)
91443 {
91444- return local_read(&bpage->write) & RB_WRITE_MASK;
91445+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
91446 }
91447
91448 static int
91449@@ -1488,7 +1488,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
91450 * bytes consumed in ring buffer from here.
91451 * Increment overrun to account for the lost events.
91452 */
91453- local_add(page_entries, &cpu_buffer->overrun);
91454+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
91455 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91456 }
91457
91458@@ -2066,7 +2066,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91459 * it is our responsibility to update
91460 * the counters.
91461 */
91462- local_add(entries, &cpu_buffer->overrun);
91463+ local_add_unchecked(entries, &cpu_buffer->overrun);
91464 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91465
91466 /*
91467@@ -2216,7 +2216,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91468 if (tail == BUF_PAGE_SIZE)
91469 tail_page->real_end = 0;
91470
91471- local_sub(length, &tail_page->write);
91472+ local_sub_unchecked(length, &tail_page->write);
91473 return;
91474 }
91475
91476@@ -2251,7 +2251,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91477 rb_event_set_padding(event);
91478
91479 /* Set the write back to the previous setting */
91480- local_sub(length, &tail_page->write);
91481+ local_sub_unchecked(length, &tail_page->write);
91482 return;
91483 }
91484
91485@@ -2263,7 +2263,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91486
91487 /* Set write to end of buffer */
91488 length = (tail + length) - BUF_PAGE_SIZE;
91489- local_sub(length, &tail_page->write);
91490+ local_sub_unchecked(length, &tail_page->write);
91491 }
91492
91493 /*
91494@@ -2289,7 +2289,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91495 * about it.
91496 */
91497 if (unlikely(next_page == commit_page)) {
91498- local_inc(&cpu_buffer->commit_overrun);
91499+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91500 goto out_reset;
91501 }
91502
91503@@ -2345,7 +2345,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91504 cpu_buffer->tail_page) &&
91505 (cpu_buffer->commit_page ==
91506 cpu_buffer->reader_page))) {
91507- local_inc(&cpu_buffer->commit_overrun);
91508+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91509 goto out_reset;
91510 }
91511 }
91512@@ -2393,7 +2393,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91513 length += RB_LEN_TIME_EXTEND;
91514
91515 tail_page = cpu_buffer->tail_page;
91516- write = local_add_return(length, &tail_page->write);
91517+ write = local_add_return_unchecked(length, &tail_page->write);
91518
91519 /* set write to only the index of the write */
91520 write &= RB_WRITE_MASK;
91521@@ -2417,7 +2417,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91522 kmemcheck_annotate_bitfield(event, bitfield);
91523 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91524
91525- local_inc(&tail_page->entries);
91526+ local_inc_unchecked(&tail_page->entries);
91527
91528 /*
91529 * If this is the first commit on the page, then update
91530@@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91531
91532 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91533 unsigned long write_mask =
91534- local_read(&bpage->write) & ~RB_WRITE_MASK;
91535+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91536 unsigned long event_length = rb_event_length(event);
91537 /*
91538 * This is on the tail page. It is possible that
91539@@ -2460,7 +2460,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91540 */
91541 old_index += write_mask;
91542 new_index += write_mask;
91543- index = local_cmpxchg(&bpage->write, old_index, new_index);
91544+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91545 if (index == old_index) {
91546 /* update counters */
91547 local_sub(event_length, &cpu_buffer->entries_bytes);
91548@@ -2852,7 +2852,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91549
91550 /* Do the likely case first */
91551 if (likely(bpage->page == (void *)addr)) {
91552- local_dec(&bpage->entries);
91553+ local_dec_unchecked(&bpage->entries);
91554 return;
91555 }
91556
91557@@ -2864,7 +2864,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91558 start = bpage;
91559 do {
91560 if (bpage->page == (void *)addr) {
91561- local_dec(&bpage->entries);
91562+ local_dec_unchecked(&bpage->entries);
91563 return;
91564 }
91565 rb_inc_page(cpu_buffer, &bpage);
91566@@ -3148,7 +3148,7 @@ static inline unsigned long
91567 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91568 {
91569 return local_read(&cpu_buffer->entries) -
91570- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91571+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91572 }
91573
91574 /**
91575@@ -3237,7 +3237,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91576 return 0;
91577
91578 cpu_buffer = buffer->buffers[cpu];
91579- ret = local_read(&cpu_buffer->overrun);
91580+ ret = local_read_unchecked(&cpu_buffer->overrun);
91581
91582 return ret;
91583 }
91584@@ -3260,7 +3260,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91585 return 0;
91586
91587 cpu_buffer = buffer->buffers[cpu];
91588- ret = local_read(&cpu_buffer->commit_overrun);
91589+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91590
91591 return ret;
91592 }
91593@@ -3345,7 +3345,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91594 /* if you care about this being correct, lock the buffer */
91595 for_each_buffer_cpu(buffer, cpu) {
91596 cpu_buffer = buffer->buffers[cpu];
91597- overruns += local_read(&cpu_buffer->overrun);
91598+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91599 }
91600
91601 return overruns;
91602@@ -3521,8 +3521,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91603 /*
91604 * Reset the reader page to size zero.
91605 */
91606- local_set(&cpu_buffer->reader_page->write, 0);
91607- local_set(&cpu_buffer->reader_page->entries, 0);
91608+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91609+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91610 local_set(&cpu_buffer->reader_page->page->commit, 0);
91611 cpu_buffer->reader_page->real_end = 0;
91612
91613@@ -3556,7 +3556,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91614 * want to compare with the last_overrun.
91615 */
91616 smp_mb();
91617- overwrite = local_read(&(cpu_buffer->overrun));
91618+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91619
91620 /*
91621 * Here's the tricky part.
91622@@ -4126,8 +4126,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91623
91624 cpu_buffer->head_page
91625 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91626- local_set(&cpu_buffer->head_page->write, 0);
91627- local_set(&cpu_buffer->head_page->entries, 0);
91628+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91629+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91630 local_set(&cpu_buffer->head_page->page->commit, 0);
91631
91632 cpu_buffer->head_page->read = 0;
91633@@ -4137,14 +4137,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91634
91635 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91636 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91637- local_set(&cpu_buffer->reader_page->write, 0);
91638- local_set(&cpu_buffer->reader_page->entries, 0);
91639+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91640+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91641 local_set(&cpu_buffer->reader_page->page->commit, 0);
91642 cpu_buffer->reader_page->read = 0;
91643
91644 local_set(&cpu_buffer->entries_bytes, 0);
91645- local_set(&cpu_buffer->overrun, 0);
91646- local_set(&cpu_buffer->commit_overrun, 0);
91647+ local_set_unchecked(&cpu_buffer->overrun, 0);
91648+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91649 local_set(&cpu_buffer->dropped_events, 0);
91650 local_set(&cpu_buffer->entries, 0);
91651 local_set(&cpu_buffer->committing, 0);
91652@@ -4549,8 +4549,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91653 rb_init_page(bpage);
91654 bpage = reader->page;
91655 reader->page = *data_page;
91656- local_set(&reader->write, 0);
91657- local_set(&reader->entries, 0);
91658+ local_set_unchecked(&reader->write, 0);
91659+ local_set_unchecked(&reader->entries, 0);
91660 reader->read = 0;
91661 *data_page = bpage;
91662
91663diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91664index e1baa92f..7b2e345 100644
91665--- a/kernel/trace/trace.c
91666+++ b/kernel/trace/trace.c
91667@@ -3461,7 +3461,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91668 return 0;
91669 }
91670
91671-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91672+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91673 {
91674 /* do nothing if flag is already set */
91675 if (!!(trace_flags & mask) == !!enabled)
91676diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91677index 99676cd..670b9e8 100644
91678--- a/kernel/trace/trace.h
91679+++ b/kernel/trace/trace.h
91680@@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91681 void trace_printk_init_buffers(void);
91682 void trace_printk_start_comm(void);
91683 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91684-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91685+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91686
91687 /*
91688 * Normal trace_printk() and friends allocates special buffers
91689diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91690index 57b67b1..66082a9 100644
91691--- a/kernel/trace/trace_clock.c
91692+++ b/kernel/trace/trace_clock.c
91693@@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
91694 return now;
91695 }
91696
91697-static atomic64_t trace_counter;
91698+static atomic64_unchecked_t trace_counter;
91699
91700 /*
91701 * trace_clock_counter(): simply an atomic counter.
91702@@ -133,5 +133,5 @@ static atomic64_t trace_counter;
91703 */
91704 u64 notrace trace_clock_counter(void)
91705 {
91706- return atomic64_add_return(1, &trace_counter);
91707+ return atomic64_inc_return_unchecked(&trace_counter);
91708 }
91709diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91710index aec1dac..6ca72ee 100644
91711--- a/kernel/trace/trace_events.c
91712+++ b/kernel/trace/trace_events.c
91713@@ -1719,7 +1719,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91714 return 0;
91715 }
91716
91717-struct ftrace_module_file_ops;
91718 static void __add_event_to_tracers(struct ftrace_event_call *call);
91719
91720 /* Add an additional event_call dynamically */
91721diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91722index 0abd9b8..6a663a2 100644
91723--- a/kernel/trace/trace_mmiotrace.c
91724+++ b/kernel/trace/trace_mmiotrace.c
91725@@ -24,7 +24,7 @@ struct header_iter {
91726 static struct trace_array *mmio_trace_array;
91727 static bool overrun_detected;
91728 static unsigned long prev_overruns;
91729-static atomic_t dropped_count;
91730+static atomic_unchecked_t dropped_count;
91731
91732 static void mmio_reset_data(struct trace_array *tr)
91733 {
91734@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91735
91736 static unsigned long count_overruns(struct trace_iterator *iter)
91737 {
91738- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91739+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91740 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91741
91742 if (over > prev_overruns)
91743@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91744 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91745 sizeof(*entry), 0, pc);
91746 if (!event) {
91747- atomic_inc(&dropped_count);
91748+ atomic_inc_unchecked(&dropped_count);
91749 return;
91750 }
91751 entry = ring_buffer_event_data(event);
91752@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91753 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91754 sizeof(*entry), 0, pc);
91755 if (!event) {
91756- atomic_inc(&dropped_count);
91757+ atomic_inc_unchecked(&dropped_count);
91758 return;
91759 }
91760 entry = ring_buffer_event_data(event);
91761diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91762index a436de1..f64dde2 100644
91763--- a/kernel/trace/trace_output.c
91764+++ b/kernel/trace/trace_output.c
91765@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91766
91767 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91768 if (!IS_ERR(p)) {
91769- p = mangle_path(s->buffer + s->len, p, "\n");
91770+ p = mangle_path(s->buffer + s->len, p, "\n\\");
91771 if (p) {
91772 s->len = p - s->buffer;
91773 return 1;
91774@@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
91775 goto out;
91776 }
91777
91778+ pax_open_kernel();
91779 if (event->funcs->trace == NULL)
91780- event->funcs->trace = trace_nop_print;
91781+ *(void **)&event->funcs->trace = trace_nop_print;
91782 if (event->funcs->raw == NULL)
91783- event->funcs->raw = trace_nop_print;
91784+ *(void **)&event->funcs->raw = trace_nop_print;
91785 if (event->funcs->hex == NULL)
91786- event->funcs->hex = trace_nop_print;
91787+ *(void **)&event->funcs->hex = trace_nop_print;
91788 if (event->funcs->binary == NULL)
91789- event->funcs->binary = trace_nop_print;
91790+ *(void **)&event->funcs->binary = trace_nop_print;
91791+ pax_close_kernel();
91792
91793 key = event->type & (EVENT_HASHSIZE - 1);
91794
91795diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91796index 21b320e..40607bc 100644
91797--- a/kernel/trace/trace_stack.c
91798+++ b/kernel/trace/trace_stack.c
91799@@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91800 return;
91801
91802 /* we do not handle interrupt stacks yet */
91803- if (!object_is_on_stack(stack))
91804+ if (!object_starts_on_stack(stack))
91805 return;
91806
91807 local_irq_save(flags);
91808diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91809index bf71b4b..04dee68 100644
91810--- a/kernel/user_namespace.c
91811+++ b/kernel/user_namespace.c
91812@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91813 !kgid_has_mapping(parent_ns, group))
91814 return -EPERM;
91815
91816+#ifdef CONFIG_GRKERNSEC
91817+ /*
91818+ * This doesn't really inspire confidence:
91819+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91820+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91821+ * Increases kernel attack surface in areas developers
91822+ * previously cared little about ("low importance due
91823+ * to requiring "root" capability")
91824+ * To be removed when this code receives *proper* review
91825+ */
91826+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91827+ !capable(CAP_SETGID))
91828+ return -EPERM;
91829+#endif
91830+
91831 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91832 if (!ns)
91833 return -ENOMEM;
91834@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91835 if (atomic_read(&current->mm->mm_users) > 1)
91836 return -EINVAL;
91837
91838- if (current->fs->users != 1)
91839+ if (atomic_read(&current->fs->users) != 1)
91840 return -EINVAL;
91841
91842 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91843diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91844index 4f69f9a..7c6f8f8 100644
91845--- a/kernel/utsname_sysctl.c
91846+++ b/kernel/utsname_sysctl.c
91847@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91848 static int proc_do_uts_string(ctl_table *table, int write,
91849 void __user *buffer, size_t *lenp, loff_t *ppos)
91850 {
91851- struct ctl_table uts_table;
91852+ ctl_table_no_const uts_table;
91853 int r;
91854 memcpy(&uts_table, table, sizeof(uts_table));
91855 uts_table.data = get_uts(table, write);
91856diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91857index 30e4822..dd2b854 100644
91858--- a/kernel/watchdog.c
91859+++ b/kernel/watchdog.c
91860@@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91861 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91862 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91863
91864-static struct smp_hotplug_thread watchdog_threads = {
91865+static struct smp_hotplug_thread watchdog_threads __read_only = {
91866 .store = &softlockup_watchdog,
91867 .thread_should_run = watchdog_should_run,
91868 .thread_fn = watchdog,
91869diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91870index 7ba5897..c8ed1f2 100644
91871--- a/kernel/workqueue.c
91872+++ b/kernel/workqueue.c
91873@@ -4710,7 +4710,7 @@ static void rebind_workers(struct worker_pool *pool)
91874 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91875 worker_flags |= WORKER_REBOUND;
91876 worker_flags &= ~WORKER_UNBOUND;
91877- ACCESS_ONCE(worker->flags) = worker_flags;
91878+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91879 }
91880
91881 spin_unlock_irq(&pool->lock);
91882diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91883index 819ac51..1c8a65e 100644
91884--- a/lib/Kconfig.debug
91885+++ b/lib/Kconfig.debug
91886@@ -853,7 +853,7 @@ config DEBUG_MUTEXES
91887
91888 config DEBUG_WW_MUTEX_SLOWPATH
91889 bool "Wait/wound mutex debugging: Slowpath testing"
91890- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91891+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91892 select DEBUG_LOCK_ALLOC
91893 select DEBUG_SPINLOCK
91894 select DEBUG_MUTEXES
91895@@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91896
91897 config DEBUG_LOCK_ALLOC
91898 bool "Lock debugging: detect incorrect freeing of live locks"
91899- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91900+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91901 select DEBUG_SPINLOCK
91902 select DEBUG_MUTEXES
91903 select LOCKDEP
91904@@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
91905
91906 config PROVE_LOCKING
91907 bool "Lock debugging: prove locking correctness"
91908- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91909+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91910 select LOCKDEP
91911 select DEBUG_SPINLOCK
91912 select DEBUG_MUTEXES
91913@@ -931,7 +931,7 @@ config LOCKDEP
91914
91915 config LOCK_STAT
91916 bool "Lock usage statistics"
91917- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91918+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91919 select LOCKDEP
91920 select DEBUG_SPINLOCK
91921 select DEBUG_MUTEXES
91922@@ -1403,6 +1403,7 @@ config LATENCYTOP
91923 depends on DEBUG_KERNEL
91924 depends on STACKTRACE_SUPPORT
91925 depends on PROC_FS
91926+ depends on !GRKERNSEC_HIDESYM
91927 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91928 select KALLSYMS
91929 select KALLSYMS_ALL
91930@@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91931 config DEBUG_STRICT_USER_COPY_CHECKS
91932 bool "Strict user copy size checks"
91933 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91934- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91935+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91936 help
91937 Enabling this option turns a certain set of sanity checks for user
91938 copy operations into compile time failures.
91939@@ -1538,7 +1539,7 @@ endmenu # runtime tests
91940
91941 config PROVIDE_OHCI1394_DMA_INIT
91942 bool "Remote debugging over FireWire early on boot"
91943- depends on PCI && X86
91944+ depends on PCI && X86 && !GRKERNSEC
91945 help
91946 If you want to debug problems which hang or crash the kernel early
91947 on boot and the crashing machine has a FireWire port, you can use
91948diff --git a/lib/Makefile b/lib/Makefile
91949index 0cd7b68..e149e37 100644
91950--- a/lib/Makefile
91951+++ b/lib/Makefile
91952@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91953 obj-$(CONFIG_BTREE) += btree.o
91954 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91955 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91956-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91957+obj-y += list_debug.o
91958 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91959
91960 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91961diff --git a/lib/average.c b/lib/average.c
91962index 114d1be..ab0350c 100644
91963--- a/lib/average.c
91964+++ b/lib/average.c
91965@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91966 {
91967 unsigned long internal = ACCESS_ONCE(avg->internal);
91968
91969- ACCESS_ONCE(avg->internal) = internal ?
91970+ ACCESS_ONCE_RW(avg->internal) = internal ?
91971 (((internal << avg->weight) - internal) +
91972 (val << avg->factor)) >> avg->weight :
91973 (val << avg->factor);
91974diff --git a/lib/bitmap.c b/lib/bitmap.c
91975index 06f7e4f..f3cf2b0 100644
91976--- a/lib/bitmap.c
91977+++ b/lib/bitmap.c
91978@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91979 {
91980 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91981 u32 chunk;
91982- const char __user __force *ubuf = (const char __user __force *)buf;
91983+ const char __user *ubuf = (const char __force_user *)buf;
91984
91985 bitmap_zero(maskp, nmaskbits);
91986
91987@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91988 {
91989 if (!access_ok(VERIFY_READ, ubuf, ulen))
91990 return -EFAULT;
91991- return __bitmap_parse((const char __force *)ubuf,
91992+ return __bitmap_parse((const char __force_kernel *)ubuf,
91993 ulen, 1, maskp, nmaskbits);
91994
91995 }
91996@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91997 {
91998 unsigned a, b;
91999 int c, old_c, totaldigits;
92000- const char __user __force *ubuf = (const char __user __force *)buf;
92001+ const char __user *ubuf = (const char __force_user *)buf;
92002 int exp_digit, in_range;
92003
92004 totaldigits = c = 0;
92005@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
92006 {
92007 if (!access_ok(VERIFY_READ, ubuf, ulen))
92008 return -EFAULT;
92009- return __bitmap_parselist((const char __force *)ubuf,
92010+ return __bitmap_parselist((const char __force_kernel *)ubuf,
92011 ulen, 1, maskp, nmaskbits);
92012 }
92013 EXPORT_SYMBOL(bitmap_parselist_user);
92014diff --git a/lib/bug.c b/lib/bug.c
92015index 1686034..a9c00c8 100644
92016--- a/lib/bug.c
92017+++ b/lib/bug.c
92018@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
92019 return BUG_TRAP_TYPE_NONE;
92020
92021 bug = find_bug(bugaddr);
92022+ if (!bug)
92023+ return BUG_TRAP_TYPE_NONE;
92024
92025 file = NULL;
92026 line = 0;
92027diff --git a/lib/debugobjects.c b/lib/debugobjects.c
92028index e0731c3..ad66444 100644
92029--- a/lib/debugobjects.c
92030+++ b/lib/debugobjects.c
92031@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
92032 if (limit > 4)
92033 return;
92034
92035- is_on_stack = object_is_on_stack(addr);
92036+ is_on_stack = object_starts_on_stack(addr);
92037 if (is_on_stack == onstack)
92038 return;
92039
92040diff --git a/lib/div64.c b/lib/div64.c
92041index 4382ad7..08aa558 100644
92042--- a/lib/div64.c
92043+++ b/lib/div64.c
92044@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
92045 EXPORT_SYMBOL(__div64_32);
92046
92047 #ifndef div_s64_rem
92048-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
92049+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
92050 {
92051 u64 quotient;
92052
92053@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
92054 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
92055 */
92056 #ifndef div64_u64
92057-u64 div64_u64(u64 dividend, u64 divisor)
92058+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
92059 {
92060 u32 high = divisor >> 32;
92061 u64 quot;
92062diff --git a/lib/dma-debug.c b/lib/dma-debug.c
92063index 98f2d7e..899da5c 100644
92064--- a/lib/dma-debug.c
92065+++ b/lib/dma-debug.c
92066@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
92067
92068 void dma_debug_add_bus(struct bus_type *bus)
92069 {
92070- struct notifier_block *nb;
92071+ notifier_block_no_const *nb;
92072
92073 if (global_disable)
92074 return;
92075@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
92076
92077 static void check_for_stack(struct device *dev, void *addr)
92078 {
92079- if (object_is_on_stack(addr))
92080+ if (object_starts_on_stack(addr))
92081 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
92082 "stack [addr=%p]\n", addr);
92083 }
92084diff --git a/lib/hash.c b/lib/hash.c
92085index fea973f..386626f 100644
92086--- a/lib/hash.c
92087+++ b/lib/hash.c
92088@@ -14,7 +14,7 @@
92089 #include <linux/hash.h>
92090 #include <linux/cache.h>
92091
92092-static struct fast_hash_ops arch_hash_ops __read_mostly = {
92093+static struct fast_hash_ops arch_hash_ops __read_only = {
92094 .hash = jhash,
92095 .hash2 = jhash2,
92096 };
92097diff --git a/lib/inflate.c b/lib/inflate.c
92098index 013a761..c28f3fc 100644
92099--- a/lib/inflate.c
92100+++ b/lib/inflate.c
92101@@ -269,7 +269,7 @@ static void free(void *where)
92102 malloc_ptr = free_mem_ptr;
92103 }
92104 #else
92105-#define malloc(a) kmalloc(a, GFP_KERNEL)
92106+#define malloc(a) kmalloc((a), GFP_KERNEL)
92107 #define free(a) kfree(a)
92108 #endif
92109
92110diff --git a/lib/ioremap.c b/lib/ioremap.c
92111index 0c9216c..863bd89 100644
92112--- a/lib/ioremap.c
92113+++ b/lib/ioremap.c
92114@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
92115 unsigned long next;
92116
92117 phys_addr -= addr;
92118- pmd = pmd_alloc(&init_mm, pud, addr);
92119+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
92120 if (!pmd)
92121 return -ENOMEM;
92122 do {
92123@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
92124 unsigned long next;
92125
92126 phys_addr -= addr;
92127- pud = pud_alloc(&init_mm, pgd, addr);
92128+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
92129 if (!pud)
92130 return -ENOMEM;
92131 do {
92132diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
92133index bd2bea9..6b3c95e 100644
92134--- a/lib/is_single_threaded.c
92135+++ b/lib/is_single_threaded.c
92136@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
92137 struct task_struct *p, *t;
92138 bool ret;
92139
92140+ if (!mm)
92141+ return true;
92142+
92143 if (atomic_read(&task->signal->live) != 1)
92144 return false;
92145
92146diff --git a/lib/kobject.c b/lib/kobject.c
92147index 58751bb..93a1853 100644
92148--- a/lib/kobject.c
92149+++ b/lib/kobject.c
92150@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
92151
92152
92153 static DEFINE_SPINLOCK(kobj_ns_type_lock);
92154-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
92155+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
92156
92157-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92158+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92159 {
92160 enum kobj_ns_type type = ops->type;
92161 int error;
92162diff --git a/lib/list_debug.c b/lib/list_debug.c
92163index c24c2f7..f0296f4 100644
92164--- a/lib/list_debug.c
92165+++ b/lib/list_debug.c
92166@@ -11,7 +11,9 @@
92167 #include <linux/bug.h>
92168 #include <linux/kernel.h>
92169 #include <linux/rculist.h>
92170+#include <linux/mm.h>
92171
92172+#ifdef CONFIG_DEBUG_LIST
92173 /*
92174 * Insert a new entry between two known consecutive entries.
92175 *
92176@@ -19,21 +21,40 @@
92177 * the prev/next entries already!
92178 */
92179
92180+static bool __list_add_debug(struct list_head *new,
92181+ struct list_head *prev,
92182+ struct list_head *next)
92183+{
92184+ if (unlikely(next->prev != prev)) {
92185+ printk(KERN_ERR "list_add corruption. next->prev should be "
92186+ "prev (%p), but was %p. (next=%p).\n",
92187+ prev, next->prev, next);
92188+ BUG();
92189+ return false;
92190+ }
92191+ if (unlikely(prev->next != next)) {
92192+ printk(KERN_ERR "list_add corruption. prev->next should be "
92193+ "next (%p), but was %p. (prev=%p).\n",
92194+ next, prev->next, prev);
92195+ BUG();
92196+ return false;
92197+ }
92198+ if (unlikely(new == prev || new == next)) {
92199+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
92200+ new, prev, next);
92201+ BUG();
92202+ return false;
92203+ }
92204+ return true;
92205+}
92206+
92207 void __list_add(struct list_head *new,
92208- struct list_head *prev,
92209- struct list_head *next)
92210+ struct list_head *prev,
92211+ struct list_head *next)
92212 {
92213- WARN(next->prev != prev,
92214- "list_add corruption. next->prev should be "
92215- "prev (%p), but was %p. (next=%p).\n",
92216- prev, next->prev, next);
92217- WARN(prev->next != next,
92218- "list_add corruption. prev->next should be "
92219- "next (%p), but was %p. (prev=%p).\n",
92220- next, prev->next, prev);
92221- WARN(new == prev || new == next,
92222- "list_add double add: new=%p, prev=%p, next=%p.\n",
92223- new, prev, next);
92224+ if (!__list_add_debug(new, prev, next))
92225+ return;
92226+
92227 next->prev = new;
92228 new->next = next;
92229 new->prev = prev;
92230@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
92231 }
92232 EXPORT_SYMBOL(__list_add);
92233
92234-void __list_del_entry(struct list_head *entry)
92235+static bool __list_del_entry_debug(struct list_head *entry)
92236 {
92237 struct list_head *prev, *next;
92238
92239 prev = entry->prev;
92240 next = entry->next;
92241
92242- if (WARN(next == LIST_POISON1,
92243- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92244- entry, LIST_POISON1) ||
92245- WARN(prev == LIST_POISON2,
92246- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92247- entry, LIST_POISON2) ||
92248- WARN(prev->next != entry,
92249- "list_del corruption. prev->next should be %p, "
92250- "but was %p\n", entry, prev->next) ||
92251- WARN(next->prev != entry,
92252- "list_del corruption. next->prev should be %p, "
92253- "but was %p\n", entry, next->prev))
92254+ if (unlikely(next == LIST_POISON1)) {
92255+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92256+ entry, LIST_POISON1);
92257+ BUG();
92258+ return false;
92259+ }
92260+ if (unlikely(prev == LIST_POISON2)) {
92261+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92262+ entry, LIST_POISON2);
92263+ BUG();
92264+ return false;
92265+ }
92266+ if (unlikely(entry->prev->next != entry)) {
92267+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
92268+ "but was %p\n", entry, prev->next);
92269+ BUG();
92270+ return false;
92271+ }
92272+ if (unlikely(entry->next->prev != entry)) {
92273+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
92274+ "but was %p\n", entry, next->prev);
92275+ BUG();
92276+ return false;
92277+ }
92278+ return true;
92279+}
92280+
92281+void __list_del_entry(struct list_head *entry)
92282+{
92283+ if (!__list_del_entry_debug(entry))
92284 return;
92285
92286- __list_del(prev, next);
92287+ __list_del(entry->prev, entry->next);
92288 }
92289 EXPORT_SYMBOL(__list_del_entry);
92290
92291@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
92292 void __list_add_rcu(struct list_head *new,
92293 struct list_head *prev, struct list_head *next)
92294 {
92295- WARN(next->prev != prev,
92296- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
92297- prev, next->prev, next);
92298- WARN(prev->next != next,
92299- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
92300- next, prev->next, prev);
92301+ if (!__list_add_debug(new, prev, next))
92302+ return;
92303+
92304 new->next = next;
92305 new->prev = prev;
92306 rcu_assign_pointer(list_next_rcu(prev), new);
92307 next->prev = new;
92308 }
92309 EXPORT_SYMBOL(__list_add_rcu);
92310+#endif
92311+
92312+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
92313+{
92314+#ifdef CONFIG_DEBUG_LIST
92315+ if (!__list_add_debug(new, prev, next))
92316+ return;
92317+#endif
92318+
92319+ pax_open_kernel();
92320+ next->prev = new;
92321+ new->next = next;
92322+ new->prev = prev;
92323+ prev->next = new;
92324+ pax_close_kernel();
92325+}
92326+EXPORT_SYMBOL(__pax_list_add);
92327+
92328+void pax_list_del(struct list_head *entry)
92329+{
92330+#ifdef CONFIG_DEBUG_LIST
92331+ if (!__list_del_entry_debug(entry))
92332+ return;
92333+#endif
92334+
92335+ pax_open_kernel();
92336+ __list_del(entry->prev, entry->next);
92337+ entry->next = LIST_POISON1;
92338+ entry->prev = LIST_POISON2;
92339+ pax_close_kernel();
92340+}
92341+EXPORT_SYMBOL(pax_list_del);
92342+
92343+void pax_list_del_init(struct list_head *entry)
92344+{
92345+ pax_open_kernel();
92346+ __list_del(entry->prev, entry->next);
92347+ INIT_LIST_HEAD(entry);
92348+ pax_close_kernel();
92349+}
92350+EXPORT_SYMBOL(pax_list_del_init);
92351+
92352+void __pax_list_add_rcu(struct list_head *new,
92353+ struct list_head *prev, struct list_head *next)
92354+{
92355+#ifdef CONFIG_DEBUG_LIST
92356+ if (!__list_add_debug(new, prev, next))
92357+ return;
92358+#endif
92359+
92360+ pax_open_kernel();
92361+ new->next = next;
92362+ new->prev = prev;
92363+ rcu_assign_pointer(list_next_rcu(prev), new);
92364+ next->prev = new;
92365+ pax_close_kernel();
92366+}
92367+EXPORT_SYMBOL(__pax_list_add_rcu);
92368+
92369+void pax_list_del_rcu(struct list_head *entry)
92370+{
92371+#ifdef CONFIG_DEBUG_LIST
92372+ if (!__list_del_entry_debug(entry))
92373+ return;
92374+#endif
92375+
92376+ pax_open_kernel();
92377+ __list_del(entry->prev, entry->next);
92378+ entry->next = LIST_POISON1;
92379+ entry->prev = LIST_POISON2;
92380+ pax_close_kernel();
92381+}
92382+EXPORT_SYMBOL(pax_list_del_rcu);
92383diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
92384index 963b703..438bc51 100644
92385--- a/lib/percpu-refcount.c
92386+++ b/lib/percpu-refcount.c
92387@@ -29,7 +29,7 @@
92388 * can't hit 0 before we've added up all the percpu refs.
92389 */
92390
92391-#define PCPU_COUNT_BIAS (1U << 31)
92392+#define PCPU_COUNT_BIAS (1U << 30)
92393
92394 /**
92395 * percpu_ref_init - initialize a percpu refcount
92396diff --git a/lib/radix-tree.c b/lib/radix-tree.c
92397index 9599aa7..9cf6c72 100644
92398--- a/lib/radix-tree.c
92399+++ b/lib/radix-tree.c
92400@@ -66,7 +66,7 @@ struct radix_tree_preload {
92401 int nr;
92402 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
92403 };
92404-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
92405+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
92406
92407 static inline void *ptr_to_indirect(void *ptr)
92408 {
92409diff --git a/lib/random32.c b/lib/random32.c
92410index fa5da61..35fe9af 100644
92411--- a/lib/random32.c
92412+++ b/lib/random32.c
92413@@ -42,7 +42,7 @@
92414 static void __init prandom_state_selftest(void);
92415 #endif
92416
92417-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
92418+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
92419
92420 /**
92421 * prandom_u32_state - seeded pseudo-random number generator.
92422diff --git a/lib/rbtree.c b/lib/rbtree.c
92423index 65f4eff..2cfa167 100644
92424--- a/lib/rbtree.c
92425+++ b/lib/rbtree.c
92426@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
92427 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
92428
92429 static const struct rb_augment_callbacks dummy_callbacks = {
92430- dummy_propagate, dummy_copy, dummy_rotate
92431+ .propagate = dummy_propagate,
92432+ .copy = dummy_copy,
92433+ .rotate = dummy_rotate
92434 };
92435
92436 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92437diff --git a/lib/show_mem.c b/lib/show_mem.c
92438index 0922579..9d7adb9 100644
92439--- a/lib/show_mem.c
92440+++ b/lib/show_mem.c
92441@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92442 quicklist_total_size());
92443 #endif
92444 #ifdef CONFIG_MEMORY_FAILURE
92445- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92446+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92447 #endif
92448 }
92449diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92450index bb2b201..46abaf9 100644
92451--- a/lib/strncpy_from_user.c
92452+++ b/lib/strncpy_from_user.c
92453@@ -21,7 +21,7 @@
92454 */
92455 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92456 {
92457- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92458+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92459 long res = 0;
92460
92461 /*
92462diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92463index a28df52..3d55877 100644
92464--- a/lib/strnlen_user.c
92465+++ b/lib/strnlen_user.c
92466@@ -26,7 +26,7 @@
92467 */
92468 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92469 {
92470- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92471+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92472 long align, res = 0;
92473 unsigned long c;
92474
92475diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92476index b604b83..c0547f6 100644
92477--- a/lib/swiotlb.c
92478+++ b/lib/swiotlb.c
92479@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92480
92481 void
92482 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92483- dma_addr_t dev_addr)
92484+ dma_addr_t dev_addr, struct dma_attrs *attrs)
92485 {
92486 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92487
92488diff --git a/lib/usercopy.c b/lib/usercopy.c
92489index 4f5b1dd..7cab418 100644
92490--- a/lib/usercopy.c
92491+++ b/lib/usercopy.c
92492@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92493 WARN(1, "Buffer overflow detected!\n");
92494 }
92495 EXPORT_SYMBOL(copy_from_user_overflow);
92496+
92497+void copy_to_user_overflow(void)
92498+{
92499+ WARN(1, "Buffer overflow detected!\n");
92500+}
92501+EXPORT_SYMBOL(copy_to_user_overflow);
92502diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92503index 0648291..42bf42b 100644
92504--- a/lib/vsprintf.c
92505+++ b/lib/vsprintf.c
92506@@ -16,6 +16,9 @@
92507 * - scnprintf and vscnprintf
92508 */
92509
92510+#ifdef CONFIG_GRKERNSEC_HIDESYM
92511+#define __INCLUDED_BY_HIDESYM 1
92512+#endif
92513 #include <stdarg.h>
92514 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92515 #include <linux/types.h>
92516@@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
92517 return number(buf, end, num, spec);
92518 }
92519
92520+#ifdef CONFIG_GRKERNSEC_HIDESYM
92521+int kptr_restrict __read_mostly = 2;
92522+#else
92523 int kptr_restrict __read_mostly;
92524+#endif
92525
92526 /*
92527 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92528@@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92529 * - 'f' For simple symbolic function names without offset
92530 * - 'S' For symbolic direct pointers with offset
92531 * - 's' For symbolic direct pointers without offset
92532+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92533 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92534 * - 'B' For backtraced symbolic direct pointers with offset
92535 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92536@@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92537
92538 if (!ptr && *fmt != 'K') {
92539 /*
92540- * Print (null) with the same width as a pointer so it makes
92541+ * Print (nil) with the same width as a pointer so it makes
92542 * tabular output look nice.
92543 */
92544 if (spec.field_width == -1)
92545 spec.field_width = default_width;
92546- return string(buf, end, "(null)", spec);
92547+ return string(buf, end, "(nil)", spec);
92548 }
92549
92550 switch (*fmt) {
92551@@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92552 /* Fallthrough */
92553 case 'S':
92554 case 's':
92555+#ifdef CONFIG_GRKERNSEC_HIDESYM
92556+ break;
92557+#else
92558+ return symbol_string(buf, end, ptr, spec, fmt);
92559+#endif
92560+ case 'A':
92561 case 'B':
92562 return symbol_string(buf, end, ptr, spec, fmt);
92563 case 'R':
92564@@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92565 va_end(va);
92566 return buf;
92567 }
92568+ case 'P':
92569+ break;
92570 case 'K':
92571 /*
92572 * %pK cannot be used in IRQ context because its test
92573@@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92574 ((const struct file *)ptr)->f_path.dentry,
92575 spec, fmt);
92576 }
92577+
92578+#ifdef CONFIG_GRKERNSEC_HIDESYM
92579+ /* 'P' = approved pointers to copy to userland,
92580+ as in the /proc/kallsyms case, as we make it display nothing
92581+ for non-root users, and the real contents for root users
92582+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92583+ above
92584+ */
92585+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92586+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92587+ dump_stack();
92588+ ptr = NULL;
92589+ }
92590+#endif
92591+
92592 spec.flags |= SMALL;
92593 if (spec.field_width == -1) {
92594 spec.field_width = default_width;
92595@@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92596 typeof(type) value; \
92597 if (sizeof(type) == 8) { \
92598 args = PTR_ALIGN(args, sizeof(u32)); \
92599- *(u32 *)&value = *(u32 *)args; \
92600- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92601+ *(u32 *)&value = *(const u32 *)args; \
92602+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92603 } else { \
92604 args = PTR_ALIGN(args, sizeof(type)); \
92605- value = *(typeof(type) *)args; \
92606+ value = *(const typeof(type) *)args; \
92607 } \
92608 args += sizeof(type); \
92609 value; \
92610@@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92611 case FORMAT_TYPE_STR: {
92612 const char *str_arg = args;
92613 args += strlen(str_arg) + 1;
92614- str = string(str, end, (char *)str_arg, spec);
92615+ str = string(str, end, str_arg, spec);
92616 break;
92617 }
92618
92619diff --git a/localversion-grsec b/localversion-grsec
92620new file mode 100644
92621index 0000000..7cd6065
92622--- /dev/null
92623+++ b/localversion-grsec
92624@@ -0,0 +1 @@
92625+-grsec
92626diff --git a/mm/Kconfig b/mm/Kconfig
92627index 2f42b9c..6095e14 100644
92628--- a/mm/Kconfig
92629+++ b/mm/Kconfig
92630@@ -330,10 +330,11 @@ config KSM
92631 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92632
92633 config DEFAULT_MMAP_MIN_ADDR
92634- int "Low address space to protect from user allocation"
92635+ int "Low address space to protect from user allocation"
92636 depends on MMU
92637- default 4096
92638- help
92639+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92640+ default 65536
92641+ help
92642 This is the portion of low virtual memory which should be protected
92643 from userspace allocation. Keeping a user from writing to low pages
92644 can help reduce the impact of kernel NULL pointer bugs.
92645@@ -364,7 +365,7 @@ config MEMORY_FAILURE
92646
92647 config HWPOISON_INJECT
92648 tristate "HWPoison pages injector"
92649- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92650+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92651 select PROC_PAGE_MONITOR
92652
92653 config NOMMU_INITIAL_TRIM_EXCESS
92654diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92655index 09d9591..165bb75 100644
92656--- a/mm/backing-dev.c
92657+++ b/mm/backing-dev.c
92658@@ -12,7 +12,7 @@
92659 #include <linux/device.h>
92660 #include <trace/events/writeback.h>
92661
92662-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92663+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92664
92665 struct backing_dev_info default_backing_dev_info = {
92666 .name = "default",
92667@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92668 return err;
92669
92670 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92671- atomic_long_inc_return(&bdi_seq));
92672+ atomic_long_inc_return_unchecked(&bdi_seq));
92673 if (err) {
92674 bdi_destroy(bdi);
92675 return err;
92676diff --git a/mm/filemap.c b/mm/filemap.c
92677index 088358c..bb415bf 100644
92678--- a/mm/filemap.c
92679+++ b/mm/filemap.c
92680@@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92681 struct address_space *mapping = file->f_mapping;
92682
92683 if (!mapping->a_ops->readpage)
92684- return -ENOEXEC;
92685+ return -ENODEV;
92686 file_accessed(file);
92687 vma->vm_ops = &generic_file_vm_ops;
92688 return 0;
92689@@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92690 *pos = i_size_read(inode);
92691
92692 if (limit != RLIM_INFINITY) {
92693+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92694 if (*pos >= limit) {
92695 send_sig(SIGXFSZ, current, 0);
92696 return -EFBIG;
92697diff --git a/mm/fremap.c b/mm/fremap.c
92698index 34feba6..315fe78 100644
92699--- a/mm/fremap.c
92700+++ b/mm/fremap.c
92701@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92702 retry:
92703 vma = find_vma(mm, start);
92704
92705+#ifdef CONFIG_PAX_SEGMEXEC
92706+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92707+ goto out;
92708+#endif
92709+
92710 /*
92711 * Make sure the vma is shared, that it supports prefaulting,
92712 * and that the remapped range is valid and fully within
92713diff --git a/mm/highmem.c b/mm/highmem.c
92714index b32b70c..e512eb0 100644
92715--- a/mm/highmem.c
92716+++ b/mm/highmem.c
92717@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92718 * So no dangers, even with speculative execution.
92719 */
92720 page = pte_page(pkmap_page_table[i]);
92721+ pax_open_kernel();
92722 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92723-
92724+ pax_close_kernel();
92725 set_page_address(page, NULL);
92726 need_flush = 1;
92727 }
92728@@ -198,9 +199,11 @@ start:
92729 }
92730 }
92731 vaddr = PKMAP_ADDR(last_pkmap_nr);
92732+
92733+ pax_open_kernel();
92734 set_pte_at(&init_mm, vaddr,
92735 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92736-
92737+ pax_close_kernel();
92738 pkmap_count[last_pkmap_nr] = 1;
92739 set_page_address(page, (void *)vaddr);
92740
92741diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92742index 002f08e..68f11e8 100644
92743--- a/mm/hugetlb.c
92744+++ b/mm/hugetlb.c
92745@@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92746 struct hstate *h = &default_hstate;
92747 unsigned long tmp;
92748 int ret;
92749+ ctl_table_no_const hugetlb_table;
92750
92751 if (!hugepages_supported())
92752 return -ENOTSUPP;
92753@@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92754 if (write && h->order >= MAX_ORDER)
92755 return -EINVAL;
92756
92757- table->data = &tmp;
92758- table->maxlen = sizeof(unsigned long);
92759- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92760+ hugetlb_table = *table;
92761+ hugetlb_table.data = &tmp;
92762+ hugetlb_table.maxlen = sizeof(unsigned long);
92763+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92764 if (ret)
92765 goto out;
92766
92767@@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92768 struct hstate *h = &default_hstate;
92769 unsigned long tmp;
92770 int ret;
92771+ ctl_table_no_const hugetlb_table;
92772
92773 if (!hugepages_supported())
92774 return -ENOTSUPP;
92775@@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92776 if (write && h->order >= MAX_ORDER)
92777 return -EINVAL;
92778
92779- table->data = &tmp;
92780- table->maxlen = sizeof(unsigned long);
92781- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92782+ hugetlb_table = *table;
92783+ hugetlb_table.data = &tmp;
92784+ hugetlb_table.maxlen = sizeof(unsigned long);
92785+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92786 if (ret)
92787 goto out;
92788
92789@@ -2655,6 +2659,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92790 return 1;
92791 }
92792
92793+#ifdef CONFIG_PAX_SEGMEXEC
92794+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92795+{
92796+ struct mm_struct *mm = vma->vm_mm;
92797+ struct vm_area_struct *vma_m;
92798+ unsigned long address_m;
92799+ pte_t *ptep_m;
92800+
92801+ vma_m = pax_find_mirror_vma(vma);
92802+ if (!vma_m)
92803+ return;
92804+
92805+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92806+ address_m = address + SEGMEXEC_TASK_SIZE;
92807+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92808+ get_page(page_m);
92809+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92810+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92811+}
92812+#endif
92813+
92814 /*
92815 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92816 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92817@@ -2772,6 +2797,11 @@ retry_avoidcopy:
92818 make_huge_pte(vma, new_page, 1));
92819 page_remove_rmap(old_page);
92820 hugepage_add_new_anon_rmap(new_page, vma, address);
92821+
92822+#ifdef CONFIG_PAX_SEGMEXEC
92823+ pax_mirror_huge_pte(vma, address, new_page);
92824+#endif
92825+
92826 /* Make the old page be freed below */
92827 new_page = old_page;
92828 }
92829@@ -2931,6 +2961,10 @@ retry:
92830 && (vma->vm_flags & VM_SHARED)));
92831 set_huge_pte_at(mm, address, ptep, new_pte);
92832
92833+#ifdef CONFIG_PAX_SEGMEXEC
92834+ pax_mirror_huge_pte(vma, address, page);
92835+#endif
92836+
92837 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92838 /* Optimization, do the COW without a second fault */
92839 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92840@@ -2997,6 +3031,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92841 struct hstate *h = hstate_vma(vma);
92842 struct address_space *mapping;
92843
92844+#ifdef CONFIG_PAX_SEGMEXEC
92845+ struct vm_area_struct *vma_m;
92846+#endif
92847+
92848 address &= huge_page_mask(h);
92849
92850 ptep = huge_pte_offset(mm, address);
92851@@ -3010,6 +3048,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92852 VM_FAULT_SET_HINDEX(hstate_index(h));
92853 }
92854
92855+#ifdef CONFIG_PAX_SEGMEXEC
92856+ vma_m = pax_find_mirror_vma(vma);
92857+ if (vma_m) {
92858+ unsigned long address_m;
92859+
92860+ if (vma->vm_start > vma_m->vm_start) {
92861+ address_m = address;
92862+ address -= SEGMEXEC_TASK_SIZE;
92863+ vma = vma_m;
92864+ h = hstate_vma(vma);
92865+ } else
92866+ address_m = address + SEGMEXEC_TASK_SIZE;
92867+
92868+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92869+ return VM_FAULT_OOM;
92870+ address_m &= HPAGE_MASK;
92871+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92872+ }
92873+#endif
92874+
92875 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92876 if (!ptep)
92877 return VM_FAULT_OOM;
92878diff --git a/mm/internal.h b/mm/internal.h
92879index 07b6736..ae8da20 100644
92880--- a/mm/internal.h
92881+++ b/mm/internal.h
92882@@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92883 * in mm/page_alloc.c
92884 */
92885 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92886+extern void free_compound_page(struct page *page);
92887 extern void prep_compound_page(struct page *page, unsigned long order);
92888 #ifdef CONFIG_MEMORY_FAILURE
92889 extern bool is_free_buddy_page(struct page *page);
92890@@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
92891
92892 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92893 unsigned long, unsigned long,
92894- unsigned long, unsigned long);
92895+ unsigned long, unsigned long) __intentional_overflow(-1);
92896
92897 extern void set_pageblock_order(void);
92898 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92899diff --git a/mm/iov_iter.c b/mm/iov_iter.c
92900index 10e46cd..e3052f6 100644
92901--- a/mm/iov_iter.c
92902+++ b/mm/iov_iter.c
92903@@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92904
92905 while (bytes) {
92906 char __user *buf = iov->iov_base + base;
92907- int copy = min(bytes, iov->iov_len - base);
92908+ size_t copy = min(bytes, iov->iov_len - base);
92909
92910 base = 0;
92911 left = __copy_from_user_inatomic(vaddr, buf, copy);
92912@@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92913
92914 kaddr = kmap_atomic(page);
92915 if (likely(i->nr_segs == 1)) {
92916- int left;
92917+ size_t left;
92918 char __user *buf = i->iov->iov_base + i->iov_offset;
92919 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92920 copied = bytes - left;
92921@@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92922
92923 kaddr = kmap(page);
92924 if (likely(i->nr_segs == 1)) {
92925- int left;
92926+ size_t left;
92927 char __user *buf = i->iov->iov_base + i->iov_offset;
92928 left = __copy_from_user(kaddr + offset, buf, bytes);
92929 copied = bytes - left;
92930@@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92931 * zero-length segments (without overruning the iovec).
92932 */
92933 while (bytes || unlikely(i->count && !iov->iov_len)) {
92934- int copy;
92935+ size_t copy;
92936
92937 copy = min(bytes, iov->iov_len - base);
92938 BUG_ON(!i->count || i->count < copy);
92939diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92940index 8d2fcdf..6dd9f1a 100644
92941--- a/mm/kmemleak.c
92942+++ b/mm/kmemleak.c
92943@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
92944
92945 for (i = 0; i < object->trace_len; i++) {
92946 void *ptr = (void *)object->trace[i];
92947- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92948+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92949 }
92950 }
92951
92952@@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
92953 return -ENOMEM;
92954 }
92955
92956- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92957+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92958 &kmemleak_fops);
92959 if (!dentry)
92960 pr_warning("Failed to create the debugfs kmemleak file\n");
92961diff --git a/mm/maccess.c b/mm/maccess.c
92962index d53adf9..03a24bf 100644
92963--- a/mm/maccess.c
92964+++ b/mm/maccess.c
92965@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92966 set_fs(KERNEL_DS);
92967 pagefault_disable();
92968 ret = __copy_from_user_inatomic(dst,
92969- (__force const void __user *)src, size);
92970+ (const void __force_user *)src, size);
92971 pagefault_enable();
92972 set_fs(old_fs);
92973
92974@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92975
92976 set_fs(KERNEL_DS);
92977 pagefault_disable();
92978- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92979+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92980 pagefault_enable();
92981 set_fs(old_fs);
92982
92983diff --git a/mm/madvise.c b/mm/madvise.c
92984index a402f8f..f5e5daa 100644
92985--- a/mm/madvise.c
92986+++ b/mm/madvise.c
92987@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92988 pgoff_t pgoff;
92989 unsigned long new_flags = vma->vm_flags;
92990
92991+#ifdef CONFIG_PAX_SEGMEXEC
92992+ struct vm_area_struct *vma_m;
92993+#endif
92994+
92995 switch (behavior) {
92996 case MADV_NORMAL:
92997 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92998@@ -126,6 +130,13 @@ success:
92999 /*
93000 * vm_flags is protected by the mmap_sem held in write mode.
93001 */
93002+
93003+#ifdef CONFIG_PAX_SEGMEXEC
93004+ vma_m = pax_find_mirror_vma(vma);
93005+ if (vma_m)
93006+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
93007+#endif
93008+
93009 vma->vm_flags = new_flags;
93010
93011 out:
93012@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
93013 struct vm_area_struct **prev,
93014 unsigned long start, unsigned long end)
93015 {
93016+
93017+#ifdef CONFIG_PAX_SEGMEXEC
93018+ struct vm_area_struct *vma_m;
93019+#endif
93020+
93021 *prev = vma;
93022 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
93023 return -EINVAL;
93024@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
93025 zap_page_range(vma, start, end - start, &details);
93026 } else
93027 zap_page_range(vma, start, end - start, NULL);
93028+
93029+#ifdef CONFIG_PAX_SEGMEXEC
93030+ vma_m = pax_find_mirror_vma(vma);
93031+ if (vma_m) {
93032+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
93033+ struct zap_details details = {
93034+ .nonlinear_vma = vma_m,
93035+ .last_index = ULONG_MAX,
93036+ };
93037+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
93038+ } else
93039+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
93040+ }
93041+#endif
93042+
93043 return 0;
93044 }
93045
93046@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
93047 if (end < start)
93048 return error;
93049
93050+#ifdef CONFIG_PAX_SEGMEXEC
93051+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
93052+ if (end > SEGMEXEC_TASK_SIZE)
93053+ return error;
93054+ } else
93055+#endif
93056+
93057+ if (end > TASK_SIZE)
93058+ return error;
93059+
93060 error = 0;
93061 if (end == start)
93062 return error;
93063diff --git a/mm/memory-failure.c b/mm/memory-failure.c
93064index eb8fb72..ae36cf3 100644
93065--- a/mm/memory-failure.c
93066+++ b/mm/memory-failure.c
93067@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
93068
93069 int sysctl_memory_failure_recovery __read_mostly = 1;
93070
93071-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
93072+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
93073
93074 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
93075
93076@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
93077 pfn, t->comm, t->pid);
93078 si.si_signo = SIGBUS;
93079 si.si_errno = 0;
93080- si.si_addr = (void *)addr;
93081+ si.si_addr = (void __user *)addr;
93082 #ifdef __ARCH_SI_TRAPNO
93083 si.si_trapno = trapno;
93084 #endif
93085@@ -791,7 +791,7 @@ static struct page_state {
93086 unsigned long res;
93087 char *msg;
93088 int (*action)(struct page *p, unsigned long pfn);
93089-} error_states[] = {
93090+} __do_const error_states[] = {
93091 { reserved, reserved, "reserved kernel", me_kernel },
93092 /*
93093 * free pages are specially detected outside this table:
93094@@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93095 nr_pages = 1 << compound_order(hpage);
93096 else /* normal page or thp */
93097 nr_pages = 1;
93098- atomic_long_add(nr_pages, &num_poisoned_pages);
93099+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
93100
93101 /*
93102 * We need/can do nothing about count=0 pages.
93103@@ -1120,7 +1120,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93104 if (PageHWPoison(hpage)) {
93105 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
93106 || (p != hpage && TestSetPageHWPoison(hpage))) {
93107- atomic_long_sub(nr_pages, &num_poisoned_pages);
93108+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93109 unlock_page(hpage);
93110 return 0;
93111 }
93112@@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93113 */
93114 if (!PageHWPoison(p)) {
93115 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
93116- atomic_long_sub(nr_pages, &num_poisoned_pages);
93117+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93118 put_page(hpage);
93119 res = 0;
93120 goto out;
93121 }
93122 if (hwpoison_filter(p)) {
93123 if (TestClearPageHWPoison(p))
93124- atomic_long_sub(nr_pages, &num_poisoned_pages);
93125+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93126 unlock_page(hpage);
93127 put_page(hpage);
93128 return 0;
93129@@ -1415,7 +1415,7 @@ int unpoison_memory(unsigned long pfn)
93130 return 0;
93131 }
93132 if (TestClearPageHWPoison(p))
93133- atomic_long_dec(&num_poisoned_pages);
93134+ atomic_long_dec_unchecked(&num_poisoned_pages);
93135 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
93136 return 0;
93137 }
93138@@ -1429,7 +1429,7 @@ int unpoison_memory(unsigned long pfn)
93139 */
93140 if (TestClearPageHWPoison(page)) {
93141 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
93142- atomic_long_sub(nr_pages, &num_poisoned_pages);
93143+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93144 freeit = 1;
93145 if (PageHuge(page))
93146 clear_page_hwpoison_huge_page(page);
93147@@ -1554,11 +1554,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
93148 if (PageHuge(page)) {
93149 set_page_hwpoison_huge_page(hpage);
93150 dequeue_hwpoisoned_huge_page(hpage);
93151- atomic_long_add(1 << compound_order(hpage),
93152+ atomic_long_add_unchecked(1 << compound_order(hpage),
93153 &num_poisoned_pages);
93154 } else {
93155 SetPageHWPoison(page);
93156- atomic_long_inc(&num_poisoned_pages);
93157+ atomic_long_inc_unchecked(&num_poisoned_pages);
93158 }
93159 }
93160 return ret;
93161@@ -1597,7 +1597,7 @@ static int __soft_offline_page(struct page *page, int flags)
93162 put_page(page);
93163 pr_info("soft_offline: %#lx: invalidated\n", pfn);
93164 SetPageHWPoison(page);
93165- atomic_long_inc(&num_poisoned_pages);
93166+ atomic_long_inc_unchecked(&num_poisoned_pages);
93167 return 0;
93168 }
93169
93170@@ -1648,7 +1648,7 @@ static int __soft_offline_page(struct page *page, int flags)
93171 if (!is_free_buddy_page(page))
93172 pr_info("soft offline: %#lx: page leaked\n",
93173 pfn);
93174- atomic_long_inc(&num_poisoned_pages);
93175+ atomic_long_inc_unchecked(&num_poisoned_pages);
93176 }
93177 } else {
93178 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
93179@@ -1722,11 +1722,11 @@ int soft_offline_page(struct page *page, int flags)
93180 if (PageHuge(page)) {
93181 set_page_hwpoison_huge_page(hpage);
93182 dequeue_hwpoisoned_huge_page(hpage);
93183- atomic_long_add(1 << compound_order(hpage),
93184+ atomic_long_add_unchecked(1 << compound_order(hpage),
93185 &num_poisoned_pages);
93186 } else {
93187 SetPageHWPoison(page);
93188- atomic_long_inc(&num_poisoned_pages);
93189+ atomic_long_inc_unchecked(&num_poisoned_pages);
93190 }
93191 }
93192 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
93193diff --git a/mm/memory.c b/mm/memory.c
93194index 4f9e530..779c7ce 100644
93195--- a/mm/memory.c
93196+++ b/mm/memory.c
93197@@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93198 free_pte_range(tlb, pmd, addr);
93199 } while (pmd++, addr = next, addr != end);
93200
93201+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
93202 start &= PUD_MASK;
93203 if (start < floor)
93204 return;
93205@@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93206 pmd = pmd_offset(pud, start);
93207 pud_clear(pud);
93208 pmd_free_tlb(tlb, pmd, start);
93209+#endif
93210+
93211 }
93212
93213 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93214@@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93215 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
93216 } while (pud++, addr = next, addr != end);
93217
93218+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
93219 start &= PGDIR_MASK;
93220 if (start < floor)
93221 return;
93222@@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93223 pud = pud_offset(pgd, start);
93224 pgd_clear(pgd);
93225 pud_free_tlb(tlb, pud, start);
93226+#endif
93227+
93228 }
93229
93230 /*
93231@@ -1652,12 +1658,6 @@ no_page_table:
93232 return page;
93233 }
93234
93235-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
93236-{
93237- return stack_guard_page_start(vma, addr) ||
93238- stack_guard_page_end(vma, addr+PAGE_SIZE);
93239-}
93240-
93241 /**
93242 * __get_user_pages() - pin user pages in memory
93243 * @tsk: task_struct of target task
93244@@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93245
93246 i = 0;
93247
93248- do {
93249+ while (nr_pages) {
93250 struct vm_area_struct *vma;
93251
93252- vma = find_extend_vma(mm, start);
93253+ vma = find_vma(mm, start);
93254 if (!vma && in_gate_area(mm, start)) {
93255 unsigned long pg = start & PAGE_MASK;
93256 pgd_t *pgd;
93257@@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93258 goto next_page;
93259 }
93260
93261- if (!vma)
93262+ if (!vma || start < vma->vm_start)
93263 goto efault;
93264 vm_flags = vma->vm_flags;
93265 if (vm_flags & (VM_IO | VM_PFNMAP))
93266@@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93267 int ret;
93268 unsigned int fault_flags = 0;
93269
93270- /* For mlock, just skip the stack guard page. */
93271- if (foll_flags & FOLL_MLOCK) {
93272- if (stack_guard_page(vma, start))
93273- goto next_page;
93274- }
93275 if (foll_flags & FOLL_WRITE)
93276 fault_flags |= FAULT_FLAG_WRITE;
93277 if (nonblocking)
93278@@ -1932,7 +1927,7 @@ next_page:
93279 start += page_increm * PAGE_SIZE;
93280 nr_pages -= page_increm;
93281 } while (nr_pages && start < vma->vm_end);
93282- } while (nr_pages);
93283+ }
93284 return i;
93285 efault:
93286 return i ? : -EFAULT;
93287@@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
93288 page_add_file_rmap(page);
93289 set_pte_at(mm, addr, pte, mk_pte(page, prot));
93290
93291+#ifdef CONFIG_PAX_SEGMEXEC
93292+ pax_mirror_file_pte(vma, addr, page, ptl);
93293+#endif
93294+
93295 retval = 0;
93296 pte_unmap_unlock(pte, ptl);
93297 return retval;
93298@@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
93299 if (!page_count(page))
93300 return -EINVAL;
93301 if (!(vma->vm_flags & VM_MIXEDMAP)) {
93302+
93303+#ifdef CONFIG_PAX_SEGMEXEC
93304+ struct vm_area_struct *vma_m;
93305+#endif
93306+
93307 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
93308 BUG_ON(vma->vm_flags & VM_PFNMAP);
93309 vma->vm_flags |= VM_MIXEDMAP;
93310+
93311+#ifdef CONFIG_PAX_SEGMEXEC
93312+ vma_m = pax_find_mirror_vma(vma);
93313+ if (vma_m)
93314+ vma_m->vm_flags |= VM_MIXEDMAP;
93315+#endif
93316+
93317 }
93318 return insert_page(vma, addr, page, vma->vm_page_prot);
93319 }
93320@@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
93321 unsigned long pfn)
93322 {
93323 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
93324+ BUG_ON(vma->vm_mirror);
93325
93326 if (addr < vma->vm_start || addr >= vma->vm_end)
93327 return -EFAULT;
93328@@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
93329
93330 BUG_ON(pud_huge(*pud));
93331
93332- pmd = pmd_alloc(mm, pud, addr);
93333+ pmd = (mm == &init_mm) ?
93334+ pmd_alloc_kernel(mm, pud, addr) :
93335+ pmd_alloc(mm, pud, addr);
93336 if (!pmd)
93337 return -ENOMEM;
93338 do {
93339@@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
93340 unsigned long next;
93341 int err;
93342
93343- pud = pud_alloc(mm, pgd, addr);
93344+ pud = (mm == &init_mm) ?
93345+ pud_alloc_kernel(mm, pgd, addr) :
93346+ pud_alloc(mm, pgd, addr);
93347 if (!pud)
93348 return -ENOMEM;
93349 do {
93350@@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
93351 return ret;
93352 }
93353
93354+#ifdef CONFIG_PAX_SEGMEXEC
93355+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
93356+{
93357+ struct mm_struct *mm = vma->vm_mm;
93358+ spinlock_t *ptl;
93359+ pte_t *pte, entry;
93360+
93361+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93362+ entry = *pte;
93363+ if (!pte_present(entry)) {
93364+ if (!pte_none(entry)) {
93365+ BUG_ON(pte_file(entry));
93366+ free_swap_and_cache(pte_to_swp_entry(entry));
93367+ pte_clear_not_present_full(mm, address, pte, 0);
93368+ }
93369+ } else {
93370+ struct page *page;
93371+
93372+ flush_cache_page(vma, address, pte_pfn(entry));
93373+ entry = ptep_clear_flush(vma, address, pte);
93374+ BUG_ON(pte_dirty(entry));
93375+ page = vm_normal_page(vma, address, entry);
93376+ if (page) {
93377+ update_hiwater_rss(mm);
93378+ if (PageAnon(page))
93379+ dec_mm_counter_fast(mm, MM_ANONPAGES);
93380+ else
93381+ dec_mm_counter_fast(mm, MM_FILEPAGES);
93382+ page_remove_rmap(page);
93383+ page_cache_release(page);
93384+ }
93385+ }
93386+ pte_unmap_unlock(pte, ptl);
93387+}
93388+
93389+/* PaX: if vma is mirrored, synchronize the mirror's PTE
93390+ *
93391+ * the ptl of the lower mapped page is held on entry and is not released on exit
93392+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
93393+ */
93394+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93395+{
93396+ struct mm_struct *mm = vma->vm_mm;
93397+ unsigned long address_m;
93398+ spinlock_t *ptl_m;
93399+ struct vm_area_struct *vma_m;
93400+ pmd_t *pmd_m;
93401+ pte_t *pte_m, entry_m;
93402+
93403+ BUG_ON(!page_m || !PageAnon(page_m));
93404+
93405+ vma_m = pax_find_mirror_vma(vma);
93406+ if (!vma_m)
93407+ return;
93408+
93409+ BUG_ON(!PageLocked(page_m));
93410+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93411+ address_m = address + SEGMEXEC_TASK_SIZE;
93412+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93413+ pte_m = pte_offset_map(pmd_m, address_m);
93414+ ptl_m = pte_lockptr(mm, pmd_m);
93415+ if (ptl != ptl_m) {
93416+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93417+ if (!pte_none(*pte_m))
93418+ goto out;
93419+ }
93420+
93421+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93422+ page_cache_get(page_m);
93423+ page_add_anon_rmap(page_m, vma_m, address_m);
93424+ inc_mm_counter_fast(mm, MM_ANONPAGES);
93425+ set_pte_at(mm, address_m, pte_m, entry_m);
93426+ update_mmu_cache(vma_m, address_m, pte_m);
93427+out:
93428+ if (ptl != ptl_m)
93429+ spin_unlock(ptl_m);
93430+ pte_unmap(pte_m);
93431+ unlock_page(page_m);
93432+}
93433+
93434+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93435+{
93436+ struct mm_struct *mm = vma->vm_mm;
93437+ unsigned long address_m;
93438+ spinlock_t *ptl_m;
93439+ struct vm_area_struct *vma_m;
93440+ pmd_t *pmd_m;
93441+ pte_t *pte_m, entry_m;
93442+
93443+ BUG_ON(!page_m || PageAnon(page_m));
93444+
93445+ vma_m = pax_find_mirror_vma(vma);
93446+ if (!vma_m)
93447+ return;
93448+
93449+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93450+ address_m = address + SEGMEXEC_TASK_SIZE;
93451+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93452+ pte_m = pte_offset_map(pmd_m, address_m);
93453+ ptl_m = pte_lockptr(mm, pmd_m);
93454+ if (ptl != ptl_m) {
93455+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93456+ if (!pte_none(*pte_m))
93457+ goto out;
93458+ }
93459+
93460+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93461+ page_cache_get(page_m);
93462+ page_add_file_rmap(page_m);
93463+ inc_mm_counter_fast(mm, MM_FILEPAGES);
93464+ set_pte_at(mm, address_m, pte_m, entry_m);
93465+ update_mmu_cache(vma_m, address_m, pte_m);
93466+out:
93467+ if (ptl != ptl_m)
93468+ spin_unlock(ptl_m);
93469+ pte_unmap(pte_m);
93470+}
93471+
93472+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93473+{
93474+ struct mm_struct *mm = vma->vm_mm;
93475+ unsigned long address_m;
93476+ spinlock_t *ptl_m;
93477+ struct vm_area_struct *vma_m;
93478+ pmd_t *pmd_m;
93479+ pte_t *pte_m, entry_m;
93480+
93481+ vma_m = pax_find_mirror_vma(vma);
93482+ if (!vma_m)
93483+ return;
93484+
93485+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93486+ address_m = address + SEGMEXEC_TASK_SIZE;
93487+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93488+ pte_m = pte_offset_map(pmd_m, address_m);
93489+ ptl_m = pte_lockptr(mm, pmd_m);
93490+ if (ptl != ptl_m) {
93491+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93492+ if (!pte_none(*pte_m))
93493+ goto out;
93494+ }
93495+
93496+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93497+ set_pte_at(mm, address_m, pte_m, entry_m);
93498+out:
93499+ if (ptl != ptl_m)
93500+ spin_unlock(ptl_m);
93501+ pte_unmap(pte_m);
93502+}
93503+
93504+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93505+{
93506+ struct page *page_m;
93507+ pte_t entry;
93508+
93509+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93510+ goto out;
93511+
93512+ entry = *pte;
93513+ page_m = vm_normal_page(vma, address, entry);
93514+ if (!page_m)
93515+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93516+ else if (PageAnon(page_m)) {
93517+ if (pax_find_mirror_vma(vma)) {
93518+ pte_unmap_unlock(pte, ptl);
93519+ lock_page(page_m);
93520+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93521+ if (pte_same(entry, *pte))
93522+ pax_mirror_anon_pte(vma, address, page_m, ptl);
93523+ else
93524+ unlock_page(page_m);
93525+ }
93526+ } else
93527+ pax_mirror_file_pte(vma, address, page_m, ptl);
93528+
93529+out:
93530+ pte_unmap_unlock(pte, ptl);
93531+}
93532+#endif
93533+
93534 /*
93535 * This routine handles present pages, when users try to write
93536 * to a shared page. It is done by copying the page to a new address
93537@@ -2860,6 +3056,12 @@ gotten:
93538 */
93539 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93540 if (likely(pte_same(*page_table, orig_pte))) {
93541+
93542+#ifdef CONFIG_PAX_SEGMEXEC
93543+ if (pax_find_mirror_vma(vma))
93544+ BUG_ON(!trylock_page(new_page));
93545+#endif
93546+
93547 if (old_page) {
93548 if (!PageAnon(old_page)) {
93549 dec_mm_counter_fast(mm, MM_FILEPAGES);
93550@@ -2911,6 +3113,10 @@ gotten:
93551 page_remove_rmap(old_page);
93552 }
93553
93554+#ifdef CONFIG_PAX_SEGMEXEC
93555+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93556+#endif
93557+
93558 /* Free the old page.. */
93559 new_page = old_page;
93560 ret |= VM_FAULT_WRITE;
93561@@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93562 swap_free(entry);
93563 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93564 try_to_free_swap(page);
93565+
93566+#ifdef CONFIG_PAX_SEGMEXEC
93567+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93568+#endif
93569+
93570 unlock_page(page);
93571 if (page != swapcache) {
93572 /*
93573@@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93574
93575 /* No need to invalidate - it was non-present before */
93576 update_mmu_cache(vma, address, page_table);
93577+
93578+#ifdef CONFIG_PAX_SEGMEXEC
93579+ pax_mirror_anon_pte(vma, address, page, ptl);
93580+#endif
93581+
93582 unlock:
93583 pte_unmap_unlock(page_table, ptl);
93584 out:
93585@@ -3226,40 +3442,6 @@ out_release:
93586 }
93587
93588 /*
93589- * This is like a special single-page "expand_{down|up}wards()",
93590- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93591- * doesn't hit another vma.
93592- */
93593-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93594-{
93595- address &= PAGE_MASK;
93596- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93597- struct vm_area_struct *prev = vma->vm_prev;
93598-
93599- /*
93600- * Is there a mapping abutting this one below?
93601- *
93602- * That's only ok if it's the same stack mapping
93603- * that has gotten split..
93604- */
93605- if (prev && prev->vm_end == address)
93606- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93607-
93608- expand_downwards(vma, address - PAGE_SIZE);
93609- }
93610- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93611- struct vm_area_struct *next = vma->vm_next;
93612-
93613- /* As VM_GROWSDOWN but s/below/above/ */
93614- if (next && next->vm_start == address + PAGE_SIZE)
93615- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93616-
93617- expand_upwards(vma, address + PAGE_SIZE);
93618- }
93619- return 0;
93620-}
93621-
93622-/*
93623 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93624 * but allow concurrent faults), and pte mapped but not yet locked.
93625 * We return with mmap_sem still held, but pte unmapped and unlocked.
93626@@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93627 unsigned long address, pte_t *page_table, pmd_t *pmd,
93628 unsigned int flags)
93629 {
93630- struct page *page;
93631+ struct page *page = NULL;
93632 spinlock_t *ptl;
93633 pte_t entry;
93634
93635- pte_unmap(page_table);
93636-
93637- /* Check if we need to add a guard page to the stack */
93638- if (check_stack_guard_page(vma, address) < 0)
93639- return VM_FAULT_SIGBUS;
93640-
93641- /* Use the zero-page for reads */
93642 if (!(flags & FAULT_FLAG_WRITE)) {
93643 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93644 vma->vm_page_prot));
93645- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93646+ ptl = pte_lockptr(mm, pmd);
93647+ spin_lock(ptl);
93648 if (!pte_none(*page_table))
93649 goto unlock;
93650 goto setpte;
93651 }
93652
93653 /* Allocate our own private page. */
93654+ pte_unmap(page_table);
93655+
93656 if (unlikely(anon_vma_prepare(vma)))
93657 goto oom;
93658 page = alloc_zeroed_user_highpage_movable(vma, address);
93659@@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93660 if (!pte_none(*page_table))
93661 goto release;
93662
93663+#ifdef CONFIG_PAX_SEGMEXEC
93664+ if (pax_find_mirror_vma(vma))
93665+ BUG_ON(!trylock_page(page));
93666+#endif
93667+
93668 inc_mm_counter_fast(mm, MM_ANONPAGES);
93669 page_add_new_anon_rmap(page, vma, address);
93670 setpte:
93671@@ -3319,6 +3502,12 @@ setpte:
93672
93673 /* No need to invalidate - it was non-present before */
93674 update_mmu_cache(vma, address, page_table);
93675+
93676+#ifdef CONFIG_PAX_SEGMEXEC
93677+ if (page)
93678+ pax_mirror_anon_pte(vma, address, page, ptl);
93679+#endif
93680+
93681 unlock:
93682 pte_unmap_unlock(page_table, ptl);
93683 return 0;
93684@@ -3515,7 +3704,8 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93685 * if page by the offset is not ready to be mapped (cold cache or
93686 * something).
93687 */
93688- if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR)) {
93689+ if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR) &&
93690+ fault_around_pages() > 1) {
93691 pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93692 do_fault_around(vma, address, pte, pgoff, flags);
93693 if (!pte_same(*pte, orig_pte))
93694@@ -3535,6 +3725,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93695 return ret;
93696 }
93697 do_set_pte(vma, address, fault_page, pte, false, false);
93698+
93699+#ifdef CONFIG_PAX_SEGMEXEC
93700+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93701+#endif
93702+
93703 unlock_page(fault_page);
93704 unlock_out:
93705 pte_unmap_unlock(pte, ptl);
93706@@ -3576,7 +3771,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93707 page_cache_release(fault_page);
93708 goto uncharge_out;
93709 }
93710+
93711+#ifdef CONFIG_PAX_SEGMEXEC
93712+ if (pax_find_mirror_vma(vma))
93713+ BUG_ON(!trylock_page(new_page));
93714+#endif
93715+
93716 do_set_pte(vma, address, new_page, pte, true, true);
93717+
93718+#ifdef CONFIG_PAX_SEGMEXEC
93719+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93720+#endif
93721+
93722 pte_unmap_unlock(pte, ptl);
93723 unlock_page(fault_page);
93724 page_cache_release(fault_page);
93725@@ -3624,6 +3830,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93726 return ret;
93727 }
93728 do_set_pte(vma, address, fault_page, pte, true, false);
93729+
93730+#ifdef CONFIG_PAX_SEGMEXEC
93731+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93732+#endif
93733+
93734 pte_unmap_unlock(pte, ptl);
93735
93736 if (set_page_dirty(fault_page))
93737@@ -3854,6 +4065,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93738 if (flags & FAULT_FLAG_WRITE)
93739 flush_tlb_fix_spurious_fault(vma, address);
93740 }
93741+
93742+#ifdef CONFIG_PAX_SEGMEXEC
93743+ pax_mirror_pte(vma, address, pte, pmd, ptl);
93744+ return 0;
93745+#endif
93746+
93747 unlock:
93748 pte_unmap_unlock(pte, ptl);
93749 return 0;
93750@@ -3870,9 +4087,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93751 pmd_t *pmd;
93752 pte_t *pte;
93753
93754+#ifdef CONFIG_PAX_SEGMEXEC
93755+ struct vm_area_struct *vma_m;
93756+#endif
93757+
93758 if (unlikely(is_vm_hugetlb_page(vma)))
93759 return hugetlb_fault(mm, vma, address, flags);
93760
93761+#ifdef CONFIG_PAX_SEGMEXEC
93762+ vma_m = pax_find_mirror_vma(vma);
93763+ if (vma_m) {
93764+ unsigned long address_m;
93765+ pgd_t *pgd_m;
93766+ pud_t *pud_m;
93767+ pmd_t *pmd_m;
93768+
93769+ if (vma->vm_start > vma_m->vm_start) {
93770+ address_m = address;
93771+ address -= SEGMEXEC_TASK_SIZE;
93772+ vma = vma_m;
93773+ } else
93774+ address_m = address + SEGMEXEC_TASK_SIZE;
93775+
93776+ pgd_m = pgd_offset(mm, address_m);
93777+ pud_m = pud_alloc(mm, pgd_m, address_m);
93778+ if (!pud_m)
93779+ return VM_FAULT_OOM;
93780+ pmd_m = pmd_alloc(mm, pud_m, address_m);
93781+ if (!pmd_m)
93782+ return VM_FAULT_OOM;
93783+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93784+ return VM_FAULT_OOM;
93785+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93786+ }
93787+#endif
93788+
93789 pgd = pgd_offset(mm, address);
93790 pud = pud_alloc(mm, pgd, address);
93791 if (!pud)
93792@@ -4000,6 +4249,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93793 spin_unlock(&mm->page_table_lock);
93794 return 0;
93795 }
93796+
93797+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93798+{
93799+ pud_t *new = pud_alloc_one(mm, address);
93800+ if (!new)
93801+ return -ENOMEM;
93802+
93803+ smp_wmb(); /* See comment in __pte_alloc */
93804+
93805+ spin_lock(&mm->page_table_lock);
93806+ if (pgd_present(*pgd)) /* Another has populated it */
93807+ pud_free(mm, new);
93808+ else
93809+ pgd_populate_kernel(mm, pgd, new);
93810+ spin_unlock(&mm->page_table_lock);
93811+ return 0;
93812+}
93813 #endif /* __PAGETABLE_PUD_FOLDED */
93814
93815 #ifndef __PAGETABLE_PMD_FOLDED
93816@@ -4030,6 +4296,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93817 spin_unlock(&mm->page_table_lock);
93818 return 0;
93819 }
93820+
93821+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93822+{
93823+ pmd_t *new = pmd_alloc_one(mm, address);
93824+ if (!new)
93825+ return -ENOMEM;
93826+
93827+ smp_wmb(); /* See comment in __pte_alloc */
93828+
93829+ spin_lock(&mm->page_table_lock);
93830+#ifndef __ARCH_HAS_4LEVEL_HACK
93831+ if (pud_present(*pud)) /* Another has populated it */
93832+ pmd_free(mm, new);
93833+ else
93834+ pud_populate_kernel(mm, pud, new);
93835+#else
93836+ if (pgd_present(*pud)) /* Another has populated it */
93837+ pmd_free(mm, new);
93838+ else
93839+ pgd_populate_kernel(mm, pud, new);
93840+#endif /* __ARCH_HAS_4LEVEL_HACK */
93841+ spin_unlock(&mm->page_table_lock);
93842+ return 0;
93843+}
93844 #endif /* __PAGETABLE_PMD_FOLDED */
93845
93846 #if !defined(__HAVE_ARCH_GATE_AREA)
93847@@ -4043,7 +4333,7 @@ static int __init gate_vma_init(void)
93848 gate_vma.vm_start = FIXADDR_USER_START;
93849 gate_vma.vm_end = FIXADDR_USER_END;
93850 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93851- gate_vma.vm_page_prot = __P101;
93852+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93853
93854 return 0;
93855 }
93856@@ -4177,8 +4467,8 @@ out:
93857 return ret;
93858 }
93859
93860-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93861- void *buf, int len, int write)
93862+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93863+ void *buf, size_t len, int write)
93864 {
93865 resource_size_t phys_addr;
93866 unsigned long prot = 0;
93867@@ -4204,8 +4494,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93868 * Access another process' address space as given in mm. If non-NULL, use the
93869 * given task for page fault accounting.
93870 */
93871-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93872- unsigned long addr, void *buf, int len, int write)
93873+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93874+ unsigned long addr, void *buf, size_t len, int write)
93875 {
93876 struct vm_area_struct *vma;
93877 void *old_buf = buf;
93878@@ -4213,7 +4503,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93879 down_read(&mm->mmap_sem);
93880 /* ignore errors, just check how much was successfully transferred */
93881 while (len) {
93882- int bytes, ret, offset;
93883+ ssize_t bytes, ret, offset;
93884 void *maddr;
93885 struct page *page = NULL;
93886
93887@@ -4272,8 +4562,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93888 *
93889 * The caller must hold a reference on @mm.
93890 */
93891-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93892- void *buf, int len, int write)
93893+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93894+ void *buf, size_t len, int write)
93895 {
93896 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93897 }
93898@@ -4283,11 +4573,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93899 * Source/target buffer must be kernel space,
93900 * Do not walk the page table directly, use get_user_pages
93901 */
93902-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93903- void *buf, int len, int write)
93904+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93905+ void *buf, size_t len, int write)
93906 {
93907 struct mm_struct *mm;
93908- int ret;
93909+ ssize_t ret;
93910
93911 mm = get_task_mm(tsk);
93912 if (!mm)
93913diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93914index 6b65d10..e6f415a 100644
93915--- a/mm/mempolicy.c
93916+++ b/mm/mempolicy.c
93917@@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93918 unsigned long vmstart;
93919 unsigned long vmend;
93920
93921+#ifdef CONFIG_PAX_SEGMEXEC
93922+ struct vm_area_struct *vma_m;
93923+#endif
93924+
93925 vma = find_vma(mm, start);
93926 if (!vma || vma->vm_start > start)
93927 return -EFAULT;
93928@@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93929 err = vma_replace_policy(vma, new_pol);
93930 if (err)
93931 goto out;
93932+
93933+#ifdef CONFIG_PAX_SEGMEXEC
93934+ vma_m = pax_find_mirror_vma(vma);
93935+ if (vma_m) {
93936+ err = vma_replace_policy(vma_m, new_pol);
93937+ if (err)
93938+ goto out;
93939+ }
93940+#endif
93941+
93942 }
93943
93944 out:
93945@@ -1222,6 +1236,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93946
93947 if (end < start)
93948 return -EINVAL;
93949+
93950+#ifdef CONFIG_PAX_SEGMEXEC
93951+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93952+ if (end > SEGMEXEC_TASK_SIZE)
93953+ return -EINVAL;
93954+ } else
93955+#endif
93956+
93957+ if (end > TASK_SIZE)
93958+ return -EINVAL;
93959+
93960 if (end == start)
93961 return 0;
93962
93963@@ -1447,8 +1472,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93964 */
93965 tcred = __task_cred(task);
93966 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93967- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93968- !capable(CAP_SYS_NICE)) {
93969+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93970 rcu_read_unlock();
93971 err = -EPERM;
93972 goto out_put;
93973@@ -1479,6 +1503,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93974 goto out;
93975 }
93976
93977+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93978+ if (mm != current->mm &&
93979+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93980+ mmput(mm);
93981+ err = -EPERM;
93982+ goto out;
93983+ }
93984+#endif
93985+
93986 err = do_migrate_pages(mm, old, new,
93987 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93988
93989diff --git a/mm/migrate.c b/mm/migrate.c
93990index bed4880..a493f67 100644
93991--- a/mm/migrate.c
93992+++ b/mm/migrate.c
93993@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93994 */
93995 tcred = __task_cred(task);
93996 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93997- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93998- !capable(CAP_SYS_NICE)) {
93999+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
94000 rcu_read_unlock();
94001 err = -EPERM;
94002 goto out;
94003diff --git a/mm/mlock.c b/mm/mlock.c
94004index b1eb536..091d154 100644
94005--- a/mm/mlock.c
94006+++ b/mm/mlock.c
94007@@ -14,6 +14,7 @@
94008 #include <linux/pagevec.h>
94009 #include <linux/mempolicy.h>
94010 #include <linux/syscalls.h>
94011+#include <linux/security.h>
94012 #include <linux/sched.h>
94013 #include <linux/export.h>
94014 #include <linux/rmap.h>
94015@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
94016 {
94017 unsigned long nstart, end, tmp;
94018 struct vm_area_struct * vma, * prev;
94019- int error;
94020+ int error = 0;
94021
94022 VM_BUG_ON(start & ~PAGE_MASK);
94023 VM_BUG_ON(len != PAGE_ALIGN(len));
94024@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
94025 return -EINVAL;
94026 if (end == start)
94027 return 0;
94028+ if (end > TASK_SIZE)
94029+ return -EINVAL;
94030+
94031 vma = find_vma(current->mm, start);
94032 if (!vma || vma->vm_start > start)
94033 return -ENOMEM;
94034@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
94035 for (nstart = start ; ; ) {
94036 vm_flags_t newflags;
94037
94038+#ifdef CONFIG_PAX_SEGMEXEC
94039+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
94040+ break;
94041+#endif
94042+
94043 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
94044
94045 newflags = vma->vm_flags & ~VM_LOCKED;
94046@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
94047 locked += current->mm->locked_vm;
94048
94049 /* check against resource limits */
94050+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
94051 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
94052 error = do_mlock(start, len, 1);
94053
94054@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
94055 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
94056 vm_flags_t newflags;
94057
94058+#ifdef CONFIG_PAX_SEGMEXEC
94059+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
94060+ break;
94061+#endif
94062+
94063 newflags = vma->vm_flags & ~VM_LOCKED;
94064 if (flags & MCL_CURRENT)
94065 newflags |= VM_LOCKED;
94066@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
94067 lock_limit >>= PAGE_SHIFT;
94068
94069 ret = -ENOMEM;
94070+
94071+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
94072+
94073 down_write(&current->mm->mmap_sem);
94074-
94075 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
94076 capable(CAP_IPC_LOCK))
94077 ret = do_mlockall(flags);
94078diff --git a/mm/mmap.c b/mm/mmap.c
94079index b1202cf..ee487f8 100644
94080--- a/mm/mmap.c
94081+++ b/mm/mmap.c
94082@@ -37,6 +37,7 @@
94083 #include <linux/sched/sysctl.h>
94084 #include <linux/notifier.h>
94085 #include <linux/memory.h>
94086+#include <linux/random.h>
94087
94088 #include <asm/uaccess.h>
94089 #include <asm/cacheflush.h>
94090@@ -53,6 +54,16 @@
94091 #define arch_rebalance_pgtables(addr, len) (addr)
94092 #endif
94093
94094+static inline void verify_mm_writelocked(struct mm_struct *mm)
94095+{
94096+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
94097+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94098+ up_read(&mm->mmap_sem);
94099+ BUG();
94100+ }
94101+#endif
94102+}
94103+
94104 static void unmap_region(struct mm_struct *mm,
94105 struct vm_area_struct *vma, struct vm_area_struct *prev,
94106 unsigned long start, unsigned long end);
94107@@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
94108 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
94109 *
94110 */
94111-pgprot_t protection_map[16] = {
94112+pgprot_t protection_map[16] __read_only = {
94113 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
94114 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
94115 };
94116
94117-pgprot_t vm_get_page_prot(unsigned long vm_flags)
94118+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
94119 {
94120- return __pgprot(pgprot_val(protection_map[vm_flags &
94121+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
94122 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
94123 pgprot_val(arch_vm_get_page_prot(vm_flags)));
94124+
94125+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94126+ if (!(__supported_pte_mask & _PAGE_NX) &&
94127+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
94128+ (vm_flags & (VM_READ | VM_WRITE)))
94129+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
94130+#endif
94131+
94132+ return prot;
94133 }
94134 EXPORT_SYMBOL(vm_get_page_prot);
94135
94136@@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
94137 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
94138 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94139 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94140+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
94141 /*
94142 * Make sure vm_committed_as in one cacheline and not cacheline shared with
94143 * other variables. It can be updated by several CPUs frequently.
94144@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
94145 struct vm_area_struct *next = vma->vm_next;
94146
94147 might_sleep();
94148+ BUG_ON(vma->vm_mirror);
94149 if (vma->vm_ops && vma->vm_ops->close)
94150 vma->vm_ops->close(vma);
94151 if (vma->vm_file)
94152@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
94153 * not page aligned -Ram Gupta
94154 */
94155 rlim = rlimit(RLIMIT_DATA);
94156+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
94157 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
94158 (mm->end_data - mm->start_data) > rlim)
94159 goto out;
94160@@ -942,6 +965,12 @@ static int
94161 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
94162 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94163 {
94164+
94165+#ifdef CONFIG_PAX_SEGMEXEC
94166+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
94167+ return 0;
94168+#endif
94169+
94170 if (is_mergeable_vma(vma, file, vm_flags) &&
94171 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94172 if (vma->vm_pgoff == vm_pgoff)
94173@@ -961,6 +990,12 @@ static int
94174 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94175 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94176 {
94177+
94178+#ifdef CONFIG_PAX_SEGMEXEC
94179+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
94180+ return 0;
94181+#endif
94182+
94183 if (is_mergeable_vma(vma, file, vm_flags) &&
94184 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94185 pgoff_t vm_pglen;
94186@@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94187 struct vm_area_struct *vma_merge(struct mm_struct *mm,
94188 struct vm_area_struct *prev, unsigned long addr,
94189 unsigned long end, unsigned long vm_flags,
94190- struct anon_vma *anon_vma, struct file *file,
94191+ struct anon_vma *anon_vma, struct file *file,
94192 pgoff_t pgoff, struct mempolicy *policy)
94193 {
94194 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
94195 struct vm_area_struct *area, *next;
94196 int err;
94197
94198+#ifdef CONFIG_PAX_SEGMEXEC
94199+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
94200+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
94201+
94202+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
94203+#endif
94204+
94205 /*
94206 * We later require that vma->vm_flags == vm_flags,
94207 * so this tests vma->vm_flags & VM_SPECIAL, too.
94208@@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94209 if (next && next->vm_end == end) /* cases 6, 7, 8 */
94210 next = next->vm_next;
94211
94212+#ifdef CONFIG_PAX_SEGMEXEC
94213+ if (prev)
94214+ prev_m = pax_find_mirror_vma(prev);
94215+ if (area)
94216+ area_m = pax_find_mirror_vma(area);
94217+ if (next)
94218+ next_m = pax_find_mirror_vma(next);
94219+#endif
94220+
94221 /*
94222 * Can it merge with the predecessor?
94223 */
94224@@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94225 /* cases 1, 6 */
94226 err = vma_adjust(prev, prev->vm_start,
94227 next->vm_end, prev->vm_pgoff, NULL);
94228- } else /* cases 2, 5, 7 */
94229+
94230+#ifdef CONFIG_PAX_SEGMEXEC
94231+ if (!err && prev_m)
94232+ err = vma_adjust(prev_m, prev_m->vm_start,
94233+ next_m->vm_end, prev_m->vm_pgoff, NULL);
94234+#endif
94235+
94236+ } else { /* cases 2, 5, 7 */
94237 err = vma_adjust(prev, prev->vm_start,
94238 end, prev->vm_pgoff, NULL);
94239+
94240+#ifdef CONFIG_PAX_SEGMEXEC
94241+ if (!err && prev_m)
94242+ err = vma_adjust(prev_m, prev_m->vm_start,
94243+ end_m, prev_m->vm_pgoff, NULL);
94244+#endif
94245+
94246+ }
94247 if (err)
94248 return NULL;
94249 khugepaged_enter_vma_merge(prev);
94250@@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94251 mpol_equal(policy, vma_policy(next)) &&
94252 can_vma_merge_before(next, vm_flags,
94253 anon_vma, file, pgoff+pglen)) {
94254- if (prev && addr < prev->vm_end) /* case 4 */
94255+ if (prev && addr < prev->vm_end) { /* case 4 */
94256 err = vma_adjust(prev, prev->vm_start,
94257 addr, prev->vm_pgoff, NULL);
94258- else /* cases 3, 8 */
94259+
94260+#ifdef CONFIG_PAX_SEGMEXEC
94261+ if (!err && prev_m)
94262+ err = vma_adjust(prev_m, prev_m->vm_start,
94263+ addr_m, prev_m->vm_pgoff, NULL);
94264+#endif
94265+
94266+ } else { /* cases 3, 8 */
94267 err = vma_adjust(area, addr, next->vm_end,
94268 next->vm_pgoff - pglen, NULL);
94269+
94270+#ifdef CONFIG_PAX_SEGMEXEC
94271+ if (!err && area_m)
94272+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
94273+ next_m->vm_pgoff - pglen, NULL);
94274+#endif
94275+
94276+ }
94277 if (err)
94278 return NULL;
94279 khugepaged_enter_vma_merge(area);
94280@@ -1174,8 +1255,10 @@ none:
94281 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94282 struct file *file, long pages)
94283 {
94284- const unsigned long stack_flags
94285- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
94286+
94287+#ifdef CONFIG_PAX_RANDMMAP
94288+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94289+#endif
94290
94291 mm->total_vm += pages;
94292
94293@@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94294 mm->shared_vm += pages;
94295 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
94296 mm->exec_vm += pages;
94297- } else if (flags & stack_flags)
94298+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
94299 mm->stack_vm += pages;
94300 }
94301 #endif /* CONFIG_PROC_FS */
94302@@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
94303 locked += mm->locked_vm;
94304 lock_limit = rlimit(RLIMIT_MEMLOCK);
94305 lock_limit >>= PAGE_SHIFT;
94306+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94307 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
94308 return -EAGAIN;
94309 }
94310@@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94311 * (the exception is when the underlying filesystem is noexec
94312 * mounted, in which case we dont add PROT_EXEC.)
94313 */
94314- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94315+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94316 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
94317 prot |= PROT_EXEC;
94318
94319@@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94320 /* Obtain the address to map to. we verify (or select) it and ensure
94321 * that it represents a valid section of the address space.
94322 */
94323- addr = get_unmapped_area(file, addr, len, pgoff, flags);
94324+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
94325 if (addr & ~PAGE_MASK)
94326 return addr;
94327
94328@@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94329 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
94330 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
94331
94332+#ifdef CONFIG_PAX_MPROTECT
94333+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94334+
94335+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
94336+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
94337+ mm->binfmt->handle_mmap)
94338+ mm->binfmt->handle_mmap(file);
94339+#endif
94340+
94341+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94342+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
94343+ gr_log_rwxmmap(file);
94344+
94345+#ifdef CONFIG_PAX_EMUPLT
94346+ vm_flags &= ~VM_EXEC;
94347+#else
94348+ return -EPERM;
94349+#endif
94350+
94351+ }
94352+
94353+ if (!(vm_flags & VM_EXEC))
94354+ vm_flags &= ~VM_MAYEXEC;
94355+#else
94356+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94357+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94358+#endif
94359+ else
94360+ vm_flags &= ~VM_MAYWRITE;
94361+ }
94362+#endif
94363+
94364+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94365+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
94366+ vm_flags &= ~VM_PAGEEXEC;
94367+#endif
94368+
94369 if (flags & MAP_LOCKED)
94370 if (!can_do_mlock())
94371 return -EPERM;
94372@@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94373 vm_flags |= VM_NORESERVE;
94374 }
94375
94376+ if (!gr_acl_handle_mmap(file, prot))
94377+ return -EACCES;
94378+
94379 addr = mmap_region(file, addr, len, vm_flags, pgoff);
94380 if (!IS_ERR_VALUE(addr) &&
94381 ((vm_flags & VM_LOCKED) ||
94382@@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
94383 vm_flags_t vm_flags = vma->vm_flags;
94384
94385 /* If it was private or non-writable, the write bit is already clear */
94386- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
94387+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
94388 return 0;
94389
94390 /* The backer wishes to know when pages are first written to? */
94391@@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94392 struct rb_node **rb_link, *rb_parent;
94393 unsigned long charged = 0;
94394
94395+#ifdef CONFIG_PAX_SEGMEXEC
94396+ struct vm_area_struct *vma_m = NULL;
94397+#endif
94398+
94399+ /*
94400+ * mm->mmap_sem is required to protect against another thread
94401+ * changing the mappings in case we sleep.
94402+ */
94403+ verify_mm_writelocked(mm);
94404+
94405 /* Check against address space limit. */
94406+
94407+#ifdef CONFIG_PAX_RANDMMAP
94408+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94409+#endif
94410+
94411 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
94412 unsigned long nr_pages;
94413
94414@@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94415
94416 /* Clear old maps */
94417 error = -ENOMEM;
94418-munmap_back:
94419 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94420 if (do_munmap(mm, addr, len))
94421 return -ENOMEM;
94422- goto munmap_back;
94423+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94424 }
94425
94426 /*
94427@@ -1556,6 +1694,16 @@ munmap_back:
94428 goto unacct_error;
94429 }
94430
94431+#ifdef CONFIG_PAX_SEGMEXEC
94432+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
94433+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94434+ if (!vma_m) {
94435+ error = -ENOMEM;
94436+ goto free_vma;
94437+ }
94438+ }
94439+#endif
94440+
94441 vma->vm_mm = mm;
94442 vma->vm_start = addr;
94443 vma->vm_end = addr + len;
94444@@ -1575,6 +1723,13 @@ munmap_back:
94445 if (error)
94446 goto unmap_and_free_vma;
94447
94448+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94449+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
94450+ vma->vm_flags |= VM_PAGEEXEC;
94451+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94452+ }
94453+#endif
94454+
94455 /* Can addr have changed??
94456 *
94457 * Answer: Yes, several device drivers can do it in their
94458@@ -1608,6 +1763,12 @@ munmap_back:
94459 }
94460
94461 vma_link(mm, vma, prev, rb_link, rb_parent);
94462+
94463+#ifdef CONFIG_PAX_SEGMEXEC
94464+ if (vma_m)
94465+ BUG_ON(pax_mirror_vma(vma_m, vma));
94466+#endif
94467+
94468 /* Once vma denies write, undo our temporary denial count */
94469 if (vm_flags & VM_DENYWRITE)
94470 allow_write_access(file);
94471@@ -1616,6 +1777,7 @@ out:
94472 perf_event_mmap(vma);
94473
94474 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94475+ track_exec_limit(mm, addr, addr + len, vm_flags);
94476 if (vm_flags & VM_LOCKED) {
94477 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94478 vma == get_gate_vma(current->mm)))
94479@@ -1648,6 +1810,12 @@ unmap_and_free_vma:
94480 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94481 charged = 0;
94482 free_vma:
94483+
94484+#ifdef CONFIG_PAX_SEGMEXEC
94485+ if (vma_m)
94486+ kmem_cache_free(vm_area_cachep, vma_m);
94487+#endif
94488+
94489 kmem_cache_free(vm_area_cachep, vma);
94490 unacct_error:
94491 if (charged)
94492@@ -1655,7 +1823,63 @@ unacct_error:
94493 return error;
94494 }
94495
94496-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94497+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94498+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94499+{
94500+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94501+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94502+
94503+ return 0;
94504+}
94505+#endif
94506+
94507+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94508+{
94509+ if (!vma) {
94510+#ifdef CONFIG_STACK_GROWSUP
94511+ if (addr > sysctl_heap_stack_gap)
94512+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94513+ else
94514+ vma = find_vma(current->mm, 0);
94515+ if (vma && (vma->vm_flags & VM_GROWSUP))
94516+ return false;
94517+#endif
94518+ return true;
94519+ }
94520+
94521+ if (addr + len > vma->vm_start)
94522+ return false;
94523+
94524+ if (vma->vm_flags & VM_GROWSDOWN)
94525+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94526+#ifdef CONFIG_STACK_GROWSUP
94527+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94528+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94529+#endif
94530+ else if (offset)
94531+ return offset <= vma->vm_start - addr - len;
94532+
94533+ return true;
94534+}
94535+
94536+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94537+{
94538+ if (vma->vm_start < len)
94539+ return -ENOMEM;
94540+
94541+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94542+ if (offset <= vma->vm_start - len)
94543+ return vma->vm_start - len - offset;
94544+ else
94545+ return -ENOMEM;
94546+ }
94547+
94548+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94549+ return vma->vm_start - len - sysctl_heap_stack_gap;
94550+ return -ENOMEM;
94551+}
94552+
94553+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94554 {
94555 /*
94556 * We implement the search by looking for an rbtree node that
94557@@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94558 }
94559 }
94560
94561- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94562+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94563 check_current:
94564 /* Check if current node has a suitable gap */
94565 if (gap_start > high_limit)
94566 return -ENOMEM;
94567+
94568+ if (gap_end - gap_start > info->threadstack_offset)
94569+ gap_start += info->threadstack_offset;
94570+ else
94571+ gap_start = gap_end;
94572+
94573+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94574+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94575+ gap_start += sysctl_heap_stack_gap;
94576+ else
94577+ gap_start = gap_end;
94578+ }
94579+ if (vma->vm_flags & VM_GROWSDOWN) {
94580+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94581+ gap_end -= sysctl_heap_stack_gap;
94582+ else
94583+ gap_end = gap_start;
94584+ }
94585 if (gap_end >= low_limit && gap_end - gap_start >= length)
94586 goto found;
94587
94588@@ -1757,7 +1999,7 @@ found:
94589 return gap_start;
94590 }
94591
94592-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94593+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94594 {
94595 struct mm_struct *mm = current->mm;
94596 struct vm_area_struct *vma;
94597@@ -1811,6 +2053,24 @@ check_current:
94598 gap_end = vma->vm_start;
94599 if (gap_end < low_limit)
94600 return -ENOMEM;
94601+
94602+ if (gap_end - gap_start > info->threadstack_offset)
94603+ gap_end -= info->threadstack_offset;
94604+ else
94605+ gap_end = gap_start;
94606+
94607+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94608+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94609+ gap_start += sysctl_heap_stack_gap;
94610+ else
94611+ gap_start = gap_end;
94612+ }
94613+ if (vma->vm_flags & VM_GROWSDOWN) {
94614+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94615+ gap_end -= sysctl_heap_stack_gap;
94616+ else
94617+ gap_end = gap_start;
94618+ }
94619 if (gap_start <= high_limit && gap_end - gap_start >= length)
94620 goto found;
94621
94622@@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94623 struct mm_struct *mm = current->mm;
94624 struct vm_area_struct *vma;
94625 struct vm_unmapped_area_info info;
94626+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94627
94628 if (len > TASK_SIZE - mmap_min_addr)
94629 return -ENOMEM;
94630@@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94631 if (flags & MAP_FIXED)
94632 return addr;
94633
94634+#ifdef CONFIG_PAX_RANDMMAP
94635+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94636+#endif
94637+
94638 if (addr) {
94639 addr = PAGE_ALIGN(addr);
94640 vma = find_vma(mm, addr);
94641 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94642- (!vma || addr + len <= vma->vm_start))
94643+ check_heap_stack_gap(vma, addr, len, offset))
94644 return addr;
94645 }
94646
94647@@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94648 info.low_limit = mm->mmap_base;
94649 info.high_limit = TASK_SIZE;
94650 info.align_mask = 0;
94651+ info.threadstack_offset = offset;
94652 return vm_unmapped_area(&info);
94653 }
94654 #endif
94655@@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94656 struct mm_struct *mm = current->mm;
94657 unsigned long addr = addr0;
94658 struct vm_unmapped_area_info info;
94659+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94660
94661 /* requested length too big for entire address space */
94662 if (len > TASK_SIZE - mmap_min_addr)
94663@@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94664 if (flags & MAP_FIXED)
94665 return addr;
94666
94667+#ifdef CONFIG_PAX_RANDMMAP
94668+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94669+#endif
94670+
94671 /* requesting a specific address */
94672 if (addr) {
94673 addr = PAGE_ALIGN(addr);
94674 vma = find_vma(mm, addr);
94675 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94676- (!vma || addr + len <= vma->vm_start))
94677+ check_heap_stack_gap(vma, addr, len, offset))
94678 return addr;
94679 }
94680
94681@@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94682 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94683 info.high_limit = mm->mmap_base;
94684 info.align_mask = 0;
94685+ info.threadstack_offset = offset;
94686 addr = vm_unmapped_area(&info);
94687
94688 /*
94689@@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94690 VM_BUG_ON(addr != -ENOMEM);
94691 info.flags = 0;
94692 info.low_limit = TASK_UNMAPPED_BASE;
94693+
94694+#ifdef CONFIG_PAX_RANDMMAP
94695+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94696+ info.low_limit += mm->delta_mmap;
94697+#endif
94698+
94699 info.high_limit = TASK_SIZE;
94700 addr = vm_unmapped_area(&info);
94701 }
94702@@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94703 return vma;
94704 }
94705
94706+#ifdef CONFIG_PAX_SEGMEXEC
94707+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94708+{
94709+ struct vm_area_struct *vma_m;
94710+
94711+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94712+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94713+ BUG_ON(vma->vm_mirror);
94714+ return NULL;
94715+ }
94716+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94717+ vma_m = vma->vm_mirror;
94718+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94719+ BUG_ON(vma->vm_file != vma_m->vm_file);
94720+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94721+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94722+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94723+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94724+ return vma_m;
94725+}
94726+#endif
94727+
94728 /*
94729 * Verify that the stack growth is acceptable and
94730 * update accounting. This is shared with both the
94731@@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94732 return -ENOMEM;
94733
94734 /* Stack limit test */
94735+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94736 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94737 return -ENOMEM;
94738
94739@@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94740 locked = mm->locked_vm + grow;
94741 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94742 limit >>= PAGE_SHIFT;
94743+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94744 if (locked > limit && !capable(CAP_IPC_LOCK))
94745 return -ENOMEM;
94746 }
94747@@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94748 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94749 * vma is the last one with address > vma->vm_end. Have to extend vma.
94750 */
94751+#ifndef CONFIG_IA64
94752+static
94753+#endif
94754 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94755 {
94756 int error;
94757+ bool locknext;
94758
94759 if (!(vma->vm_flags & VM_GROWSUP))
94760 return -EFAULT;
94761
94762+ /* Also guard against wrapping around to address 0. */
94763+ if (address < PAGE_ALIGN(address+1))
94764+ address = PAGE_ALIGN(address+1);
94765+ else
94766+ return -ENOMEM;
94767+
94768 /*
94769 * We must make sure the anon_vma is allocated
94770 * so that the anon_vma locking is not a noop.
94771 */
94772 if (unlikely(anon_vma_prepare(vma)))
94773 return -ENOMEM;
94774+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94775+ if (locknext && anon_vma_prepare(vma->vm_next))
94776+ return -ENOMEM;
94777 vma_lock_anon_vma(vma);
94778+ if (locknext)
94779+ vma_lock_anon_vma(vma->vm_next);
94780
94781 /*
94782 * vma->vm_start/vm_end cannot change under us because the caller
94783 * is required to hold the mmap_sem in read mode. We need the
94784- * anon_vma lock to serialize against concurrent expand_stacks.
94785- * Also guard against wrapping around to address 0.
94786+ * anon_vma locks to serialize against concurrent expand_stacks
94787+ * and expand_upwards.
94788 */
94789- if (address < PAGE_ALIGN(address+4))
94790- address = PAGE_ALIGN(address+4);
94791- else {
94792- vma_unlock_anon_vma(vma);
94793- return -ENOMEM;
94794- }
94795 error = 0;
94796
94797 /* Somebody else might have raced and expanded it already */
94798- if (address > vma->vm_end) {
94799+ 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)
94800+ error = -ENOMEM;
94801+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94802 unsigned long size, grow;
94803
94804 size = address - vma->vm_start;
94805@@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94806 }
94807 }
94808 }
94809+ if (locknext)
94810+ vma_unlock_anon_vma(vma->vm_next);
94811 vma_unlock_anon_vma(vma);
94812 khugepaged_enter_vma_merge(vma);
94813 validate_mm(vma->vm_mm);
94814@@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
94815 unsigned long address)
94816 {
94817 int error;
94818+ bool lockprev = false;
94819+ struct vm_area_struct *prev;
94820
94821 /*
94822 * We must make sure the anon_vma is allocated
94823@@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
94824 if (error)
94825 return error;
94826
94827+ prev = vma->vm_prev;
94828+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94829+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94830+#endif
94831+ if (lockprev && anon_vma_prepare(prev))
94832+ return -ENOMEM;
94833+ if (lockprev)
94834+ vma_lock_anon_vma(prev);
94835+
94836 vma_lock_anon_vma(vma);
94837
94838 /*
94839@@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
94840 */
94841
94842 /* Somebody else might have raced and expanded it already */
94843- if (address < vma->vm_start) {
94844+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94845+ error = -ENOMEM;
94846+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94847 unsigned long size, grow;
94848
94849+#ifdef CONFIG_PAX_SEGMEXEC
94850+ struct vm_area_struct *vma_m;
94851+
94852+ vma_m = pax_find_mirror_vma(vma);
94853+#endif
94854+
94855 size = vma->vm_end - address;
94856 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94857
94858@@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
94859 vma->vm_pgoff -= grow;
94860 anon_vma_interval_tree_post_update_vma(vma);
94861 vma_gap_update(vma);
94862+
94863+#ifdef CONFIG_PAX_SEGMEXEC
94864+ if (vma_m) {
94865+ anon_vma_interval_tree_pre_update_vma(vma_m);
94866+ vma_m->vm_start -= grow << PAGE_SHIFT;
94867+ vma_m->vm_pgoff -= grow;
94868+ anon_vma_interval_tree_post_update_vma(vma_m);
94869+ vma_gap_update(vma_m);
94870+ }
94871+#endif
94872+
94873 spin_unlock(&vma->vm_mm->page_table_lock);
94874
94875+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94876 perf_event_mmap(vma);
94877 }
94878 }
94879 }
94880 vma_unlock_anon_vma(vma);
94881+ if (lockprev)
94882+ vma_unlock_anon_vma(prev);
94883 khugepaged_enter_vma_merge(vma);
94884 validate_mm(vma->vm_mm);
94885 return error;
94886@@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94887 do {
94888 long nrpages = vma_pages(vma);
94889
94890+#ifdef CONFIG_PAX_SEGMEXEC
94891+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94892+ vma = remove_vma(vma);
94893+ continue;
94894+ }
94895+#endif
94896+
94897 if (vma->vm_flags & VM_ACCOUNT)
94898 nr_accounted += nrpages;
94899 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94900@@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94901 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94902 vma->vm_prev = NULL;
94903 do {
94904+
94905+#ifdef CONFIG_PAX_SEGMEXEC
94906+ if (vma->vm_mirror) {
94907+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94908+ vma->vm_mirror->vm_mirror = NULL;
94909+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94910+ vma->vm_mirror = NULL;
94911+ }
94912+#endif
94913+
94914 vma_rb_erase(vma, &mm->mm_rb);
94915 mm->map_count--;
94916 tail_vma = vma;
94917@@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94918 struct vm_area_struct *new;
94919 int err = -ENOMEM;
94920
94921+#ifdef CONFIG_PAX_SEGMEXEC
94922+ struct vm_area_struct *vma_m, *new_m = NULL;
94923+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94924+#endif
94925+
94926 if (is_vm_hugetlb_page(vma) && (addr &
94927 ~(huge_page_mask(hstate_vma(vma)))))
94928 return -EINVAL;
94929
94930+#ifdef CONFIG_PAX_SEGMEXEC
94931+ vma_m = pax_find_mirror_vma(vma);
94932+#endif
94933+
94934 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94935 if (!new)
94936 goto out_err;
94937
94938+#ifdef CONFIG_PAX_SEGMEXEC
94939+ if (vma_m) {
94940+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94941+ if (!new_m) {
94942+ kmem_cache_free(vm_area_cachep, new);
94943+ goto out_err;
94944+ }
94945+ }
94946+#endif
94947+
94948 /* most fields are the same, copy all, and then fixup */
94949 *new = *vma;
94950
94951@@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94952 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94953 }
94954
94955+#ifdef CONFIG_PAX_SEGMEXEC
94956+ if (vma_m) {
94957+ *new_m = *vma_m;
94958+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94959+ new_m->vm_mirror = new;
94960+ new->vm_mirror = new_m;
94961+
94962+ if (new_below)
94963+ new_m->vm_end = addr_m;
94964+ else {
94965+ new_m->vm_start = addr_m;
94966+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94967+ }
94968+ }
94969+#endif
94970+
94971 err = vma_dup_policy(vma, new);
94972 if (err)
94973 goto out_free_vma;
94974@@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94975 else
94976 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94977
94978+#ifdef CONFIG_PAX_SEGMEXEC
94979+ if (!err && vma_m) {
94980+ struct mempolicy *pol = vma_policy(new);
94981+
94982+ if (anon_vma_clone(new_m, vma_m))
94983+ goto out_free_mpol;
94984+
94985+ mpol_get(pol);
94986+ set_vma_policy(new_m, pol);
94987+
94988+ if (new_m->vm_file)
94989+ get_file(new_m->vm_file);
94990+
94991+ if (new_m->vm_ops && new_m->vm_ops->open)
94992+ new_m->vm_ops->open(new_m);
94993+
94994+ if (new_below)
94995+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94996+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94997+ else
94998+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94999+
95000+ if (err) {
95001+ if (new_m->vm_ops && new_m->vm_ops->close)
95002+ new_m->vm_ops->close(new_m);
95003+ if (new_m->vm_file)
95004+ fput(new_m->vm_file);
95005+ mpol_put(pol);
95006+ }
95007+ }
95008+#endif
95009+
95010 /* Success. */
95011 if (!err)
95012 return 0;
95013@@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95014 new->vm_ops->close(new);
95015 if (new->vm_file)
95016 fput(new->vm_file);
95017- unlink_anon_vmas(new);
95018 out_free_mpol:
95019 mpol_put(vma_policy(new));
95020 out_free_vma:
95021+
95022+#ifdef CONFIG_PAX_SEGMEXEC
95023+ if (new_m) {
95024+ unlink_anon_vmas(new_m);
95025+ kmem_cache_free(vm_area_cachep, new_m);
95026+ }
95027+#endif
95028+
95029+ unlink_anon_vmas(new);
95030 kmem_cache_free(vm_area_cachep, new);
95031 out_err:
95032 return err;
95033@@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95034 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95035 unsigned long addr, int new_below)
95036 {
95037+
95038+#ifdef CONFIG_PAX_SEGMEXEC
95039+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
95040+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
95041+ if (mm->map_count >= sysctl_max_map_count-1)
95042+ return -ENOMEM;
95043+ } else
95044+#endif
95045+
95046 if (mm->map_count >= sysctl_max_map_count)
95047 return -ENOMEM;
95048
95049@@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95050 * work. This now handles partial unmappings.
95051 * Jeremy Fitzhardinge <jeremy@goop.org>
95052 */
95053+#ifdef CONFIG_PAX_SEGMEXEC
95054 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95055 {
95056+ int ret = __do_munmap(mm, start, len);
95057+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
95058+ return ret;
95059+
95060+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
95061+}
95062+
95063+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95064+#else
95065+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95066+#endif
95067+{
95068 unsigned long end;
95069 struct vm_area_struct *vma, *prev, *last;
95070
95071+ /*
95072+ * mm->mmap_sem is required to protect against another thread
95073+ * changing the mappings in case we sleep.
95074+ */
95075+ verify_mm_writelocked(mm);
95076+
95077 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
95078 return -EINVAL;
95079
95080@@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95081 /* Fix up all other VM information */
95082 remove_vma_list(mm, vma);
95083
95084+ track_exec_limit(mm, start, end, 0UL);
95085+
95086 return 0;
95087 }
95088
95089@@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
95090 int ret;
95091 struct mm_struct *mm = current->mm;
95092
95093+
95094+#ifdef CONFIG_PAX_SEGMEXEC
95095+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
95096+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
95097+ return -EINVAL;
95098+#endif
95099+
95100 down_write(&mm->mmap_sem);
95101 ret = do_munmap(mm, start, len);
95102 up_write(&mm->mmap_sem);
95103@@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
95104 return vm_munmap(addr, len);
95105 }
95106
95107-static inline void verify_mm_writelocked(struct mm_struct *mm)
95108-{
95109-#ifdef CONFIG_DEBUG_VM
95110- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
95111- WARN_ON(1);
95112- up_read(&mm->mmap_sem);
95113- }
95114-#endif
95115-}
95116-
95117 /*
95118 * this is really a simplified "do_mmap". it only handles
95119 * anonymous maps. eventually we may be able to do some
95120@@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95121 struct rb_node ** rb_link, * rb_parent;
95122 pgoff_t pgoff = addr >> PAGE_SHIFT;
95123 int error;
95124+ unsigned long charged;
95125
95126 len = PAGE_ALIGN(len);
95127 if (!len)
95128@@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95129
95130 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
95131
95132+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
95133+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
95134+ flags &= ~VM_EXEC;
95135+
95136+#ifdef CONFIG_PAX_MPROTECT
95137+ if (mm->pax_flags & MF_PAX_MPROTECT)
95138+ flags &= ~VM_MAYEXEC;
95139+#endif
95140+
95141+ }
95142+#endif
95143+
95144 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
95145 if (error & ~PAGE_MASK)
95146 return error;
95147
95148+ charged = len >> PAGE_SHIFT;
95149+
95150 error = mlock_future_check(mm, mm->def_flags, len);
95151 if (error)
95152 return error;
95153@@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95154 /*
95155 * Clear old maps. this also does some error checking for us
95156 */
95157- munmap_back:
95158 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
95159 if (do_munmap(mm, addr, len))
95160 return -ENOMEM;
95161- goto munmap_back;
95162+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
95163 }
95164
95165 /* Check against address space limits *after* clearing old maps... */
95166- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
95167+ if (!may_expand_vm(mm, charged))
95168 return -ENOMEM;
95169
95170 if (mm->map_count > sysctl_max_map_count)
95171 return -ENOMEM;
95172
95173- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
95174+ if (security_vm_enough_memory_mm(mm, charged))
95175 return -ENOMEM;
95176
95177 /* Can we just expand an old private anonymous mapping? */
95178@@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95179 */
95180 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95181 if (!vma) {
95182- vm_unacct_memory(len >> PAGE_SHIFT);
95183+ vm_unacct_memory(charged);
95184 return -ENOMEM;
95185 }
95186
95187@@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95188 vma_link(mm, vma, prev, rb_link, rb_parent);
95189 out:
95190 perf_event_mmap(vma);
95191- mm->total_vm += len >> PAGE_SHIFT;
95192+ mm->total_vm += charged;
95193 if (flags & VM_LOCKED)
95194- mm->locked_vm += (len >> PAGE_SHIFT);
95195+ mm->locked_vm += charged;
95196 vma->vm_flags |= VM_SOFTDIRTY;
95197+ track_exec_limit(mm, addr, addr + len, flags);
95198 return addr;
95199 }
95200
95201@@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
95202 while (vma) {
95203 if (vma->vm_flags & VM_ACCOUNT)
95204 nr_accounted += vma_pages(vma);
95205+ vma->vm_mirror = NULL;
95206 vma = remove_vma(vma);
95207 }
95208 vm_unacct_memory(nr_accounted);
95209@@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95210 struct vm_area_struct *prev;
95211 struct rb_node **rb_link, *rb_parent;
95212
95213+#ifdef CONFIG_PAX_SEGMEXEC
95214+ struct vm_area_struct *vma_m = NULL;
95215+#endif
95216+
95217+ if (security_mmap_addr(vma->vm_start))
95218+ return -EPERM;
95219+
95220 /*
95221 * The vm_pgoff of a purely anonymous vma should be irrelevant
95222 * until its first write fault, when page's anon_vma and index
95223@@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95224 security_vm_enough_memory_mm(mm, vma_pages(vma)))
95225 return -ENOMEM;
95226
95227+#ifdef CONFIG_PAX_SEGMEXEC
95228+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
95229+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95230+ if (!vma_m)
95231+ return -ENOMEM;
95232+ }
95233+#endif
95234+
95235 vma_link(mm, vma, prev, rb_link, rb_parent);
95236+
95237+#ifdef CONFIG_PAX_SEGMEXEC
95238+ if (vma_m)
95239+ BUG_ON(pax_mirror_vma(vma_m, vma));
95240+#endif
95241+
95242 return 0;
95243 }
95244
95245@@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95246 struct rb_node **rb_link, *rb_parent;
95247 bool faulted_in_anon_vma = true;
95248
95249+ BUG_ON(vma->vm_mirror);
95250+
95251 /*
95252 * If anonymous vma has not yet been faulted, update new pgoff
95253 * to match new location, to increase its chance of merging.
95254@@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95255 return NULL;
95256 }
95257
95258+#ifdef CONFIG_PAX_SEGMEXEC
95259+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
95260+{
95261+ struct vm_area_struct *prev_m;
95262+ struct rb_node **rb_link_m, *rb_parent_m;
95263+ struct mempolicy *pol_m;
95264+
95265+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
95266+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
95267+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
95268+ *vma_m = *vma;
95269+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
95270+ if (anon_vma_clone(vma_m, vma))
95271+ return -ENOMEM;
95272+ pol_m = vma_policy(vma_m);
95273+ mpol_get(pol_m);
95274+ set_vma_policy(vma_m, pol_m);
95275+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
95276+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
95277+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
95278+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
95279+ if (vma_m->vm_file)
95280+ get_file(vma_m->vm_file);
95281+ if (vma_m->vm_ops && vma_m->vm_ops->open)
95282+ vma_m->vm_ops->open(vma_m);
95283+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
95284+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
95285+ vma_m->vm_mirror = vma;
95286+ vma->vm_mirror = vma_m;
95287+ return 0;
95288+}
95289+#endif
95290+
95291 /*
95292 * Return true if the calling process may expand its vm space by the passed
95293 * number of pages
95294@@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
95295
95296 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
95297
95298+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
95299 if (cur + npages > lim)
95300 return 0;
95301 return 1;
95302@@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
95303 vma->vm_start = addr;
95304 vma->vm_end = addr + len;
95305
95306+#ifdef CONFIG_PAX_MPROTECT
95307+ if (mm->pax_flags & MF_PAX_MPROTECT) {
95308+#ifndef CONFIG_PAX_MPROTECT_COMPAT
95309+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
95310+ return ERR_PTR(-EPERM);
95311+ if (!(vm_flags & VM_EXEC))
95312+ vm_flags &= ~VM_MAYEXEC;
95313+#else
95314+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
95315+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
95316+#endif
95317+ else
95318+ vm_flags &= ~VM_MAYWRITE;
95319+ }
95320+#endif
95321+
95322 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
95323 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
95324
95325diff --git a/mm/mprotect.c b/mm/mprotect.c
95326index c43d557..0b7ccd2 100644
95327--- a/mm/mprotect.c
95328+++ b/mm/mprotect.c
95329@@ -24,10 +24,18 @@
95330 #include <linux/migrate.h>
95331 #include <linux/perf_event.h>
95332 #include <linux/ksm.h>
95333+#include <linux/sched/sysctl.h>
95334+
95335+#ifdef CONFIG_PAX_MPROTECT
95336+#include <linux/elf.h>
95337+#include <linux/binfmts.h>
95338+#endif
95339+
95340 #include <asm/uaccess.h>
95341 #include <asm/pgtable.h>
95342 #include <asm/cacheflush.h>
95343 #include <asm/tlbflush.h>
95344+#include <asm/mmu_context.h>
95345
95346 #ifndef pgprot_modify
95347 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
95348@@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
95349 return pages;
95350 }
95351
95352+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95353+/* called while holding the mmap semaphor for writing except stack expansion */
95354+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
95355+{
95356+ unsigned long oldlimit, newlimit = 0UL;
95357+
95358+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
95359+ return;
95360+
95361+ spin_lock(&mm->page_table_lock);
95362+ oldlimit = mm->context.user_cs_limit;
95363+ if ((prot & VM_EXEC) && oldlimit < end)
95364+ /* USER_CS limit moved up */
95365+ newlimit = end;
95366+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
95367+ /* USER_CS limit moved down */
95368+ newlimit = start;
95369+
95370+ if (newlimit) {
95371+ mm->context.user_cs_limit = newlimit;
95372+
95373+#ifdef CONFIG_SMP
95374+ wmb();
95375+ cpus_clear(mm->context.cpu_user_cs_mask);
95376+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
95377+#endif
95378+
95379+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
95380+ }
95381+ spin_unlock(&mm->page_table_lock);
95382+ if (newlimit == end) {
95383+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
95384+
95385+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
95386+ if (is_vm_hugetlb_page(vma))
95387+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
95388+ else
95389+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
95390+ }
95391+}
95392+#endif
95393+
95394 int
95395 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95396 unsigned long start, unsigned long end, unsigned long newflags)
95397@@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95398 int error;
95399 int dirty_accountable = 0;
95400
95401+#ifdef CONFIG_PAX_SEGMEXEC
95402+ struct vm_area_struct *vma_m = NULL;
95403+ unsigned long start_m, end_m;
95404+
95405+ start_m = start + SEGMEXEC_TASK_SIZE;
95406+ end_m = end + SEGMEXEC_TASK_SIZE;
95407+#endif
95408+
95409 if (newflags == oldflags) {
95410 *pprev = vma;
95411 return 0;
95412 }
95413
95414+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
95415+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
95416+
95417+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
95418+ return -ENOMEM;
95419+
95420+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
95421+ return -ENOMEM;
95422+ }
95423+
95424 /*
95425 * If we make a private mapping writable we increase our commit;
95426 * but (without finer accounting) cannot reduce our commit if we
95427@@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95428 }
95429 }
95430
95431+#ifdef CONFIG_PAX_SEGMEXEC
95432+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
95433+ if (start != vma->vm_start) {
95434+ error = split_vma(mm, vma, start, 1);
95435+ if (error)
95436+ goto fail;
95437+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
95438+ *pprev = (*pprev)->vm_next;
95439+ }
95440+
95441+ if (end != vma->vm_end) {
95442+ error = split_vma(mm, vma, end, 0);
95443+ if (error)
95444+ goto fail;
95445+ }
95446+
95447+ if (pax_find_mirror_vma(vma)) {
95448+ error = __do_munmap(mm, start_m, end_m - start_m);
95449+ if (error)
95450+ goto fail;
95451+ } else {
95452+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95453+ if (!vma_m) {
95454+ error = -ENOMEM;
95455+ goto fail;
95456+ }
95457+ vma->vm_flags = newflags;
95458+ error = pax_mirror_vma(vma_m, vma);
95459+ if (error) {
95460+ vma->vm_flags = oldflags;
95461+ goto fail;
95462+ }
95463+ }
95464+ }
95465+#endif
95466+
95467 /*
95468 * First try to merge with previous and/or next vma.
95469 */
95470@@ -319,9 +423,21 @@ success:
95471 * vm_flags and vm_page_prot are protected by the mmap_sem
95472 * held in write mode.
95473 */
95474+
95475+#ifdef CONFIG_PAX_SEGMEXEC
95476+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95477+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95478+#endif
95479+
95480 vma->vm_flags = newflags;
95481+
95482+#ifdef CONFIG_PAX_MPROTECT
95483+ if (mm->binfmt && mm->binfmt->handle_mprotect)
95484+ mm->binfmt->handle_mprotect(vma, newflags);
95485+#endif
95486+
95487 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95488- vm_get_page_prot(newflags));
95489+ vm_get_page_prot(vma->vm_flags));
95490
95491 if (vma_wants_writenotify(vma)) {
95492 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95493@@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95494 end = start + len;
95495 if (end <= start)
95496 return -ENOMEM;
95497+
95498+#ifdef CONFIG_PAX_SEGMEXEC
95499+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95500+ if (end > SEGMEXEC_TASK_SIZE)
95501+ return -EINVAL;
95502+ } else
95503+#endif
95504+
95505+ if (end > TASK_SIZE)
95506+ return -EINVAL;
95507+
95508 if (!arch_validate_prot(prot))
95509 return -EINVAL;
95510
95511@@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95512 /*
95513 * Does the application expect PROT_READ to imply PROT_EXEC:
95514 */
95515- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95516+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95517 prot |= PROT_EXEC;
95518
95519 vm_flags = calc_vm_prot_bits(prot);
95520@@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95521 if (start > vma->vm_start)
95522 prev = vma;
95523
95524+#ifdef CONFIG_PAX_MPROTECT
95525+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95526+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
95527+#endif
95528+
95529 for (nstart = start ; ; ) {
95530 unsigned long newflags;
95531
95532@@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95533
95534 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95535 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95536+ if (prot & (PROT_WRITE | PROT_EXEC))
95537+ gr_log_rwxmprotect(vma);
95538+
95539+ error = -EACCES;
95540+ goto out;
95541+ }
95542+
95543+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95544 error = -EACCES;
95545 goto out;
95546 }
95547@@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95548 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95549 if (error)
95550 goto out;
95551+
95552+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95553+
95554 nstart = tmp;
95555
95556 if (nstart < prev->vm_end)
95557diff --git a/mm/mremap.c b/mm/mremap.c
95558index 05f1180..c3cde48 100644
95559--- a/mm/mremap.c
95560+++ b/mm/mremap.c
95561@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95562 continue;
95563 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95564 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95565+
95566+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95567+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95568+ pte = pte_exprotect(pte);
95569+#endif
95570+
95571 pte = move_soft_dirty_pte(pte);
95572 set_pte_at(mm, new_addr, new_pte, pte);
95573 }
95574@@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95575 if (is_vm_hugetlb_page(vma))
95576 goto Einval;
95577
95578+#ifdef CONFIG_PAX_SEGMEXEC
95579+ if (pax_find_mirror_vma(vma))
95580+ goto Einval;
95581+#endif
95582+
95583 /* We can't remap across vm area boundaries */
95584 if (old_len > vma->vm_end - addr)
95585 goto Efault;
95586@@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95587 unsigned long ret = -EINVAL;
95588 unsigned long charged = 0;
95589 unsigned long map_flags;
95590+ unsigned long pax_task_size = TASK_SIZE;
95591
95592 if (new_addr & ~PAGE_MASK)
95593 goto out;
95594
95595- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95596+#ifdef CONFIG_PAX_SEGMEXEC
95597+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95598+ pax_task_size = SEGMEXEC_TASK_SIZE;
95599+#endif
95600+
95601+ pax_task_size -= PAGE_SIZE;
95602+
95603+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95604 goto out;
95605
95606 /* Check if the location we're moving into overlaps the
95607 * old location at all, and fail if it does.
95608 */
95609- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95610- goto out;
95611-
95612- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95613+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95614 goto out;
95615
95616 ret = do_munmap(mm, new_addr, new_len);
95617@@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95618 unsigned long ret = -EINVAL;
95619 unsigned long charged = 0;
95620 bool locked = false;
95621+ unsigned long pax_task_size = TASK_SIZE;
95622
95623 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95624 return ret;
95625@@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95626 if (!new_len)
95627 return ret;
95628
95629+#ifdef CONFIG_PAX_SEGMEXEC
95630+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95631+ pax_task_size = SEGMEXEC_TASK_SIZE;
95632+#endif
95633+
95634+ pax_task_size -= PAGE_SIZE;
95635+
95636+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95637+ old_len > pax_task_size || addr > pax_task_size-old_len)
95638+ return ret;
95639+
95640 down_write(&current->mm->mmap_sem);
95641
95642 if (flags & MREMAP_FIXED) {
95643@@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95644 new_addr = addr;
95645 }
95646 ret = addr;
95647+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95648 goto out;
95649 }
95650 }
95651@@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95652 goto out;
95653 }
95654
95655+ map_flags = vma->vm_flags;
95656 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95657+ if (!(ret & ~PAGE_MASK)) {
95658+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95659+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95660+ }
95661 }
95662 out:
95663 if (ret & ~PAGE_MASK)
95664diff --git a/mm/nommu.c b/mm/nommu.c
95665index 431fd7c..8674512 100644
95666--- a/mm/nommu.c
95667+++ b/mm/nommu.c
95668@@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95669 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95670 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95671 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95672-int heap_stack_gap = 0;
95673
95674 atomic_long_t mmap_pages_allocated;
95675
95676@@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95677 EXPORT_SYMBOL(find_vma);
95678
95679 /*
95680- * find a VMA
95681- * - we don't extend stack VMAs under NOMMU conditions
95682- */
95683-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95684-{
95685- return find_vma(mm, addr);
95686-}
95687-
95688-/*
95689 * expand a stack to a given address
95690 * - not supported under NOMMU conditions
95691 */
95692@@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95693
95694 /* most fields are the same, copy all, and then fixup */
95695 *new = *vma;
95696+ INIT_LIST_HEAD(&new->anon_vma_chain);
95697 *region = *vma->vm_region;
95698 new->vm_region = region;
95699
95700@@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95701 }
95702 EXPORT_SYMBOL(generic_file_remap_pages);
95703
95704-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95705- unsigned long addr, void *buf, int len, int write)
95706+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95707+ unsigned long addr, void *buf, size_t len, int write)
95708 {
95709 struct vm_area_struct *vma;
95710
95711@@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95712 *
95713 * The caller must hold a reference on @mm.
95714 */
95715-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95716- void *buf, int len, int write)
95717+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95718+ void *buf, size_t len, int write)
95719 {
95720 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95721 }
95722@@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95723 * Access another process' address space.
95724 * - source/target buffer must be kernel space
95725 */
95726-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95727+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95728 {
95729 struct mm_struct *mm;
95730
95731diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95732index f972182..e7f7c07 100644
95733--- a/mm/page-writeback.c
95734+++ b/mm/page-writeback.c
95735@@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95736 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95737 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95738 */
95739-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95740+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95741 unsigned long thresh,
95742 unsigned long bg_thresh,
95743 unsigned long dirty,
95744diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95745index e98306f..3311d5e 100644
95746--- a/mm/page_alloc.c
95747+++ b/mm/page_alloc.c
95748@@ -61,6 +61,7 @@
95749 #include <linux/page-debug-flags.h>
95750 #include <linux/hugetlb.h>
95751 #include <linux/sched/rt.h>
95752+#include <linux/random.h>
95753
95754 #include <asm/sections.h>
95755 #include <asm/tlbflush.h>
95756@@ -356,7 +357,7 @@ out:
95757 * This usage means that zero-order pages may not be compound.
95758 */
95759
95760-static void free_compound_page(struct page *page)
95761+void free_compound_page(struct page *page)
95762 {
95763 __free_pages_ok(page, compound_order(page));
95764 }
95765@@ -730,6 +731,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95766 int i;
95767 int bad = 0;
95768
95769+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95770+ unsigned long index = 1UL << order;
95771+#endif
95772+
95773 trace_mm_page_free(page, order);
95774 kmemcheck_free_shadow(page, order);
95775
95776@@ -746,6 +751,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95777 debug_check_no_obj_freed(page_address(page),
95778 PAGE_SIZE << order);
95779 }
95780+
95781+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95782+ for (; index; --index)
95783+ sanitize_highpage(page + index - 1);
95784+#endif
95785+
95786 arch_free_page(page, order);
95787 kernel_map_pages(page, 1 << order, 0);
95788
95789@@ -768,6 +779,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95790 local_irq_restore(flags);
95791 }
95792
95793+#ifdef CONFIG_PAX_LATENT_ENTROPY
95794+bool __meminitdata extra_latent_entropy;
95795+
95796+static int __init setup_pax_extra_latent_entropy(char *str)
95797+{
95798+ extra_latent_entropy = true;
95799+ return 0;
95800+}
95801+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95802+
95803+volatile u64 latent_entropy __latent_entropy;
95804+EXPORT_SYMBOL(latent_entropy);
95805+#endif
95806+
95807 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95808 {
95809 unsigned int nr_pages = 1 << order;
95810@@ -783,6 +808,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95811 __ClearPageReserved(p);
95812 set_page_count(p, 0);
95813
95814+#ifdef CONFIG_PAX_LATENT_ENTROPY
95815+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95816+ u64 hash = 0;
95817+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95818+ const u64 *data = lowmem_page_address(page);
95819+
95820+ for (index = 0; index < end; index++)
95821+ hash ^= hash + data[index];
95822+ latent_entropy ^= hash;
95823+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95824+ }
95825+#endif
95826+
95827 page_zone(page)->managed_pages += nr_pages;
95828 set_page_refcounted(page);
95829 __free_pages(page, order);
95830@@ -911,8 +949,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95831 arch_alloc_page(page, order);
95832 kernel_map_pages(page, 1 << order, 1);
95833
95834+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95835 if (gfp_flags & __GFP_ZERO)
95836 prep_zero_page(page, order, gfp_flags);
95837+#endif
95838
95839 if (order && (gfp_flags & __GFP_COMP))
95840 prep_compound_page(page, order);
95841@@ -2415,7 +2455,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95842 continue;
95843 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95844 high_wmark_pages(zone) - low_wmark_pages(zone) -
95845- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95846+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95847 }
95848 }
95849
95850diff --git a/mm/page_io.c b/mm/page_io.c
95851index 7c59ef6..1358905 100644
95852--- a/mm/page_io.c
95853+++ b/mm/page_io.c
95854@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95855 struct file *swap_file = sis->swap_file;
95856 struct address_space *mapping = swap_file->f_mapping;
95857 struct iovec iov = {
95858- .iov_base = kmap(page),
95859+ .iov_base = (void __force_user *)kmap(page),
95860 .iov_len = PAGE_SIZE,
95861 };
95862
95863diff --git a/mm/percpu.c b/mm/percpu.c
95864index 2ddf9a9..f8fc075 100644
95865--- a/mm/percpu.c
95866+++ b/mm/percpu.c
95867@@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95868 static unsigned int pcpu_high_unit_cpu __read_mostly;
95869
95870 /* the address of the first chunk which starts with the kernel static area */
95871-void *pcpu_base_addr __read_mostly;
95872+void *pcpu_base_addr __read_only;
95873 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95874
95875 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95876diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95877index 8505c92..946bfc9 100644
95878--- a/mm/process_vm_access.c
95879+++ b/mm/process_vm_access.c
95880@@ -13,6 +13,7 @@
95881 #include <linux/uio.h>
95882 #include <linux/sched.h>
95883 #include <linux/highmem.h>
95884+#include <linux/security.h>
95885 #include <linux/ptrace.h>
95886 #include <linux/slab.h>
95887 #include <linux/syscalls.h>
95888@@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95889 ssize_t iov_len;
95890 size_t total_len = iov_iter_count(iter);
95891
95892+ return -ENOSYS; // PaX: until properly audited
95893+
95894 /*
95895 * Work out how many pages of struct pages we're going to need
95896 * when eventually calling get_user_pages
95897 */
95898 for (i = 0; i < riovcnt; i++) {
95899 iov_len = rvec[i].iov_len;
95900- if (iov_len > 0) {
95901- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95902- + iov_len)
95903- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95904- / PAGE_SIZE + 1;
95905- nr_pages = max(nr_pages, nr_pages_iov);
95906- }
95907+ if (iov_len <= 0)
95908+ continue;
95909+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95910+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95911+ nr_pages = max(nr_pages, nr_pages_iov);
95912 }
95913
95914 if (nr_pages == 0)
95915@@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95916 goto free_proc_pages;
95917 }
95918
95919+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95920+ rc = -EPERM;
95921+ goto put_task_struct;
95922+ }
95923+
95924 mm = mm_access(task, PTRACE_MODE_ATTACH);
95925 if (!mm || IS_ERR(mm)) {
95926 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95927diff --git a/mm/rmap.c b/mm/rmap.c
95928index 14d1e28..3777962 100644
95929--- a/mm/rmap.c
95930+++ b/mm/rmap.c
95931@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95932 struct anon_vma *anon_vma = vma->anon_vma;
95933 struct anon_vma_chain *avc;
95934
95935+#ifdef CONFIG_PAX_SEGMEXEC
95936+ struct anon_vma_chain *avc_m = NULL;
95937+#endif
95938+
95939 might_sleep();
95940 if (unlikely(!anon_vma)) {
95941 struct mm_struct *mm = vma->vm_mm;
95942@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95943 if (!avc)
95944 goto out_enomem;
95945
95946+#ifdef CONFIG_PAX_SEGMEXEC
95947+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95948+ if (!avc_m)
95949+ goto out_enomem_free_avc;
95950+#endif
95951+
95952 anon_vma = find_mergeable_anon_vma(vma);
95953 allocated = NULL;
95954 if (!anon_vma) {
95955@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95956 /* page_table_lock to protect against threads */
95957 spin_lock(&mm->page_table_lock);
95958 if (likely(!vma->anon_vma)) {
95959+
95960+#ifdef CONFIG_PAX_SEGMEXEC
95961+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95962+
95963+ if (vma_m) {
95964+ BUG_ON(vma_m->anon_vma);
95965+ vma_m->anon_vma = anon_vma;
95966+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95967+ avc_m = NULL;
95968+ }
95969+#endif
95970+
95971 vma->anon_vma = anon_vma;
95972 anon_vma_chain_link(vma, avc, anon_vma);
95973 allocated = NULL;
95974@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95975
95976 if (unlikely(allocated))
95977 put_anon_vma(allocated);
95978+
95979+#ifdef CONFIG_PAX_SEGMEXEC
95980+ if (unlikely(avc_m))
95981+ anon_vma_chain_free(avc_m);
95982+#endif
95983+
95984 if (unlikely(avc))
95985 anon_vma_chain_free(avc);
95986 }
95987 return 0;
95988
95989 out_enomem_free_avc:
95990+
95991+#ifdef CONFIG_PAX_SEGMEXEC
95992+ if (avc_m)
95993+ anon_vma_chain_free(avc_m);
95994+#endif
95995+
95996 anon_vma_chain_free(avc);
95997 out_enomem:
95998 return -ENOMEM;
95999@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
96000 * Attach the anon_vmas from src to dst.
96001 * Returns 0 on success, -ENOMEM on failure.
96002 */
96003-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
96004+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
96005 {
96006 struct anon_vma_chain *avc, *pavc;
96007 struct anon_vma *root = NULL;
96008@@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
96009 * the corresponding VMA in the parent process is attached to.
96010 * Returns 0 on success, non-zero on failure.
96011 */
96012-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
96013+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
96014 {
96015 struct anon_vma_chain *avc;
96016 struct anon_vma *anon_vma;
96017@@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
96018 void __init anon_vma_init(void)
96019 {
96020 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
96021- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
96022- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
96023+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
96024+ anon_vma_ctor);
96025+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
96026+ SLAB_PANIC|SLAB_NO_SANITIZE);
96027 }
96028
96029 /*
96030diff --git a/mm/shmem.c b/mm/shmem.c
96031index a731cef..1e82984 100644
96032--- a/mm/shmem.c
96033+++ b/mm/shmem.c
96034@@ -33,7 +33,7 @@
96035 #include <linux/swap.h>
96036 #include <linux/aio.h>
96037
96038-static struct vfsmount *shm_mnt;
96039+struct vfsmount *shm_mnt;
96040
96041 #ifdef CONFIG_SHMEM
96042 /*
96043@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
96044 #define BOGO_DIRENT_SIZE 20
96045
96046 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
96047-#define SHORT_SYMLINK_LEN 128
96048+#define SHORT_SYMLINK_LEN 64
96049
96050 /*
96051 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
96052@@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
96053 static int shmem_xattr_validate(const char *name)
96054 {
96055 struct { const char *prefix; size_t len; } arr[] = {
96056+
96057+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96058+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
96059+#endif
96060+
96061 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
96062 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
96063 };
96064@@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
96065 if (err)
96066 return err;
96067
96068+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96069+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
96070+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
96071+ return -EOPNOTSUPP;
96072+ if (size > 8)
96073+ return -EINVAL;
96074+ }
96075+#endif
96076+
96077 return simple_xattr_set(&info->xattrs, name, value, size, flags);
96078 }
96079
96080@@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
96081 int err = -ENOMEM;
96082
96083 /* Round up to L1_CACHE_BYTES to resist false sharing */
96084- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
96085- L1_CACHE_BYTES), GFP_KERNEL);
96086+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
96087 if (!sbinfo)
96088 return -ENOMEM;
96089
96090diff --git a/mm/slab.c b/mm/slab.c
96091index 9432556..e0dc685 100644
96092--- a/mm/slab.c
96093+++ b/mm/slab.c
96094@@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96095 if ((x)->max_freeable < i) \
96096 (x)->max_freeable = i; \
96097 } while (0)
96098-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
96099-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
96100-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
96101-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
96102+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
96103+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
96104+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
96105+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
96106+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
96107+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
96108 #else
96109 #define STATS_INC_ACTIVE(x) do { } while (0)
96110 #define STATS_DEC_ACTIVE(x) do { } while (0)
96111@@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96112 #define STATS_INC_ALLOCMISS(x) do { } while (0)
96113 #define STATS_INC_FREEHIT(x) do { } while (0)
96114 #define STATS_INC_FREEMISS(x) do { } while (0)
96115+#define STATS_INC_SANITIZED(x) do { } while (0)
96116+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
96117 #endif
96118
96119 #if DEBUG
96120@@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
96121 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
96122 */
96123 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
96124- const struct page *page, void *obj)
96125+ const struct page *page, const void *obj)
96126 {
96127 u32 offset = (obj - page->s_mem);
96128 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
96129@@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
96130 */
96131
96132 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
96133- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
96134+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96135
96136 if (INDEX_AC != INDEX_NODE)
96137 kmalloc_caches[INDEX_NODE] =
96138 create_kmalloc_cache("kmalloc-node",
96139- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
96140+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96141
96142 slab_early_init = 0;
96143
96144@@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
96145 struct array_cache *ac = cpu_cache_get(cachep);
96146
96147 check_irq_off();
96148+
96149+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96150+ if (pax_sanitize_slab) {
96151+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
96152+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
96153+
96154+ if (cachep->ctor)
96155+ cachep->ctor(objp);
96156+
96157+ STATS_INC_SANITIZED(cachep);
96158+ } else
96159+ STATS_INC_NOT_SANITIZED(cachep);
96160+ }
96161+#endif
96162+
96163 kmemleak_free_recursive(objp, cachep->flags);
96164 objp = cache_free_debugcheck(cachep, objp, caller);
96165
96166@@ -3748,6 +3767,7 @@ void kfree(const void *objp)
96167
96168 if (unlikely(ZERO_OR_NULL_PTR(objp)))
96169 return;
96170+ VM_BUG_ON(!virt_addr_valid(objp));
96171 local_irq_save(flags);
96172 kfree_debugcheck(objp);
96173 c = virt_to_cache(objp);
96174@@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
96175 }
96176 /* cpu stats */
96177 {
96178- unsigned long allochit = atomic_read(&cachep->allochit);
96179- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
96180- unsigned long freehit = atomic_read(&cachep->freehit);
96181- unsigned long freemiss = atomic_read(&cachep->freemiss);
96182+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
96183+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
96184+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
96185+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
96186
96187 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
96188 allochit, allocmiss, freehit, freemiss);
96189 }
96190+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96191+ {
96192+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
96193+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
96194+
96195+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
96196+ }
96197+#endif
96198 #endif
96199 }
96200
96201@@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
96202 static int __init slab_proc_init(void)
96203 {
96204 #ifdef CONFIG_DEBUG_SLAB_LEAK
96205- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
96206+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
96207 #endif
96208 return 0;
96209 }
96210 module_init(slab_proc_init);
96211 #endif
96212
96213+bool is_usercopy_object(const void *ptr)
96214+{
96215+ struct page *page;
96216+ struct kmem_cache *cachep;
96217+
96218+ if (ZERO_OR_NULL_PTR(ptr))
96219+ return false;
96220+
96221+ if (!slab_is_available())
96222+ return false;
96223+
96224+ if (!virt_addr_valid(ptr))
96225+ return false;
96226+
96227+ page = virt_to_head_page(ptr);
96228+
96229+ if (!PageSlab(page))
96230+ return false;
96231+
96232+ cachep = page->slab_cache;
96233+ return cachep->flags & SLAB_USERCOPY;
96234+}
96235+
96236+#ifdef CONFIG_PAX_USERCOPY
96237+const char *check_heap_object(const void *ptr, unsigned long n)
96238+{
96239+ struct page *page;
96240+ struct kmem_cache *cachep;
96241+ unsigned int objnr;
96242+ unsigned long offset;
96243+
96244+ if (ZERO_OR_NULL_PTR(ptr))
96245+ return "<null>";
96246+
96247+ if (!virt_addr_valid(ptr))
96248+ return NULL;
96249+
96250+ page = virt_to_head_page(ptr);
96251+
96252+ if (!PageSlab(page))
96253+ return NULL;
96254+
96255+ cachep = page->slab_cache;
96256+ if (!(cachep->flags & SLAB_USERCOPY))
96257+ return cachep->name;
96258+
96259+ objnr = obj_to_index(cachep, page, ptr);
96260+ BUG_ON(objnr >= cachep->num);
96261+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
96262+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
96263+ return NULL;
96264+
96265+ return cachep->name;
96266+}
96267+#endif
96268+
96269 /**
96270 * ksize - get the actual amount of memory allocated for a given object
96271 * @objp: Pointer to the object
96272diff --git a/mm/slab.h b/mm/slab.h
96273index 6bd4c35..97565a1 100644
96274--- a/mm/slab.h
96275+++ b/mm/slab.h
96276@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
96277 /* The slab cache that manages slab cache information */
96278 extern struct kmem_cache *kmem_cache;
96279
96280+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96281+#ifdef CONFIG_X86_64
96282+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
96283+#else
96284+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
96285+#endif
96286+extern bool pax_sanitize_slab;
96287+#endif
96288+
96289 unsigned long calculate_alignment(unsigned long flags,
96290 unsigned long align, unsigned long size);
96291
96292@@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96293
96294 /* Legal flag mask for kmem_cache_create(), for various configurations */
96295 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
96296- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
96297+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
96298+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
96299
96300 #if defined(CONFIG_DEBUG_SLAB)
96301 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
96302@@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
96303 return s;
96304
96305 page = virt_to_head_page(x);
96306+
96307+ BUG_ON(!PageSlab(page));
96308+
96309 cachep = page->slab_cache;
96310 if (slab_equal_or_root(cachep, s))
96311 return cachep;
96312diff --git a/mm/slab_common.c b/mm/slab_common.c
96313index b810fba..ae882bf 100644
96314--- a/mm/slab_common.c
96315+++ b/mm/slab_common.c
96316@@ -23,11 +23,22 @@
96317
96318 #include "slab.h"
96319
96320-enum slab_state slab_state;
96321+enum slab_state slab_state __read_only;
96322 LIST_HEAD(slab_caches);
96323 DEFINE_MUTEX(slab_mutex);
96324 struct kmem_cache *kmem_cache;
96325
96326+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96327+bool pax_sanitize_slab __read_only = true;
96328+static int __init pax_sanitize_slab_setup(char *str)
96329+{
96330+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
96331+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
96332+ return 1;
96333+}
96334+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
96335+#endif
96336+
96337 #ifdef CONFIG_DEBUG_VM
96338 static int kmem_cache_sanity_check(const char *name, size_t size)
96339 {
96340@@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
96341 if (err)
96342 goto out_free_cache;
96343
96344- s->refcount = 1;
96345+ atomic_set(&s->refcount, 1);
96346 list_add(&s->list, &slab_caches);
96347 memcg_register_cache(s);
96348 out:
96349@@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96350 get_online_cpus();
96351 mutex_lock(&slab_mutex);
96352
96353- s->refcount--;
96354- if (s->refcount)
96355+ if (!atomic_dec_and_test(&s->refcount))
96356 goto out_unlock;
96357
96358 if (kmem_cache_destroy_memcg_children(s) != 0)
96359@@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96360 rcu_barrier();
96361
96362 memcg_free_cache_params(s);
96363-#ifdef SLAB_SUPPORTS_SYSFS
96364+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96365 sysfs_slab_remove(s);
96366 #else
96367 slab_kmem_cache_release(s);
96368@@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
96369 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
96370 name, size, err);
96371
96372- s->refcount = -1; /* Exempt from merging for now */
96373+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
96374 }
96375
96376 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96377@@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96378
96379 create_boot_cache(s, name, size, flags);
96380 list_add(&s->list, &slab_caches);
96381- s->refcount = 1;
96382+ atomic_set(&s->refcount, 1);
96383 return s;
96384 }
96385
96386@@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96387 EXPORT_SYMBOL(kmalloc_dma_caches);
96388 #endif
96389
96390+#ifdef CONFIG_PAX_USERCOPY_SLABS
96391+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96392+EXPORT_SYMBOL(kmalloc_usercopy_caches);
96393+#endif
96394+
96395 /*
96396 * Conversion table for small slabs sizes / 8 to the index in the
96397 * kmalloc array. This is necessary for slabs < 192 since we have non power
96398@@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96399 return kmalloc_dma_caches[index];
96400
96401 #endif
96402+
96403+#ifdef CONFIG_PAX_USERCOPY_SLABS
96404+ if (unlikely((flags & GFP_USERCOPY)))
96405+ return kmalloc_usercopy_caches[index];
96406+
96407+#endif
96408+
96409 return kmalloc_caches[index];
96410 }
96411
96412@@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96413 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96414 if (!kmalloc_caches[i]) {
96415 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96416- 1 << i, flags);
96417+ 1 << i, SLAB_USERCOPY | flags);
96418 }
96419
96420 /*
96421@@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96422 * earlier power of two caches
96423 */
96424 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96425- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96426+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96427
96428 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96429- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96430+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96431 }
96432
96433 /* Kmalloc array is now usable */
96434@@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96435 }
96436 }
96437 #endif
96438+
96439+#ifdef CONFIG_PAX_USERCOPY_SLABS
96440+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96441+ struct kmem_cache *s = kmalloc_caches[i];
96442+
96443+ if (s) {
96444+ int size = kmalloc_size(i);
96445+ char *n = kasprintf(GFP_NOWAIT,
96446+ "usercopy-kmalloc-%d", size);
96447+
96448+ BUG_ON(!n);
96449+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96450+ size, SLAB_USERCOPY | flags);
96451+ }
96452+ }
96453+#endif
96454+
96455 }
96456 #endif /* !CONFIG_SLOB */
96457
96458@@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96459 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96460 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96461 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96462+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96463+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
96464+#endif
96465 #endif
96466 seq_putc(m, '\n');
96467 }
96468diff --git a/mm/slob.c b/mm/slob.c
96469index 730cad4..8cfd442 100644
96470--- a/mm/slob.c
96471+++ b/mm/slob.c
96472@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96473 /*
96474 * Return the size of a slob block.
96475 */
96476-static slobidx_t slob_units(slob_t *s)
96477+static slobidx_t slob_units(const slob_t *s)
96478 {
96479 if (s->units > 0)
96480 return s->units;
96481@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96482 /*
96483 * Return the next free slob block pointer after this one.
96484 */
96485-static slob_t *slob_next(slob_t *s)
96486+static slob_t *slob_next(const slob_t *s)
96487 {
96488 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96489 slobidx_t next;
96490@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96491 /*
96492 * Returns true if s is the last free block in its page.
96493 */
96494-static int slob_last(slob_t *s)
96495+static int slob_last(const slob_t *s)
96496 {
96497 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96498 }
96499
96500-static void *slob_new_pages(gfp_t gfp, int order, int node)
96501+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96502 {
96503- void *page;
96504+ struct page *page;
96505
96506 #ifdef CONFIG_NUMA
96507 if (node != NUMA_NO_NODE)
96508@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96509 if (!page)
96510 return NULL;
96511
96512- return page_address(page);
96513+ __SetPageSlab(page);
96514+ return page;
96515 }
96516
96517-static void slob_free_pages(void *b, int order)
96518+static void slob_free_pages(struct page *sp, int order)
96519 {
96520 if (current->reclaim_state)
96521 current->reclaim_state->reclaimed_slab += 1 << order;
96522- free_pages((unsigned long)b, order);
96523+ __ClearPageSlab(sp);
96524+ page_mapcount_reset(sp);
96525+ sp->private = 0;
96526+ __free_pages(sp, order);
96527 }
96528
96529 /*
96530@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96531
96532 /* Not enough space: must allocate a new page */
96533 if (!b) {
96534- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96535- if (!b)
96536+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96537+ if (!sp)
96538 return NULL;
96539- sp = virt_to_page(b);
96540- __SetPageSlab(sp);
96541+ b = page_address(sp);
96542
96543 spin_lock_irqsave(&slob_lock, flags);
96544 sp->units = SLOB_UNITS(PAGE_SIZE);
96545 sp->freelist = b;
96546+ sp->private = 0;
96547 INIT_LIST_HEAD(&sp->lru);
96548 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96549 set_slob_page_free(sp, slob_list);
96550@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96551 if (slob_page_free(sp))
96552 clear_slob_page_free(sp);
96553 spin_unlock_irqrestore(&slob_lock, flags);
96554- __ClearPageSlab(sp);
96555- page_mapcount_reset(sp);
96556- slob_free_pages(b, 0);
96557+ slob_free_pages(sp, 0);
96558 return;
96559 }
96560
96561+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96562+ if (pax_sanitize_slab)
96563+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96564+#endif
96565+
96566 if (!slob_page_free(sp)) {
96567 /* This slob page is about to become partially free. Easy! */
96568 sp->units = units;
96569@@ -424,11 +431,10 @@ out:
96570 */
96571
96572 static __always_inline void *
96573-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96574+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96575 {
96576- unsigned int *m;
96577- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96578- void *ret;
96579+ slob_t *m;
96580+ void *ret = NULL;
96581
96582 gfp &= gfp_allowed_mask;
96583
96584@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96585
96586 if (!m)
96587 return NULL;
96588- *m = size;
96589+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96590+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96591+ m[0].units = size;
96592+ m[1].units = align;
96593 ret = (void *)m + align;
96594
96595 trace_kmalloc_node(caller, ret,
96596 size, size + align, gfp, node);
96597 } else {
96598 unsigned int order = get_order(size);
96599+ struct page *page;
96600
96601 if (likely(order))
96602 gfp |= __GFP_COMP;
96603- ret = slob_new_pages(gfp, order, node);
96604+ page = slob_new_pages(gfp, order, node);
96605+ if (page) {
96606+ ret = page_address(page);
96607+ page->private = size;
96608+ }
96609
96610 trace_kmalloc_node(caller, ret,
96611 size, PAGE_SIZE << order, gfp, node);
96612 }
96613
96614- kmemleak_alloc(ret, size, 1, gfp);
96615+ return ret;
96616+}
96617+
96618+static __always_inline void *
96619+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96620+{
96621+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96622+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96623+
96624+ if (!ZERO_OR_NULL_PTR(ret))
96625+ kmemleak_alloc(ret, size, 1, gfp);
96626 return ret;
96627 }
96628
96629@@ -493,34 +517,112 @@ void kfree(const void *block)
96630 return;
96631 kmemleak_free(block);
96632
96633+ VM_BUG_ON(!virt_addr_valid(block));
96634 sp = virt_to_page(block);
96635- if (PageSlab(sp)) {
96636+ VM_BUG_ON(!PageSlab(sp));
96637+ if (!sp->private) {
96638 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96639- unsigned int *m = (unsigned int *)(block - align);
96640- slob_free(m, *m + align);
96641- } else
96642+ slob_t *m = (slob_t *)(block - align);
96643+ slob_free(m, m[0].units + align);
96644+ } else {
96645+ __ClearPageSlab(sp);
96646+ page_mapcount_reset(sp);
96647+ sp->private = 0;
96648 __free_pages(sp, compound_order(sp));
96649+ }
96650 }
96651 EXPORT_SYMBOL(kfree);
96652
96653+bool is_usercopy_object(const void *ptr)
96654+{
96655+ if (!slab_is_available())
96656+ return false;
96657+
96658+ // PAX: TODO
96659+
96660+ return false;
96661+}
96662+
96663+#ifdef CONFIG_PAX_USERCOPY
96664+const char *check_heap_object(const void *ptr, unsigned long n)
96665+{
96666+ struct page *page;
96667+ const slob_t *free;
96668+ const void *base;
96669+ unsigned long flags;
96670+
96671+ if (ZERO_OR_NULL_PTR(ptr))
96672+ return "<null>";
96673+
96674+ if (!virt_addr_valid(ptr))
96675+ return NULL;
96676+
96677+ page = virt_to_head_page(ptr);
96678+ if (!PageSlab(page))
96679+ return NULL;
96680+
96681+ if (page->private) {
96682+ base = page;
96683+ if (base <= ptr && n <= page->private - (ptr - base))
96684+ return NULL;
96685+ return "<slob>";
96686+ }
96687+
96688+ /* some tricky double walking to find the chunk */
96689+ spin_lock_irqsave(&slob_lock, flags);
96690+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96691+ free = page->freelist;
96692+
96693+ while (!slob_last(free) && (void *)free <= ptr) {
96694+ base = free + slob_units(free);
96695+ free = slob_next(free);
96696+ }
96697+
96698+ while (base < (void *)free) {
96699+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96700+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96701+ int offset;
96702+
96703+ if (ptr < base + align)
96704+ break;
96705+
96706+ offset = ptr - base - align;
96707+ if (offset >= m) {
96708+ base += size;
96709+ continue;
96710+ }
96711+
96712+ if (n > m - offset)
96713+ break;
96714+
96715+ spin_unlock_irqrestore(&slob_lock, flags);
96716+ return NULL;
96717+ }
96718+
96719+ spin_unlock_irqrestore(&slob_lock, flags);
96720+ return "<slob>";
96721+}
96722+#endif
96723+
96724 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96725 size_t ksize(const void *block)
96726 {
96727 struct page *sp;
96728 int align;
96729- unsigned int *m;
96730+ slob_t *m;
96731
96732 BUG_ON(!block);
96733 if (unlikely(block == ZERO_SIZE_PTR))
96734 return 0;
96735
96736 sp = virt_to_page(block);
96737- if (unlikely(!PageSlab(sp)))
96738- return PAGE_SIZE << compound_order(sp);
96739+ VM_BUG_ON(!PageSlab(sp));
96740+ if (sp->private)
96741+ return sp->private;
96742
96743 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96744- m = (unsigned int *)(block - align);
96745- return SLOB_UNITS(*m) * SLOB_UNIT;
96746+ m = (slob_t *)(block - align);
96747+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96748 }
96749 EXPORT_SYMBOL(ksize);
96750
96751@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96752
96753 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96754 {
96755- void *b;
96756+ void *b = NULL;
96757
96758 flags &= gfp_allowed_mask;
96759
96760 lockdep_trace_alloc(flags);
96761
96762+#ifdef CONFIG_PAX_USERCOPY_SLABS
96763+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96764+#else
96765 if (c->size < PAGE_SIZE) {
96766 b = slob_alloc(c->size, flags, c->align, node);
96767 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96768 SLOB_UNITS(c->size) * SLOB_UNIT,
96769 flags, node);
96770 } else {
96771- b = slob_new_pages(flags, get_order(c->size), node);
96772+ struct page *sp;
96773+
96774+ sp = slob_new_pages(flags, get_order(c->size), node);
96775+ if (sp) {
96776+ b = page_address(sp);
96777+ sp->private = c->size;
96778+ }
96779 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96780 PAGE_SIZE << get_order(c->size),
96781 flags, node);
96782 }
96783+#endif
96784
96785 if (b && c->ctor)
96786 c->ctor(b);
96787@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96788
96789 static void __kmem_cache_free(void *b, int size)
96790 {
96791- if (size < PAGE_SIZE)
96792+ struct page *sp;
96793+
96794+ sp = virt_to_page(b);
96795+ BUG_ON(!PageSlab(sp));
96796+ if (!sp->private)
96797 slob_free(b, size);
96798 else
96799- slob_free_pages(b, get_order(size));
96800+ slob_free_pages(sp, get_order(size));
96801 }
96802
96803 static void kmem_rcu_free(struct rcu_head *head)
96804@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96805
96806 void kmem_cache_free(struct kmem_cache *c, void *b)
96807 {
96808+ int size = c->size;
96809+
96810+#ifdef CONFIG_PAX_USERCOPY_SLABS
96811+ if (size + c->align < PAGE_SIZE) {
96812+ size += c->align;
96813+ b -= c->align;
96814+ }
96815+#endif
96816+
96817 kmemleak_free_recursive(b, c->flags);
96818 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96819 struct slob_rcu *slob_rcu;
96820- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96821- slob_rcu->size = c->size;
96822+ slob_rcu = b + (size - sizeof(struct slob_rcu));
96823+ slob_rcu->size = size;
96824 call_rcu(&slob_rcu->head, kmem_rcu_free);
96825 } else {
96826- __kmem_cache_free(b, c->size);
96827+ __kmem_cache_free(b, size);
96828 }
96829
96830+#ifdef CONFIG_PAX_USERCOPY_SLABS
96831+ trace_kfree(_RET_IP_, b);
96832+#else
96833 trace_kmem_cache_free(_RET_IP_, b);
96834+#endif
96835+
96836 }
96837 EXPORT_SYMBOL(kmem_cache_free);
96838
96839diff --git a/mm/slub.c b/mm/slub.c
96840index 2b1ce69..4a2193f 100644
96841--- a/mm/slub.c
96842+++ b/mm/slub.c
96843@@ -207,7 +207,7 @@ struct track {
96844
96845 enum track_item { TRACK_ALLOC, TRACK_FREE };
96846
96847-#ifdef CONFIG_SYSFS
96848+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96849 static int sysfs_slab_add(struct kmem_cache *);
96850 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96851 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
96852@@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
96853 if (!t->addr)
96854 return;
96855
96856- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96857+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96858 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96859 #ifdef CONFIG_STACKTRACE
96860 {
96861@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96862
96863 slab_free_hook(s, x);
96864
96865+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96866+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96867+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96868+ if (s->ctor)
96869+ s->ctor(x);
96870+ }
96871+#endif
96872+
96873 redo:
96874 /*
96875 * Determine the currently cpus per cpu slab.
96876@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96877 * Merge control. If this is set then no merging of slab caches will occur.
96878 * (Could be removed. This was introduced to pacify the merge skeptics.)
96879 */
96880-static int slub_nomerge;
96881+static int slub_nomerge = 1;
96882
96883 /*
96884 * Calculate the order of allocation given an slab object size.
96885@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96886 s->inuse = size;
96887
96888 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96889+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96890+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96891+#endif
96892 s->ctor)) {
96893 /*
96894 * Relocate free pointer after the object if it is not
96895@@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96896 EXPORT_SYMBOL(__kmalloc_node);
96897 #endif
96898
96899+bool is_usercopy_object(const void *ptr)
96900+{
96901+ struct page *page;
96902+ struct kmem_cache *s;
96903+
96904+ if (ZERO_OR_NULL_PTR(ptr))
96905+ return false;
96906+
96907+ if (!slab_is_available())
96908+ return false;
96909+
96910+ if (!virt_addr_valid(ptr))
96911+ return false;
96912+
96913+ page = virt_to_head_page(ptr);
96914+
96915+ if (!PageSlab(page))
96916+ return false;
96917+
96918+ s = page->slab_cache;
96919+ return s->flags & SLAB_USERCOPY;
96920+}
96921+
96922+#ifdef CONFIG_PAX_USERCOPY
96923+const char *check_heap_object(const void *ptr, unsigned long n)
96924+{
96925+ struct page *page;
96926+ struct kmem_cache *s;
96927+ unsigned long offset;
96928+
96929+ if (ZERO_OR_NULL_PTR(ptr))
96930+ return "<null>";
96931+
96932+ if (!virt_addr_valid(ptr))
96933+ return NULL;
96934+
96935+ page = virt_to_head_page(ptr);
96936+
96937+ if (!PageSlab(page))
96938+ return NULL;
96939+
96940+ s = page->slab_cache;
96941+ if (!(s->flags & SLAB_USERCOPY))
96942+ return s->name;
96943+
96944+ offset = (ptr - page_address(page)) % s->size;
96945+ if (offset <= s->object_size && n <= s->object_size - offset)
96946+ return NULL;
96947+
96948+ return s->name;
96949+}
96950+#endif
96951+
96952 size_t ksize(const void *object)
96953 {
96954 struct page *page;
96955@@ -3371,6 +3435,7 @@ void kfree(const void *x)
96956 if (unlikely(ZERO_OR_NULL_PTR(x)))
96957 return;
96958
96959+ VM_BUG_ON(!virt_addr_valid(x));
96960 page = virt_to_head_page(x);
96961 if (unlikely(!PageSlab(page))) {
96962 BUG_ON(!PageCompound(page));
96963@@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96964 /*
96965 * We may have set a slab to be unmergeable during bootstrap.
96966 */
96967- if (s->refcount < 0)
96968+ if (atomic_read(&s->refcount) < 0)
96969 return 1;
96970
96971 return 0;
96972@@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96973 int i;
96974 struct kmem_cache *c;
96975
96976- s->refcount++;
96977+ atomic_inc(&s->refcount);
96978
96979 /*
96980 * Adjust the object sizes so that we clear
96981@@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96982 }
96983
96984 if (sysfs_slab_alias(s, name)) {
96985- s->refcount--;
96986+ atomic_dec(&s->refcount);
96987 s = NULL;
96988 }
96989 }
96990@@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96991 }
96992 #endif
96993
96994-#ifdef CONFIG_SYSFS
96995+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96996 static int count_inuse(struct page *page)
96997 {
96998 return page->inuse;
96999@@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
97000 len += sprintf(buf + len, "%7ld ", l->count);
97001
97002 if (l->addr)
97003+#ifdef CONFIG_GRKERNSEC_HIDESYM
97004+ len += sprintf(buf + len, "%pS", NULL);
97005+#else
97006 len += sprintf(buf + len, "%pS", (void *)l->addr);
97007+#endif
97008 else
97009 len += sprintf(buf + len, "<not-available>");
97010
97011@@ -4261,12 +4330,12 @@ static void resiliency_test(void)
97012 validate_slab_cache(kmalloc_caches[9]);
97013 }
97014 #else
97015-#ifdef CONFIG_SYSFS
97016+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97017 static void resiliency_test(void) {};
97018 #endif
97019 #endif
97020
97021-#ifdef CONFIG_SYSFS
97022+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97023 enum slab_stat_type {
97024 SL_ALL, /* All slabs */
97025 SL_PARTIAL, /* Only partially allocated slabs */
97026@@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
97027 {
97028 if (!s->ctor)
97029 return 0;
97030+#ifdef CONFIG_GRKERNSEC_HIDESYM
97031+ return sprintf(buf, "%pS\n", NULL);
97032+#else
97033 return sprintf(buf, "%pS\n", s->ctor);
97034+#endif
97035 }
97036 SLAB_ATTR_RO(ctor);
97037
97038 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
97039 {
97040- return sprintf(buf, "%d\n", s->refcount - 1);
97041+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
97042 }
97043 SLAB_ATTR_RO(aliases);
97044
97045@@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
97046 SLAB_ATTR_RO(cache_dma);
97047 #endif
97048
97049+#ifdef CONFIG_PAX_USERCOPY_SLABS
97050+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
97051+{
97052+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
97053+}
97054+SLAB_ATTR_RO(usercopy);
97055+#endif
97056+
97057 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
97058 {
97059 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
97060@@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
97061 #ifdef CONFIG_ZONE_DMA
97062 &cache_dma_attr.attr,
97063 #endif
97064+#ifdef CONFIG_PAX_USERCOPY_SLABS
97065+ &usercopy_attr.attr,
97066+#endif
97067 #ifdef CONFIG_NUMA
97068 &remote_node_defrag_ratio_attr.attr,
97069 #endif
97070@@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
97071 return name;
97072 }
97073
97074+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97075 static int sysfs_slab_add(struct kmem_cache *s)
97076 {
97077 int err;
97078@@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
97079 kobject_del(&s->kobj);
97080 kobject_put(&s->kobj);
97081 }
97082+#endif
97083
97084 /*
97085 * Need to buffer aliases during bootup until sysfs becomes
97086@@ -5270,6 +5356,7 @@ struct saved_alias {
97087
97088 static struct saved_alias *alias_list;
97089
97090+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97091 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97092 {
97093 struct saved_alias *al;
97094@@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97095 alias_list = al;
97096 return 0;
97097 }
97098+#endif
97099
97100 static int __init slab_sysfs_init(void)
97101 {
97102diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
97103index 4cba9c2..b4f9fcc 100644
97104--- a/mm/sparse-vmemmap.c
97105+++ b/mm/sparse-vmemmap.c
97106@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
97107 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97108 if (!p)
97109 return NULL;
97110- pud_populate(&init_mm, pud, p);
97111+ pud_populate_kernel(&init_mm, pud, p);
97112 }
97113 return pud;
97114 }
97115@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
97116 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97117 if (!p)
97118 return NULL;
97119- pgd_populate(&init_mm, pgd, p);
97120+ pgd_populate_kernel(&init_mm, pgd, p);
97121 }
97122 return pgd;
97123 }
97124diff --git a/mm/sparse.c b/mm/sparse.c
97125index d1b48b6..6e8590e 100644
97126--- a/mm/sparse.c
97127+++ b/mm/sparse.c
97128@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
97129
97130 for (i = 0; i < PAGES_PER_SECTION; i++) {
97131 if (PageHWPoison(&memmap[i])) {
97132- atomic_long_sub(1, &num_poisoned_pages);
97133+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
97134 ClearPageHWPoison(&memmap[i]);
97135 }
97136 }
97137diff --git a/mm/swap.c b/mm/swap.c
97138index 9ce43ba..43bdc4c 100644
97139--- a/mm/swap.c
97140+++ b/mm/swap.c
97141@@ -31,6 +31,7 @@
97142 #include <linux/memcontrol.h>
97143 #include <linux/gfp.h>
97144 #include <linux/uio.h>
97145+#include <linux/hugetlb.h>
97146
97147 #include "internal.h"
97148
97149@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
97150
97151 __page_cache_release(page);
97152 dtor = get_compound_page_dtor(page);
97153+ if (!PageHuge(page))
97154+ BUG_ON(dtor != free_compound_page);
97155 (*dtor)(page);
97156 }
97157
97158diff --git a/mm/swapfile.c b/mm/swapfile.c
97159index 4a7f7e6..22cddf5 100644
97160--- a/mm/swapfile.c
97161+++ b/mm/swapfile.c
97162@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
97163
97164 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
97165 /* Activity counter to indicate that a swapon or swapoff has occurred */
97166-static atomic_t proc_poll_event = ATOMIC_INIT(0);
97167+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
97168
97169 static inline unsigned char swap_count(unsigned char ent)
97170 {
97171@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
97172 spin_unlock(&swap_lock);
97173
97174 err = 0;
97175- atomic_inc(&proc_poll_event);
97176+ atomic_inc_unchecked(&proc_poll_event);
97177 wake_up_interruptible(&proc_poll_wait);
97178
97179 out_dput:
97180@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
97181
97182 poll_wait(file, &proc_poll_wait, wait);
97183
97184- if (seq->poll_event != atomic_read(&proc_poll_event)) {
97185- seq->poll_event = atomic_read(&proc_poll_event);
97186+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
97187+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97188 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
97189 }
97190
97191@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
97192 return ret;
97193
97194 seq = file->private_data;
97195- seq->poll_event = atomic_read(&proc_poll_event);
97196+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97197 return 0;
97198 }
97199
97200@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
97201 (frontswap_map) ? "FS" : "");
97202
97203 mutex_unlock(&swapon_mutex);
97204- atomic_inc(&proc_poll_event);
97205+ atomic_inc_unchecked(&proc_poll_event);
97206 wake_up_interruptible(&proc_poll_wait);
97207
97208 if (S_ISREG(inode->i_mode))
97209diff --git a/mm/util.c b/mm/util.c
97210index d5ea733..e8953f9 100644
97211--- a/mm/util.c
97212+++ b/mm/util.c
97213@@ -299,6 +299,12 @@ done:
97214 void arch_pick_mmap_layout(struct mm_struct *mm)
97215 {
97216 mm->mmap_base = TASK_UNMAPPED_BASE;
97217+
97218+#ifdef CONFIG_PAX_RANDMMAP
97219+ if (mm->pax_flags & MF_PAX_RANDMMAP)
97220+ mm->mmap_base += mm->delta_mmap;
97221+#endif
97222+
97223 mm->get_unmapped_area = arch_get_unmapped_area;
97224 }
97225 #endif
97226@@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
97227 if (!mm->arg_end)
97228 goto out_mm; /* Shh! No looking before we're done */
97229
97230+ if (gr_acl_handle_procpidmem(task))
97231+ goto out_mm;
97232+
97233 len = mm->arg_end - mm->arg_start;
97234
97235 if (len > buflen)
97236diff --git a/mm/vmalloc.c b/mm/vmalloc.c
97237index bf233b2..1dfa1bc 100644
97238--- a/mm/vmalloc.c
97239+++ b/mm/vmalloc.c
97240@@ -40,6 +40,21 @@ struct vfree_deferred {
97241 };
97242 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
97243
97244+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97245+struct stack_deferred_llist {
97246+ struct llist_head list;
97247+ void *stack;
97248+ void *lowmem_stack;
97249+};
97250+
97251+struct stack_deferred {
97252+ struct stack_deferred_llist list;
97253+ struct work_struct wq;
97254+};
97255+
97256+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
97257+#endif
97258+
97259 static void __vunmap(const void *, int);
97260
97261 static void free_work(struct work_struct *w)
97262@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
97263 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
97264 struct llist_node *llnode = llist_del_all(&p->list);
97265 while (llnode) {
97266- void *p = llnode;
97267+ void *x = llnode;
97268 llnode = llist_next(llnode);
97269- __vunmap(p, 1);
97270+ __vunmap(x, 1);
97271 }
97272 }
97273
97274+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97275+static void unmap_work(struct work_struct *w)
97276+{
97277+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
97278+ struct llist_node *llnode = llist_del_all(&p->list.list);
97279+ while (llnode) {
97280+ struct stack_deferred_llist *x =
97281+ llist_entry((struct llist_head *)llnode,
97282+ struct stack_deferred_llist, list);
97283+ void *stack = ACCESS_ONCE(x->stack);
97284+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
97285+ llnode = llist_next(llnode);
97286+ __vunmap(stack, 0);
97287+ free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
97288+ }
97289+}
97290+#endif
97291+
97292 /*** Page table manipulation functions ***/
97293
97294 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97295@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97296
97297 pte = pte_offset_kernel(pmd, addr);
97298 do {
97299- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97300- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97301+
97302+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97303+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
97304+ BUG_ON(!pte_exec(*pte));
97305+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
97306+ continue;
97307+ }
97308+#endif
97309+
97310+ {
97311+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97312+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97313+ }
97314 } while (pte++, addr += PAGE_SIZE, addr != end);
97315 }
97316
97317@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
97318 pte = pte_alloc_kernel(pmd, addr);
97319 if (!pte)
97320 return -ENOMEM;
97321+
97322+ pax_open_kernel();
97323 do {
97324 struct page *page = pages[*nr];
97325
97326- if (WARN_ON(!pte_none(*pte)))
97327+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97328+ if (pgprot_val(prot) & _PAGE_NX)
97329+#endif
97330+
97331+ if (!pte_none(*pte)) {
97332+ pax_close_kernel();
97333+ WARN_ON(1);
97334 return -EBUSY;
97335- if (WARN_ON(!page))
97336+ }
97337+ if (!page) {
97338+ pax_close_kernel();
97339+ WARN_ON(1);
97340 return -ENOMEM;
97341+ }
97342 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
97343 (*nr)++;
97344 } while (pte++, addr += PAGE_SIZE, addr != end);
97345+ pax_close_kernel();
97346 return 0;
97347 }
97348
97349@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
97350 pmd_t *pmd;
97351 unsigned long next;
97352
97353- pmd = pmd_alloc(&init_mm, pud, addr);
97354+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
97355 if (!pmd)
97356 return -ENOMEM;
97357 do {
97358@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
97359 pud_t *pud;
97360 unsigned long next;
97361
97362- pud = pud_alloc(&init_mm, pgd, addr);
97363+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
97364 if (!pud)
97365 return -ENOMEM;
97366 do {
97367@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
97368 if (addr >= MODULES_VADDR && addr < MODULES_END)
97369 return 1;
97370 #endif
97371+
97372+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97373+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
97374+ return 1;
97375+#endif
97376+
97377 return is_vmalloc_addr(x);
97378 }
97379
97380@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
97381
97382 if (!pgd_none(*pgd)) {
97383 pud_t *pud = pud_offset(pgd, addr);
97384+#ifdef CONFIG_X86
97385+ if (!pud_large(*pud))
97386+#endif
97387 if (!pud_none(*pud)) {
97388 pmd_t *pmd = pmd_offset(pud, addr);
97389+#ifdef CONFIG_X86
97390+ if (!pmd_large(*pmd))
97391+#endif
97392 if (!pmd_none(*pmd)) {
97393 pte_t *ptep, pte;
97394
97395@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
97396 for_each_possible_cpu(i) {
97397 struct vmap_block_queue *vbq;
97398 struct vfree_deferred *p;
97399+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97400+ struct stack_deferred *p2;
97401+#endif
97402
97403 vbq = &per_cpu(vmap_block_queue, i);
97404 spin_lock_init(&vbq->lock);
97405 INIT_LIST_HEAD(&vbq->free);
97406+
97407 p = &per_cpu(vfree_deferred, i);
97408 init_llist_head(&p->list);
97409 INIT_WORK(&p->wq, free_work);
97410+
97411+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97412+ p2 = &per_cpu(stack_deferred, i);
97413+ init_llist_head(&p2->list.list);
97414+ INIT_WORK(&p2->wq, unmap_work);
97415+#endif
97416 }
97417
97418 /* Import existing vmlist entries. */
97419@@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97420 struct vm_struct *area;
97421
97422 BUG_ON(in_interrupt());
97423+
97424+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97425+ if (flags & VM_KERNEXEC) {
97426+ if (start != VMALLOC_START || end != VMALLOC_END)
97427+ return NULL;
97428+ start = (unsigned long)MODULES_EXEC_VADDR;
97429+ end = (unsigned long)MODULES_EXEC_END;
97430+ }
97431+#endif
97432+
97433 if (flags & VM_IOREMAP)
97434 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97435
97436@@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
97437 }
97438 EXPORT_SYMBOL(vunmap);
97439
97440+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97441+void unmap_process_stacks(struct task_struct *task)
97442+{
97443+ if (unlikely(in_interrupt())) {
97444+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
97445+ struct stack_deferred_llist *list = task->stack;
97446+ list->stack = task->stack;
97447+ list->lowmem_stack = task->lowmem_stack;
97448+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
97449+ schedule_work(&p->wq);
97450+ } else {
97451+ __vunmap(task->stack, 0);
97452+ free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97453+ }
97454+}
97455+#endif
97456+
97457 /**
97458 * vmap - map an array of pages into virtually contiguous space
97459 * @pages: array of page pointers
97460@@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97461 if (count > totalram_pages)
97462 return NULL;
97463
97464+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97465+ if (!(pgprot_val(prot) & _PAGE_NX))
97466+ flags |= VM_KERNEXEC;
97467+#endif
97468+
97469 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97470 __builtin_return_address(0));
97471 if (!area)
97472@@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97473 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97474 goto fail;
97475
97476+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97477+ if (!(pgprot_val(prot) & _PAGE_NX))
97478+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97479+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97480+ else
97481+#endif
97482+
97483 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97484 start, end, node, gfp_mask, caller);
97485 if (!area)
97486@@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97487 * For tight control over page level allocator and protection flags
97488 * use __vmalloc() instead.
97489 */
97490-
97491 void *vmalloc_exec(unsigned long size)
97492 {
97493- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97494+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97495 NUMA_NO_NODE, __builtin_return_address(0));
97496 }
97497
97498@@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97499 {
97500 struct vm_struct *area;
97501
97502+ BUG_ON(vma->vm_mirror);
97503+
97504 size = PAGE_ALIGN(size);
97505
97506 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97507@@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97508 v->addr, v->addr + v->size, v->size);
97509
97510 if (v->caller)
97511+#ifdef CONFIG_GRKERNSEC_HIDESYM
97512+ seq_printf(m, " %pK", v->caller);
97513+#else
97514 seq_printf(m, " %pS", v->caller);
97515+#endif
97516
97517 if (v->nr_pages)
97518 seq_printf(m, " pages=%d", v->nr_pages);
97519diff --git a/mm/vmstat.c b/mm/vmstat.c
97520index 302dd07..3841f1c 100644
97521--- a/mm/vmstat.c
97522+++ b/mm/vmstat.c
97523@@ -20,6 +20,7 @@
97524 #include <linux/writeback.h>
97525 #include <linux/compaction.h>
97526 #include <linux/mm_inline.h>
97527+#include <linux/grsecurity.h>
97528
97529 #include "internal.h"
97530
97531@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97532 *
97533 * vm_stat contains the global counters
97534 */
97535-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97536+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97537 EXPORT_SYMBOL(vm_stat);
97538
97539 #ifdef CONFIG_SMP
97540@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97541
97542 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97543 if (diff[i])
97544- atomic_long_add(diff[i], &vm_stat[i]);
97545+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97546 }
97547
97548 /*
97549@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97550 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97551 if (v) {
97552
97553- atomic_long_add(v, &zone->vm_stat[i]);
97554+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97555 global_diff[i] += v;
97556 #ifdef CONFIG_NUMA
97557 /* 3 seconds idle till flush */
97558@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97559
97560 v = p->vm_stat_diff[i];
97561 p->vm_stat_diff[i] = 0;
97562- atomic_long_add(v, &zone->vm_stat[i]);
97563+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97564 global_diff[i] += v;
97565 }
97566 }
97567@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97568 if (pset->vm_stat_diff[i]) {
97569 int v = pset->vm_stat_diff[i];
97570 pset->vm_stat_diff[i] = 0;
97571- atomic_long_add(v, &zone->vm_stat[i]);
97572- atomic_long_add(v, &vm_stat[i]);
97573+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97574+ atomic_long_add_unchecked(v, &vm_stat[i]);
97575 }
97576 }
97577 #endif
97578@@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97579 stat_items_size += sizeof(struct vm_event_state);
97580 #endif
97581
97582- v = kmalloc(stat_items_size, GFP_KERNEL);
97583+ v = kzalloc(stat_items_size, GFP_KERNEL);
97584 m->private = v;
97585 if (!v)
97586 return ERR_PTR(-ENOMEM);
97587+
97588+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97589+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97590+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97591+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97592+ && !in_group_p(grsec_proc_gid)
97593+#endif
97594+ )
97595+ return (unsigned long *)m->private + *pos;
97596+#endif
97597+#endif
97598+
97599 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97600 v[i] = global_page_state(i);
97601 v += NR_VM_ZONE_STAT_ITEMS;
97602@@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97603 cpu_notifier_register_done();
97604 #endif
97605 #ifdef CONFIG_PROC_FS
97606- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97607- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97608- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97609- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97610+ {
97611+ mode_t gr_mode = S_IRUGO;
97612+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97613+ gr_mode = S_IRUSR;
97614+#endif
97615+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97616+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97617+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97618+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97619+ }
97620 #endif
97621 return 0;
97622 }
97623diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97624index 44ebd5c..1f732bae 100644
97625--- a/net/8021q/vlan.c
97626+++ b/net/8021q/vlan.c
97627@@ -475,7 +475,7 @@ out:
97628 return NOTIFY_DONE;
97629 }
97630
97631-static struct notifier_block vlan_notifier_block __read_mostly = {
97632+static struct notifier_block vlan_notifier_block = {
97633 .notifier_call = vlan_device_event,
97634 };
97635
97636@@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97637 err = -EPERM;
97638 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97639 break;
97640- if ((args.u.name_type >= 0) &&
97641- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97642+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97643 struct vlan_net *vn;
97644
97645 vn = net_generic(net, vlan_net_id);
97646diff --git a/net/9p/client.c b/net/9p/client.c
97647index 0004cba..feba240 100644
97648--- a/net/9p/client.c
97649+++ b/net/9p/client.c
97650@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97651 len - inline_len);
97652 } else {
97653 err = copy_from_user(ename + inline_len,
97654- uidata, len - inline_len);
97655+ (char __force_user *)uidata, len - inline_len);
97656 if (err) {
97657 err = -EFAULT;
97658 goto out_err;
97659@@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97660 kernel_buf = 1;
97661 indata = data;
97662 } else
97663- indata = (__force char *)udata;
97664+ indata = (__force_kernel char *)udata;
97665 /*
97666 * response header len is 11
97667 * PDU Header(7) + IO Size (4)
97668@@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97669 kernel_buf = 1;
97670 odata = data;
97671 } else
97672- odata = (char *)udata;
97673+ odata = (char __force_kernel *)udata;
97674 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97675 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97676 fid->fid, offset, rsize);
97677diff --git a/net/9p/mod.c b/net/9p/mod.c
97678index 6ab36ae..6f1841b 100644
97679--- a/net/9p/mod.c
97680+++ b/net/9p/mod.c
97681@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97682 void v9fs_register_trans(struct p9_trans_module *m)
97683 {
97684 spin_lock(&v9fs_trans_lock);
97685- list_add_tail(&m->list, &v9fs_trans_list);
97686+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97687 spin_unlock(&v9fs_trans_lock);
97688 }
97689 EXPORT_SYMBOL(v9fs_register_trans);
97690@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97691 void v9fs_unregister_trans(struct p9_trans_module *m)
97692 {
97693 spin_lock(&v9fs_trans_lock);
97694- list_del_init(&m->list);
97695+ pax_list_del_init((struct list_head *)&m->list);
97696 spin_unlock(&v9fs_trans_lock);
97697 }
97698 EXPORT_SYMBOL(v9fs_unregister_trans);
97699diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97700index 80d08f6..de63fd1 100644
97701--- a/net/9p/trans_fd.c
97702+++ b/net/9p/trans_fd.c
97703@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97704 oldfs = get_fs();
97705 set_fs(get_ds());
97706 /* The cast to a user pointer is valid due to the set_fs() */
97707- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97708+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97709 set_fs(oldfs);
97710
97711 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97712diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97713index af46bc4..f9adfcd 100644
97714--- a/net/appletalk/atalk_proc.c
97715+++ b/net/appletalk/atalk_proc.c
97716@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97717 struct proc_dir_entry *p;
97718 int rc = -ENOMEM;
97719
97720- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97721+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97722 if (!atalk_proc_dir)
97723 goto out;
97724
97725diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97726index 876fbe8..8bbea9f 100644
97727--- a/net/atm/atm_misc.c
97728+++ b/net/atm/atm_misc.c
97729@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97730 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97731 return 1;
97732 atm_return(vcc, truesize);
97733- atomic_inc(&vcc->stats->rx_drop);
97734+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97735 return 0;
97736 }
97737 EXPORT_SYMBOL(atm_charge);
97738@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97739 }
97740 }
97741 atm_return(vcc, guess);
97742- atomic_inc(&vcc->stats->rx_drop);
97743+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97744 return NULL;
97745 }
97746 EXPORT_SYMBOL(atm_alloc_charge);
97747@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97748
97749 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97750 {
97751-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97752+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97753 __SONET_ITEMS
97754 #undef __HANDLE_ITEM
97755 }
97756@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97757
97758 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97759 {
97760-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97761+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97762 __SONET_ITEMS
97763 #undef __HANDLE_ITEM
97764 }
97765diff --git a/net/atm/lec.c b/net/atm/lec.c
97766index 4c5b8ba..95f7005 100644
97767--- a/net/atm/lec.c
97768+++ b/net/atm/lec.c
97769@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97770 }
97771
97772 static struct lane2_ops lane2_ops = {
97773- lane2_resolve, /* resolve, spec 3.1.3 */
97774- lane2_associate_req, /* associate_req, spec 3.1.4 */
97775- NULL /* associate indicator, spec 3.1.5 */
97776+ .resolve = lane2_resolve,
97777+ .associate_req = lane2_associate_req,
97778+ .associate_indicator = NULL
97779 };
97780
97781 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97782diff --git a/net/atm/lec.h b/net/atm/lec.h
97783index 4149db1..f2ab682 100644
97784--- a/net/atm/lec.h
97785+++ b/net/atm/lec.h
97786@@ -48,7 +48,7 @@ struct lane2_ops {
97787 const u8 *tlvs, u32 sizeoftlvs);
97788 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97789 const u8 *tlvs, u32 sizeoftlvs);
97790-};
97791+} __no_const;
97792
97793 /*
97794 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97795diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97796index d1b2d9a..d549f7f 100644
97797--- a/net/atm/mpoa_caches.c
97798+++ b/net/atm/mpoa_caches.c
97799@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97800
97801
97802 static struct in_cache_ops ingress_ops = {
97803- in_cache_add_entry, /* add_entry */
97804- in_cache_get, /* get */
97805- in_cache_get_with_mask, /* get_with_mask */
97806- in_cache_get_by_vcc, /* get_by_vcc */
97807- in_cache_put, /* put */
97808- in_cache_remove_entry, /* remove_entry */
97809- cache_hit, /* cache_hit */
97810- clear_count_and_expired, /* clear_count */
97811- check_resolving_entries, /* check_resolving */
97812- refresh_entries, /* refresh */
97813- in_destroy_cache /* destroy_cache */
97814+ .add_entry = in_cache_add_entry,
97815+ .get = in_cache_get,
97816+ .get_with_mask = in_cache_get_with_mask,
97817+ .get_by_vcc = in_cache_get_by_vcc,
97818+ .put = in_cache_put,
97819+ .remove_entry = in_cache_remove_entry,
97820+ .cache_hit = cache_hit,
97821+ .clear_count = clear_count_and_expired,
97822+ .check_resolving = check_resolving_entries,
97823+ .refresh = refresh_entries,
97824+ .destroy_cache = in_destroy_cache
97825 };
97826
97827 static struct eg_cache_ops egress_ops = {
97828- eg_cache_add_entry, /* add_entry */
97829- eg_cache_get_by_cache_id, /* get_by_cache_id */
97830- eg_cache_get_by_tag, /* get_by_tag */
97831- eg_cache_get_by_vcc, /* get_by_vcc */
97832- eg_cache_get_by_src_ip, /* get_by_src_ip */
97833- eg_cache_put, /* put */
97834- eg_cache_remove_entry, /* remove_entry */
97835- update_eg_cache_entry, /* update */
97836- clear_expired, /* clear_expired */
97837- eg_destroy_cache /* destroy_cache */
97838+ .add_entry = eg_cache_add_entry,
97839+ .get_by_cache_id = eg_cache_get_by_cache_id,
97840+ .get_by_tag = eg_cache_get_by_tag,
97841+ .get_by_vcc = eg_cache_get_by_vcc,
97842+ .get_by_src_ip = eg_cache_get_by_src_ip,
97843+ .put = eg_cache_put,
97844+ .remove_entry = eg_cache_remove_entry,
97845+ .update = update_eg_cache_entry,
97846+ .clear_expired = clear_expired,
97847+ .destroy_cache = eg_destroy_cache
97848 };
97849
97850
97851diff --git a/net/atm/proc.c b/net/atm/proc.c
97852index bbb6461..cf04016 100644
97853--- a/net/atm/proc.c
97854+++ b/net/atm/proc.c
97855@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97856 const struct k_atm_aal_stats *stats)
97857 {
97858 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97859- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97860- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97861- atomic_read(&stats->rx_drop));
97862+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97863+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97864+ atomic_read_unchecked(&stats->rx_drop));
97865 }
97866
97867 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97868diff --git a/net/atm/resources.c b/net/atm/resources.c
97869index 0447d5d..3cf4728 100644
97870--- a/net/atm/resources.c
97871+++ b/net/atm/resources.c
97872@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97873 static void copy_aal_stats(struct k_atm_aal_stats *from,
97874 struct atm_aal_stats *to)
97875 {
97876-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97877+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97878 __AAL_STAT_ITEMS
97879 #undef __HANDLE_ITEM
97880 }
97881@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97882 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97883 struct atm_aal_stats *to)
97884 {
97885-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97886+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97887 __AAL_STAT_ITEMS
97888 #undef __HANDLE_ITEM
97889 }
97890diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97891index 919a5ce..cc6b444 100644
97892--- a/net/ax25/sysctl_net_ax25.c
97893+++ b/net/ax25/sysctl_net_ax25.c
97894@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97895 {
97896 char path[sizeof("net/ax25/") + IFNAMSIZ];
97897 int k;
97898- struct ctl_table *table;
97899+ ctl_table_no_const *table;
97900
97901 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97902 if (!table)
97903diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97904index f04224c..f326579 100644
97905--- a/net/batman-adv/bat_iv_ogm.c
97906+++ b/net/batman-adv/bat_iv_ogm.c
97907@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97908
97909 /* randomize initial seqno to avoid collision */
97910 get_random_bytes(&random_seqno, sizeof(random_seqno));
97911- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97912+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97913
97914 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97915 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97916@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97917 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97918
97919 /* change sequence number to network order */
97920- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97921+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97922 batadv_ogm_packet->seqno = htonl(seqno);
97923- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97924+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97925
97926 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97927
97928@@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97929 return;
97930
97931 /* could be changed by schedule_own_packet() */
97932- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97933+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97934
97935 if (ogm_packet->flags & BATADV_DIRECTLINK)
97936 has_directlink_flag = true;
97937diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97938index 022d18a..919daff 100644
97939--- a/net/batman-adv/fragmentation.c
97940+++ b/net/batman-adv/fragmentation.c
97941@@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97942 frag_header.packet_type = BATADV_UNICAST_FRAG;
97943 frag_header.version = BATADV_COMPAT_VERSION;
97944 frag_header.ttl = BATADV_TTL;
97945- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97946+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97947 frag_header.reserved = 0;
97948 frag_header.no = 0;
97949 frag_header.total_size = htons(skb->len);
97950diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97951index 744a59b..8fd037c 100644
97952--- a/net/batman-adv/soft-interface.c
97953+++ b/net/batman-adv/soft-interface.c
97954@@ -296,7 +296,7 @@ send:
97955 primary_if->net_dev->dev_addr);
97956
97957 /* set broadcast sequence number */
97958- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97959+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97960 bcast_packet->seqno = htonl(seqno);
97961
97962 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97963@@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97964 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97965
97966 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97967- atomic_set(&bat_priv->bcast_seqno, 1);
97968+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97969 atomic_set(&bat_priv->tt.vn, 0);
97970 atomic_set(&bat_priv->tt.local_changes, 0);
97971 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97972@@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97973
97974 /* randomize initial seqno to avoid collision */
97975 get_random_bytes(&random_seqno, sizeof(random_seqno));
97976- atomic_set(&bat_priv->frag_seqno, random_seqno);
97977+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97978
97979 bat_priv->primary_if = NULL;
97980 bat_priv->num_ifaces = 0;
97981diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97982index 34891a5..3cfece0 100644
97983--- a/net/batman-adv/types.h
97984+++ b/net/batman-adv/types.h
97985@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
97986 struct batadv_hard_iface_bat_iv {
97987 unsigned char *ogm_buff;
97988 int ogm_buff_len;
97989- atomic_t ogm_seqno;
97990+ atomic_unchecked_t ogm_seqno;
97991 };
97992
97993 /**
97994@@ -766,7 +766,7 @@ struct batadv_priv {
97995 atomic_t bonding;
97996 atomic_t fragmentation;
97997 atomic_t packet_size_max;
97998- atomic_t frag_seqno;
97999+ atomic_unchecked_t frag_seqno;
98000 #ifdef CONFIG_BATMAN_ADV_BLA
98001 atomic_t bridge_loop_avoidance;
98002 #endif
98003@@ -785,7 +785,7 @@ struct batadv_priv {
98004 #endif
98005 uint32_t isolation_mark;
98006 uint32_t isolation_mark_mask;
98007- atomic_t bcast_seqno;
98008+ atomic_unchecked_t bcast_seqno;
98009 atomic_t bcast_queue_left;
98010 atomic_t batman_queue_left;
98011 char num_ifaces;
98012diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
98013index b9a418e..2af862a 100644
98014--- a/net/bluetooth/hci_sock.c
98015+++ b/net/bluetooth/hci_sock.c
98016@@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
98017 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
98018 }
98019
98020- len = min_t(unsigned int, len, sizeof(uf));
98021+ len = min((size_t)len, sizeof(uf));
98022 if (copy_from_user(&uf, optval, len)) {
98023 err = -EFAULT;
98024 break;
98025diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
98026index 1c97b7a..9171d69 100644
98027--- a/net/bluetooth/l2cap_core.c
98028+++ b/net/bluetooth/l2cap_core.c
98029@@ -3542,8 +3542,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
98030 break;
98031
98032 case L2CAP_CONF_RFC:
98033- if (olen == sizeof(rfc))
98034- memcpy(&rfc, (void *)val, olen);
98035+ if (olen != sizeof(rfc))
98036+ break;
98037+
98038+ memcpy(&rfc, (void *)val, olen);
98039
98040 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
98041 rfc.mode != chan->mode)
98042diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
98043index e137869..33f3ebd 100644
98044--- a/net/bluetooth/l2cap_sock.c
98045+++ b/net/bluetooth/l2cap_sock.c
98046@@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98047 struct sock *sk = sock->sk;
98048 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
98049 struct l2cap_options opts;
98050- int len, err = 0;
98051+ int err = 0;
98052+ size_t len = optlen;
98053 u32 opt;
98054
98055 BT_DBG("sk %p", sk);
98056@@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98057 opts.max_tx = chan->max_tx;
98058 opts.txwin_size = chan->tx_win;
98059
98060- len = min_t(unsigned int, sizeof(opts), optlen);
98061+ len = min(sizeof(opts), len);
98062 if (copy_from_user((char *) &opts, optval, len)) {
98063 err = -EFAULT;
98064 break;
98065@@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98066 struct bt_security sec;
98067 struct bt_power pwr;
98068 struct l2cap_conn *conn;
98069- int len, err = 0;
98070+ int err = 0;
98071+ size_t len = optlen;
98072 u32 opt;
98073
98074 BT_DBG("sk %p", sk);
98075@@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98076
98077 sec.level = BT_SECURITY_LOW;
98078
98079- len = min_t(unsigned int, sizeof(sec), optlen);
98080+ len = min(sizeof(sec), len);
98081 if (copy_from_user((char *) &sec, optval, len)) {
98082 err = -EFAULT;
98083 break;
98084@@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98085
98086 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
98087
98088- len = min_t(unsigned int, sizeof(pwr), optlen);
98089+ len = min(sizeof(pwr), len);
98090 if (copy_from_user((char *) &pwr, optval, len)) {
98091 err = -EFAULT;
98092 break;
98093diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
98094index c603a5e..7f08991 100644
98095--- a/net/bluetooth/rfcomm/sock.c
98096+++ b/net/bluetooth/rfcomm/sock.c
98097@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98098 struct sock *sk = sock->sk;
98099 struct bt_security sec;
98100 int err = 0;
98101- size_t len;
98102+ size_t len = optlen;
98103 u32 opt;
98104
98105 BT_DBG("sk %p", sk);
98106@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98107
98108 sec.level = BT_SECURITY_LOW;
98109
98110- len = min_t(unsigned int, sizeof(sec), optlen);
98111+ len = min(sizeof(sec), len);
98112 if (copy_from_user((char *) &sec, optval, len)) {
98113 err = -EFAULT;
98114 break;
98115diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
98116index 403ec09..a21a003 100644
98117--- a/net/bluetooth/rfcomm/tty.c
98118+++ b/net/bluetooth/rfcomm/tty.c
98119@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
98120 BT_DBG("tty %p id %d", tty, tty->index);
98121
98122 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
98123- dev->channel, dev->port.count);
98124+ dev->channel, atomic_read(&dev->port.count));
98125
98126 err = tty_port_open(&dev->port, tty, filp);
98127 if (err)
98128@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
98129 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
98130
98131 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
98132- dev->port.count);
98133+ atomic_read(&dev->port.count));
98134
98135 tty_port_close(&dev->port, tty, filp);
98136 }
98137diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
98138index 1059ed3..d70846a 100644
98139--- a/net/bridge/netfilter/ebtables.c
98140+++ b/net/bridge/netfilter/ebtables.c
98141@@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98142 tmp.valid_hooks = t->table->valid_hooks;
98143 }
98144 mutex_unlock(&ebt_mutex);
98145- if (copy_to_user(user, &tmp, *len) != 0) {
98146+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98147 BUGPRINT("c2u Didn't work\n");
98148 ret = -EFAULT;
98149 break;
98150@@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98151 goto out;
98152 tmp.valid_hooks = t->valid_hooks;
98153
98154- if (copy_to_user(user, &tmp, *len) != 0) {
98155+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98156 ret = -EFAULT;
98157 break;
98158 }
98159@@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98160 tmp.entries_size = t->table->entries_size;
98161 tmp.valid_hooks = t->table->valid_hooks;
98162
98163- if (copy_to_user(user, &tmp, *len) != 0) {
98164+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98165 ret = -EFAULT;
98166 break;
98167 }
98168diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
98169index 0f45522..dab651f 100644
98170--- a/net/caif/cfctrl.c
98171+++ b/net/caif/cfctrl.c
98172@@ -10,6 +10,7 @@
98173 #include <linux/spinlock.h>
98174 #include <linux/slab.h>
98175 #include <linux/pkt_sched.h>
98176+#include <linux/sched.h>
98177 #include <net/caif/caif_layer.h>
98178 #include <net/caif/cfpkt.h>
98179 #include <net/caif/cfctrl.h>
98180@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
98181 memset(&dev_info, 0, sizeof(dev_info));
98182 dev_info.id = 0xff;
98183 cfsrvl_init(&this->serv, 0, &dev_info, false);
98184- atomic_set(&this->req_seq_no, 1);
98185- atomic_set(&this->rsp_seq_no, 1);
98186+ atomic_set_unchecked(&this->req_seq_no, 1);
98187+ atomic_set_unchecked(&this->rsp_seq_no, 1);
98188 this->serv.layer.receive = cfctrl_recv;
98189 sprintf(this->serv.layer.name, "ctrl");
98190 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
98191@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
98192 struct cfctrl_request_info *req)
98193 {
98194 spin_lock_bh(&ctrl->info_list_lock);
98195- atomic_inc(&ctrl->req_seq_no);
98196- req->sequence_no = atomic_read(&ctrl->req_seq_no);
98197+ atomic_inc_unchecked(&ctrl->req_seq_no);
98198+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
98199 list_add_tail(&req->list, &ctrl->list);
98200 spin_unlock_bh(&ctrl->info_list_lock);
98201 }
98202@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
98203 if (p != first)
98204 pr_warn("Requests are not received in order\n");
98205
98206- atomic_set(&ctrl->rsp_seq_no,
98207+ atomic_set_unchecked(&ctrl->rsp_seq_no,
98208 p->sequence_no);
98209 list_del(&p->list);
98210 goto out;
98211diff --git a/net/can/af_can.c b/net/can/af_can.c
98212index a27f8aa..67174a3 100644
98213--- a/net/can/af_can.c
98214+++ b/net/can/af_can.c
98215@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
98216 };
98217
98218 /* notifier block for netdevice event */
98219-static struct notifier_block can_netdev_notifier __read_mostly = {
98220+static struct notifier_block can_netdev_notifier = {
98221 .notifier_call = can_notifier,
98222 };
98223
98224diff --git a/net/can/bcm.c b/net/can/bcm.c
98225index dcb75c0..24b1b43 100644
98226--- a/net/can/bcm.c
98227+++ b/net/can/bcm.c
98228@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
98229 }
98230
98231 /* create /proc/net/can-bcm directory */
98232- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
98233+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
98234 return 0;
98235 }
98236
98237diff --git a/net/can/gw.c b/net/can/gw.c
98238index 050a211..bb9fe33 100644
98239--- a/net/can/gw.c
98240+++ b/net/can/gw.c
98241@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
98242 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
98243
98244 static HLIST_HEAD(cgw_list);
98245-static struct notifier_block notifier;
98246
98247 static struct kmem_cache *cgw_cache __read_mostly;
98248
98249@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
98250 return err;
98251 }
98252
98253+static struct notifier_block notifier = {
98254+ .notifier_call = cgw_notifier
98255+};
98256+
98257 static __init int cgw_module_init(void)
98258 {
98259 /* sanitize given module parameter */
98260@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
98261 return -ENOMEM;
98262
98263 /* set notifier */
98264- notifier.notifier_call = cgw_notifier;
98265 register_netdevice_notifier(&notifier);
98266
98267 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
98268diff --git a/net/can/proc.c b/net/can/proc.c
98269index b543470..d2ddae2 100644
98270--- a/net/can/proc.c
98271+++ b/net/can/proc.c
98272@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
98273 void can_init_proc(void)
98274 {
98275 /* create /proc/net/can directory */
98276- can_dir = proc_mkdir("can", init_net.proc_net);
98277+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
98278
98279 if (!can_dir) {
98280 printk(KERN_INFO "can: failed to create /proc/net/can . "
98281diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
98282index 1948d59..9e854d5 100644
98283--- a/net/ceph/messenger.c
98284+++ b/net/ceph/messenger.c
98285@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
98286 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
98287
98288 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
98289-static atomic_t addr_str_seq = ATOMIC_INIT(0);
98290+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
98291
98292 static struct page *zero_page; /* used in certain error cases */
98293
98294@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
98295 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
98296 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
98297
98298- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98299+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98300 s = addr_str[i];
98301
98302 switch (ss->ss_family) {
98303diff --git a/net/compat.c b/net/compat.c
98304index bc8aeef..f9c070c 100644
98305--- a/net/compat.c
98306+++ b/net/compat.c
98307@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
98308 return -EFAULT;
98309 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
98310 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
98311- kmsg->msg_name = compat_ptr(tmp1);
98312- kmsg->msg_iov = compat_ptr(tmp2);
98313- kmsg->msg_control = compat_ptr(tmp3);
98314+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
98315+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
98316+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
98317 return 0;
98318 }
98319
98320@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98321
98322 if (kern_msg->msg_name && kern_msg->msg_namelen) {
98323 if (mode == VERIFY_READ) {
98324- int err = move_addr_to_kernel(kern_msg->msg_name,
98325+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
98326 kern_msg->msg_namelen,
98327 kern_address);
98328 if (err < 0)
98329@@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98330 }
98331
98332 tot_len = iov_from_user_compat_to_kern(kern_iov,
98333- (struct compat_iovec __user *)kern_msg->msg_iov,
98334+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
98335 kern_msg->msg_iovlen);
98336 if (tot_len >= 0)
98337 kern_msg->msg_iov = kern_iov;
98338@@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98339
98340 #define CMSG_COMPAT_FIRSTHDR(msg) \
98341 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
98342- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
98343+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
98344 (struct compat_cmsghdr __user *)NULL)
98345
98346 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
98347 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
98348 (ucmlen) <= (unsigned long) \
98349 ((mhdr)->msg_controllen - \
98350- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
98351+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
98352
98353 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
98354 struct compat_cmsghdr __user *cmsg, int cmsg_len)
98355 {
98356 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
98357- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
98358+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
98359 msg->msg_controllen)
98360 return NULL;
98361 return (struct compat_cmsghdr __user *)ptr;
98362@@ -223,7 +223,7 @@ Efault:
98363
98364 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
98365 {
98366- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98367+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98368 struct compat_cmsghdr cmhdr;
98369 struct compat_timeval ctv;
98370 struct compat_timespec cts[3];
98371@@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
98372
98373 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
98374 {
98375- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98376+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98377 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
98378 int fdnum = scm->fp->count;
98379 struct file **fp = scm->fp->fp;
98380@@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
98381 return -EFAULT;
98382 old_fs = get_fs();
98383 set_fs(KERNEL_DS);
98384- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
98385+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
98386 set_fs(old_fs);
98387
98388 return err;
98389@@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98390 len = sizeof(ktime);
98391 old_fs = get_fs();
98392 set_fs(KERNEL_DS);
98393- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98394+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98395 set_fs(old_fs);
98396
98397 if (!err) {
98398@@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98399 case MCAST_JOIN_GROUP:
98400 case MCAST_LEAVE_GROUP:
98401 {
98402- struct compat_group_req __user *gr32 = (void *)optval;
98403+ struct compat_group_req __user *gr32 = (void __user *)optval;
98404 struct group_req __user *kgr =
98405 compat_alloc_user_space(sizeof(struct group_req));
98406 u32 interface;
98407@@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98408 case MCAST_BLOCK_SOURCE:
98409 case MCAST_UNBLOCK_SOURCE:
98410 {
98411- struct compat_group_source_req __user *gsr32 = (void *)optval;
98412+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98413 struct group_source_req __user *kgsr = compat_alloc_user_space(
98414 sizeof(struct group_source_req));
98415 u32 interface;
98416@@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98417 }
98418 case MCAST_MSFILTER:
98419 {
98420- struct compat_group_filter __user *gf32 = (void *)optval;
98421+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98422 struct group_filter __user *kgf;
98423 u32 interface, fmode, numsrc;
98424
98425@@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98426 char __user *optval, int __user *optlen,
98427 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98428 {
98429- struct compat_group_filter __user *gf32 = (void *)optval;
98430+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98431 struct group_filter __user *kgf;
98432 int __user *koptlen;
98433 u32 interface, fmode, numsrc;
98434@@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
98435
98436 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98437 return -EINVAL;
98438- if (copy_from_user(a, args, nas[call]))
98439+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98440 return -EFAULT;
98441 a0 = a[0];
98442 a1 = a[1];
98443diff --git a/net/core/datagram.c b/net/core/datagram.c
98444index a16ed7b..eb44d17 100644
98445--- a/net/core/datagram.c
98446+++ b/net/core/datagram.c
98447@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98448 }
98449
98450 kfree_skb(skb);
98451- atomic_inc(&sk->sk_drops);
98452+ atomic_inc_unchecked(&sk->sk_drops);
98453 sk_mem_reclaim_partial(sk);
98454
98455 return err;
98456diff --git a/net/core/dev.c b/net/core/dev.c
98457index a7621f3..ca7dac3 100644
98458--- a/net/core/dev.c
98459+++ b/net/core/dev.c
98460@@ -1690,14 +1690,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98461 {
98462 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98463 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98464- atomic_long_inc(&dev->rx_dropped);
98465+ atomic_long_inc_unchecked(&dev->rx_dropped);
98466 kfree_skb(skb);
98467 return NET_RX_DROP;
98468 }
98469 }
98470
98471 if (unlikely(!is_skb_forwardable(dev, skb))) {
98472- atomic_long_inc(&dev->rx_dropped);
98473+ atomic_long_inc_unchecked(&dev->rx_dropped);
98474 kfree_skb(skb);
98475 return NET_RX_DROP;
98476 }
98477@@ -2470,7 +2470,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98478
98479 struct dev_gso_cb {
98480 void (*destructor)(struct sk_buff *skb);
98481-};
98482+} __no_const;
98483
98484 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98485
98486@@ -2900,7 +2900,7 @@ recursion_alert:
98487 rc = -ENETDOWN;
98488 rcu_read_unlock_bh();
98489
98490- atomic_long_inc(&dev->tx_dropped);
98491+ atomic_long_inc_unchecked(&dev->tx_dropped);
98492 kfree_skb(skb);
98493 return rc;
98494 out:
98495@@ -3244,7 +3244,7 @@ enqueue:
98496
98497 local_irq_restore(flags);
98498
98499- atomic_long_inc(&skb->dev->rx_dropped);
98500+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98501 kfree_skb(skb);
98502 return NET_RX_DROP;
98503 }
98504@@ -3321,7 +3321,7 @@ int netif_rx_ni(struct sk_buff *skb)
98505 }
98506 EXPORT_SYMBOL(netif_rx_ni);
98507
98508-static void net_tx_action(struct softirq_action *h)
98509+static __latent_entropy void net_tx_action(void)
98510 {
98511 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98512
98513@@ -3654,7 +3654,7 @@ ncls:
98514 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98515 } else {
98516 drop:
98517- atomic_long_inc(&skb->dev->rx_dropped);
98518+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98519 kfree_skb(skb);
98520 /* Jamal, now you will not able to escape explaining
98521 * me how you were going to use this. :-)
98522@@ -4375,7 +4375,7 @@ void netif_napi_del(struct napi_struct *napi)
98523 }
98524 EXPORT_SYMBOL(netif_napi_del);
98525
98526-static void net_rx_action(struct softirq_action *h)
98527+static __latent_entropy void net_rx_action(void)
98528 {
98529 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98530 unsigned long time_limit = jiffies + 2;
98531@@ -6375,8 +6375,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98532 } else {
98533 netdev_stats_to_stats64(storage, &dev->stats);
98534 }
98535- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98536- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98537+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98538+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98539 return storage;
98540 }
98541 EXPORT_SYMBOL(dev_get_stats);
98542diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98543index cf999e0..c59a975 100644
98544--- a/net/core/dev_ioctl.c
98545+++ b/net/core/dev_ioctl.c
98546@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98547 if (no_module && capable(CAP_NET_ADMIN))
98548 no_module = request_module("netdev-%s", name);
98549 if (no_module && capable(CAP_SYS_MODULE)) {
98550+#ifdef CONFIG_GRKERNSEC_MODHARDEN
98551+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
98552+#else
98553 if (!request_module("%s", name))
98554 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98555 name);
98556+#endif
98557 }
98558 }
98559 EXPORT_SYMBOL(dev_load);
98560diff --git a/net/core/filter.c b/net/core/filter.c
98561index 5310d5e..01f885e 100644
98562--- a/net/core/filter.c
98563+++ b/net/core/filter.c
98564@@ -1121,7 +1121,11 @@ do_pass:
98565 break;
98566
98567 default:
98568- goto err;
98569+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98570+ fp->code, fp->jt, fp->jf, fp->k);
98571+ kfree(addrs);
98572+ BUG();
98573+ return -EINVAL;
98574 }
98575
98576 insn++;
98577@@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98578 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98579 int pc, ret = 0;
98580
98581- BUILD_BUG_ON(BPF_MEMWORDS > 16);
98582+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
98583 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98584 if (!masks)
98585 return -ENOMEM;
98586@@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98587 if (!fp)
98588 return -ENOMEM;
98589
98590- memcpy(fp->insns, fprog->filter, fsize);
98591+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98592
98593 atomic_set(&fp->refcnt, 1);
98594 fp->len = fprog->len;
98595diff --git a/net/core/flow.c b/net/core/flow.c
98596index a0348fd..6951c76 100644
98597--- a/net/core/flow.c
98598+++ b/net/core/flow.c
98599@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98600 static int flow_entry_valid(struct flow_cache_entry *fle,
98601 struct netns_xfrm *xfrm)
98602 {
98603- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98604+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98605 return 0;
98606 if (fle->object && !fle->object->ops->check(fle->object))
98607 return 0;
98608@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98609 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98610 fcp->hash_count++;
98611 }
98612- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98613+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98614 flo = fle->object;
98615 if (!flo)
98616 goto ret_object;
98617@@ -263,7 +263,7 @@ nocache:
98618 }
98619 flo = resolver(net, key, family, dir, flo, ctx);
98620 if (fle) {
98621- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98622+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98623 if (!IS_ERR(flo))
98624 fle->object = flo;
98625 else
98626diff --git a/net/core/iovec.c b/net/core/iovec.c
98627index 26dc006..89e838e 100644
98628--- a/net/core/iovec.c
98629+++ b/net/core/iovec.c
98630@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98631 if (m->msg_name && m->msg_namelen) {
98632 if (mode == VERIFY_READ) {
98633 void __user *namep;
98634- namep = (void __user __force *) m->msg_name;
98635+ namep = (void __force_user *) m->msg_name;
98636 err = move_addr_to_kernel(namep, m->msg_namelen,
98637 address);
98638 if (err < 0)
98639@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98640 }
98641
98642 size = m->msg_iovlen * sizeof(struct iovec);
98643- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98644+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98645 return -EFAULT;
98646
98647 m->msg_iov = iov;
98648diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98649index 32d872e..487e769 100644
98650--- a/net/core/neighbour.c
98651+++ b/net/core/neighbour.c
98652@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98653 void __user *buffer, size_t *lenp, loff_t *ppos)
98654 {
98655 int size, ret;
98656- struct ctl_table tmp = *ctl;
98657+ ctl_table_no_const tmp = *ctl;
98658
98659 tmp.extra1 = &zero;
98660 tmp.extra2 = &unres_qlen_max;
98661@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98662 void __user *buffer,
98663 size_t *lenp, loff_t *ppos)
98664 {
98665- struct ctl_table tmp = *ctl;
98666+ ctl_table_no_const tmp = *ctl;
98667 int ret;
98668
98669 tmp.extra1 = &zero;
98670@@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98671 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98672 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98673 } else {
98674+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98675 dev_name_source = "default";
98676- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98677- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98678- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98679- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98680+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98681+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98682+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98683+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98684 }
98685
98686 if (handler) {
98687diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98688index 2bf8329..2eb1423 100644
98689--- a/net/core/net-procfs.c
98690+++ b/net/core/net-procfs.c
98691@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98692 struct rtnl_link_stats64 temp;
98693 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98694
98695- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98696+ if (gr_proc_is_restricted())
98697+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98698+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98699+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98700+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98701+ else
98702+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98703 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98704 dev->name, stats->rx_bytes, stats->rx_packets,
98705 stats->rx_errors,
98706@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98707 return 0;
98708 }
98709
98710-static const struct seq_operations dev_seq_ops = {
98711+const struct seq_operations dev_seq_ops = {
98712 .start = dev_seq_start,
98713 .next = dev_seq_next,
98714 .stop = dev_seq_stop,
98715@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98716
98717 static int softnet_seq_open(struct inode *inode, struct file *file)
98718 {
98719- return seq_open(file, &softnet_seq_ops);
98720+ return seq_open_restrict(file, &softnet_seq_ops);
98721 }
98722
98723 static const struct file_operations softnet_seq_fops = {
98724@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98725 else
98726 seq_printf(seq, "%04x", ntohs(pt->type));
98727
98728+#ifdef CONFIG_GRKERNSEC_HIDESYM
98729+ seq_printf(seq, " %-8s %pf\n",
98730+ pt->dev ? pt->dev->name : "", NULL);
98731+#else
98732 seq_printf(seq, " %-8s %pf\n",
98733 pt->dev ? pt->dev->name : "", pt->func);
98734+#endif
98735 }
98736
98737 return 0;
98738diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98739index 1cac29e..fb482f3 100644
98740--- a/net/core/net-sysfs.c
98741+++ b/net/core/net-sysfs.c
98742@@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
98743 {
98744 struct net_device *netdev = to_net_dev(dev);
98745 return sprintf(buf, fmt_dec,
98746- atomic_read(&netdev->carrier_changes));
98747+ atomic_read_unchecked(&netdev->carrier_changes));
98748 }
98749 static DEVICE_ATTR_RO(carrier_changes);
98750
98751diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98752index 7c8ffd9..0cb3687 100644
98753--- a/net/core/net_namespace.c
98754+++ b/net/core/net_namespace.c
98755@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98756 int error;
98757 LIST_HEAD(net_exit_list);
98758
98759- list_add_tail(&ops->list, list);
98760+ pax_list_add_tail((struct list_head *)&ops->list, list);
98761 if (ops->init || (ops->id && ops->size)) {
98762 for_each_net(net) {
98763 error = ops_init(ops, net);
98764@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98765
98766 out_undo:
98767 /* If I have an error cleanup all namespaces I initialized */
98768- list_del(&ops->list);
98769+ pax_list_del((struct list_head *)&ops->list);
98770 ops_exit_list(ops, &net_exit_list);
98771 ops_free_list(ops, &net_exit_list);
98772 return error;
98773@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98774 struct net *net;
98775 LIST_HEAD(net_exit_list);
98776
98777- list_del(&ops->list);
98778+ pax_list_del((struct list_head *)&ops->list);
98779 for_each_net(net)
98780 list_add_tail(&net->exit_list, &net_exit_list);
98781 ops_exit_list(ops, &net_exit_list);
98782@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98783 mutex_lock(&net_mutex);
98784 error = register_pernet_operations(&pernet_list, ops);
98785 if (!error && (first_device == &pernet_list))
98786- first_device = &ops->list;
98787+ first_device = (struct list_head *)&ops->list;
98788 mutex_unlock(&net_mutex);
98789 return error;
98790 }
98791diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98792index e33937f..b2b4981 100644
98793--- a/net/core/netpoll.c
98794+++ b/net/core/netpoll.c
98795@@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98796 struct udphdr *udph;
98797 struct iphdr *iph;
98798 struct ethhdr *eth;
98799- static atomic_t ip_ident;
98800+ static atomic_unchecked_t ip_ident;
98801 struct ipv6hdr *ip6h;
98802
98803 udp_len = len + sizeof(*udph);
98804@@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98805 put_unaligned(0x45, (unsigned char *)iph);
98806 iph->tos = 0;
98807 put_unaligned(htons(ip_len), &(iph->tot_len));
98808- iph->id = htons(atomic_inc_return(&ip_ident));
98809+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98810 iph->frag_off = 0;
98811 iph->ttl = 64;
98812 iph->protocol = IPPROTO_UDP;
98813diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98814index 0304f98..ddfead6 100644
98815--- a/net/core/pktgen.c
98816+++ b/net/core/pktgen.c
98817@@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
98818 pn->net = net;
98819 INIT_LIST_HEAD(&pn->pktgen_threads);
98820 pn->pktgen_exiting = false;
98821- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98822+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98823 if (!pn->proc_dir) {
98824 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98825 return -ENODEV;
98826diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98827index 1999ed8..1e6e58a 100644
98828--- a/net/core/rtnetlink.c
98829+++ b/net/core/rtnetlink.c
98830@@ -58,7 +58,7 @@ struct rtnl_link {
98831 rtnl_doit_func doit;
98832 rtnl_dumpit_func dumpit;
98833 rtnl_calcit_func calcit;
98834-};
98835+} __no_const;
98836
98837 static DEFINE_MUTEX(rtnl_mutex);
98838
98839@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98840 if (rtnl_link_ops_get(ops->kind))
98841 return -EEXIST;
98842
98843- if (!ops->dellink)
98844- ops->dellink = unregister_netdevice_queue;
98845+ if (!ops->dellink) {
98846+ pax_open_kernel();
98847+ *(void **)&ops->dellink = unregister_netdevice_queue;
98848+ pax_close_kernel();
98849+ }
98850
98851- list_add_tail(&ops->list, &link_ops);
98852+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98853 return 0;
98854 }
98855 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98856@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98857 for_each_net(net) {
98858 __rtnl_kill_links(net, ops);
98859 }
98860- list_del(&ops->list);
98861+ pax_list_del((struct list_head *)&ops->list);
98862 }
98863 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98864
98865@@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
98866 (dev->ifalias &&
98867 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
98868 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
98869- atomic_read(&dev->carrier_changes)))
98870+ atomic_read_unchecked(&dev->carrier_changes)))
98871 goto nla_put_failure;
98872
98873 if (1) {
98874diff --git a/net/core/scm.c b/net/core/scm.c
98875index b442e7e..6f5b5a2 100644
98876--- a/net/core/scm.c
98877+++ b/net/core/scm.c
98878@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98879 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98880 {
98881 struct cmsghdr __user *cm
98882- = (__force struct cmsghdr __user *)msg->msg_control;
98883+ = (struct cmsghdr __force_user *)msg->msg_control;
98884 struct cmsghdr cmhdr;
98885 int cmlen = CMSG_LEN(len);
98886 int err;
98887@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98888 err = -EFAULT;
98889 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98890 goto out;
98891- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98892+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98893 goto out;
98894 cmlen = CMSG_SPACE(len);
98895 if (msg->msg_controllen < cmlen)
98896@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98897 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98898 {
98899 struct cmsghdr __user *cm
98900- = (__force struct cmsghdr __user*)msg->msg_control;
98901+ = (struct cmsghdr __force_user *)msg->msg_control;
98902
98903 int fdmax = 0;
98904 int fdnum = scm->fp->count;
98905@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98906 if (fdnum < fdmax)
98907 fdmax = fdnum;
98908
98909- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98910+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98911 i++, cmfptr++)
98912 {
98913 struct socket *sock;
98914diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98915index 6ab5f77..6fd2a81 100644
98916--- a/net/core/skbuff.c
98917+++ b/net/core/skbuff.c
98918@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98919 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98920 int len, __wsum csum)
98921 {
98922- const struct skb_checksum_ops ops = {
98923+ static const struct skb_checksum_ops ops = {
98924 .update = csum_partial_ext,
98925 .combine = csum_block_add_ext,
98926 };
98927@@ -3221,13 +3221,15 @@ void __init skb_init(void)
98928 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98929 sizeof(struct sk_buff),
98930 0,
98931- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98932+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98933+ SLAB_NO_SANITIZE,
98934 NULL);
98935 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98936 (2*sizeof(struct sk_buff)) +
98937 sizeof(atomic_t),
98938 0,
98939- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98940+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98941+ SLAB_NO_SANITIZE,
98942 NULL);
98943 }
98944
98945diff --git a/net/core/sock.c b/net/core/sock.c
98946index 664ee42..aaf9e6e 100644
98947--- a/net/core/sock.c
98948+++ b/net/core/sock.c
98949@@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98950 struct sk_buff_head *list = &sk->sk_receive_queue;
98951
98952 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98953- atomic_inc(&sk->sk_drops);
98954+ atomic_inc_unchecked(&sk->sk_drops);
98955 trace_sock_rcvqueue_full(sk, skb);
98956 return -ENOMEM;
98957 }
98958@@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98959 return err;
98960
98961 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98962- atomic_inc(&sk->sk_drops);
98963+ atomic_inc_unchecked(&sk->sk_drops);
98964 return -ENOBUFS;
98965 }
98966
98967@@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98968 skb_dst_force(skb);
98969
98970 spin_lock_irqsave(&list->lock, flags);
98971- skb->dropcount = atomic_read(&sk->sk_drops);
98972+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98973 __skb_queue_tail(list, skb);
98974 spin_unlock_irqrestore(&list->lock, flags);
98975
98976@@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98977 skb->dev = NULL;
98978
98979 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98980- atomic_inc(&sk->sk_drops);
98981+ atomic_inc_unchecked(&sk->sk_drops);
98982 goto discard_and_relse;
98983 }
98984 if (nested)
98985@@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98986 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98987 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98988 bh_unlock_sock(sk);
98989- atomic_inc(&sk->sk_drops);
98990+ atomic_inc_unchecked(&sk->sk_drops);
98991 goto discard_and_relse;
98992 }
98993
98994@@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98995 struct timeval tm;
98996 } v;
98997
98998- int lv = sizeof(int);
98999- int len;
99000+ unsigned int lv = sizeof(int);
99001+ unsigned int len;
99002
99003 if (get_user(len, optlen))
99004 return -EFAULT;
99005- if (len < 0)
99006+ if (len > INT_MAX)
99007 return -EINVAL;
99008
99009 memset(&v, 0, sizeof(v));
99010@@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99011
99012 case SO_PEERNAME:
99013 {
99014- char address[128];
99015+ char address[_K_SS_MAXSIZE];
99016
99017 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
99018 return -ENOTCONN;
99019- if (lv < len)
99020+ if (lv < len || sizeof address < len)
99021 return -EINVAL;
99022 if (copy_to_user(optval, address, len))
99023 return -EFAULT;
99024@@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99025
99026 if (len > lv)
99027 len = lv;
99028- if (copy_to_user(optval, &v, len))
99029+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
99030 return -EFAULT;
99031 lenout:
99032 if (put_user(len, optlen))
99033@@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
99034 */
99035 smp_wmb();
99036 atomic_set(&sk->sk_refcnt, 1);
99037- atomic_set(&sk->sk_drops, 0);
99038+ atomic_set_unchecked(&sk->sk_drops, 0);
99039 }
99040 EXPORT_SYMBOL(sock_init_data);
99041
99042@@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
99043 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99044 int level, int type)
99045 {
99046+ struct sock_extended_err ee;
99047 struct sock_exterr_skb *serr;
99048 struct sk_buff *skb, *skb2;
99049 int copied, err;
99050@@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99051 sock_recv_timestamp(msg, sk, skb);
99052
99053 serr = SKB_EXT_ERR(skb);
99054- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
99055+ ee = serr->ee;
99056+ put_cmsg(msg, level, type, sizeof ee, &ee);
99057
99058 msg->msg_flags |= MSG_ERRQUEUE;
99059 err = copied;
99060diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
99061index a4216a4..1c07687 100644
99062--- a/net/core/sock_diag.c
99063+++ b/net/core/sock_diag.c
99064@@ -9,26 +9,33 @@
99065 #include <linux/inet_diag.h>
99066 #include <linux/sock_diag.h>
99067
99068-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
99069+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
99070 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
99071 static DEFINE_MUTEX(sock_diag_table_mutex);
99072
99073 int sock_diag_check_cookie(void *sk, __u32 *cookie)
99074 {
99075+#ifndef CONFIG_GRKERNSEC_HIDESYM
99076 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
99077 cookie[1] != INET_DIAG_NOCOOKIE) &&
99078 ((u32)(unsigned long)sk != cookie[0] ||
99079 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
99080 return -ESTALE;
99081 else
99082+#endif
99083 return 0;
99084 }
99085 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
99086
99087 void sock_diag_save_cookie(void *sk, __u32 *cookie)
99088 {
99089+#ifdef CONFIG_GRKERNSEC_HIDESYM
99090+ cookie[0] = 0;
99091+ cookie[1] = 0;
99092+#else
99093 cookie[0] = (u32)(unsigned long)sk;
99094 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
99095+#endif
99096 }
99097 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
99098
99099@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
99100 mutex_lock(&sock_diag_table_mutex);
99101 if (sock_diag_handlers[hndl->family])
99102 err = -EBUSY;
99103- else
99104+ else {
99105+ pax_open_kernel();
99106 sock_diag_handlers[hndl->family] = hndl;
99107+ pax_close_kernel();
99108+ }
99109 mutex_unlock(&sock_diag_table_mutex);
99110
99111 return err;
99112@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
99113
99114 mutex_lock(&sock_diag_table_mutex);
99115 BUG_ON(sock_diag_handlers[family] != hnld);
99116+ pax_open_kernel();
99117 sock_diag_handlers[family] = NULL;
99118+ pax_close_kernel();
99119 mutex_unlock(&sock_diag_table_mutex);
99120 }
99121 EXPORT_SYMBOL_GPL(sock_diag_unregister);
99122diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
99123index cf9cd13..8b56af3 100644
99124--- a/net/core/sysctl_net_core.c
99125+++ b/net/core/sysctl_net_core.c
99126@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
99127 {
99128 unsigned int orig_size, size;
99129 int ret, i;
99130- struct ctl_table tmp = {
99131+ ctl_table_no_const tmp = {
99132 .data = &size,
99133 .maxlen = sizeof(size),
99134 .mode = table->mode
99135@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
99136 void __user *buffer, size_t *lenp, loff_t *ppos)
99137 {
99138 char id[IFNAMSIZ];
99139- struct ctl_table tbl = {
99140+ ctl_table_no_const tbl = {
99141 .data = id,
99142 .maxlen = IFNAMSIZ,
99143 };
99144@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
99145
99146 static __net_init int sysctl_core_net_init(struct net *net)
99147 {
99148- struct ctl_table *tbl;
99149+ ctl_table_no_const *tbl = NULL;
99150
99151 net->core.sysctl_somaxconn = SOMAXCONN;
99152
99153- tbl = netns_core_table;
99154 if (!net_eq(net, &init_net)) {
99155- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
99156+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
99157 if (tbl == NULL)
99158 goto err_dup;
99159
99160@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
99161 if (net->user_ns != &init_user_ns) {
99162 tbl[0].procname = NULL;
99163 }
99164- }
99165-
99166- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99167+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99168+ } else
99169+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
99170 if (net->core.sysctl_hdr == NULL)
99171 goto err_reg;
99172
99173 return 0;
99174
99175 err_reg:
99176- if (tbl != netns_core_table)
99177- kfree(tbl);
99178+ kfree(tbl);
99179 err_dup:
99180 return -ENOMEM;
99181 }
99182@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
99183 kfree(tbl);
99184 }
99185
99186-static __net_initdata struct pernet_operations sysctl_core_ops = {
99187+static __net_initconst struct pernet_operations sysctl_core_ops = {
99188 .init = sysctl_core_net_init,
99189 .exit = sysctl_core_net_exit,
99190 };
99191diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
99192index 4c04848..f575934 100644
99193--- a/net/decnet/af_decnet.c
99194+++ b/net/decnet/af_decnet.c
99195@@ -465,6 +465,7 @@ static struct proto dn_proto = {
99196 .sysctl_rmem = sysctl_decnet_rmem,
99197 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
99198 .obj_size = sizeof(struct dn_sock),
99199+ .slab_flags = SLAB_USERCOPY,
99200 };
99201
99202 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
99203diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
99204index 3b726f3..1af6368 100644
99205--- a/net/decnet/dn_dev.c
99206+++ b/net/decnet/dn_dev.c
99207@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
99208 .extra1 = &min_t3,
99209 .extra2 = &max_t3
99210 },
99211- {0}
99212+ { }
99213 },
99214 };
99215
99216diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
99217index 5325b54..a0d4d69 100644
99218--- a/net/decnet/sysctl_net_decnet.c
99219+++ b/net/decnet/sysctl_net_decnet.c
99220@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
99221
99222 if (len > *lenp) len = *lenp;
99223
99224- if (copy_to_user(buffer, addr, len))
99225+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
99226 return -EFAULT;
99227
99228 *lenp = len;
99229@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
99230
99231 if (len > *lenp) len = *lenp;
99232
99233- if (copy_to_user(buffer, devname, len))
99234+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
99235 return -EFAULT;
99236
99237 *lenp = len;
99238diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
99239index ef2d543..5b9b73f 100644
99240--- a/net/ieee802154/reassembly.c
99241+++ b/net/ieee802154/reassembly.c
99242@@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
99243
99244 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99245 {
99246- struct ctl_table *table;
99247+ ctl_table_no_const *table = NULL;
99248 struct ctl_table_header *hdr;
99249
99250- table = lowpan_frags_ns_ctl_table;
99251 if (!net_eq(net, &init_net)) {
99252- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
99253+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
99254 GFP_KERNEL);
99255 if (table == NULL)
99256 goto err_alloc;
99257@@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99258 /* Don't export sysctls to unprivileged users */
99259 if (net->user_ns != &init_user_ns)
99260 table[0].procname = NULL;
99261- }
99262-
99263- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99264+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99265+ } else
99266+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
99267 if (hdr == NULL)
99268 goto err_reg;
99269
99270@@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99271 return 0;
99272
99273 err_reg:
99274- if (!net_eq(net, &init_net))
99275- kfree(table);
99276+ kfree(table);
99277 err_alloc:
99278 return -ENOMEM;
99279 }
99280diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
99281index 6af8ab6..3831cb8 100644
99282--- a/net/ipv4/af_inet.c
99283+++ b/net/ipv4/af_inet.c
99284@@ -1739,13 +1739,9 @@ static int __init inet_init(void)
99285
99286 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
99287
99288- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
99289- if (!sysctl_local_reserved_ports)
99290- goto out;
99291-
99292 rc = proto_register(&tcp_prot, 1);
99293 if (rc)
99294- goto out_free_reserved_ports;
99295+ goto out;
99296
99297 rc = proto_register(&udp_prot, 1);
99298 if (rc)
99299@@ -1855,8 +1851,6 @@ out_unregister_udp_proto:
99300 proto_unregister(&udp_prot);
99301 out_unregister_tcp_proto:
99302 proto_unregister(&tcp_prot);
99303-out_free_reserved_ports:
99304- kfree(sysctl_local_reserved_ports);
99305 goto out;
99306 }
99307
99308diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
99309index bdbf68b..deb4759 100644
99310--- a/net/ipv4/devinet.c
99311+++ b/net/ipv4/devinet.c
99312@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
99313 idx = 0;
99314 head = &net->dev_index_head[h];
99315 rcu_read_lock();
99316- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99317+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99318 net->dev_base_seq;
99319 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99320 if (idx < s_idx)
99321@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
99322 idx = 0;
99323 head = &net->dev_index_head[h];
99324 rcu_read_lock();
99325- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99326+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99327 net->dev_base_seq;
99328 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99329 if (idx < s_idx)
99330@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
99331 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
99332 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
99333
99334-static struct devinet_sysctl_table {
99335+static const struct devinet_sysctl_table {
99336 struct ctl_table_header *sysctl_header;
99337 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
99338 } devinet_sysctl = {
99339@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
99340 int err;
99341 struct ipv4_devconf *all, *dflt;
99342 #ifdef CONFIG_SYSCTL
99343- struct ctl_table *tbl = ctl_forward_entry;
99344+ ctl_table_no_const *tbl = NULL;
99345 struct ctl_table_header *forw_hdr;
99346 #endif
99347
99348@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
99349 goto err_alloc_dflt;
99350
99351 #ifdef CONFIG_SYSCTL
99352- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99353+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99354 if (tbl == NULL)
99355 goto err_alloc_ctl;
99356
99357@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99358 goto err_reg_dflt;
99359
99360 err = -ENOMEM;
99361- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99362+ if (!net_eq(net, &init_net))
99363+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99364+ else
99365+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99366 if (forw_hdr == NULL)
99367 goto err_reg_ctl;
99368 net->ipv4.forw_hdr = forw_hdr;
99369@@ -2272,8 +2275,7 @@ err_reg_ctl:
99370 err_reg_dflt:
99371 __devinet_sysctl_unregister(all);
99372 err_reg_all:
99373- if (tbl != ctl_forward_entry)
99374- kfree(tbl);
99375+ kfree(tbl);
99376 err_alloc_ctl:
99377 #endif
99378 if (dflt != &ipv4_devconf_dflt)
99379diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99380index 255aa99..45c78f8 100644
99381--- a/net/ipv4/fib_frontend.c
99382+++ b/net/ipv4/fib_frontend.c
99383@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99384 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99385 fib_sync_up(dev);
99386 #endif
99387- atomic_inc(&net->ipv4.dev_addr_genid);
99388+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99389 rt_cache_flush(dev_net(dev));
99390 break;
99391 case NETDEV_DOWN:
99392 fib_del_ifaddr(ifa, NULL);
99393- atomic_inc(&net->ipv4.dev_addr_genid);
99394+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99395 if (ifa->ifa_dev->ifa_list == NULL) {
99396 /* Last address was deleted from this interface.
99397 * Disable IP.
99398@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99399 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99400 fib_sync_up(dev);
99401 #endif
99402- atomic_inc(&net->ipv4.dev_addr_genid);
99403+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99404 rt_cache_flush(net);
99405 break;
99406 case NETDEV_DOWN:
99407diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99408index b10cd43a..22327f9 100644
99409--- a/net/ipv4/fib_semantics.c
99410+++ b/net/ipv4/fib_semantics.c
99411@@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99412 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99413 nh->nh_gw,
99414 nh->nh_parent->fib_scope);
99415- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99416+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99417
99418 return nh->nh_saddr;
99419 }
99420diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99421index a56b8e6..5be2a30 100644
99422--- a/net/ipv4/inet_connection_sock.c
99423+++ b/net/ipv4/inet_connection_sock.c
99424@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99425 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99426 #endif
99427
99428-unsigned long *sysctl_local_reserved_ports;
99429+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99430 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99431
99432 void inet_get_local_port_range(struct net *net, int *low, int *high)
99433diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99434index 8b9cf27..0d8d592 100644
99435--- a/net/ipv4/inet_hashtables.c
99436+++ b/net/ipv4/inet_hashtables.c
99437@@ -18,6 +18,7 @@
99438 #include <linux/sched.h>
99439 #include <linux/slab.h>
99440 #include <linux/wait.h>
99441+#include <linux/security.h>
99442
99443 #include <net/inet_connection_sock.h>
99444 #include <net/inet_hashtables.h>
99445@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99446 return inet_ehashfn(net, laddr, lport, faddr, fport);
99447 }
99448
99449+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99450+
99451 /*
99452 * Allocate and initialize a new local port bind bucket.
99453 * The bindhash mutex for snum's hash chain must be held here.
99454@@ -554,6 +557,8 @@ ok:
99455 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99456 spin_unlock(&head->lock);
99457
99458+ gr_update_task_in_ip_table(current, inet_sk(sk));
99459+
99460 if (tw) {
99461 inet_twsk_deschedule(tw, death_row);
99462 while (twrefcnt) {
99463diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99464index bf2cb4a..d83ba8a 100644
99465--- a/net/ipv4/inetpeer.c
99466+++ b/net/ipv4/inetpeer.c
99467@@ -482,7 +482,7 @@ relookup:
99468 if (p) {
99469 p->daddr = *daddr;
99470 atomic_set(&p->refcnt, 1);
99471- atomic_set(&p->rid, 0);
99472+ atomic_set_unchecked(&p->rid, 0);
99473 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
99474 p->rate_tokens = 0;
99475 /* 60*HZ is arbitrary, but chosen enough high so that the first
99476diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99477index ed32313..3762abe 100644
99478--- a/net/ipv4/ip_fragment.c
99479+++ b/net/ipv4/ip_fragment.c
99480@@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99481 return 0;
99482
99483 start = qp->rid;
99484- end = atomic_inc_return(&peer->rid);
99485+ end = atomic_inc_return_unchecked(&peer->rid);
99486 qp->rid = end;
99487
99488 rc = qp->q.fragments && (end - start) > max;
99489@@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99490
99491 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99492 {
99493- struct ctl_table *table;
99494+ ctl_table_no_const *table = NULL;
99495 struct ctl_table_header *hdr;
99496
99497- table = ip4_frags_ns_ctl_table;
99498 if (!net_eq(net, &init_net)) {
99499- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99500+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99501 if (table == NULL)
99502 goto err_alloc;
99503
99504@@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99505 /* Don't export sysctls to unprivileged users */
99506 if (net->user_ns != &init_user_ns)
99507 table[0].procname = NULL;
99508- }
99509+ hdr = register_net_sysctl(net, "net/ipv4", table);
99510+ } else
99511+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99512
99513- hdr = register_net_sysctl(net, "net/ipv4", table);
99514 if (hdr == NULL)
99515 goto err_reg;
99516
99517@@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99518 return 0;
99519
99520 err_reg:
99521- if (!net_eq(net, &init_net))
99522- kfree(table);
99523+ kfree(table);
99524 err_alloc:
99525 return -ENOMEM;
99526 }
99527diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99528index 94213c8..8bdb342 100644
99529--- a/net/ipv4/ip_gre.c
99530+++ b/net/ipv4/ip_gre.c
99531@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99532 module_param(log_ecn_error, bool, 0644);
99533 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99534
99535-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99536+static struct rtnl_link_ops ipgre_link_ops;
99537 static int ipgre_tunnel_init(struct net_device *dev);
99538
99539 static int ipgre_net_id __read_mostly;
99540@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99541 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99542 };
99543
99544-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99545+static struct rtnl_link_ops ipgre_link_ops = {
99546 .kind = "gre",
99547 .maxtype = IFLA_GRE_MAX,
99548 .policy = ipgre_policy,
99549@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99550 .fill_info = ipgre_fill_info,
99551 };
99552
99553-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99554+static struct rtnl_link_ops ipgre_tap_ops = {
99555 .kind = "gretap",
99556 .maxtype = IFLA_GRE_MAX,
99557 .policy = ipgre_policy,
99558diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99559index 64741b9..6f334a2 100644
99560--- a/net/ipv4/ip_sockglue.c
99561+++ b/net/ipv4/ip_sockglue.c
99562@@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99563 len = min_t(unsigned int, len, opt->optlen);
99564 if (put_user(len, optlen))
99565 return -EFAULT;
99566- if (copy_to_user(optval, opt->__data, len))
99567+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99568+ copy_to_user(optval, opt->__data, len))
99569 return -EFAULT;
99570 return 0;
99571 }
99572@@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99573 if (sk->sk_type != SOCK_STREAM)
99574 return -ENOPROTOOPT;
99575
99576- msg.msg_control = optval;
99577+ msg.msg_control = (void __force_kernel *)optval;
99578 msg.msg_controllen = len;
99579 msg.msg_flags = flags;
99580
99581diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99582index 13ef00f..8ffca25 100644
99583--- a/net/ipv4/ip_vti.c
99584+++ b/net/ipv4/ip_vti.c
99585@@ -45,7 +45,7 @@
99586 #include <net/net_namespace.h>
99587 #include <net/netns/generic.h>
99588
99589-static struct rtnl_link_ops vti_link_ops __read_mostly;
99590+static struct rtnl_link_ops vti_link_ops;
99591
99592 static int vti_net_id __read_mostly;
99593 static int vti_tunnel_init(struct net_device *dev);
99594@@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99595 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99596 };
99597
99598-static struct rtnl_link_ops vti_link_ops __read_mostly = {
99599+static struct rtnl_link_ops vti_link_ops = {
99600 .kind = "vti",
99601 .maxtype = IFLA_VTI_MAX,
99602 .policy = vti_policy,
99603diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99604index b3e86ea..18ce98c 100644
99605--- a/net/ipv4/ipconfig.c
99606+++ b/net/ipv4/ipconfig.c
99607@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99608
99609 mm_segment_t oldfs = get_fs();
99610 set_fs(get_ds());
99611- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99612+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99613 set_fs(oldfs);
99614 return res;
99615 }
99616@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99617
99618 mm_segment_t oldfs = get_fs();
99619 set_fs(get_ds());
99620- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99621+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99622 set_fs(oldfs);
99623 return res;
99624 }
99625@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99626
99627 mm_segment_t oldfs = get_fs();
99628 set_fs(get_ds());
99629- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99630+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99631 set_fs(oldfs);
99632 return res;
99633 }
99634diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99635index 62eaa00..29b2dc2 100644
99636--- a/net/ipv4/ipip.c
99637+++ b/net/ipv4/ipip.c
99638@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99639 static int ipip_net_id __read_mostly;
99640
99641 static int ipip_tunnel_init(struct net_device *dev);
99642-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99643+static struct rtnl_link_ops ipip_link_ops;
99644
99645 static int ipip_err(struct sk_buff *skb, u32 info)
99646 {
99647@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99648 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99649 };
99650
99651-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99652+static struct rtnl_link_ops ipip_link_ops = {
99653 .kind = "ipip",
99654 .maxtype = IFLA_IPTUN_MAX,
99655 .policy = ipip_policy,
99656diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99657index f95b6f9..2ee2097 100644
99658--- a/net/ipv4/netfilter/arp_tables.c
99659+++ b/net/ipv4/netfilter/arp_tables.c
99660@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99661 #endif
99662
99663 static int get_info(struct net *net, void __user *user,
99664- const int *len, int compat)
99665+ int len, int compat)
99666 {
99667 char name[XT_TABLE_MAXNAMELEN];
99668 struct xt_table *t;
99669 int ret;
99670
99671- if (*len != sizeof(struct arpt_getinfo)) {
99672- duprintf("length %u != %Zu\n", *len,
99673+ if (len != sizeof(struct arpt_getinfo)) {
99674+ duprintf("length %u != %Zu\n", len,
99675 sizeof(struct arpt_getinfo));
99676 return -EINVAL;
99677 }
99678@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99679 info.size = private->size;
99680 strcpy(info.name, name);
99681
99682- if (copy_to_user(user, &info, *len) != 0)
99683+ if (copy_to_user(user, &info, len) != 0)
99684 ret = -EFAULT;
99685 else
99686 ret = 0;
99687@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99688
99689 switch (cmd) {
99690 case ARPT_SO_GET_INFO:
99691- ret = get_info(sock_net(sk), user, len, 1);
99692+ ret = get_info(sock_net(sk), user, *len, 1);
99693 break;
99694 case ARPT_SO_GET_ENTRIES:
99695 ret = compat_get_entries(sock_net(sk), user, len);
99696@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99697
99698 switch (cmd) {
99699 case ARPT_SO_GET_INFO:
99700- ret = get_info(sock_net(sk), user, len, 0);
99701+ ret = get_info(sock_net(sk), user, *len, 0);
99702 break;
99703
99704 case ARPT_SO_GET_ENTRIES:
99705diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99706index 99e810f..3711b81 100644
99707--- a/net/ipv4/netfilter/ip_tables.c
99708+++ b/net/ipv4/netfilter/ip_tables.c
99709@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99710 #endif
99711
99712 static int get_info(struct net *net, void __user *user,
99713- const int *len, int compat)
99714+ int len, int compat)
99715 {
99716 char name[XT_TABLE_MAXNAMELEN];
99717 struct xt_table *t;
99718 int ret;
99719
99720- if (*len != sizeof(struct ipt_getinfo)) {
99721- duprintf("length %u != %zu\n", *len,
99722+ if (len != sizeof(struct ipt_getinfo)) {
99723+ duprintf("length %u != %zu\n", len,
99724 sizeof(struct ipt_getinfo));
99725 return -EINVAL;
99726 }
99727@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99728 info.size = private->size;
99729 strcpy(info.name, name);
99730
99731- if (copy_to_user(user, &info, *len) != 0)
99732+ if (copy_to_user(user, &info, len) != 0)
99733 ret = -EFAULT;
99734 else
99735 ret = 0;
99736@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99737
99738 switch (cmd) {
99739 case IPT_SO_GET_INFO:
99740- ret = get_info(sock_net(sk), user, len, 1);
99741+ ret = get_info(sock_net(sk), user, *len, 1);
99742 break;
99743 case IPT_SO_GET_ENTRIES:
99744 ret = compat_get_entries(sock_net(sk), user, len);
99745@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99746
99747 switch (cmd) {
99748 case IPT_SO_GET_INFO:
99749- ret = get_info(sock_net(sk), user, len, 0);
99750+ ret = get_info(sock_net(sk), user, *len, 0);
99751 break;
99752
99753 case IPT_SO_GET_ENTRIES:
99754diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99755index 2510c02..cfb34fa 100644
99756--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99757+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99758@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99759 spin_lock_init(&cn->lock);
99760
99761 #ifdef CONFIG_PROC_FS
99762- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99763+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99764 if (!cn->procdir) {
99765 pr_err("Unable to proc dir entry\n");
99766 return -ENOMEM;
99767diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99768index 044a0dd..e0c1971 100644
99769--- a/net/ipv4/ping.c
99770+++ b/net/ipv4/ping.c
99771@@ -59,7 +59,7 @@ struct ping_table {
99772 };
99773
99774 static struct ping_table ping_table;
99775-struct pingv6_ops pingv6_ops;
99776+struct pingv6_ops *pingv6_ops;
99777 EXPORT_SYMBOL_GPL(pingv6_ops);
99778
99779 static u16 ping_port_rover;
99780@@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99781 return -ENODEV;
99782 }
99783 }
99784- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99785+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99786 scoped);
99787 rcu_read_unlock();
99788
99789@@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99790 }
99791 #if IS_ENABLED(CONFIG_IPV6)
99792 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99793- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99794+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99795 #endif
99796 }
99797
99798@@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99799 info, (u8 *)icmph);
99800 #if IS_ENABLED(CONFIG_IPV6)
99801 } else if (family == AF_INET6) {
99802- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99803+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99804 info, (u8 *)icmph);
99805 #endif
99806 }
99807@@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99808 {
99809 struct inet_sock *isk = inet_sk(sk);
99810 int family = sk->sk_family;
99811+ struct sockaddr_in *sin;
99812+ struct sockaddr_in6 *sin6;
99813 struct sk_buff *skb;
99814 int copied, err;
99815
99816@@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99817 if (flags & MSG_OOB)
99818 goto out;
99819
99820+ if (addr_len) {
99821+ if (family == AF_INET)
99822+ *addr_len = sizeof(*sin);
99823+ else if (family == AF_INET6 && addr_len)
99824+ *addr_len = sizeof(*sin6);
99825+ }
99826+
99827 if (flags & MSG_ERRQUEUE) {
99828 if (family == AF_INET) {
99829 return ip_recv_error(sk, msg, len, addr_len);
99830 #if IS_ENABLED(CONFIG_IPV6)
99831 } else if (family == AF_INET6) {
99832- return pingv6_ops.ipv6_recv_error(sk, msg, len,
99833+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
99834 addr_len);
99835 #endif
99836 }
99837@@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99838 sin->sin_port = 0 /* skb->h.uh->source */;
99839 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99840 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99841- *addr_len = sizeof(*sin);
99842 }
99843
99844 if (isk->cmsg_flags)
99845@@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99846 sin6->sin6_scope_id =
99847 ipv6_iface_scope_id(&sin6->sin6_addr,
99848 IP6CB(skb)->iif);
99849- *addr_len = sizeof(*sin6);
99850 }
99851
99852 if (inet6_sk(sk)->rxopt.all)
99853- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99854+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99855 if (skb->protocol == htons(ETH_P_IPV6) &&
99856 inet6_sk(sk)->rxopt.all)
99857- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99858+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99859 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99860 ip_cmsg_recv(msg, skb);
99861 #endif
99862@@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99863 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99864 0, sock_i_ino(sp),
99865 atomic_read(&sp->sk_refcnt), sp,
99866- atomic_read(&sp->sk_drops));
99867+ atomic_read_unchecked(&sp->sk_drops));
99868 }
99869
99870 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99871diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99872index 2c65160..b54c00e 100644
99873--- a/net/ipv4/raw.c
99874+++ b/net/ipv4/raw.c
99875@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99876 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99877 {
99878 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99879- atomic_inc(&sk->sk_drops);
99880+ atomic_inc_unchecked(&sk->sk_drops);
99881 kfree_skb(skb);
99882 return NET_RX_DROP;
99883 }
99884@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99885 if (flags & MSG_OOB)
99886 goto out;
99887
99888+ if (addr_len)
99889+ *addr_len = sizeof(*sin);
99890+
99891 if (flags & MSG_ERRQUEUE) {
99892 err = ip_recv_error(sk, msg, len, addr_len);
99893 goto out;
99894@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99895 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99896 sin->sin_port = 0;
99897 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99898- *addr_len = sizeof(*sin);
99899 }
99900 if (inet->cmsg_flags)
99901 ip_cmsg_recv(msg, skb);
99902@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99903
99904 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99905 {
99906+ struct icmp_filter filter;
99907+
99908 if (optlen > sizeof(struct icmp_filter))
99909 optlen = sizeof(struct icmp_filter);
99910- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99911+ if (copy_from_user(&filter, optval, optlen))
99912 return -EFAULT;
99913+ raw_sk(sk)->filter = filter;
99914 return 0;
99915 }
99916
99917 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99918 {
99919 int len, ret = -EFAULT;
99920+ struct icmp_filter filter;
99921
99922 if (get_user(len, optlen))
99923 goto out;
99924@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99925 if (len > sizeof(struct icmp_filter))
99926 len = sizeof(struct icmp_filter);
99927 ret = -EFAULT;
99928- if (put_user(len, optlen) ||
99929- copy_to_user(optval, &raw_sk(sk)->filter, len))
99930+ filter = raw_sk(sk)->filter;
99931+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99932 goto out;
99933 ret = 0;
99934 out: return ret;
99935@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99936 0, 0L, 0,
99937 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99938 0, sock_i_ino(sp),
99939- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99940+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99941 }
99942
99943 static int raw_seq_show(struct seq_file *seq, void *v)
99944diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99945index fd618d4..aae0ac9 100644
99946--- a/net/ipv4/route.c
99947+++ b/net/ipv4/route.c
99948@@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99949
99950 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99951 {
99952- return seq_open(file, &rt_cache_seq_ops);
99953+ return seq_open_restrict(file, &rt_cache_seq_ops);
99954 }
99955
99956 static const struct file_operations rt_cache_seq_fops = {
99957@@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99958
99959 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99960 {
99961- return seq_open(file, &rt_cpu_seq_ops);
99962+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99963 }
99964
99965 static const struct file_operations rt_cpu_seq_fops = {
99966@@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99967
99968 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99969 {
99970- return single_open(file, rt_acct_proc_show, NULL);
99971+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99972 }
99973
99974 static const struct file_operations rt_acct_proc_fops = {
99975@@ -459,7 +459,7 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
99976
99977 #define IP_IDENTS_SZ 2048u
99978 struct ip_ident_bucket {
99979- atomic_t id;
99980+ atomic_unchecked_t id;
99981 u32 stamp32;
99982 };
99983
99984@@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
99985 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
99986 delta = prandom_u32_max(now - old);
99987
99988- return atomic_add_return(segs + delta, &bucket->id) - segs;
99989+ return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
99990 }
99991 EXPORT_SYMBOL(ip_idents_reserve);
99992
99993@@ -2618,34 +2618,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99994 .maxlen = sizeof(int),
99995 .mode = 0200,
99996 .proc_handler = ipv4_sysctl_rtcache_flush,
99997+ .extra1 = &init_net,
99998 },
99999 { },
100000 };
100001
100002 static __net_init int sysctl_route_net_init(struct net *net)
100003 {
100004- struct ctl_table *tbl;
100005+ ctl_table_no_const *tbl = NULL;
100006
100007- tbl = ipv4_route_flush_table;
100008 if (!net_eq(net, &init_net)) {
100009- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
100010+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
100011 if (tbl == NULL)
100012 goto err_dup;
100013
100014 /* Don't export sysctls to unprivileged users */
100015 if (net->user_ns != &init_user_ns)
100016 tbl[0].procname = NULL;
100017- }
100018- tbl[0].extra1 = net;
100019+ tbl[0].extra1 = net;
100020+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
100021+ } else
100022+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
100023
100024- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
100025 if (net->ipv4.route_hdr == NULL)
100026 goto err_reg;
100027 return 0;
100028
100029 err_reg:
100030- if (tbl != ipv4_route_flush_table)
100031- kfree(tbl);
100032+ kfree(tbl);
100033 err_dup:
100034 return -ENOMEM;
100035 }
100036@@ -2668,8 +2668,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
100037
100038 static __net_init int rt_genid_init(struct net *net)
100039 {
100040- atomic_set(&net->ipv4.rt_genid, 0);
100041- atomic_set(&net->fnhe_genid, 0);
100042+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
100043+ atomic_set_unchecked(&net->fnhe_genid, 0);
100044 get_random_bytes(&net->ipv4.dev_addr_genid,
100045 sizeof(net->ipv4.dev_addr_genid));
100046 return 0;
100047diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
100048index 5cde8f2..5f5684e 100644
100049--- a/net/ipv4/sysctl_net_ipv4.c
100050+++ b/net/ipv4/sysctl_net_ipv4.c
100051@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
100052 container_of(table->data, struct net, ipv4.ip_local_ports.range);
100053 int ret;
100054 int range[2];
100055- struct ctl_table tmp = {
100056+ ctl_table_no_const tmp = {
100057 .data = &range,
100058 .maxlen = sizeof(range),
100059 .mode = table->mode,
100060@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
100061 int ret;
100062 gid_t urange[2];
100063 kgid_t low, high;
100064- struct ctl_table tmp = {
100065+ ctl_table_no_const tmp = {
100066 .data = &urange,
100067 .maxlen = sizeof(urange),
100068 .mode = table->mode,
100069@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
100070 void __user *buffer, size_t *lenp, loff_t *ppos)
100071 {
100072 char val[TCP_CA_NAME_MAX];
100073- struct ctl_table tbl = {
100074+ ctl_table_no_const tbl = {
100075 .data = val,
100076 .maxlen = TCP_CA_NAME_MAX,
100077 };
100078@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
100079 void __user *buffer, size_t *lenp,
100080 loff_t *ppos)
100081 {
100082- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
100083+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
100084 int ret;
100085
100086 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100087@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
100088 void __user *buffer, size_t *lenp,
100089 loff_t *ppos)
100090 {
100091- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
100092+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
100093 int ret;
100094
100095 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100096@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
100097 void __user *buffer, size_t *lenp,
100098 loff_t *ppos)
100099 {
100100- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100101+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100102 struct tcp_fastopen_context *ctxt;
100103 int ret;
100104 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
100105@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
100106 },
100107 {
100108 .procname = "ip_local_reserved_ports",
100109- .data = NULL, /* initialized in sysctl_ipv4_init */
100110+ .data = sysctl_local_reserved_ports,
100111 .maxlen = 65536,
100112 .mode = 0644,
100113 .proc_handler = proc_do_large_bitmap,
100114@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
100115
100116 static __net_init int ipv4_sysctl_init_net(struct net *net)
100117 {
100118- struct ctl_table *table;
100119+ ctl_table_no_const *table = NULL;
100120
100121- table = ipv4_net_table;
100122 if (!net_eq(net, &init_net)) {
100123 int i;
100124
100125- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
100126+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
100127 if (table == NULL)
100128 goto err_alloc;
100129
100130@@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
100131 table[i].data += (void *)net - (void *)&init_net;
100132 }
100133
100134- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100135+ if (!net_eq(net, &init_net))
100136+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100137+ else
100138+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
100139 if (net->ipv4.ipv4_hdr == NULL)
100140 goto err_reg;
100141
100142 return 0;
100143
100144 err_reg:
100145- if (!net_eq(net, &init_net))
100146- kfree(table);
100147+ kfree(table);
100148 err_alloc:
100149 return -ENOMEM;
100150 }
100151@@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
100152 static __init int sysctl_ipv4_init(void)
100153 {
100154 struct ctl_table_header *hdr;
100155- struct ctl_table *i;
100156-
100157- for (i = ipv4_table; i->procname; i++) {
100158- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
100159- i->data = sysctl_local_reserved_ports;
100160- break;
100161- }
100162- }
100163- if (!i->procname)
100164- return -EINVAL;
100165
100166 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
100167 if (hdr == NULL)
100168diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
100169index 09b85cd..df9c266 100644
100170--- a/net/ipv4/tcp_input.c
100171+++ b/net/ipv4/tcp_input.c
100172@@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
100173 * without any lock. We want to make sure compiler wont store
100174 * intermediate values in this location.
100175 */
100176- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
100177+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
100178 sk->sk_max_pacing_rate);
100179 }
100180
100181@@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
100182 * simplifies code)
100183 */
100184 static void
100185-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100186+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100187 struct sk_buff *head, struct sk_buff *tail,
100188 u32 start, u32 end)
100189 {
100190@@ -5558,6 +5558,7 @@ discard:
100191 tcp_paws_reject(&tp->rx_opt, 0))
100192 goto discard_and_undo;
100193
100194+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
100195 if (th->syn) {
100196 /* We see SYN without ACK. It is attempt of
100197 * simultaneous connect with crossed SYNs.
100198@@ -5608,6 +5609,7 @@ discard:
100199 goto discard;
100200 #endif
100201 }
100202+#endif
100203 /* "fifth, if neither of the SYN or RST bits is set then
100204 * drop the segment and return."
100205 */
100206@@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
100207 goto discard;
100208
100209 if (th->syn) {
100210- if (th->fin)
100211+ if (th->fin || th->urg || th->psh)
100212 goto discard;
100213 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
100214 return 1;
100215diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
100216index 438f3b9..bc9e1ad 100644
100217--- a/net/ipv4/tcp_ipv4.c
100218+++ b/net/ipv4/tcp_ipv4.c
100219@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
100220 EXPORT_SYMBOL(sysctl_tcp_low_latency);
100221
100222
100223+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100224+extern int grsec_enable_blackhole;
100225+#endif
100226+
100227 #ifdef CONFIG_TCP_MD5SIG
100228 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
100229 __be32 daddr, __be32 saddr, const struct tcphdr *th);
100230@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
100231 return 0;
100232
100233 reset:
100234+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100235+ if (!grsec_enable_blackhole)
100236+#endif
100237 tcp_v4_send_reset(rsk, skb);
100238 discard:
100239 kfree_skb(skb);
100240@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
100241 TCP_SKB_CB(skb)->sacked = 0;
100242
100243 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100244- if (!sk)
100245+ if (!sk) {
100246+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100247+ ret = 1;
100248+#endif
100249 goto no_tcp_socket;
100250-
100251+ }
100252 process:
100253- if (sk->sk_state == TCP_TIME_WAIT)
100254+ if (sk->sk_state == TCP_TIME_WAIT) {
100255+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100256+ ret = 2;
100257+#endif
100258 goto do_time_wait;
100259+ }
100260
100261 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
100262 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100263@@ -2033,6 +2047,10 @@ csum_error:
100264 bad_packet:
100265 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100266 } else {
100267+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100268+ if (!grsec_enable_blackhole || (ret == 1 &&
100269+ (skb->dev->flags & IFF_LOOPBACK)))
100270+#endif
100271 tcp_v4_send_reset(NULL, skb);
100272 }
100273
100274diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
100275index 05c1b15..3e9344b 100644
100276--- a/net/ipv4/tcp_minisocks.c
100277+++ b/net/ipv4/tcp_minisocks.c
100278@@ -27,6 +27,10 @@
100279 #include <net/inet_common.h>
100280 #include <net/xfrm.h>
100281
100282+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100283+extern int grsec_enable_blackhole;
100284+#endif
100285+
100286 int sysctl_tcp_syncookies __read_mostly = 1;
100287 EXPORT_SYMBOL(sysctl_tcp_syncookies);
100288
100289@@ -709,7 +713,10 @@ embryonic_reset:
100290 * avoid becoming vulnerable to outside attack aiming at
100291 * resetting legit local connections.
100292 */
100293- req->rsk_ops->send_reset(sk, skb);
100294+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100295+ if (!grsec_enable_blackhole)
100296+#endif
100297+ req->rsk_ops->send_reset(sk, skb);
100298 } else if (fastopen) { /* received a valid RST pkt */
100299 reqsk_fastopen_remove(sk, req, true);
100300 tcp_reset(sk);
100301diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
100302index 3b66610..bfbe23a 100644
100303--- a/net/ipv4/tcp_probe.c
100304+++ b/net/ipv4/tcp_probe.c
100305@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
100306 if (cnt + width >= len)
100307 break;
100308
100309- if (copy_to_user(buf + cnt, tbuf, width))
100310+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
100311 return -EFAULT;
100312 cnt += width;
100313 }
100314diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
100315index 286227a..c495a76 100644
100316--- a/net/ipv4/tcp_timer.c
100317+++ b/net/ipv4/tcp_timer.c
100318@@ -22,6 +22,10 @@
100319 #include <linux/gfp.h>
100320 #include <net/tcp.h>
100321
100322+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100323+extern int grsec_lastack_retries;
100324+#endif
100325+
100326 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
100327 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
100328 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
100329@@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
100330 }
100331 }
100332
100333+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100334+ if ((sk->sk_state == TCP_LAST_ACK) &&
100335+ (grsec_lastack_retries > 0) &&
100336+ (grsec_lastack_retries < retry_until))
100337+ retry_until = grsec_lastack_retries;
100338+#endif
100339+
100340 if (retransmits_timed_out(sk, retry_until,
100341 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100342 /* Has it gone just too far? */
100343diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100344index 54a5fe9..78fea00 100644
100345--- a/net/ipv4/udp.c
100346+++ b/net/ipv4/udp.c
100347@@ -87,6 +87,7 @@
100348 #include <linux/types.h>
100349 #include <linux/fcntl.h>
100350 #include <linux/module.h>
100351+#include <linux/security.h>
100352 #include <linux/socket.h>
100353 #include <linux/sockios.h>
100354 #include <linux/igmp.h>
100355@@ -113,6 +114,10 @@
100356 #include <net/busy_poll.h>
100357 #include "udp_impl.h"
100358
100359+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100360+extern int grsec_enable_blackhole;
100361+#endif
100362+
100363 struct udp_table udp_table __read_mostly;
100364 EXPORT_SYMBOL(udp_table);
100365
100366@@ -615,6 +620,9 @@ found:
100367 return s;
100368 }
100369
100370+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100371+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100372+
100373 /*
100374 * This routine is called by the ICMP module when it gets some
100375 * sort of error condition. If err < 0 then the socket should
100376@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100377 dport = usin->sin_port;
100378 if (dport == 0)
100379 return -EINVAL;
100380+
100381+ err = gr_search_udp_sendmsg(sk, usin);
100382+ if (err)
100383+ return err;
100384 } else {
100385 if (sk->sk_state != TCP_ESTABLISHED)
100386 return -EDESTADDRREQ;
100387+
100388+ err = gr_search_udp_sendmsg(sk, NULL);
100389+ if (err)
100390+ return err;
100391+
100392 daddr = inet->inet_daddr;
100393 dport = inet->inet_dport;
100394 /* Open fast path for connected socket.
100395@@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100396 IS_UDPLITE(sk));
100397 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100398 IS_UDPLITE(sk));
100399- atomic_inc(&sk->sk_drops);
100400+ atomic_inc_unchecked(&sk->sk_drops);
100401 __skb_unlink(skb, rcvq);
100402 __skb_queue_tail(&list_kill, skb);
100403 }
100404@@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100405 int is_udplite = IS_UDPLITE(sk);
100406 bool slow;
100407
100408+ /*
100409+ * Check any passed addresses
100410+ */
100411+ if (addr_len)
100412+ *addr_len = sizeof(*sin);
100413+
100414 if (flags & MSG_ERRQUEUE)
100415 return ip_recv_error(sk, msg, len, addr_len);
100416
100417@@ -1244,6 +1267,10 @@ try_again:
100418 if (!skb)
100419 goto out;
100420
100421+ err = gr_search_udp_recvmsg(sk, skb);
100422+ if (err)
100423+ goto out_free;
100424+
100425 ulen = skb->len - sizeof(struct udphdr);
100426 copied = len;
100427 if (copied > ulen)
100428@@ -1277,7 +1304,7 @@ try_again:
100429 if (unlikely(err)) {
100430 trace_kfree_skb(skb, udp_recvmsg);
100431 if (!peeked) {
100432- atomic_inc(&sk->sk_drops);
100433+ atomic_inc_unchecked(&sk->sk_drops);
100434 UDP_INC_STATS_USER(sock_net(sk),
100435 UDP_MIB_INERRORS, is_udplite);
100436 }
100437@@ -1296,7 +1323,6 @@ try_again:
100438 sin->sin_port = udp_hdr(skb)->source;
100439 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100440 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100441- *addr_len = sizeof(*sin);
100442 }
100443 if (inet->cmsg_flags)
100444 ip_cmsg_recv(msg, skb);
100445@@ -1567,7 +1593,7 @@ csum_error:
100446 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100447 drop:
100448 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100449- atomic_inc(&sk->sk_drops);
100450+ atomic_inc_unchecked(&sk->sk_drops);
100451 kfree_skb(skb);
100452 return -1;
100453 }
100454@@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100455 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100456
100457 if (!skb1) {
100458- atomic_inc(&sk->sk_drops);
100459+ atomic_inc_unchecked(&sk->sk_drops);
100460 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100461 IS_UDPLITE(sk));
100462 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100463@@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100464 goto csum_error;
100465
100466 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100467+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100468+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100469+#endif
100470 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100471
100472 /*
100473@@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100474 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100475 0, sock_i_ino(sp),
100476 atomic_read(&sp->sk_refcnt), sp,
100477- atomic_read(&sp->sk_drops));
100478+ atomic_read_unchecked(&sp->sk_drops));
100479 }
100480
100481 int udp4_seq_show(struct seq_file *seq, void *v)
100482diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100483index 6156f68..d6ab46d 100644
100484--- a/net/ipv4/xfrm4_policy.c
100485+++ b/net/ipv4/xfrm4_policy.c
100486@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100487 fl4->flowi4_tos = iph->tos;
100488 }
100489
100490-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100491+static int xfrm4_garbage_collect(struct dst_ops *ops)
100492 {
100493 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100494
100495- xfrm4_policy_afinfo.garbage_collect(net);
100496+ xfrm_garbage_collect_deferred(net);
100497 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100498 }
100499
100500@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100501
100502 static int __net_init xfrm4_net_init(struct net *net)
100503 {
100504- struct ctl_table *table;
100505+ ctl_table_no_const *table = NULL;
100506 struct ctl_table_header *hdr;
100507
100508- table = xfrm4_policy_table;
100509 if (!net_eq(net, &init_net)) {
100510- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100511+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100512 if (!table)
100513 goto err_alloc;
100514
100515 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100516- }
100517-
100518- hdr = register_net_sysctl(net, "net/ipv4", table);
100519+ hdr = register_net_sysctl(net, "net/ipv4", table);
100520+ } else
100521+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100522 if (!hdr)
100523 goto err_reg;
100524
100525@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100526 return 0;
100527
100528 err_reg:
100529- if (!net_eq(net, &init_net))
100530- kfree(table);
100531+ kfree(table);
100532 err_alloc:
100533 return -ENOMEM;
100534 }
100535diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100536index 6c7fa08..8a31430 100644
100537--- a/net/ipv6/addrconf.c
100538+++ b/net/ipv6/addrconf.c
100539@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100540 idx = 0;
100541 head = &net->dev_index_head[h];
100542 rcu_read_lock();
100543- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100544+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100545 net->dev_base_seq;
100546 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100547 if (idx < s_idx)
100548@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100549 p.iph.ihl = 5;
100550 p.iph.protocol = IPPROTO_IPV6;
100551 p.iph.ttl = 64;
100552- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100553+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100554
100555 if (ops->ndo_do_ioctl) {
100556 mm_segment_t oldfs = get_fs();
100557@@ -3528,16 +3528,23 @@ static const struct file_operations if6_fops = {
100558 .release = seq_release_net,
100559 };
100560
100561+extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
100562+extern void unregister_ipv6_seq_ops_addr(void);
100563+
100564 static int __net_init if6_proc_net_init(struct net *net)
100565 {
100566- if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
100567+ register_ipv6_seq_ops_addr(&if6_seq_ops);
100568+ if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
100569+ unregister_ipv6_seq_ops_addr();
100570 return -ENOMEM;
100571+ }
100572 return 0;
100573 }
100574
100575 static void __net_exit if6_proc_net_exit(struct net *net)
100576 {
100577 remove_proc_entry("if_inet6", net->proc_net);
100578+ unregister_ipv6_seq_ops_addr();
100579 }
100580
100581 static struct pernet_operations if6_proc_net_ops = {
100582@@ -4146,7 +4153,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100583 s_ip_idx = ip_idx = cb->args[2];
100584
100585 rcu_read_lock();
100586- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100587+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100588 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100589 idx = 0;
100590 head = &net->dev_index_head[h];
100591@@ -4758,7 +4765,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100592 dst_free(&ifp->rt->dst);
100593 break;
100594 }
100595- atomic_inc(&net->ipv6.dev_addr_genid);
100596+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100597 rt_genid_bump_ipv6(net);
100598 }
100599
100600@@ -4779,7 +4786,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100601 int *valp = ctl->data;
100602 int val = *valp;
100603 loff_t pos = *ppos;
100604- struct ctl_table lctl;
100605+ ctl_table_no_const lctl;
100606 int ret;
100607
100608 /*
100609@@ -4864,7 +4871,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100610 int *valp = ctl->data;
100611 int val = *valp;
100612 loff_t pos = *ppos;
100613- struct ctl_table lctl;
100614+ ctl_table_no_const lctl;
100615 int ret;
100616
100617 /*
100618diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100619index d935889..2f64330 100644
100620--- a/net/ipv6/af_inet6.c
100621+++ b/net/ipv6/af_inet6.c
100622@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100623 net->ipv6.sysctl.bindv6only = 0;
100624 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100625 net->ipv6.sysctl.flowlabel_consistency = 1;
100626- atomic_set(&net->ipv6.rt_genid, 0);
100627+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100628
100629 err = ipv6_init_mibs(net);
100630 if (err)
100631diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100632index c3bf2d2..1f00573 100644
100633--- a/net/ipv6/datagram.c
100634+++ b/net/ipv6/datagram.c
100635@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100636 0,
100637 sock_i_ino(sp),
100638 atomic_read(&sp->sk_refcnt), sp,
100639- atomic_read(&sp->sk_drops));
100640+ atomic_read_unchecked(&sp->sk_drops));
100641 }
100642diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100643index 7b32652..0bc348b 100644
100644--- a/net/ipv6/icmp.c
100645+++ b/net/ipv6/icmp.c
100646@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100647
100648 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100649 {
100650- struct ctl_table *table;
100651+ ctl_table_no_const *table;
100652
100653 table = kmemdup(ipv6_icmp_table_template,
100654 sizeof(ipv6_icmp_table_template),
100655diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100656index 9d92146..d986c6a 100644
100657--- a/net/ipv6/ip6_gre.c
100658+++ b/net/ipv6/ip6_gre.c
100659@@ -71,7 +71,7 @@ struct ip6gre_net {
100660 struct net_device *fb_tunnel_dev;
100661 };
100662
100663-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100664+static struct rtnl_link_ops ip6gre_link_ops;
100665 static int ip6gre_tunnel_init(struct net_device *dev);
100666 static void ip6gre_tunnel_setup(struct net_device *dev);
100667 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100668@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100669 }
100670
100671
100672-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100673+static struct inet6_protocol ip6gre_protocol = {
100674 .handler = ip6gre_rcv,
100675 .err_handler = ip6gre_err,
100676 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100677@@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100678 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100679 };
100680
100681-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100682+static struct rtnl_link_ops ip6gre_link_ops = {
100683 .kind = "ip6gre",
100684 .maxtype = IFLA_GRE_MAX,
100685 .policy = ip6gre_policy,
100686@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100687 .fill_info = ip6gre_fill_info,
100688 };
100689
100690-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100691+static struct rtnl_link_ops ip6gre_tap_ops = {
100692 .kind = "ip6gretap",
100693 .maxtype = IFLA_GRE_MAX,
100694 .policy = ip6gre_policy,
100695diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100696index afa0824..04ba530 100644
100697--- a/net/ipv6/ip6_tunnel.c
100698+++ b/net/ipv6/ip6_tunnel.c
100699@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100700
100701 static int ip6_tnl_dev_init(struct net_device *dev);
100702 static void ip6_tnl_dev_setup(struct net_device *dev);
100703-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100704+static struct rtnl_link_ops ip6_link_ops;
100705
100706 static int ip6_tnl_net_id __read_mostly;
100707 struct ip6_tnl_net {
100708@@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100709 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100710 };
100711
100712-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100713+static struct rtnl_link_ops ip6_link_ops = {
100714 .kind = "ip6tnl",
100715 .maxtype = IFLA_IPTUN_MAX,
100716 .policy = ip6_tnl_policy,
100717diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100718index 6cc9f93..6e5bb7c 100644
100719--- a/net/ipv6/ip6_vti.c
100720+++ b/net/ipv6/ip6_vti.c
100721@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100722
100723 static int vti6_dev_init(struct net_device *dev);
100724 static void vti6_dev_setup(struct net_device *dev);
100725-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100726+static struct rtnl_link_ops vti6_link_ops;
100727
100728 static int vti6_net_id __read_mostly;
100729 struct vti6_net {
100730@@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100731 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100732 };
100733
100734-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100735+static struct rtnl_link_ops vti6_link_ops = {
100736 .kind = "vti6",
100737 .maxtype = IFLA_VTI_MAX,
100738 .policy = vti6_policy,
100739diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100740index edb58af..78de133 100644
100741--- a/net/ipv6/ipv6_sockglue.c
100742+++ b/net/ipv6/ipv6_sockglue.c
100743@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100744 if (sk->sk_type != SOCK_STREAM)
100745 return -ENOPROTOOPT;
100746
100747- msg.msg_control = optval;
100748+ msg.msg_control = (void __force_kernel *)optval;
100749 msg.msg_controllen = len;
100750 msg.msg_flags = flags;
100751
100752diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100753index e080fbb..412b3cf 100644
100754--- a/net/ipv6/netfilter/ip6_tables.c
100755+++ b/net/ipv6/netfilter/ip6_tables.c
100756@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100757 #endif
100758
100759 static int get_info(struct net *net, void __user *user,
100760- const int *len, int compat)
100761+ int len, int compat)
100762 {
100763 char name[XT_TABLE_MAXNAMELEN];
100764 struct xt_table *t;
100765 int ret;
100766
100767- if (*len != sizeof(struct ip6t_getinfo)) {
100768- duprintf("length %u != %zu\n", *len,
100769+ if (len != sizeof(struct ip6t_getinfo)) {
100770+ duprintf("length %u != %zu\n", len,
100771 sizeof(struct ip6t_getinfo));
100772 return -EINVAL;
100773 }
100774@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100775 info.size = private->size;
100776 strcpy(info.name, name);
100777
100778- if (copy_to_user(user, &info, *len) != 0)
100779+ if (copy_to_user(user, &info, len) != 0)
100780 ret = -EFAULT;
100781 else
100782 ret = 0;
100783@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100784
100785 switch (cmd) {
100786 case IP6T_SO_GET_INFO:
100787- ret = get_info(sock_net(sk), user, len, 1);
100788+ ret = get_info(sock_net(sk), user, *len, 1);
100789 break;
100790 case IP6T_SO_GET_ENTRIES:
100791 ret = compat_get_entries(sock_net(sk), user, len);
100792@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100793
100794 switch (cmd) {
100795 case IP6T_SO_GET_INFO:
100796- ret = get_info(sock_net(sk), user, len, 0);
100797+ ret = get_info(sock_net(sk), user, *len, 0);
100798 break;
100799
100800 case IP6T_SO_GET_ENTRIES:
100801diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100802index 767ab8d..c5ec70a 100644
100803--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100804+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100805@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100806
100807 static int nf_ct_frag6_sysctl_register(struct net *net)
100808 {
100809- struct ctl_table *table;
100810+ ctl_table_no_const *table = NULL;
100811 struct ctl_table_header *hdr;
100812
100813- table = nf_ct_frag6_sysctl_table;
100814 if (!net_eq(net, &init_net)) {
100815- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100816+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100817 GFP_KERNEL);
100818 if (table == NULL)
100819 goto err_alloc;
100820@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100821 table[0].data = &net->nf_frag.frags.timeout;
100822 table[1].data = &net->nf_frag.frags.low_thresh;
100823 table[2].data = &net->nf_frag.frags.high_thresh;
100824- }
100825-
100826- hdr = register_net_sysctl(net, "net/netfilter", table);
100827+ hdr = register_net_sysctl(net, "net/netfilter", table);
100828+ } else
100829+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100830 if (hdr == NULL)
100831 goto err_reg;
100832
100833@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100834 return 0;
100835
100836 err_reg:
100837- if (!net_eq(net, &init_net))
100838- kfree(table);
100839+ kfree(table);
100840 err_alloc:
100841 return -ENOMEM;
100842 }
100843diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100844index 6179ac1..ffa0293 100644
100845--- a/net/ipv6/output_core.c
100846+++ b/net/ipv6/output_core.c
100847@@ -8,7 +8,6 @@
100848 #include <net/addrconf.h>
100849 #include <net/secure_seq.h>
100850
100851-
100852 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
100853 {
100854 u16 offset = sizeof(struct ipv6hdr);
100855diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100856index bda7429..469b26b 100644
100857--- a/net/ipv6/ping.c
100858+++ b/net/ipv6/ping.c
100859@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100860 };
100861 #endif
100862
100863+static struct pingv6_ops real_pingv6_ops = {
100864+ .ipv6_recv_error = ipv6_recv_error,
100865+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100866+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100867+ .icmpv6_err_convert = icmpv6_err_convert,
100868+ .ipv6_icmp_error = ipv6_icmp_error,
100869+ .ipv6_chk_addr = ipv6_chk_addr,
100870+};
100871+
100872+static struct pingv6_ops dummy_pingv6_ops = {
100873+ .ipv6_recv_error = dummy_ipv6_recv_error,
100874+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100875+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100876+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
100877+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
100878+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
100879+};
100880+
100881 int __init pingv6_init(void)
100882 {
100883 #ifdef CONFIG_PROC_FS
100884@@ -253,13 +271,7 @@ int __init pingv6_init(void)
100885 if (ret)
100886 return ret;
100887 #endif
100888- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100889- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100890- pingv6_ops.ip6_datagram_recv_specific_ctl =
100891- ip6_datagram_recv_specific_ctl;
100892- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100893- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100894- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100895+ pingv6_ops = &real_pingv6_ops;
100896 return inet6_register_protosw(&pingv6_protosw);
100897 }
100898
100899@@ -268,14 +280,9 @@ int __init pingv6_init(void)
100900 */
100901 void pingv6_exit(void)
100902 {
100903- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100904- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100905- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100906- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100907- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100908- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100909 #ifdef CONFIG_PROC_FS
100910 unregister_pernet_subsys(&ping_v6_net_ops);
100911 #endif
100912+ pingv6_ops = &dummy_pingv6_ops;
100913 inet6_unregister_protosw(&pingv6_protosw);
100914 }
100915diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100916index 091d066..139d410 100644
100917--- a/net/ipv6/proc.c
100918+++ b/net/ipv6/proc.c
100919@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100920 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100921 goto proc_snmp6_fail;
100922
100923- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100924+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100925 if (!net->mib.proc_net_devsnmp6)
100926 goto proc_dev_snmp6_fail;
100927 return 0;
100928diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100929index 1f29996..46fe0c7 100644
100930--- a/net/ipv6/raw.c
100931+++ b/net/ipv6/raw.c
100932@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100933 {
100934 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100935 skb_checksum_complete(skb)) {
100936- atomic_inc(&sk->sk_drops);
100937+ atomic_inc_unchecked(&sk->sk_drops);
100938 kfree_skb(skb);
100939 return NET_RX_DROP;
100940 }
100941@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100942 struct raw6_sock *rp = raw6_sk(sk);
100943
100944 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100945- atomic_inc(&sk->sk_drops);
100946+ atomic_inc_unchecked(&sk->sk_drops);
100947 kfree_skb(skb);
100948 return NET_RX_DROP;
100949 }
100950@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100951
100952 if (inet->hdrincl) {
100953 if (skb_checksum_complete(skb)) {
100954- atomic_inc(&sk->sk_drops);
100955+ atomic_inc_unchecked(&sk->sk_drops);
100956 kfree_skb(skb);
100957 return NET_RX_DROP;
100958 }
100959@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100960 if (flags & MSG_OOB)
100961 return -EOPNOTSUPP;
100962
100963+ if (addr_len)
100964+ *addr_len=sizeof(*sin6);
100965+
100966 if (flags & MSG_ERRQUEUE)
100967 return ipv6_recv_error(sk, msg, len, addr_len);
100968
100969@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100970 sin6->sin6_flowinfo = 0;
100971 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100972 IP6CB(skb)->iif);
100973- *addr_len = sizeof(*sin6);
100974 }
100975
100976 sock_recv_ts_and_drops(msg, sk, skb);
100977@@ -610,7 +612,7 @@ out:
100978 return err;
100979 }
100980
100981-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100982+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100983 struct flowi6 *fl6, struct dst_entry **dstp,
100984 unsigned int flags)
100985 {
100986@@ -922,12 +924,15 @@ do_confirm:
100987 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100988 char __user *optval, int optlen)
100989 {
100990+ struct icmp6_filter filter;
100991+
100992 switch (optname) {
100993 case ICMPV6_FILTER:
100994 if (optlen > sizeof(struct icmp6_filter))
100995 optlen = sizeof(struct icmp6_filter);
100996- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100997+ if (copy_from_user(&filter, optval, optlen))
100998 return -EFAULT;
100999+ raw6_sk(sk)->filter = filter;
101000 return 0;
101001 default:
101002 return -ENOPROTOOPT;
101003@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
101004 char __user *optval, int __user *optlen)
101005 {
101006 int len;
101007+ struct icmp6_filter filter;
101008
101009 switch (optname) {
101010 case ICMPV6_FILTER:
101011@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
101012 len = sizeof(struct icmp6_filter);
101013 if (put_user(len, optlen))
101014 return -EFAULT;
101015- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
101016+ filter = raw6_sk(sk)->filter;
101017+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
101018 return -EFAULT;
101019 return 0;
101020 default:
101021diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
101022index cc85a9b..526a133 100644
101023--- a/net/ipv6/reassembly.c
101024+++ b/net/ipv6/reassembly.c
101025@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
101026
101027 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101028 {
101029- struct ctl_table *table;
101030+ ctl_table_no_const *table = NULL;
101031 struct ctl_table_header *hdr;
101032
101033- table = ip6_frags_ns_ctl_table;
101034 if (!net_eq(net, &init_net)) {
101035- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101036+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101037 if (table == NULL)
101038 goto err_alloc;
101039
101040@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101041 /* Don't export sysctls to unprivileged users */
101042 if (net->user_ns != &init_user_ns)
101043 table[0].procname = NULL;
101044- }
101045+ hdr = register_net_sysctl(net, "net/ipv6", table);
101046+ } else
101047+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
101048
101049- hdr = register_net_sysctl(net, "net/ipv6", table);
101050 if (hdr == NULL)
101051 goto err_reg;
101052
101053@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101054 return 0;
101055
101056 err_reg:
101057- if (!net_eq(net, &init_net))
101058- kfree(table);
101059+ kfree(table);
101060 err_alloc:
101061 return -ENOMEM;
101062 }
101063diff --git a/net/ipv6/route.c b/net/ipv6/route.c
101064index 6ebdb7b6..f225ab1 100644
101065--- a/net/ipv6/route.c
101066+++ b/net/ipv6/route.c
101067@@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
101068
101069 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
101070 {
101071- struct ctl_table *table;
101072+ ctl_table_no_const *table;
101073
101074 table = kmemdup(ipv6_route_table_template,
101075 sizeof(ipv6_route_table_template),
101076diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
101077index 4f40817..54dcbef 100644
101078--- a/net/ipv6/sit.c
101079+++ b/net/ipv6/sit.c
101080@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
101081 static void ipip6_dev_free(struct net_device *dev);
101082 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
101083 __be32 *v4dst);
101084-static struct rtnl_link_ops sit_link_ops __read_mostly;
101085+static struct rtnl_link_ops sit_link_ops;
101086
101087 static int sit_net_id __read_mostly;
101088 struct sit_net {
101089@@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
101090 unregister_netdevice_queue(dev, head);
101091 }
101092
101093-static struct rtnl_link_ops sit_link_ops __read_mostly = {
101094+static struct rtnl_link_ops sit_link_ops = {
101095 .kind = "sit",
101096 .maxtype = IFLA_IPTUN_MAX,
101097 .policy = ipip6_policy,
101098diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
101099index 7f405a1..eabef92 100644
101100--- a/net/ipv6/sysctl_net_ipv6.c
101101+++ b/net/ipv6/sysctl_net_ipv6.c
101102@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
101103
101104 static int __net_init ipv6_sysctl_net_init(struct net *net)
101105 {
101106- struct ctl_table *ipv6_table;
101107+ ctl_table_no_const *ipv6_table;
101108 struct ctl_table *ipv6_route_table;
101109 struct ctl_table *ipv6_icmp_table;
101110 int err;
101111diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
101112index e289830..79a5718 100644
101113--- a/net/ipv6/tcp_ipv6.c
101114+++ b/net/ipv6/tcp_ipv6.c
101115@@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
101116 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
101117 }
101118
101119+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101120+extern int grsec_enable_blackhole;
101121+#endif
101122+
101123 static void tcp_v6_hash(struct sock *sk)
101124 {
101125 if (sk->sk_state != TCP_CLOSE) {
101126@@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
101127 return 0;
101128
101129 reset:
101130+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101131+ if (!grsec_enable_blackhole)
101132+#endif
101133 tcp_v6_send_reset(sk, skb);
101134 discard:
101135 if (opt_skb)
101136@@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
101137 TCP_SKB_CB(skb)->sacked = 0;
101138
101139 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
101140- if (!sk)
101141+ if (!sk) {
101142+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101143+ ret = 1;
101144+#endif
101145 goto no_tcp_socket;
101146+ }
101147
101148 process:
101149- if (sk->sk_state == TCP_TIME_WAIT)
101150+ if (sk->sk_state == TCP_TIME_WAIT) {
101151+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101152+ ret = 2;
101153+#endif
101154 goto do_time_wait;
101155+ }
101156
101157 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
101158 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
101159@@ -1557,6 +1572,10 @@ csum_error:
101160 bad_packet:
101161 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
101162 } else {
101163+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101164+ if (!grsec_enable_blackhole || (ret == 1 &&
101165+ (skb->dev->flags & IFF_LOOPBACK)))
101166+#endif
101167 tcp_v6_send_reset(NULL, skb);
101168 }
101169
101170diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
101171index 20b63d2..13be908 100644
101172--- a/net/ipv6/udp.c
101173+++ b/net/ipv6/udp.c
101174@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
101175 udp_ipv6_hash_secret + net_hash_mix(net));
101176 }
101177
101178+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101179+extern int grsec_enable_blackhole;
101180+#endif
101181+
101182 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
101183 {
101184 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
101185@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101186 int is_udp4;
101187 bool slow;
101188
101189+ if (addr_len)
101190+ *addr_len = sizeof(struct sockaddr_in6);
101191+
101192 if (flags & MSG_ERRQUEUE)
101193 return ipv6_recv_error(sk, msg, len, addr_len);
101194
101195@@ -435,7 +442,7 @@ try_again:
101196 if (unlikely(err)) {
101197 trace_kfree_skb(skb, udpv6_recvmsg);
101198 if (!peeked) {
101199- atomic_inc(&sk->sk_drops);
101200+ atomic_inc_unchecked(&sk->sk_drops);
101201 if (is_udp4)
101202 UDP_INC_STATS_USER(sock_net(sk),
101203 UDP_MIB_INERRORS,
101204@@ -475,7 +482,7 @@ try_again:
101205 ipv6_iface_scope_id(&sin6->sin6_addr,
101206 IP6CB(skb)->iif);
101207 }
101208- *addr_len = sizeof(*sin6);
101209+
101210 }
101211
101212 if (np->rxopt.all)
101213@@ -690,7 +697,7 @@ csum_error:
101214 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
101215 drop:
101216 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
101217- atomic_inc(&sk->sk_drops);
101218+ atomic_inc_unchecked(&sk->sk_drops);
101219 kfree_skb(skb);
101220 return -1;
101221 }
101222@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
101223 if (likely(skb1 == NULL))
101224 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
101225 if (!skb1) {
101226- atomic_inc(&sk->sk_drops);
101227+ atomic_inc_unchecked(&sk->sk_drops);
101228 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
101229 IS_UDPLITE(sk));
101230 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
101231@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
101232 goto csum_error;
101233
101234 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
101235+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101236+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
101237+#endif
101238 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
101239
101240 kfree_skb(skb);
101241diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
101242index 2a0bbda..d75ca57 100644
101243--- a/net/ipv6/xfrm6_policy.c
101244+++ b/net/ipv6/xfrm6_policy.c
101245@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
101246 }
101247 }
101248
101249-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
101250+static int xfrm6_garbage_collect(struct dst_ops *ops)
101251 {
101252 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
101253
101254- xfrm6_policy_afinfo.garbage_collect(net);
101255+ xfrm_garbage_collect_deferred(net);
101256 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
101257 }
101258
101259@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
101260
101261 static int __net_init xfrm6_net_init(struct net *net)
101262 {
101263- struct ctl_table *table;
101264+ ctl_table_no_const *table = NULL;
101265 struct ctl_table_header *hdr;
101266
101267- table = xfrm6_policy_table;
101268 if (!net_eq(net, &init_net)) {
101269- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101270+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101271 if (!table)
101272 goto err_alloc;
101273
101274 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
101275- }
101276+ hdr = register_net_sysctl(net, "net/ipv6", table);
101277+ } else
101278+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
101279
101280- hdr = register_net_sysctl(net, "net/ipv6", table);
101281 if (!hdr)
101282 goto err_reg;
101283
101284@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
101285 return 0;
101286
101287 err_reg:
101288- if (!net_eq(net, &init_net))
101289- kfree(table);
101290+ kfree(table);
101291 err_alloc:
101292 return -ENOMEM;
101293 }
101294diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
101295index e15c16a..7cf07aa 100644
101296--- a/net/ipx/ipx_proc.c
101297+++ b/net/ipx/ipx_proc.c
101298@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
101299 struct proc_dir_entry *p;
101300 int rc = -ENOMEM;
101301
101302- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
101303+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
101304
101305 if (!ipx_proc_dir)
101306 goto out;
101307diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
101308index 2ba8b97..6d33010 100644
101309--- a/net/irda/ircomm/ircomm_tty.c
101310+++ b/net/irda/ircomm/ircomm_tty.c
101311@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101312 add_wait_queue(&port->open_wait, &wait);
101313
101314 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
101315- __FILE__, __LINE__, tty->driver->name, port->count);
101316+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101317
101318 spin_lock_irqsave(&port->lock, flags);
101319 if (!tty_hung_up_p(filp))
101320- port->count--;
101321+ atomic_dec(&port->count);
101322 port->blocked_open++;
101323 spin_unlock_irqrestore(&port->lock, flags);
101324
101325@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101326 }
101327
101328 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
101329- __FILE__, __LINE__, tty->driver->name, port->count);
101330+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101331
101332 schedule();
101333 }
101334@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101335
101336 spin_lock_irqsave(&port->lock, flags);
101337 if (!tty_hung_up_p(filp))
101338- port->count++;
101339+ atomic_inc(&port->count);
101340 port->blocked_open--;
101341 spin_unlock_irqrestore(&port->lock, flags);
101342
101343 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
101344- __FILE__, __LINE__, tty->driver->name, port->count);
101345+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101346
101347 if (!retval)
101348 port->flags |= ASYNC_NORMAL_ACTIVE;
101349@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101350
101351 /* ++ is not atomic, so this should be protected - Jean II */
101352 spin_lock_irqsave(&self->port.lock, flags);
101353- self->port.count++;
101354+ atomic_inc(&self->port.count);
101355 spin_unlock_irqrestore(&self->port.lock, flags);
101356 tty_port_tty_set(&self->port, tty);
101357
101358 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101359- self->line, self->port.count);
101360+ self->line, atomic_read(&self->port.count));
101361
101362 /* Not really used by us, but lets do it anyway */
101363 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101364@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101365 tty_kref_put(port->tty);
101366 }
101367 port->tty = NULL;
101368- port->count = 0;
101369+ atomic_set(&port->count, 0);
101370 spin_unlock_irqrestore(&port->lock, flags);
101371
101372 wake_up_interruptible(&port->open_wait);
101373@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101374 seq_putc(m, '\n');
101375
101376 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101377- seq_printf(m, "Open count: %d\n", self->port.count);
101378+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101379 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101380 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101381
101382diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101383index b9ac598..f88cc56 100644
101384--- a/net/irda/irproc.c
101385+++ b/net/irda/irproc.c
101386@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101387 {
101388 int i;
101389
101390- proc_irda = proc_mkdir("irda", init_net.proc_net);
101391+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101392 if (proc_irda == NULL)
101393 return;
101394
101395diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101396index 8c9d730..66c6305 100644
101397--- a/net/iucv/af_iucv.c
101398+++ b/net/iucv/af_iucv.c
101399@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101400
101401 write_lock_bh(&iucv_sk_list.lock);
101402
101403- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101404+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101405 while (__iucv_get_sock_by_name(name)) {
101406 sprintf(name, "%08x",
101407- atomic_inc_return(&iucv_sk_list.autobind_name));
101408+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101409 }
101410
101411 write_unlock_bh(&iucv_sk_list.lock);
101412diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101413index da78793..bdd78cf 100644
101414--- a/net/iucv/iucv.c
101415+++ b/net/iucv/iucv.c
101416@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101417 return NOTIFY_OK;
101418 }
101419
101420-static struct notifier_block __refdata iucv_cpu_notifier = {
101421+static struct notifier_block iucv_cpu_notifier = {
101422 .notifier_call = iucv_cpu_notify,
101423 };
101424
101425diff --git a/net/key/af_key.c b/net/key/af_key.c
101426index f3c8307..7127791 100644
101427--- a/net/key/af_key.c
101428+++ b/net/key/af_key.c
101429@@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101430 static u32 get_acqseq(void)
101431 {
101432 u32 res;
101433- static atomic_t acqseq;
101434+ static atomic_unchecked_t acqseq;
101435
101436 do {
101437- res = atomic_inc_return(&acqseq);
101438+ res = atomic_inc_return_unchecked(&acqseq);
101439 } while (!res);
101440 return res;
101441 }
101442diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101443index 76125c5..e474828 100644
101444--- a/net/l2tp/l2tp_eth.c
101445+++ b/net/l2tp/l2tp_eth.c
101446@@ -42,12 +42,12 @@ struct l2tp_eth {
101447 struct sock *tunnel_sock;
101448 struct l2tp_session *session;
101449 struct list_head list;
101450- atomic_long_t tx_bytes;
101451- atomic_long_t tx_packets;
101452- atomic_long_t tx_dropped;
101453- atomic_long_t rx_bytes;
101454- atomic_long_t rx_packets;
101455- atomic_long_t rx_errors;
101456+ atomic_long_unchecked_t tx_bytes;
101457+ atomic_long_unchecked_t tx_packets;
101458+ atomic_long_unchecked_t tx_dropped;
101459+ atomic_long_unchecked_t rx_bytes;
101460+ atomic_long_unchecked_t rx_packets;
101461+ atomic_long_unchecked_t rx_errors;
101462 };
101463
101464 /* via l2tp_session_priv() */
101465@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101466 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101467
101468 if (likely(ret == NET_XMIT_SUCCESS)) {
101469- atomic_long_add(len, &priv->tx_bytes);
101470- atomic_long_inc(&priv->tx_packets);
101471+ atomic_long_add_unchecked(len, &priv->tx_bytes);
101472+ atomic_long_inc_unchecked(&priv->tx_packets);
101473 } else {
101474- atomic_long_inc(&priv->tx_dropped);
101475+ atomic_long_inc_unchecked(&priv->tx_dropped);
101476 }
101477 return NETDEV_TX_OK;
101478 }
101479@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101480 {
101481 struct l2tp_eth *priv = netdev_priv(dev);
101482
101483- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101484- stats->tx_packets = atomic_long_read(&priv->tx_packets);
101485- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101486- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101487- stats->rx_packets = atomic_long_read(&priv->rx_packets);
101488- stats->rx_errors = atomic_long_read(&priv->rx_errors);
101489+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101490+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101491+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101492+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101493+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101494+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101495 return stats;
101496 }
101497
101498@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101499 nf_reset(skb);
101500
101501 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101502- atomic_long_inc(&priv->rx_packets);
101503- atomic_long_add(data_len, &priv->rx_bytes);
101504+ atomic_long_inc_unchecked(&priv->rx_packets);
101505+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101506 } else {
101507- atomic_long_inc(&priv->rx_errors);
101508+ atomic_long_inc_unchecked(&priv->rx_errors);
101509 }
101510 return;
101511
101512 error:
101513- atomic_long_inc(&priv->rx_errors);
101514+ atomic_long_inc_unchecked(&priv->rx_errors);
101515 kfree_skb(skb);
101516 }
101517
101518diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101519index 3397fe6..861fd1a 100644
101520--- a/net/l2tp/l2tp_ip.c
101521+++ b/net/l2tp/l2tp_ip.c
101522@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101523 if (flags & MSG_OOB)
101524 goto out;
101525
101526+ if (addr_len)
101527+ *addr_len = sizeof(*sin);
101528+
101529 skb = skb_recv_datagram(sk, flags, noblock, &err);
101530 if (!skb)
101531 goto out;
101532@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101533 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101534 sin->sin_port = 0;
101535 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101536- *addr_len = sizeof(*sin);
101537 }
101538 if (inet->cmsg_flags)
101539 ip_cmsg_recv(msg, skb);
101540diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101541index 1a3c7e0..80f8b0c 100644
101542--- a/net/llc/llc_proc.c
101543+++ b/net/llc/llc_proc.c
101544@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101545 int rc = -ENOMEM;
101546 struct proc_dir_entry *p;
101547
101548- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101549+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101550 if (!llc_proc_dir)
101551 goto out;
101552
101553diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101554index aaa59d7..21a2c4a 100644
101555--- a/net/mac80211/cfg.c
101556+++ b/net/mac80211/cfg.c
101557@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101558 ret = ieee80211_vif_use_channel(sdata, chandef,
101559 IEEE80211_CHANCTX_EXCLUSIVE);
101560 }
101561- } else if (local->open_count == local->monitors) {
101562+ } else if (local_read(&local->open_count) == local->monitors) {
101563 local->_oper_chandef = *chandef;
101564 ieee80211_hw_config(local, 0);
101565 }
101566@@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101567 else
101568 local->probe_req_reg--;
101569
101570- if (!local->open_count)
101571+ if (!local_read(&local->open_count))
101572 break;
101573
101574 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101575@@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101576 if (chanctx_conf) {
101577 *chandef = chanctx_conf->def;
101578 ret = 0;
101579- } else if (local->open_count > 0 &&
101580- local->open_count == local->monitors &&
101581+ } else if (local_read(&local->open_count) > 0 &&
101582+ local_read(&local->open_count) == local->monitors &&
101583 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101584 if (local->use_chanctx)
101585 *chandef = local->monitor_chandef;
101586diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101587index f169b6e..a5dc4eb 100644
101588--- a/net/mac80211/ieee80211_i.h
101589+++ b/net/mac80211/ieee80211_i.h
101590@@ -28,6 +28,7 @@
101591 #include <net/ieee80211_radiotap.h>
101592 #include <net/cfg80211.h>
101593 #include <net/mac80211.h>
101594+#include <asm/local.h>
101595 #include "key.h"
101596 #include "sta_info.h"
101597 #include "debug.h"
101598@@ -999,7 +1000,7 @@ struct ieee80211_local {
101599 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101600 spinlock_t queue_stop_reason_lock;
101601
101602- int open_count;
101603+ local_t open_count;
101604 int monitors, cooked_mntrs;
101605 /* number of interfaces with corresponding FIF_ flags */
101606 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101607diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101608index 34799e0..b411290 100644
101609--- a/net/mac80211/iface.c
101610+++ b/net/mac80211/iface.c
101611@@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101612 break;
101613 }
101614
101615- if (local->open_count == 0) {
101616+ if (local_read(&local->open_count) == 0) {
101617 res = drv_start(local);
101618 if (res)
101619 goto err_del_bss;
101620@@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101621 res = drv_add_interface(local, sdata);
101622 if (res)
101623 goto err_stop;
101624- } else if (local->monitors == 0 && local->open_count == 0) {
101625+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101626 res = ieee80211_add_virtual_monitor(local);
101627 if (res)
101628 goto err_stop;
101629@@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101630 atomic_inc(&local->iff_promiscs);
101631
101632 if (coming_up)
101633- local->open_count++;
101634+ local_inc(&local->open_count);
101635
101636 if (hw_reconf_flags)
101637 ieee80211_hw_config(local, hw_reconf_flags);
101638@@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101639 err_del_interface:
101640 drv_remove_interface(local, sdata);
101641 err_stop:
101642- if (!local->open_count)
101643+ if (!local_read(&local->open_count))
101644 drv_stop(local);
101645 err_del_bss:
101646 sdata->bss = NULL;
101647@@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101648 }
101649
101650 if (going_down)
101651- local->open_count--;
101652+ local_dec(&local->open_count);
101653
101654 switch (sdata->vif.type) {
101655 case NL80211_IFTYPE_AP_VLAN:
101656@@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101657 }
101658 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101659
101660- if (local->open_count == 0)
101661+ if (local_read(&local->open_count) == 0)
101662 ieee80211_clear_tx_pending(local);
101663
101664 /*
101665@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101666
101667 ieee80211_recalc_ps(local, -1);
101668
101669- if (local->open_count == 0) {
101670+ if (local_read(&local->open_count) == 0) {
101671 ieee80211_stop_device(local);
101672
101673 /* no reconfiguring after stop! */
101674@@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101675 ieee80211_configure_filter(local);
101676 ieee80211_hw_config(local, hw_reconf_flags);
101677
101678- if (local->monitors == local->open_count)
101679+ if (local->monitors == local_read(&local->open_count))
101680 ieee80211_add_virtual_monitor(local);
101681 }
101682
101683diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101684index 4c1bf61..00b449b 100644
101685--- a/net/mac80211/main.c
101686+++ b/net/mac80211/main.c
101687@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101688 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101689 IEEE80211_CONF_CHANGE_POWER);
101690
101691- if (changed && local->open_count) {
101692+ if (changed && local_read(&local->open_count)) {
101693 ret = drv_config(local, changed);
101694 /*
101695 * Goal:
101696diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101697index d478b88..8c8d157 100644
101698--- a/net/mac80211/pm.c
101699+++ b/net/mac80211/pm.c
101700@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101701 struct ieee80211_sub_if_data *sdata;
101702 struct sta_info *sta;
101703
101704- if (!local->open_count)
101705+ if (!local_read(&local->open_count))
101706 goto suspend;
101707
101708 ieee80211_scan_cancel(local);
101709@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101710 cancel_work_sync(&local->dynamic_ps_enable_work);
101711 del_timer_sync(&local->dynamic_ps_timer);
101712
101713- local->wowlan = wowlan && local->open_count;
101714+ local->wowlan = wowlan && local_read(&local->open_count);
101715 if (local->wowlan) {
101716 int err = drv_suspend(local, wowlan);
101717 if (err < 0) {
101718@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101719 WARN_ON(!list_empty(&local->chanctx_list));
101720
101721 /* stop hardware - this must stop RX */
101722- if (local->open_count)
101723+ if (local_read(&local->open_count))
101724 ieee80211_stop_device(local);
101725
101726 suspend:
101727diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101728index 8fdadfd..a4f72b8 100644
101729--- a/net/mac80211/rate.c
101730+++ b/net/mac80211/rate.c
101731@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101732
101733 ASSERT_RTNL();
101734
101735- if (local->open_count)
101736+ if (local_read(&local->open_count))
101737 return -EBUSY;
101738
101739 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101740diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101741index 6ff1346..936ca9a 100644
101742--- a/net/mac80211/rc80211_pid_debugfs.c
101743+++ b/net/mac80211/rc80211_pid_debugfs.c
101744@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101745
101746 spin_unlock_irqrestore(&events->lock, status);
101747
101748- if (copy_to_user(buf, pb, p))
101749+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101750 return -EFAULT;
101751
101752 return p;
101753diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101754index 3c36583..12887fe 100644
101755--- a/net/mac80211/util.c
101756+++ b/net/mac80211/util.c
101757@@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101758 }
101759 #endif
101760 /* everything else happens only if HW was up & running */
101761- if (!local->open_count)
101762+ if (!local_read(&local->open_count))
101763 goto wake_up;
101764
101765 /*
101766@@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101767 local->in_reconfig = false;
101768 barrier();
101769
101770- if (local->monitors == local->open_count && local->monitors > 0)
101771+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101772 ieee80211_add_virtual_monitor(local);
101773
101774 /*
101775diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101776index e9410d1..77b6378 100644
101777--- a/net/netfilter/Kconfig
101778+++ b/net/netfilter/Kconfig
101779@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101780
101781 To compile it as a module, choose M here. If unsure, say N.
101782
101783+config NETFILTER_XT_MATCH_GRADM
101784+ tristate '"gradm" match support'
101785+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101786+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101787+ ---help---
101788+ The gradm match allows to match on grsecurity RBAC being enabled.
101789+ It is useful when iptables rules are applied early on bootup to
101790+ prevent connections to the machine (except from a trusted host)
101791+ while the RBAC system is disabled.
101792+
101793 config NETFILTER_XT_MATCH_HASHLIMIT
101794 tristate '"hashlimit" match support'
101795 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101796diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101797index bffdad7..f9317d1 100644
101798--- a/net/netfilter/Makefile
101799+++ b/net/netfilter/Makefile
101800@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101801 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101802 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101803 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101804+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101805 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101806 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101807 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101808diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101809index 1172083..986f1c1 100644
101810--- a/net/netfilter/ipset/ip_set_core.c
101811+++ b/net/netfilter/ipset/ip_set_core.c
101812@@ -1924,7 +1924,7 @@ done:
101813 return ret;
101814 }
101815
101816-static struct nf_sockopt_ops so_set __read_mostly = {
101817+static struct nf_sockopt_ops so_set = {
101818 .pf = PF_INET,
101819 .get_optmin = SO_IP_SET,
101820 .get_optmax = SO_IP_SET + 1,
101821diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101822index a8eb0a8..86f2de4 100644
101823--- a/net/netfilter/ipvs/ip_vs_conn.c
101824+++ b/net/netfilter/ipvs/ip_vs_conn.c
101825@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101826 /* Increase the refcnt counter of the dest */
101827 ip_vs_dest_hold(dest);
101828
101829- conn_flags = atomic_read(&dest->conn_flags);
101830+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
101831 if (cp->protocol != IPPROTO_UDP)
101832 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101833 flags = cp->flags;
101834@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101835
101836 cp->control = NULL;
101837 atomic_set(&cp->n_control, 0);
101838- atomic_set(&cp->in_pkts, 0);
101839+ atomic_set_unchecked(&cp->in_pkts, 0);
101840
101841 cp->packet_xmit = NULL;
101842 cp->app = NULL;
101843@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101844
101845 /* Don't drop the entry if its number of incoming packets is not
101846 located in [0, 8] */
101847- i = atomic_read(&cp->in_pkts);
101848+ i = atomic_read_unchecked(&cp->in_pkts);
101849 if (i > 8 || i < 0) return 0;
101850
101851 if (!todrop_rate[i]) return 0;
101852diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101853index 3d2d2c8..c87e4d3 100644
101854--- a/net/netfilter/ipvs/ip_vs_core.c
101855+++ b/net/netfilter/ipvs/ip_vs_core.c
101856@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101857 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101858 /* do not touch skb anymore */
101859
101860- atomic_inc(&cp->in_pkts);
101861+ atomic_inc_unchecked(&cp->in_pkts);
101862 ip_vs_conn_put(cp);
101863 return ret;
101864 }
101865@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101866 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101867 pkts = sysctl_sync_threshold(ipvs);
101868 else
101869- pkts = atomic_add_return(1, &cp->in_pkts);
101870+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101871
101872 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101873 ip_vs_sync_conn(net, cp, pkts);
101874diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101875index c42e83d..a6a3f8b 100644
101876--- a/net/netfilter/ipvs/ip_vs_ctl.c
101877+++ b/net/netfilter/ipvs/ip_vs_ctl.c
101878@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101879 */
101880 ip_vs_rs_hash(ipvs, dest);
101881 }
101882- atomic_set(&dest->conn_flags, conn_flags);
101883+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
101884
101885 /* bind the service */
101886 old_svc = rcu_dereference_protected(dest->svc, 1);
101887@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101888 * align with netns init in ip_vs_control_net_init()
101889 */
101890
101891-static struct ctl_table vs_vars[] = {
101892+static ctl_table_no_const vs_vars[] __read_only = {
101893 {
101894 .procname = "amemthresh",
101895 .maxlen = sizeof(int),
101896@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101897 " %-7s %-6d %-10d %-10d\n",
101898 &dest->addr.in6,
101899 ntohs(dest->port),
101900- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101901+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101902 atomic_read(&dest->weight),
101903 atomic_read(&dest->activeconns),
101904 atomic_read(&dest->inactconns));
101905@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101906 "%-7s %-6d %-10d %-10d\n",
101907 ntohl(dest->addr.ip),
101908 ntohs(dest->port),
101909- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101910+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101911 atomic_read(&dest->weight),
101912 atomic_read(&dest->activeconns),
101913 atomic_read(&dest->inactconns));
101914@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101915
101916 entry.addr = dest->addr.ip;
101917 entry.port = dest->port;
101918- entry.conn_flags = atomic_read(&dest->conn_flags);
101919+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101920 entry.weight = atomic_read(&dest->weight);
101921 entry.u_threshold = dest->u_threshold;
101922 entry.l_threshold = dest->l_threshold;
101923@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101924 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101925 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101926 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101927- (atomic_read(&dest->conn_flags) &
101928+ (atomic_read_unchecked(&dest->conn_flags) &
101929 IP_VS_CONN_F_FWD_MASK)) ||
101930 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101931 atomic_read(&dest->weight)) ||
101932@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101933 {
101934 int idx;
101935 struct netns_ipvs *ipvs = net_ipvs(net);
101936- struct ctl_table *tbl;
101937+ ctl_table_no_const *tbl;
101938
101939 atomic_set(&ipvs->dropentry, 0);
101940 spin_lock_init(&ipvs->dropentry_lock);
101941diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101942index 547ff33..c8c8117 100644
101943--- a/net/netfilter/ipvs/ip_vs_lblc.c
101944+++ b/net/netfilter/ipvs/ip_vs_lblc.c
101945@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101946 * IPVS LBLC sysctl table
101947 */
101948 #ifdef CONFIG_SYSCTL
101949-static struct ctl_table vs_vars_table[] = {
101950+static ctl_table_no_const vs_vars_table[] __read_only = {
101951 {
101952 .procname = "lblc_expiration",
101953 .data = NULL,
101954diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101955index 3f21a2f..a112e85 100644
101956--- a/net/netfilter/ipvs/ip_vs_lblcr.c
101957+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101958@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101959 * IPVS LBLCR sysctl table
101960 */
101961
101962-static struct ctl_table vs_vars_table[] = {
101963+static ctl_table_no_const vs_vars_table[] __read_only = {
101964 {
101965 .procname = "lblcr_expiration",
101966 .data = NULL,
101967diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101968index db80126..ef7110e 100644
101969--- a/net/netfilter/ipvs/ip_vs_sync.c
101970+++ b/net/netfilter/ipvs/ip_vs_sync.c
101971@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101972 cp = cp->control;
101973 if (cp) {
101974 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101975- pkts = atomic_add_return(1, &cp->in_pkts);
101976+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101977 else
101978 pkts = sysctl_sync_threshold(ipvs);
101979 ip_vs_sync_conn(net, cp->control, pkts);
101980@@ -771,7 +771,7 @@ control:
101981 if (!cp)
101982 return;
101983 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101984- pkts = atomic_add_return(1, &cp->in_pkts);
101985+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101986 else
101987 pkts = sysctl_sync_threshold(ipvs);
101988 goto sloop;
101989@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101990
101991 if (opt)
101992 memcpy(&cp->in_seq, opt, sizeof(*opt));
101993- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101994+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101995 cp->state = state;
101996 cp->old_state = cp->state;
101997 /*
101998diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101999index 7f0e1cf..e9a86e6 100644
102000--- a/net/netfilter/ipvs/ip_vs_xmit.c
102001+++ b/net/netfilter/ipvs/ip_vs_xmit.c
102002@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
102003 else
102004 rc = NF_ACCEPT;
102005 /* do not touch skb anymore */
102006- atomic_inc(&cp->in_pkts);
102007+ atomic_inc_unchecked(&cp->in_pkts);
102008 goto out;
102009 }
102010
102011@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
102012 else
102013 rc = NF_ACCEPT;
102014 /* do not touch skb anymore */
102015- atomic_inc(&cp->in_pkts);
102016+ atomic_inc_unchecked(&cp->in_pkts);
102017 goto out;
102018 }
102019
102020diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
102021index a4b5e2a..13b1de3 100644
102022--- a/net/netfilter/nf_conntrack_acct.c
102023+++ b/net/netfilter/nf_conntrack_acct.c
102024@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
102025 #ifdef CONFIG_SYSCTL
102026 static int nf_conntrack_acct_init_sysctl(struct net *net)
102027 {
102028- struct ctl_table *table;
102029+ ctl_table_no_const *table;
102030
102031 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
102032 GFP_KERNEL);
102033diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
102034index 75421f2..0e69621 100644
102035--- a/net/netfilter/nf_conntrack_core.c
102036+++ b/net/netfilter/nf_conntrack_core.c
102037@@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
102038 #define DYING_NULLS_VAL ((1<<30)+1)
102039 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
102040
102041+#ifdef CONFIG_GRKERNSEC_HIDESYM
102042+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
102043+#endif
102044+
102045 int nf_conntrack_init_net(struct net *net)
102046 {
102047 int ret = -ENOMEM;
102048@@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
102049 if (!net->ct.stat)
102050 goto err_pcpu_lists;
102051
102052+#ifdef CONFIG_GRKERNSEC_HIDESYM
102053+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
102054+#else
102055 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
102056+#endif
102057 if (!net->ct.slabname)
102058 goto err_slabname;
102059
102060diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
102061index 1df1761..ce8b88a 100644
102062--- a/net/netfilter/nf_conntrack_ecache.c
102063+++ b/net/netfilter/nf_conntrack_ecache.c
102064@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
102065 #ifdef CONFIG_SYSCTL
102066 static int nf_conntrack_event_init_sysctl(struct net *net)
102067 {
102068- struct ctl_table *table;
102069+ ctl_table_no_const *table;
102070
102071 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
102072 GFP_KERNEL);
102073diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
102074index 5b3eae7..dd4b8fe 100644
102075--- a/net/netfilter/nf_conntrack_helper.c
102076+++ b/net/netfilter/nf_conntrack_helper.c
102077@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
102078
102079 static int nf_conntrack_helper_init_sysctl(struct net *net)
102080 {
102081- struct ctl_table *table;
102082+ ctl_table_no_const *table;
102083
102084 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
102085 GFP_KERNEL);
102086diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
102087index b65d586..beec902 100644
102088--- a/net/netfilter/nf_conntrack_proto.c
102089+++ b/net/netfilter/nf_conntrack_proto.c
102090@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
102091
102092 static void
102093 nf_ct_unregister_sysctl(struct ctl_table_header **header,
102094- struct ctl_table **table,
102095+ ctl_table_no_const **table,
102096 unsigned int users)
102097 {
102098 if (users > 0)
102099diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
102100index f641751..d3c5b51 100644
102101--- a/net/netfilter/nf_conntrack_standalone.c
102102+++ b/net/netfilter/nf_conntrack_standalone.c
102103@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
102104
102105 static int nf_conntrack_standalone_init_sysctl(struct net *net)
102106 {
102107- struct ctl_table *table;
102108+ ctl_table_no_const *table;
102109
102110 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
102111 GFP_KERNEL);
102112diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
102113index 7a394df..bd91a8a 100644
102114--- a/net/netfilter/nf_conntrack_timestamp.c
102115+++ b/net/netfilter/nf_conntrack_timestamp.c
102116@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
102117 #ifdef CONFIG_SYSCTL
102118 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
102119 {
102120- struct ctl_table *table;
102121+ ctl_table_no_const *table;
102122
102123 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
102124 GFP_KERNEL);
102125diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
102126index 85296d4..8becdec 100644
102127--- a/net/netfilter/nf_log.c
102128+++ b/net/netfilter/nf_log.c
102129@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
102130
102131 #ifdef CONFIG_SYSCTL
102132 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
102133-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
102134+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
102135
102136 static int nf_log_proc_dostring(struct ctl_table *table, int write,
102137 void __user *buffer, size_t *lenp, loff_t *ppos)
102138@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
102139 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
102140 mutex_unlock(&nf_log_mutex);
102141 } else {
102142+ ctl_table_no_const nf_log_table = *table;
102143+
102144 mutex_lock(&nf_log_mutex);
102145 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
102146 lockdep_is_held(&nf_log_mutex));
102147 if (!logger)
102148- table->data = "NONE";
102149+ nf_log_table.data = "NONE";
102150 else
102151- table->data = logger->name;
102152- r = proc_dostring(table, write, buffer, lenp, ppos);
102153+ nf_log_table.data = logger->name;
102154+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
102155 mutex_unlock(&nf_log_mutex);
102156 }
102157
102158diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
102159index f042ae5..30ea486 100644
102160--- a/net/netfilter/nf_sockopt.c
102161+++ b/net/netfilter/nf_sockopt.c
102162@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
102163 }
102164 }
102165
102166- list_add(&reg->list, &nf_sockopts);
102167+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
102168 out:
102169 mutex_unlock(&nf_sockopt_mutex);
102170 return ret;
102171@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
102172 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
102173 {
102174 mutex_lock(&nf_sockopt_mutex);
102175- list_del(&reg->list);
102176+ pax_list_del((struct list_head *)&reg->list);
102177 mutex_unlock(&nf_sockopt_mutex);
102178 }
102179 EXPORT_SYMBOL(nf_unregister_sockopt);
102180diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
102181index d292c8d..9f1e166 100644
102182--- a/net/netfilter/nfnetlink_log.c
102183+++ b/net/netfilter/nfnetlink_log.c
102184@@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
102185 struct nfnl_log_net {
102186 spinlock_t instances_lock;
102187 struct hlist_head instance_table[INSTANCE_BUCKETS];
102188- atomic_t global_seq;
102189+ atomic_unchecked_t global_seq;
102190 };
102191
102192 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
102193@@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
102194 /* global sequence number */
102195 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
102196 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
102197- htonl(atomic_inc_return(&log->global_seq))))
102198+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
102199 goto nla_put_failure;
102200
102201 if (data_len) {
102202diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
102203index 8a779be..1551d4c 100644
102204--- a/net/netfilter/nft_compat.c
102205+++ b/net/netfilter/nft_compat.c
102206@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
102207 /* We want to reuse existing compat_to_user */
102208 old_fs = get_fs();
102209 set_fs(KERNEL_DS);
102210- t->compat_to_user(out, in);
102211+ t->compat_to_user((void __force_user *)out, in);
102212 set_fs(old_fs);
102213 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
102214 kfree(out);
102215@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
102216 /* We want to reuse existing compat_to_user */
102217 old_fs = get_fs();
102218 set_fs(KERNEL_DS);
102219- m->compat_to_user(out, in);
102220+ m->compat_to_user((void __force_user *)out, in);
102221 set_fs(old_fs);
102222 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
102223 kfree(out);
102224diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
102225new file mode 100644
102226index 0000000..c566332
102227--- /dev/null
102228+++ b/net/netfilter/xt_gradm.c
102229@@ -0,0 +1,51 @@
102230+/*
102231+ * gradm match for netfilter
102232