]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.15.10-201408212335.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.15.10-201408212335.patch
CommitLineData
c81a02e5
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..f2438cb 100644
38753--- a/drivers/char/random.c
38754+++ b/drivers/char/random.c
38755@@ -284,9 +284,6 @@
38756 /*
38757 * To allow fractional bits to be tracked, the entropy_count field is
38758 * denominated in units of 1/8th bits.
38759- *
38760- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38761- * credit_entropy_bits() needs to be 64 bits wide.
38762 */
38763 #define ENTROPY_SHIFT 3
38764 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38765@@ -433,9 +430,9 @@ struct entropy_store {
38766 };
38767
38768 static void push_to_pool(struct work_struct *work);
38769-static __u32 input_pool_data[INPUT_POOL_WORDS];
38770-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38771-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38772+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38773+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38774+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38775
38776 static struct entropy_store input_pool = {
38777 .poolinfo = &poolinfo_table[0],
38778@@ -524,8 +521,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38779 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38780 }
38781
38782- ACCESS_ONCE(r->input_rotate) = input_rotate;
38783- ACCESS_ONCE(r->add_ptr) = i;
38784+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38785+ ACCESS_ONCE_RW(r->add_ptr) = i;
38786 smp_wmb();
38787
38788 if (out)
38789@@ -632,7 +629,7 @@ retry:
38790 /* The +2 corresponds to the /4 in the denominator */
38791
38792 do {
38793- unsigned int anfrac = min(pnfrac, pool_size/2);
38794+ u64 anfrac = min(pnfrac, pool_size/2);
38795 unsigned int add =
38796 ((pool_size - entropy_count)*anfrac*3) >> s;
38797
38798@@ -1176,7 +1173,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38799
38800 extract_buf(r, tmp);
38801 i = min_t(int, nbytes, EXTRACT_SIZE);
38802- if (copy_to_user(buf, tmp, i)) {
38803+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38804 ret = -EFAULT;
38805 break;
38806 }
38807@@ -1566,7 +1563,7 @@ static char sysctl_bootid[16];
38808 static int proc_do_uuid(struct ctl_table *table, int write,
38809 void __user *buffer, size_t *lenp, loff_t *ppos)
38810 {
38811- struct ctl_table fake_table;
38812+ ctl_table_no_const fake_table;
38813 unsigned char buf[64], tmp_uuid[16], *uuid;
38814
38815 uuid = table->data;
38816@@ -1596,7 +1593,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38817 static int proc_do_entropy(ctl_table *table, int write,
38818 void __user *buffer, size_t *lenp, loff_t *ppos)
38819 {
38820- ctl_table fake_table;
38821+ ctl_table_no_const fake_table;
38822 int entropy_count;
38823
38824 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38825diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38826index 7cc1fe22..b602d6b 100644
38827--- a/drivers/char/sonypi.c
38828+++ b/drivers/char/sonypi.c
38829@@ -54,6 +54,7 @@
38830
38831 #include <asm/uaccess.h>
38832 #include <asm/io.h>
38833+#include <asm/local.h>
38834
38835 #include <linux/sonypi.h>
38836
38837@@ -490,7 +491,7 @@ static struct sonypi_device {
38838 spinlock_t fifo_lock;
38839 wait_queue_head_t fifo_proc_list;
38840 struct fasync_struct *fifo_async;
38841- int open_count;
38842+ local_t open_count;
38843 int model;
38844 struct input_dev *input_jog_dev;
38845 struct input_dev *input_key_dev;
38846@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38847 static int sonypi_misc_release(struct inode *inode, struct file *file)
38848 {
38849 mutex_lock(&sonypi_device.lock);
38850- sonypi_device.open_count--;
38851+ local_dec(&sonypi_device.open_count);
38852 mutex_unlock(&sonypi_device.lock);
38853 return 0;
38854 }
38855@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38856 {
38857 mutex_lock(&sonypi_device.lock);
38858 /* Flush input queue on first open */
38859- if (!sonypi_device.open_count)
38860+ if (!local_read(&sonypi_device.open_count))
38861 kfifo_reset(&sonypi_device.fifo);
38862- sonypi_device.open_count++;
38863+ local_inc(&sonypi_device.open_count);
38864 mutex_unlock(&sonypi_device.lock);
38865
38866 return 0;
38867diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38868index b9a57fa..5bb9e38 100644
38869--- a/drivers/char/tpm/tpm_acpi.c
38870+++ b/drivers/char/tpm/tpm_acpi.c
38871@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38872 virt = acpi_os_map_memory(start, len);
38873 if (!virt) {
38874 kfree(log->bios_event_log);
38875+ log->bios_event_log = NULL;
38876 printk("%s: ERROR - Unable to map memory\n", __func__);
38877 return -EIO;
38878 }
38879
38880- memcpy_fromio(log->bios_event_log, virt, len);
38881+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38882
38883 acpi_os_unmap_memory(virt, len);
38884 return 0;
38885diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38886index 59f7cb2..bac8b6d 100644
38887--- a/drivers/char/tpm/tpm_eventlog.c
38888+++ b/drivers/char/tpm/tpm_eventlog.c
38889@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38890 event = addr;
38891
38892 if ((event->event_type == 0 && event->event_size == 0) ||
38893- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38894+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38895 return NULL;
38896
38897 return addr;
38898@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38899 return NULL;
38900
38901 if ((event->event_type == 0 && event->event_size == 0) ||
38902- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38903+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38904 return NULL;
38905
38906 (*pos)++;
38907@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38908 int i;
38909
38910 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38911- seq_putc(m, data[i]);
38912+ if (!seq_putc(m, data[i]))
38913+ return -EFAULT;
38914
38915 return 0;
38916 }
38917diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38918index 60aafb8..10c08e0 100644
38919--- a/drivers/char/virtio_console.c
38920+++ b/drivers/char/virtio_console.c
38921@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38922 if (to_user) {
38923 ssize_t ret;
38924
38925- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38926+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38927 if (ret)
38928 return -EFAULT;
38929 } else {
38930@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38931 if (!port_has_data(port) && !port->host_connected)
38932 return 0;
38933
38934- return fill_readbuf(port, ubuf, count, true);
38935+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38936 }
38937
38938 static int wait_port_writable(struct port *port, bool nonblock)
38939diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38940index 57a078e..c17cde8 100644
38941--- a/drivers/clk/clk-composite.c
38942+++ b/drivers/clk/clk-composite.c
38943@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38944 struct clk *clk;
38945 struct clk_init_data init;
38946 struct clk_composite *composite;
38947- struct clk_ops *clk_composite_ops;
38948+ clk_ops_no_const *clk_composite_ops;
38949
38950 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38951 if (!composite) {
38952diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38953index 501d513..fb0ecf9 100644
38954--- a/drivers/clk/socfpga/clk-gate.c
38955+++ b/drivers/clk/socfpga/clk-gate.c
38956@@ -22,6 +22,7 @@
38957 #include <linux/mfd/syscon.h>
38958 #include <linux/of.h>
38959 #include <linux/regmap.h>
38960+#include <asm/pgtable.h>
38961
38962 #include "clk.h"
38963
38964@@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
38965 return 0;
38966 }
38967
38968-static struct clk_ops gateclk_ops = {
38969+static clk_ops_no_const gateclk_ops __read_only = {
38970 .prepare = socfpga_clk_prepare,
38971 .recalc_rate = socfpga_clk_recalc_rate,
38972 .get_parent = socfpga_clk_get_parent,
38973@@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
38974 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
38975 socfpga_clk->hw.bit_idx = clk_gate[1];
38976
38977- gateclk_ops.enable = clk_gate_ops.enable;
38978- gateclk_ops.disable = clk_gate_ops.disable;
38979+ pax_open_kernel();
38980+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
38981+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
38982+ pax_close_kernel();
38983 }
38984
38985 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
38986diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
38987index de6da95..c98278b 100644
38988--- a/drivers/clk/socfpga/clk-pll.c
38989+++ b/drivers/clk/socfpga/clk-pll.c
38990@@ -21,6 +21,7 @@
38991 #include <linux/io.h>
38992 #include <linux/of.h>
38993 #include <linux/of_address.h>
38994+#include <asm/pgtable.h>
38995
38996 #include "clk.h"
38997
38998@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
38999 CLK_MGR_PLL_CLK_SRC_MASK;
39000 }
39001
39002-static struct clk_ops clk_pll_ops = {
39003+static clk_ops_no_const clk_pll_ops __read_only = {
39004 .recalc_rate = clk_pll_recalc_rate,
39005 .get_parent = clk_pll_get_parent,
39006 };
39007@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39008 pll_clk->hw.hw.init = &init;
39009
39010 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39011- clk_pll_ops.enable = clk_gate_ops.enable;
39012- clk_pll_ops.disable = clk_gate_ops.disable;
39013+ pax_open_kernel();
39014+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39015+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39016+ pax_close_kernel();
39017
39018 clk = clk_register(NULL, &pll_clk->hw.hw);
39019 if (WARN_ON(IS_ERR(clk))) {
39020diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39021index 000e4e0..4770351 100644
39022--- a/drivers/cpufreq/acpi-cpufreq.c
39023+++ b/drivers/cpufreq/acpi-cpufreq.c
39024@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39025 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39026 per_cpu(acfreq_data, cpu) = data;
39027
39028- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39029- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39030+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39031+ pax_open_kernel();
39032+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39033+ pax_close_kernel();
39034+ }
39035
39036 result = acpi_processor_register_performance(data->acpi_data, cpu);
39037 if (result)
39038@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39039 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39040 break;
39041 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39042- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39043+ pax_open_kernel();
39044+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39045+ pax_close_kernel();
39046 break;
39047 default:
39048 break;
39049@@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
39050 if (!msrs)
39051 return;
39052
39053- acpi_cpufreq_driver.boost_supported = true;
39054- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39055+ pax_open_kernel();
39056+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39057+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39058+ pax_close_kernel();
39059
39060 cpu_notifier_register_begin();
39061
39062diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39063index dcac12d..f12df60 100644
39064--- a/drivers/cpufreq/cpufreq.c
39065+++ b/drivers/cpufreq/cpufreq.c
39066@@ -2024,7 +2024,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39067 }
39068
39069 mutex_lock(&cpufreq_governor_mutex);
39070- list_del(&governor->governor_list);
39071+ pax_list_del(&governor->governor_list);
39072 mutex_unlock(&cpufreq_governor_mutex);
39073 return;
39074 }
39075@@ -2240,7 +2240,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39076 return NOTIFY_OK;
39077 }
39078
39079-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39080+static struct notifier_block cpufreq_cpu_notifier = {
39081 .notifier_call = cpufreq_cpu_callback,
39082 };
39083
39084@@ -2280,13 +2280,17 @@ int cpufreq_boost_trigger_state(int state)
39085 return 0;
39086
39087 write_lock_irqsave(&cpufreq_driver_lock, flags);
39088- cpufreq_driver->boost_enabled = state;
39089+ pax_open_kernel();
39090+ *(bool *)&cpufreq_driver->boost_enabled = state;
39091+ pax_close_kernel();
39092 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39093
39094 ret = cpufreq_driver->set_boost(state);
39095 if (ret) {
39096 write_lock_irqsave(&cpufreq_driver_lock, flags);
39097- cpufreq_driver->boost_enabled = !state;
39098+ pax_open_kernel();
39099+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39100+ pax_close_kernel();
39101 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39102
39103 pr_err("%s: Cannot %s BOOST\n",
39104@@ -2342,8 +2346,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39105
39106 pr_debug("trying to register driver %s\n", driver_data->name);
39107
39108- if (driver_data->setpolicy)
39109- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39110+ if (driver_data->setpolicy) {
39111+ pax_open_kernel();
39112+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39113+ pax_close_kernel();
39114+ }
39115
39116 write_lock_irqsave(&cpufreq_driver_lock, flags);
39117 if (cpufreq_driver) {
39118@@ -2358,8 +2365,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39119 * Check if driver provides function to enable boost -
39120 * if not, use cpufreq_boost_set_sw as default
39121 */
39122- if (!cpufreq_driver->set_boost)
39123- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39124+ if (!cpufreq_driver->set_boost) {
39125+ pax_open_kernel();
39126+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39127+ pax_close_kernel();
39128+ }
39129
39130 ret = cpufreq_sysfs_create_file(&boost.attr);
39131 if (ret) {
39132diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39133index e1c6433..31203ae 100644
39134--- a/drivers/cpufreq/cpufreq_governor.c
39135+++ b/drivers/cpufreq/cpufreq_governor.c
39136@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39137 struct dbs_data *dbs_data;
39138 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39139 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39140- struct od_ops *od_ops = NULL;
39141+ const struct od_ops *od_ops = NULL;
39142 struct od_dbs_tuners *od_tuners = NULL;
39143 struct cs_dbs_tuners *cs_tuners = NULL;
39144 struct cpu_dbs_common_info *cpu_cdbs;
39145@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39146
39147 if ((cdata->governor == GOV_CONSERVATIVE) &&
39148 (!policy->governor->initialized)) {
39149- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39150+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39151
39152 cpufreq_register_notifier(cs_ops->notifier_block,
39153 CPUFREQ_TRANSITION_NOTIFIER);
39154@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39155
39156 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39157 (policy->governor->initialized == 1)) {
39158- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39159+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39160
39161 cpufreq_unregister_notifier(cs_ops->notifier_block,
39162 CPUFREQ_TRANSITION_NOTIFIER);
39163diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39164index bfb9ae1..e1d3a7e 100644
39165--- a/drivers/cpufreq/cpufreq_governor.h
39166+++ b/drivers/cpufreq/cpufreq_governor.h
39167@@ -205,7 +205,7 @@ struct common_dbs_data {
39168 void (*exit)(struct dbs_data *dbs_data);
39169
39170 /* Governor specific ops, see below */
39171- void *gov_ops;
39172+ const void *gov_ops;
39173 };
39174
39175 /* Governor Per policy data */
39176@@ -225,7 +225,7 @@ struct od_ops {
39177 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39178 unsigned int freq_next, unsigned int relation);
39179 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39180-};
39181+} __no_const;
39182
39183 struct cs_ops {
39184 struct notifier_block *notifier_block;
39185diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39186index 18d4091..434be15 100644
39187--- a/drivers/cpufreq/cpufreq_ondemand.c
39188+++ b/drivers/cpufreq/cpufreq_ondemand.c
39189@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39190
39191 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39192
39193-static struct od_ops od_ops = {
39194+static struct od_ops od_ops __read_only = {
39195 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39196 .powersave_bias_target = generic_powersave_bias_target,
39197 .freq_increase = dbs_freq_increase,
39198@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39199 (struct cpufreq_policy *, unsigned int, unsigned int),
39200 unsigned int powersave_bias)
39201 {
39202- od_ops.powersave_bias_target = f;
39203+ pax_open_kernel();
39204+ *(void **)&od_ops.powersave_bias_target = f;
39205+ pax_close_kernel();
39206 od_set_powersave_bias(powersave_bias);
39207 }
39208 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39209
39210 void od_unregister_powersave_bias_handler(void)
39211 {
39212- od_ops.powersave_bias_target = generic_powersave_bias_target;
39213+ pax_open_kernel();
39214+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39215+ pax_close_kernel();
39216 od_set_powersave_bias(0);
39217 }
39218 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39219diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39220index 870eecc..787bbca 100644
39221--- a/drivers/cpufreq/intel_pstate.c
39222+++ b/drivers/cpufreq/intel_pstate.c
39223@@ -125,10 +125,10 @@ struct pstate_funcs {
39224 struct cpu_defaults {
39225 struct pstate_adjust_policy pid_policy;
39226 struct pstate_funcs funcs;
39227-};
39228+} __do_const;
39229
39230 static struct pstate_adjust_policy pid_params;
39231-static struct pstate_funcs pstate_funcs;
39232+static struct pstate_funcs *pstate_funcs;
39233
39234 struct perf_limits {
39235 int no_turbo;
39236@@ -530,7 +530,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39237
39238 cpu->pstate.current_pstate = pstate;
39239
39240- pstate_funcs.set(cpu, pstate);
39241+ pstate_funcs->set(cpu, pstate);
39242 }
39243
39244 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39245@@ -552,12 +552,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39246 {
39247 sprintf(cpu->name, "Intel 2nd generation core");
39248
39249- cpu->pstate.min_pstate = pstate_funcs.get_min();
39250- cpu->pstate.max_pstate = pstate_funcs.get_max();
39251- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39252+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39253+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39254+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39255
39256- if (pstate_funcs.get_vid)
39257- pstate_funcs.get_vid(cpu);
39258+ if (pstate_funcs->get_vid)
39259+ pstate_funcs->get_vid(cpu);
39260 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39261 }
39262
39263@@ -847,9 +847,9 @@ static int intel_pstate_msrs_not_valid(void)
39264 rdmsrl(MSR_IA32_APERF, aperf);
39265 rdmsrl(MSR_IA32_MPERF, mperf);
39266
39267- if (!pstate_funcs.get_max() ||
39268- !pstate_funcs.get_min() ||
39269- !pstate_funcs.get_turbo())
39270+ if (!pstate_funcs->get_max() ||
39271+ !pstate_funcs->get_min() ||
39272+ !pstate_funcs->get_turbo())
39273 return -ENODEV;
39274
39275 rdmsrl(MSR_IA32_APERF, tmp);
39276@@ -863,7 +863,7 @@ static int intel_pstate_msrs_not_valid(void)
39277 return 0;
39278 }
39279
39280-static void copy_pid_params(struct pstate_adjust_policy *policy)
39281+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39282 {
39283 pid_params.sample_rate_ms = policy->sample_rate_ms;
39284 pid_params.p_gain_pct = policy->p_gain_pct;
39285@@ -875,11 +875,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39286
39287 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39288 {
39289- pstate_funcs.get_max = funcs->get_max;
39290- pstate_funcs.get_min = funcs->get_min;
39291- pstate_funcs.get_turbo = funcs->get_turbo;
39292- pstate_funcs.set = funcs->set;
39293- pstate_funcs.get_vid = funcs->get_vid;
39294+ pstate_funcs = funcs;
39295 }
39296
39297 #if IS_ENABLED(CONFIG_ACPI)
39298diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39299index 529cfd9..0e28fff 100644
39300--- a/drivers/cpufreq/p4-clockmod.c
39301+++ b/drivers/cpufreq/p4-clockmod.c
39302@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39303 case 0x0F: /* Core Duo */
39304 case 0x16: /* Celeron Core */
39305 case 0x1C: /* Atom */
39306- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39307+ pax_open_kernel();
39308+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39309+ pax_close_kernel();
39310 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39311 case 0x0D: /* Pentium M (Dothan) */
39312- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39313+ pax_open_kernel();
39314+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39315+ pax_close_kernel();
39316 /* fall through */
39317 case 0x09: /* Pentium M (Banias) */
39318 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39319@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39320
39321 /* on P-4s, the TSC runs with constant frequency independent whether
39322 * throttling is active or not. */
39323- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39324+ pax_open_kernel();
39325+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39326+ pax_close_kernel();
39327
39328 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39329 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39330diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39331index 9bb42ba..b01b4a2 100644
39332--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39333+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39334@@ -18,14 +18,12 @@
39335 #include <asm/head.h>
39336 #include <asm/timer.h>
39337
39338-static struct cpufreq_driver *cpufreq_us3_driver;
39339-
39340 struct us3_freq_percpu_info {
39341 struct cpufreq_frequency_table table[4];
39342 };
39343
39344 /* Indexed by cpu number. */
39345-static struct us3_freq_percpu_info *us3_freq_table;
39346+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39347
39348 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39349 * in the Safari config register.
39350@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39351
39352 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39353 {
39354- if (cpufreq_us3_driver)
39355- us3_freq_target(policy, 0);
39356+ us3_freq_target(policy, 0);
39357
39358 return 0;
39359 }
39360
39361+static int __init us3_freq_init(void);
39362+static void __exit us3_freq_exit(void);
39363+
39364+static struct cpufreq_driver cpufreq_us3_driver = {
39365+ .init = us3_freq_cpu_init,
39366+ .verify = cpufreq_generic_frequency_table_verify,
39367+ .target_index = us3_freq_target,
39368+ .get = us3_freq_get,
39369+ .exit = us3_freq_cpu_exit,
39370+ .name = "UltraSPARC-III",
39371+
39372+};
39373+
39374 static int __init us3_freq_init(void)
39375 {
39376 unsigned long manuf, impl, ver;
39377- int ret;
39378
39379 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39380 return -ENODEV;
39381@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39382 (impl == CHEETAH_IMPL ||
39383 impl == CHEETAH_PLUS_IMPL ||
39384 impl == JAGUAR_IMPL ||
39385- impl == PANTHER_IMPL)) {
39386- struct cpufreq_driver *driver;
39387-
39388- ret = -ENOMEM;
39389- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39390- if (!driver)
39391- goto err_out;
39392-
39393- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39394- GFP_KERNEL);
39395- if (!us3_freq_table)
39396- goto err_out;
39397-
39398- driver->init = us3_freq_cpu_init;
39399- driver->verify = cpufreq_generic_frequency_table_verify;
39400- driver->target_index = us3_freq_target;
39401- driver->get = us3_freq_get;
39402- driver->exit = us3_freq_cpu_exit;
39403- strcpy(driver->name, "UltraSPARC-III");
39404-
39405- cpufreq_us3_driver = driver;
39406- ret = cpufreq_register_driver(driver);
39407- if (ret)
39408- goto err_out;
39409-
39410- return 0;
39411-
39412-err_out:
39413- if (driver) {
39414- kfree(driver);
39415- cpufreq_us3_driver = NULL;
39416- }
39417- kfree(us3_freq_table);
39418- us3_freq_table = NULL;
39419- return ret;
39420- }
39421+ impl == PANTHER_IMPL))
39422+ return cpufreq_register_driver(&cpufreq_us3_driver);
39423
39424 return -ENODEV;
39425 }
39426
39427 static void __exit us3_freq_exit(void)
39428 {
39429- if (cpufreq_us3_driver) {
39430- cpufreq_unregister_driver(cpufreq_us3_driver);
39431- kfree(cpufreq_us3_driver);
39432- cpufreq_us3_driver = NULL;
39433- kfree(us3_freq_table);
39434- us3_freq_table = NULL;
39435- }
39436+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39437 }
39438
39439 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39440diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39441index 6723f03..3465190 100644
39442--- a/drivers/cpufreq/speedstep-centrino.c
39443+++ b/drivers/cpufreq/speedstep-centrino.c
39444@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39445 !cpu_has(cpu, X86_FEATURE_EST))
39446 return -ENODEV;
39447
39448- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39449- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39450+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39451+ pax_open_kernel();
39452+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39453+ pax_close_kernel();
39454+ }
39455
39456 if (policy->cpu != 0)
39457 return -ENODEV;
39458diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39459index 136d6a2..06e373d 100644
39460--- a/drivers/cpuidle/driver.c
39461+++ b/drivers/cpuidle/driver.c
39462@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39463
39464 static void poll_idle_init(struct cpuidle_driver *drv)
39465 {
39466- struct cpuidle_state *state = &drv->states[0];
39467+ cpuidle_state_no_const *state = &drv->states[0];
39468
39469 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39470 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39471diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39472index ca89412..a7b9c49 100644
39473--- a/drivers/cpuidle/governor.c
39474+++ b/drivers/cpuidle/governor.c
39475@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39476 mutex_lock(&cpuidle_lock);
39477 if (__cpuidle_find_governor(gov->name) == NULL) {
39478 ret = 0;
39479- list_add_tail(&gov->governor_list, &cpuidle_governors);
39480+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39481 if (!cpuidle_curr_governor ||
39482 cpuidle_curr_governor->rating < gov->rating)
39483 cpuidle_switch_governor(gov);
39484diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39485index efe2f17..b8124f9 100644
39486--- a/drivers/cpuidle/sysfs.c
39487+++ b/drivers/cpuidle/sysfs.c
39488@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39489 NULL
39490 };
39491
39492-static struct attribute_group cpuidle_attr_group = {
39493+static attribute_group_no_const cpuidle_attr_group = {
39494 .attrs = cpuidle_default_attrs,
39495 .name = "cpuidle",
39496 };
39497diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39498index 12fea3e..1e28f47 100644
39499--- a/drivers/crypto/hifn_795x.c
39500+++ b/drivers/crypto/hifn_795x.c
39501@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39502 MODULE_PARM_DESC(hifn_pll_ref,
39503 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39504
39505-static atomic_t hifn_dev_number;
39506+static atomic_unchecked_t hifn_dev_number;
39507
39508 #define ACRYPTO_OP_DECRYPT 0
39509 #define ACRYPTO_OP_ENCRYPT 1
39510@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39511 goto err_out_disable_pci_device;
39512
39513 snprintf(name, sizeof(name), "hifn%d",
39514- atomic_inc_return(&hifn_dev_number)-1);
39515+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39516
39517 err = pci_request_regions(pdev, name);
39518 if (err)
39519diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39520index 2042ec3..a9ce67f 100644
39521--- a/drivers/devfreq/devfreq.c
39522+++ b/drivers/devfreq/devfreq.c
39523@@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39524 goto err_out;
39525 }
39526
39527- list_add(&governor->node, &devfreq_governor_list);
39528+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39529
39530 list_for_each_entry(devfreq, &devfreq_list, node) {
39531 int ret = 0;
39532@@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39533 }
39534 }
39535
39536- list_del(&governor->node);
39537+ pax_list_del((struct list_head *)&governor->node);
39538 err_out:
39539 mutex_unlock(&devfreq_list_lock);
39540
39541diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39542index 5239677..1cb71a8 100644
39543--- a/drivers/dma/sh/shdma-base.c
39544+++ b/drivers/dma/sh/shdma-base.c
39545@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39546 schan->slave_id = -EINVAL;
39547 }
39548
39549- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39550- sdev->desc_size, GFP_KERNEL);
39551+ schan->desc = kcalloc(sdev->desc_size,
39552+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39553 if (!schan->desc) {
39554 ret = -ENOMEM;
39555 goto edescalloc;
39556diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39557index dda7e75..0a4c867 100644
39558--- a/drivers/dma/sh/shdmac.c
39559+++ b/drivers/dma/sh/shdmac.c
39560@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39561 return ret;
39562 }
39563
39564-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39565+static struct notifier_block sh_dmae_nmi_notifier = {
39566 .notifier_call = sh_dmae_nmi_handler,
39567
39568 /* Run before NMI debug handler and KGDB */
39569diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39570index 592af5f..bb1d583 100644
39571--- a/drivers/edac/edac_device.c
39572+++ b/drivers/edac/edac_device.c
39573@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39574 */
39575 int edac_device_alloc_index(void)
39576 {
39577- static atomic_t device_indexes = ATOMIC_INIT(0);
39578+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39579
39580- return atomic_inc_return(&device_indexes) - 1;
39581+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39582 }
39583 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39584
39585diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39586index 01fae82..1dd8289 100644
39587--- a/drivers/edac/edac_mc_sysfs.c
39588+++ b/drivers/edac/edac_mc_sysfs.c
39589@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39590 struct dev_ch_attribute {
39591 struct device_attribute attr;
39592 int channel;
39593-};
39594+} __do_const;
39595
39596 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39597 struct dev_ch_attribute dev_attr_legacy_##_name = \
39598@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39599 }
39600
39601 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39602+ pax_open_kernel();
39603 if (mci->get_sdram_scrub_rate) {
39604- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39605- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39606+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39607+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39608 }
39609 if (mci->set_sdram_scrub_rate) {
39610- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39611- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39612+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39613+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39614 }
39615+ pax_close_kernel();
39616 err = device_create_file(&mci->dev,
39617 &dev_attr_sdram_scrub_rate);
39618 if (err) {
39619diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39620index 2cf44b4d..6dd2dc7 100644
39621--- a/drivers/edac/edac_pci.c
39622+++ b/drivers/edac/edac_pci.c
39623@@ -29,7 +29,7 @@
39624
39625 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39626 static LIST_HEAD(edac_pci_list);
39627-static atomic_t pci_indexes = ATOMIC_INIT(0);
39628+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39629
39630 /*
39631 * edac_pci_alloc_ctl_info
39632@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39633 */
39634 int edac_pci_alloc_index(void)
39635 {
39636- return atomic_inc_return(&pci_indexes) - 1;
39637+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39638 }
39639 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39640
39641diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39642index e8658e4..22746d6 100644
39643--- a/drivers/edac/edac_pci_sysfs.c
39644+++ b/drivers/edac/edac_pci_sysfs.c
39645@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39646 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39647 static int edac_pci_poll_msec = 1000; /* one second workq period */
39648
39649-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39650-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39651+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39652+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39653
39654 static struct kobject *edac_pci_top_main_kobj;
39655 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39656@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39657 void *value;
39658 ssize_t(*show) (void *, char *);
39659 ssize_t(*store) (void *, const char *, size_t);
39660-};
39661+} __do_const;
39662
39663 /* Set of show/store abstract level functions for PCI Parity object */
39664 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39665@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39666 edac_printk(KERN_CRIT, EDAC_PCI,
39667 "Signaled System Error on %s\n",
39668 pci_name(dev));
39669- atomic_inc(&pci_nonparity_count);
39670+ atomic_inc_unchecked(&pci_nonparity_count);
39671 }
39672
39673 if (status & (PCI_STATUS_PARITY)) {
39674@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39675 "Master Data Parity Error on %s\n",
39676 pci_name(dev));
39677
39678- atomic_inc(&pci_parity_count);
39679+ atomic_inc_unchecked(&pci_parity_count);
39680 }
39681
39682 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39683@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39684 "Detected Parity Error on %s\n",
39685 pci_name(dev));
39686
39687- atomic_inc(&pci_parity_count);
39688+ atomic_inc_unchecked(&pci_parity_count);
39689 }
39690 }
39691
39692@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39693 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39694 "Signaled System Error on %s\n",
39695 pci_name(dev));
39696- atomic_inc(&pci_nonparity_count);
39697+ atomic_inc_unchecked(&pci_nonparity_count);
39698 }
39699
39700 if (status & (PCI_STATUS_PARITY)) {
39701@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39702 "Master Data Parity Error on "
39703 "%s\n", pci_name(dev));
39704
39705- atomic_inc(&pci_parity_count);
39706+ atomic_inc_unchecked(&pci_parity_count);
39707 }
39708
39709 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39710@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39711 "Detected Parity Error on %s\n",
39712 pci_name(dev));
39713
39714- atomic_inc(&pci_parity_count);
39715+ atomic_inc_unchecked(&pci_parity_count);
39716 }
39717 }
39718 }
39719@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39720 if (!check_pci_errors)
39721 return;
39722
39723- before_count = atomic_read(&pci_parity_count);
39724+ before_count = atomic_read_unchecked(&pci_parity_count);
39725
39726 /* scan all PCI devices looking for a Parity Error on devices and
39727 * bridges.
39728@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39729 /* Only if operator has selected panic on PCI Error */
39730 if (edac_pci_get_panic_on_pe()) {
39731 /* If the count is different 'after' from 'before' */
39732- if (before_count != atomic_read(&pci_parity_count))
39733+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39734 panic("EDAC: PCI Parity Error");
39735 }
39736 }
39737diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39738index 51b7e3a..aa8a3e8 100644
39739--- a/drivers/edac/mce_amd.h
39740+++ b/drivers/edac/mce_amd.h
39741@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39742 bool (*mc0_mce)(u16, u8);
39743 bool (*mc1_mce)(u16, u8);
39744 bool (*mc2_mce)(u16, u8);
39745-};
39746+} __no_const;
39747
39748 void amd_report_gart_errors(bool);
39749 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39750diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39751index 57ea7f4..af06b76 100644
39752--- a/drivers/firewire/core-card.c
39753+++ b/drivers/firewire/core-card.c
39754@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39755 const struct fw_card_driver *driver,
39756 struct device *device)
39757 {
39758- static atomic_t index = ATOMIC_INIT(-1);
39759+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39760
39761- card->index = atomic_inc_return(&index);
39762+ card->index = atomic_inc_return_unchecked(&index);
39763 card->driver = driver;
39764 card->device = device;
39765 card->current_tlabel = 0;
39766@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39767
39768 void fw_core_remove_card(struct fw_card *card)
39769 {
39770- struct fw_card_driver dummy_driver = dummy_driver_template;
39771+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39772
39773 card->driver->update_phy_reg(card, 4,
39774 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39775diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39776index 2c6d5e1..a2cca6b 100644
39777--- a/drivers/firewire/core-device.c
39778+++ b/drivers/firewire/core-device.c
39779@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39780 struct config_rom_attribute {
39781 struct device_attribute attr;
39782 u32 key;
39783-};
39784+} __do_const;
39785
39786 static ssize_t show_immediate(struct device *dev,
39787 struct device_attribute *dattr, char *buf)
39788diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39789index eb6935c..3cc2bfa 100644
39790--- a/drivers/firewire/core-transaction.c
39791+++ b/drivers/firewire/core-transaction.c
39792@@ -38,6 +38,7 @@
39793 #include <linux/timer.h>
39794 #include <linux/types.h>
39795 #include <linux/workqueue.h>
39796+#include <linux/sched.h>
39797
39798 #include <asm/byteorder.h>
39799
39800diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39801index f477308..2795f24 100644
39802--- a/drivers/firewire/core.h
39803+++ b/drivers/firewire/core.h
39804@@ -111,6 +111,7 @@ struct fw_card_driver {
39805
39806 int (*stop_iso)(struct fw_iso_context *ctx);
39807 };
39808+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39809
39810 void fw_card_initialize(struct fw_card *card,
39811 const struct fw_card_driver *driver, struct device *device);
39812diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39813index 586f2f7..3545ad2 100644
39814--- a/drivers/firewire/ohci.c
39815+++ b/drivers/firewire/ohci.c
39816@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39817 be32_to_cpu(ohci->next_header));
39818 }
39819
39820+#ifndef CONFIG_GRKERNSEC
39821 if (param_remote_dma) {
39822 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39823 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39824 }
39825+#endif
39826
39827 spin_unlock_irq(&ohci->lock);
39828
39829@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39830 unsigned long flags;
39831 int n, ret = 0;
39832
39833+#ifndef CONFIG_GRKERNSEC
39834 if (param_remote_dma)
39835 return 0;
39836+#endif
39837
39838 /*
39839 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39840diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39841index 94a58a0..f5eba42 100644
39842--- a/drivers/firmware/dmi-id.c
39843+++ b/drivers/firmware/dmi-id.c
39844@@ -16,7 +16,7 @@
39845 struct dmi_device_attribute{
39846 struct device_attribute dev_attr;
39847 int field;
39848-};
39849+} __do_const;
39850 #define to_dmi_dev_attr(_dev_attr) \
39851 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39852
39853diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39854index 17afc51..0ef90cd 100644
39855--- a/drivers/firmware/dmi_scan.c
39856+++ b/drivers/firmware/dmi_scan.c
39857@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39858 if (buf == NULL)
39859 return -1;
39860
39861- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39862+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39863
39864 dmi_unmap(buf);
39865 return 0;
39866diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39867index 1491dd4..aa910db 100644
39868--- a/drivers/firmware/efi/cper.c
39869+++ b/drivers/firmware/efi/cper.c
39870@@ -41,12 +41,12 @@
39871 */
39872 u64 cper_next_record_id(void)
39873 {
39874- static atomic64_t seq;
39875+ static atomic64_unchecked_t seq;
39876
39877- if (!atomic64_read(&seq))
39878- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39879+ if (!atomic64_read_unchecked(&seq))
39880+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39881
39882- return atomic64_inc_return(&seq);
39883+ return atomic64_inc_return_unchecked(&seq);
39884 }
39885 EXPORT_SYMBOL_GPL(cper_next_record_id);
39886
39887diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39888index af20f17..4e4e545 100644
39889--- a/drivers/firmware/efi/efi.c
39890+++ b/drivers/firmware/efi/efi.c
39891@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39892 };
39893
39894 static struct efivars generic_efivars;
39895-static struct efivar_operations generic_ops;
39896+static efivar_operations_no_const generic_ops __read_only;
39897
39898 static int generic_ops_register(void)
39899 {
39900- generic_ops.get_variable = efi.get_variable;
39901- generic_ops.set_variable = efi.set_variable;
39902- generic_ops.get_next_variable = efi.get_next_variable;
39903- generic_ops.query_variable_store = efi_query_variable_store;
39904+ pax_open_kernel();
39905+ *(void **)&generic_ops.get_variable = efi.get_variable;
39906+ *(void **)&generic_ops.set_variable = efi.set_variable;
39907+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39908+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39909+ pax_close_kernel();
39910
39911 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39912 }
39913diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39914index 50ea412..caccd6e9 100644
39915--- a/drivers/firmware/efi/efivars.c
39916+++ b/drivers/firmware/efi/efivars.c
39917@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39918 static int
39919 create_efivars_bin_attributes(void)
39920 {
39921- struct bin_attribute *attr;
39922+ bin_attribute_no_const *attr;
39923 int error;
39924
39925 /* new_var */
39926diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39927index 2f569aa..c95f4fb 100644
39928--- a/drivers/firmware/google/memconsole.c
39929+++ b/drivers/firmware/google/memconsole.c
39930@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39931 if (!found_memconsole())
39932 return -ENODEV;
39933
39934- memconsole_bin_attr.size = memconsole_length;
39935+ pax_open_kernel();
39936+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39937+ pax_close_kernel();
39938+
39939 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39940 }
39941
39942diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39943index 8765bd6..2e5b147 100644
39944--- a/drivers/gpio/gpio-em.c
39945+++ b/drivers/gpio/gpio-em.c
39946@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39947 struct em_gio_priv *p;
39948 struct resource *io[2], *irq[2];
39949 struct gpio_chip *gpio_chip;
39950- struct irq_chip *irq_chip;
39951+ irq_chip_no_const *irq_chip;
39952 const char *name = dev_name(&pdev->dev);
39953 int ret;
39954
39955diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39956index 7030422..42a3fe9 100644
39957--- a/drivers/gpio/gpio-ich.c
39958+++ b/drivers/gpio/gpio-ich.c
39959@@ -94,7 +94,7 @@ struct ichx_desc {
39960 * this option allows driver caching written output values
39961 */
39962 bool use_outlvl_cache;
39963-};
39964+} __do_const;
39965
39966 static struct {
39967 spinlock_t lock;
39968diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39969index 03c9148..c66e753 100644
39970--- a/drivers/gpio/gpio-rcar.c
39971+++ b/drivers/gpio/gpio-rcar.c
39972@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39973 struct gpio_rcar_priv *p;
39974 struct resource *io, *irq;
39975 struct gpio_chip *gpio_chip;
39976- struct irq_chip *irq_chip;
39977+ irq_chip_no_const *irq_chip;
39978 struct device *dev = &pdev->dev;
39979 const char *name = dev_name(dev);
39980 int ret;
39981diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39982index 66cbcc1..0c5e622 100644
39983--- a/drivers/gpio/gpio-vr41xx.c
39984+++ b/drivers/gpio/gpio-vr41xx.c
39985@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
39986 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39987 maskl, pendl, maskh, pendh);
39988
39989- atomic_inc(&irq_err_count);
39990+ atomic_inc_unchecked(&irq_err_count);
39991
39992 return -EINVAL;
39993 }
39994diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
39995index f48817d..d35d7f8 100644
39996--- a/drivers/gpio/gpiolib.c
39997+++ b/drivers/gpio/gpiolib.c
39998@@ -1458,8 +1458,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
39999 }
40000
40001 if (gpiochip->irqchip) {
40002- gpiochip->irqchip->irq_request_resources = NULL;
40003- gpiochip->irqchip->irq_release_resources = NULL;
40004+ pax_open_kernel();
40005+ *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40006+ *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40007+ pax_close_kernel();
40008 gpiochip->irqchip = NULL;
40009 }
40010 }
40011@@ -1524,8 +1526,10 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40012 gpiochip->irqchip = NULL;
40013 return -EINVAL;
40014 }
40015- irqchip->irq_request_resources = gpiochip_irq_reqres;
40016- irqchip->irq_release_resources = gpiochip_irq_relres;
40017+ pax_open_kernel();
40018+ *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40019+ *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40020+ pax_close_kernel();
40021
40022 /*
40023 * Prepare the mapping since the irqchip shall be orthogonal to
40024diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40025index d8b7099..8a314a5 100644
40026--- a/drivers/gpu/drm/drm_crtc.c
40027+++ b/drivers/gpu/drm/drm_crtc.c
40028@@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40029 goto done;
40030 }
40031
40032- if (copy_to_user(&enum_ptr[copied].name,
40033+ if (copy_to_user(enum_ptr[copied].name,
40034 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40035 ret = -EFAULT;
40036 goto done;
40037diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40038old mode 100644
40039new mode 100755
40040index 8218078..9960928a
40041--- a/drivers/gpu/drm/drm_drv.c
40042+++ b/drivers/gpu/drm/drm_drv.c
40043@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40044 /**
40045 * Copy and IOCTL return string to user space
40046 */
40047-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40048+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40049 {
40050 int len;
40051
40052@@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
40053 struct drm_file *file_priv = filp->private_data;
40054 struct drm_device *dev;
40055 const struct drm_ioctl_desc *ioctl = NULL;
40056- drm_ioctl_t *func;
40057+ drm_ioctl_no_const_t func;
40058 unsigned int nr = DRM_IOCTL_NR(cmd);
40059 int retcode = -EINVAL;
40060 char stack_kdata[128];
40061diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40062index e1eba0b..98f69f9 100644
40063--- a/drivers/gpu/drm/drm_fops.c
40064+++ b/drivers/gpu/drm/drm_fops.c
40065@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40066 return PTR_ERR(minor);
40067
40068 dev = minor->dev;
40069- if (!dev->open_count++)
40070+ if (local_inc_return(&dev->open_count) == 1)
40071 need_setup = 1;
40072
40073 /* share address_space across all char-devs of a single device */
40074@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40075 return 0;
40076
40077 err_undo:
40078- dev->open_count--;
40079+ local_dec(&dev->open_count);
40080 drm_minor_release(minor);
40081 return retcode;
40082 }
40083@@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
40084
40085 mutex_lock(&drm_global_mutex);
40086
40087- DRM_DEBUG("open_count = %d\n", dev->open_count);
40088+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40089
40090 if (dev->driver->preclose)
40091 dev->driver->preclose(dev, file_priv);
40092@@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
40093 * Begin inline drm_release
40094 */
40095
40096- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40097+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40098 task_pid_nr(current),
40099 (long)old_encode_dev(file_priv->minor->kdev->devt),
40100- dev->open_count);
40101+ local_read(&dev->open_count));
40102
40103 /* Release any auth tokens that might point to this file_priv,
40104 (do that under the drm_global_mutex) */
40105@@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40106 * End inline drm_release
40107 */
40108
40109- if (!--dev->open_count) {
40110+ if (local_dec_and_test(&dev->open_count)) {
40111 retcode = drm_lastclose(dev);
40112 if (drm_device_is_unplugged(dev))
40113 drm_put_dev(dev);
40114diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40115index 3d2e91c..d31c4c9 100644
40116--- a/drivers/gpu/drm/drm_global.c
40117+++ b/drivers/gpu/drm/drm_global.c
40118@@ -36,7 +36,7 @@
40119 struct drm_global_item {
40120 struct mutex mutex;
40121 void *object;
40122- int refcount;
40123+ atomic_t refcount;
40124 };
40125
40126 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40127@@ -49,7 +49,7 @@ void drm_global_init(void)
40128 struct drm_global_item *item = &glob[i];
40129 mutex_init(&item->mutex);
40130 item->object = NULL;
40131- item->refcount = 0;
40132+ atomic_set(&item->refcount, 0);
40133 }
40134 }
40135
40136@@ -59,7 +59,7 @@ void drm_global_release(void)
40137 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40138 struct drm_global_item *item = &glob[i];
40139 BUG_ON(item->object != NULL);
40140- BUG_ON(item->refcount != 0);
40141+ BUG_ON(atomic_read(&item->refcount) != 0);
40142 }
40143 }
40144
40145@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40146 struct drm_global_item *item = &glob[ref->global_type];
40147
40148 mutex_lock(&item->mutex);
40149- if (item->refcount == 0) {
40150+ if (atomic_read(&item->refcount) == 0) {
40151 item->object = kzalloc(ref->size, GFP_KERNEL);
40152 if (unlikely(item->object == NULL)) {
40153 ret = -ENOMEM;
40154@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40155 goto out_err;
40156
40157 }
40158- ++item->refcount;
40159+ atomic_inc(&item->refcount);
40160 ref->object = item->object;
40161 mutex_unlock(&item->mutex);
40162 return 0;
40163@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40164 struct drm_global_item *item = &glob[ref->global_type];
40165
40166 mutex_lock(&item->mutex);
40167- BUG_ON(item->refcount == 0);
40168+ BUG_ON(atomic_read(&item->refcount) == 0);
40169 BUG_ON(ref->object != item->object);
40170- if (--item->refcount == 0) {
40171+ if (atomic_dec_and_test(&item->refcount)) {
40172 ref->release(ref);
40173 item->object = NULL;
40174 }
40175diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40176index 7473035..a48b9c5 100644
40177--- a/drivers/gpu/drm/drm_info.c
40178+++ b/drivers/gpu/drm/drm_info.c
40179@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40180 struct drm_local_map *map;
40181 struct drm_map_list *r_list;
40182
40183- /* Hardcoded from _DRM_FRAME_BUFFER,
40184- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40185- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40186- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40187+ static const char * const types[] = {
40188+ [_DRM_FRAME_BUFFER] = "FB",
40189+ [_DRM_REGISTERS] = "REG",
40190+ [_DRM_SHM] = "SHM",
40191+ [_DRM_AGP] = "AGP",
40192+ [_DRM_SCATTER_GATHER] = "SG",
40193+ [_DRM_CONSISTENT] = "PCI"};
40194 const char *type;
40195 int i;
40196
40197@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40198 map = r_list->map;
40199 if (!map)
40200 continue;
40201- if (map->type < 0 || map->type > 5)
40202+ if (map->type >= ARRAY_SIZE(types))
40203 type = "??";
40204 else
40205 type = types[map->type];
40206@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40207 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40208 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40209 vma->vm_flags & VM_IO ? 'i' : '-',
40210+#ifdef CONFIG_GRKERNSEC_HIDESYM
40211+ 0);
40212+#else
40213 vma->vm_pgoff);
40214+#endif
40215
40216 #if defined(__i386__)
40217 pgprot = pgprot_val(vma->vm_page_prot);
40218diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40219index 2f4c4343..dd12cd2 100644
40220--- a/drivers/gpu/drm/drm_ioc32.c
40221+++ b/drivers/gpu/drm/drm_ioc32.c
40222@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40223 request = compat_alloc_user_space(nbytes);
40224 if (!access_ok(VERIFY_WRITE, request, nbytes))
40225 return -EFAULT;
40226- list = (struct drm_buf_desc *) (request + 1);
40227+ list = (struct drm_buf_desc __user *) (request + 1);
40228
40229 if (__put_user(count, &request->count)
40230 || __put_user(list, &request->list))
40231@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40232 request = compat_alloc_user_space(nbytes);
40233 if (!access_ok(VERIFY_WRITE, request, nbytes))
40234 return -EFAULT;
40235- list = (struct drm_buf_pub *) (request + 1);
40236+ list = (struct drm_buf_pub __user *) (request + 1);
40237
40238 if (__put_user(count, &request->count)
40239 || __put_user(list, &request->list))
40240@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40241 return 0;
40242 }
40243
40244-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40245+drm_ioctl_compat_t drm_compat_ioctls[] = {
40246 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40247 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40248 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40249@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40250 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40251 {
40252 unsigned int nr = DRM_IOCTL_NR(cmd);
40253- drm_ioctl_compat_t *fn;
40254 int ret;
40255
40256 /* Assume that ioctls without an explicit compat routine will just
40257@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40258 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40259 return drm_ioctl(filp, cmd, arg);
40260
40261- fn = drm_compat_ioctls[nr];
40262-
40263- if (fn != NULL)
40264- ret = (*fn) (filp, cmd, arg);
40265+ if (drm_compat_ioctls[nr] != NULL)
40266+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40267 else
40268 ret = drm_ioctl(filp, cmd, arg);
40269
40270diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40271index 4c24c3a..c903cab 100644
40272--- a/drivers/gpu/drm/drm_stub.c
40273+++ b/drivers/gpu/drm/drm_stub.c
40274@@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40275
40276 drm_device_set_unplugged(dev);
40277
40278- if (dev->open_count == 0) {
40279+ if (local_read(&dev->open_count) == 0) {
40280 drm_put_dev(dev);
40281 }
40282 mutex_unlock(&drm_global_mutex);
40283diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40284index c22c309..ae758c3 100644
40285--- a/drivers/gpu/drm/drm_sysfs.c
40286+++ b/drivers/gpu/drm/drm_sysfs.c
40287@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40288 */
40289 int drm_sysfs_device_add(struct drm_minor *minor)
40290 {
40291- char *minor_str;
40292+ const char *minor_str;
40293 int r;
40294
40295 if (minor->type == DRM_MINOR_CONTROL)
40296diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40297index d4d16ed..8fb0b51 100644
40298--- a/drivers/gpu/drm/i810/i810_drv.h
40299+++ b/drivers/gpu/drm/i810/i810_drv.h
40300@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40301 int page_flipping;
40302
40303 wait_queue_head_t irq_queue;
40304- atomic_t irq_received;
40305- atomic_t irq_emitted;
40306+ atomic_unchecked_t irq_received;
40307+ atomic_unchecked_t irq_emitted;
40308
40309 int front_offset;
40310 } drm_i810_private_t;
40311diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40312index eedb023..25076a4 100644
40313--- a/drivers/gpu/drm/i915/i915_dma.c
40314+++ b/drivers/gpu/drm/i915/i915_dma.c
40315@@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40316 bool can_switch;
40317
40318 spin_lock(&dev->count_lock);
40319- can_switch = (dev->open_count == 0);
40320+ can_switch = (local_read(&dev->open_count) == 0);
40321 spin_unlock(&dev->count_lock);
40322 return can_switch;
40323 }
40324diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40325index 20fef6c..76c78fb 100644
40326--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40327+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40328@@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40329
40330 static int
40331 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40332- int count)
40333+ unsigned int count)
40334 {
40335- int i;
40336+ unsigned int i;
40337 unsigned relocs_total = 0;
40338 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40339
40340diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40341index 3c59584..500f2e9 100644
40342--- a/drivers/gpu/drm/i915/i915_ioc32.c
40343+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40344@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40345 (unsigned long)request);
40346 }
40347
40348-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40349+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40350 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40351 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40352 [DRM_I915_GETPARAM] = compat_i915_getparam,
40353@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40354 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40355 {
40356 unsigned int nr = DRM_IOCTL_NR(cmd);
40357- drm_ioctl_compat_t *fn = NULL;
40358 int ret;
40359
40360 if (nr < DRM_COMMAND_BASE)
40361 return drm_compat_ioctl(filp, cmd, arg);
40362
40363- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40364- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40365-
40366- if (fn != NULL)
40367+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40368+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40369 ret = (*fn) (filp, cmd, arg);
40370- else
40371+ } else
40372 ret = drm_ioctl(filp, cmd, arg);
40373
40374 return ret;
40375diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40376index c83eb75..d205e5b2 100644
40377--- a/drivers/gpu/drm/i915/intel_display.c
40378+++ b/drivers/gpu/drm/i915/intel_display.c
40379@@ -11179,13 +11179,13 @@ struct intel_quirk {
40380 int subsystem_vendor;
40381 int subsystem_device;
40382 void (*hook)(struct drm_device *dev);
40383-};
40384+} __do_const;
40385
40386 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40387 struct intel_dmi_quirk {
40388 void (*hook)(struct drm_device *dev);
40389 const struct dmi_system_id (*dmi_id_list)[];
40390-};
40391+} __do_const;
40392
40393 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40394 {
40395@@ -11193,18 +11193,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40396 return 1;
40397 }
40398
40399-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40400+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40401 {
40402- .dmi_id_list = &(const struct dmi_system_id[]) {
40403- {
40404- .callback = intel_dmi_reverse_brightness,
40405- .ident = "NCR Corporation",
40406- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40407- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40408- },
40409- },
40410- { } /* terminating entry */
40411+ .callback = intel_dmi_reverse_brightness,
40412+ .ident = "NCR Corporation",
40413+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40414+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40415 },
40416+ },
40417+ { } /* terminating entry */
40418+};
40419+
40420+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40421+ {
40422+ .dmi_id_list = &intel_dmi_quirks_table,
40423 .hook = quirk_invert_brightness,
40424 },
40425 };
40426diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40427index fe45321..836fdca 100644
40428--- a/drivers/gpu/drm/mga/mga_drv.h
40429+++ b/drivers/gpu/drm/mga/mga_drv.h
40430@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40431 u32 clear_cmd;
40432 u32 maccess;
40433
40434- atomic_t vbl_received; /**< Number of vblanks received. */
40435+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40436 wait_queue_head_t fence_queue;
40437- atomic_t last_fence_retired;
40438+ atomic_unchecked_t last_fence_retired;
40439 u32 next_fence_to_post;
40440
40441 unsigned int fb_cpp;
40442diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40443index 86b4bb8..ae237ad 100644
40444--- a/drivers/gpu/drm/mga/mga_ioc32.c
40445+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40446@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40447 return 0;
40448 }
40449
40450-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40451+drm_ioctl_compat_t mga_compat_ioctls[] = {
40452 [DRM_MGA_INIT] = compat_mga_init,
40453 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40454 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40455@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40456 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40457 {
40458 unsigned int nr = DRM_IOCTL_NR(cmd);
40459- drm_ioctl_compat_t *fn = NULL;
40460 int ret;
40461
40462 if (nr < DRM_COMMAND_BASE)
40463 return drm_compat_ioctl(filp, cmd, arg);
40464
40465- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40466- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40467-
40468- if (fn != NULL)
40469+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40470+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40471 ret = (*fn) (filp, cmd, arg);
40472- else
40473+ } else
40474 ret = drm_ioctl(filp, cmd, arg);
40475
40476 return ret;
40477diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40478index 1b071b8..de8601a 100644
40479--- a/drivers/gpu/drm/mga/mga_irq.c
40480+++ b/drivers/gpu/drm/mga/mga_irq.c
40481@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40482 if (crtc != 0)
40483 return 0;
40484
40485- return atomic_read(&dev_priv->vbl_received);
40486+ return atomic_read_unchecked(&dev_priv->vbl_received);
40487 }
40488
40489
40490@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40491 /* VBLANK interrupt */
40492 if (status & MGA_VLINEPEN) {
40493 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40494- atomic_inc(&dev_priv->vbl_received);
40495+ atomic_inc_unchecked(&dev_priv->vbl_received);
40496 drm_handle_vblank(dev, 0);
40497 handled = 1;
40498 }
40499@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40500 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40501 MGA_WRITE(MGA_PRIMEND, prim_end);
40502
40503- atomic_inc(&dev_priv->last_fence_retired);
40504+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40505 wake_up(&dev_priv->fence_queue);
40506 handled = 1;
40507 }
40508@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40509 * using fences.
40510 */
40511 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40512- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40513+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40514 - *sequence) <= (1 << 23)));
40515
40516 *sequence = cur_fence;
40517diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40518index 8268a4c..5105708 100644
40519--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40520+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40521@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40522 struct bit_table {
40523 const char id;
40524 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40525-};
40526+} __no_const;
40527
40528 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40529
40530diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40531index 7efbafa..19f8087 100644
40532--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40533+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40534@@ -97,7 +97,6 @@ struct nouveau_drm {
40535 struct drm_global_reference mem_global_ref;
40536 struct ttm_bo_global_ref bo_global_ref;
40537 struct ttm_bo_device bdev;
40538- atomic_t validate_sequence;
40539 int (*move)(struct nouveau_channel *,
40540 struct ttm_buffer_object *,
40541 struct ttm_mem_reg *, struct ttm_mem_reg *);
40542diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40543index c1a7e5a..38b8539 100644
40544--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40545+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40546@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40547 unsigned long arg)
40548 {
40549 unsigned int nr = DRM_IOCTL_NR(cmd);
40550- drm_ioctl_compat_t *fn = NULL;
40551+ drm_ioctl_compat_t fn = NULL;
40552 int ret;
40553
40554 if (nr < DRM_COMMAND_BASE)
40555diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40556index ab0228f..20b756b 100644
40557--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40558+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40559@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40560 }
40561
40562 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40563- nouveau_vram_manager_init,
40564- nouveau_vram_manager_fini,
40565- nouveau_vram_manager_new,
40566- nouveau_vram_manager_del,
40567- nouveau_vram_manager_debug
40568+ .init = nouveau_vram_manager_init,
40569+ .takedown = nouveau_vram_manager_fini,
40570+ .get_node = nouveau_vram_manager_new,
40571+ .put_node = nouveau_vram_manager_del,
40572+ .debug = nouveau_vram_manager_debug
40573 };
40574
40575 static int
40576@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40577 }
40578
40579 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40580- nouveau_gart_manager_init,
40581- nouveau_gart_manager_fini,
40582- nouveau_gart_manager_new,
40583- nouveau_gart_manager_del,
40584- nouveau_gart_manager_debug
40585+ .init = nouveau_gart_manager_init,
40586+ .takedown = nouveau_gart_manager_fini,
40587+ .get_node = nouveau_gart_manager_new,
40588+ .put_node = nouveau_gart_manager_del,
40589+ .debug = nouveau_gart_manager_debug
40590 };
40591
40592 #include <core/subdev/vm/nv04.h>
40593@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40594 }
40595
40596 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40597- nv04_gart_manager_init,
40598- nv04_gart_manager_fini,
40599- nv04_gart_manager_new,
40600- nv04_gart_manager_del,
40601- nv04_gart_manager_debug
40602+ .init = nv04_gart_manager_init,
40603+ .takedown = nv04_gart_manager_fini,
40604+ .get_node = nv04_gart_manager_new,
40605+ .put_node = nv04_gart_manager_del,
40606+ .debug = nv04_gart_manager_debug
40607 };
40608
40609 int
40610diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40611index fb84da3..d7ee463 100644
40612--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40613+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40614@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40615 bool can_switch;
40616
40617 spin_lock(&dev->count_lock);
40618- can_switch = (dev->open_count == 0);
40619+ can_switch = (local_read(&dev->open_count) == 0);
40620 spin_unlock(&dev->count_lock);
40621 return can_switch;
40622 }
40623diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40624index eb89653..613cf71 100644
40625--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40626+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40627@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40628 int ret;
40629
40630 mutex_lock(&qdev->async_io_mutex);
40631- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40632+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40633 if (qdev->last_sent_io_cmd > irq_num) {
40634 if (intr)
40635 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40636- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40637+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40638 else
40639 ret = wait_event_timeout(qdev->io_cmd_event,
40640- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40641+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40642 /* 0 is timeout, just bail the "hw" has gone away */
40643 if (ret <= 0)
40644 goto out;
40645- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40646+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40647 }
40648 outb(val, addr);
40649 qdev->last_sent_io_cmd = irq_num + 1;
40650 if (intr)
40651 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40652- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40653+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40654 else
40655 ret = wait_event_timeout(qdev->io_cmd_event,
40656- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40657+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40658 out:
40659 if (ret > 0)
40660 ret = 0;
40661diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40662index c3c2bbd..bc3c0fb 100644
40663--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40664+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40665@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40666 struct drm_info_node *node = (struct drm_info_node *) m->private;
40667 struct qxl_device *qdev = node->minor->dev->dev_private;
40668
40669- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40670- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40671- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40672- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40673+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40674+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40675+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40676+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40677 seq_printf(m, "%d\n", qdev->irq_received_error);
40678 return 0;
40679 }
40680diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40681index 36ed40b..0397633 100644
40682--- a/drivers/gpu/drm/qxl/qxl_drv.h
40683+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40684@@ -290,10 +290,10 @@ struct qxl_device {
40685 unsigned int last_sent_io_cmd;
40686
40687 /* interrupt handling */
40688- atomic_t irq_received;
40689- atomic_t irq_received_display;
40690- atomic_t irq_received_cursor;
40691- atomic_t irq_received_io_cmd;
40692+ atomic_unchecked_t irq_received;
40693+ atomic_unchecked_t irq_received_display;
40694+ atomic_unchecked_t irq_received_cursor;
40695+ atomic_unchecked_t irq_received_io_cmd;
40696 unsigned irq_received_error;
40697 wait_queue_head_t display_event;
40698 wait_queue_head_t cursor_event;
40699diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40700index 0bb86e6..d41416d 100644
40701--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40702+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40703@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40704
40705 /* TODO copy slow path code from i915 */
40706 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40707- 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);
40708+ 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);
40709
40710 {
40711 struct qxl_drawable *draw = fb_cmd;
40712@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40713 struct drm_qxl_reloc reloc;
40714
40715 if (copy_from_user(&reloc,
40716- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40717+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40718 sizeof(reloc))) {
40719 ret = -EFAULT;
40720 goto out_free_bos;
40721@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40722
40723 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40724
40725- struct drm_qxl_command *commands =
40726- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40727+ struct drm_qxl_command __user *commands =
40728+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40729
40730- if (copy_from_user(&user_cmd, &commands[cmd_num],
40731+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40732 sizeof(user_cmd)))
40733 return -EFAULT;
40734
40735diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40736index 3485bdc..20d26e3 100644
40737--- a/drivers/gpu/drm/qxl/qxl_irq.c
40738+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40739@@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40740 if (!pending)
40741 return IRQ_NONE;
40742
40743- atomic_inc(&qdev->irq_received);
40744+ atomic_inc_unchecked(&qdev->irq_received);
40745
40746 if (pending & QXL_INTERRUPT_DISPLAY) {
40747- atomic_inc(&qdev->irq_received_display);
40748+ atomic_inc_unchecked(&qdev->irq_received_display);
40749 wake_up_all(&qdev->display_event);
40750 qxl_queue_garbage_collect(qdev, false);
40751 }
40752 if (pending & QXL_INTERRUPT_CURSOR) {
40753- atomic_inc(&qdev->irq_received_cursor);
40754+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40755 wake_up_all(&qdev->cursor_event);
40756 }
40757 if (pending & QXL_INTERRUPT_IO_CMD) {
40758- atomic_inc(&qdev->irq_received_io_cmd);
40759+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40760 wake_up_all(&qdev->io_cmd_event);
40761 }
40762 if (pending & QXL_INTERRUPT_ERROR) {
40763@@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40764 init_waitqueue_head(&qdev->io_cmd_event);
40765 INIT_WORK(&qdev->client_monitors_config_work,
40766 qxl_client_monitors_config_work_func);
40767- atomic_set(&qdev->irq_received, 0);
40768- atomic_set(&qdev->irq_received_display, 0);
40769- atomic_set(&qdev->irq_received_cursor, 0);
40770- atomic_set(&qdev->irq_received_io_cmd, 0);
40771+ atomic_set_unchecked(&qdev->irq_received, 0);
40772+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40773+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40774+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40775 qdev->irq_received_error = 0;
40776 ret = drm_irq_install(qdev->ddev);
40777 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40778diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40779index d52c275..4e6b43d 100644
40780--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40781+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40782@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40783 }
40784 }
40785
40786-static struct vm_operations_struct qxl_ttm_vm_ops;
40787+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40788 static const struct vm_operations_struct *ttm_vm_ops;
40789
40790 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40791@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40792 return r;
40793 if (unlikely(ttm_vm_ops == NULL)) {
40794 ttm_vm_ops = vma->vm_ops;
40795+ pax_open_kernel();
40796 qxl_ttm_vm_ops = *ttm_vm_ops;
40797 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40798+ pax_close_kernel();
40799 }
40800 vma->vm_ops = &qxl_ttm_vm_ops;
40801 return 0;
40802@@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40803 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40804 {
40805 #if defined(CONFIG_DEBUG_FS)
40806- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40807- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40808- unsigned i;
40809+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40810+ {
40811+ .name = "qxl_mem_mm",
40812+ .show = &qxl_mm_dump_table,
40813+ },
40814+ {
40815+ .name = "qxl_surf_mm",
40816+ .show = &qxl_mm_dump_table,
40817+ }
40818+ };
40819
40820- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40821- if (i == 0)
40822- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40823- else
40824- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40825- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40826- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40827- qxl_mem_types_list[i].driver_features = 0;
40828- if (i == 0)
40829- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40830- else
40831- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40832+ pax_open_kernel();
40833+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40834+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40835+ pax_close_kernel();
40836
40837- }
40838- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40839+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40840 #else
40841 return 0;
40842 #endif
40843diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40844index 59459fe..be26b31 100644
40845--- a/drivers/gpu/drm/r128/r128_cce.c
40846+++ b/drivers/gpu/drm/r128/r128_cce.c
40847@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40848
40849 /* GH: Simple idle check.
40850 */
40851- atomic_set(&dev_priv->idle_count, 0);
40852+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40853
40854 /* We don't support anything other than bus-mastering ring mode,
40855 * but the ring can be in either AGP or PCI space for the ring
40856diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40857index 5bf3f5f..7000661 100644
40858--- a/drivers/gpu/drm/r128/r128_drv.h
40859+++ b/drivers/gpu/drm/r128/r128_drv.h
40860@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40861 int is_pci;
40862 unsigned long cce_buffers_offset;
40863
40864- atomic_t idle_count;
40865+ atomic_unchecked_t idle_count;
40866
40867 int page_flipping;
40868 int current_page;
40869 u32 crtc_offset;
40870 u32 crtc_offset_cntl;
40871
40872- atomic_t vbl_received;
40873+ atomic_unchecked_t vbl_received;
40874
40875 u32 color_fmt;
40876 unsigned int front_offset;
40877diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40878index b0d0fd3..a6fbbe4 100644
40879--- a/drivers/gpu/drm/r128/r128_ioc32.c
40880+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40881@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40882 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40883 }
40884
40885-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40886+drm_ioctl_compat_t r128_compat_ioctls[] = {
40887 [DRM_R128_INIT] = compat_r128_init,
40888 [DRM_R128_DEPTH] = compat_r128_depth,
40889 [DRM_R128_STIPPLE] = compat_r128_stipple,
40890@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40891 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40892 {
40893 unsigned int nr = DRM_IOCTL_NR(cmd);
40894- drm_ioctl_compat_t *fn = NULL;
40895 int ret;
40896
40897 if (nr < DRM_COMMAND_BASE)
40898 return drm_compat_ioctl(filp, cmd, arg);
40899
40900- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40901- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40902-
40903- if (fn != NULL)
40904+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40905+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40906 ret = (*fn) (filp, cmd, arg);
40907- else
40908+ } else
40909 ret = drm_ioctl(filp, cmd, arg);
40910
40911 return ret;
40912diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40913index c2ae496..30b5993 100644
40914--- a/drivers/gpu/drm/r128/r128_irq.c
40915+++ b/drivers/gpu/drm/r128/r128_irq.c
40916@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40917 if (crtc != 0)
40918 return 0;
40919
40920- return atomic_read(&dev_priv->vbl_received);
40921+ return atomic_read_unchecked(&dev_priv->vbl_received);
40922 }
40923
40924 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40925@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40926 /* VBLANK interrupt */
40927 if (status & R128_CRTC_VBLANK_INT) {
40928 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40929- atomic_inc(&dev_priv->vbl_received);
40930+ atomic_inc_unchecked(&dev_priv->vbl_received);
40931 drm_handle_vblank(dev, 0);
40932 return IRQ_HANDLED;
40933 }
40934diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40935index e806dac..f81d32f 100644
40936--- a/drivers/gpu/drm/r128/r128_state.c
40937+++ b/drivers/gpu/drm/r128/r128_state.c
40938@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40939
40940 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40941 {
40942- if (atomic_read(&dev_priv->idle_count) == 0)
40943+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40944 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40945 else
40946- atomic_set(&dev_priv->idle_count, 0);
40947+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40948 }
40949
40950 #endif
40951diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40952index 4a85bb6..aaea819 100644
40953--- a/drivers/gpu/drm/radeon/mkregtable.c
40954+++ b/drivers/gpu/drm/radeon/mkregtable.c
40955@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40956 regex_t mask_rex;
40957 regmatch_t match[4];
40958 char buf[1024];
40959- size_t end;
40960+ long end;
40961 int len;
40962 int done = 0;
40963 int r;
40964 unsigned o;
40965 struct offset *offset;
40966 char last_reg_s[10];
40967- int last_reg;
40968+ unsigned long last_reg;
40969
40970 if (regcomp
40971 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40972diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40973index 2cd144c..a01c95a 100644
40974--- a/drivers/gpu/drm/radeon/radeon_device.c
40975+++ b/drivers/gpu/drm/radeon/radeon_device.c
40976@@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40977 bool can_switch;
40978
40979 spin_lock(&dev->count_lock);
40980- can_switch = (dev->open_count == 0);
40981+ can_switch = (local_read(&dev->open_count) == 0);
40982 spin_unlock(&dev->count_lock);
40983 return can_switch;
40984 }
40985diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40986index dafd812..1bf20c7 100644
40987--- a/drivers/gpu/drm/radeon/radeon_drv.h
40988+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40989@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40990
40991 /* SW interrupt */
40992 wait_queue_head_t swi_queue;
40993- atomic_t swi_emitted;
40994+ atomic_unchecked_t swi_emitted;
40995 int vblank_crtc;
40996 uint32_t irq_enable_reg;
40997 uint32_t r500_disp_irq_reg;
40998diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40999index bdb0f93..5ff558f 100644
41000--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41001+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41002@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41003 request = compat_alloc_user_space(sizeof(*request));
41004 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41005 || __put_user(req32.param, &request->param)
41006- || __put_user((void __user *)(unsigned long)req32.value,
41007+ || __put_user((unsigned long)req32.value,
41008 &request->value))
41009 return -EFAULT;
41010
41011@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41012 #define compat_radeon_cp_setparam NULL
41013 #endif /* X86_64 || IA64 */
41014
41015-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41016+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41017 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41018 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41019 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41020@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41021 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41022 {
41023 unsigned int nr = DRM_IOCTL_NR(cmd);
41024- drm_ioctl_compat_t *fn = NULL;
41025 int ret;
41026
41027 if (nr < DRM_COMMAND_BASE)
41028 return drm_compat_ioctl(filp, cmd, arg);
41029
41030- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41031- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41032-
41033- if (fn != NULL)
41034+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41035+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41036 ret = (*fn) (filp, cmd, arg);
41037- else
41038+ } else
41039 ret = drm_ioctl(filp, cmd, arg);
41040
41041 return ret;
41042diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41043index 244b19b..c19226d 100644
41044--- a/drivers/gpu/drm/radeon/radeon_irq.c
41045+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41046@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41047 unsigned int ret;
41048 RING_LOCALS;
41049
41050- atomic_inc(&dev_priv->swi_emitted);
41051- ret = atomic_read(&dev_priv->swi_emitted);
41052+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41053+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41054
41055 BEGIN_RING(4);
41056 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41057@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41058 drm_radeon_private_t *dev_priv =
41059 (drm_radeon_private_t *) dev->dev_private;
41060
41061- atomic_set(&dev_priv->swi_emitted, 0);
41062+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41063 init_waitqueue_head(&dev_priv->swi_queue);
41064
41065 dev->max_vblank_count = 0x001fffff;
41066diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41067index 956ab7f..fbd36d8 100644
41068--- a/drivers/gpu/drm/radeon/radeon_state.c
41069+++ b/drivers/gpu/drm/radeon/radeon_state.c
41070@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41071 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41072 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41073
41074- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41075+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41076 sarea_priv->nbox * sizeof(depth_boxes[0])))
41077 return -EFAULT;
41078
41079@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41080 {
41081 drm_radeon_private_t *dev_priv = dev->dev_private;
41082 drm_radeon_getparam_t *param = data;
41083- int value;
41084+ int value = 0;
41085
41086 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41087
41088diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41089index c8a8a51..219dacc 100644
41090--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41091+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41092@@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41093 man->size = size >> PAGE_SHIFT;
41094 }
41095
41096-static struct vm_operations_struct radeon_ttm_vm_ops;
41097+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41098 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41099
41100 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41101@@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41102 }
41103 if (unlikely(ttm_vm_ops == NULL)) {
41104 ttm_vm_ops = vma->vm_ops;
41105+ pax_open_kernel();
41106 radeon_ttm_vm_ops = *ttm_vm_ops;
41107 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41108+ pax_close_kernel();
41109 }
41110 vma->vm_ops = &radeon_ttm_vm_ops;
41111 return 0;
41112diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41113index edb871d..a275c6ed 100644
41114--- a/drivers/gpu/drm/tegra/dc.c
41115+++ b/drivers/gpu/drm/tegra/dc.c
41116@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41117 }
41118
41119 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41120- dc->debugfs_files[i].data = dc;
41121+ *(void **)&dc->debugfs_files[i].data = dc;
41122
41123 err = drm_debugfs_create_files(dc->debugfs_files,
41124 ARRAY_SIZE(debugfs_files),
41125diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41126index 0e599f0..c9ea7c7 100644
41127--- a/drivers/gpu/drm/tegra/dsi.c
41128+++ b/drivers/gpu/drm/tegra/dsi.c
41129@@ -39,7 +39,7 @@ struct tegra_dsi {
41130 struct clk *clk_lp;
41131 struct clk *clk;
41132
41133- struct drm_info_list *debugfs_files;
41134+ drm_info_list_no_const *debugfs_files;
41135 struct drm_minor *minor;
41136 struct dentry *debugfs;
41137
41138diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41139index 6928015..c9853e7 100644
41140--- a/drivers/gpu/drm/tegra/hdmi.c
41141+++ b/drivers/gpu/drm/tegra/hdmi.c
41142@@ -59,7 +59,7 @@ struct tegra_hdmi {
41143 bool stereo;
41144 bool dvi;
41145
41146- struct drm_info_list *debugfs_files;
41147+ drm_info_list_no_const *debugfs_files;
41148 struct drm_minor *minor;
41149 struct dentry *debugfs;
41150 };
41151diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41152index bd850c9..d9f3573 100644
41153--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41154+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41155@@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41156 }
41157
41158 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41159- ttm_bo_man_init,
41160- ttm_bo_man_takedown,
41161- ttm_bo_man_get_node,
41162- ttm_bo_man_put_node,
41163- ttm_bo_man_debug
41164+ .init = ttm_bo_man_init,
41165+ .takedown = ttm_bo_man_takedown,
41166+ .get_node = ttm_bo_man_get_node,
41167+ .put_node = ttm_bo_man_put_node,
41168+ .debug = ttm_bo_man_debug
41169 };
41170 EXPORT_SYMBOL(ttm_bo_manager_func);
41171diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41172index dbc2def..0a9f710 100644
41173--- a/drivers/gpu/drm/ttm/ttm_memory.c
41174+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41175@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41176 zone->glob = glob;
41177 glob->zone_kernel = zone;
41178 ret = kobject_init_and_add(
41179- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41180+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41181 if (unlikely(ret != 0)) {
41182 kobject_put(&zone->kobj);
41183 return ret;
41184@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41185 zone->glob = glob;
41186 glob->zone_dma32 = zone;
41187 ret = kobject_init_and_add(
41188- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41189+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41190 if (unlikely(ret != 0)) {
41191 kobject_put(&zone->kobj);
41192 return ret;
41193diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41194index 863bef9..cba15cf 100644
41195--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41196+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41197@@ -391,9 +391,9 @@ out:
41198 static unsigned long
41199 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41200 {
41201- static atomic_t start_pool = ATOMIC_INIT(0);
41202+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41203 unsigned i;
41204- unsigned pool_offset = atomic_add_return(1, &start_pool);
41205+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41206 struct ttm_page_pool *pool;
41207 int shrink_pages = sc->nr_to_scan;
41208 unsigned long freed = 0;
41209diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41210index 3771763..883f206 100644
41211--- a/drivers/gpu/drm/udl/udl_fb.c
41212+++ b/drivers/gpu/drm/udl/udl_fb.c
41213@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41214 fb_deferred_io_cleanup(info);
41215 kfree(info->fbdefio);
41216 info->fbdefio = NULL;
41217- info->fbops->fb_mmap = udl_fb_mmap;
41218 }
41219
41220 pr_warn("released /dev/fb%d user=%d count=%d\n",
41221diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41222index ad02732..144f5ed 100644
41223--- a/drivers/gpu/drm/via/via_drv.h
41224+++ b/drivers/gpu/drm/via/via_drv.h
41225@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41226 typedef uint32_t maskarray_t[5];
41227
41228 typedef struct drm_via_irq {
41229- atomic_t irq_received;
41230+ atomic_unchecked_t irq_received;
41231 uint32_t pending_mask;
41232 uint32_t enable_mask;
41233 wait_queue_head_t irq_queue;
41234@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41235 struct timeval last_vblank;
41236 int last_vblank_valid;
41237 unsigned usec_per_vblank;
41238- atomic_t vbl_received;
41239+ atomic_unchecked_t vbl_received;
41240 drm_via_state_t hc_state;
41241 char pci_buf[VIA_PCI_BUF_SIZE];
41242 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41243diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41244index 1319433..a993b0c 100644
41245--- a/drivers/gpu/drm/via/via_irq.c
41246+++ b/drivers/gpu/drm/via/via_irq.c
41247@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41248 if (crtc != 0)
41249 return 0;
41250
41251- return atomic_read(&dev_priv->vbl_received);
41252+ return atomic_read_unchecked(&dev_priv->vbl_received);
41253 }
41254
41255 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41256@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41257
41258 status = VIA_READ(VIA_REG_INTERRUPT);
41259 if (status & VIA_IRQ_VBLANK_PENDING) {
41260- atomic_inc(&dev_priv->vbl_received);
41261- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41262+ atomic_inc_unchecked(&dev_priv->vbl_received);
41263+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41264 do_gettimeofday(&cur_vblank);
41265 if (dev_priv->last_vblank_valid) {
41266 dev_priv->usec_per_vblank =
41267@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41268 dev_priv->last_vblank = cur_vblank;
41269 dev_priv->last_vblank_valid = 1;
41270 }
41271- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41272+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41273 DRM_DEBUG("US per vblank is: %u\n",
41274 dev_priv->usec_per_vblank);
41275 }
41276@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41277
41278 for (i = 0; i < dev_priv->num_irqs; ++i) {
41279 if (status & cur_irq->pending_mask) {
41280- atomic_inc(&cur_irq->irq_received);
41281+ atomic_inc_unchecked(&cur_irq->irq_received);
41282 wake_up(&cur_irq->irq_queue);
41283 handled = 1;
41284 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41285@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41286 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41287 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41288 masks[irq][4]));
41289- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41290+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41291 } else {
41292 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41293 (((cur_irq_sequence =
41294- atomic_read(&cur_irq->irq_received)) -
41295+ atomic_read_unchecked(&cur_irq->irq_received)) -
41296 *sequence) <= (1 << 23)));
41297 }
41298 *sequence = cur_irq_sequence;
41299@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41300 }
41301
41302 for (i = 0; i < dev_priv->num_irqs; ++i) {
41303- atomic_set(&cur_irq->irq_received, 0);
41304+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41305 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41306 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41307 init_waitqueue_head(&cur_irq->irq_queue);
41308@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41309 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41310 case VIA_IRQ_RELATIVE:
41311 irqwait->request.sequence +=
41312- atomic_read(&cur_irq->irq_received);
41313+ atomic_read_unchecked(&cur_irq->irq_received);
41314 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41315 case VIA_IRQ_ABSOLUTE:
41316 break;
41317diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41318index 6b252a8..5975dfe 100644
41319--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41320+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41321@@ -437,7 +437,7 @@ struct vmw_private {
41322 * Fencing and IRQs.
41323 */
41324
41325- atomic_t marker_seq;
41326+ atomic_unchecked_t marker_seq;
41327 wait_queue_head_t fence_queue;
41328 wait_queue_head_t fifo_queue;
41329 int fence_queue_waiters; /* Protected by hw_mutex */
41330diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41331index 6ccd993..618d592 100644
41332--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41333+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41334@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41335 (unsigned int) min,
41336 (unsigned int) fifo->capabilities);
41337
41338- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41339+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41340 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41341 vmw_marker_queue_init(&fifo->marker_queue);
41342 return vmw_fifo_send_fence(dev_priv, &dummy);
41343@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41344 if (reserveable)
41345 iowrite32(bytes, fifo_mem +
41346 SVGA_FIFO_RESERVED);
41347- return fifo_mem + (next_cmd >> 2);
41348+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41349 } else {
41350 need_bounce = true;
41351 }
41352@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41353
41354 fm = vmw_fifo_reserve(dev_priv, bytes);
41355 if (unlikely(fm == NULL)) {
41356- *seqno = atomic_read(&dev_priv->marker_seq);
41357+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41358 ret = -ENOMEM;
41359 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41360 false, 3*HZ);
41361@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41362 }
41363
41364 do {
41365- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41366+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41367 } while (*seqno == 0);
41368
41369 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41370diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41371index b1273e8..9c274fd 100644
41372--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41373+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41374@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41375 }
41376
41377 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41378- vmw_gmrid_man_init,
41379- vmw_gmrid_man_takedown,
41380- vmw_gmrid_man_get_node,
41381- vmw_gmrid_man_put_node,
41382- vmw_gmrid_man_debug
41383+ .init = vmw_gmrid_man_init,
41384+ .takedown = vmw_gmrid_man_takedown,
41385+ .get_node = vmw_gmrid_man_get_node,
41386+ .put_node = vmw_gmrid_man_put_node,
41387+ .debug = vmw_gmrid_man_debug
41388 };
41389diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41390index 37881ec..319065d 100644
41391--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41392+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41393@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41394 int ret;
41395
41396 num_clips = arg->num_clips;
41397- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41398+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41399
41400 if (unlikely(num_clips == 0))
41401 return 0;
41402@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41403 int ret;
41404
41405 num_clips = arg->num_clips;
41406- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41407+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41408
41409 if (unlikely(num_clips == 0))
41410 return 0;
41411diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41412index 0c42376..6febe77 100644
41413--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41414+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41415@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41416 * emitted. Then the fence is stale and signaled.
41417 */
41418
41419- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41420+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41421 > VMW_FENCE_WRAP);
41422
41423 return ret;
41424@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41425
41426 if (fifo_idle)
41427 down_read(&fifo_state->rwsem);
41428- signal_seq = atomic_read(&dev_priv->marker_seq);
41429+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41430 ret = 0;
41431
41432 for (;;) {
41433diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41434index 8a8725c2..afed796 100644
41435--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41436+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41437@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41438 while (!vmw_lag_lt(queue, us)) {
41439 spin_lock(&queue->lock);
41440 if (list_empty(&queue->head))
41441- seqno = atomic_read(&dev_priv->marker_seq);
41442+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41443 else {
41444 marker = list_first_entry(&queue->head,
41445 struct vmw_marker, head);
41446diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41447index 6866448..2ad2b34 100644
41448--- a/drivers/gpu/vga/vga_switcheroo.c
41449+++ b/drivers/gpu/vga/vga_switcheroo.c
41450@@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41451
41452 /* this version is for the case where the power switch is separate
41453 to the device being powered down. */
41454-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41455+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41456 {
41457 /* copy over all the bus versions */
41458 if (dev->bus && dev->bus->pm) {
41459@@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41460 return ret;
41461 }
41462
41463-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41464+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41465 {
41466 /* copy over all the bus versions */
41467 if (dev->bus && dev->bus->pm) {
41468diff --git a/drivers/hid/hid-cherry.c b/drivers/hid/hid-cherry.c
41469index 1bdcccc..f745d2c 100644
41470--- a/drivers/hid/hid-cherry.c
41471+++ b/drivers/hid/hid-cherry.c
41472@@ -28,7 +28,7 @@
41473 static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41474 unsigned int *rsize)
41475 {
41476- if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
41477+ if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
41478 hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
41479 rdesc[11] = rdesc[16] = 0xff;
41480 rdesc[12] = rdesc[17] = 0x03;
41481diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41482index a5c7927..025a2b4 100644
41483--- a/drivers/hid/hid-core.c
41484+++ b/drivers/hid/hid-core.c
41485@@ -2476,7 +2476,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41486
41487 int hid_add_device(struct hid_device *hdev)
41488 {
41489- static atomic_t id = ATOMIC_INIT(0);
41490+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41491 int ret;
41492
41493 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41494@@ -2518,7 +2518,7 @@ int hid_add_device(struct hid_device *hdev)
41495 /* XXX hack, any other cleaner solution after the driver core
41496 * is converted to allow more than 20 bytes as the device name? */
41497 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41498- hdev->vendor, hdev->product, atomic_inc_return(&id));
41499+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41500
41501 hid_debug_register(hdev, dev_name(&hdev->dev));
41502 ret = device_add(&hdev->dev);
41503diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c
41504index e776963..b92bf01 100644
41505--- a/drivers/hid/hid-kye.c
41506+++ b/drivers/hid/hid-kye.c
41507@@ -300,7 +300,7 @@ static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41508 * - change the button usage range to 4-7 for the extra
41509 * buttons
41510 */
41511- if (*rsize >= 74 &&
41512+ if (*rsize >= 75 &&
41513 rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
41514 rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
41515 rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
41516diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
41517index a976f48..f91ff14 100644
41518--- a/drivers/hid/hid-lg.c
41519+++ b/drivers/hid/hid-lg.c
41520@@ -345,14 +345,14 @@ static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41521 struct usb_device_descriptor *udesc;
41522 __u16 bcdDevice, rev_maj, rev_min;
41523
41524- if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 &&
41525+ if ((drv_data->quirks & LG_RDESC) && *rsize >= 91 && rdesc[83] == 0x26 &&
41526 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
41527 hid_info(hdev,
41528 "fixing up Logitech keyboard report descriptor\n");
41529 rdesc[84] = rdesc[89] = 0x4d;
41530 rdesc[85] = rdesc[90] = 0x10;
41531 }
41532- if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 50 &&
41533+ if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 51 &&
41534 rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
41535 rdesc[49] == 0x81 && rdesc[50] == 0x06) {
41536 hid_info(hdev,
41537diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41538index 486dbde..b7ba829 100644
41539--- a/drivers/hid/hid-logitech-dj.c
41540+++ b/drivers/hid/hid-logitech-dj.c
41541@@ -238,13 +238,6 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
41542 return;
41543 }
41544
41545- if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41546- (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41547- dev_err(&djrcv_hdev->dev, "%s: invalid device index:%d\n",
41548- __func__, dj_report->device_index);
41549- return;
41550- }
41551-
41552 if (djrcv_dev->paired_dj_devices[dj_report->device_index]) {
41553 /* The device is already known. No need to reallocate it. */
41554 dbg_hid("%s: device is already known\n", __func__);
41555@@ -557,7 +550,7 @@ static int logi_dj_ll_raw_request(struct hid_device *hid,
41556 if (!out_buf)
41557 return -ENOMEM;
41558
41559- if (count < DJREPORT_SHORT_LENGTH - 2)
41560+ if (count > DJREPORT_SHORT_LENGTH - 2)
41561 count = DJREPORT_SHORT_LENGTH - 2;
41562
41563 out_buf[0] = REPORT_ID_DJ_SHORT;
41564@@ -690,6 +683,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41565 * device (via hid_input_report() ) and return 1 so hid-core does not do
41566 * anything else with it.
41567 */
41568+ if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41569+ (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41570+ dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41571+ __func__, dj_report->device_index);
41572+ return false;
41573+ }
41574
41575 spin_lock_irqsave(&djrcv_dev->lock, flags);
41576 if (dj_report->report_id == REPORT_ID_DJ_SHORT) {
41577diff --git a/drivers/hid/hid-monterey.c b/drivers/hid/hid-monterey.c
41578index 9e14c00..25daf28 100644
41579--- a/drivers/hid/hid-monterey.c
41580+++ b/drivers/hid/hid-monterey.c
41581@@ -24,7 +24,7 @@
41582 static __u8 *mr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41583 unsigned int *rsize)
41584 {
41585- if (*rsize >= 30 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
41586+ if (*rsize >= 31 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
41587 hid_info(hdev, "fixing up button/consumer in HID report descriptor\n");
41588 rdesc[30] = 0x0c;
41589 }
41590diff --git a/drivers/hid/hid-petalynx.c b/drivers/hid/hid-petalynx.c
41591index 736b250..6aca4f2 100644
41592--- a/drivers/hid/hid-petalynx.c
41593+++ b/drivers/hid/hid-petalynx.c
41594@@ -25,7 +25,7 @@
41595 static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41596 unsigned int *rsize)
41597 {
41598- if (*rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
41599+ if (*rsize >= 62 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
41600 rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
41601 rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
41602 hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n");
41603diff --git a/drivers/hid/hid-sunplus.c b/drivers/hid/hid-sunplus.c
41604index 87fc91e..91072fa 100644
41605--- a/drivers/hid/hid-sunplus.c
41606+++ b/drivers/hid/hid-sunplus.c
41607@@ -24,7 +24,7 @@
41608 static __u8 *sp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41609 unsigned int *rsize)
41610 {
41611- if (*rsize >= 107 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
41612+ if (*rsize >= 112 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
41613 rdesc[106] == 0x03) {
41614 hid_info(hdev, "fixing up Sunplus Wireless Desktop report descriptor\n");
41615 rdesc[105] = rdesc[110] = 0x03;
41616diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41617index c13fb5b..55a3802 100644
41618--- a/drivers/hid/hid-wiimote-debug.c
41619+++ b/drivers/hid/hid-wiimote-debug.c
41620@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41621 else if (size == 0)
41622 return -EIO;
41623
41624- if (copy_to_user(u, buf, size))
41625+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41626 return -EFAULT;
41627
41628 *off += size;
41629diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41630index 0d078c3..cd0962c 100644
41631--- a/drivers/hid/uhid.c
41632+++ b/drivers/hid/uhid.c
41633@@ -47,7 +47,7 @@ struct uhid_device {
41634 struct mutex report_lock;
41635 wait_queue_head_t report_wait;
41636 atomic_t report_done;
41637- atomic_t report_id;
41638+ atomic_unchecked_t report_id;
41639 struct uhid_event report_buf;
41640 };
41641
41642@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41643
41644 spin_lock_irqsave(&uhid->qlock, flags);
41645 ev->type = UHID_FEATURE;
41646- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41647+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41648 ev->u.feature.rnum = rnum;
41649 ev->u.feature.rtype = report_type;
41650
41651@@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41652 spin_lock_irqsave(&uhid->qlock, flags);
41653
41654 /* id for old report; drop it silently */
41655- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41656+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41657 goto unlock;
41658 if (atomic_read(&uhid->report_done))
41659 goto unlock;
41660diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41661index 602ca86..10a6573 100644
41662--- a/drivers/hv/channel.c
41663+++ b/drivers/hv/channel.c
41664@@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41665 int ret = 0;
41666 int t;
41667
41668- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41669- atomic_inc(&vmbus_connection.next_gpadl_handle);
41670+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41671+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41672
41673 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41674 if (ret)
41675diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41676index bcb4950..61dba6c 100644
41677--- a/drivers/hv/hv.c
41678+++ b/drivers/hv/hv.c
41679@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41680 u64 output_address = (output) ? virt_to_phys(output) : 0;
41681 u32 output_address_hi = output_address >> 32;
41682 u32 output_address_lo = output_address & 0xFFFFFFFF;
41683- void *hypercall_page = hv_context.hypercall_page;
41684+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41685
41686 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41687 "=a"(hv_status_lo) : "d" (control_hi),
41688@@ -154,7 +154,7 @@ int hv_init(void)
41689 /* See if the hypercall page is already set */
41690 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41691
41692- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41693+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41694
41695 if (!virtaddr)
41696 goto cleanup;
41697diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41698index 5e90c5d..d8fcefb 100644
41699--- a/drivers/hv/hv_balloon.c
41700+++ b/drivers/hv/hv_balloon.c
41701@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41702
41703 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41704 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41705-static atomic_t trans_id = ATOMIC_INIT(0);
41706+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41707
41708 static int dm_ring_size = (5 * PAGE_SIZE);
41709
41710@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41711 pr_info("Memory hot add failed\n");
41712
41713 dm->state = DM_INITIALIZED;
41714- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41715+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41716 vmbus_sendpacket(dm->dev->channel, &resp,
41717 sizeof(struct dm_hot_add_response),
41718 (unsigned long)NULL,
41719@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41720 memset(&status, 0, sizeof(struct dm_status));
41721 status.hdr.type = DM_STATUS_REPORT;
41722 status.hdr.size = sizeof(struct dm_status);
41723- status.hdr.trans_id = atomic_inc_return(&trans_id);
41724+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41725
41726 /*
41727 * The host expects the guest to report free memory.
41728@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41729 * send the status. This can happen if we were interrupted
41730 * after we picked our transaction ID.
41731 */
41732- if (status.hdr.trans_id != atomic_read(&trans_id))
41733+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41734 return;
41735
41736 /*
41737@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41738 */
41739
41740 do {
41741- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41742+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41743 ret = vmbus_sendpacket(dm_device.dev->channel,
41744 bl_resp,
41745 bl_resp->hdr.size,
41746@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41747
41748 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41749 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41750- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41751+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41752 resp.hdr.size = sizeof(struct dm_unballoon_response);
41753
41754 vmbus_sendpacket(dm_device.dev->channel, &resp,
41755@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41756 memset(&version_req, 0, sizeof(struct dm_version_request));
41757 version_req.hdr.type = DM_VERSION_REQUEST;
41758 version_req.hdr.size = sizeof(struct dm_version_request);
41759- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41760+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41761 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41762 version_req.is_last_attempt = 1;
41763
41764@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41765 memset(&version_req, 0, sizeof(struct dm_version_request));
41766 version_req.hdr.type = DM_VERSION_REQUEST;
41767 version_req.hdr.size = sizeof(struct dm_version_request);
41768- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41769+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41770 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41771 version_req.is_last_attempt = 0;
41772
41773@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41774 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41775 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41776 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41777- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41778+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41779
41780 cap_msg.caps.cap_bits.balloon = 1;
41781 cap_msg.caps.cap_bits.hot_add = 1;
41782diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41783index 860134d..ea3a79a 100644
41784--- a/drivers/hv/hyperv_vmbus.h
41785+++ b/drivers/hv/hyperv_vmbus.h
41786@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41787 struct vmbus_connection {
41788 enum vmbus_connect_state conn_state;
41789
41790- atomic_t next_gpadl_handle;
41791+ atomic_unchecked_t next_gpadl_handle;
41792
41793 /*
41794 * Represents channel interrupts. Each bit position represents a
41795diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41796index 8e53a3c..7a64e44 100644
41797--- a/drivers/hv/vmbus_drv.c
41798+++ b/drivers/hv/vmbus_drv.c
41799@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41800 {
41801 int ret = 0;
41802
41803- static atomic_t device_num = ATOMIC_INIT(0);
41804+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41805
41806 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41807- atomic_inc_return(&device_num));
41808+ atomic_inc_return_unchecked(&device_num));
41809
41810 child_device_obj->device.bus = &hv_bus;
41811 child_device_obj->device.parent = &hv_acpi_dev->dev;
41812diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41813index 579bdf9..75118b5 100644
41814--- a/drivers/hwmon/acpi_power_meter.c
41815+++ b/drivers/hwmon/acpi_power_meter.c
41816@@ -116,7 +116,7 @@ struct sensor_template {
41817 struct device_attribute *devattr,
41818 const char *buf, size_t count);
41819 int index;
41820-};
41821+} __do_const;
41822
41823 /* Averaging interval */
41824 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41825@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41826 struct sensor_template *attrs)
41827 {
41828 struct device *dev = &resource->acpi_dev->dev;
41829- struct sensor_device_attribute *sensors =
41830+ sensor_device_attribute_no_const *sensors =
41831 &resource->sensors[resource->num_sensors];
41832 int res = 0;
41833
41834diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41835index 3288f13..71cfb4e 100644
41836--- a/drivers/hwmon/applesmc.c
41837+++ b/drivers/hwmon/applesmc.c
41838@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41839 {
41840 struct applesmc_node_group *grp;
41841 struct applesmc_dev_attr *node;
41842- struct attribute *attr;
41843+ attribute_no_const *attr;
41844 int ret, i;
41845
41846 for (grp = groups; grp->format; grp++) {
41847diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41848index ae208f6..48b6c5b 100644
41849--- a/drivers/hwmon/asus_atk0110.c
41850+++ b/drivers/hwmon/asus_atk0110.c
41851@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41852 struct atk_sensor_data {
41853 struct list_head list;
41854 struct atk_data *data;
41855- struct device_attribute label_attr;
41856- struct device_attribute input_attr;
41857- struct device_attribute limit1_attr;
41858- struct device_attribute limit2_attr;
41859+ device_attribute_no_const label_attr;
41860+ device_attribute_no_const input_attr;
41861+ device_attribute_no_const limit1_attr;
41862+ device_attribute_no_const limit2_attr;
41863 char label_attr_name[ATTR_NAME_SIZE];
41864 char input_attr_name[ATTR_NAME_SIZE];
41865 char limit1_attr_name[ATTR_NAME_SIZE];
41866@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41867 static struct device_attribute atk_name_attr =
41868 __ATTR(name, 0444, atk_name_show, NULL);
41869
41870-static void atk_init_attribute(struct device_attribute *attr, char *name,
41871+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41872 sysfs_show_func show)
41873 {
41874 sysfs_attr_init(&attr->attr);
41875diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41876index d76f0b7..55ae976 100644
41877--- a/drivers/hwmon/coretemp.c
41878+++ b/drivers/hwmon/coretemp.c
41879@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41880 return NOTIFY_OK;
41881 }
41882
41883-static struct notifier_block coretemp_cpu_notifier __refdata = {
41884+static struct notifier_block coretemp_cpu_notifier = {
41885 .notifier_call = coretemp_cpu_callback,
41886 };
41887
41888diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41889index 632f1dc..57e6a58 100644
41890--- a/drivers/hwmon/ibmaem.c
41891+++ b/drivers/hwmon/ibmaem.c
41892@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41893 struct aem_rw_sensor_template *rw)
41894 {
41895 struct device *dev = &data->pdev->dev;
41896- struct sensor_device_attribute *sensors = data->sensors;
41897+ sensor_device_attribute_no_const *sensors = data->sensors;
41898 int err;
41899
41900 /* Set up read-only sensors */
41901diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41902index 9fbb1b1..efbaa3e 100644
41903--- a/drivers/hwmon/iio_hwmon.c
41904+++ b/drivers/hwmon/iio_hwmon.c
41905@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41906 {
41907 struct device *dev = &pdev->dev;
41908 struct iio_hwmon_state *st;
41909- struct sensor_device_attribute *a;
41910+ sensor_device_attribute_no_const *a;
41911 int ret, i;
41912 int in_i = 1, temp_i = 1, curr_i = 1;
41913 enum iio_chan_type type;
41914diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41915index 38d5a63..cf2c2ea 100644
41916--- a/drivers/hwmon/nct6775.c
41917+++ b/drivers/hwmon/nct6775.c
41918@@ -944,10 +944,10 @@ static struct attribute_group *
41919 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41920 int repeat)
41921 {
41922- struct attribute_group *group;
41923+ attribute_group_no_const *group;
41924 struct sensor_device_attr_u *su;
41925- struct sensor_device_attribute *a;
41926- struct sensor_device_attribute_2 *a2;
41927+ sensor_device_attribute_no_const *a;
41928+ sensor_device_attribute_2_no_const *a2;
41929 struct attribute **attrs;
41930 struct sensor_device_template **t;
41931 int i, count;
41932diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41933index 291d11f..3f0dbbd 100644
41934--- a/drivers/hwmon/pmbus/pmbus_core.c
41935+++ b/drivers/hwmon/pmbus/pmbus_core.c
41936@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41937 return 0;
41938 }
41939
41940-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41941+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41942 const char *name,
41943 umode_t mode,
41944 ssize_t (*show)(struct device *dev,
41945@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41946 dev_attr->store = store;
41947 }
41948
41949-static void pmbus_attr_init(struct sensor_device_attribute *a,
41950+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41951 const char *name,
41952 umode_t mode,
41953 ssize_t (*show)(struct device *dev,
41954@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41955 u16 reg, u8 mask)
41956 {
41957 struct pmbus_boolean *boolean;
41958- struct sensor_device_attribute *a;
41959+ sensor_device_attribute_no_const *a;
41960
41961 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41962 if (!boolean)
41963@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41964 bool update, bool readonly)
41965 {
41966 struct pmbus_sensor *sensor;
41967- struct device_attribute *a;
41968+ device_attribute_no_const *a;
41969
41970 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41971 if (!sensor)
41972@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41973 const char *lstring, int index)
41974 {
41975 struct pmbus_label *label;
41976- struct device_attribute *a;
41977+ device_attribute_no_const *a;
41978
41979 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41980 if (!label)
41981diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41982index 97cd45a..ac54d8b 100644
41983--- a/drivers/hwmon/sht15.c
41984+++ b/drivers/hwmon/sht15.c
41985@@ -169,7 +169,7 @@ struct sht15_data {
41986 int supply_uv;
41987 bool supply_uv_valid;
41988 struct work_struct update_supply_work;
41989- atomic_t interrupt_handled;
41990+ atomic_unchecked_t interrupt_handled;
41991 };
41992
41993 /**
41994@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41995 ret = gpio_direction_input(data->pdata->gpio_data);
41996 if (ret)
41997 return ret;
41998- atomic_set(&data->interrupt_handled, 0);
41999+ atomic_set_unchecked(&data->interrupt_handled, 0);
42000
42001 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42002 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42003 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42004 /* Only relevant if the interrupt hasn't occurred. */
42005- if (!atomic_read(&data->interrupt_handled))
42006+ if (!atomic_read_unchecked(&data->interrupt_handled))
42007 schedule_work(&data->read_work);
42008 }
42009 ret = wait_event_timeout(data->wait_queue,
42010@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42011
42012 /* First disable the interrupt */
42013 disable_irq_nosync(irq);
42014- atomic_inc(&data->interrupt_handled);
42015+ atomic_inc_unchecked(&data->interrupt_handled);
42016 /* Then schedule a reading work struct */
42017 if (data->state != SHT15_READING_NOTHING)
42018 schedule_work(&data->read_work);
42019@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42020 * If not, then start the interrupt again - care here as could
42021 * have gone low in meantime so verify it hasn't!
42022 */
42023- atomic_set(&data->interrupt_handled, 0);
42024+ atomic_set_unchecked(&data->interrupt_handled, 0);
42025 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42026 /* If still not occurred or another handler was scheduled */
42027 if (gpio_get_value(data->pdata->gpio_data)
42028- || atomic_read(&data->interrupt_handled))
42029+ || atomic_read_unchecked(&data->interrupt_handled))
42030 return;
42031 }
42032
42033diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42034index 8df43c5..b07b91d 100644
42035--- a/drivers/hwmon/via-cputemp.c
42036+++ b/drivers/hwmon/via-cputemp.c
42037@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42038 return NOTIFY_OK;
42039 }
42040
42041-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42042+static struct notifier_block via_cputemp_cpu_notifier = {
42043 .notifier_call = via_cputemp_cpu_callback,
42044 };
42045
42046diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42047index 41fc683..a39cfea 100644
42048--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42049+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42050@@ -43,7 +43,7 @@
42051 extern struct i2c_adapter amd756_smbus;
42052
42053 static struct i2c_adapter *s4882_adapter;
42054-static struct i2c_algorithm *s4882_algo;
42055+static i2c_algorithm_no_const *s4882_algo;
42056
42057 /* Wrapper access functions for multiplexed SMBus */
42058 static DEFINE_MUTEX(amd756_lock);
42059diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42060index 721f7eb..0fd2a09 100644
42061--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42062+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42063@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42064 /* usb layer */
42065
42066 /* Send command to device, and get response. */
42067-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42068+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42069 {
42070 int ret = 0;
42071 int actual;
42072diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42073index b170bdf..3c76427 100644
42074--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42075+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42076@@ -41,7 +41,7 @@
42077 extern struct i2c_adapter *nforce2_smbus;
42078
42079 static struct i2c_adapter *s4985_adapter;
42080-static struct i2c_algorithm *s4985_algo;
42081+static i2c_algorithm_no_const *s4985_algo;
42082
42083 /* Wrapper access functions for multiplexed SMBus */
42084 static DEFINE_MUTEX(nforce2_lock);
42085diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42086index 80b47e8..1a6040d9 100644
42087--- a/drivers/i2c/i2c-dev.c
42088+++ b/drivers/i2c/i2c-dev.c
42089@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42090 break;
42091 }
42092
42093- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42094+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42095 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42096 if (IS_ERR(rdwr_pa[i].buf)) {
42097 res = PTR_ERR(rdwr_pa[i].buf);
42098diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42099index 0b510ba..4fbb5085 100644
42100--- a/drivers/ide/ide-cd.c
42101+++ b/drivers/ide/ide-cd.c
42102@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42103 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42104 if ((unsigned long)buf & alignment
42105 || blk_rq_bytes(rq) & q->dma_pad_mask
42106- || object_is_on_stack(buf))
42107+ || object_starts_on_stack(buf))
42108 drive->dma = 0;
42109 }
42110 }
42111diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42112index ede16aec..e423e8a 100644
42113--- a/drivers/iio/industrialio-core.c
42114+++ b/drivers/iio/industrialio-core.c
42115@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42116 }
42117
42118 static
42119-int __iio_device_attr_init(struct device_attribute *dev_attr,
42120+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42121 const char *postfix,
42122 struct iio_chan_spec const *chan,
42123 ssize_t (*readfunc)(struct device *dev,
42124diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42125index c323917..6ddea8b 100644
42126--- a/drivers/infiniband/core/cm.c
42127+++ b/drivers/infiniband/core/cm.c
42128@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42129
42130 struct cm_counter_group {
42131 struct kobject obj;
42132- atomic_long_t counter[CM_ATTR_COUNT];
42133+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42134 };
42135
42136 struct cm_counter_attribute {
42137@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42138 struct ib_mad_send_buf *msg = NULL;
42139 int ret;
42140
42141- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42142+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42143 counter[CM_REQ_COUNTER]);
42144
42145 /* Quick state check to discard duplicate REQs. */
42146@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42147 if (!cm_id_priv)
42148 return;
42149
42150- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42151+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42152 counter[CM_REP_COUNTER]);
42153 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42154 if (ret)
42155@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42156 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42157 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42158 spin_unlock_irq(&cm_id_priv->lock);
42159- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42160+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42161 counter[CM_RTU_COUNTER]);
42162 goto out;
42163 }
42164@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42165 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42166 dreq_msg->local_comm_id);
42167 if (!cm_id_priv) {
42168- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42169+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42170 counter[CM_DREQ_COUNTER]);
42171 cm_issue_drep(work->port, work->mad_recv_wc);
42172 return -EINVAL;
42173@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42174 case IB_CM_MRA_REP_RCVD:
42175 break;
42176 case IB_CM_TIMEWAIT:
42177- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42178+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42179 counter[CM_DREQ_COUNTER]);
42180 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42181 goto unlock;
42182@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42183 cm_free_msg(msg);
42184 goto deref;
42185 case IB_CM_DREQ_RCVD:
42186- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42187+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42188 counter[CM_DREQ_COUNTER]);
42189 goto unlock;
42190 default:
42191@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42192 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42193 cm_id_priv->msg, timeout)) {
42194 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42195- atomic_long_inc(&work->port->
42196+ atomic_long_inc_unchecked(&work->port->
42197 counter_group[CM_RECV_DUPLICATES].
42198 counter[CM_MRA_COUNTER]);
42199 goto out;
42200@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42201 break;
42202 case IB_CM_MRA_REQ_RCVD:
42203 case IB_CM_MRA_REP_RCVD:
42204- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42205+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42206 counter[CM_MRA_COUNTER]);
42207 /* fall through */
42208 default:
42209@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42210 case IB_CM_LAP_IDLE:
42211 break;
42212 case IB_CM_MRA_LAP_SENT:
42213- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42214+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42215 counter[CM_LAP_COUNTER]);
42216 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42217 goto unlock;
42218@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42219 cm_free_msg(msg);
42220 goto deref;
42221 case IB_CM_LAP_RCVD:
42222- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42223+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42224 counter[CM_LAP_COUNTER]);
42225 goto unlock;
42226 default:
42227@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42228 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42229 if (cur_cm_id_priv) {
42230 spin_unlock_irq(&cm.lock);
42231- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42232+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42233 counter[CM_SIDR_REQ_COUNTER]);
42234 goto out; /* Duplicate message. */
42235 }
42236@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42237 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42238 msg->retries = 1;
42239
42240- atomic_long_add(1 + msg->retries,
42241+ atomic_long_add_unchecked(1 + msg->retries,
42242 &port->counter_group[CM_XMIT].counter[attr_index]);
42243 if (msg->retries)
42244- atomic_long_add(msg->retries,
42245+ atomic_long_add_unchecked(msg->retries,
42246 &port->counter_group[CM_XMIT_RETRIES].
42247 counter[attr_index]);
42248
42249@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42250 }
42251
42252 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42253- atomic_long_inc(&port->counter_group[CM_RECV].
42254+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42255 counter[attr_id - CM_ATTR_ID_OFFSET]);
42256
42257 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42258@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42259 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42260
42261 return sprintf(buf, "%ld\n",
42262- atomic_long_read(&group->counter[cm_attr->index]));
42263+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42264 }
42265
42266 static const struct sysfs_ops cm_counter_ops = {
42267diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42268index 9f5ad7c..588cd84 100644
42269--- a/drivers/infiniband/core/fmr_pool.c
42270+++ b/drivers/infiniband/core/fmr_pool.c
42271@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42272
42273 struct task_struct *thread;
42274
42275- atomic_t req_ser;
42276- atomic_t flush_ser;
42277+ atomic_unchecked_t req_ser;
42278+ atomic_unchecked_t flush_ser;
42279
42280 wait_queue_head_t force_wait;
42281 };
42282@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42283 struct ib_fmr_pool *pool = pool_ptr;
42284
42285 do {
42286- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42287+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42288 ib_fmr_batch_release(pool);
42289
42290- atomic_inc(&pool->flush_ser);
42291+ atomic_inc_unchecked(&pool->flush_ser);
42292 wake_up_interruptible(&pool->force_wait);
42293
42294 if (pool->flush_function)
42295@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42296 }
42297
42298 set_current_state(TASK_INTERRUPTIBLE);
42299- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42300+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42301 !kthread_should_stop())
42302 schedule();
42303 __set_current_state(TASK_RUNNING);
42304@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42305 pool->dirty_watermark = params->dirty_watermark;
42306 pool->dirty_len = 0;
42307 spin_lock_init(&pool->pool_lock);
42308- atomic_set(&pool->req_ser, 0);
42309- atomic_set(&pool->flush_ser, 0);
42310+ atomic_set_unchecked(&pool->req_ser, 0);
42311+ atomic_set_unchecked(&pool->flush_ser, 0);
42312 init_waitqueue_head(&pool->force_wait);
42313
42314 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42315@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42316 }
42317 spin_unlock_irq(&pool->pool_lock);
42318
42319- serial = atomic_inc_return(&pool->req_ser);
42320+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42321 wake_up_process(pool->thread);
42322
42323 if (wait_event_interruptible(pool->force_wait,
42324- atomic_read(&pool->flush_ser) - serial >= 0))
42325+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42326 return -EINTR;
42327
42328 return 0;
42329@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42330 } else {
42331 list_add_tail(&fmr->list, &pool->dirty_list);
42332 if (++pool->dirty_len >= pool->dirty_watermark) {
42333- atomic_inc(&pool->req_ser);
42334+ atomic_inc_unchecked(&pool->req_ser);
42335 wake_up_process(pool->thread);
42336 }
42337 }
42338diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42339index ec7a298..8742e59 100644
42340--- a/drivers/infiniband/hw/cxgb4/mem.c
42341+++ b/drivers/infiniband/hw/cxgb4/mem.c
42342@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42343 int err;
42344 struct fw_ri_tpte tpt;
42345 u32 stag_idx;
42346- static atomic_t key;
42347+ static atomic_unchecked_t key;
42348
42349 if (c4iw_fatal_error(rdev))
42350 return -EIO;
42351@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42352 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42353 rdev->stats.stag.max = rdev->stats.stag.cur;
42354 mutex_unlock(&rdev->stats.lock);
42355- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42356+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42357 }
42358 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42359 __func__, stag_state, type, pdid, stag_idx);
42360diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42361index 79b3dbc..96e5fcc 100644
42362--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42363+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42364@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42365 struct ib_atomic_eth *ateth;
42366 struct ipath_ack_entry *e;
42367 u64 vaddr;
42368- atomic64_t *maddr;
42369+ atomic64_unchecked_t *maddr;
42370 u64 sdata;
42371 u32 rkey;
42372 u8 next;
42373@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42374 IB_ACCESS_REMOTE_ATOMIC)))
42375 goto nack_acc_unlck;
42376 /* Perform atomic OP and save result. */
42377- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42378+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42379 sdata = be64_to_cpu(ateth->swap_data);
42380 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42381 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42382- (u64) atomic64_add_return(sdata, maddr) - sdata :
42383+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42384 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42385 be64_to_cpu(ateth->compare_data),
42386 sdata);
42387diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42388index 1f95bba..9530f87 100644
42389--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42390+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42391@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42392 unsigned long flags;
42393 struct ib_wc wc;
42394 u64 sdata;
42395- atomic64_t *maddr;
42396+ atomic64_unchecked_t *maddr;
42397 enum ib_wc_status send_status;
42398
42399 /*
42400@@ -382,11 +382,11 @@ again:
42401 IB_ACCESS_REMOTE_ATOMIC)))
42402 goto acc_err;
42403 /* Perform atomic OP and save result. */
42404- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42405+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42406 sdata = wqe->wr.wr.atomic.compare_add;
42407 *(u64 *) sqp->s_sge.sge.vaddr =
42408 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42409- (u64) atomic64_add_return(sdata, maddr) - sdata :
42410+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42411 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42412 sdata, wqe->wr.wr.atomic.swap);
42413 goto send_comp;
42414diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42415index fd36ec6..a6a082f 100644
42416--- a/drivers/infiniband/hw/mlx4/mad.c
42417+++ b/drivers/infiniband/hw/mlx4/mad.c
42418@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42419
42420 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42421 {
42422- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42423+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42424 cpu_to_be64(0xff00000000000000LL);
42425 }
42426
42427diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42428index ed327e6..ca1739e0 100644
42429--- a/drivers/infiniband/hw/mlx4/mcg.c
42430+++ b/drivers/infiniband/hw/mlx4/mcg.c
42431@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42432 {
42433 char name[20];
42434
42435- atomic_set(&ctx->tid, 0);
42436+ atomic_set_unchecked(&ctx->tid, 0);
42437 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42438 ctx->mcg_wq = create_singlethread_workqueue(name);
42439 if (!ctx->mcg_wq)
42440diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42441index 66b0b7d..f14836a 100644
42442--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42443+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42444@@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42445 struct list_head mcg_mgid0_list;
42446 struct workqueue_struct *mcg_wq;
42447 struct mlx4_ib_demux_pv_ctx **tun;
42448- atomic_t tid;
42449+ atomic_unchecked_t tid;
42450 int flushing; /* flushing the work queue */
42451 };
42452
42453diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42454index 9d3e5c1..6f166df 100644
42455--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42456+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42457@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42458 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42459 }
42460
42461-int mthca_QUERY_FW(struct mthca_dev *dev)
42462+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42463 {
42464 struct mthca_mailbox *mailbox;
42465 u32 *outbox;
42466@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42467 CMD_TIME_CLASS_B);
42468 }
42469
42470-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42471+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42472 int num_mtt)
42473 {
42474 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42475@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42476 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42477 }
42478
42479-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42480+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42481 int eq_num)
42482 {
42483 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42484@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42485 CMD_TIME_CLASS_B);
42486 }
42487
42488-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42489+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42490 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42491 void *in_mad, void *response_mad)
42492 {
42493diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42494index ded76c1..0cf0a08 100644
42495--- a/drivers/infiniband/hw/mthca/mthca_main.c
42496+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42497@@ -692,7 +692,7 @@ err_close:
42498 return err;
42499 }
42500
42501-static int mthca_setup_hca(struct mthca_dev *dev)
42502+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42503 {
42504 int err;
42505
42506diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42507index ed9a989..6aa5dc2 100644
42508--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42509+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42510@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42511 * through the bitmaps)
42512 */
42513
42514-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42515+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42516 {
42517 int o;
42518 int m;
42519@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42520 return key;
42521 }
42522
42523-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42524+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42525 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42526 {
42527 struct mthca_mailbox *mailbox;
42528@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42529 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42530 }
42531
42532-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42533+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42534 u64 *buffer_list, int buffer_size_shift,
42535 int list_len, u64 iova, u64 total_size,
42536 u32 access, struct mthca_mr *mr)
42537diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42538index 415f8e1..e34214e 100644
42539--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42540+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42541@@ -764,7 +764,7 @@ unlock:
42542 return 0;
42543 }
42544
42545-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42546+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42547 {
42548 struct mthca_dev *dev = to_mdev(ibcq->device);
42549 struct mthca_cq *cq = to_mcq(ibcq);
42550diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42551index 353c7b0..c6ce921 100644
42552--- a/drivers/infiniband/hw/nes/nes.c
42553+++ b/drivers/infiniband/hw/nes/nes.c
42554@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42555 LIST_HEAD(nes_adapter_list);
42556 static LIST_HEAD(nes_dev_list);
42557
42558-atomic_t qps_destroyed;
42559+atomic_unchecked_t qps_destroyed;
42560
42561 static unsigned int ee_flsh_adapter;
42562 static unsigned int sysfs_nonidx_addr;
42563@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42564 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42565 struct nes_adapter *nesadapter = nesdev->nesadapter;
42566
42567- atomic_inc(&qps_destroyed);
42568+ atomic_inc_unchecked(&qps_destroyed);
42569
42570 /* Free the control structures */
42571
42572diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42573index 33cc589..3bd6538 100644
42574--- a/drivers/infiniband/hw/nes/nes.h
42575+++ b/drivers/infiniband/hw/nes/nes.h
42576@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42577 extern unsigned int wqm_quanta;
42578 extern struct list_head nes_adapter_list;
42579
42580-extern atomic_t cm_connects;
42581-extern atomic_t cm_accepts;
42582-extern atomic_t cm_disconnects;
42583-extern atomic_t cm_closes;
42584-extern atomic_t cm_connecteds;
42585-extern atomic_t cm_connect_reqs;
42586-extern atomic_t cm_rejects;
42587-extern atomic_t mod_qp_timouts;
42588-extern atomic_t qps_created;
42589-extern atomic_t qps_destroyed;
42590-extern atomic_t sw_qps_destroyed;
42591+extern atomic_unchecked_t cm_connects;
42592+extern atomic_unchecked_t cm_accepts;
42593+extern atomic_unchecked_t cm_disconnects;
42594+extern atomic_unchecked_t cm_closes;
42595+extern atomic_unchecked_t cm_connecteds;
42596+extern atomic_unchecked_t cm_connect_reqs;
42597+extern atomic_unchecked_t cm_rejects;
42598+extern atomic_unchecked_t mod_qp_timouts;
42599+extern atomic_unchecked_t qps_created;
42600+extern atomic_unchecked_t qps_destroyed;
42601+extern atomic_unchecked_t sw_qps_destroyed;
42602 extern u32 mh_detected;
42603 extern u32 mh_pauses_sent;
42604 extern u32 cm_packets_sent;
42605@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42606 extern u32 cm_packets_received;
42607 extern u32 cm_packets_dropped;
42608 extern u32 cm_packets_retrans;
42609-extern atomic_t cm_listens_created;
42610-extern atomic_t cm_listens_destroyed;
42611+extern atomic_unchecked_t cm_listens_created;
42612+extern atomic_unchecked_t cm_listens_destroyed;
42613 extern u32 cm_backlog_drops;
42614-extern atomic_t cm_loopbacks;
42615-extern atomic_t cm_nodes_created;
42616-extern atomic_t cm_nodes_destroyed;
42617-extern atomic_t cm_accel_dropped_pkts;
42618-extern atomic_t cm_resets_recvd;
42619-extern atomic_t pau_qps_created;
42620-extern atomic_t pau_qps_destroyed;
42621+extern atomic_unchecked_t cm_loopbacks;
42622+extern atomic_unchecked_t cm_nodes_created;
42623+extern atomic_unchecked_t cm_nodes_destroyed;
42624+extern atomic_unchecked_t cm_accel_dropped_pkts;
42625+extern atomic_unchecked_t cm_resets_recvd;
42626+extern atomic_unchecked_t pau_qps_created;
42627+extern atomic_unchecked_t pau_qps_destroyed;
42628
42629 extern u32 int_mod_timer_init;
42630 extern u32 int_mod_cq_depth_256;
42631diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42632index dfa9df4..6bf7221 100644
42633--- a/drivers/infiniband/hw/nes/nes_cm.c
42634+++ b/drivers/infiniband/hw/nes/nes_cm.c
42635@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42636 u32 cm_packets_retrans;
42637 u32 cm_packets_created;
42638 u32 cm_packets_received;
42639-atomic_t cm_listens_created;
42640-atomic_t cm_listens_destroyed;
42641+atomic_unchecked_t cm_listens_created;
42642+atomic_unchecked_t cm_listens_destroyed;
42643 u32 cm_backlog_drops;
42644-atomic_t cm_loopbacks;
42645-atomic_t cm_nodes_created;
42646-atomic_t cm_nodes_destroyed;
42647-atomic_t cm_accel_dropped_pkts;
42648-atomic_t cm_resets_recvd;
42649+atomic_unchecked_t cm_loopbacks;
42650+atomic_unchecked_t cm_nodes_created;
42651+atomic_unchecked_t cm_nodes_destroyed;
42652+atomic_unchecked_t cm_accel_dropped_pkts;
42653+atomic_unchecked_t cm_resets_recvd;
42654
42655 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42656 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42657@@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42658 /* instance of function pointers for client API */
42659 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42660 static struct nes_cm_ops nes_cm_api = {
42661- mini_cm_accelerated,
42662- mini_cm_listen,
42663- mini_cm_del_listen,
42664- mini_cm_connect,
42665- mini_cm_close,
42666- mini_cm_accept,
42667- mini_cm_reject,
42668- mini_cm_recv_pkt,
42669- mini_cm_dealloc_core,
42670- mini_cm_get,
42671- mini_cm_set
42672+ .accelerated = mini_cm_accelerated,
42673+ .listen = mini_cm_listen,
42674+ .stop_listener = mini_cm_del_listen,
42675+ .connect = mini_cm_connect,
42676+ .close = mini_cm_close,
42677+ .accept = mini_cm_accept,
42678+ .reject = mini_cm_reject,
42679+ .recv_pkt = mini_cm_recv_pkt,
42680+ .destroy_cm_core = mini_cm_dealloc_core,
42681+ .get = mini_cm_get,
42682+ .set = mini_cm_set
42683 };
42684
42685 static struct nes_cm_core *g_cm_core;
42686
42687-atomic_t cm_connects;
42688-atomic_t cm_accepts;
42689-atomic_t cm_disconnects;
42690-atomic_t cm_closes;
42691-atomic_t cm_connecteds;
42692-atomic_t cm_connect_reqs;
42693-atomic_t cm_rejects;
42694+atomic_unchecked_t cm_connects;
42695+atomic_unchecked_t cm_accepts;
42696+atomic_unchecked_t cm_disconnects;
42697+atomic_unchecked_t cm_closes;
42698+atomic_unchecked_t cm_connecteds;
42699+atomic_unchecked_t cm_connect_reqs;
42700+atomic_unchecked_t cm_rejects;
42701
42702 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42703 {
42704@@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42705 kfree(listener);
42706 listener = NULL;
42707 ret = 0;
42708- atomic_inc(&cm_listens_destroyed);
42709+ atomic_inc_unchecked(&cm_listens_destroyed);
42710 } else {
42711 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42712 }
42713@@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42714 cm_node->rem_mac);
42715
42716 add_hte_node(cm_core, cm_node);
42717- atomic_inc(&cm_nodes_created);
42718+ atomic_inc_unchecked(&cm_nodes_created);
42719
42720 return cm_node;
42721 }
42722@@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42723 }
42724
42725 atomic_dec(&cm_core->node_cnt);
42726- atomic_inc(&cm_nodes_destroyed);
42727+ atomic_inc_unchecked(&cm_nodes_destroyed);
42728 nesqp = cm_node->nesqp;
42729 if (nesqp) {
42730 nesqp->cm_node = NULL;
42731@@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42732
42733 static void drop_packet(struct sk_buff *skb)
42734 {
42735- atomic_inc(&cm_accel_dropped_pkts);
42736+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42737 dev_kfree_skb_any(skb);
42738 }
42739
42740@@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42741 {
42742
42743 int reset = 0; /* whether to send reset in case of err.. */
42744- atomic_inc(&cm_resets_recvd);
42745+ atomic_inc_unchecked(&cm_resets_recvd);
42746 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42747 " refcnt=%d\n", cm_node, cm_node->state,
42748 atomic_read(&cm_node->ref_count));
42749@@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42750 rem_ref_cm_node(cm_node->cm_core, cm_node);
42751 return NULL;
42752 }
42753- atomic_inc(&cm_loopbacks);
42754+ atomic_inc_unchecked(&cm_loopbacks);
42755 loopbackremotenode->loopbackpartner = cm_node;
42756 loopbackremotenode->tcp_cntxt.rcv_wscale =
42757 NES_CM_DEFAULT_RCV_WND_SCALE;
42758@@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42759 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42760 else {
42761 rem_ref_cm_node(cm_core, cm_node);
42762- atomic_inc(&cm_accel_dropped_pkts);
42763+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42764 dev_kfree_skb_any(skb);
42765 }
42766 break;
42767@@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42768
42769 if ((cm_id) && (cm_id->event_handler)) {
42770 if (issue_disconn) {
42771- atomic_inc(&cm_disconnects);
42772+ atomic_inc_unchecked(&cm_disconnects);
42773 cm_event.event = IW_CM_EVENT_DISCONNECT;
42774 cm_event.status = disconn_status;
42775 cm_event.local_addr = cm_id->local_addr;
42776@@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42777 }
42778
42779 if (issue_close) {
42780- atomic_inc(&cm_closes);
42781+ atomic_inc_unchecked(&cm_closes);
42782 nes_disconnect(nesqp, 1);
42783
42784 cm_id->provider_data = nesqp;
42785@@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42786
42787 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42788 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42789- atomic_inc(&cm_accepts);
42790+ atomic_inc_unchecked(&cm_accepts);
42791
42792 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42793 netdev_refcnt_read(nesvnic->netdev));
42794@@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42795 struct nes_cm_core *cm_core;
42796 u8 *start_buff;
42797
42798- atomic_inc(&cm_rejects);
42799+ atomic_inc_unchecked(&cm_rejects);
42800 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42801 loopback = cm_node->loopbackpartner;
42802 cm_core = cm_node->cm_core;
42803@@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42804 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42805 ntohs(laddr->sin_port));
42806
42807- atomic_inc(&cm_connects);
42808+ atomic_inc_unchecked(&cm_connects);
42809 nesqp->active_conn = 1;
42810
42811 /* cache the cm_id in the qp */
42812@@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42813 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42814 return err;
42815 }
42816- atomic_inc(&cm_listens_created);
42817+ atomic_inc_unchecked(&cm_listens_created);
42818 }
42819
42820 cm_id->add_ref(cm_id);
42821@@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42822
42823 if (nesqp->destroyed)
42824 return;
42825- atomic_inc(&cm_connecteds);
42826+ atomic_inc_unchecked(&cm_connecteds);
42827 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42828 " local port 0x%04X. jiffies = %lu.\n",
42829 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42830@@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42831
42832 cm_id->add_ref(cm_id);
42833 ret = cm_id->event_handler(cm_id, &cm_event);
42834- atomic_inc(&cm_closes);
42835+ atomic_inc_unchecked(&cm_closes);
42836 cm_event.event = IW_CM_EVENT_CLOSE;
42837 cm_event.status = 0;
42838 cm_event.provider_data = cm_id->provider_data;
42839@@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42840 return;
42841 cm_id = cm_node->cm_id;
42842
42843- atomic_inc(&cm_connect_reqs);
42844+ atomic_inc_unchecked(&cm_connect_reqs);
42845 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42846 cm_node, cm_id, jiffies);
42847
42848@@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42849 return;
42850 cm_id = cm_node->cm_id;
42851
42852- atomic_inc(&cm_connect_reqs);
42853+ atomic_inc_unchecked(&cm_connect_reqs);
42854 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42855 cm_node, cm_id, jiffies);
42856
42857diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42858index 4166452..fc952c3 100644
42859--- a/drivers/infiniband/hw/nes/nes_mgt.c
42860+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42861@@ -40,8 +40,8 @@
42862 #include "nes.h"
42863 #include "nes_mgt.h"
42864
42865-atomic_t pau_qps_created;
42866-atomic_t pau_qps_destroyed;
42867+atomic_unchecked_t pau_qps_created;
42868+atomic_unchecked_t pau_qps_destroyed;
42869
42870 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42871 {
42872@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42873 {
42874 struct sk_buff *skb;
42875 unsigned long flags;
42876- atomic_inc(&pau_qps_destroyed);
42877+ atomic_inc_unchecked(&pau_qps_destroyed);
42878
42879 /* Free packets that have not yet been forwarded */
42880 /* Lock is acquired by skb_dequeue when removing the skb */
42881@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42882 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42883 skb_queue_head_init(&nesqp->pau_list);
42884 spin_lock_init(&nesqp->pau_lock);
42885- atomic_inc(&pau_qps_created);
42886+ atomic_inc_unchecked(&pau_qps_created);
42887 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42888 }
42889
42890diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42891index 49eb511..a774366 100644
42892--- a/drivers/infiniband/hw/nes/nes_nic.c
42893+++ b/drivers/infiniband/hw/nes/nes_nic.c
42894@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42895 target_stat_values[++index] = mh_detected;
42896 target_stat_values[++index] = mh_pauses_sent;
42897 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42898- target_stat_values[++index] = atomic_read(&cm_connects);
42899- target_stat_values[++index] = atomic_read(&cm_accepts);
42900- target_stat_values[++index] = atomic_read(&cm_disconnects);
42901- target_stat_values[++index] = atomic_read(&cm_connecteds);
42902- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42903- target_stat_values[++index] = atomic_read(&cm_rejects);
42904- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42905- target_stat_values[++index] = atomic_read(&qps_created);
42906- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42907- target_stat_values[++index] = atomic_read(&qps_destroyed);
42908- target_stat_values[++index] = atomic_read(&cm_closes);
42909+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42910+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42911+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42912+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42913+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42914+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42915+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42916+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42917+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42918+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42919+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42920 target_stat_values[++index] = cm_packets_sent;
42921 target_stat_values[++index] = cm_packets_bounced;
42922 target_stat_values[++index] = cm_packets_created;
42923 target_stat_values[++index] = cm_packets_received;
42924 target_stat_values[++index] = cm_packets_dropped;
42925 target_stat_values[++index] = cm_packets_retrans;
42926- target_stat_values[++index] = atomic_read(&cm_listens_created);
42927- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42928+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42929+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42930 target_stat_values[++index] = cm_backlog_drops;
42931- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42932- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42933- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42934- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42935- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42936+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42937+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42938+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42939+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42940+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42941 target_stat_values[++index] = nesadapter->free_4kpbl;
42942 target_stat_values[++index] = nesadapter->free_256pbl;
42943 target_stat_values[++index] = int_mod_timer_init;
42944 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42945 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42946 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42947- target_stat_values[++index] = atomic_read(&pau_qps_created);
42948- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42949+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42950+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42951 }
42952
42953 /**
42954diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42955index 218dd35..97ce31d 100644
42956--- a/drivers/infiniband/hw/nes/nes_verbs.c
42957+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42958@@ -46,9 +46,9 @@
42959
42960 #include <rdma/ib_umem.h>
42961
42962-atomic_t mod_qp_timouts;
42963-atomic_t qps_created;
42964-atomic_t sw_qps_destroyed;
42965+atomic_unchecked_t mod_qp_timouts;
42966+atomic_unchecked_t qps_created;
42967+atomic_unchecked_t sw_qps_destroyed;
42968
42969 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42970
42971@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42972 if (init_attr->create_flags)
42973 return ERR_PTR(-EINVAL);
42974
42975- atomic_inc(&qps_created);
42976+ atomic_inc_unchecked(&qps_created);
42977 switch (init_attr->qp_type) {
42978 case IB_QPT_RC:
42979 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42980@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42981 struct iw_cm_event cm_event;
42982 int ret = 0;
42983
42984- atomic_inc(&sw_qps_destroyed);
42985+ atomic_inc_unchecked(&sw_qps_destroyed);
42986 nesqp->destroyed = 1;
42987
42988 /* Blow away the connection if it exists. */
42989diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42990index c00ae09..04e91be 100644
42991--- a/drivers/infiniband/hw/qib/qib.h
42992+++ b/drivers/infiniband/hw/qib/qib.h
42993@@ -52,6 +52,7 @@
42994 #include <linux/kref.h>
42995 #include <linux/sched.h>
42996 #include <linux/kthread.h>
42997+#include <linux/slab.h>
42998
42999 #include "qib_common.h"
43000 #include "qib_verbs.h"
43001diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43002index 24c41ba..102d71f 100644
43003--- a/drivers/input/gameport/gameport.c
43004+++ b/drivers/input/gameport/gameport.c
43005@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43006 */
43007 static void gameport_init_port(struct gameport *gameport)
43008 {
43009- static atomic_t gameport_no = ATOMIC_INIT(0);
43010+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43011
43012 __module_get(THIS_MODULE);
43013
43014 mutex_init(&gameport->drv_mutex);
43015 device_initialize(&gameport->dev);
43016 dev_set_name(&gameport->dev, "gameport%lu",
43017- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43018+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43019 gameport->dev.bus = &gameport_bus;
43020 gameport->dev.release = gameport_release_port;
43021 if (gameport->parent)
43022diff --git a/drivers/input/input.c b/drivers/input/input.c
43023index 29ca0bb..f4bc2e3 100644
43024--- a/drivers/input/input.c
43025+++ b/drivers/input/input.c
43026@@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
43027 */
43028 struct input_dev *input_allocate_device(void)
43029 {
43030- static atomic_t input_no = ATOMIC_INIT(0);
43031+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43032 struct input_dev *dev;
43033
43034 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43035@@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
43036 INIT_LIST_HEAD(&dev->node);
43037
43038 dev_set_name(&dev->dev, "input%ld",
43039- (unsigned long) atomic_inc_return(&input_no) - 1);
43040+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43041
43042 __module_get(THIS_MODULE);
43043 }
43044diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43045index 4a95b22..874c182 100644
43046--- a/drivers/input/joystick/sidewinder.c
43047+++ b/drivers/input/joystick/sidewinder.c
43048@@ -30,6 +30,7 @@
43049 #include <linux/kernel.h>
43050 #include <linux/module.h>
43051 #include <linux/slab.h>
43052+#include <linux/sched.h>
43053 #include <linux/input.h>
43054 #include <linux/gameport.h>
43055 #include <linux/jiffies.h>
43056diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43057index 603fe0d..f63decc 100644
43058--- a/drivers/input/joystick/xpad.c
43059+++ b/drivers/input/joystick/xpad.c
43060@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43061
43062 static int xpad_led_probe(struct usb_xpad *xpad)
43063 {
43064- static atomic_t led_seq = ATOMIC_INIT(0);
43065+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43066 long led_no;
43067 struct xpad_led *led;
43068 struct led_classdev *led_cdev;
43069@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43070 if (!led)
43071 return -ENOMEM;
43072
43073- led_no = (long)atomic_inc_return(&led_seq) - 1;
43074+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43075
43076 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43077 led->xpad = xpad;
43078diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43079index 5a73639..d586683 100644
43080--- a/drivers/input/misc/ims-pcu.c
43081+++ b/drivers/input/misc/ims-pcu.c
43082@@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43083
43084 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43085 {
43086- static atomic_t device_no = ATOMIC_INIT(0);
43087+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43088
43089 const struct ims_pcu_device_info *info;
43090 int error;
43091@@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43092 }
43093
43094 /* Device appears to be operable, complete initialization */
43095- pcu->device_no = atomic_inc_return(&device_no) - 1;
43096+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43097
43098 /*
43099 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43100diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43101index 2f0b39d..7370f13 100644
43102--- a/drivers/input/mouse/psmouse.h
43103+++ b/drivers/input/mouse/psmouse.h
43104@@ -116,7 +116,7 @@ struct psmouse_attribute {
43105 ssize_t (*set)(struct psmouse *psmouse, void *data,
43106 const char *buf, size_t count);
43107 bool protect;
43108-};
43109+} __do_const;
43110 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43111
43112 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43113diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43114index b604564..3f14ae4 100644
43115--- a/drivers/input/mousedev.c
43116+++ b/drivers/input/mousedev.c
43117@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43118
43119 spin_unlock_irq(&client->packet_lock);
43120
43121- if (copy_to_user(buffer, data, count))
43122+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43123 return -EFAULT;
43124
43125 return count;
43126diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43127index b29134d..394deb0 100644
43128--- a/drivers/input/serio/serio.c
43129+++ b/drivers/input/serio/serio.c
43130@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43131 */
43132 static void serio_init_port(struct serio *serio)
43133 {
43134- static atomic_t serio_no = ATOMIC_INIT(0);
43135+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43136
43137 __module_get(THIS_MODULE);
43138
43139@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43140 mutex_init(&serio->drv_mutex);
43141 device_initialize(&serio->dev);
43142 dev_set_name(&serio->dev, "serio%ld",
43143- (long)atomic_inc_return(&serio_no) - 1);
43144+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
43145 serio->dev.bus = &serio_bus;
43146 serio->dev.release = serio_release_port;
43147 serio->dev.groups = serio_device_attr_groups;
43148diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43149index c9a02fe..0debc75 100644
43150--- a/drivers/input/serio/serio_raw.c
43151+++ b/drivers/input/serio/serio_raw.c
43152@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43153
43154 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43155 {
43156- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43157+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43158 struct serio_raw *serio_raw;
43159 int err;
43160
43161@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43162 }
43163
43164 snprintf(serio_raw->name, sizeof(serio_raw->name),
43165- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43166+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43167 kref_init(&serio_raw->kref);
43168 INIT_LIST_HEAD(&serio_raw->client_list);
43169 init_waitqueue_head(&serio_raw->wait);
43170diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43171index e5555fc..937986d 100644
43172--- a/drivers/iommu/iommu.c
43173+++ b/drivers/iommu/iommu.c
43174@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43175 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43176 {
43177 bus_register_notifier(bus, &iommu_bus_nb);
43178- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43179+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43180 }
43181
43182 /**
43183diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43184index 228632c9..edfe331 100644
43185--- a/drivers/iommu/irq_remapping.c
43186+++ b/drivers/iommu/irq_remapping.c
43187@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43188 void panic_if_irq_remap(const char *msg)
43189 {
43190 if (irq_remapping_enabled)
43191- panic(msg);
43192+ panic("%s", msg);
43193 }
43194
43195 static void ir_ack_apic_edge(struct irq_data *data)
43196@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43197
43198 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43199 {
43200- chip->irq_print_chip = ir_print_prefix;
43201- chip->irq_ack = ir_ack_apic_edge;
43202- chip->irq_eoi = ir_ack_apic_level;
43203- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43204+ pax_open_kernel();
43205+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43206+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43207+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43208+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43209+ pax_close_kernel();
43210 }
43211
43212 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43213diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43214index 739ca67..42ee3f1 100644
43215--- a/drivers/irqchip/irq-gic.c
43216+++ b/drivers/irqchip/irq-gic.c
43217@@ -85,7 +85,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43218 * Supported arch specific GIC irq extension.
43219 * Default make them NULL.
43220 */
43221-struct irq_chip gic_arch_extn = {
43222+irq_chip_no_const gic_arch_extn = {
43223 .irq_eoi = NULL,
43224 .irq_mask = NULL,
43225 .irq_unmask = NULL,
43226@@ -337,7 +337,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43227 chained_irq_exit(chip, desc);
43228 }
43229
43230-static struct irq_chip gic_chip = {
43231+static irq_chip_no_const gic_chip __read_only = {
43232 .name = "GIC",
43233 .irq_mask = gic_mask_irq,
43234 .irq_unmask = gic_unmask_irq,
43235diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43236index 8777065..a4a9967 100644
43237--- a/drivers/irqchip/irq-renesas-irqc.c
43238+++ b/drivers/irqchip/irq-renesas-irqc.c
43239@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43240 struct irqc_priv *p;
43241 struct resource *io;
43242 struct resource *irq;
43243- struct irq_chip *irq_chip;
43244+ irq_chip_no_const *irq_chip;
43245 const char *name = dev_name(&pdev->dev);
43246 int ret;
43247 int k;
43248diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43249index ac6f72b..81150f2 100644
43250--- a/drivers/isdn/capi/capi.c
43251+++ b/drivers/isdn/capi/capi.c
43252@@ -81,8 +81,8 @@ struct capiminor {
43253
43254 struct capi20_appl *ap;
43255 u32 ncci;
43256- atomic_t datahandle;
43257- atomic_t msgid;
43258+ atomic_unchecked_t datahandle;
43259+ atomic_unchecked_t msgid;
43260
43261 struct tty_port port;
43262 int ttyinstop;
43263@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43264 capimsg_setu16(s, 2, mp->ap->applid);
43265 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43266 capimsg_setu8 (s, 5, CAPI_RESP);
43267- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43268+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43269 capimsg_setu32(s, 8, mp->ncci);
43270 capimsg_setu16(s, 12, datahandle);
43271 }
43272@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43273 mp->outbytes -= len;
43274 spin_unlock_bh(&mp->outlock);
43275
43276- datahandle = atomic_inc_return(&mp->datahandle);
43277+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43278 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43279 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43280 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43281 capimsg_setu16(skb->data, 2, mp->ap->applid);
43282 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43283 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43284- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43285+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43286 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43287 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43288 capimsg_setu16(skb->data, 16, len); /* Data length */
43289diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43290index c44950d..10ac276 100644
43291--- a/drivers/isdn/gigaset/bas-gigaset.c
43292+++ b/drivers/isdn/gigaset/bas-gigaset.c
43293@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43294
43295
43296 static const struct gigaset_ops gigops = {
43297- gigaset_write_cmd,
43298- gigaset_write_room,
43299- gigaset_chars_in_buffer,
43300- gigaset_brkchars,
43301- gigaset_init_bchannel,
43302- gigaset_close_bchannel,
43303- gigaset_initbcshw,
43304- gigaset_freebcshw,
43305- gigaset_reinitbcshw,
43306- gigaset_initcshw,
43307- gigaset_freecshw,
43308- gigaset_set_modem_ctrl,
43309- gigaset_baud_rate,
43310- gigaset_set_line_ctrl,
43311- gigaset_isoc_send_skb,
43312- gigaset_isoc_input,
43313+ .write_cmd = gigaset_write_cmd,
43314+ .write_room = gigaset_write_room,
43315+ .chars_in_buffer = gigaset_chars_in_buffer,
43316+ .brkchars = gigaset_brkchars,
43317+ .init_bchannel = gigaset_init_bchannel,
43318+ .close_bchannel = gigaset_close_bchannel,
43319+ .initbcshw = gigaset_initbcshw,
43320+ .freebcshw = gigaset_freebcshw,
43321+ .reinitbcshw = gigaset_reinitbcshw,
43322+ .initcshw = gigaset_initcshw,
43323+ .freecshw = gigaset_freecshw,
43324+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43325+ .baud_rate = gigaset_baud_rate,
43326+ .set_line_ctrl = gigaset_set_line_ctrl,
43327+ .send_skb = gigaset_isoc_send_skb,
43328+ .handle_input = gigaset_isoc_input,
43329 };
43330
43331 /* bas_gigaset_init
43332diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43333index 600c79b..3752bab 100644
43334--- a/drivers/isdn/gigaset/interface.c
43335+++ b/drivers/isdn/gigaset/interface.c
43336@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43337 }
43338 tty->driver_data = cs;
43339
43340- ++cs->port.count;
43341+ atomic_inc(&cs->port.count);
43342
43343- if (cs->port.count == 1) {
43344+ if (atomic_read(&cs->port.count) == 1) {
43345 tty_port_tty_set(&cs->port, tty);
43346 cs->port.low_latency = 1;
43347 }
43348@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43349
43350 if (!cs->connected)
43351 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43352- else if (!cs->port.count)
43353+ else if (!atomic_read(&cs->port.count))
43354 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43355- else if (!--cs->port.count)
43356+ else if (!atomic_dec_return(&cs->port.count))
43357 tty_port_tty_set(&cs->port, NULL);
43358
43359 mutex_unlock(&cs->mutex);
43360diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43361index 8c91fd5..14f13ce 100644
43362--- a/drivers/isdn/gigaset/ser-gigaset.c
43363+++ b/drivers/isdn/gigaset/ser-gigaset.c
43364@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43365 }
43366
43367 static const struct gigaset_ops ops = {
43368- gigaset_write_cmd,
43369- gigaset_write_room,
43370- gigaset_chars_in_buffer,
43371- gigaset_brkchars,
43372- gigaset_init_bchannel,
43373- gigaset_close_bchannel,
43374- gigaset_initbcshw,
43375- gigaset_freebcshw,
43376- gigaset_reinitbcshw,
43377- gigaset_initcshw,
43378- gigaset_freecshw,
43379- gigaset_set_modem_ctrl,
43380- gigaset_baud_rate,
43381- gigaset_set_line_ctrl,
43382- gigaset_m10x_send_skb, /* asyncdata.c */
43383- gigaset_m10x_input, /* asyncdata.c */
43384+ .write_cmd = gigaset_write_cmd,
43385+ .write_room = gigaset_write_room,
43386+ .chars_in_buffer = gigaset_chars_in_buffer,
43387+ .brkchars = gigaset_brkchars,
43388+ .init_bchannel = gigaset_init_bchannel,
43389+ .close_bchannel = gigaset_close_bchannel,
43390+ .initbcshw = gigaset_initbcshw,
43391+ .freebcshw = gigaset_freebcshw,
43392+ .reinitbcshw = gigaset_reinitbcshw,
43393+ .initcshw = gigaset_initcshw,
43394+ .freecshw = gigaset_freecshw,
43395+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43396+ .baud_rate = gigaset_baud_rate,
43397+ .set_line_ctrl = gigaset_set_line_ctrl,
43398+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43399+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43400 };
43401
43402
43403diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43404index d0a41cb..b953e50 100644
43405--- a/drivers/isdn/gigaset/usb-gigaset.c
43406+++ b/drivers/isdn/gigaset/usb-gigaset.c
43407@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43408 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43409 memcpy(cs->hw.usb->bchars, buf, 6);
43410 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43411- 0, 0, &buf, 6, 2000);
43412+ 0, 0, buf, 6, 2000);
43413 }
43414
43415 static void gigaset_freebcshw(struct bc_state *bcs)
43416@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43417 }
43418
43419 static const struct gigaset_ops ops = {
43420- gigaset_write_cmd,
43421- gigaset_write_room,
43422- gigaset_chars_in_buffer,
43423- gigaset_brkchars,
43424- gigaset_init_bchannel,
43425- gigaset_close_bchannel,
43426- gigaset_initbcshw,
43427- gigaset_freebcshw,
43428- gigaset_reinitbcshw,
43429- gigaset_initcshw,
43430- gigaset_freecshw,
43431- gigaset_set_modem_ctrl,
43432- gigaset_baud_rate,
43433- gigaset_set_line_ctrl,
43434- gigaset_m10x_send_skb,
43435- gigaset_m10x_input,
43436+ .write_cmd = gigaset_write_cmd,
43437+ .write_room = gigaset_write_room,
43438+ .chars_in_buffer = gigaset_chars_in_buffer,
43439+ .brkchars = gigaset_brkchars,
43440+ .init_bchannel = gigaset_init_bchannel,
43441+ .close_bchannel = gigaset_close_bchannel,
43442+ .initbcshw = gigaset_initbcshw,
43443+ .freebcshw = gigaset_freebcshw,
43444+ .reinitbcshw = gigaset_reinitbcshw,
43445+ .initcshw = gigaset_initcshw,
43446+ .freecshw = gigaset_freecshw,
43447+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43448+ .baud_rate = gigaset_baud_rate,
43449+ .set_line_ctrl = gigaset_set_line_ctrl,
43450+ .send_skb = gigaset_m10x_send_skb,
43451+ .handle_input = gigaset_m10x_input,
43452 };
43453
43454 /*
43455diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43456index 4d9b195..455075c 100644
43457--- a/drivers/isdn/hardware/avm/b1.c
43458+++ b/drivers/isdn/hardware/avm/b1.c
43459@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43460 }
43461 if (left) {
43462 if (t4file->user) {
43463- if (copy_from_user(buf, dp, left))
43464+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43465 return -EFAULT;
43466 } else {
43467 memcpy(buf, dp, left);
43468@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43469 }
43470 if (left) {
43471 if (config->user) {
43472- if (copy_from_user(buf, dp, left))
43473+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43474 return -EFAULT;
43475 } else {
43476 memcpy(buf, dp, left);
43477diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43478index 9b856e1..fa03c92 100644
43479--- a/drivers/isdn/i4l/isdn_common.c
43480+++ b/drivers/isdn/i4l/isdn_common.c
43481@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43482 } else
43483 return -EINVAL;
43484 case IIOCDBGVAR:
43485+ if (!capable(CAP_SYS_RAWIO))
43486+ return -EPERM;
43487 if (arg) {
43488 if (copy_to_user(argp, &dev, sizeof(ulong)))
43489 return -EFAULT;
43490diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43491index 91d5730..336523e 100644
43492--- a/drivers/isdn/i4l/isdn_concap.c
43493+++ b/drivers/isdn/i4l/isdn_concap.c
43494@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43495 }
43496
43497 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43498- &isdn_concap_dl_data_req,
43499- &isdn_concap_dl_connect_req,
43500- &isdn_concap_dl_disconn_req
43501+ .data_req = &isdn_concap_dl_data_req,
43502+ .connect_req = &isdn_concap_dl_connect_req,
43503+ .disconn_req = &isdn_concap_dl_disconn_req
43504 };
43505
43506 /* The following should better go into a dedicated source file such that
43507diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43508index 3c5f249..5fac4d0 100644
43509--- a/drivers/isdn/i4l/isdn_tty.c
43510+++ b/drivers/isdn/i4l/isdn_tty.c
43511@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43512
43513 #ifdef ISDN_DEBUG_MODEM_OPEN
43514 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43515- port->count);
43516+ atomic_read(&port->count));
43517 #endif
43518- port->count++;
43519+ atomic_inc(&port->count);
43520 port->tty = tty;
43521 /*
43522 * Start up serial port
43523@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43524 #endif
43525 return;
43526 }
43527- if ((tty->count == 1) && (port->count != 1)) {
43528+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43529 /*
43530 * Uh, oh. tty->count is 1, which means that the tty
43531 * structure will be freed. Info->count should always
43532@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43533 * serial port won't be shutdown.
43534 */
43535 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43536- "info->count is %d\n", port->count);
43537- port->count = 1;
43538+ "info->count is %d\n", atomic_read(&port->count));
43539+ atomic_set(&port->count, 1);
43540 }
43541- if (--port->count < 0) {
43542+ if (atomic_dec_return(&port->count) < 0) {
43543 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43544- info->line, port->count);
43545- port->count = 0;
43546+ info->line, atomic_read(&port->count));
43547+ atomic_set(&port->count, 0);
43548 }
43549- if (port->count) {
43550+ if (atomic_read(&port->count)) {
43551 #ifdef ISDN_DEBUG_MODEM_OPEN
43552 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43553 #endif
43554@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43555 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43556 return;
43557 isdn_tty_shutdown(info);
43558- port->count = 0;
43559+ atomic_set(&port->count, 0);
43560 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43561 port->tty = NULL;
43562 wake_up_interruptible(&port->open_wait);
43563@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43564 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43565 modem_info *info = &dev->mdm.info[i];
43566
43567- if (info->port.count == 0)
43568+ if (atomic_read(&info->port.count) == 0)
43569 continue;
43570 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43571 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43572diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43573index e2d4e58..40cd045 100644
43574--- a/drivers/isdn/i4l/isdn_x25iface.c
43575+++ b/drivers/isdn/i4l/isdn_x25iface.c
43576@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43577
43578
43579 static struct concap_proto_ops ix25_pops = {
43580- &isdn_x25iface_proto_new,
43581- &isdn_x25iface_proto_del,
43582- &isdn_x25iface_proto_restart,
43583- &isdn_x25iface_proto_close,
43584- &isdn_x25iface_xmit,
43585- &isdn_x25iface_receive,
43586- &isdn_x25iface_connect_ind,
43587- &isdn_x25iface_disconn_ind
43588+ .proto_new = &isdn_x25iface_proto_new,
43589+ .proto_del = &isdn_x25iface_proto_del,
43590+ .restart = &isdn_x25iface_proto_restart,
43591+ .close = &isdn_x25iface_proto_close,
43592+ .encap_and_xmit = &isdn_x25iface_xmit,
43593+ .data_ind = &isdn_x25iface_receive,
43594+ .connect_ind = &isdn_x25iface_connect_ind,
43595+ .disconn_ind = &isdn_x25iface_disconn_ind
43596 };
43597
43598 /* error message helper function */
43599diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43600index 6a7447c..cae33fe 100644
43601--- a/drivers/isdn/icn/icn.c
43602+++ b/drivers/isdn/icn/icn.c
43603@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43604 if (count > len)
43605 count = len;
43606 if (user) {
43607- if (copy_from_user(msg, buf, count))
43608+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43609 return -EFAULT;
43610 } else
43611 memcpy(msg, buf, count);
43612diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43613index a4f05c5..1433bc5 100644
43614--- a/drivers/isdn/mISDN/dsp_cmx.c
43615+++ b/drivers/isdn/mISDN/dsp_cmx.c
43616@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43617 static u16 dsp_count; /* last sample count */
43618 static int dsp_count_valid; /* if we have last sample count */
43619
43620-void
43621+void __intentional_overflow(-1)
43622 dsp_cmx_send(void *arg)
43623 {
43624 struct dsp_conf *conf;
43625diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43626index f58a354..fbae176 100644
43627--- a/drivers/leds/leds-clevo-mail.c
43628+++ b/drivers/leds/leds-clevo-mail.c
43629@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43630 * detected as working, but in reality it is not) as low as
43631 * possible.
43632 */
43633-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43634+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43635 {
43636 .callback = clevo_mail_led_dmi_callback,
43637 .ident = "Clevo D410J",
43638diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43639index 2eb3ef6..295891f 100644
43640--- a/drivers/leds/leds-ss4200.c
43641+++ b/drivers/leds/leds-ss4200.c
43642@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43643 * detected as working, but in reality it is not) as low as
43644 * possible.
43645 */
43646-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43647+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43648 {
43649 .callback = ss4200_led_dmi_callback,
43650 .ident = "Intel SS4200-E",
43651diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43652index 0bf1e4e..b4bf44e 100644
43653--- a/drivers/lguest/core.c
43654+++ b/drivers/lguest/core.c
43655@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43656 * The end address needs +1 because __get_vm_area allocates an
43657 * extra guard page, so we need space for that.
43658 */
43659+
43660+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43661+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43662+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43663+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43664+#else
43665 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43666 VM_ALLOC, switcher_addr, switcher_addr
43667 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43668+#endif
43669+
43670 if (!switcher_vma) {
43671 err = -ENOMEM;
43672 printk("lguest: could not map switcher pages high\n");
43673@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43674 * Now the Switcher is mapped at the right address, we can't fail!
43675 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43676 */
43677- memcpy(switcher_vma->addr, start_switcher_text,
43678+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43679 end_switcher_text - start_switcher_text);
43680
43681 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43682diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43683index e8b55c3..3514c37 100644
43684--- a/drivers/lguest/page_tables.c
43685+++ b/drivers/lguest/page_tables.c
43686@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43687 /*:*/
43688
43689 #ifdef CONFIG_X86_PAE
43690-static void release_pmd(pmd_t *spmd)
43691+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43692 {
43693 /* If the entry's not present, there's nothing to release. */
43694 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43695diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43696index 922a1ac..9dd0c2a 100644
43697--- a/drivers/lguest/x86/core.c
43698+++ b/drivers/lguest/x86/core.c
43699@@ -59,7 +59,7 @@ static struct {
43700 /* Offset from where switcher.S was compiled to where we've copied it */
43701 static unsigned long switcher_offset(void)
43702 {
43703- return switcher_addr - (unsigned long)start_switcher_text;
43704+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43705 }
43706
43707 /* This cpu's struct lguest_pages (after the Switcher text page) */
43708@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43709 * These copies are pretty cheap, so we do them unconditionally: */
43710 /* Save the current Host top-level page directory.
43711 */
43712+
43713+#ifdef CONFIG_PAX_PER_CPU_PGD
43714+ pages->state.host_cr3 = read_cr3();
43715+#else
43716 pages->state.host_cr3 = __pa(current->mm->pgd);
43717+#endif
43718+
43719 /*
43720 * Set up the Guest's page tables to see this CPU's pages (and no
43721 * other CPU's pages).
43722@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43723 * compiled-in switcher code and the high-mapped copy we just made.
43724 */
43725 for (i = 0; i < IDT_ENTRIES; i++)
43726- default_idt_entries[i] += switcher_offset();
43727+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43728
43729 /*
43730 * Set up the Switcher's per-cpu areas.
43731@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43732 * it will be undisturbed when we switch. To change %cs and jump we
43733 * need this structure to feed to Intel's "lcall" instruction.
43734 */
43735- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43736+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43737 lguest_entry.segment = LGUEST_CS;
43738
43739 /*
43740diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43741index 40634b0..4f5855e 100644
43742--- a/drivers/lguest/x86/switcher_32.S
43743+++ b/drivers/lguest/x86/switcher_32.S
43744@@ -87,6 +87,7 @@
43745 #include <asm/page.h>
43746 #include <asm/segment.h>
43747 #include <asm/lguest.h>
43748+#include <asm/processor-flags.h>
43749
43750 // We mark the start of the code to copy
43751 // It's placed in .text tho it's never run here
43752@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43753 // Changes type when we load it: damn Intel!
43754 // For after we switch over our page tables
43755 // That entry will be read-only: we'd crash.
43756+
43757+#ifdef CONFIG_PAX_KERNEXEC
43758+ mov %cr0, %edx
43759+ xor $X86_CR0_WP, %edx
43760+ mov %edx, %cr0
43761+#endif
43762+
43763 movl $(GDT_ENTRY_TSS*8), %edx
43764 ltr %dx
43765
43766@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43767 // Let's clear it again for our return.
43768 // The GDT descriptor of the Host
43769 // Points to the table after two "size" bytes
43770- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43771+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43772 // Clear "used" from type field (byte 5, bit 2)
43773- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43774+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43775+
43776+#ifdef CONFIG_PAX_KERNEXEC
43777+ mov %cr0, %eax
43778+ xor $X86_CR0_WP, %eax
43779+ mov %eax, %cr0
43780+#endif
43781
43782 // Once our page table's switched, the Guest is live!
43783 // The Host fades as we run this final step.
43784@@ -295,13 +309,12 @@ deliver_to_host:
43785 // I consulted gcc, and it gave
43786 // These instructions, which I gladly credit:
43787 leal (%edx,%ebx,8), %eax
43788- movzwl (%eax),%edx
43789- movl 4(%eax), %eax
43790- xorw %ax, %ax
43791- orl %eax, %edx
43792+ movl 4(%eax), %edx
43793+ movw (%eax), %dx
43794 // Now the address of the handler's in %edx
43795 // We call it now: its "iret" drops us home.
43796- jmp *%edx
43797+ ljmp $__KERNEL_CS, $1f
43798+1: jmp *%edx
43799
43800 // Every interrupt can come to us here
43801 // But we must truly tell each apart.
43802diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43803index 7ef7461..5a09dac 100644
43804--- a/drivers/md/bcache/closure.h
43805+++ b/drivers/md/bcache/closure.h
43806@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43807 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43808 struct workqueue_struct *wq)
43809 {
43810- BUG_ON(object_is_on_stack(cl));
43811+ BUG_ON(object_starts_on_stack(cl));
43812 closure_set_ip(cl);
43813 cl->fn = fn;
43814 cl->wq = wq;
43815diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43816index 9a8e66a..10cc762 100644
43817--- a/drivers/md/bitmap.c
43818+++ b/drivers/md/bitmap.c
43819@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43820 chunk_kb ? "KB" : "B");
43821 if (bitmap->storage.file) {
43822 seq_printf(seq, ", file: ");
43823- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43824+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43825 }
43826
43827 seq_printf(seq, "\n");
43828diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43829index 5152142..623d141 100644
43830--- a/drivers/md/dm-ioctl.c
43831+++ b/drivers/md/dm-ioctl.c
43832@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43833 cmd == DM_LIST_VERSIONS_CMD)
43834 return 0;
43835
43836- if ((cmd == DM_DEV_CREATE_CMD)) {
43837+ if (cmd == DM_DEV_CREATE_CMD) {
43838 if (!*param->name) {
43839 DMWARN("name not supplied when creating device");
43840 return -EINVAL;
43841diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43842index 7dfdb5c..4caada6 100644
43843--- a/drivers/md/dm-raid1.c
43844+++ b/drivers/md/dm-raid1.c
43845@@ -40,7 +40,7 @@ enum dm_raid1_error {
43846
43847 struct mirror {
43848 struct mirror_set *ms;
43849- atomic_t error_count;
43850+ atomic_unchecked_t error_count;
43851 unsigned long error_type;
43852 struct dm_dev *dev;
43853 sector_t offset;
43854@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43855 struct mirror *m;
43856
43857 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43858- if (!atomic_read(&m->error_count))
43859+ if (!atomic_read_unchecked(&m->error_count))
43860 return m;
43861
43862 return NULL;
43863@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43864 * simple way to tell if a device has encountered
43865 * errors.
43866 */
43867- atomic_inc(&m->error_count);
43868+ atomic_inc_unchecked(&m->error_count);
43869
43870 if (test_and_set_bit(error_type, &m->error_type))
43871 return;
43872@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43873 struct mirror *m = get_default_mirror(ms);
43874
43875 do {
43876- if (likely(!atomic_read(&m->error_count)))
43877+ if (likely(!atomic_read_unchecked(&m->error_count)))
43878 return m;
43879
43880 if (m-- == ms->mirror)
43881@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43882 {
43883 struct mirror *default_mirror = get_default_mirror(m->ms);
43884
43885- return !atomic_read(&default_mirror->error_count);
43886+ return !atomic_read_unchecked(&default_mirror->error_count);
43887 }
43888
43889 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43890@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43891 */
43892 if (likely(region_in_sync(ms, region, 1)))
43893 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43894- else if (m && atomic_read(&m->error_count))
43895+ else if (m && atomic_read_unchecked(&m->error_count))
43896 m = NULL;
43897
43898 if (likely(m))
43899@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43900 }
43901
43902 ms->mirror[mirror].ms = ms;
43903- atomic_set(&(ms->mirror[mirror].error_count), 0);
43904+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43905 ms->mirror[mirror].error_type = 0;
43906 ms->mirror[mirror].offset = offset;
43907
43908@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43909 */
43910 static char device_status_char(struct mirror *m)
43911 {
43912- if (!atomic_read(&(m->error_count)))
43913+ if (!atomic_read_unchecked(&(m->error_count)))
43914 return 'A';
43915
43916 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43917diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43918index 28a9012..9c0f6a5 100644
43919--- a/drivers/md/dm-stats.c
43920+++ b/drivers/md/dm-stats.c
43921@@ -382,7 +382,7 @@ do_sync_free:
43922 synchronize_rcu_expedited();
43923 dm_stat_free(&s->rcu_head);
43924 } else {
43925- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43926+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43927 call_rcu(&s->rcu_head, dm_stat_free);
43928 }
43929 return 0;
43930@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43931 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43932 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43933 ));
43934- ACCESS_ONCE(last->last_sector) = end_sector;
43935- ACCESS_ONCE(last->last_rw) = bi_rw;
43936+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43937+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43938 }
43939
43940 rcu_read_lock();
43941diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43942index d1600d2..4c3af3a 100644
43943--- a/drivers/md/dm-stripe.c
43944+++ b/drivers/md/dm-stripe.c
43945@@ -21,7 +21,7 @@ struct stripe {
43946 struct dm_dev *dev;
43947 sector_t physical_start;
43948
43949- atomic_t error_count;
43950+ atomic_unchecked_t error_count;
43951 };
43952
43953 struct stripe_c {
43954@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43955 kfree(sc);
43956 return r;
43957 }
43958- atomic_set(&(sc->stripe[i].error_count), 0);
43959+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43960 }
43961
43962 ti->private = sc;
43963@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43964 DMEMIT("%d ", sc->stripes);
43965 for (i = 0; i < sc->stripes; i++) {
43966 DMEMIT("%s ", sc->stripe[i].dev->name);
43967- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43968+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43969 'D' : 'A';
43970 }
43971 buffer[i] = '\0';
43972@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43973 */
43974 for (i = 0; i < sc->stripes; i++)
43975 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43976- atomic_inc(&(sc->stripe[i].error_count));
43977- if (atomic_read(&(sc->stripe[i].error_count)) <
43978+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43979+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43980 DM_IO_ERROR_THRESHOLD)
43981 schedule_work(&sc->trigger_event);
43982 }
43983diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43984index 50601ec..6d3b9dc 100644
43985--- a/drivers/md/dm-table.c
43986+++ b/drivers/md/dm-table.c
43987@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43988 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43989 struct mapped_device *md)
43990 {
43991- static char *_claim_ptr = "I belong to device-mapper";
43992+ static char _claim_ptr[] = "I belong to device-mapper";
43993 struct block_device *bdev;
43994
43995 int r;
43996@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43997 if (!dev_size)
43998 return 0;
43999
44000- if ((start >= dev_size) || (start + len > dev_size)) {
44001+ if ((start >= dev_size) || (len > dev_size - start)) {
44002 DMWARN("%s: %s too small for target: "
44003 "start=%llu, len=%llu, dev_size=%llu",
44004 dm_device_name(ti->table->md), bdevname(bdev, b),
44005diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44006index e9d33ad..dae9880d 100644
44007--- a/drivers/md/dm-thin-metadata.c
44008+++ b/drivers/md/dm-thin-metadata.c
44009@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44010 {
44011 pmd->info.tm = pmd->tm;
44012 pmd->info.levels = 2;
44013- pmd->info.value_type.context = pmd->data_sm;
44014+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44015 pmd->info.value_type.size = sizeof(__le64);
44016 pmd->info.value_type.inc = data_block_inc;
44017 pmd->info.value_type.dec = data_block_dec;
44018@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44019
44020 pmd->bl_info.tm = pmd->tm;
44021 pmd->bl_info.levels = 1;
44022- pmd->bl_info.value_type.context = pmd->data_sm;
44023+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44024 pmd->bl_info.value_type.size = sizeof(__le64);
44025 pmd->bl_info.value_type.inc = data_block_inc;
44026 pmd->bl_info.value_type.dec = data_block_dec;
44027diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44028index 490ac23..b9790cd 100644
44029--- a/drivers/md/dm.c
44030+++ b/drivers/md/dm.c
44031@@ -180,9 +180,9 @@ struct mapped_device {
44032 /*
44033 * Event handling.
44034 */
44035- atomic_t event_nr;
44036+ atomic_unchecked_t event_nr;
44037 wait_queue_head_t eventq;
44038- atomic_t uevent_seq;
44039+ atomic_unchecked_t uevent_seq;
44040 struct list_head uevent_list;
44041 spinlock_t uevent_lock; /* Protect access to uevent_list */
44042
44043@@ -1895,8 +1895,8 @@ static struct mapped_device *alloc_dev(int minor)
44044 spin_lock_init(&md->deferred_lock);
44045 atomic_set(&md->holders, 1);
44046 atomic_set(&md->open_count, 0);
44047- atomic_set(&md->event_nr, 0);
44048- atomic_set(&md->uevent_seq, 0);
44049+ atomic_set_unchecked(&md->event_nr, 0);
44050+ atomic_set_unchecked(&md->uevent_seq, 0);
44051 INIT_LIST_HEAD(&md->uevent_list);
44052 spin_lock_init(&md->uevent_lock);
44053
44054@@ -2050,7 +2050,7 @@ static void event_callback(void *context)
44055
44056 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44057
44058- atomic_inc(&md->event_nr);
44059+ atomic_inc_unchecked(&md->event_nr);
44060 wake_up(&md->eventq);
44061 }
44062
44063@@ -2743,18 +2743,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44064
44065 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44066 {
44067- return atomic_add_return(1, &md->uevent_seq);
44068+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44069 }
44070
44071 uint32_t dm_get_event_nr(struct mapped_device *md)
44072 {
44073- return atomic_read(&md->event_nr);
44074+ return atomic_read_unchecked(&md->event_nr);
44075 }
44076
44077 int dm_wait_event(struct mapped_device *md, int event_nr)
44078 {
44079 return wait_event_interruptible(md->eventq,
44080- (event_nr != atomic_read(&md->event_nr)));
44081+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44082 }
44083
44084 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44085diff --git a/drivers/md/md.c b/drivers/md/md.c
44086index 9a18209..ec4d3ec 100644
44087--- a/drivers/md/md.c
44088+++ b/drivers/md/md.c
44089@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44090 * start build, activate spare
44091 */
44092 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44093-static atomic_t md_event_count;
44094+static atomic_unchecked_t md_event_count;
44095 void md_new_event(struct mddev *mddev)
44096 {
44097- atomic_inc(&md_event_count);
44098+ atomic_inc_unchecked(&md_event_count);
44099 wake_up(&md_event_waiters);
44100 }
44101 EXPORT_SYMBOL_GPL(md_new_event);
44102@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44103 */
44104 static void md_new_event_inintr(struct mddev *mddev)
44105 {
44106- atomic_inc(&md_event_count);
44107+ atomic_inc_unchecked(&md_event_count);
44108 wake_up(&md_event_waiters);
44109 }
44110
44111@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44112 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44113 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44114 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44115- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44116+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44117
44118 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44119 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44120@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44121 else
44122 sb->resync_offset = cpu_to_le64(0);
44123
44124- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44125+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44126
44127 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44128 sb->size = cpu_to_le64(mddev->dev_sectors);
44129@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44130 static ssize_t
44131 errors_show(struct md_rdev *rdev, char *page)
44132 {
44133- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44134+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44135 }
44136
44137 static ssize_t
44138@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44139 char *e;
44140 unsigned long n = simple_strtoul(buf, &e, 10);
44141 if (*buf && (*e == 0 || *e == '\n')) {
44142- atomic_set(&rdev->corrected_errors, n);
44143+ atomic_set_unchecked(&rdev->corrected_errors, n);
44144 return len;
44145 }
44146 return -EINVAL;
44147@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44148 rdev->sb_loaded = 0;
44149 rdev->bb_page = NULL;
44150 atomic_set(&rdev->nr_pending, 0);
44151- atomic_set(&rdev->read_errors, 0);
44152- atomic_set(&rdev->corrected_errors, 0);
44153+ atomic_set_unchecked(&rdev->read_errors, 0);
44154+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44155
44156 INIT_LIST_HEAD(&rdev->same_set);
44157 init_waitqueue_head(&rdev->blocked_wait);
44158@@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44159
44160 spin_unlock(&pers_lock);
44161 seq_printf(seq, "\n");
44162- seq->poll_event = atomic_read(&md_event_count);
44163+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44164 return 0;
44165 }
44166 if (v == (void*)2) {
44167@@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44168 return error;
44169
44170 seq = file->private_data;
44171- seq->poll_event = atomic_read(&md_event_count);
44172+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44173 return error;
44174 }
44175
44176@@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44177 /* always allow read */
44178 mask = POLLIN | POLLRDNORM;
44179
44180- if (seq->poll_event != atomic_read(&md_event_count))
44181+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44182 mask |= POLLERR | POLLPRI;
44183 return mask;
44184 }
44185@@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44186 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44187 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44188 (int)part_stat_read(&disk->part0, sectors[1]) -
44189- atomic_read(&disk->sync_io);
44190+ atomic_read_unchecked(&disk->sync_io);
44191 /* sync IO will cause sync_io to increase before the disk_stats
44192 * as sync_io is counted when a request starts, and
44193 * disk_stats is counted when it completes.
44194diff --git a/drivers/md/md.h b/drivers/md/md.h
44195index a49d991..3582bb7 100644
44196--- a/drivers/md/md.h
44197+++ b/drivers/md/md.h
44198@@ -94,13 +94,13 @@ struct md_rdev {
44199 * only maintained for arrays that
44200 * support hot removal
44201 */
44202- atomic_t read_errors; /* number of consecutive read errors that
44203+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44204 * we have tried to ignore.
44205 */
44206 struct timespec last_read_error; /* monotonic time since our
44207 * last read error
44208 */
44209- atomic_t corrected_errors; /* number of corrected read errors,
44210+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44211 * for reporting to userspace and storing
44212 * in superblock.
44213 */
44214@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44215
44216 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44217 {
44218- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44219+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44220 }
44221
44222 struct md_personality
44223diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44224index 786b689..ea8c956 100644
44225--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44226+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44227@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44228 * Flick into a mode where all blocks get allocated in the new area.
44229 */
44230 smm->begin = old_len;
44231- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44232+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44233
44234 /*
44235 * Extend.
44236@@ -710,7 +710,7 @@ out:
44237 /*
44238 * Switch back to normal behaviour.
44239 */
44240- memcpy(sm, &ops, sizeof(*sm));
44241+ memcpy((void *)sm, &ops, sizeof(*sm));
44242 return r;
44243 }
44244
44245diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44246index 3e6d115..ffecdeb 100644
44247--- a/drivers/md/persistent-data/dm-space-map.h
44248+++ b/drivers/md/persistent-data/dm-space-map.h
44249@@ -71,6 +71,7 @@ struct dm_space_map {
44250 dm_sm_threshold_fn fn,
44251 void *context);
44252 };
44253+typedef struct dm_space_map __no_const dm_space_map_no_const;
44254
44255 /*----------------------------------------------------------------*/
44256
44257diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44258index 56e24c0..e1c8e1f 100644
44259--- a/drivers/md/raid1.c
44260+++ b/drivers/md/raid1.c
44261@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44262 if (r1_sync_page_io(rdev, sect, s,
44263 bio->bi_io_vec[idx].bv_page,
44264 READ) != 0)
44265- atomic_add(s, &rdev->corrected_errors);
44266+ atomic_add_unchecked(s, &rdev->corrected_errors);
44267 }
44268 sectors -= s;
44269 sect += s;
44270@@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44271 test_bit(In_sync, &rdev->flags)) {
44272 if (r1_sync_page_io(rdev, sect, s,
44273 conf->tmppage, READ)) {
44274- atomic_add(s, &rdev->corrected_errors);
44275+ atomic_add_unchecked(s, &rdev->corrected_errors);
44276 printk(KERN_INFO
44277 "md/raid1:%s: read error corrected "
44278 "(%d sectors at %llu on %s)\n",
44279diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44280index cb882aa..cb8aeca 100644
44281--- a/drivers/md/raid10.c
44282+++ b/drivers/md/raid10.c
44283@@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44284 /* The write handler will notice the lack of
44285 * R10BIO_Uptodate and record any errors etc
44286 */
44287- atomic_add(r10_bio->sectors,
44288+ atomic_add_unchecked(r10_bio->sectors,
44289 &conf->mirrors[d].rdev->corrected_errors);
44290
44291 /* for reconstruct, we always reschedule after a read.
44292@@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44293 {
44294 struct timespec cur_time_mon;
44295 unsigned long hours_since_last;
44296- unsigned int read_errors = atomic_read(&rdev->read_errors);
44297+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44298
44299 ktime_get_ts(&cur_time_mon);
44300
44301@@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44302 * overflowing the shift of read_errors by hours_since_last.
44303 */
44304 if (hours_since_last >= 8 * sizeof(read_errors))
44305- atomic_set(&rdev->read_errors, 0);
44306+ atomic_set_unchecked(&rdev->read_errors, 0);
44307 else
44308- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44309+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44310 }
44311
44312 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44313@@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44314 return;
44315
44316 check_decay_read_errors(mddev, rdev);
44317- atomic_inc(&rdev->read_errors);
44318- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44319+ atomic_inc_unchecked(&rdev->read_errors);
44320+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44321 char b[BDEVNAME_SIZE];
44322 bdevname(rdev->bdev, b);
44323
44324@@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44325 "md/raid10:%s: %s: Raid device exceeded "
44326 "read_error threshold [cur %d:max %d]\n",
44327 mdname(mddev), b,
44328- atomic_read(&rdev->read_errors), max_read_errors);
44329+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44330 printk(KERN_NOTICE
44331 "md/raid10:%s: %s: Failing raid device\n",
44332 mdname(mddev), b);
44333@@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44334 sect +
44335 choose_data_offset(r10_bio, rdev)),
44336 bdevname(rdev->bdev, b));
44337- atomic_add(s, &rdev->corrected_errors);
44338+ atomic_add_unchecked(s, &rdev->corrected_errors);
44339 }
44340
44341 rdev_dec_pending(rdev, mddev);
44342@@ -2954,6 +2954,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
44343 */
44344 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
44345 end_reshape(conf);
44346+ close_sync(conf);
44347 return 0;
44348 }
44349
44350@@ -4411,7 +4412,7 @@ read_more:
44351 read_bio->bi_private = r10_bio;
44352 read_bio->bi_end_io = end_sync_read;
44353 read_bio->bi_rw = READ;
44354- read_bio->bi_flags &= ~(BIO_POOL_MASK - 1);
44355+ read_bio->bi_flags &= (~0UL << BIO_RESET_BITS);
44356 read_bio->bi_flags |= 1 << BIO_UPTODATE;
44357 read_bio->bi_vcnt = 0;
44358 read_bio->bi_iter.bi_size = 0;
44359diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44360index ad1b9be..c6316b5 100644
44361--- a/drivers/md/raid5.c
44362+++ b/drivers/md/raid5.c
44363@@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44364 return 1;
44365 }
44366
44367+#ifdef CONFIG_GRKERNSEC_HIDESYM
44368+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44369+#endif
44370+
44371 static int grow_stripes(struct r5conf *conf, int num)
44372 {
44373 struct kmem_cache *sc;
44374@@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44375 "raid%d-%s", conf->level, mdname(conf->mddev));
44376 else
44377 sprintf(conf->cache_name[0],
44378+#ifdef CONFIG_GRKERNSEC_HIDESYM
44379+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44380+#else
44381 "raid%d-%p", conf->level, conf->mddev);
44382+#endif
44383 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44384
44385 conf->active_name = 0;
44386@@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44387 mdname(conf->mddev), STRIPE_SECTORS,
44388 (unsigned long long)s,
44389 bdevname(rdev->bdev, b));
44390- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44391+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44392 clear_bit(R5_ReadError, &sh->dev[i].flags);
44393 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44394 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44395 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44396
44397- if (atomic_read(&rdev->read_errors))
44398- atomic_set(&rdev->read_errors, 0);
44399+ if (atomic_read_unchecked(&rdev->read_errors))
44400+ atomic_set_unchecked(&rdev->read_errors, 0);
44401 } else {
44402 const char *bdn = bdevname(rdev->bdev, b);
44403 int retry = 0;
44404 int set_bad = 0;
44405
44406 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44407- atomic_inc(&rdev->read_errors);
44408+ atomic_inc_unchecked(&rdev->read_errors);
44409 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44410 printk_ratelimited(
44411 KERN_WARNING
44412@@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44413 mdname(conf->mddev),
44414 (unsigned long long)s,
44415 bdn);
44416- } else if (atomic_read(&rdev->read_errors)
44417+ } else if (atomic_read_unchecked(&rdev->read_errors)
44418 > conf->max_nr_stripes)
44419 printk(KERN_WARNING
44420 "md/raid:%s: Too many read errors, failing device %s.\n",
44421@@ -3774,6 +3782,8 @@ static void handle_stripe(struct stripe_head *sh)
44422 set_bit(R5_Wantwrite, &dev->flags);
44423 if (prexor)
44424 continue;
44425+ if (s.failed > 1)
44426+ continue;
44427 if (!test_bit(R5_Insync, &dev->flags) ||
44428 ((i == sh->pd_idx || i == sh->qd_idx) &&
44429 s.failed == 0))
44430diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44431index 983db75..ef9248c 100644
44432--- a/drivers/media/dvb-core/dvbdev.c
44433+++ b/drivers/media/dvb-core/dvbdev.c
44434@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44435 const struct dvb_device *template, void *priv, int type)
44436 {
44437 struct dvb_device *dvbdev;
44438- struct file_operations *dvbdevfops;
44439+ file_operations_no_const *dvbdevfops;
44440 struct device *clsdev;
44441 int minor;
44442 int id;
44443diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44444index 539f4db..cdd403b 100644
44445--- a/drivers/media/dvb-frontends/af9033.h
44446+++ b/drivers/media/dvb-frontends/af9033.h
44447@@ -82,7 +82,7 @@ struct af9033_ops {
44448 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44449 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44450 int onoff);
44451-};
44452+} __no_const;
44453
44454
44455 #if IS_ENABLED(CONFIG_DVB_AF9033)
44456diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44457index 9b6c3bb..baeb5c7 100644
44458--- a/drivers/media/dvb-frontends/dib3000.h
44459+++ b/drivers/media/dvb-frontends/dib3000.h
44460@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44461 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44462 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44463 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44464-};
44465+} __no_const;
44466
44467 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44468 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44469diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44470index ed8cb90..5ef7f79 100644
44471--- a/drivers/media/pci/cx88/cx88-video.c
44472+++ b/drivers/media/pci/cx88/cx88-video.c
44473@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44474
44475 /* ------------------------------------------------------------------ */
44476
44477-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44478-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44479-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44480+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44481+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44482+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44483
44484 module_param_array(video_nr, int, NULL, 0444);
44485 module_param_array(vbi_nr, int, NULL, 0444);
44486diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44487index 802642d..5534900 100644
44488--- a/drivers/media/pci/ivtv/ivtv-driver.c
44489+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44490@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44491 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44492
44493 /* ivtv instance counter */
44494-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44495+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44496
44497 /* Parameter declarations */
44498 static int cardtype[IVTV_MAX_CARDS];
44499diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44500index 9a726ea..f5e9b52 100644
44501--- a/drivers/media/platform/omap/omap_vout.c
44502+++ b/drivers/media/platform/omap/omap_vout.c
44503@@ -63,7 +63,6 @@ enum omap_vout_channels {
44504 OMAP_VIDEO2,
44505 };
44506
44507-static struct videobuf_queue_ops video_vbq_ops;
44508 /* Variables configurable through module params*/
44509 static u32 video1_numbuffers = 3;
44510 static u32 video2_numbuffers = 3;
44511@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44512 {
44513 struct videobuf_queue *q;
44514 struct omap_vout_device *vout = NULL;
44515+ static struct videobuf_queue_ops video_vbq_ops = {
44516+ .buf_setup = omap_vout_buffer_setup,
44517+ .buf_prepare = omap_vout_buffer_prepare,
44518+ .buf_release = omap_vout_buffer_release,
44519+ .buf_queue = omap_vout_buffer_queue,
44520+ };
44521
44522 vout = video_drvdata(file);
44523 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44524@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44525 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44526
44527 q = &vout->vbq;
44528- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44529- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44530- video_vbq_ops.buf_release = omap_vout_buffer_release;
44531- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44532 spin_lock_init(&vout->vbq_lock);
44533
44534 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44535diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44536index fb2acc5..a2fcbdc4 100644
44537--- a/drivers/media/platform/s5p-tv/mixer.h
44538+++ b/drivers/media/platform/s5p-tv/mixer.h
44539@@ -156,7 +156,7 @@ struct mxr_layer {
44540 /** layer index (unique identifier) */
44541 int idx;
44542 /** callbacks for layer methods */
44543- struct mxr_layer_ops ops;
44544+ struct mxr_layer_ops *ops;
44545 /** format array */
44546 const struct mxr_format **fmt_array;
44547 /** size of format array */
44548diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44549index 74344c7..a39e70e 100644
44550--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44551+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44552@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44553 {
44554 struct mxr_layer *layer;
44555 int ret;
44556- struct mxr_layer_ops ops = {
44557+ static struct mxr_layer_ops ops = {
44558 .release = mxr_graph_layer_release,
44559 .buffer_set = mxr_graph_buffer_set,
44560 .stream_set = mxr_graph_stream_set,
44561diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44562index b713403..53cb5ad 100644
44563--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44564+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44565@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44566 layer->update_buf = next;
44567 }
44568
44569- layer->ops.buffer_set(layer, layer->update_buf);
44570+ layer->ops->buffer_set(layer, layer->update_buf);
44571
44572 if (done && done != layer->shadow_buf)
44573 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44574diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44575index a1ce55f..4a3c4d9 100644
44576--- a/drivers/media/platform/s5p-tv/mixer_video.c
44577+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44578@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44579 layer->geo.src.height = layer->geo.src.full_height;
44580
44581 mxr_geometry_dump(mdev, &layer->geo);
44582- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44583+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44584 mxr_geometry_dump(mdev, &layer->geo);
44585 }
44586
44587@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44588 layer->geo.dst.full_width = mbus_fmt.width;
44589 layer->geo.dst.full_height = mbus_fmt.height;
44590 layer->geo.dst.field = mbus_fmt.field;
44591- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44592+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44593
44594 mxr_geometry_dump(mdev, &layer->geo);
44595 }
44596@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44597 /* set source size to highest accepted value */
44598 geo->src.full_width = max(geo->dst.full_width, pix->width);
44599 geo->src.full_height = max(geo->dst.full_height, pix->height);
44600- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44601+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44602 mxr_geometry_dump(mdev, &layer->geo);
44603 /* set cropping to total visible screen */
44604 geo->src.width = pix->width;
44605@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44606 geo->src.x_offset = 0;
44607 geo->src.y_offset = 0;
44608 /* assure consistency of geometry */
44609- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44610+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44611 mxr_geometry_dump(mdev, &layer->geo);
44612 /* set full size to lowest possible value */
44613 geo->src.full_width = 0;
44614 geo->src.full_height = 0;
44615- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44616+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44617 mxr_geometry_dump(mdev, &layer->geo);
44618
44619 /* returning results */
44620@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44621 target->width = s->r.width;
44622 target->height = s->r.height;
44623
44624- layer->ops.fix_geometry(layer, stage, s->flags);
44625+ layer->ops->fix_geometry(layer, stage, s->flags);
44626
44627 /* retrieve update selection rectangle */
44628 res.left = target->x_offset;
44629@@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44630 mxr_output_get(mdev);
44631
44632 mxr_layer_update_output(layer);
44633- layer->ops.format_set(layer);
44634+ layer->ops->format_set(layer);
44635 /* enabling layer in hardware */
44636 spin_lock_irqsave(&layer->enq_slock, flags);
44637 layer->state = MXR_LAYER_STREAMING;
44638 spin_unlock_irqrestore(&layer->enq_slock, flags);
44639
44640- layer->ops.stream_set(layer, MXR_ENABLE);
44641+ layer->ops->stream_set(layer, MXR_ENABLE);
44642 mxr_streamer_get(mdev);
44643
44644 return 0;
44645@@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44646 spin_unlock_irqrestore(&layer->enq_slock, flags);
44647
44648 /* disabling layer in hardware */
44649- layer->ops.stream_set(layer, MXR_DISABLE);
44650+ layer->ops->stream_set(layer, MXR_DISABLE);
44651 /* remove one streamer */
44652 mxr_streamer_put(mdev);
44653 /* allow changes in output configuration */
44654@@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44655
44656 void mxr_layer_release(struct mxr_layer *layer)
44657 {
44658- if (layer->ops.release)
44659- layer->ops.release(layer);
44660+ if (layer->ops->release)
44661+ layer->ops->release(layer);
44662 }
44663
44664 void mxr_base_layer_release(struct mxr_layer *layer)
44665@@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44666
44667 layer->mdev = mdev;
44668 layer->idx = idx;
44669- layer->ops = *ops;
44670+ layer->ops = ops;
44671
44672 spin_lock_init(&layer->enq_slock);
44673 INIT_LIST_HEAD(&layer->enq_list);
44674diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44675index c9388c4..ce71ece 100644
44676--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44677+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44678@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44679 {
44680 struct mxr_layer *layer;
44681 int ret;
44682- struct mxr_layer_ops ops = {
44683+ static struct mxr_layer_ops ops = {
44684 .release = mxr_vp_layer_release,
44685 .buffer_set = mxr_vp_buffer_set,
44686 .stream_set = mxr_vp_stream_set,
44687diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44688index 3890f4f..b5c7511 100644
44689--- a/drivers/media/platform/vivi.c
44690+++ b/drivers/media/platform/vivi.c
44691@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44692 MODULE_LICENSE("Dual BSD/GPL");
44693 MODULE_VERSION(VIVI_VERSION);
44694
44695-static unsigned video_nr = -1;
44696-module_param(video_nr, uint, 0644);
44697+static int video_nr = -1;
44698+module_param(video_nr, int, 0644);
44699 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44700
44701 static unsigned n_devs = 1;
44702diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44703index d719e59..63f3470 100644
44704--- a/drivers/media/radio/radio-cadet.c
44705+++ b/drivers/media/radio/radio-cadet.c
44706@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44707 unsigned char readbuf[RDS_BUFFER];
44708 int i = 0;
44709
44710+ if (count > RDS_BUFFER)
44711+ return -EFAULT;
44712 mutex_lock(&dev->lock);
44713 if (dev->rdsstat == 0)
44714 cadet_start_rds(dev);
44715@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44716 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44717 mutex_unlock(&dev->lock);
44718
44719- if (i && copy_to_user(data, readbuf, i))
44720- return -EFAULT;
44721+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44722+ i = -EFAULT;
44723+
44724 return i;
44725 }
44726
44727diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44728index 5236035..c622c74 100644
44729--- a/drivers/media/radio/radio-maxiradio.c
44730+++ b/drivers/media/radio/radio-maxiradio.c
44731@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44732 /* TEA5757 pin mappings */
44733 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44734
44735-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44736+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44737
44738 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44739 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44740diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44741index 050b3bb..79f62b9 100644
44742--- a/drivers/media/radio/radio-shark.c
44743+++ b/drivers/media/radio/radio-shark.c
44744@@ -79,7 +79,7 @@ struct shark_device {
44745 u32 last_val;
44746 };
44747
44748-static atomic_t shark_instance = ATOMIC_INIT(0);
44749+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44750
44751 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44752 {
44753diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44754index 8654e0d..0608a64 100644
44755--- a/drivers/media/radio/radio-shark2.c
44756+++ b/drivers/media/radio/radio-shark2.c
44757@@ -74,7 +74,7 @@ struct shark_device {
44758 u8 *transfer_buffer;
44759 };
44760
44761-static atomic_t shark_instance = ATOMIC_INIT(0);
44762+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44763
44764 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44765 {
44766diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44767index 2fd9009..278cc1e 100644
44768--- a/drivers/media/radio/radio-si476x.c
44769+++ b/drivers/media/radio/radio-si476x.c
44770@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44771 struct si476x_radio *radio;
44772 struct v4l2_ctrl *ctrl;
44773
44774- static atomic_t instance = ATOMIC_INIT(0);
44775+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44776
44777 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44778 if (!radio)
44779diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44780index a1c641e..3007da9 100644
44781--- a/drivers/media/usb/dvb-usb/cxusb.c
44782+++ b/drivers/media/usb/dvb-usb/cxusb.c
44783@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44784
44785 struct dib0700_adapter_state {
44786 int (*set_param_save) (struct dvb_frontend *);
44787-};
44788+} __no_const;
44789
44790 static int dib7070_set_param_override(struct dvb_frontend *fe)
44791 {
44792diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44793index 733a7ff..f8b52e3 100644
44794--- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44795+++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44796@@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
44797
44798 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
44799 {
44800- struct hexline hx;
44801- u8 reset;
44802+ struct hexline *hx;
44803+ u8 *reset;
44804 int ret,pos=0;
44805
44806+ reset = kmalloc(1, GFP_KERNEL);
44807+ if (reset == NULL)
44808+ return -ENOMEM;
44809+
44810+ hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
44811+ if (hx == NULL) {
44812+ kfree(reset);
44813+ return -ENOMEM;
44814+ }
44815+
44816 /* stop the CPU */
44817- reset = 1;
44818- if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
44819+ reset[0] = 1;
44820+ if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
44821 err("could not stop the USB controller CPU.");
44822
44823- while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
44824- deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
44825- ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
44826+ while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
44827+ deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
44828+ ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
44829
44830- if (ret != hx.len) {
44831+ if (ret != hx->len) {
44832 err("error while transferring firmware "
44833 "(transferred size: %d, block size: %d)",
44834- ret,hx.len);
44835+ ret,hx->len);
44836 ret = -EINVAL;
44837 break;
44838 }
44839 }
44840 if (ret < 0) {
44841 err("firmware download failed at %d with %d",pos,ret);
44842+ kfree(reset);
44843+ kfree(hx);
44844 return ret;
44845 }
44846
44847 if (ret == 0) {
44848 /* restart the CPU */
44849- reset = 0;
44850- if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
44851+ reset[0] = 0;
44852+ if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
44853 err("could not restart the USB controller CPU.");
44854 ret = -EINVAL;
44855 }
44856 } else
44857 ret = -EIO;
44858
44859+ kfree(reset);
44860+ kfree(hx);
44861+
44862 return ret;
44863 }
44864 EXPORT_SYMBOL(usb_cypress_load_firmware);
44865diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44866index ae0f56a..ec71784 100644
44867--- a/drivers/media/usb/dvb-usb/dw2102.c
44868+++ b/drivers/media/usb/dvb-usb/dw2102.c
44869@@ -118,7 +118,7 @@ struct su3000_state {
44870
44871 struct s6x0_state {
44872 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44873-};
44874+} __no_const;
44875
44876 /* debug */
44877 static int dvb_usb_dw2102_debug;
44878diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
44879index 98d24ae..bc22415 100644
44880--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
44881+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
44882@@ -87,8 +87,11 @@ struct technisat_usb2_state {
44883 static int technisat_usb2_i2c_access(struct usb_device *udev,
44884 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
44885 {
44886- u8 b[64];
44887- int ret, actual_length;
44888+ u8 *b = kmalloc(64, GFP_KERNEL);
44889+ int ret, actual_length, error = 0;
44890+
44891+ if (b == NULL)
44892+ return -ENOMEM;
44893
44894 deb_i2c("i2c-access: %02x, tx: ", device_addr);
44895 debug_dump(tx, txlen, deb_i2c);
44896@@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44897
44898 if (ret < 0) {
44899 err("i2c-error: out failed %02x = %d", device_addr, ret);
44900- return -ENODEV;
44901+ error = -ENODEV;
44902+ goto out;
44903 }
44904
44905 ret = usb_bulk_msg(udev,
44906@@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44907 b, 64, &actual_length, 1000);
44908 if (ret < 0) {
44909 err("i2c-error: in failed %02x = %d", device_addr, ret);
44910- return -ENODEV;
44911+ error = -ENODEV;
44912+ goto out;
44913 }
44914
44915 if (b[0] != I2C_STATUS_OK) {
44916@@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44917 /* handle tuner-i2c-nak */
44918 if (!(b[0] == I2C_STATUS_NAK &&
44919 device_addr == 0x60
44920- /* && device_is_technisat_usb2 */))
44921- return -ENODEV;
44922+ /* && device_is_technisat_usb2 */)) {
44923+ error = -ENODEV;
44924+ goto out;
44925+ }
44926 }
44927
44928 deb_i2c("status: %d, ", b[0]);
44929@@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44930
44931 deb_i2c("\n");
44932
44933- return 0;
44934+out:
44935+ kfree(b);
44936+ return error;
44937 }
44938
44939 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
44940@@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44941 {
44942 int ret;
44943
44944- u8 led[8] = {
44945- red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44946- 0
44947- };
44948+ u8 *led = kzalloc(8, GFP_KERNEL);
44949+
44950+ if (led == NULL)
44951+ return -ENOMEM;
44952
44953 if (disable_led_control && state != LED_OFF)
44954 return 0;
44955
44956+ led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
44957+
44958 switch (state) {
44959 case LED_ON:
44960 led[1] = 0x82;
44961@@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44962 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44963 USB_TYPE_VENDOR | USB_DIR_OUT,
44964 0, 0,
44965- led, sizeof(led), 500);
44966+ led, 8, 500);
44967
44968 mutex_unlock(&d->i2c_mutex);
44969+
44970+ kfree(led);
44971+
44972 return ret;
44973 }
44974
44975 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
44976 {
44977 int ret;
44978- u8 b = 0;
44979+ u8 *b = kzalloc(1, GFP_KERNEL);
44980+
44981+ if (b == NULL)
44982+ return -ENOMEM;
44983
44984 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
44985 return -EAGAIN;
44986@@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
44987 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
44988 USB_TYPE_VENDOR | USB_DIR_OUT,
44989 (red << 8) | green, 0,
44990- &b, 1, 500);
44991+ b, 1, 500);
44992
44993 mutex_unlock(&d->i2c_mutex);
44994
44995+ kfree(b);
44996+
44997 return ret;
44998 }
44999
45000@@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45001 struct dvb_usb_device_description **desc, int *cold)
45002 {
45003 int ret;
45004- u8 version[3];
45005+ u8 *version = kmalloc(3, GFP_KERNEL);
45006
45007 /* first select the interface */
45008 if (usb_set_interface(udev, 0, 1) != 0)
45009@@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45010
45011 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
45012
45013+ if (version == NULL)
45014+ return 0;
45015+
45016 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
45017 GET_VERSION_INFO_VENDOR_REQUEST,
45018 USB_TYPE_VENDOR | USB_DIR_IN,
45019 0, 0,
45020- version, sizeof(version), 500);
45021+ version, 3, 500);
45022
45023 if (ret < 0)
45024 *cold = 1;
45025@@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45026 *cold = 0;
45027 }
45028
45029+ kfree(version);
45030+
45031 return 0;
45032 }
45033
45034@@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
45035
45036 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
45037 {
45038- u8 buf[62], *b;
45039+ u8 *buf, *b;
45040 int ret;
45041 struct ir_raw_event ev;
45042
45043+ buf = kmalloc(62, GFP_KERNEL);
45044+
45045+ if (buf == NULL)
45046+ return -ENOMEM;
45047+
45048 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
45049 buf[1] = 0x08;
45050 buf[2] = 0x8f;
45051@@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
45052 GET_IR_DATA_VENDOR_REQUEST,
45053 USB_TYPE_VENDOR | USB_DIR_IN,
45054 0x8080, 0,
45055- buf, sizeof(buf), 500);
45056+ buf, 62, 500);
45057
45058 unlock:
45059 mutex_unlock(&d->i2c_mutex);
45060
45061- if (ret < 0)
45062+ if (ret < 0) {
45063+ kfree(buf);
45064 return ret;
45065+ }
45066
45067- if (ret == 1)
45068+ if (ret == 1) {
45069+ kfree(buf);
45070 return 0; /* no key pressed */
45071+ }
45072
45073 /* decoding */
45074 b = buf+1;
45075@@ -653,6 +686,8 @@ unlock:
45076
45077 ir_raw_event_handle(d->rc_dev);
45078
45079+ kfree(buf);
45080+
45081 return 1;
45082 }
45083
45084diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45085index 7e2411c..cef73ca 100644
45086--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45087+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45088@@ -328,7 +328,7 @@ struct v4l2_buffer32 {
45089 __u32 reserved;
45090 };
45091
45092-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45093+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45094 enum v4l2_memory memory)
45095 {
45096 void __user *up_pln;
45097@@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45098 return 0;
45099 }
45100
45101-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45102+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45103 enum v4l2_memory memory)
45104 {
45105 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
45106@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45107 * by passing a very big num_planes value */
45108 uplane = compat_alloc_user_space(num_planes *
45109 sizeof(struct v4l2_plane));
45110- kp->m.planes = uplane;
45111+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
45112
45113 while (--num_planes >= 0) {
45114 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45115@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45116 if (num_planes == 0)
45117 return 0;
45118
45119- uplane = kp->m.planes;
45120+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45121 if (get_user(p, &up->m.planes))
45122 return -EFAULT;
45123 uplane32 = compat_ptr(p);
45124@@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45125 get_user(kp->capability, &up->capability) ||
45126 get_user(kp->flags, &up->flags))
45127 return -EFAULT;
45128- kp->base = compat_ptr(tmp);
45129+ kp->base = (void __force_kernel *)compat_ptr(tmp);
45130 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45131 return 0;
45132 }
45133@@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45134 n * sizeof(struct v4l2_ext_control32)))
45135 return -EFAULT;
45136 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45137- kp->controls = kcontrols;
45138+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45139 while (--n >= 0) {
45140 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45141 return -EFAULT;
45142@@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45143 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45144 {
45145 struct v4l2_ext_control32 __user *ucontrols;
45146- struct v4l2_ext_control __user *kcontrols = kp->controls;
45147+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45148 int n = kp->count;
45149 compat_caddr_t p;
45150
45151@@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
45152 put_user(kp->start_block, &up->start_block) ||
45153 put_user(kp->blocks, &up->blocks) ||
45154 put_user(tmp, &up->edid) ||
45155- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45156+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45157 return -EFAULT;
45158 return 0;
45159 }
45160diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45161index 55c6832..a91c7a6 100644
45162--- a/drivers/media/v4l2-core/v4l2-ctrls.c
45163+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45164@@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45165 return 0;
45166
45167 case V4L2_CTRL_TYPE_STRING:
45168- len = strlen(c->string);
45169- if (len < ctrl->minimum)
45170+ len = strlen_user(c->string);
45171+ if (!len || len < ctrl->minimum)
45172 return -ERANGE;
45173 if ((len - ctrl->minimum) % ctrl->step)
45174 return -ERANGE;
45175diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45176index 02d1b63..5fd6b16 100644
45177--- a/drivers/media/v4l2-core/v4l2-device.c
45178+++ b/drivers/media/v4l2-core/v4l2-device.c
45179@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45180 EXPORT_SYMBOL_GPL(v4l2_device_put);
45181
45182 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45183- atomic_t *instance)
45184+ atomic_unchecked_t *instance)
45185 {
45186- int num = atomic_inc_return(instance) - 1;
45187+ int num = atomic_inc_return_unchecked(instance) - 1;
45188 int len = strlen(basename);
45189
45190 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45191diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45192index d9113cc..7de6ccc 100644
45193--- a/drivers/media/v4l2-core/v4l2-ioctl.c
45194+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45195@@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
45196 struct file *file, void *fh, void *p);
45197 } u;
45198 void (*debug)(const void *arg, bool write_only);
45199-};
45200+} __do_const;
45201+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45202
45203 /* This control needs a priority check */
45204 #define INFO_FL_PRIO (1 << 0)
45205@@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
45206 struct video_device *vfd = video_devdata(file);
45207 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45208 bool write_only = false;
45209- struct v4l2_ioctl_info default_info;
45210+ v4l2_ioctl_info_no_const default_info;
45211 const struct v4l2_ioctl_info *info;
45212 void *fh = file->private_data;
45213 struct v4l2_fh *vfh = NULL;
45214@@ -2260,7 +2261,7 @@ done:
45215 }
45216
45217 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45218- void * __user *user_ptr, void ***kernel_ptr)
45219+ void __user **user_ptr, void ***kernel_ptr)
45220 {
45221 int ret = 0;
45222
45223@@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45224 ret = -EINVAL;
45225 break;
45226 }
45227- *user_ptr = (void __user *)buf->m.planes;
45228+ *user_ptr = (void __force_user *)buf->m.planes;
45229 *kernel_ptr = (void *)&buf->m.planes;
45230 *array_size = sizeof(struct v4l2_plane) * buf->length;
45231 ret = 1;
45232@@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45233 ret = -EINVAL;
45234 break;
45235 }
45236- *user_ptr = (void __user *)ctrls->controls;
45237+ *user_ptr = (void __force_user *)ctrls->controls;
45238 *kernel_ptr = (void *)&ctrls->controls;
45239 *array_size = sizeof(struct v4l2_ext_control)
45240 * ctrls->count;
45241@@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45242 }
45243
45244 if (has_array_args) {
45245- *kernel_ptr = user_ptr;
45246+ *kernel_ptr = (void __force_kernel *)user_ptr;
45247 if (copy_to_user(user_ptr, mbuf, array_size))
45248 err = -EFAULT;
45249 goto out_array_args;
45250diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45251index 570b18a..f880314 100644
45252--- a/drivers/message/fusion/mptbase.c
45253+++ b/drivers/message/fusion/mptbase.c
45254@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45255 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45256 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45257
45258+#ifdef CONFIG_GRKERNSEC_HIDESYM
45259+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45260+#else
45261 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45262 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45263+#endif
45264+
45265 /*
45266 * Rounding UP to nearest 4-kB boundary here...
45267 */
45268@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45269 ioc->facts.GlobalCredits);
45270
45271 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45272+#ifdef CONFIG_GRKERNSEC_HIDESYM
45273+ NULL, NULL);
45274+#else
45275 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45276+#endif
45277 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45278 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45279 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45280diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45281index 00d339c..2ea899d 100644
45282--- a/drivers/message/fusion/mptsas.c
45283+++ b/drivers/message/fusion/mptsas.c
45284@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45285 return 0;
45286 }
45287
45288+static inline void
45289+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45290+{
45291+ if (phy_info->port_details) {
45292+ phy_info->port_details->rphy = rphy;
45293+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45294+ ioc->name, rphy));
45295+ }
45296+
45297+ if (rphy) {
45298+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45299+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45300+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45301+ ioc->name, rphy, rphy->dev.release));
45302+ }
45303+}
45304+
45305 /* no mutex */
45306 static void
45307 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45308@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45309 return NULL;
45310 }
45311
45312-static inline void
45313-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45314-{
45315- if (phy_info->port_details) {
45316- phy_info->port_details->rphy = rphy;
45317- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45318- ioc->name, rphy));
45319- }
45320-
45321- if (rphy) {
45322- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45323- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45324- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45325- ioc->name, rphy, rphy->dev.release));
45326- }
45327-}
45328-
45329 static inline struct sas_port *
45330 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45331 {
45332diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45333index 727819c..ad74694 100644
45334--- a/drivers/message/fusion/mptscsih.c
45335+++ b/drivers/message/fusion/mptscsih.c
45336@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45337
45338 h = shost_priv(SChost);
45339
45340- if (h) {
45341- if (h->info_kbuf == NULL)
45342- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45343- return h->info_kbuf;
45344- h->info_kbuf[0] = '\0';
45345+ if (!h)
45346+ return NULL;
45347
45348- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45349- h->info_kbuf[size-1] = '\0';
45350- }
45351+ if (h->info_kbuf == NULL)
45352+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45353+ return h->info_kbuf;
45354+ h->info_kbuf[0] = '\0';
45355+
45356+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45357+ h->info_kbuf[size-1] = '\0';
45358
45359 return h->info_kbuf;
45360 }
45361diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45362index b7d87cd..3fb36da 100644
45363--- a/drivers/message/i2o/i2o_proc.c
45364+++ b/drivers/message/i2o/i2o_proc.c
45365@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45366 "Array Controller Device"
45367 };
45368
45369-static char *chtostr(char *tmp, u8 *chars, int n)
45370-{
45371- tmp[0] = 0;
45372- return strncat(tmp, (char *)chars, n);
45373-}
45374-
45375 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45376 char *group)
45377 {
45378@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45379 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45380 {
45381 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45382- static u32 work32[5];
45383- static u8 *work8 = (u8 *) work32;
45384- static u16 *work16 = (u16 *) work32;
45385+ u32 work32[5];
45386+ u8 *work8 = (u8 *) work32;
45387+ u16 *work16 = (u16 *) work32;
45388 int token;
45389 u32 hwcap;
45390
45391@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45392 } *result;
45393
45394 i2o_exec_execute_ddm_table ddm_table;
45395- char tmp[28 + 1];
45396
45397 result = kmalloc(sizeof(*result), GFP_KERNEL);
45398 if (!result)
45399@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45400
45401 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45402 seq_printf(seq, "%-#8x", ddm_table.module_id);
45403- seq_printf(seq, "%-29s",
45404- chtostr(tmp, ddm_table.module_name_version, 28));
45405+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45406 seq_printf(seq, "%9d ", ddm_table.data_size);
45407 seq_printf(seq, "%8d", ddm_table.code_size);
45408
45409@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45410
45411 i2o_driver_result_table *result;
45412 i2o_driver_store_table *dst;
45413- char tmp[28 + 1];
45414
45415 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45416 if (result == NULL)
45417@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45418
45419 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45420 seq_printf(seq, "%-#8x", dst->module_id);
45421- seq_printf(seq, "%-29s",
45422- chtostr(tmp, dst->module_name_version, 28));
45423- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45424+ seq_printf(seq, "%-.28s", dst->module_name_version);
45425+ seq_printf(seq, "%-.8s", dst->date);
45426 seq_printf(seq, "%8d ", dst->module_size);
45427 seq_printf(seq, "%8d ", dst->mpb_size);
45428 seq_printf(seq, "0x%04x", dst->module_flags);
45429@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45430 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45431 {
45432 struct i2o_device *d = (struct i2o_device *)seq->private;
45433- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45434+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45435 // == (allow) 512d bytes (max)
45436- static u16 *work16 = (u16 *) work32;
45437+ u16 *work16 = (u16 *) work32;
45438 int token;
45439- char tmp[16 + 1];
45440
45441 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45442
45443@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45444 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45445 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45446 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45447- seq_printf(seq, "Vendor info : %s\n",
45448- chtostr(tmp, (u8 *) (work32 + 2), 16));
45449- seq_printf(seq, "Product info : %s\n",
45450- chtostr(tmp, (u8 *) (work32 + 6), 16));
45451- seq_printf(seq, "Description : %s\n",
45452- chtostr(tmp, (u8 *) (work32 + 10), 16));
45453- seq_printf(seq, "Product rev. : %s\n",
45454- chtostr(tmp, (u8 *) (work32 + 14), 8));
45455+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45456+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45457+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45458+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45459
45460 seq_printf(seq, "Serial number : ");
45461 print_serial_number(seq, (u8 *) (work32 + 16),
45462@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45463 u8 pad[256]; // allow up to 256 byte (max) serial number
45464 } result;
45465
45466- char tmp[24 + 1];
45467-
45468 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45469
45470 if (token < 0) {
45471@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45472 }
45473
45474 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45475- seq_printf(seq, "Module name : %s\n",
45476- chtostr(tmp, result.module_name, 24));
45477- seq_printf(seq, "Module revision : %s\n",
45478- chtostr(tmp, result.module_rev, 8));
45479+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45480+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45481
45482 seq_printf(seq, "Serial number : ");
45483 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45484@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45485 u8 instance_number[4];
45486 } result;
45487
45488- char tmp[64 + 1];
45489-
45490 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45491
45492 if (token < 0) {
45493@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45494 return 0;
45495 }
45496
45497- seq_printf(seq, "Device name : %s\n",
45498- chtostr(tmp, result.device_name, 64));
45499- seq_printf(seq, "Service name : %s\n",
45500- chtostr(tmp, result.service_name, 64));
45501- seq_printf(seq, "Physical name : %s\n",
45502- chtostr(tmp, result.physical_location, 64));
45503- seq_printf(seq, "Instance number : %s\n",
45504- chtostr(tmp, result.instance_number, 4));
45505+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45506+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45507+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45508+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45509
45510 return 0;
45511 }
45512@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45513 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45514 {
45515 struct i2o_device *d = (struct i2o_device *)seq->private;
45516- static u32 work32[12];
45517- static u16 *work16 = (u16 *) work32;
45518- static u8 *work8 = (u8 *) work32;
45519+ u32 work32[12];
45520+ u16 *work16 = (u16 *) work32;
45521+ u8 *work8 = (u8 *) work32;
45522 int token;
45523
45524 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45525diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45526index 92752fb..a7494f6 100644
45527--- a/drivers/message/i2o/iop.c
45528+++ b/drivers/message/i2o/iop.c
45529@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45530
45531 spin_lock_irqsave(&c->context_list_lock, flags);
45532
45533- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45534- atomic_inc(&c->context_list_counter);
45535+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45536+ atomic_inc_unchecked(&c->context_list_counter);
45537
45538- entry->context = atomic_read(&c->context_list_counter);
45539+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45540
45541 list_add(&entry->list, &c->context_list);
45542
45543@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45544
45545 #if BITS_PER_LONG == 64
45546 spin_lock_init(&c->context_list_lock);
45547- atomic_set(&c->context_list_counter, 0);
45548+ atomic_set_unchecked(&c->context_list_counter, 0);
45549 INIT_LIST_HEAD(&c->context_list);
45550 #endif
45551
45552diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45553index d1a22aa..d0f7bf7 100644
45554--- a/drivers/mfd/ab8500-debugfs.c
45555+++ b/drivers/mfd/ab8500-debugfs.c
45556@@ -100,7 +100,7 @@ static int irq_last;
45557 static u32 *irq_count;
45558 static int num_irqs;
45559
45560-static struct device_attribute **dev_attr;
45561+static device_attribute_no_const **dev_attr;
45562 static char **event_name;
45563
45564 static u8 avg_sample = SAMPLE_16;
45565diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45566index a83eed5..62a58a9 100644
45567--- a/drivers/mfd/max8925-i2c.c
45568+++ b/drivers/mfd/max8925-i2c.c
45569@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45570 const struct i2c_device_id *id)
45571 {
45572 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45573- static struct max8925_chip *chip;
45574+ struct max8925_chip *chip;
45575 struct device_node *node = client->dev.of_node;
45576
45577 if (node && !pdata) {
45578diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45579index 460a014..21d3061 100644
45580--- a/drivers/mfd/tps65910.c
45581+++ b/drivers/mfd/tps65910.c
45582@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45583 struct tps65910_platform_data *pdata)
45584 {
45585 int ret = 0;
45586- static struct regmap_irq_chip *tps6591x_irqs_chip;
45587+ struct regmap_irq_chip *tps6591x_irqs_chip;
45588
45589 if (!irq) {
45590 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45591diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45592index 596b1f6..5b6ab74 100644
45593--- a/drivers/mfd/twl4030-irq.c
45594+++ b/drivers/mfd/twl4030-irq.c
45595@@ -34,6 +34,7 @@
45596 #include <linux/of.h>
45597 #include <linux/irqdomain.h>
45598 #include <linux/i2c/twl.h>
45599+#include <asm/pgtable.h>
45600
45601 #include "twl-core.h"
45602
45603@@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45604 * Install an irq handler for each of the SIH modules;
45605 * clone dummy irq_chip since PIH can't *do* anything
45606 */
45607- twl4030_irq_chip = dummy_irq_chip;
45608- twl4030_irq_chip.name = "twl4030";
45609+ pax_open_kernel();
45610+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45611+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45612
45613- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45614+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45615+ pax_close_kernel();
45616
45617 for (i = irq_base; i < irq_end; i++) {
45618 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45619diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45620index 464419b..64bae8d 100644
45621--- a/drivers/misc/c2port/core.c
45622+++ b/drivers/misc/c2port/core.c
45623@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45624 goto error_idr_alloc;
45625 c2dev->id = ret;
45626
45627- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45628+ pax_open_kernel();
45629+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45630+ pax_close_kernel();
45631
45632 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45633 "c2port%d", c2dev->id);
45634diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45635index 3f2b625..945e179 100644
45636--- a/drivers/misc/eeprom/sunxi_sid.c
45637+++ b/drivers/misc/eeprom/sunxi_sid.c
45638@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45639
45640 platform_set_drvdata(pdev, sid_data);
45641
45642- sid_bin_attr.size = sid_data->keysize;
45643+ pax_open_kernel();
45644+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45645+ pax_close_kernel();
45646 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45647 return -ENODEV;
45648
45649diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45650index 36f5d52..32311c3 100644
45651--- a/drivers/misc/kgdbts.c
45652+++ b/drivers/misc/kgdbts.c
45653@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45654 char before[BREAK_INSTR_SIZE];
45655 char after[BREAK_INSTR_SIZE];
45656
45657- probe_kernel_read(before, (char *)kgdbts_break_test,
45658+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45659 BREAK_INSTR_SIZE);
45660 init_simple_test();
45661 ts.tst = plant_and_detach_test;
45662@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45663 /* Activate test with initial breakpoint */
45664 if (!is_early)
45665 kgdb_breakpoint();
45666- probe_kernel_read(after, (char *)kgdbts_break_test,
45667+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45668 BREAK_INSTR_SIZE);
45669 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45670 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45671diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45672index 3ef4627..8d00486 100644
45673--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45674+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45675@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45676 * the lid is closed. This leads to interrupts as soon as a little move
45677 * is done.
45678 */
45679- atomic_inc(&lis3->count);
45680+ atomic_inc_unchecked(&lis3->count);
45681
45682 wake_up_interruptible(&lis3->misc_wait);
45683 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45684@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45685 if (lis3->pm_dev)
45686 pm_runtime_get_sync(lis3->pm_dev);
45687
45688- atomic_set(&lis3->count, 0);
45689+ atomic_set_unchecked(&lis3->count, 0);
45690 return 0;
45691 }
45692
45693@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45694 add_wait_queue(&lis3->misc_wait, &wait);
45695 while (true) {
45696 set_current_state(TASK_INTERRUPTIBLE);
45697- data = atomic_xchg(&lis3->count, 0);
45698+ data = atomic_xchg_unchecked(&lis3->count, 0);
45699 if (data)
45700 break;
45701
45702@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45703 struct lis3lv02d, miscdev);
45704
45705 poll_wait(file, &lis3->misc_wait, wait);
45706- if (atomic_read(&lis3->count))
45707+ if (atomic_read_unchecked(&lis3->count))
45708 return POLLIN | POLLRDNORM;
45709 return 0;
45710 }
45711diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45712index c439c82..1f20f57 100644
45713--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45714+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45715@@ -297,7 +297,7 @@ struct lis3lv02d {
45716 struct input_polled_dev *idev; /* input device */
45717 struct platform_device *pdev; /* platform device */
45718 struct regulator_bulk_data regulators[2];
45719- atomic_t count; /* interrupt count after last read */
45720+ atomic_unchecked_t count; /* interrupt count after last read */
45721 union axis_conversion ac; /* hw -> logical axis */
45722 int mapped_btns[3];
45723
45724diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45725index 2f30bad..c4c13d0 100644
45726--- a/drivers/misc/sgi-gru/gruhandles.c
45727+++ b/drivers/misc/sgi-gru/gruhandles.c
45728@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45729 unsigned long nsec;
45730
45731 nsec = CLKS2NSEC(clks);
45732- atomic_long_inc(&mcs_op_statistics[op].count);
45733- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45734+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45735+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45736 if (mcs_op_statistics[op].max < nsec)
45737 mcs_op_statistics[op].max = nsec;
45738 }
45739diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45740index 4f76359..cdfcb2e 100644
45741--- a/drivers/misc/sgi-gru/gruprocfs.c
45742+++ b/drivers/misc/sgi-gru/gruprocfs.c
45743@@ -32,9 +32,9 @@
45744
45745 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45746
45747-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45748+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45749 {
45750- unsigned long val = atomic_long_read(v);
45751+ unsigned long val = atomic_long_read_unchecked(v);
45752
45753 seq_printf(s, "%16lu %s\n", val, id);
45754 }
45755@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45756
45757 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45758 for (op = 0; op < mcsop_last; op++) {
45759- count = atomic_long_read(&mcs_op_statistics[op].count);
45760- total = atomic_long_read(&mcs_op_statistics[op].total);
45761+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45762+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45763 max = mcs_op_statistics[op].max;
45764 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45765 count ? total / count : 0, max);
45766diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45767index 5c3ce24..4915ccb 100644
45768--- a/drivers/misc/sgi-gru/grutables.h
45769+++ b/drivers/misc/sgi-gru/grutables.h
45770@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45771 * GRU statistics.
45772 */
45773 struct gru_stats_s {
45774- atomic_long_t vdata_alloc;
45775- atomic_long_t vdata_free;
45776- atomic_long_t gts_alloc;
45777- atomic_long_t gts_free;
45778- atomic_long_t gms_alloc;
45779- atomic_long_t gms_free;
45780- atomic_long_t gts_double_allocate;
45781- atomic_long_t assign_context;
45782- atomic_long_t assign_context_failed;
45783- atomic_long_t free_context;
45784- atomic_long_t load_user_context;
45785- atomic_long_t load_kernel_context;
45786- atomic_long_t lock_kernel_context;
45787- atomic_long_t unlock_kernel_context;
45788- atomic_long_t steal_user_context;
45789- atomic_long_t steal_kernel_context;
45790- atomic_long_t steal_context_failed;
45791- atomic_long_t nopfn;
45792- atomic_long_t asid_new;
45793- atomic_long_t asid_next;
45794- atomic_long_t asid_wrap;
45795- atomic_long_t asid_reuse;
45796- atomic_long_t intr;
45797- atomic_long_t intr_cbr;
45798- atomic_long_t intr_tfh;
45799- atomic_long_t intr_spurious;
45800- atomic_long_t intr_mm_lock_failed;
45801- atomic_long_t call_os;
45802- atomic_long_t call_os_wait_queue;
45803- atomic_long_t user_flush_tlb;
45804- atomic_long_t user_unload_context;
45805- atomic_long_t user_exception;
45806- atomic_long_t set_context_option;
45807- atomic_long_t check_context_retarget_intr;
45808- atomic_long_t check_context_unload;
45809- atomic_long_t tlb_dropin;
45810- atomic_long_t tlb_preload_page;
45811- atomic_long_t tlb_dropin_fail_no_asid;
45812- atomic_long_t tlb_dropin_fail_upm;
45813- atomic_long_t tlb_dropin_fail_invalid;
45814- atomic_long_t tlb_dropin_fail_range_active;
45815- atomic_long_t tlb_dropin_fail_idle;
45816- atomic_long_t tlb_dropin_fail_fmm;
45817- atomic_long_t tlb_dropin_fail_no_exception;
45818- atomic_long_t tfh_stale_on_fault;
45819- atomic_long_t mmu_invalidate_range;
45820- atomic_long_t mmu_invalidate_page;
45821- atomic_long_t flush_tlb;
45822- atomic_long_t flush_tlb_gru;
45823- atomic_long_t flush_tlb_gru_tgh;
45824- atomic_long_t flush_tlb_gru_zero_asid;
45825+ atomic_long_unchecked_t vdata_alloc;
45826+ atomic_long_unchecked_t vdata_free;
45827+ atomic_long_unchecked_t gts_alloc;
45828+ atomic_long_unchecked_t gts_free;
45829+ atomic_long_unchecked_t gms_alloc;
45830+ atomic_long_unchecked_t gms_free;
45831+ atomic_long_unchecked_t gts_double_allocate;
45832+ atomic_long_unchecked_t assign_context;
45833+ atomic_long_unchecked_t assign_context_failed;
45834+ atomic_long_unchecked_t free_context;
45835+ atomic_long_unchecked_t load_user_context;
45836+ atomic_long_unchecked_t load_kernel_context;
45837+ atomic_long_unchecked_t lock_kernel_context;
45838+ atomic_long_unchecked_t unlock_kernel_context;
45839+ atomic_long_unchecked_t steal_user_context;
45840+ atomic_long_unchecked_t steal_kernel_context;
45841+ atomic_long_unchecked_t steal_context_failed;
45842+ atomic_long_unchecked_t nopfn;
45843+ atomic_long_unchecked_t asid_new;
45844+ atomic_long_unchecked_t asid_next;
45845+ atomic_long_unchecked_t asid_wrap;
45846+ atomic_long_unchecked_t asid_reuse;
45847+ atomic_long_unchecked_t intr;
45848+ atomic_long_unchecked_t intr_cbr;
45849+ atomic_long_unchecked_t intr_tfh;
45850+ atomic_long_unchecked_t intr_spurious;
45851+ atomic_long_unchecked_t intr_mm_lock_failed;
45852+ atomic_long_unchecked_t call_os;
45853+ atomic_long_unchecked_t call_os_wait_queue;
45854+ atomic_long_unchecked_t user_flush_tlb;
45855+ atomic_long_unchecked_t user_unload_context;
45856+ atomic_long_unchecked_t user_exception;
45857+ atomic_long_unchecked_t set_context_option;
45858+ atomic_long_unchecked_t check_context_retarget_intr;
45859+ atomic_long_unchecked_t check_context_unload;
45860+ atomic_long_unchecked_t tlb_dropin;
45861+ atomic_long_unchecked_t tlb_preload_page;
45862+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45863+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45864+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45865+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45866+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45867+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45868+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45869+ atomic_long_unchecked_t tfh_stale_on_fault;
45870+ atomic_long_unchecked_t mmu_invalidate_range;
45871+ atomic_long_unchecked_t mmu_invalidate_page;
45872+ atomic_long_unchecked_t flush_tlb;
45873+ atomic_long_unchecked_t flush_tlb_gru;
45874+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45875+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45876
45877- atomic_long_t copy_gpa;
45878- atomic_long_t read_gpa;
45879+ atomic_long_unchecked_t copy_gpa;
45880+ atomic_long_unchecked_t read_gpa;
45881
45882- atomic_long_t mesq_receive;
45883- atomic_long_t mesq_receive_none;
45884- atomic_long_t mesq_send;
45885- atomic_long_t mesq_send_failed;
45886- atomic_long_t mesq_noop;
45887- atomic_long_t mesq_send_unexpected_error;
45888- atomic_long_t mesq_send_lb_overflow;
45889- atomic_long_t mesq_send_qlimit_reached;
45890- atomic_long_t mesq_send_amo_nacked;
45891- atomic_long_t mesq_send_put_nacked;
45892- atomic_long_t mesq_page_overflow;
45893- atomic_long_t mesq_qf_locked;
45894- atomic_long_t mesq_qf_noop_not_full;
45895- atomic_long_t mesq_qf_switch_head_failed;
45896- atomic_long_t mesq_qf_unexpected_error;
45897- atomic_long_t mesq_noop_unexpected_error;
45898- atomic_long_t mesq_noop_lb_overflow;
45899- atomic_long_t mesq_noop_qlimit_reached;
45900- atomic_long_t mesq_noop_amo_nacked;
45901- atomic_long_t mesq_noop_put_nacked;
45902- atomic_long_t mesq_noop_page_overflow;
45903+ atomic_long_unchecked_t mesq_receive;
45904+ atomic_long_unchecked_t mesq_receive_none;
45905+ atomic_long_unchecked_t mesq_send;
45906+ atomic_long_unchecked_t mesq_send_failed;
45907+ atomic_long_unchecked_t mesq_noop;
45908+ atomic_long_unchecked_t mesq_send_unexpected_error;
45909+ atomic_long_unchecked_t mesq_send_lb_overflow;
45910+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45911+ atomic_long_unchecked_t mesq_send_amo_nacked;
45912+ atomic_long_unchecked_t mesq_send_put_nacked;
45913+ atomic_long_unchecked_t mesq_page_overflow;
45914+ atomic_long_unchecked_t mesq_qf_locked;
45915+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45916+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45917+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45918+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45919+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45920+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45921+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45922+ atomic_long_unchecked_t mesq_noop_put_nacked;
45923+ atomic_long_unchecked_t mesq_noop_page_overflow;
45924
45925 };
45926
45927@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45928 tghop_invalidate, mcsop_last};
45929
45930 struct mcs_op_statistic {
45931- atomic_long_t count;
45932- atomic_long_t total;
45933+ atomic_long_unchecked_t count;
45934+ atomic_long_unchecked_t total;
45935 unsigned long max;
45936 };
45937
45938@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45939
45940 #define STAT(id) do { \
45941 if (gru_options & OPT_STATS) \
45942- atomic_long_inc(&gru_stats.id); \
45943+ atomic_long_inc_unchecked(&gru_stats.id); \
45944 } while (0)
45945
45946 #ifdef CONFIG_SGI_GRU_DEBUG
45947diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45948index c862cd4..0d176fe 100644
45949--- a/drivers/misc/sgi-xp/xp.h
45950+++ b/drivers/misc/sgi-xp/xp.h
45951@@ -288,7 +288,7 @@ struct xpc_interface {
45952 xpc_notify_func, void *);
45953 void (*received) (short, int, void *);
45954 enum xp_retval (*partid_to_nasids) (short, void *);
45955-};
45956+} __no_const;
45957
45958 extern struct xpc_interface xpc_interface;
45959
45960diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45961index 01be66d..e3a0c7e 100644
45962--- a/drivers/misc/sgi-xp/xp_main.c
45963+++ b/drivers/misc/sgi-xp/xp_main.c
45964@@ -78,13 +78,13 @@ xpc_notloaded(void)
45965 }
45966
45967 struct xpc_interface xpc_interface = {
45968- (void (*)(int))xpc_notloaded,
45969- (void (*)(int))xpc_notloaded,
45970- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45971- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45972+ .connect = (void (*)(int))xpc_notloaded,
45973+ .disconnect = (void (*)(int))xpc_notloaded,
45974+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45975+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45976 void *))xpc_notloaded,
45977- (void (*)(short, int, void *))xpc_notloaded,
45978- (enum xp_retval(*)(short, void *))xpc_notloaded
45979+ .received = (void (*)(short, int, void *))xpc_notloaded,
45980+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45981 };
45982 EXPORT_SYMBOL_GPL(xpc_interface);
45983
45984diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45985index b94d5f7..7f494c5 100644
45986--- a/drivers/misc/sgi-xp/xpc.h
45987+++ b/drivers/misc/sgi-xp/xpc.h
45988@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45989 void (*received_payload) (struct xpc_channel *, void *);
45990 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45991 };
45992+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45993
45994 /* struct xpc_partition act_state values (for XPC HB) */
45995
45996@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45997 /* found in xpc_main.c */
45998 extern struct device *xpc_part;
45999 extern struct device *xpc_chan;
46000-extern struct xpc_arch_operations xpc_arch_ops;
46001+extern xpc_arch_operations_no_const xpc_arch_ops;
46002 extern int xpc_disengage_timelimit;
46003 extern int xpc_disengage_timedout;
46004 extern int xpc_activate_IRQ_rcvd;
46005diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46006index 82dc574..8539ab2 100644
46007--- a/drivers/misc/sgi-xp/xpc_main.c
46008+++ b/drivers/misc/sgi-xp/xpc_main.c
46009@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46010 .notifier_call = xpc_system_die,
46011 };
46012
46013-struct xpc_arch_operations xpc_arch_ops;
46014+xpc_arch_operations_no_const xpc_arch_ops;
46015
46016 /*
46017 * Timer function to enforce the timelimit on the partition disengage.
46018@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46019
46020 if (((die_args->trapnr == X86_TRAP_MF) ||
46021 (die_args->trapnr == X86_TRAP_XF)) &&
46022- !user_mode_vm(die_args->regs))
46023+ !user_mode(die_args->regs))
46024 xpc_die_deactivate();
46025
46026 break;
46027diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46028index 452782b..0c10e40 100644
46029--- a/drivers/mmc/card/block.c
46030+++ b/drivers/mmc/card/block.c
46031@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46032 if (idata->ic.postsleep_min_us)
46033 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46034
46035- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46036+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46037 err = -EFAULT;
46038 goto cmd_rel_host;
46039 }
46040diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46041index f51b5ba..86614a7 100644
46042--- a/drivers/mmc/core/mmc_ops.c
46043+++ b/drivers/mmc/core/mmc_ops.c
46044@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46045 void *data_buf;
46046 int is_on_stack;
46047
46048- is_on_stack = object_is_on_stack(buf);
46049+ is_on_stack = object_starts_on_stack(buf);
46050 if (is_on_stack) {
46051 /*
46052 * dma onto stack is unsafe/nonportable, but callers to this
46053diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46054index 6834977..824ee1b 100644
46055--- a/drivers/mmc/host/dw_mmc.h
46056+++ b/drivers/mmc/host/dw_mmc.h
46057@@ -259,5 +259,5 @@ struct dw_mci_drv_data {
46058 int (*parse_dt)(struct dw_mci *host);
46059 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46060 struct dw_mci_tuning_data *tuning_data);
46061-};
46062+} __do_const;
46063 #endif /* _DW_MMC_H_ */
46064diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46065index 771c60a..12cb615 100644
46066--- a/drivers/mmc/host/mmci.c
46067+++ b/drivers/mmc/host/mmci.c
46068@@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
46069 mmc->caps2 = plat->capabilities2;
46070
46071 if (variant->busy_detect) {
46072- mmci_ops.card_busy = mmci_card_busy;
46073+ pax_open_kernel();
46074+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
46075+ pax_close_kernel();
46076 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46077 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
46078 mmc->max_busy_timeout = 0;
46079diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46080index b841bb7..d82712f5 100644
46081--- a/drivers/mmc/host/sdhci-esdhc-imx.c
46082+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
46083@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
46084 host->mmc->caps |= MMC_CAP_1_8V_DDR;
46085 }
46086
46087- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46088- sdhci_esdhc_ops.platform_execute_tuning =
46089+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46090+ pax_open_kernel();
46091+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46092 esdhc_executing_tuning;
46093+ pax_close_kernel();
46094+ }
46095
46096 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46097 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46098diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46099index d61eb5a..88c0f5d 100644
46100--- a/drivers/mmc/host/sdhci-s3c.c
46101+++ b/drivers/mmc/host/sdhci-s3c.c
46102@@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46103 * we can use overriding functions instead of default.
46104 */
46105 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
46106- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46107- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46108- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46109+ pax_open_kernel();
46110+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46111+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46112+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46113+ pax_close_kernel();
46114 }
46115
46116 /* It supports additional host capabilities if needed */
46117diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46118index 6293855..3415551 100644
46119--- a/drivers/mtd/chips/cfi_cmdset_0020.c
46120+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46121@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46122 size_t totlen = 0, thislen;
46123 int ret = 0;
46124 size_t buflen = 0;
46125- static char *buffer;
46126+ char *buffer;
46127
46128 if (!ECCBUF_SIZE) {
46129 /* We should fall back to a general writev implementation.
46130diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46131index c07cd57..61c4fbd 100644
46132--- a/drivers/mtd/nand/denali.c
46133+++ b/drivers/mtd/nand/denali.c
46134@@ -24,6 +24,7 @@
46135 #include <linux/slab.h>
46136 #include <linux/mtd/mtd.h>
46137 #include <linux/module.h>
46138+#include <linux/slab.h>
46139
46140 #include "denali.h"
46141
46142diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46143index bb77f75..47539b1 100644
46144--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46145+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46146@@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46147
46148 /* first try to map the upper buffer directly */
46149 if (virt_addr_valid(this->upper_buf) &&
46150- !object_is_on_stack(this->upper_buf)) {
46151+ !object_starts_on_stack(this->upper_buf)) {
46152 sg_init_one(sgl, this->upper_buf, this->upper_len);
46153 ret = dma_map_sg(this->dev, sgl, 1, dr);
46154 if (ret == 0)
46155diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46156index 51b9d6a..52af9a7 100644
46157--- a/drivers/mtd/nftlmount.c
46158+++ b/drivers/mtd/nftlmount.c
46159@@ -24,6 +24,7 @@
46160 #include <asm/errno.h>
46161 #include <linux/delay.h>
46162 #include <linux/slab.h>
46163+#include <linux/sched.h>
46164 #include <linux/mtd/mtd.h>
46165 #include <linux/mtd/nand.h>
46166 #include <linux/mtd/nftl.h>
46167diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46168index cf49c22..971b133 100644
46169--- a/drivers/mtd/sm_ftl.c
46170+++ b/drivers/mtd/sm_ftl.c
46171@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46172 #define SM_CIS_VENDOR_OFFSET 0x59
46173 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46174 {
46175- struct attribute_group *attr_group;
46176+ attribute_group_no_const *attr_group;
46177 struct attribute **attributes;
46178 struct sm_sysfs_attribute *vendor_attribute;
46179 char *vendor;
46180diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46181index f847e16..fc8dbe9 100644
46182--- a/drivers/net/bonding/bond_netlink.c
46183+++ b/drivers/net/bonding/bond_netlink.c
46184@@ -542,7 +542,7 @@ nla_put_failure:
46185 return -EMSGSIZE;
46186 }
46187
46188-struct rtnl_link_ops bond_link_ops __read_mostly = {
46189+struct rtnl_link_ops bond_link_ops = {
46190 .kind = "bond",
46191 .priv_size = sizeof(struct bonding),
46192 .setup = bond_setup,
46193diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46194index 9e7d95d..d447b88 100644
46195--- a/drivers/net/can/Kconfig
46196+++ b/drivers/net/can/Kconfig
46197@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46198
46199 config CAN_FLEXCAN
46200 tristate "Support for Freescale FLEXCAN based chips"
46201- depends on ARM || PPC
46202+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46203 ---help---
46204 Say Y here if you want to support for Freescale FlexCAN.
46205
46206diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46207index 455d4c3..3353ee7 100644
46208--- a/drivers/net/ethernet/8390/ax88796.c
46209+++ b/drivers/net/ethernet/8390/ax88796.c
46210@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46211 if (ax->plat->reg_offsets)
46212 ei_local->reg_offset = ax->plat->reg_offsets;
46213 else {
46214+ resource_size_t _mem_size = mem_size;
46215+ do_div(_mem_size, 0x18);
46216 ei_local->reg_offset = ax->reg_offsets;
46217 for (ret = 0; ret < 0x18; ret++)
46218- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46219+ ax->reg_offsets[ret] = _mem_size * ret;
46220 }
46221
46222 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46223diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
46224index 7330681..7e9e463 100644
46225--- a/drivers/net/ethernet/altera/altera_tse_main.c
46226+++ b/drivers/net/ethernet/altera/altera_tse_main.c
46227@@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
46228 return 0;
46229 }
46230
46231-static struct net_device_ops altera_tse_netdev_ops = {
46232+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
46233 .ndo_open = tse_open,
46234 .ndo_stop = tse_shutdown,
46235 .ndo_start_xmit = tse_start_xmit,
46236@@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
46237 ndev->netdev_ops = &altera_tse_netdev_ops;
46238 altera_tse_set_ethtool_ops(ndev);
46239
46240+ pax_open_kernel();
46241 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
46242
46243 if (priv->hash_filter)
46244 altera_tse_netdev_ops.ndo_set_rx_mode =
46245 tse_set_rx_mode_hashfilter;
46246+ pax_close_kernel();
46247
46248 /* Scatter/gather IO is not supported,
46249 * so it is turned off
46250diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46251index 3448cc0..67b2dc4 100644
46252--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46253+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46254@@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46255 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46256 {
46257 /* RX_MODE controlling object */
46258- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46259+ bnx2x_init_rx_mode_obj(bp);
46260
46261 /* multicast configuration controlling object */
46262 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46263diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46264index 31297266..944cf6e 100644
46265--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46266+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46267@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46268 return rc;
46269 }
46270
46271-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46272- struct bnx2x_rx_mode_obj *o)
46273+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46274 {
46275 if (CHIP_IS_E1x(bp)) {
46276- o->wait_comp = bnx2x_empty_rx_mode_wait;
46277- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46278+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46279+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46280 } else {
46281- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46282- o->config_rx_mode = bnx2x_set_rx_mode_e2;
46283+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46284+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46285 }
46286 }
46287
46288diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46289index 80f6c79..fb7d12d 100644
46290--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46291+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46292@@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46293
46294 /********************* RX MODE ****************/
46295
46296-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46297- struct bnx2x_rx_mode_obj *o);
46298+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46299
46300 /**
46301 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46302diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46303index 6929adb..cc68830 100644
46304--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46305+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46306@@ -571,7 +571,7 @@ static inline void __iomem *bnx2x_vf_doorbells(struct bnx2x *bp)
46307 return NULL;
46308 }
46309
46310-static inline void bnx2x_vf_pci_dealloc(struct bnx2 *bp) {return 0; }
46311+static inline void bnx2x_vf_pci_dealloc(struct bnx2x *bp) { }
46312 static inline int bnx2x_vf_pci_alloc(struct bnx2x *bp) {return 0; }
46313 static inline void bnx2x_pf_set_vfs_vlan(struct bnx2x *bp) {}
46314 static inline int bnx2x_sriov_configure(struct pci_dev *dev, int num_vfs) {return 0; }
46315diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46316index 04321e5..b51cdc4 100644
46317--- a/drivers/net/ethernet/broadcom/tg3.h
46318+++ b/drivers/net/ethernet/broadcom/tg3.h
46319@@ -150,6 +150,7 @@
46320 #define CHIPREV_ID_5750_A0 0x4000
46321 #define CHIPREV_ID_5750_A1 0x4001
46322 #define CHIPREV_ID_5750_A3 0x4003
46323+#define CHIPREV_ID_5750_C1 0x4201
46324 #define CHIPREV_ID_5750_C2 0x4202
46325 #define CHIPREV_ID_5752_A0_HW 0x5000
46326 #define CHIPREV_ID_5752_A0 0x6000
46327diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46328index 13f9636..228040f 100644
46329--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46330+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46331@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46332 }
46333
46334 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46335- bna_cb_ioceth_enable,
46336- bna_cb_ioceth_disable,
46337- bna_cb_ioceth_hbfail,
46338- bna_cb_ioceth_reset
46339+ .enable_cbfn = bna_cb_ioceth_enable,
46340+ .disable_cbfn = bna_cb_ioceth_disable,
46341+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
46342+ .reset_cbfn = bna_cb_ioceth_reset
46343 };
46344
46345 static void bna_attr_init(struct bna_ioceth *ioceth)
46346diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46347index 8cffcdf..aadf043 100644
46348--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46349+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46350@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46351 */
46352 struct l2t_skb_cb {
46353 arp_failure_handler_func arp_failure_handler;
46354-};
46355+} __no_const;
46356
46357 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46358
46359diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46360index 24e16e3..bfe6ef2 100644
46361--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46362+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46363@@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46364
46365 int i;
46366 struct adapter *ap = netdev2adap(dev);
46367- static const unsigned int *reg_ranges;
46368+ const unsigned int *reg_ranges;
46369 int arr_size = 0, buf_size = 0;
46370
46371 if (is_t4(ap->params.chip)) {
46372diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46373index c05b66d..ed69872 100644
46374--- a/drivers/net/ethernet/dec/tulip/de4x5.c
46375+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46376@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46377 for (i=0; i<ETH_ALEN; i++) {
46378 tmp.addr[i] = dev->dev_addr[i];
46379 }
46380- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46381+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46382 break;
46383
46384 case DE4X5_SET_HWADDR: /* Set the hardware address */
46385@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46386 spin_lock_irqsave(&lp->lock, flags);
46387 memcpy(&statbuf, &lp->pktStats, ioc->len);
46388 spin_unlock_irqrestore(&lp->lock, flags);
46389- if (copy_to_user(ioc->data, &statbuf, ioc->len))
46390+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46391 return -EFAULT;
46392 break;
46393 }
46394diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46395index 2b5ab7c..20e2e7f 100644
46396--- a/drivers/net/ethernet/emulex/benet/be_main.c
46397+++ b/drivers/net/ethernet/emulex/benet/be_main.c
46398@@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46399
46400 if (wrapped)
46401 newacc += 65536;
46402- ACCESS_ONCE(*acc) = newacc;
46403+ ACCESS_ONCE_RW(*acc) = newacc;
46404 }
46405
46406 static void populate_erx_stats(struct be_adapter *adapter,
46407diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46408index 68069ea..c4484f6 100644
46409--- a/drivers/net/ethernet/faraday/ftgmac100.c
46410+++ b/drivers/net/ethernet/faraday/ftgmac100.c
46411@@ -30,6 +30,8 @@
46412 #include <linux/netdevice.h>
46413 #include <linux/phy.h>
46414 #include <linux/platform_device.h>
46415+#include <linux/interrupt.h>
46416+#include <linux/irqreturn.h>
46417 #include <net/ip.h>
46418
46419 #include "ftgmac100.h"
46420diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46421index 8be5b40..081bc1b 100644
46422--- a/drivers/net/ethernet/faraday/ftmac100.c
46423+++ b/drivers/net/ethernet/faraday/ftmac100.c
46424@@ -31,6 +31,8 @@
46425 #include <linux/module.h>
46426 #include <linux/netdevice.h>
46427 #include <linux/platform_device.h>
46428+#include <linux/interrupt.h>
46429+#include <linux/irqreturn.h>
46430
46431 #include "ftmac100.h"
46432
46433diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46434index e61e637..9117795 100644
46435--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46436+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46437@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46438 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46439
46440 /* Update the base adjustement value. */
46441- ACCESS_ONCE(pf->ptp_base_adj) = incval;
46442+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46443 smp_mb(); /* Force the above update. */
46444 }
46445
46446diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46447index 8902ae6..e7bcdce 100644
46448--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46449+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46450@@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46451 }
46452
46453 /* update the base incval used to calculate frequency adjustment */
46454- ACCESS_ONCE(adapter->base_incval) = incval;
46455+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
46456 smp_mb();
46457
46458 /* need lock to prevent incorrect read while modifying cyclecounter */
46459diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46460index 089b713..28d87ae 100644
46461--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46462+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46463@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46464 struct __vxge_hw_fifo *fifo;
46465 struct vxge_hw_fifo_config *config;
46466 u32 txdl_size, txdl_per_memblock;
46467- struct vxge_hw_mempool_cbs fifo_mp_callback;
46468+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46469+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46470+ };
46471+
46472 struct __vxge_hw_virtualpath *vpath;
46473
46474 if ((vp == NULL) || (attr == NULL)) {
46475@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46476 goto exit;
46477 }
46478
46479- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46480-
46481 fifo->mempool =
46482 __vxge_hw_mempool_create(vpath->hldev,
46483 fifo->config->memblock_size,
46484diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46485index ba20c72..f30c0fe 100644
46486--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46487+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46488@@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46489 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46490 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46491 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46492- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46493+ pax_open_kernel();
46494+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46495+ pax_close_kernel();
46496 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46497 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46498 max_tx_rings = QLCNIC_MAX_TX_RINGS;
46499diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46500index be7d7a6..a8983f8 100644
46501--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46502+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46503@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46504 case QLCNIC_NON_PRIV_FUNC:
46505 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46506 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46507- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46508+ pax_open_kernel();
46509+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46510+ pax_close_kernel();
46511 break;
46512 case QLCNIC_PRIV_FUNC:
46513 ahw->op_mode = QLCNIC_PRIV_FUNC;
46514 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46515- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46516+ pax_open_kernel();
46517+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46518+ pax_close_kernel();
46519 break;
46520 case QLCNIC_MGMT_FUNC:
46521 ahw->op_mode = QLCNIC_MGMT_FUNC;
46522 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46523- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46524+ pax_open_kernel();
46525+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46526+ pax_close_kernel();
46527 break;
46528 default:
46529 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46530diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46531index 37b979b..50f5b95 100644
46532--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46533+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46534@@ -1217,7 +1217,7 @@ flash_temp:
46535 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46536 {
46537 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46538- static const struct qlcnic_dump_operations *fw_dump_ops;
46539+ const struct qlcnic_dump_operations *fw_dump_ops;
46540 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46541 u32 entry_offset, dump, no_entries, buf_offset = 0;
46542 int i, k, ops_cnt, ops_index, dump_size = 0;
46543diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46544index aa1c079..2b1a3e8 100644
46545--- a/drivers/net/ethernet/realtek/r8169.c
46546+++ b/drivers/net/ethernet/realtek/r8169.c
46547@@ -758,22 +758,22 @@ struct rtl8169_private {
46548 struct mdio_ops {
46549 void (*write)(struct rtl8169_private *, int, int);
46550 int (*read)(struct rtl8169_private *, int);
46551- } mdio_ops;
46552+ } __no_const mdio_ops;
46553
46554 struct pll_power_ops {
46555 void (*down)(struct rtl8169_private *);
46556 void (*up)(struct rtl8169_private *);
46557- } pll_power_ops;
46558+ } __no_const pll_power_ops;
46559
46560 struct jumbo_ops {
46561 void (*enable)(struct rtl8169_private *);
46562 void (*disable)(struct rtl8169_private *);
46563- } jumbo_ops;
46564+ } __no_const jumbo_ops;
46565
46566 struct csi_ops {
46567 void (*write)(struct rtl8169_private *, int, int);
46568 u32 (*read)(struct rtl8169_private *, int);
46569- } csi_ops;
46570+ } __no_const csi_ops;
46571
46572 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46573 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46574diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46575index 6b861e3..204ac86 100644
46576--- a/drivers/net/ethernet/sfc/ptp.c
46577+++ b/drivers/net/ethernet/sfc/ptp.c
46578@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46579 ptp->start.dma_addr);
46580
46581 /* Clear flag that signals MC ready */
46582- ACCESS_ONCE(*start) = 0;
46583+ ACCESS_ONCE_RW(*start) = 0;
46584 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46585 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46586 EFX_BUG_ON_PARANOID(rc);
46587diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46588index 50617c5..b13724c 100644
46589--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46590+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46591@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46592
46593 writel(value, ioaddr + MMC_CNTRL);
46594
46595- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46596- MMC_CNTRL, value);
46597+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46598+// MMC_CNTRL, value);
46599 }
46600
46601 /* To mask all all interrupts.*/
46602diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46603index d18f711d..5755800 100644
46604--- a/drivers/net/hyperv/hyperv_net.h
46605+++ b/drivers/net/hyperv/hyperv_net.h
46606@@ -101,7 +101,7 @@ struct rndis_device {
46607
46608 enum rndis_device_state state;
46609 bool link_state;
46610- atomic_t new_req_id;
46611+ atomic_unchecked_t new_req_id;
46612
46613 spinlock_t request_lock;
46614 struct list_head req_list;
46615diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46616index 143a98c..d54fbaa 100644
46617--- a/drivers/net/hyperv/rndis_filter.c
46618+++ b/drivers/net/hyperv/rndis_filter.c
46619@@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46620 * template
46621 */
46622 set = &rndis_msg->msg.set_req;
46623- set->req_id = atomic_inc_return(&dev->new_req_id);
46624+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46625
46626 /* Add to the request list */
46627 spin_lock_irqsave(&dev->request_lock, flags);
46628@@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46629
46630 /* Setup the rndis set */
46631 halt = &request->request_msg.msg.halt_req;
46632- halt->req_id = atomic_inc_return(&dev->new_req_id);
46633+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46634
46635 /* Ignore return since this msg is optional. */
46636 rndis_filter_send_request(dev, request);
46637diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46638index 78f18be..1d19c62 100644
46639--- a/drivers/net/ieee802154/fakehard.c
46640+++ b/drivers/net/ieee802154/fakehard.c
46641@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46642 phy->transmit_power = 0xbf;
46643
46644 dev->netdev_ops = &fake_ops;
46645- dev->ml_priv = &fake_mlme;
46646+ dev->ml_priv = (void *)&fake_mlme;
46647
46648 priv = netdev_priv(dev);
46649 priv->phy = phy;
46650diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46651index d650b91..7717c68 100644
46652--- a/drivers/net/macvlan.c
46653+++ b/drivers/net/macvlan.c
46654@@ -985,13 +985,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46655 int macvlan_link_register(struct rtnl_link_ops *ops)
46656 {
46657 /* common fields */
46658- ops->priv_size = sizeof(struct macvlan_dev);
46659- ops->validate = macvlan_validate;
46660- ops->maxtype = IFLA_MACVLAN_MAX;
46661- ops->policy = macvlan_policy;
46662- ops->changelink = macvlan_changelink;
46663- ops->get_size = macvlan_get_size;
46664- ops->fill_info = macvlan_fill_info;
46665+ pax_open_kernel();
46666+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46667+ *(void **)&ops->validate = macvlan_validate;
46668+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46669+ *(const void **)&ops->policy = macvlan_policy;
46670+ *(void **)&ops->changelink = macvlan_changelink;
46671+ *(void **)&ops->get_size = macvlan_get_size;
46672+ *(void **)&ops->fill_info = macvlan_fill_info;
46673+ pax_close_kernel();
46674
46675 return rtnl_link_register(ops);
46676 };
46677@@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46678 return NOTIFY_DONE;
46679 }
46680
46681-static struct notifier_block macvlan_notifier_block __read_mostly = {
46682+static struct notifier_block macvlan_notifier_block = {
46683 .notifier_call = macvlan_device_event,
46684 };
46685
46686diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46687index 3381c4f..dea5fd5 100644
46688--- a/drivers/net/macvtap.c
46689+++ b/drivers/net/macvtap.c
46690@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46691 }
46692
46693 ret = 0;
46694- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46695+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46696 put_user(q->flags, &ifr->ifr_flags))
46697 ret = -EFAULT;
46698 macvtap_put_vlan(vlan);
46699@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46700 return NOTIFY_DONE;
46701 }
46702
46703-static struct notifier_block macvtap_notifier_block __read_mostly = {
46704+static struct notifier_block macvtap_notifier_block = {
46705 .notifier_call = macvtap_device_event,
46706 };
46707
46708diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46709index 3c41a83..5fe2d7f 100644
46710--- a/drivers/net/ppp/ppp_generic.c
46711+++ b/drivers/net/ppp/ppp_generic.c
46712@@ -1016,7 +1016,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46713 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46714 struct ppp_stats stats;
46715 struct ppp_comp_stats cstats;
46716- char *vers;
46717
46718 switch (cmd) {
46719 case SIOCGPPPSTATS:
46720@@ -1038,8 +1037,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46721 break;
46722
46723 case SIOCGPPPVER:
46724- vers = PPP_VERSION;
46725- if (copy_to_user(addr, vers, strlen(vers) + 1))
46726+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46727 break;
46728 err = 0;
46729 break;
46730diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46731index 1252d9c..80e660b 100644
46732--- a/drivers/net/slip/slhc.c
46733+++ b/drivers/net/slip/slhc.c
46734@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46735 register struct tcphdr *thp;
46736 register struct iphdr *ip;
46737 register struct cstate *cs;
46738- int len, hdrlen;
46739+ long len, hdrlen;
46740 unsigned char *cp = icp;
46741
46742 /* We've got a compressed packet; read the change byte */
46743diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46744index ce4989b..b40b328 100644
46745--- a/drivers/net/team/team.c
46746+++ b/drivers/net/team/team.c
46747@@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46748 return NOTIFY_DONE;
46749 }
46750
46751-static struct notifier_block team_notifier_block __read_mostly = {
46752+static struct notifier_block team_notifier_block = {
46753 .notifier_call = team_device_event,
46754 };
46755
46756diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46757index ee328ba..c4a0041 100644
46758--- a/drivers/net/tun.c
46759+++ b/drivers/net/tun.c
46760@@ -1876,7 +1876,7 @@ unlock:
46761 }
46762
46763 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46764- unsigned long arg, int ifreq_len)
46765+ unsigned long arg, size_t ifreq_len)
46766 {
46767 struct tun_file *tfile = file->private_data;
46768 struct tun_struct *tun;
46769@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46770 unsigned int ifindex;
46771 int ret;
46772
46773+ if (ifreq_len > sizeof ifr)
46774+ return -EFAULT;
46775+
46776 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46777 if (copy_from_user(&ifr, argp, ifreq_len))
46778 return -EFAULT;
46779diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46780index 660bd5e..ac59452 100644
46781--- a/drivers/net/usb/hso.c
46782+++ b/drivers/net/usb/hso.c
46783@@ -71,7 +71,7 @@
46784 #include <asm/byteorder.h>
46785 #include <linux/serial_core.h>
46786 #include <linux/serial.h>
46787-
46788+#include <asm/local.h>
46789
46790 #define MOD_AUTHOR "Option Wireless"
46791 #define MOD_DESCRIPTION "USB High Speed Option driver"
46792@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46793 struct urb *urb;
46794
46795 urb = serial->rx_urb[0];
46796- if (serial->port.count > 0) {
46797+ if (atomic_read(&serial->port.count) > 0) {
46798 count = put_rxbuf_data(urb, serial);
46799 if (count == -1)
46800 return;
46801@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46802 DUMP1(urb->transfer_buffer, urb->actual_length);
46803
46804 /* Anyone listening? */
46805- if (serial->port.count == 0)
46806+ if (atomic_read(&serial->port.count) == 0)
46807 return;
46808
46809 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46810@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46811 tty_port_tty_set(&serial->port, tty);
46812
46813 /* check for port already opened, if not set the termios */
46814- serial->port.count++;
46815- if (serial->port.count == 1) {
46816+ if (atomic_inc_return(&serial->port.count) == 1) {
46817 serial->rx_state = RX_IDLE;
46818 /* Force default termio settings */
46819 _hso_serial_set_termios(tty, NULL);
46820@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46821 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46822 if (result) {
46823 hso_stop_serial_device(serial->parent);
46824- serial->port.count--;
46825+ atomic_dec(&serial->port.count);
46826 kref_put(&serial->parent->ref, hso_serial_ref_free);
46827 }
46828 } else {
46829@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46830
46831 /* reset the rts and dtr */
46832 /* do the actual close */
46833- serial->port.count--;
46834+ atomic_dec(&serial->port.count);
46835
46836- if (serial->port.count <= 0) {
46837- serial->port.count = 0;
46838+ if (atomic_read(&serial->port.count) <= 0) {
46839+ atomic_set(&serial->port.count, 0);
46840 tty_port_tty_set(&serial->port, NULL);
46841 if (!usb_gone)
46842 hso_stop_serial_device(serial->parent);
46843@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46844
46845 /* the actual setup */
46846 spin_lock_irqsave(&serial->serial_lock, flags);
46847- if (serial->port.count)
46848+ if (atomic_read(&serial->port.count))
46849 _hso_serial_set_termios(tty, old);
46850 else
46851 tty->termios = *old;
46852@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46853 D1("Pending read interrupt on port %d\n", i);
46854 spin_lock(&serial->serial_lock);
46855 if (serial->rx_state == RX_IDLE &&
46856- serial->port.count > 0) {
46857+ atomic_read(&serial->port.count) > 0) {
46858 /* Setup and send a ctrl req read on
46859 * port i */
46860 if (!serial->rx_urb_filled[0]) {
46861@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46862 /* Start all serial ports */
46863 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46864 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46865- if (dev2ser(serial_table[i])->port.count) {
46866+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46867 result =
46868 hso_start_serial_device(serial_table[i], GFP_NOIO);
46869 hso_kick_transmit(dev2ser(serial_table[i]));
46870diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46871index d2c0070..3c3da43 100644
46872--- a/drivers/net/usb/r8152.c
46873+++ b/drivers/net/usb/r8152.c
46874@@ -567,7 +567,7 @@ struct r8152 {
46875 void (*up)(struct r8152 *);
46876 void (*down)(struct r8152 *);
46877 void (*unload)(struct r8152 *);
46878- } rtl_ops;
46879+ } __no_const rtl_ops;
46880
46881 int intr_interval;
46882 u32 saved_wolopts;
46883diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46884index a2515887..6d13233 100644
46885--- a/drivers/net/usb/sierra_net.c
46886+++ b/drivers/net/usb/sierra_net.c
46887@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46888 /* atomic counter partially included in MAC address to make sure 2 devices
46889 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46890 */
46891-static atomic_t iface_counter = ATOMIC_INIT(0);
46892+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46893
46894 /*
46895 * SYNC Timer Delay definition used to set the expiry time
46896@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46897 dev->net->netdev_ops = &sierra_net_device_ops;
46898
46899 /* change MAC addr to include, ifacenum, and to be unique */
46900- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46901+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46902 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46903
46904 /* we will have to manufacture ethernet headers, prepare template */
46905diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
46906index 8a852b5..668a4b6 100644
46907--- a/drivers/net/virtio_net.c
46908+++ b/drivers/net/virtio_net.c
46909@@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
46910 #define RECEIVE_AVG_WEIGHT 64
46911
46912 /* Minimum alignment for mergeable packet buffers. */
46913-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
46914+#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
46915
46916 #define VIRTNET_DRIVER_VERSION "1.0.0"
46917
46918diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46919index 77dcf92..549924a 100644
46920--- a/drivers/net/vxlan.c
46921+++ b/drivers/net/vxlan.c
46922@@ -2839,7 +2839,7 @@ nla_put_failure:
46923 return -EMSGSIZE;
46924 }
46925
46926-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46927+static struct rtnl_link_ops vxlan_link_ops = {
46928 .kind = "vxlan",
46929 .maxtype = IFLA_VXLAN_MAX,
46930 .policy = vxlan_policy,
46931@@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46932 return NOTIFY_DONE;
46933 }
46934
46935-static struct notifier_block vxlan_notifier_block __read_mostly = {
46936+static struct notifier_block vxlan_notifier_block = {
46937 .notifier_call = vxlan_lowerdev_event,
46938 };
46939
46940diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46941index 5920c99..ff2e4a5 100644
46942--- a/drivers/net/wan/lmc/lmc_media.c
46943+++ b/drivers/net/wan/lmc/lmc_media.c
46944@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46945 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46946
46947 lmc_media_t lmc_ds3_media = {
46948- lmc_ds3_init, /* special media init stuff */
46949- lmc_ds3_default, /* reset to default state */
46950- lmc_ds3_set_status, /* reset status to state provided */
46951- lmc_dummy_set_1, /* set clock source */
46952- lmc_dummy_set2_1, /* set line speed */
46953- lmc_ds3_set_100ft, /* set cable length */
46954- lmc_ds3_set_scram, /* set scrambler */
46955- lmc_ds3_get_link_status, /* get link status */
46956- lmc_dummy_set_1, /* set link status */
46957- lmc_ds3_set_crc_length, /* set CRC length */
46958- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46959- lmc_ds3_watchdog
46960+ .init = lmc_ds3_init, /* special media init stuff */
46961+ .defaults = lmc_ds3_default, /* reset to default state */
46962+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46963+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46964+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46965+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46966+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46967+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46968+ .set_link_status = lmc_dummy_set_1, /* set link status */
46969+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46970+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46971+ .watchdog = lmc_ds3_watchdog
46972 };
46973
46974 lmc_media_t lmc_hssi_media = {
46975- lmc_hssi_init, /* special media init stuff */
46976- lmc_hssi_default, /* reset to default state */
46977- lmc_hssi_set_status, /* reset status to state provided */
46978- lmc_hssi_set_clock, /* set clock source */
46979- lmc_dummy_set2_1, /* set line speed */
46980- lmc_dummy_set_1, /* set cable length */
46981- lmc_dummy_set_1, /* set scrambler */
46982- lmc_hssi_get_link_status, /* get link status */
46983- lmc_hssi_set_link_status, /* set link status */
46984- lmc_hssi_set_crc_length, /* set CRC length */
46985- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46986- lmc_hssi_watchdog
46987+ .init = lmc_hssi_init, /* special media init stuff */
46988+ .defaults = lmc_hssi_default, /* reset to default state */
46989+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46990+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46991+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46992+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46993+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46994+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46995+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46996+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46997+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46998+ .watchdog = lmc_hssi_watchdog
46999 };
47000
47001-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
47002- lmc_ssi_default, /* reset to default state */
47003- lmc_ssi_set_status, /* reset status to state provided */
47004- lmc_ssi_set_clock, /* set clock source */
47005- lmc_ssi_set_speed, /* set line speed */
47006- lmc_dummy_set_1, /* set cable length */
47007- lmc_dummy_set_1, /* set scrambler */
47008- lmc_ssi_get_link_status, /* get link status */
47009- lmc_ssi_set_link_status, /* set link status */
47010- lmc_ssi_set_crc_length, /* set CRC length */
47011- lmc_dummy_set_1, /* set T1 or E1 circuit type */
47012- lmc_ssi_watchdog
47013+lmc_media_t lmc_ssi_media = {
47014+ .init = lmc_ssi_init, /* special media init stuff */
47015+ .defaults = lmc_ssi_default, /* reset to default state */
47016+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
47017+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
47018+ .set_speed = lmc_ssi_set_speed, /* set line speed */
47019+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47020+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47021+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
47022+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
47023+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
47024+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47025+ .watchdog = lmc_ssi_watchdog
47026 };
47027
47028 lmc_media_t lmc_t1_media = {
47029- lmc_t1_init, /* special media init stuff */
47030- lmc_t1_default, /* reset to default state */
47031- lmc_t1_set_status, /* reset status to state provided */
47032- lmc_t1_set_clock, /* set clock source */
47033- lmc_dummy_set2_1, /* set line speed */
47034- lmc_dummy_set_1, /* set cable length */
47035- lmc_dummy_set_1, /* set scrambler */
47036- lmc_t1_get_link_status, /* get link status */
47037- lmc_dummy_set_1, /* set link status */
47038- lmc_t1_set_crc_length, /* set CRC length */
47039- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47040- lmc_t1_watchdog
47041+ .init = lmc_t1_init, /* special media init stuff */
47042+ .defaults = lmc_t1_default, /* reset to default state */
47043+ .set_status = lmc_t1_set_status, /* reset status to state provided */
47044+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
47045+ .set_speed = lmc_dummy_set2_1, /* set line speed */
47046+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47047+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47048+ .get_link_status = lmc_t1_get_link_status, /* get link status */
47049+ .set_link_status = lmc_dummy_set_1, /* set link status */
47050+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
47051+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47052+ .watchdog = lmc_t1_watchdog
47053 };
47054
47055 static void
47056diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
47057index 5895f19..fa9fdfa 100644
47058--- a/drivers/net/wan/x25_asy.c
47059+++ b/drivers/net/wan/x25_asy.c
47060@@ -122,8 +122,12 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu)
47061 {
47062 struct x25_asy *sl = netdev_priv(dev);
47063 unsigned char *xbuff, *rbuff;
47064- int len = 2 * newmtu;
47065+ int len;
47066
47067+ if (newmtu > 65534)
47068+ return -EINVAL;
47069+
47070+ len = 2 * newmtu;
47071 xbuff = kmalloc(len + 4, GFP_ATOMIC);
47072 rbuff = kmalloc(len + 4, GFP_ATOMIC);
47073
47074diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
47075index feacc3b..5bac0de 100644
47076--- a/drivers/net/wan/z85230.c
47077+++ b/drivers/net/wan/z85230.c
47078@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
47079
47080 struct z8530_irqhandler z8530_sync =
47081 {
47082- z8530_rx,
47083- z8530_tx,
47084- z8530_status
47085+ .rx = z8530_rx,
47086+ .tx = z8530_tx,
47087+ .status = z8530_status
47088 };
47089
47090 EXPORT_SYMBOL(z8530_sync);
47091@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
47092 }
47093
47094 static struct z8530_irqhandler z8530_dma_sync = {
47095- z8530_dma_rx,
47096- z8530_dma_tx,
47097- z8530_dma_status
47098+ .rx = z8530_dma_rx,
47099+ .tx = z8530_dma_tx,
47100+ .status = z8530_dma_status
47101 };
47102
47103 static struct z8530_irqhandler z8530_txdma_sync = {
47104- z8530_rx,
47105- z8530_dma_tx,
47106- z8530_dma_status
47107+ .rx = z8530_rx,
47108+ .tx = z8530_dma_tx,
47109+ .status = z8530_dma_status
47110 };
47111
47112 /**
47113@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47114
47115 struct z8530_irqhandler z8530_nop=
47116 {
47117- z8530_rx_clear,
47118- z8530_tx_clear,
47119- z8530_status_clear
47120+ .rx = z8530_rx_clear,
47121+ .tx = z8530_tx_clear,
47122+ .status = z8530_status_clear
47123 };
47124
47125
47126diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47127index 0b60295..b8bfa5b 100644
47128--- a/drivers/net/wimax/i2400m/rx.c
47129+++ b/drivers/net/wimax/i2400m/rx.c
47130@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47131 if (i2400m->rx_roq == NULL)
47132 goto error_roq_alloc;
47133
47134- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47135+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47136 GFP_KERNEL);
47137 if (rd == NULL) {
47138 result = -ENOMEM;
47139diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47140index 64747d4..17c4cf3 100644
47141--- a/drivers/net/wireless/airo.c
47142+++ b/drivers/net/wireless/airo.c
47143@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47144 struct airo_info *ai = dev->ml_priv;
47145 int ridcode;
47146 int enabled;
47147- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47148+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47149 unsigned char *iobuf;
47150
47151 /* Only super-user can write RIDs */
47152diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47153index 99b3bfa..9559372 100644
47154--- a/drivers/net/wireless/at76c50x-usb.c
47155+++ b/drivers/net/wireless/at76c50x-usb.c
47156@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47157 }
47158
47159 /* Convert timeout from the DFU status to jiffies */
47160-static inline unsigned long at76_get_timeout(struct dfu_status *s)
47161+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47162 {
47163 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47164 | (s->poll_timeout[1] << 8)
47165diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47166index 7f1bccd..ca2ffca 100644
47167--- a/drivers/net/wireless/ath/ath10k/htc.c
47168+++ b/drivers/net/wireless/ath/ath10k/htc.c
47169@@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47170 /* registered target arrival callback from the HIF layer */
47171 int ath10k_htc_init(struct ath10k *ar)
47172 {
47173- struct ath10k_hif_cb htc_callbacks;
47174+ static struct ath10k_hif_cb htc_callbacks = {
47175+ .rx_completion = ath10k_htc_rx_completion_handler,
47176+ .tx_completion = ath10k_htc_tx_completion_handler,
47177+ };
47178 struct ath10k_htc_ep *ep = NULL;
47179 struct ath10k_htc *htc = &ar->htc;
47180
47181@@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
47182 ath10k_htc_reset_endpoint_states(htc);
47183
47184 /* setup HIF layer callbacks */
47185- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47186- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47187 htc->ar = ar;
47188
47189 /* Get HIF default pipe for HTC message exchange */
47190diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47191index 4716d33..a688310 100644
47192--- a/drivers/net/wireless/ath/ath10k/htc.h
47193+++ b/drivers/net/wireless/ath/ath10k/htc.h
47194@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47195
47196 struct ath10k_htc_ops {
47197 void (*target_send_suspend_complete)(struct ath10k *ar);
47198-};
47199+} __no_const;
47200
47201 struct ath10k_htc_ep_ops {
47202 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47203 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47204 void (*ep_tx_credits)(struct ath10k *);
47205-};
47206+} __no_const;
47207
47208 /* service connection information */
47209 struct ath10k_htc_svc_conn_req {
47210diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47211index 741b38d..b7ae41b 100644
47212--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47213+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47214@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47215 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47216 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47217
47218- ACCESS_ONCE(ads->ds_link) = i->link;
47219- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47220+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
47221+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47222
47223 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47224 ctl6 = SM(i->keytype, AR_EncrType);
47225@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47226
47227 if ((i->is_first || i->is_last) &&
47228 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47229- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47230+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47231 | set11nTries(i->rates, 1)
47232 | set11nTries(i->rates, 2)
47233 | set11nTries(i->rates, 3)
47234 | (i->dur_update ? AR_DurUpdateEna : 0)
47235 | SM(0, AR_BurstDur);
47236
47237- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47238+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47239 | set11nRate(i->rates, 1)
47240 | set11nRate(i->rates, 2)
47241 | set11nRate(i->rates, 3);
47242 } else {
47243- ACCESS_ONCE(ads->ds_ctl2) = 0;
47244- ACCESS_ONCE(ads->ds_ctl3) = 0;
47245+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47246+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47247 }
47248
47249 if (!i->is_first) {
47250- ACCESS_ONCE(ads->ds_ctl0) = 0;
47251- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47252- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47253+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47254+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47255+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47256 return;
47257 }
47258
47259@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47260 break;
47261 }
47262
47263- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47264+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47265 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47266 | SM(i->txpower, AR_XmitPower)
47267 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47268@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47269 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47270 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47271
47272- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47273- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47274+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47275+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47276
47277 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47278 return;
47279
47280- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47281+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47282 | set11nPktDurRTSCTS(i->rates, 1);
47283
47284- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47285+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47286 | set11nPktDurRTSCTS(i->rates, 3);
47287
47288- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47289+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47290 | set11nRateFlags(i->rates, 1)
47291 | set11nRateFlags(i->rates, 2)
47292 | set11nRateFlags(i->rates, 3)
47293diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47294index 729ffbf..49f50e3 100644
47295--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47296+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47297@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47298 (i->qcu << AR_TxQcuNum_S) | desc_len;
47299
47300 checksum += val;
47301- ACCESS_ONCE(ads->info) = val;
47302+ ACCESS_ONCE_RW(ads->info) = val;
47303
47304 checksum += i->link;
47305- ACCESS_ONCE(ads->link) = i->link;
47306+ ACCESS_ONCE_RW(ads->link) = i->link;
47307
47308 checksum += i->buf_addr[0];
47309- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47310+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47311 checksum += i->buf_addr[1];
47312- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47313+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47314 checksum += i->buf_addr[2];
47315- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47316+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47317 checksum += i->buf_addr[3];
47318- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47319+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47320
47321 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47322- ACCESS_ONCE(ads->ctl3) = val;
47323+ ACCESS_ONCE_RW(ads->ctl3) = val;
47324 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47325- ACCESS_ONCE(ads->ctl5) = val;
47326+ ACCESS_ONCE_RW(ads->ctl5) = val;
47327 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47328- ACCESS_ONCE(ads->ctl7) = val;
47329+ ACCESS_ONCE_RW(ads->ctl7) = val;
47330 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47331- ACCESS_ONCE(ads->ctl9) = val;
47332+ ACCESS_ONCE_RW(ads->ctl9) = val;
47333
47334 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47335- ACCESS_ONCE(ads->ctl10) = checksum;
47336+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
47337
47338 if (i->is_first || i->is_last) {
47339- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47340+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47341 | set11nTries(i->rates, 1)
47342 | set11nTries(i->rates, 2)
47343 | set11nTries(i->rates, 3)
47344 | (i->dur_update ? AR_DurUpdateEna : 0)
47345 | SM(0, AR_BurstDur);
47346
47347- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47348+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47349 | set11nRate(i->rates, 1)
47350 | set11nRate(i->rates, 2)
47351 | set11nRate(i->rates, 3);
47352 } else {
47353- ACCESS_ONCE(ads->ctl13) = 0;
47354- ACCESS_ONCE(ads->ctl14) = 0;
47355+ ACCESS_ONCE_RW(ads->ctl13) = 0;
47356+ ACCESS_ONCE_RW(ads->ctl14) = 0;
47357 }
47358
47359 ads->ctl20 = 0;
47360@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47361
47362 ctl17 = SM(i->keytype, AR_EncrType);
47363 if (!i->is_first) {
47364- ACCESS_ONCE(ads->ctl11) = 0;
47365- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47366- ACCESS_ONCE(ads->ctl15) = 0;
47367- ACCESS_ONCE(ads->ctl16) = 0;
47368- ACCESS_ONCE(ads->ctl17) = ctl17;
47369- ACCESS_ONCE(ads->ctl18) = 0;
47370- ACCESS_ONCE(ads->ctl19) = 0;
47371+ ACCESS_ONCE_RW(ads->ctl11) = 0;
47372+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47373+ ACCESS_ONCE_RW(ads->ctl15) = 0;
47374+ ACCESS_ONCE_RW(ads->ctl16) = 0;
47375+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47376+ ACCESS_ONCE_RW(ads->ctl18) = 0;
47377+ ACCESS_ONCE_RW(ads->ctl19) = 0;
47378 return;
47379 }
47380
47381- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47382+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47383 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47384 | SM(i->txpower, AR_XmitPower)
47385 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47386@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47387 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47388 ctl12 |= SM(val, AR_PAPRDChainMask);
47389
47390- ACCESS_ONCE(ads->ctl12) = ctl12;
47391- ACCESS_ONCE(ads->ctl17) = ctl17;
47392+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47393+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47394
47395- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47396+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47397 | set11nPktDurRTSCTS(i->rates, 1);
47398
47399- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47400+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47401 | set11nPktDurRTSCTS(i->rates, 3);
47402
47403- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47404+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47405 | set11nRateFlags(i->rates, 1)
47406 | set11nRateFlags(i->rates, 2)
47407 | set11nRateFlags(i->rates, 3)
47408 | SM(i->rtscts_rate, AR_RTSCTSRate);
47409
47410- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47411+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47412 }
47413
47414 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47415diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47416index 0acd4b5..0591c91 100644
47417--- a/drivers/net/wireless/ath/ath9k/hw.h
47418+++ b/drivers/net/wireless/ath/ath9k/hw.h
47419@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47420
47421 /* ANI */
47422 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47423-};
47424+} __no_const;
47425
47426 /**
47427 * struct ath_spec_scan - parameters for Atheros spectral scan
47428@@ -706,7 +706,7 @@ struct ath_hw_ops {
47429 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47430 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47431 #endif
47432-};
47433+} __no_const;
47434
47435 struct ath_nf_limits {
47436 s16 max;
47437diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47438index 92190da..f3a4c4c 100644
47439--- a/drivers/net/wireless/b43/phy_lp.c
47440+++ b/drivers/net/wireless/b43/phy_lp.c
47441@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47442 {
47443 struct ssb_bus *bus = dev->dev->sdev->bus;
47444
47445- static const struct b206x_channel *chandata = NULL;
47446+ const struct b206x_channel *chandata = NULL;
47447 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47448 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47449 u16 old_comm15, scale;
47450diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47451index dc1d20c..f7a4f06 100644
47452--- a/drivers/net/wireless/iwlegacy/3945-mac.c
47453+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47454@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47455 */
47456 if (il3945_mod_params.disable_hw_scan) {
47457 D_INFO("Disabling hw_scan\n");
47458- il3945_mac_ops.hw_scan = NULL;
47459+ pax_open_kernel();
47460+ *(void **)&il3945_mac_ops.hw_scan = NULL;
47461+ pax_close_kernel();
47462 }
47463
47464 D_INFO("*** LOAD DRIVER ***\n");
47465diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47466index d2fe259..0c4c682 100644
47467--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47468+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47469@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47470 {
47471 struct iwl_priv *priv = file->private_data;
47472 char buf[64];
47473- int buf_size;
47474+ size_t buf_size;
47475 u32 offset, len;
47476
47477 memset(buf, 0, sizeof(buf));
47478@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47479 struct iwl_priv *priv = file->private_data;
47480
47481 char buf[8];
47482- int buf_size;
47483+ size_t buf_size;
47484 u32 reset_flag;
47485
47486 memset(buf, 0, sizeof(buf));
47487@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47488 {
47489 struct iwl_priv *priv = file->private_data;
47490 char buf[8];
47491- int buf_size;
47492+ size_t buf_size;
47493 int ht40;
47494
47495 memset(buf, 0, sizeof(buf));
47496@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47497 {
47498 struct iwl_priv *priv = file->private_data;
47499 char buf[8];
47500- int buf_size;
47501+ size_t buf_size;
47502 int value;
47503
47504 memset(buf, 0, sizeof(buf));
47505@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47506 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47507 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47508
47509-static const char *fmt_value = " %-30s %10u\n";
47510-static const char *fmt_hex = " %-30s 0x%02X\n";
47511-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47512-static const char *fmt_header =
47513+static const char fmt_value[] = " %-30s %10u\n";
47514+static const char fmt_hex[] = " %-30s 0x%02X\n";
47515+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47516+static const char fmt_header[] =
47517 "%-32s current cumulative delta max\n";
47518
47519 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47520@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47521 {
47522 struct iwl_priv *priv = file->private_data;
47523 char buf[8];
47524- int buf_size;
47525+ size_t buf_size;
47526 int clear;
47527
47528 memset(buf, 0, sizeof(buf));
47529@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47530 {
47531 struct iwl_priv *priv = file->private_data;
47532 char buf[8];
47533- int buf_size;
47534+ size_t buf_size;
47535 int trace;
47536
47537 memset(buf, 0, sizeof(buf));
47538@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47539 {
47540 struct iwl_priv *priv = file->private_data;
47541 char buf[8];
47542- int buf_size;
47543+ size_t buf_size;
47544 int missed;
47545
47546 memset(buf, 0, sizeof(buf));
47547@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47548
47549 struct iwl_priv *priv = file->private_data;
47550 char buf[8];
47551- int buf_size;
47552+ size_t buf_size;
47553 int plcp;
47554
47555 memset(buf, 0, sizeof(buf));
47556@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47557
47558 struct iwl_priv *priv = file->private_data;
47559 char buf[8];
47560- int buf_size;
47561+ size_t buf_size;
47562 int flush;
47563
47564 memset(buf, 0, sizeof(buf));
47565@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47566
47567 struct iwl_priv *priv = file->private_data;
47568 char buf[8];
47569- int buf_size;
47570+ size_t buf_size;
47571 int rts;
47572
47573 if (!priv->cfg->ht_params)
47574@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47575 {
47576 struct iwl_priv *priv = file->private_data;
47577 char buf[8];
47578- int buf_size;
47579+ size_t buf_size;
47580
47581 memset(buf, 0, sizeof(buf));
47582 buf_size = min(count, sizeof(buf) - 1);
47583@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47584 struct iwl_priv *priv = file->private_data;
47585 u32 event_log_flag;
47586 char buf[8];
47587- int buf_size;
47588+ size_t buf_size;
47589
47590 /* check that the interface is up */
47591 if (!iwl_is_ready(priv))
47592@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47593 struct iwl_priv *priv = file->private_data;
47594 char buf[8];
47595 u32 calib_disabled;
47596- int buf_size;
47597+ size_t buf_size;
47598
47599 memset(buf, 0, sizeof(buf));
47600 buf_size = min(count, sizeof(buf) - 1);
47601diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47602index 6a6df71..eb5c93a 100644
47603--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47604+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47605@@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47606 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47607 {
47608 struct iwl_nvm_data *data = priv->nvm_data;
47609- char *debug_msg;
47610+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47611
47612 if (data->sku_cap_11n_enable &&
47613 !priv->cfg->ht_params) {
47614@@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47615 return -EINVAL;
47616 }
47617
47618- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47619 IWL_DEBUG_INFO(priv, debug_msg,
47620 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47621 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47622diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47623index 295b24c..cb4f823 100644
47624--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47625+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47626@@ -1558,7 +1558,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47627 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47628
47629 char buf[8];
47630- int buf_size;
47631+ size_t buf_size;
47632 u32 reset_flag;
47633
47634 memset(buf, 0, sizeof(buf));
47635@@ -1579,7 +1579,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47636 {
47637 struct iwl_trans *trans = file->private_data;
47638 char buf[8];
47639- int buf_size;
47640+ size_t buf_size;
47641 int csr;
47642
47643 memset(buf, 0, sizeof(buf));
47644diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47645index 9d7a52f..2729a99 100644
47646--- a/drivers/net/wireless/mac80211_hwsim.c
47647+++ b/drivers/net/wireless/mac80211_hwsim.c
47648@@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47649 if (channels < 1)
47650 return -EINVAL;
47651
47652- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47653- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47654- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47655- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47656- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47657- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47658- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47659- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47660- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47661- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47662- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47663- mac80211_hwsim_assign_vif_chanctx;
47664- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47665- mac80211_hwsim_unassign_vif_chanctx;
47666+ pax_open_kernel();
47667+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47668+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47669+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47670+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47671+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47672+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47673+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47674+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47675+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47676+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47677+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47678+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47679+ pax_close_kernel();
47680
47681 spin_lock_init(&hwsim_radio_lock);
47682 INIT_LIST_HEAD(&hwsim_radios);
47683diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47684index 39d22a1..4ec8612 100644
47685--- a/drivers/net/wireless/rndis_wlan.c
47686+++ b/drivers/net/wireless/rndis_wlan.c
47687@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47688
47689 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47690
47691- if (rts_threshold < 0 || rts_threshold > 2347)
47692+ if (rts_threshold > 2347)
47693 rts_threshold = 2347;
47694
47695 tmp = cpu_to_le32(rts_threshold);
47696diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47697index 5d45a1a..6f5f041 100644
47698--- a/drivers/net/wireless/rt2x00/rt2x00.h
47699+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47700@@ -375,7 +375,7 @@ struct rt2x00_intf {
47701 * for hardware which doesn't support hardware
47702 * sequence counting.
47703 */
47704- atomic_t seqno;
47705+ atomic_unchecked_t seqno;
47706 };
47707
47708 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47709diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47710index 5642ccc..01f03eb 100644
47711--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47712+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47713@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47714 * sequence counter given by mac80211.
47715 */
47716 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47717- seqno = atomic_add_return(0x10, &intf->seqno);
47718+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47719 else
47720- seqno = atomic_read(&intf->seqno);
47721+ seqno = atomic_read_unchecked(&intf->seqno);
47722
47723 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47724 hdr->seq_ctrl |= cpu_to_le16(seqno);
47725diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47726index b661f896..ddf7d2b 100644
47727--- a/drivers/net/wireless/ti/wl1251/sdio.c
47728+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47729@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47730
47731 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47732
47733- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47734- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47735+ pax_open_kernel();
47736+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47737+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47738+ pax_close_kernel();
47739
47740 wl1251_info("using dedicated interrupt line");
47741 } else {
47742- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47743- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47744+ pax_open_kernel();
47745+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47746+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47747+ pax_close_kernel();
47748
47749 wl1251_info("using SDIO interrupt");
47750 }
47751diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47752index d50dfac..0a6f5be3 100644
47753--- a/drivers/net/wireless/ti/wl12xx/main.c
47754+++ b/drivers/net/wireless/ti/wl12xx/main.c
47755@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47756 sizeof(wl->conf.mem));
47757
47758 /* read data preparation is only needed by wl127x */
47759- wl->ops->prepare_read = wl127x_prepare_read;
47760+ pax_open_kernel();
47761+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47762+ pax_close_kernel();
47763
47764 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47765 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47766@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47767 sizeof(wl->conf.mem));
47768
47769 /* read data preparation is only needed by wl127x */
47770- wl->ops->prepare_read = wl127x_prepare_read;
47771+ pax_open_kernel();
47772+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47773+ pax_close_kernel();
47774
47775 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47776 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47777diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47778index de5b4fa..7996ec6 100644
47779--- a/drivers/net/wireless/ti/wl18xx/main.c
47780+++ b/drivers/net/wireless/ti/wl18xx/main.c
47781@@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47782 }
47783
47784 if (!checksum_param) {
47785- wl18xx_ops.set_rx_csum = NULL;
47786- wl18xx_ops.init_vif = NULL;
47787+ pax_open_kernel();
47788+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47789+ *(void **)&wl18xx_ops.init_vif = NULL;
47790+ pax_close_kernel();
47791 }
47792
47793 /* Enable 11a Band only if we have 5G antennas */
47794diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47795index a912dc0..a8225ba 100644
47796--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47797+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47798@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47799 {
47800 struct zd_usb *usb = urb->context;
47801 struct zd_usb_interrupt *intr = &usb->intr;
47802- int len;
47803+ unsigned int len;
47804 u16 int_num;
47805
47806 ZD_ASSERT(in_interrupt());
47807diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47808index 683671a..4519fc2 100644
47809--- a/drivers/nfc/nfcwilink.c
47810+++ b/drivers/nfc/nfcwilink.c
47811@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47812
47813 static int nfcwilink_probe(struct platform_device *pdev)
47814 {
47815- static struct nfcwilink *drv;
47816+ struct nfcwilink *drv;
47817 int rc;
47818 __u32 protocols;
47819
47820diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47821index d93b2b6..ae50401 100644
47822--- a/drivers/oprofile/buffer_sync.c
47823+++ b/drivers/oprofile/buffer_sync.c
47824@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47825 if (cookie == NO_COOKIE)
47826 offset = pc;
47827 if (cookie == INVALID_COOKIE) {
47828- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47829+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47830 offset = pc;
47831 }
47832 if (cookie != last_cookie) {
47833@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47834 /* add userspace sample */
47835
47836 if (!mm) {
47837- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47838+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47839 return 0;
47840 }
47841
47842 cookie = lookup_dcookie(mm, s->eip, &offset);
47843
47844 if (cookie == INVALID_COOKIE) {
47845- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47846+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47847 return 0;
47848 }
47849
47850@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47851 /* ignore backtraces if failed to add a sample */
47852 if (state == sb_bt_start) {
47853 state = sb_bt_ignore;
47854- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47855+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47856 }
47857 }
47858 release_mm(mm);
47859diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47860index c0cc4e7..44d4e54 100644
47861--- a/drivers/oprofile/event_buffer.c
47862+++ b/drivers/oprofile/event_buffer.c
47863@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47864 }
47865
47866 if (buffer_pos == buffer_size) {
47867- atomic_inc(&oprofile_stats.event_lost_overflow);
47868+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47869 return;
47870 }
47871
47872diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47873index ed2c3ec..deda85a 100644
47874--- a/drivers/oprofile/oprof.c
47875+++ b/drivers/oprofile/oprof.c
47876@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47877 if (oprofile_ops.switch_events())
47878 return;
47879
47880- atomic_inc(&oprofile_stats.multiplex_counter);
47881+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47882 start_switch_worker();
47883 }
47884
47885diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47886index ee2cfce..7f8f699 100644
47887--- a/drivers/oprofile/oprofile_files.c
47888+++ b/drivers/oprofile/oprofile_files.c
47889@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47890
47891 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47892
47893-static ssize_t timeout_read(struct file *file, char __user *buf,
47894+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47895 size_t count, loff_t *offset)
47896 {
47897 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47898diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47899index 59659ce..6c860a0 100644
47900--- a/drivers/oprofile/oprofile_stats.c
47901+++ b/drivers/oprofile/oprofile_stats.c
47902@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47903 cpu_buf->sample_invalid_eip = 0;
47904 }
47905
47906- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47907- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47908- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47909- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47910- atomic_set(&oprofile_stats.multiplex_counter, 0);
47911+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47912+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47913+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47914+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47915+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47916 }
47917
47918
47919diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47920index 1fc622b..8c48fc3 100644
47921--- a/drivers/oprofile/oprofile_stats.h
47922+++ b/drivers/oprofile/oprofile_stats.h
47923@@ -13,11 +13,11 @@
47924 #include <linux/atomic.h>
47925
47926 struct oprofile_stat_struct {
47927- atomic_t sample_lost_no_mm;
47928- atomic_t sample_lost_no_mapping;
47929- atomic_t bt_lost_no_mapping;
47930- atomic_t event_lost_overflow;
47931- atomic_t multiplex_counter;
47932+ atomic_unchecked_t sample_lost_no_mm;
47933+ atomic_unchecked_t sample_lost_no_mapping;
47934+ atomic_unchecked_t bt_lost_no_mapping;
47935+ atomic_unchecked_t event_lost_overflow;
47936+ atomic_unchecked_t multiplex_counter;
47937 };
47938
47939 extern struct oprofile_stat_struct oprofile_stats;
47940diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47941index 3f49345..c750d0b 100644
47942--- a/drivers/oprofile/oprofilefs.c
47943+++ b/drivers/oprofile/oprofilefs.c
47944@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47945
47946 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47947 {
47948- atomic_t *val = file->private_data;
47949- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47950+ atomic_unchecked_t *val = file->private_data;
47951+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47952 }
47953
47954
47955@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47956
47957
47958 int oprofilefs_create_ro_atomic(struct dentry *root,
47959- char const *name, atomic_t *val)
47960+ char const *name, atomic_unchecked_t *val)
47961 {
47962 return __oprofilefs_create_file(root, name,
47963 &atomic_ro_fops, 0444, val);
47964diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47965index 61be1d9..dec05d7 100644
47966--- a/drivers/oprofile/timer_int.c
47967+++ b/drivers/oprofile/timer_int.c
47968@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47969 return NOTIFY_OK;
47970 }
47971
47972-static struct notifier_block __refdata oprofile_cpu_notifier = {
47973+static struct notifier_block oprofile_cpu_notifier = {
47974 .notifier_call = oprofile_cpu_notify,
47975 };
47976
47977diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47978index 92ed045..62d39bd7 100644
47979--- a/drivers/parport/procfs.c
47980+++ b/drivers/parport/procfs.c
47981@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47982
47983 *ppos += len;
47984
47985- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47986+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47987 }
47988
47989 #ifdef CONFIG_PARPORT_1284
47990@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47991
47992 *ppos += len;
47993
47994- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47995+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47996 }
47997 #endif /* IEEE1284.3 support. */
47998
47999diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
48000index 8dcccff..35d701d 100644
48001--- a/drivers/pci/hotplug/acpiphp_ibm.c
48002+++ b/drivers/pci/hotplug/acpiphp_ibm.c
48003@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
48004 goto init_cleanup;
48005 }
48006
48007- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
48008+ pax_open_kernel();
48009+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
48010+ pax_close_kernel();
48011 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
48012
48013 return retval;
48014diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
48015index 7536eef..52dc8fa 100644
48016--- a/drivers/pci/hotplug/cpcihp_generic.c
48017+++ b/drivers/pci/hotplug/cpcihp_generic.c
48018@@ -73,7 +73,6 @@ static u16 port;
48019 static unsigned int enum_bit;
48020 static u8 enum_mask;
48021
48022-static struct cpci_hp_controller_ops generic_hpc_ops;
48023 static struct cpci_hp_controller generic_hpc;
48024
48025 static int __init validate_parameters(void)
48026@@ -139,6 +138,10 @@ static int query_enum(void)
48027 return ((value & enum_mask) == enum_mask);
48028 }
48029
48030+static struct cpci_hp_controller_ops generic_hpc_ops = {
48031+ .query_enum = query_enum,
48032+};
48033+
48034 static int __init cpcihp_generic_init(void)
48035 {
48036 int status;
48037@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
48038 pci_dev_put(dev);
48039
48040 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
48041- generic_hpc_ops.query_enum = query_enum;
48042 generic_hpc.ops = &generic_hpc_ops;
48043
48044 status = cpci_hp_register_controller(&generic_hpc);
48045diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
48046index e8c4a7c..7046f5c 100644
48047--- a/drivers/pci/hotplug/cpcihp_zt5550.c
48048+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
48049@@ -59,7 +59,6 @@
48050 /* local variables */
48051 static bool debug;
48052 static bool poll;
48053-static struct cpci_hp_controller_ops zt5550_hpc_ops;
48054 static struct cpci_hp_controller zt5550_hpc;
48055
48056 /* Primary cPCI bus bridge device */
48057@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
48058 return 0;
48059 }
48060
48061+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
48062+ .query_enum = zt5550_hc_query_enum,
48063+};
48064+
48065 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
48066 {
48067 int status;
48068@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
48069 dbg("returned from zt5550_hc_config");
48070
48071 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
48072- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
48073 zt5550_hpc.ops = &zt5550_hpc_ops;
48074 if(!poll) {
48075 zt5550_hpc.irq = hc_dev->irq;
48076 zt5550_hpc.irq_flags = IRQF_SHARED;
48077 zt5550_hpc.dev_id = hc_dev;
48078
48079- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48080- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48081- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48082+ pax_open_kernel();
48083+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48084+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48085+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48086+ pax_open_kernel();
48087 } else {
48088 info("using ENUM# polling mode");
48089 }
48090diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
48091index 76ba8a1..20ca857 100644
48092--- a/drivers/pci/hotplug/cpqphp_nvram.c
48093+++ b/drivers/pci/hotplug/cpqphp_nvram.c
48094@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
48095
48096 void compaq_nvram_init (void __iomem *rom_start)
48097 {
48098+
48099+#ifndef CONFIG_PAX_KERNEXEC
48100 if (rom_start) {
48101 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
48102 }
48103+#endif
48104+
48105 dbg("int15 entry = %p\n", compaq_int15_entry_point);
48106
48107 /* initialize our int15 lock */
48108diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
48109index cfa92a9..29539c5 100644
48110--- a/drivers/pci/hotplug/pci_hotplug_core.c
48111+++ b/drivers/pci/hotplug/pci_hotplug_core.c
48112@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
48113 return -EINVAL;
48114 }
48115
48116- slot->ops->owner = owner;
48117- slot->ops->mod_name = mod_name;
48118+ pax_open_kernel();
48119+ *(struct module **)&slot->ops->owner = owner;
48120+ *(const char **)&slot->ops->mod_name = mod_name;
48121+ pax_close_kernel();
48122
48123 mutex_lock(&pci_hp_mutex);
48124 /*
48125diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48126index 0e0a2ff..29dff57 100644
48127--- a/drivers/pci/hotplug/pciehp_core.c
48128+++ b/drivers/pci/hotplug/pciehp_core.c
48129@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48130 struct slot *slot = ctrl->slot;
48131 struct hotplug_slot *hotplug = NULL;
48132 struct hotplug_slot_info *info = NULL;
48133- struct hotplug_slot_ops *ops = NULL;
48134+ hotplug_slot_ops_no_const *ops = NULL;
48135 char name[SLOT_NAME_SIZE];
48136 int retval = -ENOMEM;
48137
48138diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48139index fb02fc2..83dc2c3 100644
48140--- a/drivers/pci/msi.c
48141+++ b/drivers/pci/msi.c
48142@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48143 {
48144 struct attribute **msi_attrs;
48145 struct attribute *msi_attr;
48146- struct device_attribute *msi_dev_attr;
48147- struct attribute_group *msi_irq_group;
48148+ device_attribute_no_const *msi_dev_attr;
48149+ attribute_group_no_const *msi_irq_group;
48150 const struct attribute_group **msi_irq_groups;
48151 struct msi_desc *entry;
48152 int ret = -ENOMEM;
48153@@ -589,7 +589,7 @@ error_attrs:
48154 count = 0;
48155 msi_attr = msi_attrs[count];
48156 while (msi_attr) {
48157- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48158+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48159 kfree(msi_attr->name);
48160 kfree(msi_dev_attr);
48161 ++count;
48162diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48163index 4e0acef..bd98e31 100644
48164--- a/drivers/pci/pci-sysfs.c
48165+++ b/drivers/pci/pci-sysfs.c
48166@@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48167 {
48168 /* allocate attribute structure, piggyback attribute name */
48169 int name_len = write_combine ? 13 : 10;
48170- struct bin_attribute *res_attr;
48171+ bin_attribute_no_const *res_attr;
48172 int retval;
48173
48174 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48175@@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48176 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48177 {
48178 int retval;
48179- struct bin_attribute *attr;
48180+ bin_attribute_no_const *attr;
48181
48182 /* If the device has VPD, try to expose it in sysfs. */
48183 if (dev->vpd) {
48184@@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48185 {
48186 int retval;
48187 int rom_size = 0;
48188- struct bin_attribute *attr;
48189+ bin_attribute_no_const *attr;
48190
48191 if (!sysfs_initialized)
48192 return -EACCES;
48193diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48194index 6bd0822..35bc2b3 100644
48195--- a/drivers/pci/pci.h
48196+++ b/drivers/pci/pci.h
48197@@ -91,7 +91,7 @@ struct pci_vpd_ops {
48198 struct pci_vpd {
48199 unsigned int len;
48200 const struct pci_vpd_ops *ops;
48201- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48202+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48203 };
48204
48205 int pci_vpd_pci22_init(struct pci_dev *dev);
48206diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48207index e1e7026..d28dd33 100644
48208--- a/drivers/pci/pcie/aspm.c
48209+++ b/drivers/pci/pcie/aspm.c
48210@@ -27,9 +27,9 @@
48211 #define MODULE_PARAM_PREFIX "pcie_aspm."
48212
48213 /* Note: those are not register definitions */
48214-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48215-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48216-#define ASPM_STATE_L1 (4) /* L1 state */
48217+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48218+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48219+#define ASPM_STATE_L1 (4U) /* L1 state */
48220 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48221 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48222
48223diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48224index ef09f5f..49ac62f 100644
48225--- a/drivers/pci/probe.c
48226+++ b/drivers/pci/probe.c
48227@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48228 struct pci_bus_region region, inverted_region;
48229 bool bar_too_big = false, bar_disabled = false;
48230
48231- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48232+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48233
48234 /* No printks while decoding is disabled! */
48235 if (!dev->mmio_always_on) {
48236diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48237index 46d1378..30e452b 100644
48238--- a/drivers/pci/proc.c
48239+++ b/drivers/pci/proc.c
48240@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48241 static int __init pci_proc_init(void)
48242 {
48243 struct pci_dev *dev = NULL;
48244+
48245+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48246+#ifdef CONFIG_GRKERNSEC_PROC_USER
48247+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48248+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48249+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48250+#endif
48251+#else
48252 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48253+#endif
48254 proc_create("devices", 0, proc_bus_pci_dir,
48255 &proc_bus_pci_dev_operations);
48256 proc_initialized = 1;
48257diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48258index 7f3aad0..7d604bb 100644
48259--- a/drivers/platform/chrome/chromeos_laptop.c
48260+++ b/drivers/platform/chrome/chromeos_laptop.c
48261@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48262 .callback = chromeos_laptop_dmi_matched, \
48263 .driver_data = (void *)&board_
48264
48265-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48266+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48267 {
48268 .ident = "Samsung Series 5 550",
48269 .matches = {
48270diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
48271index 541f951..4dfd598 100644
48272--- a/drivers/platform/x86/alienware-wmi.c
48273+++ b/drivers/platform/x86/alienware-wmi.c
48274@@ -132,7 +132,7 @@ struct wmax_led_args {
48275 } __packed;
48276
48277 static struct platform_device *platform_device;
48278-static struct device_attribute *zone_dev_attrs;
48279+static device_attribute_no_const *zone_dev_attrs;
48280 static struct attribute **zone_attrs;
48281 static struct platform_zone *zone_data;
48282
48283@@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
48284 }
48285 };
48286
48287-static struct attribute_group zone_attribute_group = {
48288+static attribute_group_no_const zone_attribute_group = {
48289 .name = "rgb_zones",
48290 };
48291
48292diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48293index c5e082f..d6307a0 100644
48294--- a/drivers/platform/x86/asus-wmi.c
48295+++ b/drivers/platform/x86/asus-wmi.c
48296@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48297 int err;
48298 u32 retval = -1;
48299
48300+#ifdef CONFIG_GRKERNSEC_KMEM
48301+ return -EPERM;
48302+#endif
48303+
48304 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48305
48306 if (err < 0)
48307@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48308 int err;
48309 u32 retval = -1;
48310
48311+#ifdef CONFIG_GRKERNSEC_KMEM
48312+ return -EPERM;
48313+#endif
48314+
48315 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48316 &retval);
48317
48318@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48319 union acpi_object *obj;
48320 acpi_status status;
48321
48322+#ifdef CONFIG_GRKERNSEC_KMEM
48323+ return -EPERM;
48324+#endif
48325+
48326 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48327 1, asus->debug.method_id,
48328 &input, &output);
48329diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48330index 62f8030..c7f2a45 100644
48331--- a/drivers/platform/x86/msi-laptop.c
48332+++ b/drivers/platform/x86/msi-laptop.c
48333@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48334
48335 if (!quirks->ec_read_only) {
48336 /* allow userland write sysfs file */
48337- dev_attr_bluetooth.store = store_bluetooth;
48338- dev_attr_wlan.store = store_wlan;
48339- dev_attr_threeg.store = store_threeg;
48340- dev_attr_bluetooth.attr.mode |= S_IWUSR;
48341- dev_attr_wlan.attr.mode |= S_IWUSR;
48342- dev_attr_threeg.attr.mode |= S_IWUSR;
48343+ pax_open_kernel();
48344+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48345+ *(void **)&dev_attr_wlan.store = store_wlan;
48346+ *(void **)&dev_attr_threeg.store = store_threeg;
48347+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48348+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48349+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48350+ pax_close_kernel();
48351 }
48352
48353 /* disable hardware control by fn key */
48354diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48355index 70222f2..8c8ce66 100644
48356--- a/drivers/platform/x86/msi-wmi.c
48357+++ b/drivers/platform/x86/msi-wmi.c
48358@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48359 static void msi_wmi_notify(u32 value, void *context)
48360 {
48361 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48362- static struct key_entry *key;
48363+ struct key_entry *key;
48364 union acpi_object *obj;
48365 acpi_status status;
48366
48367diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48368index 9c5a074..06c976a 100644
48369--- a/drivers/platform/x86/sony-laptop.c
48370+++ b/drivers/platform/x86/sony-laptop.c
48371@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48372 }
48373
48374 /* High speed charging function */
48375-static struct device_attribute *hsc_handle;
48376+static device_attribute_no_const *hsc_handle;
48377
48378 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48379 struct device_attribute *attr,
48380@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
48381 }
48382
48383 /* low battery function */
48384-static struct device_attribute *lowbatt_handle;
48385+static device_attribute_no_const *lowbatt_handle;
48386
48387 static ssize_t sony_nc_lowbatt_store(struct device *dev,
48388 struct device_attribute *attr,
48389@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
48390 }
48391
48392 /* fan speed function */
48393-static struct device_attribute *fan_handle, *hsf_handle;
48394+static device_attribute_no_const *fan_handle, *hsf_handle;
48395
48396 static ssize_t sony_nc_hsfan_store(struct device *dev,
48397 struct device_attribute *attr,
48398@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
48399 }
48400
48401 /* USB charge function */
48402-static struct device_attribute *uc_handle;
48403+static device_attribute_no_const *uc_handle;
48404
48405 static ssize_t sony_nc_usb_charge_store(struct device *dev,
48406 struct device_attribute *attr,
48407@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
48408 }
48409
48410 /* Panel ID function */
48411-static struct device_attribute *panel_handle;
48412+static device_attribute_no_const *panel_handle;
48413
48414 static ssize_t sony_nc_panelid_show(struct device *dev,
48415 struct device_attribute *attr, char *buffer)
48416@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
48417 }
48418
48419 /* smart connect function */
48420-static struct device_attribute *sc_handle;
48421+static device_attribute_no_const *sc_handle;
48422
48423 static ssize_t sony_nc_smart_conn_store(struct device *dev,
48424 struct device_attribute *attr,
48425diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48426index 15e61c1..40a39c7 100644
48427--- a/drivers/platform/x86/thinkpad_acpi.c
48428+++ b/drivers/platform/x86/thinkpad_acpi.c
48429@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48430 return 0;
48431 }
48432
48433-void static hotkey_mask_warn_incomplete_mask(void)
48434+static void hotkey_mask_warn_incomplete_mask(void)
48435 {
48436 /* log only what the user can fix... */
48437 const u32 wantedmask = hotkey_driver_mask &
48438@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48439 && !tp_features.bright_unkfw)
48440 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48441 }
48442+}
48443
48444 #undef TPACPI_COMPARE_KEY
48445 #undef TPACPI_MAY_SEND_KEY
48446-}
48447
48448 /*
48449 * Polling driver
48450diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48451index 438d4c7..ca8a2fb 100644
48452--- a/drivers/pnp/pnpbios/bioscalls.c
48453+++ b/drivers/pnp/pnpbios/bioscalls.c
48454@@ -59,7 +59,7 @@ do { \
48455 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48456 } while(0)
48457
48458-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48459+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48460 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48461
48462 /*
48463@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48464
48465 cpu = get_cpu();
48466 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48467+
48468+ pax_open_kernel();
48469 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48470+ pax_close_kernel();
48471
48472 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48473 spin_lock_irqsave(&pnp_bios_lock, flags);
48474@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48475 :"memory");
48476 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48477
48478+ pax_open_kernel();
48479 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48480+ pax_close_kernel();
48481+
48482 put_cpu();
48483
48484 /* If we get here and this is set then the PnP BIOS faulted on us. */
48485@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48486 return status;
48487 }
48488
48489-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48490+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48491 {
48492 int i;
48493
48494@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48495 pnp_bios_callpoint.offset = header->fields.pm16offset;
48496 pnp_bios_callpoint.segment = PNP_CS16;
48497
48498+ pax_open_kernel();
48499+
48500 for_each_possible_cpu(i) {
48501 struct desc_struct *gdt = get_cpu_gdt_table(i);
48502 if (!gdt)
48503@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48504 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48505 (unsigned long)__va(header->fields.pm16dseg));
48506 }
48507+
48508+ pax_close_kernel();
48509 }
48510diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48511index 01712cb..782e822 100644
48512--- a/drivers/pnp/resource.c
48513+++ b/drivers/pnp/resource.c
48514@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48515 return 1;
48516
48517 /* check if the resource is valid */
48518- if (*irq < 0 || *irq > 15)
48519+ if (*irq > 15)
48520 return 0;
48521
48522 /* check if the resource is reserved */
48523@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48524 return 1;
48525
48526 /* check if the resource is valid */
48527- if (*dma < 0 || *dma == 4 || *dma > 7)
48528+ if (*dma == 4 || *dma > 7)
48529 return 0;
48530
48531 /* check if the resource is reserved */
48532diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48533index 0c52e2a..3421ab7 100644
48534--- a/drivers/power/pda_power.c
48535+++ b/drivers/power/pda_power.c
48536@@ -37,7 +37,11 @@ static int polling;
48537
48538 #if IS_ENABLED(CONFIG_USB_PHY)
48539 static struct usb_phy *transceiver;
48540-static struct notifier_block otg_nb;
48541+static int otg_handle_notification(struct notifier_block *nb,
48542+ unsigned long event, void *unused);
48543+static struct notifier_block otg_nb = {
48544+ .notifier_call = otg_handle_notification
48545+};
48546 #endif
48547
48548 static struct regulator *ac_draw;
48549@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48550
48551 #if IS_ENABLED(CONFIG_USB_PHY)
48552 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48553- otg_nb.notifier_call = otg_handle_notification;
48554 ret = usb_register_notifier(transceiver, &otg_nb);
48555 if (ret) {
48556 dev_err(dev, "failure to register otg notifier\n");
48557diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48558index cc439fd..8fa30df 100644
48559--- a/drivers/power/power_supply.h
48560+++ b/drivers/power/power_supply.h
48561@@ -16,12 +16,12 @@ struct power_supply;
48562
48563 #ifdef CONFIG_SYSFS
48564
48565-extern void power_supply_init_attrs(struct device_type *dev_type);
48566+extern void power_supply_init_attrs(void);
48567 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48568
48569 #else
48570
48571-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48572+static inline void power_supply_init_attrs(void) {}
48573 #define power_supply_uevent NULL
48574
48575 #endif /* CONFIG_SYSFS */
48576diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48577index 2660664..75fcb04 100644
48578--- a/drivers/power/power_supply_core.c
48579+++ b/drivers/power/power_supply_core.c
48580@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48581 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48582 EXPORT_SYMBOL_GPL(power_supply_notifier);
48583
48584-static struct device_type power_supply_dev_type;
48585+extern const struct attribute_group *power_supply_attr_groups[];
48586+static struct device_type power_supply_dev_type = {
48587+ .groups = power_supply_attr_groups,
48588+};
48589
48590 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48591 struct power_supply *supply)
48592@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48593 return PTR_ERR(power_supply_class);
48594
48595 power_supply_class->dev_uevent = power_supply_uevent;
48596- power_supply_init_attrs(&power_supply_dev_type);
48597+ power_supply_init_attrs();
48598
48599 return 0;
48600 }
48601diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48602index 44420d1..967126e 100644
48603--- a/drivers/power/power_supply_sysfs.c
48604+++ b/drivers/power/power_supply_sysfs.c
48605@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48606 .is_visible = power_supply_attr_is_visible,
48607 };
48608
48609-static const struct attribute_group *power_supply_attr_groups[] = {
48610+const struct attribute_group *power_supply_attr_groups[] = {
48611 &power_supply_attr_group,
48612 NULL,
48613 };
48614
48615-void power_supply_init_attrs(struct device_type *dev_type)
48616+void power_supply_init_attrs(void)
48617 {
48618 int i;
48619
48620- dev_type->groups = power_supply_attr_groups;
48621-
48622 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48623 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48624 }
48625diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48626index 84419af..268ede8 100644
48627--- a/drivers/powercap/powercap_sys.c
48628+++ b/drivers/powercap/powercap_sys.c
48629@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48630 struct device_attribute name_attr;
48631 };
48632
48633+static ssize_t show_constraint_name(struct device *dev,
48634+ struct device_attribute *dev_attr,
48635+ char *buf);
48636+
48637 static struct powercap_constraint_attr
48638- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48639+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48640+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48641+ .power_limit_attr = {
48642+ .attr = {
48643+ .name = NULL,
48644+ .mode = S_IWUSR | S_IRUGO
48645+ },
48646+ .show = show_constraint_power_limit_uw,
48647+ .store = store_constraint_power_limit_uw
48648+ },
48649+
48650+ .time_window_attr = {
48651+ .attr = {
48652+ .name = NULL,
48653+ .mode = S_IWUSR | S_IRUGO
48654+ },
48655+ .show = show_constraint_time_window_us,
48656+ .store = store_constraint_time_window_us
48657+ },
48658+
48659+ .max_power_attr = {
48660+ .attr = {
48661+ .name = NULL,
48662+ .mode = S_IRUGO
48663+ },
48664+ .show = show_constraint_max_power_uw,
48665+ .store = NULL
48666+ },
48667+
48668+ .min_power_attr = {
48669+ .attr = {
48670+ .name = NULL,
48671+ .mode = S_IRUGO
48672+ },
48673+ .show = show_constraint_min_power_uw,
48674+ .store = NULL
48675+ },
48676+
48677+ .max_time_window_attr = {
48678+ .attr = {
48679+ .name = NULL,
48680+ .mode = S_IRUGO
48681+ },
48682+ .show = show_constraint_max_time_window_us,
48683+ .store = NULL
48684+ },
48685+
48686+ .min_time_window_attr = {
48687+ .attr = {
48688+ .name = NULL,
48689+ .mode = S_IRUGO
48690+ },
48691+ .show = show_constraint_min_time_window_us,
48692+ .store = NULL
48693+ },
48694+
48695+ .name_attr = {
48696+ .attr = {
48697+ .name = NULL,
48698+ .mode = S_IRUGO
48699+ },
48700+ .show = show_constraint_name,
48701+ .store = NULL
48702+ }
48703+ }
48704+};
48705
48706 /* A list of powercap control_types */
48707 static LIST_HEAD(powercap_cntrl_list);
48708@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48709 }
48710
48711 static int create_constraint_attribute(int id, const char *name,
48712- int mode,
48713- struct device_attribute *dev_attr,
48714- ssize_t (*show)(struct device *,
48715- struct device_attribute *, char *),
48716- ssize_t (*store)(struct device *,
48717- struct device_attribute *,
48718- const char *, size_t)
48719- )
48720+ struct device_attribute *dev_attr)
48721 {
48722+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48723
48724- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48725- id, name);
48726- if (!dev_attr->attr.name)
48727+ if (!name)
48728 return -ENOMEM;
48729- dev_attr->attr.mode = mode;
48730- dev_attr->show = show;
48731- dev_attr->store = store;
48732+
48733+ pax_open_kernel();
48734+ *(const char **)&dev_attr->attr.name = name;
48735+ pax_close_kernel();
48736
48737 return 0;
48738 }
48739@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48740
48741 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48742 ret = create_constraint_attribute(i, "power_limit_uw",
48743- S_IWUSR | S_IRUGO,
48744- &constraint_attrs[i].power_limit_attr,
48745- show_constraint_power_limit_uw,
48746- store_constraint_power_limit_uw);
48747+ &constraint_attrs[i].power_limit_attr);
48748 if (ret)
48749 goto err_alloc;
48750 ret = create_constraint_attribute(i, "time_window_us",
48751- S_IWUSR | S_IRUGO,
48752- &constraint_attrs[i].time_window_attr,
48753- show_constraint_time_window_us,
48754- store_constraint_time_window_us);
48755+ &constraint_attrs[i].time_window_attr);
48756 if (ret)
48757 goto err_alloc;
48758- ret = create_constraint_attribute(i, "name", S_IRUGO,
48759- &constraint_attrs[i].name_attr,
48760- show_constraint_name,
48761- NULL);
48762+ ret = create_constraint_attribute(i, "name",
48763+ &constraint_attrs[i].name_attr);
48764 if (ret)
48765 goto err_alloc;
48766- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48767- &constraint_attrs[i].max_power_attr,
48768- show_constraint_max_power_uw,
48769- NULL);
48770+ ret = create_constraint_attribute(i, "max_power_uw",
48771+ &constraint_attrs[i].max_power_attr);
48772 if (ret)
48773 goto err_alloc;
48774- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48775- &constraint_attrs[i].min_power_attr,
48776- show_constraint_min_power_uw,
48777- NULL);
48778+ ret = create_constraint_attribute(i, "min_power_uw",
48779+ &constraint_attrs[i].min_power_attr);
48780 if (ret)
48781 goto err_alloc;
48782 ret = create_constraint_attribute(i, "max_time_window_us",
48783- S_IRUGO,
48784- &constraint_attrs[i].max_time_window_attr,
48785- show_constraint_max_time_window_us,
48786- NULL);
48787+ &constraint_attrs[i].max_time_window_attr);
48788 if (ret)
48789 goto err_alloc;
48790 ret = create_constraint_attribute(i, "min_time_window_us",
48791- S_IRUGO,
48792- &constraint_attrs[i].min_time_window_attr,
48793- show_constraint_min_time_window_us,
48794- NULL);
48795+ &constraint_attrs[i].min_time_window_attr);
48796 if (ret)
48797 goto err_alloc;
48798
48799@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48800 power_zone->zone_dev_attrs[count++] =
48801 &dev_attr_max_energy_range_uj.attr;
48802 if (power_zone->ops->get_energy_uj) {
48803+ pax_open_kernel();
48804 if (power_zone->ops->reset_energy_uj)
48805- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48806+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48807 else
48808- dev_attr_energy_uj.attr.mode = S_IRUGO;
48809+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48810+ pax_close_kernel();
48811 power_zone->zone_dev_attrs[count++] =
48812 &dev_attr_energy_uj.attr;
48813 }
48814diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48815index 9c5d414..c7900ce 100644
48816--- a/drivers/ptp/ptp_private.h
48817+++ b/drivers/ptp/ptp_private.h
48818@@ -51,7 +51,7 @@ struct ptp_clock {
48819 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48820 wait_queue_head_t tsev_wq;
48821 int defunct; /* tells readers to go away when clock is being removed */
48822- struct device_attribute *pin_dev_attr;
48823+ device_attribute_no_const *pin_dev_attr;
48824 struct attribute **pin_attr;
48825 struct attribute_group pin_attr_group;
48826 };
48827diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48828index 302e626..12579af 100644
48829--- a/drivers/ptp/ptp_sysfs.c
48830+++ b/drivers/ptp/ptp_sysfs.c
48831@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48832 goto no_pin_attr;
48833
48834 for (i = 0; i < n_pins; i++) {
48835- struct device_attribute *da = &ptp->pin_dev_attr[i];
48836+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48837 sysfs_attr_init(&da->attr);
48838 da->attr.name = info->pin_config[i].name;
48839 da->attr.mode = 0644;
48840diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48841index 9a09f3c..450b523 100644
48842--- a/drivers/regulator/core.c
48843+++ b/drivers/regulator/core.c
48844@@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48845 {
48846 const struct regulation_constraints *constraints = NULL;
48847 const struct regulator_init_data *init_data;
48848- static atomic_t regulator_no = ATOMIC_INIT(0);
48849+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48850 struct regulator_dev *rdev;
48851 struct device *dev;
48852 int ret, i;
48853@@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48854 rdev->dev.of_node = config->of_node;
48855 rdev->dev.parent = dev;
48856 dev_set_name(&rdev->dev, "regulator.%d",
48857- atomic_inc_return(&regulator_no) - 1);
48858+ atomic_inc_return_unchecked(&regulator_no) - 1);
48859 ret = device_register(&rdev->dev);
48860 if (ret != 0) {
48861 put_device(&rdev->dev);
48862diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48863index 2fc4111..6aa88ca 100644
48864--- a/drivers/regulator/max8660.c
48865+++ b/drivers/regulator/max8660.c
48866@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48867 max8660->shadow_regs[MAX8660_OVER1] = 5;
48868 } else {
48869 /* Otherwise devices can be toggled via software */
48870- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48871- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48872+ pax_open_kernel();
48873+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48874+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48875+ pax_close_kernel();
48876 }
48877
48878 /*
48879diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48880index dbedf17..18ff6b7 100644
48881--- a/drivers/regulator/max8973-regulator.c
48882+++ b/drivers/regulator/max8973-regulator.c
48883@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48884 if (!pdata || !pdata->enable_ext_control) {
48885 max->desc.enable_reg = MAX8973_VOUT;
48886 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48887- max->ops.enable = regulator_enable_regmap;
48888- max->ops.disable = regulator_disable_regmap;
48889- max->ops.is_enabled = regulator_is_enabled_regmap;
48890+ pax_open_kernel();
48891+ *(void **)&max->ops.enable = regulator_enable_regmap;
48892+ *(void **)&max->ops.disable = regulator_disable_regmap;
48893+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48894+ pax_close_kernel();
48895 }
48896
48897 if (pdata) {
48898diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48899index f374fa5..26f0683 100644
48900--- a/drivers/regulator/mc13892-regulator.c
48901+++ b/drivers/regulator/mc13892-regulator.c
48902@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48903 }
48904 mc13xxx_unlock(mc13892);
48905
48906- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48907+ pax_open_kernel();
48908+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48909 = mc13892_vcam_set_mode;
48910- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48911+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48912 = mc13892_vcam_get_mode;
48913+ pax_close_kernel();
48914
48915 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48916 ARRAY_SIZE(mc13892_regulators));
48917diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48918index 0963c93..ea29cce 100644
48919--- a/drivers/rtc/rtc-cmos.c
48920+++ b/drivers/rtc/rtc-cmos.c
48921@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48922 hpet_rtc_timer_init();
48923
48924 /* export at least the first block of NVRAM */
48925- nvram.size = address_space - NVRAM_OFFSET;
48926+ pax_open_kernel();
48927+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48928+ pax_close_kernel();
48929 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48930 if (retval < 0) {
48931 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48932diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48933index d049393..bb20be0 100644
48934--- a/drivers/rtc/rtc-dev.c
48935+++ b/drivers/rtc/rtc-dev.c
48936@@ -16,6 +16,7 @@
48937 #include <linux/module.h>
48938 #include <linux/rtc.h>
48939 #include <linux/sched.h>
48940+#include <linux/grsecurity.h>
48941 #include "rtc-core.h"
48942
48943 static dev_t rtc_devt;
48944@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48945 if (copy_from_user(&tm, uarg, sizeof(tm)))
48946 return -EFAULT;
48947
48948+ gr_log_timechange();
48949+
48950 return rtc_set_time(rtc, &tm);
48951
48952 case RTC_PIE_ON:
48953diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48954index f03d5ba..8325bf6 100644
48955--- a/drivers/rtc/rtc-ds1307.c
48956+++ b/drivers/rtc/rtc-ds1307.c
48957@@ -107,7 +107,7 @@ struct ds1307 {
48958 u8 offset; /* register's offset */
48959 u8 regs[11];
48960 u16 nvram_offset;
48961- struct bin_attribute *nvram;
48962+ bin_attribute_no_const *nvram;
48963 enum ds_type type;
48964 unsigned long flags;
48965 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48966diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48967index 11880c1..b823aa4 100644
48968--- a/drivers/rtc/rtc-m48t59.c
48969+++ b/drivers/rtc/rtc-m48t59.c
48970@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48971 if (IS_ERR(m48t59->rtc))
48972 return PTR_ERR(m48t59->rtc);
48973
48974- m48t59_nvram_attr.size = pdata->offset;
48975+ pax_open_kernel();
48976+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48977+ pax_close_kernel();
48978
48979 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48980 if (ret)
48981diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48982index 14b5f8d..cc9bd26 100644
48983--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48984+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48985@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48986 for (bit = 0; bit < 8; bit++) {
48987
48988 if ((pci_status[i] & (0x1 << bit)) != 0) {
48989- static const char *s;
48990+ const char *s;
48991
48992 s = pci_status_strings[bit];
48993 if (i == 7/*TARG*/ && bit == 3)
48994@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48995
48996 for (bit = 0; bit < 8; bit++) {
48997
48998- if ((split_status[i] & (0x1 << bit)) != 0) {
48999- static const char *s;
49000-
49001- s = split_status_strings[bit];
49002- printk(s, ahd_name(ahd),
49003+ if ((split_status[i] & (0x1 << bit)) != 0)
49004+ printk(split_status_strings[bit], ahd_name(ahd),
49005 split_status_source[i]);
49006- }
49007
49008 if (i > 1)
49009 continue;
49010
49011- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
49012- static const char *s;
49013-
49014- s = split_status_strings[bit];
49015- printk(s, ahd_name(ahd), "SG");
49016- }
49017+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
49018+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
49019 }
49020 }
49021 /*
49022diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
49023index e693af6..2e525b6 100644
49024--- a/drivers/scsi/bfa/bfa_fcpim.h
49025+++ b/drivers/scsi/bfa/bfa_fcpim.h
49026@@ -36,7 +36,7 @@ struct bfa_iotag_s {
49027
49028 struct bfa_itn_s {
49029 bfa_isr_func_t isr;
49030-};
49031+} __no_const;
49032
49033 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
49034 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
49035diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
49036index a3ab5cc..8143622 100644
49037--- a/drivers/scsi/bfa/bfa_fcs.c
49038+++ b/drivers/scsi/bfa/bfa_fcs.c
49039@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
49040 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
49041
49042 static struct bfa_fcs_mod_s fcs_modules[] = {
49043- { bfa_fcs_port_attach, NULL, NULL },
49044- { bfa_fcs_uf_attach, NULL, NULL },
49045- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
49046- bfa_fcs_fabric_modexit },
49047+ {
49048+ .attach = bfa_fcs_port_attach,
49049+ .modinit = NULL,
49050+ .modexit = NULL
49051+ },
49052+ {
49053+ .attach = bfa_fcs_uf_attach,
49054+ .modinit = NULL,
49055+ .modexit = NULL
49056+ },
49057+ {
49058+ .attach = bfa_fcs_fabric_attach,
49059+ .modinit = bfa_fcs_fabric_modinit,
49060+ .modexit = bfa_fcs_fabric_modexit
49061+ },
49062 };
49063
49064 /*
49065diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
49066index ff75ef8..2dfe00a 100644
49067--- a/drivers/scsi/bfa/bfa_fcs_lport.c
49068+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
49069@@ -89,15 +89,26 @@ static struct {
49070 void (*offline) (struct bfa_fcs_lport_s *port);
49071 } __port_action[] = {
49072 {
49073- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
49074- bfa_fcs_lport_unknown_offline}, {
49075- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
49076- bfa_fcs_lport_fab_offline}, {
49077- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
49078- bfa_fcs_lport_n2n_offline}, {
49079- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
49080- bfa_fcs_lport_loop_offline},
49081- };
49082+ .init = bfa_fcs_lport_unknown_init,
49083+ .online = bfa_fcs_lport_unknown_online,
49084+ .offline = bfa_fcs_lport_unknown_offline
49085+ },
49086+ {
49087+ .init = bfa_fcs_lport_fab_init,
49088+ .online = bfa_fcs_lport_fab_online,
49089+ .offline = bfa_fcs_lport_fab_offline
49090+ },
49091+ {
49092+ .init = bfa_fcs_lport_n2n_init,
49093+ .online = bfa_fcs_lport_n2n_online,
49094+ .offline = bfa_fcs_lport_n2n_offline
49095+ },
49096+ {
49097+ .init = bfa_fcs_lport_loop_init,
49098+ .online = bfa_fcs_lport_loop_online,
49099+ .offline = bfa_fcs_lport_loop_offline
49100+ },
49101+};
49102
49103 /*
49104 * fcs_port_sm FCS logical port state machine
49105diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
49106index 2e28392..9d865b6 100644
49107--- a/drivers/scsi/bfa/bfa_ioc.h
49108+++ b/drivers/scsi/bfa/bfa_ioc.h
49109@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
49110 bfa_ioc_disable_cbfn_t disable_cbfn;
49111 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
49112 bfa_ioc_reset_cbfn_t reset_cbfn;
49113-};
49114+} __no_const;
49115
49116 /*
49117 * IOC event notification mechanism.
49118@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49119 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49120 enum bfi_ioc_state fwstate);
49121 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49122-};
49123+} __no_const;
49124
49125 /*
49126 * Queue element to wait for room in request queue. FIFO order is
49127diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49128index a14c784..6de6790 100644
49129--- a/drivers/scsi/bfa/bfa_modules.h
49130+++ b/drivers/scsi/bfa/bfa_modules.h
49131@@ -78,12 +78,12 @@ enum {
49132 \
49133 extern struct bfa_module_s hal_mod_ ## __mod; \
49134 struct bfa_module_s hal_mod_ ## __mod = { \
49135- bfa_ ## __mod ## _meminfo, \
49136- bfa_ ## __mod ## _attach, \
49137- bfa_ ## __mod ## _detach, \
49138- bfa_ ## __mod ## _start, \
49139- bfa_ ## __mod ## _stop, \
49140- bfa_ ## __mod ## _iocdisable, \
49141+ .meminfo = bfa_ ## __mod ## _meminfo, \
49142+ .attach = bfa_ ## __mod ## _attach, \
49143+ .detach = bfa_ ## __mod ## _detach, \
49144+ .start = bfa_ ## __mod ## _start, \
49145+ .stop = bfa_ ## __mod ## _stop, \
49146+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
49147 }
49148
49149 #define BFA_CACHELINE_SZ (256)
49150diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49151index 045c4e1..13de803 100644
49152--- a/drivers/scsi/fcoe/fcoe_sysfs.c
49153+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49154@@ -33,8 +33,8 @@
49155 */
49156 #include "libfcoe.h"
49157
49158-static atomic_t ctlr_num;
49159-static atomic_t fcf_num;
49160+static atomic_unchecked_t ctlr_num;
49161+static atomic_unchecked_t fcf_num;
49162
49163 /*
49164 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49165@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49166 if (!ctlr)
49167 goto out;
49168
49169- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49170+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49171 ctlr->f = f;
49172 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49173 INIT_LIST_HEAD(&ctlr->fcfs);
49174@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49175 fcf->dev.parent = &ctlr->dev;
49176 fcf->dev.bus = &fcoe_bus_type;
49177 fcf->dev.type = &fcoe_fcf_device_type;
49178- fcf->id = atomic_inc_return(&fcf_num) - 1;
49179+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49180 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49181
49182 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49183@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49184 {
49185 int error;
49186
49187- atomic_set(&ctlr_num, 0);
49188- atomic_set(&fcf_num, 0);
49189+ atomic_set_unchecked(&ctlr_num, 0);
49190+ atomic_set_unchecked(&fcf_num, 0);
49191
49192 error = bus_register(&fcoe_bus_type);
49193 if (error)
49194diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49195index 3cbb57a..95e47a3 100644
49196--- a/drivers/scsi/hosts.c
49197+++ b/drivers/scsi/hosts.c
49198@@ -42,7 +42,7 @@
49199 #include "scsi_logging.h"
49200
49201
49202-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49203+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49204
49205
49206 static void scsi_host_cls_release(struct device *dev)
49207@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49208 * subtract one because we increment first then return, but we need to
49209 * know what the next host number was before increment
49210 */
49211- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49212+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49213 shost->dma_channel = 0xff;
49214
49215 /* These three are default values which can be overridden */
49216diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49217index fda6cf1..7a6b5d8 100644
49218--- a/drivers/scsi/hpsa.c
49219+++ b/drivers/scsi/hpsa.c
49220@@ -699,10 +699,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49221 unsigned long flags;
49222
49223 if (h->transMethod & CFGTBL_Trans_io_accel1)
49224- return h->access.command_completed(h, q);
49225+ return h->access->command_completed(h, q);
49226
49227 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49228- return h->access.command_completed(h, q);
49229+ return h->access->command_completed(h, q);
49230
49231 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49232 a = rq->head[rq->current_entry];
49233@@ -5460,7 +5460,7 @@ static void start_io(struct ctlr_info *h)
49234 while (!list_empty(&h->reqQ)) {
49235 c = list_entry(h->reqQ.next, struct CommandList, list);
49236 /* can't do anything if fifo is full */
49237- if ((h->access.fifo_full(h))) {
49238+ if ((h->access->fifo_full(h))) {
49239 h->fifo_recently_full = 1;
49240 dev_warn(&h->pdev->dev, "fifo full\n");
49241 break;
49242@@ -5484,7 +5484,7 @@ static void start_io(struct ctlr_info *h)
49243
49244 /* Tell the controller execute command */
49245 spin_unlock_irqrestore(&h->lock, flags);
49246- h->access.submit_command(h, c);
49247+ h->access->submit_command(h, c);
49248 spin_lock_irqsave(&h->lock, flags);
49249 }
49250 spin_unlock_irqrestore(&h->lock, flags);
49251@@ -5492,17 +5492,17 @@ static void start_io(struct ctlr_info *h)
49252
49253 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49254 {
49255- return h->access.command_completed(h, q);
49256+ return h->access->command_completed(h, q);
49257 }
49258
49259 static inline bool interrupt_pending(struct ctlr_info *h)
49260 {
49261- return h->access.intr_pending(h);
49262+ return h->access->intr_pending(h);
49263 }
49264
49265 static inline long interrupt_not_for_us(struct ctlr_info *h)
49266 {
49267- return (h->access.intr_pending(h) == 0) ||
49268+ return (h->access->intr_pending(h) == 0) ||
49269 (h->interrupts_enabled == 0);
49270 }
49271
49272@@ -6456,7 +6456,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49273 if (prod_index < 0)
49274 return -ENODEV;
49275 h->product_name = products[prod_index].product_name;
49276- h->access = *(products[prod_index].access);
49277+ h->access = products[prod_index].access;
49278
49279 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49280 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49281@@ -6735,7 +6735,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49282 {
49283 unsigned long flags;
49284
49285- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49286+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49287 spin_lock_irqsave(&h->lock, flags);
49288 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49289 spin_unlock_irqrestore(&h->lock, flags);
49290@@ -6963,7 +6963,7 @@ reinit_after_soft_reset:
49291 }
49292
49293 /* make sure the board interrupts are off */
49294- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49295+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49296
49297 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49298 goto clean2;
49299@@ -6998,7 +6998,7 @@ reinit_after_soft_reset:
49300 * fake ones to scoop up any residual completions.
49301 */
49302 spin_lock_irqsave(&h->lock, flags);
49303- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49304+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49305 spin_unlock_irqrestore(&h->lock, flags);
49306 free_irqs(h);
49307 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49308@@ -7017,9 +7017,9 @@ reinit_after_soft_reset:
49309 dev_info(&h->pdev->dev, "Board READY.\n");
49310 dev_info(&h->pdev->dev,
49311 "Waiting for stale completions to drain.\n");
49312- h->access.set_intr_mask(h, HPSA_INTR_ON);
49313+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49314 msleep(10000);
49315- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49316+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49317
49318 rc = controller_reset_failed(h->cfgtable);
49319 if (rc)
49320@@ -7045,7 +7045,7 @@ reinit_after_soft_reset:
49321 h->drv_req_rescan = 0;
49322
49323 /* Turn the interrupts on so we can service requests */
49324- h->access.set_intr_mask(h, HPSA_INTR_ON);
49325+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49326
49327 hpsa_hba_inquiry(h);
49328 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49329@@ -7114,7 +7114,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49330 * To write all data in the battery backed cache to disks
49331 */
49332 hpsa_flush_cache(h);
49333- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49334+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49335 hpsa_free_irqs_and_disable_msix(h);
49336 }
49337
49338@@ -7232,7 +7232,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49339 CFGTBL_Trans_enable_directed_msix |
49340 (trans_support & (CFGTBL_Trans_io_accel1 |
49341 CFGTBL_Trans_io_accel2));
49342- struct access_method access = SA5_performant_access;
49343+ struct access_method *access = &SA5_performant_access;
49344
49345 /* This is a bit complicated. There are 8 registers on
49346 * the controller which we write to to tell it 8 different
49347@@ -7297,12 +7297,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49348 * enable outbound interrupt coalescing in accelerator mode;
49349 */
49350 if (trans_support & CFGTBL_Trans_io_accel1) {
49351- access = SA5_ioaccel_mode1_access;
49352+ access = &SA5_ioaccel_mode1_access;
49353 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49354 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49355 } else {
49356 if (trans_support & CFGTBL_Trans_io_accel2) {
49357- access = SA5_ioaccel_mode2_access;
49358+ access = &SA5_ioaccel_mode2_access;
49359 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49360 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49361 }
49362diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49363index 44235a2..962e91b 100644
49364--- a/drivers/scsi/hpsa.h
49365+++ b/drivers/scsi/hpsa.h
49366@@ -128,7 +128,7 @@ struct ctlr_info {
49367 unsigned int msix_vector;
49368 unsigned int msi_vector;
49369 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49370- struct access_method access;
49371+ struct access_method *access;
49372 char hba_mode_enabled;
49373
49374 /* queue and queue Info */
49375@@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
49376 }
49377
49378 static struct access_method SA5_access = {
49379- SA5_submit_command,
49380- SA5_intr_mask,
49381- SA5_fifo_full,
49382- SA5_intr_pending,
49383- SA5_completed,
49384+ .submit_command = SA5_submit_command,
49385+ .set_intr_mask = SA5_intr_mask,
49386+ .fifo_full = SA5_fifo_full,
49387+ .intr_pending = SA5_intr_pending,
49388+ .command_completed = SA5_completed,
49389 };
49390
49391 static struct access_method SA5_ioaccel_mode1_access = {
49392- SA5_submit_command,
49393- SA5_performant_intr_mask,
49394- SA5_fifo_full,
49395- SA5_ioaccel_mode1_intr_pending,
49396- SA5_ioaccel_mode1_completed,
49397+ .submit_command = SA5_submit_command,
49398+ .set_intr_mask = SA5_performant_intr_mask,
49399+ .fifo_full = SA5_fifo_full,
49400+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
49401+ .command_completed = SA5_ioaccel_mode1_completed,
49402 };
49403
49404 static struct access_method SA5_ioaccel_mode2_access = {
49405- SA5_submit_command_ioaccel2,
49406- SA5_performant_intr_mask,
49407- SA5_fifo_full,
49408- SA5_performant_intr_pending,
49409- SA5_performant_completed,
49410+ .submit_command = SA5_submit_command_ioaccel2,
49411+ .set_intr_mask = SA5_performant_intr_mask,
49412+ .fifo_full = SA5_fifo_full,
49413+ .intr_pending = SA5_performant_intr_pending,
49414+ .command_completed = SA5_performant_completed,
49415 };
49416
49417 static struct access_method SA5_performant_access = {
49418- SA5_submit_command,
49419- SA5_performant_intr_mask,
49420- SA5_fifo_full,
49421- SA5_performant_intr_pending,
49422- SA5_performant_completed,
49423+ .submit_command = SA5_submit_command,
49424+ .set_intr_mask = SA5_performant_intr_mask,
49425+ .fifo_full = SA5_fifo_full,
49426+ .intr_pending = SA5_performant_intr_pending,
49427+ .command_completed = SA5_performant_completed,
49428 };
49429
49430 struct board_type {
49431diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49432index 1b3a094..068e683 100644
49433--- a/drivers/scsi/libfc/fc_exch.c
49434+++ b/drivers/scsi/libfc/fc_exch.c
49435@@ -101,12 +101,12 @@ struct fc_exch_mgr {
49436 u16 pool_max_index;
49437
49438 struct {
49439- atomic_t no_free_exch;
49440- atomic_t no_free_exch_xid;
49441- atomic_t xid_not_found;
49442- atomic_t xid_busy;
49443- atomic_t seq_not_found;
49444- atomic_t non_bls_resp;
49445+ atomic_unchecked_t no_free_exch;
49446+ atomic_unchecked_t no_free_exch_xid;
49447+ atomic_unchecked_t xid_not_found;
49448+ atomic_unchecked_t xid_busy;
49449+ atomic_unchecked_t seq_not_found;
49450+ atomic_unchecked_t non_bls_resp;
49451 } stats;
49452 };
49453
49454@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49455 /* allocate memory for exchange */
49456 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49457 if (!ep) {
49458- atomic_inc(&mp->stats.no_free_exch);
49459+ atomic_inc_unchecked(&mp->stats.no_free_exch);
49460 goto out;
49461 }
49462 memset(ep, 0, sizeof(*ep));
49463@@ -874,7 +874,7 @@ out:
49464 return ep;
49465 err:
49466 spin_unlock_bh(&pool->lock);
49467- atomic_inc(&mp->stats.no_free_exch_xid);
49468+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49469 mempool_free(ep, mp->ep_pool);
49470 return NULL;
49471 }
49472@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49473 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49474 ep = fc_exch_find(mp, xid);
49475 if (!ep) {
49476- atomic_inc(&mp->stats.xid_not_found);
49477+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49478 reject = FC_RJT_OX_ID;
49479 goto out;
49480 }
49481@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49482 ep = fc_exch_find(mp, xid);
49483 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49484 if (ep) {
49485- atomic_inc(&mp->stats.xid_busy);
49486+ atomic_inc_unchecked(&mp->stats.xid_busy);
49487 reject = FC_RJT_RX_ID;
49488 goto rel;
49489 }
49490@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49491 }
49492 xid = ep->xid; /* get our XID */
49493 } else if (!ep) {
49494- atomic_inc(&mp->stats.xid_not_found);
49495+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49496 reject = FC_RJT_RX_ID; /* XID not found */
49497 goto out;
49498 }
49499@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49500 } else {
49501 sp = &ep->seq;
49502 if (sp->id != fh->fh_seq_id) {
49503- atomic_inc(&mp->stats.seq_not_found);
49504+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49505 if (f_ctl & FC_FC_END_SEQ) {
49506 /*
49507 * Update sequence_id based on incoming last
49508@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49509
49510 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49511 if (!ep) {
49512- atomic_inc(&mp->stats.xid_not_found);
49513+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49514 goto out;
49515 }
49516 if (ep->esb_stat & ESB_ST_COMPLETE) {
49517- atomic_inc(&mp->stats.xid_not_found);
49518+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49519 goto rel;
49520 }
49521 if (ep->rxid == FC_XID_UNKNOWN)
49522 ep->rxid = ntohs(fh->fh_rx_id);
49523 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49524- atomic_inc(&mp->stats.xid_not_found);
49525+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49526 goto rel;
49527 }
49528 if (ep->did != ntoh24(fh->fh_s_id) &&
49529 ep->did != FC_FID_FLOGI) {
49530- atomic_inc(&mp->stats.xid_not_found);
49531+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49532 goto rel;
49533 }
49534 sof = fr_sof(fp);
49535@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49536 sp->ssb_stat |= SSB_ST_RESP;
49537 sp->id = fh->fh_seq_id;
49538 } else if (sp->id != fh->fh_seq_id) {
49539- atomic_inc(&mp->stats.seq_not_found);
49540+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49541 goto rel;
49542 }
49543
49544@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49545 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49546
49547 if (!sp)
49548- atomic_inc(&mp->stats.xid_not_found);
49549+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49550 else
49551- atomic_inc(&mp->stats.non_bls_resp);
49552+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49553
49554 fc_frame_free(fp);
49555 }
49556@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49557
49558 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49559 mp = ema->mp;
49560- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49561+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49562 st->fc_no_free_exch_xid +=
49563- atomic_read(&mp->stats.no_free_exch_xid);
49564- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49565- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49566- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49567- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49568+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49569+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49570+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49571+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49572+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49573 }
49574 }
49575 EXPORT_SYMBOL(fc_exch_update_stats);
49576diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49577index 766098a..1c6c971 100644
49578--- a/drivers/scsi/libsas/sas_ata.c
49579+++ b/drivers/scsi/libsas/sas_ata.c
49580@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49581 .postreset = ata_std_postreset,
49582 .error_handler = ata_std_error_handler,
49583 .post_internal_cmd = sas_ata_post_internal,
49584- .qc_defer = ata_std_qc_defer,
49585+ .qc_defer = ata_std_qc_defer,
49586 .qc_prep = ata_noop_qc_prep,
49587 .qc_issue = sas_ata_qc_issue,
49588 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49589diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49590index 94a3caf..a118dec 100644
49591--- a/drivers/scsi/lpfc/lpfc.h
49592+++ b/drivers/scsi/lpfc/lpfc.h
49593@@ -430,7 +430,7 @@ struct lpfc_vport {
49594 struct dentry *debug_nodelist;
49595 struct dentry *vport_debugfs_root;
49596 struct lpfc_debugfs_trc *disc_trc;
49597- atomic_t disc_trc_cnt;
49598+ atomic_unchecked_t disc_trc_cnt;
49599 #endif
49600 uint8_t stat_data_enabled;
49601 uint8_t stat_data_blocked;
49602@@ -879,8 +879,8 @@ struct lpfc_hba {
49603 struct timer_list fabric_block_timer;
49604 unsigned long bit_flags;
49605 #define FABRIC_COMANDS_BLOCKED 0
49606- atomic_t num_rsrc_err;
49607- atomic_t num_cmd_success;
49608+ atomic_unchecked_t num_rsrc_err;
49609+ atomic_unchecked_t num_cmd_success;
49610 unsigned long last_rsrc_error_time;
49611 unsigned long last_ramp_down_time;
49612 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49613@@ -915,7 +915,7 @@ struct lpfc_hba {
49614
49615 struct dentry *debug_slow_ring_trc;
49616 struct lpfc_debugfs_trc *slow_ring_trc;
49617- atomic_t slow_ring_trc_cnt;
49618+ atomic_unchecked_t slow_ring_trc_cnt;
49619 /* iDiag debugfs sub-directory */
49620 struct dentry *idiag_root;
49621 struct dentry *idiag_pci_cfg;
49622diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49623index 828c08e..e3378e0 100644
49624--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49625+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49626@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49627
49628 #include <linux/debugfs.h>
49629
49630-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49631+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49632 static unsigned long lpfc_debugfs_start_time = 0L;
49633
49634 /* iDiag */
49635@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49636 lpfc_debugfs_enable = 0;
49637
49638 len = 0;
49639- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49640+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49641 (lpfc_debugfs_max_disc_trc - 1);
49642 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49643 dtp = vport->disc_trc + i;
49644@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49645 lpfc_debugfs_enable = 0;
49646
49647 len = 0;
49648- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49649+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49650 (lpfc_debugfs_max_slow_ring_trc - 1);
49651 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49652 dtp = phba->slow_ring_trc + i;
49653@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49654 !vport || !vport->disc_trc)
49655 return;
49656
49657- index = atomic_inc_return(&vport->disc_trc_cnt) &
49658+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49659 (lpfc_debugfs_max_disc_trc - 1);
49660 dtp = vport->disc_trc + index;
49661 dtp->fmt = fmt;
49662 dtp->data1 = data1;
49663 dtp->data2 = data2;
49664 dtp->data3 = data3;
49665- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49666+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49667 dtp->jif = jiffies;
49668 #endif
49669 return;
49670@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49671 !phba || !phba->slow_ring_trc)
49672 return;
49673
49674- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49675+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49676 (lpfc_debugfs_max_slow_ring_trc - 1);
49677 dtp = phba->slow_ring_trc + index;
49678 dtp->fmt = fmt;
49679 dtp->data1 = data1;
49680 dtp->data2 = data2;
49681 dtp->data3 = data3;
49682- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49683+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49684 dtp->jif = jiffies;
49685 #endif
49686 return;
49687@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49688 "slow_ring buffer\n");
49689 goto debug_failed;
49690 }
49691- atomic_set(&phba->slow_ring_trc_cnt, 0);
49692+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49693 memset(phba->slow_ring_trc, 0,
49694 (sizeof(struct lpfc_debugfs_trc) *
49695 lpfc_debugfs_max_slow_ring_trc));
49696@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49697 "buffer\n");
49698 goto debug_failed;
49699 }
49700- atomic_set(&vport->disc_trc_cnt, 0);
49701+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49702
49703 snprintf(name, sizeof(name), "discovery_trace");
49704 vport->debug_disc_trc =
49705diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49706index 635eeb3..038aef6 100644
49707--- a/drivers/scsi/lpfc/lpfc_init.c
49708+++ b/drivers/scsi/lpfc/lpfc_init.c
49709@@ -11194,8 +11194,10 @@ lpfc_init(void)
49710 "misc_register returned with status %d", error);
49711
49712 if (lpfc_enable_npiv) {
49713- lpfc_transport_functions.vport_create = lpfc_vport_create;
49714- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49715+ pax_open_kernel();
49716+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49717+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49718+ pax_close_kernel();
49719 }
49720 lpfc_transport_template =
49721 fc_attach_transport(&lpfc_transport_functions);
49722diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49723index 462453e..c0023a6 100644
49724--- a/drivers/scsi/lpfc/lpfc_scsi.c
49725+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49726@@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49727 uint32_t evt_posted;
49728
49729 spin_lock_irqsave(&phba->hbalock, flags);
49730- atomic_inc(&phba->num_rsrc_err);
49731+ atomic_inc_unchecked(&phba->num_rsrc_err);
49732 phba->last_rsrc_error_time = jiffies;
49733
49734 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49735@@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49736 unsigned long num_rsrc_err, num_cmd_success;
49737 int i;
49738
49739- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49740- num_cmd_success = atomic_read(&phba->num_cmd_success);
49741+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49742+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49743
49744 /*
49745 * The error and success command counters are global per
49746@@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49747 }
49748 }
49749 lpfc_destroy_vport_work_array(phba, vports);
49750- atomic_set(&phba->num_rsrc_err, 0);
49751- atomic_set(&phba->num_cmd_success, 0);
49752+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49753+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49754 }
49755
49756 /**
49757diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49758index 6fd7d40..b444223 100644
49759--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49760+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49761@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49762 {
49763 struct scsi_device *sdev = to_scsi_device(dev);
49764 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49765- static struct _raid_device *raid_device;
49766+ struct _raid_device *raid_device;
49767 unsigned long flags;
49768 Mpi2RaidVolPage0_t vol_pg0;
49769 Mpi2ConfigReply_t mpi_reply;
49770@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49771 {
49772 struct scsi_device *sdev = to_scsi_device(dev);
49773 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49774- static struct _raid_device *raid_device;
49775+ struct _raid_device *raid_device;
49776 unsigned long flags;
49777 Mpi2RaidVolPage0_t vol_pg0;
49778 Mpi2ConfigReply_t mpi_reply;
49779@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49780 struct fw_event_work *fw_event)
49781 {
49782 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49783- static struct _raid_device *raid_device;
49784+ struct _raid_device *raid_device;
49785 unsigned long flags;
49786 u16 handle;
49787
49788@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49789 u64 sas_address;
49790 struct _sas_device *sas_device;
49791 struct _sas_node *expander_device;
49792- static struct _raid_device *raid_device;
49793+ struct _raid_device *raid_device;
49794 u8 retry_count;
49795 unsigned long flags;
49796
49797diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49798index be8ce54..94ed33a 100644
49799--- a/drivers/scsi/pmcraid.c
49800+++ b/drivers/scsi/pmcraid.c
49801@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49802 res->scsi_dev = scsi_dev;
49803 scsi_dev->hostdata = res;
49804 res->change_detected = 0;
49805- atomic_set(&res->read_failures, 0);
49806- atomic_set(&res->write_failures, 0);
49807+ atomic_set_unchecked(&res->read_failures, 0);
49808+ atomic_set_unchecked(&res->write_failures, 0);
49809 rc = 0;
49810 }
49811 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49812@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49813
49814 /* If this was a SCSI read/write command keep count of errors */
49815 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49816- atomic_inc(&res->read_failures);
49817+ atomic_inc_unchecked(&res->read_failures);
49818 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49819- atomic_inc(&res->write_failures);
49820+ atomic_inc_unchecked(&res->write_failures);
49821
49822 if (!RES_IS_GSCSI(res->cfg_entry) &&
49823 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49824@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49825 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49826 * hrrq_id assigned here in queuecommand
49827 */
49828- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49829+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49830 pinstance->num_hrrq;
49831 cmd->cmd_done = pmcraid_io_done;
49832
49833@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49834 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49835 * hrrq_id assigned here in queuecommand
49836 */
49837- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49838+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49839 pinstance->num_hrrq;
49840
49841 if (request_size) {
49842@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49843
49844 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49845 /* add resources only after host is added into system */
49846- if (!atomic_read(&pinstance->expose_resources))
49847+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49848 return;
49849
49850 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49851@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49852 init_waitqueue_head(&pinstance->reset_wait_q);
49853
49854 atomic_set(&pinstance->outstanding_cmds, 0);
49855- atomic_set(&pinstance->last_message_id, 0);
49856- atomic_set(&pinstance->expose_resources, 0);
49857+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49858+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49859
49860 INIT_LIST_HEAD(&pinstance->free_res_q);
49861 INIT_LIST_HEAD(&pinstance->used_res_q);
49862@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49863 /* Schedule worker thread to handle CCN and take care of adding and
49864 * removing devices to OS
49865 */
49866- atomic_set(&pinstance->expose_resources, 1);
49867+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49868 schedule_work(&pinstance->worker_q);
49869 return rc;
49870
49871diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49872index e1d150f..6c6df44 100644
49873--- a/drivers/scsi/pmcraid.h
49874+++ b/drivers/scsi/pmcraid.h
49875@@ -748,7 +748,7 @@ struct pmcraid_instance {
49876 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49877
49878 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49879- atomic_t last_message_id;
49880+ atomic_unchecked_t last_message_id;
49881
49882 /* configuration table */
49883 struct pmcraid_config_table *cfg_table;
49884@@ -777,7 +777,7 @@ struct pmcraid_instance {
49885 atomic_t outstanding_cmds;
49886
49887 /* should add/delete resources to mid-layer now ?*/
49888- atomic_t expose_resources;
49889+ atomic_unchecked_t expose_resources;
49890
49891
49892
49893@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49894 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49895 };
49896 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49897- atomic_t read_failures; /* count of failed READ commands */
49898- atomic_t write_failures; /* count of failed WRITE commands */
49899+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49900+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49901
49902 /* To indicate add/delete/modify during CCN */
49903 u8 change_detected;
49904diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49905index 07befcf..c0bff13 100644
49906--- a/drivers/scsi/qla2xxx/qla_attr.c
49907+++ b/drivers/scsi/qla2xxx/qla_attr.c
49908@@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49909 return 0;
49910 }
49911
49912-struct fc_function_template qla2xxx_transport_functions = {
49913+fc_function_template_no_const qla2xxx_transport_functions = {
49914
49915 .show_host_node_name = 1,
49916 .show_host_port_name = 1,
49917@@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49918 .bsg_timeout = qla24xx_bsg_timeout,
49919 };
49920
49921-struct fc_function_template qla2xxx_transport_vport_functions = {
49922+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49923
49924 .show_host_node_name = 1,
49925 .show_host_port_name = 1,
49926diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49927index e665e81..16e84e6 100644
49928--- a/drivers/scsi/qla2xxx/qla_gbl.h
49929+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49930@@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49931 struct device_attribute;
49932 extern struct device_attribute *qla2x00_host_attrs[];
49933 struct fc_function_template;
49934-extern struct fc_function_template qla2xxx_transport_functions;
49935-extern struct fc_function_template qla2xxx_transport_vport_functions;
49936+extern fc_function_template_no_const qla2xxx_transport_functions;
49937+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49938 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49939 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49940 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49941diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49942index 19e99cc..b3c0b7b 100644
49943--- a/drivers/scsi/qla2xxx/qla_os.c
49944+++ b/drivers/scsi/qla2xxx/qla_os.c
49945@@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49946 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49947 /* Ok, a 64bit DMA mask is applicable. */
49948 ha->flags.enable_64bit_addressing = 1;
49949- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49950- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49951+ pax_open_kernel();
49952+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49953+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49954+ pax_close_kernel();
49955 return;
49956 }
49957 }
49958diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49959index 73a5022..4e0797c 100644
49960--- a/drivers/scsi/qla4xxx/ql4_def.h
49961+++ b/drivers/scsi/qla4xxx/ql4_def.h
49962@@ -305,7 +305,7 @@ struct ddb_entry {
49963 * (4000 only) */
49964 atomic_t relogin_timer; /* Max Time to wait for
49965 * relogin to complete */
49966- atomic_t relogin_retry_count; /* Num of times relogin has been
49967+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49968 * retried */
49969 uint32_t default_time2wait; /* Default Min time between
49970 * relogins (+aens) */
49971diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49972index 459b9f7..2930a68 100644
49973--- a/drivers/scsi/qla4xxx/ql4_os.c
49974+++ b/drivers/scsi/qla4xxx/ql4_os.c
49975@@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49976 */
49977 if (!iscsi_is_session_online(cls_sess)) {
49978 /* Reset retry relogin timer */
49979- atomic_inc(&ddb_entry->relogin_retry_count);
49980+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49981 DEBUG2(ql4_printk(KERN_INFO, ha,
49982 "%s: index[%d] relogin timed out-retrying"
49983 " relogin (%d), retry (%d)\n", __func__,
49984 ddb_entry->fw_ddb_index,
49985- atomic_read(&ddb_entry->relogin_retry_count),
49986+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49987 ddb_entry->default_time2wait + 4));
49988 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49989 atomic_set(&ddb_entry->retry_relogin_timer,
49990@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49991
49992 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49993 atomic_set(&ddb_entry->relogin_timer, 0);
49994- atomic_set(&ddb_entry->relogin_retry_count, 0);
49995+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49996 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49997 ddb_entry->default_relogin_timeout =
49998 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49999diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
50000index 88d46fe..7351be5 100644
50001--- a/drivers/scsi/scsi.c
50002+++ b/drivers/scsi/scsi.c
50003@@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
50004 struct Scsi_Host *host = cmd->device->host;
50005 int rtn = 0;
50006
50007- atomic_inc(&cmd->device->iorequest_cnt);
50008+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
50009
50010 /* check if the device is still usable */
50011 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
50012diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
50013index d99ab3b..c4ccdef 100644
50014--- a/drivers/scsi/scsi_lib.c
50015+++ b/drivers/scsi/scsi_lib.c
50016@@ -1472,7 +1472,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
50017 shost = sdev->host;
50018 scsi_init_cmd_errh(cmd);
50019 cmd->result = DID_NO_CONNECT << 16;
50020- atomic_inc(&cmd->device->iorequest_cnt);
50021+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
50022
50023 /*
50024 * SCSI request completion path will do scsi_device_unbusy(),
50025@@ -1498,9 +1498,9 @@ static void scsi_softirq_done(struct request *rq)
50026
50027 INIT_LIST_HEAD(&cmd->eh_entry);
50028
50029- atomic_inc(&cmd->device->iodone_cnt);
50030+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
50031 if (cmd->result)
50032- atomic_inc(&cmd->device->ioerr_cnt);
50033+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
50034
50035 disposition = scsi_decide_disposition(cmd);
50036 if (disposition != SUCCESS &&
50037diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
50038index 074e8cc..f612e5c 100644
50039--- a/drivers/scsi/scsi_sysfs.c
50040+++ b/drivers/scsi/scsi_sysfs.c
50041@@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
50042 char *buf) \
50043 { \
50044 struct scsi_device *sdev = to_scsi_device(dev); \
50045- unsigned long long count = atomic_read(&sdev->field); \
50046+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
50047 return snprintf(buf, 20, "0x%llx\n", count); \
50048 } \
50049 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
50050diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
50051index e51add0..1e06a96 100644
50052--- a/drivers/scsi/scsi_tgt_lib.c
50053+++ b/drivers/scsi/scsi_tgt_lib.c
50054@@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
50055 int err;
50056
50057 dprintk("%lx %u\n", uaddr, len);
50058- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
50059+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
50060 if (err) {
50061 /*
50062 * TODO: need to fixup sg_tablesize, max_segment_size,
50063diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
50064index f80908f..22aba76 100644
50065--- a/drivers/scsi/scsi_transport_fc.c
50066+++ b/drivers/scsi/scsi_transport_fc.c
50067@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
50068 * Netlink Infrastructure
50069 */
50070
50071-static atomic_t fc_event_seq;
50072+static atomic_unchecked_t fc_event_seq;
50073
50074 /**
50075 * fc_get_event_number - Obtain the next sequential FC event number
50076@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
50077 u32
50078 fc_get_event_number(void)
50079 {
50080- return atomic_add_return(1, &fc_event_seq);
50081+ return atomic_add_return_unchecked(1, &fc_event_seq);
50082 }
50083 EXPORT_SYMBOL(fc_get_event_number);
50084
50085@@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
50086 {
50087 int error;
50088
50089- atomic_set(&fc_event_seq, 0);
50090+ atomic_set_unchecked(&fc_event_seq, 0);
50091
50092 error = transport_class_register(&fc_host_class);
50093 if (error)
50094@@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
50095 char *cp;
50096
50097 *val = simple_strtoul(buf, &cp, 0);
50098- if ((*cp && (*cp != '\n')) || (*val < 0))
50099+ if (*cp && (*cp != '\n'))
50100 return -EINVAL;
50101 /*
50102 * Check for overflow; dev_loss_tmo is u32
50103diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
50104index 0102a2d..cc3f8e9 100644
50105--- a/drivers/scsi/scsi_transport_iscsi.c
50106+++ b/drivers/scsi/scsi_transport_iscsi.c
50107@@ -79,7 +79,7 @@ struct iscsi_internal {
50108 struct transport_container session_cont;
50109 };
50110
50111-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
50112+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
50113 static struct workqueue_struct *iscsi_eh_timer_workq;
50114
50115 static DEFINE_IDA(iscsi_sess_ida);
50116@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50117 int err;
50118
50119 ihost = shost->shost_data;
50120- session->sid = atomic_add_return(1, &iscsi_session_nr);
50121+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50122
50123 if (target_id == ISCSI_MAX_TARGET) {
50124 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50125@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50126 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50127 ISCSI_TRANSPORT_VERSION);
50128
50129- atomic_set(&iscsi_session_nr, 0);
50130+ atomic_set_unchecked(&iscsi_session_nr, 0);
50131
50132 err = class_register(&iscsi_transport_class);
50133 if (err)
50134diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50135index 13e8983..d306a68 100644
50136--- a/drivers/scsi/scsi_transport_srp.c
50137+++ b/drivers/scsi/scsi_transport_srp.c
50138@@ -36,7 +36,7 @@
50139 #include "scsi_transport_srp_internal.h"
50140
50141 struct srp_host_attrs {
50142- atomic_t next_port_id;
50143+ atomic_unchecked_t next_port_id;
50144 };
50145 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50146
50147@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50148 struct Scsi_Host *shost = dev_to_shost(dev);
50149 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50150
50151- atomic_set(&srp_host->next_port_id, 0);
50152+ atomic_set_unchecked(&srp_host->next_port_id, 0);
50153 return 0;
50154 }
50155
50156@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50157 rport_fast_io_fail_timedout);
50158 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50159
50160- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50161+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50162 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50163
50164 transport_setup_device(&rport->dev);
50165diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50166index bffbd4b..cb1b68a 100644
50167--- a/drivers/scsi/sd.c
50168+++ b/drivers/scsi/sd.c
50169@@ -2971,7 +2971,7 @@ static int sd_probe(struct device *dev)
50170 sdkp->disk = gd;
50171 sdkp->index = index;
50172 atomic_set(&sdkp->openers, 0);
50173- atomic_set(&sdkp->device->ioerr_cnt, 0);
50174+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50175
50176 if (!sdp->request_queue->rq_timeout) {
50177 if (sdp->type != TYPE_MOD)
50178diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50179index df5e961..df6b97f 100644
50180--- a/drivers/scsi/sg.c
50181+++ b/drivers/scsi/sg.c
50182@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50183 sdp->disk->disk_name,
50184 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50185 NULL,
50186- (char *)arg);
50187+ (char __user *)arg);
50188 case BLKTRACESTART:
50189 return blk_trace_startstop(sdp->device->request_queue, 1);
50190 case BLKTRACESTOP:
50191diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50192index 939edf4..3f50423 100644
50193--- a/drivers/spi/spi.c
50194+++ b/drivers/spi/spi.c
50195@@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
50196 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50197
50198 /* portable code must never pass more than 32 bytes */
50199-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50200+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50201
50202 static u8 *buf;
50203
50204diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50205index 2c61783..4d49e4e 100644
50206--- a/drivers/staging/android/timed_output.c
50207+++ b/drivers/staging/android/timed_output.c
50208@@ -25,7 +25,7 @@
50209 #include "timed_output.h"
50210
50211 static struct class *timed_output_class;
50212-static atomic_t device_count;
50213+static atomic_unchecked_t device_count;
50214
50215 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50216 char *buf)
50217@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50218 timed_output_class = class_create(THIS_MODULE, "timed_output");
50219 if (IS_ERR(timed_output_class))
50220 return PTR_ERR(timed_output_class);
50221- atomic_set(&device_count, 0);
50222+ atomic_set_unchecked(&device_count, 0);
50223 timed_output_class->dev_groups = timed_output_groups;
50224 }
50225
50226@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50227 if (ret < 0)
50228 return ret;
50229
50230- tdev->index = atomic_inc_return(&device_count);
50231+ tdev->index = atomic_inc_return_unchecked(&device_count);
50232 tdev->dev = device_create(timed_output_class, NULL,
50233 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50234 if (IS_ERR(tdev->dev))
50235diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50236index fe47cd3..19a1bd1 100644
50237--- a/drivers/staging/gdm724x/gdm_tty.c
50238+++ b/drivers/staging/gdm724x/gdm_tty.c
50239@@ -44,7 +44,7 @@
50240 #define gdm_tty_send_control(n, r, v, d, l) (\
50241 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50242
50243-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50244+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50245
50246 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50247 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50248diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50249index c270c9a..94ddf82 100644
50250--- a/drivers/staging/imx-drm/imx-drm-core.c
50251+++ b/drivers/staging/imx-drm/imx-drm-core.c
50252@@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
50253 if (imxdrm->pipes >= MAX_CRTC)
50254 return -EINVAL;
50255
50256- if (imxdrm->drm->open_count)
50257+ if (local_read(&imxdrm->drm->open_count))
50258 return -EBUSY;
50259
50260 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
50261diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50262index 3f8020c..649fded 100644
50263--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50264+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50265@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50266 return 0;
50267 }
50268
50269-sfw_test_client_ops_t brw_test_client;
50270-void brw_init_test_client(void)
50271-{
50272- brw_test_client.tso_init = brw_client_init;
50273- brw_test_client.tso_fini = brw_client_fini;
50274- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50275- brw_test_client.tso_done_rpc = brw_client_done_rpc;
50276+sfw_test_client_ops_t brw_test_client = {
50277+ .tso_init = brw_client_init,
50278+ .tso_fini = brw_client_fini,
50279+ .tso_prep_rpc = brw_client_prep_rpc,
50280+ .tso_done_rpc = brw_client_done_rpc,
50281 };
50282
50283 srpc_service_t brw_test_service;
50284diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50285index 050723a..fa6fdf1 100644
50286--- a/drivers/staging/lustre/lnet/selftest/framework.c
50287+++ b/drivers/staging/lustre/lnet/selftest/framework.c
50288@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50289
50290 extern sfw_test_client_ops_t ping_test_client;
50291 extern srpc_service_t ping_test_service;
50292-extern void ping_init_test_client(void);
50293 extern void ping_init_test_service(void);
50294
50295 extern sfw_test_client_ops_t brw_test_client;
50296 extern srpc_service_t brw_test_service;
50297-extern void brw_init_test_client(void);
50298 extern void brw_init_test_service(void);
50299
50300
50301@@ -1684,12 +1682,10 @@ sfw_startup (void)
50302 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50303 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50304
50305- brw_init_test_client();
50306 brw_init_test_service();
50307 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50308 LASSERT (rc == 0);
50309
50310- ping_init_test_client();
50311 ping_init_test_service();
50312 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50313 LASSERT (rc == 0);
50314diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50315index 750cac4..e4d751f 100644
50316--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50317+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50318@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50319 return 0;
50320 }
50321
50322-sfw_test_client_ops_t ping_test_client;
50323-void ping_init_test_client(void)
50324-{
50325- ping_test_client.tso_init = ping_client_init;
50326- ping_test_client.tso_fini = ping_client_fini;
50327- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50328- ping_test_client.tso_done_rpc = ping_client_done_rpc;
50329-}
50330+sfw_test_client_ops_t ping_test_client = {
50331+ .tso_init = ping_client_init,
50332+ .tso_fini = ping_client_fini,
50333+ .tso_prep_rpc = ping_client_prep_rpc,
50334+ .tso_done_rpc = ping_client_done_rpc,
50335+};
50336
50337 srpc_service_t ping_test_service;
50338 void ping_init_test_service(void)
50339diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50340index 3e25f00..0d59cf5 100644
50341--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50342+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50343@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50344 ldlm_completion_callback lcs_completion;
50345 ldlm_blocking_callback lcs_blocking;
50346 ldlm_glimpse_callback lcs_glimpse;
50347-};
50348+} __no_const;
50349
50350 /* ldlm_lockd.c */
50351 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50352diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50353index 72cf3fe..4beac19 100644
50354--- a/drivers/staging/lustre/lustre/include/obd.h
50355+++ b/drivers/staging/lustre/lustre/include/obd.h
50356@@ -1427,7 +1427,7 @@ struct md_ops {
50357 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50358 * wrapper function in include/linux/obd_class.h.
50359 */
50360-};
50361+} __no_const;
50362
50363 struct lsm_operations {
50364 void (*lsm_free)(struct lov_stripe_md *);
50365diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50366index 986bf38..eab2558f 100644
50367--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50368+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50369@@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50370 int added = (mode == LCK_NL);
50371 int overlaps = 0;
50372 int splitted = 0;
50373- const struct ldlm_callback_suite null_cbs = { NULL };
50374+ const struct ldlm_callback_suite null_cbs = { };
50375
50376 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50377 LPU64" end "LPU64"\n", *flags,
50378diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50379index e947b91..f408990 100644
50380--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50381+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50382@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50383 int LL_PROC_PROTO(proc_console_max_delay_cs)
50384 {
50385 int rc, max_delay_cs;
50386- ctl_table_t dummy = *table;
50387+ ctl_table_no_const dummy = *table;
50388 cfs_duration_t d;
50389
50390 dummy.data = &max_delay_cs;
50391@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50392 int LL_PROC_PROTO(proc_console_min_delay_cs)
50393 {
50394 int rc, min_delay_cs;
50395- ctl_table_t dummy = *table;
50396+ ctl_table_no_const dummy = *table;
50397 cfs_duration_t d;
50398
50399 dummy.data = &min_delay_cs;
50400@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50401 int LL_PROC_PROTO(proc_console_backoff)
50402 {
50403 int rc, backoff;
50404- ctl_table_t dummy = *table;
50405+ ctl_table_no_const dummy = *table;
50406
50407 dummy.data = &backoff;
50408 dummy.proc_handler = &proc_dointvec;
50409diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50410index 24ae26d..9d09cab 100644
50411--- a/drivers/staging/lustre/lustre/libcfs/module.c
50412+++ b/drivers/staging/lustre/lustre/libcfs/module.c
50413@@ -313,11 +313,11 @@ out:
50414
50415
50416 struct cfs_psdev_ops libcfs_psdev_ops = {
50417- libcfs_psdev_open,
50418- libcfs_psdev_release,
50419- NULL,
50420- NULL,
50421- libcfs_ioctl
50422+ .p_open = libcfs_psdev_open,
50423+ .p_close = libcfs_psdev_release,
50424+ .p_read = NULL,
50425+ .p_write = NULL,
50426+ .p_ioctl = libcfs_ioctl
50427 };
50428
50429 extern int insert_proc(void);
50430diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50431index 7fbc18e..f982071 100644
50432--- a/drivers/staging/lustre/lustre/llite/dir.c
50433+++ b/drivers/staging/lustre/lustre/llite/dir.c
50434@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50435 int mode;
50436 int err;
50437
50438- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50439+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50440 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50441 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50442 lump);
50443diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50444index f670469..03b7438 100644
50445--- a/drivers/staging/media/solo6x10/solo6x10-core.c
50446+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50447@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50448
50449 static int solo_sysfs_init(struct solo_dev *solo_dev)
50450 {
50451- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50452+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50453 struct device *dev = &solo_dev->dev;
50454 const char *driver;
50455 int i;
50456diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50457index 74f037b..5b5bb76 100644
50458--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50459+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50460@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50461
50462 int solo_g723_init(struct solo_dev *solo_dev)
50463 {
50464- static struct snd_device_ops ops = { NULL };
50465+ static struct snd_device_ops ops = { };
50466 struct snd_card *card;
50467 struct snd_kcontrol_new kctl;
50468 char name[32];
50469diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50470index 7f2f247..d999137 100644
50471--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50472+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50473@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50474
50475 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50476 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50477- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50478+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50479 if (p2m_id < 0)
50480 p2m_id = -p2m_id;
50481 }
50482diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50483index 8964f8b..36eb087 100644
50484--- a/drivers/staging/media/solo6x10/solo6x10.h
50485+++ b/drivers/staging/media/solo6x10/solo6x10.h
50486@@ -237,7 +237,7 @@ struct solo_dev {
50487
50488 /* P2M DMA Engine */
50489 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50490- atomic_t p2m_count;
50491+ atomic_unchecked_t p2m_count;
50492 int p2m_jiffies;
50493 unsigned int p2m_timeouts;
50494
50495diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50496index a0f4868..139f1fb 100644
50497--- a/drivers/staging/octeon/ethernet-rx.c
50498+++ b/drivers/staging/octeon/ethernet-rx.c
50499@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50500 /* Increment RX stats for virtual ports */
50501 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50502 #ifdef CONFIG_64BIT
50503- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50504- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50505+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50506+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50507 #else
50508- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50509- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50510+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50511+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50512 #endif
50513 }
50514 netif_receive_skb(skb);
50515@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50516 dev->name);
50517 */
50518 #ifdef CONFIG_64BIT
50519- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50520+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50521 #else
50522- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50523+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50524 #endif
50525 dev_kfree_skb_irq(skb);
50526 }
50527diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50528index ff7214a..6dd90f0 100644
50529--- a/drivers/staging/octeon/ethernet.c
50530+++ b/drivers/staging/octeon/ethernet.c
50531@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50532 * since the RX tasklet also increments it.
50533 */
50534 #ifdef CONFIG_64BIT
50535- atomic64_add(rx_status.dropped_packets,
50536- (atomic64_t *)&priv->stats.rx_dropped);
50537+ atomic64_add_unchecked(rx_status.dropped_packets,
50538+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50539 #else
50540- atomic_add(rx_status.dropped_packets,
50541- (atomic_t *)&priv->stats.rx_dropped);
50542+ atomic_add_unchecked(rx_status.dropped_packets,
50543+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50544 #endif
50545 }
50546
50547diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50548index c274b34..f84de76 100644
50549--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50550+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50551@@ -271,7 +271,7 @@ struct hal_ops {
50552 s32 (*c2h_handler)(struct adapter *padapter,
50553 struct c2h_evt_hdr *c2h_evt);
50554 c2h_id_filter c2h_id_filter_ccx;
50555-};
50556+} __no_const;
50557
50558 enum rt_eeprom_type {
50559 EEPROM_93C46,
50560diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50561index e8790f8..b4a5980 100644
50562--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50563+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50564@@ -124,7 +124,7 @@ struct _io_ops {
50565 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50566 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50567 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50568-};
50569+} __no_const;
50570
50571 struct io_req {
50572 struct list_head list;
50573diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50574index dc23395..cf7e9b1 100644
50575--- a/drivers/staging/rtl8712/rtl871x_io.h
50576+++ b/drivers/staging/rtl8712/rtl871x_io.h
50577@@ -108,7 +108,7 @@ struct _io_ops {
50578 u8 *pmem);
50579 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50580 u8 *pmem);
50581-};
50582+} __no_const;
50583
50584 struct io_req {
50585 struct list_head list;
50586diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50587index d183f4b..3f4903d 100644
50588--- a/drivers/staging/rtl8723au/include/hal_intf.h
50589+++ b/drivers/staging/rtl8723au/include/hal_intf.h
50590@@ -251,7 +251,7 @@ struct hal_ops {
50591 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50592 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50593 c2h_id_filter c2h_id_filter_ccx;
50594-};
50595+} __no_const;
50596
50597 enum rt_eeprom_type {
50598 EEPROM_93C46,
50599diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50600index 8d39d800..3f21c0c 100644
50601--- a/drivers/staging/rtl8723au/include/rtw_io.h
50602+++ b/drivers/staging/rtl8723au/include/rtw_io.h
50603@@ -130,7 +130,7 @@ struct _io_ops
50604 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50605 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50606
50607-};
50608+} __no_const;
50609
50610 struct io_req {
50611 struct list_head list;
50612diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50613index fe6c951..72935ba 100644
50614--- a/drivers/staging/sbe-2t3e3/netdev.c
50615+++ b/drivers/staging/sbe-2t3e3/netdev.c
50616@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50617 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50618
50619 if (rlen)
50620- if (copy_to_user(data, &resp, rlen))
50621+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50622 return -EFAULT;
50623
50624 return 0;
50625diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50626index a863a98..d272795 100644
50627--- a/drivers/staging/usbip/vhci.h
50628+++ b/drivers/staging/usbip/vhci.h
50629@@ -83,7 +83,7 @@ struct vhci_hcd {
50630 unsigned resuming:1;
50631 unsigned long re_timeout;
50632
50633- atomic_t seqnum;
50634+ atomic_unchecked_t seqnum;
50635
50636 /*
50637 * NOTE:
50638diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50639index 70e1755..de41855 100644
50640--- a/drivers/staging/usbip/vhci_hcd.c
50641+++ b/drivers/staging/usbip/vhci_hcd.c
50642@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50643
50644 spin_lock(&vdev->priv_lock);
50645
50646- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50647+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50648 if (priv->seqnum == 0xffff)
50649 dev_info(&urb->dev->dev, "seqnum max\n");
50650
50651@@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50652 return -ENOMEM;
50653 }
50654
50655- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50656+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50657 if (unlink->seqnum == 0xffff)
50658 pr_info("seqnum max\n");
50659
50660@@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50661 vdev->rhport = rhport;
50662 }
50663
50664- atomic_set(&vhci->seqnum, 0);
50665+ atomic_set_unchecked(&vhci->seqnum, 0);
50666 spin_lock_init(&vhci->lock);
50667
50668 hcd->power_budget = 0; /* no limit */
50669diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50670index d07fcb5..358e1e1 100644
50671--- a/drivers/staging/usbip/vhci_rx.c
50672+++ b/drivers/staging/usbip/vhci_rx.c
50673@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50674 if (!urb) {
50675 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50676 pr_info("max seqnum %d\n",
50677- atomic_read(&the_controller->seqnum));
50678+ atomic_read_unchecked(&the_controller->seqnum));
50679 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50680 return;
50681 }
50682diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50683index 6eecd53..29317c6 100644
50684--- a/drivers/staging/vt6655/hostap.c
50685+++ b/drivers/staging/vt6655/hostap.c
50686@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50687 *
50688 */
50689
50690+static net_device_ops_no_const apdev_netdev_ops;
50691+
50692 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50693 {
50694 PSDevice apdev_priv;
50695 struct net_device *dev = pDevice->dev;
50696 int ret;
50697- const struct net_device_ops apdev_netdev_ops = {
50698- .ndo_start_xmit = pDevice->tx_80211,
50699- };
50700
50701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50702
50703@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50704 *apdev_priv = *pDevice;
50705 eth_hw_addr_inherit(pDevice->apdev, dev);
50706
50707+ /* only half broken now */
50708+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50709 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50710
50711 pDevice->apdev->type = ARPHRD_IEEE80211;
50712diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50713index 67ba48b..24e602f 100644
50714--- a/drivers/staging/vt6656/hostap.c
50715+++ b/drivers/staging/vt6656/hostap.c
50716@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50717 *
50718 */
50719
50720+static net_device_ops_no_const apdev_netdev_ops;
50721+
50722 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50723 {
50724 struct vnt_private *apdev_priv;
50725 struct net_device *dev = pDevice->dev;
50726 int ret;
50727- const struct net_device_ops apdev_netdev_ops = {
50728- .ndo_start_xmit = pDevice->tx_80211,
50729- };
50730
50731 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50732
50733@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50734 *apdev_priv = *pDevice;
50735 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50736
50737+ /* only half broken now */
50738+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50739 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50740
50741 pDevice->apdev->type = ARPHRD_IEEE80211;
50742diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50743index e7e9372..161f530 100644
50744--- a/drivers/target/sbp/sbp_target.c
50745+++ b/drivers/target/sbp/sbp_target.c
50746@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50747
50748 #define SESSION_MAINTENANCE_INTERVAL HZ
50749
50750-static atomic_t login_id = ATOMIC_INIT(0);
50751+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50752
50753 static void session_maintenance_work(struct work_struct *);
50754 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50755@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50756 login->lun = se_lun;
50757 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50758 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50759- login->login_id = atomic_inc_return(&login_id);
50760+ login->login_id = atomic_inc_return_unchecked(&login_id);
50761
50762 login->tgt_agt = sbp_target_agent_register(login);
50763 if (IS_ERR(login->tgt_agt)) {
50764diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50765index 6ea95d2..88607b4 100644
50766--- a/drivers/target/target_core_device.c
50767+++ b/drivers/target/target_core_device.c
50768@@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50769 spin_lock_init(&dev->se_tmr_lock);
50770 spin_lock_init(&dev->qf_cmd_lock);
50771 sema_init(&dev->caw_sem, 1);
50772- atomic_set(&dev->dev_ordered_id, 0);
50773+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50774 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50775 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50776 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50777diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50778index 14772e9..42d9f63 100644
50779--- a/drivers/target/target_core_transport.c
50780+++ b/drivers/target/target_core_transport.c
50781@@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50782 * Used to determine when ORDERED commands should go from
50783 * Dormant to Active status.
50784 */
50785- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50786+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50787 smp_mb__after_atomic_inc();
50788 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50789 cmd->se_ordered_id, cmd->sam_task_attr,
50790diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50791index 04b1be7..5eff86d 100644
50792--- a/drivers/thermal/of-thermal.c
50793+++ b/drivers/thermal/of-thermal.c
50794@@ -30,6 +30,7 @@
50795 #include <linux/err.h>
50796 #include <linux/export.h>
50797 #include <linux/string.h>
50798+#include <linux/mm.h>
50799
50800 #include "thermal_core.h"
50801
50802@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50803 tz->get_trend = get_trend;
50804 tz->sensor_data = data;
50805
50806- tzd->ops->get_temp = of_thermal_get_temp;
50807- tzd->ops->get_trend = of_thermal_get_trend;
50808+ pax_open_kernel();
50809+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50810+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50811+ pax_close_kernel();
50812 mutex_unlock(&tzd->lock);
50813
50814 return tzd;
50815@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50816 return;
50817
50818 mutex_lock(&tzd->lock);
50819- tzd->ops->get_temp = NULL;
50820- tzd->ops->get_trend = NULL;
50821+ pax_open_kernel();
50822+ *(void **)&tzd->ops->get_temp = NULL;
50823+ *(void **)&tzd->ops->get_trend = NULL;
50824+ pax_close_kernel();
50825
50826 tz->get_temp = NULL;
50827 tz->get_trend = NULL;
50828diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50829index a57bb5a..1f727d33 100644
50830--- a/drivers/tty/cyclades.c
50831+++ b/drivers/tty/cyclades.c
50832@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50833 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50834 info->port.count);
50835 #endif
50836- info->port.count++;
50837+ atomic_inc(&info->port.count);
50838 #ifdef CY_DEBUG_COUNT
50839 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50840- current->pid, info->port.count);
50841+ current->pid, atomic_read(&info->port.count));
50842 #endif
50843
50844 /*
50845@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50846 for (j = 0; j < cy_card[i].nports; j++) {
50847 info = &cy_card[i].ports[j];
50848
50849- if (info->port.count) {
50850+ if (atomic_read(&info->port.count)) {
50851 /* XXX is the ldisc num worth this? */
50852 struct tty_struct *tty;
50853 struct tty_ldisc *ld;
50854diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50855index 0ff7fda..dbc7d52 100644
50856--- a/drivers/tty/hvc/hvc_console.c
50857+++ b/drivers/tty/hvc/hvc_console.c
50858@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50859
50860 spin_lock_irqsave(&hp->port.lock, flags);
50861 /* Check and then increment for fast path open. */
50862- if (hp->port.count++ > 0) {
50863+ if (atomic_inc_return(&hp->port.count) > 1) {
50864 spin_unlock_irqrestore(&hp->port.lock, flags);
50865 hvc_kick();
50866 return 0;
50867@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50868
50869 spin_lock_irqsave(&hp->port.lock, flags);
50870
50871- if (--hp->port.count == 0) {
50872+ if (atomic_dec_return(&hp->port.count) == 0) {
50873 spin_unlock_irqrestore(&hp->port.lock, flags);
50874 /* We are done with the tty pointer now. */
50875 tty_port_tty_set(&hp->port, NULL);
50876@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50877 */
50878 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50879 } else {
50880- if (hp->port.count < 0)
50881+ if (atomic_read(&hp->port.count) < 0)
50882 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50883- hp->vtermno, hp->port.count);
50884+ hp->vtermno, atomic_read(&hp->port.count));
50885 spin_unlock_irqrestore(&hp->port.lock, flags);
50886 }
50887 }
50888@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50889 * open->hangup case this can be called after the final close so prevent
50890 * that from happening for now.
50891 */
50892- if (hp->port.count <= 0) {
50893+ if (atomic_read(&hp->port.count) <= 0) {
50894 spin_unlock_irqrestore(&hp->port.lock, flags);
50895 return;
50896 }
50897
50898- hp->port.count = 0;
50899+ atomic_set(&hp->port.count, 0);
50900 spin_unlock_irqrestore(&hp->port.lock, flags);
50901 tty_port_tty_set(&hp->port, NULL);
50902
50903@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50904 return -EPIPE;
50905
50906 /* FIXME what's this (unprotected) check for? */
50907- if (hp->port.count <= 0)
50908+ if (atomic_read(&hp->port.count) <= 0)
50909 return -EIO;
50910
50911 spin_lock_irqsave(&hp->lock, flags);
50912diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50913index 81e939e..95ead10 100644
50914--- a/drivers/tty/hvc/hvcs.c
50915+++ b/drivers/tty/hvc/hvcs.c
50916@@ -83,6 +83,7 @@
50917 #include <asm/hvcserver.h>
50918 #include <asm/uaccess.h>
50919 #include <asm/vio.h>
50920+#include <asm/local.h>
50921
50922 /*
50923 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50924@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50925
50926 spin_lock_irqsave(&hvcsd->lock, flags);
50927
50928- if (hvcsd->port.count > 0) {
50929+ if (atomic_read(&hvcsd->port.count) > 0) {
50930 spin_unlock_irqrestore(&hvcsd->lock, flags);
50931 printk(KERN_INFO "HVCS: vterm state unchanged. "
50932 "The hvcs device node is still in use.\n");
50933@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50934 }
50935 }
50936
50937- hvcsd->port.count = 0;
50938+ atomic_set(&hvcsd->port.count, 0);
50939 hvcsd->port.tty = tty;
50940 tty->driver_data = hvcsd;
50941
50942@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50943 unsigned long flags;
50944
50945 spin_lock_irqsave(&hvcsd->lock, flags);
50946- hvcsd->port.count++;
50947+ atomic_inc(&hvcsd->port.count);
50948 hvcsd->todo_mask |= HVCS_SCHED_READ;
50949 spin_unlock_irqrestore(&hvcsd->lock, flags);
50950
50951@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50952 hvcsd = tty->driver_data;
50953
50954 spin_lock_irqsave(&hvcsd->lock, flags);
50955- if (--hvcsd->port.count == 0) {
50956+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50957
50958 vio_disable_interrupts(hvcsd->vdev);
50959
50960@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50961
50962 free_irq(irq, hvcsd);
50963 return;
50964- } else if (hvcsd->port.count < 0) {
50965+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50966 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50967 " is missmanaged.\n",
50968- hvcsd->vdev->unit_address, hvcsd->port.count);
50969+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50970 }
50971
50972 spin_unlock_irqrestore(&hvcsd->lock, flags);
50973@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50974
50975 spin_lock_irqsave(&hvcsd->lock, flags);
50976 /* Preserve this so that we know how many kref refs to put */
50977- temp_open_count = hvcsd->port.count;
50978+ temp_open_count = atomic_read(&hvcsd->port.count);
50979
50980 /*
50981 * Don't kref put inside the spinlock because the destruction
50982@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50983 tty->driver_data = NULL;
50984 hvcsd->port.tty = NULL;
50985
50986- hvcsd->port.count = 0;
50987+ atomic_set(&hvcsd->port.count, 0);
50988
50989 /* This will drop any buffered data on the floor which is OK in a hangup
50990 * scenario. */
50991@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50992 * the middle of a write operation? This is a crummy place to do this
50993 * but we want to keep it all in the spinlock.
50994 */
50995- if (hvcsd->port.count <= 0) {
50996+ if (atomic_read(&hvcsd->port.count) <= 0) {
50997 spin_unlock_irqrestore(&hvcsd->lock, flags);
50998 return -ENODEV;
50999 }
51000@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
51001 {
51002 struct hvcs_struct *hvcsd = tty->driver_data;
51003
51004- if (!hvcsd || hvcsd->port.count <= 0)
51005+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
51006 return 0;
51007
51008 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
51009diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
51010index 4190199..06d5bfa 100644
51011--- a/drivers/tty/hvc/hvsi.c
51012+++ b/drivers/tty/hvc/hvsi.c
51013@@ -85,7 +85,7 @@ struct hvsi_struct {
51014 int n_outbuf;
51015 uint32_t vtermno;
51016 uint32_t virq;
51017- atomic_t seqno; /* HVSI packet sequence number */
51018+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
51019 uint16_t mctrl;
51020 uint8_t state; /* HVSI protocol state */
51021 uint8_t flags;
51022@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
51023
51024 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
51025 packet.hdr.len = sizeof(struct hvsi_query_response);
51026- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51027+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51028 packet.verb = VSV_SEND_VERSION_NUMBER;
51029 packet.u.version = HVSI_VERSION;
51030 packet.query_seqno = query_seqno+1;
51031@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
51032
51033 packet.hdr.type = VS_QUERY_PACKET_HEADER;
51034 packet.hdr.len = sizeof(struct hvsi_query);
51035- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51036+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51037 packet.verb = verb;
51038
51039 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
51040@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
51041 int wrote;
51042
51043 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
51044- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51045+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51046 packet.hdr.len = sizeof(struct hvsi_control);
51047 packet.verb = VSV_SET_MODEM_CTL;
51048 packet.mask = HVSI_TSDTR;
51049@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
51050 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
51051
51052 packet.hdr.type = VS_DATA_PACKET_HEADER;
51053- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51054+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51055 packet.hdr.len = count + sizeof(struct hvsi_header);
51056 memcpy(&packet.data, buf, count);
51057
51058@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
51059 struct hvsi_control packet __ALIGNED__;
51060
51061 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
51062- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51063+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51064 packet.hdr.len = 6;
51065 packet.verb = VSV_CLOSE_PROTOCOL;
51066
51067@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
51068
51069 tty_port_tty_set(&hp->port, tty);
51070 spin_lock_irqsave(&hp->lock, flags);
51071- hp->port.count++;
51072+ atomic_inc(&hp->port.count);
51073 atomic_set(&hp->seqno, 0);
51074 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
51075 spin_unlock_irqrestore(&hp->lock, flags);
51076@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51077
51078 spin_lock_irqsave(&hp->lock, flags);
51079
51080- if (--hp->port.count == 0) {
51081+ if (atomic_dec_return(&hp->port.count) == 0) {
51082 tty_port_tty_set(&hp->port, NULL);
51083 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
51084
51085@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51086
51087 spin_lock_irqsave(&hp->lock, flags);
51088 }
51089- } else if (hp->port.count < 0)
51090+ } else if (atomic_read(&hp->port.count) < 0)
51091 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
51092- hp - hvsi_ports, hp->port.count);
51093+ hp - hvsi_ports, atomic_read(&hp->port.count));
51094
51095 spin_unlock_irqrestore(&hp->lock, flags);
51096 }
51097@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
51098 tty_port_tty_set(&hp->port, NULL);
51099
51100 spin_lock_irqsave(&hp->lock, flags);
51101- hp->port.count = 0;
51102+ atomic_set(&hp->port.count, 0);
51103 hp->n_outbuf = 0;
51104 spin_unlock_irqrestore(&hp->lock, flags);
51105 }
51106diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
51107index 7ae6c29..05c6dba 100644
51108--- a/drivers/tty/hvc/hvsi_lib.c
51109+++ b/drivers/tty/hvc/hvsi_lib.c
51110@@ -8,7 +8,7 @@
51111
51112 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
51113 {
51114- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51115+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51116
51117 /* Assumes that always succeeds, works in practice */
51118 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51119@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51120
51121 /* Reset state */
51122 pv->established = 0;
51123- atomic_set(&pv->seqno, 0);
51124+ atomic_set_unchecked(&pv->seqno, 0);
51125
51126 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51127
51128diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51129index 17ee3bf..8d2520d 100644
51130--- a/drivers/tty/ipwireless/tty.c
51131+++ b/drivers/tty/ipwireless/tty.c
51132@@ -28,6 +28,7 @@
51133 #include <linux/tty_driver.h>
51134 #include <linux/tty_flip.h>
51135 #include <linux/uaccess.h>
51136+#include <asm/local.h>
51137
51138 #include "tty.h"
51139 #include "network.h"
51140@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51141 mutex_unlock(&tty->ipw_tty_mutex);
51142 return -ENODEV;
51143 }
51144- if (tty->port.count == 0)
51145+ if (atomic_read(&tty->port.count) == 0)
51146 tty->tx_bytes_queued = 0;
51147
51148- tty->port.count++;
51149+ atomic_inc(&tty->port.count);
51150
51151 tty->port.tty = linux_tty;
51152 linux_tty->driver_data = tty;
51153@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51154
51155 static void do_ipw_close(struct ipw_tty *tty)
51156 {
51157- tty->port.count--;
51158-
51159- if (tty->port.count == 0) {
51160+ if (atomic_dec_return(&tty->port.count) == 0) {
51161 struct tty_struct *linux_tty = tty->port.tty;
51162
51163 if (linux_tty != NULL) {
51164@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51165 return;
51166
51167 mutex_lock(&tty->ipw_tty_mutex);
51168- if (tty->port.count == 0) {
51169+ if (atomic_read(&tty->port.count) == 0) {
51170 mutex_unlock(&tty->ipw_tty_mutex);
51171 return;
51172 }
51173@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51174
51175 mutex_lock(&tty->ipw_tty_mutex);
51176
51177- if (!tty->port.count) {
51178+ if (!atomic_read(&tty->port.count)) {
51179 mutex_unlock(&tty->ipw_tty_mutex);
51180 return;
51181 }
51182@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51183 return -ENODEV;
51184
51185 mutex_lock(&tty->ipw_tty_mutex);
51186- if (!tty->port.count) {
51187+ if (!atomic_read(&tty->port.count)) {
51188 mutex_unlock(&tty->ipw_tty_mutex);
51189 return -EINVAL;
51190 }
51191@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51192 if (!tty)
51193 return -ENODEV;
51194
51195- if (!tty->port.count)
51196+ if (!atomic_read(&tty->port.count))
51197 return -EINVAL;
51198
51199 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51200@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51201 if (!tty)
51202 return 0;
51203
51204- if (!tty->port.count)
51205+ if (!atomic_read(&tty->port.count))
51206 return 0;
51207
51208 return tty->tx_bytes_queued;
51209@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51210 if (!tty)
51211 return -ENODEV;
51212
51213- if (!tty->port.count)
51214+ if (!atomic_read(&tty->port.count))
51215 return -EINVAL;
51216
51217 return get_control_lines(tty);
51218@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51219 if (!tty)
51220 return -ENODEV;
51221
51222- if (!tty->port.count)
51223+ if (!atomic_read(&tty->port.count))
51224 return -EINVAL;
51225
51226 return set_control_lines(tty, set, clear);
51227@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51228 if (!tty)
51229 return -ENODEV;
51230
51231- if (!tty->port.count)
51232+ if (!atomic_read(&tty->port.count))
51233 return -EINVAL;
51234
51235 /* FIXME: Exactly how is the tty object locked here .. */
51236@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51237 * are gone */
51238 mutex_lock(&ttyj->ipw_tty_mutex);
51239 }
51240- while (ttyj->port.count)
51241+ while (atomic_read(&ttyj->port.count))
51242 do_ipw_close(ttyj);
51243 ipwireless_disassociate_network_ttys(network,
51244 ttyj->channel_idx);
51245diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51246index 1deaca4..c8582d4 100644
51247--- a/drivers/tty/moxa.c
51248+++ b/drivers/tty/moxa.c
51249@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51250 }
51251
51252 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51253- ch->port.count++;
51254+ atomic_inc(&ch->port.count);
51255 tty->driver_data = ch;
51256 tty_port_tty_set(&ch->port, tty);
51257 mutex_lock(&ch->port.mutex);
51258diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51259index 2ebe47b..3205833 100644
51260--- a/drivers/tty/n_gsm.c
51261+++ b/drivers/tty/n_gsm.c
51262@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51263 spin_lock_init(&dlci->lock);
51264 mutex_init(&dlci->mutex);
51265 dlci->fifo = &dlci->_fifo;
51266- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51267+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51268 kfree(dlci);
51269 return NULL;
51270 }
51271@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51272 struct gsm_dlci *dlci = tty->driver_data;
51273 struct tty_port *port = &dlci->port;
51274
51275- port->count++;
51276+ atomic_inc(&port->count);
51277 tty_port_tty_set(port, tty);
51278
51279 dlci->modem_rx = 0;
51280diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51281index 0391f17..31fa586 100644
51282--- a/drivers/tty/n_tty.c
51283+++ b/drivers/tty/n_tty.c
51284@@ -115,7 +115,7 @@ struct n_tty_data {
51285 int minimum_to_wake;
51286
51287 /* consumer-published */
51288- size_t read_tail;
51289+ size_t read_tail __intentional_overflow(-1);
51290 size_t line_start;
51291
51292 /* protected by output lock */
51293@@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51294 {
51295 *ops = tty_ldisc_N_TTY;
51296 ops->owner = NULL;
51297- ops->refcount = ops->flags = 0;
51298+ atomic_set(&ops->refcount, 0);
51299+ ops->flags = 0;
51300 }
51301 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51302diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51303index 25c9bc7..24077b7 100644
51304--- a/drivers/tty/pty.c
51305+++ b/drivers/tty/pty.c
51306@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51307 panic("Couldn't register Unix98 pts driver");
51308
51309 /* Now create the /dev/ptmx special device */
51310+ pax_open_kernel();
51311 tty_default_fops(&ptmx_fops);
51312- ptmx_fops.open = ptmx_open;
51313+ *(void **)&ptmx_fops.open = ptmx_open;
51314+ pax_close_kernel();
51315
51316 cdev_init(&ptmx_cdev, &ptmx_fops);
51317 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51318diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51319index 383c4c7..d408e21 100644
51320--- a/drivers/tty/rocket.c
51321+++ b/drivers/tty/rocket.c
51322@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51323 tty->driver_data = info;
51324 tty_port_tty_set(port, tty);
51325
51326- if (port->count++ == 0) {
51327+ if (atomic_inc_return(&port->count) == 1) {
51328 atomic_inc(&rp_num_ports_open);
51329
51330 #ifdef ROCKET_DEBUG_OPEN
51331@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51332 #endif
51333 }
51334 #ifdef ROCKET_DEBUG_OPEN
51335- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51336+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51337 #endif
51338
51339 /*
51340@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51341 spin_unlock_irqrestore(&info->port.lock, flags);
51342 return;
51343 }
51344- if (info->port.count)
51345+ if (atomic_read(&info->port.count))
51346 atomic_dec(&rp_num_ports_open);
51347 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51348 spin_unlock_irqrestore(&info->port.lock, flags);
51349diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51350index 1274499..f541382 100644
51351--- a/drivers/tty/serial/ioc4_serial.c
51352+++ b/drivers/tty/serial/ioc4_serial.c
51353@@ -437,7 +437,7 @@ struct ioc4_soft {
51354 } is_intr_info[MAX_IOC4_INTR_ENTS];
51355
51356 /* Number of entries active in the above array */
51357- atomic_t is_num_intrs;
51358+ atomic_unchecked_t is_num_intrs;
51359 } is_intr_type[IOC4_NUM_INTR_TYPES];
51360
51361 /* is_ir_lock must be held while
51362@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51363 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51364 || (type == IOC4_OTHER_INTR_TYPE)));
51365
51366- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51367+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51368 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51369
51370 /* Save off the lower level interrupt handler */
51371@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51372
51373 soft = arg;
51374 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51375- num_intrs = (int)atomic_read(
51376+ num_intrs = (int)atomic_read_unchecked(
51377 &soft->is_intr_type[intr_type].is_num_intrs);
51378
51379 this_mir = this_ir = pending_intrs(soft, intr_type);
51380diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51381index a260cde..6b2b5ce 100644
51382--- a/drivers/tty/serial/kgdboc.c
51383+++ b/drivers/tty/serial/kgdboc.c
51384@@ -24,8 +24,9 @@
51385 #define MAX_CONFIG_LEN 40
51386
51387 static struct kgdb_io kgdboc_io_ops;
51388+static struct kgdb_io kgdboc_io_ops_console;
51389
51390-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51391+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51392 static int configured = -1;
51393
51394 static char config[MAX_CONFIG_LEN];
51395@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51396 kgdboc_unregister_kbd();
51397 if (configured == 1)
51398 kgdb_unregister_io_module(&kgdboc_io_ops);
51399+ else if (configured == 2)
51400+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
51401 }
51402
51403 static int configure_kgdboc(void)
51404@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51405 int err;
51406 char *cptr = config;
51407 struct console *cons;
51408+ int is_console = 0;
51409
51410 err = kgdboc_option_setup(config);
51411 if (err || !strlen(config) || isspace(config[0]))
51412 goto noconfig;
51413
51414 err = -ENODEV;
51415- kgdboc_io_ops.is_console = 0;
51416 kgdb_tty_driver = NULL;
51417
51418 kgdboc_use_kms = 0;
51419@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51420 int idx;
51421 if (cons->device && cons->device(cons, &idx) == p &&
51422 idx == tty_line) {
51423- kgdboc_io_ops.is_console = 1;
51424+ is_console = 1;
51425 break;
51426 }
51427 cons = cons->next;
51428@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51429 kgdb_tty_line = tty_line;
51430
51431 do_register:
51432- err = kgdb_register_io_module(&kgdboc_io_ops);
51433+ if (is_console) {
51434+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
51435+ configured = 2;
51436+ } else {
51437+ err = kgdb_register_io_module(&kgdboc_io_ops);
51438+ configured = 1;
51439+ }
51440 if (err)
51441 goto noconfig;
51442
51443@@ -205,8 +214,6 @@ do_register:
51444 if (err)
51445 goto nmi_con_failed;
51446
51447- configured = 1;
51448-
51449 return 0;
51450
51451 nmi_con_failed:
51452@@ -223,7 +230,7 @@ noconfig:
51453 static int __init init_kgdboc(void)
51454 {
51455 /* Already configured? */
51456- if (configured == 1)
51457+ if (configured >= 1)
51458 return 0;
51459
51460 return configure_kgdboc();
51461@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51462 if (config[len - 1] == '\n')
51463 config[len - 1] = '\0';
51464
51465- if (configured == 1)
51466+ if (configured >= 1)
51467 cleanup_kgdboc();
51468
51469 /* Go and configure with the new params. */
51470@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51471 .post_exception = kgdboc_post_exp_handler,
51472 };
51473
51474+static struct kgdb_io kgdboc_io_ops_console = {
51475+ .name = "kgdboc",
51476+ .read_char = kgdboc_get_char,
51477+ .write_char = kgdboc_put_char,
51478+ .pre_exception = kgdboc_pre_exp_handler,
51479+ .post_exception = kgdboc_post_exp_handler,
51480+ .is_console = 1
51481+};
51482+
51483 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51484 /* This is only available if kgdboc is a built in for early debugging */
51485 static int __init kgdboc_early_init(char *opt)
51486diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51487index 7307dc4..ce4fe90 100644
51488--- a/drivers/tty/serial/msm_serial.c
51489+++ b/drivers/tty/serial/msm_serial.c
51490@@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
51491 .cons = MSM_CONSOLE,
51492 };
51493
51494-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51495+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51496
51497 static const struct of_device_id msm_uartdm_table[] = {
51498 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
51499@@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51500 int irq;
51501
51502 if (pdev->id == -1)
51503- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51504+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51505
51506 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51507 return -ENXIO;
51508diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51509index 1f5505e..a1a767d 100644
51510--- a/drivers/tty/serial/samsung.c
51511+++ b/drivers/tty/serial/samsung.c
51512@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51513 }
51514 }
51515
51516+static int s3c64xx_serial_startup(struct uart_port *port);
51517 static int s3c24xx_serial_startup(struct uart_port *port)
51518 {
51519 struct s3c24xx_uart_port *ourport = to_ourport(port);
51520 int ret;
51521
51522+ /* Startup sequence is different for s3c64xx and higher SoC's */
51523+ if (s3c24xx_serial_has_interrupt_mask(port))
51524+ return s3c64xx_serial_startup(port);
51525+
51526 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51527 port->mapbase, port->membase);
51528
51529@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51530 /* setup info for port */
51531 port->dev = &platdev->dev;
51532
51533- /* Startup sequence is different for s3c64xx and higher SoC's */
51534- if (s3c24xx_serial_has_interrupt_mask(port))
51535- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51536-
51537 port->uartclk = 1;
51538
51539 if (cfg->uart_flags & UPF_CONS_FLOW) {
51540diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51541index b68550d..a62d7f8 100644
51542--- a/drivers/tty/serial/serial_core.c
51543+++ b/drivers/tty/serial/serial_core.c
51544@@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
51545
51546 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
51547
51548- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
51549+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
51550 return;
51551
51552 /*
51553@@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51554 uart_flush_buffer(tty);
51555 uart_shutdown(tty, state);
51556 spin_lock_irqsave(&port->lock, flags);
51557- port->count = 0;
51558+ atomic_set(&port->count, 0);
51559 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51560 spin_unlock_irqrestore(&port->lock, flags);
51561 tty_port_tty_set(port, NULL);
51562@@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51563 goto end;
51564 }
51565
51566- port->count++;
51567+ atomic_inc(&port->count);
51568 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51569 retval = -ENXIO;
51570 goto err_dec_count;
51571@@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51572 end:
51573 return retval;
51574 err_dec_count:
51575- port->count--;
51576+ atomic_inc(&port->count);
51577 mutex_unlock(&port->mutex);
51578 goto end;
51579 }
51580diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51581index d48e040..0f52764 100644
51582--- a/drivers/tty/synclink.c
51583+++ b/drivers/tty/synclink.c
51584@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51585
51586 if (debug_level >= DEBUG_LEVEL_INFO)
51587 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51588- __FILE__,__LINE__, info->device_name, info->port.count);
51589+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51590
51591 if (tty_port_close_start(&info->port, tty, filp) == 0)
51592 goto cleanup;
51593@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51594 cleanup:
51595 if (debug_level >= DEBUG_LEVEL_INFO)
51596 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51597- tty->driver->name, info->port.count);
51598+ tty->driver->name, atomic_read(&info->port.count));
51599
51600 } /* end of mgsl_close() */
51601
51602@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51603
51604 mgsl_flush_buffer(tty);
51605 shutdown(info);
51606-
51607- info->port.count = 0;
51608+
51609+ atomic_set(&info->port.count, 0);
51610 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51611 info->port.tty = NULL;
51612
51613@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51614
51615 if (debug_level >= DEBUG_LEVEL_INFO)
51616 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51617- __FILE__,__LINE__, tty->driver->name, port->count );
51618+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51619
51620 spin_lock_irqsave(&info->irq_spinlock, flags);
51621 if (!tty_hung_up_p(filp)) {
51622 extra_count = true;
51623- port->count--;
51624+ atomic_dec(&port->count);
51625 }
51626 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51627 port->blocked_open++;
51628@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51629
51630 if (debug_level >= DEBUG_LEVEL_INFO)
51631 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51632- __FILE__,__LINE__, tty->driver->name, port->count );
51633+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51634
51635 tty_unlock(tty);
51636 schedule();
51637@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51638
51639 /* FIXME: Racy on hangup during close wait */
51640 if (extra_count)
51641- port->count++;
51642+ atomic_inc(&port->count);
51643 port->blocked_open--;
51644
51645 if (debug_level >= DEBUG_LEVEL_INFO)
51646 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51647- __FILE__,__LINE__, tty->driver->name, port->count );
51648+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51649
51650 if (!retval)
51651 port->flags |= ASYNC_NORMAL_ACTIVE;
51652@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51653
51654 if (debug_level >= DEBUG_LEVEL_INFO)
51655 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51656- __FILE__,__LINE__,tty->driver->name, info->port.count);
51657+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51658
51659 /* If port is closing, signal caller to try again */
51660 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51661@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51662 spin_unlock_irqrestore(&info->netlock, flags);
51663 goto cleanup;
51664 }
51665- info->port.count++;
51666+ atomic_inc(&info->port.count);
51667 spin_unlock_irqrestore(&info->netlock, flags);
51668
51669- if (info->port.count == 1) {
51670+ if (atomic_read(&info->port.count) == 1) {
51671 /* 1st open on this device, init hardware */
51672 retval = startup(info);
51673 if (retval < 0)
51674@@ -3446,8 +3446,8 @@ cleanup:
51675 if (retval) {
51676 if (tty->count == 1)
51677 info->port.tty = NULL; /* tty layer will release tty struct */
51678- if(info->port.count)
51679- info->port.count--;
51680+ if (atomic_read(&info->port.count))
51681+ atomic_dec(&info->port.count);
51682 }
51683
51684 return retval;
51685@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51686 unsigned short new_crctype;
51687
51688 /* return error if TTY interface open */
51689- if (info->port.count)
51690+ if (atomic_read(&info->port.count))
51691 return -EBUSY;
51692
51693 switch (encoding)
51694@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51695
51696 /* arbitrate between network and tty opens */
51697 spin_lock_irqsave(&info->netlock, flags);
51698- if (info->port.count != 0 || info->netcount != 0) {
51699+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51700 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51701 spin_unlock_irqrestore(&info->netlock, flags);
51702 return -EBUSY;
51703@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51704 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51705
51706 /* return error if TTY interface open */
51707- if (info->port.count)
51708+ if (atomic_read(&info->port.count))
51709 return -EBUSY;
51710
51711 if (cmd != SIOCWANDEV)
51712diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51713index c359a91..959fc26 100644
51714--- a/drivers/tty/synclink_gt.c
51715+++ b/drivers/tty/synclink_gt.c
51716@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51717 tty->driver_data = info;
51718 info->port.tty = tty;
51719
51720- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51721+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51722
51723 /* If port is closing, signal caller to try again */
51724 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51725@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51726 mutex_unlock(&info->port.mutex);
51727 goto cleanup;
51728 }
51729- info->port.count++;
51730+ atomic_inc(&info->port.count);
51731 spin_unlock_irqrestore(&info->netlock, flags);
51732
51733- if (info->port.count == 1) {
51734+ if (atomic_read(&info->port.count) == 1) {
51735 /* 1st open on this device, init hardware */
51736 retval = startup(info);
51737 if (retval < 0) {
51738@@ -715,8 +715,8 @@ cleanup:
51739 if (retval) {
51740 if (tty->count == 1)
51741 info->port.tty = NULL; /* tty layer will release tty struct */
51742- if(info->port.count)
51743- info->port.count--;
51744+ if(atomic_read(&info->port.count))
51745+ atomic_dec(&info->port.count);
51746 }
51747
51748 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51749@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51750
51751 if (sanity_check(info, tty->name, "close"))
51752 return;
51753- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51754+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51755
51756 if (tty_port_close_start(&info->port, tty, filp) == 0)
51757 goto cleanup;
51758@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51759 tty_port_close_end(&info->port, tty);
51760 info->port.tty = NULL;
51761 cleanup:
51762- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51763+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51764 }
51765
51766 static void hangup(struct tty_struct *tty)
51767@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51768 shutdown(info);
51769
51770 spin_lock_irqsave(&info->port.lock, flags);
51771- info->port.count = 0;
51772+ atomic_set(&info->port.count, 0);
51773 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51774 info->port.tty = NULL;
51775 spin_unlock_irqrestore(&info->port.lock, flags);
51776@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51777 unsigned short new_crctype;
51778
51779 /* return error if TTY interface open */
51780- if (info->port.count)
51781+ if (atomic_read(&info->port.count))
51782 return -EBUSY;
51783
51784 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51785@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51786
51787 /* arbitrate between network and tty opens */
51788 spin_lock_irqsave(&info->netlock, flags);
51789- if (info->port.count != 0 || info->netcount != 0) {
51790+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51791 DBGINFO(("%s hdlc_open busy\n", dev->name));
51792 spin_unlock_irqrestore(&info->netlock, flags);
51793 return -EBUSY;
51794@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51795 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51796
51797 /* return error if TTY interface open */
51798- if (info->port.count)
51799+ if (atomic_read(&info->port.count))
51800 return -EBUSY;
51801
51802 if (cmd != SIOCWANDEV)
51803@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51804 if (port == NULL)
51805 continue;
51806 spin_lock(&port->lock);
51807- if ((port->port.count || port->netcount) &&
51808+ if ((atomic_read(&port->port.count) || port->netcount) &&
51809 port->pending_bh && !port->bh_running &&
51810 !port->bh_requested) {
51811 DBGISR(("%s bh queued\n", port->device_name));
51812@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51813 spin_lock_irqsave(&info->lock, flags);
51814 if (!tty_hung_up_p(filp)) {
51815 extra_count = true;
51816- port->count--;
51817+ atomic_dec(&port->count);
51818 }
51819 spin_unlock_irqrestore(&info->lock, flags);
51820 port->blocked_open++;
51821@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51822 remove_wait_queue(&port->open_wait, &wait);
51823
51824 if (extra_count)
51825- port->count++;
51826+ atomic_inc(&port->count);
51827 port->blocked_open--;
51828
51829 if (!retval)
51830diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51831index 53ba853..3c30f6d 100644
51832--- a/drivers/tty/synclinkmp.c
51833+++ b/drivers/tty/synclinkmp.c
51834@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51835
51836 if (debug_level >= DEBUG_LEVEL_INFO)
51837 printk("%s(%d):%s open(), old ref count = %d\n",
51838- __FILE__,__LINE__,tty->driver->name, info->port.count);
51839+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51840
51841 /* If port is closing, signal caller to try again */
51842 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51843@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51844 spin_unlock_irqrestore(&info->netlock, flags);
51845 goto cleanup;
51846 }
51847- info->port.count++;
51848+ atomic_inc(&info->port.count);
51849 spin_unlock_irqrestore(&info->netlock, flags);
51850
51851- if (info->port.count == 1) {
51852+ if (atomic_read(&info->port.count) == 1) {
51853 /* 1st open on this device, init hardware */
51854 retval = startup(info);
51855 if (retval < 0)
51856@@ -796,8 +796,8 @@ cleanup:
51857 if (retval) {
51858 if (tty->count == 1)
51859 info->port.tty = NULL; /* tty layer will release tty struct */
51860- if(info->port.count)
51861- info->port.count--;
51862+ if(atomic_read(&info->port.count))
51863+ atomic_dec(&info->port.count);
51864 }
51865
51866 return retval;
51867@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51868
51869 if (debug_level >= DEBUG_LEVEL_INFO)
51870 printk("%s(%d):%s close() entry, count=%d\n",
51871- __FILE__,__LINE__, info->device_name, info->port.count);
51872+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51873
51874 if (tty_port_close_start(&info->port, tty, filp) == 0)
51875 goto cleanup;
51876@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51877 cleanup:
51878 if (debug_level >= DEBUG_LEVEL_INFO)
51879 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51880- tty->driver->name, info->port.count);
51881+ tty->driver->name, atomic_read(&info->port.count));
51882 }
51883
51884 /* Called by tty_hangup() when a hangup is signaled.
51885@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51886 shutdown(info);
51887
51888 spin_lock_irqsave(&info->port.lock, flags);
51889- info->port.count = 0;
51890+ atomic_set(&info->port.count, 0);
51891 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51892 info->port.tty = NULL;
51893 spin_unlock_irqrestore(&info->port.lock, flags);
51894@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51895 unsigned short new_crctype;
51896
51897 /* return error if TTY interface open */
51898- if (info->port.count)
51899+ if (atomic_read(&info->port.count))
51900 return -EBUSY;
51901
51902 switch (encoding)
51903@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51904
51905 /* arbitrate between network and tty opens */
51906 spin_lock_irqsave(&info->netlock, flags);
51907- if (info->port.count != 0 || info->netcount != 0) {
51908+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51909 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51910 spin_unlock_irqrestore(&info->netlock, flags);
51911 return -EBUSY;
51912@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51913 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51914
51915 /* return error if TTY interface open */
51916- if (info->port.count)
51917+ if (atomic_read(&info->port.count))
51918 return -EBUSY;
51919
51920 if (cmd != SIOCWANDEV)
51921@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51922 * do not request bottom half processing if the
51923 * device is not open in a normal mode.
51924 */
51925- if ( port && (port->port.count || port->netcount) &&
51926+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51927 port->pending_bh && !port->bh_running &&
51928 !port->bh_requested ) {
51929 if ( debug_level >= DEBUG_LEVEL_ISR )
51930@@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51931
51932 if (debug_level >= DEBUG_LEVEL_INFO)
51933 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51934- __FILE__,__LINE__, tty->driver->name, port->count );
51935+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51936
51937 spin_lock_irqsave(&info->lock, flags);
51938 if (!tty_hung_up_p(filp)) {
51939 extra_count = true;
51940- port->count--;
51941+ atomic_dec(&port->count);
51942 }
51943 spin_unlock_irqrestore(&info->lock, flags);
51944 port->blocked_open++;
51945@@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51946
51947 if (debug_level >= DEBUG_LEVEL_INFO)
51948 printk("%s(%d):%s block_til_ready() count=%d\n",
51949- __FILE__,__LINE__, tty->driver->name, port->count );
51950+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51951
51952 tty_unlock(tty);
51953 schedule();
51954@@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51955 remove_wait_queue(&port->open_wait, &wait);
51956
51957 if (extra_count)
51958- port->count++;
51959+ atomic_inc(&port->count);
51960 port->blocked_open--;
51961
51962 if (debug_level >= DEBUG_LEVEL_INFO)
51963 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51964- __FILE__,__LINE__, tty->driver->name, port->count );
51965+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51966
51967 if (!retval)
51968 port->flags |= ASYNC_NORMAL_ACTIVE;
51969diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51970index ce396ec..04a37be 100644
51971--- a/drivers/tty/sysrq.c
51972+++ b/drivers/tty/sysrq.c
51973@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51974 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51975 size_t count, loff_t *ppos)
51976 {
51977- if (count) {
51978+ if (count && capable(CAP_SYS_ADMIN)) {
51979 char c;
51980
51981 if (get_user(c, buf))
51982diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51983index 3411071..86f2cf2 100644
51984--- a/drivers/tty/tty_io.c
51985+++ b/drivers/tty/tty_io.c
51986@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51987
51988 void tty_default_fops(struct file_operations *fops)
51989 {
51990- *fops = tty_fops;
51991+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51992 }
51993
51994 /*
51995diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51996index 2d822aa..a566234 100644
51997--- a/drivers/tty/tty_ldisc.c
51998+++ b/drivers/tty/tty_ldisc.c
51999@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
52000 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52001 tty_ldiscs[disc] = new_ldisc;
52002 new_ldisc->num = disc;
52003- new_ldisc->refcount = 0;
52004+ atomic_set(&new_ldisc->refcount, 0);
52005 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
52006
52007 return ret;
52008@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
52009 return -EINVAL;
52010
52011 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52012- if (tty_ldiscs[disc]->refcount)
52013+ if (atomic_read(&tty_ldiscs[disc]->refcount))
52014 ret = -EBUSY;
52015 else
52016 tty_ldiscs[disc] = NULL;
52017@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
52018 if (ldops) {
52019 ret = ERR_PTR(-EAGAIN);
52020 if (try_module_get(ldops->owner)) {
52021- ldops->refcount++;
52022+ atomic_inc(&ldops->refcount);
52023 ret = ldops;
52024 }
52025 }
52026@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
52027 unsigned long flags;
52028
52029 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52030- ldops->refcount--;
52031+ atomic_dec(&ldops->refcount);
52032 module_put(ldops->owner);
52033 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
52034 }
52035diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
52036index 3f746c8..2f2fcaa 100644
52037--- a/drivers/tty/tty_port.c
52038+++ b/drivers/tty/tty_port.c
52039@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
52040 unsigned long flags;
52041
52042 spin_lock_irqsave(&port->lock, flags);
52043- port->count = 0;
52044+ atomic_set(&port->count, 0);
52045 port->flags &= ~ASYNC_NORMAL_ACTIVE;
52046 tty = port->tty;
52047 if (tty)
52048@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52049 /* The port lock protects the port counts */
52050 spin_lock_irqsave(&port->lock, flags);
52051 if (!tty_hung_up_p(filp))
52052- port->count--;
52053+ atomic_dec(&port->count);
52054 port->blocked_open++;
52055 spin_unlock_irqrestore(&port->lock, flags);
52056
52057@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52058 we must not mess that up further */
52059 spin_lock_irqsave(&port->lock, flags);
52060 if (!tty_hung_up_p(filp))
52061- port->count++;
52062+ atomic_inc(&port->count);
52063 port->blocked_open--;
52064 if (retval == 0)
52065 port->flags |= ASYNC_NORMAL_ACTIVE;
52066@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
52067 return 0;
52068 }
52069
52070- if (tty->count == 1 && port->count != 1) {
52071+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
52072 printk(KERN_WARNING
52073 "tty_port_close_start: tty->count = 1 port count = %d.\n",
52074- port->count);
52075- port->count = 1;
52076+ atomic_read(&port->count));
52077+ atomic_set(&port->count, 1);
52078 }
52079- if (--port->count < 0) {
52080+ if (atomic_dec_return(&port->count) < 0) {
52081 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
52082- port->count);
52083- port->count = 0;
52084+ atomic_read(&port->count));
52085+ atomic_set(&port->count, 0);
52086 }
52087
52088- if (port->count) {
52089+ if (atomic_read(&port->count)) {
52090 spin_unlock_irqrestore(&port->lock, flags);
52091 return 0;
52092 }
52093@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
52094 {
52095 spin_lock_irq(&port->lock);
52096 if (!tty_hung_up_p(filp))
52097- ++port->count;
52098+ atomic_inc(&port->count);
52099 spin_unlock_irq(&port->lock);
52100 tty_port_tty_set(port, tty);
52101
52102diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
52103index d0e3a44..5f8b754 100644
52104--- a/drivers/tty/vt/keyboard.c
52105+++ b/drivers/tty/vt/keyboard.c
52106@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
52107 kbd->kbdmode == VC_OFF) &&
52108 value != KVAL(K_SAK))
52109 return; /* SAK is allowed even in raw mode */
52110+
52111+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52112+ {
52113+ void *func = fn_handler[value];
52114+ if (func == fn_show_state || func == fn_show_ptregs ||
52115+ func == fn_show_mem)
52116+ return;
52117+ }
52118+#endif
52119+
52120 fn_handler[value](vc);
52121 }
52122
52123@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52124 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52125 return -EFAULT;
52126
52127- if (!capable(CAP_SYS_TTY_CONFIG))
52128- perm = 0;
52129-
52130 switch (cmd) {
52131 case KDGKBENT:
52132 /* Ensure another thread doesn't free it under us */
52133@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52134 spin_unlock_irqrestore(&kbd_event_lock, flags);
52135 return put_user(val, &user_kbe->kb_value);
52136 case KDSKBENT:
52137+ if (!capable(CAP_SYS_TTY_CONFIG))
52138+ perm = 0;
52139+
52140 if (!perm)
52141 return -EPERM;
52142 if (!i && v == K_NOSUCHMAP) {
52143@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52144 int i, j, k;
52145 int ret;
52146
52147- if (!capable(CAP_SYS_TTY_CONFIG))
52148- perm = 0;
52149-
52150 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52151 if (!kbs) {
52152 ret = -ENOMEM;
52153@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52154 kfree(kbs);
52155 return ((p && *p) ? -EOVERFLOW : 0);
52156 case KDSKBSENT:
52157+ if (!capable(CAP_SYS_TTY_CONFIG))
52158+ perm = 0;
52159+
52160 if (!perm) {
52161 ret = -EPERM;
52162 goto reterr;
52163diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52164index a673e5b..36e5d32 100644
52165--- a/drivers/uio/uio.c
52166+++ b/drivers/uio/uio.c
52167@@ -25,6 +25,7 @@
52168 #include <linux/kobject.h>
52169 #include <linux/cdev.h>
52170 #include <linux/uio_driver.h>
52171+#include <asm/local.h>
52172
52173 #define UIO_MAX_DEVICES (1U << MINORBITS)
52174
52175@@ -32,7 +33,7 @@ struct uio_device {
52176 struct module *owner;
52177 struct device *dev;
52178 int minor;
52179- atomic_t event;
52180+ atomic_unchecked_t event;
52181 struct fasync_struct *async_queue;
52182 wait_queue_head_t wait;
52183 struct uio_info *info;
52184@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52185 struct device_attribute *attr, char *buf)
52186 {
52187 struct uio_device *idev = dev_get_drvdata(dev);
52188- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52189+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52190 }
52191 static DEVICE_ATTR_RO(event);
52192
52193@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52194 {
52195 struct uio_device *idev = info->uio_dev;
52196
52197- atomic_inc(&idev->event);
52198+ atomic_inc_unchecked(&idev->event);
52199 wake_up_interruptible(&idev->wait);
52200 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52201 }
52202@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52203 }
52204
52205 listener->dev = idev;
52206- listener->event_count = atomic_read(&idev->event);
52207+ listener->event_count = atomic_read_unchecked(&idev->event);
52208 filep->private_data = listener;
52209
52210 if (idev->info->open) {
52211@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52212 return -EIO;
52213
52214 poll_wait(filep, &idev->wait, wait);
52215- if (listener->event_count != atomic_read(&idev->event))
52216+ if (listener->event_count != atomic_read_unchecked(&idev->event))
52217 return POLLIN | POLLRDNORM;
52218 return 0;
52219 }
52220@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52221 do {
52222 set_current_state(TASK_INTERRUPTIBLE);
52223
52224- event_count = atomic_read(&idev->event);
52225+ event_count = atomic_read_unchecked(&idev->event);
52226 if (event_count != listener->event_count) {
52227 if (copy_to_user(buf, &event_count, count))
52228 retval = -EFAULT;
52229@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52230 static int uio_find_mem_index(struct vm_area_struct *vma)
52231 {
52232 struct uio_device *idev = vma->vm_private_data;
52233+ unsigned long size;
52234
52235 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52236- if (idev->info->mem[vma->vm_pgoff].size == 0)
52237+ size = idev->info->mem[vma->vm_pgoff].size;
52238+ if (size == 0)
52239+ return -1;
52240+ if (vma->vm_end - vma->vm_start > size)
52241 return -1;
52242 return (int)vma->vm_pgoff;
52243 }
52244@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52245 idev->owner = owner;
52246 idev->info = info;
52247 init_waitqueue_head(&idev->wait);
52248- atomic_set(&idev->event, 0);
52249+ atomic_set_unchecked(&idev->event, 0);
52250
52251 ret = uio_get_minor(idev);
52252 if (ret)
52253diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52254index 813d4d3..a71934f 100644
52255--- a/drivers/usb/atm/cxacru.c
52256+++ b/drivers/usb/atm/cxacru.c
52257@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52258 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52259 if (ret < 2)
52260 return -EINVAL;
52261- if (index < 0 || index > 0x7f)
52262+ if (index > 0x7f)
52263 return -EINVAL;
52264 pos += tmp;
52265
52266diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52267index dada014..1d0d517 100644
52268--- a/drivers/usb/atm/usbatm.c
52269+++ b/drivers/usb/atm/usbatm.c
52270@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52271 if (printk_ratelimit())
52272 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52273 __func__, vpi, vci);
52274- atomic_inc(&vcc->stats->rx_err);
52275+ atomic_inc_unchecked(&vcc->stats->rx_err);
52276 return;
52277 }
52278
52279@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52280 if (length > ATM_MAX_AAL5_PDU) {
52281 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52282 __func__, length, vcc);
52283- atomic_inc(&vcc->stats->rx_err);
52284+ atomic_inc_unchecked(&vcc->stats->rx_err);
52285 goto out;
52286 }
52287
52288@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52289 if (sarb->len < pdu_length) {
52290 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52291 __func__, pdu_length, sarb->len, vcc);
52292- atomic_inc(&vcc->stats->rx_err);
52293+ atomic_inc_unchecked(&vcc->stats->rx_err);
52294 goto out;
52295 }
52296
52297 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52298 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52299 __func__, vcc);
52300- atomic_inc(&vcc->stats->rx_err);
52301+ atomic_inc_unchecked(&vcc->stats->rx_err);
52302 goto out;
52303 }
52304
52305@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52306 if (printk_ratelimit())
52307 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52308 __func__, length);
52309- atomic_inc(&vcc->stats->rx_drop);
52310+ atomic_inc_unchecked(&vcc->stats->rx_drop);
52311 goto out;
52312 }
52313
52314@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52315
52316 vcc->push(vcc, skb);
52317
52318- atomic_inc(&vcc->stats->rx);
52319+ atomic_inc_unchecked(&vcc->stats->rx);
52320 out:
52321 skb_trim(sarb, 0);
52322 }
52323@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52324 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52325
52326 usbatm_pop(vcc, skb);
52327- atomic_inc(&vcc->stats->tx);
52328+ atomic_inc_unchecked(&vcc->stats->tx);
52329
52330 skb = skb_dequeue(&instance->sndqueue);
52331 }
52332@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52333 if (!left--)
52334 return sprintf(page,
52335 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52336- atomic_read(&atm_dev->stats.aal5.tx),
52337- atomic_read(&atm_dev->stats.aal5.tx_err),
52338- atomic_read(&atm_dev->stats.aal5.rx),
52339- atomic_read(&atm_dev->stats.aal5.rx_err),
52340- atomic_read(&atm_dev->stats.aal5.rx_drop));
52341+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52342+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52343+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52344+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52345+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52346
52347 if (!left--) {
52348 if (instance->disconnected)
52349diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52350index 2a3bbdf..91d72cf 100644
52351--- a/drivers/usb/core/devices.c
52352+++ b/drivers/usb/core/devices.c
52353@@ -126,7 +126,7 @@ static const char format_endpt[] =
52354 * time it gets called.
52355 */
52356 static struct device_connect_event {
52357- atomic_t count;
52358+ atomic_unchecked_t count;
52359 wait_queue_head_t wait;
52360 } device_event = {
52361 .count = ATOMIC_INIT(1),
52362@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52363
52364 void usbfs_conn_disc_event(void)
52365 {
52366- atomic_add(2, &device_event.count);
52367+ atomic_add_unchecked(2, &device_event.count);
52368 wake_up(&device_event.wait);
52369 }
52370
52371@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52372
52373 poll_wait(file, &device_event.wait, wait);
52374
52375- event_count = atomic_read(&device_event.count);
52376+ event_count = atomic_read_unchecked(&device_event.count);
52377 if (file->f_version != event_count) {
52378 file->f_version = event_count;
52379 return POLLIN | POLLRDNORM;
52380diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52381index 257876e..4304364 100644
52382--- a/drivers/usb/core/devio.c
52383+++ b/drivers/usb/core/devio.c
52384@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52385 struct usb_dev_state *ps = file->private_data;
52386 struct usb_device *dev = ps->dev;
52387 ssize_t ret = 0;
52388- unsigned len;
52389+ size_t len;
52390 loff_t pos;
52391 int i;
52392
52393@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52394 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52395 struct usb_config_descriptor *config =
52396 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52397- unsigned int length = le16_to_cpu(config->wTotalLength);
52398+ size_t length = le16_to_cpu(config->wTotalLength);
52399
52400 if (*ppos < pos + length) {
52401
52402 /* The descriptor may claim to be longer than it
52403 * really is. Here is the actual allocated length. */
52404- unsigned alloclen =
52405+ size_t alloclen =
52406 le16_to_cpu(dev->config[i].desc.wTotalLength);
52407
52408- len = length - (*ppos - pos);
52409+ len = length + pos - *ppos;
52410 if (len > nbytes)
52411 len = nbytes;
52412
52413 /* Simply don't write (skip over) unallocated parts */
52414 if (alloclen > (*ppos - pos)) {
52415- alloclen -= (*ppos - pos);
52416+ alloclen = alloclen + pos - *ppos;
52417 if (copy_to_user(buf,
52418 dev->rawdescriptors[i] + (*ppos - pos),
52419 min(len, alloclen))) {
52420diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52421index 9c4e292..b89877f 100644
52422--- a/drivers/usb/core/hcd.c
52423+++ b/drivers/usb/core/hcd.c
52424@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52425 */
52426 usb_get_urb(urb);
52427 atomic_inc(&urb->use_count);
52428- atomic_inc(&urb->dev->urbnum);
52429+ atomic_inc_unchecked(&urb->dev->urbnum);
52430 usbmon_urb_submit(&hcd->self, urb);
52431
52432 /* NOTE requirements on root-hub callers (usbfs and the hub
52433@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52434 urb->hcpriv = NULL;
52435 INIT_LIST_HEAD(&urb->urb_list);
52436 atomic_dec(&urb->use_count);
52437- atomic_dec(&urb->dev->urbnum);
52438+ atomic_dec_unchecked(&urb->dev->urbnum);
52439 if (atomic_read(&urb->reject))
52440 wake_up(&usb_kill_urb_queue);
52441 usb_put_urb(urb);
52442diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52443index 00c4b96..b4498c8 100644
52444--- a/drivers/usb/core/hub.c
52445+++ b/drivers/usb/core/hub.c
52446@@ -27,6 +27,7 @@
52447 #include <linux/freezer.h>
52448 #include <linux/random.h>
52449 #include <linux/pm_qos.h>
52450+#include <linux/grsecurity.h>
52451
52452 #include <asm/uaccess.h>
52453 #include <asm/byteorder.h>
52454@@ -4531,6 +4532,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52455 goto done;
52456 return;
52457 }
52458+
52459+ if (gr_handle_new_usb())
52460+ goto done;
52461+
52462 if (hub_is_superspeed(hub->hdev))
52463 unit_load = 150;
52464 else
52465diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52466index 0c8a7fc..c45b40a 100644
52467--- a/drivers/usb/core/message.c
52468+++ b/drivers/usb/core/message.c
52469@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52470 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52471 * error number.
52472 */
52473-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52474+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52475 __u8 requesttype, __u16 value, __u16 index, void *data,
52476 __u16 size, int timeout)
52477 {
52478@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52479 * If successful, 0. Otherwise a negative error number. The number of actual
52480 * bytes transferred will be stored in the @actual_length parameter.
52481 */
52482-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52483+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52484 void *data, int len, int *actual_length, int timeout)
52485 {
52486 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52487@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52488 * bytes transferred will be stored in the @actual_length parameter.
52489 *
52490 */
52491-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52492+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52493 void *data, int len, int *actual_length, int timeout)
52494 {
52495 struct urb *urb;
52496diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52497index 1236c60..d47a51c 100644
52498--- a/drivers/usb/core/sysfs.c
52499+++ b/drivers/usb/core/sysfs.c
52500@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52501 struct usb_device *udev;
52502
52503 udev = to_usb_device(dev);
52504- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52505+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52506 }
52507 static DEVICE_ATTR_RO(urbnum);
52508
52509diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52510index 4d11449..f4ccabf 100644
52511--- a/drivers/usb/core/usb.c
52512+++ b/drivers/usb/core/usb.c
52513@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52514 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52515 dev->state = USB_STATE_ATTACHED;
52516 dev->lpm_disable_count = 1;
52517- atomic_set(&dev->urbnum, 0);
52518+ atomic_set_unchecked(&dev->urbnum, 0);
52519
52520 INIT_LIST_HEAD(&dev->ep0.urb_list);
52521 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52522diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52523index 85f398d..d375bbe 100644
52524--- a/drivers/usb/dwc3/gadget.c
52525+++ b/drivers/usb/dwc3/gadget.c
52526@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52527 if (!usb_endpoint_xfer_isoc(desc))
52528 return 0;
52529
52530- memset(&trb_link, 0, sizeof(trb_link));
52531-
52532 /* Link TRB for ISOC. The HWO bit is never reset */
52533 trb_st_hw = &dep->trb_pool[0];
52534
52535diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52536index 8cfc319..4868255 100644
52537--- a/drivers/usb/early/ehci-dbgp.c
52538+++ b/drivers/usb/early/ehci-dbgp.c
52539@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52540
52541 #ifdef CONFIG_KGDB
52542 static struct kgdb_io kgdbdbgp_io_ops;
52543-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52544+static struct kgdb_io kgdbdbgp_io_ops_console;
52545+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52546 #else
52547 #define dbgp_kgdb_mode (0)
52548 #endif
52549@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52550 .write_char = kgdbdbgp_write_char,
52551 };
52552
52553+static struct kgdb_io kgdbdbgp_io_ops_console = {
52554+ .name = "kgdbdbgp",
52555+ .read_char = kgdbdbgp_read_char,
52556+ .write_char = kgdbdbgp_write_char,
52557+ .is_console = 1
52558+};
52559+
52560 static int kgdbdbgp_wait_time;
52561
52562 static int __init kgdbdbgp_parse_config(char *str)
52563@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52564 ptr++;
52565 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52566 }
52567- kgdb_register_io_module(&kgdbdbgp_io_ops);
52568- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52569+ if (early_dbgp_console.index != -1)
52570+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52571+ else
52572+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52573
52574 return 0;
52575 }
52576diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52577index 2b4c82d..06a8ee6 100644
52578--- a/drivers/usb/gadget/f_uac1.c
52579+++ b/drivers/usb/gadget/f_uac1.c
52580@@ -13,6 +13,7 @@
52581 #include <linux/kernel.h>
52582 #include <linux/device.h>
52583 #include <linux/atomic.h>
52584+#include <linux/module.h>
52585
52586 #include "u_uac1.h"
52587
52588diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52589index ad0aca8..8ff84865 100644
52590--- a/drivers/usb/gadget/u_serial.c
52591+++ b/drivers/usb/gadget/u_serial.c
52592@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52593 spin_lock_irq(&port->port_lock);
52594
52595 /* already open? Great. */
52596- if (port->port.count) {
52597+ if (atomic_read(&port->port.count)) {
52598 status = 0;
52599- port->port.count++;
52600+ atomic_inc(&port->port.count);
52601
52602 /* currently opening/closing? wait ... */
52603 } else if (port->openclose) {
52604@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52605 tty->driver_data = port;
52606 port->port.tty = tty;
52607
52608- port->port.count = 1;
52609+ atomic_set(&port->port.count, 1);
52610 port->openclose = false;
52611
52612 /* if connected, start the I/O stream */
52613@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52614
52615 spin_lock_irq(&port->port_lock);
52616
52617- if (port->port.count != 1) {
52618- if (port->port.count == 0)
52619+ if (atomic_read(&port->port.count) != 1) {
52620+ if (atomic_read(&port->port.count) == 0)
52621 WARN_ON(1);
52622 else
52623- --port->port.count;
52624+ atomic_dec(&port->port.count);
52625 goto exit;
52626 }
52627
52628@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52629 * and sleep if necessary
52630 */
52631 port->openclose = true;
52632- port->port.count = 0;
52633+ atomic_set(&port->port.count, 0);
52634
52635 gser = port->port_usb;
52636 if (gser && gser->disconnect)
52637@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52638 int cond;
52639
52640 spin_lock_irq(&port->port_lock);
52641- cond = (port->port.count == 0) && !port->openclose;
52642+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52643 spin_unlock_irq(&port->port_lock);
52644 return cond;
52645 }
52646@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52647 /* if it's already open, start I/O ... and notify the serial
52648 * protocol about open/close status (connect/disconnect).
52649 */
52650- if (port->port.count) {
52651+ if (atomic_read(&port->port.count)) {
52652 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52653 gs_start_io(port);
52654 if (gser->connect)
52655@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52656
52657 port->port_usb = NULL;
52658 gser->ioport = NULL;
52659- if (port->port.count > 0 || port->openclose) {
52660+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52661 wake_up_interruptible(&port->drain_wait);
52662 if (port->port.tty)
52663 tty_hangup(port->port.tty);
52664@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52665
52666 /* finally, free any unused/unusable I/O buffers */
52667 spin_lock_irqsave(&port->port_lock, flags);
52668- if (port->port.count == 0 && !port->openclose)
52669+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52670 gs_buf_free(&port->port_write_buf);
52671 gs_free_requests(gser->out, &port->read_pool, NULL);
52672 gs_free_requests(gser->out, &port->read_queue, NULL);
52673diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52674index 7a55fea..cc0ed4f 100644
52675--- a/drivers/usb/gadget/u_uac1.c
52676+++ b/drivers/usb/gadget/u_uac1.c
52677@@ -16,6 +16,7 @@
52678 #include <linux/ctype.h>
52679 #include <linux/random.h>
52680 #include <linux/syscalls.h>
52681+#include <linux/module.h>
52682
52683 #include "u_uac1.h"
52684
52685diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52686index 7ae0c4d..35521b7 100644
52687--- a/drivers/usb/host/ehci-hub.c
52688+++ b/drivers/usb/host/ehci-hub.c
52689@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52690 urb->transfer_flags = URB_DIR_IN;
52691 usb_get_urb(urb);
52692 atomic_inc(&urb->use_count);
52693- atomic_inc(&urb->dev->urbnum);
52694+ atomic_inc_unchecked(&urb->dev->urbnum);
52695 urb->setup_dma = dma_map_single(
52696 hcd->self.controller,
52697 urb->setup_packet,
52698@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52699 urb->status = -EINPROGRESS;
52700 usb_get_urb(urb);
52701 atomic_inc(&urb->use_count);
52702- atomic_inc(&urb->dev->urbnum);
52703+ atomic_inc_unchecked(&urb->dev->urbnum);
52704 retval = submit_single_step_set_feature(hcd, urb, 0);
52705 if (!retval && !wait_for_completion_timeout(&done,
52706 msecs_to_jiffies(2000))) {
52707diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
52708index d0d8fad..668ef7b 100644
52709--- a/drivers/usb/host/hwa-hc.c
52710+++ b/drivers/usb/host/hwa-hc.c
52711@@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52712 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
52713 struct wahc *wa = &hwahc->wa;
52714 struct device *dev = &wa->usb_iface->dev;
52715- u8 mas_le[UWB_NUM_MAS/8];
52716+ u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
52717+
52718+ if (mas_le == NULL)
52719+ return -ENOMEM;
52720
52721 /* Set the stream index */
52722 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
52723@@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52724 WUSB_REQ_SET_WUSB_MAS,
52725 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
52726 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
52727- mas_le, 32, USB_CTRL_SET_TIMEOUT);
52728+ mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
52729 if (result < 0)
52730 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
52731 out:
52732+ kfree(mas_le);
52733+
52734 return result;
52735 }
52736
52737diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52738index ba6a5d6..f88f7f3 100644
52739--- a/drivers/usb/misc/appledisplay.c
52740+++ b/drivers/usb/misc/appledisplay.c
52741@@ -83,7 +83,7 @@ struct appledisplay {
52742 spinlock_t lock;
52743 };
52744
52745-static atomic_t count_displays = ATOMIC_INIT(0);
52746+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52747 static struct workqueue_struct *wq;
52748
52749 static void appledisplay_complete(struct urb *urb)
52750@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52751
52752 /* Register backlight device */
52753 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52754- atomic_inc_return(&count_displays) - 1);
52755+ atomic_inc_return_unchecked(&count_displays) - 1);
52756 memset(&props, 0, sizeof(struct backlight_properties));
52757 props.type = BACKLIGHT_RAW;
52758 props.max_brightness = 0xff;
52759diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52760index 8d7fc48..01c4986 100644
52761--- a/drivers/usb/serial/console.c
52762+++ b/drivers/usb/serial/console.c
52763@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52764
52765 info->port = port;
52766
52767- ++port->port.count;
52768+ atomic_inc(&port->port.count);
52769 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52770 if (serial->type->set_termios) {
52771 /*
52772@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52773 }
52774 /* Now that any required fake tty operations are completed restore
52775 * the tty port count */
52776- --port->port.count;
52777+ atomic_dec(&port->port.count);
52778 /* The console is special in terms of closing the device so
52779 * indicate this port is now acting as a system console. */
52780 port->port.console = 1;
52781@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52782 free_tty:
52783 kfree(tty);
52784 reset_open_count:
52785- port->port.count = 0;
52786+ atomic_set(&port->port.count, 0);
52787 usb_autopm_put_interface(serial->interface);
52788 error_get_interface:
52789 usb_serial_put(serial);
52790@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52791 static void usb_console_write(struct console *co,
52792 const char *buf, unsigned count)
52793 {
52794- static struct usbcons_info *info = &usbcons_info;
52795+ struct usbcons_info *info = &usbcons_info;
52796 struct usb_serial_port *port = info->port;
52797 struct usb_serial *serial;
52798 int retval = -ENODEV;
52799diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52800index 307e339..6aa97cb 100644
52801--- a/drivers/usb/storage/usb.h
52802+++ b/drivers/usb/storage/usb.h
52803@@ -63,7 +63,7 @@ struct us_unusual_dev {
52804 __u8 useProtocol;
52805 __u8 useTransport;
52806 int (*initFunction)(struct us_data *);
52807-};
52808+} __do_const;
52809
52810
52811 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52812diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52813index f2a8d29..7bc3fe7 100644
52814--- a/drivers/usb/wusbcore/wa-hc.h
52815+++ b/drivers/usb/wusbcore/wa-hc.h
52816@@ -240,7 +240,7 @@ struct wahc {
52817 spinlock_t xfer_list_lock;
52818 struct work_struct xfer_enqueue_work;
52819 struct work_struct xfer_error_work;
52820- atomic_t xfer_id_count;
52821+ atomic_unchecked_t xfer_id_count;
52822
52823 kernel_ulong_t quirks;
52824 };
52825@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52826 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52827 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52828 wa->dto_in_use = 0;
52829- atomic_set(&wa->xfer_id_count, 1);
52830+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52831 /* init the buf in URBs */
52832 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52833 usb_init_urb(&(wa->buf_in_urbs[index]));
52834diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52835index 3e2e4ed..060c9b8 100644
52836--- a/drivers/usb/wusbcore/wa-xfer.c
52837+++ b/drivers/usb/wusbcore/wa-xfer.c
52838@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52839 */
52840 static void wa_xfer_id_init(struct wa_xfer *xfer)
52841 {
52842- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52843+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52844 }
52845
52846 /* Return the xfer's ID. */
52847diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52848index 512f479..7e041d0 100644
52849--- a/drivers/vfio/vfio.c
52850+++ b/drivers/vfio/vfio.c
52851@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52852 return 0;
52853
52854 /* TODO Prevent device auto probing */
52855- WARN("Device %s added to live group %d!\n", dev_name(dev),
52856+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52857 iommu_group_id(group->iommu_group));
52858
52859 return 0;
52860diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52861index 5174eba..451e6bc 100644
52862--- a/drivers/vhost/vringh.c
52863+++ b/drivers/vhost/vringh.c
52864@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52865 /* Userspace access helpers: in this case, addresses are really userspace. */
52866 static inline int getu16_user(u16 *val, const u16 *p)
52867 {
52868- return get_user(*val, (__force u16 __user *)p);
52869+ return get_user(*val, (u16 __force_user *)p);
52870 }
52871
52872 static inline int putu16_user(u16 *p, u16 val)
52873 {
52874- return put_user(val, (__force u16 __user *)p);
52875+ return put_user(val, (u16 __force_user *)p);
52876 }
52877
52878 static inline int copydesc_user(void *dst, const void *src, size_t len)
52879 {
52880- return copy_from_user(dst, (__force void __user *)src, len) ?
52881+ return copy_from_user(dst, (void __force_user *)src, len) ?
52882 -EFAULT : 0;
52883 }
52884
52885@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52886 const struct vring_used_elem *src,
52887 unsigned int num)
52888 {
52889- return copy_to_user((__force void __user *)dst, src,
52890+ return copy_to_user((void __force_user *)dst, src,
52891 sizeof(*dst) * num) ? -EFAULT : 0;
52892 }
52893
52894 static inline int xfer_from_user(void *src, void *dst, size_t len)
52895 {
52896- return copy_from_user(dst, (__force void __user *)src, len) ?
52897+ return copy_from_user(dst, (void __force_user *)src, len) ?
52898 -EFAULT : 0;
52899 }
52900
52901 static inline int xfer_to_user(void *dst, void *src, size_t len)
52902 {
52903- return copy_to_user((__force void __user *)dst, src, len) ?
52904+ return copy_to_user((void __force_user *)dst, src, len) ?
52905 -EFAULT : 0;
52906 }
52907
52908@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52909 vrh->last_used_idx = 0;
52910 vrh->vring.num = num;
52911 /* vring expects kernel addresses, but only used via accessors. */
52912- vrh->vring.desc = (__force struct vring_desc *)desc;
52913- vrh->vring.avail = (__force struct vring_avail *)avail;
52914- vrh->vring.used = (__force struct vring_used *)used;
52915+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52916+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52917+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52918 return 0;
52919 }
52920 EXPORT_SYMBOL(vringh_init_user);
52921@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52922
52923 static inline int putu16_kern(u16 *p, u16 val)
52924 {
52925- ACCESS_ONCE(*p) = val;
52926+ ACCESS_ONCE_RW(*p) = val;
52927 return 0;
52928 }
52929
52930diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52931index 84a110a..96312c3 100644
52932--- a/drivers/video/backlight/kb3886_bl.c
52933+++ b/drivers/video/backlight/kb3886_bl.c
52934@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52935 static unsigned long kb3886bl_flags;
52936 #define KB3886BL_SUSPENDED 0x01
52937
52938-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52939+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52940 {
52941 .ident = "Sahara Touch-iT",
52942 .matches = {
52943diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52944index 1b0b233..6f34c2c 100644
52945--- a/drivers/video/fbdev/arcfb.c
52946+++ b/drivers/video/fbdev/arcfb.c
52947@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52948 return -ENOSPC;
52949
52950 err = 0;
52951- if ((count + p) > fbmemlength) {
52952+ if (count > (fbmemlength - p)) {
52953 count = fbmemlength - p;
52954 err = -ENOSPC;
52955 }
52956diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52957index 52108be..c7c110d 100644
52958--- a/drivers/video/fbdev/aty/aty128fb.c
52959+++ b/drivers/video/fbdev/aty/aty128fb.c
52960@@ -149,7 +149,7 @@ enum {
52961 };
52962
52963 /* Must match above enum */
52964-static char * const r128_family[] = {
52965+static const char * const r128_family[] = {
52966 "AGP",
52967 "PCI",
52968 "PRO AGP",
52969diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52970index c3d0074..0b9077e 100644
52971--- a/drivers/video/fbdev/aty/atyfb_base.c
52972+++ b/drivers/video/fbdev/aty/atyfb_base.c
52973@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52974 par->accel_flags = var->accel_flags; /* hack */
52975
52976 if (var->accel_flags) {
52977- info->fbops->fb_sync = atyfb_sync;
52978+ pax_open_kernel();
52979+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52980+ pax_close_kernel();
52981 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52982 } else {
52983- info->fbops->fb_sync = NULL;
52984+ pax_open_kernel();
52985+ *(void **)&info->fbops->fb_sync = NULL;
52986+ pax_close_kernel();
52987 info->flags |= FBINFO_HWACCEL_DISABLED;
52988 }
52989
52990diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52991index 2fa0317..4983f2a 100644
52992--- a/drivers/video/fbdev/aty/mach64_cursor.c
52993+++ b/drivers/video/fbdev/aty/mach64_cursor.c
52994@@ -8,6 +8,7 @@
52995 #include "../core/fb_draw.h"
52996
52997 #include <asm/io.h>
52998+#include <asm/pgtable.h>
52999
53000 #ifdef __sparc__
53001 #include <asm/fbio.h>
53002@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
53003 info->sprite.buf_align = 16; /* and 64 lines tall. */
53004 info->sprite.flags = FB_PIXMAP_IO;
53005
53006- info->fbops->fb_cursor = atyfb_cursor;
53007+ pax_open_kernel();
53008+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
53009+ pax_close_kernel();
53010
53011 return 0;
53012 }
53013diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
53014index 900aa4e..6d49418 100644
53015--- a/drivers/video/fbdev/core/fb_defio.c
53016+++ b/drivers/video/fbdev/core/fb_defio.c
53017@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
53018
53019 BUG_ON(!fbdefio);
53020 mutex_init(&fbdefio->lock);
53021- info->fbops->fb_mmap = fb_deferred_io_mmap;
53022+ pax_open_kernel();
53023+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
53024+ pax_close_kernel();
53025 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
53026 INIT_LIST_HEAD(&fbdefio->pagelist);
53027 if (fbdefio->delay == 0) /* set a default of 1 s */
53028@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
53029 page->mapping = NULL;
53030 }
53031
53032- info->fbops->fb_mmap = NULL;
53033+ *(void **)&info->fbops->fb_mmap = NULL;
53034 mutex_destroy(&fbdefio->lock);
53035 }
53036 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
53037diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
53038index b6d5008..5bca7bf 100644
53039--- a/drivers/video/fbdev/core/fbmem.c
53040+++ b/drivers/video/fbdev/core/fbmem.c
53041@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
53042 image->dx += image->width + 8;
53043 }
53044 } else if (rotate == FB_ROTATE_UD) {
53045- for (x = 0; x < num && image->dx >= 0; x++) {
53046+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
53047 info->fbops->fb_imageblit(info, image);
53048 image->dx -= image->width + 8;
53049 }
53050@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
53051 image->dy += image->height + 8;
53052 }
53053 } else if (rotate == FB_ROTATE_CCW) {
53054- for (x = 0; x < num && image->dy >= 0; x++) {
53055+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
53056 info->fbops->fb_imageblit(info, image);
53057 image->dy -= image->height + 8;
53058 }
53059@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
53060 return -EFAULT;
53061 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
53062 return -EINVAL;
53063- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
53064+ if (con2fb.framebuffer >= FB_MAX)
53065 return -EINVAL;
53066 if (!registered_fb[con2fb.framebuffer])
53067 request_module("fb%d", con2fb.framebuffer);
53068@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
53069 __u32 data;
53070 int err;
53071
53072- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
53073+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
53074
53075 data = (__u32) (unsigned long) fix->smem_start;
53076 err |= put_user(data, &fix32->smem_start);
53077diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
53078index e23392e..8a77540 100644
53079--- a/drivers/video/fbdev/hyperv_fb.c
53080+++ b/drivers/video/fbdev/hyperv_fb.c
53081@@ -235,7 +235,7 @@ static uint screen_fb_size;
53082 static inline int synthvid_send(struct hv_device *hdev,
53083 struct synthvid_msg *msg)
53084 {
53085- static atomic64_t request_id = ATOMIC64_INIT(0);
53086+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
53087 int ret;
53088
53089 msg->pipe_hdr.type = PIPE_MSG_DATA;
53090@@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
53091
53092 ret = vmbus_sendpacket(hdev->channel, msg,
53093 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
53094- atomic64_inc_return(&request_id),
53095+ atomic64_inc_return_unchecked(&request_id),
53096 VM_PKT_DATA_INBAND, 0);
53097
53098 if (ret)
53099diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
53100index 7672d2e..b56437f 100644
53101--- a/drivers/video/fbdev/i810/i810_accel.c
53102+++ b/drivers/video/fbdev/i810/i810_accel.c
53103@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
53104 }
53105 }
53106 printk("ringbuffer lockup!!!\n");
53107+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
53108 i810_report_error(mmio);
53109 par->dev_flags |= LOCKUP;
53110 info->pixmap.scan_align = 1;
53111diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53112index a01147f..5d896f8 100644
53113--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53114+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53115@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
53116
53117 #ifdef CONFIG_FB_MATROX_MYSTIQUE
53118 struct matrox_switch matrox_mystique = {
53119- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
53120+ .preinit = MGA1064_preinit,
53121+ .reset = MGA1064_reset,
53122+ .init = MGA1064_init,
53123+ .restore = MGA1064_restore,
53124 };
53125 EXPORT_SYMBOL(matrox_mystique);
53126 #endif
53127
53128 #ifdef CONFIG_FB_MATROX_G
53129 struct matrox_switch matrox_G100 = {
53130- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
53131+ .preinit = MGAG100_preinit,
53132+ .reset = MGAG100_reset,
53133+ .init = MGAG100_init,
53134+ .restore = MGAG100_restore,
53135 };
53136 EXPORT_SYMBOL(matrox_G100);
53137 #endif
53138diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53139index 195ad7c..09743fc 100644
53140--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53141+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53142@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
53143 }
53144
53145 struct matrox_switch matrox_millennium = {
53146- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
53147+ .preinit = Ti3026_preinit,
53148+ .reset = Ti3026_reset,
53149+ .init = Ti3026_init,
53150+ .restore = Ti3026_restore
53151 };
53152 EXPORT_SYMBOL(matrox_millennium);
53153 #endif
53154diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53155index fe92eed..106e085 100644
53156--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53157+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53158@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
53159 struct mb862xxfb_par *par = info->par;
53160
53161 if (info->var.bits_per_pixel == 32) {
53162- info->fbops->fb_fillrect = cfb_fillrect;
53163- info->fbops->fb_copyarea = cfb_copyarea;
53164- info->fbops->fb_imageblit = cfb_imageblit;
53165+ pax_open_kernel();
53166+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53167+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53168+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53169+ pax_close_kernel();
53170 } else {
53171 outreg(disp, GC_L0EM, 3);
53172- info->fbops->fb_fillrect = mb86290fb_fillrect;
53173- info->fbops->fb_copyarea = mb86290fb_copyarea;
53174- info->fbops->fb_imageblit = mb86290fb_imageblit;
53175+ pax_open_kernel();
53176+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
53177+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
53178+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
53179+ pax_close_kernel();
53180 }
53181 outreg(draw, GDC_REG_DRAW_BASE, 0);
53182 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
53183diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
53184index def0412..fed6529 100644
53185--- a/drivers/video/fbdev/nvidia/nvidia.c
53186+++ b/drivers/video/fbdev/nvidia/nvidia.c
53187@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
53188 info->fix.line_length = (info->var.xres_virtual *
53189 info->var.bits_per_pixel) >> 3;
53190 if (info->var.accel_flags) {
53191- info->fbops->fb_imageblit = nvidiafb_imageblit;
53192- info->fbops->fb_fillrect = nvidiafb_fillrect;
53193- info->fbops->fb_copyarea = nvidiafb_copyarea;
53194- info->fbops->fb_sync = nvidiafb_sync;
53195+ pax_open_kernel();
53196+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
53197+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
53198+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
53199+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
53200+ pax_close_kernel();
53201 info->pixmap.scan_align = 4;
53202 info->flags &= ~FBINFO_HWACCEL_DISABLED;
53203 info->flags |= FBINFO_READS_FAST;
53204 NVResetGraphics(info);
53205 } else {
53206- info->fbops->fb_imageblit = cfb_imageblit;
53207- info->fbops->fb_fillrect = cfb_fillrect;
53208- info->fbops->fb_copyarea = cfb_copyarea;
53209- info->fbops->fb_sync = NULL;
53210+ pax_open_kernel();
53211+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53212+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53213+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53214+ *(void **)&info->fbops->fb_sync = NULL;
53215+ pax_close_kernel();
53216 info->pixmap.scan_align = 1;
53217 info->flags |= FBINFO_HWACCEL_DISABLED;
53218 info->flags &= ~FBINFO_READS_FAST;
53219@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
53220 info->pixmap.size = 8 * 1024;
53221 info->pixmap.flags = FB_PIXMAP_SYSTEM;
53222
53223- if (!hwcur)
53224- info->fbops->fb_cursor = NULL;
53225+ if (!hwcur) {
53226+ pax_open_kernel();
53227+ *(void **)&info->fbops->fb_cursor = NULL;
53228+ pax_close_kernel();
53229+ }
53230
53231 info->var.accel_flags = (!noaccel);
53232
53233diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
53234index 2412a0d..294215b 100644
53235--- a/drivers/video/fbdev/omap2/dss/display.c
53236+++ b/drivers/video/fbdev/omap2/dss/display.c
53237@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
53238 if (dssdev->name == NULL)
53239 dssdev->name = dssdev->alias;
53240
53241+ pax_open_kernel();
53242 if (drv && drv->get_resolution == NULL)
53243- drv->get_resolution = omapdss_default_get_resolution;
53244+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
53245 if (drv && drv->get_recommended_bpp == NULL)
53246- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53247+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53248 if (drv && drv->get_timings == NULL)
53249- drv->get_timings = omapdss_default_get_timings;
53250+ *(void **)&drv->get_timings = omapdss_default_get_timings;
53251+ pax_close_kernel();
53252
53253 mutex_lock(&panel_list_mutex);
53254 list_add_tail(&dssdev->panel_list, &panel_list);
53255diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
53256index 83433cb..71e9b98 100644
53257--- a/drivers/video/fbdev/s1d13xxxfb.c
53258+++ b/drivers/video/fbdev/s1d13xxxfb.c
53259@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
53260
53261 switch(prod_id) {
53262 case S1D13506_PROD_ID: /* activate acceleration */
53263- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53264- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53265+ pax_open_kernel();
53266+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53267+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53268+ pax_close_kernel();
53269 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
53270 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
53271 break;
53272diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53273index 2bcc84a..29dd1ea 100644
53274--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
53275+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53276@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
53277 }
53278
53279 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
53280- lcdc_sys_write_index,
53281- lcdc_sys_write_data,
53282- lcdc_sys_read_data,
53283+ .write_index = lcdc_sys_write_index,
53284+ .write_data = lcdc_sys_write_data,
53285+ .read_data = lcdc_sys_read_data,
53286 };
53287
53288 static int sh_mobile_lcdc_sginit(struct fb_info *info,
53289diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
53290index d513ed6..90b0de9 100644
53291--- a/drivers/video/fbdev/smscufx.c
53292+++ b/drivers/video/fbdev/smscufx.c
53293@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
53294 fb_deferred_io_cleanup(info);
53295 kfree(info->fbdefio);
53296 info->fbdefio = NULL;
53297- info->fbops->fb_mmap = ufx_ops_mmap;
53298+ pax_open_kernel();
53299+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
53300+ pax_close_kernel();
53301 }
53302
53303 pr_debug("released /dev/fb%d user=%d count=%d",
53304diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
53305index 77b890e..458e666 100644
53306--- a/drivers/video/fbdev/udlfb.c
53307+++ b/drivers/video/fbdev/udlfb.c
53308@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
53309 dlfb_urb_completion(urb);
53310
53311 error:
53312- atomic_add(bytes_sent, &dev->bytes_sent);
53313- atomic_add(bytes_identical, &dev->bytes_identical);
53314- atomic_add(width*height*2, &dev->bytes_rendered);
53315+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53316+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53317+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
53318 end_cycles = get_cycles();
53319- atomic_add(((unsigned int) ((end_cycles - start_cycles)
53320+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53321 >> 10)), /* Kcycles */
53322 &dev->cpu_kcycles_used);
53323
53324@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
53325 dlfb_urb_completion(urb);
53326
53327 error:
53328- atomic_add(bytes_sent, &dev->bytes_sent);
53329- atomic_add(bytes_identical, &dev->bytes_identical);
53330- atomic_add(bytes_rendered, &dev->bytes_rendered);
53331+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53332+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53333+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
53334 end_cycles = get_cycles();
53335- atomic_add(((unsigned int) ((end_cycles - start_cycles)
53336+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53337 >> 10)), /* Kcycles */
53338 &dev->cpu_kcycles_used);
53339 }
53340@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
53341 fb_deferred_io_cleanup(info);
53342 kfree(info->fbdefio);
53343 info->fbdefio = NULL;
53344- info->fbops->fb_mmap = dlfb_ops_mmap;
53345+ pax_open_kernel();
53346+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
53347+ pax_close_kernel();
53348 }
53349
53350 pr_warn("released /dev/fb%d user=%d count=%d\n",
53351@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
53352 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53353 struct dlfb_data *dev = fb_info->par;
53354 return snprintf(buf, PAGE_SIZE, "%u\n",
53355- atomic_read(&dev->bytes_rendered));
53356+ atomic_read_unchecked(&dev->bytes_rendered));
53357 }
53358
53359 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53360@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53361 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53362 struct dlfb_data *dev = fb_info->par;
53363 return snprintf(buf, PAGE_SIZE, "%u\n",
53364- atomic_read(&dev->bytes_identical));
53365+ atomic_read_unchecked(&dev->bytes_identical));
53366 }
53367
53368 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53369@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53370 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53371 struct dlfb_data *dev = fb_info->par;
53372 return snprintf(buf, PAGE_SIZE, "%u\n",
53373- atomic_read(&dev->bytes_sent));
53374+ atomic_read_unchecked(&dev->bytes_sent));
53375 }
53376
53377 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53378@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53379 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53380 struct dlfb_data *dev = fb_info->par;
53381 return snprintf(buf, PAGE_SIZE, "%u\n",
53382- atomic_read(&dev->cpu_kcycles_used));
53383+ atomic_read_unchecked(&dev->cpu_kcycles_used));
53384 }
53385
53386 static ssize_t edid_show(
53387@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
53388 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53389 struct dlfb_data *dev = fb_info->par;
53390
53391- atomic_set(&dev->bytes_rendered, 0);
53392- atomic_set(&dev->bytes_identical, 0);
53393- atomic_set(&dev->bytes_sent, 0);
53394- atomic_set(&dev->cpu_kcycles_used, 0);
53395+ atomic_set_unchecked(&dev->bytes_rendered, 0);
53396+ atomic_set_unchecked(&dev->bytes_identical, 0);
53397+ atomic_set_unchecked(&dev->bytes_sent, 0);
53398+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
53399
53400 return count;
53401 }
53402diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
53403index 509d452..7c9d2de 100644
53404--- a/drivers/video/fbdev/uvesafb.c
53405+++ b/drivers/video/fbdev/uvesafb.c
53406@@ -19,6 +19,7 @@
53407 #include <linux/io.h>
53408 #include <linux/mutex.h>
53409 #include <linux/slab.h>
53410+#include <linux/moduleloader.h>
53411 #include <video/edid.h>
53412 #include <video/uvesafb.h>
53413 #ifdef CONFIG_X86
53414@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
53415 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
53416 par->pmi_setpal = par->ypan = 0;
53417 } else {
53418+
53419+#ifdef CONFIG_PAX_KERNEXEC
53420+#ifdef CONFIG_MODULES
53421+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
53422+#endif
53423+ if (!par->pmi_code) {
53424+ par->pmi_setpal = par->ypan = 0;
53425+ return 0;
53426+ }
53427+#endif
53428+
53429 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
53430 + task->t.regs.edi);
53431+
53432+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53433+ pax_open_kernel();
53434+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
53435+ pax_close_kernel();
53436+
53437+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
53438+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
53439+#else
53440 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
53441 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
53442+#endif
53443+
53444 printk(KERN_INFO "uvesafb: protected mode interface info at "
53445 "%04x:%04x\n",
53446 (u16)task->t.regs.es, (u16)task->t.regs.edi);
53447@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
53448 par->ypan = ypan;
53449
53450 if (par->pmi_setpal || par->ypan) {
53451+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
53452 if (__supported_pte_mask & _PAGE_NX) {
53453 par->pmi_setpal = par->ypan = 0;
53454 printk(KERN_WARNING "uvesafb: NX protection is active, "
53455 "better not use the PMI.\n");
53456- } else {
53457+ } else
53458+#endif
53459 uvesafb_vbe_getpmi(task, par);
53460- }
53461 }
53462 #else
53463 /* The protected mode interface is not available on non-x86. */
53464@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53465 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
53466
53467 /* Disable blanking if the user requested so. */
53468- if (!blank)
53469- info->fbops->fb_blank = NULL;
53470+ if (!blank) {
53471+ pax_open_kernel();
53472+ *(void **)&info->fbops->fb_blank = NULL;
53473+ pax_close_kernel();
53474+ }
53475
53476 /*
53477 * Find out how much IO memory is required for the mode with
53478@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53479 info->flags = FBINFO_FLAG_DEFAULT |
53480 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
53481
53482- if (!par->ypan)
53483- info->fbops->fb_pan_display = NULL;
53484+ if (!par->ypan) {
53485+ pax_open_kernel();
53486+ *(void **)&info->fbops->fb_pan_display = NULL;
53487+ pax_close_kernel();
53488+ }
53489 }
53490
53491 static void uvesafb_init_mtrr(struct fb_info *info)
53492@@ -1787,6 +1817,11 @@ out_mode:
53493 out:
53494 kfree(par->vbe_modes);
53495
53496+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53497+ if (par->pmi_code)
53498+ module_free_exec(NULL, par->pmi_code);
53499+#endif
53500+
53501 framebuffer_release(info);
53502 return err;
53503 }
53504@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
53505 kfree(par->vbe_state_orig);
53506 kfree(par->vbe_state_saved);
53507
53508+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53509+ if (par->pmi_code)
53510+ module_free_exec(NULL, par->pmi_code);
53511+#endif
53512+
53513 framebuffer_release(info);
53514 }
53515 return 0;
53516diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
53517index 6170e7f..dd63031 100644
53518--- a/drivers/video/fbdev/vesafb.c
53519+++ b/drivers/video/fbdev/vesafb.c
53520@@ -9,6 +9,7 @@
53521 */
53522
53523 #include <linux/module.h>
53524+#include <linux/moduleloader.h>
53525 #include <linux/kernel.h>
53526 #include <linux/errno.h>
53527 #include <linux/string.h>
53528@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53529 static int vram_total; /* Set total amount of memory */
53530 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53531 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53532-static void (*pmi_start)(void) __read_mostly;
53533-static void (*pmi_pal) (void) __read_mostly;
53534+static void (*pmi_start)(void) __read_only;
53535+static void (*pmi_pal) (void) __read_only;
53536 static int depth __read_mostly;
53537 static int vga_compat __read_mostly;
53538 /* --------------------------------------------------------------------- */
53539@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
53540 unsigned int size_remap;
53541 unsigned int size_total;
53542 char *option = NULL;
53543+ void *pmi_code = NULL;
53544
53545 /* ignore error return of fb_get_options */
53546 fb_get_options("vesafb", &option);
53547@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
53548 size_remap = size_total;
53549 vesafb_fix.smem_len = size_remap;
53550
53551-#ifndef __i386__
53552- screen_info.vesapm_seg = 0;
53553-#endif
53554-
53555 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53556 printk(KERN_WARNING
53557 "vesafb: cannot reserve video memory at 0x%lx\n",
53558@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53559 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53560 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53561
53562+#ifdef __i386__
53563+
53564+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53565+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
53566+ if (!pmi_code)
53567+#elif !defined(CONFIG_PAX_KERNEXEC)
53568+ if (0)
53569+#endif
53570+
53571+#endif
53572+ screen_info.vesapm_seg = 0;
53573+
53574 if (screen_info.vesapm_seg) {
53575- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53576- screen_info.vesapm_seg,screen_info.vesapm_off);
53577+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53578+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53579 }
53580
53581 if (screen_info.vesapm_seg < 0xc000)
53582@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53583
53584 if (ypan || pmi_setpal) {
53585 unsigned short *pmi_base;
53586+
53587 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53588- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53589- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53590+
53591+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53592+ pax_open_kernel();
53593+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53594+#else
53595+ pmi_code = pmi_base;
53596+#endif
53597+
53598+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53599+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53600+
53601+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53602+ pmi_start = ktva_ktla(pmi_start);
53603+ pmi_pal = ktva_ktla(pmi_pal);
53604+ pax_close_kernel();
53605+#endif
53606+
53607 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53608 if (pmi_base[3]) {
53609 printk(KERN_INFO "vesafb: pmi: ports = ");
53610@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53611 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53612 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53613
53614- if (!ypan)
53615- info->fbops->fb_pan_display = NULL;
53616+ if (!ypan) {
53617+ pax_open_kernel();
53618+ *(void **)&info->fbops->fb_pan_display = NULL;
53619+ pax_close_kernel();
53620+ }
53621
53622 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53623 err = -ENOMEM;
53624@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53625 fb_info(info, "%s frame buffer device\n", info->fix.id);
53626 return 0;
53627 err:
53628+
53629+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53630+ module_free_exec(NULL, pmi_code);
53631+#endif
53632+
53633 if (info->screen_base)
53634 iounmap(info->screen_base);
53635 framebuffer_release(info);
53636diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53637index 88714ae..16c2e11 100644
53638--- a/drivers/video/fbdev/via/via_clock.h
53639+++ b/drivers/video/fbdev/via/via_clock.h
53640@@ -56,7 +56,7 @@ struct via_clock {
53641
53642 void (*set_engine_pll_state)(u8 state);
53643 void (*set_engine_pll)(struct via_pll_config config);
53644-};
53645+} __no_const;
53646
53647
53648 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53649diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53650index 3c14e43..2630570 100644
53651--- a/drivers/video/logo/logo_linux_clut224.ppm
53652+++ b/drivers/video/logo/logo_linux_clut224.ppm
53653@@ -2,1603 +2,1123 @@ P3
53654 # Standard 224-color Linux logo
53655 80 80
53656 255
53657- 0 0 0 0 0 0 0 0 0 0 0 0
53658- 0 0 0 0 0 0 0 0 0 0 0 0
53659- 0 0 0 0 0 0 0 0 0 0 0 0
53660- 0 0 0 0 0 0 0 0 0 0 0 0
53661- 0 0 0 0 0 0 0 0 0 0 0 0
53662- 0 0 0 0 0 0 0 0 0 0 0 0
53663- 0 0 0 0 0 0 0 0 0 0 0 0
53664- 0 0 0 0 0 0 0 0 0 0 0 0
53665- 0 0 0 0 0 0 0 0 0 0 0 0
53666- 6 6 6 6 6 6 10 10 10 10 10 10
53667- 10 10 10 6 6 6 6 6 6 6 6 6
53668- 0 0 0 0 0 0 0 0 0 0 0 0
53669- 0 0 0 0 0 0 0 0 0 0 0 0
53670- 0 0 0 0 0 0 0 0 0 0 0 0
53671- 0 0 0 0 0 0 0 0 0 0 0 0
53672- 0 0 0 0 0 0 0 0 0 0 0 0
53673- 0 0 0 0 0 0 0 0 0 0 0 0
53674- 0 0 0 0 0 0 0 0 0 0 0 0
53675- 0 0 0 0 0 0 0 0 0 0 0 0
53676- 0 0 0 0 0 0 0 0 0 0 0 0
53677- 0 0 0 0 0 0 0 0 0 0 0 0
53678- 0 0 0 0 0 0 0 0 0 0 0 0
53679- 0 0 0 0 0 0 0 0 0 0 0 0
53680- 0 0 0 0 0 0 0 0 0 0 0 0
53681- 0 0 0 0 0 0 0 0 0 0 0 0
53682- 0 0 0 0 0 0 0 0 0 0 0 0
53683- 0 0 0 0 0 0 0 0 0 0 0 0
53684- 0 0 0 0 0 0 0 0 0 0 0 0
53685- 0 0 0 6 6 6 10 10 10 14 14 14
53686- 22 22 22 26 26 26 30 30 30 34 34 34
53687- 30 30 30 30 30 30 26 26 26 18 18 18
53688- 14 14 14 10 10 10 6 6 6 0 0 0
53689- 0 0 0 0 0 0 0 0 0 0 0 0
53690- 0 0 0 0 0 0 0 0 0 0 0 0
53691- 0 0 0 0 0 0 0 0 0 0 0 0
53692- 0 0 0 0 0 0 0 0 0 0 0 0
53693- 0 0 0 0 0 0 0 0 0 0 0 0
53694- 0 0 0 0 0 0 0 0 0 0 0 0
53695- 0 0 0 0 0 0 0 0 0 0 0 0
53696- 0 0 0 0 0 0 0 0 0 0 0 0
53697- 0 0 0 0 0 0 0 0 0 0 0 0
53698- 0 0 0 0 0 1 0 0 1 0 0 0
53699- 0 0 0 0 0 0 0 0 0 0 0 0
53700- 0 0 0 0 0 0 0 0 0 0 0 0
53701- 0 0 0 0 0 0 0 0 0 0 0 0
53702- 0 0 0 0 0 0 0 0 0 0 0 0
53703- 0 0 0 0 0 0 0 0 0 0 0 0
53704- 0 0 0 0 0 0 0 0 0 0 0 0
53705- 6 6 6 14 14 14 26 26 26 42 42 42
53706- 54 54 54 66 66 66 78 78 78 78 78 78
53707- 78 78 78 74 74 74 66 66 66 54 54 54
53708- 42 42 42 26 26 26 18 18 18 10 10 10
53709- 6 6 6 0 0 0 0 0 0 0 0 0
53710- 0 0 0 0 0 0 0 0 0 0 0 0
53711- 0 0 0 0 0 0 0 0 0 0 0 0
53712- 0 0 0 0 0 0 0 0 0 0 0 0
53713- 0 0 0 0 0 0 0 0 0 0 0 0
53714- 0 0 0 0 0 0 0 0 0 0 0 0
53715- 0 0 0 0 0 0 0 0 0 0 0 0
53716- 0 0 0 0 0 0 0 0 0 0 0 0
53717- 0 0 0 0 0 0 0 0 0 0 0 0
53718- 0 0 1 0 0 0 0 0 0 0 0 0
53719- 0 0 0 0 0 0 0 0 0 0 0 0
53720- 0 0 0 0 0 0 0 0 0 0 0 0
53721- 0 0 0 0 0 0 0 0 0 0 0 0
53722- 0 0 0 0 0 0 0 0 0 0 0 0
53723- 0 0 0 0 0 0 0 0 0 0 0 0
53724- 0 0 0 0 0 0 0 0 0 10 10 10
53725- 22 22 22 42 42 42 66 66 66 86 86 86
53726- 66 66 66 38 38 38 38 38 38 22 22 22
53727- 26 26 26 34 34 34 54 54 54 66 66 66
53728- 86 86 86 70 70 70 46 46 46 26 26 26
53729- 14 14 14 6 6 6 0 0 0 0 0 0
53730- 0 0 0 0 0 0 0 0 0 0 0 0
53731- 0 0 0 0 0 0 0 0 0 0 0 0
53732- 0 0 0 0 0 0 0 0 0 0 0 0
53733- 0 0 0 0 0 0 0 0 0 0 0 0
53734- 0 0 0 0 0 0 0 0 0 0 0 0
53735- 0 0 0 0 0 0 0 0 0 0 0 0
53736- 0 0 0 0 0 0 0 0 0 0 0 0
53737- 0 0 0 0 0 0 0 0 0 0 0 0
53738- 0 0 1 0 0 1 0 0 1 0 0 0
53739- 0 0 0 0 0 0 0 0 0 0 0 0
53740- 0 0 0 0 0 0 0 0 0 0 0 0
53741- 0 0 0 0 0 0 0 0 0 0 0 0
53742- 0 0 0 0 0 0 0 0 0 0 0 0
53743- 0 0 0 0 0 0 0 0 0 0 0 0
53744- 0 0 0 0 0 0 10 10 10 26 26 26
53745- 50 50 50 82 82 82 58 58 58 6 6 6
53746- 2 2 6 2 2 6 2 2 6 2 2 6
53747- 2 2 6 2 2 6 2 2 6 2 2 6
53748- 6 6 6 54 54 54 86 86 86 66 66 66
53749- 38 38 38 18 18 18 6 6 6 0 0 0
53750- 0 0 0 0 0 0 0 0 0 0 0 0
53751- 0 0 0 0 0 0 0 0 0 0 0 0
53752- 0 0 0 0 0 0 0 0 0 0 0 0
53753- 0 0 0 0 0 0 0 0 0 0 0 0
53754- 0 0 0 0 0 0 0 0 0 0 0 0
53755- 0 0 0 0 0 0 0 0 0 0 0 0
53756- 0 0 0 0 0 0 0 0 0 0 0 0
53757- 0 0 0 0 0 0 0 0 0 0 0 0
53758- 0 0 0 0 0 0 0 0 0 0 0 0
53759- 0 0 0 0 0 0 0 0 0 0 0 0
53760- 0 0 0 0 0 0 0 0 0 0 0 0
53761- 0 0 0 0 0 0 0 0 0 0 0 0
53762- 0 0 0 0 0 0 0 0 0 0 0 0
53763- 0 0 0 0 0 0 0 0 0 0 0 0
53764- 0 0 0 6 6 6 22 22 22 50 50 50
53765- 78 78 78 34 34 34 2 2 6 2 2 6
53766- 2 2 6 2 2 6 2 2 6 2 2 6
53767- 2 2 6 2 2 6 2 2 6 2 2 6
53768- 2 2 6 2 2 6 6 6 6 70 70 70
53769- 78 78 78 46 46 46 22 22 22 6 6 6
53770- 0 0 0 0 0 0 0 0 0 0 0 0
53771- 0 0 0 0 0 0 0 0 0 0 0 0
53772- 0 0 0 0 0 0 0 0 0 0 0 0
53773- 0 0 0 0 0 0 0 0 0 0 0 0
53774- 0 0 0 0 0 0 0 0 0 0 0 0
53775- 0 0 0 0 0 0 0 0 0 0 0 0
53776- 0 0 0 0 0 0 0 0 0 0 0 0
53777- 0 0 0 0 0 0 0 0 0 0 0 0
53778- 0 0 1 0 0 1 0 0 1 0 0 0
53779- 0 0 0 0 0 0 0 0 0 0 0 0
53780- 0 0 0 0 0 0 0 0 0 0 0 0
53781- 0 0 0 0 0 0 0 0 0 0 0 0
53782- 0 0 0 0 0 0 0 0 0 0 0 0
53783- 0 0 0 0 0 0 0 0 0 0 0 0
53784- 6 6 6 18 18 18 42 42 42 82 82 82
53785- 26 26 26 2 2 6 2 2 6 2 2 6
53786- 2 2 6 2 2 6 2 2 6 2 2 6
53787- 2 2 6 2 2 6 2 2 6 14 14 14
53788- 46 46 46 34 34 34 6 6 6 2 2 6
53789- 42 42 42 78 78 78 42 42 42 18 18 18
53790- 6 6 6 0 0 0 0 0 0 0 0 0
53791- 0 0 0 0 0 0 0 0 0 0 0 0
53792- 0 0 0 0 0 0 0 0 0 0 0 0
53793- 0 0 0 0 0 0 0 0 0 0 0 0
53794- 0 0 0 0 0 0 0 0 0 0 0 0
53795- 0 0 0 0 0 0 0 0 0 0 0 0
53796- 0 0 0 0 0 0 0 0 0 0 0 0
53797- 0 0 0 0 0 0 0 0 0 0 0 0
53798- 0 0 1 0 0 0 0 0 1 0 0 0
53799- 0 0 0 0 0 0 0 0 0 0 0 0
53800- 0 0 0 0 0 0 0 0 0 0 0 0
53801- 0 0 0 0 0 0 0 0 0 0 0 0
53802- 0 0 0 0 0 0 0 0 0 0 0 0
53803- 0 0 0 0 0 0 0 0 0 0 0 0
53804- 10 10 10 30 30 30 66 66 66 58 58 58
53805- 2 2 6 2 2 6 2 2 6 2 2 6
53806- 2 2 6 2 2 6 2 2 6 2 2 6
53807- 2 2 6 2 2 6 2 2 6 26 26 26
53808- 86 86 86 101 101 101 46 46 46 10 10 10
53809- 2 2 6 58 58 58 70 70 70 34 34 34
53810- 10 10 10 0 0 0 0 0 0 0 0 0
53811- 0 0 0 0 0 0 0 0 0 0 0 0
53812- 0 0 0 0 0 0 0 0 0 0 0 0
53813- 0 0 0 0 0 0 0 0 0 0 0 0
53814- 0 0 0 0 0 0 0 0 0 0 0 0
53815- 0 0 0 0 0 0 0 0 0 0 0 0
53816- 0 0 0 0 0 0 0 0 0 0 0 0
53817- 0 0 0 0 0 0 0 0 0 0 0 0
53818- 0 0 1 0 0 1 0 0 1 0 0 0
53819- 0 0 0 0 0 0 0 0 0 0 0 0
53820- 0 0 0 0 0 0 0 0 0 0 0 0
53821- 0 0 0 0 0 0 0 0 0 0 0 0
53822- 0 0 0 0 0 0 0 0 0 0 0 0
53823- 0 0 0 0 0 0 0 0 0 0 0 0
53824- 14 14 14 42 42 42 86 86 86 10 10 10
53825- 2 2 6 2 2 6 2 2 6 2 2 6
53826- 2 2 6 2 2 6 2 2 6 2 2 6
53827- 2 2 6 2 2 6 2 2 6 30 30 30
53828- 94 94 94 94 94 94 58 58 58 26 26 26
53829- 2 2 6 6 6 6 78 78 78 54 54 54
53830- 22 22 22 6 6 6 0 0 0 0 0 0
53831- 0 0 0 0 0 0 0 0 0 0 0 0
53832- 0 0 0 0 0 0 0 0 0 0 0 0
53833- 0 0 0 0 0 0 0 0 0 0 0 0
53834- 0 0 0 0 0 0 0 0 0 0 0 0
53835- 0 0 0 0 0 0 0 0 0 0 0 0
53836- 0 0 0 0 0 0 0 0 0 0 0 0
53837- 0 0 0 0 0 0 0 0 0 0 0 0
53838- 0 0 0 0 0 0 0 0 0 0 0 0
53839- 0 0 0 0 0 0 0 0 0 0 0 0
53840- 0 0 0 0 0 0 0 0 0 0 0 0
53841- 0 0 0 0 0 0 0 0 0 0 0 0
53842- 0 0 0 0 0 0 0 0 0 0 0 0
53843- 0 0 0 0 0 0 0 0 0 6 6 6
53844- 22 22 22 62 62 62 62 62 62 2 2 6
53845- 2 2 6 2 2 6 2 2 6 2 2 6
53846- 2 2 6 2 2 6 2 2 6 2 2 6
53847- 2 2 6 2 2 6 2 2 6 26 26 26
53848- 54 54 54 38 38 38 18 18 18 10 10 10
53849- 2 2 6 2 2 6 34 34 34 82 82 82
53850- 38 38 38 14 14 14 0 0 0 0 0 0
53851- 0 0 0 0 0 0 0 0 0 0 0 0
53852- 0 0 0 0 0 0 0 0 0 0 0 0
53853- 0 0 0 0 0 0 0 0 0 0 0 0
53854- 0 0 0 0 0 0 0 0 0 0 0 0
53855- 0 0 0 0 0 0 0 0 0 0 0 0
53856- 0 0 0 0 0 0 0 0 0 0 0 0
53857- 0 0 0 0 0 0 0 0 0 0 0 0
53858- 0 0 0 0 0 1 0 0 1 0 0 0
53859- 0 0 0 0 0 0 0 0 0 0 0 0
53860- 0 0 0 0 0 0 0 0 0 0 0 0
53861- 0 0 0 0 0 0 0 0 0 0 0 0
53862- 0 0 0 0 0 0 0 0 0 0 0 0
53863- 0 0 0 0 0 0 0 0 0 6 6 6
53864- 30 30 30 78 78 78 30 30 30 2 2 6
53865- 2 2 6 2 2 6 2 2 6 2 2 6
53866- 2 2 6 2 2 6 2 2 6 2 2 6
53867- 2 2 6 2 2 6 2 2 6 10 10 10
53868- 10 10 10 2 2 6 2 2 6 2 2 6
53869- 2 2 6 2 2 6 2 2 6 78 78 78
53870- 50 50 50 18 18 18 6 6 6 0 0 0
53871- 0 0 0 0 0 0 0 0 0 0 0 0
53872- 0 0 0 0 0 0 0 0 0 0 0 0
53873- 0 0 0 0 0 0 0 0 0 0 0 0
53874- 0 0 0 0 0 0 0 0 0 0 0 0
53875- 0 0 0 0 0 0 0 0 0 0 0 0
53876- 0 0 0 0 0 0 0 0 0 0 0 0
53877- 0 0 0 0 0 0 0 0 0 0 0 0
53878- 0 0 1 0 0 0 0 0 0 0 0 0
53879- 0 0 0 0 0 0 0 0 0 0 0 0
53880- 0 0 0 0 0 0 0 0 0 0 0 0
53881- 0 0 0 0 0 0 0 0 0 0 0 0
53882- 0 0 0 0 0 0 0 0 0 0 0 0
53883- 0 0 0 0 0 0 0 0 0 10 10 10
53884- 38 38 38 86 86 86 14 14 14 2 2 6
53885- 2 2 6 2 2 6 2 2 6 2 2 6
53886- 2 2 6 2 2 6 2 2 6 2 2 6
53887- 2 2 6 2 2 6 2 2 6 2 2 6
53888- 2 2 6 2 2 6 2 2 6 2 2 6
53889- 2 2 6 2 2 6 2 2 6 54 54 54
53890- 66 66 66 26 26 26 6 6 6 0 0 0
53891- 0 0 0 0 0 0 0 0 0 0 0 0
53892- 0 0 0 0 0 0 0 0 0 0 0 0
53893- 0 0 0 0 0 0 0 0 0 0 0 0
53894- 0 0 0 0 0 0 0 0 0 0 0 0
53895- 0 0 0 0 0 0 0 0 0 0 0 0
53896- 0 0 0 0 0 0 0 0 0 0 0 0
53897- 0 0 0 0 0 0 0 0 0 0 0 0
53898- 0 0 0 0 0 1 0 0 1 0 0 0
53899- 0 0 0 0 0 0 0 0 0 0 0 0
53900- 0 0 0 0 0 0 0 0 0 0 0 0
53901- 0 0 0 0 0 0 0 0 0 0 0 0
53902- 0 0 0 0 0 0 0 0 0 0 0 0
53903- 0 0 0 0 0 0 0 0 0 14 14 14
53904- 42 42 42 82 82 82 2 2 6 2 2 6
53905- 2 2 6 6 6 6 10 10 10 2 2 6
53906- 2 2 6 2 2 6 2 2 6 2 2 6
53907- 2 2 6 2 2 6 2 2 6 6 6 6
53908- 14 14 14 10 10 10 2 2 6 2 2 6
53909- 2 2 6 2 2 6 2 2 6 18 18 18
53910- 82 82 82 34 34 34 10 10 10 0 0 0
53911- 0 0 0 0 0 0 0 0 0 0 0 0
53912- 0 0 0 0 0 0 0 0 0 0 0 0
53913- 0 0 0 0 0 0 0 0 0 0 0 0
53914- 0 0 0 0 0 0 0 0 0 0 0 0
53915- 0 0 0 0 0 0 0 0 0 0 0 0
53916- 0 0 0 0 0 0 0 0 0 0 0 0
53917- 0 0 0 0 0 0 0 0 0 0 0 0
53918- 0 0 1 0 0 0 0 0 0 0 0 0
53919- 0 0 0 0 0 0 0 0 0 0 0 0
53920- 0 0 0 0 0 0 0 0 0 0 0 0
53921- 0 0 0 0 0 0 0 0 0 0 0 0
53922- 0 0 0 0 0 0 0 0 0 0 0 0
53923- 0 0 0 0 0 0 0 0 0 14 14 14
53924- 46 46 46 86 86 86 2 2 6 2 2 6
53925- 6 6 6 6 6 6 22 22 22 34 34 34
53926- 6 6 6 2 2 6 2 2 6 2 2 6
53927- 2 2 6 2 2 6 18 18 18 34 34 34
53928- 10 10 10 50 50 50 22 22 22 2 2 6
53929- 2 2 6 2 2 6 2 2 6 10 10 10
53930- 86 86 86 42 42 42 14 14 14 0 0 0
53931- 0 0 0 0 0 0 0 0 0 0 0 0
53932- 0 0 0 0 0 0 0 0 0 0 0 0
53933- 0 0 0 0 0 0 0 0 0 0 0 0
53934- 0 0 0 0 0 0 0 0 0 0 0 0
53935- 0 0 0 0 0 0 0 0 0 0 0 0
53936- 0 0 0 0 0 0 0 0 0 0 0 0
53937- 0 0 0 0 0 0 0 0 0 0 0 0
53938- 0 0 1 0 0 1 0 0 1 0 0 0
53939- 0 0 0 0 0 0 0 0 0 0 0 0
53940- 0 0 0 0 0 0 0 0 0 0 0 0
53941- 0 0 0 0 0 0 0 0 0 0 0 0
53942- 0 0 0 0 0 0 0 0 0 0 0 0
53943- 0 0 0 0 0 0 0 0 0 14 14 14
53944- 46 46 46 86 86 86 2 2 6 2 2 6
53945- 38 38 38 116 116 116 94 94 94 22 22 22
53946- 22 22 22 2 2 6 2 2 6 2 2 6
53947- 14 14 14 86 86 86 138 138 138 162 162 162
53948-154 154 154 38 38 38 26 26 26 6 6 6
53949- 2 2 6 2 2 6 2 2 6 2 2 6
53950- 86 86 86 46 46 46 14 14 14 0 0 0
53951- 0 0 0 0 0 0 0 0 0 0 0 0
53952- 0 0 0 0 0 0 0 0 0 0 0 0
53953- 0 0 0 0 0 0 0 0 0 0 0 0
53954- 0 0 0 0 0 0 0 0 0 0 0 0
53955- 0 0 0 0 0 0 0 0 0 0 0 0
53956- 0 0 0 0 0 0 0 0 0 0 0 0
53957- 0 0 0 0 0 0 0 0 0 0 0 0
53958- 0 0 0 0 0 0 0 0 0 0 0 0
53959- 0 0 0 0 0 0 0 0 0 0 0 0
53960- 0 0 0 0 0 0 0 0 0 0 0 0
53961- 0 0 0 0 0 0 0 0 0 0 0 0
53962- 0 0 0 0 0 0 0 0 0 0 0 0
53963- 0 0 0 0 0 0 0 0 0 14 14 14
53964- 46 46 46 86 86 86 2 2 6 14 14 14
53965-134 134 134 198 198 198 195 195 195 116 116 116
53966- 10 10 10 2 2 6 2 2 6 6 6 6
53967-101 98 89 187 187 187 210 210 210 218 218 218
53968-214 214 214 134 134 134 14 14 14 6 6 6
53969- 2 2 6 2 2 6 2 2 6 2 2 6
53970- 86 86 86 50 50 50 18 18 18 6 6 6
53971- 0 0 0 0 0 0 0 0 0 0 0 0
53972- 0 0 0 0 0 0 0 0 0 0 0 0
53973- 0 0 0 0 0 0 0 0 0 0 0 0
53974- 0 0 0 0 0 0 0 0 0 0 0 0
53975- 0 0 0 0 0 0 0 0 0 0 0 0
53976- 0 0 0 0 0 0 0 0 0 0 0 0
53977- 0 0 0 0 0 0 0 0 1 0 0 0
53978- 0 0 1 0 0 1 0 0 1 0 0 0
53979- 0 0 0 0 0 0 0 0 0 0 0 0
53980- 0 0 0 0 0 0 0 0 0 0 0 0
53981- 0 0 0 0 0 0 0 0 0 0 0 0
53982- 0 0 0 0 0 0 0 0 0 0 0 0
53983- 0 0 0 0 0 0 0 0 0 14 14 14
53984- 46 46 46 86 86 86 2 2 6 54 54 54
53985-218 218 218 195 195 195 226 226 226 246 246 246
53986- 58 58 58 2 2 6 2 2 6 30 30 30
53987-210 210 210 253 253 253 174 174 174 123 123 123
53988-221 221 221 234 234 234 74 74 74 2 2 6
53989- 2 2 6 2 2 6 2 2 6 2 2 6
53990- 70 70 70 58 58 58 22 22 22 6 6 6
53991- 0 0 0 0 0 0 0 0 0 0 0 0
53992- 0 0 0 0 0 0 0 0 0 0 0 0
53993- 0 0 0 0 0 0 0 0 0 0 0 0
53994- 0 0 0 0 0 0 0 0 0 0 0 0
53995- 0 0 0 0 0 0 0 0 0 0 0 0
53996- 0 0 0 0 0 0 0 0 0 0 0 0
53997- 0 0 0 0 0 0 0 0 0 0 0 0
53998- 0 0 0 0 0 0 0 0 0 0 0 0
53999- 0 0 0 0 0 0 0 0 0 0 0 0
54000- 0 0 0 0 0 0 0 0 0 0 0 0
54001- 0 0 0 0 0 0 0 0 0 0 0 0
54002- 0 0 0 0 0 0 0 0 0 0 0 0
54003- 0 0 0 0 0 0 0 0 0 14 14 14
54004- 46 46 46 82 82 82 2 2 6 106 106 106
54005-170 170 170 26 26 26 86 86 86 226 226 226
54006-123 123 123 10 10 10 14 14 14 46 46 46
54007-231 231 231 190 190 190 6 6 6 70 70 70
54008- 90 90 90 238 238 238 158 158 158 2 2 6
54009- 2 2 6 2 2 6 2 2 6 2 2 6
54010- 70 70 70 58 58 58 22 22 22 6 6 6
54011- 0 0 0 0 0 0 0 0 0 0 0 0
54012- 0 0 0 0 0 0 0 0 0 0 0 0
54013- 0 0 0 0 0 0 0 0 0 0 0 0
54014- 0 0 0 0 0 0 0 0 0 0 0 0
54015- 0 0 0 0 0 0 0 0 0 0 0 0
54016- 0 0 0 0 0 0 0 0 0 0 0 0
54017- 0 0 0 0 0 0 0 0 1 0 0 0
54018- 0 0 1 0 0 1 0 0 1 0 0 0
54019- 0 0 0 0 0 0 0 0 0 0 0 0
54020- 0 0 0 0 0 0 0 0 0 0 0 0
54021- 0 0 0 0 0 0 0 0 0 0 0 0
54022- 0 0 0 0 0 0 0 0 0 0 0 0
54023- 0 0 0 0 0 0 0 0 0 14 14 14
54024- 42 42 42 86 86 86 6 6 6 116 116 116
54025-106 106 106 6 6 6 70 70 70 149 149 149
54026-128 128 128 18 18 18 38 38 38 54 54 54
54027-221 221 221 106 106 106 2 2 6 14 14 14
54028- 46 46 46 190 190 190 198 198 198 2 2 6
54029- 2 2 6 2 2 6 2 2 6 2 2 6
54030- 74 74 74 62 62 62 22 22 22 6 6 6
54031- 0 0 0 0 0 0 0 0 0 0 0 0
54032- 0 0 0 0 0 0 0 0 0 0 0 0
54033- 0 0 0 0 0 0 0 0 0 0 0 0
54034- 0 0 0 0 0 0 0 0 0 0 0 0
54035- 0 0 0 0 0 0 0 0 0 0 0 0
54036- 0 0 0 0 0 0 0 0 0 0 0 0
54037- 0 0 0 0 0 0 0 0 1 0 0 0
54038- 0 0 1 0 0 0 0 0 1 0 0 0
54039- 0 0 0 0 0 0 0 0 0 0 0 0
54040- 0 0 0 0 0 0 0 0 0 0 0 0
54041- 0 0 0 0 0 0 0 0 0 0 0 0
54042- 0 0 0 0 0 0 0 0 0 0 0 0
54043- 0 0 0 0 0 0 0 0 0 14 14 14
54044- 42 42 42 94 94 94 14 14 14 101 101 101
54045-128 128 128 2 2 6 18 18 18 116 116 116
54046-118 98 46 121 92 8 121 92 8 98 78 10
54047-162 162 162 106 106 106 2 2 6 2 2 6
54048- 2 2 6 195 195 195 195 195 195 6 6 6
54049- 2 2 6 2 2 6 2 2 6 2 2 6
54050- 74 74 74 62 62 62 22 22 22 6 6 6
54051- 0 0 0 0 0 0 0 0 0 0 0 0
54052- 0 0 0 0 0 0 0 0 0 0 0 0
54053- 0 0 0 0 0 0 0 0 0 0 0 0
54054- 0 0 0 0 0 0 0 0 0 0 0 0
54055- 0 0 0 0 0 0 0 0 0 0 0 0
54056- 0 0 0 0 0 0 0 0 0 0 0 0
54057- 0 0 0 0 0 0 0 0 1 0 0 1
54058- 0 0 1 0 0 0 0 0 1 0 0 0
54059- 0 0 0 0 0 0 0 0 0 0 0 0
54060- 0 0 0 0 0 0 0 0 0 0 0 0
54061- 0 0 0 0 0 0 0 0 0 0 0 0
54062- 0 0 0 0 0 0 0 0 0 0 0 0
54063- 0 0 0 0 0 0 0 0 0 10 10 10
54064- 38 38 38 90 90 90 14 14 14 58 58 58
54065-210 210 210 26 26 26 54 38 6 154 114 10
54066-226 170 11 236 186 11 225 175 15 184 144 12
54067-215 174 15 175 146 61 37 26 9 2 2 6
54068- 70 70 70 246 246 246 138 138 138 2 2 6
54069- 2 2 6 2 2 6 2 2 6 2 2 6
54070- 70 70 70 66 66 66 26 26 26 6 6 6
54071- 0 0 0 0 0 0 0 0 0 0 0 0
54072- 0 0 0 0 0 0 0 0 0 0 0 0
54073- 0 0 0 0 0 0 0 0 0 0 0 0
54074- 0 0 0 0 0 0 0 0 0 0 0 0
54075- 0 0 0 0 0 0 0 0 0 0 0 0
54076- 0 0 0 0 0 0 0 0 0 0 0 0
54077- 0 0 0 0 0 0 0 0 0 0 0 0
54078- 0 0 0 0 0 0 0 0 0 0 0 0
54079- 0 0 0 0 0 0 0 0 0 0 0 0
54080- 0 0 0 0 0 0 0 0 0 0 0 0
54081- 0 0 0 0 0 0 0 0 0 0 0 0
54082- 0 0 0 0 0 0 0 0 0 0 0 0
54083- 0 0 0 0 0 0 0 0 0 10 10 10
54084- 38 38 38 86 86 86 14 14 14 10 10 10
54085-195 195 195 188 164 115 192 133 9 225 175 15
54086-239 182 13 234 190 10 232 195 16 232 200 30
54087-245 207 45 241 208 19 232 195 16 184 144 12
54088-218 194 134 211 206 186 42 42 42 2 2 6
54089- 2 2 6 2 2 6 2 2 6 2 2 6
54090- 50 50 50 74 74 74 30 30 30 6 6 6
54091- 0 0 0 0 0 0 0 0 0 0 0 0
54092- 0 0 0 0 0 0 0 0 0 0 0 0
54093- 0 0 0 0 0 0 0 0 0 0 0 0
54094- 0 0 0 0 0 0 0 0 0 0 0 0
54095- 0 0 0 0 0 0 0 0 0 0 0 0
54096- 0 0 0 0 0 0 0 0 0 0 0 0
54097- 0 0 0 0 0 0 0 0 0 0 0 0
54098- 0 0 0 0 0 0 0 0 0 0 0 0
54099- 0 0 0 0 0 0 0 0 0 0 0 0
54100- 0 0 0 0 0 0 0 0 0 0 0 0
54101- 0 0 0 0 0 0 0 0 0 0 0 0
54102- 0 0 0 0 0 0 0 0 0 0 0 0
54103- 0 0 0 0 0 0 0 0 0 10 10 10
54104- 34 34 34 86 86 86 14 14 14 2 2 6
54105-121 87 25 192 133 9 219 162 10 239 182 13
54106-236 186 11 232 195 16 241 208 19 244 214 54
54107-246 218 60 246 218 38 246 215 20 241 208 19
54108-241 208 19 226 184 13 121 87 25 2 2 6
54109- 2 2 6 2 2 6 2 2 6 2 2 6
54110- 50 50 50 82 82 82 34 34 34 10 10 10
54111- 0 0 0 0 0 0 0 0 0 0 0 0
54112- 0 0 0 0 0 0 0 0 0 0 0 0
54113- 0 0 0 0 0 0 0 0 0 0 0 0
54114- 0 0 0 0 0 0 0 0 0 0 0 0
54115- 0 0 0 0 0 0 0 0 0 0 0 0
54116- 0 0 0 0 0 0 0 0 0 0 0 0
54117- 0 0 0 0 0 0 0 0 0 0 0 0
54118- 0 0 0 0 0 0 0 0 0 0 0 0
54119- 0 0 0 0 0 0 0 0 0 0 0 0
54120- 0 0 0 0 0 0 0 0 0 0 0 0
54121- 0 0 0 0 0 0 0 0 0 0 0 0
54122- 0 0 0 0 0 0 0 0 0 0 0 0
54123- 0 0 0 0 0 0 0 0 0 10 10 10
54124- 34 34 34 82 82 82 30 30 30 61 42 6
54125-180 123 7 206 145 10 230 174 11 239 182 13
54126-234 190 10 238 202 15 241 208 19 246 218 74
54127-246 218 38 246 215 20 246 215 20 246 215 20
54128-226 184 13 215 174 15 184 144 12 6 6 6
54129- 2 2 6 2 2 6 2 2 6 2 2 6
54130- 26 26 26 94 94 94 42 42 42 14 14 14
54131- 0 0 0 0 0 0 0 0 0 0 0 0
54132- 0 0 0 0 0 0 0 0 0 0 0 0
54133- 0 0 0 0 0 0 0 0 0 0 0 0
54134- 0 0 0 0 0 0 0 0 0 0 0 0
54135- 0 0 0 0 0 0 0 0 0 0 0 0
54136- 0 0 0 0 0 0 0 0 0 0 0 0
54137- 0 0 0 0 0 0 0 0 0 0 0 0
54138- 0 0 0 0 0 0 0 0 0 0 0 0
54139- 0 0 0 0 0 0 0 0 0 0 0 0
54140- 0 0 0 0 0 0 0 0 0 0 0 0
54141- 0 0 0 0 0 0 0 0 0 0 0 0
54142- 0 0 0 0 0 0 0 0 0 0 0 0
54143- 0 0 0 0 0 0 0 0 0 10 10 10
54144- 30 30 30 78 78 78 50 50 50 104 69 6
54145-192 133 9 216 158 10 236 178 12 236 186 11
54146-232 195 16 241 208 19 244 214 54 245 215 43
54147-246 215 20 246 215 20 241 208 19 198 155 10
54148-200 144 11 216 158 10 156 118 10 2 2 6
54149- 2 2 6 2 2 6 2 2 6 2 2 6
54150- 6 6 6 90 90 90 54 54 54 18 18 18
54151- 6 6 6 0 0 0 0 0 0 0 0 0
54152- 0 0 0 0 0 0 0 0 0 0 0 0
54153- 0 0 0 0 0 0 0 0 0 0 0 0
54154- 0 0 0 0 0 0 0 0 0 0 0 0
54155- 0 0 0 0 0 0 0 0 0 0 0 0
54156- 0 0 0 0 0 0 0 0 0 0 0 0
54157- 0 0 0 0 0 0 0 0 0 0 0 0
54158- 0 0 0 0 0 0 0 0 0 0 0 0
54159- 0 0 0 0 0 0 0 0 0 0 0 0
54160- 0 0 0 0 0 0 0 0 0 0 0 0
54161- 0 0 0 0 0 0 0 0 0 0 0 0
54162- 0 0 0 0 0 0 0 0 0 0 0 0
54163- 0 0 0 0 0 0 0 0 0 10 10 10
54164- 30 30 30 78 78 78 46 46 46 22 22 22
54165-137 92 6 210 162 10 239 182 13 238 190 10
54166-238 202 15 241 208 19 246 215 20 246 215 20
54167-241 208 19 203 166 17 185 133 11 210 150 10
54168-216 158 10 210 150 10 102 78 10 2 2 6
54169- 6 6 6 54 54 54 14 14 14 2 2 6
54170- 2 2 6 62 62 62 74 74 74 30 30 30
54171- 10 10 10 0 0 0 0 0 0 0 0 0
54172- 0 0 0 0 0 0 0 0 0 0 0 0
54173- 0 0 0 0 0 0 0 0 0 0 0 0
54174- 0 0 0 0 0 0 0 0 0 0 0 0
54175- 0 0 0 0 0 0 0 0 0 0 0 0
54176- 0 0 0 0 0 0 0 0 0 0 0 0
54177- 0 0 0 0 0 0 0 0 0 0 0 0
54178- 0 0 0 0 0 0 0 0 0 0 0 0
54179- 0 0 0 0 0 0 0 0 0 0 0 0
54180- 0 0 0 0 0 0 0 0 0 0 0 0
54181- 0 0 0 0 0 0 0 0 0 0 0 0
54182- 0 0 0 0 0 0 0 0 0 0 0 0
54183- 0 0 0 0 0 0 0 0 0 10 10 10
54184- 34 34 34 78 78 78 50 50 50 6 6 6
54185- 94 70 30 139 102 15 190 146 13 226 184 13
54186-232 200 30 232 195 16 215 174 15 190 146 13
54187-168 122 10 192 133 9 210 150 10 213 154 11
54188-202 150 34 182 157 106 101 98 89 2 2 6
54189- 2 2 6 78 78 78 116 116 116 58 58 58
54190- 2 2 6 22 22 22 90 90 90 46 46 46
54191- 18 18 18 6 6 6 0 0 0 0 0 0
54192- 0 0 0 0 0 0 0 0 0 0 0 0
54193- 0 0 0 0 0 0 0 0 0 0 0 0
54194- 0 0 0 0 0 0 0 0 0 0 0 0
54195- 0 0 0 0 0 0 0 0 0 0 0 0
54196- 0 0 0 0 0 0 0 0 0 0 0 0
54197- 0 0 0 0 0 0 0 0 0 0 0 0
54198- 0 0 0 0 0 0 0 0 0 0 0 0
54199- 0 0 0 0 0 0 0 0 0 0 0 0
54200- 0 0 0 0 0 0 0 0 0 0 0 0
54201- 0 0 0 0 0 0 0 0 0 0 0 0
54202- 0 0 0 0 0 0 0 0 0 0 0 0
54203- 0 0 0 0 0 0 0 0 0 10 10 10
54204- 38 38 38 86 86 86 50 50 50 6 6 6
54205-128 128 128 174 154 114 156 107 11 168 122 10
54206-198 155 10 184 144 12 197 138 11 200 144 11
54207-206 145 10 206 145 10 197 138 11 188 164 115
54208-195 195 195 198 198 198 174 174 174 14 14 14
54209- 2 2 6 22 22 22 116 116 116 116 116 116
54210- 22 22 22 2 2 6 74 74 74 70 70 70
54211- 30 30 30 10 10 10 0 0 0 0 0 0
54212- 0 0 0 0 0 0 0 0 0 0 0 0
54213- 0 0 0 0 0 0 0 0 0 0 0 0
54214- 0 0 0 0 0 0 0 0 0 0 0 0
54215- 0 0 0 0 0 0 0 0 0 0 0 0
54216- 0 0 0 0 0 0 0 0 0 0 0 0
54217- 0 0 0 0 0 0 0 0 0 0 0 0
54218- 0 0 0 0 0 0 0 0 0 0 0 0
54219- 0 0 0 0 0 0 0 0 0 0 0 0
54220- 0 0 0 0 0 0 0 0 0 0 0 0
54221- 0 0 0 0 0 0 0 0 0 0 0 0
54222- 0 0 0 0 0 0 0 0 0 0 0 0
54223- 0 0 0 0 0 0 6 6 6 18 18 18
54224- 50 50 50 101 101 101 26 26 26 10 10 10
54225-138 138 138 190 190 190 174 154 114 156 107 11
54226-197 138 11 200 144 11 197 138 11 192 133 9
54227-180 123 7 190 142 34 190 178 144 187 187 187
54228-202 202 202 221 221 221 214 214 214 66 66 66
54229- 2 2 6 2 2 6 50 50 50 62 62 62
54230- 6 6 6 2 2 6 10 10 10 90 90 90
54231- 50 50 50 18 18 18 6 6 6 0 0 0
54232- 0 0 0 0 0 0 0 0 0 0 0 0
54233- 0 0 0 0 0 0 0 0 0 0 0 0
54234- 0 0 0 0 0 0 0 0 0 0 0 0
54235- 0 0 0 0 0 0 0 0 0 0 0 0
54236- 0 0 0 0 0 0 0 0 0 0 0 0
54237- 0 0 0 0 0 0 0 0 0 0 0 0
54238- 0 0 0 0 0 0 0 0 0 0 0 0
54239- 0 0 0 0 0 0 0 0 0 0 0 0
54240- 0 0 0 0 0 0 0 0 0 0 0 0
54241- 0 0 0 0 0 0 0 0 0 0 0 0
54242- 0 0 0 0 0 0 0 0 0 0 0 0
54243- 0 0 0 0 0 0 10 10 10 34 34 34
54244- 74 74 74 74 74 74 2 2 6 6 6 6
54245-144 144 144 198 198 198 190 190 190 178 166 146
54246-154 121 60 156 107 11 156 107 11 168 124 44
54247-174 154 114 187 187 187 190 190 190 210 210 210
54248-246 246 246 253 253 253 253 253 253 182 182 182
54249- 6 6 6 2 2 6 2 2 6 2 2 6
54250- 2 2 6 2 2 6 2 2 6 62 62 62
54251- 74 74 74 34 34 34 14 14 14 0 0 0
54252- 0 0 0 0 0 0 0 0 0 0 0 0
54253- 0 0 0 0 0 0 0 0 0 0 0 0
54254- 0 0 0 0 0 0 0 0 0 0 0 0
54255- 0 0 0 0 0 0 0 0 0 0 0 0
54256- 0 0 0 0 0 0 0 0 0 0 0 0
54257- 0 0 0 0 0 0 0 0 0 0 0 0
54258- 0 0 0 0 0 0 0 0 0 0 0 0
54259- 0 0 0 0 0 0 0 0 0 0 0 0
54260- 0 0 0 0 0 0 0 0 0 0 0 0
54261- 0 0 0 0 0 0 0 0 0 0 0 0
54262- 0 0 0 0 0 0 0 0 0 0 0 0
54263- 0 0 0 10 10 10 22 22 22 54 54 54
54264- 94 94 94 18 18 18 2 2 6 46 46 46
54265-234 234 234 221 221 221 190 190 190 190 190 190
54266-190 190 190 187 187 187 187 187 187 190 190 190
54267-190 190 190 195 195 195 214 214 214 242 242 242
54268-253 253 253 253 253 253 253 253 253 253 253 253
54269- 82 82 82 2 2 6 2 2 6 2 2 6
54270- 2 2 6 2 2 6 2 2 6 14 14 14
54271- 86 86 86 54 54 54 22 22 22 6 6 6
54272- 0 0 0 0 0 0 0 0 0 0 0 0
54273- 0 0 0 0 0 0 0 0 0 0 0 0
54274- 0 0 0 0 0 0 0 0 0 0 0 0
54275- 0 0 0 0 0 0 0 0 0 0 0 0
54276- 0 0 0 0 0 0 0 0 0 0 0 0
54277- 0 0 0 0 0 0 0 0 0 0 0 0
54278- 0 0 0 0 0 0 0 0 0 0 0 0
54279- 0 0 0 0 0 0 0 0 0 0 0 0
54280- 0 0 0 0 0 0 0 0 0 0 0 0
54281- 0 0 0 0 0 0 0 0 0 0 0 0
54282- 0 0 0 0 0 0 0 0 0 0 0 0
54283- 6 6 6 18 18 18 46 46 46 90 90 90
54284- 46 46 46 18 18 18 6 6 6 182 182 182
54285-253 253 253 246 246 246 206 206 206 190 190 190
54286-190 190 190 190 190 190 190 190 190 190 190 190
54287-206 206 206 231 231 231 250 250 250 253 253 253
54288-253 253 253 253 253 253 253 253 253 253 253 253
54289-202 202 202 14 14 14 2 2 6 2 2 6
54290- 2 2 6 2 2 6 2 2 6 2 2 6
54291- 42 42 42 86 86 86 42 42 42 18 18 18
54292- 6 6 6 0 0 0 0 0 0 0 0 0
54293- 0 0 0 0 0 0 0 0 0 0 0 0
54294- 0 0 0 0 0 0 0 0 0 0 0 0
54295- 0 0 0 0 0 0 0 0 0 0 0 0
54296- 0 0 0 0 0 0 0 0 0 0 0 0
54297- 0 0 0 0 0 0 0 0 0 0 0 0
54298- 0 0 0 0 0 0 0 0 0 0 0 0
54299- 0 0 0 0 0 0 0 0 0 0 0 0
54300- 0 0 0 0 0 0 0 0 0 0 0 0
54301- 0 0 0 0 0 0 0 0 0 0 0 0
54302- 0 0 0 0 0 0 0 0 0 6 6 6
54303- 14 14 14 38 38 38 74 74 74 66 66 66
54304- 2 2 6 6 6 6 90 90 90 250 250 250
54305-253 253 253 253 253 253 238 238 238 198 198 198
54306-190 190 190 190 190 190 195 195 195 221 221 221
54307-246 246 246 253 253 253 253 253 253 253 253 253
54308-253 253 253 253 253 253 253 253 253 253 253 253
54309-253 253 253 82 82 82 2 2 6 2 2 6
54310- 2 2 6 2 2 6 2 2 6 2 2 6
54311- 2 2 6 78 78 78 70 70 70 34 34 34
54312- 14 14 14 6 6 6 0 0 0 0 0 0
54313- 0 0 0 0 0 0 0 0 0 0 0 0
54314- 0 0 0 0 0 0 0 0 0 0 0 0
54315- 0 0 0 0 0 0 0 0 0 0 0 0
54316- 0 0 0 0 0 0 0 0 0 0 0 0
54317- 0 0 0 0 0 0 0 0 0 0 0 0
54318- 0 0 0 0 0 0 0 0 0 0 0 0
54319- 0 0 0 0 0 0 0 0 0 0 0 0
54320- 0 0 0 0 0 0 0 0 0 0 0 0
54321- 0 0 0 0 0 0 0 0 0 0 0 0
54322- 0 0 0 0 0 0 0 0 0 14 14 14
54323- 34 34 34 66 66 66 78 78 78 6 6 6
54324- 2 2 6 18 18 18 218 218 218 253 253 253
54325-253 253 253 253 253 253 253 253 253 246 246 246
54326-226 226 226 231 231 231 246 246 246 253 253 253
54327-253 253 253 253 253 253 253 253 253 253 253 253
54328-253 253 253 253 253 253 253 253 253 253 253 253
54329-253 253 253 178 178 178 2 2 6 2 2 6
54330- 2 2 6 2 2 6 2 2 6 2 2 6
54331- 2 2 6 18 18 18 90 90 90 62 62 62
54332- 30 30 30 10 10 10 0 0 0 0 0 0
54333- 0 0 0 0 0 0 0 0 0 0 0 0
54334- 0 0 0 0 0 0 0 0 0 0 0 0
54335- 0 0 0 0 0 0 0 0 0 0 0 0
54336- 0 0 0 0 0 0 0 0 0 0 0 0
54337- 0 0 0 0 0 0 0 0 0 0 0 0
54338- 0 0 0 0 0 0 0 0 0 0 0 0
54339- 0 0 0 0 0 0 0 0 0 0 0 0
54340- 0 0 0 0 0 0 0 0 0 0 0 0
54341- 0 0 0 0 0 0 0 0 0 0 0 0
54342- 0 0 0 0 0 0 10 10 10 26 26 26
54343- 58 58 58 90 90 90 18 18 18 2 2 6
54344- 2 2 6 110 110 110 253 253 253 253 253 253
54345-253 253 253 253 253 253 253 253 253 253 253 253
54346-250 250 250 253 253 253 253 253 253 253 253 253
54347-253 253 253 253 253 253 253 253 253 253 253 253
54348-253 253 253 253 253 253 253 253 253 253 253 253
54349-253 253 253 231 231 231 18 18 18 2 2 6
54350- 2 2 6 2 2 6 2 2 6 2 2 6
54351- 2 2 6 2 2 6 18 18 18 94 94 94
54352- 54 54 54 26 26 26 10 10 10 0 0 0
54353- 0 0 0 0 0 0 0 0 0 0 0 0
54354- 0 0 0 0 0 0 0 0 0 0 0 0
54355- 0 0 0 0 0 0 0 0 0 0 0 0
54356- 0 0 0 0 0 0 0 0 0 0 0 0
54357- 0 0 0 0 0 0 0 0 0 0 0 0
54358- 0 0 0 0 0 0 0 0 0 0 0 0
54359- 0 0 0 0 0 0 0 0 0 0 0 0
54360- 0 0 0 0 0 0 0 0 0 0 0 0
54361- 0 0 0 0 0 0 0 0 0 0 0 0
54362- 0 0 0 6 6 6 22 22 22 50 50 50
54363- 90 90 90 26 26 26 2 2 6 2 2 6
54364- 14 14 14 195 195 195 250 250 250 253 253 253
54365-253 253 253 253 253 253 253 253 253 253 253 253
54366-253 253 253 253 253 253 253 253 253 253 253 253
54367-253 253 253 253 253 253 253 253 253 253 253 253
54368-253 253 253 253 253 253 253 253 253 253 253 253
54369-250 250 250 242 242 242 54 54 54 2 2 6
54370- 2 2 6 2 2 6 2 2 6 2 2 6
54371- 2 2 6 2 2 6 2 2 6 38 38 38
54372- 86 86 86 50 50 50 22 22 22 6 6 6
54373- 0 0 0 0 0 0 0 0 0 0 0 0
54374- 0 0 0 0 0 0 0 0 0 0 0 0
54375- 0 0 0 0 0 0 0 0 0 0 0 0
54376- 0 0 0 0 0 0 0 0 0 0 0 0
54377- 0 0 0 0 0 0 0 0 0 0 0 0
54378- 0 0 0 0 0 0 0 0 0 0 0 0
54379- 0 0 0 0 0 0 0 0 0 0 0 0
54380- 0 0 0 0 0 0 0 0 0 0 0 0
54381- 0 0 0 0 0 0 0 0 0 0 0 0
54382- 6 6 6 14 14 14 38 38 38 82 82 82
54383- 34 34 34 2 2 6 2 2 6 2 2 6
54384- 42 42 42 195 195 195 246 246 246 253 253 253
54385-253 253 253 253 253 253 253 253 253 250 250 250
54386-242 242 242 242 242 242 250 250 250 253 253 253
54387-253 253 253 253 253 253 253 253 253 253 253 253
54388-253 253 253 250 250 250 246 246 246 238 238 238
54389-226 226 226 231 231 231 101 101 101 6 6 6
54390- 2 2 6 2 2 6 2 2 6 2 2 6
54391- 2 2 6 2 2 6 2 2 6 2 2 6
54392- 38 38 38 82 82 82 42 42 42 14 14 14
54393- 6 6 6 0 0 0 0 0 0 0 0 0
54394- 0 0 0 0 0 0 0 0 0 0 0 0
54395- 0 0 0 0 0 0 0 0 0 0 0 0
54396- 0 0 0 0 0 0 0 0 0 0 0 0
54397- 0 0 0 0 0 0 0 0 0 0 0 0
54398- 0 0 0 0 0 0 0 0 0 0 0 0
54399- 0 0 0 0 0 0 0 0 0 0 0 0
54400- 0 0 0 0 0 0 0 0 0 0 0 0
54401- 0 0 0 0 0 0 0 0 0 0 0 0
54402- 10 10 10 26 26 26 62 62 62 66 66 66
54403- 2 2 6 2 2 6 2 2 6 6 6 6
54404- 70 70 70 170 170 170 206 206 206 234 234 234
54405-246 246 246 250 250 250 250 250 250 238 238 238
54406-226 226 226 231 231 231 238 238 238 250 250 250
54407-250 250 250 250 250 250 246 246 246 231 231 231
54408-214 214 214 206 206 206 202 202 202 202 202 202
54409-198 198 198 202 202 202 182 182 182 18 18 18
54410- 2 2 6 2 2 6 2 2 6 2 2 6
54411- 2 2 6 2 2 6 2 2 6 2 2 6
54412- 2 2 6 62 62 62 66 66 66 30 30 30
54413- 10 10 10 0 0 0 0 0 0 0 0 0
54414- 0 0 0 0 0 0 0 0 0 0 0 0
54415- 0 0 0 0 0 0 0 0 0 0 0 0
54416- 0 0 0 0 0 0 0 0 0 0 0 0
54417- 0 0 0 0 0 0 0 0 0 0 0 0
54418- 0 0 0 0 0 0 0 0 0 0 0 0
54419- 0 0 0 0 0 0 0 0 0 0 0 0
54420- 0 0 0 0 0 0 0 0 0 0 0 0
54421- 0 0 0 0 0 0 0 0 0 0 0 0
54422- 14 14 14 42 42 42 82 82 82 18 18 18
54423- 2 2 6 2 2 6 2 2 6 10 10 10
54424- 94 94 94 182 182 182 218 218 218 242 242 242
54425-250 250 250 253 253 253 253 253 253 250 250 250
54426-234 234 234 253 253 253 253 253 253 253 253 253
54427-253 253 253 253 253 253 253 253 253 246 246 246
54428-238 238 238 226 226 226 210 210 210 202 202 202
54429-195 195 195 195 195 195 210 210 210 158 158 158
54430- 6 6 6 14 14 14 50 50 50 14 14 14
54431- 2 2 6 2 2 6 2 2 6 2 2 6
54432- 2 2 6 6 6 6 86 86 86 46 46 46
54433- 18 18 18 6 6 6 0 0 0 0 0 0
54434- 0 0 0 0 0 0 0 0 0 0 0 0
54435- 0 0 0 0 0 0 0 0 0 0 0 0
54436- 0 0 0 0 0 0 0 0 0 0 0 0
54437- 0 0 0 0 0 0 0 0 0 0 0 0
54438- 0 0 0 0 0 0 0 0 0 0 0 0
54439- 0 0 0 0 0 0 0 0 0 0 0 0
54440- 0 0 0 0 0 0 0 0 0 0 0 0
54441- 0 0 0 0 0 0 0 0 0 6 6 6
54442- 22 22 22 54 54 54 70 70 70 2 2 6
54443- 2 2 6 10 10 10 2 2 6 22 22 22
54444-166 166 166 231 231 231 250 250 250 253 253 253
54445-253 253 253 253 253 253 253 253 253 250 250 250
54446-242 242 242 253 253 253 253 253 253 253 253 253
54447-253 253 253 253 253 253 253 253 253 253 253 253
54448-253 253 253 253 253 253 253 253 253 246 246 246
54449-231 231 231 206 206 206 198 198 198 226 226 226
54450- 94 94 94 2 2 6 6 6 6 38 38 38
54451- 30 30 30 2 2 6 2 2 6 2 2 6
54452- 2 2 6 2 2 6 62 62 62 66 66 66
54453- 26 26 26 10 10 10 0 0 0 0 0 0
54454- 0 0 0 0 0 0 0 0 0 0 0 0
54455- 0 0 0 0 0 0 0 0 0 0 0 0
54456- 0 0 0 0 0 0 0 0 0 0 0 0
54457- 0 0 0 0 0 0 0 0 0 0 0 0
54458- 0 0 0 0 0 0 0 0 0 0 0 0
54459- 0 0 0 0 0 0 0 0 0 0 0 0
54460- 0 0 0 0 0 0 0 0 0 0 0 0
54461- 0 0 0 0 0 0 0 0 0 10 10 10
54462- 30 30 30 74 74 74 50 50 50 2 2 6
54463- 26 26 26 26 26 26 2 2 6 106 106 106
54464-238 238 238 253 253 253 253 253 253 253 253 253
54465-253 253 253 253 253 253 253 253 253 253 253 253
54466-253 253 253 253 253 253 253 253 253 253 253 253
54467-253 253 253 253 253 253 253 253 253 253 253 253
54468-253 253 253 253 253 253 253 253 253 253 253 253
54469-253 253 253 246 246 246 218 218 218 202 202 202
54470-210 210 210 14 14 14 2 2 6 2 2 6
54471- 30 30 30 22 22 22 2 2 6 2 2 6
54472- 2 2 6 2 2 6 18 18 18 86 86 86
54473- 42 42 42 14 14 14 0 0 0 0 0 0
54474- 0 0 0 0 0 0 0 0 0 0 0 0
54475- 0 0 0 0 0 0 0 0 0 0 0 0
54476- 0 0 0 0 0 0 0 0 0 0 0 0
54477- 0 0 0 0 0 0 0 0 0 0 0 0
54478- 0 0 0 0 0 0 0 0 0 0 0 0
54479- 0 0 0 0 0 0 0 0 0 0 0 0
54480- 0 0 0 0 0 0 0 0 0 0 0 0
54481- 0 0 0 0 0 0 0 0 0 14 14 14
54482- 42 42 42 90 90 90 22 22 22 2 2 6
54483- 42 42 42 2 2 6 18 18 18 218 218 218
54484-253 253 253 253 253 253 253 253 253 253 253 253
54485-253 253 253 253 253 253 253 253 253 253 253 253
54486-253 253 253 253 253 253 253 253 253 253 253 253
54487-253 253 253 253 253 253 253 253 253 253 253 253
54488-253 253 253 253 253 253 253 253 253 253 253 253
54489-253 253 253 253 253 253 250 250 250 221 221 221
54490-218 218 218 101 101 101 2 2 6 14 14 14
54491- 18 18 18 38 38 38 10 10 10 2 2 6
54492- 2 2 6 2 2 6 2 2 6 78 78 78
54493- 58 58 58 22 22 22 6 6 6 0 0 0
54494- 0 0 0 0 0 0 0 0 0 0 0 0
54495- 0 0 0 0 0 0 0 0 0 0 0 0
54496- 0 0 0 0 0 0 0 0 0 0 0 0
54497- 0 0 0 0 0 0 0 0 0 0 0 0
54498- 0 0 0 0 0 0 0 0 0 0 0 0
54499- 0 0 0 0 0 0 0 0 0 0 0 0
54500- 0 0 0 0 0 0 0 0 0 0 0 0
54501- 0 0 0 0 0 0 6 6 6 18 18 18
54502- 54 54 54 82 82 82 2 2 6 26 26 26
54503- 22 22 22 2 2 6 123 123 123 253 253 253
54504-253 253 253 253 253 253 253 253 253 253 253 253
54505-253 253 253 253 253 253 253 253 253 253 253 253
54506-253 253 253 253 253 253 253 253 253 253 253 253
54507-253 253 253 253 253 253 253 253 253 253 253 253
54508-253 253 253 253 253 253 253 253 253 253 253 253
54509-253 253 253 253 253 253 253 253 253 250 250 250
54510-238 238 238 198 198 198 6 6 6 38 38 38
54511- 58 58 58 26 26 26 38 38 38 2 2 6
54512- 2 2 6 2 2 6 2 2 6 46 46 46
54513- 78 78 78 30 30 30 10 10 10 0 0 0
54514- 0 0 0 0 0 0 0 0 0 0 0 0
54515- 0 0 0 0 0 0 0 0 0 0 0 0
54516- 0 0 0 0 0 0 0 0 0 0 0 0
54517- 0 0 0 0 0 0 0 0 0 0 0 0
54518- 0 0 0 0 0 0 0 0 0 0 0 0
54519- 0 0 0 0 0 0 0 0 0 0 0 0
54520- 0 0 0 0 0 0 0 0 0 0 0 0
54521- 0 0 0 0 0 0 10 10 10 30 30 30
54522- 74 74 74 58 58 58 2 2 6 42 42 42
54523- 2 2 6 22 22 22 231 231 231 253 253 253
54524-253 253 253 253 253 253 253 253 253 253 253 253
54525-253 253 253 253 253 253 253 253 253 250 250 250
54526-253 253 253 253 253 253 253 253 253 253 253 253
54527-253 253 253 253 253 253 253 253 253 253 253 253
54528-253 253 253 253 253 253 253 253 253 253 253 253
54529-253 253 253 253 253 253 253 253 253 253 253 253
54530-253 253 253 246 246 246 46 46 46 38 38 38
54531- 42 42 42 14 14 14 38 38 38 14 14 14
54532- 2 2 6 2 2 6 2 2 6 6 6 6
54533- 86 86 86 46 46 46 14 14 14 0 0 0
54534- 0 0 0 0 0 0 0 0 0 0 0 0
54535- 0 0 0 0 0 0 0 0 0 0 0 0
54536- 0 0 0 0 0 0 0 0 0 0 0 0
54537- 0 0 0 0 0 0 0 0 0 0 0 0
54538- 0 0 0 0 0 0 0 0 0 0 0 0
54539- 0 0 0 0 0 0 0 0 0 0 0 0
54540- 0 0 0 0 0 0 0 0 0 0 0 0
54541- 0 0 0 6 6 6 14 14 14 42 42 42
54542- 90 90 90 18 18 18 18 18 18 26 26 26
54543- 2 2 6 116 116 116 253 253 253 253 253 253
54544-253 253 253 253 253 253 253 253 253 253 253 253
54545-253 253 253 253 253 253 250 250 250 238 238 238
54546-253 253 253 253 253 253 253 253 253 253 253 253
54547-253 253 253 253 253 253 253 253 253 253 253 253
54548-253 253 253 253 253 253 253 253 253 253 253 253
54549-253 253 253 253 253 253 253 253 253 253 253 253
54550-253 253 253 253 253 253 94 94 94 6 6 6
54551- 2 2 6 2 2 6 10 10 10 34 34 34
54552- 2 2 6 2 2 6 2 2 6 2 2 6
54553- 74 74 74 58 58 58 22 22 22 6 6 6
54554- 0 0 0 0 0 0 0 0 0 0 0 0
54555- 0 0 0 0 0 0 0 0 0 0 0 0
54556- 0 0 0 0 0 0 0 0 0 0 0 0
54557- 0 0 0 0 0 0 0 0 0 0 0 0
54558- 0 0 0 0 0 0 0 0 0 0 0 0
54559- 0 0 0 0 0 0 0 0 0 0 0 0
54560- 0 0 0 0 0 0 0 0 0 0 0 0
54561- 0 0 0 10 10 10 26 26 26 66 66 66
54562- 82 82 82 2 2 6 38 38 38 6 6 6
54563- 14 14 14 210 210 210 253 253 253 253 253 253
54564-253 253 253 253 253 253 253 253 253 253 253 253
54565-253 253 253 253 253 253 246 246 246 242 242 242
54566-253 253 253 253 253 253 253 253 253 253 253 253
54567-253 253 253 253 253 253 253 253 253 253 253 253
54568-253 253 253 253 253 253 253 253 253 253 253 253
54569-253 253 253 253 253 253 253 253 253 253 253 253
54570-253 253 253 253 253 253 144 144 144 2 2 6
54571- 2 2 6 2 2 6 2 2 6 46 46 46
54572- 2 2 6 2 2 6 2 2 6 2 2 6
54573- 42 42 42 74 74 74 30 30 30 10 10 10
54574- 0 0 0 0 0 0 0 0 0 0 0 0
54575- 0 0 0 0 0 0 0 0 0 0 0 0
54576- 0 0 0 0 0 0 0 0 0 0 0 0
54577- 0 0 0 0 0 0 0 0 0 0 0 0
54578- 0 0 0 0 0 0 0 0 0 0 0 0
54579- 0 0 0 0 0 0 0 0 0 0 0 0
54580- 0 0 0 0 0 0 0 0 0 0 0 0
54581- 6 6 6 14 14 14 42 42 42 90 90 90
54582- 26 26 26 6 6 6 42 42 42 2 2 6
54583- 74 74 74 250 250 250 253 253 253 253 253 253
54584-253 253 253 253 253 253 253 253 253 253 253 253
54585-253 253 253 253 253 253 242 242 242 242 242 242
54586-253 253 253 253 253 253 253 253 253 253 253 253
54587-253 253 253 253 253 253 253 253 253 253 253 253
54588-253 253 253 253 253 253 253 253 253 253 253 253
54589-253 253 253 253 253 253 253 253 253 253 253 253
54590-253 253 253 253 253 253 182 182 182 2 2 6
54591- 2 2 6 2 2 6 2 2 6 46 46 46
54592- 2 2 6 2 2 6 2 2 6 2 2 6
54593- 10 10 10 86 86 86 38 38 38 10 10 10
54594- 0 0 0 0 0 0 0 0 0 0 0 0
54595- 0 0 0 0 0 0 0 0 0 0 0 0
54596- 0 0 0 0 0 0 0 0 0 0 0 0
54597- 0 0 0 0 0 0 0 0 0 0 0 0
54598- 0 0 0 0 0 0 0 0 0 0 0 0
54599- 0 0 0 0 0 0 0 0 0 0 0 0
54600- 0 0 0 0 0 0 0 0 0 0 0 0
54601- 10 10 10 26 26 26 66 66 66 82 82 82
54602- 2 2 6 22 22 22 18 18 18 2 2 6
54603-149 149 149 253 253 253 253 253 253 253 253 253
54604-253 253 253 253 253 253 253 253 253 253 253 253
54605-253 253 253 253 253 253 234 234 234 242 242 242
54606-253 253 253 253 253 253 253 253 253 253 253 253
54607-253 253 253 253 253 253 253 253 253 253 253 253
54608-253 253 253 253 253 253 253 253 253 253 253 253
54609-253 253 253 253 253 253 253 253 253 253 253 253
54610-253 253 253 253 253 253 206 206 206 2 2 6
54611- 2 2 6 2 2 6 2 2 6 38 38 38
54612- 2 2 6 2 2 6 2 2 6 2 2 6
54613- 6 6 6 86 86 86 46 46 46 14 14 14
54614- 0 0 0 0 0 0 0 0 0 0 0 0
54615- 0 0 0 0 0 0 0 0 0 0 0 0
54616- 0 0 0 0 0 0 0 0 0 0 0 0
54617- 0 0 0 0 0 0 0 0 0 0 0 0
54618- 0 0 0 0 0 0 0 0 0 0 0 0
54619- 0 0 0 0 0 0 0 0 0 0 0 0
54620- 0 0 0 0 0 0 0 0 0 6 6 6
54621- 18 18 18 46 46 46 86 86 86 18 18 18
54622- 2 2 6 34 34 34 10 10 10 6 6 6
54623-210 210 210 253 253 253 253 253 253 253 253 253
54624-253 253 253 253 253 253 253 253 253 253 253 253
54625-253 253 253 253 253 253 234 234 234 242 242 242
54626-253 253 253 253 253 253 253 253 253 253 253 253
54627-253 253 253 253 253 253 253 253 253 253 253 253
54628-253 253 253 253 253 253 253 253 253 253 253 253
54629-253 253 253 253 253 253 253 253 253 253 253 253
54630-253 253 253 253 253 253 221 221 221 6 6 6
54631- 2 2 6 2 2 6 6 6 6 30 30 30
54632- 2 2 6 2 2 6 2 2 6 2 2 6
54633- 2 2 6 82 82 82 54 54 54 18 18 18
54634- 6 6 6 0 0 0 0 0 0 0 0 0
54635- 0 0 0 0 0 0 0 0 0 0 0 0
54636- 0 0 0 0 0 0 0 0 0 0 0 0
54637- 0 0 0 0 0 0 0 0 0 0 0 0
54638- 0 0 0 0 0 0 0 0 0 0 0 0
54639- 0 0 0 0 0 0 0 0 0 0 0 0
54640- 0 0 0 0 0 0 0 0 0 10 10 10
54641- 26 26 26 66 66 66 62 62 62 2 2 6
54642- 2 2 6 38 38 38 10 10 10 26 26 26
54643-238 238 238 253 253 253 253 253 253 253 253 253
54644-253 253 253 253 253 253 253 253 253 253 253 253
54645-253 253 253 253 253 253 231 231 231 238 238 238
54646-253 253 253 253 253 253 253 253 253 253 253 253
54647-253 253 253 253 253 253 253 253 253 253 253 253
54648-253 253 253 253 253 253 253 253 253 253 253 253
54649-253 253 253 253 253 253 253 253 253 253 253 253
54650-253 253 253 253 253 253 231 231 231 6 6 6
54651- 2 2 6 2 2 6 10 10 10 30 30 30
54652- 2 2 6 2 2 6 2 2 6 2 2 6
54653- 2 2 6 66 66 66 58 58 58 22 22 22
54654- 6 6 6 0 0 0 0 0 0 0 0 0
54655- 0 0 0 0 0 0 0 0 0 0 0 0
54656- 0 0 0 0 0 0 0 0 0 0 0 0
54657- 0 0 0 0 0 0 0 0 0 0 0 0
54658- 0 0 0 0 0 0 0 0 0 0 0 0
54659- 0 0 0 0 0 0 0 0 0 0 0 0
54660- 0 0 0 0 0 0 0 0 0 10 10 10
54661- 38 38 38 78 78 78 6 6 6 2 2 6
54662- 2 2 6 46 46 46 14 14 14 42 42 42
54663-246 246 246 253 253 253 253 253 253 253 253 253
54664-253 253 253 253 253 253 253 253 253 253 253 253
54665-253 253 253 253 253 253 231 231 231 242 242 242
54666-253 253 253 253 253 253 253 253 253 253 253 253
54667-253 253 253 253 253 253 253 253 253 253 253 253
54668-253 253 253 253 253 253 253 253 253 253 253 253
54669-253 253 253 253 253 253 253 253 253 253 253 253
54670-253 253 253 253 253 253 234 234 234 10 10 10
54671- 2 2 6 2 2 6 22 22 22 14 14 14
54672- 2 2 6 2 2 6 2 2 6 2 2 6
54673- 2 2 6 66 66 66 62 62 62 22 22 22
54674- 6 6 6 0 0 0 0 0 0 0 0 0
54675- 0 0 0 0 0 0 0 0 0 0 0 0
54676- 0 0 0 0 0 0 0 0 0 0 0 0
54677- 0 0 0 0 0 0 0 0 0 0 0 0
54678- 0 0 0 0 0 0 0 0 0 0 0 0
54679- 0 0 0 0 0 0 0 0 0 0 0 0
54680- 0 0 0 0 0 0 6 6 6 18 18 18
54681- 50 50 50 74 74 74 2 2 6 2 2 6
54682- 14 14 14 70 70 70 34 34 34 62 62 62
54683-250 250 250 253 253 253 253 253 253 253 253 253
54684-253 253 253 253 253 253 253 253 253 253 253 253
54685-253 253 253 253 253 253 231 231 231 246 246 246
54686-253 253 253 253 253 253 253 253 253 253 253 253
54687-253 253 253 253 253 253 253 253 253 253 253 253
54688-253 253 253 253 253 253 253 253 253 253 253 253
54689-253 253 253 253 253 253 253 253 253 253 253 253
54690-253 253 253 253 253 253 234 234 234 14 14 14
54691- 2 2 6 2 2 6 30 30 30 2 2 6
54692- 2 2 6 2 2 6 2 2 6 2 2 6
54693- 2 2 6 66 66 66 62 62 62 22 22 22
54694- 6 6 6 0 0 0 0 0 0 0 0 0
54695- 0 0 0 0 0 0 0 0 0 0 0 0
54696- 0 0 0 0 0 0 0 0 0 0 0 0
54697- 0 0 0 0 0 0 0 0 0 0 0 0
54698- 0 0 0 0 0 0 0 0 0 0 0 0
54699- 0 0 0 0 0 0 0 0 0 0 0 0
54700- 0 0 0 0 0 0 6 6 6 18 18 18
54701- 54 54 54 62 62 62 2 2 6 2 2 6
54702- 2 2 6 30 30 30 46 46 46 70 70 70
54703-250 250 250 253 253 253 253 253 253 253 253 253
54704-253 253 253 253 253 253 253 253 253 253 253 253
54705-253 253 253 253 253 253 231 231 231 246 246 246
54706-253 253 253 253 253 253 253 253 253 253 253 253
54707-253 253 253 253 253 253 253 253 253 253 253 253
54708-253 253 253 253 253 253 253 253 253 253 253 253
54709-253 253 253 253 253 253 253 253 253 253 253 253
54710-253 253 253 253 253 253 226 226 226 10 10 10
54711- 2 2 6 6 6 6 30 30 30 2 2 6
54712- 2 2 6 2 2 6 2 2 6 2 2 6
54713- 2 2 6 66 66 66 58 58 58 22 22 22
54714- 6 6 6 0 0 0 0 0 0 0 0 0
54715- 0 0 0 0 0 0 0 0 0 0 0 0
54716- 0 0 0 0 0 0 0 0 0 0 0 0
54717- 0 0 0 0 0 0 0 0 0 0 0 0
54718- 0 0 0 0 0 0 0 0 0 0 0 0
54719- 0 0 0 0 0 0 0 0 0 0 0 0
54720- 0 0 0 0 0 0 6 6 6 22 22 22
54721- 58 58 58 62 62 62 2 2 6 2 2 6
54722- 2 2 6 2 2 6 30 30 30 78 78 78
54723-250 250 250 253 253 253 253 253 253 253 253 253
54724-253 253 253 253 253 253 253 253 253 253 253 253
54725-253 253 253 253 253 253 231 231 231 246 246 246
54726-253 253 253 253 253 253 253 253 253 253 253 253
54727-253 253 253 253 253 253 253 253 253 253 253 253
54728-253 253 253 253 253 253 253 253 253 253 253 253
54729-253 253 253 253 253 253 253 253 253 253 253 253
54730-253 253 253 253 253 253 206 206 206 2 2 6
54731- 22 22 22 34 34 34 18 14 6 22 22 22
54732- 26 26 26 18 18 18 6 6 6 2 2 6
54733- 2 2 6 82 82 82 54 54 54 18 18 18
54734- 6 6 6 0 0 0 0 0 0 0 0 0
54735- 0 0 0 0 0 0 0 0 0 0 0 0
54736- 0 0 0 0 0 0 0 0 0 0 0 0
54737- 0 0 0 0 0 0 0 0 0 0 0 0
54738- 0 0 0 0 0 0 0 0 0 0 0 0
54739- 0 0 0 0 0 0 0 0 0 0 0 0
54740- 0 0 0 0 0 0 6 6 6 26 26 26
54741- 62 62 62 106 106 106 74 54 14 185 133 11
54742-210 162 10 121 92 8 6 6 6 62 62 62
54743-238 238 238 253 253 253 253 253 253 253 253 253
54744-253 253 253 253 253 253 253 253 253 253 253 253
54745-253 253 253 253 253 253 231 231 231 246 246 246
54746-253 253 253 253 253 253 253 253 253 253 253 253
54747-253 253 253 253 253 253 253 253 253 253 253 253
54748-253 253 253 253 253 253 253 253 253 253 253 253
54749-253 253 253 253 253 253 253 253 253 253 253 253
54750-253 253 253 253 253 253 158 158 158 18 18 18
54751- 14 14 14 2 2 6 2 2 6 2 2 6
54752- 6 6 6 18 18 18 66 66 66 38 38 38
54753- 6 6 6 94 94 94 50 50 50 18 18 18
54754- 6 6 6 0 0 0 0 0 0 0 0 0
54755- 0 0 0 0 0 0 0 0 0 0 0 0
54756- 0 0 0 0 0 0 0 0 0 0 0 0
54757- 0 0 0 0 0 0 0 0 0 0 0 0
54758- 0 0 0 0 0 0 0 0 0 0 0 0
54759- 0 0 0 0 0 0 0 0 0 6 6 6
54760- 10 10 10 10 10 10 18 18 18 38 38 38
54761- 78 78 78 142 134 106 216 158 10 242 186 14
54762-246 190 14 246 190 14 156 118 10 10 10 10
54763- 90 90 90 238 238 238 253 253 253 253 253 253
54764-253 253 253 253 253 253 253 253 253 253 253 253
54765-253 253 253 253 253 253 231 231 231 250 250 250
54766-253 253 253 253 253 253 253 253 253 253 253 253
54767-253 253 253 253 253 253 253 253 253 253 253 253
54768-253 253 253 253 253 253 253 253 253 253 253 253
54769-253 253 253 253 253 253 253 253 253 246 230 190
54770-238 204 91 238 204 91 181 142 44 37 26 9
54771- 2 2 6 2 2 6 2 2 6 2 2 6
54772- 2 2 6 2 2 6 38 38 38 46 46 46
54773- 26 26 26 106 106 106 54 54 54 18 18 18
54774- 6 6 6 0 0 0 0 0 0 0 0 0
54775- 0 0 0 0 0 0 0 0 0 0 0 0
54776- 0 0 0 0 0 0 0 0 0 0 0 0
54777- 0 0 0 0 0 0 0 0 0 0 0 0
54778- 0 0 0 0 0 0 0 0 0 0 0 0
54779- 0 0 0 6 6 6 14 14 14 22 22 22
54780- 30 30 30 38 38 38 50 50 50 70 70 70
54781-106 106 106 190 142 34 226 170 11 242 186 14
54782-246 190 14 246 190 14 246 190 14 154 114 10
54783- 6 6 6 74 74 74 226 226 226 253 253 253
54784-253 253 253 253 253 253 253 253 253 253 253 253
54785-253 253 253 253 253 253 231 231 231 250 250 250
54786-253 253 253 253 253 253 253 253 253 253 253 253
54787-253 253 253 253 253 253 253 253 253 253 253 253
54788-253 253 253 253 253 253 253 253 253 253 253 253
54789-253 253 253 253 253 253 253 253 253 228 184 62
54790-241 196 14 241 208 19 232 195 16 38 30 10
54791- 2 2 6 2 2 6 2 2 6 2 2 6
54792- 2 2 6 6 6 6 30 30 30 26 26 26
54793-203 166 17 154 142 90 66 66 66 26 26 26
54794- 6 6 6 0 0 0 0 0 0 0 0 0
54795- 0 0 0 0 0 0 0 0 0 0 0 0
54796- 0 0 0 0 0 0 0 0 0 0 0 0
54797- 0 0 0 0 0 0 0 0 0 0 0 0
54798- 0 0 0 0 0 0 0 0 0 0 0 0
54799- 6 6 6 18 18 18 38 38 38 58 58 58
54800- 78 78 78 86 86 86 101 101 101 123 123 123
54801-175 146 61 210 150 10 234 174 13 246 186 14
54802-246 190 14 246 190 14 246 190 14 238 190 10
54803-102 78 10 2 2 6 46 46 46 198 198 198
54804-253 253 253 253 253 253 253 253 253 253 253 253
54805-253 253 253 253 253 253 234 234 234 242 242 242
54806-253 253 253 253 253 253 253 253 253 253 253 253
54807-253 253 253 253 253 253 253 253 253 253 253 253
54808-253 253 253 253 253 253 253 253 253 253 253 253
54809-253 253 253 253 253 253 253 253 253 224 178 62
54810-242 186 14 241 196 14 210 166 10 22 18 6
54811- 2 2 6 2 2 6 2 2 6 2 2 6
54812- 2 2 6 2 2 6 6 6 6 121 92 8
54813-238 202 15 232 195 16 82 82 82 34 34 34
54814- 10 10 10 0 0 0 0 0 0 0 0 0
54815- 0 0 0 0 0 0 0 0 0 0 0 0
54816- 0 0 0 0 0 0 0 0 0 0 0 0
54817- 0 0 0 0 0 0 0 0 0 0 0 0
54818- 0 0 0 0 0 0 0 0 0 0 0 0
54819- 14 14 14 38 38 38 70 70 70 154 122 46
54820-190 142 34 200 144 11 197 138 11 197 138 11
54821-213 154 11 226 170 11 242 186 14 246 190 14
54822-246 190 14 246 190 14 246 190 14 246 190 14
54823-225 175 15 46 32 6 2 2 6 22 22 22
54824-158 158 158 250 250 250 253 253 253 253 253 253
54825-253 253 253 253 253 253 253 253 253 253 253 253
54826-253 253 253 253 253 253 253 253 253 253 253 253
54827-253 253 253 253 253 253 253 253 253 253 253 253
54828-253 253 253 253 253 253 253 253 253 253 253 253
54829-253 253 253 250 250 250 242 242 242 224 178 62
54830-239 182 13 236 186 11 213 154 11 46 32 6
54831- 2 2 6 2 2 6 2 2 6 2 2 6
54832- 2 2 6 2 2 6 61 42 6 225 175 15
54833-238 190 10 236 186 11 112 100 78 42 42 42
54834- 14 14 14 0 0 0 0 0 0 0 0 0
54835- 0 0 0 0 0 0 0 0 0 0 0 0
54836- 0 0 0 0 0 0 0 0 0 0 0 0
54837- 0 0 0 0 0 0 0 0 0 0 0 0
54838- 0 0 0 0 0 0 0 0 0 6 6 6
54839- 22 22 22 54 54 54 154 122 46 213 154 11
54840-226 170 11 230 174 11 226 170 11 226 170 11
54841-236 178 12 242 186 14 246 190 14 246 190 14
54842-246 190 14 246 190 14 246 190 14 246 190 14
54843-241 196 14 184 144 12 10 10 10 2 2 6
54844- 6 6 6 116 116 116 242 242 242 253 253 253
54845-253 253 253 253 253 253 253 253 253 253 253 253
54846-253 253 253 253 253 253 253 253 253 253 253 253
54847-253 253 253 253 253 253 253 253 253 253 253 253
54848-253 253 253 253 253 253 253 253 253 253 253 253
54849-253 253 253 231 231 231 198 198 198 214 170 54
54850-236 178 12 236 178 12 210 150 10 137 92 6
54851- 18 14 6 2 2 6 2 2 6 2 2 6
54852- 6 6 6 70 47 6 200 144 11 236 178 12
54853-239 182 13 239 182 13 124 112 88 58 58 58
54854- 22 22 22 6 6 6 0 0 0 0 0 0
54855- 0 0 0 0 0 0 0 0 0 0 0 0
54856- 0 0 0 0 0 0 0 0 0 0 0 0
54857- 0 0 0 0 0 0 0 0 0 0 0 0
54858- 0 0 0 0 0 0 0 0 0 10 10 10
54859- 30 30 30 70 70 70 180 133 36 226 170 11
54860-239 182 13 242 186 14 242 186 14 246 186 14
54861-246 190 14 246 190 14 246 190 14 246 190 14
54862-246 190 14 246 190 14 246 190 14 246 190 14
54863-246 190 14 232 195 16 98 70 6 2 2 6
54864- 2 2 6 2 2 6 66 66 66 221 221 221
54865-253 253 253 253 253 253 253 253 253 253 253 253
54866-253 253 253 253 253 253 253 253 253 253 253 253
54867-253 253 253 253 253 253 253 253 253 253 253 253
54868-253 253 253 253 253 253 253 253 253 253 253 253
54869-253 253 253 206 206 206 198 198 198 214 166 58
54870-230 174 11 230 174 11 216 158 10 192 133 9
54871-163 110 8 116 81 8 102 78 10 116 81 8
54872-167 114 7 197 138 11 226 170 11 239 182 13
54873-242 186 14 242 186 14 162 146 94 78 78 78
54874- 34 34 34 14 14 14 6 6 6 0 0 0
54875- 0 0 0 0 0 0 0 0 0 0 0 0
54876- 0 0 0 0 0 0 0 0 0 0 0 0
54877- 0 0 0 0 0 0 0 0 0 0 0 0
54878- 0 0 0 0 0 0 0 0 0 6 6 6
54879- 30 30 30 78 78 78 190 142 34 226 170 11
54880-239 182 13 246 190 14 246 190 14 246 190 14
54881-246 190 14 246 190 14 246 190 14 246 190 14
54882-246 190 14 246 190 14 246 190 14 246 190 14
54883-246 190 14 241 196 14 203 166 17 22 18 6
54884- 2 2 6 2 2 6 2 2 6 38 38 38
54885-218 218 218 253 253 253 253 253 253 253 253 253
54886-253 253 253 253 253 253 253 253 253 253 253 253
54887-253 253 253 253 253 253 253 253 253 253 253 253
54888-253 253 253 253 253 253 253 253 253 253 253 253
54889-250 250 250 206 206 206 198 198 198 202 162 69
54890-226 170 11 236 178 12 224 166 10 210 150 10
54891-200 144 11 197 138 11 192 133 9 197 138 11
54892-210 150 10 226 170 11 242 186 14 246 190 14
54893-246 190 14 246 186 14 225 175 15 124 112 88
54894- 62 62 62 30 30 30 14 14 14 6 6 6
54895- 0 0 0 0 0 0 0 0 0 0 0 0
54896- 0 0 0 0 0 0 0 0 0 0 0 0
54897- 0 0 0 0 0 0 0 0 0 0 0 0
54898- 0 0 0 0 0 0 0 0 0 10 10 10
54899- 30 30 30 78 78 78 174 135 50 224 166 10
54900-239 182 13 246 190 14 246 190 14 246 190 14
54901-246 190 14 246 190 14 246 190 14 246 190 14
54902-246 190 14 246 190 14 246 190 14 246 190 14
54903-246 190 14 246 190 14 241 196 14 139 102 15
54904- 2 2 6 2 2 6 2 2 6 2 2 6
54905- 78 78 78 250 250 250 253 253 253 253 253 253
54906-253 253 253 253 253 253 253 253 253 253 253 253
54907-253 253 253 253 253 253 253 253 253 253 253 253
54908-253 253 253 253 253 253 253 253 253 253 253 253
54909-250 250 250 214 214 214 198 198 198 190 150 46
54910-219 162 10 236 178 12 234 174 13 224 166 10
54911-216 158 10 213 154 11 213 154 11 216 158 10
54912-226 170 11 239 182 13 246 190 14 246 190 14
54913-246 190 14 246 190 14 242 186 14 206 162 42
54914-101 101 101 58 58 58 30 30 30 14 14 14
54915- 6 6 6 0 0 0 0 0 0 0 0 0
54916- 0 0 0 0 0 0 0 0 0 0 0 0
54917- 0 0 0 0 0 0 0 0 0 0 0 0
54918- 0 0 0 0 0 0 0 0 0 10 10 10
54919- 30 30 30 74 74 74 174 135 50 216 158 10
54920-236 178 12 246 190 14 246 190 14 246 190 14
54921-246 190 14 246 190 14 246 190 14 246 190 14
54922-246 190 14 246 190 14 246 190 14 246 190 14
54923-246 190 14 246 190 14 241 196 14 226 184 13
54924- 61 42 6 2 2 6 2 2 6 2 2 6
54925- 22 22 22 238 238 238 253 253 253 253 253 253
54926-253 253 253 253 253 253 253 253 253 253 253 253
54927-253 253 253 253 253 253 253 253 253 253 253 253
54928-253 253 253 253 253 253 253 253 253 253 253 253
54929-253 253 253 226 226 226 187 187 187 180 133 36
54930-216 158 10 236 178 12 239 182 13 236 178 12
54931-230 174 11 226 170 11 226 170 11 230 174 11
54932-236 178 12 242 186 14 246 190 14 246 190 14
54933-246 190 14 246 190 14 246 186 14 239 182 13
54934-206 162 42 106 106 106 66 66 66 34 34 34
54935- 14 14 14 6 6 6 0 0 0 0 0 0
54936- 0 0 0 0 0 0 0 0 0 0 0 0
54937- 0 0 0 0 0 0 0 0 0 0 0 0
54938- 0 0 0 0 0 0 0 0 0 6 6 6
54939- 26 26 26 70 70 70 163 133 67 213 154 11
54940-236 178 12 246 190 14 246 190 14 246 190 14
54941-246 190 14 246 190 14 246 190 14 246 190 14
54942-246 190 14 246 190 14 246 190 14 246 190 14
54943-246 190 14 246 190 14 246 190 14 241 196 14
54944-190 146 13 18 14 6 2 2 6 2 2 6
54945- 46 46 46 246 246 246 253 253 253 253 253 253
54946-253 253 253 253 253 253 253 253 253 253 253 253
54947-253 253 253 253 253 253 253 253 253 253 253 253
54948-253 253 253 253 253 253 253 253 253 253 253 253
54949-253 253 253 221 221 221 86 86 86 156 107 11
54950-216 158 10 236 178 12 242 186 14 246 186 14
54951-242 186 14 239 182 13 239 182 13 242 186 14
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-242 186 14 225 175 15 142 122 72 66 66 66
54955- 30 30 30 10 10 10 0 0 0 0 0 0
54956- 0 0 0 0 0 0 0 0 0 0 0 0
54957- 0 0 0 0 0 0 0 0 0 0 0 0
54958- 0 0 0 0 0 0 0 0 0 6 6 6
54959- 26 26 26 70 70 70 163 133 67 210 150 10
54960-236 178 12 246 190 14 246 190 14 246 190 14
54961-246 190 14 246 190 14 246 190 14 246 190 14
54962-246 190 14 246 190 14 246 190 14 246 190 14
54963-246 190 14 246 190 14 246 190 14 246 190 14
54964-232 195 16 121 92 8 34 34 34 106 106 106
54965-221 221 221 253 253 253 253 253 253 253 253 253
54966-253 253 253 253 253 253 253 253 253 253 253 253
54967-253 253 253 253 253 253 253 253 253 253 253 253
54968-253 253 253 253 253 253 253 253 253 253 253 253
54969-242 242 242 82 82 82 18 14 6 163 110 8
54970-216 158 10 236 178 12 242 186 14 246 190 14
54971-246 190 14 246 190 14 246 190 14 246 190 14
54972-246 190 14 246 190 14 246 190 14 246 190 14
54973-246 190 14 246 190 14 246 190 14 246 190 14
54974-246 190 14 246 190 14 242 186 14 163 133 67
54975- 46 46 46 18 18 18 6 6 6 0 0 0
54976- 0 0 0 0 0 0 0 0 0 0 0 0
54977- 0 0 0 0 0 0 0 0 0 0 0 0
54978- 0 0 0 0 0 0 0 0 0 10 10 10
54979- 30 30 30 78 78 78 163 133 67 210 150 10
54980-236 178 12 246 186 14 246 190 14 246 190 14
54981-246 190 14 246 190 14 246 190 14 246 190 14
54982-246 190 14 246 190 14 246 190 14 246 190 14
54983-246 190 14 246 190 14 246 190 14 246 190 14
54984-241 196 14 215 174 15 190 178 144 253 253 253
54985-253 253 253 253 253 253 253 253 253 253 253 253
54986-253 253 253 253 253 253 253 253 253 253 253 253
54987-253 253 253 253 253 253 253 253 253 253 253 253
54988-253 253 253 253 253 253 253 253 253 218 218 218
54989- 58 58 58 2 2 6 22 18 6 167 114 7
54990-216 158 10 236 178 12 246 186 14 246 190 14
54991-246 190 14 246 190 14 246 190 14 246 190 14
54992-246 190 14 246 190 14 246 190 14 246 190 14
54993-246 190 14 246 190 14 246 190 14 246 190 14
54994-246 190 14 246 186 14 242 186 14 190 150 46
54995- 54 54 54 22 22 22 6 6 6 0 0 0
54996- 0 0 0 0 0 0 0 0 0 0 0 0
54997- 0 0 0 0 0 0 0 0 0 0 0 0
54998- 0 0 0 0 0 0 0 0 0 14 14 14
54999- 38 38 38 86 86 86 180 133 36 213 154 11
55000-236 178 12 246 186 14 246 190 14 246 190 14
55001-246 190 14 246 190 14 246 190 14 246 190 14
55002-246 190 14 246 190 14 246 190 14 246 190 14
55003-246 190 14 246 190 14 246 190 14 246 190 14
55004-246 190 14 232 195 16 190 146 13 214 214 214
55005-253 253 253 253 253 253 253 253 253 253 253 253
55006-253 253 253 253 253 253 253 253 253 253 253 253
55007-253 253 253 253 253 253 253 253 253 253 253 253
55008-253 253 253 250 250 250 170 170 170 26 26 26
55009- 2 2 6 2 2 6 37 26 9 163 110 8
55010-219 162 10 239 182 13 246 186 14 246 190 14
55011-246 190 14 246 190 14 246 190 14 246 190 14
55012-246 190 14 246 190 14 246 190 14 246 190 14
55013-246 190 14 246 190 14 246 190 14 246 190 14
55014-246 186 14 236 178 12 224 166 10 142 122 72
55015- 46 46 46 18 18 18 6 6 6 0 0 0
55016- 0 0 0 0 0 0 0 0 0 0 0 0
55017- 0 0 0 0 0 0 0 0 0 0 0 0
55018- 0 0 0 0 0 0 6 6 6 18 18 18
55019- 50 50 50 109 106 95 192 133 9 224 166 10
55020-242 186 14 246 190 14 246 190 14 246 190 14
55021-246 190 14 246 190 14 246 190 14 246 190 14
55022-246 190 14 246 190 14 246 190 14 246 190 14
55023-246 190 14 246 190 14 246 190 14 246 190 14
55024-242 186 14 226 184 13 210 162 10 142 110 46
55025-226 226 226 253 253 253 253 253 253 253 253 253
55026-253 253 253 253 253 253 253 253 253 253 253 253
55027-253 253 253 253 253 253 253 253 253 253 253 253
55028-198 198 198 66 66 66 2 2 6 2 2 6
55029- 2 2 6 2 2 6 50 34 6 156 107 11
55030-219 162 10 239 182 13 246 186 14 246 190 14
55031-246 190 14 246 190 14 246 190 14 246 190 14
55032-246 190 14 246 190 14 246 190 14 246 190 14
55033-246 190 14 246 190 14 246 190 14 242 186 14
55034-234 174 13 213 154 11 154 122 46 66 66 66
55035- 30 30 30 10 10 10 0 0 0 0 0 0
55036- 0 0 0 0 0 0 0 0 0 0 0 0
55037- 0 0 0 0 0 0 0 0 0 0 0 0
55038- 0 0 0 0 0 0 6 6 6 22 22 22
55039- 58 58 58 154 121 60 206 145 10 234 174 13
55040-242 186 14 246 186 14 246 190 14 246 190 14
55041-246 190 14 246 190 14 246 190 14 246 190 14
55042-246 190 14 246 190 14 246 190 14 246 190 14
55043-246 190 14 246 190 14 246 190 14 246 190 14
55044-246 186 14 236 178 12 210 162 10 163 110 8
55045- 61 42 6 138 138 138 218 218 218 250 250 250
55046-253 253 253 253 253 253 253 253 253 250 250 250
55047-242 242 242 210 210 210 144 144 144 66 66 66
55048- 6 6 6 2 2 6 2 2 6 2 2 6
55049- 2 2 6 2 2 6 61 42 6 163 110 8
55050-216 158 10 236 178 12 246 190 14 246 190 14
55051-246 190 14 246 190 14 246 190 14 246 190 14
55052-246 190 14 246 190 14 246 190 14 246 190 14
55053-246 190 14 239 182 13 230 174 11 216 158 10
55054-190 142 34 124 112 88 70 70 70 38 38 38
55055- 18 18 18 6 6 6 0 0 0 0 0 0
55056- 0 0 0 0 0 0 0 0 0 0 0 0
55057- 0 0 0 0 0 0 0 0 0 0 0 0
55058- 0 0 0 0 0 0 6 6 6 22 22 22
55059- 62 62 62 168 124 44 206 145 10 224 166 10
55060-236 178 12 239 182 13 242 186 14 242 186 14
55061-246 186 14 246 190 14 246 190 14 246 190 14
55062-246 190 14 246 190 14 246 190 14 246 190 14
55063-246 190 14 246 190 14 246 190 14 246 190 14
55064-246 190 14 236 178 12 216 158 10 175 118 6
55065- 80 54 7 2 2 6 6 6 6 30 30 30
55066- 54 54 54 62 62 62 50 50 50 38 38 38
55067- 14 14 14 2 2 6 2 2 6 2 2 6
55068- 2 2 6 2 2 6 2 2 6 2 2 6
55069- 2 2 6 6 6 6 80 54 7 167 114 7
55070-213 154 11 236 178 12 246 190 14 246 190 14
55071-246 190 14 246 190 14 246 190 14 246 190 14
55072-246 190 14 242 186 14 239 182 13 239 182 13
55073-230 174 11 210 150 10 174 135 50 124 112 88
55074- 82 82 82 54 54 54 34 34 34 18 18 18
55075- 6 6 6 0 0 0 0 0 0 0 0 0
55076- 0 0 0 0 0 0 0 0 0 0 0 0
55077- 0 0 0 0 0 0 0 0 0 0 0 0
55078- 0 0 0 0 0 0 6 6 6 18 18 18
55079- 50 50 50 158 118 36 192 133 9 200 144 11
55080-216 158 10 219 162 10 224 166 10 226 170 11
55081-230 174 11 236 178 12 239 182 13 239 182 13
55082-242 186 14 246 186 14 246 190 14 246 190 14
55083-246 190 14 246 190 14 246 190 14 246 190 14
55084-246 186 14 230 174 11 210 150 10 163 110 8
55085-104 69 6 10 10 10 2 2 6 2 2 6
55086- 2 2 6 2 2 6 2 2 6 2 2 6
55087- 2 2 6 2 2 6 2 2 6 2 2 6
55088- 2 2 6 2 2 6 2 2 6 2 2 6
55089- 2 2 6 6 6 6 91 60 6 167 114 7
55090-206 145 10 230 174 11 242 186 14 246 190 14
55091-246 190 14 246 190 14 246 186 14 242 186 14
55092-239 182 13 230 174 11 224 166 10 213 154 11
55093-180 133 36 124 112 88 86 86 86 58 58 58
55094- 38 38 38 22 22 22 10 10 10 6 6 6
55095- 0 0 0 0 0 0 0 0 0 0 0 0
55096- 0 0 0 0 0 0 0 0 0 0 0 0
55097- 0 0 0 0 0 0 0 0 0 0 0 0
55098- 0 0 0 0 0 0 0 0 0 14 14 14
55099- 34 34 34 70 70 70 138 110 50 158 118 36
55100-167 114 7 180 123 7 192 133 9 197 138 11
55101-200 144 11 206 145 10 213 154 11 219 162 10
55102-224 166 10 230 174 11 239 182 13 242 186 14
55103-246 186 14 246 186 14 246 186 14 246 186 14
55104-239 182 13 216 158 10 185 133 11 152 99 6
55105-104 69 6 18 14 6 2 2 6 2 2 6
55106- 2 2 6 2 2 6 2 2 6 2 2 6
55107- 2 2 6 2 2 6 2 2 6 2 2 6
55108- 2 2 6 2 2 6 2 2 6 2 2 6
55109- 2 2 6 6 6 6 80 54 7 152 99 6
55110-192 133 9 219 162 10 236 178 12 239 182 13
55111-246 186 14 242 186 14 239 182 13 236 178 12
55112-224 166 10 206 145 10 192 133 9 154 121 60
55113- 94 94 94 62 62 62 42 42 42 22 22 22
55114- 14 14 14 6 6 6 0 0 0 0 0 0
55115- 0 0 0 0 0 0 0 0 0 0 0 0
55116- 0 0 0 0 0 0 0 0 0 0 0 0
55117- 0 0 0 0 0 0 0 0 0 0 0 0
55118- 0 0 0 0 0 0 0 0 0 6 6 6
55119- 18 18 18 34 34 34 58 58 58 78 78 78
55120-101 98 89 124 112 88 142 110 46 156 107 11
55121-163 110 8 167 114 7 175 118 6 180 123 7
55122-185 133 11 197 138 11 210 150 10 219 162 10
55123-226 170 11 236 178 12 236 178 12 234 174 13
55124-219 162 10 197 138 11 163 110 8 130 83 6
55125- 91 60 6 10 10 10 2 2 6 2 2 6
55126- 18 18 18 38 38 38 38 38 38 38 38 38
55127- 38 38 38 38 38 38 38 38 38 38 38 38
55128- 38 38 38 38 38 38 26 26 26 2 2 6
55129- 2 2 6 6 6 6 70 47 6 137 92 6
55130-175 118 6 200 144 11 219 162 10 230 174 11
55131-234 174 13 230 174 11 219 162 10 210 150 10
55132-192 133 9 163 110 8 124 112 88 82 82 82
55133- 50 50 50 30 30 30 14 14 14 6 6 6
55134- 0 0 0 0 0 0 0 0 0 0 0 0
55135- 0 0 0 0 0 0 0 0 0 0 0 0
55136- 0 0 0 0 0 0 0 0 0 0 0 0
55137- 0 0 0 0 0 0 0 0 0 0 0 0
55138- 0 0 0 0 0 0 0 0 0 0 0 0
55139- 6 6 6 14 14 14 22 22 22 34 34 34
55140- 42 42 42 58 58 58 74 74 74 86 86 86
55141-101 98 89 122 102 70 130 98 46 121 87 25
55142-137 92 6 152 99 6 163 110 8 180 123 7
55143-185 133 11 197 138 11 206 145 10 200 144 11
55144-180 123 7 156 107 11 130 83 6 104 69 6
55145- 50 34 6 54 54 54 110 110 110 101 98 89
55146- 86 86 86 82 82 82 78 78 78 78 78 78
55147- 78 78 78 78 78 78 78 78 78 78 78 78
55148- 78 78 78 82 82 82 86 86 86 94 94 94
55149-106 106 106 101 101 101 86 66 34 124 80 6
55150-156 107 11 180 123 7 192 133 9 200 144 11
55151-206 145 10 200 144 11 192 133 9 175 118 6
55152-139 102 15 109 106 95 70 70 70 42 42 42
55153- 22 22 22 10 10 10 0 0 0 0 0 0
55154- 0 0 0 0 0 0 0 0 0 0 0 0
55155- 0 0 0 0 0 0 0 0 0 0 0 0
55156- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10
55160- 14 14 14 22 22 22 30 30 30 38 38 38
55161- 50 50 50 62 62 62 74 74 74 90 90 90
55162-101 98 89 112 100 78 121 87 25 124 80 6
55163-137 92 6 152 99 6 152 99 6 152 99 6
55164-138 86 6 124 80 6 98 70 6 86 66 30
55165-101 98 89 82 82 82 58 58 58 46 46 46
55166- 38 38 38 34 34 34 34 34 34 34 34 34
55167- 34 34 34 34 34 34 34 34 34 34 34 34
55168- 34 34 34 34 34 34 38 38 38 42 42 42
55169- 54 54 54 82 82 82 94 86 76 91 60 6
55170-134 86 6 156 107 11 167 114 7 175 118 6
55171-175 118 6 167 114 7 152 99 6 121 87 25
55172-101 98 89 62 62 62 34 34 34 18 18 18
55173- 6 6 6 0 0 0 0 0 0 0 0 0
55174- 0 0 0 0 0 0 0 0 0 0 0 0
55175- 0 0 0 0 0 0 0 0 0 0 0 0
55176- 0 0 0 0 0 0 0 0 0 0 0 0
55177- 0 0 0 0 0 0 0 0 0 0 0 0
55178- 0 0 0 0 0 0 0 0 0 0 0 0
55179- 0 0 0 0 0 0 0 0 0 0 0 0
55180- 0 0 0 6 6 6 6 6 6 10 10 10
55181- 18 18 18 22 22 22 30 30 30 42 42 42
55182- 50 50 50 66 66 66 86 86 86 101 98 89
55183-106 86 58 98 70 6 104 69 6 104 69 6
55184-104 69 6 91 60 6 82 62 34 90 90 90
55185- 62 62 62 38 38 38 22 22 22 14 14 14
55186- 10 10 10 10 10 10 10 10 10 10 10 10
55187- 10 10 10 10 10 10 6 6 6 10 10 10
55188- 10 10 10 10 10 10 10 10 10 14 14 14
55189- 22 22 22 42 42 42 70 70 70 89 81 66
55190- 80 54 7 104 69 6 124 80 6 137 92 6
55191-134 86 6 116 81 8 100 82 52 86 86 86
55192- 58 58 58 30 30 30 14 14 14 6 6 6
55193- 0 0 0 0 0 0 0 0 0 0 0 0
55194- 0 0 0 0 0 0 0 0 0 0 0 0
55195- 0 0 0 0 0 0 0 0 0 0 0 0
55196- 0 0 0 0 0 0 0 0 0 0 0 0
55197- 0 0 0 0 0 0 0 0 0 0 0 0
55198- 0 0 0 0 0 0 0 0 0 0 0 0
55199- 0 0 0 0 0 0 0 0 0 0 0 0
55200- 0 0 0 0 0 0 0 0 0 0 0 0
55201- 0 0 0 6 6 6 10 10 10 14 14 14
55202- 18 18 18 26 26 26 38 38 38 54 54 54
55203- 70 70 70 86 86 86 94 86 76 89 81 66
55204- 89 81 66 86 86 86 74 74 74 50 50 50
55205- 30 30 30 14 14 14 6 6 6 0 0 0
55206- 0 0 0 0 0 0 0 0 0 0 0 0
55207- 0 0 0 0 0 0 0 0 0 0 0 0
55208- 0 0 0 0 0 0 0 0 0 0 0 0
55209- 6 6 6 18 18 18 34 34 34 58 58 58
55210- 82 82 82 89 81 66 89 81 66 89 81 66
55211- 94 86 66 94 86 76 74 74 74 50 50 50
55212- 26 26 26 14 14 14 6 6 6 0 0 0
55213- 0 0 0 0 0 0 0 0 0 0 0 0
55214- 0 0 0 0 0 0 0 0 0 0 0 0
55215- 0 0 0 0 0 0 0 0 0 0 0 0
55216- 0 0 0 0 0 0 0 0 0 0 0 0
55217- 0 0 0 0 0 0 0 0 0 0 0 0
55218- 0 0 0 0 0 0 0 0 0 0 0 0
55219- 0 0 0 0 0 0 0 0 0 0 0 0
55220- 0 0 0 0 0 0 0 0 0 0 0 0
55221- 0 0 0 0 0 0 0 0 0 0 0 0
55222- 6 6 6 6 6 6 14 14 14 18 18 18
55223- 30 30 30 38 38 38 46 46 46 54 54 54
55224- 50 50 50 42 42 42 30 30 30 18 18 18
55225- 10 10 10 0 0 0 0 0 0 0 0 0
55226- 0 0 0 0 0 0 0 0 0 0 0 0
55227- 0 0 0 0 0 0 0 0 0 0 0 0
55228- 0 0 0 0 0 0 0 0 0 0 0 0
55229- 0 0 0 6 6 6 14 14 14 26 26 26
55230- 38 38 38 50 50 50 58 58 58 58 58 58
55231- 54 54 54 42 42 42 30 30 30 18 18 18
55232- 10 10 10 0 0 0 0 0 0 0 0 0
55233- 0 0 0 0 0 0 0 0 0 0 0 0
55234- 0 0 0 0 0 0 0 0 0 0 0 0
55235- 0 0 0 0 0 0 0 0 0 0 0 0
55236- 0 0 0 0 0 0 0 0 0 0 0 0
55237- 0 0 0 0 0 0 0 0 0 0 0 0
55238- 0 0 0 0 0 0 0 0 0 0 0 0
55239- 0 0 0 0 0 0 0 0 0 0 0 0
55240- 0 0 0 0 0 0 0 0 0 0 0 0
55241- 0 0 0 0 0 0 0 0 0 0 0 0
55242- 0 0 0 0 0 0 0 0 0 6 6 6
55243- 6 6 6 10 10 10 14 14 14 18 18 18
55244- 18 18 18 14 14 14 10 10 10 6 6 6
55245- 0 0 0 0 0 0 0 0 0 0 0 0
55246- 0 0 0 0 0 0 0 0 0 0 0 0
55247- 0 0 0 0 0 0 0 0 0 0 0 0
55248- 0 0 0 0 0 0 0 0 0 0 0 0
55249- 0 0 0 0 0 0 0 0 0 6 6 6
55250- 14 14 14 18 18 18 22 22 22 22 22 22
55251- 18 18 18 14 14 14 10 10 10 6 6 6
55252- 0 0 0 0 0 0 0 0 0 0 0 0
55253- 0 0 0 0 0 0 0 0 0 0 0 0
55254- 0 0 0 0 0 0 0 0 0 0 0 0
55255- 0 0 0 0 0 0 0 0 0 0 0 0
55256- 0 0 0 0 0 0 0 0 0 0 0 0
55257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55260+4 4 4 4 4 4 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 4 4 4 4 4 4
55263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55266+4 4 4 4 4 4 4 4 4 4 4 4 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
55271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55274+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55280+4 4 4 4 4 4 4 4 4 4 4 4 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
55285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55288+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55294+4 4 4 4 4 4 4 4 4 4 4 4 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
55299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55302+4 4 4 4 4 4 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 4 4 4 4 4 4
55304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55308+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
55313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55322+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
55326+4 4 4 4 4 4
55327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55336+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
55340+4 4 4 4 4 4
55341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55345+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
55346+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
55347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55350+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
55351+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55352+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
55353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55354+4 4 4 4 4 4
55355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55359+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
55360+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
55361+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55364+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
55365+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
55366+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
55367+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55368+4 4 4 4 4 4
55369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55373+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
55374+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
55375+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55378+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
55379+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
55380+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
55381+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
55382+4 4 4 4 4 4
55383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55386+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
55387+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
55388+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
55389+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
55390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55391+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55392+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
55393+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
55394+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
55395+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
55396+4 4 4 4 4 4
55397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55400+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
55401+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
55402+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
55403+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
55404+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55405+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
55406+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
55407+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
55408+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
55409+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
55410+4 4 4 4 4 4
55411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55414+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
55415+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
55416+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
55417+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
55418+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55419+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
55420+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
55421+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
55422+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
55423+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
55424+4 4 4 4 4 4
55425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55427+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
55428+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
55429+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
55430+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
55431+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
55432+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
55433+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
55434+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
55435+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
55436+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
55437+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
55438+4 4 4 4 4 4
55439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55441+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
55442+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
55443+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
55444+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
55445+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
55446+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
55447+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
55448+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
55449+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
55450+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
55451+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
55452+4 4 4 4 4 4
55453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55455+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
55456+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
55457+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
55458+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
55459+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
55460+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
55461+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
55462+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
55463+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
55464+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
55465+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55466+4 4 4 4 4 4
55467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55469+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
55470+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
55471+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
55472+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
55473+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
55474+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
55475+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
55476+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
55477+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
55478+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
55479+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
55480+4 4 4 4 4 4
55481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55482+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
55483+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
55484+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
55485+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
55486+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
55487+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
55488+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
55489+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
55490+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
55491+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
55492+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
55493+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
55494+4 4 4 4 4 4
55495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55496+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
55497+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
55498+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
55499+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55500+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
55501+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
55502+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
55503+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
55504+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
55505+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
55506+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
55507+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
55508+0 0 0 4 4 4
55509+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55510+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
55511+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
55512+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
55513+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
55514+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
55515+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
55516+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
55517+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
55518+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
55519+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
55520+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
55521+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
55522+2 0 0 0 0 0
55523+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
55524+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
55525+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
55526+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
55527+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
55528+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
55529+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
55530+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
55531+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
55532+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
55533+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
55534+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
55535+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
55536+37 38 37 0 0 0
55537+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55538+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
55539+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
55540+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
55541+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
55542+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
55543+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55544+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55545+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55546+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55547+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55548+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55549+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55550+85 115 134 4 0 0
55551+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55552+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55553+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55554+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55555+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55556+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55557+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55558+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55559+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55560+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55561+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55562+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55563+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55564+60 73 81 4 0 0
55565+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55566+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55567+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55568+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55569+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55570+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55571+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55572+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55573+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55574+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55575+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55576+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55577+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55578+16 19 21 4 0 0
55579+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55580+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55581+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55582+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55583+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55584+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55585+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55586+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55587+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55588+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55589+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55590+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55591+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55592+4 0 0 4 3 3
55593+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55594+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55595+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55597+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55598+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55599+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55600+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55601+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55602+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55603+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55604+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55605+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55606+3 2 2 4 4 4
55607+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55608+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55609+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55610+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55611+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55612+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55613+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55614+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55615+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55616+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55617+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55618+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55619+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55620+4 4 4 4 4 4
55621+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55622+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55623+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55624+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55625+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55626+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55627+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55628+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55629+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55630+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55631+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55632+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55633+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55634+4 4 4 4 4 4
55635+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55636+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55637+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55638+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55639+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55640+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55641+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55642+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55643+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55644+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55645+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55646+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55647+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55648+5 5 5 5 5 5
55649+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55650+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55651+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55652+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55653+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55654+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55655+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55656+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55657+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55658+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55659+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55660+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55661+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55662+5 5 5 4 4 4
55663+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55664+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55665+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55666+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55667+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55668+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55669+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55670+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55671+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55672+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55673+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55674+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55676+4 4 4 4 4 4
55677+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55678+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55679+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55680+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55681+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55682+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55683+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55684+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55685+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55686+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55687+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55688+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55690+4 4 4 4 4 4
55691+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55692+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55693+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55694+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55695+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55696+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55697+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55698+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55699+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55700+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55701+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55704+4 4 4 4 4 4
55705+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55706+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55707+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55708+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55709+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55710+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55711+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55712+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55713+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55714+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55715+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55718+4 4 4 4 4 4
55719+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55720+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55721+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55722+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55723+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55724+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55725+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55726+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55727+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55728+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55729+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55732+4 4 4 4 4 4
55733+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55734+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55735+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55736+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55737+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55738+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55739+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55740+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55741+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55742+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55743+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55746+4 4 4 4 4 4
55747+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55748+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55749+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55750+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55751+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55752+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55753+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55754+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55755+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55756+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55757+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55760+4 4 4 4 4 4
55761+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55762+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55763+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55764+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55765+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55766+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55767+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55768+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55769+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55770+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55771+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55774+4 4 4 4 4 4
55775+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55776+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55777+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55778+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55779+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55780+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55781+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55782+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55783+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55784+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55785+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55788+4 4 4 4 4 4
55789+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55790+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55791+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55792+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55793+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55794+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55795+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55796+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55797+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55798+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55799+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55802+4 4 4 4 4 4
55803+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55804+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55805+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55806+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55807+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55808+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55809+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55810+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55811+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55812+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55813+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55816+4 4 4 4 4 4
55817+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55818+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55819+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55820+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55821+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55822+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55823+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55824+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55825+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55826+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55827+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55830+4 4 4 4 4 4
55831+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55832+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55833+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55834+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55835+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55836+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55837+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55838+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55839+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55840+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55841+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55844+4 4 4 4 4 4
55845+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55846+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55847+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55848+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55849+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55850+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55851+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55852+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55853+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55854+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55855+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55858+4 4 4 4 4 4
55859+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55860+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55861+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55862+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55863+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55864+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55865+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55866+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55867+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55868+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55869+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55872+4 4 4 4 4 4
55873+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55874+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55875+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55876+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55877+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55878+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55879+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55880+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55881+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55882+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55883+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55886+4 4 4 4 4 4
55887+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55888+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55889+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55890+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55891+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55892+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55893+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55894+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55895+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55896+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55897+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55900+4 4 4 4 4 4
55901+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55902+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55903+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55904+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55905+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55906+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55907+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55908+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55909+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55910+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55911+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55914+4 4 4 4 4 4
55915+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55916+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55917+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55918+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55919+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55920+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55921+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55922+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55923+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55924+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55925+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55928+4 4 4 4 4 4
55929+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55930+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55931+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55932+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55933+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55934+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55935+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55936+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55937+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55938+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55939+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55942+4 4 4 4 4 4
55943+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55944+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55945+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55946+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55947+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55948+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55949+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55950+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55951+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55952+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55953+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55956+4 4 4 4 4 4
55957+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55958+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55959+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55960+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55961+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55962+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55963+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55964+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55965+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55966+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55967+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55970+4 4 4 4 4 4
55971+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55972+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55973+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55974+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55975+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55976+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55977+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55978+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55979+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55980+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55981+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55984+4 4 4 4 4 4
55985+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55986+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55987+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55988+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55989+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55990+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55991+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55992+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55993+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55994+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55995+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55998+4 4 4 4 4 4
55999+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
56000+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
56001+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
56002+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
56003+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
56004+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
56005+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
56006+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
56007+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
56008+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
56009+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
56010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56012+4 4 4 4 4 4
56013+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
56014+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
56015+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
56016+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
56017+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
56018+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
56019+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
56020+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
56021+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
56022+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
56023+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
56024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56026+4 4 4 4 4 4
56027+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
56028+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
56029+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
56030+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
56031+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
56032+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
56033+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
56034+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
56035+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
56036+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
56037+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56040+4 4 4 4 4 4
56041+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
56042+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
56043+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
56044+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
56045+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
56046+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
56047+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56048+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
56049+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
56050+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
56051+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
56052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56054+4 4 4 4 4 4
56055+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
56056+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
56057+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
56058+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
56059+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
56060+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
56061+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
56062+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
56063+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
56064+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
56065+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56068+4 4 4 4 4 4
56069+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
56070+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
56071+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
56072+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
56073+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
56074+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
56075+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
56076+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
56077+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
56078+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
56079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56082+4 4 4 4 4 4
56083+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56084+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
56085+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
56086+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
56087+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
56088+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
56089+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
56090+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
56091+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
56092+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
56093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56096+4 4 4 4 4 4
56097+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
56098+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
56099+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
56100+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
56101+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
56102+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
56103+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
56104+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
56105+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
56106+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
56107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56110+4 4 4 4 4 4
56111+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
56112+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
56113+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
56114+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
56115+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
56116+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
56117+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
56118+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
56119+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
56120+4 3 3 5 5 5 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56124+4 4 4 4 4 4
56125+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
56126+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56127+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
56128+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
56129+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
56130+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
56131+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
56132+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
56133+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
56134+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
56137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56138+4 4 4 4 4 4
56139+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
56140+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
56141+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
56142+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
56143+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
56144+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
56145+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
56146+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
56147+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
56148+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56152+4 4 4 4 4 4
56153+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
56154+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
56155+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
56156+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
56157+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
56158+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
56159+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
56160+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
56161+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56162+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
56166+4 4 4 4 4 4
56167+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
56168+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
56169+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56170+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
56171+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
56172+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
56173+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
56174+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 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 4 4 4
56181+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56182+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
56183+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
56184+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
56185+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
56186+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
56187+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
56188+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 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
56195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56196+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
56197+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56198+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
56199+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
56200+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
56201+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
56202+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 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
56209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56210+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
56211+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
56212+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
56213+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
56214+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
56215+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
56216+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
56223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56224+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
56225+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
56226+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56227+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
56228+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
56229+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
56230+5 5 5 5 5 5 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 4 4 4 4 4 4 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
56237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56239+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56240+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
56241+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
56242+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
56243+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
56244+4 3 3 5 5 5 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 4 4 4 4 4 4 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
56251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56254+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56255+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
56256+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
56257+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 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
56265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56268+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56269+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56270+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
56271+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 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
56279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56280+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
56283+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56284+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56285+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
56289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56292+4 4 4 4 4 4
56293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56296+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
56297+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
56298+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
56299+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
56300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56306+4 4 4 4 4 4
56307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56311+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
56312+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56313+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
56314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56320+4 4 4 4 4 4
56321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56325+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
56326+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
56327+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
56328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56334+4 4 4 4 4 4
56335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56339+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
56340+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
56341+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56348+4 4 4 4 4 4
56349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56353+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
56354+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
56355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56362+4 4 4 4 4 4
56363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56367+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56368+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
56369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56376+4 4 4 4 4 4
56377diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56378index fef20db..d28b1ab 100644
56379--- a/drivers/xen/xenfs/xenstored.c
56380+++ b/drivers/xen/xenfs/xenstored.c
56381@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56382 static int xsd_kva_open(struct inode *inode, struct file *file)
56383 {
56384 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56385+#ifdef CONFIG_GRKERNSEC_HIDESYM
56386+ NULL);
56387+#else
56388 xen_store_interface);
56389+#endif
56390+
56391 if (!file->private_data)
56392 return -ENOMEM;
56393 return 0;
56394diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56395index c71e886..61d3d44b 100644
56396--- a/fs/9p/vfs_addr.c
56397+++ b/fs/9p/vfs_addr.c
56398@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56399
56400 retval = v9fs_file_write_internal(inode,
56401 v9inode->writeback_fid,
56402- (__force const char __user *)buffer,
56403+ (const char __force_user *)buffer,
56404 len, &offset, 0);
56405 if (retval > 0)
56406 retval = 0;
56407diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56408index 53161ec..e261d8a 100644
56409--- a/fs/9p/vfs_inode.c
56410+++ b/fs/9p/vfs_inode.c
56411@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56412 void
56413 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56414 {
56415- char *s = nd_get_link(nd);
56416+ const char *s = nd_get_link(nd);
56417
56418 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56419 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56420diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56421index 370b24c..ff0be7b 100644
56422--- a/fs/Kconfig.binfmt
56423+++ b/fs/Kconfig.binfmt
56424@@ -103,7 +103,7 @@ config HAVE_AOUT
56425
56426 config BINFMT_AOUT
56427 tristate "Kernel support for a.out and ECOFF binaries"
56428- depends on HAVE_AOUT
56429+ depends on HAVE_AOUT && BROKEN
56430 ---help---
56431 A.out (Assembler.OUTput) is a set of formats for libraries and
56432 executables used in the earliest versions of UNIX. Linux used
56433diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56434index 2946712..f737435 100644
56435--- a/fs/afs/inode.c
56436+++ b/fs/afs/inode.c
56437@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56438 struct afs_vnode *vnode;
56439 struct super_block *sb;
56440 struct inode *inode;
56441- static atomic_t afs_autocell_ino;
56442+ static atomic_unchecked_t afs_autocell_ino;
56443
56444 _enter("{%x:%u},%*.*s,",
56445 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56446@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56447 data.fid.unique = 0;
56448 data.fid.vnode = 0;
56449
56450- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56451+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56452 afs_iget5_autocell_test, afs_iget5_set,
56453 &data);
56454 if (!inode) {
56455diff --git a/fs/aio.c b/fs/aio.c
56456index 6d68e01..573d8dc 100644
56457--- a/fs/aio.c
56458+++ b/fs/aio.c
56459@@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56460 size += sizeof(struct io_event) * nr_events;
56461
56462 nr_pages = PFN_UP(size);
56463- if (nr_pages < 0)
56464+ if (nr_pages <= 0)
56465 return -EINVAL;
56466
56467 file = aio_private_file(ctx, nr_pages);
56468diff --git a/fs/attr.c b/fs/attr.c
56469index 6530ced..4a827e2 100644
56470--- a/fs/attr.c
56471+++ b/fs/attr.c
56472@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56473 unsigned long limit;
56474
56475 limit = rlimit(RLIMIT_FSIZE);
56476+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56477 if (limit != RLIM_INFINITY && offset > limit)
56478 goto out_sig;
56479 if (offset > inode->i_sb->s_maxbytes)
56480diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56481index 116fd38..c04182da 100644
56482--- a/fs/autofs4/waitq.c
56483+++ b/fs/autofs4/waitq.c
56484@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56485 {
56486 unsigned long sigpipe, flags;
56487 mm_segment_t fs;
56488- const char *data = (const char *)addr;
56489+ const char __user *data = (const char __force_user *)addr;
56490 ssize_t wr = 0;
56491
56492 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56493@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56494 return 1;
56495 }
56496
56497+#ifdef CONFIG_GRKERNSEC_HIDESYM
56498+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56499+#endif
56500+
56501 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56502 enum autofs_notify notify)
56503 {
56504@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56505
56506 /* If this is a direct mount request create a dummy name */
56507 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56508+#ifdef CONFIG_GRKERNSEC_HIDESYM
56509+ /* this name does get written to userland via autofs4_write() */
56510+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56511+#else
56512 qstr.len = sprintf(name, "%p", dentry);
56513+#endif
56514 else {
56515 qstr.len = autofs4_getpath(sbi, dentry, &name);
56516 if (!qstr.len) {
56517diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56518index 2722387..56059b5 100644
56519--- a/fs/befs/endian.h
56520+++ b/fs/befs/endian.h
56521@@ -11,7 +11,7 @@
56522
56523 #include <asm/byteorder.h>
56524
56525-static inline u64
56526+static inline u64 __intentional_overflow(-1)
56527 fs64_to_cpu(const struct super_block *sb, fs64 n)
56528 {
56529 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56530@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56531 return (__force fs64)cpu_to_be64(n);
56532 }
56533
56534-static inline u32
56535+static inline u32 __intentional_overflow(-1)
56536 fs32_to_cpu(const struct super_block *sb, fs32 n)
56537 {
56538 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56539@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56540 return (__force fs32)cpu_to_be32(n);
56541 }
56542
56543-static inline u16
56544+static inline u16 __intentional_overflow(-1)
56545 fs16_to_cpu(const struct super_block *sb, fs16 n)
56546 {
56547 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56548diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56549index ca0ba15..0fa3257 100644
56550--- a/fs/binfmt_aout.c
56551+++ b/fs/binfmt_aout.c
56552@@ -16,6 +16,7 @@
56553 #include <linux/string.h>
56554 #include <linux/fs.h>
56555 #include <linux/file.h>
56556+#include <linux/security.h>
56557 #include <linux/stat.h>
56558 #include <linux/fcntl.h>
56559 #include <linux/ptrace.h>
56560@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56561 #endif
56562 # define START_STACK(u) ((void __user *)u.start_stack)
56563
56564+ memset(&dump, 0, sizeof(dump));
56565+
56566 fs = get_fs();
56567 set_fs(KERNEL_DS);
56568 has_dumped = 1;
56569@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56570
56571 /* If the size of the dump file exceeds the rlimit, then see what would happen
56572 if we wrote the stack, but not the data area. */
56573+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56574 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56575 dump.u_dsize = 0;
56576
56577 /* Make sure we have enough room to write the stack and data areas. */
56578+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56579 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56580 dump.u_ssize = 0;
56581
56582@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56583 rlim = rlimit(RLIMIT_DATA);
56584 if (rlim >= RLIM_INFINITY)
56585 rlim = ~0;
56586+
56587+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56588 if (ex.a_data + ex.a_bss > rlim)
56589 return -ENOMEM;
56590
56591@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56592
56593 install_exec_creds(bprm);
56594
56595+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56596+ current->mm->pax_flags = 0UL;
56597+#endif
56598+
56599+#ifdef CONFIG_PAX_PAGEEXEC
56600+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56601+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56602+
56603+#ifdef CONFIG_PAX_EMUTRAMP
56604+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56605+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56606+#endif
56607+
56608+#ifdef CONFIG_PAX_MPROTECT
56609+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56610+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56611+#endif
56612+
56613+ }
56614+#endif
56615+
56616 if (N_MAGIC(ex) == OMAGIC) {
56617 unsigned long text_addr, map_size;
56618 loff_t pos;
56619@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56620 }
56621
56622 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56623- PROT_READ | PROT_WRITE | PROT_EXEC,
56624+ PROT_READ | PROT_WRITE,
56625 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56626 fd_offset + ex.a_text);
56627 if (error != N_DATADDR(ex)) {
56628diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56629index aa3cb62..bc53934 100644
56630--- a/fs/binfmt_elf.c
56631+++ b/fs/binfmt_elf.c
56632@@ -34,6 +34,7 @@
56633 #include <linux/utsname.h>
56634 #include <linux/coredump.h>
56635 #include <linux/sched.h>
56636+#include <linux/xattr.h>
56637 #include <asm/uaccess.h>
56638 #include <asm/param.h>
56639 #include <asm/page.h>
56640@@ -47,7 +48,7 @@
56641
56642 static int load_elf_binary(struct linux_binprm *bprm);
56643 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56644- int, int, unsigned long);
56645+ int, int, unsigned long) __intentional_overflow(-1);
56646
56647 #ifdef CONFIG_USELIB
56648 static int load_elf_library(struct file *);
56649@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56650 #define elf_core_dump NULL
56651 #endif
56652
56653+#ifdef CONFIG_PAX_MPROTECT
56654+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56655+#endif
56656+
56657+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56658+static void elf_handle_mmap(struct file *file);
56659+#endif
56660+
56661 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56662 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56663 #else
56664@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56665 .load_binary = load_elf_binary,
56666 .load_shlib = load_elf_library,
56667 .core_dump = elf_core_dump,
56668+
56669+#ifdef CONFIG_PAX_MPROTECT
56670+ .handle_mprotect= elf_handle_mprotect,
56671+#endif
56672+
56673+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56674+ .handle_mmap = elf_handle_mmap,
56675+#endif
56676+
56677 .min_coredump = ELF_EXEC_PAGESIZE,
56678 };
56679
56680@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56681
56682 static int set_brk(unsigned long start, unsigned long end)
56683 {
56684+ unsigned long e = end;
56685+
56686 start = ELF_PAGEALIGN(start);
56687 end = ELF_PAGEALIGN(end);
56688 if (end > start) {
56689@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56690 if (BAD_ADDR(addr))
56691 return addr;
56692 }
56693- current->mm->start_brk = current->mm->brk = end;
56694+ current->mm->start_brk = current->mm->brk = e;
56695 return 0;
56696 }
56697
56698@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56699 elf_addr_t __user *u_rand_bytes;
56700 const char *k_platform = ELF_PLATFORM;
56701 const char *k_base_platform = ELF_BASE_PLATFORM;
56702- unsigned char k_rand_bytes[16];
56703+ u32 k_rand_bytes[4];
56704 int items;
56705 elf_addr_t *elf_info;
56706 int ei_index = 0;
56707 const struct cred *cred = current_cred();
56708 struct vm_area_struct *vma;
56709+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56710
56711 /*
56712 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56713@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56714 * Generate 16 random bytes for userspace PRNG seeding.
56715 */
56716 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56717- u_rand_bytes = (elf_addr_t __user *)
56718- STACK_ALLOC(p, sizeof(k_rand_bytes));
56719+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56720+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56721+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56722+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56723+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56724+ u_rand_bytes = (elf_addr_t __user *) p;
56725 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56726 return -EFAULT;
56727
56728@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56729 return -EFAULT;
56730 current->mm->env_end = p;
56731
56732+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56733+
56734 /* Put the elf_info on the stack in the right place. */
56735 sp = (elf_addr_t __user *)envp + 1;
56736- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56737+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56738 return -EFAULT;
56739 return 0;
56740 }
56741@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56742 an ELF header */
56743
56744 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56745- struct file *interpreter, unsigned long *interp_map_addr,
56746- unsigned long no_base)
56747+ struct file *interpreter, unsigned long no_base)
56748 {
56749 struct elf_phdr *elf_phdata;
56750 struct elf_phdr *eppnt;
56751- unsigned long load_addr = 0;
56752+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56753 int load_addr_set = 0;
56754 unsigned long last_bss = 0, elf_bss = 0;
56755- unsigned long error = ~0UL;
56756+ unsigned long error = -EINVAL;
56757 unsigned long total_size;
56758 int retval, i, size;
56759
56760@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56761 goto out_close;
56762 }
56763
56764+#ifdef CONFIG_PAX_SEGMEXEC
56765+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56766+ pax_task_size = SEGMEXEC_TASK_SIZE;
56767+#endif
56768+
56769 eppnt = elf_phdata;
56770 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56771 if (eppnt->p_type == PT_LOAD) {
56772@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56773 map_addr = elf_map(interpreter, load_addr + vaddr,
56774 eppnt, elf_prot, elf_type, total_size);
56775 total_size = 0;
56776- if (!*interp_map_addr)
56777- *interp_map_addr = map_addr;
56778 error = map_addr;
56779 if (BAD_ADDR(map_addr))
56780 goto out_close;
56781@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56782 k = load_addr + eppnt->p_vaddr;
56783 if (BAD_ADDR(k) ||
56784 eppnt->p_filesz > eppnt->p_memsz ||
56785- eppnt->p_memsz > TASK_SIZE ||
56786- TASK_SIZE - eppnt->p_memsz < k) {
56787+ eppnt->p_memsz > pax_task_size ||
56788+ pax_task_size - eppnt->p_memsz < k) {
56789 error = -ENOMEM;
56790 goto out_close;
56791 }
56792@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56793 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56794
56795 /* Map the last of the bss segment */
56796- error = vm_brk(elf_bss, last_bss - elf_bss);
56797- if (BAD_ADDR(error))
56798- goto out_close;
56799+ if (last_bss > elf_bss) {
56800+ error = vm_brk(elf_bss, last_bss - elf_bss);
56801+ if (BAD_ADDR(error))
56802+ goto out_close;
56803+ }
56804 }
56805
56806 error = load_addr;
56807@@ -543,6 +574,336 @@ out:
56808 return error;
56809 }
56810
56811+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56812+#ifdef CONFIG_PAX_SOFTMODE
56813+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56814+{
56815+ unsigned long pax_flags = 0UL;
56816+
56817+#ifdef CONFIG_PAX_PAGEEXEC
56818+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56819+ pax_flags |= MF_PAX_PAGEEXEC;
56820+#endif
56821+
56822+#ifdef CONFIG_PAX_SEGMEXEC
56823+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56824+ pax_flags |= MF_PAX_SEGMEXEC;
56825+#endif
56826+
56827+#ifdef CONFIG_PAX_EMUTRAMP
56828+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56829+ pax_flags |= MF_PAX_EMUTRAMP;
56830+#endif
56831+
56832+#ifdef CONFIG_PAX_MPROTECT
56833+ if (elf_phdata->p_flags & PF_MPROTECT)
56834+ pax_flags |= MF_PAX_MPROTECT;
56835+#endif
56836+
56837+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56838+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56839+ pax_flags |= MF_PAX_RANDMMAP;
56840+#endif
56841+
56842+ return pax_flags;
56843+}
56844+#endif
56845+
56846+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56847+{
56848+ unsigned long pax_flags = 0UL;
56849+
56850+#ifdef CONFIG_PAX_PAGEEXEC
56851+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56852+ pax_flags |= MF_PAX_PAGEEXEC;
56853+#endif
56854+
56855+#ifdef CONFIG_PAX_SEGMEXEC
56856+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56857+ pax_flags |= MF_PAX_SEGMEXEC;
56858+#endif
56859+
56860+#ifdef CONFIG_PAX_EMUTRAMP
56861+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56862+ pax_flags |= MF_PAX_EMUTRAMP;
56863+#endif
56864+
56865+#ifdef CONFIG_PAX_MPROTECT
56866+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56867+ pax_flags |= MF_PAX_MPROTECT;
56868+#endif
56869+
56870+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56871+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56872+ pax_flags |= MF_PAX_RANDMMAP;
56873+#endif
56874+
56875+ return pax_flags;
56876+}
56877+#endif
56878+
56879+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56880+#ifdef CONFIG_PAX_SOFTMODE
56881+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56882+{
56883+ unsigned long pax_flags = 0UL;
56884+
56885+#ifdef CONFIG_PAX_PAGEEXEC
56886+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56887+ pax_flags |= MF_PAX_PAGEEXEC;
56888+#endif
56889+
56890+#ifdef CONFIG_PAX_SEGMEXEC
56891+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56892+ pax_flags |= MF_PAX_SEGMEXEC;
56893+#endif
56894+
56895+#ifdef CONFIG_PAX_EMUTRAMP
56896+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56897+ pax_flags |= MF_PAX_EMUTRAMP;
56898+#endif
56899+
56900+#ifdef CONFIG_PAX_MPROTECT
56901+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56902+ pax_flags |= MF_PAX_MPROTECT;
56903+#endif
56904+
56905+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56906+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56907+ pax_flags |= MF_PAX_RANDMMAP;
56908+#endif
56909+
56910+ return pax_flags;
56911+}
56912+#endif
56913+
56914+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56915+{
56916+ unsigned long pax_flags = 0UL;
56917+
56918+#ifdef CONFIG_PAX_PAGEEXEC
56919+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56920+ pax_flags |= MF_PAX_PAGEEXEC;
56921+#endif
56922+
56923+#ifdef CONFIG_PAX_SEGMEXEC
56924+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56925+ pax_flags |= MF_PAX_SEGMEXEC;
56926+#endif
56927+
56928+#ifdef CONFIG_PAX_EMUTRAMP
56929+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56930+ pax_flags |= MF_PAX_EMUTRAMP;
56931+#endif
56932+
56933+#ifdef CONFIG_PAX_MPROTECT
56934+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56935+ pax_flags |= MF_PAX_MPROTECT;
56936+#endif
56937+
56938+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56939+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56940+ pax_flags |= MF_PAX_RANDMMAP;
56941+#endif
56942+
56943+ return pax_flags;
56944+}
56945+#endif
56946+
56947+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56948+static unsigned long pax_parse_defaults(void)
56949+{
56950+ unsigned long pax_flags = 0UL;
56951+
56952+#ifdef CONFIG_PAX_SOFTMODE
56953+ if (pax_softmode)
56954+ return pax_flags;
56955+#endif
56956+
56957+#ifdef CONFIG_PAX_PAGEEXEC
56958+ pax_flags |= MF_PAX_PAGEEXEC;
56959+#endif
56960+
56961+#ifdef CONFIG_PAX_SEGMEXEC
56962+ pax_flags |= MF_PAX_SEGMEXEC;
56963+#endif
56964+
56965+#ifdef CONFIG_PAX_MPROTECT
56966+ pax_flags |= MF_PAX_MPROTECT;
56967+#endif
56968+
56969+#ifdef CONFIG_PAX_RANDMMAP
56970+ if (randomize_va_space)
56971+ pax_flags |= MF_PAX_RANDMMAP;
56972+#endif
56973+
56974+ return pax_flags;
56975+}
56976+
56977+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56978+{
56979+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56980+
56981+#ifdef CONFIG_PAX_EI_PAX
56982+
56983+#ifdef CONFIG_PAX_SOFTMODE
56984+ if (pax_softmode)
56985+ return pax_flags;
56986+#endif
56987+
56988+ pax_flags = 0UL;
56989+
56990+#ifdef CONFIG_PAX_PAGEEXEC
56991+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56992+ pax_flags |= MF_PAX_PAGEEXEC;
56993+#endif
56994+
56995+#ifdef CONFIG_PAX_SEGMEXEC
56996+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56997+ pax_flags |= MF_PAX_SEGMEXEC;
56998+#endif
56999+
57000+#ifdef CONFIG_PAX_EMUTRAMP
57001+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
57002+ pax_flags |= MF_PAX_EMUTRAMP;
57003+#endif
57004+
57005+#ifdef CONFIG_PAX_MPROTECT
57006+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
57007+ pax_flags |= MF_PAX_MPROTECT;
57008+#endif
57009+
57010+#ifdef CONFIG_PAX_ASLR
57011+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
57012+ pax_flags |= MF_PAX_RANDMMAP;
57013+#endif
57014+
57015+#endif
57016+
57017+ return pax_flags;
57018+
57019+}
57020+
57021+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
57022+{
57023+
57024+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57025+ unsigned long i;
57026+
57027+ for (i = 0UL; i < elf_ex->e_phnum; i++)
57028+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
57029+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
57030+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
57031+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
57032+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
57033+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
57034+ return PAX_PARSE_FLAGS_FALLBACK;
57035+
57036+#ifdef CONFIG_PAX_SOFTMODE
57037+ if (pax_softmode)
57038+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
57039+ else
57040+#endif
57041+
57042+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
57043+ break;
57044+ }
57045+#endif
57046+
57047+ return PAX_PARSE_FLAGS_FALLBACK;
57048+}
57049+
57050+static unsigned long pax_parse_xattr_pax(struct file * const file)
57051+{
57052+
57053+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
57054+ ssize_t xattr_size, i;
57055+ unsigned char xattr_value[sizeof("pemrs") - 1];
57056+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
57057+
57058+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
57059+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
57060+ return PAX_PARSE_FLAGS_FALLBACK;
57061+
57062+ for (i = 0; i < xattr_size; i++)
57063+ switch (xattr_value[i]) {
57064+ default:
57065+ return PAX_PARSE_FLAGS_FALLBACK;
57066+
57067+#define parse_flag(option1, option2, flag) \
57068+ case option1: \
57069+ if (pax_flags_hardmode & MF_PAX_##flag) \
57070+ return PAX_PARSE_FLAGS_FALLBACK;\
57071+ pax_flags_hardmode |= MF_PAX_##flag; \
57072+ break; \
57073+ case option2: \
57074+ if (pax_flags_softmode & MF_PAX_##flag) \
57075+ return PAX_PARSE_FLAGS_FALLBACK;\
57076+ pax_flags_softmode |= MF_PAX_##flag; \
57077+ break;
57078+
57079+ parse_flag('p', 'P', PAGEEXEC);
57080+ parse_flag('e', 'E', EMUTRAMP);
57081+ parse_flag('m', 'M', MPROTECT);
57082+ parse_flag('r', 'R', RANDMMAP);
57083+ parse_flag('s', 'S', SEGMEXEC);
57084+
57085+#undef parse_flag
57086+ }
57087+
57088+ if (pax_flags_hardmode & pax_flags_softmode)
57089+ return PAX_PARSE_FLAGS_FALLBACK;
57090+
57091+#ifdef CONFIG_PAX_SOFTMODE
57092+ if (pax_softmode)
57093+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
57094+ else
57095+#endif
57096+
57097+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
57098+#else
57099+ return PAX_PARSE_FLAGS_FALLBACK;
57100+#endif
57101+
57102+}
57103+
57104+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
57105+{
57106+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
57107+
57108+ pax_flags = pax_parse_defaults();
57109+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
57110+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
57111+ xattr_pax_flags = pax_parse_xattr_pax(file);
57112+
57113+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57114+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57115+ pt_pax_flags != xattr_pax_flags)
57116+ return -EINVAL;
57117+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57118+ pax_flags = xattr_pax_flags;
57119+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57120+ pax_flags = pt_pax_flags;
57121+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57122+ pax_flags = ei_pax_flags;
57123+
57124+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57125+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57126+ if ((__supported_pte_mask & _PAGE_NX))
57127+ pax_flags &= ~MF_PAX_SEGMEXEC;
57128+ else
57129+ pax_flags &= ~MF_PAX_PAGEEXEC;
57130+ }
57131+#endif
57132+
57133+ if (0 > pax_check_flags(&pax_flags))
57134+ return -EINVAL;
57135+
57136+ current->mm->pax_flags = pax_flags;
57137+ return 0;
57138+}
57139+#endif
57140+
57141 /*
57142 * These are the functions used to load ELF style executables and shared
57143 * libraries. There is no binary dependent code anywhere else.
57144@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57145 {
57146 unsigned int random_variable = 0;
57147
57148+#ifdef CONFIG_PAX_RANDUSTACK
57149+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57150+ return stack_top - current->mm->delta_stack;
57151+#endif
57152+
57153 if ((current->flags & PF_RANDOMIZE) &&
57154 !(current->personality & ADDR_NO_RANDOMIZE)) {
57155 random_variable = get_random_int() & STACK_RND_MASK;
57156@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57157 unsigned long load_addr = 0, load_bias = 0;
57158 int load_addr_set = 0;
57159 char * elf_interpreter = NULL;
57160- unsigned long error;
57161+ unsigned long error = 0;
57162 struct elf_phdr *elf_ppnt, *elf_phdata;
57163 unsigned long elf_bss, elf_brk;
57164 int retval, i;
57165@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57166 struct elfhdr elf_ex;
57167 struct elfhdr interp_elf_ex;
57168 } *loc;
57169+ unsigned long pax_task_size;
57170
57171 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57172 if (!loc) {
57173@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
57174 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57175 may depend on the personality. */
57176 SET_PERSONALITY(loc->elf_ex);
57177+
57178+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57179+ current->mm->pax_flags = 0UL;
57180+#endif
57181+
57182+#ifdef CONFIG_PAX_DLRESOLVE
57183+ current->mm->call_dl_resolve = 0UL;
57184+#endif
57185+
57186+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57187+ current->mm->call_syscall = 0UL;
57188+#endif
57189+
57190+#ifdef CONFIG_PAX_ASLR
57191+ current->mm->delta_mmap = 0UL;
57192+ current->mm->delta_stack = 0UL;
57193+#endif
57194+
57195+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57196+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57197+ send_sig(SIGKILL, current, 0);
57198+ goto out_free_dentry;
57199+ }
57200+#endif
57201+
57202+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57203+ pax_set_initial_flags(bprm);
57204+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57205+ if (pax_set_initial_flags_func)
57206+ (pax_set_initial_flags_func)(bprm);
57207+#endif
57208+
57209+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57210+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57211+ current->mm->context.user_cs_limit = PAGE_SIZE;
57212+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57213+ }
57214+#endif
57215+
57216+#ifdef CONFIG_PAX_SEGMEXEC
57217+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57218+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57219+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57220+ pax_task_size = SEGMEXEC_TASK_SIZE;
57221+ current->mm->def_flags |= VM_NOHUGEPAGE;
57222+ } else
57223+#endif
57224+
57225+ pax_task_size = TASK_SIZE;
57226+
57227+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57228+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57229+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57230+ put_cpu();
57231+ }
57232+#endif
57233+
57234+#ifdef CONFIG_PAX_ASLR
57235+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57236+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57237+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57238+ }
57239+#endif
57240+
57241+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57242+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57243+ executable_stack = EXSTACK_DISABLE_X;
57244+ current->personality &= ~READ_IMPLIES_EXEC;
57245+ } else
57246+#endif
57247+
57248 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57249 current->personality |= READ_IMPLIES_EXEC;
57250
57251@@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57252 #else
57253 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57254 #endif
57255+
57256+#ifdef CONFIG_PAX_RANDMMAP
57257+ /* PaX: randomize base address at the default exe base if requested */
57258+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57259+#ifdef CONFIG_SPARC64
57260+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57261+#else
57262+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57263+#endif
57264+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57265+ elf_flags |= MAP_FIXED;
57266+ }
57267+#endif
57268+
57269 }
57270
57271 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57272@@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57273 * allowed task size. Note that p_filesz must always be
57274 * <= p_memsz so it is only necessary to check p_memsz.
57275 */
57276- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57277- elf_ppnt->p_memsz > TASK_SIZE ||
57278- TASK_SIZE - elf_ppnt->p_memsz < k) {
57279+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57280+ elf_ppnt->p_memsz > pax_task_size ||
57281+ pax_task_size - elf_ppnt->p_memsz < k) {
57282 /* set_brk can never work. Avoid overflows. */
57283 send_sig(SIGKILL, current, 0);
57284 retval = -EINVAL;
57285@@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57286 goto out_free_dentry;
57287 }
57288 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57289- send_sig(SIGSEGV, current, 0);
57290- retval = -EFAULT; /* Nobody gets to see this, but.. */
57291- goto out_free_dentry;
57292+ /*
57293+ * This bss-zeroing can fail if the ELF
57294+ * file specifies odd protections. So
57295+ * we don't check the return value
57296+ */
57297 }
57298
57299+#ifdef CONFIG_PAX_RANDMMAP
57300+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57301+ unsigned long start, size, flags;
57302+ vm_flags_t vm_flags;
57303+
57304+ start = ELF_PAGEALIGN(elf_brk);
57305+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57306+ flags = MAP_FIXED | MAP_PRIVATE;
57307+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57308+
57309+ down_write(&current->mm->mmap_sem);
57310+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57311+ retval = -ENOMEM;
57312+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57313+// if (current->personality & ADDR_NO_RANDOMIZE)
57314+// vm_flags |= VM_READ | VM_MAYREAD;
57315+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57316+ retval = IS_ERR_VALUE(start) ? start : 0;
57317+ }
57318+ up_write(&current->mm->mmap_sem);
57319+ if (retval == 0)
57320+ retval = set_brk(start + size, start + size + PAGE_SIZE);
57321+ if (retval < 0) {
57322+ send_sig(SIGKILL, current, 0);
57323+ goto out_free_dentry;
57324+ }
57325+ }
57326+#endif
57327+
57328 if (elf_interpreter) {
57329- unsigned long interp_map_addr = 0;
57330-
57331 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57332 interpreter,
57333- &interp_map_addr,
57334 load_bias);
57335 if (!IS_ERR((void *)elf_entry)) {
57336 /*
57337@@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57338 * Decide what to dump of a segment, part, all or none.
57339 */
57340 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57341- unsigned long mm_flags)
57342+ unsigned long mm_flags, long signr)
57343 {
57344 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57345
57346@@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57347 if (vma->vm_file == NULL)
57348 return 0;
57349
57350- if (FILTER(MAPPED_PRIVATE))
57351+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57352 goto whole;
57353
57354 /*
57355@@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57356 {
57357 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57358 int i = 0;
57359- do
57360+ do {
57361 i += 2;
57362- while (auxv[i - 2] != AT_NULL);
57363+ } while (auxv[i - 2] != AT_NULL);
57364 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57365 }
57366
57367@@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57368 {
57369 mm_segment_t old_fs = get_fs();
57370 set_fs(KERNEL_DS);
57371- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57372+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57373 set_fs(old_fs);
57374 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57375 }
57376@@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57377 }
57378
57379 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57380- unsigned long mm_flags)
57381+ struct coredump_params *cprm)
57382 {
57383 struct vm_area_struct *vma;
57384 size_t size = 0;
57385
57386 for (vma = first_vma(current, gate_vma); vma != NULL;
57387 vma = next_vma(vma, gate_vma))
57388- size += vma_dump_size(vma, mm_flags);
57389+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57390 return size;
57391 }
57392
57393@@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57394
57395 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57396
57397- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57398+ offset += elf_core_vma_data_size(gate_vma, cprm);
57399 offset += elf_core_extra_data_size();
57400 e_shoff = offset;
57401
57402@@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57403 phdr.p_offset = offset;
57404 phdr.p_vaddr = vma->vm_start;
57405 phdr.p_paddr = 0;
57406- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57407+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57408 phdr.p_memsz = vma->vm_end - vma->vm_start;
57409 offset += phdr.p_filesz;
57410 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57411@@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57412 unsigned long addr;
57413 unsigned long end;
57414
57415- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57416+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57417
57418 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57419 struct page *page;
57420@@ -2202,6 +2682,167 @@ out:
57421
57422 #endif /* CONFIG_ELF_CORE */
57423
57424+#ifdef CONFIG_PAX_MPROTECT
57425+/* PaX: non-PIC ELF libraries need relocations on their executable segments
57426+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57427+ * we'll remove VM_MAYWRITE for good on RELRO segments.
57428+ *
57429+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57430+ * basis because we want to allow the common case and not the special ones.
57431+ */
57432+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57433+{
57434+ struct elfhdr elf_h;
57435+ struct elf_phdr elf_p;
57436+ unsigned long i;
57437+ unsigned long oldflags;
57438+ bool is_textrel_rw, is_textrel_rx, is_relro;
57439+
57440+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57441+ return;
57442+
57443+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57444+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57445+
57446+#ifdef CONFIG_PAX_ELFRELOCS
57447+ /* possible TEXTREL */
57448+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57449+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57450+#else
57451+ is_textrel_rw = false;
57452+ is_textrel_rx = false;
57453+#endif
57454+
57455+ /* possible RELRO */
57456+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57457+
57458+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57459+ return;
57460+
57461+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57462+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57463+
57464+#ifdef CONFIG_PAX_ETEXECRELOCS
57465+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57466+#else
57467+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57468+#endif
57469+
57470+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57471+ !elf_check_arch(&elf_h) ||
57472+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57473+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57474+ return;
57475+
57476+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57477+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57478+ return;
57479+ switch (elf_p.p_type) {
57480+ case PT_DYNAMIC:
57481+ if (!is_textrel_rw && !is_textrel_rx)
57482+ continue;
57483+ i = 0UL;
57484+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57485+ elf_dyn dyn;
57486+
57487+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57488+ break;
57489+ if (dyn.d_tag == DT_NULL)
57490+ break;
57491+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57492+ gr_log_textrel(vma);
57493+ if (is_textrel_rw)
57494+ vma->vm_flags |= VM_MAYWRITE;
57495+ else
57496+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57497+ vma->vm_flags &= ~VM_MAYWRITE;
57498+ break;
57499+ }
57500+ i++;
57501+ }
57502+ is_textrel_rw = false;
57503+ is_textrel_rx = false;
57504+ continue;
57505+
57506+ case PT_GNU_RELRO:
57507+ if (!is_relro)
57508+ continue;
57509+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57510+ vma->vm_flags &= ~VM_MAYWRITE;
57511+ is_relro = false;
57512+ continue;
57513+
57514+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57515+ case PT_PAX_FLAGS: {
57516+ const char *msg_mprotect = "", *msg_emutramp = "";
57517+ char *buffer_lib, *buffer_exe;
57518+
57519+ if (elf_p.p_flags & PF_NOMPROTECT)
57520+ msg_mprotect = "MPROTECT disabled";
57521+
57522+#ifdef CONFIG_PAX_EMUTRAMP
57523+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57524+ msg_emutramp = "EMUTRAMP enabled";
57525+#endif
57526+
57527+ if (!msg_mprotect[0] && !msg_emutramp[0])
57528+ continue;
57529+
57530+ if (!printk_ratelimit())
57531+ continue;
57532+
57533+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57534+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57535+ if (buffer_lib && buffer_exe) {
57536+ char *path_lib, *path_exe;
57537+
57538+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57539+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57540+
57541+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57542+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57543+
57544+ }
57545+ free_page((unsigned long)buffer_exe);
57546+ free_page((unsigned long)buffer_lib);
57547+ continue;
57548+ }
57549+#endif
57550+
57551+ }
57552+ }
57553+}
57554+#endif
57555+
57556+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57557+
57558+extern int grsec_enable_log_rwxmaps;
57559+
57560+static void elf_handle_mmap(struct file *file)
57561+{
57562+ struct elfhdr elf_h;
57563+ struct elf_phdr elf_p;
57564+ unsigned long i;
57565+
57566+ if (!grsec_enable_log_rwxmaps)
57567+ return;
57568+
57569+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57570+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57571+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57572+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57573+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57574+ return;
57575+
57576+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57577+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57578+ return;
57579+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57580+ gr_log_ptgnustack(file);
57581+ }
57582+}
57583+#endif
57584+
57585 static int __init init_elf_binfmt(void)
57586 {
57587 register_binfmt(&elf_format);
57588diff --git a/fs/bio.c b/fs/bio.c
57589index 6f0362b..26a7496 100644
57590--- a/fs/bio.c
57591+++ b/fs/bio.c
57592@@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57593 /*
57594 * Overflow, abort
57595 */
57596- if (end < start)
57597+ if (end < start || end - start > INT_MAX - nr_pages)
57598 return ERR_PTR(-EINVAL);
57599
57600 nr_pages += end - start;
57601@@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57602 /*
57603 * Overflow, abort
57604 */
57605- if (end < start)
57606+ if (end < start || end - start > INT_MAX - nr_pages)
57607 return ERR_PTR(-EINVAL);
57608
57609 nr_pages += end - start;
57610@@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57611 const int read = bio_data_dir(bio) == READ;
57612 struct bio_map_data *bmd = bio->bi_private;
57613 int i;
57614- char *p = bmd->sgvecs[0].iov_base;
57615+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57616
57617 bio_for_each_segment_all(bvec, bio, i) {
57618 char *addr = page_address(bvec->bv_page);
57619diff --git a/fs/block_dev.c b/fs/block_dev.c
57620index 552a8d1..d51ccf3 100644
57621--- a/fs/block_dev.c
57622+++ b/fs/block_dev.c
57623@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57624 else if (bdev->bd_contains == bdev)
57625 return true; /* is a whole device which isn't held */
57626
57627- else if (whole->bd_holder == bd_may_claim)
57628+ else if (whole->bd_holder == (void *)bd_may_claim)
57629 return true; /* is a partition of a device that is being partitioned */
57630 else if (whole->bd_holder != NULL)
57631 return false; /* is a partition of a held device */
57632diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57633index 1bcfcdb..e942132 100644
57634--- a/fs/btrfs/ctree.c
57635+++ b/fs/btrfs/ctree.c
57636@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57637 free_extent_buffer(buf);
57638 add_root_to_dirty_list(root);
57639 } else {
57640- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57641- parent_start = parent->start;
57642- else
57643+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57644+ if (parent)
57645+ parent_start = parent->start;
57646+ else
57647+ parent_start = 0;
57648+ } else
57649 parent_start = 0;
57650
57651 WARN_ON(trans->transid != btrfs_header_generation(parent));
57652diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57653index 33e561a..16df7ae 100644
57654--- a/fs/btrfs/delayed-inode.c
57655+++ b/fs/btrfs/delayed-inode.c
57656@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57657
57658 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57659 {
57660- int seq = atomic_inc_return(&delayed_root->items_seq);
57661+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57662 if ((atomic_dec_return(&delayed_root->items) <
57663 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57664 waitqueue_active(&delayed_root->wait))
57665@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57666
57667 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57668 {
57669- int val = atomic_read(&delayed_root->items_seq);
57670+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57671
57672 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57673 return 1;
57674@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57675 int seq;
57676 int ret;
57677
57678- seq = atomic_read(&delayed_root->items_seq);
57679+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57680
57681 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57682 if (ret)
57683diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57684index f70119f..ab5894d 100644
57685--- a/fs/btrfs/delayed-inode.h
57686+++ b/fs/btrfs/delayed-inode.h
57687@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57688 */
57689 struct list_head prepare_list;
57690 atomic_t items; /* for delayed items */
57691- atomic_t items_seq; /* for delayed items */
57692+ atomic_unchecked_t items_seq; /* for delayed items */
57693 int nodes; /* for delayed nodes */
57694 wait_queue_head_t wait;
57695 };
57696@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57697 struct btrfs_delayed_root *delayed_root)
57698 {
57699 atomic_set(&delayed_root->items, 0);
57700- atomic_set(&delayed_root->items_seq, 0);
57701+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57702 delayed_root->nodes = 0;
57703 spin_lock_init(&delayed_root->lock);
57704 init_waitqueue_head(&delayed_root->wait);
57705diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57706index 2f6d7b1..f186382 100644
57707--- a/fs/btrfs/ioctl.c
57708+++ b/fs/btrfs/ioctl.c
57709@@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57710 for (i = 0; i < num_types; i++) {
57711 struct btrfs_space_info *tmp;
57712
57713+ /* Don't copy in more than we allocated */
57714 if (!slot_count)
57715 break;
57716
57717+ slot_count--;
57718+
57719 info = NULL;
57720 rcu_read_lock();
57721 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57722@@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57723 memcpy(dest, &space, sizeof(space));
57724 dest++;
57725 space_args.total_spaces++;
57726- slot_count--;
57727 }
57728- if (!slot_count)
57729- break;
57730 }
57731 up_read(&info->groups_sem);
57732 }
57733diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57734index 9601d25..2896d6c 100644
57735--- a/fs/btrfs/super.c
57736+++ b/fs/btrfs/super.c
57737@@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57738 function, line, errstr);
57739 return;
57740 }
57741- ACCESS_ONCE(trans->transaction->aborted) = errno;
57742+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57743 /* Wake up anybody who may be waiting on this transaction */
57744 wake_up(&root->fs_info->transaction_wait);
57745 wake_up(&root->fs_info->transaction_blocked_wait);
57746diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57747index 4825cd2..b2fe768 100644
57748--- a/fs/btrfs/sysfs.c
57749+++ b/fs/btrfs/sysfs.c
57750@@ -438,7 +438,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57751 for (set = 0; set < FEAT_MAX; set++) {
57752 int i;
57753 struct attribute *attrs[2];
57754- struct attribute_group agroup = {
57755+ attribute_group_no_const agroup = {
57756 .name = "features",
57757 .attrs = attrs,
57758 };
57759diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57760index e2f45fc..b036909 100644
57761--- a/fs/btrfs/tree-log.c
57762+++ b/fs/btrfs/tree-log.c
57763@@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57764 blk_finish_plug(&plug);
57765 btrfs_abort_transaction(trans, root, ret);
57766 btrfs_free_logged_extents(log, log_transid);
57767- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57768+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57769 trans->transid;
57770 mutex_unlock(&root->log_mutex);
57771 goto out;
57772@@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57773 list_del_init(&root_log_ctx.list);
57774
57775 blk_finish_plug(&plug);
57776- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57777+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57778 trans->transid;
57779 if (ret != -ENOSPC) {
57780 btrfs_abort_transaction(trans, root, ret);
57781@@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57782 * now that we've moved on to the tree of log tree roots,
57783 * check the full commit flag again
57784 */
57785- if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57786+ if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57787 trans->transid) {
57788 blk_finish_plug(&plug);
57789 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57790@@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57791 EXTENT_DIRTY | EXTENT_NEW);
57792 blk_finish_plug(&plug);
57793 if (ret) {
57794- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57795+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57796 trans->transid;
57797 btrfs_abort_transaction(trans, root, ret);
57798 btrfs_free_logged_extents(log, log_transid);
57799@@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57800 */
57801 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57802 if (ret) {
57803- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57804+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57805 trans->transid;
57806 btrfs_abort_transaction(trans, root, ret);
57807 goto out_wake_log_root;
57808diff --git a/fs/buffer.c b/fs/buffer.c
57809index 9ddb9fc..7aa2487 100644
57810--- a/fs/buffer.c
57811+++ b/fs/buffer.c
57812@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57813 bh_cachep = kmem_cache_create("buffer_head",
57814 sizeof(struct buffer_head), 0,
57815 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57816- SLAB_MEM_SPREAD),
57817+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57818 NULL);
57819
57820 /*
57821diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57822index 5b99baf..47fffb5 100644
57823--- a/fs/cachefiles/bind.c
57824+++ b/fs/cachefiles/bind.c
57825@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57826 args);
57827
57828 /* start by checking things over */
57829- ASSERT(cache->fstop_percent >= 0 &&
57830- cache->fstop_percent < cache->fcull_percent &&
57831+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57832 cache->fcull_percent < cache->frun_percent &&
57833 cache->frun_percent < 100);
57834
57835- ASSERT(cache->bstop_percent >= 0 &&
57836- cache->bstop_percent < cache->bcull_percent &&
57837+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57838 cache->bcull_percent < cache->brun_percent &&
57839 cache->brun_percent < 100);
57840
57841diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57842index 0a1467b..6a53245 100644
57843--- a/fs/cachefiles/daemon.c
57844+++ b/fs/cachefiles/daemon.c
57845@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57846 if (n > buflen)
57847 return -EMSGSIZE;
57848
57849- if (copy_to_user(_buffer, buffer, n) != 0)
57850+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57851 return -EFAULT;
57852
57853 return n;
57854@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57855 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57856 return -EIO;
57857
57858- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57859+ if (datalen > PAGE_SIZE - 1)
57860 return -EOPNOTSUPP;
57861
57862 /* drag the command string into the kernel so we can parse it */
57863@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57864 if (args[0] != '%' || args[1] != '\0')
57865 return -EINVAL;
57866
57867- if (fstop < 0 || fstop >= cache->fcull_percent)
57868+ if (fstop >= cache->fcull_percent)
57869 return cachefiles_daemon_range_error(cache, args);
57870
57871 cache->fstop_percent = fstop;
57872@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57873 if (args[0] != '%' || args[1] != '\0')
57874 return -EINVAL;
57875
57876- if (bstop < 0 || bstop >= cache->bcull_percent)
57877+ if (bstop >= cache->bcull_percent)
57878 return cachefiles_daemon_range_error(cache, args);
57879
57880 cache->bstop_percent = bstop;
57881diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57882index 5349473..d6c0b93 100644
57883--- a/fs/cachefiles/internal.h
57884+++ b/fs/cachefiles/internal.h
57885@@ -59,7 +59,7 @@ struct cachefiles_cache {
57886 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57887 struct rb_root active_nodes; /* active nodes (can't be culled) */
57888 rwlock_t active_lock; /* lock for active_nodes */
57889- atomic_t gravecounter; /* graveyard uniquifier */
57890+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57891 unsigned frun_percent; /* when to stop culling (% files) */
57892 unsigned fcull_percent; /* when to start culling (% files) */
57893 unsigned fstop_percent; /* when to stop allocating (% files) */
57894@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57895 * proc.c
57896 */
57897 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57898-extern atomic_t cachefiles_lookup_histogram[HZ];
57899-extern atomic_t cachefiles_mkdir_histogram[HZ];
57900-extern atomic_t cachefiles_create_histogram[HZ];
57901+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57902+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57903+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57904
57905 extern int __init cachefiles_proc_init(void);
57906 extern void cachefiles_proc_cleanup(void);
57907 static inline
57908-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57909+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57910 {
57911 unsigned long jif = jiffies - start_jif;
57912 if (jif >= HZ)
57913 jif = HZ - 1;
57914- atomic_inc(&histogram[jif]);
57915+ atomic_inc_unchecked(&histogram[jif]);
57916 }
57917
57918 #else
57919diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57920index c0a6817..ea811166 100644
57921--- a/fs/cachefiles/namei.c
57922+++ b/fs/cachefiles/namei.c
57923@@ -317,7 +317,7 @@ try_again:
57924 /* first step is to make up a grave dentry in the graveyard */
57925 sprintf(nbuffer, "%08x%08x",
57926 (uint32_t) get_seconds(),
57927- (uint32_t) atomic_inc_return(&cache->gravecounter));
57928+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57929
57930 /* do the multiway lock magic */
57931 trap = lock_rename(cache->graveyard, dir);
57932diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57933index eccd339..4c1d995 100644
57934--- a/fs/cachefiles/proc.c
57935+++ b/fs/cachefiles/proc.c
57936@@ -14,9 +14,9 @@
57937 #include <linux/seq_file.h>
57938 #include "internal.h"
57939
57940-atomic_t cachefiles_lookup_histogram[HZ];
57941-atomic_t cachefiles_mkdir_histogram[HZ];
57942-atomic_t cachefiles_create_histogram[HZ];
57943+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57944+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57945+atomic_unchecked_t cachefiles_create_histogram[HZ];
57946
57947 /*
57948 * display the latency histogram
57949@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57950 return 0;
57951 default:
57952 index = (unsigned long) v - 3;
57953- x = atomic_read(&cachefiles_lookup_histogram[index]);
57954- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57955- z = atomic_read(&cachefiles_create_histogram[index]);
57956+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57957+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57958+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57959 if (x == 0 && y == 0 && z == 0)
57960 return 0;
57961
57962diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57963index 4b1fb5c..0d2a699 100644
57964--- a/fs/cachefiles/rdwr.c
57965+++ b/fs/cachefiles/rdwr.c
57966@@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57967 old_fs = get_fs();
57968 set_fs(KERNEL_DS);
57969 ret = file->f_op->write(
57970- file, (const void __user *) data, len, &pos);
57971+ file, (const void __force_user *) data, len, &pos);
57972 set_fs(old_fs);
57973 kunmap(page);
57974 file_end_write(file);
57975diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57976index c29d6ae..a56c4ae 100644
57977--- a/fs/ceph/dir.c
57978+++ b/fs/ceph/dir.c
57979@@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57980 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57981 struct ceph_mds_client *mdsc = fsc->mdsc;
57982 unsigned frag = fpos_frag(ctx->pos);
57983- int off = fpos_off(ctx->pos);
57984+ unsigned int off = fpos_off(ctx->pos);
57985 int err;
57986 u32 ftype;
57987 struct ceph_mds_reply_info_parsed *rinfo;
57988diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57989index 06150fd..192061b 100644
57990--- a/fs/ceph/super.c
57991+++ b/fs/ceph/super.c
57992@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57993 /*
57994 * construct our own bdi so we can control readahead, etc.
57995 */
57996-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57997+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57998
57999 static int ceph_register_bdi(struct super_block *sb,
58000 struct ceph_fs_client *fsc)
58001@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
58002 default_backing_dev_info.ra_pages;
58003
58004 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
58005- atomic_long_inc_return(&bdi_seq));
58006+ atomic_long_inc_return_unchecked(&bdi_seq));
58007 if (!err)
58008 sb->s_bdi = &fsc->backing_dev_info;
58009 return err;
58010diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
58011index f3ac415..3d2420c 100644
58012--- a/fs/cifs/cifs_debug.c
58013+++ b/fs/cifs/cifs_debug.c
58014@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
58015
58016 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
58017 #ifdef CONFIG_CIFS_STATS2
58018- atomic_set(&totBufAllocCount, 0);
58019- atomic_set(&totSmBufAllocCount, 0);
58020+ atomic_set_unchecked(&totBufAllocCount, 0);
58021+ atomic_set_unchecked(&totSmBufAllocCount, 0);
58022 #endif /* CONFIG_CIFS_STATS2 */
58023 spin_lock(&cifs_tcp_ses_lock);
58024 list_for_each(tmp1, &cifs_tcp_ses_list) {
58025@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
58026 tcon = list_entry(tmp3,
58027 struct cifs_tcon,
58028 tcon_list);
58029- atomic_set(&tcon->num_smbs_sent, 0);
58030+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
58031 if (server->ops->clear_stats)
58032 server->ops->clear_stats(tcon);
58033 }
58034@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
58035 smBufAllocCount.counter, cifs_min_small);
58036 #ifdef CONFIG_CIFS_STATS2
58037 seq_printf(m, "Total Large %d Small %d Allocations\n",
58038- atomic_read(&totBufAllocCount),
58039- atomic_read(&totSmBufAllocCount));
58040+ atomic_read_unchecked(&totBufAllocCount),
58041+ atomic_read_unchecked(&totSmBufAllocCount));
58042 #endif /* CONFIG_CIFS_STATS2 */
58043
58044 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
58045@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
58046 if (tcon->need_reconnect)
58047 seq_puts(m, "\tDISCONNECTED ");
58048 seq_printf(m, "\nSMBs: %d",
58049- atomic_read(&tcon->num_smbs_sent));
58050+ atomic_read_unchecked(&tcon->num_smbs_sent));
58051 if (server->ops->print_stats)
58052 server->ops->print_stats(m, tcon);
58053 }
58054diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
58055index 5be1f997..fa1015a1 100644
58056--- a/fs/cifs/cifsfs.c
58057+++ b/fs/cifs/cifsfs.c
58058@@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
58059 */
58060 cifs_req_cachep = kmem_cache_create("cifs_request",
58061 CIFSMaxBufSize + max_hdr_size, 0,
58062- SLAB_HWCACHE_ALIGN, NULL);
58063+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
58064 if (cifs_req_cachep == NULL)
58065 return -ENOMEM;
58066
58067@@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
58068 efficient to alloc 1 per page off the slab compared to 17K (5page)
58069 alloc of large cifs buffers even when page debugging is on */
58070 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
58071- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
58072+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
58073 NULL);
58074 if (cifs_sm_req_cachep == NULL) {
58075 mempool_destroy(cifs_req_poolp);
58076@@ -1180,8 +1180,8 @@ init_cifs(void)
58077 atomic_set(&bufAllocCount, 0);
58078 atomic_set(&smBufAllocCount, 0);
58079 #ifdef CONFIG_CIFS_STATS2
58080- atomic_set(&totBufAllocCount, 0);
58081- atomic_set(&totSmBufAllocCount, 0);
58082+ atomic_set_unchecked(&totBufAllocCount, 0);
58083+ atomic_set_unchecked(&totSmBufAllocCount, 0);
58084 #endif /* CONFIG_CIFS_STATS2 */
58085
58086 atomic_set(&midCount, 0);
58087diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
58088index 30f6e92..e915ba5 100644
58089--- a/fs/cifs/cifsglob.h
58090+++ b/fs/cifs/cifsglob.h
58091@@ -806,35 +806,35 @@ struct cifs_tcon {
58092 __u16 Flags; /* optional support bits */
58093 enum statusEnum tidStatus;
58094 #ifdef CONFIG_CIFS_STATS
58095- atomic_t num_smbs_sent;
58096+ atomic_unchecked_t num_smbs_sent;
58097 union {
58098 struct {
58099- atomic_t num_writes;
58100- atomic_t num_reads;
58101- atomic_t num_flushes;
58102- atomic_t num_oplock_brks;
58103- atomic_t num_opens;
58104- atomic_t num_closes;
58105- atomic_t num_deletes;
58106- atomic_t num_mkdirs;
58107- atomic_t num_posixopens;
58108- atomic_t num_posixmkdirs;
58109- atomic_t num_rmdirs;
58110- atomic_t num_renames;
58111- atomic_t num_t2renames;
58112- atomic_t num_ffirst;
58113- atomic_t num_fnext;
58114- atomic_t num_fclose;
58115- atomic_t num_hardlinks;
58116- atomic_t num_symlinks;
58117- atomic_t num_locks;
58118- atomic_t num_acl_get;
58119- atomic_t num_acl_set;
58120+ atomic_unchecked_t num_writes;
58121+ atomic_unchecked_t num_reads;
58122+ atomic_unchecked_t num_flushes;
58123+ atomic_unchecked_t num_oplock_brks;
58124+ atomic_unchecked_t num_opens;
58125+ atomic_unchecked_t num_closes;
58126+ atomic_unchecked_t num_deletes;
58127+ atomic_unchecked_t num_mkdirs;
58128+ atomic_unchecked_t num_posixopens;
58129+ atomic_unchecked_t num_posixmkdirs;
58130+ atomic_unchecked_t num_rmdirs;
58131+ atomic_unchecked_t num_renames;
58132+ atomic_unchecked_t num_t2renames;
58133+ atomic_unchecked_t num_ffirst;
58134+ atomic_unchecked_t num_fnext;
58135+ atomic_unchecked_t num_fclose;
58136+ atomic_unchecked_t num_hardlinks;
58137+ atomic_unchecked_t num_symlinks;
58138+ atomic_unchecked_t num_locks;
58139+ atomic_unchecked_t num_acl_get;
58140+ atomic_unchecked_t num_acl_set;
58141 } cifs_stats;
58142 #ifdef CONFIG_CIFS_SMB2
58143 struct {
58144- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58145- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58146+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58147+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58148 } smb2_stats;
58149 #endif /* CONFIG_CIFS_SMB2 */
58150 } stats;
58151@@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
58152 }
58153
58154 #ifdef CONFIG_CIFS_STATS
58155-#define cifs_stats_inc atomic_inc
58156+#define cifs_stats_inc atomic_inc_unchecked
58157
58158 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58159 unsigned int bytes)
58160@@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58161 /* Various Debug counters */
58162 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58163 #ifdef CONFIG_CIFS_STATS2
58164-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58165-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58166+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58167+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58168 #endif
58169 GLOBAL_EXTERN atomic_t smBufAllocCount;
58170 GLOBAL_EXTERN atomic_t midCount;
58171diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58172index 5ed03e0..e9a3a6c 100644
58173--- a/fs/cifs/file.c
58174+++ b/fs/cifs/file.c
58175@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58176 index = mapping->writeback_index; /* Start from prev offset */
58177 end = -1;
58178 } else {
58179- index = wbc->range_start >> PAGE_CACHE_SHIFT;
58180- end = wbc->range_end >> PAGE_CACHE_SHIFT;
58181- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58182+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58183 range_whole = true;
58184+ index = 0;
58185+ end = ULONG_MAX;
58186+ } else {
58187+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
58188+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
58189+ }
58190 scanned = true;
58191 }
58192 retry:
58193diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58194index 3b0c62e..f7d090c 100644
58195--- a/fs/cifs/misc.c
58196+++ b/fs/cifs/misc.c
58197@@ -170,7 +170,7 @@ cifs_buf_get(void)
58198 memset(ret_buf, 0, buf_size + 3);
58199 atomic_inc(&bufAllocCount);
58200 #ifdef CONFIG_CIFS_STATS2
58201- atomic_inc(&totBufAllocCount);
58202+ atomic_inc_unchecked(&totBufAllocCount);
58203 #endif /* CONFIG_CIFS_STATS2 */
58204 }
58205
58206@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58207 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58208 atomic_inc(&smBufAllocCount);
58209 #ifdef CONFIG_CIFS_STATS2
58210- atomic_inc(&totSmBufAllocCount);
58211+ atomic_inc_unchecked(&totSmBufAllocCount);
58212 #endif /* CONFIG_CIFS_STATS2 */
58213
58214 }
58215diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58216index d1fdfa8..94558f8 100644
58217--- a/fs/cifs/smb1ops.c
58218+++ b/fs/cifs/smb1ops.c
58219@@ -626,27 +626,27 @@ static void
58220 cifs_clear_stats(struct cifs_tcon *tcon)
58221 {
58222 #ifdef CONFIG_CIFS_STATS
58223- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58224- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58225- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58226- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58227- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58228- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58229- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58230- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58231- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58232- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58233- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58234- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58235- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58236- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58237- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58238- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58239- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58240- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58241- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58242- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58243- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58244+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58245+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58246+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58247+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58248+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58249+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58250+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58251+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58252+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58253+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58254+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58255+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58256+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58257+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58258+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58259+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58260+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58261+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58262+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58263+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58264+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58265 #endif
58266 }
58267
58268@@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58269 {
58270 #ifdef CONFIG_CIFS_STATS
58271 seq_printf(m, " Oplocks breaks: %d",
58272- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58273+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58274 seq_printf(m, "\nReads: %d Bytes: %llu",
58275- atomic_read(&tcon->stats.cifs_stats.num_reads),
58276+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58277 (long long)(tcon->bytes_read));
58278 seq_printf(m, "\nWrites: %d Bytes: %llu",
58279- atomic_read(&tcon->stats.cifs_stats.num_writes),
58280+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58281 (long long)(tcon->bytes_written));
58282 seq_printf(m, "\nFlushes: %d",
58283- atomic_read(&tcon->stats.cifs_stats.num_flushes));
58284+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58285 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58286- atomic_read(&tcon->stats.cifs_stats.num_locks),
58287- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58288- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58289+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58290+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58291+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58292 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58293- atomic_read(&tcon->stats.cifs_stats.num_opens),
58294- atomic_read(&tcon->stats.cifs_stats.num_closes),
58295- atomic_read(&tcon->stats.cifs_stats.num_deletes));
58296+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58297+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58298+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58299 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58300- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58301- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58302+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58303+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58304 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58305- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58306- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58307+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58308+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58309 seq_printf(m, "\nRenames: %d T2 Renames %d",
58310- atomic_read(&tcon->stats.cifs_stats.num_renames),
58311- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58312+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58313+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58314 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58315- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58316- atomic_read(&tcon->stats.cifs_stats.num_fnext),
58317- atomic_read(&tcon->stats.cifs_stats.num_fclose));
58318+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58319+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58320+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58321 #endif
58322 }
58323
58324diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58325index 35ddc3e..563e809 100644
58326--- a/fs/cifs/smb2ops.c
58327+++ b/fs/cifs/smb2ops.c
58328@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58329 #ifdef CONFIG_CIFS_STATS
58330 int i;
58331 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58332- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58333- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58334+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58335+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58336 }
58337 #endif
58338 }
58339@@ -405,65 +405,65 @@ static void
58340 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58341 {
58342 #ifdef CONFIG_CIFS_STATS
58343- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58344- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58345+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58346+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58347 seq_printf(m, "\nNegotiates: %d sent %d failed",
58348- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58349- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58350+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58351+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58352 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58353- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58354- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58355+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58356+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58357 seq_printf(m, "\nLogoffs: %d sent %d failed",
58358- atomic_read(&sent[SMB2_LOGOFF_HE]),
58359- atomic_read(&failed[SMB2_LOGOFF_HE]));
58360+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58361+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58362 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58363- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58364- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58365+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58366+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58367 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58368- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58369- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58370+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58371+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58372 seq_printf(m, "\nCreates: %d sent %d failed",
58373- atomic_read(&sent[SMB2_CREATE_HE]),
58374- atomic_read(&failed[SMB2_CREATE_HE]));
58375+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58376+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58377 seq_printf(m, "\nCloses: %d sent %d failed",
58378- atomic_read(&sent[SMB2_CLOSE_HE]),
58379- atomic_read(&failed[SMB2_CLOSE_HE]));
58380+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58381+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58382 seq_printf(m, "\nFlushes: %d sent %d failed",
58383- atomic_read(&sent[SMB2_FLUSH_HE]),
58384- atomic_read(&failed[SMB2_FLUSH_HE]));
58385+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58386+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58387 seq_printf(m, "\nReads: %d sent %d failed",
58388- atomic_read(&sent[SMB2_READ_HE]),
58389- atomic_read(&failed[SMB2_READ_HE]));
58390+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
58391+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
58392 seq_printf(m, "\nWrites: %d sent %d failed",
58393- atomic_read(&sent[SMB2_WRITE_HE]),
58394- atomic_read(&failed[SMB2_WRITE_HE]));
58395+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58396+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58397 seq_printf(m, "\nLocks: %d sent %d failed",
58398- atomic_read(&sent[SMB2_LOCK_HE]),
58399- atomic_read(&failed[SMB2_LOCK_HE]));
58400+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58401+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58402 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58403- atomic_read(&sent[SMB2_IOCTL_HE]),
58404- atomic_read(&failed[SMB2_IOCTL_HE]));
58405+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58406+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58407 seq_printf(m, "\nCancels: %d sent %d failed",
58408- atomic_read(&sent[SMB2_CANCEL_HE]),
58409- atomic_read(&failed[SMB2_CANCEL_HE]));
58410+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58411+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58412 seq_printf(m, "\nEchos: %d sent %d failed",
58413- atomic_read(&sent[SMB2_ECHO_HE]),
58414- atomic_read(&failed[SMB2_ECHO_HE]));
58415+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58416+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58417 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58418- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58419- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58420+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58421+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58422 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58423- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58424- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58425+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58426+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58427 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58428- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58429- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58430+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58431+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58432 seq_printf(m, "\nSetInfos: %d sent %d failed",
58433- atomic_read(&sent[SMB2_SET_INFO_HE]),
58434- atomic_read(&failed[SMB2_SET_INFO_HE]));
58435+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58436+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58437 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58438- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58439- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58440+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58441+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58442 #endif
58443 }
58444
58445diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58446index 1fb6ad2..758e171 100644
58447--- a/fs/cifs/smb2pdu.c
58448+++ b/fs/cifs/smb2pdu.c
58449@@ -2097,8 +2097,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58450 default:
58451 cifs_dbg(VFS, "info level %u isn't supported\n",
58452 srch_inf->info_level);
58453- rc = -EINVAL;
58454- goto qdir_exit;
58455+ return -EINVAL;
58456 }
58457
58458 req->FileIndex = cpu_to_le32(index);
58459diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58460index 1da168c..8bc7ff6 100644
58461--- a/fs/coda/cache.c
58462+++ b/fs/coda/cache.c
58463@@ -24,7 +24,7 @@
58464 #include "coda_linux.h"
58465 #include "coda_cache.h"
58466
58467-static atomic_t permission_epoch = ATOMIC_INIT(0);
58468+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58469
58470 /* replace or extend an acl cache hit */
58471 void coda_cache_enter(struct inode *inode, int mask)
58472@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58473 struct coda_inode_info *cii = ITOC(inode);
58474
58475 spin_lock(&cii->c_lock);
58476- cii->c_cached_epoch = atomic_read(&permission_epoch);
58477+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58478 if (!uid_eq(cii->c_uid, current_fsuid())) {
58479 cii->c_uid = current_fsuid();
58480 cii->c_cached_perm = mask;
58481@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58482 {
58483 struct coda_inode_info *cii = ITOC(inode);
58484 spin_lock(&cii->c_lock);
58485- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58486+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58487 spin_unlock(&cii->c_lock);
58488 }
58489
58490 /* remove all acl caches */
58491 void coda_cache_clear_all(struct super_block *sb)
58492 {
58493- atomic_inc(&permission_epoch);
58494+ atomic_inc_unchecked(&permission_epoch);
58495 }
58496
58497
58498@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58499 spin_lock(&cii->c_lock);
58500 hit = (mask & cii->c_cached_perm) == mask &&
58501 uid_eq(cii->c_uid, current_fsuid()) &&
58502- cii->c_cached_epoch == atomic_read(&permission_epoch);
58503+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58504 spin_unlock(&cii->c_lock);
58505
58506 return hit;
58507diff --git a/fs/compat.c b/fs/compat.c
58508index 66d3d3c..9c10175 100644
58509--- a/fs/compat.c
58510+++ b/fs/compat.c
58511@@ -54,7 +54,7 @@
58512 #include <asm/ioctls.h>
58513 #include "internal.h"
58514
58515-int compat_log = 1;
58516+int compat_log = 0;
58517
58518 int compat_printk(const char *fmt, ...)
58519 {
58520@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
58521
58522 set_fs(KERNEL_DS);
58523 /* The __user pointer cast is valid because of the set_fs() */
58524- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58525+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58526 set_fs(oldfs);
58527 /* truncating is ok because it's a user address */
58528 if (!ret)
58529@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58530 goto out;
58531
58532 ret = -EINVAL;
58533- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58534+ if (nr_segs > UIO_MAXIOV)
58535 goto out;
58536 if (nr_segs > fast_segs) {
58537 ret = -ENOMEM;
58538@@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
58539 struct compat_readdir_callback {
58540 struct dir_context ctx;
58541 struct compat_old_linux_dirent __user *dirent;
58542+ struct file * file;
58543 int result;
58544 };
58545
58546@@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58547 buf->result = -EOVERFLOW;
58548 return -EOVERFLOW;
58549 }
58550+
58551+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58552+ return 0;
58553+
58554 buf->result++;
58555 dirent = buf->dirent;
58556 if (!access_ok(VERIFY_WRITE, dirent,
58557@@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58558 if (!f.file)
58559 return -EBADF;
58560
58561+ buf.file = f.file;
58562 error = iterate_dir(f.file, &buf.ctx);
58563 if (buf.result)
58564 error = buf.result;
58565@@ -917,6 +923,7 @@ struct compat_getdents_callback {
58566 struct dir_context ctx;
58567 struct compat_linux_dirent __user *current_dir;
58568 struct compat_linux_dirent __user *previous;
58569+ struct file * file;
58570 int count;
58571 int error;
58572 };
58573@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58574 buf->error = -EOVERFLOW;
58575 return -EOVERFLOW;
58576 }
58577+
58578+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58579+ return 0;
58580+
58581 dirent = buf->previous;
58582 if (dirent) {
58583 if (__put_user(offset, &dirent->d_off))
58584@@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58585 if (!f.file)
58586 return -EBADF;
58587
58588+ buf.file = f.file;
58589 error = iterate_dir(f.file, &buf.ctx);
58590 if (error >= 0)
58591 error = buf.error;
58592@@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58593 struct dir_context ctx;
58594 struct linux_dirent64 __user *current_dir;
58595 struct linux_dirent64 __user *previous;
58596+ struct file * file;
58597 int count;
58598 int error;
58599 };
58600@@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58601 buf->error = -EINVAL; /* only used if we fail.. */
58602 if (reclen > buf->count)
58603 return -EINVAL;
58604+
58605+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58606+ return 0;
58607+
58608 dirent = buf->previous;
58609
58610 if (dirent) {
58611@@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58612 if (!f.file)
58613 return -EBADF;
58614
58615+ buf.file = f.file;
58616 error = iterate_dir(f.file, &buf.ctx);
58617 if (error >= 0)
58618 error = buf.error;
58619diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58620index 4d24d17..4f8c09e 100644
58621--- a/fs/compat_binfmt_elf.c
58622+++ b/fs/compat_binfmt_elf.c
58623@@ -30,11 +30,13 @@
58624 #undef elf_phdr
58625 #undef elf_shdr
58626 #undef elf_note
58627+#undef elf_dyn
58628 #undef elf_addr_t
58629 #define elfhdr elf32_hdr
58630 #define elf_phdr elf32_phdr
58631 #define elf_shdr elf32_shdr
58632 #define elf_note elf32_note
58633+#define elf_dyn Elf32_Dyn
58634 #define elf_addr_t Elf32_Addr
58635
58636 /*
58637diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58638index e822890..fed89d9 100644
58639--- a/fs/compat_ioctl.c
58640+++ b/fs/compat_ioctl.c
58641@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58642 return -EFAULT;
58643 if (__get_user(udata, &ss32->iomem_base))
58644 return -EFAULT;
58645- ss.iomem_base = compat_ptr(udata);
58646+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58647 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58648 __get_user(ss.port_high, &ss32->port_high))
58649 return -EFAULT;
58650@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58651 for (i = 0; i < nmsgs; i++) {
58652 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58653 return -EFAULT;
58654- if (get_user(datap, &umsgs[i].buf) ||
58655- put_user(compat_ptr(datap), &tmsgs[i].buf))
58656+ if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
58657+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58658 return -EFAULT;
58659 }
58660 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58661@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58662 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58663 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58664 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58665- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58666+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58667 return -EFAULT;
58668
58669 return ioctl_preallocate(file, p);
58670@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58671 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58672 {
58673 unsigned int a, b;
58674- a = *(unsigned int *)p;
58675- b = *(unsigned int *)q;
58676+ a = *(const unsigned int *)p;
58677+ b = *(const unsigned int *)q;
58678 if (a > b)
58679 return 1;
58680 if (a < b)
58681diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58682index e081acb..911df21 100644
58683--- a/fs/configfs/dir.c
58684+++ b/fs/configfs/dir.c
58685@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58686 }
58687 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58688 struct configfs_dirent *next;
58689- const char *name;
58690+ const unsigned char * name;
58691+ char d_name[sizeof(next->s_dentry->d_iname)];
58692 int len;
58693 struct inode *inode = NULL;
58694
58695@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58696 continue;
58697
58698 name = configfs_get_name(next);
58699- len = strlen(name);
58700+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58701+ len = next->s_dentry->d_name.len;
58702+ memcpy(d_name, name, len);
58703+ name = d_name;
58704+ } else
58705+ len = strlen(name);
58706
58707 /*
58708 * We'll have a dentry and an inode for
58709diff --git a/fs/coredump.c b/fs/coredump.c
58710index a93f7e6..d58bcbe 100644
58711--- a/fs/coredump.c
58712+++ b/fs/coredump.c
58713@@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58714 struct pipe_inode_info *pipe = file->private_data;
58715
58716 pipe_lock(pipe);
58717- pipe->readers++;
58718- pipe->writers--;
58719+ atomic_inc(&pipe->readers);
58720+ atomic_dec(&pipe->writers);
58721 wake_up_interruptible_sync(&pipe->wait);
58722 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58723 pipe_unlock(pipe);
58724@@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58725 * We actually want wait_event_freezable() but then we need
58726 * to clear TIF_SIGPENDING and improve dump_interrupted().
58727 */
58728- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58729+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58730
58731 pipe_lock(pipe);
58732- pipe->readers--;
58733- pipe->writers++;
58734+ atomic_dec(&pipe->readers);
58735+ atomic_inc(&pipe->writers);
58736 pipe_unlock(pipe);
58737 }
58738
58739@@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58740 struct files_struct *displaced;
58741 bool need_nonrelative = false;
58742 bool core_dumped = false;
58743- static atomic_t core_dump_count = ATOMIC_INIT(0);
58744+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58745+ long signr = siginfo->si_signo;
58746+ int dumpable;
58747 struct coredump_params cprm = {
58748 .siginfo = siginfo,
58749 .regs = signal_pt_regs(),
58750@@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58751 .mm_flags = mm->flags,
58752 };
58753
58754- audit_core_dumps(siginfo->si_signo);
58755+ audit_core_dumps(signr);
58756+
58757+ dumpable = __get_dumpable(cprm.mm_flags);
58758+
58759+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58760+ gr_handle_brute_attach(dumpable);
58761
58762 binfmt = mm->binfmt;
58763 if (!binfmt || !binfmt->core_dump)
58764 goto fail;
58765- if (!__get_dumpable(cprm.mm_flags))
58766+ if (!dumpable)
58767 goto fail;
58768
58769 cred = prepare_creds();
58770@@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58771 need_nonrelative = true;
58772 }
58773
58774- retval = coredump_wait(siginfo->si_signo, &core_state);
58775+ retval = coredump_wait(signr, &core_state);
58776 if (retval < 0)
58777 goto fail_creds;
58778
58779@@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58780 }
58781 cprm.limit = RLIM_INFINITY;
58782
58783- dump_count = atomic_inc_return(&core_dump_count);
58784+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58785 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58786 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58787 task_tgid_vnr(current), current->comm);
58788@@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58789 } else {
58790 struct inode *inode;
58791
58792+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58793+
58794 if (cprm.limit < binfmt->min_coredump)
58795 goto fail_unlock;
58796
58797@@ -673,7 +682,7 @@ close_fail:
58798 filp_close(cprm.file, NULL);
58799 fail_dropcount:
58800 if (ispipe)
58801- atomic_dec(&core_dump_count);
58802+ atomic_dec_unchecked(&core_dump_count);
58803 fail_unlock:
58804 kfree(cn.corename);
58805 coredump_finish(mm, core_dumped);
58806@@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58807 struct file *file = cprm->file;
58808 loff_t pos = file->f_pos;
58809 ssize_t n;
58810+
58811+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58812 if (cprm->written + nr > cprm->limit)
58813 return 0;
58814 while (nr) {
58815diff --git a/fs/dcache.c b/fs/dcache.c
58816index e99c6f5..2838bf58 100644
58817--- a/fs/dcache.c
58818+++ b/fs/dcache.c
58819@@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58820 */
58821 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58822 if (name->len > DNAME_INLINE_LEN-1) {
58823- dname = kmalloc(name->len + 1, GFP_KERNEL);
58824+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58825 if (!dname) {
58826 kmem_cache_free(dentry_cache, dentry);
58827 return NULL;
58828@@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58829 mempages -= reserve;
58830
58831 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58832- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58833+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58834+ SLAB_NO_SANITIZE, NULL);
58835
58836 dcache_init();
58837 inode_init();
58838diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58839index 8c41b52..145b1b9 100644
58840--- a/fs/debugfs/inode.c
58841+++ b/fs/debugfs/inode.c
58842@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58843 */
58844 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58845 {
58846+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58847+ return __create_file(name, S_IFDIR | S_IRWXU,
58848+#else
58849 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58850+#endif
58851 parent, NULL, NULL);
58852 }
58853 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58854diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58855index d4a9431..77f9b2e 100644
58856--- a/fs/ecryptfs/inode.c
58857+++ b/fs/ecryptfs/inode.c
58858@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58859 old_fs = get_fs();
58860 set_fs(get_ds());
58861 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58862- (char __user *)lower_buf,
58863+ (char __force_user *)lower_buf,
58864 PATH_MAX);
58865 set_fs(old_fs);
58866 if (rc < 0)
58867diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58868index e4141f2..d8263e8 100644
58869--- a/fs/ecryptfs/miscdev.c
58870+++ b/fs/ecryptfs/miscdev.c
58871@@ -304,7 +304,7 @@ check_list:
58872 goto out_unlock_msg_ctx;
58873 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58874 if (msg_ctx->msg) {
58875- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58876+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58877 goto out_unlock_msg_ctx;
58878 i += packet_length_size;
58879 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58880diff --git a/fs/exec.c b/fs/exec.c
58881index 238b7aa..a421d91 100644
58882--- a/fs/exec.c
58883+++ b/fs/exec.c
58884@@ -56,8 +56,20 @@
58885 #include <linux/pipe_fs_i.h>
58886 #include <linux/oom.h>
58887 #include <linux/compat.h>
58888+#include <linux/random.h>
58889+#include <linux/seq_file.h>
58890+#include <linux/coredump.h>
58891+#include <linux/mman.h>
58892+
58893+#ifdef CONFIG_PAX_REFCOUNT
58894+#include <linux/kallsyms.h>
58895+#include <linux/kdebug.h>
58896+#endif
58897+
58898+#include <trace/events/fs.h>
58899
58900 #include <asm/uaccess.h>
58901+#include <asm/sections.h>
58902 #include <asm/mmu_context.h>
58903 #include <asm/tlb.h>
58904
58905@@ -66,19 +78,34 @@
58906
58907 #include <trace/events/sched.h>
58908
58909+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58910+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58911+{
58912+ 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");
58913+}
58914+#endif
58915+
58916+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58917+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58918+EXPORT_SYMBOL(pax_set_initial_flags_func);
58919+#endif
58920+
58921 int suid_dumpable = 0;
58922
58923 static LIST_HEAD(formats);
58924 static DEFINE_RWLOCK(binfmt_lock);
58925
58926+extern int gr_process_kernel_exec_ban(void);
58927+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58928+
58929 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58930 {
58931 BUG_ON(!fmt);
58932 if (WARN_ON(!fmt->load_binary))
58933 return;
58934 write_lock(&binfmt_lock);
58935- insert ? list_add(&fmt->lh, &formats) :
58936- list_add_tail(&fmt->lh, &formats);
58937+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58938+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58939 write_unlock(&binfmt_lock);
58940 }
58941
58942@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58943 void unregister_binfmt(struct linux_binfmt * fmt)
58944 {
58945 write_lock(&binfmt_lock);
58946- list_del(&fmt->lh);
58947+ pax_list_del((struct list_head *)&fmt->lh);
58948 write_unlock(&binfmt_lock);
58949 }
58950
58951@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58952 int write)
58953 {
58954 struct page *page;
58955- int ret;
58956
58957-#ifdef CONFIG_STACK_GROWSUP
58958- if (write) {
58959- ret = expand_downwards(bprm->vma, pos);
58960- if (ret < 0)
58961- return NULL;
58962- }
58963-#endif
58964- ret = get_user_pages(current, bprm->mm, pos,
58965- 1, write, 1, &page, NULL);
58966- if (ret <= 0)
58967+ if (0 > expand_downwards(bprm->vma, pos))
58968+ return NULL;
58969+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58970 return NULL;
58971
58972 if (write) {
58973@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58974 if (size <= ARG_MAX)
58975 return page;
58976
58977+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58978+ // only allow 512KB for argv+env on suid/sgid binaries
58979+ // to prevent easy ASLR exhaustion
58980+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58981+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58982+ (size > (512 * 1024))) {
58983+ put_page(page);
58984+ return NULL;
58985+ }
58986+#endif
58987+
58988 /*
58989 * Limit to 1/4-th the stack size for the argv+env strings.
58990 * This ensures that:
58991@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58992 vma->vm_end = STACK_TOP_MAX;
58993 vma->vm_start = vma->vm_end - PAGE_SIZE;
58994 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58995+
58996+#ifdef CONFIG_PAX_SEGMEXEC
58997+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58998+#endif
58999+
59000 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
59001 INIT_LIST_HEAD(&vma->anon_vma_chain);
59002
59003@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
59004 mm->stack_vm = mm->total_vm = 1;
59005 up_write(&mm->mmap_sem);
59006 bprm->p = vma->vm_end - sizeof(void *);
59007+
59008+#ifdef CONFIG_PAX_RANDUSTACK
59009+ if (randomize_va_space)
59010+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
59011+#endif
59012+
59013 return 0;
59014 err:
59015 up_write(&mm->mmap_sem);
59016@@ -399,7 +440,7 @@ struct user_arg_ptr {
59017 } ptr;
59018 };
59019
59020-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
59021+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
59022 {
59023 const char __user *native;
59024
59025@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
59026 compat_uptr_t compat;
59027
59028 if (get_user(compat, argv.ptr.compat + nr))
59029- return ERR_PTR(-EFAULT);
59030+ return (const char __force_user *)ERR_PTR(-EFAULT);
59031
59032 return compat_ptr(compat);
59033 }
59034 #endif
59035
59036 if (get_user(native, argv.ptr.native + nr))
59037- return ERR_PTR(-EFAULT);
59038+ return (const char __force_user *)ERR_PTR(-EFAULT);
59039
59040 return native;
59041 }
59042@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
59043 if (!p)
59044 break;
59045
59046- if (IS_ERR(p))
59047+ if (IS_ERR((const char __force_kernel *)p))
59048 return -EFAULT;
59049
59050 if (i >= max)
59051@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
59052
59053 ret = -EFAULT;
59054 str = get_user_arg_ptr(argv, argc);
59055- if (IS_ERR(str))
59056+ if (IS_ERR((const char __force_kernel *)str))
59057 goto out;
59058
59059 len = strnlen_user(str, MAX_ARG_STRLEN);
59060@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
59061 int r;
59062 mm_segment_t oldfs = get_fs();
59063 struct user_arg_ptr argv = {
59064- .ptr.native = (const char __user *const __user *)__argv,
59065+ .ptr.native = (const char __user * const __force_user *)__argv,
59066 };
59067
59068 set_fs(KERNEL_DS);
59069@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59070 unsigned long new_end = old_end - shift;
59071 struct mmu_gather tlb;
59072
59073- BUG_ON(new_start > new_end);
59074+ if (new_start >= new_end || new_start < mmap_min_addr)
59075+ return -ENOMEM;
59076
59077 /*
59078 * ensure there are no vmas between where we want to go
59079@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59080 if (vma != find_vma(mm, new_start))
59081 return -EFAULT;
59082
59083+#ifdef CONFIG_PAX_SEGMEXEC
59084+ BUG_ON(pax_find_mirror_vma(vma));
59085+#endif
59086+
59087 /*
59088 * cover the whole range: [new_start, old_end)
59089 */
59090@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59091 stack_top = arch_align_stack(stack_top);
59092 stack_top = PAGE_ALIGN(stack_top);
59093
59094- if (unlikely(stack_top < mmap_min_addr) ||
59095- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
59096- return -ENOMEM;
59097-
59098 stack_shift = vma->vm_end - stack_top;
59099
59100 bprm->p -= stack_shift;
59101@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
59102 bprm->exec -= stack_shift;
59103
59104 down_write(&mm->mmap_sem);
59105+
59106+ /* Move stack pages down in memory. */
59107+ if (stack_shift) {
59108+ ret = shift_arg_pages(vma, stack_shift);
59109+ if (ret)
59110+ goto out_unlock;
59111+ }
59112+
59113 vm_flags = VM_STACK_FLAGS;
59114
59115+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59116+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59117+ vm_flags &= ~VM_EXEC;
59118+
59119+#ifdef CONFIG_PAX_MPROTECT
59120+ if (mm->pax_flags & MF_PAX_MPROTECT)
59121+ vm_flags &= ~VM_MAYEXEC;
59122+#endif
59123+
59124+ }
59125+#endif
59126+
59127 /*
59128 * Adjust stack execute permissions; explicitly enable for
59129 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59130@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59131 goto out_unlock;
59132 BUG_ON(prev != vma);
59133
59134- /* Move stack pages down in memory. */
59135- if (stack_shift) {
59136- ret = shift_arg_pages(vma, stack_shift);
59137- if (ret)
59138- goto out_unlock;
59139- }
59140-
59141 /* mprotect_fixup is overkill to remove the temporary stack flags */
59142 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59143
59144@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59145 #endif
59146 current->mm->start_stack = bprm->p;
59147 ret = expand_stack(vma, stack_base);
59148+
59149+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59150+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59151+ unsigned long size;
59152+ vm_flags_t vm_flags;
59153+
59154+ size = STACK_TOP - vma->vm_end;
59155+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59156+
59157+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59158+
59159+#ifdef CONFIG_X86
59160+ if (!ret) {
59161+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59162+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59163+ }
59164+#endif
59165+
59166+ }
59167+#endif
59168+
59169 if (ret)
59170 ret = -EFAULT;
59171
59172@@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
59173
59174 fsnotify_open(file);
59175
59176+ trace_open_exec(name->name);
59177+
59178 err = deny_write_access(file);
59179 if (err)
59180 goto exit;
59181@@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
59182 old_fs = get_fs();
59183 set_fs(get_ds());
59184 /* The cast to a user pointer is valid due to the set_fs() */
59185- result = vfs_read(file, (void __user *)addr, count, &pos);
59186+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
59187 set_fs(old_fs);
59188 return result;
59189 }
59190@@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
59191 tsk->mm = mm;
59192 tsk->active_mm = mm;
59193 activate_mm(active_mm, mm);
59194+ populate_stack();
59195 tsk->mm->vmacache_seqnum = 0;
59196 vmacache_flush(tsk);
59197 task_unlock(tsk);
59198@@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59199 }
59200 rcu_read_unlock();
59201
59202- if (p->fs->users > n_fs)
59203+ if (atomic_read(&p->fs->users) > n_fs)
59204 bprm->unsafe |= LSM_UNSAFE_SHARE;
59205 else
59206 p->fs->in_exec = 1;
59207@@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59208 return ret;
59209 }
59210
59211+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59212+static DEFINE_PER_CPU(u64, exec_counter);
59213+static int __init init_exec_counters(void)
59214+{
59215+ unsigned int cpu;
59216+
59217+ for_each_possible_cpu(cpu) {
59218+ per_cpu(exec_counter, cpu) = (u64)cpu;
59219+ }
59220+
59221+ return 0;
59222+}
59223+early_initcall(init_exec_counters);
59224+static inline void increment_exec_counter(void)
59225+{
59226+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
59227+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59228+}
59229+#else
59230+static inline void increment_exec_counter(void) {}
59231+#endif
59232+
59233+extern void gr_handle_exec_args(struct linux_binprm *bprm,
59234+ struct user_arg_ptr argv);
59235+
59236 /*
59237 * sys_execve() executes a new program.
59238 */
59239@@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
59240 struct user_arg_ptr argv,
59241 struct user_arg_ptr envp)
59242 {
59243+#ifdef CONFIG_GRKERNSEC
59244+ struct file *old_exec_file;
59245+ struct acl_subject_label *old_acl;
59246+ struct rlimit old_rlim[RLIM_NLIMITS];
59247+#endif
59248 struct linux_binprm *bprm;
59249 struct file *file;
59250 struct files_struct *displaced;
59251@@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
59252 if (IS_ERR(filename))
59253 return PTR_ERR(filename);
59254
59255+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59256+
59257 /*
59258 * We move the actual failure in case of RLIMIT_NPROC excess from
59259 * set*uid() to execve() because too many poorly written programs
59260@@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
59261 if (IS_ERR(file))
59262 goto out_unmark;
59263
59264+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
59265+ retval = -EPERM;
59266+ goto out_unmark;
59267+ }
59268+
59269 sched_exec();
59270
59271 bprm->file = file;
59272 bprm->filename = bprm->interp = filename->name;
59273
59274+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59275+ retval = -EACCES;
59276+ goto out_unmark;
59277+ }
59278+
59279 retval = bprm_mm_init(bprm);
59280 if (retval)
59281 goto out_unmark;
59282@@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
59283 if (retval < 0)
59284 goto out;
59285
59286+#ifdef CONFIG_GRKERNSEC
59287+ old_acl = current->acl;
59288+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59289+ old_exec_file = current->exec_file;
59290+ get_file(file);
59291+ current->exec_file = file;
59292+#endif
59293+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59294+ /* limit suid stack to 8MB
59295+ * we saved the old limits above and will restore them if this exec fails
59296+ */
59297+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59298+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59299+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59300+#endif
59301+
59302+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59303+ retval = -EPERM;
59304+ goto out_fail;
59305+ }
59306+
59307+ if (!gr_tpe_allow(file)) {
59308+ retval = -EACCES;
59309+ goto out_fail;
59310+ }
59311+
59312+ if (gr_check_crash_exec(file)) {
59313+ retval = -EACCES;
59314+ goto out_fail;
59315+ }
59316+
59317+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59318+ bprm->unsafe);
59319+ if (retval < 0)
59320+ goto out_fail;
59321+
59322 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59323 if (retval < 0)
59324- goto out;
59325+ goto out_fail;
59326
59327 bprm->exec = bprm->p;
59328 retval = copy_strings(bprm->envc, envp, bprm);
59329 if (retval < 0)
59330- goto out;
59331+ goto out_fail;
59332
59333 retval = copy_strings(bprm->argc, argv, bprm);
59334 if (retval < 0)
59335- goto out;
59336+ goto out_fail;
59337+
59338+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59339+
59340+ gr_handle_exec_args(bprm, argv);
59341
59342 retval = exec_binprm(bprm);
59343 if (retval < 0)
59344- goto out;
59345+ goto out_fail;
59346+#ifdef CONFIG_GRKERNSEC
59347+ if (old_exec_file)
59348+ fput(old_exec_file);
59349+#endif
59350
59351 /* execve succeeded */
59352+
59353+ increment_exec_counter();
59354 current->fs->in_exec = 0;
59355 current->in_execve = 0;
59356 acct_update_integrals(current);
59357@@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
59358 put_files_struct(displaced);
59359 return retval;
59360
59361+out_fail:
59362+#ifdef CONFIG_GRKERNSEC
59363+ current->acl = old_acl;
59364+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59365+ fput(current->exec_file);
59366+ current->exec_file = old_exec_file;
59367+#endif
59368+
59369 out:
59370 if (bprm->mm) {
59371 acct_arg_size(bprm, 0);
59372@@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
59373 return compat_do_execve(getname(filename), argv, envp);
59374 }
59375 #endif
59376+
59377+int pax_check_flags(unsigned long *flags)
59378+{
59379+ int retval = 0;
59380+
59381+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59382+ if (*flags & MF_PAX_SEGMEXEC)
59383+ {
59384+ *flags &= ~MF_PAX_SEGMEXEC;
59385+ retval = -EINVAL;
59386+ }
59387+#endif
59388+
59389+ if ((*flags & MF_PAX_PAGEEXEC)
59390+
59391+#ifdef CONFIG_PAX_PAGEEXEC
59392+ && (*flags & MF_PAX_SEGMEXEC)
59393+#endif
59394+
59395+ )
59396+ {
59397+ *flags &= ~MF_PAX_PAGEEXEC;
59398+ retval = -EINVAL;
59399+ }
59400+
59401+ if ((*flags & MF_PAX_MPROTECT)
59402+
59403+#ifdef CONFIG_PAX_MPROTECT
59404+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59405+#endif
59406+
59407+ )
59408+ {
59409+ *flags &= ~MF_PAX_MPROTECT;
59410+ retval = -EINVAL;
59411+ }
59412+
59413+ if ((*flags & MF_PAX_EMUTRAMP)
59414+
59415+#ifdef CONFIG_PAX_EMUTRAMP
59416+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59417+#endif
59418+
59419+ )
59420+ {
59421+ *flags &= ~MF_PAX_EMUTRAMP;
59422+ retval = -EINVAL;
59423+ }
59424+
59425+ return retval;
59426+}
59427+
59428+EXPORT_SYMBOL(pax_check_flags);
59429+
59430+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59431+char *pax_get_path(const struct path *path, char *buf, int buflen)
59432+{
59433+ char *pathname = d_path(path, buf, buflen);
59434+
59435+ if (IS_ERR(pathname))
59436+ goto toolong;
59437+
59438+ pathname = mangle_path(buf, pathname, "\t\n\\");
59439+ if (!pathname)
59440+ goto toolong;
59441+
59442+ *pathname = 0;
59443+ return buf;
59444+
59445+toolong:
59446+ return "<path too long>";
59447+}
59448+EXPORT_SYMBOL(pax_get_path);
59449+
59450+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59451+{
59452+ struct task_struct *tsk = current;
59453+ struct mm_struct *mm = current->mm;
59454+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59455+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59456+ char *path_exec = NULL;
59457+ char *path_fault = NULL;
59458+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
59459+ siginfo_t info = { };
59460+
59461+ if (buffer_exec && buffer_fault) {
59462+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59463+
59464+ down_read(&mm->mmap_sem);
59465+ vma = mm->mmap;
59466+ while (vma && (!vma_exec || !vma_fault)) {
59467+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59468+ vma_exec = vma;
59469+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59470+ vma_fault = vma;
59471+ vma = vma->vm_next;
59472+ }
59473+ if (vma_exec)
59474+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59475+ if (vma_fault) {
59476+ start = vma_fault->vm_start;
59477+ end = vma_fault->vm_end;
59478+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59479+ if (vma_fault->vm_file)
59480+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59481+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59482+ path_fault = "<heap>";
59483+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59484+ path_fault = "<stack>";
59485+ else
59486+ path_fault = "<anonymous mapping>";
59487+ }
59488+ up_read(&mm->mmap_sem);
59489+ }
59490+ if (tsk->signal->curr_ip)
59491+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59492+ else
59493+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59494+ 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),
59495+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59496+ free_page((unsigned long)buffer_exec);
59497+ free_page((unsigned long)buffer_fault);
59498+ pax_report_insns(regs, pc, sp);
59499+ info.si_signo = SIGKILL;
59500+ info.si_errno = 0;
59501+ info.si_code = SI_KERNEL;
59502+ info.si_pid = 0;
59503+ info.si_uid = 0;
59504+ do_coredump(&info);
59505+}
59506+#endif
59507+
59508+#ifdef CONFIG_PAX_REFCOUNT
59509+void pax_report_refcount_overflow(struct pt_regs *regs)
59510+{
59511+ if (current->signal->curr_ip)
59512+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59513+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59514+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59515+ else
59516+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59517+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59518+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59519+ preempt_disable();
59520+ show_regs(regs);
59521+ preempt_enable();
59522+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59523+}
59524+#endif
59525+
59526+#ifdef CONFIG_PAX_USERCOPY
59527+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59528+static noinline int check_stack_object(const void *obj, unsigned long len)
59529+{
59530+ const void * const stack = task_stack_page(current);
59531+ const void * const stackend = stack + THREAD_SIZE;
59532+
59533+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59534+ const void *frame = NULL;
59535+ const void *oldframe;
59536+#endif
59537+
59538+ if (obj + len < obj)
59539+ return -1;
59540+
59541+ if (obj + len <= stack || stackend <= obj)
59542+ return 0;
59543+
59544+ if (obj < stack || stackend < obj + len)
59545+ return -1;
59546+
59547+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59548+ oldframe = __builtin_frame_address(1);
59549+ if (oldframe)
59550+ frame = __builtin_frame_address(2);
59551+ /*
59552+ low ----------------------------------------------> high
59553+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59554+ ^----------------^
59555+ allow copies only within here
59556+ */
59557+ while (stack <= frame && frame < stackend) {
59558+ /* if obj + len extends past the last frame, this
59559+ check won't pass and the next frame will be 0,
59560+ causing us to bail out and correctly report
59561+ the copy as invalid
59562+ */
59563+ if (obj + len <= frame)
59564+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59565+ oldframe = frame;
59566+ frame = *(const void * const *)frame;
59567+ }
59568+ return -1;
59569+#else
59570+ return 1;
59571+#endif
59572+}
59573+
59574+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59575+{
59576+ if (current->signal->curr_ip)
59577+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59578+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59579+ else
59580+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59581+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59582+ dump_stack();
59583+ gr_handle_kernel_exploit();
59584+ do_group_exit(SIGKILL);
59585+}
59586+#endif
59587+
59588+#ifdef CONFIG_PAX_USERCOPY
59589+
59590+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59591+{
59592+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59593+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59594+#ifdef CONFIG_MODULES
59595+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59596+#else
59597+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59598+#endif
59599+
59600+#else
59601+ unsigned long textlow = (unsigned long)_stext;
59602+ unsigned long texthigh = (unsigned long)_etext;
59603+
59604+#ifdef CONFIG_X86_64
59605+ /* check against linear mapping as well */
59606+ if (high > (unsigned long)__va(__pa(textlow)) &&
59607+ low < (unsigned long)__va(__pa(texthigh)))
59608+ return true;
59609+#endif
59610+
59611+#endif
59612+
59613+ if (high <= textlow || low >= texthigh)
59614+ return false;
59615+ else
59616+ return true;
59617+}
59618+#endif
59619+
59620+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59621+{
59622+#ifdef CONFIG_PAX_USERCOPY
59623+ const char *type;
59624+#endif
59625+
59626+#ifndef CONFIG_STACK_GROWSUP
59627+ unsigned long stackstart = (unsigned long)task_stack_page(current);
59628+ unsigned long currentsp = (unsigned long)&stackstart;
59629+ if (unlikely((currentsp < stackstart + 512 ||
59630+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59631+ BUG();
59632+#endif
59633+
59634+#ifndef CONFIG_PAX_USERCOPY_DEBUG
59635+ if (const_size)
59636+ return;
59637+#endif
59638+
59639+#ifdef CONFIG_PAX_USERCOPY
59640+ if (!n)
59641+ return;
59642+
59643+ type = check_heap_object(ptr, n);
59644+ if (!type) {
59645+ int ret = check_stack_object(ptr, n);
59646+ if (ret == 1 || ret == 2)
59647+ return;
59648+ if (ret == 0) {
59649+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59650+ type = "<kernel text>";
59651+ else
59652+ return;
59653+ } else
59654+ type = "<process stack>";
59655+ }
59656+
59657+ pax_report_usercopy(ptr, n, to_user, type);
59658+#endif
59659+
59660+}
59661+EXPORT_SYMBOL(__check_object_size);
59662+
59663+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59664+void pax_track_stack(void)
59665+{
59666+ unsigned long sp = (unsigned long)&sp;
59667+ if (sp < current_thread_info()->lowest_stack &&
59668+ sp > (unsigned long)task_stack_page(current))
59669+ current_thread_info()->lowest_stack = sp;
59670+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59671+ BUG();
59672+}
59673+EXPORT_SYMBOL(pax_track_stack);
59674+#endif
59675+
59676+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59677+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59678+{
59679+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59680+ dump_stack();
59681+ do_group_exit(SIGKILL);
59682+}
59683+EXPORT_SYMBOL(report_size_overflow);
59684+#endif
59685diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59686index 9f9992b..8b59411 100644
59687--- a/fs/ext2/balloc.c
59688+++ b/fs/ext2/balloc.c
59689@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59690
59691 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59692 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59693- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59694+ if (free_blocks < root_blocks + 1 &&
59695 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59696 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59697- !in_group_p (sbi->s_resgid))) {
59698+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59699 return 0;
59700 }
59701 return 1;
59702diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59703index 9142614..97484fa 100644
59704--- a/fs/ext2/xattr.c
59705+++ b/fs/ext2/xattr.c
59706@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59707 struct buffer_head *bh = NULL;
59708 struct ext2_xattr_entry *entry;
59709 char *end;
59710- size_t rest = buffer_size;
59711+ size_t rest = buffer_size, total_size = 0;
59712 int error;
59713
59714 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59715@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59716 buffer += size;
59717 }
59718 rest -= size;
59719+ total_size += size;
59720 }
59721 }
59722- error = buffer_size - rest; /* total size */
59723+ error = total_size;
59724
59725 cleanup:
59726 brelse(bh);
59727diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59728index 158b5d4..2432610 100644
59729--- a/fs/ext3/balloc.c
59730+++ b/fs/ext3/balloc.c
59731@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59732
59733 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59734 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59735- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59736+ if (free_blocks < root_blocks + 1 &&
59737 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59738 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59739- !in_group_p (sbi->s_resgid))) {
59740+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59741 return 0;
59742 }
59743 return 1;
59744diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59745index c6874be..f8a6ae8 100644
59746--- a/fs/ext3/xattr.c
59747+++ b/fs/ext3/xattr.c
59748@@ -330,7 +330,7 @@ static int
59749 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59750 char *buffer, size_t buffer_size)
59751 {
59752- size_t rest = buffer_size;
59753+ size_t rest = buffer_size, total_size = 0;
59754
59755 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59756 const struct xattr_handler *handler =
59757@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59758 buffer += size;
59759 }
59760 rest -= size;
59761+ total_size += size;
59762 }
59763 }
59764- return buffer_size - rest;
59765+ return total_size;
59766 }
59767
59768 static int
59769diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59770index 5c56785..77698a2 100644
59771--- a/fs/ext4/balloc.c
59772+++ b/fs/ext4/balloc.c
59773@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59774 /* Hm, nope. Are (enough) root reserved clusters available? */
59775 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59776 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59777- capable(CAP_SYS_RESOURCE) ||
59778- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59779+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59780+ capable_nolog(CAP_SYS_RESOURCE)) {
59781
59782 if (free_clusters >= (nclusters + dirty_clusters +
59783 resv_clusters))
59784diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59785index f542e48..c0275f5 100644
59786--- a/fs/ext4/ext4.h
59787+++ b/fs/ext4/ext4.h
59788@@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59789 unsigned long s_mb_last_start;
59790
59791 /* stats for buddy allocator */
59792- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59793- atomic_t s_bal_success; /* we found long enough chunks */
59794- atomic_t s_bal_allocated; /* in blocks */
59795- atomic_t s_bal_ex_scanned; /* total extents scanned */
59796- atomic_t s_bal_goals; /* goal hits */
59797- atomic_t s_bal_breaks; /* too long searches */
59798- atomic_t s_bal_2orders; /* 2^order hits */
59799+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59800+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59801+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59802+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59803+ atomic_unchecked_t s_bal_goals; /* goal hits */
59804+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59805+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59806 spinlock_t s_bal_lock;
59807 unsigned long s_mb_buddies_generated;
59808 unsigned long long s_mb_generation_time;
59809- atomic_t s_mb_lost_chunks;
59810- atomic_t s_mb_preallocated;
59811- atomic_t s_mb_discarded;
59812+ atomic_unchecked_t s_mb_lost_chunks;
59813+ atomic_unchecked_t s_mb_preallocated;
59814+ atomic_unchecked_t s_mb_discarded;
59815 atomic_t s_lock_busy;
59816
59817 /* locality groups */
59818diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
59819index e6574d7..c30cbe2 100644
59820--- a/fs/ext4/indirect.c
59821+++ b/fs/ext4/indirect.c
59822@@ -1345,8 +1345,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59823 if (level == 0 ||
59824 (bh && all_zeroes((__le32 *)bh->b_data,
59825 (__le32 *)bh->b_data + addr_per_block))) {
59826- ext4_free_data(handle, inode, parent_bh, &blk, &blk+1);
59827- *i_data = 0;
59828+ ext4_free_data(handle, inode, parent_bh,
59829+ i_data, i_data + 1);
59830 }
59831 brelse(bh);
59832 bh = NULL;
59833diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59834index 2735a72..d083044 100644
59835--- a/fs/ext4/mballoc.c
59836+++ b/fs/ext4/mballoc.c
59837@@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59838 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59839
59840 if (EXT4_SB(sb)->s_mb_stats)
59841- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59842+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59843
59844 break;
59845 }
59846@@ -2199,7 +2199,7 @@ repeat:
59847 ac->ac_status = AC_STATUS_CONTINUE;
59848 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59849 cr = 3;
59850- atomic_inc(&sbi->s_mb_lost_chunks);
59851+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59852 goto repeat;
59853 }
59854 }
59855@@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59856 if (sbi->s_mb_stats) {
59857 ext4_msg(sb, KERN_INFO,
59858 "mballoc: %u blocks %u reqs (%u success)",
59859- atomic_read(&sbi->s_bal_allocated),
59860- atomic_read(&sbi->s_bal_reqs),
59861- atomic_read(&sbi->s_bal_success));
59862+ atomic_read_unchecked(&sbi->s_bal_allocated),
59863+ atomic_read_unchecked(&sbi->s_bal_reqs),
59864+ atomic_read_unchecked(&sbi->s_bal_success));
59865 ext4_msg(sb, KERN_INFO,
59866 "mballoc: %u extents scanned, %u goal hits, "
59867 "%u 2^N hits, %u breaks, %u lost",
59868- atomic_read(&sbi->s_bal_ex_scanned),
59869- atomic_read(&sbi->s_bal_goals),
59870- atomic_read(&sbi->s_bal_2orders),
59871- atomic_read(&sbi->s_bal_breaks),
59872- atomic_read(&sbi->s_mb_lost_chunks));
59873+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59874+ atomic_read_unchecked(&sbi->s_bal_goals),
59875+ atomic_read_unchecked(&sbi->s_bal_2orders),
59876+ atomic_read_unchecked(&sbi->s_bal_breaks),
59877+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59878 ext4_msg(sb, KERN_INFO,
59879 "mballoc: %lu generated and it took %Lu",
59880 sbi->s_mb_buddies_generated,
59881 sbi->s_mb_generation_time);
59882 ext4_msg(sb, KERN_INFO,
59883 "mballoc: %u preallocated, %u discarded",
59884- atomic_read(&sbi->s_mb_preallocated),
59885- atomic_read(&sbi->s_mb_discarded));
59886+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59887+ atomic_read_unchecked(&sbi->s_mb_discarded));
59888 }
59889
59890 free_percpu(sbi->s_locality_groups);
59891@@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59892 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59893
59894 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59895- atomic_inc(&sbi->s_bal_reqs);
59896- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59897+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59898+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59899 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59900- atomic_inc(&sbi->s_bal_success);
59901- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59902+ atomic_inc_unchecked(&sbi->s_bal_success);
59903+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59904 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59905 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59906- atomic_inc(&sbi->s_bal_goals);
59907+ atomic_inc_unchecked(&sbi->s_bal_goals);
59908 if (ac->ac_found > sbi->s_mb_max_to_scan)
59909- atomic_inc(&sbi->s_bal_breaks);
59910+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59911 }
59912
59913 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59914@@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59915 trace_ext4_mb_new_inode_pa(ac, pa);
59916
59917 ext4_mb_use_inode_pa(ac, pa);
59918- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59919+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59920
59921 ei = EXT4_I(ac->ac_inode);
59922 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59923@@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59924 trace_ext4_mb_new_group_pa(ac, pa);
59925
59926 ext4_mb_use_group_pa(ac, pa);
59927- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59928+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59929
59930 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59931 lg = ac->ac_lg;
59932@@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59933 * from the bitmap and continue.
59934 */
59935 }
59936- atomic_add(free, &sbi->s_mb_discarded);
59937+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59938
59939 return err;
59940 }
59941@@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59942 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59943 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59944 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59945- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59946+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59947 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59948
59949 return 0;
59950diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59951index 04434ad..6404663 100644
59952--- a/fs/ext4/mmp.c
59953+++ b/fs/ext4/mmp.c
59954@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59955 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59956 const char *function, unsigned int line, const char *msg)
59957 {
59958- __ext4_warning(sb, function, line, msg);
59959+ __ext4_warning(sb, function, line, "%s", msg);
59960 __ext4_warning(sb, function, line,
59961 "MMP failure info: last update time: %llu, last update "
59962 "node: %s, last update device: %s\n",
59963diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59964index 29a403c..f58dbdb 100644
59965--- a/fs/ext4/super.c
59966+++ b/fs/ext4/super.c
59967@@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59968 }
59969
59970 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59971-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59972+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59973 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59974
59975 #ifdef CONFIG_QUOTA
59976@@ -2453,7 +2453,7 @@ struct ext4_attr {
59977 int offset;
59978 int deprecated_val;
59979 } u;
59980-};
59981+} __do_const;
59982
59983 static int parse_strtoull(const char *buf,
59984 unsigned long long max, unsigned long long *value)
59985diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59986index 4eec399..1d9444c 100644
59987--- a/fs/ext4/xattr.c
59988+++ b/fs/ext4/xattr.c
59989@@ -383,7 +383,7 @@ static int
59990 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59991 char *buffer, size_t buffer_size)
59992 {
59993- size_t rest = buffer_size;
59994+ size_t rest = buffer_size, total_size = 0;
59995
59996 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59997 const struct xattr_handler *handler =
59998@@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59999 buffer += size;
60000 }
60001 rest -= size;
60002+ total_size += size;
60003 }
60004 }
60005- return buffer_size - rest;
60006+ return total_size;
60007 }
60008
60009 static int
60010diff --git a/fs/fcntl.c b/fs/fcntl.c
60011index 72c82f6..a18b263 100644
60012--- a/fs/fcntl.c
60013+++ b/fs/fcntl.c
60014@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
60015 if (err)
60016 return err;
60017
60018+ if (gr_handle_chroot_fowner(pid, type))
60019+ return -ENOENT;
60020+ if (gr_check_protected_task_fowner(pid, type))
60021+ return -EACCES;
60022+
60023 f_modown(filp, pid, type, force);
60024 return 0;
60025 }
60026diff --git a/fs/fhandle.c b/fs/fhandle.c
60027index 999ff5c..ac037c9 100644
60028--- a/fs/fhandle.c
60029+++ b/fs/fhandle.c
60030@@ -8,6 +8,7 @@
60031 #include <linux/fs_struct.h>
60032 #include <linux/fsnotify.h>
60033 #include <linux/personality.h>
60034+#include <linux/grsecurity.h>
60035 #include <asm/uaccess.h>
60036 #include "internal.h"
60037 #include "mount.h"
60038@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
60039 } else
60040 retval = 0;
60041 /* copy the mount id */
60042- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
60043- sizeof(*mnt_id)) ||
60044+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
60045 copy_to_user(ufh, handle,
60046 sizeof(struct file_handle) + handle_bytes))
60047 retval = -EFAULT;
60048@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
60049 * the directory. Ideally we would like CAP_DAC_SEARCH.
60050 * But we don't have that
60051 */
60052- if (!capable(CAP_DAC_READ_SEARCH)) {
60053+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
60054 retval = -EPERM;
60055 goto out_err;
60056 }
60057diff --git a/fs/file.c b/fs/file.c
60058index 8f294cf..d0f3872 100644
60059--- a/fs/file.c
60060+++ b/fs/file.c
60061@@ -16,6 +16,7 @@
60062 #include <linux/slab.h>
60063 #include <linux/vmalloc.h>
60064 #include <linux/file.h>
60065+#include <linux/security.h>
60066 #include <linux/fdtable.h>
60067 #include <linux/bitops.h>
60068 #include <linux/interrupt.h>
60069@@ -144,7 +145,7 @@ out:
60070 * Return <0 error code on error; 1 on successful completion.
60071 * The files->file_lock should be held on entry, and will be held on exit.
60072 */
60073-static int expand_fdtable(struct files_struct *files, int nr)
60074+static int expand_fdtable(struct files_struct *files, unsigned int nr)
60075 __releases(files->file_lock)
60076 __acquires(files->file_lock)
60077 {
60078@@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
60079 * expanded and execution may have blocked.
60080 * The files->file_lock should be held on entry, and will be held on exit.
60081 */
60082-static int expand_files(struct files_struct *files, int nr)
60083+static int expand_files(struct files_struct *files, unsigned int nr)
60084 {
60085 struct fdtable *fdt;
60086
60087@@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
60088 if (!file)
60089 return __close_fd(files, fd);
60090
60091+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
60092 if (fd >= rlimit(RLIMIT_NOFILE))
60093 return -EBADF;
60094
60095@@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
60096 if (unlikely(oldfd == newfd))
60097 return -EINVAL;
60098
60099+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
60100 if (newfd >= rlimit(RLIMIT_NOFILE))
60101 return -EBADF;
60102
60103@@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
60104 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
60105 {
60106 int err;
60107+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
60108 if (from >= rlimit(RLIMIT_NOFILE))
60109 return -EINVAL;
60110 err = alloc_fd(from, flags);
60111diff --git a/fs/filesystems.c b/fs/filesystems.c
60112index 5797d45..7d7d79a 100644
60113--- a/fs/filesystems.c
60114+++ b/fs/filesystems.c
60115@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
60116 int len = dot ? dot - name : strlen(name);
60117
60118 fs = __get_fs_type(name, len);
60119+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60120+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
60121+#else
60122 if (!fs && (request_module("fs-%.*s", len, name) == 0))
60123+#endif
60124 fs = __get_fs_type(name, len);
60125
60126 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
60127diff --git a/fs/fs_struct.c b/fs/fs_struct.c
60128index 7dca743..543d620 100644
60129--- a/fs/fs_struct.c
60130+++ b/fs/fs_struct.c
60131@@ -4,6 +4,7 @@
60132 #include <linux/path.h>
60133 #include <linux/slab.h>
60134 #include <linux/fs_struct.h>
60135+#include <linux/grsecurity.h>
60136 #include "internal.h"
60137
60138 /*
60139@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
60140 write_seqcount_begin(&fs->seq);
60141 old_root = fs->root;
60142 fs->root = *path;
60143+ gr_set_chroot_entries(current, path);
60144 write_seqcount_end(&fs->seq);
60145 spin_unlock(&fs->lock);
60146 if (old_root.dentry)
60147@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
60148 int hits = 0;
60149 spin_lock(&fs->lock);
60150 write_seqcount_begin(&fs->seq);
60151+ /* this root replacement is only done by pivot_root,
60152+ leave grsec's chroot tagging alone for this task
60153+ so that a pivoted root isn't treated as a chroot
60154+ */
60155 hits += replace_path(&fs->root, old_root, new_root);
60156 hits += replace_path(&fs->pwd, old_root, new_root);
60157 write_seqcount_end(&fs->seq);
60158@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
60159 task_lock(tsk);
60160 spin_lock(&fs->lock);
60161 tsk->fs = NULL;
60162- kill = !--fs->users;
60163+ gr_clear_chroot_entries(tsk);
60164+ kill = !atomic_dec_return(&fs->users);
60165 spin_unlock(&fs->lock);
60166 task_unlock(tsk);
60167 if (kill)
60168@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60169 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60170 /* We don't need to lock fs - think why ;-) */
60171 if (fs) {
60172- fs->users = 1;
60173+ atomic_set(&fs->users, 1);
60174 fs->in_exec = 0;
60175 spin_lock_init(&fs->lock);
60176 seqcount_init(&fs->seq);
60177@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60178 spin_lock(&old->lock);
60179 fs->root = old->root;
60180 path_get(&fs->root);
60181+ /* instead of calling gr_set_chroot_entries here,
60182+ we call it from every caller of this function
60183+ */
60184 fs->pwd = old->pwd;
60185 path_get(&fs->pwd);
60186 spin_unlock(&old->lock);
60187@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60188
60189 task_lock(current);
60190 spin_lock(&fs->lock);
60191- kill = !--fs->users;
60192+ kill = !atomic_dec_return(&fs->users);
60193 current->fs = new_fs;
60194+ gr_set_chroot_entries(current, &new_fs->root);
60195 spin_unlock(&fs->lock);
60196 task_unlock(current);
60197
60198@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60199
60200 int current_umask(void)
60201 {
60202- return current->fs->umask;
60203+ return current->fs->umask | gr_acl_umask();
60204 }
60205 EXPORT_SYMBOL(current_umask);
60206
60207 /* to be mentioned only in INIT_TASK */
60208 struct fs_struct init_fs = {
60209- .users = 1,
60210+ .users = ATOMIC_INIT(1),
60211 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60212 .seq = SEQCNT_ZERO(init_fs.seq),
60213 .umask = 0022,
60214diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60215index 29d7feb..303644d 100644
60216--- a/fs/fscache/cookie.c
60217+++ b/fs/fscache/cookie.c
60218@@ -19,7 +19,7 @@
60219
60220 struct kmem_cache *fscache_cookie_jar;
60221
60222-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60223+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60224
60225 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60226 static int fscache_alloc_object(struct fscache_cache *cache,
60227@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60228 parent ? (char *) parent->def->name : "<no-parent>",
60229 def->name, netfs_data, enable);
60230
60231- fscache_stat(&fscache_n_acquires);
60232+ fscache_stat_unchecked(&fscache_n_acquires);
60233
60234 /* if there's no parent cookie, then we don't create one here either */
60235 if (!parent) {
60236- fscache_stat(&fscache_n_acquires_null);
60237+ fscache_stat_unchecked(&fscache_n_acquires_null);
60238 _leave(" [no parent]");
60239 return NULL;
60240 }
60241@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60242 /* allocate and initialise a cookie */
60243 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60244 if (!cookie) {
60245- fscache_stat(&fscache_n_acquires_oom);
60246+ fscache_stat_unchecked(&fscache_n_acquires_oom);
60247 _leave(" [ENOMEM]");
60248 return NULL;
60249 }
60250@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60251
60252 switch (cookie->def->type) {
60253 case FSCACHE_COOKIE_TYPE_INDEX:
60254- fscache_stat(&fscache_n_cookie_index);
60255+ fscache_stat_unchecked(&fscache_n_cookie_index);
60256 break;
60257 case FSCACHE_COOKIE_TYPE_DATAFILE:
60258- fscache_stat(&fscache_n_cookie_data);
60259+ fscache_stat_unchecked(&fscache_n_cookie_data);
60260 break;
60261 default:
60262- fscache_stat(&fscache_n_cookie_special);
60263+ fscache_stat_unchecked(&fscache_n_cookie_special);
60264 break;
60265 }
60266
60267@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60268 } else {
60269 atomic_dec(&parent->n_children);
60270 __fscache_cookie_put(cookie);
60271- fscache_stat(&fscache_n_acquires_nobufs);
60272+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60273 _leave(" = NULL");
60274 return NULL;
60275 }
60276@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60277 }
60278 }
60279
60280- fscache_stat(&fscache_n_acquires_ok);
60281+ fscache_stat_unchecked(&fscache_n_acquires_ok);
60282 _leave(" = %p", cookie);
60283 return cookie;
60284 }
60285@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60286 cache = fscache_select_cache_for_object(cookie->parent);
60287 if (!cache) {
60288 up_read(&fscache_addremove_sem);
60289- fscache_stat(&fscache_n_acquires_no_cache);
60290+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60291 _leave(" = -ENOMEDIUM [no cache]");
60292 return -ENOMEDIUM;
60293 }
60294@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60295 object = cache->ops->alloc_object(cache, cookie);
60296 fscache_stat_d(&fscache_n_cop_alloc_object);
60297 if (IS_ERR(object)) {
60298- fscache_stat(&fscache_n_object_no_alloc);
60299+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
60300 ret = PTR_ERR(object);
60301 goto error;
60302 }
60303
60304- fscache_stat(&fscache_n_object_alloc);
60305+ fscache_stat_unchecked(&fscache_n_object_alloc);
60306
60307- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60308+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60309
60310 _debug("ALLOC OBJ%x: %s {%lx}",
60311 object->debug_id, cookie->def->name, object->events);
60312@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60313
60314 _enter("{%s}", cookie->def->name);
60315
60316- fscache_stat(&fscache_n_invalidates);
60317+ fscache_stat_unchecked(&fscache_n_invalidates);
60318
60319 /* Only permit invalidation of data files. Invalidating an index will
60320 * require the caller to release all its attachments to the tree rooted
60321@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60322 {
60323 struct fscache_object *object;
60324
60325- fscache_stat(&fscache_n_updates);
60326+ fscache_stat_unchecked(&fscache_n_updates);
60327
60328 if (!cookie) {
60329- fscache_stat(&fscache_n_updates_null);
60330+ fscache_stat_unchecked(&fscache_n_updates_null);
60331 _leave(" [no cookie]");
60332 return;
60333 }
60334@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60335 */
60336 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60337 {
60338- fscache_stat(&fscache_n_relinquishes);
60339+ fscache_stat_unchecked(&fscache_n_relinquishes);
60340 if (retire)
60341- fscache_stat(&fscache_n_relinquishes_retire);
60342+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60343
60344 if (!cookie) {
60345- fscache_stat(&fscache_n_relinquishes_null);
60346+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
60347 _leave(" [no cookie]");
60348 return;
60349 }
60350@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60351 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60352 goto inconsistent;
60353
60354- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60355+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60356
60357 __fscache_use_cookie(cookie);
60358 if (fscache_submit_op(object, op) < 0)
60359diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60360index 4226f66..0fb3f45 100644
60361--- a/fs/fscache/internal.h
60362+++ b/fs/fscache/internal.h
60363@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60364 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60365 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60366 struct fscache_operation *,
60367- atomic_t *,
60368- atomic_t *,
60369+ atomic_unchecked_t *,
60370+ atomic_unchecked_t *,
60371 void (*)(struct fscache_operation *));
60372 extern void fscache_invalidate_writes(struct fscache_cookie *);
60373
60374@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60375 * stats.c
60376 */
60377 #ifdef CONFIG_FSCACHE_STATS
60378-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60379-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60380+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60381+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60382
60383-extern atomic_t fscache_n_op_pend;
60384-extern atomic_t fscache_n_op_run;
60385-extern atomic_t fscache_n_op_enqueue;
60386-extern atomic_t fscache_n_op_deferred_release;
60387-extern atomic_t fscache_n_op_release;
60388-extern atomic_t fscache_n_op_gc;
60389-extern atomic_t fscache_n_op_cancelled;
60390-extern atomic_t fscache_n_op_rejected;
60391+extern atomic_unchecked_t fscache_n_op_pend;
60392+extern atomic_unchecked_t fscache_n_op_run;
60393+extern atomic_unchecked_t fscache_n_op_enqueue;
60394+extern atomic_unchecked_t fscache_n_op_deferred_release;
60395+extern atomic_unchecked_t fscache_n_op_release;
60396+extern atomic_unchecked_t fscache_n_op_gc;
60397+extern atomic_unchecked_t fscache_n_op_cancelled;
60398+extern atomic_unchecked_t fscache_n_op_rejected;
60399
60400-extern atomic_t fscache_n_attr_changed;
60401-extern atomic_t fscache_n_attr_changed_ok;
60402-extern atomic_t fscache_n_attr_changed_nobufs;
60403-extern atomic_t fscache_n_attr_changed_nomem;
60404-extern atomic_t fscache_n_attr_changed_calls;
60405+extern atomic_unchecked_t fscache_n_attr_changed;
60406+extern atomic_unchecked_t fscache_n_attr_changed_ok;
60407+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60408+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60409+extern atomic_unchecked_t fscache_n_attr_changed_calls;
60410
60411-extern atomic_t fscache_n_allocs;
60412-extern atomic_t fscache_n_allocs_ok;
60413-extern atomic_t fscache_n_allocs_wait;
60414-extern atomic_t fscache_n_allocs_nobufs;
60415-extern atomic_t fscache_n_allocs_intr;
60416-extern atomic_t fscache_n_allocs_object_dead;
60417-extern atomic_t fscache_n_alloc_ops;
60418-extern atomic_t fscache_n_alloc_op_waits;
60419+extern atomic_unchecked_t fscache_n_allocs;
60420+extern atomic_unchecked_t fscache_n_allocs_ok;
60421+extern atomic_unchecked_t fscache_n_allocs_wait;
60422+extern atomic_unchecked_t fscache_n_allocs_nobufs;
60423+extern atomic_unchecked_t fscache_n_allocs_intr;
60424+extern atomic_unchecked_t fscache_n_allocs_object_dead;
60425+extern atomic_unchecked_t fscache_n_alloc_ops;
60426+extern atomic_unchecked_t fscache_n_alloc_op_waits;
60427
60428-extern atomic_t fscache_n_retrievals;
60429-extern atomic_t fscache_n_retrievals_ok;
60430-extern atomic_t fscache_n_retrievals_wait;
60431-extern atomic_t fscache_n_retrievals_nodata;
60432-extern atomic_t fscache_n_retrievals_nobufs;
60433-extern atomic_t fscache_n_retrievals_intr;
60434-extern atomic_t fscache_n_retrievals_nomem;
60435-extern atomic_t fscache_n_retrievals_object_dead;
60436-extern atomic_t fscache_n_retrieval_ops;
60437-extern atomic_t fscache_n_retrieval_op_waits;
60438+extern atomic_unchecked_t fscache_n_retrievals;
60439+extern atomic_unchecked_t fscache_n_retrievals_ok;
60440+extern atomic_unchecked_t fscache_n_retrievals_wait;
60441+extern atomic_unchecked_t fscache_n_retrievals_nodata;
60442+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60443+extern atomic_unchecked_t fscache_n_retrievals_intr;
60444+extern atomic_unchecked_t fscache_n_retrievals_nomem;
60445+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60446+extern atomic_unchecked_t fscache_n_retrieval_ops;
60447+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60448
60449-extern atomic_t fscache_n_stores;
60450-extern atomic_t fscache_n_stores_ok;
60451-extern atomic_t fscache_n_stores_again;
60452-extern atomic_t fscache_n_stores_nobufs;
60453-extern atomic_t fscache_n_stores_oom;
60454-extern atomic_t fscache_n_store_ops;
60455-extern atomic_t fscache_n_store_calls;
60456-extern atomic_t fscache_n_store_pages;
60457-extern atomic_t fscache_n_store_radix_deletes;
60458-extern atomic_t fscache_n_store_pages_over_limit;
60459+extern atomic_unchecked_t fscache_n_stores;
60460+extern atomic_unchecked_t fscache_n_stores_ok;
60461+extern atomic_unchecked_t fscache_n_stores_again;
60462+extern atomic_unchecked_t fscache_n_stores_nobufs;
60463+extern atomic_unchecked_t fscache_n_stores_oom;
60464+extern atomic_unchecked_t fscache_n_store_ops;
60465+extern atomic_unchecked_t fscache_n_store_calls;
60466+extern atomic_unchecked_t fscache_n_store_pages;
60467+extern atomic_unchecked_t fscache_n_store_radix_deletes;
60468+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60469
60470-extern atomic_t fscache_n_store_vmscan_not_storing;
60471-extern atomic_t fscache_n_store_vmscan_gone;
60472-extern atomic_t fscache_n_store_vmscan_busy;
60473-extern atomic_t fscache_n_store_vmscan_cancelled;
60474-extern atomic_t fscache_n_store_vmscan_wait;
60475+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60476+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60477+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60478+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60479+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60480
60481-extern atomic_t fscache_n_marks;
60482-extern atomic_t fscache_n_uncaches;
60483+extern atomic_unchecked_t fscache_n_marks;
60484+extern atomic_unchecked_t fscache_n_uncaches;
60485
60486-extern atomic_t fscache_n_acquires;
60487-extern atomic_t fscache_n_acquires_null;
60488-extern atomic_t fscache_n_acquires_no_cache;
60489-extern atomic_t fscache_n_acquires_ok;
60490-extern atomic_t fscache_n_acquires_nobufs;
60491-extern atomic_t fscache_n_acquires_oom;
60492+extern atomic_unchecked_t fscache_n_acquires;
60493+extern atomic_unchecked_t fscache_n_acquires_null;
60494+extern atomic_unchecked_t fscache_n_acquires_no_cache;
60495+extern atomic_unchecked_t fscache_n_acquires_ok;
60496+extern atomic_unchecked_t fscache_n_acquires_nobufs;
60497+extern atomic_unchecked_t fscache_n_acquires_oom;
60498
60499-extern atomic_t fscache_n_invalidates;
60500-extern atomic_t fscache_n_invalidates_run;
60501+extern atomic_unchecked_t fscache_n_invalidates;
60502+extern atomic_unchecked_t fscache_n_invalidates_run;
60503
60504-extern atomic_t fscache_n_updates;
60505-extern atomic_t fscache_n_updates_null;
60506-extern atomic_t fscache_n_updates_run;
60507+extern atomic_unchecked_t fscache_n_updates;
60508+extern atomic_unchecked_t fscache_n_updates_null;
60509+extern atomic_unchecked_t fscache_n_updates_run;
60510
60511-extern atomic_t fscache_n_relinquishes;
60512-extern atomic_t fscache_n_relinquishes_null;
60513-extern atomic_t fscache_n_relinquishes_waitcrt;
60514-extern atomic_t fscache_n_relinquishes_retire;
60515+extern atomic_unchecked_t fscache_n_relinquishes;
60516+extern atomic_unchecked_t fscache_n_relinquishes_null;
60517+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60518+extern atomic_unchecked_t fscache_n_relinquishes_retire;
60519
60520-extern atomic_t fscache_n_cookie_index;
60521-extern atomic_t fscache_n_cookie_data;
60522-extern atomic_t fscache_n_cookie_special;
60523+extern atomic_unchecked_t fscache_n_cookie_index;
60524+extern atomic_unchecked_t fscache_n_cookie_data;
60525+extern atomic_unchecked_t fscache_n_cookie_special;
60526
60527-extern atomic_t fscache_n_object_alloc;
60528-extern atomic_t fscache_n_object_no_alloc;
60529-extern atomic_t fscache_n_object_lookups;
60530-extern atomic_t fscache_n_object_lookups_negative;
60531-extern atomic_t fscache_n_object_lookups_positive;
60532-extern atomic_t fscache_n_object_lookups_timed_out;
60533-extern atomic_t fscache_n_object_created;
60534-extern atomic_t fscache_n_object_avail;
60535-extern atomic_t fscache_n_object_dead;
60536+extern atomic_unchecked_t fscache_n_object_alloc;
60537+extern atomic_unchecked_t fscache_n_object_no_alloc;
60538+extern atomic_unchecked_t fscache_n_object_lookups;
60539+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60540+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60541+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60542+extern atomic_unchecked_t fscache_n_object_created;
60543+extern atomic_unchecked_t fscache_n_object_avail;
60544+extern atomic_unchecked_t fscache_n_object_dead;
60545
60546-extern atomic_t fscache_n_checkaux_none;
60547-extern atomic_t fscache_n_checkaux_okay;
60548-extern atomic_t fscache_n_checkaux_update;
60549-extern atomic_t fscache_n_checkaux_obsolete;
60550+extern atomic_unchecked_t fscache_n_checkaux_none;
60551+extern atomic_unchecked_t fscache_n_checkaux_okay;
60552+extern atomic_unchecked_t fscache_n_checkaux_update;
60553+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60554
60555 extern atomic_t fscache_n_cop_alloc_object;
60556 extern atomic_t fscache_n_cop_lookup_object;
60557@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60558 atomic_inc(stat);
60559 }
60560
60561+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60562+{
60563+ atomic_inc_unchecked(stat);
60564+}
60565+
60566 static inline void fscache_stat_d(atomic_t *stat)
60567 {
60568 atomic_dec(stat);
60569@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60570
60571 #define __fscache_stat(stat) (NULL)
60572 #define fscache_stat(stat) do {} while (0)
60573+#define fscache_stat_unchecked(stat) do {} while (0)
60574 #define fscache_stat_d(stat) do {} while (0)
60575 #endif
60576
60577diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60578index d3b4539..ed0c659 100644
60579--- a/fs/fscache/object.c
60580+++ b/fs/fscache/object.c
60581@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60582 _debug("LOOKUP \"%s\" in \"%s\"",
60583 cookie->def->name, object->cache->tag->name);
60584
60585- fscache_stat(&fscache_n_object_lookups);
60586+ fscache_stat_unchecked(&fscache_n_object_lookups);
60587 fscache_stat(&fscache_n_cop_lookup_object);
60588 ret = object->cache->ops->lookup_object(object);
60589 fscache_stat_d(&fscache_n_cop_lookup_object);
60590@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60591 if (ret == -ETIMEDOUT) {
60592 /* probably stuck behind another object, so move this one to
60593 * the back of the queue */
60594- fscache_stat(&fscache_n_object_lookups_timed_out);
60595+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60596 _leave(" [timeout]");
60597 return NO_TRANSIT;
60598 }
60599@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60600 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60601
60602 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60603- fscache_stat(&fscache_n_object_lookups_negative);
60604+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60605
60606 /* Allow write requests to begin stacking up and read requests to begin
60607 * returning ENODATA.
60608@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60609 /* if we were still looking up, then we must have a positive lookup
60610 * result, in which case there may be data available */
60611 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60612- fscache_stat(&fscache_n_object_lookups_positive);
60613+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60614
60615 /* We do (presumably) have data */
60616 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60617@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60618 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60619 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60620 } else {
60621- fscache_stat(&fscache_n_object_created);
60622+ fscache_stat_unchecked(&fscache_n_object_created);
60623 }
60624
60625 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60626@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60627 fscache_stat_d(&fscache_n_cop_lookup_complete);
60628
60629 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60630- fscache_stat(&fscache_n_object_avail);
60631+ fscache_stat_unchecked(&fscache_n_object_avail);
60632
60633 _leave("");
60634 return transit_to(JUMPSTART_DEPS);
60635@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60636
60637 /* this just shifts the object release to the work processor */
60638 fscache_put_object(object);
60639- fscache_stat(&fscache_n_object_dead);
60640+ fscache_stat_unchecked(&fscache_n_object_dead);
60641
60642 _leave("");
60643 return transit_to(OBJECT_DEAD);
60644@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60645 enum fscache_checkaux result;
60646
60647 if (!object->cookie->def->check_aux) {
60648- fscache_stat(&fscache_n_checkaux_none);
60649+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60650 return FSCACHE_CHECKAUX_OKAY;
60651 }
60652
60653@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60654 switch (result) {
60655 /* entry okay as is */
60656 case FSCACHE_CHECKAUX_OKAY:
60657- fscache_stat(&fscache_n_checkaux_okay);
60658+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60659 break;
60660
60661 /* entry requires update */
60662 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60663- fscache_stat(&fscache_n_checkaux_update);
60664+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60665 break;
60666
60667 /* entry requires deletion */
60668 case FSCACHE_CHECKAUX_OBSOLETE:
60669- fscache_stat(&fscache_n_checkaux_obsolete);
60670+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60671 break;
60672
60673 default:
60674@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60675 {
60676 const struct fscache_state *s;
60677
60678- fscache_stat(&fscache_n_invalidates_run);
60679+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60680 fscache_stat(&fscache_n_cop_invalidate_object);
60681 s = _fscache_invalidate_object(object, event);
60682 fscache_stat_d(&fscache_n_cop_invalidate_object);
60683@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60684 {
60685 _enter("{OBJ%x},%d", object->debug_id, event);
60686
60687- fscache_stat(&fscache_n_updates_run);
60688+ fscache_stat_unchecked(&fscache_n_updates_run);
60689 fscache_stat(&fscache_n_cop_update_object);
60690 object->cache->ops->update_object(object);
60691 fscache_stat_d(&fscache_n_cop_update_object);
60692diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60693index 318071a..379938b 100644
60694--- a/fs/fscache/operation.c
60695+++ b/fs/fscache/operation.c
60696@@ -17,7 +17,7 @@
60697 #include <linux/slab.h>
60698 #include "internal.h"
60699
60700-atomic_t fscache_op_debug_id;
60701+atomic_unchecked_t fscache_op_debug_id;
60702 EXPORT_SYMBOL(fscache_op_debug_id);
60703
60704 /**
60705@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60706 ASSERTCMP(atomic_read(&op->usage), >, 0);
60707 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60708
60709- fscache_stat(&fscache_n_op_enqueue);
60710+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60711 switch (op->flags & FSCACHE_OP_TYPE) {
60712 case FSCACHE_OP_ASYNC:
60713 _debug("queue async");
60714@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60715 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60716 if (op->processor)
60717 fscache_enqueue_operation(op);
60718- fscache_stat(&fscache_n_op_run);
60719+ fscache_stat_unchecked(&fscache_n_op_run);
60720 }
60721
60722 /*
60723@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60724 if (object->n_in_progress > 0) {
60725 atomic_inc(&op->usage);
60726 list_add_tail(&op->pend_link, &object->pending_ops);
60727- fscache_stat(&fscache_n_op_pend);
60728+ fscache_stat_unchecked(&fscache_n_op_pend);
60729 } else if (!list_empty(&object->pending_ops)) {
60730 atomic_inc(&op->usage);
60731 list_add_tail(&op->pend_link, &object->pending_ops);
60732- fscache_stat(&fscache_n_op_pend);
60733+ fscache_stat_unchecked(&fscache_n_op_pend);
60734 fscache_start_operations(object);
60735 } else {
60736 ASSERTCMP(object->n_in_progress, ==, 0);
60737@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60738 object->n_exclusive++; /* reads and writes must wait */
60739 atomic_inc(&op->usage);
60740 list_add_tail(&op->pend_link, &object->pending_ops);
60741- fscache_stat(&fscache_n_op_pend);
60742+ fscache_stat_unchecked(&fscache_n_op_pend);
60743 ret = 0;
60744 } else {
60745 /* If we're in any other state, there must have been an I/O
60746@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60747 if (object->n_exclusive > 0) {
60748 atomic_inc(&op->usage);
60749 list_add_tail(&op->pend_link, &object->pending_ops);
60750- fscache_stat(&fscache_n_op_pend);
60751+ fscache_stat_unchecked(&fscache_n_op_pend);
60752 } else if (!list_empty(&object->pending_ops)) {
60753 atomic_inc(&op->usage);
60754 list_add_tail(&op->pend_link, &object->pending_ops);
60755- fscache_stat(&fscache_n_op_pend);
60756+ fscache_stat_unchecked(&fscache_n_op_pend);
60757 fscache_start_operations(object);
60758 } else {
60759 ASSERTCMP(object->n_exclusive, ==, 0);
60760@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60761 object->n_ops++;
60762 atomic_inc(&op->usage);
60763 list_add_tail(&op->pend_link, &object->pending_ops);
60764- fscache_stat(&fscache_n_op_pend);
60765+ fscache_stat_unchecked(&fscache_n_op_pend);
60766 ret = 0;
60767 } else if (fscache_object_is_dying(object)) {
60768- fscache_stat(&fscache_n_op_rejected);
60769+ fscache_stat_unchecked(&fscache_n_op_rejected);
60770 op->state = FSCACHE_OP_ST_CANCELLED;
60771 ret = -ENOBUFS;
60772 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60773@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60774 ret = -EBUSY;
60775 if (op->state == FSCACHE_OP_ST_PENDING) {
60776 ASSERT(!list_empty(&op->pend_link));
60777- fscache_stat(&fscache_n_op_cancelled);
60778+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60779 list_del_init(&op->pend_link);
60780 if (do_cancel)
60781 do_cancel(op);
60782@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60783 while (!list_empty(&object->pending_ops)) {
60784 op = list_entry(object->pending_ops.next,
60785 struct fscache_operation, pend_link);
60786- fscache_stat(&fscache_n_op_cancelled);
60787+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60788 list_del_init(&op->pend_link);
60789
60790 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60791@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60792 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60793 op->state = FSCACHE_OP_ST_DEAD;
60794
60795- fscache_stat(&fscache_n_op_release);
60796+ fscache_stat_unchecked(&fscache_n_op_release);
60797
60798 if (op->release) {
60799 op->release(op);
60800@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60801 * lock, and defer it otherwise */
60802 if (!spin_trylock(&object->lock)) {
60803 _debug("defer put");
60804- fscache_stat(&fscache_n_op_deferred_release);
60805+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60806
60807 cache = object->cache;
60808 spin_lock(&cache->op_gc_list_lock);
60809@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60810
60811 _debug("GC DEFERRED REL OBJ%x OP%x",
60812 object->debug_id, op->debug_id);
60813- fscache_stat(&fscache_n_op_gc);
60814+ fscache_stat_unchecked(&fscache_n_op_gc);
60815
60816 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60817 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60818diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60819index 7f5c658..6c1e164 100644
60820--- a/fs/fscache/page.c
60821+++ b/fs/fscache/page.c
60822@@ -61,7 +61,7 @@ try_again:
60823 val = radix_tree_lookup(&cookie->stores, page->index);
60824 if (!val) {
60825 rcu_read_unlock();
60826- fscache_stat(&fscache_n_store_vmscan_not_storing);
60827+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60828 __fscache_uncache_page(cookie, page);
60829 return true;
60830 }
60831@@ -91,11 +91,11 @@ try_again:
60832 spin_unlock(&cookie->stores_lock);
60833
60834 if (xpage) {
60835- fscache_stat(&fscache_n_store_vmscan_cancelled);
60836- fscache_stat(&fscache_n_store_radix_deletes);
60837+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60838+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60839 ASSERTCMP(xpage, ==, page);
60840 } else {
60841- fscache_stat(&fscache_n_store_vmscan_gone);
60842+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60843 }
60844
60845 wake_up_bit(&cookie->flags, 0);
60846@@ -110,11 +110,11 @@ page_busy:
60847 * sleeping on memory allocation, so we may need to impose a timeout
60848 * too. */
60849 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60850- fscache_stat(&fscache_n_store_vmscan_busy);
60851+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60852 return false;
60853 }
60854
60855- fscache_stat(&fscache_n_store_vmscan_wait);
60856+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60857 __fscache_wait_on_page_write(cookie, page);
60858 gfp &= ~__GFP_WAIT;
60859 goto try_again;
60860@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60861 FSCACHE_COOKIE_STORING_TAG);
60862 if (!radix_tree_tag_get(&cookie->stores, page->index,
60863 FSCACHE_COOKIE_PENDING_TAG)) {
60864- fscache_stat(&fscache_n_store_radix_deletes);
60865+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60866 xpage = radix_tree_delete(&cookie->stores, page->index);
60867 }
60868 spin_unlock(&cookie->stores_lock);
60869@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60870
60871 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60872
60873- fscache_stat(&fscache_n_attr_changed_calls);
60874+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60875
60876 if (fscache_object_is_active(object)) {
60877 fscache_stat(&fscache_n_cop_attr_changed);
60878@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60879
60880 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60881
60882- fscache_stat(&fscache_n_attr_changed);
60883+ fscache_stat_unchecked(&fscache_n_attr_changed);
60884
60885 op = kzalloc(sizeof(*op), GFP_KERNEL);
60886 if (!op) {
60887- fscache_stat(&fscache_n_attr_changed_nomem);
60888+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60889 _leave(" = -ENOMEM");
60890 return -ENOMEM;
60891 }
60892@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60893 if (fscache_submit_exclusive_op(object, op) < 0)
60894 goto nobufs;
60895 spin_unlock(&cookie->lock);
60896- fscache_stat(&fscache_n_attr_changed_ok);
60897+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60898 fscache_put_operation(op);
60899 _leave(" = 0");
60900 return 0;
60901@@ -225,7 +225,7 @@ nobufs:
60902 kfree(op);
60903 if (wake_cookie)
60904 __fscache_wake_unused_cookie(cookie);
60905- fscache_stat(&fscache_n_attr_changed_nobufs);
60906+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60907 _leave(" = %d", -ENOBUFS);
60908 return -ENOBUFS;
60909 }
60910@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60911 /* allocate a retrieval operation and attempt to submit it */
60912 op = kzalloc(sizeof(*op), GFP_NOIO);
60913 if (!op) {
60914- fscache_stat(&fscache_n_retrievals_nomem);
60915+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60916 return NULL;
60917 }
60918
60919@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60920 return 0;
60921 }
60922
60923- fscache_stat(&fscache_n_retrievals_wait);
60924+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60925
60926 jif = jiffies;
60927 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60928 fscache_wait_bit_interruptible,
60929 TASK_INTERRUPTIBLE) != 0) {
60930- fscache_stat(&fscache_n_retrievals_intr);
60931+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60932 _leave(" = -ERESTARTSYS");
60933 return -ERESTARTSYS;
60934 }
60935@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60936 */
60937 int fscache_wait_for_operation_activation(struct fscache_object *object,
60938 struct fscache_operation *op,
60939- atomic_t *stat_op_waits,
60940- atomic_t *stat_object_dead,
60941+ atomic_unchecked_t *stat_op_waits,
60942+ atomic_unchecked_t *stat_object_dead,
60943 void (*do_cancel)(struct fscache_operation *))
60944 {
60945 int ret;
60946@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60947
60948 _debug(">>> WT");
60949 if (stat_op_waits)
60950- fscache_stat(stat_op_waits);
60951+ fscache_stat_unchecked(stat_op_waits);
60952 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60953 fscache_wait_bit_interruptible,
60954 TASK_INTERRUPTIBLE) != 0) {
60955@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60956 check_if_dead:
60957 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60958 if (stat_object_dead)
60959- fscache_stat(stat_object_dead);
60960+ fscache_stat_unchecked(stat_object_dead);
60961 _leave(" = -ENOBUFS [cancelled]");
60962 return -ENOBUFS;
60963 }
60964@@ -366,7 +366,7 @@ check_if_dead:
60965 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60966 fscache_cancel_op(op, do_cancel);
60967 if (stat_object_dead)
60968- fscache_stat(stat_object_dead);
60969+ fscache_stat_unchecked(stat_object_dead);
60970 return -ENOBUFS;
60971 }
60972 return 0;
60973@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60974
60975 _enter("%p,%p,,,", cookie, page);
60976
60977- fscache_stat(&fscache_n_retrievals);
60978+ fscache_stat_unchecked(&fscache_n_retrievals);
60979
60980 if (hlist_empty(&cookie->backing_objects))
60981 goto nobufs;
60982@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60983 goto nobufs_unlock_dec;
60984 spin_unlock(&cookie->lock);
60985
60986- fscache_stat(&fscache_n_retrieval_ops);
60987+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60988
60989 /* pin the netfs read context in case we need to do the actual netfs
60990 * read because we've encountered a cache read failure */
60991@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60992
60993 error:
60994 if (ret == -ENOMEM)
60995- fscache_stat(&fscache_n_retrievals_nomem);
60996+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60997 else if (ret == -ERESTARTSYS)
60998- fscache_stat(&fscache_n_retrievals_intr);
60999+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
61000 else if (ret == -ENODATA)
61001- fscache_stat(&fscache_n_retrievals_nodata);
61002+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
61003 else if (ret < 0)
61004- fscache_stat(&fscache_n_retrievals_nobufs);
61005+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61006 else
61007- fscache_stat(&fscache_n_retrievals_ok);
61008+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
61009
61010 fscache_put_retrieval(op);
61011 _leave(" = %d", ret);
61012@@ -490,7 +490,7 @@ nobufs_unlock:
61013 __fscache_wake_unused_cookie(cookie);
61014 kfree(op);
61015 nobufs:
61016- fscache_stat(&fscache_n_retrievals_nobufs);
61017+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61018 _leave(" = -ENOBUFS");
61019 return -ENOBUFS;
61020 }
61021@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
61022
61023 _enter("%p,,%d,,,", cookie, *nr_pages);
61024
61025- fscache_stat(&fscache_n_retrievals);
61026+ fscache_stat_unchecked(&fscache_n_retrievals);
61027
61028 if (hlist_empty(&cookie->backing_objects))
61029 goto nobufs;
61030@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
61031 goto nobufs_unlock_dec;
61032 spin_unlock(&cookie->lock);
61033
61034- fscache_stat(&fscache_n_retrieval_ops);
61035+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
61036
61037 /* pin the netfs read context in case we need to do the actual netfs
61038 * read because we've encountered a cache read failure */
61039@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
61040
61041 error:
61042 if (ret == -ENOMEM)
61043- fscache_stat(&fscache_n_retrievals_nomem);
61044+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
61045 else if (ret == -ERESTARTSYS)
61046- fscache_stat(&fscache_n_retrievals_intr);
61047+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
61048 else if (ret == -ENODATA)
61049- fscache_stat(&fscache_n_retrievals_nodata);
61050+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
61051 else if (ret < 0)
61052- fscache_stat(&fscache_n_retrievals_nobufs);
61053+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61054 else
61055- fscache_stat(&fscache_n_retrievals_ok);
61056+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
61057
61058 fscache_put_retrieval(op);
61059 _leave(" = %d", ret);
61060@@ -621,7 +621,7 @@ nobufs_unlock:
61061 if (wake_cookie)
61062 __fscache_wake_unused_cookie(cookie);
61063 nobufs:
61064- fscache_stat(&fscache_n_retrievals_nobufs);
61065+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61066 _leave(" = -ENOBUFS");
61067 return -ENOBUFS;
61068 }
61069@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61070
61071 _enter("%p,%p,,,", cookie, page);
61072
61073- fscache_stat(&fscache_n_allocs);
61074+ fscache_stat_unchecked(&fscache_n_allocs);
61075
61076 if (hlist_empty(&cookie->backing_objects))
61077 goto nobufs;
61078@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61079 goto nobufs_unlock_dec;
61080 spin_unlock(&cookie->lock);
61081
61082- fscache_stat(&fscache_n_alloc_ops);
61083+ fscache_stat_unchecked(&fscache_n_alloc_ops);
61084
61085 ret = fscache_wait_for_operation_activation(
61086 object, &op->op,
61087@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61088
61089 error:
61090 if (ret == -ERESTARTSYS)
61091- fscache_stat(&fscache_n_allocs_intr);
61092+ fscache_stat_unchecked(&fscache_n_allocs_intr);
61093 else if (ret < 0)
61094- fscache_stat(&fscache_n_allocs_nobufs);
61095+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61096 else
61097- fscache_stat(&fscache_n_allocs_ok);
61098+ fscache_stat_unchecked(&fscache_n_allocs_ok);
61099
61100 fscache_put_retrieval(op);
61101 _leave(" = %d", ret);
61102@@ -715,7 +715,7 @@ nobufs_unlock:
61103 if (wake_cookie)
61104 __fscache_wake_unused_cookie(cookie);
61105 nobufs:
61106- fscache_stat(&fscache_n_allocs_nobufs);
61107+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61108 _leave(" = -ENOBUFS");
61109 return -ENOBUFS;
61110 }
61111@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61112
61113 spin_lock(&cookie->stores_lock);
61114
61115- fscache_stat(&fscache_n_store_calls);
61116+ fscache_stat_unchecked(&fscache_n_store_calls);
61117
61118 /* find a page to store */
61119 page = NULL;
61120@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61121 page = results[0];
61122 _debug("gang %d [%lx]", n, page->index);
61123 if (page->index > op->store_limit) {
61124- fscache_stat(&fscache_n_store_pages_over_limit);
61125+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
61126 goto superseded;
61127 }
61128
61129@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61130 spin_unlock(&cookie->stores_lock);
61131 spin_unlock(&object->lock);
61132
61133- fscache_stat(&fscache_n_store_pages);
61134+ fscache_stat_unchecked(&fscache_n_store_pages);
61135 fscache_stat(&fscache_n_cop_write_page);
61136 ret = object->cache->ops->write_page(op, page);
61137 fscache_stat_d(&fscache_n_cop_write_page);
61138@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61139 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61140 ASSERT(PageFsCache(page));
61141
61142- fscache_stat(&fscache_n_stores);
61143+ fscache_stat_unchecked(&fscache_n_stores);
61144
61145 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
61146 _leave(" = -ENOBUFS [invalidating]");
61147@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61148 spin_unlock(&cookie->stores_lock);
61149 spin_unlock(&object->lock);
61150
61151- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
61152+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61153 op->store_limit = object->store_limit;
61154
61155 __fscache_use_cookie(cookie);
61156@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61157
61158 spin_unlock(&cookie->lock);
61159 radix_tree_preload_end();
61160- fscache_stat(&fscache_n_store_ops);
61161- fscache_stat(&fscache_n_stores_ok);
61162+ fscache_stat_unchecked(&fscache_n_store_ops);
61163+ fscache_stat_unchecked(&fscache_n_stores_ok);
61164
61165 /* the work queue now carries its own ref on the object */
61166 fscache_put_operation(&op->op);
61167@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61168 return 0;
61169
61170 already_queued:
61171- fscache_stat(&fscache_n_stores_again);
61172+ fscache_stat_unchecked(&fscache_n_stores_again);
61173 already_pending:
61174 spin_unlock(&cookie->stores_lock);
61175 spin_unlock(&object->lock);
61176 spin_unlock(&cookie->lock);
61177 radix_tree_preload_end();
61178 kfree(op);
61179- fscache_stat(&fscache_n_stores_ok);
61180+ fscache_stat_unchecked(&fscache_n_stores_ok);
61181 _leave(" = 0");
61182 return 0;
61183
61184@@ -1024,14 +1024,14 @@ nobufs:
61185 kfree(op);
61186 if (wake_cookie)
61187 __fscache_wake_unused_cookie(cookie);
61188- fscache_stat(&fscache_n_stores_nobufs);
61189+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
61190 _leave(" = -ENOBUFS");
61191 return -ENOBUFS;
61192
61193 nomem_free:
61194 kfree(op);
61195 nomem:
61196- fscache_stat(&fscache_n_stores_oom);
61197+ fscache_stat_unchecked(&fscache_n_stores_oom);
61198 _leave(" = -ENOMEM");
61199 return -ENOMEM;
61200 }
61201@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61202 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61203 ASSERTCMP(page, !=, NULL);
61204
61205- fscache_stat(&fscache_n_uncaches);
61206+ fscache_stat_unchecked(&fscache_n_uncaches);
61207
61208 /* cache withdrawal may beat us to it */
61209 if (!PageFsCache(page))
61210@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61211 struct fscache_cookie *cookie = op->op.object->cookie;
61212
61213 #ifdef CONFIG_FSCACHE_STATS
61214- atomic_inc(&fscache_n_marks);
61215+ atomic_inc_unchecked(&fscache_n_marks);
61216 #endif
61217
61218 _debug("- mark %p{%lx}", page, page->index);
61219diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61220index 40d13c7..ddf52b9 100644
61221--- a/fs/fscache/stats.c
61222+++ b/fs/fscache/stats.c
61223@@ -18,99 +18,99 @@
61224 /*
61225 * operation counters
61226 */
61227-atomic_t fscache_n_op_pend;
61228-atomic_t fscache_n_op_run;
61229-atomic_t fscache_n_op_enqueue;
61230-atomic_t fscache_n_op_requeue;
61231-atomic_t fscache_n_op_deferred_release;
61232-atomic_t fscache_n_op_release;
61233-atomic_t fscache_n_op_gc;
61234-atomic_t fscache_n_op_cancelled;
61235-atomic_t fscache_n_op_rejected;
61236+atomic_unchecked_t fscache_n_op_pend;
61237+atomic_unchecked_t fscache_n_op_run;
61238+atomic_unchecked_t fscache_n_op_enqueue;
61239+atomic_unchecked_t fscache_n_op_requeue;
61240+atomic_unchecked_t fscache_n_op_deferred_release;
61241+atomic_unchecked_t fscache_n_op_release;
61242+atomic_unchecked_t fscache_n_op_gc;
61243+atomic_unchecked_t fscache_n_op_cancelled;
61244+atomic_unchecked_t fscache_n_op_rejected;
61245
61246-atomic_t fscache_n_attr_changed;
61247-atomic_t fscache_n_attr_changed_ok;
61248-atomic_t fscache_n_attr_changed_nobufs;
61249-atomic_t fscache_n_attr_changed_nomem;
61250-atomic_t fscache_n_attr_changed_calls;
61251+atomic_unchecked_t fscache_n_attr_changed;
61252+atomic_unchecked_t fscache_n_attr_changed_ok;
61253+atomic_unchecked_t fscache_n_attr_changed_nobufs;
61254+atomic_unchecked_t fscache_n_attr_changed_nomem;
61255+atomic_unchecked_t fscache_n_attr_changed_calls;
61256
61257-atomic_t fscache_n_allocs;
61258-atomic_t fscache_n_allocs_ok;
61259-atomic_t fscache_n_allocs_wait;
61260-atomic_t fscache_n_allocs_nobufs;
61261-atomic_t fscache_n_allocs_intr;
61262-atomic_t fscache_n_allocs_object_dead;
61263-atomic_t fscache_n_alloc_ops;
61264-atomic_t fscache_n_alloc_op_waits;
61265+atomic_unchecked_t fscache_n_allocs;
61266+atomic_unchecked_t fscache_n_allocs_ok;
61267+atomic_unchecked_t fscache_n_allocs_wait;
61268+atomic_unchecked_t fscache_n_allocs_nobufs;
61269+atomic_unchecked_t fscache_n_allocs_intr;
61270+atomic_unchecked_t fscache_n_allocs_object_dead;
61271+atomic_unchecked_t fscache_n_alloc_ops;
61272+atomic_unchecked_t fscache_n_alloc_op_waits;
61273
61274-atomic_t fscache_n_retrievals;
61275-atomic_t fscache_n_retrievals_ok;
61276-atomic_t fscache_n_retrievals_wait;
61277-atomic_t fscache_n_retrievals_nodata;
61278-atomic_t fscache_n_retrievals_nobufs;
61279-atomic_t fscache_n_retrievals_intr;
61280-atomic_t fscache_n_retrievals_nomem;
61281-atomic_t fscache_n_retrievals_object_dead;
61282-atomic_t fscache_n_retrieval_ops;
61283-atomic_t fscache_n_retrieval_op_waits;
61284+atomic_unchecked_t fscache_n_retrievals;
61285+atomic_unchecked_t fscache_n_retrievals_ok;
61286+atomic_unchecked_t fscache_n_retrievals_wait;
61287+atomic_unchecked_t fscache_n_retrievals_nodata;
61288+atomic_unchecked_t fscache_n_retrievals_nobufs;
61289+atomic_unchecked_t fscache_n_retrievals_intr;
61290+atomic_unchecked_t fscache_n_retrievals_nomem;
61291+atomic_unchecked_t fscache_n_retrievals_object_dead;
61292+atomic_unchecked_t fscache_n_retrieval_ops;
61293+atomic_unchecked_t fscache_n_retrieval_op_waits;
61294
61295-atomic_t fscache_n_stores;
61296-atomic_t fscache_n_stores_ok;
61297-atomic_t fscache_n_stores_again;
61298-atomic_t fscache_n_stores_nobufs;
61299-atomic_t fscache_n_stores_oom;
61300-atomic_t fscache_n_store_ops;
61301-atomic_t fscache_n_store_calls;
61302-atomic_t fscache_n_store_pages;
61303-atomic_t fscache_n_store_radix_deletes;
61304-atomic_t fscache_n_store_pages_over_limit;
61305+atomic_unchecked_t fscache_n_stores;
61306+atomic_unchecked_t fscache_n_stores_ok;
61307+atomic_unchecked_t fscache_n_stores_again;
61308+atomic_unchecked_t fscache_n_stores_nobufs;
61309+atomic_unchecked_t fscache_n_stores_oom;
61310+atomic_unchecked_t fscache_n_store_ops;
61311+atomic_unchecked_t fscache_n_store_calls;
61312+atomic_unchecked_t fscache_n_store_pages;
61313+atomic_unchecked_t fscache_n_store_radix_deletes;
61314+atomic_unchecked_t fscache_n_store_pages_over_limit;
61315
61316-atomic_t fscache_n_store_vmscan_not_storing;
61317-atomic_t fscache_n_store_vmscan_gone;
61318-atomic_t fscache_n_store_vmscan_busy;
61319-atomic_t fscache_n_store_vmscan_cancelled;
61320-atomic_t fscache_n_store_vmscan_wait;
61321+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61322+atomic_unchecked_t fscache_n_store_vmscan_gone;
61323+atomic_unchecked_t fscache_n_store_vmscan_busy;
61324+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61325+atomic_unchecked_t fscache_n_store_vmscan_wait;
61326
61327-atomic_t fscache_n_marks;
61328-atomic_t fscache_n_uncaches;
61329+atomic_unchecked_t fscache_n_marks;
61330+atomic_unchecked_t fscache_n_uncaches;
61331
61332-atomic_t fscache_n_acquires;
61333-atomic_t fscache_n_acquires_null;
61334-atomic_t fscache_n_acquires_no_cache;
61335-atomic_t fscache_n_acquires_ok;
61336-atomic_t fscache_n_acquires_nobufs;
61337-atomic_t fscache_n_acquires_oom;
61338+atomic_unchecked_t fscache_n_acquires;
61339+atomic_unchecked_t fscache_n_acquires_null;
61340+atomic_unchecked_t fscache_n_acquires_no_cache;
61341+atomic_unchecked_t fscache_n_acquires_ok;
61342+atomic_unchecked_t fscache_n_acquires_nobufs;
61343+atomic_unchecked_t fscache_n_acquires_oom;
61344
61345-atomic_t fscache_n_invalidates;
61346-atomic_t fscache_n_invalidates_run;
61347+atomic_unchecked_t fscache_n_invalidates;
61348+atomic_unchecked_t fscache_n_invalidates_run;
61349
61350-atomic_t fscache_n_updates;
61351-atomic_t fscache_n_updates_null;
61352-atomic_t fscache_n_updates_run;
61353+atomic_unchecked_t fscache_n_updates;
61354+atomic_unchecked_t fscache_n_updates_null;
61355+atomic_unchecked_t fscache_n_updates_run;
61356
61357-atomic_t fscache_n_relinquishes;
61358-atomic_t fscache_n_relinquishes_null;
61359-atomic_t fscache_n_relinquishes_waitcrt;
61360-atomic_t fscache_n_relinquishes_retire;
61361+atomic_unchecked_t fscache_n_relinquishes;
61362+atomic_unchecked_t fscache_n_relinquishes_null;
61363+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61364+atomic_unchecked_t fscache_n_relinquishes_retire;
61365
61366-atomic_t fscache_n_cookie_index;
61367-atomic_t fscache_n_cookie_data;
61368-atomic_t fscache_n_cookie_special;
61369+atomic_unchecked_t fscache_n_cookie_index;
61370+atomic_unchecked_t fscache_n_cookie_data;
61371+atomic_unchecked_t fscache_n_cookie_special;
61372
61373-atomic_t fscache_n_object_alloc;
61374-atomic_t fscache_n_object_no_alloc;
61375-atomic_t fscache_n_object_lookups;
61376-atomic_t fscache_n_object_lookups_negative;
61377-atomic_t fscache_n_object_lookups_positive;
61378-atomic_t fscache_n_object_lookups_timed_out;
61379-atomic_t fscache_n_object_created;
61380-atomic_t fscache_n_object_avail;
61381-atomic_t fscache_n_object_dead;
61382+atomic_unchecked_t fscache_n_object_alloc;
61383+atomic_unchecked_t fscache_n_object_no_alloc;
61384+atomic_unchecked_t fscache_n_object_lookups;
61385+atomic_unchecked_t fscache_n_object_lookups_negative;
61386+atomic_unchecked_t fscache_n_object_lookups_positive;
61387+atomic_unchecked_t fscache_n_object_lookups_timed_out;
61388+atomic_unchecked_t fscache_n_object_created;
61389+atomic_unchecked_t fscache_n_object_avail;
61390+atomic_unchecked_t fscache_n_object_dead;
61391
61392-atomic_t fscache_n_checkaux_none;
61393-atomic_t fscache_n_checkaux_okay;
61394-atomic_t fscache_n_checkaux_update;
61395-atomic_t fscache_n_checkaux_obsolete;
61396+atomic_unchecked_t fscache_n_checkaux_none;
61397+atomic_unchecked_t fscache_n_checkaux_okay;
61398+atomic_unchecked_t fscache_n_checkaux_update;
61399+atomic_unchecked_t fscache_n_checkaux_obsolete;
61400
61401 atomic_t fscache_n_cop_alloc_object;
61402 atomic_t fscache_n_cop_lookup_object;
61403@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61404 seq_puts(m, "FS-Cache statistics\n");
61405
61406 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61407- atomic_read(&fscache_n_cookie_index),
61408- atomic_read(&fscache_n_cookie_data),
61409- atomic_read(&fscache_n_cookie_special));
61410+ atomic_read_unchecked(&fscache_n_cookie_index),
61411+ atomic_read_unchecked(&fscache_n_cookie_data),
61412+ atomic_read_unchecked(&fscache_n_cookie_special));
61413
61414 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61415- atomic_read(&fscache_n_object_alloc),
61416- atomic_read(&fscache_n_object_no_alloc),
61417- atomic_read(&fscache_n_object_avail),
61418- atomic_read(&fscache_n_object_dead));
61419+ atomic_read_unchecked(&fscache_n_object_alloc),
61420+ atomic_read_unchecked(&fscache_n_object_no_alloc),
61421+ atomic_read_unchecked(&fscache_n_object_avail),
61422+ atomic_read_unchecked(&fscache_n_object_dead));
61423 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61424- atomic_read(&fscache_n_checkaux_none),
61425- atomic_read(&fscache_n_checkaux_okay),
61426- atomic_read(&fscache_n_checkaux_update),
61427- atomic_read(&fscache_n_checkaux_obsolete));
61428+ atomic_read_unchecked(&fscache_n_checkaux_none),
61429+ atomic_read_unchecked(&fscache_n_checkaux_okay),
61430+ atomic_read_unchecked(&fscache_n_checkaux_update),
61431+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61432
61433 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61434- atomic_read(&fscache_n_marks),
61435- atomic_read(&fscache_n_uncaches));
61436+ atomic_read_unchecked(&fscache_n_marks),
61437+ atomic_read_unchecked(&fscache_n_uncaches));
61438
61439 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61440 " oom=%u\n",
61441- atomic_read(&fscache_n_acquires),
61442- atomic_read(&fscache_n_acquires_null),
61443- atomic_read(&fscache_n_acquires_no_cache),
61444- atomic_read(&fscache_n_acquires_ok),
61445- atomic_read(&fscache_n_acquires_nobufs),
61446- atomic_read(&fscache_n_acquires_oom));
61447+ atomic_read_unchecked(&fscache_n_acquires),
61448+ atomic_read_unchecked(&fscache_n_acquires_null),
61449+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
61450+ atomic_read_unchecked(&fscache_n_acquires_ok),
61451+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
61452+ atomic_read_unchecked(&fscache_n_acquires_oom));
61453
61454 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61455- atomic_read(&fscache_n_object_lookups),
61456- atomic_read(&fscache_n_object_lookups_negative),
61457- atomic_read(&fscache_n_object_lookups_positive),
61458- atomic_read(&fscache_n_object_created),
61459- atomic_read(&fscache_n_object_lookups_timed_out));
61460+ atomic_read_unchecked(&fscache_n_object_lookups),
61461+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
61462+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
61463+ atomic_read_unchecked(&fscache_n_object_created),
61464+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61465
61466 seq_printf(m, "Invals : n=%u run=%u\n",
61467- atomic_read(&fscache_n_invalidates),
61468- atomic_read(&fscache_n_invalidates_run));
61469+ atomic_read_unchecked(&fscache_n_invalidates),
61470+ atomic_read_unchecked(&fscache_n_invalidates_run));
61471
61472 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61473- atomic_read(&fscache_n_updates),
61474- atomic_read(&fscache_n_updates_null),
61475- atomic_read(&fscache_n_updates_run));
61476+ atomic_read_unchecked(&fscache_n_updates),
61477+ atomic_read_unchecked(&fscache_n_updates_null),
61478+ atomic_read_unchecked(&fscache_n_updates_run));
61479
61480 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61481- atomic_read(&fscache_n_relinquishes),
61482- atomic_read(&fscache_n_relinquishes_null),
61483- atomic_read(&fscache_n_relinquishes_waitcrt),
61484- atomic_read(&fscache_n_relinquishes_retire));
61485+ atomic_read_unchecked(&fscache_n_relinquishes),
61486+ atomic_read_unchecked(&fscache_n_relinquishes_null),
61487+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61488+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
61489
61490 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61491- atomic_read(&fscache_n_attr_changed),
61492- atomic_read(&fscache_n_attr_changed_ok),
61493- atomic_read(&fscache_n_attr_changed_nobufs),
61494- atomic_read(&fscache_n_attr_changed_nomem),
61495- atomic_read(&fscache_n_attr_changed_calls));
61496+ atomic_read_unchecked(&fscache_n_attr_changed),
61497+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
61498+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61499+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61500+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
61501
61502 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61503- atomic_read(&fscache_n_allocs),
61504- atomic_read(&fscache_n_allocs_ok),
61505- atomic_read(&fscache_n_allocs_wait),
61506- atomic_read(&fscache_n_allocs_nobufs),
61507- atomic_read(&fscache_n_allocs_intr));
61508+ atomic_read_unchecked(&fscache_n_allocs),
61509+ atomic_read_unchecked(&fscache_n_allocs_ok),
61510+ atomic_read_unchecked(&fscache_n_allocs_wait),
61511+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
61512+ atomic_read_unchecked(&fscache_n_allocs_intr));
61513 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61514- atomic_read(&fscache_n_alloc_ops),
61515- atomic_read(&fscache_n_alloc_op_waits),
61516- atomic_read(&fscache_n_allocs_object_dead));
61517+ atomic_read_unchecked(&fscache_n_alloc_ops),
61518+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
61519+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
61520
61521 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61522 " int=%u oom=%u\n",
61523- atomic_read(&fscache_n_retrievals),
61524- atomic_read(&fscache_n_retrievals_ok),
61525- atomic_read(&fscache_n_retrievals_wait),
61526- atomic_read(&fscache_n_retrievals_nodata),
61527- atomic_read(&fscache_n_retrievals_nobufs),
61528- atomic_read(&fscache_n_retrievals_intr),
61529- atomic_read(&fscache_n_retrievals_nomem));
61530+ atomic_read_unchecked(&fscache_n_retrievals),
61531+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61532+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61533+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61534+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61535+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61536+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61537 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61538- atomic_read(&fscache_n_retrieval_ops),
61539- atomic_read(&fscache_n_retrieval_op_waits),
61540- atomic_read(&fscache_n_retrievals_object_dead));
61541+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61542+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61543+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61544
61545 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61546- atomic_read(&fscache_n_stores),
61547- atomic_read(&fscache_n_stores_ok),
61548- atomic_read(&fscache_n_stores_again),
61549- atomic_read(&fscache_n_stores_nobufs),
61550- atomic_read(&fscache_n_stores_oom));
61551+ atomic_read_unchecked(&fscache_n_stores),
61552+ atomic_read_unchecked(&fscache_n_stores_ok),
61553+ atomic_read_unchecked(&fscache_n_stores_again),
61554+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61555+ atomic_read_unchecked(&fscache_n_stores_oom));
61556 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61557- atomic_read(&fscache_n_store_ops),
61558- atomic_read(&fscache_n_store_calls),
61559- atomic_read(&fscache_n_store_pages),
61560- atomic_read(&fscache_n_store_radix_deletes),
61561- atomic_read(&fscache_n_store_pages_over_limit));
61562+ atomic_read_unchecked(&fscache_n_store_ops),
61563+ atomic_read_unchecked(&fscache_n_store_calls),
61564+ atomic_read_unchecked(&fscache_n_store_pages),
61565+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61566+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61567
61568 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61569- atomic_read(&fscache_n_store_vmscan_not_storing),
61570- atomic_read(&fscache_n_store_vmscan_gone),
61571- atomic_read(&fscache_n_store_vmscan_busy),
61572- atomic_read(&fscache_n_store_vmscan_cancelled),
61573- atomic_read(&fscache_n_store_vmscan_wait));
61574+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61575+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61576+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61577+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61578+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61579
61580 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61581- atomic_read(&fscache_n_op_pend),
61582- atomic_read(&fscache_n_op_run),
61583- atomic_read(&fscache_n_op_enqueue),
61584- atomic_read(&fscache_n_op_cancelled),
61585- atomic_read(&fscache_n_op_rejected));
61586+ atomic_read_unchecked(&fscache_n_op_pend),
61587+ atomic_read_unchecked(&fscache_n_op_run),
61588+ atomic_read_unchecked(&fscache_n_op_enqueue),
61589+ atomic_read_unchecked(&fscache_n_op_cancelled),
61590+ atomic_read_unchecked(&fscache_n_op_rejected));
61591 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61592- atomic_read(&fscache_n_op_deferred_release),
61593- atomic_read(&fscache_n_op_release),
61594- atomic_read(&fscache_n_op_gc));
61595+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61596+ atomic_read_unchecked(&fscache_n_op_release),
61597+ atomic_read_unchecked(&fscache_n_op_gc));
61598
61599 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61600 atomic_read(&fscache_n_cop_alloc_object),
61601diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61602index 13b691a..1ffca5ae 100644
61603--- a/fs/fuse/cuse.c
61604+++ b/fs/fuse/cuse.c
61605@@ -607,10 +607,12 @@ static int __init cuse_init(void)
61606 INIT_LIST_HEAD(&cuse_conntbl[i]);
61607
61608 /* inherit and extend fuse_dev_operations */
61609- cuse_channel_fops = fuse_dev_operations;
61610- cuse_channel_fops.owner = THIS_MODULE;
61611- cuse_channel_fops.open = cuse_channel_open;
61612- cuse_channel_fops.release = cuse_channel_release;
61613+ pax_open_kernel();
61614+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61615+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61616+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61617+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61618+ pax_close_kernel();
61619
61620 cuse_class = class_create(THIS_MODULE, "cuse");
61621 if (IS_ERR(cuse_class))
61622diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61623index 75fa055..73b76d8 100644
61624--- a/fs/fuse/dev.c
61625+++ b/fs/fuse/dev.c
61626@@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61627 ret = 0;
61628 pipe_lock(pipe);
61629
61630- if (!pipe->readers) {
61631+ if (!atomic_read(&pipe->readers)) {
61632 send_sig(SIGPIPE, current, 0);
61633 if (!ret)
61634 ret = -EPIPE;
61635@@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61636 page_nr++;
61637 ret += buf->len;
61638
61639- if (pipe->files)
61640+ if (atomic_read(&pipe->files))
61641 do_wakeup = 1;
61642 }
61643
61644diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61645index 202a972..c4836eb 100644
61646--- a/fs/fuse/dir.c
61647+++ b/fs/fuse/dir.c
61648@@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
61649 return link;
61650 }
61651
61652-static void free_link(char *link)
61653+static void free_link(const char *link)
61654 {
61655 if (!IS_ERR(link))
61656 free_page((unsigned long) link);
61657diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61658index 9c470fd..aae410e 100644
61659--- a/fs/hostfs/hostfs_kern.c
61660+++ b/fs/hostfs/hostfs_kern.c
61661@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61662
61663 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61664 {
61665- char *s = nd_get_link(nd);
61666+ const char *s = nd_get_link(nd);
61667 if (!IS_ERR(s))
61668 __putname(s);
61669 }
61670diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61671index e19d4c0..8a357a9 100644
61672--- a/fs/hugetlbfs/inode.c
61673+++ b/fs/hugetlbfs/inode.c
61674@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61675 struct mm_struct *mm = current->mm;
61676 struct vm_area_struct *vma;
61677 struct hstate *h = hstate_file(file);
61678+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61679 struct vm_unmapped_area_info info;
61680
61681 if (len & ~huge_page_mask(h))
61682@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61683 return addr;
61684 }
61685
61686+#ifdef CONFIG_PAX_RANDMMAP
61687+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61688+#endif
61689+
61690 if (addr) {
61691 addr = ALIGN(addr, huge_page_size(h));
61692 vma = find_vma(mm, addr);
61693- if (TASK_SIZE - len >= addr &&
61694- (!vma || addr + len <= vma->vm_start))
61695+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61696 return addr;
61697 }
61698
61699 info.flags = 0;
61700 info.length = len;
61701 info.low_limit = TASK_UNMAPPED_BASE;
61702+
61703+#ifdef CONFIG_PAX_RANDMMAP
61704+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61705+ info.low_limit += mm->delta_mmap;
61706+#endif
61707+
61708 info.high_limit = TASK_SIZE;
61709 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61710 info.align_offset = 0;
61711@@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61712 };
61713 MODULE_ALIAS_FS("hugetlbfs");
61714
61715-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61716+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61717
61718 static int can_do_hugetlb_shm(void)
61719 {
61720diff --git a/fs/inode.c b/fs/inode.c
61721index d2fb2f2..a6444b0 100644
61722--- a/fs/inode.c
61723+++ b/fs/inode.c
61724@@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61725 unsigned int *p = &get_cpu_var(last_ino);
61726 unsigned int res = *p;
61727
61728+start:
61729+
61730 #ifdef CONFIG_SMP
61731 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61732- static atomic_t shared_last_ino;
61733- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61734+ static atomic_unchecked_t shared_last_ino;
61735+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61736
61737 res = next - LAST_INO_BATCH;
61738 }
61739 #endif
61740
61741- *p = ++res;
61742+ if (unlikely(!++res))
61743+ goto start; /* never zero */
61744+ *p = res;
61745 put_cpu_var(last_ino);
61746 return res;
61747 }
61748diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
61749index 4556ce1..5ddaf86 100644
61750--- a/fs/isofs/inode.c
61751+++ b/fs/isofs/inode.c
61752@@ -61,7 +61,7 @@ static void isofs_put_super(struct super_block *sb)
61753 return;
61754 }
61755
61756-static int isofs_read_inode(struct inode *);
61757+static int isofs_read_inode(struct inode *, int relocated);
61758 static int isofs_statfs (struct dentry *, struct kstatfs *);
61759
61760 static struct kmem_cache *isofs_inode_cachep;
61761@@ -1259,7 +1259,7 @@ out_toomany:
61762 goto out;
61763 }
61764
61765-static int isofs_read_inode(struct inode *inode)
61766+static int isofs_read_inode(struct inode *inode, int relocated)
61767 {
61768 struct super_block *sb = inode->i_sb;
61769 struct isofs_sb_info *sbi = ISOFS_SB(sb);
61770@@ -1404,7 +1404,7 @@ static int isofs_read_inode(struct inode *inode)
61771 */
61772
61773 if (!high_sierra) {
61774- parse_rock_ridge_inode(de, inode);
61775+ parse_rock_ridge_inode(de, inode, relocated);
61776 /* if we want uid/gid set, override the rock ridge setting */
61777 if (sbi->s_uid_set)
61778 inode->i_uid = sbi->s_uid;
61779@@ -1483,9 +1483,10 @@ static int isofs_iget5_set(struct inode *ino, void *data)
61780 * offset that point to the underlying meta-data for the inode. The
61781 * code below is otherwise similar to the iget() code in
61782 * include/linux/fs.h */
61783-struct inode *isofs_iget(struct super_block *sb,
61784- unsigned long block,
61785- unsigned long offset)
61786+struct inode *__isofs_iget(struct super_block *sb,
61787+ unsigned long block,
61788+ unsigned long offset,
61789+ int relocated)
61790 {
61791 unsigned long hashval;
61792 struct inode *inode;
61793@@ -1507,7 +1508,7 @@ struct inode *isofs_iget(struct super_block *sb,
61794 return ERR_PTR(-ENOMEM);
61795
61796 if (inode->i_state & I_NEW) {
61797- ret = isofs_read_inode(inode);
61798+ ret = isofs_read_inode(inode, relocated);
61799 if (ret < 0) {
61800 iget_failed(inode);
61801 inode = ERR_PTR(ret);
61802diff --git a/fs/isofs/isofs.h b/fs/isofs/isofs.h
61803index 9916723..0ac4c1f 100644
61804--- a/fs/isofs/isofs.h
61805+++ b/fs/isofs/isofs.h
61806@@ -107,7 +107,7 @@ extern int iso_date(char *, int);
61807
61808 struct inode; /* To make gcc happy */
61809
61810-extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *);
61811+extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
61812 extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
61813 extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
61814
61815@@ -118,9 +118,24 @@ extern struct dentry *isofs_lookup(struct inode *, struct dentry *, unsigned int
61816 extern struct buffer_head *isofs_bread(struct inode *, sector_t);
61817 extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
61818
61819-extern struct inode *isofs_iget(struct super_block *sb,
61820- unsigned long block,
61821- unsigned long offset);
61822+struct inode *__isofs_iget(struct super_block *sb,
61823+ unsigned long block,
61824+ unsigned long offset,
61825+ int relocated);
61826+
61827+static inline struct inode *isofs_iget(struct super_block *sb,
61828+ unsigned long block,
61829+ unsigned long offset)
61830+{
61831+ return __isofs_iget(sb, block, offset, 0);
61832+}
61833+
61834+static inline struct inode *isofs_iget_reloc(struct super_block *sb,
61835+ unsigned long block,
61836+ unsigned long offset)
61837+{
61838+ return __isofs_iget(sb, block, offset, 1);
61839+}
61840
61841 /* Because the inode number is no longer relevant to finding the
61842 * underlying meta-data for an inode, we are free to choose a more
61843diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
61844index c0bf424..f488bba 100644
61845--- a/fs/isofs/rock.c
61846+++ b/fs/isofs/rock.c
61847@@ -288,12 +288,16 @@ eio:
61848 goto out;
61849 }
61850
61851+#define RR_REGARD_XA 1
61852+#define RR_RELOC_DE 2
61853+
61854 static int
61855 parse_rock_ridge_inode_internal(struct iso_directory_record *de,
61856- struct inode *inode, int regard_xa)
61857+ struct inode *inode, int flags)
61858 {
61859 int symlink_len = 0;
61860 int cnt, sig;
61861+ unsigned int reloc_block;
61862 struct inode *reloc;
61863 struct rock_ridge *rr;
61864 int rootflag;
61865@@ -305,7 +309,7 @@ parse_rock_ridge_inode_internal(struct iso_directory_record *de,
61866
61867 init_rock_state(&rs, inode);
61868 setup_rock_ridge(de, inode, &rs);
61869- if (regard_xa) {
61870+ if (flags & RR_REGARD_XA) {
61871 rs.chr += 14;
61872 rs.len -= 14;
61873 if (rs.len < 0)
61874@@ -485,12 +489,22 @@ repeat:
61875 "relocated directory\n");
61876 goto out;
61877 case SIG('C', 'L'):
61878- ISOFS_I(inode)->i_first_extent =
61879- isonum_733(rr->u.CL.location);
61880- reloc =
61881- isofs_iget(inode->i_sb,
61882- ISOFS_I(inode)->i_first_extent,
61883- 0);
61884+ if (flags & RR_RELOC_DE) {
61885+ printk(KERN_ERR
61886+ "ISOFS: Recursive directory relocation "
61887+ "is not supported\n");
61888+ goto eio;
61889+ }
61890+ reloc_block = isonum_733(rr->u.CL.location);
61891+ if (reloc_block == ISOFS_I(inode)->i_iget5_block &&
61892+ ISOFS_I(inode)->i_iget5_offset == 0) {
61893+ printk(KERN_ERR
61894+ "ISOFS: Directory relocation points to "
61895+ "itself\n");
61896+ goto eio;
61897+ }
61898+ ISOFS_I(inode)->i_first_extent = reloc_block;
61899+ reloc = isofs_iget_reloc(inode->i_sb, reloc_block, 0);
61900 if (IS_ERR(reloc)) {
61901 ret = PTR_ERR(reloc);
61902 goto out;
61903@@ -637,9 +651,11 @@ static char *get_symlink_chunk(char *rpnt, struct rock_ridge *rr, char *plimit)
61904 return rpnt;
61905 }
61906
61907-int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode)
61908+int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode,
61909+ int relocated)
61910 {
61911- int result = parse_rock_ridge_inode_internal(de, inode, 0);
61912+ int flags = relocated ? RR_RELOC_DE : 0;
61913+ int result = parse_rock_ridge_inode_internal(de, inode, flags);
61914
61915 /*
61916 * if rockridge flag was reset and we didn't look for attributes
61917@@ -647,7 +663,8 @@ int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode)
61918 */
61919 if ((ISOFS_SB(inode->i_sb)->s_rock_offset == -1)
61920 && (ISOFS_SB(inode->i_sb)->s_rock == 2)) {
61921- result = parse_rock_ridge_inode_internal(de, inode, 14);
61922+ result = parse_rock_ridge_inode_internal(de, inode,
61923+ flags | RR_REGARD_XA);
61924 }
61925 return result;
61926 }
61927diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61928index 4a6cf28..d3a29d3 100644
61929--- a/fs/jffs2/erase.c
61930+++ b/fs/jffs2/erase.c
61931@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61932 struct jffs2_unknown_node marker = {
61933 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61934 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61935- .totlen = cpu_to_je32(c->cleanmarker_size)
61936+ .totlen = cpu_to_je32(c->cleanmarker_size),
61937+ .hdr_crc = cpu_to_je32(0)
61938 };
61939
61940 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61941diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61942index a6597d6..41b30ec 100644
61943--- a/fs/jffs2/wbuf.c
61944+++ b/fs/jffs2/wbuf.c
61945@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61946 {
61947 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61948 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61949- .totlen = constant_cpu_to_je32(8)
61950+ .totlen = constant_cpu_to_je32(8),
61951+ .hdr_crc = constant_cpu_to_je32(0)
61952 };
61953
61954 /*
61955diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61956index 97f7fda..09bd33d 100644
61957--- a/fs/jfs/super.c
61958+++ b/fs/jfs/super.c
61959@@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61960
61961 jfs_inode_cachep =
61962 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61963- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61964+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61965 init_once);
61966 if (jfs_inode_cachep == NULL)
61967 return -ENOMEM;
61968diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61969index a693f5b..82276a1 100644
61970--- a/fs/kernfs/dir.c
61971+++ b/fs/kernfs/dir.c
61972@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61973 *
61974 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61975 */
61976-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61977+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61978 {
61979 unsigned long hash = init_name_hash();
61980 unsigned int len = strlen(name);
61981diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61982index 5e9a80c..3853a24 100644
61983--- a/fs/kernfs/file.c
61984+++ b/fs/kernfs/file.c
61985@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61986
61987 struct kernfs_open_node {
61988 atomic_t refcnt;
61989- atomic_t event;
61990+ atomic_unchecked_t event;
61991 wait_queue_head_t poll;
61992 struct list_head files; /* goes through kernfs_open_file.list */
61993 };
61994@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61995 {
61996 struct kernfs_open_file *of = sf->private;
61997
61998- of->event = atomic_read(&of->kn->attr.open->event);
61999+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
62000
62001 return of->kn->attr.ops->seq_show(sf, v);
62002 }
62003@@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
62004 return ret;
62005 }
62006
62007-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
62008- void *buf, int len, int write)
62009+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
62010+ void *buf, size_t len, int write)
62011 {
62012 struct file *file = vma->vm_file;
62013 struct kernfs_open_file *of = kernfs_of(file);
62014- int ret;
62015+ ssize_t ret;
62016
62017 if (!of->vm_ops)
62018 return -EINVAL;
62019@@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
62020 return -ENOMEM;
62021
62022 atomic_set(&new_on->refcnt, 0);
62023- atomic_set(&new_on->event, 1);
62024+ atomic_set_unchecked(&new_on->event, 1);
62025 init_waitqueue_head(&new_on->poll);
62026 INIT_LIST_HEAD(&new_on->files);
62027 goto retry;
62028@@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
62029
62030 kernfs_put_active(kn);
62031
62032- if (of->event != atomic_read(&on->event))
62033+ if (of->event != atomic_read_unchecked(&on->event))
62034 goto trigger;
62035
62036 return DEFAULT_POLLMASK;
62037@@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
62038 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
62039 on = kn->attr.open;
62040 if (on) {
62041- atomic_inc(&on->event);
62042+ atomic_inc_unchecked(&on->event);
62043 wake_up_interruptible(&on->poll);
62044 }
62045 }
62046diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
62047index 8a19889..4c3069a 100644
62048--- a/fs/kernfs/symlink.c
62049+++ b/fs/kernfs/symlink.c
62050@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
62051 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
62052 void *cookie)
62053 {
62054- char *page = nd_get_link(nd);
62055+ const char *page = nd_get_link(nd);
62056 if (!IS_ERR(page))
62057 free_page((unsigned long)page);
62058 }
62059diff --git a/fs/libfs.c b/fs/libfs.c
62060index a184424..944ddce 100644
62061--- a/fs/libfs.c
62062+++ b/fs/libfs.c
62063@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
62064
62065 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
62066 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
62067+ char d_name[sizeof(next->d_iname)];
62068+ const unsigned char *name;
62069+
62070 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
62071 if (!simple_positive(next)) {
62072 spin_unlock(&next->d_lock);
62073@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
62074
62075 spin_unlock(&next->d_lock);
62076 spin_unlock(&dentry->d_lock);
62077- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
62078+ name = next->d_name.name;
62079+ if (name == next->d_iname) {
62080+ memcpy(d_name, name, next->d_name.len);
62081+ name = d_name;
62082+ }
62083+ if (!dir_emit(ctx, name, next->d_name.len,
62084 next->d_inode->i_ino, dt_type(next->d_inode)))
62085 return 0;
62086 spin_lock(&dentry->d_lock);
62087@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
62088 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
62089 void *cookie)
62090 {
62091- char *s = nd_get_link(nd);
62092+ const char *s = nd_get_link(nd);
62093 if (!IS_ERR(s))
62094 kfree(s);
62095 }
62096diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
62097index acd3947..1f896e2 100644
62098--- a/fs/lockd/clntproc.c
62099+++ b/fs/lockd/clntproc.c
62100@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
62101 /*
62102 * Cookie counter for NLM requests
62103 */
62104-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
62105+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
62106
62107 void nlmclnt_next_cookie(struct nlm_cookie *c)
62108 {
62109- u32 cookie = atomic_inc_return(&nlm_cookie);
62110+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
62111
62112 memcpy(c->data, &cookie, 4);
62113 c->len=4;
62114diff --git a/fs/locks.c b/fs/locks.c
62115index e390bd9..c79870e 100644
62116--- a/fs/locks.c
62117+++ b/fs/locks.c
62118@@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
62119 locks_remove_posix(filp, (fl_owner_t)filp);
62120
62121 if (filp->f_op->flock) {
62122- struct file_lock fl = {
62123+ struct file_lock flock = {
62124 .fl_pid = current->tgid,
62125 .fl_file = filp,
62126 .fl_flags = FL_FLOCK,
62127 .fl_type = F_UNLCK,
62128 .fl_end = OFFSET_MAX,
62129 };
62130- filp->f_op->flock(filp, F_SETLKW, &fl);
62131- if (fl.fl_ops && fl.fl_ops->fl_release_private)
62132- fl.fl_ops->fl_release_private(&fl);
62133+ filp->f_op->flock(filp, F_SETLKW, &flock);
62134+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
62135+ flock.fl_ops->fl_release_private(&flock);
62136 }
62137
62138 spin_lock(&inode->i_lock);
62139diff --git a/fs/mount.h b/fs/mount.h
62140index d55297f..f5b28c5 100644
62141--- a/fs/mount.h
62142+++ b/fs/mount.h
62143@@ -11,7 +11,7 @@ struct mnt_namespace {
62144 u64 seq; /* Sequence number to prevent loops */
62145 wait_queue_head_t poll;
62146 u64 event;
62147-};
62148+} __randomize_layout;
62149
62150 struct mnt_pcp {
62151 int mnt_count;
62152@@ -57,7 +57,7 @@ struct mount {
62153 int mnt_expiry_mark; /* true if marked for expiry */
62154 int mnt_pinned;
62155 struct path mnt_ex_mountpoint;
62156-};
62157+} __randomize_layout;
62158
62159 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
62160
62161diff --git a/fs/namei.c b/fs/namei.c
62162index 9eb787e..5f520b67 100644
62163--- a/fs/namei.c
62164+++ b/fs/namei.c
62165@@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
62166 if (ret != -EACCES)
62167 return ret;
62168
62169+#ifdef CONFIG_GRKERNSEC
62170+ /* we'll block if we have to log due to a denied capability use */
62171+ if (mask & MAY_NOT_BLOCK)
62172+ return -ECHILD;
62173+#endif
62174+
62175 if (S_ISDIR(inode->i_mode)) {
62176 /* DACs are overridable for directories */
62177- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
62178- return 0;
62179 if (!(mask & MAY_WRITE))
62180- if (capable_wrt_inode_uidgid(inode,
62181- CAP_DAC_READ_SEARCH))
62182+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
62183+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
62184 return 0;
62185+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
62186+ return 0;
62187 return -EACCES;
62188 }
62189 /*
62190+ * Searching includes executable on directories, else just read.
62191+ */
62192+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
62193+ if (mask == MAY_READ)
62194+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
62195+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
62196+ return 0;
62197+
62198+ /*
62199 * Read/write DACs are always overridable.
62200 * Executable DACs are overridable when there is
62201 * at least one exec bit set.
62202@@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
62203 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
62204 return 0;
62205
62206- /*
62207- * Searching includes executable on directories, else just read.
62208- */
62209- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
62210- if (mask == MAY_READ)
62211- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
62212- return 0;
62213-
62214 return -EACCES;
62215 }
62216 EXPORT_SYMBOL(generic_permission);
62217@@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
62218 {
62219 struct dentry *dentry = link->dentry;
62220 int error;
62221- char *s;
62222+ const char *s;
62223
62224 BUG_ON(nd->flags & LOOKUP_RCU);
62225
62226@@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
62227 if (error)
62228 goto out_put_nd_path;
62229
62230+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
62231+ dentry->d_inode, dentry, nd->path.mnt)) {
62232+ error = -EACCES;
62233+ goto out_put_nd_path;
62234+ }
62235+
62236 nd->last_type = LAST_BIND;
62237 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
62238 error = PTR_ERR(*p);
62239@@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
62240 if (res)
62241 break;
62242 res = walk_component(nd, path, LOOKUP_FOLLOW);
62243+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
62244+ res = -EACCES;
62245 put_link(nd, &link, cookie);
62246 } while (res > 0);
62247
62248@@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
62249 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
62250 {
62251 unsigned long a, b, adata, bdata, mask, hash, len;
62252- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
62253+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
62254
62255 hash = a = 0;
62256 len = -sizeof(unsigned long);
62257@@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
62258 if (err)
62259 break;
62260 err = lookup_last(nd, &path);
62261+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
62262+ err = -EACCES;
62263 put_link(nd, &link, cookie);
62264 }
62265 }
62266@@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
62267 if (!err)
62268 err = complete_walk(nd);
62269
62270+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
62271+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62272+ path_put(&nd->path);
62273+ err = -ENOENT;
62274+ }
62275+ }
62276+
62277 if (!err && nd->flags & LOOKUP_DIRECTORY) {
62278 if (!d_can_lookup(nd->path.dentry)) {
62279 path_put(&nd->path);
62280@@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
62281 retval = path_lookupat(dfd, name->name,
62282 flags | LOOKUP_REVAL, nd);
62283
62284- if (likely(!retval))
62285+ if (likely(!retval)) {
62286 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
62287+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
62288+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
62289+ path_put(&nd->path);
62290+ return -ENOENT;
62291+ }
62292+ }
62293+ }
62294 return retval;
62295 }
62296
62297@@ -2570,6 +2601,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
62298 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
62299 return -EPERM;
62300
62301+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
62302+ return -EPERM;
62303+ if (gr_handle_rawio(inode))
62304+ return -EPERM;
62305+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
62306+ return -EACCES;
62307+
62308 return 0;
62309 }
62310
62311@@ -2801,7 +2839,7 @@ looked_up:
62312 * cleared otherwise prior to returning.
62313 */
62314 static int lookup_open(struct nameidata *nd, struct path *path,
62315- struct file *file,
62316+ struct path *link, struct file *file,
62317 const struct open_flags *op,
62318 bool got_write, int *opened)
62319 {
62320@@ -2836,6 +2874,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62321 /* Negative dentry, just create the file */
62322 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
62323 umode_t mode = op->mode;
62324+
62325+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
62326+ error = -EACCES;
62327+ goto out_dput;
62328+ }
62329+
62330+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
62331+ error = -EACCES;
62332+ goto out_dput;
62333+ }
62334+
62335 if (!IS_POSIXACL(dir->d_inode))
62336 mode &= ~current_umask();
62337 /*
62338@@ -2857,6 +2906,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62339 nd->flags & LOOKUP_EXCL);
62340 if (error)
62341 goto out_dput;
62342+ else
62343+ gr_handle_create(dentry, nd->path.mnt);
62344 }
62345 out_no_open:
62346 path->dentry = dentry;
62347@@ -2871,7 +2922,7 @@ out_dput:
62348 /*
62349 * Handle the last step of open()
62350 */
62351-static int do_last(struct nameidata *nd, struct path *path,
62352+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62353 struct file *file, const struct open_flags *op,
62354 int *opened, struct filename *name)
62355 {
62356@@ -2921,6 +2972,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62357 if (error)
62358 return error;
62359
62360+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62361+ error = -ENOENT;
62362+ goto out;
62363+ }
62364+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62365+ error = -EACCES;
62366+ goto out;
62367+ }
62368+
62369 audit_inode(name, dir, LOOKUP_PARENT);
62370 error = -EISDIR;
62371 /* trailing slashes? */
62372@@ -2940,7 +3000,7 @@ retry_lookup:
62373 */
62374 }
62375 mutex_lock(&dir->d_inode->i_mutex);
62376- error = lookup_open(nd, path, file, op, got_write, opened);
62377+ error = lookup_open(nd, path, link, file, op, got_write, opened);
62378 mutex_unlock(&dir->d_inode->i_mutex);
62379
62380 if (error <= 0) {
62381@@ -2964,11 +3024,28 @@ retry_lookup:
62382 goto finish_open_created;
62383 }
62384
62385+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62386+ error = -ENOENT;
62387+ goto exit_dput;
62388+ }
62389+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62390+ error = -EACCES;
62391+ goto exit_dput;
62392+ }
62393+
62394 /*
62395 * create/update audit record if it already exists.
62396 */
62397- if (d_is_positive(path->dentry))
62398+ if (d_is_positive(path->dentry)) {
62399+ /* only check if O_CREAT is specified, all other checks need to go
62400+ into may_open */
62401+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62402+ error = -EACCES;
62403+ goto exit_dput;
62404+ }
62405+
62406 audit_inode(name, path->dentry, 0);
62407+ }
62408
62409 /*
62410 * If atomic_open() acquired write access it is dropped now due to
62411@@ -3009,6 +3086,11 @@ finish_lookup:
62412 }
62413 }
62414 BUG_ON(inode != path->dentry->d_inode);
62415+ /* if we're resolving a symlink to another symlink */
62416+ if (link && gr_handle_symlink_owner(link, inode)) {
62417+ error = -EACCES;
62418+ goto out;
62419+ }
62420 return 1;
62421 }
62422
62423@@ -3018,7 +3100,6 @@ finish_lookup:
62424 save_parent.dentry = nd->path.dentry;
62425 save_parent.mnt = mntget(path->mnt);
62426 nd->path.dentry = path->dentry;
62427-
62428 }
62429 nd->inode = inode;
62430 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62431@@ -3028,7 +3109,18 @@ finish_open:
62432 path_put(&save_parent);
62433 return error;
62434 }
62435+
62436+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62437+ error = -ENOENT;
62438+ goto out;
62439+ }
62440+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62441+ error = -EACCES;
62442+ goto out;
62443+ }
62444+
62445 audit_inode(name, nd->path.dentry, 0);
62446+
62447 error = -EISDIR;
62448 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
62449 goto out;
62450@@ -3191,7 +3283,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62451 if (unlikely(error))
62452 goto out;
62453
62454- error = do_last(nd, &path, file, op, &opened, pathname);
62455+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62456 while (unlikely(error > 0)) { /* trailing symlink */
62457 struct path link = path;
62458 void *cookie;
62459@@ -3209,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62460 error = follow_link(&link, nd, &cookie);
62461 if (unlikely(error))
62462 break;
62463- error = do_last(nd, &path, file, op, &opened, pathname);
62464+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
62465 put_link(nd, &link, cookie);
62466 }
62467 out:
62468@@ -3309,9 +3401,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62469 goto unlock;
62470
62471 error = -EEXIST;
62472- if (d_is_positive(dentry))
62473+ if (d_is_positive(dentry)) {
62474+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62475+ error = -ENOENT;
62476 goto fail;
62477-
62478+ }
62479 /*
62480 * Special case - lookup gave negative, but... we had foo/bar/
62481 * From the vfs_mknod() POV we just have a negative dentry -
62482@@ -3363,6 +3457,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62483 }
62484 EXPORT_SYMBOL(user_path_create);
62485
62486+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62487+{
62488+ struct filename *tmp = getname(pathname);
62489+ struct dentry *res;
62490+ if (IS_ERR(tmp))
62491+ return ERR_CAST(tmp);
62492+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62493+ if (IS_ERR(res))
62494+ putname(tmp);
62495+ else
62496+ *to = tmp;
62497+ return res;
62498+}
62499+
62500 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62501 {
62502 int error = may_create(dir, dentry);
62503@@ -3426,6 +3534,17 @@ retry:
62504
62505 if (!IS_POSIXACL(path.dentry->d_inode))
62506 mode &= ~current_umask();
62507+
62508+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62509+ error = -EPERM;
62510+ goto out;
62511+ }
62512+
62513+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62514+ error = -EACCES;
62515+ goto out;
62516+ }
62517+
62518 error = security_path_mknod(&path, dentry, mode, dev);
62519 if (error)
62520 goto out;
62521@@ -3442,6 +3561,8 @@ retry:
62522 break;
62523 }
62524 out:
62525+ if (!error)
62526+ gr_handle_create(dentry, path.mnt);
62527 done_path_create(&path, dentry);
62528 if (retry_estale(error, lookup_flags)) {
62529 lookup_flags |= LOOKUP_REVAL;
62530@@ -3495,9 +3616,16 @@ retry:
62531
62532 if (!IS_POSIXACL(path.dentry->d_inode))
62533 mode &= ~current_umask();
62534+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62535+ error = -EACCES;
62536+ goto out;
62537+ }
62538 error = security_path_mkdir(&path, dentry, mode);
62539 if (!error)
62540 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62541+ if (!error)
62542+ gr_handle_create(dentry, path.mnt);
62543+out:
62544 done_path_create(&path, dentry);
62545 if (retry_estale(error, lookup_flags)) {
62546 lookup_flags |= LOOKUP_REVAL;
62547@@ -3580,6 +3708,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62548 struct filename *name;
62549 struct dentry *dentry;
62550 struct nameidata nd;
62551+ ino_t saved_ino = 0;
62552+ dev_t saved_dev = 0;
62553 unsigned int lookup_flags = 0;
62554 retry:
62555 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62556@@ -3612,10 +3742,21 @@ retry:
62557 error = -ENOENT;
62558 goto exit3;
62559 }
62560+
62561+ saved_ino = dentry->d_inode->i_ino;
62562+ saved_dev = gr_get_dev_from_dentry(dentry);
62563+
62564+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62565+ error = -EACCES;
62566+ goto exit3;
62567+ }
62568+
62569 error = security_path_rmdir(&nd.path, dentry);
62570 if (error)
62571 goto exit3;
62572 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62573+ if (!error && (saved_dev || saved_ino))
62574+ gr_handle_delete(saved_ino, saved_dev);
62575 exit3:
62576 dput(dentry);
62577 exit2:
62578@@ -3706,6 +3847,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62579 struct nameidata nd;
62580 struct inode *inode = NULL;
62581 struct inode *delegated_inode = NULL;
62582+ ino_t saved_ino = 0;
62583+ dev_t saved_dev = 0;
62584 unsigned int lookup_flags = 0;
62585 retry:
62586 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62587@@ -3732,10 +3875,22 @@ retry_deleg:
62588 if (d_is_negative(dentry))
62589 goto slashes;
62590 ihold(inode);
62591+
62592+ if (inode->i_nlink <= 1) {
62593+ saved_ino = inode->i_ino;
62594+ saved_dev = gr_get_dev_from_dentry(dentry);
62595+ }
62596+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62597+ error = -EACCES;
62598+ goto exit2;
62599+ }
62600+
62601 error = security_path_unlink(&nd.path, dentry);
62602 if (error)
62603 goto exit2;
62604 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62605+ if (!error && (saved_ino || saved_dev))
62606+ gr_handle_delete(saved_ino, saved_dev);
62607 exit2:
62608 dput(dentry);
62609 }
62610@@ -3824,9 +3979,17 @@ retry:
62611 if (IS_ERR(dentry))
62612 goto out_putname;
62613
62614+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62615+ error = -EACCES;
62616+ goto out;
62617+ }
62618+
62619 error = security_path_symlink(&path, dentry, from->name);
62620 if (!error)
62621 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62622+ if (!error)
62623+ gr_handle_create(dentry, path.mnt);
62624+out:
62625 done_path_create(&path, dentry);
62626 if (retry_estale(error, lookup_flags)) {
62627 lookup_flags |= LOOKUP_REVAL;
62628@@ -3930,6 +4093,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62629 struct dentry *new_dentry;
62630 struct path old_path, new_path;
62631 struct inode *delegated_inode = NULL;
62632+ struct filename *to = NULL;
62633 int how = 0;
62634 int error;
62635
62636@@ -3953,7 +4117,7 @@ retry:
62637 if (error)
62638 return error;
62639
62640- new_dentry = user_path_create(newdfd, newname, &new_path,
62641+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62642 (how & LOOKUP_REVAL));
62643 error = PTR_ERR(new_dentry);
62644 if (IS_ERR(new_dentry))
62645@@ -3965,11 +4129,28 @@ retry:
62646 error = may_linkat(&old_path);
62647 if (unlikely(error))
62648 goto out_dput;
62649+
62650+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62651+ old_path.dentry->d_inode,
62652+ old_path.dentry->d_inode->i_mode, to)) {
62653+ error = -EACCES;
62654+ goto out_dput;
62655+ }
62656+
62657+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62658+ old_path.dentry, old_path.mnt, to)) {
62659+ error = -EACCES;
62660+ goto out_dput;
62661+ }
62662+
62663 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62664 if (error)
62665 goto out_dput;
62666 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62667+ if (!error)
62668+ gr_handle_create(new_dentry, new_path.mnt);
62669 out_dput:
62670+ putname(to);
62671 done_path_create(&new_path, new_dentry);
62672 if (delegated_inode) {
62673 error = break_deleg_wait(&delegated_inode);
62674@@ -4279,6 +4460,12 @@ retry_deleg:
62675 if (new_dentry == trap)
62676 goto exit5;
62677
62678+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62679+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
62680+ to, flags);
62681+ if (error)
62682+ goto exit5;
62683+
62684 error = security_path_rename(&oldnd.path, old_dentry,
62685 &newnd.path, new_dentry, flags);
62686 if (error)
62687@@ -4286,6 +4473,9 @@ retry_deleg:
62688 error = vfs_rename(old_dir->d_inode, old_dentry,
62689 new_dir->d_inode, new_dentry,
62690 &delegated_inode, flags);
62691+ if (!error)
62692+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62693+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
62694 exit5:
62695 dput(new_dentry);
62696 exit4:
62697@@ -4328,14 +4518,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62698
62699 int readlink_copy(char __user *buffer, int buflen, const char *link)
62700 {
62701+ char tmpbuf[64];
62702+ const char *newlink;
62703 int len = PTR_ERR(link);
62704+
62705 if (IS_ERR(link))
62706 goto out;
62707
62708 len = strlen(link);
62709 if (len > (unsigned) buflen)
62710 len = buflen;
62711- if (copy_to_user(buffer, link, len))
62712+
62713+ if (len < sizeof(tmpbuf)) {
62714+ memcpy(tmpbuf, link, len);
62715+ newlink = tmpbuf;
62716+ } else
62717+ newlink = link;
62718+
62719+ if (copy_to_user(buffer, newlink, len))
62720 len = -EFAULT;
62721 out:
62722 return len;
62723diff --git a/fs/namespace.c b/fs/namespace.c
62724index 182bc41..72e3cf1 100644
62725--- a/fs/namespace.c
62726+++ b/fs/namespace.c
62727@@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
62728 if (!(sb->s_flags & MS_RDONLY))
62729 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62730 up_write(&sb->s_umount);
62731+
62732+ gr_log_remount(mnt->mnt_devname, retval);
62733+
62734 return retval;
62735 }
62736
62737@@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
62738 }
62739 unlock_mount_hash();
62740 namespace_unlock();
62741+
62742+ gr_log_unmount(mnt->mnt_devname, retval);
62743+
62744 return retval;
62745 }
62746
62747@@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
62748 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62749 */
62750
62751-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62752+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62753 {
62754 struct path path;
62755 struct mount *mnt;
62756@@ -1431,7 +1437,7 @@ out:
62757 /*
62758 * The 2.0 compatible umount. No flags.
62759 */
62760-SYSCALL_DEFINE1(oldumount, char __user *, name)
62761+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62762 {
62763 return sys_umount(name, 0);
62764 }
62765@@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62766 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62767 MS_STRICTATIME);
62768
62769+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62770+ retval = -EPERM;
62771+ goto dput_out;
62772+ }
62773+
62774+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62775+ retval = -EPERM;
62776+ goto dput_out;
62777+ }
62778+
62779 if (flags & MS_REMOUNT)
62780 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62781 data_page);
62782@@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62783 dev_name, data_page);
62784 dput_out:
62785 path_put(&path);
62786+
62787+ gr_log_mount(dev_name, dir_name, retval);
62788+
62789 return retval;
62790 }
62791
62792@@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62793 * number incrementing at 10Ghz will take 12,427 years to wrap which
62794 * is effectively never, so we can ignore the possibility.
62795 */
62796-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62797+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62798
62799 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62800 {
62801@@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62802 kfree(new_ns);
62803 return ERR_PTR(ret);
62804 }
62805- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62806+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62807 atomic_set(&new_ns->count, 1);
62808 new_ns->root = NULL;
62809 INIT_LIST_HEAD(&new_ns->list);
62810@@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62811 return new_ns;
62812 }
62813
62814-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62815+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62816 struct user_namespace *user_ns, struct fs_struct *new_fs)
62817 {
62818 struct mnt_namespace *new_ns;
62819@@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62820 }
62821 EXPORT_SYMBOL(mount_subtree);
62822
62823-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62824- char __user *, type, unsigned long, flags, void __user *, data)
62825+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62826+ const char __user *, type, unsigned long, flags, void __user *, data)
62827 {
62828 int ret;
62829 char *kernel_type;
62830@@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62831 if (error)
62832 goto out2;
62833
62834+ if (gr_handle_chroot_pivot()) {
62835+ error = -EPERM;
62836+ goto out2;
62837+ }
62838+
62839 get_fs_root(current->fs, &root);
62840 old_mp = lock_mount(&old);
62841 error = PTR_ERR(old_mp);
62842@@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62843 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62844 return -EPERM;
62845
62846- if (fs->users != 1)
62847+ if (atomic_read(&fs->users) != 1)
62848 return -EINVAL;
62849
62850 get_mnt_ns(mnt_ns);
62851diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62852index f4ccfe6..a5cf064 100644
62853--- a/fs/nfs/callback_xdr.c
62854+++ b/fs/nfs/callback_xdr.c
62855@@ -51,7 +51,7 @@ struct callback_op {
62856 callback_decode_arg_t decode_args;
62857 callback_encode_res_t encode_res;
62858 long res_maxsize;
62859-};
62860+} __do_const;
62861
62862 static struct callback_op callback_ops[];
62863
62864diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62865index c79f3e7..d61d671 100644
62866--- a/fs/nfs/inode.c
62867+++ b/fs/nfs/inode.c
62868@@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62869 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62870 }
62871
62872-static atomic_long_t nfs_attr_generation_counter;
62873+static atomic_long_unchecked_t nfs_attr_generation_counter;
62874
62875 static unsigned long nfs_read_attr_generation_counter(void)
62876 {
62877- return atomic_long_read(&nfs_attr_generation_counter);
62878+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62879 }
62880
62881 unsigned long nfs_inc_attr_generation_counter(void)
62882 {
62883- return atomic_long_inc_return(&nfs_attr_generation_counter);
62884+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62885 }
62886
62887 void nfs_fattr_init(struct nfs_fattr *fattr)
62888diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
62889index 8f854dd..d0fec26 100644
62890--- a/fs/nfs/nfs3acl.c
62891+++ b/fs/nfs/nfs3acl.c
62892@@ -256,7 +256,7 @@ nfs3_list_one_acl(struct inode *inode, int type, const char *name, void *data,
62893 char *p = data + *result;
62894
62895 acl = get_acl(inode, type);
62896- if (!acl)
62897+ if (IS_ERR_OR_NULL(acl))
62898 return 0;
62899
62900 posix_acl_release(acl);
62901diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62902index 95e3720..46c23fa 100644
62903--- a/fs/nfsd/nfs4proc.c
62904+++ b/fs/nfsd/nfs4proc.c
62905@@ -1169,7 +1169,7 @@ struct nfsd4_operation {
62906 nfsd4op_rsize op_rsize_bop;
62907 stateid_getter op_get_currentstateid;
62908 stateid_setter op_set_currentstateid;
62909-};
62910+} __do_const;
62911
62912 static struct nfsd4_operation nfsd4_ops[];
62913
62914diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62915index 3297158..7bb8436 100644
62916--- a/fs/nfsd/nfs4xdr.c
62917+++ b/fs/nfsd/nfs4xdr.c
62918@@ -1541,7 +1541,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62919
62920 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62921
62922-static nfsd4_dec nfsd4_dec_ops[] = {
62923+static const nfsd4_dec nfsd4_dec_ops[] = {
62924 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62925 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62926 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62927diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62928index f8f060f..c4ba09a 100644
62929--- a/fs/nfsd/nfscache.c
62930+++ b/fs/nfsd/nfscache.c
62931@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62932 {
62933 struct svc_cacherep *rp = rqstp->rq_cacherep;
62934 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62935- int len;
62936+ long len;
62937 size_t bufsize = 0;
62938
62939 if (!rp)
62940 return;
62941
62942- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62943- len >>= 2;
62944+ if (statp) {
62945+ len = (char*)statp - (char*)resv->iov_base;
62946+ len = resv->iov_len - len;
62947+ len >>= 2;
62948+ }
62949
62950 /* Don't cache excessive amounts of data and XDR failures */
62951 if (!statp || len > (256 >> 2)) {
62952diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62953index 16f0673..1c2c30ab 100644
62954--- a/fs/nfsd/vfs.c
62955+++ b/fs/nfsd/vfs.c
62956@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62957 } else {
62958 oldfs = get_fs();
62959 set_fs(KERNEL_DS);
62960- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62961+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62962 set_fs(oldfs);
62963 }
62964
62965@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62966
62967 /* Write the data. */
62968 oldfs = get_fs(); set_fs(KERNEL_DS);
62969- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62970+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62971 set_fs(oldfs);
62972 if (host_err < 0)
62973 goto out_nfserr;
62974@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62975 */
62976
62977 oldfs = get_fs(); set_fs(KERNEL_DS);
62978- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62979+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62980 set_fs(oldfs);
62981
62982 if (host_err < 0)
62983diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62984index 52ccd34..43a53b1 100644
62985--- a/fs/nls/nls_base.c
62986+++ b/fs/nls/nls_base.c
62987@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62988
62989 int __register_nls(struct nls_table *nls, struct module *owner)
62990 {
62991- struct nls_table ** tmp = &tables;
62992+ struct nls_table *tmp = tables;
62993
62994 if (nls->next)
62995 return -EBUSY;
62996
62997- nls->owner = owner;
62998+ pax_open_kernel();
62999+ *(void **)&nls->owner = owner;
63000+ pax_close_kernel();
63001 spin_lock(&nls_lock);
63002- while (*tmp) {
63003- if (nls == *tmp) {
63004+ while (tmp) {
63005+ if (nls == tmp) {
63006 spin_unlock(&nls_lock);
63007 return -EBUSY;
63008 }
63009- tmp = &(*tmp)->next;
63010+ tmp = tmp->next;
63011 }
63012- nls->next = tables;
63013+ pax_open_kernel();
63014+ *(struct nls_table **)&nls->next = tables;
63015+ pax_close_kernel();
63016 tables = nls;
63017 spin_unlock(&nls_lock);
63018 return 0;
63019@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
63020
63021 int unregister_nls(struct nls_table * nls)
63022 {
63023- struct nls_table ** tmp = &tables;
63024+ struct nls_table * const * tmp = &tables;
63025
63026 spin_lock(&nls_lock);
63027 while (*tmp) {
63028 if (nls == *tmp) {
63029- *tmp = nls->next;
63030+ pax_open_kernel();
63031+ *(struct nls_table **)tmp = nls->next;
63032+ pax_close_kernel();
63033 spin_unlock(&nls_lock);
63034 return 0;
63035 }
63036diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
63037index 162b3f1..6076a7c 100644
63038--- a/fs/nls/nls_euc-jp.c
63039+++ b/fs/nls/nls_euc-jp.c
63040@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
63041 p_nls = load_nls("cp932");
63042
63043 if (p_nls) {
63044- table.charset2upper = p_nls->charset2upper;
63045- table.charset2lower = p_nls->charset2lower;
63046+ pax_open_kernel();
63047+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
63048+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
63049+ pax_close_kernel();
63050 return register_nls(&table);
63051 }
63052
63053diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
63054index a80a741..7b96e1b 100644
63055--- a/fs/nls/nls_koi8-ru.c
63056+++ b/fs/nls/nls_koi8-ru.c
63057@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
63058 p_nls = load_nls("koi8-u");
63059
63060 if (p_nls) {
63061- table.charset2upper = p_nls->charset2upper;
63062- table.charset2lower = p_nls->charset2lower;
63063+ pax_open_kernel();
63064+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
63065+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
63066+ pax_close_kernel();
63067 return register_nls(&table);
63068 }
63069
63070diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
63071index 732648b..d3b017f 100644
63072--- a/fs/notify/fanotify/fanotify_user.c
63073+++ b/fs/notify/fanotify/fanotify_user.c
63074@@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
63075
63076 fd = fanotify_event_metadata.fd;
63077 ret = -EFAULT;
63078- if (copy_to_user(buf, &fanotify_event_metadata,
63079- fanotify_event_metadata.event_len))
63080+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
63081+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
63082 goto out_close_fd;
63083
63084 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
63085diff --git a/fs/notify/notification.c b/fs/notify/notification.c
63086index 1e58402..bb2d6f4 100644
63087--- a/fs/notify/notification.c
63088+++ b/fs/notify/notification.c
63089@@ -48,7 +48,7 @@
63090 #include <linux/fsnotify_backend.h>
63091 #include "fsnotify.h"
63092
63093-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
63094+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
63095
63096 /**
63097 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
63098@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
63099 */
63100 u32 fsnotify_get_cookie(void)
63101 {
63102- return atomic_inc_return(&fsnotify_sync_cookie);
63103+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
63104 }
63105 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
63106
63107diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
63108index 9e38daf..5727cae 100644
63109--- a/fs/ntfs/dir.c
63110+++ b/fs/ntfs/dir.c
63111@@ -1310,7 +1310,7 @@ find_next_index_buffer:
63112 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
63113 ~(s64)(ndir->itype.index.block_size - 1)));
63114 /* Bounds checks. */
63115- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
63116+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
63117 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
63118 "inode 0x%lx or driver bug.", vdir->i_ino);
63119 goto err_out;
63120diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
63121index db9bd8a..8338fb6 100644
63122--- a/fs/ntfs/file.c
63123+++ b/fs/ntfs/file.c
63124@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
63125 char *addr;
63126 size_t total = 0;
63127 unsigned len;
63128- int left;
63129+ unsigned left;
63130
63131 do {
63132 len = PAGE_CACHE_SIZE - ofs;
63133diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
63134index 9de2491..3306095 100644
63135--- a/fs/ntfs/super.c
63136+++ b/fs/ntfs/super.c
63137@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
63138 if (!silent)
63139 ntfs_error(sb, "Primary boot sector is invalid.");
63140 } else if (!silent)
63141- ntfs_error(sb, read_err_str, "primary");
63142+ ntfs_error(sb, read_err_str, "%s", "primary");
63143 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
63144 if (bh_primary)
63145 brelse(bh_primary);
63146@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
63147 goto hotfix_primary_boot_sector;
63148 brelse(bh_backup);
63149 } else if (!silent)
63150- ntfs_error(sb, read_err_str, "backup");
63151+ ntfs_error(sb, read_err_str, "%s", "backup");
63152 /* Try to read NT3.51- backup boot sector. */
63153 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
63154 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
63155@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
63156 "sector.");
63157 brelse(bh_backup);
63158 } else if (!silent)
63159- ntfs_error(sb, read_err_str, "backup");
63160+ ntfs_error(sb, read_err_str, "%s", "backup");
63161 /* We failed. Cleanup and return. */
63162 if (bh_primary)
63163 brelse(bh_primary);
63164diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
63165index 0440134..d52c93a 100644
63166--- a/fs/ocfs2/localalloc.c
63167+++ b/fs/ocfs2/localalloc.c
63168@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
63169 goto bail;
63170 }
63171
63172- atomic_inc(&osb->alloc_stats.moves);
63173+ atomic_inc_unchecked(&osb->alloc_stats.moves);
63174
63175 bail:
63176 if (handle)
63177diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
63178index 8d64a97..c37665d 100644
63179--- a/fs/ocfs2/ocfs2.h
63180+++ b/fs/ocfs2/ocfs2.h
63181@@ -236,11 +236,11 @@ enum ocfs2_vol_state
63182
63183 struct ocfs2_alloc_stats
63184 {
63185- atomic_t moves;
63186- atomic_t local_data;
63187- atomic_t bitmap_data;
63188- atomic_t bg_allocs;
63189- atomic_t bg_extends;
63190+ atomic_unchecked_t moves;
63191+ atomic_unchecked_t local_data;
63192+ atomic_unchecked_t bitmap_data;
63193+ atomic_unchecked_t bg_allocs;
63194+ atomic_unchecked_t bg_extends;
63195 };
63196
63197 enum ocfs2_local_alloc_state
63198diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
63199index 0cb889a..6a26b24 100644
63200--- a/fs/ocfs2/suballoc.c
63201+++ b/fs/ocfs2/suballoc.c
63202@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
63203 mlog_errno(status);
63204 goto bail;
63205 }
63206- atomic_inc(&osb->alloc_stats.bg_extends);
63207+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
63208
63209 /* You should never ask for this much metadata */
63210 BUG_ON(bits_wanted >
63211@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
63212 mlog_errno(status);
63213 goto bail;
63214 }
63215- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63216+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63217
63218 *suballoc_loc = res.sr_bg_blkno;
63219 *suballoc_bit_start = res.sr_bit_offset;
63220@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
63221 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
63222 res->sr_bits);
63223
63224- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63225+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63226
63227 BUG_ON(res->sr_bits != 1);
63228
63229@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
63230 mlog_errno(status);
63231 goto bail;
63232 }
63233- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63234+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63235
63236 BUG_ON(res.sr_bits != 1);
63237
63238@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
63239 cluster_start,
63240 num_clusters);
63241 if (!status)
63242- atomic_inc(&osb->alloc_stats.local_data);
63243+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
63244 } else {
63245 if (min_clusters > (osb->bitmap_cpg - 1)) {
63246 /* The only paths asking for contiguousness
63247@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
63248 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
63249 res.sr_bg_blkno,
63250 res.sr_bit_offset);
63251- atomic_inc(&osb->alloc_stats.bitmap_data);
63252+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
63253 *num_clusters = res.sr_bits;
63254 }
63255 }
63256diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
63257index a7cdd56..c583144 100644
63258--- a/fs/ocfs2/super.c
63259+++ b/fs/ocfs2/super.c
63260@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
63261 "%10s => GlobalAllocs: %d LocalAllocs: %d "
63262 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
63263 "Stats",
63264- atomic_read(&osb->alloc_stats.bitmap_data),
63265- atomic_read(&osb->alloc_stats.local_data),
63266- atomic_read(&osb->alloc_stats.bg_allocs),
63267- atomic_read(&osb->alloc_stats.moves),
63268- atomic_read(&osb->alloc_stats.bg_extends));
63269+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
63270+ atomic_read_unchecked(&osb->alloc_stats.local_data),
63271+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
63272+ atomic_read_unchecked(&osb->alloc_stats.moves),
63273+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
63274
63275 out += snprintf(buf + out, len - out,
63276 "%10s => State: %u Descriptor: %llu Size: %u bits "
63277@@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
63278
63279 mutex_init(&osb->system_file_mutex);
63280
63281- atomic_set(&osb->alloc_stats.moves, 0);
63282- atomic_set(&osb->alloc_stats.local_data, 0);
63283- atomic_set(&osb->alloc_stats.bitmap_data, 0);
63284- atomic_set(&osb->alloc_stats.bg_allocs, 0);
63285- atomic_set(&osb->alloc_stats.bg_extends, 0);
63286+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
63287+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
63288+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
63289+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
63290+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
63291
63292 /* Copy the blockcheck stats from the superblock probe */
63293 osb->osb_ecc_stats = *stats;
63294diff --git a/fs/open.c b/fs/open.c
63295index dd24f21..c1f4b3a 100644
63296--- a/fs/open.c
63297+++ b/fs/open.c
63298@@ -32,6 +32,8 @@
63299 #include <linux/dnotify.h>
63300 #include <linux/compat.h>
63301
63302+#define CREATE_TRACE_POINTS
63303+#include <trace/events/fs.h>
63304 #include "internal.h"
63305
63306 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
63307@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
63308 error = locks_verify_truncate(inode, NULL, length);
63309 if (!error)
63310 error = security_path_truncate(path);
63311+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
63312+ error = -EACCES;
63313 if (!error)
63314 error = do_truncate(path->dentry, length, 0, NULL);
63315
63316@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
63317 error = locks_verify_truncate(inode, f.file, length);
63318 if (!error)
63319 error = security_path_truncate(&f.file->f_path);
63320+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
63321+ error = -EACCES;
63322 if (!error)
63323 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
63324 sb_end_write(inode->i_sb);
63325@@ -380,6 +386,9 @@ retry:
63326 if (__mnt_is_readonly(path.mnt))
63327 res = -EROFS;
63328
63329+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
63330+ res = -EACCES;
63331+
63332 out_path_release:
63333 path_put(&path);
63334 if (retry_estale(res, lookup_flags)) {
63335@@ -411,6 +420,8 @@ retry:
63336 if (error)
63337 goto dput_and_out;
63338
63339+ gr_log_chdir(path.dentry, path.mnt);
63340+
63341 set_fs_pwd(current->fs, &path);
63342
63343 dput_and_out:
63344@@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
63345 goto out_putf;
63346
63347 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
63348+
63349+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
63350+ error = -EPERM;
63351+
63352+ if (!error)
63353+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63354+
63355 if (!error)
63356 set_fs_pwd(current->fs, &f.file->f_path);
63357 out_putf:
63358@@ -469,7 +487,13 @@ retry:
63359 if (error)
63360 goto dput_and_out;
63361
63362+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63363+ goto dput_and_out;
63364+
63365 set_fs_root(current->fs, &path);
63366+
63367+ gr_handle_chroot_chdir(&path);
63368+
63369 error = 0;
63370 dput_and_out:
63371 path_put(&path);
63372@@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
63373 return error;
63374 retry_deleg:
63375 mutex_lock(&inode->i_mutex);
63376+
63377+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63378+ error = -EACCES;
63379+ goto out_unlock;
63380+ }
63381+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63382+ error = -EACCES;
63383+ goto out_unlock;
63384+ }
63385+
63386 error = security_path_chmod(path, mode);
63387 if (error)
63388 goto out_unlock;
63389@@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63390 uid = make_kuid(current_user_ns(), user);
63391 gid = make_kgid(current_user_ns(), group);
63392
63393+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
63394+ return -EACCES;
63395+
63396 newattrs.ia_valid = ATTR_CTIME;
63397 if (user != (uid_t) -1) {
63398 if (!uid_valid(uid))
63399@@ -977,6 +1014,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63400 } else {
63401 fsnotify_open(f);
63402 fd_install(fd, f);
63403+ trace_do_sys_open(tmp->name, flags, mode);
63404 }
63405 }
63406 putname(tmp);
63407diff --git a/fs/pipe.c b/fs/pipe.c
63408index 034bffa..6c6b522 100644
63409--- a/fs/pipe.c
63410+++ b/fs/pipe.c
63411@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63412
63413 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63414 {
63415- if (pipe->files)
63416+ if (atomic_read(&pipe->files))
63417 mutex_lock_nested(&pipe->mutex, subclass);
63418 }
63419
63420@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63421
63422 void pipe_unlock(struct pipe_inode_info *pipe)
63423 {
63424- if (pipe->files)
63425+ if (atomic_read(&pipe->files))
63426 mutex_unlock(&pipe->mutex);
63427 }
63428 EXPORT_SYMBOL(pipe_unlock);
63429@@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
63430 }
63431 if (bufs) /* More to do? */
63432 continue;
63433- if (!pipe->writers)
63434+ if (!atomic_read(&pipe->writers))
63435 break;
63436- if (!pipe->waiting_writers) {
63437+ if (!atomic_read(&pipe->waiting_writers)) {
63438 /* syscall merging: Usually we must not sleep
63439 * if O_NONBLOCK is set, or if we got some data.
63440 * But if a writer sleeps in kernel space, then
63441@@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63442 ret = 0;
63443 __pipe_lock(pipe);
63444
63445- if (!pipe->readers) {
63446+ if (!atomic_read(&pipe->readers)) {
63447 send_sig(SIGPIPE, current, 0);
63448 ret = -EPIPE;
63449 goto out;
63450@@ -461,7 +461,7 @@ redo1:
63451 for (;;) {
63452 int bufs;
63453
63454- if (!pipe->readers) {
63455+ if (!atomic_read(&pipe->readers)) {
63456 send_sig(SIGPIPE, current, 0);
63457 if (!ret)
63458 ret = -EPIPE;
63459@@ -552,9 +552,9 @@ redo2:
63460 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63461 do_wakeup = 0;
63462 }
63463- pipe->waiting_writers++;
63464+ atomic_inc(&pipe->waiting_writers);
63465 pipe_wait(pipe);
63466- pipe->waiting_writers--;
63467+ atomic_dec(&pipe->waiting_writers);
63468 }
63469 out:
63470 __pipe_unlock(pipe);
63471@@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63472 mask = 0;
63473 if (filp->f_mode & FMODE_READ) {
63474 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63475- if (!pipe->writers && filp->f_version != pipe->w_counter)
63476+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63477 mask |= POLLHUP;
63478 }
63479
63480@@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63481 * Most Unices do not set POLLERR for FIFOs but on Linux they
63482 * behave exactly like pipes for poll().
63483 */
63484- if (!pipe->readers)
63485+ if (!atomic_read(&pipe->readers))
63486 mask |= POLLERR;
63487 }
63488
63489@@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63490 int kill = 0;
63491
63492 spin_lock(&inode->i_lock);
63493- if (!--pipe->files) {
63494+ if (atomic_dec_and_test(&pipe->files)) {
63495 inode->i_pipe = NULL;
63496 kill = 1;
63497 }
63498@@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
63499
63500 __pipe_lock(pipe);
63501 if (file->f_mode & FMODE_READ)
63502- pipe->readers--;
63503+ atomic_dec(&pipe->readers);
63504 if (file->f_mode & FMODE_WRITE)
63505- pipe->writers--;
63506+ atomic_dec(&pipe->writers);
63507
63508- if (pipe->readers || pipe->writers) {
63509+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63510 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63511 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63512 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63513@@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63514 kfree(pipe);
63515 }
63516
63517-static struct vfsmount *pipe_mnt __read_mostly;
63518+struct vfsmount *pipe_mnt __read_mostly;
63519
63520 /*
63521 * pipefs_dname() is called from d_path().
63522@@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
63523 goto fail_iput;
63524
63525 inode->i_pipe = pipe;
63526- pipe->files = 2;
63527- pipe->readers = pipe->writers = 1;
63528+ atomic_set(&pipe->files, 2);
63529+ atomic_set(&pipe->readers, 1);
63530+ atomic_set(&pipe->writers, 1);
63531 inode->i_fop = &pipefifo_fops;
63532
63533 /*
63534@@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63535 spin_lock(&inode->i_lock);
63536 if (inode->i_pipe) {
63537 pipe = inode->i_pipe;
63538- pipe->files++;
63539+ atomic_inc(&pipe->files);
63540 spin_unlock(&inode->i_lock);
63541 } else {
63542 spin_unlock(&inode->i_lock);
63543 pipe = alloc_pipe_info();
63544 if (!pipe)
63545 return -ENOMEM;
63546- pipe->files = 1;
63547+ atomic_set(&pipe->files, 1);
63548 spin_lock(&inode->i_lock);
63549 if (unlikely(inode->i_pipe)) {
63550- inode->i_pipe->files++;
63551+ atomic_inc(&inode->i_pipe->files);
63552 spin_unlock(&inode->i_lock);
63553 free_pipe_info(pipe);
63554 pipe = inode->i_pipe;
63555@@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63556 * opened, even when there is no process writing the FIFO.
63557 */
63558 pipe->r_counter++;
63559- if (pipe->readers++ == 0)
63560+ if (atomic_inc_return(&pipe->readers) == 1)
63561 wake_up_partner(pipe);
63562
63563- if (!is_pipe && !pipe->writers) {
63564+ if (!is_pipe && !atomic_read(&pipe->writers)) {
63565 if ((filp->f_flags & O_NONBLOCK)) {
63566 /* suppress POLLHUP until we have
63567 * seen a writer */
63568@@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63569 * errno=ENXIO when there is no process reading the FIFO.
63570 */
63571 ret = -ENXIO;
63572- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63573+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63574 goto err;
63575
63576 pipe->w_counter++;
63577- if (!pipe->writers++)
63578+ if (atomic_inc_return(&pipe->writers) == 1)
63579 wake_up_partner(pipe);
63580
63581- if (!is_pipe && !pipe->readers) {
63582+ if (!is_pipe && !atomic_read(&pipe->readers)) {
63583 if (wait_for_partner(pipe, &pipe->r_counter))
63584 goto err_wr;
63585 }
63586@@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63587 * the process can at least talk to itself.
63588 */
63589
63590- pipe->readers++;
63591- pipe->writers++;
63592+ atomic_inc(&pipe->readers);
63593+ atomic_inc(&pipe->writers);
63594 pipe->r_counter++;
63595 pipe->w_counter++;
63596- if (pipe->readers == 1 || pipe->writers == 1)
63597+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63598 wake_up_partner(pipe);
63599 break;
63600
63601@@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63602 return 0;
63603
63604 err_rd:
63605- if (!--pipe->readers)
63606+ if (atomic_dec_and_test(&pipe->readers))
63607 wake_up_interruptible(&pipe->wait);
63608 ret = -ERESTARTSYS;
63609 goto err;
63610
63611 err_wr:
63612- if (!--pipe->writers)
63613+ if (atomic_dec_and_test(&pipe->writers))
63614 wake_up_interruptible(&pipe->wait);
63615 ret = -ERESTARTSYS;
63616 goto err;
63617diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63618index 0855f77..6787d50 100644
63619--- a/fs/posix_acl.c
63620+++ b/fs/posix_acl.c
63621@@ -20,6 +20,7 @@
63622 #include <linux/xattr.h>
63623 #include <linux/export.h>
63624 #include <linux/user_namespace.h>
63625+#include <linux/grsecurity.h>
63626
63627 struct posix_acl **acl_by_type(struct inode *inode, int type)
63628 {
63629@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63630 }
63631 }
63632 if (mode_p)
63633- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63634+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63635 return not_equiv;
63636 }
63637 EXPORT_SYMBOL(posix_acl_equiv_mode);
63638@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63639 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63640 }
63641
63642- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63643+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63644 return not_equiv;
63645 }
63646
63647@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63648 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63649 int err = -ENOMEM;
63650 if (clone) {
63651+ *mode_p &= ~gr_acl_umask();
63652+
63653 err = posix_acl_create_masq(clone, mode_p);
63654 if (err < 0) {
63655 posix_acl_release(clone);
63656@@ -659,11 +662,12 @@ struct posix_acl *
63657 posix_acl_from_xattr(struct user_namespace *user_ns,
63658 const void *value, size_t size)
63659 {
63660- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63661- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63662+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63663+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63664 int count;
63665 struct posix_acl *acl;
63666 struct posix_acl_entry *acl_e;
63667+ umode_t umask = gr_acl_umask();
63668
63669 if (!value)
63670 return NULL;
63671@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63672
63673 switch(acl_e->e_tag) {
63674 case ACL_USER_OBJ:
63675+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63676+ break;
63677 case ACL_GROUP_OBJ:
63678 case ACL_MASK:
63679+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63680+ break;
63681 case ACL_OTHER:
63682+ acl_e->e_perm &= ~(umask & S_IRWXO);
63683 break;
63684
63685 case ACL_USER:
63686+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63687 acl_e->e_uid =
63688 make_kuid(user_ns,
63689 le32_to_cpu(entry->e_id));
63690@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63691 goto fail;
63692 break;
63693 case ACL_GROUP:
63694+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63695 acl_e->e_gid =
63696 make_kgid(user_ns,
63697 le32_to_cpu(entry->e_id));
63698diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63699index 2183fcf..3c32a98 100644
63700--- a/fs/proc/Kconfig
63701+++ b/fs/proc/Kconfig
63702@@ -30,7 +30,7 @@ config PROC_FS
63703
63704 config PROC_KCORE
63705 bool "/proc/kcore support" if !ARM
63706- depends on PROC_FS && MMU
63707+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63708 help
63709 Provides a virtual ELF core file of the live kernel. This can
63710 be read with gdb and other ELF tools. No modifications can be
63711@@ -38,8 +38,8 @@ config PROC_KCORE
63712
63713 config PROC_VMCORE
63714 bool "/proc/vmcore support"
63715- depends on PROC_FS && CRASH_DUMP
63716- default y
63717+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63718+ default n
63719 help
63720 Exports the dump image of crashed kernel in ELF format.
63721
63722@@ -63,8 +63,8 @@ config PROC_SYSCTL
63723 limited in memory.
63724
63725 config PROC_PAGE_MONITOR
63726- default y
63727- depends on PROC_FS && MMU
63728+ default n
63729+ depends on PROC_FS && MMU && !GRKERNSEC
63730 bool "Enable /proc page monitoring" if EXPERT
63731 help
63732 Various /proc files exist to monitor process memory utilization:
63733diff --git a/fs/proc/array.c b/fs/proc/array.c
63734index 64db2bc..a8185d6 100644
63735--- a/fs/proc/array.c
63736+++ b/fs/proc/array.c
63737@@ -60,6 +60,7 @@
63738 #include <linux/tty.h>
63739 #include <linux/string.h>
63740 #include <linux/mman.h>
63741+#include <linux/grsecurity.h>
63742 #include <linux/proc_fs.h>
63743 #include <linux/ioport.h>
63744 #include <linux/uaccess.h>
63745@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63746 seq_putc(m, '\n');
63747 }
63748
63749+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63750+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63751+{
63752+ if (p->mm)
63753+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63754+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63755+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63756+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63757+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63758+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63759+ else
63760+ seq_printf(m, "PaX:\t-----\n");
63761+}
63762+#endif
63763+
63764 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63765 struct pid *pid, struct task_struct *task)
63766 {
63767@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63768 task_cpus_allowed(m, task);
63769 cpuset_task_status_allowed(m, task);
63770 task_context_switch_counts(m, task);
63771+
63772+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63773+ task_pax(m, task);
63774+#endif
63775+
63776+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63777+ task_grsec_rbac(m, task);
63778+#endif
63779+
63780 return 0;
63781 }
63782
63783+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63784+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63785+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63786+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63787+#endif
63788+
63789 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63790 struct pid *pid, struct task_struct *task, int whole)
63791 {
63792@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63793 char tcomm[sizeof(task->comm)];
63794 unsigned long flags;
63795
63796+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63797+ if (current->exec_id != m->exec_id) {
63798+ gr_log_badprocpid("stat");
63799+ return 0;
63800+ }
63801+#endif
63802+
63803 state = *get_task_state(task);
63804 vsize = eip = esp = 0;
63805 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63806@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63807 gtime = task_gtime(task);
63808 }
63809
63810+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63811+ if (PAX_RAND_FLAGS(mm)) {
63812+ eip = 0;
63813+ esp = 0;
63814+ wchan = 0;
63815+ }
63816+#endif
63817+#ifdef CONFIG_GRKERNSEC_HIDESYM
63818+ wchan = 0;
63819+ eip =0;
63820+ esp =0;
63821+#endif
63822+
63823 /* scale priority and nice values from timeslices to -20..20 */
63824 /* to make it look like a "normal" Unix priority/nice value */
63825 priority = task_prio(task);
63826@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63827 seq_put_decimal_ull(m, ' ', vsize);
63828 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63829 seq_put_decimal_ull(m, ' ', rsslim);
63830+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63831+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63832+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63833+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63834+#else
63835 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63836 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63837 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63838+#endif
63839 seq_put_decimal_ull(m, ' ', esp);
63840 seq_put_decimal_ull(m, ' ', eip);
63841 /* The signal information here is obsolete.
63842@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63843 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63844 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63845
63846- if (mm && permitted) {
63847+ if (mm && permitted
63848+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63849+ && !PAX_RAND_FLAGS(mm)
63850+#endif
63851+ ) {
63852 seq_put_decimal_ull(m, ' ', mm->start_data);
63853 seq_put_decimal_ull(m, ' ', mm->end_data);
63854 seq_put_decimal_ull(m, ' ', mm->start_brk);
63855@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63856 struct pid *pid, struct task_struct *task)
63857 {
63858 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63859- struct mm_struct *mm = get_task_mm(task);
63860+ struct mm_struct *mm;
63861
63862+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63863+ if (current->exec_id != m->exec_id) {
63864+ gr_log_badprocpid("statm");
63865+ return 0;
63866+ }
63867+#endif
63868+ mm = get_task_mm(task);
63869 if (mm) {
63870 size = task_statm(mm, &shared, &text, &data, &resident);
63871 mmput(mm);
63872@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63873 return 0;
63874 }
63875
63876+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63877+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63878+{
63879+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63880+}
63881+#endif
63882+
63883 #ifdef CONFIG_CHECKPOINT_RESTORE
63884 static struct pid *
63885 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63886diff --git a/fs/proc/base.c b/fs/proc/base.c
63887index 2d696b0..b9da447 100644
63888--- a/fs/proc/base.c
63889+++ b/fs/proc/base.c
63890@@ -113,6 +113,14 @@ struct pid_entry {
63891 union proc_op op;
63892 };
63893
63894+struct getdents_callback {
63895+ struct linux_dirent __user * current_dir;
63896+ struct linux_dirent __user * previous;
63897+ struct file * file;
63898+ int count;
63899+ int error;
63900+};
63901+
63902 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63903 .name = (NAME), \
63904 .len = sizeof(NAME) - 1, \
63905@@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63906 return get_cmdline(task, buffer, PAGE_SIZE);
63907 }
63908
63909+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63910+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63911+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63912+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63913+#endif
63914+
63915 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63916 {
63917 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63918 int res = PTR_ERR(mm);
63919 if (mm && !IS_ERR(mm)) {
63920 unsigned int nwords = 0;
63921+
63922+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63923+ /* allow if we're currently ptracing this task */
63924+ if (PAX_RAND_FLAGS(mm) &&
63925+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63926+ mmput(mm);
63927+ return 0;
63928+ }
63929+#endif
63930+
63931 do {
63932 nwords += 2;
63933 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63934@@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63935 }
63936
63937
63938-#ifdef CONFIG_KALLSYMS
63939+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63940 /*
63941 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63942 * Returns the resolved symbol. If that fails, simply return the address.
63943@@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63944 mutex_unlock(&task->signal->cred_guard_mutex);
63945 }
63946
63947-#ifdef CONFIG_STACKTRACE
63948+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63949
63950 #define MAX_STACK_TRACE_DEPTH 64
63951
63952@@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63953 return count;
63954 }
63955
63956-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63957+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63958 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63959 {
63960 long nr;
63961@@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63962 /************************************************************************/
63963
63964 /* permission checks */
63965-static int proc_fd_access_allowed(struct inode *inode)
63966+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63967 {
63968 struct task_struct *task;
63969 int allowed = 0;
63970@@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63971 */
63972 task = get_proc_task(inode);
63973 if (task) {
63974- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63975+ if (log)
63976+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63977+ else
63978+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63979 put_task_struct(task);
63980 }
63981 return allowed;
63982@@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63983 struct task_struct *task,
63984 int hide_pid_min)
63985 {
63986+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63987+ return false;
63988+
63989+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63990+ rcu_read_lock();
63991+ {
63992+ const struct cred *tmpcred = current_cred();
63993+ const struct cred *cred = __task_cred(task);
63994+
63995+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63996+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63997+ || in_group_p(grsec_proc_gid)
63998+#endif
63999+ ) {
64000+ rcu_read_unlock();
64001+ return true;
64002+ }
64003+ }
64004+ rcu_read_unlock();
64005+
64006+ if (!pid->hide_pid)
64007+ return false;
64008+#endif
64009+
64010 if (pid->hide_pid < hide_pid_min)
64011 return true;
64012 if (in_group_p(pid->pid_gid))
64013 return true;
64014+
64015 return ptrace_may_access(task, PTRACE_MODE_READ);
64016 }
64017
64018@@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
64019 put_task_struct(task);
64020
64021 if (!has_perms) {
64022+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64023+ {
64024+#else
64025 if (pid->hide_pid == 2) {
64026+#endif
64027 /*
64028 * Let's make getdents(), stat(), and open()
64029 * consistent with each other. If a process
64030@@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
64031 if (!task)
64032 return -ESRCH;
64033
64034+ if (gr_acl_handle_procpidmem(task)) {
64035+ put_task_struct(task);
64036+ return -EPERM;
64037+ }
64038+
64039 mm = mm_access(task, mode);
64040 put_task_struct(task);
64041
64042@@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
64043
64044 file->private_data = mm;
64045
64046+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64047+ file->f_version = current->exec_id;
64048+#endif
64049+
64050 return 0;
64051 }
64052
64053@@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
64054 ssize_t copied;
64055 char *page;
64056
64057+#ifdef CONFIG_GRKERNSEC
64058+ if (write)
64059+ return -EPERM;
64060+#endif
64061+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64062+ if (file->f_version != current->exec_id) {
64063+ gr_log_badprocpid("mem");
64064+ return 0;
64065+ }
64066+#endif
64067+
64068 if (!mm)
64069 return 0;
64070
64071@@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
64072 goto free;
64073
64074 while (count > 0) {
64075- int this_len = min_t(int, count, PAGE_SIZE);
64076+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
64077
64078 if (write && copy_from_user(page, buf, this_len)) {
64079 copied = -EFAULT;
64080@@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
64081 if (!mm)
64082 return 0;
64083
64084+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64085+ if (file->f_version != current->exec_id) {
64086+ gr_log_badprocpid("environ");
64087+ return 0;
64088+ }
64089+#endif
64090+
64091 page = (char *)__get_free_page(GFP_TEMPORARY);
64092 if (!page)
64093 return -ENOMEM;
64094@@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
64095 goto free;
64096 while (count > 0) {
64097 size_t this_len, max_len;
64098- int retval;
64099+ ssize_t retval;
64100
64101 if (src >= (mm->env_end - mm->env_start))
64102 break;
64103@@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
64104 int error = -EACCES;
64105
64106 /* Are we allowed to snoop on the tasks file descriptors? */
64107- if (!proc_fd_access_allowed(inode))
64108+ if (!proc_fd_access_allowed(inode, 0))
64109 goto out;
64110
64111 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
64112@@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
64113 struct path path;
64114
64115 /* Are we allowed to snoop on the tasks file descriptors? */
64116- if (!proc_fd_access_allowed(inode))
64117- goto out;
64118+ /* logging this is needed for learning on chromium to work properly,
64119+ but we don't want to flood the logs from 'ps' which does a readlink
64120+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
64121+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
64122+ */
64123+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
64124+ if (!proc_fd_access_allowed(inode,0))
64125+ goto out;
64126+ } else {
64127+ if (!proc_fd_access_allowed(inode,1))
64128+ goto out;
64129+ }
64130
64131 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
64132 if (error)
64133@@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
64134 rcu_read_lock();
64135 cred = __task_cred(task);
64136 inode->i_uid = cred->euid;
64137+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64138+ inode->i_gid = grsec_proc_gid;
64139+#else
64140 inode->i_gid = cred->egid;
64141+#endif
64142 rcu_read_unlock();
64143 }
64144 security_task_to_inode(task, inode);
64145@@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
64146 return -ENOENT;
64147 }
64148 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
64149+#ifdef CONFIG_GRKERNSEC_PROC_USER
64150+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
64151+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64152+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
64153+#endif
64154 task_dumpable(task)) {
64155 cred = __task_cred(task);
64156 stat->uid = cred->euid;
64157+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64158+ stat->gid = grsec_proc_gid;
64159+#else
64160 stat->gid = cred->egid;
64161+#endif
64162 }
64163 }
64164 rcu_read_unlock();
64165@@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
64166
64167 if (task) {
64168 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
64169+#ifdef CONFIG_GRKERNSEC_PROC_USER
64170+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
64171+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64172+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
64173+#endif
64174 task_dumpable(task)) {
64175 rcu_read_lock();
64176 cred = __task_cred(task);
64177 inode->i_uid = cred->euid;
64178+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64179+ inode->i_gid = grsec_proc_gid;
64180+#else
64181 inode->i_gid = cred->egid;
64182+#endif
64183 rcu_read_unlock();
64184 } else {
64185 inode->i_uid = GLOBAL_ROOT_UID;
64186@@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
64187 if (!task)
64188 goto out_no_task;
64189
64190+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
64191+ goto out;
64192+
64193 /*
64194 * Yes, it does not scale. And it should not. Don't add
64195 * new entries into /proc/<tgid>/ without very good reasons.
64196@@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
64197 if (!task)
64198 return -ENOENT;
64199
64200+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
64201+ goto out;
64202+
64203 if (!dir_emit_dots(file, ctx))
64204 goto out;
64205
64206@@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
64207 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
64208 #endif
64209 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
64210-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
64211+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
64212 INF("syscall", S_IRUSR, proc_pid_syscall),
64213 #endif
64214 INF("cmdline", S_IRUGO, proc_pid_cmdline),
64215@@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
64216 #ifdef CONFIG_SECURITY
64217 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
64218 #endif
64219-#ifdef CONFIG_KALLSYMS
64220+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64221 INF("wchan", S_IRUGO, proc_pid_wchan),
64222 #endif
64223-#ifdef CONFIG_STACKTRACE
64224+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64225 ONE("stack", S_IRUSR, proc_pid_stack),
64226 #endif
64227 #ifdef CONFIG_SCHEDSTATS
64228@@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
64229 #ifdef CONFIG_HARDWALL
64230 INF("hardwall", S_IRUGO, proc_pid_hardwall),
64231 #endif
64232+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64233+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
64234+#endif
64235 #ifdef CONFIG_USER_NS
64236 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
64237 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
64238@@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
64239 if (!inode)
64240 goto out;
64241
64242+#ifdef CONFIG_GRKERNSEC_PROC_USER
64243+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
64244+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64245+ inode->i_gid = grsec_proc_gid;
64246+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
64247+#else
64248 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
64249+#endif
64250 inode->i_op = &proc_tgid_base_inode_operations;
64251 inode->i_fop = &proc_tgid_base_operations;
64252 inode->i_flags|=S_IMMUTABLE;
64253@@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
64254 if (!task)
64255 goto out;
64256
64257+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
64258+ goto out_put_task;
64259+
64260 result = proc_pid_instantiate(dir, dentry, task, NULL);
64261+out_put_task:
64262 put_task_struct(task);
64263 out:
64264 return ERR_PTR(result);
64265@@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
64266 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
64267 #endif
64268 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
64269-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
64270+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
64271 INF("syscall", S_IRUSR, proc_pid_syscall),
64272 #endif
64273 INF("cmdline", S_IRUGO, proc_pid_cmdline),
64274@@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
64275 #ifdef CONFIG_SECURITY
64276 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
64277 #endif
64278-#ifdef CONFIG_KALLSYMS
64279+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64280 INF("wchan", S_IRUGO, proc_pid_wchan),
64281 #endif
64282-#ifdef CONFIG_STACKTRACE
64283+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64284 ONE("stack", S_IRUSR, proc_pid_stack),
64285 #endif
64286 #ifdef CONFIG_SCHEDSTATS
64287diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
64288index cbd82df..c0407d2 100644
64289--- a/fs/proc/cmdline.c
64290+++ b/fs/proc/cmdline.c
64291@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
64292
64293 static int __init proc_cmdline_init(void)
64294 {
64295+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64296+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
64297+#else
64298 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
64299+#endif
64300 return 0;
64301 }
64302 fs_initcall(proc_cmdline_init);
64303diff --git a/fs/proc/devices.c b/fs/proc/devices.c
64304index 50493ed..248166b 100644
64305--- a/fs/proc/devices.c
64306+++ b/fs/proc/devices.c
64307@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
64308
64309 static int __init proc_devices_init(void)
64310 {
64311+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64312+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
64313+#else
64314 proc_create("devices", 0, NULL, &proc_devinfo_operations);
64315+#endif
64316 return 0;
64317 }
64318 fs_initcall(proc_devices_init);
64319diff --git a/fs/proc/fd.c b/fs/proc/fd.c
64320index 0788d09..9cc1385 100644
64321--- a/fs/proc/fd.c
64322+++ b/fs/proc/fd.c
64323@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
64324 if (!task)
64325 return -ENOENT;
64326
64327- files = get_files_struct(task);
64328+ if (!gr_acl_handle_procpidmem(task))
64329+ files = get_files_struct(task);
64330 put_task_struct(task);
64331
64332 if (files) {
64333@@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
64334 */
64335 int proc_fd_permission(struct inode *inode, int mask)
64336 {
64337+ struct task_struct *task;
64338 int rv = generic_permission(inode, mask);
64339- if (rv == 0)
64340- return 0;
64341+
64342 if (task_tgid(current) == proc_pid(inode))
64343 rv = 0;
64344+
64345+ task = get_proc_task(inode);
64346+ if (task == NULL)
64347+ return rv;
64348+
64349+ if (gr_acl_handle_procpidmem(task))
64350+ rv = -EACCES;
64351+
64352+ put_task_struct(task);
64353+
64354 return rv;
64355 }
64356
64357diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64358index b7f268e..3bea6b7 100644
64359--- a/fs/proc/generic.c
64360+++ b/fs/proc/generic.c
64361@@ -23,6 +23,7 @@
64362 #include <linux/bitops.h>
64363 #include <linux/spinlock.h>
64364 #include <linux/completion.h>
64365+#include <linux/grsecurity.h>
64366 #include <asm/uaccess.h>
64367
64368 #include "internal.h"
64369@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64370 return proc_lookup_de(PDE(dir), dir, dentry);
64371 }
64372
64373+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64374+ unsigned int flags)
64375+{
64376+ if (gr_proc_is_restricted())
64377+ return ERR_PTR(-EACCES);
64378+
64379+ return proc_lookup_de(PDE(dir), dir, dentry);
64380+}
64381+
64382 /*
64383 * This returns non-zero if at EOF, so that the /proc
64384 * root directory can use this and check if it should
64385@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64386 return proc_readdir_de(PDE(inode), file, ctx);
64387 }
64388
64389+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64390+{
64391+ struct inode *inode = file_inode(file);
64392+
64393+ if (gr_proc_is_restricted())
64394+ return -EACCES;
64395+
64396+ return proc_readdir_de(PDE(inode), file, ctx);
64397+}
64398+
64399 /*
64400 * These are the generic /proc directory operations. They
64401 * use the in-memory "struct proc_dir_entry" tree to parse
64402@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64403 .iterate = proc_readdir,
64404 };
64405
64406+static const struct file_operations proc_dir_restricted_operations = {
64407+ .llseek = generic_file_llseek,
64408+ .read = generic_read_dir,
64409+ .iterate = proc_readdir_restrict,
64410+};
64411+
64412 /*
64413 * proc directories can do almost nothing..
64414 */
64415@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64416 .setattr = proc_notify_change,
64417 };
64418
64419+static const struct inode_operations proc_dir_restricted_inode_operations = {
64420+ .lookup = proc_lookup_restrict,
64421+ .getattr = proc_getattr,
64422+ .setattr = proc_notify_change,
64423+};
64424+
64425 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64426 {
64427 struct proc_dir_entry *tmp;
64428@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64429 return ret;
64430
64431 if (S_ISDIR(dp->mode)) {
64432- dp->proc_fops = &proc_dir_operations;
64433- dp->proc_iops = &proc_dir_inode_operations;
64434+ if (dp->restricted) {
64435+ dp->proc_fops = &proc_dir_restricted_operations;
64436+ dp->proc_iops = &proc_dir_restricted_inode_operations;
64437+ } else {
64438+ dp->proc_fops = &proc_dir_operations;
64439+ dp->proc_iops = &proc_dir_inode_operations;
64440+ }
64441 dir->nlink++;
64442 } else if (S_ISLNK(dp->mode)) {
64443 dp->proc_iops = &proc_link_inode_operations;
64444@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64445 }
64446 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64447
64448+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64449+ struct proc_dir_entry *parent, void *data)
64450+{
64451+ struct proc_dir_entry *ent;
64452+
64453+ if (mode == 0)
64454+ mode = S_IRUGO | S_IXUGO;
64455+
64456+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64457+ if (ent) {
64458+ ent->data = data;
64459+ ent->restricted = 1;
64460+ if (proc_register(parent, ent) < 0) {
64461+ kfree(ent);
64462+ ent = NULL;
64463+ }
64464+ }
64465+ return ent;
64466+}
64467+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64468+
64469 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64470 struct proc_dir_entry *parent)
64471 {
64472@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64473 }
64474 EXPORT_SYMBOL(proc_mkdir);
64475
64476+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64477+ struct proc_dir_entry *parent)
64478+{
64479+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
64480+}
64481+EXPORT_SYMBOL(proc_mkdir_restrict);
64482+
64483 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64484 struct proc_dir_entry *parent,
64485 const struct file_operations *proc_fops,
64486diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64487index 0adbc02..bee4d0b 100644
64488--- a/fs/proc/inode.c
64489+++ b/fs/proc/inode.c
64490@@ -23,11 +23,17 @@
64491 #include <linux/slab.h>
64492 #include <linux/mount.h>
64493 #include <linux/magic.h>
64494+#include <linux/grsecurity.h>
64495
64496 #include <asm/uaccess.h>
64497
64498 #include "internal.h"
64499
64500+#ifdef CONFIG_PROC_SYSCTL
64501+extern const struct inode_operations proc_sys_inode_operations;
64502+extern const struct inode_operations proc_sys_dir_operations;
64503+#endif
64504+
64505 static void proc_evict_inode(struct inode *inode)
64506 {
64507 struct proc_dir_entry *de;
64508@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64509 ns = PROC_I(inode)->ns.ns;
64510 if (ns_ops && ns)
64511 ns_ops->put(ns);
64512+
64513+#ifdef CONFIG_PROC_SYSCTL
64514+ if (inode->i_op == &proc_sys_inode_operations ||
64515+ inode->i_op == &proc_sys_dir_operations)
64516+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64517+#endif
64518+
64519 }
64520
64521 static struct kmem_cache * proc_inode_cachep;
64522@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64523 if (de->mode) {
64524 inode->i_mode = de->mode;
64525 inode->i_uid = de->uid;
64526+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64527+ inode->i_gid = grsec_proc_gid;
64528+#else
64529 inode->i_gid = de->gid;
64530+#endif
64531 }
64532 if (de->size)
64533 inode->i_size = de->size;
64534diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64535index 3ab6d14..b26174e 100644
64536--- a/fs/proc/internal.h
64537+++ b/fs/proc/internal.h
64538@@ -46,9 +46,10 @@ struct proc_dir_entry {
64539 struct completion *pde_unload_completion;
64540 struct list_head pde_openers; /* who did ->open, but not ->release */
64541 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64542+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64543 u8 namelen;
64544 char name[];
64545-};
64546+} __randomize_layout;
64547
64548 union proc_op {
64549 int (*proc_get_link)(struct dentry *, struct path *);
64550@@ -67,7 +68,7 @@ struct proc_inode {
64551 struct ctl_table *sysctl_entry;
64552 struct proc_ns ns;
64553 struct inode vfs_inode;
64554-};
64555+} __randomize_layout;
64556
64557 /*
64558 * General functions
64559@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64560 struct pid *, struct task_struct *);
64561 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64562 struct pid *, struct task_struct *);
64563+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64564+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64565+#endif
64566
64567 /*
64568 * base.c
64569@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64570 extern spinlock_t proc_subdir_lock;
64571
64572 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64573+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64574 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64575 struct dentry *);
64576 extern int proc_readdir(struct file *, struct dir_context *);
64577+extern int proc_readdir_restrict(struct file *, struct dir_context *);
64578 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64579
64580 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64581diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64582index a352d57..cb94a5c 100644
64583--- a/fs/proc/interrupts.c
64584+++ b/fs/proc/interrupts.c
64585@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64586
64587 static int __init proc_interrupts_init(void)
64588 {
64589+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64590+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64591+#else
64592 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64593+#endif
64594 return 0;
64595 }
64596 fs_initcall(proc_interrupts_init);
64597diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64598index 39e6ef3..2f9cb5e 100644
64599--- a/fs/proc/kcore.c
64600+++ b/fs/proc/kcore.c
64601@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64602 * the addresses in the elf_phdr on our list.
64603 */
64604 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64605- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64606+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64607+ if (tsz > buflen)
64608 tsz = buflen;
64609-
64610+
64611 while (buflen) {
64612 struct kcore_list *m;
64613
64614@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64615 kfree(elf_buf);
64616 } else {
64617 if (kern_addr_valid(start)) {
64618- unsigned long n;
64619+ char *elf_buf;
64620+ mm_segment_t oldfs;
64621
64622- n = copy_to_user(buffer, (char *)start, tsz);
64623- /*
64624- * We cannot distinguish between fault on source
64625- * and fault on destination. When this happens
64626- * we clear too and hope it will trigger the
64627- * EFAULT again.
64628- */
64629- if (n) {
64630- if (clear_user(buffer + tsz - n,
64631- n))
64632+ elf_buf = kmalloc(tsz, GFP_KERNEL);
64633+ if (!elf_buf)
64634+ return -ENOMEM;
64635+ oldfs = get_fs();
64636+ set_fs(KERNEL_DS);
64637+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64638+ set_fs(oldfs);
64639+ if (copy_to_user(buffer, elf_buf, tsz)) {
64640+ kfree(elf_buf);
64641 return -EFAULT;
64642+ }
64643 }
64644+ set_fs(oldfs);
64645+ kfree(elf_buf);
64646 } else {
64647 if (clear_user(buffer, tsz))
64648 return -EFAULT;
64649@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64650
64651 static int open_kcore(struct inode *inode, struct file *filp)
64652 {
64653+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64654+ return -EPERM;
64655+#endif
64656 if (!capable(CAP_SYS_RAWIO))
64657 return -EPERM;
64658 if (kcore_need_update)
64659diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64660index 7445af0..7c5113c 100644
64661--- a/fs/proc/meminfo.c
64662+++ b/fs/proc/meminfo.c
64663@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64664 vmi.used >> 10,
64665 vmi.largest_chunk >> 10
64666 #ifdef CONFIG_MEMORY_FAILURE
64667- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64668+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64669 #endif
64670 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64671 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64672diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64673index d4a3574..b421ce9 100644
64674--- a/fs/proc/nommu.c
64675+++ b/fs/proc/nommu.c
64676@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64677
64678 if (file) {
64679 seq_pad(m, ' ');
64680- seq_path(m, &file->f_path, "");
64681+ seq_path(m, &file->f_path, "\n\\");
64682 }
64683
64684 seq_putc(m, '\n');
64685diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64686index 4677bb7..dad3045 100644
64687--- a/fs/proc/proc_net.c
64688+++ b/fs/proc/proc_net.c
64689@@ -23,9 +23,27 @@
64690 #include <linux/nsproxy.h>
64691 #include <net/net_namespace.h>
64692 #include <linux/seq_file.h>
64693+#include <linux/grsecurity.h>
64694
64695 #include "internal.h"
64696
64697+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64698+static struct seq_operations *ipv6_seq_ops_addr;
64699+
64700+void register_ipv6_seq_ops_addr(struct seq_operations *addr)
64701+{
64702+ ipv6_seq_ops_addr = addr;
64703+}
64704+
64705+void unregister_ipv6_seq_ops_addr(void)
64706+{
64707+ ipv6_seq_ops_addr = NULL;
64708+}
64709+
64710+EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
64711+EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
64712+#endif
64713+
64714 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
64715 {
64716 return pde->parent->data;
64717@@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
64718 return maybe_get_net(PDE_NET(PDE(inode)));
64719 }
64720
64721+extern const struct seq_operations dev_seq_ops;
64722+
64723 int seq_open_net(struct inode *ino, struct file *f,
64724 const struct seq_operations *ops, int size)
64725 {
64726@@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
64727
64728 BUG_ON(size < sizeof(*p));
64729
64730+ /* only permit access to /proc/net/dev */
64731+ if (
64732+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64733+ ops != ipv6_seq_ops_addr &&
64734+#endif
64735+ ops != &dev_seq_ops && gr_proc_is_restricted())
64736+ return -EACCES;
64737+
64738 net = get_proc_net(ino);
64739 if (net == NULL)
64740 return -ENXIO;
64741@@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
64742 int err;
64743 struct net *net;
64744
64745+ if (gr_proc_is_restricted())
64746+ return -EACCES;
64747+
64748 err = -ENXIO;
64749 net = get_proc_net(inode);
64750 if (net == NULL)
64751diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64752index 7129046..6914844 100644
64753--- a/fs/proc/proc_sysctl.c
64754+++ b/fs/proc/proc_sysctl.c
64755@@ -11,13 +11,21 @@
64756 #include <linux/namei.h>
64757 #include <linux/mm.h>
64758 #include <linux/module.h>
64759+#include <linux/nsproxy.h>
64760+#ifdef CONFIG_GRKERNSEC
64761+#include <net/net_namespace.h>
64762+#endif
64763 #include "internal.h"
64764
64765+extern int gr_handle_chroot_sysctl(const int op);
64766+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64767+ const int op);
64768+
64769 static const struct dentry_operations proc_sys_dentry_operations;
64770 static const struct file_operations proc_sys_file_operations;
64771-static const struct inode_operations proc_sys_inode_operations;
64772+const struct inode_operations proc_sys_inode_operations;
64773 static const struct file_operations proc_sys_dir_file_operations;
64774-static const struct inode_operations proc_sys_dir_operations;
64775+const struct inode_operations proc_sys_dir_operations;
64776
64777 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64778 {
64779@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64780
64781 err = NULL;
64782 d_set_d_op(dentry, &proc_sys_dentry_operations);
64783+
64784+ gr_handle_proc_create(dentry, inode);
64785+
64786 d_add(dentry, inode);
64787
64788 out:
64789@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64790 struct inode *inode = file_inode(filp);
64791 struct ctl_table_header *head = grab_header(inode);
64792 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64793+ int op = write ? MAY_WRITE : MAY_READ;
64794 ssize_t error;
64795 size_t res;
64796
64797@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64798 * and won't be until we finish.
64799 */
64800 error = -EPERM;
64801- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64802+ if (sysctl_perm(head, table, op))
64803 goto out;
64804
64805 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64806@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64807 if (!table->proc_handler)
64808 goto out;
64809
64810+#ifdef CONFIG_GRKERNSEC
64811+ error = -EPERM;
64812+ if (gr_handle_chroot_sysctl(op))
64813+ goto out;
64814+ dget(filp->f_path.dentry);
64815+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64816+ dput(filp->f_path.dentry);
64817+ goto out;
64818+ }
64819+ dput(filp->f_path.dentry);
64820+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64821+ goto out;
64822+ if (write) {
64823+ if (current->nsproxy->net_ns != table->extra2) {
64824+ if (!capable(CAP_SYS_ADMIN))
64825+ goto out;
64826+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64827+ goto out;
64828+ }
64829+#endif
64830+
64831 /* careful: calling conventions are nasty here */
64832 res = count;
64833 error = table->proc_handler(table, write, buf, &res, ppos);
64834@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64835 return false;
64836 } else {
64837 d_set_d_op(child, &proc_sys_dentry_operations);
64838+
64839+ gr_handle_proc_create(child, inode);
64840+
64841 d_add(child, inode);
64842 }
64843 } else {
64844@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64845 if ((*pos)++ < ctx->pos)
64846 return true;
64847
64848+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64849+ return 0;
64850+
64851 if (unlikely(S_ISLNK(table->mode)))
64852 res = proc_sys_link_fill_cache(file, ctx, head, table);
64853 else
64854@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64855 if (IS_ERR(head))
64856 return PTR_ERR(head);
64857
64858+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64859+ return -ENOENT;
64860+
64861 generic_fillattr(inode, stat);
64862 if (table)
64863 stat->mode = (stat->mode & S_IFMT) | table->mode;
64864@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64865 .llseek = generic_file_llseek,
64866 };
64867
64868-static const struct inode_operations proc_sys_inode_operations = {
64869+const struct inode_operations proc_sys_inode_operations = {
64870 .permission = proc_sys_permission,
64871 .setattr = proc_sys_setattr,
64872 .getattr = proc_sys_getattr,
64873 };
64874
64875-static const struct inode_operations proc_sys_dir_operations = {
64876+const struct inode_operations proc_sys_dir_operations = {
64877 .lookup = proc_sys_lookup,
64878 .permission = proc_sys_permission,
64879 .setattr = proc_sys_setattr,
64880@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64881 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64882 const char *name, int namelen)
64883 {
64884- struct ctl_table *table;
64885+ ctl_table_no_const *table;
64886 struct ctl_dir *new;
64887 struct ctl_node *node;
64888 char *new_name;
64889@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64890 return NULL;
64891
64892 node = (struct ctl_node *)(new + 1);
64893- table = (struct ctl_table *)(node + 1);
64894+ table = (ctl_table_no_const *)(node + 1);
64895 new_name = (char *)(table + 2);
64896 memcpy(new_name, name, namelen);
64897 new_name[namelen] = '\0';
64898@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64899 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64900 struct ctl_table_root *link_root)
64901 {
64902- struct ctl_table *link_table, *entry, *link;
64903+ ctl_table_no_const *link_table, *link;
64904+ struct ctl_table *entry;
64905 struct ctl_table_header *links;
64906 struct ctl_node *node;
64907 char *link_name;
64908@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64909 return NULL;
64910
64911 node = (struct ctl_node *)(links + 1);
64912- link_table = (struct ctl_table *)(node + nr_entries);
64913+ link_table = (ctl_table_no_const *)(node + nr_entries);
64914 link_name = (char *)&link_table[nr_entries + 1];
64915
64916 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64917@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64918 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64919 struct ctl_table *table)
64920 {
64921- struct ctl_table *ctl_table_arg = NULL;
64922- struct ctl_table *entry, *files;
64923+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64924+ struct ctl_table *entry;
64925 int nr_files = 0;
64926 int nr_dirs = 0;
64927 int err = -ENOMEM;
64928@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64929 nr_files++;
64930 }
64931
64932- files = table;
64933 /* If there are mixed files and directories we need a new table */
64934 if (nr_dirs && nr_files) {
64935- struct ctl_table *new;
64936+ ctl_table_no_const *new;
64937 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64938 GFP_KERNEL);
64939 if (!files)
64940@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64941 /* Register everything except a directory full of subdirectories */
64942 if (nr_files || !nr_dirs) {
64943 struct ctl_table_header *header;
64944- header = __register_sysctl_table(set, path, files);
64945+ header = __register_sysctl_table(set, path, files ? files : table);
64946 if (!header) {
64947 kfree(ctl_table_arg);
64948 goto out;
64949diff --git a/fs/proc/root.c b/fs/proc/root.c
64950index 5dbadec..473af2f 100644
64951--- a/fs/proc/root.c
64952+++ b/fs/proc/root.c
64953@@ -185,7 +185,15 @@ void __init proc_root_init(void)
64954 proc_mkdir("openprom", NULL);
64955 #endif
64956 proc_tty_init();
64957+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64958+#ifdef CONFIG_GRKERNSEC_PROC_USER
64959+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64960+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64961+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64962+#endif
64963+#else
64964 proc_mkdir("bus", NULL);
64965+#endif
64966 proc_sys_init();
64967 }
64968
64969diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64970index 9d231e9..2e1b51a 100644
64971--- a/fs/proc/stat.c
64972+++ b/fs/proc/stat.c
64973@@ -11,6 +11,7 @@
64974 #include <linux/irqnr.h>
64975 #include <linux/cputime.h>
64976 #include <linux/tick.h>
64977+#include <linux/grsecurity.h>
64978
64979 #ifndef arch_irq_stat_cpu
64980 #define arch_irq_stat_cpu(cpu) 0
64981@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64982 u64 sum_softirq = 0;
64983 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64984 struct timespec boottime;
64985+ int unrestricted = 1;
64986+
64987+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64988+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64989+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64990+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64991+ && !in_group_p(grsec_proc_gid)
64992+#endif
64993+ )
64994+ unrestricted = 0;
64995+#endif
64996+#endif
64997
64998 user = nice = system = idle = iowait =
64999 irq = softirq = steal = 0;
65000@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
65001 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
65002 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
65003 idle += get_idle_time(i);
65004- iowait += get_iowait_time(i);
65005- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
65006- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
65007- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
65008- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
65009- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
65010- sum += kstat_cpu_irqs_sum(i);
65011- sum += arch_irq_stat_cpu(i);
65012+ if (unrestricted) {
65013+ iowait += get_iowait_time(i);
65014+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
65015+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
65016+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
65017+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
65018+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
65019+ sum += kstat_cpu_irqs_sum(i);
65020+ sum += arch_irq_stat_cpu(i);
65021+ for (j = 0; j < NR_SOFTIRQS; j++) {
65022+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
65023
65024- for (j = 0; j < NR_SOFTIRQS; j++) {
65025- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
65026-
65027- per_softirq_sums[j] += softirq_stat;
65028- sum_softirq += softirq_stat;
65029+ per_softirq_sums[j] += softirq_stat;
65030+ sum_softirq += softirq_stat;
65031+ }
65032 }
65033 }
65034- sum += arch_irq_stat();
65035+ if (unrestricted)
65036+ sum += arch_irq_stat();
65037
65038 seq_puts(p, "cpu ");
65039 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
65040@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
65041 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
65042 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
65043 idle = get_idle_time(i);
65044- iowait = get_iowait_time(i);
65045- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
65046- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
65047- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
65048- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
65049- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
65050+ if (unrestricted) {
65051+ iowait = get_iowait_time(i);
65052+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
65053+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
65054+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
65055+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
65056+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
65057+ }
65058 seq_printf(p, "cpu%d", i);
65059 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
65060 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
65061@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
65062
65063 /* sum again ? it could be updated? */
65064 for_each_irq_nr(j)
65065- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
65066+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
65067
65068 seq_printf(p,
65069 "\nctxt %llu\n"
65070@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
65071 "processes %lu\n"
65072 "procs_running %lu\n"
65073 "procs_blocked %lu\n",
65074- nr_context_switches(),
65075+ unrestricted ? nr_context_switches() : 0ULL,
65076 (unsigned long)jif,
65077- total_forks,
65078- nr_running(),
65079- nr_iowait());
65080+ unrestricted ? total_forks : 0UL,
65081+ unrestricted ? nr_running() : 0UL,
65082+ unrestricted ? nr_iowait() : 0UL);
65083
65084 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
65085
65086diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
65087index c4b2646..84f0d7b 100644
65088--- a/fs/proc/task_mmu.c
65089+++ b/fs/proc/task_mmu.c
65090@@ -13,12 +13,19 @@
65091 #include <linux/swap.h>
65092 #include <linux/swapops.h>
65093 #include <linux/mmu_notifier.h>
65094+#include <linux/grsecurity.h>
65095
65096 #include <asm/elf.h>
65097 #include <asm/uaccess.h>
65098 #include <asm/tlbflush.h>
65099 #include "internal.h"
65100
65101+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65102+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65103+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
65104+ _mm->pax_flags & MF_PAX_SEGMEXEC))
65105+#endif
65106+
65107 void task_mem(struct seq_file *m, struct mm_struct *mm)
65108 {
65109 unsigned long data, text, lib, swap;
65110@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
65111 "VmExe:\t%8lu kB\n"
65112 "VmLib:\t%8lu kB\n"
65113 "VmPTE:\t%8lu kB\n"
65114- "VmSwap:\t%8lu kB\n",
65115- hiwater_vm << (PAGE_SHIFT-10),
65116+ "VmSwap:\t%8lu kB\n"
65117+
65118+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65119+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
65120+#endif
65121+
65122+ ,hiwater_vm << (PAGE_SHIFT-10),
65123 total_vm << (PAGE_SHIFT-10),
65124 mm->locked_vm << (PAGE_SHIFT-10),
65125 mm->pinned_vm << (PAGE_SHIFT-10),
65126@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
65127 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
65128 (PTRS_PER_PTE * sizeof(pte_t) *
65129 atomic_long_read(&mm->nr_ptes)) >> 10,
65130- swap << (PAGE_SHIFT-10));
65131+ swap << (PAGE_SHIFT-10)
65132+
65133+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65134+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65135+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
65136+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
65137+#else
65138+ , mm->context.user_cs_base
65139+ , mm->context.user_cs_limit
65140+#endif
65141+#endif
65142+
65143+ );
65144 }
65145
65146 unsigned long task_vsize(struct mm_struct *mm)
65147@@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
65148 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
65149 }
65150
65151- /* We don't show the stack guard page in /proc/maps */
65152+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65153+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
65154+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
65155+#else
65156 start = vma->vm_start;
65157- if (stack_guard_page_start(vma, start))
65158- start += PAGE_SIZE;
65159 end = vma->vm_end;
65160- if (stack_guard_page_end(vma, end))
65161- end -= PAGE_SIZE;
65162+#endif
65163
65164 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
65165 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
65166@@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
65167 flags & VM_WRITE ? 'w' : '-',
65168 flags & VM_EXEC ? 'x' : '-',
65169 flags & VM_MAYSHARE ? 's' : 'p',
65170+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65171+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
65172+#else
65173 pgoff,
65174+#endif
65175 MAJOR(dev), MINOR(dev), ino);
65176
65177 /*
65178@@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
65179 */
65180 if (file) {
65181 seq_pad(m, ' ');
65182- seq_path(m, &file->f_path, "\n");
65183+ seq_path(m, &file->f_path, "\n\\");
65184 goto done;
65185 }
65186
65187@@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
65188 * Thread stack in /proc/PID/task/TID/maps or
65189 * the main process stack.
65190 */
65191- if (!is_pid || (vma->vm_start <= mm->start_stack &&
65192- vma->vm_end >= mm->start_stack)) {
65193+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
65194+ (vma->vm_start <= mm->start_stack &&
65195+ vma->vm_end >= mm->start_stack)) {
65196 name = "[stack]";
65197 } else {
65198 /* Thread stack in /proc/PID/maps */
65199@@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
65200 struct proc_maps_private *priv = m->private;
65201 struct task_struct *task = priv->task;
65202
65203+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65204+ if (current->exec_id != m->exec_id) {
65205+ gr_log_badprocpid("maps");
65206+ return 0;
65207+ }
65208+#endif
65209+
65210 show_map_vma(m, vma, is_pid);
65211
65212 if (m->count < m->size) /* vma is copied successfully */
65213@@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
65214 .private = &mss,
65215 };
65216
65217+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65218+ if (current->exec_id != m->exec_id) {
65219+ gr_log_badprocpid("smaps");
65220+ return 0;
65221+ }
65222+#endif
65223 memset(&mss, 0, sizeof mss);
65224- mss.vma = vma;
65225- /* mmap_sem is held in m_start */
65226- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
65227- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
65228-
65229+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65230+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
65231+#endif
65232+ mss.vma = vma;
65233+ /* mmap_sem is held in m_start */
65234+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
65235+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
65236+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65237+ }
65238+#endif
65239 show_map_vma(m, vma, is_pid);
65240
65241 seq_printf(m,
65242@@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
65243 "KernelPageSize: %8lu kB\n"
65244 "MMUPageSize: %8lu kB\n"
65245 "Locked: %8lu kB\n",
65246+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65247+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
65248+#else
65249 (vma->vm_end - vma->vm_start) >> 10,
65250+#endif
65251 mss.resident >> 10,
65252 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
65253 mss.shared_clean >> 10,
65254@@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
65255 char buffer[64];
65256 int nid;
65257
65258+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65259+ if (current->exec_id != m->exec_id) {
65260+ gr_log_badprocpid("numa_maps");
65261+ return 0;
65262+ }
65263+#endif
65264+
65265 if (!mm)
65266 return 0;
65267
65268@@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
65269 mpol_to_str(buffer, sizeof(buffer), pol);
65270 mpol_cond_put(pol);
65271
65272+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65273+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
65274+#else
65275 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
65276+#endif
65277
65278 if (file) {
65279 seq_printf(m, " file=");
65280- seq_path(m, &file->f_path, "\n\t= ");
65281+ seq_path(m, &file->f_path, "\n\t\\= ");
65282 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
65283 seq_printf(m, " heap");
65284 } else {
65285diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
65286index 678455d..ebd3245 100644
65287--- a/fs/proc/task_nommu.c
65288+++ b/fs/proc/task_nommu.c
65289@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
65290 else
65291 bytes += kobjsize(mm);
65292
65293- if (current->fs && current->fs->users > 1)
65294+ if (current->fs && atomic_read(&current->fs->users) > 1)
65295 sbytes += kobjsize(current->fs);
65296 else
65297 bytes += kobjsize(current->fs);
65298@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
65299
65300 if (file) {
65301 seq_pad(m, ' ');
65302- seq_path(m, &file->f_path, "");
65303+ seq_path(m, &file->f_path, "\n\\");
65304 } else if (mm) {
65305 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
65306
65307diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
65308index 6a8e785..41f2a6c 100644
65309--- a/fs/proc/vmcore.c
65310+++ b/fs/proc/vmcore.c
65311@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
65312 nr_bytes = count;
65313
65314 /* If pfn is not ram, return zeros for sparse dump files */
65315- if (pfn_is_ram(pfn) == 0)
65316- memset(buf, 0, nr_bytes);
65317- else {
65318+ if (pfn_is_ram(pfn) == 0) {
65319+ if (userbuf) {
65320+ if (clear_user((char __force_user *)buf, nr_bytes))
65321+ return -EFAULT;
65322+ } else
65323+ memset(buf, 0, nr_bytes);
65324+ } else {
65325 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
65326 offset, userbuf);
65327 if (tmp < 0)
65328@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
65329 static int copy_to(void *target, void *src, size_t size, int userbuf)
65330 {
65331 if (userbuf) {
65332- if (copy_to_user((char __user *) target, src, size))
65333+ if (copy_to_user((char __force_user *) target, src, size))
65334 return -EFAULT;
65335 } else {
65336 memcpy(target, src, size);
65337@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65338 if (*fpos < m->offset + m->size) {
65339 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
65340 start = m->paddr + *fpos - m->offset;
65341- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
65342+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
65343 if (tmp < 0)
65344 return tmp;
65345 buflen -= tsz;
65346@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65347 static ssize_t read_vmcore(struct file *file, char __user *buffer,
65348 size_t buflen, loff_t *fpos)
65349 {
65350- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
65351+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
65352 }
65353
65354 /*
65355diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
65356index b00fcc9..e0c6381 100644
65357--- a/fs/qnx6/qnx6.h
65358+++ b/fs/qnx6/qnx6.h
65359@@ -74,7 +74,7 @@ enum {
65360 BYTESEX_BE,
65361 };
65362
65363-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65364+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65365 {
65366 if (sbi->s_bytesex == BYTESEX_LE)
65367 return le64_to_cpu((__force __le64)n);
65368@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65369 return (__force __fs64)cpu_to_be64(n);
65370 }
65371
65372-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65373+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65374 {
65375 if (sbi->s_bytesex == BYTESEX_LE)
65376 return le32_to_cpu((__force __le32)n);
65377diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65378index 72d2917..c917c12 100644
65379--- a/fs/quota/netlink.c
65380+++ b/fs/quota/netlink.c
65381@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65382 void quota_send_warning(struct kqid qid, dev_t dev,
65383 const char warntype)
65384 {
65385- static atomic_t seq;
65386+ static atomic_unchecked_t seq;
65387 struct sk_buff *skb;
65388 void *msg_head;
65389 int ret;
65390@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65391 "VFS: Not enough memory to send quota warning.\n");
65392 return;
65393 }
65394- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65395+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65396 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65397 if (!msg_head) {
65398 printk(KERN_ERR
65399diff --git a/fs/read_write.c b/fs/read_write.c
65400index 31c6efa..a068805 100644
65401--- a/fs/read_write.c
65402+++ b/fs/read_write.c
65403@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65404
65405 old_fs = get_fs();
65406 set_fs(get_ds());
65407- p = (__force const char __user *)buf;
65408+ p = (const char __force_user *)buf;
65409 if (count > MAX_RW_COUNT)
65410 count = MAX_RW_COUNT;
65411 if (file->f_op->write)
65412diff --git a/fs/readdir.c b/fs/readdir.c
65413index 5b53d99..a6c3049 100644
65414--- a/fs/readdir.c
65415+++ b/fs/readdir.c
65416@@ -17,6 +17,7 @@
65417 #include <linux/security.h>
65418 #include <linux/syscalls.h>
65419 #include <linux/unistd.h>
65420+#include <linux/namei.h>
65421
65422 #include <asm/uaccess.h>
65423
65424@@ -69,6 +70,7 @@ struct old_linux_dirent {
65425 struct readdir_callback {
65426 struct dir_context ctx;
65427 struct old_linux_dirent __user * dirent;
65428+ struct file * file;
65429 int result;
65430 };
65431
65432@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65433 buf->result = -EOVERFLOW;
65434 return -EOVERFLOW;
65435 }
65436+
65437+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65438+ return 0;
65439+
65440 buf->result++;
65441 dirent = buf->dirent;
65442 if (!access_ok(VERIFY_WRITE, dirent,
65443@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65444 if (!f.file)
65445 return -EBADF;
65446
65447+ buf.file = f.file;
65448 error = iterate_dir(f.file, &buf.ctx);
65449 if (buf.result)
65450 error = buf.result;
65451@@ -142,6 +149,7 @@ struct getdents_callback {
65452 struct dir_context ctx;
65453 struct linux_dirent __user * current_dir;
65454 struct linux_dirent __user * previous;
65455+ struct file * file;
65456 int count;
65457 int error;
65458 };
65459@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65460 buf->error = -EOVERFLOW;
65461 return -EOVERFLOW;
65462 }
65463+
65464+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65465+ return 0;
65466+
65467 dirent = buf->previous;
65468 if (dirent) {
65469 if (__put_user(offset, &dirent->d_off))
65470@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65471 if (!f.file)
65472 return -EBADF;
65473
65474+ buf.file = f.file;
65475 error = iterate_dir(f.file, &buf.ctx);
65476 if (error >= 0)
65477 error = buf.error;
65478@@ -226,6 +239,7 @@ struct getdents_callback64 {
65479 struct dir_context ctx;
65480 struct linux_dirent64 __user * current_dir;
65481 struct linux_dirent64 __user * previous;
65482+ struct file *file;
65483 int count;
65484 int error;
65485 };
65486@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65487 buf->error = -EINVAL; /* only used if we fail.. */
65488 if (reclen > buf->count)
65489 return -EINVAL;
65490+
65491+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65492+ return 0;
65493+
65494 dirent = buf->previous;
65495 if (dirent) {
65496 if (__put_user(offset, &dirent->d_off))
65497@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65498 if (!f.file)
65499 return -EBADF;
65500
65501+ buf.file = f.file;
65502 error = iterate_dir(f.file, &buf.ctx);
65503 if (error >= 0)
65504 error = buf.error;
65505diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65506index 9a3c68c..767933e 100644
65507--- a/fs/reiserfs/do_balan.c
65508+++ b/fs/reiserfs/do_balan.c
65509@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65510 return;
65511 }
65512
65513- atomic_inc(&(fs_generation(tb->tb_sb)));
65514+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65515 do_balance_starts(tb);
65516
65517 /* balance leaf returns 0 except if combining L R and S into
65518diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65519index ee382ef..f4eb6eb5 100644
65520--- a/fs/reiserfs/item_ops.c
65521+++ b/fs/reiserfs/item_ops.c
65522@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65523 }
65524
65525 static struct item_operations errcatch_ops = {
65526- errcatch_bytes_number,
65527- errcatch_decrement_key,
65528- errcatch_is_left_mergeable,
65529- errcatch_print_item,
65530- errcatch_check_item,
65531+ .bytes_number = errcatch_bytes_number,
65532+ .decrement_key = errcatch_decrement_key,
65533+ .is_left_mergeable = errcatch_is_left_mergeable,
65534+ .print_item = errcatch_print_item,
65535+ .check_item = errcatch_check_item,
65536
65537- errcatch_create_vi,
65538- errcatch_check_left,
65539- errcatch_check_right,
65540- errcatch_part_size,
65541- errcatch_unit_num,
65542- errcatch_print_vi
65543+ .create_vi = errcatch_create_vi,
65544+ .check_left = errcatch_check_left,
65545+ .check_right = errcatch_check_right,
65546+ .part_size = errcatch_part_size,
65547+ .unit_num = errcatch_unit_num,
65548+ .print_vi = errcatch_print_vi
65549 };
65550
65551 //////////////////////////////////////////////////////////////////////////////
65552diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65553index 02b0b7d..c85018b 100644
65554--- a/fs/reiserfs/procfs.c
65555+++ b/fs/reiserfs/procfs.c
65556@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65557 "SMALL_TAILS " : "NO_TAILS ",
65558 replay_only(sb) ? "REPLAY_ONLY " : "",
65559 convert_reiserfs(sb) ? "CONV " : "",
65560- atomic_read(&r->s_generation_counter),
65561+ atomic_read_unchecked(&r->s_generation_counter),
65562 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65563 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65564 SF(s_good_search_by_key_reada), SF(s_bmaps),
65565diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65566index 83d4eac..04e39a7 100644
65567--- a/fs/reiserfs/reiserfs.h
65568+++ b/fs/reiserfs/reiserfs.h
65569@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65570 /* Comment? -Hans */
65571 wait_queue_head_t s_wait;
65572 /* To be obsoleted soon by per buffer seals.. -Hans */
65573- atomic_t s_generation_counter; // increased by one every time the
65574+ atomic_unchecked_t s_generation_counter; // increased by one every time the
65575 // tree gets re-balanced
65576 unsigned long s_properties; /* File system properties. Currently holds
65577 on-disk FS format */
65578@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65579 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65580
65581 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65582-#define get_generation(s) atomic_read (&fs_generation(s))
65583+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65584 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65585 #define __fs_changed(gen,s) (gen != get_generation (s))
65586 #define fs_changed(gen,s) \
65587diff --git a/fs/select.c b/fs/select.c
65588index 467bb1c..cf9d65a 100644
65589--- a/fs/select.c
65590+++ b/fs/select.c
65591@@ -20,6 +20,7 @@
65592 #include <linux/export.h>
65593 #include <linux/slab.h>
65594 #include <linux/poll.h>
65595+#include <linux/security.h>
65596 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65597 #include <linux/file.h>
65598 #include <linux/fdtable.h>
65599@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65600 struct poll_list *walk = head;
65601 unsigned long todo = nfds;
65602
65603+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65604 if (nfds > rlimit(RLIMIT_NOFILE))
65605 return -EINVAL;
65606
65607diff --git a/fs/seq_file.c b/fs/seq_file.c
65608index 1d641bb..c2f4743 100644
65609--- a/fs/seq_file.c
65610+++ b/fs/seq_file.c
65611@@ -10,6 +10,8 @@
65612 #include <linux/seq_file.h>
65613 #include <linux/slab.h>
65614 #include <linux/cred.h>
65615+#include <linux/sched.h>
65616+#include <linux/grsecurity.h>
65617
65618 #include <asm/uaccess.h>
65619 #include <asm/page.h>
65620@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65621 #ifdef CONFIG_USER_NS
65622 p->user_ns = file->f_cred->user_ns;
65623 #endif
65624+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65625+ p->exec_id = current->exec_id;
65626+#endif
65627
65628 /*
65629 * Wrappers around seq_open(e.g. swaps_open) need to be
65630@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65631 }
65632 EXPORT_SYMBOL(seq_open);
65633
65634+
65635+int seq_open_restrict(struct file *file, const struct seq_operations *op)
65636+{
65637+ if (gr_proc_is_restricted())
65638+ return -EACCES;
65639+
65640+ return seq_open(file, op);
65641+}
65642+EXPORT_SYMBOL(seq_open_restrict);
65643+
65644 static int traverse(struct seq_file *m, loff_t offset)
65645 {
65646 loff_t pos = 0, index;
65647@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65648 return 0;
65649 }
65650 if (!m->buf) {
65651- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65652+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65653 if (!m->buf)
65654 return -ENOMEM;
65655 }
65656@@ -137,7 +152,7 @@ Eoverflow:
65657 m->op->stop(m, p);
65658 kfree(m->buf);
65659 m->count = 0;
65660- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65661+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65662 return !m->buf ? -ENOMEM : -EAGAIN;
65663 }
65664
65665@@ -153,7 +168,7 @@ Eoverflow:
65666 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65667 {
65668 struct seq_file *m = file->private_data;
65669- size_t copied = 0;
65670+ ssize_t copied = 0;
65671 loff_t pos;
65672 size_t n;
65673 void *p;
65674@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65675
65676 /* grab buffer if we didn't have one */
65677 if (!m->buf) {
65678- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65679+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65680 if (!m->buf)
65681 goto Enomem;
65682 }
65683@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65684 m->op->stop(m, p);
65685 kfree(m->buf);
65686 m->count = 0;
65687- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65688+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65689 if (!m->buf)
65690 goto Enomem;
65691 m->version = 0;
65692@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65693 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65694 void *data)
65695 {
65696- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65697+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65698 int res = -ENOMEM;
65699
65700 if (op) {
65701@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65702 }
65703 EXPORT_SYMBOL(single_open_size);
65704
65705+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65706+ void *data)
65707+{
65708+ if (gr_proc_is_restricted())
65709+ return -EACCES;
65710+
65711+ return single_open(file, show, data);
65712+}
65713+EXPORT_SYMBOL(single_open_restrict);
65714+
65715+
65716 int single_release(struct inode *inode, struct file *file)
65717 {
65718 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65719diff --git a/fs/splice.c b/fs/splice.c
65720index e246954..bd4f5b5 100644
65721--- a/fs/splice.c
65722+++ b/fs/splice.c
65723@@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65724 pipe_lock(pipe);
65725
65726 for (;;) {
65727- if (!pipe->readers) {
65728+ if (!atomic_read(&pipe->readers)) {
65729 send_sig(SIGPIPE, current, 0);
65730 if (!ret)
65731 ret = -EPIPE;
65732@@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65733 page_nr++;
65734 ret += buf->len;
65735
65736- if (pipe->files)
65737+ if (atomic_read(&pipe->files))
65738 do_wakeup = 1;
65739
65740 if (!--spd->nr_pages)
65741@@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65742 do_wakeup = 0;
65743 }
65744
65745- pipe->waiting_writers++;
65746+ atomic_inc(&pipe->waiting_writers);
65747 pipe_wait(pipe);
65748- pipe->waiting_writers--;
65749+ atomic_dec(&pipe->waiting_writers);
65750 }
65751
65752 pipe_unlock(pipe);
65753@@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65754 old_fs = get_fs();
65755 set_fs(get_ds());
65756 /* The cast to a user pointer is valid due to the set_fs() */
65757- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65758+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65759 set_fs(old_fs);
65760
65761 return res;
65762@@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65763 old_fs = get_fs();
65764 set_fs(get_ds());
65765 /* The cast to a user pointer is valid due to the set_fs() */
65766- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65767+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65768 set_fs(old_fs);
65769
65770 return res;
65771@@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65772 goto err;
65773
65774 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65775- vec[i].iov_base = (void __user *) page_address(page);
65776+ vec[i].iov_base = (void __force_user *) page_address(page);
65777 vec[i].iov_len = this_len;
65778 spd.pages[i] = page;
65779 spd.nr_pages++;
65780@@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65781 ops->release(pipe, buf);
65782 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65783 pipe->nrbufs--;
65784- if (pipe->files)
65785+ if (atomic_read(&pipe->files))
65786 sd->need_wakeup = true;
65787 }
65788
65789@@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65790 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65791 {
65792 while (!pipe->nrbufs) {
65793- if (!pipe->writers)
65794+ if (!atomic_read(&pipe->writers))
65795 return 0;
65796
65797- if (!pipe->waiting_writers && sd->num_spliced)
65798+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65799 return 0;
65800
65801 if (sd->flags & SPLICE_F_NONBLOCK)
65802@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65803 * out of the pipe right after the splice_to_pipe(). So set
65804 * PIPE_READERS appropriately.
65805 */
65806- pipe->readers = 1;
65807+ atomic_set(&pipe->readers, 1);
65808
65809 current->splice_pipe = pipe;
65810 }
65811@@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65812
65813 partial[buffers].offset = off;
65814 partial[buffers].len = plen;
65815+ partial[buffers].private = 0;
65816
65817 off = 0;
65818 len -= plen;
65819@@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65820 ret = -ERESTARTSYS;
65821 break;
65822 }
65823- if (!pipe->writers)
65824+ if (!atomic_read(&pipe->writers))
65825 break;
65826- if (!pipe->waiting_writers) {
65827+ if (!atomic_read(&pipe->waiting_writers)) {
65828 if (flags & SPLICE_F_NONBLOCK) {
65829 ret = -EAGAIN;
65830 break;
65831@@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65832 pipe_lock(pipe);
65833
65834 while (pipe->nrbufs >= pipe->buffers) {
65835- if (!pipe->readers) {
65836+ if (!atomic_read(&pipe->readers)) {
65837 send_sig(SIGPIPE, current, 0);
65838 ret = -EPIPE;
65839 break;
65840@@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65841 ret = -ERESTARTSYS;
65842 break;
65843 }
65844- pipe->waiting_writers++;
65845+ atomic_inc(&pipe->waiting_writers);
65846 pipe_wait(pipe);
65847- pipe->waiting_writers--;
65848+ atomic_dec(&pipe->waiting_writers);
65849 }
65850
65851 pipe_unlock(pipe);
65852@@ -1806,14 +1807,14 @@ retry:
65853 pipe_double_lock(ipipe, opipe);
65854
65855 do {
65856- if (!opipe->readers) {
65857+ if (!atomic_read(&opipe->readers)) {
65858 send_sig(SIGPIPE, current, 0);
65859 if (!ret)
65860 ret = -EPIPE;
65861 break;
65862 }
65863
65864- if (!ipipe->nrbufs && !ipipe->writers)
65865+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65866 break;
65867
65868 /*
65869@@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65870 pipe_double_lock(ipipe, opipe);
65871
65872 do {
65873- if (!opipe->readers) {
65874+ if (!atomic_read(&opipe->readers)) {
65875 send_sig(SIGPIPE, current, 0);
65876 if (!ret)
65877 ret = -EPIPE;
65878@@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65879 * return EAGAIN if we have the potential of some data in the
65880 * future, otherwise just return 0
65881 */
65882- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65883+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65884 ret = -EAGAIN;
65885
65886 pipe_unlock(ipipe);
65887diff --git a/fs/stat.c b/fs/stat.c
65888index ae0c3ce..9ee641c 100644
65889--- a/fs/stat.c
65890+++ b/fs/stat.c
65891@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65892 stat->gid = inode->i_gid;
65893 stat->rdev = inode->i_rdev;
65894 stat->size = i_size_read(inode);
65895- stat->atime = inode->i_atime;
65896- stat->mtime = inode->i_mtime;
65897+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65898+ stat->atime = inode->i_ctime;
65899+ stat->mtime = inode->i_ctime;
65900+ } else {
65901+ stat->atime = inode->i_atime;
65902+ stat->mtime = inode->i_mtime;
65903+ }
65904 stat->ctime = inode->i_ctime;
65905 stat->blksize = (1 << inode->i_blkbits);
65906 stat->blocks = inode->i_blocks;
65907@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65908 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65909 {
65910 struct inode *inode = path->dentry->d_inode;
65911+ int retval;
65912
65913- if (inode->i_op->getattr)
65914- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65915+ if (inode->i_op->getattr) {
65916+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65917+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65918+ stat->atime = stat->ctime;
65919+ stat->mtime = stat->ctime;
65920+ }
65921+ return retval;
65922+ }
65923
65924 generic_fillattr(inode, stat);
65925 return 0;
65926diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65927index 0b45ff4..847de5b 100644
65928--- a/fs/sysfs/dir.c
65929+++ b/fs/sysfs/dir.c
65930@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65931 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65932 {
65933 struct kernfs_node *parent, *kn;
65934+ const char *name;
65935+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65936+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65937+ const char *parent_name;
65938+#endif
65939
65940 BUG_ON(!kobj);
65941
65942+ name = kobject_name(kobj);
65943+
65944 if (kobj->parent)
65945 parent = kobj->parent->sd;
65946 else
65947@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65948 if (!parent)
65949 return -ENOENT;
65950
65951- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65952- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65953+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65954+ parent_name = parent->name;
65955+ mode = S_IRWXU;
65956+
65957+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65958+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65959+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65960+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65961+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65962+#endif
65963+
65964+ kn = kernfs_create_dir_ns(parent, name,
65965+ mode, kobj, ns);
65966 if (IS_ERR(kn)) {
65967 if (PTR_ERR(kn) == -EEXIST)
65968- sysfs_warn_dup(parent, kobject_name(kobj));
65969+ sysfs_warn_dup(parent, name);
65970 return PTR_ERR(kn);
65971 }
65972
65973diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65974index 69d4889..a810bd4 100644
65975--- a/fs/sysv/sysv.h
65976+++ b/fs/sysv/sysv.h
65977@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65978 #endif
65979 }
65980
65981-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65982+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65983 {
65984 if (sbi->s_bytesex == BYTESEX_PDP)
65985 return PDP_swab((__force __u32)n);
65986diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65987index e18b988..f1d4ad0f 100644
65988--- a/fs/ubifs/io.c
65989+++ b/fs/ubifs/io.c
65990@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65991 return err;
65992 }
65993
65994-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65995+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65996 {
65997 int err;
65998
65999diff --git a/fs/udf/misc.c b/fs/udf/misc.c
66000index c175b4d..8f36a16 100644
66001--- a/fs/udf/misc.c
66002+++ b/fs/udf/misc.c
66003@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
66004
66005 u8 udf_tag_checksum(const struct tag *t)
66006 {
66007- u8 *data = (u8 *)t;
66008+ const u8 *data = (const u8 *)t;
66009 u8 checksum = 0;
66010 int i;
66011 for (i = 0; i < sizeof(struct tag); ++i)
66012diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
66013index 8d974c4..b82f6ec 100644
66014--- a/fs/ufs/swab.h
66015+++ b/fs/ufs/swab.h
66016@@ -22,7 +22,7 @@ enum {
66017 BYTESEX_BE
66018 };
66019
66020-static inline u64
66021+static inline u64 __intentional_overflow(-1)
66022 fs64_to_cpu(struct super_block *sbp, __fs64 n)
66023 {
66024 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
66025@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
66026 return (__force __fs64)cpu_to_be64(n);
66027 }
66028
66029-static inline u32
66030+static inline u32 __intentional_overflow(-1)
66031 fs32_to_cpu(struct super_block *sbp, __fs32 n)
66032 {
66033 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
66034diff --git a/fs/utimes.c b/fs/utimes.c
66035index aa138d6..5f3a811 100644
66036--- a/fs/utimes.c
66037+++ b/fs/utimes.c
66038@@ -1,6 +1,7 @@
66039 #include <linux/compiler.h>
66040 #include <linux/file.h>
66041 #include <linux/fs.h>
66042+#include <linux/security.h>
66043 #include <linux/linkage.h>
66044 #include <linux/mount.h>
66045 #include <linux/namei.h>
66046@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
66047 }
66048 }
66049 retry_deleg:
66050+
66051+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
66052+ error = -EACCES;
66053+ goto mnt_drop_write_and_out;
66054+ }
66055+
66056 mutex_lock(&inode->i_mutex);
66057 error = notify_change(path->dentry, &newattrs, &delegated_inode);
66058 mutex_unlock(&inode->i_mutex);
66059diff --git a/fs/xattr.c b/fs/xattr.c
66060index 3377dff..f394815 100644
66061--- a/fs/xattr.c
66062+++ b/fs/xattr.c
66063@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
66064 return rc;
66065 }
66066
66067+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
66068+ssize_t
66069+pax_getxattr(struct dentry *dentry, void *value, size_t size)
66070+{
66071+ struct inode *inode = dentry->d_inode;
66072+ ssize_t error;
66073+
66074+ error = inode_permission(inode, MAY_EXEC);
66075+ if (error)
66076+ return error;
66077+
66078+ if (inode->i_op->getxattr)
66079+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
66080+ else
66081+ error = -EOPNOTSUPP;
66082+
66083+ return error;
66084+}
66085+EXPORT_SYMBOL(pax_getxattr);
66086+#endif
66087+
66088 ssize_t
66089 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
66090 {
66091@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
66092 * Extended attribute SET operations
66093 */
66094 static long
66095-setxattr(struct dentry *d, const char __user *name, const void __user *value,
66096+setxattr(struct path *path, const char __user *name, const void __user *value,
66097 size_t size, int flags)
66098 {
66099 int error;
66100@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
66101 posix_acl_fix_xattr_from_user(kvalue, size);
66102 }
66103
66104- error = vfs_setxattr(d, kname, kvalue, size, flags);
66105+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
66106+ error = -EACCES;
66107+ goto out;
66108+ }
66109+
66110+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
66111 out:
66112 if (vvalue)
66113 vfree(vvalue);
66114@@ -377,7 +403,7 @@ retry:
66115 return error;
66116 error = mnt_want_write(path.mnt);
66117 if (!error) {
66118- error = setxattr(path.dentry, name, value, size, flags);
66119+ error = setxattr(&path, name, value, size, flags);
66120 mnt_drop_write(path.mnt);
66121 }
66122 path_put(&path);
66123@@ -401,7 +427,7 @@ retry:
66124 return error;
66125 error = mnt_want_write(path.mnt);
66126 if (!error) {
66127- error = setxattr(path.dentry, name, value, size, flags);
66128+ error = setxattr(&path, name, value, size, flags);
66129 mnt_drop_write(path.mnt);
66130 }
66131 path_put(&path);
66132@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
66133 const void __user *,value, size_t, size, int, flags)
66134 {
66135 struct fd f = fdget(fd);
66136- struct dentry *dentry;
66137 int error = -EBADF;
66138
66139 if (!f.file)
66140 return error;
66141- dentry = f.file->f_path.dentry;
66142- audit_inode(NULL, dentry, 0);
66143+ audit_inode(NULL, f.file->f_path.dentry, 0);
66144 error = mnt_want_write_file(f.file);
66145 if (!error) {
66146- error = setxattr(dentry, name, value, size, flags);
66147+ error = setxattr(&f.file->f_path, name, value, size, flags);
66148 mnt_drop_write_file(f.file);
66149 }
66150 fdput(f);
66151@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
66152 * Extended attribute REMOVE operations
66153 */
66154 static long
66155-removexattr(struct dentry *d, const char __user *name)
66156+removexattr(struct path *path, const char __user *name)
66157 {
66158 int error;
66159 char kname[XATTR_NAME_MAX + 1];
66160@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
66161 if (error < 0)
66162 return error;
66163
66164- return vfs_removexattr(d, kname);
66165+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
66166+ return -EACCES;
66167+
66168+ return vfs_removexattr(path->dentry, kname);
66169 }
66170
66171 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
66172@@ -652,7 +679,7 @@ retry:
66173 return error;
66174 error = mnt_want_write(path.mnt);
66175 if (!error) {
66176- error = removexattr(path.dentry, name);
66177+ error = removexattr(&path, name);
66178 mnt_drop_write(path.mnt);
66179 }
66180 path_put(&path);
66181@@ -675,7 +702,7 @@ retry:
66182 return error;
66183 error = mnt_want_write(path.mnt);
66184 if (!error) {
66185- error = removexattr(path.dentry, name);
66186+ error = removexattr(&path, name);
66187 mnt_drop_write(path.mnt);
66188 }
66189 path_put(&path);
66190@@ -689,16 +716,16 @@ retry:
66191 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
66192 {
66193 struct fd f = fdget(fd);
66194- struct dentry *dentry;
66195+ struct path *path;
66196 int error = -EBADF;
66197
66198 if (!f.file)
66199 return error;
66200- dentry = f.file->f_path.dentry;
66201- audit_inode(NULL, dentry, 0);
66202+ path = &f.file->f_path;
66203+ audit_inode(NULL, path->dentry, 0);
66204 error = mnt_want_write_file(f.file);
66205 if (!error) {
66206- error = removexattr(dentry, name);
66207+ error = removexattr(path, name);
66208 mnt_drop_write_file(f.file);
66209 }
66210 fdput(f);
66211diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
66212index f0efc7e..ba72910 100644
66213--- a/fs/xfs/xfs_bmap.c
66214+++ b/fs/xfs/xfs_bmap.c
66215@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
66216
66217 #else
66218 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
66219-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
66220+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
66221 #endif /* DEBUG */
66222
66223 /*
66224diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
66225index aead369..0dfecfd 100644
66226--- a/fs/xfs/xfs_dir2_readdir.c
66227+++ b/fs/xfs/xfs_dir2_readdir.c
66228@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
66229 ino = dp->d_ops->sf_get_ino(sfp, sfep);
66230 filetype = dp->d_ops->sf_get_ftype(sfep);
66231 ctx->pos = off & 0x7fffffff;
66232- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
66233+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
66234+ char name[sfep->namelen];
66235+ memcpy(name, sfep->name, sfep->namelen);
66236+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
66237+ return 0;
66238+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
66239 xfs_dir3_get_dtype(mp, filetype)))
66240 return 0;
66241 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
66242diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
66243index 6152cbe..f0f9eaa 100644
66244--- a/fs/xfs/xfs_ioctl.c
66245+++ b/fs/xfs/xfs_ioctl.c
66246@@ -122,7 +122,7 @@ xfs_find_handle(
66247 }
66248
66249 error = -EFAULT;
66250- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
66251+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
66252 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
66253 goto out_put;
66254
66255diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
66256new file mode 100644
66257index 0000000..27cec32
66258--- /dev/null
66259+++ b/grsecurity/Kconfig
66260@@ -0,0 +1,1166 @@
66261+#
66262+# grecurity configuration
66263+#
66264+menu "Memory Protections"
66265+depends on GRKERNSEC
66266+
66267+config GRKERNSEC_KMEM
66268+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
66269+ default y if GRKERNSEC_CONFIG_AUTO
66270+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
66271+ help
66272+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
66273+ be written to or read from to modify or leak the contents of the running
66274+ kernel. /dev/port will also not be allowed to be opened, writing to
66275+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
66276+ If you have module support disabled, enabling this will close up several
66277+ ways that are currently used to insert malicious code into the running
66278+ kernel.
66279+
66280+ Even with this feature enabled, we still highly recommend that
66281+ you use the RBAC system, as it is still possible for an attacker to
66282+ modify the running kernel through other more obscure methods.
66283+
66284+ It is highly recommended that you say Y here if you meet all the
66285+ conditions above.
66286+
66287+config GRKERNSEC_VM86
66288+ bool "Restrict VM86 mode"
66289+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66290+ depends on X86_32
66291+
66292+ help
66293+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
66294+ make use of a special execution mode on 32bit x86 processors called
66295+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
66296+ video cards and will still work with this option enabled. The purpose
66297+ of the option is to prevent exploitation of emulation errors in
66298+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
66299+ Nearly all users should be able to enable this option.
66300+
66301+config GRKERNSEC_IO
66302+ bool "Disable privileged I/O"
66303+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66304+ depends on X86
66305+ select RTC_CLASS
66306+ select RTC_INTF_DEV
66307+ select RTC_DRV_CMOS
66308+
66309+ help
66310+ If you say Y here, all ioperm and iopl calls will return an error.
66311+ Ioperm and iopl can be used to modify the running kernel.
66312+ Unfortunately, some programs need this access to operate properly,
66313+ the most notable of which are XFree86 and hwclock. hwclock can be
66314+ remedied by having RTC support in the kernel, so real-time
66315+ clock support is enabled if this option is enabled, to ensure
66316+ that hwclock operates correctly. If hwclock still does not work,
66317+ either update udev or symlink /dev/rtc to /dev/rtc0.
66318+
66319+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
66320+ you may not be able to boot into a graphical environment with this
66321+ option enabled. In this case, you should use the RBAC system instead.
66322+
66323+config GRKERNSEC_JIT_HARDEN
66324+ bool "Harden BPF JIT against spray attacks"
66325+ default y if GRKERNSEC_CONFIG_AUTO
66326+ depends on BPF_JIT && X86
66327+ help
66328+ If you say Y here, the native code generated by the kernel's Berkeley
66329+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
66330+ attacks that attempt to fit attacker-beneficial instructions in
66331+ 32bit immediate fields of JIT-generated native instructions. The
66332+ attacker will generally aim to cause an unintended instruction sequence
66333+ of JIT-generated native code to execute by jumping into the middle of
66334+ a generated instruction. This feature effectively randomizes the 32bit
66335+ immediate constants present in the generated code to thwart such attacks.
66336+
66337+ If you're using KERNEXEC, it's recommended that you enable this option
66338+ to supplement the hardening of the kernel.
66339+
66340+config GRKERNSEC_PERF_HARDEN
66341+ bool "Disable unprivileged PERF_EVENTS usage by default"
66342+ default y if GRKERNSEC_CONFIG_AUTO
66343+ depends on PERF_EVENTS
66344+ help
66345+ If you say Y here, the range of acceptable values for the
66346+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
66347+ default to a new value: 3. When the sysctl is set to this value, no
66348+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
66349+
66350+ Though PERF_EVENTS can be used legitimately for performance monitoring
66351+ and low-level application profiling, it is forced on regardless of
66352+ configuration, has been at fault for several vulnerabilities, and
66353+ creates new opportunities for side channels and other information leaks.
66354+
66355+ This feature puts PERF_EVENTS into a secure default state and permits
66356+ the administrator to change out of it temporarily if unprivileged
66357+ application profiling is needed.
66358+
66359+config GRKERNSEC_RAND_THREADSTACK
66360+ bool "Insert random gaps between thread stacks"
66361+ default y if GRKERNSEC_CONFIG_AUTO
66362+ depends on PAX_RANDMMAP && !PPC
66363+ help
66364+ If you say Y here, a random-sized gap will be enforced between allocated
66365+ thread stacks. Glibc's NPTL and other threading libraries that
66366+ pass MAP_STACK to the kernel for thread stack allocation are supported.
66367+ The implementation currently provides 8 bits of entropy for the gap.
66368+
66369+ Many distributions do not compile threaded remote services with the
66370+ -fstack-check argument to GCC, causing the variable-sized stack-based
66371+ allocator, alloca(), to not probe the stack on allocation. This
66372+ permits an unbounded alloca() to skip over any guard page and potentially
66373+ modify another thread's stack reliably. An enforced random gap
66374+ reduces the reliability of such an attack and increases the chance
66375+ that such a read/write to another thread's stack instead lands in
66376+ an unmapped area, causing a crash and triggering grsecurity's
66377+ anti-bruteforcing logic.
66378+
66379+config GRKERNSEC_PROC_MEMMAP
66380+ bool "Harden ASLR against information leaks and entropy reduction"
66381+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66382+ depends on PAX_NOEXEC || PAX_ASLR
66383+ help
66384+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66385+ give no information about the addresses of its mappings if
66386+ PaX features that rely on random addresses are enabled on the task.
66387+ In addition to sanitizing this information and disabling other
66388+ dangerous sources of information, this option causes reads of sensitive
66389+ /proc/<pid> entries where the file descriptor was opened in a different
66390+ task than the one performing the read. Such attempts are logged.
66391+ This option also limits argv/env strings for suid/sgid binaries
66392+ to 512KB to prevent a complete exhaustion of the stack entropy provided
66393+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66394+ binaries to prevent alternative mmap layouts from being abused.
66395+
66396+ If you use PaX it is essential that you say Y here as it closes up
66397+ several holes that make full ASLR useless locally.
66398+
66399+
66400+config GRKERNSEC_KSTACKOVERFLOW
66401+ bool "Prevent kernel stack overflows"
66402+ default y if GRKERNSEC_CONFIG_AUTO
66403+ depends on !IA64 && 64BIT
66404+ help
66405+ If you say Y here, the kernel's process stacks will be allocated
66406+ with vmalloc instead of the kernel's default allocator. This
66407+ introduces guard pages that in combination with the alloca checking
66408+ of the STACKLEAK feature prevents all forms of kernel process stack
66409+ overflow abuse. Note that this is different from kernel stack
66410+ buffer overflows.
66411+
66412+config GRKERNSEC_BRUTE
66413+ bool "Deter exploit bruteforcing"
66414+ default y if GRKERNSEC_CONFIG_AUTO
66415+ help
66416+ If you say Y here, attempts to bruteforce exploits against forking
66417+ daemons such as apache or sshd, as well as against suid/sgid binaries
66418+ will be deterred. When a child of a forking daemon is killed by PaX
66419+ or crashes due to an illegal instruction or other suspicious signal,
66420+ the parent process will be delayed 30 seconds upon every subsequent
66421+ fork until the administrator is able to assess the situation and
66422+ restart the daemon.
66423+ In the suid/sgid case, the attempt is logged, the user has all their
66424+ existing instances of the suid/sgid binary terminated and will
66425+ be unable to execute any suid/sgid binaries for 15 minutes.
66426+
66427+ It is recommended that you also enable signal logging in the auditing
66428+ section so that logs are generated when a process triggers a suspicious
66429+ signal.
66430+ If the sysctl option is enabled, a sysctl option with name
66431+ "deter_bruteforce" is created.
66432+
66433+config GRKERNSEC_MODHARDEN
66434+ bool "Harden module auto-loading"
66435+ default y if GRKERNSEC_CONFIG_AUTO
66436+ depends on MODULES
66437+ help
66438+ If you say Y here, module auto-loading in response to use of some
66439+ feature implemented by an unloaded module will be restricted to
66440+ root users. Enabling this option helps defend against attacks
66441+ by unprivileged users who abuse the auto-loading behavior to
66442+ cause a vulnerable module to load that is then exploited.
66443+
66444+ If this option prevents a legitimate use of auto-loading for a
66445+ non-root user, the administrator can execute modprobe manually
66446+ with the exact name of the module mentioned in the alert log.
66447+ Alternatively, the administrator can add the module to the list
66448+ of modules loaded at boot by modifying init scripts.
66449+
66450+ Modification of init scripts will most likely be needed on
66451+ Ubuntu servers with encrypted home directory support enabled,
66452+ as the first non-root user logging in will cause the ecb(aes),
66453+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66454+
66455+config GRKERNSEC_HIDESYM
66456+ bool "Hide kernel symbols"
66457+ default y if GRKERNSEC_CONFIG_AUTO
66458+ select PAX_USERCOPY_SLABS
66459+ help
66460+ If you say Y here, getting information on loaded modules, and
66461+ displaying all kernel symbols through a syscall will be restricted
66462+ to users with CAP_SYS_MODULE. For software compatibility reasons,
66463+ /proc/kallsyms will be restricted to the root user. The RBAC
66464+ system can hide that entry even from root.
66465+
66466+ This option also prevents leaking of kernel addresses through
66467+ several /proc entries.
66468+
66469+ Note that this option is only effective provided the following
66470+ conditions are met:
66471+ 1) The kernel using grsecurity is not precompiled by some distribution
66472+ 2) You have also enabled GRKERNSEC_DMESG
66473+ 3) You are using the RBAC system and hiding other files such as your
66474+ kernel image and System.map. Alternatively, enabling this option
66475+ causes the permissions on /boot, /lib/modules, and the kernel
66476+ source directory to change at compile time to prevent
66477+ reading by non-root users.
66478+ If the above conditions are met, this option will aid in providing a
66479+ useful protection against local kernel exploitation of overflows
66480+ and arbitrary read/write vulnerabilities.
66481+
66482+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66483+ in addition to this feature.
66484+
66485+config GRKERNSEC_RANDSTRUCT
66486+ bool "Randomize layout of sensitive kernel structures"
66487+ default y if GRKERNSEC_CONFIG_AUTO
66488+ select GRKERNSEC_HIDESYM
66489+ select MODVERSIONS if MODULES
66490+ help
66491+ If you say Y here, the layouts of a number of sensitive kernel
66492+ structures (task, fs, cred, etc) and all structures composed entirely
66493+ of function pointers (aka "ops" structs) will be randomized at compile-time.
66494+ This can introduce the requirement of an additional infoleak
66495+ vulnerability for exploits targeting these structure types.
66496+
66497+ Enabling this feature will introduce some performance impact, slightly
66498+ increase memory usage, and prevent the use of forensic tools like
66499+ Volatility against the system (unless the kernel source tree isn't
66500+ cleaned after kernel installation).
66501+
66502+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66503+ It remains after a make clean to allow for external modules to be compiled
66504+ with the existing seed and will be removed by a make mrproper or
66505+ make distclean.
66506+
66507+ Note that the implementation requires gcc 4.6.4. or newer. You may need
66508+ to install the supporting headers explicitly in addition to the normal
66509+ gcc package.
66510+
66511+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66512+ bool "Use cacheline-aware structure randomization"
66513+ depends on GRKERNSEC_RANDSTRUCT
66514+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66515+ help
66516+ If you say Y here, the RANDSTRUCT randomization will make a best effort
66517+ at restricting randomization to cacheline-sized groups of elements. It
66518+ will further not randomize bitfields in structures. This reduces the
66519+ performance hit of RANDSTRUCT at the cost of weakened randomization.
66520+
66521+config GRKERNSEC_KERN_LOCKOUT
66522+ bool "Active kernel exploit response"
66523+ default y if GRKERNSEC_CONFIG_AUTO
66524+ depends on X86 || ARM || PPC || SPARC
66525+ help
66526+ If you say Y here, when a PaX alert is triggered due to suspicious
66527+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66528+ or an OOPS occurs due to bad memory accesses, instead of just
66529+ terminating the offending process (and potentially allowing
66530+ a subsequent exploit from the same user), we will take one of two
66531+ actions:
66532+ If the user was root, we will panic the system
66533+ If the user was non-root, we will log the attempt, terminate
66534+ all processes owned by the user, then prevent them from creating
66535+ any new processes until the system is restarted
66536+ This deters repeated kernel exploitation/bruteforcing attempts
66537+ and is useful for later forensics.
66538+
66539+config GRKERNSEC_OLD_ARM_USERLAND
66540+ bool "Old ARM userland compatibility"
66541+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66542+ help
66543+ If you say Y here, stubs of executable code to perform such operations
66544+ as "compare-exchange" will be placed at fixed locations in the ARM vector
66545+ table. This is unfortunately needed for old ARM userland meant to run
66546+ across a wide range of processors. Without this option enabled,
66547+ the get_tls and data memory barrier stubs will be emulated by the kernel,
66548+ which is enough for Linaro userlands or other userlands designed for v6
66549+ and newer ARM CPUs. It's recommended that you try without this option enabled
66550+ first, and only enable it if your userland does not boot (it will likely fail
66551+ at init time).
66552+
66553+endmenu
66554+menu "Role Based Access Control Options"
66555+depends on GRKERNSEC
66556+
66557+config GRKERNSEC_RBAC_DEBUG
66558+ bool
66559+
66560+config GRKERNSEC_NO_RBAC
66561+ bool "Disable RBAC system"
66562+ help
66563+ If you say Y here, the /dev/grsec device will be removed from the kernel,
66564+ preventing the RBAC system from being enabled. You should only say Y
66565+ here if you have no intention of using the RBAC system, so as to prevent
66566+ an attacker with root access from misusing the RBAC system to hide files
66567+ and processes when loadable module support and /dev/[k]mem have been
66568+ locked down.
66569+
66570+config GRKERNSEC_ACL_HIDEKERN
66571+ bool "Hide kernel processes"
66572+ help
66573+ If you say Y here, all kernel threads will be hidden to all
66574+ processes but those whose subject has the "view hidden processes"
66575+ flag.
66576+
66577+config GRKERNSEC_ACL_MAXTRIES
66578+ int "Maximum tries before password lockout"
66579+ default 3
66580+ help
66581+ This option enforces the maximum number of times a user can attempt
66582+ to authorize themselves with the grsecurity RBAC system before being
66583+ denied the ability to attempt authorization again for a specified time.
66584+ The lower the number, the harder it will be to brute-force a password.
66585+
66586+config GRKERNSEC_ACL_TIMEOUT
66587+ int "Time to wait after max password tries, in seconds"
66588+ default 30
66589+ help
66590+ This option specifies the time the user must wait after attempting to
66591+ authorize to the RBAC system with the maximum number of invalid
66592+ passwords. The higher the number, the harder it will be to brute-force
66593+ a password.
66594+
66595+endmenu
66596+menu "Filesystem Protections"
66597+depends on GRKERNSEC
66598+
66599+config GRKERNSEC_PROC
66600+ bool "Proc restrictions"
66601+ default y if GRKERNSEC_CONFIG_AUTO
66602+ help
66603+ If you say Y here, the permissions of the /proc filesystem
66604+ will be altered to enhance system security and privacy. You MUST
66605+ choose either a user only restriction or a user and group restriction.
66606+ Depending upon the option you choose, you can either restrict users to
66607+ see only the processes they themselves run, or choose a group that can
66608+ view all processes and files normally restricted to root if you choose
66609+ the "restrict to user only" option. NOTE: If you're running identd or
66610+ ntpd as a non-root user, you will have to run it as the group you
66611+ specify here.
66612+
66613+config GRKERNSEC_PROC_USER
66614+ bool "Restrict /proc to user only"
66615+ depends on GRKERNSEC_PROC
66616+ help
66617+ If you say Y here, non-root users will only be able to view their own
66618+ processes, and restricts them from viewing network-related information,
66619+ and viewing kernel symbol and module information.
66620+
66621+config GRKERNSEC_PROC_USERGROUP
66622+ bool "Allow special group"
66623+ default y if GRKERNSEC_CONFIG_AUTO
66624+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66625+ help
66626+ If you say Y here, you will be able to select a group that will be
66627+ able to view all processes and network-related information. If you've
66628+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66629+ remain hidden. This option is useful if you want to run identd as
66630+ a non-root user. The group you select may also be chosen at boot time
66631+ via "grsec_proc_gid=" on the kernel commandline.
66632+
66633+config GRKERNSEC_PROC_GID
66634+ int "GID for special group"
66635+ depends on GRKERNSEC_PROC_USERGROUP
66636+ default 1001
66637+
66638+config GRKERNSEC_PROC_ADD
66639+ bool "Additional restrictions"
66640+ default y if GRKERNSEC_CONFIG_AUTO
66641+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66642+ help
66643+ If you say Y here, additional restrictions will be placed on
66644+ /proc that keep normal users from viewing device information and
66645+ slabinfo information that could be useful for exploits.
66646+
66647+config GRKERNSEC_LINK
66648+ bool "Linking restrictions"
66649+ default y if GRKERNSEC_CONFIG_AUTO
66650+ help
66651+ If you say Y here, /tmp race exploits will be prevented, since users
66652+ will no longer be able to follow symlinks owned by other users in
66653+ world-writable +t directories (e.g. /tmp), unless the owner of the
66654+ symlink is the owner of the directory. users will also not be
66655+ able to hardlink to files they do not own. If the sysctl option is
66656+ enabled, a sysctl option with name "linking_restrictions" is created.
66657+
66658+config GRKERNSEC_SYMLINKOWN
66659+ bool "Kernel-enforced SymlinksIfOwnerMatch"
66660+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66661+ help
66662+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
66663+ that prevents it from being used as a security feature. As Apache
66664+ verifies the symlink by performing a stat() against the target of
66665+ the symlink before it is followed, an attacker can setup a symlink
66666+ to point to a same-owned file, then replace the symlink with one
66667+ that targets another user's file just after Apache "validates" the
66668+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
66669+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66670+ will be in place for the group you specify. If the sysctl option
66671+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
66672+ created.
66673+
66674+config GRKERNSEC_SYMLINKOWN_GID
66675+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66676+ depends on GRKERNSEC_SYMLINKOWN
66677+ default 1006
66678+ help
66679+ Setting this GID determines what group kernel-enforced
66680+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66681+ is enabled, a sysctl option with name "symlinkown_gid" is created.
66682+
66683+config GRKERNSEC_FIFO
66684+ bool "FIFO restrictions"
66685+ default y if GRKERNSEC_CONFIG_AUTO
66686+ help
66687+ If you say Y here, users will not be able to write to FIFOs they don't
66688+ own in world-writable +t directories (e.g. /tmp), unless the owner of
66689+ the FIFO is the same owner of the directory it's held in. If the sysctl
66690+ option is enabled, a sysctl option with name "fifo_restrictions" is
66691+ created.
66692+
66693+config GRKERNSEC_SYSFS_RESTRICT
66694+ bool "Sysfs/debugfs restriction"
66695+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66696+ depends on SYSFS
66697+ help
66698+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66699+ any filesystem normally mounted under it (e.g. debugfs) will be
66700+ mostly accessible only by root. These filesystems generally provide access
66701+ to hardware and debug information that isn't appropriate for unprivileged
66702+ users of the system. Sysfs and debugfs have also become a large source
66703+ of new vulnerabilities, ranging from infoleaks to local compromise.
66704+ There has been very little oversight with an eye toward security involved
66705+ in adding new exporters of information to these filesystems, so their
66706+ use is discouraged.
66707+ For reasons of compatibility, a few directories have been whitelisted
66708+ for access by non-root users:
66709+ /sys/fs/selinux
66710+ /sys/fs/fuse
66711+ /sys/devices/system/cpu
66712+
66713+config GRKERNSEC_ROFS
66714+ bool "Runtime read-only mount protection"
66715+ depends on SYSCTL
66716+ help
66717+ If you say Y here, a sysctl option with name "romount_protect" will
66718+ be created. By setting this option to 1 at runtime, filesystems
66719+ will be protected in the following ways:
66720+ * No new writable mounts will be allowed
66721+ * Existing read-only mounts won't be able to be remounted read/write
66722+ * Write operations will be denied on all block devices
66723+ This option acts independently of grsec_lock: once it is set to 1,
66724+ it cannot be turned off. Therefore, please be mindful of the resulting
66725+ behavior if this option is enabled in an init script on a read-only
66726+ filesystem.
66727+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66728+ and GRKERNSEC_IO should be enabled and module loading disabled via
66729+ config or at runtime.
66730+ This feature is mainly intended for secure embedded systems.
66731+
66732+
66733+config GRKERNSEC_DEVICE_SIDECHANNEL
66734+ bool "Eliminate stat/notify-based device sidechannels"
66735+ default y if GRKERNSEC_CONFIG_AUTO
66736+ help
66737+ If you say Y here, timing analyses on block or character
66738+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66739+ will be thwarted for unprivileged users. If a process without
66740+ CAP_MKNOD stats such a device, the last access and last modify times
66741+ will match the device's create time. No access or modify events
66742+ will be triggered through inotify/dnotify/fanotify for such devices.
66743+ This feature will prevent attacks that may at a minimum
66744+ allow an attacker to determine the administrator's password length.
66745+
66746+config GRKERNSEC_CHROOT
66747+ bool "Chroot jail restrictions"
66748+ default y if GRKERNSEC_CONFIG_AUTO
66749+ help
66750+ If you say Y here, you will be able to choose several options that will
66751+ make breaking out of a chrooted jail much more difficult. If you
66752+ encounter no software incompatibilities with the following options, it
66753+ is recommended that you enable each one.
66754+
66755+ Note that the chroot restrictions are not intended to apply to "chroots"
66756+ to directories that are simple bind mounts of the global root filesystem.
66757+ For several other reasons, a user shouldn't expect any significant
66758+ security by performing such a chroot.
66759+
66760+config GRKERNSEC_CHROOT_MOUNT
66761+ bool "Deny mounts"
66762+ default y if GRKERNSEC_CONFIG_AUTO
66763+ depends on GRKERNSEC_CHROOT
66764+ help
66765+ If you say Y here, processes inside a chroot will not be able to
66766+ mount or remount filesystems. If the sysctl option is enabled, a
66767+ sysctl option with name "chroot_deny_mount" is created.
66768+
66769+config GRKERNSEC_CHROOT_DOUBLE
66770+ bool "Deny double-chroots"
66771+ default y if GRKERNSEC_CONFIG_AUTO
66772+ depends on GRKERNSEC_CHROOT
66773+ help
66774+ If you say Y here, processes inside a chroot will not be able to chroot
66775+ again outside the chroot. This is a widely used method of breaking
66776+ out of a chroot jail and should not be allowed. If the sysctl
66777+ option is enabled, a sysctl option with name
66778+ "chroot_deny_chroot" is created.
66779+
66780+config GRKERNSEC_CHROOT_PIVOT
66781+ bool "Deny pivot_root in chroot"
66782+ default y if GRKERNSEC_CONFIG_AUTO
66783+ depends on GRKERNSEC_CHROOT
66784+ help
66785+ If you say Y here, processes inside a chroot will not be able to use
66786+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66787+ works similar to chroot in that it changes the root filesystem. This
66788+ function could be misused in a chrooted process to attempt to break out
66789+ of the chroot, and therefore should not be allowed. If the sysctl
66790+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66791+ created.
66792+
66793+config GRKERNSEC_CHROOT_CHDIR
66794+ bool "Enforce chdir(\"/\") on all chroots"
66795+ default y if GRKERNSEC_CONFIG_AUTO
66796+ depends on GRKERNSEC_CHROOT
66797+ help
66798+ If you say Y here, the current working directory of all newly-chrooted
66799+ applications will be set to the the root directory of the chroot.
66800+ The man page on chroot(2) states:
66801+ Note that this call does not change the current working
66802+ directory, so that `.' can be outside the tree rooted at
66803+ `/'. In particular, the super-user can escape from a
66804+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66805+
66806+ It is recommended that you say Y here, since it's not known to break
66807+ any software. If the sysctl option is enabled, a sysctl option with
66808+ name "chroot_enforce_chdir" is created.
66809+
66810+config GRKERNSEC_CHROOT_CHMOD
66811+ bool "Deny (f)chmod +s"
66812+ default y if GRKERNSEC_CONFIG_AUTO
66813+ depends on GRKERNSEC_CHROOT
66814+ help
66815+ If you say Y here, processes inside a chroot will not be able to chmod
66816+ or fchmod files to make them have suid or sgid bits. This protects
66817+ against another published method of breaking a chroot. If the sysctl
66818+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66819+ created.
66820+
66821+config GRKERNSEC_CHROOT_FCHDIR
66822+ bool "Deny fchdir and fhandle out of chroot"
66823+ default y if GRKERNSEC_CONFIG_AUTO
66824+ depends on GRKERNSEC_CHROOT
66825+ help
66826+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66827+ to a file descriptor of the chrooting process that points to a directory
66828+ outside the filesystem will be stopped. Additionally, this option prevents
66829+ use of the recently-created syscall for opening files by a guessable "file
66830+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66831+ with name "chroot_deny_fchdir" is created.
66832+
66833+config GRKERNSEC_CHROOT_MKNOD
66834+ bool "Deny mknod"
66835+ default y if GRKERNSEC_CONFIG_AUTO
66836+ depends on GRKERNSEC_CHROOT
66837+ help
66838+ If you say Y here, processes inside a chroot will not be allowed to
66839+ mknod. The problem with using mknod inside a chroot is that it
66840+ would allow an attacker to create a device entry that is the same
66841+ as one on the physical root of your system, which could range from
66842+ anything from the console device to a device for your harddrive (which
66843+ they could then use to wipe the drive or steal data). It is recommended
66844+ that you say Y here, unless you run into software incompatibilities.
66845+ If the sysctl option is enabled, a sysctl option with name
66846+ "chroot_deny_mknod" is created.
66847+
66848+config GRKERNSEC_CHROOT_SHMAT
66849+ bool "Deny shmat() out of chroot"
66850+ default y if GRKERNSEC_CONFIG_AUTO
66851+ depends on GRKERNSEC_CHROOT
66852+ help
66853+ If you say Y here, processes inside a chroot will not be able to attach
66854+ to shared memory segments that were created outside of the chroot jail.
66855+ It is recommended that you say Y here. If the sysctl option is enabled,
66856+ a sysctl option with name "chroot_deny_shmat" is created.
66857+
66858+config GRKERNSEC_CHROOT_UNIX
66859+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66860+ default y if GRKERNSEC_CONFIG_AUTO
66861+ depends on GRKERNSEC_CHROOT
66862+ help
66863+ If you say Y here, processes inside a chroot will not be able to
66864+ connect to abstract (meaning not belonging to a filesystem) Unix
66865+ domain sockets that were bound outside of a chroot. It is recommended
66866+ that you say Y here. If the sysctl option is enabled, a sysctl option
66867+ with name "chroot_deny_unix" is created.
66868+
66869+config GRKERNSEC_CHROOT_FINDTASK
66870+ bool "Protect outside processes"
66871+ default y if GRKERNSEC_CONFIG_AUTO
66872+ depends on GRKERNSEC_CHROOT
66873+ help
66874+ If you say Y here, processes inside a chroot will not be able to
66875+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66876+ getsid, or view any process outside of the chroot. If the sysctl
66877+ option is enabled, a sysctl option with name "chroot_findtask" is
66878+ created.
66879+
66880+config GRKERNSEC_CHROOT_NICE
66881+ bool "Restrict priority changes"
66882+ default y if GRKERNSEC_CONFIG_AUTO
66883+ depends on GRKERNSEC_CHROOT
66884+ help
66885+ If you say Y here, processes inside a chroot will not be able to raise
66886+ the priority of processes in the chroot, or alter the priority of
66887+ processes outside the chroot. This provides more security than simply
66888+ removing CAP_SYS_NICE from the process' capability set. If the
66889+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66890+ is created.
66891+
66892+config GRKERNSEC_CHROOT_SYSCTL
66893+ bool "Deny sysctl writes"
66894+ default y if GRKERNSEC_CONFIG_AUTO
66895+ depends on GRKERNSEC_CHROOT
66896+ help
66897+ If you say Y here, an attacker in a chroot will not be able to
66898+ write to sysctl entries, either by sysctl(2) or through a /proc
66899+ interface. It is strongly recommended that you say Y here. If the
66900+ sysctl option is enabled, a sysctl option with name
66901+ "chroot_deny_sysctl" is created.
66902+
66903+config GRKERNSEC_CHROOT_CAPS
66904+ bool "Capability restrictions"
66905+ default y if GRKERNSEC_CONFIG_AUTO
66906+ depends on GRKERNSEC_CHROOT
66907+ help
66908+ If you say Y here, the capabilities on all processes within a
66909+ chroot jail will be lowered to stop module insertion, raw i/o,
66910+ system and net admin tasks, rebooting the system, modifying immutable
66911+ files, modifying IPC owned by another, and changing the system time.
66912+ This is left an option because it can break some apps. Disable this
66913+ if your chrooted apps are having problems performing those kinds of
66914+ tasks. If the sysctl option is enabled, a sysctl option with
66915+ name "chroot_caps" is created.
66916+
66917+config GRKERNSEC_CHROOT_INITRD
66918+ bool "Exempt initrd tasks from restrictions"
66919+ default y if GRKERNSEC_CONFIG_AUTO
66920+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66921+ help
66922+ If you say Y here, tasks started prior to init will be exempted from
66923+ grsecurity's chroot restrictions. This option is mainly meant to
66924+ resolve Plymouth's performing privileged operations unnecessarily
66925+ in a chroot.
66926+
66927+endmenu
66928+menu "Kernel Auditing"
66929+depends on GRKERNSEC
66930+
66931+config GRKERNSEC_AUDIT_GROUP
66932+ bool "Single group for auditing"
66933+ help
66934+ If you say Y here, the exec and chdir logging features will only operate
66935+ on a group you specify. This option is recommended if you only want to
66936+ watch certain users instead of having a large amount of logs from the
66937+ entire system. If the sysctl option is enabled, a sysctl option with
66938+ name "audit_group" is created.
66939+
66940+config GRKERNSEC_AUDIT_GID
66941+ int "GID for auditing"
66942+ depends on GRKERNSEC_AUDIT_GROUP
66943+ default 1007
66944+
66945+config GRKERNSEC_EXECLOG
66946+ bool "Exec logging"
66947+ help
66948+ If you say Y here, all execve() calls will be logged (since the
66949+ other exec*() calls are frontends to execve(), all execution
66950+ will be logged). Useful for shell-servers that like to keep track
66951+ of their users. If the sysctl option is enabled, a sysctl option with
66952+ name "exec_logging" is created.
66953+ WARNING: This option when enabled will produce a LOT of logs, especially
66954+ on an active system.
66955+
66956+config GRKERNSEC_RESLOG
66957+ bool "Resource logging"
66958+ default y if GRKERNSEC_CONFIG_AUTO
66959+ help
66960+ If you say Y here, all attempts to overstep resource limits will
66961+ be logged with the resource name, the requested size, and the current
66962+ limit. It is highly recommended that you say Y here. If the sysctl
66963+ option is enabled, a sysctl option with name "resource_logging" is
66964+ created. If the RBAC system is enabled, the sysctl value is ignored.
66965+
66966+config GRKERNSEC_CHROOT_EXECLOG
66967+ bool "Log execs within chroot"
66968+ help
66969+ If you say Y here, all executions inside a chroot jail will be logged
66970+ to syslog. This can cause a large amount of logs if certain
66971+ applications (eg. djb's daemontools) are installed on the system, and
66972+ is therefore left as an option. If the sysctl option is enabled, a
66973+ sysctl option with name "chroot_execlog" is created.
66974+
66975+config GRKERNSEC_AUDIT_PTRACE
66976+ bool "Ptrace logging"
66977+ help
66978+ If you say Y here, all attempts to attach to a process via ptrace
66979+ will be logged. If the sysctl option is enabled, a sysctl option
66980+ with name "audit_ptrace" is created.
66981+
66982+config GRKERNSEC_AUDIT_CHDIR
66983+ bool "Chdir logging"
66984+ help
66985+ If you say Y here, all chdir() calls will be logged. If the sysctl
66986+ option is enabled, a sysctl option with name "audit_chdir" is created.
66987+
66988+config GRKERNSEC_AUDIT_MOUNT
66989+ bool "(Un)Mount logging"
66990+ help
66991+ If you say Y here, all mounts and unmounts will be logged. If the
66992+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66993+ created.
66994+
66995+config GRKERNSEC_SIGNAL
66996+ bool "Signal logging"
66997+ default y if GRKERNSEC_CONFIG_AUTO
66998+ help
66999+ If you say Y here, certain important signals will be logged, such as
67000+ SIGSEGV, which will as a result inform you of when a error in a program
67001+ occurred, which in some cases could mean a possible exploit attempt.
67002+ If the sysctl option is enabled, a sysctl option with name
67003+ "signal_logging" is created.
67004+
67005+config GRKERNSEC_FORKFAIL
67006+ bool "Fork failure logging"
67007+ help
67008+ If you say Y here, all failed fork() attempts will be logged.
67009+ This could suggest a fork bomb, or someone attempting to overstep
67010+ their process limit. If the sysctl option is enabled, a sysctl option
67011+ with name "forkfail_logging" is created.
67012+
67013+config GRKERNSEC_TIME
67014+ bool "Time change logging"
67015+ default y if GRKERNSEC_CONFIG_AUTO
67016+ help
67017+ If you say Y here, any changes of the system clock will be logged.
67018+ If the sysctl option is enabled, a sysctl option with name
67019+ "timechange_logging" is created.
67020+
67021+config GRKERNSEC_PROC_IPADDR
67022+ bool "/proc/<pid>/ipaddr support"
67023+ default y if GRKERNSEC_CONFIG_AUTO
67024+ help
67025+ If you say Y here, a new entry will be added to each /proc/<pid>
67026+ directory that contains the IP address of the person using the task.
67027+ The IP is carried across local TCP and AF_UNIX stream sockets.
67028+ This information can be useful for IDS/IPSes to perform remote response
67029+ to a local attack. The entry is readable by only the owner of the
67030+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
67031+ the RBAC system), and thus does not create privacy concerns.
67032+
67033+config GRKERNSEC_RWXMAP_LOG
67034+ bool 'Denied RWX mmap/mprotect logging'
67035+ default y if GRKERNSEC_CONFIG_AUTO
67036+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
67037+ help
67038+ If you say Y here, calls to mmap() and mprotect() with explicit
67039+ usage of PROT_WRITE and PROT_EXEC together will be logged when
67040+ denied by the PAX_MPROTECT feature. This feature will also
67041+ log other problematic scenarios that can occur when PAX_MPROTECT
67042+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
67043+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
67044+ is created.
67045+
67046+endmenu
67047+
67048+menu "Executable Protections"
67049+depends on GRKERNSEC
67050+
67051+config GRKERNSEC_DMESG
67052+ bool "Dmesg(8) restriction"
67053+ default y if GRKERNSEC_CONFIG_AUTO
67054+ help
67055+ If you say Y here, non-root users will not be able to use dmesg(8)
67056+ to view the contents of the kernel's circular log buffer.
67057+ The kernel's log buffer often contains kernel addresses and other
67058+ identifying information useful to an attacker in fingerprinting a
67059+ system for a targeted exploit.
67060+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
67061+ created.
67062+
67063+config GRKERNSEC_HARDEN_PTRACE
67064+ bool "Deter ptrace-based process snooping"
67065+ default y if GRKERNSEC_CONFIG_AUTO
67066+ help
67067+ If you say Y here, TTY sniffers and other malicious monitoring
67068+ programs implemented through ptrace will be defeated. If you
67069+ have been using the RBAC system, this option has already been
67070+ enabled for several years for all users, with the ability to make
67071+ fine-grained exceptions.
67072+
67073+ This option only affects the ability of non-root users to ptrace
67074+ processes that are not a descendent of the ptracing process.
67075+ This means that strace ./binary and gdb ./binary will still work,
67076+ but attaching to arbitrary processes will not. If the sysctl
67077+ option is enabled, a sysctl option with name "harden_ptrace" is
67078+ created.
67079+
67080+config GRKERNSEC_PTRACE_READEXEC
67081+ bool "Require read access to ptrace sensitive binaries"
67082+ default y if GRKERNSEC_CONFIG_AUTO
67083+ help
67084+ If you say Y here, unprivileged users will not be able to ptrace unreadable
67085+ binaries. This option is useful in environments that
67086+ remove the read bits (e.g. file mode 4711) from suid binaries to
67087+ prevent infoleaking of their contents. This option adds
67088+ consistency to the use of that file mode, as the binary could normally
67089+ be read out when run without privileges while ptracing.
67090+
67091+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
67092+ is created.
67093+
67094+config GRKERNSEC_SETXID
67095+ bool "Enforce consistent multithreaded privileges"
67096+ default y if GRKERNSEC_CONFIG_AUTO
67097+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
67098+ help
67099+ If you say Y here, a change from a root uid to a non-root uid
67100+ in a multithreaded application will cause the resulting uids,
67101+ gids, supplementary groups, and capabilities in that thread
67102+ to be propagated to the other threads of the process. In most
67103+ cases this is unnecessary, as glibc will emulate this behavior
67104+ on behalf of the application. Other libcs do not act in the
67105+ same way, allowing the other threads of the process to continue
67106+ running with root privileges. If the sysctl option is enabled,
67107+ a sysctl option with name "consistent_setxid" is created.
67108+
67109+config GRKERNSEC_HARDEN_IPC
67110+ bool "Disallow access to overly-permissive IPC objects"
67111+ default y if GRKERNSEC_CONFIG_AUTO
67112+ depends on SYSVIPC
67113+ help
67114+ If you say Y here, access to overly-permissive IPC objects (shared
67115+ memory, message queues, and semaphores) will be denied for processes
67116+ given the following criteria beyond normal permission checks:
67117+ 1) If the IPC object is world-accessible and the euid doesn't match
67118+ that of the creator or current uid for the IPC object
67119+ 2) If the IPC object is group-accessible and the egid doesn't
67120+ match that of the creator or current gid for the IPC object
67121+ It's a common error to grant too much permission to these objects,
67122+ with impact ranging from denial of service and information leaking to
67123+ privilege escalation. This feature was developed in response to
67124+ research by Tim Brown:
67125+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
67126+ who found hundreds of such insecure usages. Processes with
67127+ CAP_IPC_OWNER are still permitted to access these IPC objects.
67128+ If the sysctl option is enabled, a sysctl option with name
67129+ "harden_ipc" is created.
67130+
67131+config GRKERNSEC_TPE
67132+ bool "Trusted Path Execution (TPE)"
67133+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
67134+ help
67135+ If you say Y here, you will be able to choose a gid to add to the
67136+ supplementary groups of users you want to mark as "untrusted."
67137+ These users will not be able to execute any files that are not in
67138+ root-owned directories writable only by root. If the sysctl option
67139+ is enabled, a sysctl option with name "tpe" is created.
67140+
67141+config GRKERNSEC_TPE_ALL
67142+ bool "Partially restrict all non-root users"
67143+ depends on GRKERNSEC_TPE
67144+ help
67145+ If you say Y here, all non-root users will be covered under
67146+ a weaker TPE restriction. This is separate from, and in addition to,
67147+ the main TPE options that you have selected elsewhere. Thus, if a
67148+ "trusted" GID is chosen, this restriction applies to even that GID.
67149+ Under this restriction, all non-root users will only be allowed to
67150+ execute files in directories they own that are not group or
67151+ world-writable, or in directories owned by root and writable only by
67152+ root. If the sysctl option is enabled, a sysctl option with name
67153+ "tpe_restrict_all" is created.
67154+
67155+config GRKERNSEC_TPE_INVERT
67156+ bool "Invert GID option"
67157+ depends on GRKERNSEC_TPE
67158+ help
67159+ If you say Y here, the group you specify in the TPE configuration will
67160+ decide what group TPE restrictions will be *disabled* for. This
67161+ option is useful if you want TPE restrictions to be applied to most
67162+ users on the system. If the sysctl option is enabled, a sysctl option
67163+ with name "tpe_invert" is created. Unlike other sysctl options, this
67164+ entry will default to on for backward-compatibility.
67165+
67166+config GRKERNSEC_TPE_GID
67167+ int
67168+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
67169+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
67170+
67171+config GRKERNSEC_TPE_UNTRUSTED_GID
67172+ int "GID for TPE-untrusted users"
67173+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
67174+ default 1005
67175+ help
67176+ Setting this GID determines what group TPE restrictions will be
67177+ *enabled* for. If the sysctl option is enabled, a sysctl option
67178+ with name "tpe_gid" is created.
67179+
67180+config GRKERNSEC_TPE_TRUSTED_GID
67181+ int "GID for TPE-trusted users"
67182+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
67183+ default 1005
67184+ help
67185+ Setting this GID determines what group TPE restrictions will be
67186+ *disabled* for. If the sysctl option is enabled, a sysctl option
67187+ with name "tpe_gid" is created.
67188+
67189+endmenu
67190+menu "Network Protections"
67191+depends on GRKERNSEC
67192+
67193+config GRKERNSEC_BLACKHOLE
67194+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
67195+ default y if GRKERNSEC_CONFIG_AUTO
67196+ depends on NET
67197+ help
67198+ If you say Y here, neither TCP resets nor ICMP
67199+ destination-unreachable packets will be sent in response to packets
67200+ sent to ports for which no associated listening process exists.
67201+ This feature supports both IPV4 and IPV6 and exempts the
67202+ loopback interface from blackholing. Enabling this feature
67203+ makes a host more resilient to DoS attacks and reduces network
67204+ visibility against scanners.
67205+
67206+ The blackhole feature as-implemented is equivalent to the FreeBSD
67207+ blackhole feature, as it prevents RST responses to all packets, not
67208+ just SYNs. Under most application behavior this causes no
67209+ problems, but applications (like haproxy) may not close certain
67210+ connections in a way that cleanly terminates them on the remote
67211+ end, leaving the remote host in LAST_ACK state. Because of this
67212+ side-effect and to prevent intentional LAST_ACK DoSes, this
67213+ feature also adds automatic mitigation against such attacks.
67214+ The mitigation drastically reduces the amount of time a socket
67215+ can spend in LAST_ACK state. If you're using haproxy and not
67216+ all servers it connects to have this option enabled, consider
67217+ disabling this feature on the haproxy host.
67218+
67219+ If the sysctl option is enabled, two sysctl options with names
67220+ "ip_blackhole" and "lastack_retries" will be created.
67221+ While "ip_blackhole" takes the standard zero/non-zero on/off
67222+ toggle, "lastack_retries" uses the same kinds of values as
67223+ "tcp_retries1" and "tcp_retries2". The default value of 4
67224+ prevents a socket from lasting more than 45 seconds in LAST_ACK
67225+ state.
67226+
67227+config GRKERNSEC_NO_SIMULT_CONNECT
67228+ bool "Disable TCP Simultaneous Connect"
67229+ default y if GRKERNSEC_CONFIG_AUTO
67230+ depends on NET
67231+ help
67232+ If you say Y here, a feature by Willy Tarreau will be enabled that
67233+ removes a weakness in Linux's strict implementation of TCP that
67234+ allows two clients to connect to each other without either entering
67235+ a listening state. The weakness allows an attacker to easily prevent
67236+ a client from connecting to a known server provided the source port
67237+ for the connection is guessed correctly.
67238+
67239+ As the weakness could be used to prevent an antivirus or IPS from
67240+ fetching updates, or prevent an SSL gateway from fetching a CRL,
67241+ it should be eliminated by enabling this option. Though Linux is
67242+ one of few operating systems supporting simultaneous connect, it
67243+ has no legitimate use in practice and is rarely supported by firewalls.
67244+
67245+config GRKERNSEC_SOCKET
67246+ bool "Socket restrictions"
67247+ depends on NET
67248+ help
67249+ If you say Y here, you will be able to choose from several options.
67250+ If you assign a GID on your system and add it to the supplementary
67251+ groups of users you want to restrict socket access to, this patch
67252+ will perform up to three things, based on the option(s) you choose.
67253+
67254+config GRKERNSEC_SOCKET_ALL
67255+ bool "Deny any sockets to group"
67256+ depends on GRKERNSEC_SOCKET
67257+ help
67258+ If you say Y here, you will be able to choose a GID of whose users will
67259+ be unable to connect to other hosts from your machine or run server
67260+ applications from your machine. If the sysctl option is enabled, a
67261+ sysctl option with name "socket_all" is created.
67262+
67263+config GRKERNSEC_SOCKET_ALL_GID
67264+ int "GID to deny all sockets for"
67265+ depends on GRKERNSEC_SOCKET_ALL
67266+ default 1004
67267+ help
67268+ Here you can choose the GID to disable socket access for. Remember to
67269+ add the users you want socket access disabled for to the GID
67270+ specified here. If the sysctl option is enabled, a sysctl option
67271+ with name "socket_all_gid" is created.
67272+
67273+config GRKERNSEC_SOCKET_CLIENT
67274+ bool "Deny client sockets to group"
67275+ depends on GRKERNSEC_SOCKET
67276+ help
67277+ If you say Y here, you will be able to choose a GID of whose users will
67278+ be unable to connect to other hosts from your machine, but will be
67279+ able to run servers. If this option is enabled, all users in the group
67280+ you specify will have to use passive mode when initiating ftp transfers
67281+ from the shell on your machine. If the sysctl option is enabled, a
67282+ sysctl option with name "socket_client" is created.
67283+
67284+config GRKERNSEC_SOCKET_CLIENT_GID
67285+ int "GID to deny client sockets for"
67286+ depends on GRKERNSEC_SOCKET_CLIENT
67287+ default 1003
67288+ help
67289+ Here you can choose the GID to disable client socket access for.
67290+ Remember to add the users you want client socket access disabled for to
67291+ the GID specified here. If the sysctl option is enabled, a sysctl
67292+ option with name "socket_client_gid" is created.
67293+
67294+config GRKERNSEC_SOCKET_SERVER
67295+ bool "Deny server sockets to group"
67296+ depends on GRKERNSEC_SOCKET
67297+ help
67298+ If you say Y here, you will be able to choose a GID of whose users will
67299+ be unable to run server applications from your machine. If the sysctl
67300+ option is enabled, a sysctl option with name "socket_server" is created.
67301+
67302+config GRKERNSEC_SOCKET_SERVER_GID
67303+ int "GID to deny server sockets for"
67304+ depends on GRKERNSEC_SOCKET_SERVER
67305+ default 1002
67306+ help
67307+ Here you can choose the GID to disable server socket access for.
67308+ Remember to add the users you want server socket access disabled for to
67309+ the GID specified here. If the sysctl option is enabled, a sysctl
67310+ option with name "socket_server_gid" is created.
67311+
67312+endmenu
67313+
67314+menu "Physical Protections"
67315+depends on GRKERNSEC
67316+
67317+config GRKERNSEC_DENYUSB
67318+ bool "Deny new USB connections after toggle"
67319+ default y if GRKERNSEC_CONFIG_AUTO
67320+ depends on SYSCTL && USB_SUPPORT
67321+ help
67322+ If you say Y here, a new sysctl option with name "deny_new_usb"
67323+ will be created. Setting its value to 1 will prevent any new
67324+ USB devices from being recognized by the OS. Any attempted USB
67325+ device insertion will be logged. This option is intended to be
67326+ used against custom USB devices designed to exploit vulnerabilities
67327+ in various USB device drivers.
67328+
67329+ For greatest effectiveness, this sysctl should be set after any
67330+ relevant init scripts. This option is safe to enable in distros
67331+ as each user can choose whether or not to toggle the sysctl.
67332+
67333+config GRKERNSEC_DENYUSB_FORCE
67334+ bool "Reject all USB devices not connected at boot"
67335+ select USB
67336+ depends on GRKERNSEC_DENYUSB
67337+ help
67338+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
67339+ that doesn't involve a sysctl entry. This option should only be
67340+ enabled if you're sure you want to deny all new USB connections
67341+ at runtime and don't want to modify init scripts. This should not
67342+ be enabled by distros. It forces the core USB code to be built
67343+ into the kernel image so that all devices connected at boot time
67344+ can be recognized and new USB device connections can be prevented
67345+ prior to init running.
67346+
67347+endmenu
67348+
67349+menu "Sysctl Support"
67350+depends on GRKERNSEC && SYSCTL
67351+
67352+config GRKERNSEC_SYSCTL
67353+ bool "Sysctl support"
67354+ default y if GRKERNSEC_CONFIG_AUTO
67355+ help
67356+ If you say Y here, you will be able to change the options that
67357+ grsecurity runs with at bootup, without having to recompile your
67358+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
67359+ to enable (1) or disable (0) various features. All the sysctl entries
67360+ are mutable until the "grsec_lock" entry is set to a non-zero value.
67361+ All features enabled in the kernel configuration are disabled at boot
67362+ if you do not say Y to the "Turn on features by default" option.
67363+ All options should be set at startup, and the grsec_lock entry should
67364+ be set to a non-zero value after all the options are set.
67365+ *THIS IS EXTREMELY IMPORTANT*
67366+
67367+config GRKERNSEC_SYSCTL_DISTRO
67368+ bool "Extra sysctl support for distro makers (READ HELP)"
67369+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
67370+ help
67371+ If you say Y here, additional sysctl options will be created
67372+ for features that affect processes running as root. Therefore,
67373+ it is critical when using this option that the grsec_lock entry be
67374+ enabled after boot. Only distros with prebuilt kernel packages
67375+ with this option enabled that can ensure grsec_lock is enabled
67376+ after boot should use this option.
67377+ *Failure to set grsec_lock after boot makes all grsec features
67378+ this option covers useless*
67379+
67380+ Currently this option creates the following sysctl entries:
67381+ "Disable Privileged I/O": "disable_priv_io"
67382+
67383+config GRKERNSEC_SYSCTL_ON
67384+ bool "Turn on features by default"
67385+ default y if GRKERNSEC_CONFIG_AUTO
67386+ depends on GRKERNSEC_SYSCTL
67387+ help
67388+ If you say Y here, instead of having all features enabled in the
67389+ kernel configuration disabled at boot time, the features will be
67390+ enabled at boot time. It is recommended you say Y here unless
67391+ there is some reason you would want all sysctl-tunable features to
67392+ be disabled by default. As mentioned elsewhere, it is important
67393+ to enable the grsec_lock entry once you have finished modifying
67394+ the sysctl entries.
67395+
67396+endmenu
67397+menu "Logging Options"
67398+depends on GRKERNSEC
67399+
67400+config GRKERNSEC_FLOODTIME
67401+ int "Seconds in between log messages (minimum)"
67402+ default 10
67403+ help
67404+ This option allows you to enforce the number of seconds between
67405+ grsecurity log messages. The default should be suitable for most
67406+ people, however, if you choose to change it, choose a value small enough
67407+ to allow informative logs to be produced, but large enough to
67408+ prevent flooding.
67409+
67410+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67411+ any rate limiting on grsecurity log messages.
67412+
67413+config GRKERNSEC_FLOODBURST
67414+ int "Number of messages in a burst (maximum)"
67415+ default 6
67416+ help
67417+ This option allows you to choose the maximum number of messages allowed
67418+ within the flood time interval you chose in a separate option. The
67419+ default should be suitable for most people, however if you find that
67420+ many of your logs are being interpreted as flooding, you may want to
67421+ raise this value.
67422+
67423+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67424+ any rate limiting on grsecurity log messages.
67425+
67426+endmenu
67427diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67428new file mode 100644
67429index 0000000..30ababb
67430--- /dev/null
67431+++ b/grsecurity/Makefile
67432@@ -0,0 +1,54 @@
67433+# grsecurity – access control and security hardening for Linux
67434+# All code in this directory and various hooks located throughout the Linux kernel are
67435+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67436+# http://www.grsecurity.net spender@grsecurity.net
67437+#
67438+# This program is free software; you can redistribute it and/or
67439+# modify it under the terms of the GNU General Public License version 2
67440+# as published by the Free Software Foundation.
67441+#
67442+# This program is distributed in the hope that it will be useful,
67443+# but WITHOUT ANY WARRANTY; without even the implied warranty of
67444+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67445+# GNU General Public License for more details.
67446+#
67447+# You should have received a copy of the GNU General Public License
67448+# along with this program; if not, write to the Free Software
67449+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67450+
67451+KBUILD_CFLAGS += -Werror
67452+
67453+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67454+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
67455+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67456+ grsec_usb.o grsec_ipc.o grsec_proc.o
67457+
67458+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67459+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67460+ gracl_learn.o grsec_log.o gracl_policy.o
67461+ifdef CONFIG_COMPAT
67462+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67463+endif
67464+
67465+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67466+
67467+ifdef CONFIG_NET
67468+obj-y += grsec_sock.o
67469+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67470+endif
67471+
67472+ifndef CONFIG_GRKERNSEC
67473+obj-y += grsec_disabled.o
67474+endif
67475+
67476+ifdef CONFIG_GRKERNSEC_HIDESYM
67477+extra-y := grsec_hidesym.o
67478+$(obj)/grsec_hidesym.o:
67479+ @-chmod -f 500 /boot
67480+ @-chmod -f 500 /lib/modules
67481+ @-chmod -f 500 /lib64/modules
67482+ @-chmod -f 500 /lib32/modules
67483+ @-chmod -f 700 .
67484+ @-chmod -f 700 $(objtree)
67485+ @echo ' grsec: protected kernel image paths'
67486+endif
67487diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67488new file mode 100644
67489index 0000000..58223f6
67490--- /dev/null
67491+++ b/grsecurity/gracl.c
67492@@ -0,0 +1,2702 @@
67493+#include <linux/kernel.h>
67494+#include <linux/module.h>
67495+#include <linux/sched.h>
67496+#include <linux/mm.h>
67497+#include <linux/file.h>
67498+#include <linux/fs.h>
67499+#include <linux/namei.h>
67500+#include <linux/mount.h>
67501+#include <linux/tty.h>
67502+#include <linux/proc_fs.h>
67503+#include <linux/lglock.h>
67504+#include <linux/slab.h>
67505+#include <linux/vmalloc.h>
67506+#include <linux/types.h>
67507+#include <linux/sysctl.h>
67508+#include <linux/netdevice.h>
67509+#include <linux/ptrace.h>
67510+#include <linux/gracl.h>
67511+#include <linux/gralloc.h>
67512+#include <linux/security.h>
67513+#include <linux/grinternal.h>
67514+#include <linux/pid_namespace.h>
67515+#include <linux/stop_machine.h>
67516+#include <linux/fdtable.h>
67517+#include <linux/percpu.h>
67518+#include <linux/lglock.h>
67519+#include <linux/hugetlb.h>
67520+#include <linux/posix-timers.h>
67521+#include <linux/prefetch.h>
67522+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67523+#include <linux/magic.h>
67524+#include <linux/pagemap.h>
67525+#include "../fs/btrfs/async-thread.h"
67526+#include "../fs/btrfs/ctree.h"
67527+#include "../fs/btrfs/btrfs_inode.h"
67528+#endif
67529+#include "../fs/mount.h"
67530+
67531+#include <asm/uaccess.h>
67532+#include <asm/errno.h>
67533+#include <asm/mman.h>
67534+
67535+#define FOR_EACH_ROLE_START(role) \
67536+ role = running_polstate.role_list; \
67537+ while (role) {
67538+
67539+#define FOR_EACH_ROLE_END(role) \
67540+ role = role->prev; \
67541+ }
67542+
67543+extern struct path gr_real_root;
67544+
67545+static struct gr_policy_state running_polstate;
67546+struct gr_policy_state *polstate = &running_polstate;
67547+extern struct gr_alloc_state *current_alloc_state;
67548+
67549+extern char *gr_shared_page[4];
67550+DEFINE_RWLOCK(gr_inode_lock);
67551+
67552+static unsigned int gr_status __read_only = GR_STATUS_INIT;
67553+
67554+#ifdef CONFIG_NET
67555+extern struct vfsmount *sock_mnt;
67556+#endif
67557+
67558+extern struct vfsmount *pipe_mnt;
67559+extern struct vfsmount *shm_mnt;
67560+
67561+#ifdef CONFIG_HUGETLBFS
67562+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67563+#endif
67564+
67565+extern u16 acl_sp_role_value;
67566+extern struct acl_object_label *fakefs_obj_rw;
67567+extern struct acl_object_label *fakefs_obj_rwx;
67568+
67569+int gr_acl_is_enabled(void)
67570+{
67571+ return (gr_status & GR_READY);
67572+}
67573+
67574+void gr_enable_rbac_system(void)
67575+{
67576+ pax_open_kernel();
67577+ gr_status |= GR_READY;
67578+ pax_close_kernel();
67579+}
67580+
67581+int gr_rbac_disable(void *unused)
67582+{
67583+ pax_open_kernel();
67584+ gr_status &= ~GR_READY;
67585+ pax_close_kernel();
67586+
67587+ return 0;
67588+}
67589+
67590+static inline dev_t __get_dev(const struct dentry *dentry)
67591+{
67592+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67593+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67594+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67595+ else
67596+#endif
67597+ return dentry->d_sb->s_dev;
67598+}
67599+
67600+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67601+{
67602+ return __get_dev(dentry);
67603+}
67604+
67605+static char gr_task_roletype_to_char(struct task_struct *task)
67606+{
67607+ switch (task->role->roletype &
67608+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67609+ GR_ROLE_SPECIAL)) {
67610+ case GR_ROLE_DEFAULT:
67611+ return 'D';
67612+ case GR_ROLE_USER:
67613+ return 'U';
67614+ case GR_ROLE_GROUP:
67615+ return 'G';
67616+ case GR_ROLE_SPECIAL:
67617+ return 'S';
67618+ }
67619+
67620+ return 'X';
67621+}
67622+
67623+char gr_roletype_to_char(void)
67624+{
67625+ return gr_task_roletype_to_char(current);
67626+}
67627+
67628+__inline__ int
67629+gr_acl_tpe_check(void)
67630+{
67631+ if (unlikely(!(gr_status & GR_READY)))
67632+ return 0;
67633+ if (current->role->roletype & GR_ROLE_TPE)
67634+ return 1;
67635+ else
67636+ return 0;
67637+}
67638+
67639+int
67640+gr_handle_rawio(const struct inode *inode)
67641+{
67642+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67643+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67644+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67645+ !capable(CAP_SYS_RAWIO))
67646+ return 1;
67647+#endif
67648+ return 0;
67649+}
67650+
67651+int
67652+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67653+{
67654+ if (likely(lena != lenb))
67655+ return 0;
67656+
67657+ return !memcmp(a, b, lena);
67658+}
67659+
67660+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67661+{
67662+ *buflen -= namelen;
67663+ if (*buflen < 0)
67664+ return -ENAMETOOLONG;
67665+ *buffer -= namelen;
67666+ memcpy(*buffer, str, namelen);
67667+ return 0;
67668+}
67669+
67670+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67671+{
67672+ return prepend(buffer, buflen, name->name, name->len);
67673+}
67674+
67675+static int prepend_path(const struct path *path, struct path *root,
67676+ char **buffer, int *buflen)
67677+{
67678+ struct dentry *dentry = path->dentry;
67679+ struct vfsmount *vfsmnt = path->mnt;
67680+ struct mount *mnt = real_mount(vfsmnt);
67681+ bool slash = false;
67682+ int error = 0;
67683+
67684+ while (dentry != root->dentry || vfsmnt != root->mnt) {
67685+ struct dentry * parent;
67686+
67687+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67688+ /* Global root? */
67689+ if (!mnt_has_parent(mnt)) {
67690+ goto out;
67691+ }
67692+ dentry = mnt->mnt_mountpoint;
67693+ mnt = mnt->mnt_parent;
67694+ vfsmnt = &mnt->mnt;
67695+ continue;
67696+ }
67697+ parent = dentry->d_parent;
67698+ prefetch(parent);
67699+ spin_lock(&dentry->d_lock);
67700+ error = prepend_name(buffer, buflen, &dentry->d_name);
67701+ spin_unlock(&dentry->d_lock);
67702+ if (!error)
67703+ error = prepend(buffer, buflen, "/", 1);
67704+ if (error)
67705+ break;
67706+
67707+ slash = true;
67708+ dentry = parent;
67709+ }
67710+
67711+out:
67712+ if (!error && !slash)
67713+ error = prepend(buffer, buflen, "/", 1);
67714+
67715+ return error;
67716+}
67717+
67718+/* this must be called with mount_lock and rename_lock held */
67719+
67720+static char *__our_d_path(const struct path *path, struct path *root,
67721+ char *buf, int buflen)
67722+{
67723+ char *res = buf + buflen;
67724+ int error;
67725+
67726+ prepend(&res, &buflen, "\0", 1);
67727+ error = prepend_path(path, root, &res, &buflen);
67728+ if (error)
67729+ return ERR_PTR(error);
67730+
67731+ return res;
67732+}
67733+
67734+static char *
67735+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67736+{
67737+ char *retval;
67738+
67739+ retval = __our_d_path(path, root, buf, buflen);
67740+ if (unlikely(IS_ERR(retval)))
67741+ retval = strcpy(buf, "<path too long>");
67742+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67743+ retval[1] = '\0';
67744+
67745+ return retval;
67746+}
67747+
67748+static char *
67749+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67750+ char *buf, int buflen)
67751+{
67752+ struct path path;
67753+ char *res;
67754+
67755+ path.dentry = (struct dentry *)dentry;
67756+ path.mnt = (struct vfsmount *)vfsmnt;
67757+
67758+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67759+ by the RBAC system */
67760+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67761+
67762+ return res;
67763+}
67764+
67765+static char *
67766+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67767+ char *buf, int buflen)
67768+{
67769+ char *res;
67770+ struct path path;
67771+ struct path root;
67772+ struct task_struct *reaper = init_pid_ns.child_reaper;
67773+
67774+ path.dentry = (struct dentry *)dentry;
67775+ path.mnt = (struct vfsmount *)vfsmnt;
67776+
67777+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67778+ get_fs_root(reaper->fs, &root);
67779+
67780+ read_seqlock_excl(&mount_lock);
67781+ write_seqlock(&rename_lock);
67782+ res = gen_full_path(&path, &root, buf, buflen);
67783+ write_sequnlock(&rename_lock);
67784+ read_sequnlock_excl(&mount_lock);
67785+
67786+ path_put(&root);
67787+ return res;
67788+}
67789+
67790+char *
67791+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67792+{
67793+ char *ret;
67794+ read_seqlock_excl(&mount_lock);
67795+ write_seqlock(&rename_lock);
67796+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67797+ PAGE_SIZE);
67798+ write_sequnlock(&rename_lock);
67799+ read_sequnlock_excl(&mount_lock);
67800+ return ret;
67801+}
67802+
67803+static char *
67804+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67805+{
67806+ char *ret;
67807+ char *buf;
67808+ int buflen;
67809+
67810+ read_seqlock_excl(&mount_lock);
67811+ write_seqlock(&rename_lock);
67812+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67813+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67814+ buflen = (int)(ret - buf);
67815+ if (buflen >= 5)
67816+ prepend(&ret, &buflen, "/proc", 5);
67817+ else
67818+ ret = strcpy(buf, "<path too long>");
67819+ write_sequnlock(&rename_lock);
67820+ read_sequnlock_excl(&mount_lock);
67821+ return ret;
67822+}
67823+
67824+char *
67825+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67826+{
67827+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67828+ PAGE_SIZE);
67829+}
67830+
67831+char *
67832+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67833+{
67834+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67835+ PAGE_SIZE);
67836+}
67837+
67838+char *
67839+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67840+{
67841+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67842+ PAGE_SIZE);
67843+}
67844+
67845+char *
67846+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67847+{
67848+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67849+ PAGE_SIZE);
67850+}
67851+
67852+char *
67853+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67854+{
67855+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67856+ PAGE_SIZE);
67857+}
67858+
67859+__inline__ __u32
67860+to_gr_audit(const __u32 reqmode)
67861+{
67862+ /* masks off auditable permission flags, then shifts them to create
67863+ auditing flags, and adds the special case of append auditing if
67864+ we're requesting write */
67865+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67866+}
67867+
67868+struct acl_role_label *
67869+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67870+ const gid_t gid)
67871+{
67872+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67873+ struct acl_role_label *match;
67874+ struct role_allowed_ip *ipp;
67875+ unsigned int x;
67876+ u32 curr_ip = task->signal->saved_ip;
67877+
67878+ match = state->acl_role_set.r_hash[index];
67879+
67880+ while (match) {
67881+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67882+ for (x = 0; x < match->domain_child_num; x++) {
67883+ if (match->domain_children[x] == uid)
67884+ goto found;
67885+ }
67886+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67887+ break;
67888+ match = match->next;
67889+ }
67890+found:
67891+ if (match == NULL) {
67892+ try_group:
67893+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67894+ match = state->acl_role_set.r_hash[index];
67895+
67896+ while (match) {
67897+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67898+ for (x = 0; x < match->domain_child_num; x++) {
67899+ if (match->domain_children[x] == gid)
67900+ goto found2;
67901+ }
67902+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67903+ break;
67904+ match = match->next;
67905+ }
67906+found2:
67907+ if (match == NULL)
67908+ match = state->default_role;
67909+ if (match->allowed_ips == NULL)
67910+ return match;
67911+ else {
67912+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67913+ if (likely
67914+ ((ntohl(curr_ip) & ipp->netmask) ==
67915+ (ntohl(ipp->addr) & ipp->netmask)))
67916+ return match;
67917+ }
67918+ match = state->default_role;
67919+ }
67920+ } else if (match->allowed_ips == NULL) {
67921+ return match;
67922+ } else {
67923+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67924+ if (likely
67925+ ((ntohl(curr_ip) & ipp->netmask) ==
67926+ (ntohl(ipp->addr) & ipp->netmask)))
67927+ return match;
67928+ }
67929+ goto try_group;
67930+ }
67931+
67932+ return match;
67933+}
67934+
67935+static struct acl_role_label *
67936+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67937+ const gid_t gid)
67938+{
67939+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67940+}
67941+
67942+struct acl_subject_label *
67943+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67944+ const struct acl_role_label *role)
67945+{
67946+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67947+ struct acl_subject_label *match;
67948+
67949+ match = role->subj_hash[index];
67950+
67951+ while (match && (match->inode != ino || match->device != dev ||
67952+ (match->mode & GR_DELETED))) {
67953+ match = match->next;
67954+ }
67955+
67956+ if (match && !(match->mode & GR_DELETED))
67957+ return match;
67958+ else
67959+ return NULL;
67960+}
67961+
67962+struct acl_subject_label *
67963+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67964+ const struct acl_role_label *role)
67965+{
67966+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67967+ struct acl_subject_label *match;
67968+
67969+ match = role->subj_hash[index];
67970+
67971+ while (match && (match->inode != ino || match->device != dev ||
67972+ !(match->mode & GR_DELETED))) {
67973+ match = match->next;
67974+ }
67975+
67976+ if (match && (match->mode & GR_DELETED))
67977+ return match;
67978+ else
67979+ return NULL;
67980+}
67981+
67982+static struct acl_object_label *
67983+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67984+ const struct acl_subject_label *subj)
67985+{
67986+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67987+ struct acl_object_label *match;
67988+
67989+ match = subj->obj_hash[index];
67990+
67991+ while (match && (match->inode != ino || match->device != dev ||
67992+ (match->mode & GR_DELETED))) {
67993+ match = match->next;
67994+ }
67995+
67996+ if (match && !(match->mode & GR_DELETED))
67997+ return match;
67998+ else
67999+ return NULL;
68000+}
68001+
68002+static struct acl_object_label *
68003+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
68004+ const struct acl_subject_label *subj)
68005+{
68006+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
68007+ struct acl_object_label *match;
68008+
68009+ match = subj->obj_hash[index];
68010+
68011+ while (match && (match->inode != ino || match->device != dev ||
68012+ !(match->mode & GR_DELETED))) {
68013+ match = match->next;
68014+ }
68015+
68016+ if (match && (match->mode & GR_DELETED))
68017+ return match;
68018+
68019+ match = subj->obj_hash[index];
68020+
68021+ while (match && (match->inode != ino || match->device != dev ||
68022+ (match->mode & GR_DELETED))) {
68023+ match = match->next;
68024+ }
68025+
68026+ if (match && !(match->mode & GR_DELETED))
68027+ return match;
68028+ else
68029+ return NULL;
68030+}
68031+
68032+struct name_entry *
68033+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
68034+{
68035+ unsigned int len = strlen(name);
68036+ unsigned int key = full_name_hash(name, len);
68037+ unsigned int index = key % state->name_set.n_size;
68038+ struct name_entry *match;
68039+
68040+ match = state->name_set.n_hash[index];
68041+
68042+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
68043+ match = match->next;
68044+
68045+ return match;
68046+}
68047+
68048+static struct name_entry *
68049+lookup_name_entry(const char *name)
68050+{
68051+ return __lookup_name_entry(&running_polstate, name);
68052+}
68053+
68054+static struct name_entry *
68055+lookup_name_entry_create(const char *name)
68056+{
68057+ unsigned int len = strlen(name);
68058+ unsigned int key = full_name_hash(name, len);
68059+ unsigned int index = key % running_polstate.name_set.n_size;
68060+ struct name_entry *match;
68061+
68062+ match = running_polstate.name_set.n_hash[index];
68063+
68064+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
68065+ !match->deleted))
68066+ match = match->next;
68067+
68068+ if (match && match->deleted)
68069+ return match;
68070+
68071+ match = running_polstate.name_set.n_hash[index];
68072+
68073+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
68074+ match->deleted))
68075+ match = match->next;
68076+
68077+ if (match && !match->deleted)
68078+ return match;
68079+ else
68080+ return NULL;
68081+}
68082+
68083+static struct inodev_entry *
68084+lookup_inodev_entry(const ino_t ino, const dev_t dev)
68085+{
68086+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
68087+ struct inodev_entry *match;
68088+
68089+ match = running_polstate.inodev_set.i_hash[index];
68090+
68091+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
68092+ match = match->next;
68093+
68094+ return match;
68095+}
68096+
68097+void
68098+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
68099+{
68100+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
68101+ state->inodev_set.i_size);
68102+ struct inodev_entry **curr;
68103+
68104+ entry->prev = NULL;
68105+
68106+ curr = &state->inodev_set.i_hash[index];
68107+ if (*curr != NULL)
68108+ (*curr)->prev = entry;
68109+
68110+ entry->next = *curr;
68111+ *curr = entry;
68112+
68113+ return;
68114+}
68115+
68116+static void
68117+insert_inodev_entry(struct inodev_entry *entry)
68118+{
68119+ __insert_inodev_entry(&running_polstate, entry);
68120+}
68121+
68122+void
68123+insert_acl_obj_label(struct acl_object_label *obj,
68124+ struct acl_subject_label *subj)
68125+{
68126+ unsigned int index =
68127+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
68128+ struct acl_object_label **curr;
68129+
68130+ obj->prev = NULL;
68131+
68132+ curr = &subj->obj_hash[index];
68133+ if (*curr != NULL)
68134+ (*curr)->prev = obj;
68135+
68136+ obj->next = *curr;
68137+ *curr = obj;
68138+
68139+ return;
68140+}
68141+
68142+void
68143+insert_acl_subj_label(struct acl_subject_label *obj,
68144+ struct acl_role_label *role)
68145+{
68146+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
68147+ struct acl_subject_label **curr;
68148+
68149+ obj->prev = NULL;
68150+
68151+ curr = &role->subj_hash[index];
68152+ if (*curr != NULL)
68153+ (*curr)->prev = obj;
68154+
68155+ obj->next = *curr;
68156+ *curr = obj;
68157+
68158+ return;
68159+}
68160+
68161+/* derived from glibc fnmatch() 0: match, 1: no match*/
68162+
68163+static int
68164+glob_match(const char *p, const char *n)
68165+{
68166+ char c;
68167+
68168+ while ((c = *p++) != '\0') {
68169+ switch (c) {
68170+ case '?':
68171+ if (*n == '\0')
68172+ return 1;
68173+ else if (*n == '/')
68174+ return 1;
68175+ break;
68176+ case '\\':
68177+ if (*n != c)
68178+ return 1;
68179+ break;
68180+ case '*':
68181+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
68182+ if (*n == '/')
68183+ return 1;
68184+ else if (c == '?') {
68185+ if (*n == '\0')
68186+ return 1;
68187+ else
68188+ ++n;
68189+ }
68190+ }
68191+ if (c == '\0') {
68192+ return 0;
68193+ } else {
68194+ const char *endp;
68195+
68196+ if ((endp = strchr(n, '/')) == NULL)
68197+ endp = n + strlen(n);
68198+
68199+ if (c == '[') {
68200+ for (--p; n < endp; ++n)
68201+ if (!glob_match(p, n))
68202+ return 0;
68203+ } else if (c == '/') {
68204+ while (*n != '\0' && *n != '/')
68205+ ++n;
68206+ if (*n == '/' && !glob_match(p, n + 1))
68207+ return 0;
68208+ } else {
68209+ for (--p; n < endp; ++n)
68210+ if (*n == c && !glob_match(p, n))
68211+ return 0;
68212+ }
68213+
68214+ return 1;
68215+ }
68216+ case '[':
68217+ {
68218+ int not;
68219+ char cold;
68220+
68221+ if (*n == '\0' || *n == '/')
68222+ return 1;
68223+
68224+ not = (*p == '!' || *p == '^');
68225+ if (not)
68226+ ++p;
68227+
68228+ c = *p++;
68229+ for (;;) {
68230+ unsigned char fn = (unsigned char)*n;
68231+
68232+ if (c == '\0')
68233+ return 1;
68234+ else {
68235+ if (c == fn)
68236+ goto matched;
68237+ cold = c;
68238+ c = *p++;
68239+
68240+ if (c == '-' && *p != ']') {
68241+ unsigned char cend = *p++;
68242+
68243+ if (cend == '\0')
68244+ return 1;
68245+
68246+ if (cold <= fn && fn <= cend)
68247+ goto matched;
68248+
68249+ c = *p++;
68250+ }
68251+ }
68252+
68253+ if (c == ']')
68254+ break;
68255+ }
68256+ if (!not)
68257+ return 1;
68258+ break;
68259+ matched:
68260+ while (c != ']') {
68261+ if (c == '\0')
68262+ return 1;
68263+
68264+ c = *p++;
68265+ }
68266+ if (not)
68267+ return 1;
68268+ }
68269+ break;
68270+ default:
68271+ if (c != *n)
68272+ return 1;
68273+ }
68274+
68275+ ++n;
68276+ }
68277+
68278+ if (*n == '\0')
68279+ return 0;
68280+
68281+ if (*n == '/')
68282+ return 0;
68283+
68284+ return 1;
68285+}
68286+
68287+static struct acl_object_label *
68288+chk_glob_label(struct acl_object_label *globbed,
68289+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
68290+{
68291+ struct acl_object_label *tmp;
68292+
68293+ if (*path == NULL)
68294+ *path = gr_to_filename_nolock(dentry, mnt);
68295+
68296+ tmp = globbed;
68297+
68298+ while (tmp) {
68299+ if (!glob_match(tmp->filename, *path))
68300+ return tmp;
68301+ tmp = tmp->next;
68302+ }
68303+
68304+ return NULL;
68305+}
68306+
68307+static struct acl_object_label *
68308+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68309+ const ino_t curr_ino, const dev_t curr_dev,
68310+ const struct acl_subject_label *subj, char **path, const int checkglob)
68311+{
68312+ struct acl_subject_label *tmpsubj;
68313+ struct acl_object_label *retval;
68314+ struct acl_object_label *retval2;
68315+
68316+ tmpsubj = (struct acl_subject_label *) subj;
68317+ read_lock(&gr_inode_lock);
68318+ do {
68319+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
68320+ if (retval) {
68321+ if (checkglob && retval->globbed) {
68322+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
68323+ if (retval2)
68324+ retval = retval2;
68325+ }
68326+ break;
68327+ }
68328+ } while ((tmpsubj = tmpsubj->parent_subject));
68329+ read_unlock(&gr_inode_lock);
68330+
68331+ return retval;
68332+}
68333+
68334+static __inline__ struct acl_object_label *
68335+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68336+ struct dentry *curr_dentry,
68337+ const struct acl_subject_label *subj, char **path, const int checkglob)
68338+{
68339+ int newglob = checkglob;
68340+ ino_t inode;
68341+ dev_t device;
68342+
68343+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
68344+ as we don't want a / * rule to match instead of the / object
68345+ don't do this for create lookups that call this function though, since they're looking up
68346+ on the parent and thus need globbing checks on all paths
68347+ */
68348+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
68349+ newglob = GR_NO_GLOB;
68350+
68351+ spin_lock(&curr_dentry->d_lock);
68352+ inode = curr_dentry->d_inode->i_ino;
68353+ device = __get_dev(curr_dentry);
68354+ spin_unlock(&curr_dentry->d_lock);
68355+
68356+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
68357+}
68358+
68359+#ifdef CONFIG_HUGETLBFS
68360+static inline bool
68361+is_hugetlbfs_mnt(const struct vfsmount *mnt)
68362+{
68363+ int i;
68364+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
68365+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
68366+ return true;
68367+ }
68368+
68369+ return false;
68370+}
68371+#endif
68372+
68373+static struct acl_object_label *
68374+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68375+ const struct acl_subject_label *subj, char *path, const int checkglob)
68376+{
68377+ struct dentry *dentry = (struct dentry *) l_dentry;
68378+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68379+ struct mount *real_mnt = real_mount(mnt);
68380+ struct acl_object_label *retval;
68381+ struct dentry *parent;
68382+
68383+ read_seqlock_excl(&mount_lock);
68384+ write_seqlock(&rename_lock);
68385+
68386+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68387+#ifdef CONFIG_NET
68388+ mnt == sock_mnt ||
68389+#endif
68390+#ifdef CONFIG_HUGETLBFS
68391+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68392+#endif
68393+ /* ignore Eric Biederman */
68394+ IS_PRIVATE(l_dentry->d_inode))) {
68395+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68396+ goto out;
68397+ }
68398+
68399+ for (;;) {
68400+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68401+ break;
68402+
68403+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68404+ if (!mnt_has_parent(real_mnt))
68405+ break;
68406+
68407+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68408+ if (retval != NULL)
68409+ goto out;
68410+
68411+ dentry = real_mnt->mnt_mountpoint;
68412+ real_mnt = real_mnt->mnt_parent;
68413+ mnt = &real_mnt->mnt;
68414+ continue;
68415+ }
68416+
68417+ parent = dentry->d_parent;
68418+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68419+ if (retval != NULL)
68420+ goto out;
68421+
68422+ dentry = parent;
68423+ }
68424+
68425+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68426+
68427+ /* gr_real_root is pinned so we don't have to hold a reference */
68428+ if (retval == NULL)
68429+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68430+out:
68431+ write_sequnlock(&rename_lock);
68432+ read_sequnlock_excl(&mount_lock);
68433+
68434+ BUG_ON(retval == NULL);
68435+
68436+ return retval;
68437+}
68438+
68439+static __inline__ struct acl_object_label *
68440+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68441+ const struct acl_subject_label *subj)
68442+{
68443+ char *path = NULL;
68444+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68445+}
68446+
68447+static __inline__ struct acl_object_label *
68448+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68449+ const struct acl_subject_label *subj)
68450+{
68451+ char *path = NULL;
68452+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68453+}
68454+
68455+static __inline__ struct acl_object_label *
68456+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68457+ const struct acl_subject_label *subj, char *path)
68458+{
68459+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68460+}
68461+
68462+struct acl_subject_label *
68463+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68464+ const struct acl_role_label *role)
68465+{
68466+ struct dentry *dentry = (struct dentry *) l_dentry;
68467+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68468+ struct mount *real_mnt = real_mount(mnt);
68469+ struct acl_subject_label *retval;
68470+ struct dentry *parent;
68471+
68472+ read_seqlock_excl(&mount_lock);
68473+ write_seqlock(&rename_lock);
68474+
68475+ for (;;) {
68476+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68477+ break;
68478+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68479+ if (!mnt_has_parent(real_mnt))
68480+ break;
68481+
68482+ spin_lock(&dentry->d_lock);
68483+ read_lock(&gr_inode_lock);
68484+ retval =
68485+ lookup_acl_subj_label(dentry->d_inode->i_ino,
68486+ __get_dev(dentry), role);
68487+ read_unlock(&gr_inode_lock);
68488+ spin_unlock(&dentry->d_lock);
68489+ if (retval != NULL)
68490+ goto out;
68491+
68492+ dentry = real_mnt->mnt_mountpoint;
68493+ real_mnt = real_mnt->mnt_parent;
68494+ mnt = &real_mnt->mnt;
68495+ continue;
68496+ }
68497+
68498+ spin_lock(&dentry->d_lock);
68499+ read_lock(&gr_inode_lock);
68500+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68501+ __get_dev(dentry), role);
68502+ read_unlock(&gr_inode_lock);
68503+ parent = dentry->d_parent;
68504+ spin_unlock(&dentry->d_lock);
68505+
68506+ if (retval != NULL)
68507+ goto out;
68508+
68509+ dentry = parent;
68510+ }
68511+
68512+ spin_lock(&dentry->d_lock);
68513+ read_lock(&gr_inode_lock);
68514+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68515+ __get_dev(dentry), role);
68516+ read_unlock(&gr_inode_lock);
68517+ spin_unlock(&dentry->d_lock);
68518+
68519+ if (unlikely(retval == NULL)) {
68520+ /* gr_real_root is pinned, we don't need to hold a reference */
68521+ read_lock(&gr_inode_lock);
68522+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68523+ __get_dev(gr_real_root.dentry), role);
68524+ read_unlock(&gr_inode_lock);
68525+ }
68526+out:
68527+ write_sequnlock(&rename_lock);
68528+ read_sequnlock_excl(&mount_lock);
68529+
68530+ BUG_ON(retval == NULL);
68531+
68532+ return retval;
68533+}
68534+
68535+void
68536+assign_special_role(const char *rolename)
68537+{
68538+ struct acl_object_label *obj;
68539+ struct acl_role_label *r;
68540+ struct acl_role_label *assigned = NULL;
68541+ struct task_struct *tsk;
68542+ struct file *filp;
68543+
68544+ FOR_EACH_ROLE_START(r)
68545+ if (!strcmp(rolename, r->rolename) &&
68546+ (r->roletype & GR_ROLE_SPECIAL)) {
68547+ assigned = r;
68548+ break;
68549+ }
68550+ FOR_EACH_ROLE_END(r)
68551+
68552+ if (!assigned)
68553+ return;
68554+
68555+ read_lock(&tasklist_lock);
68556+ read_lock(&grsec_exec_file_lock);
68557+
68558+ tsk = current->real_parent;
68559+ if (tsk == NULL)
68560+ goto out_unlock;
68561+
68562+ filp = tsk->exec_file;
68563+ if (filp == NULL)
68564+ goto out_unlock;
68565+
68566+ tsk->is_writable = 0;
68567+ tsk->inherited = 0;
68568+
68569+ tsk->acl_sp_role = 1;
68570+ tsk->acl_role_id = ++acl_sp_role_value;
68571+ tsk->role = assigned;
68572+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68573+
68574+ /* ignore additional mmap checks for processes that are writable
68575+ by the default ACL */
68576+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68577+ if (unlikely(obj->mode & GR_WRITE))
68578+ tsk->is_writable = 1;
68579+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68580+ if (unlikely(obj->mode & GR_WRITE))
68581+ tsk->is_writable = 1;
68582+
68583+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68584+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68585+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68586+#endif
68587+
68588+out_unlock:
68589+ read_unlock(&grsec_exec_file_lock);
68590+ read_unlock(&tasklist_lock);
68591+ return;
68592+}
68593+
68594+
68595+static void
68596+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68597+{
68598+ struct task_struct *task = current;
68599+ const struct cred *cred = current_cred();
68600+
68601+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68602+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68603+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68604+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68605+
68606+ return;
68607+}
68608+
68609+static void
68610+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68611+{
68612+ struct task_struct *task = current;
68613+ const struct cred *cred = current_cred();
68614+
68615+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68616+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68617+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68618+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68619+
68620+ return;
68621+}
68622+
68623+static void
68624+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68625+{
68626+ struct task_struct *task = current;
68627+ const struct cred *cred = current_cred();
68628+
68629+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68630+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68631+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68632+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68633+
68634+ return;
68635+}
68636+
68637+static void
68638+gr_set_proc_res(struct task_struct *task)
68639+{
68640+ struct acl_subject_label *proc;
68641+ unsigned short i;
68642+
68643+ proc = task->acl;
68644+
68645+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68646+ return;
68647+
68648+ for (i = 0; i < RLIM_NLIMITS; i++) {
68649+ if (!(proc->resmask & (1U << i)))
68650+ continue;
68651+
68652+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68653+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68654+
68655+ if (i == RLIMIT_CPU)
68656+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
68657+ }
68658+
68659+ return;
68660+}
68661+
68662+/* both of the below must be called with
68663+ rcu_read_lock();
68664+ read_lock(&tasklist_lock);
68665+ read_lock(&grsec_exec_file_lock);
68666+*/
68667+
68668+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68669+{
68670+ char *tmpname;
68671+ struct acl_subject_label *tmpsubj;
68672+ struct file *filp;
68673+ struct name_entry *nmatch;
68674+
68675+ filp = task->exec_file;
68676+ if (filp == NULL)
68677+ return NULL;
68678+
68679+ /* the following is to apply the correct subject
68680+ on binaries running when the RBAC system
68681+ is enabled, when the binaries have been
68682+ replaced or deleted since their execution
68683+ -----
68684+ when the RBAC system starts, the inode/dev
68685+ from exec_file will be one the RBAC system
68686+ is unaware of. It only knows the inode/dev
68687+ of the present file on disk, or the absence
68688+ of it.
68689+ */
68690+
68691+ if (filename)
68692+ nmatch = __lookup_name_entry(state, filename);
68693+ else {
68694+ preempt_disable();
68695+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68696+
68697+ nmatch = __lookup_name_entry(state, tmpname);
68698+ preempt_enable();
68699+ }
68700+ tmpsubj = NULL;
68701+ if (nmatch) {
68702+ if (nmatch->deleted)
68703+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68704+ else
68705+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68706+ }
68707+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68708+ then we fall back to a normal lookup based on the binary's ino/dev
68709+ */
68710+ if (tmpsubj == NULL)
68711+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68712+
68713+ return tmpsubj;
68714+}
68715+
68716+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68717+{
68718+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68719+}
68720+
68721+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68722+{
68723+ struct acl_object_label *obj;
68724+ struct file *filp;
68725+
68726+ filp = task->exec_file;
68727+
68728+ task->acl = subj;
68729+ task->is_writable = 0;
68730+ /* ignore additional mmap checks for processes that are writable
68731+ by the default ACL */
68732+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68733+ if (unlikely(obj->mode & GR_WRITE))
68734+ task->is_writable = 1;
68735+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68736+ if (unlikely(obj->mode & GR_WRITE))
68737+ task->is_writable = 1;
68738+
68739+ gr_set_proc_res(task);
68740+
68741+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68742+ 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);
68743+#endif
68744+}
68745+
68746+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68747+{
68748+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68749+}
68750+
68751+__u32
68752+gr_search_file(const struct dentry * dentry, const __u32 mode,
68753+ const struct vfsmount * mnt)
68754+{
68755+ __u32 retval = mode;
68756+ struct acl_subject_label *curracl;
68757+ struct acl_object_label *currobj;
68758+
68759+ if (unlikely(!(gr_status & GR_READY)))
68760+ return (mode & ~GR_AUDITS);
68761+
68762+ curracl = current->acl;
68763+
68764+ currobj = chk_obj_label(dentry, mnt, curracl);
68765+ retval = currobj->mode & mode;
68766+
68767+ /* if we're opening a specified transfer file for writing
68768+ (e.g. /dev/initctl), then transfer our role to init
68769+ */
68770+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68771+ current->role->roletype & GR_ROLE_PERSIST)) {
68772+ struct task_struct *task = init_pid_ns.child_reaper;
68773+
68774+ if (task->role != current->role) {
68775+ struct acl_subject_label *subj;
68776+
68777+ task->acl_sp_role = 0;
68778+ task->acl_role_id = current->acl_role_id;
68779+ task->role = current->role;
68780+ rcu_read_lock();
68781+ read_lock(&grsec_exec_file_lock);
68782+ subj = gr_get_subject_for_task(task, NULL);
68783+ gr_apply_subject_to_task(task, subj);
68784+ read_unlock(&grsec_exec_file_lock);
68785+ rcu_read_unlock();
68786+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68787+ }
68788+ }
68789+
68790+ if (unlikely
68791+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68792+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68793+ __u32 new_mode = mode;
68794+
68795+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68796+
68797+ retval = new_mode;
68798+
68799+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68800+ new_mode |= GR_INHERIT;
68801+
68802+ if (!(mode & GR_NOLEARN))
68803+ gr_log_learn(dentry, mnt, new_mode);
68804+ }
68805+
68806+ return retval;
68807+}
68808+
68809+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68810+ const struct dentry *parent,
68811+ const struct vfsmount *mnt)
68812+{
68813+ struct name_entry *match;
68814+ struct acl_object_label *matchpo;
68815+ struct acl_subject_label *curracl;
68816+ char *path;
68817+
68818+ if (unlikely(!(gr_status & GR_READY)))
68819+ return NULL;
68820+
68821+ preempt_disable();
68822+ path = gr_to_filename_rbac(new_dentry, mnt);
68823+ match = lookup_name_entry_create(path);
68824+
68825+ curracl = current->acl;
68826+
68827+ if (match) {
68828+ read_lock(&gr_inode_lock);
68829+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68830+ read_unlock(&gr_inode_lock);
68831+
68832+ if (matchpo) {
68833+ preempt_enable();
68834+ return matchpo;
68835+ }
68836+ }
68837+
68838+ // lookup parent
68839+
68840+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68841+
68842+ preempt_enable();
68843+ return matchpo;
68844+}
68845+
68846+__u32
68847+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68848+ const struct vfsmount * mnt, const __u32 mode)
68849+{
68850+ struct acl_object_label *matchpo;
68851+ __u32 retval;
68852+
68853+ if (unlikely(!(gr_status & GR_READY)))
68854+ return (mode & ~GR_AUDITS);
68855+
68856+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68857+
68858+ retval = matchpo->mode & mode;
68859+
68860+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68861+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68862+ __u32 new_mode = mode;
68863+
68864+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68865+
68866+ gr_log_learn(new_dentry, mnt, new_mode);
68867+ return new_mode;
68868+ }
68869+
68870+ return retval;
68871+}
68872+
68873+__u32
68874+gr_check_link(const struct dentry * new_dentry,
68875+ const struct dentry * parent_dentry,
68876+ const struct vfsmount * parent_mnt,
68877+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68878+{
68879+ struct acl_object_label *obj;
68880+ __u32 oldmode, newmode;
68881+ __u32 needmode;
68882+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68883+ GR_DELETE | GR_INHERIT;
68884+
68885+ if (unlikely(!(gr_status & GR_READY)))
68886+ return (GR_CREATE | GR_LINK);
68887+
68888+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68889+ oldmode = obj->mode;
68890+
68891+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68892+ newmode = obj->mode;
68893+
68894+ needmode = newmode & checkmodes;
68895+
68896+ // old name for hardlink must have at least the permissions of the new name
68897+ if ((oldmode & needmode) != needmode)
68898+ goto bad;
68899+
68900+ // if old name had restrictions/auditing, make sure the new name does as well
68901+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68902+
68903+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68904+ if (is_privileged_binary(old_dentry))
68905+ needmode |= GR_SETID;
68906+
68907+ if ((newmode & needmode) != needmode)
68908+ goto bad;
68909+
68910+ // enforce minimum permissions
68911+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68912+ return newmode;
68913+bad:
68914+ needmode = oldmode;
68915+ if (is_privileged_binary(old_dentry))
68916+ needmode |= GR_SETID;
68917+
68918+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68919+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68920+ return (GR_CREATE | GR_LINK);
68921+ } else if (newmode & GR_SUPPRESS)
68922+ return GR_SUPPRESS;
68923+ else
68924+ return 0;
68925+}
68926+
68927+int
68928+gr_check_hidden_task(const struct task_struct *task)
68929+{
68930+ if (unlikely(!(gr_status & GR_READY)))
68931+ return 0;
68932+
68933+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68934+ return 1;
68935+
68936+ return 0;
68937+}
68938+
68939+int
68940+gr_check_protected_task(const struct task_struct *task)
68941+{
68942+ if (unlikely(!(gr_status & GR_READY) || !task))
68943+ return 0;
68944+
68945+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68946+ task->acl != current->acl)
68947+ return 1;
68948+
68949+ return 0;
68950+}
68951+
68952+int
68953+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68954+{
68955+ struct task_struct *p;
68956+ int ret = 0;
68957+
68958+ if (unlikely(!(gr_status & GR_READY) || !pid))
68959+ return ret;
68960+
68961+ read_lock(&tasklist_lock);
68962+ do_each_pid_task(pid, type, p) {
68963+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68964+ p->acl != current->acl) {
68965+ ret = 1;
68966+ goto out;
68967+ }
68968+ } while_each_pid_task(pid, type, p);
68969+out:
68970+ read_unlock(&tasklist_lock);
68971+
68972+ return ret;
68973+}
68974+
68975+void
68976+gr_copy_label(struct task_struct *tsk)
68977+{
68978+ struct task_struct *p = current;
68979+
68980+ tsk->inherited = p->inherited;
68981+ tsk->acl_sp_role = 0;
68982+ tsk->acl_role_id = p->acl_role_id;
68983+ tsk->acl = p->acl;
68984+ tsk->role = p->role;
68985+ tsk->signal->used_accept = 0;
68986+ tsk->signal->curr_ip = p->signal->curr_ip;
68987+ tsk->signal->saved_ip = p->signal->saved_ip;
68988+ if (p->exec_file)
68989+ get_file(p->exec_file);
68990+ tsk->exec_file = p->exec_file;
68991+ tsk->is_writable = p->is_writable;
68992+ if (unlikely(p->signal->used_accept)) {
68993+ p->signal->curr_ip = 0;
68994+ p->signal->saved_ip = 0;
68995+ }
68996+
68997+ return;
68998+}
68999+
69000+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
69001+
69002+int
69003+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69004+{
69005+ unsigned int i;
69006+ __u16 num;
69007+ uid_t *uidlist;
69008+ uid_t curuid;
69009+ int realok = 0;
69010+ int effectiveok = 0;
69011+ int fsok = 0;
69012+ uid_t globalreal, globaleffective, globalfs;
69013+
69014+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
69015+ struct user_struct *user;
69016+
69017+ if (!uid_valid(real))
69018+ goto skipit;
69019+
69020+ /* find user based on global namespace */
69021+
69022+ globalreal = GR_GLOBAL_UID(real);
69023+
69024+ user = find_user(make_kuid(&init_user_ns, globalreal));
69025+ if (user == NULL)
69026+ goto skipit;
69027+
69028+ if (gr_process_kernel_setuid_ban(user)) {
69029+ /* for find_user */
69030+ free_uid(user);
69031+ return 1;
69032+ }
69033+
69034+ /* for find_user */
69035+ free_uid(user);
69036+
69037+skipit:
69038+#endif
69039+
69040+ if (unlikely(!(gr_status & GR_READY)))
69041+ return 0;
69042+
69043+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69044+ gr_log_learn_uid_change(real, effective, fs);
69045+
69046+ num = current->acl->user_trans_num;
69047+ uidlist = current->acl->user_transitions;
69048+
69049+ if (uidlist == NULL)
69050+ return 0;
69051+
69052+ if (!uid_valid(real)) {
69053+ realok = 1;
69054+ globalreal = (uid_t)-1;
69055+ } else {
69056+ globalreal = GR_GLOBAL_UID(real);
69057+ }
69058+ if (!uid_valid(effective)) {
69059+ effectiveok = 1;
69060+ globaleffective = (uid_t)-1;
69061+ } else {
69062+ globaleffective = GR_GLOBAL_UID(effective);
69063+ }
69064+ if (!uid_valid(fs)) {
69065+ fsok = 1;
69066+ globalfs = (uid_t)-1;
69067+ } else {
69068+ globalfs = GR_GLOBAL_UID(fs);
69069+ }
69070+
69071+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
69072+ for (i = 0; i < num; i++) {
69073+ curuid = uidlist[i];
69074+ if (globalreal == curuid)
69075+ realok = 1;
69076+ if (globaleffective == curuid)
69077+ effectiveok = 1;
69078+ if (globalfs == curuid)
69079+ fsok = 1;
69080+ }
69081+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
69082+ for (i = 0; i < num; i++) {
69083+ curuid = uidlist[i];
69084+ if (globalreal == curuid)
69085+ break;
69086+ if (globaleffective == curuid)
69087+ break;
69088+ if (globalfs == curuid)
69089+ break;
69090+ }
69091+ /* not in deny list */
69092+ if (i == num) {
69093+ realok = 1;
69094+ effectiveok = 1;
69095+ fsok = 1;
69096+ }
69097+ }
69098+
69099+ if (realok && effectiveok && fsok)
69100+ return 0;
69101+ else {
69102+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
69103+ return 1;
69104+ }
69105+}
69106+
69107+int
69108+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69109+{
69110+ unsigned int i;
69111+ __u16 num;
69112+ gid_t *gidlist;
69113+ gid_t curgid;
69114+ int realok = 0;
69115+ int effectiveok = 0;
69116+ int fsok = 0;
69117+ gid_t globalreal, globaleffective, globalfs;
69118+
69119+ if (unlikely(!(gr_status & GR_READY)))
69120+ return 0;
69121+
69122+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69123+ gr_log_learn_gid_change(real, effective, fs);
69124+
69125+ num = current->acl->group_trans_num;
69126+ gidlist = current->acl->group_transitions;
69127+
69128+ if (gidlist == NULL)
69129+ return 0;
69130+
69131+ if (!gid_valid(real)) {
69132+ realok = 1;
69133+ globalreal = (gid_t)-1;
69134+ } else {
69135+ globalreal = GR_GLOBAL_GID(real);
69136+ }
69137+ if (!gid_valid(effective)) {
69138+ effectiveok = 1;
69139+ globaleffective = (gid_t)-1;
69140+ } else {
69141+ globaleffective = GR_GLOBAL_GID(effective);
69142+ }
69143+ if (!gid_valid(fs)) {
69144+ fsok = 1;
69145+ globalfs = (gid_t)-1;
69146+ } else {
69147+ globalfs = GR_GLOBAL_GID(fs);
69148+ }
69149+
69150+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
69151+ for (i = 0; i < num; i++) {
69152+ curgid = gidlist[i];
69153+ if (globalreal == curgid)
69154+ realok = 1;
69155+ if (globaleffective == curgid)
69156+ effectiveok = 1;
69157+ if (globalfs == curgid)
69158+ fsok = 1;
69159+ }
69160+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
69161+ for (i = 0; i < num; i++) {
69162+ curgid = gidlist[i];
69163+ if (globalreal == curgid)
69164+ break;
69165+ if (globaleffective == curgid)
69166+ break;
69167+ if (globalfs == curgid)
69168+ break;
69169+ }
69170+ /* not in deny list */
69171+ if (i == num) {
69172+ realok = 1;
69173+ effectiveok = 1;
69174+ fsok = 1;
69175+ }
69176+ }
69177+
69178+ if (realok && effectiveok && fsok)
69179+ return 0;
69180+ else {
69181+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
69182+ return 1;
69183+ }
69184+}
69185+
69186+extern int gr_acl_is_capable(const int cap);
69187+
69188+void
69189+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
69190+{
69191+ struct acl_role_label *role = task->role;
69192+ struct acl_subject_label *subj = NULL;
69193+ struct acl_object_label *obj;
69194+ struct file *filp;
69195+ uid_t uid;
69196+ gid_t gid;
69197+
69198+ if (unlikely(!(gr_status & GR_READY)))
69199+ return;
69200+
69201+ uid = GR_GLOBAL_UID(kuid);
69202+ gid = GR_GLOBAL_GID(kgid);
69203+
69204+ filp = task->exec_file;
69205+
69206+ /* kernel process, we'll give them the kernel role */
69207+ if (unlikely(!filp)) {
69208+ task->role = running_polstate.kernel_role;
69209+ task->acl = running_polstate.kernel_role->root_label;
69210+ return;
69211+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
69212+ /* save the current ip at time of role lookup so that the proper
69213+ IP will be learned for role_allowed_ip */
69214+ task->signal->saved_ip = task->signal->curr_ip;
69215+ role = lookup_acl_role_label(task, uid, gid);
69216+ }
69217+
69218+ /* don't change the role if we're not a privileged process */
69219+ if (role && task->role != role &&
69220+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
69221+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
69222+ return;
69223+
69224+ /* perform subject lookup in possibly new role
69225+ we can use this result below in the case where role == task->role
69226+ */
69227+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
69228+
69229+ /* if we changed uid/gid, but result in the same role
69230+ and are using inheritance, don't lose the inherited subject
69231+ if current subject is other than what normal lookup
69232+ would result in, we arrived via inheritance, don't
69233+ lose subject
69234+ */
69235+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
69236+ (subj == task->acl)))
69237+ task->acl = subj;
69238+
69239+ /* leave task->inherited unaffected */
69240+
69241+ task->role = role;
69242+
69243+ task->is_writable = 0;
69244+
69245+ /* ignore additional mmap checks for processes that are writable
69246+ by the default ACL */
69247+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69248+ if (unlikely(obj->mode & GR_WRITE))
69249+ task->is_writable = 1;
69250+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
69251+ if (unlikely(obj->mode & GR_WRITE))
69252+ task->is_writable = 1;
69253+
69254+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69255+ 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);
69256+#endif
69257+
69258+ gr_set_proc_res(task);
69259+
69260+ return;
69261+}
69262+
69263+int
69264+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
69265+ const int unsafe_flags)
69266+{
69267+ struct task_struct *task = current;
69268+ struct acl_subject_label *newacl;
69269+ struct acl_object_label *obj;
69270+ __u32 retmode;
69271+
69272+ if (unlikely(!(gr_status & GR_READY)))
69273+ return 0;
69274+
69275+ newacl = chk_subj_label(dentry, mnt, task->role);
69276+
69277+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
69278+ did an exec
69279+ */
69280+ rcu_read_lock();
69281+ read_lock(&tasklist_lock);
69282+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
69283+ (task->parent->acl->mode & GR_POVERRIDE))) {
69284+ read_unlock(&tasklist_lock);
69285+ rcu_read_unlock();
69286+ goto skip_check;
69287+ }
69288+ read_unlock(&tasklist_lock);
69289+ rcu_read_unlock();
69290+
69291+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
69292+ !(task->role->roletype & GR_ROLE_GOD) &&
69293+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
69294+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
69295+ if (unsafe_flags & LSM_UNSAFE_SHARE)
69296+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
69297+ else
69298+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
69299+ return -EACCES;
69300+ }
69301+
69302+skip_check:
69303+
69304+ obj = chk_obj_label(dentry, mnt, task->acl);
69305+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
69306+
69307+ if (!(task->acl->mode & GR_INHERITLEARN) &&
69308+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
69309+ if (obj->nested)
69310+ task->acl = obj->nested;
69311+ else
69312+ task->acl = newacl;
69313+ task->inherited = 0;
69314+ } else {
69315+ task->inherited = 1;
69316+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
69317+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
69318+ }
69319+
69320+ task->is_writable = 0;
69321+
69322+ /* ignore additional mmap checks for processes that are writable
69323+ by the default ACL */
69324+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
69325+ if (unlikely(obj->mode & GR_WRITE))
69326+ task->is_writable = 1;
69327+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
69328+ if (unlikely(obj->mode & GR_WRITE))
69329+ task->is_writable = 1;
69330+
69331+ gr_set_proc_res(task);
69332+
69333+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69334+ 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);
69335+#endif
69336+ return 0;
69337+}
69338+
69339+/* always called with valid inodev ptr */
69340+static void
69341+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
69342+{
69343+ struct acl_object_label *matchpo;
69344+ struct acl_subject_label *matchps;
69345+ struct acl_subject_label *subj;
69346+ struct acl_role_label *role;
69347+ unsigned int x;
69348+
69349+ FOR_EACH_ROLE_START(role)
69350+ FOR_EACH_SUBJECT_START(role, subj, x)
69351+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69352+ matchpo->mode |= GR_DELETED;
69353+ FOR_EACH_SUBJECT_END(subj,x)
69354+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69355+ /* nested subjects aren't in the role's subj_hash table */
69356+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69357+ matchpo->mode |= GR_DELETED;
69358+ FOR_EACH_NESTED_SUBJECT_END(subj)
69359+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
69360+ matchps->mode |= GR_DELETED;
69361+ FOR_EACH_ROLE_END(role)
69362+
69363+ inodev->nentry->deleted = 1;
69364+
69365+ return;
69366+}
69367+
69368+void
69369+gr_handle_delete(const ino_t ino, const dev_t dev)
69370+{
69371+ struct inodev_entry *inodev;
69372+
69373+ if (unlikely(!(gr_status & GR_READY)))
69374+ return;
69375+
69376+ write_lock(&gr_inode_lock);
69377+ inodev = lookup_inodev_entry(ino, dev);
69378+ if (inodev != NULL)
69379+ do_handle_delete(inodev, ino, dev);
69380+ write_unlock(&gr_inode_lock);
69381+
69382+ return;
69383+}
69384+
69385+static void
69386+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69387+ const ino_t newinode, const dev_t newdevice,
69388+ struct acl_subject_label *subj)
69389+{
69390+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69391+ struct acl_object_label *match;
69392+
69393+ match = subj->obj_hash[index];
69394+
69395+ while (match && (match->inode != oldinode ||
69396+ match->device != olddevice ||
69397+ !(match->mode & GR_DELETED)))
69398+ match = match->next;
69399+
69400+ if (match && (match->inode == oldinode)
69401+ && (match->device == olddevice)
69402+ && (match->mode & GR_DELETED)) {
69403+ if (match->prev == NULL) {
69404+ subj->obj_hash[index] = match->next;
69405+ if (match->next != NULL)
69406+ match->next->prev = NULL;
69407+ } else {
69408+ match->prev->next = match->next;
69409+ if (match->next != NULL)
69410+ match->next->prev = match->prev;
69411+ }
69412+ match->prev = NULL;
69413+ match->next = NULL;
69414+ match->inode = newinode;
69415+ match->device = newdevice;
69416+ match->mode &= ~GR_DELETED;
69417+
69418+ insert_acl_obj_label(match, subj);
69419+ }
69420+
69421+ return;
69422+}
69423+
69424+static void
69425+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69426+ const ino_t newinode, const dev_t newdevice,
69427+ struct acl_role_label *role)
69428+{
69429+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69430+ struct acl_subject_label *match;
69431+
69432+ match = role->subj_hash[index];
69433+
69434+ while (match && (match->inode != oldinode ||
69435+ match->device != olddevice ||
69436+ !(match->mode & GR_DELETED)))
69437+ match = match->next;
69438+
69439+ if (match && (match->inode == oldinode)
69440+ && (match->device == olddevice)
69441+ && (match->mode & GR_DELETED)) {
69442+ if (match->prev == NULL) {
69443+ role->subj_hash[index] = match->next;
69444+ if (match->next != NULL)
69445+ match->next->prev = NULL;
69446+ } else {
69447+ match->prev->next = match->next;
69448+ if (match->next != NULL)
69449+ match->next->prev = match->prev;
69450+ }
69451+ match->prev = NULL;
69452+ match->next = NULL;
69453+ match->inode = newinode;
69454+ match->device = newdevice;
69455+ match->mode &= ~GR_DELETED;
69456+
69457+ insert_acl_subj_label(match, role);
69458+ }
69459+
69460+ return;
69461+}
69462+
69463+static void
69464+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69465+ const ino_t newinode, const dev_t newdevice)
69466+{
69467+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69468+ struct inodev_entry *match;
69469+
69470+ match = running_polstate.inodev_set.i_hash[index];
69471+
69472+ while (match && (match->nentry->inode != oldinode ||
69473+ match->nentry->device != olddevice || !match->nentry->deleted))
69474+ match = match->next;
69475+
69476+ if (match && (match->nentry->inode == oldinode)
69477+ && (match->nentry->device == olddevice) &&
69478+ match->nentry->deleted) {
69479+ if (match->prev == NULL) {
69480+ running_polstate.inodev_set.i_hash[index] = match->next;
69481+ if (match->next != NULL)
69482+ match->next->prev = NULL;
69483+ } else {
69484+ match->prev->next = match->next;
69485+ if (match->next != NULL)
69486+ match->next->prev = match->prev;
69487+ }
69488+ match->prev = NULL;
69489+ match->next = NULL;
69490+ match->nentry->inode = newinode;
69491+ match->nentry->device = newdevice;
69492+ match->nentry->deleted = 0;
69493+
69494+ insert_inodev_entry(match);
69495+ }
69496+
69497+ return;
69498+}
69499+
69500+static void
69501+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69502+{
69503+ struct acl_subject_label *subj;
69504+ struct acl_role_label *role;
69505+ unsigned int x;
69506+
69507+ FOR_EACH_ROLE_START(role)
69508+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69509+
69510+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69511+ if ((subj->inode == ino) && (subj->device == dev)) {
69512+ subj->inode = ino;
69513+ subj->device = dev;
69514+ }
69515+ /* nested subjects aren't in the role's subj_hash table */
69516+ update_acl_obj_label(matchn->inode, matchn->device,
69517+ ino, dev, subj);
69518+ FOR_EACH_NESTED_SUBJECT_END(subj)
69519+ FOR_EACH_SUBJECT_START(role, subj, x)
69520+ update_acl_obj_label(matchn->inode, matchn->device,
69521+ ino, dev, subj);
69522+ FOR_EACH_SUBJECT_END(subj,x)
69523+ FOR_EACH_ROLE_END(role)
69524+
69525+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69526+
69527+ return;
69528+}
69529+
69530+static void
69531+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69532+ const struct vfsmount *mnt)
69533+{
69534+ ino_t ino = dentry->d_inode->i_ino;
69535+ dev_t dev = __get_dev(dentry);
69536+
69537+ __do_handle_create(matchn, ino, dev);
69538+
69539+ return;
69540+}
69541+
69542+void
69543+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69544+{
69545+ struct name_entry *matchn;
69546+
69547+ if (unlikely(!(gr_status & GR_READY)))
69548+ return;
69549+
69550+ preempt_disable();
69551+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69552+
69553+ if (unlikely((unsigned long)matchn)) {
69554+ write_lock(&gr_inode_lock);
69555+ do_handle_create(matchn, dentry, mnt);
69556+ write_unlock(&gr_inode_lock);
69557+ }
69558+ preempt_enable();
69559+
69560+ return;
69561+}
69562+
69563+void
69564+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69565+{
69566+ struct name_entry *matchn;
69567+
69568+ if (unlikely(!(gr_status & GR_READY)))
69569+ return;
69570+
69571+ preempt_disable();
69572+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69573+
69574+ if (unlikely((unsigned long)matchn)) {
69575+ write_lock(&gr_inode_lock);
69576+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69577+ write_unlock(&gr_inode_lock);
69578+ }
69579+ preempt_enable();
69580+
69581+ return;
69582+}
69583+
69584+void
69585+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69586+ struct dentry *old_dentry,
69587+ struct dentry *new_dentry,
69588+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
69589+{
69590+ struct name_entry *matchn;
69591+ struct name_entry *matchn2 = NULL;
69592+ struct inodev_entry *inodev;
69593+ struct inode *inode = new_dentry->d_inode;
69594+ ino_t old_ino = old_dentry->d_inode->i_ino;
69595+ dev_t old_dev = __get_dev(old_dentry);
69596+ unsigned int exchange = flags & RENAME_EXCHANGE;
69597+
69598+ /* vfs_rename swaps the name and parent link for old_dentry and
69599+ new_dentry
69600+ at this point, old_dentry has the new name, parent link, and inode
69601+ for the renamed file
69602+ if a file is being replaced by a rename, new_dentry has the inode
69603+ and name for the replaced file
69604+ */
69605+
69606+ if (unlikely(!(gr_status & GR_READY)))
69607+ return;
69608+
69609+ preempt_disable();
69610+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69611+
69612+ /* exchange cases:
69613+ a filename exists for the source, but not dest
69614+ do a recreate on source
69615+ a filename exists for the dest, but not source
69616+ do a recreate on dest
69617+ a filename exists for both source and dest
69618+ delete source and dest, then create source and dest
69619+ a filename exists for neither source nor dest
69620+ no updates needed
69621+
69622+ the name entry lookups get us the old inode/dev associated with
69623+ each name, so do the deletes first (if possible) so that when
69624+ we do the create, we pick up on the right entries
69625+ */
69626+
69627+ if (exchange)
69628+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
69629+
69630+ /* we wouldn't have to check d_inode if it weren't for
69631+ NFS silly-renaming
69632+ */
69633+
69634+ write_lock(&gr_inode_lock);
69635+ if (unlikely((replace || exchange) && inode)) {
69636+ ino_t new_ino = inode->i_ino;
69637+ dev_t new_dev = __get_dev(new_dentry);
69638+
69639+ inodev = lookup_inodev_entry(new_ino, new_dev);
69640+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69641+ do_handle_delete(inodev, new_ino, new_dev);
69642+ }
69643+
69644+ inodev = lookup_inodev_entry(old_ino, old_dev);
69645+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69646+ do_handle_delete(inodev, old_ino, old_dev);
69647+
69648+ if (unlikely(matchn != NULL))
69649+ do_handle_create(matchn, old_dentry, mnt);
69650+
69651+ if (unlikely(matchn2 != NULL))
69652+ do_handle_create(matchn2, new_dentry, mnt);
69653+
69654+ write_unlock(&gr_inode_lock);
69655+ preempt_enable();
69656+
69657+ return;
69658+}
69659+
69660+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69661+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69662+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69663+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69664+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69665+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69666+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69667+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69668+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69669+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69670+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69671+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69672+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69673+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69674+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69675+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69676+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69677+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69678+};
69679+
69680+void
69681+gr_learn_resource(const struct task_struct *task,
69682+ const int res, const unsigned long wanted, const int gt)
69683+{
69684+ struct acl_subject_label *acl;
69685+ const struct cred *cred;
69686+
69687+ if (unlikely((gr_status & GR_READY) &&
69688+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69689+ goto skip_reslog;
69690+
69691+ gr_log_resource(task, res, wanted, gt);
69692+skip_reslog:
69693+
69694+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69695+ return;
69696+
69697+ acl = task->acl;
69698+
69699+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69700+ !(acl->resmask & (1U << (unsigned short) res))))
69701+ return;
69702+
69703+ if (wanted >= acl->res[res].rlim_cur) {
69704+ unsigned long res_add;
69705+
69706+ res_add = wanted + res_learn_bumps[res];
69707+
69708+ acl->res[res].rlim_cur = res_add;
69709+
69710+ if (wanted > acl->res[res].rlim_max)
69711+ acl->res[res].rlim_max = res_add;
69712+
69713+ /* only log the subject filename, since resource logging is supported for
69714+ single-subject learning only */
69715+ rcu_read_lock();
69716+ cred = __task_cred(task);
69717+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69718+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69719+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69720+ "", (unsigned long) res, &task->signal->saved_ip);
69721+ rcu_read_unlock();
69722+ }
69723+
69724+ return;
69725+}
69726+EXPORT_SYMBOL_GPL(gr_learn_resource);
69727+#endif
69728+
69729+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69730+void
69731+pax_set_initial_flags(struct linux_binprm *bprm)
69732+{
69733+ struct task_struct *task = current;
69734+ struct acl_subject_label *proc;
69735+ unsigned long flags;
69736+
69737+ if (unlikely(!(gr_status & GR_READY)))
69738+ return;
69739+
69740+ flags = pax_get_flags(task);
69741+
69742+ proc = task->acl;
69743+
69744+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69745+ flags &= ~MF_PAX_PAGEEXEC;
69746+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69747+ flags &= ~MF_PAX_SEGMEXEC;
69748+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69749+ flags &= ~MF_PAX_RANDMMAP;
69750+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69751+ flags &= ~MF_PAX_EMUTRAMP;
69752+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69753+ flags &= ~MF_PAX_MPROTECT;
69754+
69755+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69756+ flags |= MF_PAX_PAGEEXEC;
69757+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69758+ flags |= MF_PAX_SEGMEXEC;
69759+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69760+ flags |= MF_PAX_RANDMMAP;
69761+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69762+ flags |= MF_PAX_EMUTRAMP;
69763+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69764+ flags |= MF_PAX_MPROTECT;
69765+
69766+ pax_set_flags(task, flags);
69767+
69768+ return;
69769+}
69770+#endif
69771+
69772+int
69773+gr_handle_proc_ptrace(struct task_struct *task)
69774+{
69775+ struct file *filp;
69776+ struct task_struct *tmp = task;
69777+ struct task_struct *curtemp = current;
69778+ __u32 retmode;
69779+
69780+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69781+ if (unlikely(!(gr_status & GR_READY)))
69782+ return 0;
69783+#endif
69784+
69785+ read_lock(&tasklist_lock);
69786+ read_lock(&grsec_exec_file_lock);
69787+ filp = task->exec_file;
69788+
69789+ while (task_pid_nr(tmp) > 0) {
69790+ if (tmp == curtemp)
69791+ break;
69792+ tmp = tmp->real_parent;
69793+ }
69794+
69795+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69796+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69797+ read_unlock(&grsec_exec_file_lock);
69798+ read_unlock(&tasklist_lock);
69799+ return 1;
69800+ }
69801+
69802+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69803+ if (!(gr_status & GR_READY)) {
69804+ read_unlock(&grsec_exec_file_lock);
69805+ read_unlock(&tasklist_lock);
69806+ return 0;
69807+ }
69808+#endif
69809+
69810+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69811+ read_unlock(&grsec_exec_file_lock);
69812+ read_unlock(&tasklist_lock);
69813+
69814+ if (retmode & GR_NOPTRACE)
69815+ return 1;
69816+
69817+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69818+ && (current->acl != task->acl || (current->acl != current->role->root_label
69819+ && task_pid_nr(current) != task_pid_nr(task))))
69820+ return 1;
69821+
69822+ return 0;
69823+}
69824+
69825+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69826+{
69827+ if (unlikely(!(gr_status & GR_READY)))
69828+ return;
69829+
69830+ if (!(current->role->roletype & GR_ROLE_GOD))
69831+ return;
69832+
69833+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69834+ p->role->rolename, gr_task_roletype_to_char(p),
69835+ p->acl->filename);
69836+}
69837+
69838+int
69839+gr_handle_ptrace(struct task_struct *task, const long request)
69840+{
69841+ struct task_struct *tmp = task;
69842+ struct task_struct *curtemp = current;
69843+ __u32 retmode;
69844+
69845+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69846+ if (unlikely(!(gr_status & GR_READY)))
69847+ return 0;
69848+#endif
69849+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69850+ read_lock(&tasklist_lock);
69851+ while (task_pid_nr(tmp) > 0) {
69852+ if (tmp == curtemp)
69853+ break;
69854+ tmp = tmp->real_parent;
69855+ }
69856+
69857+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69858+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69859+ read_unlock(&tasklist_lock);
69860+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69861+ return 1;
69862+ }
69863+ read_unlock(&tasklist_lock);
69864+ }
69865+
69866+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69867+ if (!(gr_status & GR_READY))
69868+ return 0;
69869+#endif
69870+
69871+ read_lock(&grsec_exec_file_lock);
69872+ if (unlikely(!task->exec_file)) {
69873+ read_unlock(&grsec_exec_file_lock);
69874+ return 0;
69875+ }
69876+
69877+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69878+ read_unlock(&grsec_exec_file_lock);
69879+
69880+ if (retmode & GR_NOPTRACE) {
69881+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69882+ return 1;
69883+ }
69884+
69885+ if (retmode & GR_PTRACERD) {
69886+ switch (request) {
69887+ case PTRACE_SEIZE:
69888+ case PTRACE_POKETEXT:
69889+ case PTRACE_POKEDATA:
69890+ case PTRACE_POKEUSR:
69891+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69892+ case PTRACE_SETREGS:
69893+ case PTRACE_SETFPREGS:
69894+#endif
69895+#ifdef CONFIG_X86
69896+ case PTRACE_SETFPXREGS:
69897+#endif
69898+#ifdef CONFIG_ALTIVEC
69899+ case PTRACE_SETVRREGS:
69900+#endif
69901+ return 1;
69902+ default:
69903+ return 0;
69904+ }
69905+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69906+ !(current->role->roletype & GR_ROLE_GOD) &&
69907+ (current->acl != task->acl)) {
69908+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69909+ return 1;
69910+ }
69911+
69912+ return 0;
69913+}
69914+
69915+static int is_writable_mmap(const struct file *filp)
69916+{
69917+ struct task_struct *task = current;
69918+ struct acl_object_label *obj, *obj2;
69919+
69920+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69921+ !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))) {
69922+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69923+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69924+ task->role->root_label);
69925+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69926+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69927+ return 1;
69928+ }
69929+ }
69930+ return 0;
69931+}
69932+
69933+int
69934+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69935+{
69936+ __u32 mode;
69937+
69938+ if (unlikely(!file || !(prot & PROT_EXEC)))
69939+ return 1;
69940+
69941+ if (is_writable_mmap(file))
69942+ return 0;
69943+
69944+ mode =
69945+ gr_search_file(file->f_path.dentry,
69946+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69947+ file->f_path.mnt);
69948+
69949+ if (!gr_tpe_allow(file))
69950+ return 0;
69951+
69952+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69953+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69954+ return 0;
69955+ } else if (unlikely(!(mode & GR_EXEC))) {
69956+ return 0;
69957+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69958+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69959+ return 1;
69960+ }
69961+
69962+ return 1;
69963+}
69964+
69965+int
69966+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69967+{
69968+ __u32 mode;
69969+
69970+ if (unlikely(!file || !(prot & PROT_EXEC)))
69971+ return 1;
69972+
69973+ if (is_writable_mmap(file))
69974+ return 0;
69975+
69976+ mode =
69977+ gr_search_file(file->f_path.dentry,
69978+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69979+ file->f_path.mnt);
69980+
69981+ if (!gr_tpe_allow(file))
69982+ return 0;
69983+
69984+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69985+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69986+ return 0;
69987+ } else if (unlikely(!(mode & GR_EXEC))) {
69988+ return 0;
69989+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69990+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69991+ return 1;
69992+ }
69993+
69994+ return 1;
69995+}
69996+
69997+void
69998+gr_acl_handle_psacct(struct task_struct *task, const long code)
69999+{
70000+ unsigned long runtime, cputime;
70001+ cputime_t utime, stime;
70002+ unsigned int wday, cday;
70003+ __u8 whr, chr;
70004+ __u8 wmin, cmin;
70005+ __u8 wsec, csec;
70006+ struct timespec timeval;
70007+
70008+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
70009+ !(task->acl->mode & GR_PROCACCT)))
70010+ return;
70011+
70012+ do_posix_clock_monotonic_gettime(&timeval);
70013+ runtime = timeval.tv_sec - task->start_time.tv_sec;
70014+ wday = runtime / (60 * 60 * 24);
70015+ runtime -= wday * (60 * 60 * 24);
70016+ whr = runtime / (60 * 60);
70017+ runtime -= whr * (60 * 60);
70018+ wmin = runtime / 60;
70019+ runtime -= wmin * 60;
70020+ wsec = runtime;
70021+
70022+ task_cputime(task, &utime, &stime);
70023+ cputime = cputime_to_secs(utime + stime);
70024+ cday = cputime / (60 * 60 * 24);
70025+ cputime -= cday * (60 * 60 * 24);
70026+ chr = cputime / (60 * 60);
70027+ cputime -= chr * (60 * 60);
70028+ cmin = cputime / 60;
70029+ cputime -= cmin * 60;
70030+ csec = cputime;
70031+
70032+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
70033+
70034+ return;
70035+}
70036+
70037+#ifdef CONFIG_TASKSTATS
70038+int gr_is_taskstats_denied(int pid)
70039+{
70040+ struct task_struct *task;
70041+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70042+ const struct cred *cred;
70043+#endif
70044+ int ret = 0;
70045+
70046+ /* restrict taskstats viewing to un-chrooted root users
70047+ who have the 'view' subject flag if the RBAC system is enabled
70048+ */
70049+
70050+ rcu_read_lock();
70051+ read_lock(&tasklist_lock);
70052+ task = find_task_by_vpid(pid);
70053+ if (task) {
70054+#ifdef CONFIG_GRKERNSEC_CHROOT
70055+ if (proc_is_chrooted(task))
70056+ ret = -EACCES;
70057+#endif
70058+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70059+ cred = __task_cred(task);
70060+#ifdef CONFIG_GRKERNSEC_PROC_USER
70061+ if (gr_is_global_nonroot(cred->uid))
70062+ ret = -EACCES;
70063+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70064+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
70065+ ret = -EACCES;
70066+#endif
70067+#endif
70068+ if (gr_status & GR_READY) {
70069+ if (!(task->acl->mode & GR_VIEW))
70070+ ret = -EACCES;
70071+ }
70072+ } else
70073+ ret = -ENOENT;
70074+
70075+ read_unlock(&tasklist_lock);
70076+ rcu_read_unlock();
70077+
70078+ return ret;
70079+}
70080+#endif
70081+
70082+/* AUXV entries are filled via a descendant of search_binary_handler
70083+ after we've already applied the subject for the target
70084+*/
70085+int gr_acl_enable_at_secure(void)
70086+{
70087+ if (unlikely(!(gr_status & GR_READY)))
70088+ return 0;
70089+
70090+ if (current->acl->mode & GR_ATSECURE)
70091+ return 1;
70092+
70093+ return 0;
70094+}
70095+
70096+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
70097+{
70098+ struct task_struct *task = current;
70099+ struct dentry *dentry = file->f_path.dentry;
70100+ struct vfsmount *mnt = file->f_path.mnt;
70101+ struct acl_object_label *obj, *tmp;
70102+ struct acl_subject_label *subj;
70103+ unsigned int bufsize;
70104+ int is_not_root;
70105+ char *path;
70106+ dev_t dev = __get_dev(dentry);
70107+
70108+ if (unlikely(!(gr_status & GR_READY)))
70109+ return 1;
70110+
70111+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
70112+ return 1;
70113+
70114+ /* ignore Eric Biederman */
70115+ if (IS_PRIVATE(dentry->d_inode))
70116+ return 1;
70117+
70118+ subj = task->acl;
70119+ read_lock(&gr_inode_lock);
70120+ do {
70121+ obj = lookup_acl_obj_label(ino, dev, subj);
70122+ if (obj != NULL) {
70123+ read_unlock(&gr_inode_lock);
70124+ return (obj->mode & GR_FIND) ? 1 : 0;
70125+ }
70126+ } while ((subj = subj->parent_subject));
70127+ read_unlock(&gr_inode_lock);
70128+
70129+ /* this is purely an optimization since we're looking for an object
70130+ for the directory we're doing a readdir on
70131+ if it's possible for any globbed object to match the entry we're
70132+ filling into the directory, then the object we find here will be
70133+ an anchor point with attached globbed objects
70134+ */
70135+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
70136+ if (obj->globbed == NULL)
70137+ return (obj->mode & GR_FIND) ? 1 : 0;
70138+
70139+ is_not_root = ((obj->filename[0] == '/') &&
70140+ (obj->filename[1] == '\0')) ? 0 : 1;
70141+ bufsize = PAGE_SIZE - namelen - is_not_root;
70142+
70143+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
70144+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
70145+ return 1;
70146+
70147+ preempt_disable();
70148+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
70149+ bufsize);
70150+
70151+ bufsize = strlen(path);
70152+
70153+ /* if base is "/", don't append an additional slash */
70154+ if (is_not_root)
70155+ *(path + bufsize) = '/';
70156+ memcpy(path + bufsize + is_not_root, name, namelen);
70157+ *(path + bufsize + namelen + is_not_root) = '\0';
70158+
70159+ tmp = obj->globbed;
70160+ while (tmp) {
70161+ if (!glob_match(tmp->filename, path)) {
70162+ preempt_enable();
70163+ return (tmp->mode & GR_FIND) ? 1 : 0;
70164+ }
70165+ tmp = tmp->next;
70166+ }
70167+ preempt_enable();
70168+ return (obj->mode & GR_FIND) ? 1 : 0;
70169+}
70170+
70171+void gr_put_exec_file(struct task_struct *task)
70172+{
70173+ struct file *filp;
70174+
70175+ write_lock(&grsec_exec_file_lock);
70176+ filp = task->exec_file;
70177+ task->exec_file = NULL;
70178+ write_unlock(&grsec_exec_file_lock);
70179+
70180+ if (filp)
70181+ fput(filp);
70182+
70183+ return;
70184+}
70185+
70186+
70187+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
70188+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
70189+#endif
70190+#ifdef CONFIG_SECURITY
70191+EXPORT_SYMBOL_GPL(gr_check_user_change);
70192+EXPORT_SYMBOL_GPL(gr_check_group_change);
70193+#endif
70194+
70195diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
70196new file mode 100644
70197index 0000000..18ffbbd
70198--- /dev/null
70199+++ b/grsecurity/gracl_alloc.c
70200@@ -0,0 +1,105 @@
70201+#include <linux/kernel.h>
70202+#include <linux/mm.h>
70203+#include <linux/slab.h>
70204+#include <linux/vmalloc.h>
70205+#include <linux/gracl.h>
70206+#include <linux/grsecurity.h>
70207+
70208+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
70209+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
70210+
70211+static __inline__ int
70212+alloc_pop(void)
70213+{
70214+ if (current_alloc_state->alloc_stack_next == 1)
70215+ return 0;
70216+
70217+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
70218+
70219+ current_alloc_state->alloc_stack_next--;
70220+
70221+ return 1;
70222+}
70223+
70224+static __inline__ int
70225+alloc_push(void *buf)
70226+{
70227+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
70228+ return 1;
70229+
70230+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
70231+
70232+ current_alloc_state->alloc_stack_next++;
70233+
70234+ return 0;
70235+}
70236+
70237+void *
70238+acl_alloc(unsigned long len)
70239+{
70240+ void *ret = NULL;
70241+
70242+ if (!len || len > PAGE_SIZE)
70243+ goto out;
70244+
70245+ ret = kmalloc(len, GFP_KERNEL);
70246+
70247+ if (ret) {
70248+ if (alloc_push(ret)) {
70249+ kfree(ret);
70250+ ret = NULL;
70251+ }
70252+ }
70253+
70254+out:
70255+ return ret;
70256+}
70257+
70258+void *
70259+acl_alloc_num(unsigned long num, unsigned long len)
70260+{
70261+ if (!len || (num > (PAGE_SIZE / len)))
70262+ return NULL;
70263+
70264+ return acl_alloc(num * len);
70265+}
70266+
70267+void
70268+acl_free_all(void)
70269+{
70270+ if (!current_alloc_state->alloc_stack)
70271+ return;
70272+
70273+ while (alloc_pop()) ;
70274+
70275+ if (current_alloc_state->alloc_stack) {
70276+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
70277+ kfree(current_alloc_state->alloc_stack);
70278+ else
70279+ vfree(current_alloc_state->alloc_stack);
70280+ }
70281+
70282+ current_alloc_state->alloc_stack = NULL;
70283+ current_alloc_state->alloc_stack_size = 1;
70284+ current_alloc_state->alloc_stack_next = 1;
70285+
70286+ return;
70287+}
70288+
70289+int
70290+acl_alloc_stack_init(unsigned long size)
70291+{
70292+ if ((size * sizeof (void *)) <= PAGE_SIZE)
70293+ current_alloc_state->alloc_stack =
70294+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
70295+ else
70296+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
70297+
70298+ current_alloc_state->alloc_stack_size = size;
70299+ current_alloc_state->alloc_stack_next = 1;
70300+
70301+ if (!current_alloc_state->alloc_stack)
70302+ return 0;
70303+ else
70304+ return 1;
70305+}
70306diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
70307new file mode 100644
70308index 0000000..bdd51ea
70309--- /dev/null
70310+++ b/grsecurity/gracl_cap.c
70311@@ -0,0 +1,110 @@
70312+#include <linux/kernel.h>
70313+#include <linux/module.h>
70314+#include <linux/sched.h>
70315+#include <linux/gracl.h>
70316+#include <linux/grsecurity.h>
70317+#include <linux/grinternal.h>
70318+
70319+extern const char *captab_log[];
70320+extern int captab_log_entries;
70321+
70322+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70323+{
70324+ struct acl_subject_label *curracl;
70325+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70326+ kernel_cap_t cap_audit = __cap_empty_set;
70327+
70328+ if (!gr_acl_is_enabled())
70329+ return 1;
70330+
70331+ curracl = task->acl;
70332+
70333+ cap_drop = curracl->cap_lower;
70334+ cap_mask = curracl->cap_mask;
70335+ cap_audit = curracl->cap_invert_audit;
70336+
70337+ while ((curracl = curracl->parent_subject)) {
70338+ /* if the cap isn't specified in the current computed mask but is specified in the
70339+ current level subject, and is lowered in the current level subject, then add
70340+ it to the set of dropped capabilities
70341+ otherwise, add the current level subject's mask to the current computed mask
70342+ */
70343+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70344+ cap_raise(cap_mask, cap);
70345+ if (cap_raised(curracl->cap_lower, cap))
70346+ cap_raise(cap_drop, cap);
70347+ if (cap_raised(curracl->cap_invert_audit, cap))
70348+ cap_raise(cap_audit, cap);
70349+ }
70350+ }
70351+
70352+ if (!cap_raised(cap_drop, cap)) {
70353+ if (cap_raised(cap_audit, cap))
70354+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
70355+ return 1;
70356+ }
70357+
70358+ curracl = task->acl;
70359+
70360+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
70361+ && cap_raised(cred->cap_effective, cap)) {
70362+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
70363+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
70364+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
70365+ gr_to_filename(task->exec_file->f_path.dentry,
70366+ task->exec_file->f_path.mnt) : curracl->filename,
70367+ curracl->filename, 0UL,
70368+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
70369+ return 1;
70370+ }
70371+
70372+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
70373+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
70374+
70375+ return 0;
70376+}
70377+
70378+int
70379+gr_acl_is_capable(const int cap)
70380+{
70381+ return gr_task_acl_is_capable(current, current_cred(), cap);
70382+}
70383+
70384+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
70385+{
70386+ struct acl_subject_label *curracl;
70387+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70388+
70389+ if (!gr_acl_is_enabled())
70390+ return 1;
70391+
70392+ curracl = task->acl;
70393+
70394+ cap_drop = curracl->cap_lower;
70395+ cap_mask = curracl->cap_mask;
70396+
70397+ while ((curracl = curracl->parent_subject)) {
70398+ /* if the cap isn't specified in the current computed mask but is specified in the
70399+ current level subject, and is lowered in the current level subject, then add
70400+ it to the set of dropped capabilities
70401+ otherwise, add the current level subject's mask to the current computed mask
70402+ */
70403+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70404+ cap_raise(cap_mask, cap);
70405+ if (cap_raised(curracl->cap_lower, cap))
70406+ cap_raise(cap_drop, cap);
70407+ }
70408+ }
70409+
70410+ if (!cap_raised(cap_drop, cap))
70411+ return 1;
70412+
70413+ return 0;
70414+}
70415+
70416+int
70417+gr_acl_is_capable_nolog(const int cap)
70418+{
70419+ return gr_task_acl_is_capable_nolog(current, cap);
70420+}
70421+
70422diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70423new file mode 100644
70424index 0000000..ca25605
70425--- /dev/null
70426+++ b/grsecurity/gracl_compat.c
70427@@ -0,0 +1,270 @@
70428+#include <linux/kernel.h>
70429+#include <linux/gracl.h>
70430+#include <linux/compat.h>
70431+#include <linux/gracl_compat.h>
70432+
70433+#include <asm/uaccess.h>
70434+
70435+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70436+{
70437+ struct gr_arg_wrapper_compat uwrapcompat;
70438+
70439+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70440+ return -EFAULT;
70441+
70442+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70443+ (uwrapcompat.version != 0x2901)) ||
70444+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70445+ return -EINVAL;
70446+
70447+ uwrap->arg = compat_ptr(uwrapcompat.arg);
70448+ uwrap->version = uwrapcompat.version;
70449+ uwrap->size = sizeof(struct gr_arg);
70450+
70451+ return 0;
70452+}
70453+
70454+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70455+{
70456+ struct gr_arg_compat argcompat;
70457+
70458+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70459+ return -EFAULT;
70460+
70461+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70462+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70463+ arg->role_db.num_roles = argcompat.role_db.num_roles;
70464+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70465+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70466+ arg->role_db.num_objects = argcompat.role_db.num_objects;
70467+
70468+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70469+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70470+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70471+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70472+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70473+ arg->segv_device = argcompat.segv_device;
70474+ arg->segv_inode = argcompat.segv_inode;
70475+ arg->segv_uid = argcompat.segv_uid;
70476+ arg->num_sprole_pws = argcompat.num_sprole_pws;
70477+ arg->mode = argcompat.mode;
70478+
70479+ return 0;
70480+}
70481+
70482+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70483+{
70484+ struct acl_object_label_compat objcompat;
70485+
70486+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70487+ return -EFAULT;
70488+
70489+ obj->filename = compat_ptr(objcompat.filename);
70490+ obj->inode = objcompat.inode;
70491+ obj->device = objcompat.device;
70492+ obj->mode = objcompat.mode;
70493+
70494+ obj->nested = compat_ptr(objcompat.nested);
70495+ obj->globbed = compat_ptr(objcompat.globbed);
70496+
70497+ obj->prev = compat_ptr(objcompat.prev);
70498+ obj->next = compat_ptr(objcompat.next);
70499+
70500+ return 0;
70501+}
70502+
70503+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70504+{
70505+ unsigned int i;
70506+ struct acl_subject_label_compat subjcompat;
70507+
70508+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70509+ return -EFAULT;
70510+
70511+ subj->filename = compat_ptr(subjcompat.filename);
70512+ subj->inode = subjcompat.inode;
70513+ subj->device = subjcompat.device;
70514+ subj->mode = subjcompat.mode;
70515+ subj->cap_mask = subjcompat.cap_mask;
70516+ subj->cap_lower = subjcompat.cap_lower;
70517+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
70518+
70519+ for (i = 0; i < GR_NLIMITS; i++) {
70520+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70521+ subj->res[i].rlim_cur = RLIM_INFINITY;
70522+ else
70523+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70524+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70525+ subj->res[i].rlim_max = RLIM_INFINITY;
70526+ else
70527+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70528+ }
70529+ subj->resmask = subjcompat.resmask;
70530+
70531+ subj->user_trans_type = subjcompat.user_trans_type;
70532+ subj->group_trans_type = subjcompat.group_trans_type;
70533+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70534+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70535+ subj->user_trans_num = subjcompat.user_trans_num;
70536+ subj->group_trans_num = subjcompat.group_trans_num;
70537+
70538+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70539+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70540+ subj->ip_type = subjcompat.ip_type;
70541+ subj->ips = compat_ptr(subjcompat.ips);
70542+ subj->ip_num = subjcompat.ip_num;
70543+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
70544+
70545+ subj->crashes = subjcompat.crashes;
70546+ subj->expires = subjcompat.expires;
70547+
70548+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70549+ subj->hash = compat_ptr(subjcompat.hash);
70550+ subj->prev = compat_ptr(subjcompat.prev);
70551+ subj->next = compat_ptr(subjcompat.next);
70552+
70553+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70554+ subj->obj_hash_size = subjcompat.obj_hash_size;
70555+ subj->pax_flags = subjcompat.pax_flags;
70556+
70557+ return 0;
70558+}
70559+
70560+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70561+{
70562+ struct acl_role_label_compat rolecompat;
70563+
70564+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70565+ return -EFAULT;
70566+
70567+ role->rolename = compat_ptr(rolecompat.rolename);
70568+ role->uidgid = rolecompat.uidgid;
70569+ role->roletype = rolecompat.roletype;
70570+
70571+ role->auth_attempts = rolecompat.auth_attempts;
70572+ role->expires = rolecompat.expires;
70573+
70574+ role->root_label = compat_ptr(rolecompat.root_label);
70575+ role->hash = compat_ptr(rolecompat.hash);
70576+
70577+ role->prev = compat_ptr(rolecompat.prev);
70578+ role->next = compat_ptr(rolecompat.next);
70579+
70580+ role->transitions = compat_ptr(rolecompat.transitions);
70581+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70582+ role->domain_children = compat_ptr(rolecompat.domain_children);
70583+ role->domain_child_num = rolecompat.domain_child_num;
70584+
70585+ role->umask = rolecompat.umask;
70586+
70587+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
70588+ role->subj_hash_size = rolecompat.subj_hash_size;
70589+
70590+ return 0;
70591+}
70592+
70593+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70594+{
70595+ struct role_allowed_ip_compat roleip_compat;
70596+
70597+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70598+ return -EFAULT;
70599+
70600+ roleip->addr = roleip_compat.addr;
70601+ roleip->netmask = roleip_compat.netmask;
70602+
70603+ roleip->prev = compat_ptr(roleip_compat.prev);
70604+ roleip->next = compat_ptr(roleip_compat.next);
70605+
70606+ return 0;
70607+}
70608+
70609+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70610+{
70611+ struct role_transition_compat trans_compat;
70612+
70613+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70614+ return -EFAULT;
70615+
70616+ trans->rolename = compat_ptr(trans_compat.rolename);
70617+
70618+ trans->prev = compat_ptr(trans_compat.prev);
70619+ trans->next = compat_ptr(trans_compat.next);
70620+
70621+ return 0;
70622+
70623+}
70624+
70625+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70626+{
70627+ struct gr_hash_struct_compat hash_compat;
70628+
70629+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70630+ return -EFAULT;
70631+
70632+ hash->table = compat_ptr(hash_compat.table);
70633+ hash->nametable = compat_ptr(hash_compat.nametable);
70634+ hash->first = compat_ptr(hash_compat.first);
70635+
70636+ hash->table_size = hash_compat.table_size;
70637+ hash->used_size = hash_compat.used_size;
70638+
70639+ hash->type = hash_compat.type;
70640+
70641+ return 0;
70642+}
70643+
70644+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70645+{
70646+ compat_uptr_t ptrcompat;
70647+
70648+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70649+ return -EFAULT;
70650+
70651+ *(void **)ptr = compat_ptr(ptrcompat);
70652+
70653+ return 0;
70654+}
70655+
70656+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70657+{
70658+ struct acl_ip_label_compat ip_compat;
70659+
70660+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70661+ return -EFAULT;
70662+
70663+ ip->iface = compat_ptr(ip_compat.iface);
70664+ ip->addr = ip_compat.addr;
70665+ ip->netmask = ip_compat.netmask;
70666+ ip->low = ip_compat.low;
70667+ ip->high = ip_compat.high;
70668+ ip->mode = ip_compat.mode;
70669+ ip->type = ip_compat.type;
70670+
70671+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70672+
70673+ ip->prev = compat_ptr(ip_compat.prev);
70674+ ip->next = compat_ptr(ip_compat.next);
70675+
70676+ return 0;
70677+}
70678+
70679+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70680+{
70681+ struct sprole_pw_compat pw_compat;
70682+
70683+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70684+ return -EFAULT;
70685+
70686+ pw->rolename = compat_ptr(pw_compat.rolename);
70687+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70688+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70689+
70690+ return 0;
70691+}
70692+
70693+size_t get_gr_arg_wrapper_size_compat(void)
70694+{
70695+ return sizeof(struct gr_arg_wrapper_compat);
70696+}
70697+
70698diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70699new file mode 100644
70700index 0000000..4008fdc
70701--- /dev/null
70702+++ b/grsecurity/gracl_fs.c
70703@@ -0,0 +1,445 @@
70704+#include <linux/kernel.h>
70705+#include <linux/sched.h>
70706+#include <linux/types.h>
70707+#include <linux/fs.h>
70708+#include <linux/file.h>
70709+#include <linux/stat.h>
70710+#include <linux/grsecurity.h>
70711+#include <linux/grinternal.h>
70712+#include <linux/gracl.h>
70713+
70714+umode_t
70715+gr_acl_umask(void)
70716+{
70717+ if (unlikely(!gr_acl_is_enabled()))
70718+ return 0;
70719+
70720+ return current->role->umask;
70721+}
70722+
70723+__u32
70724+gr_acl_handle_hidden_file(const struct dentry * dentry,
70725+ const struct vfsmount * mnt)
70726+{
70727+ __u32 mode;
70728+
70729+ if (unlikely(d_is_negative(dentry)))
70730+ return GR_FIND;
70731+
70732+ mode =
70733+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70734+
70735+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70736+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70737+ return mode;
70738+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70739+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70740+ return 0;
70741+ } else if (unlikely(!(mode & GR_FIND)))
70742+ return 0;
70743+
70744+ return GR_FIND;
70745+}
70746+
70747+__u32
70748+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70749+ int acc_mode)
70750+{
70751+ __u32 reqmode = GR_FIND;
70752+ __u32 mode;
70753+
70754+ if (unlikely(d_is_negative(dentry)))
70755+ return reqmode;
70756+
70757+ if (acc_mode & MAY_APPEND)
70758+ reqmode |= GR_APPEND;
70759+ else if (acc_mode & MAY_WRITE)
70760+ reqmode |= GR_WRITE;
70761+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70762+ reqmode |= GR_READ;
70763+
70764+ mode =
70765+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70766+ mnt);
70767+
70768+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70769+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70770+ reqmode & GR_READ ? " reading" : "",
70771+ reqmode & GR_WRITE ? " writing" : reqmode &
70772+ GR_APPEND ? " appending" : "");
70773+ return reqmode;
70774+ } else
70775+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70776+ {
70777+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70778+ reqmode & GR_READ ? " reading" : "",
70779+ reqmode & GR_WRITE ? " writing" : reqmode &
70780+ GR_APPEND ? " appending" : "");
70781+ return 0;
70782+ } else if (unlikely((mode & reqmode) != reqmode))
70783+ return 0;
70784+
70785+ return reqmode;
70786+}
70787+
70788+__u32
70789+gr_acl_handle_creat(const struct dentry * dentry,
70790+ const struct dentry * p_dentry,
70791+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70792+ const int imode)
70793+{
70794+ __u32 reqmode = GR_WRITE | GR_CREATE;
70795+ __u32 mode;
70796+
70797+ if (acc_mode & MAY_APPEND)
70798+ reqmode |= GR_APPEND;
70799+ // if a directory was required or the directory already exists, then
70800+ // don't count this open as a read
70801+ if ((acc_mode & MAY_READ) &&
70802+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70803+ reqmode |= GR_READ;
70804+ if ((open_flags & O_CREAT) &&
70805+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70806+ reqmode |= GR_SETID;
70807+
70808+ mode =
70809+ gr_check_create(dentry, p_dentry, p_mnt,
70810+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70811+
70812+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70813+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70814+ reqmode & GR_READ ? " reading" : "",
70815+ reqmode & GR_WRITE ? " writing" : reqmode &
70816+ GR_APPEND ? " appending" : "");
70817+ return reqmode;
70818+ } else
70819+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70820+ {
70821+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70822+ reqmode & GR_READ ? " reading" : "",
70823+ reqmode & GR_WRITE ? " writing" : reqmode &
70824+ GR_APPEND ? " appending" : "");
70825+ return 0;
70826+ } else if (unlikely((mode & reqmode) != reqmode))
70827+ return 0;
70828+
70829+ return reqmode;
70830+}
70831+
70832+__u32
70833+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70834+ const int fmode)
70835+{
70836+ __u32 mode, reqmode = GR_FIND;
70837+
70838+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70839+ reqmode |= GR_EXEC;
70840+ if (fmode & S_IWOTH)
70841+ reqmode |= GR_WRITE;
70842+ if (fmode & S_IROTH)
70843+ reqmode |= GR_READ;
70844+
70845+ mode =
70846+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70847+ mnt);
70848+
70849+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70850+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70851+ reqmode & GR_READ ? " reading" : "",
70852+ reqmode & GR_WRITE ? " writing" : "",
70853+ reqmode & GR_EXEC ? " executing" : "");
70854+ return reqmode;
70855+ } else
70856+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70857+ {
70858+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70859+ reqmode & GR_READ ? " reading" : "",
70860+ reqmode & GR_WRITE ? " writing" : "",
70861+ reqmode & GR_EXEC ? " executing" : "");
70862+ return 0;
70863+ } else if (unlikely((mode & reqmode) != reqmode))
70864+ return 0;
70865+
70866+ return reqmode;
70867+}
70868+
70869+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70870+{
70871+ __u32 mode;
70872+
70873+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70874+
70875+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70876+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70877+ return mode;
70878+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70879+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70880+ return 0;
70881+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70882+ return 0;
70883+
70884+ return (reqmode);
70885+}
70886+
70887+__u32
70888+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70889+{
70890+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70891+}
70892+
70893+__u32
70894+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70895+{
70896+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70897+}
70898+
70899+__u32
70900+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70901+{
70902+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70903+}
70904+
70905+__u32
70906+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70907+{
70908+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70909+}
70910+
70911+__u32
70912+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70913+ umode_t *modeptr)
70914+{
70915+ umode_t mode;
70916+
70917+ *modeptr &= ~gr_acl_umask();
70918+ mode = *modeptr;
70919+
70920+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70921+ return 1;
70922+
70923+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70924+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70925+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70926+ GR_CHMOD_ACL_MSG);
70927+ } else {
70928+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70929+ }
70930+}
70931+
70932+__u32
70933+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70934+{
70935+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70936+}
70937+
70938+__u32
70939+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70940+{
70941+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70942+}
70943+
70944+__u32
70945+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70946+{
70947+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70948+}
70949+
70950+__u32
70951+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70952+{
70953+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70954+}
70955+
70956+__u32
70957+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70958+{
70959+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70960+ GR_UNIXCONNECT_ACL_MSG);
70961+}
70962+
70963+/* hardlinks require at minimum create and link permission,
70964+ any additional privilege required is based on the
70965+ privilege of the file being linked to
70966+*/
70967+__u32
70968+gr_acl_handle_link(const struct dentry * new_dentry,
70969+ const struct dentry * parent_dentry,
70970+ const struct vfsmount * parent_mnt,
70971+ const struct dentry * old_dentry,
70972+ const struct vfsmount * old_mnt, const struct filename *to)
70973+{
70974+ __u32 mode;
70975+ __u32 needmode = GR_CREATE | GR_LINK;
70976+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70977+
70978+ mode =
70979+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70980+ old_mnt);
70981+
70982+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70983+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70984+ return mode;
70985+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70986+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70987+ return 0;
70988+ } else if (unlikely((mode & needmode) != needmode))
70989+ return 0;
70990+
70991+ return 1;
70992+}
70993+
70994+__u32
70995+gr_acl_handle_symlink(const struct dentry * new_dentry,
70996+ const struct dentry * parent_dentry,
70997+ const struct vfsmount * parent_mnt, const struct filename *from)
70998+{
70999+ __u32 needmode = GR_WRITE | GR_CREATE;
71000+ __u32 mode;
71001+
71002+ mode =
71003+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
71004+ GR_CREATE | GR_AUDIT_CREATE |
71005+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
71006+
71007+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
71008+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
71009+ return mode;
71010+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
71011+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
71012+ return 0;
71013+ } else if (unlikely((mode & needmode) != needmode))
71014+ return 0;
71015+
71016+ return (GR_WRITE | GR_CREATE);
71017+}
71018+
71019+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)
71020+{
71021+ __u32 mode;
71022+
71023+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
71024+
71025+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
71026+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
71027+ return mode;
71028+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
71029+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
71030+ return 0;
71031+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
71032+ return 0;
71033+
71034+ return (reqmode);
71035+}
71036+
71037+__u32
71038+gr_acl_handle_mknod(const struct dentry * new_dentry,
71039+ const struct dentry * parent_dentry,
71040+ const struct vfsmount * parent_mnt,
71041+ const int mode)
71042+{
71043+ __u32 reqmode = GR_WRITE | GR_CREATE;
71044+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
71045+ reqmode |= GR_SETID;
71046+
71047+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
71048+ reqmode, GR_MKNOD_ACL_MSG);
71049+}
71050+
71051+__u32
71052+gr_acl_handle_mkdir(const struct dentry *new_dentry,
71053+ const struct dentry *parent_dentry,
71054+ const struct vfsmount *parent_mnt)
71055+{
71056+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
71057+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
71058+}
71059+
71060+#define RENAME_CHECK_SUCCESS(old, new) \
71061+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
71062+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
71063+
71064+int
71065+gr_acl_handle_rename(struct dentry *new_dentry,
71066+ struct dentry *parent_dentry,
71067+ const struct vfsmount *parent_mnt,
71068+ struct dentry *old_dentry,
71069+ struct inode *old_parent_inode,
71070+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
71071+{
71072+ __u32 comp1, comp2;
71073+ int error = 0;
71074+
71075+ if (unlikely(!gr_acl_is_enabled()))
71076+ return 0;
71077+
71078+ if (flags & RENAME_EXCHANGE) {
71079+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
71080+ GR_AUDIT_READ | GR_AUDIT_WRITE |
71081+ GR_SUPPRESS, parent_mnt);
71082+ comp2 =
71083+ gr_search_file(old_dentry,
71084+ GR_READ | GR_WRITE | GR_AUDIT_READ |
71085+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
71086+ } else if (d_is_negative(new_dentry)) {
71087+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
71088+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
71089+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
71090+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
71091+ GR_DELETE | GR_AUDIT_DELETE |
71092+ GR_AUDIT_READ | GR_AUDIT_WRITE |
71093+ GR_SUPPRESS, old_mnt);
71094+ } else {
71095+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
71096+ GR_CREATE | GR_DELETE |
71097+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
71098+ GR_AUDIT_READ | GR_AUDIT_WRITE |
71099+ GR_SUPPRESS, parent_mnt);
71100+ comp2 =
71101+ gr_search_file(old_dentry,
71102+ GR_READ | GR_WRITE | GR_AUDIT_READ |
71103+ GR_DELETE | GR_AUDIT_DELETE |
71104+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
71105+ }
71106+
71107+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
71108+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
71109+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
71110+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
71111+ && !(comp2 & GR_SUPPRESS)) {
71112+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
71113+ error = -EACCES;
71114+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
71115+ error = -EACCES;
71116+
71117+ return error;
71118+}
71119+
71120+void
71121+gr_acl_handle_exit(void)
71122+{
71123+ u16 id;
71124+ char *rolename;
71125+
71126+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
71127+ !(current->role->roletype & GR_ROLE_PERSIST))) {
71128+ id = current->acl_role_id;
71129+ rolename = current->role->rolename;
71130+ gr_set_acls(1);
71131+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
71132+ }
71133+
71134+ gr_put_exec_file(current);
71135+ return;
71136+}
71137+
71138+int
71139+gr_acl_handle_procpidmem(const struct task_struct *task)
71140+{
71141+ if (unlikely(!gr_acl_is_enabled()))
71142+ return 0;
71143+
71144+ if (task != current && task->acl->mode & GR_PROTPROCFD)
71145+ return -EACCES;
71146+
71147+ return 0;
71148+}
71149diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
71150new file mode 100644
71151index 0000000..f056b81
71152--- /dev/null
71153+++ b/grsecurity/gracl_ip.c
71154@@ -0,0 +1,386 @@
71155+#include <linux/kernel.h>
71156+#include <asm/uaccess.h>
71157+#include <asm/errno.h>
71158+#include <net/sock.h>
71159+#include <linux/file.h>
71160+#include <linux/fs.h>
71161+#include <linux/net.h>
71162+#include <linux/in.h>
71163+#include <linux/skbuff.h>
71164+#include <linux/ip.h>
71165+#include <linux/udp.h>
71166+#include <linux/types.h>
71167+#include <linux/sched.h>
71168+#include <linux/netdevice.h>
71169+#include <linux/inetdevice.h>
71170+#include <linux/gracl.h>
71171+#include <linux/grsecurity.h>
71172+#include <linux/grinternal.h>
71173+
71174+#define GR_BIND 0x01
71175+#define GR_CONNECT 0x02
71176+#define GR_INVERT 0x04
71177+#define GR_BINDOVERRIDE 0x08
71178+#define GR_CONNECTOVERRIDE 0x10
71179+#define GR_SOCK_FAMILY 0x20
71180+
71181+static const char * gr_protocols[IPPROTO_MAX] = {
71182+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
71183+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
71184+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
71185+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
71186+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
71187+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
71188+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
71189+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
71190+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
71191+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
71192+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
71193+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
71194+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
71195+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
71196+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
71197+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
71198+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
71199+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
71200+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
71201+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
71202+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
71203+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
71204+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
71205+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
71206+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
71207+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
71208+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
71209+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
71210+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
71211+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
71212+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
71213+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
71214+ };
71215+
71216+static const char * gr_socktypes[SOCK_MAX] = {
71217+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
71218+ "unknown:7", "unknown:8", "unknown:9", "packet"
71219+ };
71220+
71221+static const char * gr_sockfamilies[AF_MAX+1] = {
71222+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
71223+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
71224+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
71225+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
71226+ };
71227+
71228+const char *
71229+gr_proto_to_name(unsigned char proto)
71230+{
71231+ return gr_protocols[proto];
71232+}
71233+
71234+const char *
71235+gr_socktype_to_name(unsigned char type)
71236+{
71237+ return gr_socktypes[type];
71238+}
71239+
71240+const char *
71241+gr_sockfamily_to_name(unsigned char family)
71242+{
71243+ return gr_sockfamilies[family];
71244+}
71245+
71246+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
71247+
71248+int
71249+gr_search_socket(const int domain, const int type, const int protocol)
71250+{
71251+ struct acl_subject_label *curr;
71252+ const struct cred *cred = current_cred();
71253+
71254+ if (unlikely(!gr_acl_is_enabled()))
71255+ goto exit;
71256+
71257+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
71258+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
71259+ goto exit; // let the kernel handle it
71260+
71261+ curr = current->acl;
71262+
71263+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
71264+ /* the family is allowed, if this is PF_INET allow it only if
71265+ the extra sock type/protocol checks pass */
71266+ if (domain == PF_INET)
71267+ goto inet_check;
71268+ goto exit;
71269+ } else {
71270+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71271+ __u32 fakeip = 0;
71272+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71273+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71274+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71275+ gr_to_filename(current->exec_file->f_path.dentry,
71276+ current->exec_file->f_path.mnt) :
71277+ curr->filename, curr->filename,
71278+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
71279+ &current->signal->saved_ip);
71280+ goto exit;
71281+ }
71282+ goto exit_fail;
71283+ }
71284+
71285+inet_check:
71286+ /* the rest of this checking is for IPv4 only */
71287+ if (!curr->ips)
71288+ goto exit;
71289+
71290+ if ((curr->ip_type & (1U << type)) &&
71291+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
71292+ goto exit;
71293+
71294+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71295+ /* we don't place acls on raw sockets , and sometimes
71296+ dgram/ip sockets are opened for ioctl and not
71297+ bind/connect, so we'll fake a bind learn log */
71298+ if (type == SOCK_RAW || type == SOCK_PACKET) {
71299+ __u32 fakeip = 0;
71300+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71301+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71302+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71303+ gr_to_filename(current->exec_file->f_path.dentry,
71304+ current->exec_file->f_path.mnt) :
71305+ curr->filename, curr->filename,
71306+ &fakeip, 0, type,
71307+ protocol, GR_CONNECT, &current->signal->saved_ip);
71308+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
71309+ __u32 fakeip = 0;
71310+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71311+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71312+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71313+ gr_to_filename(current->exec_file->f_path.dentry,
71314+ current->exec_file->f_path.mnt) :
71315+ curr->filename, curr->filename,
71316+ &fakeip, 0, type,
71317+ protocol, GR_BIND, &current->signal->saved_ip);
71318+ }
71319+ /* we'll log when they use connect or bind */
71320+ goto exit;
71321+ }
71322+
71323+exit_fail:
71324+ if (domain == PF_INET)
71325+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
71326+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
71327+ else if (rcu_access_pointer(net_families[domain]) != NULL)
71328+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
71329+ gr_socktype_to_name(type), protocol);
71330+
71331+ return 0;
71332+exit:
71333+ return 1;
71334+}
71335+
71336+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)
71337+{
71338+ if ((ip->mode & mode) &&
71339+ (ip_port >= ip->low) &&
71340+ (ip_port <= ip->high) &&
71341+ ((ntohl(ip_addr) & our_netmask) ==
71342+ (ntohl(our_addr) & our_netmask))
71343+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
71344+ && (ip->type & (1U << type))) {
71345+ if (ip->mode & GR_INVERT)
71346+ return 2; // specifically denied
71347+ else
71348+ return 1; // allowed
71349+ }
71350+
71351+ return 0; // not specifically allowed, may continue parsing
71352+}
71353+
71354+static int
71355+gr_search_connectbind(const int full_mode, struct sock *sk,
71356+ struct sockaddr_in *addr, const int type)
71357+{
71358+ char iface[IFNAMSIZ] = {0};
71359+ struct acl_subject_label *curr;
71360+ struct acl_ip_label *ip;
71361+ struct inet_sock *isk;
71362+ struct net_device *dev;
71363+ struct in_device *idev;
71364+ unsigned long i;
71365+ int ret;
71366+ int mode = full_mode & (GR_BIND | GR_CONNECT);
71367+ __u32 ip_addr = 0;
71368+ __u32 our_addr;
71369+ __u32 our_netmask;
71370+ char *p;
71371+ __u16 ip_port = 0;
71372+ const struct cred *cred = current_cred();
71373+
71374+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
71375+ return 0;
71376+
71377+ curr = current->acl;
71378+ isk = inet_sk(sk);
71379+
71380+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
71381+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
71382+ addr->sin_addr.s_addr = curr->inaddr_any_override;
71383+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
71384+ struct sockaddr_in saddr;
71385+ int err;
71386+
71387+ saddr.sin_family = AF_INET;
71388+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
71389+ saddr.sin_port = isk->inet_sport;
71390+
71391+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71392+ if (err)
71393+ return err;
71394+
71395+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71396+ if (err)
71397+ return err;
71398+ }
71399+
71400+ if (!curr->ips)
71401+ return 0;
71402+
71403+ ip_addr = addr->sin_addr.s_addr;
71404+ ip_port = ntohs(addr->sin_port);
71405+
71406+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71407+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71408+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71409+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71410+ gr_to_filename(current->exec_file->f_path.dentry,
71411+ current->exec_file->f_path.mnt) :
71412+ curr->filename, curr->filename,
71413+ &ip_addr, ip_port, type,
71414+ sk->sk_protocol, mode, &current->signal->saved_ip);
71415+ return 0;
71416+ }
71417+
71418+ for (i = 0; i < curr->ip_num; i++) {
71419+ ip = *(curr->ips + i);
71420+ if (ip->iface != NULL) {
71421+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
71422+ p = strchr(iface, ':');
71423+ if (p != NULL)
71424+ *p = '\0';
71425+ dev = dev_get_by_name(sock_net(sk), iface);
71426+ if (dev == NULL)
71427+ continue;
71428+ idev = in_dev_get(dev);
71429+ if (idev == NULL) {
71430+ dev_put(dev);
71431+ continue;
71432+ }
71433+ rcu_read_lock();
71434+ for_ifa(idev) {
71435+ if (!strcmp(ip->iface, ifa->ifa_label)) {
71436+ our_addr = ifa->ifa_address;
71437+ our_netmask = 0xffffffff;
71438+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71439+ if (ret == 1) {
71440+ rcu_read_unlock();
71441+ in_dev_put(idev);
71442+ dev_put(dev);
71443+ return 0;
71444+ } else if (ret == 2) {
71445+ rcu_read_unlock();
71446+ in_dev_put(idev);
71447+ dev_put(dev);
71448+ goto denied;
71449+ }
71450+ }
71451+ } endfor_ifa(idev);
71452+ rcu_read_unlock();
71453+ in_dev_put(idev);
71454+ dev_put(dev);
71455+ } else {
71456+ our_addr = ip->addr;
71457+ our_netmask = ip->netmask;
71458+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71459+ if (ret == 1)
71460+ return 0;
71461+ else if (ret == 2)
71462+ goto denied;
71463+ }
71464+ }
71465+
71466+denied:
71467+ if (mode == GR_BIND)
71468+ 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));
71469+ else if (mode == GR_CONNECT)
71470+ 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));
71471+
71472+ return -EACCES;
71473+}
71474+
71475+int
71476+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71477+{
71478+ /* always allow disconnection of dgram sockets with connect */
71479+ if (addr->sin_family == AF_UNSPEC)
71480+ return 0;
71481+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71482+}
71483+
71484+int
71485+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71486+{
71487+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71488+}
71489+
71490+int gr_search_listen(struct socket *sock)
71491+{
71492+ struct sock *sk = sock->sk;
71493+ struct sockaddr_in addr;
71494+
71495+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71496+ addr.sin_port = inet_sk(sk)->inet_sport;
71497+
71498+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71499+}
71500+
71501+int gr_search_accept(struct socket *sock)
71502+{
71503+ struct sock *sk = sock->sk;
71504+ struct sockaddr_in addr;
71505+
71506+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71507+ addr.sin_port = inet_sk(sk)->inet_sport;
71508+
71509+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71510+}
71511+
71512+int
71513+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71514+{
71515+ if (addr)
71516+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71517+ else {
71518+ struct sockaddr_in sin;
71519+ const struct inet_sock *inet = inet_sk(sk);
71520+
71521+ sin.sin_addr.s_addr = inet->inet_daddr;
71522+ sin.sin_port = inet->inet_dport;
71523+
71524+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71525+ }
71526+}
71527+
71528+int
71529+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71530+{
71531+ struct sockaddr_in sin;
71532+
71533+ if (unlikely(skb->len < sizeof (struct udphdr)))
71534+ return 0; // skip this packet
71535+
71536+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71537+ sin.sin_port = udp_hdr(skb)->source;
71538+
71539+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71540+}
71541diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71542new file mode 100644
71543index 0000000..25f54ef
71544--- /dev/null
71545+++ b/grsecurity/gracl_learn.c
71546@@ -0,0 +1,207 @@
71547+#include <linux/kernel.h>
71548+#include <linux/mm.h>
71549+#include <linux/sched.h>
71550+#include <linux/poll.h>
71551+#include <linux/string.h>
71552+#include <linux/file.h>
71553+#include <linux/types.h>
71554+#include <linux/vmalloc.h>
71555+#include <linux/grinternal.h>
71556+
71557+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71558+ size_t count, loff_t *ppos);
71559+extern int gr_acl_is_enabled(void);
71560+
71561+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71562+static int gr_learn_attached;
71563+
71564+/* use a 512k buffer */
71565+#define LEARN_BUFFER_SIZE (512 * 1024)
71566+
71567+static DEFINE_SPINLOCK(gr_learn_lock);
71568+static DEFINE_MUTEX(gr_learn_user_mutex);
71569+
71570+/* we need to maintain two buffers, so that the kernel context of grlearn
71571+ uses a semaphore around the userspace copying, and the other kernel contexts
71572+ use a spinlock when copying into the buffer, since they cannot sleep
71573+*/
71574+static char *learn_buffer;
71575+static char *learn_buffer_user;
71576+static int learn_buffer_len;
71577+static int learn_buffer_user_len;
71578+
71579+static ssize_t
71580+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71581+{
71582+ DECLARE_WAITQUEUE(wait, current);
71583+ ssize_t retval = 0;
71584+
71585+ add_wait_queue(&learn_wait, &wait);
71586+ set_current_state(TASK_INTERRUPTIBLE);
71587+ do {
71588+ mutex_lock(&gr_learn_user_mutex);
71589+ spin_lock(&gr_learn_lock);
71590+ if (learn_buffer_len)
71591+ break;
71592+ spin_unlock(&gr_learn_lock);
71593+ mutex_unlock(&gr_learn_user_mutex);
71594+ if (file->f_flags & O_NONBLOCK) {
71595+ retval = -EAGAIN;
71596+ goto out;
71597+ }
71598+ if (signal_pending(current)) {
71599+ retval = -ERESTARTSYS;
71600+ goto out;
71601+ }
71602+
71603+ schedule();
71604+ } while (1);
71605+
71606+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71607+ learn_buffer_user_len = learn_buffer_len;
71608+ retval = learn_buffer_len;
71609+ learn_buffer_len = 0;
71610+
71611+ spin_unlock(&gr_learn_lock);
71612+
71613+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71614+ retval = -EFAULT;
71615+
71616+ mutex_unlock(&gr_learn_user_mutex);
71617+out:
71618+ set_current_state(TASK_RUNNING);
71619+ remove_wait_queue(&learn_wait, &wait);
71620+ return retval;
71621+}
71622+
71623+static unsigned int
71624+poll_learn(struct file * file, poll_table * wait)
71625+{
71626+ poll_wait(file, &learn_wait, wait);
71627+
71628+ if (learn_buffer_len)
71629+ return (POLLIN | POLLRDNORM);
71630+
71631+ return 0;
71632+}
71633+
71634+void
71635+gr_clear_learn_entries(void)
71636+{
71637+ char *tmp;
71638+
71639+ mutex_lock(&gr_learn_user_mutex);
71640+ spin_lock(&gr_learn_lock);
71641+ tmp = learn_buffer;
71642+ learn_buffer = NULL;
71643+ spin_unlock(&gr_learn_lock);
71644+ if (tmp)
71645+ vfree(tmp);
71646+ if (learn_buffer_user != NULL) {
71647+ vfree(learn_buffer_user);
71648+ learn_buffer_user = NULL;
71649+ }
71650+ learn_buffer_len = 0;
71651+ mutex_unlock(&gr_learn_user_mutex);
71652+
71653+ return;
71654+}
71655+
71656+void
71657+gr_add_learn_entry(const char *fmt, ...)
71658+{
71659+ va_list args;
71660+ unsigned int len;
71661+
71662+ if (!gr_learn_attached)
71663+ return;
71664+
71665+ spin_lock(&gr_learn_lock);
71666+
71667+ /* leave a gap at the end so we know when it's "full" but don't have to
71668+ compute the exact length of the string we're trying to append
71669+ */
71670+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71671+ spin_unlock(&gr_learn_lock);
71672+ wake_up_interruptible(&learn_wait);
71673+ return;
71674+ }
71675+ if (learn_buffer == NULL) {
71676+ spin_unlock(&gr_learn_lock);
71677+ return;
71678+ }
71679+
71680+ va_start(args, fmt);
71681+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71682+ va_end(args);
71683+
71684+ learn_buffer_len += len + 1;
71685+
71686+ spin_unlock(&gr_learn_lock);
71687+ wake_up_interruptible(&learn_wait);
71688+
71689+ return;
71690+}
71691+
71692+static int
71693+open_learn(struct inode *inode, struct file *file)
71694+{
71695+ if (file->f_mode & FMODE_READ && gr_learn_attached)
71696+ return -EBUSY;
71697+ if (file->f_mode & FMODE_READ) {
71698+ int retval = 0;
71699+ mutex_lock(&gr_learn_user_mutex);
71700+ if (learn_buffer == NULL)
71701+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71702+ if (learn_buffer_user == NULL)
71703+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71704+ if (learn_buffer == NULL) {
71705+ retval = -ENOMEM;
71706+ goto out_error;
71707+ }
71708+ if (learn_buffer_user == NULL) {
71709+ retval = -ENOMEM;
71710+ goto out_error;
71711+ }
71712+ learn_buffer_len = 0;
71713+ learn_buffer_user_len = 0;
71714+ gr_learn_attached = 1;
71715+out_error:
71716+ mutex_unlock(&gr_learn_user_mutex);
71717+ return retval;
71718+ }
71719+ return 0;
71720+}
71721+
71722+static int
71723+close_learn(struct inode *inode, struct file *file)
71724+{
71725+ if (file->f_mode & FMODE_READ) {
71726+ char *tmp = NULL;
71727+ mutex_lock(&gr_learn_user_mutex);
71728+ spin_lock(&gr_learn_lock);
71729+ tmp = learn_buffer;
71730+ learn_buffer = NULL;
71731+ spin_unlock(&gr_learn_lock);
71732+ if (tmp)
71733+ vfree(tmp);
71734+ if (learn_buffer_user != NULL) {
71735+ vfree(learn_buffer_user);
71736+ learn_buffer_user = NULL;
71737+ }
71738+ learn_buffer_len = 0;
71739+ learn_buffer_user_len = 0;
71740+ gr_learn_attached = 0;
71741+ mutex_unlock(&gr_learn_user_mutex);
71742+ }
71743+
71744+ return 0;
71745+}
71746+
71747+const struct file_operations grsec_fops = {
71748+ .read = read_learn,
71749+ .write = write_grsec_handler,
71750+ .open = open_learn,
71751+ .release = close_learn,
71752+ .poll = poll_learn,
71753+};
71754diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71755new file mode 100644
71756index 0000000..3f8ade0
71757--- /dev/null
71758+++ b/grsecurity/gracl_policy.c
71759@@ -0,0 +1,1782 @@
71760+#include <linux/kernel.h>
71761+#include <linux/module.h>
71762+#include <linux/sched.h>
71763+#include <linux/mm.h>
71764+#include <linux/file.h>
71765+#include <linux/fs.h>
71766+#include <linux/namei.h>
71767+#include <linux/mount.h>
71768+#include <linux/tty.h>
71769+#include <linux/proc_fs.h>
71770+#include <linux/lglock.h>
71771+#include <linux/slab.h>
71772+#include <linux/vmalloc.h>
71773+#include <linux/types.h>
71774+#include <linux/sysctl.h>
71775+#include <linux/netdevice.h>
71776+#include <linux/ptrace.h>
71777+#include <linux/gracl.h>
71778+#include <linux/gralloc.h>
71779+#include <linux/security.h>
71780+#include <linux/grinternal.h>
71781+#include <linux/pid_namespace.h>
71782+#include <linux/stop_machine.h>
71783+#include <linux/fdtable.h>
71784+#include <linux/percpu.h>
71785+#include <linux/lglock.h>
71786+#include <linux/hugetlb.h>
71787+#include <linux/posix-timers.h>
71788+#include "../fs/mount.h"
71789+
71790+#include <asm/uaccess.h>
71791+#include <asm/errno.h>
71792+#include <asm/mman.h>
71793+
71794+extern struct gr_policy_state *polstate;
71795+
71796+#define FOR_EACH_ROLE_START(role) \
71797+ role = polstate->role_list; \
71798+ while (role) {
71799+
71800+#define FOR_EACH_ROLE_END(role) \
71801+ role = role->prev; \
71802+ }
71803+
71804+struct path gr_real_root;
71805+
71806+extern struct gr_alloc_state *current_alloc_state;
71807+
71808+u16 acl_sp_role_value;
71809+
71810+static DEFINE_MUTEX(gr_dev_mutex);
71811+
71812+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71813+extern void gr_clear_learn_entries(void);
71814+
71815+struct gr_arg *gr_usermode __read_only;
71816+unsigned char *gr_system_salt __read_only;
71817+unsigned char *gr_system_sum __read_only;
71818+
71819+static unsigned int gr_auth_attempts = 0;
71820+static unsigned long gr_auth_expires = 0UL;
71821+
71822+struct acl_object_label *fakefs_obj_rw;
71823+struct acl_object_label *fakefs_obj_rwx;
71824+
71825+extern int gr_init_uidset(void);
71826+extern void gr_free_uidset(void);
71827+extern void gr_remove_uid(uid_t uid);
71828+extern int gr_find_uid(uid_t uid);
71829+
71830+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71831+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71832+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71833+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71834+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);
71835+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71836+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71837+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71838+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71839+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71840+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71841+extern void assign_special_role(const char *rolename);
71842+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71843+extern int gr_rbac_disable(void *unused);
71844+extern void gr_enable_rbac_system(void);
71845+
71846+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71847+{
71848+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71849+ return -EFAULT;
71850+
71851+ return 0;
71852+}
71853+
71854+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71855+{
71856+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71857+ return -EFAULT;
71858+
71859+ return 0;
71860+}
71861+
71862+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71863+{
71864+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71865+ return -EFAULT;
71866+
71867+ return 0;
71868+}
71869+
71870+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71871+{
71872+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71873+ return -EFAULT;
71874+
71875+ return 0;
71876+}
71877+
71878+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71879+{
71880+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71881+ return -EFAULT;
71882+
71883+ return 0;
71884+}
71885+
71886+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71887+{
71888+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71889+ return -EFAULT;
71890+
71891+ return 0;
71892+}
71893+
71894+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71895+{
71896+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71897+ return -EFAULT;
71898+
71899+ return 0;
71900+}
71901+
71902+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71903+{
71904+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71905+ return -EFAULT;
71906+
71907+ return 0;
71908+}
71909+
71910+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71911+{
71912+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71913+ return -EFAULT;
71914+
71915+ return 0;
71916+}
71917+
71918+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71919+{
71920+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71921+ return -EFAULT;
71922+
71923+ if (((uwrap->version != GRSECURITY_VERSION) &&
71924+ (uwrap->version != 0x2901)) ||
71925+ (uwrap->size != sizeof(struct gr_arg)))
71926+ return -EINVAL;
71927+
71928+ return 0;
71929+}
71930+
71931+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71932+{
71933+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71934+ return -EFAULT;
71935+
71936+ return 0;
71937+}
71938+
71939+static size_t get_gr_arg_wrapper_size_normal(void)
71940+{
71941+ return sizeof(struct gr_arg_wrapper);
71942+}
71943+
71944+#ifdef CONFIG_COMPAT
71945+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71946+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71947+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71948+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71949+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71950+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71951+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71952+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71953+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71954+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71955+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71956+extern size_t get_gr_arg_wrapper_size_compat(void);
71957+
71958+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71959+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71960+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71961+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71962+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71963+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71964+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71965+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71966+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71967+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71968+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71969+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71970+
71971+#else
71972+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71973+#define copy_gr_arg copy_gr_arg_normal
71974+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71975+#define copy_acl_object_label copy_acl_object_label_normal
71976+#define copy_acl_subject_label copy_acl_subject_label_normal
71977+#define copy_acl_role_label copy_acl_role_label_normal
71978+#define copy_acl_ip_label copy_acl_ip_label_normal
71979+#define copy_pointer_from_array copy_pointer_from_array_normal
71980+#define copy_sprole_pw copy_sprole_pw_normal
71981+#define copy_role_transition copy_role_transition_normal
71982+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71983+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71984+#endif
71985+
71986+static struct acl_subject_label *
71987+lookup_subject_map(const struct acl_subject_label *userp)
71988+{
71989+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71990+ struct subject_map *match;
71991+
71992+ match = polstate->subj_map_set.s_hash[index];
71993+
71994+ while (match && match->user != userp)
71995+ match = match->next;
71996+
71997+ if (match != NULL)
71998+ return match->kernel;
71999+ else
72000+ return NULL;
72001+}
72002+
72003+static void
72004+insert_subj_map_entry(struct subject_map *subjmap)
72005+{
72006+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
72007+ struct subject_map **curr;
72008+
72009+ subjmap->prev = NULL;
72010+
72011+ curr = &polstate->subj_map_set.s_hash[index];
72012+ if (*curr != NULL)
72013+ (*curr)->prev = subjmap;
72014+
72015+ subjmap->next = *curr;
72016+ *curr = subjmap;
72017+
72018+ return;
72019+}
72020+
72021+static void
72022+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
72023+{
72024+ unsigned int index =
72025+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
72026+ struct acl_role_label **curr;
72027+ struct acl_role_label *tmp, *tmp2;
72028+
72029+ curr = &polstate->acl_role_set.r_hash[index];
72030+
72031+ /* simple case, slot is empty, just set it to our role */
72032+ if (*curr == NULL) {
72033+ *curr = role;
72034+ } else {
72035+ /* example:
72036+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
72037+ 2 -> 3
72038+ */
72039+ /* first check to see if we can already be reached via this slot */
72040+ tmp = *curr;
72041+ while (tmp && tmp != role)
72042+ tmp = tmp->next;
72043+ if (tmp == role) {
72044+ /* we don't need to add ourselves to this slot's chain */
72045+ return;
72046+ }
72047+ /* we need to add ourselves to this chain, two cases */
72048+ if (role->next == NULL) {
72049+ /* simple case, append the current chain to our role */
72050+ role->next = *curr;
72051+ *curr = role;
72052+ } else {
72053+ /* 1 -> 2 -> 3 -> 4
72054+ 2 -> 3 -> 4
72055+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
72056+ */
72057+ /* trickier case: walk our role's chain until we find
72058+ the role for the start of the current slot's chain */
72059+ tmp = role;
72060+ tmp2 = *curr;
72061+ while (tmp->next && tmp->next != tmp2)
72062+ tmp = tmp->next;
72063+ if (tmp->next == tmp2) {
72064+ /* from example above, we found 3, so just
72065+ replace this slot's chain with ours */
72066+ *curr = role;
72067+ } else {
72068+ /* we didn't find a subset of our role's chain
72069+ in the current slot's chain, so append their
72070+ chain to ours, and set us as the first role in
72071+ the slot's chain
72072+
72073+ we could fold this case with the case above,
72074+ but making it explicit for clarity
72075+ */
72076+ tmp->next = tmp2;
72077+ *curr = role;
72078+ }
72079+ }
72080+ }
72081+
72082+ return;
72083+}
72084+
72085+static void
72086+insert_acl_role_label(struct acl_role_label *role)
72087+{
72088+ int i;
72089+
72090+ if (polstate->role_list == NULL) {
72091+ polstate->role_list = role;
72092+ role->prev = NULL;
72093+ } else {
72094+ role->prev = polstate->role_list;
72095+ polstate->role_list = role;
72096+ }
72097+
72098+ /* used for hash chains */
72099+ role->next = NULL;
72100+
72101+ if (role->roletype & GR_ROLE_DOMAIN) {
72102+ for (i = 0; i < role->domain_child_num; i++)
72103+ __insert_acl_role_label(role, role->domain_children[i]);
72104+ } else
72105+ __insert_acl_role_label(role, role->uidgid);
72106+}
72107+
72108+static int
72109+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
72110+{
72111+ struct name_entry **curr, *nentry;
72112+ struct inodev_entry *ientry;
72113+ unsigned int len = strlen(name);
72114+ unsigned int key = full_name_hash(name, len);
72115+ unsigned int index = key % polstate->name_set.n_size;
72116+
72117+ curr = &polstate->name_set.n_hash[index];
72118+
72119+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
72120+ curr = &((*curr)->next);
72121+
72122+ if (*curr != NULL)
72123+ return 1;
72124+
72125+ nentry = acl_alloc(sizeof (struct name_entry));
72126+ if (nentry == NULL)
72127+ return 0;
72128+ ientry = acl_alloc(sizeof (struct inodev_entry));
72129+ if (ientry == NULL)
72130+ return 0;
72131+ ientry->nentry = nentry;
72132+
72133+ nentry->key = key;
72134+ nentry->name = name;
72135+ nentry->inode = inode;
72136+ nentry->device = device;
72137+ nentry->len = len;
72138+ nentry->deleted = deleted;
72139+
72140+ nentry->prev = NULL;
72141+ curr = &polstate->name_set.n_hash[index];
72142+ if (*curr != NULL)
72143+ (*curr)->prev = nentry;
72144+ nentry->next = *curr;
72145+ *curr = nentry;
72146+
72147+ /* insert us into the table searchable by inode/dev */
72148+ __insert_inodev_entry(polstate, ientry);
72149+
72150+ return 1;
72151+}
72152+
72153+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
72154+
72155+static void *
72156+create_table(__u32 * len, int elementsize)
72157+{
72158+ unsigned int table_sizes[] = {
72159+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
72160+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
72161+ 4194301, 8388593, 16777213, 33554393, 67108859
72162+ };
72163+ void *newtable = NULL;
72164+ unsigned int pwr = 0;
72165+
72166+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
72167+ table_sizes[pwr] <= *len)
72168+ pwr++;
72169+
72170+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
72171+ return newtable;
72172+
72173+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
72174+ newtable =
72175+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
72176+ else
72177+ newtable = vmalloc(table_sizes[pwr] * elementsize);
72178+
72179+ *len = table_sizes[pwr];
72180+
72181+ return newtable;
72182+}
72183+
72184+static int
72185+init_variables(const struct gr_arg *arg, bool reload)
72186+{
72187+ struct task_struct *reaper = init_pid_ns.child_reaper;
72188+ unsigned int stacksize;
72189+
72190+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
72191+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
72192+ polstate->name_set.n_size = arg->role_db.num_objects;
72193+ polstate->inodev_set.i_size = arg->role_db.num_objects;
72194+
72195+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
72196+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
72197+ return 1;
72198+
72199+ if (!reload) {
72200+ if (!gr_init_uidset())
72201+ return 1;
72202+ }
72203+
72204+ /* set up the stack that holds allocation info */
72205+
72206+ stacksize = arg->role_db.num_pointers + 5;
72207+
72208+ if (!acl_alloc_stack_init(stacksize))
72209+ return 1;
72210+
72211+ if (!reload) {
72212+ /* grab reference for the real root dentry and vfsmount */
72213+ get_fs_root(reaper->fs, &gr_real_root);
72214+
72215+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72216+ 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);
72217+#endif
72218+
72219+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
72220+ if (fakefs_obj_rw == NULL)
72221+ return 1;
72222+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
72223+
72224+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
72225+ if (fakefs_obj_rwx == NULL)
72226+ return 1;
72227+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
72228+ }
72229+
72230+ polstate->subj_map_set.s_hash =
72231+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
72232+ polstate->acl_role_set.r_hash =
72233+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
72234+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
72235+ polstate->inodev_set.i_hash =
72236+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
72237+
72238+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
72239+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
72240+ return 1;
72241+
72242+ memset(polstate->subj_map_set.s_hash, 0,
72243+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
72244+ memset(polstate->acl_role_set.r_hash, 0,
72245+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
72246+ memset(polstate->name_set.n_hash, 0,
72247+ sizeof (struct name_entry *) * polstate->name_set.n_size);
72248+ memset(polstate->inodev_set.i_hash, 0,
72249+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
72250+
72251+ return 0;
72252+}
72253+
72254+/* free information not needed after startup
72255+ currently contains user->kernel pointer mappings for subjects
72256+*/
72257+
72258+static void
72259+free_init_variables(void)
72260+{
72261+ __u32 i;
72262+
72263+ if (polstate->subj_map_set.s_hash) {
72264+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
72265+ if (polstate->subj_map_set.s_hash[i]) {
72266+ kfree(polstate->subj_map_set.s_hash[i]);
72267+ polstate->subj_map_set.s_hash[i] = NULL;
72268+ }
72269+ }
72270+
72271+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
72272+ PAGE_SIZE)
72273+ kfree(polstate->subj_map_set.s_hash);
72274+ else
72275+ vfree(polstate->subj_map_set.s_hash);
72276+ }
72277+
72278+ return;
72279+}
72280+
72281+static void
72282+free_variables(bool reload)
72283+{
72284+ struct acl_subject_label *s;
72285+ struct acl_role_label *r;
72286+ struct task_struct *task, *task2;
72287+ unsigned int x;
72288+
72289+ if (!reload) {
72290+ gr_clear_learn_entries();
72291+
72292+ read_lock(&tasklist_lock);
72293+ do_each_thread(task2, task) {
72294+ task->acl_sp_role = 0;
72295+ task->acl_role_id = 0;
72296+ task->inherited = 0;
72297+ task->acl = NULL;
72298+ task->role = NULL;
72299+ } while_each_thread(task2, task);
72300+ read_unlock(&tasklist_lock);
72301+
72302+ kfree(fakefs_obj_rw);
72303+ fakefs_obj_rw = NULL;
72304+ kfree(fakefs_obj_rwx);
72305+ fakefs_obj_rwx = NULL;
72306+
72307+ /* release the reference to the real root dentry and vfsmount */
72308+ path_put(&gr_real_root);
72309+ memset(&gr_real_root, 0, sizeof(gr_real_root));
72310+ }
72311+
72312+ /* free all object hash tables */
72313+
72314+ FOR_EACH_ROLE_START(r)
72315+ if (r->subj_hash == NULL)
72316+ goto next_role;
72317+ FOR_EACH_SUBJECT_START(r, s, x)
72318+ if (s->obj_hash == NULL)
72319+ break;
72320+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72321+ kfree(s->obj_hash);
72322+ else
72323+ vfree(s->obj_hash);
72324+ FOR_EACH_SUBJECT_END(s, x)
72325+ FOR_EACH_NESTED_SUBJECT_START(r, s)
72326+ if (s->obj_hash == NULL)
72327+ break;
72328+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72329+ kfree(s->obj_hash);
72330+ else
72331+ vfree(s->obj_hash);
72332+ FOR_EACH_NESTED_SUBJECT_END(s)
72333+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
72334+ kfree(r->subj_hash);
72335+ else
72336+ vfree(r->subj_hash);
72337+ r->subj_hash = NULL;
72338+next_role:
72339+ FOR_EACH_ROLE_END(r)
72340+
72341+ acl_free_all();
72342+
72343+ if (polstate->acl_role_set.r_hash) {
72344+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
72345+ PAGE_SIZE)
72346+ kfree(polstate->acl_role_set.r_hash);
72347+ else
72348+ vfree(polstate->acl_role_set.r_hash);
72349+ }
72350+ if (polstate->name_set.n_hash) {
72351+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
72352+ PAGE_SIZE)
72353+ kfree(polstate->name_set.n_hash);
72354+ else
72355+ vfree(polstate->name_set.n_hash);
72356+ }
72357+
72358+ if (polstate->inodev_set.i_hash) {
72359+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
72360+ PAGE_SIZE)
72361+ kfree(polstate->inodev_set.i_hash);
72362+ else
72363+ vfree(polstate->inodev_set.i_hash);
72364+ }
72365+
72366+ if (!reload)
72367+ gr_free_uidset();
72368+
72369+ memset(&polstate->name_set, 0, sizeof (struct name_db));
72370+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
72371+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
72372+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
72373+
72374+ polstate->default_role = NULL;
72375+ polstate->kernel_role = NULL;
72376+ polstate->role_list = NULL;
72377+
72378+ return;
72379+}
72380+
72381+static struct acl_subject_label *
72382+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
72383+
72384+static int alloc_and_copy_string(char **name, unsigned int maxlen)
72385+{
72386+ unsigned int len = strnlen_user(*name, maxlen);
72387+ char *tmp;
72388+
72389+ if (!len || len >= maxlen)
72390+ return -EINVAL;
72391+
72392+ if ((tmp = (char *) acl_alloc(len)) == NULL)
72393+ return -ENOMEM;
72394+
72395+ if (copy_from_user(tmp, *name, len))
72396+ return -EFAULT;
72397+
72398+ tmp[len-1] = '\0';
72399+ *name = tmp;
72400+
72401+ return 0;
72402+}
72403+
72404+static int
72405+copy_user_glob(struct acl_object_label *obj)
72406+{
72407+ struct acl_object_label *g_tmp, **guser;
72408+ int error;
72409+
72410+ if (obj->globbed == NULL)
72411+ return 0;
72412+
72413+ guser = &obj->globbed;
72414+ while (*guser) {
72415+ g_tmp = (struct acl_object_label *)
72416+ acl_alloc(sizeof (struct acl_object_label));
72417+ if (g_tmp == NULL)
72418+ return -ENOMEM;
72419+
72420+ if (copy_acl_object_label(g_tmp, *guser))
72421+ return -EFAULT;
72422+
72423+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72424+ if (error)
72425+ return error;
72426+
72427+ *guser = g_tmp;
72428+ guser = &(g_tmp->next);
72429+ }
72430+
72431+ return 0;
72432+}
72433+
72434+static int
72435+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72436+ struct acl_role_label *role)
72437+{
72438+ struct acl_object_label *o_tmp;
72439+ int ret;
72440+
72441+ while (userp) {
72442+ if ((o_tmp = (struct acl_object_label *)
72443+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
72444+ return -ENOMEM;
72445+
72446+ if (copy_acl_object_label(o_tmp, userp))
72447+ return -EFAULT;
72448+
72449+ userp = o_tmp->prev;
72450+
72451+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72452+ if (ret)
72453+ return ret;
72454+
72455+ insert_acl_obj_label(o_tmp, subj);
72456+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72457+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72458+ return -ENOMEM;
72459+
72460+ ret = copy_user_glob(o_tmp);
72461+ if (ret)
72462+ return ret;
72463+
72464+ if (o_tmp->nested) {
72465+ int already_copied;
72466+
72467+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72468+ if (IS_ERR(o_tmp->nested))
72469+ return PTR_ERR(o_tmp->nested);
72470+
72471+ /* insert into nested subject list if we haven't copied this one yet
72472+ to prevent duplicate entries */
72473+ if (!already_copied) {
72474+ o_tmp->nested->next = role->hash->first;
72475+ role->hash->first = o_tmp->nested;
72476+ }
72477+ }
72478+ }
72479+
72480+ return 0;
72481+}
72482+
72483+static __u32
72484+count_user_subjs(struct acl_subject_label *userp)
72485+{
72486+ struct acl_subject_label s_tmp;
72487+ __u32 num = 0;
72488+
72489+ while (userp) {
72490+ if (copy_acl_subject_label(&s_tmp, userp))
72491+ break;
72492+
72493+ userp = s_tmp.prev;
72494+ }
72495+
72496+ return num;
72497+}
72498+
72499+static int
72500+copy_user_allowedips(struct acl_role_label *rolep)
72501+{
72502+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72503+
72504+ ruserip = rolep->allowed_ips;
72505+
72506+ while (ruserip) {
72507+ rlast = rtmp;
72508+
72509+ if ((rtmp = (struct role_allowed_ip *)
72510+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72511+ return -ENOMEM;
72512+
72513+ if (copy_role_allowed_ip(rtmp, ruserip))
72514+ return -EFAULT;
72515+
72516+ ruserip = rtmp->prev;
72517+
72518+ if (!rlast) {
72519+ rtmp->prev = NULL;
72520+ rolep->allowed_ips = rtmp;
72521+ } else {
72522+ rlast->next = rtmp;
72523+ rtmp->prev = rlast;
72524+ }
72525+
72526+ if (!ruserip)
72527+ rtmp->next = NULL;
72528+ }
72529+
72530+ return 0;
72531+}
72532+
72533+static int
72534+copy_user_transitions(struct acl_role_label *rolep)
72535+{
72536+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
72537+ int error;
72538+
72539+ rusertp = rolep->transitions;
72540+
72541+ while (rusertp) {
72542+ rlast = rtmp;
72543+
72544+ if ((rtmp = (struct role_transition *)
72545+ acl_alloc(sizeof (struct role_transition))) == NULL)
72546+ return -ENOMEM;
72547+
72548+ if (copy_role_transition(rtmp, rusertp))
72549+ return -EFAULT;
72550+
72551+ rusertp = rtmp->prev;
72552+
72553+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72554+ if (error)
72555+ return error;
72556+
72557+ if (!rlast) {
72558+ rtmp->prev = NULL;
72559+ rolep->transitions = rtmp;
72560+ } else {
72561+ rlast->next = rtmp;
72562+ rtmp->prev = rlast;
72563+ }
72564+
72565+ if (!rusertp)
72566+ rtmp->next = NULL;
72567+ }
72568+
72569+ return 0;
72570+}
72571+
72572+static __u32 count_user_objs(const struct acl_object_label __user *userp)
72573+{
72574+ struct acl_object_label o_tmp;
72575+ __u32 num = 0;
72576+
72577+ while (userp) {
72578+ if (copy_acl_object_label(&o_tmp, userp))
72579+ break;
72580+
72581+ userp = o_tmp.prev;
72582+ num++;
72583+ }
72584+
72585+ return num;
72586+}
72587+
72588+static struct acl_subject_label *
72589+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72590+{
72591+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72592+ __u32 num_objs;
72593+ struct acl_ip_label **i_tmp, *i_utmp2;
72594+ struct gr_hash_struct ghash;
72595+ struct subject_map *subjmap;
72596+ unsigned int i_num;
72597+ int err;
72598+
72599+ if (already_copied != NULL)
72600+ *already_copied = 0;
72601+
72602+ s_tmp = lookup_subject_map(userp);
72603+
72604+ /* we've already copied this subject into the kernel, just return
72605+ the reference to it, and don't copy it over again
72606+ */
72607+ if (s_tmp) {
72608+ if (already_copied != NULL)
72609+ *already_copied = 1;
72610+ return(s_tmp);
72611+ }
72612+
72613+ if ((s_tmp = (struct acl_subject_label *)
72614+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72615+ return ERR_PTR(-ENOMEM);
72616+
72617+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72618+ if (subjmap == NULL)
72619+ return ERR_PTR(-ENOMEM);
72620+
72621+ subjmap->user = userp;
72622+ subjmap->kernel = s_tmp;
72623+ insert_subj_map_entry(subjmap);
72624+
72625+ if (copy_acl_subject_label(s_tmp, userp))
72626+ return ERR_PTR(-EFAULT);
72627+
72628+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72629+ if (err)
72630+ return ERR_PTR(err);
72631+
72632+ if (!strcmp(s_tmp->filename, "/"))
72633+ role->root_label = s_tmp;
72634+
72635+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72636+ return ERR_PTR(-EFAULT);
72637+
72638+ /* copy user and group transition tables */
72639+
72640+ if (s_tmp->user_trans_num) {
72641+ uid_t *uidlist;
72642+
72643+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72644+ if (uidlist == NULL)
72645+ return ERR_PTR(-ENOMEM);
72646+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72647+ return ERR_PTR(-EFAULT);
72648+
72649+ s_tmp->user_transitions = uidlist;
72650+ }
72651+
72652+ if (s_tmp->group_trans_num) {
72653+ gid_t *gidlist;
72654+
72655+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72656+ if (gidlist == NULL)
72657+ return ERR_PTR(-ENOMEM);
72658+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72659+ return ERR_PTR(-EFAULT);
72660+
72661+ s_tmp->group_transitions = gidlist;
72662+ }
72663+
72664+ /* set up object hash table */
72665+ num_objs = count_user_objs(ghash.first);
72666+
72667+ s_tmp->obj_hash_size = num_objs;
72668+ s_tmp->obj_hash =
72669+ (struct acl_object_label **)
72670+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72671+
72672+ if (!s_tmp->obj_hash)
72673+ return ERR_PTR(-ENOMEM);
72674+
72675+ memset(s_tmp->obj_hash, 0,
72676+ s_tmp->obj_hash_size *
72677+ sizeof (struct acl_object_label *));
72678+
72679+ /* add in objects */
72680+ err = copy_user_objs(ghash.first, s_tmp, role);
72681+
72682+ if (err)
72683+ return ERR_PTR(err);
72684+
72685+ /* set pointer for parent subject */
72686+ if (s_tmp->parent_subject) {
72687+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72688+
72689+ if (IS_ERR(s_tmp2))
72690+ return s_tmp2;
72691+
72692+ s_tmp->parent_subject = s_tmp2;
72693+ }
72694+
72695+ /* add in ip acls */
72696+
72697+ if (!s_tmp->ip_num) {
72698+ s_tmp->ips = NULL;
72699+ goto insert;
72700+ }
72701+
72702+ i_tmp =
72703+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72704+ sizeof (struct acl_ip_label *));
72705+
72706+ if (!i_tmp)
72707+ return ERR_PTR(-ENOMEM);
72708+
72709+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72710+ *(i_tmp + i_num) =
72711+ (struct acl_ip_label *)
72712+ acl_alloc(sizeof (struct acl_ip_label));
72713+ if (!*(i_tmp + i_num))
72714+ return ERR_PTR(-ENOMEM);
72715+
72716+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72717+ return ERR_PTR(-EFAULT);
72718+
72719+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72720+ return ERR_PTR(-EFAULT);
72721+
72722+ if ((*(i_tmp + i_num))->iface == NULL)
72723+ continue;
72724+
72725+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72726+ if (err)
72727+ return ERR_PTR(err);
72728+ }
72729+
72730+ s_tmp->ips = i_tmp;
72731+
72732+insert:
72733+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72734+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72735+ return ERR_PTR(-ENOMEM);
72736+
72737+ return s_tmp;
72738+}
72739+
72740+static int
72741+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72742+{
72743+ struct acl_subject_label s_pre;
72744+ struct acl_subject_label * ret;
72745+ int err;
72746+
72747+ while (userp) {
72748+ if (copy_acl_subject_label(&s_pre, userp))
72749+ return -EFAULT;
72750+
72751+ ret = do_copy_user_subj(userp, role, NULL);
72752+
72753+ err = PTR_ERR(ret);
72754+ if (IS_ERR(ret))
72755+ return err;
72756+
72757+ insert_acl_subj_label(ret, role);
72758+
72759+ userp = s_pre.prev;
72760+ }
72761+
72762+ return 0;
72763+}
72764+
72765+static int
72766+copy_user_acl(struct gr_arg *arg)
72767+{
72768+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72769+ struct acl_subject_label *subj_list;
72770+ struct sprole_pw *sptmp;
72771+ struct gr_hash_struct *ghash;
72772+ uid_t *domainlist;
72773+ unsigned int r_num;
72774+ int err = 0;
72775+ __u16 i;
72776+ __u32 num_subjs;
72777+
72778+ /* we need a default and kernel role */
72779+ if (arg->role_db.num_roles < 2)
72780+ return -EINVAL;
72781+
72782+ /* copy special role authentication info from userspace */
72783+
72784+ polstate->num_sprole_pws = arg->num_sprole_pws;
72785+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72786+
72787+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72788+ return -ENOMEM;
72789+
72790+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72791+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72792+ if (!sptmp)
72793+ return -ENOMEM;
72794+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72795+ return -EFAULT;
72796+
72797+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72798+ if (err)
72799+ return err;
72800+
72801+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72802+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72803+#endif
72804+
72805+ polstate->acl_special_roles[i] = sptmp;
72806+ }
72807+
72808+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72809+
72810+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72811+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72812+
72813+ if (!r_tmp)
72814+ return -ENOMEM;
72815+
72816+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72817+ return -EFAULT;
72818+
72819+ if (copy_acl_role_label(r_tmp, r_utmp2))
72820+ return -EFAULT;
72821+
72822+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72823+ if (err)
72824+ return err;
72825+
72826+ if (!strcmp(r_tmp->rolename, "default")
72827+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72828+ polstate->default_role = r_tmp;
72829+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72830+ polstate->kernel_role = r_tmp;
72831+ }
72832+
72833+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72834+ return -ENOMEM;
72835+
72836+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72837+ return -EFAULT;
72838+
72839+ r_tmp->hash = ghash;
72840+
72841+ num_subjs = count_user_subjs(r_tmp->hash->first);
72842+
72843+ r_tmp->subj_hash_size = num_subjs;
72844+ r_tmp->subj_hash =
72845+ (struct acl_subject_label **)
72846+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72847+
72848+ if (!r_tmp->subj_hash)
72849+ return -ENOMEM;
72850+
72851+ err = copy_user_allowedips(r_tmp);
72852+ if (err)
72853+ return err;
72854+
72855+ /* copy domain info */
72856+ if (r_tmp->domain_children != NULL) {
72857+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72858+ if (domainlist == NULL)
72859+ return -ENOMEM;
72860+
72861+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72862+ return -EFAULT;
72863+
72864+ r_tmp->domain_children = domainlist;
72865+ }
72866+
72867+ err = copy_user_transitions(r_tmp);
72868+ if (err)
72869+ return err;
72870+
72871+ memset(r_tmp->subj_hash, 0,
72872+ r_tmp->subj_hash_size *
72873+ sizeof (struct acl_subject_label *));
72874+
72875+ /* acquire the list of subjects, then NULL out
72876+ the list prior to parsing the subjects for this role,
72877+ as during this parsing the list is replaced with a list
72878+ of *nested* subjects for the role
72879+ */
72880+ subj_list = r_tmp->hash->first;
72881+
72882+ /* set nested subject list to null */
72883+ r_tmp->hash->first = NULL;
72884+
72885+ err = copy_user_subjs(subj_list, r_tmp);
72886+
72887+ if (err)
72888+ return err;
72889+
72890+ insert_acl_role_label(r_tmp);
72891+ }
72892+
72893+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72894+ return -EINVAL;
72895+
72896+ return err;
72897+}
72898+
72899+static int gracl_reload_apply_policies(void *reload)
72900+{
72901+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72902+ struct task_struct *task, *task2;
72903+ struct acl_role_label *role, *rtmp;
72904+ struct acl_subject_label *subj;
72905+ const struct cred *cred;
72906+ int role_applied;
72907+ int ret = 0;
72908+
72909+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72910+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72911+
72912+ /* first make sure we'll be able to apply the new policy cleanly */
72913+ do_each_thread(task2, task) {
72914+ if (task->exec_file == NULL)
72915+ continue;
72916+ role_applied = 0;
72917+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72918+ /* preserve special roles */
72919+ FOR_EACH_ROLE_START(role)
72920+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72921+ rtmp = task->role;
72922+ task->role = role;
72923+ role_applied = 1;
72924+ break;
72925+ }
72926+ FOR_EACH_ROLE_END(role)
72927+ }
72928+ if (!role_applied) {
72929+ cred = __task_cred(task);
72930+ rtmp = task->role;
72931+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72932+ }
72933+ /* this handles non-nested inherited subjects, nested subjects will still
72934+ be dropped currently */
72935+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72936+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72937+ /* change the role back so that we've made no modifications to the policy */
72938+ task->role = rtmp;
72939+
72940+ if (subj == NULL || task->tmpacl == NULL) {
72941+ ret = -EINVAL;
72942+ goto out;
72943+ }
72944+ } while_each_thread(task2, task);
72945+
72946+ /* now actually apply the policy */
72947+
72948+ do_each_thread(task2, task) {
72949+ if (task->exec_file) {
72950+ role_applied = 0;
72951+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72952+ /* preserve special roles */
72953+ FOR_EACH_ROLE_START(role)
72954+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72955+ task->role = role;
72956+ role_applied = 1;
72957+ break;
72958+ }
72959+ FOR_EACH_ROLE_END(role)
72960+ }
72961+ if (!role_applied) {
72962+ cred = __task_cred(task);
72963+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72964+ }
72965+ /* this handles non-nested inherited subjects, nested subjects will still
72966+ be dropped currently */
72967+ if (!reload_state->oldmode && task->inherited)
72968+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72969+ else {
72970+ /* looked up and tagged to the task previously */
72971+ subj = task->tmpacl;
72972+ }
72973+ /* subj will be non-null */
72974+ __gr_apply_subject_to_task(polstate, task, subj);
72975+ if (reload_state->oldmode) {
72976+ task->acl_role_id = 0;
72977+ task->acl_sp_role = 0;
72978+ task->inherited = 0;
72979+ }
72980+ } else {
72981+ // it's a kernel process
72982+ task->role = polstate->kernel_role;
72983+ task->acl = polstate->kernel_role->root_label;
72984+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72985+ task->acl->mode &= ~GR_PROCFIND;
72986+#endif
72987+ }
72988+ } while_each_thread(task2, task);
72989+
72990+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72991+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72992+
72993+out:
72994+
72995+ return ret;
72996+}
72997+
72998+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72999+{
73000+ struct gr_reload_state new_reload_state = { };
73001+ int err;
73002+
73003+ new_reload_state.oldpolicy_ptr = polstate;
73004+ new_reload_state.oldalloc_ptr = current_alloc_state;
73005+ new_reload_state.oldmode = oldmode;
73006+
73007+ current_alloc_state = &new_reload_state.newalloc;
73008+ polstate = &new_reload_state.newpolicy;
73009+
73010+ /* everything relevant is now saved off, copy in the new policy */
73011+ if (init_variables(args, true)) {
73012+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
73013+ err = -ENOMEM;
73014+ goto error;
73015+ }
73016+
73017+ err = copy_user_acl(args);
73018+ free_init_variables();
73019+ if (err)
73020+ goto error;
73021+ /* the new policy is copied in, with the old policy available via saved_state
73022+ first go through applying roles, making sure to preserve special roles
73023+ then apply new subjects, making sure to preserve inherited and nested subjects,
73024+ though currently only inherited subjects will be preserved
73025+ */
73026+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
73027+ if (err)
73028+ goto error;
73029+
73030+ /* we've now applied the new policy, so restore the old policy state to free it */
73031+ polstate = &new_reload_state.oldpolicy;
73032+ current_alloc_state = &new_reload_state.oldalloc;
73033+ free_variables(true);
73034+
73035+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
73036+ to running_polstate/current_alloc_state inside stop_machine
73037+ */
73038+ err = 0;
73039+ goto out;
73040+error:
73041+ /* on error of loading the new policy, we'll just keep the previous
73042+ policy set around
73043+ */
73044+ free_variables(true);
73045+
73046+ /* doesn't affect runtime, but maintains consistent state */
73047+out:
73048+ polstate = new_reload_state.oldpolicy_ptr;
73049+ current_alloc_state = new_reload_state.oldalloc_ptr;
73050+
73051+ return err;
73052+}
73053+
73054+static int
73055+gracl_init(struct gr_arg *args)
73056+{
73057+ int error = 0;
73058+
73059+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
73060+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
73061+
73062+ if (init_variables(args, false)) {
73063+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
73064+ error = -ENOMEM;
73065+ goto out;
73066+ }
73067+
73068+ error = copy_user_acl(args);
73069+ free_init_variables();
73070+ if (error)
73071+ goto out;
73072+
73073+ error = gr_set_acls(0);
73074+ if (error)
73075+ goto out;
73076+
73077+ gr_enable_rbac_system();
73078+
73079+ return 0;
73080+
73081+out:
73082+ free_variables(false);
73083+ return error;
73084+}
73085+
73086+static int
73087+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
73088+ unsigned char **sum)
73089+{
73090+ struct acl_role_label *r;
73091+ struct role_allowed_ip *ipp;
73092+ struct role_transition *trans;
73093+ unsigned int i;
73094+ int found = 0;
73095+ u32 curr_ip = current->signal->curr_ip;
73096+
73097+ current->signal->saved_ip = curr_ip;
73098+
73099+ /* check transition table */
73100+
73101+ for (trans = current->role->transitions; trans; trans = trans->next) {
73102+ if (!strcmp(rolename, trans->rolename)) {
73103+ found = 1;
73104+ break;
73105+ }
73106+ }
73107+
73108+ if (!found)
73109+ return 0;
73110+
73111+ /* handle special roles that do not require authentication
73112+ and check ip */
73113+
73114+ FOR_EACH_ROLE_START(r)
73115+ if (!strcmp(rolename, r->rolename) &&
73116+ (r->roletype & GR_ROLE_SPECIAL)) {
73117+ found = 0;
73118+ if (r->allowed_ips != NULL) {
73119+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
73120+ if ((ntohl(curr_ip) & ipp->netmask) ==
73121+ (ntohl(ipp->addr) & ipp->netmask))
73122+ found = 1;
73123+ }
73124+ } else
73125+ found = 2;
73126+ if (!found)
73127+ return 0;
73128+
73129+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
73130+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
73131+ *salt = NULL;
73132+ *sum = NULL;
73133+ return 1;
73134+ }
73135+ }
73136+ FOR_EACH_ROLE_END(r)
73137+
73138+ for (i = 0; i < polstate->num_sprole_pws; i++) {
73139+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
73140+ *salt = polstate->acl_special_roles[i]->salt;
73141+ *sum = polstate->acl_special_roles[i]->sum;
73142+ return 1;
73143+ }
73144+ }
73145+
73146+ return 0;
73147+}
73148+
73149+int gr_check_secure_terminal(struct task_struct *task)
73150+{
73151+ struct task_struct *p, *p2, *p3;
73152+ struct files_struct *files;
73153+ struct fdtable *fdt;
73154+ struct file *our_file = NULL, *file;
73155+ int i;
73156+
73157+ if (task->signal->tty == NULL)
73158+ return 1;
73159+
73160+ files = get_files_struct(task);
73161+ if (files != NULL) {
73162+ rcu_read_lock();
73163+ fdt = files_fdtable(files);
73164+ for (i=0; i < fdt->max_fds; i++) {
73165+ file = fcheck_files(files, i);
73166+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
73167+ get_file(file);
73168+ our_file = file;
73169+ }
73170+ }
73171+ rcu_read_unlock();
73172+ put_files_struct(files);
73173+ }
73174+
73175+ if (our_file == NULL)
73176+ return 1;
73177+
73178+ read_lock(&tasklist_lock);
73179+ do_each_thread(p2, p) {
73180+ files = get_files_struct(p);
73181+ if (files == NULL ||
73182+ (p->signal && p->signal->tty == task->signal->tty)) {
73183+ if (files != NULL)
73184+ put_files_struct(files);
73185+ continue;
73186+ }
73187+ rcu_read_lock();
73188+ fdt = files_fdtable(files);
73189+ for (i=0; i < fdt->max_fds; i++) {
73190+ file = fcheck_files(files, i);
73191+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
73192+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
73193+ p3 = task;
73194+ while (task_pid_nr(p3) > 0) {
73195+ if (p3 == p)
73196+ break;
73197+ p3 = p3->real_parent;
73198+ }
73199+ if (p3 == p)
73200+ break;
73201+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
73202+ gr_handle_alertkill(p);
73203+ rcu_read_unlock();
73204+ put_files_struct(files);
73205+ read_unlock(&tasklist_lock);
73206+ fput(our_file);
73207+ return 0;
73208+ }
73209+ }
73210+ rcu_read_unlock();
73211+ put_files_struct(files);
73212+ } while_each_thread(p2, p);
73213+ read_unlock(&tasklist_lock);
73214+
73215+ fput(our_file);
73216+ return 1;
73217+}
73218+
73219+ssize_t
73220+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
73221+{
73222+ struct gr_arg_wrapper uwrap;
73223+ unsigned char *sprole_salt = NULL;
73224+ unsigned char *sprole_sum = NULL;
73225+ int error = 0;
73226+ int error2 = 0;
73227+ size_t req_count = 0;
73228+ unsigned char oldmode = 0;
73229+
73230+ mutex_lock(&gr_dev_mutex);
73231+
73232+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
73233+ error = -EPERM;
73234+ goto out;
73235+ }
73236+
73237+#ifdef CONFIG_COMPAT
73238+ pax_open_kernel();
73239+ if (is_compat_task()) {
73240+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
73241+ copy_gr_arg = &copy_gr_arg_compat;
73242+ copy_acl_object_label = &copy_acl_object_label_compat;
73243+ copy_acl_subject_label = &copy_acl_subject_label_compat;
73244+ copy_acl_role_label = &copy_acl_role_label_compat;
73245+ copy_acl_ip_label = &copy_acl_ip_label_compat;
73246+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
73247+ copy_role_transition = &copy_role_transition_compat;
73248+ copy_sprole_pw = &copy_sprole_pw_compat;
73249+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
73250+ copy_pointer_from_array = &copy_pointer_from_array_compat;
73251+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
73252+ } else {
73253+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
73254+ copy_gr_arg = &copy_gr_arg_normal;
73255+ copy_acl_object_label = &copy_acl_object_label_normal;
73256+ copy_acl_subject_label = &copy_acl_subject_label_normal;
73257+ copy_acl_role_label = &copy_acl_role_label_normal;
73258+ copy_acl_ip_label = &copy_acl_ip_label_normal;
73259+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
73260+ copy_role_transition = &copy_role_transition_normal;
73261+ copy_sprole_pw = &copy_sprole_pw_normal;
73262+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
73263+ copy_pointer_from_array = &copy_pointer_from_array_normal;
73264+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
73265+ }
73266+ pax_close_kernel();
73267+#endif
73268+
73269+ req_count = get_gr_arg_wrapper_size();
73270+
73271+ if (count != req_count) {
73272+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
73273+ error = -EINVAL;
73274+ goto out;
73275+ }
73276+
73277+
73278+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
73279+ gr_auth_expires = 0;
73280+ gr_auth_attempts = 0;
73281+ }
73282+
73283+ error = copy_gr_arg_wrapper(buf, &uwrap);
73284+ if (error)
73285+ goto out;
73286+
73287+ error = copy_gr_arg(uwrap.arg, gr_usermode);
73288+ if (error)
73289+ goto out;
73290+
73291+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
73292+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73293+ time_after(gr_auth_expires, get_seconds())) {
73294+ error = -EBUSY;
73295+ goto out;
73296+ }
73297+
73298+ /* if non-root trying to do anything other than use a special role,
73299+ do not attempt authentication, do not count towards authentication
73300+ locking
73301+ */
73302+
73303+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
73304+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
73305+ gr_is_global_nonroot(current_uid())) {
73306+ error = -EPERM;
73307+ goto out;
73308+ }
73309+
73310+ /* ensure pw and special role name are null terminated */
73311+
73312+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
73313+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
73314+
73315+ /* Okay.
73316+ * We have our enough of the argument structure..(we have yet
73317+ * to copy_from_user the tables themselves) . Copy the tables
73318+ * only if we need them, i.e. for loading operations. */
73319+
73320+ switch (gr_usermode->mode) {
73321+ case GR_STATUS:
73322+ if (gr_acl_is_enabled()) {
73323+ error = 1;
73324+ if (!gr_check_secure_terminal(current))
73325+ error = 3;
73326+ } else
73327+ error = 2;
73328+ goto out;
73329+ case GR_SHUTDOWN:
73330+ if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73331+ stop_machine(gr_rbac_disable, NULL, NULL);
73332+ free_variables(false);
73333+ memset(gr_usermode, 0, sizeof(struct gr_arg));
73334+ memset(gr_system_salt, 0, GR_SALT_LEN);
73335+ memset(gr_system_sum, 0, GR_SHA_LEN);
73336+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
73337+ } else if (gr_acl_is_enabled()) {
73338+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
73339+ error = -EPERM;
73340+ } else {
73341+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
73342+ error = -EAGAIN;
73343+ }
73344+ break;
73345+ case GR_ENABLE:
73346+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
73347+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
73348+ else {
73349+ if (gr_acl_is_enabled())
73350+ error = -EAGAIN;
73351+ else
73352+ error = error2;
73353+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
73354+ }
73355+ break;
73356+ case GR_OLDRELOAD:
73357+ oldmode = 1;
73358+ case GR_RELOAD:
73359+ if (!gr_acl_is_enabled()) {
73360+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
73361+ error = -EAGAIN;
73362+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73363+ error2 = gracl_reload(gr_usermode, oldmode);
73364+ if (!error2)
73365+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
73366+ else {
73367+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73368+ error = error2;
73369+ }
73370+ } else {
73371+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73372+ error = -EPERM;
73373+ }
73374+ break;
73375+ case GR_SEGVMOD:
73376+ if (unlikely(!gr_acl_is_enabled())) {
73377+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
73378+ error = -EAGAIN;
73379+ break;
73380+ }
73381+
73382+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73383+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
73384+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
73385+ struct acl_subject_label *segvacl;
73386+ segvacl =
73387+ lookup_acl_subj_label(gr_usermode->segv_inode,
73388+ gr_usermode->segv_device,
73389+ current->role);
73390+ if (segvacl) {
73391+ segvacl->crashes = 0;
73392+ segvacl->expires = 0;
73393+ }
73394+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
73395+ gr_remove_uid(gr_usermode->segv_uid);
73396+ }
73397+ } else {
73398+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
73399+ error = -EPERM;
73400+ }
73401+ break;
73402+ case GR_SPROLE:
73403+ case GR_SPROLEPAM:
73404+ if (unlikely(!gr_acl_is_enabled())) {
73405+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73406+ error = -EAGAIN;
73407+ break;
73408+ }
73409+
73410+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73411+ current->role->expires = 0;
73412+ current->role->auth_attempts = 0;
73413+ }
73414+
73415+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73416+ time_after(current->role->expires, get_seconds())) {
73417+ error = -EBUSY;
73418+ goto out;
73419+ }
73420+
73421+ if (lookup_special_role_auth
73422+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
73423+ && ((!sprole_salt && !sprole_sum)
73424+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
73425+ char *p = "";
73426+ assign_special_role(gr_usermode->sp_role);
73427+ read_lock(&tasklist_lock);
73428+ if (current->real_parent)
73429+ p = current->real_parent->role->rolename;
73430+ read_unlock(&tasklist_lock);
73431+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73432+ p, acl_sp_role_value);
73433+ } else {
73434+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
73435+ error = -EPERM;
73436+ if(!(current->role->auth_attempts++))
73437+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73438+
73439+ goto out;
73440+ }
73441+ break;
73442+ case GR_UNSPROLE:
73443+ if (unlikely(!gr_acl_is_enabled())) {
73444+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73445+ error = -EAGAIN;
73446+ break;
73447+ }
73448+
73449+ if (current->role->roletype & GR_ROLE_SPECIAL) {
73450+ char *p = "";
73451+ int i = 0;
73452+
73453+ read_lock(&tasklist_lock);
73454+ if (current->real_parent) {
73455+ p = current->real_parent->role->rolename;
73456+ i = current->real_parent->acl_role_id;
73457+ }
73458+ read_unlock(&tasklist_lock);
73459+
73460+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73461+ gr_set_acls(1);
73462+ } else {
73463+ error = -EPERM;
73464+ goto out;
73465+ }
73466+ break;
73467+ default:
73468+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
73469+ error = -EINVAL;
73470+ break;
73471+ }
73472+
73473+ if (error != -EPERM)
73474+ goto out;
73475+
73476+ if(!(gr_auth_attempts++))
73477+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73478+
73479+ out:
73480+ mutex_unlock(&gr_dev_mutex);
73481+
73482+ if (!error)
73483+ error = req_count;
73484+
73485+ return error;
73486+}
73487+
73488+int
73489+gr_set_acls(const int type)
73490+{
73491+ struct task_struct *task, *task2;
73492+ struct acl_role_label *role = current->role;
73493+ struct acl_subject_label *subj;
73494+ __u16 acl_role_id = current->acl_role_id;
73495+ const struct cred *cred;
73496+ int ret;
73497+
73498+ rcu_read_lock();
73499+ read_lock(&tasklist_lock);
73500+ read_lock(&grsec_exec_file_lock);
73501+ do_each_thread(task2, task) {
73502+ /* check to see if we're called from the exit handler,
73503+ if so, only replace ACLs that have inherited the admin
73504+ ACL */
73505+
73506+ if (type && (task->role != role ||
73507+ task->acl_role_id != acl_role_id))
73508+ continue;
73509+
73510+ task->acl_role_id = 0;
73511+ task->acl_sp_role = 0;
73512+ task->inherited = 0;
73513+
73514+ if (task->exec_file) {
73515+ cred = __task_cred(task);
73516+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73517+ subj = __gr_get_subject_for_task(polstate, task, NULL);
73518+ if (subj == NULL) {
73519+ ret = -EINVAL;
73520+ read_unlock(&grsec_exec_file_lock);
73521+ read_unlock(&tasklist_lock);
73522+ rcu_read_unlock();
73523+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73524+ return ret;
73525+ }
73526+ __gr_apply_subject_to_task(polstate, task, subj);
73527+ } else {
73528+ // it's a kernel process
73529+ task->role = polstate->kernel_role;
73530+ task->acl = polstate->kernel_role->root_label;
73531+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73532+ task->acl->mode &= ~GR_PROCFIND;
73533+#endif
73534+ }
73535+ } while_each_thread(task2, task);
73536+ read_unlock(&grsec_exec_file_lock);
73537+ read_unlock(&tasklist_lock);
73538+ rcu_read_unlock();
73539+
73540+ return 0;
73541+}
73542diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73543new file mode 100644
73544index 0000000..39645c9
73545--- /dev/null
73546+++ b/grsecurity/gracl_res.c
73547@@ -0,0 +1,68 @@
73548+#include <linux/kernel.h>
73549+#include <linux/sched.h>
73550+#include <linux/gracl.h>
73551+#include <linux/grinternal.h>
73552+
73553+static const char *restab_log[] = {
73554+ [RLIMIT_CPU] = "RLIMIT_CPU",
73555+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73556+ [RLIMIT_DATA] = "RLIMIT_DATA",
73557+ [RLIMIT_STACK] = "RLIMIT_STACK",
73558+ [RLIMIT_CORE] = "RLIMIT_CORE",
73559+ [RLIMIT_RSS] = "RLIMIT_RSS",
73560+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
73561+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73562+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73563+ [RLIMIT_AS] = "RLIMIT_AS",
73564+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73565+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73566+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73567+ [RLIMIT_NICE] = "RLIMIT_NICE",
73568+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73569+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73570+ [GR_CRASH_RES] = "RLIMIT_CRASH"
73571+};
73572+
73573+void
73574+gr_log_resource(const struct task_struct *task,
73575+ const int res, const unsigned long wanted, const int gt)
73576+{
73577+ const struct cred *cred;
73578+ unsigned long rlim;
73579+
73580+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
73581+ return;
73582+
73583+ // not yet supported resource
73584+ if (unlikely(!restab_log[res]))
73585+ return;
73586+
73587+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73588+ rlim = task_rlimit_max(task, res);
73589+ else
73590+ rlim = task_rlimit(task, res);
73591+
73592+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73593+ return;
73594+
73595+ rcu_read_lock();
73596+ cred = __task_cred(task);
73597+
73598+ if (res == RLIMIT_NPROC &&
73599+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73600+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73601+ goto out_rcu_unlock;
73602+ else if (res == RLIMIT_MEMLOCK &&
73603+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73604+ goto out_rcu_unlock;
73605+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73606+ goto out_rcu_unlock;
73607+ rcu_read_unlock();
73608+
73609+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73610+
73611+ return;
73612+out_rcu_unlock:
73613+ rcu_read_unlock();
73614+ return;
73615+}
73616diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73617new file mode 100644
73618index 0000000..2040e61
73619--- /dev/null
73620+++ b/grsecurity/gracl_segv.c
73621@@ -0,0 +1,313 @@
73622+#include <linux/kernel.h>
73623+#include <linux/mm.h>
73624+#include <asm/uaccess.h>
73625+#include <asm/errno.h>
73626+#include <asm/mman.h>
73627+#include <net/sock.h>
73628+#include <linux/file.h>
73629+#include <linux/fs.h>
73630+#include <linux/net.h>
73631+#include <linux/in.h>
73632+#include <linux/slab.h>
73633+#include <linux/types.h>
73634+#include <linux/sched.h>
73635+#include <linux/timer.h>
73636+#include <linux/gracl.h>
73637+#include <linux/grsecurity.h>
73638+#include <linux/grinternal.h>
73639+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73640+#include <linux/magic.h>
73641+#include <linux/pagemap.h>
73642+#include "../fs/btrfs/async-thread.h"
73643+#include "../fs/btrfs/ctree.h"
73644+#include "../fs/btrfs/btrfs_inode.h"
73645+#endif
73646+
73647+static struct crash_uid *uid_set;
73648+static unsigned short uid_used;
73649+static DEFINE_SPINLOCK(gr_uid_lock);
73650+extern rwlock_t gr_inode_lock;
73651+extern struct acl_subject_label *
73652+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73653+ struct acl_role_label *role);
73654+
73655+static inline dev_t __get_dev(const struct dentry *dentry)
73656+{
73657+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73658+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73659+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
73660+ else
73661+#endif
73662+ return dentry->d_sb->s_dev;
73663+}
73664+
73665+int
73666+gr_init_uidset(void)
73667+{
73668+ uid_set =
73669+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73670+ uid_used = 0;
73671+
73672+ return uid_set ? 1 : 0;
73673+}
73674+
73675+void
73676+gr_free_uidset(void)
73677+{
73678+ if (uid_set) {
73679+ struct crash_uid *tmpset;
73680+ spin_lock(&gr_uid_lock);
73681+ tmpset = uid_set;
73682+ uid_set = NULL;
73683+ uid_used = 0;
73684+ spin_unlock(&gr_uid_lock);
73685+ if (tmpset)
73686+ kfree(tmpset);
73687+ }
73688+
73689+ return;
73690+}
73691+
73692+int
73693+gr_find_uid(const uid_t uid)
73694+{
73695+ struct crash_uid *tmp = uid_set;
73696+ uid_t buid;
73697+ int low = 0, high = uid_used - 1, mid;
73698+
73699+ while (high >= low) {
73700+ mid = (low + high) >> 1;
73701+ buid = tmp[mid].uid;
73702+ if (buid == uid)
73703+ return mid;
73704+ if (buid > uid)
73705+ high = mid - 1;
73706+ if (buid < uid)
73707+ low = mid + 1;
73708+ }
73709+
73710+ return -1;
73711+}
73712+
73713+static __inline__ void
73714+gr_insertsort(void)
73715+{
73716+ unsigned short i, j;
73717+ struct crash_uid index;
73718+
73719+ for (i = 1; i < uid_used; i++) {
73720+ index = uid_set[i];
73721+ j = i;
73722+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73723+ uid_set[j] = uid_set[j - 1];
73724+ j--;
73725+ }
73726+ uid_set[j] = index;
73727+ }
73728+
73729+ return;
73730+}
73731+
73732+static __inline__ void
73733+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73734+{
73735+ int loc;
73736+ uid_t uid = GR_GLOBAL_UID(kuid);
73737+
73738+ if (uid_used == GR_UIDTABLE_MAX)
73739+ return;
73740+
73741+ loc = gr_find_uid(uid);
73742+
73743+ if (loc >= 0) {
73744+ uid_set[loc].expires = expires;
73745+ return;
73746+ }
73747+
73748+ uid_set[uid_used].uid = uid;
73749+ uid_set[uid_used].expires = expires;
73750+ uid_used++;
73751+
73752+ gr_insertsort();
73753+
73754+ return;
73755+}
73756+
73757+void
73758+gr_remove_uid(const unsigned short loc)
73759+{
73760+ unsigned short i;
73761+
73762+ for (i = loc + 1; i < uid_used; i++)
73763+ uid_set[i - 1] = uid_set[i];
73764+
73765+ uid_used--;
73766+
73767+ return;
73768+}
73769+
73770+int
73771+gr_check_crash_uid(const kuid_t kuid)
73772+{
73773+ int loc;
73774+ int ret = 0;
73775+ uid_t uid;
73776+
73777+ if (unlikely(!gr_acl_is_enabled()))
73778+ return 0;
73779+
73780+ uid = GR_GLOBAL_UID(kuid);
73781+
73782+ spin_lock(&gr_uid_lock);
73783+ loc = gr_find_uid(uid);
73784+
73785+ if (loc < 0)
73786+ goto out_unlock;
73787+
73788+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73789+ gr_remove_uid(loc);
73790+ else
73791+ ret = 1;
73792+
73793+out_unlock:
73794+ spin_unlock(&gr_uid_lock);
73795+ return ret;
73796+}
73797+
73798+static __inline__ int
73799+proc_is_setxid(const struct cred *cred)
73800+{
73801+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73802+ !uid_eq(cred->uid, cred->fsuid))
73803+ return 1;
73804+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73805+ !gid_eq(cred->gid, cred->fsgid))
73806+ return 1;
73807+
73808+ return 0;
73809+}
73810+
73811+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73812+
73813+void
73814+gr_handle_crash(struct task_struct *task, const int sig)
73815+{
73816+ struct acl_subject_label *curr;
73817+ struct task_struct *tsk, *tsk2;
73818+ const struct cred *cred;
73819+ const struct cred *cred2;
73820+
73821+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73822+ return;
73823+
73824+ if (unlikely(!gr_acl_is_enabled()))
73825+ return;
73826+
73827+ curr = task->acl;
73828+
73829+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73830+ return;
73831+
73832+ if (time_before_eq(curr->expires, get_seconds())) {
73833+ curr->expires = 0;
73834+ curr->crashes = 0;
73835+ }
73836+
73837+ curr->crashes++;
73838+
73839+ if (!curr->expires)
73840+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73841+
73842+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73843+ time_after(curr->expires, get_seconds())) {
73844+ rcu_read_lock();
73845+ cred = __task_cred(task);
73846+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73847+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73848+ spin_lock(&gr_uid_lock);
73849+ gr_insert_uid(cred->uid, curr->expires);
73850+ spin_unlock(&gr_uid_lock);
73851+ curr->expires = 0;
73852+ curr->crashes = 0;
73853+ read_lock(&tasklist_lock);
73854+ do_each_thread(tsk2, tsk) {
73855+ cred2 = __task_cred(tsk);
73856+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73857+ gr_fake_force_sig(SIGKILL, tsk);
73858+ } while_each_thread(tsk2, tsk);
73859+ read_unlock(&tasklist_lock);
73860+ } else {
73861+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73862+ read_lock(&tasklist_lock);
73863+ read_lock(&grsec_exec_file_lock);
73864+ do_each_thread(tsk2, tsk) {
73865+ if (likely(tsk != task)) {
73866+ // if this thread has the same subject as the one that triggered
73867+ // RES_CRASH and it's the same binary, kill it
73868+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73869+ gr_fake_force_sig(SIGKILL, tsk);
73870+ }
73871+ } while_each_thread(tsk2, tsk);
73872+ read_unlock(&grsec_exec_file_lock);
73873+ read_unlock(&tasklist_lock);
73874+ }
73875+ rcu_read_unlock();
73876+ }
73877+
73878+ return;
73879+}
73880+
73881+int
73882+gr_check_crash_exec(const struct file *filp)
73883+{
73884+ struct acl_subject_label *curr;
73885+
73886+ if (unlikely(!gr_acl_is_enabled()))
73887+ return 0;
73888+
73889+ read_lock(&gr_inode_lock);
73890+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73891+ __get_dev(filp->f_path.dentry),
73892+ current->role);
73893+ read_unlock(&gr_inode_lock);
73894+
73895+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73896+ (!curr->crashes && !curr->expires))
73897+ return 0;
73898+
73899+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73900+ time_after(curr->expires, get_seconds()))
73901+ return 1;
73902+ else if (time_before_eq(curr->expires, get_seconds())) {
73903+ curr->crashes = 0;
73904+ curr->expires = 0;
73905+ }
73906+
73907+ return 0;
73908+}
73909+
73910+void
73911+gr_handle_alertkill(struct task_struct *task)
73912+{
73913+ struct acl_subject_label *curracl;
73914+ __u32 curr_ip;
73915+ struct task_struct *p, *p2;
73916+
73917+ if (unlikely(!gr_acl_is_enabled()))
73918+ return;
73919+
73920+ curracl = task->acl;
73921+ curr_ip = task->signal->curr_ip;
73922+
73923+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73924+ read_lock(&tasklist_lock);
73925+ do_each_thread(p2, p) {
73926+ if (p->signal->curr_ip == curr_ip)
73927+ gr_fake_force_sig(SIGKILL, p);
73928+ } while_each_thread(p2, p);
73929+ read_unlock(&tasklist_lock);
73930+ } else if (curracl->mode & GR_KILLPROC)
73931+ gr_fake_force_sig(SIGKILL, task);
73932+
73933+ return;
73934+}
73935diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73936new file mode 100644
73937index 0000000..98011b0
73938--- /dev/null
73939+++ b/grsecurity/gracl_shm.c
73940@@ -0,0 +1,40 @@
73941+#include <linux/kernel.h>
73942+#include <linux/mm.h>
73943+#include <linux/sched.h>
73944+#include <linux/file.h>
73945+#include <linux/ipc.h>
73946+#include <linux/gracl.h>
73947+#include <linux/grsecurity.h>
73948+#include <linux/grinternal.h>
73949+
73950+int
73951+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73952+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73953+{
73954+ struct task_struct *task;
73955+
73956+ if (!gr_acl_is_enabled())
73957+ return 1;
73958+
73959+ rcu_read_lock();
73960+ read_lock(&tasklist_lock);
73961+
73962+ task = find_task_by_vpid(shm_cprid);
73963+
73964+ if (unlikely(!task))
73965+ task = find_task_by_vpid(shm_lapid);
73966+
73967+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73968+ (task_pid_nr(task) == shm_lapid)) &&
73969+ (task->acl->mode & GR_PROTSHM) &&
73970+ (task->acl != current->acl))) {
73971+ read_unlock(&tasklist_lock);
73972+ rcu_read_unlock();
73973+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73974+ return 0;
73975+ }
73976+ read_unlock(&tasklist_lock);
73977+ rcu_read_unlock();
73978+
73979+ return 1;
73980+}
73981diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73982new file mode 100644
73983index 0000000..bc0be01
73984--- /dev/null
73985+++ b/grsecurity/grsec_chdir.c
73986@@ -0,0 +1,19 @@
73987+#include <linux/kernel.h>
73988+#include <linux/sched.h>
73989+#include <linux/fs.h>
73990+#include <linux/file.h>
73991+#include <linux/grsecurity.h>
73992+#include <linux/grinternal.h>
73993+
73994+void
73995+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73996+{
73997+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73998+ if ((grsec_enable_chdir && grsec_enable_group &&
73999+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
74000+ !grsec_enable_group)) {
74001+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
74002+ }
74003+#endif
74004+ return;
74005+}
74006diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
74007new file mode 100644
74008index 0000000..baa635c
74009--- /dev/null
74010+++ b/grsecurity/grsec_chroot.c
74011@@ -0,0 +1,387 @@
74012+#include <linux/kernel.h>
74013+#include <linux/module.h>
74014+#include <linux/sched.h>
74015+#include <linux/file.h>
74016+#include <linux/fs.h>
74017+#include <linux/mount.h>
74018+#include <linux/types.h>
74019+#include "../fs/mount.h"
74020+#include <linux/grsecurity.h>
74021+#include <linux/grinternal.h>
74022+
74023+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
74024+int gr_init_ran;
74025+#endif
74026+
74027+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
74028+{
74029+#ifdef CONFIG_GRKERNSEC
74030+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
74031+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
74032+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
74033+ && gr_init_ran
74034+#endif
74035+ )
74036+ task->gr_is_chrooted = 1;
74037+ else {
74038+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
74039+ if (task_pid_nr(task) == 1 && !gr_init_ran)
74040+ gr_init_ran = 1;
74041+#endif
74042+ task->gr_is_chrooted = 0;
74043+ }
74044+
74045+ task->gr_chroot_dentry = path->dentry;
74046+#endif
74047+ return;
74048+}
74049+
74050+void gr_clear_chroot_entries(struct task_struct *task)
74051+{
74052+#ifdef CONFIG_GRKERNSEC
74053+ task->gr_is_chrooted = 0;
74054+ task->gr_chroot_dentry = NULL;
74055+#endif
74056+ return;
74057+}
74058+
74059+int
74060+gr_handle_chroot_unix(const pid_t pid)
74061+{
74062+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74063+ struct task_struct *p;
74064+
74065+ if (unlikely(!grsec_enable_chroot_unix))
74066+ return 1;
74067+
74068+ if (likely(!proc_is_chrooted(current)))
74069+ return 1;
74070+
74071+ rcu_read_lock();
74072+ read_lock(&tasklist_lock);
74073+ p = find_task_by_vpid_unrestricted(pid);
74074+ if (unlikely(p && !have_same_root(current, p))) {
74075+ read_unlock(&tasklist_lock);
74076+ rcu_read_unlock();
74077+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
74078+ return 0;
74079+ }
74080+ read_unlock(&tasklist_lock);
74081+ rcu_read_unlock();
74082+#endif
74083+ return 1;
74084+}
74085+
74086+int
74087+gr_handle_chroot_nice(void)
74088+{
74089+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74090+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
74091+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
74092+ return -EPERM;
74093+ }
74094+#endif
74095+ return 0;
74096+}
74097+
74098+int
74099+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
74100+{
74101+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74102+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
74103+ && proc_is_chrooted(current)) {
74104+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
74105+ return -EACCES;
74106+ }
74107+#endif
74108+ return 0;
74109+}
74110+
74111+int
74112+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
74113+{
74114+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74115+ struct task_struct *p;
74116+ int ret = 0;
74117+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
74118+ return ret;
74119+
74120+ read_lock(&tasklist_lock);
74121+ do_each_pid_task(pid, type, p) {
74122+ if (!have_same_root(current, p)) {
74123+ ret = 1;
74124+ goto out;
74125+ }
74126+ } while_each_pid_task(pid, type, p);
74127+out:
74128+ read_unlock(&tasklist_lock);
74129+ return ret;
74130+#endif
74131+ return 0;
74132+}
74133+
74134+int
74135+gr_pid_is_chrooted(struct task_struct *p)
74136+{
74137+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74138+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
74139+ return 0;
74140+
74141+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
74142+ !have_same_root(current, p)) {
74143+ return 1;
74144+ }
74145+#endif
74146+ return 0;
74147+}
74148+
74149+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
74150+
74151+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
74152+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
74153+{
74154+ struct path path, currentroot;
74155+ int ret = 0;
74156+
74157+ path.dentry = (struct dentry *)u_dentry;
74158+ path.mnt = (struct vfsmount *)u_mnt;
74159+ get_fs_root(current->fs, &currentroot);
74160+ if (path_is_under(&path, &currentroot))
74161+ ret = 1;
74162+ path_put(&currentroot);
74163+
74164+ return ret;
74165+}
74166+#endif
74167+
74168+int
74169+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
74170+{
74171+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74172+ if (!grsec_enable_chroot_fchdir)
74173+ return 1;
74174+
74175+ if (!proc_is_chrooted(current))
74176+ return 1;
74177+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
74178+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
74179+ return 0;
74180+ }
74181+#endif
74182+ return 1;
74183+}
74184+
74185+int
74186+gr_chroot_fhandle(void)
74187+{
74188+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74189+ if (!grsec_enable_chroot_fchdir)
74190+ return 1;
74191+
74192+ if (!proc_is_chrooted(current))
74193+ return 1;
74194+ else {
74195+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
74196+ return 0;
74197+ }
74198+#endif
74199+ return 1;
74200+}
74201+
74202+int
74203+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74204+ const time_t shm_createtime)
74205+{
74206+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74207+ struct task_struct *p;
74208+ time_t starttime;
74209+
74210+ if (unlikely(!grsec_enable_chroot_shmat))
74211+ return 1;
74212+
74213+ if (likely(!proc_is_chrooted(current)))
74214+ return 1;
74215+
74216+ rcu_read_lock();
74217+ read_lock(&tasklist_lock);
74218+
74219+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
74220+ starttime = p->start_time.tv_sec;
74221+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
74222+ if (have_same_root(current, p)) {
74223+ goto allow;
74224+ } else {
74225+ read_unlock(&tasklist_lock);
74226+ rcu_read_unlock();
74227+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
74228+ return 0;
74229+ }
74230+ }
74231+ /* creator exited, pid reuse, fall through to next check */
74232+ }
74233+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
74234+ if (unlikely(!have_same_root(current, p))) {
74235+ read_unlock(&tasklist_lock);
74236+ rcu_read_unlock();
74237+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
74238+ return 0;
74239+ }
74240+ }
74241+
74242+allow:
74243+ read_unlock(&tasklist_lock);
74244+ rcu_read_unlock();
74245+#endif
74246+ return 1;
74247+}
74248+
74249+void
74250+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
74251+{
74252+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74253+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
74254+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
74255+#endif
74256+ return;
74257+}
74258+
74259+int
74260+gr_handle_chroot_mknod(const struct dentry *dentry,
74261+ const struct vfsmount *mnt, const int mode)
74262+{
74263+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74264+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
74265+ proc_is_chrooted(current)) {
74266+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
74267+ return -EPERM;
74268+ }
74269+#endif
74270+ return 0;
74271+}
74272+
74273+int
74274+gr_handle_chroot_mount(const struct dentry *dentry,
74275+ const struct vfsmount *mnt, const char *dev_name)
74276+{
74277+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74278+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
74279+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
74280+ return -EPERM;
74281+ }
74282+#endif
74283+ return 0;
74284+}
74285+
74286+int
74287+gr_handle_chroot_pivot(void)
74288+{
74289+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74290+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
74291+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
74292+ return -EPERM;
74293+ }
74294+#endif
74295+ return 0;
74296+}
74297+
74298+int
74299+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
74300+{
74301+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74302+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
74303+ !gr_is_outside_chroot(dentry, mnt)) {
74304+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
74305+ return -EPERM;
74306+ }
74307+#endif
74308+ return 0;
74309+}
74310+
74311+extern const char *captab_log[];
74312+extern int captab_log_entries;
74313+
74314+int
74315+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74316+{
74317+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74318+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74319+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74320+ if (cap_raised(chroot_caps, cap)) {
74321+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
74322+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
74323+ }
74324+ return 0;
74325+ }
74326+ }
74327+#endif
74328+ return 1;
74329+}
74330+
74331+int
74332+gr_chroot_is_capable(const int cap)
74333+{
74334+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74335+ return gr_task_chroot_is_capable(current, current_cred(), cap);
74336+#endif
74337+ return 1;
74338+}
74339+
74340+int
74341+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
74342+{
74343+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74344+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74345+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74346+ if (cap_raised(chroot_caps, cap)) {
74347+ return 0;
74348+ }
74349+ }
74350+#endif
74351+ return 1;
74352+}
74353+
74354+int
74355+gr_chroot_is_capable_nolog(const int cap)
74356+{
74357+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74358+ return gr_task_chroot_is_capable_nolog(current, cap);
74359+#endif
74360+ return 1;
74361+}
74362+
74363+int
74364+gr_handle_chroot_sysctl(const int op)
74365+{
74366+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74367+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
74368+ proc_is_chrooted(current))
74369+ return -EACCES;
74370+#endif
74371+ return 0;
74372+}
74373+
74374+void
74375+gr_handle_chroot_chdir(const struct path *path)
74376+{
74377+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74378+ if (grsec_enable_chroot_chdir)
74379+ set_fs_pwd(current->fs, path);
74380+#endif
74381+ return;
74382+}
74383+
74384+int
74385+gr_handle_chroot_chmod(const struct dentry *dentry,
74386+ const struct vfsmount *mnt, const int mode)
74387+{
74388+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74389+ /* allow chmod +s on directories, but not files */
74390+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
74391+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
74392+ proc_is_chrooted(current)) {
74393+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
74394+ return -EPERM;
74395+ }
74396+#endif
74397+ return 0;
74398+}
74399diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
74400new file mode 100644
74401index 0000000..de31e65
74402--- /dev/null
74403+++ b/grsecurity/grsec_disabled.c
74404@@ -0,0 +1,434 @@
74405+#include <linux/kernel.h>
74406+#include <linux/module.h>
74407+#include <linux/sched.h>
74408+#include <linux/file.h>
74409+#include <linux/fs.h>
74410+#include <linux/kdev_t.h>
74411+#include <linux/net.h>
74412+#include <linux/in.h>
74413+#include <linux/ip.h>
74414+#include <linux/skbuff.h>
74415+#include <linux/sysctl.h>
74416+
74417+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74418+void
74419+pax_set_initial_flags(struct linux_binprm *bprm)
74420+{
74421+ return;
74422+}
74423+#endif
74424+
74425+#ifdef CONFIG_SYSCTL
74426+__u32
74427+gr_handle_sysctl(const struct ctl_table * table, const int op)
74428+{
74429+ return 0;
74430+}
74431+#endif
74432+
74433+#ifdef CONFIG_TASKSTATS
74434+int gr_is_taskstats_denied(int pid)
74435+{
74436+ return 0;
74437+}
74438+#endif
74439+
74440+int
74441+gr_acl_is_enabled(void)
74442+{
74443+ return 0;
74444+}
74445+
74446+void
74447+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74448+{
74449+ return;
74450+}
74451+
74452+int
74453+gr_handle_rawio(const struct inode *inode)
74454+{
74455+ return 0;
74456+}
74457+
74458+void
74459+gr_acl_handle_psacct(struct task_struct *task, const long code)
74460+{
74461+ return;
74462+}
74463+
74464+int
74465+gr_handle_ptrace(struct task_struct *task, const long request)
74466+{
74467+ return 0;
74468+}
74469+
74470+int
74471+gr_handle_proc_ptrace(struct task_struct *task)
74472+{
74473+ return 0;
74474+}
74475+
74476+int
74477+gr_set_acls(const int type)
74478+{
74479+ return 0;
74480+}
74481+
74482+int
74483+gr_check_hidden_task(const struct task_struct *tsk)
74484+{
74485+ return 0;
74486+}
74487+
74488+int
74489+gr_check_protected_task(const struct task_struct *task)
74490+{
74491+ return 0;
74492+}
74493+
74494+int
74495+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74496+{
74497+ return 0;
74498+}
74499+
74500+void
74501+gr_copy_label(struct task_struct *tsk)
74502+{
74503+ return;
74504+}
74505+
74506+void
74507+gr_set_pax_flags(struct task_struct *task)
74508+{
74509+ return;
74510+}
74511+
74512+int
74513+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74514+ const int unsafe_share)
74515+{
74516+ return 0;
74517+}
74518+
74519+void
74520+gr_handle_delete(const ino_t ino, const dev_t dev)
74521+{
74522+ return;
74523+}
74524+
74525+void
74526+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74527+{
74528+ return;
74529+}
74530+
74531+void
74532+gr_handle_crash(struct task_struct *task, const int sig)
74533+{
74534+ return;
74535+}
74536+
74537+int
74538+gr_check_crash_exec(const struct file *filp)
74539+{
74540+ return 0;
74541+}
74542+
74543+int
74544+gr_check_crash_uid(const kuid_t uid)
74545+{
74546+ return 0;
74547+}
74548+
74549+void
74550+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74551+ struct dentry *old_dentry,
74552+ struct dentry *new_dentry,
74553+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
74554+{
74555+ return;
74556+}
74557+
74558+int
74559+gr_search_socket(const int family, const int type, const int protocol)
74560+{
74561+ return 1;
74562+}
74563+
74564+int
74565+gr_search_connectbind(const int mode, const struct socket *sock,
74566+ const struct sockaddr_in *addr)
74567+{
74568+ return 0;
74569+}
74570+
74571+void
74572+gr_handle_alertkill(struct task_struct *task)
74573+{
74574+ return;
74575+}
74576+
74577+__u32
74578+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74579+{
74580+ return 1;
74581+}
74582+
74583+__u32
74584+gr_acl_handle_hidden_file(const struct dentry * dentry,
74585+ const struct vfsmount * mnt)
74586+{
74587+ return 1;
74588+}
74589+
74590+__u32
74591+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74592+ int acc_mode)
74593+{
74594+ return 1;
74595+}
74596+
74597+__u32
74598+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74599+{
74600+ return 1;
74601+}
74602+
74603+__u32
74604+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74605+{
74606+ return 1;
74607+}
74608+
74609+int
74610+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74611+ unsigned int *vm_flags)
74612+{
74613+ return 1;
74614+}
74615+
74616+__u32
74617+gr_acl_handle_truncate(const struct dentry * dentry,
74618+ const struct vfsmount * mnt)
74619+{
74620+ return 1;
74621+}
74622+
74623+__u32
74624+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74625+{
74626+ return 1;
74627+}
74628+
74629+__u32
74630+gr_acl_handle_access(const struct dentry * dentry,
74631+ const struct vfsmount * mnt, const int fmode)
74632+{
74633+ return 1;
74634+}
74635+
74636+__u32
74637+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74638+ umode_t *mode)
74639+{
74640+ return 1;
74641+}
74642+
74643+__u32
74644+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74645+{
74646+ return 1;
74647+}
74648+
74649+__u32
74650+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74651+{
74652+ return 1;
74653+}
74654+
74655+__u32
74656+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74657+{
74658+ return 1;
74659+}
74660+
74661+void
74662+grsecurity_init(void)
74663+{
74664+ return;
74665+}
74666+
74667+umode_t gr_acl_umask(void)
74668+{
74669+ return 0;
74670+}
74671+
74672+__u32
74673+gr_acl_handle_mknod(const struct dentry * new_dentry,
74674+ const struct dentry * parent_dentry,
74675+ const struct vfsmount * parent_mnt,
74676+ const int mode)
74677+{
74678+ return 1;
74679+}
74680+
74681+__u32
74682+gr_acl_handle_mkdir(const struct dentry * new_dentry,
74683+ const struct dentry * parent_dentry,
74684+ const struct vfsmount * parent_mnt)
74685+{
74686+ return 1;
74687+}
74688+
74689+__u32
74690+gr_acl_handle_symlink(const struct dentry * new_dentry,
74691+ const struct dentry * parent_dentry,
74692+ const struct vfsmount * parent_mnt, const struct filename *from)
74693+{
74694+ return 1;
74695+}
74696+
74697+__u32
74698+gr_acl_handle_link(const struct dentry * new_dentry,
74699+ const struct dentry * parent_dentry,
74700+ const struct vfsmount * parent_mnt,
74701+ const struct dentry * old_dentry,
74702+ const struct vfsmount * old_mnt, const struct filename *to)
74703+{
74704+ return 1;
74705+}
74706+
74707+int
74708+gr_acl_handle_rename(const struct dentry *new_dentry,
74709+ const struct dentry *parent_dentry,
74710+ const struct vfsmount *parent_mnt,
74711+ const struct dentry *old_dentry,
74712+ const struct inode *old_parent_inode,
74713+ const struct vfsmount *old_mnt, const struct filename *newname,
74714+ unsigned int flags)
74715+{
74716+ return 0;
74717+}
74718+
74719+int
74720+gr_acl_handle_filldir(const struct file *file, const char *name,
74721+ const int namelen, const ino_t ino)
74722+{
74723+ return 1;
74724+}
74725+
74726+int
74727+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74728+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74729+{
74730+ return 1;
74731+}
74732+
74733+int
74734+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74735+{
74736+ return 0;
74737+}
74738+
74739+int
74740+gr_search_accept(const struct socket *sock)
74741+{
74742+ return 0;
74743+}
74744+
74745+int
74746+gr_search_listen(const struct socket *sock)
74747+{
74748+ return 0;
74749+}
74750+
74751+int
74752+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74753+{
74754+ return 0;
74755+}
74756+
74757+__u32
74758+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74759+{
74760+ return 1;
74761+}
74762+
74763+__u32
74764+gr_acl_handle_creat(const struct dentry * dentry,
74765+ const struct dentry * p_dentry,
74766+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74767+ const int imode)
74768+{
74769+ return 1;
74770+}
74771+
74772+void
74773+gr_acl_handle_exit(void)
74774+{
74775+ return;
74776+}
74777+
74778+int
74779+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74780+{
74781+ return 1;
74782+}
74783+
74784+void
74785+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74786+{
74787+ return;
74788+}
74789+
74790+int
74791+gr_acl_handle_procpidmem(const struct task_struct *task)
74792+{
74793+ return 0;
74794+}
74795+
74796+int
74797+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74798+{
74799+ return 0;
74800+}
74801+
74802+int
74803+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74804+{
74805+ return 0;
74806+}
74807+
74808+int
74809+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74810+{
74811+ return 0;
74812+}
74813+
74814+int
74815+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74816+{
74817+ return 0;
74818+}
74819+
74820+int gr_acl_enable_at_secure(void)
74821+{
74822+ return 0;
74823+}
74824+
74825+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74826+{
74827+ return dentry->d_sb->s_dev;
74828+}
74829+
74830+void gr_put_exec_file(struct task_struct *task)
74831+{
74832+ return;
74833+}
74834+
74835+#ifdef CONFIG_SECURITY
74836+EXPORT_SYMBOL_GPL(gr_check_user_change);
74837+EXPORT_SYMBOL_GPL(gr_check_group_change);
74838+#endif
74839diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74840new file mode 100644
74841index 0000000..14638ff
74842--- /dev/null
74843+++ b/grsecurity/grsec_exec.c
74844@@ -0,0 +1,188 @@
74845+#include <linux/kernel.h>
74846+#include <linux/sched.h>
74847+#include <linux/file.h>
74848+#include <linux/binfmts.h>
74849+#include <linux/fs.h>
74850+#include <linux/types.h>
74851+#include <linux/grdefs.h>
74852+#include <linux/grsecurity.h>
74853+#include <linux/grinternal.h>
74854+#include <linux/capability.h>
74855+#include <linux/module.h>
74856+#include <linux/compat.h>
74857+
74858+#include <asm/uaccess.h>
74859+
74860+#ifdef CONFIG_GRKERNSEC_EXECLOG
74861+static char gr_exec_arg_buf[132];
74862+static DEFINE_MUTEX(gr_exec_arg_mutex);
74863+#endif
74864+
74865+struct user_arg_ptr {
74866+#ifdef CONFIG_COMPAT
74867+ bool is_compat;
74868+#endif
74869+ union {
74870+ const char __user *const __user *native;
74871+#ifdef CONFIG_COMPAT
74872+ const compat_uptr_t __user *compat;
74873+#endif
74874+ } ptr;
74875+};
74876+
74877+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74878+
74879+void
74880+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74881+{
74882+#ifdef CONFIG_GRKERNSEC_EXECLOG
74883+ char *grarg = gr_exec_arg_buf;
74884+ unsigned int i, x, execlen = 0;
74885+ char c;
74886+
74887+ if (!((grsec_enable_execlog && grsec_enable_group &&
74888+ in_group_p(grsec_audit_gid))
74889+ || (grsec_enable_execlog && !grsec_enable_group)))
74890+ return;
74891+
74892+ mutex_lock(&gr_exec_arg_mutex);
74893+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74894+
74895+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74896+ const char __user *p;
74897+ unsigned int len;
74898+
74899+ p = get_user_arg_ptr(argv, i);
74900+ if (IS_ERR(p))
74901+ goto log;
74902+
74903+ len = strnlen_user(p, 128 - execlen);
74904+ if (len > 128 - execlen)
74905+ len = 128 - execlen;
74906+ else if (len > 0)
74907+ len--;
74908+ if (copy_from_user(grarg + execlen, p, len))
74909+ goto log;
74910+
74911+ /* rewrite unprintable characters */
74912+ for (x = 0; x < len; x++) {
74913+ c = *(grarg + execlen + x);
74914+ if (c < 32 || c > 126)
74915+ *(grarg + execlen + x) = ' ';
74916+ }
74917+
74918+ execlen += len;
74919+ *(grarg + execlen) = ' ';
74920+ *(grarg + execlen + 1) = '\0';
74921+ execlen++;
74922+ }
74923+
74924+ log:
74925+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74926+ bprm->file->f_path.mnt, grarg);
74927+ mutex_unlock(&gr_exec_arg_mutex);
74928+#endif
74929+ return;
74930+}
74931+
74932+#ifdef CONFIG_GRKERNSEC
74933+extern int gr_acl_is_capable(const int cap);
74934+extern int gr_acl_is_capable_nolog(const int cap);
74935+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74936+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74937+extern int gr_chroot_is_capable(const int cap);
74938+extern int gr_chroot_is_capable_nolog(const int cap);
74939+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74940+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74941+#endif
74942+
74943+const char *captab_log[] = {
74944+ "CAP_CHOWN",
74945+ "CAP_DAC_OVERRIDE",
74946+ "CAP_DAC_READ_SEARCH",
74947+ "CAP_FOWNER",
74948+ "CAP_FSETID",
74949+ "CAP_KILL",
74950+ "CAP_SETGID",
74951+ "CAP_SETUID",
74952+ "CAP_SETPCAP",
74953+ "CAP_LINUX_IMMUTABLE",
74954+ "CAP_NET_BIND_SERVICE",
74955+ "CAP_NET_BROADCAST",
74956+ "CAP_NET_ADMIN",
74957+ "CAP_NET_RAW",
74958+ "CAP_IPC_LOCK",
74959+ "CAP_IPC_OWNER",
74960+ "CAP_SYS_MODULE",
74961+ "CAP_SYS_RAWIO",
74962+ "CAP_SYS_CHROOT",
74963+ "CAP_SYS_PTRACE",
74964+ "CAP_SYS_PACCT",
74965+ "CAP_SYS_ADMIN",
74966+ "CAP_SYS_BOOT",
74967+ "CAP_SYS_NICE",
74968+ "CAP_SYS_RESOURCE",
74969+ "CAP_SYS_TIME",
74970+ "CAP_SYS_TTY_CONFIG",
74971+ "CAP_MKNOD",
74972+ "CAP_LEASE",
74973+ "CAP_AUDIT_WRITE",
74974+ "CAP_AUDIT_CONTROL",
74975+ "CAP_SETFCAP",
74976+ "CAP_MAC_OVERRIDE",
74977+ "CAP_MAC_ADMIN",
74978+ "CAP_SYSLOG",
74979+ "CAP_WAKE_ALARM",
74980+ "CAP_BLOCK_SUSPEND"
74981+};
74982+
74983+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74984+
74985+int gr_is_capable(const int cap)
74986+{
74987+#ifdef CONFIG_GRKERNSEC
74988+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74989+ return 1;
74990+ return 0;
74991+#else
74992+ return 1;
74993+#endif
74994+}
74995+
74996+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74997+{
74998+#ifdef CONFIG_GRKERNSEC
74999+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
75000+ return 1;
75001+ return 0;
75002+#else
75003+ return 1;
75004+#endif
75005+}
75006+
75007+int gr_is_capable_nolog(const int cap)
75008+{
75009+#ifdef CONFIG_GRKERNSEC
75010+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
75011+ return 1;
75012+ return 0;
75013+#else
75014+ return 1;
75015+#endif
75016+}
75017+
75018+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
75019+{
75020+#ifdef CONFIG_GRKERNSEC
75021+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
75022+ return 1;
75023+ return 0;
75024+#else
75025+ return 1;
75026+#endif
75027+}
75028+
75029+EXPORT_SYMBOL_GPL(gr_is_capable);
75030+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
75031+EXPORT_SYMBOL_GPL(gr_task_is_capable);
75032+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
75033diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
75034new file mode 100644
75035index 0000000..06cc6ea
75036--- /dev/null
75037+++ b/grsecurity/grsec_fifo.c
75038@@ -0,0 +1,24 @@
75039+#include <linux/kernel.h>
75040+#include <linux/sched.h>
75041+#include <linux/fs.h>
75042+#include <linux/file.h>
75043+#include <linux/grinternal.h>
75044+
75045+int
75046+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
75047+ const struct dentry *dir, const int flag, const int acc_mode)
75048+{
75049+#ifdef CONFIG_GRKERNSEC_FIFO
75050+ const struct cred *cred = current_cred();
75051+
75052+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
75053+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
75054+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
75055+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
75056+ if (!inode_permission(dentry->d_inode, acc_mode))
75057+ 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));
75058+ return -EACCES;
75059+ }
75060+#endif
75061+ return 0;
75062+}
75063diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
75064new file mode 100644
75065index 0000000..8ca18bf
75066--- /dev/null
75067+++ b/grsecurity/grsec_fork.c
75068@@ -0,0 +1,23 @@
75069+#include <linux/kernel.h>
75070+#include <linux/sched.h>
75071+#include <linux/grsecurity.h>
75072+#include <linux/grinternal.h>
75073+#include <linux/errno.h>
75074+
75075+void
75076+gr_log_forkfail(const int retval)
75077+{
75078+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75079+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
75080+ switch (retval) {
75081+ case -EAGAIN:
75082+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
75083+ break;
75084+ case -ENOMEM:
75085+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
75086+ break;
75087+ }
75088+ }
75089+#endif
75090+ return;
75091+}
75092diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
75093new file mode 100644
75094index 0000000..b7cb191
75095--- /dev/null
75096+++ b/grsecurity/grsec_init.c
75097@@ -0,0 +1,286 @@
75098+#include <linux/kernel.h>
75099+#include <linux/sched.h>
75100+#include <linux/mm.h>
75101+#include <linux/gracl.h>
75102+#include <linux/slab.h>
75103+#include <linux/vmalloc.h>
75104+#include <linux/percpu.h>
75105+#include <linux/module.h>
75106+
75107+int grsec_enable_ptrace_readexec;
75108+int grsec_enable_setxid;
75109+int grsec_enable_symlinkown;
75110+kgid_t grsec_symlinkown_gid;
75111+int grsec_enable_brute;
75112+int grsec_enable_link;
75113+int grsec_enable_dmesg;
75114+int grsec_enable_harden_ptrace;
75115+int grsec_enable_harden_ipc;
75116+int grsec_enable_fifo;
75117+int grsec_enable_execlog;
75118+int grsec_enable_signal;
75119+int grsec_enable_forkfail;
75120+int grsec_enable_audit_ptrace;
75121+int grsec_enable_time;
75122+int grsec_enable_group;
75123+kgid_t grsec_audit_gid;
75124+int grsec_enable_chdir;
75125+int grsec_enable_mount;
75126+int grsec_enable_rofs;
75127+int grsec_deny_new_usb;
75128+int grsec_enable_chroot_findtask;
75129+int grsec_enable_chroot_mount;
75130+int grsec_enable_chroot_shmat;
75131+int grsec_enable_chroot_fchdir;
75132+int grsec_enable_chroot_double;
75133+int grsec_enable_chroot_pivot;
75134+int grsec_enable_chroot_chdir;
75135+int grsec_enable_chroot_chmod;
75136+int grsec_enable_chroot_mknod;
75137+int grsec_enable_chroot_nice;
75138+int grsec_enable_chroot_execlog;
75139+int grsec_enable_chroot_caps;
75140+int grsec_enable_chroot_sysctl;
75141+int grsec_enable_chroot_unix;
75142+int grsec_enable_tpe;
75143+kgid_t grsec_tpe_gid;
75144+int grsec_enable_blackhole;
75145+#ifdef CONFIG_IPV6_MODULE
75146+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
75147+#endif
75148+int grsec_lastack_retries;
75149+int grsec_enable_tpe_all;
75150+int grsec_enable_tpe_invert;
75151+int grsec_enable_socket_all;
75152+kgid_t grsec_socket_all_gid;
75153+int grsec_enable_socket_client;
75154+kgid_t grsec_socket_client_gid;
75155+int grsec_enable_socket_server;
75156+kgid_t grsec_socket_server_gid;
75157+int grsec_resource_logging;
75158+int grsec_disable_privio;
75159+int grsec_enable_log_rwxmaps;
75160+int grsec_lock;
75161+
75162+DEFINE_SPINLOCK(grsec_alert_lock);
75163+unsigned long grsec_alert_wtime = 0;
75164+unsigned long grsec_alert_fyet = 0;
75165+
75166+DEFINE_SPINLOCK(grsec_audit_lock);
75167+
75168+DEFINE_RWLOCK(grsec_exec_file_lock);
75169+
75170+char *gr_shared_page[4];
75171+
75172+char *gr_alert_log_fmt;
75173+char *gr_audit_log_fmt;
75174+char *gr_alert_log_buf;
75175+char *gr_audit_log_buf;
75176+
75177+extern struct gr_arg *gr_usermode;
75178+extern unsigned char *gr_system_salt;
75179+extern unsigned char *gr_system_sum;
75180+
75181+void __init
75182+grsecurity_init(void)
75183+{
75184+ int j;
75185+ /* create the per-cpu shared pages */
75186+
75187+#ifdef CONFIG_X86
75188+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
75189+#endif
75190+
75191+ for (j = 0; j < 4; j++) {
75192+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
75193+ if (gr_shared_page[j] == NULL) {
75194+ panic("Unable to allocate grsecurity shared page");
75195+ return;
75196+ }
75197+ }
75198+
75199+ /* allocate log buffers */
75200+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
75201+ if (!gr_alert_log_fmt) {
75202+ panic("Unable to allocate grsecurity alert log format buffer");
75203+ return;
75204+ }
75205+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
75206+ if (!gr_audit_log_fmt) {
75207+ panic("Unable to allocate grsecurity audit log format buffer");
75208+ return;
75209+ }
75210+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
75211+ if (!gr_alert_log_buf) {
75212+ panic("Unable to allocate grsecurity alert log buffer");
75213+ return;
75214+ }
75215+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
75216+ if (!gr_audit_log_buf) {
75217+ panic("Unable to allocate grsecurity audit log buffer");
75218+ return;
75219+ }
75220+
75221+ /* allocate memory for authentication structure */
75222+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
75223+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
75224+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
75225+
75226+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
75227+ panic("Unable to allocate grsecurity authentication structure");
75228+ return;
75229+ }
75230+
75231+#ifdef CONFIG_GRKERNSEC_IO
75232+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
75233+ grsec_disable_privio = 1;
75234+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
75235+ grsec_disable_privio = 1;
75236+#else
75237+ grsec_disable_privio = 0;
75238+#endif
75239+#endif
75240+
75241+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75242+ /* for backward compatibility, tpe_invert always defaults to on if
75243+ enabled in the kernel
75244+ */
75245+ grsec_enable_tpe_invert = 1;
75246+#endif
75247+
75248+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
75249+#ifndef CONFIG_GRKERNSEC_SYSCTL
75250+ grsec_lock = 1;
75251+#endif
75252+
75253+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75254+ grsec_enable_log_rwxmaps = 1;
75255+#endif
75256+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75257+ grsec_enable_group = 1;
75258+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
75259+#endif
75260+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75261+ grsec_enable_ptrace_readexec = 1;
75262+#endif
75263+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75264+ grsec_enable_chdir = 1;
75265+#endif
75266+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75267+ grsec_enable_harden_ptrace = 1;
75268+#endif
75269+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75270+ grsec_enable_harden_ipc = 1;
75271+#endif
75272+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75273+ grsec_enable_mount = 1;
75274+#endif
75275+#ifdef CONFIG_GRKERNSEC_LINK
75276+ grsec_enable_link = 1;
75277+#endif
75278+#ifdef CONFIG_GRKERNSEC_BRUTE
75279+ grsec_enable_brute = 1;
75280+#endif
75281+#ifdef CONFIG_GRKERNSEC_DMESG
75282+ grsec_enable_dmesg = 1;
75283+#endif
75284+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75285+ grsec_enable_blackhole = 1;
75286+ grsec_lastack_retries = 4;
75287+#endif
75288+#ifdef CONFIG_GRKERNSEC_FIFO
75289+ grsec_enable_fifo = 1;
75290+#endif
75291+#ifdef CONFIG_GRKERNSEC_EXECLOG
75292+ grsec_enable_execlog = 1;
75293+#endif
75294+#ifdef CONFIG_GRKERNSEC_SETXID
75295+ grsec_enable_setxid = 1;
75296+#endif
75297+#ifdef CONFIG_GRKERNSEC_SIGNAL
75298+ grsec_enable_signal = 1;
75299+#endif
75300+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75301+ grsec_enable_forkfail = 1;
75302+#endif
75303+#ifdef CONFIG_GRKERNSEC_TIME
75304+ grsec_enable_time = 1;
75305+#endif
75306+#ifdef CONFIG_GRKERNSEC_RESLOG
75307+ grsec_resource_logging = 1;
75308+#endif
75309+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75310+ grsec_enable_chroot_findtask = 1;
75311+#endif
75312+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75313+ grsec_enable_chroot_unix = 1;
75314+#endif
75315+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75316+ grsec_enable_chroot_mount = 1;
75317+#endif
75318+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75319+ grsec_enable_chroot_fchdir = 1;
75320+#endif
75321+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75322+ grsec_enable_chroot_shmat = 1;
75323+#endif
75324+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75325+ grsec_enable_audit_ptrace = 1;
75326+#endif
75327+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75328+ grsec_enable_chroot_double = 1;
75329+#endif
75330+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75331+ grsec_enable_chroot_pivot = 1;
75332+#endif
75333+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75334+ grsec_enable_chroot_chdir = 1;
75335+#endif
75336+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75337+ grsec_enable_chroot_chmod = 1;
75338+#endif
75339+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75340+ grsec_enable_chroot_mknod = 1;
75341+#endif
75342+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75343+ grsec_enable_chroot_nice = 1;
75344+#endif
75345+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75346+ grsec_enable_chroot_execlog = 1;
75347+#endif
75348+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75349+ grsec_enable_chroot_caps = 1;
75350+#endif
75351+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75352+ grsec_enable_chroot_sysctl = 1;
75353+#endif
75354+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75355+ grsec_enable_symlinkown = 1;
75356+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
75357+#endif
75358+#ifdef CONFIG_GRKERNSEC_TPE
75359+ grsec_enable_tpe = 1;
75360+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
75361+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75362+ grsec_enable_tpe_all = 1;
75363+#endif
75364+#endif
75365+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75366+ grsec_enable_socket_all = 1;
75367+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
75368+#endif
75369+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75370+ grsec_enable_socket_client = 1;
75371+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
75372+#endif
75373+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75374+ grsec_enable_socket_server = 1;
75375+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
75376+#endif
75377+#endif
75378+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
75379+ grsec_deny_new_usb = 1;
75380+#endif
75381+
75382+ return;
75383+}
75384diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
75385new file mode 100644
75386index 0000000..1773300
75387--- /dev/null
75388+++ b/grsecurity/grsec_ipc.c
75389@@ -0,0 +1,48 @@
75390+#include <linux/kernel.h>
75391+#include <linux/mm.h>
75392+#include <linux/sched.h>
75393+#include <linux/file.h>
75394+#include <linux/ipc.h>
75395+#include <linux/ipc_namespace.h>
75396+#include <linux/grsecurity.h>
75397+#include <linux/grinternal.h>
75398+
75399+int
75400+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
75401+{
75402+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75403+ int write;
75404+ int orig_granted_mode;
75405+ kuid_t euid;
75406+ kgid_t egid;
75407+
75408+ if (!grsec_enable_harden_ipc)
75409+ return 1;
75410+
75411+ euid = current_euid();
75412+ egid = current_egid();
75413+
75414+ write = requested_mode & 00002;
75415+ orig_granted_mode = ipcp->mode;
75416+
75417+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
75418+ orig_granted_mode >>= 6;
75419+ else {
75420+ /* if likely wrong permissions, lock to user */
75421+ if (orig_granted_mode & 0007)
75422+ orig_granted_mode = 0;
75423+ /* otherwise do a egid-only check */
75424+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
75425+ orig_granted_mode >>= 3;
75426+ /* otherwise, no access */
75427+ else
75428+ orig_granted_mode = 0;
75429+ }
75430+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
75431+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
75432+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
75433+ return 0;
75434+ }
75435+#endif
75436+ return 1;
75437+}
75438diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75439new file mode 100644
75440index 0000000..5e05e20
75441--- /dev/null
75442+++ b/grsecurity/grsec_link.c
75443@@ -0,0 +1,58 @@
75444+#include <linux/kernel.h>
75445+#include <linux/sched.h>
75446+#include <linux/fs.h>
75447+#include <linux/file.h>
75448+#include <linux/grinternal.h>
75449+
75450+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75451+{
75452+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75453+ const struct inode *link_inode = link->dentry->d_inode;
75454+
75455+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75456+ /* ignore root-owned links, e.g. /proc/self */
75457+ gr_is_global_nonroot(link_inode->i_uid) && target &&
75458+ !uid_eq(link_inode->i_uid, target->i_uid)) {
75459+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75460+ return 1;
75461+ }
75462+#endif
75463+ return 0;
75464+}
75465+
75466+int
75467+gr_handle_follow_link(const struct inode *parent,
75468+ const struct inode *inode,
75469+ const struct dentry *dentry, const struct vfsmount *mnt)
75470+{
75471+#ifdef CONFIG_GRKERNSEC_LINK
75472+ const struct cred *cred = current_cred();
75473+
75474+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75475+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75476+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75477+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75478+ return -EACCES;
75479+ }
75480+#endif
75481+ return 0;
75482+}
75483+
75484+int
75485+gr_handle_hardlink(const struct dentry *dentry,
75486+ const struct vfsmount *mnt,
75487+ struct inode *inode, const int mode, const struct filename *to)
75488+{
75489+#ifdef CONFIG_GRKERNSEC_LINK
75490+ const struct cred *cred = current_cred();
75491+
75492+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75493+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75494+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75495+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75496+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75497+ return -EPERM;
75498+ }
75499+#endif
75500+ return 0;
75501+}
75502diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75503new file mode 100644
75504index 0000000..dbe0a6b
75505--- /dev/null
75506+++ b/grsecurity/grsec_log.c
75507@@ -0,0 +1,341 @@
75508+#include <linux/kernel.h>
75509+#include <linux/sched.h>
75510+#include <linux/file.h>
75511+#include <linux/tty.h>
75512+#include <linux/fs.h>
75513+#include <linux/mm.h>
75514+#include <linux/grinternal.h>
75515+
75516+#ifdef CONFIG_TREE_PREEMPT_RCU
75517+#define DISABLE_PREEMPT() preempt_disable()
75518+#define ENABLE_PREEMPT() preempt_enable()
75519+#else
75520+#define DISABLE_PREEMPT()
75521+#define ENABLE_PREEMPT()
75522+#endif
75523+
75524+#define BEGIN_LOCKS(x) \
75525+ DISABLE_PREEMPT(); \
75526+ rcu_read_lock(); \
75527+ read_lock(&tasklist_lock); \
75528+ read_lock(&grsec_exec_file_lock); \
75529+ if (x != GR_DO_AUDIT) \
75530+ spin_lock(&grsec_alert_lock); \
75531+ else \
75532+ spin_lock(&grsec_audit_lock)
75533+
75534+#define END_LOCKS(x) \
75535+ if (x != GR_DO_AUDIT) \
75536+ spin_unlock(&grsec_alert_lock); \
75537+ else \
75538+ spin_unlock(&grsec_audit_lock); \
75539+ read_unlock(&grsec_exec_file_lock); \
75540+ read_unlock(&tasklist_lock); \
75541+ rcu_read_unlock(); \
75542+ ENABLE_PREEMPT(); \
75543+ if (x == GR_DONT_AUDIT) \
75544+ gr_handle_alertkill(current)
75545+
75546+enum {
75547+ FLOODING,
75548+ NO_FLOODING
75549+};
75550+
75551+extern char *gr_alert_log_fmt;
75552+extern char *gr_audit_log_fmt;
75553+extern char *gr_alert_log_buf;
75554+extern char *gr_audit_log_buf;
75555+
75556+static int gr_log_start(int audit)
75557+{
75558+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75559+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75560+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75561+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75562+ unsigned long curr_secs = get_seconds();
75563+
75564+ if (audit == GR_DO_AUDIT)
75565+ goto set_fmt;
75566+
75567+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75568+ grsec_alert_wtime = curr_secs;
75569+ grsec_alert_fyet = 0;
75570+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75571+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75572+ grsec_alert_fyet++;
75573+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75574+ grsec_alert_wtime = curr_secs;
75575+ grsec_alert_fyet++;
75576+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75577+ return FLOODING;
75578+ }
75579+ else return FLOODING;
75580+
75581+set_fmt:
75582+#endif
75583+ memset(buf, 0, PAGE_SIZE);
75584+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
75585+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75586+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75587+ } else if (current->signal->curr_ip) {
75588+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75589+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75590+ } else if (gr_acl_is_enabled()) {
75591+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75592+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75593+ } else {
75594+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
75595+ strcpy(buf, fmt);
75596+ }
75597+
75598+ return NO_FLOODING;
75599+}
75600+
75601+static void gr_log_middle(int audit, const char *msg, va_list ap)
75602+ __attribute__ ((format (printf, 2, 0)));
75603+
75604+static void gr_log_middle(int audit, const char *msg, va_list ap)
75605+{
75606+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75607+ unsigned int len = strlen(buf);
75608+
75609+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75610+
75611+ return;
75612+}
75613+
75614+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75615+ __attribute__ ((format (printf, 2, 3)));
75616+
75617+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75618+{
75619+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75620+ unsigned int len = strlen(buf);
75621+ va_list ap;
75622+
75623+ va_start(ap, msg);
75624+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75625+ va_end(ap);
75626+
75627+ return;
75628+}
75629+
75630+static void gr_log_end(int audit, int append_default)
75631+{
75632+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75633+ if (append_default) {
75634+ struct task_struct *task = current;
75635+ struct task_struct *parent = task->real_parent;
75636+ const struct cred *cred = __task_cred(task);
75637+ const struct cred *pcred = __task_cred(parent);
75638+ unsigned int len = strlen(buf);
75639+
75640+ 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));
75641+ }
75642+
75643+ printk("%s\n", buf);
75644+
75645+ return;
75646+}
75647+
75648+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75649+{
75650+ int logtype;
75651+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75652+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75653+ void *voidptr = NULL;
75654+ int num1 = 0, num2 = 0;
75655+ unsigned long ulong1 = 0, ulong2 = 0;
75656+ struct dentry *dentry = NULL;
75657+ struct vfsmount *mnt = NULL;
75658+ struct file *file = NULL;
75659+ struct task_struct *task = NULL;
75660+ struct vm_area_struct *vma = NULL;
75661+ const struct cred *cred, *pcred;
75662+ va_list ap;
75663+
75664+ BEGIN_LOCKS(audit);
75665+ logtype = gr_log_start(audit);
75666+ if (logtype == FLOODING) {
75667+ END_LOCKS(audit);
75668+ return;
75669+ }
75670+ va_start(ap, argtypes);
75671+ switch (argtypes) {
75672+ case GR_TTYSNIFF:
75673+ task = va_arg(ap, struct task_struct *);
75674+ 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));
75675+ break;
75676+ case GR_SYSCTL_HIDDEN:
75677+ str1 = va_arg(ap, char *);
75678+ gr_log_middle_varargs(audit, msg, result, str1);
75679+ break;
75680+ case GR_RBAC:
75681+ dentry = va_arg(ap, struct dentry *);
75682+ mnt = va_arg(ap, struct vfsmount *);
75683+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75684+ break;
75685+ case GR_RBAC_STR:
75686+ dentry = va_arg(ap, struct dentry *);
75687+ mnt = va_arg(ap, struct vfsmount *);
75688+ str1 = va_arg(ap, char *);
75689+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75690+ break;
75691+ case GR_STR_RBAC:
75692+ str1 = va_arg(ap, char *);
75693+ dentry = va_arg(ap, struct dentry *);
75694+ mnt = va_arg(ap, struct vfsmount *);
75695+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75696+ break;
75697+ case GR_RBAC_MODE2:
75698+ dentry = va_arg(ap, struct dentry *);
75699+ mnt = va_arg(ap, struct vfsmount *);
75700+ str1 = va_arg(ap, char *);
75701+ str2 = va_arg(ap, char *);
75702+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75703+ break;
75704+ case GR_RBAC_MODE3:
75705+ dentry = va_arg(ap, struct dentry *);
75706+ mnt = va_arg(ap, struct vfsmount *);
75707+ str1 = va_arg(ap, char *);
75708+ str2 = va_arg(ap, char *);
75709+ str3 = va_arg(ap, char *);
75710+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75711+ break;
75712+ case GR_FILENAME:
75713+ dentry = va_arg(ap, struct dentry *);
75714+ mnt = va_arg(ap, struct vfsmount *);
75715+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75716+ break;
75717+ case GR_STR_FILENAME:
75718+ str1 = va_arg(ap, char *);
75719+ dentry = va_arg(ap, struct dentry *);
75720+ mnt = va_arg(ap, struct vfsmount *);
75721+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75722+ break;
75723+ case GR_FILENAME_STR:
75724+ dentry = va_arg(ap, struct dentry *);
75725+ mnt = va_arg(ap, struct vfsmount *);
75726+ str1 = va_arg(ap, char *);
75727+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75728+ break;
75729+ case GR_FILENAME_TWO_INT:
75730+ dentry = va_arg(ap, struct dentry *);
75731+ mnt = va_arg(ap, struct vfsmount *);
75732+ num1 = va_arg(ap, int);
75733+ num2 = va_arg(ap, int);
75734+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75735+ break;
75736+ case GR_FILENAME_TWO_INT_STR:
75737+ dentry = va_arg(ap, struct dentry *);
75738+ mnt = va_arg(ap, struct vfsmount *);
75739+ num1 = va_arg(ap, int);
75740+ num2 = va_arg(ap, int);
75741+ str1 = va_arg(ap, char *);
75742+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75743+ break;
75744+ case GR_TEXTREL:
75745+ file = va_arg(ap, struct file *);
75746+ ulong1 = va_arg(ap, unsigned long);
75747+ ulong2 = va_arg(ap, unsigned long);
75748+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75749+ break;
75750+ case GR_PTRACE:
75751+ task = va_arg(ap, struct task_struct *);
75752+ 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));
75753+ break;
75754+ case GR_RESOURCE:
75755+ task = va_arg(ap, struct task_struct *);
75756+ cred = __task_cred(task);
75757+ pcred = __task_cred(task->real_parent);
75758+ ulong1 = va_arg(ap, unsigned long);
75759+ str1 = va_arg(ap, char *);
75760+ ulong2 = va_arg(ap, unsigned long);
75761+ 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));
75762+ break;
75763+ case GR_CAP:
75764+ task = va_arg(ap, struct task_struct *);
75765+ cred = __task_cred(task);
75766+ pcred = __task_cred(task->real_parent);
75767+ str1 = va_arg(ap, char *);
75768+ 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));
75769+ break;
75770+ case GR_SIG:
75771+ str1 = va_arg(ap, char *);
75772+ voidptr = va_arg(ap, void *);
75773+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75774+ break;
75775+ case GR_SIG2:
75776+ task = va_arg(ap, struct task_struct *);
75777+ cred = __task_cred(task);
75778+ pcred = __task_cred(task->real_parent);
75779+ num1 = va_arg(ap, int);
75780+ 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));
75781+ break;
75782+ case GR_CRASH1:
75783+ task = va_arg(ap, struct task_struct *);
75784+ cred = __task_cred(task);
75785+ pcred = __task_cred(task->real_parent);
75786+ ulong1 = va_arg(ap, unsigned long);
75787+ 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);
75788+ break;
75789+ case GR_CRASH2:
75790+ task = va_arg(ap, struct task_struct *);
75791+ cred = __task_cred(task);
75792+ pcred = __task_cred(task->real_parent);
75793+ ulong1 = va_arg(ap, unsigned long);
75794+ 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);
75795+ break;
75796+ case GR_RWXMAP:
75797+ file = va_arg(ap, struct file *);
75798+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75799+ break;
75800+ case GR_RWXMAPVMA:
75801+ vma = va_arg(ap, struct vm_area_struct *);
75802+ if (vma->vm_file)
75803+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75804+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75805+ str1 = "<stack>";
75806+ else if (vma->vm_start <= current->mm->brk &&
75807+ vma->vm_end >= current->mm->start_brk)
75808+ str1 = "<heap>";
75809+ else
75810+ str1 = "<anonymous mapping>";
75811+ gr_log_middle_varargs(audit, msg, str1);
75812+ break;
75813+ case GR_PSACCT:
75814+ {
75815+ unsigned int wday, cday;
75816+ __u8 whr, chr;
75817+ __u8 wmin, cmin;
75818+ __u8 wsec, csec;
75819+ char cur_tty[64] = { 0 };
75820+ char parent_tty[64] = { 0 };
75821+
75822+ task = va_arg(ap, struct task_struct *);
75823+ wday = va_arg(ap, unsigned int);
75824+ cday = va_arg(ap, unsigned int);
75825+ whr = va_arg(ap, int);
75826+ chr = va_arg(ap, int);
75827+ wmin = va_arg(ap, int);
75828+ cmin = va_arg(ap, int);
75829+ wsec = va_arg(ap, int);
75830+ csec = va_arg(ap, int);
75831+ ulong1 = va_arg(ap, unsigned long);
75832+ cred = __task_cred(task);
75833+ pcred = __task_cred(task->real_parent);
75834+
75835+ 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));
75836+ }
75837+ break;
75838+ default:
75839+ gr_log_middle(audit, msg, ap);
75840+ }
75841+ va_end(ap);
75842+ // these don't need DEFAULTSECARGS printed on the end
75843+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75844+ gr_log_end(audit, 0);
75845+ else
75846+ gr_log_end(audit, 1);
75847+ END_LOCKS(audit);
75848+}
75849diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75850new file mode 100644
75851index 0000000..0e39d8c
75852--- /dev/null
75853+++ b/grsecurity/grsec_mem.c
75854@@ -0,0 +1,48 @@
75855+#include <linux/kernel.h>
75856+#include <linux/sched.h>
75857+#include <linux/mm.h>
75858+#include <linux/mman.h>
75859+#include <linux/module.h>
75860+#include <linux/grinternal.h>
75861+
75862+void gr_handle_msr_write(void)
75863+{
75864+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75865+ return;
75866+}
75867+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75868+
75869+void
75870+gr_handle_ioperm(void)
75871+{
75872+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75873+ return;
75874+}
75875+
75876+void
75877+gr_handle_iopl(void)
75878+{
75879+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75880+ return;
75881+}
75882+
75883+void
75884+gr_handle_mem_readwrite(u64 from, u64 to)
75885+{
75886+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75887+ return;
75888+}
75889+
75890+void
75891+gr_handle_vm86(void)
75892+{
75893+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75894+ return;
75895+}
75896+
75897+void
75898+gr_log_badprocpid(const char *entry)
75899+{
75900+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75901+ return;
75902+}
75903diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75904new file mode 100644
75905index 0000000..cd9e124
75906--- /dev/null
75907+++ b/grsecurity/grsec_mount.c
75908@@ -0,0 +1,65 @@
75909+#include <linux/kernel.h>
75910+#include <linux/sched.h>
75911+#include <linux/mount.h>
75912+#include <linux/major.h>
75913+#include <linux/grsecurity.h>
75914+#include <linux/grinternal.h>
75915+
75916+void
75917+gr_log_remount(const char *devname, const int retval)
75918+{
75919+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75920+ if (grsec_enable_mount && (retval >= 0))
75921+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75922+#endif
75923+ return;
75924+}
75925+
75926+void
75927+gr_log_unmount(const char *devname, const int retval)
75928+{
75929+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75930+ if (grsec_enable_mount && (retval >= 0))
75931+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75932+#endif
75933+ return;
75934+}
75935+
75936+void
75937+gr_log_mount(const char *from, const char *to, const int retval)
75938+{
75939+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75940+ if (grsec_enable_mount && (retval >= 0))
75941+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75942+#endif
75943+ return;
75944+}
75945+
75946+int
75947+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75948+{
75949+#ifdef CONFIG_GRKERNSEC_ROFS
75950+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75951+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75952+ return -EPERM;
75953+ } else
75954+ return 0;
75955+#endif
75956+ return 0;
75957+}
75958+
75959+int
75960+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75961+{
75962+#ifdef CONFIG_GRKERNSEC_ROFS
75963+ struct inode *inode = dentry->d_inode;
75964+
75965+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75966+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75967+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75968+ return -EPERM;
75969+ } else
75970+ return 0;
75971+#endif
75972+ return 0;
75973+}
75974diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75975new file mode 100644
75976index 0000000..6ee9d50
75977--- /dev/null
75978+++ b/grsecurity/grsec_pax.c
75979@@ -0,0 +1,45 @@
75980+#include <linux/kernel.h>
75981+#include <linux/sched.h>
75982+#include <linux/mm.h>
75983+#include <linux/file.h>
75984+#include <linux/grinternal.h>
75985+#include <linux/grsecurity.h>
75986+
75987+void
75988+gr_log_textrel(struct vm_area_struct * vma)
75989+{
75990+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75991+ if (grsec_enable_log_rwxmaps)
75992+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75993+#endif
75994+ return;
75995+}
75996+
75997+void gr_log_ptgnustack(struct file *file)
75998+{
75999+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76000+ if (grsec_enable_log_rwxmaps)
76001+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
76002+#endif
76003+ return;
76004+}
76005+
76006+void
76007+gr_log_rwxmmap(struct file *file)
76008+{
76009+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76010+ if (grsec_enable_log_rwxmaps)
76011+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
76012+#endif
76013+ return;
76014+}
76015+
76016+void
76017+gr_log_rwxmprotect(struct vm_area_struct *vma)
76018+{
76019+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76020+ if (grsec_enable_log_rwxmaps)
76021+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
76022+#endif
76023+ return;
76024+}
76025diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
76026new file mode 100644
76027index 0000000..2005a3a
76028--- /dev/null
76029+++ b/grsecurity/grsec_proc.c
76030@@ -0,0 +1,20 @@
76031+#include <linux/kernel.h>
76032+#include <linux/sched.h>
76033+#include <linux/grsecurity.h>
76034+#include <linux/grinternal.h>
76035+
76036+int gr_proc_is_restricted(void)
76037+{
76038+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76039+ const struct cred *cred = current_cred();
76040+#endif
76041+
76042+#ifdef CONFIG_GRKERNSEC_PROC_USER
76043+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
76044+ return -EACCES;
76045+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76046+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
76047+ return -EACCES;
76048+#endif
76049+ return 0;
76050+}
76051diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
76052new file mode 100644
76053index 0000000..f7f29aa
76054--- /dev/null
76055+++ b/grsecurity/grsec_ptrace.c
76056@@ -0,0 +1,30 @@
76057+#include <linux/kernel.h>
76058+#include <linux/sched.h>
76059+#include <linux/grinternal.h>
76060+#include <linux/security.h>
76061+
76062+void
76063+gr_audit_ptrace(struct task_struct *task)
76064+{
76065+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76066+ if (grsec_enable_audit_ptrace)
76067+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
76068+#endif
76069+ return;
76070+}
76071+
76072+int
76073+gr_ptrace_readexec(struct file *file, int unsafe_flags)
76074+{
76075+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76076+ const struct dentry *dentry = file->f_path.dentry;
76077+ const struct vfsmount *mnt = file->f_path.mnt;
76078+
76079+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
76080+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
76081+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
76082+ return -EACCES;
76083+ }
76084+#endif
76085+ return 0;
76086+}
76087diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
76088new file mode 100644
76089index 0000000..3860c7e
76090--- /dev/null
76091+++ b/grsecurity/grsec_sig.c
76092@@ -0,0 +1,236 @@
76093+#include <linux/kernel.h>
76094+#include <linux/sched.h>
76095+#include <linux/fs.h>
76096+#include <linux/delay.h>
76097+#include <linux/grsecurity.h>
76098+#include <linux/grinternal.h>
76099+#include <linux/hardirq.h>
76100+
76101+char *signames[] = {
76102+ [SIGSEGV] = "Segmentation fault",
76103+ [SIGILL] = "Illegal instruction",
76104+ [SIGABRT] = "Abort",
76105+ [SIGBUS] = "Invalid alignment/Bus error"
76106+};
76107+
76108+void
76109+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
76110+{
76111+#ifdef CONFIG_GRKERNSEC_SIGNAL
76112+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
76113+ (sig == SIGABRT) || (sig == SIGBUS))) {
76114+ if (task_pid_nr(t) == task_pid_nr(current)) {
76115+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
76116+ } else {
76117+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
76118+ }
76119+ }
76120+#endif
76121+ return;
76122+}
76123+
76124+int
76125+gr_handle_signal(const struct task_struct *p, const int sig)
76126+{
76127+#ifdef CONFIG_GRKERNSEC
76128+ /* ignore the 0 signal for protected task checks */
76129+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
76130+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
76131+ return -EPERM;
76132+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
76133+ return -EPERM;
76134+ }
76135+#endif
76136+ return 0;
76137+}
76138+
76139+#ifdef CONFIG_GRKERNSEC
76140+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
76141+
76142+int gr_fake_force_sig(int sig, struct task_struct *t)
76143+{
76144+ unsigned long int flags;
76145+ int ret, blocked, ignored;
76146+ struct k_sigaction *action;
76147+
76148+ spin_lock_irqsave(&t->sighand->siglock, flags);
76149+ action = &t->sighand->action[sig-1];
76150+ ignored = action->sa.sa_handler == SIG_IGN;
76151+ blocked = sigismember(&t->blocked, sig);
76152+ if (blocked || ignored) {
76153+ action->sa.sa_handler = SIG_DFL;
76154+ if (blocked) {
76155+ sigdelset(&t->blocked, sig);
76156+ recalc_sigpending_and_wake(t);
76157+ }
76158+ }
76159+ if (action->sa.sa_handler == SIG_DFL)
76160+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
76161+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
76162+
76163+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
76164+
76165+ return ret;
76166+}
76167+#endif
76168+
76169+#define GR_USER_BAN_TIME (15 * 60)
76170+#define GR_DAEMON_BRUTE_TIME (30 * 60)
76171+
76172+void gr_handle_brute_attach(int dumpable)
76173+{
76174+#ifdef CONFIG_GRKERNSEC_BRUTE
76175+ struct task_struct *p = current;
76176+ kuid_t uid = GLOBAL_ROOT_UID;
76177+ int daemon = 0;
76178+
76179+ if (!grsec_enable_brute)
76180+ return;
76181+
76182+ rcu_read_lock();
76183+ read_lock(&tasklist_lock);
76184+ read_lock(&grsec_exec_file_lock);
76185+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
76186+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
76187+ p->real_parent->brute = 1;
76188+ daemon = 1;
76189+ } else {
76190+ const struct cred *cred = __task_cred(p), *cred2;
76191+ struct task_struct *tsk, *tsk2;
76192+
76193+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
76194+ struct user_struct *user;
76195+
76196+ uid = cred->uid;
76197+
76198+ /* this is put upon execution past expiration */
76199+ user = find_user(uid);
76200+ if (user == NULL)
76201+ goto unlock;
76202+ user->suid_banned = 1;
76203+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
76204+ if (user->suid_ban_expires == ~0UL)
76205+ user->suid_ban_expires--;
76206+
76207+ /* only kill other threads of the same binary, from the same user */
76208+ do_each_thread(tsk2, tsk) {
76209+ cred2 = __task_cred(tsk);
76210+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
76211+ gr_fake_force_sig(SIGKILL, tsk);
76212+ } while_each_thread(tsk2, tsk);
76213+ }
76214+ }
76215+unlock:
76216+ read_unlock(&grsec_exec_file_lock);
76217+ read_unlock(&tasklist_lock);
76218+ rcu_read_unlock();
76219+
76220+ if (gr_is_global_nonroot(uid))
76221+ 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);
76222+ else if (daemon)
76223+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
76224+
76225+#endif
76226+ return;
76227+}
76228+
76229+void gr_handle_brute_check(void)
76230+{
76231+#ifdef CONFIG_GRKERNSEC_BRUTE
76232+ struct task_struct *p = current;
76233+
76234+ if (unlikely(p->brute)) {
76235+ if (!grsec_enable_brute)
76236+ p->brute = 0;
76237+ else if (time_before(get_seconds(), p->brute_expires))
76238+ msleep(30 * 1000);
76239+ }
76240+#endif
76241+ return;
76242+}
76243+
76244+void gr_handle_kernel_exploit(void)
76245+{
76246+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76247+ const struct cred *cred;
76248+ struct task_struct *tsk, *tsk2;
76249+ struct user_struct *user;
76250+ kuid_t uid;
76251+
76252+ if (in_irq() || in_serving_softirq() || in_nmi())
76253+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
76254+
76255+ uid = current_uid();
76256+
76257+ if (gr_is_global_root(uid))
76258+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
76259+ else {
76260+ /* kill all the processes of this user, hold a reference
76261+ to their creds struct, and prevent them from creating
76262+ another process until system reset
76263+ */
76264+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
76265+ GR_GLOBAL_UID(uid));
76266+ /* we intentionally leak this ref */
76267+ user = get_uid(current->cred->user);
76268+ if (user)
76269+ user->kernel_banned = 1;
76270+
76271+ /* kill all processes of this user */
76272+ read_lock(&tasklist_lock);
76273+ do_each_thread(tsk2, tsk) {
76274+ cred = __task_cred(tsk);
76275+ if (uid_eq(cred->uid, uid))
76276+ gr_fake_force_sig(SIGKILL, tsk);
76277+ } while_each_thread(tsk2, tsk);
76278+ read_unlock(&tasklist_lock);
76279+ }
76280+#endif
76281+}
76282+
76283+#ifdef CONFIG_GRKERNSEC_BRUTE
76284+static bool suid_ban_expired(struct user_struct *user)
76285+{
76286+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
76287+ user->suid_banned = 0;
76288+ user->suid_ban_expires = 0;
76289+ free_uid(user);
76290+ return true;
76291+ }
76292+
76293+ return false;
76294+}
76295+#endif
76296+
76297+int gr_process_kernel_exec_ban(void)
76298+{
76299+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76300+ if (unlikely(current->cred->user->kernel_banned))
76301+ return -EPERM;
76302+#endif
76303+ return 0;
76304+}
76305+
76306+int gr_process_kernel_setuid_ban(struct user_struct *user)
76307+{
76308+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76309+ if (unlikely(user->kernel_banned))
76310+ gr_fake_force_sig(SIGKILL, current);
76311+#endif
76312+ return 0;
76313+}
76314+
76315+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
76316+{
76317+#ifdef CONFIG_GRKERNSEC_BRUTE
76318+ struct user_struct *user = current->cred->user;
76319+ if (unlikely(user->suid_banned)) {
76320+ if (suid_ban_expired(user))
76321+ return 0;
76322+ /* disallow execution of suid binaries only */
76323+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
76324+ return -EPERM;
76325+ }
76326+#endif
76327+ return 0;
76328+}
76329diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
76330new file mode 100644
76331index 0000000..c0aef3a
76332--- /dev/null
76333+++ b/grsecurity/grsec_sock.c
76334@@ -0,0 +1,244 @@
76335+#include <linux/kernel.h>
76336+#include <linux/module.h>
76337+#include <linux/sched.h>
76338+#include <linux/file.h>
76339+#include <linux/net.h>
76340+#include <linux/in.h>
76341+#include <linux/ip.h>
76342+#include <net/sock.h>
76343+#include <net/inet_sock.h>
76344+#include <linux/grsecurity.h>
76345+#include <linux/grinternal.h>
76346+#include <linux/gracl.h>
76347+
76348+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
76349+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
76350+
76351+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
76352+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
76353+
76354+#ifdef CONFIG_UNIX_MODULE
76355+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
76356+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
76357+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
76358+EXPORT_SYMBOL_GPL(gr_handle_create);
76359+#endif
76360+
76361+#ifdef CONFIG_GRKERNSEC
76362+#define gr_conn_table_size 32749
76363+struct conn_table_entry {
76364+ struct conn_table_entry *next;
76365+ struct signal_struct *sig;
76366+};
76367+
76368+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
76369+DEFINE_SPINLOCK(gr_conn_table_lock);
76370+
76371+extern const char * gr_socktype_to_name(unsigned char type);
76372+extern const char * gr_proto_to_name(unsigned char proto);
76373+extern const char * gr_sockfamily_to_name(unsigned char family);
76374+
76375+static __inline__ int
76376+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
76377+{
76378+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
76379+}
76380+
76381+static __inline__ int
76382+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
76383+ __u16 sport, __u16 dport)
76384+{
76385+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
76386+ sig->gr_sport == sport && sig->gr_dport == dport))
76387+ return 1;
76388+ else
76389+ return 0;
76390+}
76391+
76392+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
76393+{
76394+ struct conn_table_entry **match;
76395+ unsigned int index;
76396+
76397+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76398+ sig->gr_sport, sig->gr_dport,
76399+ gr_conn_table_size);
76400+
76401+ newent->sig = sig;
76402+
76403+ match = &gr_conn_table[index];
76404+ newent->next = *match;
76405+ *match = newent;
76406+
76407+ return;
76408+}
76409+
76410+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
76411+{
76412+ struct conn_table_entry *match, *last = NULL;
76413+ unsigned int index;
76414+
76415+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76416+ sig->gr_sport, sig->gr_dport,
76417+ gr_conn_table_size);
76418+
76419+ match = gr_conn_table[index];
76420+ while (match && !conn_match(match->sig,
76421+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
76422+ sig->gr_dport)) {
76423+ last = match;
76424+ match = match->next;
76425+ }
76426+
76427+ if (match) {
76428+ if (last)
76429+ last->next = match->next;
76430+ else
76431+ gr_conn_table[index] = NULL;
76432+ kfree(match);
76433+ }
76434+
76435+ return;
76436+}
76437+
76438+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76439+ __u16 sport, __u16 dport)
76440+{
76441+ struct conn_table_entry *match;
76442+ unsigned int index;
76443+
76444+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76445+
76446+ match = gr_conn_table[index];
76447+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76448+ match = match->next;
76449+
76450+ if (match)
76451+ return match->sig;
76452+ else
76453+ return NULL;
76454+}
76455+
76456+#endif
76457+
76458+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76459+{
76460+#ifdef CONFIG_GRKERNSEC
76461+ struct signal_struct *sig = task->signal;
76462+ struct conn_table_entry *newent;
76463+
76464+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76465+ if (newent == NULL)
76466+ return;
76467+ /* no bh lock needed since we are called with bh disabled */
76468+ spin_lock(&gr_conn_table_lock);
76469+ gr_del_task_from_ip_table_nolock(sig);
76470+ sig->gr_saddr = inet->inet_rcv_saddr;
76471+ sig->gr_daddr = inet->inet_daddr;
76472+ sig->gr_sport = inet->inet_sport;
76473+ sig->gr_dport = inet->inet_dport;
76474+ gr_add_to_task_ip_table_nolock(sig, newent);
76475+ spin_unlock(&gr_conn_table_lock);
76476+#endif
76477+ return;
76478+}
76479+
76480+void gr_del_task_from_ip_table(struct task_struct *task)
76481+{
76482+#ifdef CONFIG_GRKERNSEC
76483+ spin_lock_bh(&gr_conn_table_lock);
76484+ gr_del_task_from_ip_table_nolock(task->signal);
76485+ spin_unlock_bh(&gr_conn_table_lock);
76486+#endif
76487+ return;
76488+}
76489+
76490+void
76491+gr_attach_curr_ip(const struct sock *sk)
76492+{
76493+#ifdef CONFIG_GRKERNSEC
76494+ struct signal_struct *p, *set;
76495+ const struct inet_sock *inet = inet_sk(sk);
76496+
76497+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76498+ return;
76499+
76500+ set = current->signal;
76501+
76502+ spin_lock_bh(&gr_conn_table_lock);
76503+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76504+ inet->inet_dport, inet->inet_sport);
76505+ if (unlikely(p != NULL)) {
76506+ set->curr_ip = p->curr_ip;
76507+ set->used_accept = 1;
76508+ gr_del_task_from_ip_table_nolock(p);
76509+ spin_unlock_bh(&gr_conn_table_lock);
76510+ return;
76511+ }
76512+ spin_unlock_bh(&gr_conn_table_lock);
76513+
76514+ set->curr_ip = inet->inet_daddr;
76515+ set->used_accept = 1;
76516+#endif
76517+ return;
76518+}
76519+
76520+int
76521+gr_handle_sock_all(const int family, const int type, const int protocol)
76522+{
76523+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76524+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76525+ (family != AF_UNIX)) {
76526+ if (family == AF_INET)
76527+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76528+ else
76529+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76530+ return -EACCES;
76531+ }
76532+#endif
76533+ return 0;
76534+}
76535+
76536+int
76537+gr_handle_sock_server(const struct sockaddr *sck)
76538+{
76539+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76540+ if (grsec_enable_socket_server &&
76541+ in_group_p(grsec_socket_server_gid) &&
76542+ sck && (sck->sa_family != AF_UNIX) &&
76543+ (sck->sa_family != AF_LOCAL)) {
76544+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76545+ return -EACCES;
76546+ }
76547+#endif
76548+ return 0;
76549+}
76550+
76551+int
76552+gr_handle_sock_server_other(const struct sock *sck)
76553+{
76554+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76555+ if (grsec_enable_socket_server &&
76556+ in_group_p(grsec_socket_server_gid) &&
76557+ sck && (sck->sk_family != AF_UNIX) &&
76558+ (sck->sk_family != AF_LOCAL)) {
76559+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76560+ return -EACCES;
76561+ }
76562+#endif
76563+ return 0;
76564+}
76565+
76566+int
76567+gr_handle_sock_client(const struct sockaddr *sck)
76568+{
76569+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76570+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76571+ sck && (sck->sa_family != AF_UNIX) &&
76572+ (sck->sa_family != AF_LOCAL)) {
76573+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76574+ return -EACCES;
76575+ }
76576+#endif
76577+ return 0;
76578+}
76579diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76580new file mode 100644
76581index 0000000..8159888
76582--- /dev/null
76583+++ b/grsecurity/grsec_sysctl.c
76584@@ -0,0 +1,479 @@
76585+#include <linux/kernel.h>
76586+#include <linux/sched.h>
76587+#include <linux/sysctl.h>
76588+#include <linux/grsecurity.h>
76589+#include <linux/grinternal.h>
76590+
76591+int
76592+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76593+{
76594+#ifdef CONFIG_GRKERNSEC_SYSCTL
76595+ if (dirname == NULL || name == NULL)
76596+ return 0;
76597+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76598+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76599+ return -EACCES;
76600+ }
76601+#endif
76602+ return 0;
76603+}
76604+
76605+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76606+static int __maybe_unused __read_only one = 1;
76607+#endif
76608+
76609+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76610+ defined(CONFIG_GRKERNSEC_DENYUSB)
76611+struct ctl_table grsecurity_table[] = {
76612+#ifdef CONFIG_GRKERNSEC_SYSCTL
76613+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76614+#ifdef CONFIG_GRKERNSEC_IO
76615+ {
76616+ .procname = "disable_priv_io",
76617+ .data = &grsec_disable_privio,
76618+ .maxlen = sizeof(int),
76619+ .mode = 0600,
76620+ .proc_handler = &proc_dointvec,
76621+ },
76622+#endif
76623+#endif
76624+#ifdef CONFIG_GRKERNSEC_LINK
76625+ {
76626+ .procname = "linking_restrictions",
76627+ .data = &grsec_enable_link,
76628+ .maxlen = sizeof(int),
76629+ .mode = 0600,
76630+ .proc_handler = &proc_dointvec,
76631+ },
76632+#endif
76633+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76634+ {
76635+ .procname = "enforce_symlinksifowner",
76636+ .data = &grsec_enable_symlinkown,
76637+ .maxlen = sizeof(int),
76638+ .mode = 0600,
76639+ .proc_handler = &proc_dointvec,
76640+ },
76641+ {
76642+ .procname = "symlinkown_gid",
76643+ .data = &grsec_symlinkown_gid,
76644+ .maxlen = sizeof(int),
76645+ .mode = 0600,
76646+ .proc_handler = &proc_dointvec,
76647+ },
76648+#endif
76649+#ifdef CONFIG_GRKERNSEC_BRUTE
76650+ {
76651+ .procname = "deter_bruteforce",
76652+ .data = &grsec_enable_brute,
76653+ .maxlen = sizeof(int),
76654+ .mode = 0600,
76655+ .proc_handler = &proc_dointvec,
76656+ },
76657+#endif
76658+#ifdef CONFIG_GRKERNSEC_FIFO
76659+ {
76660+ .procname = "fifo_restrictions",
76661+ .data = &grsec_enable_fifo,
76662+ .maxlen = sizeof(int),
76663+ .mode = 0600,
76664+ .proc_handler = &proc_dointvec,
76665+ },
76666+#endif
76667+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76668+ {
76669+ .procname = "ptrace_readexec",
76670+ .data = &grsec_enable_ptrace_readexec,
76671+ .maxlen = sizeof(int),
76672+ .mode = 0600,
76673+ .proc_handler = &proc_dointvec,
76674+ },
76675+#endif
76676+#ifdef CONFIG_GRKERNSEC_SETXID
76677+ {
76678+ .procname = "consistent_setxid",
76679+ .data = &grsec_enable_setxid,
76680+ .maxlen = sizeof(int),
76681+ .mode = 0600,
76682+ .proc_handler = &proc_dointvec,
76683+ },
76684+#endif
76685+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76686+ {
76687+ .procname = "ip_blackhole",
76688+ .data = &grsec_enable_blackhole,
76689+ .maxlen = sizeof(int),
76690+ .mode = 0600,
76691+ .proc_handler = &proc_dointvec,
76692+ },
76693+ {
76694+ .procname = "lastack_retries",
76695+ .data = &grsec_lastack_retries,
76696+ .maxlen = sizeof(int),
76697+ .mode = 0600,
76698+ .proc_handler = &proc_dointvec,
76699+ },
76700+#endif
76701+#ifdef CONFIG_GRKERNSEC_EXECLOG
76702+ {
76703+ .procname = "exec_logging",
76704+ .data = &grsec_enable_execlog,
76705+ .maxlen = sizeof(int),
76706+ .mode = 0600,
76707+ .proc_handler = &proc_dointvec,
76708+ },
76709+#endif
76710+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76711+ {
76712+ .procname = "rwxmap_logging",
76713+ .data = &grsec_enable_log_rwxmaps,
76714+ .maxlen = sizeof(int),
76715+ .mode = 0600,
76716+ .proc_handler = &proc_dointvec,
76717+ },
76718+#endif
76719+#ifdef CONFIG_GRKERNSEC_SIGNAL
76720+ {
76721+ .procname = "signal_logging",
76722+ .data = &grsec_enable_signal,
76723+ .maxlen = sizeof(int),
76724+ .mode = 0600,
76725+ .proc_handler = &proc_dointvec,
76726+ },
76727+#endif
76728+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76729+ {
76730+ .procname = "forkfail_logging",
76731+ .data = &grsec_enable_forkfail,
76732+ .maxlen = sizeof(int),
76733+ .mode = 0600,
76734+ .proc_handler = &proc_dointvec,
76735+ },
76736+#endif
76737+#ifdef CONFIG_GRKERNSEC_TIME
76738+ {
76739+ .procname = "timechange_logging",
76740+ .data = &grsec_enable_time,
76741+ .maxlen = sizeof(int),
76742+ .mode = 0600,
76743+ .proc_handler = &proc_dointvec,
76744+ },
76745+#endif
76746+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76747+ {
76748+ .procname = "chroot_deny_shmat",
76749+ .data = &grsec_enable_chroot_shmat,
76750+ .maxlen = sizeof(int),
76751+ .mode = 0600,
76752+ .proc_handler = &proc_dointvec,
76753+ },
76754+#endif
76755+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76756+ {
76757+ .procname = "chroot_deny_unix",
76758+ .data = &grsec_enable_chroot_unix,
76759+ .maxlen = sizeof(int),
76760+ .mode = 0600,
76761+ .proc_handler = &proc_dointvec,
76762+ },
76763+#endif
76764+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76765+ {
76766+ .procname = "chroot_deny_mount",
76767+ .data = &grsec_enable_chroot_mount,
76768+ .maxlen = sizeof(int),
76769+ .mode = 0600,
76770+ .proc_handler = &proc_dointvec,
76771+ },
76772+#endif
76773+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76774+ {
76775+ .procname = "chroot_deny_fchdir",
76776+ .data = &grsec_enable_chroot_fchdir,
76777+ .maxlen = sizeof(int),
76778+ .mode = 0600,
76779+ .proc_handler = &proc_dointvec,
76780+ },
76781+#endif
76782+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76783+ {
76784+ .procname = "chroot_deny_chroot",
76785+ .data = &grsec_enable_chroot_double,
76786+ .maxlen = sizeof(int),
76787+ .mode = 0600,
76788+ .proc_handler = &proc_dointvec,
76789+ },
76790+#endif
76791+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76792+ {
76793+ .procname = "chroot_deny_pivot",
76794+ .data = &grsec_enable_chroot_pivot,
76795+ .maxlen = sizeof(int),
76796+ .mode = 0600,
76797+ .proc_handler = &proc_dointvec,
76798+ },
76799+#endif
76800+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76801+ {
76802+ .procname = "chroot_enforce_chdir",
76803+ .data = &grsec_enable_chroot_chdir,
76804+ .maxlen = sizeof(int),
76805+ .mode = 0600,
76806+ .proc_handler = &proc_dointvec,
76807+ },
76808+#endif
76809+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76810+ {
76811+ .procname = "chroot_deny_chmod",
76812+ .data = &grsec_enable_chroot_chmod,
76813+ .maxlen = sizeof(int),
76814+ .mode = 0600,
76815+ .proc_handler = &proc_dointvec,
76816+ },
76817+#endif
76818+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76819+ {
76820+ .procname = "chroot_deny_mknod",
76821+ .data = &grsec_enable_chroot_mknod,
76822+ .maxlen = sizeof(int),
76823+ .mode = 0600,
76824+ .proc_handler = &proc_dointvec,
76825+ },
76826+#endif
76827+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76828+ {
76829+ .procname = "chroot_restrict_nice",
76830+ .data = &grsec_enable_chroot_nice,
76831+ .maxlen = sizeof(int),
76832+ .mode = 0600,
76833+ .proc_handler = &proc_dointvec,
76834+ },
76835+#endif
76836+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76837+ {
76838+ .procname = "chroot_execlog",
76839+ .data = &grsec_enable_chroot_execlog,
76840+ .maxlen = sizeof(int),
76841+ .mode = 0600,
76842+ .proc_handler = &proc_dointvec,
76843+ },
76844+#endif
76845+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76846+ {
76847+ .procname = "chroot_caps",
76848+ .data = &grsec_enable_chroot_caps,
76849+ .maxlen = sizeof(int),
76850+ .mode = 0600,
76851+ .proc_handler = &proc_dointvec,
76852+ },
76853+#endif
76854+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76855+ {
76856+ .procname = "chroot_deny_sysctl",
76857+ .data = &grsec_enable_chroot_sysctl,
76858+ .maxlen = sizeof(int),
76859+ .mode = 0600,
76860+ .proc_handler = &proc_dointvec,
76861+ },
76862+#endif
76863+#ifdef CONFIG_GRKERNSEC_TPE
76864+ {
76865+ .procname = "tpe",
76866+ .data = &grsec_enable_tpe,
76867+ .maxlen = sizeof(int),
76868+ .mode = 0600,
76869+ .proc_handler = &proc_dointvec,
76870+ },
76871+ {
76872+ .procname = "tpe_gid",
76873+ .data = &grsec_tpe_gid,
76874+ .maxlen = sizeof(int),
76875+ .mode = 0600,
76876+ .proc_handler = &proc_dointvec,
76877+ },
76878+#endif
76879+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76880+ {
76881+ .procname = "tpe_invert",
76882+ .data = &grsec_enable_tpe_invert,
76883+ .maxlen = sizeof(int),
76884+ .mode = 0600,
76885+ .proc_handler = &proc_dointvec,
76886+ },
76887+#endif
76888+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76889+ {
76890+ .procname = "tpe_restrict_all",
76891+ .data = &grsec_enable_tpe_all,
76892+ .maxlen = sizeof(int),
76893+ .mode = 0600,
76894+ .proc_handler = &proc_dointvec,
76895+ },
76896+#endif
76897+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76898+ {
76899+ .procname = "socket_all",
76900+ .data = &grsec_enable_socket_all,
76901+ .maxlen = sizeof(int),
76902+ .mode = 0600,
76903+ .proc_handler = &proc_dointvec,
76904+ },
76905+ {
76906+ .procname = "socket_all_gid",
76907+ .data = &grsec_socket_all_gid,
76908+ .maxlen = sizeof(int),
76909+ .mode = 0600,
76910+ .proc_handler = &proc_dointvec,
76911+ },
76912+#endif
76913+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76914+ {
76915+ .procname = "socket_client",
76916+ .data = &grsec_enable_socket_client,
76917+ .maxlen = sizeof(int),
76918+ .mode = 0600,
76919+ .proc_handler = &proc_dointvec,
76920+ },
76921+ {
76922+ .procname = "socket_client_gid",
76923+ .data = &grsec_socket_client_gid,
76924+ .maxlen = sizeof(int),
76925+ .mode = 0600,
76926+ .proc_handler = &proc_dointvec,
76927+ },
76928+#endif
76929+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76930+ {
76931+ .procname = "socket_server",
76932+ .data = &grsec_enable_socket_server,
76933+ .maxlen = sizeof(int),
76934+ .mode = 0600,
76935+ .proc_handler = &proc_dointvec,
76936+ },
76937+ {
76938+ .procname = "socket_server_gid",
76939+ .data = &grsec_socket_server_gid,
76940+ .maxlen = sizeof(int),
76941+ .mode = 0600,
76942+ .proc_handler = &proc_dointvec,
76943+ },
76944+#endif
76945+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76946+ {
76947+ .procname = "audit_group",
76948+ .data = &grsec_enable_group,
76949+ .maxlen = sizeof(int),
76950+ .mode = 0600,
76951+ .proc_handler = &proc_dointvec,
76952+ },
76953+ {
76954+ .procname = "audit_gid",
76955+ .data = &grsec_audit_gid,
76956+ .maxlen = sizeof(int),
76957+ .mode = 0600,
76958+ .proc_handler = &proc_dointvec,
76959+ },
76960+#endif
76961+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76962+ {
76963+ .procname = "audit_chdir",
76964+ .data = &grsec_enable_chdir,
76965+ .maxlen = sizeof(int),
76966+ .mode = 0600,
76967+ .proc_handler = &proc_dointvec,
76968+ },
76969+#endif
76970+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76971+ {
76972+ .procname = "audit_mount",
76973+ .data = &grsec_enable_mount,
76974+ .maxlen = sizeof(int),
76975+ .mode = 0600,
76976+ .proc_handler = &proc_dointvec,
76977+ },
76978+#endif
76979+#ifdef CONFIG_GRKERNSEC_DMESG
76980+ {
76981+ .procname = "dmesg",
76982+ .data = &grsec_enable_dmesg,
76983+ .maxlen = sizeof(int),
76984+ .mode = 0600,
76985+ .proc_handler = &proc_dointvec,
76986+ },
76987+#endif
76988+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76989+ {
76990+ .procname = "chroot_findtask",
76991+ .data = &grsec_enable_chroot_findtask,
76992+ .maxlen = sizeof(int),
76993+ .mode = 0600,
76994+ .proc_handler = &proc_dointvec,
76995+ },
76996+#endif
76997+#ifdef CONFIG_GRKERNSEC_RESLOG
76998+ {
76999+ .procname = "resource_logging",
77000+ .data = &grsec_resource_logging,
77001+ .maxlen = sizeof(int),
77002+ .mode = 0600,
77003+ .proc_handler = &proc_dointvec,
77004+ },
77005+#endif
77006+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77007+ {
77008+ .procname = "audit_ptrace",
77009+ .data = &grsec_enable_audit_ptrace,
77010+ .maxlen = sizeof(int),
77011+ .mode = 0600,
77012+ .proc_handler = &proc_dointvec,
77013+ },
77014+#endif
77015+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77016+ {
77017+ .procname = "harden_ptrace",
77018+ .data = &grsec_enable_harden_ptrace,
77019+ .maxlen = sizeof(int),
77020+ .mode = 0600,
77021+ .proc_handler = &proc_dointvec,
77022+ },
77023+#endif
77024+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77025+ {
77026+ .procname = "harden_ipc",
77027+ .data = &grsec_enable_harden_ipc,
77028+ .maxlen = sizeof(int),
77029+ .mode = 0600,
77030+ .proc_handler = &proc_dointvec,
77031+ },
77032+#endif
77033+ {
77034+ .procname = "grsec_lock",
77035+ .data = &grsec_lock,
77036+ .maxlen = sizeof(int),
77037+ .mode = 0600,
77038+ .proc_handler = &proc_dointvec,
77039+ },
77040+#endif
77041+#ifdef CONFIG_GRKERNSEC_ROFS
77042+ {
77043+ .procname = "romount_protect",
77044+ .data = &grsec_enable_rofs,
77045+ .maxlen = sizeof(int),
77046+ .mode = 0600,
77047+ .proc_handler = &proc_dointvec_minmax,
77048+ .extra1 = &one,
77049+ .extra2 = &one,
77050+ },
77051+#endif
77052+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
77053+ {
77054+ .procname = "deny_new_usb",
77055+ .data = &grsec_deny_new_usb,
77056+ .maxlen = sizeof(int),
77057+ .mode = 0600,
77058+ .proc_handler = &proc_dointvec,
77059+ },
77060+#endif
77061+ { }
77062+};
77063+#endif
77064diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
77065new file mode 100644
77066index 0000000..61b514e
77067--- /dev/null
77068+++ b/grsecurity/grsec_time.c
77069@@ -0,0 +1,16 @@
77070+#include <linux/kernel.h>
77071+#include <linux/sched.h>
77072+#include <linux/grinternal.h>
77073+#include <linux/module.h>
77074+
77075+void
77076+gr_log_timechange(void)
77077+{
77078+#ifdef CONFIG_GRKERNSEC_TIME
77079+ if (grsec_enable_time)
77080+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
77081+#endif
77082+ return;
77083+}
77084+
77085+EXPORT_SYMBOL_GPL(gr_log_timechange);
77086diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
77087new file mode 100644
77088index 0000000..d1953de
77089--- /dev/null
77090+++ b/grsecurity/grsec_tpe.c
77091@@ -0,0 +1,78 @@
77092+#include <linux/kernel.h>
77093+#include <linux/sched.h>
77094+#include <linux/file.h>
77095+#include <linux/fs.h>
77096+#include <linux/grinternal.h>
77097+
77098+extern int gr_acl_tpe_check(void);
77099+
77100+int
77101+gr_tpe_allow(const struct file *file)
77102+{
77103+#ifdef CONFIG_GRKERNSEC
77104+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
77105+ struct inode *file_inode = file->f_path.dentry->d_inode;
77106+ const struct cred *cred = current_cred();
77107+ char *msg = NULL;
77108+ char *msg2 = NULL;
77109+
77110+ // never restrict root
77111+ if (gr_is_global_root(cred->uid))
77112+ return 1;
77113+
77114+ if (grsec_enable_tpe) {
77115+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77116+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
77117+ msg = "not being in trusted group";
77118+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
77119+ msg = "being in untrusted group";
77120+#else
77121+ if (in_group_p(grsec_tpe_gid))
77122+ msg = "being in untrusted group";
77123+#endif
77124+ }
77125+ if (!msg && gr_acl_tpe_check())
77126+ msg = "being in untrusted role";
77127+
77128+ // not in any affected group/role
77129+ if (!msg)
77130+ goto next_check;
77131+
77132+ if (gr_is_global_nonroot(inode->i_uid))
77133+ msg2 = "file in non-root-owned directory";
77134+ else if (inode->i_mode & S_IWOTH)
77135+ msg2 = "file in world-writable directory";
77136+ else if (inode->i_mode & S_IWGRP)
77137+ msg2 = "file in group-writable directory";
77138+ else if (file_inode->i_mode & S_IWOTH)
77139+ msg2 = "file is world-writable";
77140+
77141+ if (msg && msg2) {
77142+ char fullmsg[70] = {0};
77143+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
77144+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
77145+ return 0;
77146+ }
77147+ msg = NULL;
77148+next_check:
77149+#ifdef CONFIG_GRKERNSEC_TPE_ALL
77150+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
77151+ return 1;
77152+
77153+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
77154+ msg = "directory not owned by user";
77155+ else if (inode->i_mode & S_IWOTH)
77156+ msg = "file in world-writable directory";
77157+ else if (inode->i_mode & S_IWGRP)
77158+ msg = "file in group-writable directory";
77159+ else if (file_inode->i_mode & S_IWOTH)
77160+ msg = "file is world-writable";
77161+
77162+ if (msg) {
77163+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
77164+ return 0;
77165+ }
77166+#endif
77167+#endif
77168+ return 1;
77169+}
77170diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
77171new file mode 100644
77172index 0000000..ae02d8e
77173--- /dev/null
77174+++ b/grsecurity/grsec_usb.c
77175@@ -0,0 +1,15 @@
77176+#include <linux/kernel.h>
77177+#include <linux/grinternal.h>
77178+#include <linux/module.h>
77179+
77180+int gr_handle_new_usb(void)
77181+{
77182+#ifdef CONFIG_GRKERNSEC_DENYUSB
77183+ if (grsec_deny_new_usb) {
77184+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
77185+ return 1;
77186+ }
77187+#endif
77188+ return 0;
77189+}
77190+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
77191diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
77192new file mode 100644
77193index 0000000..158b330
77194--- /dev/null
77195+++ b/grsecurity/grsum.c
77196@@ -0,0 +1,64 @@
77197+#include <linux/err.h>
77198+#include <linux/kernel.h>
77199+#include <linux/sched.h>
77200+#include <linux/mm.h>
77201+#include <linux/scatterlist.h>
77202+#include <linux/crypto.h>
77203+#include <linux/gracl.h>
77204+
77205+
77206+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
77207+#error "crypto and sha256 must be built into the kernel"
77208+#endif
77209+
77210+int
77211+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
77212+{
77213+ struct crypto_hash *tfm;
77214+ struct hash_desc desc;
77215+ struct scatterlist sg[2];
77216+ unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
77217+ unsigned long *tmpsumptr = (unsigned long *)temp_sum;
77218+ unsigned long *sumptr = (unsigned long *)sum;
77219+ int cryptres;
77220+ int retval = 1;
77221+ volatile int mismatched = 0;
77222+ volatile int dummy = 0;
77223+ unsigned int i;
77224+
77225+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
77226+ if (IS_ERR(tfm)) {
77227+ /* should never happen, since sha256 should be built in */
77228+ memset(entry->pw, 0, GR_PW_LEN);
77229+ return 1;
77230+ }
77231+
77232+ sg_init_table(sg, 2);
77233+ sg_set_buf(&sg[0], salt, GR_SALT_LEN);
77234+ sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
77235+
77236+ desc.tfm = tfm;
77237+ desc.flags = 0;
77238+
77239+ cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
77240+ temp_sum);
77241+
77242+ memset(entry->pw, 0, GR_PW_LEN);
77243+
77244+ if (cryptres)
77245+ goto out;
77246+
77247+ for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
77248+ if (sumptr[i] != tmpsumptr[i])
77249+ mismatched = 1;
77250+ else
77251+ dummy = 1; // waste a cycle
77252+
77253+ if (!mismatched)
77254+ retval = dummy - 1;
77255+
77256+out:
77257+ crypto_free_hash(tfm);
77258+
77259+ return retval;
77260+}
77261diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
77262index 77ff547..181834f 100644
77263--- a/include/asm-generic/4level-fixup.h
77264+++ b/include/asm-generic/4level-fixup.h
77265@@ -13,8 +13,10 @@
77266 #define pmd_alloc(mm, pud, address) \
77267 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
77268 NULL: pmd_offset(pud, address))
77269+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
77270
77271 #define pud_alloc(mm, pgd, address) (pgd)
77272+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
77273 #define pud_offset(pgd, start) (pgd)
77274 #define pud_none(pud) 0
77275 #define pud_bad(pud) 0
77276diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
77277index b7babf0..97f4c4f 100644
77278--- a/include/asm-generic/atomic-long.h
77279+++ b/include/asm-generic/atomic-long.h
77280@@ -22,6 +22,12 @@
77281
77282 typedef atomic64_t atomic_long_t;
77283
77284+#ifdef CONFIG_PAX_REFCOUNT
77285+typedef atomic64_unchecked_t atomic_long_unchecked_t;
77286+#else
77287+typedef atomic64_t atomic_long_unchecked_t;
77288+#endif
77289+
77290 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
77291
77292 static inline long atomic_long_read(atomic_long_t *l)
77293@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77294 return (long)atomic64_read(v);
77295 }
77296
77297+#ifdef CONFIG_PAX_REFCOUNT
77298+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77299+{
77300+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77301+
77302+ return (long)atomic64_read_unchecked(v);
77303+}
77304+#endif
77305+
77306 static inline void atomic_long_set(atomic_long_t *l, long i)
77307 {
77308 atomic64_t *v = (atomic64_t *)l;
77309@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77310 atomic64_set(v, i);
77311 }
77312
77313+#ifdef CONFIG_PAX_REFCOUNT
77314+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77315+{
77316+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77317+
77318+ atomic64_set_unchecked(v, i);
77319+}
77320+#endif
77321+
77322 static inline void atomic_long_inc(atomic_long_t *l)
77323 {
77324 atomic64_t *v = (atomic64_t *)l;
77325@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77326 atomic64_inc(v);
77327 }
77328
77329+#ifdef CONFIG_PAX_REFCOUNT
77330+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77331+{
77332+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77333+
77334+ atomic64_inc_unchecked(v);
77335+}
77336+#endif
77337+
77338 static inline void atomic_long_dec(atomic_long_t *l)
77339 {
77340 atomic64_t *v = (atomic64_t *)l;
77341@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77342 atomic64_dec(v);
77343 }
77344
77345+#ifdef CONFIG_PAX_REFCOUNT
77346+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77347+{
77348+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77349+
77350+ atomic64_dec_unchecked(v);
77351+}
77352+#endif
77353+
77354 static inline void atomic_long_add(long i, atomic_long_t *l)
77355 {
77356 atomic64_t *v = (atomic64_t *)l;
77357@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77358 atomic64_add(i, v);
77359 }
77360
77361+#ifdef CONFIG_PAX_REFCOUNT
77362+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77363+{
77364+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77365+
77366+ atomic64_add_unchecked(i, v);
77367+}
77368+#endif
77369+
77370 static inline void atomic_long_sub(long i, atomic_long_t *l)
77371 {
77372 atomic64_t *v = (atomic64_t *)l;
77373@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77374 atomic64_sub(i, v);
77375 }
77376
77377+#ifdef CONFIG_PAX_REFCOUNT
77378+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77379+{
77380+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77381+
77382+ atomic64_sub_unchecked(i, v);
77383+}
77384+#endif
77385+
77386 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77387 {
77388 atomic64_t *v = (atomic64_t *)l;
77389@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
77390 return atomic64_add_negative(i, v);
77391 }
77392
77393-static inline long atomic_long_add_return(long i, atomic_long_t *l)
77394+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
77395 {
77396 atomic64_t *v = (atomic64_t *)l;
77397
77398 return (long)atomic64_add_return(i, v);
77399 }
77400
77401+#ifdef CONFIG_PAX_REFCOUNT
77402+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77403+{
77404+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77405+
77406+ return (long)atomic64_add_return_unchecked(i, v);
77407+}
77408+#endif
77409+
77410 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77411 {
77412 atomic64_t *v = (atomic64_t *)l;
77413@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77414 return (long)atomic64_inc_return(v);
77415 }
77416
77417+#ifdef CONFIG_PAX_REFCOUNT
77418+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77419+{
77420+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77421+
77422+ return (long)atomic64_inc_return_unchecked(v);
77423+}
77424+#endif
77425+
77426 static inline long atomic_long_dec_return(atomic_long_t *l)
77427 {
77428 atomic64_t *v = (atomic64_t *)l;
77429@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77430
77431 typedef atomic_t atomic_long_t;
77432
77433+#ifdef CONFIG_PAX_REFCOUNT
77434+typedef atomic_unchecked_t atomic_long_unchecked_t;
77435+#else
77436+typedef atomic_t atomic_long_unchecked_t;
77437+#endif
77438+
77439 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
77440 static inline long atomic_long_read(atomic_long_t *l)
77441 {
77442@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77443 return (long)atomic_read(v);
77444 }
77445
77446+#ifdef CONFIG_PAX_REFCOUNT
77447+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77448+{
77449+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77450+
77451+ return (long)atomic_read_unchecked(v);
77452+}
77453+#endif
77454+
77455 static inline void atomic_long_set(atomic_long_t *l, long i)
77456 {
77457 atomic_t *v = (atomic_t *)l;
77458@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77459 atomic_set(v, i);
77460 }
77461
77462+#ifdef CONFIG_PAX_REFCOUNT
77463+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77464+{
77465+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77466+
77467+ atomic_set_unchecked(v, i);
77468+}
77469+#endif
77470+
77471 static inline void atomic_long_inc(atomic_long_t *l)
77472 {
77473 atomic_t *v = (atomic_t *)l;
77474@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77475 atomic_inc(v);
77476 }
77477
77478+#ifdef CONFIG_PAX_REFCOUNT
77479+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77480+{
77481+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77482+
77483+ atomic_inc_unchecked(v);
77484+}
77485+#endif
77486+
77487 static inline void atomic_long_dec(atomic_long_t *l)
77488 {
77489 atomic_t *v = (atomic_t *)l;
77490@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77491 atomic_dec(v);
77492 }
77493
77494+#ifdef CONFIG_PAX_REFCOUNT
77495+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77496+{
77497+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77498+
77499+ atomic_dec_unchecked(v);
77500+}
77501+#endif
77502+
77503 static inline void atomic_long_add(long i, atomic_long_t *l)
77504 {
77505 atomic_t *v = (atomic_t *)l;
77506@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77507 atomic_add(i, v);
77508 }
77509
77510+#ifdef CONFIG_PAX_REFCOUNT
77511+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77512+{
77513+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77514+
77515+ atomic_add_unchecked(i, v);
77516+}
77517+#endif
77518+
77519 static inline void atomic_long_sub(long i, atomic_long_t *l)
77520 {
77521 atomic_t *v = (atomic_t *)l;
77522@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77523 atomic_sub(i, v);
77524 }
77525
77526+#ifdef CONFIG_PAX_REFCOUNT
77527+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77528+{
77529+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77530+
77531+ atomic_sub_unchecked(i, v);
77532+}
77533+#endif
77534+
77535 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77536 {
77537 atomic_t *v = (atomic_t *)l;
77538@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77539 return (long)atomic_add_return(i, v);
77540 }
77541
77542+#ifdef CONFIG_PAX_REFCOUNT
77543+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77544+{
77545+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77546+
77547+ return (long)atomic_add_return_unchecked(i, v);
77548+}
77549+
77550+#endif
77551+
77552 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77553 {
77554 atomic_t *v = (atomic_t *)l;
77555@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77556 return (long)atomic_inc_return(v);
77557 }
77558
77559+#ifdef CONFIG_PAX_REFCOUNT
77560+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77561+{
77562+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77563+
77564+ return (long)atomic_inc_return_unchecked(v);
77565+}
77566+#endif
77567+
77568 static inline long atomic_long_dec_return(atomic_long_t *l)
77569 {
77570 atomic_t *v = (atomic_t *)l;
77571@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77572
77573 #endif /* BITS_PER_LONG == 64 */
77574
77575+#ifdef CONFIG_PAX_REFCOUNT
77576+static inline void pax_refcount_needs_these_functions(void)
77577+{
77578+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
77579+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77580+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77581+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77582+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77583+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77584+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77585+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77586+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77587+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77588+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77589+#ifdef CONFIG_X86
77590+ atomic_clear_mask_unchecked(0, NULL);
77591+ atomic_set_mask_unchecked(0, NULL);
77592+#endif
77593+
77594+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77595+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77596+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77597+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77598+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77599+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77600+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77601+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77602+}
77603+#else
77604+#define atomic_read_unchecked(v) atomic_read(v)
77605+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77606+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77607+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77608+#define atomic_inc_unchecked(v) atomic_inc(v)
77609+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77610+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77611+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77612+#define atomic_dec_unchecked(v) atomic_dec(v)
77613+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77614+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77615+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77616+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77617+
77618+#define atomic_long_read_unchecked(v) atomic_long_read(v)
77619+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77620+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77621+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77622+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77623+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77624+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77625+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77626+#endif
77627+
77628 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77629diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77630index 33bd2de..f31bff97 100644
77631--- a/include/asm-generic/atomic.h
77632+++ b/include/asm-generic/atomic.h
77633@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77634 * Atomically clears the bits set in @mask from @v
77635 */
77636 #ifndef atomic_clear_mask
77637-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77638+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77639 {
77640 unsigned long flags;
77641
77642diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77643index b18ce4f..2ee2843 100644
77644--- a/include/asm-generic/atomic64.h
77645+++ b/include/asm-generic/atomic64.h
77646@@ -16,6 +16,8 @@ typedef struct {
77647 long long counter;
77648 } atomic64_t;
77649
77650+typedef atomic64_t atomic64_unchecked_t;
77651+
77652 #define ATOMIC64_INIT(i) { (i) }
77653
77654 extern long long atomic64_read(const atomic64_t *v);
77655@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77656 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77657 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77658
77659+#define atomic64_read_unchecked(v) atomic64_read(v)
77660+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77661+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77662+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77663+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77664+#define atomic64_inc_unchecked(v) atomic64_inc(v)
77665+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77666+#define atomic64_dec_unchecked(v) atomic64_dec(v)
77667+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77668+
77669 #endif /* _ASM_GENERIC_ATOMIC64_H */
77670diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
77671index 6f692f8..2ad9dd2 100644
77672--- a/include/asm-generic/barrier.h
77673+++ b/include/asm-generic/barrier.h
77674@@ -66,7 +66,7 @@
77675 do { \
77676 compiletime_assert_atomic_type(*p); \
77677 smp_mb(); \
77678- ACCESS_ONCE(*p) = (v); \
77679+ ACCESS_ONCE_RW(*p) = (v); \
77680 } while (0)
77681
77682 #define smp_load_acquire(p) \
77683diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77684index a60a7cc..0fe12f2 100644
77685--- a/include/asm-generic/bitops/__fls.h
77686+++ b/include/asm-generic/bitops/__fls.h
77687@@ -9,7 +9,7 @@
77688 *
77689 * Undefined if no set bit exists, so code should check against 0 first.
77690 */
77691-static __always_inline unsigned long __fls(unsigned long word)
77692+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77693 {
77694 int num = BITS_PER_LONG - 1;
77695
77696diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77697index 0576d1f..dad6c71 100644
77698--- a/include/asm-generic/bitops/fls.h
77699+++ b/include/asm-generic/bitops/fls.h
77700@@ -9,7 +9,7 @@
77701 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77702 */
77703
77704-static __always_inline int fls(int x)
77705+static __always_inline int __intentional_overflow(-1) fls(int x)
77706 {
77707 int r = 32;
77708
77709diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77710index b097cf8..3d40e14 100644
77711--- a/include/asm-generic/bitops/fls64.h
77712+++ b/include/asm-generic/bitops/fls64.h
77713@@ -15,7 +15,7 @@
77714 * at position 64.
77715 */
77716 #if BITS_PER_LONG == 32
77717-static __always_inline int fls64(__u64 x)
77718+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77719 {
77720 __u32 h = x >> 32;
77721 if (h)
77722@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77723 return fls(x);
77724 }
77725 #elif BITS_PER_LONG == 64
77726-static __always_inline int fls64(__u64 x)
77727+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77728 {
77729 if (x == 0)
77730 return 0;
77731diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77732index 1bfcfe5..e04c5c9 100644
77733--- a/include/asm-generic/cache.h
77734+++ b/include/asm-generic/cache.h
77735@@ -6,7 +6,7 @@
77736 * cache lines need to provide their own cache.h.
77737 */
77738
77739-#define L1_CACHE_SHIFT 5
77740-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77741+#define L1_CACHE_SHIFT 5UL
77742+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77743
77744 #endif /* __ASM_GENERIC_CACHE_H */
77745diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77746index 0d68a1e..b74a761 100644
77747--- a/include/asm-generic/emergency-restart.h
77748+++ b/include/asm-generic/emergency-restart.h
77749@@ -1,7 +1,7 @@
77750 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77751 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77752
77753-static inline void machine_emergency_restart(void)
77754+static inline __noreturn void machine_emergency_restart(void)
77755 {
77756 machine_restart(NULL);
77757 }
77758diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
77759index 975e1cc..0b8a083 100644
77760--- a/include/asm-generic/io.h
77761+++ b/include/asm-generic/io.h
77762@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
77763 * These are pretty trivial
77764 */
77765 #ifndef virt_to_phys
77766-static inline unsigned long virt_to_phys(volatile void *address)
77767+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
77768 {
77769 return __pa((unsigned long)address);
77770 }
77771diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77772index 90f99c7..00ce236 100644
77773--- a/include/asm-generic/kmap_types.h
77774+++ b/include/asm-generic/kmap_types.h
77775@@ -2,9 +2,9 @@
77776 #define _ASM_GENERIC_KMAP_TYPES_H
77777
77778 #ifdef __WITH_KM_FENCE
77779-# define KM_TYPE_NR 41
77780+# define KM_TYPE_NR 42
77781 #else
77782-# define KM_TYPE_NR 20
77783+# define KM_TYPE_NR 21
77784 #endif
77785
77786 #endif
77787diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77788index 9ceb03b..62b0b8f 100644
77789--- a/include/asm-generic/local.h
77790+++ b/include/asm-generic/local.h
77791@@ -23,24 +23,37 @@ typedef struct
77792 atomic_long_t a;
77793 } local_t;
77794
77795+typedef struct {
77796+ atomic_long_unchecked_t a;
77797+} local_unchecked_t;
77798+
77799 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77800
77801 #define local_read(l) atomic_long_read(&(l)->a)
77802+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77803 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77804+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77805 #define local_inc(l) atomic_long_inc(&(l)->a)
77806+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77807 #define local_dec(l) atomic_long_dec(&(l)->a)
77808+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77809 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77810+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77811 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77812+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77813
77814 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77815 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77816 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77817 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77818 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77819+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77820 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77821 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77822+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77823
77824 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77825+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77826 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77827 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77828 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77829diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77830index 725612b..9cc513a 100644
77831--- a/include/asm-generic/pgtable-nopmd.h
77832+++ b/include/asm-generic/pgtable-nopmd.h
77833@@ -1,14 +1,19 @@
77834 #ifndef _PGTABLE_NOPMD_H
77835 #define _PGTABLE_NOPMD_H
77836
77837-#ifndef __ASSEMBLY__
77838-
77839 #include <asm-generic/pgtable-nopud.h>
77840
77841-struct mm_struct;
77842-
77843 #define __PAGETABLE_PMD_FOLDED
77844
77845+#define PMD_SHIFT PUD_SHIFT
77846+#define PTRS_PER_PMD 1
77847+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77848+#define PMD_MASK (~(PMD_SIZE-1))
77849+
77850+#ifndef __ASSEMBLY__
77851+
77852+struct mm_struct;
77853+
77854 /*
77855 * Having the pmd type consist of a pud gets the size right, and allows
77856 * us to conceptually access the pud entry that this pmd is folded into
77857@@ -16,11 +21,6 @@ struct mm_struct;
77858 */
77859 typedef struct { pud_t pud; } pmd_t;
77860
77861-#define PMD_SHIFT PUD_SHIFT
77862-#define PTRS_PER_PMD 1
77863-#define PMD_SIZE (1UL << PMD_SHIFT)
77864-#define PMD_MASK (~(PMD_SIZE-1))
77865-
77866 /*
77867 * The "pud_xxx()" functions here are trivial for a folded two-level
77868 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77869diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77870index 810431d..0ec4804f 100644
77871--- a/include/asm-generic/pgtable-nopud.h
77872+++ b/include/asm-generic/pgtable-nopud.h
77873@@ -1,10 +1,15 @@
77874 #ifndef _PGTABLE_NOPUD_H
77875 #define _PGTABLE_NOPUD_H
77876
77877-#ifndef __ASSEMBLY__
77878-
77879 #define __PAGETABLE_PUD_FOLDED
77880
77881+#define PUD_SHIFT PGDIR_SHIFT
77882+#define PTRS_PER_PUD 1
77883+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77884+#define PUD_MASK (~(PUD_SIZE-1))
77885+
77886+#ifndef __ASSEMBLY__
77887+
77888 /*
77889 * Having the pud type consist of a pgd gets the size right, and allows
77890 * us to conceptually access the pgd entry that this pud is folded into
77891@@ -12,11 +17,6 @@
77892 */
77893 typedef struct { pgd_t pgd; } pud_t;
77894
77895-#define PUD_SHIFT PGDIR_SHIFT
77896-#define PTRS_PER_PUD 1
77897-#define PUD_SIZE (1UL << PUD_SHIFT)
77898-#define PUD_MASK (~(PUD_SIZE-1))
77899-
77900 /*
77901 * The "pgd_xxx()" functions here are trivial for a folded two-level
77902 * setup: the pud is never bad, and a pud always exists (as it's folded
77903@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77904 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77905
77906 #define pgd_populate(mm, pgd, pud) do { } while (0)
77907+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77908 /*
77909 * (puds are folded into pgds so this doesn't get actually called,
77910 * but the define is needed for a generic inline function.)
77911diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77912index a8015a7..7a4407b 100644
77913--- a/include/asm-generic/pgtable.h
77914+++ b/include/asm-generic/pgtable.h
77915@@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77916 }
77917 #endif /* CONFIG_NUMA_BALANCING */
77918
77919+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77920+#ifdef CONFIG_PAX_KERNEXEC
77921+#error KERNEXEC requires pax_open_kernel
77922+#else
77923+static inline unsigned long pax_open_kernel(void) { return 0; }
77924+#endif
77925+#endif
77926+
77927+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77928+#ifdef CONFIG_PAX_KERNEXEC
77929+#error KERNEXEC requires pax_close_kernel
77930+#else
77931+static inline unsigned long pax_close_kernel(void) { return 0; }
77932+#endif
77933+#endif
77934+
77935 #endif /* CONFIG_MMU */
77936
77937 #endif /* !__ASSEMBLY__ */
77938diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77939index 72d8803..cb9749c 100644
77940--- a/include/asm-generic/uaccess.h
77941+++ b/include/asm-generic/uaccess.h
77942@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77943 return __clear_user(to, n);
77944 }
77945
77946+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77947+#ifdef CONFIG_PAX_MEMORY_UDEREF
77948+#error UDEREF requires pax_open_userland
77949+#else
77950+static inline unsigned long pax_open_userland(void) { return 0; }
77951+#endif
77952+#endif
77953+
77954+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77955+#ifdef CONFIG_PAX_MEMORY_UDEREF
77956+#error UDEREF requires pax_close_userland
77957+#else
77958+static inline unsigned long pax_close_userland(void) { return 0; }
77959+#endif
77960+#endif
77961+
77962 #endif /* __ASM_GENERIC_UACCESS_H */
77963diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77964index 146e4ff..f4f9609 100644
77965--- a/include/asm-generic/vmlinux.lds.h
77966+++ b/include/asm-generic/vmlinux.lds.h
77967@@ -251,6 +251,7 @@
77968 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77969 VMLINUX_SYMBOL(__start_rodata) = .; \
77970 *(.rodata) *(.rodata.*) \
77971+ *(.data..read_only) \
77972 *(__vermagic) /* Kernel version magic */ \
77973 . = ALIGN(8); \
77974 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77975@@ -737,17 +738,18 @@
77976 * section in the linker script will go there too. @phdr should have
77977 * a leading colon.
77978 *
77979- * Note that this macros defines __per_cpu_load as an absolute symbol.
77980+ * Note that this macros defines per_cpu_load as an absolute symbol.
77981 * If there is no need to put the percpu section at a predetermined
77982 * address, use PERCPU_SECTION.
77983 */
77984 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77985- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77986- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77987+ per_cpu_load = .; \
77988+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77989 - LOAD_OFFSET) { \
77990+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77991 PERCPU_INPUT(cacheline) \
77992 } phdr \
77993- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77994+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77995
77996 /**
77997 * PERCPU_SECTION - define output section for percpu area, simple version
77998diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77999index 016c2f1..c4baa98 100644
78000--- a/include/crypto/algapi.h
78001+++ b/include/crypto/algapi.h
78002@@ -34,7 +34,7 @@ struct crypto_type {
78003 unsigned int maskclear;
78004 unsigned int maskset;
78005 unsigned int tfmsize;
78006-};
78007+} __do_const;
78008
78009 struct crypto_instance {
78010 struct crypto_alg alg;
78011diff --git a/include/drm/drmP.h b/include/drm/drmP.h
78012index a7c2a86..078f1b6 100644
78013--- a/include/drm/drmP.h
78014+++ b/include/drm/drmP.h
78015@@ -68,6 +68,7 @@
78016 #include <linux/workqueue.h>
78017 #include <linux/poll.h>
78018 #include <asm/pgalloc.h>
78019+#include <asm/local.h>
78020 #include <drm/drm.h>
78021 #include <drm/drm_sarea.h>
78022 #include <drm/drm_vma_manager.h>
78023@@ -268,10 +269,12 @@ do { \
78024 * \param cmd command.
78025 * \param arg argument.
78026 */
78027-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
78028+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
78029+ struct drm_file *file_priv);
78030+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
78031 struct drm_file *file_priv);
78032
78033-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
78034+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
78035 unsigned long arg);
78036
78037 #define DRM_IOCTL_NR(n) _IOC_NR(n)
78038@@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
78039 struct drm_ioctl_desc {
78040 unsigned int cmd;
78041 int flags;
78042- drm_ioctl_t *func;
78043+ drm_ioctl_t func;
78044 unsigned int cmd_drv;
78045 const char *name;
78046-};
78047+} __do_const;
78048
78049 /**
78050 * Creates a driver or general drm_ioctl_desc array entry for the given
78051@@ -1001,7 +1004,8 @@ struct drm_info_list {
78052 int (*show)(struct seq_file*, void*); /** show callback */
78053 u32 driver_features; /**< Required driver features for this entry */
78054 void *data;
78055-};
78056+} __do_const;
78057+typedef struct drm_info_list __no_const drm_info_list_no_const;
78058
78059 /**
78060 * debugfs node structure. This structure represents a debugfs file.
78061@@ -1083,7 +1087,7 @@ struct drm_device {
78062
78063 /** \name Usage Counters */
78064 /*@{ */
78065- int open_count; /**< Outstanding files open */
78066+ local_t open_count; /**< Outstanding files open */
78067 int buf_use; /**< Buffers in use -- cannot alloc */
78068 atomic_t buf_alloc; /**< Buffer allocation in progress */
78069 /*@} */
78070diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
78071index 36a5feb..d9f01aa 100644
78072--- a/include/drm/drm_crtc_helper.h
78073+++ b/include/drm/drm_crtc_helper.h
78074@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
78075 struct drm_connector *connector);
78076 /* disable encoder when not in use - more explicit than dpms off */
78077 void (*disable)(struct drm_encoder *encoder);
78078-};
78079+} __no_const;
78080
78081 /**
78082 * drm_connector_helper_funcs - helper operations for connectors
78083diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
78084index 012d58f..d0a0642 100644
78085--- a/include/drm/i915_pciids.h
78086+++ b/include/drm/i915_pciids.h
78087@@ -37,7 +37,7 @@
78088 */
78089 #define INTEL_VGA_DEVICE(id, info) { \
78090 0x8086, id, \
78091- ~0, ~0, \
78092+ PCI_ANY_ID, PCI_ANY_ID, \
78093 0x030000, 0xff0000, \
78094 (unsigned long) info }
78095
78096diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
78097index 72dcbe8..8db58d7 100644
78098--- a/include/drm/ttm/ttm_memory.h
78099+++ b/include/drm/ttm/ttm_memory.h
78100@@ -48,7 +48,7 @@
78101
78102 struct ttm_mem_shrink {
78103 int (*do_shrink) (struct ttm_mem_shrink *);
78104-};
78105+} __no_const;
78106
78107 /**
78108 * struct ttm_mem_global - Global memory accounting structure.
78109diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
78110index 49a8284..9643967 100644
78111--- a/include/drm/ttm/ttm_page_alloc.h
78112+++ b/include/drm/ttm/ttm_page_alloc.h
78113@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
78114 */
78115 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
78116
78117+struct device;
78118 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
78119 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
78120
78121diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
78122index 4b840e8..155d235 100644
78123--- a/include/keys/asymmetric-subtype.h
78124+++ b/include/keys/asymmetric-subtype.h
78125@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
78126 /* Verify the signature on a key of this subtype (optional) */
78127 int (*verify_signature)(const struct key *key,
78128 const struct public_key_signature *sig);
78129-};
78130+} __do_const;
78131
78132 /**
78133 * asymmetric_key_subtype - Get the subtype from an asymmetric key
78134diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
78135index c1da539..1dcec55 100644
78136--- a/include/linux/atmdev.h
78137+++ b/include/linux/atmdev.h
78138@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
78139 #endif
78140
78141 struct k_atm_aal_stats {
78142-#define __HANDLE_ITEM(i) atomic_t i
78143+#define __HANDLE_ITEM(i) atomic_unchecked_t i
78144 __AAL_STAT_ITEMS
78145 #undef __HANDLE_ITEM
78146 };
78147@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
78148 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
78149 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
78150 struct module *owner;
78151-};
78152+} __do_const ;
78153
78154 struct atmphy_ops {
78155 int (*start)(struct atm_dev *dev);
78156diff --git a/include/linux/audit.h b/include/linux/audit.h
78157index 22cfddb..ab759e8 100644
78158--- a/include/linux/audit.h
78159+++ b/include/linux/audit.h
78160@@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
78161 extern unsigned int audit_serial(void);
78162 extern int auditsc_get_stamp(struct audit_context *ctx,
78163 struct timespec *t, unsigned int *serial);
78164-extern int audit_set_loginuid(kuid_t loginuid);
78165+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
78166
78167 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
78168 {
78169diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
78170index 61f29e5..e67c658 100644
78171--- a/include/linux/binfmts.h
78172+++ b/include/linux/binfmts.h
78173@@ -44,7 +44,7 @@ struct linux_binprm {
78174 unsigned interp_flags;
78175 unsigned interp_data;
78176 unsigned long loader, exec;
78177-};
78178+} __randomize_layout;
78179
78180 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
78181 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
78182@@ -73,8 +73,10 @@ struct linux_binfmt {
78183 int (*load_binary)(struct linux_binprm *);
78184 int (*load_shlib)(struct file *);
78185 int (*core_dump)(struct coredump_params *cprm);
78186+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
78187+ void (*handle_mmap)(struct file *);
78188 unsigned long min_coredump; /* minimal dump size */
78189-};
78190+} __do_const __randomize_layout;
78191
78192 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
78193
78194diff --git a/include/linux/bitops.h b/include/linux/bitops.h
78195index be5fd38..d71192a 100644
78196--- a/include/linux/bitops.h
78197+++ b/include/linux/bitops.h
78198@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
78199 * @word: value to rotate
78200 * @shift: bits to roll
78201 */
78202-static inline __u32 rol32(__u32 word, unsigned int shift)
78203+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
78204 {
78205 return (word << shift) | (word >> (32 - shift));
78206 }
78207@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
78208 * @word: value to rotate
78209 * @shift: bits to roll
78210 */
78211-static inline __u32 ror32(__u32 word, unsigned int shift)
78212+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
78213 {
78214 return (word >> shift) | (word << (32 - shift));
78215 }
78216@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
78217 return (__s32)(value << shift) >> shift;
78218 }
78219
78220-static inline unsigned fls_long(unsigned long l)
78221+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
78222 {
78223 if (sizeof(l) == 4)
78224 return fls(l);
78225diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
78226index 0d84981..bb741c0 100644
78227--- a/include/linux/blkdev.h
78228+++ b/include/linux/blkdev.h
78229@@ -1584,7 +1584,7 @@ struct block_device_operations {
78230 /* this callback is with swap_lock and sometimes page table lock held */
78231 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
78232 struct module *owner;
78233-};
78234+} __do_const;
78235
78236 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
78237 unsigned long);
78238diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
78239index afc1343..9735539 100644
78240--- a/include/linux/blktrace_api.h
78241+++ b/include/linux/blktrace_api.h
78242@@ -25,7 +25,7 @@ struct blk_trace {
78243 struct dentry *dropped_file;
78244 struct dentry *msg_file;
78245 struct list_head running_list;
78246- atomic_t dropped;
78247+ atomic_unchecked_t dropped;
78248 };
78249
78250 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
78251diff --git a/include/linux/cache.h b/include/linux/cache.h
78252index 17e7e82..1d7da26 100644
78253--- a/include/linux/cache.h
78254+++ b/include/linux/cache.h
78255@@ -16,6 +16,14 @@
78256 #define __read_mostly
78257 #endif
78258
78259+#ifndef __read_only
78260+#ifdef CONFIG_PAX_KERNEXEC
78261+#error KERNEXEC requires __read_only
78262+#else
78263+#define __read_only __read_mostly
78264+#endif
78265+#endif
78266+
78267 #ifndef ____cacheline_aligned
78268 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
78269 #endif
78270diff --git a/include/linux/capability.h b/include/linux/capability.h
78271index 84b13ad..172cdee 100644
78272--- a/include/linux/capability.h
78273+++ b/include/linux/capability.h
78274@@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
78275 extern bool capable(int cap);
78276 extern bool ns_capable(struct user_namespace *ns, int cap);
78277 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
78278+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
78279 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
78280+extern bool capable_nolog(int cap);
78281+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
78282
78283 /* audit system wants to get cap info from files as well */
78284 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
78285
78286+extern int is_privileged_binary(const struct dentry *dentry);
78287+
78288 #endif /* !_LINUX_CAPABILITY_H */
78289diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
78290index 8609d57..86e4d79 100644
78291--- a/include/linux/cdrom.h
78292+++ b/include/linux/cdrom.h
78293@@ -87,7 +87,6 @@ struct cdrom_device_ops {
78294
78295 /* driver specifications */
78296 const int capability; /* capability flags */
78297- int n_minors; /* number of active minor devices */
78298 /* handle uniform packets for scsi type devices (scsi,atapi) */
78299 int (*generic_packet) (struct cdrom_device_info *,
78300 struct packet_command *);
78301diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
78302index 4ce9056..86caac6 100644
78303--- a/include/linux/cleancache.h
78304+++ b/include/linux/cleancache.h
78305@@ -31,7 +31,7 @@ struct cleancache_ops {
78306 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
78307 void (*invalidate_inode)(int, struct cleancache_filekey);
78308 void (*invalidate_fs)(int);
78309-};
78310+} __no_const;
78311
78312 extern struct cleancache_ops *
78313 cleancache_register_ops(struct cleancache_ops *ops);
78314diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
78315index 5119174..8e264f8 100644
78316--- a/include/linux/clk-provider.h
78317+++ b/include/linux/clk-provider.h
78318@@ -174,6 +174,7 @@ struct clk_ops {
78319 void (*init)(struct clk_hw *hw);
78320 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
78321 };
78322+typedef struct clk_ops __no_const clk_ops_no_const;
78323
78324 /**
78325 * struct clk_init_data - holds init data that's common to all clocks and is
78326diff --git a/include/linux/compat.h b/include/linux/compat.h
78327index e649426..a74047b 100644
78328--- a/include/linux/compat.h
78329+++ b/include/linux/compat.h
78330@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
78331 compat_size_t __user *len_ptr);
78332
78333 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
78334-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
78335+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
78336 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
78337 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
78338 compat_ssize_t msgsz, int msgflg);
78339@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
78340 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
78341 compat_ulong_t addr, compat_ulong_t data);
78342 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
78343- compat_long_t addr, compat_long_t data);
78344+ compat_ulong_t addr, compat_ulong_t data);
78345
78346 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
78347 /*
78348diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
78349index 2507fd2..55203f8 100644
78350--- a/include/linux/compiler-gcc4.h
78351+++ b/include/linux/compiler-gcc4.h
78352@@ -39,9 +39,34 @@
78353 # define __compiletime_warning(message) __attribute__((warning(message)))
78354 # define __compiletime_error(message) __attribute__((error(message)))
78355 #endif /* __CHECKER__ */
78356+
78357+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
78358+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
78359+#define __bos0(ptr) __bos((ptr), 0)
78360+#define __bos1(ptr) __bos((ptr), 1)
78361 #endif /* GCC_VERSION >= 40300 */
78362
78363 #if GCC_VERSION >= 40500
78364+
78365+#ifdef RANDSTRUCT_PLUGIN
78366+#define __randomize_layout __attribute__((randomize_layout))
78367+#define __no_randomize_layout __attribute__((no_randomize_layout))
78368+#endif
78369+
78370+#ifdef CONSTIFY_PLUGIN
78371+#define __no_const __attribute__((no_const))
78372+#define __do_const __attribute__((do_const))
78373+#endif
78374+
78375+#ifdef SIZE_OVERFLOW_PLUGIN
78376+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
78377+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
78378+#endif
78379+
78380+#ifdef LATENT_ENTROPY_PLUGIN
78381+#define __latent_entropy __attribute__((latent_entropy))
78382+#endif
78383+
78384 /*
78385 * Mark a position in code as unreachable. This can be used to
78386 * suppress control flow warnings after asm blocks that transfer
78387diff --git a/include/linux/compiler.h b/include/linux/compiler.h
78388index ee7239e..7c11769 100644
78389--- a/include/linux/compiler.h
78390+++ b/include/linux/compiler.h
78391@@ -5,11 +5,14 @@
78392
78393 #ifdef __CHECKER__
78394 # define __user __attribute__((noderef, address_space(1)))
78395+# define __force_user __force __user
78396 # define __kernel __attribute__((address_space(0)))
78397+# define __force_kernel __force __kernel
78398 # define __safe __attribute__((safe))
78399 # define __force __attribute__((force))
78400 # define __nocast __attribute__((nocast))
78401 # define __iomem __attribute__((noderef, address_space(2)))
78402+# define __force_iomem __force __iomem
78403 # define __must_hold(x) __attribute__((context(x,1,1)))
78404 # define __acquires(x) __attribute__((context(x,0,1)))
78405 # define __releases(x) __attribute__((context(x,1,0)))
78406@@ -17,20 +20,37 @@
78407 # define __release(x) __context__(x,-1)
78408 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
78409 # define __percpu __attribute__((noderef, address_space(3)))
78410+# define __force_percpu __force __percpu
78411 #ifdef CONFIG_SPARSE_RCU_POINTER
78412 # define __rcu __attribute__((noderef, address_space(4)))
78413+# define __force_rcu __force __rcu
78414 #else
78415 # define __rcu
78416+# define __force_rcu
78417 #endif
78418 extern void __chk_user_ptr(const volatile void __user *);
78419 extern void __chk_io_ptr(const volatile void __iomem *);
78420 #else
78421-# define __user
78422-# define __kernel
78423+# ifdef CHECKER_PLUGIN
78424+//# define __user
78425+//# define __force_user
78426+//# define __kernel
78427+//# define __force_kernel
78428+# else
78429+# ifdef STRUCTLEAK_PLUGIN
78430+# define __user __attribute__((user))
78431+# else
78432+# define __user
78433+# endif
78434+# define __force_user
78435+# define __kernel
78436+# define __force_kernel
78437+# endif
78438 # define __safe
78439 # define __force
78440 # define __nocast
78441 # define __iomem
78442+# define __force_iomem
78443 # define __chk_user_ptr(x) (void)0
78444 # define __chk_io_ptr(x) (void)0
78445 # define __builtin_warning(x, y...) (1)
78446@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
78447 # define __release(x) (void)0
78448 # define __cond_lock(x,c) (c)
78449 # define __percpu
78450+# define __force_percpu
78451 # define __rcu
78452+# define __force_rcu
78453 #endif
78454
78455 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
78456@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78457 # define __attribute_const__ /* unimplemented */
78458 #endif
78459
78460+#ifndef __randomize_layout
78461+# define __randomize_layout
78462+#endif
78463+
78464+#ifndef __no_randomize_layout
78465+# define __no_randomize_layout
78466+#endif
78467+
78468+#ifndef __no_const
78469+# define __no_const
78470+#endif
78471+
78472+#ifndef __do_const
78473+# define __do_const
78474+#endif
78475+
78476+#ifndef __size_overflow
78477+# define __size_overflow(...)
78478+#endif
78479+
78480+#ifndef __intentional_overflow
78481+# define __intentional_overflow(...)
78482+#endif
78483+
78484+#ifndef __latent_entropy
78485+# define __latent_entropy
78486+#endif
78487+
78488 /*
78489 * Tell gcc if a function is cold. The compiler will assume any path
78490 * directly leading to the call is unlikely.
78491@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78492 #define __cold
78493 #endif
78494
78495+#ifndef __alloc_size
78496+#define __alloc_size(...)
78497+#endif
78498+
78499+#ifndef __bos
78500+#define __bos(ptr, arg)
78501+#endif
78502+
78503+#ifndef __bos0
78504+#define __bos0(ptr)
78505+#endif
78506+
78507+#ifndef __bos1
78508+#define __bos1(ptr)
78509+#endif
78510+
78511 /* Simple shorthand for a section definition */
78512 #ifndef __section
78513 # define __section(S) __attribute__ ((__section__(#S)))
78514@@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78515 * use is to mediate communication between process-level code and irq/NMI
78516 * handlers, all running on the same CPU.
78517 */
78518-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78519+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78520+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78521
78522 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78523 #ifdef CONFIG_KPROBES
78524diff --git a/include/linux/completion.h b/include/linux/completion.h
78525index 5d5aaae..0ea9b84 100644
78526--- a/include/linux/completion.h
78527+++ b/include/linux/completion.h
78528@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78529
78530 extern void wait_for_completion(struct completion *);
78531 extern void wait_for_completion_io(struct completion *);
78532-extern int wait_for_completion_interruptible(struct completion *x);
78533-extern int wait_for_completion_killable(struct completion *x);
78534+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78535+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78536 extern unsigned long wait_for_completion_timeout(struct completion *x,
78537- unsigned long timeout);
78538+ unsigned long timeout) __intentional_overflow(-1);
78539 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78540- unsigned long timeout);
78541+ unsigned long timeout) __intentional_overflow(-1);
78542 extern long wait_for_completion_interruptible_timeout(
78543- struct completion *x, unsigned long timeout);
78544+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78545 extern long wait_for_completion_killable_timeout(
78546- struct completion *x, unsigned long timeout);
78547+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78548 extern bool try_wait_for_completion(struct completion *x);
78549 extern bool completion_done(struct completion *x);
78550
78551diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78552index 34025df..d94bbbc 100644
78553--- a/include/linux/configfs.h
78554+++ b/include/linux/configfs.h
78555@@ -125,7 +125,7 @@ struct configfs_attribute {
78556 const char *ca_name;
78557 struct module *ca_owner;
78558 umode_t ca_mode;
78559-};
78560+} __do_const;
78561
78562 /*
78563 * Users often need to create attribute structures for their configurable
78564diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78565index 5ae5100..b809662 100644
78566--- a/include/linux/cpufreq.h
78567+++ b/include/linux/cpufreq.h
78568@@ -200,6 +200,7 @@ struct global_attr {
78569 ssize_t (*store)(struct kobject *a, struct attribute *b,
78570 const char *c, size_t count);
78571 };
78572+typedef struct global_attr __no_const global_attr_no_const;
78573
78574 #define define_one_global_ro(_name) \
78575 static struct global_attr _name = \
78576@@ -242,7 +243,7 @@ struct cpufreq_driver {
78577 bool boost_supported;
78578 bool boost_enabled;
78579 int (*set_boost) (int state);
78580-};
78581+} __do_const;
78582
78583 /* flags */
78584 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78585diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78586index b0238cb..db89e1e 100644
78587--- a/include/linux/cpuidle.h
78588+++ b/include/linux/cpuidle.h
78589@@ -50,7 +50,8 @@ struct cpuidle_state {
78590 int index);
78591
78592 int (*enter_dead) (struct cpuidle_device *dev, int index);
78593-};
78594+} __do_const;
78595+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78596
78597 /* Idle State Flags */
78598 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78599@@ -211,7 +212,7 @@ struct cpuidle_governor {
78600 void (*reflect) (struct cpuidle_device *dev, int index);
78601
78602 struct module *owner;
78603-};
78604+} __do_const;
78605
78606 #ifdef CONFIG_CPU_IDLE
78607 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78608diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78609index d08e4d2..95fad61 100644
78610--- a/include/linux/cpumask.h
78611+++ b/include/linux/cpumask.h
78612@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78613 }
78614
78615 /* Valid inputs for n are -1 and 0. */
78616-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78617+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78618 {
78619 return n+1;
78620 }
78621
78622-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78623+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78624 {
78625 return n+1;
78626 }
78627
78628-static inline unsigned int cpumask_next_and(int n,
78629+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78630 const struct cpumask *srcp,
78631 const struct cpumask *andp)
78632 {
78633@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78634 *
78635 * Returns >= nr_cpu_ids if no further cpus set.
78636 */
78637-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78638+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78639 {
78640 /* -1 is a legal arg here. */
78641 if (n != -1)
78642@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78643 *
78644 * Returns >= nr_cpu_ids if no further cpus unset.
78645 */
78646-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78647+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78648 {
78649 /* -1 is a legal arg here. */
78650 if (n != -1)
78651@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78652 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78653 }
78654
78655-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78656+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78657 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78658
78659 /**
78660diff --git a/include/linux/cred.h b/include/linux/cred.h
78661index f61d6c8..d372d95 100644
78662--- a/include/linux/cred.h
78663+++ b/include/linux/cred.h
78664@@ -35,7 +35,7 @@ struct group_info {
78665 int nblocks;
78666 kgid_t small_block[NGROUPS_SMALL];
78667 kgid_t *blocks[0];
78668-};
78669+} __randomize_layout;
78670
78671 /**
78672 * get_group_info - Get a reference to a group info structure
78673@@ -136,7 +136,7 @@ struct cred {
78674 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78675 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78676 struct rcu_head rcu; /* RCU deletion hook */
78677-};
78678+} __randomize_layout;
78679
78680 extern void __put_cred(struct cred *);
78681 extern void exit_creds(struct task_struct *);
78682@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78683 static inline void validate_process_creds(void)
78684 {
78685 }
78686+static inline void validate_task_creds(struct task_struct *task)
78687+{
78688+}
78689 #endif
78690
78691 /**
78692@@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
78693
78694 #define task_uid(task) (task_cred_xxx((task), uid))
78695 #define task_euid(task) (task_cred_xxx((task), euid))
78696+#define task_securebits(task) (task_cred_xxx((task), securebits))
78697
78698 #define current_cred_xxx(xxx) \
78699 ({ \
78700diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78701index b92eadf..b4ecdc1 100644
78702--- a/include/linux/crypto.h
78703+++ b/include/linux/crypto.h
78704@@ -373,7 +373,7 @@ struct cipher_tfm {
78705 const u8 *key, unsigned int keylen);
78706 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78707 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78708-};
78709+} __no_const;
78710
78711 struct hash_tfm {
78712 int (*init)(struct hash_desc *desc);
78713@@ -394,13 +394,13 @@ struct compress_tfm {
78714 int (*cot_decompress)(struct crypto_tfm *tfm,
78715 const u8 *src, unsigned int slen,
78716 u8 *dst, unsigned int *dlen);
78717-};
78718+} __no_const;
78719
78720 struct rng_tfm {
78721 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78722 unsigned int dlen);
78723 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78724-};
78725+} __no_const;
78726
78727 #define crt_ablkcipher crt_u.ablkcipher
78728 #define crt_aead crt_u.aead
78729diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78730index 653589e..4ef254a 100644
78731--- a/include/linux/ctype.h
78732+++ b/include/linux/ctype.h
78733@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78734 * Fast implementation of tolower() for internal usage. Do not use in your
78735 * code.
78736 */
78737-static inline char _tolower(const char c)
78738+static inline unsigned char _tolower(const unsigned char c)
78739 {
78740 return c | 0x20;
78741 }
78742diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78743index 3c7ec32..4ca97cc 100644
78744--- a/include/linux/dcache.h
78745+++ b/include/linux/dcache.h
78746@@ -133,7 +133,7 @@ struct dentry {
78747 } d_u;
78748 struct list_head d_subdirs; /* our children */
78749 struct hlist_node d_alias; /* inode alias list */
78750-};
78751+} __randomize_layout;
78752
78753 /*
78754 * dentry->d_lock spinlock nesting subclasses:
78755diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78756index 7925bf0..d5143d2 100644
78757--- a/include/linux/decompress/mm.h
78758+++ b/include/linux/decompress/mm.h
78759@@ -77,7 +77,7 @@ static void free(void *where)
78760 * warnings when not needed (indeed large_malloc / large_free are not
78761 * needed by inflate */
78762
78763-#define malloc(a) kmalloc(a, GFP_KERNEL)
78764+#define malloc(a) kmalloc((a), GFP_KERNEL)
78765 #define free(a) kfree(a)
78766
78767 #define large_malloc(a) vmalloc(a)
78768diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78769index d48dc00..211ee54 100644
78770--- a/include/linux/devfreq.h
78771+++ b/include/linux/devfreq.h
78772@@ -114,7 +114,7 @@ struct devfreq_governor {
78773 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78774 int (*event_handler)(struct devfreq *devfreq,
78775 unsigned int event, void *data);
78776-};
78777+} __do_const;
78778
78779 /**
78780 * struct devfreq - Device devfreq structure
78781diff --git a/include/linux/device.h b/include/linux/device.h
78782index d1d1c05..a90fdb0 100644
78783--- a/include/linux/device.h
78784+++ b/include/linux/device.h
78785@@ -310,7 +310,7 @@ struct subsys_interface {
78786 struct list_head node;
78787 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78788 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78789-};
78790+} __do_const;
78791
78792 int subsys_interface_register(struct subsys_interface *sif);
78793 void subsys_interface_unregister(struct subsys_interface *sif);
78794@@ -506,7 +506,7 @@ struct device_type {
78795 void (*release)(struct device *dev);
78796
78797 const struct dev_pm_ops *pm;
78798-};
78799+} __do_const;
78800
78801 /* interface for exporting device attributes */
78802 struct device_attribute {
78803@@ -516,11 +516,12 @@ struct device_attribute {
78804 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78805 const char *buf, size_t count);
78806 };
78807+typedef struct device_attribute __no_const device_attribute_no_const;
78808
78809 struct dev_ext_attribute {
78810 struct device_attribute attr;
78811 void *var;
78812-};
78813+} __do_const;
78814
78815 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78816 char *buf);
78817diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78818index fd4aee2..1f28db9 100644
78819--- a/include/linux/dma-mapping.h
78820+++ b/include/linux/dma-mapping.h
78821@@ -54,7 +54,7 @@ struct dma_map_ops {
78822 u64 (*get_required_mask)(struct device *dev);
78823 #endif
78824 int is_phys;
78825-};
78826+} __do_const;
78827
78828 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78829
78830diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78831index 72cb0dd..7fe9a4b 100644
78832--- a/include/linux/dmaengine.h
78833+++ b/include/linux/dmaengine.h
78834@@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78835 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78836 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78837
78838-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78839+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78840 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78841-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78842+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78843 struct dma_pinned_list *pinned_list, struct page *page,
78844 unsigned int offset, size_t len);
78845
78846diff --git a/include/linux/efi.h b/include/linux/efi.h
78847index 6c100ff..e3289b4 100644
78848--- a/include/linux/efi.h
78849+++ b/include/linux/efi.h
78850@@ -1009,6 +1009,7 @@ struct efivar_operations {
78851 efi_set_variable_t *set_variable;
78852 efi_query_variable_store_t *query_variable_store;
78853 };
78854+typedef struct efivar_operations __no_const efivar_operations_no_const;
78855
78856 struct efivars {
78857 /*
78858diff --git a/include/linux/elf.h b/include/linux/elf.h
78859index 67a5fa7..b817372 100644
78860--- a/include/linux/elf.h
78861+++ b/include/linux/elf.h
78862@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78863 #define elf_note elf32_note
78864 #define elf_addr_t Elf32_Off
78865 #define Elf_Half Elf32_Half
78866+#define elf_dyn Elf32_Dyn
78867
78868 #else
78869
78870@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78871 #define elf_note elf64_note
78872 #define elf_addr_t Elf64_Off
78873 #define Elf_Half Elf64_Half
78874+#define elf_dyn Elf64_Dyn
78875
78876 #endif
78877
78878diff --git a/include/linux/err.h b/include/linux/err.h
78879index a729120..6ede2c9 100644
78880--- a/include/linux/err.h
78881+++ b/include/linux/err.h
78882@@ -20,12 +20,12 @@
78883
78884 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78885
78886-static inline void * __must_check ERR_PTR(long error)
78887+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78888 {
78889 return (void *) error;
78890 }
78891
78892-static inline long __must_check PTR_ERR(__force const void *ptr)
78893+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78894 {
78895 return (long) ptr;
78896 }
78897diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78898index f488145..3b6b04e 100644
78899--- a/include/linux/extcon.h
78900+++ b/include/linux/extcon.h
78901@@ -135,7 +135,7 @@ struct extcon_dev {
78902 /* /sys/class/extcon/.../mutually_exclusive/... */
78903 struct attribute_group attr_g_muex;
78904 struct attribute **attrs_muex;
78905- struct device_attribute *d_attrs_muex;
78906+ device_attribute_no_const *d_attrs_muex;
78907 };
78908
78909 /**
78910diff --git a/include/linux/fb.h b/include/linux/fb.h
78911index fe6ac95..898d41d 100644
78912--- a/include/linux/fb.h
78913+++ b/include/linux/fb.h
78914@@ -304,7 +304,7 @@ struct fb_ops {
78915 /* called at KDB enter and leave time to prepare the console */
78916 int (*fb_debug_enter)(struct fb_info *info);
78917 int (*fb_debug_leave)(struct fb_info *info);
78918-};
78919+} __do_const;
78920
78921 #ifdef CONFIG_FB_TILEBLITTING
78922 #define FB_TILE_CURSOR_NONE 0
78923diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78924index 230f87b..1fd0485 100644
78925--- a/include/linux/fdtable.h
78926+++ b/include/linux/fdtable.h
78927@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78928 void put_files_struct(struct files_struct *fs);
78929 void reset_files_struct(struct files_struct *);
78930 int unshare_files(struct files_struct **);
78931-struct files_struct *dup_fd(struct files_struct *, int *);
78932+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78933 void do_close_on_exec(struct files_struct *);
78934 int iterate_fd(struct files_struct *, unsigned,
78935 int (*)(const void *, struct file *, unsigned),
78936diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78937index 8293262..2b3b8bd 100644
78938--- a/include/linux/frontswap.h
78939+++ b/include/linux/frontswap.h
78940@@ -11,7 +11,7 @@ struct frontswap_ops {
78941 int (*load)(unsigned, pgoff_t, struct page *);
78942 void (*invalidate_page)(unsigned, pgoff_t);
78943 void (*invalidate_area)(unsigned);
78944-};
78945+} __no_const;
78946
78947 extern bool frontswap_enabled;
78948 extern struct frontswap_ops *
78949diff --git a/include/linux/fs.h b/include/linux/fs.h
78950index 8780312..425cc22 100644
78951--- a/include/linux/fs.h
78952+++ b/include/linux/fs.h
78953@@ -398,7 +398,7 @@ struct address_space {
78954 spinlock_t private_lock; /* for use by the address_space */
78955 struct list_head private_list; /* ditto */
78956 void *private_data; /* ditto */
78957-} __attribute__((aligned(sizeof(long))));
78958+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78959 /*
78960 * On most architectures that alignment is already the case; but
78961 * must be enforced here for CRIS, to let the least significant bit
78962@@ -441,7 +441,7 @@ struct block_device {
78963 int bd_fsfreeze_count;
78964 /* Mutex for freeze */
78965 struct mutex bd_fsfreeze_mutex;
78966-};
78967+} __randomize_layout;
78968
78969 /*
78970 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78971@@ -585,7 +585,7 @@ struct inode {
78972 #endif
78973
78974 void *i_private; /* fs or device private pointer */
78975-};
78976+} __randomize_layout;
78977
78978 static inline int inode_unhashed(struct inode *inode)
78979 {
78980@@ -778,7 +778,7 @@ struct file {
78981 struct list_head f_tfile_llink;
78982 #endif /* #ifdef CONFIG_EPOLL */
78983 struct address_space *f_mapping;
78984-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78985+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78986
78987 struct file_handle {
78988 __u32 handle_bytes;
78989@@ -906,7 +906,7 @@ struct file_lock {
78990 int state; /* state of grant or error if -ve */
78991 } afs;
78992 } fl_u;
78993-};
78994+} __randomize_layout;
78995
78996 /* The following constant reflects the upper bound of the file/locking space */
78997 #ifndef OFFSET_MAX
78998@@ -1255,7 +1255,7 @@ struct super_block {
78999 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
79000 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
79001 struct rcu_head rcu;
79002-};
79003+} __randomize_layout;
79004
79005 extern struct timespec current_fs_time(struct super_block *sb);
79006
79007@@ -1477,7 +1477,8 @@ struct file_operations {
79008 long (*fallocate)(struct file *file, int mode, loff_t offset,
79009 loff_t len);
79010 int (*show_fdinfo)(struct seq_file *m, struct file *f);
79011-};
79012+} __do_const __randomize_layout;
79013+typedef struct file_operations __no_const file_operations_no_const;
79014
79015 struct inode_operations {
79016 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
79017@@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
79018 return !IS_DEADDIR(inode);
79019 }
79020
79021+static inline bool is_sidechannel_device(const struct inode *inode)
79022+{
79023+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
79024+ umode_t mode = inode->i_mode;
79025+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
79026+#else
79027+ return false;
79028+#endif
79029+}
79030+
79031 #endif /* _LINUX_FS_H */
79032diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
79033index 0efc3e6..fd23610 100644
79034--- a/include/linux/fs_struct.h
79035+++ b/include/linux/fs_struct.h
79036@@ -6,13 +6,13 @@
79037 #include <linux/seqlock.h>
79038
79039 struct fs_struct {
79040- int users;
79041+ atomic_t users;
79042 spinlock_t lock;
79043 seqcount_t seq;
79044 int umask;
79045 int in_exec;
79046 struct path root, pwd;
79047-};
79048+} __randomize_layout;
79049
79050 extern struct kmem_cache *fs_cachep;
79051
79052diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
79053index 7714849..a4a5c7a 100644
79054--- a/include/linux/fscache-cache.h
79055+++ b/include/linux/fscache-cache.h
79056@@ -113,7 +113,7 @@ struct fscache_operation {
79057 fscache_operation_release_t release;
79058 };
79059
79060-extern atomic_t fscache_op_debug_id;
79061+extern atomic_unchecked_t fscache_op_debug_id;
79062 extern void fscache_op_work_func(struct work_struct *work);
79063
79064 extern void fscache_enqueue_operation(struct fscache_operation *);
79065@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
79066 INIT_WORK(&op->work, fscache_op_work_func);
79067 atomic_set(&op->usage, 1);
79068 op->state = FSCACHE_OP_ST_INITIALISED;
79069- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
79070+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
79071 op->processor = processor;
79072 op->release = release;
79073 INIT_LIST_HEAD(&op->pend_link);
79074diff --git a/include/linux/fscache.h b/include/linux/fscache.h
79075index 115bb81..e7b812b 100644
79076--- a/include/linux/fscache.h
79077+++ b/include/linux/fscache.h
79078@@ -152,7 +152,7 @@ struct fscache_cookie_def {
79079 * - this is mandatory for any object that may have data
79080 */
79081 void (*now_uncached)(void *cookie_netfs_data);
79082-};
79083+} __do_const;
79084
79085 /*
79086 * fscache cached network filesystem type
79087diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
79088index 1c804b0..1432c2b 100644
79089--- a/include/linux/fsnotify.h
79090+++ b/include/linux/fsnotify.h
79091@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
79092 struct inode *inode = file_inode(file);
79093 __u32 mask = FS_ACCESS;
79094
79095+ if (is_sidechannel_device(inode))
79096+ return;
79097+
79098 if (S_ISDIR(inode->i_mode))
79099 mask |= FS_ISDIR;
79100
79101@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
79102 struct inode *inode = file_inode(file);
79103 __u32 mask = FS_MODIFY;
79104
79105+ if (is_sidechannel_device(inode))
79106+ return;
79107+
79108 if (S_ISDIR(inode->i_mode))
79109 mask |= FS_ISDIR;
79110
79111@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
79112 */
79113 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
79114 {
79115- return kstrdup(name, GFP_KERNEL);
79116+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
79117 }
79118
79119 /*
79120diff --git a/include/linux/genhd.h b/include/linux/genhd.h
79121index 9f3c275..8bdff5d 100644
79122--- a/include/linux/genhd.h
79123+++ b/include/linux/genhd.h
79124@@ -194,7 +194,7 @@ struct gendisk {
79125 struct kobject *slave_dir;
79126
79127 struct timer_rand_state *random;
79128- atomic_t sync_io; /* RAID */
79129+ atomic_unchecked_t sync_io; /* RAID */
79130 struct disk_events *ev;
79131 #ifdef CONFIG_BLK_DEV_INTEGRITY
79132 struct blk_integrity *integrity;
79133@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
79134 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
79135
79136 /* drivers/char/random.c */
79137-extern void add_disk_randomness(struct gendisk *disk);
79138+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
79139 extern void rand_initialize_disk(struct gendisk *disk);
79140
79141 static inline sector_t get_start_sect(struct block_device *bdev)
79142diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
79143index c0894dd..2fbf10c 100644
79144--- a/include/linux/genl_magic_func.h
79145+++ b/include/linux/genl_magic_func.h
79146@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
79147 },
79148
79149 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
79150-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
79151+static struct genl_ops ZZZ_genl_ops[] = {
79152 #include GENL_MAGIC_INCLUDE_FILE
79153 };
79154
79155diff --git a/include/linux/gfp.h b/include/linux/gfp.h
79156index 39b81dc..819dc51 100644
79157--- a/include/linux/gfp.h
79158+++ b/include/linux/gfp.h
79159@@ -36,6 +36,13 @@ struct vm_area_struct;
79160 #define ___GFP_NO_KSWAPD 0x400000u
79161 #define ___GFP_OTHER_NODE 0x800000u
79162 #define ___GFP_WRITE 0x1000000u
79163+
79164+#ifdef CONFIG_PAX_USERCOPY_SLABS
79165+#define ___GFP_USERCOPY 0x2000000u
79166+#else
79167+#define ___GFP_USERCOPY 0
79168+#endif
79169+
79170 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
79171
79172 /*
79173@@ -93,6 +100,7 @@ struct vm_area_struct;
79174 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
79175 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
79176 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
79177+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
79178
79179 /*
79180 * This may seem redundant, but it's a way of annotating false positives vs.
79181@@ -100,7 +108,7 @@ struct vm_area_struct;
79182 */
79183 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
79184
79185-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
79186+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
79187 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
79188
79189 /* This equals 0, but use constants in case they ever change */
79190@@ -158,6 +166,8 @@ struct vm_area_struct;
79191 /* 4GB DMA on some platforms */
79192 #define GFP_DMA32 __GFP_DMA32
79193
79194+#define GFP_USERCOPY __GFP_USERCOPY
79195+
79196 /* Convert GFP flags to their corresponding migrate type */
79197 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
79198 {
79199diff --git a/include/linux/gracl.h b/include/linux/gracl.h
79200new file mode 100644
79201index 0000000..edb2cb6
79202--- /dev/null
79203+++ b/include/linux/gracl.h
79204@@ -0,0 +1,340 @@
79205+#ifndef GR_ACL_H
79206+#define GR_ACL_H
79207+
79208+#include <linux/grdefs.h>
79209+#include <linux/resource.h>
79210+#include <linux/capability.h>
79211+#include <linux/dcache.h>
79212+#include <asm/resource.h>
79213+
79214+/* Major status information */
79215+
79216+#define GR_VERSION "grsecurity 3.0"
79217+#define GRSECURITY_VERSION 0x3000
79218+
79219+enum {
79220+ GR_SHUTDOWN = 0,
79221+ GR_ENABLE = 1,
79222+ GR_SPROLE = 2,
79223+ GR_OLDRELOAD = 3,
79224+ GR_SEGVMOD = 4,
79225+ GR_STATUS = 5,
79226+ GR_UNSPROLE = 6,
79227+ GR_PASSSET = 7,
79228+ GR_SPROLEPAM = 8,
79229+ GR_RELOAD = 9,
79230+};
79231+
79232+/* Password setup definitions
79233+ * kernel/grhash.c */
79234+enum {
79235+ GR_PW_LEN = 128,
79236+ GR_SALT_LEN = 16,
79237+ GR_SHA_LEN = 32,
79238+};
79239+
79240+enum {
79241+ GR_SPROLE_LEN = 64,
79242+};
79243+
79244+enum {
79245+ GR_NO_GLOB = 0,
79246+ GR_REG_GLOB,
79247+ GR_CREATE_GLOB
79248+};
79249+
79250+#define GR_NLIMITS 32
79251+
79252+/* Begin Data Structures */
79253+
79254+struct sprole_pw {
79255+ unsigned char *rolename;
79256+ unsigned char salt[GR_SALT_LEN];
79257+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
79258+};
79259+
79260+struct name_entry {
79261+ __u32 key;
79262+ ino_t inode;
79263+ dev_t device;
79264+ char *name;
79265+ __u16 len;
79266+ __u8 deleted;
79267+ struct name_entry *prev;
79268+ struct name_entry *next;
79269+};
79270+
79271+struct inodev_entry {
79272+ struct name_entry *nentry;
79273+ struct inodev_entry *prev;
79274+ struct inodev_entry *next;
79275+};
79276+
79277+struct acl_role_db {
79278+ struct acl_role_label **r_hash;
79279+ __u32 r_size;
79280+};
79281+
79282+struct inodev_db {
79283+ struct inodev_entry **i_hash;
79284+ __u32 i_size;
79285+};
79286+
79287+struct name_db {
79288+ struct name_entry **n_hash;
79289+ __u32 n_size;
79290+};
79291+
79292+struct crash_uid {
79293+ uid_t uid;
79294+ unsigned long expires;
79295+};
79296+
79297+struct gr_hash_struct {
79298+ void **table;
79299+ void **nametable;
79300+ void *first;
79301+ __u32 table_size;
79302+ __u32 used_size;
79303+ int type;
79304+};
79305+
79306+/* Userspace Grsecurity ACL data structures */
79307+
79308+struct acl_subject_label {
79309+ char *filename;
79310+ ino_t inode;
79311+ dev_t device;
79312+ __u32 mode;
79313+ kernel_cap_t cap_mask;
79314+ kernel_cap_t cap_lower;
79315+ kernel_cap_t cap_invert_audit;
79316+
79317+ struct rlimit res[GR_NLIMITS];
79318+ __u32 resmask;
79319+
79320+ __u8 user_trans_type;
79321+ __u8 group_trans_type;
79322+ uid_t *user_transitions;
79323+ gid_t *group_transitions;
79324+ __u16 user_trans_num;
79325+ __u16 group_trans_num;
79326+
79327+ __u32 sock_families[2];
79328+ __u32 ip_proto[8];
79329+ __u32 ip_type;
79330+ struct acl_ip_label **ips;
79331+ __u32 ip_num;
79332+ __u32 inaddr_any_override;
79333+
79334+ __u32 crashes;
79335+ unsigned long expires;
79336+
79337+ struct acl_subject_label *parent_subject;
79338+ struct gr_hash_struct *hash;
79339+ struct acl_subject_label *prev;
79340+ struct acl_subject_label *next;
79341+
79342+ struct acl_object_label **obj_hash;
79343+ __u32 obj_hash_size;
79344+ __u16 pax_flags;
79345+};
79346+
79347+struct role_allowed_ip {
79348+ __u32 addr;
79349+ __u32 netmask;
79350+
79351+ struct role_allowed_ip *prev;
79352+ struct role_allowed_ip *next;
79353+};
79354+
79355+struct role_transition {
79356+ char *rolename;
79357+
79358+ struct role_transition *prev;
79359+ struct role_transition *next;
79360+};
79361+
79362+struct acl_role_label {
79363+ char *rolename;
79364+ uid_t uidgid;
79365+ __u16 roletype;
79366+
79367+ __u16 auth_attempts;
79368+ unsigned long expires;
79369+
79370+ struct acl_subject_label *root_label;
79371+ struct gr_hash_struct *hash;
79372+
79373+ struct acl_role_label *prev;
79374+ struct acl_role_label *next;
79375+
79376+ struct role_transition *transitions;
79377+ struct role_allowed_ip *allowed_ips;
79378+ uid_t *domain_children;
79379+ __u16 domain_child_num;
79380+
79381+ umode_t umask;
79382+
79383+ struct acl_subject_label **subj_hash;
79384+ __u32 subj_hash_size;
79385+};
79386+
79387+struct user_acl_role_db {
79388+ struct acl_role_label **r_table;
79389+ __u32 num_pointers; /* Number of allocations to track */
79390+ __u32 num_roles; /* Number of roles */
79391+ __u32 num_domain_children; /* Number of domain children */
79392+ __u32 num_subjects; /* Number of subjects */
79393+ __u32 num_objects; /* Number of objects */
79394+};
79395+
79396+struct acl_object_label {
79397+ char *filename;
79398+ ino_t inode;
79399+ dev_t device;
79400+ __u32 mode;
79401+
79402+ struct acl_subject_label *nested;
79403+ struct acl_object_label *globbed;
79404+
79405+ /* next two structures not used */
79406+
79407+ struct acl_object_label *prev;
79408+ struct acl_object_label *next;
79409+};
79410+
79411+struct acl_ip_label {
79412+ char *iface;
79413+ __u32 addr;
79414+ __u32 netmask;
79415+ __u16 low, high;
79416+ __u8 mode;
79417+ __u32 type;
79418+ __u32 proto[8];
79419+
79420+ /* next two structures not used */
79421+
79422+ struct acl_ip_label *prev;
79423+ struct acl_ip_label *next;
79424+};
79425+
79426+struct gr_arg {
79427+ struct user_acl_role_db role_db;
79428+ unsigned char pw[GR_PW_LEN];
79429+ unsigned char salt[GR_SALT_LEN];
79430+ unsigned char sum[GR_SHA_LEN];
79431+ unsigned char sp_role[GR_SPROLE_LEN];
79432+ struct sprole_pw *sprole_pws;
79433+ dev_t segv_device;
79434+ ino_t segv_inode;
79435+ uid_t segv_uid;
79436+ __u16 num_sprole_pws;
79437+ __u16 mode;
79438+};
79439+
79440+struct gr_arg_wrapper {
79441+ struct gr_arg *arg;
79442+ __u32 version;
79443+ __u32 size;
79444+};
79445+
79446+struct subject_map {
79447+ struct acl_subject_label *user;
79448+ struct acl_subject_label *kernel;
79449+ struct subject_map *prev;
79450+ struct subject_map *next;
79451+};
79452+
79453+struct acl_subj_map_db {
79454+ struct subject_map **s_hash;
79455+ __u32 s_size;
79456+};
79457+
79458+struct gr_policy_state {
79459+ struct sprole_pw **acl_special_roles;
79460+ __u16 num_sprole_pws;
79461+ struct acl_role_label *kernel_role;
79462+ struct acl_role_label *role_list;
79463+ struct acl_role_label *default_role;
79464+ struct acl_role_db acl_role_set;
79465+ struct acl_subj_map_db subj_map_set;
79466+ struct name_db name_set;
79467+ struct inodev_db inodev_set;
79468+};
79469+
79470+struct gr_alloc_state {
79471+ unsigned long alloc_stack_next;
79472+ unsigned long alloc_stack_size;
79473+ void **alloc_stack;
79474+};
79475+
79476+struct gr_reload_state {
79477+ struct gr_policy_state oldpolicy;
79478+ struct gr_alloc_state oldalloc;
79479+ struct gr_policy_state newpolicy;
79480+ struct gr_alloc_state newalloc;
79481+ struct gr_policy_state *oldpolicy_ptr;
79482+ struct gr_alloc_state *oldalloc_ptr;
79483+ unsigned char oldmode;
79484+};
79485+
79486+/* End Data Structures Section */
79487+
79488+/* Hash functions generated by empirical testing by Brad Spengler
79489+ Makes good use of the low bits of the inode. Generally 0-1 times
79490+ in loop for successful match. 0-3 for unsuccessful match.
79491+ Shift/add algorithm with modulus of table size and an XOR*/
79492+
79493+static __inline__ unsigned int
79494+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79495+{
79496+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
79497+}
79498+
79499+ static __inline__ unsigned int
79500+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79501+{
79502+ return ((const unsigned long)userp % sz);
79503+}
79504+
79505+static __inline__ unsigned int
79506+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79507+{
79508+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79509+}
79510+
79511+static __inline__ unsigned int
79512+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79513+{
79514+ return full_name_hash((const unsigned char *)name, len) % sz;
79515+}
79516+
79517+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79518+ subj = NULL; \
79519+ iter = 0; \
79520+ while (iter < role->subj_hash_size) { \
79521+ if (subj == NULL) \
79522+ subj = role->subj_hash[iter]; \
79523+ if (subj == NULL) { \
79524+ iter++; \
79525+ continue; \
79526+ }
79527+
79528+#define FOR_EACH_SUBJECT_END(subj,iter) \
79529+ subj = subj->next; \
79530+ if (subj == NULL) \
79531+ iter++; \
79532+ }
79533+
79534+
79535+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79536+ subj = role->hash->first; \
79537+ while (subj != NULL) {
79538+
79539+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79540+ subj = subj->next; \
79541+ }
79542+
79543+#endif
79544+
79545diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79546new file mode 100644
79547index 0000000..33ebd1f
79548--- /dev/null
79549+++ b/include/linux/gracl_compat.h
79550@@ -0,0 +1,156 @@
79551+#ifndef GR_ACL_COMPAT_H
79552+#define GR_ACL_COMPAT_H
79553+
79554+#include <linux/resource.h>
79555+#include <asm/resource.h>
79556+
79557+struct sprole_pw_compat {
79558+ compat_uptr_t rolename;
79559+ unsigned char salt[GR_SALT_LEN];
79560+ unsigned char sum[GR_SHA_LEN];
79561+};
79562+
79563+struct gr_hash_struct_compat {
79564+ compat_uptr_t table;
79565+ compat_uptr_t nametable;
79566+ compat_uptr_t first;
79567+ __u32 table_size;
79568+ __u32 used_size;
79569+ int type;
79570+};
79571+
79572+struct acl_subject_label_compat {
79573+ compat_uptr_t filename;
79574+ compat_ino_t inode;
79575+ __u32 device;
79576+ __u32 mode;
79577+ kernel_cap_t cap_mask;
79578+ kernel_cap_t cap_lower;
79579+ kernel_cap_t cap_invert_audit;
79580+
79581+ struct compat_rlimit res[GR_NLIMITS];
79582+ __u32 resmask;
79583+
79584+ __u8 user_trans_type;
79585+ __u8 group_trans_type;
79586+ compat_uptr_t user_transitions;
79587+ compat_uptr_t group_transitions;
79588+ __u16 user_trans_num;
79589+ __u16 group_trans_num;
79590+
79591+ __u32 sock_families[2];
79592+ __u32 ip_proto[8];
79593+ __u32 ip_type;
79594+ compat_uptr_t ips;
79595+ __u32 ip_num;
79596+ __u32 inaddr_any_override;
79597+
79598+ __u32 crashes;
79599+ compat_ulong_t expires;
79600+
79601+ compat_uptr_t parent_subject;
79602+ compat_uptr_t hash;
79603+ compat_uptr_t prev;
79604+ compat_uptr_t next;
79605+
79606+ compat_uptr_t obj_hash;
79607+ __u32 obj_hash_size;
79608+ __u16 pax_flags;
79609+};
79610+
79611+struct role_allowed_ip_compat {
79612+ __u32 addr;
79613+ __u32 netmask;
79614+
79615+ compat_uptr_t prev;
79616+ compat_uptr_t next;
79617+};
79618+
79619+struct role_transition_compat {
79620+ compat_uptr_t rolename;
79621+
79622+ compat_uptr_t prev;
79623+ compat_uptr_t next;
79624+};
79625+
79626+struct acl_role_label_compat {
79627+ compat_uptr_t rolename;
79628+ uid_t uidgid;
79629+ __u16 roletype;
79630+
79631+ __u16 auth_attempts;
79632+ compat_ulong_t expires;
79633+
79634+ compat_uptr_t root_label;
79635+ compat_uptr_t hash;
79636+
79637+ compat_uptr_t prev;
79638+ compat_uptr_t next;
79639+
79640+ compat_uptr_t transitions;
79641+ compat_uptr_t allowed_ips;
79642+ compat_uptr_t domain_children;
79643+ __u16 domain_child_num;
79644+
79645+ umode_t umask;
79646+
79647+ compat_uptr_t subj_hash;
79648+ __u32 subj_hash_size;
79649+};
79650+
79651+struct user_acl_role_db_compat {
79652+ compat_uptr_t r_table;
79653+ __u32 num_pointers;
79654+ __u32 num_roles;
79655+ __u32 num_domain_children;
79656+ __u32 num_subjects;
79657+ __u32 num_objects;
79658+};
79659+
79660+struct acl_object_label_compat {
79661+ compat_uptr_t filename;
79662+ compat_ino_t inode;
79663+ __u32 device;
79664+ __u32 mode;
79665+
79666+ compat_uptr_t nested;
79667+ compat_uptr_t globbed;
79668+
79669+ compat_uptr_t prev;
79670+ compat_uptr_t next;
79671+};
79672+
79673+struct acl_ip_label_compat {
79674+ compat_uptr_t iface;
79675+ __u32 addr;
79676+ __u32 netmask;
79677+ __u16 low, high;
79678+ __u8 mode;
79679+ __u32 type;
79680+ __u32 proto[8];
79681+
79682+ compat_uptr_t prev;
79683+ compat_uptr_t next;
79684+};
79685+
79686+struct gr_arg_compat {
79687+ struct user_acl_role_db_compat role_db;
79688+ unsigned char pw[GR_PW_LEN];
79689+ unsigned char salt[GR_SALT_LEN];
79690+ unsigned char sum[GR_SHA_LEN];
79691+ unsigned char sp_role[GR_SPROLE_LEN];
79692+ compat_uptr_t sprole_pws;
79693+ __u32 segv_device;
79694+ compat_ino_t segv_inode;
79695+ uid_t segv_uid;
79696+ __u16 num_sprole_pws;
79697+ __u16 mode;
79698+};
79699+
79700+struct gr_arg_wrapper_compat {
79701+ compat_uptr_t arg;
79702+ __u32 version;
79703+ __u32 size;
79704+};
79705+
79706+#endif
79707diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79708new file mode 100644
79709index 0000000..323ecf2
79710--- /dev/null
79711+++ b/include/linux/gralloc.h
79712@@ -0,0 +1,9 @@
79713+#ifndef __GRALLOC_H
79714+#define __GRALLOC_H
79715+
79716+void acl_free_all(void);
79717+int acl_alloc_stack_init(unsigned long size);
79718+void *acl_alloc(unsigned long len);
79719+void *acl_alloc_num(unsigned long num, unsigned long len);
79720+
79721+#endif
79722diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79723new file mode 100644
79724index 0000000..be66033
79725--- /dev/null
79726+++ b/include/linux/grdefs.h
79727@@ -0,0 +1,140 @@
79728+#ifndef GRDEFS_H
79729+#define GRDEFS_H
79730+
79731+/* Begin grsecurity status declarations */
79732+
79733+enum {
79734+ GR_READY = 0x01,
79735+ GR_STATUS_INIT = 0x00 // disabled state
79736+};
79737+
79738+/* Begin ACL declarations */
79739+
79740+/* Role flags */
79741+
79742+enum {
79743+ GR_ROLE_USER = 0x0001,
79744+ GR_ROLE_GROUP = 0x0002,
79745+ GR_ROLE_DEFAULT = 0x0004,
79746+ GR_ROLE_SPECIAL = 0x0008,
79747+ GR_ROLE_AUTH = 0x0010,
79748+ GR_ROLE_NOPW = 0x0020,
79749+ GR_ROLE_GOD = 0x0040,
79750+ GR_ROLE_LEARN = 0x0080,
79751+ GR_ROLE_TPE = 0x0100,
79752+ GR_ROLE_DOMAIN = 0x0200,
79753+ GR_ROLE_PAM = 0x0400,
79754+ GR_ROLE_PERSIST = 0x0800
79755+};
79756+
79757+/* ACL Subject and Object mode flags */
79758+enum {
79759+ GR_DELETED = 0x80000000
79760+};
79761+
79762+/* ACL Object-only mode flags */
79763+enum {
79764+ GR_READ = 0x00000001,
79765+ GR_APPEND = 0x00000002,
79766+ GR_WRITE = 0x00000004,
79767+ GR_EXEC = 0x00000008,
79768+ GR_FIND = 0x00000010,
79769+ GR_INHERIT = 0x00000020,
79770+ GR_SETID = 0x00000040,
79771+ GR_CREATE = 0x00000080,
79772+ GR_DELETE = 0x00000100,
79773+ GR_LINK = 0x00000200,
79774+ GR_AUDIT_READ = 0x00000400,
79775+ GR_AUDIT_APPEND = 0x00000800,
79776+ GR_AUDIT_WRITE = 0x00001000,
79777+ GR_AUDIT_EXEC = 0x00002000,
79778+ GR_AUDIT_FIND = 0x00004000,
79779+ GR_AUDIT_INHERIT= 0x00008000,
79780+ GR_AUDIT_SETID = 0x00010000,
79781+ GR_AUDIT_CREATE = 0x00020000,
79782+ GR_AUDIT_DELETE = 0x00040000,
79783+ GR_AUDIT_LINK = 0x00080000,
79784+ GR_PTRACERD = 0x00100000,
79785+ GR_NOPTRACE = 0x00200000,
79786+ GR_SUPPRESS = 0x00400000,
79787+ GR_NOLEARN = 0x00800000,
79788+ GR_INIT_TRANSFER= 0x01000000
79789+};
79790+
79791+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79792+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79793+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79794+
79795+/* ACL subject-only mode flags */
79796+enum {
79797+ GR_KILL = 0x00000001,
79798+ GR_VIEW = 0x00000002,
79799+ GR_PROTECTED = 0x00000004,
79800+ GR_LEARN = 0x00000008,
79801+ GR_OVERRIDE = 0x00000010,
79802+ /* just a placeholder, this mode is only used in userspace */
79803+ GR_DUMMY = 0x00000020,
79804+ GR_PROTSHM = 0x00000040,
79805+ GR_KILLPROC = 0x00000080,
79806+ GR_KILLIPPROC = 0x00000100,
79807+ /* just a placeholder, this mode is only used in userspace */
79808+ GR_NOTROJAN = 0x00000200,
79809+ GR_PROTPROCFD = 0x00000400,
79810+ GR_PROCACCT = 0x00000800,
79811+ GR_RELAXPTRACE = 0x00001000,
79812+ //GR_NESTED = 0x00002000,
79813+ GR_INHERITLEARN = 0x00004000,
79814+ GR_PROCFIND = 0x00008000,
79815+ GR_POVERRIDE = 0x00010000,
79816+ GR_KERNELAUTH = 0x00020000,
79817+ GR_ATSECURE = 0x00040000,
79818+ GR_SHMEXEC = 0x00080000
79819+};
79820+
79821+enum {
79822+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79823+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79824+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79825+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79826+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79827+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79828+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79829+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79830+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79831+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79832+};
79833+
79834+enum {
79835+ GR_ID_USER = 0x01,
79836+ GR_ID_GROUP = 0x02,
79837+};
79838+
79839+enum {
79840+ GR_ID_ALLOW = 0x01,
79841+ GR_ID_DENY = 0x02,
79842+};
79843+
79844+#define GR_CRASH_RES 31
79845+#define GR_UIDTABLE_MAX 500
79846+
79847+/* begin resource learning section */
79848+enum {
79849+ GR_RLIM_CPU_BUMP = 60,
79850+ GR_RLIM_FSIZE_BUMP = 50000,
79851+ GR_RLIM_DATA_BUMP = 10000,
79852+ GR_RLIM_STACK_BUMP = 1000,
79853+ GR_RLIM_CORE_BUMP = 10000,
79854+ GR_RLIM_RSS_BUMP = 500000,
79855+ GR_RLIM_NPROC_BUMP = 1,
79856+ GR_RLIM_NOFILE_BUMP = 5,
79857+ GR_RLIM_MEMLOCK_BUMP = 50000,
79858+ GR_RLIM_AS_BUMP = 500000,
79859+ GR_RLIM_LOCKS_BUMP = 2,
79860+ GR_RLIM_SIGPENDING_BUMP = 5,
79861+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79862+ GR_RLIM_NICE_BUMP = 1,
79863+ GR_RLIM_RTPRIO_BUMP = 1,
79864+ GR_RLIM_RTTIME_BUMP = 1000000
79865+};
79866+
79867+#endif
79868diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79869new file mode 100644
79870index 0000000..d25522e
79871--- /dev/null
79872+++ b/include/linux/grinternal.h
79873@@ -0,0 +1,229 @@
79874+#ifndef __GRINTERNAL_H
79875+#define __GRINTERNAL_H
79876+
79877+#ifdef CONFIG_GRKERNSEC
79878+
79879+#include <linux/fs.h>
79880+#include <linux/mnt_namespace.h>
79881+#include <linux/nsproxy.h>
79882+#include <linux/gracl.h>
79883+#include <linux/grdefs.h>
79884+#include <linux/grmsg.h>
79885+
79886+void gr_add_learn_entry(const char *fmt, ...)
79887+ __attribute__ ((format (printf, 1, 2)));
79888+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79889+ const struct vfsmount *mnt);
79890+__u32 gr_check_create(const struct dentry *new_dentry,
79891+ const struct dentry *parent,
79892+ const struct vfsmount *mnt, const __u32 mode);
79893+int gr_check_protected_task(const struct task_struct *task);
79894+__u32 to_gr_audit(const __u32 reqmode);
79895+int gr_set_acls(const int type);
79896+int gr_acl_is_enabled(void);
79897+char gr_roletype_to_char(void);
79898+
79899+void gr_handle_alertkill(struct task_struct *task);
79900+char *gr_to_filename(const struct dentry *dentry,
79901+ const struct vfsmount *mnt);
79902+char *gr_to_filename1(const struct dentry *dentry,
79903+ const struct vfsmount *mnt);
79904+char *gr_to_filename2(const struct dentry *dentry,
79905+ const struct vfsmount *mnt);
79906+char *gr_to_filename3(const struct dentry *dentry,
79907+ const struct vfsmount *mnt);
79908+
79909+extern int grsec_enable_ptrace_readexec;
79910+extern int grsec_enable_harden_ptrace;
79911+extern int grsec_enable_link;
79912+extern int grsec_enable_fifo;
79913+extern int grsec_enable_execve;
79914+extern int grsec_enable_shm;
79915+extern int grsec_enable_execlog;
79916+extern int grsec_enable_signal;
79917+extern int grsec_enable_audit_ptrace;
79918+extern int grsec_enable_forkfail;
79919+extern int grsec_enable_time;
79920+extern int grsec_enable_rofs;
79921+extern int grsec_deny_new_usb;
79922+extern int grsec_enable_chroot_shmat;
79923+extern int grsec_enable_chroot_mount;
79924+extern int grsec_enable_chroot_double;
79925+extern int grsec_enable_chroot_pivot;
79926+extern int grsec_enable_chroot_chdir;
79927+extern int grsec_enable_chroot_chmod;
79928+extern int grsec_enable_chroot_mknod;
79929+extern int grsec_enable_chroot_fchdir;
79930+extern int grsec_enable_chroot_nice;
79931+extern int grsec_enable_chroot_execlog;
79932+extern int grsec_enable_chroot_caps;
79933+extern int grsec_enable_chroot_sysctl;
79934+extern int grsec_enable_chroot_unix;
79935+extern int grsec_enable_symlinkown;
79936+extern kgid_t grsec_symlinkown_gid;
79937+extern int grsec_enable_tpe;
79938+extern kgid_t grsec_tpe_gid;
79939+extern int grsec_enable_tpe_all;
79940+extern int grsec_enable_tpe_invert;
79941+extern int grsec_enable_socket_all;
79942+extern kgid_t grsec_socket_all_gid;
79943+extern int grsec_enable_socket_client;
79944+extern kgid_t grsec_socket_client_gid;
79945+extern int grsec_enable_socket_server;
79946+extern kgid_t grsec_socket_server_gid;
79947+extern kgid_t grsec_audit_gid;
79948+extern int grsec_enable_group;
79949+extern int grsec_enable_log_rwxmaps;
79950+extern int grsec_enable_mount;
79951+extern int grsec_enable_chdir;
79952+extern int grsec_resource_logging;
79953+extern int grsec_enable_blackhole;
79954+extern int grsec_lastack_retries;
79955+extern int grsec_enable_brute;
79956+extern int grsec_enable_harden_ipc;
79957+extern int grsec_lock;
79958+
79959+extern spinlock_t grsec_alert_lock;
79960+extern unsigned long grsec_alert_wtime;
79961+extern unsigned long grsec_alert_fyet;
79962+
79963+extern spinlock_t grsec_audit_lock;
79964+
79965+extern rwlock_t grsec_exec_file_lock;
79966+
79967+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79968+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79969+ (tsk)->exec_file->f_path.mnt) : "/")
79970+
79971+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79972+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79973+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79974+
79975+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79976+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79977+ (tsk)->exec_file->f_path.mnt) : "/")
79978+
79979+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79980+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79981+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79982+
79983+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79984+
79985+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79986+
79987+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79988+{
79989+ if (file1 && file2) {
79990+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79991+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79992+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79993+ return true;
79994+ }
79995+
79996+ return false;
79997+}
79998+
79999+#define GR_CHROOT_CAPS {{ \
80000+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
80001+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
80002+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
80003+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
80004+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
80005+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
80006+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
80007+
80008+#define security_learn(normal_msg,args...) \
80009+({ \
80010+ read_lock(&grsec_exec_file_lock); \
80011+ gr_add_learn_entry(normal_msg "\n", ## args); \
80012+ read_unlock(&grsec_exec_file_lock); \
80013+})
80014+
80015+enum {
80016+ GR_DO_AUDIT,
80017+ GR_DONT_AUDIT,
80018+ /* used for non-audit messages that we shouldn't kill the task on */
80019+ GR_DONT_AUDIT_GOOD
80020+};
80021+
80022+enum {
80023+ GR_TTYSNIFF,
80024+ GR_RBAC,
80025+ GR_RBAC_STR,
80026+ GR_STR_RBAC,
80027+ GR_RBAC_MODE2,
80028+ GR_RBAC_MODE3,
80029+ GR_FILENAME,
80030+ GR_SYSCTL_HIDDEN,
80031+ GR_NOARGS,
80032+ GR_ONE_INT,
80033+ GR_ONE_INT_TWO_STR,
80034+ GR_ONE_STR,
80035+ GR_STR_INT,
80036+ GR_TWO_STR_INT,
80037+ GR_TWO_INT,
80038+ GR_TWO_U64,
80039+ GR_THREE_INT,
80040+ GR_FIVE_INT_TWO_STR,
80041+ GR_TWO_STR,
80042+ GR_THREE_STR,
80043+ GR_FOUR_STR,
80044+ GR_STR_FILENAME,
80045+ GR_FILENAME_STR,
80046+ GR_FILENAME_TWO_INT,
80047+ GR_FILENAME_TWO_INT_STR,
80048+ GR_TEXTREL,
80049+ GR_PTRACE,
80050+ GR_RESOURCE,
80051+ GR_CAP,
80052+ GR_SIG,
80053+ GR_SIG2,
80054+ GR_CRASH1,
80055+ GR_CRASH2,
80056+ GR_PSACCT,
80057+ GR_RWXMAP,
80058+ GR_RWXMAPVMA
80059+};
80060+
80061+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
80062+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
80063+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
80064+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
80065+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
80066+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
80067+#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)
80068+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
80069+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
80070+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
80071+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
80072+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
80073+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
80074+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
80075+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
80076+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
80077+#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)
80078+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
80079+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
80080+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
80081+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
80082+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
80083+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
80084+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
80085+#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)
80086+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
80087+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
80088+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
80089+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
80090+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
80091+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
80092+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
80093+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
80094+#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)
80095+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
80096+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
80097+
80098+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
80099+
80100+#endif
80101+
80102+#endif
80103diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
80104new file mode 100644
80105index 0000000..b02ba9d
80106--- /dev/null
80107+++ b/include/linux/grmsg.h
80108@@ -0,0 +1,117 @@
80109+#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"
80110+#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"
80111+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
80112+#define GR_STOPMOD_MSG "denied modification of module state by "
80113+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
80114+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
80115+#define GR_IOPERM_MSG "denied use of ioperm() by "
80116+#define GR_IOPL_MSG "denied use of iopl() by "
80117+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
80118+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
80119+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
80120+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
80121+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
80122+#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"
80123+#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"
80124+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
80125+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
80126+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
80127+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
80128+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
80129+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
80130+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
80131+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
80132+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
80133+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
80134+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
80135+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
80136+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
80137+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
80138+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
80139+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
80140+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
80141+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
80142+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
80143+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
80144+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
80145+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
80146+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
80147+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
80148+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
80149+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
80150+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
80151+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
80152+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
80153+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
80154+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
80155+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
80156+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
80157+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
80158+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
80159+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
80160+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
80161+#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"
80162+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
80163+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
80164+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
80165+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
80166+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
80167+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
80168+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
80169+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
80170+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
80171+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
80172+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
80173+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
80174+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
80175+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
80176+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
80177+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
80178+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
80179+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
80180+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
80181+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
80182+#define GR_FAILFORK_MSG "failed fork with errno %s by "
80183+#define GR_NICE_CHROOT_MSG "denied priority change by "
80184+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
80185+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
80186+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
80187+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
80188+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
80189+#define GR_TIME_MSG "time set by "
80190+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
80191+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
80192+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
80193+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
80194+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
80195+#define GR_BIND_MSG "denied bind() by "
80196+#define GR_CONNECT_MSG "denied connect() by "
80197+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
80198+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
80199+#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"
80200+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
80201+#define GR_CAP_ACL_MSG "use of %s denied for "
80202+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
80203+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
80204+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
80205+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
80206+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
80207+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
80208+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
80209+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
80210+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
80211+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
80212+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
80213+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
80214+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
80215+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
80216+#define GR_VM86_MSG "denied use of vm86 by "
80217+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
80218+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
80219+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
80220+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
80221+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
80222+#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 "
80223+#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 "
80224+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
80225+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
80226diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
80227new file mode 100644
80228index 0000000..e6d120f
80229--- /dev/null
80230+++ b/include/linux/grsecurity.h
80231@@ -0,0 +1,252 @@
80232+#ifndef GR_SECURITY_H
80233+#define GR_SECURITY_H
80234+#include <linux/fs.h>
80235+#include <linux/fs_struct.h>
80236+#include <linux/binfmts.h>
80237+#include <linux/gracl.h>
80238+
80239+/* notify of brain-dead configs */
80240+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80241+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
80242+#endif
80243+#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80244+#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
80245+#endif
80246+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
80247+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
80248+#endif
80249+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
80250+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
80251+#endif
80252+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
80253+#error "CONFIG_PAX enabled, but no PaX options are enabled."
80254+#endif
80255+
80256+int gr_handle_new_usb(void);
80257+
80258+void gr_handle_brute_attach(int dumpable);
80259+void gr_handle_brute_check(void);
80260+void gr_handle_kernel_exploit(void);
80261+
80262+char gr_roletype_to_char(void);
80263+
80264+int gr_proc_is_restricted(void);
80265+
80266+int gr_acl_enable_at_secure(void);
80267+
80268+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
80269+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
80270+
80271+void gr_del_task_from_ip_table(struct task_struct *p);
80272+
80273+int gr_pid_is_chrooted(struct task_struct *p);
80274+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
80275+int gr_handle_chroot_nice(void);
80276+int gr_handle_chroot_sysctl(const int op);
80277+int gr_handle_chroot_setpriority(struct task_struct *p,
80278+ const int niceval);
80279+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
80280+int gr_chroot_fhandle(void);
80281+int gr_handle_chroot_chroot(const struct dentry *dentry,
80282+ const struct vfsmount *mnt);
80283+void gr_handle_chroot_chdir(const struct path *path);
80284+int gr_handle_chroot_chmod(const struct dentry *dentry,
80285+ const struct vfsmount *mnt, const int mode);
80286+int gr_handle_chroot_mknod(const struct dentry *dentry,
80287+ const struct vfsmount *mnt, const int mode);
80288+int gr_handle_chroot_mount(const struct dentry *dentry,
80289+ const struct vfsmount *mnt,
80290+ const char *dev_name);
80291+int gr_handle_chroot_pivot(void);
80292+int gr_handle_chroot_unix(const pid_t pid);
80293+
80294+int gr_handle_rawio(const struct inode *inode);
80295+
80296+void gr_handle_ioperm(void);
80297+void gr_handle_iopl(void);
80298+void gr_handle_msr_write(void);
80299+
80300+umode_t gr_acl_umask(void);
80301+
80302+int gr_tpe_allow(const struct file *file);
80303+
80304+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
80305+void gr_clear_chroot_entries(struct task_struct *task);
80306+
80307+void gr_log_forkfail(const int retval);
80308+void gr_log_timechange(void);
80309+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
80310+void gr_log_chdir(const struct dentry *dentry,
80311+ const struct vfsmount *mnt);
80312+void gr_log_chroot_exec(const struct dentry *dentry,
80313+ const struct vfsmount *mnt);
80314+void gr_log_remount(const char *devname, const int retval);
80315+void gr_log_unmount(const char *devname, const int retval);
80316+void gr_log_mount(const char *from, const char *to, const int retval);
80317+void gr_log_textrel(struct vm_area_struct *vma);
80318+void gr_log_ptgnustack(struct file *file);
80319+void gr_log_rwxmmap(struct file *file);
80320+void gr_log_rwxmprotect(struct vm_area_struct *vma);
80321+
80322+int gr_handle_follow_link(const struct inode *parent,
80323+ const struct inode *inode,
80324+ const struct dentry *dentry,
80325+ const struct vfsmount *mnt);
80326+int gr_handle_fifo(const struct dentry *dentry,
80327+ const struct vfsmount *mnt,
80328+ const struct dentry *dir, const int flag,
80329+ const int acc_mode);
80330+int gr_handle_hardlink(const struct dentry *dentry,
80331+ const struct vfsmount *mnt,
80332+ struct inode *inode,
80333+ const int mode, const struct filename *to);
80334+
80335+int gr_is_capable(const int cap);
80336+int gr_is_capable_nolog(const int cap);
80337+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
80338+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
80339+
80340+void gr_copy_label(struct task_struct *tsk);
80341+void gr_handle_crash(struct task_struct *task, const int sig);
80342+int gr_handle_signal(const struct task_struct *p, const int sig);
80343+int gr_check_crash_uid(const kuid_t uid);
80344+int gr_check_protected_task(const struct task_struct *task);
80345+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
80346+int gr_acl_handle_mmap(const struct file *file,
80347+ const unsigned long prot);
80348+int gr_acl_handle_mprotect(const struct file *file,
80349+ const unsigned long prot);
80350+int gr_check_hidden_task(const struct task_struct *tsk);
80351+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
80352+ const struct vfsmount *mnt);
80353+__u32 gr_acl_handle_utime(const struct dentry *dentry,
80354+ const struct vfsmount *mnt);
80355+__u32 gr_acl_handle_access(const struct dentry *dentry,
80356+ const struct vfsmount *mnt, const int fmode);
80357+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
80358+ const struct vfsmount *mnt, umode_t *mode);
80359+__u32 gr_acl_handle_chown(const struct dentry *dentry,
80360+ const struct vfsmount *mnt);
80361+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
80362+ const struct vfsmount *mnt);
80363+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
80364+ const struct vfsmount *mnt);
80365+int gr_handle_ptrace(struct task_struct *task, const long request);
80366+int gr_handle_proc_ptrace(struct task_struct *task);
80367+__u32 gr_acl_handle_execve(const struct dentry *dentry,
80368+ const struct vfsmount *mnt);
80369+int gr_check_crash_exec(const struct file *filp);
80370+int gr_acl_is_enabled(void);
80371+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
80372+ const kgid_t gid);
80373+int gr_set_proc_label(const struct dentry *dentry,
80374+ const struct vfsmount *mnt,
80375+ const int unsafe_flags);
80376+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
80377+ const struct vfsmount *mnt);
80378+__u32 gr_acl_handle_open(const struct dentry *dentry,
80379+ const struct vfsmount *mnt, int acc_mode);
80380+__u32 gr_acl_handle_creat(const struct dentry *dentry,
80381+ const struct dentry *p_dentry,
80382+ const struct vfsmount *p_mnt,
80383+ int open_flags, int acc_mode, const int imode);
80384+void gr_handle_create(const struct dentry *dentry,
80385+ const struct vfsmount *mnt);
80386+void gr_handle_proc_create(const struct dentry *dentry,
80387+ const struct inode *inode);
80388+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
80389+ const struct dentry *parent_dentry,
80390+ const struct vfsmount *parent_mnt,
80391+ const int mode);
80392+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
80393+ const struct dentry *parent_dentry,
80394+ const struct vfsmount *parent_mnt);
80395+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
80396+ const struct vfsmount *mnt);
80397+void gr_handle_delete(const ino_t ino, const dev_t dev);
80398+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
80399+ const struct vfsmount *mnt);
80400+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
80401+ const struct dentry *parent_dentry,
80402+ const struct vfsmount *parent_mnt,
80403+ const struct filename *from);
80404+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
80405+ const struct dentry *parent_dentry,
80406+ const struct vfsmount *parent_mnt,
80407+ const struct dentry *old_dentry,
80408+ const struct vfsmount *old_mnt, const struct filename *to);
80409+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
80410+int gr_acl_handle_rename(struct dentry *new_dentry,
80411+ struct dentry *parent_dentry,
80412+ const struct vfsmount *parent_mnt,
80413+ struct dentry *old_dentry,
80414+ struct inode *old_parent_inode,
80415+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
80416+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
80417+ struct dentry *old_dentry,
80418+ struct dentry *new_dentry,
80419+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
80420+__u32 gr_check_link(const struct dentry *new_dentry,
80421+ const struct dentry *parent_dentry,
80422+ const struct vfsmount *parent_mnt,
80423+ const struct dentry *old_dentry,
80424+ const struct vfsmount *old_mnt);
80425+int gr_acl_handle_filldir(const struct file *file, const char *name,
80426+ const unsigned int namelen, const ino_t ino);
80427+
80428+__u32 gr_acl_handle_unix(const struct dentry *dentry,
80429+ const struct vfsmount *mnt);
80430+void gr_acl_handle_exit(void);
80431+void gr_acl_handle_psacct(struct task_struct *task, const long code);
80432+int gr_acl_handle_procpidmem(const struct task_struct *task);
80433+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
80434+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
80435+void gr_audit_ptrace(struct task_struct *task);
80436+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
80437+void gr_put_exec_file(struct task_struct *task);
80438+
80439+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
80440+
80441+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
80442+extern void gr_learn_resource(const struct task_struct *task, const int res,
80443+ const unsigned long wanted, const int gt);
80444+#else
80445+static inline void gr_learn_resource(const struct task_struct *task, const int res,
80446+ const unsigned long wanted, const int gt)
80447+{
80448+}
80449+#endif
80450+
80451+#ifdef CONFIG_GRKERNSEC_RESLOG
80452+extern void gr_log_resource(const struct task_struct *task, const int res,
80453+ const unsigned long wanted, const int gt);
80454+#else
80455+static inline void gr_log_resource(const struct task_struct *task, const int res,
80456+ const unsigned long wanted, const int gt)
80457+{
80458+}
80459+#endif
80460+
80461+#ifdef CONFIG_GRKERNSEC
80462+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
80463+void gr_handle_vm86(void);
80464+void gr_handle_mem_readwrite(u64 from, u64 to);
80465+
80466+void gr_log_badprocpid(const char *entry);
80467+
80468+extern int grsec_enable_dmesg;
80469+extern int grsec_disable_privio;
80470+
80471+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80472+extern kgid_t grsec_proc_gid;
80473+#endif
80474+
80475+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80476+extern int grsec_enable_chroot_findtask;
80477+#endif
80478+#ifdef CONFIG_GRKERNSEC_SETXID
80479+extern int grsec_enable_setxid;
80480+#endif
80481+#endif
80482+
80483+#endif
80484diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80485new file mode 100644
80486index 0000000..e7ffaaf
80487--- /dev/null
80488+++ b/include/linux/grsock.h
80489@@ -0,0 +1,19 @@
80490+#ifndef __GRSOCK_H
80491+#define __GRSOCK_H
80492+
80493+extern void gr_attach_curr_ip(const struct sock *sk);
80494+extern int gr_handle_sock_all(const int family, const int type,
80495+ const int protocol);
80496+extern int gr_handle_sock_server(const struct sockaddr *sck);
80497+extern int gr_handle_sock_server_other(const struct sock *sck);
80498+extern int gr_handle_sock_client(const struct sockaddr *sck);
80499+extern int gr_search_connect(struct socket * sock,
80500+ struct sockaddr_in * addr);
80501+extern int gr_search_bind(struct socket * sock,
80502+ struct sockaddr_in * addr);
80503+extern int gr_search_listen(struct socket * sock);
80504+extern int gr_search_accept(struct socket * sock);
80505+extern int gr_search_socket(const int domain, const int type,
80506+ const int protocol);
80507+
80508+#endif
80509diff --git a/include/linux/hash.h b/include/linux/hash.h
80510index bd1754c..8240892 100644
80511--- a/include/linux/hash.h
80512+++ b/include/linux/hash.h
80513@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80514 struct fast_hash_ops {
80515 u32 (*hash)(const void *data, u32 len, u32 seed);
80516 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80517-};
80518+} __no_const;
80519
80520 /**
80521 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80522diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80523index 7fb31da..08b5114 100644
80524--- a/include/linux/highmem.h
80525+++ b/include/linux/highmem.h
80526@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80527 kunmap_atomic(kaddr);
80528 }
80529
80530+static inline void sanitize_highpage(struct page *page)
80531+{
80532+ void *kaddr;
80533+ unsigned long flags;
80534+
80535+ local_irq_save(flags);
80536+ kaddr = kmap_atomic(page);
80537+ clear_page(kaddr);
80538+ kunmap_atomic(kaddr);
80539+ local_irq_restore(flags);
80540+}
80541+
80542 static inline void zero_user_segments(struct page *page,
80543 unsigned start1, unsigned end1,
80544 unsigned start2, unsigned end2)
80545diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80546index 1c7b89a..7dda400 100644
80547--- a/include/linux/hwmon-sysfs.h
80548+++ b/include/linux/hwmon-sysfs.h
80549@@ -25,7 +25,8 @@
80550 struct sensor_device_attribute{
80551 struct device_attribute dev_attr;
80552 int index;
80553-};
80554+} __do_const;
80555+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80556 #define to_sensor_dev_attr(_dev_attr) \
80557 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80558
80559@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80560 struct device_attribute dev_attr;
80561 u8 index;
80562 u8 nr;
80563-};
80564+} __do_const;
80565+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80566 #define to_sensor_dev_attr_2(_dev_attr) \
80567 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80568
80569diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80570index b556e0a..c10a515 100644
80571--- a/include/linux/i2c.h
80572+++ b/include/linux/i2c.h
80573@@ -378,6 +378,7 @@ struct i2c_algorithm {
80574 /* To determine what the adapter supports */
80575 u32 (*functionality) (struct i2c_adapter *);
80576 };
80577+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80578
80579 /**
80580 * struct i2c_bus_recovery_info - I2C bus recovery information
80581diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80582index d23c3c2..eb63c81 100644
80583--- a/include/linux/i2o.h
80584+++ b/include/linux/i2o.h
80585@@ -565,7 +565,7 @@ struct i2o_controller {
80586 struct i2o_device *exec; /* Executive */
80587 #if BITS_PER_LONG == 64
80588 spinlock_t context_list_lock; /* lock for context_list */
80589- atomic_t context_list_counter; /* needed for unique contexts */
80590+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80591 struct list_head context_list; /* list of context id's
80592 and pointers */
80593 #endif
80594diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80595index aff7ad8..3942bbd 100644
80596--- a/include/linux/if_pppox.h
80597+++ b/include/linux/if_pppox.h
80598@@ -76,7 +76,7 @@ struct pppox_proto {
80599 int (*ioctl)(struct socket *sock, unsigned int cmd,
80600 unsigned long arg);
80601 struct module *owner;
80602-};
80603+} __do_const;
80604
80605 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80606 extern void unregister_pppox_proto(int proto_num);
80607diff --git a/include/linux/init.h b/include/linux/init.h
80608index a3ba270..a1b6604 100644
80609--- a/include/linux/init.h
80610+++ b/include/linux/init.h
80611@@ -37,9 +37,17 @@
80612 * section.
80613 */
80614
80615+#define add_init_latent_entropy __latent_entropy
80616+
80617+#ifdef CONFIG_MEMORY_HOTPLUG
80618+#define add_meminit_latent_entropy
80619+#else
80620+#define add_meminit_latent_entropy __latent_entropy
80621+#endif
80622+
80623 /* These are for everybody (although not all archs will actually
80624 discard it in modules) */
80625-#define __init __section(.init.text) __cold notrace
80626+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80627 #define __initdata __section(.init.data)
80628 #define __initconst __constsection(.init.rodata)
80629 #define __exitdata __section(.exit.data)
80630@@ -100,7 +108,7 @@
80631 #define __cpuexitconst
80632
80633 /* Used for MEMORY_HOTPLUG */
80634-#define __meminit __section(.meminit.text) __cold notrace
80635+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80636 #define __meminitdata __section(.meminit.data)
80637 #define __meminitconst __constsection(.meminit.rodata)
80638 #define __memexit __section(.memexit.text) __exitused __cold notrace
80639diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80640index 6df7f9f..d0bf699 100644
80641--- a/include/linux/init_task.h
80642+++ b/include/linux/init_task.h
80643@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80644
80645 #define INIT_TASK_COMM "swapper"
80646
80647+#ifdef CONFIG_X86
80648+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80649+#else
80650+#define INIT_TASK_THREAD_INFO
80651+#endif
80652+
80653 #ifdef CONFIG_RT_MUTEXES
80654 # define INIT_RT_MUTEXES(tsk) \
80655 .pi_waiters = RB_ROOT, \
80656@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80657 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80658 .comm = INIT_TASK_COMM, \
80659 .thread = INIT_THREAD, \
80660+ INIT_TASK_THREAD_INFO \
80661 .fs = &init_fs, \
80662 .files = &init_files, \
80663 .signal = &init_signals, \
80664diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80665index 051c850..431f83a 100644
80666--- a/include/linux/interrupt.h
80667+++ b/include/linux/interrupt.h
80668@@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80669
80670 struct softirq_action
80671 {
80672- void (*action)(struct softirq_action *);
80673-};
80674+ void (*action)(void);
80675+} __no_const;
80676
80677 asmlinkage void do_softirq(void);
80678 asmlinkage void __do_softirq(void);
80679@@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
80680 }
80681 #endif
80682
80683-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80684+extern void open_softirq(int nr, void (*action)(void));
80685 extern void softirq_init(void);
80686 extern void __raise_softirq_irqoff(unsigned int nr);
80687
80688diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80689index b96a5b2..2732d1c 100644
80690--- a/include/linux/iommu.h
80691+++ b/include/linux/iommu.h
80692@@ -131,7 +131,7 @@ struct iommu_ops {
80693 u32 (*domain_get_windows)(struct iommu_domain *domain);
80694
80695 unsigned long pgsize_bitmap;
80696-};
80697+} __do_const;
80698
80699 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80700 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80701diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80702index 5e3a906..3131d0f 100644
80703--- a/include/linux/ioport.h
80704+++ b/include/linux/ioport.h
80705@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80706 int adjust_resource(struct resource *res, resource_size_t start,
80707 resource_size_t size);
80708 resource_size_t resource_alignment(struct resource *res);
80709-static inline resource_size_t resource_size(const struct resource *res)
80710+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80711 {
80712 return res->end - res->start + 1;
80713 }
80714diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80715index 35e7eca..6afb7ad 100644
80716--- a/include/linux/ipc_namespace.h
80717+++ b/include/linux/ipc_namespace.h
80718@@ -69,7 +69,7 @@ struct ipc_namespace {
80719 struct user_namespace *user_ns;
80720
80721 unsigned int proc_inum;
80722-};
80723+} __randomize_layout;
80724
80725 extern struct ipc_namespace init_ipc_ns;
80726 extern atomic_t nr_ipc_ns;
80727diff --git a/include/linux/irq.h b/include/linux/irq.h
80728index 5c57efb..965a62b 100644
80729--- a/include/linux/irq.h
80730+++ b/include/linux/irq.h
80731@@ -344,7 +344,8 @@ struct irq_chip {
80732 void (*irq_release_resources)(struct irq_data *data);
80733
80734 unsigned long flags;
80735-};
80736+} __do_const;
80737+typedef struct irq_chip __no_const irq_chip_no_const;
80738
80739 /*
80740 * irq_chip specific flags
80741diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80742index 7ed92d0..589abf5 100644
80743--- a/include/linux/irqchip/arm-gic.h
80744+++ b/include/linux/irqchip/arm-gic.h
80745@@ -73,9 +73,11 @@
80746
80747 #ifndef __ASSEMBLY__
80748
80749+#include <linux/irq.h>
80750+
80751 struct device_node;
80752
80753-extern struct irq_chip gic_arch_extn;
80754+extern irq_chip_no_const gic_arch_extn;
80755
80756 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80757 u32 offset, struct device_node *);
80758diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80759index 1f44466..b481806 100644
80760--- a/include/linux/jiffies.h
80761+++ b/include/linux/jiffies.h
80762@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80763 /*
80764 * Convert various time units to each other:
80765 */
80766-extern unsigned int jiffies_to_msecs(const unsigned long j);
80767-extern unsigned int jiffies_to_usecs(const unsigned long j);
80768+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80769+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80770
80771-static inline u64 jiffies_to_nsecs(const unsigned long j)
80772+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80773 {
80774 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80775 }
80776
80777-extern unsigned long msecs_to_jiffies(const unsigned int m);
80778-extern unsigned long usecs_to_jiffies(const unsigned int u);
80779+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80780+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80781 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80782 extern void jiffies_to_timespec(const unsigned long jiffies,
80783- struct timespec *value);
80784-extern unsigned long timeval_to_jiffies(const struct timeval *value);
80785+ struct timespec *value) __intentional_overflow(-1);
80786+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80787 extern void jiffies_to_timeval(const unsigned long jiffies,
80788 struct timeval *value);
80789
80790diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80791index 6883e19..e854fcb 100644
80792--- a/include/linux/kallsyms.h
80793+++ b/include/linux/kallsyms.h
80794@@ -15,7 +15,8 @@
80795
80796 struct module;
80797
80798-#ifdef CONFIG_KALLSYMS
80799+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80800+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80801 /* Lookup the address for a symbol. Returns 0 if not found. */
80802 unsigned long kallsyms_lookup_name(const char *name);
80803
80804@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80805 /* Stupid that this does nothing, but I didn't create this mess. */
80806 #define __print_symbol(fmt, addr)
80807 #endif /*CONFIG_KALLSYMS*/
80808+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80809+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80810+extern unsigned long kallsyms_lookup_name(const char *name);
80811+extern void __print_symbol(const char *fmt, unsigned long address);
80812+extern int sprint_backtrace(char *buffer, unsigned long address);
80813+extern int sprint_symbol(char *buffer, unsigned long address);
80814+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80815+const char *kallsyms_lookup(unsigned long addr,
80816+ unsigned long *symbolsize,
80817+ unsigned long *offset,
80818+ char **modname, char *namebuf);
80819+extern int kallsyms_lookup_size_offset(unsigned long addr,
80820+ unsigned long *symbolsize,
80821+ unsigned long *offset);
80822+#endif
80823
80824 /* This macro allows us to keep printk typechecking */
80825 static __printf(1, 2)
80826diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80827index a74c3a8..28d3f21 100644
80828--- a/include/linux/key-type.h
80829+++ b/include/linux/key-type.h
80830@@ -131,7 +131,7 @@ struct key_type {
80831 /* internal fields */
80832 struct list_head link; /* link in types list */
80833 struct lock_class_key lock_class; /* key->sem lock class */
80834-};
80835+} __do_const;
80836
80837 extern struct key_type key_type_keyring;
80838
80839diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80840index 6b06d37..c134867 100644
80841--- a/include/linux/kgdb.h
80842+++ b/include/linux/kgdb.h
80843@@ -52,7 +52,7 @@ extern int kgdb_connected;
80844 extern int kgdb_io_module_registered;
80845
80846 extern atomic_t kgdb_setting_breakpoint;
80847-extern atomic_t kgdb_cpu_doing_single_step;
80848+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80849
80850 extern struct task_struct *kgdb_usethread;
80851 extern struct task_struct *kgdb_contthread;
80852@@ -254,7 +254,7 @@ struct kgdb_arch {
80853 void (*correct_hw_break)(void);
80854
80855 void (*enable_nmi)(bool on);
80856-};
80857+} __do_const;
80858
80859 /**
80860 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80861@@ -279,7 +279,7 @@ struct kgdb_io {
80862 void (*pre_exception) (void);
80863 void (*post_exception) (void);
80864 int is_console;
80865-};
80866+} __do_const;
80867
80868 extern struct kgdb_arch arch_kgdb_ops;
80869
80870diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80871index 0555cc6..40116ce 100644
80872--- a/include/linux/kmod.h
80873+++ b/include/linux/kmod.h
80874@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80875 * usually useless though. */
80876 extern __printf(2, 3)
80877 int __request_module(bool wait, const char *name, ...);
80878+extern __printf(3, 4)
80879+int ___request_module(bool wait, char *param_name, const char *name, ...);
80880 #define request_module(mod...) __request_module(true, mod)
80881 #define request_module_nowait(mod...) __request_module(false, mod)
80882 #define try_then_request_module(x, mod...) \
80883@@ -57,6 +59,9 @@ struct subprocess_info {
80884 struct work_struct work;
80885 struct completion *complete;
80886 char *path;
80887+#ifdef CONFIG_GRKERNSEC
80888+ char *origpath;
80889+#endif
80890 char **argv;
80891 char **envp;
80892 int wait;
80893diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80894index f896a33..f2eb10f 100644
80895--- a/include/linux/kobject.h
80896+++ b/include/linux/kobject.h
80897@@ -116,7 +116,7 @@ struct kobj_type {
80898 struct attribute **default_attrs;
80899 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80900 const void *(*namespace)(struct kobject *kobj);
80901-};
80902+} __do_const;
80903
80904 struct kobj_uevent_env {
80905 char *argv[3];
80906@@ -140,6 +140,7 @@ struct kobj_attribute {
80907 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80908 const char *buf, size_t count);
80909 };
80910+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80911
80912 extern const struct sysfs_ops kobj_sysfs_ops;
80913
80914@@ -167,7 +168,7 @@ struct kset {
80915 spinlock_t list_lock;
80916 struct kobject kobj;
80917 const struct kset_uevent_ops *uevent_ops;
80918-};
80919+} __randomize_layout;
80920
80921 extern void kset_init(struct kset *kset);
80922 extern int __must_check kset_register(struct kset *kset);
80923diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80924index df32d25..fb52e27 100644
80925--- a/include/linux/kobject_ns.h
80926+++ b/include/linux/kobject_ns.h
80927@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80928 const void *(*netlink_ns)(struct sock *sk);
80929 const void *(*initial_ns)(void);
80930 void (*drop_ns)(void *);
80931-};
80932+} __do_const;
80933
80934 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80935 int kobj_ns_type_registered(enum kobj_ns_type type);
80936diff --git a/include/linux/kref.h b/include/linux/kref.h
80937index 484604d..0f6c5b6 100644
80938--- a/include/linux/kref.h
80939+++ b/include/linux/kref.h
80940@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80941 static inline int kref_sub(struct kref *kref, unsigned int count,
80942 void (*release)(struct kref *kref))
80943 {
80944- WARN_ON(release == NULL);
80945+ BUG_ON(release == NULL);
80946
80947 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80948 release(kref);
80949diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80950index 7d21cf9..bc0c81f 100644
80951--- a/include/linux/kvm_host.h
80952+++ b/include/linux/kvm_host.h
80953@@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80954 {
80955 }
80956 #endif
80957-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80958+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80959 struct module *module);
80960 void kvm_exit(void);
80961
80962@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80963 struct kvm_guest_debug *dbg);
80964 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80965
80966-int kvm_arch_init(void *opaque);
80967+int kvm_arch_init(const void *opaque);
80968 void kvm_arch_exit(void);
80969
80970 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80971diff --git a/include/linux/libata.h b/include/linux/libata.h
80972index 92abb49..e7fff2a 100644
80973--- a/include/linux/libata.h
80974+++ b/include/linux/libata.h
80975@@ -976,7 +976,7 @@ struct ata_port_operations {
80976 * fields must be pointers.
80977 */
80978 const struct ata_port_operations *inherits;
80979-};
80980+} __do_const;
80981
80982 struct ata_port_info {
80983 unsigned long flags;
80984diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80985index a6a42dd..6c5ebce 100644
80986--- a/include/linux/linkage.h
80987+++ b/include/linux/linkage.h
80988@@ -36,6 +36,7 @@
80989 #endif
80990
80991 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80992+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80993 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80994
80995 /*
80996diff --git a/include/linux/list.h b/include/linux/list.h
80997index ef95941..82db65a 100644
80998--- a/include/linux/list.h
80999+++ b/include/linux/list.h
81000@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
81001 extern void list_del(struct list_head *entry);
81002 #endif
81003
81004+extern void __pax_list_add(struct list_head *new,
81005+ struct list_head *prev,
81006+ struct list_head *next);
81007+static inline void pax_list_add(struct list_head *new, struct list_head *head)
81008+{
81009+ __pax_list_add(new, head, head->next);
81010+}
81011+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
81012+{
81013+ __pax_list_add(new, head->prev, head);
81014+}
81015+extern void pax_list_del(struct list_head *entry);
81016+
81017 /**
81018 * list_replace - replace old entry by new one
81019 * @old : the element to be replaced
81020@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
81021 INIT_LIST_HEAD(entry);
81022 }
81023
81024+extern void pax_list_del_init(struct list_head *entry);
81025+
81026 /**
81027 * list_move - delete from one list and add as another's head
81028 * @list: the entry to move
81029diff --git a/include/linux/math64.h b/include/linux/math64.h
81030index c45c089..298841c 100644
81031--- a/include/linux/math64.h
81032+++ b/include/linux/math64.h
81033@@ -15,7 +15,7 @@
81034 * This is commonly provided by 32bit archs to provide an optimized 64bit
81035 * divide.
81036 */
81037-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
81038+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
81039 {
81040 *remainder = dividend % divisor;
81041 return dividend / divisor;
81042@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
81043 /**
81044 * div64_u64 - unsigned 64bit divide with 64bit divisor
81045 */
81046-static inline u64 div64_u64(u64 dividend, u64 divisor)
81047+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
81048 {
81049 return dividend / divisor;
81050 }
81051@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
81052 #define div64_ul(x, y) div_u64((x), (y))
81053
81054 #ifndef div_u64_rem
81055-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
81056+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
81057 {
81058 *remainder = do_div(dividend, divisor);
81059 return dividend;
81060@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
81061 #endif
81062
81063 #ifndef div64_u64
81064-extern u64 div64_u64(u64 dividend, u64 divisor);
81065+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
81066 #endif
81067
81068 #ifndef div64_s64
81069@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
81070 * divide.
81071 */
81072 #ifndef div_u64
81073-static inline u64 div_u64(u64 dividend, u32 divisor)
81074+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
81075 {
81076 u32 remainder;
81077 return div_u64_rem(dividend, divisor, &remainder);
81078diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
81079index f230a97..714c006 100644
81080--- a/include/linux/mempolicy.h
81081+++ b/include/linux/mempolicy.h
81082@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
81083 }
81084
81085 #define vma_policy(vma) ((vma)->vm_policy)
81086+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
81087+{
81088+ vma->vm_policy = pol;
81089+}
81090
81091 static inline void mpol_get(struct mempolicy *pol)
81092 {
81093@@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
81094 }
81095
81096 #define vma_policy(vma) NULL
81097+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
81098+{
81099+}
81100
81101 static inline int
81102 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
81103diff --git a/include/linux/mm.h b/include/linux/mm.h
81104index d677706..673408c 100644
81105--- a/include/linux/mm.h
81106+++ b/include/linux/mm.h
81107@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
81108 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
81109 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
81110 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
81111+
81112+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81113+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
81114+#endif
81115+
81116 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
81117
81118 #ifdef CONFIG_MEM_SOFT_DIRTY
81119@@ -237,8 +242,8 @@ struct vm_operations_struct {
81120 /* called by access_process_vm when get_user_pages() fails, typically
81121 * for use by special VMAs that can switch between memory and hardware
81122 */
81123- int (*access)(struct vm_area_struct *vma, unsigned long addr,
81124- void *buf, int len, int write);
81125+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
81126+ void *buf, size_t len, int write);
81127 #ifdef CONFIG_NUMA
81128 /*
81129 * set_policy() op must add a reference to any non-NULL @new mempolicy
81130@@ -268,6 +273,7 @@ struct vm_operations_struct {
81131 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
81132 unsigned long size, pgoff_t pgoff);
81133 };
81134+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
81135
81136 struct mmu_gather;
81137 struct inode;
81138@@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
81139 unsigned long *pfn);
81140 int follow_phys(struct vm_area_struct *vma, unsigned long address,
81141 unsigned int flags, unsigned long *prot, resource_size_t *phys);
81142-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81143- void *buf, int len, int write);
81144+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81145+ void *buf, size_t len, int write);
81146
81147 static inline void unmap_shared_mapping_range(struct address_space *mapping,
81148 loff_t const holebegin, loff_t const holelen)
81149@@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
81150 }
81151 #endif
81152
81153-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
81154-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81155- void *buf, int len, int write);
81156+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
81157+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
81158+ void *buf, size_t len, int write);
81159
81160 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81161 unsigned long start, unsigned long nr_pages,
81162@@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
81163 int clear_page_dirty_for_io(struct page *page);
81164 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
81165
81166-/* Is the vma a continuation of the stack vma above it? */
81167-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
81168-{
81169- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
81170-}
81171-
81172-static inline int stack_guard_page_start(struct vm_area_struct *vma,
81173- unsigned long addr)
81174-{
81175- return (vma->vm_flags & VM_GROWSDOWN) &&
81176- (vma->vm_start == addr) &&
81177- !vma_growsdown(vma->vm_prev, addr);
81178-}
81179-
81180-/* Is the vma a continuation of the stack vma below it? */
81181-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
81182-{
81183- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
81184-}
81185-
81186-static inline int stack_guard_page_end(struct vm_area_struct *vma,
81187- unsigned long addr)
81188-{
81189- return (vma->vm_flags & VM_GROWSUP) &&
81190- (vma->vm_end == addr) &&
81191- !vma_growsup(vma->vm_next, addr);
81192-}
81193-
81194 extern pid_t
81195 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
81196
81197@@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
81198 }
81199 #endif
81200
81201+#ifdef CONFIG_MMU
81202+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
81203+#else
81204+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
81205+{
81206+ return __pgprot(0);
81207+}
81208+#endif
81209+
81210 int vma_wants_writenotify(struct vm_area_struct *vma);
81211
81212 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
81213@@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
81214 {
81215 return 0;
81216 }
81217+
81218+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
81219+ unsigned long address)
81220+{
81221+ return 0;
81222+}
81223 #else
81224 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
81225+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
81226 #endif
81227
81228 #ifdef __PAGETABLE_PMD_FOLDED
81229@@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
81230 {
81231 return 0;
81232 }
81233+
81234+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
81235+ unsigned long address)
81236+{
81237+ return 0;
81238+}
81239 #else
81240 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
81241+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
81242 #endif
81243
81244 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
81245@@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
81246 NULL: pud_offset(pgd, address);
81247 }
81248
81249+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81250+{
81251+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
81252+ NULL: pud_offset(pgd, address);
81253+}
81254+
81255 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
81256 {
81257 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
81258 NULL: pmd_offset(pud, address);
81259 }
81260+
81261+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
81262+{
81263+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
81264+ NULL: pmd_offset(pud, address);
81265+}
81266 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
81267
81268 #if USE_SPLIT_PTE_PTLOCKS
81269@@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
81270 unsigned long addr, unsigned long len,
81271 unsigned long flags, struct page **pages);
81272
81273-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
81274+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
81275
81276 extern unsigned long mmap_region(struct file *file, unsigned long addr,
81277 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
81278@@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81279 unsigned long len, unsigned long prot, unsigned long flags,
81280 unsigned long pgoff, unsigned long *populate);
81281 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
81282+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
81283
81284 #ifdef CONFIG_MMU
81285 extern int __mm_populate(unsigned long addr, unsigned long len,
81286@@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
81287 unsigned long high_limit;
81288 unsigned long align_mask;
81289 unsigned long align_offset;
81290+ unsigned long threadstack_offset;
81291 };
81292
81293-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
81294-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81295+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
81296+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
81297
81298 /*
81299 * Search for an unmapped address range.
81300@@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81301 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
81302 */
81303 static inline unsigned long
81304-vm_unmapped_area(struct vm_unmapped_area_info *info)
81305+vm_unmapped_area(const struct vm_unmapped_area_info *info)
81306 {
81307 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
81308 return unmapped_area(info);
81309@@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
81310 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
81311 struct vm_area_struct **pprev);
81312
81313+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
81314+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
81315+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
81316+
81317 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
81318 NULL if none. Assume start_addr < end_addr. */
81319 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
81320@@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
81321 return vma;
81322 }
81323
81324-#ifdef CONFIG_MMU
81325-pgprot_t vm_get_page_prot(unsigned long vm_flags);
81326-#else
81327-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
81328-{
81329- return __pgprot(0);
81330-}
81331-#endif
81332-
81333 #ifdef CONFIG_NUMA_BALANCING
81334 unsigned long change_prot_numa(struct vm_area_struct *vma,
81335 unsigned long start, unsigned long end);
81336@@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
81337 static inline void vm_stat_account(struct mm_struct *mm,
81338 unsigned long flags, struct file *file, long pages)
81339 {
81340+
81341+#ifdef CONFIG_PAX_RANDMMAP
81342+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81343+#endif
81344+
81345 mm->total_vm += pages;
81346 }
81347 #endif /* CONFIG_PROC_FS */
81348@@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
81349 extern int sysctl_memory_failure_early_kill;
81350 extern int sysctl_memory_failure_recovery;
81351 extern void shake_page(struct page *p, int access);
81352-extern atomic_long_t num_poisoned_pages;
81353+extern atomic_long_unchecked_t num_poisoned_pages;
81354 extern int soft_offline_page(struct page *page, int flags);
81355
81356 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
81357@@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
81358 static inline void setup_nr_node_ids(void) {}
81359 #endif
81360
81361+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81362+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
81363+#else
81364+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
81365+#endif
81366+
81367 #endif /* __KERNEL__ */
81368 #endif /* _LINUX_MM_H */
81369diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
81370index 8967e20..61f7900 100644
81371--- a/include/linux/mm_types.h
81372+++ b/include/linux/mm_types.h
81373@@ -308,7 +308,9 @@ struct vm_area_struct {
81374 #ifdef CONFIG_NUMA
81375 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
81376 #endif
81377-};
81378+
81379+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
81380+} __randomize_layout;
81381
81382 struct core_thread {
81383 struct task_struct *task;
81384@@ -454,7 +456,25 @@ struct mm_struct {
81385 bool tlb_flush_pending;
81386 #endif
81387 struct uprobes_state uprobes_state;
81388-};
81389+
81390+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81391+ unsigned long pax_flags;
81392+#endif
81393+
81394+#ifdef CONFIG_PAX_DLRESOLVE
81395+ unsigned long call_dl_resolve;
81396+#endif
81397+
81398+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
81399+ unsigned long call_syscall;
81400+#endif
81401+
81402+#ifdef CONFIG_PAX_ASLR
81403+ unsigned long delta_mmap; /* randomized offset */
81404+ unsigned long delta_stack; /* randomized offset */
81405+#endif
81406+
81407+} __randomize_layout;
81408
81409 static inline void mm_init_cpumask(struct mm_struct *mm)
81410 {
81411diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
81412index c5d5278..f0b68c8 100644
81413--- a/include/linux/mmiotrace.h
81414+++ b/include/linux/mmiotrace.h
81415@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
81416 /* Called from ioremap.c */
81417 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
81418 void __iomem *addr);
81419-extern void mmiotrace_iounmap(volatile void __iomem *addr);
81420+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
81421
81422 /* For anyone to insert markers. Remember trailing newline. */
81423 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
81424@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
81425 {
81426 }
81427
81428-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
81429+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
81430 {
81431 }
81432
81433diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
81434index 835aa3d..676b387 100644
81435--- a/include/linux/mmzone.h
81436+++ b/include/linux/mmzone.h
81437@@ -406,7 +406,7 @@ struct zone {
81438 unsigned long flags; /* zone flags, see below */
81439
81440 /* Zone statistics */
81441- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81442+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81443
81444 /*
81445 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
81446diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
81447index 44eeef0..a92d3f9 100644
81448--- a/include/linux/mod_devicetable.h
81449+++ b/include/linux/mod_devicetable.h
81450@@ -139,7 +139,7 @@ struct usb_device_id {
81451 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
81452 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
81453
81454-#define HID_ANY_ID (~0)
81455+#define HID_ANY_ID (~0U)
81456 #define HID_BUS_ANY 0xffff
81457 #define HID_GROUP_ANY 0x0000
81458
81459@@ -475,7 +475,7 @@ struct dmi_system_id {
81460 const char *ident;
81461 struct dmi_strmatch matches[4];
81462 void *driver_data;
81463-};
81464+} __do_const;
81465 /*
81466 * struct dmi_device_id appears during expansion of
81467 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
81468diff --git a/include/linux/module.h b/include/linux/module.h
81469index f520a76..5f898ef 100644
81470--- a/include/linux/module.h
81471+++ b/include/linux/module.h
81472@@ -17,9 +17,11 @@
81473 #include <linux/moduleparam.h>
81474 #include <linux/jump_label.h>
81475 #include <linux/export.h>
81476+#include <linux/fs.h>
81477
81478 #include <linux/percpu.h>
81479 #include <asm/module.h>
81480+#include <asm/pgtable.h>
81481
81482 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81483 #define MODULE_SIG_STRING "~Module signature appended~\n"
81484@@ -42,7 +44,7 @@ struct module_kobject {
81485 struct kobject *drivers_dir;
81486 struct module_param_attrs *mp;
81487 struct completion *kobj_completion;
81488-};
81489+} __randomize_layout;
81490
81491 struct module_attribute {
81492 struct attribute attr;
81493@@ -54,12 +56,13 @@ struct module_attribute {
81494 int (*test)(struct module *);
81495 void (*free)(struct module *);
81496 };
81497+typedef struct module_attribute __no_const module_attribute_no_const;
81498
81499 struct module_version_attribute {
81500 struct module_attribute mattr;
81501 const char *module_name;
81502 const char *version;
81503-} __attribute__ ((__aligned__(sizeof(void *))));
81504+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81505
81506 extern ssize_t __modver_version_show(struct module_attribute *,
81507 struct module_kobject *, char *);
81508@@ -235,7 +238,7 @@ struct module {
81509
81510 /* Sysfs stuff. */
81511 struct module_kobject mkobj;
81512- struct module_attribute *modinfo_attrs;
81513+ module_attribute_no_const *modinfo_attrs;
81514 const char *version;
81515 const char *srcversion;
81516 struct kobject *holders_dir;
81517@@ -284,19 +287,16 @@ struct module {
81518 int (*init)(void);
81519
81520 /* If this is non-NULL, vfree after init() returns */
81521- void *module_init;
81522+ void *module_init_rx, *module_init_rw;
81523
81524 /* Here is the actual code + data, vfree'd on unload. */
81525- void *module_core;
81526+ void *module_core_rx, *module_core_rw;
81527
81528 /* Here are the sizes of the init and core sections */
81529- unsigned int init_size, core_size;
81530+ unsigned int init_size_rw, core_size_rw;
81531
81532 /* The size of the executable code in each section. */
81533- unsigned int init_text_size, core_text_size;
81534-
81535- /* Size of RO sections of the module (text+rodata) */
81536- unsigned int init_ro_size, core_ro_size;
81537+ unsigned int init_size_rx, core_size_rx;
81538
81539 /* Arch-specific module values */
81540 struct mod_arch_specific arch;
81541@@ -352,6 +352,10 @@ struct module {
81542 #ifdef CONFIG_EVENT_TRACING
81543 struct ftrace_event_call **trace_events;
81544 unsigned int num_trace_events;
81545+ struct file_operations trace_id;
81546+ struct file_operations trace_enable;
81547+ struct file_operations trace_format;
81548+ struct file_operations trace_filter;
81549 #endif
81550 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81551 unsigned int num_ftrace_callsites;
81552@@ -375,7 +379,7 @@ struct module {
81553 ctor_fn_t *ctors;
81554 unsigned int num_ctors;
81555 #endif
81556-};
81557+} __randomize_layout;
81558 #ifndef MODULE_ARCH_INIT
81559 #define MODULE_ARCH_INIT {}
81560 #endif
81561@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
81562 bool is_module_percpu_address(unsigned long addr);
81563 bool is_module_text_address(unsigned long addr);
81564
81565+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81566+{
81567+
81568+#ifdef CONFIG_PAX_KERNEXEC
81569+ if (ktla_ktva(addr) >= (unsigned long)start &&
81570+ ktla_ktva(addr) < (unsigned long)start + size)
81571+ return 1;
81572+#endif
81573+
81574+ return ((void *)addr >= start && (void *)addr < start + size);
81575+}
81576+
81577+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81578+{
81579+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81580+}
81581+
81582+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81583+{
81584+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81585+}
81586+
81587+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81588+{
81589+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81590+}
81591+
81592+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81593+{
81594+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81595+}
81596+
81597 static inline int within_module_core(unsigned long addr, const struct module *mod)
81598 {
81599- return (unsigned long)mod->module_core <= addr &&
81600- addr < (unsigned long)mod->module_core + mod->core_size;
81601+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81602 }
81603
81604 static inline int within_module_init(unsigned long addr, const struct module *mod)
81605 {
81606- return (unsigned long)mod->module_init <= addr &&
81607- addr < (unsigned long)mod->module_init + mod->init_size;
81608+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81609 }
81610
81611 /* Search for module by name: must hold module_mutex. */
81612diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81613index 560ca53..ef621ef 100644
81614--- a/include/linux/moduleloader.h
81615+++ b/include/linux/moduleloader.h
81616@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81617 sections. Returns NULL on failure. */
81618 void *module_alloc(unsigned long size);
81619
81620+#ifdef CONFIG_PAX_KERNEXEC
81621+void *module_alloc_exec(unsigned long size);
81622+#else
81623+#define module_alloc_exec(x) module_alloc(x)
81624+#endif
81625+
81626 /* Free memory returned from module_alloc. */
81627 void module_free(struct module *mod, void *module_region);
81628
81629+#ifdef CONFIG_PAX_KERNEXEC
81630+void module_free_exec(struct module *mod, void *module_region);
81631+#else
81632+#define module_free_exec(x, y) module_free((x), (y))
81633+#endif
81634+
81635 /*
81636 * Apply the given relocation to the (simplified) ELF. Return -error
81637 * or 0.
81638@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81639 unsigned int relsec,
81640 struct module *me)
81641 {
81642+#ifdef CONFIG_MODULES
81643 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81644+#endif
81645 return -ENOEXEC;
81646 }
81647 #endif
81648@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81649 unsigned int relsec,
81650 struct module *me)
81651 {
81652+#ifdef CONFIG_MODULES
81653 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81654+#endif
81655 return -ENOEXEC;
81656 }
81657 #endif
81658diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81659index 204a677..e9b486a 100644
81660--- a/include/linux/moduleparam.h
81661+++ b/include/linux/moduleparam.h
81662@@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
81663 * @len is usually just sizeof(string).
81664 */
81665 #define module_param_string(name, string, len, perm) \
81666- static const struct kparam_string __param_string_##name \
81667+ static const struct kparam_string __param_string_##name __used \
81668 = { len, string }; \
81669 __module_param_call(MODULE_PARAM_PREFIX, name, \
81670 &param_ops_string, \
81671@@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81672 */
81673 #define module_param_array_named(name, array, type, nump, perm) \
81674 param_check_##type(name, &(array)[0]); \
81675- static const struct kparam_array __param_arr_##name \
81676+ static const struct kparam_array __param_arr_##name __used \
81677 = { .max = ARRAY_SIZE(array), .num = nump, \
81678 .ops = &param_ops_##type, \
81679 .elemsize = sizeof(array[0]), .elem = array }; \
81680diff --git a/include/linux/mount.h b/include/linux/mount.h
81681index 839bac2..a96b37c 100644
81682--- a/include/linux/mount.h
81683+++ b/include/linux/mount.h
81684@@ -59,7 +59,7 @@ struct vfsmount {
81685 struct dentry *mnt_root; /* root of the mounted tree */
81686 struct super_block *mnt_sb; /* pointer to superblock */
81687 int mnt_flags;
81688-};
81689+} __randomize_layout;
81690
81691 struct file; /* forward dec */
81692
81693diff --git a/include/linux/namei.h b/include/linux/namei.h
81694index 492de72..1bddcd4 100644
81695--- a/include/linux/namei.h
81696+++ b/include/linux/namei.h
81697@@ -19,7 +19,7 @@ struct nameidata {
81698 unsigned seq, m_seq;
81699 int last_type;
81700 unsigned depth;
81701- char *saved_names[MAX_NESTED_LINKS + 1];
81702+ const char *saved_names[MAX_NESTED_LINKS + 1];
81703 };
81704
81705 /*
81706@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81707
81708 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81709
81710-static inline void nd_set_link(struct nameidata *nd, char *path)
81711+static inline void nd_set_link(struct nameidata *nd, const char *path)
81712 {
81713 nd->saved_names[nd->depth] = path;
81714 }
81715
81716-static inline char *nd_get_link(struct nameidata *nd)
81717+static inline const char *nd_get_link(const struct nameidata *nd)
81718 {
81719 return nd->saved_names[nd->depth];
81720 }
81721diff --git a/include/linux/net.h b/include/linux/net.h
81722index 17d8339..81656c0 100644
81723--- a/include/linux/net.h
81724+++ b/include/linux/net.h
81725@@ -192,7 +192,7 @@ struct net_proto_family {
81726 int (*create)(struct net *net, struct socket *sock,
81727 int protocol, int kern);
81728 struct module *owner;
81729-};
81730+} __do_const;
81731
81732 struct iovec;
81733 struct kvec;
81734diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81735index b42d07b..7f45ae2 100644
81736--- a/include/linux/netdevice.h
81737+++ b/include/linux/netdevice.h
81738@@ -1146,6 +1146,7 @@ struct net_device_ops {
81739 void *priv);
81740 int (*ndo_get_lock_subclass)(struct net_device *dev);
81741 };
81742+typedef struct net_device_ops __no_const net_device_ops_no_const;
81743
81744 /**
81745 * enum net_device_priv_flags - &struct net_device priv_flags
81746@@ -1313,11 +1314,11 @@ struct net_device {
81747 struct net_device_stats stats;
81748
81749 /* dropped packets by core network, Do not use this in drivers */
81750- atomic_long_t rx_dropped;
81751- atomic_long_t tx_dropped;
81752+ atomic_long_unchecked_t rx_dropped;
81753+ atomic_long_unchecked_t tx_dropped;
81754
81755 /* Stats to monitor carrier on<->off transitions */
81756- atomic_t carrier_changes;
81757+ atomic_unchecked_t carrier_changes;
81758
81759 #ifdef CONFIG_WIRELESS_EXT
81760 /* List of functions to handle Wireless Extensions (instead of ioctl).
81761diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81762index 2077489..a15e561 100644
81763--- a/include/linux/netfilter.h
81764+++ b/include/linux/netfilter.h
81765@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81766 #endif
81767 /* Use the module struct to lock set/get code in place */
81768 struct module *owner;
81769-};
81770+} __do_const;
81771
81772 /* Function to register/unregister hook points. */
81773 int nf_register_hook(struct nf_hook_ops *reg);
81774diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81775index e955d47..04a5338 100644
81776--- a/include/linux/netfilter/nfnetlink.h
81777+++ b/include/linux/netfilter/nfnetlink.h
81778@@ -19,7 +19,7 @@ struct nfnl_callback {
81779 const struct nlattr * const cda[]);
81780 const struct nla_policy *policy; /* netlink attribute policy */
81781 const u_int16_t attr_count; /* number of nlattr's */
81782-};
81783+} __do_const;
81784
81785 struct nfnetlink_subsystem {
81786 const char *name;
81787diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81788new file mode 100644
81789index 0000000..33f4af8
81790--- /dev/null
81791+++ b/include/linux/netfilter/xt_gradm.h
81792@@ -0,0 +1,9 @@
81793+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81794+#define _LINUX_NETFILTER_XT_GRADM_H 1
81795+
81796+struct xt_gradm_mtinfo {
81797+ __u16 flags;
81798+ __u16 invflags;
81799+};
81800+
81801+#endif
81802diff --git a/include/linux/nls.h b/include/linux/nls.h
81803index 520681b..1d67ed2 100644
81804--- a/include/linux/nls.h
81805+++ b/include/linux/nls.h
81806@@ -31,7 +31,7 @@ struct nls_table {
81807 const unsigned char *charset2upper;
81808 struct module *owner;
81809 struct nls_table *next;
81810-};
81811+} __do_const;
81812
81813 /* this value hold the maximum octet of charset */
81814 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81815diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81816index d14a4c3..a078786 100644
81817--- a/include/linux/notifier.h
81818+++ b/include/linux/notifier.h
81819@@ -54,7 +54,8 @@ struct notifier_block {
81820 notifier_fn_t notifier_call;
81821 struct notifier_block __rcu *next;
81822 int priority;
81823-};
81824+} __do_const;
81825+typedef struct notifier_block __no_const notifier_block_no_const;
81826
81827 struct atomic_notifier_head {
81828 spinlock_t lock;
81829diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81830index b2a0f15..4d7da32 100644
81831--- a/include/linux/oprofile.h
81832+++ b/include/linux/oprofile.h
81833@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81834 int oprofilefs_create_ro_ulong(struct dentry * root,
81835 char const * name, ulong * val);
81836
81837-/** Create a file for read-only access to an atomic_t. */
81838+/** Create a file for read-only access to an atomic_unchecked_t. */
81839 int oprofilefs_create_ro_atomic(struct dentry * root,
81840- char const * name, atomic_t * val);
81841+ char const * name, atomic_unchecked_t * val);
81842
81843 /** create a directory */
81844 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81845diff --git a/include/linux/padata.h b/include/linux/padata.h
81846index 4386946..f50c615 100644
81847--- a/include/linux/padata.h
81848+++ b/include/linux/padata.h
81849@@ -129,7 +129,7 @@ struct parallel_data {
81850 struct padata_serial_queue __percpu *squeue;
81851 atomic_t reorder_objects;
81852 atomic_t refcnt;
81853- atomic_t seq_nr;
81854+ atomic_unchecked_t seq_nr;
81855 struct padata_cpumask cpumask;
81856 spinlock_t lock ____cacheline_aligned;
81857 unsigned int processed;
81858diff --git a/include/linux/path.h b/include/linux/path.h
81859index d137218..be0c176 100644
81860--- a/include/linux/path.h
81861+++ b/include/linux/path.h
81862@@ -1,13 +1,15 @@
81863 #ifndef _LINUX_PATH_H
81864 #define _LINUX_PATH_H
81865
81866+#include <linux/compiler.h>
81867+
81868 struct dentry;
81869 struct vfsmount;
81870
81871 struct path {
81872 struct vfsmount *mnt;
81873 struct dentry *dentry;
81874-};
81875+} __randomize_layout;
81876
81877 extern void path_get(const struct path *);
81878 extern void path_put(const struct path *);
81879diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81880index 5f2e559..7d59314 100644
81881--- a/include/linux/pci_hotplug.h
81882+++ b/include/linux/pci_hotplug.h
81883@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81884 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81885 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81886 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81887-};
81888+} __do_const;
81889+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81890
81891 /**
81892 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81893diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81894index 3ef6ea1..ed1a248 100644
81895--- a/include/linux/perf_event.h
81896+++ b/include/linux/perf_event.h
81897@@ -328,8 +328,8 @@ struct perf_event {
81898
81899 enum perf_event_active_state state;
81900 unsigned int attach_state;
81901- local64_t count;
81902- atomic64_t child_count;
81903+ local64_t count; /* PaX: fix it one day */
81904+ atomic64_unchecked_t child_count;
81905
81906 /*
81907 * These are the total time in nanoseconds that the event
81908@@ -380,8 +380,8 @@ struct perf_event {
81909 * These accumulate total time (in nanoseconds) that children
81910 * events have been enabled and running, respectively.
81911 */
81912- atomic64_t child_total_time_enabled;
81913- atomic64_t child_total_time_running;
81914+ atomic64_unchecked_t child_total_time_enabled;
81915+ atomic64_unchecked_t child_total_time_running;
81916
81917 /*
81918 * Protect attach/detach and child_list:
81919@@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81920 entry->ip[entry->nr++] = ip;
81921 }
81922
81923-extern int sysctl_perf_event_paranoid;
81924+extern int sysctl_perf_event_legitimately_concerned;
81925 extern int sysctl_perf_event_mlock;
81926 extern int sysctl_perf_event_sample_rate;
81927 extern int sysctl_perf_cpu_time_max_percent;
81928@@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81929 loff_t *ppos);
81930
81931
81932+static inline bool perf_paranoid_any(void)
81933+{
81934+ return sysctl_perf_event_legitimately_concerned > 2;
81935+}
81936+
81937 static inline bool perf_paranoid_tracepoint_raw(void)
81938 {
81939- return sysctl_perf_event_paranoid > -1;
81940+ return sysctl_perf_event_legitimately_concerned > -1;
81941 }
81942
81943 static inline bool perf_paranoid_cpu(void)
81944 {
81945- return sysctl_perf_event_paranoid > 0;
81946+ return sysctl_perf_event_legitimately_concerned > 0;
81947 }
81948
81949 static inline bool perf_paranoid_kernel(void)
81950 {
81951- return sysctl_perf_event_paranoid > 1;
81952+ return sysctl_perf_event_legitimately_concerned > 1;
81953 }
81954
81955 extern void perf_event_init(void);
81956@@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81957 struct device_attribute attr;
81958 u64 id;
81959 const char *event_str;
81960-};
81961+} __do_const;
81962
81963 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81964 static struct perf_pmu_events_attr _var = { \
81965diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81966index 7246ef3..1539ea4 100644
81967--- a/include/linux/pid_namespace.h
81968+++ b/include/linux/pid_namespace.h
81969@@ -43,7 +43,7 @@ struct pid_namespace {
81970 int hide_pid;
81971 int reboot; /* group exit code if this pidns was rebooted */
81972 unsigned int proc_inum;
81973-};
81974+} __randomize_layout;
81975
81976 extern struct pid_namespace init_pid_ns;
81977
81978diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81979index eb8b8ac..62649e1 100644
81980--- a/include/linux/pipe_fs_i.h
81981+++ b/include/linux/pipe_fs_i.h
81982@@ -47,10 +47,10 @@ struct pipe_inode_info {
81983 struct mutex mutex;
81984 wait_queue_head_t wait;
81985 unsigned int nrbufs, curbuf, buffers;
81986- unsigned int readers;
81987- unsigned int writers;
81988- unsigned int files;
81989- unsigned int waiting_writers;
81990+ atomic_t readers;
81991+ atomic_t writers;
81992+ atomic_t files;
81993+ atomic_t waiting_writers;
81994 unsigned int r_counter;
81995 unsigned int w_counter;
81996 struct page *tmp_page;
81997diff --git a/include/linux/pm.h b/include/linux/pm.h
81998index d915d03..0531037 100644
81999--- a/include/linux/pm.h
82000+++ b/include/linux/pm.h
82001@@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
82002 struct dev_pm_domain {
82003 struct dev_pm_ops ops;
82004 };
82005+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
82006
82007 /*
82008 * The PM_EVENT_ messages are also used by drivers implementing the legacy
82009diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
82010index 7c1d252..0e7061d 100644
82011--- a/include/linux/pm_domain.h
82012+++ b/include/linux/pm_domain.h
82013@@ -44,11 +44,11 @@ struct gpd_dev_ops {
82014 int (*thaw_early)(struct device *dev);
82015 int (*thaw)(struct device *dev);
82016 bool (*active_wakeup)(struct device *dev);
82017-};
82018+} __no_const;
82019
82020 struct gpd_cpu_data {
82021 unsigned int saved_exit_latency;
82022- struct cpuidle_state *idle_state;
82023+ cpuidle_state_no_const *idle_state;
82024 };
82025
82026 struct generic_pm_domain {
82027diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
82028index 2a5897a..4f9af63 100644
82029--- a/include/linux/pm_runtime.h
82030+++ b/include/linux/pm_runtime.h
82031@@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
82032
82033 static inline void pm_runtime_mark_last_busy(struct device *dev)
82034 {
82035- ACCESS_ONCE(dev->power.last_busy) = jiffies;
82036+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
82037 }
82038
82039 #else /* !CONFIG_PM_RUNTIME */
82040diff --git a/include/linux/pnp.h b/include/linux/pnp.h
82041index 195aafc..49a7bc2 100644
82042--- a/include/linux/pnp.h
82043+++ b/include/linux/pnp.h
82044@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
82045 struct pnp_fixup {
82046 char id[7];
82047 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
82048-};
82049+} __do_const;
82050
82051 /* config parameters */
82052 #define PNP_CONFIG_NORMAL 0x0001
82053diff --git a/include/linux/poison.h b/include/linux/poison.h
82054index 2110a81..13a11bb 100644
82055--- a/include/linux/poison.h
82056+++ b/include/linux/poison.h
82057@@ -19,8 +19,8 @@
82058 * under normal circumstances, used to verify that nobody uses
82059 * non-initialized list entries.
82060 */
82061-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
82062-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
82063+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
82064+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
82065
82066 /********** include/linux/timer.h **********/
82067 /*
82068diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
82069index d8b187c3..9a9257a 100644
82070--- a/include/linux/power/smartreflex.h
82071+++ b/include/linux/power/smartreflex.h
82072@@ -238,7 +238,7 @@ struct omap_sr_class_data {
82073 int (*notify)(struct omap_sr *sr, u32 status);
82074 u8 notify_flags;
82075 u8 class_type;
82076-};
82077+} __do_const;
82078
82079 /**
82080 * struct omap_sr_nvalue_table - Smartreflex n-target value info
82081diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
82082index 4ea1d37..80f4b33 100644
82083--- a/include/linux/ppp-comp.h
82084+++ b/include/linux/ppp-comp.h
82085@@ -84,7 +84,7 @@ struct compressor {
82086 struct module *owner;
82087 /* Extra skb space needed by the compressor algorithm */
82088 unsigned int comp_extra;
82089-};
82090+} __do_const;
82091
82092 /*
82093 * The return value from decompress routine is the length of the
82094diff --git a/include/linux/preempt.h b/include/linux/preempt.h
82095index de83b4e..c4b997d 100644
82096--- a/include/linux/preempt.h
82097+++ b/include/linux/preempt.h
82098@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
82099 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
82100 #endif
82101
82102+#define raw_preempt_count_add(val) __preempt_count_add(val)
82103+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
82104+
82105 #define __preempt_count_inc() __preempt_count_add(1)
82106 #define __preempt_count_dec() __preempt_count_sub(1)
82107
82108 #define preempt_count_inc() preempt_count_add(1)
82109+#define raw_preempt_count_inc() raw_preempt_count_add(1)
82110 #define preempt_count_dec() preempt_count_sub(1)
82111+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
82112
82113 #ifdef CONFIG_PREEMPT_COUNT
82114
82115@@ -41,6 +46,12 @@ do { \
82116 barrier(); \
82117 } while (0)
82118
82119+#define raw_preempt_disable() \
82120+do { \
82121+ raw_preempt_count_inc(); \
82122+ barrier(); \
82123+} while (0)
82124+
82125 #define sched_preempt_enable_no_resched() \
82126 do { \
82127 barrier(); \
82128@@ -49,6 +60,12 @@ do { \
82129
82130 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
82131
82132+#define raw_preempt_enable_no_resched() \
82133+do { \
82134+ barrier(); \
82135+ raw_preempt_count_dec(); \
82136+} while (0)
82137+
82138 #ifdef CONFIG_PREEMPT
82139 #define preempt_enable() \
82140 do { \
82141@@ -113,8 +130,10 @@ do { \
82142 * region.
82143 */
82144 #define preempt_disable() barrier()
82145+#define raw_preempt_disable() barrier()
82146 #define sched_preempt_enable_no_resched() barrier()
82147 #define preempt_enable_no_resched() barrier()
82148+#define raw_preempt_enable_no_resched() barrier()
82149 #define preempt_enable() barrier()
82150 #define preempt_check_resched() do { } while (0)
82151
82152@@ -128,11 +147,13 @@ do { \
82153 /*
82154 * Modules have no business playing preemption tricks.
82155 */
82156+#ifndef CONFIG_PAX_KERNEXEC
82157 #undef sched_preempt_enable_no_resched
82158 #undef preempt_enable_no_resched
82159 #undef preempt_enable_no_resched_notrace
82160 #undef preempt_check_resched
82161 #endif
82162+#endif
82163
82164 #define preempt_set_need_resched() \
82165 do { \
82166diff --git a/include/linux/printk.h b/include/linux/printk.h
82167index 7847301..29cd406 100644
82168--- a/include/linux/printk.h
82169+++ b/include/linux/printk.h
82170@@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
82171 void early_printk(const char *s, ...) { }
82172 #endif
82173
82174+extern int kptr_restrict;
82175+
82176 #ifdef CONFIG_PRINTK
82177 asmlinkage __printf(5, 0)
82178 int vprintk_emit(int facility, int level,
82179@@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
82180
82181 extern int printk_delay_msec;
82182 extern int dmesg_restrict;
82183-extern int kptr_restrict;
82184
82185 extern void wake_up_klogd(void);
82186
82187diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
82188index 608e60a..79cfb18 100644
82189--- a/include/linux/proc_fs.h
82190+++ b/include/linux/proc_fs.h
82191@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
82192 extern struct proc_dir_entry *proc_symlink(const char *,
82193 struct proc_dir_entry *, const char *);
82194 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
82195+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
82196 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
82197 struct proc_dir_entry *, void *);
82198+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
82199+ struct proc_dir_entry *, void *);
82200 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
82201 struct proc_dir_entry *);
82202
82203@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
82204 return proc_create_data(name, mode, parent, proc_fops, NULL);
82205 }
82206
82207+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
82208+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
82209+{
82210+#ifdef CONFIG_GRKERNSEC_PROC_USER
82211+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
82212+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82213+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
82214+#else
82215+ return proc_create_data(name, mode, parent, proc_fops, NULL);
82216+#endif
82217+}
82218+
82219+
82220 extern void proc_set_size(struct proc_dir_entry *, loff_t);
82221 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
82222 extern void *PDE_DATA(const struct inode *);
82223@@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
82224 struct proc_dir_entry *parent,const char *dest) { return NULL;}
82225 static inline struct proc_dir_entry *proc_mkdir(const char *name,
82226 struct proc_dir_entry *parent) {return NULL;}
82227+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
82228+ struct proc_dir_entry *parent) { return NULL; }
82229 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
82230 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
82231+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
82232+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
82233 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
82234 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
82235 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
82236@@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
82237 static inline struct proc_dir_entry *proc_net_mkdir(
82238 struct net *net, const char *name, struct proc_dir_entry *parent)
82239 {
82240- return proc_mkdir_data(name, 0, parent, net);
82241+ return proc_mkdir_data_restrict(name, 0, parent, net);
82242 }
82243
82244 #endif /* _LINUX_PROC_FS_H */
82245diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
82246index 34a1e10..70f6bde 100644
82247--- a/include/linux/proc_ns.h
82248+++ b/include/linux/proc_ns.h
82249@@ -14,7 +14,7 @@ struct proc_ns_operations {
82250 void (*put)(void *ns);
82251 int (*install)(struct nsproxy *nsproxy, void *ns);
82252 unsigned int (*inum)(void *ns);
82253-};
82254+} __do_const __randomize_layout;
82255
82256 struct proc_ns {
82257 void *ns;
82258diff --git a/include/linux/quota.h b/include/linux/quota.h
82259index cc7494a..1e27036 100644
82260--- a/include/linux/quota.h
82261+++ b/include/linux/quota.h
82262@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
82263
82264 extern bool qid_eq(struct kqid left, struct kqid right);
82265 extern bool qid_lt(struct kqid left, struct kqid right);
82266-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
82267+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
82268 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
82269 extern bool qid_valid(struct kqid qid);
82270
82271diff --git a/include/linux/random.h b/include/linux/random.h
82272index 57fbbff..2170304 100644
82273--- a/include/linux/random.h
82274+++ b/include/linux/random.h
82275@@ -9,9 +9,19 @@
82276 #include <uapi/linux/random.h>
82277
82278 extern void add_device_randomness(const void *, unsigned int);
82279+
82280+static inline void add_latent_entropy(void)
82281+{
82282+
82283+#ifdef LATENT_ENTROPY_PLUGIN
82284+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82285+#endif
82286+
82287+}
82288+
82289 extern void add_input_randomness(unsigned int type, unsigned int code,
82290- unsigned int value);
82291-extern void add_interrupt_randomness(int irq, int irq_flags);
82292+ unsigned int value) __latent_entropy;
82293+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
82294
82295 extern void get_random_bytes(void *buf, int nbytes);
82296 extern void get_random_bytes_arch(void *buf, int nbytes);
82297@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
82298 extern const struct file_operations random_fops, urandom_fops;
82299 #endif
82300
82301-unsigned int get_random_int(void);
82302+unsigned int __intentional_overflow(-1) get_random_int(void);
82303 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
82304
82305-u32 prandom_u32(void);
82306+u32 prandom_u32(void) __intentional_overflow(-1);
82307 void prandom_bytes(void *buf, int nbytes);
82308 void prandom_seed(u32 seed);
82309 void prandom_reseed_late(void);
82310@@ -37,6 +47,11 @@ struct rnd_state {
82311 u32 prandom_u32_state(struct rnd_state *state);
82312 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
82313
82314+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
82315+{
82316+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
82317+}
82318+
82319 /**
82320 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
82321 * @ep_ro: right open interval endpoint
82322@@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
82323 *
82324 * Returns: pseudo-random number in interval [0, ep_ro)
82325 */
82326-static inline u32 prandom_u32_max(u32 ep_ro)
82327+static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
82328 {
82329 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
82330 }
82331diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
82332index fea49b5..2ac22bb 100644
82333--- a/include/linux/rbtree_augmented.h
82334+++ b/include/linux/rbtree_augmented.h
82335@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
82336 old->rbaugmented = rbcompute(old); \
82337 } \
82338 rbstatic const struct rb_augment_callbacks rbname = { \
82339- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
82340+ .propagate = rbname ## _propagate, \
82341+ .copy = rbname ## _copy, \
82342+ .rotate = rbname ## _rotate \
82343 };
82344
82345
82346diff --git a/include/linux/rculist.h b/include/linux/rculist.h
82347index 8183b46..a388711 100644
82348--- a/include/linux/rculist.h
82349+++ b/include/linux/rculist.h
82350@@ -29,8 +29,8 @@
82351 */
82352 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
82353 {
82354- ACCESS_ONCE(list->next) = list;
82355- ACCESS_ONCE(list->prev) = list;
82356+ ACCESS_ONCE_RW(list->next) = list;
82357+ ACCESS_ONCE_RW(list->prev) = list;
82358 }
82359
82360 /*
82361@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
82362 struct list_head *prev, struct list_head *next);
82363 #endif
82364
82365+void __pax_list_add_rcu(struct list_head *new,
82366+ struct list_head *prev, struct list_head *next);
82367+
82368 /**
82369 * list_add_rcu - add a new entry to rcu-protected list
82370 * @new: new entry to be added
82371@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
82372 __list_add_rcu(new, head, head->next);
82373 }
82374
82375+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
82376+{
82377+ __pax_list_add_rcu(new, head, head->next);
82378+}
82379+
82380 /**
82381 * list_add_tail_rcu - add a new entry to rcu-protected list
82382 * @new: new entry to be added
82383@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
82384 __list_add_rcu(new, head->prev, head);
82385 }
82386
82387+static inline void pax_list_add_tail_rcu(struct list_head *new,
82388+ struct list_head *head)
82389+{
82390+ __pax_list_add_rcu(new, head->prev, head);
82391+}
82392+
82393 /**
82394 * list_del_rcu - deletes entry from list without re-initialization
82395 * @entry: the element to delete from the list.
82396@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
82397 entry->prev = LIST_POISON2;
82398 }
82399
82400+extern void pax_list_del_rcu(struct list_head *entry);
82401+
82402 /**
82403 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
82404 * @n: the element to delete from the hash list.
82405diff --git a/include/linux/reboot.h b/include/linux/reboot.h
82406index 48bf152..d38b785 100644
82407--- a/include/linux/reboot.h
82408+++ b/include/linux/reboot.h
82409@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
82410 */
82411
82412 extern void migrate_to_reboot_cpu(void);
82413-extern void machine_restart(char *cmd);
82414-extern void machine_halt(void);
82415-extern void machine_power_off(void);
82416+extern void machine_restart(char *cmd) __noreturn;
82417+extern void machine_halt(void) __noreturn;
82418+extern void machine_power_off(void) __noreturn;
82419
82420 extern void machine_shutdown(void);
82421 struct pt_regs;
82422@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
82423 */
82424
82425 extern void kernel_restart_prepare(char *cmd);
82426-extern void kernel_restart(char *cmd);
82427-extern void kernel_halt(void);
82428-extern void kernel_power_off(void);
82429+extern void kernel_restart(char *cmd) __noreturn;
82430+extern void kernel_halt(void) __noreturn;
82431+extern void kernel_power_off(void) __noreturn;
82432
82433 extern int C_A_D; /* for sysctl */
82434 void ctrl_alt_del(void);
82435@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
82436 * Emergency restart, callable from an interrupt handler.
82437 */
82438
82439-extern void emergency_restart(void);
82440+extern void emergency_restart(void) __noreturn;
82441 #include <asm/emergency-restart.h>
82442
82443 #endif /* _LINUX_REBOOT_H */
82444diff --git a/include/linux/regset.h b/include/linux/regset.h
82445index 8e0c9fe..ac4d221 100644
82446--- a/include/linux/regset.h
82447+++ b/include/linux/regset.h
82448@@ -161,7 +161,8 @@ struct user_regset {
82449 unsigned int align;
82450 unsigned int bias;
82451 unsigned int core_note_type;
82452-};
82453+} __do_const;
82454+typedef struct user_regset __no_const user_regset_no_const;
82455
82456 /**
82457 * struct user_regset_view - available regsets
82458diff --git a/include/linux/relay.h b/include/linux/relay.h
82459index d7c8359..818daf5 100644
82460--- a/include/linux/relay.h
82461+++ b/include/linux/relay.h
82462@@ -157,7 +157,7 @@ struct rchan_callbacks
82463 * The callback should return 0 if successful, negative if not.
82464 */
82465 int (*remove_buf_file)(struct dentry *dentry);
82466-};
82467+} __no_const;
82468
82469 /*
82470 * CONFIG_RELAY kernel API, kernel/relay.c
82471diff --git a/include/linux/rio.h b/include/linux/rio.h
82472index 6bda06f..bf39a9b 100644
82473--- a/include/linux/rio.h
82474+++ b/include/linux/rio.h
82475@@ -358,7 +358,7 @@ struct rio_ops {
82476 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
82477 u64 rstart, u32 size, u32 flags);
82478 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
82479-};
82480+} __no_const;
82481
82482 #define RIO_RESOURCE_MEM 0x00000100
82483 #define RIO_RESOURCE_DOORBELL 0x00000200
82484diff --git a/include/linux/rmap.h b/include/linux/rmap.h
82485index b66c211..13d2915 100644
82486--- a/include/linux/rmap.h
82487+++ b/include/linux/rmap.h
82488@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
82489 void anon_vma_init(void); /* create anon_vma_cachep */
82490 int anon_vma_prepare(struct vm_area_struct *);
82491 void unlink_anon_vmas(struct vm_area_struct *);
82492-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82493-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82494+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82495+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82496
82497 static inline void anon_vma_merge(struct vm_area_struct *vma,
82498 struct vm_area_struct *next)
82499diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
82500index a964f72..b475afb 100644
82501--- a/include/linux/scatterlist.h
82502+++ b/include/linux/scatterlist.h
82503@@ -1,6 +1,7 @@
82504 #ifndef _LINUX_SCATTERLIST_H
82505 #define _LINUX_SCATTERLIST_H
82506
82507+#include <linux/sched.h>
82508 #include <linux/string.h>
82509 #include <linux/bug.h>
82510 #include <linux/mm.h>
82511@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
82512 #ifdef CONFIG_DEBUG_SG
82513 BUG_ON(!virt_addr_valid(buf));
82514 #endif
82515+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82516+ if (object_starts_on_stack(buf)) {
82517+ void *adjbuf = buf - current->stack + current->lowmem_stack;
82518+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
82519+ } else
82520+#endif
82521 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
82522 }
82523
82524diff --git a/include/linux/sched.h b/include/linux/sched.h
82525index 221b2bd..e2e5f82 100644
82526--- a/include/linux/sched.h
82527+++ b/include/linux/sched.h
82528@@ -131,6 +131,7 @@ struct fs_struct;
82529 struct perf_event_context;
82530 struct blk_plug;
82531 struct filename;
82532+struct linux_binprm;
82533
82534 #define VMACACHE_BITS 2
82535 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
82536@@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
82537 extern int in_sched_functions(unsigned long addr);
82538
82539 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82540-extern signed long schedule_timeout(signed long timeout);
82541+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82542 extern signed long schedule_timeout_interruptible(signed long timeout);
82543 extern signed long schedule_timeout_killable(signed long timeout);
82544 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82545@@ -391,6 +392,19 @@ struct nsproxy;
82546 struct user_namespace;
82547
82548 #ifdef CONFIG_MMU
82549+
82550+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82551+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82552+#else
82553+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82554+{
82555+ return 0;
82556+}
82557+#endif
82558+
82559+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82560+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82561+
82562 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82563 extern unsigned long
82564 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82565@@ -688,6 +702,17 @@ struct signal_struct {
82566 #ifdef CONFIG_TASKSTATS
82567 struct taskstats *stats;
82568 #endif
82569+
82570+#ifdef CONFIG_GRKERNSEC
82571+ u32 curr_ip;
82572+ u32 saved_ip;
82573+ u32 gr_saddr;
82574+ u32 gr_daddr;
82575+ u16 gr_sport;
82576+ u16 gr_dport;
82577+ u8 used_accept:1;
82578+#endif
82579+
82580 #ifdef CONFIG_AUDIT
82581 unsigned audit_tty;
82582 unsigned audit_tty_log_passwd;
82583@@ -714,7 +739,7 @@ struct signal_struct {
82584 struct mutex cred_guard_mutex; /* guard against foreign influences on
82585 * credential calculations
82586 * (notably. ptrace) */
82587-};
82588+} __randomize_layout;
82589
82590 /*
82591 * Bits in flags field of signal_struct.
82592@@ -768,6 +793,14 @@ struct user_struct {
82593 struct key *session_keyring; /* UID's default session keyring */
82594 #endif
82595
82596+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82597+ unsigned char kernel_banned;
82598+#endif
82599+#ifdef CONFIG_GRKERNSEC_BRUTE
82600+ unsigned char suid_banned;
82601+ unsigned long suid_ban_expires;
82602+#endif
82603+
82604 /* Hash table maintenance information */
82605 struct hlist_node uidhash_node;
82606 kuid_t uid;
82607@@ -775,7 +808,7 @@ struct user_struct {
82608 #ifdef CONFIG_PERF_EVENTS
82609 atomic_long_t locked_vm;
82610 #endif
82611-};
82612+} __randomize_layout;
82613
82614 extern int uids_sysfs_init(void);
82615
82616@@ -1179,6 +1212,9 @@ enum perf_event_task_context {
82617 struct task_struct {
82618 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
82619 void *stack;
82620+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82621+ void *lowmem_stack;
82622+#endif
82623 atomic_t usage;
82624 unsigned int flags; /* per process flags, defined below */
82625 unsigned int ptrace;
82626@@ -1304,8 +1340,8 @@ struct task_struct {
82627 struct list_head thread_node;
82628
82629 struct completion *vfork_done; /* for vfork() */
82630- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82631- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82632+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82633+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82634
82635 cputime_t utime, stime, utimescaled, stimescaled;
82636 cputime_t gtime;
82637@@ -1330,11 +1366,6 @@ struct task_struct {
82638 struct task_cputime cputime_expires;
82639 struct list_head cpu_timers[3];
82640
82641-/* process credentials */
82642- const struct cred __rcu *real_cred; /* objective and real subjective task
82643- * credentials (COW) */
82644- const struct cred __rcu *cred; /* effective (overridable) subjective task
82645- * credentials (COW) */
82646 char comm[TASK_COMM_LEN]; /* executable name excluding path
82647 - access with [gs]et_task_comm (which lock
82648 it with task_lock())
82649@@ -1351,6 +1382,10 @@ struct task_struct {
82650 #endif
82651 /* CPU-specific state of this task */
82652 struct thread_struct thread;
82653+/* thread_info moved to task_struct */
82654+#ifdef CONFIG_X86
82655+ struct thread_info tinfo;
82656+#endif
82657 /* filesystem information */
82658 struct fs_struct *fs;
82659 /* open file information */
82660@@ -1427,6 +1462,10 @@ struct task_struct {
82661 gfp_t lockdep_reclaim_gfp;
82662 #endif
82663
82664+/* process credentials */
82665+ const struct cred __rcu *real_cred; /* objective and real subjective task
82666+ * credentials (COW) */
82667+
82668 /* journalling filesystem info */
82669 void *journal_info;
82670
82671@@ -1465,6 +1504,10 @@ struct task_struct {
82672 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82673 struct list_head cg_list;
82674 #endif
82675+
82676+ const struct cred __rcu *cred; /* effective (overridable) subjective task
82677+ * credentials (COW) */
82678+
82679 #ifdef CONFIG_FUTEX
82680 struct robust_list_head __user *robust_list;
82681 #ifdef CONFIG_COMPAT
82682@@ -1610,7 +1653,78 @@ struct task_struct {
82683 unsigned int sequential_io;
82684 unsigned int sequential_io_avg;
82685 #endif
82686-};
82687+
82688+#ifdef CONFIG_GRKERNSEC
82689+ /* grsecurity */
82690+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82691+ u64 exec_id;
82692+#endif
82693+#ifdef CONFIG_GRKERNSEC_SETXID
82694+ const struct cred *delayed_cred;
82695+#endif
82696+ struct dentry *gr_chroot_dentry;
82697+ struct acl_subject_label *acl;
82698+ struct acl_subject_label *tmpacl;
82699+ struct acl_role_label *role;
82700+ struct file *exec_file;
82701+ unsigned long brute_expires;
82702+ u16 acl_role_id;
82703+ u8 inherited;
82704+ /* is this the task that authenticated to the special role */
82705+ u8 acl_sp_role;
82706+ u8 is_writable;
82707+ u8 brute;
82708+ u8 gr_is_chrooted;
82709+#endif
82710+
82711+} __randomize_layout;
82712+
82713+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82714+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82715+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82716+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82717+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82718+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82719+
82720+#ifdef CONFIG_PAX_SOFTMODE
82721+extern int pax_softmode;
82722+#endif
82723+
82724+extern int pax_check_flags(unsigned long *);
82725+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82726+
82727+/* if tsk != current then task_lock must be held on it */
82728+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82729+static inline unsigned long pax_get_flags(struct task_struct *tsk)
82730+{
82731+ if (likely(tsk->mm))
82732+ return tsk->mm->pax_flags;
82733+ else
82734+ return 0UL;
82735+}
82736+
82737+/* if tsk != current then task_lock must be held on it */
82738+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82739+{
82740+ if (likely(tsk->mm)) {
82741+ tsk->mm->pax_flags = flags;
82742+ return 0;
82743+ }
82744+ return -EINVAL;
82745+}
82746+#endif
82747+
82748+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82749+extern void pax_set_initial_flags(struct linux_binprm *bprm);
82750+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82751+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82752+#endif
82753+
82754+struct path;
82755+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82756+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82757+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82758+extern void pax_report_refcount_overflow(struct pt_regs *regs);
82759
82760 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82761 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82762@@ -1692,7 +1806,7 @@ struct pid_namespace;
82763 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82764 struct pid_namespace *ns);
82765
82766-static inline pid_t task_pid_nr(struct task_struct *tsk)
82767+static inline pid_t task_pid_nr(const struct task_struct *tsk)
82768 {
82769 return tsk->pid;
82770 }
82771@@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
82772
82773 extern void sched_clock_init(void);
82774
82775+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82776+static inline void populate_stack(void)
82777+{
82778+ struct task_struct *curtask = current;
82779+ int c;
82780+ int *ptr = curtask->stack;
82781+ int *end = curtask->stack + THREAD_SIZE;
82782+
82783+ while (ptr < end) {
82784+ c = *(volatile int *)ptr;
82785+ ptr += PAGE_SIZE/sizeof(int);
82786+ }
82787+}
82788+#else
82789+static inline void populate_stack(void)
82790+{
82791+}
82792+#endif
82793+
82794 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82795 static inline void sched_clock_tick(void)
82796 {
82797@@ -2172,7 +2305,9 @@ void yield(void);
82798 extern struct exec_domain default_exec_domain;
82799
82800 union thread_union {
82801+#ifndef CONFIG_X86
82802 struct thread_info thread_info;
82803+#endif
82804 unsigned long stack[THREAD_SIZE/sizeof(long)];
82805 };
82806
82807@@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82808 */
82809
82810 extern struct task_struct *find_task_by_vpid(pid_t nr);
82811+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82812 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82813 struct pid_namespace *ns);
82814
82815@@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82816 extern void exit_itimers(struct signal_struct *);
82817 extern void flush_itimer_signals(void);
82818
82819-extern void do_group_exit(int);
82820+extern __noreturn void do_group_exit(int);
82821
82822 extern int allow_signal(int);
82823 extern int disallow_signal(int);
82824@@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82825
82826 #endif
82827
82828-static inline int object_is_on_stack(void *obj)
82829+static inline int object_starts_on_stack(const void *obj)
82830 {
82831- void *stack = task_stack_page(current);
82832+ const void *stack = task_stack_page(current);
82833
82834 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82835 }
82836diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82837index 8045a55..c959cd5 100644
82838--- a/include/linux/sched/sysctl.h
82839+++ b/include/linux/sched/sysctl.h
82840@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82841 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82842
82843 extern int sysctl_max_map_count;
82844+extern unsigned long sysctl_heap_stack_gap;
82845
82846 extern unsigned int sysctl_sched_latency;
82847 extern unsigned int sysctl_sched_min_granularity;
82848diff --git a/include/linux/security.h b/include/linux/security.h
82849index 6478ce3..5e6ad6e 100644
82850--- a/include/linux/security.h
82851+++ b/include/linux/security.h
82852@@ -27,6 +27,7 @@
82853 #include <linux/slab.h>
82854 #include <linux/err.h>
82855 #include <linux/string.h>
82856+#include <linux/grsecurity.h>
82857
82858 struct linux_binprm;
82859 struct cred;
82860@@ -116,8 +117,6 @@ struct seq_file;
82861
82862 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82863
82864-void reset_security_ops(void);
82865-
82866 #ifdef CONFIG_MMU
82867 extern unsigned long mmap_min_addr;
82868 extern unsigned long dac_mmap_min_addr;
82869@@ -1719,7 +1718,7 @@ struct security_operations {
82870 struct audit_context *actx);
82871 void (*audit_rule_free) (void *lsmrule);
82872 #endif /* CONFIG_AUDIT */
82873-};
82874+} __randomize_layout;
82875
82876 /* prototypes */
82877 extern int security_init(void);
82878diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82879index dc368b8..e895209 100644
82880--- a/include/linux/semaphore.h
82881+++ b/include/linux/semaphore.h
82882@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82883 }
82884
82885 extern void down(struct semaphore *sem);
82886-extern int __must_check down_interruptible(struct semaphore *sem);
82887+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82888 extern int __must_check down_killable(struct semaphore *sem);
82889 extern int __must_check down_trylock(struct semaphore *sem);
82890 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82891diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82892index 52e0097..383f21d 100644
82893--- a/include/linux/seq_file.h
82894+++ b/include/linux/seq_file.h
82895@@ -27,6 +27,9 @@ struct seq_file {
82896 struct mutex lock;
82897 const struct seq_operations *op;
82898 int poll_event;
82899+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82900+ u64 exec_id;
82901+#endif
82902 #ifdef CONFIG_USER_NS
82903 struct user_namespace *user_ns;
82904 #endif
82905@@ -39,6 +42,7 @@ struct seq_operations {
82906 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82907 int (*show) (struct seq_file *m, void *v);
82908 };
82909+typedef struct seq_operations __no_const seq_operations_no_const;
82910
82911 #define SEQ_SKIP 1
82912
82913@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82914
82915 char *mangle_path(char *s, const char *p, const char *esc);
82916 int seq_open(struct file *, const struct seq_operations *);
82917+int seq_open_restrict(struct file *, const struct seq_operations *);
82918 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82919 loff_t seq_lseek(struct file *, loff_t, int);
82920 int seq_release(struct inode *, struct file *);
82921@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82922 }
82923
82924 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82925+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82926 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82927 int single_release(struct inode *, struct file *);
82928 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82929diff --git a/include/linux/shm.h b/include/linux/shm.h
82930index 1e2cd2e..0288750 100644
82931--- a/include/linux/shm.h
82932+++ b/include/linux/shm.h
82933@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82934
82935 /* The task created the shm object. NULL if the task is dead. */
82936 struct task_struct *shm_creator;
82937+#ifdef CONFIG_GRKERNSEC
82938+ time_t shm_createtime;
82939+ pid_t shm_lapid;
82940+#endif
82941 };
82942
82943 /* shm_mode upper byte flags */
82944diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82945index 08074a8..e2ae280 100644
82946--- a/include/linux/skbuff.h
82947+++ b/include/linux/skbuff.h
82948@@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82949 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82950 int node);
82951 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82952-static inline struct sk_buff *alloc_skb(unsigned int size,
82953+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82954 gfp_t priority)
82955 {
82956 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82957@@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82958 return skb->inner_transport_header - skb->inner_network_header;
82959 }
82960
82961-static inline int skb_network_offset(const struct sk_buff *skb)
82962+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82963 {
82964 return skb_network_header(skb) - skb->data;
82965 }
82966@@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82967 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82968 */
82969 #ifndef NET_SKB_PAD
82970-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82971+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82972 #endif
82973
82974 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82975@@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82976 int *err);
82977 unsigned int datagram_poll(struct file *file, struct socket *sock,
82978 struct poll_table_struct *wait);
82979-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82980+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82981 struct iovec *to, int size);
82982 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82983 struct iovec *iov);
82984@@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82985 nf_bridge_put(skb->nf_bridge);
82986 skb->nf_bridge = NULL;
82987 #endif
82988+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82989+ skb->nf_trace = 0;
82990+#endif
82991 }
82992
82993 static inline void nf_reset_trace(struct sk_buff *skb)
82994diff --git a/include/linux/slab.h b/include/linux/slab.h
82995index 307bfbe..a999cf3 100644
82996--- a/include/linux/slab.h
82997+++ b/include/linux/slab.h
82998@@ -14,15 +14,29 @@
82999 #include <linux/gfp.h>
83000 #include <linux/types.h>
83001 #include <linux/workqueue.h>
83002-
83003+#include <linux/err.h>
83004
83005 /*
83006 * Flags to pass to kmem_cache_create().
83007 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
83008 */
83009 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
83010+
83011+#ifdef CONFIG_PAX_USERCOPY_SLABS
83012+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
83013+#else
83014+#define SLAB_USERCOPY 0x00000000UL
83015+#endif
83016+
83017 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
83018 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
83019+
83020+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83021+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
83022+#else
83023+#define SLAB_NO_SANITIZE 0x00000000UL
83024+#endif
83025+
83026 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
83027 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
83028 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
83029@@ -98,10 +112,13 @@
83030 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
83031 * Both make kfree a no-op.
83032 */
83033-#define ZERO_SIZE_PTR ((void *)16)
83034+#define ZERO_SIZE_PTR \
83035+({ \
83036+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
83037+ (void *)(-MAX_ERRNO-1L); \
83038+})
83039
83040-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
83041- (unsigned long)ZERO_SIZE_PTR)
83042+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
83043
83044 #include <linux/kmemleak.h>
83045
83046@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
83047 void kfree(const void *);
83048 void kzfree(const void *);
83049 size_t ksize(const void *);
83050+const char *check_heap_object(const void *ptr, unsigned long n);
83051+bool is_usercopy_object(const void *ptr);
83052
83053 /*
83054 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
83055@@ -174,7 +193,7 @@ struct kmem_cache {
83056 unsigned int align; /* Alignment as calculated */
83057 unsigned long flags; /* Active flags on the slab */
83058 const char *name; /* Slab name for sysfs */
83059- int refcount; /* Use counter */
83060+ atomic_t refcount; /* Use counter */
83061 void (*ctor)(void *); /* Called on object slot creation */
83062 struct list_head list; /* List of all slab caches on the system */
83063 };
83064@@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
83065 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
83066 #endif
83067
83068+#ifdef CONFIG_PAX_USERCOPY_SLABS
83069+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
83070+#endif
83071+
83072 /*
83073 * Figure out which kmalloc slab an allocation of a certain size
83074 * belongs to.
83075@@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
83076 * 2 = 120 .. 192 bytes
83077 * n = 2^(n-1) .. 2^n -1
83078 */
83079-static __always_inline int kmalloc_index(size_t size)
83080+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
83081 {
83082 if (!size)
83083 return 0;
83084@@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
83085 }
83086 #endif /* !CONFIG_SLOB */
83087
83088-void *__kmalloc(size_t size, gfp_t flags);
83089+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
83090 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
83091
83092 #ifdef CONFIG_NUMA
83093-void *__kmalloc_node(size_t size, gfp_t flags, int node);
83094+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
83095 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
83096 #else
83097 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
83098diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
83099index 8235dfb..47ce586 100644
83100--- a/include/linux/slab_def.h
83101+++ b/include/linux/slab_def.h
83102@@ -38,7 +38,7 @@ struct kmem_cache {
83103 /* 4) cache creation/removal */
83104 const char *name;
83105 struct list_head list;
83106- int refcount;
83107+ atomic_t refcount;
83108 int object_size;
83109 int align;
83110
83111@@ -54,10 +54,14 @@ struct kmem_cache {
83112 unsigned long node_allocs;
83113 unsigned long node_frees;
83114 unsigned long node_overflow;
83115- atomic_t allochit;
83116- atomic_t allocmiss;
83117- atomic_t freehit;
83118- atomic_t freemiss;
83119+ atomic_unchecked_t allochit;
83120+ atomic_unchecked_t allocmiss;
83121+ atomic_unchecked_t freehit;
83122+ atomic_unchecked_t freemiss;
83123+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83124+ atomic_unchecked_t sanitized;
83125+ atomic_unchecked_t not_sanitized;
83126+#endif
83127
83128 /*
83129 * If debugging is enabled, then the allocator can add additional
83130diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
83131index d82abd4..408c3a0 100644
83132--- a/include/linux/slub_def.h
83133+++ b/include/linux/slub_def.h
83134@@ -74,7 +74,7 @@ struct kmem_cache {
83135 struct kmem_cache_order_objects max;
83136 struct kmem_cache_order_objects min;
83137 gfp_t allocflags; /* gfp flags to use on each alloc */
83138- int refcount; /* Refcount for slab cache destroy */
83139+ atomic_t refcount; /* Refcount for slab cache destroy */
83140 void (*ctor)(void *);
83141 int inuse; /* Offset to metadata */
83142 int align; /* Alignment */
83143diff --git a/include/linux/smp.h b/include/linux/smp.h
83144index 633f5ed..6c3dc3f 100644
83145--- a/include/linux/smp.h
83146+++ b/include/linux/smp.h
83147@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
83148 #endif
83149
83150 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
83151+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
83152 #define put_cpu() preempt_enable()
83153+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
83154
83155 /*
83156 * Callback to arch code if there's nosmp or maxcpus=0 on the
83157diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
83158index 46cca4c..3323536 100644
83159--- a/include/linux/sock_diag.h
83160+++ b/include/linux/sock_diag.h
83161@@ -11,7 +11,7 @@ struct sock;
83162 struct sock_diag_handler {
83163 __u8 family;
83164 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
83165-};
83166+} __do_const;
83167
83168 int sock_diag_register(const struct sock_diag_handler *h);
83169 void sock_diag_unregister(const struct sock_diag_handler *h);
83170diff --git a/include/linux/sonet.h b/include/linux/sonet.h
83171index 680f9a3..f13aeb0 100644
83172--- a/include/linux/sonet.h
83173+++ b/include/linux/sonet.h
83174@@ -7,7 +7,7 @@
83175 #include <uapi/linux/sonet.h>
83176
83177 struct k_sonet_stats {
83178-#define __HANDLE_ITEM(i) atomic_t i
83179+#define __HANDLE_ITEM(i) atomic_unchecked_t i
83180 __SONET_ITEMS
83181 #undef __HANDLE_ITEM
83182 };
83183diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
83184index 07d8e53..dc934c9 100644
83185--- a/include/linux/sunrpc/addr.h
83186+++ b/include/linux/sunrpc/addr.h
83187@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
83188 {
83189 switch (sap->sa_family) {
83190 case AF_INET:
83191- return ntohs(((struct sockaddr_in *)sap)->sin_port);
83192+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
83193 case AF_INET6:
83194- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
83195+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
83196 }
83197 return 0;
83198 }
83199@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
83200 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
83201 const struct sockaddr *src)
83202 {
83203- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
83204+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
83205 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
83206
83207 dsin->sin_family = ssin->sin_family;
83208@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
83209 if (sa->sa_family != AF_INET6)
83210 return 0;
83211
83212- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
83213+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
83214 }
83215
83216 #endif /* _LINUX_SUNRPC_ADDR_H */
83217diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
83218index 70736b9..37f33db 100644
83219--- a/include/linux/sunrpc/clnt.h
83220+++ b/include/linux/sunrpc/clnt.h
83221@@ -97,7 +97,7 @@ struct rpc_procinfo {
83222 unsigned int p_timer; /* Which RTT timer to use */
83223 u32 p_statidx; /* Which procedure to account */
83224 const char * p_name; /* name of procedure */
83225-};
83226+} __do_const;
83227
83228 #ifdef __KERNEL__
83229
83230diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
83231index 04e7632..2e2a8a3 100644
83232--- a/include/linux/sunrpc/svc.h
83233+++ b/include/linux/sunrpc/svc.h
83234@@ -412,7 +412,7 @@ struct svc_procedure {
83235 unsigned int pc_count; /* call count */
83236 unsigned int pc_cachetype; /* cache info (NFS) */
83237 unsigned int pc_xdrressize; /* maximum size of XDR reply */
83238-};
83239+} __do_const;
83240
83241 /*
83242 * Function prototypes.
83243diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
83244index 0b8e3e6..33e0a01 100644
83245--- a/include/linux/sunrpc/svc_rdma.h
83246+++ b/include/linux/sunrpc/svc_rdma.h
83247@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
83248 extern unsigned int svcrdma_max_requests;
83249 extern unsigned int svcrdma_max_req_size;
83250
83251-extern atomic_t rdma_stat_recv;
83252-extern atomic_t rdma_stat_read;
83253-extern atomic_t rdma_stat_write;
83254-extern atomic_t rdma_stat_sq_starve;
83255-extern atomic_t rdma_stat_rq_starve;
83256-extern atomic_t rdma_stat_rq_poll;
83257-extern atomic_t rdma_stat_rq_prod;
83258-extern atomic_t rdma_stat_sq_poll;
83259-extern atomic_t rdma_stat_sq_prod;
83260+extern atomic_unchecked_t rdma_stat_recv;
83261+extern atomic_unchecked_t rdma_stat_read;
83262+extern atomic_unchecked_t rdma_stat_write;
83263+extern atomic_unchecked_t rdma_stat_sq_starve;
83264+extern atomic_unchecked_t rdma_stat_rq_starve;
83265+extern atomic_unchecked_t rdma_stat_rq_poll;
83266+extern atomic_unchecked_t rdma_stat_rq_prod;
83267+extern atomic_unchecked_t rdma_stat_sq_poll;
83268+extern atomic_unchecked_t rdma_stat_sq_prod;
83269
83270 #define RPCRDMA_VERSION 1
83271
83272diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
83273index 8d71d65..f79586e 100644
83274--- a/include/linux/sunrpc/svcauth.h
83275+++ b/include/linux/sunrpc/svcauth.h
83276@@ -120,7 +120,7 @@ struct auth_ops {
83277 int (*release)(struct svc_rqst *rq);
83278 void (*domain_release)(struct auth_domain *);
83279 int (*set_client)(struct svc_rqst *rq);
83280-};
83281+} __do_const;
83282
83283 #define SVC_GARBAGE 1
83284 #define SVC_SYSERR 2
83285diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
83286index a5ffd32..0935dea 100644
83287--- a/include/linux/swiotlb.h
83288+++ b/include/linux/swiotlb.h
83289@@ -60,7 +60,8 @@ extern void
83290
83291 extern void
83292 swiotlb_free_coherent(struct device *hwdev, size_t size,
83293- void *vaddr, dma_addr_t dma_handle);
83294+ void *vaddr, dma_addr_t dma_handle,
83295+ struct dma_attrs *attrs);
83296
83297 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
83298 unsigned long offset, size_t size,
83299diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
83300index a4a0588..752870e 100644
83301--- a/include/linux/syscalls.h
83302+++ b/include/linux/syscalls.h
83303@@ -98,10 +98,16 @@ struct sigaltstack;
83304 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
83305
83306 #define __SC_DECL(t, a) t a
83307+#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))
83308 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
83309 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
83310 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
83311-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
83312+#define __SC_LONG(t, a) __typeof( \
83313+ __builtin_choose_expr( \
83314+ sizeof(t) > sizeof(int), \
83315+ (t) 0, \
83316+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
83317+ )) a
83318 #define __SC_CAST(t, a) (t) a
83319 #define __SC_ARGS(t, a) a
83320 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
83321@@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
83322 asmlinkage long sys_fsync(unsigned int fd);
83323 asmlinkage long sys_fdatasync(unsigned int fd);
83324 asmlinkage long sys_bdflush(int func, long data);
83325-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
83326- char __user *type, unsigned long flags,
83327+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
83328+ const char __user *type, unsigned long flags,
83329 void __user *data);
83330-asmlinkage long sys_umount(char __user *name, int flags);
83331-asmlinkage long sys_oldumount(char __user *name);
83332+asmlinkage long sys_umount(const char __user *name, int flags);
83333+asmlinkage long sys_oldumount(const char __user *name);
83334 asmlinkage long sys_truncate(const char __user *path, long length);
83335 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
83336 asmlinkage long sys_stat(const char __user *filename,
83337@@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
83338 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
83339 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
83340 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
83341- struct sockaddr __user *, int);
83342+ struct sockaddr __user *, int) __intentional_overflow(0);
83343 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
83344 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
83345 unsigned int vlen, unsigned flags);
83346diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
83347index 27b3b0b..e093dd9 100644
83348--- a/include/linux/syscore_ops.h
83349+++ b/include/linux/syscore_ops.h
83350@@ -16,7 +16,7 @@ struct syscore_ops {
83351 int (*suspend)(void);
83352 void (*resume)(void);
83353 void (*shutdown)(void);
83354-};
83355+} __do_const;
83356
83357 extern void register_syscore_ops(struct syscore_ops *ops);
83358 extern void unregister_syscore_ops(struct syscore_ops *ops);
83359diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
83360index 14a8ff2..fa95f3a 100644
83361--- a/include/linux/sysctl.h
83362+++ b/include/linux/sysctl.h
83363@@ -34,13 +34,13 @@ struct ctl_table_root;
83364 struct ctl_table_header;
83365 struct ctl_dir;
83366
83367-typedef struct ctl_table ctl_table;
83368-
83369 typedef int proc_handler (struct ctl_table *ctl, int write,
83370 void __user *buffer, size_t *lenp, loff_t *ppos);
83371
83372 extern int proc_dostring(struct ctl_table *, int,
83373 void __user *, size_t *, loff_t *);
83374+extern int proc_dostring_modpriv(struct ctl_table *, int,
83375+ void __user *, size_t *, loff_t *);
83376 extern int proc_dointvec(struct ctl_table *, int,
83377 void __user *, size_t *, loff_t *);
83378 extern int proc_dointvec_minmax(struct ctl_table *, int,
83379@@ -115,7 +115,9 @@ struct ctl_table
83380 struct ctl_table_poll *poll;
83381 void *extra1;
83382 void *extra2;
83383-};
83384+} __do_const __randomize_layout;
83385+typedef struct ctl_table __no_const ctl_table_no_const;
83386+typedef struct ctl_table ctl_table;
83387
83388 struct ctl_node {
83389 struct rb_node node;
83390diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
83391index 5ffaa34..fe3e31c 100644
83392--- a/include/linux/sysfs.h
83393+++ b/include/linux/sysfs.h
83394@@ -34,7 +34,8 @@ struct attribute {
83395 struct lock_class_key *key;
83396 struct lock_class_key skey;
83397 #endif
83398-};
83399+} __do_const;
83400+typedef struct attribute __no_const attribute_no_const;
83401
83402 /**
83403 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
83404@@ -63,7 +64,8 @@ struct attribute_group {
83405 struct attribute *, int);
83406 struct attribute **attrs;
83407 struct bin_attribute **bin_attrs;
83408-};
83409+} __do_const;
83410+typedef struct attribute_group __no_const attribute_group_no_const;
83411
83412 /**
83413 * Use these macros to make defining attributes easier. See include/linux/device.h
83414@@ -128,7 +130,8 @@ struct bin_attribute {
83415 char *, loff_t, size_t);
83416 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
83417 struct vm_area_struct *vma);
83418-};
83419+} __do_const;
83420+typedef struct bin_attribute __no_const bin_attribute_no_const;
83421
83422 /**
83423 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
83424diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
83425index 387fa7d..3fcde6b 100644
83426--- a/include/linux/sysrq.h
83427+++ b/include/linux/sysrq.h
83428@@ -16,6 +16,7 @@
83429
83430 #include <linux/errno.h>
83431 #include <linux/types.h>
83432+#include <linux/compiler.h>
83433
83434 /* Possible values of bitmask for enabling sysrq functions */
83435 /* 0x0001 is reserved for enable everything */
83436@@ -33,7 +34,7 @@ struct sysrq_key_op {
83437 char *help_msg;
83438 char *action_msg;
83439 int enable_mask;
83440-};
83441+} __do_const;
83442
83443 #ifdef CONFIG_MAGIC_SYSRQ
83444
83445diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
83446index fddbe20..a0e76ab 100644
83447--- a/include/linux/thread_info.h
83448+++ b/include/linux/thread_info.h
83449@@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
83450 #error "no set_restore_sigmask() provided and default one won't work"
83451 #endif
83452
83453+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
83454+
83455+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
83456+{
83457+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
83458+}
83459+
83460 #endif /* __KERNEL__ */
83461
83462 #endif /* _LINUX_THREAD_INFO_H */
83463diff --git a/include/linux/tty.h b/include/linux/tty.h
83464index 1c3316a..ae83b9f 100644
83465--- a/include/linux/tty.h
83466+++ b/include/linux/tty.h
83467@@ -202,7 +202,7 @@ struct tty_port {
83468 const struct tty_port_operations *ops; /* Port operations */
83469 spinlock_t lock; /* Lock protecting tty field */
83470 int blocked_open; /* Waiting to open */
83471- int count; /* Usage count */
83472+ atomic_t count; /* Usage count */
83473 wait_queue_head_t open_wait; /* Open waiters */
83474 wait_queue_head_t close_wait; /* Close waiters */
83475 wait_queue_head_t delta_msr_wait; /* Modem status change */
83476@@ -284,7 +284,7 @@ struct tty_struct {
83477 /* If the tty has a pending do_SAK, queue it here - akpm */
83478 struct work_struct SAK_work;
83479 struct tty_port *port;
83480-};
83481+} __randomize_layout;
83482
83483 /* Each of a tty's open files has private_data pointing to tty_file_private */
83484 struct tty_file_private {
83485@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
83486 struct tty_struct *tty, struct file *filp);
83487 static inline int tty_port_users(struct tty_port *port)
83488 {
83489- return port->count + port->blocked_open;
83490+ return atomic_read(&port->count) + port->blocked_open;
83491 }
83492
83493 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
83494diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
83495index 756a609..89db85e 100644
83496--- a/include/linux/tty_driver.h
83497+++ b/include/linux/tty_driver.h
83498@@ -285,7 +285,7 @@ struct tty_operations {
83499 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
83500 #endif
83501 const struct file_operations *proc_fops;
83502-};
83503+} __do_const __randomize_layout;
83504
83505 struct tty_driver {
83506 int magic; /* magic number for this structure */
83507@@ -319,7 +319,7 @@ struct tty_driver {
83508
83509 const struct tty_operations *ops;
83510 struct list_head tty_drivers;
83511-};
83512+} __randomize_layout;
83513
83514 extern struct list_head tty_drivers;
83515
83516diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
83517index add26da..22c00bef 100644
83518--- a/include/linux/tty_ldisc.h
83519+++ b/include/linux/tty_ldisc.h
83520@@ -212,7 +212,7 @@ struct tty_ldisc_ops {
83521
83522 struct module *owner;
83523
83524- int refcount;
83525+ atomic_t refcount;
83526 };
83527
83528 struct tty_ldisc {
83529diff --git a/include/linux/types.h b/include/linux/types.h
83530index 4d118ba..c3ee9bf 100644
83531--- a/include/linux/types.h
83532+++ b/include/linux/types.h
83533@@ -176,10 +176,26 @@ typedef struct {
83534 int counter;
83535 } atomic_t;
83536
83537+#ifdef CONFIG_PAX_REFCOUNT
83538+typedef struct {
83539+ int counter;
83540+} atomic_unchecked_t;
83541+#else
83542+typedef atomic_t atomic_unchecked_t;
83543+#endif
83544+
83545 #ifdef CONFIG_64BIT
83546 typedef struct {
83547 long counter;
83548 } atomic64_t;
83549+
83550+#ifdef CONFIG_PAX_REFCOUNT
83551+typedef struct {
83552+ long counter;
83553+} atomic64_unchecked_t;
83554+#else
83555+typedef atomic64_t atomic64_unchecked_t;
83556+#endif
83557 #endif
83558
83559 struct list_head {
83560diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83561index ecd3319..8a36ded 100644
83562--- a/include/linux/uaccess.h
83563+++ b/include/linux/uaccess.h
83564@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83565 long ret; \
83566 mm_segment_t old_fs = get_fs(); \
83567 \
83568- set_fs(KERNEL_DS); \
83569 pagefault_disable(); \
83570- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83571- pagefault_enable(); \
83572+ set_fs(KERNEL_DS); \
83573+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83574 set_fs(old_fs); \
83575+ pagefault_enable(); \
83576 ret; \
83577 })
83578
83579diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83580index 2d1f9b6..d7a9fce 100644
83581--- a/include/linux/uidgid.h
83582+++ b/include/linux/uidgid.h
83583@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83584
83585 #endif /* CONFIG_USER_NS */
83586
83587+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83588+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83589+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83590+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83591+
83592 #endif /* _LINUX_UIDGID_H */
83593diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83594index 99c1b4d..562e6f3 100644
83595--- a/include/linux/unaligned/access_ok.h
83596+++ b/include/linux/unaligned/access_ok.h
83597@@ -4,34 +4,34 @@
83598 #include <linux/kernel.h>
83599 #include <asm/byteorder.h>
83600
83601-static inline u16 get_unaligned_le16(const void *p)
83602+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83603 {
83604- return le16_to_cpup((__le16 *)p);
83605+ return le16_to_cpup((const __le16 *)p);
83606 }
83607
83608-static inline u32 get_unaligned_le32(const void *p)
83609+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83610 {
83611- return le32_to_cpup((__le32 *)p);
83612+ return le32_to_cpup((const __le32 *)p);
83613 }
83614
83615-static inline u64 get_unaligned_le64(const void *p)
83616+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83617 {
83618- return le64_to_cpup((__le64 *)p);
83619+ return le64_to_cpup((const __le64 *)p);
83620 }
83621
83622-static inline u16 get_unaligned_be16(const void *p)
83623+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83624 {
83625- return be16_to_cpup((__be16 *)p);
83626+ return be16_to_cpup((const __be16 *)p);
83627 }
83628
83629-static inline u32 get_unaligned_be32(const void *p)
83630+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83631 {
83632- return be32_to_cpup((__be32 *)p);
83633+ return be32_to_cpup((const __be32 *)p);
83634 }
83635
83636-static inline u64 get_unaligned_be64(const void *p)
83637+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83638 {
83639- return be64_to_cpup((__be64 *)p);
83640+ return be64_to_cpup((const __be64 *)p);
83641 }
83642
83643 static inline void put_unaligned_le16(u16 val, void *p)
83644diff --git a/include/linux/usb.h b/include/linux/usb.h
83645index 6b7ec37..4428419 100644
83646--- a/include/linux/usb.h
83647+++ b/include/linux/usb.h
83648@@ -569,7 +569,7 @@ struct usb_device {
83649 int maxchild;
83650
83651 u32 quirks;
83652- atomic_t urbnum;
83653+ atomic_unchecked_t urbnum;
83654
83655 unsigned long active_duration;
83656
83657@@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83658
83659 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83660 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83661- void *data, __u16 size, int timeout);
83662+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
83663 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83664 void *data, int len, int *actual_length, int timeout);
83665 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83666diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83667index e452ba6..78f8e80 100644
83668--- a/include/linux/usb/renesas_usbhs.h
83669+++ b/include/linux/usb/renesas_usbhs.h
83670@@ -39,7 +39,7 @@ enum {
83671 */
83672 struct renesas_usbhs_driver_callback {
83673 int (*notify_hotplug)(struct platform_device *pdev);
83674-};
83675+} __no_const;
83676
83677 /*
83678 * callback functions for platform
83679diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83680index 4836ba3..603f6ee 100644
83681--- a/include/linux/user_namespace.h
83682+++ b/include/linux/user_namespace.h
83683@@ -33,7 +33,7 @@ struct user_namespace {
83684 struct key *persistent_keyring_register;
83685 struct rw_semaphore persistent_keyring_register_sem;
83686 #endif
83687-};
83688+} __randomize_layout;
83689
83690 extern struct user_namespace init_user_ns;
83691
83692diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83693index 239e277..22a5cf5 100644
83694--- a/include/linux/utsname.h
83695+++ b/include/linux/utsname.h
83696@@ -24,7 +24,7 @@ struct uts_namespace {
83697 struct new_utsname name;
83698 struct user_namespace *user_ns;
83699 unsigned int proc_inum;
83700-};
83701+} __randomize_layout;
83702 extern struct uts_namespace init_uts_ns;
83703
83704 #ifdef CONFIG_UTS_NS
83705diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83706index 6f8fbcf..4efc177 100644
83707--- a/include/linux/vermagic.h
83708+++ b/include/linux/vermagic.h
83709@@ -25,9 +25,42 @@
83710 #define MODULE_ARCH_VERMAGIC ""
83711 #endif
83712
83713+#ifdef CONFIG_PAX_REFCOUNT
83714+#define MODULE_PAX_REFCOUNT "REFCOUNT "
83715+#else
83716+#define MODULE_PAX_REFCOUNT ""
83717+#endif
83718+
83719+#ifdef CONSTIFY_PLUGIN
83720+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83721+#else
83722+#define MODULE_CONSTIFY_PLUGIN ""
83723+#endif
83724+
83725+#ifdef STACKLEAK_PLUGIN
83726+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83727+#else
83728+#define MODULE_STACKLEAK_PLUGIN ""
83729+#endif
83730+
83731+#ifdef RANDSTRUCT_PLUGIN
83732+#include <generated/randomize_layout_hash.h>
83733+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83734+#else
83735+#define MODULE_RANDSTRUCT_PLUGIN
83736+#endif
83737+
83738+#ifdef CONFIG_GRKERNSEC
83739+#define MODULE_GRSEC "GRSEC "
83740+#else
83741+#define MODULE_GRSEC ""
83742+#endif
83743+
83744 #define VERMAGIC_STRING \
83745 UTS_RELEASE " " \
83746 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83747 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83748- MODULE_ARCH_VERMAGIC
83749+ MODULE_ARCH_VERMAGIC \
83750+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83751+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83752
83753diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83754index 502073a..a7de024 100644
83755--- a/include/linux/vga_switcheroo.h
83756+++ b/include/linux/vga_switcheroo.h
83757@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83758
83759 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83760
83761-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83762-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83763+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83764+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83765 #else
83766
83767 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83768@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83769
83770 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83771
83772-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83773-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83774+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83775+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83776
83777 #endif
83778 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83779diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83780index 4b8a891..e9a2863 100644
83781--- a/include/linux/vmalloc.h
83782+++ b/include/linux/vmalloc.h
83783@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83784 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83785 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83786 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83787+
83788+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83789+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83790+#endif
83791+
83792 /* bits [20..32] reserved for arch specific ioremap internals */
83793
83794 /*
83795@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
83796 unsigned long flags, pgprot_t prot);
83797 extern void vunmap(const void *addr);
83798
83799+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83800+extern void unmap_process_stacks(struct task_struct *task);
83801+#endif
83802+
83803 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83804 unsigned long uaddr, void *kaddr,
83805 unsigned long size);
83806@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83807
83808 /* for /dev/kmem */
83809 extern long vread(char *buf, char *addr, unsigned long count);
83810-extern long vwrite(char *buf, char *addr, unsigned long count);
83811+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83812
83813 /*
83814 * Internals. Dont't use..
83815diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83816index 45c9cd1..20bd0bf 100644
83817--- a/include/linux/vmstat.h
83818+++ b/include/linux/vmstat.h
83819@@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83820 /*
83821 * Zone based page accounting with per cpu differentials.
83822 */
83823-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83824+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83825
83826 static inline void zone_page_state_add(long x, struct zone *zone,
83827 enum zone_stat_item item)
83828 {
83829- atomic_long_add(x, &zone->vm_stat[item]);
83830- atomic_long_add(x, &vm_stat[item]);
83831+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83832+ atomic_long_add_unchecked(x, &vm_stat[item]);
83833 }
83834
83835-static inline unsigned long global_page_state(enum zone_stat_item item)
83836+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83837 {
83838- long x = atomic_long_read(&vm_stat[item]);
83839+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83840 #ifdef CONFIG_SMP
83841 if (x < 0)
83842 x = 0;
83843@@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83844 return x;
83845 }
83846
83847-static inline unsigned long zone_page_state(struct zone *zone,
83848+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83849 enum zone_stat_item item)
83850 {
83851- long x = atomic_long_read(&zone->vm_stat[item]);
83852+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83853 #ifdef CONFIG_SMP
83854 if (x < 0)
83855 x = 0;
83856@@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83857 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83858 enum zone_stat_item item)
83859 {
83860- long x = atomic_long_read(&zone->vm_stat[item]);
83861+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83862
83863 #ifdef CONFIG_SMP
83864 int cpu;
83865@@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83866
83867 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83868 {
83869- atomic_long_inc(&zone->vm_stat[item]);
83870- atomic_long_inc(&vm_stat[item]);
83871+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83872+ atomic_long_inc_unchecked(&vm_stat[item]);
83873 }
83874
83875 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83876 {
83877- atomic_long_dec(&zone->vm_stat[item]);
83878- atomic_long_dec(&vm_stat[item]);
83879+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83880+ atomic_long_dec_unchecked(&vm_stat[item]);
83881 }
83882
83883 static inline void __inc_zone_page_state(struct page *page,
83884diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83885index 91b0a68..0e9adf6 100644
83886--- a/include/linux/xattr.h
83887+++ b/include/linux/xattr.h
83888@@ -28,7 +28,7 @@ struct xattr_handler {
83889 size_t size, int handler_flags);
83890 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83891 size_t size, int flags, int handler_flags);
83892-};
83893+} __do_const;
83894
83895 struct xattr {
83896 const char *name;
83897@@ -37,6 +37,9 @@ struct xattr {
83898 };
83899
83900 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83901+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83902+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83903+#endif
83904 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83905 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83906 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83907diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83908index 9c5a6b4..09c9438 100644
83909--- a/include/linux/zlib.h
83910+++ b/include/linux/zlib.h
83911@@ -31,6 +31,7 @@
83912 #define _ZLIB_H
83913
83914 #include <linux/zconf.h>
83915+#include <linux/compiler.h>
83916
83917 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83918 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83919@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83920
83921 /* basic functions */
83922
83923-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83924+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83925 /*
83926 Returns the number of bytes that needs to be allocated for a per-
83927 stream workspace with the specified parameters. A pointer to this
83928diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83929index eec6e46..82d5641 100644
83930--- a/include/media/v4l2-dev.h
83931+++ b/include/media/v4l2-dev.h
83932@@ -77,7 +77,7 @@ struct v4l2_file_operations {
83933 int (*mmap) (struct file *, struct vm_area_struct *);
83934 int (*open) (struct file *);
83935 int (*release) (struct file *);
83936-};
83937+} __do_const;
83938
83939 /*
83940 * Newer version of video_device, handled by videodev2.c
83941diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83942index c9b1593..a572459 100644
83943--- a/include/media/v4l2-device.h
83944+++ b/include/media/v4l2-device.h
83945@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83946 this function returns 0. If the name ends with a digit (e.g. cx18),
83947 then the name will be set to cx18-0 since cx180 looks really odd. */
83948 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83949- atomic_t *instance);
83950+ atomic_unchecked_t *instance);
83951
83952 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83953 Since the parent disappears this ensures that v4l2_dev doesn't have an
83954diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83955index d9fa68f..45c88d1 100644
83956--- a/include/net/9p/transport.h
83957+++ b/include/net/9p/transport.h
83958@@ -63,7 +63,7 @@ struct p9_trans_module {
83959 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83960 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83961 char *, char *, int , int, int, int);
83962-};
83963+} __do_const;
83964
83965 void v9fs_register_trans(struct p9_trans_module *m);
83966 void v9fs_unregister_trans(struct p9_trans_module *m);
83967diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83968index a175ba4..196eb82 100644
83969--- a/include/net/af_unix.h
83970+++ b/include/net/af_unix.h
83971@@ -36,7 +36,7 @@ struct unix_skb_parms {
83972 u32 secid; /* Security ID */
83973 #endif
83974 u32 consumed;
83975-};
83976+} __randomize_layout;
83977
83978 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83979 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83980diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83981index 4abdcb2..945c5cc 100644
83982--- a/include/net/bluetooth/l2cap.h
83983+++ b/include/net/bluetooth/l2cap.h
83984@@ -601,7 +601,7 @@ struct l2cap_ops {
83985 long (*get_sndtimeo) (struct l2cap_chan *chan);
83986 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83987 unsigned long len, int nb);
83988-};
83989+} __do_const;
83990
83991 struct l2cap_conn {
83992 struct hci_conn *hcon;
83993diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83994index f2ae33d..c457cf0 100644
83995--- a/include/net/caif/cfctrl.h
83996+++ b/include/net/caif/cfctrl.h
83997@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83998 void (*radioset_rsp)(void);
83999 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
84000 struct cflayer *client_layer);
84001-};
84002+} __no_const;
84003
84004 /* Link Setup Parameters for CAIF-Links. */
84005 struct cfctrl_link_param {
84006@@ -101,8 +101,8 @@ struct cfctrl_request_info {
84007 struct cfctrl {
84008 struct cfsrvl serv;
84009 struct cfctrl_rsp res;
84010- atomic_t req_seq_no;
84011- atomic_t rsp_seq_no;
84012+ atomic_unchecked_t req_seq_no;
84013+ atomic_unchecked_t rsp_seq_no;
84014 struct list_head list;
84015 /* Protects from simultaneous access to first_req list */
84016 spinlock_t info_list_lock;
84017diff --git a/include/net/flow.h b/include/net/flow.h
84018index 8109a15..504466d 100644
84019--- a/include/net/flow.h
84020+++ b/include/net/flow.h
84021@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
84022
84023 void flow_cache_flush(struct net *net);
84024 void flow_cache_flush_deferred(struct net *net);
84025-extern atomic_t flow_cache_genid;
84026+extern atomic_unchecked_t flow_cache_genid;
84027
84028 #endif
84029diff --git a/include/net/genetlink.h b/include/net/genetlink.h
84030index 93695f0..766d71c 100644
84031--- a/include/net/genetlink.h
84032+++ b/include/net/genetlink.h
84033@@ -120,7 +120,7 @@ struct genl_ops {
84034 u8 cmd;
84035 u8 internal_flags;
84036 u8 flags;
84037-};
84038+} __do_const;
84039
84040 int __genl_register_family(struct genl_family *family);
84041
84042diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
84043index 734d9b5..48a9a4b 100644
84044--- a/include/net/gro_cells.h
84045+++ b/include/net/gro_cells.h
84046@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
84047 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
84048
84049 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
84050- atomic_long_inc(&dev->rx_dropped);
84051+ atomic_long_inc_unchecked(&dev->rx_dropped);
84052 kfree_skb(skb);
84053 return;
84054 }
84055diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
84056index 7a43138..bc76865 100644
84057--- a/include/net/inet_connection_sock.h
84058+++ b/include/net/inet_connection_sock.h
84059@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
84060 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
84061 int (*bind_conflict)(const struct sock *sk,
84062 const struct inet_bind_bucket *tb, bool relax);
84063-};
84064+} __do_const;
84065
84066 /** inet_connection_sock - INET connection oriented sock
84067 *
84068diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
84069index 823ec7b..1af4453 100644
84070--- a/include/net/inetpeer.h
84071+++ b/include/net/inetpeer.h
84072@@ -47,7 +47,7 @@ struct inet_peer {
84073 */
84074 union {
84075 struct {
84076- atomic_t rid; /* Frag reception counter */
84077+ atomic_unchecked_t rid; /* Frag reception counter */
84078 };
84079 struct rcu_head rcu;
84080 struct inet_peer *gc_next;
84081diff --git a/include/net/ip.h b/include/net/ip.h
84082index 54de029..6a28064 100644
84083--- a/include/net/ip.h
84084+++ b/include/net/ip.h
84085@@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
84086
84087 void inet_get_local_port_range(struct net *net, int *low, int *high);
84088
84089-extern unsigned long *sysctl_local_reserved_ports;
84090+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
84091 static inline int inet_is_reserved_local_port(int port)
84092 {
84093 return test_bit(port, sysctl_local_reserved_ports);
84094@@ -310,7 +310,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
84095 }
84096 }
84097
84098-u32 ip_idents_reserve(u32 hash, int segs);
84099+u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
84100 void __ip_select_ident(struct iphdr *iph, int segs);
84101
84102 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
84103diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
84104index 9922093..a1755d6 100644
84105--- a/include/net/ip_fib.h
84106+++ b/include/net/ip_fib.h
84107@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
84108
84109 #define FIB_RES_SADDR(net, res) \
84110 ((FIB_RES_NH(res).nh_saddr_genid == \
84111- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
84112+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
84113 FIB_RES_NH(res).nh_saddr : \
84114 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
84115 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
84116diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
84117index 5679d92..2e7a690 100644
84118--- a/include/net/ip_vs.h
84119+++ b/include/net/ip_vs.h
84120@@ -558,7 +558,7 @@ struct ip_vs_conn {
84121 struct ip_vs_conn *control; /* Master control connection */
84122 atomic_t n_control; /* Number of controlled ones */
84123 struct ip_vs_dest *dest; /* real server */
84124- atomic_t in_pkts; /* incoming packet counter */
84125+ atomic_unchecked_t in_pkts; /* incoming packet counter */
84126
84127 /* packet transmitter for different forwarding methods. If it
84128 mangles the packet, it must return NF_DROP or better NF_STOLEN,
84129@@ -705,7 +705,7 @@ struct ip_vs_dest {
84130 __be16 port; /* port number of the server */
84131 union nf_inet_addr addr; /* IP address of the server */
84132 volatile unsigned int flags; /* dest status flags */
84133- atomic_t conn_flags; /* flags to copy to conn */
84134+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
84135 atomic_t weight; /* server weight */
84136
84137 atomic_t refcnt; /* reference counter */
84138@@ -960,11 +960,11 @@ struct netns_ipvs {
84139 /* ip_vs_lblc */
84140 int sysctl_lblc_expiration;
84141 struct ctl_table_header *lblc_ctl_header;
84142- struct ctl_table *lblc_ctl_table;
84143+ ctl_table_no_const *lblc_ctl_table;
84144 /* ip_vs_lblcr */
84145 int sysctl_lblcr_expiration;
84146 struct ctl_table_header *lblcr_ctl_header;
84147- struct ctl_table *lblcr_ctl_table;
84148+ ctl_table_no_const *lblcr_ctl_table;
84149 /* ip_vs_est */
84150 struct list_head est_list; /* estimator list */
84151 spinlock_t est_lock;
84152diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
84153index 8d4f588..2e37ad2 100644
84154--- a/include/net/irda/ircomm_tty.h
84155+++ b/include/net/irda/ircomm_tty.h
84156@@ -33,6 +33,7 @@
84157 #include <linux/termios.h>
84158 #include <linux/timer.h>
84159 #include <linux/tty.h> /* struct tty_struct */
84160+#include <asm/local.h>
84161
84162 #include <net/irda/irias_object.h>
84163 #include <net/irda/ircomm_core.h>
84164diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
84165index 714cc9a..ea05f3e 100644
84166--- a/include/net/iucv/af_iucv.h
84167+++ b/include/net/iucv/af_iucv.h
84168@@ -149,7 +149,7 @@ struct iucv_skb_cb {
84169 struct iucv_sock_list {
84170 struct hlist_head head;
84171 rwlock_t lock;
84172- atomic_t autobind_name;
84173+ atomic_unchecked_t autobind_name;
84174 };
84175
84176 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
84177diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
84178index f3be818..bf46196 100644
84179--- a/include/net/llc_c_ac.h
84180+++ b/include/net/llc_c_ac.h
84181@@ -87,7 +87,7 @@
84182 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
84183 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
84184
84185-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
84186+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
84187
84188 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
84189 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
84190diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
84191index 3948cf1..83b28c4 100644
84192--- a/include/net/llc_c_ev.h
84193+++ b/include/net/llc_c_ev.h
84194@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
84195 return (struct llc_conn_state_ev *)skb->cb;
84196 }
84197
84198-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
84199-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
84200+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
84201+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
84202
84203 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
84204 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
84205diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
84206index 0e79cfb..f46db31 100644
84207--- a/include/net/llc_c_st.h
84208+++ b/include/net/llc_c_st.h
84209@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
84210 u8 next_state;
84211 llc_conn_ev_qfyr_t *ev_qualifiers;
84212 llc_conn_action_t *ev_actions;
84213-};
84214+} __do_const;
84215
84216 struct llc_conn_state {
84217 u8 current_state;
84218diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
84219index a61b98c..aade1eb 100644
84220--- a/include/net/llc_s_ac.h
84221+++ b/include/net/llc_s_ac.h
84222@@ -23,7 +23,7 @@
84223 #define SAP_ACT_TEST_IND 9
84224
84225 /* All action functions must look like this */
84226-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
84227+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
84228
84229 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
84230 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
84231diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
84232index 567c681..cd73ac02 100644
84233--- a/include/net/llc_s_st.h
84234+++ b/include/net/llc_s_st.h
84235@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
84236 llc_sap_ev_t ev;
84237 u8 next_state;
84238 llc_sap_action_t *ev_actions;
84239-};
84240+} __do_const;
84241
84242 struct llc_sap_state {
84243 u8 curr_state;
84244diff --git a/include/net/mac80211.h b/include/net/mac80211.h
84245index 8248e39..7610eec 100644
84246--- a/include/net/mac80211.h
84247+++ b/include/net/mac80211.h
84248@@ -4467,7 +4467,7 @@ struct rate_control_ops {
84249 void (*add_sta_debugfs)(void *priv, void *priv_sta,
84250 struct dentry *dir);
84251 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
84252-};
84253+} __do_const;
84254
84255 static inline int rate_supported(struct ieee80211_sta *sta,
84256 enum ieee80211_band band,
84257diff --git a/include/net/neighbour.h b/include/net/neighbour.h
84258index 7277caf..fd095bc 100644
84259--- a/include/net/neighbour.h
84260+++ b/include/net/neighbour.h
84261@@ -163,7 +163,7 @@ struct neigh_ops {
84262 void (*error_report)(struct neighbour *, struct sk_buff *);
84263 int (*output)(struct neighbour *, struct sk_buff *);
84264 int (*connected_output)(struct neighbour *, struct sk_buff *);
84265-};
84266+} __do_const;
84267
84268 struct pneigh_entry {
84269 struct pneigh_entry *next;
84270@@ -203,7 +203,6 @@ struct neigh_table {
84271 void (*proxy_redo)(struct sk_buff *skb);
84272 char *id;
84273 struct neigh_parms parms;
84274- /* HACK. gc_* should follow parms without a gap! */
84275 int gc_interval;
84276 int gc_thresh1;
84277 int gc_thresh2;
84278@@ -218,7 +217,7 @@ struct neigh_table {
84279 struct neigh_statistics __percpu *stats;
84280 struct neigh_hash_table __rcu *nht;
84281 struct pneigh_entry **phash_buckets;
84282-};
84283+} __randomize_layout;
84284
84285 static inline int neigh_parms_family(struct neigh_parms *p)
84286 {
84287diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
84288index 5f9eb26..85699c4 100644
84289--- a/include/net/net_namespace.h
84290+++ b/include/net/net_namespace.h
84291@@ -129,8 +129,8 @@ struct net {
84292 struct netns_ipvs *ipvs;
84293 #endif
84294 struct sock *diag_nlsk;
84295- atomic_t fnhe_genid;
84296-};
84297+ atomic_unchecked_t fnhe_genid;
84298+} __randomize_layout;
84299
84300 #include <linux/seq_file_net.h>
84301
84302@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
84303 #define __net_init __init
84304 #define __net_exit __exit_refok
84305 #define __net_initdata __initdata
84306+#ifdef CONSTIFY_PLUGIN
84307 #define __net_initconst __initconst
84308+#else
84309+#define __net_initconst __initdata
84310+#endif
84311 #endif
84312
84313 struct pernet_operations {
84314@@ -296,7 +300,7 @@ struct pernet_operations {
84315 void (*exit_batch)(struct list_head *net_exit_list);
84316 int *id;
84317 size_t size;
84318-};
84319+} __do_const;
84320
84321 /*
84322 * Use these carefully. If you implement a network device and it
84323@@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
84324
84325 static inline int rt_genid_ipv4(struct net *net)
84326 {
84327- return atomic_read(&net->ipv4.rt_genid);
84328+ return atomic_read_unchecked(&net->ipv4.rt_genid);
84329 }
84330
84331 static inline void rt_genid_bump_ipv4(struct net *net)
84332 {
84333- atomic_inc(&net->ipv4.rt_genid);
84334+ atomic_inc_unchecked(&net->ipv4.rt_genid);
84335 }
84336
84337 #if IS_ENABLED(CONFIG_IPV6)
84338 static inline int rt_genid_ipv6(struct net *net)
84339 {
84340- return atomic_read(&net->ipv6.rt_genid);
84341+ return atomic_read_unchecked(&net->ipv6.rt_genid);
84342 }
84343
84344 static inline void rt_genid_bump_ipv6(struct net *net)
84345 {
84346- atomic_inc(&net->ipv6.rt_genid);
84347+ atomic_inc_unchecked(&net->ipv6.rt_genid);
84348 }
84349 #else
84350 static inline int rt_genid_ipv6(struct net *net)
84351@@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
84352
84353 static inline int fnhe_genid(struct net *net)
84354 {
84355- return atomic_read(&net->fnhe_genid);
84356+ return atomic_read_unchecked(&net->fnhe_genid);
84357 }
84358
84359 static inline void fnhe_genid_bump(struct net *net)
84360 {
84361- atomic_inc(&net->fnhe_genid);
84362+ atomic_inc_unchecked(&net->fnhe_genid);
84363 }
84364
84365 #endif /* __NET_NET_NAMESPACE_H */
84366diff --git a/include/net/netdma.h b/include/net/netdma.h
84367index 8ba8ce2..99b7fff 100644
84368--- a/include/net/netdma.h
84369+++ b/include/net/netdma.h
84370@@ -24,7 +24,7 @@
84371 #include <linux/dmaengine.h>
84372 #include <linux/skbuff.h>
84373
84374-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84375+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84376 struct sk_buff *skb, int offset, struct iovec *to,
84377 size_t len, struct dma_pinned_list *pinned_list);
84378
84379diff --git a/include/net/netlink.h b/include/net/netlink.h
84380index 2b47eaa..6d5bcc2 100644
84381--- a/include/net/netlink.h
84382+++ b/include/net/netlink.h
84383@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
84384 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
84385 {
84386 if (mark)
84387- skb_trim(skb, (unsigned char *) mark - skb->data);
84388+ skb_trim(skb, (const unsigned char *) mark - skb->data);
84389 }
84390
84391 /**
84392diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
84393index 773cce3..6a11852 100644
84394--- a/include/net/netns/conntrack.h
84395+++ b/include/net/netns/conntrack.h
84396@@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
84397 struct nf_proto_net {
84398 #ifdef CONFIG_SYSCTL
84399 struct ctl_table_header *ctl_table_header;
84400- struct ctl_table *ctl_table;
84401+ ctl_table_no_const *ctl_table;
84402 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
84403 struct ctl_table_header *ctl_compat_header;
84404- struct ctl_table *ctl_compat_table;
84405+ ctl_table_no_const *ctl_compat_table;
84406 #endif
84407 #endif
84408 unsigned int users;
84409@@ -59,7 +59,7 @@ struct nf_ip_net {
84410 struct nf_icmp_net icmpv6;
84411 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
84412 struct ctl_table_header *ctl_table_header;
84413- struct ctl_table *ctl_table;
84414+ ctl_table_no_const *ctl_table;
84415 #endif
84416 };
84417
84418diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
84419index b2704fd0..421d717 100644
84420--- a/include/net/netns/ipv4.h
84421+++ b/include/net/netns/ipv4.h
84422@@ -79,7 +79,7 @@ struct netns_ipv4 {
84423
84424 struct ping_group_range ping_group_range;
84425
84426- atomic_t dev_addr_genid;
84427+ atomic_unchecked_t dev_addr_genid;
84428
84429 #ifdef CONFIG_IP_MROUTE
84430 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
84431@@ -89,6 +89,6 @@ struct netns_ipv4 {
84432 struct fib_rules_ops *mr_rules_ops;
84433 #endif
84434 #endif
84435- atomic_t rt_genid;
84436+ atomic_unchecked_t rt_genid;
84437 };
84438 #endif
84439diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
84440index 21edaf1..4c5faae 100644
84441--- a/include/net/netns/ipv6.h
84442+++ b/include/net/netns/ipv6.h
84443@@ -73,8 +73,8 @@ struct netns_ipv6 {
84444 struct fib_rules_ops *mr6_rules_ops;
84445 #endif
84446 #endif
84447- atomic_t dev_addr_genid;
84448- atomic_t rt_genid;
84449+ atomic_unchecked_t dev_addr_genid;
84450+ atomic_unchecked_t rt_genid;
84451 };
84452
84453 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
84454diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
84455index 3492434..209f58c 100644
84456--- a/include/net/netns/xfrm.h
84457+++ b/include/net/netns/xfrm.h
84458@@ -64,7 +64,7 @@ struct netns_xfrm {
84459
84460 /* flow cache part */
84461 struct flow_cache flow_cache_global;
84462- atomic_t flow_cache_genid;
84463+ atomic_unchecked_t flow_cache_genid;
84464 struct list_head flow_cache_gc_list;
84465 spinlock_t flow_cache_gc_lock;
84466 struct work_struct flow_cache_gc_work;
84467diff --git a/include/net/ping.h b/include/net/ping.h
84468index 026479b..d9b2829 100644
84469--- a/include/net/ping.h
84470+++ b/include/net/ping.h
84471@@ -54,7 +54,7 @@ struct ping_iter_state {
84472
84473 extern struct proto ping_prot;
84474 #if IS_ENABLED(CONFIG_IPV6)
84475-extern struct pingv6_ops pingv6_ops;
84476+extern struct pingv6_ops *pingv6_ops;
84477 #endif
84478
84479 struct pingfakehdr {
84480diff --git a/include/net/protocol.h b/include/net/protocol.h
84481index a7e986b..dc67bce 100644
84482--- a/include/net/protocol.h
84483+++ b/include/net/protocol.h
84484@@ -49,7 +49,7 @@ struct net_protocol {
84485 * socket lookup?
84486 */
84487 icmp_strict_tag_validation:1;
84488-};
84489+} __do_const;
84490
84491 #if IS_ENABLED(CONFIG_IPV6)
84492 struct inet6_protocol {
84493@@ -62,7 +62,7 @@ struct inet6_protocol {
84494 u8 type, u8 code, int offset,
84495 __be32 info);
84496 unsigned int flags; /* INET6_PROTO_xxx */
84497-};
84498+} __do_const;
84499
84500 #define INET6_PROTO_NOPOLICY 0x1
84501 #define INET6_PROTO_FINAL 0x2
84502diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
84503index 72240e5..8c14bef 100644
84504--- a/include/net/rtnetlink.h
84505+++ b/include/net/rtnetlink.h
84506@@ -93,7 +93,7 @@ struct rtnl_link_ops {
84507 int (*fill_slave_info)(struct sk_buff *skb,
84508 const struct net_device *dev,
84509 const struct net_device *slave_dev);
84510-};
84511+} __do_const;
84512
84513 int __rtnl_link_register(struct rtnl_link_ops *ops);
84514 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
84515diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
84516index 4a5b9a3..ca27d73 100644
84517--- a/include/net/sctp/checksum.h
84518+++ b/include/net/sctp/checksum.h
84519@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
84520 unsigned int offset)
84521 {
84522 struct sctphdr *sh = sctp_hdr(skb);
84523- __le32 ret, old = sh->checksum;
84524- const struct skb_checksum_ops ops = {
84525+ __le32 ret, old = sh->checksum;
84526+ static const struct skb_checksum_ops ops = {
84527 .update = sctp_csum_update,
84528 .combine = sctp_csum_combine,
84529 };
84530diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
84531index 7f4eeb3..37e8fe1 100644
84532--- a/include/net/sctp/sm.h
84533+++ b/include/net/sctp/sm.h
84534@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84535 typedef struct {
84536 sctp_state_fn_t *fn;
84537 const char *name;
84538-} sctp_sm_table_entry_t;
84539+} __do_const sctp_sm_table_entry_t;
84540
84541 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84542 * currently in use.
84543@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84544 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84545
84546 /* Extern declarations for major data structures. */
84547-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84548+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84549
84550
84551 /* Get the size of a DATA chunk payload. */
84552diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84553index 0dfcc92..7967849 100644
84554--- a/include/net/sctp/structs.h
84555+++ b/include/net/sctp/structs.h
84556@@ -507,7 +507,7 @@ struct sctp_pf {
84557 struct sctp_association *asoc);
84558 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84559 struct sctp_af *af;
84560-};
84561+} __do_const;
84562
84563
84564 /* Structure to track chunk fragments that have been acked, but peer
84565diff --git a/include/net/sock.h b/include/net/sock.h
84566index f5a7e22..043b85f 100644
84567--- a/include/net/sock.h
84568+++ b/include/net/sock.h
84569@@ -348,7 +348,7 @@ struct sock {
84570 unsigned int sk_napi_id;
84571 unsigned int sk_ll_usec;
84572 #endif
84573- atomic_t sk_drops;
84574+ atomic_unchecked_t sk_drops;
84575 int sk_rcvbuf;
84576
84577 struct sk_filter __rcu *sk_filter;
84578@@ -1036,7 +1036,7 @@ struct proto {
84579 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84580 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84581 #endif
84582-};
84583+} __randomize_layout;
84584
84585 /*
84586 * Bits in struct cg_proto.flags
84587@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84588 return ret >> PAGE_SHIFT;
84589 }
84590
84591-static inline long
84592+static inline long __intentional_overflow(-1)
84593 sk_memory_allocated(const struct sock *sk)
84594 {
84595 struct proto *prot = sk->sk_prot;
84596@@ -1368,7 +1368,7 @@ struct sock_iocb {
84597 struct scm_cookie *scm;
84598 struct msghdr *msg, async_msg;
84599 struct kiocb *kiocb;
84600-};
84601+} __randomize_layout;
84602
84603 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84604 {
84605@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84606 }
84607
84608 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84609- char __user *from, char *to,
84610+ char __user *from, unsigned char *to,
84611 int copy, int offset)
84612 {
84613 if (skb->ip_summed == CHECKSUM_NONE) {
84614@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84615 }
84616 }
84617
84618-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84619+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84620
84621 /**
84622 * sk_page_frag - return an appropriate page_frag
84623diff --git a/include/net/tcp.h b/include/net/tcp.h
84624index 87d8774..cf214f8 100644
84625--- a/include/net/tcp.h
84626+++ b/include/net/tcp.h
84627@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84628 void tcp_xmit_retransmit_queue(struct sock *);
84629 void tcp_simple_retransmit(struct sock *);
84630 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84631-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84632+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84633
84634 void tcp_send_probe0(struct sock *);
84635 void tcp_send_partial(struct sock *);
84636@@ -715,8 +715,8 @@ struct tcp_skb_cb {
84637 struct inet6_skb_parm h6;
84638 #endif
84639 } header; /* For incoming frames */
84640- __u32 seq; /* Starting sequence number */
84641- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84642+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
84643+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84644 __u32 when; /* used to compute rtt's */
84645 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84646
84647@@ -730,7 +730,7 @@ struct tcp_skb_cb {
84648
84649 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84650 /* 1 byte hole */
84651- __u32 ack_seq; /* Sequence number ACK'd */
84652+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84653 };
84654
84655 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84656diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84657index 116e9c7..3070537 100644
84658--- a/include/net/xfrm.h
84659+++ b/include/net/xfrm.h
84660@@ -285,7 +285,6 @@ struct xfrm_dst;
84661 struct xfrm_policy_afinfo {
84662 unsigned short family;
84663 struct dst_ops *dst_ops;
84664- void (*garbage_collect)(struct net *net);
84665 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84666 const xfrm_address_t *saddr,
84667 const xfrm_address_t *daddr);
84668@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
84669 struct net_device *dev,
84670 const struct flowi *fl);
84671 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84672-};
84673+} __do_const;
84674
84675 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84676 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84677@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
84678 int (*transport_finish)(struct sk_buff *skb,
84679 int async);
84680 void (*local_error)(struct sk_buff *skb, u32 mtu);
84681-};
84682+} __do_const;
84683
84684 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84685 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84686@@ -437,7 +436,7 @@ struct xfrm_mode {
84687 struct module *owner;
84688 unsigned int encap;
84689 int flags;
84690-};
84691+} __do_const;
84692
84693 /* Flags for xfrm_mode. */
84694 enum {
84695@@ -534,7 +533,7 @@ struct xfrm_policy {
84696 struct timer_list timer;
84697
84698 struct flow_cache_object flo;
84699- atomic_t genid;
84700+ atomic_unchecked_t genid;
84701 u32 priority;
84702 u32 index;
84703 struct xfrm_mark mark;
84704@@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84705 }
84706
84707 void xfrm_garbage_collect(struct net *net);
84708+void xfrm_garbage_collect_deferred(struct net *net);
84709
84710 #else
84711
84712@@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84713 static inline void xfrm_garbage_collect(struct net *net)
84714 {
84715 }
84716+static inline void xfrm_garbage_collect_deferred(struct net *net)
84717+{
84718+}
84719 #endif
84720
84721 static __inline__
84722diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84723index 1017e0b..227aa4d 100644
84724--- a/include/rdma/iw_cm.h
84725+++ b/include/rdma/iw_cm.h
84726@@ -122,7 +122,7 @@ struct iw_cm_verbs {
84727 int backlog);
84728
84729 int (*destroy_listen)(struct iw_cm_id *cm_id);
84730-};
84731+} __no_const;
84732
84733 /**
84734 * iw_create_cm_id - Create an IW CM identifier.
84735diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84736index 52beadf..598734c 100644
84737--- a/include/scsi/libfc.h
84738+++ b/include/scsi/libfc.h
84739@@ -771,6 +771,7 @@ struct libfc_function_template {
84740 */
84741 void (*disc_stop_final) (struct fc_lport *);
84742 };
84743+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84744
84745 /**
84746 * struct fc_disc - Discovery context
84747@@ -875,7 +876,7 @@ struct fc_lport {
84748 struct fc_vport *vport;
84749
84750 /* Operational Information */
84751- struct libfc_function_template tt;
84752+ libfc_function_template_no_const tt;
84753 u8 link_up;
84754 u8 qfull;
84755 enum fc_lport_state state;
84756diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84757index 27ab310..60dc245 100644
84758--- a/include/scsi/scsi_device.h
84759+++ b/include/scsi/scsi_device.h
84760@@ -187,9 +187,9 @@ struct scsi_device {
84761 unsigned int max_device_blocked; /* what device_blocked counts down from */
84762 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84763
84764- atomic_t iorequest_cnt;
84765- atomic_t iodone_cnt;
84766- atomic_t ioerr_cnt;
84767+ atomic_unchecked_t iorequest_cnt;
84768+ atomic_unchecked_t iodone_cnt;
84769+ atomic_unchecked_t ioerr_cnt;
84770
84771 struct device sdev_gendev,
84772 sdev_dev;
84773diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84774index 8c79980..723f6f9 100644
84775--- a/include/scsi/scsi_transport_fc.h
84776+++ b/include/scsi/scsi_transport_fc.h
84777@@ -752,7 +752,8 @@ struct fc_function_template {
84778 unsigned long show_host_system_hostname:1;
84779
84780 unsigned long disable_target_scan:1;
84781-};
84782+} __do_const;
84783+typedef struct fc_function_template __no_const fc_function_template_no_const;
84784
84785
84786 /**
84787diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84788index ae6c3b8..fd748ac 100644
84789--- a/include/sound/compress_driver.h
84790+++ b/include/sound/compress_driver.h
84791@@ -128,7 +128,7 @@ struct snd_compr_ops {
84792 struct snd_compr_caps *caps);
84793 int (*get_codec_caps) (struct snd_compr_stream *stream,
84794 struct snd_compr_codec_caps *codec);
84795-};
84796+} __no_const;
84797
84798 /**
84799 * struct snd_compr: Compressed device
84800diff --git a/include/sound/soc.h b/include/sound/soc.h
84801index 0b83168..d67280a 100644
84802--- a/include/sound/soc.h
84803+++ b/include/sound/soc.h
84804@@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84805 /* probe ordering - for components with runtime dependencies */
84806 int probe_order;
84807 int remove_order;
84808-};
84809+} __do_const;
84810
84811 /* SoC platform interface */
84812 struct snd_soc_platform_driver {
84813@@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84814 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84815 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84816 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84817-};
84818+} __do_const;
84819
84820 struct snd_soc_platform {
84821 const char *name;
84822diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84823index 9ec9864..e2ee1ee 100644
84824--- a/include/target/target_core_base.h
84825+++ b/include/target/target_core_base.h
84826@@ -761,7 +761,7 @@ struct se_device {
84827 atomic_long_t write_bytes;
84828 /* Active commands on this virtual SE device */
84829 atomic_t simple_cmds;
84830- atomic_t dev_ordered_id;
84831+ atomic_unchecked_t dev_ordered_id;
84832 atomic_t dev_ordered_sync;
84833 atomic_t dev_qf_count;
84834 int export_count;
84835diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84836new file mode 100644
84837index 0000000..fb634b7
84838--- /dev/null
84839+++ b/include/trace/events/fs.h
84840@@ -0,0 +1,53 @@
84841+#undef TRACE_SYSTEM
84842+#define TRACE_SYSTEM fs
84843+
84844+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84845+#define _TRACE_FS_H
84846+
84847+#include <linux/fs.h>
84848+#include <linux/tracepoint.h>
84849+
84850+TRACE_EVENT(do_sys_open,
84851+
84852+ TP_PROTO(const char *filename, int flags, int mode),
84853+
84854+ TP_ARGS(filename, flags, mode),
84855+
84856+ TP_STRUCT__entry(
84857+ __string( filename, filename )
84858+ __field( int, flags )
84859+ __field( int, mode )
84860+ ),
84861+
84862+ TP_fast_assign(
84863+ __assign_str(filename, filename);
84864+ __entry->flags = flags;
84865+ __entry->mode = mode;
84866+ ),
84867+
84868+ TP_printk("\"%s\" %x %o",
84869+ __get_str(filename), __entry->flags, __entry->mode)
84870+);
84871+
84872+TRACE_EVENT(open_exec,
84873+
84874+ TP_PROTO(const char *filename),
84875+
84876+ TP_ARGS(filename),
84877+
84878+ TP_STRUCT__entry(
84879+ __string( filename, filename )
84880+ ),
84881+
84882+ TP_fast_assign(
84883+ __assign_str(filename, filename);
84884+ ),
84885+
84886+ TP_printk("\"%s\"",
84887+ __get_str(filename))
84888+);
84889+
84890+#endif /* _TRACE_FS_H */
84891+
84892+/* This part must be outside protection */
84893+#include <trace/define_trace.h>
84894diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84895index 1c09820..7f5ec79 100644
84896--- a/include/trace/events/irq.h
84897+++ b/include/trace/events/irq.h
84898@@ -36,7 +36,7 @@ struct softirq_action;
84899 */
84900 TRACE_EVENT(irq_handler_entry,
84901
84902- TP_PROTO(int irq, struct irqaction *action),
84903+ TP_PROTO(int irq, const struct irqaction *action),
84904
84905 TP_ARGS(irq, action),
84906
84907@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84908 */
84909 TRACE_EVENT(irq_handler_exit,
84910
84911- TP_PROTO(int irq, struct irqaction *action, int ret),
84912+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84913
84914 TP_ARGS(irq, action, ret),
84915
84916diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84917index 7caf44c..23c6f27 100644
84918--- a/include/uapi/linux/a.out.h
84919+++ b/include/uapi/linux/a.out.h
84920@@ -39,6 +39,14 @@ enum machine_type {
84921 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84922 };
84923
84924+/* Constants for the N_FLAGS field */
84925+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84926+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84927+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84928+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84929+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84930+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84931+
84932 #if !defined (N_MAGIC)
84933 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84934 #endif
84935diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84936index 22b6ad3..aeba37e 100644
84937--- a/include/uapi/linux/bcache.h
84938+++ b/include/uapi/linux/bcache.h
84939@@ -5,6 +5,7 @@
84940 * Bcache on disk data structures
84941 */
84942
84943+#include <linux/compiler.h>
84944 #include <asm/types.h>
84945
84946 #define BITMASK(name, type, field, offset, size) \
84947@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84948 /* Btree keys - all units are in sectors */
84949
84950 struct bkey {
84951- __u64 high;
84952- __u64 low;
84953+ __u64 high __intentional_overflow(-1);
84954+ __u64 low __intentional_overflow(-1);
84955 __u64 ptr[];
84956 };
84957
84958diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84959index d876736..ccce5c0 100644
84960--- a/include/uapi/linux/byteorder/little_endian.h
84961+++ b/include/uapi/linux/byteorder/little_endian.h
84962@@ -42,51 +42,51 @@
84963
84964 static inline __le64 __cpu_to_le64p(const __u64 *p)
84965 {
84966- return (__force __le64)*p;
84967+ return (__force const __le64)*p;
84968 }
84969-static inline __u64 __le64_to_cpup(const __le64 *p)
84970+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84971 {
84972- return (__force __u64)*p;
84973+ return (__force const __u64)*p;
84974 }
84975 static inline __le32 __cpu_to_le32p(const __u32 *p)
84976 {
84977- return (__force __le32)*p;
84978+ return (__force const __le32)*p;
84979 }
84980 static inline __u32 __le32_to_cpup(const __le32 *p)
84981 {
84982- return (__force __u32)*p;
84983+ return (__force const __u32)*p;
84984 }
84985 static inline __le16 __cpu_to_le16p(const __u16 *p)
84986 {
84987- return (__force __le16)*p;
84988+ return (__force const __le16)*p;
84989 }
84990 static inline __u16 __le16_to_cpup(const __le16 *p)
84991 {
84992- return (__force __u16)*p;
84993+ return (__force const __u16)*p;
84994 }
84995 static inline __be64 __cpu_to_be64p(const __u64 *p)
84996 {
84997- return (__force __be64)__swab64p(p);
84998+ return (__force const __be64)__swab64p(p);
84999 }
85000 static inline __u64 __be64_to_cpup(const __be64 *p)
85001 {
85002- return __swab64p((__u64 *)p);
85003+ return __swab64p((const __u64 *)p);
85004 }
85005 static inline __be32 __cpu_to_be32p(const __u32 *p)
85006 {
85007- return (__force __be32)__swab32p(p);
85008+ return (__force const __be32)__swab32p(p);
85009 }
85010-static inline __u32 __be32_to_cpup(const __be32 *p)
85011+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
85012 {
85013- return __swab32p((__u32 *)p);
85014+ return __swab32p((const __u32 *)p);
85015 }
85016 static inline __be16 __cpu_to_be16p(const __u16 *p)
85017 {
85018- return (__force __be16)__swab16p(p);
85019+ return (__force const __be16)__swab16p(p);
85020 }
85021 static inline __u16 __be16_to_cpup(const __be16 *p)
85022 {
85023- return __swab16p((__u16 *)p);
85024+ return __swab16p((const __u16 *)p);
85025 }
85026 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
85027 #define __le64_to_cpus(x) do { (void)(x); } while (0)
85028diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
85029index ef6103b..d4e65dd 100644
85030--- a/include/uapi/linux/elf.h
85031+++ b/include/uapi/linux/elf.h
85032@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
85033 #define PT_GNU_EH_FRAME 0x6474e550
85034
85035 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
85036+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
85037+
85038+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
85039+
85040+/* Constants for the e_flags field */
85041+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
85042+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
85043+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
85044+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
85045+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
85046+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
85047
85048 /*
85049 * Extended Numbering
85050@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
85051 #define DT_DEBUG 21
85052 #define DT_TEXTREL 22
85053 #define DT_JMPREL 23
85054+#define DT_FLAGS 30
85055+ #define DF_TEXTREL 0x00000004
85056 #define DT_ENCODING 32
85057 #define OLD_DT_LOOS 0x60000000
85058 #define DT_LOOS 0x6000000d
85059@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
85060 #define PF_W 0x2
85061 #define PF_X 0x1
85062
85063+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
85064+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
85065+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
85066+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
85067+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
85068+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
85069+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
85070+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
85071+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
85072+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
85073+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
85074+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
85075+
85076 typedef struct elf32_phdr{
85077 Elf32_Word p_type;
85078 Elf32_Off p_offset;
85079@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
85080 #define EI_OSABI 7
85081 #define EI_PAD 8
85082
85083+#define EI_PAX 14
85084+
85085 #define ELFMAG0 0x7f /* EI_MAG */
85086 #define ELFMAG1 'E'
85087 #define ELFMAG2 'L'
85088diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
85089index aa169c4..6a2771d 100644
85090--- a/include/uapi/linux/personality.h
85091+++ b/include/uapi/linux/personality.h
85092@@ -30,6 +30,7 @@ enum {
85093 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
85094 ADDR_NO_RANDOMIZE | \
85095 ADDR_COMPAT_LAYOUT | \
85096+ ADDR_LIMIT_3GB | \
85097 MMAP_PAGE_ZERO)
85098
85099 /*
85100diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
85101index 7530e74..e714828 100644
85102--- a/include/uapi/linux/screen_info.h
85103+++ b/include/uapi/linux/screen_info.h
85104@@ -43,7 +43,8 @@ struct screen_info {
85105 __u16 pages; /* 0x32 */
85106 __u16 vesa_attributes; /* 0x34 */
85107 __u32 capabilities; /* 0x36 */
85108- __u8 _reserved[6]; /* 0x3a */
85109+ __u16 vesapm_size; /* 0x3a */
85110+ __u8 _reserved[4]; /* 0x3c */
85111 } __attribute__((packed));
85112
85113 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
85114diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
85115index 0e011eb..82681b1 100644
85116--- a/include/uapi/linux/swab.h
85117+++ b/include/uapi/linux/swab.h
85118@@ -43,7 +43,7 @@
85119 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
85120 */
85121
85122-static inline __attribute_const__ __u16 __fswab16(__u16 val)
85123+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
85124 {
85125 #ifdef __HAVE_BUILTIN_BSWAP16__
85126 return __builtin_bswap16(val);
85127@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
85128 #endif
85129 }
85130
85131-static inline __attribute_const__ __u32 __fswab32(__u32 val)
85132+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
85133 {
85134 #ifdef __HAVE_BUILTIN_BSWAP32__
85135 return __builtin_bswap32(val);
85136@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
85137 #endif
85138 }
85139
85140-static inline __attribute_const__ __u64 __fswab64(__u64 val)
85141+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
85142 {
85143 #ifdef __HAVE_BUILTIN_BSWAP64__
85144 return __builtin_bswap64(val);
85145diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
85146index 6d67213..552fdd9 100644
85147--- a/include/uapi/linux/sysctl.h
85148+++ b/include/uapi/linux/sysctl.h
85149@@ -155,8 +155,6 @@ enum
85150 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
85151 };
85152
85153-
85154-
85155 /* CTL_VM names: */
85156 enum
85157 {
85158diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
85159index ea468ee..4d367a5 100644
85160--- a/include/uapi/linux/videodev2.h
85161+++ b/include/uapi/linux/videodev2.h
85162@@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
85163 union {
85164 __s32 value;
85165 __s64 value64;
85166- char *string;
85167+ char __user *string;
85168 };
85169 } __attribute__ ((packed));
85170
85171diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
85172index c38355c..17a57bc 100644
85173--- a/include/uapi/linux/xattr.h
85174+++ b/include/uapi/linux/xattr.h
85175@@ -73,5 +73,9 @@
85176 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
85177 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
85178
85179+/* User namespace */
85180+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
85181+#define XATTR_PAX_FLAGS_SUFFIX "flags"
85182+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
85183
85184 #endif /* _UAPI_LINUX_XATTR_H */
85185diff --git a/include/video/udlfb.h b/include/video/udlfb.h
85186index f9466fa..f4e2b81 100644
85187--- a/include/video/udlfb.h
85188+++ b/include/video/udlfb.h
85189@@ -53,10 +53,10 @@ struct dlfb_data {
85190 u32 pseudo_palette[256];
85191 int blank_mode; /*one of FB_BLANK_ */
85192 /* blit-only rendering path metrics, exposed through sysfs */
85193- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
85194- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
85195- atomic_t bytes_sent; /* to usb, after compression including overhead */
85196- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
85197+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
85198+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
85199+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
85200+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
85201 };
85202
85203 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
85204diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
85205index 30f5362..8ed8ac9 100644
85206--- a/include/video/uvesafb.h
85207+++ b/include/video/uvesafb.h
85208@@ -122,6 +122,7 @@ struct uvesafb_par {
85209 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
85210 u8 pmi_setpal; /* PMI for palette changes */
85211 u16 *pmi_base; /* protected mode interface location */
85212+ u8 *pmi_code; /* protected mode code location */
85213 void *pmi_start;
85214 void *pmi_pal;
85215 u8 *vbe_state_orig; /*
85216diff --git a/init/Kconfig b/init/Kconfig
85217index 9d3585b..ad45d34 100644
85218--- a/init/Kconfig
85219+++ b/init/Kconfig
85220@@ -1093,6 +1093,7 @@ endif # CGROUPS
85221
85222 config CHECKPOINT_RESTORE
85223 bool "Checkpoint/restore support" if EXPERT
85224+ depends on !GRKERNSEC
85225 default n
85226 help
85227 Enables additional kernel features in a sake of checkpoint/restore.
85228@@ -1570,7 +1571,7 @@ config SLUB_DEBUG
85229
85230 config COMPAT_BRK
85231 bool "Disable heap randomization"
85232- default y
85233+ default n
85234 help
85235 Randomizing heap placement makes heap exploits harder, but it
85236 also breaks ancient binaries (including anything libc5 based).
85237@@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
85238 config STOP_MACHINE
85239 bool
85240 default y
85241- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
85242+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
85243 help
85244 Need stop_machine() primitive.
85245
85246diff --git a/init/Makefile b/init/Makefile
85247index 7bc47ee..6da2dc7 100644
85248--- a/init/Makefile
85249+++ b/init/Makefile
85250@@ -2,6 +2,9 @@
85251 # Makefile for the linux kernel.
85252 #
85253
85254+ccflags-y := $(GCC_PLUGINS_CFLAGS)
85255+asflags-y := $(GCC_PLUGINS_AFLAGS)
85256+
85257 obj-y := main.o version.o mounts.o
85258 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
85259 obj-y += noinitramfs.o
85260diff --git a/init/do_mounts.c b/init/do_mounts.c
85261index 82f2288..ea1430a 100644
85262--- a/init/do_mounts.c
85263+++ b/init/do_mounts.c
85264@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
85265 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
85266 {
85267 struct super_block *s;
85268- int err = sys_mount(name, "/root", fs, flags, data);
85269+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
85270 if (err)
85271 return err;
85272
85273- sys_chdir("/root");
85274+ sys_chdir((const char __force_user *)"/root");
85275 s = current->fs->pwd.dentry->d_sb;
85276 ROOT_DEV = s->s_dev;
85277 printk(KERN_INFO
85278@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
85279 va_start(args, fmt);
85280 vsprintf(buf, fmt, args);
85281 va_end(args);
85282- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
85283+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
85284 if (fd >= 0) {
85285 sys_ioctl(fd, FDEJECT, 0);
85286 sys_close(fd);
85287 }
85288 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
85289- fd = sys_open("/dev/console", O_RDWR, 0);
85290+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
85291 if (fd >= 0) {
85292 sys_ioctl(fd, TCGETS, (long)&termios);
85293 termios.c_lflag &= ~ICANON;
85294 sys_ioctl(fd, TCSETSF, (long)&termios);
85295- sys_read(fd, &c, 1);
85296+ sys_read(fd, (char __user *)&c, 1);
85297 termios.c_lflag |= ICANON;
85298 sys_ioctl(fd, TCSETSF, (long)&termios);
85299 sys_close(fd);
85300@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
85301 mount_root();
85302 out:
85303 devtmpfs_mount("dev");
85304- sys_mount(".", "/", NULL, MS_MOVE, NULL);
85305- sys_chroot(".");
85306+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85307+ sys_chroot((const char __force_user *)".");
85308 }
85309
85310 static bool is_tmpfs;
85311diff --git a/init/do_mounts.h b/init/do_mounts.h
85312index f5b978a..69dbfe8 100644
85313--- a/init/do_mounts.h
85314+++ b/init/do_mounts.h
85315@@ -15,15 +15,15 @@ extern int root_mountflags;
85316
85317 static inline int create_dev(char *name, dev_t dev)
85318 {
85319- sys_unlink(name);
85320- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
85321+ sys_unlink((char __force_user *)name);
85322+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
85323 }
85324
85325 #if BITS_PER_LONG == 32
85326 static inline u32 bstat(char *name)
85327 {
85328 struct stat64 stat;
85329- if (sys_stat64(name, &stat) != 0)
85330+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
85331 return 0;
85332 if (!S_ISBLK(stat.st_mode))
85333 return 0;
85334@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
85335 static inline u32 bstat(char *name)
85336 {
85337 struct stat stat;
85338- if (sys_newstat(name, &stat) != 0)
85339+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
85340 return 0;
85341 if (!S_ISBLK(stat.st_mode))
85342 return 0;
85343diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
85344index 3e0878e..8a9d7a0 100644
85345--- a/init/do_mounts_initrd.c
85346+++ b/init/do_mounts_initrd.c
85347@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
85348 {
85349 sys_unshare(CLONE_FS | CLONE_FILES);
85350 /* stdin/stdout/stderr for /linuxrc */
85351- sys_open("/dev/console", O_RDWR, 0);
85352+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
85353 sys_dup(0);
85354 sys_dup(0);
85355 /* move initrd over / and chdir/chroot in initrd root */
85356- sys_chdir("/root");
85357- sys_mount(".", "/", NULL, MS_MOVE, NULL);
85358- sys_chroot(".");
85359+ sys_chdir((const char __force_user *)"/root");
85360+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85361+ sys_chroot((const char __force_user *)".");
85362 sys_setsid();
85363 return 0;
85364 }
85365@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
85366 create_dev("/dev/root.old", Root_RAM0);
85367 /* mount initrd on rootfs' /root */
85368 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
85369- sys_mkdir("/old", 0700);
85370- sys_chdir("/old");
85371+ sys_mkdir((const char __force_user *)"/old", 0700);
85372+ sys_chdir((const char __force_user *)"/old");
85373
85374 /* try loading default modules from initrd */
85375 load_default_modules();
85376@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
85377 current->flags &= ~PF_FREEZER_SKIP;
85378
85379 /* move initrd to rootfs' /old */
85380- sys_mount("..", ".", NULL, MS_MOVE, NULL);
85381+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
85382 /* switch root and cwd back to / of rootfs */
85383- sys_chroot("..");
85384+ sys_chroot((const char __force_user *)"..");
85385
85386 if (new_decode_dev(real_root_dev) == Root_RAM0) {
85387- sys_chdir("/old");
85388+ sys_chdir((const char __force_user *)"/old");
85389 return;
85390 }
85391
85392- sys_chdir("/");
85393+ sys_chdir((const char __force_user *)"/");
85394 ROOT_DEV = new_decode_dev(real_root_dev);
85395 mount_root();
85396
85397 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
85398- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
85399+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
85400 if (!error)
85401 printk("okay\n");
85402 else {
85403- int fd = sys_open("/dev/root.old", O_RDWR, 0);
85404+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
85405 if (error == -ENOENT)
85406 printk("/initrd does not exist. Ignored.\n");
85407 else
85408 printk("failed\n");
85409 printk(KERN_NOTICE "Unmounting old root\n");
85410- sys_umount("/old", MNT_DETACH);
85411+ sys_umount((char __force_user *)"/old", MNT_DETACH);
85412 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
85413 if (fd < 0) {
85414 error = fd;
85415@@ -127,11 +127,11 @@ int __init initrd_load(void)
85416 * mounted in the normal path.
85417 */
85418 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
85419- sys_unlink("/initrd.image");
85420+ sys_unlink((const char __force_user *)"/initrd.image");
85421 handle_initrd();
85422 return 1;
85423 }
85424 }
85425- sys_unlink("/initrd.image");
85426+ sys_unlink((const char __force_user *)"/initrd.image");
85427 return 0;
85428 }
85429diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
85430index 8cb6db5..d729f50 100644
85431--- a/init/do_mounts_md.c
85432+++ b/init/do_mounts_md.c
85433@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
85434 partitioned ? "_d" : "", minor,
85435 md_setup_args[ent].device_names);
85436
85437- fd = sys_open(name, 0, 0);
85438+ fd = sys_open((char __force_user *)name, 0, 0);
85439 if (fd < 0) {
85440 printk(KERN_ERR "md: open failed - cannot start "
85441 "array %s\n", name);
85442@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
85443 * array without it
85444 */
85445 sys_close(fd);
85446- fd = sys_open(name, 0, 0);
85447+ fd = sys_open((char __force_user *)name, 0, 0);
85448 sys_ioctl(fd, BLKRRPART, 0);
85449 }
85450 sys_close(fd);
85451@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
85452
85453 wait_for_device_probe();
85454
85455- fd = sys_open("/dev/md0", 0, 0);
85456+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
85457 if (fd >= 0) {
85458 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
85459 sys_close(fd);
85460diff --git a/init/init_task.c b/init/init_task.c
85461index ba0a7f36..2bcf1d5 100644
85462--- a/init/init_task.c
85463+++ b/init/init_task.c
85464@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
85465 * Initial thread structure. Alignment of this is handled by a special
85466 * linker map entry.
85467 */
85468+#ifdef CONFIG_X86
85469+union thread_union init_thread_union __init_task_data;
85470+#else
85471 union thread_union init_thread_union __init_task_data =
85472 { INIT_THREAD_INFO(init_task) };
85473+#endif
85474diff --git a/init/initramfs.c b/init/initramfs.c
85475index a8497fa..35b3c90 100644
85476--- a/init/initramfs.c
85477+++ b/init/initramfs.c
85478@@ -84,7 +84,7 @@ static void __init free_hash(void)
85479 }
85480 }
85481
85482-static long __init do_utime(char *filename, time_t mtime)
85483+static long __init do_utime(char __force_user *filename, time_t mtime)
85484 {
85485 struct timespec t[2];
85486
85487@@ -119,7 +119,7 @@ static void __init dir_utime(void)
85488 struct dir_entry *de, *tmp;
85489 list_for_each_entry_safe(de, tmp, &dir_list, list) {
85490 list_del(&de->list);
85491- do_utime(de->name, de->mtime);
85492+ do_utime((char __force_user *)de->name, de->mtime);
85493 kfree(de->name);
85494 kfree(de);
85495 }
85496@@ -281,7 +281,7 @@ static int __init maybe_link(void)
85497 if (nlink >= 2) {
85498 char *old = find_link(major, minor, ino, mode, collected);
85499 if (old)
85500- return (sys_link(old, collected) < 0) ? -1 : 1;
85501+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
85502 }
85503 return 0;
85504 }
85505@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
85506 {
85507 struct stat st;
85508
85509- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
85510+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
85511 if (S_ISDIR(st.st_mode))
85512- sys_rmdir(path);
85513+ sys_rmdir((char __force_user *)path);
85514 else
85515- sys_unlink(path);
85516+ sys_unlink((char __force_user *)path);
85517 }
85518 }
85519
85520@@ -315,7 +315,7 @@ static int __init do_name(void)
85521 int openflags = O_WRONLY|O_CREAT;
85522 if (ml != 1)
85523 openflags |= O_TRUNC;
85524- wfd = sys_open(collected, openflags, mode);
85525+ wfd = sys_open((char __force_user *)collected, openflags, mode);
85526
85527 if (wfd >= 0) {
85528 sys_fchown(wfd, uid, gid);
85529@@ -327,17 +327,17 @@ static int __init do_name(void)
85530 }
85531 }
85532 } else if (S_ISDIR(mode)) {
85533- sys_mkdir(collected, mode);
85534- sys_chown(collected, uid, gid);
85535- sys_chmod(collected, mode);
85536+ sys_mkdir((char __force_user *)collected, mode);
85537+ sys_chown((char __force_user *)collected, uid, gid);
85538+ sys_chmod((char __force_user *)collected, mode);
85539 dir_add(collected, mtime);
85540 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85541 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85542 if (maybe_link() == 0) {
85543- sys_mknod(collected, mode, rdev);
85544- sys_chown(collected, uid, gid);
85545- sys_chmod(collected, mode);
85546- do_utime(collected, mtime);
85547+ sys_mknod((char __force_user *)collected, mode, rdev);
85548+ sys_chown((char __force_user *)collected, uid, gid);
85549+ sys_chmod((char __force_user *)collected, mode);
85550+ do_utime((char __force_user *)collected, mtime);
85551 }
85552 }
85553 return 0;
85554@@ -346,15 +346,15 @@ static int __init do_name(void)
85555 static int __init do_copy(void)
85556 {
85557 if (count >= body_len) {
85558- sys_write(wfd, victim, body_len);
85559+ sys_write(wfd, (char __force_user *)victim, body_len);
85560 sys_close(wfd);
85561- do_utime(vcollected, mtime);
85562+ do_utime((char __force_user *)vcollected, mtime);
85563 kfree(vcollected);
85564 eat(body_len);
85565 state = SkipIt;
85566 return 0;
85567 } else {
85568- sys_write(wfd, victim, count);
85569+ sys_write(wfd, (char __force_user *)victim, count);
85570 body_len -= count;
85571 eat(count);
85572 return 1;
85573@@ -365,9 +365,9 @@ static int __init do_symlink(void)
85574 {
85575 collected[N_ALIGN(name_len) + body_len] = '\0';
85576 clean_path(collected, 0);
85577- sys_symlink(collected + N_ALIGN(name_len), collected);
85578- sys_lchown(collected, uid, gid);
85579- do_utime(collected, mtime);
85580+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85581+ sys_lchown((char __force_user *)collected, uid, gid);
85582+ do_utime((char __force_user *)collected, mtime);
85583 state = SkipIt;
85584 next_state = Reset;
85585 return 0;
85586diff --git a/init/main.c b/init/main.c
85587index eb0ea86..b91cd60 100644
85588--- a/init/main.c
85589+++ b/init/main.c
85590@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85591 static inline void mark_rodata_ro(void) { }
85592 #endif
85593
85594+extern void grsecurity_init(void);
85595+
85596 /*
85597 * Debug helper: via this flag we know that we are in 'early bootup code'
85598 * where only the boot processor is running with IRQ disabled. This means
85599@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85600
85601 __setup("reset_devices", set_reset_devices);
85602
85603+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85604+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85605+static int __init setup_grsec_proc_gid(char *str)
85606+{
85607+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85608+ return 1;
85609+}
85610+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85611+#endif
85612+
85613+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85614+unsigned long pax_user_shadow_base __read_only;
85615+EXPORT_SYMBOL(pax_user_shadow_base);
85616+extern char pax_enter_kernel_user[];
85617+extern char pax_exit_kernel_user[];
85618+#endif
85619+
85620+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85621+static int __init setup_pax_nouderef(char *str)
85622+{
85623+#ifdef CONFIG_X86_32
85624+ unsigned int cpu;
85625+ struct desc_struct *gdt;
85626+
85627+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85628+ gdt = get_cpu_gdt_table(cpu);
85629+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85630+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85631+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85632+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85633+ }
85634+ loadsegment(ds, __KERNEL_DS);
85635+ loadsegment(es, __KERNEL_DS);
85636+ loadsegment(ss, __KERNEL_DS);
85637+#else
85638+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85639+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85640+ clone_pgd_mask = ~(pgdval_t)0UL;
85641+ pax_user_shadow_base = 0UL;
85642+ setup_clear_cpu_cap(X86_FEATURE_PCID);
85643+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85644+#endif
85645+
85646+ return 0;
85647+}
85648+early_param("pax_nouderef", setup_pax_nouderef);
85649+
85650+#ifdef CONFIG_X86_64
85651+static int __init setup_pax_weakuderef(char *str)
85652+{
85653+ if (clone_pgd_mask != ~(pgdval_t)0UL)
85654+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85655+ return 1;
85656+}
85657+__setup("pax_weakuderef", setup_pax_weakuderef);
85658+#endif
85659+#endif
85660+
85661+#ifdef CONFIG_PAX_SOFTMODE
85662+int pax_softmode;
85663+
85664+static int __init setup_pax_softmode(char *str)
85665+{
85666+ get_option(&str, &pax_softmode);
85667+ return 1;
85668+}
85669+__setup("pax_softmode=", setup_pax_softmode);
85670+#endif
85671+
85672 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85673 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85674 static const char *panic_later, *panic_param;
85675@@ -692,25 +763,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85676 {
85677 int count = preempt_count();
85678 int ret;
85679- char msgbuf[64];
85680+ const char *msg1 = "", *msg2 = "";
85681
85682 if (initcall_debug)
85683 ret = do_one_initcall_debug(fn);
85684 else
85685 ret = fn();
85686
85687- msgbuf[0] = 0;
85688-
85689 if (preempt_count() != count) {
85690- sprintf(msgbuf, "preemption imbalance ");
85691+ msg1 = " preemption imbalance";
85692 preempt_count_set(count);
85693 }
85694 if (irqs_disabled()) {
85695- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85696+ msg2 = " disabled interrupts";
85697 local_irq_enable();
85698 }
85699- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85700+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85701
85702+ add_latent_entropy();
85703 return ret;
85704 }
85705
85706@@ -817,8 +887,8 @@ static int run_init_process(const char *init_filename)
85707 {
85708 argv_init[0] = init_filename;
85709 return do_execve(getname_kernel(init_filename),
85710- (const char __user *const __user *)argv_init,
85711- (const char __user *const __user *)envp_init);
85712+ (const char __user *const __force_user *)argv_init,
85713+ (const char __user *const __force_user *)envp_init);
85714 }
85715
85716 static int try_to_run_init_process(const char *init_filename)
85717@@ -835,6 +905,10 @@ static int try_to_run_init_process(const char *init_filename)
85718 return ret;
85719 }
85720
85721+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85722+extern int gr_init_ran;
85723+#endif
85724+
85725 static noinline void __init kernel_init_freeable(void);
85726
85727 static int __ref kernel_init(void *unused)
85728@@ -859,6 +933,11 @@ static int __ref kernel_init(void *unused)
85729 ramdisk_execute_command, ret);
85730 }
85731
85732+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85733+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
85734+ gr_init_ran = 1;
85735+#endif
85736+
85737 /*
85738 * We try each of these until one succeeds.
85739 *
85740@@ -914,7 +993,7 @@ static noinline void __init kernel_init_freeable(void)
85741 do_basic_setup();
85742
85743 /* Open the /dev/console on the rootfs, this should never fail */
85744- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85745+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85746 pr_err("Warning: unable to open an initial console.\n");
85747
85748 (void) sys_dup(0);
85749@@ -927,11 +1006,13 @@ static noinline void __init kernel_init_freeable(void)
85750 if (!ramdisk_execute_command)
85751 ramdisk_execute_command = "/init";
85752
85753- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85754+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85755 ramdisk_execute_command = NULL;
85756 prepare_namespace();
85757 }
85758
85759+ grsecurity_init();
85760+
85761 /*
85762 * Ok, we have completed the initial bootup, and
85763 * we're essentially up and running. Get rid of the
85764diff --git a/ipc/compat.c b/ipc/compat.c
85765index 45d035d..e4a7f99 100644
85766--- a/ipc/compat.c
85767+++ b/ipc/compat.c
85768@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85769 COMPAT_SHMLBA);
85770 if (err < 0)
85771 return err;
85772- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85773+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85774 }
85775 case SHMDT:
85776 return sys_shmdt(compat_ptr(ptr));
85777diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85778index 998d31b..30c24df 100644
85779--- a/ipc/ipc_sysctl.c
85780+++ b/ipc/ipc_sysctl.c
85781@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85782 static int proc_ipc_dointvec(ctl_table *table, int write,
85783 void __user *buffer, size_t *lenp, loff_t *ppos)
85784 {
85785- struct ctl_table ipc_table;
85786+ ctl_table_no_const ipc_table;
85787
85788 memcpy(&ipc_table, table, sizeof(ipc_table));
85789 ipc_table.data = get_ipc(table);
85790@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85791 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85792 void __user *buffer, size_t *lenp, loff_t *ppos)
85793 {
85794- struct ctl_table ipc_table;
85795+ ctl_table_no_const ipc_table;
85796
85797 memcpy(&ipc_table, table, sizeof(ipc_table));
85798 ipc_table.data = get_ipc(table);
85799@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85800 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85801 void __user *buffer, size_t *lenp, loff_t *ppos)
85802 {
85803- struct ctl_table ipc_table;
85804+ ctl_table_no_const ipc_table;
85805 size_t lenp_bef = *lenp;
85806 int rc;
85807
85808@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85809 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85810 void __user *buffer, size_t *lenp, loff_t *ppos)
85811 {
85812- struct ctl_table ipc_table;
85813+ ctl_table_no_const ipc_table;
85814 memcpy(&ipc_table, table, sizeof(ipc_table));
85815 ipc_table.data = get_ipc(table);
85816
85817@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85818 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85819 void __user *buffer, size_t *lenp, loff_t *ppos)
85820 {
85821- struct ctl_table ipc_table;
85822+ ctl_table_no_const ipc_table;
85823 size_t lenp_bef = *lenp;
85824 int oldval;
85825 int rc;
85826diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85827index 5bb8bfe..a38ec05 100644
85828--- a/ipc/mq_sysctl.c
85829+++ b/ipc/mq_sysctl.c
85830@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85831 static int proc_mq_dointvec(ctl_table *table, int write,
85832 void __user *buffer, size_t *lenp, loff_t *ppos)
85833 {
85834- struct ctl_table mq_table;
85835+ ctl_table_no_const mq_table;
85836 memcpy(&mq_table, table, sizeof(mq_table));
85837 mq_table.data = get_mq(table);
85838
85839@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85840 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85841 void __user *buffer, size_t *lenp, loff_t *ppos)
85842 {
85843- struct ctl_table mq_table;
85844+ ctl_table_no_const mq_table;
85845 memcpy(&mq_table, table, sizeof(mq_table));
85846 mq_table.data = get_mq(table);
85847
85848diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85849index 4fcf39a..d3cc2ec 100644
85850--- a/ipc/mqueue.c
85851+++ b/ipc/mqueue.c
85852@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85853 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85854 info->attr.mq_msgsize);
85855
85856+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85857 spin_lock(&mq_lock);
85858 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85859 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85860diff --git a/ipc/msg.c b/ipc/msg.c
85861index 6498531..b0ff3c8 100644
85862--- a/ipc/msg.c
85863+++ b/ipc/msg.c
85864@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85865 return security_msg_queue_associate(msq, msgflg);
85866 }
85867
85868+static struct ipc_ops msg_ops = {
85869+ .getnew = newque,
85870+ .associate = msg_security,
85871+ .more_checks = NULL
85872+};
85873+
85874 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85875 {
85876 struct ipc_namespace *ns;
85877- struct ipc_ops msg_ops;
85878 struct ipc_params msg_params;
85879
85880 ns = current->nsproxy->ipc_ns;
85881
85882- msg_ops.getnew = newque;
85883- msg_ops.associate = msg_security;
85884- msg_ops.more_checks = NULL;
85885-
85886 msg_params.key = key;
85887 msg_params.flg = msgflg;
85888
85889diff --git a/ipc/sem.c b/ipc/sem.c
85890index bee5554..e9af81dd 100644
85891--- a/ipc/sem.c
85892+++ b/ipc/sem.c
85893@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85894 return 0;
85895 }
85896
85897+static struct ipc_ops sem_ops = {
85898+ .getnew = newary,
85899+ .associate = sem_security,
85900+ .more_checks = sem_more_checks
85901+};
85902+
85903 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85904 {
85905 struct ipc_namespace *ns;
85906- struct ipc_ops sem_ops;
85907 struct ipc_params sem_params;
85908
85909 ns = current->nsproxy->ipc_ns;
85910@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85911 if (nsems < 0 || nsems > ns->sc_semmsl)
85912 return -EINVAL;
85913
85914- sem_ops.getnew = newary;
85915- sem_ops.associate = sem_security;
85916- sem_ops.more_checks = sem_more_checks;
85917-
85918 sem_params.key = key;
85919 sem_params.flg = semflg;
85920 sem_params.u.nsems = nsems;
85921diff --git a/ipc/shm.c b/ipc/shm.c
85922index 7645961..afc7f02 100644
85923--- a/ipc/shm.c
85924+++ b/ipc/shm.c
85925@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85926 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85927 #endif
85928
85929+#ifdef CONFIG_GRKERNSEC
85930+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85931+ const time_t shm_createtime, const kuid_t cuid,
85932+ const int shmid);
85933+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85934+ const time_t shm_createtime);
85935+#endif
85936+
85937 void shm_init_ns(struct ipc_namespace *ns)
85938 {
85939 ns->shm_ctlmax = SHMMAX;
85940@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85941 shp->shm_lprid = 0;
85942 shp->shm_atim = shp->shm_dtim = 0;
85943 shp->shm_ctim = get_seconds();
85944+#ifdef CONFIG_GRKERNSEC
85945+ {
85946+ struct timespec timeval;
85947+ do_posix_clock_monotonic_gettime(&timeval);
85948+
85949+ shp->shm_createtime = timeval.tv_sec;
85950+ }
85951+#endif
85952 shp->shm_segsz = size;
85953 shp->shm_nattch = 0;
85954 shp->shm_file = file;
85955@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85956 return 0;
85957 }
85958
85959+static struct ipc_ops shm_ops = {
85960+ .getnew = newseg,
85961+ .associate = shm_security,
85962+ .more_checks = shm_more_checks
85963+};
85964+
85965 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85966 {
85967 struct ipc_namespace *ns;
85968- struct ipc_ops shm_ops;
85969 struct ipc_params shm_params;
85970
85971 ns = current->nsproxy->ipc_ns;
85972
85973- shm_ops.getnew = newseg;
85974- shm_ops.associate = shm_security;
85975- shm_ops.more_checks = shm_more_checks;
85976-
85977 shm_params.key = key;
85978 shm_params.flg = shmflg;
85979 shm_params.u.size = size;
85980@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85981 f_mode = FMODE_READ | FMODE_WRITE;
85982 }
85983 if (shmflg & SHM_EXEC) {
85984+
85985+#ifdef CONFIG_PAX_MPROTECT
85986+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85987+ goto out;
85988+#endif
85989+
85990 prot |= PROT_EXEC;
85991 acc_mode |= S_IXUGO;
85992 }
85993@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85994 if (err)
85995 goto out_unlock;
85996
85997+#ifdef CONFIG_GRKERNSEC
85998+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85999+ shp->shm_perm.cuid, shmid) ||
86000+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
86001+ err = -EACCES;
86002+ goto out_unlock;
86003+ }
86004+#endif
86005+
86006 ipc_lock_object(&shp->shm_perm);
86007
86008 /* check if shm_destroy() is tearing down shp */
86009@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
86010 path = shp->shm_file->f_path;
86011 path_get(&path);
86012 shp->shm_nattch++;
86013+#ifdef CONFIG_GRKERNSEC
86014+ shp->shm_lapid = current->pid;
86015+#endif
86016 size = i_size_read(path.dentry->d_inode);
86017 ipc_unlock_object(&shp->shm_perm);
86018 rcu_read_unlock();
86019diff --git a/ipc/util.c b/ipc/util.c
86020index 2eb0d1e..0308564 100644
86021--- a/ipc/util.c
86022+++ b/ipc/util.c
86023@@ -71,6 +71,8 @@ struct ipc_proc_iface {
86024 int (*show)(struct seq_file *, void *);
86025 };
86026
86027+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
86028+
86029 static void ipc_memory_notifier(struct work_struct *work)
86030 {
86031 ipcns_notify(IPCNS_MEMCHANGED);
86032@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
86033 granted_mode >>= 6;
86034 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
86035 granted_mode >>= 3;
86036+
86037+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
86038+ return -1;
86039+
86040 /* is there some bit set in requested_mode but not in granted_mode? */
86041 if ((requested_mode & ~granted_mode & 0007) &&
86042 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
86043diff --git a/kernel/acct.c b/kernel/acct.c
86044index 8d6e145..33e0b1e 100644
86045--- a/kernel/acct.c
86046+++ b/kernel/acct.c
86047@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
86048 */
86049 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
86050 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
86051- file->f_op->write(file, (char *)&ac,
86052+ file->f_op->write(file, (char __force_user *)&ac,
86053 sizeof(acct_t), &file->f_pos);
86054 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
86055 set_fs(fs);
86056diff --git a/kernel/audit.c b/kernel/audit.c
86057index 47845c5..bd9dd5b 100644
86058--- a/kernel/audit.c
86059+++ b/kernel/audit.c
86060@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
86061 3) suppressed due to audit_rate_limit
86062 4) suppressed due to audit_backlog_limit
86063 */
86064-static atomic_t audit_lost = ATOMIC_INIT(0);
86065+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
86066
86067 /* The netlink socket. */
86068 static struct sock *audit_sock;
86069@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
86070 unsigned long now;
86071 int print;
86072
86073- atomic_inc(&audit_lost);
86074+ atomic_inc_unchecked(&audit_lost);
86075
86076 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
86077
86078@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
86079 if (print) {
86080 if (printk_ratelimit())
86081 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
86082- atomic_read(&audit_lost),
86083+ atomic_read_unchecked(&audit_lost),
86084 audit_rate_limit,
86085 audit_backlog_limit);
86086 audit_panic(message);
86087@@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86088 s.pid = audit_pid;
86089 s.rate_limit = audit_rate_limit;
86090 s.backlog_limit = audit_backlog_limit;
86091- s.lost = atomic_read(&audit_lost);
86092+ s.lost = atomic_read_unchecked(&audit_lost);
86093 s.backlog = skb_queue_len(&audit_skb_queue);
86094 s.version = AUDIT_VERSION_LATEST;
86095 s.backlog_wait_time = audit_backlog_wait_time;
86096diff --git a/kernel/auditsc.c b/kernel/auditsc.c
86097index 21eae3c..66db239 100644
86098--- a/kernel/auditsc.c
86099+++ b/kernel/auditsc.c
86100@@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
86101 }
86102
86103 /* global counter which is incremented every time something logs in */
86104-static atomic_t session_id = ATOMIC_INIT(0);
86105+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
86106
86107 static int audit_set_loginuid_perm(kuid_t loginuid)
86108 {
86109@@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
86110
86111 /* are we setting or clearing? */
86112 if (uid_valid(loginuid))
86113- sessionid = (unsigned int)atomic_inc_return(&session_id);
86114+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
86115
86116 task->sessionid = sessionid;
86117 task->loginuid = loginuid;
86118diff --git a/kernel/capability.c b/kernel/capability.c
86119index 24663b3..b926ae1 100644
86120--- a/kernel/capability.c
86121+++ b/kernel/capability.c
86122@@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
86123 * before modification is attempted and the application
86124 * fails.
86125 */
86126+ if (tocopy > ARRAY_SIZE(kdata))
86127+ return -EFAULT;
86128+
86129 if (copy_to_user(dataptr, kdata, tocopy
86130 * sizeof(struct __user_cap_data_struct))) {
86131 return -EFAULT;
86132@@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
86133 int ret;
86134
86135 rcu_read_lock();
86136- ret = security_capable(__task_cred(t), ns, cap);
86137+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
86138+ gr_task_is_capable(t, __task_cred(t), cap);
86139 rcu_read_unlock();
86140
86141- return (ret == 0);
86142+ return ret;
86143 }
86144
86145 /**
86146@@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
86147 int ret;
86148
86149 rcu_read_lock();
86150- ret = security_capable_noaudit(__task_cred(t), ns, cap);
86151+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
86152 rcu_read_unlock();
86153
86154- return (ret == 0);
86155+ return ret;
86156 }
86157
86158 /**
86159@@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
86160 BUG();
86161 }
86162
86163- if (security_capable(current_cred(), ns, cap) == 0) {
86164+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
86165 current->flags |= PF_SUPERPRIV;
86166 return true;
86167 }
86168@@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
86169 }
86170 EXPORT_SYMBOL(ns_capable);
86171
86172+bool ns_capable_nolog(struct user_namespace *ns, int cap)
86173+{
86174+ if (unlikely(!cap_valid(cap))) {
86175+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
86176+ BUG();
86177+ }
86178+
86179+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
86180+ current->flags |= PF_SUPERPRIV;
86181+ return true;
86182+ }
86183+ return false;
86184+}
86185+EXPORT_SYMBOL(ns_capable_nolog);
86186+
86187 /**
86188 * file_ns_capable - Determine if the file's opener had a capability in effect
86189 * @file: The file we want to check
86190@@ -423,6 +442,12 @@ bool capable(int cap)
86191 }
86192 EXPORT_SYMBOL(capable);
86193
86194+bool capable_nolog(int cap)
86195+{
86196+ return ns_capable_nolog(&init_user_ns, cap);
86197+}
86198+EXPORT_SYMBOL(capable_nolog);
86199+
86200 /**
86201 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
86202 * @inode: The inode in question
86203@@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
86204 kgid_has_mapping(ns, inode->i_gid);
86205 }
86206 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
86207+
86208+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
86209+{
86210+ struct user_namespace *ns = current_user_ns();
86211+
86212+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
86213+ kgid_has_mapping(ns, inode->i_gid);
86214+}
86215+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
86216diff --git a/kernel/cgroup.c b/kernel/cgroup.c
86217index 073226b..969c746 100644
86218--- a/kernel/cgroup.c
86219+++ b/kernel/cgroup.c
86220@@ -4808,7 +4808,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
86221 struct task_struct *task;
86222 int count = 0;
86223
86224- seq_printf(seq, "css_set %p\n", cset);
86225+ seq_printf(seq, "css_set %pK\n", cset);
86226
86227 list_for_each_entry(task, &cset->tasks, cg_list) {
86228 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
86229diff --git a/kernel/compat.c b/kernel/compat.c
86230index e40b043..3da8f51 100644
86231--- a/kernel/compat.c
86232+++ b/kernel/compat.c
86233@@ -13,6 +13,7 @@
86234
86235 #include <linux/linkage.h>
86236 #include <linux/compat.h>
86237+#include <linux/module.h>
86238 #include <linux/errno.h>
86239 #include <linux/time.h>
86240 #include <linux/signal.h>
86241@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
86242 mm_segment_t oldfs;
86243 long ret;
86244
86245- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
86246+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
86247 oldfs = get_fs();
86248 set_fs(KERNEL_DS);
86249 ret = hrtimer_nanosleep_restart(restart);
86250@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
86251 oldfs = get_fs();
86252 set_fs(KERNEL_DS);
86253 ret = hrtimer_nanosleep(&tu,
86254- rmtp ? (struct timespec __user *)&rmt : NULL,
86255+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
86256 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
86257 set_fs(oldfs);
86258
86259@@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
86260 mm_segment_t old_fs = get_fs();
86261
86262 set_fs(KERNEL_DS);
86263- ret = sys_sigpending((old_sigset_t __user *) &s);
86264+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
86265 set_fs(old_fs);
86266 if (ret == 0)
86267 ret = put_user(s, set);
86268@@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
86269 mm_segment_t old_fs = get_fs();
86270
86271 set_fs(KERNEL_DS);
86272- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
86273+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
86274 set_fs(old_fs);
86275
86276 if (!ret) {
86277@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
86278 set_fs (KERNEL_DS);
86279 ret = sys_wait4(pid,
86280 (stat_addr ?
86281- (unsigned int __user *) &status : NULL),
86282- options, (struct rusage __user *) &r);
86283+ (unsigned int __force_user *) &status : NULL),
86284+ options, (struct rusage __force_user *) &r);
86285 set_fs (old_fs);
86286
86287 if (ret > 0) {
86288@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
86289 memset(&info, 0, sizeof(info));
86290
86291 set_fs(KERNEL_DS);
86292- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
86293- uru ? (struct rusage __user *)&ru : NULL);
86294+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
86295+ uru ? (struct rusage __force_user *)&ru : NULL);
86296 set_fs(old_fs);
86297
86298 if ((ret < 0) || (info.si_signo == 0))
86299@@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
86300 oldfs = get_fs();
86301 set_fs(KERNEL_DS);
86302 err = sys_timer_settime(timer_id, flags,
86303- (struct itimerspec __user *) &newts,
86304- (struct itimerspec __user *) &oldts);
86305+ (struct itimerspec __force_user *) &newts,
86306+ (struct itimerspec __force_user *) &oldts);
86307 set_fs(oldfs);
86308 if (!err && old && put_compat_itimerspec(old, &oldts))
86309 return -EFAULT;
86310@@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
86311 oldfs = get_fs();
86312 set_fs(KERNEL_DS);
86313 err = sys_timer_gettime(timer_id,
86314- (struct itimerspec __user *) &ts);
86315+ (struct itimerspec __force_user *) &ts);
86316 set_fs(oldfs);
86317 if (!err && put_compat_itimerspec(setting, &ts))
86318 return -EFAULT;
86319@@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
86320 oldfs = get_fs();
86321 set_fs(KERNEL_DS);
86322 err = sys_clock_settime(which_clock,
86323- (struct timespec __user *) &ts);
86324+ (struct timespec __force_user *) &ts);
86325 set_fs(oldfs);
86326 return err;
86327 }
86328@@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
86329 oldfs = get_fs();
86330 set_fs(KERNEL_DS);
86331 err = sys_clock_gettime(which_clock,
86332- (struct timespec __user *) &ts);
86333+ (struct timespec __force_user *) &ts);
86334 set_fs(oldfs);
86335 if (!err && compat_put_timespec(&ts, tp))
86336 return -EFAULT;
86337@@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
86338
86339 oldfs = get_fs();
86340 set_fs(KERNEL_DS);
86341- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
86342+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
86343 set_fs(oldfs);
86344
86345 err = compat_put_timex(utp, &txc);
86346@@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
86347 oldfs = get_fs();
86348 set_fs(KERNEL_DS);
86349 err = sys_clock_getres(which_clock,
86350- (struct timespec __user *) &ts);
86351+ (struct timespec __force_user *) &ts);
86352 set_fs(oldfs);
86353 if (!err && tp && compat_put_timespec(&ts, tp))
86354 return -EFAULT;
86355@@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
86356 struct timespec tu;
86357 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
86358
86359- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
86360+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
86361 oldfs = get_fs();
86362 set_fs(KERNEL_DS);
86363 err = clock_nanosleep_restart(restart);
86364@@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
86365 oldfs = get_fs();
86366 set_fs(KERNEL_DS);
86367 err = sys_clock_nanosleep(which_clock, flags,
86368- (struct timespec __user *) &in,
86369- (struct timespec __user *) &out);
86370+ (struct timespec __force_user *) &in,
86371+ (struct timespec __force_user *) &out);
86372 set_fs(oldfs);
86373
86374 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
86375@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
86376 mm_segment_t old_fs = get_fs();
86377
86378 set_fs(KERNEL_DS);
86379- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
86380+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
86381 set_fs(old_fs);
86382 if (compat_put_timespec(&t, interval))
86383 return -EFAULT;
86384diff --git a/kernel/configs.c b/kernel/configs.c
86385index c18b1f1..b9a0132 100644
86386--- a/kernel/configs.c
86387+++ b/kernel/configs.c
86388@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
86389 struct proc_dir_entry *entry;
86390
86391 /* create the current config file */
86392+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
86393+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
86394+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
86395+ &ikconfig_file_ops);
86396+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86397+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
86398+ &ikconfig_file_ops);
86399+#endif
86400+#else
86401 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
86402 &ikconfig_file_ops);
86403+#endif
86404+
86405 if (!entry)
86406 return -ENOMEM;
86407
86408diff --git a/kernel/cred.c b/kernel/cred.c
86409index e0573a4..26c0fd3 100644
86410--- a/kernel/cred.c
86411+++ b/kernel/cred.c
86412@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
86413 validate_creds(cred);
86414 alter_cred_subscribers(cred, -1);
86415 put_cred(cred);
86416+
86417+#ifdef CONFIG_GRKERNSEC_SETXID
86418+ cred = (struct cred *) tsk->delayed_cred;
86419+ if (cred != NULL) {
86420+ tsk->delayed_cred = NULL;
86421+ validate_creds(cred);
86422+ alter_cred_subscribers(cred, -1);
86423+ put_cred(cred);
86424+ }
86425+#endif
86426 }
86427
86428 /**
86429@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
86430 * Always returns 0 thus allowing this function to be tail-called at the end
86431 * of, say, sys_setgid().
86432 */
86433-int commit_creds(struct cred *new)
86434+static int __commit_creds(struct cred *new)
86435 {
86436 struct task_struct *task = current;
86437 const struct cred *old = task->real_cred;
86438@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
86439
86440 get_cred(new); /* we will require a ref for the subj creds too */
86441
86442+ gr_set_role_label(task, new->uid, new->gid);
86443+
86444 /* dumpability changes */
86445 if (!uid_eq(old->euid, new->euid) ||
86446 !gid_eq(old->egid, new->egid) ||
86447@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
86448 put_cred(old);
86449 return 0;
86450 }
86451+#ifdef CONFIG_GRKERNSEC_SETXID
86452+extern int set_user(struct cred *new);
86453+
86454+void gr_delayed_cred_worker(void)
86455+{
86456+ const struct cred *new = current->delayed_cred;
86457+ struct cred *ncred;
86458+
86459+ current->delayed_cred = NULL;
86460+
86461+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
86462+ // from doing get_cred on it when queueing this
86463+ put_cred(new);
86464+ return;
86465+ } else if (new == NULL)
86466+ return;
86467+
86468+ ncred = prepare_creds();
86469+ if (!ncred)
86470+ goto die;
86471+ // uids
86472+ ncred->uid = new->uid;
86473+ ncred->euid = new->euid;
86474+ ncred->suid = new->suid;
86475+ ncred->fsuid = new->fsuid;
86476+ // gids
86477+ ncred->gid = new->gid;
86478+ ncred->egid = new->egid;
86479+ ncred->sgid = new->sgid;
86480+ ncred->fsgid = new->fsgid;
86481+ // groups
86482+ set_groups(ncred, new->group_info);
86483+ // caps
86484+ ncred->securebits = new->securebits;
86485+ ncred->cap_inheritable = new->cap_inheritable;
86486+ ncred->cap_permitted = new->cap_permitted;
86487+ ncred->cap_effective = new->cap_effective;
86488+ ncred->cap_bset = new->cap_bset;
86489+
86490+ if (set_user(ncred)) {
86491+ abort_creds(ncred);
86492+ goto die;
86493+ }
86494+
86495+ // from doing get_cred on it when queueing this
86496+ put_cred(new);
86497+
86498+ __commit_creds(ncred);
86499+ return;
86500+die:
86501+ // from doing get_cred on it when queueing this
86502+ put_cred(new);
86503+ do_group_exit(SIGKILL);
86504+}
86505+#endif
86506+
86507+int commit_creds(struct cred *new)
86508+{
86509+#ifdef CONFIG_GRKERNSEC_SETXID
86510+ int ret;
86511+ int schedule_it = 0;
86512+ struct task_struct *t;
86513+ unsigned oldsecurebits = current_cred()->securebits;
86514+
86515+ /* we won't get called with tasklist_lock held for writing
86516+ and interrupts disabled as the cred struct in that case is
86517+ init_cred
86518+ */
86519+ if (grsec_enable_setxid && !current_is_single_threaded() &&
86520+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
86521+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
86522+ schedule_it = 1;
86523+ }
86524+ ret = __commit_creds(new);
86525+ if (schedule_it) {
86526+ rcu_read_lock();
86527+ read_lock(&tasklist_lock);
86528+ for (t = next_thread(current); t != current;
86529+ t = next_thread(t)) {
86530+ /* we'll check if the thread has uid 0 in
86531+ * the delayed worker routine
86532+ */
86533+ if (task_securebits(t) == oldsecurebits &&
86534+ t->delayed_cred == NULL) {
86535+ t->delayed_cred = get_cred(new);
86536+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86537+ set_tsk_need_resched(t);
86538+ }
86539+ }
86540+ read_unlock(&tasklist_lock);
86541+ rcu_read_unlock();
86542+ }
86543+
86544+ return ret;
86545+#else
86546+ return __commit_creds(new);
86547+#endif
86548+}
86549+
86550 EXPORT_SYMBOL(commit_creds);
86551
86552 /**
86553diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86554index 2956c8d..cfe1e2e 100644
86555--- a/kernel/debug/debug_core.c
86556+++ b/kernel/debug/debug_core.c
86557@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86558 */
86559 static atomic_t masters_in_kgdb;
86560 static atomic_t slaves_in_kgdb;
86561-static atomic_t kgdb_break_tasklet_var;
86562+static atomic_unchecked_t kgdb_break_tasklet_var;
86563 atomic_t kgdb_setting_breakpoint;
86564
86565 struct task_struct *kgdb_usethread;
86566@@ -134,7 +134,7 @@ int kgdb_single_step;
86567 static pid_t kgdb_sstep_pid;
86568
86569 /* to keep track of the CPU which is doing the single stepping*/
86570-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86571+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86572
86573 /*
86574 * If you are debugging a problem where roundup (the collection of
86575@@ -549,7 +549,7 @@ return_normal:
86576 * kernel will only try for the value of sstep_tries before
86577 * giving up and continuing on.
86578 */
86579- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86580+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86581 (kgdb_info[cpu].task &&
86582 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86583 atomic_set(&kgdb_active, -1);
86584@@ -647,8 +647,8 @@ cpu_master_loop:
86585 }
86586
86587 kgdb_restore:
86588- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86589- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86590+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86591+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86592 if (kgdb_info[sstep_cpu].task)
86593 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86594 else
86595@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
86596 static void kgdb_tasklet_bpt(unsigned long ing)
86597 {
86598 kgdb_breakpoint();
86599- atomic_set(&kgdb_break_tasklet_var, 0);
86600+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86601 }
86602
86603 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86604
86605 void kgdb_schedule_breakpoint(void)
86606 {
86607- if (atomic_read(&kgdb_break_tasklet_var) ||
86608+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86609 atomic_read(&kgdb_active) != -1 ||
86610 atomic_read(&kgdb_setting_breakpoint))
86611 return;
86612- atomic_inc(&kgdb_break_tasklet_var);
86613+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
86614 tasklet_schedule(&kgdb_tasklet_breakpoint);
86615 }
86616 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86617diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86618index 0b097c8..11dd5c5 100644
86619--- a/kernel/debug/kdb/kdb_main.c
86620+++ b/kernel/debug/kdb/kdb_main.c
86621@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86622 continue;
86623
86624 kdb_printf("%-20s%8u 0x%p ", mod->name,
86625- mod->core_size, (void *)mod);
86626+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
86627 #ifdef CONFIG_MODULE_UNLOAD
86628 kdb_printf("%4ld ", module_refcount(mod));
86629 #endif
86630@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86631 kdb_printf(" (Loading)");
86632 else
86633 kdb_printf(" (Live)");
86634- kdb_printf(" 0x%p", mod->module_core);
86635+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86636
86637 #ifdef CONFIG_MODULE_UNLOAD
86638 {
86639diff --git a/kernel/events/core.c b/kernel/events/core.c
86640index 935271c..8888f93 100644
86641--- a/kernel/events/core.c
86642+++ b/kernel/events/core.c
86643@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86644 * 0 - disallow raw tracepoint access for unpriv
86645 * 1 - disallow cpu events for unpriv
86646 * 2 - disallow kernel profiling for unpriv
86647+ * 3 - disallow all unpriv perf event use
86648 */
86649-int sysctl_perf_event_paranoid __read_mostly = 1;
86650+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86651+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86652+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86653+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86654+#else
86655+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86656+#endif
86657
86658 /* Minimum for 512 kiB + 1 user control page */
86659 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86660@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86661
86662 tmp *= sysctl_perf_cpu_time_max_percent;
86663 do_div(tmp, 100);
86664- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86665+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86666 }
86667
86668 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86669@@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86670 }
86671 }
86672
86673-static atomic64_t perf_event_id;
86674+static atomic64_unchecked_t perf_event_id;
86675
86676 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86677 enum event_type_t event_type);
86678@@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
86679
86680 static inline u64 perf_event_count(struct perf_event *event)
86681 {
86682- return local64_read(&event->count) + atomic64_read(&event->child_count);
86683+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86684 }
86685
86686 static u64 perf_event_read(struct perf_event *event)
86687@@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86688 mutex_lock(&event->child_mutex);
86689 total += perf_event_read(event);
86690 *enabled += event->total_time_enabled +
86691- atomic64_read(&event->child_total_time_enabled);
86692+ atomic64_read_unchecked(&event->child_total_time_enabled);
86693 *running += event->total_time_running +
86694- atomic64_read(&event->child_total_time_running);
86695+ atomic64_read_unchecked(&event->child_total_time_running);
86696
86697 list_for_each_entry(child, &event->child_list, child_list) {
86698 total += perf_event_read(child);
86699@@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
86700 userpg->offset -= local64_read(&event->hw.prev_count);
86701
86702 userpg->time_enabled = enabled +
86703- atomic64_read(&event->child_total_time_enabled);
86704+ atomic64_read_unchecked(&event->child_total_time_enabled);
86705
86706 userpg->time_running = running +
86707- atomic64_read(&event->child_total_time_running);
86708+ atomic64_read_unchecked(&event->child_total_time_running);
86709
86710 arch_perf_update_userpage(userpg, now);
86711
86712@@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86713
86714 /* Data. */
86715 sp = perf_user_stack_pointer(regs);
86716- rem = __output_copy_user(handle, (void *) sp, dump_size);
86717+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86718 dyn_size = dump_size - rem;
86719
86720 perf_output_skip(handle, rem);
86721@@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86722 values[n++] = perf_event_count(event);
86723 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86724 values[n++] = enabled +
86725- atomic64_read(&event->child_total_time_enabled);
86726+ atomic64_read_unchecked(&event->child_total_time_enabled);
86727 }
86728 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86729 values[n++] = running +
86730- atomic64_read(&event->child_total_time_running);
86731+ atomic64_read_unchecked(&event->child_total_time_running);
86732 }
86733 if (read_format & PERF_FORMAT_ID)
86734 values[n++] = primary_event_id(event);
86735@@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86736 event->parent = parent_event;
86737
86738 event->ns = get_pid_ns(task_active_pid_ns(current));
86739- event->id = atomic64_inc_return(&perf_event_id);
86740+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
86741
86742 event->state = PERF_EVENT_STATE_INACTIVE;
86743
86744@@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
86745 if (flags & ~PERF_FLAG_ALL)
86746 return -EINVAL;
86747
86748+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86749+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86750+ return -EACCES;
86751+#endif
86752+
86753 err = perf_copy_attr(attr_uptr, &attr);
86754 if (err)
86755 return err;
86756@@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
86757 /*
86758 * Add back the child's count to the parent's count:
86759 */
86760- atomic64_add(child_val, &parent_event->child_count);
86761- atomic64_add(child_event->total_time_enabled,
86762+ atomic64_add_unchecked(child_val, &parent_event->child_count);
86763+ atomic64_add_unchecked(child_event->total_time_enabled,
86764 &parent_event->child_total_time_enabled);
86765- atomic64_add(child_event->total_time_running,
86766+ atomic64_add_unchecked(child_event->total_time_running,
86767 &parent_event->child_total_time_running);
86768
86769 /*
86770diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86771index 569b2187..19940d9 100644
86772--- a/kernel/events/internal.h
86773+++ b/kernel/events/internal.h
86774@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86775 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86776 }
86777
86778-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86779+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86780 static inline unsigned long \
86781 func_name(struct perf_output_handle *handle, \
86782- const void *buf, unsigned long len) \
86783+ const void user *buf, unsigned long len) \
86784 { \
86785 unsigned long size, written; \
86786 \
86787@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86788 return 0;
86789 }
86790
86791-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86792+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86793
86794 static inline unsigned long
86795 memcpy_skip(void *dst, const void *src, unsigned long n)
86796@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86797 return 0;
86798 }
86799
86800-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86801+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86802
86803 #ifndef arch_perf_out_copy_user
86804 #define arch_perf_out_copy_user arch_perf_out_copy_user
86805@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86806 }
86807 #endif
86808
86809-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86810+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86811
86812 /* Callchain handling */
86813 extern struct perf_callchain_entry *
86814diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86815index 04709b6..d330828 100644
86816--- a/kernel/events/uprobes.c
86817+++ b/kernel/events/uprobes.c
86818@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86819 {
86820 struct page *page;
86821 uprobe_opcode_t opcode;
86822- int result;
86823+ long result;
86824
86825 pagefault_disable();
86826 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86827diff --git a/kernel/exit.c b/kernel/exit.c
86828index 6ed6a1d..edecb0e 100644
86829--- a/kernel/exit.c
86830+++ b/kernel/exit.c
86831@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86832 struct task_struct *leader;
86833 int zap_leader;
86834 repeat:
86835+#ifdef CONFIG_NET
86836+ gr_del_task_from_ip_table(p);
86837+#endif
86838+
86839 /* don't need to get the RCU readlock here - the process is dead and
86840 * can't be modifying its own credentials. But shut RCU-lockdep up */
86841 rcu_read_lock();
86842@@ -330,7 +334,7 @@ int allow_signal(int sig)
86843 * know it'll be handled, so that they don't get converted to
86844 * SIGKILL or just silently dropped.
86845 */
86846- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86847+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86848 recalc_sigpending();
86849 spin_unlock_irq(&current->sighand->siglock);
86850 return 0;
86851@@ -699,6 +703,8 @@ void do_exit(long code)
86852 struct task_struct *tsk = current;
86853 int group_dead;
86854
86855+ set_fs(USER_DS);
86856+
86857 profile_task_exit(tsk);
86858
86859 WARN_ON(blk_needs_flush_plug(tsk));
86860@@ -715,7 +721,6 @@ void do_exit(long code)
86861 * mm_release()->clear_child_tid() from writing to a user-controlled
86862 * kernel address.
86863 */
86864- set_fs(USER_DS);
86865
86866 ptrace_event(PTRACE_EVENT_EXIT, code);
86867
86868@@ -774,6 +779,9 @@ void do_exit(long code)
86869 tsk->exit_code = code;
86870 taskstats_exit(tsk, group_dead);
86871
86872+ gr_acl_handle_psacct(tsk, code);
86873+ gr_acl_handle_exit();
86874+
86875 exit_mm(tsk);
86876
86877 if (group_dead)
86878@@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86879 * Take down every thread in the group. This is called by fatal signals
86880 * as well as by sys_exit_group (below).
86881 */
86882-void
86883+__noreturn void
86884 do_group_exit(int exit_code)
86885 {
86886 struct signal_struct *sig = current->signal;
86887diff --git a/kernel/fork.c b/kernel/fork.c
86888index 68b9226..0700bf6 100644
86889--- a/kernel/fork.c
86890+++ b/kernel/fork.c
86891@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86892 # endif
86893 #endif
86894
86895+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86896+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86897+ int node, void **lowmem_stack)
86898+{
86899+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
86900+ void *ret = NULL;
86901+ unsigned int i;
86902+
86903+ *lowmem_stack = alloc_thread_info_node(tsk, node);
86904+ if (*lowmem_stack == NULL)
86905+ goto out;
86906+
86907+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86908+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86909+
86910+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86911+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86912+ if (ret == NULL) {
86913+ free_thread_info(*lowmem_stack);
86914+ *lowmem_stack = NULL;
86915+ }
86916+
86917+out:
86918+ return ret;
86919+}
86920+
86921+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86922+{
86923+ unmap_process_stacks(tsk);
86924+}
86925+#else
86926+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86927+ int node, void **lowmem_stack)
86928+{
86929+ return alloc_thread_info_node(tsk, node);
86930+}
86931+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86932+{
86933+ free_thread_info(ti);
86934+}
86935+#endif
86936+
86937 /* SLAB cache for signal_struct structures (tsk->signal) */
86938 static struct kmem_cache *signal_cachep;
86939
86940@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86941 /* SLAB cache for mm_struct structures (tsk->mm) */
86942 static struct kmem_cache *mm_cachep;
86943
86944-static void account_kernel_stack(struct thread_info *ti, int account)
86945+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86946 {
86947+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86948+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86949+#else
86950 struct zone *zone = page_zone(virt_to_page(ti));
86951+#endif
86952
86953 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86954 }
86955
86956 void free_task(struct task_struct *tsk)
86957 {
86958- account_kernel_stack(tsk->stack, -1);
86959+ account_kernel_stack(tsk, tsk->stack, -1);
86960 arch_release_thread_info(tsk->stack);
86961- free_thread_info(tsk->stack);
86962+ gr_free_thread_info(tsk, tsk->stack);
86963 rt_mutex_debug_task_free(tsk);
86964 ftrace_graph_exit_task(tsk);
86965 put_seccomp_filter(tsk);
86966@@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86967 struct task_struct *tsk;
86968 struct thread_info *ti;
86969 unsigned long *stackend;
86970+ void *lowmem_stack;
86971 int node = tsk_fork_get_node(orig);
86972 int err;
86973
86974@@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86975 if (!tsk)
86976 return NULL;
86977
86978- ti = alloc_thread_info_node(tsk, node);
86979+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86980 if (!ti)
86981 goto free_tsk;
86982
86983@@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86984 goto free_ti;
86985
86986 tsk->stack = ti;
86987+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86988+ tsk->lowmem_stack = lowmem_stack;
86989+#endif
86990
86991 setup_thread_stack(tsk, orig);
86992 clear_user_return_notifier(tsk);
86993@@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86994 *stackend = STACK_END_MAGIC; /* for overflow detection */
86995
86996 #ifdef CONFIG_CC_STACKPROTECTOR
86997- tsk->stack_canary = get_random_int();
86998+ tsk->stack_canary = pax_get_random_long();
86999 #endif
87000
87001 /*
87002@@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
87003 tsk->splice_pipe = NULL;
87004 tsk->task_frag.page = NULL;
87005
87006- account_kernel_stack(ti, 1);
87007+ account_kernel_stack(tsk, ti, 1);
87008
87009 return tsk;
87010
87011 free_ti:
87012- free_thread_info(ti);
87013+ gr_free_thread_info(tsk, ti);
87014 free_tsk:
87015 free_task_struct(tsk);
87016 return NULL;
87017 }
87018
87019 #ifdef CONFIG_MMU
87020-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
87021+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
87022+{
87023+ struct vm_area_struct *tmp;
87024+ unsigned long charge;
87025+ struct file *file;
87026+ int retval;
87027+
87028+ charge = 0;
87029+ if (mpnt->vm_flags & VM_ACCOUNT) {
87030+ unsigned long len = vma_pages(mpnt);
87031+
87032+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
87033+ goto fail_nomem;
87034+ charge = len;
87035+ }
87036+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
87037+ if (!tmp)
87038+ goto fail_nomem;
87039+ *tmp = *mpnt;
87040+ tmp->vm_mm = mm;
87041+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
87042+ retval = vma_dup_policy(mpnt, tmp);
87043+ if (retval)
87044+ goto fail_nomem_policy;
87045+ if (anon_vma_fork(tmp, mpnt))
87046+ goto fail_nomem_anon_vma_fork;
87047+ tmp->vm_flags &= ~VM_LOCKED;
87048+ tmp->vm_next = tmp->vm_prev = NULL;
87049+ tmp->vm_mirror = NULL;
87050+ file = tmp->vm_file;
87051+ if (file) {
87052+ struct inode *inode = file_inode(file);
87053+ struct address_space *mapping = file->f_mapping;
87054+
87055+ get_file(file);
87056+ if (tmp->vm_flags & VM_DENYWRITE)
87057+ atomic_dec(&inode->i_writecount);
87058+ mutex_lock(&mapping->i_mmap_mutex);
87059+ if (tmp->vm_flags & VM_SHARED)
87060+ mapping->i_mmap_writable++;
87061+ flush_dcache_mmap_lock(mapping);
87062+ /* insert tmp into the share list, just after mpnt */
87063+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
87064+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
87065+ else
87066+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
87067+ flush_dcache_mmap_unlock(mapping);
87068+ mutex_unlock(&mapping->i_mmap_mutex);
87069+ }
87070+
87071+ /*
87072+ * Clear hugetlb-related page reserves for children. This only
87073+ * affects MAP_PRIVATE mappings. Faults generated by the child
87074+ * are not guaranteed to succeed, even if read-only
87075+ */
87076+ if (is_vm_hugetlb_page(tmp))
87077+ reset_vma_resv_huge_pages(tmp);
87078+
87079+ return tmp;
87080+
87081+fail_nomem_anon_vma_fork:
87082+ mpol_put(vma_policy(tmp));
87083+fail_nomem_policy:
87084+ kmem_cache_free(vm_area_cachep, tmp);
87085+fail_nomem:
87086+ vm_unacct_memory(charge);
87087+ return NULL;
87088+}
87089+
87090+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
87091 {
87092 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
87093 struct rb_node **rb_link, *rb_parent;
87094 int retval;
87095- unsigned long charge;
87096
87097 uprobe_start_dup_mmap();
87098 down_write(&oldmm->mmap_sem);
87099@@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
87100
87101 prev = NULL;
87102 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
87103- struct file *file;
87104-
87105 if (mpnt->vm_flags & VM_DONTCOPY) {
87106 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
87107 -vma_pages(mpnt));
87108 continue;
87109 }
87110- charge = 0;
87111- if (mpnt->vm_flags & VM_ACCOUNT) {
87112- unsigned long len = vma_pages(mpnt);
87113-
87114- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
87115- goto fail_nomem;
87116- charge = len;
87117- }
87118- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
87119- if (!tmp)
87120- goto fail_nomem;
87121- *tmp = *mpnt;
87122- INIT_LIST_HEAD(&tmp->anon_vma_chain);
87123- retval = vma_dup_policy(mpnt, tmp);
87124- if (retval)
87125- goto fail_nomem_policy;
87126- tmp->vm_mm = mm;
87127- if (anon_vma_fork(tmp, mpnt))
87128- goto fail_nomem_anon_vma_fork;
87129- tmp->vm_flags &= ~VM_LOCKED;
87130- tmp->vm_next = tmp->vm_prev = NULL;
87131- file = tmp->vm_file;
87132- if (file) {
87133- struct inode *inode = file_inode(file);
87134- struct address_space *mapping = file->f_mapping;
87135-
87136- get_file(file);
87137- if (tmp->vm_flags & VM_DENYWRITE)
87138- atomic_dec(&inode->i_writecount);
87139- mutex_lock(&mapping->i_mmap_mutex);
87140- if (tmp->vm_flags & VM_SHARED)
87141- mapping->i_mmap_writable++;
87142- flush_dcache_mmap_lock(mapping);
87143- /* insert tmp into the share list, just after mpnt */
87144- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
87145- vma_nonlinear_insert(tmp,
87146- &mapping->i_mmap_nonlinear);
87147- else
87148- vma_interval_tree_insert_after(tmp, mpnt,
87149- &mapping->i_mmap);
87150- flush_dcache_mmap_unlock(mapping);
87151- mutex_unlock(&mapping->i_mmap_mutex);
87152+ tmp = dup_vma(mm, oldmm, mpnt);
87153+ if (!tmp) {
87154+ retval = -ENOMEM;
87155+ goto out;
87156 }
87157
87158 /*
87159@@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
87160 if (retval)
87161 goto out;
87162 }
87163+
87164+#ifdef CONFIG_PAX_SEGMEXEC
87165+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
87166+ struct vm_area_struct *mpnt_m;
87167+
87168+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
87169+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
87170+
87171+ if (!mpnt->vm_mirror)
87172+ continue;
87173+
87174+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
87175+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
87176+ mpnt->vm_mirror = mpnt_m;
87177+ } else {
87178+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
87179+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
87180+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
87181+ mpnt->vm_mirror->vm_mirror = mpnt;
87182+ }
87183+ }
87184+ BUG_ON(mpnt_m);
87185+ }
87186+#endif
87187+
87188 /* a new mm has just been created */
87189 arch_dup_mmap(oldmm, mm);
87190 retval = 0;
87191@@ -472,14 +575,6 @@ out:
87192 up_write(&oldmm->mmap_sem);
87193 uprobe_end_dup_mmap();
87194 return retval;
87195-fail_nomem_anon_vma_fork:
87196- mpol_put(vma_policy(tmp));
87197-fail_nomem_policy:
87198- kmem_cache_free(vm_area_cachep, tmp);
87199-fail_nomem:
87200- retval = -ENOMEM;
87201- vm_unacct_memory(charge);
87202- goto out;
87203 }
87204
87205 static inline int mm_alloc_pgd(struct mm_struct *mm)
87206@@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
87207 return ERR_PTR(err);
87208
87209 mm = get_task_mm(task);
87210- if (mm && mm != current->mm &&
87211- !ptrace_may_access(task, mode)) {
87212+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
87213+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
87214 mmput(mm);
87215 mm = ERR_PTR(-EACCES);
87216 }
87217@@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
87218 spin_unlock(&fs->lock);
87219 return -EAGAIN;
87220 }
87221- fs->users++;
87222+ atomic_inc(&fs->users);
87223 spin_unlock(&fs->lock);
87224 return 0;
87225 }
87226 tsk->fs = copy_fs_struct(fs);
87227 if (!tsk->fs)
87228 return -ENOMEM;
87229+ /* Carry through gr_chroot_dentry and is_chrooted instead
87230+ of recomputing it here. Already copied when the task struct
87231+ is duplicated. This allows pivot_root to not be treated as
87232+ a chroot
87233+ */
87234+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
87235+
87236 return 0;
87237 }
87238
87239@@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
87240 * parts of the process environment (as per the clone
87241 * flags). The actual kick-off is left to the caller.
87242 */
87243-static struct task_struct *copy_process(unsigned long clone_flags,
87244+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
87245 unsigned long stack_start,
87246 unsigned long stack_size,
87247 int __user *child_tidptr,
87248@@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
87249 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
87250 #endif
87251 retval = -EAGAIN;
87252+
87253+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
87254+
87255 if (atomic_read(&p->real_cred->user->processes) >=
87256 task_rlimit(p, RLIMIT_NPROC)) {
87257 if (p->real_cred->user != INIT_USER &&
87258@@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
87259 goto bad_fork_free_pid;
87260 }
87261
87262+ /* synchronizes with gr_set_acls()
87263+ we need to call this past the point of no return for fork()
87264+ */
87265+ gr_copy_label(p);
87266+
87267 if (likely(p->pid)) {
87268 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
87269
87270@@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
87271 bad_fork_free:
87272 free_task(p);
87273 fork_out:
87274+ gr_log_forkfail(retval);
87275+
87276 return ERR_PTR(retval);
87277 }
87278
87279@@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
87280
87281 p = copy_process(clone_flags, stack_start, stack_size,
87282 child_tidptr, NULL, trace);
87283+ add_latent_entropy();
87284 /*
87285 * Do this prior waking up the new thread - the thread pointer
87286 * might get invalid after that point, if the thread exits quickly.
87287@@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
87288 if (clone_flags & CLONE_PARENT_SETTID)
87289 put_user(nr, parent_tidptr);
87290
87291+ gr_handle_brute_check();
87292+
87293 if (clone_flags & CLONE_VFORK) {
87294 p->vfork_done = &vfork;
87295 init_completion(&vfork);
87296@@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
87297 mm_cachep = kmem_cache_create("mm_struct",
87298 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
87299 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
87300- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
87301+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
87302 mmap_init();
87303 nsproxy_cache_init();
87304 }
87305@@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
87306 return 0;
87307
87308 /* don't need lock here; in the worst case we'll do useless copy */
87309- if (fs->users == 1)
87310+ if (atomic_read(&fs->users) == 1)
87311 return 0;
87312
87313 *new_fsp = copy_fs_struct(fs);
87314@@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
87315 fs = current->fs;
87316 spin_lock(&fs->lock);
87317 current->fs = new_fs;
87318- if (--fs->users)
87319+ gr_set_chroot_entries(current, &current->fs->root);
87320+ if (atomic_dec_return(&fs->users))
87321 new_fs = NULL;
87322 else
87323 new_fs = fs;
87324diff --git a/kernel/futex.c b/kernel/futex.c
87325index de938d2..c566038 100644
87326--- a/kernel/futex.c
87327+++ b/kernel/futex.c
87328@@ -202,7 +202,7 @@ struct futex_pi_state {
87329 atomic_t refcount;
87330
87331 union futex_key key;
87332-};
87333+} __randomize_layout;
87334
87335 /**
87336 * struct futex_q - The hashed futex queue entry, one per waiting task
87337@@ -236,7 +236,7 @@ struct futex_q {
87338 struct rt_mutex_waiter *rt_waiter;
87339 union futex_key *requeue_pi_key;
87340 u32 bitset;
87341-};
87342+} __randomize_layout;
87343
87344 static const struct futex_q futex_q_init = {
87345 /* list gets initialized in queue_me()*/
87346@@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
87347 struct page *page, *page_head;
87348 int err, ro = 0;
87349
87350+#ifdef CONFIG_PAX_SEGMEXEC
87351+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
87352+ return -EFAULT;
87353+#endif
87354+
87355 /*
87356 * The futex address must be "naturally" aligned.
87357 */
87358@@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
87359
87360 static int get_futex_value_locked(u32 *dest, u32 __user *from)
87361 {
87362- int ret;
87363+ unsigned long ret;
87364
87365 pagefault_disable();
87366 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
87367@@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
87368 {
87369 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
87370 u32 curval;
87371+ mm_segment_t oldfs;
87372
87373 /*
87374 * This will fail and we want it. Some arch implementations do
87375@@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
87376 * implementation, the non-functional ones will return
87377 * -ENOSYS.
87378 */
87379+ oldfs = get_fs();
87380+ set_fs(USER_DS);
87381 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
87382 futex_cmpxchg_enabled = 1;
87383+ set_fs(oldfs);
87384 #endif
87385 }
87386
87387diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
87388index 55c8c93..9ba7ad6 100644
87389--- a/kernel/futex_compat.c
87390+++ b/kernel/futex_compat.c
87391@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
87392 return 0;
87393 }
87394
87395-static void __user *futex_uaddr(struct robust_list __user *entry,
87396+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
87397 compat_long_t futex_offset)
87398 {
87399 compat_uptr_t base = ptr_to_compat(entry);
87400diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
87401index f45b75b..bfac6d5 100644
87402--- a/kernel/gcov/base.c
87403+++ b/kernel/gcov/base.c
87404@@ -108,11 +108,6 @@ void gcov_enable_events(void)
87405 }
87406
87407 #ifdef CONFIG_MODULES
87408-static inline int within(void *addr, void *start, unsigned long size)
87409-{
87410- return ((addr >= start) && (addr < start + size));
87411-}
87412-
87413 /* Update list and generate events when modules are unloaded. */
87414 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87415 void *data)
87416@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87417
87418 /* Remove entries located in module from linked list. */
87419 while ((info = gcov_info_next(info))) {
87420- if (within(info, mod->module_core, mod->core_size)) {
87421+ if (within_module_core_rw((unsigned long)info, mod)) {
87422 gcov_info_unlink(prev, info);
87423 if (gcov_events_enabled)
87424 gcov_event(GCOV_REMOVE, info);
87425diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
87426index e0501fe..312edd6 100644
87427--- a/kernel/hrtimer.c
87428+++ b/kernel/hrtimer.c
87429@@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
87430 local_irq_restore(flags);
87431 }
87432
87433-static void run_hrtimer_softirq(struct softirq_action *h)
87434+static __latent_entropy void run_hrtimer_softirq(void)
87435 {
87436 hrtimer_peek_ahead_timers();
87437 }
87438diff --git a/kernel/irq_work.c b/kernel/irq_work.c
87439index a82170e..5b01e7f 100644
87440--- a/kernel/irq_work.c
87441+++ b/kernel/irq_work.c
87442@@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
87443 return NOTIFY_OK;
87444 }
87445
87446-static struct notifier_block cpu_notify;
87447+static struct notifier_block cpu_notify = {
87448+ .notifier_call = irq_work_cpu_notify,
87449+ .priority = 0,
87450+};
87451
87452 static __init int irq_work_init_cpu_notifier(void)
87453 {
87454- cpu_notify.notifier_call = irq_work_cpu_notify;
87455- cpu_notify.priority = 0;
87456 register_cpu_notifier(&cpu_notify);
87457 return 0;
87458 }
87459diff --git a/kernel/jump_label.c b/kernel/jump_label.c
87460index 9019f15..9a3c42e 100644
87461--- a/kernel/jump_label.c
87462+++ b/kernel/jump_label.c
87463@@ -14,6 +14,7 @@
87464 #include <linux/err.h>
87465 #include <linux/static_key.h>
87466 #include <linux/jump_label_ratelimit.h>
87467+#include <linux/mm.h>
87468
87469 #ifdef HAVE_JUMP_LABEL
87470
87471@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
87472
87473 size = (((unsigned long)stop - (unsigned long)start)
87474 / sizeof(struct jump_entry));
87475+ pax_open_kernel();
87476 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
87477+ pax_close_kernel();
87478 }
87479
87480 static void jump_label_update(struct static_key *key, int enable);
87481@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
87482 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
87483 struct jump_entry *iter;
87484
87485+ pax_open_kernel();
87486 for (iter = iter_start; iter < iter_stop; iter++) {
87487 if (within_module_init(iter->code, mod))
87488 iter->code = 0;
87489 }
87490+ pax_close_kernel();
87491 }
87492
87493 static int
87494diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
87495index cb0cf37..b69e161 100644
87496--- a/kernel/kallsyms.c
87497+++ b/kernel/kallsyms.c
87498@@ -11,6 +11,9 @@
87499 * Changed the compression method from stem compression to "table lookup"
87500 * compression (see scripts/kallsyms.c for a more complete description)
87501 */
87502+#ifdef CONFIG_GRKERNSEC_HIDESYM
87503+#define __INCLUDED_BY_HIDESYM 1
87504+#endif
87505 #include <linux/kallsyms.h>
87506 #include <linux/module.h>
87507 #include <linux/init.h>
87508@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
87509
87510 static inline int is_kernel_inittext(unsigned long addr)
87511 {
87512+ if (system_state != SYSTEM_BOOTING)
87513+ return 0;
87514+
87515 if (addr >= (unsigned long)_sinittext
87516 && addr <= (unsigned long)_einittext)
87517 return 1;
87518 return 0;
87519 }
87520
87521+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87522+#ifdef CONFIG_MODULES
87523+static inline int is_module_text(unsigned long addr)
87524+{
87525+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
87526+ return 1;
87527+
87528+ addr = ktla_ktva(addr);
87529+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
87530+}
87531+#else
87532+static inline int is_module_text(unsigned long addr)
87533+{
87534+ return 0;
87535+}
87536+#endif
87537+#endif
87538+
87539 static inline int is_kernel_text(unsigned long addr)
87540 {
87541 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
87542@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
87543
87544 static inline int is_kernel(unsigned long addr)
87545 {
87546+
87547+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87548+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
87549+ return 1;
87550+
87551+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
87552+#else
87553 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
87554+#endif
87555+
87556 return 1;
87557 return in_gate_area_no_mm(addr);
87558 }
87559
87560 static int is_ksym_addr(unsigned long addr)
87561 {
87562+
87563+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87564+ if (is_module_text(addr))
87565+ return 0;
87566+#endif
87567+
87568 if (all_var)
87569 return is_kernel(addr);
87570
87571@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
87572
87573 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
87574 {
87575- iter->name[0] = '\0';
87576 iter->nameoff = get_symbol_offset(new_pos);
87577 iter->pos = new_pos;
87578 }
87579@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
87580 {
87581 struct kallsym_iter *iter = m->private;
87582
87583+#ifdef CONFIG_GRKERNSEC_HIDESYM
87584+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
87585+ return 0;
87586+#endif
87587+
87588 /* Some debugging symbols have no name. Ignore them. */
87589 if (!iter->name[0])
87590 return 0;
87591@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
87592 */
87593 type = iter->exported ? toupper(iter->type) :
87594 tolower(iter->type);
87595+
87596 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87597 type, iter->name, iter->module_name);
87598 } else
87599@@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87600 struct kallsym_iter *iter;
87601 int ret;
87602
87603- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87604+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87605 if (!iter)
87606 return -ENOMEM;
87607 reset_iter(iter, 0);
87608diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87609index e30ac0f..3528cac 100644
87610--- a/kernel/kcmp.c
87611+++ b/kernel/kcmp.c
87612@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87613 struct task_struct *task1, *task2;
87614 int ret;
87615
87616+#ifdef CONFIG_GRKERNSEC
87617+ return -ENOSYS;
87618+#endif
87619+
87620 rcu_read_lock();
87621
87622 /*
87623diff --git a/kernel/kexec.c b/kernel/kexec.c
87624index 28c5706..bfc8388 100644
87625--- a/kernel/kexec.c
87626+++ b/kernel/kexec.c
87627@@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
87628 compat_ulong_t, flags)
87629 {
87630 struct compat_kexec_segment in;
87631- struct kexec_segment out, __user *ksegments;
87632+ struct kexec_segment out;
87633+ struct kexec_segment __user *ksegments;
87634 unsigned long i, result;
87635
87636 /* Don't allow clients that don't understand the native
87637diff --git a/kernel/kmod.c b/kernel/kmod.c
87638index 6b375af..eaff670 100644
87639--- a/kernel/kmod.c
87640+++ b/kernel/kmod.c
87641@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87642 kfree(info->argv);
87643 }
87644
87645-static int call_modprobe(char *module_name, int wait)
87646+static int call_modprobe(char *module_name, char *module_param, int wait)
87647 {
87648 struct subprocess_info *info;
87649 static char *envp[] = {
87650@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87651 NULL
87652 };
87653
87654- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87655+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87656 if (!argv)
87657 goto out;
87658
87659@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87660 argv[1] = "-q";
87661 argv[2] = "--";
87662 argv[3] = module_name; /* check free_modprobe_argv() */
87663- argv[4] = NULL;
87664+ argv[4] = module_param;
87665+ argv[5] = NULL;
87666
87667 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87668 NULL, free_modprobe_argv, NULL);
87669@@ -129,9 +130,8 @@ out:
87670 * If module auto-loading support is disabled then this function
87671 * becomes a no-operation.
87672 */
87673-int __request_module(bool wait, const char *fmt, ...)
87674+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87675 {
87676- va_list args;
87677 char module_name[MODULE_NAME_LEN];
87678 unsigned int max_modprobes;
87679 int ret;
87680@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87681 if (!modprobe_path[0])
87682 return 0;
87683
87684- va_start(args, fmt);
87685- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87686- va_end(args);
87687+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87688 if (ret >= MODULE_NAME_LEN)
87689 return -ENAMETOOLONG;
87690
87691@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87692 if (ret)
87693 return ret;
87694
87695+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87696+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87697+ /* hack to workaround consolekit/udisks stupidity */
87698+ read_lock(&tasklist_lock);
87699+ if (!strcmp(current->comm, "mount") &&
87700+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87701+ read_unlock(&tasklist_lock);
87702+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87703+ return -EPERM;
87704+ }
87705+ read_unlock(&tasklist_lock);
87706+ }
87707+#endif
87708+
87709 /* If modprobe needs a service that is in a module, we get a recursive
87710 * loop. Limit the number of running kmod threads to max_threads/2 or
87711 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87712@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87713
87714 trace_module_request(module_name, wait, _RET_IP_);
87715
87716- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87717+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87718
87719 atomic_dec(&kmod_concurrent);
87720 return ret;
87721 }
87722+
87723+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87724+{
87725+ va_list args;
87726+ int ret;
87727+
87728+ va_start(args, fmt);
87729+ ret = ____request_module(wait, module_param, fmt, args);
87730+ va_end(args);
87731+
87732+ return ret;
87733+}
87734+
87735+int __request_module(bool wait, const char *fmt, ...)
87736+{
87737+ va_list args;
87738+ int ret;
87739+
87740+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87741+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87742+ char module_param[MODULE_NAME_LEN];
87743+
87744+ memset(module_param, 0, sizeof(module_param));
87745+
87746+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87747+
87748+ va_start(args, fmt);
87749+ ret = ____request_module(wait, module_param, fmt, args);
87750+ va_end(args);
87751+
87752+ return ret;
87753+ }
87754+#endif
87755+
87756+ va_start(args, fmt);
87757+ ret = ____request_module(wait, NULL, fmt, args);
87758+ va_end(args);
87759+
87760+ return ret;
87761+}
87762+
87763 EXPORT_SYMBOL(__request_module);
87764 #endif /* CONFIG_MODULES */
87765
87766@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87767 */
87768 set_user_nice(current, 0);
87769
87770+#ifdef CONFIG_GRKERNSEC
87771+ /* this is race-free as far as userland is concerned as we copied
87772+ out the path to be used prior to this point and are now operating
87773+ on that copy
87774+ */
87775+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87776+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87777+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87778+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87779+ retval = -EPERM;
87780+ goto fail;
87781+ }
87782+#endif
87783+
87784 retval = -ENOMEM;
87785 new = prepare_kernel_cred(current);
87786 if (!new)
87787@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87788 commit_creds(new);
87789
87790 retval = do_execve(getname_kernel(sub_info->path),
87791- (const char __user *const __user *)sub_info->argv,
87792- (const char __user *const __user *)sub_info->envp);
87793+ (const char __user *const __force_user *)sub_info->argv,
87794+ (const char __user *const __force_user *)sub_info->envp);
87795 if (!retval)
87796 return 0;
87797
87798@@ -260,6 +327,10 @@ static int call_helper(void *data)
87799
87800 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87801 {
87802+#ifdef CONFIG_GRKERNSEC
87803+ kfree(info->path);
87804+ info->path = info->origpath;
87805+#endif
87806 if (info->cleanup)
87807 (*info->cleanup)(info);
87808 kfree(info);
87809@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87810 *
87811 * Thus the __user pointer cast is valid here.
87812 */
87813- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87814+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87815
87816 /*
87817 * If ret is 0, either ____call_usermodehelper failed and the
87818@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87819 goto out;
87820
87821 INIT_WORK(&sub_info->work, __call_usermodehelper);
87822+#ifdef CONFIG_GRKERNSEC
87823+ sub_info->origpath = path;
87824+ sub_info->path = kstrdup(path, gfp_mask);
87825+#else
87826 sub_info->path = path;
87827+#endif
87828 sub_info->argv = argv;
87829 sub_info->envp = envp;
87830
87831@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87832 static int proc_cap_handler(struct ctl_table *table, int write,
87833 void __user *buffer, size_t *lenp, loff_t *ppos)
87834 {
87835- struct ctl_table t;
87836+ ctl_table_no_const t;
87837 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87838 kernel_cap_t new_cap;
87839 int err, i;
87840diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87841index ceeadfc..11c18b6 100644
87842--- a/kernel/kprobes.c
87843+++ b/kernel/kprobes.c
87844@@ -31,6 +31,9 @@
87845 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87846 * <prasanna@in.ibm.com> added function-return probes.
87847 */
87848+#ifdef CONFIG_GRKERNSEC_HIDESYM
87849+#define __INCLUDED_BY_HIDESYM 1
87850+#endif
87851 #include <linux/kprobes.h>
87852 #include <linux/hash.h>
87853 #include <linux/init.h>
87854@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87855
87856 static void *alloc_insn_page(void)
87857 {
87858- return module_alloc(PAGE_SIZE);
87859+ return module_alloc_exec(PAGE_SIZE);
87860 }
87861
87862 static void free_insn_page(void *page)
87863 {
87864- module_free(NULL, page);
87865+ module_free_exec(NULL, page);
87866 }
87867
87868 struct kprobe_insn_cache kprobe_insn_slots = {
87869@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87870 kprobe_type = "k";
87871
87872 if (sym)
87873- seq_printf(pi, "%p %s %s+0x%x %s ",
87874+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87875 p->addr, kprobe_type, sym, offset,
87876 (modname ? modname : " "));
87877 else
87878- seq_printf(pi, "%p %s %p ",
87879+ seq_printf(pi, "%pK %s %pK ",
87880 p->addr, kprobe_type, p->addr);
87881
87882 if (!pp)
87883diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87884index 2495a9b..071b906 100644
87885--- a/kernel/ksysfs.c
87886+++ b/kernel/ksysfs.c
87887@@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87888 {
87889 if (count+1 > UEVENT_HELPER_PATH_LEN)
87890 return -ENOENT;
87891+ if (!capable(CAP_SYS_ADMIN))
87892+ return -EPERM;
87893 memcpy(uevent_helper, buf, count);
87894 uevent_helper[count] = '\0';
87895 if (count && uevent_helper[count-1] == '\n')
87896@@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87897 return count;
87898 }
87899
87900-static struct bin_attribute notes_attr = {
87901+static bin_attribute_no_const notes_attr __read_only = {
87902 .attr = {
87903 .name = "notes",
87904 .mode = S_IRUGO,
87905diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87906index d24e433..fa04fb8 100644
87907--- a/kernel/locking/lockdep.c
87908+++ b/kernel/locking/lockdep.c
87909@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87910 end = (unsigned long) &_end,
87911 addr = (unsigned long) obj;
87912
87913+#ifdef CONFIG_PAX_KERNEXEC
87914+ start = ktla_ktva(start);
87915+#endif
87916+
87917 /*
87918 * static variable?
87919 */
87920@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87921 if (!static_obj(lock->key)) {
87922 debug_locks_off();
87923 printk("INFO: trying to register non-static key.\n");
87924+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87925 printk("the code is fine but needs lockdep annotation.\n");
87926 printk("turning off the locking correctness validator.\n");
87927 dump_stack();
87928@@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87929 if (!class)
87930 return 0;
87931 }
87932- atomic_inc((atomic_t *)&class->ops);
87933+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87934 if (very_verbose(class)) {
87935 printk("\nacquire class [%p] %s", class->key, class->name);
87936 if (class->name_version > 1)
87937diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87938index ef43ac4..2720dfa 100644
87939--- a/kernel/locking/lockdep_proc.c
87940+++ b/kernel/locking/lockdep_proc.c
87941@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87942 return 0;
87943 }
87944
87945- seq_printf(m, "%p", class->key);
87946+ seq_printf(m, "%pK", class->key);
87947 #ifdef CONFIG_DEBUG_LOCKDEP
87948 seq_printf(m, " OPS:%8ld", class->ops);
87949 #endif
87950@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87951
87952 list_for_each_entry(entry, &class->locks_after, entry) {
87953 if (entry->distance == 1) {
87954- seq_printf(m, " -> [%p] ", entry->class->key);
87955+ seq_printf(m, " -> [%pK] ", entry->class->key);
87956 print_name(m, entry->class);
87957 seq_puts(m, "\n");
87958 }
87959@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87960 if (!class->key)
87961 continue;
87962
87963- seq_printf(m, "[%p] ", class->key);
87964+ seq_printf(m, "[%pK] ", class->key);
87965 print_name(m, class);
87966 seq_puts(m, "\n");
87967 }
87968@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87969 if (!i)
87970 seq_line(m, '-', 40-namelen, namelen);
87971
87972- snprintf(ip, sizeof(ip), "[<%p>]",
87973+ snprintf(ip, sizeof(ip), "[<%pK>]",
87974 (void *)class->contention_point[i]);
87975 seq_printf(m, "%40s %14lu %29s %pS\n",
87976 name, stats->contention_point[i],
87977@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87978 if (!i)
87979 seq_line(m, '-', 40-namelen, namelen);
87980
87981- snprintf(ip, sizeof(ip), "[<%p>]",
87982+ snprintf(ip, sizeof(ip), "[<%pK>]",
87983 (void *)class->contending_point[i]);
87984 seq_printf(m, "%40s %14lu %29s %pS\n",
87985 name, stats->contending_point[i],
87986diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87987index 838dc9e..760e158 100644
87988--- a/kernel/locking/mcs_spinlock.c
87989+++ b/kernel/locking/mcs_spinlock.c
87990@@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87991 if (likely(prev == NULL))
87992 return true;
87993
87994- ACCESS_ONCE(prev->next) = node;
87995+ ACCESS_ONCE_RW(prev->next) = node;
87996
87997 /*
87998 * Normally @prev is untouchable after the above store; because at that
87999@@ -143,8 +143,8 @@ unqueue:
88000 * it will wait in Step-A.
88001 */
88002
88003- ACCESS_ONCE(next->prev) = prev;
88004- ACCESS_ONCE(prev->next) = next;
88005+ ACCESS_ONCE_RW(next->prev) = prev;
88006+ ACCESS_ONCE_RW(prev->next) = next;
88007
88008 return false;
88009 }
88010@@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
88011 */
88012 next = xchg(&node->next, NULL);
88013 if (next) {
88014- ACCESS_ONCE(next->locked) = 1;
88015+ ACCESS_ONCE_RW(next->locked) = 1;
88016 return;
88017 }
88018
88019 next = osq_wait_next(lock, node, NULL);
88020 if (next)
88021- ACCESS_ONCE(next->locked) = 1;
88022+ ACCESS_ONCE_RW(next->locked) = 1;
88023 }
88024
88025 #endif
88026diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
88027index a2dbac4..e02a34a 100644
88028--- a/kernel/locking/mcs_spinlock.h
88029+++ b/kernel/locking/mcs_spinlock.h
88030@@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
88031 */
88032 return;
88033 }
88034- ACCESS_ONCE(prev->next) = node;
88035+ ACCESS_ONCE_RW(prev->next) = node;
88036
88037 /* Wait until the lock holder passes the lock down. */
88038 arch_mcs_spin_lock_contended(&node->locked);
88039diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
88040index 5cf6731..ce3bc5a 100644
88041--- a/kernel/locking/mutex-debug.c
88042+++ b/kernel/locking/mutex-debug.c
88043@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
88044 }
88045
88046 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
88047- struct thread_info *ti)
88048+ struct task_struct *task)
88049 {
88050 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
88051
88052 /* Mark the current thread as blocked on the lock: */
88053- ti->task->blocked_on = waiter;
88054+ task->blocked_on = waiter;
88055 }
88056
88057 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
88058- struct thread_info *ti)
88059+ struct task_struct *task)
88060 {
88061 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
88062- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
88063- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
88064- ti->task->blocked_on = NULL;
88065+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
88066+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
88067+ task->blocked_on = NULL;
88068
88069 list_del_init(&waiter->list);
88070 waiter->task = NULL;
88071diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
88072index 0799fd3..d06ae3b 100644
88073--- a/kernel/locking/mutex-debug.h
88074+++ b/kernel/locking/mutex-debug.h
88075@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
88076 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
88077 extern void debug_mutex_add_waiter(struct mutex *lock,
88078 struct mutex_waiter *waiter,
88079- struct thread_info *ti);
88080+ struct task_struct *task);
88081 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
88082- struct thread_info *ti);
88083+ struct task_struct *task);
88084 extern void debug_mutex_unlock(struct mutex *lock);
88085 extern void debug_mutex_init(struct mutex *lock, const char *name,
88086 struct lock_class_key *key);
88087diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
88088index bc73d33..6f308aa 100644
88089--- a/kernel/locking/mutex.c
88090+++ b/kernel/locking/mutex.c
88091@@ -490,7 +490,7 @@ slowpath:
88092 goto skip_wait;
88093
88094 debug_mutex_lock_common(lock, &waiter);
88095- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
88096+ debug_mutex_add_waiter(lock, &waiter, task);
88097
88098 /* add waiting tasks to the end of the waitqueue (FIFO): */
88099 list_add_tail(&waiter.list, &lock->wait_list);
88100@@ -534,7 +534,7 @@ slowpath:
88101 schedule_preempt_disabled();
88102 spin_lock_mutex(&lock->wait_lock, flags);
88103 }
88104- mutex_remove_waiter(lock, &waiter, current_thread_info());
88105+ mutex_remove_waiter(lock, &waiter, task);
88106 /* set it to 0 if there are no waiters left: */
88107 if (likely(list_empty(&lock->wait_list)))
88108 atomic_set(&lock->count, 0);
88109@@ -571,7 +571,7 @@ skip_wait:
88110 return 0;
88111
88112 err:
88113- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
88114+ mutex_remove_waiter(lock, &waiter, task);
88115 spin_unlock_mutex(&lock->wait_lock, flags);
88116 debug_mutex_free_waiter(&waiter);
88117 mutex_release(&lock->dep_map, 1, ip);
88118diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
88119index 1d96dd0..994ff19 100644
88120--- a/kernel/locking/rtmutex-tester.c
88121+++ b/kernel/locking/rtmutex-tester.c
88122@@ -22,7 +22,7 @@
88123 #define MAX_RT_TEST_MUTEXES 8
88124
88125 static spinlock_t rttest_lock;
88126-static atomic_t rttest_event;
88127+static atomic_unchecked_t rttest_event;
88128
88129 struct test_thread_data {
88130 int opcode;
88131@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88132
88133 case RTTEST_LOCKCONT:
88134 td->mutexes[td->opdata] = 1;
88135- td->event = atomic_add_return(1, &rttest_event);
88136+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88137 return 0;
88138
88139 case RTTEST_RESET:
88140@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88141 return 0;
88142
88143 case RTTEST_RESETEVENT:
88144- atomic_set(&rttest_event, 0);
88145+ atomic_set_unchecked(&rttest_event, 0);
88146 return 0;
88147
88148 default:
88149@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88150 return ret;
88151
88152 td->mutexes[id] = 1;
88153- td->event = atomic_add_return(1, &rttest_event);
88154+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88155 rt_mutex_lock(&mutexes[id]);
88156- td->event = atomic_add_return(1, &rttest_event);
88157+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88158 td->mutexes[id] = 4;
88159 return 0;
88160
88161@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88162 return ret;
88163
88164 td->mutexes[id] = 1;
88165- td->event = atomic_add_return(1, &rttest_event);
88166+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88167 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
88168- td->event = atomic_add_return(1, &rttest_event);
88169+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88170 td->mutexes[id] = ret ? 0 : 4;
88171 return ret ? -EINTR : 0;
88172
88173@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88174 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
88175 return ret;
88176
88177- td->event = atomic_add_return(1, &rttest_event);
88178+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88179 rt_mutex_unlock(&mutexes[id]);
88180- td->event = atomic_add_return(1, &rttest_event);
88181+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88182 td->mutexes[id] = 0;
88183 return 0;
88184
88185@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
88186 break;
88187
88188 td->mutexes[dat] = 2;
88189- td->event = atomic_add_return(1, &rttest_event);
88190+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88191 break;
88192
88193 default:
88194@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
88195 return;
88196
88197 td->mutexes[dat] = 3;
88198- td->event = atomic_add_return(1, &rttest_event);
88199+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88200 break;
88201
88202 case RTTEST_LOCKNOWAIT:
88203@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
88204 return;
88205
88206 td->mutexes[dat] = 1;
88207- td->event = atomic_add_return(1, &rttest_event);
88208+ td->event = atomic_add_return_unchecked(1, &rttest_event);
88209 return;
88210
88211 default:
88212diff --git a/kernel/module.c b/kernel/module.c
88213index 079c461..741f79c 100644
88214--- a/kernel/module.c
88215+++ b/kernel/module.c
88216@@ -61,6 +61,7 @@
88217 #include <linux/pfn.h>
88218 #include <linux/bsearch.h>
88219 #include <linux/fips.h>
88220+#include <linux/grsecurity.h>
88221 #include <uapi/linux/module.h>
88222 #include "module-internal.h"
88223
88224@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
88225
88226 /* Bounds of module allocation, for speeding __module_address.
88227 * Protected by module_mutex. */
88228-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
88229+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
88230+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
88231
88232 int register_module_notifier(struct notifier_block * nb)
88233 {
88234@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
88235 return true;
88236
88237 list_for_each_entry_rcu(mod, &modules, list) {
88238- struct symsearch arr[] = {
88239+ struct symsearch modarr[] = {
88240 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
88241 NOT_GPL_ONLY, false },
88242 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
88243@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
88244 if (mod->state == MODULE_STATE_UNFORMED)
88245 continue;
88246
88247- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
88248+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
88249 return true;
88250 }
88251 return false;
88252@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
88253 if (!pcpusec->sh_size)
88254 return 0;
88255
88256- if (align > PAGE_SIZE) {
88257+ if (align-1 >= PAGE_SIZE) {
88258 pr_warn("%s: per-cpu alignment %li > %li\n",
88259 mod->name, align, PAGE_SIZE);
88260 align = PAGE_SIZE;
88261@@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
88262 static ssize_t show_coresize(struct module_attribute *mattr,
88263 struct module_kobject *mk, char *buffer)
88264 {
88265- return sprintf(buffer, "%u\n", mk->mod->core_size);
88266+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
88267 }
88268
88269 static struct module_attribute modinfo_coresize =
88270@@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
88271 static ssize_t show_initsize(struct module_attribute *mattr,
88272 struct module_kobject *mk, char *buffer)
88273 {
88274- return sprintf(buffer, "%u\n", mk->mod->init_size);
88275+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
88276 }
88277
88278 static struct module_attribute modinfo_initsize =
88279@@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
88280 goto bad_version;
88281 }
88282
88283+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88284+ /*
88285+ * avoid potentially printing jibberish on attempted load
88286+ * of a module randomized with a different seed
88287+ */
88288+ pr_warn("no symbol version for %s\n", symname);
88289+#else
88290 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
88291+#endif
88292 return 0;
88293
88294 bad_version:
88295+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88296+ /*
88297+ * avoid potentially printing jibberish on attempted load
88298+ * of a module randomized with a different seed
88299+ */
88300+ printk("attempted module disagrees about version of symbol %s\n",
88301+ symname);
88302+#else
88303 printk("%s: disagrees about version of symbol %s\n",
88304 mod->name, symname);
88305+#endif
88306 return 0;
88307 }
88308
88309@@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
88310 */
88311 #ifdef CONFIG_SYSFS
88312
88313-#ifdef CONFIG_KALLSYMS
88314+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
88315 static inline bool sect_empty(const Elf_Shdr *sect)
88316 {
88317 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
88318@@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
88319 {
88320 unsigned int notes, loaded, i;
88321 struct module_notes_attrs *notes_attrs;
88322- struct bin_attribute *nattr;
88323+ bin_attribute_no_const *nattr;
88324
88325 /* failed to create section attributes, so can't create notes */
88326 if (!mod->sect_attrs)
88327@@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
88328 static int module_add_modinfo_attrs(struct module *mod)
88329 {
88330 struct module_attribute *attr;
88331- struct module_attribute *temp_attr;
88332+ module_attribute_no_const *temp_attr;
88333 int error = 0;
88334 int i;
88335
88336@@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
88337
88338 static void unset_module_core_ro_nx(struct module *mod)
88339 {
88340- set_page_attributes(mod->module_core + mod->core_text_size,
88341- mod->module_core + mod->core_size,
88342+ set_page_attributes(mod->module_core_rw,
88343+ mod->module_core_rw + mod->core_size_rw,
88344 set_memory_x);
88345- set_page_attributes(mod->module_core,
88346- mod->module_core + mod->core_ro_size,
88347+ set_page_attributes(mod->module_core_rx,
88348+ mod->module_core_rx + mod->core_size_rx,
88349 set_memory_rw);
88350 }
88351
88352 static void unset_module_init_ro_nx(struct module *mod)
88353 {
88354- set_page_attributes(mod->module_init + mod->init_text_size,
88355- mod->module_init + mod->init_size,
88356+ set_page_attributes(mod->module_init_rw,
88357+ mod->module_init_rw + mod->init_size_rw,
88358 set_memory_x);
88359- set_page_attributes(mod->module_init,
88360- mod->module_init + mod->init_ro_size,
88361+ set_page_attributes(mod->module_init_rx,
88362+ mod->module_init_rx + mod->init_size_rx,
88363 set_memory_rw);
88364 }
88365
88366@@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
88367 list_for_each_entry_rcu(mod, &modules, list) {
88368 if (mod->state == MODULE_STATE_UNFORMED)
88369 continue;
88370- if ((mod->module_core) && (mod->core_text_size)) {
88371- set_page_attributes(mod->module_core,
88372- mod->module_core + mod->core_text_size,
88373+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
88374+ set_page_attributes(mod->module_core_rx,
88375+ mod->module_core_rx + mod->core_size_rx,
88376 set_memory_rw);
88377 }
88378- if ((mod->module_init) && (mod->init_text_size)) {
88379- set_page_attributes(mod->module_init,
88380- mod->module_init + mod->init_text_size,
88381+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
88382+ set_page_attributes(mod->module_init_rx,
88383+ mod->module_init_rx + mod->init_size_rx,
88384 set_memory_rw);
88385 }
88386 }
88387@@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
88388 list_for_each_entry_rcu(mod, &modules, list) {
88389 if (mod->state == MODULE_STATE_UNFORMED)
88390 continue;
88391- if ((mod->module_core) && (mod->core_text_size)) {
88392- set_page_attributes(mod->module_core,
88393- mod->module_core + mod->core_text_size,
88394+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
88395+ set_page_attributes(mod->module_core_rx,
88396+ mod->module_core_rx + mod->core_size_rx,
88397 set_memory_ro);
88398 }
88399- if ((mod->module_init) && (mod->init_text_size)) {
88400- set_page_attributes(mod->module_init,
88401- mod->module_init + mod->init_text_size,
88402+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
88403+ set_page_attributes(mod->module_init_rx,
88404+ mod->module_init_rx + mod->init_size_rx,
88405 set_memory_ro);
88406 }
88407 }
88408@@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
88409
88410 /* This may be NULL, but that's OK */
88411 unset_module_init_ro_nx(mod);
88412- module_free(mod, mod->module_init);
88413+ module_free(mod, mod->module_init_rw);
88414+ module_free_exec(mod, mod->module_init_rx);
88415 kfree(mod->args);
88416 percpu_modfree(mod);
88417
88418 /* Free lock-classes: */
88419- lockdep_free_key_range(mod->module_core, mod->core_size);
88420+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
88421+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
88422
88423 /* Finally, free the core (containing the module structure) */
88424 unset_module_core_ro_nx(mod);
88425- module_free(mod, mod->module_core);
88426+ module_free_exec(mod, mod->module_core_rx);
88427+ module_free(mod, mod->module_core_rw);
88428
88429 #ifdef CONFIG_MPU
88430 update_protections(current->mm);
88431@@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88432 int ret = 0;
88433 const struct kernel_symbol *ksym;
88434
88435+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88436+ int is_fs_load = 0;
88437+ int register_filesystem_found = 0;
88438+ char *p;
88439+
88440+ p = strstr(mod->args, "grsec_modharden_fs");
88441+ if (p) {
88442+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
88443+ /* copy \0 as well */
88444+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
88445+ is_fs_load = 1;
88446+ }
88447+#endif
88448+
88449 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
88450 const char *name = info->strtab + sym[i].st_name;
88451
88452+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88453+ /* it's a real shame this will never get ripped and copied
88454+ upstream! ;(
88455+ */
88456+ if (is_fs_load && !strcmp(name, "register_filesystem"))
88457+ register_filesystem_found = 1;
88458+#endif
88459+
88460 switch (sym[i].st_shndx) {
88461 case SHN_COMMON:
88462 /* Ignore common symbols */
88463@@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88464 ksym = resolve_symbol_wait(mod, info, name);
88465 /* Ok if resolved. */
88466 if (ksym && !IS_ERR(ksym)) {
88467+ pax_open_kernel();
88468 sym[i].st_value = ksym->value;
88469+ pax_close_kernel();
88470 break;
88471 }
88472
88473@@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88474 secbase = (unsigned long)mod_percpu(mod);
88475 else
88476 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
88477+ pax_open_kernel();
88478 sym[i].st_value += secbase;
88479+ pax_close_kernel();
88480 break;
88481 }
88482 }
88483
88484+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88485+ if (is_fs_load && !register_filesystem_found) {
88486+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
88487+ ret = -EPERM;
88488+ }
88489+#endif
88490+
88491 return ret;
88492 }
88493
88494@@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
88495 || s->sh_entsize != ~0UL
88496 || strstarts(sname, ".init"))
88497 continue;
88498- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
88499+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88500+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
88501+ else
88502+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
88503 pr_debug("\t%s\n", sname);
88504 }
88505- switch (m) {
88506- case 0: /* executable */
88507- mod->core_size = debug_align(mod->core_size);
88508- mod->core_text_size = mod->core_size;
88509- break;
88510- case 1: /* RO: text and ro-data */
88511- mod->core_size = debug_align(mod->core_size);
88512- mod->core_ro_size = mod->core_size;
88513- break;
88514- case 3: /* whole core */
88515- mod->core_size = debug_align(mod->core_size);
88516- break;
88517- }
88518 }
88519
88520 pr_debug("Init section allocation order:\n");
88521@@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
88522 || s->sh_entsize != ~0UL
88523 || !strstarts(sname, ".init"))
88524 continue;
88525- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
88526- | INIT_OFFSET_MASK);
88527+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88528+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
88529+ else
88530+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
88531+ s->sh_entsize |= INIT_OFFSET_MASK;
88532 pr_debug("\t%s\n", sname);
88533 }
88534- switch (m) {
88535- case 0: /* executable */
88536- mod->init_size = debug_align(mod->init_size);
88537- mod->init_text_size = mod->init_size;
88538- break;
88539- case 1: /* RO: text and ro-data */
88540- mod->init_size = debug_align(mod->init_size);
88541- mod->init_ro_size = mod->init_size;
88542- break;
88543- case 3: /* whole init */
88544- mod->init_size = debug_align(mod->init_size);
88545- break;
88546- }
88547 }
88548 }
88549
88550@@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88551
88552 /* Put symbol section at end of init part of module. */
88553 symsect->sh_flags |= SHF_ALLOC;
88554- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
88555+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
88556 info->index.sym) | INIT_OFFSET_MASK;
88557 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
88558
88559@@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88560 }
88561
88562 /* Append room for core symbols at end of core part. */
88563- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
88564- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
88565- mod->core_size += strtab_size;
88566+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
88567+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
88568+ mod->core_size_rx += strtab_size;
88569
88570 /* Put string table section at end of init part of module. */
88571 strsect->sh_flags |= SHF_ALLOC;
88572- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
88573+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
88574 info->index.str) | INIT_OFFSET_MASK;
88575 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
88576 }
88577@@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88578 /* Make sure we get permanent strtab: don't use info->strtab. */
88579 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
88580
88581+ pax_open_kernel();
88582+
88583 /* Set types up while we still have access to sections. */
88584 for (i = 0; i < mod->num_symtab; i++)
88585 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
88586
88587- mod->core_symtab = dst = mod->module_core + info->symoffs;
88588- mod->core_strtab = s = mod->module_core + info->stroffs;
88589+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
88590+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
88591 src = mod->symtab;
88592 for (ndst = i = 0; i < mod->num_symtab; i++) {
88593 if (i == 0 ||
88594@@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88595 }
88596 }
88597 mod->core_num_syms = ndst;
88598+
88599+ pax_close_kernel();
88600 }
88601 #else
88602 static inline void layout_symtab(struct module *mod, struct load_info *info)
88603@@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
88604 return vmalloc_exec(size);
88605 }
88606
88607-static void *module_alloc_update_bounds(unsigned long size)
88608+static void *module_alloc_update_bounds_rw(unsigned long size)
88609 {
88610 void *ret = module_alloc(size);
88611
88612 if (ret) {
88613 mutex_lock(&module_mutex);
88614 /* Update module bounds. */
88615- if ((unsigned long)ret < module_addr_min)
88616- module_addr_min = (unsigned long)ret;
88617- if ((unsigned long)ret + size > module_addr_max)
88618- module_addr_max = (unsigned long)ret + size;
88619+ if ((unsigned long)ret < module_addr_min_rw)
88620+ module_addr_min_rw = (unsigned long)ret;
88621+ if ((unsigned long)ret + size > module_addr_max_rw)
88622+ module_addr_max_rw = (unsigned long)ret + size;
88623+ mutex_unlock(&module_mutex);
88624+ }
88625+ return ret;
88626+}
88627+
88628+static void *module_alloc_update_bounds_rx(unsigned long size)
88629+{
88630+ void *ret = module_alloc_exec(size);
88631+
88632+ if (ret) {
88633+ mutex_lock(&module_mutex);
88634+ /* Update module bounds. */
88635+ if ((unsigned long)ret < module_addr_min_rx)
88636+ module_addr_min_rx = (unsigned long)ret;
88637+ if ((unsigned long)ret + size > module_addr_max_rx)
88638+ module_addr_max_rx = (unsigned long)ret + size;
88639 mutex_unlock(&module_mutex);
88640 }
88641 return ret;
88642@@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88643 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88644
88645 if (info->index.sym == 0) {
88646+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88647+ /*
88648+ * avoid potentially printing jibberish on attempted load
88649+ * of a module randomized with a different seed
88650+ */
88651+ pr_warn("module has no symbols (stripped?)\n");
88652+#else
88653 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88654+#endif
88655 return ERR_PTR(-ENOEXEC);
88656 }
88657
88658@@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88659 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88660 {
88661 const char *modmagic = get_modinfo(info, "vermagic");
88662+ const char *license = get_modinfo(info, "license");
88663 int err;
88664
88665+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88666+ if (!license || !license_is_gpl_compatible(license))
88667+ return -ENOEXEC;
88668+#endif
88669+
88670 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88671 modmagic = NULL;
88672
88673@@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88674 }
88675
88676 /* Set up license info based on the info section */
88677- set_license(mod, get_modinfo(info, "license"));
88678+ set_license(mod, license);
88679
88680 return 0;
88681 }
88682@@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
88683 void *ptr;
88684
88685 /* Do the allocs. */
88686- ptr = module_alloc_update_bounds(mod->core_size);
88687+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88688 /*
88689 * The pointer to this block is stored in the module structure
88690 * which is inside the block. Just mark it as not being a
88691@@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
88692 if (!ptr)
88693 return -ENOMEM;
88694
88695- memset(ptr, 0, mod->core_size);
88696- mod->module_core = ptr;
88697+ memset(ptr, 0, mod->core_size_rw);
88698+ mod->module_core_rw = ptr;
88699
88700- if (mod->init_size) {
88701- ptr = module_alloc_update_bounds(mod->init_size);
88702+ if (mod->init_size_rw) {
88703+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88704 /*
88705 * The pointer to this block is stored in the module structure
88706 * which is inside the block. This block doesn't need to be
88707@@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
88708 */
88709 kmemleak_ignore(ptr);
88710 if (!ptr) {
88711- module_free(mod, mod->module_core);
88712+ module_free(mod, mod->module_core_rw);
88713 return -ENOMEM;
88714 }
88715- memset(ptr, 0, mod->init_size);
88716- mod->module_init = ptr;
88717+ memset(ptr, 0, mod->init_size_rw);
88718+ mod->module_init_rw = ptr;
88719 } else
88720- mod->module_init = NULL;
88721+ mod->module_init_rw = NULL;
88722+
88723+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88724+ kmemleak_not_leak(ptr);
88725+ if (!ptr) {
88726+ if (mod->module_init_rw)
88727+ module_free(mod, mod->module_init_rw);
88728+ module_free(mod, mod->module_core_rw);
88729+ return -ENOMEM;
88730+ }
88731+
88732+ pax_open_kernel();
88733+ memset(ptr, 0, mod->core_size_rx);
88734+ pax_close_kernel();
88735+ mod->module_core_rx = ptr;
88736+
88737+ if (mod->init_size_rx) {
88738+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88739+ kmemleak_ignore(ptr);
88740+ if (!ptr && mod->init_size_rx) {
88741+ module_free_exec(mod, mod->module_core_rx);
88742+ if (mod->module_init_rw)
88743+ module_free(mod, mod->module_init_rw);
88744+ module_free(mod, mod->module_core_rw);
88745+ return -ENOMEM;
88746+ }
88747+
88748+ pax_open_kernel();
88749+ memset(ptr, 0, mod->init_size_rx);
88750+ pax_close_kernel();
88751+ mod->module_init_rx = ptr;
88752+ } else
88753+ mod->module_init_rx = NULL;
88754
88755 /* Transfer each section which specifies SHF_ALLOC */
88756 pr_debug("final section addresses:\n");
88757@@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
88758 if (!(shdr->sh_flags & SHF_ALLOC))
88759 continue;
88760
88761- if (shdr->sh_entsize & INIT_OFFSET_MASK)
88762- dest = mod->module_init
88763- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88764- else
88765- dest = mod->module_core + shdr->sh_entsize;
88766+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88767+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88768+ dest = mod->module_init_rw
88769+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88770+ else
88771+ dest = mod->module_init_rx
88772+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88773+ } else {
88774+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88775+ dest = mod->module_core_rw + shdr->sh_entsize;
88776+ else
88777+ dest = mod->module_core_rx + shdr->sh_entsize;
88778+ }
88779+
88780+ if (shdr->sh_type != SHT_NOBITS) {
88781+
88782+#ifdef CONFIG_PAX_KERNEXEC
88783+#ifdef CONFIG_X86_64
88784+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88785+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88786+#endif
88787+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88788+ pax_open_kernel();
88789+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88790+ pax_close_kernel();
88791+ } else
88792+#endif
88793
88794- if (shdr->sh_type != SHT_NOBITS)
88795 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88796+ }
88797 /* Update sh_addr to point to copy in image. */
88798- shdr->sh_addr = (unsigned long)dest;
88799+
88800+#ifdef CONFIG_PAX_KERNEXEC
88801+ if (shdr->sh_flags & SHF_EXECINSTR)
88802+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88803+ else
88804+#endif
88805+
88806+ shdr->sh_addr = (unsigned long)dest;
88807 pr_debug("\t0x%lx %s\n",
88808 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88809 }
88810@@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88811 * Do it before processing of module parameters, so the module
88812 * can provide parameter accessor functions of its own.
88813 */
88814- if (mod->module_init)
88815- flush_icache_range((unsigned long)mod->module_init,
88816- (unsigned long)mod->module_init
88817- + mod->init_size);
88818- flush_icache_range((unsigned long)mod->module_core,
88819- (unsigned long)mod->module_core + mod->core_size);
88820+ if (mod->module_init_rx)
88821+ flush_icache_range((unsigned long)mod->module_init_rx,
88822+ (unsigned long)mod->module_init_rx
88823+ + mod->init_size_rx);
88824+ flush_icache_range((unsigned long)mod->module_core_rx,
88825+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88826
88827 set_fs(old_fs);
88828 }
88829@@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88830 static void module_deallocate(struct module *mod, struct load_info *info)
88831 {
88832 percpu_modfree(mod);
88833- module_free(mod, mod->module_init);
88834- module_free(mod, mod->module_core);
88835+ module_free_exec(mod, mod->module_init_rx);
88836+ module_free_exec(mod, mod->module_core_rx);
88837+ module_free(mod, mod->module_init_rw);
88838+ module_free(mod, mod->module_core_rw);
88839 }
88840
88841 int __weak module_finalize(const Elf_Ehdr *hdr,
88842@@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88843 static int post_relocation(struct module *mod, const struct load_info *info)
88844 {
88845 /* Sort exception table now relocations are done. */
88846+ pax_open_kernel();
88847 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88848+ pax_close_kernel();
88849
88850 /* Copy relocated percpu area over. */
88851 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88852@@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88853 MODULE_STATE_COMING, mod);
88854
88855 /* Set RO and NX regions for core */
88856- set_section_ro_nx(mod->module_core,
88857- mod->core_text_size,
88858- mod->core_ro_size,
88859- mod->core_size);
88860+ set_section_ro_nx(mod->module_core_rx,
88861+ mod->core_size_rx,
88862+ mod->core_size_rx,
88863+ mod->core_size_rx);
88864
88865 /* Set RO and NX regions for init */
88866- set_section_ro_nx(mod->module_init,
88867- mod->init_text_size,
88868- mod->init_ro_size,
88869- mod->init_size);
88870+ set_section_ro_nx(mod->module_init_rx,
88871+ mod->init_size_rx,
88872+ mod->init_size_rx,
88873+ mod->init_size_rx);
88874
88875 do_mod_ctors(mod);
88876 /* Start the module */
88877@@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88878 mod->strtab = mod->core_strtab;
88879 #endif
88880 unset_module_init_ro_nx(mod);
88881- module_free(mod, mod->module_init);
88882- mod->module_init = NULL;
88883- mod->init_size = 0;
88884- mod->init_ro_size = 0;
88885- mod->init_text_size = 0;
88886+ module_free(mod, mod->module_init_rw);
88887+ module_free_exec(mod, mod->module_init_rx);
88888+ mod->module_init_rw = NULL;
88889+ mod->module_init_rx = NULL;
88890+ mod->init_size_rw = 0;
88891+ mod->init_size_rx = 0;
88892 mutex_unlock(&module_mutex);
88893 wake_up_all(&module_wq);
88894
88895@@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88896 if (err)
88897 goto free_unload;
88898
88899+ /* Now copy in args */
88900+ mod->args = strndup_user(uargs, ~0UL >> 1);
88901+ if (IS_ERR(mod->args)) {
88902+ err = PTR_ERR(mod->args);
88903+ goto free_unload;
88904+ }
88905+
88906 /* Set up MODINFO_ATTR fields */
88907 setup_modinfo(mod, info);
88908
88909+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88910+ {
88911+ char *p, *p2;
88912+
88913+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88914+ 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);
88915+ err = -EPERM;
88916+ goto free_modinfo;
88917+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88918+ p += sizeof("grsec_modharden_normal") - 1;
88919+ p2 = strstr(p, "_");
88920+ if (p2) {
88921+ *p2 = '\0';
88922+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88923+ *p2 = '_';
88924+ }
88925+ err = -EPERM;
88926+ goto free_modinfo;
88927+ }
88928+ }
88929+#endif
88930+
88931 /* Fix up syms, so that st_value is a pointer to location. */
88932 err = simplify_symbols(mod, info);
88933 if (err < 0)
88934@@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88935
88936 flush_module_icache(mod);
88937
88938- /* Now copy in args */
88939- mod->args = strndup_user(uargs, ~0UL >> 1);
88940- if (IS_ERR(mod->args)) {
88941- err = PTR_ERR(mod->args);
88942- goto free_arch_cleanup;
88943- }
88944-
88945 dynamic_debug_setup(info->debug, info->num_debug);
88946
88947 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88948@@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88949 ddebug_cleanup:
88950 dynamic_debug_remove(info->debug);
88951 synchronize_sched();
88952- kfree(mod->args);
88953- free_arch_cleanup:
88954 module_arch_cleanup(mod);
88955 free_modinfo:
88956 free_modinfo(mod);
88957+ kfree(mod->args);
88958 free_unload:
88959 module_unload_free(mod);
88960 unlink_mod:
88961@@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88962 unsigned long nextval;
88963
88964 /* At worse, next value is at end of module */
88965- if (within_module_init(addr, mod))
88966- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88967+ if (within_module_init_rx(addr, mod))
88968+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88969+ else if (within_module_init_rw(addr, mod))
88970+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88971+ else if (within_module_core_rx(addr, mod))
88972+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88973+ else if (within_module_core_rw(addr, mod))
88974+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88975 else
88976- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88977+ return NULL;
88978
88979 /* Scan for closest preceding symbol, and next symbol. (ELF
88980 starts real symbols at 1). */
88981@@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88982 return 0;
88983
88984 seq_printf(m, "%s %u",
88985- mod->name, mod->init_size + mod->core_size);
88986+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88987 print_unload_info(m, mod);
88988
88989 /* Informative for users. */
88990@@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88991 mod->state == MODULE_STATE_COMING ? "Loading":
88992 "Live");
88993 /* Used by oprofile and other similar tools. */
88994- seq_printf(m, " 0x%pK", mod->module_core);
88995+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88996
88997 /* Taints info */
88998 if (mod->taints)
88999@@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
89000
89001 static int __init proc_modules_init(void)
89002 {
89003+#ifndef CONFIG_GRKERNSEC_HIDESYM
89004+#ifdef CONFIG_GRKERNSEC_PROC_USER
89005+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
89006+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89007+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
89008+#else
89009 proc_create("modules", 0, NULL, &proc_modules_operations);
89010+#endif
89011+#else
89012+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
89013+#endif
89014 return 0;
89015 }
89016 module_init(proc_modules_init);
89017@@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
89018 {
89019 struct module *mod;
89020
89021- if (addr < module_addr_min || addr > module_addr_max)
89022+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
89023+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
89024 return NULL;
89025
89026 list_for_each_entry_rcu(mod, &modules, list) {
89027 if (mod->state == MODULE_STATE_UNFORMED)
89028 continue;
89029- if (within_module_core(addr, mod)
89030- || within_module_init(addr, mod))
89031+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
89032 return mod;
89033 }
89034 return NULL;
89035@@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
89036 */
89037 struct module *__module_text_address(unsigned long addr)
89038 {
89039- struct module *mod = __module_address(addr);
89040+ struct module *mod;
89041+
89042+#ifdef CONFIG_X86_32
89043+ addr = ktla_ktva(addr);
89044+#endif
89045+
89046+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
89047+ return NULL;
89048+
89049+ mod = __module_address(addr);
89050+
89051 if (mod) {
89052 /* Make sure it's within the text section. */
89053- if (!within(addr, mod->module_init, mod->init_text_size)
89054- && !within(addr, mod->module_core, mod->core_text_size))
89055+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
89056 mod = NULL;
89057 }
89058 return mod;
89059diff --git a/kernel/notifier.c b/kernel/notifier.c
89060index db4c8b0..ad011c5 100644
89061--- a/kernel/notifier.c
89062+++ b/kernel/notifier.c
89063@@ -5,6 +5,7 @@
89064 #include <linux/rcupdate.h>
89065 #include <linux/vmalloc.h>
89066 #include <linux/reboot.h>
89067+#include <linux/mm.h>
89068
89069 /*
89070 * Notifier list for kernel code which wants to be called
89071@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
89072 while ((*nl) != NULL) {
89073 if (n->priority > (*nl)->priority)
89074 break;
89075- nl = &((*nl)->next);
89076+ nl = (struct notifier_block **)&((*nl)->next);
89077 }
89078- n->next = *nl;
89079+ pax_open_kernel();
89080+ *(const void **)&n->next = *nl;
89081 rcu_assign_pointer(*nl, n);
89082+ pax_close_kernel();
89083 return 0;
89084 }
89085
89086@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
89087 return 0;
89088 if (n->priority > (*nl)->priority)
89089 break;
89090- nl = &((*nl)->next);
89091+ nl = (struct notifier_block **)&((*nl)->next);
89092 }
89093- n->next = *nl;
89094+ pax_open_kernel();
89095+ *(const void **)&n->next = *nl;
89096 rcu_assign_pointer(*nl, n);
89097+ pax_close_kernel();
89098 return 0;
89099 }
89100
89101@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
89102 {
89103 while ((*nl) != NULL) {
89104 if ((*nl) == n) {
89105+ pax_open_kernel();
89106 rcu_assign_pointer(*nl, n->next);
89107+ pax_close_kernel();
89108 return 0;
89109 }
89110- nl = &((*nl)->next);
89111+ nl = (struct notifier_block **)&((*nl)->next);
89112 }
89113 return -ENOENT;
89114 }
89115diff --git a/kernel/padata.c b/kernel/padata.c
89116index 161402f..598814c 100644
89117--- a/kernel/padata.c
89118+++ b/kernel/padata.c
89119@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
89120 * seq_nr mod. number of cpus in use.
89121 */
89122
89123- seq_nr = atomic_inc_return(&pd->seq_nr);
89124+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
89125 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
89126
89127 return padata_index_to_cpu(pd, cpu_index);
89128@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
89129 padata_init_pqueues(pd);
89130 padata_init_squeues(pd);
89131 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
89132- atomic_set(&pd->seq_nr, -1);
89133+ atomic_set_unchecked(&pd->seq_nr, -1);
89134 atomic_set(&pd->reorder_objects, 0);
89135 atomic_set(&pd->refcnt, 0);
89136 pd->pinst = pinst;
89137diff --git a/kernel/panic.c b/kernel/panic.c
89138index d02fa9f..9faec0a 100644
89139--- a/kernel/panic.c
89140+++ b/kernel/panic.c
89141@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
89142 /*
89143 * Stop ourself in panic -- architecture code may override this
89144 */
89145-void __weak panic_smp_self_stop(void)
89146+void __weak __noreturn panic_smp_self_stop(void)
89147 {
89148 while (1)
89149 cpu_relax();
89150@@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
89151 disable_trace_on_warning();
89152
89153 pr_warn("------------[ cut here ]------------\n");
89154- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
89155+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
89156 raw_smp_processor_id(), current->pid, file, line, caller);
89157
89158 if (args)
89159@@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
89160 */
89161 __visible void __stack_chk_fail(void)
89162 {
89163- panic("stack-protector: Kernel stack is corrupted in: %p\n",
89164+ dump_stack();
89165+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
89166 __builtin_return_address(0));
89167 }
89168 EXPORT_SYMBOL(__stack_chk_fail);
89169diff --git a/kernel/pid.c b/kernel/pid.c
89170index 9b9a266..c20ef80 100644
89171--- a/kernel/pid.c
89172+++ b/kernel/pid.c
89173@@ -33,6 +33,7 @@
89174 #include <linux/rculist.h>
89175 #include <linux/bootmem.h>
89176 #include <linux/hash.h>
89177+#include <linux/security.h>
89178 #include <linux/pid_namespace.h>
89179 #include <linux/init_task.h>
89180 #include <linux/syscalls.h>
89181@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
89182
89183 int pid_max = PID_MAX_DEFAULT;
89184
89185-#define RESERVED_PIDS 300
89186+#define RESERVED_PIDS 500
89187
89188 int pid_max_min = RESERVED_PIDS + 1;
89189 int pid_max_max = PID_MAX_LIMIT;
89190@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
89191 */
89192 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
89193 {
89194+ struct task_struct *task;
89195+
89196 rcu_lockdep_assert(rcu_read_lock_held(),
89197 "find_task_by_pid_ns() needs rcu_read_lock()"
89198 " protection");
89199- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
89200+
89201+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
89202+
89203+ if (gr_pid_is_chrooted(task))
89204+ return NULL;
89205+
89206+ return task;
89207 }
89208
89209 struct task_struct *find_task_by_vpid(pid_t vnr)
89210@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
89211 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
89212 }
89213
89214+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
89215+{
89216+ rcu_lockdep_assert(rcu_read_lock_held(),
89217+ "find_task_by_pid_ns() needs rcu_read_lock()"
89218+ " protection");
89219+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
89220+}
89221+
89222 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
89223 {
89224 struct pid *pid;
89225diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
89226index db95d8e..a0ca23f 100644
89227--- a/kernel/pid_namespace.c
89228+++ b/kernel/pid_namespace.c
89229@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
89230 void __user *buffer, size_t *lenp, loff_t *ppos)
89231 {
89232 struct pid_namespace *pid_ns = task_active_pid_ns(current);
89233- struct ctl_table tmp = *table;
89234+ ctl_table_no_const tmp = *table;
89235
89236 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
89237 return -EPERM;
89238diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
89239index 3b89464..5e38379 100644
89240--- a/kernel/posix-cpu-timers.c
89241+++ b/kernel/posix-cpu-timers.c
89242@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
89243
89244 static __init int init_posix_cpu_timers(void)
89245 {
89246- struct k_clock process = {
89247+ static struct k_clock process = {
89248 .clock_getres = process_cpu_clock_getres,
89249 .clock_get = process_cpu_clock_get,
89250 .timer_create = process_cpu_timer_create,
89251 .nsleep = process_cpu_nsleep,
89252 .nsleep_restart = process_cpu_nsleep_restart,
89253 };
89254- struct k_clock thread = {
89255+ static struct k_clock thread = {
89256 .clock_getres = thread_cpu_clock_getres,
89257 .clock_get = thread_cpu_clock_get,
89258 .timer_create = thread_cpu_timer_create,
89259diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
89260index 424c2d4..679242f 100644
89261--- a/kernel/posix-timers.c
89262+++ b/kernel/posix-timers.c
89263@@ -43,6 +43,7 @@
89264 #include <linux/hash.h>
89265 #include <linux/posix-clock.h>
89266 #include <linux/posix-timers.h>
89267+#include <linux/grsecurity.h>
89268 #include <linux/syscalls.h>
89269 #include <linux/wait.h>
89270 #include <linux/workqueue.h>
89271@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
89272 * which we beg off on and pass to do_sys_settimeofday().
89273 */
89274
89275-static struct k_clock posix_clocks[MAX_CLOCKS];
89276+static struct k_clock *posix_clocks[MAX_CLOCKS];
89277
89278 /*
89279 * These ones are defined below.
89280@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
89281 */
89282 static __init int init_posix_timers(void)
89283 {
89284- struct k_clock clock_realtime = {
89285+ static struct k_clock clock_realtime = {
89286 .clock_getres = hrtimer_get_res,
89287 .clock_get = posix_clock_realtime_get,
89288 .clock_set = posix_clock_realtime_set,
89289@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
89290 .timer_get = common_timer_get,
89291 .timer_del = common_timer_del,
89292 };
89293- struct k_clock clock_monotonic = {
89294+ static struct k_clock clock_monotonic = {
89295 .clock_getres = hrtimer_get_res,
89296 .clock_get = posix_ktime_get_ts,
89297 .nsleep = common_nsleep,
89298@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
89299 .timer_get = common_timer_get,
89300 .timer_del = common_timer_del,
89301 };
89302- struct k_clock clock_monotonic_raw = {
89303+ static struct k_clock clock_monotonic_raw = {
89304 .clock_getres = hrtimer_get_res,
89305 .clock_get = posix_get_monotonic_raw,
89306 };
89307- struct k_clock clock_realtime_coarse = {
89308+ static struct k_clock clock_realtime_coarse = {
89309 .clock_getres = posix_get_coarse_res,
89310 .clock_get = posix_get_realtime_coarse,
89311 };
89312- struct k_clock clock_monotonic_coarse = {
89313+ static struct k_clock clock_monotonic_coarse = {
89314 .clock_getres = posix_get_coarse_res,
89315 .clock_get = posix_get_monotonic_coarse,
89316 };
89317- struct k_clock clock_tai = {
89318+ static struct k_clock clock_tai = {
89319 .clock_getres = hrtimer_get_res,
89320 .clock_get = posix_get_tai,
89321 .nsleep = common_nsleep,
89322@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
89323 .timer_get = common_timer_get,
89324 .timer_del = common_timer_del,
89325 };
89326- struct k_clock clock_boottime = {
89327+ static struct k_clock clock_boottime = {
89328 .clock_getres = hrtimer_get_res,
89329 .clock_get = posix_get_boottime,
89330 .nsleep = common_nsleep,
89331@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
89332 return;
89333 }
89334
89335- posix_clocks[clock_id] = *new_clock;
89336+ posix_clocks[clock_id] = new_clock;
89337 }
89338 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
89339
89340@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
89341 return (id & CLOCKFD_MASK) == CLOCKFD ?
89342 &clock_posix_dynamic : &clock_posix_cpu;
89343
89344- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
89345+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
89346 return NULL;
89347- return &posix_clocks[id];
89348+ return posix_clocks[id];
89349 }
89350
89351 static int common_timer_create(struct k_itimer *new_timer)
89352@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
89353 struct k_clock *kc = clockid_to_kclock(which_clock);
89354 struct k_itimer *new_timer;
89355 int error, new_timer_id;
89356- sigevent_t event;
89357+ sigevent_t event = { };
89358 int it_id_set = IT_ID_NOT_SET;
89359
89360 if (!kc)
89361@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
89362 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
89363 return -EFAULT;
89364
89365+ /* only the CLOCK_REALTIME clock can be set, all other clocks
89366+ have their clock_set fptr set to a nosettime dummy function
89367+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
89368+ call common_clock_set, which calls do_sys_settimeofday, which
89369+ we hook
89370+ */
89371+
89372 return kc->clock_set(which_clock, &new_tp);
89373 }
89374
89375diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
89376index 2fac9cc..56fef29 100644
89377--- a/kernel/power/Kconfig
89378+++ b/kernel/power/Kconfig
89379@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
89380 config HIBERNATION
89381 bool "Hibernation (aka 'suspend to disk')"
89382 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
89383+ depends on !GRKERNSEC_KMEM
89384+ depends on !PAX_MEMORY_SANITIZE
89385 select HIBERNATE_CALLBACKS
89386 select LZO_COMPRESS
89387 select LZO_DECOMPRESS
89388diff --git a/kernel/power/process.c b/kernel/power/process.c
89389index 14f9a8d..98ee610 100644
89390--- a/kernel/power/process.c
89391+++ b/kernel/power/process.c
89392@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
89393 unsigned int elapsed_msecs;
89394 bool wakeup = false;
89395 int sleep_usecs = USEC_PER_MSEC;
89396+ bool timedout = false;
89397
89398 do_gettimeofday(&start);
89399
89400@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
89401
89402 while (true) {
89403 todo = 0;
89404+ if (time_after(jiffies, end_time))
89405+ timedout = true;
89406 read_lock(&tasklist_lock);
89407 do_each_thread(g, p) {
89408 if (p == current || !freeze_task(p))
89409 continue;
89410
89411- if (!freezer_should_skip(p))
89412+ if (!freezer_should_skip(p)) {
89413 todo++;
89414+ if (timedout) {
89415+ printk(KERN_ERR "Task refusing to freeze:\n");
89416+ sched_show_task(p);
89417+ }
89418+ }
89419 } while_each_thread(g, p);
89420 read_unlock(&tasklist_lock);
89421
89422@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
89423 todo += wq_busy;
89424 }
89425
89426- if (!todo || time_after(jiffies, end_time))
89427+ if (!todo || timedout)
89428 break;
89429
89430 if (pm_wakeup_pending()) {
89431diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
89432index 63594be..8444e0f 100644
89433--- a/kernel/printk/printk.c
89434+++ b/kernel/printk/printk.c
89435@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
89436 if (from_file && type != SYSLOG_ACTION_OPEN)
89437 return 0;
89438
89439+#ifdef CONFIG_GRKERNSEC_DMESG
89440+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
89441+ return -EPERM;
89442+#endif
89443+
89444 if (syslog_action_restricted(type)) {
89445 if (capable(CAP_SYSLOG))
89446 return 0;
89447diff --git a/kernel/profile.c b/kernel/profile.c
89448index cb980f0..ccd8782 100644
89449--- a/kernel/profile.c
89450+++ b/kernel/profile.c
89451@@ -37,7 +37,7 @@ struct profile_hit {
89452 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
89453 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
89454
89455-static atomic_t *prof_buffer;
89456+static atomic_unchecked_t *prof_buffer;
89457 static unsigned long prof_len, prof_shift;
89458
89459 int prof_on __read_mostly;
89460@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
89461 hits[i].pc = 0;
89462 continue;
89463 }
89464- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89465+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89466 hits[i].hits = hits[i].pc = 0;
89467 }
89468 }
89469@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89470 * Add the current hit(s) and flush the write-queue out
89471 * to the global buffer:
89472 */
89473- atomic_add(nr_hits, &prof_buffer[pc]);
89474+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
89475 for (i = 0; i < NR_PROFILE_HIT; ++i) {
89476- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89477+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89478 hits[i].pc = hits[i].hits = 0;
89479 }
89480 out:
89481@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89482 {
89483 unsigned long pc;
89484 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
89485- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89486+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89487 }
89488 #endif /* !CONFIG_SMP */
89489
89490@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
89491 return -EFAULT;
89492 buf++; p++; count--; read++;
89493 }
89494- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
89495+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
89496 if (copy_to_user(buf, (void *)pnt, count))
89497 return -EFAULT;
89498 read += count;
89499@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
89500 }
89501 #endif
89502 profile_discard_flip_buffers();
89503- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
89504+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
89505 return count;
89506 }
89507
89508diff --git a/kernel/ptrace.c b/kernel/ptrace.c
89509index adf9862..9d86345 100644
89510--- a/kernel/ptrace.c
89511+++ b/kernel/ptrace.c
89512@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
89513 if (seize)
89514 flags |= PT_SEIZED;
89515 rcu_read_lock();
89516- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89517+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89518 flags |= PT_PTRACE_CAP;
89519 rcu_read_unlock();
89520 task->ptrace = flags;
89521@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
89522 break;
89523 return -EIO;
89524 }
89525- if (copy_to_user(dst, buf, retval))
89526+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
89527 return -EFAULT;
89528 copied += retval;
89529 src += retval;
89530@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
89531 bool seized = child->ptrace & PT_SEIZED;
89532 int ret = -EIO;
89533 siginfo_t siginfo, *si;
89534- void __user *datavp = (void __user *) data;
89535+ void __user *datavp = (__force void __user *) data;
89536 unsigned long __user *datalp = datavp;
89537 unsigned long flags;
89538
89539@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
89540 goto out;
89541 }
89542
89543+ if (gr_handle_ptrace(child, request)) {
89544+ ret = -EPERM;
89545+ goto out_put_task_struct;
89546+ }
89547+
89548 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89549 ret = ptrace_attach(child, request, addr, data);
89550 /*
89551 * Some architectures need to do book-keeping after
89552 * a ptrace attach.
89553 */
89554- if (!ret)
89555+ if (!ret) {
89556 arch_ptrace_attach(child);
89557+ gr_audit_ptrace(child);
89558+ }
89559 goto out_put_task_struct;
89560 }
89561
89562@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
89563 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
89564 if (copied != sizeof(tmp))
89565 return -EIO;
89566- return put_user(tmp, (unsigned long __user *)data);
89567+ return put_user(tmp, (__force unsigned long __user *)data);
89568 }
89569
89570 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
89571@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
89572 }
89573
89574 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89575- compat_long_t, addr, compat_long_t, data)
89576+ compat_ulong_t, addr, compat_ulong_t, data)
89577 {
89578 struct task_struct *child;
89579 long ret;
89580@@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89581 goto out;
89582 }
89583
89584+ if (gr_handle_ptrace(child, request)) {
89585+ ret = -EPERM;
89586+ goto out_put_task_struct;
89587+ }
89588+
89589 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89590 ret = ptrace_attach(child, request, addr, data);
89591 /*
89592 * Some architectures need to do book-keeping after
89593 * a ptrace attach.
89594 */
89595- if (!ret)
89596+ if (!ret) {
89597 arch_ptrace_attach(child);
89598+ gr_audit_ptrace(child);
89599+ }
89600 goto out_put_task_struct;
89601 }
89602
89603diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
89604index bd30bc6..dce23da 100644
89605--- a/kernel/rcu/rcutorture.c
89606+++ b/kernel/rcu/rcutorture.c
89607@@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89608 rcu_torture_count) = { 0 };
89609 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89610 rcu_torture_batch) = { 0 };
89611-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89612-static atomic_t n_rcu_torture_alloc;
89613-static atomic_t n_rcu_torture_alloc_fail;
89614-static atomic_t n_rcu_torture_free;
89615-static atomic_t n_rcu_torture_mberror;
89616-static atomic_t n_rcu_torture_error;
89617+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89618+static atomic_unchecked_t n_rcu_torture_alloc;
89619+static atomic_unchecked_t n_rcu_torture_alloc_fail;
89620+static atomic_unchecked_t n_rcu_torture_free;
89621+static atomic_unchecked_t n_rcu_torture_mberror;
89622+static atomic_unchecked_t n_rcu_torture_error;
89623 static long n_rcu_torture_barrier_error;
89624 static long n_rcu_torture_boost_ktrerror;
89625 static long n_rcu_torture_boost_rterror;
89626@@ -186,11 +186,11 @@ rcu_torture_alloc(void)
89627
89628 spin_lock_bh(&rcu_torture_lock);
89629 if (list_empty(&rcu_torture_freelist)) {
89630- atomic_inc(&n_rcu_torture_alloc_fail);
89631+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89632 spin_unlock_bh(&rcu_torture_lock);
89633 return NULL;
89634 }
89635- atomic_inc(&n_rcu_torture_alloc);
89636+ atomic_inc_unchecked(&n_rcu_torture_alloc);
89637 p = rcu_torture_freelist.next;
89638 list_del_init(p);
89639 spin_unlock_bh(&rcu_torture_lock);
89640@@ -203,7 +203,7 @@ rcu_torture_alloc(void)
89641 static void
89642 rcu_torture_free(struct rcu_torture *p)
89643 {
89644- atomic_inc(&n_rcu_torture_free);
89645+ atomic_inc_unchecked(&n_rcu_torture_free);
89646 spin_lock_bh(&rcu_torture_lock);
89647 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89648 spin_unlock_bh(&rcu_torture_lock);
89649@@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
89650 i = rp->rtort_pipe_count;
89651 if (i > RCU_TORTURE_PIPE_LEN)
89652 i = RCU_TORTURE_PIPE_LEN;
89653- atomic_inc(&rcu_torture_wcount[i]);
89654+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89655 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89656 rp->rtort_mbtest = 0;
89657 rcu_torture_free(rp);
89658@@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
89659 i = old_rp->rtort_pipe_count;
89660 if (i > RCU_TORTURE_PIPE_LEN)
89661 i = RCU_TORTURE_PIPE_LEN;
89662- atomic_inc(&rcu_torture_wcount[i]);
89663+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89664 old_rp->rtort_pipe_count++;
89665 if (gp_normal == gp_exp)
89666 exp = !!(torture_random(&rand) & 0x80);
89667@@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
89668 i = rp->rtort_pipe_count;
89669 if (i > RCU_TORTURE_PIPE_LEN)
89670 i = RCU_TORTURE_PIPE_LEN;
89671- atomic_inc(&rcu_torture_wcount[i]);
89672+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89673 if (++rp->rtort_pipe_count >=
89674 RCU_TORTURE_PIPE_LEN) {
89675 rp->rtort_mbtest = 0;
89676@@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
89677 return;
89678 }
89679 if (p->rtort_mbtest == 0)
89680- atomic_inc(&n_rcu_torture_mberror);
89681+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89682 spin_lock(&rand_lock);
89683 cur_ops->read_delay(&rand);
89684 n_rcu_torture_timers++;
89685@@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
89686 continue;
89687 }
89688 if (p->rtort_mbtest == 0)
89689- atomic_inc(&n_rcu_torture_mberror);
89690+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89691 cur_ops->read_delay(&rand);
89692 preempt_disable();
89693 pipe_count = p->rtort_pipe_count;
89694@@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
89695 }
89696 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89697 page += sprintf(page,
89698- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89699+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89700 rcu_torture_current,
89701 rcu_torture_current_version,
89702 list_empty(&rcu_torture_freelist),
89703- atomic_read(&n_rcu_torture_alloc),
89704- atomic_read(&n_rcu_torture_alloc_fail),
89705- atomic_read(&n_rcu_torture_free));
89706+ atomic_read_unchecked(&n_rcu_torture_alloc),
89707+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89708+ atomic_read_unchecked(&n_rcu_torture_free));
89709 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89710- atomic_read(&n_rcu_torture_mberror),
89711+ atomic_read_unchecked(&n_rcu_torture_mberror),
89712 n_rcu_torture_boost_ktrerror,
89713 n_rcu_torture_boost_rterror);
89714 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89715@@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
89716 n_barrier_attempts,
89717 n_rcu_torture_barrier_error);
89718 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89719- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89720+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89721 n_rcu_torture_barrier_error != 0 ||
89722 n_rcu_torture_boost_ktrerror != 0 ||
89723 n_rcu_torture_boost_rterror != 0 ||
89724 n_rcu_torture_boost_failure != 0 ||
89725 i > 1) {
89726 page += sprintf(page, "!!! ");
89727- atomic_inc(&n_rcu_torture_error);
89728+ atomic_inc_unchecked(&n_rcu_torture_error);
89729 WARN_ON_ONCE(1);
89730 }
89731 page += sprintf(page, "Reader Pipe: ");
89732@@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
89733 page += sprintf(page, "Free-Block Circulation: ");
89734 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89735 page += sprintf(page, " %d",
89736- atomic_read(&rcu_torture_wcount[i]));
89737+ atomic_read_unchecked(&rcu_torture_wcount[i]));
89738 }
89739 page += sprintf(page, "\n");
89740 if (cur_ops->stats)
89741@@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
89742
89743 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89744
89745- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89746+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89747 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89748 else if (torture_onoff_failures())
89749 rcu_torture_print_module_parms(cur_ops,
89750@@ -1460,18 +1460,18 @@ rcu_torture_init(void)
89751
89752 rcu_torture_current = NULL;
89753 rcu_torture_current_version = 0;
89754- atomic_set(&n_rcu_torture_alloc, 0);
89755- atomic_set(&n_rcu_torture_alloc_fail, 0);
89756- atomic_set(&n_rcu_torture_free, 0);
89757- atomic_set(&n_rcu_torture_mberror, 0);
89758- atomic_set(&n_rcu_torture_error, 0);
89759+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89760+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89761+ atomic_set_unchecked(&n_rcu_torture_free, 0);
89762+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89763+ atomic_set_unchecked(&n_rcu_torture_error, 0);
89764 n_rcu_torture_barrier_error = 0;
89765 n_rcu_torture_boost_ktrerror = 0;
89766 n_rcu_torture_boost_rterror = 0;
89767 n_rcu_torture_boost_failure = 0;
89768 n_rcu_torture_boosts = 0;
89769 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89770- atomic_set(&rcu_torture_wcount[i], 0);
89771+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89772 for_each_possible_cpu(cpu) {
89773 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89774 per_cpu(rcu_torture_count, cpu)[i] = 0;
89775diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89776index c639556..cf0a0d5 100644
89777--- a/kernel/rcu/srcu.c
89778+++ b/kernel/rcu/srcu.c
89779@@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89780
89781 idx = ACCESS_ONCE(sp->completed) & 0x1;
89782 preempt_disable();
89783- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89784+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89785 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89786- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89787+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89788 preempt_enable();
89789 return idx;
89790 }
89791diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89792index d9efcc1..ea543e9 100644
89793--- a/kernel/rcu/tiny.c
89794+++ b/kernel/rcu/tiny.c
89795@@ -42,7 +42,7 @@
89796 /* Forward declarations for tiny_plugin.h. */
89797 struct rcu_ctrlblk;
89798 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89799-static void rcu_process_callbacks(struct softirq_action *unused);
89800+static void rcu_process_callbacks(void);
89801 static void __call_rcu(struct rcu_head *head,
89802 void (*func)(struct rcu_head *rcu),
89803 struct rcu_ctrlblk *rcp);
89804@@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89805 false));
89806 }
89807
89808-static void rcu_process_callbacks(struct softirq_action *unused)
89809+static __latent_entropy void rcu_process_callbacks(void)
89810 {
89811 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89812 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89813diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89814index 0c47e30..a084591 100644
89815--- a/kernel/rcu/tree.c
89816+++ b/kernel/rcu/tree.c
89817@@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89818 rcu_prepare_for_idle(smp_processor_id());
89819 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89820 smp_mb__before_atomic_inc(); /* See above. */
89821- atomic_inc(&rdtp->dynticks);
89822+ atomic_inc_unchecked(&rdtp->dynticks);
89823 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89824- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89825+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89826
89827 /*
89828 * It is illegal to enter an extended quiescent state while
89829@@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89830 int user)
89831 {
89832 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89833- atomic_inc(&rdtp->dynticks);
89834+ atomic_inc_unchecked(&rdtp->dynticks);
89835 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89836 smp_mb__after_atomic_inc(); /* See above. */
89837- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89838+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89839 rcu_cleanup_after_idle(smp_processor_id());
89840 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89841 if (!user && !is_idle_task(current)) {
89842@@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89843 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89844
89845 if (rdtp->dynticks_nmi_nesting == 0 &&
89846- (atomic_read(&rdtp->dynticks) & 0x1))
89847+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89848 return;
89849 rdtp->dynticks_nmi_nesting++;
89850 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89851- atomic_inc(&rdtp->dynticks);
89852+ atomic_inc_unchecked(&rdtp->dynticks);
89853 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89854 smp_mb__after_atomic_inc(); /* See above. */
89855- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89856+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89857 }
89858
89859 /**
89860@@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89861 return;
89862 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89863 smp_mb__before_atomic_inc(); /* See above. */
89864- atomic_inc(&rdtp->dynticks);
89865+ atomic_inc_unchecked(&rdtp->dynticks);
89866 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89867- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89868+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89869 }
89870
89871 /**
89872@@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89873 */
89874 bool notrace __rcu_is_watching(void)
89875 {
89876- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89877+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89878 }
89879
89880 /**
89881@@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89882 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89883 bool *isidle, unsigned long *maxj)
89884 {
89885- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89886+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89887 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89888 return (rdp->dynticks_snap & 0x1) == 0;
89889 }
89890@@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89891 unsigned int curr;
89892 unsigned int snap;
89893
89894- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89895+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89896 snap = (unsigned int)rdp->dynticks_snap;
89897
89898 /*
89899@@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89900 rdp = this_cpu_ptr(rsp->rda);
89901 rcu_preempt_check_blocked_tasks(rnp);
89902 rnp->qsmask = rnp->qsmaskinit;
89903- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89904+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89905 WARN_ON_ONCE(rnp->completed != rsp->completed);
89906- ACCESS_ONCE(rnp->completed) = rsp->completed;
89907+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89908 if (rnp == rdp->mynode)
89909 __note_gp_changes(rsp, rnp, rdp);
89910 rcu_preempt_boost_start_gp(rnp);
89911@@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89912 rcu_for_each_node_breadth_first(rsp, rnp) {
89913 raw_spin_lock_irq(&rnp->lock);
89914 smp_mb__after_unlock_lock();
89915- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89916+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89917 rdp = this_cpu_ptr(rsp->rda);
89918 if (rnp == rdp->mynode)
89919 __note_gp_changes(rsp, rnp, rdp);
89920@@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89921 rcu_nocb_gp_set(rnp, nocb);
89922
89923 /* Declare grace period done. */
89924- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89925+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89926 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89927 rsp->fqs_state = RCU_GP_IDLE;
89928 rdp = this_cpu_ptr(rsp->rda);
89929@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89930 rsp->qlen += rdp->qlen;
89931 rdp->n_cbs_orphaned += rdp->qlen;
89932 rdp->qlen_lazy = 0;
89933- ACCESS_ONCE(rdp->qlen) = 0;
89934+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89935 }
89936
89937 /*
89938@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89939 }
89940 smp_mb(); /* List handling before counting for rcu_barrier(). */
89941 rdp->qlen_lazy -= count_lazy;
89942- ACCESS_ONCE(rdp->qlen) -= count;
89943+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89944 rdp->n_cbs_invoked += count;
89945
89946 /* Reinstate batch limit if we have worked down the excess. */
89947@@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89948 if (rnp_old != NULL)
89949 raw_spin_unlock(&rnp_old->fqslock);
89950 if (ret) {
89951- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89952+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89953 return;
89954 }
89955 rnp_old = rnp;
89956@@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89957 smp_mb__after_unlock_lock();
89958 raw_spin_unlock(&rnp_old->fqslock);
89959 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89960- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89961+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89962 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89963 return; /* Someone beat us to it. */
89964 }
89965@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89966 /*
89967 * Do RCU core processing for the current CPU.
89968 */
89969-static void rcu_process_callbacks(struct softirq_action *unused)
89970+static void rcu_process_callbacks(void)
89971 {
89972 struct rcu_state *rsp;
89973
89974@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89975 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89976 if (debug_rcu_head_queue(head)) {
89977 /* Probable double call_rcu(), so leak the callback. */
89978- ACCESS_ONCE(head->func) = rcu_leak_callback;
89979+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89980 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89981 return;
89982 }
89983@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89984 local_irq_restore(flags);
89985 return;
89986 }
89987- ACCESS_ONCE(rdp->qlen)++;
89988+ ACCESS_ONCE_RW(rdp->qlen)++;
89989 if (lazy)
89990 rdp->qlen_lazy++;
89991 else
89992@@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89993 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89994 * course be required on a 64-bit system.
89995 */
89996- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89997+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89998 (ulong)atomic_long_read(&rsp->expedited_done) +
89999 ULONG_MAX / 8)) {
90000 synchronize_sched();
90001- atomic_long_inc(&rsp->expedited_wrap);
90002+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
90003 return;
90004 }
90005
90006@@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
90007 * Take a ticket. Note that atomic_inc_return() implies a
90008 * full memory barrier.
90009 */
90010- snap = atomic_long_inc_return(&rsp->expedited_start);
90011+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
90012 firstsnap = snap;
90013 get_online_cpus();
90014 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
90015@@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
90016 synchronize_sched_expedited_cpu_stop,
90017 NULL) == -EAGAIN) {
90018 put_online_cpus();
90019- atomic_long_inc(&rsp->expedited_tryfail);
90020+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
90021
90022 /* Check to see if someone else did our work for us. */
90023 s = atomic_long_read(&rsp->expedited_done);
90024 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
90025 /* ensure test happens before caller kfree */
90026 smp_mb__before_atomic_inc(); /* ^^^ */
90027- atomic_long_inc(&rsp->expedited_workdone1);
90028+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
90029 return;
90030 }
90031
90032@@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
90033 udelay(trycount * num_online_cpus());
90034 } else {
90035 wait_rcu_gp(call_rcu_sched);
90036- atomic_long_inc(&rsp->expedited_normal);
90037+ atomic_long_inc_unchecked(&rsp->expedited_normal);
90038 return;
90039 }
90040
90041@@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
90042 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
90043 /* ensure test happens before caller kfree */
90044 smp_mb__before_atomic_inc(); /* ^^^ */
90045- atomic_long_inc(&rsp->expedited_workdone2);
90046+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
90047 return;
90048 }
90049
90050@@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
90051 * period works for us.
90052 */
90053 get_online_cpus();
90054- snap = atomic_long_read(&rsp->expedited_start);
90055+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
90056 smp_mb(); /* ensure read is before try_stop_cpus(). */
90057 }
90058- atomic_long_inc(&rsp->expedited_stoppedcpus);
90059+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
90060
90061 /*
90062 * Everyone up to our most recent fetch is covered by our grace
90063@@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
90064 * than we did already did their update.
90065 */
90066 do {
90067- atomic_long_inc(&rsp->expedited_done_tries);
90068+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
90069 s = atomic_long_read(&rsp->expedited_done);
90070 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
90071 /* ensure test happens before caller kfree */
90072 smp_mb__before_atomic_inc(); /* ^^^ */
90073- atomic_long_inc(&rsp->expedited_done_lost);
90074+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
90075 break;
90076 }
90077 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
90078- atomic_long_inc(&rsp->expedited_done_exit);
90079+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
90080
90081 put_online_cpus();
90082 }
90083@@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
90084 * ACCESS_ONCE() to prevent the compiler from speculating
90085 * the increment to precede the early-exit check.
90086 */
90087- ACCESS_ONCE(rsp->n_barrier_done)++;
90088+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
90089 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
90090 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
90091 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
90092@@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
90093
90094 /* Increment ->n_barrier_done to prevent duplicate work. */
90095 smp_mb(); /* Keep increment after above mechanism. */
90096- ACCESS_ONCE(rsp->n_barrier_done)++;
90097+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
90098 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
90099 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
90100 smp_mb(); /* Keep increment before caller's subsequent code. */
90101@@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
90102 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
90103 init_callback_list(rdp);
90104 rdp->qlen_lazy = 0;
90105- ACCESS_ONCE(rdp->qlen) = 0;
90106+ ACCESS_ONCE_RW(rdp->qlen) = 0;
90107 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
90108 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
90109- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
90110+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
90111 rdp->cpu = cpu;
90112 rdp->rsp = rsp;
90113 rcu_boot_init_nocb_percpu_data(rdp);
90114@@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
90115 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
90116 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
90117 rcu_sysidle_init_percpu_data(rdp->dynticks);
90118- atomic_set(&rdp->dynticks->dynticks,
90119- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
90120+ atomic_set_unchecked(&rdp->dynticks->dynticks,
90121+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
90122 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
90123
90124 /* Add CPU to rcu_node bitmasks. */
90125diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
90126index 75dc3c3..b95d624 100644
90127--- a/kernel/rcu/tree.h
90128+++ b/kernel/rcu/tree.h
90129@@ -87,11 +87,11 @@ struct rcu_dynticks {
90130 long long dynticks_nesting; /* Track irq/process nesting level. */
90131 /* Process level is worth LLONG_MAX/2. */
90132 int dynticks_nmi_nesting; /* Track NMI nesting level. */
90133- atomic_t dynticks; /* Even value for idle, else odd. */
90134+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
90135 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
90136 long long dynticks_idle_nesting;
90137 /* irq/process nesting level from idle. */
90138- atomic_t dynticks_idle; /* Even value for idle, else odd. */
90139+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
90140 /* "Idle" excludes userspace execution. */
90141 unsigned long dynticks_idle_jiffies;
90142 /* End of last non-NMI non-idle period. */
90143@@ -431,17 +431,17 @@ struct rcu_state {
90144 /* _rcu_barrier(). */
90145 /* End of fields guarded by barrier_mutex. */
90146
90147- atomic_long_t expedited_start; /* Starting ticket. */
90148- atomic_long_t expedited_done; /* Done ticket. */
90149- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
90150- atomic_long_t expedited_tryfail; /* # acquisition failures. */
90151- atomic_long_t expedited_workdone1; /* # done by others #1. */
90152- atomic_long_t expedited_workdone2; /* # done by others #2. */
90153- atomic_long_t expedited_normal; /* # fallbacks to normal. */
90154- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
90155- atomic_long_t expedited_done_tries; /* # tries to update _done. */
90156- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
90157- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
90158+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
90159+ atomic_long_t expedited_done; /* Done ticket. */
90160+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
90161+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
90162+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
90163+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
90164+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
90165+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
90166+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
90167+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
90168+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
90169
90170 unsigned long jiffies_force_qs; /* Time at which to invoke */
90171 /* force_quiescent_state(). */
90172diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
90173index 962d1d5..c6c62d12d 100644
90174--- a/kernel/rcu/tree_plugin.h
90175+++ b/kernel/rcu/tree_plugin.h
90176@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
90177 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
90178 {
90179 return !rcu_preempted_readers_exp(rnp) &&
90180- ACCESS_ONCE(rnp->expmask) == 0;
90181+ ACCESS_ONCE_RW(rnp->expmask) == 0;
90182 }
90183
90184 /*
90185@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
90186
90187 /* Clean up and exit. */
90188 smp_mb(); /* ensure expedited GP seen before counter increment. */
90189- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
90190+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
90191 unlock_mb_ret:
90192 mutex_unlock(&sync_rcu_preempt_exp_mutex);
90193 mb_ret:
90194@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
90195 free_cpumask_var(cm);
90196 }
90197
90198-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
90199+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
90200 .store = &rcu_cpu_kthread_task,
90201 .thread_should_run = rcu_cpu_kthread_should_run,
90202 .thread_fn = rcu_cpu_kthread,
90203@@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
90204 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
90205 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
90206 cpu, ticks_value, ticks_title,
90207- atomic_read(&rdtp->dynticks) & 0xfff,
90208+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
90209 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
90210 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
90211 fast_no_hz);
90212@@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
90213
90214 /* Enqueue the callback on the nocb list and update counts. */
90215 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
90216- ACCESS_ONCE(*old_rhpp) = rhp;
90217+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
90218 atomic_long_add(rhcount, &rdp->nocb_q_count);
90219 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
90220
90221@@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
90222 * Extract queued callbacks, update counts, and wait
90223 * for a grace period to elapse.
90224 */
90225- ACCESS_ONCE(rdp->nocb_head) = NULL;
90226+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
90227 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
90228 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
90229 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
90230- ACCESS_ONCE(rdp->nocb_p_count) += c;
90231- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
90232+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
90233+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
90234 rcu_nocb_wait_gp(rdp);
90235
90236 /* Each pass through the following loop invokes a callback. */
90237@@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
90238 list = next;
90239 }
90240 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
90241- ACCESS_ONCE(rdp->nocb_p_count) -= c;
90242- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
90243+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
90244+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
90245 rdp->n_nocbs_invoked += c;
90246 }
90247 return 0;
90248@@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
90249 {
90250 if (!rcu_nocb_need_deferred_wakeup(rdp))
90251 return;
90252- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
90253+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
90254 wake_up(&rdp->nocb_wq);
90255 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
90256 }
90257@@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
90258 t = kthread_run(rcu_nocb_kthread, rdp,
90259 "rcuo%c/%d", rsp->abbr, cpu);
90260 BUG_ON(IS_ERR(t));
90261- ACCESS_ONCE(rdp->nocb_kthread) = t;
90262+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
90263 }
90264 }
90265
90266@@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
90267
90268 /* Record start of fully idle period. */
90269 j = jiffies;
90270- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
90271+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
90272 smp_mb__before_atomic_inc();
90273- atomic_inc(&rdtp->dynticks_idle);
90274+ atomic_inc_unchecked(&rdtp->dynticks_idle);
90275 smp_mb__after_atomic_inc();
90276- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
90277+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
90278 }
90279
90280 /*
90281@@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
90282
90283 /* Record end of idle period. */
90284 smp_mb__before_atomic_inc();
90285- atomic_inc(&rdtp->dynticks_idle);
90286+ atomic_inc_unchecked(&rdtp->dynticks_idle);
90287 smp_mb__after_atomic_inc();
90288- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
90289+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
90290
90291 /*
90292 * If we are the timekeeping CPU, we are permitted to be non-idle
90293@@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
90294 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
90295
90296 /* Pick up current idle and NMI-nesting counter and check. */
90297- cur = atomic_read(&rdtp->dynticks_idle);
90298+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
90299 if (cur & 0x1) {
90300 *isidle = false; /* We are not idle! */
90301 return;
90302@@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
90303 case RCU_SYSIDLE_NOT:
90304
90305 /* First time all are idle, so note a short idle period. */
90306- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
90307+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
90308 break;
90309
90310 case RCU_SYSIDLE_SHORT:
90311@@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
90312 static void rcu_sysidle_cancel(void)
90313 {
90314 smp_mb();
90315- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
90316+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
90317 }
90318
90319 /*
90320@@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
90321 smp_mb(); /* grace period precedes setting inuse. */
90322
90323 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
90324- ACCESS_ONCE(rshp->inuse) = 0;
90325+ ACCESS_ONCE_RW(rshp->inuse) = 0;
90326 }
90327
90328 /*
90329diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
90330index 5cdc62e..cc52e88 100644
90331--- a/kernel/rcu/tree_trace.c
90332+++ b/kernel/rcu/tree_trace.c
90333@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
90334 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
90335 rdp->passed_quiesce, rdp->qs_pending);
90336 seq_printf(m, " dt=%d/%llx/%d df=%lu",
90337- atomic_read(&rdp->dynticks->dynticks),
90338+ atomic_read_unchecked(&rdp->dynticks->dynticks),
90339 rdp->dynticks->dynticks_nesting,
90340 rdp->dynticks->dynticks_nmi_nesting,
90341 rdp->dynticks_fqs);
90342@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
90343 struct rcu_state *rsp = (struct rcu_state *)m->private;
90344
90345 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",
90346- atomic_long_read(&rsp->expedited_start),
90347+ atomic_long_read_unchecked(&rsp->expedited_start),
90348 atomic_long_read(&rsp->expedited_done),
90349- atomic_long_read(&rsp->expedited_wrap),
90350- atomic_long_read(&rsp->expedited_tryfail),
90351- atomic_long_read(&rsp->expedited_workdone1),
90352- atomic_long_read(&rsp->expedited_workdone2),
90353- atomic_long_read(&rsp->expedited_normal),
90354- atomic_long_read(&rsp->expedited_stoppedcpus),
90355- atomic_long_read(&rsp->expedited_done_tries),
90356- atomic_long_read(&rsp->expedited_done_lost),
90357- atomic_long_read(&rsp->expedited_done_exit));
90358+ atomic_long_read_unchecked(&rsp->expedited_wrap),
90359+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
90360+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
90361+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
90362+ atomic_long_read_unchecked(&rsp->expedited_normal),
90363+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
90364+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
90365+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
90366+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
90367 return 0;
90368 }
90369
90370diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
90371index 4c0a9b0..7e81362 100644
90372--- a/kernel/rcu/update.c
90373+++ b/kernel/rcu/update.c
90374@@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
90375 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
90376 */
90377 if (till_stall_check < 3) {
90378- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
90379+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
90380 till_stall_check = 3;
90381 } else if (till_stall_check > 300) {
90382- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
90383+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
90384 till_stall_check = 300;
90385 }
90386 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
90387diff --git a/kernel/resource.c b/kernel/resource.c
90388index 8957d68..770cbe4 100644
90389--- a/kernel/resource.c
90390+++ b/kernel/resource.c
90391@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
90392
90393 static int __init ioresources_init(void)
90394 {
90395+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90396+#ifdef CONFIG_GRKERNSEC_PROC_USER
90397+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
90398+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
90399+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90400+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
90401+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
90402+#endif
90403+#else
90404 proc_create("ioports", 0, NULL, &proc_ioports_operations);
90405 proc_create("iomem", 0, NULL, &proc_iomem_operations);
90406+#endif
90407 return 0;
90408 }
90409 __initcall(ioresources_init);
90410diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
90411index e73efba..c9bfbd4 100644
90412--- a/kernel/sched/auto_group.c
90413+++ b/kernel/sched/auto_group.c
90414@@ -11,7 +11,7 @@
90415
90416 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
90417 static struct autogroup autogroup_default;
90418-static atomic_t autogroup_seq_nr;
90419+static atomic_unchecked_t autogroup_seq_nr;
90420
90421 void __init autogroup_init(struct task_struct *init_task)
90422 {
90423@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
90424
90425 kref_init(&ag->kref);
90426 init_rwsem(&ag->lock);
90427- ag->id = atomic_inc_return(&autogroup_seq_nr);
90428+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
90429 ag->tg = tg;
90430 #ifdef CONFIG_RT_GROUP_SCHED
90431 /*
90432diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
90433index a63f4dc..349bbb0 100644
90434--- a/kernel/sched/completion.c
90435+++ b/kernel/sched/completion.c
90436@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
90437 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90438 * or number of jiffies left till timeout) if completed.
90439 */
90440-long __sched
90441+long __sched __intentional_overflow(-1)
90442 wait_for_completion_interruptible_timeout(struct completion *x,
90443 unsigned long timeout)
90444 {
90445@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
90446 *
90447 * Return: -ERESTARTSYS if interrupted, 0 if completed.
90448 */
90449-int __sched wait_for_completion_killable(struct completion *x)
90450+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
90451 {
90452 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
90453 if (t == -ERESTARTSYS)
90454@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
90455 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90456 * or number of jiffies left till timeout) if completed.
90457 */
90458-long __sched
90459+long __sched __intentional_overflow(-1)
90460 wait_for_completion_killable_timeout(struct completion *x,
90461 unsigned long timeout)
90462 {
90463diff --git a/kernel/sched/core.c b/kernel/sched/core.c
90464index 8da7e49..ef10a02 100644
90465--- a/kernel/sched/core.c
90466+++ b/kernel/sched/core.c
90467@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
90468 int sysctl_numa_balancing(struct ctl_table *table, int write,
90469 void __user *buffer, size_t *lenp, loff_t *ppos)
90470 {
90471- struct ctl_table t;
90472+ ctl_table_no_const t;
90473 int err;
90474 int state = numabalancing_enabled;
90475
90476@@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
90477 next->active_mm = oldmm;
90478 atomic_inc(&oldmm->mm_count);
90479 enter_lazy_tlb(oldmm, next);
90480- } else
90481+ } else {
90482 switch_mm(oldmm, mm, next);
90483+ populate_stack();
90484+ }
90485
90486 if (!prev->mm) {
90487 prev->active_mm = NULL;
90488@@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
90489 /* convert nice value [19,-20] to rlimit style value [1,40] */
90490 int nice_rlim = 20 - nice;
90491
90492+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
90493+
90494 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
90495 capable(CAP_SYS_NICE));
90496 }
90497@@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
90498 if (nice > MAX_NICE)
90499 nice = MAX_NICE;
90500
90501- if (increment < 0 && !can_nice(current, nice))
90502+ if (increment < 0 && (!can_nice(current, nice) ||
90503+ gr_handle_chroot_nice()))
90504 return -EPERM;
90505
90506 retval = security_task_setnice(current, nice);
90507@@ -3310,6 +3315,7 @@ recheck:
90508 if (policy != p->policy && !rlim_rtprio)
90509 return -EPERM;
90510
90511+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
90512 /* can't increase priority */
90513 if (attr->sched_priority > p->rt_priority &&
90514 attr->sched_priority > rlim_rtprio)
90515@@ -4708,6 +4714,7 @@ void idle_task_exit(void)
90516
90517 if (mm != &init_mm) {
90518 switch_mm(mm, &init_mm, current);
90519+ populate_stack();
90520 finish_arch_post_lock_switch();
90521 }
90522 mmdrop(mm);
90523@@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
90524
90525 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
90526
90527-static struct ctl_table sd_ctl_dir[] = {
90528+static ctl_table_no_const sd_ctl_dir[] __read_only = {
90529 {
90530 .procname = "sched_domain",
90531 .mode = 0555,
90532@@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
90533 {}
90534 };
90535
90536-static struct ctl_table *sd_alloc_ctl_entry(int n)
90537+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
90538 {
90539- struct ctl_table *entry =
90540+ ctl_table_no_const *entry =
90541 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
90542
90543 return entry;
90544 }
90545
90546-static void sd_free_ctl_entry(struct ctl_table **tablep)
90547+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
90548 {
90549- struct ctl_table *entry;
90550+ ctl_table_no_const *entry;
90551
90552 /*
90553 * In the intermediate directories, both the child directory and
90554@@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
90555 * will always be set. In the lowest directory the names are
90556 * static strings and all have proc handlers.
90557 */
90558- for (entry = *tablep; entry->mode; entry++) {
90559- if (entry->child)
90560- sd_free_ctl_entry(&entry->child);
90561+ for (entry = tablep; entry->mode; entry++) {
90562+ if (entry->child) {
90563+ sd_free_ctl_entry(entry->child);
90564+ pax_open_kernel();
90565+ entry->child = NULL;
90566+ pax_close_kernel();
90567+ }
90568 if (entry->proc_handler == NULL)
90569 kfree(entry->procname);
90570 }
90571
90572- kfree(*tablep);
90573- *tablep = NULL;
90574+ kfree(tablep);
90575 }
90576
90577 static int min_load_idx = 0;
90578 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
90579
90580 static void
90581-set_table_entry(struct ctl_table *entry,
90582+set_table_entry(ctl_table_no_const *entry,
90583 const char *procname, void *data, int maxlen,
90584 umode_t mode, proc_handler *proc_handler,
90585 bool load_idx)
90586@@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
90587 static struct ctl_table *
90588 sd_alloc_ctl_domain_table(struct sched_domain *sd)
90589 {
90590- struct ctl_table *table = sd_alloc_ctl_entry(14);
90591+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
90592
90593 if (table == NULL)
90594 return NULL;
90595@@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
90596 return table;
90597 }
90598
90599-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
90600+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
90601 {
90602- struct ctl_table *entry, *table;
90603+ ctl_table_no_const *entry, *table;
90604 struct sched_domain *sd;
90605 int domain_num = 0, i;
90606 char buf[32];
90607@@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
90608 static void register_sched_domain_sysctl(void)
90609 {
90610 int i, cpu_num = num_possible_cpus();
90611- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
90612+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
90613 char buf[32];
90614
90615 WARN_ON(sd_ctl_dir[0].child);
90616+ pax_open_kernel();
90617 sd_ctl_dir[0].child = entry;
90618+ pax_close_kernel();
90619
90620 if (entry == NULL)
90621 return;
90622@@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
90623 if (sd_sysctl_header)
90624 unregister_sysctl_table(sd_sysctl_header);
90625 sd_sysctl_header = NULL;
90626- if (sd_ctl_dir[0].child)
90627- sd_free_ctl_entry(&sd_ctl_dir[0].child);
90628+ if (sd_ctl_dir[0].child) {
90629+ sd_free_ctl_entry(sd_ctl_dir[0].child);
90630+ pax_open_kernel();
90631+ sd_ctl_dir[0].child = NULL;
90632+ pax_close_kernel();
90633+ }
90634 }
90635 #else
90636 static void register_sched_domain_sysctl(void)
90637diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
90638index 8cbe2d2..61f20a1 100644
90639--- a/kernel/sched/fair.c
90640+++ b/kernel/sched/fair.c
90641@@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
90642
90643 static void reset_ptenuma_scan(struct task_struct *p)
90644 {
90645- ACCESS_ONCE(p->mm->numa_scan_seq)++;
90646+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
90647 p->mm->numa_scan_offset = 0;
90648 }
90649
90650@@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
90651 * run_rebalance_domains is triggered when needed from the scheduler tick.
90652 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
90653 */
90654-static void run_rebalance_domains(struct softirq_action *h)
90655+static __latent_entropy void run_rebalance_domains(void)
90656 {
90657 struct rq *this_rq = this_rq();
90658 enum cpu_idle_type idle = this_rq->idle_balance ?
90659diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
90660index 369b4d6..fa4eb3b 100644
90661--- a/kernel/sched/sched.h
90662+++ b/kernel/sched/sched.h
90663@@ -1157,7 +1157,7 @@ struct sched_class {
90664 #ifdef CONFIG_FAIR_GROUP_SCHED
90665 void (*task_move_group) (struct task_struct *p, int on_rq);
90666 #endif
90667-};
90668+} __do_const;
90669
90670 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
90671 {
90672diff --git a/kernel/signal.c b/kernel/signal.c
90673index 6ea13c0..31e3b25 100644
90674--- a/kernel/signal.c
90675+++ b/kernel/signal.c
90676@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
90677
90678 int print_fatal_signals __read_mostly;
90679
90680-static void __user *sig_handler(struct task_struct *t, int sig)
90681+static __sighandler_t sig_handler(struct task_struct *t, int sig)
90682 {
90683 return t->sighand->action[sig - 1].sa.sa_handler;
90684 }
90685
90686-static int sig_handler_ignored(void __user *handler, int sig)
90687+static int sig_handler_ignored(__sighandler_t handler, int sig)
90688 {
90689 /* Is it explicitly or implicitly ignored? */
90690 return handler == SIG_IGN ||
90691@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90692
90693 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90694 {
90695- void __user *handler;
90696+ __sighandler_t handler;
90697
90698 handler = sig_handler(t, sig);
90699
90700@@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90701 atomic_inc(&user->sigpending);
90702 rcu_read_unlock();
90703
90704+ if (!override_rlimit)
90705+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90706+
90707 if (override_rlimit ||
90708 atomic_read(&user->sigpending) <=
90709 task_rlimit(t, RLIMIT_SIGPENDING)) {
90710@@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90711
90712 int unhandled_signal(struct task_struct *tsk, int sig)
90713 {
90714- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90715+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90716 if (is_global_init(tsk))
90717 return 1;
90718 if (handler != SIG_IGN && handler != SIG_DFL)
90719@@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90720 }
90721 }
90722
90723+ /* allow glibc communication via tgkill to other threads in our
90724+ thread group */
90725+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90726+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90727+ && gr_handle_signal(t, sig))
90728+ return -EPERM;
90729+
90730 return security_task_kill(t, info, sig, 0);
90731 }
90732
90733@@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90734 return send_signal(sig, info, p, 1);
90735 }
90736
90737-static int
90738+int
90739 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90740 {
90741 return send_signal(sig, info, t, 0);
90742@@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90743 unsigned long int flags;
90744 int ret, blocked, ignored;
90745 struct k_sigaction *action;
90746+ int is_unhandled = 0;
90747
90748 spin_lock_irqsave(&t->sighand->siglock, flags);
90749 action = &t->sighand->action[sig-1];
90750@@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90751 }
90752 if (action->sa.sa_handler == SIG_DFL)
90753 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90754+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90755+ is_unhandled = 1;
90756 ret = specific_send_sig_info(sig, info, t);
90757 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90758
90759+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
90760+ normal operation */
90761+ if (is_unhandled) {
90762+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90763+ gr_handle_crash(t, sig);
90764+ }
90765+
90766 return ret;
90767 }
90768
90769@@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90770 ret = check_kill_permission(sig, info, p);
90771 rcu_read_unlock();
90772
90773- if (!ret && sig)
90774+ if (!ret && sig) {
90775 ret = do_send_sig_info(sig, info, p, true);
90776+ if (!ret)
90777+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90778+ }
90779
90780 return ret;
90781 }
90782@@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90783 int error = -ESRCH;
90784
90785 rcu_read_lock();
90786- p = find_task_by_vpid(pid);
90787+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90788+ /* allow glibc communication via tgkill to other threads in our
90789+ thread group */
90790+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90791+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90792+ p = find_task_by_vpid_unrestricted(pid);
90793+ else
90794+#endif
90795+ p = find_task_by_vpid(pid);
90796 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90797 error = check_kill_permission(sig, info, p);
90798 /*
90799@@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90800 }
90801 seg = get_fs();
90802 set_fs(KERNEL_DS);
90803- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90804- (stack_t __force __user *) &uoss,
90805+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90806+ (stack_t __force_user *) &uoss,
90807 compat_user_stack_pointer());
90808 set_fs(seg);
90809 if (ret >= 0 && uoss_ptr) {
90810diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90811index eb89e18..a4e6792 100644
90812--- a/kernel/smpboot.c
90813+++ b/kernel/smpboot.c
90814@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90815 }
90816 smpboot_unpark_thread(plug_thread, cpu);
90817 }
90818- list_add(&plug_thread->list, &hotplug_threads);
90819+ pax_list_add(&plug_thread->list, &hotplug_threads);
90820 out:
90821 mutex_unlock(&smpboot_threads_lock);
90822 return ret;
90823@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90824 {
90825 get_online_cpus();
90826 mutex_lock(&smpboot_threads_lock);
90827- list_del(&plug_thread->list);
90828+ pax_list_del(&plug_thread->list);
90829 smpboot_destroy_threads(plug_thread);
90830 mutex_unlock(&smpboot_threads_lock);
90831 put_online_cpus();
90832diff --git a/kernel/softirq.c b/kernel/softirq.c
90833index 92f24f5..db41501 100644
90834--- a/kernel/softirq.c
90835+++ b/kernel/softirq.c
90836@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90837 EXPORT_SYMBOL(irq_stat);
90838 #endif
90839
90840-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90841+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90842
90843 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90844
90845@@ -268,7 +268,7 @@ restart:
90846 kstat_incr_softirqs_this_cpu(vec_nr);
90847
90848 trace_softirq_entry(vec_nr);
90849- h->action(h);
90850+ h->action();
90851 trace_softirq_exit(vec_nr);
90852 if (unlikely(prev_count != preempt_count())) {
90853 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90854@@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90855 or_softirq_pending(1UL << nr);
90856 }
90857
90858-void open_softirq(int nr, void (*action)(struct softirq_action *))
90859+void __init open_softirq(int nr, void (*action)(void))
90860 {
90861 softirq_vec[nr].action = action;
90862 }
90863@@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90864 }
90865 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90866
90867-static void tasklet_action(struct softirq_action *a)
90868+static void tasklet_action(void)
90869 {
90870 struct tasklet_struct *list;
90871
90872@@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90873 }
90874 }
90875
90876-static void tasklet_hi_action(struct softirq_action *a)
90877+static __latent_entropy void tasklet_hi_action(void)
90878 {
90879 struct tasklet_struct *list;
90880
90881@@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90882 .notifier_call = cpu_callback
90883 };
90884
90885-static struct smp_hotplug_thread softirq_threads = {
90886+static struct smp_hotplug_thread softirq_threads __read_only = {
90887 .store = &ksoftirqd,
90888 .thread_should_run = ksoftirqd_should_run,
90889 .thread_fn = run_ksoftirqd,
90890diff --git a/kernel/sys.c b/kernel/sys.c
90891index fba0f29..84400e2 100644
90892--- a/kernel/sys.c
90893+++ b/kernel/sys.c
90894@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90895 error = -EACCES;
90896 goto out;
90897 }
90898+
90899+ if (gr_handle_chroot_setpriority(p, niceval)) {
90900+ error = -EACCES;
90901+ goto out;
90902+ }
90903+
90904 no_nice = security_task_setnice(p, niceval);
90905 if (no_nice) {
90906 error = no_nice;
90907@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90908 goto error;
90909 }
90910
90911+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90912+ goto error;
90913+
90914 if (rgid != (gid_t) -1 ||
90915 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90916 new->sgid = new->egid;
90917@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90918 old = current_cred();
90919
90920 retval = -EPERM;
90921+
90922+ if (gr_check_group_change(kgid, kgid, kgid))
90923+ goto error;
90924+
90925 if (ns_capable(old->user_ns, CAP_SETGID))
90926 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90927 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90928@@ -403,7 +416,7 @@ error:
90929 /*
90930 * change the user struct in a credentials set to match the new UID
90931 */
90932-static int set_user(struct cred *new)
90933+int set_user(struct cred *new)
90934 {
90935 struct user_struct *new_user;
90936
90937@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90938 goto error;
90939 }
90940
90941+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90942+ goto error;
90943+
90944 if (!uid_eq(new->uid, old->uid)) {
90945 retval = set_user(new);
90946 if (retval < 0)
90947@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90948 old = current_cred();
90949
90950 retval = -EPERM;
90951+
90952+ if (gr_check_crash_uid(kuid))
90953+ goto error;
90954+ if (gr_check_user_change(kuid, kuid, kuid))
90955+ goto error;
90956+
90957 if (ns_capable(old->user_ns, CAP_SETUID)) {
90958 new->suid = new->uid = kuid;
90959 if (!uid_eq(kuid, old->uid)) {
90960@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90961 goto error;
90962 }
90963
90964+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90965+ goto error;
90966+
90967 if (ruid != (uid_t) -1) {
90968 new->uid = kruid;
90969 if (!uid_eq(kruid, old->uid)) {
90970@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90971 goto error;
90972 }
90973
90974+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90975+ goto error;
90976+
90977 if (rgid != (gid_t) -1)
90978 new->gid = krgid;
90979 if (egid != (gid_t) -1)
90980@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90981 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90982 ns_capable(old->user_ns, CAP_SETUID)) {
90983 if (!uid_eq(kuid, old->fsuid)) {
90984+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90985+ goto error;
90986+
90987 new->fsuid = kuid;
90988 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90989 goto change_okay;
90990 }
90991 }
90992
90993+error:
90994 abort_creds(new);
90995 return old_fsuid;
90996
90997@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90998 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90999 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
91000 ns_capable(old->user_ns, CAP_SETGID)) {
91001+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
91002+ goto error;
91003+
91004 if (!gid_eq(kgid, old->fsgid)) {
91005 new->fsgid = kgid;
91006 goto change_okay;
91007 }
91008 }
91009
91010+error:
91011 abort_creds(new);
91012 return old_fsgid;
91013
91014@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
91015 return -EFAULT;
91016
91017 down_read(&uts_sem);
91018- error = __copy_to_user(&name->sysname, &utsname()->sysname,
91019+ error = __copy_to_user(name->sysname, &utsname()->sysname,
91020 __OLD_UTS_LEN);
91021 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
91022- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
91023+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
91024 __OLD_UTS_LEN);
91025 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
91026- error |= __copy_to_user(&name->release, &utsname()->release,
91027+ error |= __copy_to_user(name->release, &utsname()->release,
91028 __OLD_UTS_LEN);
91029 error |= __put_user(0, name->release + __OLD_UTS_LEN);
91030- error |= __copy_to_user(&name->version, &utsname()->version,
91031+ error |= __copy_to_user(name->version, &utsname()->version,
91032 __OLD_UTS_LEN);
91033 error |= __put_user(0, name->version + __OLD_UTS_LEN);
91034- error |= __copy_to_user(&name->machine, &utsname()->machine,
91035+ error |= __copy_to_user(name->machine, &utsname()->machine,
91036 __OLD_UTS_LEN);
91037 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
91038 up_read(&uts_sem);
91039@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
91040 */
91041 new_rlim->rlim_cur = 1;
91042 }
91043+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
91044+ is changed to a lower value. Since tasks can be created by the same
91045+ user in between this limit change and an execve by this task, force
91046+ a recheck only for this task by setting PF_NPROC_EXCEEDED
91047+ */
91048+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
91049+ tsk->flags |= PF_NPROC_EXCEEDED;
91050 }
91051 if (!retval) {
91052 if (old_rlim)
91053diff --git a/kernel/sysctl.c b/kernel/sysctl.c
91054index 0e0373f..69f5181 100644
91055--- a/kernel/sysctl.c
91056+++ b/kernel/sysctl.c
91057@@ -94,7 +94,6 @@
91058
91059
91060 #if defined(CONFIG_SYSCTL)
91061-
91062 /* External variables not in a header file. */
91063 extern int max_threads;
91064 extern int suid_dumpable;
91065@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
91066
91067 /* Constants used for minimum and maximum */
91068 #ifdef CONFIG_LOCKUP_DETECTOR
91069-static int sixty = 60;
91070+static int sixty __read_only = 60;
91071 #endif
91072
91073-static int __maybe_unused neg_one = -1;
91074+static int __maybe_unused neg_one __read_only = -1;
91075
91076-static int zero;
91077-static int __maybe_unused one = 1;
91078-static int __maybe_unused two = 2;
91079-static int __maybe_unused four = 4;
91080-static unsigned long one_ul = 1;
91081-static int one_hundred = 100;
91082+static int zero __read_only = 0;
91083+static int __maybe_unused one __read_only = 1;
91084+static int __maybe_unused two __read_only = 2;
91085+static int __maybe_unused three __read_only = 3;
91086+static int __maybe_unused four __read_only = 4;
91087+static unsigned long one_ul __read_only = 1;
91088+static int one_hundred __read_only = 100;
91089 #ifdef CONFIG_PRINTK
91090-static int ten_thousand = 10000;
91091+static int ten_thousand __read_only = 10000;
91092 #endif
91093
91094 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
91095@@ -178,10 +178,8 @@ static int proc_taint(struct ctl_table *table, int write,
91096 void __user *buffer, size_t *lenp, loff_t *ppos);
91097 #endif
91098
91099-#ifdef CONFIG_PRINTK
91100 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
91101 void __user *buffer, size_t *lenp, loff_t *ppos);
91102-#endif
91103
91104 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
91105 void __user *buffer, size_t *lenp, loff_t *ppos);
91106@@ -212,6 +210,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
91107
91108 #endif
91109
91110+extern struct ctl_table grsecurity_table[];
91111+
91112 static struct ctl_table kern_table[];
91113 static struct ctl_table vm_table[];
91114 static struct ctl_table fs_table[];
91115@@ -226,6 +226,20 @@ extern struct ctl_table epoll_table[];
91116 int sysctl_legacy_va_layout;
91117 #endif
91118
91119+#ifdef CONFIG_PAX_SOFTMODE
91120+static ctl_table pax_table[] = {
91121+ {
91122+ .procname = "softmode",
91123+ .data = &pax_softmode,
91124+ .maxlen = sizeof(unsigned int),
91125+ .mode = 0600,
91126+ .proc_handler = &proc_dointvec,
91127+ },
91128+
91129+ { }
91130+};
91131+#endif
91132+
91133 /* The default sysctl tables: */
91134
91135 static struct ctl_table sysctl_base_table[] = {
91136@@ -274,6 +288,22 @@ static int max_extfrag_threshold = 1000;
91137 #endif
91138
91139 static struct ctl_table kern_table[] = {
91140+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
91141+ {
91142+ .procname = "grsecurity",
91143+ .mode = 0500,
91144+ .child = grsecurity_table,
91145+ },
91146+#endif
91147+
91148+#ifdef CONFIG_PAX_SOFTMODE
91149+ {
91150+ .procname = "pax",
91151+ .mode = 0500,
91152+ .child = pax_table,
91153+ },
91154+#endif
91155+
91156 {
91157 .procname = "sched_child_runs_first",
91158 .data = &sysctl_sched_child_runs_first,
91159@@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
91160 .data = &modprobe_path,
91161 .maxlen = KMOD_PATH_LEN,
91162 .mode = 0644,
91163- .proc_handler = proc_dostring,
91164+ .proc_handler = proc_dostring_modpriv,
91165 },
91166 {
91167 .procname = "modules_disabled",
91168@@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
91169 .extra1 = &zero,
91170 .extra2 = &one,
91171 },
91172+#endif
91173 {
91174 .procname = "kptr_restrict",
91175 .data = &kptr_restrict,
91176 .maxlen = sizeof(int),
91177 .mode = 0644,
91178 .proc_handler = proc_dointvec_minmax_sysadmin,
91179+#ifdef CONFIG_GRKERNSEC_HIDESYM
91180+ .extra1 = &two,
91181+#else
91182 .extra1 = &zero,
91183+#endif
91184 .extra2 = &two,
91185 },
91186-#endif
91187 {
91188 .procname = "ngroups_max",
91189 .data = &ngroups_max,
91190@@ -1050,10 +1084,17 @@ static struct ctl_table kern_table[] = {
91191 */
91192 {
91193 .procname = "perf_event_paranoid",
91194- .data = &sysctl_perf_event_paranoid,
91195- .maxlen = sizeof(sysctl_perf_event_paranoid),
91196+ .data = &sysctl_perf_event_legitimately_concerned,
91197+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
91198 .mode = 0644,
91199- .proc_handler = proc_dointvec,
91200+ /* go ahead, be a hero */
91201+ .proc_handler = proc_dointvec_minmax_sysadmin,
91202+ .extra1 = &neg_one,
91203+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
91204+ .extra2 = &three,
91205+#else
91206+ .extra2 = &two,
91207+#endif
91208 },
91209 {
91210 .procname = "perf_event_mlock_kb",
91211@@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
91212 .proc_handler = proc_dointvec_minmax,
91213 .extra1 = &zero,
91214 },
91215+ {
91216+ .procname = "heap_stack_gap",
91217+ .data = &sysctl_heap_stack_gap,
91218+ .maxlen = sizeof(sysctl_heap_stack_gap),
91219+ .mode = 0644,
91220+ .proc_handler = proc_doulongvec_minmax,
91221+ },
91222 #else
91223 {
91224 .procname = "nr_trim_pages",
91225@@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
91226 buffer, lenp, ppos);
91227 }
91228
91229+int proc_dostring_modpriv(struct ctl_table *table, int write,
91230+ void __user *buffer, size_t *lenp, loff_t *ppos)
91231+{
91232+ if (write && !capable(CAP_SYS_MODULE))
91233+ return -EPERM;
91234+
91235+ return _proc_do_string(table->data, table->maxlen, write,
91236+ buffer, lenp, ppos);
91237+}
91238+
91239 static size_t proc_skip_spaces(char **buf)
91240 {
91241 size_t ret;
91242@@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
91243 len = strlen(tmp);
91244 if (len > *size)
91245 len = *size;
91246+ if (len > sizeof(tmp))
91247+ len = sizeof(tmp);
91248 if (copy_to_user(*buf, tmp, len))
91249 return -EFAULT;
91250 *size -= len;
91251@@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
91252 static int proc_taint(struct ctl_table *table, int write,
91253 void __user *buffer, size_t *lenp, loff_t *ppos)
91254 {
91255- struct ctl_table t;
91256+ ctl_table_no_const t;
91257 unsigned long tmptaint = get_taint();
91258 int err;
91259
91260@@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
91261 return err;
91262 }
91263
91264-#ifdef CONFIG_PRINTK
91265 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
91266 void __user *buffer, size_t *lenp, loff_t *ppos)
91267 {
91268@@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
91269
91270 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
91271 }
91272-#endif
91273
91274 struct do_proc_dointvec_minmax_conv_param {
91275 int *min;
91276@@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
91277 return -ENOSYS;
91278 }
91279
91280+int proc_dostring_modpriv(struct ctl_table *table, int write,
91281+ void __user *buffer, size_t *lenp, loff_t *ppos)
91282+{
91283+ return -ENOSYS;
91284+}
91285+
91286 int proc_dointvec(struct ctl_table *table, int write,
91287 void __user *buffer, size_t *lenp, loff_t *ppos)
91288 {
91289@@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
91290 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
91291 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
91292 EXPORT_SYMBOL(proc_dostring);
91293+EXPORT_SYMBOL(proc_dostring_modpriv);
91294 EXPORT_SYMBOL(proc_doulongvec_minmax);
91295 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
91296diff --git a/kernel/taskstats.c b/kernel/taskstats.c
91297index 13d2f7c..c93d0b0 100644
91298--- a/kernel/taskstats.c
91299+++ b/kernel/taskstats.c
91300@@ -28,9 +28,12 @@
91301 #include <linux/fs.h>
91302 #include <linux/file.h>
91303 #include <linux/pid_namespace.h>
91304+#include <linux/grsecurity.h>
91305 #include <net/genetlink.h>
91306 #include <linux/atomic.h>
91307
91308+extern int gr_is_taskstats_denied(int pid);
91309+
91310 /*
91311 * Maximum length of a cpumask that can be specified in
91312 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
91313@@ -576,6 +579,9 @@ err:
91314
91315 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
91316 {
91317+ if (gr_is_taskstats_denied(current->pid))
91318+ return -EACCES;
91319+
91320 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
91321 return cmd_attr_register_cpumask(info);
91322 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
91323diff --git a/kernel/time.c b/kernel/time.c
91324index 7c7964c..2a0d412 100644
91325--- a/kernel/time.c
91326+++ b/kernel/time.c
91327@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
91328 return error;
91329
91330 if (tz) {
91331+ /* we log in do_settimeofday called below, so don't log twice
91332+ */
91333+ if (!tv)
91334+ gr_log_timechange();
91335+
91336 sys_tz = *tz;
91337 update_vsyscall_tz();
91338 if (firsttime) {
91339diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
91340index fe75444..190c528 100644
91341--- a/kernel/time/alarmtimer.c
91342+++ b/kernel/time/alarmtimer.c
91343@@ -811,7 +811,7 @@ static int __init alarmtimer_init(void)
91344 struct platform_device *pdev;
91345 int error = 0;
91346 int i;
91347- struct k_clock alarm_clock = {
91348+ static struct k_clock alarm_clock = {
91349 .clock_getres = alarm_clock_getres,
91350 .clock_get = alarm_clock_get,
91351 .timer_create = alarm_timer_create,
91352diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
91353index f7df8ea..0810193 100644
91354--- a/kernel/time/timekeeping.c
91355+++ b/kernel/time/timekeeping.c
91356@@ -15,6 +15,7 @@
91357 #include <linux/init.h>
91358 #include <linux/mm.h>
91359 #include <linux/sched.h>
91360+#include <linux/grsecurity.h>
91361 #include <linux/syscore_ops.h>
91362 #include <linux/clocksource.h>
91363 #include <linux/jiffies.h>
91364@@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
91365 if (!timespec_valid_strict(tv))
91366 return -EINVAL;
91367
91368+ gr_log_timechange();
91369+
91370 raw_spin_lock_irqsave(&timekeeper_lock, flags);
91371 write_seqcount_begin(&timekeeper_seq);
91372
91373diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
91374index 61ed862..3b52c65 100644
91375--- a/kernel/time/timer_list.c
91376+++ b/kernel/time/timer_list.c
91377@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
91378
91379 static void print_name_offset(struct seq_file *m, void *sym)
91380 {
91381+#ifdef CONFIG_GRKERNSEC_HIDESYM
91382+ SEQ_printf(m, "<%p>", NULL);
91383+#else
91384 char symname[KSYM_NAME_LEN];
91385
91386 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
91387 SEQ_printf(m, "<%pK>", sym);
91388 else
91389 SEQ_printf(m, "%s", symname);
91390+#endif
91391 }
91392
91393 static void
91394@@ -119,7 +123,11 @@ next_one:
91395 static void
91396 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
91397 {
91398+#ifdef CONFIG_GRKERNSEC_HIDESYM
91399+ SEQ_printf(m, " .base: %p\n", NULL);
91400+#else
91401 SEQ_printf(m, " .base: %pK\n", base);
91402+#endif
91403 SEQ_printf(m, " .index: %d\n",
91404 base->index);
91405 SEQ_printf(m, " .resolution: %Lu nsecs\n",
91406@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
91407 {
91408 struct proc_dir_entry *pe;
91409
91410+#ifdef CONFIG_GRKERNSEC_PROC_ADD
91411+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
91412+#else
91413 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
91414+#endif
91415 if (!pe)
91416 return -ENOMEM;
91417 return 0;
91418diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
91419index 1fb08f2..ca4bb1e 100644
91420--- a/kernel/time/timer_stats.c
91421+++ b/kernel/time/timer_stats.c
91422@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
91423 static unsigned long nr_entries;
91424 static struct entry entries[MAX_ENTRIES];
91425
91426-static atomic_t overflow_count;
91427+static atomic_unchecked_t overflow_count;
91428
91429 /*
91430 * The entries are in a hash-table, for fast lookup:
91431@@ -140,7 +140,7 @@ static void reset_entries(void)
91432 nr_entries = 0;
91433 memset(entries, 0, sizeof(entries));
91434 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
91435- atomic_set(&overflow_count, 0);
91436+ atomic_set_unchecked(&overflow_count, 0);
91437 }
91438
91439 static struct entry *alloc_entry(void)
91440@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91441 if (likely(entry))
91442 entry->count++;
91443 else
91444- atomic_inc(&overflow_count);
91445+ atomic_inc_unchecked(&overflow_count);
91446
91447 out_unlock:
91448 raw_spin_unlock_irqrestore(lock, flags);
91449@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91450
91451 static void print_name_offset(struct seq_file *m, unsigned long addr)
91452 {
91453+#ifdef CONFIG_GRKERNSEC_HIDESYM
91454+ seq_printf(m, "<%p>", NULL);
91455+#else
91456 char symname[KSYM_NAME_LEN];
91457
91458 if (lookup_symbol_name(addr, symname) < 0)
91459- seq_printf(m, "<%p>", (void *)addr);
91460+ seq_printf(m, "<%pK>", (void *)addr);
91461 else
91462 seq_printf(m, "%s", symname);
91463+#endif
91464 }
91465
91466 static int tstats_show(struct seq_file *m, void *v)
91467@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
91468
91469 seq_puts(m, "Timer Stats Version: v0.3\n");
91470 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
91471- if (atomic_read(&overflow_count))
91472- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
91473+ if (atomic_read_unchecked(&overflow_count))
91474+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
91475 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
91476
91477 for (i = 0; i < nr_entries; i++) {
91478@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
91479 {
91480 struct proc_dir_entry *pe;
91481
91482+#ifdef CONFIG_GRKERNSEC_PROC_ADD
91483+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
91484+#else
91485 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
91486+#endif
91487 if (!pe)
91488 return -ENOMEM;
91489 return 0;
91490diff --git a/kernel/timer.c b/kernel/timer.c
91491index 3bb01a3..0e7760e 100644
91492--- a/kernel/timer.c
91493+++ b/kernel/timer.c
91494@@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
91495 /*
91496 * This function runs timers and the timer-tq in bottom half context.
91497 */
91498-static void run_timer_softirq(struct softirq_action *h)
91499+static __latent_entropy void run_timer_softirq(void)
91500 {
91501 struct tvec_base *base = __this_cpu_read(tvec_bases);
91502
91503@@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
91504 *
91505 * In all cases the return value is guaranteed to be non-negative.
91506 */
91507-signed long __sched schedule_timeout(signed long timeout)
91508+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
91509 {
91510 struct timer_list timer;
91511 unsigned long expire;
91512diff --git a/kernel/torture.c b/kernel/torture.c
91513index acc9afc..4f9eb49 100644
91514--- a/kernel/torture.c
91515+++ b/kernel/torture.c
91516@@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
91517 mutex_lock(&fullstop_mutex);
91518 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
91519 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
91520- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
91521+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
91522 } else {
91523 pr_warn("Concurrent rmmod and shutdown illegal!\n");
91524 }
91525@@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
91526 do {
91527 if (!torture_must_stop()) {
91528 schedule_timeout_interruptible(stutter);
91529- ACCESS_ONCE(stutter_pause_test) = 1;
91530+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
91531 }
91532 if (!torture_must_stop())
91533 schedule_timeout_interruptible(stutter);
91534- ACCESS_ONCE(stutter_pause_test) = 0;
91535+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
91536 torture_shutdown_absorb("torture_stutter");
91537 } while (!torture_must_stop());
91538 torture_kthread_stopping("torture_stutter");
91539@@ -636,7 +636,7 @@ bool torture_cleanup(void)
91540 schedule_timeout_uninterruptible(10);
91541 return true;
91542 }
91543- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
91544+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
91545 mutex_unlock(&fullstop_mutex);
91546 torture_shutdown_cleanup();
91547 torture_shuffle_cleanup();
91548diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
91549index c1bd4ad..4b861dc 100644
91550--- a/kernel/trace/blktrace.c
91551+++ b/kernel/trace/blktrace.c
91552@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
91553 struct blk_trace *bt = filp->private_data;
91554 char buf[16];
91555
91556- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
91557+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
91558
91559 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
91560 }
91561@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
91562 return 1;
91563
91564 bt = buf->chan->private_data;
91565- atomic_inc(&bt->dropped);
91566+ atomic_inc_unchecked(&bt->dropped);
91567 return 0;
91568 }
91569
91570@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
91571
91572 bt->dir = dir;
91573 bt->dev = dev;
91574- atomic_set(&bt->dropped, 0);
91575+ atomic_set_unchecked(&bt->dropped, 0);
91576 INIT_LIST_HEAD(&bt->running_list);
91577
91578 ret = -EIO;
91579diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
91580index 5aeac53..863ed29 100644
91581--- a/kernel/trace/ftrace.c
91582+++ b/kernel/trace/ftrace.c
91583@@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
91584 if (unlikely(ftrace_disabled))
91585 return 0;
91586
91587+ ret = ftrace_arch_code_modify_prepare();
91588+ FTRACE_WARN_ON(ret);
91589+ if (ret)
91590+ return 0;
91591+
91592 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
91593+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
91594 if (ret) {
91595 ftrace_bug(ret, ip);
91596- return 0;
91597 }
91598- return 1;
91599+ return ret ? 0 : 1;
91600 }
91601
91602 /*
91603@@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
91604 if (!count)
91605 return 0;
91606
91607+ pax_open_kernel();
91608 sort(start, count, sizeof(*start),
91609 ftrace_cmp_ips, ftrace_swap_ips);
91610+ pax_close_kernel();
91611
91612 start_pg = ftrace_allocate_pages(count);
91613 if (!start_pg)
91614@@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
91615 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
91616
91617 static int ftrace_graph_active;
91618-static struct notifier_block ftrace_suspend_notifier;
91619-
91620 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
91621 {
91622 return 0;
91623@@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
91624 ftrace_graph_entry = ftrace_graph_entry_test;
91625 }
91626
91627+static struct notifier_block ftrace_suspend_notifier = {
91628+ .notifier_call = ftrace_suspend_notifier_call
91629+};
91630+
91631 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91632 trace_func_graph_ent_t entryfunc)
91633 {
91634@@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91635 goto out;
91636 }
91637
91638- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
91639 register_pm_notifier(&ftrace_suspend_notifier);
91640
91641 ftrace_graph_active++;
91642diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
91643index ff70271..e1e8cf1 100644
91644--- a/kernel/trace/ring_buffer.c
91645+++ b/kernel/trace/ring_buffer.c
91646@@ -352,9 +352,9 @@ struct buffer_data_page {
91647 */
91648 struct buffer_page {
91649 struct list_head list; /* list of buffer pages */
91650- local_t write; /* index for next write */
91651+ local_unchecked_t write; /* index for next write */
91652 unsigned read; /* index for next read */
91653- local_t entries; /* entries on this page */
91654+ local_unchecked_t entries; /* entries on this page */
91655 unsigned long real_end; /* real end of data */
91656 struct buffer_data_page *page; /* Actual data page */
91657 };
91658@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
91659 unsigned long last_overrun;
91660 local_t entries_bytes;
91661 local_t entries;
91662- local_t overrun;
91663- local_t commit_overrun;
91664+ local_unchecked_t overrun;
91665+ local_unchecked_t commit_overrun;
91666 local_t dropped_events;
91667 local_t committing;
91668 local_t commits;
91669@@ -991,8 +991,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91670 *
91671 * We add a counter to the write field to denote this.
91672 */
91673- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
91674- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
91675+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
91676+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
91677
91678 /*
91679 * Just make sure we have seen our old_write and synchronize
91680@@ -1020,8 +1020,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91681 * cmpxchg to only update if an interrupt did not already
91682 * do it for us. If the cmpxchg fails, we don't care.
91683 */
91684- (void)local_cmpxchg(&next_page->write, old_write, val);
91685- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
91686+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
91687+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
91688
91689 /*
91690 * No need to worry about races with clearing out the commit.
91691@@ -1388,12 +1388,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
91692
91693 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
91694 {
91695- return local_read(&bpage->entries) & RB_WRITE_MASK;
91696+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
91697 }
91698
91699 static inline unsigned long rb_page_write(struct buffer_page *bpage)
91700 {
91701- return local_read(&bpage->write) & RB_WRITE_MASK;
91702+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
91703 }
91704
91705 static int
91706@@ -1488,7 +1488,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
91707 * bytes consumed in ring buffer from here.
91708 * Increment overrun to account for the lost events.
91709 */
91710- local_add(page_entries, &cpu_buffer->overrun);
91711+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
91712 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91713 }
91714
91715@@ -2066,7 +2066,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91716 * it is our responsibility to update
91717 * the counters.
91718 */
91719- local_add(entries, &cpu_buffer->overrun);
91720+ local_add_unchecked(entries, &cpu_buffer->overrun);
91721 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91722
91723 /*
91724@@ -2216,7 +2216,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91725 if (tail == BUF_PAGE_SIZE)
91726 tail_page->real_end = 0;
91727
91728- local_sub(length, &tail_page->write);
91729+ local_sub_unchecked(length, &tail_page->write);
91730 return;
91731 }
91732
91733@@ -2251,7 +2251,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91734 rb_event_set_padding(event);
91735
91736 /* Set the write back to the previous setting */
91737- local_sub(length, &tail_page->write);
91738+ local_sub_unchecked(length, &tail_page->write);
91739 return;
91740 }
91741
91742@@ -2263,7 +2263,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91743
91744 /* Set write to end of buffer */
91745 length = (tail + length) - BUF_PAGE_SIZE;
91746- local_sub(length, &tail_page->write);
91747+ local_sub_unchecked(length, &tail_page->write);
91748 }
91749
91750 /*
91751@@ -2289,7 +2289,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91752 * about it.
91753 */
91754 if (unlikely(next_page == commit_page)) {
91755- local_inc(&cpu_buffer->commit_overrun);
91756+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91757 goto out_reset;
91758 }
91759
91760@@ -2345,7 +2345,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91761 cpu_buffer->tail_page) &&
91762 (cpu_buffer->commit_page ==
91763 cpu_buffer->reader_page))) {
91764- local_inc(&cpu_buffer->commit_overrun);
91765+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91766 goto out_reset;
91767 }
91768 }
91769@@ -2393,7 +2393,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91770 length += RB_LEN_TIME_EXTEND;
91771
91772 tail_page = cpu_buffer->tail_page;
91773- write = local_add_return(length, &tail_page->write);
91774+ write = local_add_return_unchecked(length, &tail_page->write);
91775
91776 /* set write to only the index of the write */
91777 write &= RB_WRITE_MASK;
91778@@ -2417,7 +2417,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91779 kmemcheck_annotate_bitfield(event, bitfield);
91780 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91781
91782- local_inc(&tail_page->entries);
91783+ local_inc_unchecked(&tail_page->entries);
91784
91785 /*
91786 * If this is the first commit on the page, then update
91787@@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91788
91789 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91790 unsigned long write_mask =
91791- local_read(&bpage->write) & ~RB_WRITE_MASK;
91792+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91793 unsigned long event_length = rb_event_length(event);
91794 /*
91795 * This is on the tail page. It is possible that
91796@@ -2460,7 +2460,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91797 */
91798 old_index += write_mask;
91799 new_index += write_mask;
91800- index = local_cmpxchg(&bpage->write, old_index, new_index);
91801+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91802 if (index == old_index) {
91803 /* update counters */
91804 local_sub(event_length, &cpu_buffer->entries_bytes);
91805@@ -2852,7 +2852,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91806
91807 /* Do the likely case first */
91808 if (likely(bpage->page == (void *)addr)) {
91809- local_dec(&bpage->entries);
91810+ local_dec_unchecked(&bpage->entries);
91811 return;
91812 }
91813
91814@@ -2864,7 +2864,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91815 start = bpage;
91816 do {
91817 if (bpage->page == (void *)addr) {
91818- local_dec(&bpage->entries);
91819+ local_dec_unchecked(&bpage->entries);
91820 return;
91821 }
91822 rb_inc_page(cpu_buffer, &bpage);
91823@@ -3148,7 +3148,7 @@ static inline unsigned long
91824 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91825 {
91826 return local_read(&cpu_buffer->entries) -
91827- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91828+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91829 }
91830
91831 /**
91832@@ -3237,7 +3237,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91833 return 0;
91834
91835 cpu_buffer = buffer->buffers[cpu];
91836- ret = local_read(&cpu_buffer->overrun);
91837+ ret = local_read_unchecked(&cpu_buffer->overrun);
91838
91839 return ret;
91840 }
91841@@ -3260,7 +3260,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91842 return 0;
91843
91844 cpu_buffer = buffer->buffers[cpu];
91845- ret = local_read(&cpu_buffer->commit_overrun);
91846+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91847
91848 return ret;
91849 }
91850@@ -3345,7 +3345,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91851 /* if you care about this being correct, lock the buffer */
91852 for_each_buffer_cpu(buffer, cpu) {
91853 cpu_buffer = buffer->buffers[cpu];
91854- overruns += local_read(&cpu_buffer->overrun);
91855+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91856 }
91857
91858 return overruns;
91859@@ -3521,8 +3521,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91860 /*
91861 * Reset the reader page to size zero.
91862 */
91863- local_set(&cpu_buffer->reader_page->write, 0);
91864- local_set(&cpu_buffer->reader_page->entries, 0);
91865+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91866+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91867 local_set(&cpu_buffer->reader_page->page->commit, 0);
91868 cpu_buffer->reader_page->real_end = 0;
91869
91870@@ -3556,7 +3556,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91871 * want to compare with the last_overrun.
91872 */
91873 smp_mb();
91874- overwrite = local_read(&(cpu_buffer->overrun));
91875+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91876
91877 /*
91878 * Here's the tricky part.
91879@@ -4126,8 +4126,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91880
91881 cpu_buffer->head_page
91882 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91883- local_set(&cpu_buffer->head_page->write, 0);
91884- local_set(&cpu_buffer->head_page->entries, 0);
91885+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91886+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91887 local_set(&cpu_buffer->head_page->page->commit, 0);
91888
91889 cpu_buffer->head_page->read = 0;
91890@@ -4137,14 +4137,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91891
91892 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91893 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91894- local_set(&cpu_buffer->reader_page->write, 0);
91895- local_set(&cpu_buffer->reader_page->entries, 0);
91896+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91897+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91898 local_set(&cpu_buffer->reader_page->page->commit, 0);
91899 cpu_buffer->reader_page->read = 0;
91900
91901 local_set(&cpu_buffer->entries_bytes, 0);
91902- local_set(&cpu_buffer->overrun, 0);
91903- local_set(&cpu_buffer->commit_overrun, 0);
91904+ local_set_unchecked(&cpu_buffer->overrun, 0);
91905+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91906 local_set(&cpu_buffer->dropped_events, 0);
91907 local_set(&cpu_buffer->entries, 0);
91908 local_set(&cpu_buffer->committing, 0);
91909@@ -4549,8 +4549,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91910 rb_init_page(bpage);
91911 bpage = reader->page;
91912 reader->page = *data_page;
91913- local_set(&reader->write, 0);
91914- local_set(&reader->entries, 0);
91915+ local_set_unchecked(&reader->write, 0);
91916+ local_set_unchecked(&reader->entries, 0);
91917 reader->read = 0;
91918 *data_page = bpage;
91919
91920diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91921index e1baa92f..7b2e345 100644
91922--- a/kernel/trace/trace.c
91923+++ b/kernel/trace/trace.c
91924@@ -3461,7 +3461,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91925 return 0;
91926 }
91927
91928-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91929+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91930 {
91931 /* do nothing if flag is already set */
91932 if (!!(trace_flags & mask) == !!enabled)
91933diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91934index 99676cd..670b9e8 100644
91935--- a/kernel/trace/trace.h
91936+++ b/kernel/trace/trace.h
91937@@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91938 void trace_printk_init_buffers(void);
91939 void trace_printk_start_comm(void);
91940 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91941-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91942+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91943
91944 /*
91945 * Normal trace_printk() and friends allocates special buffers
91946diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91947index 57b67b1..66082a9 100644
91948--- a/kernel/trace/trace_clock.c
91949+++ b/kernel/trace/trace_clock.c
91950@@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
91951 return now;
91952 }
91953
91954-static atomic64_t trace_counter;
91955+static atomic64_unchecked_t trace_counter;
91956
91957 /*
91958 * trace_clock_counter(): simply an atomic counter.
91959@@ -133,5 +133,5 @@ static atomic64_t trace_counter;
91960 */
91961 u64 notrace trace_clock_counter(void)
91962 {
91963- return atomic64_add_return(1, &trace_counter);
91964+ return atomic64_inc_return_unchecked(&trace_counter);
91965 }
91966diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91967index aec1dac..6ca72ee 100644
91968--- a/kernel/trace/trace_events.c
91969+++ b/kernel/trace/trace_events.c
91970@@ -1719,7 +1719,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91971 return 0;
91972 }
91973
91974-struct ftrace_module_file_ops;
91975 static void __add_event_to_tracers(struct ftrace_event_call *call);
91976
91977 /* Add an additional event_call dynamically */
91978diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91979index 0abd9b8..6a663a2 100644
91980--- a/kernel/trace/trace_mmiotrace.c
91981+++ b/kernel/trace/trace_mmiotrace.c
91982@@ -24,7 +24,7 @@ struct header_iter {
91983 static struct trace_array *mmio_trace_array;
91984 static bool overrun_detected;
91985 static unsigned long prev_overruns;
91986-static atomic_t dropped_count;
91987+static atomic_unchecked_t dropped_count;
91988
91989 static void mmio_reset_data(struct trace_array *tr)
91990 {
91991@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91992
91993 static unsigned long count_overruns(struct trace_iterator *iter)
91994 {
91995- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91996+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91997 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91998
91999 if (over > prev_overruns)
92000@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
92001 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
92002 sizeof(*entry), 0, pc);
92003 if (!event) {
92004- atomic_inc(&dropped_count);
92005+ atomic_inc_unchecked(&dropped_count);
92006 return;
92007 }
92008 entry = ring_buffer_event_data(event);
92009@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
92010 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
92011 sizeof(*entry), 0, pc);
92012 if (!event) {
92013- atomic_inc(&dropped_count);
92014+ atomic_inc_unchecked(&dropped_count);
92015 return;
92016 }
92017 entry = ring_buffer_event_data(event);
92018diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
92019index a436de1..f64dde2 100644
92020--- a/kernel/trace/trace_output.c
92021+++ b/kernel/trace/trace_output.c
92022@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
92023
92024 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
92025 if (!IS_ERR(p)) {
92026- p = mangle_path(s->buffer + s->len, p, "\n");
92027+ p = mangle_path(s->buffer + s->len, p, "\n\\");
92028 if (p) {
92029 s->len = p - s->buffer;
92030 return 1;
92031@@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
92032 goto out;
92033 }
92034
92035+ pax_open_kernel();
92036 if (event->funcs->trace == NULL)
92037- event->funcs->trace = trace_nop_print;
92038+ *(void **)&event->funcs->trace = trace_nop_print;
92039 if (event->funcs->raw == NULL)
92040- event->funcs->raw = trace_nop_print;
92041+ *(void **)&event->funcs->raw = trace_nop_print;
92042 if (event->funcs->hex == NULL)
92043- event->funcs->hex = trace_nop_print;
92044+ *(void **)&event->funcs->hex = trace_nop_print;
92045 if (event->funcs->binary == NULL)
92046- event->funcs->binary = trace_nop_print;
92047+ *(void **)&event->funcs->binary = trace_nop_print;
92048+ pax_close_kernel();
92049
92050 key = event->type & (EVENT_HASHSIZE - 1);
92051
92052diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
92053index 21b320e..40607bc 100644
92054--- a/kernel/trace/trace_stack.c
92055+++ b/kernel/trace/trace_stack.c
92056@@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
92057 return;
92058
92059 /* we do not handle interrupt stacks yet */
92060- if (!object_is_on_stack(stack))
92061+ if (!object_starts_on_stack(stack))
92062 return;
92063
92064 local_irq_save(flags);
92065diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
92066index bf71b4b..04dee68 100644
92067--- a/kernel/user_namespace.c
92068+++ b/kernel/user_namespace.c
92069@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
92070 !kgid_has_mapping(parent_ns, group))
92071 return -EPERM;
92072
92073+#ifdef CONFIG_GRKERNSEC
92074+ /*
92075+ * This doesn't really inspire confidence:
92076+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
92077+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
92078+ * Increases kernel attack surface in areas developers
92079+ * previously cared little about ("low importance due
92080+ * to requiring "root" capability")
92081+ * To be removed when this code receives *proper* review
92082+ */
92083+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
92084+ !capable(CAP_SETGID))
92085+ return -EPERM;
92086+#endif
92087+
92088 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
92089 if (!ns)
92090 return -ENOMEM;
92091@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
92092 if (atomic_read(&current->mm->mm_users) > 1)
92093 return -EINVAL;
92094
92095- if (current->fs->users != 1)
92096+ if (atomic_read(&current->fs->users) != 1)
92097 return -EINVAL;
92098
92099 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
92100diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
92101index 4f69f9a..7c6f8f8 100644
92102--- a/kernel/utsname_sysctl.c
92103+++ b/kernel/utsname_sysctl.c
92104@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
92105 static int proc_do_uts_string(ctl_table *table, int write,
92106 void __user *buffer, size_t *lenp, loff_t *ppos)
92107 {
92108- struct ctl_table uts_table;
92109+ ctl_table_no_const uts_table;
92110 int r;
92111 memcpy(&uts_table, table, sizeof(uts_table));
92112 uts_table.data = get_uts(table, write);
92113diff --git a/kernel/watchdog.c b/kernel/watchdog.c
92114index 30e4822..dd2b854 100644
92115--- a/kernel/watchdog.c
92116+++ b/kernel/watchdog.c
92117@@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
92118 static void watchdog_nmi_disable(unsigned int cpu) { return; }
92119 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
92120
92121-static struct smp_hotplug_thread watchdog_threads = {
92122+static struct smp_hotplug_thread watchdog_threads __read_only = {
92123 .store = &softlockup_watchdog,
92124 .thread_should_run = watchdog_should_run,
92125 .thread_fn = watchdog,
92126diff --git a/kernel/workqueue.c b/kernel/workqueue.c
92127index 7ba5897..c8ed1f2 100644
92128--- a/kernel/workqueue.c
92129+++ b/kernel/workqueue.c
92130@@ -4710,7 +4710,7 @@ static void rebind_workers(struct worker_pool *pool)
92131 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
92132 worker_flags |= WORKER_REBOUND;
92133 worker_flags &= ~WORKER_UNBOUND;
92134- ACCESS_ONCE(worker->flags) = worker_flags;
92135+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
92136 }
92137
92138 spin_unlock_irq(&pool->lock);
92139diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
92140index 819ac51..1c8a65e 100644
92141--- a/lib/Kconfig.debug
92142+++ b/lib/Kconfig.debug
92143@@ -853,7 +853,7 @@ config DEBUG_MUTEXES
92144
92145 config DEBUG_WW_MUTEX_SLOWPATH
92146 bool "Wait/wound mutex debugging: Slowpath testing"
92147- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
92148+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
92149 select DEBUG_LOCK_ALLOC
92150 select DEBUG_SPINLOCK
92151 select DEBUG_MUTEXES
92152@@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
92153
92154 config DEBUG_LOCK_ALLOC
92155 bool "Lock debugging: detect incorrect freeing of live locks"
92156- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
92157+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
92158 select DEBUG_SPINLOCK
92159 select DEBUG_MUTEXES
92160 select LOCKDEP
92161@@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
92162
92163 config PROVE_LOCKING
92164 bool "Lock debugging: prove locking correctness"
92165- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
92166+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
92167 select LOCKDEP
92168 select DEBUG_SPINLOCK
92169 select DEBUG_MUTEXES
92170@@ -931,7 +931,7 @@ config LOCKDEP
92171
92172 config LOCK_STAT
92173 bool "Lock usage statistics"
92174- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
92175+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
92176 select LOCKDEP
92177 select DEBUG_SPINLOCK
92178 select DEBUG_MUTEXES
92179@@ -1403,6 +1403,7 @@ config LATENCYTOP
92180 depends on DEBUG_KERNEL
92181 depends on STACKTRACE_SUPPORT
92182 depends on PROC_FS
92183+ depends on !GRKERNSEC_HIDESYM
92184 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
92185 select KALLSYMS
92186 select KALLSYMS_ALL
92187@@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
92188 config DEBUG_STRICT_USER_COPY_CHECKS
92189 bool "Strict user copy size checks"
92190 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
92191- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
92192+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
92193 help
92194 Enabling this option turns a certain set of sanity checks for user
92195 copy operations into compile time failures.
92196@@ -1538,7 +1539,7 @@ endmenu # runtime tests
92197
92198 config PROVIDE_OHCI1394_DMA_INIT
92199 bool "Remote debugging over FireWire early on boot"
92200- depends on PCI && X86
92201+ depends on PCI && X86 && !GRKERNSEC
92202 help
92203 If you want to debug problems which hang or crash the kernel early
92204 on boot and the crashing machine has a FireWire port, you can use
92205diff --git a/lib/Makefile b/lib/Makefile
92206index 0cd7b68..e149e37 100644
92207--- a/lib/Makefile
92208+++ b/lib/Makefile
92209@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
92210 obj-$(CONFIG_BTREE) += btree.o
92211 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
92212 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
92213-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
92214+obj-y += list_debug.o
92215 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
92216
92217 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
92218diff --git a/lib/average.c b/lib/average.c
92219index 114d1be..ab0350c 100644
92220--- a/lib/average.c
92221+++ b/lib/average.c
92222@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
92223 {
92224 unsigned long internal = ACCESS_ONCE(avg->internal);
92225
92226- ACCESS_ONCE(avg->internal) = internal ?
92227+ ACCESS_ONCE_RW(avg->internal) = internal ?
92228 (((internal << avg->weight) - internal) +
92229 (val << avg->factor)) >> avg->weight :
92230 (val << avg->factor);
92231diff --git a/lib/bitmap.c b/lib/bitmap.c
92232index 06f7e4f..f3cf2b0 100644
92233--- a/lib/bitmap.c
92234+++ b/lib/bitmap.c
92235@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
92236 {
92237 int c, old_c, totaldigits, ndigits, nchunks, nbits;
92238 u32 chunk;
92239- const char __user __force *ubuf = (const char __user __force *)buf;
92240+ const char __user *ubuf = (const char __force_user *)buf;
92241
92242 bitmap_zero(maskp, nmaskbits);
92243
92244@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
92245 {
92246 if (!access_ok(VERIFY_READ, ubuf, ulen))
92247 return -EFAULT;
92248- return __bitmap_parse((const char __force *)ubuf,
92249+ return __bitmap_parse((const char __force_kernel *)ubuf,
92250 ulen, 1, maskp, nmaskbits);
92251
92252 }
92253@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
92254 {
92255 unsigned a, b;
92256 int c, old_c, totaldigits;
92257- const char __user __force *ubuf = (const char __user __force *)buf;
92258+ const char __user *ubuf = (const char __force_user *)buf;
92259 int exp_digit, in_range;
92260
92261 totaldigits = c = 0;
92262@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
92263 {
92264 if (!access_ok(VERIFY_READ, ubuf, ulen))
92265 return -EFAULT;
92266- return __bitmap_parselist((const char __force *)ubuf,
92267+ return __bitmap_parselist((const char __force_kernel *)ubuf,
92268 ulen, 1, maskp, nmaskbits);
92269 }
92270 EXPORT_SYMBOL(bitmap_parselist_user);
92271diff --git a/lib/bug.c b/lib/bug.c
92272index 1686034..a9c00c8 100644
92273--- a/lib/bug.c
92274+++ b/lib/bug.c
92275@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
92276 return BUG_TRAP_TYPE_NONE;
92277
92278 bug = find_bug(bugaddr);
92279+ if (!bug)
92280+ return BUG_TRAP_TYPE_NONE;
92281
92282 file = NULL;
92283 line = 0;
92284diff --git a/lib/debugobjects.c b/lib/debugobjects.c
92285index e0731c3..ad66444 100644
92286--- a/lib/debugobjects.c
92287+++ b/lib/debugobjects.c
92288@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
92289 if (limit > 4)
92290 return;
92291
92292- is_on_stack = object_is_on_stack(addr);
92293+ is_on_stack = object_starts_on_stack(addr);
92294 if (is_on_stack == onstack)
92295 return;
92296
92297diff --git a/lib/div64.c b/lib/div64.c
92298index 4382ad7..08aa558 100644
92299--- a/lib/div64.c
92300+++ b/lib/div64.c
92301@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
92302 EXPORT_SYMBOL(__div64_32);
92303
92304 #ifndef div_s64_rem
92305-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
92306+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
92307 {
92308 u64 quotient;
92309
92310@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
92311 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
92312 */
92313 #ifndef div64_u64
92314-u64 div64_u64(u64 dividend, u64 divisor)
92315+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
92316 {
92317 u32 high = divisor >> 32;
92318 u64 quot;
92319diff --git a/lib/dma-debug.c b/lib/dma-debug.c
92320index 98f2d7e..899da5c 100644
92321--- a/lib/dma-debug.c
92322+++ b/lib/dma-debug.c
92323@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
92324
92325 void dma_debug_add_bus(struct bus_type *bus)
92326 {
92327- struct notifier_block *nb;
92328+ notifier_block_no_const *nb;
92329
92330 if (global_disable)
92331 return;
92332@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
92333
92334 static void check_for_stack(struct device *dev, void *addr)
92335 {
92336- if (object_is_on_stack(addr))
92337+ if (object_starts_on_stack(addr))
92338 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
92339 "stack [addr=%p]\n", addr);
92340 }
92341diff --git a/lib/hash.c b/lib/hash.c
92342index fea973f..386626f 100644
92343--- a/lib/hash.c
92344+++ b/lib/hash.c
92345@@ -14,7 +14,7 @@
92346 #include <linux/hash.h>
92347 #include <linux/cache.h>
92348
92349-static struct fast_hash_ops arch_hash_ops __read_mostly = {
92350+static struct fast_hash_ops arch_hash_ops __read_only = {
92351 .hash = jhash,
92352 .hash2 = jhash2,
92353 };
92354diff --git a/lib/inflate.c b/lib/inflate.c
92355index 013a761..c28f3fc 100644
92356--- a/lib/inflate.c
92357+++ b/lib/inflate.c
92358@@ -269,7 +269,7 @@ static void free(void *where)
92359 malloc_ptr = free_mem_ptr;
92360 }
92361 #else
92362-#define malloc(a) kmalloc(a, GFP_KERNEL)
92363+#define malloc(a) kmalloc((a), GFP_KERNEL)
92364 #define free(a) kfree(a)
92365 #endif
92366
92367diff --git a/lib/ioremap.c b/lib/ioremap.c
92368index 0c9216c..863bd89 100644
92369--- a/lib/ioremap.c
92370+++ b/lib/ioremap.c
92371@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
92372 unsigned long next;
92373
92374 phys_addr -= addr;
92375- pmd = pmd_alloc(&init_mm, pud, addr);
92376+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
92377 if (!pmd)
92378 return -ENOMEM;
92379 do {
92380@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
92381 unsigned long next;
92382
92383 phys_addr -= addr;
92384- pud = pud_alloc(&init_mm, pgd, addr);
92385+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
92386 if (!pud)
92387 return -ENOMEM;
92388 do {
92389diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
92390index bd2bea9..6b3c95e 100644
92391--- a/lib/is_single_threaded.c
92392+++ b/lib/is_single_threaded.c
92393@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
92394 struct task_struct *p, *t;
92395 bool ret;
92396
92397+ if (!mm)
92398+ return true;
92399+
92400 if (atomic_read(&task->signal->live) != 1)
92401 return false;
92402
92403diff --git a/lib/kobject.c b/lib/kobject.c
92404index 58751bb..93a1853 100644
92405--- a/lib/kobject.c
92406+++ b/lib/kobject.c
92407@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
92408
92409
92410 static DEFINE_SPINLOCK(kobj_ns_type_lock);
92411-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
92412+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
92413
92414-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92415+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92416 {
92417 enum kobj_ns_type type = ops->type;
92418 int error;
92419diff --git a/lib/list_debug.c b/lib/list_debug.c
92420index c24c2f7..f0296f4 100644
92421--- a/lib/list_debug.c
92422+++ b/lib/list_debug.c
92423@@ -11,7 +11,9 @@
92424 #include <linux/bug.h>
92425 #include <linux/kernel.h>
92426 #include <linux/rculist.h>
92427+#include <linux/mm.h>
92428
92429+#ifdef CONFIG_DEBUG_LIST
92430 /*
92431 * Insert a new entry between two known consecutive entries.
92432 *
92433@@ -19,21 +21,40 @@
92434 * the prev/next entries already!
92435 */
92436
92437+static bool __list_add_debug(struct list_head *new,
92438+ struct list_head *prev,
92439+ struct list_head *next)
92440+{
92441+ if (unlikely(next->prev != prev)) {
92442+ printk(KERN_ERR "list_add corruption. next->prev should be "
92443+ "prev (%p), but was %p. (next=%p).\n",
92444+ prev, next->prev, next);
92445+ BUG();
92446+ return false;
92447+ }
92448+ if (unlikely(prev->next != next)) {
92449+ printk(KERN_ERR "list_add corruption. prev->next should be "
92450+ "next (%p), but was %p. (prev=%p).\n",
92451+ next, prev->next, prev);
92452+ BUG();
92453+ return false;
92454+ }
92455+ if (unlikely(new == prev || new == next)) {
92456+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
92457+ new, prev, next);
92458+ BUG();
92459+ return false;
92460+ }
92461+ return true;
92462+}
92463+
92464 void __list_add(struct list_head *new,
92465- struct list_head *prev,
92466- struct list_head *next)
92467+ struct list_head *prev,
92468+ struct list_head *next)
92469 {
92470- WARN(next->prev != prev,
92471- "list_add corruption. next->prev should be "
92472- "prev (%p), but was %p. (next=%p).\n",
92473- prev, next->prev, next);
92474- WARN(prev->next != next,
92475- "list_add corruption. prev->next should be "
92476- "next (%p), but was %p. (prev=%p).\n",
92477- next, prev->next, prev);
92478- WARN(new == prev || new == next,
92479- "list_add double add: new=%p, prev=%p, next=%p.\n",
92480- new, prev, next);
92481+ if (!__list_add_debug(new, prev, next))
92482+ return;
92483+
92484 next->prev = new;
92485 new->next = next;
92486 new->prev = prev;
92487@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
92488 }
92489 EXPORT_SYMBOL(__list_add);
92490
92491-void __list_del_entry(struct list_head *entry)
92492+static bool __list_del_entry_debug(struct list_head *entry)
92493 {
92494 struct list_head *prev, *next;
92495
92496 prev = entry->prev;
92497 next = entry->next;
92498
92499- if (WARN(next == LIST_POISON1,
92500- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92501- entry, LIST_POISON1) ||
92502- WARN(prev == LIST_POISON2,
92503- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92504- entry, LIST_POISON2) ||
92505- WARN(prev->next != entry,
92506- "list_del corruption. prev->next should be %p, "
92507- "but was %p\n", entry, prev->next) ||
92508- WARN(next->prev != entry,
92509- "list_del corruption. next->prev should be %p, "
92510- "but was %p\n", entry, next->prev))
92511+ if (unlikely(next == LIST_POISON1)) {
92512+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92513+ entry, LIST_POISON1);
92514+ BUG();
92515+ return false;
92516+ }
92517+ if (unlikely(prev == LIST_POISON2)) {
92518+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92519+ entry, LIST_POISON2);
92520+ BUG();
92521+ return false;
92522+ }
92523+ if (unlikely(entry->prev->next != entry)) {
92524+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
92525+ "but was %p\n", entry, prev->next);
92526+ BUG();
92527+ return false;
92528+ }
92529+ if (unlikely(entry->next->prev != entry)) {
92530+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
92531+ "but was %p\n", entry, next->prev);
92532+ BUG();
92533+ return false;
92534+ }
92535+ return true;
92536+}
92537+
92538+void __list_del_entry(struct list_head *entry)
92539+{
92540+ if (!__list_del_entry_debug(entry))
92541 return;
92542
92543- __list_del(prev, next);
92544+ __list_del(entry->prev, entry->next);
92545 }
92546 EXPORT_SYMBOL(__list_del_entry);
92547
92548@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
92549 void __list_add_rcu(struct list_head *new,
92550 struct list_head *prev, struct list_head *next)
92551 {
92552- WARN(next->prev != prev,
92553- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
92554- prev, next->prev, next);
92555- WARN(prev->next != next,
92556- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
92557- next, prev->next, prev);
92558+ if (!__list_add_debug(new, prev, next))
92559+ return;
92560+
92561 new->next = next;
92562 new->prev = prev;
92563 rcu_assign_pointer(list_next_rcu(prev), new);
92564 next->prev = new;
92565 }
92566 EXPORT_SYMBOL(__list_add_rcu);
92567+#endif
92568+
92569+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
92570+{
92571+#ifdef CONFIG_DEBUG_LIST
92572+ if (!__list_add_debug(new, prev, next))
92573+ return;
92574+#endif
92575+
92576+ pax_open_kernel();
92577+ next->prev = new;
92578+ new->next = next;
92579+ new->prev = prev;
92580+ prev->next = new;
92581+ pax_close_kernel();
92582+}
92583+EXPORT_SYMBOL(__pax_list_add);
92584+
92585+void pax_list_del(struct list_head *entry)
92586+{
92587+#ifdef CONFIG_DEBUG_LIST
92588+ if (!__list_del_entry_debug(entry))
92589+ return;
92590+#endif
92591+
92592+ pax_open_kernel();
92593+ __list_del(entry->prev, entry->next);
92594+ entry->next = LIST_POISON1;
92595+ entry->prev = LIST_POISON2;
92596+ pax_close_kernel();
92597+}
92598+EXPORT_SYMBOL(pax_list_del);
92599+
92600+void pax_list_del_init(struct list_head *entry)
92601+{
92602+ pax_open_kernel();
92603+ __list_del(entry->prev, entry->next);
92604+ INIT_LIST_HEAD(entry);
92605+ pax_close_kernel();
92606+}
92607+EXPORT_SYMBOL(pax_list_del_init);
92608+
92609+void __pax_list_add_rcu(struct list_head *new,
92610+ struct list_head *prev, struct list_head *next)
92611+{
92612+#ifdef CONFIG_DEBUG_LIST
92613+ if (!__list_add_debug(new, prev, next))
92614+ return;
92615+#endif
92616+
92617+ pax_open_kernel();
92618+ new->next = next;
92619+ new->prev = prev;
92620+ rcu_assign_pointer(list_next_rcu(prev), new);
92621+ next->prev = new;
92622+ pax_close_kernel();
92623+}
92624+EXPORT_SYMBOL(__pax_list_add_rcu);
92625+
92626+void pax_list_del_rcu(struct list_head *entry)
92627+{
92628+#ifdef CONFIG_DEBUG_LIST
92629+ if (!__list_del_entry_debug(entry))
92630+ return;
92631+#endif
92632+
92633+ pax_open_kernel();
92634+ __list_del(entry->prev, entry->next);
92635+ entry->next = LIST_POISON1;
92636+ entry->prev = LIST_POISON2;
92637+ pax_close_kernel();
92638+}
92639+EXPORT_SYMBOL(pax_list_del_rcu);
92640diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
92641index 963b703..438bc51 100644
92642--- a/lib/percpu-refcount.c
92643+++ b/lib/percpu-refcount.c
92644@@ -29,7 +29,7 @@
92645 * can't hit 0 before we've added up all the percpu refs.
92646 */
92647
92648-#define PCPU_COUNT_BIAS (1U << 31)
92649+#define PCPU_COUNT_BIAS (1U << 30)
92650
92651 /**
92652 * percpu_ref_init - initialize a percpu refcount
92653diff --git a/lib/radix-tree.c b/lib/radix-tree.c
92654index 9599aa7..9cf6c72 100644
92655--- a/lib/radix-tree.c
92656+++ b/lib/radix-tree.c
92657@@ -66,7 +66,7 @@ struct radix_tree_preload {
92658 int nr;
92659 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
92660 };
92661-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
92662+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
92663
92664 static inline void *ptr_to_indirect(void *ptr)
92665 {
92666diff --git a/lib/random32.c b/lib/random32.c
92667index fa5da61..35fe9af 100644
92668--- a/lib/random32.c
92669+++ b/lib/random32.c
92670@@ -42,7 +42,7 @@
92671 static void __init prandom_state_selftest(void);
92672 #endif
92673
92674-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
92675+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
92676
92677 /**
92678 * prandom_u32_state - seeded pseudo-random number generator.
92679diff --git a/lib/rbtree.c b/lib/rbtree.c
92680index 65f4eff..2cfa167 100644
92681--- a/lib/rbtree.c
92682+++ b/lib/rbtree.c
92683@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
92684 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
92685
92686 static const struct rb_augment_callbacks dummy_callbacks = {
92687- dummy_propagate, dummy_copy, dummy_rotate
92688+ .propagate = dummy_propagate,
92689+ .copy = dummy_copy,
92690+ .rotate = dummy_rotate
92691 };
92692
92693 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92694diff --git a/lib/show_mem.c b/lib/show_mem.c
92695index 0922579..9d7adb9 100644
92696--- a/lib/show_mem.c
92697+++ b/lib/show_mem.c
92698@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92699 quicklist_total_size());
92700 #endif
92701 #ifdef CONFIG_MEMORY_FAILURE
92702- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92703+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92704 #endif
92705 }
92706diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92707index bb2b201..46abaf9 100644
92708--- a/lib/strncpy_from_user.c
92709+++ b/lib/strncpy_from_user.c
92710@@ -21,7 +21,7 @@
92711 */
92712 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92713 {
92714- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92715+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92716 long res = 0;
92717
92718 /*
92719diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92720index a28df52..3d55877 100644
92721--- a/lib/strnlen_user.c
92722+++ b/lib/strnlen_user.c
92723@@ -26,7 +26,7 @@
92724 */
92725 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92726 {
92727- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92728+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92729 long align, res = 0;
92730 unsigned long c;
92731
92732diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92733index b604b83..c0547f6 100644
92734--- a/lib/swiotlb.c
92735+++ b/lib/swiotlb.c
92736@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92737
92738 void
92739 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92740- dma_addr_t dev_addr)
92741+ dma_addr_t dev_addr, struct dma_attrs *attrs)
92742 {
92743 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92744
92745diff --git a/lib/usercopy.c b/lib/usercopy.c
92746index 4f5b1dd..7cab418 100644
92747--- a/lib/usercopy.c
92748+++ b/lib/usercopy.c
92749@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92750 WARN(1, "Buffer overflow detected!\n");
92751 }
92752 EXPORT_SYMBOL(copy_from_user_overflow);
92753+
92754+void copy_to_user_overflow(void)
92755+{
92756+ WARN(1, "Buffer overflow detected!\n");
92757+}
92758+EXPORT_SYMBOL(copy_to_user_overflow);
92759diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92760index 0648291..42bf42b 100644
92761--- a/lib/vsprintf.c
92762+++ b/lib/vsprintf.c
92763@@ -16,6 +16,9 @@
92764 * - scnprintf and vscnprintf
92765 */
92766
92767+#ifdef CONFIG_GRKERNSEC_HIDESYM
92768+#define __INCLUDED_BY_HIDESYM 1
92769+#endif
92770 #include <stdarg.h>
92771 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92772 #include <linux/types.h>
92773@@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
92774 return number(buf, end, num, spec);
92775 }
92776
92777+#ifdef CONFIG_GRKERNSEC_HIDESYM
92778+int kptr_restrict __read_mostly = 2;
92779+#else
92780 int kptr_restrict __read_mostly;
92781+#endif
92782
92783 /*
92784 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92785@@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92786 * - 'f' For simple symbolic function names without offset
92787 * - 'S' For symbolic direct pointers with offset
92788 * - 's' For symbolic direct pointers without offset
92789+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92790 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92791 * - 'B' For backtraced symbolic direct pointers with offset
92792 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92793@@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92794
92795 if (!ptr && *fmt != 'K') {
92796 /*
92797- * Print (null) with the same width as a pointer so it makes
92798+ * Print (nil) with the same width as a pointer so it makes
92799 * tabular output look nice.
92800 */
92801 if (spec.field_width == -1)
92802 spec.field_width = default_width;
92803- return string(buf, end, "(null)", spec);
92804+ return string(buf, end, "(nil)", spec);
92805 }
92806
92807 switch (*fmt) {
92808@@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92809 /* Fallthrough */
92810 case 'S':
92811 case 's':
92812+#ifdef CONFIG_GRKERNSEC_HIDESYM
92813+ break;
92814+#else
92815+ return symbol_string(buf, end, ptr, spec, fmt);
92816+#endif
92817+ case 'A':
92818 case 'B':
92819 return symbol_string(buf, end, ptr, spec, fmt);
92820 case 'R':
92821@@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92822 va_end(va);
92823 return buf;
92824 }
92825+ case 'P':
92826+ break;
92827 case 'K':
92828 /*
92829 * %pK cannot be used in IRQ context because its test
92830@@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92831 ((const struct file *)ptr)->f_path.dentry,
92832 spec, fmt);
92833 }
92834+
92835+#ifdef CONFIG_GRKERNSEC_HIDESYM
92836+ /* 'P' = approved pointers to copy to userland,
92837+ as in the /proc/kallsyms case, as we make it display nothing
92838+ for non-root users, and the real contents for root users
92839+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92840+ above
92841+ */
92842+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92843+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92844+ dump_stack();
92845+ ptr = NULL;
92846+ }
92847+#endif
92848+
92849 spec.flags |= SMALL;
92850 if (spec.field_width == -1) {
92851 spec.field_width = default_width;
92852@@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92853 typeof(type) value; \
92854 if (sizeof(type) == 8) { \
92855 args = PTR_ALIGN(args, sizeof(u32)); \
92856- *(u32 *)&value = *(u32 *)args; \
92857- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92858+ *(u32 *)&value = *(const u32 *)args; \
92859+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92860 } else { \
92861 args = PTR_ALIGN(args, sizeof(type)); \
92862- value = *(typeof(type) *)args; \
92863+ value = *(const typeof(type) *)args; \
92864 } \
92865 args += sizeof(type); \
92866 value; \
92867@@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92868 case FORMAT_TYPE_STR: {
92869 const char *str_arg = args;
92870 args += strlen(str_arg) + 1;
92871- str = string(str, end, (char *)str_arg, spec);
92872+ str = string(str, end, str_arg, spec);
92873 break;
92874 }
92875
92876diff --git a/localversion-grsec b/localversion-grsec
92877new file mode 100644
92878index 0000000..7cd6065
92879--- /dev/null
92880+++ b/localversion-grsec
92881@@ -0,0 +1 @@
92882+-grsec
92883diff --git a/mm/Kconfig b/mm/Kconfig
92884index 2f42b9c..6095e14 100644
92885--- a/mm/Kconfig
92886+++ b/mm/Kconfig
92887@@ -330,10 +330,11 @@ config KSM
92888 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92889
92890 config DEFAULT_MMAP_MIN_ADDR
92891- int "Low address space to protect from user allocation"
92892+ int "Low address space to protect from user allocation"
92893 depends on MMU
92894- default 4096
92895- help
92896+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92897+ default 65536
92898+ help
92899 This is the portion of low virtual memory which should be protected
92900 from userspace allocation. Keeping a user from writing to low pages
92901 can help reduce the impact of kernel NULL pointer bugs.
92902@@ -364,7 +365,7 @@ config MEMORY_FAILURE
92903
92904 config HWPOISON_INJECT
92905 tristate "HWPoison pages injector"
92906- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92907+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92908 select PROC_PAGE_MONITOR
92909
92910 config NOMMU_INITIAL_TRIM_EXCESS
92911diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92912index 09d9591..165bb75 100644
92913--- a/mm/backing-dev.c
92914+++ b/mm/backing-dev.c
92915@@ -12,7 +12,7 @@
92916 #include <linux/device.h>
92917 #include <trace/events/writeback.h>
92918
92919-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92920+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92921
92922 struct backing_dev_info default_backing_dev_info = {
92923 .name = "default",
92924@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92925 return err;
92926
92927 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92928- atomic_long_inc_return(&bdi_seq));
92929+ atomic_long_inc_return_unchecked(&bdi_seq));
92930 if (err) {
92931 bdi_destroy(bdi);
92932 return err;
92933diff --git a/mm/filemap.c b/mm/filemap.c
92934index 088358c..bb415bf 100644
92935--- a/mm/filemap.c
92936+++ b/mm/filemap.c
92937@@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92938 struct address_space *mapping = file->f_mapping;
92939
92940 if (!mapping->a_ops->readpage)
92941- return -ENOEXEC;
92942+ return -ENODEV;
92943 file_accessed(file);
92944 vma->vm_ops = &generic_file_vm_ops;
92945 return 0;
92946@@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92947 *pos = i_size_read(inode);
92948
92949 if (limit != RLIM_INFINITY) {
92950+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92951 if (*pos >= limit) {
92952 send_sig(SIGXFSZ, current, 0);
92953 return -EFBIG;
92954diff --git a/mm/fremap.c b/mm/fremap.c
92955index 34feba6..315fe78 100644
92956--- a/mm/fremap.c
92957+++ b/mm/fremap.c
92958@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92959 retry:
92960 vma = find_vma(mm, start);
92961
92962+#ifdef CONFIG_PAX_SEGMEXEC
92963+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92964+ goto out;
92965+#endif
92966+
92967 /*
92968 * Make sure the vma is shared, that it supports prefaulting,
92969 * and that the remapped range is valid and fully within
92970diff --git a/mm/highmem.c b/mm/highmem.c
92971index b32b70c..e512eb0 100644
92972--- a/mm/highmem.c
92973+++ b/mm/highmem.c
92974@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92975 * So no dangers, even with speculative execution.
92976 */
92977 page = pte_page(pkmap_page_table[i]);
92978+ pax_open_kernel();
92979 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92980-
92981+ pax_close_kernel();
92982 set_page_address(page, NULL);
92983 need_flush = 1;
92984 }
92985@@ -198,9 +199,11 @@ start:
92986 }
92987 }
92988 vaddr = PKMAP_ADDR(last_pkmap_nr);
92989+
92990+ pax_open_kernel();
92991 set_pte_at(&init_mm, vaddr,
92992 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92993-
92994+ pax_close_kernel();
92995 pkmap_count[last_pkmap_nr] = 1;
92996 set_page_address(page, (void *)vaddr);
92997
92998diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92999index 002f08e..68f11e8 100644
93000--- a/mm/hugetlb.c
93001+++ b/mm/hugetlb.c
93002@@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
93003 struct hstate *h = &default_hstate;
93004 unsigned long tmp;
93005 int ret;
93006+ ctl_table_no_const hugetlb_table;
93007
93008 if (!hugepages_supported())
93009 return -ENOTSUPP;
93010@@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
93011 if (write && h->order >= MAX_ORDER)
93012 return -EINVAL;
93013
93014- table->data = &tmp;
93015- table->maxlen = sizeof(unsigned long);
93016- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
93017+ hugetlb_table = *table;
93018+ hugetlb_table.data = &tmp;
93019+ hugetlb_table.maxlen = sizeof(unsigned long);
93020+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
93021 if (ret)
93022 goto out;
93023
93024@@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
93025 struct hstate *h = &default_hstate;
93026 unsigned long tmp;
93027 int ret;
93028+ ctl_table_no_const hugetlb_table;
93029
93030 if (!hugepages_supported())
93031 return -ENOTSUPP;
93032@@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
93033 if (write && h->order >= MAX_ORDER)
93034 return -EINVAL;
93035
93036- table->data = &tmp;
93037- table->maxlen = sizeof(unsigned long);
93038- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
93039+ hugetlb_table = *table;
93040+ hugetlb_table.data = &tmp;
93041+ hugetlb_table.maxlen = sizeof(unsigned long);
93042+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
93043 if (ret)
93044 goto out;
93045
93046@@ -2655,6 +2659,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
93047 return 1;
93048 }
93049
93050+#ifdef CONFIG_PAX_SEGMEXEC
93051+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
93052+{
93053+ struct mm_struct *mm = vma->vm_mm;
93054+ struct vm_area_struct *vma_m;
93055+ unsigned long address_m;
93056+ pte_t *ptep_m;
93057+
93058+ vma_m = pax_find_mirror_vma(vma);
93059+ if (!vma_m)
93060+ return;
93061+
93062+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93063+ address_m = address + SEGMEXEC_TASK_SIZE;
93064+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
93065+ get_page(page_m);
93066+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
93067+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
93068+}
93069+#endif
93070+
93071 /*
93072 * Hugetlb_cow() should be called with page lock of the original hugepage held.
93073 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
93074@@ -2772,6 +2797,11 @@ retry_avoidcopy:
93075 make_huge_pte(vma, new_page, 1));
93076 page_remove_rmap(old_page);
93077 hugepage_add_new_anon_rmap(new_page, vma, address);
93078+
93079+#ifdef CONFIG_PAX_SEGMEXEC
93080+ pax_mirror_huge_pte(vma, address, new_page);
93081+#endif
93082+
93083 /* Make the old page be freed below */
93084 new_page = old_page;
93085 }
93086@@ -2931,6 +2961,10 @@ retry:
93087 && (vma->vm_flags & VM_SHARED)));
93088 set_huge_pte_at(mm, address, ptep, new_pte);
93089
93090+#ifdef CONFIG_PAX_SEGMEXEC
93091+ pax_mirror_huge_pte(vma, address, page);
93092+#endif
93093+
93094 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
93095 /* Optimization, do the COW without a second fault */
93096 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
93097@@ -2997,6 +3031,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93098 struct hstate *h = hstate_vma(vma);
93099 struct address_space *mapping;
93100
93101+#ifdef CONFIG_PAX_SEGMEXEC
93102+ struct vm_area_struct *vma_m;
93103+#endif
93104+
93105 address &= huge_page_mask(h);
93106
93107 ptep = huge_pte_offset(mm, address);
93108@@ -3010,6 +3048,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93109 VM_FAULT_SET_HINDEX(hstate_index(h));
93110 }
93111
93112+#ifdef CONFIG_PAX_SEGMEXEC
93113+ vma_m = pax_find_mirror_vma(vma);
93114+ if (vma_m) {
93115+ unsigned long address_m;
93116+
93117+ if (vma->vm_start > vma_m->vm_start) {
93118+ address_m = address;
93119+ address -= SEGMEXEC_TASK_SIZE;
93120+ vma = vma_m;
93121+ h = hstate_vma(vma);
93122+ } else
93123+ address_m = address + SEGMEXEC_TASK_SIZE;
93124+
93125+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
93126+ return VM_FAULT_OOM;
93127+ address_m &= HPAGE_MASK;
93128+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
93129+ }
93130+#endif
93131+
93132 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
93133 if (!ptep)
93134 return VM_FAULT_OOM;
93135diff --git a/mm/internal.h b/mm/internal.h
93136index 07b6736..ae8da20 100644
93137--- a/mm/internal.h
93138+++ b/mm/internal.h
93139@@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
93140 * in mm/page_alloc.c
93141 */
93142 extern void __free_pages_bootmem(struct page *page, unsigned int order);
93143+extern void free_compound_page(struct page *page);
93144 extern void prep_compound_page(struct page *page, unsigned long order);
93145 #ifdef CONFIG_MEMORY_FAILURE
93146 extern bool is_free_buddy_page(struct page *page);
93147@@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
93148
93149 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
93150 unsigned long, unsigned long,
93151- unsigned long, unsigned long);
93152+ unsigned long, unsigned long) __intentional_overflow(-1);
93153
93154 extern void set_pageblock_order(void);
93155 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
93156diff --git a/mm/iov_iter.c b/mm/iov_iter.c
93157index 10e46cd..e3052f6 100644
93158--- a/mm/iov_iter.c
93159+++ b/mm/iov_iter.c
93160@@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
93161
93162 while (bytes) {
93163 char __user *buf = iov->iov_base + base;
93164- int copy = min(bytes, iov->iov_len - base);
93165+ size_t copy = min(bytes, iov->iov_len - base);
93166
93167 base = 0;
93168 left = __copy_from_user_inatomic(vaddr, buf, copy);
93169@@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
93170
93171 kaddr = kmap_atomic(page);
93172 if (likely(i->nr_segs == 1)) {
93173- int left;
93174+ size_t left;
93175 char __user *buf = i->iov->iov_base + i->iov_offset;
93176 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
93177 copied = bytes - left;
93178@@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
93179
93180 kaddr = kmap(page);
93181 if (likely(i->nr_segs == 1)) {
93182- int left;
93183+ size_t left;
93184 char __user *buf = i->iov->iov_base + i->iov_offset;
93185 left = __copy_from_user(kaddr + offset, buf, bytes);
93186 copied = bytes - left;
93187@@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
93188 * zero-length segments (without overruning the iovec).
93189 */
93190 while (bytes || unlikely(i->count && !iov->iov_len)) {
93191- int copy;
93192+ size_t copy;
93193
93194 copy = min(bytes, iov->iov_len - base);
93195 BUG_ON(!i->count || i->count < copy);
93196diff --git a/mm/kmemleak.c b/mm/kmemleak.c
93197index 8d2fcdf..6dd9f1a 100644
93198--- a/mm/kmemleak.c
93199+++ b/mm/kmemleak.c
93200@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
93201
93202 for (i = 0; i < object->trace_len; i++) {
93203 void *ptr = (void *)object->trace[i];
93204- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
93205+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
93206 }
93207 }
93208
93209@@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
93210 return -ENOMEM;
93211 }
93212
93213- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
93214+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
93215 &kmemleak_fops);
93216 if (!dentry)
93217 pr_warning("Failed to create the debugfs kmemleak file\n");
93218diff --git a/mm/maccess.c b/mm/maccess.c
93219index d53adf9..03a24bf 100644
93220--- a/mm/maccess.c
93221+++ b/mm/maccess.c
93222@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
93223 set_fs(KERNEL_DS);
93224 pagefault_disable();
93225 ret = __copy_from_user_inatomic(dst,
93226- (__force const void __user *)src, size);
93227+ (const void __force_user *)src, size);
93228 pagefault_enable();
93229 set_fs(old_fs);
93230
93231@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
93232
93233 set_fs(KERNEL_DS);
93234 pagefault_disable();
93235- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
93236+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
93237 pagefault_enable();
93238 set_fs(old_fs);
93239
93240diff --git a/mm/madvise.c b/mm/madvise.c
93241index a402f8f..f5e5daa 100644
93242--- a/mm/madvise.c
93243+++ b/mm/madvise.c
93244@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
93245 pgoff_t pgoff;
93246 unsigned long new_flags = vma->vm_flags;
93247
93248+#ifdef CONFIG_PAX_SEGMEXEC
93249+ struct vm_area_struct *vma_m;
93250+#endif
93251+
93252 switch (behavior) {
93253 case MADV_NORMAL:
93254 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
93255@@ -126,6 +130,13 @@ success:
93256 /*
93257 * vm_flags is protected by the mmap_sem held in write mode.
93258 */
93259+
93260+#ifdef CONFIG_PAX_SEGMEXEC
93261+ vma_m = pax_find_mirror_vma(vma);
93262+ if (vma_m)
93263+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
93264+#endif
93265+
93266 vma->vm_flags = new_flags;
93267
93268 out:
93269@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
93270 struct vm_area_struct **prev,
93271 unsigned long start, unsigned long end)
93272 {
93273+
93274+#ifdef CONFIG_PAX_SEGMEXEC
93275+ struct vm_area_struct *vma_m;
93276+#endif
93277+
93278 *prev = vma;
93279 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
93280 return -EINVAL;
93281@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
93282 zap_page_range(vma, start, end - start, &details);
93283 } else
93284 zap_page_range(vma, start, end - start, NULL);
93285+
93286+#ifdef CONFIG_PAX_SEGMEXEC
93287+ vma_m = pax_find_mirror_vma(vma);
93288+ if (vma_m) {
93289+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
93290+ struct zap_details details = {
93291+ .nonlinear_vma = vma_m,
93292+ .last_index = ULONG_MAX,
93293+ };
93294+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
93295+ } else
93296+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
93297+ }
93298+#endif
93299+
93300 return 0;
93301 }
93302
93303@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
93304 if (end < start)
93305 return error;
93306
93307+#ifdef CONFIG_PAX_SEGMEXEC
93308+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
93309+ if (end > SEGMEXEC_TASK_SIZE)
93310+ return error;
93311+ } else
93312+#endif
93313+
93314+ if (end > TASK_SIZE)
93315+ return error;
93316+
93317 error = 0;
93318 if (end == start)
93319 return error;
93320diff --git a/mm/memory-failure.c b/mm/memory-failure.c
93321index eb8fb72..ae36cf3 100644
93322--- a/mm/memory-failure.c
93323+++ b/mm/memory-failure.c
93324@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
93325
93326 int sysctl_memory_failure_recovery __read_mostly = 1;
93327
93328-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
93329+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
93330
93331 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
93332
93333@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
93334 pfn, t->comm, t->pid);
93335 si.si_signo = SIGBUS;
93336 si.si_errno = 0;
93337- si.si_addr = (void *)addr;
93338+ si.si_addr = (void __user *)addr;
93339 #ifdef __ARCH_SI_TRAPNO
93340 si.si_trapno = trapno;
93341 #endif
93342@@ -791,7 +791,7 @@ static struct page_state {
93343 unsigned long res;
93344 char *msg;
93345 int (*action)(struct page *p, unsigned long pfn);
93346-} error_states[] = {
93347+} __do_const error_states[] = {
93348 { reserved, reserved, "reserved kernel", me_kernel },
93349 /*
93350 * free pages are specially detected outside this table:
93351@@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93352 nr_pages = 1 << compound_order(hpage);
93353 else /* normal page or thp */
93354 nr_pages = 1;
93355- atomic_long_add(nr_pages, &num_poisoned_pages);
93356+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
93357
93358 /*
93359 * We need/can do nothing about count=0 pages.
93360@@ -1120,7 +1120,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93361 if (PageHWPoison(hpage)) {
93362 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
93363 || (p != hpage && TestSetPageHWPoison(hpage))) {
93364- atomic_long_sub(nr_pages, &num_poisoned_pages);
93365+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93366 unlock_page(hpage);
93367 return 0;
93368 }
93369@@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93370 */
93371 if (!PageHWPoison(p)) {
93372 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
93373- atomic_long_sub(nr_pages, &num_poisoned_pages);
93374+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93375 put_page(hpage);
93376 res = 0;
93377 goto out;
93378 }
93379 if (hwpoison_filter(p)) {
93380 if (TestClearPageHWPoison(p))
93381- atomic_long_sub(nr_pages, &num_poisoned_pages);
93382+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93383 unlock_page(hpage);
93384 put_page(hpage);
93385 return 0;
93386@@ -1415,7 +1415,7 @@ int unpoison_memory(unsigned long pfn)
93387 return 0;
93388 }
93389 if (TestClearPageHWPoison(p))
93390- atomic_long_dec(&num_poisoned_pages);
93391+ atomic_long_dec_unchecked(&num_poisoned_pages);
93392 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
93393 return 0;
93394 }
93395@@ -1429,7 +1429,7 @@ int unpoison_memory(unsigned long pfn)
93396 */
93397 if (TestClearPageHWPoison(page)) {
93398 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
93399- atomic_long_sub(nr_pages, &num_poisoned_pages);
93400+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93401 freeit = 1;
93402 if (PageHuge(page))
93403 clear_page_hwpoison_huge_page(page);
93404@@ -1554,11 +1554,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
93405 if (PageHuge(page)) {
93406 set_page_hwpoison_huge_page(hpage);
93407 dequeue_hwpoisoned_huge_page(hpage);
93408- atomic_long_add(1 << compound_order(hpage),
93409+ atomic_long_add_unchecked(1 << compound_order(hpage),
93410 &num_poisoned_pages);
93411 } else {
93412 SetPageHWPoison(page);
93413- atomic_long_inc(&num_poisoned_pages);
93414+ atomic_long_inc_unchecked(&num_poisoned_pages);
93415 }
93416 }
93417 return ret;
93418@@ -1597,7 +1597,7 @@ static int __soft_offline_page(struct page *page, int flags)
93419 put_page(page);
93420 pr_info("soft_offline: %#lx: invalidated\n", pfn);
93421 SetPageHWPoison(page);
93422- atomic_long_inc(&num_poisoned_pages);
93423+ atomic_long_inc_unchecked(&num_poisoned_pages);
93424 return 0;
93425 }
93426
93427@@ -1648,7 +1648,7 @@ static int __soft_offline_page(struct page *page, int flags)
93428 if (!is_free_buddy_page(page))
93429 pr_info("soft offline: %#lx: page leaked\n",
93430 pfn);
93431- atomic_long_inc(&num_poisoned_pages);
93432+ atomic_long_inc_unchecked(&num_poisoned_pages);
93433 }
93434 } else {
93435 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
93436@@ -1722,11 +1722,11 @@ int soft_offline_page(struct page *page, int flags)
93437 if (PageHuge(page)) {
93438 set_page_hwpoison_huge_page(hpage);
93439 dequeue_hwpoisoned_huge_page(hpage);
93440- atomic_long_add(1 << compound_order(hpage),
93441+ atomic_long_add_unchecked(1 << compound_order(hpage),
93442 &num_poisoned_pages);
93443 } else {
93444 SetPageHWPoison(page);
93445- atomic_long_inc(&num_poisoned_pages);
93446+ atomic_long_inc_unchecked(&num_poisoned_pages);
93447 }
93448 }
93449 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
93450diff --git a/mm/memory.c b/mm/memory.c
93451index 4f9e530..779c7ce 100644
93452--- a/mm/memory.c
93453+++ b/mm/memory.c
93454@@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93455 free_pte_range(tlb, pmd, addr);
93456 } while (pmd++, addr = next, addr != end);
93457
93458+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
93459 start &= PUD_MASK;
93460 if (start < floor)
93461 return;
93462@@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93463 pmd = pmd_offset(pud, start);
93464 pud_clear(pud);
93465 pmd_free_tlb(tlb, pmd, start);
93466+#endif
93467+
93468 }
93469
93470 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93471@@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93472 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
93473 } while (pud++, addr = next, addr != end);
93474
93475+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
93476 start &= PGDIR_MASK;
93477 if (start < floor)
93478 return;
93479@@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93480 pud = pud_offset(pgd, start);
93481 pgd_clear(pgd);
93482 pud_free_tlb(tlb, pud, start);
93483+#endif
93484+
93485 }
93486
93487 /*
93488@@ -1652,12 +1658,6 @@ no_page_table:
93489 return page;
93490 }
93491
93492-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
93493-{
93494- return stack_guard_page_start(vma, addr) ||
93495- stack_guard_page_end(vma, addr+PAGE_SIZE);
93496-}
93497-
93498 /**
93499 * __get_user_pages() - pin user pages in memory
93500 * @tsk: task_struct of target task
93501@@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93502
93503 i = 0;
93504
93505- do {
93506+ while (nr_pages) {
93507 struct vm_area_struct *vma;
93508
93509- vma = find_extend_vma(mm, start);
93510+ vma = find_vma(mm, start);
93511 if (!vma && in_gate_area(mm, start)) {
93512 unsigned long pg = start & PAGE_MASK;
93513 pgd_t *pgd;
93514@@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93515 goto next_page;
93516 }
93517
93518- if (!vma)
93519+ if (!vma || start < vma->vm_start)
93520 goto efault;
93521 vm_flags = vma->vm_flags;
93522 if (vm_flags & (VM_IO | VM_PFNMAP))
93523@@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93524 int ret;
93525 unsigned int fault_flags = 0;
93526
93527- /* For mlock, just skip the stack guard page. */
93528- if (foll_flags & FOLL_MLOCK) {
93529- if (stack_guard_page(vma, start))
93530- goto next_page;
93531- }
93532 if (foll_flags & FOLL_WRITE)
93533 fault_flags |= FAULT_FLAG_WRITE;
93534 if (nonblocking)
93535@@ -1932,7 +1927,7 @@ next_page:
93536 start += page_increm * PAGE_SIZE;
93537 nr_pages -= page_increm;
93538 } while (nr_pages && start < vma->vm_end);
93539- } while (nr_pages);
93540+ }
93541 return i;
93542 efault:
93543 return i ? : -EFAULT;
93544@@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
93545 page_add_file_rmap(page);
93546 set_pte_at(mm, addr, pte, mk_pte(page, prot));
93547
93548+#ifdef CONFIG_PAX_SEGMEXEC
93549+ pax_mirror_file_pte(vma, addr, page, ptl);
93550+#endif
93551+
93552 retval = 0;
93553 pte_unmap_unlock(pte, ptl);
93554 return retval;
93555@@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
93556 if (!page_count(page))
93557 return -EINVAL;
93558 if (!(vma->vm_flags & VM_MIXEDMAP)) {
93559+
93560+#ifdef CONFIG_PAX_SEGMEXEC
93561+ struct vm_area_struct *vma_m;
93562+#endif
93563+
93564 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
93565 BUG_ON(vma->vm_flags & VM_PFNMAP);
93566 vma->vm_flags |= VM_MIXEDMAP;
93567+
93568+#ifdef CONFIG_PAX_SEGMEXEC
93569+ vma_m = pax_find_mirror_vma(vma);
93570+ if (vma_m)
93571+ vma_m->vm_flags |= VM_MIXEDMAP;
93572+#endif
93573+
93574 }
93575 return insert_page(vma, addr, page, vma->vm_page_prot);
93576 }
93577@@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
93578 unsigned long pfn)
93579 {
93580 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
93581+ BUG_ON(vma->vm_mirror);
93582
93583 if (addr < vma->vm_start || addr >= vma->vm_end)
93584 return -EFAULT;
93585@@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
93586
93587 BUG_ON(pud_huge(*pud));
93588
93589- pmd = pmd_alloc(mm, pud, addr);
93590+ pmd = (mm == &init_mm) ?
93591+ pmd_alloc_kernel(mm, pud, addr) :
93592+ pmd_alloc(mm, pud, addr);
93593 if (!pmd)
93594 return -ENOMEM;
93595 do {
93596@@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
93597 unsigned long next;
93598 int err;
93599
93600- pud = pud_alloc(mm, pgd, addr);
93601+ pud = (mm == &init_mm) ?
93602+ pud_alloc_kernel(mm, pgd, addr) :
93603+ pud_alloc(mm, pgd, addr);
93604 if (!pud)
93605 return -ENOMEM;
93606 do {
93607@@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
93608 return ret;
93609 }
93610
93611+#ifdef CONFIG_PAX_SEGMEXEC
93612+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
93613+{
93614+ struct mm_struct *mm = vma->vm_mm;
93615+ spinlock_t *ptl;
93616+ pte_t *pte, entry;
93617+
93618+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93619+ entry = *pte;
93620+ if (!pte_present(entry)) {
93621+ if (!pte_none(entry)) {
93622+ BUG_ON(pte_file(entry));
93623+ free_swap_and_cache(pte_to_swp_entry(entry));
93624+ pte_clear_not_present_full(mm, address, pte, 0);
93625+ }
93626+ } else {
93627+ struct page *page;
93628+
93629+ flush_cache_page(vma, address, pte_pfn(entry));
93630+ entry = ptep_clear_flush(vma, address, pte);
93631+ BUG_ON(pte_dirty(entry));
93632+ page = vm_normal_page(vma, address, entry);
93633+ if (page) {
93634+ update_hiwater_rss(mm);
93635+ if (PageAnon(page))
93636+ dec_mm_counter_fast(mm, MM_ANONPAGES);
93637+ else
93638+ dec_mm_counter_fast(mm, MM_FILEPAGES);
93639+ page_remove_rmap(page);
93640+ page_cache_release(page);
93641+ }
93642+ }
93643+ pte_unmap_unlock(pte, ptl);
93644+}
93645+
93646+/* PaX: if vma is mirrored, synchronize the mirror's PTE
93647+ *
93648+ * the ptl of the lower mapped page is held on entry and is not released on exit
93649+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
93650+ */
93651+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93652+{
93653+ struct mm_struct *mm = vma->vm_mm;
93654+ unsigned long address_m;
93655+ spinlock_t *ptl_m;
93656+ struct vm_area_struct *vma_m;
93657+ pmd_t *pmd_m;
93658+ pte_t *pte_m, entry_m;
93659+
93660+ BUG_ON(!page_m || !PageAnon(page_m));
93661+
93662+ vma_m = pax_find_mirror_vma(vma);
93663+ if (!vma_m)
93664+ return;
93665+
93666+ BUG_ON(!PageLocked(page_m));
93667+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93668+ address_m = address + SEGMEXEC_TASK_SIZE;
93669+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93670+ pte_m = pte_offset_map(pmd_m, address_m);
93671+ ptl_m = pte_lockptr(mm, pmd_m);
93672+ if (ptl != ptl_m) {
93673+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93674+ if (!pte_none(*pte_m))
93675+ goto out;
93676+ }
93677+
93678+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93679+ page_cache_get(page_m);
93680+ page_add_anon_rmap(page_m, vma_m, address_m);
93681+ inc_mm_counter_fast(mm, MM_ANONPAGES);
93682+ set_pte_at(mm, address_m, pte_m, entry_m);
93683+ update_mmu_cache(vma_m, address_m, pte_m);
93684+out:
93685+ if (ptl != ptl_m)
93686+ spin_unlock(ptl_m);
93687+ pte_unmap(pte_m);
93688+ unlock_page(page_m);
93689+}
93690+
93691+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93692+{
93693+ struct mm_struct *mm = vma->vm_mm;
93694+ unsigned long address_m;
93695+ spinlock_t *ptl_m;
93696+ struct vm_area_struct *vma_m;
93697+ pmd_t *pmd_m;
93698+ pte_t *pte_m, entry_m;
93699+
93700+ BUG_ON(!page_m || PageAnon(page_m));
93701+
93702+ vma_m = pax_find_mirror_vma(vma);
93703+ if (!vma_m)
93704+ return;
93705+
93706+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93707+ address_m = address + SEGMEXEC_TASK_SIZE;
93708+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93709+ pte_m = pte_offset_map(pmd_m, address_m);
93710+ ptl_m = pte_lockptr(mm, pmd_m);
93711+ if (ptl != ptl_m) {
93712+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93713+ if (!pte_none(*pte_m))
93714+ goto out;
93715+ }
93716+
93717+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93718+ page_cache_get(page_m);
93719+ page_add_file_rmap(page_m);
93720+ inc_mm_counter_fast(mm, MM_FILEPAGES);
93721+ set_pte_at(mm, address_m, pte_m, entry_m);
93722+ update_mmu_cache(vma_m, address_m, pte_m);
93723+out:
93724+ if (ptl != ptl_m)
93725+ spin_unlock(ptl_m);
93726+ pte_unmap(pte_m);
93727+}
93728+
93729+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93730+{
93731+ struct mm_struct *mm = vma->vm_mm;
93732+ unsigned long address_m;
93733+ spinlock_t *ptl_m;
93734+ struct vm_area_struct *vma_m;
93735+ pmd_t *pmd_m;
93736+ pte_t *pte_m, entry_m;
93737+
93738+ vma_m = pax_find_mirror_vma(vma);
93739+ if (!vma_m)
93740+ return;
93741+
93742+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93743+ address_m = address + SEGMEXEC_TASK_SIZE;
93744+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93745+ pte_m = pte_offset_map(pmd_m, address_m);
93746+ ptl_m = pte_lockptr(mm, pmd_m);
93747+ if (ptl != ptl_m) {
93748+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93749+ if (!pte_none(*pte_m))
93750+ goto out;
93751+ }
93752+
93753+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93754+ set_pte_at(mm, address_m, pte_m, entry_m);
93755+out:
93756+ if (ptl != ptl_m)
93757+ spin_unlock(ptl_m);
93758+ pte_unmap(pte_m);
93759+}
93760+
93761+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93762+{
93763+ struct page *page_m;
93764+ pte_t entry;
93765+
93766+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93767+ goto out;
93768+
93769+ entry = *pte;
93770+ page_m = vm_normal_page(vma, address, entry);
93771+ if (!page_m)
93772+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93773+ else if (PageAnon(page_m)) {
93774+ if (pax_find_mirror_vma(vma)) {
93775+ pte_unmap_unlock(pte, ptl);
93776+ lock_page(page_m);
93777+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93778+ if (pte_same(entry, *pte))
93779+ pax_mirror_anon_pte(vma, address, page_m, ptl);
93780+ else
93781+ unlock_page(page_m);
93782+ }
93783+ } else
93784+ pax_mirror_file_pte(vma, address, page_m, ptl);
93785+
93786+out:
93787+ pte_unmap_unlock(pte, ptl);
93788+}
93789+#endif
93790+
93791 /*
93792 * This routine handles present pages, when users try to write
93793 * to a shared page. It is done by copying the page to a new address
93794@@ -2860,6 +3056,12 @@ gotten:
93795 */
93796 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93797 if (likely(pte_same(*page_table, orig_pte))) {
93798+
93799+#ifdef CONFIG_PAX_SEGMEXEC
93800+ if (pax_find_mirror_vma(vma))
93801+ BUG_ON(!trylock_page(new_page));
93802+#endif
93803+
93804 if (old_page) {
93805 if (!PageAnon(old_page)) {
93806 dec_mm_counter_fast(mm, MM_FILEPAGES);
93807@@ -2911,6 +3113,10 @@ gotten:
93808 page_remove_rmap(old_page);
93809 }
93810
93811+#ifdef CONFIG_PAX_SEGMEXEC
93812+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93813+#endif
93814+
93815 /* Free the old page.. */
93816 new_page = old_page;
93817 ret |= VM_FAULT_WRITE;
93818@@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93819 swap_free(entry);
93820 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93821 try_to_free_swap(page);
93822+
93823+#ifdef CONFIG_PAX_SEGMEXEC
93824+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93825+#endif
93826+
93827 unlock_page(page);
93828 if (page != swapcache) {
93829 /*
93830@@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93831
93832 /* No need to invalidate - it was non-present before */
93833 update_mmu_cache(vma, address, page_table);
93834+
93835+#ifdef CONFIG_PAX_SEGMEXEC
93836+ pax_mirror_anon_pte(vma, address, page, ptl);
93837+#endif
93838+
93839 unlock:
93840 pte_unmap_unlock(page_table, ptl);
93841 out:
93842@@ -3226,40 +3442,6 @@ out_release:
93843 }
93844
93845 /*
93846- * This is like a special single-page "expand_{down|up}wards()",
93847- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93848- * doesn't hit another vma.
93849- */
93850-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93851-{
93852- address &= PAGE_MASK;
93853- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93854- struct vm_area_struct *prev = vma->vm_prev;
93855-
93856- /*
93857- * Is there a mapping abutting this one below?
93858- *
93859- * That's only ok if it's the same stack mapping
93860- * that has gotten split..
93861- */
93862- if (prev && prev->vm_end == address)
93863- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93864-
93865- expand_downwards(vma, address - PAGE_SIZE);
93866- }
93867- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93868- struct vm_area_struct *next = vma->vm_next;
93869-
93870- /* As VM_GROWSDOWN but s/below/above/ */
93871- if (next && next->vm_start == address + PAGE_SIZE)
93872- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93873-
93874- expand_upwards(vma, address + PAGE_SIZE);
93875- }
93876- return 0;
93877-}
93878-
93879-/*
93880 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93881 * but allow concurrent faults), and pte mapped but not yet locked.
93882 * We return with mmap_sem still held, but pte unmapped and unlocked.
93883@@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93884 unsigned long address, pte_t *page_table, pmd_t *pmd,
93885 unsigned int flags)
93886 {
93887- struct page *page;
93888+ struct page *page = NULL;
93889 spinlock_t *ptl;
93890 pte_t entry;
93891
93892- pte_unmap(page_table);
93893-
93894- /* Check if we need to add a guard page to the stack */
93895- if (check_stack_guard_page(vma, address) < 0)
93896- return VM_FAULT_SIGBUS;
93897-
93898- /* Use the zero-page for reads */
93899 if (!(flags & FAULT_FLAG_WRITE)) {
93900 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93901 vma->vm_page_prot));
93902- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93903+ ptl = pte_lockptr(mm, pmd);
93904+ spin_lock(ptl);
93905 if (!pte_none(*page_table))
93906 goto unlock;
93907 goto setpte;
93908 }
93909
93910 /* Allocate our own private page. */
93911+ pte_unmap(page_table);
93912+
93913 if (unlikely(anon_vma_prepare(vma)))
93914 goto oom;
93915 page = alloc_zeroed_user_highpage_movable(vma, address);
93916@@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93917 if (!pte_none(*page_table))
93918 goto release;
93919
93920+#ifdef CONFIG_PAX_SEGMEXEC
93921+ if (pax_find_mirror_vma(vma))
93922+ BUG_ON(!trylock_page(page));
93923+#endif
93924+
93925 inc_mm_counter_fast(mm, MM_ANONPAGES);
93926 page_add_new_anon_rmap(page, vma, address);
93927 setpte:
93928@@ -3319,6 +3502,12 @@ setpte:
93929
93930 /* No need to invalidate - it was non-present before */
93931 update_mmu_cache(vma, address, page_table);
93932+
93933+#ifdef CONFIG_PAX_SEGMEXEC
93934+ if (page)
93935+ pax_mirror_anon_pte(vma, address, page, ptl);
93936+#endif
93937+
93938 unlock:
93939 pte_unmap_unlock(page_table, ptl);
93940 return 0;
93941@@ -3515,7 +3704,8 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93942 * if page by the offset is not ready to be mapped (cold cache or
93943 * something).
93944 */
93945- if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR)) {
93946+ if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR) &&
93947+ fault_around_pages() > 1) {
93948 pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93949 do_fault_around(vma, address, pte, pgoff, flags);
93950 if (!pte_same(*pte, orig_pte))
93951@@ -3535,6 +3725,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93952 return ret;
93953 }
93954 do_set_pte(vma, address, fault_page, pte, false, false);
93955+
93956+#ifdef CONFIG_PAX_SEGMEXEC
93957+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93958+#endif
93959+
93960 unlock_page(fault_page);
93961 unlock_out:
93962 pte_unmap_unlock(pte, ptl);
93963@@ -3576,7 +3771,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93964 page_cache_release(fault_page);
93965 goto uncharge_out;
93966 }
93967+
93968+#ifdef CONFIG_PAX_SEGMEXEC
93969+ if (pax_find_mirror_vma(vma))
93970+ BUG_ON(!trylock_page(new_page));
93971+#endif
93972+
93973 do_set_pte(vma, address, new_page, pte, true, true);
93974+
93975+#ifdef CONFIG_PAX_SEGMEXEC
93976+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93977+#endif
93978+
93979 pte_unmap_unlock(pte, ptl);
93980 unlock_page(fault_page);
93981 page_cache_release(fault_page);
93982@@ -3624,6 +3830,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93983 return ret;
93984 }
93985 do_set_pte(vma, address, fault_page, pte, true, false);
93986+
93987+#ifdef CONFIG_PAX_SEGMEXEC
93988+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93989+#endif
93990+
93991 pte_unmap_unlock(pte, ptl);
93992
93993 if (set_page_dirty(fault_page))
93994@@ -3854,6 +4065,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93995 if (flags & FAULT_FLAG_WRITE)
93996 flush_tlb_fix_spurious_fault(vma, address);
93997 }
93998+
93999+#ifdef CONFIG_PAX_SEGMEXEC
94000+ pax_mirror_pte(vma, address, pte, pmd, ptl);
94001+ return 0;
94002+#endif
94003+
94004 unlock:
94005 pte_unmap_unlock(pte, ptl);
94006 return 0;
94007@@ -3870,9 +4087,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
94008 pmd_t *pmd;
94009 pte_t *pte;
94010
94011+#ifdef CONFIG_PAX_SEGMEXEC
94012+ struct vm_area_struct *vma_m;
94013+#endif
94014+
94015 if (unlikely(is_vm_hugetlb_page(vma)))
94016 return hugetlb_fault(mm, vma, address, flags);
94017
94018+#ifdef CONFIG_PAX_SEGMEXEC
94019+ vma_m = pax_find_mirror_vma(vma);
94020+ if (vma_m) {
94021+ unsigned long address_m;
94022+ pgd_t *pgd_m;
94023+ pud_t *pud_m;
94024+ pmd_t *pmd_m;
94025+
94026+ if (vma->vm_start > vma_m->vm_start) {
94027+ address_m = address;
94028+ address -= SEGMEXEC_TASK_SIZE;
94029+ vma = vma_m;
94030+ } else
94031+ address_m = address + SEGMEXEC_TASK_SIZE;
94032+
94033+ pgd_m = pgd_offset(mm, address_m);
94034+ pud_m = pud_alloc(mm, pgd_m, address_m);
94035+ if (!pud_m)
94036+ return VM_FAULT_OOM;
94037+ pmd_m = pmd_alloc(mm, pud_m, address_m);
94038+ if (!pmd_m)
94039+ return VM_FAULT_OOM;
94040+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
94041+ return VM_FAULT_OOM;
94042+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
94043+ }
94044+#endif
94045+
94046 pgd = pgd_offset(mm, address);
94047 pud = pud_alloc(mm, pgd, address);
94048 if (!pud)
94049@@ -4000,6 +4249,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
94050 spin_unlock(&mm->page_table_lock);
94051 return 0;
94052 }
94053+
94054+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
94055+{
94056+ pud_t *new = pud_alloc_one(mm, address);
94057+ if (!new)
94058+ return -ENOMEM;
94059+
94060+ smp_wmb(); /* See comment in __pte_alloc */
94061+
94062+ spin_lock(&mm->page_table_lock);
94063+ if (pgd_present(*pgd)) /* Another has populated it */
94064+ pud_free(mm, new);
94065+ else
94066+ pgd_populate_kernel(mm, pgd, new);
94067+ spin_unlock(&mm->page_table_lock);
94068+ return 0;
94069+}
94070 #endif /* __PAGETABLE_PUD_FOLDED */
94071
94072 #ifndef __PAGETABLE_PMD_FOLDED
94073@@ -4030,6 +4296,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
94074 spin_unlock(&mm->page_table_lock);
94075 return 0;
94076 }
94077+
94078+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
94079+{
94080+ pmd_t *new = pmd_alloc_one(mm, address);
94081+ if (!new)
94082+ return -ENOMEM;
94083+
94084+ smp_wmb(); /* See comment in __pte_alloc */
94085+
94086+ spin_lock(&mm->page_table_lock);
94087+#ifndef __ARCH_HAS_4LEVEL_HACK
94088+ if (pud_present(*pud)) /* Another has populated it */
94089+ pmd_free(mm, new);
94090+ else
94091+ pud_populate_kernel(mm, pud, new);
94092+#else
94093+ if (pgd_present(*pud)) /* Another has populated it */
94094+ pmd_free(mm, new);
94095+ else
94096+ pgd_populate_kernel(mm, pud, new);
94097+#endif /* __ARCH_HAS_4LEVEL_HACK */
94098+ spin_unlock(&mm->page_table_lock);
94099+ return 0;
94100+}
94101 #endif /* __PAGETABLE_PMD_FOLDED */
94102
94103 #if !defined(__HAVE_ARCH_GATE_AREA)
94104@@ -4043,7 +4333,7 @@ static int __init gate_vma_init(void)
94105 gate_vma.vm_start = FIXADDR_USER_START;
94106 gate_vma.vm_end = FIXADDR_USER_END;
94107 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
94108- gate_vma.vm_page_prot = __P101;
94109+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
94110
94111 return 0;
94112 }
94113@@ -4177,8 +4467,8 @@ out:
94114 return ret;
94115 }
94116
94117-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
94118- void *buf, int len, int write)
94119+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
94120+ void *buf, size_t len, int write)
94121 {
94122 resource_size_t phys_addr;
94123 unsigned long prot = 0;
94124@@ -4204,8 +4494,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
94125 * Access another process' address space as given in mm. If non-NULL, use the
94126 * given task for page fault accounting.
94127 */
94128-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94129- unsigned long addr, void *buf, int len, int write)
94130+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94131+ unsigned long addr, void *buf, size_t len, int write)
94132 {
94133 struct vm_area_struct *vma;
94134 void *old_buf = buf;
94135@@ -4213,7 +4503,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94136 down_read(&mm->mmap_sem);
94137 /* ignore errors, just check how much was successfully transferred */
94138 while (len) {
94139- int bytes, ret, offset;
94140+ ssize_t bytes, ret, offset;
94141 void *maddr;
94142 struct page *page = NULL;
94143
94144@@ -4272,8 +4562,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94145 *
94146 * The caller must hold a reference on @mm.
94147 */
94148-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94149- void *buf, int len, int write)
94150+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94151+ void *buf, size_t len, int write)
94152 {
94153 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94154 }
94155@@ -4283,11 +4573,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94156 * Source/target buffer must be kernel space,
94157 * Do not walk the page table directly, use get_user_pages
94158 */
94159-int access_process_vm(struct task_struct *tsk, unsigned long addr,
94160- void *buf, int len, int write)
94161+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
94162+ void *buf, size_t len, int write)
94163 {
94164 struct mm_struct *mm;
94165- int ret;
94166+ ssize_t ret;
94167
94168 mm = get_task_mm(tsk);
94169 if (!mm)
94170diff --git a/mm/mempolicy.c b/mm/mempolicy.c
94171index 6b65d10..e6f415a 100644
94172--- a/mm/mempolicy.c
94173+++ b/mm/mempolicy.c
94174@@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
94175 unsigned long vmstart;
94176 unsigned long vmend;
94177
94178+#ifdef CONFIG_PAX_SEGMEXEC
94179+ struct vm_area_struct *vma_m;
94180+#endif
94181+
94182 vma = find_vma(mm, start);
94183 if (!vma || vma->vm_start > start)
94184 return -EFAULT;
94185@@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
94186 err = vma_replace_policy(vma, new_pol);
94187 if (err)
94188 goto out;
94189+
94190+#ifdef CONFIG_PAX_SEGMEXEC
94191+ vma_m = pax_find_mirror_vma(vma);
94192+ if (vma_m) {
94193+ err = vma_replace_policy(vma_m, new_pol);
94194+ if (err)
94195+ goto out;
94196+ }
94197+#endif
94198+
94199 }
94200
94201 out:
94202@@ -1222,6 +1236,17 @@ static long do_mbind(unsigned long start, unsigned long len,
94203
94204 if (end < start)
94205 return -EINVAL;
94206+
94207+#ifdef CONFIG_PAX_SEGMEXEC
94208+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94209+ if (end > SEGMEXEC_TASK_SIZE)
94210+ return -EINVAL;
94211+ } else
94212+#endif
94213+
94214+ if (end > TASK_SIZE)
94215+ return -EINVAL;
94216+
94217 if (end == start)
94218 return 0;
94219
94220@@ -1447,8 +1472,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
94221 */
94222 tcred = __task_cred(task);
94223 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
94224- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
94225- !capable(CAP_SYS_NICE)) {
94226+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
94227 rcu_read_unlock();
94228 err = -EPERM;
94229 goto out_put;
94230@@ -1479,6 +1503,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
94231 goto out;
94232 }
94233
94234+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
94235+ if (mm != current->mm &&
94236+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
94237+ mmput(mm);
94238+ err = -EPERM;
94239+ goto out;
94240+ }
94241+#endif
94242+
94243 err = do_migrate_pages(mm, old, new,
94244 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
94245
94246diff --git a/mm/migrate.c b/mm/migrate.c
94247index bed4880..a493f67 100644
94248--- a/mm/migrate.c
94249+++ b/mm/migrate.c
94250@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
94251 */
94252 tcred = __task_cred(task);
94253 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
94254- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
94255- !capable(CAP_SYS_NICE)) {
94256+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
94257 rcu_read_unlock();
94258 err = -EPERM;
94259 goto out;
94260diff --git a/mm/mlock.c b/mm/mlock.c
94261index b1eb536..091d154 100644
94262--- a/mm/mlock.c
94263+++ b/mm/mlock.c
94264@@ -14,6 +14,7 @@
94265 #include <linux/pagevec.h>
94266 #include <linux/mempolicy.h>
94267 #include <linux/syscalls.h>
94268+#include <linux/security.h>
94269 #include <linux/sched.h>
94270 #include <linux/export.h>
94271 #include <linux/rmap.h>
94272@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
94273 {
94274 unsigned long nstart, end, tmp;
94275 struct vm_area_struct * vma, * prev;
94276- int error;
94277+ int error = 0;
94278
94279 VM_BUG_ON(start & ~PAGE_MASK);
94280 VM_BUG_ON(len != PAGE_ALIGN(len));
94281@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
94282 return -EINVAL;
94283 if (end == start)
94284 return 0;
94285+ if (end > TASK_SIZE)
94286+ return -EINVAL;
94287+
94288 vma = find_vma(current->mm, start);
94289 if (!vma || vma->vm_start > start)
94290 return -ENOMEM;
94291@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
94292 for (nstart = start ; ; ) {
94293 vm_flags_t newflags;
94294
94295+#ifdef CONFIG_PAX_SEGMEXEC
94296+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
94297+ break;
94298+#endif
94299+
94300 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
94301
94302 newflags = vma->vm_flags & ~VM_LOCKED;
94303@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
94304 locked += current->mm->locked_vm;
94305
94306 /* check against resource limits */
94307+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
94308 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
94309 error = do_mlock(start, len, 1);
94310
94311@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
94312 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
94313 vm_flags_t newflags;
94314
94315+#ifdef CONFIG_PAX_SEGMEXEC
94316+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
94317+ break;
94318+#endif
94319+
94320 newflags = vma->vm_flags & ~VM_LOCKED;
94321 if (flags & MCL_CURRENT)
94322 newflags |= VM_LOCKED;
94323@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
94324 lock_limit >>= PAGE_SHIFT;
94325
94326 ret = -ENOMEM;
94327+
94328+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
94329+
94330 down_write(&current->mm->mmap_sem);
94331-
94332 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
94333 capable(CAP_IPC_LOCK))
94334 ret = do_mlockall(flags);
94335diff --git a/mm/mmap.c b/mm/mmap.c
94336index b1202cf..ee487f8 100644
94337--- a/mm/mmap.c
94338+++ b/mm/mmap.c
94339@@ -37,6 +37,7 @@
94340 #include <linux/sched/sysctl.h>
94341 #include <linux/notifier.h>
94342 #include <linux/memory.h>
94343+#include <linux/random.h>
94344
94345 #include <asm/uaccess.h>
94346 #include <asm/cacheflush.h>
94347@@ -53,6 +54,16 @@
94348 #define arch_rebalance_pgtables(addr, len) (addr)
94349 #endif
94350
94351+static inline void verify_mm_writelocked(struct mm_struct *mm)
94352+{
94353+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
94354+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94355+ up_read(&mm->mmap_sem);
94356+ BUG();
94357+ }
94358+#endif
94359+}
94360+
94361 static void unmap_region(struct mm_struct *mm,
94362 struct vm_area_struct *vma, struct vm_area_struct *prev,
94363 unsigned long start, unsigned long end);
94364@@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
94365 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
94366 *
94367 */
94368-pgprot_t protection_map[16] = {
94369+pgprot_t protection_map[16] __read_only = {
94370 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
94371 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
94372 };
94373
94374-pgprot_t vm_get_page_prot(unsigned long vm_flags)
94375+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
94376 {
94377- return __pgprot(pgprot_val(protection_map[vm_flags &
94378+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
94379 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
94380 pgprot_val(arch_vm_get_page_prot(vm_flags)));
94381+
94382+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94383+ if (!(__supported_pte_mask & _PAGE_NX) &&
94384+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
94385+ (vm_flags & (VM_READ | VM_WRITE)))
94386+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
94387+#endif
94388+
94389+ return prot;
94390 }
94391 EXPORT_SYMBOL(vm_get_page_prot);
94392
94393@@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
94394 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
94395 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94396 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94397+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
94398 /*
94399 * Make sure vm_committed_as in one cacheline and not cacheline shared with
94400 * other variables. It can be updated by several CPUs frequently.
94401@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
94402 struct vm_area_struct *next = vma->vm_next;
94403
94404 might_sleep();
94405+ BUG_ON(vma->vm_mirror);
94406 if (vma->vm_ops && vma->vm_ops->close)
94407 vma->vm_ops->close(vma);
94408 if (vma->vm_file)
94409@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
94410 * not page aligned -Ram Gupta
94411 */
94412 rlim = rlimit(RLIMIT_DATA);
94413+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
94414 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
94415 (mm->end_data - mm->start_data) > rlim)
94416 goto out;
94417@@ -942,6 +965,12 @@ static int
94418 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
94419 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94420 {
94421+
94422+#ifdef CONFIG_PAX_SEGMEXEC
94423+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
94424+ return 0;
94425+#endif
94426+
94427 if (is_mergeable_vma(vma, file, vm_flags) &&
94428 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94429 if (vma->vm_pgoff == vm_pgoff)
94430@@ -961,6 +990,12 @@ static int
94431 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94432 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94433 {
94434+
94435+#ifdef CONFIG_PAX_SEGMEXEC
94436+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
94437+ return 0;
94438+#endif
94439+
94440 if (is_mergeable_vma(vma, file, vm_flags) &&
94441 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94442 pgoff_t vm_pglen;
94443@@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94444 struct vm_area_struct *vma_merge(struct mm_struct *mm,
94445 struct vm_area_struct *prev, unsigned long addr,
94446 unsigned long end, unsigned long vm_flags,
94447- struct anon_vma *anon_vma, struct file *file,
94448+ struct anon_vma *anon_vma, struct file *file,
94449 pgoff_t pgoff, struct mempolicy *policy)
94450 {
94451 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
94452 struct vm_area_struct *area, *next;
94453 int err;
94454
94455+#ifdef CONFIG_PAX_SEGMEXEC
94456+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
94457+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
94458+
94459+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
94460+#endif
94461+
94462 /*
94463 * We later require that vma->vm_flags == vm_flags,
94464 * so this tests vma->vm_flags & VM_SPECIAL, too.
94465@@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94466 if (next && next->vm_end == end) /* cases 6, 7, 8 */
94467 next = next->vm_next;
94468
94469+#ifdef CONFIG_PAX_SEGMEXEC
94470+ if (prev)
94471+ prev_m = pax_find_mirror_vma(prev);
94472+ if (area)
94473+ area_m = pax_find_mirror_vma(area);
94474+ if (next)
94475+ next_m = pax_find_mirror_vma(next);
94476+#endif
94477+
94478 /*
94479 * Can it merge with the predecessor?
94480 */
94481@@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94482 /* cases 1, 6 */
94483 err = vma_adjust(prev, prev->vm_start,
94484 next->vm_end, prev->vm_pgoff, NULL);
94485- } else /* cases 2, 5, 7 */
94486+
94487+#ifdef CONFIG_PAX_SEGMEXEC
94488+ if (!err && prev_m)
94489+ err = vma_adjust(prev_m, prev_m->vm_start,
94490+ next_m->vm_end, prev_m->vm_pgoff, NULL);
94491+#endif
94492+
94493+ } else { /* cases 2, 5, 7 */
94494 err = vma_adjust(prev, prev->vm_start,
94495 end, prev->vm_pgoff, NULL);
94496+
94497+#ifdef CONFIG_PAX_SEGMEXEC
94498+ if (!err && prev_m)
94499+ err = vma_adjust(prev_m, prev_m->vm_start,
94500+ end_m, prev_m->vm_pgoff, NULL);
94501+#endif
94502+
94503+ }
94504 if (err)
94505 return NULL;
94506 khugepaged_enter_vma_merge(prev);
94507@@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94508 mpol_equal(policy, vma_policy(next)) &&
94509 can_vma_merge_before(next, vm_flags,
94510 anon_vma, file, pgoff+pglen)) {
94511- if (prev && addr < prev->vm_end) /* case 4 */
94512+ if (prev && addr < prev->vm_end) { /* case 4 */
94513 err = vma_adjust(prev, prev->vm_start,
94514 addr, prev->vm_pgoff, NULL);
94515- else /* cases 3, 8 */
94516+
94517+#ifdef CONFIG_PAX_SEGMEXEC
94518+ if (!err && prev_m)
94519+ err = vma_adjust(prev_m, prev_m->vm_start,
94520+ addr_m, prev_m->vm_pgoff, NULL);
94521+#endif
94522+
94523+ } else { /* cases 3, 8 */
94524 err = vma_adjust(area, addr, next->vm_end,
94525 next->vm_pgoff - pglen, NULL);
94526+
94527+#ifdef CONFIG_PAX_SEGMEXEC
94528+ if (!err && area_m)
94529+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
94530+ next_m->vm_pgoff - pglen, NULL);
94531+#endif
94532+
94533+ }
94534 if (err)
94535 return NULL;
94536 khugepaged_enter_vma_merge(area);
94537@@ -1174,8 +1255,10 @@ none:
94538 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94539 struct file *file, long pages)
94540 {
94541- const unsigned long stack_flags
94542- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
94543+
94544+#ifdef CONFIG_PAX_RANDMMAP
94545+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94546+#endif
94547
94548 mm->total_vm += pages;
94549
94550@@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94551 mm->shared_vm += pages;
94552 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
94553 mm->exec_vm += pages;
94554- } else if (flags & stack_flags)
94555+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
94556 mm->stack_vm += pages;
94557 }
94558 #endif /* CONFIG_PROC_FS */
94559@@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
94560 locked += mm->locked_vm;
94561 lock_limit = rlimit(RLIMIT_MEMLOCK);
94562 lock_limit >>= PAGE_SHIFT;
94563+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94564 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
94565 return -EAGAIN;
94566 }
94567@@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94568 * (the exception is when the underlying filesystem is noexec
94569 * mounted, in which case we dont add PROT_EXEC.)
94570 */
94571- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94572+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94573 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
94574 prot |= PROT_EXEC;
94575
94576@@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94577 /* Obtain the address to map to. we verify (or select) it and ensure
94578 * that it represents a valid section of the address space.
94579 */
94580- addr = get_unmapped_area(file, addr, len, pgoff, flags);
94581+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
94582 if (addr & ~PAGE_MASK)
94583 return addr;
94584
94585@@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94586 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
94587 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
94588
94589+#ifdef CONFIG_PAX_MPROTECT
94590+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94591+
94592+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
94593+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
94594+ mm->binfmt->handle_mmap)
94595+ mm->binfmt->handle_mmap(file);
94596+#endif
94597+
94598+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94599+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
94600+ gr_log_rwxmmap(file);
94601+
94602+#ifdef CONFIG_PAX_EMUPLT
94603+ vm_flags &= ~VM_EXEC;
94604+#else
94605+ return -EPERM;
94606+#endif
94607+
94608+ }
94609+
94610+ if (!(vm_flags & VM_EXEC))
94611+ vm_flags &= ~VM_MAYEXEC;
94612+#else
94613+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94614+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94615+#endif
94616+ else
94617+ vm_flags &= ~VM_MAYWRITE;
94618+ }
94619+#endif
94620+
94621+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94622+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
94623+ vm_flags &= ~VM_PAGEEXEC;
94624+#endif
94625+
94626 if (flags & MAP_LOCKED)
94627 if (!can_do_mlock())
94628 return -EPERM;
94629@@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94630 vm_flags |= VM_NORESERVE;
94631 }
94632
94633+ if (!gr_acl_handle_mmap(file, prot))
94634+ return -EACCES;
94635+
94636 addr = mmap_region(file, addr, len, vm_flags, pgoff);
94637 if (!IS_ERR_VALUE(addr) &&
94638 ((vm_flags & VM_LOCKED) ||
94639@@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
94640 vm_flags_t vm_flags = vma->vm_flags;
94641
94642 /* If it was private or non-writable, the write bit is already clear */
94643- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
94644+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
94645 return 0;
94646
94647 /* The backer wishes to know when pages are first written to? */
94648@@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94649 struct rb_node **rb_link, *rb_parent;
94650 unsigned long charged = 0;
94651
94652+#ifdef CONFIG_PAX_SEGMEXEC
94653+ struct vm_area_struct *vma_m = NULL;
94654+#endif
94655+
94656+ /*
94657+ * mm->mmap_sem is required to protect against another thread
94658+ * changing the mappings in case we sleep.
94659+ */
94660+ verify_mm_writelocked(mm);
94661+
94662 /* Check against address space limit. */
94663+
94664+#ifdef CONFIG_PAX_RANDMMAP
94665+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94666+#endif
94667+
94668 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
94669 unsigned long nr_pages;
94670
94671@@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94672
94673 /* Clear old maps */
94674 error = -ENOMEM;
94675-munmap_back:
94676 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94677 if (do_munmap(mm, addr, len))
94678 return -ENOMEM;
94679- goto munmap_back;
94680+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94681 }
94682
94683 /*
94684@@ -1556,6 +1694,16 @@ munmap_back:
94685 goto unacct_error;
94686 }
94687
94688+#ifdef CONFIG_PAX_SEGMEXEC
94689+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
94690+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94691+ if (!vma_m) {
94692+ error = -ENOMEM;
94693+ goto free_vma;
94694+ }
94695+ }
94696+#endif
94697+
94698 vma->vm_mm = mm;
94699 vma->vm_start = addr;
94700 vma->vm_end = addr + len;
94701@@ -1575,6 +1723,13 @@ munmap_back:
94702 if (error)
94703 goto unmap_and_free_vma;
94704
94705+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94706+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
94707+ vma->vm_flags |= VM_PAGEEXEC;
94708+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94709+ }
94710+#endif
94711+
94712 /* Can addr have changed??
94713 *
94714 * Answer: Yes, several device drivers can do it in their
94715@@ -1608,6 +1763,12 @@ munmap_back:
94716 }
94717
94718 vma_link(mm, vma, prev, rb_link, rb_parent);
94719+
94720+#ifdef CONFIG_PAX_SEGMEXEC
94721+ if (vma_m)
94722+ BUG_ON(pax_mirror_vma(vma_m, vma));
94723+#endif
94724+
94725 /* Once vma denies write, undo our temporary denial count */
94726 if (vm_flags & VM_DENYWRITE)
94727 allow_write_access(file);
94728@@ -1616,6 +1777,7 @@ out:
94729 perf_event_mmap(vma);
94730
94731 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94732+ track_exec_limit(mm, addr, addr + len, vm_flags);
94733 if (vm_flags & VM_LOCKED) {
94734 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94735 vma == get_gate_vma(current->mm)))
94736@@ -1648,6 +1810,12 @@ unmap_and_free_vma:
94737 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94738 charged = 0;
94739 free_vma:
94740+
94741+#ifdef CONFIG_PAX_SEGMEXEC
94742+ if (vma_m)
94743+ kmem_cache_free(vm_area_cachep, vma_m);
94744+#endif
94745+
94746 kmem_cache_free(vm_area_cachep, vma);
94747 unacct_error:
94748 if (charged)
94749@@ -1655,7 +1823,63 @@ unacct_error:
94750 return error;
94751 }
94752
94753-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94754+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94755+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94756+{
94757+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94758+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94759+
94760+ return 0;
94761+}
94762+#endif
94763+
94764+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94765+{
94766+ if (!vma) {
94767+#ifdef CONFIG_STACK_GROWSUP
94768+ if (addr > sysctl_heap_stack_gap)
94769+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94770+ else
94771+ vma = find_vma(current->mm, 0);
94772+ if (vma && (vma->vm_flags & VM_GROWSUP))
94773+ return false;
94774+#endif
94775+ return true;
94776+ }
94777+
94778+ if (addr + len > vma->vm_start)
94779+ return false;
94780+
94781+ if (vma->vm_flags & VM_GROWSDOWN)
94782+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94783+#ifdef CONFIG_STACK_GROWSUP
94784+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94785+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94786+#endif
94787+ else if (offset)
94788+ return offset <= vma->vm_start - addr - len;
94789+
94790+ return true;
94791+}
94792+
94793+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94794+{
94795+ if (vma->vm_start < len)
94796+ return -ENOMEM;
94797+
94798+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94799+ if (offset <= vma->vm_start - len)
94800+ return vma->vm_start - len - offset;
94801+ else
94802+ return -ENOMEM;
94803+ }
94804+
94805+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94806+ return vma->vm_start - len - sysctl_heap_stack_gap;
94807+ return -ENOMEM;
94808+}
94809+
94810+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94811 {
94812 /*
94813 * We implement the search by looking for an rbtree node that
94814@@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94815 }
94816 }
94817
94818- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94819+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94820 check_current:
94821 /* Check if current node has a suitable gap */
94822 if (gap_start > high_limit)
94823 return -ENOMEM;
94824+
94825+ if (gap_end - gap_start > info->threadstack_offset)
94826+ gap_start += info->threadstack_offset;
94827+ else
94828+ gap_start = gap_end;
94829+
94830+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94831+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94832+ gap_start += sysctl_heap_stack_gap;
94833+ else
94834+ gap_start = gap_end;
94835+ }
94836+ if (vma->vm_flags & VM_GROWSDOWN) {
94837+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94838+ gap_end -= sysctl_heap_stack_gap;
94839+ else
94840+ gap_end = gap_start;
94841+ }
94842 if (gap_end >= low_limit && gap_end - gap_start >= length)
94843 goto found;
94844
94845@@ -1757,7 +1999,7 @@ found:
94846 return gap_start;
94847 }
94848
94849-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94850+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94851 {
94852 struct mm_struct *mm = current->mm;
94853 struct vm_area_struct *vma;
94854@@ -1811,6 +2053,24 @@ check_current:
94855 gap_end = vma->vm_start;
94856 if (gap_end < low_limit)
94857 return -ENOMEM;
94858+
94859+ if (gap_end - gap_start > info->threadstack_offset)
94860+ gap_end -= info->threadstack_offset;
94861+ else
94862+ gap_end = gap_start;
94863+
94864+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94865+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94866+ gap_start += sysctl_heap_stack_gap;
94867+ else
94868+ gap_start = gap_end;
94869+ }
94870+ if (vma->vm_flags & VM_GROWSDOWN) {
94871+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94872+ gap_end -= sysctl_heap_stack_gap;
94873+ else
94874+ gap_end = gap_start;
94875+ }
94876 if (gap_start <= high_limit && gap_end - gap_start >= length)
94877 goto found;
94878
94879@@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94880 struct mm_struct *mm = current->mm;
94881 struct vm_area_struct *vma;
94882 struct vm_unmapped_area_info info;
94883+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94884
94885 if (len > TASK_SIZE - mmap_min_addr)
94886 return -ENOMEM;
94887@@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94888 if (flags & MAP_FIXED)
94889 return addr;
94890
94891+#ifdef CONFIG_PAX_RANDMMAP
94892+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94893+#endif
94894+
94895 if (addr) {
94896 addr = PAGE_ALIGN(addr);
94897 vma = find_vma(mm, addr);
94898 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94899- (!vma || addr + len <= vma->vm_start))
94900+ check_heap_stack_gap(vma, addr, len, offset))
94901 return addr;
94902 }
94903
94904@@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94905 info.low_limit = mm->mmap_base;
94906 info.high_limit = TASK_SIZE;
94907 info.align_mask = 0;
94908+ info.threadstack_offset = offset;
94909 return vm_unmapped_area(&info);
94910 }
94911 #endif
94912@@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94913 struct mm_struct *mm = current->mm;
94914 unsigned long addr = addr0;
94915 struct vm_unmapped_area_info info;
94916+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94917
94918 /* requested length too big for entire address space */
94919 if (len > TASK_SIZE - mmap_min_addr)
94920@@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94921 if (flags & MAP_FIXED)
94922 return addr;
94923
94924+#ifdef CONFIG_PAX_RANDMMAP
94925+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94926+#endif
94927+
94928 /* requesting a specific address */
94929 if (addr) {
94930 addr = PAGE_ALIGN(addr);
94931 vma = find_vma(mm, addr);
94932 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94933- (!vma || addr + len <= vma->vm_start))
94934+ check_heap_stack_gap(vma, addr, len, offset))
94935 return addr;
94936 }
94937
94938@@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94939 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94940 info.high_limit = mm->mmap_base;
94941 info.align_mask = 0;
94942+ info.threadstack_offset = offset;
94943 addr = vm_unmapped_area(&info);
94944
94945 /*
94946@@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94947 VM_BUG_ON(addr != -ENOMEM);
94948 info.flags = 0;
94949 info.low_limit = TASK_UNMAPPED_BASE;
94950+
94951+#ifdef CONFIG_PAX_RANDMMAP
94952+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94953+ info.low_limit += mm->delta_mmap;
94954+#endif
94955+
94956 info.high_limit = TASK_SIZE;
94957 addr = vm_unmapped_area(&info);
94958 }
94959@@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94960 return vma;
94961 }
94962
94963+#ifdef CONFIG_PAX_SEGMEXEC
94964+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94965+{
94966+ struct vm_area_struct *vma_m;
94967+
94968+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94969+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94970+ BUG_ON(vma->vm_mirror);
94971+ return NULL;
94972+ }
94973+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94974+ vma_m = vma->vm_mirror;
94975+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94976+ BUG_ON(vma->vm_file != vma_m->vm_file);
94977+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94978+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94979+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94980+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94981+ return vma_m;
94982+}
94983+#endif
94984+
94985 /*
94986 * Verify that the stack growth is acceptable and
94987 * update accounting. This is shared with both the
94988@@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94989 return -ENOMEM;
94990
94991 /* Stack limit test */
94992+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94993 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94994 return -ENOMEM;
94995
94996@@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94997 locked = mm->locked_vm + grow;
94998 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94999 limit >>= PAGE_SHIFT;
95000+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
95001 if (locked > limit && !capable(CAP_IPC_LOCK))
95002 return -ENOMEM;
95003 }
95004@@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
95005 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
95006 * vma is the last one with address > vma->vm_end. Have to extend vma.
95007 */
95008+#ifndef CONFIG_IA64
95009+static
95010+#endif
95011 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
95012 {
95013 int error;
95014+ bool locknext;
95015
95016 if (!(vma->vm_flags & VM_GROWSUP))
95017 return -EFAULT;
95018
95019+ /* Also guard against wrapping around to address 0. */
95020+ if (address < PAGE_ALIGN(address+1))
95021+ address = PAGE_ALIGN(address+1);
95022+ else
95023+ return -ENOMEM;
95024+
95025 /*
95026 * We must make sure the anon_vma is allocated
95027 * so that the anon_vma locking is not a noop.
95028 */
95029 if (unlikely(anon_vma_prepare(vma)))
95030 return -ENOMEM;
95031+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
95032+ if (locknext && anon_vma_prepare(vma->vm_next))
95033+ return -ENOMEM;
95034 vma_lock_anon_vma(vma);
95035+ if (locknext)
95036+ vma_lock_anon_vma(vma->vm_next);
95037
95038 /*
95039 * vma->vm_start/vm_end cannot change under us because the caller
95040 * is required to hold the mmap_sem in read mode. We need the
95041- * anon_vma lock to serialize against concurrent expand_stacks.
95042- * Also guard against wrapping around to address 0.
95043+ * anon_vma locks to serialize against concurrent expand_stacks
95044+ * and expand_upwards.
95045 */
95046- if (address < PAGE_ALIGN(address+4))
95047- address = PAGE_ALIGN(address+4);
95048- else {
95049- vma_unlock_anon_vma(vma);
95050- return -ENOMEM;
95051- }
95052 error = 0;
95053
95054 /* Somebody else might have raced and expanded it already */
95055- if (address > vma->vm_end) {
95056+ 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)
95057+ error = -ENOMEM;
95058+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
95059 unsigned long size, grow;
95060
95061 size = address - vma->vm_start;
95062@@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
95063 }
95064 }
95065 }
95066+ if (locknext)
95067+ vma_unlock_anon_vma(vma->vm_next);
95068 vma_unlock_anon_vma(vma);
95069 khugepaged_enter_vma_merge(vma);
95070 validate_mm(vma->vm_mm);
95071@@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
95072 unsigned long address)
95073 {
95074 int error;
95075+ bool lockprev = false;
95076+ struct vm_area_struct *prev;
95077
95078 /*
95079 * We must make sure the anon_vma is allocated
95080@@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
95081 if (error)
95082 return error;
95083
95084+ prev = vma->vm_prev;
95085+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
95086+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
95087+#endif
95088+ if (lockprev && anon_vma_prepare(prev))
95089+ return -ENOMEM;
95090+ if (lockprev)
95091+ vma_lock_anon_vma(prev);
95092+
95093 vma_lock_anon_vma(vma);
95094
95095 /*
95096@@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
95097 */
95098
95099 /* Somebody else might have raced and expanded it already */
95100- if (address < vma->vm_start) {
95101+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
95102+ error = -ENOMEM;
95103+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
95104 unsigned long size, grow;
95105
95106+#ifdef CONFIG_PAX_SEGMEXEC
95107+ struct vm_area_struct *vma_m;
95108+
95109+ vma_m = pax_find_mirror_vma(vma);
95110+#endif
95111+
95112 size = vma->vm_end - address;
95113 grow = (vma->vm_start - address) >> PAGE_SHIFT;
95114
95115@@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
95116 vma->vm_pgoff -= grow;
95117 anon_vma_interval_tree_post_update_vma(vma);
95118 vma_gap_update(vma);
95119+
95120+#ifdef CONFIG_PAX_SEGMEXEC
95121+ if (vma_m) {
95122+ anon_vma_interval_tree_pre_update_vma(vma_m);
95123+ vma_m->vm_start -= grow << PAGE_SHIFT;
95124+ vma_m->vm_pgoff -= grow;
95125+ anon_vma_interval_tree_post_update_vma(vma_m);
95126+ vma_gap_update(vma_m);
95127+ }
95128+#endif
95129+
95130 spin_unlock(&vma->vm_mm->page_table_lock);
95131
95132+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
95133 perf_event_mmap(vma);
95134 }
95135 }
95136 }
95137 vma_unlock_anon_vma(vma);
95138+ if (lockprev)
95139+ vma_unlock_anon_vma(prev);
95140 khugepaged_enter_vma_merge(vma);
95141 validate_mm(vma->vm_mm);
95142 return error;
95143@@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
95144 do {
95145 long nrpages = vma_pages(vma);
95146
95147+#ifdef CONFIG_PAX_SEGMEXEC
95148+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
95149+ vma = remove_vma(vma);
95150+ continue;
95151+ }
95152+#endif
95153+
95154 if (vma->vm_flags & VM_ACCOUNT)
95155 nr_accounted += nrpages;
95156 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
95157@@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
95158 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
95159 vma->vm_prev = NULL;
95160 do {
95161+
95162+#ifdef CONFIG_PAX_SEGMEXEC
95163+ if (vma->vm_mirror) {
95164+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
95165+ vma->vm_mirror->vm_mirror = NULL;
95166+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
95167+ vma->vm_mirror = NULL;
95168+ }
95169+#endif
95170+
95171 vma_rb_erase(vma, &mm->mm_rb);
95172 mm->map_count--;
95173 tail_vma = vma;
95174@@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95175 struct vm_area_struct *new;
95176 int err = -ENOMEM;
95177
95178+#ifdef CONFIG_PAX_SEGMEXEC
95179+ struct vm_area_struct *vma_m, *new_m = NULL;
95180+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
95181+#endif
95182+
95183 if (is_vm_hugetlb_page(vma) && (addr &
95184 ~(huge_page_mask(hstate_vma(vma)))))
95185 return -EINVAL;
95186
95187+#ifdef CONFIG_PAX_SEGMEXEC
95188+ vma_m = pax_find_mirror_vma(vma);
95189+#endif
95190+
95191 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
95192 if (!new)
95193 goto out_err;
95194
95195+#ifdef CONFIG_PAX_SEGMEXEC
95196+ if (vma_m) {
95197+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
95198+ if (!new_m) {
95199+ kmem_cache_free(vm_area_cachep, new);
95200+ goto out_err;
95201+ }
95202+ }
95203+#endif
95204+
95205 /* most fields are the same, copy all, and then fixup */
95206 *new = *vma;
95207
95208@@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95209 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
95210 }
95211
95212+#ifdef CONFIG_PAX_SEGMEXEC
95213+ if (vma_m) {
95214+ *new_m = *vma_m;
95215+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
95216+ new_m->vm_mirror = new;
95217+ new->vm_mirror = new_m;
95218+
95219+ if (new_below)
95220+ new_m->vm_end = addr_m;
95221+ else {
95222+ new_m->vm_start = addr_m;
95223+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
95224+ }
95225+ }
95226+#endif
95227+
95228 err = vma_dup_policy(vma, new);
95229 if (err)
95230 goto out_free_vma;
95231@@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95232 else
95233 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
95234
95235+#ifdef CONFIG_PAX_SEGMEXEC
95236+ if (!err && vma_m) {
95237+ struct mempolicy *pol = vma_policy(new);
95238+
95239+ if (anon_vma_clone(new_m, vma_m))
95240+ goto out_free_mpol;
95241+
95242+ mpol_get(pol);
95243+ set_vma_policy(new_m, pol);
95244+
95245+ if (new_m->vm_file)
95246+ get_file(new_m->vm_file);
95247+
95248+ if (new_m->vm_ops && new_m->vm_ops->open)
95249+ new_m->vm_ops->open(new_m);
95250+
95251+ if (new_below)
95252+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
95253+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
95254+ else
95255+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
95256+
95257+ if (err) {
95258+ if (new_m->vm_ops && new_m->vm_ops->close)
95259+ new_m->vm_ops->close(new_m);
95260+ if (new_m->vm_file)
95261+ fput(new_m->vm_file);
95262+ mpol_put(pol);
95263+ }
95264+ }
95265+#endif
95266+
95267 /* Success. */
95268 if (!err)
95269 return 0;
95270@@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95271 new->vm_ops->close(new);
95272 if (new->vm_file)
95273 fput(new->vm_file);
95274- unlink_anon_vmas(new);
95275 out_free_mpol:
95276 mpol_put(vma_policy(new));
95277 out_free_vma:
95278+
95279+#ifdef CONFIG_PAX_SEGMEXEC
95280+ if (new_m) {
95281+ unlink_anon_vmas(new_m);
95282+ kmem_cache_free(vm_area_cachep, new_m);
95283+ }
95284+#endif
95285+
95286+ unlink_anon_vmas(new);
95287 kmem_cache_free(vm_area_cachep, new);
95288 out_err:
95289 return err;
95290@@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95291 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95292 unsigned long addr, int new_below)
95293 {
95294+
95295+#ifdef CONFIG_PAX_SEGMEXEC
95296+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
95297+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
95298+ if (mm->map_count >= sysctl_max_map_count-1)
95299+ return -ENOMEM;
95300+ } else
95301+#endif
95302+
95303 if (mm->map_count >= sysctl_max_map_count)
95304 return -ENOMEM;
95305
95306@@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95307 * work. This now handles partial unmappings.
95308 * Jeremy Fitzhardinge <jeremy@goop.org>
95309 */
95310+#ifdef CONFIG_PAX_SEGMEXEC
95311 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95312 {
95313+ int ret = __do_munmap(mm, start, len);
95314+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
95315+ return ret;
95316+
95317+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
95318+}
95319+
95320+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95321+#else
95322+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95323+#endif
95324+{
95325 unsigned long end;
95326 struct vm_area_struct *vma, *prev, *last;
95327
95328+ /*
95329+ * mm->mmap_sem is required to protect against another thread
95330+ * changing the mappings in case we sleep.
95331+ */
95332+ verify_mm_writelocked(mm);
95333+
95334 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
95335 return -EINVAL;
95336
95337@@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95338 /* Fix up all other VM information */
95339 remove_vma_list(mm, vma);
95340
95341+ track_exec_limit(mm, start, end, 0UL);
95342+
95343 return 0;
95344 }
95345
95346@@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
95347 int ret;
95348 struct mm_struct *mm = current->mm;
95349
95350+
95351+#ifdef CONFIG_PAX_SEGMEXEC
95352+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
95353+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
95354+ return -EINVAL;
95355+#endif
95356+
95357 down_write(&mm->mmap_sem);
95358 ret = do_munmap(mm, start, len);
95359 up_write(&mm->mmap_sem);
95360@@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
95361 return vm_munmap(addr, len);
95362 }
95363
95364-static inline void verify_mm_writelocked(struct mm_struct *mm)
95365-{
95366-#ifdef CONFIG_DEBUG_VM
95367- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
95368- WARN_ON(1);
95369- up_read(&mm->mmap_sem);
95370- }
95371-#endif
95372-}
95373-
95374 /*
95375 * this is really a simplified "do_mmap". it only handles
95376 * anonymous maps. eventually we may be able to do some
95377@@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95378 struct rb_node ** rb_link, * rb_parent;
95379 pgoff_t pgoff = addr >> PAGE_SHIFT;
95380 int error;
95381+ unsigned long charged;
95382
95383 len = PAGE_ALIGN(len);
95384 if (!len)
95385@@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95386
95387 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
95388
95389+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
95390+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
95391+ flags &= ~VM_EXEC;
95392+
95393+#ifdef CONFIG_PAX_MPROTECT
95394+ if (mm->pax_flags & MF_PAX_MPROTECT)
95395+ flags &= ~VM_MAYEXEC;
95396+#endif
95397+
95398+ }
95399+#endif
95400+
95401 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
95402 if (error & ~PAGE_MASK)
95403 return error;
95404
95405+ charged = len >> PAGE_SHIFT;
95406+
95407 error = mlock_future_check(mm, mm->def_flags, len);
95408 if (error)
95409 return error;
95410@@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95411 /*
95412 * Clear old maps. this also does some error checking for us
95413 */
95414- munmap_back:
95415 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
95416 if (do_munmap(mm, addr, len))
95417 return -ENOMEM;
95418- goto munmap_back;
95419+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
95420 }
95421
95422 /* Check against address space limits *after* clearing old maps... */
95423- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
95424+ if (!may_expand_vm(mm, charged))
95425 return -ENOMEM;
95426
95427 if (mm->map_count > sysctl_max_map_count)
95428 return -ENOMEM;
95429
95430- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
95431+ if (security_vm_enough_memory_mm(mm, charged))
95432 return -ENOMEM;
95433
95434 /* Can we just expand an old private anonymous mapping? */
95435@@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95436 */
95437 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95438 if (!vma) {
95439- vm_unacct_memory(len >> PAGE_SHIFT);
95440+ vm_unacct_memory(charged);
95441 return -ENOMEM;
95442 }
95443
95444@@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95445 vma_link(mm, vma, prev, rb_link, rb_parent);
95446 out:
95447 perf_event_mmap(vma);
95448- mm->total_vm += len >> PAGE_SHIFT;
95449+ mm->total_vm += charged;
95450 if (flags & VM_LOCKED)
95451- mm->locked_vm += (len >> PAGE_SHIFT);
95452+ mm->locked_vm += charged;
95453 vma->vm_flags |= VM_SOFTDIRTY;
95454+ track_exec_limit(mm, addr, addr + len, flags);
95455 return addr;
95456 }
95457
95458@@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
95459 while (vma) {
95460 if (vma->vm_flags & VM_ACCOUNT)
95461 nr_accounted += vma_pages(vma);
95462+ vma->vm_mirror = NULL;
95463 vma = remove_vma(vma);
95464 }
95465 vm_unacct_memory(nr_accounted);
95466@@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95467 struct vm_area_struct *prev;
95468 struct rb_node **rb_link, *rb_parent;
95469
95470+#ifdef CONFIG_PAX_SEGMEXEC
95471+ struct vm_area_struct *vma_m = NULL;
95472+#endif
95473+
95474+ if (security_mmap_addr(vma->vm_start))
95475+ return -EPERM;
95476+
95477 /*
95478 * The vm_pgoff of a purely anonymous vma should be irrelevant
95479 * until its first write fault, when page's anon_vma and index
95480@@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95481 security_vm_enough_memory_mm(mm, vma_pages(vma)))
95482 return -ENOMEM;
95483
95484+#ifdef CONFIG_PAX_SEGMEXEC
95485+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
95486+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95487+ if (!vma_m)
95488+ return -ENOMEM;
95489+ }
95490+#endif
95491+
95492 vma_link(mm, vma, prev, rb_link, rb_parent);
95493+
95494+#ifdef CONFIG_PAX_SEGMEXEC
95495+ if (vma_m)
95496+ BUG_ON(pax_mirror_vma(vma_m, vma));
95497+#endif
95498+
95499 return 0;
95500 }
95501
95502@@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95503 struct rb_node **rb_link, *rb_parent;
95504 bool faulted_in_anon_vma = true;
95505
95506+ BUG_ON(vma->vm_mirror);
95507+
95508 /*
95509 * If anonymous vma has not yet been faulted, update new pgoff
95510 * to match new location, to increase its chance of merging.
95511@@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95512 return NULL;
95513 }
95514
95515+#ifdef CONFIG_PAX_SEGMEXEC
95516+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
95517+{
95518+ struct vm_area_struct *prev_m;
95519+ struct rb_node **rb_link_m, *rb_parent_m;
95520+ struct mempolicy *pol_m;
95521+
95522+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
95523+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
95524+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
95525+ *vma_m = *vma;
95526+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
95527+ if (anon_vma_clone(vma_m, vma))
95528+ return -ENOMEM;
95529+ pol_m = vma_policy(vma_m);
95530+ mpol_get(pol_m);
95531+ set_vma_policy(vma_m, pol_m);
95532+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
95533+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
95534+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
95535+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
95536+ if (vma_m->vm_file)
95537+ get_file(vma_m->vm_file);
95538+ if (vma_m->vm_ops && vma_m->vm_ops->open)
95539+ vma_m->vm_ops->open(vma_m);
95540+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
95541+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
95542+ vma_m->vm_mirror = vma;
95543+ vma->vm_mirror = vma_m;
95544+ return 0;
95545+}
95546+#endif
95547+
95548 /*
95549 * Return true if the calling process may expand its vm space by the passed
95550 * number of pages
95551@@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
95552
95553 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
95554
95555+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
95556 if (cur + npages > lim)
95557 return 0;
95558 return 1;
95559@@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
95560 vma->vm_start = addr;
95561 vma->vm_end = addr + len;
95562
95563+#ifdef CONFIG_PAX_MPROTECT
95564+ if (mm->pax_flags & MF_PAX_MPROTECT) {
95565+#ifndef CONFIG_PAX_MPROTECT_COMPAT
95566+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
95567+ return ERR_PTR(-EPERM);
95568+ if (!(vm_flags & VM_EXEC))
95569+ vm_flags &= ~VM_MAYEXEC;
95570+#else
95571+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
95572+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
95573+#endif
95574+ else
95575+ vm_flags &= ~VM_MAYWRITE;
95576+ }
95577+#endif
95578+
95579 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
95580 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
95581
95582diff --git a/mm/mprotect.c b/mm/mprotect.c
95583index c43d557..0b7ccd2 100644
95584--- a/mm/mprotect.c
95585+++ b/mm/mprotect.c
95586@@ -24,10 +24,18 @@
95587 #include <linux/migrate.h>
95588 #include <linux/perf_event.h>
95589 #include <linux/ksm.h>
95590+#include <linux/sched/sysctl.h>
95591+
95592+#ifdef CONFIG_PAX_MPROTECT
95593+#include <linux/elf.h>
95594+#include <linux/binfmts.h>
95595+#endif
95596+
95597 #include <asm/uaccess.h>
95598 #include <asm/pgtable.h>
95599 #include <asm/cacheflush.h>
95600 #include <asm/tlbflush.h>
95601+#include <asm/mmu_context.h>
95602
95603 #ifndef pgprot_modify
95604 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
95605@@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
95606 return pages;
95607 }
95608
95609+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95610+/* called while holding the mmap semaphor for writing except stack expansion */
95611+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
95612+{
95613+ unsigned long oldlimit, newlimit = 0UL;
95614+
95615+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
95616+ return;
95617+
95618+ spin_lock(&mm->page_table_lock);
95619+ oldlimit = mm->context.user_cs_limit;
95620+ if ((prot & VM_EXEC) && oldlimit < end)
95621+ /* USER_CS limit moved up */
95622+ newlimit = end;
95623+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
95624+ /* USER_CS limit moved down */
95625+ newlimit = start;
95626+
95627+ if (newlimit) {
95628+ mm->context.user_cs_limit = newlimit;
95629+
95630+#ifdef CONFIG_SMP
95631+ wmb();
95632+ cpus_clear(mm->context.cpu_user_cs_mask);
95633+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
95634+#endif
95635+
95636+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
95637+ }
95638+ spin_unlock(&mm->page_table_lock);
95639+ if (newlimit == end) {
95640+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
95641+
95642+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
95643+ if (is_vm_hugetlb_page(vma))
95644+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
95645+ else
95646+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
95647+ }
95648+}
95649+#endif
95650+
95651 int
95652 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95653 unsigned long start, unsigned long end, unsigned long newflags)
95654@@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95655 int error;
95656 int dirty_accountable = 0;
95657
95658+#ifdef CONFIG_PAX_SEGMEXEC
95659+ struct vm_area_struct *vma_m = NULL;
95660+ unsigned long start_m, end_m;
95661+
95662+ start_m = start + SEGMEXEC_TASK_SIZE;
95663+ end_m = end + SEGMEXEC_TASK_SIZE;
95664+#endif
95665+
95666 if (newflags == oldflags) {
95667 *pprev = vma;
95668 return 0;
95669 }
95670
95671+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
95672+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
95673+
95674+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
95675+ return -ENOMEM;
95676+
95677+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
95678+ return -ENOMEM;
95679+ }
95680+
95681 /*
95682 * If we make a private mapping writable we increase our commit;
95683 * but (without finer accounting) cannot reduce our commit if we
95684@@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95685 }
95686 }
95687
95688+#ifdef CONFIG_PAX_SEGMEXEC
95689+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
95690+ if (start != vma->vm_start) {
95691+ error = split_vma(mm, vma, start, 1);
95692+ if (error)
95693+ goto fail;
95694+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
95695+ *pprev = (*pprev)->vm_next;
95696+ }
95697+
95698+ if (end != vma->vm_end) {
95699+ error = split_vma(mm, vma, end, 0);
95700+ if (error)
95701+ goto fail;
95702+ }
95703+
95704+ if (pax_find_mirror_vma(vma)) {
95705+ error = __do_munmap(mm, start_m, end_m - start_m);
95706+ if (error)
95707+ goto fail;
95708+ } else {
95709+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95710+ if (!vma_m) {
95711+ error = -ENOMEM;
95712+ goto fail;
95713+ }
95714+ vma->vm_flags = newflags;
95715+ error = pax_mirror_vma(vma_m, vma);
95716+ if (error) {
95717+ vma->vm_flags = oldflags;
95718+ goto fail;
95719+ }
95720+ }
95721+ }
95722+#endif
95723+
95724 /*
95725 * First try to merge with previous and/or next vma.
95726 */
95727@@ -319,9 +423,21 @@ success:
95728 * vm_flags and vm_page_prot are protected by the mmap_sem
95729 * held in write mode.
95730 */
95731+
95732+#ifdef CONFIG_PAX_SEGMEXEC
95733+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95734+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95735+#endif
95736+
95737 vma->vm_flags = newflags;
95738+
95739+#ifdef CONFIG_PAX_MPROTECT
95740+ if (mm->binfmt && mm->binfmt->handle_mprotect)
95741+ mm->binfmt->handle_mprotect(vma, newflags);
95742+#endif
95743+
95744 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95745- vm_get_page_prot(newflags));
95746+ vm_get_page_prot(vma->vm_flags));
95747
95748 if (vma_wants_writenotify(vma)) {
95749 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95750@@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95751 end = start + len;
95752 if (end <= start)
95753 return -ENOMEM;
95754+
95755+#ifdef CONFIG_PAX_SEGMEXEC
95756+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95757+ if (end > SEGMEXEC_TASK_SIZE)
95758+ return -EINVAL;
95759+ } else
95760+#endif
95761+
95762+ if (end > TASK_SIZE)
95763+ return -EINVAL;
95764+
95765 if (!arch_validate_prot(prot))
95766 return -EINVAL;
95767
95768@@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95769 /*
95770 * Does the application expect PROT_READ to imply PROT_EXEC:
95771 */
95772- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95773+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95774 prot |= PROT_EXEC;
95775
95776 vm_flags = calc_vm_prot_bits(prot);
95777@@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95778 if (start > vma->vm_start)
95779 prev = vma;
95780
95781+#ifdef CONFIG_PAX_MPROTECT
95782+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95783+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
95784+#endif
95785+
95786 for (nstart = start ; ; ) {
95787 unsigned long newflags;
95788
95789@@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95790
95791 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95792 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95793+ if (prot & (PROT_WRITE | PROT_EXEC))
95794+ gr_log_rwxmprotect(vma);
95795+
95796+ error = -EACCES;
95797+ goto out;
95798+ }
95799+
95800+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95801 error = -EACCES;
95802 goto out;
95803 }
95804@@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95805 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95806 if (error)
95807 goto out;
95808+
95809+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95810+
95811 nstart = tmp;
95812
95813 if (nstart < prev->vm_end)
95814diff --git a/mm/mremap.c b/mm/mremap.c
95815index 05f1180..c3cde48 100644
95816--- a/mm/mremap.c
95817+++ b/mm/mremap.c
95818@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95819 continue;
95820 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95821 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95822+
95823+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95824+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95825+ pte = pte_exprotect(pte);
95826+#endif
95827+
95828 pte = move_soft_dirty_pte(pte);
95829 set_pte_at(mm, new_addr, new_pte, pte);
95830 }
95831@@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95832 if (is_vm_hugetlb_page(vma))
95833 goto Einval;
95834
95835+#ifdef CONFIG_PAX_SEGMEXEC
95836+ if (pax_find_mirror_vma(vma))
95837+ goto Einval;
95838+#endif
95839+
95840 /* We can't remap across vm area boundaries */
95841 if (old_len > vma->vm_end - addr)
95842 goto Efault;
95843@@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95844 unsigned long ret = -EINVAL;
95845 unsigned long charged = 0;
95846 unsigned long map_flags;
95847+ unsigned long pax_task_size = TASK_SIZE;
95848
95849 if (new_addr & ~PAGE_MASK)
95850 goto out;
95851
95852- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95853+#ifdef CONFIG_PAX_SEGMEXEC
95854+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95855+ pax_task_size = SEGMEXEC_TASK_SIZE;
95856+#endif
95857+
95858+ pax_task_size -= PAGE_SIZE;
95859+
95860+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95861 goto out;
95862
95863 /* Check if the location we're moving into overlaps the
95864 * old location at all, and fail if it does.
95865 */
95866- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95867- goto out;
95868-
95869- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95870+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95871 goto out;
95872
95873 ret = do_munmap(mm, new_addr, new_len);
95874@@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95875 unsigned long ret = -EINVAL;
95876 unsigned long charged = 0;
95877 bool locked = false;
95878+ unsigned long pax_task_size = TASK_SIZE;
95879
95880 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95881 return ret;
95882@@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95883 if (!new_len)
95884 return ret;
95885
95886+#ifdef CONFIG_PAX_SEGMEXEC
95887+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95888+ pax_task_size = SEGMEXEC_TASK_SIZE;
95889+#endif
95890+
95891+ pax_task_size -= PAGE_SIZE;
95892+
95893+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95894+ old_len > pax_task_size || addr > pax_task_size-old_len)
95895+ return ret;
95896+
95897 down_write(&current->mm->mmap_sem);
95898
95899 if (flags & MREMAP_FIXED) {
95900@@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95901 new_addr = addr;
95902 }
95903 ret = addr;
95904+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95905 goto out;
95906 }
95907 }
95908@@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95909 goto out;
95910 }
95911
95912+ map_flags = vma->vm_flags;
95913 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95914+ if (!(ret & ~PAGE_MASK)) {
95915+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95916+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95917+ }
95918 }
95919 out:
95920 if (ret & ~PAGE_MASK)
95921diff --git a/mm/nommu.c b/mm/nommu.c
95922index 431fd7c..8674512 100644
95923--- a/mm/nommu.c
95924+++ b/mm/nommu.c
95925@@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95926 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95927 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95928 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95929-int heap_stack_gap = 0;
95930
95931 atomic_long_t mmap_pages_allocated;
95932
95933@@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95934 EXPORT_SYMBOL(find_vma);
95935
95936 /*
95937- * find a VMA
95938- * - we don't extend stack VMAs under NOMMU conditions
95939- */
95940-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95941-{
95942- return find_vma(mm, addr);
95943-}
95944-
95945-/*
95946 * expand a stack to a given address
95947 * - not supported under NOMMU conditions
95948 */
95949@@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95950
95951 /* most fields are the same, copy all, and then fixup */
95952 *new = *vma;
95953+ INIT_LIST_HEAD(&new->anon_vma_chain);
95954 *region = *vma->vm_region;
95955 new->vm_region = region;
95956
95957@@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95958 }
95959 EXPORT_SYMBOL(generic_file_remap_pages);
95960
95961-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95962- unsigned long addr, void *buf, int len, int write)
95963+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95964+ unsigned long addr, void *buf, size_t len, int write)
95965 {
95966 struct vm_area_struct *vma;
95967
95968@@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95969 *
95970 * The caller must hold a reference on @mm.
95971 */
95972-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95973- void *buf, int len, int write)
95974+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95975+ void *buf, size_t len, int write)
95976 {
95977 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95978 }
95979@@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95980 * Access another process' address space.
95981 * - source/target buffer must be kernel space
95982 */
95983-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95984+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95985 {
95986 struct mm_struct *mm;
95987
95988diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95989index f972182..e7f7c07 100644
95990--- a/mm/page-writeback.c
95991+++ b/mm/page-writeback.c
95992@@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95993 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95994 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95995 */
95996-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95997+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95998 unsigned long thresh,
95999 unsigned long bg_thresh,
96000 unsigned long dirty,
96001diff --git a/mm/page_alloc.c b/mm/page_alloc.c
96002index e98306f..3311d5e 100644
96003--- a/mm/page_alloc.c
96004+++ b/mm/page_alloc.c
96005@@ -61,6 +61,7 @@
96006 #include <linux/page-debug-flags.h>
96007 #include <linux/hugetlb.h>
96008 #include <linux/sched/rt.h>
96009+#include <linux/random.h>
96010
96011 #include <asm/sections.h>
96012 #include <asm/tlbflush.h>
96013@@ -356,7 +357,7 @@ out:
96014 * This usage means that zero-order pages may not be compound.
96015 */
96016
96017-static void free_compound_page(struct page *page)
96018+void free_compound_page(struct page *page)
96019 {
96020 __free_pages_ok(page, compound_order(page));
96021 }
96022@@ -730,6 +731,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
96023 int i;
96024 int bad = 0;
96025
96026+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96027+ unsigned long index = 1UL << order;
96028+#endif
96029+
96030 trace_mm_page_free(page, order);
96031 kmemcheck_free_shadow(page, order);
96032
96033@@ -746,6 +751,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
96034 debug_check_no_obj_freed(page_address(page),
96035 PAGE_SIZE << order);
96036 }
96037+
96038+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96039+ for (; index; --index)
96040+ sanitize_highpage(page + index - 1);
96041+#endif
96042+
96043 arch_free_page(page, order);
96044 kernel_map_pages(page, 1 << order, 0);
96045
96046@@ -768,6 +779,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
96047 local_irq_restore(flags);
96048 }
96049
96050+#ifdef CONFIG_PAX_LATENT_ENTROPY
96051+bool __meminitdata extra_latent_entropy;
96052+
96053+static int __init setup_pax_extra_latent_entropy(char *str)
96054+{
96055+ extra_latent_entropy = true;
96056+ return 0;
96057+}
96058+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
96059+
96060+volatile u64 latent_entropy __latent_entropy;
96061+EXPORT_SYMBOL(latent_entropy);
96062+#endif
96063+
96064 void __init __free_pages_bootmem(struct page *page, unsigned int order)
96065 {
96066 unsigned int nr_pages = 1 << order;
96067@@ -783,6 +808,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
96068 __ClearPageReserved(p);
96069 set_page_count(p, 0);
96070
96071+#ifdef CONFIG_PAX_LATENT_ENTROPY
96072+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
96073+ u64 hash = 0;
96074+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
96075+ const u64 *data = lowmem_page_address(page);
96076+
96077+ for (index = 0; index < end; index++)
96078+ hash ^= hash + data[index];
96079+ latent_entropy ^= hash;
96080+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
96081+ }
96082+#endif
96083+
96084 page_zone(page)->managed_pages += nr_pages;
96085 set_page_refcounted(page);
96086 __free_pages(page, order);
96087@@ -911,8 +949,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
96088 arch_alloc_page(page, order);
96089 kernel_map_pages(page, 1 << order, 1);
96090
96091+#ifndef CONFIG_PAX_MEMORY_SANITIZE
96092 if (gfp_flags & __GFP_ZERO)
96093 prep_zero_page(page, order, gfp_flags);
96094+#endif
96095
96096 if (order && (gfp_flags & __GFP_COMP))
96097 prep_compound_page(page, order);
96098@@ -2415,7 +2455,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
96099 continue;
96100 mod_zone_page_state(zone, NR_ALLOC_BATCH,
96101 high_wmark_pages(zone) - low_wmark_pages(zone) -
96102- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
96103+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
96104 }
96105 }
96106
96107diff --git a/mm/page_io.c b/mm/page_io.c
96108index 7c59ef6..1358905 100644
96109--- a/mm/page_io.c
96110+++ b/mm/page_io.c
96111@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
96112 struct file *swap_file = sis->swap_file;
96113 struct address_space *mapping = swap_file->f_mapping;
96114 struct iovec iov = {
96115- .iov_base = kmap(page),
96116+ .iov_base = (void __force_user *)kmap(page),
96117 .iov_len = PAGE_SIZE,
96118 };
96119
96120diff --git a/mm/percpu.c b/mm/percpu.c
96121index 2ddf9a9..f8fc075 100644
96122--- a/mm/percpu.c
96123+++ b/mm/percpu.c
96124@@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
96125 static unsigned int pcpu_high_unit_cpu __read_mostly;
96126
96127 /* the address of the first chunk which starts with the kernel static area */
96128-void *pcpu_base_addr __read_mostly;
96129+void *pcpu_base_addr __read_only;
96130 EXPORT_SYMBOL_GPL(pcpu_base_addr);
96131
96132 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
96133diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
96134index 8505c92..946bfc9 100644
96135--- a/mm/process_vm_access.c
96136+++ b/mm/process_vm_access.c
96137@@ -13,6 +13,7 @@
96138 #include <linux/uio.h>
96139 #include <linux/sched.h>
96140 #include <linux/highmem.h>
96141+#include <linux/security.h>
96142 #include <linux/ptrace.h>
96143 #include <linux/slab.h>
96144 #include <linux/syscalls.h>
96145@@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
96146 ssize_t iov_len;
96147 size_t total_len = iov_iter_count(iter);
96148
96149+ return -ENOSYS; // PaX: until properly audited
96150+
96151 /*
96152 * Work out how many pages of struct pages we're going to need
96153 * when eventually calling get_user_pages
96154 */
96155 for (i = 0; i < riovcnt; i++) {
96156 iov_len = rvec[i].iov_len;
96157- if (iov_len > 0) {
96158- nr_pages_iov = ((unsigned long)rvec[i].iov_base
96159- + iov_len)
96160- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
96161- / PAGE_SIZE + 1;
96162- nr_pages = max(nr_pages, nr_pages_iov);
96163- }
96164+ if (iov_len <= 0)
96165+ continue;
96166+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
96167+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
96168+ nr_pages = max(nr_pages, nr_pages_iov);
96169 }
96170
96171 if (nr_pages == 0)
96172@@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
96173 goto free_proc_pages;
96174 }
96175
96176+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
96177+ rc = -EPERM;
96178+ goto put_task_struct;
96179+ }
96180+
96181 mm = mm_access(task, PTRACE_MODE_ATTACH);
96182 if (!mm || IS_ERR(mm)) {
96183 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
96184diff --git a/mm/rmap.c b/mm/rmap.c
96185index 14d1e28..3777962 100644
96186--- a/mm/rmap.c
96187+++ b/mm/rmap.c
96188@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
96189 struct anon_vma *anon_vma = vma->anon_vma;
96190 struct anon_vma_chain *avc;
96191
96192+#ifdef CONFIG_PAX_SEGMEXEC
96193+ struct anon_vma_chain *avc_m = NULL;
96194+#endif
96195+
96196 might_sleep();
96197 if (unlikely(!anon_vma)) {
96198 struct mm_struct *mm = vma->vm_mm;
96199@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
96200 if (!avc)
96201 goto out_enomem;
96202
96203+#ifdef CONFIG_PAX_SEGMEXEC
96204+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
96205+ if (!avc_m)
96206+ goto out_enomem_free_avc;
96207+#endif
96208+
96209 anon_vma = find_mergeable_anon_vma(vma);
96210 allocated = NULL;
96211 if (!anon_vma) {
96212@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
96213 /* page_table_lock to protect against threads */
96214 spin_lock(&mm->page_table_lock);
96215 if (likely(!vma->anon_vma)) {
96216+
96217+#ifdef CONFIG_PAX_SEGMEXEC
96218+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
96219+
96220+ if (vma_m) {
96221+ BUG_ON(vma_m->anon_vma);
96222+ vma_m->anon_vma = anon_vma;
96223+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
96224+ avc_m = NULL;
96225+ }
96226+#endif
96227+
96228 vma->anon_vma = anon_vma;
96229 anon_vma_chain_link(vma, avc, anon_vma);
96230 allocated = NULL;
96231@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
96232
96233 if (unlikely(allocated))
96234 put_anon_vma(allocated);
96235+
96236+#ifdef CONFIG_PAX_SEGMEXEC
96237+ if (unlikely(avc_m))
96238+ anon_vma_chain_free(avc_m);
96239+#endif
96240+
96241 if (unlikely(avc))
96242 anon_vma_chain_free(avc);
96243 }
96244 return 0;
96245
96246 out_enomem_free_avc:
96247+
96248+#ifdef CONFIG_PAX_SEGMEXEC
96249+ if (avc_m)
96250+ anon_vma_chain_free(avc_m);
96251+#endif
96252+
96253 anon_vma_chain_free(avc);
96254 out_enomem:
96255 return -ENOMEM;
96256@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
96257 * Attach the anon_vmas from src to dst.
96258 * Returns 0 on success, -ENOMEM on failure.
96259 */
96260-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
96261+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
96262 {
96263 struct anon_vma_chain *avc, *pavc;
96264 struct anon_vma *root = NULL;
96265@@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
96266 * the corresponding VMA in the parent process is attached to.
96267 * Returns 0 on success, non-zero on failure.
96268 */
96269-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
96270+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
96271 {
96272 struct anon_vma_chain *avc;
96273 struct anon_vma *anon_vma;
96274@@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
96275 void __init anon_vma_init(void)
96276 {
96277 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
96278- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
96279- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
96280+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
96281+ anon_vma_ctor);
96282+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
96283+ SLAB_PANIC|SLAB_NO_SANITIZE);
96284 }
96285
96286 /*
96287diff --git a/mm/shmem.c b/mm/shmem.c
96288index a731cef..1e82984 100644
96289--- a/mm/shmem.c
96290+++ b/mm/shmem.c
96291@@ -33,7 +33,7 @@
96292 #include <linux/swap.h>
96293 #include <linux/aio.h>
96294
96295-static struct vfsmount *shm_mnt;
96296+struct vfsmount *shm_mnt;
96297
96298 #ifdef CONFIG_SHMEM
96299 /*
96300@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
96301 #define BOGO_DIRENT_SIZE 20
96302
96303 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
96304-#define SHORT_SYMLINK_LEN 128
96305+#define SHORT_SYMLINK_LEN 64
96306
96307 /*
96308 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
96309@@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
96310 static int shmem_xattr_validate(const char *name)
96311 {
96312 struct { const char *prefix; size_t len; } arr[] = {
96313+
96314+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96315+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
96316+#endif
96317+
96318 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
96319 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
96320 };
96321@@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
96322 if (err)
96323 return err;
96324
96325+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96326+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
96327+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
96328+ return -EOPNOTSUPP;
96329+ if (size > 8)
96330+ return -EINVAL;
96331+ }
96332+#endif
96333+
96334 return simple_xattr_set(&info->xattrs, name, value, size, flags);
96335 }
96336
96337@@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
96338 int err = -ENOMEM;
96339
96340 /* Round up to L1_CACHE_BYTES to resist false sharing */
96341- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
96342- L1_CACHE_BYTES), GFP_KERNEL);
96343+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
96344 if (!sbinfo)
96345 return -ENOMEM;
96346
96347diff --git a/mm/slab.c b/mm/slab.c
96348index 9432556..e0dc685 100644
96349--- a/mm/slab.c
96350+++ b/mm/slab.c
96351@@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96352 if ((x)->max_freeable < i) \
96353 (x)->max_freeable = i; \
96354 } while (0)
96355-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
96356-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
96357-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
96358-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
96359+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
96360+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
96361+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
96362+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
96363+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
96364+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
96365 #else
96366 #define STATS_INC_ACTIVE(x) do { } while (0)
96367 #define STATS_DEC_ACTIVE(x) do { } while (0)
96368@@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96369 #define STATS_INC_ALLOCMISS(x) do { } while (0)
96370 #define STATS_INC_FREEHIT(x) do { } while (0)
96371 #define STATS_INC_FREEMISS(x) do { } while (0)
96372+#define STATS_INC_SANITIZED(x) do { } while (0)
96373+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
96374 #endif
96375
96376 #if DEBUG
96377@@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
96378 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
96379 */
96380 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
96381- const struct page *page, void *obj)
96382+ const struct page *page, const void *obj)
96383 {
96384 u32 offset = (obj - page->s_mem);
96385 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
96386@@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
96387 */
96388
96389 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
96390- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
96391+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96392
96393 if (INDEX_AC != INDEX_NODE)
96394 kmalloc_caches[INDEX_NODE] =
96395 create_kmalloc_cache("kmalloc-node",
96396- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
96397+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96398
96399 slab_early_init = 0;
96400
96401@@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
96402 struct array_cache *ac = cpu_cache_get(cachep);
96403
96404 check_irq_off();
96405+
96406+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96407+ if (pax_sanitize_slab) {
96408+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
96409+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
96410+
96411+ if (cachep->ctor)
96412+ cachep->ctor(objp);
96413+
96414+ STATS_INC_SANITIZED(cachep);
96415+ } else
96416+ STATS_INC_NOT_SANITIZED(cachep);
96417+ }
96418+#endif
96419+
96420 kmemleak_free_recursive(objp, cachep->flags);
96421 objp = cache_free_debugcheck(cachep, objp, caller);
96422
96423@@ -3748,6 +3767,7 @@ void kfree(const void *objp)
96424
96425 if (unlikely(ZERO_OR_NULL_PTR(objp)))
96426 return;
96427+ VM_BUG_ON(!virt_addr_valid(objp));
96428 local_irq_save(flags);
96429 kfree_debugcheck(objp);
96430 c = virt_to_cache(objp);
96431@@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
96432 }
96433 /* cpu stats */
96434 {
96435- unsigned long allochit = atomic_read(&cachep->allochit);
96436- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
96437- unsigned long freehit = atomic_read(&cachep->freehit);
96438- unsigned long freemiss = atomic_read(&cachep->freemiss);
96439+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
96440+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
96441+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
96442+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
96443
96444 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
96445 allochit, allocmiss, freehit, freemiss);
96446 }
96447+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96448+ {
96449+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
96450+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
96451+
96452+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
96453+ }
96454+#endif
96455 #endif
96456 }
96457
96458@@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
96459 static int __init slab_proc_init(void)
96460 {
96461 #ifdef CONFIG_DEBUG_SLAB_LEAK
96462- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
96463+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
96464 #endif
96465 return 0;
96466 }
96467 module_init(slab_proc_init);
96468 #endif
96469
96470+bool is_usercopy_object(const void *ptr)
96471+{
96472+ struct page *page;
96473+ struct kmem_cache *cachep;
96474+
96475+ if (ZERO_OR_NULL_PTR(ptr))
96476+ return false;
96477+
96478+ if (!slab_is_available())
96479+ return false;
96480+
96481+ if (!virt_addr_valid(ptr))
96482+ return false;
96483+
96484+ page = virt_to_head_page(ptr);
96485+
96486+ if (!PageSlab(page))
96487+ return false;
96488+
96489+ cachep = page->slab_cache;
96490+ return cachep->flags & SLAB_USERCOPY;
96491+}
96492+
96493+#ifdef CONFIG_PAX_USERCOPY
96494+const char *check_heap_object(const void *ptr, unsigned long n)
96495+{
96496+ struct page *page;
96497+ struct kmem_cache *cachep;
96498+ unsigned int objnr;
96499+ unsigned long offset;
96500+
96501+ if (ZERO_OR_NULL_PTR(ptr))
96502+ return "<null>";
96503+
96504+ if (!virt_addr_valid(ptr))
96505+ return NULL;
96506+
96507+ page = virt_to_head_page(ptr);
96508+
96509+ if (!PageSlab(page))
96510+ return NULL;
96511+
96512+ cachep = page->slab_cache;
96513+ if (!(cachep->flags & SLAB_USERCOPY))
96514+ return cachep->name;
96515+
96516+ objnr = obj_to_index(cachep, page, ptr);
96517+ BUG_ON(objnr >= cachep->num);
96518+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
96519+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
96520+ return NULL;
96521+
96522+ return cachep->name;
96523+}
96524+#endif
96525+
96526 /**
96527 * ksize - get the actual amount of memory allocated for a given object
96528 * @objp: Pointer to the object
96529diff --git a/mm/slab.h b/mm/slab.h
96530index 6bd4c35..97565a1 100644
96531--- a/mm/slab.h
96532+++ b/mm/slab.h
96533@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
96534 /* The slab cache that manages slab cache information */
96535 extern struct kmem_cache *kmem_cache;
96536
96537+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96538+#ifdef CONFIG_X86_64
96539+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
96540+#else
96541+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
96542+#endif
96543+extern bool pax_sanitize_slab;
96544+#endif
96545+
96546 unsigned long calculate_alignment(unsigned long flags,
96547 unsigned long align, unsigned long size);
96548
96549@@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96550
96551 /* Legal flag mask for kmem_cache_create(), for various configurations */
96552 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
96553- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
96554+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
96555+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
96556
96557 #if defined(CONFIG_DEBUG_SLAB)
96558 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
96559@@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
96560 return s;
96561
96562 page = virt_to_head_page(x);
96563+
96564+ BUG_ON(!PageSlab(page));
96565+
96566 cachep = page->slab_cache;
96567 if (slab_equal_or_root(cachep, s))
96568 return cachep;
96569diff --git a/mm/slab_common.c b/mm/slab_common.c
96570index b810fba..ae882bf 100644
96571--- a/mm/slab_common.c
96572+++ b/mm/slab_common.c
96573@@ -23,11 +23,22 @@
96574
96575 #include "slab.h"
96576
96577-enum slab_state slab_state;
96578+enum slab_state slab_state __read_only;
96579 LIST_HEAD(slab_caches);
96580 DEFINE_MUTEX(slab_mutex);
96581 struct kmem_cache *kmem_cache;
96582
96583+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96584+bool pax_sanitize_slab __read_only = true;
96585+static int __init pax_sanitize_slab_setup(char *str)
96586+{
96587+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
96588+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
96589+ return 1;
96590+}
96591+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
96592+#endif
96593+
96594 #ifdef CONFIG_DEBUG_VM
96595 static int kmem_cache_sanity_check(const char *name, size_t size)
96596 {
96597@@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
96598 if (err)
96599 goto out_free_cache;
96600
96601- s->refcount = 1;
96602+ atomic_set(&s->refcount, 1);
96603 list_add(&s->list, &slab_caches);
96604 memcg_register_cache(s);
96605 out:
96606@@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96607 get_online_cpus();
96608 mutex_lock(&slab_mutex);
96609
96610- s->refcount--;
96611- if (s->refcount)
96612+ if (!atomic_dec_and_test(&s->refcount))
96613 goto out_unlock;
96614
96615 if (kmem_cache_destroy_memcg_children(s) != 0)
96616@@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96617 rcu_barrier();
96618
96619 memcg_free_cache_params(s);
96620-#ifdef SLAB_SUPPORTS_SYSFS
96621+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96622 sysfs_slab_remove(s);
96623 #else
96624 slab_kmem_cache_release(s);
96625@@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
96626 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
96627 name, size, err);
96628
96629- s->refcount = -1; /* Exempt from merging for now */
96630+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
96631 }
96632
96633 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96634@@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96635
96636 create_boot_cache(s, name, size, flags);
96637 list_add(&s->list, &slab_caches);
96638- s->refcount = 1;
96639+ atomic_set(&s->refcount, 1);
96640 return s;
96641 }
96642
96643@@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96644 EXPORT_SYMBOL(kmalloc_dma_caches);
96645 #endif
96646
96647+#ifdef CONFIG_PAX_USERCOPY_SLABS
96648+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96649+EXPORT_SYMBOL(kmalloc_usercopy_caches);
96650+#endif
96651+
96652 /*
96653 * Conversion table for small slabs sizes / 8 to the index in the
96654 * kmalloc array. This is necessary for slabs < 192 since we have non power
96655@@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96656 return kmalloc_dma_caches[index];
96657
96658 #endif
96659+
96660+#ifdef CONFIG_PAX_USERCOPY_SLABS
96661+ if (unlikely((flags & GFP_USERCOPY)))
96662+ return kmalloc_usercopy_caches[index];
96663+
96664+#endif
96665+
96666 return kmalloc_caches[index];
96667 }
96668
96669@@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96670 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96671 if (!kmalloc_caches[i]) {
96672 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96673- 1 << i, flags);
96674+ 1 << i, SLAB_USERCOPY | flags);
96675 }
96676
96677 /*
96678@@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96679 * earlier power of two caches
96680 */
96681 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96682- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96683+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96684
96685 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96686- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96687+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96688 }
96689
96690 /* Kmalloc array is now usable */
96691@@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96692 }
96693 }
96694 #endif
96695+
96696+#ifdef CONFIG_PAX_USERCOPY_SLABS
96697+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96698+ struct kmem_cache *s = kmalloc_caches[i];
96699+
96700+ if (s) {
96701+ int size = kmalloc_size(i);
96702+ char *n = kasprintf(GFP_NOWAIT,
96703+ "usercopy-kmalloc-%d", size);
96704+
96705+ BUG_ON(!n);
96706+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96707+ size, SLAB_USERCOPY | flags);
96708+ }
96709+ }
96710+#endif
96711+
96712 }
96713 #endif /* !CONFIG_SLOB */
96714
96715@@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96716 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96717 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96718 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96719+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96720+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
96721+#endif
96722 #endif
96723 seq_putc(m, '\n');
96724 }
96725diff --git a/mm/slob.c b/mm/slob.c
96726index 730cad4..8cfd442 100644
96727--- a/mm/slob.c
96728+++ b/mm/slob.c
96729@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96730 /*
96731 * Return the size of a slob block.
96732 */
96733-static slobidx_t slob_units(slob_t *s)
96734+static slobidx_t slob_units(const slob_t *s)
96735 {
96736 if (s->units > 0)
96737 return s->units;
96738@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96739 /*
96740 * Return the next free slob block pointer after this one.
96741 */
96742-static slob_t *slob_next(slob_t *s)
96743+static slob_t *slob_next(const slob_t *s)
96744 {
96745 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96746 slobidx_t next;
96747@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96748 /*
96749 * Returns true if s is the last free block in its page.
96750 */
96751-static int slob_last(slob_t *s)
96752+static int slob_last(const slob_t *s)
96753 {
96754 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96755 }
96756
96757-static void *slob_new_pages(gfp_t gfp, int order, int node)
96758+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96759 {
96760- void *page;
96761+ struct page *page;
96762
96763 #ifdef CONFIG_NUMA
96764 if (node != NUMA_NO_NODE)
96765@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96766 if (!page)
96767 return NULL;
96768
96769- return page_address(page);
96770+ __SetPageSlab(page);
96771+ return page;
96772 }
96773
96774-static void slob_free_pages(void *b, int order)
96775+static void slob_free_pages(struct page *sp, int order)
96776 {
96777 if (current->reclaim_state)
96778 current->reclaim_state->reclaimed_slab += 1 << order;
96779- free_pages((unsigned long)b, order);
96780+ __ClearPageSlab(sp);
96781+ page_mapcount_reset(sp);
96782+ sp->private = 0;
96783+ __free_pages(sp, order);
96784 }
96785
96786 /*
96787@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96788
96789 /* Not enough space: must allocate a new page */
96790 if (!b) {
96791- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96792- if (!b)
96793+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96794+ if (!sp)
96795 return NULL;
96796- sp = virt_to_page(b);
96797- __SetPageSlab(sp);
96798+ b = page_address(sp);
96799
96800 spin_lock_irqsave(&slob_lock, flags);
96801 sp->units = SLOB_UNITS(PAGE_SIZE);
96802 sp->freelist = b;
96803+ sp->private = 0;
96804 INIT_LIST_HEAD(&sp->lru);
96805 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96806 set_slob_page_free(sp, slob_list);
96807@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96808 if (slob_page_free(sp))
96809 clear_slob_page_free(sp);
96810 spin_unlock_irqrestore(&slob_lock, flags);
96811- __ClearPageSlab(sp);
96812- page_mapcount_reset(sp);
96813- slob_free_pages(b, 0);
96814+ slob_free_pages(sp, 0);
96815 return;
96816 }
96817
96818+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96819+ if (pax_sanitize_slab)
96820+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96821+#endif
96822+
96823 if (!slob_page_free(sp)) {
96824 /* This slob page is about to become partially free. Easy! */
96825 sp->units = units;
96826@@ -424,11 +431,10 @@ out:
96827 */
96828
96829 static __always_inline void *
96830-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96831+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96832 {
96833- unsigned int *m;
96834- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96835- void *ret;
96836+ slob_t *m;
96837+ void *ret = NULL;
96838
96839 gfp &= gfp_allowed_mask;
96840
96841@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96842
96843 if (!m)
96844 return NULL;
96845- *m = size;
96846+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96847+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96848+ m[0].units = size;
96849+ m[1].units = align;
96850 ret = (void *)m + align;
96851
96852 trace_kmalloc_node(caller, ret,
96853 size, size + align, gfp, node);
96854 } else {
96855 unsigned int order = get_order(size);
96856+ struct page *page;
96857
96858 if (likely(order))
96859 gfp |= __GFP_COMP;
96860- ret = slob_new_pages(gfp, order, node);
96861+ page = slob_new_pages(gfp, order, node);
96862+ if (page) {
96863+ ret = page_address(page);
96864+ page->private = size;
96865+ }
96866
96867 trace_kmalloc_node(caller, ret,
96868 size, PAGE_SIZE << order, gfp, node);
96869 }
96870
96871- kmemleak_alloc(ret, size, 1, gfp);
96872+ return ret;
96873+}
96874+
96875+static __always_inline void *
96876+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96877+{
96878+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96879+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96880+
96881+ if (!ZERO_OR_NULL_PTR(ret))
96882+ kmemleak_alloc(ret, size, 1, gfp);
96883 return ret;
96884 }
96885
96886@@ -493,34 +517,112 @@ void kfree(const void *block)
96887 return;
96888 kmemleak_free(block);
96889
96890+ VM_BUG_ON(!virt_addr_valid(block));
96891 sp = virt_to_page(block);
96892- if (PageSlab(sp)) {
96893+ VM_BUG_ON(!PageSlab(sp));
96894+ if (!sp->private) {
96895 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96896- unsigned int *m = (unsigned int *)(block - align);
96897- slob_free(m, *m + align);
96898- } else
96899+ slob_t *m = (slob_t *)(block - align);
96900+ slob_free(m, m[0].units + align);
96901+ } else {
96902+ __ClearPageSlab(sp);
96903+ page_mapcount_reset(sp);
96904+ sp->private = 0;
96905 __free_pages(sp, compound_order(sp));
96906+ }
96907 }
96908 EXPORT_SYMBOL(kfree);
96909
96910+bool is_usercopy_object(const void *ptr)
96911+{
96912+ if (!slab_is_available())
96913+ return false;
96914+
96915+ // PAX: TODO
96916+
96917+ return false;
96918+}
96919+
96920+#ifdef CONFIG_PAX_USERCOPY
96921+const char *check_heap_object(const void *ptr, unsigned long n)
96922+{
96923+ struct page *page;
96924+ const slob_t *free;
96925+ const void *base;
96926+ unsigned long flags;
96927+
96928+ if (ZERO_OR_NULL_PTR(ptr))
96929+ return "<null>";
96930+
96931+ if (!virt_addr_valid(ptr))
96932+ return NULL;
96933+
96934+ page = virt_to_head_page(ptr);
96935+ if (!PageSlab(page))
96936+ return NULL;
96937+
96938+ if (page->private) {
96939+ base = page;
96940+ if (base <= ptr && n <= page->private - (ptr - base))
96941+ return NULL;
96942+ return "<slob>";
96943+ }
96944+
96945+ /* some tricky double walking to find the chunk */
96946+ spin_lock_irqsave(&slob_lock, flags);
96947+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96948+ free = page->freelist;
96949+
96950+ while (!slob_last(free) && (void *)free <= ptr) {
96951+ base = free + slob_units(free);
96952+ free = slob_next(free);
96953+ }
96954+
96955+ while (base < (void *)free) {
96956+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96957+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96958+ int offset;
96959+
96960+ if (ptr < base + align)
96961+ break;
96962+
96963+ offset = ptr - base - align;
96964+ if (offset >= m) {
96965+ base += size;
96966+ continue;
96967+ }
96968+
96969+ if (n > m - offset)
96970+ break;
96971+
96972+ spin_unlock_irqrestore(&slob_lock, flags);
96973+ return NULL;
96974+ }
96975+
96976+ spin_unlock_irqrestore(&slob_lock, flags);
96977+ return "<slob>";
96978+}
96979+#endif
96980+
96981 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96982 size_t ksize(const void *block)
96983 {
96984 struct page *sp;
96985 int align;
96986- unsigned int *m;
96987+ slob_t *m;
96988
96989 BUG_ON(!block);
96990 if (unlikely(block == ZERO_SIZE_PTR))
96991 return 0;
96992
96993 sp = virt_to_page(block);
96994- if (unlikely(!PageSlab(sp)))
96995- return PAGE_SIZE << compound_order(sp);
96996+ VM_BUG_ON(!PageSlab(sp));
96997+ if (sp->private)
96998+ return sp->private;
96999
97000 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
97001- m = (unsigned int *)(block - align);
97002- return SLOB_UNITS(*m) * SLOB_UNIT;
97003+ m = (slob_t *)(block - align);
97004+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
97005 }
97006 EXPORT_SYMBOL(ksize);
97007
97008@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
97009
97010 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
97011 {
97012- void *b;
97013+ void *b = NULL;
97014
97015 flags &= gfp_allowed_mask;
97016
97017 lockdep_trace_alloc(flags);
97018
97019+#ifdef CONFIG_PAX_USERCOPY_SLABS
97020+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
97021+#else
97022 if (c->size < PAGE_SIZE) {
97023 b = slob_alloc(c->size, flags, c->align, node);
97024 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
97025 SLOB_UNITS(c->size) * SLOB_UNIT,
97026 flags, node);
97027 } else {
97028- b = slob_new_pages(flags, get_order(c->size), node);
97029+ struct page *sp;
97030+
97031+ sp = slob_new_pages(flags, get_order(c->size), node);
97032+ if (sp) {
97033+ b = page_address(sp);
97034+ sp->private = c->size;
97035+ }
97036 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
97037 PAGE_SIZE << get_order(c->size),
97038 flags, node);
97039 }
97040+#endif
97041
97042 if (b && c->ctor)
97043 c->ctor(b);
97044@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
97045
97046 static void __kmem_cache_free(void *b, int size)
97047 {
97048- if (size < PAGE_SIZE)
97049+ struct page *sp;
97050+
97051+ sp = virt_to_page(b);
97052+ BUG_ON(!PageSlab(sp));
97053+ if (!sp->private)
97054 slob_free(b, size);
97055 else
97056- slob_free_pages(b, get_order(size));
97057+ slob_free_pages(sp, get_order(size));
97058 }
97059
97060 static void kmem_rcu_free(struct rcu_head *head)
97061@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
97062
97063 void kmem_cache_free(struct kmem_cache *c, void *b)
97064 {
97065+ int size = c->size;
97066+
97067+#ifdef CONFIG_PAX_USERCOPY_SLABS
97068+ if (size + c->align < PAGE_SIZE) {
97069+ size += c->align;
97070+ b -= c->align;
97071+ }
97072+#endif
97073+
97074 kmemleak_free_recursive(b, c->flags);
97075 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
97076 struct slob_rcu *slob_rcu;
97077- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
97078- slob_rcu->size = c->size;
97079+ slob_rcu = b + (size - sizeof(struct slob_rcu));
97080+ slob_rcu->size = size;
97081 call_rcu(&slob_rcu->head, kmem_rcu_free);
97082 } else {
97083- __kmem_cache_free(b, c->size);
97084+ __kmem_cache_free(b, size);
97085 }
97086
97087+#ifdef CONFIG_PAX_USERCOPY_SLABS
97088+ trace_kfree(_RET_IP_, b);
97089+#else
97090 trace_kmem_cache_free(_RET_IP_, b);
97091+#endif
97092+
97093 }
97094 EXPORT_SYMBOL(kmem_cache_free);
97095
97096diff --git a/mm/slub.c b/mm/slub.c
97097index 2b1ce69..4a2193f 100644
97098--- a/mm/slub.c
97099+++ b/mm/slub.c
97100@@ -207,7 +207,7 @@ struct track {
97101
97102 enum track_item { TRACK_ALLOC, TRACK_FREE };
97103
97104-#ifdef CONFIG_SYSFS
97105+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97106 static int sysfs_slab_add(struct kmem_cache *);
97107 static int sysfs_slab_alias(struct kmem_cache *, const char *);
97108 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
97109@@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
97110 if (!t->addr)
97111 return;
97112
97113- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
97114+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
97115 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
97116 #ifdef CONFIG_STACKTRACE
97117 {
97118@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
97119
97120 slab_free_hook(s, x);
97121
97122+#ifdef CONFIG_PAX_MEMORY_SANITIZE
97123+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
97124+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
97125+ if (s->ctor)
97126+ s->ctor(x);
97127+ }
97128+#endif
97129+
97130 redo:
97131 /*
97132 * Determine the currently cpus per cpu slab.
97133@@ -2733,7 +2741,7 @@ static int slub_min_objects;
97134 * Merge control. If this is set then no merging of slab caches will occur.
97135 * (Could be removed. This was introduced to pacify the merge skeptics.)
97136 */
97137-static int slub_nomerge;
97138+static int slub_nomerge = 1;
97139
97140 /*
97141 * Calculate the order of allocation given an slab object size.
97142@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
97143 s->inuse = size;
97144
97145 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
97146+#ifdef CONFIG_PAX_MEMORY_SANITIZE
97147+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
97148+#endif
97149 s->ctor)) {
97150 /*
97151 * Relocate free pointer after the object if it is not
97152@@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
97153 EXPORT_SYMBOL(__kmalloc_node);
97154 #endif
97155
97156+bool is_usercopy_object(const void *ptr)
97157+{
97158+ struct page *page;
97159+ struct kmem_cache *s;
97160+
97161+ if (ZERO_OR_NULL_PTR(ptr))
97162+ return false;
97163+
97164+ if (!slab_is_available())
97165+ return false;
97166+
97167+ if (!virt_addr_valid(ptr))
97168+ return false;
97169+
97170+ page = virt_to_head_page(ptr);
97171+
97172+ if (!PageSlab(page))
97173+ return false;
97174+
97175+ s = page->slab_cache;
97176+ return s->flags & SLAB_USERCOPY;
97177+}
97178+
97179+#ifdef CONFIG_PAX_USERCOPY
97180+const char *check_heap_object(const void *ptr, unsigned long n)
97181+{
97182+ struct page *page;
97183+ struct kmem_cache *s;
97184+ unsigned long offset;
97185+
97186+ if (ZERO_OR_NULL_PTR(ptr))
97187+ return "<null>";
97188+
97189+ if (!virt_addr_valid(ptr))
97190+ return NULL;
97191+
97192+ page = virt_to_head_page(ptr);
97193+
97194+ if (!PageSlab(page))
97195+ return NULL;
97196+
97197+ s = page->slab_cache;
97198+ if (!(s->flags & SLAB_USERCOPY))
97199+ return s->name;
97200+
97201+ offset = (ptr - page_address(page)) % s->size;
97202+ if (offset <= s->object_size && n <= s->object_size - offset)
97203+ return NULL;
97204+
97205+ return s->name;
97206+}
97207+#endif
97208+
97209 size_t ksize(const void *object)
97210 {
97211 struct page *page;
97212@@ -3371,6 +3435,7 @@ void kfree(const void *x)
97213 if (unlikely(ZERO_OR_NULL_PTR(x)))
97214 return;
97215
97216+ VM_BUG_ON(!virt_addr_valid(x));
97217 page = virt_to_head_page(x);
97218 if (unlikely(!PageSlab(page))) {
97219 BUG_ON(!PageCompound(page));
97220@@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
97221 /*
97222 * We may have set a slab to be unmergeable during bootstrap.
97223 */
97224- if (s->refcount < 0)
97225+ if (atomic_read(&s->refcount) < 0)
97226 return 1;
97227
97228 return 0;
97229@@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
97230 int i;
97231 struct kmem_cache *c;
97232
97233- s->refcount++;
97234+ atomic_inc(&s->refcount);
97235
97236 /*
97237 * Adjust the object sizes so that we clear
97238@@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
97239 }
97240
97241 if (sysfs_slab_alias(s, name)) {
97242- s->refcount--;
97243+ atomic_dec(&s->refcount);
97244 s = NULL;
97245 }
97246 }
97247@@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
97248 }
97249 #endif
97250
97251-#ifdef CONFIG_SYSFS
97252+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97253 static int count_inuse(struct page *page)
97254 {
97255 return page->inuse;
97256@@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
97257 len += sprintf(buf + len, "%7ld ", l->count);
97258
97259 if (l->addr)
97260+#ifdef CONFIG_GRKERNSEC_HIDESYM
97261+ len += sprintf(buf + len, "%pS", NULL);
97262+#else
97263 len += sprintf(buf + len, "%pS", (void *)l->addr);
97264+#endif
97265 else
97266 len += sprintf(buf + len, "<not-available>");
97267
97268@@ -4261,12 +4330,12 @@ static void resiliency_test(void)
97269 validate_slab_cache(kmalloc_caches[9]);
97270 }
97271 #else
97272-#ifdef CONFIG_SYSFS
97273+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97274 static void resiliency_test(void) {};
97275 #endif
97276 #endif
97277
97278-#ifdef CONFIG_SYSFS
97279+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97280 enum slab_stat_type {
97281 SL_ALL, /* All slabs */
97282 SL_PARTIAL, /* Only partially allocated slabs */
97283@@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
97284 {
97285 if (!s->ctor)
97286 return 0;
97287+#ifdef CONFIG_GRKERNSEC_HIDESYM
97288+ return sprintf(buf, "%pS\n", NULL);
97289+#else
97290 return sprintf(buf, "%pS\n", s->ctor);
97291+#endif
97292 }
97293 SLAB_ATTR_RO(ctor);
97294
97295 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
97296 {
97297- return sprintf(buf, "%d\n", s->refcount - 1);
97298+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
97299 }
97300 SLAB_ATTR_RO(aliases);
97301
97302@@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
97303 SLAB_ATTR_RO(cache_dma);
97304 #endif
97305
97306+#ifdef CONFIG_PAX_USERCOPY_SLABS
97307+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
97308+{
97309+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
97310+}
97311+SLAB_ATTR_RO(usercopy);
97312+#endif
97313+
97314 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
97315 {
97316 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
97317@@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
97318 #ifdef CONFIG_ZONE_DMA
97319 &cache_dma_attr.attr,
97320 #endif
97321+#ifdef CONFIG_PAX_USERCOPY_SLABS
97322+ &usercopy_attr.attr,
97323+#endif
97324 #ifdef CONFIG_NUMA
97325 &remote_node_defrag_ratio_attr.attr,
97326 #endif
97327@@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
97328 return name;
97329 }
97330
97331+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97332 static int sysfs_slab_add(struct kmem_cache *s)
97333 {
97334 int err;
97335@@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
97336 kobject_del(&s->kobj);
97337 kobject_put(&s->kobj);
97338 }
97339+#endif
97340
97341 /*
97342 * Need to buffer aliases during bootup until sysfs becomes
97343@@ -5270,6 +5356,7 @@ struct saved_alias {
97344
97345 static struct saved_alias *alias_list;
97346
97347+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97348 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97349 {
97350 struct saved_alias *al;
97351@@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97352 alias_list = al;
97353 return 0;
97354 }
97355+#endif
97356
97357 static int __init slab_sysfs_init(void)
97358 {
97359diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
97360index 4cba9c2..b4f9fcc 100644
97361--- a/mm/sparse-vmemmap.c
97362+++ b/mm/sparse-vmemmap.c
97363@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
97364 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97365 if (!p)
97366 return NULL;
97367- pud_populate(&init_mm, pud, p);
97368+ pud_populate_kernel(&init_mm, pud, p);
97369 }
97370 return pud;
97371 }
97372@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
97373 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97374 if (!p)
97375 return NULL;
97376- pgd_populate(&init_mm, pgd, p);
97377+ pgd_populate_kernel(&init_mm, pgd, p);
97378 }
97379 return pgd;
97380 }
97381diff --git a/mm/sparse.c b/mm/sparse.c
97382index d1b48b6..6e8590e 100644
97383--- a/mm/sparse.c
97384+++ b/mm/sparse.c
97385@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
97386
97387 for (i = 0; i < PAGES_PER_SECTION; i++) {
97388 if (PageHWPoison(&memmap[i])) {
97389- atomic_long_sub(1, &num_poisoned_pages);
97390+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
97391 ClearPageHWPoison(&memmap[i]);
97392 }
97393 }
97394diff --git a/mm/swap.c b/mm/swap.c
97395index 9ce43ba..43bdc4c 100644
97396--- a/mm/swap.c
97397+++ b/mm/swap.c
97398@@ -31,6 +31,7 @@
97399 #include <linux/memcontrol.h>
97400 #include <linux/gfp.h>
97401 #include <linux/uio.h>
97402+#include <linux/hugetlb.h>
97403
97404 #include "internal.h"
97405
97406@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
97407
97408 __page_cache_release(page);
97409 dtor = get_compound_page_dtor(page);
97410+ if (!PageHuge(page))
97411+ BUG_ON(dtor != free_compound_page);
97412 (*dtor)(page);
97413 }
97414
97415diff --git a/mm/swapfile.c b/mm/swapfile.c
97416index 4a7f7e6..22cddf5 100644
97417--- a/mm/swapfile.c
97418+++ b/mm/swapfile.c
97419@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
97420
97421 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
97422 /* Activity counter to indicate that a swapon or swapoff has occurred */
97423-static atomic_t proc_poll_event = ATOMIC_INIT(0);
97424+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
97425
97426 static inline unsigned char swap_count(unsigned char ent)
97427 {
97428@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
97429 spin_unlock(&swap_lock);
97430
97431 err = 0;
97432- atomic_inc(&proc_poll_event);
97433+ atomic_inc_unchecked(&proc_poll_event);
97434 wake_up_interruptible(&proc_poll_wait);
97435
97436 out_dput:
97437@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
97438
97439 poll_wait(file, &proc_poll_wait, wait);
97440
97441- if (seq->poll_event != atomic_read(&proc_poll_event)) {
97442- seq->poll_event = atomic_read(&proc_poll_event);
97443+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
97444+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97445 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
97446 }
97447
97448@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
97449 return ret;
97450
97451 seq = file->private_data;
97452- seq->poll_event = atomic_read(&proc_poll_event);
97453+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97454 return 0;
97455 }
97456
97457@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
97458 (frontswap_map) ? "FS" : "");
97459
97460 mutex_unlock(&swapon_mutex);
97461- atomic_inc(&proc_poll_event);
97462+ atomic_inc_unchecked(&proc_poll_event);
97463 wake_up_interruptible(&proc_poll_wait);
97464
97465 if (S_ISREG(inode->i_mode))
97466diff --git a/mm/util.c b/mm/util.c
97467index d5ea733..e8953f9 100644
97468--- a/mm/util.c
97469+++ b/mm/util.c
97470@@ -299,6 +299,12 @@ done:
97471 void arch_pick_mmap_layout(struct mm_struct *mm)
97472 {
97473 mm->mmap_base = TASK_UNMAPPED_BASE;
97474+
97475+#ifdef CONFIG_PAX_RANDMMAP
97476+ if (mm->pax_flags & MF_PAX_RANDMMAP)
97477+ mm->mmap_base += mm->delta_mmap;
97478+#endif
97479+
97480 mm->get_unmapped_area = arch_get_unmapped_area;
97481 }
97482 #endif
97483@@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
97484 if (!mm->arg_end)
97485 goto out_mm; /* Shh! No looking before we're done */
97486
97487+ if (gr_acl_handle_procpidmem(task))
97488+ goto out_mm;
97489+
97490 len = mm->arg_end - mm->arg_start;
97491
97492 if (len > buflen)
97493diff --git a/mm/vmalloc.c b/mm/vmalloc.c
97494index bf233b2..1dfa1bc 100644
97495--- a/mm/vmalloc.c
97496+++ b/mm/vmalloc.c
97497@@ -40,6 +40,21 @@ struct vfree_deferred {
97498 };
97499 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
97500
97501+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97502+struct stack_deferred_llist {
97503+ struct llist_head list;
97504+ void *stack;
97505+ void *lowmem_stack;
97506+};
97507+
97508+struct stack_deferred {
97509+ struct stack_deferred_llist list;
97510+ struct work_struct wq;
97511+};
97512+
97513+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
97514+#endif
97515+
97516 static void __vunmap(const void *, int);
97517
97518 static void free_work(struct work_struct *w)
97519@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
97520 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
97521 struct llist_node *llnode = llist_del_all(&p->list);
97522 while (llnode) {
97523- void *p = llnode;
97524+ void *x = llnode;
97525 llnode = llist_next(llnode);
97526- __vunmap(p, 1);
97527+ __vunmap(x, 1);
97528 }
97529 }
97530
97531+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97532+static void unmap_work(struct work_struct *w)
97533+{
97534+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
97535+ struct llist_node *llnode = llist_del_all(&p->list.list);
97536+ while (llnode) {
97537+ struct stack_deferred_llist *x =
97538+ llist_entry((struct llist_head *)llnode,
97539+ struct stack_deferred_llist, list);
97540+ void *stack = ACCESS_ONCE(x->stack);
97541+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
97542+ llnode = llist_next(llnode);
97543+ __vunmap(stack, 0);
97544+ free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
97545+ }
97546+}
97547+#endif
97548+
97549 /*** Page table manipulation functions ***/
97550
97551 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97552@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97553
97554 pte = pte_offset_kernel(pmd, addr);
97555 do {
97556- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97557- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97558+
97559+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97560+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
97561+ BUG_ON(!pte_exec(*pte));
97562+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
97563+ continue;
97564+ }
97565+#endif
97566+
97567+ {
97568+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97569+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97570+ }
97571 } while (pte++, addr += PAGE_SIZE, addr != end);
97572 }
97573
97574@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
97575 pte = pte_alloc_kernel(pmd, addr);
97576 if (!pte)
97577 return -ENOMEM;
97578+
97579+ pax_open_kernel();
97580 do {
97581 struct page *page = pages[*nr];
97582
97583- if (WARN_ON(!pte_none(*pte)))
97584+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97585+ if (pgprot_val(prot) & _PAGE_NX)
97586+#endif
97587+
97588+ if (!pte_none(*pte)) {
97589+ pax_close_kernel();
97590+ WARN_ON(1);
97591 return -EBUSY;
97592- if (WARN_ON(!page))
97593+ }
97594+ if (!page) {
97595+ pax_close_kernel();
97596+ WARN_ON(1);
97597 return -ENOMEM;
97598+ }
97599 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
97600 (*nr)++;
97601 } while (pte++, addr += PAGE_SIZE, addr != end);
97602+ pax_close_kernel();
97603 return 0;
97604 }
97605
97606@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
97607 pmd_t *pmd;
97608 unsigned long next;
97609
97610- pmd = pmd_alloc(&init_mm, pud, addr);
97611+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
97612 if (!pmd)
97613 return -ENOMEM;
97614 do {
97615@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
97616 pud_t *pud;
97617 unsigned long next;
97618
97619- pud = pud_alloc(&init_mm, pgd, addr);
97620+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
97621 if (!pud)
97622 return -ENOMEM;
97623 do {
97624@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
97625 if (addr >= MODULES_VADDR && addr < MODULES_END)
97626 return 1;
97627 #endif
97628+
97629+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97630+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
97631+ return 1;
97632+#endif
97633+
97634 return is_vmalloc_addr(x);
97635 }
97636
97637@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
97638
97639 if (!pgd_none(*pgd)) {
97640 pud_t *pud = pud_offset(pgd, addr);
97641+#ifdef CONFIG_X86
97642+ if (!pud_large(*pud))
97643+#endif
97644 if (!pud_none(*pud)) {
97645 pmd_t *pmd = pmd_offset(pud, addr);
97646+#ifdef CONFIG_X86
97647+ if (!pmd_large(*pmd))
97648+#endif
97649 if (!pmd_none(*pmd)) {
97650 pte_t *ptep, pte;
97651
97652@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
97653 for_each_possible_cpu(i) {
97654 struct vmap_block_queue *vbq;
97655 struct vfree_deferred *p;
97656+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97657+ struct stack_deferred *p2;
97658+#endif
97659
97660 vbq = &per_cpu(vmap_block_queue, i);
97661 spin_lock_init(&vbq->lock);
97662 INIT_LIST_HEAD(&vbq->free);
97663+
97664 p = &per_cpu(vfree_deferred, i);
97665 init_llist_head(&p->list);
97666 INIT_WORK(&p->wq, free_work);
97667+
97668+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97669+ p2 = &per_cpu(stack_deferred, i);
97670+ init_llist_head(&p2->list.list);
97671+ INIT_WORK(&p2->wq, unmap_work);
97672+#endif
97673 }
97674
97675 /* Import existing vmlist entries. */
97676@@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97677 struct vm_struct *area;
97678
97679 BUG_ON(in_interrupt());
97680+
97681+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97682+ if (flags & VM_KERNEXEC) {
97683+ if (start != VMALLOC_START || end != VMALLOC_END)
97684+ return NULL;
97685+ start = (unsigned long)MODULES_EXEC_VADDR;
97686+ end = (unsigned long)MODULES_EXEC_END;
97687+ }
97688+#endif
97689+
97690 if (flags & VM_IOREMAP)
97691 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97692
97693@@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
97694 }
97695 EXPORT_SYMBOL(vunmap);
97696
97697+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97698+void unmap_process_stacks(struct task_struct *task)
97699+{
97700+ if (unlikely(in_interrupt())) {
97701+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
97702+ struct stack_deferred_llist *list = task->stack;
97703+ list->stack = task->stack;
97704+ list->lowmem_stack = task->lowmem_stack;
97705+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
97706+ schedule_work(&p->wq);
97707+ } else {
97708+ __vunmap(task->stack, 0);
97709+ free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97710+ }
97711+}
97712+#endif
97713+
97714 /**
97715 * vmap - map an array of pages into virtually contiguous space
97716 * @pages: array of page pointers
97717@@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97718 if (count > totalram_pages)
97719 return NULL;
97720
97721+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97722+ if (!(pgprot_val(prot) & _PAGE_NX))
97723+ flags |= VM_KERNEXEC;
97724+#endif
97725+
97726 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97727 __builtin_return_address(0));
97728 if (!area)
97729@@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97730 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97731 goto fail;
97732
97733+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97734+ if (!(pgprot_val(prot) & _PAGE_NX))
97735+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97736+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97737+ else
97738+#endif
97739+
97740 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97741 start, end, node, gfp_mask, caller);
97742 if (!area)
97743@@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97744 * For tight control over page level allocator and protection flags
97745 * use __vmalloc() instead.
97746 */
97747-
97748 void *vmalloc_exec(unsigned long size)
97749 {
97750- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97751+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97752 NUMA_NO_NODE, __builtin_return_address(0));
97753 }
97754
97755@@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97756 {
97757 struct vm_struct *area;
97758
97759+ BUG_ON(vma->vm_mirror);
97760+
97761 size = PAGE_ALIGN(size);
97762
97763 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97764@@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97765 v->addr, v->addr + v->size, v->size);
97766
97767 if (v->caller)
97768+#ifdef CONFIG_GRKERNSEC_HIDESYM
97769+ seq_printf(m, " %pK", v->caller);
97770+#else
97771 seq_printf(m, " %pS", v->caller);
97772+#endif
97773
97774 if (v->nr_pages)
97775 seq_printf(m, " pages=%d", v->nr_pages);
97776diff --git a/mm/vmstat.c b/mm/vmstat.c
97777index 302dd07..3841f1c 100644
97778--- a/mm/vmstat.c
97779+++ b/mm/vmstat.c
97780@@ -20,6 +20,7 @@
97781 #include <linux/writeback.h>
97782 #include <linux/compaction.h>
97783 #include <linux/mm_inline.h>
97784+#include <linux/grsecurity.h>
97785
97786 #include "internal.h"
97787
97788@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97789 *
97790 * vm_stat contains the global counters
97791 */
97792-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97793+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97794 EXPORT_SYMBOL(vm_stat);
97795
97796 #ifdef CONFIG_SMP
97797@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97798
97799 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97800 if (diff[i])
97801- atomic_long_add(diff[i], &vm_stat[i]);
97802+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97803 }
97804
97805 /*
97806@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97807 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97808 if (v) {
97809
97810- atomic_long_add(v, &zone->vm_stat[i]);
97811+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97812 global_diff[i] += v;
97813 #ifdef CONFIG_NUMA
97814 /* 3 seconds idle till flush */
97815@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97816
97817 v = p->vm_stat_diff[i];
97818 p->vm_stat_diff[i] = 0;
97819- atomic_long_add(v, &zone->vm_stat[i]);
97820+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97821 global_diff[i] += v;
97822 }
97823 }
97824@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97825 if (pset->vm_stat_diff[i]) {
97826 int v = pset->vm_stat_diff[i];
97827 pset->vm_stat_diff[i] = 0;
97828- atomic_long_add(v, &zone->vm_stat[i]);
97829- atomic_long_add(v, &vm_stat[i]);
97830+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97831+ atomic_long_add_unchecked(v, &vm_stat[i]);
97832 }
97833 }
97834 #endif
97835@@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97836 stat_items_size += sizeof(struct vm_event_state);
97837 #endif
97838
97839- v = kmalloc(stat_items_size, GFP_KERNEL);
97840+ v = kzalloc(stat_items_size, GFP_KERNEL);
97841 m->private = v;
97842 if (!v)
97843 return ERR_PTR(-ENOMEM);
97844+
97845+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97846+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97847+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97848+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97849+ && !in_group_p(grsec_proc_gid)
97850+#endif
97851+ )
97852+ return (unsigned long *)m->private + *pos;
97853+#endif
97854+#endif
97855+
97856 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97857 v[i] = global_page_state(i);
97858 v += NR_VM_ZONE_STAT_ITEMS;
97859@@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97860 cpu_notifier_register_done();
97861 #endif
97862 #ifdef CONFIG_PROC_FS
97863- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97864- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97865- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97866- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97867+ {
97868+ mode_t gr_mode = S_IRUGO;
97869+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97870+ gr_mode = S_IRUSR;
97871+#endif
97872+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97873+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97874+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97875+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97876+ }
97877 #endif
97878 return 0;
97879 }
97880diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97881index 44ebd5c..1f732bae 100644
97882--- a/net/8021q/vlan.c
97883+++ b/net/8021q/vlan.c
97884@@ -475,7 +475,7 @@ out:
97885 return NOTIFY_DONE;
97886 }
97887
97888-static struct notifier_block vlan_notifier_block __read_mostly = {
97889+static struct notifier_block vlan_notifier_block = {
97890 .notifier_call = vlan_device_event,
97891 };
97892
97893@@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97894 err = -EPERM;
97895 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97896 break;
97897- if ((args.u.name_type >= 0) &&
97898- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97899+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97900 struct vlan_net *vn;
97901
97902 vn = net_generic(net, vlan_net_id);
97903diff --git a/net/9p/client.c b/net/9p/client.c
97904index 0004cba..feba240 100644
97905--- a/net/9p/client.c
97906+++ b/net/9p/client.c
97907@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97908 len - inline_len);
97909 } else {
97910 err = copy_from_user(ename + inline_len,
97911- uidata, len - inline_len);
97912+ (char __force_user *)uidata, len - inline_len);
97913 if (err) {
97914 err = -EFAULT;
97915 goto out_err;
97916@@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97917 kernel_buf = 1;
97918 indata = data;
97919 } else
97920- indata = (__force char *)udata;
97921+ indata = (__force_kernel char *)udata;
97922 /*
97923 * response header len is 11
97924 * PDU Header(7) + IO Size (4)
97925@@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97926 kernel_buf = 1;
97927 odata = data;
97928 } else
97929- odata = (char *)udata;
97930+ odata = (char __force_kernel *)udata;
97931 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97932 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97933 fid->fid, offset, rsize);
97934diff --git a/net/9p/mod.c b/net/9p/mod.c
97935index 6ab36ae..6f1841b 100644
97936--- a/net/9p/mod.c
97937+++ b/net/9p/mod.c
97938@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97939 void v9fs_register_trans(struct p9_trans_module *m)
97940 {
97941 spin_lock(&v9fs_trans_lock);
97942- list_add_tail(&m->list, &v9fs_trans_list);
97943+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97944 spin_unlock(&v9fs_trans_lock);
97945 }
97946 EXPORT_SYMBOL(v9fs_register_trans);
97947@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97948 void v9fs_unregister_trans(struct p9_trans_module *m)
97949 {
97950 spin_lock(&v9fs_trans_lock);
97951- list_del_init(&m->list);
97952+ pax_list_del_init((struct list_head *)&m->list);
97953 spin_unlock(&v9fs_trans_lock);
97954 }
97955 EXPORT_SYMBOL(v9fs_unregister_trans);
97956diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97957index 80d08f6..de63fd1 100644
97958--- a/net/9p/trans_fd.c
97959+++ b/net/9p/trans_fd.c
97960@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97961 oldfs = get_fs();
97962 set_fs(get_ds());
97963 /* The cast to a user pointer is valid due to the set_fs() */
97964- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97965+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97966 set_fs(oldfs);
97967
97968 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97969diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97970index af46bc4..f9adfcd 100644
97971--- a/net/appletalk/atalk_proc.c
97972+++ b/net/appletalk/atalk_proc.c
97973@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97974 struct proc_dir_entry *p;
97975 int rc = -ENOMEM;
97976
97977- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97978+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97979 if (!atalk_proc_dir)
97980 goto out;
97981
97982diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97983index 876fbe8..8bbea9f 100644
97984--- a/net/atm/atm_misc.c
97985+++ b/net/atm/atm_misc.c
97986@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97987 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97988 return 1;
97989 atm_return(vcc, truesize);
97990- atomic_inc(&vcc->stats->rx_drop);
97991+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97992 return 0;
97993 }
97994 EXPORT_SYMBOL(atm_charge);
97995@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97996 }
97997 }
97998 atm_return(vcc, guess);
97999- atomic_inc(&vcc->stats->rx_drop);
98000+ atomic_inc_unchecked(&vcc->stats->rx_drop);
98001 return NULL;
98002 }
98003 EXPORT_SYMBOL(atm_alloc_charge);
98004@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
98005
98006 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
98007 {
98008-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
98009+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
98010 __SONET_ITEMS
98011 #undef __HANDLE_ITEM
98012 }
98013@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
98014
98015 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
98016 {
98017-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
98018+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
98019 __SONET_ITEMS
98020 #undef __HANDLE_ITEM
98021 }
98022diff --git a/net/atm/lec.c b/net/atm/lec.c
98023index 4c5b8ba..95f7005 100644
98024--- a/net/atm/lec.c
98025+++ b/net/atm/lec.c
98026@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
98027 }
98028
98029 static struct lane2_ops lane2_ops = {
98030- lane2_resolve, /* resolve, spec 3.1.3 */
98031- lane2_associate_req, /* associate_req, spec 3.1.4 */
98032- NULL /* associate indicator, spec 3.1.5 */
98033+ .resolve = lane2_resolve,
98034+ .associate_req = lane2_associate_req,
98035+ .associate_indicator = NULL
98036 };
98037
98038 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
98039diff --git a/net/atm/lec.h b/net/atm/lec.h
98040index 4149db1..f2ab682 100644
98041--- a/net/atm/lec.h
98042+++ b/net/atm/lec.h
98043@@ -48,7 +48,7 @@ struct lane2_ops {
98044 const u8 *tlvs, u32 sizeoftlvs);
98045 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
98046 const u8 *tlvs, u32 sizeoftlvs);
98047-};
98048+} __no_const;
98049
98050 /*
98051 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
98052diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
98053index d1b2d9a..d549f7f 100644
98054--- a/net/atm/mpoa_caches.c
98055+++ b/net/atm/mpoa_caches.c
98056@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
98057
98058
98059 static struct in_cache_ops ingress_ops = {
98060- in_cache_add_entry, /* add_entry */
98061- in_cache_get, /* get */
98062- in_cache_get_with_mask, /* get_with_mask */
98063- in_cache_get_by_vcc, /* get_by_vcc */
98064- in_cache_put, /* put */
98065- in_cache_remove_entry, /* remove_entry */
98066- cache_hit, /* cache_hit */
98067- clear_count_and_expired, /* clear_count */
98068- check_resolving_entries, /* check_resolving */
98069- refresh_entries, /* refresh */
98070- in_destroy_cache /* destroy_cache */
98071+ .add_entry = in_cache_add_entry,
98072+ .get = in_cache_get,
98073+ .get_with_mask = in_cache_get_with_mask,
98074+ .get_by_vcc = in_cache_get_by_vcc,
98075+ .put = in_cache_put,
98076+ .remove_entry = in_cache_remove_entry,
98077+ .cache_hit = cache_hit,
98078+ .clear_count = clear_count_and_expired,
98079+ .check_resolving = check_resolving_entries,
98080+ .refresh = refresh_entries,
98081+ .destroy_cache = in_destroy_cache
98082 };
98083
98084 static struct eg_cache_ops egress_ops = {
98085- eg_cache_add_entry, /* add_entry */
98086- eg_cache_get_by_cache_id, /* get_by_cache_id */
98087- eg_cache_get_by_tag, /* get_by_tag */
98088- eg_cache_get_by_vcc, /* get_by_vcc */
98089- eg_cache_get_by_src_ip, /* get_by_src_ip */
98090- eg_cache_put, /* put */
98091- eg_cache_remove_entry, /* remove_entry */
98092- update_eg_cache_entry, /* update */
98093- clear_expired, /* clear_expired */
98094- eg_destroy_cache /* destroy_cache */
98095+ .add_entry = eg_cache_add_entry,
98096+ .get_by_cache_id = eg_cache_get_by_cache_id,
98097+ .get_by_tag = eg_cache_get_by_tag,
98098+ .get_by_vcc = eg_cache_get_by_vcc,
98099+ .get_by_src_ip = eg_cache_get_by_src_ip,
98100+ .put = eg_cache_put,
98101+ .remove_entry = eg_cache_remove_entry,
98102+ .update = update_eg_cache_entry,
98103+ .clear_expired = clear_expired,
98104+ .destroy_cache = eg_destroy_cache
98105 };
98106
98107
98108diff --git a/net/atm/proc.c b/net/atm/proc.c
98109index bbb6461..cf04016 100644
98110--- a/net/atm/proc.c
98111+++ b/net/atm/proc.c
98112@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
98113 const struct k_atm_aal_stats *stats)
98114 {
98115 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
98116- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
98117- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
98118- atomic_read(&stats->rx_drop));
98119+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
98120+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
98121+ atomic_read_unchecked(&stats->rx_drop));
98122 }
98123
98124 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
98125diff --git a/net/atm/resources.c b/net/atm/resources.c
98126index 0447d5d..3cf4728 100644
98127--- a/net/atm/resources.c
98128+++ b/net/atm/resources.c
98129@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
98130 static void copy_aal_stats(struct k_atm_aal_stats *from,
98131 struct atm_aal_stats *to)
98132 {
98133-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
98134+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
98135 __AAL_STAT_ITEMS
98136 #undef __HANDLE_ITEM
98137 }
98138@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
98139 static void subtract_aal_stats(struct k_atm_aal_stats *from,
98140 struct atm_aal_stats *to)
98141 {
98142-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
98143+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
98144 __AAL_STAT_ITEMS
98145 #undef __HANDLE_ITEM
98146 }
98147diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
98148index 919a5ce..cc6b444 100644
98149--- a/net/ax25/sysctl_net_ax25.c
98150+++ b/net/ax25/sysctl_net_ax25.c
98151@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
98152 {
98153 char path[sizeof("net/ax25/") + IFNAMSIZ];
98154 int k;
98155- struct ctl_table *table;
98156+ ctl_table_no_const *table;
98157
98158 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
98159 if (!table)
98160diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
98161index f04224c..f326579 100644
98162--- a/net/batman-adv/bat_iv_ogm.c
98163+++ b/net/batman-adv/bat_iv_ogm.c
98164@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
98165
98166 /* randomize initial seqno to avoid collision */
98167 get_random_bytes(&random_seqno, sizeof(random_seqno));
98168- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
98169+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
98170
98171 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
98172 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
98173@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
98174 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
98175
98176 /* change sequence number to network order */
98177- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
98178+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
98179 batadv_ogm_packet->seqno = htonl(seqno);
98180- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
98181+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
98182
98183 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
98184
98185@@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
98186 return;
98187
98188 /* could be changed by schedule_own_packet() */
98189- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
98190+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
98191
98192 if (ogm_packet->flags & BATADV_DIRECTLINK)
98193 has_directlink_flag = true;
98194diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
98195index 022d18a..919daff 100644
98196--- a/net/batman-adv/fragmentation.c
98197+++ b/net/batman-adv/fragmentation.c
98198@@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
98199 frag_header.packet_type = BATADV_UNICAST_FRAG;
98200 frag_header.version = BATADV_COMPAT_VERSION;
98201 frag_header.ttl = BATADV_TTL;
98202- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
98203+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
98204 frag_header.reserved = 0;
98205 frag_header.no = 0;
98206 frag_header.total_size = htons(skb->len);
98207diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
98208index 744a59b..8fd037c 100644
98209--- a/net/batman-adv/soft-interface.c
98210+++ b/net/batman-adv/soft-interface.c
98211@@ -296,7 +296,7 @@ send:
98212 primary_if->net_dev->dev_addr);
98213
98214 /* set broadcast sequence number */
98215- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
98216+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
98217 bcast_packet->seqno = htonl(seqno);
98218
98219 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
98220@@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
98221 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
98222
98223 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
98224- atomic_set(&bat_priv->bcast_seqno, 1);
98225+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
98226 atomic_set(&bat_priv->tt.vn, 0);
98227 atomic_set(&bat_priv->tt.local_changes, 0);
98228 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
98229@@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
98230
98231 /* randomize initial seqno to avoid collision */
98232 get_random_bytes(&random_seqno, sizeof(random_seqno));
98233- atomic_set(&bat_priv->frag_seqno, random_seqno);
98234+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
98235
98236 bat_priv->primary_if = NULL;
98237 bat_priv->num_ifaces = 0;
98238diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
98239index 34891a5..3cfece0 100644
98240--- a/net/batman-adv/types.h
98241+++ b/net/batman-adv/types.h
98242@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
98243 struct batadv_hard_iface_bat_iv {
98244 unsigned char *ogm_buff;
98245 int ogm_buff_len;
98246- atomic_t ogm_seqno;
98247+ atomic_unchecked_t ogm_seqno;
98248 };
98249
98250 /**
98251@@ -766,7 +766,7 @@ struct batadv_priv {
98252 atomic_t bonding;
98253 atomic_t fragmentation;
98254 atomic_t packet_size_max;
98255- atomic_t frag_seqno;
98256+ atomic_unchecked_t frag_seqno;
98257 #ifdef CONFIG_BATMAN_ADV_BLA
98258 atomic_t bridge_loop_avoidance;
98259 #endif
98260@@ -785,7 +785,7 @@ struct batadv_priv {
98261 #endif
98262 uint32_t isolation_mark;
98263 uint32_t isolation_mark_mask;
98264- atomic_t bcast_seqno;
98265+ atomic_unchecked_t bcast_seqno;
98266 atomic_t bcast_queue_left;
98267 atomic_t batman_queue_left;
98268 char num_ifaces;
98269diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
98270index b9a418e..2af862a 100644
98271--- a/net/bluetooth/hci_sock.c
98272+++ b/net/bluetooth/hci_sock.c
98273@@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
98274 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
98275 }
98276
98277- len = min_t(unsigned int, len, sizeof(uf));
98278+ len = min((size_t)len, sizeof(uf));
98279 if (copy_from_user(&uf, optval, len)) {
98280 err = -EFAULT;
98281 break;
98282diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
98283index 1c97b7a..9171d69 100644
98284--- a/net/bluetooth/l2cap_core.c
98285+++ b/net/bluetooth/l2cap_core.c
98286@@ -3542,8 +3542,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
98287 break;
98288
98289 case L2CAP_CONF_RFC:
98290- if (olen == sizeof(rfc))
98291- memcpy(&rfc, (void *)val, olen);
98292+ if (olen != sizeof(rfc))
98293+ break;
98294+
98295+ memcpy(&rfc, (void *)val, olen);
98296
98297 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
98298 rfc.mode != chan->mode)
98299diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
98300index e137869..33f3ebd 100644
98301--- a/net/bluetooth/l2cap_sock.c
98302+++ b/net/bluetooth/l2cap_sock.c
98303@@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98304 struct sock *sk = sock->sk;
98305 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
98306 struct l2cap_options opts;
98307- int len, err = 0;
98308+ int err = 0;
98309+ size_t len = optlen;
98310 u32 opt;
98311
98312 BT_DBG("sk %p", sk);
98313@@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98314 opts.max_tx = chan->max_tx;
98315 opts.txwin_size = chan->tx_win;
98316
98317- len = min_t(unsigned int, sizeof(opts), optlen);
98318+ len = min(sizeof(opts), len);
98319 if (copy_from_user((char *) &opts, optval, len)) {
98320 err = -EFAULT;
98321 break;
98322@@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98323 struct bt_security sec;
98324 struct bt_power pwr;
98325 struct l2cap_conn *conn;
98326- int len, err = 0;
98327+ int err = 0;
98328+ size_t len = optlen;
98329 u32 opt;
98330
98331 BT_DBG("sk %p", sk);
98332@@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98333
98334 sec.level = BT_SECURITY_LOW;
98335
98336- len = min_t(unsigned int, sizeof(sec), optlen);
98337+ len = min(sizeof(sec), len);
98338 if (copy_from_user((char *) &sec, optval, len)) {
98339 err = -EFAULT;
98340 break;
98341@@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98342
98343 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
98344
98345- len = min_t(unsigned int, sizeof(pwr), optlen);
98346+ len = min(sizeof(pwr), len);
98347 if (copy_from_user((char *) &pwr, optval, len)) {
98348 err = -EFAULT;
98349 break;
98350diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
98351index c603a5e..7f08991 100644
98352--- a/net/bluetooth/rfcomm/sock.c
98353+++ b/net/bluetooth/rfcomm/sock.c
98354@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98355 struct sock *sk = sock->sk;
98356 struct bt_security sec;
98357 int err = 0;
98358- size_t len;
98359+ size_t len = optlen;
98360 u32 opt;
98361
98362 BT_DBG("sk %p", sk);
98363@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98364
98365 sec.level = BT_SECURITY_LOW;
98366
98367- len = min_t(unsigned int, sizeof(sec), optlen);
98368+ len = min(sizeof(sec), len);
98369 if (copy_from_user((char *) &sec, optval, len)) {
98370 err = -EFAULT;
98371 break;
98372diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
98373index 403ec09..a21a003 100644
98374--- a/net/bluetooth/rfcomm/tty.c
98375+++ b/net/bluetooth/rfcomm/tty.c
98376@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
98377 BT_DBG("tty %p id %d", tty, tty->index);
98378
98379 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
98380- dev->channel, dev->port.count);
98381+ dev->channel, atomic_read(&dev->port.count));
98382
98383 err = tty_port_open(&dev->port, tty, filp);
98384 if (err)
98385@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
98386 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
98387
98388 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
98389- dev->port.count);
98390+ atomic_read(&dev->port.count));
98391
98392 tty_port_close(&dev->port, tty, filp);
98393 }
98394diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
98395index 1059ed3..d70846a 100644
98396--- a/net/bridge/netfilter/ebtables.c
98397+++ b/net/bridge/netfilter/ebtables.c
98398@@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98399 tmp.valid_hooks = t->table->valid_hooks;
98400 }
98401 mutex_unlock(&ebt_mutex);
98402- if (copy_to_user(user, &tmp, *len) != 0) {
98403+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98404 BUGPRINT("c2u Didn't work\n");
98405 ret = -EFAULT;
98406 break;
98407@@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98408 goto out;
98409 tmp.valid_hooks = t->valid_hooks;
98410
98411- if (copy_to_user(user, &tmp, *len) != 0) {
98412+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98413 ret = -EFAULT;
98414 break;
98415 }
98416@@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98417 tmp.entries_size = t->table->entries_size;
98418 tmp.valid_hooks = t->table->valid_hooks;
98419
98420- if (copy_to_user(user, &tmp, *len) != 0) {
98421+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98422 ret = -EFAULT;
98423 break;
98424 }
98425diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
98426index 0f45522..dab651f 100644
98427--- a/net/caif/cfctrl.c
98428+++ b/net/caif/cfctrl.c
98429@@ -10,6 +10,7 @@
98430 #include <linux/spinlock.h>
98431 #include <linux/slab.h>
98432 #include <linux/pkt_sched.h>
98433+#include <linux/sched.h>
98434 #include <net/caif/caif_layer.h>
98435 #include <net/caif/cfpkt.h>
98436 #include <net/caif/cfctrl.h>
98437@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
98438 memset(&dev_info, 0, sizeof(dev_info));
98439 dev_info.id = 0xff;
98440 cfsrvl_init(&this->serv, 0, &dev_info, false);
98441- atomic_set(&this->req_seq_no, 1);
98442- atomic_set(&this->rsp_seq_no, 1);
98443+ atomic_set_unchecked(&this->req_seq_no, 1);
98444+ atomic_set_unchecked(&this->rsp_seq_no, 1);
98445 this->serv.layer.receive = cfctrl_recv;
98446 sprintf(this->serv.layer.name, "ctrl");
98447 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
98448@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
98449 struct cfctrl_request_info *req)
98450 {
98451 spin_lock_bh(&ctrl->info_list_lock);
98452- atomic_inc(&ctrl->req_seq_no);
98453- req->sequence_no = atomic_read(&ctrl->req_seq_no);
98454+ atomic_inc_unchecked(&ctrl->req_seq_no);
98455+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
98456 list_add_tail(&req->list, &ctrl->list);
98457 spin_unlock_bh(&ctrl->info_list_lock);
98458 }
98459@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
98460 if (p != first)
98461 pr_warn("Requests are not received in order\n");
98462
98463- atomic_set(&ctrl->rsp_seq_no,
98464+ atomic_set_unchecked(&ctrl->rsp_seq_no,
98465 p->sequence_no);
98466 list_del(&p->list);
98467 goto out;
98468diff --git a/net/can/af_can.c b/net/can/af_can.c
98469index a27f8aa..67174a3 100644
98470--- a/net/can/af_can.c
98471+++ b/net/can/af_can.c
98472@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
98473 };
98474
98475 /* notifier block for netdevice event */
98476-static struct notifier_block can_netdev_notifier __read_mostly = {
98477+static struct notifier_block can_netdev_notifier = {
98478 .notifier_call = can_notifier,
98479 };
98480
98481diff --git a/net/can/bcm.c b/net/can/bcm.c
98482index dcb75c0..24b1b43 100644
98483--- a/net/can/bcm.c
98484+++ b/net/can/bcm.c
98485@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
98486 }
98487
98488 /* create /proc/net/can-bcm directory */
98489- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
98490+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
98491 return 0;
98492 }
98493
98494diff --git a/net/can/gw.c b/net/can/gw.c
98495index 050a211..bb9fe33 100644
98496--- a/net/can/gw.c
98497+++ b/net/can/gw.c
98498@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
98499 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
98500
98501 static HLIST_HEAD(cgw_list);
98502-static struct notifier_block notifier;
98503
98504 static struct kmem_cache *cgw_cache __read_mostly;
98505
98506@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
98507 return err;
98508 }
98509
98510+static struct notifier_block notifier = {
98511+ .notifier_call = cgw_notifier
98512+};
98513+
98514 static __init int cgw_module_init(void)
98515 {
98516 /* sanitize given module parameter */
98517@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
98518 return -ENOMEM;
98519
98520 /* set notifier */
98521- notifier.notifier_call = cgw_notifier;
98522 register_netdevice_notifier(&notifier);
98523
98524 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
98525diff --git a/net/can/proc.c b/net/can/proc.c
98526index b543470..d2ddae2 100644
98527--- a/net/can/proc.c
98528+++ b/net/can/proc.c
98529@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
98530 void can_init_proc(void)
98531 {
98532 /* create /proc/net/can directory */
98533- can_dir = proc_mkdir("can", init_net.proc_net);
98534+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
98535
98536 if (!can_dir) {
98537 printk(KERN_INFO "can: failed to create /proc/net/can . "
98538diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
98539index 1948d59..9e854d5 100644
98540--- a/net/ceph/messenger.c
98541+++ b/net/ceph/messenger.c
98542@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
98543 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
98544
98545 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
98546-static atomic_t addr_str_seq = ATOMIC_INIT(0);
98547+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
98548
98549 static struct page *zero_page; /* used in certain error cases */
98550
98551@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
98552 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
98553 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
98554
98555- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98556+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98557 s = addr_str[i];
98558
98559 switch (ss->ss_family) {
98560diff --git a/net/compat.c b/net/compat.c
98561index bc8aeef..f9c070c 100644
98562--- a/net/compat.c
98563+++ b/net/compat.c
98564@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
98565 return -EFAULT;
98566 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
98567 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
98568- kmsg->msg_name = compat_ptr(tmp1);
98569- kmsg->msg_iov = compat_ptr(tmp2);
98570- kmsg->msg_control = compat_ptr(tmp3);
98571+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
98572+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
98573+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
98574 return 0;
98575 }
98576
98577@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98578
98579 if (kern_msg->msg_name && kern_msg->msg_namelen) {
98580 if (mode == VERIFY_READ) {
98581- int err = move_addr_to_kernel(kern_msg->msg_name,
98582+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
98583 kern_msg->msg_namelen,
98584 kern_address);
98585 if (err < 0)
98586@@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98587 }
98588
98589 tot_len = iov_from_user_compat_to_kern(kern_iov,
98590- (struct compat_iovec __user *)kern_msg->msg_iov,
98591+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
98592 kern_msg->msg_iovlen);
98593 if (tot_len >= 0)
98594 kern_msg->msg_iov = kern_iov;
98595@@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98596
98597 #define CMSG_COMPAT_FIRSTHDR(msg) \
98598 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
98599- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
98600+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
98601 (struct compat_cmsghdr __user *)NULL)
98602
98603 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
98604 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
98605 (ucmlen) <= (unsigned long) \
98606 ((mhdr)->msg_controllen - \
98607- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
98608+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
98609
98610 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
98611 struct compat_cmsghdr __user *cmsg, int cmsg_len)
98612 {
98613 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
98614- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
98615+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
98616 msg->msg_controllen)
98617 return NULL;
98618 return (struct compat_cmsghdr __user *)ptr;
98619@@ -223,7 +223,7 @@ Efault:
98620
98621 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
98622 {
98623- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98624+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98625 struct compat_cmsghdr cmhdr;
98626 struct compat_timeval ctv;
98627 struct compat_timespec cts[3];
98628@@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
98629
98630 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
98631 {
98632- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98633+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98634 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
98635 int fdnum = scm->fp->count;
98636 struct file **fp = scm->fp->fp;
98637@@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
98638 return -EFAULT;
98639 old_fs = get_fs();
98640 set_fs(KERNEL_DS);
98641- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
98642+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
98643 set_fs(old_fs);
98644
98645 return err;
98646@@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98647 len = sizeof(ktime);
98648 old_fs = get_fs();
98649 set_fs(KERNEL_DS);
98650- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98651+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98652 set_fs(old_fs);
98653
98654 if (!err) {
98655@@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98656 case MCAST_JOIN_GROUP:
98657 case MCAST_LEAVE_GROUP:
98658 {
98659- struct compat_group_req __user *gr32 = (void *)optval;
98660+ struct compat_group_req __user *gr32 = (void __user *)optval;
98661 struct group_req __user *kgr =
98662 compat_alloc_user_space(sizeof(struct group_req));
98663 u32 interface;
98664@@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98665 case MCAST_BLOCK_SOURCE:
98666 case MCAST_UNBLOCK_SOURCE:
98667 {
98668- struct compat_group_source_req __user *gsr32 = (void *)optval;
98669+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98670 struct group_source_req __user *kgsr = compat_alloc_user_space(
98671 sizeof(struct group_source_req));
98672 u32 interface;
98673@@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98674 }
98675 case MCAST_MSFILTER:
98676 {
98677- struct compat_group_filter __user *gf32 = (void *)optval;
98678+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98679 struct group_filter __user *kgf;
98680 u32 interface, fmode, numsrc;
98681
98682@@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98683 char __user *optval, int __user *optlen,
98684 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98685 {
98686- struct compat_group_filter __user *gf32 = (void *)optval;
98687+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98688 struct group_filter __user *kgf;
98689 int __user *koptlen;
98690 u32 interface, fmode, numsrc;
98691@@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
98692
98693 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98694 return -EINVAL;
98695- if (copy_from_user(a, args, nas[call]))
98696+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98697 return -EFAULT;
98698 a0 = a[0];
98699 a1 = a[1];
98700diff --git a/net/core/datagram.c b/net/core/datagram.c
98701index a16ed7b..eb44d17 100644
98702--- a/net/core/datagram.c
98703+++ b/net/core/datagram.c
98704@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98705 }
98706
98707 kfree_skb(skb);
98708- atomic_inc(&sk->sk_drops);
98709+ atomic_inc_unchecked(&sk->sk_drops);
98710 sk_mem_reclaim_partial(sk);
98711
98712 return err;
98713diff --git a/net/core/dev.c b/net/core/dev.c
98714index a7621f3..ca7dac3 100644
98715--- a/net/core/dev.c
98716+++ b/net/core/dev.c
98717@@ -1690,14 +1690,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98718 {
98719 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98720 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98721- atomic_long_inc(&dev->rx_dropped);
98722+ atomic_long_inc_unchecked(&dev->rx_dropped);
98723 kfree_skb(skb);
98724 return NET_RX_DROP;
98725 }
98726 }
98727
98728 if (unlikely(!is_skb_forwardable(dev, skb))) {
98729- atomic_long_inc(&dev->rx_dropped);
98730+ atomic_long_inc_unchecked(&dev->rx_dropped);
98731 kfree_skb(skb);
98732 return NET_RX_DROP;
98733 }
98734@@ -2470,7 +2470,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98735
98736 struct dev_gso_cb {
98737 void (*destructor)(struct sk_buff *skb);
98738-};
98739+} __no_const;
98740
98741 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98742
98743@@ -2900,7 +2900,7 @@ recursion_alert:
98744 rc = -ENETDOWN;
98745 rcu_read_unlock_bh();
98746
98747- atomic_long_inc(&dev->tx_dropped);
98748+ atomic_long_inc_unchecked(&dev->tx_dropped);
98749 kfree_skb(skb);
98750 return rc;
98751 out:
98752@@ -3244,7 +3244,7 @@ enqueue:
98753
98754 local_irq_restore(flags);
98755
98756- atomic_long_inc(&skb->dev->rx_dropped);
98757+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98758 kfree_skb(skb);
98759 return NET_RX_DROP;
98760 }
98761@@ -3321,7 +3321,7 @@ int netif_rx_ni(struct sk_buff *skb)
98762 }
98763 EXPORT_SYMBOL(netif_rx_ni);
98764
98765-static void net_tx_action(struct softirq_action *h)
98766+static __latent_entropy void net_tx_action(void)
98767 {
98768 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98769
98770@@ -3654,7 +3654,7 @@ ncls:
98771 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98772 } else {
98773 drop:
98774- atomic_long_inc(&skb->dev->rx_dropped);
98775+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98776 kfree_skb(skb);
98777 /* Jamal, now you will not able to escape explaining
98778 * me how you were going to use this. :-)
98779@@ -4375,7 +4375,7 @@ void netif_napi_del(struct napi_struct *napi)
98780 }
98781 EXPORT_SYMBOL(netif_napi_del);
98782
98783-static void net_rx_action(struct softirq_action *h)
98784+static __latent_entropy void net_rx_action(void)
98785 {
98786 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98787 unsigned long time_limit = jiffies + 2;
98788@@ -6375,8 +6375,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98789 } else {
98790 netdev_stats_to_stats64(storage, &dev->stats);
98791 }
98792- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98793- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98794+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98795+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98796 return storage;
98797 }
98798 EXPORT_SYMBOL(dev_get_stats);
98799diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98800index cf999e0..c59a975 100644
98801--- a/net/core/dev_ioctl.c
98802+++ b/net/core/dev_ioctl.c
98803@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98804 if (no_module && capable(CAP_NET_ADMIN))
98805 no_module = request_module("netdev-%s", name);
98806 if (no_module && capable(CAP_SYS_MODULE)) {
98807+#ifdef CONFIG_GRKERNSEC_MODHARDEN
98808+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
98809+#else
98810 if (!request_module("%s", name))
98811 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98812 name);
98813+#endif
98814 }
98815 }
98816 EXPORT_SYMBOL(dev_load);
98817diff --git a/net/core/filter.c b/net/core/filter.c
98818index 5310d5e..01f885e 100644
98819--- a/net/core/filter.c
98820+++ b/net/core/filter.c
98821@@ -1121,7 +1121,11 @@ do_pass:
98822 break;
98823
98824 default:
98825- goto err;
98826+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98827+ fp->code, fp->jt, fp->jf, fp->k);
98828+ kfree(addrs);
98829+ BUG();
98830+ return -EINVAL;
98831 }
98832
98833 insn++;
98834@@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98835 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98836 int pc, ret = 0;
98837
98838- BUILD_BUG_ON(BPF_MEMWORDS > 16);
98839+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
98840 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98841 if (!masks)
98842 return -ENOMEM;
98843@@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98844 if (!fp)
98845 return -ENOMEM;
98846
98847- memcpy(fp->insns, fprog->filter, fsize);
98848+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98849
98850 atomic_set(&fp->refcnt, 1);
98851 fp->len = fprog->len;
98852diff --git a/net/core/flow.c b/net/core/flow.c
98853index a0348fd..6951c76 100644
98854--- a/net/core/flow.c
98855+++ b/net/core/flow.c
98856@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98857 static int flow_entry_valid(struct flow_cache_entry *fle,
98858 struct netns_xfrm *xfrm)
98859 {
98860- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98861+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98862 return 0;
98863 if (fle->object && !fle->object->ops->check(fle->object))
98864 return 0;
98865@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98866 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98867 fcp->hash_count++;
98868 }
98869- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98870+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98871 flo = fle->object;
98872 if (!flo)
98873 goto ret_object;
98874@@ -263,7 +263,7 @@ nocache:
98875 }
98876 flo = resolver(net, key, family, dir, flo, ctx);
98877 if (fle) {
98878- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98879+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98880 if (!IS_ERR(flo))
98881 fle->object = flo;
98882 else
98883diff --git a/net/core/iovec.c b/net/core/iovec.c
98884index 26dc006..89e838e 100644
98885--- a/net/core/iovec.c
98886+++ b/net/core/iovec.c
98887@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98888 if (m->msg_name && m->msg_namelen) {
98889 if (mode == VERIFY_READ) {
98890 void __user *namep;
98891- namep = (void __user __force *) m->msg_name;
98892+ namep = (void __force_user *) m->msg_name;
98893 err = move_addr_to_kernel(namep, m->msg_namelen,
98894 address);
98895 if (err < 0)
98896@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98897 }
98898
98899 size = m->msg_iovlen * sizeof(struct iovec);
98900- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98901+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98902 return -EFAULT;
98903
98904 m->msg_iov = iov;
98905diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98906index 32d872e..487e769 100644
98907--- a/net/core/neighbour.c
98908+++ b/net/core/neighbour.c
98909@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98910 void __user *buffer, size_t *lenp, loff_t *ppos)
98911 {
98912 int size, ret;
98913- struct ctl_table tmp = *ctl;
98914+ ctl_table_no_const tmp = *ctl;
98915
98916 tmp.extra1 = &zero;
98917 tmp.extra2 = &unres_qlen_max;
98918@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98919 void __user *buffer,
98920 size_t *lenp, loff_t *ppos)
98921 {
98922- struct ctl_table tmp = *ctl;
98923+ ctl_table_no_const tmp = *ctl;
98924 int ret;
98925
98926 tmp.extra1 = &zero;
98927@@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98928 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98929 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98930 } else {
98931+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98932 dev_name_source = "default";
98933- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98934- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98935- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98936- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98937+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98938+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98939+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98940+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98941 }
98942
98943 if (handler) {
98944diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98945index 2bf8329..2eb1423 100644
98946--- a/net/core/net-procfs.c
98947+++ b/net/core/net-procfs.c
98948@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98949 struct rtnl_link_stats64 temp;
98950 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98951
98952- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98953+ if (gr_proc_is_restricted())
98954+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98955+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98956+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98957+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98958+ else
98959+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98960 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98961 dev->name, stats->rx_bytes, stats->rx_packets,
98962 stats->rx_errors,
98963@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98964 return 0;
98965 }
98966
98967-static const struct seq_operations dev_seq_ops = {
98968+const struct seq_operations dev_seq_ops = {
98969 .start = dev_seq_start,
98970 .next = dev_seq_next,
98971 .stop = dev_seq_stop,
98972@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98973
98974 static int softnet_seq_open(struct inode *inode, struct file *file)
98975 {
98976- return seq_open(file, &softnet_seq_ops);
98977+ return seq_open_restrict(file, &softnet_seq_ops);
98978 }
98979
98980 static const struct file_operations softnet_seq_fops = {
98981@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98982 else
98983 seq_printf(seq, "%04x", ntohs(pt->type));
98984
98985+#ifdef CONFIG_GRKERNSEC_HIDESYM
98986+ seq_printf(seq, " %-8s %pf\n",
98987+ pt->dev ? pt->dev->name : "", NULL);
98988+#else
98989 seq_printf(seq, " %-8s %pf\n",
98990 pt->dev ? pt->dev->name : "", pt->func);
98991+#endif
98992 }
98993
98994 return 0;
98995diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98996index 1cac29e..fb482f3 100644
98997--- a/net/core/net-sysfs.c
98998+++ b/net/core/net-sysfs.c
98999@@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
99000 {
99001 struct net_device *netdev = to_net_dev(dev);
99002 return sprintf(buf, fmt_dec,
99003- atomic_read(&netdev->carrier_changes));
99004+ atomic_read_unchecked(&netdev->carrier_changes));
99005 }
99006 static DEVICE_ATTR_RO(carrier_changes);
99007
99008diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
99009index 7c8ffd9..0cb3687 100644
99010--- a/net/core/net_namespace.c
99011+++ b/net/core/net_namespace.c
99012@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
99013 int error;
99014 LIST_HEAD(net_exit_list);
99015
99016- list_add_tail(&ops->list, list);
99017+ pax_list_add_tail((struct list_head *)&ops->list, list);
99018 if (ops->init || (ops->id && ops->size)) {
99019 for_each_net(net) {
99020 error = ops_init(ops, net);
99021@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
99022
99023 out_undo:
99024 /* If I have an error cleanup all namespaces I initialized */
99025- list_del(&ops->list);
99026+ pax_list_del((struct list_head *)&ops->list);
99027 ops_exit_list(ops, &net_exit_list);
99028 ops_free_list(ops, &net_exit_list);
99029 return error;
99030@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
99031 struct net *net;
99032 LIST_HEAD(net_exit_list);
99033
99034- list_del(&ops->list);
99035+ pax_list_del((struct list_head *)&ops->list);
99036 for_each_net(net)
99037 list_add_tail(&net->exit_list, &net_exit_list);
99038 ops_exit_list(ops, &net_exit_list);
99039@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
99040 mutex_lock(&net_mutex);
99041 error = register_pernet_operations(&pernet_list, ops);
99042 if (!error && (first_device == &pernet_list))
99043- first_device = &ops->list;
99044+ first_device = (struct list_head *)&ops->list;
99045 mutex_unlock(&net_mutex);
99046 return error;
99047 }
99048diff --git a/net/core/netpoll.c b/net/core/netpoll.c
99049index e33937f..b2b4981 100644
99050--- a/net/core/netpoll.c
99051+++ b/net/core/netpoll.c
99052@@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
99053 struct udphdr *udph;
99054 struct iphdr *iph;
99055 struct ethhdr *eth;
99056- static atomic_t ip_ident;
99057+ static atomic_unchecked_t ip_ident;
99058 struct ipv6hdr *ip6h;
99059
99060 udp_len = len + sizeof(*udph);
99061@@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
99062 put_unaligned(0x45, (unsigned char *)iph);
99063 iph->tos = 0;
99064 put_unaligned(htons(ip_len), &(iph->tot_len));
99065- iph->id = htons(atomic_inc_return(&ip_ident));
99066+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
99067 iph->frag_off = 0;
99068 iph->ttl = 64;
99069 iph->protocol = IPPROTO_UDP;
99070diff --git a/net/core/pktgen.c b/net/core/pktgen.c
99071index 0304f98..ddfead6 100644
99072--- a/net/core/pktgen.c
99073+++ b/net/core/pktgen.c
99074@@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
99075 pn->net = net;
99076 INIT_LIST_HEAD(&pn->pktgen_threads);
99077 pn->pktgen_exiting = false;
99078- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
99079+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
99080 if (!pn->proc_dir) {
99081 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
99082 return -ENODEV;
99083diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
99084index 1999ed8..1e6e58a 100644
99085--- a/net/core/rtnetlink.c
99086+++ b/net/core/rtnetlink.c
99087@@ -58,7 +58,7 @@ struct rtnl_link {
99088 rtnl_doit_func doit;
99089 rtnl_dumpit_func dumpit;
99090 rtnl_calcit_func calcit;
99091-};
99092+} __no_const;
99093
99094 static DEFINE_MUTEX(rtnl_mutex);
99095
99096@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
99097 if (rtnl_link_ops_get(ops->kind))
99098 return -EEXIST;
99099
99100- if (!ops->dellink)
99101- ops->dellink = unregister_netdevice_queue;
99102+ if (!ops->dellink) {
99103+ pax_open_kernel();
99104+ *(void **)&ops->dellink = unregister_netdevice_queue;
99105+ pax_close_kernel();
99106+ }
99107
99108- list_add_tail(&ops->list, &link_ops);
99109+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
99110 return 0;
99111 }
99112 EXPORT_SYMBOL_GPL(__rtnl_link_register);
99113@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
99114 for_each_net(net) {
99115 __rtnl_kill_links(net, ops);
99116 }
99117- list_del(&ops->list);
99118+ pax_list_del((struct list_head *)&ops->list);
99119 }
99120 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
99121
99122@@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
99123 (dev->ifalias &&
99124 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
99125 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
99126- atomic_read(&dev->carrier_changes)))
99127+ atomic_read_unchecked(&dev->carrier_changes)))
99128 goto nla_put_failure;
99129
99130 if (1) {
99131diff --git a/net/core/scm.c b/net/core/scm.c
99132index b442e7e..6f5b5a2 100644
99133--- a/net/core/scm.c
99134+++ b/net/core/scm.c
99135@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
99136 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
99137 {
99138 struct cmsghdr __user *cm
99139- = (__force struct cmsghdr __user *)msg->msg_control;
99140+ = (struct cmsghdr __force_user *)msg->msg_control;
99141 struct cmsghdr cmhdr;
99142 int cmlen = CMSG_LEN(len);
99143 int err;
99144@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
99145 err = -EFAULT;
99146 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
99147 goto out;
99148- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
99149+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
99150 goto out;
99151 cmlen = CMSG_SPACE(len);
99152 if (msg->msg_controllen < cmlen)
99153@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
99154 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
99155 {
99156 struct cmsghdr __user *cm
99157- = (__force struct cmsghdr __user*)msg->msg_control;
99158+ = (struct cmsghdr __force_user *)msg->msg_control;
99159
99160 int fdmax = 0;
99161 int fdnum = scm->fp->count;
99162@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
99163 if (fdnum < fdmax)
99164 fdmax = fdnum;
99165
99166- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
99167+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
99168 i++, cmfptr++)
99169 {
99170 struct socket *sock;
99171diff --git a/net/core/skbuff.c b/net/core/skbuff.c
99172index 6ab5f77..6fd2a81 100644
99173--- a/net/core/skbuff.c
99174+++ b/net/core/skbuff.c
99175@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
99176 __wsum skb_checksum(const struct sk_buff *skb, int offset,
99177 int len, __wsum csum)
99178 {
99179- const struct skb_checksum_ops ops = {
99180+ static const struct skb_checksum_ops ops = {
99181 .update = csum_partial_ext,
99182 .combine = csum_block_add_ext,
99183 };
99184@@ -3221,13 +3221,15 @@ void __init skb_init(void)
99185 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
99186 sizeof(struct sk_buff),
99187 0,
99188- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
99189+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
99190+ SLAB_NO_SANITIZE,
99191 NULL);
99192 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
99193 (2*sizeof(struct sk_buff)) +
99194 sizeof(atomic_t),
99195 0,
99196- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
99197+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
99198+ SLAB_NO_SANITIZE,
99199 NULL);
99200 }
99201
99202diff --git a/net/core/sock.c b/net/core/sock.c
99203index 664ee42..aaf9e6e 100644
99204--- a/net/core/sock.c
99205+++ b/net/core/sock.c
99206@@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
99207 struct sk_buff_head *list = &sk->sk_receive_queue;
99208
99209 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
99210- atomic_inc(&sk->sk_drops);
99211+ atomic_inc_unchecked(&sk->sk_drops);
99212 trace_sock_rcvqueue_full(sk, skb);
99213 return -ENOMEM;
99214 }
99215@@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
99216 return err;
99217
99218 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
99219- atomic_inc(&sk->sk_drops);
99220+ atomic_inc_unchecked(&sk->sk_drops);
99221 return -ENOBUFS;
99222 }
99223
99224@@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
99225 skb_dst_force(skb);
99226
99227 spin_lock_irqsave(&list->lock, flags);
99228- skb->dropcount = atomic_read(&sk->sk_drops);
99229+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
99230 __skb_queue_tail(list, skb);
99231 spin_unlock_irqrestore(&list->lock, flags);
99232
99233@@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
99234 skb->dev = NULL;
99235
99236 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
99237- atomic_inc(&sk->sk_drops);
99238+ atomic_inc_unchecked(&sk->sk_drops);
99239 goto discard_and_relse;
99240 }
99241 if (nested)
99242@@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
99243 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
99244 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
99245 bh_unlock_sock(sk);
99246- atomic_inc(&sk->sk_drops);
99247+ atomic_inc_unchecked(&sk->sk_drops);
99248 goto discard_and_relse;
99249 }
99250
99251@@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99252 struct timeval tm;
99253 } v;
99254
99255- int lv = sizeof(int);
99256- int len;
99257+ unsigned int lv = sizeof(int);
99258+ unsigned int len;
99259
99260 if (get_user(len, optlen))
99261 return -EFAULT;
99262- if (len < 0)
99263+ if (len > INT_MAX)
99264 return -EINVAL;
99265
99266 memset(&v, 0, sizeof(v));
99267@@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99268
99269 case SO_PEERNAME:
99270 {
99271- char address[128];
99272+ char address[_K_SS_MAXSIZE];
99273
99274 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
99275 return -ENOTCONN;
99276- if (lv < len)
99277+ if (lv < len || sizeof address < len)
99278 return -EINVAL;
99279 if (copy_to_user(optval, address, len))
99280 return -EFAULT;
99281@@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99282
99283 if (len > lv)
99284 len = lv;
99285- if (copy_to_user(optval, &v, len))
99286+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
99287 return -EFAULT;
99288 lenout:
99289 if (put_user(len, optlen))
99290@@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
99291 */
99292 smp_wmb();
99293 atomic_set(&sk->sk_refcnt, 1);
99294- atomic_set(&sk->sk_drops, 0);
99295+ atomic_set_unchecked(&sk->sk_drops, 0);
99296 }
99297 EXPORT_SYMBOL(sock_init_data);
99298
99299@@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
99300 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99301 int level, int type)
99302 {
99303+ struct sock_extended_err ee;
99304 struct sock_exterr_skb *serr;
99305 struct sk_buff *skb, *skb2;
99306 int copied, err;
99307@@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99308 sock_recv_timestamp(msg, sk, skb);
99309
99310 serr = SKB_EXT_ERR(skb);
99311- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
99312+ ee = serr->ee;
99313+ put_cmsg(msg, level, type, sizeof ee, &ee);
99314
99315 msg->msg_flags |= MSG_ERRQUEUE;
99316 err = copied;
99317diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
99318index a4216a4..1c07687 100644
99319--- a/net/core/sock_diag.c
99320+++ b/net/core/sock_diag.c
99321@@ -9,26 +9,33 @@
99322 #include <linux/inet_diag.h>
99323 #include <linux/sock_diag.h>
99324
99325-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
99326+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
99327 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
99328 static DEFINE_MUTEX(sock_diag_table_mutex);
99329
99330 int sock_diag_check_cookie(void *sk, __u32 *cookie)
99331 {
99332+#ifndef CONFIG_GRKERNSEC_HIDESYM
99333 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
99334 cookie[1] != INET_DIAG_NOCOOKIE) &&
99335 ((u32)(unsigned long)sk != cookie[0] ||
99336 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
99337 return -ESTALE;
99338 else
99339+#endif
99340 return 0;
99341 }
99342 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
99343
99344 void sock_diag_save_cookie(void *sk, __u32 *cookie)
99345 {
99346+#ifdef CONFIG_GRKERNSEC_HIDESYM
99347+ cookie[0] = 0;
99348+ cookie[1] = 0;
99349+#else
99350 cookie[0] = (u32)(unsigned long)sk;
99351 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
99352+#endif
99353 }
99354 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
99355
99356@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
99357 mutex_lock(&sock_diag_table_mutex);
99358 if (sock_diag_handlers[hndl->family])
99359 err = -EBUSY;
99360- else
99361+ else {
99362+ pax_open_kernel();
99363 sock_diag_handlers[hndl->family] = hndl;
99364+ pax_close_kernel();
99365+ }
99366 mutex_unlock(&sock_diag_table_mutex);
99367
99368 return err;
99369@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
99370
99371 mutex_lock(&sock_diag_table_mutex);
99372 BUG_ON(sock_diag_handlers[family] != hnld);
99373+ pax_open_kernel();
99374 sock_diag_handlers[family] = NULL;
99375+ pax_close_kernel();
99376 mutex_unlock(&sock_diag_table_mutex);
99377 }
99378 EXPORT_SYMBOL_GPL(sock_diag_unregister);
99379diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
99380index cf9cd13..8b56af3 100644
99381--- a/net/core/sysctl_net_core.c
99382+++ b/net/core/sysctl_net_core.c
99383@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
99384 {
99385 unsigned int orig_size, size;
99386 int ret, i;
99387- struct ctl_table tmp = {
99388+ ctl_table_no_const tmp = {
99389 .data = &size,
99390 .maxlen = sizeof(size),
99391 .mode = table->mode
99392@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
99393 void __user *buffer, size_t *lenp, loff_t *ppos)
99394 {
99395 char id[IFNAMSIZ];
99396- struct ctl_table tbl = {
99397+ ctl_table_no_const tbl = {
99398 .data = id,
99399 .maxlen = IFNAMSIZ,
99400 };
99401@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
99402
99403 static __net_init int sysctl_core_net_init(struct net *net)
99404 {
99405- struct ctl_table *tbl;
99406+ ctl_table_no_const *tbl = NULL;
99407
99408 net->core.sysctl_somaxconn = SOMAXCONN;
99409
99410- tbl = netns_core_table;
99411 if (!net_eq(net, &init_net)) {
99412- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
99413+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
99414 if (tbl == NULL)
99415 goto err_dup;
99416
99417@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
99418 if (net->user_ns != &init_user_ns) {
99419 tbl[0].procname = NULL;
99420 }
99421- }
99422-
99423- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99424+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99425+ } else
99426+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
99427 if (net->core.sysctl_hdr == NULL)
99428 goto err_reg;
99429
99430 return 0;
99431
99432 err_reg:
99433- if (tbl != netns_core_table)
99434- kfree(tbl);
99435+ kfree(tbl);
99436 err_dup:
99437 return -ENOMEM;
99438 }
99439@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
99440 kfree(tbl);
99441 }
99442
99443-static __net_initdata struct pernet_operations sysctl_core_ops = {
99444+static __net_initconst struct pernet_operations sysctl_core_ops = {
99445 .init = sysctl_core_net_init,
99446 .exit = sysctl_core_net_exit,
99447 };
99448diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
99449index 4c04848..f575934 100644
99450--- a/net/decnet/af_decnet.c
99451+++ b/net/decnet/af_decnet.c
99452@@ -465,6 +465,7 @@ static struct proto dn_proto = {
99453 .sysctl_rmem = sysctl_decnet_rmem,
99454 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
99455 .obj_size = sizeof(struct dn_sock),
99456+ .slab_flags = SLAB_USERCOPY,
99457 };
99458
99459 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
99460diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
99461index 3b726f3..1af6368 100644
99462--- a/net/decnet/dn_dev.c
99463+++ b/net/decnet/dn_dev.c
99464@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
99465 .extra1 = &min_t3,
99466 .extra2 = &max_t3
99467 },
99468- {0}
99469+ { }
99470 },
99471 };
99472
99473diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
99474index 5325b54..a0d4d69 100644
99475--- a/net/decnet/sysctl_net_decnet.c
99476+++ b/net/decnet/sysctl_net_decnet.c
99477@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
99478
99479 if (len > *lenp) len = *lenp;
99480
99481- if (copy_to_user(buffer, addr, len))
99482+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
99483 return -EFAULT;
99484
99485 *lenp = len;
99486@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
99487
99488 if (len > *lenp) len = *lenp;
99489
99490- if (copy_to_user(buffer, devname, len))
99491+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
99492 return -EFAULT;
99493
99494 *lenp = len;
99495diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
99496index ef2d543..5b9b73f 100644
99497--- a/net/ieee802154/reassembly.c
99498+++ b/net/ieee802154/reassembly.c
99499@@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
99500
99501 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99502 {
99503- struct ctl_table *table;
99504+ ctl_table_no_const *table = NULL;
99505 struct ctl_table_header *hdr;
99506
99507- table = lowpan_frags_ns_ctl_table;
99508 if (!net_eq(net, &init_net)) {
99509- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
99510+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
99511 GFP_KERNEL);
99512 if (table == NULL)
99513 goto err_alloc;
99514@@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99515 /* Don't export sysctls to unprivileged users */
99516 if (net->user_ns != &init_user_ns)
99517 table[0].procname = NULL;
99518- }
99519-
99520- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99521+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99522+ } else
99523+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
99524 if (hdr == NULL)
99525 goto err_reg;
99526
99527@@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99528 return 0;
99529
99530 err_reg:
99531- if (!net_eq(net, &init_net))
99532- kfree(table);
99533+ kfree(table);
99534 err_alloc:
99535 return -ENOMEM;
99536 }
99537diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
99538index 6af8ab6..3831cb8 100644
99539--- a/net/ipv4/af_inet.c
99540+++ b/net/ipv4/af_inet.c
99541@@ -1739,13 +1739,9 @@ static int __init inet_init(void)
99542
99543 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
99544
99545- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
99546- if (!sysctl_local_reserved_ports)
99547- goto out;
99548-
99549 rc = proto_register(&tcp_prot, 1);
99550 if (rc)
99551- goto out_free_reserved_ports;
99552+ goto out;
99553
99554 rc = proto_register(&udp_prot, 1);
99555 if (rc)
99556@@ -1855,8 +1851,6 @@ out_unregister_udp_proto:
99557 proto_unregister(&udp_prot);
99558 out_unregister_tcp_proto:
99559 proto_unregister(&tcp_prot);
99560-out_free_reserved_ports:
99561- kfree(sysctl_local_reserved_ports);
99562 goto out;
99563 }
99564
99565diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
99566index bdbf68b..deb4759 100644
99567--- a/net/ipv4/devinet.c
99568+++ b/net/ipv4/devinet.c
99569@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
99570 idx = 0;
99571 head = &net->dev_index_head[h];
99572 rcu_read_lock();
99573- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99574+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99575 net->dev_base_seq;
99576 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99577 if (idx < s_idx)
99578@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
99579 idx = 0;
99580 head = &net->dev_index_head[h];
99581 rcu_read_lock();
99582- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99583+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99584 net->dev_base_seq;
99585 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99586 if (idx < s_idx)
99587@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
99588 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
99589 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
99590
99591-static struct devinet_sysctl_table {
99592+static const struct devinet_sysctl_table {
99593 struct ctl_table_header *sysctl_header;
99594 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
99595 } devinet_sysctl = {
99596@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
99597 int err;
99598 struct ipv4_devconf *all, *dflt;
99599 #ifdef CONFIG_SYSCTL
99600- struct ctl_table *tbl = ctl_forward_entry;
99601+ ctl_table_no_const *tbl = NULL;
99602 struct ctl_table_header *forw_hdr;
99603 #endif
99604
99605@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
99606 goto err_alloc_dflt;
99607
99608 #ifdef CONFIG_SYSCTL
99609- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99610+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99611 if (tbl == NULL)
99612 goto err_alloc_ctl;
99613
99614@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99615 goto err_reg_dflt;
99616
99617 err = -ENOMEM;
99618- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99619+ if (!net_eq(net, &init_net))
99620+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99621+ else
99622+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99623 if (forw_hdr == NULL)
99624 goto err_reg_ctl;
99625 net->ipv4.forw_hdr = forw_hdr;
99626@@ -2272,8 +2275,7 @@ err_reg_ctl:
99627 err_reg_dflt:
99628 __devinet_sysctl_unregister(all);
99629 err_reg_all:
99630- if (tbl != ctl_forward_entry)
99631- kfree(tbl);
99632+ kfree(tbl);
99633 err_alloc_ctl:
99634 #endif
99635 if (dflt != &ipv4_devconf_dflt)
99636diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99637index 255aa99..45c78f8 100644
99638--- a/net/ipv4/fib_frontend.c
99639+++ b/net/ipv4/fib_frontend.c
99640@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99641 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99642 fib_sync_up(dev);
99643 #endif
99644- atomic_inc(&net->ipv4.dev_addr_genid);
99645+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99646 rt_cache_flush(dev_net(dev));
99647 break;
99648 case NETDEV_DOWN:
99649 fib_del_ifaddr(ifa, NULL);
99650- atomic_inc(&net->ipv4.dev_addr_genid);
99651+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99652 if (ifa->ifa_dev->ifa_list == NULL) {
99653 /* Last address was deleted from this interface.
99654 * Disable IP.
99655@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99656 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99657 fib_sync_up(dev);
99658 #endif
99659- atomic_inc(&net->ipv4.dev_addr_genid);
99660+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99661 rt_cache_flush(net);
99662 break;
99663 case NETDEV_DOWN:
99664diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99665index b10cd43a..22327f9 100644
99666--- a/net/ipv4/fib_semantics.c
99667+++ b/net/ipv4/fib_semantics.c
99668@@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99669 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99670 nh->nh_gw,
99671 nh->nh_parent->fib_scope);
99672- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99673+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99674
99675 return nh->nh_saddr;
99676 }
99677diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99678index a56b8e6..5be2a30 100644
99679--- a/net/ipv4/inet_connection_sock.c
99680+++ b/net/ipv4/inet_connection_sock.c
99681@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99682 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99683 #endif
99684
99685-unsigned long *sysctl_local_reserved_ports;
99686+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99687 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99688
99689 void inet_get_local_port_range(struct net *net, int *low, int *high)
99690diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99691index 8b9cf27..0d8d592 100644
99692--- a/net/ipv4/inet_hashtables.c
99693+++ b/net/ipv4/inet_hashtables.c
99694@@ -18,6 +18,7 @@
99695 #include <linux/sched.h>
99696 #include <linux/slab.h>
99697 #include <linux/wait.h>
99698+#include <linux/security.h>
99699
99700 #include <net/inet_connection_sock.h>
99701 #include <net/inet_hashtables.h>
99702@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99703 return inet_ehashfn(net, laddr, lport, faddr, fport);
99704 }
99705
99706+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99707+
99708 /*
99709 * Allocate and initialize a new local port bind bucket.
99710 * The bindhash mutex for snum's hash chain must be held here.
99711@@ -554,6 +557,8 @@ ok:
99712 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99713 spin_unlock(&head->lock);
99714
99715+ gr_update_task_in_ip_table(current, inet_sk(sk));
99716+
99717 if (tw) {
99718 inet_twsk_deschedule(tw, death_row);
99719 while (twrefcnt) {
99720diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99721index bf2cb4a..d83ba8a 100644
99722--- a/net/ipv4/inetpeer.c
99723+++ b/net/ipv4/inetpeer.c
99724@@ -482,7 +482,7 @@ relookup:
99725 if (p) {
99726 p->daddr = *daddr;
99727 atomic_set(&p->refcnt, 1);
99728- atomic_set(&p->rid, 0);
99729+ atomic_set_unchecked(&p->rid, 0);
99730 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
99731 p->rate_tokens = 0;
99732 /* 60*HZ is arbitrary, but chosen enough high so that the first
99733diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99734index ed32313..3762abe 100644
99735--- a/net/ipv4/ip_fragment.c
99736+++ b/net/ipv4/ip_fragment.c
99737@@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99738 return 0;
99739
99740 start = qp->rid;
99741- end = atomic_inc_return(&peer->rid);
99742+ end = atomic_inc_return_unchecked(&peer->rid);
99743 qp->rid = end;
99744
99745 rc = qp->q.fragments && (end - start) > max;
99746@@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99747
99748 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99749 {
99750- struct ctl_table *table;
99751+ ctl_table_no_const *table = NULL;
99752 struct ctl_table_header *hdr;
99753
99754- table = ip4_frags_ns_ctl_table;
99755 if (!net_eq(net, &init_net)) {
99756- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99757+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99758 if (table == NULL)
99759 goto err_alloc;
99760
99761@@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99762 /* Don't export sysctls to unprivileged users */
99763 if (net->user_ns != &init_user_ns)
99764 table[0].procname = NULL;
99765- }
99766+ hdr = register_net_sysctl(net, "net/ipv4", table);
99767+ } else
99768+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99769
99770- hdr = register_net_sysctl(net, "net/ipv4", table);
99771 if (hdr == NULL)
99772 goto err_reg;
99773
99774@@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99775 return 0;
99776
99777 err_reg:
99778- if (!net_eq(net, &init_net))
99779- kfree(table);
99780+ kfree(table);
99781 err_alloc:
99782 return -ENOMEM;
99783 }
99784diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99785index 94213c8..8bdb342 100644
99786--- a/net/ipv4/ip_gre.c
99787+++ b/net/ipv4/ip_gre.c
99788@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99789 module_param(log_ecn_error, bool, 0644);
99790 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99791
99792-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99793+static struct rtnl_link_ops ipgre_link_ops;
99794 static int ipgre_tunnel_init(struct net_device *dev);
99795
99796 static int ipgre_net_id __read_mostly;
99797@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99798 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99799 };
99800
99801-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99802+static struct rtnl_link_ops ipgre_link_ops = {
99803 .kind = "gre",
99804 .maxtype = IFLA_GRE_MAX,
99805 .policy = ipgre_policy,
99806@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99807 .fill_info = ipgre_fill_info,
99808 };
99809
99810-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99811+static struct rtnl_link_ops ipgre_tap_ops = {
99812 .kind = "gretap",
99813 .maxtype = IFLA_GRE_MAX,
99814 .policy = ipgre_policy,
99815diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99816index 64741b9..6f334a2 100644
99817--- a/net/ipv4/ip_sockglue.c
99818+++ b/net/ipv4/ip_sockglue.c
99819@@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99820 len = min_t(unsigned int, len, opt->optlen);
99821 if (put_user(len, optlen))
99822 return -EFAULT;
99823- if (copy_to_user(optval, opt->__data, len))
99824+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99825+ copy_to_user(optval, opt->__data, len))
99826 return -EFAULT;
99827 return 0;
99828 }
99829@@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99830 if (sk->sk_type != SOCK_STREAM)
99831 return -ENOPROTOOPT;
99832
99833- msg.msg_control = optval;
99834+ msg.msg_control = (void __force_kernel *)optval;
99835 msg.msg_controllen = len;
99836 msg.msg_flags = flags;
99837
99838diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99839index 13ef00f..8ffca25 100644
99840--- a/net/ipv4/ip_vti.c
99841+++ b/net/ipv4/ip_vti.c
99842@@ -45,7 +45,7 @@
99843 #include <net/net_namespace.h>
99844 #include <net/netns/generic.h>
99845
99846-static struct rtnl_link_ops vti_link_ops __read_mostly;
99847+static struct rtnl_link_ops vti_link_ops;
99848
99849 static int vti_net_id __read_mostly;
99850 static int vti_tunnel_init(struct net_device *dev);
99851@@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99852 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99853 };
99854
99855-static struct rtnl_link_ops vti_link_ops __read_mostly = {
99856+static struct rtnl_link_ops vti_link_ops = {
99857 .kind = "vti",
99858 .maxtype = IFLA_VTI_MAX,
99859 .policy = vti_policy,
99860diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99861index b3e86ea..18ce98c 100644
99862--- a/net/ipv4/ipconfig.c
99863+++ b/net/ipv4/ipconfig.c
99864@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99865
99866 mm_segment_t oldfs = get_fs();
99867 set_fs(get_ds());
99868- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99869+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99870 set_fs(oldfs);
99871 return res;
99872 }
99873@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99874
99875 mm_segment_t oldfs = get_fs();
99876 set_fs(get_ds());
99877- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99878+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99879 set_fs(oldfs);
99880 return res;
99881 }
99882@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99883
99884 mm_segment_t oldfs = get_fs();
99885 set_fs(get_ds());
99886- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99887+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99888 set_fs(oldfs);
99889 return res;
99890 }
99891diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99892index 62eaa00..29b2dc2 100644
99893--- a/net/ipv4/ipip.c
99894+++ b/net/ipv4/ipip.c
99895@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99896 static int ipip_net_id __read_mostly;
99897
99898 static int ipip_tunnel_init(struct net_device *dev);
99899-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99900+static struct rtnl_link_ops ipip_link_ops;
99901
99902 static int ipip_err(struct sk_buff *skb, u32 info)
99903 {
99904@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99905 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99906 };
99907
99908-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99909+static struct rtnl_link_ops ipip_link_ops = {
99910 .kind = "ipip",
99911 .maxtype = IFLA_IPTUN_MAX,
99912 .policy = ipip_policy,
99913diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99914index f95b6f9..2ee2097 100644
99915--- a/net/ipv4/netfilter/arp_tables.c
99916+++ b/net/ipv4/netfilter/arp_tables.c
99917@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99918 #endif
99919
99920 static int get_info(struct net *net, void __user *user,
99921- const int *len, int compat)
99922+ int len, int compat)
99923 {
99924 char name[XT_TABLE_MAXNAMELEN];
99925 struct xt_table *t;
99926 int ret;
99927
99928- if (*len != sizeof(struct arpt_getinfo)) {
99929- duprintf("length %u != %Zu\n", *len,
99930+ if (len != sizeof(struct arpt_getinfo)) {
99931+ duprintf("length %u != %Zu\n", len,
99932 sizeof(struct arpt_getinfo));
99933 return -EINVAL;
99934 }
99935@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99936 info.size = private->size;
99937 strcpy(info.name, name);
99938
99939- if (copy_to_user(user, &info, *len) != 0)
99940+ if (copy_to_user(user, &info, len) != 0)
99941 ret = -EFAULT;
99942 else
99943 ret = 0;
99944@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99945
99946 switch (cmd) {
99947 case ARPT_SO_GET_INFO:
99948- ret = get_info(sock_net(sk), user, len, 1);
99949+ ret = get_info(sock_net(sk), user, *len, 1);
99950 break;
99951 case ARPT_SO_GET_ENTRIES:
99952 ret = compat_get_entries(sock_net(sk), user, len);
99953@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99954
99955 switch (cmd) {
99956 case ARPT_SO_GET_INFO:
99957- ret = get_info(sock_net(sk), user, len, 0);
99958+ ret = get_info(sock_net(sk), user, *len, 0);
99959 break;
99960
99961 case ARPT_SO_GET_ENTRIES:
99962diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99963index 99e810f..3711b81 100644
99964--- a/net/ipv4/netfilter/ip_tables.c
99965+++ b/net/ipv4/netfilter/ip_tables.c
99966@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99967 #endif
99968
99969 static int get_info(struct net *net, void __user *user,
99970- const int *len, int compat)
99971+ int len, int compat)
99972 {
99973 char name[XT_TABLE_MAXNAMELEN];
99974 struct xt_table *t;
99975 int ret;
99976
99977- if (*len != sizeof(struct ipt_getinfo)) {
99978- duprintf("length %u != %zu\n", *len,
99979+ if (len != sizeof(struct ipt_getinfo)) {
99980+ duprintf("length %u != %zu\n", len,
99981 sizeof(struct ipt_getinfo));
99982 return -EINVAL;
99983 }
99984@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99985 info.size = private->size;
99986 strcpy(info.name, name);
99987
99988- if (copy_to_user(user, &info, *len) != 0)
99989+ if (copy_to_user(user, &info, len) != 0)
99990 ret = -EFAULT;
99991 else
99992 ret = 0;
99993@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99994
99995 switch (cmd) {
99996 case IPT_SO_GET_INFO:
99997- ret = get_info(sock_net(sk), user, len, 1);
99998+ ret = get_info(sock_net(sk), user, *len, 1);
99999 break;
100000 case IPT_SO_GET_ENTRIES:
100001 ret = compat_get_entries(sock_net(sk), user, len);
100002@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100003
100004 switch (cmd) {
100005 case IPT_SO_GET_INFO:
100006- ret = get_info(sock_net(sk), user, len, 0);
100007+ ret = get_info(sock_net(sk), user, *len, 0);
100008 break;
100009
100010 case IPT_SO_GET_ENTRIES:
100011diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
100012index 2510c02..cfb34fa 100644
100013--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
100014+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
100015@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
100016 spin_lock_init(&cn->lock);
100017
100018 #ifdef CONFIG_PROC_FS
100019- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
100020+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
100021 if (!cn->procdir) {
100022 pr_err("Unable to proc dir entry\n");
100023 return -ENOMEM;
100024diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
100025index 044a0dd..e0c1971 100644
100026--- a/net/ipv4/ping.c
100027+++ b/net/ipv4/ping.c
100028@@ -59,7 +59,7 @@ struct ping_table {
100029 };
100030
100031 static struct ping_table ping_table;
100032-struct pingv6_ops pingv6_ops;
100033+struct pingv6_ops *pingv6_ops;
100034 EXPORT_SYMBOL_GPL(pingv6_ops);
100035
100036 static u16 ping_port_rover;
100037@@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
100038 return -ENODEV;
100039 }
100040 }
100041- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
100042+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
100043 scoped);
100044 rcu_read_unlock();
100045
100046@@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
100047 }
100048 #if IS_ENABLED(CONFIG_IPV6)
100049 } else if (skb->protocol == htons(ETH_P_IPV6)) {
100050- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
100051+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
100052 #endif
100053 }
100054
100055@@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
100056 info, (u8 *)icmph);
100057 #if IS_ENABLED(CONFIG_IPV6)
100058 } else if (family == AF_INET6) {
100059- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
100060+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
100061 info, (u8 *)icmph);
100062 #endif
100063 }
100064@@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100065 {
100066 struct inet_sock *isk = inet_sk(sk);
100067 int family = sk->sk_family;
100068+ struct sockaddr_in *sin;
100069+ struct sockaddr_in6 *sin6;
100070 struct sk_buff *skb;
100071 int copied, err;
100072
100073@@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100074 if (flags & MSG_OOB)
100075 goto out;
100076
100077+ if (addr_len) {
100078+ if (family == AF_INET)
100079+ *addr_len = sizeof(*sin);
100080+ else if (family == AF_INET6 && addr_len)
100081+ *addr_len = sizeof(*sin6);
100082+ }
100083+
100084 if (flags & MSG_ERRQUEUE) {
100085 if (family == AF_INET) {
100086 return ip_recv_error(sk, msg, len, addr_len);
100087 #if IS_ENABLED(CONFIG_IPV6)
100088 } else if (family == AF_INET6) {
100089- return pingv6_ops.ipv6_recv_error(sk, msg, len,
100090+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
100091 addr_len);
100092 #endif
100093 }
100094@@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100095 sin->sin_port = 0 /* skb->h.uh->source */;
100096 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100097 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100098- *addr_len = sizeof(*sin);
100099 }
100100
100101 if (isk->cmsg_flags)
100102@@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100103 sin6->sin6_scope_id =
100104 ipv6_iface_scope_id(&sin6->sin6_addr,
100105 IP6CB(skb)->iif);
100106- *addr_len = sizeof(*sin6);
100107 }
100108
100109 if (inet6_sk(sk)->rxopt.all)
100110- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
100111+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
100112 if (skb->protocol == htons(ETH_P_IPV6) &&
100113 inet6_sk(sk)->rxopt.all)
100114- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
100115+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
100116 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
100117 ip_cmsg_recv(msg, skb);
100118 #endif
100119@@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
100120 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100121 0, sock_i_ino(sp),
100122 atomic_read(&sp->sk_refcnt), sp,
100123- atomic_read(&sp->sk_drops));
100124+ atomic_read_unchecked(&sp->sk_drops));
100125 }
100126
100127 static int ping_v4_seq_show(struct seq_file *seq, void *v)
100128diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
100129index 2c65160..b54c00e 100644
100130--- a/net/ipv4/raw.c
100131+++ b/net/ipv4/raw.c
100132@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
100133 int raw_rcv(struct sock *sk, struct sk_buff *skb)
100134 {
100135 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
100136- atomic_inc(&sk->sk_drops);
100137+ atomic_inc_unchecked(&sk->sk_drops);
100138 kfree_skb(skb);
100139 return NET_RX_DROP;
100140 }
100141@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100142 if (flags & MSG_OOB)
100143 goto out;
100144
100145+ if (addr_len)
100146+ *addr_len = sizeof(*sin);
100147+
100148 if (flags & MSG_ERRQUEUE) {
100149 err = ip_recv_error(sk, msg, len, addr_len);
100150 goto out;
100151@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100152 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100153 sin->sin_port = 0;
100154 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100155- *addr_len = sizeof(*sin);
100156 }
100157 if (inet->cmsg_flags)
100158 ip_cmsg_recv(msg, skb);
100159@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
100160
100161 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
100162 {
100163+ struct icmp_filter filter;
100164+
100165 if (optlen > sizeof(struct icmp_filter))
100166 optlen = sizeof(struct icmp_filter);
100167- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
100168+ if (copy_from_user(&filter, optval, optlen))
100169 return -EFAULT;
100170+ raw_sk(sk)->filter = filter;
100171 return 0;
100172 }
100173
100174 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
100175 {
100176 int len, ret = -EFAULT;
100177+ struct icmp_filter filter;
100178
100179 if (get_user(len, optlen))
100180 goto out;
100181@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
100182 if (len > sizeof(struct icmp_filter))
100183 len = sizeof(struct icmp_filter);
100184 ret = -EFAULT;
100185- if (put_user(len, optlen) ||
100186- copy_to_user(optval, &raw_sk(sk)->filter, len))
100187+ filter = raw_sk(sk)->filter;
100188+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
100189 goto out;
100190 ret = 0;
100191 out: return ret;
100192@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
100193 0, 0L, 0,
100194 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
100195 0, sock_i_ino(sp),
100196- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
100197+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
100198 }
100199
100200 static int raw_seq_show(struct seq_file *seq, void *v)
100201diff --git a/net/ipv4/route.c b/net/ipv4/route.c
100202index fd618d4..aae0ac9 100644
100203--- a/net/ipv4/route.c
100204+++ b/net/ipv4/route.c
100205@@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
100206
100207 static int rt_cache_seq_open(struct inode *inode, struct file *file)
100208 {
100209- return seq_open(file, &rt_cache_seq_ops);
100210+ return seq_open_restrict(file, &rt_cache_seq_ops);
100211 }
100212
100213 static const struct file_operations rt_cache_seq_fops = {
100214@@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
100215
100216 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
100217 {
100218- return seq_open(file, &rt_cpu_seq_ops);
100219+ return seq_open_restrict(file, &rt_cpu_seq_ops);
100220 }
100221
100222 static const struct file_operations rt_cpu_seq_fops = {
100223@@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
100224
100225 static int rt_acct_proc_open(struct inode *inode, struct file *file)
100226 {
100227- return single_open(file, rt_acct_proc_show, NULL);
100228+ return single_open_restrict(file, rt_acct_proc_show, NULL);
100229 }
100230
100231 static const struct file_operations rt_acct_proc_fops = {
100232@@ -459,7 +459,7 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
100233
100234 #define IP_IDENTS_SZ 2048u
100235 struct ip_ident_bucket {
100236- atomic_t id;
100237+ atomic_unchecked_t id;
100238 u32 stamp32;
100239 };
100240
100241@@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
100242 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
100243 delta = prandom_u32_max(now - old);
100244
100245- return atomic_add_return(segs + delta, &bucket->id) - segs;
100246+ return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
100247 }
100248 EXPORT_SYMBOL(ip_idents_reserve);
100249
100250@@ -2618,34 +2618,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
100251 .maxlen = sizeof(int),
100252 .mode = 0200,
100253 .proc_handler = ipv4_sysctl_rtcache_flush,
100254+ .extra1 = &init_net,
100255 },
100256 { },
100257 };
100258
100259 static __net_init int sysctl_route_net_init(struct net *net)
100260 {
100261- struct ctl_table *tbl;
100262+ ctl_table_no_const *tbl = NULL;
100263
100264- tbl = ipv4_route_flush_table;
100265 if (!net_eq(net, &init_net)) {
100266- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
100267+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
100268 if (tbl == NULL)
100269 goto err_dup;
100270
100271 /* Don't export sysctls to unprivileged users */
100272 if (net->user_ns != &init_user_ns)
100273 tbl[0].procname = NULL;
100274- }
100275- tbl[0].extra1 = net;
100276+ tbl[0].extra1 = net;
100277+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
100278+ } else
100279+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
100280
100281- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
100282 if (net->ipv4.route_hdr == NULL)
100283 goto err_reg;
100284 return 0;
100285
100286 err_reg:
100287- if (tbl != ipv4_route_flush_table)
100288- kfree(tbl);
100289+ kfree(tbl);
100290 err_dup:
100291 return -ENOMEM;
100292 }
100293@@ -2668,8 +2668,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
100294
100295 static __net_init int rt_genid_init(struct net *net)
100296 {
100297- atomic_set(&net->ipv4.rt_genid, 0);
100298- atomic_set(&net->fnhe_genid, 0);
100299+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
100300+ atomic_set_unchecked(&net->fnhe_genid, 0);
100301 get_random_bytes(&net->ipv4.dev_addr_genid,
100302 sizeof(net->ipv4.dev_addr_genid));
100303 return 0;
100304diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
100305index 5cde8f2..5f5684e 100644
100306--- a/net/ipv4/sysctl_net_ipv4.c
100307+++ b/net/ipv4/sysctl_net_ipv4.c
100308@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
100309 container_of(table->data, struct net, ipv4.ip_local_ports.range);
100310 int ret;
100311 int range[2];
100312- struct ctl_table tmp = {
100313+ ctl_table_no_const tmp = {
100314 .data = &range,
100315 .maxlen = sizeof(range),
100316 .mode = table->mode,
100317@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
100318 int ret;
100319 gid_t urange[2];
100320 kgid_t low, high;
100321- struct ctl_table tmp = {
100322+ ctl_table_no_const tmp = {
100323 .data = &urange,
100324 .maxlen = sizeof(urange),
100325 .mode = table->mode,
100326@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
100327 void __user *buffer, size_t *lenp, loff_t *ppos)
100328 {
100329 char val[TCP_CA_NAME_MAX];
100330- struct ctl_table tbl = {
100331+ ctl_table_no_const tbl = {
100332 .data = val,
100333 .maxlen = TCP_CA_NAME_MAX,
100334 };
100335@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
100336 void __user *buffer, size_t *lenp,
100337 loff_t *ppos)
100338 {
100339- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
100340+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
100341 int ret;
100342
100343 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100344@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
100345 void __user *buffer, size_t *lenp,
100346 loff_t *ppos)
100347 {
100348- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
100349+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
100350 int ret;
100351
100352 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100353@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
100354 void __user *buffer, size_t *lenp,
100355 loff_t *ppos)
100356 {
100357- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100358+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100359 struct tcp_fastopen_context *ctxt;
100360 int ret;
100361 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
100362@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
100363 },
100364 {
100365 .procname = "ip_local_reserved_ports",
100366- .data = NULL, /* initialized in sysctl_ipv4_init */
100367+ .data = sysctl_local_reserved_ports,
100368 .maxlen = 65536,
100369 .mode = 0644,
100370 .proc_handler = proc_do_large_bitmap,
100371@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
100372
100373 static __net_init int ipv4_sysctl_init_net(struct net *net)
100374 {
100375- struct ctl_table *table;
100376+ ctl_table_no_const *table = NULL;
100377
100378- table = ipv4_net_table;
100379 if (!net_eq(net, &init_net)) {
100380 int i;
100381
100382- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
100383+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
100384 if (table == NULL)
100385 goto err_alloc;
100386
100387@@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
100388 table[i].data += (void *)net - (void *)&init_net;
100389 }
100390
100391- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100392+ if (!net_eq(net, &init_net))
100393+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100394+ else
100395+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
100396 if (net->ipv4.ipv4_hdr == NULL)
100397 goto err_reg;
100398
100399 return 0;
100400
100401 err_reg:
100402- if (!net_eq(net, &init_net))
100403- kfree(table);
100404+ kfree(table);
100405 err_alloc:
100406 return -ENOMEM;
100407 }
100408@@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
100409 static __init int sysctl_ipv4_init(void)
100410 {
100411 struct ctl_table_header *hdr;
100412- struct ctl_table *i;
100413-
100414- for (i = ipv4_table; i->procname; i++) {
100415- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
100416- i->data = sysctl_local_reserved_ports;
100417- break;
100418- }
100419- }
100420- if (!i->procname)
100421- return -EINVAL;
100422
100423 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
100424 if (hdr == NULL)
100425diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
100426index 09b85cd..df9c266 100644
100427--- a/net/ipv4/tcp_input.c
100428+++ b/net/ipv4/tcp_input.c
100429@@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
100430 * without any lock. We want to make sure compiler wont store
100431 * intermediate values in this location.
100432 */
100433- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
100434+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
100435 sk->sk_max_pacing_rate);
100436 }
100437
100438@@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
100439 * simplifies code)
100440 */
100441 static void
100442-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100443+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100444 struct sk_buff *head, struct sk_buff *tail,
100445 u32 start, u32 end)
100446 {
100447@@ -5558,6 +5558,7 @@ discard:
100448 tcp_paws_reject(&tp->rx_opt, 0))
100449 goto discard_and_undo;
100450
100451+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
100452 if (th->syn) {
100453 /* We see SYN without ACK. It is attempt of
100454 * simultaneous connect with crossed SYNs.
100455@@ -5608,6 +5609,7 @@ discard:
100456 goto discard;
100457 #endif
100458 }
100459+#endif
100460 /* "fifth, if neither of the SYN or RST bits is set then
100461 * drop the segment and return."
100462 */
100463@@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
100464 goto discard;
100465
100466 if (th->syn) {
100467- if (th->fin)
100468+ if (th->fin || th->urg || th->psh)
100469 goto discard;
100470 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
100471 return 1;
100472diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
100473index 438f3b9..bc9e1ad 100644
100474--- a/net/ipv4/tcp_ipv4.c
100475+++ b/net/ipv4/tcp_ipv4.c
100476@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
100477 EXPORT_SYMBOL(sysctl_tcp_low_latency);
100478
100479
100480+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100481+extern int grsec_enable_blackhole;
100482+#endif
100483+
100484 #ifdef CONFIG_TCP_MD5SIG
100485 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
100486 __be32 daddr, __be32 saddr, const struct tcphdr *th);
100487@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
100488 return 0;
100489
100490 reset:
100491+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100492+ if (!grsec_enable_blackhole)
100493+#endif
100494 tcp_v4_send_reset(rsk, skb);
100495 discard:
100496 kfree_skb(skb);
100497@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
100498 TCP_SKB_CB(skb)->sacked = 0;
100499
100500 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100501- if (!sk)
100502+ if (!sk) {
100503+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100504+ ret = 1;
100505+#endif
100506 goto no_tcp_socket;
100507-
100508+ }
100509 process:
100510- if (sk->sk_state == TCP_TIME_WAIT)
100511+ if (sk->sk_state == TCP_TIME_WAIT) {
100512+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100513+ ret = 2;
100514+#endif
100515 goto do_time_wait;
100516+ }
100517
100518 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
100519 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100520@@ -2033,6 +2047,10 @@ csum_error:
100521 bad_packet:
100522 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100523 } else {
100524+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100525+ if (!grsec_enable_blackhole || (ret == 1 &&
100526+ (skb->dev->flags & IFF_LOOPBACK)))
100527+#endif
100528 tcp_v4_send_reset(NULL, skb);
100529 }
100530
100531diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
100532index 05c1b15..3e9344b 100644
100533--- a/net/ipv4/tcp_minisocks.c
100534+++ b/net/ipv4/tcp_minisocks.c
100535@@ -27,6 +27,10 @@
100536 #include <net/inet_common.h>
100537 #include <net/xfrm.h>
100538
100539+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100540+extern int grsec_enable_blackhole;
100541+#endif
100542+
100543 int sysctl_tcp_syncookies __read_mostly = 1;
100544 EXPORT_SYMBOL(sysctl_tcp_syncookies);
100545
100546@@ -709,7 +713,10 @@ embryonic_reset:
100547 * avoid becoming vulnerable to outside attack aiming at
100548 * resetting legit local connections.
100549 */
100550- req->rsk_ops->send_reset(sk, skb);
100551+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100552+ if (!grsec_enable_blackhole)
100553+#endif
100554+ req->rsk_ops->send_reset(sk, skb);
100555 } else if (fastopen) { /* received a valid RST pkt */
100556 reqsk_fastopen_remove(sk, req, true);
100557 tcp_reset(sk);
100558diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
100559index 3b66610..bfbe23a 100644
100560--- a/net/ipv4/tcp_probe.c
100561+++ b/net/ipv4/tcp_probe.c
100562@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
100563 if (cnt + width >= len)
100564 break;
100565
100566- if (copy_to_user(buf + cnt, tbuf, width))
100567+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
100568 return -EFAULT;
100569 cnt += width;
100570 }
100571diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
100572index 286227a..c495a76 100644
100573--- a/net/ipv4/tcp_timer.c
100574+++ b/net/ipv4/tcp_timer.c
100575@@ -22,6 +22,10 @@
100576 #include <linux/gfp.h>
100577 #include <net/tcp.h>
100578
100579+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100580+extern int grsec_lastack_retries;
100581+#endif
100582+
100583 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
100584 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
100585 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
100586@@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
100587 }
100588 }
100589
100590+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100591+ if ((sk->sk_state == TCP_LAST_ACK) &&
100592+ (grsec_lastack_retries > 0) &&
100593+ (grsec_lastack_retries < retry_until))
100594+ retry_until = grsec_lastack_retries;
100595+#endif
100596+
100597 if (retransmits_timed_out(sk, retry_until,
100598 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100599 /* Has it gone just too far? */
100600diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100601index 54a5fe9..78fea00 100644
100602--- a/net/ipv4/udp.c
100603+++ b/net/ipv4/udp.c
100604@@ -87,6 +87,7 @@
100605 #include <linux/types.h>
100606 #include <linux/fcntl.h>
100607 #include <linux/module.h>
100608+#include <linux/security.h>
100609 #include <linux/socket.h>
100610 #include <linux/sockios.h>
100611 #include <linux/igmp.h>
100612@@ -113,6 +114,10 @@
100613 #include <net/busy_poll.h>
100614 #include "udp_impl.h"
100615
100616+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100617+extern int grsec_enable_blackhole;
100618+#endif
100619+
100620 struct udp_table udp_table __read_mostly;
100621 EXPORT_SYMBOL(udp_table);
100622
100623@@ -615,6 +620,9 @@ found:
100624 return s;
100625 }
100626
100627+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100628+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100629+
100630 /*
100631 * This routine is called by the ICMP module when it gets some
100632 * sort of error condition. If err < 0 then the socket should
100633@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100634 dport = usin->sin_port;
100635 if (dport == 0)
100636 return -EINVAL;
100637+
100638+ err = gr_search_udp_sendmsg(sk, usin);
100639+ if (err)
100640+ return err;
100641 } else {
100642 if (sk->sk_state != TCP_ESTABLISHED)
100643 return -EDESTADDRREQ;
100644+
100645+ err = gr_search_udp_sendmsg(sk, NULL);
100646+ if (err)
100647+ return err;
100648+
100649 daddr = inet->inet_daddr;
100650 dport = inet->inet_dport;
100651 /* Open fast path for connected socket.
100652@@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100653 IS_UDPLITE(sk));
100654 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100655 IS_UDPLITE(sk));
100656- atomic_inc(&sk->sk_drops);
100657+ atomic_inc_unchecked(&sk->sk_drops);
100658 __skb_unlink(skb, rcvq);
100659 __skb_queue_tail(&list_kill, skb);
100660 }
100661@@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100662 int is_udplite = IS_UDPLITE(sk);
100663 bool slow;
100664
100665+ /*
100666+ * Check any passed addresses
100667+ */
100668+ if (addr_len)
100669+ *addr_len = sizeof(*sin);
100670+
100671 if (flags & MSG_ERRQUEUE)
100672 return ip_recv_error(sk, msg, len, addr_len);
100673
100674@@ -1244,6 +1267,10 @@ try_again:
100675 if (!skb)
100676 goto out;
100677
100678+ err = gr_search_udp_recvmsg(sk, skb);
100679+ if (err)
100680+ goto out_free;
100681+
100682 ulen = skb->len - sizeof(struct udphdr);
100683 copied = len;
100684 if (copied > ulen)
100685@@ -1277,7 +1304,7 @@ try_again:
100686 if (unlikely(err)) {
100687 trace_kfree_skb(skb, udp_recvmsg);
100688 if (!peeked) {
100689- atomic_inc(&sk->sk_drops);
100690+ atomic_inc_unchecked(&sk->sk_drops);
100691 UDP_INC_STATS_USER(sock_net(sk),
100692 UDP_MIB_INERRORS, is_udplite);
100693 }
100694@@ -1296,7 +1323,6 @@ try_again:
100695 sin->sin_port = udp_hdr(skb)->source;
100696 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100697 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100698- *addr_len = sizeof(*sin);
100699 }
100700 if (inet->cmsg_flags)
100701 ip_cmsg_recv(msg, skb);
100702@@ -1567,7 +1593,7 @@ csum_error:
100703 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100704 drop:
100705 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100706- atomic_inc(&sk->sk_drops);
100707+ atomic_inc_unchecked(&sk->sk_drops);
100708 kfree_skb(skb);
100709 return -1;
100710 }
100711@@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100712 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100713
100714 if (!skb1) {
100715- atomic_inc(&sk->sk_drops);
100716+ atomic_inc_unchecked(&sk->sk_drops);
100717 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100718 IS_UDPLITE(sk));
100719 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100720@@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100721 goto csum_error;
100722
100723 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100724+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100725+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100726+#endif
100727 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100728
100729 /*
100730@@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100731 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100732 0, sock_i_ino(sp),
100733 atomic_read(&sp->sk_refcnt), sp,
100734- atomic_read(&sp->sk_drops));
100735+ atomic_read_unchecked(&sp->sk_drops));
100736 }
100737
100738 int udp4_seq_show(struct seq_file *seq, void *v)
100739diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100740index 6156f68..d6ab46d 100644
100741--- a/net/ipv4/xfrm4_policy.c
100742+++ b/net/ipv4/xfrm4_policy.c
100743@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100744 fl4->flowi4_tos = iph->tos;
100745 }
100746
100747-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100748+static int xfrm4_garbage_collect(struct dst_ops *ops)
100749 {
100750 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100751
100752- xfrm4_policy_afinfo.garbage_collect(net);
100753+ xfrm_garbage_collect_deferred(net);
100754 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100755 }
100756
100757@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100758
100759 static int __net_init xfrm4_net_init(struct net *net)
100760 {
100761- struct ctl_table *table;
100762+ ctl_table_no_const *table = NULL;
100763 struct ctl_table_header *hdr;
100764
100765- table = xfrm4_policy_table;
100766 if (!net_eq(net, &init_net)) {
100767- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100768+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100769 if (!table)
100770 goto err_alloc;
100771
100772 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100773- }
100774-
100775- hdr = register_net_sysctl(net, "net/ipv4", table);
100776+ hdr = register_net_sysctl(net, "net/ipv4", table);
100777+ } else
100778+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100779 if (!hdr)
100780 goto err_reg;
100781
100782@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100783 return 0;
100784
100785 err_reg:
100786- if (!net_eq(net, &init_net))
100787- kfree(table);
100788+ kfree(table);
100789 err_alloc:
100790 return -ENOMEM;
100791 }
100792diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100793index 6c7fa08..8a31430 100644
100794--- a/net/ipv6/addrconf.c
100795+++ b/net/ipv6/addrconf.c
100796@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100797 idx = 0;
100798 head = &net->dev_index_head[h];
100799 rcu_read_lock();
100800- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100801+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100802 net->dev_base_seq;
100803 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100804 if (idx < s_idx)
100805@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100806 p.iph.ihl = 5;
100807 p.iph.protocol = IPPROTO_IPV6;
100808 p.iph.ttl = 64;
100809- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100810+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100811
100812 if (ops->ndo_do_ioctl) {
100813 mm_segment_t oldfs = get_fs();
100814@@ -3528,16 +3528,23 @@ static const struct file_operations if6_fops = {
100815 .release = seq_release_net,
100816 };
100817
100818+extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
100819+extern void unregister_ipv6_seq_ops_addr(void);
100820+
100821 static int __net_init if6_proc_net_init(struct net *net)
100822 {
100823- if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
100824+ register_ipv6_seq_ops_addr(&if6_seq_ops);
100825+ if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
100826+ unregister_ipv6_seq_ops_addr();
100827 return -ENOMEM;
100828+ }
100829 return 0;
100830 }
100831
100832 static void __net_exit if6_proc_net_exit(struct net *net)
100833 {
100834 remove_proc_entry("if_inet6", net->proc_net);
100835+ unregister_ipv6_seq_ops_addr();
100836 }
100837
100838 static struct pernet_operations if6_proc_net_ops = {
100839@@ -4146,7 +4153,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100840 s_ip_idx = ip_idx = cb->args[2];
100841
100842 rcu_read_lock();
100843- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100844+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100845 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100846 idx = 0;
100847 head = &net->dev_index_head[h];
100848@@ -4758,7 +4765,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100849 dst_free(&ifp->rt->dst);
100850 break;
100851 }
100852- atomic_inc(&net->ipv6.dev_addr_genid);
100853+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100854 rt_genid_bump_ipv6(net);
100855 }
100856
100857@@ -4779,7 +4786,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100858 int *valp = ctl->data;
100859 int val = *valp;
100860 loff_t pos = *ppos;
100861- struct ctl_table lctl;
100862+ ctl_table_no_const lctl;
100863 int ret;
100864
100865 /*
100866@@ -4864,7 +4871,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100867 int *valp = ctl->data;
100868 int val = *valp;
100869 loff_t pos = *ppos;
100870- struct ctl_table lctl;
100871+ ctl_table_no_const lctl;
100872 int ret;
100873
100874 /*
100875diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100876index d935889..2f64330 100644
100877--- a/net/ipv6/af_inet6.c
100878+++ b/net/ipv6/af_inet6.c
100879@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100880 net->ipv6.sysctl.bindv6only = 0;
100881 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100882 net->ipv6.sysctl.flowlabel_consistency = 1;
100883- atomic_set(&net->ipv6.rt_genid, 0);
100884+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100885
100886 err = ipv6_init_mibs(net);
100887 if (err)
100888diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100889index c3bf2d2..1f00573 100644
100890--- a/net/ipv6/datagram.c
100891+++ b/net/ipv6/datagram.c
100892@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100893 0,
100894 sock_i_ino(sp),
100895 atomic_read(&sp->sk_refcnt), sp,
100896- atomic_read(&sp->sk_drops));
100897+ atomic_read_unchecked(&sp->sk_drops));
100898 }
100899diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100900index 7b32652..0bc348b 100644
100901--- a/net/ipv6/icmp.c
100902+++ b/net/ipv6/icmp.c
100903@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100904
100905 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100906 {
100907- struct ctl_table *table;
100908+ ctl_table_no_const *table;
100909
100910 table = kmemdup(ipv6_icmp_table_template,
100911 sizeof(ipv6_icmp_table_template),
100912diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100913index 9d92146..d986c6a 100644
100914--- a/net/ipv6/ip6_gre.c
100915+++ b/net/ipv6/ip6_gre.c
100916@@ -71,7 +71,7 @@ struct ip6gre_net {
100917 struct net_device *fb_tunnel_dev;
100918 };
100919
100920-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100921+static struct rtnl_link_ops ip6gre_link_ops;
100922 static int ip6gre_tunnel_init(struct net_device *dev);
100923 static void ip6gre_tunnel_setup(struct net_device *dev);
100924 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100925@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100926 }
100927
100928
100929-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100930+static struct inet6_protocol ip6gre_protocol = {
100931 .handler = ip6gre_rcv,
100932 .err_handler = ip6gre_err,
100933 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100934@@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100935 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100936 };
100937
100938-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100939+static struct rtnl_link_ops ip6gre_link_ops = {
100940 .kind = "ip6gre",
100941 .maxtype = IFLA_GRE_MAX,
100942 .policy = ip6gre_policy,
100943@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100944 .fill_info = ip6gre_fill_info,
100945 };
100946
100947-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100948+static struct rtnl_link_ops ip6gre_tap_ops = {
100949 .kind = "ip6gretap",
100950 .maxtype = IFLA_GRE_MAX,
100951 .policy = ip6gre_policy,
100952diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100953index afa0824..04ba530 100644
100954--- a/net/ipv6/ip6_tunnel.c
100955+++ b/net/ipv6/ip6_tunnel.c
100956@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100957
100958 static int ip6_tnl_dev_init(struct net_device *dev);
100959 static void ip6_tnl_dev_setup(struct net_device *dev);
100960-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100961+static struct rtnl_link_ops ip6_link_ops;
100962
100963 static int ip6_tnl_net_id __read_mostly;
100964 struct ip6_tnl_net {
100965@@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100966 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100967 };
100968
100969-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100970+static struct rtnl_link_ops ip6_link_ops = {
100971 .kind = "ip6tnl",
100972 .maxtype = IFLA_IPTUN_MAX,
100973 .policy = ip6_tnl_policy,
100974diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100975index 6cc9f93..6e5bb7c 100644
100976--- a/net/ipv6/ip6_vti.c
100977+++ b/net/ipv6/ip6_vti.c
100978@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100979
100980 static int vti6_dev_init(struct net_device *dev);
100981 static void vti6_dev_setup(struct net_device *dev);
100982-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100983+static struct rtnl_link_ops vti6_link_ops;
100984
100985 static int vti6_net_id __read_mostly;
100986 struct vti6_net {
100987@@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100988 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100989 };
100990
100991-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100992+static struct rtnl_link_ops vti6_link_ops = {
100993 .kind = "vti6",
100994 .maxtype = IFLA_VTI_MAX,
100995 .policy = vti6_policy,
100996diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100997index edb58af..78de133 100644
100998--- a/net/ipv6/ipv6_sockglue.c
100999+++ b/net/ipv6/ipv6_sockglue.c
101000@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
101001 if (sk->sk_type != SOCK_STREAM)
101002 return -ENOPROTOOPT;
101003
101004- msg.msg_control = optval;
101005+ msg.msg_control = (void __force_kernel *)optval;
101006 msg.msg_controllen = len;
101007 msg.msg_flags = flags;
101008
101009diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
101010index e080fbb..412b3cf 100644
101011--- a/net/ipv6/netfilter/ip6_tables.c
101012+++ b/net/ipv6/netfilter/ip6_tables.c
101013@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
101014 #endif
101015
101016 static int get_info(struct net *net, void __user *user,
101017- const int *len, int compat)
101018+ int len, int compat)
101019 {
101020 char name[XT_TABLE_MAXNAMELEN];
101021 struct xt_table *t;
101022 int ret;
101023
101024- if (*len != sizeof(struct ip6t_getinfo)) {
101025- duprintf("length %u != %zu\n", *len,
101026+ if (len != sizeof(struct ip6t_getinfo)) {
101027+ duprintf("length %u != %zu\n", len,
101028 sizeof(struct ip6t_getinfo));
101029 return -EINVAL;
101030 }
101031@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
101032 info.size = private->size;
101033 strcpy(info.name, name);
101034
101035- if (copy_to_user(user, &info, *len) != 0)
101036+ if (copy_to_user(user, &info, len) != 0)
101037 ret = -EFAULT;
101038 else
101039 ret = 0;
101040@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101041
101042 switch (cmd) {
101043 case IP6T_SO_GET_INFO:
101044- ret = get_info(sock_net(sk), user, len, 1);
101045+ ret = get_info(sock_net(sk), user, *len, 1);
101046 break;
101047 case IP6T_SO_GET_ENTRIES:
101048 ret = compat_get_entries(sock_net(sk), user, len);
101049@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101050
101051 switch (cmd) {
101052 case IP6T_SO_GET_INFO:
101053- ret = get_info(sock_net(sk), user, len, 0);
101054+ ret = get_info(sock_net(sk), user, *len, 0);
101055 break;
101056
101057 case IP6T_SO_GET_ENTRIES:
101058diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
101059index 767ab8d..c5ec70a 100644
101060--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
101061+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
101062@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
101063
101064 static int nf_ct_frag6_sysctl_register(struct net *net)
101065 {
101066- struct ctl_table *table;
101067+ ctl_table_no_const *table = NULL;
101068 struct ctl_table_header *hdr;
101069
101070- table = nf_ct_frag6_sysctl_table;
101071 if (!net_eq(net, &init_net)) {
101072- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
101073+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
101074 GFP_KERNEL);
101075 if (table == NULL)
101076 goto err_alloc;
101077@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
101078 table[0].data = &net->nf_frag.frags.timeout;
101079 table[1].data = &net->nf_frag.frags.low_thresh;
101080 table[2].data = &net->nf_frag.frags.high_thresh;
101081- }
101082-
101083- hdr = register_net_sysctl(net, "net/netfilter", table);
101084+ hdr = register_net_sysctl(net, "net/netfilter", table);
101085+ } else
101086+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
101087 if (hdr == NULL)
101088 goto err_reg;
101089
101090@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
101091 return 0;
101092
101093 err_reg:
101094- if (!net_eq(net, &init_net))
101095- kfree(table);
101096+ kfree(table);
101097 err_alloc:
101098 return -ENOMEM;
101099 }
101100diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
101101index 6179ac1..ffa0293 100644
101102--- a/net/ipv6/output_core.c
101103+++ b/net/ipv6/output_core.c
101104@@ -8,7 +8,6 @@
101105 #include <net/addrconf.h>
101106 #include <net/secure_seq.h>
101107
101108-
101109 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
101110 {
101111 u16 offset = sizeof(struct ipv6hdr);
101112diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
101113index bda7429..469b26b 100644
101114--- a/net/ipv6/ping.c
101115+++ b/net/ipv6/ping.c
101116@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
101117 };
101118 #endif
101119
101120+static struct pingv6_ops real_pingv6_ops = {
101121+ .ipv6_recv_error = ipv6_recv_error,
101122+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
101123+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
101124+ .icmpv6_err_convert = icmpv6_err_convert,
101125+ .ipv6_icmp_error = ipv6_icmp_error,
101126+ .ipv6_chk_addr = ipv6_chk_addr,
101127+};
101128+
101129+static struct pingv6_ops dummy_pingv6_ops = {
101130+ .ipv6_recv_error = dummy_ipv6_recv_error,
101131+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
101132+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
101133+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
101134+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
101135+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
101136+};
101137+
101138 int __init pingv6_init(void)
101139 {
101140 #ifdef CONFIG_PROC_FS
101141@@ -253,13 +271,7 @@ int __init pingv6_init(void)
101142 if (ret)
101143 return ret;
101144 #endif
101145- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
101146- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
101147- pingv6_ops.ip6_datagram_recv_specific_ctl =
101148- ip6_datagram_recv_specific_ctl;
101149- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
101150- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
101151- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
101152+ pingv6_ops = &real_pingv6_ops;
101153 return inet6_register_protosw(&pingv6_protosw);
101154 }
101155
101156@@ -268,14 +280,9 @@ int __init pingv6_init(void)
101157 */
101158 void pingv6_exit(void)
101159 {
101160- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
101161- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
101162- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
101163- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
101164- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
101165- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
101166 #ifdef CONFIG_PROC_FS
101167 unregister_pernet_subsys(&ping_v6_net_ops);
101168 #endif
101169+ pingv6_ops = &dummy_pingv6_ops;
101170 inet6_unregister_protosw(&pingv6_protosw);
101171 }
101172diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
101173index 091d066..139d410 100644
101174--- a/net/ipv6/proc.c
101175+++ b/net/ipv6/proc.c
101176@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
101177 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
101178 goto proc_snmp6_fail;
101179
101180- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
101181+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
101182 if (!net->mib.proc_net_devsnmp6)
101183 goto proc_dev_snmp6_fail;
101184 return 0;
101185diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
101186index 1f29996..46fe0c7 100644
101187--- a/net/ipv6/raw.c
101188+++ b/net/ipv6/raw.c
101189@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
101190 {
101191 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
101192 skb_checksum_complete(skb)) {
101193- atomic_inc(&sk->sk_drops);
101194+ atomic_inc_unchecked(&sk->sk_drops);
101195 kfree_skb(skb);
101196 return NET_RX_DROP;
101197 }
101198@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
101199 struct raw6_sock *rp = raw6_sk(sk);
101200
101201 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
101202- atomic_inc(&sk->sk_drops);
101203+ atomic_inc_unchecked(&sk->sk_drops);
101204 kfree_skb(skb);
101205 return NET_RX_DROP;
101206 }
101207@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
101208
101209 if (inet->hdrincl) {
101210 if (skb_checksum_complete(skb)) {
101211- atomic_inc(&sk->sk_drops);
101212+ atomic_inc_unchecked(&sk->sk_drops);
101213 kfree_skb(skb);
101214 return NET_RX_DROP;
101215 }
101216@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101217 if (flags & MSG_OOB)
101218 return -EOPNOTSUPP;
101219
101220+ if (addr_len)
101221+ *addr_len=sizeof(*sin6);
101222+
101223 if (flags & MSG_ERRQUEUE)
101224 return ipv6_recv_error(sk, msg, len, addr_len);
101225
101226@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101227 sin6->sin6_flowinfo = 0;
101228 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
101229 IP6CB(skb)->iif);
101230- *addr_len = sizeof(*sin6);
101231 }
101232
101233 sock_recv_ts_and_drops(msg, sk, skb);
101234@@ -610,7 +612,7 @@ out:
101235 return err;
101236 }
101237
101238-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
101239+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
101240 struct flowi6 *fl6, struct dst_entry **dstp,
101241 unsigned int flags)
101242 {
101243@@ -922,12 +924,15 @@ do_confirm:
101244 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
101245 char __user *optval, int optlen)
101246 {
101247+ struct icmp6_filter filter;
101248+
101249 switch (optname) {
101250 case ICMPV6_FILTER:
101251 if (optlen > sizeof(struct icmp6_filter))
101252 optlen = sizeof(struct icmp6_filter);
101253- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
101254+ if (copy_from_user(&filter, optval, optlen))
101255 return -EFAULT;
101256+ raw6_sk(sk)->filter = filter;
101257 return 0;
101258 default:
101259 return -ENOPROTOOPT;
101260@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
101261 char __user *optval, int __user *optlen)
101262 {
101263 int len;
101264+ struct icmp6_filter filter;
101265
101266 switch (optname) {
101267 case ICMPV6_FILTER:
101268@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
101269 len = sizeof(struct icmp6_filter);
101270 if (put_user(len, optlen))
101271 return -EFAULT;
101272- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
101273+ filter = raw6_sk(sk)->filter;
101274+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
101275 return -EFAULT;
101276 return 0;
101277 default:
101278diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
101279index cc85a9b..526a133 100644
101280--- a/net/ipv6/reassembly.c
101281+++ b/net/ipv6/reassembly.c
101282@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
101283
101284 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101285 {
101286- struct ctl_table *table;
101287+ ctl_table_no_const *table = NULL;
101288 struct ctl_table_header *hdr;
101289
101290- table = ip6_frags_ns_ctl_table;
101291 if (!net_eq(net, &init_net)) {
101292- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101293+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101294 if (table == NULL)
101295 goto err_alloc;
101296
101297@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101298 /* Don't export sysctls to unprivileged users */
101299 if (net->user_ns != &init_user_ns)
101300 table[0].procname = NULL;
101301- }
101302+ hdr = register_net_sysctl(net, "net/ipv6", table);
101303+ } else
101304+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
101305
101306- hdr = register_net_sysctl(net, "net/ipv6", table);
101307 if (hdr == NULL)
101308 goto err_reg;
101309
101310@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101311 return 0;
101312
101313 err_reg:
101314- if (!net_eq(net, &init_net))
101315- kfree(table);
101316+ kfree(table);
101317 err_alloc:
101318 return -ENOMEM;
101319 }
101320diff --git a/net/ipv6/route.c b/net/ipv6/route.c
101321index 6ebdb7b6..f225ab1 100644
101322--- a/net/ipv6/route.c
101323+++ b/net/ipv6/route.c
101324@@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
101325
101326 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
101327 {
101328- struct ctl_table *table;
101329+ ctl_table_no_const *table;
101330
101331 table = kmemdup(ipv6_route_table_template,
101332 sizeof(ipv6_route_table_template),
101333diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
101334index 4f40817..54dcbef 100644
101335--- a/net/ipv6/sit.c
101336+++ b/net/ipv6/sit.c
101337@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
101338 static void ipip6_dev_free(struct net_device *dev);
101339 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
101340 __be32 *v4dst);
101341-static struct rtnl_link_ops sit_link_ops __read_mostly;
101342+static struct rtnl_link_ops sit_link_ops;
101343
101344 static int sit_net_id __read_mostly;
101345 struct sit_net {
101346@@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
101347 unregister_netdevice_queue(dev, head);
101348 }
101349
101350-static struct rtnl_link_ops sit_link_ops __read_mostly = {
101351+static struct rtnl_link_ops sit_link_ops = {
101352 .kind = "sit",
101353 .maxtype = IFLA_IPTUN_MAX,
101354 .policy = ipip6_policy,
101355diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
101356index 7f405a1..eabef92 100644
101357--- a/net/ipv6/sysctl_net_ipv6.c
101358+++ b/net/ipv6/sysctl_net_ipv6.c
101359@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
101360
101361 static int __net_init ipv6_sysctl_net_init(struct net *net)
101362 {
101363- struct ctl_table *ipv6_table;
101364+ ctl_table_no_const *ipv6_table;
101365 struct ctl_table *ipv6_route_table;
101366 struct ctl_table *ipv6_icmp_table;
101367 int err;
101368diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
101369index e289830..79a5718 100644
101370--- a/net/ipv6/tcp_ipv6.c
101371+++ b/net/ipv6/tcp_ipv6.c
101372@@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
101373 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
101374 }
101375
101376+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101377+extern int grsec_enable_blackhole;
101378+#endif
101379+
101380 static void tcp_v6_hash(struct sock *sk)
101381 {
101382 if (sk->sk_state != TCP_CLOSE) {
101383@@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
101384 return 0;
101385
101386 reset:
101387+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101388+ if (!grsec_enable_blackhole)
101389+#endif
101390 tcp_v6_send_reset(sk, skb);
101391 discard:
101392 if (opt_skb)
101393@@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
101394 TCP_SKB_CB(skb)->sacked = 0;
101395
101396 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
101397- if (!sk)
101398+ if (!sk) {
101399+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101400+ ret = 1;
101401+#endif
101402 goto no_tcp_socket;
101403+ }
101404
101405 process:
101406- if (sk->sk_state == TCP_TIME_WAIT)
101407+ if (sk->sk_state == TCP_TIME_WAIT) {
101408+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101409+ ret = 2;
101410+#endif
101411 goto do_time_wait;
101412+ }
101413
101414 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
101415 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
101416@@ -1557,6 +1572,10 @@ csum_error:
101417 bad_packet:
101418 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
101419 } else {
101420+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101421+ if (!grsec_enable_blackhole || (ret == 1 &&
101422+ (skb->dev->flags & IFF_LOOPBACK)))
101423+#endif
101424 tcp_v6_send_reset(NULL, skb);
101425 }
101426
101427diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
101428index 20b63d2..13be908 100644
101429--- a/net/ipv6/udp.c
101430+++ b/net/ipv6/udp.c
101431@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
101432 udp_ipv6_hash_secret + net_hash_mix(net));
101433 }
101434
101435+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101436+extern int grsec_enable_blackhole;
101437+#endif
101438+
101439 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
101440 {
101441 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
101442@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101443 int is_udp4;
101444 bool slow;
101445
101446+ if (addr_len)
101447+ *addr_len = sizeof(struct sockaddr_in6);
101448+
101449 if (flags & MSG_ERRQUEUE)
101450 return ipv6_recv_error(sk, msg, len, addr_len);
101451
101452@@ -435,7 +442,7 @@ try_again:
101453 if (unlikely(err)) {
101454 trace_kfree_skb(skb, udpv6_recvmsg);
101455 if (!peeked) {
101456- atomic_inc(&sk->sk_drops);
101457+ atomic_inc_unchecked(&sk->sk_drops);
101458 if (is_udp4)
101459 UDP_INC_STATS_USER(sock_net(sk),
101460 UDP_MIB_INERRORS,
101461@@ -475,7 +482,7 @@ try_again:
101462 ipv6_iface_scope_id(&sin6->sin6_addr,
101463 IP6CB(skb)->iif);
101464 }
101465- *addr_len = sizeof(*sin6);
101466+
101467 }
101468
101469 if (np->rxopt.all)
101470@@ -690,7 +697,7 @@ csum_error:
101471 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
101472 drop:
101473 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
101474- atomic_inc(&sk->sk_drops);
101475+ atomic_inc_unchecked(&sk->sk_drops);
101476 kfree_skb(skb);
101477 return -1;
101478 }
101479@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
101480 if (likely(skb1 == NULL))
101481 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
101482 if (!skb1) {
101483- atomic_inc(&sk->sk_drops);
101484+ atomic_inc_unchecked(&sk->sk_drops);
101485 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
101486 IS_UDPLITE(sk));
101487 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
101488@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
101489 goto csum_error;
101490
101491 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
101492+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101493+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
101494+#endif
101495 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
101496
101497 kfree_skb(skb);
101498diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
101499index 2a0bbda..d75ca57 100644
101500--- a/net/ipv6/xfrm6_policy.c
101501+++ b/net/ipv6/xfrm6_policy.c
101502@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
101503 }
101504 }
101505
101506-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
101507+static int xfrm6_garbage_collect(struct dst_ops *ops)
101508 {
101509 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
101510
101511- xfrm6_policy_afinfo.garbage_collect(net);
101512+ xfrm_garbage_collect_deferred(net);
101513 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
101514 }
101515
101516@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
101517
101518 static int __net_init xfrm6_net_init(struct net *net)
101519 {
101520- struct ctl_table *table;
101521+ ctl_table_no_const *table = NULL;
101522 struct ctl_table_header *hdr;
101523
101524- table = xfrm6_policy_table;
101525 if (!net_eq(net, &init_net)) {
101526- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101527+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101528 if (!table)
101529 goto err_alloc;
101530
101531 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
101532- }
101533+ hdr = register_net_sysctl(net, "net/ipv6", table);
101534+ } else
101535+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
101536
101537- hdr = register_net_sysctl(net, "net/ipv6", table);
101538 if (!hdr)
101539 goto err_reg;
101540
101541@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
101542 return 0;
101543
101544 err_reg:
101545- if (!net_eq(net, &init_net))
101546- kfree(table);
101547+ kfree(table);
101548 err_alloc:
101549 return -ENOMEM;
101550 }
101551diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
101552index e15c16a..7cf07aa 100644
101553--- a/net/ipx/ipx_proc.c
101554+++ b/net/ipx/ipx_proc.c
101555@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
101556 struct proc_dir_entry *p;
101557 int rc = -ENOMEM;
101558
101559- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
101560+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
101561
101562 if (!ipx_proc_dir)
101563 goto out;
101564diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
101565index 2ba8b97..6d33010 100644
101566--- a/net/irda/ircomm/ircomm_tty.c
101567+++ b/net/irda/ircomm/ircomm_tty.c
101568@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101569 add_wait_queue(&port->open_wait, &wait);
101570
101571 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
101572- __FILE__, __LINE__, tty->driver->name, port->count);
101573+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101574
101575 spin_lock_irqsave(&port->lock, flags);
101576 if (!tty_hung_up_p(filp))
101577- port->count--;
101578+ atomic_dec(&port->count);
101579 port->blocked_open++;
101580 spin_unlock_irqrestore(&port->lock, flags);
101581
101582@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101583 }
101584
101585 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
101586- __FILE__, __LINE__, tty->driver->name, port->count);
101587+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101588
101589 schedule();
101590 }
101591@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101592
101593 spin_lock_irqsave(&port->lock, flags);
101594 if (!tty_hung_up_p(filp))
101595- port->count++;
101596+ atomic_inc(&port->count);
101597 port->blocked_open--;
101598 spin_unlock_irqrestore(&port->lock, flags);
101599
101600 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
101601- __FILE__, __LINE__, tty->driver->name, port->count);
101602+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101603
101604 if (!retval)
101605 port->flags |= ASYNC_NORMAL_ACTIVE;
101606@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101607
101608 /* ++ is not atomic, so this should be protected - Jean II */
101609 spin_lock_irqsave(&self->port.lock, flags);
101610- self->port.count++;
101611+ atomic_inc(&self->port.count);
101612 spin_unlock_irqrestore(&self->port.lock, flags);
101613 tty_port_tty_set(&self->port, tty);
101614
101615 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101616- self->line, self->port.count);
101617+ self->line, atomic_read(&self->port.count));
101618
101619 /* Not really used by us, but lets do it anyway */
101620 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101621@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101622 tty_kref_put(port->tty);
101623 }
101624 port->tty = NULL;
101625- port->count = 0;
101626+ atomic_set(&port->count, 0);
101627 spin_unlock_irqrestore(&port->lock, flags);
101628
101629 wake_up_interruptible(&port->open_wait);
101630@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101631 seq_putc(m, '\n');
101632
101633 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101634- seq_printf(m, "Open count: %d\n", self->port.count);
101635+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101636 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101637 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101638
101639diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101640index b9ac598..f88cc56 100644
101641--- a/net/irda/irproc.c
101642+++ b/net/irda/irproc.c
101643@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101644 {
101645 int i;
101646
101647- proc_irda = proc_mkdir("irda", init_net.proc_net);
101648+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101649 if (proc_irda == NULL)
101650 return;
101651
101652diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101653index 8c9d730..66c6305 100644
101654--- a/net/iucv/af_iucv.c
101655+++ b/net/iucv/af_iucv.c
101656@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101657
101658 write_lock_bh(&iucv_sk_list.lock);
101659
101660- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101661+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101662 while (__iucv_get_sock_by_name(name)) {
101663 sprintf(name, "%08x",
101664- atomic_inc_return(&iucv_sk_list.autobind_name));
101665+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101666 }
101667
101668 write_unlock_bh(&iucv_sk_list.lock);
101669diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101670index da78793..bdd78cf 100644
101671--- a/net/iucv/iucv.c
101672+++ b/net/iucv/iucv.c
101673@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101674 return NOTIFY_OK;
101675 }
101676
101677-static struct notifier_block __refdata iucv_cpu_notifier = {
101678+static struct notifier_block iucv_cpu_notifier = {
101679 .notifier_call = iucv_cpu_notify,
101680 };
101681
101682diff --git a/net/key/af_key.c b/net/key/af_key.c
101683index f3c8307..7127791 100644
101684--- a/net/key/af_key.c
101685+++ b/net/key/af_key.c
101686@@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101687 static u32 get_acqseq(void)
101688 {
101689 u32 res;
101690- static atomic_t acqseq;
101691+ static atomic_unchecked_t acqseq;
101692
101693 do {
101694- res = atomic_inc_return(&acqseq);
101695+ res = atomic_inc_return_unchecked(&acqseq);
101696 } while (!res);
101697 return res;
101698 }
101699diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101700index 76125c5..e474828 100644
101701--- a/net/l2tp/l2tp_eth.c
101702+++ b/net/l2tp/l2tp_eth.c
101703@@ -42,12 +42,12 @@ struct l2tp_eth {
101704 struct sock *tunnel_sock;
101705 struct l2tp_session *session;
101706 struct list_head list;
101707- atomic_long_t tx_bytes;
101708- atomic_long_t tx_packets;
101709- atomic_long_t tx_dropped;
101710- atomic_long_t rx_bytes;
101711- atomic_long_t rx_packets;
101712- atomic_long_t rx_errors;
101713+ atomic_long_unchecked_t tx_bytes;
101714+ atomic_long_unchecked_t tx_packets;
101715+ atomic_long_unchecked_t tx_dropped;
101716+ atomic_long_unchecked_t rx_bytes;
101717+ atomic_long_unchecked_t rx_packets;
101718+ atomic_long_unchecked_t rx_errors;
101719 };
101720
101721 /* via l2tp_session_priv() */
101722@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101723 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101724
101725 if (likely(ret == NET_XMIT_SUCCESS)) {
101726- atomic_long_add(len, &priv->tx_bytes);
101727- atomic_long_inc(&priv->tx_packets);
101728+ atomic_long_add_unchecked(len, &priv->tx_bytes);
101729+ atomic_long_inc_unchecked(&priv->tx_packets);
101730 } else {
101731- atomic_long_inc(&priv->tx_dropped);
101732+ atomic_long_inc_unchecked(&priv->tx_dropped);
101733 }
101734 return NETDEV_TX_OK;
101735 }
101736@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101737 {
101738 struct l2tp_eth *priv = netdev_priv(dev);
101739
101740- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101741- stats->tx_packets = atomic_long_read(&priv->tx_packets);
101742- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101743- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101744- stats->rx_packets = atomic_long_read(&priv->rx_packets);
101745- stats->rx_errors = atomic_long_read(&priv->rx_errors);
101746+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101747+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101748+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101749+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101750+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101751+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101752 return stats;
101753 }
101754
101755@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101756 nf_reset(skb);
101757
101758 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101759- atomic_long_inc(&priv->rx_packets);
101760- atomic_long_add(data_len, &priv->rx_bytes);
101761+ atomic_long_inc_unchecked(&priv->rx_packets);
101762+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101763 } else {
101764- atomic_long_inc(&priv->rx_errors);
101765+ atomic_long_inc_unchecked(&priv->rx_errors);
101766 }
101767 return;
101768
101769 error:
101770- atomic_long_inc(&priv->rx_errors);
101771+ atomic_long_inc_unchecked(&priv->rx_errors);
101772 kfree_skb(skb);
101773 }
101774
101775diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101776index 3397fe6..861fd1a 100644
101777--- a/net/l2tp/l2tp_ip.c
101778+++ b/net/l2tp/l2tp_ip.c
101779@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101780 if (flags & MSG_OOB)
101781 goto out;
101782
101783+ if (addr_len)
101784+ *addr_len = sizeof(*sin);
101785+
101786 skb = skb_recv_datagram(sk, flags, noblock, &err);
101787 if (!skb)
101788 goto out;
101789@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101790 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101791 sin->sin_port = 0;
101792 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101793- *addr_len = sizeof(*sin);
101794 }
101795 if (inet->cmsg_flags)
101796 ip_cmsg_recv(msg, skb);
101797diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101798index 1a3c7e0..80f8b0c 100644
101799--- a/net/llc/llc_proc.c
101800+++ b/net/llc/llc_proc.c
101801@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101802 int rc = -ENOMEM;
101803 struct proc_dir_entry *p;
101804
101805- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101806+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101807 if (!llc_proc_dir)
101808 goto out;
101809
101810diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101811index aaa59d7..21a2c4a 100644
101812--- a/net/mac80211/cfg.c
101813+++ b/net/mac80211/cfg.c
101814@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101815 ret = ieee80211_vif_use_channel(sdata, chandef,
101816 IEEE80211_CHANCTX_EXCLUSIVE);
101817 }
101818- } else if (local->open_count == local->monitors) {
101819+ } else if (local_read(&local->open_count) == local->monitors) {
101820 local->_oper_chandef = *chandef;
101821 ieee80211_hw_config(local, 0);
101822 }
101823@@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101824 else
101825 local->probe_req_reg--;
101826
101827- if (!local->open_count)
101828+ if (!local_read(&local->open_count))
101829 break;
101830
101831 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101832@@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101833 if (chanctx_conf) {
101834 *chandef = chanctx_conf->def;
101835 ret = 0;
101836- } else if (local->open_count > 0 &&
101837- local->open_count == local->monitors &&
101838+ } else if (local_read(&local->open_count) > 0 &&
101839+ local_read(&local->open_count) == local->monitors &&
101840 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101841 if (local->use_chanctx)
101842 *chandef = local->monitor_chandef;
101843diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101844index f169b6e..a5dc4eb 100644
101845--- a/net/mac80211/ieee80211_i.h
101846+++ b/net/mac80211/ieee80211_i.h
101847@@ -28,6 +28,7 @@
101848 #include <net/ieee80211_radiotap.h>
101849 #include <net/cfg80211.h>
101850 #include <net/mac80211.h>
101851+#include <asm/local.h>
101852 #include "key.h"
101853 #include "sta_info.h"
101854 #include "debug.h"
101855@@ -999,7 +1000,7 @@ struct ieee80211_local {
101856 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101857 spinlock_t queue_stop_reason_lock;
101858
101859- int open_count;
101860+ local_t open_count;
101861 int monitors, cooked_mntrs;
101862 /* number of interfaces with corresponding FIF_ flags */
101863 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101864diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101865index 34799e0..b411290 100644
101866--- a/net/mac80211/iface.c
101867+++ b/net/mac80211/iface.c
101868@@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101869 break;
101870 }
101871
101872- if (local->open_count == 0) {
101873+ if (local_read(&local->open_count) == 0) {
101874 res = drv_start(local);
101875 if (res)
101876 goto err_del_bss;
101877@@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101878 res = drv_add_interface(local, sdata);
101879 if (res)
101880 goto err_stop;
101881- } else if (local->monitors == 0 && local->open_count == 0) {
101882+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101883 res = ieee80211_add_virtual_monitor(local);
101884 if (res)
101885 goto err_stop;
101886@@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101887 atomic_inc(&local->iff_promiscs);
101888
101889 if (coming_up)
101890- local->open_count++;
101891+ local_inc(&local->open_count);
101892
101893 if (hw_reconf_flags)
101894 ieee80211_hw_config(local, hw_reconf_flags);
101895@@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101896 err_del_interface:
101897 drv_remove_interface(local, sdata);
101898 err_stop:
101899- if (!local->open_count)
101900+ if (!local_read(&local->open_count))
101901 drv_stop(local);
101902 err_del_bss:
101903 sdata->bss = NULL;
101904@@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101905 }
101906
101907 if (going_down)
101908- local->open_count--;
101909+ local_dec(&local->open_count);
101910
101911 switch (sdata->vif.type) {
101912 case NL80211_IFTYPE_AP_VLAN:
101913@@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101914 }
101915 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101916
101917- if (local->open_count == 0)
101918+ if (local_read(&local->open_count) == 0)
101919 ieee80211_clear_tx_pending(local);
101920
101921 /*
101922@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101923
101924 ieee80211_recalc_ps(local, -1);
101925
101926- if (local->open_count == 0) {
101927+ if (local_read(&local->open_count) == 0) {
101928 ieee80211_stop_device(local);
101929
101930 /* no reconfiguring after stop! */
101931@@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101932 ieee80211_configure_filter(local);
101933 ieee80211_hw_config(local, hw_reconf_flags);
101934
101935- if (local->monitors == local->open_count)
101936+ if (local->monitors == local_read(&local->open_count))
101937 ieee80211_add_virtual_monitor(local);
101938 }
101939
101940diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101941index 4c1bf61..00b449b 100644
101942--- a/net/mac80211/main.c
101943+++ b/net/mac80211/main.c
101944@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101945 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101946 IEEE80211_CONF_CHANGE_POWER);
101947
101948- if (changed && local->open_count) {
101949+ if (changed && local_read(&local->open_count)) {
101950 ret = drv_config(local, changed);
101951 /*
101952 * Goal:
101953diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101954index d478b88..8c8d157 100644
101955--- a/net/mac80211/pm.c
101956+++ b/net/mac80211/pm.c
101957@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101958 struct ieee80211_sub_if_data *sdata;
101959 struct sta_info *sta;
101960
101961- if (!local->open_count)
101962+ if (!local_read(&local->open_count))
101963 goto suspend;
101964
101965 ieee80211_scan_cancel(local);
101966@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101967 cancel_work_sync(&local->dynamic_ps_enable_work);
101968 del_timer_sync(&local->dynamic_ps_timer);
101969
101970- local->wowlan = wowlan && local->open_count;
101971+ local->wowlan = wowlan && local_read(&local->open_count);
101972 if (local->wowlan) {
101973 int err = drv_suspend(local, wowlan);
101974 if (err < 0) {
101975@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101976 WARN_ON(!list_empty(&local->chanctx_list));
101977
101978 /* stop hardware - this must stop RX */
101979- if (local->open_count)
101980+ if (local_read(&local->open_count))
101981 ieee80211_stop_device(local);
101982
101983 suspend:
101984diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101985index 8fdadfd..a4f72b8 100644
101986--- a/net/mac80211/rate.c
101987+++ b/net/mac80211/rate.c
101988@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101989
101990 ASSERT_RTNL();
101991
101992- if (local->open_count)
101993+ if (local_read(&local->open_count))
101994 return -EBUSY;
101995
101996 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101997diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101998index 6ff1346..936ca9a 100644
101999--- a/net/mac80211/rc80211_pid_debugfs.c
102000+++ b/net/mac80211/rc80211_pid_debugfs.c
102001@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
102002
102003 spin_unlock_irqrestore(&events->lock, status);
102004
102005- if (copy_to_user(buf, pb, p))
102006+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
102007 return -EFAULT;
102008
102009 return p;
102010diff --git a/net/mac80211/util.c b/net/mac80211/util.c
102011index 3c36583..12887fe 100644
102012--- a/net/mac80211/util.c
102013+++ b/net/mac80211/util.c
102014@@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
102015 }
102016 #endif
102017 /* everything else happens only if HW was up & running */
102018- if (!local->open_count)
102019+ if (!local_read(&local->open_count))
102020 goto wake_up;
102021
102022 /*
102023@@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
102024 local->in_reconfig = false;
102025 barrier();
102026
102027- if (local->monitors == local->open_count && local->monitors > 0)
102028+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
102029 ieee80211_add_virtual_monitor(local);
102030
102031 /*
102032diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
102033index e9410d1..77b6378 100644
102034--- a/net/netfilter/Kconfig
102035+++ b/net/netfilter/Kconfig
102036@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
102037
102038 To compile it as a module, choose M here. If unsure, say N.
102039
102040+config NETFILTER_XT_MATCH_GRADM
102041+ tristate '"gradm" match support'
102042+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
102043+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
102044+ ---help---
102045+ The gradm match allows to match on grsecurity RBAC being enabled.
102046+ It is useful when iptables rules are applied early on bootup to
102047+ prevent connections to the machine (except from a trusted host)
102048+ while the RBAC system is disabled.
102049+
102050 config NETFILTER_XT_MATCH_HASHLIMIT
102051 tristate '"hashlimit" match support'
102052 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
102053diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
102054index bffdad7..f9317d1 100644
102055--- a/net/netfilter/Makefile
102056+++ b/net/netfilter/Makefile
102057@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
102058 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
102059 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
102060 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
102061+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
102062 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
102063 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
102064 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
102065diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
102066index 1172083..986f1c1 100644
102067--- a/net/netfilter/ipset/ip_set_core.c
102068+++ b/net/netfilter/ipset/ip_set_core.c
102069@@ -1924,7 +1924,7 @@ done:
102070 return ret;
102071 }
102072
102073-static struct nf_sockopt_ops so_set __read_mostly = {
102074+static struct nf_sockopt_ops so_set = {
102075 .pf = PF_INET,
102076 .get_optmin = SO_IP_SET,
102077 .get_optmax = SO_IP_SET + 1,
102078diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
102079index a8eb0a8..86f2de4 100644
102080--- a/net/netfilter/ipvs/ip_vs_conn.c
102081+++ b/net/netfilter/ipvs/ip_vs_conn.c
102082@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
102083 /* Increase the refcnt counter of the dest */
102084 ip_vs_dest_hold(dest);
102085
102086- conn_flags = atomic_read(&dest->conn_flags);
102087+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
102088 if (cp->protocol != IPPROTO_UDP)
102089 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
102090 flags = cp->flags;
102091@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
102092
102093 cp->control = NULL;
102094 atomic_set(&cp->n_control, 0);
102095- atomic_set(&cp->in_pkts, 0);
102096+ atomic_set_unchecked(&cp->in_pkts, 0);
102097
102098 cp->packet_xmit = NULL;
102099 cp->app = NULL;
102100@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
102101
102102 /* Don't drop the entry if its number of incoming packets is not
102103 located in [0, 8] */
102104- i = atomic_read(&cp->in_pkts);
102105+ i = atomic_read_unchecked(&cp->in_pkts);
102106 if (i > 8 || i < 0) return 0;
102107
102108 if (!todrop_rate[i]) return 0;
102109diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
102110index 3d2d2c8..c87e4d3 100644
102111--- a/net/netfilter/ipvs/ip_vs_core.c
102112+++ b/net/netfilter/ipvs/ip_vs_core.c
102113@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
102114 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
102115 /* do not touch skb anymore */
102116
102117- atomic_inc(&cp->in_pkts);
102118+ atomic_inc_unchecked(&cp->in_pkts);
102119 ip_vs_conn_put(cp);
102120 return ret;
102121 }
102122@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
102123 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
102124 pkts = sysctl_sync_threshold(ipvs);
102125 else
102126- pkts = atomic_add_return(1, &cp->in_pkts);
102127+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
102128
102129 if (ipvs->sync_state & IP_VS_STATE_MASTER)
102130 ip_vs_sync_conn(net, cp, pkts);
102131diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
102132index c42e83d..a6a3f8b 100644
102133--- a/net/netfilter/ipvs/ip_vs_ctl.c
102134+++ b/net/netfilter/ipvs/ip_vs_ctl.c
102135@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
102136 */
102137 ip_vs_rs_hash(ipvs, dest);
102138 }
102139- atomic_set(&dest->conn_flags, conn_flags);
102140+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
102141
102142 /* bind the service */
102143 old_svc = rcu_dereference_protected(dest->svc, 1);
102144@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
102145 * align with netns init in ip_vs_control_net_init()
102146 */
102147
102148-static struct ctl_table vs_vars[] = {
102149+static ctl_table_no_const vs_vars[] __read_only = {
102150 {
102151 .procname = "amemthresh",
102152 .maxlen = sizeof(int),
102153@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
102154 " %-7s %-6d %-10d %-10d\n",
102155 &dest->addr.in6,
102156 ntohs(dest->port),
102157- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
102158+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
102159 atomic_read(&dest->weight),
102160 atomic_read(&dest->activeconns),
102161 atomic_read(&dest->inactconns));
102162@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
102163 "%-7s %-6d %-10d %-10d\n",
102164 ntohl(dest->addr.ip),
102165 ntohs(dest->port),
102166- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
102167+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
102168 atomic_read(&dest->weight),
102169 atomic_read(&dest->activeconns),
102170 atomic_read(&dest->inactconns));
102171@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
102172
102173 entry.addr = dest->addr.ip;
102174 entry.port = dest->port;
102175- entry.conn_flags = atomic_read(&dest->conn_flags);
102176+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
102177 entry.weight = atomic_read(&dest->weight);
102178 entry.u_threshold = dest->u_threshold;
102179 entry.l_threshold = dest->l_threshold;
102180@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
102181 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
102182 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
102183 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
102184- (atomic_read(&dest->conn_flags) &
102185+ (atomic_read_unchecked(&dest->conn_flags) &
102186 IP_VS_CONN_F_FWD_MASK)) ||
102187 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
102188 atomic_read(&dest->weight)) ||
102189@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
102190 {
102191 int idx;
102192 struct netns_ipvs *ipvs = net_ipvs(net);
102193- struct ctl_table *tbl;
102194+ ctl_table_no_const *tbl;
102195
102196 atomic_set(&ipvs->dropentry, 0);
102197 spin_lock_init(&ipvs->dropentry_lock);
102198diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
102199index 547ff33..c8c8117 100644
102200--- a/net/netfilter/ipvs/ip_vs_lblc.c
102201+++ b/net/netfilter/ipvs/ip_vs_lblc.c
102202@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
102203 * IPVS LBLC sysctl table
102204 */
102205 #ifdef CONFIG_SYSCTL
102206-static struct ctl_table vs_vars_table[] = {
102207+static ctl_table_no_const vs_vars_table[] __read_only = {
102208 {
102209 .procname = "lblc_expiration",
102210 .data = NULL,
102211diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
102212index 3f21a2f..a112e85 100644
102213--- a/net/netfilter/ipvs/ip_vs_lblcr.c
102214+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
102215@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
102216 * IPVS LBLCR sysctl table
102217 */
102218
102219-static struct ctl_table vs_vars_table[] = {
102220+static ctl_table_no_const vs_vars_table[] __read_only = {
102221 {
102222 .procname = "lblcr_expiration",
102223 .data = NULL,
102224diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
102225index db80126..ef7110e 100644
102226--- a/net/netfilter/ipvs/ip_vs_sync.c
102227+++ b/net/netfilter/ipvs/ip_vs_sync.c
102228@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
102229 cp = cp->control;
102230 if (cp) {
102231 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
102232- pkts = atomic_add_return(1, &cp->in_pkts);
102233+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
102234 else
102235 pkts = sysctl_sync_threshold(ipvs);
102236 ip_vs_sync_conn(net, cp->control, pkts);
102237@@ -771,7 +771,7 @@ control:
102238 if (!cp)
102239 return;
102240 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
102241- pkts = atomic_add_return(1, &cp->in_pkts);
102242+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
102243 else
102244 pkts = sysctl_sync_threshold(ipvs);
102245 goto sloop;
102246@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
102247
102248 if (opt)
102249 memcpy(&cp->in_seq, opt, sizeof(*opt));
102250- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
102251+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
102252 cp->state = state;
102253 cp->old_state = cp->state;
102254 /*
102255diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
102256index 7f0e1cf..e9a86e6 100644
102257--- a/net/netfilter/ipvs/ip_vs_xmit.c
102258+++ b/net/netfilter/ipvs/ip_vs_xmit.c
102259@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
102260 else
102261 rc = NF_ACCEPT;
102262 /* do not touch skb anymore */
102263- atomic_inc(&cp->in_pkts);
102264+ atomic_inc_unchecked(&cp->in_pkts);
102265 goto out;
102266 }
102267
102268@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
102269 else
102270 rc = NF_ACCEPT;
102271 /* do not touch skb anymore */
102272- atomic_inc(&cp->in_pkts);
102273+ atomic_inc_unchecked(&cp->in_pkts);
102274 goto out;
102275 }
102276
102277diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
102278index a4b5e2a..13b1de3 100644
102279--- a/net/netfilter/nf_conntrack_acct.c
102280+++ b/net/netfilter/nf_conntrack_acct.c
102281@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
102282 #ifdef CONFIG_SYSCTL
102283 static int nf_conntrack_acct_init_sysctl(struct net *net)
102284 {
102285- struct ctl_table *table;
102286+ ctl_table_no_const *table;
102287
102288 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
102289 GFP_KERNEL);
102290diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
102291index 75421f2..0e69621 100644
102292--- a/net/netfilter/nf_conntrack_core.c
102293+++ b/net/netfilter/nf_conntrack_core.c
102294@@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
102295 #define DYING_NULLS_VAL ((1<<30)+1)
102296 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
102297
102298+#ifdef CONFIG_GRKERNSEC_HIDESYM
102299+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
102300+#endif
102301+
102302 int nf_conntrack_init_net(struct net *net)
102303 {
102304 int ret = -ENOMEM;
102305@@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
102306 if (!net->ct.stat)
102307 goto err_pcpu_lists;
102308
102309+#ifdef CONFIG_GRKERNSEC_HIDESYM
102310+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
102311+#else
102312 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
102313+#endif
102314 if (!net->ct.slabname)
102315 goto err_slabname;
102316
102317diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
102318index 1df1761..ce8b88a 100644
102319--- a/net/netfilter/nf_conntrack_ecache.c
102320+++ b/net/netfilter/nf_conntrack_ecache.c
102321@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
102322 #ifdef CONFIG_SYSCTL
102323 static int nf_conntrack_event_init_sysctl(struct net *net)
102324 {
102325- struct ctl_table *table;
102326+ ctl_table_no_const *table;
102327
102328 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
102329 GFP_KERNEL);
102330diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
102331index 5b3eae7..dd4b8fe 100644
102332--- a/net/netfilter/nf_conntrack_helper.c
102333+++ b/net/netfilter/nf_conntrack_helper.c
102334@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
102335
102336 static int nf_conntrack_helper_init_sysctl(struct net *net)
102337 {
102338- struct ctl_table *table;
102339+ ctl_table_no_const *table;
102340
102341 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
102342 GFP_KERNEL);
102343diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
102344index b65d586..beec902 100644
102345--- a/net/netfilter/nf_conntrack_proto.c
102346+++ b/net/netfilter/nf_conntrack_proto.c
102347@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
102348
102349 static void
102350 nf_ct_unregister_sysctl(struct ctl_table_header **header,
102351- struct ctl_table **table,
102352+ ctl_table_no_const **table,
102353 unsigned int users)
102354 {
102355 if (users > 0)
102356diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
102357index f641751..d3c5b51 100644
102358--- a/net/netfilter/nf_conntrack_standalone.c
102359+++ b/net/netfilter/nf_conntrack_standalone.c
102360@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
102361
102362 static int nf_conntrack_standalone_init_sysctl(struct net *net)
102363 {
102364- struct ctl_table *table;
102365+ ctl_table_no_const *table;
102366
102367 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
102368 GFP_KERNEL);
102369diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
102370index 7a394df..bd91a8a 100644
102371--- a/net/netfilter/nf_conntrack_timestamp.c
102372+++ b/net/netfilter/nf_conntrack_timestamp.c
102373@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
102374 #ifdef CONFIG_SYSCTL
102375 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
102376 {
102377- struct ctl_table *table;
102378+ ctl_table_no_const *table;
102379
102380 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
102381 GFP_KERNEL);
102382diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
102383index 85296d4..8becdec 100644
102384--- a/net/netfilter/nf_log.c
102385+++ b/net/netfilter/nf_log.c
102386@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
102387
102388 #ifdef CONFIG_SYSCTL
102389 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
102390-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
102391+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
102392
102393 static int nf_log_proc_dostring(struct ctl_table *table, int write,
102394 void __user *buffer, size_t *lenp, loff_t *ppos)
102395@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
102396 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
102397 mutex_unlock(&nf_log_mutex);
102398 } else {
102399+ ctl_table_no_const nf_log_table = *table;
102400+
102401 mutex_lock(&nf_log_mutex);
102402 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
102403 lockdep_is_held(&nf_log_mutex));
102404 if (!logger)
102405- table->data = "NONE";
102406+ nf_log_table.data = "NONE";
102407 else
102408- table->data = logger->name;
102409- r = proc_dostring(table, write, buffer, lenp, ppos);
102410+ nf_log_table.data = logger->name;
102411+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
102412 mutex_unlock(&nf_log_mutex);
102413 }
102414
102415diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
102416index f042ae5..30ea486 100644
102417--- a/net/netfilter/nf_sockopt.c
102418+++ b/net/netfilter/nf_sockopt.c
102419@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
102420 }
102421 }
102422
102423- list_add(&reg->list, &nf_sockopts);
102424+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
102425 out:
102426 mutex_unlock(&nf_sockopt_mutex);
102427 return ret;
102428@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
102429 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
102430 {
102431 mutex_lock(&nf_sockopt_mutex);
102432- list_del(&reg->list);
102433+ pax_list_del((struct list_head *)&reg->list);
102434 mutex_unlock(&nf_sockopt_mutex);
102435 }
102436 EXPORT_SYMBOL(nf_unregister_sockopt);
102437diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
102438index d292c8d..9f1e166 100644
102439--- a/net/netfilter/nfnetlink_log.c
102440+++ b/net/netfilter/nfnetlink_log.c
102441@@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
102442 struct nfnl_log_net {
102443 spinlock_t instances_lock;
102444 struct hlist_head instance_table[INSTANCE_BUCKETS];
102445- atomic_t global_seq;
102446+ atomic_unchecked_t global_seq;
102447 };
102448
102449 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
102450@@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
102451 /* global sequence number */
102452 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
102453 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
102454- htonl(atomic_inc_return(&log->global_seq))))
102455+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
102456 goto nla_put_failure;
102457
102458 if (data_len) {
102459diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
102460index 8a779be..1551d4c 100644
102461--- a/net/netfilter/nft_compat.c
102462+++ b/net/netfilter/nft_compat.c
102463@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
102464 /* We want to reuse existing compat_to_user */
102465 old_fs = get_fs();
102466 set_fs(KERNEL_DS);
102467- t->compat_to_user(out, in);
102468+ t->compat_to_user((void __force_user *)out, in);
102469 set_fs(old_fs);
102470 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
102471 kfree(out);
102472@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
102473 /* We want to reuse existing compat_to_user */
102474 old_fs = get_fs();
102475 set_fs(KERNEL_DS);
102476- m->compat_to_user(out, in);
102477+ m->compat_to_user((void __force_user *)out, in);
102478 set_fs(old_fs);
102479 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
102480 kfree(out);
102481diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
102482new file mode 100644
102483index 0000000..c566332
102484--- /dev/null
102485+++ b/net/netfilter/xt_gradm.c
102486@@ -0,0 +1,51 @@
102487+/*
102488+ * gradm match for netfilter
102489